2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2016 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 if {[catch
{set _gitworktree
[exec git config
--get core.worktree
]}]} {
38 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
45 # A simple scheduler for compute-intensive stuff.
46 # The aim is to make sure that event handlers for GUI actions can
47 # run at least every 50-100 ms. Unfortunately fileevent handlers are
48 # run before X event handlers, so reading from a fast source can
49 # make the GUI completely unresponsive.
51 global isonrunq runq currunq
54 if {[info exists isonrunq
($script)]} return
55 if {$runq eq
{} && ![info exists currunq
]} {
58 lappend runq
[list
{} $script]
59 set isonrunq
($script) 1
62 proc filerun
{fd
script} {
63 fileevent
$fd readable
[list filereadable
$fd $script]
66 proc filereadable
{fd
script} {
69 fileevent
$fd readable
{}
70 if {$runq eq
{} && ![info exists currunq
]} {
73 lappend runq
[list
$fd $script]
79 for {set i
0} {$i < [llength
$runq]} {} {
80 if {[lindex
$runq $i 0] eq
$fd} {
81 set runq
[lreplace
$runq $i $i]
89 global isonrunq runq currunq
91 set tstart
[clock clicks
-milliseconds]
93 while {[llength
$runq] > 0} {
94 set fd
[lindex
$runq 0 0]
95 set script [lindex
$runq 0 1]
96 set currunq
[lindex
$runq 0]
97 set runq
[lrange
$runq 1 end
]
98 set repeat
[eval $script]
100 set t1
[clock clicks
-milliseconds]
101 set t
[expr {$t1 - $t0}]
102 if {$repeat ne
{} && $repeat} {
103 if {$fd eq
{} ||
$repeat == 2} {
104 # script returns 1 if it wants to be readded
105 # file readers return 2 if they could do more straight away
106 lappend runq
[list
$fd $script]
108 fileevent
$fd readable
[list filereadable
$fd $script]
110 } elseif
{$fd eq
{}} {
111 unset isonrunq
($script)
114 if {$t1 - $tstart >= 80} break
121 proc reg_instance
{fd
} {
122 global commfd leftover loginstance
124 set i
[incr loginstance
]
130 proc unmerged_files
{files
} {
133 # find the list of unmerged files
137 set fd
[open
"| git ls-files -u" r
]
139 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
142 while {[gets $fd line] >= 0} {
143 set i [string first "\t" $line]
145 set fname [string range $line [expr {$i+1}] end]
146 if {[lsearch -exact $mlist $fname] >= 0} continue
148 if {$files eq {} || [path_filter $files $fname]} {
156 proc parseviewargs {n arglist} {
157 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
159 global worddiff git_version
163 set vinlinediff($n) 0
168 set origargs $arglist
172 foreach arg $arglist {
179 switch -glob -- $arg {
183 # remove from origargs in case we hit an unknown option
184 set origargs [lreplace $origargs $i $i]
188 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
189 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
190 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
191 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
192 "--ignore-space-change" - "-U*" - "--unified=*" {
193 # These request or affect diff output, which we don't want.
194 # Some could be used to set our defaults for diff display.
195 lappend diffargs
$arg
197 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
198 "--name-only" - "--name-status" - "--color" -
199 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
200 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
201 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
202 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
203 "--objects" - "--objects-edge" - "--reverse" {
204 # These cause our parsing of git log's output to fail, or else
205 # they're options we want to set ourselves, so ignore them.
207 "--color-words*" - "--word-diff=color" {
208 # These trigger a word diff in the console interface,
209 # so help the user by enabling our own support
210 if {[package vcompare
$git_version "1.7.2"] >= 0} {
211 set worddiff
[mc
"Color words"]
215 if {[package vcompare
$git_version "1.7.2"] >= 0} {
216 set worddiff
[mc
"Markup words"]
219 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
220 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
221 "--full-history" - "--dense" - "--sparse" -
222 "--follow" - "--left-right" - "--encoding=*" {
223 # These are harmless, and some are even useful
226 "--diff-filter=*" - "--no-merges" - "--unpacked" -
227 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
228 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
229 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
230 "--remove-empty" - "--first-parent" - "--cherry-pick" -
231 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
232 "--simplify-by-decoration" {
233 # These mean that we get a subset of the commits
238 # Line-log with 'stuck' argument (unstuck form is
241 set vinlinediff
($n) 1
246 # This appears to be the only one that has a value as a
247 # separate word following it
257 # git rev-parse doesn't understand --merge
258 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
260 "--no-replace-objects" {
261 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
264 # Other flag arguments including -<n>
265 if {[string is digit
-strict [string range
$arg 1 end
]]} {
268 # a flag argument that we don't recognize;
269 # that means we can't optimize
275 # Non-flag arguments specify commits or ranges of commits
276 if {[string match
"*...*" $arg]} {
277 lappend revargs
--gitk-symmetric-diff-marker
283 set vdflags
($n) $diffargs
284 set vflags
($n) $glflags
285 set vrevs
($n) $revargs
286 set vfiltered
($n) $filtered
287 set vorigargs
($n) $origargs
291 proc parseviewrevs
{view revs
} {
292 global vposids vnegids
296 } elseif
{[lsearch
-exact $revs --all] >= 0} {
299 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
300 # we get stdout followed by stderr in $err
301 # for an unknown rev, git rev-parse echoes it and then errors out
302 set errlines
[split $err "\n"]
304 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
305 set line
[lindex
$errlines $l]
306 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
307 if {[string match
"fatal:*" $line]} {
308 if {[string match
"fatal: ambiguous argument*" $line]
310 if {[llength
$badrev] == 1} {
311 set err
"unknown revision $badrev"
313 set err
"unknown revisions: [join $badrev ", "]"
316 set err
[join [lrange
$errlines $l end
] "\n"]
323 error_popup
"[mc "Error parsing revisions
:"] $err"
330 foreach id
[split $ids "\n"] {
331 if {$id eq
"--gitk-symmetric-diff-marker"} {
333 } elseif
{[string match
"^*" $id]} {
340 lappend neg
[string range
$id 1 end
]
345 lset ret end
$id...
[lindex
$ret end
]
351 set vposids
($view) $pos
352 set vnegids
($view) $neg
356 # Start off a git log process and arrange to read its output
357 proc start_rev_list
{view
} {
358 global startmsecs commitidx viewcomplete curview
360 global viewargs viewargscmd viewfiles vfilelimit
361 global showlocalchanges
362 global viewactive viewinstances vmergeonly
363 global mainheadid viewmainheadid viewmainheadid_orig
364 global vcanopt vflags vrevs vorigargs
367 set startmsecs
[clock clicks
-milliseconds]
368 set commitidx
($view) 0
369 # these are set this way for the error exits
370 set viewcomplete
($view) 1
371 set viewactive
($view) 0
374 set args
$viewargs($view)
375 if {$viewargscmd($view) ne
{}} {
377 set str
[exec sh
-c $viewargscmd($view)]
379 error_popup
"[mc "Error executing
--argscmd command:"] $err"
382 set args
[concat
$args [split $str "\n"]]
384 set vcanopt
($view) [parseviewargs
$view $args]
386 set files
$viewfiles($view)
387 if {$vmergeonly($view)} {
388 set files
[unmerged_files
$files]
391 if {$nr_unmerged == 0} {
392 error_popup
[mc
"No files selected: --merge specified but\
393 no files are unmerged."]
395 error_popup
[mc
"No files selected: --merge specified but\
396 no unmerged files are within file limit."]
401 set vfilelimit
($view) $files
403 if {$vcanopt($view)} {
404 set revs
[parseviewrevs
$view $vrevs($view)]
408 set args
[concat
$vflags($view) $revs]
410 set args
$vorigargs($view)
414 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
415 --parents --boundary $args "--" $files] r
]
417 error_popup
"[mc "Error executing git log
:"] $err"
420 set i
[reg_instance
$fd]
421 set viewinstances
($view) [list
$i]
422 set viewmainheadid
($view) $mainheadid
423 set viewmainheadid_orig
($view) $mainheadid
424 if {$files ne
{} && $mainheadid ne
{}} {
425 get_viewmainhead
$view
427 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
428 interestedin
$viewmainheadid($view) dodiffindex
430 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
431 if {$tclencoding != {}} {
432 fconfigure
$fd -encoding $tclencoding
434 filerun
$fd [list getcommitlines
$fd $i $view 0]
435 nowbusy
$view [mc
"Reading"]
436 set viewcomplete
($view) 0
437 set viewactive
($view) 1
441 proc stop_instance
{inst
} {
442 global commfd leftover
444 set fd
$commfd($inst)
448 if {$
::tcl_platform
(platform
) eq
{windows
}} {
449 exec taskkill
/pid
$pid
457 unset leftover
($inst)
460 proc stop_backends
{} {
463 foreach inst
[array names commfd
] {
468 proc stop_rev_list
{view
} {
471 foreach inst
$viewinstances($view) {
474 set viewinstances
($view) {}
477 proc reset_pending_select
{selid
} {
478 global pending_select mainheadid selectheadid
481 set pending_select
$selid
482 } elseif
{$selectheadid ne
{}} {
483 set pending_select
$selectheadid
485 set pending_select
$mainheadid
489 proc getcommits
{selid
} {
490 global canv curview need_redisplay viewactive
493 if {[start_rev_list
$curview]} {
494 reset_pending_select
$selid
495 show_status
[mc
"Reading commits..."]
498 show_status
[mc
"No commits selected"]
502 proc updatecommits
{} {
503 global curview vcanopt vorigargs vfilelimit viewinstances
504 global viewactive viewcomplete tclencoding
505 global startmsecs showneartags showlocalchanges
506 global mainheadid viewmainheadid viewmainheadid_orig pending_select
508 global varcid vposids vnegids vflags vrevs
511 set hasworktree
[hasworktree
]
514 if {$mainheadid ne
$viewmainheadid_orig($view)} {
515 if {$showlocalchanges} {
518 set viewmainheadid
($view) $mainheadid
519 set viewmainheadid_orig
($view) $mainheadid
520 if {$vfilelimit($view) ne
{}} {
521 get_viewmainhead
$view
524 if {$showlocalchanges} {
527 if {$vcanopt($view)} {
528 set oldpos
$vposids($view)
529 set oldneg
$vnegids($view)
530 set revs
[parseviewrevs
$view $vrevs($view)]
534 # note: getting the delta when negative refs change is hard,
535 # and could require multiple git log invocations, so in that
536 # case we ask git log for all the commits (not just the delta)
537 if {$oldneg eq
$vnegids($view)} {
540 # take out positive refs that we asked for before or
541 # that we have already seen
543 if {[string length
$rev] == 40} {
544 if {[lsearch
-exact $oldpos $rev] < 0
545 && ![info exists varcid
($view,$rev)]} {
550 lappend
$newrevs $rev
553 if {$npos == 0} return
555 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
557 set args
[concat
$vflags($view) $revs --not $oldpos]
559 set args
$vorigargs($view)
562 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
563 --parents --boundary $args "--" $vfilelimit($view)] r
]
565 error_popup
"[mc "Error executing git log
:"] $err"
568 if {$viewactive($view) == 0} {
569 set startmsecs
[clock clicks
-milliseconds]
571 set i
[reg_instance
$fd]
572 lappend viewinstances
($view) $i
573 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
574 if {$tclencoding != {}} {
575 fconfigure
$fd -encoding $tclencoding
577 filerun
$fd [list getcommitlines
$fd $i $view 1]
578 incr viewactive
($view)
579 set viewcomplete
($view) 0
580 reset_pending_select
{}
581 nowbusy
$view [mc
"Reading"]
587 proc reloadcommits
{} {
588 global curview viewcomplete selectedline currentid thickerline
589 global showneartags treediffs commitinterest cached_commitrow
590 global targetid commitinfo
593 if {$selectedline ne
{}} {
597 if {!$viewcomplete($curview)} {
598 stop_rev_list
$curview
602 unset -nocomplain currentid
603 unset -nocomplain thickerline
604 unset -nocomplain treediffs
611 unset -nocomplain commitinfo
612 unset -nocomplain commitinterest
613 unset -nocomplain cached_commitrow
614 unset -nocomplain targetid
620 # This makes a string representation of a positive integer which
621 # sorts as a string in numerical order
624 return [format
"%x" $n]
625 } elseif
{$n < 256} {
626 return [format
"x%.2x" $n]
627 } elseif
{$n < 65536} {
628 return [format
"y%.4x" $n]
630 return [format
"z%.8x" $n]
633 # Procedures used in reordering commits from git log (without
634 # --topo-order) into the order for display.
636 proc varcinit
{view
} {
637 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
638 global vtokmod varcmod vrowmod varcix vlastins
640 set varcstart
($view) {{}}
641 set vupptr
($view) {0}
642 set vdownptr
($view) {0}
643 set vleftptr
($view) {0}
644 set vbackptr
($view) {0}
645 set varctok
($view) {{}}
646 set varcrow
($view) {{}}
647 set vtokmod
($view) {}
650 set varcix
($view) {{}}
651 set vlastins
($view) {0}
654 proc resetvarcs
{view
} {
655 global varcid varccommits parents children vseedcount ordertok
658 foreach vid
[array names varcid
$view,*] {
663 foreach vid
[array names vshortids
$view,*] {
664 unset vshortids
($vid)
666 # some commits might have children but haven't been seen yet
667 foreach vid
[array names children
$view,*] {
670 foreach va
[array names varccommits
$view,*] {
671 unset varccommits
($va)
673 foreach vd
[array names vseedcount
$view,*] {
674 unset vseedcount
($vd)
676 unset -nocomplain ordertok
679 # returns a list of the commits with no children
681 global vdownptr vleftptr varcstart
684 set a
[lindex
$vdownptr($v) 0]
686 lappend ret
[lindex
$varcstart($v) $a]
687 set a
[lindex
$vleftptr($v) $a]
692 proc newvarc
{view id
} {
693 global varcid varctok parents children vdatemode
694 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
695 global commitdata commitinfo vseedcount varccommits vlastins
697 set a
[llength
$varctok($view)]
699 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
700 if {![info exists commitinfo
($id)]} {
701 parsecommit
$id $commitdata($id) 1
703 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
704 if {![string is integer
-strict $cdate]} {
707 if {![info exists vseedcount
($view,$cdate)]} {
708 set vseedcount
($view,$cdate) -1
710 set c
[incr vseedcount
($view,$cdate)]
711 set cdate
[expr {$cdate ^
0xffffffff}]
712 set tok
"s[strrep $cdate][strrep $c]"
717 if {[llength
$children($vid)] > 0} {
718 set kid
[lindex
$children($vid) end
]
719 set k
$varcid($view,$kid)
720 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
723 set tok
[lindex
$varctok($view) $k]
727 set i
[lsearch
-exact $parents($view,$ki) $id]
728 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
729 append tok
[strrep
$j]
731 set c
[lindex
$vlastins($view) $ka]
732 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
734 set b
[lindex
$vdownptr($view) $ka]
736 set b
[lindex
$vleftptr($view) $c]
738 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
740 set b
[lindex
$vleftptr($view) $c]
743 lset vdownptr
($view) $ka $a
744 lappend vbackptr
($view) 0
746 lset vleftptr
($view) $c $a
747 lappend vbackptr
($view) $c
749 lset vlastins
($view) $ka $a
750 lappend vupptr
($view) $ka
751 lappend vleftptr
($view) $b
753 lset vbackptr
($view) $b $a
755 lappend varctok
($view) $tok
756 lappend varcstart
($view) $id
757 lappend vdownptr
($view) 0
758 lappend varcrow
($view) {}
759 lappend varcix
($view) {}
760 set varccommits
($view,$a) {}
761 lappend vlastins
($view) 0
765 proc splitvarc
{p v
} {
766 global varcid varcstart varccommits varctok vtokmod
767 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
769 set oa
$varcid($v,$p)
770 set otok
[lindex
$varctok($v) $oa]
771 set ac
$varccommits($v,$oa)
772 set i
[lsearch
-exact $varccommits($v,$oa) $p]
774 set na
[llength
$varctok($v)]
775 # "%" sorts before "0"...
776 set tok
"$otok%[strrep $i]"
777 lappend varctok
($v) $tok
778 lappend varcrow
($v) {}
779 lappend varcix
($v) {}
780 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
781 set varccommits
($v,$na) [lrange
$ac $i end
]
782 lappend varcstart
($v) $p
783 foreach id
$varccommits($v,$na) {
784 set varcid
($v,$id) $na
786 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
787 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
788 lset vdownptr
($v) $oa $na
789 lset vlastins
($v) $oa 0
790 lappend vupptr
($v) $oa
791 lappend vleftptr
($v) 0
792 lappend vbackptr
($v) 0
793 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
794 lset vupptr
($v) $b $na
796 if {[string compare
$otok $vtokmod($v)] <= 0} {
801 proc renumbervarc
{a v
} {
802 global parents children varctok varcstart varccommits
803 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
805 set t1
[clock clicks
-milliseconds]
811 if {[info exists isrelated
($a)]} {
813 set id
[lindex
$varccommits($v,$a) end
]
814 foreach p
$parents($v,$id) {
815 if {[info exists varcid
($v,$p)]} {
816 set isrelated
($varcid($v,$p)) 1
821 set b
[lindex
$vdownptr($v) $a]
824 set b
[lindex
$vleftptr($v) $a]
826 set a
[lindex
$vupptr($v) $a]
832 if {![info exists kidchanged
($a)]} continue
833 set id
[lindex
$varcstart($v) $a]
834 if {[llength
$children($v,$id)] > 1} {
835 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
838 set oldtok
[lindex
$varctok($v) $a]
839 if {!$vdatemode($v)} {
845 set kid
[last_real_child
$v,$id]
847 set k
$varcid($v,$kid)
848 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
851 set tok
[lindex
$varctok($v) $k]
855 set i
[lsearch
-exact $parents($v,$ki) $id]
856 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
857 append tok
[strrep
$j]
859 if {$tok eq
$oldtok} {
862 set id
[lindex
$varccommits($v,$a) end
]
863 foreach p
$parents($v,$id) {
864 if {[info exists varcid
($v,$p)]} {
865 set kidchanged
($varcid($v,$p)) 1
870 lset varctok
($v) $a $tok
871 set b
[lindex
$vupptr($v) $a]
873 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
876 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
879 set c
[lindex
$vbackptr($v) $a]
880 set d
[lindex
$vleftptr($v) $a]
882 lset vdownptr
($v) $b $d
884 lset vleftptr
($v) $c $d
887 lset vbackptr
($v) $d $c
889 if {[lindex
$vlastins($v) $b] == $a} {
890 lset vlastins
($v) $b $c
892 lset vupptr
($v) $a $ka
893 set c
[lindex
$vlastins($v) $ka]
895 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
897 set b
[lindex
$vdownptr($v) $ka]
899 set b
[lindex
$vleftptr($v) $c]
902 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
904 set b
[lindex
$vleftptr($v) $c]
907 lset vdownptr
($v) $ka $a
908 lset vbackptr
($v) $a 0
910 lset vleftptr
($v) $c $a
911 lset vbackptr
($v) $a $c
913 lset vleftptr
($v) $a $b
915 lset vbackptr
($v) $b $a
917 lset vlastins
($v) $ka $a
920 foreach id
[array names sortkids
] {
921 if {[llength
$children($v,$id)] > 1} {
922 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
926 set t2
[clock clicks
-milliseconds]
927 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
930 # Fix up the graph after we have found out that in view $v,
931 # $p (a commit that we have already seen) is actually the parent
932 # of the last commit in arc $a.
933 proc fix_reversal
{p a v
} {
934 global varcid varcstart varctok vupptr
936 set pa
$varcid($v,$p)
937 if {$p ne
[lindex
$varcstart($v) $pa]} {
939 set pa
$varcid($v,$p)
941 # seeds always need to be renumbered
942 if {[lindex
$vupptr($v) $pa] == 0 ||
943 [string compare
[lindex
$varctok($v) $a] \
944 [lindex
$varctok($v) $pa]] > 0} {
949 proc insertrow
{id p v
} {
950 global cmitlisted children parents varcid varctok vtokmod
951 global varccommits ordertok commitidx numcommits curview
952 global targetid targetrow vshortids
956 set cmitlisted
($vid) 1
957 set children
($vid) {}
958 set parents
($vid) [list
$p]
959 set a
[newvarc
$v $id]
961 lappend vshortids
($v,[string range
$id 0 3]) $id
962 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
965 lappend varccommits
($v,$a) $id
967 if {[llength
[lappend children
($vp) $id]] > 1} {
968 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
969 unset -nocomplain ordertok
971 fix_reversal
$p $a $v
973 if {$v == $curview} {
974 set numcommits
$commitidx($v)
976 if {[info exists targetid
]} {
977 if {![comes_before
$targetid $p]} {
984 proc insertfakerow
{id p
} {
985 global varcid varccommits parents children cmitlisted
986 global commitidx varctok vtokmod targetid targetrow curview numcommits
990 set i
[lsearch
-exact $varccommits($v,$a) $p]
992 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
995 set children
($v,$id) {}
996 set parents
($v,$id) [list
$p]
997 set varcid
($v,$id) $a
998 lappend children
($v,$p) $id
999 set cmitlisted
($v,$id) 1
1000 set numcommits
[incr commitidx
($v)]
1001 # note we deliberately don't update varcstart($v) even if $i == 0
1002 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
1004 if {[info exists targetid
]} {
1005 if {![comes_before
$targetid $p]} {
1013 proc removefakerow
{id
} {
1014 global varcid varccommits parents children commitidx
1015 global varctok vtokmod cmitlisted currentid selectedline
1016 global targetid curview numcommits
1019 if {[llength
$parents($v,$id)] != 1} {
1020 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1023 set p
[lindex
$parents($v,$id) 0]
1024 set a
$varcid($v,$id)
1025 set i
[lsearch
-exact $varccommits($v,$a) $id]
1027 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1030 unset varcid
($v,$id)
1031 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1032 unset parents
($v,$id)
1033 unset children
($v,$id)
1034 unset cmitlisted
($v,$id)
1035 set numcommits
[incr commitidx
($v) -1]
1036 set j
[lsearch
-exact $children($v,$p) $id]
1038 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1041 if {[info exist currentid
] && $id eq
$currentid} {
1045 if {[info exists targetid
] && $targetid eq
$id} {
1052 proc real_children
{vp
} {
1053 global children nullid nullid2
1056 foreach id
$children($vp) {
1057 if {$id ne
$nullid && $id ne
$nullid2} {
1064 proc first_real_child
{vp
} {
1065 global children nullid nullid2
1067 foreach id
$children($vp) {
1068 if {$id ne
$nullid && $id ne
$nullid2} {
1075 proc last_real_child
{vp
} {
1076 global children nullid nullid2
1078 set kids
$children($vp)
1079 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1080 set id
[lindex
$kids $i]
1081 if {$id ne
$nullid && $id ne
$nullid2} {
1088 proc vtokcmp
{v a b
} {
1089 global varctok varcid
1091 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1092 [lindex
$varctok($v) $varcid($v,$b)]]
1095 # This assumes that if lim is not given, the caller has checked that
1096 # arc a's token is less than $vtokmod($v)
1097 proc modify_arc
{v a
{lim
{}}} {
1098 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1101 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1104 set r
[lindex
$varcrow($v) $a]
1105 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1108 set vtokmod
($v) [lindex
$varctok($v) $a]
1110 if {$v == $curview} {
1111 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1112 set a
[lindex
$vupptr($v) $a]
1118 set lim
[llength
$varccommits($v,$a)]
1120 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1127 proc update_arcrows
{v
} {
1128 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1129 global varcid vrownum varcorder varcix varccommits
1130 global vupptr vdownptr vleftptr varctok
1131 global displayorder parentlist curview cached_commitrow
1133 if {$vrowmod($v) == $commitidx($v)} return
1134 if {$v == $curview} {
1135 if {[llength
$displayorder] > $vrowmod($v)} {
1136 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1137 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1139 unset -nocomplain cached_commitrow
1141 set narctot
[expr {[llength
$varctok($v)] - 1}]
1143 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1144 # go up the tree until we find something that has a row number,
1145 # or we get to a seed
1146 set a
[lindex
$vupptr($v) $a]
1149 set a
[lindex
$vdownptr($v) 0]
1152 set varcorder
($v) [list
$a]
1153 lset varcix
($v) $a 0
1154 lset varcrow
($v) $a 0
1158 set arcn
[lindex
$varcix($v) $a]
1159 if {[llength
$vrownum($v)] > $arcn + 1} {
1160 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1161 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1163 set row
[lindex
$varcrow($v) $a]
1167 incr row
[llength
$varccommits($v,$a)]
1168 # go down if possible
1169 set b
[lindex
$vdownptr($v) $a]
1171 # if not, go left, or go up until we can go left
1173 set b
[lindex
$vleftptr($v) $a]
1175 set a
[lindex
$vupptr($v) $a]
1181 lappend vrownum
($v) $row
1182 lappend varcorder
($v) $a
1183 lset varcix
($v) $a $arcn
1184 lset varcrow
($v) $a $row
1186 set vtokmod
($v) [lindex
$varctok($v) $p]
1188 set vrowmod
($v) $row
1189 if {[info exists currentid
]} {
1190 set selectedline
[rowofcommit
$currentid]
1194 # Test whether view $v contains commit $id
1195 proc commitinview
{id v
} {
1198 return [info exists varcid
($v,$id)]
1201 # Return the row number for commit $id in the current view
1202 proc rowofcommit
{id
} {
1203 global varcid varccommits varcrow curview cached_commitrow
1204 global varctok vtokmod
1207 if {![info exists varcid
($v,$id)]} {
1208 puts
"oops rowofcommit no arc for [shortids $id]"
1211 set a
$varcid($v,$id)
1212 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1215 if {[info exists cached_commitrow
($id)]} {
1216 return $cached_commitrow($id)
1218 set i
[lsearch
-exact $varccommits($v,$a) $id]
1220 puts
"oops didn't find commit [shortids $id] in arc $a"
1223 incr i
[lindex
$varcrow($v) $a]
1224 set cached_commitrow
($id) $i
1228 # Returns 1 if a is on an earlier row than b, otherwise 0
1229 proc comes_before
{a b
} {
1230 global varcid varctok curview
1233 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1234 ![info exists varcid
($v,$b)]} {
1237 if {$varcid($v,$a) != $varcid($v,$b)} {
1238 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1239 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1241 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1244 proc bsearch
{l elt
} {
1245 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1250 while {$hi - $lo > 1} {
1251 set mid
[expr {int
(($lo + $hi) / 2)}]
1252 set t
[lindex
$l $mid]
1255 } elseif
{$elt > $t} {
1264 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1265 proc make_disporder
{start end
} {
1266 global vrownum curview commitidx displayorder parentlist
1267 global varccommits varcorder parents vrowmod varcrow
1268 global d_valid_start d_valid_end
1270 if {$end > $vrowmod($curview)} {
1271 update_arcrows
$curview
1273 set ai
[bsearch
$vrownum($curview) $start]
1274 set start
[lindex
$vrownum($curview) $ai]
1275 set narc
[llength
$vrownum($curview)]
1276 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1277 set a
[lindex
$varcorder($curview) $ai]
1278 set l
[llength
$displayorder]
1279 set al
[llength
$varccommits($curview,$a)]
1280 if {$l < $r + $al} {
1282 set pad
[ntimes
[expr {$r - $l}] {}]
1283 set displayorder
[concat
$displayorder $pad]
1284 set parentlist
[concat
$parentlist $pad]
1285 } elseif
{$l > $r} {
1286 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1287 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1289 foreach id
$varccommits($curview,$a) {
1290 lappend displayorder
$id
1291 lappend parentlist
$parents($curview,$id)
1293 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1295 foreach id
$varccommits($curview,$a) {
1296 lset displayorder
$i $id
1297 lset parentlist
$i $parents($curview,$id)
1305 proc commitonrow
{row
} {
1308 set id
[lindex
$displayorder $row]
1310 make_disporder
$row [expr {$row + 1}]
1311 set id
[lindex
$displayorder $row]
1316 proc closevarcs
{v
} {
1317 global varctok varccommits varcid parents children
1318 global cmitlisted commitidx vtokmod curview numcommits
1320 set missing_parents
0
1322 set narcs
[llength
$varctok($v)]
1323 for {set a
1} {$a < $narcs} {incr a
} {
1324 set id
[lindex
$varccommits($v,$a) end
]
1325 foreach p
$parents($v,$id) {
1326 if {[info exists varcid
($v,$p)]} continue
1327 # add p as a new commit
1328 incr missing_parents
1329 set cmitlisted
($v,$p) 0
1330 set parents
($v,$p) {}
1331 if {[llength
$children($v,$p)] == 1 &&
1332 [llength
$parents($v,$id)] == 1} {
1335 set b
[newvarc
$v $p]
1337 set varcid
($v,$p) $b
1338 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1341 lappend varccommits
($v,$b) $p
1343 if {$v == $curview} {
1344 set numcommits
$commitidx($v)
1346 set scripts
[check_interest
$p $scripts]
1349 if {$missing_parents > 0} {
1350 foreach s
$scripts {
1356 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1357 # Assumes we already have an arc for $rwid.
1358 proc rewrite_commit
{v id rwid
} {
1359 global children parents varcid varctok vtokmod varccommits
1361 foreach ch
$children($v,$id) {
1362 # make $rwid be $ch's parent in place of $id
1363 set i
[lsearch
-exact $parents($v,$ch) $id]
1365 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1367 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1368 # add $ch to $rwid's children and sort the list if necessary
1369 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1370 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1371 $children($v,$rwid)]
1373 # fix the graph after joining $id to $rwid
1374 set a
$varcid($v,$ch)
1375 fix_reversal
$rwid $a $v
1376 # parentlist is wrong for the last element of arc $a
1377 # even if displayorder is right, hence the 3rd arg here
1378 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1382 # Mechanism for registering a command to be executed when we come
1383 # across a particular commit. To handle the case when only the
1384 # prefix of the commit is known, the commitinterest array is now
1385 # indexed by the first 4 characters of the ID. Each element is a
1386 # list of id, cmd pairs.
1387 proc interestedin
{id cmd
} {
1388 global commitinterest
1390 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1393 proc check_interest
{id scripts
} {
1394 global commitinterest
1396 set prefix
[string range
$id 0 3]
1397 if {[info exists commitinterest
($prefix)]} {
1399 foreach
{i
script} $commitinterest($prefix) {
1400 if {[string match
"$i*" $id]} {
1401 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1403 lappend newlist
$i $script
1406 if {$newlist ne
{}} {
1407 set commitinterest
($prefix) $newlist
1409 unset commitinterest
($prefix)
1415 proc getcommitlines
{fd inst view updating
} {
1416 global cmitlisted leftover
1417 global commitidx commitdata vdatemode
1418 global parents children curview hlview
1419 global idpending ordertok
1420 global varccommits varcid varctok vtokmod vfilelimit vshortids
1422 set stuff
[read $fd 500000]
1423 # git log doesn't terminate the last commit with a null...
1424 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1431 global commfd viewcomplete viewactive viewname
1432 global viewinstances
1434 set i
[lsearch
-exact $viewinstances($view) $inst]
1436 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1438 # set it blocking so we wait for the process to terminate
1439 fconfigure
$fd -blocking 1
1440 if {[catch
{close
$fd} err
]} {
1442 if {$view != $curview} {
1443 set fv
" for the \"$viewname($view)\" view"
1445 if {[string range
$err 0 4] == "usage"} {
1446 set err
"Gitk: error reading commits$fv:\
1447 bad arguments to git log."
1448 if {$viewname($view) eq
[mc
"Command line"]} {
1450 " (Note: arguments to gitk are passed to git log\
1451 to allow selection of commits to be displayed.)"
1454 set err
"Error reading commits$fv: $err"
1458 if {[incr viewactive
($view) -1] <= 0} {
1459 set viewcomplete
($view) 1
1460 # Check if we have seen any ids listed as parents that haven't
1461 # appeared in the list
1465 if {$view == $curview} {
1474 set i
[string first
"\0" $stuff $start]
1476 append leftover
($inst) [string range
$stuff $start end
]
1480 set cmit
$leftover($inst)
1481 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1482 set leftover
($inst) {}
1484 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1486 set start
[expr {$i + 1}]
1487 set j
[string first
"\n" $cmit]
1490 if {$j >= 0 && [string match
"commit *" $cmit]} {
1491 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1492 if {[string match
{[-^
<>]*} $ids]} {
1493 switch
-- [string index
$ids 0] {
1499 set ids
[string range
$ids 1 end
]
1503 if {[string length
$id] != 40} {
1511 if {[string length
$shortcmit] > 80} {
1512 set shortcmit
"[string range $shortcmit 0 80]..."
1514 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1517 set id [lindex $ids 0]
1520 lappend vshortids($view,[string range $id 0 3]) $id
1522 if {!$listed && $updating && ![info exists varcid($vid)] &&
1523 $vfilelimit($view) ne {}} {
1524 # git log doesn't rewrite parents
for unlisted commits
1525 # when doing path limiting, so work around that here
1526 # by working out the rewritten parent with git rev-list
1527 # and if we already know about it, using the rewritten
1528 # parent as a substitute parent for $id's children.
1530 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1531 $id -- $vfilelimit($view)]
1533 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1534 # use $rwid in place of $id
1535 rewrite_commit
$view $id $rwid
1542 if {[info exists varcid
($vid)]} {
1543 if {$cmitlisted($vid) ||
!$listed} continue
1547 set olds
[lrange
$ids 1 end
]
1551 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1552 set cmitlisted
($vid) $listed
1553 set parents
($vid) $olds
1554 if {![info exists children
($vid)]} {
1555 set children
($vid) {}
1556 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1557 set k
[lindex
$children($vid) 0]
1558 if {[llength
$parents($view,$k)] == 1 &&
1559 (!$vdatemode($view) ||
1560 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1561 set a
$varcid($view,$k)
1566 set a
[newvarc
$view $id]
1568 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1571 if {![info exists varcid
($vid)]} {
1573 lappend varccommits
($view,$a) $id
1574 incr commitidx
($view)
1579 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1581 if {[llength
[lappend children
($vp) $id]] > 1 &&
1582 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1583 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1585 unset -nocomplain ordertok
1587 if {[info exists varcid
($view,$p)]} {
1588 fix_reversal
$p $a $view
1594 set scripts
[check_interest
$id $scripts]
1598 global numcommits hlview
1600 if {$view == $curview} {
1601 set numcommits
$commitidx($view)
1604 if {[info exists hlview
] && $view == $hlview} {
1605 # we never actually get here...
1608 foreach s
$scripts {
1615 proc chewcommits
{} {
1616 global curview hlview viewcomplete
1617 global pending_select
1620 if {$viewcomplete($curview)} {
1621 global commitidx varctok
1622 global numcommits startmsecs
1624 if {[info exists pending_select
]} {
1626 reset_pending_select
{}
1628 if {[commitinview
$pending_select $curview]} {
1629 selectline
[rowofcommit
$pending_select] 1
1631 set row
[first_real_row
]
1635 if {$commitidx($curview) > 0} {
1636 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1637 #puts "overall $ms ms for $numcommits commits"
1638 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1640 show_status
[mc
"No commits selected"]
1647 proc do_readcommit
{id
} {
1650 # Invoke git-log to handle automatic encoding conversion
1651 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1652 # Read the results using i18n.logoutputencoding
1653 fconfigure
$fd -translation lf
-eofchar {}
1654 if {$tclencoding != {}} {
1655 fconfigure
$fd -encoding $tclencoding
1657 set contents
[read $fd]
1659 # Remove the heading line
1660 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1665 proc readcommit
{id
} {
1666 if {[catch
{set contents
[do_readcommit
$id]}]} return
1667 parsecommit
$id $contents 1
1670 proc parsecommit
{id contents listed
} {
1680 set hdrend
[string first
"\n\n" $contents]
1682 # should never happen...
1683 set hdrend
[string length
$contents]
1685 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1686 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1687 foreach line
[split $header "\n"] {
1688 set line
[split $line " "]
1689 set tag
[lindex
$line 0]
1690 if {$tag == "author"} {
1691 set audate
[lrange
$line end-1 end
]
1692 set auname
[join [lrange
$line 1 end-2
] " "]
1693 } elseif
{$tag == "committer"} {
1694 set comdate
[lrange
$line end-1 end
]
1695 set comname
[join [lrange
$line 1 end-2
] " "]
1699 # take the first non-blank line of the comment as the headline
1700 set headline
[string trimleft
$comment]
1701 set i
[string first
"\n" $headline]
1703 set headline
[string range
$headline 0 $i]
1705 set headline
[string trimright
$headline]
1706 set i
[string first
"\r" $headline]
1708 set headline
[string trimright
[string range
$headline 0 $i]]
1711 # git log indents the comment by 4 spaces;
1712 # if we got this via git cat-file, add the indentation
1714 foreach line
[split $comment "\n"] {
1715 append newcomment
" "
1716 append newcomment
$line
1717 append newcomment
"\n"
1719 set comment
$newcomment
1721 set hasnote
[string first
"\nNotes:\n" $contents]
1723 # If there is diff output shown in the git-log stream, split it
1724 # out. But get rid of the empty line that always precedes the
1726 set i
[string first
"\n\ndiff" $comment]
1728 set diff [string range
$comment $i+1 end
]
1729 set comment
[string range
$comment 0 $i-1]
1731 set commitinfo
($id) [list
$headline $auname $audate \
1732 $comname $comdate $comment $hasnote $diff]
1735 proc getcommit
{id
} {
1736 global commitdata commitinfo
1738 if {[info exists commitdata
($id)]} {
1739 parsecommit
$id $commitdata($id) 1
1742 if {![info exists commitinfo
($id)]} {
1743 set commitinfo
($id) [list
[mc
"No commit information available"]]
1749 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1750 # and are present in the current view.
1751 # This is fairly slow...
1752 proc longid
{prefix
} {
1753 global varcid curview vshortids
1756 if {[string length
$prefix] >= 4} {
1757 set vshortid
$curview,[string range
$prefix 0 3]
1758 if {[info exists vshortids
($vshortid)]} {
1759 foreach id
$vshortids($vshortid) {
1760 if {[string match
"$prefix*" $id]} {
1761 if {[lsearch
-exact $ids $id] < 0} {
1763 if {[llength
$ids] >= 2} break
1769 foreach match
[array names varcid
"$curview,$prefix*"] {
1770 lappend ids
[lindex
[split $match ","] 1]
1771 if {[llength
$ids] >= 2} break
1778 global tagids idtags headids idheads tagobjid
1779 global otherrefids idotherrefs mainhead mainheadid
1780 global selecthead selectheadid
1784 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1785 unset -nocomplain $v
1787 set refd
[open
[list | git show-ref
-d] r
]
1788 if {$tclencoding != {}} {
1789 fconfigure
$refd -encoding $tclencoding
1791 while {[gets
$refd line
] >= 0} {
1792 if {[string index
$line 40] ne
" "} continue
1793 set id
[string range
$line 0 39]
1794 set ref
[string range
$line 41 end
]
1795 if {![string match
"refs/*" $ref]} continue
1796 set name
[string range
$ref 5 end
]
1797 if {[string match
"remotes/*" $name]} {
1798 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1799 set headids
($name) $id
1800 lappend idheads
($id) $name
1802 } elseif
{[string match
"heads/*" $name]} {
1803 set name
[string range
$name 6 end
]
1804 set headids
($name) $id
1805 lappend idheads
($id) $name
1806 } elseif
{[string match
"tags/*" $name]} {
1807 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1808 # which is what we want since the former is the commit ID
1809 set name
[string range
$name 5 end
]
1810 if {[string match
"*^{}" $name]} {
1811 set name
[string range
$name 0 end-3
]
1813 set tagobjid
($name) $id
1815 set tagids
($name) $id
1816 lappend idtags
($id) $name
1818 set otherrefids
($name) $id
1819 lappend idotherrefs
($id) $name
1826 set mainheadid
[exec git rev-parse HEAD
]
1827 set thehead
[exec git symbolic-ref HEAD
]
1828 if {[string match
"refs/heads/*" $thehead]} {
1829 set mainhead
[string range
$thehead 11 end
]
1833 if {$selecthead ne
{}} {
1835 set selectheadid
[exec git rev-parse
--verify $selecthead]
1840 # skip over fake commits
1841 proc first_real_row
{} {
1842 global nullid nullid2 numcommits
1844 for {set row
0} {$row < $numcommits} {incr row
} {
1845 set id
[commitonrow
$row]
1846 if {$id ne
$nullid && $id ne
$nullid2} {
1853 # update things for a head moved to a child of its previous location
1854 proc movehead
{id name
} {
1855 global headids idheads
1857 removehead
$headids($name) $name
1858 set headids
($name) $id
1859 lappend idheads
($id) $name
1862 # update things when a head has been removed
1863 proc removehead
{id name
} {
1864 global headids idheads
1866 if {$idheads($id) eq
$name} {
1869 set i
[lsearch
-exact $idheads($id) $name]
1871 set idheads
($id) [lreplace
$idheads($id) $i $i]
1874 unset headids
($name)
1877 proc ttk_toplevel
{w args
} {
1879 eval [linsert
$args 0 ::toplevel
$w]
1881 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1886 proc make_transient
{window origin
} {
1889 # In MacOS Tk 8.4 transient appears to work by setting
1890 # overrideredirect, which is utterly useless, since the
1891 # windows get no border, and are not even kept above
1893 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1895 wm transient
$window $origin
1897 # Windows fails to place transient windows normally, so
1898 # schedule a callback to center them on the parent.
1899 if {[tk windowingsystem
] eq
{win32
}} {
1900 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1904 proc show_error
{w top msg
} {
1906 if {![info exists NS
]} {set NS
""}
1907 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1908 message
$w.m
-text $msg -justify center
-aspect 400
1909 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1910 ${NS}::button
$w.ok
-default active
-text [mc OK
] -command "destroy $top"
1911 pack
$w.ok
-side bottom
-fill x
1912 bind $top <Visibility
> "grab $top; focus $top"
1913 bind $top <Key-Return
> "destroy $top"
1914 bind $top <Key-space
> "destroy $top"
1915 bind $top <Key-Escape
> "destroy $top"
1919 proc error_popup
{msg
{owner .
}} {
1920 if {[tk windowingsystem
] eq
"win32"} {
1921 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1922 -parent $owner -message $msg
1926 make_transient
$w $owner
1927 show_error
$w $w $msg
1931 proc confirm_popup
{msg
{owner .
}} {
1932 global confirm_ok NS
1936 make_transient
$w $owner
1937 message
$w.m
-text $msg -justify center
-aspect 400
1938 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1939 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1940 pack
$w.ok
-side left
-fill x
1941 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1942 pack
$w.cancel
-side right
-fill x
1943 bind $w <Visibility
> "grab $w; focus $w"
1944 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1945 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1946 bind $w <Key-Escape
> "destroy $w"
1947 tk
::PlaceWindow
$w widget
$owner
1952 proc setoptions
{} {
1955 if {[tk windowingsystem
] ne
"win32"} {
1956 option add
*Panedwindow.showHandle
1 startupFile
1957 option add
*Panedwindow.sashRelief raised startupFile
1958 if {[tk windowingsystem
] ne
"aqua"} {
1959 option add
*Menu.font uifont startupFile
1962 option add
*Menu.TearOff
0 startupFile
1964 option add
*Button.font uifont startupFile
1965 option add
*Checkbutton.font uifont startupFile
1966 option add
*Radiobutton.font uifont startupFile
1967 option add
*Menubutton.font uifont startupFile
1968 option add
*Label.font uifont startupFile
1969 option add
*Message.font uifont startupFile
1970 option add
*Entry.font textfont startupFile
1971 option add
*Text.font textfont startupFile
1972 option add
*Labelframe.font uifont startupFile
1973 option add
*Spinbox.font textfont startupFile
1974 option add
*Listbox.font mainfont startupFile
1977 proc setttkstyle
{} {
1978 eval font configure TkDefaultFont
[fontflags mainfont
]
1979 eval font configure TkTextFont
[fontflags textfont
]
1980 eval font configure TkHeadingFont
[fontflags mainfont
]
1981 eval font configure TkCaptionFont
[fontflags mainfont
] -weight bold
1982 eval font configure TkTooltipFont
[fontflags uifont
]
1983 eval font configure TkFixedFont
[fontflags textfont
]
1984 eval font configure TkIconFont
[fontflags uifont
]
1985 eval font configure TkMenuFont
[fontflags uifont
]
1986 eval font configure TkSmallCaptionFont
[fontflags uifont
]
1989 # Make a menu and submenus.
1990 # m is the window name for the menu, items is the list of menu items to add.
1991 # Each item is a list {mc label type description options...}
1992 # mc is ignored; it's so we can put mc there to alert xgettext
1993 # label is the string that appears in the menu
1994 # type is cascade, command or radiobutton (should add checkbutton)
1995 # description depends on type; it's the sublist for cascade, the
1996 # command to invoke for command, or {variable value} for radiobutton
1997 proc makemenu
{m items
} {
1999 if {[tk windowingsystem
] eq
{aqua
}} {
2005 set name
[mc
[lindex
$i 1]]
2006 set type [lindex
$i 2]
2007 set thing
[lindex
$i 3]
2008 set params
[list
$type]
2010 set u
[string first
"&" [string map
{&& x
} $name]]
2011 lappend params
-label [string map
{&& & & {}} $name]
2013 lappend params
-underline $u
2018 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
2019 lappend params
-menu $m.
$submenu
2022 lappend params
-command $thing
2025 lappend params
-variable [lindex
$thing 0] \
2026 -value [lindex
$thing 1]
2029 set tail [lrange
$i 4 end
]
2030 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2031 eval $m add
$params $tail
2032 if {$type eq
"cascade"} {
2033 makemenu
$m.
$submenu $thing
2038 # translate string and remove ampersands
2040 return [string map
{&& & & {}} [mc
$str]]
2043 proc cleardropsel
{w
} {
2046 proc makedroplist
{w varname args
} {
2050 foreach label
$args {
2051 set cx
[string length
$label]
2052 if {$cx > $width} {set width
$cx}
2054 set gm
[ttk
::combobox
$w -width $width -state readonly\
2055 -textvariable $varname -values $args \
2056 -exportselection false
]
2057 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2059 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2064 proc makewindow {} {
2065 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2067 global findtype findtypemenu findloc findstring fstring geometry
2068 global entries sha1entry sha1string sha1but
2069 global diffcontextstring diffcontext
2071 global maincursor textcursor curtextcursor
2072 global rowctxmenu fakerowmenu mergemax wrapcomment
2073 global highlight_files gdttype
2074 global searchstring sstring
2075 global bgcolor fgcolor bglist fglist diffcolors diffbgcolors selectbgcolor
2076 global uifgcolor uifgdisabledcolor
2077 global filesepbgcolor filesepfgcolor
2078 global mergecolors foundbgcolor currentsearchhitbgcolor
2079 global headctxmenu progresscanv progressitem progresscoords statusw
2080 global fprogitem fprogcoord lastprogupdate progupdatepending
2081 global rprogitem rprogcoord rownumsel numcommits
2082 global have_tk85 use_ttk NS
2086 # The "mc" arguments here are purely so that xgettext
2087 # sees the following string as needing to be translated
2089 mc "&File" cascade {
2090 {mc "&Update" command updatecommits -accelerator F5}
2091 {mc "&Reload" command reloadcommits -accelerator Shift-F5}
2092 {mc "Reread re&ferences" command rereadrefs}
2093 {mc "&List references" command showrefs -accelerator F2}
2095 {mc "Start git &gui" command {exec git gui &}}
2097 {mc "&Quit" command doquit -accelerator Meta1-Q}
2100 mc "&Edit" cascade {
2101 {mc "&Preferences" command doprefs}
2104 mc "&View" cascade {
2105 {mc "&New view..." command {newview 0} -accelerator Shift-F4}
2106 {mc "&Edit view..." command editview -state disabled -accelerator F4}
2107 {mc "&Delete view" command delview -state disabled}
2109 {mc "&All files" radiobutton {selectedview 0} -command {showview 0}}
2111 if {[tk windowingsystem] ne "aqua"} {
2113 mc "&Help" cascade {
2114 {mc "&About gitk" command about}
2115 {mc "&Key bindings" command keys}
2117 set bar [list $file $edit $view $help]
2119 proc ::tk::mac::ShowPreferences {} {doprefs}
2120 proc ::tk::mac::Quit {} {doquit}
2121 lset file end [lreplace [lindex $file end] end-1 end]
2123 xx "&Apple" cascade {
2124 {mc "&About gitk" command about}
2128 mc "&Help" cascade {
2129 {mc "&Key bindings" command keys}
2131 set bar [list $apple $file $view $help]
2134 . configure -menu .bar
2137 # cover the non-themed toplevel with a themed frame.
2138 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2141 # the gui has upper and lower half, parts of a paned window.
2142 ${NS}::panedwindow .ctop -orient vertical
2144 # possibly use assumed geometry
2145 if {![info exists geometry(pwsash0)]} {
2146 set geometry(topheight) [expr {15 * $linespc}]
2147 set geometry(topwidth) [expr {80 * $charspc}]
2148 set geometry(botheight) [expr {15 * $linespc}]
2149 set geometry(botwidth) [expr {50 * $charspc}]
2150 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2151 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2154 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2155 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2156 ${NS}::frame .tf.histframe
2157 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2159 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2162 # create three canvases
2163 set cscroll .tf.histframe.csb
2164 set canv .tf.histframe.pwclist.canv
2166 -selectbackground $selectbgcolor \
2167 -background $bgcolor -bd 0 \
2168 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2169 .tf.histframe.pwclist add $canv
2170 set canv2 .tf.histframe.pwclist.canv2
2172 -selectbackground $selectbgcolor \
2173 -background $bgcolor -bd 0 -yscrollincr $linespc
2174 .tf.histframe.pwclist add $canv2
2175 set canv3 .tf.histframe.pwclist.canv3
2177 -selectbackground $selectbgcolor \
2178 -background $bgcolor -bd 0 -yscrollincr $linespc
2179 .tf.histframe.pwclist add $canv3
2181 bind .tf.histframe.pwclist <Map> {
2183 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2184 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2187 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2188 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2191 # a scroll bar to rule them
2192 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2193 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2194 pack $cscroll -side right -fill y
2195 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2196 lappend bglist $canv $canv2 $canv3
2197 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2199 # we have two button bars at bottom of top frame. Bar 1
2200 ${NS}::frame .tf.bar
2201 ${NS}::frame .tf.lbar -height 15
2203 set sha1entry .tf.bar.sha1
2204 set entries $sha1entry
2205 set sha1but .tf.bar.sha1label
2206 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2207 -command gotocommit -width 8
2208 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2209 pack .tf.bar.sha1label -side left
2210 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2211 trace add variable sha1string write sha1change
2212 pack $sha1entry -side left -pady 2
2215 #define left_width 16
2216 #define left_height 16
2217 static unsigned char left_bits[] = {
2218 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2219 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2220 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2223 #define right_width 16
2224 #define right_height 16
2225 static unsigned char right_bits[] = {
2226 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2227 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2228 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2230 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2231 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2232 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2233 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2235 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2237 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2239 .tf.bar.leftbut configure -image bm-left
2241 pack .tf.bar.leftbut -side left -fill y
2242 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2244 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2246 .tf.bar.rightbut configure -image bm-right
2248 pack .tf.bar.rightbut -side left -fill y
2250 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2252 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2253 -relief sunken -anchor e
2254 ${NS}::label .tf.bar.rowlabel2 -text "/"
2255 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2256 -relief sunken -anchor e
2257 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2260 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2263 trace add variable selectedline write selectedline_change
2265 # Status label and progress bar
2266 set statusw .tf.bar.status
2267 ${NS}::label $statusw -width 15 -relief sunken
2268 pack $statusw -side left -padx 5
2270 set progresscanv [ttk::progressbar .tf.bar.progress]
2272 set h [expr {[font metrics uifont -linespace] + 2}]
2273 set progresscanv .tf.bar.progress
2274 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2275 set progressitem [$progresscanv create rect -1 0 0 $h -fill "#00ff00"]
2276 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2277 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2279 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2280 set progresscoords {0 0}
2283 bind $progresscanv <Configure> adjustprogress
2284 set lastprogupdate [clock clicks -milliseconds]
2285 set progupdatepending 0
2287 # build up the bottom bar of upper window
2288 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2291 #define down_width 16
2292 #define down_height 16
2293 static unsigned char down_bits[] = {
2294 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2295 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2296 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2297 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
2299 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2300 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2301 .tf.lbar.fnext configure -image bm-down
2305 #define up_height 16
2306 static unsigned char up_bits[] = {
2307 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2308 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2309 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2310 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
2312 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2313 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2314 .tf.lbar.fprev configure -image bm-up
2316 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2318 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2320 set gdttype [mc "containing:"]
2321 set gm [makedroplist .tf.lbar.gdttype gdttype \
2322 [mc "containing:"] \
2323 [mc "touching paths:"] \
2324 [mc "adding/removing string:"] \
2325 [mc "changing lines matching:"]]
2326 trace add variable gdttype write gdttype_change
2327 pack .tf.lbar.gdttype -side left -fill y
2330 set fstring .tf.lbar.findstring
2331 lappend entries $fstring
2332 ${NS}::entry $fstring -width 30 -textvariable findstring
2333 trace add variable findstring write find_change
2334 set findtype [mc "Exact"]
2335 set findtypemenu [makedroplist .tf.lbar.findtype \
2336 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2337 trace add variable findtype write findcom_change
2338 set findloc [mc "All fields"]
2339 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2340 [mc "Comments"] [mc "Author"] [mc "Committer"]
2341 trace add variable findloc write find_change
2342 pack .tf.lbar.findloc -side right
2343 pack .tf.lbar.findtype -side right
2344 pack $fstring -side left -expand 1 -fill x
2346 # Finish putting the upper half of the viewer together
2347 pack .tf.lbar -in .tf -side bottom -fill x
2348 pack .tf.bar -in .tf -side bottom -fill x
2349 pack .tf.histframe -fill both -side top -expand 1
2352 .ctop paneconfigure .tf -height $geometry(topheight)
2353 .ctop paneconfigure .tf -width $geometry(topwidth)
2356 # now build up the bottom
2357 ${NS}::panedwindow .pwbottom -orient horizontal
2359 # lower left, a text box over search bar, scroll bar to the right
2360 # if we know window height, then that will set the lower text height, otherwise
2361 # we set lower text height which will drive window height
2362 if {[info exists geometry(main)]} {
2363 ${NS}::frame .bleft -width $geometry(botwidth)
2365 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2367 ${NS}::frame .bleft.top
2368 ${NS}::frame .bleft.mid
2369 ${NS}::frame .bleft.bottom
2371 # gap between sub-widgets
2372 set wgap [font measure uifont "i"]
2374 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2375 pack .bleft.top.search -side left -padx 5
2376 set sstring .bleft.top.sstring
2378 ${NS}::entry $sstring -width 20 -textvariable searchstring
2379 lappend entries $sstring
2380 trace add variable searchstring write incrsearch
2381 pack $sstring -side left -expand 1 -fill x
2382 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2383 -command changediffdisp -variable diffelide -value {0 0}
2384 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2385 -command changediffdisp -variable diffelide -value {0 1}
2386 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2387 -command changediffdisp -variable diffelide -value {1 0}
2389 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2390 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
2391 spinbox .bleft.mid.diffcontext -width 5 \
2392 -from 0 -increment 1 -to 10000000 \
2393 -validate all -validatecommand "diffcontextvalidate %P" \
2394 -textvariable diffcontextstring
2395 .bleft.mid.diffcontext set $diffcontext
2396 trace add variable diffcontextstring write diffcontextchange
2397 lappend entries .bleft.mid.diffcontext
2398 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
2399 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2400 -command changeignorespace -variable ignorespace
2401 pack .bleft.mid.ignspace -side left -padx 5
2403 set worddiff [mc "Line diff"]
2404 if {[package vcompare $git_version "1.7.2"] >= 0} {
2405 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2406 [mc "Markup words"] [mc "Color words"]
2407 trace add variable worddiff write changeworddiff
2408 pack .bleft.mid.worddiff -side left -padx 5
2411 set ctext .bleft.bottom.ctext
2412 text $ctext -background $bgcolor -foreground $fgcolor \
2413 -state disabled -undo 0 -font textfont \
2414 -yscrollcommand scrolltext -wrap none \
2415 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2417 $ctext conf -tabstyle wordprocessor
2419 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2420 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2421 pack .bleft.top -side top -fill x
2422 pack .bleft.mid -side top -fill x
2423 grid $ctext .bleft.bottom.sb -sticky nsew
2424 grid .bleft.bottom.sbhorizontal -sticky ew
2425 grid columnconfigure .bleft.bottom 0 -weight 1
2426 grid rowconfigure .bleft.bottom 0 -weight 1
2427 grid rowconfigure .bleft.bottom 1 -weight 0
2428 pack .bleft.bottom -side top -fill both -expand 1
2429 lappend bglist $ctext
2430 lappend fglist $ctext
2432 $ctext tag conf comment -wrap $wrapcomment
2433 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2434 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2435 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2436 $ctext tag conf d0 -back [lindex $diffbgcolors 0]
2437 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2438 $ctext tag conf dresult -back [lindex $diffbgcolors 1]
2439 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2440 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2441 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2442 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2443 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2444 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2445 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2446 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2447 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2448 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2449 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2450 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2451 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2452 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2453 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2454 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2455 $ctext tag conf mmax -fore darkgrey
2457 $ctext tag conf mresult -font textfontbold
2458 $ctext tag conf msep -font textfontbold
2459 $ctext tag conf found -back $foundbgcolor
2460 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2461 $ctext tag conf wwrap -wrap word -lmargin2 1c
2462 $ctext tag conf bold -font textfontbold
2463 # set these to the lowest priority:
2464 $ctext tag lower currentsearchhit
2465 $ctext tag lower found
2466 $ctext tag lower filesep
2467 $ctext tag lower dresult
2470 .pwbottom add .bleft
2472 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2476 ${NS}::frame .bright
2477 ${NS}::frame .bright.mode
2478 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2479 -command reselectline -variable cmitmode -value "patch"
2480 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2481 -command reselectline -variable cmitmode -value "tree"
2482 grid .bright.mode.patch .bright.mode.tree -sticky ew
2483 pack .bright.mode -side top -fill x
2484 set cflist .bright.cfiles
2485 set indent [font measure mainfont "nn"]
2487 -selectbackground $selectbgcolor \
2488 -background $bgcolor -foreground $fgcolor \
2490 -tabs [list $indent [expr {2 * $indent}]] \
2491 -yscrollcommand ".bright.sb set" \
2492 -cursor [. cget -cursor] \
2493 -spacing1 1 -spacing3 1
2494 lappend bglist $cflist
2495 lappend fglist $cflist
2496 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2497 pack .bright.sb -side right -fill y
2498 pack $cflist -side left -fill both -expand 1
2499 $cflist tag configure highlight \
2500 -background [$cflist cget -selectbackground]
2501 $cflist tag configure bold -font mainfontbold
2503 .pwbottom add .bright
2506 # restore window width & height if known
2507 if {[info exists geometry(main)]} {
2508 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2509 if {$w > [winfo screenwidth .]} {
2510 set w [winfo screenwidth .]
2512 if {$h > [winfo screenheight .]} {
2513 set h [winfo screenheight .]
2515 wm geometry . "${w}x$h"
2519 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2520 wm state . $geometry(state)
2523 if {[tk windowingsystem] eq {aqua}} {
2534 %W sashpos 0 $::geometry(topheight)
2536 bind .pwbottom <Map> {
2538 %W sashpos 0 $::geometry(botwidth)
2540 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2543 pack .ctop -fill both -expand 1
2544 bindall <1> {selcanvline %W %x %y}
2545 #bindall <B1-Motion> {selcanvline %W %x %y}
2546 if {[tk windowingsystem] == "win32"} {
2547 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2548 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2550 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2551 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2552 bind $ctext <Button> {
2554 $ctext xview scroll -5 units
2555 } elseif {"%b" eq 7} {
2556 $ctext xview scroll 5 units
2559 if {[tk windowingsystem] eq "aqua"} {
2560 bindall <MouseWheel> {
2561 set delta [expr {- (%D)}]
2562 allcanvs yview scroll $delta units
2564 bindall <Shift-MouseWheel> {
2565 set delta [expr {- (%D)}]
2566 $canv xview scroll $delta units
2570 bindall <$::BM> "canvscan mark %W %x %y"
2571 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2572 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2573 bind . <$M1B-Key-w> doquit
2574 bindkey <Home> selfirstline
2575 bindkey <End> sellastline
2576 bind . <Key-Up> "selnextline -1"
2577 bind . <Key-Down> "selnextline 1"
2578 bind . <Shift-Key-Up> "dofind -1 0"
2579 bind . <Shift-Key-Down> "dofind 1 0"
2580 bindkey <Key-Right> "goforw"
2581 bindkey <Key-Left> "goback"
2582 bind . <Key-Prior> "selnextpage -1"
2583 bind . <Key-Next> "selnextpage 1"
2584 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2585 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2586 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2587 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2588 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2589 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2590 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2591 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2592 bindkey <Key-space> "$ctext yview scroll 1 pages"
2593 bindkey p "selnextline -1"
2594 bindkey n "selnextline 1"
2597 bindkey k "selnextline -1"
2598 bindkey j "selnextline 1"
2602 bindkey d "$ctext yview scroll 18 units"
2603 bindkey u "$ctext yview scroll -18 units"
2604 bindkey g {$sha1entry delete 0 end; focus $sha1entry}
2605 bindkey / {focus $fstring}
2606 bindkey <Key-KP_Divide> {focus $fstring}
2607 bindkey <Key-Return> {dofind 1 1}
2608 bindkey ? {dofind -1 1}
2610 bind . <F5> updatecommits
2611 bindmodfunctionkey Shift 5 reloadcommits
2612 bind . <F2> showrefs
2613 bindmodfunctionkey Shift 4 {newview 0}
2614 bind . <F4> edit_or_newview
2615 bind . <$M1B-q> doquit
2616 bind . <$M1B-f> {dofind 1 1}
2617 bind . <$M1B-g> {dofind 1 0}
2618 bind . <$M1B-r> dosearchback
2619 bind . <$M1B-s> dosearch
2620 bind . <$M1B-equal> {incrfont 1}
2621 bind . <$M1B-plus> {incrfont 1}
2622 bind . <$M1B-KP_Add> {incrfont 1}
2623 bind . <$M1B-minus> {incrfont -1}
2624 bind . <$M1B-KP_Subtract> {incrfont -1}
2625 wm protocol . WM_DELETE_WINDOW doquit
2626 bind . <Destroy> {stop_backends}
2627 bind . <Button-1> "click %W"
2628 bind $fstring <Key-Return> {dofind 1 1}
2629 bind $sha1entry <Key-Return> {gotocommit; break}
2630 bind $sha1entry <<PasteSelection>> clearsha1
2631 bind $sha1entry <<Paste>> clearsha1
2632 bind $cflist <1> {sel_flist %W %x %y; break}
2633 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2634 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2636 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2637 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2638 bind $ctext <Button-1> {focus %W}
2639 bind $ctext <<Selection>> rehighlight_search_results
2640 for {set i 1} {$i < 10} {incr i} {
2641 bind . <$M1B-Key-$i> [list go_to_parent $i]
2644 set maincursor [. cget -cursor]
2645 set textcursor [$ctext cget -cursor]
2646 set curtextcursor $textcursor
2648 set rowctxmenu .rowctxmenu
2649 makemenu $rowctxmenu {
2650 {mc "Diff this -> selected" command {diffvssel 0}}
2651 {mc "Diff selected -> this" command {diffvssel 1}}
2652 {mc "Make patch" command mkpatch}
2653 {mc "Create tag" command mktag}
2654 {mc "Copy commit reference" command copyreference}
2655 {mc "Write commit to file" command writecommit}
2656 {mc "Create new branch" command mkbranch}
2657 {mc "Cherry-pick this commit" command cherrypick}
2658 {mc "Reset HEAD branch to here" command resethead}
2659 {mc "Mark this commit" command markhere}
2660 {mc "Return to mark" command gotomark}
2661 {mc "Find descendant of this and mark" command find_common_desc}
2662 {mc "Compare with marked commit" command compare_commits}
2663 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2664 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2665 {mc "Revert this commit" command revert}
2667 $rowctxmenu configure -tearoff 0
2669 set fakerowmenu .fakerowmenu
2670 makemenu $fakerowmenu {
2671 {mc "Diff this -> selected" command {diffvssel 0}}
2672 {mc "Diff selected -> this" command {diffvssel 1}}
2673 {mc "Make patch" command mkpatch}
2674 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2675 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2677 $fakerowmenu configure -tearoff 0
2679 set headctxmenu .headctxmenu
2680 makemenu $headctxmenu {
2681 {mc "Check out this branch" command cobranch}
2682 {mc "Rename this branch" command mvbranch}
2683 {mc "Remove this branch" command rmbranch}
2684 {mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
2686 $headctxmenu configure -tearoff 0
2689 set flist_menu .flistctxmenu
2690 makemenu $flist_menu {
2691 {mc "Highlight this too" command {flist_hl 0}}
2692 {mc "Highlight this only" command {flist_hl 1}}
2693 {mc "External diff" command {external_diff}}
2694 {mc "Blame parent commit" command {external_blame 1}}
2695 {mc "Copy path" command {clipboard clear; clipboard append $flist_menu_file}}
2697 $flist_menu configure -tearoff 0
2700 set diff_menu .diffctxmenu
2701 makemenu $diff_menu {
2702 {mc "Show origin of this line" command show_line_source}
2703 {mc "Run git gui blame on this line" command {external_blame_diff}}
2705 $diff_menu configure -tearoff 0
2708 # Windows sends all mouse wheel events to the current focused window, not
2709 # the one where the mouse hovers, so bind those events here and redirect
2710 # to the correct window
2711 proc windows_mousewheel_redirector {W X Y D} {
2712 global canv canv2 canv3
2713 set w [winfo containing -displayof $W $X $Y]
2715 set u [expr {$D < 0 ? 5 : -5}]
2716 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2717 allcanvs yview scroll $u units
2720 $w yview scroll $u units
2726 # Update row number label when selectedline changes
2727 proc selectedline_change {n1 n2 op} {
2728 global selectedline rownumsel
2730 if {$selectedline eq {}} {
2733 set rownumsel [expr {$selectedline + 1}]
2737 # mouse-2 makes all windows scan vertically, but only the one
2738 # the cursor is in scans horizontally
2739 proc canvscan {op w x y} {
2740 global canv canv2 canv3
2741 foreach c [list $canv $canv2 $canv3] {
2750 proc scrollcanv {cscroll f0 f1} {
2751 $cscroll set $f0 $f1
2756 # when we make a key binding for the toplevel, make sure
2757 # it doesn't get triggered when that key is pressed in the
2758 # find string entry widget.
2759 proc bindkey {ev script} {
2762 set escript [bind Entry $ev]
2763 if {$escript == {}} {
2764 set escript [bind Entry <Key>]
2766 foreach e $entries {
2767 bind $e $ev "$escript; break"
2771 proc bindmodfunctionkey {mod n script} {
2772 bind . <$mod-F$n> $script
2773 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2776 # set the focus back to the toplevel for any click outside
2779 global ctext entries
2780 foreach e [concat $entries $ctext] {
2781 if {$w == $e} return
2786 # Adjust the progress bar for a change in requested extent or canvas size
2787 proc adjustprogress {} {
2788 global progresscanv progressitem progresscoords
2789 global fprogitem fprogcoord lastprogupdate progupdatepending
2790 global rprogitem rprogcoord use_ttk
2793 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2797 set w [expr {[winfo width $progresscanv] - 4}]
2798 set x0 [expr {$w * [lindex $progresscoords 0]}]
2799 set x1 [expr {$w * [lindex $progresscoords 1]}]
2800 set h [winfo height $progresscanv]
2801 $progresscanv coords $progressitem $x0 0 $x1 $h
2802 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2803 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2804 set now [clock clicks -milliseconds]
2805 if {$now >= $lastprogupdate + 100} {
2806 set progupdatepending 0
2808 } elseif {!$progupdatepending} {
2809 set progupdatepending 1
2810 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2814 proc doprogupdate {} {
2815 global lastprogupdate progupdatepending
2817 if {$progupdatepending} {
2818 set progupdatepending 0
2819 set lastprogupdate [clock clicks -milliseconds]
2824 proc config_check_tmp_exists {tries_left} {
2825 global config_file_tmp
2827 if {[file exists $config_file_tmp]} {
2829 if {$tries_left > 0} {
2830 after 100 [list config_check_tmp_exists $tries_left]
2832 error_popup "There appears to be a stale $config_file_tmp\
2833 file, which will prevent gitk from saving its configuration on exit.\
2834 Please remove it if it is not being used by any existing gitk process."
2839 proc config_init_trace {name} {
2840 global config_variable_changed config_variable_original
2843 set config_variable_changed($name) 0
2844 set config_variable_original($name) $var
2847 proc config_variable_change_cb {name name2 op} {
2848 global config_variable_changed config_variable_original
2851 if {$op eq "write" &&
2852 (![info exists config_variable_original($name)] ||
2853 $config_variable_original($name) ne $var)} {
2854 set config_variable_changed($name) 1
2858 proc savestuff {w} {
2860 global config_file config_file_tmp
2861 global config_variables config_variable_changed
2864 upvar #0 viewname current_viewname
2865 upvar #0 viewfiles current_viewfiles
2866 upvar #0 viewargs current_viewargs
2867 upvar #0 viewargscmd current_viewargscmd
2868 upvar #0 viewperm current_viewperm
2869 upvar #0 nextviewnum current_nextviewnum
2870 upvar #0 use_ttk current_use_ttk
2872 if {$stuffsaved} return
2873 if {![winfo viewable .]} return
2877 while {[catch {set f [open $config_file_tmp {WRONLY CREAT EXCL}]}]} {
2878 if {[incr try_count] > 50} {
2879 error "Unable to write config file: $config_file_tmp exists"
2884 if {$::tcl_platform(platform) eq {windows}} {
2885 file attributes $config_file_tmp -hidden true
2887 if {[file exists $config_file]} {
2890 foreach var_name $config_variables {
2891 upvar #0 $var_name var
2892 upvar 0 $var_name old_var
2893 if {!$config_variable_changed($var_name) && [info exists old_var]} {
2894 puts $f [list set $var_name $old_var]
2896 puts $f [list set $var_name $var]
2900 puts $f "set geometry(main) [wm geometry .]"
2901 puts $f "set geometry(state) [wm state .]"
2902 puts $f "set geometry(topwidth) [winfo width .tf]"
2903 puts $f "set geometry(topheight) [winfo height .tf]"
2904 if {$current_use_ttk} {
2905 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2906 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2908 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2909 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2911 puts $f "set geometry(botwidth) [winfo width .bleft]"
2912 puts $f "set geometry(botheight) [winfo height .bleft]"
2914 array set view_save {}
2916 if {![info exists permviews]} { set permviews {} }
2917 foreach view $permviews {
2918 set view_save([lindex $view 0]) 1
2919 set views([lindex $view 0]) $view
2921 puts -nonewline $f "set permviews {"
2922 for {set v 1} {$v < $current_nextviewnum} {incr v} {
2923 if {$viewchanged($v)} {
2924 if {$current_viewperm($v)} {
2925 set views($current_viewname($v)) [list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]
2927 set view_save($current_viewname($v)) 0
2931 # write old and updated view to their places and append remaining to the end
2932 foreach view $permviews {
2933 set view_name [lindex $view 0]
2934 if {$view_save($view_name)} {
2935 puts $f "{$views($view_name)}"
2937 unset views($view_name)
2939 foreach view_name [array names views] {
2940 puts $f "{$views($view_name)}"
2944 file rename -force $config_file_tmp $config_file
2947 puts "Error saving config: $err"
2950 file delete -force $config_file_tmp
2955 proc resizeclistpanes {win w} {
2956 global oldwidth use_ttk
2957 if {[info exists oldwidth($win)]} {
2959 set s0 [$win sashpos 0]
2960 set s1 [$win sashpos 1]
2962 set s0 [$win sash coord 0]
2963 set s1 [$win sash coord 1]
2966 set sash0 [expr {int($w/2 - 2)}]
2967 set sash1 [expr {int($w*5/6 - 2)}]
2969 set factor [expr {1.0 * $w / $oldwidth($win)}]
2970 set sash0 [expr {int($factor * [lindex $s0 0])}]
2971 set sash1 [expr {int($factor * [lindex $s1 0])}]
2975 if {$sash1 < $sash0 + 20} {
2976 set sash1 [expr {$sash0 + 20}]
2978 if {$sash1 > $w - 10} {
2979 set sash1 [expr {$w - 10}]
2980 if {$sash0 > $sash1 - 20} {
2981 set sash0 [expr {$sash1 - 20}]
2986 $win sashpos 0 $sash0
2987 $win sashpos 1 $sash1
2989 $win sash place 0 $sash0 [lindex $s0 1]
2990 $win sash place 1 $sash1 [lindex $s1 1]
2993 set oldwidth($win) $w
2996 proc resizecdetpanes {win w} {
2997 global oldwidth use_ttk
2998 if {[info exists oldwidth($win)]} {
3000 set s0 [$win sashpos 0]
3002 set s0 [$win sash coord 0]
3005 set sash0 [expr {int($w*3/4 - 2)}]
3007 set factor [expr {1.0 * $w / $oldwidth($win)}]
3008 set sash0 [expr {int($factor * [lindex $s0 0])}]
3012 if {$sash0 > $w - 15} {
3013 set sash0 [expr {$w - 15}]
3017 $win sashpos 0 $sash0
3019 $win sash place 0 $sash0 [lindex $s0 1]
3022 set oldwidth($win) $w
3025 proc allcanvs args {
3026 global canv canv2 canv3
3032 proc bindall {event action} {
3033 global canv canv2 canv3
3034 bind $canv $event $action
3035 bind $canv2 $event $action
3036 bind $canv3 $event $action
3042 if {[winfo exists $w]} {
3047 wm title $w [mc "About gitk"]
3049 message $w.m -text [mc "
3050 Gitk - a commit viewer for git
3052 Copyright \u00a9 2005-2016 Paul Mackerras
3054 Use and redistribute under the terms of the GNU General Public License"] \
3055 -justify center -aspect 400 -border 2 -bg $bgcolor -relief groove
3056 pack $w.m -side top -fill x -padx 2 -pady 2
3057 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3058 pack $w.ok -side bottom
3059 bind $w <Visibility> "focus $w.ok"
3060 bind $w <Key-Escape> "destroy $w"
3061 bind $w <Key-Return> "destroy $w"
3062 tk::PlaceWindow $w widget .
3068 if {[winfo exists $w]} {
3072 if {[tk windowingsystem] eq {aqua}} {
3078 wm title $w [mc "Gitk key bindings"]
3080 message $w.m -text "
3081 [mc "Gitk key bindings:"]
3083 [mc "<%s-Q> Quit" $M1T]
3084 [mc "<%s-W> Close window" $M1T]
3085 [mc "<Home> Move to first commit"]
3086 [mc "<End> Move to last commit"]
3087 [mc "<Up>, p, k Move up one commit"]
3088 [mc "<Down>, n, j Move down one commit"]
3089 [mc "<Left>, z, h Go back in history list"]
3090 [mc "<Right>, x, l Go forward in history list"]
3091 [mc "<%s-n> Go to n-th parent of current commit in history list" $M1T]
3092 [mc "<PageUp> Move up one page in commit list"]
3093 [mc "<PageDown> Move down one page in commit list"]
3094 [mc "<%s-Home> Scroll to top of commit list" $M1T]
3095 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
3096 [mc "<%s-Up> Scroll commit list up one line" $M1T]
3097 [mc "<%s-Down> Scroll commit list down one line" $M1T]
3098 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
3099 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
3100 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
3101 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
3102 [mc "<Delete>, b Scroll diff view up one page"]
3103 [mc "<Backspace> Scroll diff view up one page"]
3104 [mc "<Space> Scroll diff view down one page"]
3105 [mc "u Scroll diff view up 18 lines"]
3106 [mc "d Scroll diff view down 18 lines"]
3107 [mc "<%s-F> Find" $M1T]
3108 [mc "<%s-G> Move to next find hit" $M1T]
3109 [mc "<Return> Move to next find hit"]
3110 [mc "g Go to commit"]
3111 [mc "/ Focus the search box"]
3112 [mc "? Move to previous find hit"]
3113 [mc "f Scroll diff view to next file"]
3114 [mc "<%s-S> Search for next hit in diff view" $M1T]
3115 [mc "<%s-R> Search for previous hit in diff view" $M1T]
3116 [mc "<%s-KP+> Increase font size" $M1T]
3117 [mc "<%s-plus> Increase font size" $M1T]
3118 [mc "<%s-KP-> Decrease font size" $M1T]
3119 [mc "<%s-minus> Decrease font size" $M1T]
3122 -justify left -bg $bgcolor -border 2 -relief groove
3123 pack $w.m -side top -fill both -padx 2 -pady 2
3124 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3125 bind $w <Key-Escape> [list destroy $w]
3126 pack $w.ok -side bottom
3127 bind $w <Visibility> "focus $w.ok"
3128 bind $w <Key-Escape> "destroy $w"
3129 bind $w <Key-Return> "destroy $w"
3132 # Procedures for manipulating the file list window at the
3133 # bottom right of the overall window.
3135 proc treeview {w l openlevs} {
3136 global treecontents treediropen treeheight treeparent treeindex
3146 set treecontents() {}
3147 $w conf -state normal
3149 while {[string range $f 0 $prefixend] ne $prefix} {
3150 if {$lev <= $openlevs} {
3151 $w mark set e:$treeindex($prefix) "end -1c"
3152 $w mark gravity e:$treeindex($prefix) left
3154 set treeheight($prefix) $ht
3155 incr ht [lindex $htstack end]
3156 set htstack [lreplace $htstack end end]
3157 set prefixend [lindex $prefendstack end]
3158 set prefendstack [lreplace $prefendstack end end]
3159 set prefix [string range $prefix 0 $prefixend]
3162 set tail [string range $f [expr {$prefixend+1}] end]
3163 while {[set slash [string first "/" $tail]] >= 0} {
3166 lappend prefendstack $prefixend
3167 incr prefixend [expr {$slash + 1}]
3168 set d [string range $tail 0 $slash]
3169 lappend treecontents($prefix) $d
3170 set oldprefix $prefix
3172 set treecontents($prefix) {}
3173 set treeindex($prefix) [incr ix]
3174 set treeparent($prefix) $oldprefix
3175 set tail [string range $tail [expr {$slash+1}] end]
3176 if {$lev <= $openlevs} {
3178 set treediropen($prefix) [expr {$lev < $openlevs}]
3179 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3180 $w mark set d:$ix "end -1c"
3181 $w mark gravity d:$ix left
3183 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3185 $w image create end -align center -image $bm -padx 1 \
3187 $w insert end $d [highlight_tag $prefix]
3188 $w mark set s:$ix "end -1c"
3189 $w mark gravity s:$ix left
3194 if {$lev <= $openlevs} {
3197 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3199 $w insert end $tail [highlight_tag $f]
3201 lappend treecontents($prefix) $tail
3204 while {$htstack ne {}} {
3205 set treeheight($prefix) $ht
3206 incr ht [lindex $htstack end]
3207 set htstack [lreplace $htstack end end]
3208 set prefixend [lindex $prefendstack end]
3209 set prefendstack [lreplace $prefendstack end end]
3210 set prefix [string range $prefix 0 $prefixend]
3212 $w conf -state disabled
3215 proc linetoelt {l} {
3216 global treeheight treecontents
3221 foreach e $treecontents($prefix) {
3226 if {[string index $e end] eq "/"} {
3227 set n $treeheight($prefix$e)
3239 proc highlight_tree {y prefix} {
3240 global treeheight treecontents cflist
3242 foreach e $treecontents($prefix) {
3244 if {[highlight_tag $path] ne {}} {
3245 $cflist tag add bold $y.0 "$y.0 lineend"
3248 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3249 set y [highlight_tree $y $path]
3255 proc treeclosedir {w dir} {
3256 global treediropen treeheight treeparent treeindex
3258 set ix $treeindex($dir)
3259 $w conf -state normal
3260 $w delete s:$ix e:$ix
3261 set treediropen($dir) 0
3262 $w image configure a:$ix -image tri-rt
3263 $w conf -state disabled
3264 set n [expr {1 - $treeheight($dir)}]
3265 while {$dir ne {}} {
3266 incr treeheight($dir) $n
3267 set dir $treeparent($dir)
3271 proc treeopendir {w dir} {
3272 global treediropen treeheight treeparent treecontents treeindex
3274 set ix $treeindex($dir)
3275 $w conf -state normal
3276 $w image configure a:$ix -image tri-dn
3277 $w mark set e:$ix s:$ix
3278 $w mark gravity e:$ix right
3281 set n [llength $treecontents($dir)]
3282 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3285 incr treeheight($x) $n
3287 foreach e $treecontents($dir) {
3289 if {[string index $e end] eq "/"} {
3290 set iy $treeindex($de)
3291 $w mark set d:$iy e:$ix
3292 $w mark gravity d:$iy left
3293 $w insert e:$ix $str
3294 set treediropen($de) 0
3295 $w image create e:$ix -align center -image tri-rt -padx 1 \
3297 $w insert e:$ix $e [highlight_tag $de]
3298 $w mark set s:$iy e:$ix
3299 $w mark gravity s:$iy left
3300 set treeheight($de) 1
3302 $w insert e:$ix $str
3303 $w insert e:$ix $e [highlight_tag $de]
3306 $w mark gravity e:$ix right
3307 $w conf -state disabled
3308 set treediropen($dir) 1
3309 set top [lindex [split [$w index @0,0] .] 0]
3310 set ht [$w cget -height]
3311 set l [lindex [split [$w index s:$ix] .] 0]
3314 } elseif {$l + $n + 1 > $top + $ht} {
3315 set top [expr {$l + $n + 2 - $ht}]
3323 proc treeclick {w x y} {
3324 global treediropen cmitmode ctext cflist cflist_top
3326 if {$cmitmode ne "tree"} return
3327 if {![info exists cflist_top]} return
3328 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3329 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3330 $cflist tag add highlight $l.0 "$l.0 lineend"
3336 set e [linetoelt $l]
3337 if {[string index $e end] ne "/"} {
3339 } elseif {$treediropen($e)} {
3346 proc setfilelist {id} {
3347 global treefilelist cflist jump_to_here
3349 treeview $cflist $treefilelist($id) 0
3350 if {$jump_to_here ne {}} {
3351 set f [lindex $jump_to_here 0]
3352 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3358 image create bitmap tri-rt -background black -foreground blue -data {
3359 #define tri-rt_width 13
3360 #define tri-rt_height 13
3361 static unsigned char tri-rt_bits[] = {
3362 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3363 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3366 #define tri-rt-mask_width 13
3367 #define tri-rt-mask_height 13
3368 static unsigned char tri-rt-mask_bits[] = {
3369 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3370 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3373 image create bitmap tri-dn -background black -foreground blue -data {
3374 #define tri-dn_width 13
3375 #define tri-dn_height 13
3376 static unsigned char tri-dn_bits[] = {
3377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3378 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3381 #define tri-dn-mask_width 13
3382 #define tri-dn-mask_height 13
3383 static unsigned char tri-dn-mask_bits[] = {
3384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3385 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3389 image create bitmap reficon-T -background black -foreground yellow -data {
3390 #define tagicon_width 13
3391 #define tagicon_height 9
3392 static unsigned char tagicon_bits[] = {
3393 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3394 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3396 #define tagicon-mask_width 13
3397 #define tagicon-mask_height 9
3398 static unsigned char tagicon-mask_bits[] = {
3399 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3400 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3403 #define headicon_width 13
3404 #define headicon_height 9
3405 static unsigned char headicon_bits[] = {
3406 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3407 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3410 #define headicon-mask_width 13
3411 #define headicon-mask_height 9
3412 static unsigned char headicon-mask_bits[] = {
3413 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3414 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3416 image create bitmap reficon-H -background black -foreground "#00ff00" \
3417 -data $rectdata -maskdata $rectmask
3418 image create bitmap reficon-R -background black -foreground "#ffddaa" \
3419 -data $rectdata -maskdata $rectmask
3420 image create bitmap reficon-o -background black -foreground "#ddddff" \
3421 -data $rectdata -maskdata $rectmask
3423 proc init_flist {first} {
3424 global cflist cflist_top difffilestart
3426 $cflist conf -state normal
3427 $cflist delete 0.0 end
3429 $cflist insert end $first
3431 $cflist tag add highlight 1.0 "1.0 lineend"
3433 unset -nocomplain cflist_top
3435 $cflist conf -state disabled
3436 set difffilestart {}
3439 proc highlight_tag {f} {
3440 global highlight_paths
3442 foreach p $highlight_paths {
3443 if {[string match $p $f]} {
3450 proc highlight_filelist {} {
3451 global cmitmode cflist
3453 $cflist conf -state normal
3454 if {$cmitmode ne "tree"} {
3455 set end [lindex [split [$cflist index end] .] 0]
3456 for {set l 2} {$l < $end} {incr l} {
3457 set line [$cflist get $l.0 "$l.0 lineend"]
3458 if {[highlight_tag $line] ne {}} {
3459 $cflist tag add bold $l.0 "$l.0 lineend"
3465 $cflist conf -state disabled
3468 proc unhighlight_filelist {} {
3471 $cflist conf -state normal
3472 $cflist tag remove bold 1.0 end
3473 $cflist conf -state disabled
3476 proc add_flist {fl} {
3479 $cflist conf -state normal
3481 $cflist insert end "\n"
3482 $cflist insert end $f [highlight_tag $f]
3484 $cflist conf -state disabled
3487 proc sel_flist {w x y} {
3488 global ctext difffilestart cflist cflist_top cmitmode
3490 if {$cmitmode eq "tree"} return
3491 if {![info exists cflist_top]} return
3492 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3493 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3494 $cflist tag add highlight $l.0 "$l.0 lineend"
3499 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3501 suppress_highlighting_file_for_current_scrollpos
3504 proc pop_flist_menu {w X Y x y} {
3505 global ctext cflist cmitmode flist_menu flist_menu_file
3506 global treediffs diffids
3509 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3511 if {$cmitmode eq "tree"} {
3512 set e [linetoelt $l]
3513 if {[string index $e end] eq "/"} return
3515 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3517 set flist_menu_file $e
3518 set xdiffstate "normal"
3519 if {$cmitmode eq "tree"} {
3520 set xdiffstate "disabled"
3522 # Disable "External diff" item in tree mode
3523 $flist_menu entryconf 2 -state $xdiffstate
3524 tk_popup $flist_menu $X $Y
3527 proc find_ctext_fileinfo {line} {
3528 global ctext_file_names ctext_file_lines
3530 set ok [bsearch $ctext_file_lines $line]
3531 set tline [lindex $ctext_file_lines $ok]
3533 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3536 return [list [lindex $ctext_file_names $ok] $tline]
3540 proc pop_diff_menu {w X Y x y} {
3541 global ctext diff_menu flist_menu_file
3542 global diff_menu_txtpos diff_menu_line
3543 global diff_menu_filebase
3545 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3546 set diff_menu_line [lindex $diff_menu_txtpos 0]
3547 # don't pop up the menu on hunk-separator or file-separator lines
3548 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3552 set f [find_ctext_fileinfo $diff_menu_line]
3553 if {$f eq {}} return
3554 set flist_menu_file [lindex $f 0]
3555 set diff_menu_filebase [lindex $f 1]
3556 tk_popup $diff_menu $X $Y
3559 proc flist_hl {only} {
3560 global flist_menu_file findstring gdttype
3562 set x [shellquote $flist_menu_file]
3563 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3566 append findstring " " $x
3568 set gdttype [mc "touching paths:"]
3571 proc gitknewtmpdir {} {
3572 global diffnum gitktmpdir gitdir env
3574 if {![info exists gitktmpdir]} {
3575 if {[info exists env(GITK_TMPDIR)]} {
3576 set tmpdir $env(GITK_TMPDIR)
3577 } elseif {[info exists env(TMPDIR)]} {
3578 set tmpdir $env(TMPDIR)
3582 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
3583 if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} {
3584 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3586 if {[catch {file mkdir $gitktmpdir} err]} {
3587 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3594 set diffdir [file join $gitktmpdir $diffnum]
3595 if {[catch {file mkdir $diffdir} err]} {
3596 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3602 proc save_file_from_commit {filename output what} {
3605 if {[catch {exec git show $filename -- > $output} err]} {
3606 if {[string match "fatal: bad revision *" $err]} {
3609 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3615 proc external_diff_get_one_file {diffid filename diffdir} {
3616 global nullid nullid2 nullfile
3619 if {$diffid == $nullid} {
3620 set difffile [file join $worktree $filename]
3621 if {[file exists $difffile]} {
3626 if {$diffid == $nullid2} {
3627 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3628 return [save_file_from_commit :$filename $difffile index]
3630 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3631 return [save_file_from_commit $diffid:$filename $difffile \
3635 proc external_diff {} {
3636 global nullid nullid2
3637 global flist_menu_file
3641 if {[llength $diffids] == 1} {
3642 # no reference commit given
3643 set diffidto [lindex $diffids 0]
3644 if {$diffidto eq $nullid} {
3645 # diffing working copy with index
3646 set diffidfrom $nullid2
3647 } elseif {$diffidto eq $nullid2} {
3648 # diffing index with HEAD
3649 set diffidfrom "HEAD"
3651 # use first parent commit
3652 global parentlist selectedline
3653 set diffidfrom [lindex $parentlist $selectedline 0]
3656 set diffidfrom [lindex $diffids 0]
3657 set diffidto [lindex $diffids 1]
3660 # make sure that several diffs wont collide
3661 set diffdir [gitknewtmpdir]
3662 if {$diffdir eq {}} return
3664 # gather files to diff
3665 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3666 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3668 if {$difffromfile ne {} && $difftofile ne {}} {
3669 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3670 if {[catch {set fl [open |$cmd r]} err]} {
3671 file delete -force $diffdir
3672 error_popup "$extdifftool: [mc "command failed:"] $err"
3674 fconfigure $fl -blocking 0
3675 filerun $fl [list delete_at_eof $fl $diffdir]
3680 proc find_hunk_blamespec {base line} {
3683 # Find and parse the hunk header
3684 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3685 if {$s_lix eq {}} return
3687 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3688 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3689 s_line old_specs osz osz1 new_line nsz]} {
3693 # base lines for the parents
3694 set base_lines [list $new_line]
3695 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3696 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3697 old_spec old_line osz]} {
3700 lappend base_lines $old_line
3703 # Now scan the lines to determine offset within the hunk
3704 set max_parent [expr {[llength $base_lines]-2}]
3706 set s_lno [lindex [split $s_lix "."] 0]
3708 # Determine if the line is removed
3709 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3710 if {[string match {[-+ ]*} $chunk]} {
3711 set removed_idx [string first "-" $chunk]
3712 # Choose a parent index
3713 if {$removed_idx >= 0} {
3714 set parent $removed_idx
3716 set unchanged_idx [string first " " $chunk]
3717 if {$unchanged_idx >= 0} {
3718 set parent $unchanged_idx
3720 # blame the current commit
3724 # then count other lines that belong to it
3725 for {set i $line} {[incr i -1] > $s_lno} {} {
3726 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3727 # Determine if the line is removed
3728 set removed_idx [string first "-" $chunk]
3730 set code [string index $chunk $parent]
3731 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3735 if {$removed_idx < 0} {
3745 incr dline [lindex $base_lines $parent]
3746 return [list $parent $dline]
3749 proc external_blame_diff {} {
3750 global currentid cmitmode
3751 global diff_menu_txtpos diff_menu_line
3752 global diff_menu_filebase flist_menu_file
3754 if {$cmitmode eq "tree"} {
3756 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3758 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3760 set parent_idx [lindex $hinfo 0]
3761 set line [lindex $hinfo 1]
3768 external_blame $parent_idx $line
3771 # Find the SHA1 ID of the blob for file $fname in the index
3773 proc index_sha1 {fname} {
3774 set f [open [list | git ls-files -s $fname] r]
3775 while {[gets $f line] >= 0} {
3776 set info [lindex [split $line "\t"] 0]
3777 set stage [lindex $info 2]
3778 if {$stage eq "0" || $stage eq "2"} {
3780 return [lindex $info 1]
3787 # Turn an absolute path into one relative to the current directory
3788 proc make_relative {f} {
3789 if {[file pathtype $f] eq "relative"} {
3792 set elts [file split $f]
3793 set here [file split [pwd]]
3798 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3805 set elts [concat $res [lrange $elts $ei end]]
3806 return [eval file join $elts]
3809 proc external_blame {parent_idx {line {}}} {
3810 global flist_menu_file cdup
3811 global nullid nullid2
3812 global parentlist selectedline currentid
3814 if {$parent_idx > 0} {
3815 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3817 set base_commit $currentid
3820 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3821 error_popup [mc "No such commit"]
3825 set cmdline [list git gui blame]
3826 if {$line ne {} && $line > 1} {
3827 lappend cmdline "--line=$line"
3829 set f [file join $cdup $flist_menu_file]
3830 # Unfortunately it seems git gui blame doesn't like
3831 # being given an absolute path...
3832 set f [make_relative $f]
3833 lappend cmdline $base_commit $f
3834 if {[catch {eval exec $cmdline &} err]} {
3835 error_popup "[mc "git gui blame: command failed:"] $err"
3839 proc show_line_source {} {
3840 global cmitmode currentid parents curview blamestuff blameinst
3841 global diff_menu_line diff_menu_filebase flist_menu_file
3842 global nullid nullid2 gitdir cdup
3845 if {$cmitmode eq "tree"} {
3847 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3849 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3850 if {$h eq {}} return
3851 set pi [lindex $h 0]
3853 mark_ctext_line $diff_menu_line
3857 if {$currentid eq $nullid} {
3859 # must be a merge in progress...
3861 # get the last line from .git/MERGE_HEAD
3862 set f [open [file join $gitdir MERGE_HEAD] r]
3863 set id [lindex [split [read $f] "\n"] end-1]
3866 error_popup [mc "Couldn't read merge head: %s" $err]
3869 } elseif {$parents($curview,$currentid) eq $nullid2} {
3870 # need to do the blame from the index
3872 set from_index [index_sha1 $flist_menu_file]
3874 error_popup [mc "Error reading index: %s" $err]
3878 set id $parents($curview,$currentid)
3881 set id [lindex $parents($curview,$currentid) $pi]
3883 set line [lindex $h 1]
3886 if {$from_index ne {}} {
3887 lappend blameargs | git cat-file blob $from_index
3889 lappend blameargs | git blame -p -L$line,+1
3890 if {$from_index ne {}} {
3891 lappend blameargs --contents -
3893 lappend blameargs $id
3895 lappend blameargs -- [file join $cdup $flist_menu_file]
3897 set f [open $blameargs r]
3899 error_popup [mc "Couldn't start git blame: %s" $err]
3902 nowbusy blaming [mc "Searching"]
3903 fconfigure $f -blocking 0
3904 set i [reg_instance $f]
3905 set blamestuff($i) {}
3907 filerun $f [list read_line_source $f $i]
3910 proc stopblaming {} {
3913 if {[info exists blameinst]} {
3914 stop_instance $blameinst
3920 proc read_line_source {fd inst} {
3921 global blamestuff curview commfd blameinst nullid nullid2
3923 while {[gets $fd line] >= 0} {
3924 lappend blamestuff($inst) $line
3932 fconfigure $fd -blocking 1
3933 if {[catch {close $fd} err]} {
3934 error_popup [mc "Error running git blame: %s" $err]
3939 set line [split [lindex $blamestuff($inst) 0] " "]
3940 set id [lindex $line 0]
3941 set lnum [lindex $line 1]
3942 if {[string length $id] == 40 && [string is xdigit $id] &&
3943 [string is digit -strict $lnum]} {
3944 # look for "filename" line
3945 foreach l $blamestuff($inst) {
3946 if {[string match "filename *" $l]} {
3947 set fname [string range $l 9 end]
3953 # all looks good, select it
3954 if {$id eq $nullid} {
3955 # blame uses all-zeroes to mean not committed,
3956 # which would mean a change in the index
3959 if {[commitinview $id $curview]} {
3960 selectline [rowofcommit $id] 1 [list $fname $lnum] 1
3962 error_popup [mc "That line comes from commit %s, \
3963 which is not in this view" [shortids $id]]
3966 puts "oops couldn't parse git blame output"
3971 # delete $dir when we see eof on $f (presumably because the child has exited)
3972 proc delete_at_eof {f dir} {
3973 while {[gets $f line] >= 0} {}
3975 if {[catch {close $f} err]} {
3976 error_popup "[mc "External diff viewer failed:"] $err"
3978 file delete -force $dir
3984 # Functions for adding and removing shell-type quoting
3986 proc shellquote {str} {
3987 if {![string match "*\['\"\\ \t]*" $str]} {
3990 if {![string match "*\['\"\\]*" $str]} {
3993 if {![string match "*'*" $str]} {
3996 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3999 proc shellarglist {l} {
4005 append str [shellquote $a]
4010 proc shelldequote {str} {
4015 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
4016 append ret [string range $str $used end]
4017 set used [string length $str]
4020 set first [lindex $first 0]
4021 set ch [string index $str $first]
4022 if {$first > $used} {
4023 append ret [string range $str $used [expr {$first - 1}]]
4026 if {$ch eq " " || $ch eq "\t"} break
4029 set first [string first "'" $str $used]
4031 error "unmatched single-quote"
4033 append ret [string range $str $used [expr {$first - 1}]]
4038 if {$used >= [string length $str]} {
4039 error "trailing backslash"
4041 append ret [string index $str $used]
4046 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
4047 error "unmatched double-quote"
4049 set first [lindex $first 0]
4050 set ch [string index $str $first]
4051 if {$first > $used} {
4052 append ret [string range $str $used [expr {$first - 1}]]
4055 if {$ch eq "\""} break
4057 append ret [string index $str $used]
4061 return [list $used $ret]
4064 proc shellsplit {str} {
4067 set str [string trimleft $str]
4068 if {$str eq {}} break
4069 set dq [shelldequote $str]
4070 set n [lindex $dq 0]
4071 set word [lindex $dq 1]
4072 set str [string range $str $n end]
4078 proc set_window_title {} {
4079 global appname curview viewname vrevs
4080 set rev [mc "All files"]
4081 if {$curview ne 0} {
4082 if {$viewname($curview) eq [mc "Command line"]} {
4083 set rev [string map {"--gitk-symmetric-diff-marker" "--merge"} $vrevs($curview)]
4085 set rev $viewname($curview)
4088 wm title . "[reponame]: $rev - $appname"
4091 # Code to implement multiple views
4093 proc newview {ishighlight} {
4094 global nextviewnum newviewname newishighlight
4095 global revtreeargs viewargscmd newviewopts curview
4097 set newishighlight $ishighlight
4099 if {[winfo exists $top]} {
4103 decode_view_opts $nextviewnum $revtreeargs
4104 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
4105 set newviewopts($nextviewnum,perm) 0
4106 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
4107 vieweditor $top $nextviewnum [mc "Gitk view definition"]
4110 set known_view_options {
4111 {perm b . {} {mc "Remember this view"}}
4112 {reflabel l + {} {mc "References (space separated list):"}}
4113 {refs t15 .. {} {mc "Branches & tags:"}}
4114 {allrefs b *. "--all" {mc "All refs"}}
4115 {branches b . "--branches" {mc "All (local) branches"}}
4116 {tags b . "--tags" {mc "All tags"}}
4117 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
4118 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
4119 {author t15 .. "--author=*" {mc "Author:"}}
4120 {committer t15 . "--committer=*" {mc "Committer:"}}
4121 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
4122 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
4123 {igrep b .. "--invert-grep" {mc "Matches no Commit Info criteria"}}
4124 {changes_l l + {} {mc "Changes to Files:"}}
4125 {pickaxe_s r0 . {} {mc "Fixed String"}}
4126 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
4127 {pickaxe t15 .. "-S*" {mc "Search string:"}}
4128 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
4129 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
4130 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
4131 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
4132 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
4133 {skip t10 . "--skip=*" {mc "Number to skip:"}}
4134 {misc_lbl l + {} {mc "Miscellaneous options:"}}
4135 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
4136 {lright b . "--left-right" {mc "Mark branch sides"}}
4137 {first b . "--first-parent" {mc "Limit to first parent"}}
4138 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
4139 {args t50 *. {} {mc "Additional arguments to git log:"}}
4140 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4141 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4144 # Convert $newviewopts($n, ...) into args for git log.
4145 proc encode_view_opts {n} {
4146 global known_view_options newviewopts
4149 foreach opt $known_view_options {
4150 set patterns [lindex $opt 3]
4151 if {$patterns eq {}} continue
4152 set pattern [lindex $patterns 0]
4154 if {[lindex $opt 1] eq "b"} {
4155 set val $newviewopts($n,[lindex $opt 0])
4157 lappend rargs $pattern
4159 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4160 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4161 set val $newviewopts($n,$button_id)
4162 if {$val eq $value} {
4163 lappend rargs $pattern
4166 set val $newviewopts($n,[lindex $opt 0])
4167 set val [string trim $val]
4169 set pfix [string range $pattern 0 end-1]
4170 lappend rargs $pfix$val
4174 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4175 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4178 # Fill $newviewopts($n, ...) based on args for git log.
4179 proc decode_view_opts {n view_args} {
4180 global known_view_options newviewopts
4182 foreach opt $known_view_options {
4183 set id [lindex $opt 0]
4184 if {[lindex $opt 1] eq "b"} {
4187 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4189 regexp {^(.*_)} $id uselessvar id
4195 set newviewopts($n,$id) $val
4199 foreach arg $view_args {
4200 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4201 && ![info exists found(limit)]} {
4202 set newviewopts($n,limit) $cnt
4207 foreach opt $known_view_options {
4208 set id [lindex $opt 0]
4209 if {[info exists found($id)]} continue
4210 foreach pattern [lindex $opt 3] {
4211 if {![string match $pattern $arg]} continue
4212 if {[lindex $opt 1] eq "b"} {
4215 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4217 regexp {^(.*_)} $id uselessvar id
4221 set size [string length $pattern]
4222 set val [string range $arg [expr {$size-1}] end]
4224 set newviewopts($n,$id) $val
4228 if {[info exists val]} break
4230 if {[info exists val]} continue
4231 if {[regexp {^-} $arg]} {
4234 lappend refargs $arg
4237 set newviewopts($n,refs) [shellarglist $refargs]
4238 set newviewopts($n,args) [shellarglist $oargs]
4241 proc edit_or_newview {} {
4253 global viewname viewperm newviewname newviewopts
4254 global viewargs viewargscmd
4256 set top .gitkvedit-$curview
4257 if {[winfo exists $top]} {
4261 decode_view_opts $curview $viewargs($curview)
4262 set newviewname($curview) $viewname($curview)
4263 set newviewopts($curview,perm) $viewperm($curview)
4264 set newviewopts($curview,cmd) $viewargscmd($curview)
4265 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4268 proc vieweditor {top n title} {
4269 global newviewname newviewopts viewfiles bgcolor
4270 global known_view_options NS
4273 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4274 make_transient $top .
4277 ${NS}::frame $top.nfr
4278 ${NS}::label $top.nl -text [mc "View Name"]
4279 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4280 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4281 pack $top.nl -in $top.nfr -side left -padx {0 5}
4282 pack $top.name -in $top.nfr -side left -padx {0 25}
4288 foreach opt $known_view_options {
4289 set id [lindex $opt 0]
4290 set type [lindex $opt 1]
4291 set flags [lindex $opt 2]
4292 set title [eval [lindex $opt 4]]
4295 if {$flags eq "+" || $flags eq "*"} {
4296 set cframe $top.fr$cnt
4298 ${NS}::frame $cframe
4299 pack $cframe -in $top -fill x -pady 3 -padx 3
4300 set cexpand [expr {$flags eq "*"}]
4301 } elseif {$flags eq ".." || $flags eq "*."} {
4302 set cframe $top.fr$cnt
4304 ${NS}::frame $cframe
4305 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4306 set cexpand [expr {$flags eq "*."}]
4312 ${NS}::label $cframe.l_$id -text $title
4313 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4314 } elseif {$type eq "b"} {
4315 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4316 pack $cframe.c_$id -in $cframe -side left \
4317 -padx [list $lxpad 0] -expand $cexpand -anchor w
4318 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4319 regexp {^(.*_)} $id uselessvar button_id
4320 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4321 pack $cframe.c_$id -in $cframe -side left \
4322 -padx [list $lxpad 0] -expand $cexpand -anchor w
4323 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4324 ${NS}::label $cframe.l_$id -text $title
4325 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4326 -textvariable newviewopts($n,$id)
4327 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4328 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4329 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4330 ${NS}::label $cframe.l_$id -text $title
4331 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4332 -textvariable newviewopts($n,$id)
4333 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4334 pack $cframe.e_$id -in $cframe -side top -fill x
4335 } elseif {$type eq "path"} {
4336 ${NS}::label $top.l -text $title
4337 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4338 text $top.t -width 40 -height 5 -background $bgcolor
4339 if {[info exists viewfiles($n)]} {
4340 foreach f $viewfiles($n) {
4341 $top.t insert end $f
4342 $top.t insert end "\n"
4344 $top.t delete {end - 1c} end
4345 $top.t mark set insert 0.0
4347 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4351 ${NS}::frame $top.buts
4352 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4353 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4354 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4355 bind $top <Control-Return> [list newviewok $top $n]
4356 bind $top <F5> [list newviewok $top $n 1]
4357 bind $top <Escape> [list destroy $top]
4358 grid $top.buts.ok $top.buts.apply $top.buts.can
4359 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4360 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4361 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4362 pack $top.buts -in $top -side top -fill x
4366 proc doviewmenu {m first cmd op argv} {
4367 set nmenu [$m index end]
4368 for {set i $first} {$i <= $nmenu} {incr i} {
4369 if {[$m entrycget $i -command] eq $cmd} {
4370 eval $m $op $i $argv
4376 proc allviewmenus {n op args} {
4379 doviewmenu .bar.view 5 [list showview $n] $op $args
4380 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4383 proc newviewok {top n {apply 0}} {
4384 global nextviewnum newviewperm newviewname newishighlight
4385 global viewname viewfiles viewperm viewchanged selectedview curview
4386 global viewargs viewargscmd newviewopts viewhlmenu
4389 set newargs [encode_view_opts $n]
4391 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4395 foreach f [split [$top.t get 0.0 end] "\n"] {
4396 set ft [string trim $f]
4401 if {![info exists viewfiles($n)]} {
4402 # creating a new view
4404 set viewname($n) $newviewname($n)
4405 set viewperm($n) $newviewopts($n,perm)
4406 set viewchanged($n) 1
4407 set viewfiles($n) $files
4408 set viewargs($n) $newargs
4409 set viewargscmd($n) $newviewopts($n,cmd)
4411 if {!$newishighlight} {
4414 run addvhighlight $n
4417 # editing an existing view
4418 set viewperm($n) $newviewopts($n,perm)
4419 set viewchanged($n) 1
4420 if {$newviewname($n) ne $viewname($n)} {
4421 set viewname($n) $newviewname($n)
4422 doviewmenu .bar.view 5 [list showview $n] \
4423 entryconf [list -label $viewname($n)]
4424 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4425 # entryconf [list -label $viewname($n) -value $viewname($n)]
4427 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4428 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4429 set viewfiles($n) $files
4430 set viewargs($n) $newargs
4431 set viewargscmd($n) $newviewopts($n,cmd)
4432 if {$curview == $n} {
4438 catch {destroy $top}
4442 global curview viewperm hlview selectedhlview viewchanged
4444 if {$curview == 0} return
4445 if {[info exists hlview] && $hlview == $curview} {
4446 set selectedhlview [mc "None"]
4449 allviewmenus $curview delete
4450 set viewperm($curview) 0
4451 set viewchanged($curview) 1
4455 proc addviewmenu {n} {
4456 global viewname viewhlmenu
4458 .bar.view add radiobutton -label $viewname($n) \
4459 -command [list showview $n] -variable selectedview -value $n
4460 #$viewhlmenu add radiobutton -label $viewname($n) \
4461 # -command [list addvhighlight $n] -variable selectedhlview
4465 global curview cached_commitrow ordertok
4466 global displayorder parentlist rowidlist rowisopt rowfinal
4467 global colormap rowtextx nextcolor canvxmax
4468 global numcommits viewcomplete
4469 global selectedline currentid canv canvy0
4471 global pending_select mainheadid
4474 global hlview selectedhlview commitinterest
4476 if {$n == $curview} return
4478 set ymax [lindex [$canv cget -scrollregion] 3]
4479 set span [$canv yview]
4480 set ytop [expr {[lindex $span 0] * $ymax}]
4481 set ybot [expr {[lindex $span 1] * $ymax}]
4482 set yscreen [expr {($ybot - $ytop) / 2}]
4483 if {$selectedline ne {}} {
4484 set selid $currentid
4485 set y [yc $selectedline]
4486 if {$ytop < $y && $y < $ybot} {
4487 set yscreen [expr {$y - $ytop}]
4489 } elseif {[info exists pending_select]} {
4490 set selid $pending_select
4491 unset pending_select
4495 unset -nocomplain treediffs
4497 if {[info exists hlview] && $hlview == $n} {
4499 set selectedhlview [mc "None"]
4501 unset -nocomplain commitinterest
4502 unset -nocomplain cached_commitrow
4503 unset -nocomplain ordertok
4507 .bar.view entryconf [mca "&Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4508 .bar.view entryconf [mca "&Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4511 if {![info exists viewcomplete($n)]} {
4521 set numcommits $commitidx($n)
4523 unset -nocomplain colormap
4524 unset -nocomplain rowtextx
4526 set canvxmax [$canv cget -width]
4532 if {$selid ne {} && [commitinview $selid $n]} {
4533 set row [rowofcommit $selid]
4534 # try to get the selected row in the same position on the screen
4535 set ymax [lindex [$canv cget -scrollregion] 3]
4536 set ytop [expr {[yc $row] - $yscreen}]
4540 set yf [expr {$ytop * 1.0 / $ymax}]
4542 allcanvs yview moveto $yf
4546 } elseif {!$viewcomplete($n)} {
4547 reset_pending_select $selid
4549 reset_pending_select {}
4551 if {[commitinview $pending_select $curview]} {
4552 selectline [rowofcommit $pending_select] 1
4554 set row [first_real_row]
4555 if {$row < $numcommits} {
4560 if {!$viewcomplete($n)} {
4561 if {$numcommits == 0} {
4562 show_status [mc "Reading commits..."]
4564 } elseif {$numcommits == 0} {
4565 show_status [mc "No commits selected"]
4570 # Stuff relating to the highlighting facility
4572 proc ishighlighted {id} {
4573 global vhighlights fhighlights nhighlights rhighlights
4575 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4576 return $nhighlights($id)
4578 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4579 return $vhighlights($id)
4581 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4582 return $fhighlights($id)
4584 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4585 return $rhighlights($id)
4590 proc bolden {id font} {
4591 global canv linehtag currentid boldids need_redisplay markedid
4593 # need_redisplay = 1 means the display is stale and about to be redrawn
4594 if {$need_redisplay} return
4596 $canv itemconf $linehtag($id) -font $font
4597 if {[info exists currentid] && $id eq $currentid} {
4599 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4600 -outline {{}} -tags secsel \
4601 -fill [$canv cget -selectbackground]]
4604 if {[info exists markedid] && $id eq $markedid} {
4609 proc bolden_name {id font} {
4610 global canv2 linentag currentid boldnameids need_redisplay
4612 if {$need_redisplay} return
4613 lappend boldnameids $id
4614 $canv2 itemconf $linentag($id) -font $font
4615 if {[info exists currentid] && $id eq $currentid} {
4616 $canv2 delete secsel
4617 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4618 -outline {{}} -tags secsel \
4619 -fill [$canv2 cget -selectbackground]]
4628 foreach id $boldids {
4629 if {![ishighlighted $id]} {
4632 lappend stillbold $id
4635 set boldids $stillbold
4638 proc addvhighlight {n} {
4639 global hlview viewcomplete curview vhl_done commitidx
4641 if {[info exists hlview]} {
4645 if {$n != $curview && ![info exists viewcomplete($n)]} {
4648 set vhl_done $commitidx($hlview)
4649 if {$vhl_done > 0} {
4654 proc delvhighlight {} {
4655 global hlview vhighlights
4657 if {![info exists hlview]} return
4659 unset -nocomplain vhighlights
4663 proc vhighlightmore {} {
4664 global hlview vhl_done commitidx vhighlights curview
4666 set max $commitidx($hlview)
4667 set vr [visiblerows]
4668 set r0 [lindex $vr 0]
4669 set r1 [lindex $vr 1]
4670 for {set i $vhl_done} {$i < $max} {incr i} {
4671 set id [commitonrow $i $hlview]
4672 if {[commitinview $id $curview]} {
4673 set row [rowofcommit $id]
4674 if {$r0 <= $row && $row <= $r1} {
4675 if {![highlighted $row]} {
4676 bolden $id mainfontbold
4678 set vhighlights($id) 1
4686 proc askvhighlight {row id} {
4687 global hlview vhighlights iddrawn
4689 if {[commitinview $id $hlview]} {
4690 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4691 bolden $id mainfontbold
4693 set vhighlights($id) 1
4695 set vhighlights($id) 0
4699 proc hfiles_change {} {
4700 global highlight_files filehighlight fhighlights fh_serial
4701 global highlight_paths
4703 if {[info exists filehighlight]} {
4704 # delete previous highlights
4705 catch {close $filehighlight}
4707 unset -nocomplain fhighlights
4709 unhighlight_filelist
4711 set highlight_paths {}
4712 after cancel do_file_hl $fh_serial
4714 if {$highlight_files ne {}} {
4715 after 300 do_file_hl $fh_serial
4719 proc gdttype_change {name ix op} {
4720 global gdttype highlight_files findstring findpattern
4723 if {$findstring ne {}} {
4724 if {$gdttype eq [mc "containing:"]} {
4725 if {$highlight_files ne {}} {
4726 set highlight_files {}
4731 if {$findpattern ne {}} {
4735 set highlight_files $findstring
4740 # enable/disable findtype/findloc menus too
4743 proc find_change {name ix op} {
4744 global gdttype findstring highlight_files
4747 if {$gdttype eq [mc "containing:"]} {
4750 if {$highlight_files ne $findstring} {
4751 set highlight_files $findstring
4758 proc findcom_change args {
4759 global nhighlights boldnameids
4760 global findpattern findtype findstring gdttype
4763 # delete previous highlights, if any
4764 foreach id $boldnameids {
4765 bolden_name $id mainfont
4768 unset -nocomplain nhighlights
4771 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4773 } elseif {$findtype eq [mc "Regexp"]} {
4774 set findpattern $findstring
4776 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4778 set findpattern "*$e*"
4782 proc makepatterns {l} {
4785 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4786 if {[string index $ee end] eq "/"} {
4796 proc do_file_hl {serial} {
4797 global highlight_files filehighlight highlight_paths gdttype fhl_list
4798 global cdup findtype
4800 if {$gdttype eq [mc "touching paths:"]} {
4801 # If "exact" match then convert backslashes to forward slashes.
4802 # Most useful to support Windows-flavoured file paths.
4803 if {$findtype eq [mc "Exact"]} {
4804 set highlight_files [string map {"\\" "/"} $highlight_files]
4806 if {[catch {set paths [shellsplit $highlight_files]}]} return
4807 set highlight_paths [makepatterns $paths]
4809 set relative_paths {}
4810 foreach path $paths {
4811 lappend relative_paths [file join $cdup $path]
4813 set gdtargs [concat -- $relative_paths]
4814 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4815 set gdtargs [list "-S$highlight_files"]
4816 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4817 set gdtargs [list "-G$highlight_files"]
4819 # must be "containing:", i.e. we're searching commit info
4822 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4823 set filehighlight [open $cmd r+]
4824 fconfigure $filehighlight -blocking 0
4825 filerun $filehighlight readfhighlight
4831 proc flushhighlights {} {
4832 global filehighlight fhl_list
4834 if {[info exists filehighlight]} {
4836 puts $filehighlight ""
4837 flush $filehighlight
4841 proc askfilehighlight {row id} {
4842 global filehighlight fhighlights fhl_list
4844 lappend fhl_list $id
4845 set fhighlights($id) -1
4846 puts $filehighlight $id
4849 proc readfhighlight {} {
4850 global filehighlight fhighlights curview iddrawn
4851 global fhl_list find_dirn
4853 if {![info exists filehighlight]} {
4857 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4858 set line [string trim $line]
4859 set i [lsearch -exact $fhl_list $line]
4860 if {$i < 0} continue
4861 for {set j 0} {$j < $i} {incr j} {
4862 set id [lindex $fhl_list $j]
4863 set fhighlights($id) 0
4865 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4866 if {$line eq {}} continue
4867 if {![commitinview $line $curview]} continue
4868 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4869 bolden $line mainfontbold
4871 set fhighlights($line) 1
4873 if {[eof $filehighlight]} {
4875 puts "oops, git diff-tree died"
4876 catch {close $filehighlight}
4880 if {[info exists find_dirn]} {
4886 proc doesmatch {f} {
4887 global findtype findpattern
4889 if {$findtype eq [mc "Regexp"]} {
4890 return [regexp $findpattern $f]
4891 } elseif {$findtype eq [mc "IgnCase"]} {
4892 return [string match -nocase $findpattern $f]
4894 return [string match $findpattern $f]
4898 proc askfindhighlight {row id} {
4899 global nhighlights commitinfo iddrawn
4901 global markingmatches
4903 if {![info exists commitinfo($id)]} {
4906 set info $commitinfo($id)
4908 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4909 foreach f $info ty $fldtypes {
4910 if {$ty eq ""} continue
4911 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4913 if {$ty eq [mc "Author"]} {
4920 if {$isbold && [info exists iddrawn($id)]} {
4921 if {![ishighlighted $id]} {
4922 bolden $id mainfontbold
4924 bolden_name $id mainfontbold
4927 if {$markingmatches} {
4928 markrowmatches $row $id
4931 set nhighlights($id) $isbold
4934 proc markrowmatches {row id} {
4935 global canv canv2 linehtag linentag commitinfo findloc
4937 set headline [lindex $commitinfo($id) 0]
4938 set author [lindex $commitinfo($id) 1]
4939 $canv delete match$row
4940 $canv2 delete match$row
4941 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4942 set m [findmatches $headline]
4944 markmatches $canv $row $headline $linehtag($id) $m \
4945 [$canv itemcget $linehtag($id) -font] $row
4948 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4949 set m [findmatches $author]
4951 markmatches $canv2 $row $author $linentag($id) $m \
4952 [$canv2 itemcget $linentag($id) -font] $row
4957 proc vrel_change {name ix op} {
4958 global highlight_related
4961 if {$highlight_related ne [mc "None"]} {
4966 # prepare for testing whether commits are descendents or ancestors of a
4967 proc rhighlight_sel {a} {
4968 global descendent desc_todo ancestor anc_todo
4969 global highlight_related
4971 unset -nocomplain descendent
4972 set desc_todo [list $a]
4973 unset -nocomplain ancestor
4974 set anc_todo [list $a]
4975 if {$highlight_related ne [mc "None"]} {
4981 proc rhighlight_none {} {
4984 unset -nocomplain rhighlights
4988 proc is_descendent {a} {
4989 global curview children descendent desc_todo
4992 set la [rowofcommit $a]
4996 for {set i 0} {$i < [llength $todo]} {incr i} {
4997 set do [lindex $todo $i]
4998 if {[rowofcommit $do] < $la} {
4999 lappend leftover $do
5002 foreach nk $children($v,$do) {
5003 if {![info exists descendent($nk)]} {
5004 set descendent($nk) 1
5012 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
5016 set descendent($a) 0
5017 set desc_todo $leftover
5020 proc is_ancestor {a} {
5021 global curview parents ancestor anc_todo
5024 set la [rowofcommit $a]
5028 for {set i 0} {$i < [llength $todo]} {incr i} {
5029 set do [lindex $todo $i]
5030 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
5031 lappend leftover $do
5034 foreach np $parents($v,$do) {
5035 if {![info exists ancestor($np)]} {
5044 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
5049 set anc_todo $leftover
5052 proc askrelhighlight {row id} {
5053 global descendent highlight_related iddrawn rhighlights
5054 global selectedline ancestor
5056 if {$selectedline eq {}} return
5058 if {$highlight_related eq [mc "Descendant"] ||
5059 $highlight_related eq [mc "Not descendant"]} {
5060 if {![info exists descendent($id)]} {
5063 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
5066 } elseif {$highlight_related eq [mc "Ancestor"] ||
5067 $highlight_related eq [mc "Not ancestor"]} {
5068 if {![info exists ancestor($id)]} {
5071 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
5075 if {[info exists iddrawn($id)]} {
5076 if {$isbold && ![ishighlighted $id]} {
5077 bolden $id mainfontbold
5080 set rhighlights($id) $isbold
5083 # Graph layout functions
5085 proc shortids {ids} {
5088 if {[llength $id] > 1} {
5089 lappend res [shortids $id]
5090 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
5091 lappend res [string range $id 0 7]
5102 for {set mask 1} {$mask <= $n} {incr mask $mask} {
5103 if {($n & $mask) != 0} {
5104 set ret [concat $ret $o]
5106 set o [concat $o $o]
5111 proc ordertoken {id} {
5112 global ordertok curview varcid varcstart varctok curview parents children
5113 global nullid nullid2
5115 if {[info exists ordertok($id)]} {
5116 return $ordertok($id)
5121 if {[info exists varcid($curview,$id)]} {
5122 set a $varcid($curview,$id)
5123 set p [lindex $varcstart($curview) $a]
5125 set p [lindex $children($curview,$id) 0]
5127 if {[info exists ordertok($p)]} {
5128 set tok $ordertok($p)
5131 set id [first_real_child $curview,$p]
5134 set tok [lindex $varctok($curview) $varcid($curview,$p)]
5137 if {[llength $parents($curview,$id)] == 1} {
5138 lappend todo [list $p {}]
5140 set j [lsearch -exact $parents($curview,$id) $p]
5142 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5144 lappend todo [list $p [strrep $j]]
5147 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5148 set p [lindex $todo $i 0]
5149 append tok [lindex $todo $i 1]
5150 set ordertok($p) $tok
5152 set ordertok($origid) $tok
5156 # Work out where id should go in idlist so that order-token
5157 # values increase from left to right
5158 proc idcol {idlist id {i 0}} {
5159 set t [ordertoken $id]
5163 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5164 if {$i > [llength $idlist]} {
5165 set i [llength $idlist]
5167 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5170 if {$t > [ordertoken [lindex $idlist $i]]} {
5171 while {[incr i] < [llength $idlist] &&
5172 $t >= [ordertoken [lindex $idlist $i]]} {}
5178 proc initlayout {} {
5179 global rowidlist rowisopt rowfinal displayorder parentlist
5180 global numcommits canvxmax canv
5182 global colormap rowtextx
5191 set canvxmax [$canv cget -width]
5192 unset -nocomplain colormap
5193 unset -nocomplain rowtextx
5197 proc setcanvscroll {} {
5198 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5199 global lastscrollset lastscrollrows
5201 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5202 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5203 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5204 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5205 set lastscrollset [clock clicks -milliseconds]
5206 set lastscrollrows $numcommits
5209 proc visiblerows {} {
5210 global canv numcommits linespc
5212 set ymax [lindex [$canv cget -scrollregion] 3]
5213 if {$ymax eq {} || $ymax == 0} return
5215 set y0 [expr {int([lindex $f 0] * $ymax)}]
5216 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5220 set y1 [expr {int([lindex $f 1] * $ymax)}]
5221 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5222 if {$r1 >= $numcommits} {
5223 set r1 [expr {$numcommits - 1}]
5225 return [list $r0 $r1]
5228 proc layoutmore {} {
5229 global commitidx viewcomplete curview
5230 global numcommits pending_select curview
5231 global lastscrollset lastscrollrows
5233 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5234 [clock clicks -milliseconds] - $lastscrollset > 500} {
5237 if {[info exists pending_select] &&
5238 [commitinview $pending_select $curview]} {
5240 selectline [rowofcommit $pending_select] 1
5245 # With path limiting, we mightn't get the actual HEAD commit,
5246 # so ask git rev-list what is the first ancestor of HEAD that
5247 # touches a file in the path limit.
5248 proc get_viewmainhead {view} {
5249 global viewmainheadid vfilelimit viewinstances mainheadid
5252 set rfd [open [concat | git rev-list -1 $mainheadid \
5253 -- $vfilelimit($view)] r]
5254 set j [reg_instance $rfd]
5255 lappend viewinstances($view) $j
5256 fconfigure $rfd -blocking 0
5257 filerun $rfd [list getviewhead $rfd $j $view]
5258 set viewmainheadid($curview) {}
5262 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5263 proc getviewhead {fd inst view} {
5264 global viewmainheadid commfd curview viewinstances showlocalchanges
5267 if {[gets $fd line] < 0} {
5271 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5274 set viewmainheadid($view) $id
5277 set i [lsearch -exact $viewinstances($view) $inst]
5279 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5281 if {$showlocalchanges && $id ne {} && $view == $curview} {
5287 proc doshowlocalchanges {} {
5288 global curview viewmainheadid
5290 if {$viewmainheadid($curview) eq {}} return
5291 if {[commitinview $viewmainheadid($curview) $curview]} {
5294 interestedin $viewmainheadid($curview) dodiffindex
5298 proc dohidelocalchanges {} {
5299 global nullid nullid2 lserial curview
5301 if {[commitinview $nullid $curview]} {
5302 removefakerow $nullid
5304 if {[commitinview $nullid2 $curview]} {
5305 removefakerow $nullid2
5310 # spawn off a process to do git diff-index --cached HEAD
5311 proc dodiffindex {} {
5312 global lserial showlocalchanges vfilelimit curview
5313 global hasworktree git_version
5315 if {!$showlocalchanges || !$hasworktree} return
5317 if {[package vcompare $git_version "1.7.2"] >= 0} {
5318 set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
5320 set cmd "|git diff-index --cached HEAD"
5322 if {$vfilelimit($curview) ne {}} {
5323 set cmd [concat $cmd -- $vfilelimit($curview)]
5325 set fd [open $cmd r]
5326 fconfigure $fd -blocking 0
5327 set i [reg_instance $fd]
5328 filerun $fd [list readdiffindex $fd $lserial $i]
5331 proc readdiffindex {fd serial inst} {
5332 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5336 if {[gets $fd line] < 0} {
5342 # we only need to see one line and we don't really care what it says...
5345 if {$serial != $lserial} {
5349 # now see if there are any local changes not checked in to the index
5350 set cmd "|git diff-files"
5351 if {$vfilelimit($curview) ne {}} {
5352 set cmd [concat $cmd -- $vfilelimit($curview)]
5354 set fd [open $cmd r]
5355 fconfigure $fd -blocking 0
5356 set i [reg_instance $fd]
5357 filerun $fd [list readdifffiles $fd $serial $i]
5359 if {$isdiff && ![commitinview $nullid2 $curview]} {
5360 # add the line for the changes in the index to the graph
5361 set hl [mc "Local changes checked in to index but not committed"]
5362 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5363 set commitdata($nullid2) "\n $hl\n"
5364 if {[commitinview $nullid $curview]} {
5365 removefakerow $nullid
5367 insertfakerow $nullid2 $viewmainheadid($curview)
5368 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5369 if {[commitinview $nullid $curview]} {
5370 removefakerow $nullid
5372 removefakerow $nullid2
5377 proc readdifffiles {fd serial inst} {
5378 global viewmainheadid nullid nullid2 curview
5379 global commitinfo commitdata lserial
5382 if {[gets $fd line] < 0} {
5388 # we only need to see one line and we don't really care what it says...
5391 if {$serial != $lserial} {
5395 if {$isdiff && ![commitinview $nullid $curview]} {
5396 # add the line for the local diff to the graph
5397 set hl [mc "Local uncommitted changes, not checked in to index"]
5398 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5399 set commitdata($nullid) "\n $hl\n"
5400 if {[commitinview $nullid2 $curview]} {
5403 set p $viewmainheadid($curview)
5405 insertfakerow $nullid $p
5406 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5407 removefakerow $nullid
5412 proc nextuse {id row} {
5413 global curview children
5415 if {[info exists children($curview,$id)]} {
5416 foreach kid $children($curview,$id) {
5417 if {![commitinview $kid $curview]} {
5420 if {[rowofcommit $kid] > $row} {
5421 return [rowofcommit $kid]
5425 if {[commitinview $id $curview]} {
5426 return [rowofcommit $id]
5431 proc prevuse {id row} {
5432 global curview children
5435 if {[info exists children($curview,$id)]} {
5436 foreach kid $children($curview,$id) {
5437 if {![commitinview $kid $curview]} break
5438 if {[rowofcommit $kid] < $row} {
5439 set ret [rowofcommit $kid]
5446 proc make_idlist {row} {
5447 global displayorder parentlist uparrowlen downarrowlen mingaplen
5448 global commitidx curview children
5450 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5454 set ra [expr {$row - $downarrowlen}]
5458 set rb [expr {$row + $uparrowlen}]
5459 if {$rb > $commitidx($curview)} {
5460 set rb $commitidx($curview)
5462 make_disporder $r [expr {$rb + 1}]
5464 for {} {$r < $ra} {incr r} {
5465 set nextid [lindex $displayorder [expr {$r + 1}]]
5466 foreach p [lindex $parentlist $r] {
5467 if {$p eq $nextid} continue
5468 set rn [nextuse $p $r]
5470 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5471 lappend ids [list [ordertoken $p] $p]
5475 for {} {$r < $row} {incr r} {
5476 set nextid [lindex $displayorder [expr {$r + 1}]]
5477 foreach p [lindex $parentlist $r] {
5478 if {$p eq $nextid} continue
5479 set rn [nextuse $p $r]
5480 if {$rn < 0 || $rn >= $row} {
5481 lappend ids [list [ordertoken $p] $p]
5485 set id [lindex $displayorder $row]
5486 lappend ids [list [ordertoken $id] $id]
5488 foreach p [lindex $parentlist $r] {
5489 set firstkid [lindex $children($curview,$p) 0]
5490 if {[rowofcommit $firstkid] < $row} {
5491 lappend ids [list [ordertoken $p] $p]
5495 set id [lindex $displayorder $r]
5497 set firstkid [lindex $children($curview,$id) 0]
5498 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5499 lappend ids [list [ordertoken $id] $id]
5504 foreach idx [lsort -unique $ids] {
5505 lappend idlist [lindex $idx 1]
5510 proc rowsequal {a b} {
5511 while {[set i [lsearch -exact $a {}]] >= 0} {
5512 set a [lreplace $a $i $i]
5514 while {[set i [lsearch -exact $b {}]] >= 0} {
5515 set b [lreplace $b $i $i]
5517 return [expr {$a eq $b}]
5520 proc makeupline {id row rend col} {
5521 global rowidlist uparrowlen downarrowlen mingaplen
5523 for {set r $rend} {1} {set r $rstart} {
5524 set rstart [prevuse $id $r]
5525 if {$rstart < 0} return
5526 if {$rstart < $row} break
5528 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5529 set rstart [expr {$rend - $uparrowlen - 1}]
5531 for {set r $rstart} {[incr r] <= $row} {} {
5532 set idlist [lindex $rowidlist $r]
5533 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5534 set col [idcol $idlist $id $col]
5535 lset rowidlist $r [linsert $idlist $col $id]
5541 proc layoutrows {row endrow} {
5542 global rowidlist rowisopt rowfinal displayorder
5543 global uparrowlen downarrowlen maxwidth mingaplen
5544 global children parentlist
5545 global commitidx viewcomplete curview
5547 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5550 set rm1 [expr {$row - 1}]
5551 foreach id [lindex $rowidlist $rm1] {
5556 set final [lindex $rowfinal $rm1]
5558 for {} {$row < $endrow} {incr row} {
5559 set rm1 [expr {$row - 1}]
5560 if {$rm1 < 0 || $idlist eq {}} {
5561 set idlist [make_idlist $row]
5564 set id [lindex $displayorder $rm1]
5565 set col [lsearch -exact $idlist $id]
5566 set idlist [lreplace $idlist $col $col]
5567 foreach p [lindex $parentlist $rm1] {
5568 if {[lsearch -exact $idlist $p] < 0} {
5569 set col [idcol $idlist $p $col]
5570 set idlist [linsert $idlist $col $p]
5571 # if not the first child, we have to insert a line going up
5572 if {$id ne [lindex $children($curview,$p) 0]} {
5573 makeupline $p $rm1 $row $col
5577 set id [lindex $displayorder $row]
5578 if {$row > $downarrowlen} {
5579 set termrow [expr {$row - $downarrowlen - 1}]
5580 foreach p [lindex $parentlist $termrow] {
5581 set i [lsearch -exact $idlist $p]
5582 if {$i < 0} continue
5583 set nr [nextuse $p $termrow]
5584 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5585 set idlist [lreplace $idlist $i $i]
5589 set col [lsearch -exact $idlist $id]
5591 set col [idcol $idlist $id]
5592 set idlist [linsert $idlist $col $id]
5593 if {$children($curview,$id) ne {}} {
5594 makeupline $id $rm1 $row $col
5597 set r [expr {$row + $uparrowlen - 1}]
5598 if {$r < $commitidx($curview)} {
5600 foreach p [lindex $parentlist $r] {
5601 if {[lsearch -exact $idlist $p] >= 0} continue
5602 set fk [lindex $children($curview,$p) 0]
5603 if {[rowofcommit $fk] < $row} {
5604 set x [idcol $idlist $p $x]
5605 set idlist [linsert $idlist $x $p]
5608 if {[incr r] < $commitidx($curview)} {
5609 set p [lindex $displayorder $r]
5610 if {[lsearch -exact $idlist $p] < 0} {
5611 set fk [lindex $children($curview,$p) 0]
5612 if {$fk ne {} && [rowofcommit $fk] < $row} {
5613 set x [idcol $idlist $p $x]
5614 set idlist [linsert $idlist $x $p]
5620 if {$final && !$viewcomplete($curview) &&
5621 $row + $uparrowlen + $mingaplen + $downarrowlen
5622 >= $commitidx($curview)} {
5625 set l [llength $rowidlist]
5627 lappend rowidlist $idlist
5629 lappend rowfinal $final
5630 } elseif {$row < $l} {
5631 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5632 lset rowidlist $row $idlist
5635 lset rowfinal $row $final
5637 set pad [ntimes [expr {$row - $l}] {}]
5638 set rowidlist [concat $rowidlist $pad]
5639 lappend rowidlist $idlist
5640 set rowfinal [concat $rowfinal $pad]
5641 lappend rowfinal $final
5642 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5648 proc changedrow {row} {
5649 global displayorder iddrawn rowisopt need_redisplay
5651 set l [llength $rowisopt]
5653 lset rowisopt $row 0
5654 if {$row + 1 < $l} {
5655 lset rowisopt [expr {$row + 1}] 0
5656 if {$row + 2 < $l} {
5657 lset rowisopt [expr {$row + 2}] 0
5661 set id [lindex $displayorder $row]
5662 if {[info exists iddrawn($id)]} {
5663 set need_redisplay 1
5667 proc insert_pad {row col npad} {
5670 set pad [ntimes $npad {}]
5671 set idlist [lindex $rowidlist $row]
5672 set bef [lrange $idlist 0 [expr {$col - 1}]]
5673 set aft [lrange $idlist $col end]
5674 set i [lsearch -exact $aft {}]
5676 set aft [lreplace $aft $i $i]
5678 lset rowidlist $row [concat $bef $pad $aft]
5682 proc optimize_rows {row col endrow} {
5683 global rowidlist rowisopt displayorder curview children
5688 for {} {$row < $endrow} {incr row; set col 0} {
5689 if {[lindex $rowisopt $row]} continue
5691 set y0 [expr {$row - 1}]
5692 set ym [expr {$row - 2}]
5693 set idlist [lindex $rowidlist $row]
5694 set previdlist [lindex $rowidlist $y0]
5695 if {$idlist eq {} || $previdlist eq {}} continue
5697 set pprevidlist [lindex $rowidlist $ym]
5698 if {$pprevidlist eq {}} continue
5704 for {} {$col < [llength $idlist]} {incr col} {
5705 set id [lindex $idlist $col]
5706 if {[lindex $previdlist $col] eq $id} continue
5711 set x0 [lsearch -exact $previdlist $id]
5712 if {$x0 < 0} continue
5713 set z [expr {$x0 - $col}]
5717 set xm [lsearch -exact $pprevidlist $id]
5719 set z0 [expr {$xm - $x0}]
5723 # if row y0 is the first child of $id then it's not an arrow
5724 if {[lindex $children($curview,$id) 0] ne
5725 [lindex $displayorder $y0]} {
5729 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5730 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5733 # Looking at lines from this row to the previous row,
5734 # make them go straight up if they end in an arrow on
5735 # the previous row; otherwise make them go straight up
5737 if {$z < -1 || ($z < 0 && $isarrow)} {
5738 # Line currently goes left too much;
5739 # insert pads in the previous row, then optimize it
5740 set npad [expr {-1 - $z + $isarrow}]
5741 insert_pad $y0 $x0 $npad
5743 optimize_rows $y0 $x0 $row
5745 set previdlist [lindex $rowidlist $y0]
5746 set x0 [lsearch -exact $previdlist $id]
5747 set z [expr {$x0 - $col}]
5749 set pprevidlist [lindex $rowidlist $ym]
5750 set xm [lsearch -exact $pprevidlist $id]
5751 set z0 [expr {$xm - $x0}]
5753 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5754 # Line currently goes right too much;
5755 # insert pads in this line
5756 set npad [expr {$z - 1 + $isarrow}]
5757 insert_pad $row $col $npad
5758 set idlist [lindex $rowidlist $row]
5760 set z [expr {$x0 - $col}]
5763 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5764 # this line links to its first child on row $row-2
5765 set id [lindex $displayorder $ym]
5766 set xc [lsearch -exact $pprevidlist $id]
5768 set z0 [expr {$xc - $x0}]
5771 # avoid lines jigging left then immediately right
5772 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5773 insert_pad $y0 $x0 1
5775 optimize_rows $y0 $x0 $row
5776 set previdlist [lindex $rowidlist $y0]
5780 # Find the first column that doesn't have a line going right
5781 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5782 set id [lindex $idlist $col]
5783 if {$id eq {}} break
5784 set x0 [lsearch -exact $previdlist $id]
5786 # check if this is the link to the first child
5787 set kid [lindex $displayorder $y0]
5788 if {[lindex $children($curview,$id) 0] eq $kid} {
5789 # it is, work out offset to child
5790 set x0 [lsearch -exact $previdlist $kid]
5793 if {$x0 <= $col} break
5795 # Insert a pad at that column as long as it has a line and
5796 # isn't the last column
5797 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5798 set idlist [linsert $idlist $col {}]
5799 lset rowidlist $row $idlist
5807 global canvx0 linespc
5808 return [expr {$canvx0 + $col * $linespc}]
5812 global canvy0 linespc
5813 return [expr {$canvy0 + $row * $linespc}]
5816 proc linewidth {id} {
5817 global thickerline lthickness
5820 if {[info exists thickerline] && $id eq $thickerline} {
5821 set wid [expr {2 * $lthickness}]
5826 proc rowranges {id} {
5827 global curview children uparrowlen downarrowlen
5830 set kids $children($curview,$id)
5836 foreach child $kids {
5837 if {![commitinview $child $curview]} break
5838 set row [rowofcommit $child]
5839 if {![info exists prev]} {
5840 lappend ret [expr {$row + 1}]
5842 if {$row <= $prevrow} {
5843 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5845 # see if the line extends the whole way from prevrow to row
5846 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5847 [lsearch -exact [lindex $rowidlist \
5848 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5849 # it doesn't, see where it ends
5850 set r [expr {$prevrow + $downarrowlen}]
5851 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5852 while {[incr r -1] > $prevrow &&
5853 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5855 while {[incr r] <= $row &&
5856 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5860 # see where it starts up again
5861 set r [expr {$row - $uparrowlen}]
5862 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5863 while {[incr r] < $row &&
5864 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5866 while {[incr r -1] >= $prevrow &&
5867 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5873 if {$child eq $id} {
5882 proc drawlineseg {id row endrow arrowlow} {
5883 global rowidlist displayorder iddrawn linesegs
5884 global canv colormap linespc curview maxlinelen parentlist
5886 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5887 set le [expr {$row + 1}]
5890 set c [lsearch -exact [lindex $rowidlist $le] $id]
5896 set x [lindex $displayorder $le]
5901 if {[info exists iddrawn($x)] || $le == $endrow} {
5902 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5918 if {[info exists linesegs($id)]} {
5919 set lines $linesegs($id)
5921 set r0 [lindex $li 0]
5923 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5933 set li [lindex $lines [expr {$i-1}]]
5934 set r1 [lindex $li 1]
5935 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5940 set x [lindex $cols [expr {$le - $row}]]
5941 set xp [lindex $cols [expr {$le - 1 - $row}]]
5942 set dir [expr {$xp - $x}]
5944 set ith [lindex $lines $i 2]
5945 set coords [$canv coords $ith]
5946 set ah [$canv itemcget $ith -arrow]
5947 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5948 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5949 if {$x2 ne {} && $x - $x2 == $dir} {
5950 set coords [lrange $coords 0 end-2]
5953 set coords [list [xc $le $x] [yc $le]]
5956 set itl [lindex $lines [expr {$i-1}] 2]
5957 set al [$canv itemcget $itl -arrow]
5958 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5959 } elseif {$arrowlow} {
5960 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5961 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5965 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5966 for {set y $le} {[incr y -1] > $row} {} {
5968 set xp [lindex $cols [expr {$y - 1 - $row}]]
5969 set ndir [expr {$xp - $x}]
5970 if {$dir != $ndir || $xp < 0} {
5971 lappend coords [xc $y $x] [yc $y]
5977 # join parent line to first child
5978 set ch [lindex $displayorder $row]
5979 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5981 puts "oops: drawlineseg: child $ch not on row $row"
5982 } elseif {$xc != $x} {
5983 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5984 set d [expr {int(0.5 * $linespc)}]
5987 set x2 [expr {$x1 - $d}]
5989 set x2 [expr {$x1 + $d}]
5992 set y1 [expr {$y2 + $d}]
5993 lappend coords $x1 $y1 $x2 $y2
5994 } elseif {$xc < $x - 1} {
5995 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5996 } elseif {$xc > $x + 1} {
5997 lappend coords [xc $row [expr {$x+1}]] [yc $row]
6001 lappend coords [xc $row $x] [yc $row]
6003 set xn [xc $row $xp]
6005 lappend coords $xn $yn
6009 set t [$canv create line $coords -width [linewidth $id] \
6010 -fill $colormap($id) -tags lines.$id -arrow $arrow]
6013 set lines [linsert $lines $i [list $row $le $t]]
6015 $canv coords $ith $coords
6016 if {$arrow ne $ah} {
6017 $canv itemconf $ith -arrow $arrow
6019 lset lines $i 0 $row
6022 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
6023 set ndir [expr {$xo - $xp}]
6024 set clow [$canv coords $itl]
6025 if {$dir == $ndir} {
6026 set clow [lrange $clow 2 end]
6028 set coords [concat $coords $clow]
6030 lset lines [expr {$i-1}] 1 $le
6032 # coalesce two pieces
6034 set b [lindex $lines [expr {$i-1}] 0]
6035 set e [lindex $lines $i 1]
6036 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
6038 $canv coords $itl $coords
6039 if {$arrow ne $al} {
6040 $canv itemconf $itl -arrow $arrow
6044 set linesegs($id) $lines
6048 proc drawparentlinks {id row} {
6049 global rowidlist canv colormap curview parentlist
6050 global idpos linespc
6052 set rowids [lindex $rowidlist $row]
6053 set col [lsearch -exact $rowids $id]
6054 if {$col < 0} return
6055 set olds [lindex $parentlist $row]
6056 set row2 [expr {$row + 1}]
6057 set x [xc $row $col]
6060 set d [expr {int(0.5 * $linespc)}]
6061 set ymid [expr {$y + $d}]
6062 set ids [lindex $rowidlist $row2]
6063 # rmx = right-most X coord used
6066 set i [lsearch -exact $ids $p]
6068 puts "oops, parent $p of $id not in list"
6071 set x2 [xc $row2 $i]
6075 set j [lsearch -exact $rowids $p]
6077 # drawlineseg will do this one for us
6081 # should handle duplicated parents here...
6082 set coords [list $x $y]
6084 # if attaching to a vertical segment, draw a smaller
6085 # slant for visual distinctness
6088 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
6090 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
6092 } elseif {$i < $col && $i < $j} {
6093 # segment slants towards us already
6094 lappend coords [xc $row $j] $y
6096 if {$i < $col - 1} {
6097 lappend coords [expr {$x2 + $linespc}] $y
6098 } elseif {$i > $col + 1} {
6099 lappend coords [expr {$x2 - $linespc}] $y
6101 lappend coords $x2 $y2
6104 lappend coords $x2 $y2
6106 set t [$canv create line $coords -width [linewidth $p] \
6107 -fill $colormap($p) -tags lines.$p]
6111 if {$rmx > [lindex $idpos($id) 1]} {
6112 lset idpos($id) 1 $rmx
6117 proc drawlines {id} {
6120 $canv itemconf lines.$id -width [linewidth $id]
6123 proc drawcmittext {id row col} {
6124 global linespc canv canv2 canv3 fgcolor curview
6125 global cmitlisted commitinfo rowidlist parentlist
6126 global rowtextx idpos idtags idheads idotherrefs
6127 global linehtag linentag linedtag selectedline
6128 global canvxmax boldids boldnameids fgcolor markedid
6129 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
6130 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
6131 global circleoutlinecolor
6133 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
6134 set listed $cmitlisted($curview,$id)
6135 if {$id eq $nullid} {
6136 set ofill $workingfilescirclecolor
6137 } elseif {$id eq $nullid2} {
6138 set ofill $indexcirclecolor
6139 } elseif {$id eq $mainheadid} {
6140 set ofill $mainheadcirclecolor
6142 set ofill [lindex $circlecolors $listed]
6144 set x [xc $row $col]
6146 set orad [expr {$linespc / 3}]
6148 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6149 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6150 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6151 } elseif {$listed == 3} {
6152 # triangle pointing left for left-side commits
6153 set t [$canv create polygon \
6154 [expr {$x - $orad}] $y \
6155 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6156 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6157 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6159 # triangle pointing right for right-side commits
6160 set t [$canv create polygon \
6161 [expr {$x + $orad - 1}] $y \
6162 [expr {$x - $orad}] [expr {$y - $orad}] \
6163 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6164 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6166 set circleitem($row) $t
6168 $canv bind $t <1> {selcanvline {} %x %y}
6169 set rmx [llength [lindex $rowidlist $row]]
6170 set olds [lindex $parentlist $row]
6172 set nextids [lindex $rowidlist [expr {$row + 1}]]
6174 set i [lsearch -exact $nextids $p]
6180 set xt [xc $row $rmx]
6181 set rowtextx($row) $xt
6182 set idpos($id) [list $x $xt $y]
6183 if {[info exists idtags($id)] || [info exists idheads($id)]
6184 || [info exists idotherrefs($id)]} {
6185 set xt [drawtags $id $x $xt $y]
6187 if {[lindex $commitinfo($id) 6] > 0} {
6188 set xt [drawnotesign $xt $y]
6190 set headline [lindex $commitinfo($id) 0]
6191 set name [lindex $commitinfo($id) 1]
6192 set date [lindex $commitinfo($id) 2]
6193 set date [formatdate $date]
6196 set isbold [ishighlighted $id]
6199 set font mainfontbold
6201 lappend boldnameids $id
6202 set nfont mainfontbold
6205 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6206 -text $headline -font $font -tags text]
6207 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6208 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6209 -text $name -font $nfont -tags text]
6210 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6211 -text $date -font mainfont -tags text]
6212 if {$selectedline == $row} {
6215 if {[info exists markedid] && $markedid eq $id} {
6218 set xr [expr {$xt + [font measure $font $headline]}]
6219 if {$xr > $canvxmax} {
6225 proc drawcmitrow {row} {
6226 global displayorder rowidlist nrows_drawn
6227 global iddrawn markingmatches
6228 global commitinfo numcommits
6229 global filehighlight fhighlights findpattern nhighlights
6230 global hlview vhighlights
6231 global highlight_related rhighlights
6233 if {$row >= $numcommits} return
6235 set id [lindex $displayorder $row]
6236 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6237 askvhighlight $row $id
6239 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6240 askfilehighlight $row $id
6242 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6243 askfindhighlight $row $id
6245 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6246 askrelhighlight $row $id
6248 if {![info exists iddrawn($id)]} {
6249 set col [lsearch -exact [lindex $rowidlist $row] $id]
6251 puts "oops, row $row id $id not in list"
6254 if {![info exists commitinfo($id)]} {
6258 drawcmittext $id $row $col
6262 if {$markingmatches} {
6263 markrowmatches $row $id
6267 proc drawcommits {row {endrow {}}} {
6268 global numcommits iddrawn displayorder curview need_redisplay
6269 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6274 if {$endrow eq {}} {
6277 if {$endrow >= $numcommits} {
6278 set endrow [expr {$numcommits - 1}]
6281 set rl1 [expr {$row - $downarrowlen - 3}]
6285 set ro1 [expr {$row - 3}]
6289 set r2 [expr {$endrow + $uparrowlen + 3}]
6290 if {$r2 > $numcommits} {
6293 for {set r $rl1} {$r < $r2} {incr r} {
6294 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6298 set rl1 [expr {$r + 1}]
6304 optimize_rows $ro1 0 $r2
6305 if {$need_redisplay || $nrows_drawn > 2000} {
6309 # make the lines join to already-drawn rows either side
6310 set r [expr {$row - 1}]
6311 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6314 set er [expr {$endrow + 1}]
6315 if {$er >= $numcommits ||
6316 ![info exists iddrawn([lindex $displayorder $er])]} {
6319 for {} {$r <= $er} {incr r} {
6320 set id [lindex $displayorder $r]
6321 set wasdrawn [info exists iddrawn($id)]
6323 if {$r == $er} break
6324 set nextid [lindex $displayorder [expr {$r + 1}]]
6325 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6326 drawparentlinks $id $r
6328 set rowids [lindex $rowidlist $r]
6329 foreach lid $rowids {
6330 if {$lid eq {}} continue
6331 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6333 # see if this is the first child of any of its parents
6334 foreach p [lindex $parentlist $r] {
6335 if {[lsearch -exact $rowids $p] < 0} {
6336 # make this line extend up to the child
6337 set lineend($p) [drawlineseg $p $r $er 0]
6341 set lineend($lid) [drawlineseg $lid $r $er 1]
6347 proc undolayout {row} {
6348 global uparrowlen mingaplen downarrowlen
6349 global rowidlist rowisopt rowfinal need_redisplay
6351 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6355 if {[llength $rowidlist] > $r} {
6357 set rowidlist [lrange $rowidlist 0 $r]
6358 set rowfinal [lrange $rowfinal 0 $r]
6359 set rowisopt [lrange $rowisopt 0 $r]
6360 set need_redisplay 1
6365 proc drawvisible {} {
6366 global canv linespc curview vrowmod selectedline targetrow targetid
6367 global need_redisplay cscroll numcommits
6369 set fs [$canv yview]
6370 set ymax [lindex [$canv cget -scrollregion] 3]
6371 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6372 set f0 [lindex $fs 0]
6373 set f1 [lindex $fs 1]
6374 set y0 [expr {int($f0 * $ymax)}]
6375 set y1 [expr {int($f1 * $ymax)}]
6377 if {[info exists targetid]} {
6378 if {[commitinview $targetid $curview]} {
6379 set r [rowofcommit $targetid]
6380 if {$r != $targetrow} {
6381 # Fix up the scrollregion and change the scrolling position
6382 # now that our target row has moved.
6383 set diff [expr {($r - $targetrow) * $linespc}]
6386 set ymax [lindex [$canv cget -scrollregion] 3]
6389 set f0 [expr {$y0 / $ymax}]
6390 set f1 [expr {$y1 / $ymax}]
6391 allcanvs yview moveto $f0
6392 $cscroll set $f0 $f1
6393 set need_redisplay 1
6400 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6401 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6402 if {$endrow >= $vrowmod($curview)} {
6403 update_arcrows $curview
6405 if {$selectedline ne {} &&
6406 $row <= $selectedline && $selectedline <= $endrow} {
6407 set targetrow $selectedline
6408 } elseif {[info exists targetid]} {
6409 set targetrow [expr {int(($row + $endrow) / 2)}]
6411 if {[info exists targetrow]} {
6412 if {$targetrow >= $numcommits} {
6413 set targetrow [expr {$numcommits - 1}]
6415 set targetid [commitonrow $targetrow]
6417 drawcommits $row $endrow
6420 proc clear_display {} {
6421 global iddrawn linesegs need_redisplay nrows_drawn
6422 global vhighlights fhighlights nhighlights rhighlights
6423 global linehtag linentag linedtag boldids boldnameids
6426 unset -nocomplain iddrawn
6427 unset -nocomplain linesegs
6428 unset -nocomplain linehtag
6429 unset -nocomplain linentag
6430 unset -nocomplain linedtag
6433 unset -nocomplain vhighlights
6434 unset -nocomplain fhighlights
6435 unset -nocomplain nhighlights
6436 unset -nocomplain rhighlights
6437 set need_redisplay 0
6441 proc findcrossings {id} {
6442 global rowidlist parentlist numcommits displayorder
6446 foreach {s e} [rowranges $id] {
6447 if {$e >= $numcommits} {
6448 set e [expr {$numcommits - 1}]
6450 if {$e <= $s} continue
6451 for {set row $e} {[incr row -1] >= $s} {} {
6452 set x [lsearch -exact [lindex $rowidlist $row] $id]
6454 set olds [lindex $parentlist $row]
6455 set kid [lindex $displayorder $row]
6456 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6457 if {$kidx < 0} continue
6458 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6460 set px [lsearch -exact $nextrow $p]
6461 if {$px < 0} continue
6462 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6463 if {[lsearch -exact $ccross $p] >= 0} continue
6464 if {$x == $px + ($kidx < $px? -1: 1)} {
6466 } elseif {[lsearch -exact $cross $p] < 0} {
6473 return [concat $ccross {{}} $cross]
6476 proc assigncolor {id} {
6477 global colormap colors nextcolor
6478 global parents children children curview
6480 if {[info exists colormap($id)]} return
6481 set ncolors [llength $colors]
6482 if {[info exists children($curview,$id)]} {
6483 set kids $children($curview,$id)
6487 if {[llength $kids] == 1} {
6488 set child [lindex $kids 0]
6489 if {[info exists colormap($child)]
6490 && [llength $parents($curview,$child)] == 1} {
6491 set colormap($id) $colormap($child)
6497 foreach x [findcrossings $id] {
6499 # delimiter between corner crossings and other crossings
6500 if {[llength $badcolors] >= $ncolors - 1} break
6501 set origbad $badcolors
6503 if {[info exists colormap($x)]
6504 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6505 lappend badcolors $colormap($x)
6508 if {[llength $badcolors] >= $ncolors} {
6509 set badcolors $origbad
6511 set origbad $badcolors
6512 if {[llength $badcolors] < $ncolors - 1} {
6513 foreach child $kids {
6514 if {[info exists colormap($child)]
6515 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6516 lappend badcolors $colormap($child)
6518 foreach p $parents($curview,$child) {
6519 if {[info exists colormap($p)]
6520 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6521 lappend badcolors $colormap($p)
6525 if {[llength $badcolors] >= $ncolors} {
6526 set badcolors $origbad
6529 for {set i 0} {$i <= $ncolors} {incr i} {
6530 set c [lindex $colors $nextcolor]
6531 if {[incr nextcolor] >= $ncolors} {
6534 if {[lsearch -exact $badcolors $c]} break
6536 set colormap($id) $c
6539 proc bindline {t id} {
6542 $canv bind $t <Enter> "lineenter %x %y $id"
6543 $canv bind $t <Motion> "linemotion %x %y $id"
6544 $canv bind $t <Leave> "lineleave $id"
6545 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6548 proc graph_pane_width {} {
6552 set g [.tf.histframe.pwclist sashpos 0]
6554 set g [.tf.histframe.pwclist sash coord 0]
6556 return [lindex $g 0]
6559 proc totalwidth {l font extra} {
6562 set tot [expr {$tot + [font measure $font $str] + $extra}]
6567 proc drawtags {id x xt y1} {
6568 global idtags idheads idotherrefs mainhead
6569 global linespc lthickness
6570 global canv rowtextx curview fgcolor bgcolor ctxbut
6571 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6572 global tagbgcolor tagfgcolor tagoutlinecolor
6581 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6582 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6583 set extra [expr {$delta + $lthickness + $linespc}]
6585 if {[info exists idtags($id)]} {
6586 set marks $idtags($id)
6587 set ntags [llength $marks]
6588 if {$ntags > $maxtags ||
6589 [totalwidth $marks mainfont $extra] > $maxwidth} {
6590 # show just a single "n tags..." tag
6593 set marks [list "tag..."]
6595 set marks [list [format "%d tags..." $ntags]]
6600 if {[info exists idheads($id)]} {
6601 set marks [concat $marks $idheads($id)]
6602 set nheads [llength $idheads($id)]
6604 if {[info exists idotherrefs($id)]} {
6605 set marks [concat $marks $idotherrefs($id)]
6611 set yt [expr {$y1 - 0.5 * $linespc}]
6612 set yb [expr {$yt + $linespc - 1}]
6616 foreach tag $marks {
6618 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6619 set wid [font measure mainfontbold $tag]
6621 set wid [font measure mainfont $tag]
6625 set xt [expr {$xt + $wid + $extra}]
6627 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6628 -width $lthickness -fill $reflinecolor -tags tag.$id]
6630 foreach tag $marks x $xvals wid $wvals {
6631 set tag_quoted [string map {% %%} $tag]
6632 set xl [expr {$x + $delta}]
6633 set xr [expr {$x + $delta + $wid + $lthickness}]
6635 if {[incr ntags -1] >= 0} {
6637 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6638 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6639 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6642 set tagclick [list showtags $id 1]
6644 set tagclick [list showtag $tag_quoted 1]
6646 $canv bind $t <1> $tagclick
6647 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6649 # draw a head or other ref
6650 if {[incr nheads -1] >= 0} {
6651 set col $headbgcolor
6652 if {$tag eq $mainhead} {
6653 set font mainfontbold
6658 set xl [expr {$xl - $delta/2}]
6659 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6660 -width 1 -outline black -fill $col -tags tag.$id
6661 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6662 set rwid [font measure mainfont $remoteprefix]
6663 set xi [expr {$x + 1}]
6664 set yti [expr {$yt + 1}]
6665 set xri [expr {$x + $rwid}]
6666 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6667 -width 0 -fill $remotebgcolor -tags tag.$id
6670 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6671 -font $font -tags [list tag.$id text]]
6673 $canv bind $t <1> $tagclick
6674 } elseif {$nheads >= 0} {
6675 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6681 proc drawnotesign {xt y} {
6682 global linespc canv fgcolor
6684 set orad [expr {$linespc / 3}]
6685 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6686 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6687 -fill yellow -outline $fgcolor -width 1 -tags circle]
6688 set xt [expr {$xt + $orad * 3}]
6692 proc xcoord {i level ln} {
6693 global canvx0 xspc1 xspc2
6695 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6696 if {$i > 0 && $i == $level} {
6697 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6698 } elseif {$i > $level} {
6699 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6704 proc show_status {msg} {
6709 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6710 -tags text -fill $fgcolor
6713 # Don't change the text pane cursor if it is currently the hand cursor,
6714 # showing that we are over a sha1 ID link.
6715 proc settextcursor {c} {
6716 global ctext curtextcursor
6718 if {[$ctext cget -cursor] == $curtextcursor} {
6719 $ctext config -cursor $c
6721 set curtextcursor $c
6724 proc nowbusy {what {name {}}} {
6725 global isbusy busyname statusw
6727 if {[array names isbusy] eq {}} {
6728 . config -cursor watch
6732 set busyname($what) $name
6734 $statusw conf -text $name
6738 proc notbusy {what} {
6739 global isbusy maincursor textcursor busyname statusw
6743 if {$busyname($what) ne {} &&
6744 [$statusw cget -text] eq $busyname($what)} {
6745 $statusw conf -text {}
6748 if {[array names isbusy] eq {}} {
6749 . config -cursor $maincursor
6750 settextcursor $textcursor
6754 proc findmatches {f} {
6755 global findtype findstring
6756 if {$findtype == [mc "Regexp"]} {
6757 set matches [regexp -indices -all -inline $findstring $f]
6760 if {$findtype == [mc "IgnCase"]} {
6761 set f [string tolower $f]
6762 set fs [string tolower $fs]
6766 set l [string length $fs]
6767 while {[set j [string first $fs $f $i]] >= 0} {
6768 lappend matches [list $j [expr {$j+$l-1}]]
6769 set i [expr {$j + $l}]
6775 proc dofind {{dirn 1} {wrap 1}} {
6776 global findstring findstartline findcurline selectedline numcommits
6777 global gdttype filehighlight fh_serial find_dirn findallowwrap
6779 if {[info exists find_dirn]} {
6780 if {$find_dirn == $dirn} return
6784 if {$findstring eq {} || $numcommits == 0} return
6785 if {$selectedline eq {}} {
6786 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6788 set findstartline $selectedline
6790 set findcurline $findstartline
6791 nowbusy finding [mc "Searching"]
6792 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6793 after cancel do_file_hl $fh_serial
6794 do_file_hl $fh_serial
6797 set findallowwrap $wrap
6801 proc stopfinding {} {
6802 global find_dirn findcurline fprogcoord
6804 if {[info exists find_dirn]} {
6815 global commitdata commitinfo numcommits findpattern findloc
6816 global findstartline findcurline findallowwrap
6817 global find_dirn gdttype fhighlights fprogcoord
6818 global curview varcorder vrownum varccommits vrowmod
6820 if {![info exists find_dirn]} {
6823 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6826 if {$find_dirn > 0} {
6828 if {$l >= $numcommits} {
6831 if {$l <= $findstartline} {
6832 set lim [expr {$findstartline + 1}]
6835 set moretodo $findallowwrap
6842 if {$l >= $findstartline} {
6843 set lim [expr {$findstartline - 1}]
6846 set moretodo $findallowwrap
6849 set n [expr {($lim - $l) * $find_dirn}]
6854 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6855 update_arcrows $curview
6859 set ai [bsearch $vrownum($curview) $l]
6860 set a [lindex $varcorder($curview) $ai]
6861 set arow [lindex $vrownum($curview) $ai]
6862 set ids [lindex $varccommits($curview,$a)]
6863 set arowend [expr {$arow + [llength $ids]}]
6864 if {$gdttype eq [mc "containing:"]} {
6865 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6866 if {$l < $arow || $l >= $arowend} {
6868 set a [lindex $varcorder($curview) $ai]
6869 set arow [lindex $vrownum($curview) $ai]
6870 set ids [lindex $varccommits($curview,$a)]
6871 set arowend [expr {$arow + [llength $ids]}]
6873 set id [lindex $ids [expr {$l - $arow}]]
6874 # shouldn't happen unless git log doesn't give all the commits...
6875 if {![info exists commitdata($id)] ||
6876 ![doesmatch $commitdata($id)]} {
6879 if {![info exists commitinfo($id)]} {
6882 set info $commitinfo($id)
6883 foreach f $info ty $fldtypes {
6884 if {$ty eq ""} continue
6885 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6894 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6895 if {$l < $arow || $l >= $arowend} {
6897 set a [lindex $varcorder($curview) $ai]
6898 set arow [lindex $vrownum($curview) $ai]
6899 set ids [lindex $varccommits($curview,$a)]
6900 set arowend [expr {$arow + [llength $ids]}]
6902 set id [lindex $ids [expr {$l - $arow}]]
6903 if {![info exists fhighlights($id)]} {
6904 # this sets fhighlights($id) to -1
6905 askfilehighlight $l $id
6907 if {$fhighlights($id) > 0} {
6911 if {$fhighlights($id) < 0} {
6914 set findcurline [expr {$l - $find_dirn}]
6919 if {$found || ($domore && !$moretodo)} {
6935 set findcurline [expr {$l - $find_dirn}]
6937 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6941 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6946 proc findselectline {l} {
6947 global findloc commentend ctext findcurline markingmatches gdttype
6949 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6952 if {$markingmatches &&
6953 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6954 # highlight the matches in the comments
6955 set f [$ctext get 1.0 $commentend]
6956 set matches [findmatches $f]
6957 foreach match $matches {
6958 set start [lindex $match 0]
6959 set end [expr {[lindex $match 1] + 1}]
6960 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6966 # mark the bits of a headline or author that match a find string
6967 proc markmatches {canv l str tag matches font row} {
6970 set bbox [$canv bbox $tag]
6971 set x0 [lindex $bbox 0]
6972 set y0 [lindex $bbox 1]
6973 set y1 [lindex $bbox 3]
6974 foreach match $matches {
6975 set start [lindex $match 0]
6976 set end [lindex $match 1]
6977 if {$start > $end} continue
6978 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6979 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6980 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6981 [expr {$x0+$xlen+2}] $y1 \
6982 -outline {} -tags [list match$l matches] -fill yellow]
6984 if {$row == $selectedline} {
6985 $canv raise $t secsel
6990 proc unmarkmatches {} {
6991 global markingmatches
6993 allcanvs delete matches
6994 set markingmatches 0
6998 proc selcanvline {w x y} {
6999 global canv canvy0 ctext linespc
7001 set ymax [lindex [$canv cget -scrollregion] 3]
7002 if {$ymax == {}} return
7003 set yfrac [lindex [$canv yview] 0]
7004 set y [expr {$y + $yfrac * $ymax}]
7005 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
7010 set xmax [lindex [$canv cget -scrollregion] 2]
7011 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
7012 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
7018 proc commit_descriptor {p} {
7020 if {![info exists commitinfo($p)]} {
7024 if {[llength $commitinfo($p)] > 1} {
7025 set l [lindex $commitinfo($p) 0]
7030 # append some text to the ctext widget, and make any SHA1 ID
7031 # that we know about be a clickable link.
7032 # Also look for URLs of the form "http[s]://..." and make them web links.
7033 proc appendwithlinks {text tags} {
7034 global ctext linknum curview
7036 set start [$ctext index "end - 1c"]
7037 $ctext insert end $text $tags
7038 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
7042 set linkid [string range $text $s $e]
7044 $ctext tag delete link$linknum
7045 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
7046 setlink $linkid link$linknum
7049 set wlinks [regexp -indices -all -inline -line \
7050 {https?://[^[:space:]]+} $text]
7052 set s2 [lindex $l 0]
7053 set e2 [lindex $l 1]
7054 set url [string range $text $s2 $e2]
7056 $ctext tag delete link$linknum
7057 $ctext tag add link$linknum "$start + $s2 c" "$start + $e2 c"
7058 setwlink $url link$linknum
7063 proc setlink {id lk} {
7064 global curview ctext pendinglinks
7067 if {[string range $id 0 1] eq "-g"} {
7068 set id [string range $id 2 end]
7072 if {[string length $id] < 40} {
7073 set matches [longid $id]
7074 if {[llength $matches] > 0} {
7075 if {[llength $matches] > 1} return
7077 set id [lindex $matches 0]
7080 set known [commitinview $id $curview]
7083 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
7084 $ctext tag bind $lk <1> [list selbyid $id]
7085 $ctext tag bind $lk <Enter> {linkcursor %W 1}
7086 $ctext tag bind $lk <Leave> {linkcursor %W -1}
7088 lappend pendinglinks($id) $lk
7089 interestedin $id {makelink %P}
7093 proc setwlink {url lk} {
7098 if {$web_browser eq {}} return
7099 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
7100 $ctext tag bind $lk <1> [list browseweb $url]
7101 $ctext tag bind $lk <Enter> {linkcursor %W 1}
7102 $ctext tag bind $lk <Leave> {linkcursor %W -1}
7105 proc appendshortlink {id {pre {}} {post {}}} {
7106 global ctext linknum
7108 $ctext insert end $pre
7109 $ctext tag delete link$linknum
7110 $ctext insert end [string range $id 0 7] link$linknum
7111 $ctext insert end $post
7112 setlink $id link$linknum
7116 proc makelink {id} {
7119 if {![info exists pendinglinks($id)]} return
7120 foreach lk $pendinglinks($id) {
7123 unset pendinglinks($id)
7126 proc linkcursor {w inc} {
7127 global linkentercount curtextcursor
7129 if {[incr linkentercount $inc] > 0} {
7130 $w configure -cursor hand2
7132 $w configure -cursor $curtextcursor
7133 if {$linkentercount < 0} {
7134 set linkentercount 0
7139 proc browseweb {url} {
7142 if {$web_browser eq {}} return
7143 # Use eval here in case $web_browser is a command plus some arguments
7144 if {[catch {eval exec $web_browser [list $url] &} err]} {
7145 error_popup "[mc "Error starting web browser:"] $err"
7149 proc viewnextline {dir} {
7153 set ymax [lindex [$canv cget -scrollregion] 3]
7154 set wnow [$canv yview]
7155 set wtop [expr {[lindex $wnow 0] * $ymax}]
7156 set newtop [expr {$wtop + $dir * $linespc}]
7159 } elseif {$newtop > $ymax} {
7162 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7165 # add a list of tag or branch names at position pos
7166 # returns the number of names inserted
7167 proc appendrefs {pos ids var} {
7168 global ctext linknum curview $var maxrefs visiblerefs mainheadid
7170 if {[catch {$ctext index $pos}]} {
7173 $ctext conf -state normal
7174 $ctext delete $pos "$pos lineend"
7177 foreach tag [set $var\($id\)] {
7178 lappend tags [list $tag $id]
7183 set tags [lsort -index 0 -decreasing $tags]
7186 if {[llength $tags] > $maxrefs} {
7187 # If we are displaying heads, and there are too many,
7188 # see if there are some important heads to display.
7189 # Currently that are the current head and heads listed in $visiblerefs option
7191 if {$var eq "idheads"} {
7194 set hname [lindex $ti 0]
7195 set id [lindex $ti 1]
7196 if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) &&
7197 [llength $itags] < $maxrefs} {
7206 set str [mc "and many more"]
7211 $ctext insert $pos "$str ([llength $tags])"
7212 set nutags [llength $tags]
7217 set id [lindex $ti 1]
7220 $ctext tag delete $lk
7221 $ctext insert $pos $sep
7222 $ctext insert $pos [lindex $ti 0] $lk
7226 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7227 $ctext conf -state disabled
7228 return [expr {[llength $tags] + $nutags}]
7231 # called when we have finished computing the nearby tags
7232 proc dispneartags {delay} {
7233 global selectedline currentid showneartags tagphase
7235 if {$selectedline eq {} || !$showneartags} return
7236 after cancel dispnexttag
7238 after 200 dispnexttag
7241 after idle dispnexttag
7246 proc dispnexttag {} {
7247 global selectedline currentid showneartags tagphase ctext
7249 if {$selectedline eq {} || !$showneartags} return
7250 switch -- $tagphase {
7252 set dtags [desctags $currentid]
7254 appendrefs precedes $dtags idtags
7258 set atags [anctags $currentid]
7260 appendrefs follows $atags idtags
7264 set dheads [descheads $currentid]
7265 if {$dheads ne {}} {
7266 if {[appendrefs branch $dheads idheads] > 1
7267 && [$ctext get "branch -3c"] eq "h"} {
7268 # turn "Branch" into "Branches"
7269 $ctext conf -state normal
7270 $ctext insert "branch -2c" "es"
7271 $ctext conf -state disabled
7276 if {[incr tagphase] <= 2} {
7277 after idle dispnexttag
7281 proc make_secsel {id} {
7282 global linehtag linentag linedtag canv canv2 canv3
7284 if {![info exists linehtag($id)]} return
7286 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7287 -tags secsel -fill [$canv cget -selectbackground]]
7289 $canv2 delete secsel
7290 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7291 -tags secsel -fill [$canv2 cget -selectbackground]]
7293 $canv3 delete secsel
7294 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7295 -tags secsel -fill [$canv3 cget -selectbackground]]
7299 proc make_idmark {id} {
7300 global linehtag canv fgcolor
7302 if {![info exists linehtag($id)]} return
7304 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7305 -tags markid -outline $fgcolor]
7309 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7310 global canv ctext commitinfo selectedline
7311 global canvy0 linespc parents children curview
7312 global currentid sha1entry
7313 global commentend idtags linknum
7314 global mergemax numcommits pending_select
7315 global cmitmode showneartags allcommits
7316 global targetrow targetid lastscrollrows
7317 global autoselect autosellen jump_to_here
7320 unset -nocomplain pending_select
7325 if {$l < 0 || $l >= $numcommits} return
7326 set id [commitonrow $l]
7331 if {$lastscrollrows < $numcommits} {
7335 if {$cmitmode ne "patch" && $switch_to_patch} {
7336 set cmitmode "patch"
7339 set y [expr {$canvy0 + $l * $linespc}]
7340 set ymax [lindex [$canv cget -scrollregion] 3]
7341 set ytop [expr {$y - $linespc - 1}]
7342 set ybot [expr {$y + $linespc + 1}]
7343 set wnow [$canv yview]
7344 set wtop [expr {[lindex $wnow 0] * $ymax}]
7345 set wbot [expr {[lindex $wnow 1] * $ymax}]
7346 set wh [expr {$wbot - $wtop}]
7348 if {$ytop < $wtop} {
7349 if {$ybot < $wtop} {
7350 set newtop [expr {$y - $wh / 2.0}]
7353 if {$newtop > $wtop - $linespc} {
7354 set newtop [expr {$wtop - $linespc}]
7357 } elseif {$ybot > $wbot} {
7358 if {$ytop > $wbot} {
7359 set newtop [expr {$y - $wh / 2.0}]
7361 set newtop [expr {$ybot - $wh}]
7362 if {$newtop < $wtop + $linespc} {
7363 set newtop [expr {$wtop + $linespc}]
7367 if {$newtop != $wtop} {
7371 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7378 addtohistory [list selbyid $id 0] savecmitpos
7381 $sha1entry delete 0 end
7382 $sha1entry insert 0 $id
7384 $sha1entry selection range 0 $autosellen
7388 $ctext conf -state normal
7391 if {![info exists commitinfo($id)]} {
7394 set info $commitinfo($id)
7395 set date [formatdate [lindex $info 2]]
7396 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7397 set date [formatdate [lindex $info 4]]
7398 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7399 if {[info exists idtags($id)]} {
7400 $ctext insert end [mc "Tags:"]
7401 foreach tag $idtags($id) {
7402 $ctext insert end " $tag"
7404 $ctext insert end "\n"
7408 set olds $parents($curview,$id)
7409 if {[llength $olds] > 1} {
7412 if {$np >= $mergemax} {
7417 $ctext insert end "[mc "Parent"]: " $tag
7418 appendwithlinks [commit_descriptor $p] {}
7423 append headers "[mc "Parent"]: [commit_descriptor $p]"
7427 foreach c $children($curview,$id) {
7428 append headers "[mc "Child"]: [commit_descriptor $c]"
7431 # make anything that looks like a SHA1 ID be a clickable link
7432 appendwithlinks $headers {}
7433 if {$showneartags} {
7434 if {![info exists allcommits]} {
7437 $ctext insert end "[mc "Branch"]: "
7438 $ctext mark set branch "end -1c"
7439 $ctext mark gravity branch left
7440 $ctext insert end "\n[mc "Follows"]: "
7441 $ctext mark set follows "end -1c"
7442 $ctext mark gravity follows left
7443 $ctext insert end "\n[mc "Precedes"]: "
7444 $ctext mark set precedes "end -1c"
7445 $ctext mark gravity precedes left
7446 $ctext insert end "\n"
7449 $ctext insert end "\n"
7450 set comment [lindex $info 5]
7451 if {[string first "\r" $comment] >= 0} {
7452 set comment [string map {"\r" "\n "} $comment]
7454 appendwithlinks $comment {comment}
7456 $ctext tag remove found 1.0 end
7457 $ctext conf -state disabled
7458 set commentend [$ctext index "end - 1c"]
7460 set jump_to_here $desired_loc
7461 init_flist [mc "Comments"]
7462 if {$cmitmode eq "tree"} {
7464 } elseif {$vinlinediff($curview) == 1} {
7466 } elseif {[llength $olds] <= 1} {
7473 proc selfirstline {} {
7478 proc sellastline {} {
7481 set l [expr {$numcommits - 1}]
7485 proc selnextline {dir} {
7488 if {$selectedline eq {}} return
7489 set l [expr {$selectedline + $dir}]
7494 proc selnextpage {dir} {
7495 global canv linespc selectedline numcommits
7497 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7501 allcanvs yview scroll [expr {$dir * $lpp}] units
7503 if {$selectedline eq {}} return
7504 set l [expr {$selectedline + $dir * $lpp}]
7507 } elseif {$l >= $numcommits} {
7508 set l [expr $numcommits - 1]
7514 proc unselectline {} {
7515 global selectedline currentid
7518 unset -nocomplain currentid
7519 allcanvs delete secsel
7523 proc reselectline {} {
7526 if {$selectedline ne {}} {
7527 selectline $selectedline 0
7531 proc addtohistory {cmd {saveproc {}}} {
7532 global history historyindex curview
7536 set elt [list $curview $cmd $saveproc {}]
7537 if {$historyindex > 0
7538 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7542 if {$historyindex < [llength $history]} {
7543 set history [lreplace $history $historyindex end $elt]
7545 lappend history $elt
7548 if {$historyindex > 1} {
7549 .tf.bar.leftbut conf -state normal
7551 .tf.bar.leftbut conf -state disabled
7553 .tf.bar.rightbut conf -state disabled
7556 # save the scrolling position of the diff display pane
7557 proc save_position {} {
7558 global historyindex history
7560 if {$historyindex < 1} return
7561 set hi [expr {$historyindex - 1}]
7562 set fn [lindex $history $hi 2]
7564 lset history $hi 3 [eval $fn]
7568 proc unset_posvars {} {
7571 if {[info exists last_posvars]} {
7572 foreach {var val} $last_posvars {
7574 unset -nocomplain $var
7581 global curview last_posvars
7583 set view [lindex $elt 0]
7584 set cmd [lindex $elt 1]
7585 set pv [lindex $elt 3]
7586 if {$curview != $view} {
7590 foreach {var val} $pv {
7594 set last_posvars $pv
7599 global history historyindex
7602 if {$historyindex > 1} {
7604 incr historyindex -1
7605 godo [lindex $history [expr {$historyindex - 1}]]
7606 .tf.bar.rightbut conf -state normal
7608 if {$historyindex <= 1} {
7609 .tf.bar.leftbut conf -state disabled
7614 global history historyindex
7617 if {$historyindex < [llength $history]} {
7619 set cmd [lindex $history $historyindex]
7622 .tf.bar.leftbut conf -state normal
7624 if {$historyindex >= [llength $history]} {
7625 .tf.bar.rightbut conf -state disabled
7629 proc go_to_parent {i} {
7630 global parents curview targetid
7631 set ps $parents($curview,$targetid)
7632 if {[llength $ps] >= $i} {
7633 selbyid [lindex $ps [expr $i - 1]]
7638 global treefilelist treeidlist diffids diffmergeid treepending
7639 global nullid nullid2
7642 unset -nocomplain diffmergeid
7643 if {![info exists treefilelist($id)]} {
7644 if {![info exists treepending]} {
7645 if {$id eq $nullid} {
7646 set cmd [list | git ls-files]
7647 } elseif {$id eq $nullid2} {
7648 set cmd [list | git ls-files --stage -t]
7650 set cmd [list | git ls-tree -r $id]
7652 if {[catch {set gtf [open $cmd r]}]} {
7656 set treefilelist($id) {}
7657 set treeidlist($id) {}
7658 fconfigure $gtf -blocking 0 -encoding binary
7659 filerun $gtf [list gettreeline $gtf $id]
7666 proc gettreeline {gtf id} {
7667 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7670 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7671 if {$diffids eq $nullid} {
7674 set i [string first "\t" $line]
7675 if {$i < 0} continue
7676 set fname [string range $line [expr {$i+1}] end]
7677 set line [string range $line 0 [expr {$i-1}]]
7678 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7679 set sha1 [lindex $line 2]
7680 lappend treeidlist($id) $sha1
7682 if {[string index $fname 0] eq "\""} {
7683 set fname [lindex $fname 0]
7685 set fname [encoding convertfrom $fname]
7686 lappend treefilelist($id) $fname
7689 return [expr {$nl >= 1000? 2: 1}]
7693 if {$cmitmode ne "tree"} {
7694 if {![info exists diffmergeid]} {
7695 gettreediffs $diffids
7697 } elseif {$id ne $diffids} {
7706 global treefilelist treeidlist diffids nullid nullid2
7707 global ctext_file_names ctext_file_lines
7708 global ctext commentend
7710 set i [lsearch -exact $treefilelist($diffids) $f]
7712 puts "oops, $f not in list for id $diffids"
7715 if {$diffids eq $nullid} {
7716 if {[catch {set bf [open $f r]} err]} {
7717 puts "oops, can't read $f: $err"
7721 set blob [lindex $treeidlist($diffids) $i]
7722 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7723 puts "oops, error reading blob $blob: $err"
7727 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7728 filerun $bf [list getblobline $bf $diffids]
7729 $ctext config -state normal
7730 clear_ctext $commentend
7731 lappend ctext_file_names $f
7732 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7733 $ctext insert end "\n"
7734 $ctext insert end "$f\n" filesep
7735 $ctext config -state disabled
7736 $ctext yview $commentend
7740 proc getblobline {bf id} {
7741 global diffids cmitmode ctext
7743 if {$id ne $diffids || $cmitmode ne "tree"} {
7747 $ctext config -state normal
7749 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7750 $ctext insert end "$line\n"
7753 global jump_to_here ctext_file_names commentend
7755 # delete last newline
7756 $ctext delete "end - 2c" "end - 1c"
7758 if {$jump_to_here ne {} &&
7759 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7760 set lnum [expr {[lindex $jump_to_here 1] +
7761 [lindex [split $commentend .] 0]}]
7762 mark_ctext_line $lnum
7764 $ctext config -state disabled
7767 $ctext config -state disabled
7768 return [expr {$nl >= 1000? 2: 1}]
7771 proc mark_ctext_line {lnum} {
7772 global ctext markbgcolor
7774 $ctext tag delete omark
7775 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7776 $ctext tag conf omark -background $markbgcolor
7780 proc mergediff {id} {
7782 global diffids treediffs
7783 global parents curview
7787 set treediffs($id) {}
7788 set np [llength $parents($curview,$id)]
7793 proc startdiff {ids} {
7794 global treediffs diffids treepending diffmergeid nullid nullid2
7798 unset -nocomplain diffmergeid
7799 if {![info exists treediffs($ids)] ||
7800 [lsearch -exact $ids $nullid] >= 0 ||
7801 [lsearch -exact $ids $nullid2] >= 0} {
7802 if {![info exists treepending]} {
7810 proc showinlinediff {ids} {
7811 global commitinfo commitdata ctext
7814 set info $commitinfo($ids)
7815 set diff [lindex $info 7]
7816 set difflines [split $diff "\n"]
7822 foreach line $difflines {
7823 if {![string compare -length 5 "diff " $line]} {
7825 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7826 # offset also accounts for the b/ prefix
7827 lappend treediff [string range $line 6 end]
7832 set treediffs($ids) $treediff
7835 $ctext conf -state normal
7836 foreach line $difflines {
7837 parseblobdiffline $ids $line
7839 maybe_scroll_ctext 1
7840 $ctext conf -state disabled
7843 # If the filename (name) is under any of the passed filter paths
7844 # then return true to include the file in the listing.
7845 proc path_filter {filter name} {
7846 set worktree [gitworktree]
7848 set fq_p [file normalize $p]
7849 set fq_n [file normalize [file join $worktree $name]]
7850 if {[string match [file normalize $fq_p]* $fq_n]} {
7857 proc addtocflist {ids} {
7860 add_flist $treediffs($ids)
7864 proc diffcmd {ids flags} {
7865 global log_showroot nullid nullid2 git_version
7867 set i [lsearch -exact $ids $nullid]
7868 set j [lsearch -exact $ids $nullid2]
7870 if {[llength $ids] > 1 && $j < 0} {
7871 # comparing working directory with some specific revision
7872 set cmd [concat | git diff-index $flags]
7874 lappend cmd -R [lindex $ids 1]
7876 lappend cmd [lindex $ids 0]
7879 # comparing working directory with index
7880 set cmd [concat | git diff-files $flags]
7885 } elseif {$j >= 0} {
7886 if {[package vcompare $git_version "1.7.2"] >= 0} {
7887 set flags "$flags --ignore-submodules=dirty"
7889 set cmd [concat | git diff-index --cached $flags]
7890 if {[llength $ids] > 1} {
7891 # comparing index with specific revision
7893 lappend cmd -R [lindex $ids 1]
7895 lappend cmd [lindex $ids 0]
7898 # comparing index with HEAD
7902 if {$log_showroot} {
7903 lappend flags --root
7905 set cmd [concat | git diff-tree -r $flags $ids]
7910 proc gettreediffs {ids} {
7911 global treediff treepending limitdiffs vfilelimit curview
7913 set cmd [diffcmd $ids {--no-commit-id}]
7914 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7915 set cmd [concat $cmd -- $vfilelimit($curview)]
7917 if {[catch {set gdtf [open $cmd r]}]} return
7919 set treepending $ids
7921 fconfigure $gdtf -blocking 0 -encoding binary
7922 filerun $gdtf [list gettreediffline $gdtf $ids]
7925 proc gettreediffline {gdtf ids} {
7926 global treediff treediffs treepending diffids diffmergeid
7927 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7932 if {$perfile_attrs} {
7933 # cache_gitattr is slow, and even slower on win32 where we
7934 # have to invoke it for only about 30 paths at a time
7936 if {[tk windowingsystem] == "win32"} {
7940 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7941 set i [string first "\t" $line]
7943 set file [string range $line [expr {$i+1}] end]
7944 if {[string index $file 0] eq "\""} {
7945 set file [lindex $file 0]
7947 set file [encoding convertfrom $file]
7948 if {$file ne [lindex $treediff end]} {
7949 lappend treediff $file
7950 lappend sublist $file
7954 if {$perfile_attrs} {
7955 cache_gitattr encoding $sublist
7958 return [expr {$nr >= $max? 2: 1}]
7961 set treediffs($ids) $treediff
7963 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7965 } elseif {$ids != $diffids} {
7966 if {![info exists diffmergeid]} {
7967 gettreediffs $diffids
7975 # empty string or positive integer
7976 proc diffcontextvalidate {v} {
7977 return [regexp {^(|[1-9][0-9]*)$} $v]
7980 proc diffcontextchange {n1 n2 op} {
7981 global diffcontextstring diffcontext
7983 if {[string is integer -strict $diffcontextstring]} {
7984 if {$diffcontextstring >= 0} {
7985 set diffcontext $diffcontextstring
7991 proc changeignorespace {} {
7995 proc changeworddiff {name ix op} {
7999 proc initblobdiffvars {} {
8000 global diffencoding targetline diffnparents
8001 global diffinhdr currdiffsubmod diffseehere
8005 set diffencoding [get_path_encoding {}]
8006 set currdiffsubmod ""
8010 proc getblobdiffs {ids} {
8011 global blobdifffd diffids env
8016 global limitdiffs vfilelimit curview
8020 if {[package vcompare $git_version "1.6.1"] >= 0} {
8021 set textconv "--textconv"
8024 if {[package vcompare $git_version "1.6.6"] >= 0} {
8025 set submodule "--submodule"
8027 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
8031 if {$worddiff ne [mc "Line diff"]} {
8032 append cmd " --word-diff=porcelain"
8034 if {$limitdiffs && $vfilelimit($curview) ne {}} {
8035 set cmd [concat $cmd -- $vfilelimit($curview)]
8037 if {[catch {set bdf [open $cmd r]} err]} {
8038 error_popup [mc "Error getting diffs: %s" $err]
8041 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
8042 set blobdifffd($ids) $bdf
8044 filerun $bdf [list getblobdiffline $bdf $diffids]
8047 proc savecmitpos {} {
8048 global ctext cmitmode
8050 if {$cmitmode eq "tree"} {
8053 return [list target_scrollpos [$ctext index @0,0]]
8056 proc savectextpos {} {
8059 return [list target_scrollpos [$ctext index @0,0]]
8062 proc maybe_scroll_ctext {ateof} {
8063 global ctext target_scrollpos
8065 if {![info exists target_scrollpos]} return
8067 set nlines [expr {[winfo height $ctext]
8068 / [font metrics textfont -linespace]}]
8069 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
8071 $ctext yview $target_scrollpos
8072 unset target_scrollpos
8075 proc setinlist {var i val} {
8078 while {[llength [set $var]] < $i} {
8081 if {[llength [set $var]] == $i} {
8088 proc makediffhdr {fname ids} {
8089 global ctext curdiffstart treediffs diffencoding
8090 global ctext_file_names jump_to_here targetline diffline
8092 set fname [encoding convertfrom $fname]
8093 set diffencoding [get_path_encoding $fname]
8094 set i [lsearch -exact $treediffs($ids) $fname]
8096 setinlist difffilestart $i $curdiffstart
8098 lset ctext_file_names end $fname
8099 set l [expr {(78 - [string length $fname]) / 2}]
8100 set pad [string range "----------------------------------------" 1 $l]
8101 $ctext insert $curdiffstart "$pad $fname $pad" filesep
8103 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
8104 set targetline [lindex $jump_to_here 1]
8109 proc blobdiffmaybeseehere {ateof} {
8111 if {$diffseehere >= 0} {
8112 mark_ctext_line [lindex [split $diffseehere .] 0]
8114 maybe_scroll_ctext $ateof
8117 proc getblobdiffline {bdf ids} {
8118 global diffids blobdifffd
8122 $ctext conf -state normal
8123 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
8124 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
8125 # Older diff read. Abort it.
8127 if {$ids != $diffids} {
8128 array unset blobdifffd $ids
8132 parseblobdiffline $ids $line
8134 $ctext conf -state disabled
8135 blobdiffmaybeseehere [eof $bdf]
8138 array unset blobdifffd $ids
8141 return [expr {$nr >= 1000? 2: 1}]
8144 proc parseblobdiffline {ids line} {
8145 global ctext curdiffstart
8146 global diffnexthead diffnextnote difffilestart
8147 global ctext_file_names ctext_file_lines
8148 global diffinhdr treediffs mergemax diffnparents
8149 global diffencoding jump_to_here targetline diffline currdiffsubmod
8150 global worddiff diffseehere
8152 if {![string compare -length 5 "diff " $line]} {
8153 if {![regexp {^diff (--cc|--git) } $line m type]} {
8154 set line [encoding convertfrom $line]
8155 $ctext insert end "$line\n" hunksep
8158 # start of a new file
8160 set currdiffsubmod ""
8162 $ctext insert end "\n"
8163 set curdiffstart [$ctext index "end - 1c"]
8164 lappend ctext_file_names ""
8165 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8166 $ctext insert end "\n" filesep
8168 if {$type eq "--cc"} {
8169 # start of a new file in a merge diff
8170 set fname [string range $line 10 end]
8171 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
8172 lappend treediffs($ids) $fname
8173 add_flist [list $fname]
8177 set line [string range $line 11 end]
8178 # If the name hasn't changed the length will be odd,
8179 # the middle char will be a space, and the two bits either
8180 # side will be a/name and b/name, or "a/name" and "b/name".
8181 # If the name has changed we'll get "rename from" and
8182 # "rename to" or "copy from" and "copy to" lines following
8183 # this, and we'll use them to get the filenames.
8184 # This complexity is necessary because spaces in the
8185 # filename(s) don't get escaped.
8186 set l [string length $line]
8187 set i [expr {$l / 2}]
8188 if {!(($l & 1) && [string index $line $i] eq " " &&
8189 [string range $line 2 [expr {$i - 1}]] eq \
8190 [string range $line [expr {$i + 3}] end])} {
8193 # unescape if quoted and chop off the a/ from the front
8194 if {[string index $line 0] eq "\""} {
8195 set fname [string range [lindex $line 0] 2 end]
8197 set fname [string range $line 2 [expr {$i - 1}]]
8200 makediffhdr $fname $ids
8202 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8203 set fname [encoding convertfrom [string range $line 16 end]]
8204 $ctext insert end "\n"
8205 set curdiffstart [$ctext index "end - 1c"]
8206 lappend ctext_file_names $fname
8207 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8208 $ctext insert end "$line\n" filesep
8209 set i [lsearch -exact $treediffs($ids) $fname]
8211 setinlist difffilestart $i $curdiffstart
8214 } elseif {![string compare -length 2 "@@" $line]} {
8215 regexp {^@@+} $line ats
8216 set line [encoding convertfrom $diffencoding $line]
8217 $ctext insert end "$line\n" hunksep
8218 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8221 set diffnparents [expr {[string length $ats] - 1}]
8224 } elseif {![string compare -length 10 "Submodule " $line]} {
8225 # start of a new submodule
8226 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8227 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8229 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8231 if {$currdiffsubmod != $fname} {
8232 $ctext insert end "\n"; # Add newline after commit message
8234 set curdiffstart [$ctext index "end - 1c"]
8235 lappend ctext_file_names ""
8236 if {$currdiffsubmod != $fname} {
8237 lappend ctext_file_lines $fname
8238 makediffhdr $fname $ids
8239 set currdiffsubmod $fname
8240 $ctext insert end "\n$line\n" filesep
8242 $ctext insert end "$line\n" filesep
8244 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8245 set line [encoding convertfrom $diffencoding $line]
8246 $ctext insert end "$line\n" dresult
8247 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8248 set line [encoding convertfrom $diffencoding $line]
8249 $ctext insert end "$line\n" d0
8250 } elseif {$diffinhdr} {
8251 if {![string compare -length 12 "rename from " $line]} {
8252 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8253 if {[string index $fname 0] eq "\""} {
8254 set fname [lindex $fname 0]
8256 set fname [encoding convertfrom $fname]
8257 set i [lsearch -exact $treediffs($ids) $fname]
8259 setinlist difffilestart $i $curdiffstart
8261 } elseif {![string compare -length 10 $line "rename to "] ||
8262 ![string compare -length 8 $line "copy to "]} {
8263 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8264 if {[string index $fname 0] eq "\""} {
8265 set fname [lindex $fname 0]
8267 makediffhdr $fname $ids
8268 } elseif {[string compare -length 3 $line "---"] == 0} {
8271 } elseif {[string compare -length 3 $line "+++"] == 0} {
8275 $ctext insert end "$line\n" filesep
8278 set line [string map {\x1A ^Z} \
8279 [encoding convertfrom $diffencoding $line]]
8280 # parse the prefix - one ' ', '-' or '+' for each parent
8281 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8282 set tag [expr {$diffnparents > 1? "m": "d"}]
8283 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8284 set words_pre_markup ""
8285 set words_post_markup ""
8286 if {[string trim $prefix " -+"] eq {}} {
8287 # prefix only has " ", "-" and "+" in it: normal diff line
8288 set num [string first "-" $prefix]
8290 set line [string range $line 1 end]
8293 # removed line, first parent with line is $num
8294 if {$num >= $mergemax} {
8297 if {$dowords && $worddiff eq [mc "Markup words"]} {
8298 $ctext insert end "\[-$line-\]" $tag$num
8300 $ctext insert end "$line" $tag$num
8303 $ctext insert end "\n" $tag$num
8307 if {[string first "+" $prefix] >= 0} {
8309 lappend tags ${tag}result
8310 if {$diffnparents > 1} {
8311 set num [string first " " $prefix]
8313 if {$num >= $mergemax} {
8319 set words_pre_markup "{+"
8320 set words_post_markup "+}"
8322 if {$targetline ne {}} {
8323 if {$diffline == $targetline} {
8324 set diffseehere [$ctext index "end - 1 chars"]
8330 if {$dowords && $worddiff eq [mc "Markup words"]} {
8331 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8333 $ctext insert end "$line" $tags
8336 $ctext insert end "\n" $tags
8339 } elseif {$dowords && $prefix eq "~"} {
8340 $ctext insert end "\n" {}
8342 # "\ No newline at end of file",
8343 # or something else we don't recognize
8344 $ctext insert end "$line\n" hunksep
8349 proc changediffdisp {} {
8350 global ctext diffelide
8352 $ctext tag conf d0 -elide [lindex $diffelide 0]
8353 $ctext tag conf dresult -elide [lindex $diffelide 1]
8356 proc highlightfile {cline} {
8357 global cflist cflist_top
8359 if {![info exists cflist_top]} return
8361 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8362 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8363 $cflist see $cline.0
8364 set cflist_top $cline
8367 proc highlightfile_for_scrollpos {topidx} {
8368 global cmitmode difffilestart
8370 if {$cmitmode eq "tree"} return
8371 if {![info exists difffilestart]} return
8373 set top [lindex [split $topidx .] 0]
8374 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8377 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8382 global difffilestart ctext cmitmode
8384 if {$cmitmode eq "tree"} return
8386 set here [$ctext index @0,0]
8387 foreach loc $difffilestart {
8388 if {[$ctext compare $loc >= $here]} {
8398 global difffilestart ctext cmitmode
8400 if {$cmitmode eq "tree"} return
8401 set here [$ctext index @0,0]
8402 foreach loc $difffilestart {
8403 if {[$ctext compare $loc > $here]} {
8410 proc clear_ctext {{first 1.0}} {
8411 global ctext smarktop smarkbot
8412 global ctext_file_names ctext_file_lines
8415 set l [lindex [split $first .] 0]
8416 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8419 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8422 $ctext delete $first end
8423 if {$first eq "1.0"} {
8424 unset -nocomplain pendinglinks
8426 set ctext_file_names {}
8427 set ctext_file_lines {}
8430 proc settabs {{firstab {}}} {
8431 global firsttabstop tabstop ctext have_tk85
8433 if {$firstab ne {} && $have_tk85} {
8434 set firsttabstop $firstab
8436 set w [font measure textfont "0"]
8437 if {$firsttabstop != 0} {
8438 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8439 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8440 } elseif {$have_tk85 || $tabstop != 8} {
8441 $ctext conf -tabs [expr {$tabstop * $w}]
8443 $ctext conf -tabs {}
8447 proc incrsearch {name ix op} {
8448 global ctext searchstring searchdirn
8450 if {[catch {$ctext index anchor}]} {
8451 # no anchor set, use start of selection, or of visible area
8452 set sel [$ctext tag ranges sel]
8454 $ctext mark set anchor [lindex $sel 0]
8455 } elseif {$searchdirn eq "-forwards"} {
8456 $ctext mark set anchor @0,0
8458 $ctext mark set anchor @0,[winfo height $ctext]
8461 if {$searchstring ne {}} {
8462 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8465 set mend "$here + $mlen c"
8466 $ctext tag remove sel 1.0 end
8467 $ctext tag add sel $here $mend
8468 suppress_highlighting_file_for_current_scrollpos
8469 highlightfile_for_scrollpos $here
8472 rehighlight_search_results
8476 global sstring ctext searchstring searchdirn
8479 $sstring icursor end
8480 set searchdirn -forwards
8481 if {$searchstring ne {}} {
8482 set sel [$ctext tag ranges sel]
8484 set start "[lindex $sel 0] + 1c"
8485 } elseif {[catch {set start [$ctext index anchor]}]} {
8488 set match [$ctext search -count mlen -- $searchstring $start]
8489 $ctext tag remove sel 1.0 end
8495 suppress_highlighting_file_for_current_scrollpos
8496 highlightfile_for_scrollpos $match
8497 set mend "$match + $mlen c"
8498 $ctext tag add sel $match $mend
8499 $ctext mark unset anchor
8500 rehighlight_search_results
8504 proc dosearchback {} {
8505 global sstring ctext searchstring searchdirn
8508 $sstring icursor end
8509 set searchdirn -backwards
8510 if {$searchstring ne {}} {
8511 set sel [$ctext tag ranges sel]
8513 set start [lindex $sel 0]
8514 } elseif {[catch {set start [$ctext index anchor]}]} {
8515 set start @0,[winfo height $ctext]
8517 set match [$ctext search -backwards -count ml -- $searchstring $start]
8518 $ctext tag remove sel 1.0 end
8524 suppress_highlighting_file_for_current_scrollpos
8525 highlightfile_for_scrollpos $match
8526 set mend "$match + $ml c"
8527 $ctext tag add sel $match $mend
8528 $ctext mark unset anchor
8529 rehighlight_search_results
8533 proc rehighlight_search_results {} {
8534 global ctext searchstring
8536 $ctext tag remove found 1.0 end
8537 $ctext tag remove currentsearchhit 1.0 end
8539 if {$searchstring ne {}} {
8544 proc searchmark {first last} {
8545 global ctext searchstring
8547 set sel [$ctext tag ranges sel]
8551 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8552 if {$match eq {}} break
8553 set mend "$match + $mlen c"
8554 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8555 $ctext tag add currentsearchhit $match $mend
8557 $ctext tag add found $match $mend
8562 proc searchmarkvisible {doall} {
8563 global ctext smarktop smarkbot
8565 set topline [lindex [split [$ctext index @0,0] .] 0]
8566 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8567 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8568 # no overlap with previous
8569 searchmark $topline $botline
8570 set smarktop $topline
8571 set smarkbot $botline
8573 if {$topline < $smarktop} {
8574 searchmark $topline [expr {$smarktop-1}]
8575 set smarktop $topline
8577 if {$botline > $smarkbot} {
8578 searchmark [expr {$smarkbot+1}] $botline
8579 set smarkbot $botline
8584 proc suppress_highlighting_file_for_current_scrollpos {} {
8585 global ctext suppress_highlighting_file_for_this_scrollpos
8587 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8590 proc scrolltext {f0 f1} {
8591 global searchstring cmitmode ctext
8592 global suppress_highlighting_file_for_this_scrollpos
8594 set topidx [$ctext index @0,0]
8595 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8596 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8597 highlightfile_for_scrollpos $topidx
8600 unset -nocomplain suppress_highlighting_file_for_this_scrollpos
8602 .bleft.bottom.sb set $f0 $f1
8603 if {$searchstring ne {}} {
8609 global linespc charspc canvx0 canvy0
8610 global xspc1 xspc2 lthickness
8612 set linespc [font metrics mainfont -linespace]
8613 set charspc [font measure mainfont "m"]
8614 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8615 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8616 set lthickness [expr {int($linespc / 9) + 1}]
8617 set xspc1(0) $linespc
8625 set ymax [lindex [$canv cget -scrollregion] 3]
8626 if {$ymax eq {} || $ymax == 0} return
8627 set span [$canv yview]
8630 allcanvs yview moveto [lindex $span 0]
8632 if {$selectedline ne {}} {
8633 selectline $selectedline 0
8634 allcanvs yview moveto [lindex $span 0]
8638 proc parsefont {f n} {
8641 set fontattr($f,family) [lindex $n 0]
8643 if {$s eq {} || $s == 0} {
8646 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8648 set fontattr($f,size) $s
8649 set fontattr($f,weight) normal
8650 set fontattr($f,slant) roman
8651 foreach style [lrange $n 2 end] {
8654 "bold" {set fontattr($f,weight) $style}
8656 "italic" {set fontattr($f,slant) $style}
8661 proc fontflags {f {isbold 0}} {
8664 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8665 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8666 -slant $fontattr($f,slant)]
8672 set n [list $fontattr($f,family) $fontattr($f,size)]
8673 if {$fontattr($f,weight) eq "bold"} {
8676 if {$fontattr($f,slant) eq "italic"} {
8682 proc incrfont {inc} {
8683 global mainfont textfont ctext canv cflist showrefstop
8684 global stopped entries fontattr
8687 set s $fontattr(mainfont,size)
8692 set fontattr(mainfont,size) $s
8693 font config mainfont -size $s
8694 font config mainfontbold -size $s
8695 set mainfont [fontname mainfont]
8696 set s $fontattr(textfont,size)
8701 set fontattr(textfont,size) $s
8702 font config textfont -size $s
8703 font config textfontbold -size $s
8704 set textfont [fontname textfont]
8711 global sha1entry sha1string
8712 if {[string length $sha1string] == 40} {
8713 $sha1entry delete 0 end
8717 proc sha1change {n1 n2 op} {
8718 global sha1string currentid sha1but
8719 if {$sha1string == {}
8720 || ([info exists currentid] && $sha1string == $currentid)} {
8725 if {[$sha1but cget -state] == $state} return
8726 if {$state == "normal"} {
8727 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8729 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8733 proc gotocommit {} {
8734 global sha1string tagids headids curview varcid
8736 if {$sha1string == {}
8737 || ([info exists currentid] && $sha1string == $currentid)} return
8738 if {[info exists tagids($sha1string)]} {
8739 set id $tagids($sha1string)
8740 } elseif {[info exists headids($sha1string)]} {
8741 set id $headids($sha1string)
8743 set id [string tolower $sha1string]
8744 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8745 set matches [longid $id]
8746 if {$matches ne {}} {
8747 if {[llength $matches] > 1} {
8748 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8751 set id [lindex $matches 0]
8754 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8755 error_popup [mc "Revision %s is not known" $sha1string]
8760 if {[commitinview $id $curview]} {
8761 selectline [rowofcommit $id] 1
8764 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8765 set msg [mc "SHA1 id %s is not known" $sha1string]
8767 set msg [mc "Revision %s is not in the current view" $sha1string]
8772 proc lineenter {x y id} {
8773 global hoverx hovery hoverid hovertimer
8774 global commitinfo canv
8776 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8780 if {[info exists hovertimer]} {
8781 after cancel $hovertimer
8783 set hovertimer [after 500 linehover]
8787 proc linemotion {x y id} {
8788 global hoverx hovery hoverid hovertimer
8790 if {[info exists hoverid] && $id == $hoverid} {
8793 if {[info exists hovertimer]} {
8794 after cancel $hovertimer
8796 set hovertimer [after 500 linehover]
8800 proc lineleave {id} {
8801 global hoverid hovertimer canv
8803 if {[info exists hoverid] && $id == $hoverid} {
8805 if {[info exists hovertimer]} {
8806 after cancel $hovertimer
8814 global hoverx hovery hoverid hovertimer
8815 global canv linespc lthickness
8816 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8820 set text [lindex $commitinfo($hoverid) 0]
8821 set ymax [lindex [$canv cget -scrollregion] 3]
8822 if {$ymax == {}} return
8823 set yfrac [lindex [$canv yview] 0]
8824 set x [expr {$hoverx + 2 * $linespc}]
8825 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8826 set x0 [expr {$x - 2 * $lthickness}]
8827 set y0 [expr {$y - 2 * $lthickness}]
8828 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8829 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8830 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8831 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8832 -width 1 -tags hover]
8834 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8835 -font mainfont -fill $linehoverfgcolor]
8839 proc clickisonarrow {id y} {
8842 set ranges [rowranges $id]
8843 set thresh [expr {2 * $lthickness + 6}]
8844 set n [expr {[llength $ranges] - 1}]
8845 for {set i 1} {$i < $n} {incr i} {
8846 set row [lindex $ranges $i]
8847 if {abs([yc $row] - $y) < $thresh} {
8854 proc arrowjump {id n y} {
8857 # 1 <-> 2, 3 <-> 4, etc...
8858 set n [expr {(($n - 1) ^ 1) + 1}]
8859 set row [lindex [rowranges $id] $n]
8861 set ymax [lindex [$canv cget -scrollregion] 3]
8862 if {$ymax eq {} || $ymax <= 0} return
8863 set view [$canv yview]
8864 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8865 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8869 allcanvs yview moveto $yfrac
8872 proc lineclick {x y id isnew} {
8873 global ctext commitinfo children canv thickerline curview
8875 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8880 # draw this line thicker than normal
8884 set ymax [lindex [$canv cget -scrollregion] 3]
8885 if {$ymax eq {}} return
8886 set yfrac [lindex [$canv yview] 0]
8887 set y [expr {$y + $yfrac * $ymax}]
8889 set dirn [clickisonarrow $id $y]
8891 arrowjump $id $dirn $y
8896 addtohistory [list lineclick $x $y $id 0] savectextpos
8898 # fill the details pane with info about this line
8899 $ctext conf -state normal
8902 $ctext insert end "[mc "Parent"]:\t"
8903 $ctext insert end $id link0
8905 set info $commitinfo($id)
8906 $ctext insert end "\n\t[lindex $info 0]\n"
8907 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8908 set date [formatdate [lindex $info 2]]
8909 $ctext insert end "\t[mc "Date"]:\t$date\n"
8910 set kids $children($curview,$id)
8912 $ctext insert end "\n[mc "Children"]:"
8914 foreach child $kids {
8916 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8917 set info $commitinfo($child)
8918 $ctext insert end "\n\t"
8919 $ctext insert end $child link$i
8920 setlink $child link$i
8921 $ctext insert end "\n\t[lindex $info 0]"
8922 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8923 set date [formatdate [lindex $info 2]]
8924 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8927 maybe_scroll_ctext 1
8928 $ctext conf -state disabled
8932 proc normalline {} {
8934 if {[info exists thickerline]} {
8941 proc selbyid {id {isnew 1}} {
8943 if {[commitinview $id $curview]} {
8944 selectline [rowofcommit $id] $isnew
8950 if {![info exists startmstime]} {
8951 set startmstime [clock clicks -milliseconds]
8953 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8956 proc rowmenu {x y id} {
8957 global rowctxmenu selectedline rowmenuid curview
8958 global nullid nullid2 fakerowmenu mainhead markedid
8962 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8967 if {[info exists markedid] && $markedid ne $id} {
8972 if {$id ne $nullid && $id ne $nullid2} {
8973 set menu $rowctxmenu
8974 if {$mainhead ne {}} {
8975 $menu entryconfigure 8 -label [mc "Reset %s branch to here" $mainhead] -state normal
8977 $menu entryconfigure 8 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8979 $menu entryconfigure 10 -state $mstate
8980 $menu entryconfigure 11 -state $mstate
8981 $menu entryconfigure 12 -state $mstate
8983 set menu $fakerowmenu
8985 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8986 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8987 $menu entryconfigure [mca "Make patch"] -state $state
8988 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8989 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8990 tk_popup $menu $x $y
8994 global rowmenuid markedid canv
8996 set markedid $rowmenuid
8997 make_idmark $markedid
9003 if {[info exists markedid]} {
9008 proc replace_by_kids {l r} {
9009 global curview children
9011 set id [commitonrow $r]
9012 set l [lreplace $l 0 0]
9013 foreach kid $children($curview,$id) {
9014 lappend l [rowofcommit $kid]
9016 return [lsort -integer -decreasing -unique $l]
9019 proc find_common_desc {} {
9020 global markedid rowmenuid curview children
9022 if {![info exists markedid]} return
9023 if {![commitinview $markedid $curview] ||
9024 ![commitinview $rowmenuid $curview]} return
9025 #set t1 [clock clicks -milliseconds]
9026 set l1 [list [rowofcommit $markedid]]
9027 set l2 [list [rowofcommit $rowmenuid]]
9029 set r1 [lindex $l1 0]
9030 set r2 [lindex $l2 0]
9031 if {$r1 eq {} || $r2 eq {}} break
9037 set l1 [replace_by_kids $l1 $r1]
9039 set l2 [replace_by_kids $l2 $r2]
9042 #set t2 [clock clicks -milliseconds]
9043 #puts "took [expr {$t2-$t1}]ms"
9046 proc compare_commits {} {
9047 global markedid rowmenuid curview children
9049 if {![info exists markedid]} return
9050 if {![commitinview $markedid $curview]} return
9051 addtohistory [list do_cmp_commits $markedid $rowmenuid]
9052 do_cmp_commits $markedid $rowmenuid
9055 proc getpatchid {id} {
9058 if {![info exists patchids($id)]} {
9059 set cmd [diffcmd [list $id] {-p --root}]
9060 # trim off the initial "|"
9061 set cmd [lrange $cmd 1 end]
9063 set x [eval exec $cmd | git patch-id]
9064 set patchids($id) [lindex $x 0]
9066 set patchids($id) "error"
9069 return $patchids($id)
9072 proc do_cmp_commits {a b} {
9073 global ctext curview parents children patchids commitinfo
9075 $ctext conf -state normal
9078 for {set i 0} {$i < 100} {incr i} {
9081 if {[llength $parents($curview,$a)] > 1} {
9082 appendshortlink $a [mc "Skipping merge commit "] "\n"
9085 set patcha [getpatchid $a]
9087 if {[llength $parents($curview,$b)] > 1} {
9088 appendshortlink $b [mc "Skipping merge commit "] "\n"
9091 set patchb [getpatchid $b]
9093 if {!$skipa && !$skipb} {
9094 set heada [lindex $commitinfo($a) 0]
9095 set headb [lindex $commitinfo($b) 0]
9096 if {$patcha eq "error"} {
9097 appendshortlink $a [mc "Error getting patch ID for "] \
9098 [mc " - stopping\n"]
9101 if {$patchb eq "error"} {
9102 appendshortlink $b [mc "Error getting patch ID for "] \
9103 [mc " - stopping\n"]
9106 if {$patcha eq $patchb} {
9107 if {$heada eq $headb} {
9108 appendshortlink $a [mc "Commit "]
9109 appendshortlink $b " == " " $heada\n"
9111 appendshortlink $a [mc "Commit "] " $heada\n"
9112 appendshortlink $b [mc " is the same patch as\n "] \
9118 $ctext insert end "\n"
9119 appendshortlink $a [mc "Commit "] " $heada\n"
9120 appendshortlink $b [mc " differs from\n "] \
9122 $ctext insert end [mc "Diff of commits:\n\n"]
9123 $ctext conf -state disabled
9130 set kids [real_children $curview,$a]
9131 if {[llength $kids] != 1} {
9132 $ctext insert end "\n"
9133 appendshortlink $a [mc "Commit "] \
9134 [mc " has %s children - stopping\n" [llength $kids]]
9137 set a [lindex $kids 0]
9140 set kids [real_children $curview,$b]
9141 if {[llength $kids] != 1} {
9142 appendshortlink $b [mc "Commit "] \
9143 [mc " has %s children - stopping\n" [llength $kids]]
9146 set b [lindex $kids 0]
9149 $ctext conf -state disabled
9152 proc diffcommits {a b} {
9153 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
9155 set tmpdir [gitknewtmpdir]
9156 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
9157 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
9159 exec git diff-tree -p --pretty $a >$fna
9160 exec git diff-tree -p --pretty $b >$fnb
9162 error_popup [mc "Error writing commit to file: %s" $err]
9166 set fd [open "| diff -U$diffcontext $fna $fnb" r]
9168 error_popup [mc "Error diffing commits: %s" $err]
9171 set diffids [list commits $a $b]
9172 set blobdifffd($diffids) $fd
9174 set currdiffsubmod ""
9175 filerun $fd [list getblobdiffline $fd $diffids]
9178 proc diffvssel {dirn} {
9179 global rowmenuid selectedline
9181 if {$selectedline eq {}} return
9183 set oldid [commitonrow $selectedline]
9184 set newid $rowmenuid
9186 set oldid $rowmenuid
9187 set newid [commitonrow $selectedline]
9189 addtohistory [list doseldiff $oldid $newid] savectextpos
9190 doseldiff $oldid $newid
9193 proc diffvsmark {dirn} {
9194 global rowmenuid markedid
9196 if {![info exists markedid]} return
9199 set newid $rowmenuid
9201 set oldid $rowmenuid
9204 addtohistory [list doseldiff $oldid $newid] savectextpos
9205 doseldiff $oldid $newid
9208 proc doseldiff {oldid newid} {
9212 $ctext conf -state normal
9214 init_flist [mc "Top"]
9215 $ctext insert end "[mc "From"] "
9216 $ctext insert end $oldid link0
9217 setlink $oldid link0
9218 $ctext insert end "\n "
9219 $ctext insert end [lindex $commitinfo($oldid) 0]
9220 $ctext insert end "\n\n[mc "To"] "
9221 $ctext insert end $newid link1
9222 setlink $newid link1
9223 $ctext insert end "\n "
9224 $ctext insert end [lindex $commitinfo($newid) 0]
9225 $ctext insert end "\n"
9226 $ctext conf -state disabled
9227 $ctext tag remove found 1.0 end
9228 startdiff [list $oldid $newid]
9232 global rowmenuid currentid commitinfo patchtop patchnum NS
9234 if {![info exists currentid]} return
9235 set oldid $currentid
9236 set oldhead [lindex $commitinfo($oldid) 0]
9237 set newid $rowmenuid
9238 set newhead [lindex $commitinfo($newid) 0]
9241 catch {destroy $top}
9243 make_transient $top .
9244 ${NS}::label $top.title -text [mc "Generate patch"]
9245 grid $top.title - -pady 10
9246 ${NS}::label $top.from -text [mc "From:"]
9247 ${NS}::entry $top.fromsha1 -width 40
9248 $top.fromsha1 insert 0 $oldid
9249 $top.fromsha1 conf -state readonly
9250 grid $top.from $top.fromsha1 -sticky w
9251 ${NS}::entry $top.fromhead -width 60
9252 $top.fromhead insert 0 $oldhead
9253 $top.fromhead conf -state readonly
9254 grid x $top.fromhead -sticky w
9255 ${NS}::label $top.to -text [mc "To:"]
9256 ${NS}::entry $top.tosha1 -width 40
9257 $top.tosha1 insert 0 $newid
9258 $top.tosha1 conf -state readonly
9259 grid $top.to $top.tosha1 -sticky w
9260 ${NS}::entry $top.tohead -width 60
9261 $top.tohead insert 0 $newhead
9262 $top.tohead conf -state readonly
9263 grid x $top.tohead -sticky w
9264 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9265 grid $top.rev x -pady 10 -padx 5
9266 ${NS}::label $top.flab -text [mc "Output file:"]
9267 ${NS}::entry $top.fname -width 60
9268 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9270 grid $top.flab $top.fname -sticky w
9271 ${NS}::frame $top.buts
9272 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9273 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9274 bind $top <Key-Return> mkpatchgo
9275 bind $top <Key-Escape> mkpatchcan
9276 grid $top.buts.gen $top.buts.can
9277 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9278 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9279 grid $top.buts - -pady 10 -sticky ew
9283 proc mkpatchrev {} {
9286 set oldid [$patchtop.fromsha1 get]
9287 set oldhead [$patchtop.fromhead get]
9288 set newid [$patchtop.tosha1 get]
9289 set newhead [$patchtop.tohead get]
9290 foreach e [list fromsha1 fromhead tosha1 tohead] \
9291 v [list $newid $newhead $oldid $oldhead] {
9292 $patchtop.$e conf -state normal
9293 $patchtop.$e delete 0 end
9294 $patchtop.$e insert 0 $v
9295 $patchtop.$e conf -state readonly
9300 global patchtop nullid nullid2
9302 set oldid [$patchtop.fromsha1 get]
9303 set newid [$patchtop.tosha1 get]
9304 set fname [$patchtop.fname get]
9305 set cmd [diffcmd [list $oldid $newid] -p]
9306 # trim off the initial "|"
9307 set cmd [lrange $cmd 1 end]
9308 lappend cmd >$fname &
9309 if {[catch {eval exec $cmd} err]} {
9310 error_popup "[mc "Error creating patch:"] $err" $patchtop
9312 catch {destroy $patchtop}
9316 proc mkpatchcan {} {
9319 catch {destroy $patchtop}
9324 global rowmenuid mktagtop commitinfo NS
9328 catch {destroy $top}
9330 make_transient $top .
9331 ${NS}::label $top.title -text [mc "Create tag"]
9332 grid $top.title - -pady 10
9333 ${NS}::label $top.id -text [mc "ID:"]
9334 ${NS}::entry $top.sha1 -width 40
9335 $top.sha1 insert 0 $rowmenuid
9336 $top.sha1 conf -state readonly
9337 grid $top.id $top.sha1 -sticky w
9338 ${NS}::entry $top.head -width 60
9339 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9340 $top.head conf -state readonly
9341 grid x $top.head -sticky w
9342 ${NS}::label $top.tlab -text [mc "Tag name:"]
9343 ${NS}::entry $top.tag -width 60
9344 grid $top.tlab $top.tag -sticky w
9345 ${NS}::label $top.op -text [mc "Tag message is optional"]
9346 grid $top.op -columnspan 2 -sticky we
9347 ${NS}::label $top.mlab -text [mc "Tag message:"]
9348 ${NS}::entry $top.msg -width 60
9349 grid $top.mlab $top.msg -sticky w
9350 ${NS}::frame $top.buts
9351 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9352 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9353 bind $top <Key-Return> mktaggo
9354 bind $top <Key-Escape> mktagcan
9355 grid $top.buts.gen $top.buts.can
9356 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9357 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9358 grid $top.buts - -pady 10 -sticky ew
9363 global mktagtop env tagids idtags
9365 set id [$mktagtop.sha1 get]
9366 set tag [$mktagtop.tag get]
9367 set msg [$mktagtop.msg get]
9369 error_popup [mc "No tag name specified"] $mktagtop
9372 if {[info exists tagids($tag)]} {
9373 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9378 exec git tag -a -m $msg $tag $id
9380 exec git tag $tag $id
9383 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9387 set tagids($tag) $id
9388 lappend idtags($id) $tag
9396 proc redrawtags {id} {
9397 global canv linehtag idpos currentid curview cmitlisted markedid
9398 global canvxmax iddrawn circleitem mainheadid circlecolors
9399 global mainheadcirclecolor
9401 if {![commitinview $id $curview]} return
9402 if {![info exists iddrawn($id)]} return
9403 set row [rowofcommit $id]
9404 if {$id eq $mainheadid} {
9405 set ofill $mainheadcirclecolor
9407 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9409 $canv itemconf $circleitem($row) -fill $ofill
9410 $canv delete tag.$id
9411 set xt [eval drawtags $id $idpos($id)]
9412 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9413 set text [$canv itemcget $linehtag($id) -text]
9414 set font [$canv itemcget $linehtag($id) -font]
9415 set xr [expr {$xt + [font measure $font $text]}]
9416 if {$xr > $canvxmax} {
9420 if {[info exists currentid] && $currentid == $id} {
9423 if {[info exists markedid] && $markedid eq $id} {
9431 catch {destroy $mktagtop}
9436 if {![domktag]} return
9440 proc copyreference {} {
9441 global rowmenuid autosellen
9443 set format "%h (\"%s\", %ad)"
9444 set cmd [list git show -s --pretty=format:$format --date=short]
9445 if {$autosellen < 40} {
9446 lappend cmd --abbrev=$autosellen
9448 set reference [eval exec $cmd $rowmenuid]
9451 clipboard append $reference
9454 proc writecommit {} {
9455 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9457 set top .writecommit
9459 catch {destroy $top}
9461 make_transient $top .
9462 ${NS}::label $top.title -text [mc "Write commit to file"]
9463 grid $top.title - -pady 10
9464 ${NS}::label $top.id -text [mc "ID:"]
9465 ${NS}::entry $top.sha1 -width 40
9466 $top.sha1 insert 0 $rowmenuid
9467 $top.sha1 conf -state readonly
9468 grid $top.id $top.sha1 -sticky w
9469 ${NS}::entry $top.head -width 60
9470 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9471 $top.head conf -state readonly
9472 grid x $top.head -sticky w
9473 ${NS}::label $top.clab -text [mc "Command:"]
9474 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9475 grid $top.clab $top.cmd -sticky w -pady 10
9476 ${NS}::label $top.flab -text [mc "Output file:"]
9477 ${NS}::entry $top.fname -width 60
9478 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9479 grid $top.flab $top.fname -sticky w
9480 ${NS}::frame $top.buts
9481 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9482 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9483 bind $top <Key-Return> wrcomgo
9484 bind $top <Key-Escape> wrcomcan
9485 grid $top.buts.gen $top.buts.can
9486 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9487 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9488 grid $top.buts - -pady 10 -sticky ew
9495 set id [$wrcomtop.sha1 get]
9496 set cmd "echo $id | [$wrcomtop.cmd get]"
9497 set fname [$wrcomtop.fname get]
9498 if {[catch {exec sh -c $cmd >$fname &} err]} {
9499 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9501 catch {destroy $wrcomtop}
9508 catch {destroy $wrcomtop}
9515 set top .branchdialog
9518 set val(id) $rowmenuid
9519 set val(command) [list mkbrgo $top]
9521 set ui(title) [mc "Create branch"]
9522 set ui(accept) [mc "Create"]
9524 branchdia $top val ui
9529 global headmenuid headmenuhead
9531 set top .branchdialog
9533 set val(name) $headmenuhead
9534 set val(id) $headmenuid
9535 set val(command) [list mvbrgo $top $headmenuhead]
9537 set ui(title) [mc "Rename branch %s" $headmenuhead]
9538 set ui(accept) [mc "Rename"]
9540 branchdia $top val ui
9543 proc branchdia {top valvar uivar} {
9544 global NS commitinfo
9545 upvar $valvar val $uivar ui
9547 catch {destroy $top}
9549 make_transient $top .
9550 ${NS}::label $top.title -text $ui(title)
9551 grid $top.title - -pady 10
9552 ${NS}::label $top.id -text [mc "ID:"]
9553 ${NS}::entry $top.sha1 -width 40
9554 $top.sha1 insert 0 $val(id)
9555 $top.sha1 conf -state readonly
9556 grid $top.id $top.sha1 -sticky w
9557 ${NS}::entry $top.head -width 60
9558 $top.head insert 0 [lindex $commitinfo($val(id)) 0]
9559 $top.head conf -state readonly
9560 grid x $top.head -sticky ew
9561 grid columnconfigure $top 1 -weight 1
9562 ${NS}::label $top.nlab -text [mc "Name:"]
9563 ${NS}::entry $top.name -width 40
9564 $top.name insert 0 $val(name)
9565 grid $top.nlab $top.name -sticky w
9566 ${NS}::frame $top.buts
9567 ${NS}::button $top.buts.go -text $ui(accept) -command $val(command)
9568 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9569 bind $top <Key-Return> $val(command)
9570 bind $top <Key-Escape> "catch {destroy $top}"
9571 grid $top.buts.go $top.buts.can
9572 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9573 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9574 grid $top.buts - -pady 10 -sticky ew
9579 global headids idheads
9581 set name [$top.name get]
9582 set id [$top.sha1 get]
9586 error_popup [mc "Please specify a name for the new branch"] $top
9589 if {[info exists headids($name)]} {
9590 if {![confirm_popup [mc \
9591 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9594 set old_id $headids($name)
9597 catch {destroy $top}
9598 lappend cmdargs $name $id
9602 eval exec git branch $cmdargs
9608 if {$old_id ne {}} {
9614 set headids($name) $id
9615 lappend idheads($id) $name
9624 proc mvbrgo {top prevname} {
9625 global headids idheads mainhead mainheadid
9627 set name [$top.name get]
9628 set id [$top.sha1 get]
9630 if {$name eq $prevname} {
9631 catch {destroy $top}
9635 error_popup [mc "Please specify a new name for the branch"] $top
9638 catch {destroy $top}
9639 lappend cmdargs -m $prevname $name
9640 nowbusy renamebranch
9643 eval exec git branch $cmdargs
9645 notbusy renamebranch
9648 notbusy renamebranch
9649 removehead $id $prevname
9650 removedhead $id $prevname
9651 set headids($name) $id
9652 lappend idheads($id) $name
9654 if {$prevname eq $mainhead} {
9664 proc exec_citool {tool_args {baseid {}}} {
9665 global commitinfo env
9667 set save_env [array get env GIT_AUTHOR_*]
9669 if {$baseid ne {}} {
9670 if {![info exists commitinfo($baseid)]} {
9673 set author [lindex $commitinfo($baseid) 1]
9674 set date [lindex $commitinfo($baseid) 2]
9675 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9676 $author author name email]
9678 set env(GIT_AUTHOR_NAME) $name
9679 set env(GIT_AUTHOR_EMAIL) $email
9680 set env(GIT_AUTHOR_DATE) $date
9684 eval exec git citool $tool_args &
9686 array unset env GIT_AUTHOR_*
9687 array set env $save_env
9690 proc cherrypick {} {
9691 global rowmenuid curview
9692 global mainhead mainheadid
9695 set oldhead [exec git rev-parse HEAD]
9696 set dheads [descheads $rowmenuid]
9697 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9698 set ok [confirm_popup [mc "Commit %s is already\
9699 included in branch %s -- really re-apply it?" \
9700 [string range $rowmenuid 0 7] $mainhead]]
9703 nowbusy cherrypick [mc "Cherry-picking"]
9705 # Unfortunately git-cherry-pick writes stuff to stderr even when
9706 # no error occurs, and exec takes that as an indication of error...
9707 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9710 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9712 error_popup [mc "Cherry-pick failed because of local changes\
9713 to file '%s'.\nPlease commit, reset or stash\
9714 your changes and try again." $fname]
9715 } elseif {[regexp -line \
9716 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9718 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9719 conflict.\nDo you wish to run git citool to\
9721 # Force citool to read MERGE_MSG
9722 file delete [file join $gitdir "GITGUI_MSG"]
9723 exec_citool {} $rowmenuid
9731 set newhead [exec git rev-parse HEAD]
9732 if {$newhead eq $oldhead} {
9734 error_popup [mc "No changes committed"]
9737 addnewchild $newhead $oldhead
9738 if {[commitinview $oldhead $curview]} {
9739 # XXX this isn't right if we have a path limit...
9740 insertrow $newhead $oldhead $curview
9741 if {$mainhead ne {}} {
9742 movehead $newhead $mainhead
9743 movedhead $newhead $mainhead
9745 set mainheadid $newhead
9754 global rowmenuid curview
9755 global mainhead mainheadid
9758 set oldhead [exec git rev-parse HEAD]
9759 set dheads [descheads $rowmenuid]
9760 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9761 set ok [confirm_popup [mc "Commit %s is not\
9762 included in branch %s -- really revert it?" \
9763 [string range $rowmenuid 0 7] $mainhead]]
9766 nowbusy revert [mc "Reverting"]
9769 if [catch {exec git revert --no-edit $rowmenuid} err] {
9771 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9773 regsub {\n( |\t)+} $files "\n" files
9774 error_popup [mc "Revert failed because of local changes to\
9775 the following files:%s Please commit, reset or stash \
9776 your changes and try again." $files]
9777 } elseif [regexp {error: could not revert} $err] {
9778 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9779 Do you wish to run git citool to resolve it?"]] {
9780 # Force citool to read MERGE_MSG
9781 file delete [file join $gitdir "GITGUI_MSG"]
9782 exec_citool {} $rowmenuid
9784 } else { error_popup $err }
9789 set newhead [exec git rev-parse HEAD]
9790 if { $newhead eq $oldhead } {
9792 error_popup [mc "No changes committed"]
9796 addnewchild $newhead $oldhead
9798 if [commitinview $oldhead $curview] {
9799 # XXX this isn't right if we have a path limit...
9800 insertrow $newhead $oldhead $curview
9801 if {$mainhead ne {}} {
9802 movehead $newhead $mainhead
9803 movedhead $newhead $mainhead
9805 set mainheadid $newhead
9815 global mainhead rowmenuid confirm_ok resettype NS
9818 set w ".confirmreset"
9821 wm title $w [mc "Confirm reset"]
9822 ${NS}::label $w.m -text \
9823 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9824 pack $w.m -side top -fill x -padx 20 -pady 20
9825 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9827 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9828 -text [mc "Soft: Leave working tree and index untouched"]
9829 grid $w.f.soft -sticky w
9830 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9831 -text [mc "Mixed: Leave working tree untouched, reset index"]
9832 grid $w.f.mixed -sticky w
9833 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9834 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9835 grid $w.f.hard -sticky w
9836 pack $w.f -side top -fill x -padx 4
9837 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9838 pack $w.ok -side left -fill x -padx 20 -pady 20
9839 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9840 bind $w <Key-Escape> [list destroy $w]
9841 pack $w.cancel -side right -fill x -padx 20 -pady 20
9842 bind $w <Visibility> "grab $w; focus $w"
9844 if {!$confirm_ok} return
9845 if {[catch {set fd [open \
9846 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9850 filerun $fd [list readresetstat $fd]
9851 nowbusy reset [mc "Resetting"]
9856 proc readresetstat {fd} {
9857 global mainhead mainheadid showlocalchanges rprogcoord
9859 if {[gets $fd line] >= 0} {
9860 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9861 set rprogcoord [expr {1.0 * $m / $n}]
9869 if {[catch {close $fd} err]} {
9872 set oldhead $mainheadid
9873 set newhead [exec git rev-parse HEAD]
9874 if {$newhead ne $oldhead} {
9875 movehead $newhead $mainhead
9876 movedhead $newhead $mainhead
9877 set mainheadid $newhead
9881 if {$showlocalchanges} {
9887 # context menu for a head
9888 proc headmenu {x y id head} {
9889 global headmenuid headmenuhead headctxmenu mainhead headids
9893 set headmenuhead $head
9894 array set state {0 normal 1 normal 2 normal}
9895 if {[string match "remotes/*" $head]} {
9896 set localhead [string range $head [expr [string last / $head] + 1] end]
9897 if {[info exists headids($localhead)]} {
9898 set state(0) disabled
9900 array set state {1 disabled 2 disabled}
9902 if {$head eq $mainhead} {
9903 array set state {0 disabled 2 disabled}
9906 $headctxmenu entryconfigure $i -state $state($i)
9908 tk_popup $headctxmenu $x $y
9912 global headmenuid headmenuhead headids
9913 global showlocalchanges
9915 # check the tree is clean first??
9916 set newhead $headmenuhead
9917 set command [list | git checkout]
9918 if {[string match "remotes/*" $newhead]} {
9920 set newhead [string range $newhead [expr [string last / $newhead] + 1] end]
9921 # The following check is redundant - the menu option should
9922 # be disabled to begin with...
9923 if {[info exists headids($newhead)]} {
9924 error_popup [mc "A local branch named %s exists already" $newhead]
9927 lappend command -b $newhead --track $remote
9929 lappend command $newhead
9931 lappend command 2>@1
9932 nowbusy checkout [mc "Checking out"]
9936 set fd [open $command r]
9940 if {$showlocalchanges} {
9944 filerun $fd [list readcheckoutstat $fd $newhead $headmenuid]
9948 proc readcheckoutstat {fd newhead newheadid} {
9949 global mainhead mainheadid headids idheads showlocalchanges progresscoords
9950 global viewmainheadid curview
9952 if {[gets $fd line] >= 0} {
9953 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9954 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9959 set progresscoords {0 0}
9962 if {[catch {close $fd} err]} {
9966 set oldmainid $mainheadid
9967 if {! [info exists headids($newhead)]} {
9968 set headids($newhead) $newheadid
9969 lappend idheads($newheadid) $newhead
9970 addedhead $newheadid $newhead
9972 set mainhead $newhead
9973 set mainheadid $newheadid
9974 set viewmainheadid($curview) $newheadid
9975 redrawtags $oldmainid
9976 redrawtags $newheadid
9978 if {$showlocalchanges} {
9984 global headmenuid headmenuhead mainhead
9987 set head $headmenuhead
9989 # this check shouldn't be needed any more...
9990 if {$head eq $mainhead} {
9991 error_popup [mc "Cannot delete the currently checked-out branch"]
9994 set dheads [descheads $id]
9995 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9996 # the stuff on this branch isn't on any other branch
9997 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9998 branch.\nReally delete branch %s?" $head $head]]} return
10002 if {[catch {exec git branch -D $head} err]} {
10007 removehead $id $head
10008 removedhead $id $head
10015 # Display a list of tags and heads
10017 global showrefstop bgcolor fgcolor selectbgcolor NS
10018 global bglist fglist reflistfilter reflist maincursor
10021 set showrefstop $top
10022 if {[winfo exists $top]} {
10028 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
10029 make_transient $top .
10030 text $top.list -background $bgcolor -foreground $fgcolor \
10031 -selectbackground $selectbgcolor -font mainfont \
10032 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
10033 -width 30 -height 20 -cursor $maincursor \
10034 -spacing1 1 -spacing3 1 -state disabled
10035 $top.list tag configure highlight -background $selectbgcolor
10036 if {![lsearch -exact $bglist $top.list]} {
10037 lappend bglist $top.list
10038 lappend fglist $top.list
10040 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
10041 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
10042 grid $top.list $top.ysb -sticky nsew
10043 grid $top.xsb x -sticky ew
10044 ${NS}::frame $top.f
10045 ${NS}::label $top.f.l -text "[mc "Filter"]: "
10046 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
10047 set reflistfilter "*"
10048 trace add variable reflistfilter write reflistfilter_change
10049 pack $top.f.e -side right -fill x -expand 1
10050 pack $top.f.l -side left
10051 grid $top.f - -sticky ew -pady 2
10052 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
10053 bind $top <Key-Escape> [list destroy $top]
10055 grid columnconfigure $top 0 -weight 1
10056 grid rowconfigure $top 0 -weight 1
10057 bind $top.list <1> {break}
10058 bind $top.list <B1-Motion> {break}
10059 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
10064 proc sel_reflist {w x y} {
10065 global showrefstop reflist headids tagids otherrefids
10067 if {![winfo exists $showrefstop]} return
10068 set l [lindex [split [$w index "@$x,$y"] "."] 0]
10069 set ref [lindex $reflist [expr {$l-1}]]
10070 set n [lindex $ref 0]
10071 switch -- [lindex $ref 1] {
10072 "H" {selbyid $headids($n)}
10073 "R" {selbyid $headids($n)}
10074 "T" {selbyid $tagids($n)}
10075 "o" {selbyid $otherrefids($n)}
10077 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
10080 proc unsel_reflist {} {
10083 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
10084 $showrefstop.list tag remove highlight 0.0 end
10087 proc reflistfilter_change {n1 n2 op} {
10088 global reflistfilter
10090 after cancel refill_reflist
10091 after 200 refill_reflist
10094 proc refill_reflist {} {
10095 global reflist reflistfilter showrefstop headids tagids otherrefids
10098 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
10100 foreach n [array names headids] {
10101 if {[string match $reflistfilter $n]} {
10102 if {[commitinview $headids($n) $curview]} {
10103 if {[string match "remotes/*" $n]} {
10104 lappend refs [list $n R]
10106 lappend refs [list $n H]
10109 interestedin $headids($n) {run refill_reflist}
10113 foreach n [array names tagids] {
10114 if {[string match $reflistfilter $n]} {
10115 if {[commitinview $tagids($n) $curview]} {
10116 lappend refs [list $n T]
10118 interestedin $tagids($n) {run refill_reflist}
10122 foreach n [array names otherrefids] {
10123 if {[string match $reflistfilter $n]} {
10124 if {[commitinview $otherrefids($n) $curview]} {
10125 lappend refs [list $n o]
10127 interestedin $otherrefids($n) {run refill_reflist}
10131 set refs [lsort -index 0 $refs]
10132 if {$refs eq $reflist} return
10134 # Update the contents of $showrefstop.list according to the
10135 # differences between $reflist (old) and $refs (new)
10136 $showrefstop.list conf -state normal
10137 $showrefstop.list insert end "\n"
10140 while {$i < [llength $reflist] || $j < [llength $refs]} {
10141 if {$i < [llength $reflist]} {
10142 if {$j < [llength $refs]} {
10143 set cmp [string compare [lindex $reflist $i 0] \
10144 [lindex $refs $j 0]]
10146 set cmp [string compare [lindex $reflist $i 1] \
10147 [lindex $refs $j 1]]
10157 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
10165 set l [expr {$j + 1}]
10166 $showrefstop.list image create $l.0 -align baseline \
10167 -image reficon-[lindex $refs $j 1] -padx 2
10168 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
10174 # delete last newline
10175 $showrefstop.list delete end-2c end-1c
10176 $showrefstop.list conf -state disabled
10179 # Stuff for finding nearby tags
10180 proc getallcommits {} {
10181 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
10182 global idheads idtags idotherrefs allparents tagobjid
10185 if {![info exists allcommits]} {
10191 set allccache [file join $gitdir "gitk.cache"]
10193 set f [open $allccache r]
10202 set cmd [list | git rev-list --parents]
10203 set allcupdate [expr {$seeds ne {}}]
10204 if {!$allcupdate} {
10207 set refs [concat [array names idheads] [array names idtags] \
10208 [array names idotherrefs]]
10211 foreach name [array names tagobjid] {
10212 lappend tagobjs $tagobjid($name)
10214 foreach id [lsort -unique $refs] {
10215 if {![info exists allparents($id)] &&
10216 [lsearch -exact $tagobjs $id] < 0} {
10221 foreach id $seeds {
10227 set fd [open [concat $cmd $ids] r]
10228 fconfigure $fd -blocking 0
10231 filerun $fd [list getallclines $fd]
10237 # Since most commits have 1 parent and 1 child, we group strings of
10238 # such commits into "arcs" joining branch/merge points (BMPs), which
10239 # are commits that either don't have 1 parent or don't have 1 child.
10241 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
10242 # arcout(id) - outgoing arcs for BMP
10243 # arcids(a) - list of IDs on arc including end but not start
10244 # arcstart(a) - BMP ID at start of arc
10245 # arcend(a) - BMP ID at end of arc
10246 # growing(a) - arc a is still growing
10247 # arctags(a) - IDs out of arcids (excluding end) that have tags
10248 # archeads(a) - IDs out of arcids (excluding end) that have heads
10249 # The start of an arc is at the descendent end, so "incoming" means
10250 # coming from descendents, and "outgoing" means going towards ancestors.
10252 proc getallclines {fd} {
10253 global allparents allchildren idtags idheads nextarc
10254 global arcnos arcids arctags arcout arcend arcstart archeads growing
10255 global seeds allcommits cachedarcs allcupdate
10258 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
10259 set id [lindex $line 0]
10260 if {[info exists allparents($id)]} {
10265 set olds [lrange $line 1 end]
10266 set allparents($id) $olds
10267 if {![info exists allchildren($id)]} {
10268 set allchildren($id) {}
10273 if {[llength $olds] == 1 && [llength $a] == 1} {
10274 lappend arcids($a) $id
10275 if {[info exists idtags($id)]} {
10276 lappend arctags($a) $id
10278 if {[info exists idheads($id)]} {
10279 lappend archeads($a) $id
10281 if {[info exists allparents($olds)]} {
10282 # seen parent already
10283 if {![info exists arcout($olds)]} {
10286 lappend arcids($a) $olds
10287 set arcend($a) $olds
10290 lappend allchildren($olds) $id
10291 lappend arcnos($olds) $a
10295 foreach a $arcnos($id) {
10296 lappend arcids($a) $id
10303 lappend allchildren($p) $id
10304 set a [incr nextarc]
10305 set arcstart($a) $id
10306 set archeads($a) {}
10308 set archeads($a) {}
10312 if {[info exists allparents($p)]} {
10313 # seen it already, may need to make a new branch
10314 if {![info exists arcout($p)]} {
10317 lappend arcids($a) $p
10321 lappend arcnos($p) $a
10323 set arcout($id) $ao
10326 global cached_dheads cached_dtags cached_atags
10327 unset -nocomplain cached_dheads
10328 unset -nocomplain cached_dtags
10329 unset -nocomplain cached_atags
10332 return [expr {$nid >= 1000? 2: 1}]
10336 fconfigure $fd -blocking 1
10339 # got an error reading the list of commits
10340 # if we were updating, try rereading the whole thing again
10346 error_popup "[mc "Error reading commit topology information;\
10347 branch and preceding/following tag information\
10348 will be incomplete."]\n($err)"
10351 if {[incr allcommits -1] == 0} {
10361 proc recalcarc {a} {
10362 global arctags archeads arcids idtags idheads
10366 foreach id [lrange $arcids($a) 0 end-1] {
10367 if {[info exists idtags($id)]} {
10370 if {[info exists idheads($id)]} {
10374 set arctags($a) $at
10375 set archeads($a) $ah
10378 proc splitarc {p} {
10379 global arcnos arcids nextarc arctags archeads idtags idheads
10380 global arcstart arcend arcout allparents growing
10383 if {[llength $a] != 1} {
10384 puts "oops splitarc called but [llength $a] arcs already"
10387 set a [lindex $a 0]
10388 set i [lsearch -exact $arcids($a) $p]
10390 puts "oops splitarc $p not in arc $a"
10393 set na [incr nextarc]
10394 if {[info exists arcend($a)]} {
10395 set arcend($na) $arcend($a)
10397 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10398 set j [lsearch -exact $arcnos($l) $a]
10399 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10401 set tail [lrange $arcids($a) [expr {$i+1}] end]
10402 set arcids($a) [lrange $arcids($a) 0 $i]
10404 set arcstart($na) $p
10406 set arcids($na) $tail
10407 if {[info exists growing($a)]} {
10413 if {[llength $arcnos($id)] == 1} {
10414 set arcnos($id) $na
10416 set j [lsearch -exact $arcnos($id) $a]
10417 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10421 # reconstruct tags and heads lists
10422 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10426 set arctags($na) {}
10427 set archeads($na) {}
10431 # Update things for a new commit added that is a child of one
10432 # existing commit. Used when cherry-picking.
10433 proc addnewchild {id p} {
10434 global allparents allchildren idtags nextarc
10435 global arcnos arcids arctags arcout arcend arcstart archeads growing
10436 global seeds allcommits
10438 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10439 set allparents($id) [list $p]
10440 set allchildren($id) {}
10443 lappend allchildren($p) $id
10444 set a [incr nextarc]
10445 set arcstart($a) $id
10446 set archeads($a) {}
10448 set arcids($a) [list $p]
10450 if {![info exists arcout($p)]} {
10453 lappend arcnos($p) $a
10454 set arcout($id) [list $a]
10457 # This implements a cache for the topology information.
10458 # The cache saves, for each arc, the start and end of the arc,
10459 # the ids on the arc, and the outgoing arcs from the end.
10460 proc readcache {f} {
10461 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10462 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10466 set lim $cachedarcs
10467 if {$lim - $a > 500} {
10468 set lim [expr {$a + 500}]
10472 # finish reading the cache and setting up arctags, etc.
10474 if {$line ne "1"} {error "bad final version"}
10476 foreach id [array names idtags] {
10477 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10478 [llength $allparents($id)] == 1} {
10479 set a [lindex $arcnos($id) 0]
10480 if {$arctags($a) eq {}} {
10485 foreach id [array names idheads] {
10486 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10487 [llength $allparents($id)] == 1} {
10488 set a [lindex $arcnos($id) 0]
10489 if {$archeads($a) eq {}} {
10494 foreach id [lsort -unique $possible_seeds] {
10495 if {$arcnos($id) eq {}} {
10501 while {[incr a] <= $lim} {
10503 if {[llength $line] != 3} {error "bad line"}
10504 set s [lindex $line 0]
10505 set arcstart($a) $s
10506 lappend arcout($s) $a
10507 if {![info exists arcnos($s)]} {
10508 lappend possible_seeds $s
10511 set e [lindex $line 1]
10516 if {![info exists arcout($e)]} {
10520 set arcids($a) [lindex $line 2]
10521 foreach id $arcids($a) {
10522 lappend allparents($s) $id
10524 lappend arcnos($id) $a
10526 if {![info exists allparents($s)]} {
10527 set allparents($s) {}
10530 set archeads($a) {}
10532 set nextarc [expr {$a - 1}]
10544 proc getcache {f} {
10545 global nextarc cachedarcs possible_seeds
10549 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10550 # make sure it's an integer
10551 set cachedarcs [expr {int([lindex $line 1])}]
10552 if {$cachedarcs < 0} {error "bad number of arcs"}
10554 set possible_seeds {}
10562 proc dropcache {err} {
10563 global allcwait nextarc cachedarcs seeds
10565 #puts "dropping cache ($err)"
10566 foreach v {arcnos arcout arcids arcstart arcend growing \
10567 arctags archeads allparents allchildren} {
10569 unset -nocomplain $v
10578 proc writecache {f} {
10579 global cachearc cachedarcs allccache
10580 global arcstart arcend arcnos arcids arcout
10583 set lim $cachedarcs
10584 if {$lim - $a > 1000} {
10585 set lim [expr {$a + 1000}]
10588 while {[incr a] <= $lim} {
10589 if {[info exists arcend($a)]} {
10590 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10592 puts $f [list $arcstart($a) {} $arcids($a)]
10597 catch {file delete $allccache}
10598 #puts "writing cache failed ($err)"
10601 set cachearc [expr {$a - 1}]
10602 if {$a > $cachedarcs} {
10610 proc savecache {} {
10611 global nextarc cachedarcs cachearc allccache
10613 if {$nextarc == $cachedarcs} return
10615 set cachedarcs $nextarc
10617 set f [open $allccache w]
10618 puts $f [list 1 $cachedarcs]
10623 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10624 # or 0 if neither is true.
10625 proc anc_or_desc {a b} {
10626 global arcout arcstart arcend arcnos cached_isanc
10628 if {$arcnos($a) eq $arcnos($b)} {
10629 # Both are on the same arc(s); either both are the same BMP,
10630 # or if one is not a BMP, the other is also not a BMP or is
10631 # the BMP at end of the arc (and it only has 1 incoming arc).
10632 # Or both can be BMPs with no incoming arcs.
10633 if {$a eq $b || $arcnos($a) eq {}} {
10636 # assert {[llength $arcnos($a)] == 1}
10637 set arc [lindex $arcnos($a) 0]
10638 set i [lsearch -exact $arcids($arc) $a]
10639 set j [lsearch -exact $arcids($arc) $b]
10640 if {$i < 0 || $i > $j} {
10647 if {![info exists arcout($a)]} {
10648 set arc [lindex $arcnos($a) 0]
10649 if {[info exists arcend($arc)]} {
10650 set aend $arcend($arc)
10654 set a $arcstart($arc)
10658 if {![info exists arcout($b)]} {
10659 set arc [lindex $arcnos($b) 0]
10660 if {[info exists arcend($arc)]} {
10661 set bend $arcend($arc)
10665 set b $arcstart($arc)
10675 if {[info exists cached_isanc($a,$bend)]} {
10676 if {$cached_isanc($a,$bend)} {
10680 if {[info exists cached_isanc($b,$aend)]} {
10681 if {$cached_isanc($b,$aend)} {
10684 if {[info exists cached_isanc($a,$bend)]} {
10689 set todo [list $a $b]
10692 for {set i 0} {$i < [llength $todo]} {incr i} {
10693 set x [lindex $todo $i]
10694 if {$anc($x) eq {}} {
10697 foreach arc $arcnos($x) {
10698 set xd $arcstart($arc)
10699 if {$xd eq $bend} {
10700 set cached_isanc($a,$bend) 1
10701 set cached_isanc($b,$aend) 0
10703 } elseif {$xd eq $aend} {
10704 set cached_isanc($b,$aend) 1
10705 set cached_isanc($a,$bend) 0
10708 if {![info exists anc($xd)]} {
10709 set anc($xd) $anc($x)
10711 } elseif {$anc($xd) ne $anc($x)} {
10716 set cached_isanc($a,$bend) 0
10717 set cached_isanc($b,$aend) 0
10721 # This identifies whether $desc has an ancestor that is
10722 # a growing tip of the graph and which is not an ancestor of $anc
10723 # and returns 0 if so and 1 if not.
10724 # If we subsequently discover a tag on such a growing tip, and that
10725 # turns out to be a descendent of $anc (which it could, since we
10726 # don't necessarily see children before parents), then $desc
10727 # isn't a good choice to display as a descendent tag of
10728 # $anc (since it is the descendent of another tag which is
10729 # a descendent of $anc). Similarly, $anc isn't a good choice to
10730 # display as a ancestor tag of $desc.
10732 proc is_certain {desc anc} {
10733 global arcnos arcout arcstart arcend growing problems
10736 if {[llength $arcnos($anc)] == 1} {
10737 # tags on the same arc are certain
10738 if {$arcnos($desc) eq $arcnos($anc)} {
10741 if {![info exists arcout($anc)]} {
10742 # if $anc is partway along an arc, use the start of the arc instead
10743 set a [lindex $arcnos($anc) 0]
10744 set anc $arcstart($a)
10747 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10750 set a [lindex $arcnos($desc) 0]
10756 set anclist [list $x]
10760 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10761 set x [lindex $anclist $i]
10766 foreach a $arcout($x) {
10767 if {[info exists growing($a)]} {
10768 if {![info exists growanc($x)] && $dl($x)} {
10774 if {[info exists dl($y)]} {
10778 if {![info exists done($y)]} {
10781 if {[info exists growanc($x)]} {
10785 for {set k 0} {$k < [llength $xl]} {incr k} {
10786 set z [lindex $xl $k]
10787 foreach c $arcout($z) {
10788 if {[info exists arcend($c)]} {
10790 if {[info exists dl($v)] && $dl($v)} {
10792 if {![info exists done($v)]} {
10795 if {[info exists growanc($v)]} {
10805 } elseif {$y eq $anc || !$dl($x)} {
10816 foreach x [array names growanc] {
10825 proc validate_arctags {a} {
10826 global arctags idtags
10829 set na $arctags($a)
10830 foreach id $arctags($a) {
10832 if {![info exists idtags($id)]} {
10833 set na [lreplace $na $i $i]
10837 set arctags($a) $na
10840 proc validate_archeads {a} {
10841 global archeads idheads
10844 set na $archeads($a)
10845 foreach id $archeads($a) {
10847 if {![info exists idheads($id)]} {
10848 set na [lreplace $na $i $i]
10852 set archeads($a) $na
10855 # Return the list of IDs that have tags that are descendents of id,
10856 # ignoring IDs that are descendents of IDs already reported.
10857 proc desctags {id} {
10858 global arcnos arcstart arcids arctags idtags allparents
10859 global growing cached_dtags
10861 if {![info exists allparents($id)]} {
10864 set t1 [clock clicks -milliseconds]
10866 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10867 # part-way along an arc; check that arc first
10868 set a [lindex $arcnos($id) 0]
10869 if {$arctags($a) ne {}} {
10870 validate_arctags $a
10871 set i [lsearch -exact $arcids($a) $id]
10873 foreach t $arctags($a) {
10874 set j [lsearch -exact $arcids($a) $t]
10875 if {$j >= $i} break
10882 set id $arcstart($a)
10883 if {[info exists idtags($id)]} {
10887 if {[info exists cached_dtags($id)]} {
10888 return $cached_dtags($id)
10892 set todo [list $id]
10895 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10896 set id [lindex $todo $i]
10898 set ta [info exists hastaggedancestor($id)]
10902 # ignore tags on starting node
10903 if {!$ta && $i > 0} {
10904 if {[info exists idtags($id)]} {
10905 set tagloc($id) $id
10907 } elseif {[info exists cached_dtags($id)]} {
10908 set tagloc($id) $cached_dtags($id)
10912 foreach a $arcnos($id) {
10913 set d $arcstart($a)
10914 if {!$ta && $arctags($a) ne {}} {
10915 validate_arctags $a
10916 if {$arctags($a) ne {}} {
10917 lappend tagloc($id) [lindex $arctags($a) end]
10920 if {$ta || $arctags($a) ne {}} {
10921 set tomark [list $d]
10922 for {set j 0} {$j < [llength $tomark]} {incr j} {
10923 set dd [lindex $tomark $j]
10924 if {![info exists hastaggedancestor($dd)]} {
10925 if {[info exists done($dd)]} {
10926 foreach b $arcnos($dd) {
10927 lappend tomark $arcstart($b)
10929 if {[info exists tagloc($dd)]} {
10932 } elseif {[info exists queued($dd)]} {
10935 set hastaggedancestor($dd) 1
10939 if {![info exists queued($d)]} {
10942 if {![info exists hastaggedancestor($d)]} {
10949 foreach id [array names tagloc] {
10950 if {![info exists hastaggedancestor($id)]} {
10951 foreach t $tagloc($id) {
10952 if {[lsearch -exact $tags $t] < 0} {
10958 set t2 [clock clicks -milliseconds]
10961 # remove tags that are descendents of other tags
10962 for {set i 0} {$i < [llength $tags]} {incr i} {
10963 set a [lindex $tags $i]
10964 for {set j 0} {$j < $i} {incr j} {
10965 set b [lindex $tags $j]
10966 set r [anc_or_desc $a $b]
10968 set tags [lreplace $tags $j $j]
10971 } elseif {$r == -1} {
10972 set tags [lreplace $tags $i $i]
10979 if {[array names growing] ne {}} {
10980 # graph isn't finished, need to check if any tag could get
10981 # eclipsed by another tag coming later. Simply ignore any
10982 # tags that could later get eclipsed.
10985 if {[is_certain $t $origid]} {
10989 if {$tags eq $ctags} {
10990 set cached_dtags($origid) $tags
10995 set cached_dtags($origid) $tags
10997 set t3 [clock clicks -milliseconds]
10998 if {0 && $t3 - $t1 >= 100} {
10999 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
11000 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
11005 proc anctags {id} {
11006 global arcnos arcids arcout arcend arctags idtags allparents
11007 global growing cached_atags
11009 if {![info exists allparents($id)]} {
11012 set t1 [clock clicks -milliseconds]
11014 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
11015 # part-way along an arc; check that arc first
11016 set a [lindex $arcnos($id) 0]
11017 if {$arctags($a) ne {}} {
11018 validate_arctags $a
11019 set i [lsearch -exact $arcids($a) $id]
11020 foreach t $arctags($a) {
11021 set j [lsearch -exact $arcids($a) $t]
11027 if {![info exists arcend($a)]} {
11031 if {[info exists idtags($id)]} {
11035 if {[info exists cached_atags($id)]} {
11036 return $cached_atags($id)
11040 set todo [list $id]
11044 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
11045 set id [lindex $todo $i]
11047 set td [info exists hastaggeddescendent($id)]
11051 # ignore tags on starting node
11052 if {!$td && $i > 0} {
11053 if {[info exists idtags($id)]} {
11054 set tagloc($id) $id
11056 } elseif {[info exists cached_atags($id)]} {
11057 set tagloc($id) $cached_atags($id)
11061 foreach a $arcout($id) {
11062 if {!$td && $arctags($a) ne {}} {
11063 validate_arctags $a
11064 if {$arctags($a) ne {}} {
11065 lappend tagloc($id) [lindex $arctags($a) 0]
11068 if {![info exists arcend($a)]} continue
11070 if {$td || $arctags($a) ne {}} {
11071 set tomark [list $d]
11072 for {set j 0} {$j < [llength $tomark]} {incr j} {
11073 set dd [lindex $tomark $j]
11074 if {![info exists hastaggeddescendent($dd)]} {
11075 if {[info exists done($dd)]} {
11076 foreach b $arcout($dd) {
11077 if {[info exists arcend($b)]} {
11078 lappend tomark $arcend($b)
11081 if {[info exists tagloc($dd)]} {
11084 } elseif {[info exists queued($dd)]} {
11087 set hastaggeddescendent($dd) 1
11091 if {![info exists queued($d)]} {
11094 if {![info exists hastaggeddescendent($d)]} {
11100 set t2 [clock clicks -milliseconds]
11103 foreach id [array names tagloc] {
11104 if {![info exists hastaggeddescendent($id)]} {
11105 foreach t $tagloc($id) {
11106 if {[lsearch -exact $tags $t] < 0} {
11113 # remove tags that are ancestors of other tags
11114 for {set i 0} {$i < [llength $tags]} {incr i} {
11115 set a [lindex $tags $i]
11116 for {set j 0} {$j < $i} {incr j} {
11117 set b [lindex $tags $j]
11118 set r [anc_or_desc $a $b]
11120 set tags [lreplace $tags $j $j]
11123 } elseif {$r == 1} {
11124 set tags [lreplace $tags $i $i]
11131 if {[array names growing] ne {}} {
11132 # graph isn't finished, need to check if any tag could get
11133 # eclipsed by another tag coming later. Simply ignore any
11134 # tags that could later get eclipsed.
11137 if {[is_certain $origid $t]} {
11141 if {$tags eq $ctags} {
11142 set cached_atags($origid) $tags
11147 set cached_atags($origid) $tags
11149 set t3 [clock clicks -milliseconds]
11150 if {0 && $t3 - $t1 >= 100} {
11151 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
11152 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
11157 # Return the list of IDs that have heads that are descendents of id,
11158 # including id itself if it has a head.
11159 proc descheads {id} {
11160 global arcnos arcstart arcids archeads idheads cached_dheads
11161 global allparents arcout
11163 if {![info exists allparents($id)]} {
11167 if {![info exists arcout($id)]} {
11168 # part-way along an arc; check it first
11169 set a [lindex $arcnos($id) 0]
11170 if {$archeads($a) ne {}} {
11171 validate_archeads $a
11172 set i [lsearch -exact $arcids($a) $id]
11173 foreach t $archeads($a) {
11174 set j [lsearch -exact $arcids($a) $t]
11179 set id $arcstart($a)
11182 set todo [list $id]
11185 for {set i 0} {$i < [llength $todo]} {incr i} {
11186 set id [lindex $todo $i]
11187 if {[info exists cached_dheads($id)]} {
11188 set ret [concat $ret $cached_dheads($id)]
11190 if {[info exists idheads($id)]} {
11193 foreach a $arcnos($id) {
11194 if {$archeads($a) ne {}} {
11195 validate_archeads $a
11196 if {$archeads($a) ne {}} {
11197 set ret [concat $ret $archeads($a)]
11200 set d $arcstart($a)
11201 if {![info exists seen($d)]} {
11208 set ret [lsort -unique $ret]
11209 set cached_dheads($origid) $ret
11210 return [concat $ret $aret]
11213 proc addedtag {id} {
11214 global arcnos arcout cached_dtags cached_atags
11216 if {![info exists arcnos($id)]} return
11217 if {![info exists arcout($id)]} {
11218 recalcarc [lindex $arcnos($id) 0]
11220 unset -nocomplain cached_dtags
11221 unset -nocomplain cached_atags
11224 proc addedhead {hid head} {
11225 global arcnos arcout cached_dheads
11227 if {![info exists arcnos($hid)]} return
11228 if {![info exists arcout($hid)]} {
11229 recalcarc [lindex $arcnos($hid) 0]
11231 unset -nocomplain cached_dheads
11234 proc removedhead {hid head} {
11235 global cached_dheads
11237 unset -nocomplain cached_dheads
11240 proc movedhead {hid head} {
11241 global arcnos arcout cached_dheads
11243 if {![info exists arcnos($hid)]} return
11244 if {![info exists arcout($hid)]} {
11245 recalcarc [lindex $arcnos($hid) 0]
11247 unset -nocomplain cached_dheads
11250 proc changedrefs {} {
11251 global cached_dheads cached_dtags cached_atags cached_tagcontent
11252 global arctags archeads arcnos arcout idheads idtags
11254 foreach id [concat [array names idheads] [array names idtags]] {
11255 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
11256 set a [lindex $arcnos($id) 0]
11257 if {![info exists donearc($a)]} {
11263 unset -nocomplain cached_tagcontent
11264 unset -nocomplain cached_dtags
11265 unset -nocomplain cached_atags
11266 unset -nocomplain cached_dheads
11269 proc rereadrefs {} {
11270 global idtags idheads idotherrefs mainheadid
11272 set refids [concat [array names idtags] \
11273 [array names idheads] [array names idotherrefs]]
11274 foreach id $refids {
11275 if {![info exists ref($id)]} {
11276 set ref($id) [listrefs $id]
11279 set oldmainhead $mainheadid
11282 set refids [lsort -unique [concat $refids [array names idtags] \
11283 [array names idheads] [array names idotherrefs]]]
11284 foreach id $refids {
11285 set v [listrefs $id]
11286 if {![info exists ref($id)] || $ref($id) != $v} {
11290 if {$oldmainhead ne $mainheadid} {
11291 redrawtags $oldmainhead
11292 redrawtags $mainheadid
11297 proc listrefs {id} {
11298 global idtags idheads idotherrefs
11301 if {[info exists idtags($id)]} {
11305 if {[info exists idheads($id)]} {
11306 set y $idheads($id)
11309 if {[info exists idotherrefs($id)]} {
11310 set z $idotherrefs($id)
11312 return [list $x $y $z]
11315 proc add_tag_ctext {tag} {
11316 global ctext cached_tagcontent tagids
11318 if {![info exists cached_tagcontent($tag)]} {
11320 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11323 $ctext insert end "[mc "Tag"]: $tag\n" bold
11324 if {[info exists cached_tagcontent($tag)]} {
11325 set text $cached_tagcontent($tag)
11327 set text "[mc "Id"]: $tagids($tag)"
11329 appendwithlinks $text {}
11332 proc showtag {tag isnew} {
11333 global ctext cached_tagcontent tagids linknum tagobjid
11336 addtohistory [list showtag $tag 0] savectextpos
11338 $ctext conf -state normal
11343 maybe_scroll_ctext 1
11344 $ctext conf -state disabled
11348 proc showtags {id isnew} {
11349 global idtags ctext linknum
11352 addtohistory [list showtags $id 0] savectextpos
11354 $ctext conf -state normal
11359 foreach tag $idtags($id) {
11360 $ctext insert end $sep
11364 maybe_scroll_ctext 1
11365 $ctext conf -state disabled
11377 if {[info exists gitktmpdir]} {
11378 catch {file delete -force $gitktmpdir}
11382 proc mkfontdisp {font top which} {
11383 global fontattr fontpref $font NS use_ttk
11385 set fontpref($font) [set $font]
11386 ${NS}::button $top.${font}but -text $which \
11387 -command [list choosefont $font $which]
11388 ${NS}::label $top.$font -relief flat -font $font \
11389 -text $fontattr($font,family) -justify left
11390 grid x $top.${font}but $top.$font -sticky w
11393 proc choosefont {font which} {
11394 global fontparam fontlist fonttop fontattr
11397 set fontparam(which) $which
11398 set fontparam(font) $font
11399 set fontparam(family) [font actual $font -family]
11400 set fontparam(size) $fontattr($font,size)
11401 set fontparam(weight) $fontattr($font,weight)
11402 set fontparam(slant) $fontattr($font,slant)
11405 if {![winfo exists $top]} {
11407 eval font config sample [font actual $font]
11409 make_transient $top $prefstop
11410 wm title $top [mc "Gitk font chooser"]
11411 ${NS}::label $top.l -textvariable fontparam(which)
11412 pack $top.l -side top
11413 set fontlist [lsort [font families]]
11414 ${NS}::frame $top.f
11415 listbox $top.f.fam -listvariable fontlist \
11416 -yscrollcommand [list $top.f.sb set]
11417 bind $top.f.fam <<ListboxSelect>> selfontfam
11418 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11419 pack $top.f.sb -side right -fill y
11420 pack $top.f.fam -side left -fill both -expand 1
11421 pack $top.f -side top -fill both -expand 1
11422 ${NS}::frame $top.g
11423 spinbox $top.g.size -from 4 -to 40 -width 4 \
11424 -textvariable fontparam(size) \
11425 -validatecommand {string is integer -strict %s}
11426 checkbutton $top.g.bold -padx 5 \
11427 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11428 -variable fontparam(weight) -onvalue bold -offvalue normal
11429 checkbutton $top.g.ital -padx 5 \
11430 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11431 -variable fontparam(slant) -onvalue italic -offvalue roman
11432 pack $top.g.size $top.g.bold $top.g.ital -side left
11433 pack $top.g -side top
11434 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11436 $top.c create text 100 25 -anchor center -text $which -font sample \
11437 -fill black -tags text
11438 bind $top.c <Configure> [list centertext $top.c]
11439 pack $top.c -side top -fill x
11440 ${NS}::frame $top.buts
11441 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11442 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11443 bind $top <Key-Return> fontok
11444 bind $top <Key-Escape> fontcan
11445 grid $top.buts.ok $top.buts.can
11446 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11447 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11448 pack $top.buts -side bottom -fill x
11449 trace add variable fontparam write chg_fontparam
11452 $top.c itemconf text -text $which
11454 set i [lsearch -exact $fontlist $fontparam(family)]
11456 $top.f.fam selection set $i
11461 proc centertext {w} {
11462 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11466 global fontparam fontpref prefstop
11468 set f $fontparam(font)
11469 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11470 if {$fontparam(weight) eq "bold"} {
11471 lappend fontpref($f) "bold"
11473 if {$fontparam(slant) eq "italic"} {
11474 lappend fontpref($f) "italic"
11476 set w $prefstop.notebook.fonts.$f
11477 $w conf -text $fontparam(family) -font $fontpref($f)
11483 global fonttop fontparam
11485 if {[info exists fonttop]} {
11486 catch {destroy $fonttop}
11487 catch {font delete sample}
11493 if {[package vsatisfies [package provide Tk] 8.6]} {
11494 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11495 # function to make use of it.
11496 proc choosefont {font which} {
11497 tk fontchooser configure -title $which -font $font \
11498 -command [list on_choosefont $font $which]
11499 tk fontchooser show
11501 proc on_choosefont {font which newfont} {
11503 puts stderr "$font $newfont"
11504 array set f [font actual $newfont]
11505 set fontparam(which) $which
11506 set fontparam(font) $font
11507 set fontparam(family) $f(-family)
11508 set fontparam(size) $f(-size)
11509 set fontparam(weight) $f(-weight)
11510 set fontparam(slant) $f(-slant)
11515 proc selfontfam {} {
11516 global fonttop fontparam
11518 set i [$fonttop.f.fam curselection]
11520 set fontparam(family) [$fonttop.f.fam get $i]
11524 proc chg_fontparam {v sub op} {
11527 font config sample -$sub $fontparam($sub)
11530 # Create a property sheet tab page
11531 proc create_prefs_page {w} {
11533 set parent [join [lrange [split $w .] 0 end-1] .]
11534 if {[winfo class $parent] eq "TNotebook"} {
11537 ${NS}::labelframe $w
11541 proc prefspage_general {notebook} {
11542 global NS maxwidth maxgraphpct showneartags showlocalchanges
11543 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11544 global hideremotes want_ttk have_ttk maxrefs web_browser
11546 set page [create_prefs_page $notebook.general]
11548 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11549 grid $page.ldisp - -sticky w -pady 10
11550 ${NS}::label $page.spacer -text " "
11551 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11552 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11553 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11554 #xgettext:no-tcl-format
11555 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11556 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11557 grid x $page.maxpctl $page.maxpct -sticky w
11558 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11559 -variable showlocalchanges
11560 grid x $page.showlocal -sticky w
11561 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11562 -variable autoselect
11563 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11564 grid x $page.autoselect $page.autosellen -sticky w
11565 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11566 -variable hideremotes
11567 grid x $page.hideremotes -sticky w
11569 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11570 grid $page.ddisp - -sticky w -pady 10
11571 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11572 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11573 grid x $page.tabstopl $page.tabstop -sticky w
11574 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11575 -variable showneartags
11576 grid x $page.ntag -sticky w
11577 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11578 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11579 grid x $page.maxrefsl $page.maxrefs -sticky w
11580 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11581 -variable limitdiffs
11582 grid x $page.ldiff -sticky w
11583 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11584 -variable perfile_attrs
11585 grid x $page.lattr -sticky w
11587 ${NS}::entry $page.extdifft -textvariable extdifftool
11588 ${NS}::frame $page.extdifff
11589 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11590 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11591 pack $page.extdifff.l $page.extdifff.b -side left
11592 pack configure $page.extdifff.l -padx 10
11593 grid x $page.extdifff $page.extdifft -sticky ew
11595 ${NS}::entry $page.webbrowser -textvariable web_browser
11596 ${NS}::frame $page.webbrowserf
11597 ${NS}::label $page.webbrowserf.l -text [mc "Web browser" ]
11598 pack $page.webbrowserf.l -side left
11599 pack configure $page.webbrowserf.l -padx 10
11600 grid x $page.webbrowserf $page.webbrowser -sticky ew
11602 ${NS}::label $page.lgen -text [mc "General options"]
11603 grid $page.lgen - -sticky w -pady 10
11604 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11605 -text [mc "Use themed widgets"]
11607 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11609 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11611 grid x $page.want_ttk $page.ttk_note -sticky w
11615 proc prefspage_colors {notebook} {
11616 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11617 global diffbgcolors
11619 set page [create_prefs_page $notebook.colors]
11621 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11622 grid $page.cdisp - -sticky w -pady 10
11623 label $page.ui -padx 40 -relief sunk -background $uicolor
11624 ${NS}::button $page.uibut -text [mc "Interface"] \
11625 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11626 grid x $page.uibut $page.ui -sticky w
11627 label $page.bg -padx 40 -relief sunk -background $bgcolor
11628 ${NS}::button $page.bgbut -text [mc "Background"] \
11629 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11630 grid x $page.bgbut $page.bg -sticky w
11631 label $page.fg -padx 40 -relief sunk -background $fgcolor
11632 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11633 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11634 grid x $page.fgbut $page.fg -sticky w
11635 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11636 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11637 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11638 [list $ctext tag conf d0 -foreground]]
11639 grid x $page.diffoldbut $page.diffold -sticky w
11640 label $page.diffoldbg -padx 40 -relief sunk -background [lindex $diffbgcolors 0]
11641 ${NS}::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \
11642 -command [list choosecolor diffbgcolors 0 $page.diffoldbg \
11643 [mc "diff old lines bg"] \
11644 [list $ctext tag conf d0 -background]]
11645 grid x $page.diffoldbgbut $page.diffoldbg -sticky w
11646 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11647 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11648 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11649 [list $ctext tag conf dresult -foreground]]
11650 grid x $page.diffnewbut $page.diffnew -sticky w
11651 label $page.diffnewbg -padx 40 -relief sunk -background [lindex $diffbgcolors 1]
11652 ${NS}::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \
11653 -command [list choosecolor diffbgcolors 1 $page.diffnewbg \
11654 [mc "diff new lines bg"] \
11655 [list $ctext tag conf dresult -background]]
11656 grid x $page.diffnewbgbut $page.diffnewbg -sticky w
11657 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11658 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11659 -command [list choosecolor diffcolors 2 $page.hunksep \
11660 [mc "diff hunk header"] \
11661 [list $ctext tag conf hunksep -foreground]]
11662 grid x $page.hunksepbut $page.hunksep -sticky w
11663 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11664 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11665 -command [list choosecolor markbgcolor {} $page.markbgsep \
11666 [mc "marked line background"] \
11667 [list $ctext tag conf omark -background]]
11668 grid x $page.markbgbut $page.markbgsep -sticky w
11669 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11670 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11671 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11672 grid x $page.selbgbut $page.selbgsep -sticky w
11676 proc prefspage_fonts {notebook} {
11678 set page [create_prefs_page $notebook.fonts]
11679 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11680 grid $page.cfont - -sticky w -pady 10
11681 mkfontdisp mainfont $page [mc "Main font"]
11682 mkfontdisp textfont $page [mc "Diff display font"]
11683 mkfontdisp uifont $page [mc "User interface font"]
11688 global maxwidth maxgraphpct use_ttk NS
11689 global oldprefs prefstop showneartags showlocalchanges
11690 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11691 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11692 global hideremotes want_ttk have_ttk
11696 if {[winfo exists $top]} {
11700 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11701 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11702 set oldprefs($v) [set $v]
11705 wm title $top [mc "Gitk preferences"]
11706 make_transient $top .
11708 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11709 set notebook [ttk::notebook $top.notebook]
11711 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11714 lappend pages [prefspage_general $notebook] [mc "General"]
11715 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11716 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11718 foreach {page title} $pages {
11719 if {$use_notebook} {
11720 $notebook add $page -text $title
11722 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11723 -text $title -command [list raise $page]]
11724 $page configure -text $title
11725 grid $btn -row 0 -column [incr col] -sticky w
11726 grid $page -row 1 -column 0 -sticky news -columnspan 100
11730 if {!$use_notebook} {
11731 grid columnconfigure $notebook 0 -weight 1
11732 grid rowconfigure $notebook 1 -weight 1
11733 raise [lindex $pages 0]
11736 grid $notebook -sticky news -padx 2 -pady 2
11737 grid rowconfigure $top 0 -weight 1
11738 grid columnconfigure $top 0 -weight 1
11740 ${NS}::frame $top.buts
11741 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11742 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11743 bind $top <Key-Return> prefsok
11744 bind $top <Key-Escape> prefscan
11745 grid $top.buts.ok $top.buts.can
11746 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11747 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11748 grid $top.buts - - -pady 10 -sticky ew
11749 grid columnconfigure $top 2 -weight 1
11750 bind $top <Visibility> [list focus $top.buts.ok]
11753 proc choose_extdiff {} {
11756 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11758 set extdifftool $prog
11762 proc choosecolor {v vi w x cmd} {
11765 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11766 -title [mc "Gitk: choose color for %s" $x]]
11767 if {$c eq {}} return
11768 $w conf -background $c
11773 proc setselbg {c} {
11774 global bglist cflist
11775 foreach w $bglist {
11776 if {[winfo exists $w]} {
11777 $w configure -selectbackground $c
11780 $cflist tag configure highlight \
11781 -background [$cflist cget -selectbackground]
11782 allcanvs itemconf secsel -fill $c
11785 # This sets the background color and the color scheme for the whole UI.
11786 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11787 # if we don't specify one ourselves, which makes the checkbuttons and
11788 # radiobuttons look bad. This chooses white for selectColor if the
11789 # background color is light, or black if it is dark.
11791 if {[tk windowingsystem] eq "win32"} { return }
11792 set bg [winfo rgb . $c]
11794 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11797 tk_setPalette background $c selectColor $selc
11803 foreach w $bglist {
11804 if {[winfo exists $w]} {
11805 $w conf -background $c
11813 foreach w $fglist {
11814 if {[winfo exists $w]} {
11815 $w conf -foreground $c
11818 allcanvs itemconf text -fill $c
11819 $canv itemconf circle -outline $c
11820 $canv itemconf markid -outline $c
11824 global oldprefs prefstop
11826 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11827 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11829 set $v $oldprefs($v)
11831 catch {destroy $prefstop}
11837 global maxwidth maxgraphpct
11838 global oldprefs prefstop showneartags showlocalchanges
11839 global fontpref mainfont textfont uifont
11840 global limitdiffs treediffs perfile_attrs
11843 catch {destroy $prefstop}
11847 if {$mainfont ne $fontpref(mainfont)} {
11848 set mainfont $fontpref(mainfont)
11849 parsefont mainfont $mainfont
11850 eval font configure mainfont [fontflags mainfont]
11851 eval font configure mainfontbold [fontflags mainfont 1]
11855 if {$textfont ne $fontpref(textfont)} {
11856 set textfont $fontpref(textfont)
11857 parsefont textfont $textfont
11858 eval font configure textfont [fontflags textfont]
11859 eval font configure textfontbold [fontflags textfont 1]
11861 if {$uifont ne $fontpref(uifont)} {
11862 set uifont $fontpref(uifont)
11863 parsefont uifont $uifont
11864 eval font configure uifont [fontflags uifont]
11867 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11868 if {$showlocalchanges} {
11874 if {$limitdiffs != $oldprefs(limitdiffs) ||
11875 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11876 # treediffs elements are limited by path;
11877 # won't have encodings cached if perfile_attrs was just turned on
11878 unset -nocomplain treediffs
11880 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11881 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11883 } elseif {$showneartags != $oldprefs(showneartags) ||
11884 $limitdiffs != $oldprefs(limitdiffs)} {
11887 if {$hideremotes != $oldprefs(hideremotes)} {
11892 proc formatdate {d} {
11893 global datetimeformat
11895 # If $datetimeformat includes a timezone, display in the
11896 # timezone of the argument. Otherwise, display in local time.
11897 if {[string match {*%[zZ]*} $datetimeformat]} {
11898 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11899 # Tcl < 8.5 does not support -timezone. Emulate it by
11900 # setting TZ (e.g. TZ=<-0430>+04:30).
11902 if {[info exists env(TZ)]} {
11903 set savedTZ $env(TZ)
11905 set zone [lindex $d 1]
11906 set sign [string map {+ - - +} [string index $zone 0]]
11907 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11908 set d [clock format [lindex $d 0] -format $datetimeformat]
11909 if {[info exists savedTZ]} {
11910 set env(TZ) $savedTZ
11916 set d [clock format [lindex $d 0] -format $datetimeformat]
11922 # This list of encoding names and aliases is distilled from
11923 # http://www.iana.org/assignments/character-sets.
11924 # Not all of them are supported by Tcl.
11925 set encoding_aliases {
11926 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11927 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11928 { ISO-10646-UTF-1 csISO10646UTF1 }
11929 { ISO_646.basic:1983 ref csISO646basic1983 }
11930 { INVARIANT csINVARIANT }
11931 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11932 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11933 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11934 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11935 { NATS-DANO iso-ir-9-1 csNATSDANO }
11936 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11937 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11938 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11939 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11940 { ISO-2022-KR csISO2022KR }
11942 { ISO-2022-JP csISO2022JP }
11943 { ISO-2022-JP-2 csISO2022JP2 }
11944 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11945 csISO13JISC6220jp }
11946 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11947 { IT iso-ir-15 ISO646-IT csISO15Italian }
11948 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11949 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11950 { greek7-old iso-ir-18 csISO18Greek7Old }
11951 { latin-greek iso-ir-19 csISO19LatinGreek }
11952 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11953 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11954 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11955 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11956 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11957 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11958 { INIS iso-ir-49 csISO49INIS }
11959 { INIS-8 iso-ir-50 csISO50INIS8 }
11960 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11961 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11962 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11963 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11964 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11965 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11966 csISO60Norwegian1 }
11967 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11968 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11969 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11970 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11971 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11972 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11973 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11974 { greek7 iso-ir-88 csISO88Greek7 }
11975 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11976 { iso-ir-90 csISO90 }
11977 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11978 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11979 csISO92JISC62991984b }
11980 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11981 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11982 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11983 csISO95JIS62291984handadd }
11984 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11985 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11986 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11987 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11988 CP819 csISOLatin1 }
11989 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11990 { T.61-7bit iso-ir-102 csISO102T617bit }
11991 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11992 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11993 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11994 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11995 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11996 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11997 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11998 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11999 arabic csISOLatinArabic }
12000 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
12001 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
12002 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
12003 greek greek8 csISOLatinGreek }
12004 { T.101-G2 iso-ir-128 csISO128T101G2 }
12005 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
12007 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
12008 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
12009 { CSN_369103 iso-ir-139 csISO139CSN369103 }
12010 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
12011 { ISO_6937-2-add iso-ir-142 csISOTextComm }
12012 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
12013 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
12014 csISOLatinCyrillic }
12015 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
12016 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
12017 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
12018 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
12019 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
12020 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
12021 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
12022 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
12023 { ISO_10367-box iso-ir-155 csISO10367Box }
12024 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
12025 { latin-lap lap iso-ir-158 csISO158Lap }
12026 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
12027 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
12030 { JIS_X0201 X0201 csHalfWidthKatakana }
12031 { KSC5636 ISO646-KR csKSC5636 }
12032 { ISO-10646-UCS-2 csUnicode }
12033 { ISO-10646-UCS-4 csUCS4 }
12034 { DEC-MCS dec csDECMCS }
12035 { hp-roman8 roman8 r8 csHPRoman8 }
12036 { macintosh mac csMacintosh }
12037 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
12039 { IBM038 EBCDIC-INT cp038 csIBM038 }
12040 { IBM273 CP273 csIBM273 }
12041 { IBM274 EBCDIC-BE CP274 csIBM274 }
12042 { IBM275 EBCDIC-BR cp275 csIBM275 }
12043 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
12044 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
12045 { IBM280 CP280 ebcdic-cp-it csIBM280 }
12046 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
12047 { IBM284 CP284 ebcdic-cp-es csIBM284 }
12048 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
12049 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
12050 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
12051 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
12052 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
12053 { IBM424 cp424 ebcdic-cp-he csIBM424 }
12054 { IBM437 cp437 437 csPC8CodePage437 }
12055 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
12056 { IBM775 cp775 csPC775Baltic }
12057 { IBM850 cp850 850 csPC850Multilingual }
12058 { IBM851 cp851 851 csIBM851 }
12059 { IBM852 cp852 852 csPCp852 }
12060 { IBM855 cp855 855 csIBM855 }
12061 { IBM857 cp857 857 csIBM857 }
12062 { IBM860 cp860 860 csIBM860 }
12063 { IBM861 cp861 861 cp-is csIBM861 }
12064 { IBM862 cp862 862 csPC862LatinHebrew }
12065 { IBM863 cp863 863 csIBM863 }
12066 { IBM864 cp864 csIBM864 }
12067 { IBM865 cp865 865 csIBM865 }
12068 { IBM866 cp866 866 csIBM866 }
12069 { IBM868 CP868 cp-ar csIBM868 }
12070 { IBM869 cp869 869 cp-gr csIBM869 }
12071 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
12072 { IBM871 CP871 ebcdic-cp-is csIBM871 }
12073 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
12074 { IBM891 cp891 csIBM891 }
12075 { IBM903 cp903 csIBM903 }
12076 { IBM904 cp904 904 csIBBM904 }
12077 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
12078 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
12079 { IBM1026 CP1026 csIBM1026 }
12080 { EBCDIC-AT-DE csIBMEBCDICATDE }
12081 { EBCDIC-AT-DE-A csEBCDICATDEA }
12082 { EBCDIC-CA-FR csEBCDICCAFR }
12083 { EBCDIC-DK-NO csEBCDICDKNO }
12084 { EBCDIC-DK-NO-A csEBCDICDKNOA }
12085 { EBCDIC-FI-SE csEBCDICFISE }
12086 { EBCDIC-FI-SE-A csEBCDICFISEA }
12087 { EBCDIC-FR csEBCDICFR }
12088 { EBCDIC-IT csEBCDICIT }
12089 { EBCDIC-PT csEBCDICPT }
12090 { EBCDIC-ES csEBCDICES }
12091 { EBCDIC-ES-A csEBCDICESA }
12092 { EBCDIC-ES-S csEBCDICESS }
12093 { EBCDIC-UK csEBCDICUK }
12094 { EBCDIC-US csEBCDICUS }
12095 { UNKNOWN-8BIT csUnknown8BiT }
12096 { MNEMONIC csMnemonic }
12098 { VISCII csVISCII }
12101 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
12102 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
12103 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
12104 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
12105 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
12106 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
12107 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
12108 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
12109 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
12110 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
12111 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
12112 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
12113 { IBM1047 IBM-1047 }
12114 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
12115 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
12116 { UNICODE-1-1 csUnicode11 }
12117 { CESU-8 csCESU-8 }
12118 { BOCU-1 csBOCU-1 }
12119 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
12120 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
12122 { ISO-8859-15 ISO_8859-15 Latin-9 }
12123 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
12124 { GBK CP936 MS936 windows-936 }
12125 { JIS_Encoding csJISEncoding }
12126 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
12127 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
12129 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
12130 { ISO-10646-UCS-Basic csUnicodeASCII }
12131 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
12132 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
12133 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
12134 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
12135 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
12136 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
12137 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
12138 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
12139 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
12140 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
12141 { Adobe-Standard-Encoding csAdobeStandardEncoding }
12142 { Ventura-US csVenturaUS }
12143 { Ventura-International csVenturaInternational }
12144 { PC8-Danish-Norwegian csPC8DanishNorwegian }
12145 { PC8-Turkish csPC8Turkish }
12146 { IBM-Symbols csIBMSymbols }
12147 { IBM-Thai csIBMThai }
12148 { HP-Legal csHPLegal }
12149 { HP-Pi-font csHPPiFont }
12150 { HP-Math8 csHPMath8 }
12151 { Adobe-Symbol-Encoding csHPPSMath }
12152 { HP-DeskTop csHPDesktop }
12153 { Ventura-Math csVenturaMath }
12154 { Microsoft-Publishing csMicrosoftPublishing }
12155 { Windows-31J csWindows31J }
12156 { GB2312 csGB2312 }
12160 proc tcl_encoding {enc} {
12161 global encoding_aliases tcl_encoding_cache
12162 if {[info exists tcl_encoding_cache($enc)]} {
12163 return $tcl_encoding_cache($enc)
12165 set names [encoding names]
12166 set lcnames [string tolower $names]
12167 set enc [string tolower $enc]
12168 set i [lsearch -exact $lcnames $enc]
12170 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
12171 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
12172 set i [lsearch -exact $lcnames $encx]
12176 foreach l $encoding_aliases {
12177 set ll [string tolower $l]
12178 if {[lsearch -exact $ll $enc] < 0} continue
12179 # look through the aliases for one that tcl knows about
12181 set i [lsearch -exact $lcnames $e]
12183 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
12184 set i [lsearch -exact $lcnames $ex]
12194 set tclenc [lindex $names $i]
12196 set tcl_encoding_cache($enc) $tclenc
12200 proc gitattr {path attr default} {
12201 global path_attr_cache
12202 if {[info exists path_attr_cache($attr,$path)]} {
12203 set r $path_attr_cache($attr,$path)
12205 set r "unspecified"
12206 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
12207 regexp "(.*): $attr: (.*)" $line m f r
12209 set path_attr_cache($attr,$path) $r
12211 if {$r eq "unspecified"} {
12217 proc cache_gitattr {attr pathlist} {
12218 global path_attr_cache
12220 foreach path $pathlist {
12221 if {![info exists path_attr_cache($attr,$path)]} {
12222 lappend newlist $path
12226 if {[tk windowingsystem] == "win32"} {
12227 # windows has a 32k limit on the arguments to a command...
12230 while {$newlist ne {}} {
12231 set head [lrange $newlist 0 [expr {$lim - 1}]]
12232 set newlist [lrange $newlist $lim end]
12233 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
12234 foreach row [split $rlist "\n"] {
12235 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
12236 if {[string index $path 0] eq "\""} {
12237 set path [encoding convertfrom [lindex $path 0]]
12239 set path_attr_cache($attr,$path) $value
12246 proc get_path_encoding {path} {
12247 global gui_encoding perfile_attrs
12248 set tcl_enc $gui_encoding
12249 if {$path ne {} && $perfile_attrs} {
12250 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
12258 ## For msgcat loading, first locate the installation location.
12259 if { [info exists ::env(GITK_MSGSDIR)] } {
12260 ## Msgsdir was manually set in the environment.
12261 set gitk_msgsdir $::env(GITK_MSGSDIR)
12263 ## Let's guess the prefix from argv0.
12264 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12265 set gitk_libdir [file join $gitk_prefix share gitk lib]
12266 set gitk_msgsdir [file join $gitk_libdir msgs]
12270 ## Internationalization (i18n) through msgcat and gettext. See
12271 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12272 package require msgcat
12273 namespace import ::msgcat::mc
12274 ## And eventually load the actual message catalog
12275 ::msgcat::mcload $gitk_msgsdir
12277 # First check that Tcl/Tk is recent enough
12278 if {[catch {package require Tk 8.4} err]} {
12279 show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
12280 Gitk requires at least Tcl/Tk 8.4."]
12284 # on OSX bring the current Wish process window to front
12285 if {[tk windowingsystem] eq "aqua"} {
12286 exec osascript -e [format {
12287 tell application "System Events"
12288 set frontmost of processes whose unix id is %d to true
12293 # Unset GIT_TRACE var if set
12294 if { [info exists ::env(GIT_TRACE)] } {
12295 unset ::env(GIT_TRACE)
12299 set wrcomcmd "git diff-tree --stdin -p --pretty=email"
12303 set gitencoding [exec git config --get i18n.commitencoding]
12306 set gitencoding [exec git config --get i18n.logoutputencoding]
12308 if {$gitencoding == ""} {
12309 set gitencoding "utf-8"
12311 set tclencoding [tcl_encoding $gitencoding]
12312 if {$tclencoding == {}} {
12313 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
12316 set gui_encoding [encoding system]
12318 set enc [exec git config --get gui.encoding]
12320 set tclenc [tcl_encoding $enc]
12321 if {$tclenc ne {}} {
12322 set gui_encoding $tclenc
12324 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
12329 set log_showroot true
12331 set log_showroot [exec git config --bool --get log.showroot]
12334 if {[tk windowingsystem] eq "aqua"} {
12335 set mainfont {{Lucida Grande} 9}
12336 set textfont {Monaco 9}
12337 set uifont {{Lucida Grande} 9 bold}
12338 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
12340 set mainfont {sans 9}
12341 set textfont {monospace 9}
12342 set uifont {sans 9 bold}
12344 set mainfont {Helvetica 9}
12345 set textfont {Courier 9}
12346 set uifont {Helvetica 9 bold}
12349 set findmergefiles 0
12357 set cmitmode "patch"
12358 set wrapcomment "none"
12362 set visiblerefs {"master"}
12364 set showlocalchanges 1
12366 set datetimeformat "%Y-%m-%d %H:%M:%S"
12369 set perfile_attrs 0
12372 if {[tk windowingsystem] eq "aqua"} {
12373 set extdifftool "opendiff"
12375 set extdifftool "meld"
12378 set colors {"#00ff00" red blue magenta darkgrey brown orange}
12379 if {[tk windowingsystem] eq "win32"} {
12380 set uicolor SystemButtonFace
12381 set uifgcolor SystemButtonText
12382 set uifgdisabledcolor SystemDisabledText
12383 set bgcolor SystemWindow
12384 set fgcolor SystemWindowText
12385 set selectbgcolor SystemHighlight
12386 set web_browser "cmd /c start"
12389 set uifgcolor black
12390 set uifgdisabledcolor "#999"
12393 set selectbgcolor gray85
12394 if {[tk windowingsystem] eq "aqua"} {
12395 set web_browser "open"
12397 set web_browser "xdg-open"
12400 set diffcolors {"#c30000" "#009800" blue}
12401 set diffbgcolors {"#fff3f3" "#f0fff0"}
12403 set mergecolors {red blue "#00ff00" purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12406 set markbgcolor "#e0e0ff"
12408 set headbgcolor "#00ff00"
12409 set headfgcolor black
12410 set headoutlinecolor black
12411 set remotebgcolor #ffddaa
12412 set tagbgcolor yellow
12413 set tagfgcolor black
12414 set tagoutlinecolor black
12415 set reflinecolor black
12416 set filesepbgcolor #aaaaaa
12417 set filesepfgcolor black
12418 set linehoverbgcolor #ffff80
12419 set linehoverfgcolor black
12420 set linehoveroutlinecolor black
12421 set mainheadcirclecolor yellow
12422 set workingfilescirclecolor red
12423 set indexcirclecolor "#00ff00"
12424 set circlecolors {white blue gray blue blue}
12425 set linkfgcolor blue
12426 set circleoutlinecolor $fgcolor
12427 set foundbgcolor yellow
12428 set currentsearchhitbgcolor orange
12430 # button for popping up context menus
12431 if {[tk windowingsystem] eq "aqua"} {
12432 set ctxbut <Button-2>
12434 set ctxbut <Button-3>
12438 # follow the XDG base directory specification by default. See
12439 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12440 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12441 # XDG_CONFIG_HOME environment variable is set
12442 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12443 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12445 # default XDG_CONFIG_HOME
12446 set config_file "~/.config/git/gitk"
12447 set config_file_tmp "~/.config/git/gitk-tmp"
12449 if {![file exists $config_file]} {
12450 # for backward compatibility use the old config file if it exists
12451 if {[file exists "~/.gitk"]} {
12452 set config_file "~/.gitk"
12453 set config_file_tmp "~/.gitk-tmp"
12454 } elseif {![file exists [file dirname $config_file]]} {
12455 file mkdir [file dirname $config_file]
12458 source $config_file
12460 config_check_tmp_exists 50
12462 set config_variables {
12463 mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12464 cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12465 hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12466 bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12467 markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
12468 extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
12469 remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
12470 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12471 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
12472 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors
12475 foreach var $config_variables {
12476 config_init_trace $var
12477 trace add variable $var write config_variable_change_cb
12480 parsefont mainfont $mainfont
12481 eval font create mainfont [fontflags mainfont]
12482 eval font create mainfontbold [fontflags mainfont 1]
12484 parsefont textfont $textfont
12485 eval font create textfont [fontflags textfont]
12486 eval font create textfontbold [fontflags textfont 1]
12488 parsefont uifont $uifont
12489 eval font create uifont [fontflags uifont]
12495 # check that we can find a .git directory somewhere...
12496 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12497 show_error {} . [mc "Cannot find a git repository here."]
12502 set selectheadid {}
12505 set cmdline_files {}
12507 set revtreeargscmd {}
12508 foreach arg $argv {
12509 switch -glob -- $arg {
12512 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12515 "--select-commit=*" {
12516 set selecthead [string range $arg 16 end]
12519 set revtreeargscmd [string range $arg 10 end]
12522 lappend revtreeargs $arg
12528 if {$selecthead eq "HEAD"} {
12532 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12533 # no -- on command line, but some arguments (other than --argscmd)
12535 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12536 set cmdline_files [split $f "\n"]
12537 set n [llength $cmdline_files]
12538 set revtreeargs [lrange $revtreeargs 0 end-$n]
12539 # Unfortunately git rev-parse doesn't produce an error when
12540 # something is both a revision and a filename. To be consistent
12541 # with git log and git rev-list, check revtreeargs for filenames.
12542 foreach arg $revtreeargs {
12543 if {[file exists $arg]} {
12544 show_error {} . [mc "Ambiguous argument '%s': both revision\
12545 and filename" $arg]
12550 # unfortunately we get both stdout and stderr in $err,
12551 # so look for "fatal:".
12552 set i [string first "fatal:" $err]
12554 set err [string range $err [expr {$i + 6}] end]
12556 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12561 set nullid "0000000000000000000000000000000000000000"
12562 set nullid2 "0000000000000000000000000000000000000001"
12563 set nullfile "/dev/null"
12565 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12566 if {![info exists have_ttk]} {
12567 set have_ttk [llength [info commands ::ttk::style]]
12569 set use_ttk [expr {$have_ttk && $want_ttk}]
12570 set NS [expr {$use_ttk ? "ttk" : ""}]
12576 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12579 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12580 set show_notes "--show-notes"
12590 set highlight_paths {}
12592 set searchdirn -forwards
12595 set diffelide {0 0}
12596 set markingmatches 0
12597 set linkentercount 0
12598 set need_redisplay 0
12605 set selectedhlview [mc "None"]
12606 set highlight_related [mc "None"]
12607 set highlight_files {}
12608 set viewfiles(0) {}
12610 set viewchanged(0) 0
12612 set viewargscmd(0) {}
12614 set selectedline {}
12622 set hasworktree [hasworktree]
12624 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12625 set cdup [exec git rev-parse --show-cdup]
12627 set worktree [gitworktree]
12631 image create photo gitlogo -width 16 -height 16
12633 image create photo gitlogominus -width 4 -height 2
12634 gitlogominus put #C00000 -to 0 0 4 2
12635 gitlogo copy gitlogominus -to 1 5
12636 gitlogo copy gitlogominus -to 6 5
12637 gitlogo copy gitlogominus -to 11 5
12638 image delete gitlogominus
12640 image create photo gitlogoplus -width 4 -height 4
12641 gitlogoplus put #008000 -to 1 0 3 4
12642 gitlogoplus put #008000 -to 0 1 4 3
12643 gitlogo copy gitlogoplus -to 1 9
12644 gitlogo copy gitlogoplus -to 6 9
12645 gitlogo copy gitlogoplus -to 11 9
12646 image delete gitlogoplus
12648 image create photo gitlogo32 -width 32 -height 32
12649 gitlogo32 copy gitlogo -zoom 2 2
12651 wm iconphoto . -default gitlogo gitlogo32
12653 # wait for the window to become visible
12654 tkwait visibility .
12659 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12660 # create a view for the files/dirs specified on the command line
12664 set viewname(1) [mc "Command line"]
12665 set viewfiles(1) $cmdline_files
12666 set viewargs(1) $revtreeargs
12667 set viewargscmd(1) $revtreeargscmd
12669 set viewchanged(1) 0
12672 .bar.view entryconf [mca "&Edit view..."] -state normal
12673 .bar.view entryconf [mca "&Delete view"] -state normal
12676 if {[info exists permviews]} {
12677 foreach v $permviews {
12680 set viewname($n) [lindex $v 0]
12681 set viewfiles($n) [lindex $v 1]
12682 set viewargs($n) [lindex $v 2]
12683 set viewargscmd($n) [lindex $v 3]
12685 set viewchanged($n) 0
12690 if {[tk windowingsystem] eq "win32"} {
12698 # indent-tabs-mode: t