2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2014 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.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 set n
[file normalize
$gitdir]
20 if {[string match
"*/.git" $n]} {
21 set n
[string range
$n 0 end-5
]
28 if {[info exists _gitworktree
]} {
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
37 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
38 if {$_gitworktree eq
""} {
39 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
49 # run before X event handlers, so reading from a fast source can
50 # make the GUI completely unresponsive.
52 global isonrunq runq currunq
55 if {[info exists isonrunq
($script)]} return
56 if {$runq eq
{} && ![info exists currunq
]} {
59 lappend runq
[list
{} $script]
60 set isonrunq
($script) 1
63 proc filerun
{fd
script} {
64 fileevent
$fd readable
[list filereadable
$fd $script]
67 proc filereadable
{fd
script} {
70 fileevent
$fd readable
{}
71 if {$runq eq
{} && ![info exists currunq
]} {
74 lappend runq
[list
$fd $script]
80 for {set i
0} {$i < [llength
$runq]} {} {
81 if {[lindex
$runq $i 0] eq
$fd} {
82 set runq
[lreplace
$runq $i $i]
90 global isonrunq runq currunq
92 set tstart
[clock clicks
-milliseconds]
94 while {[llength
$runq] > 0} {
95 set fd
[lindex
$runq 0 0]
96 set script [lindex
$runq 0 1]
97 set currunq
[lindex
$runq 0]
98 set runq
[lrange
$runq 1 end
]
99 set repeat
[eval $script]
101 set t1
[clock clicks
-milliseconds]
102 set t
[expr {$t1 - $t0}]
103 if {$repeat ne
{} && $repeat} {
104 if {$fd eq
{} ||
$repeat == 2} {
105 # script returns 1 if it wants to be readded
106 # file readers return 2 if they could do more straight away
107 lappend runq
[list
$fd $script]
109 fileevent
$fd readable
[list filereadable
$fd $script]
111 } elseif
{$fd eq
{}} {
112 unset isonrunq
($script)
115 if {$t1 - $tstart >= 80} break
122 proc reg_instance
{fd
} {
123 global commfd leftover loginstance
125 set i
[incr loginstance
]
131 proc unmerged_files
{files
} {
134 # find the list of unmerged files
138 set fd
[open
"| git ls-files -u" r
]
140 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
149 if {$files eq {} || [path_filter $files $fname]} {
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
160 global worddiff git_version
164 set vinlinediff($n) 0
169 set origargs $arglist
173 foreach arg $arglist {
180 switch -glob -- $arg {
184 # remove from origargs in case we hit an unknown option
185 set origargs [lreplace $origargs $i $i]
189 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
190 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
191 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
192 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
193 "--ignore-space-change" - "-U*" - "--unified=*" {
194 # These request or affect diff output, which we don't want.
195 # Some could be used to set our defaults for diff display.
196 lappend diffargs
$arg
198 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
199 "--name-only" - "--name-status" - "--color" -
200 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
201 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
202 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
203 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
204 "--objects" - "--objects-edge" - "--reverse" {
205 # These cause our parsing of git log's output to fail, or else
206 # they're options we want to set ourselves, so ignore them.
208 "--color-words*" - "--word-diff=color" {
209 # These trigger a word diff in the console interface,
210 # so help the user by enabling our own support
211 if {[package vcompare
$git_version "1.7.2"] >= 0} {
212 set worddiff
[mc
"Color words"]
216 if {[package vcompare
$git_version "1.7.2"] >= 0} {
217 set worddiff
[mc
"Markup words"]
220 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
221 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
222 "--full-history" - "--dense" - "--sparse" -
223 "--follow" - "--left-right" - "--encoding=*" {
224 # These are harmless, and some are even useful
227 "--diff-filter=*" - "--no-merges" - "--unpacked" -
228 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
229 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
230 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
231 "--remove-empty" - "--first-parent" - "--cherry-pick" -
232 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
233 "--simplify-by-decoration" {
234 # These mean that we get a subset of the commits
239 # Line-log with 'stuck' argument (unstuck form is
242 set vinlinediff
($n) 1
247 # This appears to be the only one that has a value as a
248 # separate word following it
258 # git rev-parse doesn't understand --merge
259 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
261 "--no-replace-objects" {
262 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
265 # Other flag arguments including -<n>
266 if {[string is digit
-strict [string range
$arg 1 end
]]} {
269 # a flag argument that we don't recognize;
270 # that means we can't optimize
276 # Non-flag arguments specify commits or ranges of commits
277 if {[string match
"*...*" $arg]} {
278 lappend revargs
--gitk-symmetric-diff-marker
284 set vdflags
($n) $diffargs
285 set vflags
($n) $glflags
286 set vrevs
($n) $revargs
287 set vfiltered
($n) $filtered
288 set vorigargs
($n) $origargs
292 proc parseviewrevs
{view revs
} {
293 global vposids vnegids
298 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
299 # we get stdout followed by stderr in $err
300 # for an unknown rev, git rev-parse echoes it and then errors out
301 set errlines
[split $err "\n"]
303 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
304 set line
[lindex
$errlines $l]
305 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
306 if {[string match
"fatal:*" $line]} {
307 if {[string match
"fatal: ambiguous argument*" $line]
309 if {[llength
$badrev] == 1} {
310 set err
"unknown revision $badrev"
312 set err
"unknown revisions: [join $badrev ", "]"
315 set err
[join [lrange
$errlines $l end
] "\n"]
322 error_popup
"[mc "Error parsing revisions
:"] $err"
329 foreach id
[split $ids "\n"] {
330 if {$id eq
"--gitk-symmetric-diff-marker"} {
332 } elseif
{[string match
"^*" $id]} {
339 lappend neg
[string range
$id 1 end
]
344 lset ret end
$id...
[lindex
$ret end
]
350 set vposids
($view) $pos
351 set vnegids
($view) $neg
355 # Start off a git log process and arrange to read its output
356 proc start_rev_list
{view
} {
357 global startmsecs commitidx viewcomplete curview
359 global viewargs viewargscmd viewfiles vfilelimit
360 global showlocalchanges
361 global viewactive viewinstances vmergeonly
362 global mainheadid viewmainheadid viewmainheadid_orig
363 global vcanopt vflags vrevs vorigargs
366 set startmsecs
[clock clicks
-milliseconds]
367 set commitidx
($view) 0
368 # these are set this way for the error exits
369 set viewcomplete
($view) 1
370 set viewactive
($view) 0
373 set args
$viewargs($view)
374 if {$viewargscmd($view) ne
{}} {
376 set str
[exec sh
-c $viewargscmd($view)]
378 error_popup
"[mc "Error executing
--argscmd command:"] $err"
381 set args
[concat
$args [split $str "\n"]]
383 set vcanopt
($view) [parseviewargs
$view $args]
385 set files
$viewfiles($view)
386 if {$vmergeonly($view)} {
387 set files
[unmerged_files
$files]
390 if {$nr_unmerged == 0} {
391 error_popup
[mc
"No files selected: --merge specified but\
392 no files are unmerged."]
394 error_popup
[mc
"No files selected: --merge specified but\
395 no unmerged files are within file limit."]
400 set vfilelimit
($view) $files
402 if {$vcanopt($view)} {
403 set revs
[parseviewrevs
$view $vrevs($view)]
407 set args
[concat
$vflags($view) $revs]
409 set args
$vorigargs($view)
413 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
414 --parents --boundary $args "--" $files] r
]
416 error_popup
"[mc "Error executing git log
:"] $err"
419 set i
[reg_instance
$fd]
420 set viewinstances
($view) [list
$i]
421 set viewmainheadid
($view) $mainheadid
422 set viewmainheadid_orig
($view) $mainheadid
423 if {$files ne
{} && $mainheadid ne
{}} {
424 get_viewmainhead
$view
426 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
427 interestedin
$viewmainheadid($view) dodiffindex
429 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
430 if {$tclencoding != {}} {
431 fconfigure
$fd -encoding $tclencoding
433 filerun
$fd [list getcommitlines
$fd $i $view 0]
434 nowbusy
$view [mc
"Reading"]
435 set viewcomplete
($view) 0
436 set viewactive
($view) 1
440 proc stop_instance
{inst
} {
441 global commfd leftover
443 set fd
$commfd($inst)
447 if {$
::tcl_platform
(platform
) eq
{windows
}} {
456 unset leftover
($inst)
459 proc stop_backends
{} {
462 foreach inst
[array names commfd
] {
467 proc stop_rev_list
{view
} {
470 foreach inst
$viewinstances($view) {
473 set viewinstances
($view) {}
476 proc reset_pending_select
{selid
} {
477 global pending_select mainheadid selectheadid
480 set pending_select
$selid
481 } elseif
{$selectheadid ne
{}} {
482 set pending_select
$selectheadid
484 set pending_select
$mainheadid
488 proc getcommits
{selid
} {
489 global canv curview need_redisplay viewactive
492 if {[start_rev_list
$curview]} {
493 reset_pending_select
$selid
494 show_status
[mc
"Reading commits..."]
497 show_status
[mc
"No commits selected"]
501 proc updatecommits
{} {
502 global curview vcanopt vorigargs vfilelimit viewinstances
503 global viewactive viewcomplete tclencoding
504 global startmsecs showneartags showlocalchanges
505 global mainheadid viewmainheadid viewmainheadid_orig pending_select
507 global varcid vposids vnegids vflags vrevs
510 set hasworktree
[hasworktree
]
513 if {$mainheadid ne
$viewmainheadid_orig($view)} {
514 if {$showlocalchanges} {
517 set viewmainheadid
($view) $mainheadid
518 set viewmainheadid_orig
($view) $mainheadid
519 if {$vfilelimit($view) ne
{}} {
520 get_viewmainhead
$view
523 if {$showlocalchanges} {
526 if {$vcanopt($view)} {
527 set oldpos
$vposids($view)
528 set oldneg
$vnegids($view)
529 set revs
[parseviewrevs
$view $vrevs($view)]
533 # note: getting the delta when negative refs change is hard,
534 # and could require multiple git log invocations, so in that
535 # case we ask git log for all the commits (not just the delta)
536 if {$oldneg eq
$vnegids($view)} {
539 # take out positive refs that we asked for before or
540 # that we have already seen
542 if {[string length
$rev] == 40} {
543 if {[lsearch
-exact $oldpos $rev] < 0
544 && ![info exists varcid
($view,$rev)]} {
549 lappend
$newrevs $rev
552 if {$npos == 0} return
554 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
556 set args
[concat
$vflags($view) $revs --not $oldpos]
558 set args
$vorigargs($view)
561 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
562 --parents --boundary $args "--" $vfilelimit($view)] r
]
564 error_popup
"[mc "Error executing git log
:"] $err"
567 if {$viewactive($view) == 0} {
568 set startmsecs
[clock clicks
-milliseconds]
570 set i
[reg_instance
$fd]
571 lappend viewinstances
($view) $i
572 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
573 if {$tclencoding != {}} {
574 fconfigure
$fd -encoding $tclencoding
576 filerun
$fd [list getcommitlines
$fd $i $view 1]
577 incr viewactive
($view)
578 set viewcomplete
($view) 0
579 reset_pending_select
{}
580 nowbusy
$view [mc
"Reading"]
586 proc reloadcommits
{} {
587 global curview viewcomplete selectedline currentid thickerline
588 global showneartags treediffs commitinterest cached_commitrow
592 if {$selectedline ne
{}} {
596 if {!$viewcomplete($curview)} {
597 stop_rev_list
$curview
601 catch
{unset currentid
}
602 catch
{unset thickerline
}
603 catch
{unset treediffs
}
610 catch
{unset commitinterest
}
611 catch
{unset cached_commitrow
}
612 catch
{unset targetid
}
618 # This makes a string representation of a positive integer which
619 # sorts as a string in numerical order
622 return [format
"%x" $n]
623 } elseif
{$n < 256} {
624 return [format
"x%.2x" $n]
625 } elseif
{$n < 65536} {
626 return [format
"y%.4x" $n]
628 return [format
"z%.8x" $n]
631 # Procedures used in reordering commits from git log (without
632 # --topo-order) into the order for display.
634 proc varcinit
{view
} {
635 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
636 global vtokmod varcmod vrowmod varcix vlastins
638 set varcstart
($view) {{}}
639 set vupptr
($view) {0}
640 set vdownptr
($view) {0}
641 set vleftptr
($view) {0}
642 set vbackptr
($view) {0}
643 set varctok
($view) {{}}
644 set varcrow
($view) {{}}
645 set vtokmod
($view) {}
648 set varcix
($view) {{}}
649 set vlastins
($view) {0}
652 proc resetvarcs
{view
} {
653 global varcid varccommits parents children vseedcount ordertok
656 foreach vid
[array names varcid
$view,*] {
661 foreach vid
[array names vshortids
$view,*] {
662 unset vshortids
($vid)
664 # some commits might have children but haven't been seen yet
665 foreach vid
[array names children
$view,*] {
668 foreach va
[array names varccommits
$view,*] {
669 unset varccommits
($va)
671 foreach vd
[array names vseedcount
$view,*] {
672 unset vseedcount
($vd)
674 catch
{unset ordertok
}
677 # returns a list of the commits with no children
679 global vdownptr vleftptr varcstart
682 set a
[lindex
$vdownptr($v) 0]
684 lappend ret
[lindex
$varcstart($v) $a]
685 set a
[lindex
$vleftptr($v) $a]
690 proc newvarc
{view id
} {
691 global varcid varctok parents children vdatemode
692 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
693 global commitdata commitinfo vseedcount varccommits vlastins
695 set a
[llength
$varctok($view)]
697 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
698 if {![info exists commitinfo
($id)]} {
699 parsecommit
$id $commitdata($id) 1
701 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
702 if {![string is integer
-strict $cdate]} {
705 if {![info exists vseedcount
($view,$cdate)]} {
706 set vseedcount
($view,$cdate) -1
708 set c
[incr vseedcount
($view,$cdate)]
709 set cdate
[expr {$cdate ^
0xffffffff}]
710 set tok
"s[strrep $cdate][strrep $c]"
715 if {[llength
$children($vid)] > 0} {
716 set kid
[lindex
$children($vid) end
]
717 set k
$varcid($view,$kid)
718 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
721 set tok
[lindex
$varctok($view) $k]
725 set i
[lsearch
-exact $parents($view,$ki) $id]
726 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
727 append tok
[strrep
$j]
729 set c
[lindex
$vlastins($view) $ka]
730 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
732 set b
[lindex
$vdownptr($view) $ka]
734 set b
[lindex
$vleftptr($view) $c]
736 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
738 set b
[lindex
$vleftptr($view) $c]
741 lset vdownptr
($view) $ka $a
742 lappend vbackptr
($view) 0
744 lset vleftptr
($view) $c $a
745 lappend vbackptr
($view) $c
747 lset vlastins
($view) $ka $a
748 lappend vupptr
($view) $ka
749 lappend vleftptr
($view) $b
751 lset vbackptr
($view) $b $a
753 lappend varctok
($view) $tok
754 lappend varcstart
($view) $id
755 lappend vdownptr
($view) 0
756 lappend varcrow
($view) {}
757 lappend varcix
($view) {}
758 set varccommits
($view,$a) {}
759 lappend vlastins
($view) 0
763 proc splitvarc
{p v
} {
764 global varcid varcstart varccommits varctok vtokmod
765 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
767 set oa
$varcid($v,$p)
768 set otok
[lindex
$varctok($v) $oa]
769 set ac
$varccommits($v,$oa)
770 set i
[lsearch
-exact $varccommits($v,$oa) $p]
772 set na
[llength
$varctok($v)]
773 # "%" sorts before "0"...
774 set tok
"$otok%[strrep $i]"
775 lappend varctok
($v) $tok
776 lappend varcrow
($v) {}
777 lappend varcix
($v) {}
778 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
779 set varccommits
($v,$na) [lrange
$ac $i end
]
780 lappend varcstart
($v) $p
781 foreach id
$varccommits($v,$na) {
782 set varcid
($v,$id) $na
784 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
785 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
786 lset vdownptr
($v) $oa $na
787 lset vlastins
($v) $oa 0
788 lappend vupptr
($v) $oa
789 lappend vleftptr
($v) 0
790 lappend vbackptr
($v) 0
791 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
792 lset vupptr
($v) $b $na
794 if {[string compare
$otok $vtokmod($v)] <= 0} {
799 proc renumbervarc
{a v
} {
800 global parents children varctok varcstart varccommits
801 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
803 set t1
[clock clicks
-milliseconds]
809 if {[info exists isrelated
($a)]} {
811 set id
[lindex
$varccommits($v,$a) end
]
812 foreach p
$parents($v,$id) {
813 if {[info exists varcid
($v,$p)]} {
814 set isrelated
($varcid($v,$p)) 1
819 set b
[lindex
$vdownptr($v) $a]
822 set b
[lindex
$vleftptr($v) $a]
824 set a
[lindex
$vupptr($v) $a]
830 if {![info exists kidchanged
($a)]} continue
831 set id
[lindex
$varcstart($v) $a]
832 if {[llength
$children($v,$id)] > 1} {
833 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
836 set oldtok
[lindex
$varctok($v) $a]
837 if {!$vdatemode($v)} {
843 set kid
[last_real_child
$v,$id]
845 set k
$varcid($v,$kid)
846 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
849 set tok
[lindex
$varctok($v) $k]
853 set i
[lsearch
-exact $parents($v,$ki) $id]
854 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
855 append tok
[strrep
$j]
857 if {$tok eq
$oldtok} {
860 set id
[lindex
$varccommits($v,$a) end
]
861 foreach p
$parents($v,$id) {
862 if {[info exists varcid
($v,$p)]} {
863 set kidchanged
($varcid($v,$p)) 1
868 lset varctok
($v) $a $tok
869 set b
[lindex
$vupptr($v) $a]
871 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
874 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
877 set c
[lindex
$vbackptr($v) $a]
878 set d
[lindex
$vleftptr($v) $a]
880 lset vdownptr
($v) $b $d
882 lset vleftptr
($v) $c $d
885 lset vbackptr
($v) $d $c
887 if {[lindex
$vlastins($v) $b] == $a} {
888 lset vlastins
($v) $b $c
890 lset vupptr
($v) $a $ka
891 set c
[lindex
$vlastins($v) $ka]
893 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
895 set b
[lindex
$vdownptr($v) $ka]
897 set b
[lindex
$vleftptr($v) $c]
900 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
902 set b
[lindex
$vleftptr($v) $c]
905 lset vdownptr
($v) $ka $a
906 lset vbackptr
($v) $a 0
908 lset vleftptr
($v) $c $a
909 lset vbackptr
($v) $a $c
911 lset vleftptr
($v) $a $b
913 lset vbackptr
($v) $b $a
915 lset vlastins
($v) $ka $a
918 foreach id
[array names sortkids
] {
919 if {[llength
$children($v,$id)] > 1} {
920 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
924 set t2
[clock clicks
-milliseconds]
925 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
928 # Fix up the graph after we have found out that in view $v,
929 # $p (a commit that we have already seen) is actually the parent
930 # of the last commit in arc $a.
931 proc fix_reversal
{p a v
} {
932 global varcid varcstart varctok vupptr
934 set pa
$varcid($v,$p)
935 if {$p ne
[lindex
$varcstart($v) $pa]} {
937 set pa
$varcid($v,$p)
939 # seeds always need to be renumbered
940 if {[lindex
$vupptr($v) $pa] == 0 ||
941 [string compare
[lindex
$varctok($v) $a] \
942 [lindex
$varctok($v) $pa]] > 0} {
947 proc insertrow
{id p v
} {
948 global cmitlisted children parents varcid varctok vtokmod
949 global varccommits ordertok commitidx numcommits curview
950 global targetid targetrow vshortids
954 set cmitlisted
($vid) 1
955 set children
($vid) {}
956 set parents
($vid) [list
$p]
957 set a
[newvarc
$v $id]
959 lappend vshortids
($v,[string range
$id 0 3]) $id
960 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
963 lappend varccommits
($v,$a) $id
965 if {[llength
[lappend children
($vp) $id]] > 1} {
966 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
967 catch
{unset ordertok
}
969 fix_reversal
$p $a $v
971 if {$v == $curview} {
972 set numcommits
$commitidx($v)
974 if {[info exists targetid
]} {
975 if {![comes_before
$targetid $p]} {
982 proc insertfakerow
{id p
} {
983 global varcid varccommits parents children cmitlisted
984 global commitidx varctok vtokmod targetid targetrow curview numcommits
988 set i
[lsearch
-exact $varccommits($v,$a) $p]
990 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
993 set children
($v,$id) {}
994 set parents
($v,$id) [list
$p]
995 set varcid
($v,$id) $a
996 lappend children
($v,$p) $id
997 set cmitlisted
($v,$id) 1
998 set numcommits
[incr commitidx
($v)]
999 # note we deliberately don't update varcstart($v) even if $i == 0
1000 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
1002 if {[info exists targetid
]} {
1003 if {![comes_before
$targetid $p]} {
1011 proc removefakerow
{id
} {
1012 global varcid varccommits parents children commitidx
1013 global varctok vtokmod cmitlisted currentid selectedline
1014 global targetid curview numcommits
1017 if {[llength
$parents($v,$id)] != 1} {
1018 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1021 set p
[lindex
$parents($v,$id) 0]
1022 set a
$varcid($v,$id)
1023 set i
[lsearch
-exact $varccommits($v,$a) $id]
1025 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1028 unset varcid
($v,$id)
1029 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1030 unset parents
($v,$id)
1031 unset children
($v,$id)
1032 unset cmitlisted
($v,$id)
1033 set numcommits
[incr commitidx
($v) -1]
1034 set j
[lsearch
-exact $children($v,$p) $id]
1036 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1039 if {[info exist currentid
] && $id eq
$currentid} {
1043 if {[info exists targetid
] && $targetid eq
$id} {
1050 proc real_children
{vp
} {
1051 global children nullid nullid2
1054 foreach id
$children($vp) {
1055 if {$id ne
$nullid && $id ne
$nullid2} {
1062 proc first_real_child
{vp
} {
1063 global children nullid nullid2
1065 foreach id
$children($vp) {
1066 if {$id ne
$nullid && $id ne
$nullid2} {
1073 proc last_real_child
{vp
} {
1074 global children nullid nullid2
1076 set kids
$children($vp)
1077 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1078 set id
[lindex
$kids $i]
1079 if {$id ne
$nullid && $id ne
$nullid2} {
1086 proc vtokcmp
{v a b
} {
1087 global varctok varcid
1089 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1090 [lindex
$varctok($v) $varcid($v,$b)]]
1093 # This assumes that if lim is not given, the caller has checked that
1094 # arc a's token is less than $vtokmod($v)
1095 proc modify_arc
{v a
{lim
{}}} {
1096 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1099 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1102 set r
[lindex
$varcrow($v) $a]
1103 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1106 set vtokmod
($v) [lindex
$varctok($v) $a]
1108 if {$v == $curview} {
1109 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1110 set a
[lindex
$vupptr($v) $a]
1116 set lim
[llength
$varccommits($v,$a)]
1118 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1125 proc update_arcrows
{v
} {
1126 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1127 global varcid vrownum varcorder varcix varccommits
1128 global vupptr vdownptr vleftptr varctok
1129 global displayorder parentlist curview cached_commitrow
1131 if {$vrowmod($v) == $commitidx($v)} return
1132 if {$v == $curview} {
1133 if {[llength
$displayorder] > $vrowmod($v)} {
1134 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1135 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1137 catch
{unset cached_commitrow
}
1139 set narctot
[expr {[llength
$varctok($v)] - 1}]
1141 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1142 # go up the tree until we find something that has a row number,
1143 # or we get to a seed
1144 set a
[lindex
$vupptr($v) $a]
1147 set a
[lindex
$vdownptr($v) 0]
1150 set varcorder
($v) [list
$a]
1151 lset varcix
($v) $a 0
1152 lset varcrow
($v) $a 0
1156 set arcn
[lindex
$varcix($v) $a]
1157 if {[llength
$vrownum($v)] > $arcn + 1} {
1158 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1159 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1161 set row
[lindex
$varcrow($v) $a]
1165 incr row
[llength
$varccommits($v,$a)]
1166 # go down if possible
1167 set b
[lindex
$vdownptr($v) $a]
1169 # if not, go left, or go up until we can go left
1171 set b
[lindex
$vleftptr($v) $a]
1173 set a
[lindex
$vupptr($v) $a]
1179 lappend vrownum
($v) $row
1180 lappend varcorder
($v) $a
1181 lset varcix
($v) $a $arcn
1182 lset varcrow
($v) $a $row
1184 set vtokmod
($v) [lindex
$varctok($v) $p]
1186 set vrowmod
($v) $row
1187 if {[info exists currentid
]} {
1188 set selectedline
[rowofcommit
$currentid]
1192 # Test whether view $v contains commit $id
1193 proc commitinview
{id v
} {
1196 return [info exists varcid
($v,$id)]
1199 # Return the row number for commit $id in the current view
1200 proc rowofcommit
{id
} {
1201 global varcid varccommits varcrow curview cached_commitrow
1202 global varctok vtokmod
1205 if {![info exists varcid
($v,$id)]} {
1206 puts
"oops rowofcommit no arc for [shortids $id]"
1209 set a
$varcid($v,$id)
1210 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1213 if {[info exists cached_commitrow
($id)]} {
1214 return $cached_commitrow($id)
1216 set i
[lsearch
-exact $varccommits($v,$a) $id]
1218 puts
"oops didn't find commit [shortids $id] in arc $a"
1221 incr i
[lindex
$varcrow($v) $a]
1222 set cached_commitrow
($id) $i
1226 # Returns 1 if a is on an earlier row than b, otherwise 0
1227 proc comes_before
{a b
} {
1228 global varcid varctok curview
1231 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1232 ![info exists varcid
($v,$b)]} {
1235 if {$varcid($v,$a) != $varcid($v,$b)} {
1236 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1237 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1239 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1242 proc bsearch
{l elt
} {
1243 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1248 while {$hi - $lo > 1} {
1249 set mid
[expr {int
(($lo + $hi) / 2)}]
1250 set t
[lindex
$l $mid]
1253 } elseif
{$elt > $t} {
1262 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1263 proc make_disporder
{start end
} {
1264 global vrownum curview commitidx displayorder parentlist
1265 global varccommits varcorder parents vrowmod varcrow
1266 global d_valid_start d_valid_end
1268 if {$end > $vrowmod($curview)} {
1269 update_arcrows
$curview
1271 set ai
[bsearch
$vrownum($curview) $start]
1272 set start
[lindex
$vrownum($curview) $ai]
1273 set narc
[llength
$vrownum($curview)]
1274 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1275 set a
[lindex
$varcorder($curview) $ai]
1276 set l
[llength
$displayorder]
1277 set al
[llength
$varccommits($curview,$a)]
1278 if {$l < $r + $al} {
1280 set pad
[ntimes
[expr {$r - $l}] {}]
1281 set displayorder
[concat
$displayorder $pad]
1282 set parentlist
[concat
$parentlist $pad]
1283 } elseif
{$l > $r} {
1284 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1285 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1287 foreach id
$varccommits($curview,$a) {
1288 lappend displayorder
$id
1289 lappend parentlist
$parents($curview,$id)
1291 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1293 foreach id
$varccommits($curview,$a) {
1294 lset displayorder
$i $id
1295 lset parentlist
$i $parents($curview,$id)
1303 proc commitonrow
{row
} {
1306 set id
[lindex
$displayorder $row]
1308 make_disporder
$row [expr {$row + 1}]
1309 set id
[lindex
$displayorder $row]
1314 proc closevarcs
{v
} {
1315 global varctok varccommits varcid parents children
1316 global cmitlisted commitidx vtokmod
1318 set missing_parents
0
1320 set narcs
[llength
$varctok($v)]
1321 for {set a
1} {$a < $narcs} {incr a
} {
1322 set id
[lindex
$varccommits($v,$a) end
]
1323 foreach p
$parents($v,$id) {
1324 if {[info exists varcid
($v,$p)]} continue
1325 # add p as a new commit
1326 incr missing_parents
1327 set cmitlisted
($v,$p) 0
1328 set parents
($v,$p) {}
1329 if {[llength
$children($v,$p)] == 1 &&
1330 [llength
$parents($v,$id)] == 1} {
1333 set b
[newvarc
$v $p]
1335 set varcid
($v,$p) $b
1336 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1339 lappend varccommits
($v,$b) $p
1341 set scripts
[check_interest
$p $scripts]
1344 if {$missing_parents > 0} {
1345 foreach s
$scripts {
1351 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1352 # Assumes we already have an arc for $rwid.
1353 proc rewrite_commit
{v id rwid
} {
1354 global children parents varcid varctok vtokmod varccommits
1356 foreach ch
$children($v,$id) {
1357 # make $rwid be $ch's parent in place of $id
1358 set i
[lsearch
-exact $parents($v,$ch) $id]
1360 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1362 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1363 # add $ch to $rwid's children and sort the list if necessary
1364 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1365 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1366 $children($v,$rwid)]
1368 # fix the graph after joining $id to $rwid
1369 set a
$varcid($v,$ch)
1370 fix_reversal
$rwid $a $v
1371 # parentlist is wrong for the last element of arc $a
1372 # even if displayorder is right, hence the 3rd arg here
1373 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1377 # Mechanism for registering a command to be executed when we come
1378 # across a particular commit. To handle the case when only the
1379 # prefix of the commit is known, the commitinterest array is now
1380 # indexed by the first 4 characters of the ID. Each element is a
1381 # list of id, cmd pairs.
1382 proc interestedin
{id cmd
} {
1383 global commitinterest
1385 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1388 proc check_interest
{id scripts
} {
1389 global commitinterest
1391 set prefix
[string range
$id 0 3]
1392 if {[info exists commitinterest
($prefix)]} {
1394 foreach
{i
script} $commitinterest($prefix) {
1395 if {[string match
"$i*" $id]} {
1396 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1398 lappend newlist
$i $script
1401 if {$newlist ne
{}} {
1402 set commitinterest
($prefix) $newlist
1404 unset commitinterest
($prefix)
1410 proc getcommitlines
{fd inst view updating
} {
1411 global cmitlisted leftover
1412 global commitidx commitdata vdatemode
1413 global parents children curview hlview
1414 global idpending ordertok
1415 global varccommits varcid varctok vtokmod vfilelimit vshortids
1417 set stuff
[read $fd 500000]
1418 # git log doesn't terminate the last commit with a null...
1419 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1426 global commfd viewcomplete viewactive viewname
1427 global viewinstances
1429 set i
[lsearch
-exact $viewinstances($view) $inst]
1431 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1433 # set it blocking so we wait for the process to terminate
1434 fconfigure
$fd -blocking 1
1435 if {[catch
{close
$fd} err
]} {
1437 if {$view != $curview} {
1438 set fv
" for the \"$viewname($view)\" view"
1440 if {[string range
$err 0 4] == "usage"} {
1441 set err
"Gitk: error reading commits$fv:\
1442 bad arguments to git log."
1443 if {$viewname($view) eq
"Command line"} {
1445 " (Note: arguments to gitk are passed to git log\
1446 to allow selection of commits to be displayed.)"
1449 set err
"Error reading commits$fv: $err"
1453 if {[incr viewactive
($view) -1] <= 0} {
1454 set viewcomplete
($view) 1
1455 # Check if we have seen any ids listed as parents that haven't
1456 # appeared in the list
1460 if {$view == $curview} {
1469 set i
[string first
"\0" $stuff $start]
1471 append leftover
($inst) [string range
$stuff $start end
]
1475 set cmit
$leftover($inst)
1476 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1477 set leftover
($inst) {}
1479 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1481 set start
[expr {$i + 1}]
1482 set j
[string first
"\n" $cmit]
1485 if {$j >= 0 && [string match
"commit *" $cmit]} {
1486 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1487 if {[string match
{[-^
<>]*} $ids]} {
1488 switch
-- [string index
$ids 0] {
1494 set ids
[string range
$ids 1 end
]
1498 if {[string length
$id] != 40} {
1506 if {[string length
$shortcmit] > 80} {
1507 set shortcmit
"[string range $shortcmit 0 80]..."
1509 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1512 set id [lindex $ids 0]
1515 lappend vshortids($view,[string range $id 0 3]) $id
1517 if {!$listed && $updating && ![info exists varcid($vid)] &&
1518 $vfilelimit($view) ne {}} {
1519 # git log doesn't rewrite parents
for unlisted commits
1520 # when doing path limiting, so work around that here
1521 # by working out the rewritten parent with git rev-list
1522 # and if we already know about it, using the rewritten
1523 # parent as a substitute parent for $id's children.
1525 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1526 $id -- $vfilelimit($view)]
1528 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1529 # use $rwid in place of $id
1530 rewrite_commit
$view $id $rwid
1537 if {[info exists varcid
($vid)]} {
1538 if {$cmitlisted($vid) ||
!$listed} continue
1542 set olds
[lrange
$ids 1 end
]
1546 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1547 set cmitlisted
($vid) $listed
1548 set parents
($vid) $olds
1549 if {![info exists children
($vid)]} {
1550 set children
($vid) {}
1551 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1552 set k
[lindex
$children($vid) 0]
1553 if {[llength
$parents($view,$k)] == 1 &&
1554 (!$vdatemode($view) ||
1555 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1556 set a
$varcid($view,$k)
1561 set a
[newvarc
$view $id]
1563 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1566 if {![info exists varcid
($vid)]} {
1568 lappend varccommits
($view,$a) $id
1569 incr commitidx
($view)
1574 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1576 if {[llength
[lappend children
($vp) $id]] > 1 &&
1577 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1578 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1580 catch
{unset ordertok
}
1582 if {[info exists varcid
($view,$p)]} {
1583 fix_reversal
$p $a $view
1589 set scripts
[check_interest
$id $scripts]
1593 global numcommits hlview
1595 if {$view == $curview} {
1596 set numcommits
$commitidx($view)
1599 if {[info exists hlview
] && $view == $hlview} {
1600 # we never actually get here...
1603 foreach s
$scripts {
1610 proc chewcommits
{} {
1611 global curview hlview viewcomplete
1612 global pending_select
1615 if {$viewcomplete($curview)} {
1616 global commitidx varctok
1617 global numcommits startmsecs
1619 if {[info exists pending_select
]} {
1621 reset_pending_select
{}
1623 if {[commitinview
$pending_select $curview]} {
1624 selectline
[rowofcommit
$pending_select] 1
1626 set row
[first_real_row
]
1630 if {$commitidx($curview) > 0} {
1631 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1632 #puts "overall $ms ms for $numcommits commits"
1633 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1635 show_status
[mc
"No commits selected"]
1642 proc do_readcommit
{id
} {
1645 # Invoke git-log to handle automatic encoding conversion
1646 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1647 # Read the results using i18n.logoutputencoding
1648 fconfigure
$fd -translation lf
-eofchar {}
1649 if {$tclencoding != {}} {
1650 fconfigure
$fd -encoding $tclencoding
1652 set contents
[read $fd]
1654 # Remove the heading line
1655 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1660 proc readcommit
{id
} {
1661 if {[catch
{set contents
[do_readcommit
$id]}]} return
1662 parsecommit
$id $contents 1
1665 proc parsecommit
{id contents listed
} {
1675 set hdrend
[string first
"\n\n" $contents]
1677 # should never happen...
1678 set hdrend
[string length
$contents]
1680 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1681 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1682 foreach line
[split $header "\n"] {
1683 set line
[split $line " "]
1684 set tag
[lindex
$line 0]
1685 if {$tag == "author"} {
1686 set audate
[lrange
$line end-1 end
]
1687 set auname
[join [lrange
$line 1 end-2
] " "]
1688 } elseif
{$tag == "committer"} {
1689 set comdate
[lrange
$line end-1 end
]
1690 set comname
[join [lrange
$line 1 end-2
] " "]
1694 # take the first non-blank line of the comment as the headline
1695 set headline
[string trimleft
$comment]
1696 set i
[string first
"\n" $headline]
1698 set headline
[string range
$headline 0 $i]
1700 set headline
[string trimright
$headline]
1701 set i
[string first
"\r" $headline]
1703 set headline
[string trimright
[string range
$headline 0 $i]]
1706 # git log indents the comment by 4 spaces;
1707 # if we got this via git cat-file, add the indentation
1709 foreach line
[split $comment "\n"] {
1710 append newcomment
" "
1711 append newcomment
$line
1712 append newcomment
"\n"
1714 set comment
$newcomment
1716 set hasnote
[string first
"\nNotes:\n" $contents]
1718 # If there is diff output shown in the git-log stream, split it
1719 # out. But get rid of the empty line that always precedes the
1721 set i
[string first
"\n\ndiff" $comment]
1723 set diff [string range
$comment $i+1 end
]
1724 set comment
[string range
$comment 0 $i-1]
1726 set commitinfo
($id) [list
$headline $auname $audate \
1727 $comname $comdate $comment $hasnote $diff]
1730 proc getcommit
{id
} {
1731 global commitdata commitinfo
1733 if {[info exists commitdata
($id)]} {
1734 parsecommit
$id $commitdata($id) 1
1737 if {![info exists commitinfo
($id)]} {
1738 set commitinfo
($id) [list
[mc
"No commit information available"]]
1744 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1745 # and are present in the current view.
1746 # This is fairly slow...
1747 proc longid
{prefix
} {
1748 global varcid curview vshortids
1751 if {[string length
$prefix] >= 4} {
1752 set vshortid
$curview,[string range
$prefix 0 3]
1753 if {[info exists vshortids
($vshortid)]} {
1754 foreach id
$vshortids($vshortid) {
1755 if {[string match
"$prefix*" $id]} {
1756 if {[lsearch
-exact $ids $id] < 0} {
1758 if {[llength
$ids] >= 2} break
1764 foreach match
[array names varcid
"$curview,$prefix*"] {
1765 lappend ids
[lindex
[split $match ","] 1]
1766 if {[llength
$ids] >= 2} break
1773 global tagids idtags headids idheads tagobjid
1774 global otherrefids idotherrefs mainhead mainheadid
1775 global selecthead selectheadid
1778 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1781 set refd
[open
[list | git show-ref
-d] r
]
1782 while {[gets
$refd line
] >= 0} {
1783 if {[string index
$line 40] ne
" "} continue
1784 set id
[string range
$line 0 39]
1785 set ref
[string range
$line 41 end
]
1786 if {![string match
"refs/*" $ref]} continue
1787 set name
[string range
$ref 5 end
]
1788 if {[string match
"remotes/*" $name]} {
1789 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1790 set headids
($name) $id
1791 lappend idheads
($id) $name
1793 } elseif
{[string match
"heads/*" $name]} {
1794 set name
[string range
$name 6 end
]
1795 set headids
($name) $id
1796 lappend idheads
($id) $name
1797 } elseif
{[string match
"tags/*" $name]} {
1798 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1799 # which is what we want since the former is the commit ID
1800 set name
[string range
$name 5 end
]
1801 if {[string match
"*^{}" $name]} {
1802 set name
[string range
$name 0 end-3
]
1804 set tagobjid
($name) $id
1806 set tagids
($name) $id
1807 lappend idtags
($id) $name
1809 set otherrefids
($name) $id
1810 lappend idotherrefs
($id) $name
1817 set mainheadid
[exec git rev-parse HEAD
]
1818 set thehead
[exec git symbolic-ref HEAD
]
1819 if {[string match
"refs/heads/*" $thehead]} {
1820 set mainhead
[string range
$thehead 11 end
]
1824 if {$selecthead ne
{}} {
1826 set selectheadid
[exec git rev-parse
--verify $selecthead]
1831 # skip over fake commits
1832 proc first_real_row
{} {
1833 global nullid nullid2 numcommits
1835 for {set row
0} {$row < $numcommits} {incr row
} {
1836 set id
[commitonrow
$row]
1837 if {$id ne
$nullid && $id ne
$nullid2} {
1844 # update things for a head moved to a child of its previous location
1845 proc movehead
{id name
} {
1846 global headids idheads
1848 removehead
$headids($name) $name
1849 set headids
($name) $id
1850 lappend idheads
($id) $name
1853 # update things when a head has been removed
1854 proc removehead
{id name
} {
1855 global headids idheads
1857 if {$idheads($id) eq
$name} {
1860 set i
[lsearch
-exact $idheads($id) $name]
1862 set idheads
($id) [lreplace
$idheads($id) $i $i]
1865 unset headids
($name)
1868 proc ttk_toplevel
{w args
} {
1870 eval [linsert
$args 0 ::toplevel
$w]
1872 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1877 proc make_transient
{window origin
} {
1880 # In MacOS Tk 8.4 transient appears to work by setting
1881 # overrideredirect, which is utterly useless, since the
1882 # windows get no border, and are not even kept above
1884 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1886 wm transient
$window $origin
1888 # Windows fails to place transient windows normally, so
1889 # schedule a callback to center them on the parent.
1890 if {[tk windowingsystem
] eq
{win32
}} {
1891 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1895 proc show_error
{w top msg
{mc mc
}} {
1897 if {![info exists NS
]} {set NS
""}
1898 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1899 message
$w.m
-text $msg -justify center
-aspect 400
1900 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1901 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1902 pack
$w.ok
-side bottom
-fill x
1903 bind $top <Visibility
> "grab $top; focus $top"
1904 bind $top <Key-Return
> "destroy $top"
1905 bind $top <Key-space
> "destroy $top"
1906 bind $top <Key-Escape
> "destroy $top"
1910 proc error_popup
{msg
{owner .
}} {
1911 if {[tk windowingsystem
] eq
"win32"} {
1912 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1913 -parent $owner -message $msg
1917 make_transient
$w $owner
1918 show_error
$w $w $msg
1922 proc confirm_popup
{msg
{owner .
}} {
1923 global confirm_ok NS
1927 make_transient
$w $owner
1928 message
$w.m
-text $msg -justify center
-aspect 400
1929 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1930 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1931 pack
$w.ok
-side left
-fill x
1932 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1933 pack
$w.cancel
-side right
-fill x
1934 bind $w <Visibility
> "grab $w; focus $w"
1935 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1936 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1937 bind $w <Key-Escape
> "destroy $w"
1938 tk
::PlaceWindow
$w widget
$owner
1943 proc setoptions
{} {
1944 if {[tk windowingsystem
] ne
"win32"} {
1945 option add
*Panedwindow.showHandle
1 startupFile
1946 option add
*Panedwindow.sashRelief raised startupFile
1947 if {[tk windowingsystem
] ne
"aqua"} {
1948 option add
*Menu.font uifont startupFile
1951 option add
*Menu.TearOff
0 startupFile
1953 option add
*Button.font uifont startupFile
1954 option add
*Checkbutton.font uifont startupFile
1955 option add
*Radiobutton.font uifont startupFile
1956 option add
*Menubutton.font uifont startupFile
1957 option add
*Label.font uifont startupFile
1958 option add
*Message.font uifont startupFile
1959 option add
*Entry.font textfont startupFile
1960 option add
*Text.font textfont startupFile
1961 option add
*Labelframe.font uifont startupFile
1962 option add
*Spinbox.font textfont startupFile
1963 option add
*Listbox.font mainfont startupFile
1966 # Make a menu and submenus.
1967 # m is the window name for the menu, items is the list of menu items to add.
1968 # Each item is a list {mc label type description options...}
1969 # mc is ignored; it's so we can put mc there to alert xgettext
1970 # label is the string that appears in the menu
1971 # type is cascade, command or radiobutton (should add checkbutton)
1972 # description depends on type; it's the sublist for cascade, the
1973 # command to invoke for command, or {variable value} for radiobutton
1974 proc makemenu
{m items
} {
1976 if {[tk windowingsystem
] eq
{aqua
}} {
1982 set name
[mc
[lindex
$i 1]]
1983 set type [lindex
$i 2]
1984 set thing
[lindex
$i 3]
1985 set params
[list
$type]
1987 set u
[string first
"&" [string map
{&& x
} $name]]
1988 lappend params
-label [string map
{&& & & {}} $name]
1990 lappend params
-underline $u
1995 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1996 lappend params
-menu $m.
$submenu
1999 lappend params
-command $thing
2002 lappend params
-variable [lindex
$thing 0] \
2003 -value [lindex
$thing 1]
2006 set tail [lrange
$i 4 end
]
2007 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2008 eval $m add
$params $tail
2009 if {$type eq
"cascade"} {
2010 makemenu
$m.
$submenu $thing
2015 # translate string and remove ampersands
2017 return [string map
{&& & & {}} [mc
$str]]
2020 proc cleardropsel
{w
} {
2023 proc makedroplist
{w varname args
} {
2027 foreach label
$args {
2028 set cx
[string length
$label]
2029 if {$cx > $width} {set width
$cx}
2031 set gm
[ttk
::combobox
$w -width $width -state readonly\
2032 -textvariable $varname -values $args \
2033 -exportselection false
]
2034 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2036 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2041 proc makewindow {} {
2042 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2044 global findtype findtypemenu findloc findstring fstring geometry
2045 global entries sha1entry sha1string sha1but
2046 global diffcontextstring diffcontext
2048 global maincursor textcursor curtextcursor
2049 global rowctxmenu fakerowmenu mergemax wrapcomment
2050 global highlight_files gdttype
2051 global searchstring sstring
2052 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2053 global uifgcolor uifgdisabledcolor
2054 global filesepbgcolor filesepfgcolor
2055 global mergecolors foundbgcolor currentsearchhitbgcolor
2056 global headctxmenu progresscanv progressitem progresscoords statusw
2057 global fprogitem fprogcoord lastprogupdate progupdatepending
2058 global rprogitem rprogcoord rownumsel numcommits
2059 global have_tk85 use_ttk NS
2063 # The "mc" arguments here are purely so that xgettext
2064 # sees the following string as needing to be translated
2067 {mc "Update" command updatecommits -accelerator F5}
2068 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2069 {mc "Reread references" command rereadrefs}
2070 {mc "List references" command showrefs -accelerator F2}
2072 {mc "Start git gui" command {exec git gui &}}
2074 {mc "Quit" command doquit -accelerator Meta1-Q}
2078 {mc "Preferences" command doprefs}
2082 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2083 {mc "Edit view..." command editview -state disabled -accelerator F4}
2084 {mc "Delete view" command delview -state disabled}
2086 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2088 if {[tk windowingsystem] ne "aqua"} {
2091 {mc "About gitk" command about}
2092 {mc "Key bindings" command keys}
2094 set bar [list $file $edit $view $help]
2096 proc ::tk::mac::ShowPreferences {} {doprefs}
2097 proc ::tk::mac::Quit {} {doquit}
2098 lset file end [lreplace [lindex $file end] end-1 end]
2100 xx "Apple" cascade {
2101 {mc "About gitk" command about}
2106 {mc "Key bindings" command keys}
2108 set bar [list $apple $file $view $help]
2111 . configure -menu .bar
2114 # cover the non-themed toplevel with a themed frame.
2115 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2118 # the gui has upper and lower half, parts of a paned window.
2119 ${NS}::panedwindow .ctop -orient vertical
2121 # possibly use assumed geometry
2122 if {![info exists geometry(pwsash0)]} {
2123 set geometry(topheight) [expr {15 * $linespc}]
2124 set geometry(topwidth) [expr {80 * $charspc}]
2125 set geometry(botheight) [expr {15 * $linespc}]
2126 set geometry(botwidth) [expr {50 * $charspc}]
2127 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2128 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2131 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2132 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2133 ${NS}::frame .tf.histframe
2134 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2136 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2139 # create three canvases
2140 set cscroll .tf.histframe.csb
2141 set canv .tf.histframe.pwclist.canv
2143 -selectbackground $selectbgcolor \
2144 -background $bgcolor -bd 0 \
2145 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2146 .tf.histframe.pwclist add $canv
2147 set canv2 .tf.histframe.pwclist.canv2
2149 -selectbackground $selectbgcolor \
2150 -background $bgcolor -bd 0 -yscrollincr $linespc
2151 .tf.histframe.pwclist add $canv2
2152 set canv3 .tf.histframe.pwclist.canv3
2154 -selectbackground $selectbgcolor \
2155 -background $bgcolor -bd 0 -yscrollincr $linespc
2156 .tf.histframe.pwclist add $canv3
2158 bind .tf.histframe.pwclist <Map> {
2160 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2161 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2164 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2165 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2168 # a scroll bar to rule them
2169 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2170 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2171 pack $cscroll -side right -fill y
2172 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2173 lappend bglist $canv $canv2 $canv3
2174 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2176 # we have two button bars at bottom of top frame. Bar 1
2177 ${NS}::frame .tf.bar
2178 ${NS}::frame .tf.lbar -height 15
2180 set sha1entry .tf.bar.sha1
2181 set entries $sha1entry
2182 set sha1but .tf.bar.sha1label
2183 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2184 -command gotocommit -width 8
2185 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2186 pack .tf.bar.sha1label -side left
2187 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2188 trace add variable sha1string write sha1change
2189 pack $sha1entry -side left -pady 2
2192 #define left_width 16
2193 #define left_height 16
2194 static unsigned char left_bits[] = {
2195 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2196 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2197 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2200 #define right_width 16
2201 #define right_height 16
2202 static unsigned char right_bits[] = {
2203 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2204 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2205 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2207 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2208 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2209 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2210 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2212 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2214 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2216 .tf.bar.leftbut configure -image bm-left
2218 pack .tf.bar.leftbut -side left -fill y
2219 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2221 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2223 .tf.bar.rightbut configure -image bm-right
2225 pack .tf.bar.rightbut -side left -fill y
2227 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2229 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2230 -relief sunken -anchor e
2231 ${NS}::label .tf.bar.rowlabel2 -text "/"
2232 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2233 -relief sunken -anchor e
2234 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2237 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2240 trace add variable selectedline write selectedline_change
2242 # Status label and progress bar
2243 set statusw .tf.bar.status
2244 ${NS}::label $statusw -width 15 -relief sunken
2245 pack $statusw -side left -padx 5
2247 set progresscanv [ttk::progressbar .tf.bar.progress]
2249 set h [expr {[font metrics uifont -linespace] + 2}]
2250 set progresscanv .tf.bar.progress
2251 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2252 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2253 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2254 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2256 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2257 set progresscoords {0 0}
2260 bind $progresscanv <Configure> adjustprogress
2261 set lastprogupdate [clock clicks -milliseconds]
2262 set progupdatepending 0
2264 # build up the bottom bar of upper window
2265 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2268 #define down_width 16
2269 #define down_height 16
2270 static unsigned char down_bits[] = {
2271 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2272 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2273 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2274 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
2276 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2277 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2278 .tf.lbar.fnext configure -image bm-down
2282 #define up_height 16
2283 static unsigned char up_bits[] = {
2284 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2285 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2286 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2287 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
2289 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2290 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2291 .tf.lbar.fprev configure -image bm-up
2293 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2295 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2297 set gdttype [mc "containing:"]
2298 set gm [makedroplist .tf.lbar.gdttype gdttype \
2299 [mc "containing:"] \
2300 [mc "touching paths:"] \
2301 [mc "adding/removing string:"] \
2302 [mc "changing lines matching:"]]
2303 trace add variable gdttype write gdttype_change
2304 pack .tf.lbar.gdttype -side left -fill y
2307 set fstring .tf.lbar.findstring
2308 lappend entries $fstring
2309 ${NS}::entry $fstring -width 30 -textvariable findstring
2310 trace add variable findstring write find_change
2311 set findtype [mc "Exact"]
2312 set findtypemenu [makedroplist .tf.lbar.findtype \
2313 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2314 trace add variable findtype write findcom_change
2315 set findloc [mc "All fields"]
2316 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2317 [mc "Comments"] [mc "Author"] [mc "Committer"]
2318 trace add variable findloc write find_change
2319 pack .tf.lbar.findloc -side right
2320 pack .tf.lbar.findtype -side right
2321 pack $fstring -side left -expand 1 -fill x
2323 # Finish putting the upper half of the viewer together
2324 pack .tf.lbar -in .tf -side bottom -fill x
2325 pack .tf.bar -in .tf -side bottom -fill x
2326 pack .tf.histframe -fill both -side top -expand 1
2329 .ctop paneconfigure .tf -height $geometry(topheight)
2330 .ctop paneconfigure .tf -width $geometry(topwidth)
2333 # now build up the bottom
2334 ${NS}::panedwindow .pwbottom -orient horizontal
2336 # lower left, a text box over search bar, scroll bar to the right
2337 # if we know window height, then that will set the lower text height, otherwise
2338 # we set lower text height which will drive window height
2339 if {[info exists geometry(main)]} {
2340 ${NS}::frame .bleft -width $geometry(botwidth)
2342 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2344 ${NS}::frame .bleft.top
2345 ${NS}::frame .bleft.mid
2346 ${NS}::frame .bleft.bottom
2348 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2349 pack .bleft.top.search -side left -padx 5
2350 set sstring .bleft.top.sstring
2352 ${NS}::entry $sstring -width 20 -textvariable searchstring
2353 lappend entries $sstring
2354 trace add variable searchstring write incrsearch
2355 pack $sstring -side left -expand 1 -fill x
2356 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2357 -command changediffdisp -variable diffelide -value {0 0}
2358 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2359 -command changediffdisp -variable diffelide -value {0 1}
2360 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2361 -command changediffdisp -variable diffelide -value {1 0}
2362 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2363 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2364 spinbox .bleft.mid.diffcontext -width 5 \
2365 -from 0 -increment 1 -to 10000000 \
2366 -validate all -validatecommand "diffcontextvalidate %P" \
2367 -textvariable diffcontextstring
2368 .bleft.mid.diffcontext set $diffcontext
2369 trace add variable diffcontextstring write diffcontextchange
2370 lappend entries .bleft.mid.diffcontext
2371 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2372 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2373 -command changeignorespace -variable ignorespace
2374 pack .bleft.mid.ignspace -side left -padx 5
2376 set worddiff [mc "Line diff"]
2377 if {[package vcompare $git_version "1.7.2"] >= 0} {
2378 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2379 [mc "Markup words"] [mc "Color words"]
2380 trace add variable worddiff write changeworddiff
2381 pack .bleft.mid.worddiff -side left -padx 5
2384 set ctext .bleft.bottom.ctext
2385 text $ctext -background $bgcolor -foreground $fgcolor \
2386 -state disabled -font textfont \
2387 -yscrollcommand scrolltext -wrap none \
2388 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2390 $ctext conf -tabstyle wordprocessor
2392 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2393 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2394 pack .bleft.top -side top -fill x
2395 pack .bleft.mid -side top -fill x
2396 grid $ctext .bleft.bottom.sb -sticky nsew
2397 grid .bleft.bottom.sbhorizontal -sticky ew
2398 grid columnconfigure .bleft.bottom 0 -weight 1
2399 grid rowconfigure .bleft.bottom 0 -weight 1
2400 grid rowconfigure .bleft.bottom 1 -weight 0
2401 pack .bleft.bottom -side top -fill both -expand 1
2402 lappend bglist $ctext
2403 lappend fglist $ctext
2405 $ctext tag conf comment -wrap $wrapcomment
2406 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2407 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2408 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2409 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2410 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2411 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2412 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2413 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2414 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2415 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2416 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2417 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2418 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2419 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2420 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2421 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2422 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2423 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2424 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2425 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2426 $ctext tag conf mmax -fore darkgrey
2428 $ctext tag conf mresult -font textfontbold
2429 $ctext tag conf msep -font textfontbold
2430 $ctext tag conf found -back $foundbgcolor
2431 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2432 $ctext tag conf wwrap -wrap word -lmargin2 1c
2433 $ctext tag conf bold -font textfontbold
2435 .pwbottom add .bleft
2437 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2441 ${NS}::frame .bright
2442 ${NS}::frame .bright.mode
2443 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2444 -command reselectline -variable cmitmode -value "patch"
2445 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2446 -command reselectline -variable cmitmode -value "tree"
2447 grid .bright.mode.patch .bright.mode.tree -sticky ew
2448 pack .bright.mode -side top -fill x
2449 set cflist .bright.cfiles
2450 set indent [font measure mainfont "nn"]
2452 -selectbackground $selectbgcolor \
2453 -background $bgcolor -foreground $fgcolor \
2455 -tabs [list $indent [expr {2 * $indent}]] \
2456 -yscrollcommand ".bright.sb set" \
2457 -cursor [. cget -cursor] \
2458 -spacing1 1 -spacing3 1
2459 lappend bglist $cflist
2460 lappend fglist $cflist
2461 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2462 pack .bright.sb -side right -fill y
2463 pack $cflist -side left -fill both -expand 1
2464 $cflist tag configure highlight \
2465 -background [$cflist cget -selectbackground]
2466 $cflist tag configure bold -font mainfontbold
2468 .pwbottom add .bright
2471 # restore window width & height if known
2472 if {[info exists geometry(main)]} {
2473 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2474 if {$w > [winfo screenwidth .]} {
2475 set w [winfo screenwidth .]
2477 if {$h > [winfo screenheight .]} {
2478 set h [winfo screenheight .]
2480 wm geometry . "${w}x$h"
2484 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2485 wm state . $geometry(state)
2488 if {[tk windowingsystem] eq {aqua}} {
2499 %W sashpos 0 $::geometry(topheight)
2501 bind .pwbottom <Map> {
2503 %W sashpos 0 $::geometry(botwidth)
2507 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2508 pack .ctop -fill both -expand 1
2509 bindall <1> {selcanvline %W %x %y}
2510 #bindall <B1-Motion> {selcanvline %W %x %y}
2511 if {[tk windowingsystem] == "win32"} {
2512 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2513 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2515 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2516 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2517 if {[tk windowingsystem] eq "aqua"} {
2518 bindall <MouseWheel> {
2519 set delta [expr {- (%D)}]
2520 allcanvs yview scroll $delta units
2522 bindall <Shift-MouseWheel> {
2523 set delta [expr {- (%D)}]
2524 $canv xview scroll $delta units
2528 bindall <$::BM> "canvscan mark %W %x %y"
2529 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2530 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2531 bind . <$M1B-Key-w> doquit
2532 bindkey <Home> selfirstline
2533 bindkey <End> sellastline
2534 bind . <Key-Up> "selnextline -1"
2535 bind . <Key-Down> "selnextline 1"
2536 bind . <Shift-Key-Up> "dofind -1 0"
2537 bind . <Shift-Key-Down> "dofind 1 0"
2538 bindkey <Key-Right> "goforw"
2539 bindkey <Key-Left> "goback"
2540 bind . <Key-Prior> "selnextpage -1"
2541 bind . <Key-Next> "selnextpage 1"
2542 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2543 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2544 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2545 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2546 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2547 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2548 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2549 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2550 bindkey <Key-space> "$ctext yview scroll 1 pages"
2551 bindkey p "selnextline -1"
2552 bindkey n "selnextline 1"
2555 bindkey k "selnextline -1"
2556 bindkey j "selnextline 1"
2560 bindkey d "$ctext yview scroll 18 units"
2561 bindkey u "$ctext yview scroll -18 units"
2562 bindkey / {focus $fstring}
2563 bindkey <Key-KP_Divide> {focus $fstring}
2564 bindkey <Key-Return> {dofind 1 1}
2565 bindkey ? {dofind -1 1}
2567 bind . <F5> updatecommits
2568 bindmodfunctionkey Shift 5 reloadcommits
2569 bind . <F2> showrefs
2570 bindmodfunctionkey Shift 4 {newview 0}
2571 bind . <F4> edit_or_newview
2572 bind . <$M1B-q> doquit
2573 bind . <$M1B-f> {dofind 1 1}
2574 bind . <$M1B-g> {dofind 1 0}
2575 bind . <$M1B-r> dosearchback
2576 bind . <$M1B-s> dosearch
2577 bind . <$M1B-equal> {incrfont 1}
2578 bind . <$M1B-plus> {incrfont 1}
2579 bind . <$M1B-KP_Add> {incrfont 1}
2580 bind . <$M1B-minus> {incrfont -1}
2581 bind . <$M1B-KP_Subtract> {incrfont -1}
2582 wm protocol . WM_DELETE_WINDOW doquit
2583 bind . <Destroy> {stop_backends}
2584 bind . <Button-1> "click %W"
2585 bind $fstring <Key-Return> {dofind 1 1}
2586 bind $sha1entry <Key-Return> {gotocommit; break}
2587 bind $sha1entry <<PasteSelection>> clearsha1
2588 bind $sha1entry <<Paste>> clearsha1
2589 bind $cflist <1> {sel_flist %W %x %y; break}
2590 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2591 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2593 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2594 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2595 bind $ctext <Button-1> {focus %W}
2596 bind $ctext <<Selection>> rehighlight_search_results
2598 set maincursor [. cget -cursor]
2599 set textcursor [$ctext cget -cursor]
2600 set curtextcursor $textcursor
2602 set rowctxmenu .rowctxmenu
2603 makemenu $rowctxmenu {
2604 {mc "Diff this -> selected" command {diffvssel 0}}
2605 {mc "Diff selected -> this" command {diffvssel 1}}
2606 {mc "Make patch" command mkpatch}
2607 {mc "Create tag" command mktag}
2608 {mc "Write commit to file" command writecommit}
2609 {mc "Create new branch" command mkbranch}
2610 {mc "Cherry-pick this commit" command cherrypick}
2611 {mc "Reset HEAD branch to here" command resethead}
2612 {mc "Mark this commit" command markhere}
2613 {mc "Return to mark" command gotomark}
2614 {mc "Find descendant of this and mark" command find_common_desc}
2615 {mc "Compare with marked commit" command compare_commits}
2616 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2617 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2618 {mc "Revert this commit" command revert}
2620 $rowctxmenu configure -tearoff 0
2622 set fakerowmenu .fakerowmenu
2623 makemenu $fakerowmenu {
2624 {mc "Diff this -> selected" command {diffvssel 0}}
2625 {mc "Diff selected -> this" command {diffvssel 1}}
2626 {mc "Make patch" command mkpatch}
2627 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2628 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2630 $fakerowmenu configure -tearoff 0
2632 set headctxmenu .headctxmenu
2633 makemenu $headctxmenu {
2634 {mc "Check out this branch" command cobranch}
2635 {mc "Remove this branch" command rmbranch}
2637 $headctxmenu configure -tearoff 0
2640 set flist_menu .flistctxmenu
2641 makemenu $flist_menu {
2642 {mc "Highlight this too" command {flist_hl 0}}
2643 {mc "Highlight this only" command {flist_hl 1}}
2644 {mc "External diff" command {external_diff}}
2645 {mc "Blame parent commit" command {external_blame 1}}
2647 $flist_menu configure -tearoff 0
2650 set diff_menu .diffctxmenu
2651 makemenu $diff_menu {
2652 {mc "Show origin of this line" command show_line_source}
2653 {mc "Run git gui blame on this line" command {external_blame_diff}}
2655 $diff_menu configure -tearoff 0
2658 # Windows sends all mouse wheel events to the current focused window, not
2659 # the one where the mouse hovers, so bind those events here and redirect
2660 # to the correct window
2661 proc windows_mousewheel_redirector {W X Y D} {
2662 global canv canv2 canv3
2663 set w [winfo containing -displayof $W $X $Y]
2665 set u [expr {$D < 0 ? 5 : -5}]
2666 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2667 allcanvs yview scroll $u units
2670 $w yview scroll $u units
2676 # Update row number label when selectedline changes
2677 proc selectedline_change {n1 n2 op} {
2678 global selectedline rownumsel
2680 if {$selectedline eq {}} {
2683 set rownumsel [expr {$selectedline + 1}]
2687 # mouse-2 makes all windows scan vertically, but only the one
2688 # the cursor is in scans horizontally
2689 proc canvscan {op w x y} {
2690 global canv canv2 canv3
2691 foreach c [list $canv $canv2 $canv3] {
2700 proc scrollcanv {cscroll f0 f1} {
2701 $cscroll set $f0 $f1
2706 # when we make a key binding for the toplevel, make sure
2707 # it doesn't get triggered when that key is pressed in the
2708 # find string entry widget.
2709 proc bindkey {ev script} {
2712 set escript [bind Entry $ev]
2713 if {$escript == {}} {
2714 set escript [bind Entry <Key>]
2716 foreach e $entries {
2717 bind $e $ev "$escript; break"
2721 proc bindmodfunctionkey {mod n script} {
2722 bind . <$mod-F$n> $script
2723 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2726 # set the focus back to the toplevel for any click outside
2729 global ctext entries
2730 foreach e [concat $entries $ctext] {
2731 if {$w == $e} return
2736 # Adjust the progress bar for a change in requested extent or canvas size
2737 proc adjustprogress {} {
2738 global progresscanv progressitem progresscoords
2739 global fprogitem fprogcoord lastprogupdate progupdatepending
2740 global rprogitem rprogcoord use_ttk
2743 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2747 set w [expr {[winfo width $progresscanv] - 4}]
2748 set x0 [expr {$w * [lindex $progresscoords 0]}]
2749 set x1 [expr {$w * [lindex $progresscoords 1]}]
2750 set h [winfo height $progresscanv]
2751 $progresscanv coords $progressitem $x0 0 $x1 $h
2752 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2753 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2754 set now [clock clicks -milliseconds]
2755 if {$now >= $lastprogupdate + 100} {
2756 set progupdatepending 0
2758 } elseif {!$progupdatepending} {
2759 set progupdatepending 1
2760 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2764 proc doprogupdate {} {
2765 global lastprogupdate progupdatepending
2767 if {$progupdatepending} {
2768 set progupdatepending 0
2769 set lastprogupdate [clock clicks -milliseconds]
2774 proc savestuff {w} {
2775 global canv canv2 canv3 mainfont textfont uifont tabstop
2776 global stuffsaved findmergefiles maxgraphpct
2777 global maxwidth showneartags showlocalchanges
2778 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2779 global cmitmode wrapcomment datetimeformat limitdiffs
2780 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2781 global uifgcolor uifgdisabledcolor
2782 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2783 global tagbgcolor tagfgcolor tagoutlinecolor
2784 global reflinecolor filesepbgcolor filesepfgcolor
2785 global mergecolors foundbgcolor currentsearchhitbgcolor
2786 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2787 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2788 global linkfgcolor circleoutlinecolor
2789 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2790 global hideremotes want_ttk maxrefs
2791 global config_file config_file_tmp
2793 if {$stuffsaved} return
2794 if {![winfo viewable .]} return
2796 if {[file exists $config_file_tmp]} {
2797 file delete -force $config_file_tmp
2799 set f [open $config_file_tmp w]
2800 if {$::tcl_platform(platform) eq {windows}} {
2801 file attributes $config_file_tmp -hidden true
2803 puts $f [list set mainfont $mainfont]
2804 puts $f [list set textfont $textfont]
2805 puts $f [list set uifont $uifont]
2806 puts $f [list set tabstop $tabstop]
2807 puts $f [list set findmergefiles $findmergefiles]
2808 puts $f [list set maxgraphpct $maxgraphpct]
2809 puts $f [list set maxwidth $maxwidth]
2810 puts $f [list set cmitmode $cmitmode]
2811 puts $f [list set wrapcomment $wrapcomment]
2812 puts $f [list set autoselect $autoselect]
2813 puts $f [list set autosellen $autosellen]
2814 puts $f [list set showneartags $showneartags]
2815 puts $f [list set maxrefs $maxrefs]
2816 puts $f [list set hideremotes $hideremotes]
2817 puts $f [list set showlocalchanges $showlocalchanges]
2818 puts $f [list set datetimeformat $datetimeformat]
2819 puts $f [list set limitdiffs $limitdiffs]
2820 puts $f [list set uicolor $uicolor]
2821 puts $f [list set want_ttk $want_ttk]
2822 puts $f [list set bgcolor $bgcolor]
2823 puts $f [list set fgcolor $fgcolor]
2824 puts $f [list set uifgcolor $uifgcolor]
2825 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2826 puts $f [list set colors $colors]
2827 puts $f [list set diffcolors $diffcolors]
2828 puts $f [list set mergecolors $mergecolors]
2829 puts $f [list set markbgcolor $markbgcolor]
2830 puts $f [list set diffcontext $diffcontext]
2831 puts $f [list set selectbgcolor $selectbgcolor]
2832 puts $f [list set foundbgcolor $foundbgcolor]
2833 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2834 puts $f [list set extdifftool $extdifftool]
2835 puts $f [list set perfile_attrs $perfile_attrs]
2836 puts $f [list set headbgcolor $headbgcolor]
2837 puts $f [list set headfgcolor $headfgcolor]
2838 puts $f [list set headoutlinecolor $headoutlinecolor]
2839 puts $f [list set remotebgcolor $remotebgcolor]
2840 puts $f [list set tagbgcolor $tagbgcolor]
2841 puts $f [list set tagfgcolor $tagfgcolor]
2842 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2843 puts $f [list set reflinecolor $reflinecolor]
2844 puts $f [list set filesepbgcolor $filesepbgcolor]
2845 puts $f [list set filesepfgcolor $filesepfgcolor]
2846 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2847 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2848 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2849 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2850 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2851 puts $f [list set indexcirclecolor $indexcirclecolor]
2852 puts $f [list set circlecolors $circlecolors]
2853 puts $f [list set linkfgcolor $linkfgcolor]
2854 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2856 puts $f "set geometry(main) [wm geometry .]"
2857 puts $f "set geometry(state) [wm state .]"
2858 puts $f "set geometry(topwidth) [winfo width .tf]"
2859 puts $f "set geometry(topheight) [winfo height .tf]"
2861 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2862 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2864 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2865 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2867 puts $f "set geometry(botwidth) [winfo width .bleft]"
2868 puts $f "set geometry(botheight) [winfo height .bleft]"
2870 puts -nonewline $f "set permviews {"
2871 for {set v 0} {$v < $nextviewnum} {incr v} {
2872 if {$viewperm($v)} {
2873 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2878 file rename -force $config_file_tmp $config_file
2883 proc resizeclistpanes {win w} {
2884 global oldwidth use_ttk
2885 if {[info exists oldwidth($win)]} {
2887 set s0 [$win sashpos 0]
2888 set s1 [$win sashpos 1]
2890 set s0 [$win sash coord 0]
2891 set s1 [$win sash coord 1]
2894 set sash0 [expr {int($w/2 - 2)}]
2895 set sash1 [expr {int($w*5/6 - 2)}]
2897 set factor [expr {1.0 * $w / $oldwidth($win)}]
2898 set sash0 [expr {int($factor * [lindex $s0 0])}]
2899 set sash1 [expr {int($factor * [lindex $s1 0])}]
2903 if {$sash1 < $sash0 + 20} {
2904 set sash1 [expr {$sash0 + 20}]
2906 if {$sash1 > $w - 10} {
2907 set sash1 [expr {$w - 10}]
2908 if {$sash0 > $sash1 - 20} {
2909 set sash0 [expr {$sash1 - 20}]
2914 $win sashpos 0 $sash0
2915 $win sashpos 1 $sash1
2917 $win sash place 0 $sash0 [lindex $s0 1]
2918 $win sash place 1 $sash1 [lindex $s1 1]
2921 set oldwidth($win) $w
2924 proc resizecdetpanes {win w} {
2925 global oldwidth use_ttk
2926 if {[info exists oldwidth($win)]} {
2928 set s0 [$win sashpos 0]
2930 set s0 [$win sash coord 0]
2933 set sash0 [expr {int($w*3/4 - 2)}]
2935 set factor [expr {1.0 * $w / $oldwidth($win)}]
2936 set sash0 [expr {int($factor * [lindex $s0 0])}]
2940 if {$sash0 > $w - 15} {
2941 set sash0 [expr {$w - 15}]
2945 $win sashpos 0 $sash0
2947 $win sash place 0 $sash0 [lindex $s0 1]
2950 set oldwidth($win) $w
2953 proc allcanvs args {
2954 global canv canv2 canv3
2960 proc bindall {event action} {
2961 global canv canv2 canv3
2962 bind $canv $event $action
2963 bind $canv2 $event $action
2964 bind $canv3 $event $action
2970 if {[winfo exists $w]} {
2975 wm title $w [mc "About gitk"]
2977 message $w.m -text [mc "
2978 Gitk - a commit viewer for git
2980 Copyright \u00a9 2005-2014 Paul Mackerras
2982 Use and redistribute under the terms of the GNU General Public License"] \
2983 -justify center -aspect 400 -border 2 -bg white -relief groove
2984 pack $w.m -side top -fill x -padx 2 -pady 2
2985 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2986 pack $w.ok -side bottom
2987 bind $w <Visibility> "focus $w.ok"
2988 bind $w <Key-Escape> "destroy $w"
2989 bind $w <Key-Return> "destroy $w"
2990 tk::PlaceWindow $w widget .
2996 if {[winfo exists $w]} {
3000 if {[tk windowingsystem] eq {aqua}} {
3006 wm title $w [mc "Gitk key bindings"]
3008 message $w.m -text "
3009 [mc "Gitk key bindings:"]
3011 [mc "<%s-Q> Quit" $M1T]
3012 [mc "<%s-W> Close window" $M1T]
3013 [mc "<Home> Move to first commit"]
3014 [mc "<End> Move to last commit"]
3015 [mc "<Up>, p, k Move up one commit"]
3016 [mc "<Down>, n, j Move down one commit"]
3017 [mc "<Left>, z, h Go back in history list"]
3018 [mc "<Right>, x, l Go forward in history list"]
3019 [mc "<PageUp> Move up one page in commit list"]
3020 [mc "<PageDown> Move down one page in commit list"]
3021 [mc "<%s-Home> Scroll to top of commit list" $M1T]
3022 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
3023 [mc "<%s-Up> Scroll commit list up one line" $M1T]
3024 [mc "<%s-Down> Scroll commit list down one line" $M1T]
3025 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
3026 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
3027 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
3028 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
3029 [mc "<Delete>, b Scroll diff view up one page"]
3030 [mc "<Backspace> Scroll diff view up one page"]
3031 [mc "<Space> Scroll diff view down one page"]
3032 [mc "u Scroll diff view up 18 lines"]
3033 [mc "d Scroll diff view down 18 lines"]
3034 [mc "<%s-F> Find" $M1T]
3035 [mc "<%s-G> Move to next find hit" $M1T]
3036 [mc "<Return> Move to next find hit"]
3037 [mc "/ Focus the search box"]
3038 [mc "? Move to previous find hit"]
3039 [mc "f Scroll diff view to next file"]
3040 [mc "<%s-S> Search for next hit in diff view" $M1T]
3041 [mc "<%s-R> Search for previous hit in diff view" $M1T]
3042 [mc "<%s-KP+> Increase font size" $M1T]
3043 [mc "<%s-plus> Increase font size" $M1T]
3044 [mc "<%s-KP-> Decrease font size" $M1T]
3045 [mc "<%s-minus> Decrease font size" $M1T]
3048 -justify left -bg white -border 2 -relief groove
3049 pack $w.m -side top -fill both -padx 2 -pady 2
3050 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3051 bind $w <Key-Escape> [list destroy $w]
3052 pack $w.ok -side bottom
3053 bind $w <Visibility> "focus $w.ok"
3054 bind $w <Key-Escape> "destroy $w"
3055 bind $w <Key-Return> "destroy $w"
3058 # Procedures for manipulating the file list window at the
3059 # bottom right of the overall window.
3061 proc treeview {w l openlevs} {
3062 global treecontents treediropen treeheight treeparent treeindex
3072 set treecontents() {}
3073 $w conf -state normal
3075 while {[string range $f 0 $prefixend] ne $prefix} {
3076 if {$lev <= $openlevs} {
3077 $w mark set e:$treeindex($prefix) "end -1c"
3078 $w mark gravity e:$treeindex($prefix) left
3080 set treeheight($prefix) $ht
3081 incr ht [lindex $htstack end]
3082 set htstack [lreplace $htstack end end]
3083 set prefixend [lindex $prefendstack end]
3084 set prefendstack [lreplace $prefendstack end end]
3085 set prefix [string range $prefix 0 $prefixend]
3088 set tail [string range $f [expr {$prefixend+1}] end]
3089 while {[set slash [string first "/" $tail]] >= 0} {
3092 lappend prefendstack $prefixend
3093 incr prefixend [expr {$slash + 1}]
3094 set d [string range $tail 0 $slash]
3095 lappend treecontents($prefix) $d
3096 set oldprefix $prefix
3098 set treecontents($prefix) {}
3099 set treeindex($prefix) [incr ix]
3100 set treeparent($prefix) $oldprefix
3101 set tail [string range $tail [expr {$slash+1}] end]
3102 if {$lev <= $openlevs} {
3104 set treediropen($prefix) [expr {$lev < $openlevs}]
3105 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3106 $w mark set d:$ix "end -1c"
3107 $w mark gravity d:$ix left
3109 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3111 $w image create end -align center -image $bm -padx 1 \
3113 $w insert end $d [highlight_tag $prefix]
3114 $w mark set s:$ix "end -1c"
3115 $w mark gravity s:$ix left
3120 if {$lev <= $openlevs} {
3123 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3125 $w insert end $tail [highlight_tag $f]
3127 lappend treecontents($prefix) $tail
3130 while {$htstack ne {}} {
3131 set treeheight($prefix) $ht
3132 incr ht [lindex $htstack end]
3133 set htstack [lreplace $htstack end end]
3134 set prefixend [lindex $prefendstack end]
3135 set prefendstack [lreplace $prefendstack end end]
3136 set prefix [string range $prefix 0 $prefixend]
3138 $w conf -state disabled
3141 proc linetoelt {l} {
3142 global treeheight treecontents
3147 foreach e $treecontents($prefix) {
3152 if {[string index $e end] eq "/"} {
3153 set n $treeheight($prefix$e)
3165 proc highlight_tree {y prefix} {
3166 global treeheight treecontents cflist
3168 foreach e $treecontents($prefix) {
3170 if {[highlight_tag $path] ne {}} {
3171 $cflist tag add bold $y.0 "$y.0 lineend"
3174 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3175 set y [highlight_tree $y $path]
3181 proc treeclosedir {w dir} {
3182 global treediropen treeheight treeparent treeindex
3184 set ix $treeindex($dir)
3185 $w conf -state normal
3186 $w delete s:$ix e:$ix
3187 set treediropen($dir) 0
3188 $w image configure a:$ix -image tri-rt
3189 $w conf -state disabled
3190 set n [expr {1 - $treeheight($dir)}]
3191 while {$dir ne {}} {
3192 incr treeheight($dir) $n
3193 set dir $treeparent($dir)
3197 proc treeopendir {w dir} {
3198 global treediropen treeheight treeparent treecontents treeindex
3200 set ix $treeindex($dir)
3201 $w conf -state normal
3202 $w image configure a:$ix -image tri-dn
3203 $w mark set e:$ix s:$ix
3204 $w mark gravity e:$ix right
3207 set n [llength $treecontents($dir)]
3208 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3211 incr treeheight($x) $n
3213 foreach e $treecontents($dir) {
3215 if {[string index $e end] eq "/"} {
3216 set iy $treeindex($de)
3217 $w mark set d:$iy e:$ix
3218 $w mark gravity d:$iy left
3219 $w insert e:$ix $str
3220 set treediropen($de) 0
3221 $w image create e:$ix -align center -image tri-rt -padx 1 \
3223 $w insert e:$ix $e [highlight_tag $de]
3224 $w mark set s:$iy e:$ix
3225 $w mark gravity s:$iy left
3226 set treeheight($de) 1
3228 $w insert e:$ix $str
3229 $w insert e:$ix $e [highlight_tag $de]
3232 $w mark gravity e:$ix right
3233 $w conf -state disabled
3234 set treediropen($dir) 1
3235 set top [lindex [split [$w index @0,0] .] 0]
3236 set ht [$w cget -height]
3237 set l [lindex [split [$w index s:$ix] .] 0]
3240 } elseif {$l + $n + 1 > $top + $ht} {
3241 set top [expr {$l + $n + 2 - $ht}]
3249 proc treeclick {w x y} {
3250 global treediropen cmitmode ctext cflist cflist_top
3252 if {$cmitmode ne "tree"} return
3253 if {![info exists cflist_top]} return
3254 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3255 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3256 $cflist tag add highlight $l.0 "$l.0 lineend"
3262 set e [linetoelt $l]
3263 if {[string index $e end] ne "/"} {
3265 } elseif {$treediropen($e)} {
3272 proc setfilelist {id} {
3273 global treefilelist cflist jump_to_here
3275 treeview $cflist $treefilelist($id) 0
3276 if {$jump_to_here ne {}} {
3277 set f [lindex $jump_to_here 0]
3278 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3284 image create bitmap tri-rt -background black -foreground blue -data {
3285 #define tri-rt_width 13
3286 #define tri-rt_height 13
3287 static unsigned char tri-rt_bits[] = {
3288 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3289 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3292 #define tri-rt-mask_width 13
3293 #define tri-rt-mask_height 13
3294 static unsigned char tri-rt-mask_bits[] = {
3295 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3296 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3299 image create bitmap tri-dn -background black -foreground blue -data {
3300 #define tri-dn_width 13
3301 #define tri-dn_height 13
3302 static unsigned char tri-dn_bits[] = {
3303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3304 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3307 #define tri-dn-mask_width 13
3308 #define tri-dn-mask_height 13
3309 static unsigned char tri-dn-mask_bits[] = {
3310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3311 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3315 image create bitmap reficon-T -background black -foreground yellow -data {
3316 #define tagicon_width 13
3317 #define tagicon_height 9
3318 static unsigned char tagicon_bits[] = {
3319 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3320 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3322 #define tagicon-mask_width 13
3323 #define tagicon-mask_height 9
3324 static unsigned char tagicon-mask_bits[] = {
3325 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3326 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3329 #define headicon_width 13
3330 #define headicon_height 9
3331 static unsigned char headicon_bits[] = {
3332 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3333 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3336 #define headicon-mask_width 13
3337 #define headicon-mask_height 9
3338 static unsigned char headicon-mask_bits[] = {
3339 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3340 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3342 image create bitmap reficon-H -background black -foreground green \
3343 -data $rectdata -maskdata $rectmask
3344 image create bitmap reficon-o -background black -foreground "#ddddff" \
3345 -data $rectdata -maskdata $rectmask
3347 proc init_flist {first} {
3348 global cflist cflist_top difffilestart
3350 $cflist conf -state normal
3351 $cflist delete 0.0 end
3353 $cflist insert end $first
3355 $cflist tag add highlight 1.0 "1.0 lineend"
3357 catch {unset cflist_top}
3359 $cflist conf -state disabled
3360 set difffilestart {}
3363 proc highlight_tag {f} {
3364 global highlight_paths
3366 foreach p $highlight_paths {
3367 if {[string match $p $f]} {
3374 proc highlight_filelist {} {
3375 global cmitmode cflist
3377 $cflist conf -state normal
3378 if {$cmitmode ne "tree"} {
3379 set end [lindex [split [$cflist index end] .] 0]
3380 for {set l 2} {$l < $end} {incr l} {
3381 set line [$cflist get $l.0 "$l.0 lineend"]
3382 if {[highlight_tag $line] ne {}} {
3383 $cflist tag add bold $l.0 "$l.0 lineend"
3389 $cflist conf -state disabled
3392 proc unhighlight_filelist {} {
3395 $cflist conf -state normal
3396 $cflist tag remove bold 1.0 end
3397 $cflist conf -state disabled
3400 proc add_flist {fl} {
3403 $cflist conf -state normal
3405 $cflist insert end "\n"
3406 $cflist insert end $f [highlight_tag $f]
3408 $cflist conf -state disabled
3411 proc sel_flist {w x y} {
3412 global ctext difffilestart cflist cflist_top cmitmode
3414 if {$cmitmode eq "tree"} return
3415 if {![info exists cflist_top]} return
3416 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3417 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3418 $cflist tag add highlight $l.0 "$l.0 lineend"
3423 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3425 suppress_highlighting_file_for_current_scrollpos
3428 proc pop_flist_menu {w X Y x y} {
3429 global ctext cflist cmitmode flist_menu flist_menu_file
3430 global treediffs diffids
3433 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3435 if {$cmitmode eq "tree"} {
3436 set e [linetoelt $l]
3437 if {[string index $e end] eq "/"} return
3439 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3441 set flist_menu_file $e
3442 set xdiffstate "normal"
3443 if {$cmitmode eq "tree"} {
3444 set xdiffstate "disabled"
3446 # Disable "External diff" item in tree mode
3447 $flist_menu entryconf 2 -state $xdiffstate
3448 tk_popup $flist_menu $X $Y
3451 proc find_ctext_fileinfo {line} {
3452 global ctext_file_names ctext_file_lines
3454 set ok [bsearch $ctext_file_lines $line]
3455 set tline [lindex $ctext_file_lines $ok]
3457 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3460 return [list [lindex $ctext_file_names $ok] $tline]
3464 proc pop_diff_menu {w X Y x y} {
3465 global ctext diff_menu flist_menu_file
3466 global diff_menu_txtpos diff_menu_line
3467 global diff_menu_filebase
3469 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3470 set diff_menu_line [lindex $diff_menu_txtpos 0]
3471 # don't pop up the menu on hunk-separator or file-separator lines
3472 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3476 set f [find_ctext_fileinfo $diff_menu_line]
3477 if {$f eq {}} return
3478 set flist_menu_file [lindex $f 0]
3479 set diff_menu_filebase [lindex $f 1]
3480 tk_popup $diff_menu $X $Y
3483 proc flist_hl {only} {
3484 global flist_menu_file findstring gdttype
3486 set x [shellquote $flist_menu_file]
3487 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3490 append findstring " " $x
3492 set gdttype [mc "touching paths:"]
3495 proc gitknewtmpdir {} {
3496 global diffnum gitktmpdir gitdir env
3498 if {![info exists gitktmpdir]} {
3499 if {[info exists env(GITK_TMPDIR)]} {
3500 set tmpdir $env(GITK_TMPDIR)
3501 } elseif {[info exists env(TMPDIR)]} {
3502 set tmpdir $env(TMPDIR)
3506 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
3507 set gitktmpdir [exec mktemp -d $gitktmpformat]
3508 if {[catch {file mkdir $gitktmpdir} err]} {
3509 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3516 set diffdir [file join $gitktmpdir $diffnum]
3517 if {[catch {file mkdir $diffdir} err]} {
3518 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3524 proc save_file_from_commit {filename output what} {
3527 if {[catch {exec git show $filename -- > $output} err]} {
3528 if {[string match "fatal: bad revision *" $err]} {
3531 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3537 proc external_diff_get_one_file {diffid filename diffdir} {
3538 global nullid nullid2 nullfile
3541 if {$diffid == $nullid} {
3542 set difffile [file join $worktree $filename]
3543 if {[file exists $difffile]} {
3548 if {$diffid == $nullid2} {
3549 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3550 return [save_file_from_commit :$filename $difffile index]
3552 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3553 return [save_file_from_commit $diffid:$filename $difffile \
3557 proc external_diff {} {
3558 global nullid nullid2
3559 global flist_menu_file
3563 if {[llength $diffids] == 1} {
3564 # no reference commit given
3565 set diffidto [lindex $diffids 0]
3566 if {$diffidto eq $nullid} {
3567 # diffing working copy with index
3568 set diffidfrom $nullid2
3569 } elseif {$diffidto eq $nullid2} {
3570 # diffing index with HEAD
3571 set diffidfrom "HEAD"
3573 # use first parent commit
3574 global parentlist selectedline
3575 set diffidfrom [lindex $parentlist $selectedline 0]
3578 set diffidfrom [lindex $diffids 0]
3579 set diffidto [lindex $diffids 1]
3582 # make sure that several diffs wont collide
3583 set diffdir [gitknewtmpdir]
3584 if {$diffdir eq {}} return
3586 # gather files to diff
3587 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3588 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3590 if {$difffromfile ne {} && $difftofile ne {}} {
3591 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3592 if {[catch {set fl [open |$cmd r]} err]} {
3593 file delete -force $diffdir
3594 error_popup "$extdifftool: [mc "command failed:"] $err"
3596 fconfigure $fl -blocking 0
3597 filerun $fl [list delete_at_eof $fl $diffdir]
3602 proc find_hunk_blamespec {base line} {
3605 # Find and parse the hunk header
3606 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3607 if {$s_lix eq {}} return
3609 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3610 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3611 s_line old_specs osz osz1 new_line nsz]} {
3615 # base lines for the parents
3616 set base_lines [list $new_line]
3617 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3618 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3619 old_spec old_line osz]} {
3622 lappend base_lines $old_line
3625 # Now scan the lines to determine offset within the hunk
3626 set max_parent [expr {[llength $base_lines]-2}]
3628 set s_lno [lindex [split $s_lix "."] 0]
3630 # Determine if the line is removed
3631 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3632 if {[string match {[-+ ]*} $chunk]} {
3633 set removed_idx [string first "-" $chunk]
3634 # Choose a parent index
3635 if {$removed_idx >= 0} {
3636 set parent $removed_idx
3638 set unchanged_idx [string first " " $chunk]
3639 if {$unchanged_idx >= 0} {
3640 set parent $unchanged_idx
3642 # blame the current commit
3646 # then count other lines that belong to it
3647 for {set i $line} {[incr i -1] > $s_lno} {} {
3648 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3649 # Determine if the line is removed
3650 set removed_idx [string first "-" $chunk]
3652 set code [string index $chunk $parent]
3653 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3657 if {$removed_idx < 0} {
3667 incr dline [lindex $base_lines $parent]
3668 return [list $parent $dline]
3671 proc external_blame_diff {} {
3672 global currentid cmitmode
3673 global diff_menu_txtpos diff_menu_line
3674 global diff_menu_filebase flist_menu_file
3676 if {$cmitmode eq "tree"} {
3678 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3680 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3682 set parent_idx [lindex $hinfo 0]
3683 set line [lindex $hinfo 1]
3690 external_blame $parent_idx $line
3693 # Find the SHA1 ID of the blob for file $fname in the index
3695 proc index_sha1 {fname} {
3696 set f [open [list | git ls-files -s $fname] r]
3697 while {[gets $f line] >= 0} {
3698 set info [lindex [split $line "\t"] 0]
3699 set stage [lindex $info 2]
3700 if {$stage eq "0" || $stage eq "2"} {
3702 return [lindex $info 1]
3709 # Turn an absolute path into one relative to the current directory
3710 proc make_relative {f} {
3711 if {[file pathtype $f] eq "relative"} {
3714 set elts [file split $f]
3715 set here [file split [pwd]]
3720 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3727 set elts [concat $res [lrange $elts $ei end]]
3728 return [eval file join $elts]
3731 proc external_blame {parent_idx {line {}}} {
3732 global flist_menu_file cdup
3733 global nullid nullid2
3734 global parentlist selectedline currentid
3736 if {$parent_idx > 0} {
3737 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3739 set base_commit $currentid
3742 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3743 error_popup [mc "No such commit"]
3747 set cmdline [list git gui blame]
3748 if {$line ne {} && $line > 1} {
3749 lappend cmdline "--line=$line"
3751 set f [file join $cdup $flist_menu_file]
3752 # Unfortunately it seems git gui blame doesn't like
3753 # being given an absolute path...
3754 set f [make_relative $f]
3755 lappend cmdline $base_commit $f
3756 if {[catch {eval exec $cmdline &} err]} {
3757 error_popup "[mc "git gui blame: command failed:"] $err"
3761 proc show_line_source {} {
3762 global cmitmode currentid parents curview blamestuff blameinst
3763 global diff_menu_line diff_menu_filebase flist_menu_file
3764 global nullid nullid2 gitdir cdup
3767 if {$cmitmode eq "tree"} {
3769 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3771 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3772 if {$h eq {}} return
3773 set pi [lindex $h 0]
3775 mark_ctext_line $diff_menu_line
3779 if {$currentid eq $nullid} {
3781 # must be a merge in progress...
3783 # get the last line from .git/MERGE_HEAD
3784 set f [open [file join $gitdir MERGE_HEAD] r]
3785 set id [lindex [split [read $f] "\n"] end-1]
3788 error_popup [mc "Couldn't read merge head: %s" $err]
3791 } elseif {$parents($curview,$currentid) eq $nullid2} {
3792 # need to do the blame from the index
3794 set from_index [index_sha1 $flist_menu_file]
3796 error_popup [mc "Error reading index: %s" $err]
3800 set id $parents($curview,$currentid)
3803 set id [lindex $parents($curview,$currentid) $pi]
3805 set line [lindex $h 1]
3808 if {$from_index ne {}} {
3809 lappend blameargs | git cat-file blob $from_index
3811 lappend blameargs | git blame -p -L$line,+1
3812 if {$from_index ne {}} {
3813 lappend blameargs --contents -
3815 lappend blameargs $id
3817 lappend blameargs -- [file join $cdup $flist_menu_file]
3819 set f [open $blameargs r]
3821 error_popup [mc "Couldn't start git blame: %s" $err]
3824 nowbusy blaming [mc "Searching"]
3825 fconfigure $f -blocking 0
3826 set i [reg_instance $f]
3827 set blamestuff($i) {}
3829 filerun $f [list read_line_source $f $i]
3832 proc stopblaming {} {
3835 if {[info exists blameinst]} {
3836 stop_instance $blameinst
3842 proc read_line_source {fd inst} {
3843 global blamestuff curview commfd blameinst nullid nullid2
3845 while {[gets $fd line] >= 0} {
3846 lappend blamestuff($inst) $line
3854 fconfigure $fd -blocking 1
3855 if {[catch {close $fd} err]} {
3856 error_popup [mc "Error running git blame: %s" $err]
3861 set line [split [lindex $blamestuff($inst) 0] " "]
3862 set id [lindex $line 0]
3863 set lnum [lindex $line 1]
3864 if {[string length $id] == 40 && [string is xdigit $id] &&
3865 [string is digit -strict $lnum]} {
3866 # look for "filename" line
3867 foreach l $blamestuff($inst) {
3868 if {[string match "filename *" $l]} {
3869 set fname [string range $l 9 end]
3875 # all looks good, select it
3876 if {$id eq $nullid} {
3877 # blame uses all-zeroes to mean not committed,
3878 # which would mean a change in the index
3881 if {[commitinview $id $curview]} {
3882 selectline [rowofcommit $id] 1 [list $fname $lnum] 1
3884 error_popup [mc "That line comes from commit %s, \
3885 which is not in this view" [shortids $id]]
3888 puts "oops couldn't parse git blame output"
3893 # delete $dir when we see eof on $f (presumably because the child has exited)
3894 proc delete_at_eof {f dir} {
3895 while {[gets $f line] >= 0} {}
3897 if {[catch {close $f} err]} {
3898 error_popup "[mc "External diff viewer failed:"] $err"
3900 file delete -force $dir
3906 # Functions for adding and removing shell-type quoting
3908 proc shellquote {str} {
3909 if {![string match "*\['\"\\ \t]*" $str]} {
3912 if {![string match "*\['\"\\]*" $str]} {
3915 if {![string match "*'*" $str]} {
3918 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3921 proc shellarglist {l} {
3927 append str [shellquote $a]
3932 proc shelldequote {str} {
3937 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3938 append ret [string range $str $used end]
3939 set used [string length $str]
3942 set first [lindex $first 0]
3943 set ch [string index $str $first]
3944 if {$first > $used} {
3945 append ret [string range $str $used [expr {$first - 1}]]
3948 if {$ch eq " " || $ch eq "\t"} break
3951 set first [string first "'" $str $used]
3953 error "unmatched single-quote"
3955 append ret [string range $str $used [expr {$first - 1}]]
3960 if {$used >= [string length $str]} {
3961 error "trailing backslash"
3963 append ret [string index $str $used]
3968 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3969 error "unmatched double-quote"
3971 set first [lindex $first 0]
3972 set ch [string index $str $first]
3973 if {$first > $used} {
3974 append ret [string range $str $used [expr {$first - 1}]]
3977 if {$ch eq "\""} break
3979 append ret [string index $str $used]
3983 return [list $used $ret]
3986 proc shellsplit {str} {
3989 set str [string trimleft $str]
3990 if {$str eq {}} break
3991 set dq [shelldequote $str]
3992 set n [lindex $dq 0]
3993 set word [lindex $dq 1]
3994 set str [string range $str $n end]
4000 # Code to implement multiple views
4002 proc newview {ishighlight} {
4003 global nextviewnum newviewname newishighlight
4004 global revtreeargs viewargscmd newviewopts curview
4006 set newishighlight $ishighlight
4008 if {[winfo exists $top]} {
4012 decode_view_opts $nextviewnum $revtreeargs
4013 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
4014 set newviewopts($nextviewnum,perm) 0
4015 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
4016 vieweditor $top $nextviewnum [mc "Gitk view definition"]
4019 set known_view_options {
4020 {perm b . {} {mc "Remember this view"}}
4021 {reflabel l + {} {mc "References (space separated list):"}}
4022 {refs t15 .. {} {mc "Branches & tags:"}}
4023 {allrefs b *. "--all" {mc "All refs"}}
4024 {branches b . "--branches" {mc "All (local) branches"}}
4025 {tags b . "--tags" {mc "All tags"}}
4026 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
4027 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
4028 {author t15 .. "--author=*" {mc "Author:"}}
4029 {committer t15 . "--committer=*" {mc "Committer:"}}
4030 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
4031 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
4032 {changes_l l + {} {mc "Changes to Files:"}}
4033 {pickaxe_s r0 . {} {mc "Fixed String"}}
4034 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
4035 {pickaxe t15 .. "-S*" {mc "Search string:"}}
4036 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
4037 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
4038 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
4039 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
4040 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
4041 {skip t10 . "--skip=*" {mc "Number to skip:"}}
4042 {misc_lbl l + {} {mc "Miscellaneous options:"}}
4043 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
4044 {lright b . "--left-right" {mc "Mark branch sides"}}
4045 {first b . "--first-parent" {mc "Limit to first parent"}}
4046 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
4047 {args t50 *. {} {mc "Additional arguments to git log:"}}
4048 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4049 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4052 # Convert $newviewopts($n, ...) into args for git log.
4053 proc encode_view_opts {n} {
4054 global known_view_options newviewopts
4057 foreach opt $known_view_options {
4058 set patterns [lindex $opt 3]
4059 if {$patterns eq {}} continue
4060 set pattern [lindex $patterns 0]
4062 if {[lindex $opt 1] eq "b"} {
4063 set val $newviewopts($n,[lindex $opt 0])
4065 lappend rargs $pattern
4067 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4068 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4069 set val $newviewopts($n,$button_id)
4070 if {$val eq $value} {
4071 lappend rargs $pattern
4074 set val $newviewopts($n,[lindex $opt 0])
4075 set val [string trim $val]
4077 set pfix [string range $pattern 0 end-1]
4078 lappend rargs $pfix$val
4082 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4083 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4086 # Fill $newviewopts($n, ...) based on args for git log.
4087 proc decode_view_opts {n view_args} {
4088 global known_view_options newviewopts
4090 foreach opt $known_view_options {
4091 set id [lindex $opt 0]
4092 if {[lindex $opt 1] eq "b"} {
4095 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4097 regexp {^(.*_)} $id uselessvar id
4103 set newviewopts($n,$id) $val
4107 foreach arg $view_args {
4108 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4109 && ![info exists found(limit)]} {
4110 set newviewopts($n,limit) $cnt
4115 foreach opt $known_view_options {
4116 set id [lindex $opt 0]
4117 if {[info exists found($id)]} continue
4118 foreach pattern [lindex $opt 3] {
4119 if {![string match $pattern $arg]} continue
4120 if {[lindex $opt 1] eq "b"} {
4123 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4125 regexp {^(.*_)} $id uselessvar id
4129 set size [string length $pattern]
4130 set val [string range $arg [expr {$size-1}] end]
4132 set newviewopts($n,$id) $val
4136 if {[info exists val]} break
4138 if {[info exists val]} continue
4139 if {[regexp {^-} $arg]} {
4142 lappend refargs $arg
4145 set newviewopts($n,refs) [shellarglist $refargs]
4146 set newviewopts($n,args) [shellarglist $oargs]
4149 proc edit_or_newview {} {
4161 global viewname viewperm newviewname newviewopts
4162 global viewargs viewargscmd
4164 set top .gitkvedit-$curview
4165 if {[winfo exists $top]} {
4169 decode_view_opts $curview $viewargs($curview)
4170 set newviewname($curview) $viewname($curview)
4171 set newviewopts($curview,perm) $viewperm($curview)
4172 set newviewopts($curview,cmd) $viewargscmd($curview)
4173 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4176 proc vieweditor {top n title} {
4177 global newviewname newviewopts viewfiles bgcolor
4178 global known_view_options NS
4181 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4182 make_transient $top .
4185 ${NS}::frame $top.nfr
4186 ${NS}::label $top.nl -text [mc "View Name"]
4187 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4188 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4189 pack $top.nl -in $top.nfr -side left -padx {0 5}
4190 pack $top.name -in $top.nfr -side left -padx {0 25}
4196 foreach opt $known_view_options {
4197 set id [lindex $opt 0]
4198 set type [lindex $opt 1]
4199 set flags [lindex $opt 2]
4200 set title [eval [lindex $opt 4]]
4203 if {$flags eq "+" || $flags eq "*"} {
4204 set cframe $top.fr$cnt
4206 ${NS}::frame $cframe
4207 pack $cframe -in $top -fill x -pady 3 -padx 3
4208 set cexpand [expr {$flags eq "*"}]
4209 } elseif {$flags eq ".." || $flags eq "*."} {
4210 set cframe $top.fr$cnt
4212 ${NS}::frame $cframe
4213 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4214 set cexpand [expr {$flags eq "*."}]
4220 ${NS}::label $cframe.l_$id -text $title
4221 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4222 } elseif {$type eq "b"} {
4223 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4224 pack $cframe.c_$id -in $cframe -side left \
4225 -padx [list $lxpad 0] -expand $cexpand -anchor w
4226 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4227 regexp {^(.*_)} $id uselessvar button_id
4228 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4229 pack $cframe.c_$id -in $cframe -side left \
4230 -padx [list $lxpad 0] -expand $cexpand -anchor w
4231 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4232 ${NS}::label $cframe.l_$id -text $title
4233 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4234 -textvariable newviewopts($n,$id)
4235 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4236 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4237 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4238 ${NS}::label $cframe.l_$id -text $title
4239 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4240 -textvariable newviewopts($n,$id)
4241 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4242 pack $cframe.e_$id -in $cframe -side top -fill x
4243 } elseif {$type eq "path"} {
4244 ${NS}::label $top.l -text $title
4245 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4246 text $top.t -width 40 -height 5 -background $bgcolor
4247 if {[info exists viewfiles($n)]} {
4248 foreach f $viewfiles($n) {
4249 $top.t insert end $f
4250 $top.t insert end "\n"
4252 $top.t delete {end - 1c} end
4253 $top.t mark set insert 0.0
4255 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4259 ${NS}::frame $top.buts
4260 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4261 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4262 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4263 bind $top <Control-Return> [list newviewok $top $n]
4264 bind $top <F5> [list newviewok $top $n 1]
4265 bind $top <Escape> [list destroy $top]
4266 grid $top.buts.ok $top.buts.apply $top.buts.can
4267 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4268 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4269 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4270 pack $top.buts -in $top -side top -fill x
4274 proc doviewmenu {m first cmd op argv} {
4275 set nmenu [$m index end]
4276 for {set i $first} {$i <= $nmenu} {incr i} {
4277 if {[$m entrycget $i -command] eq $cmd} {
4278 eval $m $op $i $argv
4284 proc allviewmenus {n op args} {
4287 doviewmenu .bar.view 5 [list showview $n] $op $args
4288 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4291 proc newviewok {top n {apply 0}} {
4292 global nextviewnum newviewperm newviewname newishighlight
4293 global viewname viewfiles viewperm selectedview curview
4294 global viewargs viewargscmd newviewopts viewhlmenu
4297 set newargs [encode_view_opts $n]
4299 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4303 foreach f [split [$top.t get 0.0 end] "\n"] {
4304 set ft [string trim $f]
4309 if {![info exists viewfiles($n)]} {
4310 # creating a new view
4312 set viewname($n) $newviewname($n)
4313 set viewperm($n) $newviewopts($n,perm)
4314 set viewfiles($n) $files
4315 set viewargs($n) $newargs
4316 set viewargscmd($n) $newviewopts($n,cmd)
4318 if {!$newishighlight} {
4321 run addvhighlight $n
4324 # editing an existing view
4325 set viewperm($n) $newviewopts($n,perm)
4326 if {$newviewname($n) ne $viewname($n)} {
4327 set viewname($n) $newviewname($n)
4328 doviewmenu .bar.view 5 [list showview $n] \
4329 entryconf [list -label $viewname($n)]
4330 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4331 # entryconf [list -label $viewname($n) -value $viewname($n)]
4333 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4334 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4335 set viewfiles($n) $files
4336 set viewargs($n) $newargs
4337 set viewargscmd($n) $newviewopts($n,cmd)
4338 if {$curview == $n} {
4344 catch {destroy $top}
4348 global curview viewperm hlview selectedhlview
4350 if {$curview == 0} return
4351 if {[info exists hlview] && $hlview == $curview} {
4352 set selectedhlview [mc "None"]
4355 allviewmenus $curview delete
4356 set viewperm($curview) 0
4360 proc addviewmenu {n} {
4361 global viewname viewhlmenu
4363 .bar.view add radiobutton -label $viewname($n) \
4364 -command [list showview $n] -variable selectedview -value $n
4365 #$viewhlmenu add radiobutton -label $viewname($n) \
4366 # -command [list addvhighlight $n] -variable selectedhlview
4370 global curview cached_commitrow ordertok
4371 global displayorder parentlist rowidlist rowisopt rowfinal
4372 global colormap rowtextx nextcolor canvxmax
4373 global numcommits viewcomplete
4374 global selectedline currentid canv canvy0
4376 global pending_select mainheadid
4379 global hlview selectedhlview commitinterest
4381 if {$n == $curview} return
4383 set ymax [lindex [$canv cget -scrollregion] 3]
4384 set span [$canv yview]
4385 set ytop [expr {[lindex $span 0] * $ymax}]
4386 set ybot [expr {[lindex $span 1] * $ymax}]
4387 set yscreen [expr {($ybot - $ytop) / 2}]
4388 if {$selectedline ne {}} {
4389 set selid $currentid
4390 set y [yc $selectedline]
4391 if {$ytop < $y && $y < $ybot} {
4392 set yscreen [expr {$y - $ytop}]
4394 } elseif {[info exists pending_select]} {
4395 set selid $pending_select
4396 unset pending_select
4400 catch {unset treediffs}
4402 if {[info exists hlview] && $hlview == $n} {
4404 set selectedhlview [mc "None"]
4406 catch {unset commitinterest}
4407 catch {unset cached_commitrow}
4408 catch {unset ordertok}
4412 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4413 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4416 if {![info exists viewcomplete($n)]} {
4426 set numcommits $commitidx($n)
4428 catch {unset colormap}
4429 catch {unset rowtextx}
4431 set canvxmax [$canv cget -width]
4437 if {$selid ne {} && [commitinview $selid $n]} {
4438 set row [rowofcommit $selid]
4439 # try to get the selected row in the same position on the screen
4440 set ymax [lindex [$canv cget -scrollregion] 3]
4441 set ytop [expr {[yc $row] - $yscreen}]
4445 set yf [expr {$ytop * 1.0 / $ymax}]
4447 allcanvs yview moveto $yf
4451 } elseif {!$viewcomplete($n)} {
4452 reset_pending_select $selid
4454 reset_pending_select {}
4456 if {[commitinview $pending_select $curview]} {
4457 selectline [rowofcommit $pending_select] 1
4459 set row [first_real_row]
4460 if {$row < $numcommits} {
4465 if {!$viewcomplete($n)} {
4466 if {$numcommits == 0} {
4467 show_status [mc "Reading commits..."]
4469 } elseif {$numcommits == 0} {
4470 show_status [mc "No commits selected"]
4474 # Stuff relating to the highlighting facility
4476 proc ishighlighted {id} {
4477 global vhighlights fhighlights nhighlights rhighlights
4479 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4480 return $nhighlights($id)
4482 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4483 return $vhighlights($id)
4485 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4486 return $fhighlights($id)
4488 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4489 return $rhighlights($id)
4494 proc bolden {id font} {
4495 global canv linehtag currentid boldids need_redisplay markedid
4497 # need_redisplay = 1 means the display is stale and about to be redrawn
4498 if {$need_redisplay} return
4500 $canv itemconf $linehtag($id) -font $font
4501 if {[info exists currentid] && $id eq $currentid} {
4503 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4504 -outline {{}} -tags secsel \
4505 -fill [$canv cget -selectbackground]]
4508 if {[info exists markedid] && $id eq $markedid} {
4513 proc bolden_name {id font} {
4514 global canv2 linentag currentid boldnameids need_redisplay
4516 if {$need_redisplay} return
4517 lappend boldnameids $id
4518 $canv2 itemconf $linentag($id) -font $font
4519 if {[info exists currentid] && $id eq $currentid} {
4520 $canv2 delete secsel
4521 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4522 -outline {{}} -tags secsel \
4523 -fill [$canv2 cget -selectbackground]]
4532 foreach id $boldids {
4533 if {![ishighlighted $id]} {
4536 lappend stillbold $id
4539 set boldids $stillbold
4542 proc addvhighlight {n} {
4543 global hlview viewcomplete curview vhl_done commitidx
4545 if {[info exists hlview]} {
4549 if {$n != $curview && ![info exists viewcomplete($n)]} {
4552 set vhl_done $commitidx($hlview)
4553 if {$vhl_done > 0} {
4558 proc delvhighlight {} {
4559 global hlview vhighlights
4561 if {![info exists hlview]} return
4563 catch {unset vhighlights}
4567 proc vhighlightmore {} {
4568 global hlview vhl_done commitidx vhighlights curview
4570 set max $commitidx($hlview)
4571 set vr [visiblerows]
4572 set r0 [lindex $vr 0]
4573 set r1 [lindex $vr 1]
4574 for {set i $vhl_done} {$i < $max} {incr i} {
4575 set id [commitonrow $i $hlview]
4576 if {[commitinview $id $curview]} {
4577 set row [rowofcommit $id]
4578 if {$r0 <= $row && $row <= $r1} {
4579 if {![highlighted $row]} {
4580 bolden $id mainfontbold
4582 set vhighlights($id) 1
4590 proc askvhighlight {row id} {
4591 global hlview vhighlights iddrawn
4593 if {[commitinview $id $hlview]} {
4594 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4595 bolden $id mainfontbold
4597 set vhighlights($id) 1
4599 set vhighlights($id) 0
4603 proc hfiles_change {} {
4604 global highlight_files filehighlight fhighlights fh_serial
4605 global highlight_paths
4607 if {[info exists filehighlight]} {
4608 # delete previous highlights
4609 catch {close $filehighlight}
4611 catch {unset fhighlights}
4613 unhighlight_filelist
4615 set highlight_paths {}
4616 after cancel do_file_hl $fh_serial
4618 if {$highlight_files ne {}} {
4619 after 300 do_file_hl $fh_serial
4623 proc gdttype_change {name ix op} {
4624 global gdttype highlight_files findstring findpattern
4627 if {$findstring ne {}} {
4628 if {$gdttype eq [mc "containing:"]} {
4629 if {$highlight_files ne {}} {
4630 set highlight_files {}
4635 if {$findpattern ne {}} {
4639 set highlight_files $findstring
4644 # enable/disable findtype/findloc menus too
4647 proc find_change {name ix op} {
4648 global gdttype findstring highlight_files
4651 if {$gdttype eq [mc "containing:"]} {
4654 if {$highlight_files ne $findstring} {
4655 set highlight_files $findstring
4662 proc findcom_change args {
4663 global nhighlights boldnameids
4664 global findpattern findtype findstring gdttype
4667 # delete previous highlights, if any
4668 foreach id $boldnameids {
4669 bolden_name $id mainfont
4672 catch {unset nhighlights}
4675 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4677 } elseif {$findtype eq [mc "Regexp"]} {
4678 set findpattern $findstring
4680 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4682 set findpattern "*$e*"
4686 proc makepatterns {l} {
4689 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4690 if {[string index $ee end] eq "/"} {
4700 proc do_file_hl {serial} {
4701 global highlight_files filehighlight highlight_paths gdttype fhl_list
4702 global cdup findtype
4704 if {$gdttype eq [mc "touching paths:"]} {
4705 # If "exact" match then convert backslashes to forward slashes.
4706 # Most useful to support Windows-flavoured file paths.
4707 if {$findtype eq [mc "Exact"]} {
4708 set highlight_files [string map {"\\" "/"} $highlight_files]
4710 if {[catch {set paths [shellsplit $highlight_files]}]} return
4711 set highlight_paths [makepatterns $paths]
4713 set relative_paths {}
4714 foreach path $paths {
4715 lappend relative_paths [file join $cdup $path]
4717 set gdtargs [concat -- $relative_paths]
4718 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4719 set gdtargs [list "-S$highlight_files"]
4720 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4721 set gdtargs [list "-G$highlight_files"]
4723 # must be "containing:", i.e. we're searching commit info
4726 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4727 set filehighlight [open $cmd r+]
4728 fconfigure $filehighlight -blocking 0
4729 filerun $filehighlight readfhighlight
4735 proc flushhighlights {} {
4736 global filehighlight fhl_list
4738 if {[info exists filehighlight]} {
4740 puts $filehighlight ""
4741 flush $filehighlight
4745 proc askfilehighlight {row id} {
4746 global filehighlight fhighlights fhl_list
4748 lappend fhl_list $id
4749 set fhighlights($id) -1
4750 puts $filehighlight $id
4753 proc readfhighlight {} {
4754 global filehighlight fhighlights curview iddrawn
4755 global fhl_list find_dirn
4757 if {![info exists filehighlight]} {
4761 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4762 set line [string trim $line]
4763 set i [lsearch -exact $fhl_list $line]
4764 if {$i < 0} continue
4765 for {set j 0} {$j < $i} {incr j} {
4766 set id [lindex $fhl_list $j]
4767 set fhighlights($id) 0
4769 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4770 if {$line eq {}} continue
4771 if {![commitinview $line $curview]} continue
4772 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4773 bolden $line mainfontbold
4775 set fhighlights($line) 1
4777 if {[eof $filehighlight]} {
4779 puts "oops, git diff-tree died"
4780 catch {close $filehighlight}
4784 if {[info exists find_dirn]} {
4790 proc doesmatch {f} {
4791 global findtype findpattern
4793 if {$findtype eq [mc "Regexp"]} {
4794 return [regexp $findpattern $f]
4795 } elseif {$findtype eq [mc "IgnCase"]} {
4796 return [string match -nocase $findpattern $f]
4798 return [string match $findpattern $f]
4802 proc askfindhighlight {row id} {
4803 global nhighlights commitinfo iddrawn
4805 global markingmatches
4807 if {![info exists commitinfo($id)]} {
4810 set info $commitinfo($id)
4812 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4813 foreach f $info ty $fldtypes {
4814 if {$ty eq ""} continue
4815 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4817 if {$ty eq [mc "Author"]} {
4824 if {$isbold && [info exists iddrawn($id)]} {
4825 if {![ishighlighted $id]} {
4826 bolden $id mainfontbold
4828 bolden_name $id mainfontbold
4831 if {$markingmatches} {
4832 markrowmatches $row $id
4835 set nhighlights($id) $isbold
4838 proc markrowmatches {row id} {
4839 global canv canv2 linehtag linentag commitinfo findloc
4841 set headline [lindex $commitinfo($id) 0]
4842 set author [lindex $commitinfo($id) 1]
4843 $canv delete match$row
4844 $canv2 delete match$row
4845 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4846 set m [findmatches $headline]
4848 markmatches $canv $row $headline $linehtag($id) $m \
4849 [$canv itemcget $linehtag($id) -font] $row
4852 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4853 set m [findmatches $author]
4855 markmatches $canv2 $row $author $linentag($id) $m \
4856 [$canv2 itemcget $linentag($id) -font] $row
4861 proc vrel_change {name ix op} {
4862 global highlight_related
4865 if {$highlight_related ne [mc "None"]} {
4870 # prepare for testing whether commits are descendents or ancestors of a
4871 proc rhighlight_sel {a} {
4872 global descendent desc_todo ancestor anc_todo
4873 global highlight_related
4875 catch {unset descendent}
4876 set desc_todo [list $a]
4877 catch {unset ancestor}
4878 set anc_todo [list $a]
4879 if {$highlight_related ne [mc "None"]} {
4885 proc rhighlight_none {} {
4888 catch {unset rhighlights}
4892 proc is_descendent {a} {
4893 global curview children descendent desc_todo
4896 set la [rowofcommit $a]
4900 for {set i 0} {$i < [llength $todo]} {incr i} {
4901 set do [lindex $todo $i]
4902 if {[rowofcommit $do] < $la} {
4903 lappend leftover $do
4906 foreach nk $children($v,$do) {
4907 if {![info exists descendent($nk)]} {
4908 set descendent($nk) 1
4916 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4920 set descendent($a) 0
4921 set desc_todo $leftover
4924 proc is_ancestor {a} {
4925 global curview parents ancestor anc_todo
4928 set la [rowofcommit $a]
4932 for {set i 0} {$i < [llength $todo]} {incr i} {
4933 set do [lindex $todo $i]
4934 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4935 lappend leftover $do
4938 foreach np $parents($v,$do) {
4939 if {![info exists ancestor($np)]} {
4948 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4953 set anc_todo $leftover
4956 proc askrelhighlight {row id} {
4957 global descendent highlight_related iddrawn rhighlights
4958 global selectedline ancestor
4960 if {$selectedline eq {}} return
4962 if {$highlight_related eq [mc "Descendant"] ||
4963 $highlight_related eq [mc "Not descendant"]} {
4964 if {![info exists descendent($id)]} {
4967 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4970 } elseif {$highlight_related eq [mc "Ancestor"] ||
4971 $highlight_related eq [mc "Not ancestor"]} {
4972 if {![info exists ancestor($id)]} {
4975 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4979 if {[info exists iddrawn($id)]} {
4980 if {$isbold && ![ishighlighted $id]} {
4981 bolden $id mainfontbold
4984 set rhighlights($id) $isbold
4987 # Graph layout functions
4989 proc shortids {ids} {
4992 if {[llength $id] > 1} {
4993 lappend res [shortids $id]
4994 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4995 lappend res [string range $id 0 7]
5006 for {set mask 1} {$mask <= $n} {incr mask $mask} {
5007 if {($n & $mask) != 0} {
5008 set ret [concat $ret $o]
5010 set o [concat $o $o]
5015 proc ordertoken {id} {
5016 global ordertok curview varcid varcstart varctok curview parents children
5017 global nullid nullid2
5019 if {[info exists ordertok($id)]} {
5020 return $ordertok($id)
5025 if {[info exists varcid($curview,$id)]} {
5026 set a $varcid($curview,$id)
5027 set p [lindex $varcstart($curview) $a]
5029 set p [lindex $children($curview,$id) 0]
5031 if {[info exists ordertok($p)]} {
5032 set tok $ordertok($p)
5035 set id [first_real_child $curview,$p]
5038 set tok [lindex $varctok($curview) $varcid($curview,$p)]
5041 if {[llength $parents($curview,$id)] == 1} {
5042 lappend todo [list $p {}]
5044 set j [lsearch -exact $parents($curview,$id) $p]
5046 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5048 lappend todo [list $p [strrep $j]]
5051 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5052 set p [lindex $todo $i 0]
5053 append tok [lindex $todo $i 1]
5054 set ordertok($p) $tok
5056 set ordertok($origid) $tok
5060 # Work out where id should go in idlist so that order-token
5061 # values increase from left to right
5062 proc idcol {idlist id {i 0}} {
5063 set t [ordertoken $id]
5067 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5068 if {$i > [llength $idlist]} {
5069 set i [llength $idlist]
5071 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5074 if {$t > [ordertoken [lindex $idlist $i]]} {
5075 while {[incr i] < [llength $idlist] &&
5076 $t >= [ordertoken [lindex $idlist $i]]} {}
5082 proc initlayout {} {
5083 global rowidlist rowisopt rowfinal displayorder parentlist
5084 global numcommits canvxmax canv
5086 global colormap rowtextx
5095 set canvxmax [$canv cget -width]
5096 catch {unset colormap}
5097 catch {unset rowtextx}
5101 proc setcanvscroll {} {
5102 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5103 global lastscrollset lastscrollrows
5105 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5106 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5107 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5108 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5109 set lastscrollset [clock clicks -milliseconds]
5110 set lastscrollrows $numcommits
5113 proc visiblerows {} {
5114 global canv numcommits linespc
5116 set ymax [lindex [$canv cget -scrollregion] 3]
5117 if {$ymax eq {} || $ymax == 0} return
5119 set y0 [expr {int([lindex $f 0] * $ymax)}]
5120 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5124 set y1 [expr {int([lindex $f 1] * $ymax)}]
5125 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5126 if {$r1 >= $numcommits} {
5127 set r1 [expr {$numcommits - 1}]
5129 return [list $r0 $r1]
5132 proc layoutmore {} {
5133 global commitidx viewcomplete curview
5134 global numcommits pending_select curview
5135 global lastscrollset lastscrollrows
5137 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5138 [clock clicks -milliseconds] - $lastscrollset > 500} {
5141 if {[info exists pending_select] &&
5142 [commitinview $pending_select $curview]} {
5144 selectline [rowofcommit $pending_select] 1
5149 # With path limiting, we mightn't get the actual HEAD commit,
5150 # so ask git rev-list what is the first ancestor of HEAD that
5151 # touches a file in the path limit.
5152 proc get_viewmainhead {view} {
5153 global viewmainheadid vfilelimit viewinstances mainheadid
5156 set rfd [open [concat | git rev-list -1 $mainheadid \
5157 -- $vfilelimit($view)] r]
5158 set j [reg_instance $rfd]
5159 lappend viewinstances($view) $j
5160 fconfigure $rfd -blocking 0
5161 filerun $rfd [list getviewhead $rfd $j $view]
5162 set viewmainheadid($curview) {}
5166 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5167 proc getviewhead {fd inst view} {
5168 global viewmainheadid commfd curview viewinstances showlocalchanges
5171 if {[gets $fd line] < 0} {
5175 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5178 set viewmainheadid($view) $id
5181 set i [lsearch -exact $viewinstances($view) $inst]
5183 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5185 if {$showlocalchanges && $id ne {} && $view == $curview} {
5191 proc doshowlocalchanges {} {
5192 global curview viewmainheadid
5194 if {$viewmainheadid($curview) eq {}} return
5195 if {[commitinview $viewmainheadid($curview) $curview]} {
5198 interestedin $viewmainheadid($curview) dodiffindex
5202 proc dohidelocalchanges {} {
5203 global nullid nullid2 lserial curview
5205 if {[commitinview $nullid $curview]} {
5206 removefakerow $nullid
5208 if {[commitinview $nullid2 $curview]} {
5209 removefakerow $nullid2
5214 # spawn off a process to do git diff-index --cached HEAD
5215 proc dodiffindex {} {
5216 global lserial showlocalchanges vfilelimit curview
5217 global hasworktree git_version
5219 if {!$showlocalchanges || !$hasworktree} return
5221 if {[package vcompare $git_version "1.7.2"] >= 0} {
5222 set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
5224 set cmd "|git diff-index --cached HEAD"
5226 if {$vfilelimit($curview) ne {}} {
5227 set cmd [concat $cmd -- $vfilelimit($curview)]
5229 set fd [open $cmd r]
5230 fconfigure $fd -blocking 0
5231 set i [reg_instance $fd]
5232 filerun $fd [list readdiffindex $fd $lserial $i]
5235 proc readdiffindex {fd serial inst} {
5236 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5240 if {[gets $fd line] < 0} {
5246 # we only need to see one line and we don't really care what it says...
5249 if {$serial != $lserial} {
5253 # now see if there are any local changes not checked in to the index
5254 set cmd "|git diff-files"
5255 if {$vfilelimit($curview) ne {}} {
5256 set cmd [concat $cmd -- $vfilelimit($curview)]
5258 set fd [open $cmd r]
5259 fconfigure $fd -blocking 0
5260 set i [reg_instance $fd]
5261 filerun $fd [list readdifffiles $fd $serial $i]
5263 if {$isdiff && ![commitinview $nullid2 $curview]} {
5264 # add the line for the changes in the index to the graph
5265 set hl [mc "Local changes checked in to index but not committed"]
5266 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5267 set commitdata($nullid2) "\n $hl\n"
5268 if {[commitinview $nullid $curview]} {
5269 removefakerow $nullid
5271 insertfakerow $nullid2 $viewmainheadid($curview)
5272 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5273 if {[commitinview $nullid $curview]} {
5274 removefakerow $nullid
5276 removefakerow $nullid2
5281 proc readdifffiles {fd serial inst} {
5282 global viewmainheadid nullid nullid2 curview
5283 global commitinfo commitdata lserial
5286 if {[gets $fd line] < 0} {
5292 # we only need to see one line and we don't really care what it says...
5295 if {$serial != $lserial} {
5299 if {$isdiff && ![commitinview $nullid $curview]} {
5300 # add the line for the local diff to the graph
5301 set hl [mc "Local uncommitted changes, not checked in to index"]
5302 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5303 set commitdata($nullid) "\n $hl\n"
5304 if {[commitinview $nullid2 $curview]} {
5307 set p $viewmainheadid($curview)
5309 insertfakerow $nullid $p
5310 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5311 removefakerow $nullid
5316 proc nextuse {id row} {
5317 global curview children
5319 if {[info exists children($curview,$id)]} {
5320 foreach kid $children($curview,$id) {
5321 if {![commitinview $kid $curview]} {
5324 if {[rowofcommit $kid] > $row} {
5325 return [rowofcommit $kid]
5329 if {[commitinview $id $curview]} {
5330 return [rowofcommit $id]
5335 proc prevuse {id row} {
5336 global curview children
5339 if {[info exists children($curview,$id)]} {
5340 foreach kid $children($curview,$id) {
5341 if {![commitinview $kid $curview]} break
5342 if {[rowofcommit $kid] < $row} {
5343 set ret [rowofcommit $kid]
5350 proc make_idlist {row} {
5351 global displayorder parentlist uparrowlen downarrowlen mingaplen
5352 global commitidx curview children
5354 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5358 set ra [expr {$row - $downarrowlen}]
5362 set rb [expr {$row + $uparrowlen}]
5363 if {$rb > $commitidx($curview)} {
5364 set rb $commitidx($curview)
5366 make_disporder $r [expr {$rb + 1}]
5368 for {} {$r < $ra} {incr r} {
5369 set nextid [lindex $displayorder [expr {$r + 1}]]
5370 foreach p [lindex $parentlist $r] {
5371 if {$p eq $nextid} continue
5372 set rn [nextuse $p $r]
5374 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5375 lappend ids [list [ordertoken $p] $p]
5379 for {} {$r < $row} {incr r} {
5380 set nextid [lindex $displayorder [expr {$r + 1}]]
5381 foreach p [lindex $parentlist $r] {
5382 if {$p eq $nextid} continue
5383 set rn [nextuse $p $r]
5384 if {$rn < 0 || $rn >= $row} {
5385 lappend ids [list [ordertoken $p] $p]
5389 set id [lindex $displayorder $row]
5390 lappend ids [list [ordertoken $id] $id]
5392 foreach p [lindex $parentlist $r] {
5393 set firstkid [lindex $children($curview,$p) 0]
5394 if {[rowofcommit $firstkid] < $row} {
5395 lappend ids [list [ordertoken $p] $p]
5399 set id [lindex $displayorder $r]
5401 set firstkid [lindex $children($curview,$id) 0]
5402 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5403 lappend ids [list [ordertoken $id] $id]
5408 foreach idx [lsort -unique $ids] {
5409 lappend idlist [lindex $idx 1]
5414 proc rowsequal {a b} {
5415 while {[set i [lsearch -exact $a {}]] >= 0} {
5416 set a [lreplace $a $i $i]
5418 while {[set i [lsearch -exact $b {}]] >= 0} {
5419 set b [lreplace $b $i $i]
5421 return [expr {$a eq $b}]
5424 proc makeupline {id row rend col} {
5425 global rowidlist uparrowlen downarrowlen mingaplen
5427 for {set r $rend} {1} {set r $rstart} {
5428 set rstart [prevuse $id $r]
5429 if {$rstart < 0} return
5430 if {$rstart < $row} break
5432 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5433 set rstart [expr {$rend - $uparrowlen - 1}]
5435 for {set r $rstart} {[incr r] <= $row} {} {
5436 set idlist [lindex $rowidlist $r]
5437 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5438 set col [idcol $idlist $id $col]
5439 lset rowidlist $r [linsert $idlist $col $id]
5445 proc layoutrows {row endrow} {
5446 global rowidlist rowisopt rowfinal displayorder
5447 global uparrowlen downarrowlen maxwidth mingaplen
5448 global children parentlist
5449 global commitidx viewcomplete curview
5451 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5454 set rm1 [expr {$row - 1}]
5455 foreach id [lindex $rowidlist $rm1] {
5460 set final [lindex $rowfinal $rm1]
5462 for {} {$row < $endrow} {incr row} {
5463 set rm1 [expr {$row - 1}]
5464 if {$rm1 < 0 || $idlist eq {}} {
5465 set idlist [make_idlist $row]
5468 set id [lindex $displayorder $rm1]
5469 set col [lsearch -exact $idlist $id]
5470 set idlist [lreplace $idlist $col $col]
5471 foreach p [lindex $parentlist $rm1] {
5472 if {[lsearch -exact $idlist $p] < 0} {
5473 set col [idcol $idlist $p $col]
5474 set idlist [linsert $idlist $col $p]
5475 # if not the first child, we have to insert a line going up
5476 if {$id ne [lindex $children($curview,$p) 0]} {
5477 makeupline $p $rm1 $row $col
5481 set id [lindex $displayorder $row]
5482 if {$row > $downarrowlen} {
5483 set termrow [expr {$row - $downarrowlen - 1}]
5484 foreach p [lindex $parentlist $termrow] {
5485 set i [lsearch -exact $idlist $p]
5486 if {$i < 0} continue
5487 set nr [nextuse $p $termrow]
5488 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5489 set idlist [lreplace $idlist $i $i]
5493 set col [lsearch -exact $idlist $id]
5495 set col [idcol $idlist $id]
5496 set idlist [linsert $idlist $col $id]
5497 if {$children($curview,$id) ne {}} {
5498 makeupline $id $rm1 $row $col
5501 set r [expr {$row + $uparrowlen - 1}]
5502 if {$r < $commitidx($curview)} {
5504 foreach p [lindex $parentlist $r] {
5505 if {[lsearch -exact $idlist $p] >= 0} continue
5506 set fk [lindex $children($curview,$p) 0]
5507 if {[rowofcommit $fk] < $row} {
5508 set x [idcol $idlist $p $x]
5509 set idlist [linsert $idlist $x $p]
5512 if {[incr r] < $commitidx($curview)} {
5513 set p [lindex $displayorder $r]
5514 if {[lsearch -exact $idlist $p] < 0} {
5515 set fk [lindex $children($curview,$p) 0]
5516 if {$fk ne {} && [rowofcommit $fk] < $row} {
5517 set x [idcol $idlist $p $x]
5518 set idlist [linsert $idlist $x $p]
5524 if {$final && !$viewcomplete($curview) &&
5525 $row + $uparrowlen + $mingaplen + $downarrowlen
5526 >= $commitidx($curview)} {
5529 set l [llength $rowidlist]
5531 lappend rowidlist $idlist
5533 lappend rowfinal $final
5534 } elseif {$row < $l} {
5535 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5536 lset rowidlist $row $idlist
5539 lset rowfinal $row $final
5541 set pad [ntimes [expr {$row - $l}] {}]
5542 set rowidlist [concat $rowidlist $pad]
5543 lappend rowidlist $idlist
5544 set rowfinal [concat $rowfinal $pad]
5545 lappend rowfinal $final
5546 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5552 proc changedrow {row} {
5553 global displayorder iddrawn rowisopt need_redisplay
5555 set l [llength $rowisopt]
5557 lset rowisopt $row 0
5558 if {$row + 1 < $l} {
5559 lset rowisopt [expr {$row + 1}] 0
5560 if {$row + 2 < $l} {
5561 lset rowisopt [expr {$row + 2}] 0
5565 set id [lindex $displayorder $row]
5566 if {[info exists iddrawn($id)]} {
5567 set need_redisplay 1
5571 proc insert_pad {row col npad} {
5574 set pad [ntimes $npad {}]
5575 set idlist [lindex $rowidlist $row]
5576 set bef [lrange $idlist 0 [expr {$col - 1}]]
5577 set aft [lrange $idlist $col end]
5578 set i [lsearch -exact $aft {}]
5580 set aft [lreplace $aft $i $i]
5582 lset rowidlist $row [concat $bef $pad $aft]
5586 proc optimize_rows {row col endrow} {
5587 global rowidlist rowisopt displayorder curview children
5592 for {} {$row < $endrow} {incr row; set col 0} {
5593 if {[lindex $rowisopt $row]} continue
5595 set y0 [expr {$row - 1}]
5596 set ym [expr {$row - 2}]
5597 set idlist [lindex $rowidlist $row]
5598 set previdlist [lindex $rowidlist $y0]
5599 if {$idlist eq {} || $previdlist eq {}} continue
5601 set pprevidlist [lindex $rowidlist $ym]
5602 if {$pprevidlist eq {}} continue
5608 for {} {$col < [llength $idlist]} {incr col} {
5609 set id [lindex $idlist $col]
5610 if {[lindex $previdlist $col] eq $id} continue
5615 set x0 [lsearch -exact $previdlist $id]
5616 if {$x0 < 0} continue
5617 set z [expr {$x0 - $col}]
5621 set xm [lsearch -exact $pprevidlist $id]
5623 set z0 [expr {$xm - $x0}]
5627 # if row y0 is the first child of $id then it's not an arrow
5628 if {[lindex $children($curview,$id) 0] ne
5629 [lindex $displayorder $y0]} {
5633 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5634 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5637 # Looking at lines from this row to the previous row,
5638 # make them go straight up if they end in an arrow on
5639 # the previous row; otherwise make them go straight up
5641 if {$z < -1 || ($z < 0 && $isarrow)} {
5642 # Line currently goes left too much;
5643 # insert pads in the previous row, then optimize it
5644 set npad [expr {-1 - $z + $isarrow}]
5645 insert_pad $y0 $x0 $npad
5647 optimize_rows $y0 $x0 $row
5649 set previdlist [lindex $rowidlist $y0]
5650 set x0 [lsearch -exact $previdlist $id]
5651 set z [expr {$x0 - $col}]
5653 set pprevidlist [lindex $rowidlist $ym]
5654 set xm [lsearch -exact $pprevidlist $id]
5655 set z0 [expr {$xm - $x0}]
5657 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5658 # Line currently goes right too much;
5659 # insert pads in this line
5660 set npad [expr {$z - 1 + $isarrow}]
5661 insert_pad $row $col $npad
5662 set idlist [lindex $rowidlist $row]
5664 set z [expr {$x0 - $col}]
5667 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5668 # this line links to its first child on row $row-2
5669 set id [lindex $displayorder $ym]
5670 set xc [lsearch -exact $pprevidlist $id]
5672 set z0 [expr {$xc - $x0}]
5675 # avoid lines jigging left then immediately right
5676 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5677 insert_pad $y0 $x0 1
5679 optimize_rows $y0 $x0 $row
5680 set previdlist [lindex $rowidlist $y0]
5684 # Find the first column that doesn't have a line going right
5685 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5686 set id [lindex $idlist $col]
5687 if {$id eq {}} break
5688 set x0 [lsearch -exact $previdlist $id]
5690 # check if this is the link to the first child
5691 set kid [lindex $displayorder $y0]
5692 if {[lindex $children($curview,$id) 0] eq $kid} {
5693 # it is, work out offset to child
5694 set x0 [lsearch -exact $previdlist $kid]
5697 if {$x0 <= $col} break
5699 # Insert a pad at that column as long as it has a line and
5700 # isn't the last column
5701 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5702 set idlist [linsert $idlist $col {}]
5703 lset rowidlist $row $idlist
5711 global canvx0 linespc
5712 return [expr {$canvx0 + $col * $linespc}]
5716 global canvy0 linespc
5717 return [expr {$canvy0 + $row * $linespc}]
5720 proc linewidth {id} {
5721 global thickerline lthickness
5724 if {[info exists thickerline] && $id eq $thickerline} {
5725 set wid [expr {2 * $lthickness}]
5730 proc rowranges {id} {
5731 global curview children uparrowlen downarrowlen
5734 set kids $children($curview,$id)
5740 foreach child $kids {
5741 if {![commitinview $child $curview]} break
5742 set row [rowofcommit $child]
5743 if {![info exists prev]} {
5744 lappend ret [expr {$row + 1}]
5746 if {$row <= $prevrow} {
5747 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5749 # see if the line extends the whole way from prevrow to row
5750 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5751 [lsearch -exact [lindex $rowidlist \
5752 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5753 # it doesn't, see where it ends
5754 set r [expr {$prevrow + $downarrowlen}]
5755 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5756 while {[incr r -1] > $prevrow &&
5757 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5759 while {[incr r] <= $row &&
5760 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5764 # see where it starts up again
5765 set r [expr {$row - $uparrowlen}]
5766 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5767 while {[incr r] < $row &&
5768 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5770 while {[incr r -1] >= $prevrow &&
5771 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5777 if {$child eq $id} {
5786 proc drawlineseg {id row endrow arrowlow} {
5787 global rowidlist displayorder iddrawn linesegs
5788 global canv colormap linespc curview maxlinelen parentlist
5790 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5791 set le [expr {$row + 1}]
5794 set c [lsearch -exact [lindex $rowidlist $le] $id]
5800 set x [lindex $displayorder $le]
5805 if {[info exists iddrawn($x)] || $le == $endrow} {
5806 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5822 if {[info exists linesegs($id)]} {
5823 set lines $linesegs($id)
5825 set r0 [lindex $li 0]
5827 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5837 set li [lindex $lines [expr {$i-1}]]
5838 set r1 [lindex $li 1]
5839 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5844 set x [lindex $cols [expr {$le - $row}]]
5845 set xp [lindex $cols [expr {$le - 1 - $row}]]
5846 set dir [expr {$xp - $x}]
5848 set ith [lindex $lines $i 2]
5849 set coords [$canv coords $ith]
5850 set ah [$canv itemcget $ith -arrow]
5851 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5852 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5853 if {$x2 ne {} && $x - $x2 == $dir} {
5854 set coords [lrange $coords 0 end-2]
5857 set coords [list [xc $le $x] [yc $le]]
5860 set itl [lindex $lines [expr {$i-1}] 2]
5861 set al [$canv itemcget $itl -arrow]
5862 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5863 } elseif {$arrowlow} {
5864 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5865 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5869 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5870 for {set y $le} {[incr y -1] > $row} {} {
5872 set xp [lindex $cols [expr {$y - 1 - $row}]]
5873 set ndir [expr {$xp - $x}]
5874 if {$dir != $ndir || $xp < 0} {
5875 lappend coords [xc $y $x] [yc $y]
5881 # join parent line to first child
5882 set ch [lindex $displayorder $row]
5883 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5885 puts "oops: drawlineseg: child $ch not on row $row"
5886 } elseif {$xc != $x} {
5887 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5888 set d [expr {int(0.5 * $linespc)}]
5891 set x2 [expr {$x1 - $d}]
5893 set x2 [expr {$x1 + $d}]
5896 set y1 [expr {$y2 + $d}]
5897 lappend coords $x1 $y1 $x2 $y2
5898 } elseif {$xc < $x - 1} {
5899 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5900 } elseif {$xc > $x + 1} {
5901 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5905 lappend coords [xc $row $x] [yc $row]
5907 set xn [xc $row $xp]
5909 lappend coords $xn $yn
5913 set t [$canv create line $coords -width [linewidth $id] \
5914 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5917 set lines [linsert $lines $i [list $row $le $t]]
5919 $canv coords $ith $coords
5920 if {$arrow ne $ah} {
5921 $canv itemconf $ith -arrow $arrow
5923 lset lines $i 0 $row
5926 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5927 set ndir [expr {$xo - $xp}]
5928 set clow [$canv coords $itl]
5929 if {$dir == $ndir} {
5930 set clow [lrange $clow 2 end]
5932 set coords [concat $coords $clow]
5934 lset lines [expr {$i-1}] 1 $le
5936 # coalesce two pieces
5938 set b [lindex $lines [expr {$i-1}] 0]
5939 set e [lindex $lines $i 1]
5940 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5942 $canv coords $itl $coords
5943 if {$arrow ne $al} {
5944 $canv itemconf $itl -arrow $arrow
5948 set linesegs($id) $lines
5952 proc drawparentlinks {id row} {
5953 global rowidlist canv colormap curview parentlist
5954 global idpos linespc
5956 set rowids [lindex $rowidlist $row]
5957 set col [lsearch -exact $rowids $id]
5958 if {$col < 0} return
5959 set olds [lindex $parentlist $row]
5960 set row2 [expr {$row + 1}]
5961 set x [xc $row $col]
5964 set d [expr {int(0.5 * $linespc)}]
5965 set ymid [expr {$y + $d}]
5966 set ids [lindex $rowidlist $row2]
5967 # rmx = right-most X coord used
5970 set i [lsearch -exact $ids $p]
5972 puts "oops, parent $p of $id not in list"
5975 set x2 [xc $row2 $i]
5979 set j [lsearch -exact $rowids $p]
5981 # drawlineseg will do this one for us
5985 # should handle duplicated parents here...
5986 set coords [list $x $y]
5988 # if attaching to a vertical segment, draw a smaller
5989 # slant for visual distinctness
5992 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5994 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5996 } elseif {$i < $col && $i < $j} {
5997 # segment slants towards us already
5998 lappend coords [xc $row $j] $y
6000 if {$i < $col - 1} {
6001 lappend coords [expr {$x2 + $linespc}] $y
6002 } elseif {$i > $col + 1} {
6003 lappend coords [expr {$x2 - $linespc}] $y
6005 lappend coords $x2 $y2
6008 lappend coords $x2 $y2
6010 set t [$canv create line $coords -width [linewidth $p] \
6011 -fill $colormap($p) -tags lines.$p]
6015 if {$rmx > [lindex $idpos($id) 1]} {
6016 lset idpos($id) 1 $rmx
6021 proc drawlines {id} {
6024 $canv itemconf lines.$id -width [linewidth $id]
6027 proc drawcmittext {id row col} {
6028 global linespc canv canv2 canv3 fgcolor curview
6029 global cmitlisted commitinfo rowidlist parentlist
6030 global rowtextx idpos idtags idheads idotherrefs
6031 global linehtag linentag linedtag selectedline
6032 global canvxmax boldids boldnameids fgcolor markedid
6033 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
6034 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
6035 global circleoutlinecolor
6037 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
6038 set listed $cmitlisted($curview,$id)
6039 if {$id eq $nullid} {
6040 set ofill $workingfilescirclecolor
6041 } elseif {$id eq $nullid2} {
6042 set ofill $indexcirclecolor
6043 } elseif {$id eq $mainheadid} {
6044 set ofill $mainheadcirclecolor
6046 set ofill [lindex $circlecolors $listed]
6048 set x [xc $row $col]
6050 set orad [expr {$linespc / 3}]
6052 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6053 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6054 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6055 } elseif {$listed == 3} {
6056 # triangle pointing left for left-side commits
6057 set t [$canv create polygon \
6058 [expr {$x - $orad}] $y \
6059 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6060 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6061 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6063 # triangle pointing right for right-side commits
6064 set t [$canv create polygon \
6065 [expr {$x + $orad - 1}] $y \
6066 [expr {$x - $orad}] [expr {$y - $orad}] \
6067 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6068 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6070 set circleitem($row) $t
6072 $canv bind $t <1> {selcanvline {} %x %y}
6073 set rmx [llength [lindex $rowidlist $row]]
6074 set olds [lindex $parentlist $row]
6076 set nextids [lindex $rowidlist [expr {$row + 1}]]
6078 set i [lsearch -exact $nextids $p]
6084 set xt [xc $row $rmx]
6085 set rowtextx($row) $xt
6086 set idpos($id) [list $x $xt $y]
6087 if {[info exists idtags($id)] || [info exists idheads($id)]
6088 || [info exists idotherrefs($id)]} {
6089 set xt [drawtags $id $x $xt $y]
6091 if {[lindex $commitinfo($id) 6] > 0} {
6092 set xt [drawnotesign $xt $y]
6094 set headline [lindex $commitinfo($id) 0]
6095 set name [lindex $commitinfo($id) 1]
6096 set date [lindex $commitinfo($id) 2]
6097 set date [formatdate $date]
6100 set isbold [ishighlighted $id]
6103 set font mainfontbold
6105 lappend boldnameids $id
6106 set nfont mainfontbold
6109 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6110 -text $headline -font $font -tags text]
6111 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6112 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6113 -text $name -font $nfont -tags text]
6114 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6115 -text $date -font mainfont -tags text]
6116 if {$selectedline == $row} {
6119 if {[info exists markedid] && $markedid eq $id} {
6122 set xr [expr {$xt + [font measure $font $headline]}]
6123 if {$xr > $canvxmax} {
6129 proc drawcmitrow {row} {
6130 global displayorder rowidlist nrows_drawn
6131 global iddrawn markingmatches
6132 global commitinfo numcommits
6133 global filehighlight fhighlights findpattern nhighlights
6134 global hlview vhighlights
6135 global highlight_related rhighlights
6137 if {$row >= $numcommits} return
6139 set id [lindex $displayorder $row]
6140 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6141 askvhighlight $row $id
6143 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6144 askfilehighlight $row $id
6146 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6147 askfindhighlight $row $id
6149 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6150 askrelhighlight $row $id
6152 if {![info exists iddrawn($id)]} {
6153 set col [lsearch -exact [lindex $rowidlist $row] $id]
6155 puts "oops, row $row id $id not in list"
6158 if {![info exists commitinfo($id)]} {
6162 drawcmittext $id $row $col
6166 if {$markingmatches} {
6167 markrowmatches $row $id
6171 proc drawcommits {row {endrow {}}} {
6172 global numcommits iddrawn displayorder curview need_redisplay
6173 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6178 if {$endrow eq {}} {
6181 if {$endrow >= $numcommits} {
6182 set endrow [expr {$numcommits - 1}]
6185 set rl1 [expr {$row - $downarrowlen - 3}]
6189 set ro1 [expr {$row - 3}]
6193 set r2 [expr {$endrow + $uparrowlen + 3}]
6194 if {$r2 > $numcommits} {
6197 for {set r $rl1} {$r < $r2} {incr r} {
6198 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6202 set rl1 [expr {$r + 1}]
6208 optimize_rows $ro1 0 $r2
6209 if {$need_redisplay || $nrows_drawn > 2000} {
6213 # make the lines join to already-drawn rows either side
6214 set r [expr {$row - 1}]
6215 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6218 set er [expr {$endrow + 1}]
6219 if {$er >= $numcommits ||
6220 ![info exists iddrawn([lindex $displayorder $er])]} {
6223 for {} {$r <= $er} {incr r} {
6224 set id [lindex $displayorder $r]
6225 set wasdrawn [info exists iddrawn($id)]
6227 if {$r == $er} break
6228 set nextid [lindex $displayorder [expr {$r + 1}]]
6229 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6230 drawparentlinks $id $r
6232 set rowids [lindex $rowidlist $r]
6233 foreach lid $rowids {
6234 if {$lid eq {}} continue
6235 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6237 # see if this is the first child of any of its parents
6238 foreach p [lindex $parentlist $r] {
6239 if {[lsearch -exact $rowids $p] < 0} {
6240 # make this line extend up to the child
6241 set lineend($p) [drawlineseg $p $r $er 0]
6245 set lineend($lid) [drawlineseg $lid $r $er 1]
6251 proc undolayout {row} {
6252 global uparrowlen mingaplen downarrowlen
6253 global rowidlist rowisopt rowfinal need_redisplay
6255 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6259 if {[llength $rowidlist] > $r} {
6261 set rowidlist [lrange $rowidlist 0 $r]
6262 set rowfinal [lrange $rowfinal 0 $r]
6263 set rowisopt [lrange $rowisopt 0 $r]
6264 set need_redisplay 1
6269 proc drawvisible {} {
6270 global canv linespc curview vrowmod selectedline targetrow targetid
6271 global need_redisplay cscroll numcommits
6273 set fs [$canv yview]
6274 set ymax [lindex [$canv cget -scrollregion] 3]
6275 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6276 set f0 [lindex $fs 0]
6277 set f1 [lindex $fs 1]
6278 set y0 [expr {int($f0 * $ymax)}]
6279 set y1 [expr {int($f1 * $ymax)}]
6281 if {[info exists targetid]} {
6282 if {[commitinview $targetid $curview]} {
6283 set r [rowofcommit $targetid]
6284 if {$r != $targetrow} {
6285 # Fix up the scrollregion and change the scrolling position
6286 # now that our target row has moved.
6287 set diff [expr {($r - $targetrow) * $linespc}]
6290 set ymax [lindex [$canv cget -scrollregion] 3]
6293 set f0 [expr {$y0 / $ymax}]
6294 set f1 [expr {$y1 / $ymax}]
6295 allcanvs yview moveto $f0
6296 $cscroll set $f0 $f1
6297 set need_redisplay 1
6304 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6305 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6306 if {$endrow >= $vrowmod($curview)} {
6307 update_arcrows $curview
6309 if {$selectedline ne {} &&
6310 $row <= $selectedline && $selectedline <= $endrow} {
6311 set targetrow $selectedline
6312 } elseif {[info exists targetid]} {
6313 set targetrow [expr {int(($row + $endrow) / 2)}]
6315 if {[info exists targetrow]} {
6316 if {$targetrow >= $numcommits} {
6317 set targetrow [expr {$numcommits - 1}]
6319 set targetid [commitonrow $targetrow]
6321 drawcommits $row $endrow
6324 proc clear_display {} {
6325 global iddrawn linesegs need_redisplay nrows_drawn
6326 global vhighlights fhighlights nhighlights rhighlights
6327 global linehtag linentag linedtag boldids boldnameids
6330 catch {unset iddrawn}
6331 catch {unset linesegs}
6332 catch {unset linehtag}
6333 catch {unset linentag}
6334 catch {unset linedtag}
6337 catch {unset vhighlights}
6338 catch {unset fhighlights}
6339 catch {unset nhighlights}
6340 catch {unset rhighlights}
6341 set need_redisplay 0
6345 proc findcrossings {id} {
6346 global rowidlist parentlist numcommits displayorder
6350 foreach {s e} [rowranges $id] {
6351 if {$e >= $numcommits} {
6352 set e [expr {$numcommits - 1}]
6354 if {$e <= $s} continue
6355 for {set row $e} {[incr row -1] >= $s} {} {
6356 set x [lsearch -exact [lindex $rowidlist $row] $id]
6358 set olds [lindex $parentlist $row]
6359 set kid [lindex $displayorder $row]
6360 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6361 if {$kidx < 0} continue
6362 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6364 set px [lsearch -exact $nextrow $p]
6365 if {$px < 0} continue
6366 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6367 if {[lsearch -exact $ccross $p] >= 0} continue
6368 if {$x == $px + ($kidx < $px? -1: 1)} {
6370 } elseif {[lsearch -exact $cross $p] < 0} {
6377 return [concat $ccross {{}} $cross]
6380 proc assigncolor {id} {
6381 global colormap colors nextcolor
6382 global parents children children curview
6384 if {[info exists colormap($id)]} return
6385 set ncolors [llength $colors]
6386 if {[info exists children($curview,$id)]} {
6387 set kids $children($curview,$id)
6391 if {[llength $kids] == 1} {
6392 set child [lindex $kids 0]
6393 if {[info exists colormap($child)]
6394 && [llength $parents($curview,$child)] == 1} {
6395 set colormap($id) $colormap($child)
6401 foreach x [findcrossings $id] {
6403 # delimiter between corner crossings and other crossings
6404 if {[llength $badcolors] >= $ncolors - 1} break
6405 set origbad $badcolors
6407 if {[info exists colormap($x)]
6408 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6409 lappend badcolors $colormap($x)
6412 if {[llength $badcolors] >= $ncolors} {
6413 set badcolors $origbad
6415 set origbad $badcolors
6416 if {[llength $badcolors] < $ncolors - 1} {
6417 foreach child $kids {
6418 if {[info exists colormap($child)]
6419 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6420 lappend badcolors $colormap($child)
6422 foreach p $parents($curview,$child) {
6423 if {[info exists colormap($p)]
6424 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6425 lappend badcolors $colormap($p)
6429 if {[llength $badcolors] >= $ncolors} {
6430 set badcolors $origbad
6433 for {set i 0} {$i <= $ncolors} {incr i} {
6434 set c [lindex $colors $nextcolor]
6435 if {[incr nextcolor] >= $ncolors} {
6438 if {[lsearch -exact $badcolors $c]} break
6440 set colormap($id) $c
6443 proc bindline {t id} {
6446 $canv bind $t <Enter> "lineenter %x %y $id"
6447 $canv bind $t <Motion> "linemotion %x %y $id"
6448 $canv bind $t <Leave> "lineleave $id"
6449 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6452 proc graph_pane_width {} {
6456 set g [.tf.histframe.pwclist sashpos 0]
6458 set g [.tf.histframe.pwclist sash coord 0]
6460 return [lindex $g 0]
6463 proc totalwidth {l font extra} {
6466 set tot [expr {$tot + [font measure $font $str] + $extra}]
6471 proc drawtags {id x xt y1} {
6472 global idtags idheads idotherrefs mainhead
6473 global linespc lthickness
6474 global canv rowtextx curview fgcolor bgcolor ctxbut
6475 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6476 global tagbgcolor tagfgcolor tagoutlinecolor
6485 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6486 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6487 set extra [expr {$delta + $lthickness + $linespc}]
6489 if {[info exists idtags($id)]} {
6490 set marks $idtags($id)
6491 set ntags [llength $marks]
6492 if {$ntags > $maxtags ||
6493 [totalwidth $marks mainfont $extra] > $maxwidth} {
6494 # show just a single "n tags..." tag
6497 set marks [list "tag..."]
6499 set marks [list [format "%d tags..." $ntags]]
6504 if {[info exists idheads($id)]} {
6505 set marks [concat $marks $idheads($id)]
6506 set nheads [llength $idheads($id)]
6508 if {[info exists idotherrefs($id)]} {
6509 set marks [concat $marks $idotherrefs($id)]
6515 set yt [expr {$y1 - 0.5 * $linespc}]
6516 set yb [expr {$yt + $linespc - 1}]
6520 foreach tag $marks {
6522 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6523 set wid [font measure mainfontbold $tag]
6525 set wid [font measure mainfont $tag]
6529 set xt [expr {$xt + $wid + $extra}]
6531 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6532 -width $lthickness -fill $reflinecolor -tags tag.$id]
6534 foreach tag $marks x $xvals wid $wvals {
6535 set tag_quoted [string map {% %%} $tag]
6536 set xl [expr {$x + $delta}]
6537 set xr [expr {$x + $delta + $wid + $lthickness}]
6539 if {[incr ntags -1] >= 0} {
6541 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6542 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6543 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6546 set tagclick [list showtags $id 1]
6548 set tagclick [list showtag $tag_quoted 1]
6550 $canv bind $t <1> $tagclick
6551 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6553 # draw a head or other ref
6554 if {[incr nheads -1] >= 0} {
6555 set col $headbgcolor
6556 if {$tag eq $mainhead} {
6557 set font mainfontbold
6562 set xl [expr {$xl - $delta/2}]
6563 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6564 -width 1 -outline black -fill $col -tags tag.$id
6565 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6566 set rwid [font measure mainfont $remoteprefix]
6567 set xi [expr {$x + 1}]
6568 set yti [expr {$yt + 1}]
6569 set xri [expr {$x + $rwid}]
6570 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6571 -width 0 -fill $remotebgcolor -tags tag.$id
6574 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6575 -font $font -tags [list tag.$id text]]
6577 $canv bind $t <1> $tagclick
6578 } elseif {$nheads >= 0} {
6579 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6585 proc drawnotesign {xt y} {
6586 global linespc canv fgcolor
6588 set orad [expr {$linespc / 3}]
6589 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6590 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6591 -fill yellow -outline $fgcolor -width 1 -tags circle]
6592 set xt [expr {$xt + $orad * 3}]
6596 proc xcoord {i level ln} {
6597 global canvx0 xspc1 xspc2
6599 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6600 if {$i > 0 && $i == $level} {
6601 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6602 } elseif {$i > $level} {
6603 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6608 proc show_status {msg} {
6612 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6613 -tags text -fill $fgcolor
6616 # Don't change the text pane cursor if it is currently the hand cursor,
6617 # showing that we are over a sha1 ID link.
6618 proc settextcursor {c} {
6619 global ctext curtextcursor
6621 if {[$ctext cget -cursor] == $curtextcursor} {
6622 $ctext config -cursor $c
6624 set curtextcursor $c
6627 proc nowbusy {what {name {}}} {
6628 global isbusy busyname statusw
6630 if {[array names isbusy] eq {}} {
6631 . config -cursor watch
6635 set busyname($what) $name
6637 $statusw conf -text $name
6641 proc notbusy {what} {
6642 global isbusy maincursor textcursor busyname statusw
6646 if {$busyname($what) ne {} &&
6647 [$statusw cget -text] eq $busyname($what)} {
6648 $statusw conf -text {}
6651 if {[array names isbusy] eq {}} {
6652 . config -cursor $maincursor
6653 settextcursor $textcursor
6657 proc findmatches {f} {
6658 global findtype findstring
6659 if {$findtype == [mc "Regexp"]} {
6660 set matches [regexp -indices -all -inline $findstring $f]
6663 if {$findtype == [mc "IgnCase"]} {
6664 set f [string tolower $f]
6665 set fs [string tolower $fs]
6669 set l [string length $fs]
6670 while {[set j [string first $fs $f $i]] >= 0} {
6671 lappend matches [list $j [expr {$j+$l-1}]]
6672 set i [expr {$j + $l}]
6678 proc dofind {{dirn 1} {wrap 1}} {
6679 global findstring findstartline findcurline selectedline numcommits
6680 global gdttype filehighlight fh_serial find_dirn findallowwrap
6682 if {[info exists find_dirn]} {
6683 if {$find_dirn == $dirn} return
6687 if {$findstring eq {} || $numcommits == 0} return
6688 if {$selectedline eq {}} {
6689 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6691 set findstartline $selectedline
6693 set findcurline $findstartline
6694 nowbusy finding [mc "Searching"]
6695 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6696 after cancel do_file_hl $fh_serial
6697 do_file_hl $fh_serial
6700 set findallowwrap $wrap
6704 proc stopfinding {} {
6705 global find_dirn findcurline fprogcoord
6707 if {[info exists find_dirn]} {
6718 global commitdata commitinfo numcommits findpattern findloc
6719 global findstartline findcurline findallowwrap
6720 global find_dirn gdttype fhighlights fprogcoord
6721 global curview varcorder vrownum varccommits vrowmod
6723 if {![info exists find_dirn]} {
6726 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6729 if {$find_dirn > 0} {
6731 if {$l >= $numcommits} {
6734 if {$l <= $findstartline} {
6735 set lim [expr {$findstartline + 1}]
6738 set moretodo $findallowwrap
6745 if {$l >= $findstartline} {
6746 set lim [expr {$findstartline - 1}]
6749 set moretodo $findallowwrap
6752 set n [expr {($lim - $l) * $find_dirn}]
6757 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6758 update_arcrows $curview
6762 set ai [bsearch $vrownum($curview) $l]
6763 set a [lindex $varcorder($curview) $ai]
6764 set arow [lindex $vrownum($curview) $ai]
6765 set ids [lindex $varccommits($curview,$a)]
6766 set arowend [expr {$arow + [llength $ids]}]
6767 if {$gdttype eq [mc "containing:"]} {
6768 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6769 if {$l < $arow || $l >= $arowend} {
6771 set a [lindex $varcorder($curview) $ai]
6772 set arow [lindex $vrownum($curview) $ai]
6773 set ids [lindex $varccommits($curview,$a)]
6774 set arowend [expr {$arow + [llength $ids]}]
6776 set id [lindex $ids [expr {$l - $arow}]]
6777 # shouldn't happen unless git log doesn't give all the commits...
6778 if {![info exists commitdata($id)] ||
6779 ![doesmatch $commitdata($id)]} {
6782 if {![info exists commitinfo($id)]} {
6785 set info $commitinfo($id)
6786 foreach f $info ty $fldtypes {
6787 if {$ty eq ""} continue
6788 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6797 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6798 if {$l < $arow || $l >= $arowend} {
6800 set a [lindex $varcorder($curview) $ai]
6801 set arow [lindex $vrownum($curview) $ai]
6802 set ids [lindex $varccommits($curview,$a)]
6803 set arowend [expr {$arow + [llength $ids]}]
6805 set id [lindex $ids [expr {$l - $arow}]]
6806 if {![info exists fhighlights($id)]} {
6807 # this sets fhighlights($id) to -1
6808 askfilehighlight $l $id
6810 if {$fhighlights($id) > 0} {
6814 if {$fhighlights($id) < 0} {
6817 set findcurline [expr {$l - $find_dirn}]
6822 if {$found || ($domore && !$moretodo)} {
6838 set findcurline [expr {$l - $find_dirn}]
6840 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6844 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6849 proc findselectline {l} {
6850 global findloc commentend ctext findcurline markingmatches gdttype
6852 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6855 if {$markingmatches &&
6856 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6857 # highlight the matches in the comments
6858 set f [$ctext get 1.0 $commentend]
6859 set matches [findmatches $f]
6860 foreach match $matches {
6861 set start [lindex $match 0]
6862 set end [expr {[lindex $match 1] + 1}]
6863 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6869 # mark the bits of a headline or author that match a find string
6870 proc markmatches {canv l str tag matches font row} {
6873 set bbox [$canv bbox $tag]
6874 set x0 [lindex $bbox 0]
6875 set y0 [lindex $bbox 1]
6876 set y1 [lindex $bbox 3]
6877 foreach match $matches {
6878 set start [lindex $match 0]
6879 set end [lindex $match 1]
6880 if {$start > $end} continue
6881 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6882 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6883 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6884 [expr {$x0+$xlen+2}] $y1 \
6885 -outline {} -tags [list match$l matches] -fill yellow]
6887 if {$row == $selectedline} {
6888 $canv raise $t secsel
6893 proc unmarkmatches {} {
6894 global markingmatches
6896 allcanvs delete matches
6897 set markingmatches 0
6901 proc selcanvline {w x y} {
6902 global canv canvy0 ctext linespc
6904 set ymax [lindex [$canv cget -scrollregion] 3]
6905 if {$ymax == {}} return
6906 set yfrac [lindex [$canv yview] 0]
6907 set y [expr {$y + $yfrac * $ymax}]
6908 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6913 set xmax [lindex [$canv cget -scrollregion] 2]
6914 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6915 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6921 proc commit_descriptor {p} {
6923 if {![info exists commitinfo($p)]} {
6927 if {[llength $commitinfo($p)] > 1} {
6928 set l [lindex $commitinfo($p) 0]
6933 # append some text to the ctext widget, and make any SHA1 ID
6934 # that we know about be a clickable link.
6935 proc appendwithlinks {text tags} {
6936 global ctext linknum curview
6938 set start [$ctext index "end - 1c"]
6939 $ctext insert end $text $tags
6940 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6944 set linkid [string range $text $s $e]
6946 $ctext tag delete link$linknum
6947 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6948 setlink $linkid link$linknum
6953 proc setlink {id lk} {
6954 global curview ctext pendinglinks
6957 if {[string range $id 0 1] eq "-g"} {
6958 set id [string range $id 2 end]
6962 if {[string length $id] < 40} {
6963 set matches [longid $id]
6964 if {[llength $matches] > 0} {
6965 if {[llength $matches] > 1} return
6967 set id [lindex $matches 0]
6970 set known [commitinview $id $curview]
6973 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6974 $ctext tag bind $lk <1> [list selbyid $id]
6975 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6976 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6978 lappend pendinglinks($id) $lk
6979 interestedin $id {makelink %P}
6983 proc appendshortlink {id {pre {}} {post {}}} {
6984 global ctext linknum
6986 $ctext insert end $pre
6987 $ctext tag delete link$linknum
6988 $ctext insert end [string range $id 0 7] link$linknum
6989 $ctext insert end $post
6990 setlink $id link$linknum
6994 proc makelink {id} {
6997 if {![info exists pendinglinks($id)]} return
6998 foreach lk $pendinglinks($id) {
7001 unset pendinglinks($id)
7004 proc linkcursor {w inc} {
7005 global linkentercount curtextcursor
7007 if {[incr linkentercount $inc] > 0} {
7008 $w configure -cursor hand2
7010 $w configure -cursor $curtextcursor
7011 if {$linkentercount < 0} {
7012 set linkentercount 0
7017 proc viewnextline {dir} {
7021 set ymax [lindex [$canv cget -scrollregion] 3]
7022 set wnow [$canv yview]
7023 set wtop [expr {[lindex $wnow 0] * $ymax}]
7024 set newtop [expr {$wtop + $dir * $linespc}]
7027 } elseif {$newtop > $ymax} {
7030 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7033 # add a list of tag or branch names at position pos
7034 # returns the number of names inserted
7035 proc appendrefs {pos ids var} {
7036 global ctext linknum curview $var maxrefs mainheadid
7038 if {[catch {$ctext index $pos}]} {
7041 $ctext conf -state normal
7042 $ctext delete $pos "$pos lineend"
7045 foreach tag [set $var\($id\)] {
7046 lappend tags [list $tag $id]
7051 set tags [lsort -index 0 -decreasing $tags]
7054 if {[llength $tags] > $maxrefs} {
7055 # If we are displaying heads, and there are too many,
7056 # see if there are some important heads to display.
7057 # Currently this means "master" and the current head.
7059 if {$var eq "idheads"} {
7062 set hname [lindex $ti 0]
7063 set id [lindex $ti 1]
7064 if {($hname eq "master" || $id eq $mainheadid) &&
7065 [llength $itags] < $maxrefs} {
7074 set str [mc "and many more"]
7079 $ctext insert $pos "$str ([llength $tags])"
7080 set nutags [llength $tags]
7085 set id [lindex $ti 1]
7088 $ctext tag delete $lk
7089 $ctext insert $pos $sep
7090 $ctext insert $pos [lindex $ti 0] $lk
7094 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7095 $ctext conf -state disabled
7096 return [expr {[llength $tags] + $nutags}]
7099 # called when we have finished computing the nearby tags
7100 proc dispneartags {delay} {
7101 global selectedline currentid showneartags tagphase
7103 if {$selectedline eq {} || !$showneartags} return
7104 after cancel dispnexttag
7106 after 200 dispnexttag
7109 after idle dispnexttag
7114 proc dispnexttag {} {
7115 global selectedline currentid showneartags tagphase ctext
7117 if {$selectedline eq {} || !$showneartags} return
7118 switch -- $tagphase {
7120 set dtags [desctags $currentid]
7122 appendrefs precedes $dtags idtags
7126 set atags [anctags $currentid]
7128 appendrefs follows $atags idtags
7132 set dheads [descheads $currentid]
7133 if {$dheads ne {}} {
7134 if {[appendrefs branch $dheads idheads] > 1
7135 && [$ctext get "branch -3c"] eq "h"} {
7136 # turn "Branch" into "Branches"
7137 $ctext conf -state normal
7138 $ctext insert "branch -2c" "es"
7139 $ctext conf -state disabled
7144 if {[incr tagphase] <= 2} {
7145 after idle dispnexttag
7149 proc make_secsel {id} {
7150 global linehtag linentag linedtag canv canv2 canv3
7152 if {![info exists linehtag($id)]} return
7154 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7155 -tags secsel -fill [$canv cget -selectbackground]]
7157 $canv2 delete secsel
7158 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7159 -tags secsel -fill [$canv2 cget -selectbackground]]
7161 $canv3 delete secsel
7162 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7163 -tags secsel -fill [$canv3 cget -selectbackground]]
7167 proc make_idmark {id} {
7168 global linehtag canv fgcolor
7170 if {![info exists linehtag($id)]} return
7172 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7173 -tags markid -outline $fgcolor]
7177 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7178 global canv ctext commitinfo selectedline
7179 global canvy0 linespc parents children curview
7180 global currentid sha1entry
7181 global commentend idtags linknum
7182 global mergemax numcommits pending_select
7183 global cmitmode showneartags allcommits
7184 global targetrow targetid lastscrollrows
7185 global autoselect autosellen jump_to_here
7188 catch {unset pending_select}
7193 if {$l < 0 || $l >= $numcommits} return
7194 set id [commitonrow $l]
7199 if {$lastscrollrows < $numcommits} {
7203 if {$cmitmode ne "patch" && $switch_to_patch} {
7204 set cmitmode "patch"
7207 set y [expr {$canvy0 + $l * $linespc}]
7208 set ymax [lindex [$canv cget -scrollregion] 3]
7209 set ytop [expr {$y - $linespc - 1}]
7210 set ybot [expr {$y + $linespc + 1}]
7211 set wnow [$canv yview]
7212 set wtop [expr {[lindex $wnow 0] * $ymax}]
7213 set wbot [expr {[lindex $wnow 1] * $ymax}]
7214 set wh [expr {$wbot - $wtop}]
7216 if {$ytop < $wtop} {
7217 if {$ybot < $wtop} {
7218 set newtop [expr {$y - $wh / 2.0}]
7221 if {$newtop > $wtop - $linespc} {
7222 set newtop [expr {$wtop - $linespc}]
7225 } elseif {$ybot > $wbot} {
7226 if {$ytop > $wbot} {
7227 set newtop [expr {$y - $wh / 2.0}]
7229 set newtop [expr {$ybot - $wh}]
7230 if {$newtop < $wtop + $linespc} {
7231 set newtop [expr {$wtop + $linespc}]
7235 if {$newtop != $wtop} {
7239 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7246 addtohistory [list selbyid $id 0] savecmitpos
7249 $sha1entry delete 0 end
7250 $sha1entry insert 0 $id
7252 $sha1entry selection range 0 $autosellen
7256 $ctext conf -state normal
7259 if {![info exists commitinfo($id)]} {
7262 set info $commitinfo($id)
7263 set date [formatdate [lindex $info 2]]
7264 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7265 set date [formatdate [lindex $info 4]]
7266 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7267 if {[info exists idtags($id)]} {
7268 $ctext insert end [mc "Tags:"]
7269 foreach tag $idtags($id) {
7270 $ctext insert end " $tag"
7272 $ctext insert end "\n"
7276 set olds $parents($curview,$id)
7277 if {[llength $olds] > 1} {
7280 if {$np >= $mergemax} {
7285 $ctext insert end "[mc "Parent"]: " $tag
7286 appendwithlinks [commit_descriptor $p] {}
7291 append headers "[mc "Parent"]: [commit_descriptor $p]"
7295 foreach c $children($curview,$id) {
7296 append headers "[mc "Child"]: [commit_descriptor $c]"
7299 # make anything that looks like a SHA1 ID be a clickable link
7300 appendwithlinks $headers {}
7301 if {$showneartags} {
7302 if {![info exists allcommits]} {
7305 $ctext insert end "[mc "Branch"]: "
7306 $ctext mark set branch "end -1c"
7307 $ctext mark gravity branch left
7308 $ctext insert end "\n[mc "Follows"]: "
7309 $ctext mark set follows "end -1c"
7310 $ctext mark gravity follows left
7311 $ctext insert end "\n[mc "Precedes"]: "
7312 $ctext mark set precedes "end -1c"
7313 $ctext mark gravity precedes left
7314 $ctext insert end "\n"
7317 $ctext insert end "\n"
7318 set comment [lindex $info 5]
7319 if {[string first "\r" $comment] >= 0} {
7320 set comment [string map {"\r" "\n "} $comment]
7322 appendwithlinks $comment {comment}
7324 $ctext tag remove found 1.0 end
7325 $ctext conf -state disabled
7326 set commentend [$ctext index "end - 1c"]
7328 set jump_to_here $desired_loc
7329 init_flist [mc "Comments"]
7330 if {$cmitmode eq "tree"} {
7332 } elseif {$vinlinediff($curview) == 1} {
7334 } elseif {[llength $olds] <= 1} {
7341 proc selfirstline {} {
7346 proc sellastline {} {
7349 set l [expr {$numcommits - 1}]
7353 proc selnextline {dir} {
7356 if {$selectedline eq {}} return
7357 set l [expr {$selectedline + $dir}]
7362 proc selnextpage {dir} {
7363 global canv linespc selectedline numcommits
7365 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7369 allcanvs yview scroll [expr {$dir * $lpp}] units
7371 if {$selectedline eq {}} return
7372 set l [expr {$selectedline + $dir * $lpp}]
7375 } elseif {$l >= $numcommits} {
7376 set l [expr $numcommits - 1]
7382 proc unselectline {} {
7383 global selectedline currentid
7386 catch {unset currentid}
7387 allcanvs delete secsel
7391 proc reselectline {} {
7394 if {$selectedline ne {}} {
7395 selectline $selectedline 0
7399 proc addtohistory {cmd {saveproc {}}} {
7400 global history historyindex curview
7404 set elt [list $curview $cmd $saveproc {}]
7405 if {$historyindex > 0
7406 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7410 if {$historyindex < [llength $history]} {
7411 set history [lreplace $history $historyindex end $elt]
7413 lappend history $elt
7416 if {$historyindex > 1} {
7417 .tf.bar.leftbut conf -state normal
7419 .tf.bar.leftbut conf -state disabled
7421 .tf.bar.rightbut conf -state disabled
7424 # save the scrolling position of the diff display pane
7425 proc save_position {} {
7426 global historyindex history
7428 if {$historyindex < 1} return
7429 set hi [expr {$historyindex - 1}]
7430 set fn [lindex $history $hi 2]
7432 lset history $hi 3 [eval $fn]
7436 proc unset_posvars {} {
7439 if {[info exists last_posvars]} {
7440 foreach {var val} $last_posvars {
7449 global curview last_posvars
7451 set view [lindex $elt 0]
7452 set cmd [lindex $elt 1]
7453 set pv [lindex $elt 3]
7454 if {$curview != $view} {
7458 foreach {var val} $pv {
7462 set last_posvars $pv
7467 global history historyindex
7470 if {$historyindex > 1} {
7472 incr historyindex -1
7473 godo [lindex $history [expr {$historyindex - 1}]]
7474 .tf.bar.rightbut conf -state normal
7476 if {$historyindex <= 1} {
7477 .tf.bar.leftbut conf -state disabled
7482 global history historyindex
7485 if {$historyindex < [llength $history]} {
7487 set cmd [lindex $history $historyindex]
7490 .tf.bar.leftbut conf -state normal
7492 if {$historyindex >= [llength $history]} {
7493 .tf.bar.rightbut conf -state disabled
7498 global treefilelist treeidlist diffids diffmergeid treepending
7499 global nullid nullid2
7502 catch {unset diffmergeid}
7503 if {![info exists treefilelist($id)]} {
7504 if {![info exists treepending]} {
7505 if {$id eq $nullid} {
7506 set cmd [list | git ls-files]
7507 } elseif {$id eq $nullid2} {
7508 set cmd [list | git ls-files --stage -t]
7510 set cmd [list | git ls-tree -r $id]
7512 if {[catch {set gtf [open $cmd r]}]} {
7516 set treefilelist($id) {}
7517 set treeidlist($id) {}
7518 fconfigure $gtf -blocking 0 -encoding binary
7519 filerun $gtf [list gettreeline $gtf $id]
7526 proc gettreeline {gtf id} {
7527 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7530 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7531 if {$diffids eq $nullid} {
7534 set i [string first "\t" $line]
7535 if {$i < 0} continue
7536 set fname [string range $line [expr {$i+1}] end]
7537 set line [string range $line 0 [expr {$i-1}]]
7538 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7539 set sha1 [lindex $line 2]
7540 lappend treeidlist($id) $sha1
7542 if {[string index $fname 0] eq "\""} {
7543 set fname [lindex $fname 0]
7545 set fname [encoding convertfrom $fname]
7546 lappend treefilelist($id) $fname
7549 return [expr {$nl >= 1000? 2: 1}]
7553 if {$cmitmode ne "tree"} {
7554 if {![info exists diffmergeid]} {
7555 gettreediffs $diffids
7557 } elseif {$id ne $diffids} {
7566 global treefilelist treeidlist diffids nullid nullid2
7567 global ctext_file_names ctext_file_lines
7568 global ctext commentend
7570 set i [lsearch -exact $treefilelist($diffids) $f]
7572 puts "oops, $f not in list for id $diffids"
7575 if {$diffids eq $nullid} {
7576 if {[catch {set bf [open $f r]} err]} {
7577 puts "oops, can't read $f: $err"
7581 set blob [lindex $treeidlist($diffids) $i]
7582 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7583 puts "oops, error reading blob $blob: $err"
7587 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7588 filerun $bf [list getblobline $bf $diffids]
7589 $ctext config -state normal
7590 clear_ctext $commentend
7591 lappend ctext_file_names $f
7592 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7593 $ctext insert end "\n"
7594 $ctext insert end "$f\n" filesep
7595 $ctext config -state disabled
7596 $ctext yview $commentend
7600 proc getblobline {bf id} {
7601 global diffids cmitmode ctext
7603 if {$id ne $diffids || $cmitmode ne "tree"} {
7607 $ctext config -state normal
7609 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7610 $ctext insert end "$line\n"
7613 global jump_to_here ctext_file_names commentend
7615 # delete last newline
7616 $ctext delete "end - 2c" "end - 1c"
7618 if {$jump_to_here ne {} &&
7619 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7620 set lnum [expr {[lindex $jump_to_here 1] +
7621 [lindex [split $commentend .] 0]}]
7622 mark_ctext_line $lnum
7624 $ctext config -state disabled
7627 $ctext config -state disabled
7628 return [expr {$nl >= 1000? 2: 1}]
7631 proc mark_ctext_line {lnum} {
7632 global ctext markbgcolor
7634 $ctext tag delete omark
7635 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7636 $ctext tag conf omark -background $markbgcolor
7640 proc mergediff {id} {
7642 global diffids treediffs
7643 global parents curview
7647 set treediffs($id) {}
7648 set np [llength $parents($curview,$id)]
7653 proc startdiff {ids} {
7654 global treediffs diffids treepending diffmergeid nullid nullid2
7658 catch {unset diffmergeid}
7659 if {![info exists treediffs($ids)] ||
7660 [lsearch -exact $ids $nullid] >= 0 ||
7661 [lsearch -exact $ids $nullid2] >= 0} {
7662 if {![info exists treepending]} {
7670 proc showinlinediff {ids} {
7671 global commitinfo commitdata ctext
7674 set info $commitinfo($ids)
7675 set diff [lindex $info 7]
7676 set difflines [split $diff "\n"]
7682 foreach line $difflines {
7683 if {![string compare -length 5 "diff " $line]} {
7685 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7686 # offset also accounts for the b/ prefix
7687 lappend treediff [string range $line 6 end]
7692 set treediffs($ids) $treediff
7695 $ctext conf -state normal
7696 foreach line $difflines {
7697 parseblobdiffline $ids $line
7699 maybe_scroll_ctext 1
7700 $ctext conf -state disabled
7703 # If the filename (name) is under any of the passed filter paths
7704 # then return true to include the file in the listing.
7705 proc path_filter {filter name} {
7706 set worktree [gitworktree]
7708 set fq_p [file normalize $p]
7709 set fq_n [file normalize [file join $worktree $name]]
7710 if {[string match [file normalize $fq_p]* $fq_n]} {
7717 proc addtocflist {ids} {
7720 add_flist $treediffs($ids)
7724 proc diffcmd {ids flags} {
7725 global log_showroot nullid nullid2 git_version
7727 set i [lsearch -exact $ids $nullid]
7728 set j [lsearch -exact $ids $nullid2]
7730 if {[llength $ids] > 1 && $j < 0} {
7731 # comparing working directory with some specific revision
7732 set cmd [concat | git diff-index $flags]
7734 lappend cmd -R [lindex $ids 1]
7736 lappend cmd [lindex $ids 0]
7739 # comparing working directory with index
7740 set cmd [concat | git diff-files $flags]
7745 } elseif {$j >= 0} {
7746 if {[package vcompare $git_version "1.7.2"] >= 0} {
7747 set flags "$flags --ignore-submodules=dirty"
7749 set cmd [concat | git diff-index --cached $flags]
7750 if {[llength $ids] > 1} {
7751 # comparing index with specific revision
7753 lappend cmd -R [lindex $ids 1]
7755 lappend cmd [lindex $ids 0]
7758 # comparing index with HEAD
7762 if {$log_showroot} {
7763 lappend flags --root
7765 set cmd [concat | git diff-tree -r $flags $ids]
7770 proc gettreediffs {ids} {
7771 global treediff treepending limitdiffs vfilelimit curview
7773 set cmd [diffcmd $ids {--no-commit-id}]
7774 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7775 set cmd [concat $cmd -- $vfilelimit($curview)]
7777 if {[catch {set gdtf [open $cmd r]}]} return
7779 set treepending $ids
7781 fconfigure $gdtf -blocking 0 -encoding binary
7782 filerun $gdtf [list gettreediffline $gdtf $ids]
7785 proc gettreediffline {gdtf ids} {
7786 global treediff treediffs treepending diffids diffmergeid
7787 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7792 if {$perfile_attrs} {
7793 # cache_gitattr is slow, and even slower on win32 where we
7794 # have to invoke it for only about 30 paths at a time
7796 if {[tk windowingsystem] == "win32"} {
7800 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7801 set i [string first "\t" $line]
7803 set file [string range $line [expr {$i+1}] end]
7804 if {[string index $file 0] eq "\""} {
7805 set file [lindex $file 0]
7807 set file [encoding convertfrom $file]
7808 if {$file ne [lindex $treediff end]} {
7809 lappend treediff $file
7810 lappend sublist $file
7814 if {$perfile_attrs} {
7815 cache_gitattr encoding $sublist
7818 return [expr {$nr >= $max? 2: 1}]
7821 set treediffs($ids) $treediff
7823 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7825 } elseif {$ids != $diffids} {
7826 if {![info exists diffmergeid]} {
7827 gettreediffs $diffids
7835 # empty string or positive integer
7836 proc diffcontextvalidate {v} {
7837 return [regexp {^(|[1-9][0-9]*)$} $v]
7840 proc diffcontextchange {n1 n2 op} {
7841 global diffcontextstring diffcontext
7843 if {[string is integer -strict $diffcontextstring]} {
7844 if {$diffcontextstring >= 0} {
7845 set diffcontext $diffcontextstring
7851 proc changeignorespace {} {
7855 proc changeworddiff {name ix op} {
7859 proc initblobdiffvars {} {
7860 global diffencoding targetline diffnparents
7861 global diffinhdr currdiffsubmod diffseehere
7865 set diffencoding [get_path_encoding {}]
7866 set currdiffsubmod ""
7870 proc getblobdiffs {ids} {
7871 global blobdifffd diffids env
7876 global limitdiffs vfilelimit curview
7880 if {[package vcompare $git_version "1.6.1"] >= 0} {
7881 set textconv "--textconv"
7884 if {[package vcompare $git_version "1.6.6"] >= 0} {
7885 set submodule "--submodule"
7887 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7891 if {$worddiff ne [mc "Line diff"]} {
7892 append cmd " --word-diff=porcelain"
7894 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7895 set cmd [concat $cmd -- $vfilelimit($curview)]
7897 if {[catch {set bdf [open $cmd r]} err]} {
7898 error_popup [mc "Error getting diffs: %s" $err]
7901 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7902 set blobdifffd($ids) $bdf
7904 filerun $bdf [list getblobdiffline $bdf $diffids]
7907 proc savecmitpos {} {
7908 global ctext cmitmode
7910 if {$cmitmode eq "tree"} {
7913 return [list target_scrollpos [$ctext index @0,0]]
7916 proc savectextpos {} {
7919 return [list target_scrollpos [$ctext index @0,0]]
7922 proc maybe_scroll_ctext {ateof} {
7923 global ctext target_scrollpos
7925 if {![info exists target_scrollpos]} return
7927 set nlines [expr {[winfo height $ctext]
7928 / [font metrics textfont -linespace]}]
7929 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7931 $ctext yview $target_scrollpos
7932 unset target_scrollpos
7935 proc setinlist {var i val} {
7938 while {[llength [set $var]] < $i} {
7941 if {[llength [set $var]] == $i} {
7948 proc makediffhdr {fname ids} {
7949 global ctext curdiffstart treediffs diffencoding
7950 global ctext_file_names jump_to_here targetline diffline
7952 set fname [encoding convertfrom $fname]
7953 set diffencoding [get_path_encoding $fname]
7954 set i [lsearch -exact $treediffs($ids) $fname]
7956 setinlist difffilestart $i $curdiffstart
7958 lset ctext_file_names end $fname
7959 set l [expr {(78 - [string length $fname]) / 2}]
7960 set pad [string range "----------------------------------------" 1 $l]
7961 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7963 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7964 set targetline [lindex $jump_to_here 1]
7969 proc blobdiffmaybeseehere {ateof} {
7971 if {$diffseehere >= 0} {
7972 mark_ctext_line [lindex [split $diffseehere .] 0]
7974 maybe_scroll_ctext $ateof
7977 proc getblobdiffline {bdf ids} {
7978 global diffids blobdifffd
7982 $ctext conf -state normal
7983 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7984 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7988 parseblobdiffline $ids $line
7990 $ctext conf -state disabled
7991 blobdiffmaybeseehere [eof $bdf]
7996 return [expr {$nr >= 1000? 2: 1}]
7999 proc parseblobdiffline {ids line} {
8000 global ctext curdiffstart
8001 global diffnexthead diffnextnote difffilestart
8002 global ctext_file_names ctext_file_lines
8003 global diffinhdr treediffs mergemax diffnparents
8004 global diffencoding jump_to_here targetline diffline currdiffsubmod
8005 global worddiff diffseehere
8007 if {![string compare -length 5 "diff " $line]} {
8008 if {![regexp {^diff (--cc|--git) } $line m type]} {
8009 set line [encoding convertfrom $line]
8010 $ctext insert end "$line\n" hunksep
8013 # start of a new file
8015 $ctext insert end "\n"
8016 set curdiffstart [$ctext index "end - 1c"]
8017 lappend ctext_file_names ""
8018 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8019 $ctext insert end "\n" filesep
8021 if {$type eq "--cc"} {
8022 # start of a new file in a merge diff
8023 set fname [string range $line 10 end]
8024 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
8025 lappend treediffs($ids) $fname
8026 add_flist [list $fname]
8030 set line [string range $line 11 end]
8031 # If the name hasn't changed the length will be odd,
8032 # the middle char will be a space, and the two bits either
8033 # side will be a/name and b/name, or "a/name" and "b/name".
8034 # If the name has changed we'll get "rename from" and
8035 # "rename to" or "copy from" and "copy to" lines following
8036 # this, and we'll use them to get the filenames.
8037 # This complexity is necessary because spaces in the
8038 # filename(s) don't get escaped.
8039 set l [string length $line]
8040 set i [expr {$l / 2}]
8041 if {!(($l & 1) && [string index $line $i] eq " " &&
8042 [string range $line 2 [expr {$i - 1}]] eq \
8043 [string range $line [expr {$i + 3}] end])} {
8046 # unescape if quoted and chop off the a/ from the front
8047 if {[string index $line 0] eq "\""} {
8048 set fname [string range [lindex $line 0] 2 end]
8050 set fname [string range $line 2 [expr {$i - 1}]]
8053 makediffhdr $fname $ids
8055 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8056 set fname [encoding convertfrom [string range $line 16 end]]
8057 $ctext insert end "\n"
8058 set curdiffstart [$ctext index "end - 1c"]
8059 lappend ctext_file_names $fname
8060 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8061 $ctext insert end "$line\n" filesep
8062 set i [lsearch -exact $treediffs($ids) $fname]
8064 setinlist difffilestart $i $curdiffstart
8067 } elseif {![string compare -length 2 "@@" $line]} {
8068 regexp {^@@+} $line ats
8069 set line [encoding convertfrom $diffencoding $line]
8070 $ctext insert end "$line\n" hunksep
8071 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8074 set diffnparents [expr {[string length $ats] - 1}]
8077 } elseif {![string compare -length 10 "Submodule " $line]} {
8078 # start of a new submodule
8079 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8080 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8082 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8084 if {$currdiffsubmod != $fname} {
8085 $ctext insert end "\n"; # Add newline after commit message
8087 set curdiffstart [$ctext index "end - 1c"]
8088 lappend ctext_file_names ""
8089 if {$currdiffsubmod != $fname} {
8090 lappend ctext_file_lines $fname
8091 makediffhdr $fname $ids
8092 set currdiffsubmod $fname
8093 $ctext insert end "\n$line\n" filesep
8095 $ctext insert end "$line\n" filesep
8097 } elseif {![string compare -length 3 " >" $line]} {
8098 set $currdiffsubmod ""
8099 set line [encoding convertfrom $diffencoding $line]
8100 $ctext insert end "$line\n" dresult
8101 } elseif {![string compare -length 3 " <" $line]} {
8102 set $currdiffsubmod ""
8103 set line [encoding convertfrom $diffencoding $line]
8104 $ctext insert end "$line\n" d0
8105 } elseif {$diffinhdr} {
8106 if {![string compare -length 12 "rename from " $line]} {
8107 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8108 if {[string index $fname 0] eq "\""} {
8109 set fname [lindex $fname 0]
8111 set fname [encoding convertfrom $fname]
8112 set i [lsearch -exact $treediffs($ids) $fname]
8114 setinlist difffilestart $i $curdiffstart
8116 } elseif {![string compare -length 10 $line "rename to "] ||
8117 ![string compare -length 8 $line "copy to "]} {
8118 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8119 if {[string index $fname 0] eq "\""} {
8120 set fname [lindex $fname 0]
8122 makediffhdr $fname $ids
8123 } elseif {[string compare -length 3 $line "---"] == 0} {
8126 } elseif {[string compare -length 3 $line "+++"] == 0} {
8130 $ctext insert end "$line\n" filesep
8133 set line [string map {\x1A ^Z} \
8134 [encoding convertfrom $diffencoding $line]]
8135 # parse the prefix - one ' ', '-' or '+' for each parent
8136 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8137 set tag [expr {$diffnparents > 1? "m": "d"}]
8138 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8139 set words_pre_markup ""
8140 set words_post_markup ""
8141 if {[string trim $prefix " -+"] eq {}} {
8142 # prefix only has " ", "-" and "+" in it: normal diff line
8143 set num [string first "-" $prefix]
8145 set line [string range $line 1 end]
8148 # removed line, first parent with line is $num
8149 if {$num >= $mergemax} {
8152 if {$dowords && $worddiff eq [mc "Markup words"]} {
8153 $ctext insert end "\[-$line-\]" $tag$num
8155 $ctext insert end "$line" $tag$num
8158 $ctext insert end "\n" $tag$num
8162 if {[string first "+" $prefix] >= 0} {
8164 lappend tags ${tag}result
8165 if {$diffnparents > 1} {
8166 set num [string first " " $prefix]
8168 if {$num >= $mergemax} {
8174 set words_pre_markup "{+"
8175 set words_post_markup "+}"
8177 if {$targetline ne {}} {
8178 if {$diffline == $targetline} {
8179 set diffseehere [$ctext index "end - 1 chars"]
8185 if {$dowords && $worddiff eq [mc "Markup words"]} {
8186 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8188 $ctext insert end "$line" $tags
8191 $ctext insert end "\n" $tags
8194 } elseif {$dowords && $prefix eq "~"} {
8195 $ctext insert end "\n" {}
8197 # "\ No newline at end of file",
8198 # or something else we don't recognize
8199 $ctext insert end "$line\n" hunksep
8204 proc changediffdisp {} {
8205 global ctext diffelide
8207 $ctext tag conf d0 -elide [lindex $diffelide 0]
8208 $ctext tag conf dresult -elide [lindex $diffelide 1]
8211 proc highlightfile {cline} {
8212 global cflist cflist_top
8214 if {![info exists cflist_top]} return
8216 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8217 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8218 $cflist see $cline.0
8219 set cflist_top $cline
8222 proc highlightfile_for_scrollpos {topidx} {
8223 global cmitmode difffilestart
8225 if {$cmitmode eq "tree"} return
8226 if {![info exists difffilestart]} return
8228 set top [lindex [split $topidx .] 0]
8229 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8232 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8237 global difffilestart ctext cmitmode
8239 if {$cmitmode eq "tree"} return
8241 set here [$ctext index @0,0]
8242 foreach loc $difffilestart {
8243 if {[$ctext compare $loc >= $here]} {
8253 global difffilestart ctext cmitmode
8255 if {$cmitmode eq "tree"} return
8256 set here [$ctext index @0,0]
8257 foreach loc $difffilestart {
8258 if {[$ctext compare $loc > $here]} {
8265 proc clear_ctext {{first 1.0}} {
8266 global ctext smarktop smarkbot
8267 global ctext_file_names ctext_file_lines
8270 set l [lindex [split $first .] 0]
8271 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8274 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8277 $ctext delete $first end
8278 if {$first eq "1.0"} {
8279 catch {unset pendinglinks}
8281 set ctext_file_names {}
8282 set ctext_file_lines {}
8285 proc settabs {{firstab {}}} {
8286 global firsttabstop tabstop ctext have_tk85
8288 if {$firstab ne {} && $have_tk85} {
8289 set firsttabstop $firstab
8291 set w [font measure textfont "0"]
8292 if {$firsttabstop != 0} {
8293 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8294 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8295 } elseif {$have_tk85 || $tabstop != 8} {
8296 $ctext conf -tabs [expr {$tabstop * $w}]
8298 $ctext conf -tabs {}
8302 proc incrsearch {name ix op} {
8303 global ctext searchstring searchdirn
8305 if {[catch {$ctext index anchor}]} {
8306 # no anchor set, use start of selection, or of visible area
8307 set sel [$ctext tag ranges sel]
8309 $ctext mark set anchor [lindex $sel 0]
8310 } elseif {$searchdirn eq "-forwards"} {
8311 $ctext mark set anchor @0,0
8313 $ctext mark set anchor @0,[winfo height $ctext]
8316 if {$searchstring ne {}} {
8317 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8320 set mend "$here + $mlen c"
8321 $ctext tag remove sel 1.0 end
8322 $ctext tag add sel $here $mend
8323 suppress_highlighting_file_for_current_scrollpos
8324 highlightfile_for_scrollpos $here
8327 rehighlight_search_results
8331 global sstring ctext searchstring searchdirn
8334 $sstring icursor end
8335 set searchdirn -forwards
8336 if {$searchstring ne {}} {
8337 set sel [$ctext tag ranges sel]
8339 set start "[lindex $sel 0] + 1c"
8340 } elseif {[catch {set start [$ctext index anchor]}]} {
8343 set match [$ctext search -count mlen -- $searchstring $start]
8344 $ctext tag remove sel 1.0 end
8350 suppress_highlighting_file_for_current_scrollpos
8351 highlightfile_for_scrollpos $match
8352 set mend "$match + $mlen c"
8353 $ctext tag add sel $match $mend
8354 $ctext mark unset anchor
8355 rehighlight_search_results
8359 proc dosearchback {} {
8360 global sstring ctext searchstring searchdirn
8363 $sstring icursor end
8364 set searchdirn -backwards
8365 if {$searchstring ne {}} {
8366 set sel [$ctext tag ranges sel]
8368 set start [lindex $sel 0]
8369 } elseif {[catch {set start [$ctext index anchor]}]} {
8370 set start @0,[winfo height $ctext]
8372 set match [$ctext search -backwards -count ml -- $searchstring $start]
8373 $ctext tag remove sel 1.0 end
8379 suppress_highlighting_file_for_current_scrollpos
8380 highlightfile_for_scrollpos $match
8381 set mend "$match + $ml c"
8382 $ctext tag add sel $match $mend
8383 $ctext mark unset anchor
8384 rehighlight_search_results
8388 proc rehighlight_search_results {} {
8389 global ctext searchstring
8391 $ctext tag remove found 1.0 end
8392 $ctext tag remove currentsearchhit 1.0 end
8394 if {$searchstring ne {}} {
8399 proc searchmark {first last} {
8400 global ctext searchstring
8402 set sel [$ctext tag ranges sel]
8406 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8407 if {$match eq {}} break
8408 set mend "$match + $mlen c"
8409 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8410 $ctext tag add currentsearchhit $match $mend
8412 $ctext tag add found $match $mend
8417 proc searchmarkvisible {doall} {
8418 global ctext smarktop smarkbot
8420 set topline [lindex [split [$ctext index @0,0] .] 0]
8421 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8422 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8423 # no overlap with previous
8424 searchmark $topline $botline
8425 set smarktop $topline
8426 set smarkbot $botline
8428 if {$topline < $smarktop} {
8429 searchmark $topline [expr {$smarktop-1}]
8430 set smarktop $topline
8432 if {$botline > $smarkbot} {
8433 searchmark [expr {$smarkbot+1}] $botline
8434 set smarkbot $botline
8439 proc suppress_highlighting_file_for_current_scrollpos {} {
8440 global ctext suppress_highlighting_file_for_this_scrollpos
8442 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8445 proc scrolltext {f0 f1} {
8446 global searchstring cmitmode ctext
8447 global suppress_highlighting_file_for_this_scrollpos
8449 set topidx [$ctext index @0,0]
8450 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8451 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8452 highlightfile_for_scrollpos $topidx
8455 catch {unset suppress_highlighting_file_for_this_scrollpos}
8457 .bleft.bottom.sb set $f0 $f1
8458 if {$searchstring ne {}} {
8464 global linespc charspc canvx0 canvy0
8465 global xspc1 xspc2 lthickness
8467 set linespc [font metrics mainfont -linespace]
8468 set charspc [font measure mainfont "m"]
8469 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8470 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8471 set lthickness [expr {int($linespc / 9) + 1}]
8472 set xspc1(0) $linespc
8480 set ymax [lindex [$canv cget -scrollregion] 3]
8481 if {$ymax eq {} || $ymax == 0} return
8482 set span [$canv yview]
8485 allcanvs yview moveto [lindex $span 0]
8487 if {$selectedline ne {}} {
8488 selectline $selectedline 0
8489 allcanvs yview moveto [lindex $span 0]
8493 proc parsefont {f n} {
8496 set fontattr($f,family) [lindex $n 0]
8498 if {$s eq {} || $s == 0} {
8501 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8503 set fontattr($f,size) $s
8504 set fontattr($f,weight) normal
8505 set fontattr($f,slant) roman
8506 foreach style [lrange $n 2 end] {
8509 "bold" {set fontattr($f,weight) $style}
8511 "italic" {set fontattr($f,slant) $style}
8516 proc fontflags {f {isbold 0}} {
8519 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8520 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8521 -slant $fontattr($f,slant)]
8527 set n [list $fontattr($f,family) $fontattr($f,size)]
8528 if {$fontattr($f,weight) eq "bold"} {
8531 if {$fontattr($f,slant) eq "italic"} {
8537 proc incrfont {inc} {
8538 global mainfont textfont ctext canv cflist showrefstop
8539 global stopped entries fontattr
8542 set s $fontattr(mainfont,size)
8547 set fontattr(mainfont,size) $s
8548 font config mainfont -size $s
8549 font config mainfontbold -size $s
8550 set mainfont [fontname mainfont]
8551 set s $fontattr(textfont,size)
8556 set fontattr(textfont,size) $s
8557 font config textfont -size $s
8558 font config textfontbold -size $s
8559 set textfont [fontname textfont]
8566 global sha1entry sha1string
8567 if {[string length $sha1string] == 40} {
8568 $sha1entry delete 0 end
8572 proc sha1change {n1 n2 op} {
8573 global sha1string currentid sha1but
8574 if {$sha1string == {}
8575 || ([info exists currentid] && $sha1string == $currentid)} {
8580 if {[$sha1but cget -state] == $state} return
8581 if {$state == "normal"} {
8582 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8584 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8588 proc gotocommit {} {
8589 global sha1string tagids headids curview varcid
8591 if {$sha1string == {}
8592 || ([info exists currentid] && $sha1string == $currentid)} return
8593 if {[info exists tagids($sha1string)]} {
8594 set id $tagids($sha1string)
8595 } elseif {[info exists headids($sha1string)]} {
8596 set id $headids($sha1string)
8598 set id [string tolower $sha1string]
8599 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8600 set matches [longid $id]
8601 if {$matches ne {}} {
8602 if {[llength $matches] > 1} {
8603 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8606 set id [lindex $matches 0]
8609 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8610 error_popup [mc "Revision %s is not known" $sha1string]
8615 if {[commitinview $id $curview]} {
8616 selectline [rowofcommit $id] 1
8619 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8620 set msg [mc "SHA1 id %s is not known" $sha1string]
8622 set msg [mc "Revision %s is not in the current view" $sha1string]
8627 proc lineenter {x y id} {
8628 global hoverx hovery hoverid hovertimer
8629 global commitinfo canv
8631 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8635 if {[info exists hovertimer]} {
8636 after cancel $hovertimer
8638 set hovertimer [after 500 linehover]
8642 proc linemotion {x y id} {
8643 global hoverx hovery hoverid hovertimer
8645 if {[info exists hoverid] && $id == $hoverid} {
8648 if {[info exists hovertimer]} {
8649 after cancel $hovertimer
8651 set hovertimer [after 500 linehover]
8655 proc lineleave {id} {
8656 global hoverid hovertimer canv
8658 if {[info exists hoverid] && $id == $hoverid} {
8660 if {[info exists hovertimer]} {
8661 after cancel $hovertimer
8669 global hoverx hovery hoverid hovertimer
8670 global canv linespc lthickness
8671 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8675 set text [lindex $commitinfo($hoverid) 0]
8676 set ymax [lindex [$canv cget -scrollregion] 3]
8677 if {$ymax == {}} return
8678 set yfrac [lindex [$canv yview] 0]
8679 set x [expr {$hoverx + 2 * $linespc}]
8680 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8681 set x0 [expr {$x - 2 * $lthickness}]
8682 set y0 [expr {$y - 2 * $lthickness}]
8683 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8684 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8685 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8686 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8687 -width 1 -tags hover]
8689 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8690 -font mainfont -fill $linehoverfgcolor]
8694 proc clickisonarrow {id y} {
8697 set ranges [rowranges $id]
8698 set thresh [expr {2 * $lthickness + 6}]
8699 set n [expr {[llength $ranges] - 1}]
8700 for {set i 1} {$i < $n} {incr i} {
8701 set row [lindex $ranges $i]
8702 if {abs([yc $row] - $y) < $thresh} {
8709 proc arrowjump {id n y} {
8712 # 1 <-> 2, 3 <-> 4, etc...
8713 set n [expr {(($n - 1) ^ 1) + 1}]
8714 set row [lindex [rowranges $id] $n]
8716 set ymax [lindex [$canv cget -scrollregion] 3]
8717 if {$ymax eq {} || $ymax <= 0} return
8718 set view [$canv yview]
8719 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8720 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8724 allcanvs yview moveto $yfrac
8727 proc lineclick {x y id isnew} {
8728 global ctext commitinfo children canv thickerline curview
8730 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8735 # draw this line thicker than normal
8739 set ymax [lindex [$canv cget -scrollregion] 3]
8740 if {$ymax eq {}} return
8741 set yfrac [lindex [$canv yview] 0]
8742 set y [expr {$y + $yfrac * $ymax}]
8744 set dirn [clickisonarrow $id $y]
8746 arrowjump $id $dirn $y
8751 addtohistory [list lineclick $x $y $id 0] savectextpos
8753 # fill the details pane with info about this line
8754 $ctext conf -state normal
8757 $ctext insert end "[mc "Parent"]:\t"
8758 $ctext insert end $id link0
8760 set info $commitinfo($id)
8761 $ctext insert end "\n\t[lindex $info 0]\n"
8762 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8763 set date [formatdate [lindex $info 2]]
8764 $ctext insert end "\t[mc "Date"]:\t$date\n"
8765 set kids $children($curview,$id)
8767 $ctext insert end "\n[mc "Children"]:"
8769 foreach child $kids {
8771 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8772 set info $commitinfo($child)
8773 $ctext insert end "\n\t"
8774 $ctext insert end $child link$i
8775 setlink $child link$i
8776 $ctext insert end "\n\t[lindex $info 0]"
8777 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8778 set date [formatdate [lindex $info 2]]
8779 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8782 maybe_scroll_ctext 1
8783 $ctext conf -state disabled
8787 proc normalline {} {
8789 if {[info exists thickerline]} {
8796 proc selbyid {id {isnew 1}} {
8798 if {[commitinview $id $curview]} {
8799 selectline [rowofcommit $id] $isnew
8805 if {![info exists startmstime]} {
8806 set startmstime [clock clicks -milliseconds]
8808 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8811 proc rowmenu {x y id} {
8812 global rowctxmenu selectedline rowmenuid curview
8813 global nullid nullid2 fakerowmenu mainhead markedid
8817 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8822 if {[info exists markedid] && $markedid ne $id} {
8827 if {$id ne $nullid && $id ne $nullid2} {
8828 set menu $rowctxmenu
8829 if {$mainhead ne {}} {
8830 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8832 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8834 $menu entryconfigure 9 -state $mstate
8835 $menu entryconfigure 10 -state $mstate
8836 $menu entryconfigure 11 -state $mstate
8838 set menu $fakerowmenu
8840 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8841 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8842 $menu entryconfigure [mca "Make patch"] -state $state
8843 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8844 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8845 tk_popup $menu $x $y
8849 global rowmenuid markedid canv
8851 set markedid $rowmenuid
8852 make_idmark $markedid
8858 if {[info exists markedid]} {
8863 proc replace_by_kids {l r} {
8864 global curview children
8866 set id [commitonrow $r]
8867 set l [lreplace $l 0 0]
8868 foreach kid $children($curview,$id) {
8869 lappend l [rowofcommit $kid]
8871 return [lsort -integer -decreasing -unique $l]
8874 proc find_common_desc {} {
8875 global markedid rowmenuid curview children
8877 if {![info exists markedid]} return
8878 if {![commitinview $markedid $curview] ||
8879 ![commitinview $rowmenuid $curview]} return
8880 #set t1 [clock clicks -milliseconds]
8881 set l1 [list [rowofcommit $markedid]]
8882 set l2 [list [rowofcommit $rowmenuid]]
8884 set r1 [lindex $l1 0]
8885 set r2 [lindex $l2 0]
8886 if {$r1 eq {} || $r2 eq {}} break
8892 set l1 [replace_by_kids $l1 $r1]
8894 set l2 [replace_by_kids $l2 $r2]
8897 #set t2 [clock clicks -milliseconds]
8898 #puts "took [expr {$t2-$t1}]ms"
8901 proc compare_commits {} {
8902 global markedid rowmenuid curview children
8904 if {![info exists markedid]} return
8905 if {![commitinview $markedid $curview]} return
8906 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8907 do_cmp_commits $markedid $rowmenuid
8910 proc getpatchid {id} {
8913 if {![info exists patchids($id)]} {
8914 set cmd [diffcmd [list $id] {-p --root}]
8915 # trim off the initial "|"
8916 set cmd [lrange $cmd 1 end]
8918 set x [eval exec $cmd | git patch-id]
8919 set patchids($id) [lindex $x 0]
8921 set patchids($id) "error"
8924 return $patchids($id)
8927 proc do_cmp_commits {a b} {
8928 global ctext curview parents children patchids commitinfo
8930 $ctext conf -state normal
8933 for {set i 0} {$i < 100} {incr i} {
8936 if {[llength $parents($curview,$a)] > 1} {
8937 appendshortlink $a [mc "Skipping merge commit "] "\n"
8940 set patcha [getpatchid $a]
8942 if {[llength $parents($curview,$b)] > 1} {
8943 appendshortlink $b [mc "Skipping merge commit "] "\n"
8946 set patchb [getpatchid $b]
8948 if {!$skipa && !$skipb} {
8949 set heada [lindex $commitinfo($a) 0]
8950 set headb [lindex $commitinfo($b) 0]
8951 if {$patcha eq "error"} {
8952 appendshortlink $a [mc "Error getting patch ID for "] \
8953 [mc " - stopping\n"]
8956 if {$patchb eq "error"} {
8957 appendshortlink $b [mc "Error getting patch ID for "] \
8958 [mc " - stopping\n"]
8961 if {$patcha eq $patchb} {
8962 if {$heada eq $headb} {
8963 appendshortlink $a [mc "Commit "]
8964 appendshortlink $b " == " " $heada\n"
8966 appendshortlink $a [mc "Commit "] " $heada\n"
8967 appendshortlink $b [mc " is the same patch as\n "] \
8973 $ctext insert end "\n"
8974 appendshortlink $a [mc "Commit "] " $heada\n"
8975 appendshortlink $b [mc " differs from\n "] \
8977 $ctext insert end [mc "Diff of commits:\n\n"]
8978 $ctext conf -state disabled
8985 set kids [real_children $curview,$a]
8986 if {[llength $kids] != 1} {
8987 $ctext insert end "\n"
8988 appendshortlink $a [mc "Commit "] \
8989 [mc " has %s children - stopping\n" [llength $kids]]
8992 set a [lindex $kids 0]
8995 set kids [real_children $curview,$b]
8996 if {[llength $kids] != 1} {
8997 appendshortlink $b [mc "Commit "] \
8998 [mc " has %s children - stopping\n" [llength $kids]]
9001 set b [lindex $kids 0]
9004 $ctext conf -state disabled
9007 proc diffcommits {a b} {
9008 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
9010 set tmpdir [gitknewtmpdir]
9011 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
9012 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
9014 exec git diff-tree -p --pretty $a >$fna
9015 exec git diff-tree -p --pretty $b >$fnb
9017 error_popup [mc "Error writing commit to file: %s" $err]
9021 set fd [open "| diff -U$diffcontext $fna $fnb" r]
9023 error_popup [mc "Error diffing commits: %s" $err]
9026 set diffids [list commits $a $b]
9027 set blobdifffd($diffids) $fd
9029 set currdiffsubmod ""
9030 filerun $fd [list getblobdiffline $fd $diffids]
9033 proc diffvssel {dirn} {
9034 global rowmenuid selectedline
9036 if {$selectedline eq {}} return
9038 set oldid [commitonrow $selectedline]
9039 set newid $rowmenuid
9041 set oldid $rowmenuid
9042 set newid [commitonrow $selectedline]
9044 addtohistory [list doseldiff $oldid $newid] savectextpos
9045 doseldiff $oldid $newid
9048 proc diffvsmark {dirn} {
9049 global rowmenuid markedid
9051 if {![info exists markedid]} return
9054 set newid $rowmenuid
9056 set oldid $rowmenuid
9059 addtohistory [list doseldiff $oldid $newid] savectextpos
9060 doseldiff $oldid $newid
9063 proc doseldiff {oldid newid} {
9067 $ctext conf -state normal
9069 init_flist [mc "Top"]
9070 $ctext insert end "[mc "From"] "
9071 $ctext insert end $oldid link0
9072 setlink $oldid link0
9073 $ctext insert end "\n "
9074 $ctext insert end [lindex $commitinfo($oldid) 0]
9075 $ctext insert end "\n\n[mc "To"] "
9076 $ctext insert end $newid link1
9077 setlink $newid link1
9078 $ctext insert end "\n "
9079 $ctext insert end [lindex $commitinfo($newid) 0]
9080 $ctext insert end "\n"
9081 $ctext conf -state disabled
9082 $ctext tag remove found 1.0 end
9083 startdiff [list $oldid $newid]
9087 global rowmenuid currentid commitinfo patchtop patchnum NS
9089 if {![info exists currentid]} return
9090 set oldid $currentid
9091 set oldhead [lindex $commitinfo($oldid) 0]
9092 set newid $rowmenuid
9093 set newhead [lindex $commitinfo($newid) 0]
9096 catch {destroy $top}
9098 make_transient $top .
9099 ${NS}::label $top.title -text [mc "Generate patch"]
9100 grid $top.title - -pady 10
9101 ${NS}::label $top.from -text [mc "From:"]
9102 ${NS}::entry $top.fromsha1 -width 40
9103 $top.fromsha1 insert 0 $oldid
9104 $top.fromsha1 conf -state readonly
9105 grid $top.from $top.fromsha1 -sticky w
9106 ${NS}::entry $top.fromhead -width 60
9107 $top.fromhead insert 0 $oldhead
9108 $top.fromhead conf -state readonly
9109 grid x $top.fromhead -sticky w
9110 ${NS}::label $top.to -text [mc "To:"]
9111 ${NS}::entry $top.tosha1 -width 40
9112 $top.tosha1 insert 0 $newid
9113 $top.tosha1 conf -state readonly
9114 grid $top.to $top.tosha1 -sticky w
9115 ${NS}::entry $top.tohead -width 60
9116 $top.tohead insert 0 $newhead
9117 $top.tohead conf -state readonly
9118 grid x $top.tohead -sticky w
9119 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9120 grid $top.rev x -pady 10 -padx 5
9121 ${NS}::label $top.flab -text [mc "Output file:"]
9122 ${NS}::entry $top.fname -width 60
9123 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9125 grid $top.flab $top.fname -sticky w
9126 ${NS}::frame $top.buts
9127 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9128 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9129 bind $top <Key-Return> mkpatchgo
9130 bind $top <Key-Escape> mkpatchcan
9131 grid $top.buts.gen $top.buts.can
9132 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9133 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9134 grid $top.buts - -pady 10 -sticky ew
9138 proc mkpatchrev {} {
9141 set oldid [$patchtop.fromsha1 get]
9142 set oldhead [$patchtop.fromhead get]
9143 set newid [$patchtop.tosha1 get]
9144 set newhead [$patchtop.tohead get]
9145 foreach e [list fromsha1 fromhead tosha1 tohead] \
9146 v [list $newid $newhead $oldid $oldhead] {
9147 $patchtop.$e conf -state normal
9148 $patchtop.$e delete 0 end
9149 $patchtop.$e insert 0 $v
9150 $patchtop.$e conf -state readonly
9155 global patchtop nullid nullid2
9157 set oldid [$patchtop.fromsha1 get]
9158 set newid [$patchtop.tosha1 get]
9159 set fname [$patchtop.fname get]
9160 set cmd [diffcmd [list $oldid $newid] -p]
9161 # trim off the initial "|"
9162 set cmd [lrange $cmd 1 end]
9163 lappend cmd >$fname &
9164 if {[catch {eval exec $cmd} err]} {
9165 error_popup "[mc "Error creating patch:"] $err" $patchtop
9167 catch {destroy $patchtop}
9171 proc mkpatchcan {} {
9174 catch {destroy $patchtop}
9179 global rowmenuid mktagtop commitinfo NS
9183 catch {destroy $top}
9185 make_transient $top .
9186 ${NS}::label $top.title -text [mc "Create tag"]
9187 grid $top.title - -pady 10
9188 ${NS}::label $top.id -text [mc "ID:"]
9189 ${NS}::entry $top.sha1 -width 40
9190 $top.sha1 insert 0 $rowmenuid
9191 $top.sha1 conf -state readonly
9192 grid $top.id $top.sha1 -sticky w
9193 ${NS}::entry $top.head -width 60
9194 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9195 $top.head conf -state readonly
9196 grid x $top.head -sticky w
9197 ${NS}::label $top.tlab -text [mc "Tag name:"]
9198 ${NS}::entry $top.tag -width 60
9199 grid $top.tlab $top.tag -sticky w
9200 ${NS}::label $top.op -text [mc "Tag message is optional"]
9201 grid $top.op -columnspan 2 -sticky we
9202 ${NS}::label $top.mlab -text [mc "Tag message:"]
9203 ${NS}::entry $top.msg -width 60
9204 grid $top.mlab $top.msg -sticky w
9205 ${NS}::frame $top.buts
9206 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9207 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9208 bind $top <Key-Return> mktaggo
9209 bind $top <Key-Escape> mktagcan
9210 grid $top.buts.gen $top.buts.can
9211 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9212 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9213 grid $top.buts - -pady 10 -sticky ew
9218 global mktagtop env tagids idtags
9220 set id [$mktagtop.sha1 get]
9221 set tag [$mktagtop.tag get]
9222 set msg [$mktagtop.msg get]
9224 error_popup [mc "No tag name specified"] $mktagtop
9227 if {[info exists tagids($tag)]} {
9228 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9233 exec git tag -a -m $msg $tag $id
9235 exec git tag $tag $id
9238 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9242 set tagids($tag) $id
9243 lappend idtags($id) $tag
9251 proc redrawtags {id} {
9252 global canv linehtag idpos currentid curview cmitlisted markedid
9253 global canvxmax iddrawn circleitem mainheadid circlecolors
9254 global mainheadcirclecolor
9256 if {![commitinview $id $curview]} return
9257 if {![info exists iddrawn($id)]} return
9258 set row [rowofcommit $id]
9259 if {$id eq $mainheadid} {
9260 set ofill $mainheadcirclecolor
9262 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9264 $canv itemconf $circleitem($row) -fill $ofill
9265 $canv delete tag.$id
9266 set xt [eval drawtags $id $idpos($id)]
9267 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9268 set text [$canv itemcget $linehtag($id) -text]
9269 set font [$canv itemcget $linehtag($id) -font]
9270 set xr [expr {$xt + [font measure $font $text]}]
9271 if {$xr > $canvxmax} {
9275 if {[info exists currentid] && $currentid == $id} {
9278 if {[info exists markedid] && $markedid eq $id} {
9286 catch {destroy $mktagtop}
9291 if {![domktag]} return
9295 proc writecommit {} {
9296 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9298 set top .writecommit
9300 catch {destroy $top}
9302 make_transient $top .
9303 ${NS}::label $top.title -text [mc "Write commit to file"]
9304 grid $top.title - -pady 10
9305 ${NS}::label $top.id -text [mc "ID:"]
9306 ${NS}::entry $top.sha1 -width 40
9307 $top.sha1 insert 0 $rowmenuid
9308 $top.sha1 conf -state readonly
9309 grid $top.id $top.sha1 -sticky w
9310 ${NS}::entry $top.head -width 60
9311 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9312 $top.head conf -state readonly
9313 grid x $top.head -sticky w
9314 ${NS}::label $top.clab -text [mc "Command:"]
9315 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9316 grid $top.clab $top.cmd -sticky w -pady 10
9317 ${NS}::label $top.flab -text [mc "Output file:"]
9318 ${NS}::entry $top.fname -width 60
9319 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9320 grid $top.flab $top.fname -sticky w
9321 ${NS}::frame $top.buts
9322 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9323 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9324 bind $top <Key-Return> wrcomgo
9325 bind $top <Key-Escape> wrcomcan
9326 grid $top.buts.gen $top.buts.can
9327 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9328 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9329 grid $top.buts - -pady 10 -sticky ew
9336 set id [$wrcomtop.sha1 get]
9337 set cmd "echo $id | [$wrcomtop.cmd get]"
9338 set fname [$wrcomtop.fname get]
9339 if {[catch {exec sh -c $cmd >$fname &} err]} {
9340 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9342 catch {destroy $wrcomtop}
9349 catch {destroy $wrcomtop}
9354 global rowmenuid mkbrtop NS
9357 catch {destroy $top}
9359 make_transient $top .
9360 ${NS}::label $top.title -text [mc "Create new branch"]
9361 grid $top.title - -pady 10
9362 ${NS}::label $top.id -text [mc "ID:"]
9363 ${NS}::entry $top.sha1 -width 40
9364 $top.sha1 insert 0 $rowmenuid
9365 $top.sha1 conf -state readonly
9366 grid $top.id $top.sha1 -sticky w
9367 ${NS}::label $top.nlab -text [mc "Name:"]
9368 ${NS}::entry $top.name -width 40
9369 grid $top.nlab $top.name -sticky w
9370 ${NS}::frame $top.buts
9371 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9372 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9373 bind $top <Key-Return> [list mkbrgo $top]
9374 bind $top <Key-Escape> "catch {destroy $top}"
9375 grid $top.buts.go $top.buts.can
9376 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9377 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9378 grid $top.buts - -pady 10 -sticky ew
9383 global headids idheads
9385 set name [$top.name get]
9386 set id [$top.sha1 get]
9390 error_popup [mc "Please specify a name for the new branch"] $top
9393 if {[info exists headids($name)]} {
9394 if {![confirm_popup [mc \
9395 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9398 set old_id $headids($name)
9401 catch {destroy $top}
9402 lappend cmdargs $name $id
9406 eval exec git branch $cmdargs
9412 if {$old_id ne {}} {
9418 set headids($name) $id
9419 lappend idheads($id) $name
9428 proc exec_citool {tool_args {baseid {}}} {
9429 global commitinfo env
9431 set save_env [array get env GIT_AUTHOR_*]
9433 if {$baseid ne {}} {
9434 if {![info exists commitinfo($baseid)]} {
9437 set author [lindex $commitinfo($baseid) 1]
9438 set date [lindex $commitinfo($baseid) 2]
9439 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9440 $author author name email]
9442 set env(GIT_AUTHOR_NAME) $name
9443 set env(GIT_AUTHOR_EMAIL) $email
9444 set env(GIT_AUTHOR_DATE) $date
9448 eval exec git citool $tool_args &
9450 array unset env GIT_AUTHOR_*
9451 array set env $save_env
9454 proc cherrypick {} {
9455 global rowmenuid curview
9456 global mainhead mainheadid
9459 set oldhead [exec git rev-parse HEAD]
9460 set dheads [descheads $rowmenuid]
9461 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9462 set ok [confirm_popup [mc "Commit %s is already\
9463 included in branch %s -- really re-apply it?" \
9464 [string range $rowmenuid 0 7] $mainhead]]
9467 nowbusy cherrypick [mc "Cherry-picking"]
9469 # Unfortunately git-cherry-pick writes stuff to stderr even when
9470 # no error occurs, and exec takes that as an indication of error...
9471 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9474 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9476 error_popup [mc "Cherry-pick failed because of local changes\
9477 to file '%s'.\nPlease commit, reset or stash\
9478 your changes and try again." $fname]
9479 } elseif {[regexp -line \
9480 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9482 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9483 conflict.\nDo you wish to run git citool to\
9485 # Force citool to read MERGE_MSG
9486 file delete [file join $gitdir "GITGUI_MSG"]
9487 exec_citool {} $rowmenuid
9495 set newhead [exec git rev-parse HEAD]
9496 if {$newhead eq $oldhead} {
9498 error_popup [mc "No changes committed"]
9501 addnewchild $newhead $oldhead
9502 if {[commitinview $oldhead $curview]} {
9503 # XXX this isn't right if we have a path limit...
9504 insertrow $newhead $oldhead $curview
9505 if {$mainhead ne {}} {
9506 movehead $newhead $mainhead
9507 movedhead $newhead $mainhead
9509 set mainheadid $newhead
9518 global rowmenuid curview
9519 global mainhead mainheadid
9522 set oldhead [exec git rev-parse HEAD]
9523 set dheads [descheads $rowmenuid]
9524 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9525 set ok [confirm_popup [mc "Commit %s is not\
9526 included in branch %s -- really revert it?" \
9527 [string range $rowmenuid 0 7] $mainhead]]
9530 nowbusy revert [mc "Reverting"]
9533 if [catch {exec git revert --no-edit $rowmenuid} err] {
9535 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9537 regsub {\n( |\t)+} $files "\n" files
9538 error_popup [mc "Revert failed because of local changes to\
9539 the following files:%s Please commit, reset or stash \
9540 your changes and try again." $files]
9541 } elseif [regexp {error: could not revert} $err] {
9542 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9543 Do you wish to run git citool to resolve it?"]] {
9544 # Force citool to read MERGE_MSG
9545 file delete [file join $gitdir "GITGUI_MSG"]
9546 exec_citool {} $rowmenuid
9548 } else { error_popup $err }
9553 set newhead [exec git rev-parse HEAD]
9554 if { $newhead eq $oldhead } {
9556 error_popup [mc "No changes committed"]
9560 addnewchild $newhead $oldhead
9562 if [commitinview $oldhead $curview] {
9563 # XXX this isn't right if we have a path limit...
9564 insertrow $newhead $oldhead $curview
9565 if {$mainhead ne {}} {
9566 movehead $newhead $mainhead
9567 movedhead $newhead $mainhead
9569 set mainheadid $newhead
9579 global mainhead rowmenuid confirm_ok resettype NS
9582 set w ".confirmreset"
9585 wm title $w [mc "Confirm reset"]
9586 ${NS}::label $w.m -text \
9587 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9588 pack $w.m -side top -fill x -padx 20 -pady 20
9589 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9591 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9592 -text [mc "Soft: Leave working tree and index untouched"]
9593 grid $w.f.soft -sticky w
9594 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9595 -text [mc "Mixed: Leave working tree untouched, reset index"]
9596 grid $w.f.mixed -sticky w
9597 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9598 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9599 grid $w.f.hard -sticky w
9600 pack $w.f -side top -fill x -padx 4
9601 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9602 pack $w.ok -side left -fill x -padx 20 -pady 20
9603 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9604 bind $w <Key-Escape> [list destroy $w]
9605 pack $w.cancel -side right -fill x -padx 20 -pady 20
9606 bind $w <Visibility> "grab $w; focus $w"
9608 if {!$confirm_ok} return
9609 if {[catch {set fd [open \
9610 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9614 filerun $fd [list readresetstat $fd]
9615 nowbusy reset [mc "Resetting"]
9620 proc readresetstat {fd} {
9621 global mainhead mainheadid showlocalchanges rprogcoord
9623 if {[gets $fd line] >= 0} {
9624 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9625 set rprogcoord [expr {1.0 * $m / $n}]
9633 if {[catch {close $fd} err]} {
9636 set oldhead $mainheadid
9637 set newhead [exec git rev-parse HEAD]
9638 if {$newhead ne $oldhead} {
9639 movehead $newhead $mainhead
9640 movedhead $newhead $mainhead
9641 set mainheadid $newhead
9645 if {$showlocalchanges} {
9651 # context menu for a head
9652 proc headmenu {x y id head} {
9653 global headmenuid headmenuhead headctxmenu mainhead
9657 set headmenuhead $head
9659 if {[string match "remotes/*" $head]} {
9662 if {$head eq $mainhead} {
9665 $headctxmenu entryconfigure 0 -state $state
9666 $headctxmenu entryconfigure 1 -state $state
9667 tk_popup $headctxmenu $x $y
9671 global headmenuid headmenuhead headids
9672 global showlocalchanges
9674 # check the tree is clean first??
9675 nowbusy checkout [mc "Checking out"]
9679 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9683 if {$showlocalchanges} {
9687 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9691 proc readcheckoutstat {fd newhead newheadid} {
9692 global mainhead mainheadid headids showlocalchanges progresscoords
9693 global viewmainheadid curview
9695 if {[gets $fd line] >= 0} {
9696 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9697 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9702 set progresscoords {0 0}
9705 if {[catch {close $fd} err]} {
9708 set oldmainid $mainheadid
9709 set mainhead $newhead
9710 set mainheadid $newheadid
9711 set viewmainheadid($curview) $newheadid
9712 redrawtags $oldmainid
9713 redrawtags $newheadid
9715 if {$showlocalchanges} {
9721 global headmenuid headmenuhead mainhead
9724 set head $headmenuhead
9726 # this check shouldn't be needed any more...
9727 if {$head eq $mainhead} {
9728 error_popup [mc "Cannot delete the currently checked-out branch"]
9731 set dheads [descheads $id]
9732 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9733 # the stuff on this branch isn't on any other branch
9734 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9735 branch.\nReally delete branch %s?" $head $head]]} return
9739 if {[catch {exec git branch -D $head} err]} {
9744 removehead $id $head
9745 removedhead $id $head
9752 # Display a list of tags and heads
9754 global showrefstop bgcolor fgcolor selectbgcolor NS
9755 global bglist fglist reflistfilter reflist maincursor
9758 set showrefstop $top
9759 if {[winfo exists $top]} {
9765 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9766 make_transient $top .
9767 text $top.list -background $bgcolor -foreground $fgcolor \
9768 -selectbackground $selectbgcolor -font mainfont \
9769 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9770 -width 30 -height 20 -cursor $maincursor \
9771 -spacing1 1 -spacing3 1 -state disabled
9772 $top.list tag configure highlight -background $selectbgcolor
9773 lappend bglist $top.list
9774 lappend fglist $top.list
9775 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9776 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9777 grid $top.list $top.ysb -sticky nsew
9778 grid $top.xsb x -sticky ew
9780 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9781 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9782 set reflistfilter "*"
9783 trace add variable reflistfilter write reflistfilter_change
9784 pack $top.f.e -side right -fill x -expand 1
9785 pack $top.f.l -side left
9786 grid $top.f - -sticky ew -pady 2
9787 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9788 bind $top <Key-Escape> [list destroy $top]
9790 grid columnconfigure $top 0 -weight 1
9791 grid rowconfigure $top 0 -weight 1
9792 bind $top.list <1> {break}
9793 bind $top.list <B1-Motion> {break}
9794 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9799 proc sel_reflist {w x y} {
9800 global showrefstop reflist headids tagids otherrefids
9802 if {![winfo exists $showrefstop]} return
9803 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9804 set ref [lindex $reflist [expr {$l-1}]]
9805 set n [lindex $ref 0]
9806 switch -- [lindex $ref 1] {
9807 "H" {selbyid $headids($n)}
9808 "T" {selbyid $tagids($n)}
9809 "o" {selbyid $otherrefids($n)}
9811 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9814 proc unsel_reflist {} {
9817 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9818 $showrefstop.list tag remove highlight 0.0 end
9821 proc reflistfilter_change {n1 n2 op} {
9822 global reflistfilter
9824 after cancel refill_reflist
9825 after 200 refill_reflist
9828 proc refill_reflist {} {
9829 global reflist reflistfilter showrefstop headids tagids otherrefids
9832 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9834 foreach n [array names headids] {
9835 if {[string match $reflistfilter $n]} {
9836 if {[commitinview $headids($n) $curview]} {
9837 lappend refs [list $n H]
9839 interestedin $headids($n) {run refill_reflist}
9843 foreach n [array names tagids] {
9844 if {[string match $reflistfilter $n]} {
9845 if {[commitinview $tagids($n) $curview]} {
9846 lappend refs [list $n T]
9848 interestedin $tagids($n) {run refill_reflist}
9852 foreach n [array names otherrefids] {
9853 if {[string match $reflistfilter $n]} {
9854 if {[commitinview $otherrefids($n) $curview]} {
9855 lappend refs [list $n o]
9857 interestedin $otherrefids($n) {run refill_reflist}
9861 set refs [lsort -index 0 $refs]
9862 if {$refs eq $reflist} return
9864 # Update the contents of $showrefstop.list according to the
9865 # differences between $reflist (old) and $refs (new)
9866 $showrefstop.list conf -state normal
9867 $showrefstop.list insert end "\n"
9870 while {$i < [llength $reflist] || $j < [llength $refs]} {
9871 if {$i < [llength $reflist]} {
9872 if {$j < [llength $refs]} {
9873 set cmp [string compare [lindex $reflist $i 0] \
9874 [lindex $refs $j 0]]
9876 set cmp [string compare [lindex $reflist $i 1] \
9877 [lindex $refs $j 1]]
9887 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9895 set l [expr {$j + 1}]
9896 $showrefstop.list image create $l.0 -align baseline \
9897 -image reficon-[lindex $refs $j 1] -padx 2
9898 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9904 # delete last newline
9905 $showrefstop.list delete end-2c end-1c
9906 $showrefstop.list conf -state disabled
9909 # Stuff for finding nearby tags
9910 proc getallcommits {} {
9911 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9912 global idheads idtags idotherrefs allparents tagobjid
9915 if {![info exists allcommits]} {
9921 set allccache [file join $gitdir "gitk.cache"]
9923 set f [open $allccache r]
9932 set cmd [list | git rev-list --parents]
9933 set allcupdate [expr {$seeds ne {}}]
9937 set refs [concat [array names idheads] [array names idtags] \
9938 [array names idotherrefs]]
9941 foreach name [array names tagobjid] {
9942 lappend tagobjs $tagobjid($name)
9944 foreach id [lsort -unique $refs] {
9945 if {![info exists allparents($id)] &&
9946 [lsearch -exact $tagobjs $id] < 0} {
9957 set fd [open [concat $cmd $ids] r]
9958 fconfigure $fd -blocking 0
9961 filerun $fd [list getallclines $fd]
9967 # Since most commits have 1 parent and 1 child, we group strings of
9968 # such commits into "arcs" joining branch/merge points (BMPs), which
9969 # are commits that either don't have 1 parent or don't have 1 child.
9971 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9972 # arcout(id) - outgoing arcs for BMP
9973 # arcids(a) - list of IDs on arc including end but not start
9974 # arcstart(a) - BMP ID at start of arc
9975 # arcend(a) - BMP ID at end of arc
9976 # growing(a) - arc a is still growing
9977 # arctags(a) - IDs out of arcids (excluding end) that have tags
9978 # archeads(a) - IDs out of arcids (excluding end) that have heads
9979 # The start of an arc is at the descendent end, so "incoming" means
9980 # coming from descendents, and "outgoing" means going towards ancestors.
9982 proc getallclines {fd} {
9983 global allparents allchildren idtags idheads nextarc
9984 global arcnos arcids arctags arcout arcend arcstart archeads growing
9985 global seeds allcommits cachedarcs allcupdate
9988 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9989 set id [lindex $line 0]
9990 if {[info exists allparents($id)]} {
9995 set olds [lrange $line 1 end]
9996 set allparents($id) $olds
9997 if {![info exists allchildren($id)]} {
9998 set allchildren($id) {}
10003 if {[llength $olds] == 1 && [llength $a] == 1} {
10004 lappend arcids($a) $id
10005 if {[info exists idtags($id)]} {
10006 lappend arctags($a) $id
10008 if {[info exists idheads($id)]} {
10009 lappend archeads($a) $id
10011 if {[info exists allparents($olds)]} {
10012 # seen parent already
10013 if {![info exists arcout($olds)]} {
10016 lappend arcids($a) $olds
10017 set arcend($a) $olds
10020 lappend allchildren($olds) $id
10021 lappend arcnos($olds) $a
10025 foreach a $arcnos($id) {
10026 lappend arcids($a) $id
10033 lappend allchildren($p) $id
10034 set a [incr nextarc]
10035 set arcstart($a) $id
10036 set archeads($a) {}
10038 set archeads($a) {}
10042 if {[info exists allparents($p)]} {
10043 # seen it already, may need to make a new branch
10044 if {![info exists arcout($p)]} {
10047 lappend arcids($a) $p
10051 lappend arcnos($p) $a
10053 set arcout($id) $ao
10056 global cached_dheads cached_dtags cached_atags
10057 catch {unset cached_dheads}
10058 catch {unset cached_dtags}
10059 catch {unset cached_atags}
10062 return [expr {$nid >= 1000? 2: 1}]
10066 fconfigure $fd -blocking 1
10069 # got an error reading the list of commits
10070 # if we were updating, try rereading the whole thing again
10076 error_popup "[mc "Error reading commit topology information;\
10077 branch and preceding/following tag information\
10078 will be incomplete."]\n($err)"
10081 if {[incr allcommits -1] == 0} {
10091 proc recalcarc {a} {
10092 global arctags archeads arcids idtags idheads
10096 foreach id [lrange $arcids($a) 0 end-1] {
10097 if {[info exists idtags($id)]} {
10100 if {[info exists idheads($id)]} {
10104 set arctags($a) $at
10105 set archeads($a) $ah
10108 proc splitarc {p} {
10109 global arcnos arcids nextarc arctags archeads idtags idheads
10110 global arcstart arcend arcout allparents growing
10113 if {[llength $a] != 1} {
10114 puts "oops splitarc called but [llength $a] arcs already"
10117 set a [lindex $a 0]
10118 set i [lsearch -exact $arcids($a) $p]
10120 puts "oops splitarc $p not in arc $a"
10123 set na [incr nextarc]
10124 if {[info exists arcend($a)]} {
10125 set arcend($na) $arcend($a)
10127 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10128 set j [lsearch -exact $arcnos($l) $a]
10129 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10131 set tail [lrange $arcids($a) [expr {$i+1}] end]
10132 set arcids($a) [lrange $arcids($a) 0 $i]
10134 set arcstart($na) $p
10136 set arcids($na) $tail
10137 if {[info exists growing($a)]} {
10143 if {[llength $arcnos($id)] == 1} {
10144 set arcnos($id) $na
10146 set j [lsearch -exact $arcnos($id) $a]
10147 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10151 # reconstruct tags and heads lists
10152 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10156 set arctags($na) {}
10157 set archeads($na) {}
10161 # Update things for a new commit added that is a child of one
10162 # existing commit. Used when cherry-picking.
10163 proc addnewchild {id p} {
10164 global allparents allchildren idtags nextarc
10165 global arcnos arcids arctags arcout arcend arcstart archeads growing
10166 global seeds allcommits
10168 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10169 set allparents($id) [list $p]
10170 set allchildren($id) {}
10173 lappend allchildren($p) $id
10174 set a [incr nextarc]
10175 set arcstart($a) $id
10176 set archeads($a) {}
10178 set arcids($a) [list $p]
10180 if {![info exists arcout($p)]} {
10183 lappend arcnos($p) $a
10184 set arcout($id) [list $a]
10187 # This implements a cache for the topology information.
10188 # The cache saves, for each arc, the start and end of the arc,
10189 # the ids on the arc, and the outgoing arcs from the end.
10190 proc readcache {f} {
10191 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10192 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10196 set lim $cachedarcs
10197 if {$lim - $a > 500} {
10198 set lim [expr {$a + 500}]
10202 # finish reading the cache and setting up arctags, etc.
10204 if {$line ne "1"} {error "bad final version"}
10206 foreach id [array names idtags] {
10207 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10208 [llength $allparents($id)] == 1} {
10209 set a [lindex $arcnos($id) 0]
10210 if {$arctags($a) eq {}} {
10215 foreach id [array names idheads] {
10216 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10217 [llength $allparents($id)] == 1} {
10218 set a [lindex $arcnos($id) 0]
10219 if {$archeads($a) eq {}} {
10224 foreach id [lsort -unique $possible_seeds] {
10225 if {$arcnos($id) eq {}} {
10231 while {[incr a] <= $lim} {
10233 if {[llength $line] != 3} {error "bad line"}
10234 set s [lindex $line 0]
10235 set arcstart($a) $s
10236 lappend arcout($s) $a
10237 if {![info exists arcnos($s)]} {
10238 lappend possible_seeds $s
10241 set e [lindex $line 1]
10246 if {![info exists arcout($e)]} {
10250 set arcids($a) [lindex $line 2]
10251 foreach id $arcids($a) {
10252 lappend allparents($s) $id
10254 lappend arcnos($id) $a
10256 if {![info exists allparents($s)]} {
10257 set allparents($s) {}
10260 set archeads($a) {}
10262 set nextarc [expr {$a - 1}]
10274 proc getcache {f} {
10275 global nextarc cachedarcs possible_seeds
10279 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10280 # make sure it's an integer
10281 set cachedarcs [expr {int([lindex $line 1])}]
10282 if {$cachedarcs < 0} {error "bad number of arcs"}
10284 set possible_seeds {}
10292 proc dropcache {err} {
10293 global allcwait nextarc cachedarcs seeds
10295 #puts "dropping cache ($err)"
10296 foreach v {arcnos arcout arcids arcstart arcend growing \
10297 arctags archeads allparents allchildren} {
10308 proc writecache {f} {
10309 global cachearc cachedarcs allccache
10310 global arcstart arcend arcnos arcids arcout
10313 set lim $cachedarcs
10314 if {$lim - $a > 1000} {
10315 set lim [expr {$a + 1000}]
10318 while {[incr a] <= $lim} {
10319 if {[info exists arcend($a)]} {
10320 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10322 puts $f [list $arcstart($a) {} $arcids($a)]
10327 catch {file delete $allccache}
10328 #puts "writing cache failed ($err)"
10331 set cachearc [expr {$a - 1}]
10332 if {$a > $cachedarcs} {
10340 proc savecache {} {
10341 global nextarc cachedarcs cachearc allccache
10343 if {$nextarc == $cachedarcs} return
10345 set cachedarcs $nextarc
10347 set f [open $allccache w]
10348 puts $f [list 1 $cachedarcs]
10353 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10354 # or 0 if neither is true.
10355 proc anc_or_desc {a b} {
10356 global arcout arcstart arcend arcnos cached_isanc
10358 if {$arcnos($a) eq $arcnos($b)} {
10359 # Both are on the same arc(s); either both are the same BMP,
10360 # or if one is not a BMP, the other is also not a BMP or is
10361 # the BMP at end of the arc (and it only has 1 incoming arc).
10362 # Or both can be BMPs with no incoming arcs.
10363 if {$a eq $b || $arcnos($a) eq {}} {
10366 # assert {[llength $arcnos($a)] == 1}
10367 set arc [lindex $arcnos($a) 0]
10368 set i [lsearch -exact $arcids($arc) $a]
10369 set j [lsearch -exact $arcids($arc) $b]
10370 if {$i < 0 || $i > $j} {
10377 if {![info exists arcout($a)]} {
10378 set arc [lindex $arcnos($a) 0]
10379 if {[info exists arcend($arc)]} {
10380 set aend $arcend($arc)
10384 set a $arcstart($arc)
10388 if {![info exists arcout($b)]} {
10389 set arc [lindex $arcnos($b) 0]
10390 if {[info exists arcend($arc)]} {
10391 set bend $arcend($arc)
10395 set b $arcstart($arc)
10405 if {[info exists cached_isanc($a,$bend)]} {
10406 if {$cached_isanc($a,$bend)} {
10410 if {[info exists cached_isanc($b,$aend)]} {
10411 if {$cached_isanc($b,$aend)} {
10414 if {[info exists cached_isanc($a,$bend)]} {
10419 set todo [list $a $b]
10422 for {set i 0} {$i < [llength $todo]} {incr i} {
10423 set x [lindex $todo $i]
10424 if {$anc($x) eq {}} {
10427 foreach arc $arcnos($x) {
10428 set xd $arcstart($arc)
10429 if {$xd eq $bend} {
10430 set cached_isanc($a,$bend) 1
10431 set cached_isanc($b,$aend) 0
10433 } elseif {$xd eq $aend} {
10434 set cached_isanc($b,$aend) 1
10435 set cached_isanc($a,$bend) 0
10438 if {![info exists anc($xd)]} {
10439 set anc($xd) $anc($x)
10441 } elseif {$anc($xd) ne $anc($x)} {
10446 set cached_isanc($a,$bend) 0
10447 set cached_isanc($b,$aend) 0
10451 # This identifies whether $desc has an ancestor that is
10452 # a growing tip of the graph and which is not an ancestor of $anc
10453 # and returns 0 if so and 1 if not.
10454 # If we subsequently discover a tag on such a growing tip, and that
10455 # turns out to be a descendent of $anc (which it could, since we
10456 # don't necessarily see children before parents), then $desc
10457 # isn't a good choice to display as a descendent tag of
10458 # $anc (since it is the descendent of another tag which is
10459 # a descendent of $anc). Similarly, $anc isn't a good choice to
10460 # display as a ancestor tag of $desc.
10462 proc is_certain {desc anc} {
10463 global arcnos arcout arcstart arcend growing problems
10466 if {[llength $arcnos($anc)] == 1} {
10467 # tags on the same arc are certain
10468 if {$arcnos($desc) eq $arcnos($anc)} {
10471 if {![info exists arcout($anc)]} {
10472 # if $anc is partway along an arc, use the start of the arc instead
10473 set a [lindex $arcnos($anc) 0]
10474 set anc $arcstart($a)
10477 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10480 set a [lindex $arcnos($desc) 0]
10486 set anclist [list $x]
10490 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10491 set x [lindex $anclist $i]
10496 foreach a $arcout($x) {
10497 if {[info exists growing($a)]} {
10498 if {![info exists growanc($x)] && $dl($x)} {
10504 if {[info exists dl($y)]} {
10508 if {![info exists done($y)]} {
10511 if {[info exists growanc($x)]} {
10515 for {set k 0} {$k < [llength $xl]} {incr k} {
10516 set z [lindex $xl $k]
10517 foreach c $arcout($z) {
10518 if {[info exists arcend($c)]} {
10520 if {[info exists dl($v)] && $dl($v)} {
10522 if {![info exists done($v)]} {
10525 if {[info exists growanc($v)]} {
10535 } elseif {$y eq $anc || !$dl($x)} {
10546 foreach x [array names growanc] {
10555 proc validate_arctags {a} {
10556 global arctags idtags
10559 set na $arctags($a)
10560 foreach id $arctags($a) {
10562 if {![info exists idtags($id)]} {
10563 set na [lreplace $na $i $i]
10567 set arctags($a) $na
10570 proc validate_archeads {a} {
10571 global archeads idheads
10574 set na $archeads($a)
10575 foreach id $archeads($a) {
10577 if {![info exists idheads($id)]} {
10578 set na [lreplace $na $i $i]
10582 set archeads($a) $na
10585 # Return the list of IDs that have tags that are descendents of id,
10586 # ignoring IDs that are descendents of IDs already reported.
10587 proc desctags {id} {
10588 global arcnos arcstart arcids arctags idtags allparents
10589 global growing cached_dtags
10591 if {![info exists allparents($id)]} {
10594 set t1 [clock clicks -milliseconds]
10596 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10597 # part-way along an arc; check that arc first
10598 set a [lindex $arcnos($id) 0]
10599 if {$arctags($a) ne {}} {
10600 validate_arctags $a
10601 set i [lsearch -exact $arcids($a) $id]
10603 foreach t $arctags($a) {
10604 set j [lsearch -exact $arcids($a) $t]
10605 if {$j >= $i} break
10612 set id $arcstart($a)
10613 if {[info exists idtags($id)]} {
10617 if {[info exists cached_dtags($id)]} {
10618 return $cached_dtags($id)
10622 set todo [list $id]
10625 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10626 set id [lindex $todo $i]
10628 set ta [info exists hastaggedancestor($id)]
10632 # ignore tags on starting node
10633 if {!$ta && $i > 0} {
10634 if {[info exists idtags($id)]} {
10635 set tagloc($id) $id
10637 } elseif {[info exists cached_dtags($id)]} {
10638 set tagloc($id) $cached_dtags($id)
10642 foreach a $arcnos($id) {
10643 set d $arcstart($a)
10644 if {!$ta && $arctags($a) ne {}} {
10645 validate_arctags $a
10646 if {$arctags($a) ne {}} {
10647 lappend tagloc($id) [lindex $arctags($a) end]
10650 if {$ta || $arctags($a) ne {}} {
10651 set tomark [list $d]
10652 for {set j 0} {$j < [llength $tomark]} {incr j} {
10653 set dd [lindex $tomark $j]
10654 if {![info exists hastaggedancestor($dd)]} {
10655 if {[info exists done($dd)]} {
10656 foreach b $arcnos($dd) {
10657 lappend tomark $arcstart($b)
10659 if {[info exists tagloc($dd)]} {
10662 } elseif {[info exists queued($dd)]} {
10665 set hastaggedancestor($dd) 1
10669 if {![info exists queued($d)]} {
10672 if {![info exists hastaggedancestor($d)]} {
10679 foreach id [array names tagloc] {
10680 if {![info exists hastaggedancestor($id)]} {
10681 foreach t $tagloc($id) {
10682 if {[lsearch -exact $tags $t] < 0} {
10688 set t2 [clock clicks -milliseconds]
10691 # remove tags that are descendents of other tags
10692 for {set i 0} {$i < [llength $tags]} {incr i} {
10693 set a [lindex $tags $i]
10694 for {set j 0} {$j < $i} {incr j} {
10695 set b [lindex $tags $j]
10696 set r [anc_or_desc $a $b]
10698 set tags [lreplace $tags $j $j]
10701 } elseif {$r == -1} {
10702 set tags [lreplace $tags $i $i]
10709 if {[array names growing] ne {}} {
10710 # graph isn't finished, need to check if any tag could get
10711 # eclipsed by another tag coming later. Simply ignore any
10712 # tags that could later get eclipsed.
10715 if {[is_certain $t $origid]} {
10719 if {$tags eq $ctags} {
10720 set cached_dtags($origid) $tags
10725 set cached_dtags($origid) $tags
10727 set t3 [clock clicks -milliseconds]
10728 if {0 && $t3 - $t1 >= 100} {
10729 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10730 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10735 proc anctags {id} {
10736 global arcnos arcids arcout arcend arctags idtags allparents
10737 global growing cached_atags
10739 if {![info exists allparents($id)]} {
10742 set t1 [clock clicks -milliseconds]
10744 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10745 # part-way along an arc; check that arc first
10746 set a [lindex $arcnos($id) 0]
10747 if {$arctags($a) ne {}} {
10748 validate_arctags $a
10749 set i [lsearch -exact $arcids($a) $id]
10750 foreach t $arctags($a) {
10751 set j [lsearch -exact $arcids($a) $t]
10757 if {![info exists arcend($a)]} {
10761 if {[info exists idtags($id)]} {
10765 if {[info exists cached_atags($id)]} {
10766 return $cached_atags($id)
10770 set todo [list $id]
10774 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10775 set id [lindex $todo $i]
10777 set td [info exists hastaggeddescendent($id)]
10781 # ignore tags on starting node
10782 if {!$td && $i > 0} {
10783 if {[info exists idtags($id)]} {
10784 set tagloc($id) $id
10786 } elseif {[info exists cached_atags($id)]} {
10787 set tagloc($id) $cached_atags($id)
10791 foreach a $arcout($id) {
10792 if {!$td && $arctags($a) ne {}} {
10793 validate_arctags $a
10794 if {$arctags($a) ne {}} {
10795 lappend tagloc($id) [lindex $arctags($a) 0]
10798 if {![info exists arcend($a)]} continue
10800 if {$td || $arctags($a) ne {}} {
10801 set tomark [list $d]
10802 for {set j 0} {$j < [llength $tomark]} {incr j} {
10803 set dd [lindex $tomark $j]
10804 if {![info exists hastaggeddescendent($dd)]} {
10805 if {[info exists done($dd)]} {
10806 foreach b $arcout($dd) {
10807 if {[info exists arcend($b)]} {
10808 lappend tomark $arcend($b)
10811 if {[info exists tagloc($dd)]} {
10814 } elseif {[info exists queued($dd)]} {
10817 set hastaggeddescendent($dd) 1
10821 if {![info exists queued($d)]} {
10824 if {![info exists hastaggeddescendent($d)]} {
10830 set t2 [clock clicks -milliseconds]
10833 foreach id [array names tagloc] {
10834 if {![info exists hastaggeddescendent($id)]} {
10835 foreach t $tagloc($id) {
10836 if {[lsearch -exact $tags $t] < 0} {
10843 # remove tags that are ancestors of other tags
10844 for {set i 0} {$i < [llength $tags]} {incr i} {
10845 set a [lindex $tags $i]
10846 for {set j 0} {$j < $i} {incr j} {
10847 set b [lindex $tags $j]
10848 set r [anc_or_desc $a $b]
10850 set tags [lreplace $tags $j $j]
10853 } elseif {$r == 1} {
10854 set tags [lreplace $tags $i $i]
10861 if {[array names growing] ne {}} {
10862 # graph isn't finished, need to check if any tag could get
10863 # eclipsed by another tag coming later. Simply ignore any
10864 # tags that could later get eclipsed.
10867 if {[is_certain $origid $t]} {
10871 if {$tags eq $ctags} {
10872 set cached_atags($origid) $tags
10877 set cached_atags($origid) $tags
10879 set t3 [clock clicks -milliseconds]
10880 if {0 && $t3 - $t1 >= 100} {
10881 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10882 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10887 # Return the list of IDs that have heads that are descendents of id,
10888 # including id itself if it has a head.
10889 proc descheads {id} {
10890 global arcnos arcstart arcids archeads idheads cached_dheads
10891 global allparents arcout
10893 if {![info exists allparents($id)]} {
10897 if {![info exists arcout($id)]} {
10898 # part-way along an arc; check it first
10899 set a [lindex $arcnos($id) 0]
10900 if {$archeads($a) ne {}} {
10901 validate_archeads $a
10902 set i [lsearch -exact $arcids($a) $id]
10903 foreach t $archeads($a) {
10904 set j [lsearch -exact $arcids($a) $t]
10909 set id $arcstart($a)
10912 set todo [list $id]
10915 for {set i 0} {$i < [llength $todo]} {incr i} {
10916 set id [lindex $todo $i]
10917 if {[info exists cached_dheads($id)]} {
10918 set ret [concat $ret $cached_dheads($id)]
10920 if {[info exists idheads($id)]} {
10923 foreach a $arcnos($id) {
10924 if {$archeads($a) ne {}} {
10925 validate_archeads $a
10926 if {$archeads($a) ne {}} {
10927 set ret [concat $ret $archeads($a)]
10930 set d $arcstart($a)
10931 if {![info exists seen($d)]} {
10938 set ret [lsort -unique $ret]
10939 set cached_dheads($origid) $ret
10940 return [concat $ret $aret]
10943 proc addedtag {id} {
10944 global arcnos arcout cached_dtags cached_atags
10946 if {![info exists arcnos($id)]} return
10947 if {![info exists arcout($id)]} {
10948 recalcarc [lindex $arcnos($id) 0]
10950 catch {unset cached_dtags}
10951 catch {unset cached_atags}
10954 proc addedhead {hid head} {
10955 global arcnos arcout cached_dheads
10957 if {![info exists arcnos($hid)]} return
10958 if {![info exists arcout($hid)]} {
10959 recalcarc [lindex $arcnos($hid) 0]
10961 catch {unset cached_dheads}
10964 proc removedhead {hid head} {
10965 global cached_dheads
10967 catch {unset cached_dheads}
10970 proc movedhead {hid head} {
10971 global arcnos arcout cached_dheads
10973 if {![info exists arcnos($hid)]} return
10974 if {![info exists arcout($hid)]} {
10975 recalcarc [lindex $arcnos($hid) 0]
10977 catch {unset cached_dheads}
10980 proc changedrefs {} {
10981 global cached_dheads cached_dtags cached_atags cached_tagcontent
10982 global arctags archeads arcnos arcout idheads idtags
10984 foreach id [concat [array names idheads] [array names idtags]] {
10985 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10986 set a [lindex $arcnos($id) 0]
10987 if {![info exists donearc($a)]} {
10993 catch {unset cached_tagcontent}
10994 catch {unset cached_dtags}
10995 catch {unset cached_atags}
10996 catch {unset cached_dheads}
10999 proc rereadrefs {} {
11000 global idtags idheads idotherrefs mainheadid
11002 set refids [concat [array names idtags] \
11003 [array names idheads] [array names idotherrefs]]
11004 foreach id $refids {
11005 if {![info exists ref($id)]} {
11006 set ref($id) [listrefs $id]
11009 set oldmainhead $mainheadid
11012 set refids [lsort -unique [concat $refids [array names idtags] \
11013 [array names idheads] [array names idotherrefs]]]
11014 foreach id $refids {
11015 set v [listrefs $id]
11016 if {![info exists ref($id)] || $ref($id) != $v} {
11020 if {$oldmainhead ne $mainheadid} {
11021 redrawtags $oldmainhead
11022 redrawtags $mainheadid
11027 proc listrefs {id} {
11028 global idtags idheads idotherrefs
11031 if {[info exists idtags($id)]} {
11035 if {[info exists idheads($id)]} {
11036 set y $idheads($id)
11039 if {[info exists idotherrefs($id)]} {
11040 set z $idotherrefs($id)
11042 return [list $x $y $z]
11045 proc add_tag_ctext {tag} {
11046 global ctext cached_tagcontent tagids
11048 if {![info exists cached_tagcontent($tag)]} {
11050 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11053 $ctext insert end "[mc "Tag"]: $tag\n" bold
11054 if {[info exists cached_tagcontent($tag)]} {
11055 set text $cached_tagcontent($tag)
11057 set text "[mc "Id"]: $tagids($tag)"
11059 appendwithlinks $text {}
11062 proc showtag {tag isnew} {
11063 global ctext cached_tagcontent tagids linknum tagobjid
11066 addtohistory [list showtag $tag 0] savectextpos
11068 $ctext conf -state normal
11073 maybe_scroll_ctext 1
11074 $ctext conf -state disabled
11078 proc showtags {id isnew} {
11079 global idtags ctext linknum
11082 addtohistory [list showtags $id 0] savectextpos
11084 $ctext conf -state normal
11089 foreach tag $idtags($id) {
11090 $ctext insert end $sep
11094 maybe_scroll_ctext 1
11095 $ctext conf -state disabled
11107 if {[info exists gitktmpdir]} {
11108 catch {file delete -force $gitktmpdir}
11112 proc mkfontdisp {font top which} {
11113 global fontattr fontpref $font NS use_ttk
11115 set fontpref($font) [set $font]
11116 ${NS}::button $top.${font}but -text $which \
11117 -command [list choosefont $font $which]
11118 ${NS}::label $top.$font -relief flat -font $font \
11119 -text $fontattr($font,family) -justify left
11120 grid x $top.${font}but $top.$font -sticky w
11123 proc choosefont {font which} {
11124 global fontparam fontlist fonttop fontattr
11127 set fontparam(which) $which
11128 set fontparam(font) $font
11129 set fontparam(family) [font actual $font -family]
11130 set fontparam(size) $fontattr($font,size)
11131 set fontparam(weight) $fontattr($font,weight)
11132 set fontparam(slant) $fontattr($font,slant)
11135 if {![winfo exists $top]} {
11137 eval font config sample [font actual $font]
11139 make_transient $top $prefstop
11140 wm title $top [mc "Gitk font chooser"]
11141 ${NS}::label $top.l -textvariable fontparam(which)
11142 pack $top.l -side top
11143 set fontlist [lsort [font families]]
11144 ${NS}::frame $top.f
11145 listbox $top.f.fam -listvariable fontlist \
11146 -yscrollcommand [list $top.f.sb set]
11147 bind $top.f.fam <<ListboxSelect>> selfontfam
11148 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11149 pack $top.f.sb -side right -fill y
11150 pack $top.f.fam -side left -fill both -expand 1
11151 pack $top.f -side top -fill both -expand 1
11152 ${NS}::frame $top.g
11153 spinbox $top.g.size -from 4 -to 40 -width 4 \
11154 -textvariable fontparam(size) \
11155 -validatecommand {string is integer -strict %s}
11156 checkbutton $top.g.bold -padx 5 \
11157 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11158 -variable fontparam(weight) -onvalue bold -offvalue normal
11159 checkbutton $top.g.ital -padx 5 \
11160 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11161 -variable fontparam(slant) -onvalue italic -offvalue roman
11162 pack $top.g.size $top.g.bold $top.g.ital -side left
11163 pack $top.g -side top
11164 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11166 $top.c create text 100 25 -anchor center -text $which -font sample \
11167 -fill black -tags text
11168 bind $top.c <Configure> [list centertext $top.c]
11169 pack $top.c -side top -fill x
11170 ${NS}::frame $top.buts
11171 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11172 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11173 bind $top <Key-Return> fontok
11174 bind $top <Key-Escape> fontcan
11175 grid $top.buts.ok $top.buts.can
11176 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11177 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11178 pack $top.buts -side bottom -fill x
11179 trace add variable fontparam write chg_fontparam
11182 $top.c itemconf text -text $which
11184 set i [lsearch -exact $fontlist $fontparam(family)]
11186 $top.f.fam selection set $i
11191 proc centertext {w} {
11192 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11196 global fontparam fontpref prefstop
11198 set f $fontparam(font)
11199 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11200 if {$fontparam(weight) eq "bold"} {
11201 lappend fontpref($f) "bold"
11203 if {$fontparam(slant) eq "italic"} {
11204 lappend fontpref($f) "italic"
11206 set w $prefstop.notebook.fonts.$f
11207 $w conf -text $fontparam(family) -font $fontpref($f)
11213 global fonttop fontparam
11215 if {[info exists fonttop]} {
11216 catch {destroy $fonttop}
11217 catch {font delete sample}
11223 if {[package vsatisfies [package provide Tk] 8.6]} {
11224 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11225 # function to make use of it.
11226 proc choosefont {font which} {
11227 tk fontchooser configure -title $which -font $font \
11228 -command [list on_choosefont $font $which]
11229 tk fontchooser show
11231 proc on_choosefont {font which newfont} {
11233 puts stderr "$font $newfont"
11234 array set f [font actual $newfont]
11235 set fontparam(which) $which
11236 set fontparam(font) $font
11237 set fontparam(family) $f(-family)
11238 set fontparam(size) $f(-size)
11239 set fontparam(weight) $f(-weight)
11240 set fontparam(slant) $f(-slant)
11245 proc selfontfam {} {
11246 global fonttop fontparam
11248 set i [$fonttop.f.fam curselection]
11250 set fontparam(family) [$fonttop.f.fam get $i]
11254 proc chg_fontparam {v sub op} {
11257 font config sample -$sub $fontparam($sub)
11260 # Create a property sheet tab page
11261 proc create_prefs_page {w} {
11263 set parent [join [lrange [split $w .] 0 end-1] .]
11264 if {[winfo class $parent] eq "TNotebook"} {
11267 ${NS}::labelframe $w
11271 proc prefspage_general {notebook} {
11272 global NS maxwidth maxgraphpct showneartags showlocalchanges
11273 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11274 global hideremotes want_ttk have_ttk maxrefs
11276 set page [create_prefs_page $notebook.general]
11278 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11279 grid $page.ldisp - -sticky w -pady 10
11280 ${NS}::label $page.spacer -text " "
11281 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11282 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11283 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11284 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11285 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11286 grid x $page.maxpctl $page.maxpct -sticky w
11287 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11288 -variable showlocalchanges
11289 grid x $page.showlocal -sticky w
11290 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11291 -variable autoselect
11292 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11293 grid x $page.autoselect $page.autosellen -sticky w
11294 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11295 -variable hideremotes
11296 grid x $page.hideremotes -sticky w
11298 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11299 grid $page.ddisp - -sticky w -pady 10
11300 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11301 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11302 grid x $page.tabstopl $page.tabstop -sticky w
11303 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11304 -variable showneartags
11305 grid x $page.ntag -sticky w
11306 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11307 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11308 grid x $page.maxrefsl $page.maxrefs -sticky w
11309 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11310 -variable limitdiffs
11311 grid x $page.ldiff -sticky w
11312 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11313 -variable perfile_attrs
11314 grid x $page.lattr -sticky w
11316 ${NS}::entry $page.extdifft -textvariable extdifftool
11317 ${NS}::frame $page.extdifff
11318 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11319 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11320 pack $page.extdifff.l $page.extdifff.b -side left
11321 pack configure $page.extdifff.l -padx 10
11322 grid x $page.extdifff $page.extdifft -sticky ew
11324 ${NS}::label $page.lgen -text [mc "General options"]
11325 grid $page.lgen - -sticky w -pady 10
11326 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11327 -text [mc "Use themed widgets"]
11329 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11331 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11333 grid x $page.want_ttk $page.ttk_note -sticky w
11337 proc prefspage_colors {notebook} {
11338 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11340 set page [create_prefs_page $notebook.colors]
11342 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11343 grid $page.cdisp - -sticky w -pady 10
11344 label $page.ui -padx 40 -relief sunk -background $uicolor
11345 ${NS}::button $page.uibut -text [mc "Interface"] \
11346 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11347 grid x $page.uibut $page.ui -sticky w
11348 label $page.bg -padx 40 -relief sunk -background $bgcolor
11349 ${NS}::button $page.bgbut -text [mc "Background"] \
11350 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11351 grid x $page.bgbut $page.bg -sticky w
11352 label $page.fg -padx 40 -relief sunk -background $fgcolor
11353 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11354 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11355 grid x $page.fgbut $page.fg -sticky w
11356 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11357 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11358 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11359 [list $ctext tag conf d0 -foreground]]
11360 grid x $page.diffoldbut $page.diffold -sticky w
11361 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11362 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11363 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11364 [list $ctext tag conf dresult -foreground]]
11365 grid x $page.diffnewbut $page.diffnew -sticky w
11366 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11367 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11368 -command [list choosecolor diffcolors 2 $page.hunksep \
11369 [mc "diff hunk header"] \
11370 [list $ctext tag conf hunksep -foreground]]
11371 grid x $page.hunksepbut $page.hunksep -sticky w
11372 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11373 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11374 -command [list choosecolor markbgcolor {} $page.markbgsep \
11375 [mc "marked line background"] \
11376 [list $ctext tag conf omark -background]]
11377 grid x $page.markbgbut $page.markbgsep -sticky w
11378 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11379 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11380 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11381 grid x $page.selbgbut $page.selbgsep -sticky w
11385 proc prefspage_fonts {notebook} {
11387 set page [create_prefs_page $notebook.fonts]
11388 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11389 grid $page.cfont - -sticky w -pady 10
11390 mkfontdisp mainfont $page [mc "Main font"]
11391 mkfontdisp textfont $page [mc "Diff display font"]
11392 mkfontdisp uifont $page [mc "User interface font"]
11397 global maxwidth maxgraphpct use_ttk NS
11398 global oldprefs prefstop showneartags showlocalchanges
11399 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11400 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11401 global hideremotes want_ttk have_ttk
11405 if {[winfo exists $top]} {
11409 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11410 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11411 set oldprefs($v) [set $v]
11414 wm title $top [mc "Gitk preferences"]
11415 make_transient $top .
11417 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11418 set notebook [ttk::notebook $top.notebook]
11420 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11423 lappend pages [prefspage_general $notebook] [mc "General"]
11424 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11425 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11427 foreach {page title} $pages {
11428 if {$use_notebook} {
11429 $notebook add $page -text $title
11431 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11432 -text $title -command [list raise $page]]
11433 $page configure -text $title
11434 grid $btn -row 0 -column [incr col] -sticky w
11435 grid $page -row 1 -column 0 -sticky news -columnspan 100
11439 if {!$use_notebook} {
11440 grid columnconfigure $notebook 0 -weight 1
11441 grid rowconfigure $notebook 1 -weight 1
11442 raise [lindex $pages 0]
11445 grid $notebook -sticky news -padx 2 -pady 2
11446 grid rowconfigure $top 0 -weight 1
11447 grid columnconfigure $top 0 -weight 1
11449 ${NS}::frame $top.buts
11450 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11451 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11452 bind $top <Key-Return> prefsok
11453 bind $top <Key-Escape> prefscan
11454 grid $top.buts.ok $top.buts.can
11455 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11456 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11457 grid $top.buts - - -pady 10 -sticky ew
11458 grid columnconfigure $top 2 -weight 1
11459 bind $top <Visibility> [list focus $top.buts.ok]
11462 proc choose_extdiff {} {
11465 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11467 set extdifftool $prog
11471 proc choosecolor {v vi w x cmd} {
11474 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11475 -title [mc "Gitk: choose color for %s" $x]]
11476 if {$c eq {}} return
11477 $w conf -background $c
11482 proc setselbg {c} {
11483 global bglist cflist
11484 foreach w $bglist {
11485 $w configure -selectbackground $c
11487 $cflist tag configure highlight \
11488 -background [$cflist cget -selectbackground]
11489 allcanvs itemconf secsel -fill $c
11492 # This sets the background color and the color scheme for the whole UI.
11493 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11494 # if we don't specify one ourselves, which makes the checkbuttons and
11495 # radiobuttons look bad. This chooses white for selectColor if the
11496 # background color is light, or black if it is dark.
11498 if {[tk windowingsystem] eq "win32"} { return }
11499 set bg [winfo rgb . $c]
11501 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11504 tk_setPalette background $c selectColor $selc
11510 foreach w $bglist {
11511 $w conf -background $c
11518 foreach w $fglist {
11519 $w conf -foreground $c
11521 allcanvs itemconf text -fill $c
11522 $canv itemconf circle -outline $c
11523 $canv itemconf markid -outline $c
11527 global oldprefs prefstop
11529 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11530 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11532 set $v $oldprefs($v)
11534 catch {destroy $prefstop}
11540 global maxwidth maxgraphpct
11541 global oldprefs prefstop showneartags showlocalchanges
11542 global fontpref mainfont textfont uifont
11543 global limitdiffs treediffs perfile_attrs
11546 catch {destroy $prefstop}
11550 if {$mainfont ne $fontpref(mainfont)} {
11551 set mainfont $fontpref(mainfont)
11552 parsefont mainfont $mainfont
11553 eval font configure mainfont [fontflags mainfont]
11554 eval font configure mainfontbold [fontflags mainfont 1]
11558 if {$textfont ne $fontpref(textfont)} {
11559 set textfont $fontpref(textfont)
11560 parsefont textfont $textfont
11561 eval font configure textfont [fontflags textfont]
11562 eval font configure textfontbold [fontflags textfont 1]
11564 if {$uifont ne $fontpref(uifont)} {
11565 set uifont $fontpref(uifont)
11566 parsefont uifont $uifont
11567 eval font configure uifont [fontflags uifont]
11570 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11571 if {$showlocalchanges} {
11577 if {$limitdiffs != $oldprefs(limitdiffs) ||
11578 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11579 # treediffs elements are limited by path;
11580 # won't have encodings cached if perfile_attrs was just turned on
11581 catch {unset treediffs}
11583 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11584 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11586 } elseif {$showneartags != $oldprefs(showneartags) ||
11587 $limitdiffs != $oldprefs(limitdiffs)} {
11590 if {$hideremotes != $oldprefs(hideremotes)} {
11595 proc formatdate {d} {
11596 global datetimeformat
11598 # If $datetimeformat includes a timezone, display in the
11599 # timezone of the argument. Otherwise, display in local time.
11600 if {[string match {*%[zZ]*} $datetimeformat]} {
11601 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11602 # Tcl < 8.5 does not support -timezone. Emulate it by
11603 # setting TZ (e.g. TZ=<-0430>+04:30).
11605 if {[info exists env(TZ)]} {
11606 set savedTZ $env(TZ)
11608 set zone [lindex $d 1]
11609 set sign [string map {+ - - +} [string index $zone 0]]
11610 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11611 set d [clock format [lindex $d 0] -format $datetimeformat]
11612 if {[info exists savedTZ]} {
11613 set env(TZ) $savedTZ
11619 set d [clock format [lindex $d 0] -format $datetimeformat]
11625 # This list of encoding names and aliases is distilled from
11626 # http://www.iana.org/assignments/character-sets.
11627 # Not all of them are supported by Tcl.
11628 set encoding_aliases {
11629 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11630 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11631 { ISO-10646-UTF-1 csISO10646UTF1 }
11632 { ISO_646.basic:1983 ref csISO646basic1983 }
11633 { INVARIANT csINVARIANT }
11634 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11635 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11636 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11637 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11638 { NATS-DANO iso-ir-9-1 csNATSDANO }
11639 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11640 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11641 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11642 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11643 { ISO-2022-KR csISO2022KR }
11645 { ISO-2022-JP csISO2022JP }
11646 { ISO-2022-JP-2 csISO2022JP2 }
11647 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11648 csISO13JISC6220jp }
11649 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11650 { IT iso-ir-15 ISO646-IT csISO15Italian }
11651 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11652 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11653 { greek7-old iso-ir-18 csISO18Greek7Old }
11654 { latin-greek iso-ir-19 csISO19LatinGreek }
11655 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11656 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11657 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11658 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11659 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11660 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11661 { INIS iso-ir-49 csISO49INIS }
11662 { INIS-8 iso-ir-50 csISO50INIS8 }
11663 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11664 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11665 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11666 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11667 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11668 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11669 csISO60Norwegian1 }
11670 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11671 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11672 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11673 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11674 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11675 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11676 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11677 { greek7 iso-ir-88 csISO88Greek7 }
11678 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11679 { iso-ir-90 csISO90 }
11680 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11681 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11682 csISO92JISC62991984b }
11683 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11684 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11685 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11686 csISO95JIS62291984handadd }
11687 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11688 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11689 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11690 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11691 CP819 csISOLatin1 }
11692 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11693 { T.61-7bit iso-ir-102 csISO102T617bit }
11694 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11695 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11696 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11697 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11698 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11699 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11700 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11701 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11702 arabic csISOLatinArabic }
11703 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11704 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11705 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11706 greek greek8 csISOLatinGreek }
11707 { T.101-G2 iso-ir-128 csISO128T101G2 }
11708 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11710 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11711 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11712 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11713 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11714 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11715 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11716 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11717 csISOLatinCyrillic }
11718 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11719 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11720 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11721 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11722 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11723 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11724 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11725 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11726 { ISO_10367-box iso-ir-155 csISO10367Box }
11727 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11728 { latin-lap lap iso-ir-158 csISO158Lap }
11729 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11730 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11733 { JIS_X0201 X0201 csHalfWidthKatakana }
11734 { KSC5636 ISO646-KR csKSC5636 }
11735 { ISO-10646-UCS-2 csUnicode }
11736 { ISO-10646-UCS-4 csUCS4 }
11737 { DEC-MCS dec csDECMCS }
11738 { hp-roman8 roman8 r8 csHPRoman8 }
11739 { macintosh mac csMacintosh }
11740 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11742 { IBM038 EBCDIC-INT cp038 csIBM038 }
11743 { IBM273 CP273 csIBM273 }
11744 { IBM274 EBCDIC-BE CP274 csIBM274 }
11745 { IBM275 EBCDIC-BR cp275 csIBM275 }
11746 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11747 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11748 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11749 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11750 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11751 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11752 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11753 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11754 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11755 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11756 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11757 { IBM437 cp437 437 csPC8CodePage437 }
11758 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11759 { IBM775 cp775 csPC775Baltic }
11760 { IBM850 cp850 850 csPC850Multilingual }
11761 { IBM851 cp851 851 csIBM851 }
11762 { IBM852 cp852 852 csPCp852 }
11763 { IBM855 cp855 855 csIBM855 }
11764 { IBM857 cp857 857 csIBM857 }
11765 { IBM860 cp860 860 csIBM860 }
11766 { IBM861 cp861 861 cp-is csIBM861 }
11767 { IBM862 cp862 862 csPC862LatinHebrew }
11768 { IBM863 cp863 863 csIBM863 }
11769 { IBM864 cp864 csIBM864 }
11770 { IBM865 cp865 865 csIBM865 }
11771 { IBM866 cp866 866 csIBM866 }
11772 { IBM868 CP868 cp-ar csIBM868 }
11773 { IBM869 cp869 869 cp-gr csIBM869 }
11774 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11775 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11776 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11777 { IBM891 cp891 csIBM891 }
11778 { IBM903 cp903 csIBM903 }
11779 { IBM904 cp904 904 csIBBM904 }
11780 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11781 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11782 { IBM1026 CP1026 csIBM1026 }
11783 { EBCDIC-AT-DE csIBMEBCDICATDE }
11784 { EBCDIC-AT-DE-A csEBCDICATDEA }
11785 { EBCDIC-CA-FR csEBCDICCAFR }
11786 { EBCDIC-DK-NO csEBCDICDKNO }
11787 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11788 { EBCDIC-FI-SE csEBCDICFISE }
11789 { EBCDIC-FI-SE-A csEBCDICFISEA }
11790 { EBCDIC-FR csEBCDICFR }
11791 { EBCDIC-IT csEBCDICIT }
11792 { EBCDIC-PT csEBCDICPT }
11793 { EBCDIC-ES csEBCDICES }
11794 { EBCDIC-ES-A csEBCDICESA }
11795 { EBCDIC-ES-S csEBCDICESS }
11796 { EBCDIC-UK csEBCDICUK }
11797 { EBCDIC-US csEBCDICUS }
11798 { UNKNOWN-8BIT csUnknown8BiT }
11799 { MNEMONIC csMnemonic }
11801 { VISCII csVISCII }
11804 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11805 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11806 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11807 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11808 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11809 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11810 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11811 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11812 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11813 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11814 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11815 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11816 { IBM1047 IBM-1047 }
11817 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11818 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11819 { UNICODE-1-1 csUnicode11 }
11820 { CESU-8 csCESU-8 }
11821 { BOCU-1 csBOCU-1 }
11822 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11823 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11825 { ISO-8859-15 ISO_8859-15 Latin-9 }
11826 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11827 { GBK CP936 MS936 windows-936 }
11828 { JIS_Encoding csJISEncoding }
11829 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11830 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11832 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11833 { ISO-10646-UCS-Basic csUnicodeASCII }
11834 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11835 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11836 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11837 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11838 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11839 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11840 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11841 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11842 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11843 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11844 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11845 { Ventura-US csVenturaUS }
11846 { Ventura-International csVenturaInternational }
11847 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11848 { PC8-Turkish csPC8Turkish }
11849 { IBM-Symbols csIBMSymbols }
11850 { IBM-Thai csIBMThai }
11851 { HP-Legal csHPLegal }
11852 { HP-Pi-font csHPPiFont }
11853 { HP-Math8 csHPMath8 }
11854 { Adobe-Symbol-Encoding csHPPSMath }
11855 { HP-DeskTop csHPDesktop }
11856 { Ventura-Math csVenturaMath }
11857 { Microsoft-Publishing csMicrosoftPublishing }
11858 { Windows-31J csWindows31J }
11859 { GB2312 csGB2312 }
11863 proc tcl_encoding {enc} {
11864 global encoding_aliases tcl_encoding_cache
11865 if {[info exists tcl_encoding_cache($enc)]} {
11866 return $tcl_encoding_cache($enc)
11868 set names [encoding names]
11869 set lcnames [string tolower $names]
11870 set enc [string tolower $enc]
11871 set i [lsearch -exact $lcnames $enc]
11873 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11874 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11875 set i [lsearch -exact $lcnames $encx]
11879 foreach l $encoding_aliases {
11880 set ll [string tolower $l]
11881 if {[lsearch -exact $ll $enc] < 0} continue
11882 # look through the aliases for one that tcl knows about
11884 set i [lsearch -exact $lcnames $e]
11886 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11887 set i [lsearch -exact $lcnames $ex]
11897 set tclenc [lindex $names $i]
11899 set tcl_encoding_cache($enc) $tclenc
11903 proc gitattr {path attr default} {
11904 global path_attr_cache
11905 if {[info exists path_attr_cache($attr,$path)]} {
11906 set r $path_attr_cache($attr,$path)
11908 set r "unspecified"
11909 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11910 regexp "(.*): $attr: (.*)" $line m f r
11912 set path_attr_cache($attr,$path) $r
11914 if {$r eq "unspecified"} {
11920 proc cache_gitattr {attr pathlist} {
11921 global path_attr_cache
11923 foreach path $pathlist {
11924 if {![info exists path_attr_cache($attr,$path)]} {
11925 lappend newlist $path
11929 if {[tk windowingsystem] == "win32"} {
11930 # windows has a 32k limit on the arguments to a command...
11933 while {$newlist ne {}} {
11934 set head [lrange $newlist 0 [expr {$lim - 1}]]
11935 set newlist [lrange $newlist $lim end]
11936 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11937 foreach row [split $rlist "\n"] {
11938 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11939 if {[string index $path 0] eq "\""} {
11940 set path [encoding convertfrom [lindex $path 0]]
11942 set path_attr_cache($attr,$path) $value
11949 proc get_path_encoding {path} {
11950 global gui_encoding perfile_attrs
11951 set tcl_enc $gui_encoding
11952 if {$path ne {} && $perfile_attrs} {
11953 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11961 # First check that Tcl/Tk is recent enough
11962 if {[catch {package require Tk 8.4} err]} {
11963 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11964 Gitk requires at least Tcl/Tk 8.4." list
11968 # on OSX bring the current Wish process window to front
11969 if {[tk windowingsystem] eq "aqua"} {
11970 exec osascript -e [format {
11971 tell application "System Events"
11972 set frontmost of processes whose unix id is %d to true
11977 # Unset GIT_TRACE var if set
11978 if { [info exists ::env(GIT_TRACE)] } {
11979 unset ::env(GIT_TRACE)
11983 set wrcomcmd "git diff-tree --stdin -p --pretty"
11987 set gitencoding [exec git config --get i18n.commitencoding]
11990 set gitencoding [exec git config --get i18n.logoutputencoding]
11992 if {$gitencoding == ""} {
11993 set gitencoding "utf-8"
11995 set tclencoding [tcl_encoding $gitencoding]
11996 if {$tclencoding == {}} {
11997 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
12000 set gui_encoding [encoding system]
12002 set enc [exec git config --get gui.encoding]
12004 set tclenc [tcl_encoding $enc]
12005 if {$tclenc ne {}} {
12006 set gui_encoding $tclenc
12008 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
12013 set log_showroot true
12015 set log_showroot [exec git config --bool --get log.showroot]
12018 if {[tk windowingsystem] eq "aqua"} {
12019 set mainfont {{Lucida Grande} 9}
12020 set textfont {Monaco 9}
12021 set uifont {{Lucida Grande} 9 bold}
12022 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
12024 set mainfont {sans 9}
12025 set textfont {monospace 9}
12026 set uifont {sans 9 bold}
12028 set mainfont {Helvetica 9}
12029 set textfont {Courier 9}
12030 set uifont {Helvetica 9 bold}
12033 set findmergefiles 0
12041 set cmitmode "patch"
12042 set wrapcomment "none"
12047 set showlocalchanges 1
12049 set datetimeformat "%Y-%m-%d %H:%M:%S"
12052 set perfile_attrs 0
12055 if {[tk windowingsystem] eq "aqua"} {
12056 set extdifftool "opendiff"
12058 set extdifftool "meld"
12061 set colors {green red blue magenta darkgrey brown orange}
12062 if {[tk windowingsystem] eq "win32"} {
12063 set uicolor SystemButtonFace
12064 set uifgcolor SystemButtonText
12065 set uifgdisabledcolor SystemDisabledText
12066 set bgcolor SystemWindow
12067 set fgcolor SystemWindowText
12068 set selectbgcolor SystemHighlight
12071 set uifgcolor black
12072 set uifgdisabledcolor "#999"
12075 set selectbgcolor gray85
12077 set diffcolors {red "#00a000" blue}
12079 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12082 set markbgcolor "#e0e0ff"
12084 set headbgcolor green
12085 set headfgcolor black
12086 set headoutlinecolor black
12087 set remotebgcolor #ffddaa
12088 set tagbgcolor yellow
12089 set tagfgcolor black
12090 set tagoutlinecolor black
12091 set reflinecolor black
12092 set filesepbgcolor #aaaaaa
12093 set filesepfgcolor black
12094 set linehoverbgcolor #ffff80
12095 set linehoverfgcolor black
12096 set linehoveroutlinecolor black
12097 set mainheadcirclecolor yellow
12098 set workingfilescirclecolor red
12099 set indexcirclecolor green
12100 set circlecolors {white blue gray blue blue}
12101 set linkfgcolor blue
12102 set circleoutlinecolor $fgcolor
12103 set foundbgcolor yellow
12104 set currentsearchhitbgcolor orange
12106 # button for popping up context menus
12107 if {[tk windowingsystem] eq "aqua"} {
12108 set ctxbut <Button-2>
12110 set ctxbut <Button-3>
12113 ## For msgcat loading, first locate the installation location.
12114 if { [info exists ::env(GITK_MSGSDIR)] } {
12115 ## Msgsdir was manually set in the environment.
12116 set gitk_msgsdir $::env(GITK_MSGSDIR)
12118 ## Let's guess the prefix from argv0.
12119 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12120 set gitk_libdir [file join $gitk_prefix share gitk lib]
12121 set gitk_msgsdir [file join $gitk_libdir msgs]
12125 ## Internationalization (i18n) through msgcat and gettext. See
12126 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12127 package require msgcat
12128 namespace import ::msgcat::mc
12129 ## And eventually load the actual message catalog
12130 ::msgcat::mcload $gitk_msgsdir
12133 # follow the XDG base directory specification by default. See
12134 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12135 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12136 # XDG_CONFIG_HOME environment variable is set
12137 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12138 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12140 # default XDG_CONFIG_HOME
12141 set config_file "~/.config/git/gitk"
12142 set config_file_tmp "~/.config/git/gitk-tmp"
12144 if {![file exists $config_file]} {
12145 # for backward compatibility use the old config file if it exists
12146 if {[file exists "~/.gitk"]} {
12147 set config_file "~/.gitk"
12148 set config_file_tmp "~/.gitk-tmp"
12149 } elseif {![file exists [file dirname $config_file]]} {
12150 file mkdir [file dirname $config_file]
12153 source $config_file
12156 parsefont mainfont $mainfont
12157 eval font create mainfont [fontflags mainfont]
12158 eval font create mainfontbold [fontflags mainfont 1]
12160 parsefont textfont $textfont
12161 eval font create textfont [fontflags textfont]
12162 eval font create textfontbold [fontflags textfont 1]
12164 parsefont uifont $uifont
12165 eval font create uifont [fontflags uifont]
12171 # check that we can find a .git directory somewhere...
12172 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12173 show_error {} . [mc "Cannot find a git repository here."]
12178 set selectheadid {}
12181 set cmdline_files {}
12183 set revtreeargscmd {}
12184 foreach arg $argv {
12185 switch -glob -- $arg {
12188 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12191 "--select-commit=*" {
12192 set selecthead [string range $arg 16 end]
12195 set revtreeargscmd [string range $arg 10 end]
12198 lappend revtreeargs $arg
12204 if {$selecthead eq "HEAD"} {
12208 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12209 # no -- on command line, but some arguments (other than --argscmd)
12211 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12212 set cmdline_files [split $f "\n"]
12213 set n [llength $cmdline_files]
12214 set revtreeargs [lrange $revtreeargs 0 end-$n]
12215 # Unfortunately git rev-parse doesn't produce an error when
12216 # something is both a revision and a filename. To be consistent
12217 # with git log and git rev-list, check revtreeargs for filenames.
12218 foreach arg $revtreeargs {
12219 if {[file exists $arg]} {
12220 show_error {} . [mc "Ambiguous argument '%s': both revision\
12221 and filename" $arg]
12226 # unfortunately we get both stdout and stderr in $err,
12227 # so look for "fatal:".
12228 set i [string first "fatal:" $err]
12230 set err [string range $err [expr {$i + 6}] end]
12232 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12237 set nullid "0000000000000000000000000000000000000000"
12238 set nullid2 "0000000000000000000000000000000000000001"
12239 set nullfile "/dev/null"
12241 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12242 if {![info exists have_ttk]} {
12243 set have_ttk [llength [info commands ::ttk::style]]
12245 set use_ttk [expr {$have_ttk && $want_ttk}]
12246 set NS [expr {$use_ttk ? "ttk" : ""}]
12248 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12251 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12252 set show_notes "--show-notes"
12262 set highlight_paths {}
12264 set searchdirn -forwards
12267 set diffelide {0 0}
12268 set markingmatches 0
12269 set linkentercount 0
12270 set need_redisplay 0
12277 set selectedhlview [mc "None"]
12278 set highlight_related [mc "None"]
12279 set highlight_files {}
12280 set viewfiles(0) {}
12283 set viewargscmd(0) {}
12285 set selectedline {}
12293 set hasworktree [hasworktree]
12295 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12296 set cdup [exec git rev-parse --show-cdup]
12298 set worktree [exec git rev-parse --show-toplevel]
12302 image create photo gitlogo -width 16 -height 16
12304 image create photo gitlogominus -width 4 -height 2
12305 gitlogominus put #C00000 -to 0 0 4 2
12306 gitlogo copy gitlogominus -to 1 5
12307 gitlogo copy gitlogominus -to 6 5
12308 gitlogo copy gitlogominus -to 11 5
12309 image delete gitlogominus
12311 image create photo gitlogoplus -width 4 -height 4
12312 gitlogoplus put #008000 -to 1 0 3 4
12313 gitlogoplus put #008000 -to 0 1 4 3
12314 gitlogo copy gitlogoplus -to 1 9
12315 gitlogo copy gitlogoplus -to 6 9
12316 gitlogo copy gitlogoplus -to 11 9
12317 image delete gitlogoplus
12319 image create photo gitlogo32 -width 32 -height 32
12320 gitlogo32 copy gitlogo -zoom 2 2
12322 wm iconphoto . -default gitlogo gitlogo32
12324 # wait for the window to become visible
12325 tkwait visibility .
12326 wm title . "$appname: [reponame]"
12330 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12331 # create a view for the files/dirs specified on the command line
12335 set viewname(1) [mc "Command line"]
12336 set viewfiles(1) $cmdline_files
12337 set viewargs(1) $revtreeargs
12338 set viewargscmd(1) $revtreeargscmd
12342 .bar.view entryconf [mca "Edit view..."] -state normal
12343 .bar.view entryconf [mca "Delete view"] -state normal
12346 if {[info exists permviews]} {
12347 foreach v $permviews {
12350 set viewname($n) [lindex $v 0]
12351 set viewfiles($n) [lindex $v 1]
12352 set viewargs($n) [lindex $v 2]
12353 set viewargscmd($n) [lindex $v 3]
12359 if {[tk windowingsystem] eq "win32"} {
12367 # indent-tabs-mode: t