2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2014 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 set n
[file normalize
$gitdir]
20 if {[string match
"*/.git" $n]} {
21 set n
[string range
$n 0 end-5
]
28 if {[info exists _gitworktree
]} {
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
37 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
38 if {$_gitworktree eq
""} {
39 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
49 # run before X event handlers, so reading from a fast source can
50 # make the GUI completely unresponsive.
52 global isonrunq runq currunq
55 if {[info exists isonrunq
($script)]} return
56 if {$runq eq
{} && ![info exists currunq
]} {
59 lappend runq
[list
{} $script]
60 set isonrunq
($script) 1
63 proc filerun
{fd
script} {
64 fileevent
$fd readable
[list filereadable
$fd $script]
67 proc filereadable
{fd
script} {
70 fileevent
$fd readable
{}
71 if {$runq eq
{} && ![info exists currunq
]} {
74 lappend runq
[list
$fd $script]
80 for {set i
0} {$i < [llength
$runq]} {} {
81 if {[lindex
$runq $i 0] eq
$fd} {
82 set runq
[lreplace
$runq $i $i]
90 global isonrunq runq currunq
92 set tstart
[clock clicks
-milliseconds]
94 while {[llength
$runq] > 0} {
95 set fd
[lindex
$runq 0 0]
96 set script [lindex
$runq 0 1]
97 set currunq
[lindex
$runq 0]
98 set runq
[lrange
$runq 1 end
]
99 set repeat
[eval $script]
101 set t1
[clock clicks
-milliseconds]
102 set t
[expr {$t1 - $t0}]
103 if {$repeat ne
{} && $repeat} {
104 if {$fd eq
{} ||
$repeat == 2} {
105 # script returns 1 if it wants to be readded
106 # file readers return 2 if they could do more straight away
107 lappend runq
[list
$fd $script]
109 fileevent
$fd readable
[list filereadable
$fd $script]
111 } elseif
{$fd eq
{}} {
112 unset isonrunq
($script)
115 if {$t1 - $tstart >= 80} break
122 proc reg_instance
{fd
} {
123 global commfd leftover loginstance
125 set i
[incr loginstance
]
131 proc unmerged_files
{files
} {
134 # find the list of unmerged files
138 set fd
[open
"| git ls-files -u" r
]
140 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
149 if {$files eq {} || [path_filter $files $fname]} {
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
160 global worddiff git_version
164 set vinlinediff($n) 0
169 set origargs $arglist
173 foreach arg $arglist {
180 switch -glob -- $arg {
184 # remove from origargs in case we hit an unknown option
185 set origargs [lreplace $origargs $i $i]
189 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
190 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
191 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
192 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
193 "--ignore-space-change" - "-U*" - "--unified=*" {
194 # These request or affect diff output, which we don't want.
195 # Some could be used to set our defaults for diff display.
196 lappend diffargs
$arg
198 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
199 "--name-only" - "--name-status" - "--color" -
200 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
201 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
202 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
203 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
204 "--objects" - "--objects-edge" - "--reverse" {
205 # These cause our parsing of git log's output to fail, or else
206 # they're options we want to set ourselves, so ignore them.
208 "--color-words*" - "--word-diff=color" {
209 # These trigger a word diff in the console interface,
210 # so help the user by enabling our own support
211 if {[package vcompare
$git_version "1.7.2"] >= 0} {
212 set worddiff
[mc
"Color words"]
216 if {[package vcompare
$git_version "1.7.2"] >= 0} {
217 set worddiff
[mc
"Markup words"]
220 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
221 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
222 "--full-history" - "--dense" - "--sparse" -
223 "--follow" - "--left-right" - "--encoding=*" {
224 # These are harmless, and some are even useful
227 "--diff-filter=*" - "--no-merges" - "--unpacked" -
228 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
229 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
230 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
231 "--remove-empty" - "--first-parent" - "--cherry-pick" -
232 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
233 "--simplify-by-decoration" {
234 # These mean that we get a subset of the commits
239 # Line-log with 'stuck' argument (unstuck form is
242 set vinlinediff
($n) 1
247 # This appears to be the only one that has a value as a
248 # separate word following it
258 # git rev-parse doesn't understand --merge
259 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
261 "--no-replace-objects" {
262 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
265 # Other flag arguments including -<n>
266 if {[string is digit
-strict [string range
$arg 1 end
]]} {
269 # a flag argument that we don't recognize;
270 # that means we can't optimize
276 # Non-flag arguments specify commits or ranges of commits
277 if {[string match
"*...*" $arg]} {
278 lappend revargs
--gitk-symmetric-diff-marker
284 set vdflags
($n) $diffargs
285 set vflags
($n) $glflags
286 set vrevs
($n) $revargs
287 set vfiltered
($n) $filtered
288 set vorigargs
($n) $origargs
292 proc parseviewrevs
{view revs
} {
293 global vposids vnegids
298 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
299 # we get stdout followed by stderr in $err
300 # for an unknown rev, git rev-parse echoes it and then errors out
301 set errlines
[split $err "\n"]
303 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
304 set line
[lindex
$errlines $l]
305 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
306 if {[string match
"fatal:*" $line]} {
307 if {[string match
"fatal: ambiguous argument*" $line]
309 if {[llength
$badrev] == 1} {
310 set err
"unknown revision $badrev"
312 set err
"unknown revisions: [join $badrev ", "]"
315 set err
[join [lrange
$errlines $l end
] "\n"]
322 error_popup
"[mc "Error parsing revisions
:"] $err"
329 foreach id
[split $ids "\n"] {
330 if {$id eq
"--gitk-symmetric-diff-marker"} {
332 } elseif
{[string match
"^*" $id]} {
339 lappend neg
[string range
$id 1 end
]
344 lset ret end
$id...
[lindex
$ret end
]
350 set vposids
($view) $pos
351 set vnegids
($view) $neg
355 # Start off a git log process and arrange to read its output
356 proc start_rev_list
{view
} {
357 global startmsecs commitidx viewcomplete curview
359 global viewargs viewargscmd viewfiles vfilelimit
360 global showlocalchanges
361 global viewactive viewinstances vmergeonly
362 global mainheadid viewmainheadid viewmainheadid_orig
363 global vcanopt vflags vrevs vorigargs
366 set startmsecs
[clock clicks
-milliseconds]
367 set commitidx
($view) 0
368 # these are set this way for the error exits
369 set viewcomplete
($view) 1
370 set viewactive
($view) 0
373 set args
$viewargs($view)
374 if {$viewargscmd($view) ne
{}} {
376 set str
[exec sh
-c $viewargscmd($view)]
378 error_popup
"[mc "Error executing
--argscmd command:"] $err"
381 set args
[concat
$args [split $str "\n"]]
383 set vcanopt
($view) [parseviewargs
$view $args]
385 set files
$viewfiles($view)
386 if {$vmergeonly($view)} {
387 set files
[unmerged_files
$files]
390 if {$nr_unmerged == 0} {
391 error_popup
[mc
"No files selected: --merge specified but\
392 no files are unmerged."]
394 error_popup
[mc
"No files selected: --merge specified but\
395 no unmerged files are within file limit."]
400 set vfilelimit
($view) $files
402 if {$vcanopt($view)} {
403 set revs
[parseviewrevs
$view $vrevs($view)]
407 set args
[concat
$vflags($view) $revs]
409 set args
$vorigargs($view)
413 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
414 --parents --boundary $args "--" $files] r
]
416 error_popup
"[mc "Error executing git log
:"] $err"
419 set i
[reg_instance
$fd]
420 set viewinstances
($view) [list
$i]
421 set viewmainheadid
($view) $mainheadid
422 set viewmainheadid_orig
($view) $mainheadid
423 if {$files ne
{} && $mainheadid ne
{}} {
424 get_viewmainhead
$view
426 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
427 interestedin
$viewmainheadid($view) dodiffindex
429 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
430 if {$tclencoding != {}} {
431 fconfigure
$fd -encoding $tclencoding
433 filerun
$fd [list getcommitlines
$fd $i $view 0]
434 nowbusy
$view [mc
"Reading"]
435 set viewcomplete
($view) 0
436 set viewactive
($view) 1
440 proc stop_instance
{inst
} {
441 global commfd leftover
443 set fd
$commfd($inst)
447 if {$
::tcl_platform
(platform
) eq
{windows
}} {
456 unset leftover
($inst)
459 proc stop_backends
{} {
462 foreach inst
[array names commfd
] {
467 proc stop_rev_list
{view
} {
470 foreach inst
$viewinstances($view) {
473 set viewinstances
($view) {}
476 proc reset_pending_select
{selid
} {
477 global pending_select mainheadid selectheadid
480 set pending_select
$selid
481 } elseif
{$selectheadid ne
{}} {
482 set pending_select
$selectheadid
484 set pending_select
$mainheadid
488 proc getcommits
{selid
} {
489 global canv curview need_redisplay viewactive
492 if {[start_rev_list
$curview]} {
493 reset_pending_select
$selid
494 show_status
[mc
"Reading commits..."]
497 show_status
[mc
"No commits selected"]
501 proc updatecommits
{} {
502 global curview vcanopt vorigargs vfilelimit viewinstances
503 global viewactive viewcomplete tclencoding
504 global startmsecs showneartags showlocalchanges
505 global mainheadid viewmainheadid viewmainheadid_orig pending_select
507 global varcid vposids vnegids vflags vrevs
510 set hasworktree
[hasworktree
]
513 if {$mainheadid ne
$viewmainheadid_orig($view)} {
514 if {$showlocalchanges} {
517 set viewmainheadid
($view) $mainheadid
518 set viewmainheadid_orig
($view) $mainheadid
519 if {$vfilelimit($view) ne
{}} {
520 get_viewmainhead
$view
523 if {$showlocalchanges} {
526 if {$vcanopt($view)} {
527 set oldpos
$vposids($view)
528 set oldneg
$vnegids($view)
529 set revs
[parseviewrevs
$view $vrevs($view)]
533 # note: getting the delta when negative refs change is hard,
534 # and could require multiple git log invocations, so in that
535 # case we ask git log for all the commits (not just the delta)
536 if {$oldneg eq
$vnegids($view)} {
539 # take out positive refs that we asked for before or
540 # that we have already seen
542 if {[string length
$rev] == 40} {
543 if {[lsearch
-exact $oldpos $rev] < 0
544 && ![info exists varcid
($view,$rev)]} {
549 lappend
$newrevs $rev
552 if {$npos == 0} return
554 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
556 set args
[concat
$vflags($view) $revs --not $oldpos]
558 set args
$vorigargs($view)
561 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
562 --parents --boundary $args "--" $vfilelimit($view)] r
]
564 error_popup
"[mc "Error executing git log
:"] $err"
567 if {$viewactive($view) == 0} {
568 set startmsecs
[clock clicks
-milliseconds]
570 set i
[reg_instance
$fd]
571 lappend viewinstances
($view) $i
572 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
573 if {$tclencoding != {}} {
574 fconfigure
$fd -encoding $tclencoding
576 filerun
$fd [list getcommitlines
$fd $i $view 1]
577 incr viewactive
($view)
578 set viewcomplete
($view) 0
579 reset_pending_select
{}
580 nowbusy
$view [mc
"Reading"]
586 proc reloadcommits
{} {
587 global curview viewcomplete selectedline currentid thickerline
588 global showneartags treediffs commitinterest cached_commitrow
592 if {$selectedline ne
{}} {
596 if {!$viewcomplete($curview)} {
597 stop_rev_list
$curview
601 catch
{unset currentid
}
602 catch
{unset thickerline
}
603 catch
{unset treediffs
}
610 catch
{unset commitinterest
}
611 catch
{unset cached_commitrow
}
612 catch
{unset targetid
}
618 # This makes a string representation of a positive integer which
619 # sorts as a string in numerical order
622 return [format
"%x" $n]
623 } elseif
{$n < 256} {
624 return [format
"x%.2x" $n]
625 } elseif
{$n < 65536} {
626 return [format
"y%.4x" $n]
628 return [format
"z%.8x" $n]
631 # Procedures used in reordering commits from git log (without
632 # --topo-order) into the order for display.
634 proc varcinit
{view
} {
635 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
636 global vtokmod varcmod vrowmod varcix vlastins
638 set varcstart
($view) {{}}
639 set vupptr
($view) {0}
640 set vdownptr
($view) {0}
641 set vleftptr
($view) {0}
642 set vbackptr
($view) {0}
643 set varctok
($view) {{}}
644 set varcrow
($view) {{}}
645 set vtokmod
($view) {}
648 set varcix
($view) {{}}
649 set vlastins
($view) {0}
652 proc resetvarcs
{view
} {
653 global varcid varccommits parents children vseedcount ordertok
656 foreach vid
[array names varcid
$view,*] {
661 foreach vid
[array names vshortids
$view,*] {
662 unset vshortids
($vid)
664 # some commits might have children but haven't been seen yet
665 foreach vid
[array names children
$view,*] {
668 foreach va
[array names varccommits
$view,*] {
669 unset varccommits
($va)
671 foreach vd
[array names vseedcount
$view,*] {
672 unset vseedcount
($vd)
674 catch
{unset ordertok
}
677 # returns a list of the commits with no children
679 global vdownptr vleftptr varcstart
682 set a
[lindex
$vdownptr($v) 0]
684 lappend ret
[lindex
$varcstart($v) $a]
685 set a
[lindex
$vleftptr($v) $a]
690 proc newvarc
{view id
} {
691 global varcid varctok parents children vdatemode
692 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
693 global commitdata commitinfo vseedcount varccommits vlastins
695 set a
[llength
$varctok($view)]
697 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
698 if {![info exists commitinfo
($id)]} {
699 parsecommit
$id $commitdata($id) 1
701 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
702 if {![string is integer
-strict $cdate]} {
705 if {![info exists vseedcount
($view,$cdate)]} {
706 set vseedcount
($view,$cdate) -1
708 set c
[incr vseedcount
($view,$cdate)]
709 set cdate
[expr {$cdate ^
0xffffffff}]
710 set tok
"s[strrep $cdate][strrep $c]"
715 if {[llength
$children($vid)] > 0} {
716 set kid
[lindex
$children($vid) end
]
717 set k
$varcid($view,$kid)
718 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
721 set tok
[lindex
$varctok($view) $k]
725 set i
[lsearch
-exact $parents($view,$ki) $id]
726 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
727 append tok
[strrep
$j]
729 set c
[lindex
$vlastins($view) $ka]
730 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
732 set b
[lindex
$vdownptr($view) $ka]
734 set b
[lindex
$vleftptr($view) $c]
736 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
738 set b
[lindex
$vleftptr($view) $c]
741 lset vdownptr
($view) $ka $a
742 lappend vbackptr
($view) 0
744 lset vleftptr
($view) $c $a
745 lappend vbackptr
($view) $c
747 lset vlastins
($view) $ka $a
748 lappend vupptr
($view) $ka
749 lappend vleftptr
($view) $b
751 lset vbackptr
($view) $b $a
753 lappend varctok
($view) $tok
754 lappend varcstart
($view) $id
755 lappend vdownptr
($view) 0
756 lappend varcrow
($view) {}
757 lappend varcix
($view) {}
758 set varccommits
($view,$a) {}
759 lappend vlastins
($view) 0
763 proc splitvarc
{p v
} {
764 global varcid varcstart varccommits varctok vtokmod
765 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
767 set oa
$varcid($v,$p)
768 set otok
[lindex
$varctok($v) $oa]
769 set ac
$varccommits($v,$oa)
770 set i
[lsearch
-exact $varccommits($v,$oa) $p]
772 set na
[llength
$varctok($v)]
773 # "%" sorts before "0"...
774 set tok
"$otok%[strrep $i]"
775 lappend varctok
($v) $tok
776 lappend varcrow
($v) {}
777 lappend varcix
($v) {}
778 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
779 set varccommits
($v,$na) [lrange
$ac $i end
]
780 lappend varcstart
($v) $p
781 foreach id
$varccommits($v,$na) {
782 set varcid
($v,$id) $na
784 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
785 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
786 lset vdownptr
($v) $oa $na
787 lset vlastins
($v) $oa 0
788 lappend vupptr
($v) $oa
789 lappend vleftptr
($v) 0
790 lappend vbackptr
($v) 0
791 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
792 lset vupptr
($v) $b $na
794 if {[string compare
$otok $vtokmod($v)] <= 0} {
799 proc renumbervarc
{a v
} {
800 global parents children varctok varcstart varccommits
801 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
803 set t1
[clock clicks
-milliseconds]
809 if {[info exists isrelated
($a)]} {
811 set id
[lindex
$varccommits($v,$a) end
]
812 foreach p
$parents($v,$id) {
813 if {[info exists varcid
($v,$p)]} {
814 set isrelated
($varcid($v,$p)) 1
819 set b
[lindex
$vdownptr($v) $a]
822 set b
[lindex
$vleftptr($v) $a]
824 set a
[lindex
$vupptr($v) $a]
830 if {![info exists kidchanged
($a)]} continue
831 set id
[lindex
$varcstart($v) $a]
832 if {[llength
$children($v,$id)] > 1} {
833 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
836 set oldtok
[lindex
$varctok($v) $a]
837 if {!$vdatemode($v)} {
843 set kid
[last_real_child
$v,$id]
845 set k
$varcid($v,$kid)
846 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
849 set tok
[lindex
$varctok($v) $k]
853 set i
[lsearch
-exact $parents($v,$ki) $id]
854 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
855 append tok
[strrep
$j]
857 if {$tok eq
$oldtok} {
860 set id
[lindex
$varccommits($v,$a) end
]
861 foreach p
$parents($v,$id) {
862 if {[info exists varcid
($v,$p)]} {
863 set kidchanged
($varcid($v,$p)) 1
868 lset varctok
($v) $a $tok
869 set b
[lindex
$vupptr($v) $a]
871 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
874 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
877 set c
[lindex
$vbackptr($v) $a]
878 set d
[lindex
$vleftptr($v) $a]
880 lset vdownptr
($v) $b $d
882 lset vleftptr
($v) $c $d
885 lset vbackptr
($v) $d $c
887 if {[lindex
$vlastins($v) $b] == $a} {
888 lset vlastins
($v) $b $c
890 lset vupptr
($v) $a $ka
891 set c
[lindex
$vlastins($v) $ka]
893 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
895 set b
[lindex
$vdownptr($v) $ka]
897 set b
[lindex
$vleftptr($v) $c]
900 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
902 set b
[lindex
$vleftptr($v) $c]
905 lset vdownptr
($v) $ka $a
906 lset vbackptr
($v) $a 0
908 lset vleftptr
($v) $c $a
909 lset vbackptr
($v) $a $c
911 lset vleftptr
($v) $a $b
913 lset vbackptr
($v) $b $a
915 lset vlastins
($v) $ka $a
918 foreach id
[array names sortkids
] {
919 if {[llength
$children($v,$id)] > 1} {
920 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
924 set t2
[clock clicks
-milliseconds]
925 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
928 # Fix up the graph after we have found out that in view $v,
929 # $p (a commit that we have already seen) is actually the parent
930 # of the last commit in arc $a.
931 proc fix_reversal
{p a v
} {
932 global varcid varcstart varctok vupptr
934 set pa
$varcid($v,$p)
935 if {$p ne
[lindex
$varcstart($v) $pa]} {
937 set pa
$varcid($v,$p)
939 # seeds always need to be renumbered
940 if {[lindex
$vupptr($v) $pa] == 0 ||
941 [string compare
[lindex
$varctok($v) $a] \
942 [lindex
$varctok($v) $pa]] > 0} {
947 proc insertrow
{id p v
} {
948 global cmitlisted children parents varcid varctok vtokmod
949 global varccommits ordertok commitidx numcommits curview
950 global targetid targetrow vshortids
954 set cmitlisted
($vid) 1
955 set children
($vid) {}
956 set parents
($vid) [list
$p]
957 set a
[newvarc
$v $id]
959 lappend vshortids
($v,[string range
$id 0 3]) $id
960 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
963 lappend varccommits
($v,$a) $id
965 if {[llength
[lappend children
($vp) $id]] > 1} {
966 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
967 catch
{unset ordertok
}
969 fix_reversal
$p $a $v
971 if {$v == $curview} {
972 set numcommits
$commitidx($v)
974 if {[info exists targetid
]} {
975 if {![comes_before
$targetid $p]} {
982 proc insertfakerow
{id p
} {
983 global varcid varccommits parents children cmitlisted
984 global commitidx varctok vtokmod targetid targetrow curview numcommits
988 set i
[lsearch
-exact $varccommits($v,$a) $p]
990 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
993 set children
($v,$id) {}
994 set parents
($v,$id) [list
$p]
995 set varcid
($v,$id) $a
996 lappend children
($v,$p) $id
997 set cmitlisted
($v,$id) 1
998 set numcommits
[incr commitidx
($v)]
999 # note we deliberately don't update varcstart($v) even if $i == 0
1000 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
1002 if {[info exists targetid
]} {
1003 if {![comes_before
$targetid $p]} {
1011 proc removefakerow
{id
} {
1012 global varcid varccommits parents children commitidx
1013 global varctok vtokmod cmitlisted currentid selectedline
1014 global targetid curview numcommits
1017 if {[llength
$parents($v,$id)] != 1} {
1018 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1021 set p
[lindex
$parents($v,$id) 0]
1022 set a
$varcid($v,$id)
1023 set i
[lsearch
-exact $varccommits($v,$a) $id]
1025 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1028 unset varcid
($v,$id)
1029 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1030 unset parents
($v,$id)
1031 unset children
($v,$id)
1032 unset cmitlisted
($v,$id)
1033 set numcommits
[incr commitidx
($v) -1]
1034 set j
[lsearch
-exact $children($v,$p) $id]
1036 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1039 if {[info exist currentid
] && $id eq
$currentid} {
1043 if {[info exists targetid
] && $targetid eq
$id} {
1050 proc real_children
{vp
} {
1051 global children nullid nullid2
1054 foreach id
$children($vp) {
1055 if {$id ne
$nullid && $id ne
$nullid2} {
1062 proc first_real_child
{vp
} {
1063 global children nullid nullid2
1065 foreach id
$children($vp) {
1066 if {$id ne
$nullid && $id ne
$nullid2} {
1073 proc last_real_child
{vp
} {
1074 global children nullid nullid2
1076 set kids
$children($vp)
1077 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1078 set id
[lindex
$kids $i]
1079 if {$id ne
$nullid && $id ne
$nullid2} {
1086 proc vtokcmp
{v a b
} {
1087 global varctok varcid
1089 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1090 [lindex
$varctok($v) $varcid($v,$b)]]
1093 # This assumes that if lim is not given, the caller has checked that
1094 # arc a's token is less than $vtokmod($v)
1095 proc modify_arc
{v a
{lim
{}}} {
1096 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1099 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1102 set r
[lindex
$varcrow($v) $a]
1103 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1106 set vtokmod
($v) [lindex
$varctok($v) $a]
1108 if {$v == $curview} {
1109 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1110 set a
[lindex
$vupptr($v) $a]
1116 set lim
[llength
$varccommits($v,$a)]
1118 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1125 proc update_arcrows
{v
} {
1126 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1127 global varcid vrownum varcorder varcix varccommits
1128 global vupptr vdownptr vleftptr varctok
1129 global displayorder parentlist curview cached_commitrow
1131 if {$vrowmod($v) == $commitidx($v)} return
1132 if {$v == $curview} {
1133 if {[llength
$displayorder] > $vrowmod($v)} {
1134 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1135 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1137 catch
{unset cached_commitrow
}
1139 set narctot
[expr {[llength
$varctok($v)] - 1}]
1141 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1142 # go up the tree until we find something that has a row number,
1143 # or we get to a seed
1144 set a
[lindex
$vupptr($v) $a]
1147 set a
[lindex
$vdownptr($v) 0]
1150 set varcorder
($v) [list
$a]
1151 lset varcix
($v) $a 0
1152 lset varcrow
($v) $a 0
1156 set arcn
[lindex
$varcix($v) $a]
1157 if {[llength
$vrownum($v)] > $arcn + 1} {
1158 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1159 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1161 set row
[lindex
$varcrow($v) $a]
1165 incr row
[llength
$varccommits($v,$a)]
1166 # go down if possible
1167 set b
[lindex
$vdownptr($v) $a]
1169 # if not, go left, or go up until we can go left
1171 set b
[lindex
$vleftptr($v) $a]
1173 set a
[lindex
$vupptr($v) $a]
1179 lappend vrownum
($v) $row
1180 lappend varcorder
($v) $a
1181 lset varcix
($v) $a $arcn
1182 lset varcrow
($v) $a $row
1184 set vtokmod
($v) [lindex
$varctok($v) $p]
1186 set vrowmod
($v) $row
1187 if {[info exists currentid
]} {
1188 set selectedline
[rowofcommit
$currentid]
1192 # Test whether view $v contains commit $id
1193 proc commitinview
{id v
} {
1196 return [info exists varcid
($v,$id)]
1199 # Return the row number for commit $id in the current view
1200 proc rowofcommit
{id
} {
1201 global varcid varccommits varcrow curview cached_commitrow
1202 global varctok vtokmod
1205 if {![info exists varcid
($v,$id)]} {
1206 puts
"oops rowofcommit no arc for [shortids $id]"
1209 set a
$varcid($v,$id)
1210 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1213 if {[info exists cached_commitrow
($id)]} {
1214 return $cached_commitrow($id)
1216 set i
[lsearch
-exact $varccommits($v,$a) $id]
1218 puts
"oops didn't find commit [shortids $id] in arc $a"
1221 incr i
[lindex
$varcrow($v) $a]
1222 set cached_commitrow
($id) $i
1226 # Returns 1 if a is on an earlier row than b, otherwise 0
1227 proc comes_before
{a b
} {
1228 global varcid varctok curview
1231 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1232 ![info exists varcid
($v,$b)]} {
1235 if {$varcid($v,$a) != $varcid($v,$b)} {
1236 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1237 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1239 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1242 proc bsearch
{l elt
} {
1243 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1248 while {$hi - $lo > 1} {
1249 set mid
[expr {int
(($lo + $hi) / 2)}]
1250 set t
[lindex
$l $mid]
1253 } elseif
{$elt > $t} {
1262 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1263 proc make_disporder
{start end
} {
1264 global vrownum curview commitidx displayorder parentlist
1265 global varccommits varcorder parents vrowmod varcrow
1266 global d_valid_start d_valid_end
1268 if {$end > $vrowmod($curview)} {
1269 update_arcrows
$curview
1271 set ai
[bsearch
$vrownum($curview) $start]
1272 set start
[lindex
$vrownum($curview) $ai]
1273 set narc
[llength
$vrownum($curview)]
1274 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1275 set a
[lindex
$varcorder($curview) $ai]
1276 set l
[llength
$displayorder]
1277 set al
[llength
$varccommits($curview,$a)]
1278 if {$l < $r + $al} {
1280 set pad
[ntimes
[expr {$r - $l}] {}]
1281 set displayorder
[concat
$displayorder $pad]
1282 set parentlist
[concat
$parentlist $pad]
1283 } elseif
{$l > $r} {
1284 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1285 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1287 foreach id
$varccommits($curview,$a) {
1288 lappend displayorder
$id
1289 lappend parentlist
$parents($curview,$id)
1291 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1293 foreach id
$varccommits($curview,$a) {
1294 lset displayorder
$i $id
1295 lset parentlist
$i $parents($curview,$id)
1303 proc commitonrow
{row
} {
1306 set id
[lindex
$displayorder $row]
1308 make_disporder
$row [expr {$row + 1}]
1309 set id
[lindex
$displayorder $row]
1314 proc closevarcs
{v
} {
1315 global varctok varccommits varcid parents children
1316 global cmitlisted commitidx vtokmod
1318 set missing_parents
0
1320 set narcs
[llength
$varctok($v)]
1321 for {set a
1} {$a < $narcs} {incr a
} {
1322 set id
[lindex
$varccommits($v,$a) end
]
1323 foreach p
$parents($v,$id) {
1324 if {[info exists varcid
($v,$p)]} continue
1325 # add p as a new commit
1326 incr missing_parents
1327 set cmitlisted
($v,$p) 0
1328 set parents
($v,$p) {}
1329 if {[llength
$children($v,$p)] == 1 &&
1330 [llength
$parents($v,$id)] == 1} {
1333 set b
[newvarc
$v $p]
1335 set varcid
($v,$p) $b
1336 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1339 lappend varccommits
($v,$b) $p
1341 set scripts
[check_interest
$p $scripts]
1344 if {$missing_parents > 0} {
1345 foreach s
$scripts {
1351 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1352 # Assumes we already have an arc for $rwid.
1353 proc rewrite_commit
{v id rwid
} {
1354 global children parents varcid varctok vtokmod varccommits
1356 foreach ch
$children($v,$id) {
1357 # make $rwid be $ch's parent in place of $id
1358 set i
[lsearch
-exact $parents($v,$ch) $id]
1360 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1362 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1363 # add $ch to $rwid's children and sort the list if necessary
1364 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1365 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1366 $children($v,$rwid)]
1368 # fix the graph after joining $id to $rwid
1369 set a
$varcid($v,$ch)
1370 fix_reversal
$rwid $a $v
1371 # parentlist is wrong for the last element of arc $a
1372 # even if displayorder is right, hence the 3rd arg here
1373 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1377 # Mechanism for registering a command to be executed when we come
1378 # across a particular commit. To handle the case when only the
1379 # prefix of the commit is known, the commitinterest array is now
1380 # indexed by the first 4 characters of the ID. Each element is a
1381 # list of id, cmd pairs.
1382 proc interestedin
{id cmd
} {
1383 global commitinterest
1385 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1388 proc check_interest
{id scripts
} {
1389 global commitinterest
1391 set prefix
[string range
$id 0 3]
1392 if {[info exists commitinterest
($prefix)]} {
1394 foreach
{i
script} $commitinterest($prefix) {
1395 if {[string match
"$i*" $id]} {
1396 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1398 lappend newlist
$i $script
1401 if {$newlist ne
{}} {
1402 set commitinterest
($prefix) $newlist
1404 unset commitinterest
($prefix)
1410 proc getcommitlines
{fd inst view updating
} {
1411 global cmitlisted leftover
1412 global commitidx commitdata vdatemode
1413 global parents children curview hlview
1414 global idpending ordertok
1415 global varccommits varcid varctok vtokmod vfilelimit vshortids
1417 set stuff
[read $fd 500000]
1418 # git log doesn't terminate the last commit with a null...
1419 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1426 global commfd viewcomplete viewactive viewname
1427 global viewinstances
1429 set i
[lsearch
-exact $viewinstances($view) $inst]
1431 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1433 # set it blocking so we wait for the process to terminate
1434 fconfigure
$fd -blocking 1
1435 if {[catch
{close
$fd} err
]} {
1437 if {$view != $curview} {
1438 set fv
" for the \"$viewname($view)\" view"
1440 if {[string range
$err 0 4] == "usage"} {
1441 set err
"Gitk: error reading commits$fv:\
1442 bad arguments to git log."
1443 if {$viewname($view) eq
"Command line"} {
1445 " (Note: arguments to gitk are passed to git log\
1446 to allow selection of commits to be displayed.)"
1449 set err
"Error reading commits$fv: $err"
1453 if {[incr viewactive
($view) -1] <= 0} {
1454 set viewcomplete
($view) 1
1455 # Check if we have seen any ids listed as parents that haven't
1456 # appeared in the list
1460 if {$view == $curview} {
1469 set i
[string first
"\0" $stuff $start]
1471 append leftover
($inst) [string range
$stuff $start end
]
1475 set cmit
$leftover($inst)
1476 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1477 set leftover
($inst) {}
1479 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1481 set start
[expr {$i + 1}]
1482 set j
[string first
"\n" $cmit]
1485 if {$j >= 0 && [string match
"commit *" $cmit]} {
1486 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1487 if {[string match
{[-^
<>]*} $ids]} {
1488 switch
-- [string index
$ids 0] {
1494 set ids
[string range
$ids 1 end
]
1498 if {[string length
$id] != 40} {
1506 if {[string length
$shortcmit] > 80} {
1507 set shortcmit
"[string range $shortcmit 0 80]..."
1509 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1512 set id [lindex $ids 0]
1515 lappend vshortids($view,[string range $id 0 3]) $id
1517 if {!$listed && $updating && ![info exists varcid($vid)] &&
1518 $vfilelimit($view) ne {}} {
1519 # git log doesn't rewrite parents
for unlisted commits
1520 # when doing path limiting, so work around that here
1521 # by working out the rewritten parent with git rev-list
1522 # and if we already know about it, using the rewritten
1523 # parent as a substitute parent for $id's children.
1525 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1526 $id -- $vfilelimit($view)]
1528 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1529 # use $rwid in place of $id
1530 rewrite_commit
$view $id $rwid
1537 if {[info exists varcid
($vid)]} {
1538 if {$cmitlisted($vid) ||
!$listed} continue
1542 set olds
[lrange
$ids 1 end
]
1546 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1547 set cmitlisted
($vid) $listed
1548 set parents
($vid) $olds
1549 if {![info exists children
($vid)]} {
1550 set children
($vid) {}
1551 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1552 set k
[lindex
$children($vid) 0]
1553 if {[llength
$parents($view,$k)] == 1 &&
1554 (!$vdatemode($view) ||
1555 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1556 set a
$varcid($view,$k)
1561 set a
[newvarc
$view $id]
1563 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1566 if {![info exists varcid
($vid)]} {
1568 lappend varccommits
($view,$a) $id
1569 incr commitidx
($view)
1574 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1576 if {[llength
[lappend children
($vp) $id]] > 1 &&
1577 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1578 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1580 catch
{unset ordertok
}
1582 if {[info exists varcid
($view,$p)]} {
1583 fix_reversal
$p $a $view
1589 set scripts
[check_interest
$id $scripts]
1593 global numcommits hlview
1595 if {$view == $curview} {
1596 set numcommits
$commitidx($view)
1599 if {[info exists hlview
] && $view == $hlview} {
1600 # we never actually get here...
1603 foreach s
$scripts {
1610 proc chewcommits
{} {
1611 global curview hlview viewcomplete
1612 global pending_select
1615 if {$viewcomplete($curview)} {
1616 global commitidx varctok
1617 global numcommits startmsecs
1619 if {[info exists pending_select
]} {
1621 reset_pending_select
{}
1623 if {[commitinview
$pending_select $curview]} {
1624 selectline
[rowofcommit
$pending_select] 1
1626 set row
[first_real_row
]
1630 if {$commitidx($curview) > 0} {
1631 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1632 #puts "overall $ms ms for $numcommits commits"
1633 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1635 show_status
[mc
"No commits selected"]
1642 proc do_readcommit
{id
} {
1645 # Invoke git-log to handle automatic encoding conversion
1646 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1647 # Read the results using i18n.logoutputencoding
1648 fconfigure
$fd -translation lf
-eofchar {}
1649 if {$tclencoding != {}} {
1650 fconfigure
$fd -encoding $tclencoding
1652 set contents
[read $fd]
1654 # Remove the heading line
1655 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1660 proc readcommit
{id
} {
1661 if {[catch
{set contents
[do_readcommit
$id]}]} return
1662 parsecommit
$id $contents 1
1665 proc parsecommit
{id contents listed
} {
1675 set hdrend
[string first
"\n\n" $contents]
1677 # should never happen...
1678 set hdrend
[string length
$contents]
1680 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1681 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1682 foreach line
[split $header "\n"] {
1683 set line
[split $line " "]
1684 set tag
[lindex
$line 0]
1685 if {$tag == "author"} {
1686 set audate
[lrange
$line end-1 end
]
1687 set auname
[join [lrange
$line 1 end-2
] " "]
1688 } elseif
{$tag == "committer"} {
1689 set comdate
[lrange
$line end-1 end
]
1690 set comname
[join [lrange
$line 1 end-2
] " "]
1694 # take the first non-blank line of the comment as the headline
1695 set headline
[string trimleft
$comment]
1696 set i
[string first
"\n" $headline]
1698 set headline
[string range
$headline 0 $i]
1700 set headline
[string trimright
$headline]
1701 set i
[string first
"\r" $headline]
1703 set headline
[string trimright
[string range
$headline 0 $i]]
1706 # git log indents the comment by 4 spaces;
1707 # if we got this via git cat-file, add the indentation
1709 foreach line
[split $comment "\n"] {
1710 append newcomment
" "
1711 append newcomment
$line
1712 append newcomment
"\n"
1714 set comment
$newcomment
1716 set hasnote
[string first
"\nNotes:\n" $contents]
1718 # If there is diff output shown in the git-log stream, split it
1719 # out. But get rid of the empty line that always precedes the
1721 set i
[string first
"\n\ndiff" $comment]
1723 set diff [string range
$comment $i+1 end
]
1724 set comment
[string range
$comment 0 $i-1]
1726 set commitinfo
($id) [list
$headline $auname $audate \
1727 $comname $comdate $comment $hasnote $diff]
1730 proc getcommit
{id
} {
1731 global commitdata commitinfo
1733 if {[info exists commitdata
($id)]} {
1734 parsecommit
$id $commitdata($id) 1
1737 if {![info exists commitinfo
($id)]} {
1738 set commitinfo
($id) [list
[mc
"No commit information available"]]
1744 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1745 # and are present in the current view.
1746 # This is fairly slow...
1747 proc longid
{prefix
} {
1748 global varcid curview vshortids
1751 if {[string length
$prefix] >= 4} {
1752 set vshortid
$curview,[string range
$prefix 0 3]
1753 if {[info exists vshortids
($vshortid)]} {
1754 foreach id
$vshortids($vshortid) {
1755 if {[string match
"$prefix*" $id]} {
1756 if {[lsearch
-exact $ids $id] < 0} {
1758 if {[llength
$ids] >= 2} break
1764 foreach match
[array names varcid
"$curview,$prefix*"] {
1765 lappend ids
[lindex
[split $match ","] 1]
1766 if {[llength
$ids] >= 2} break
1773 global tagids idtags headids idheads tagobjid
1774 global otherrefids idotherrefs mainhead mainheadid
1775 global selecthead selectheadid
1778 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1781 set refd
[open
[list | git show-ref
-d] r
]
1782 while {[gets
$refd line
] >= 0} {
1783 if {[string index
$line 40] ne
" "} continue
1784 set id
[string range
$line 0 39]
1785 set ref
[string range
$line 41 end
]
1786 if {![string match
"refs/*" $ref]} continue
1787 set name
[string range
$ref 5 end
]
1788 if {[string match
"remotes/*" $name]} {
1789 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1790 set headids
($name) $id
1791 lappend idheads
($id) $name
1793 } elseif
{[string match
"heads/*" $name]} {
1794 set name
[string range
$name 6 end
]
1795 set headids
($name) $id
1796 lappend idheads
($id) $name
1797 } elseif
{[string match
"tags/*" $name]} {
1798 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1799 # which is what we want since the former is the commit ID
1800 set name
[string range
$name 5 end
]
1801 if {[string match
"*^{}" $name]} {
1802 set name
[string range
$name 0 end-3
]
1804 set tagobjid
($name) $id
1806 set tagids
($name) $id
1807 lappend idtags
($id) $name
1809 set otherrefids
($name) $id
1810 lappend idotherrefs
($id) $name
1817 set mainheadid
[exec git rev-parse HEAD
]
1818 set thehead
[exec git symbolic-ref HEAD
]
1819 if {[string match
"refs/heads/*" $thehead]} {
1820 set mainhead
[string range
$thehead 11 end
]
1824 if {$selecthead ne
{}} {
1826 set selectheadid
[exec git rev-parse
--verify $selecthead]
1831 # skip over fake commits
1832 proc first_real_row
{} {
1833 global nullid nullid2 numcommits
1835 for {set row
0} {$row < $numcommits} {incr row
} {
1836 set id
[commitonrow
$row]
1837 if {$id ne
$nullid && $id ne
$nullid2} {
1844 # update things for a head moved to a child of its previous location
1845 proc movehead
{id name
} {
1846 global headids idheads
1848 removehead
$headids($name) $name
1849 set headids
($name) $id
1850 lappend idheads
($id) $name
1853 # update things when a head has been removed
1854 proc removehead
{id name
} {
1855 global headids idheads
1857 if {$idheads($id) eq
$name} {
1860 set i
[lsearch
-exact $idheads($id) $name]
1862 set idheads
($id) [lreplace
$idheads($id) $i $i]
1865 unset headids
($name)
1868 proc ttk_toplevel
{w args
} {
1870 eval [linsert
$args 0 ::toplevel
$w]
1872 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1877 proc make_transient
{window origin
} {
1880 # In MacOS Tk 8.4 transient appears to work by setting
1881 # overrideredirect, which is utterly useless, since the
1882 # windows get no border, and are not even kept above
1884 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1886 wm transient
$window $origin
1888 # Windows fails to place transient windows normally, so
1889 # schedule a callback to center them on the parent.
1890 if {[tk windowingsystem
] eq
{win32
}} {
1891 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1895 proc show_error
{w top msg
{mc mc
}} {
1897 if {![info exists NS
]} {set NS
""}
1898 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1899 message
$w.m
-text $msg -justify center
-aspect 400
1900 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1901 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1902 pack
$w.ok
-side bottom
-fill x
1903 bind $top <Visibility
> "grab $top; focus $top"
1904 bind $top <Key-Return
> "destroy $top"
1905 bind $top <Key-space
> "destroy $top"
1906 bind $top <Key-Escape
> "destroy $top"
1910 proc error_popup
{msg
{owner .
}} {
1911 if {[tk windowingsystem
] eq
"win32"} {
1912 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1913 -parent $owner -message $msg
1917 make_transient
$w $owner
1918 show_error
$w $w $msg
1922 proc confirm_popup
{msg
{owner .
}} {
1923 global confirm_ok NS
1927 make_transient
$w $owner
1928 message
$w.m
-text $msg -justify center
-aspect 400
1929 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1930 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1931 pack
$w.ok
-side left
-fill x
1932 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1933 pack
$w.cancel
-side right
-fill x
1934 bind $w <Visibility
> "grab $w; focus $w"
1935 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1936 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1937 bind $w <Key-Escape
> "destroy $w"
1938 tk
::PlaceWindow
$w widget
$owner
1943 proc setoptions
{} {
1944 if {[tk windowingsystem
] ne
"win32"} {
1945 option add
*Panedwindow.showHandle
1 startupFile
1946 option add
*Panedwindow.sashRelief raised startupFile
1947 if {[tk windowingsystem
] ne
"aqua"} {
1948 option add
*Menu.font uifont startupFile
1951 option add
*Menu.TearOff
0 startupFile
1953 option add
*Button.font uifont startupFile
1954 option add
*Checkbutton.font uifont startupFile
1955 option add
*Radiobutton.font uifont startupFile
1956 option add
*Menubutton.font uifont startupFile
1957 option add
*Label.font uifont startupFile
1958 option add
*Message.font uifont startupFile
1959 option add
*Entry.font textfont startupFile
1960 option add
*Text.font textfont startupFile
1961 option add
*Labelframe.font uifont startupFile
1962 option add
*Spinbox.font textfont startupFile
1963 option add
*Listbox.font mainfont startupFile
1966 # Make a menu and submenus.
1967 # m is the window name for the menu, items is the list of menu items to add.
1968 # Each item is a list {mc label type description options...}
1969 # mc is ignored; it's so we can put mc there to alert xgettext
1970 # label is the string that appears in the menu
1971 # type is cascade, command or radiobutton (should add checkbutton)
1972 # description depends on type; it's the sublist for cascade, the
1973 # command to invoke for command, or {variable value} for radiobutton
1974 proc makemenu
{m items
} {
1976 if {[tk windowingsystem
] eq
{aqua
}} {
1982 set name
[mc
[lindex
$i 1]]
1983 set type [lindex
$i 2]
1984 set thing
[lindex
$i 3]
1985 set params
[list
$type]
1987 set u
[string first
"&" [string map
{&& x
} $name]]
1988 lappend params
-label [string map
{&& & & {}} $name]
1990 lappend params
-underline $u
1995 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1996 lappend params
-menu $m.
$submenu
1999 lappend params
-command $thing
2002 lappend params
-variable [lindex
$thing 0] \
2003 -value [lindex
$thing 1]
2006 set tail [lrange
$i 4 end
]
2007 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2008 eval $m add
$params $tail
2009 if {$type eq
"cascade"} {
2010 makemenu
$m.
$submenu $thing
2015 # translate string and remove ampersands
2017 return [string map
{&& & & {}} [mc
$str]]
2020 proc cleardropsel
{w
} {
2023 proc makedroplist
{w varname args
} {
2027 foreach label
$args {
2028 set cx
[string length
$label]
2029 if {$cx > $width} {set width
$cx}
2031 set gm
[ttk
::combobox
$w -width $width -state readonly\
2032 -textvariable $varname -values $args \
2033 -exportselection false
]
2034 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2036 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2041 proc makewindow {} {
2042 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2044 global findtype findtypemenu findloc findstring fstring geometry
2045 global entries sha1entry sha1string sha1but
2046 global diffcontextstring diffcontext
2048 global maincursor textcursor curtextcursor
2049 global rowctxmenu fakerowmenu mergemax wrapcomment
2050 global highlight_files gdttype
2051 global searchstring sstring
2052 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2053 global uifgcolor uifgdisabledcolor
2054 global filesepbgcolor filesepfgcolor
2055 global mergecolors foundbgcolor currentsearchhitbgcolor
2056 global headctxmenu progresscanv progressitem progresscoords statusw
2057 global fprogitem fprogcoord lastprogupdate progupdatepending
2058 global rprogitem rprogcoord rownumsel numcommits
2059 global have_tk85 use_ttk NS
2063 # The "mc" arguments here are purely so that xgettext
2064 # sees the following string as needing to be translated
2067 {mc "Update" command updatecommits -accelerator F5}
2068 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2069 {mc "Reread references" command rereadrefs}
2070 {mc "List references" command showrefs -accelerator F2}
2072 {mc "Start git gui" command {exec git gui &}}
2074 {mc "Quit" command doquit -accelerator Meta1-Q}
2078 {mc "Preferences" command doprefs}
2082 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2083 {mc "Edit view..." command editview -state disabled -accelerator F4}
2084 {mc "Delete view" command delview -state disabled}
2086 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2088 if {[tk windowingsystem] ne "aqua"} {
2091 {mc "About gitk" command about}
2092 {mc "Key bindings" command keys}
2094 set bar [list $file $edit $view $help]
2096 proc ::tk::mac::ShowPreferences {} {doprefs}
2097 proc ::tk::mac::Quit {} {doquit}
2098 lset file end [lreplace [lindex $file end] end-1 end]
2100 xx "Apple" cascade {
2101 {mc "About gitk" command about}
2106 {mc "Key bindings" command keys}
2108 set bar [list $apple $file $view $help]
2111 . configure -menu .bar
2114 # cover the non-themed toplevel with a themed frame.
2115 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2118 # the gui has upper and lower half, parts of a paned window.
2119 ${NS}::panedwindow .ctop -orient vertical
2121 # possibly use assumed geometry
2122 if {![info exists geometry(pwsash0)]} {
2123 set geometry(topheight) [expr {15 * $linespc}]
2124 set geometry(topwidth) [expr {80 * $charspc}]
2125 set geometry(botheight) [expr {15 * $linespc}]
2126 set geometry(botwidth) [expr {50 * $charspc}]
2127 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2128 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2131 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2132 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2133 ${NS}::frame .tf.histframe
2134 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2136 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2139 # create three canvases
2140 set cscroll .tf.histframe.csb
2141 set canv .tf.histframe.pwclist.canv
2143 -selectbackground $selectbgcolor \
2144 -background $bgcolor -bd 0 \
2145 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2146 .tf.histframe.pwclist add $canv
2147 set canv2 .tf.histframe.pwclist.canv2
2149 -selectbackground $selectbgcolor \
2150 -background $bgcolor -bd 0 -yscrollincr $linespc
2151 .tf.histframe.pwclist add $canv2
2152 set canv3 .tf.histframe.pwclist.canv3
2154 -selectbackground $selectbgcolor \
2155 -background $bgcolor -bd 0 -yscrollincr $linespc
2156 .tf.histframe.pwclist add $canv3
2158 bind .tf.histframe.pwclist <Map> {
2160 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2161 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2164 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2165 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2168 # a scroll bar to rule them
2169 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2170 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2171 pack $cscroll -side right -fill y
2172 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2173 lappend bglist $canv $canv2 $canv3
2174 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2176 # we have two button bars at bottom of top frame. Bar 1
2177 ${NS}::frame .tf.bar
2178 ${NS}::frame .tf.lbar -height 15
2180 set sha1entry .tf.bar.sha1
2181 set entries $sha1entry
2182 set sha1but .tf.bar.sha1label
2183 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2184 -command gotocommit -width 8
2185 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2186 pack .tf.bar.sha1label -side left
2187 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2188 trace add variable sha1string write sha1change
2189 pack $sha1entry -side left -pady 2
2192 #define left_width 16
2193 #define left_height 16
2194 static unsigned char left_bits[] = {
2195 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2196 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2197 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2200 #define right_width 16
2201 #define right_height 16
2202 static unsigned char right_bits[] = {
2203 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2204 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2205 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2207 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2208 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2209 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2210 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2212 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2214 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2216 .tf.bar.leftbut configure -image bm-left
2218 pack .tf.bar.leftbut -side left -fill y
2219 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2221 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2223 .tf.bar.rightbut configure -image bm-right
2225 pack .tf.bar.rightbut -side left -fill y
2227 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2229 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2230 -relief sunken -anchor e
2231 ${NS}::label .tf.bar.rowlabel2 -text "/"
2232 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2233 -relief sunken -anchor e
2234 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2237 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2240 trace add variable selectedline write selectedline_change
2242 # Status label and progress bar
2243 set statusw .tf.bar.status
2244 ${NS}::label $statusw -width 15 -relief sunken
2245 pack $statusw -side left -padx 5
2247 set progresscanv [ttk::progressbar .tf.bar.progress]
2249 set h [expr {[font metrics uifont -linespace] + 2}]
2250 set progresscanv .tf.bar.progress
2251 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2252 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2253 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2254 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2256 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2257 set progresscoords {0 0}
2260 bind $progresscanv <Configure> adjustprogress
2261 set lastprogupdate [clock clicks -milliseconds]
2262 set progupdatepending 0
2264 # build up the bottom bar of upper window
2265 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2268 #define down_width 16
2269 #define down_height 16
2270 static unsigned char down_bits[] = {
2271 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2272 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2273 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2274 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
2276 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2277 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2278 .tf.lbar.fnext configure -image bm-down
2282 #define up_height 16
2283 static unsigned char up_bits[] = {
2284 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2285 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2286 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2287 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
2289 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2290 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2291 .tf.lbar.fprev configure -image bm-up
2293 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2295 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2297 set gdttype [mc "containing:"]
2298 set gm [makedroplist .tf.lbar.gdttype gdttype \
2299 [mc "containing:"] \
2300 [mc "touching paths:"] \
2301 [mc "adding/removing string:"] \
2302 [mc "changing lines matching:"]]
2303 trace add variable gdttype write gdttype_change
2304 pack .tf.lbar.gdttype -side left -fill y
2307 set fstring .tf.lbar.findstring
2308 lappend entries $fstring
2309 ${NS}::entry $fstring -width 30 -textvariable findstring
2310 trace add variable findstring write find_change
2311 set findtype [mc "Exact"]
2312 set findtypemenu [makedroplist .tf.lbar.findtype \
2313 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2314 trace add variable findtype write findcom_change
2315 set findloc [mc "All fields"]
2316 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2317 [mc "Comments"] [mc "Author"] [mc "Committer"]
2318 trace add variable findloc write find_change
2319 pack .tf.lbar.findloc -side right
2320 pack .tf.lbar.findtype -side right
2321 pack $fstring -side left -expand 1 -fill x
2323 # Finish putting the upper half of the viewer together
2324 pack .tf.lbar -in .tf -side bottom -fill x
2325 pack .tf.bar -in .tf -side bottom -fill x
2326 pack .tf.histframe -fill both -side top -expand 1
2329 .ctop paneconfigure .tf -height $geometry(topheight)
2330 .ctop paneconfigure .tf -width $geometry(topwidth)
2333 # now build up the bottom
2334 ${NS}::panedwindow .pwbottom -orient horizontal
2336 # lower left, a text box over search bar, scroll bar to the right
2337 # if we know window height, then that will set the lower text height, otherwise
2338 # we set lower text height which will drive window height
2339 if {[info exists geometry(main)]} {
2340 ${NS}::frame .bleft -width $geometry(botwidth)
2342 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2344 ${NS}::frame .bleft.top
2345 ${NS}::frame .bleft.mid
2346 ${NS}::frame .bleft.bottom
2348 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2349 pack .bleft.top.search -side left -padx 5
2350 set sstring .bleft.top.sstring
2352 ${NS}::entry $sstring -width 20 -textvariable searchstring
2353 lappend entries $sstring
2354 trace add variable searchstring write incrsearch
2355 pack $sstring -side left -expand 1 -fill x
2356 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2357 -command changediffdisp -variable diffelide -value {0 0}
2358 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2359 -command changediffdisp -variable diffelide -value {0 1}
2360 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2361 -command changediffdisp -variable diffelide -value {1 0}
2362 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2363 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2364 spinbox .bleft.mid.diffcontext -width 5 \
2365 -from 0 -increment 1 -to 10000000 \
2366 -validate all -validatecommand "diffcontextvalidate %P" \
2367 -textvariable diffcontextstring
2368 .bleft.mid.diffcontext set $diffcontext
2369 trace add variable diffcontextstring write diffcontextchange
2370 lappend entries .bleft.mid.diffcontext
2371 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2372 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2373 -command changeignorespace -variable ignorespace
2374 pack .bleft.mid.ignspace -side left -padx 5
2376 set worddiff [mc "Line diff"]
2377 if {[package vcompare $git_version "1.7.2"] >= 0} {
2378 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2379 [mc "Markup words"] [mc "Color words"]
2380 trace add variable worddiff write changeworddiff
2381 pack .bleft.mid.worddiff -side left -padx 5
2384 set ctext .bleft.bottom.ctext
2385 text $ctext -background $bgcolor -foreground $fgcolor \
2386 -state disabled -font textfont \
2387 -yscrollcommand scrolltext -wrap none \
2388 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2390 $ctext conf -tabstyle wordprocessor
2392 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2393 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2394 pack .bleft.top -side top -fill x
2395 pack .bleft.mid -side top -fill x
2396 grid $ctext .bleft.bottom.sb -sticky nsew
2397 grid .bleft.bottom.sbhorizontal -sticky ew
2398 grid columnconfigure .bleft.bottom 0 -weight 1
2399 grid rowconfigure .bleft.bottom 0 -weight 1
2400 grid rowconfigure .bleft.bottom 1 -weight 0
2401 pack .bleft.bottom -side top -fill both -expand 1
2402 lappend bglist $ctext
2403 lappend fglist $ctext
2405 $ctext tag conf comment -wrap $wrapcomment
2406 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2407 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2408 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2409 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2410 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2411 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2412 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2413 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2414 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2415 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2416 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2417 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2418 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2419 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2420 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2421 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2422 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2423 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2424 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2425 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2426 $ctext tag conf mmax -fore darkgrey
2428 $ctext tag conf mresult -font textfontbold
2429 $ctext tag conf msep -font textfontbold
2430 $ctext tag conf found -back $foundbgcolor
2431 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2432 $ctext tag conf wwrap -wrap word -lmargin2 1c
2433 $ctext tag conf bold -font textfontbold
2435 .pwbottom add .bleft
2437 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2441 ${NS}::frame .bright
2442 ${NS}::frame .bright.mode
2443 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2444 -command reselectline -variable cmitmode -value "patch"
2445 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2446 -command reselectline -variable cmitmode -value "tree"
2447 grid .bright.mode.patch .bright.mode.tree -sticky ew
2448 pack .bright.mode -side top -fill x
2449 set cflist .bright.cfiles
2450 set indent [font measure mainfont "nn"]
2452 -selectbackground $selectbgcolor \
2453 -background $bgcolor -foreground $fgcolor \
2455 -tabs [list $indent [expr {2 * $indent}]] \
2456 -yscrollcommand ".bright.sb set" \
2457 -cursor [. cget -cursor] \
2458 -spacing1 1 -spacing3 1
2459 lappend bglist $cflist
2460 lappend fglist $cflist
2461 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2462 pack .bright.sb -side right -fill y
2463 pack $cflist -side left -fill both -expand 1
2464 $cflist tag configure highlight \
2465 -background [$cflist cget -selectbackground]
2466 $cflist tag configure bold -font mainfontbold
2468 .pwbottom add .bright
2471 # restore window width & height if known
2472 if {[info exists geometry(main)]} {
2473 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2474 if {$w > [winfo screenwidth .]} {
2475 set w [winfo screenwidth .]
2477 if {$h > [winfo screenheight .]} {
2478 set h [winfo screenheight .]
2480 wm geometry . "${w}x$h"
2484 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2485 wm state . $geometry(state)
2488 if {[tk windowingsystem] eq {aqua}} {
2499 %W sashpos 0 $::geometry(topheight)
2501 bind .pwbottom <Map> {
2503 %W sashpos 0 $::geometry(botwidth)
2507 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2508 pack .ctop -fill both -expand 1
2509 bindall <1> {selcanvline %W %x %y}
2510 #bindall <B1-Motion> {selcanvline %W %x %y}
2511 if {[tk windowingsystem] == "win32"} {
2512 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2513 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2515 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2516 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2517 if {[tk windowingsystem] eq "aqua"} {
2518 bindall <MouseWheel> {
2519 set delta [expr {- (%D)}]
2520 allcanvs yview scroll $delta units
2522 bindall <Shift-MouseWheel> {
2523 set delta [expr {- (%D)}]
2524 $canv xview scroll $delta units
2528 bindall <$::BM> "canvscan mark %W %x %y"
2529 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2530 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2531 bind . <$M1B-Key-w> doquit
2532 bindkey <Home> selfirstline
2533 bindkey <End> sellastline
2534 bind . <Key-Up> "selnextline -1"
2535 bind . <Key-Down> "selnextline 1"
2536 bind . <Shift-Key-Up> "dofind -1 0"
2537 bind . <Shift-Key-Down> "dofind 1 0"
2538 bindkey <Key-Right> "goforw"
2539 bindkey <Key-Left> "goback"
2540 bind . <Key-Prior> "selnextpage -1"
2541 bind . <Key-Next> "selnextpage 1"
2542 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2543 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2544 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2545 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2546 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2547 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2548 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2549 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2550 bindkey <Key-space> "$ctext yview scroll 1 pages"
2551 bindkey p "selnextline -1"
2552 bindkey n "selnextline 1"
2555 bindkey k "selnextline -1"
2556 bindkey j "selnextline 1"
2560 bindkey d "$ctext yview scroll 18 units"
2561 bindkey u "$ctext yview scroll -18 units"
2562 bindkey / {focus $fstring}
2563 bindkey <Key-KP_Divide> {focus $fstring}
2564 bindkey <Key-Return> {dofind 1 1}
2565 bindkey ? {dofind -1 1}
2567 bind . <F5> updatecommits
2568 bindmodfunctionkey Shift 5 reloadcommits
2569 bind . <F2> showrefs
2570 bindmodfunctionkey Shift 4 {newview 0}
2571 bind . <F4> edit_or_newview
2572 bind . <$M1B-q> doquit
2573 bind . <$M1B-f> {dofind 1 1}
2574 bind . <$M1B-g> {dofind 1 0}
2575 bind . <$M1B-r> dosearchback
2576 bind . <$M1B-s> dosearch
2577 bind . <$M1B-equal> {incrfont 1}
2578 bind . <$M1B-plus> {incrfont 1}
2579 bind . <$M1B-KP_Add> {incrfont 1}
2580 bind . <$M1B-minus> {incrfont -1}
2581 bind . <$M1B-KP_Subtract> {incrfont -1}
2582 wm protocol . WM_DELETE_WINDOW doquit
2583 bind . <Destroy> {stop_backends}
2584 bind . <Button-1> "click %W"
2585 bind $fstring <Key-Return> {dofind 1 1}
2586 bind $sha1entry <Key-Return> {gotocommit; break}
2587 bind $sha1entry <<PasteSelection>> clearsha1
2588 bind $sha1entry <<Paste>> clearsha1
2589 bind $cflist <1> {sel_flist %W %x %y; break}
2590 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2591 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2593 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2594 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2595 bind $ctext <Button-1> {focus %W}
2596 bind $ctext <<Selection>> rehighlight_search_results
2598 set maincursor [. cget -cursor]
2599 set textcursor [$ctext cget -cursor]
2600 set curtextcursor $textcursor
2602 set rowctxmenu .rowctxmenu
2603 makemenu $rowctxmenu {
2604 {mc "Diff this -> selected" command {diffvssel 0}}
2605 {mc "Diff selected -> this" command {diffvssel 1}}
2606 {mc "Make patch" command mkpatch}
2607 {mc "Create tag" command mktag}
2608 {mc "Write commit to file" command writecommit}
2609 {mc "Create new branch" command mkbranch}
2610 {mc "Cherry-pick this commit" command cherrypick}
2611 {mc "Reset HEAD branch to here" command resethead}
2612 {mc "Mark this commit" command markhere}
2613 {mc "Return to mark" command gotomark}
2614 {mc "Find descendant of this and mark" command find_common_desc}
2615 {mc "Compare with marked commit" command compare_commits}
2616 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2617 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2618 {mc "Revert this commit" command revert}
2620 $rowctxmenu configure -tearoff 0
2622 set fakerowmenu .fakerowmenu
2623 makemenu $fakerowmenu {
2624 {mc "Diff this -> selected" command {diffvssel 0}}
2625 {mc "Diff selected -> this" command {diffvssel 1}}
2626 {mc "Make patch" command mkpatch}
2627 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2628 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2630 $fakerowmenu configure -tearoff 0
2632 set headctxmenu .headctxmenu
2633 makemenu $headctxmenu {
2634 {mc "Check out this branch" command cobranch}
2635 {mc "Remove this branch" command rmbranch}
2637 $headctxmenu configure -tearoff 0
2640 set flist_menu .flistctxmenu
2641 makemenu $flist_menu {
2642 {mc "Highlight this too" command {flist_hl 0}}
2643 {mc "Highlight this only" command {flist_hl 1}}
2644 {mc "External diff" command {external_diff}}
2645 {mc "Blame parent commit" command {external_blame 1}}
2647 $flist_menu configure -tearoff 0
2650 set diff_menu .diffctxmenu
2651 makemenu $diff_menu {
2652 {mc "Show origin of this line" command show_line_source}
2653 {mc "Run git gui blame on this line" command {external_blame_diff}}
2655 $diff_menu configure -tearoff 0
2658 # Windows sends all mouse wheel events to the current focused window, not
2659 # the one where the mouse hovers, so bind those events here and redirect
2660 # to the correct window
2661 proc windows_mousewheel_redirector {W X Y D} {
2662 global canv canv2 canv3
2663 set w [winfo containing -displayof $W $X $Y]
2665 set u [expr {$D < 0 ? 5 : -5}]
2666 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2667 allcanvs yview scroll $u units
2670 $w yview scroll $u units
2676 # Update row number label when selectedline changes
2677 proc selectedline_change {n1 n2 op} {
2678 global selectedline rownumsel
2680 if {$selectedline eq {}} {
2683 set rownumsel [expr {$selectedline + 1}]
2687 # mouse-2 makes all windows scan vertically, but only the one
2688 # the cursor is in scans horizontally
2689 proc canvscan {op w x y} {
2690 global canv canv2 canv3
2691 foreach c [list $canv $canv2 $canv3] {
2700 proc scrollcanv {cscroll f0 f1} {
2701 $cscroll set $f0 $f1
2706 # when we make a key binding for the toplevel, make sure
2707 # it doesn't get triggered when that key is pressed in the
2708 # find string entry widget.
2709 proc bindkey {ev script} {
2712 set escript [bind Entry $ev]
2713 if {$escript == {}} {
2714 set escript [bind Entry <Key>]
2716 foreach e $entries {
2717 bind $e $ev "$escript; break"
2721 proc bindmodfunctionkey {mod n script} {
2722 bind . <$mod-F$n> $script
2723 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2726 # set the focus back to the toplevel for any click outside
2729 global ctext entries
2730 foreach e [concat $entries $ctext] {
2731 if {$w == $e} return
2736 # Adjust the progress bar for a change in requested extent or canvas size
2737 proc adjustprogress {} {
2738 global progresscanv progressitem progresscoords
2739 global fprogitem fprogcoord lastprogupdate progupdatepending
2740 global rprogitem rprogcoord use_ttk
2743 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2747 set w [expr {[winfo width $progresscanv] - 4}]
2748 set x0 [expr {$w * [lindex $progresscoords 0]}]
2749 set x1 [expr {$w * [lindex $progresscoords 1]}]
2750 set h [winfo height $progresscanv]
2751 $progresscanv coords $progressitem $x0 0 $x1 $h
2752 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2753 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2754 set now [clock clicks -milliseconds]
2755 if {$now >= $lastprogupdate + 100} {
2756 set progupdatepending 0
2758 } elseif {!$progupdatepending} {
2759 set progupdatepending 1
2760 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2764 proc doprogupdate {} {
2765 global lastprogupdate progupdatepending
2767 if {$progupdatepending} {
2768 set progupdatepending 0
2769 set lastprogupdate [clock clicks -milliseconds]
2774 proc savestuff {w} {
2775 global canv canv2 canv3 mainfont textfont uifont tabstop
2776 global stuffsaved findmergefiles maxgraphpct
2777 global maxwidth showneartags showlocalchanges
2778 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2779 global cmitmode wrapcomment datetimeformat limitdiffs
2780 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2781 global uifgcolor uifgdisabledcolor
2782 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2783 global tagbgcolor tagfgcolor tagoutlinecolor
2784 global reflinecolor filesepbgcolor filesepfgcolor
2785 global mergecolors foundbgcolor currentsearchhitbgcolor
2786 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2787 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2788 global linkfgcolor circleoutlinecolor
2789 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2790 global hideremotes want_ttk maxrefs
2791 global config_file config_file_tmp
2793 if {$stuffsaved} return
2794 if {![winfo viewable .]} return
2796 if {[file exists $config_file_tmp]} {
2797 file delete -force $config_file_tmp
2799 set f [open $config_file_tmp w]
2800 if {$::tcl_platform(platform) eq {windows}} {
2801 file attributes $config_file_tmp -hidden true
2803 puts $f [list set mainfont $mainfont]
2804 puts $f [list set textfont $textfont]
2805 puts $f [list set uifont $uifont]
2806 puts $f [list set tabstop $tabstop]
2807 puts $f [list set findmergefiles $findmergefiles]
2808 puts $f [list set maxgraphpct $maxgraphpct]
2809 puts $f [list set maxwidth $maxwidth]
2810 puts $f [list set cmitmode $cmitmode]
2811 puts $f [list set wrapcomment $wrapcomment]
2812 puts $f [list set autoselect $autoselect]
2813 puts $f [list set autosellen $autosellen]
2814 puts $f [list set showneartags $showneartags]
2815 puts $f [list set maxrefs $maxrefs]
2816 puts $f [list set hideremotes $hideremotes]
2817 puts $f [list set showlocalchanges $showlocalchanges]
2818 puts $f [list set datetimeformat $datetimeformat]
2819 puts $f [list set limitdiffs $limitdiffs]
2820 puts $f [list set uicolor $uicolor]
2821 puts $f [list set want_ttk $want_ttk]
2822 puts $f [list set bgcolor $bgcolor]
2823 puts $f [list set fgcolor $fgcolor]
2824 puts $f [list set uifgcolor $uifgcolor]
2825 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2826 puts $f [list set colors $colors]
2827 puts $f [list set diffcolors $diffcolors]
2828 puts $f [list set mergecolors $mergecolors]
2829 puts $f [list set markbgcolor $markbgcolor]
2830 puts $f [list set diffcontext $diffcontext]
2831 puts $f [list set selectbgcolor $selectbgcolor]
2832 puts $f [list set foundbgcolor $foundbgcolor]
2833 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2834 puts $f [list set extdifftool $extdifftool]
2835 puts $f [list set perfile_attrs $perfile_attrs]
2836 puts $f [list set headbgcolor $headbgcolor]
2837 puts $f [list set headfgcolor $headfgcolor]
2838 puts $f [list set headoutlinecolor $headoutlinecolor]
2839 puts $f [list set remotebgcolor $remotebgcolor]
2840 puts $f [list set tagbgcolor $tagbgcolor]
2841 puts $f [list set tagfgcolor $tagfgcolor]
2842 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2843 puts $f [list set reflinecolor $reflinecolor]
2844 puts $f [list set filesepbgcolor $filesepbgcolor]
2845 puts $f [list set filesepfgcolor $filesepfgcolor]
2846 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2847 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2848 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2849 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2850 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2851 puts $f [list set indexcirclecolor $indexcirclecolor]
2852 puts $f [list set circlecolors $circlecolors]
2853 puts $f [list set linkfgcolor $linkfgcolor]
2854 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2856 puts $f "set geometry(main) [wm geometry .]"
2857 puts $f "set geometry(state) [wm state .]"
2858 puts $f "set geometry(topwidth) [winfo width .tf]"
2859 puts $f "set geometry(topheight) [winfo height .tf]"
2861 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2862 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2864 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2865 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2867 puts $f "set geometry(botwidth) [winfo width .bleft]"
2868 puts $f "set geometry(botheight) [winfo height .bleft]"
2870 puts -nonewline $f "set permviews {"
2871 for {set v 0} {$v < $nextviewnum} {incr v} {
2872 if {$viewperm($v)} {
2873 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2878 file rename -force $config_file_tmp $config_file
2883 proc resizeclistpanes {win w} {
2884 global oldwidth use_ttk
2885 if {[info exists oldwidth($win)]} {
2887 set s0 [$win sashpos 0]
2888 set s1 [$win sashpos 1]
2890 set s0 [$win sash coord 0]
2891 set s1 [$win sash coord 1]
2894 set sash0 [expr {int($w/2 - 2)}]
2895 set sash1 [expr {int($w*5/6 - 2)}]
2897 set factor [expr {1.0 * $w / $oldwidth($win)}]
2898 set sash0 [expr {int($factor * [lindex $s0 0])}]
2899 set sash1 [expr {int($factor * [lindex $s1 0])}]
2903 if {$sash1 < $sash0 + 20} {
2904 set sash1 [expr {$sash0 + 20}]
2906 if {$sash1 > $w - 10} {
2907 set sash1 [expr {$w - 10}]
2908 if {$sash0 > $sash1 - 20} {
2909 set sash0 [expr {$sash1 - 20}]
2914 $win sashpos 0 $sash0
2915 $win sashpos 1 $sash1
2917 $win sash place 0 $sash0 [lindex $s0 1]
2918 $win sash place 1 $sash1 [lindex $s1 1]
2921 set oldwidth($win) $w
2924 proc resizecdetpanes {win w} {
2925 global oldwidth use_ttk
2926 if {[info exists oldwidth($win)]} {
2928 set s0 [$win sashpos 0]
2930 set s0 [$win sash coord 0]
2933 set sash0 [expr {int($w*3/4 - 2)}]
2935 set factor [expr {1.0 * $w / $oldwidth($win)}]
2936 set sash0 [expr {int($factor * [lindex $s0 0])}]
2940 if {$sash0 > $w - 15} {
2941 set sash0 [expr {$w - 15}]
2945 $win sashpos 0 $sash0
2947 $win sash place 0 $sash0 [lindex $s0 1]
2950 set oldwidth($win) $w
2953 proc allcanvs args {
2954 global canv canv2 canv3
2960 proc bindall {event action} {
2961 global canv canv2 canv3
2962 bind $canv $event $action
2963 bind $canv2 $event $action
2964 bind $canv3 $event $action
2970 if {[winfo exists $w]} {
2975 wm title $w [mc "About gitk"]
2977 message $w.m -text [mc "
2978 Gitk - a commit viewer for git
2980 Copyright \u00a9 2005-2014 Paul Mackerras
2982 Use and redistribute under the terms of the GNU General Public License"] \
2983 -justify center -aspect 400 -border 2 -bg white -relief groove
2984 pack $w.m -side top -fill x -padx 2 -pady 2
2985 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2986 pack $w.ok -side bottom
2987 bind $w <Visibility> "focus $w.ok"
2988 bind $w <Key-Escape> "destroy $w"
2989 bind $w <Key-Return> "destroy $w"
2990 tk::PlaceWindow $w widget .
2996 if {[winfo exists $w]} {
3000 if {[tk windowingsystem] eq {aqua}} {
3006 wm title $w [mc "Gitk key bindings"]
3008 message $w.m -text "
3009 [mc "Gitk key bindings:"]
3011 [mc "<%s-Q> Quit" $M1T]
3012 [mc "<%s-W> Close window" $M1T]
3013 [mc "<Home> Move to first commit"]
3014 [mc "<End> Move to last commit"]
3015 [mc "<Up>, p, k Move up one commit"]
3016 [mc "<Down>, n, j Move down one commit"]
3017 [mc "<Left>, z, h Go back in history list"]
3018 [mc "<Right>, x, l Go forward in history list"]
3019 [mc "<PageUp> Move up one page in commit list"]
3020 [mc "<PageDown> Move down one page in commit list"]
3021 [mc "<%s-Home> Scroll to top of commit list" $M1T]
3022 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
3023 [mc "<%s-Up> Scroll commit list up one line" $M1T]
3024 [mc "<%s-Down> Scroll commit list down one line" $M1T]
3025 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
3026 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
3027 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
3028 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
3029 [mc "<Delete>, b Scroll diff view up one page"]
3030 [mc "<Backspace> Scroll diff view up one page"]
3031 [mc "<Space> Scroll diff view down one page"]
3032 [mc "u Scroll diff view up 18 lines"]
3033 [mc "d Scroll diff view down 18 lines"]
3034 [mc "<%s-F> Find" $M1T]
3035 [mc "<%s-G> Move to next find hit" $M1T]
3036 [mc "<Return> Move to next find hit"]
3037 [mc "/ Focus the search box"]
3038 [mc "? Move to previous find hit"]
3039 [mc "f Scroll diff view to next file"]
3040 [mc "<%s-S> Search for next hit in diff view" $M1T]
3041 [mc "<%s-R> Search for previous hit in diff view" $M1T]
3042 [mc "<%s-KP+> Increase font size" $M1T]
3043 [mc "<%s-plus> Increase font size" $M1T]
3044 [mc "<%s-KP-> Decrease font size" $M1T]
3045 [mc "<%s-minus> Decrease font size" $M1T]
3048 -justify left -bg white -border 2 -relief groove
3049 pack $w.m -side top -fill both -padx 2 -pady 2
3050 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3051 bind $w <Key-Escape> [list destroy $w]
3052 pack $w.ok -side bottom
3053 bind $w <Visibility> "focus $w.ok"
3054 bind $w <Key-Escape> "destroy $w"
3055 bind $w <Key-Return> "destroy $w"
3058 # Procedures for manipulating the file list window at the
3059 # bottom right of the overall window.
3061 proc treeview {w l openlevs} {
3062 global treecontents treediropen treeheight treeparent treeindex
3072 set treecontents() {}
3073 $w conf -state normal
3075 while {[string range $f 0 $prefixend] ne $prefix} {
3076 if {$lev <= $openlevs} {
3077 $w mark set e:$treeindex($prefix) "end -1c"
3078 $w mark gravity e:$treeindex($prefix) left
3080 set treeheight($prefix) $ht
3081 incr ht [lindex $htstack end]
3082 set htstack [lreplace $htstack end end]
3083 set prefixend [lindex $prefendstack end]
3084 set prefendstack [lreplace $prefendstack end end]
3085 set prefix [string range $prefix 0 $prefixend]
3088 set tail [string range $f [expr {$prefixend+1}] end]
3089 while {[set slash [string first "/" $tail]] >= 0} {
3092 lappend prefendstack $prefixend
3093 incr prefixend [expr {$slash + 1}]
3094 set d [string range $tail 0 $slash]
3095 lappend treecontents($prefix) $d
3096 set oldprefix $prefix
3098 set treecontents($prefix) {}
3099 set treeindex($prefix) [incr ix]
3100 set treeparent($prefix) $oldprefix
3101 set tail [string range $tail [expr {$slash+1}] end]
3102 if {$lev <= $openlevs} {
3104 set treediropen($prefix) [expr {$lev < $openlevs}]
3105 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3106 $w mark set d:$ix "end -1c"
3107 $w mark gravity d:$ix left
3109 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3111 $w image create end -align center -image $bm -padx 1 \
3113 $w insert end $d [highlight_tag $prefix]
3114 $w mark set s:$ix "end -1c"
3115 $w mark gravity s:$ix left
3120 if {$lev <= $openlevs} {
3123 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3125 $w insert end $tail [highlight_tag $f]
3127 lappend treecontents($prefix) $tail
3130 while {$htstack ne {}} {
3131 set treeheight($prefix) $ht
3132 incr ht [lindex $htstack end]
3133 set htstack [lreplace $htstack end end]
3134 set prefixend [lindex $prefendstack end]
3135 set prefendstack [lreplace $prefendstack end end]
3136 set prefix [string range $prefix 0 $prefixend]
3138 $w conf -state disabled
3141 proc linetoelt {l} {
3142 global treeheight treecontents
3147 foreach e $treecontents($prefix) {
3152 if {[string index $e end] eq "/"} {
3153 set n $treeheight($prefix$e)
3165 proc highlight_tree {y prefix} {
3166 global treeheight treecontents cflist
3168 foreach e $treecontents($prefix) {
3170 if {[highlight_tag $path] ne {}} {
3171 $cflist tag add bold $y.0 "$y.0 lineend"
3174 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3175 set y [highlight_tree $y $path]
3181 proc treeclosedir {w dir} {
3182 global treediropen treeheight treeparent treeindex
3184 set ix $treeindex($dir)
3185 $w conf -state normal
3186 $w delete s:$ix e:$ix
3187 set treediropen($dir) 0
3188 $w image configure a:$ix -image tri-rt
3189 $w conf -state disabled
3190 set n [expr {1 - $treeheight($dir)}]
3191 while {$dir ne {}} {
3192 incr treeheight($dir) $n
3193 set dir $treeparent($dir)
3197 proc treeopendir {w dir} {
3198 global treediropen treeheight treeparent treecontents treeindex
3200 set ix $treeindex($dir)
3201 $w conf -state normal
3202 $w image configure a:$ix -image tri-dn
3203 $w mark set e:$ix s:$ix
3204 $w mark gravity e:$ix right
3207 set n [llength $treecontents($dir)]
3208 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3211 incr treeheight($x) $n
3213 foreach e $treecontents($dir) {
3215 if {[string index $e end] eq "/"} {
3216 set iy $treeindex($de)
3217 $w mark set d:$iy e:$ix
3218 $w mark gravity d:$iy left
3219 $w insert e:$ix $str
3220 set treediropen($de) 0
3221 $w image create e:$ix -align center -image tri-rt -padx 1 \
3223 $w insert e:$ix $e [highlight_tag $de]
3224 $w mark set s:$iy e:$ix
3225 $w mark gravity s:$iy left
3226 set treeheight($de) 1
3228 $w insert e:$ix $str
3229 $w insert e:$ix $e [highlight_tag $de]
3232 $w mark gravity e:$ix right
3233 $w conf -state disabled
3234 set treediropen($dir) 1
3235 set top [lindex [split [$w index @0,0] .] 0]
3236 set ht [$w cget -height]
3237 set l [lindex [split [$w index s:$ix] .] 0]
3240 } elseif {$l + $n + 1 > $top + $ht} {
3241 set top [expr {$l + $n + 2 - $ht}]
3249 proc treeclick {w x y} {
3250 global treediropen cmitmode ctext cflist cflist_top
3252 if {$cmitmode ne "tree"} return
3253 if {![info exists cflist_top]} return
3254 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3255 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3256 $cflist tag add highlight $l.0 "$l.0 lineend"
3262 set e [linetoelt $l]
3263 if {[string index $e end] ne "/"} {
3265 } elseif {$treediropen($e)} {
3272 proc setfilelist {id} {
3273 global treefilelist cflist jump_to_here
3275 treeview $cflist $treefilelist($id) 0
3276 if {$jump_to_here ne {}} {
3277 set f [lindex $jump_to_here 0]
3278 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3284 image create bitmap tri-rt -background black -foreground blue -data {
3285 #define tri-rt_width 13
3286 #define tri-rt_height 13
3287 static unsigned char tri-rt_bits[] = {
3288 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3289 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3292 #define tri-rt-mask_width 13
3293 #define tri-rt-mask_height 13
3294 static unsigned char tri-rt-mask_bits[] = {
3295 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3296 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3299 image create bitmap tri-dn -background black -foreground blue -data {
3300 #define tri-dn_width 13
3301 #define tri-dn_height 13
3302 static unsigned char tri-dn_bits[] = {
3303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3304 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3307 #define tri-dn-mask_width 13
3308 #define tri-dn-mask_height 13
3309 static unsigned char tri-dn-mask_bits[] = {
3310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3311 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3315 image create bitmap reficon-T -background black -foreground yellow -data {
3316 #define tagicon_width 13
3317 #define tagicon_height 9
3318 static unsigned char tagicon_bits[] = {
3319 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3320 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3322 #define tagicon-mask_width 13
3323 #define tagicon-mask_height 9
3324 static unsigned char tagicon-mask_bits[] = {
3325 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3326 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3329 #define headicon_width 13
3330 #define headicon_height 9
3331 static unsigned char headicon_bits[] = {
3332 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3333 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3336 #define headicon-mask_width 13
3337 #define headicon-mask_height 9
3338 static unsigned char headicon-mask_bits[] = {
3339 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3340 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3342 image create bitmap reficon-H -background black -foreground green \
3343 -data $rectdata -maskdata $rectmask
3344 image create bitmap reficon-o -background black -foreground "#ddddff" \
3345 -data $rectdata -maskdata $rectmask
3347 proc init_flist {first} {
3348 global cflist cflist_top difffilestart
3350 $cflist conf -state normal
3351 $cflist delete 0.0 end
3353 $cflist insert end $first
3355 $cflist tag add highlight 1.0 "1.0 lineend"
3357 catch {unset cflist_top}
3359 $cflist conf -state disabled
3360 set difffilestart {}
3363 proc highlight_tag {f} {
3364 global highlight_paths
3366 foreach p $highlight_paths {
3367 if {[string match $p $f]} {
3374 proc highlight_filelist {} {
3375 global cmitmode cflist
3377 $cflist conf -state normal
3378 if {$cmitmode ne "tree"} {
3379 set end [lindex [split [$cflist index end] .] 0]
3380 for {set l 2} {$l < $end} {incr l} {
3381 set line [$cflist get $l.0 "$l.0 lineend"]
3382 if {[highlight_tag $line] ne {}} {
3383 $cflist tag add bold $l.0 "$l.0 lineend"
3389 $cflist conf -state disabled
3392 proc unhighlight_filelist {} {
3395 $cflist conf -state normal
3396 $cflist tag remove bold 1.0 end
3397 $cflist conf -state disabled
3400 proc add_flist {fl} {
3403 $cflist conf -state normal
3405 $cflist insert end "\n"
3406 $cflist insert end $f [highlight_tag $f]
3408 $cflist conf -state disabled
3411 proc sel_flist {w x y} {
3412 global ctext difffilestart cflist cflist_top cmitmode
3414 if {$cmitmode eq "tree"} return
3415 if {![info exists cflist_top]} return
3416 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3417 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3418 $cflist tag add highlight $l.0 "$l.0 lineend"
3423 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3425 suppress_highlighting_file_for_current_scrollpos
3428 proc pop_flist_menu {w X Y x y} {
3429 global ctext cflist cmitmode flist_menu flist_menu_file
3430 global treediffs diffids
3433 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3435 if {$cmitmode eq "tree"} {
3436 set e [linetoelt $l]
3437 if {[string index $e end] eq "/"} return
3439 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3441 set flist_menu_file $e
3442 set xdiffstate "normal"
3443 if {$cmitmode eq "tree"} {
3444 set xdiffstate "disabled"
3446 # Disable "External diff" item in tree mode
3447 $flist_menu entryconf 2 -state $xdiffstate
3448 tk_popup $flist_menu $X $Y
3451 proc find_ctext_fileinfo {line} {
3452 global ctext_file_names ctext_file_lines
3454 set ok [bsearch $ctext_file_lines $line]
3455 set tline [lindex $ctext_file_lines $ok]
3457 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3460 return [list [lindex $ctext_file_names $ok] $tline]
3464 proc pop_diff_menu {w X Y x y} {
3465 global ctext diff_menu flist_menu_file
3466 global diff_menu_txtpos diff_menu_line
3467 global diff_menu_filebase
3469 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3470 set diff_menu_line [lindex $diff_menu_txtpos 0]
3471 # don't pop up the menu on hunk-separator or file-separator lines
3472 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3476 set f [find_ctext_fileinfo $diff_menu_line]
3477 if {$f eq {}} return
3478 set flist_menu_file [lindex $f 0]
3479 set diff_menu_filebase [lindex $f 1]
3480 tk_popup $diff_menu $X $Y
3483 proc flist_hl {only} {
3484 global flist_menu_file findstring gdttype
3486 set x [shellquote $flist_menu_file]
3487 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3490 append findstring " " $x
3492 set gdttype [mc "touching paths:"]
3495 proc gitknewtmpdir {} {
3496 global diffnum gitktmpdir gitdir
3498 if {![info exists gitktmpdir]} {
3499 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3500 if {[catch {file mkdir $gitktmpdir} err]} {
3501 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3508 set diffdir [file join $gitktmpdir $diffnum]
3509 if {[catch {file mkdir $diffdir} err]} {
3510 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3516 proc save_file_from_commit {filename output what} {
3519 if {[catch {exec git show $filename -- > $output} err]} {
3520 if {[string match "fatal: bad revision *" $err]} {
3523 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3529 proc external_diff_get_one_file {diffid filename diffdir} {
3530 global nullid nullid2 nullfile
3533 if {$diffid == $nullid} {
3534 set difffile [file join $worktree $filename]
3535 if {[file exists $difffile]} {
3540 if {$diffid == $nullid2} {
3541 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3542 return [save_file_from_commit :$filename $difffile index]
3544 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3545 return [save_file_from_commit $diffid:$filename $difffile \
3549 proc external_diff {} {
3550 global nullid nullid2
3551 global flist_menu_file
3555 if {[llength $diffids] == 1} {
3556 # no reference commit given
3557 set diffidto [lindex $diffids 0]
3558 if {$diffidto eq $nullid} {
3559 # diffing working copy with index
3560 set diffidfrom $nullid2
3561 } elseif {$diffidto eq $nullid2} {
3562 # diffing index with HEAD
3563 set diffidfrom "HEAD"
3565 # use first parent commit
3566 global parentlist selectedline
3567 set diffidfrom [lindex $parentlist $selectedline 0]
3570 set diffidfrom [lindex $diffids 0]
3571 set diffidto [lindex $diffids 1]
3574 # make sure that several diffs wont collide
3575 set diffdir [gitknewtmpdir]
3576 if {$diffdir eq {}} return
3578 # gather files to diff
3579 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3580 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3582 if {$difffromfile ne {} && $difftofile ne {}} {
3583 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3584 if {[catch {set fl [open |$cmd r]} err]} {
3585 file delete -force $diffdir
3586 error_popup "$extdifftool: [mc "command failed:"] $err"
3588 fconfigure $fl -blocking 0
3589 filerun $fl [list delete_at_eof $fl $diffdir]
3594 proc find_hunk_blamespec {base line} {
3597 # Find and parse the hunk header
3598 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3599 if {$s_lix eq {}} return
3601 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3602 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3603 s_line old_specs osz osz1 new_line nsz]} {
3607 # base lines for the parents
3608 set base_lines [list $new_line]
3609 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3610 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3611 old_spec old_line osz]} {
3614 lappend base_lines $old_line
3617 # Now scan the lines to determine offset within the hunk
3618 set max_parent [expr {[llength $base_lines]-2}]
3620 set s_lno [lindex [split $s_lix "."] 0]
3622 # Determine if the line is removed
3623 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3624 if {[string match {[-+ ]*} $chunk]} {
3625 set removed_idx [string first "-" $chunk]
3626 # Choose a parent index
3627 if {$removed_idx >= 0} {
3628 set parent $removed_idx
3630 set unchanged_idx [string first " " $chunk]
3631 if {$unchanged_idx >= 0} {
3632 set parent $unchanged_idx
3634 # blame the current commit
3638 # then count other lines that belong to it
3639 for {set i $line} {[incr i -1] > $s_lno} {} {
3640 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3641 # Determine if the line is removed
3642 set removed_idx [string first "-" $chunk]
3644 set code [string index $chunk $parent]
3645 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3649 if {$removed_idx < 0} {
3659 incr dline [lindex $base_lines $parent]
3660 return [list $parent $dline]
3663 proc external_blame_diff {} {
3664 global currentid cmitmode
3665 global diff_menu_txtpos diff_menu_line
3666 global diff_menu_filebase flist_menu_file
3668 if {$cmitmode eq "tree"} {
3670 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3672 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3674 set parent_idx [lindex $hinfo 0]
3675 set line [lindex $hinfo 1]
3682 external_blame $parent_idx $line
3685 # Find the SHA1 ID of the blob for file $fname in the index
3687 proc index_sha1 {fname} {
3688 set f [open [list | git ls-files -s $fname] r]
3689 while {[gets $f line] >= 0} {
3690 set info [lindex [split $line "\t"] 0]
3691 set stage [lindex $info 2]
3692 if {$stage eq "0" || $stage eq "2"} {
3694 return [lindex $info 1]
3701 # Turn an absolute path into one relative to the current directory
3702 proc make_relative {f} {
3703 if {[file pathtype $f] eq "relative"} {
3706 set elts [file split $f]
3707 set here [file split [pwd]]
3712 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3719 set elts [concat $res [lrange $elts $ei end]]
3720 return [eval file join $elts]
3723 proc external_blame {parent_idx {line {}}} {
3724 global flist_menu_file cdup
3725 global nullid nullid2
3726 global parentlist selectedline currentid
3728 if {$parent_idx > 0} {
3729 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3731 set base_commit $currentid
3734 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3735 error_popup [mc "No such commit"]
3739 set cmdline [list git gui blame]
3740 if {$line ne {} && $line > 1} {
3741 lappend cmdline "--line=$line"
3743 set f [file join $cdup $flist_menu_file]
3744 # Unfortunately it seems git gui blame doesn't like
3745 # being given an absolute path...
3746 set f [make_relative $f]
3747 lappend cmdline $base_commit $f
3748 if {[catch {eval exec $cmdline &} err]} {
3749 error_popup "[mc "git gui blame: command failed:"] $err"
3753 proc show_line_source {} {
3754 global cmitmode currentid parents curview blamestuff blameinst
3755 global diff_menu_line diff_menu_filebase flist_menu_file
3756 global nullid nullid2 gitdir cdup
3759 if {$cmitmode eq "tree"} {
3761 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3763 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3764 if {$h eq {}} return
3765 set pi [lindex $h 0]
3767 mark_ctext_line $diff_menu_line
3771 if {$currentid eq $nullid} {
3773 # must be a merge in progress...
3775 # get the last line from .git/MERGE_HEAD
3776 set f [open [file join $gitdir MERGE_HEAD] r]
3777 set id [lindex [split [read $f] "\n"] end-1]
3780 error_popup [mc "Couldn't read merge head: %s" $err]
3783 } elseif {$parents($curview,$currentid) eq $nullid2} {
3784 # need to do the blame from the index
3786 set from_index [index_sha1 $flist_menu_file]
3788 error_popup [mc "Error reading index: %s" $err]
3792 set id $parents($curview,$currentid)
3795 set id [lindex $parents($curview,$currentid) $pi]
3797 set line [lindex $h 1]
3800 if {$from_index ne {}} {
3801 lappend blameargs | git cat-file blob $from_index
3803 lappend blameargs | git blame -p -L$line,+1
3804 if {$from_index ne {}} {
3805 lappend blameargs --contents -
3807 lappend blameargs $id
3809 lappend blameargs -- [file join $cdup $flist_menu_file]
3811 set f [open $blameargs r]
3813 error_popup [mc "Couldn't start git blame: %s" $err]
3816 nowbusy blaming [mc "Searching"]
3817 fconfigure $f -blocking 0
3818 set i [reg_instance $f]
3819 set blamestuff($i) {}
3821 filerun $f [list read_line_source $f $i]
3824 proc stopblaming {} {
3827 if {[info exists blameinst]} {
3828 stop_instance $blameinst
3834 proc read_line_source {fd inst} {
3835 global blamestuff curview commfd blameinst nullid nullid2
3837 while {[gets $fd line] >= 0} {
3838 lappend blamestuff($inst) $line
3846 fconfigure $fd -blocking 1
3847 if {[catch {close $fd} err]} {
3848 error_popup [mc "Error running git blame: %s" $err]
3853 set line [split [lindex $blamestuff($inst) 0] " "]
3854 set id [lindex $line 0]
3855 set lnum [lindex $line 1]
3856 if {[string length $id] == 40 && [string is xdigit $id] &&
3857 [string is digit -strict $lnum]} {
3858 # look for "filename" line
3859 foreach l $blamestuff($inst) {
3860 if {[string match "filename *" $l]} {
3861 set fname [string range $l 9 end]
3867 # all looks good, select it
3868 if {$id eq $nullid} {
3869 # blame uses all-zeroes to mean not committed,
3870 # which would mean a change in the index
3873 if {[commitinview $id $curview]} {
3874 selectline [rowofcommit $id] 1 [list $fname $lnum]
3876 error_popup [mc "That line comes from commit %s, \
3877 which is not in this view" [shortids $id]]
3880 puts "oops couldn't parse git blame output"
3885 # delete $dir when we see eof on $f (presumably because the child has exited)
3886 proc delete_at_eof {f dir} {
3887 while {[gets $f line] >= 0} {}
3889 if {[catch {close $f} err]} {
3890 error_popup "[mc "External diff viewer failed:"] $err"
3892 file delete -force $dir
3898 # Functions for adding and removing shell-type quoting
3900 proc shellquote {str} {
3901 if {![string match "*\['\"\\ \t]*" $str]} {
3904 if {![string match "*\['\"\\]*" $str]} {
3907 if {![string match "*'*" $str]} {
3910 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3913 proc shellarglist {l} {
3919 append str [shellquote $a]
3924 proc shelldequote {str} {
3929 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3930 append ret [string range $str $used end]
3931 set used [string length $str]
3934 set first [lindex $first 0]
3935 set ch [string index $str $first]
3936 if {$first > $used} {
3937 append ret [string range $str $used [expr {$first - 1}]]
3940 if {$ch eq " " || $ch eq "\t"} break
3943 set first [string first "'" $str $used]
3945 error "unmatched single-quote"
3947 append ret [string range $str $used [expr {$first - 1}]]
3952 if {$used >= [string length $str]} {
3953 error "trailing backslash"
3955 append ret [string index $str $used]
3960 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3961 error "unmatched double-quote"
3963 set first [lindex $first 0]
3964 set ch [string index $str $first]
3965 if {$first > $used} {
3966 append ret [string range $str $used [expr {$first - 1}]]
3969 if {$ch eq "\""} break
3971 append ret [string index $str $used]
3975 return [list $used $ret]
3978 proc shellsplit {str} {
3981 set str [string trimleft $str]
3982 if {$str eq {}} break
3983 set dq [shelldequote $str]
3984 set n [lindex $dq 0]
3985 set word [lindex $dq 1]
3986 set str [string range $str $n end]
3992 # Code to implement multiple views
3994 proc newview {ishighlight} {
3995 global nextviewnum newviewname newishighlight
3996 global revtreeargs viewargscmd newviewopts curview
3998 set newishighlight $ishighlight
4000 if {[winfo exists $top]} {
4004 decode_view_opts $nextviewnum $revtreeargs
4005 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
4006 set newviewopts($nextviewnum,perm) 0
4007 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
4008 vieweditor $top $nextviewnum [mc "Gitk view definition"]
4011 set known_view_options {
4012 {perm b . {} {mc "Remember this view"}}
4013 {reflabel l + {} {mc "References (space separated list):"}}
4014 {refs t15 .. {} {mc "Branches & tags:"}}
4015 {allrefs b *. "--all" {mc "All refs"}}
4016 {branches b . "--branches" {mc "All (local) branches"}}
4017 {tags b . "--tags" {mc "All tags"}}
4018 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
4019 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
4020 {author t15 .. "--author=*" {mc "Author:"}}
4021 {committer t15 . "--committer=*" {mc "Committer:"}}
4022 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
4023 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
4024 {changes_l l + {} {mc "Changes to Files:"}}
4025 {pickaxe_s r0 . {} {mc "Fixed String"}}
4026 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
4027 {pickaxe t15 .. "-S*" {mc "Search string:"}}
4028 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
4029 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
4030 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
4031 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
4032 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
4033 {skip t10 . "--skip=*" {mc "Number to skip:"}}
4034 {misc_lbl l + {} {mc "Miscellaneous options:"}}
4035 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
4036 {lright b . "--left-right" {mc "Mark branch sides"}}
4037 {first b . "--first-parent" {mc "Limit to first parent"}}
4038 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
4039 {args t50 *. {} {mc "Additional arguments to git log:"}}
4040 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4041 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4044 # Convert $newviewopts($n, ...) into args for git log.
4045 proc encode_view_opts {n} {
4046 global known_view_options newviewopts
4049 foreach opt $known_view_options {
4050 set patterns [lindex $opt 3]
4051 if {$patterns eq {}} continue
4052 set pattern [lindex $patterns 0]
4054 if {[lindex $opt 1] eq "b"} {
4055 set val $newviewopts($n,[lindex $opt 0])
4057 lappend rargs $pattern
4059 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4060 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4061 set val $newviewopts($n,$button_id)
4062 if {$val eq $value} {
4063 lappend rargs $pattern
4066 set val $newviewopts($n,[lindex $opt 0])
4067 set val [string trim $val]
4069 set pfix [string range $pattern 0 end-1]
4070 lappend rargs $pfix$val
4074 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4075 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4078 # Fill $newviewopts($n, ...) based on args for git log.
4079 proc decode_view_opts {n view_args} {
4080 global known_view_options newviewopts
4082 foreach opt $known_view_options {
4083 set id [lindex $opt 0]
4084 if {[lindex $opt 1] eq "b"} {
4087 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4089 regexp {^(.*_)} $id uselessvar id
4095 set newviewopts($n,$id) $val
4099 foreach arg $view_args {
4100 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4101 && ![info exists found(limit)]} {
4102 set newviewopts($n,limit) $cnt
4107 foreach opt $known_view_options {
4108 set id [lindex $opt 0]
4109 if {[info exists found($id)]} continue
4110 foreach pattern [lindex $opt 3] {
4111 if {![string match $pattern $arg]} continue
4112 if {[lindex $opt 1] eq "b"} {
4115 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4117 regexp {^(.*_)} $id uselessvar id
4121 set size [string length $pattern]
4122 set val [string range $arg [expr {$size-1}] end]
4124 set newviewopts($n,$id) $val
4128 if {[info exists val]} break
4130 if {[info exists val]} continue
4131 if {[regexp {^-} $arg]} {
4134 lappend refargs $arg
4137 set newviewopts($n,refs) [shellarglist $refargs]
4138 set newviewopts($n,args) [shellarglist $oargs]
4141 proc edit_or_newview {} {
4153 global viewname viewperm newviewname newviewopts
4154 global viewargs viewargscmd
4156 set top .gitkvedit-$curview
4157 if {[winfo exists $top]} {
4161 decode_view_opts $curview $viewargs($curview)
4162 set newviewname($curview) $viewname($curview)
4163 set newviewopts($curview,perm) $viewperm($curview)
4164 set newviewopts($curview,cmd) $viewargscmd($curview)
4165 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4168 proc vieweditor {top n title} {
4169 global newviewname newviewopts viewfiles bgcolor
4170 global known_view_options NS
4173 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4174 make_transient $top .
4177 ${NS}::frame $top.nfr
4178 ${NS}::label $top.nl -text [mc "View Name"]
4179 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4180 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4181 pack $top.nl -in $top.nfr -side left -padx {0 5}
4182 pack $top.name -in $top.nfr -side left -padx {0 25}
4188 foreach opt $known_view_options {
4189 set id [lindex $opt 0]
4190 set type [lindex $opt 1]
4191 set flags [lindex $opt 2]
4192 set title [eval [lindex $opt 4]]
4195 if {$flags eq "+" || $flags eq "*"} {
4196 set cframe $top.fr$cnt
4198 ${NS}::frame $cframe
4199 pack $cframe -in $top -fill x -pady 3 -padx 3
4200 set cexpand [expr {$flags eq "*"}]
4201 } elseif {$flags eq ".." || $flags eq "*."} {
4202 set cframe $top.fr$cnt
4204 ${NS}::frame $cframe
4205 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4206 set cexpand [expr {$flags eq "*."}]
4212 ${NS}::label $cframe.l_$id -text $title
4213 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4214 } elseif {$type eq "b"} {
4215 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4216 pack $cframe.c_$id -in $cframe -side left \
4217 -padx [list $lxpad 0] -expand $cexpand -anchor w
4218 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4219 regexp {^(.*_)} $id uselessvar button_id
4220 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4221 pack $cframe.c_$id -in $cframe -side left \
4222 -padx [list $lxpad 0] -expand $cexpand -anchor w
4223 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4224 ${NS}::label $cframe.l_$id -text $title
4225 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4226 -textvariable newviewopts($n,$id)
4227 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4228 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4229 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4230 ${NS}::label $cframe.l_$id -text $title
4231 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4232 -textvariable newviewopts($n,$id)
4233 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4234 pack $cframe.e_$id -in $cframe -side top -fill x
4235 } elseif {$type eq "path"} {
4236 ${NS}::label $top.l -text $title
4237 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4238 text $top.t -width 40 -height 5 -background $bgcolor
4239 if {[info exists viewfiles($n)]} {
4240 foreach f $viewfiles($n) {
4241 $top.t insert end $f
4242 $top.t insert end "\n"
4244 $top.t delete {end - 1c} end
4245 $top.t mark set insert 0.0
4247 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4251 ${NS}::frame $top.buts
4252 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4253 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4254 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4255 bind $top <Control-Return> [list newviewok $top $n]
4256 bind $top <F5> [list newviewok $top $n 1]
4257 bind $top <Escape> [list destroy $top]
4258 grid $top.buts.ok $top.buts.apply $top.buts.can
4259 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4260 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4261 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4262 pack $top.buts -in $top -side top -fill x
4266 proc doviewmenu {m first cmd op argv} {
4267 set nmenu [$m index end]
4268 for {set i $first} {$i <= $nmenu} {incr i} {
4269 if {[$m entrycget $i -command] eq $cmd} {
4270 eval $m $op $i $argv
4276 proc allviewmenus {n op args} {
4279 doviewmenu .bar.view 5 [list showview $n] $op $args
4280 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4283 proc newviewok {top n {apply 0}} {
4284 global nextviewnum newviewperm newviewname newishighlight
4285 global viewname viewfiles viewperm selectedview curview
4286 global viewargs viewargscmd newviewopts viewhlmenu
4289 set newargs [encode_view_opts $n]
4291 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4295 foreach f [split [$top.t get 0.0 end] "\n"] {
4296 set ft [string trim $f]
4301 if {![info exists viewfiles($n)]} {
4302 # creating a new view
4304 set viewname($n) $newviewname($n)
4305 set viewperm($n) $newviewopts($n,perm)
4306 set viewfiles($n) $files
4307 set viewargs($n) $newargs
4308 set viewargscmd($n) $newviewopts($n,cmd)
4310 if {!$newishighlight} {
4313 run addvhighlight $n
4316 # editing an existing view
4317 set viewperm($n) $newviewopts($n,perm)
4318 if {$newviewname($n) ne $viewname($n)} {
4319 set viewname($n) $newviewname($n)
4320 doviewmenu .bar.view 5 [list showview $n] \
4321 entryconf [list -label $viewname($n)]
4322 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4323 # entryconf [list -label $viewname($n) -value $viewname($n)]
4325 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4326 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4327 set viewfiles($n) $files
4328 set viewargs($n) $newargs
4329 set viewargscmd($n) $newviewopts($n,cmd)
4330 if {$curview == $n} {
4336 catch {destroy $top}
4340 global curview viewperm hlview selectedhlview
4342 if {$curview == 0} return
4343 if {[info exists hlview] && $hlview == $curview} {
4344 set selectedhlview [mc "None"]
4347 allviewmenus $curview delete
4348 set viewperm($curview) 0
4352 proc addviewmenu {n} {
4353 global viewname viewhlmenu
4355 .bar.view add radiobutton -label $viewname($n) \
4356 -command [list showview $n] -variable selectedview -value $n
4357 #$viewhlmenu add radiobutton -label $viewname($n) \
4358 # -command [list addvhighlight $n] -variable selectedhlview
4362 global curview cached_commitrow ordertok
4363 global displayorder parentlist rowidlist rowisopt rowfinal
4364 global colormap rowtextx nextcolor canvxmax
4365 global numcommits viewcomplete
4366 global selectedline currentid canv canvy0
4368 global pending_select mainheadid
4371 global hlview selectedhlview commitinterest
4373 if {$n == $curview} return
4375 set ymax [lindex [$canv cget -scrollregion] 3]
4376 set span [$canv yview]
4377 set ytop [expr {[lindex $span 0] * $ymax}]
4378 set ybot [expr {[lindex $span 1] * $ymax}]
4379 set yscreen [expr {($ybot - $ytop) / 2}]
4380 if {$selectedline ne {}} {
4381 set selid $currentid
4382 set y [yc $selectedline]
4383 if {$ytop < $y && $y < $ybot} {
4384 set yscreen [expr {$y - $ytop}]
4386 } elseif {[info exists pending_select]} {
4387 set selid $pending_select
4388 unset pending_select
4392 catch {unset treediffs}
4394 if {[info exists hlview] && $hlview == $n} {
4396 set selectedhlview [mc "None"]
4398 catch {unset commitinterest}
4399 catch {unset cached_commitrow}
4400 catch {unset ordertok}
4404 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4405 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4408 if {![info exists viewcomplete($n)]} {
4418 set numcommits $commitidx($n)
4420 catch {unset colormap}
4421 catch {unset rowtextx}
4423 set canvxmax [$canv cget -width]
4429 if {$selid ne {} && [commitinview $selid $n]} {
4430 set row [rowofcommit $selid]
4431 # try to get the selected row in the same position on the screen
4432 set ymax [lindex [$canv cget -scrollregion] 3]
4433 set ytop [expr {[yc $row] - $yscreen}]
4437 set yf [expr {$ytop * 1.0 / $ymax}]
4439 allcanvs yview moveto $yf
4443 } elseif {!$viewcomplete($n)} {
4444 reset_pending_select $selid
4446 reset_pending_select {}
4448 if {[commitinview $pending_select $curview]} {
4449 selectline [rowofcommit $pending_select] 1
4451 set row [first_real_row]
4452 if {$row < $numcommits} {
4457 if {!$viewcomplete($n)} {
4458 if {$numcommits == 0} {
4459 show_status [mc "Reading commits..."]
4461 } elseif {$numcommits == 0} {
4462 show_status [mc "No commits selected"]
4466 # Stuff relating to the highlighting facility
4468 proc ishighlighted {id} {
4469 global vhighlights fhighlights nhighlights rhighlights
4471 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4472 return $nhighlights($id)
4474 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4475 return $vhighlights($id)
4477 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4478 return $fhighlights($id)
4480 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4481 return $rhighlights($id)
4486 proc bolden {id font} {
4487 global canv linehtag currentid boldids need_redisplay markedid
4489 # need_redisplay = 1 means the display is stale and about to be redrawn
4490 if {$need_redisplay} return
4492 $canv itemconf $linehtag($id) -font $font
4493 if {[info exists currentid] && $id eq $currentid} {
4495 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4496 -outline {{}} -tags secsel \
4497 -fill [$canv cget -selectbackground]]
4500 if {[info exists markedid] && $id eq $markedid} {
4505 proc bolden_name {id font} {
4506 global canv2 linentag currentid boldnameids need_redisplay
4508 if {$need_redisplay} return
4509 lappend boldnameids $id
4510 $canv2 itemconf $linentag($id) -font $font
4511 if {[info exists currentid] && $id eq $currentid} {
4512 $canv2 delete secsel
4513 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4514 -outline {{}} -tags secsel \
4515 -fill [$canv2 cget -selectbackground]]
4524 foreach id $boldids {
4525 if {![ishighlighted $id]} {
4528 lappend stillbold $id
4531 set boldids $stillbold
4534 proc addvhighlight {n} {
4535 global hlview viewcomplete curview vhl_done commitidx
4537 if {[info exists hlview]} {
4541 if {$n != $curview && ![info exists viewcomplete($n)]} {
4544 set vhl_done $commitidx($hlview)
4545 if {$vhl_done > 0} {
4550 proc delvhighlight {} {
4551 global hlview vhighlights
4553 if {![info exists hlview]} return
4555 catch {unset vhighlights}
4559 proc vhighlightmore {} {
4560 global hlview vhl_done commitidx vhighlights curview
4562 set max $commitidx($hlview)
4563 set vr [visiblerows]
4564 set r0 [lindex $vr 0]
4565 set r1 [lindex $vr 1]
4566 for {set i $vhl_done} {$i < $max} {incr i} {
4567 set id [commitonrow $i $hlview]
4568 if {[commitinview $id $curview]} {
4569 set row [rowofcommit $id]
4570 if {$r0 <= $row && $row <= $r1} {
4571 if {![highlighted $row]} {
4572 bolden $id mainfontbold
4574 set vhighlights($id) 1
4582 proc askvhighlight {row id} {
4583 global hlview vhighlights iddrawn
4585 if {[commitinview $id $hlview]} {
4586 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4587 bolden $id mainfontbold
4589 set vhighlights($id) 1
4591 set vhighlights($id) 0
4595 proc hfiles_change {} {
4596 global highlight_files filehighlight fhighlights fh_serial
4597 global highlight_paths
4599 if {[info exists filehighlight]} {
4600 # delete previous highlights
4601 catch {close $filehighlight}
4603 catch {unset fhighlights}
4605 unhighlight_filelist
4607 set highlight_paths {}
4608 after cancel do_file_hl $fh_serial
4610 if {$highlight_files ne {}} {
4611 after 300 do_file_hl $fh_serial
4615 proc gdttype_change {name ix op} {
4616 global gdttype highlight_files findstring findpattern
4619 if {$findstring ne {}} {
4620 if {$gdttype eq [mc "containing:"]} {
4621 if {$highlight_files ne {}} {
4622 set highlight_files {}
4627 if {$findpattern ne {}} {
4631 set highlight_files $findstring
4636 # enable/disable findtype/findloc menus too
4639 proc find_change {name ix op} {
4640 global gdttype findstring highlight_files
4643 if {$gdttype eq [mc "containing:"]} {
4646 if {$highlight_files ne $findstring} {
4647 set highlight_files $findstring
4654 proc findcom_change args {
4655 global nhighlights boldnameids
4656 global findpattern findtype findstring gdttype
4659 # delete previous highlights, if any
4660 foreach id $boldnameids {
4661 bolden_name $id mainfont
4664 catch {unset nhighlights}
4667 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4669 } elseif {$findtype eq [mc "Regexp"]} {
4670 set findpattern $findstring
4672 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4674 set findpattern "*$e*"
4678 proc makepatterns {l} {
4681 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4682 if {[string index $ee end] eq "/"} {
4692 proc do_file_hl {serial} {
4693 global highlight_files filehighlight highlight_paths gdttype fhl_list
4694 global cdup findtype
4696 if {$gdttype eq [mc "touching paths:"]} {
4697 # If "exact" match then convert backslashes to forward slashes.
4698 # Most useful to support Windows-flavoured file paths.
4699 if {$findtype eq [mc "Exact"]} {
4700 set highlight_files [string map {"\\" "/"} $highlight_files]
4702 if {[catch {set paths [shellsplit $highlight_files]}]} return
4703 set highlight_paths [makepatterns $paths]
4705 set relative_paths {}
4706 foreach path $paths {
4707 lappend relative_paths [file join $cdup $path]
4709 set gdtargs [concat -- $relative_paths]
4710 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4711 set gdtargs [list "-S$highlight_files"]
4712 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4713 set gdtargs [list "-G$highlight_files"]
4715 # must be "containing:", i.e. we're searching commit info
4718 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4719 set filehighlight [open $cmd r+]
4720 fconfigure $filehighlight -blocking 0
4721 filerun $filehighlight readfhighlight
4727 proc flushhighlights {} {
4728 global filehighlight fhl_list
4730 if {[info exists filehighlight]} {
4732 puts $filehighlight ""
4733 flush $filehighlight
4737 proc askfilehighlight {row id} {
4738 global filehighlight fhighlights fhl_list
4740 lappend fhl_list $id
4741 set fhighlights($id) -1
4742 puts $filehighlight $id
4745 proc readfhighlight {} {
4746 global filehighlight fhighlights curview iddrawn
4747 global fhl_list find_dirn
4749 if {![info exists filehighlight]} {
4753 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4754 set line [string trim $line]
4755 set i [lsearch -exact $fhl_list $line]
4756 if {$i < 0} continue
4757 for {set j 0} {$j < $i} {incr j} {
4758 set id [lindex $fhl_list $j]
4759 set fhighlights($id) 0
4761 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4762 if {$line eq {}} continue
4763 if {![commitinview $line $curview]} continue
4764 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4765 bolden $line mainfontbold
4767 set fhighlights($line) 1
4769 if {[eof $filehighlight]} {
4771 puts "oops, git diff-tree died"
4772 catch {close $filehighlight}
4776 if {[info exists find_dirn]} {
4782 proc doesmatch {f} {
4783 global findtype findpattern
4785 if {$findtype eq [mc "Regexp"]} {
4786 return [regexp $findpattern $f]
4787 } elseif {$findtype eq [mc "IgnCase"]} {
4788 return [string match -nocase $findpattern $f]
4790 return [string match $findpattern $f]
4794 proc askfindhighlight {row id} {
4795 global nhighlights commitinfo iddrawn
4797 global markingmatches
4799 if {![info exists commitinfo($id)]} {
4802 set info $commitinfo($id)
4804 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4805 foreach f $info ty $fldtypes {
4806 if {$ty eq ""} continue
4807 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4809 if {$ty eq [mc "Author"]} {
4816 if {$isbold && [info exists iddrawn($id)]} {
4817 if {![ishighlighted $id]} {
4818 bolden $id mainfontbold
4820 bolden_name $id mainfontbold
4823 if {$markingmatches} {
4824 markrowmatches $row $id
4827 set nhighlights($id) $isbold
4830 proc markrowmatches {row id} {
4831 global canv canv2 linehtag linentag commitinfo findloc
4833 set headline [lindex $commitinfo($id) 0]
4834 set author [lindex $commitinfo($id) 1]
4835 $canv delete match$row
4836 $canv2 delete match$row
4837 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4838 set m [findmatches $headline]
4840 markmatches $canv $row $headline $linehtag($id) $m \
4841 [$canv itemcget $linehtag($id) -font] $row
4844 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4845 set m [findmatches $author]
4847 markmatches $canv2 $row $author $linentag($id) $m \
4848 [$canv2 itemcget $linentag($id) -font] $row
4853 proc vrel_change {name ix op} {
4854 global highlight_related
4857 if {$highlight_related ne [mc "None"]} {
4862 # prepare for testing whether commits are descendents or ancestors of a
4863 proc rhighlight_sel {a} {
4864 global descendent desc_todo ancestor anc_todo
4865 global highlight_related
4867 catch {unset descendent}
4868 set desc_todo [list $a]
4869 catch {unset ancestor}
4870 set anc_todo [list $a]
4871 if {$highlight_related ne [mc "None"]} {
4877 proc rhighlight_none {} {
4880 catch {unset rhighlights}
4884 proc is_descendent {a} {
4885 global curview children descendent desc_todo
4888 set la [rowofcommit $a]
4892 for {set i 0} {$i < [llength $todo]} {incr i} {
4893 set do [lindex $todo $i]
4894 if {[rowofcommit $do] < $la} {
4895 lappend leftover $do
4898 foreach nk $children($v,$do) {
4899 if {![info exists descendent($nk)]} {
4900 set descendent($nk) 1
4908 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4912 set descendent($a) 0
4913 set desc_todo $leftover
4916 proc is_ancestor {a} {
4917 global curview parents ancestor anc_todo
4920 set la [rowofcommit $a]
4924 for {set i 0} {$i < [llength $todo]} {incr i} {
4925 set do [lindex $todo $i]
4926 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4927 lappend leftover $do
4930 foreach np $parents($v,$do) {
4931 if {![info exists ancestor($np)]} {
4940 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4945 set anc_todo $leftover
4948 proc askrelhighlight {row id} {
4949 global descendent highlight_related iddrawn rhighlights
4950 global selectedline ancestor
4952 if {$selectedline eq {}} return
4954 if {$highlight_related eq [mc "Descendant"] ||
4955 $highlight_related eq [mc "Not descendant"]} {
4956 if {![info exists descendent($id)]} {
4959 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4962 } elseif {$highlight_related eq [mc "Ancestor"] ||
4963 $highlight_related eq [mc "Not ancestor"]} {
4964 if {![info exists ancestor($id)]} {
4967 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4971 if {[info exists iddrawn($id)]} {
4972 if {$isbold && ![ishighlighted $id]} {
4973 bolden $id mainfontbold
4976 set rhighlights($id) $isbold
4979 # Graph layout functions
4981 proc shortids {ids} {
4984 if {[llength $id] > 1} {
4985 lappend res [shortids $id]
4986 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4987 lappend res [string range $id 0 7]
4998 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4999 if {($n & $mask) != 0} {
5000 set ret [concat $ret $o]
5002 set o [concat $o $o]
5007 proc ordertoken {id} {
5008 global ordertok curview varcid varcstart varctok curview parents children
5009 global nullid nullid2
5011 if {[info exists ordertok($id)]} {
5012 return $ordertok($id)
5017 if {[info exists varcid($curview,$id)]} {
5018 set a $varcid($curview,$id)
5019 set p [lindex $varcstart($curview) $a]
5021 set p [lindex $children($curview,$id) 0]
5023 if {[info exists ordertok($p)]} {
5024 set tok $ordertok($p)
5027 set id [first_real_child $curview,$p]
5030 set tok [lindex $varctok($curview) $varcid($curview,$p)]
5033 if {[llength $parents($curview,$id)] == 1} {
5034 lappend todo [list $p {}]
5036 set j [lsearch -exact $parents($curview,$id) $p]
5038 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5040 lappend todo [list $p [strrep $j]]
5043 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5044 set p [lindex $todo $i 0]
5045 append tok [lindex $todo $i 1]
5046 set ordertok($p) $tok
5048 set ordertok($origid) $tok
5052 # Work out where id should go in idlist so that order-token
5053 # values increase from left to right
5054 proc idcol {idlist id {i 0}} {
5055 set t [ordertoken $id]
5059 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5060 if {$i > [llength $idlist]} {
5061 set i [llength $idlist]
5063 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5066 if {$t > [ordertoken [lindex $idlist $i]]} {
5067 while {[incr i] < [llength $idlist] &&
5068 $t >= [ordertoken [lindex $idlist $i]]} {}
5074 proc initlayout {} {
5075 global rowidlist rowisopt rowfinal displayorder parentlist
5076 global numcommits canvxmax canv
5078 global colormap rowtextx
5087 set canvxmax [$canv cget -width]
5088 catch {unset colormap}
5089 catch {unset rowtextx}
5093 proc setcanvscroll {} {
5094 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5095 global lastscrollset lastscrollrows
5097 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5098 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5099 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5100 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5101 set lastscrollset [clock clicks -milliseconds]
5102 set lastscrollrows $numcommits
5105 proc visiblerows {} {
5106 global canv numcommits linespc
5108 set ymax [lindex [$canv cget -scrollregion] 3]
5109 if {$ymax eq {} || $ymax == 0} return
5111 set y0 [expr {int([lindex $f 0] * $ymax)}]
5112 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5116 set y1 [expr {int([lindex $f 1] * $ymax)}]
5117 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5118 if {$r1 >= $numcommits} {
5119 set r1 [expr {$numcommits - 1}]
5121 return [list $r0 $r1]
5124 proc layoutmore {} {
5125 global commitidx viewcomplete curview
5126 global numcommits pending_select curview
5127 global lastscrollset lastscrollrows
5129 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5130 [clock clicks -milliseconds] - $lastscrollset > 500} {
5133 if {[info exists pending_select] &&
5134 [commitinview $pending_select $curview]} {
5136 selectline [rowofcommit $pending_select] 1
5141 # With path limiting, we mightn't get the actual HEAD commit,
5142 # so ask git rev-list what is the first ancestor of HEAD that
5143 # touches a file in the path limit.
5144 proc get_viewmainhead {view} {
5145 global viewmainheadid vfilelimit viewinstances mainheadid
5148 set rfd [open [concat | git rev-list -1 $mainheadid \
5149 -- $vfilelimit($view)] r]
5150 set j [reg_instance $rfd]
5151 lappend viewinstances($view) $j
5152 fconfigure $rfd -blocking 0
5153 filerun $rfd [list getviewhead $rfd $j $view]
5154 set viewmainheadid($curview) {}
5158 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5159 proc getviewhead {fd inst view} {
5160 global viewmainheadid commfd curview viewinstances showlocalchanges
5163 if {[gets $fd line] < 0} {
5167 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5170 set viewmainheadid($view) $id
5173 set i [lsearch -exact $viewinstances($view) $inst]
5175 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5177 if {$showlocalchanges && $id ne {} && $view == $curview} {
5183 proc doshowlocalchanges {} {
5184 global curview viewmainheadid
5186 if {$viewmainheadid($curview) eq {}} return
5187 if {[commitinview $viewmainheadid($curview) $curview]} {
5190 interestedin $viewmainheadid($curview) dodiffindex
5194 proc dohidelocalchanges {} {
5195 global nullid nullid2 lserial curview
5197 if {[commitinview $nullid $curview]} {
5198 removefakerow $nullid
5200 if {[commitinview $nullid2 $curview]} {
5201 removefakerow $nullid2
5206 # spawn off a process to do git diff-index --cached HEAD
5207 proc dodiffindex {} {
5208 global lserial showlocalchanges vfilelimit curview
5211 if {!$showlocalchanges || !$hasworktree} return
5213 set cmd "|git diff-index --cached HEAD"
5214 if {$vfilelimit($curview) ne {}} {
5215 set cmd [concat $cmd -- $vfilelimit($curview)]
5217 set fd [open $cmd r]
5218 fconfigure $fd -blocking 0
5219 set i [reg_instance $fd]
5220 filerun $fd [list readdiffindex $fd $lserial $i]
5223 proc readdiffindex {fd serial inst} {
5224 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5228 if {[gets $fd line] < 0} {
5234 # we only need to see one line and we don't really care what it says...
5237 if {$serial != $lserial} {
5241 # now see if there are any local changes not checked in to the index
5242 set cmd "|git diff-files"
5243 if {$vfilelimit($curview) ne {}} {
5244 set cmd [concat $cmd -- $vfilelimit($curview)]
5246 set fd [open $cmd r]
5247 fconfigure $fd -blocking 0
5248 set i [reg_instance $fd]
5249 filerun $fd [list readdifffiles $fd $serial $i]
5251 if {$isdiff && ![commitinview $nullid2 $curview]} {
5252 # add the line for the changes in the index to the graph
5253 set hl [mc "Local changes checked in to index but not committed"]
5254 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5255 set commitdata($nullid2) "\n $hl\n"
5256 if {[commitinview $nullid $curview]} {
5257 removefakerow $nullid
5259 insertfakerow $nullid2 $viewmainheadid($curview)
5260 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5261 if {[commitinview $nullid $curview]} {
5262 removefakerow $nullid
5264 removefakerow $nullid2
5269 proc readdifffiles {fd serial inst} {
5270 global viewmainheadid nullid nullid2 curview
5271 global commitinfo commitdata lserial
5274 if {[gets $fd line] < 0} {
5280 # we only need to see one line and we don't really care what it says...
5283 if {$serial != $lserial} {
5287 if {$isdiff && ![commitinview $nullid $curview]} {
5288 # add the line for the local diff to the graph
5289 set hl [mc "Local uncommitted changes, not checked in to index"]
5290 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5291 set commitdata($nullid) "\n $hl\n"
5292 if {[commitinview $nullid2 $curview]} {
5295 set p $viewmainheadid($curview)
5297 insertfakerow $nullid $p
5298 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5299 removefakerow $nullid
5304 proc nextuse {id row} {
5305 global curview children
5307 if {[info exists children($curview,$id)]} {
5308 foreach kid $children($curview,$id) {
5309 if {![commitinview $kid $curview]} {
5312 if {[rowofcommit $kid] > $row} {
5313 return [rowofcommit $kid]
5317 if {[commitinview $id $curview]} {
5318 return [rowofcommit $id]
5323 proc prevuse {id row} {
5324 global curview children
5327 if {[info exists children($curview,$id)]} {
5328 foreach kid $children($curview,$id) {
5329 if {![commitinview $kid $curview]} break
5330 if {[rowofcommit $kid] < $row} {
5331 set ret [rowofcommit $kid]
5338 proc make_idlist {row} {
5339 global displayorder parentlist uparrowlen downarrowlen mingaplen
5340 global commitidx curview children
5342 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5346 set ra [expr {$row - $downarrowlen}]
5350 set rb [expr {$row + $uparrowlen}]
5351 if {$rb > $commitidx($curview)} {
5352 set rb $commitidx($curview)
5354 make_disporder $r [expr {$rb + 1}]
5356 for {} {$r < $ra} {incr r} {
5357 set nextid [lindex $displayorder [expr {$r + 1}]]
5358 foreach p [lindex $parentlist $r] {
5359 if {$p eq $nextid} continue
5360 set rn [nextuse $p $r]
5362 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5363 lappend ids [list [ordertoken $p] $p]
5367 for {} {$r < $row} {incr r} {
5368 set nextid [lindex $displayorder [expr {$r + 1}]]
5369 foreach p [lindex $parentlist $r] {
5370 if {$p eq $nextid} continue
5371 set rn [nextuse $p $r]
5372 if {$rn < 0 || $rn >= $row} {
5373 lappend ids [list [ordertoken $p] $p]
5377 set id [lindex $displayorder $row]
5378 lappend ids [list [ordertoken $id] $id]
5380 foreach p [lindex $parentlist $r] {
5381 set firstkid [lindex $children($curview,$p) 0]
5382 if {[rowofcommit $firstkid] < $row} {
5383 lappend ids [list [ordertoken $p] $p]
5387 set id [lindex $displayorder $r]
5389 set firstkid [lindex $children($curview,$id) 0]
5390 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5391 lappend ids [list [ordertoken $id] $id]
5396 foreach idx [lsort -unique $ids] {
5397 lappend idlist [lindex $idx 1]
5402 proc rowsequal {a b} {
5403 while {[set i [lsearch -exact $a {}]] >= 0} {
5404 set a [lreplace $a $i $i]
5406 while {[set i [lsearch -exact $b {}]] >= 0} {
5407 set b [lreplace $b $i $i]
5409 return [expr {$a eq $b}]
5412 proc makeupline {id row rend col} {
5413 global rowidlist uparrowlen downarrowlen mingaplen
5415 for {set r $rend} {1} {set r $rstart} {
5416 set rstart [prevuse $id $r]
5417 if {$rstart < 0} return
5418 if {$rstart < $row} break
5420 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5421 set rstart [expr {$rend - $uparrowlen - 1}]
5423 for {set r $rstart} {[incr r] <= $row} {} {
5424 set idlist [lindex $rowidlist $r]
5425 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5426 set col [idcol $idlist $id $col]
5427 lset rowidlist $r [linsert $idlist $col $id]
5433 proc layoutrows {row endrow} {
5434 global rowidlist rowisopt rowfinal displayorder
5435 global uparrowlen downarrowlen maxwidth mingaplen
5436 global children parentlist
5437 global commitidx viewcomplete curview
5439 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5442 set rm1 [expr {$row - 1}]
5443 foreach id [lindex $rowidlist $rm1] {
5448 set final [lindex $rowfinal $rm1]
5450 for {} {$row < $endrow} {incr row} {
5451 set rm1 [expr {$row - 1}]
5452 if {$rm1 < 0 || $idlist eq {}} {
5453 set idlist [make_idlist $row]
5456 set id [lindex $displayorder $rm1]
5457 set col [lsearch -exact $idlist $id]
5458 set idlist [lreplace $idlist $col $col]
5459 foreach p [lindex $parentlist $rm1] {
5460 if {[lsearch -exact $idlist $p] < 0} {
5461 set col [idcol $idlist $p $col]
5462 set idlist [linsert $idlist $col $p]
5463 # if not the first child, we have to insert a line going up
5464 if {$id ne [lindex $children($curview,$p) 0]} {
5465 makeupline $p $rm1 $row $col
5469 set id [lindex $displayorder $row]
5470 if {$row > $downarrowlen} {
5471 set termrow [expr {$row - $downarrowlen - 1}]
5472 foreach p [lindex $parentlist $termrow] {
5473 set i [lsearch -exact $idlist $p]
5474 if {$i < 0} continue
5475 set nr [nextuse $p $termrow]
5476 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5477 set idlist [lreplace $idlist $i $i]
5481 set col [lsearch -exact $idlist $id]
5483 set col [idcol $idlist $id]
5484 set idlist [linsert $idlist $col $id]
5485 if {$children($curview,$id) ne {}} {
5486 makeupline $id $rm1 $row $col
5489 set r [expr {$row + $uparrowlen - 1}]
5490 if {$r < $commitidx($curview)} {
5492 foreach p [lindex $parentlist $r] {
5493 if {[lsearch -exact $idlist $p] >= 0} continue
5494 set fk [lindex $children($curview,$p) 0]
5495 if {[rowofcommit $fk] < $row} {
5496 set x [idcol $idlist $p $x]
5497 set idlist [linsert $idlist $x $p]
5500 if {[incr r] < $commitidx($curview)} {
5501 set p [lindex $displayorder $r]
5502 if {[lsearch -exact $idlist $p] < 0} {
5503 set fk [lindex $children($curview,$p) 0]
5504 if {$fk ne {} && [rowofcommit $fk] < $row} {
5505 set x [idcol $idlist $p $x]
5506 set idlist [linsert $idlist $x $p]
5512 if {$final && !$viewcomplete($curview) &&
5513 $row + $uparrowlen + $mingaplen + $downarrowlen
5514 >= $commitidx($curview)} {
5517 set l [llength $rowidlist]
5519 lappend rowidlist $idlist
5521 lappend rowfinal $final
5522 } elseif {$row < $l} {
5523 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5524 lset rowidlist $row $idlist
5527 lset rowfinal $row $final
5529 set pad [ntimes [expr {$row - $l}] {}]
5530 set rowidlist [concat $rowidlist $pad]
5531 lappend rowidlist $idlist
5532 set rowfinal [concat $rowfinal $pad]
5533 lappend rowfinal $final
5534 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5540 proc changedrow {row} {
5541 global displayorder iddrawn rowisopt need_redisplay
5543 set l [llength $rowisopt]
5545 lset rowisopt $row 0
5546 if {$row + 1 < $l} {
5547 lset rowisopt [expr {$row + 1}] 0
5548 if {$row + 2 < $l} {
5549 lset rowisopt [expr {$row + 2}] 0
5553 set id [lindex $displayorder $row]
5554 if {[info exists iddrawn($id)]} {
5555 set need_redisplay 1
5559 proc insert_pad {row col npad} {
5562 set pad [ntimes $npad {}]
5563 set idlist [lindex $rowidlist $row]
5564 set bef [lrange $idlist 0 [expr {$col - 1}]]
5565 set aft [lrange $idlist $col end]
5566 set i [lsearch -exact $aft {}]
5568 set aft [lreplace $aft $i $i]
5570 lset rowidlist $row [concat $bef $pad $aft]
5574 proc optimize_rows {row col endrow} {
5575 global rowidlist rowisopt displayorder curview children
5580 for {} {$row < $endrow} {incr row; set col 0} {
5581 if {[lindex $rowisopt $row]} continue
5583 set y0 [expr {$row - 1}]
5584 set ym [expr {$row - 2}]
5585 set idlist [lindex $rowidlist $row]
5586 set previdlist [lindex $rowidlist $y0]
5587 if {$idlist eq {} || $previdlist eq {}} continue
5589 set pprevidlist [lindex $rowidlist $ym]
5590 if {$pprevidlist eq {}} continue
5596 for {} {$col < [llength $idlist]} {incr col} {
5597 set id [lindex $idlist $col]
5598 if {[lindex $previdlist $col] eq $id} continue
5603 set x0 [lsearch -exact $previdlist $id]
5604 if {$x0 < 0} continue
5605 set z [expr {$x0 - $col}]
5609 set xm [lsearch -exact $pprevidlist $id]
5611 set z0 [expr {$xm - $x0}]
5615 # if row y0 is the first child of $id then it's not an arrow
5616 if {[lindex $children($curview,$id) 0] ne
5617 [lindex $displayorder $y0]} {
5621 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5622 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5625 # Looking at lines from this row to the previous row,
5626 # make them go straight up if they end in an arrow on
5627 # the previous row; otherwise make them go straight up
5629 if {$z < -1 || ($z < 0 && $isarrow)} {
5630 # Line currently goes left too much;
5631 # insert pads in the previous row, then optimize it
5632 set npad [expr {-1 - $z + $isarrow}]
5633 insert_pad $y0 $x0 $npad
5635 optimize_rows $y0 $x0 $row
5637 set previdlist [lindex $rowidlist $y0]
5638 set x0 [lsearch -exact $previdlist $id]
5639 set z [expr {$x0 - $col}]
5641 set pprevidlist [lindex $rowidlist $ym]
5642 set xm [lsearch -exact $pprevidlist $id]
5643 set z0 [expr {$xm - $x0}]
5645 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5646 # Line currently goes right too much;
5647 # insert pads in this line
5648 set npad [expr {$z - 1 + $isarrow}]
5649 insert_pad $row $col $npad
5650 set idlist [lindex $rowidlist $row]
5652 set z [expr {$x0 - $col}]
5655 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5656 # this line links to its first child on row $row-2
5657 set id [lindex $displayorder $ym]
5658 set xc [lsearch -exact $pprevidlist $id]
5660 set z0 [expr {$xc - $x0}]
5663 # avoid lines jigging left then immediately right
5664 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5665 insert_pad $y0 $x0 1
5667 optimize_rows $y0 $x0 $row
5668 set previdlist [lindex $rowidlist $y0]
5672 # Find the first column that doesn't have a line going right
5673 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5674 set id [lindex $idlist $col]
5675 if {$id eq {}} break
5676 set x0 [lsearch -exact $previdlist $id]
5678 # check if this is the link to the first child
5679 set kid [lindex $displayorder $y0]
5680 if {[lindex $children($curview,$id) 0] eq $kid} {
5681 # it is, work out offset to child
5682 set x0 [lsearch -exact $previdlist $kid]
5685 if {$x0 <= $col} break
5687 # Insert a pad at that column as long as it has a line and
5688 # isn't the last column
5689 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5690 set idlist [linsert $idlist $col {}]
5691 lset rowidlist $row $idlist
5699 global canvx0 linespc
5700 return [expr {$canvx0 + $col * $linespc}]
5704 global canvy0 linespc
5705 return [expr {$canvy0 + $row * $linespc}]
5708 proc linewidth {id} {
5709 global thickerline lthickness
5712 if {[info exists thickerline] && $id eq $thickerline} {
5713 set wid [expr {2 * $lthickness}]
5718 proc rowranges {id} {
5719 global curview children uparrowlen downarrowlen
5722 set kids $children($curview,$id)
5728 foreach child $kids {
5729 if {![commitinview $child $curview]} break
5730 set row [rowofcommit $child]
5731 if {![info exists prev]} {
5732 lappend ret [expr {$row + 1}]
5734 if {$row <= $prevrow} {
5735 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5737 # see if the line extends the whole way from prevrow to row
5738 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5739 [lsearch -exact [lindex $rowidlist \
5740 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5741 # it doesn't, see where it ends
5742 set r [expr {$prevrow + $downarrowlen}]
5743 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5744 while {[incr r -1] > $prevrow &&
5745 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5747 while {[incr r] <= $row &&
5748 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5752 # see where it starts up again
5753 set r [expr {$row - $uparrowlen}]
5754 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5755 while {[incr r] < $row &&
5756 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5758 while {[incr r -1] >= $prevrow &&
5759 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5765 if {$child eq $id} {
5774 proc drawlineseg {id row endrow arrowlow} {
5775 global rowidlist displayorder iddrawn linesegs
5776 global canv colormap linespc curview maxlinelen parentlist
5778 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5779 set le [expr {$row + 1}]
5782 set c [lsearch -exact [lindex $rowidlist $le] $id]
5788 set x [lindex $displayorder $le]
5793 if {[info exists iddrawn($x)] || $le == $endrow} {
5794 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5810 if {[info exists linesegs($id)]} {
5811 set lines $linesegs($id)
5813 set r0 [lindex $li 0]
5815 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5825 set li [lindex $lines [expr {$i-1}]]
5826 set r1 [lindex $li 1]
5827 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5832 set x [lindex $cols [expr {$le - $row}]]
5833 set xp [lindex $cols [expr {$le - 1 - $row}]]
5834 set dir [expr {$xp - $x}]
5836 set ith [lindex $lines $i 2]
5837 set coords [$canv coords $ith]
5838 set ah [$canv itemcget $ith -arrow]
5839 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5840 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5841 if {$x2 ne {} && $x - $x2 == $dir} {
5842 set coords [lrange $coords 0 end-2]
5845 set coords [list [xc $le $x] [yc $le]]
5848 set itl [lindex $lines [expr {$i-1}] 2]
5849 set al [$canv itemcget $itl -arrow]
5850 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5851 } elseif {$arrowlow} {
5852 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5853 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5857 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5858 for {set y $le} {[incr y -1] > $row} {} {
5860 set xp [lindex $cols [expr {$y - 1 - $row}]]
5861 set ndir [expr {$xp - $x}]
5862 if {$dir != $ndir || $xp < 0} {
5863 lappend coords [xc $y $x] [yc $y]
5869 # join parent line to first child
5870 set ch [lindex $displayorder $row]
5871 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5873 puts "oops: drawlineseg: child $ch not on row $row"
5874 } elseif {$xc != $x} {
5875 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5876 set d [expr {int(0.5 * $linespc)}]
5879 set x2 [expr {$x1 - $d}]
5881 set x2 [expr {$x1 + $d}]
5884 set y1 [expr {$y2 + $d}]
5885 lappend coords $x1 $y1 $x2 $y2
5886 } elseif {$xc < $x - 1} {
5887 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5888 } elseif {$xc > $x + 1} {
5889 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5893 lappend coords [xc $row $x] [yc $row]
5895 set xn [xc $row $xp]
5897 lappend coords $xn $yn
5901 set t [$canv create line $coords -width [linewidth $id] \
5902 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5905 set lines [linsert $lines $i [list $row $le $t]]
5907 $canv coords $ith $coords
5908 if {$arrow ne $ah} {
5909 $canv itemconf $ith -arrow $arrow
5911 lset lines $i 0 $row
5914 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5915 set ndir [expr {$xo - $xp}]
5916 set clow [$canv coords $itl]
5917 if {$dir == $ndir} {
5918 set clow [lrange $clow 2 end]
5920 set coords [concat $coords $clow]
5922 lset lines [expr {$i-1}] 1 $le
5924 # coalesce two pieces
5926 set b [lindex $lines [expr {$i-1}] 0]
5927 set e [lindex $lines $i 1]
5928 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5930 $canv coords $itl $coords
5931 if {$arrow ne $al} {
5932 $canv itemconf $itl -arrow $arrow
5936 set linesegs($id) $lines
5940 proc drawparentlinks {id row} {
5941 global rowidlist canv colormap curview parentlist
5942 global idpos linespc
5944 set rowids [lindex $rowidlist $row]
5945 set col [lsearch -exact $rowids $id]
5946 if {$col < 0} return
5947 set olds [lindex $parentlist $row]
5948 set row2 [expr {$row + 1}]
5949 set x [xc $row $col]
5952 set d [expr {int(0.5 * $linespc)}]
5953 set ymid [expr {$y + $d}]
5954 set ids [lindex $rowidlist $row2]
5955 # rmx = right-most X coord used
5958 set i [lsearch -exact $ids $p]
5960 puts "oops, parent $p of $id not in list"
5963 set x2 [xc $row2 $i]
5967 set j [lsearch -exact $rowids $p]
5969 # drawlineseg will do this one for us
5973 # should handle duplicated parents here...
5974 set coords [list $x $y]
5976 # if attaching to a vertical segment, draw a smaller
5977 # slant for visual distinctness
5980 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5982 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5984 } elseif {$i < $col && $i < $j} {
5985 # segment slants towards us already
5986 lappend coords [xc $row $j] $y
5988 if {$i < $col - 1} {
5989 lappend coords [expr {$x2 + $linespc}] $y
5990 } elseif {$i > $col + 1} {
5991 lappend coords [expr {$x2 - $linespc}] $y
5993 lappend coords $x2 $y2
5996 lappend coords $x2 $y2
5998 set t [$canv create line $coords -width [linewidth $p] \
5999 -fill $colormap($p) -tags lines.$p]
6003 if {$rmx > [lindex $idpos($id) 1]} {
6004 lset idpos($id) 1 $rmx
6009 proc drawlines {id} {
6012 $canv itemconf lines.$id -width [linewidth $id]
6015 proc drawcmittext {id row col} {
6016 global linespc canv canv2 canv3 fgcolor curview
6017 global cmitlisted commitinfo rowidlist parentlist
6018 global rowtextx idpos idtags idheads idotherrefs
6019 global linehtag linentag linedtag selectedline
6020 global canvxmax boldids boldnameids fgcolor markedid
6021 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
6022 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
6023 global circleoutlinecolor
6025 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
6026 set listed $cmitlisted($curview,$id)
6027 if {$id eq $nullid} {
6028 set ofill $workingfilescirclecolor
6029 } elseif {$id eq $nullid2} {
6030 set ofill $indexcirclecolor
6031 } elseif {$id eq $mainheadid} {
6032 set ofill $mainheadcirclecolor
6034 set ofill [lindex $circlecolors $listed]
6036 set x [xc $row $col]
6038 set orad [expr {$linespc / 3}]
6040 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6041 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6042 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6043 } elseif {$listed == 3} {
6044 # triangle pointing left for left-side commits
6045 set t [$canv create polygon \
6046 [expr {$x - $orad}] $y \
6047 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6048 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6049 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6051 # triangle pointing right for right-side commits
6052 set t [$canv create polygon \
6053 [expr {$x + $orad - 1}] $y \
6054 [expr {$x - $orad}] [expr {$y - $orad}] \
6055 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6056 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6058 set circleitem($row) $t
6060 $canv bind $t <1> {selcanvline {} %x %y}
6061 set rmx [llength [lindex $rowidlist $row]]
6062 set olds [lindex $parentlist $row]
6064 set nextids [lindex $rowidlist [expr {$row + 1}]]
6066 set i [lsearch -exact $nextids $p]
6072 set xt [xc $row $rmx]
6073 set rowtextx($row) $xt
6074 set idpos($id) [list $x $xt $y]
6075 if {[info exists idtags($id)] || [info exists idheads($id)]
6076 || [info exists idotherrefs($id)]} {
6077 set xt [drawtags $id $x $xt $y]
6079 if {[lindex $commitinfo($id) 6] > 0} {
6080 set xt [drawnotesign $xt $y]
6082 set headline [lindex $commitinfo($id) 0]
6083 set name [lindex $commitinfo($id) 1]
6084 set date [lindex $commitinfo($id) 2]
6085 set date [formatdate $date]
6088 set isbold [ishighlighted $id]
6091 set font mainfontbold
6093 lappend boldnameids $id
6094 set nfont mainfontbold
6097 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6098 -text $headline -font $font -tags text]
6099 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6100 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6101 -text $name -font $nfont -tags text]
6102 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6103 -text $date -font mainfont -tags text]
6104 if {$selectedline == $row} {
6107 if {[info exists markedid] && $markedid eq $id} {
6110 set xr [expr {$xt + [font measure $font $headline]}]
6111 if {$xr > $canvxmax} {
6117 proc drawcmitrow {row} {
6118 global displayorder rowidlist nrows_drawn
6119 global iddrawn markingmatches
6120 global commitinfo numcommits
6121 global filehighlight fhighlights findpattern nhighlights
6122 global hlview vhighlights
6123 global highlight_related rhighlights
6125 if {$row >= $numcommits} return
6127 set id [lindex $displayorder $row]
6128 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6129 askvhighlight $row $id
6131 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6132 askfilehighlight $row $id
6134 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6135 askfindhighlight $row $id
6137 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6138 askrelhighlight $row $id
6140 if {![info exists iddrawn($id)]} {
6141 set col [lsearch -exact [lindex $rowidlist $row] $id]
6143 puts "oops, row $row id $id not in list"
6146 if {![info exists commitinfo($id)]} {
6150 drawcmittext $id $row $col
6154 if {$markingmatches} {
6155 markrowmatches $row $id
6159 proc drawcommits {row {endrow {}}} {
6160 global numcommits iddrawn displayorder curview need_redisplay
6161 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6166 if {$endrow eq {}} {
6169 if {$endrow >= $numcommits} {
6170 set endrow [expr {$numcommits - 1}]
6173 set rl1 [expr {$row - $downarrowlen - 3}]
6177 set ro1 [expr {$row - 3}]
6181 set r2 [expr {$endrow + $uparrowlen + 3}]
6182 if {$r2 > $numcommits} {
6185 for {set r $rl1} {$r < $r2} {incr r} {
6186 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6190 set rl1 [expr {$r + 1}]
6196 optimize_rows $ro1 0 $r2
6197 if {$need_redisplay || $nrows_drawn > 2000} {
6201 # make the lines join to already-drawn rows either side
6202 set r [expr {$row - 1}]
6203 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6206 set er [expr {$endrow + 1}]
6207 if {$er >= $numcommits ||
6208 ![info exists iddrawn([lindex $displayorder $er])]} {
6211 for {} {$r <= $er} {incr r} {
6212 set id [lindex $displayorder $r]
6213 set wasdrawn [info exists iddrawn($id)]
6215 if {$r == $er} break
6216 set nextid [lindex $displayorder [expr {$r + 1}]]
6217 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6218 drawparentlinks $id $r
6220 set rowids [lindex $rowidlist $r]
6221 foreach lid $rowids {
6222 if {$lid eq {}} continue
6223 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6225 # see if this is the first child of any of its parents
6226 foreach p [lindex $parentlist $r] {
6227 if {[lsearch -exact $rowids $p] < 0} {
6228 # make this line extend up to the child
6229 set lineend($p) [drawlineseg $p $r $er 0]
6233 set lineend($lid) [drawlineseg $lid $r $er 1]
6239 proc undolayout {row} {
6240 global uparrowlen mingaplen downarrowlen
6241 global rowidlist rowisopt rowfinal need_redisplay
6243 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6247 if {[llength $rowidlist] > $r} {
6249 set rowidlist [lrange $rowidlist 0 $r]
6250 set rowfinal [lrange $rowfinal 0 $r]
6251 set rowisopt [lrange $rowisopt 0 $r]
6252 set need_redisplay 1
6257 proc drawvisible {} {
6258 global canv linespc curview vrowmod selectedline targetrow targetid
6259 global need_redisplay cscroll numcommits
6261 set fs [$canv yview]
6262 set ymax [lindex [$canv cget -scrollregion] 3]
6263 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6264 set f0 [lindex $fs 0]
6265 set f1 [lindex $fs 1]
6266 set y0 [expr {int($f0 * $ymax)}]
6267 set y1 [expr {int($f1 * $ymax)}]
6269 if {[info exists targetid]} {
6270 if {[commitinview $targetid $curview]} {
6271 set r [rowofcommit $targetid]
6272 if {$r != $targetrow} {
6273 # Fix up the scrollregion and change the scrolling position
6274 # now that our target row has moved.
6275 set diff [expr {($r - $targetrow) * $linespc}]
6278 set ymax [lindex [$canv cget -scrollregion] 3]
6281 set f0 [expr {$y0 / $ymax}]
6282 set f1 [expr {$y1 / $ymax}]
6283 allcanvs yview moveto $f0
6284 $cscroll set $f0 $f1
6285 set need_redisplay 1
6292 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6293 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6294 if {$endrow >= $vrowmod($curview)} {
6295 update_arcrows $curview
6297 if {$selectedline ne {} &&
6298 $row <= $selectedline && $selectedline <= $endrow} {
6299 set targetrow $selectedline
6300 } elseif {[info exists targetid]} {
6301 set targetrow [expr {int(($row + $endrow) / 2)}]
6303 if {[info exists targetrow]} {
6304 if {$targetrow >= $numcommits} {
6305 set targetrow [expr {$numcommits - 1}]
6307 set targetid [commitonrow $targetrow]
6309 drawcommits $row $endrow
6312 proc clear_display {} {
6313 global iddrawn linesegs need_redisplay nrows_drawn
6314 global vhighlights fhighlights nhighlights rhighlights
6315 global linehtag linentag linedtag boldids boldnameids
6318 catch {unset iddrawn}
6319 catch {unset linesegs}
6320 catch {unset linehtag}
6321 catch {unset linentag}
6322 catch {unset linedtag}
6325 catch {unset vhighlights}
6326 catch {unset fhighlights}
6327 catch {unset nhighlights}
6328 catch {unset rhighlights}
6329 set need_redisplay 0
6333 proc findcrossings {id} {
6334 global rowidlist parentlist numcommits displayorder
6338 foreach {s e} [rowranges $id] {
6339 if {$e >= $numcommits} {
6340 set e [expr {$numcommits - 1}]
6342 if {$e <= $s} continue
6343 for {set row $e} {[incr row -1] >= $s} {} {
6344 set x [lsearch -exact [lindex $rowidlist $row] $id]
6346 set olds [lindex $parentlist $row]
6347 set kid [lindex $displayorder $row]
6348 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6349 if {$kidx < 0} continue
6350 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6352 set px [lsearch -exact $nextrow $p]
6353 if {$px < 0} continue
6354 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6355 if {[lsearch -exact $ccross $p] >= 0} continue
6356 if {$x == $px + ($kidx < $px? -1: 1)} {
6358 } elseif {[lsearch -exact $cross $p] < 0} {
6365 return [concat $ccross {{}} $cross]
6368 proc assigncolor {id} {
6369 global colormap colors nextcolor
6370 global parents children children curview
6372 if {[info exists colormap($id)]} return
6373 set ncolors [llength $colors]
6374 if {[info exists children($curview,$id)]} {
6375 set kids $children($curview,$id)
6379 if {[llength $kids] == 1} {
6380 set child [lindex $kids 0]
6381 if {[info exists colormap($child)]
6382 && [llength $parents($curview,$child)] == 1} {
6383 set colormap($id) $colormap($child)
6389 foreach x [findcrossings $id] {
6391 # delimiter between corner crossings and other crossings
6392 if {[llength $badcolors] >= $ncolors - 1} break
6393 set origbad $badcolors
6395 if {[info exists colormap($x)]
6396 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6397 lappend badcolors $colormap($x)
6400 if {[llength $badcolors] >= $ncolors} {
6401 set badcolors $origbad
6403 set origbad $badcolors
6404 if {[llength $badcolors] < $ncolors - 1} {
6405 foreach child $kids {
6406 if {[info exists colormap($child)]
6407 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6408 lappend badcolors $colormap($child)
6410 foreach p $parents($curview,$child) {
6411 if {[info exists colormap($p)]
6412 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6413 lappend badcolors $colormap($p)
6417 if {[llength $badcolors] >= $ncolors} {
6418 set badcolors $origbad
6421 for {set i 0} {$i <= $ncolors} {incr i} {
6422 set c [lindex $colors $nextcolor]
6423 if {[incr nextcolor] >= $ncolors} {
6426 if {[lsearch -exact $badcolors $c]} break
6428 set colormap($id) $c
6431 proc bindline {t id} {
6434 $canv bind $t <Enter> "lineenter %x %y $id"
6435 $canv bind $t <Motion> "linemotion %x %y $id"
6436 $canv bind $t <Leave> "lineleave $id"
6437 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6440 proc graph_pane_width {} {
6444 set g [.tf.histframe.pwclist sashpos 0]
6446 set g [.tf.histframe.pwclist sash coord 0]
6448 return [lindex $g 0]
6451 proc totalwidth {l font extra} {
6454 set tot [expr {$tot + [font measure $font $str] + $extra}]
6459 proc drawtags {id x xt y1} {
6460 global idtags idheads idotherrefs mainhead
6461 global linespc lthickness
6462 global canv rowtextx curview fgcolor bgcolor ctxbut
6463 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6464 global tagbgcolor tagfgcolor tagoutlinecolor
6473 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6474 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6475 set extra [expr {$delta + $lthickness + $linespc}]
6477 if {[info exists idtags($id)]} {
6478 set marks $idtags($id)
6479 set ntags [llength $marks]
6480 if {$ntags > $maxtags ||
6481 [totalwidth $marks mainfont $extra] > $maxwidth} {
6482 # show just a single "n tags..." tag
6485 set marks [list "tag..."]
6487 set marks [list [format "%d tags..." $ntags]]
6492 if {[info exists idheads($id)]} {
6493 set marks [concat $marks $idheads($id)]
6494 set nheads [llength $idheads($id)]
6496 if {[info exists idotherrefs($id)]} {
6497 set marks [concat $marks $idotherrefs($id)]
6503 set yt [expr {$y1 - 0.5 * $linespc}]
6504 set yb [expr {$yt + $linespc - 1}]
6508 foreach tag $marks {
6510 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6511 set wid [font measure mainfontbold $tag]
6513 set wid [font measure mainfont $tag]
6517 set xt [expr {$xt + $wid + $extra}]
6519 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6520 -width $lthickness -fill $reflinecolor -tags tag.$id]
6522 foreach tag $marks x $xvals wid $wvals {
6523 set tag_quoted [string map {% %%} $tag]
6524 set xl [expr {$x + $delta}]
6525 set xr [expr {$x + $delta + $wid + $lthickness}]
6527 if {[incr ntags -1] >= 0} {
6529 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6530 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6531 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6534 set tagclick [list showtags $id 1]
6536 set tagclick [list showtag $tag_quoted 1]
6538 $canv bind $t <1> $tagclick
6539 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6541 # draw a head or other ref
6542 if {[incr nheads -1] >= 0} {
6543 set col $headbgcolor
6544 if {$tag eq $mainhead} {
6545 set font mainfontbold
6550 set xl [expr {$xl - $delta/2}]
6551 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6552 -width 1 -outline black -fill $col -tags tag.$id
6553 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6554 set rwid [font measure mainfont $remoteprefix]
6555 set xi [expr {$x + 1}]
6556 set yti [expr {$yt + 1}]
6557 set xri [expr {$x + $rwid}]
6558 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6559 -width 0 -fill $remotebgcolor -tags tag.$id
6562 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6563 -font $font -tags [list tag.$id text]]
6565 $canv bind $t <1> $tagclick
6566 } elseif {$nheads >= 0} {
6567 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6573 proc drawnotesign {xt y} {
6574 global linespc canv fgcolor
6576 set orad [expr {$linespc / 3}]
6577 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6578 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6579 -fill yellow -outline $fgcolor -width 1 -tags circle]
6580 set xt [expr {$xt + $orad * 3}]
6584 proc xcoord {i level ln} {
6585 global canvx0 xspc1 xspc2
6587 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6588 if {$i > 0 && $i == $level} {
6589 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6590 } elseif {$i > $level} {
6591 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6596 proc show_status {msg} {
6600 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6601 -tags text -fill $fgcolor
6604 # Don't change the text pane cursor if it is currently the hand cursor,
6605 # showing that we are over a sha1 ID link.
6606 proc settextcursor {c} {
6607 global ctext curtextcursor
6609 if {[$ctext cget -cursor] == $curtextcursor} {
6610 $ctext config -cursor $c
6612 set curtextcursor $c
6615 proc nowbusy {what {name {}}} {
6616 global isbusy busyname statusw
6618 if {[array names isbusy] eq {}} {
6619 . config -cursor watch
6623 set busyname($what) $name
6625 $statusw conf -text $name
6629 proc notbusy {what} {
6630 global isbusy maincursor textcursor busyname statusw
6634 if {$busyname($what) ne {} &&
6635 [$statusw cget -text] eq $busyname($what)} {
6636 $statusw conf -text {}
6639 if {[array names isbusy] eq {}} {
6640 . config -cursor $maincursor
6641 settextcursor $textcursor
6645 proc findmatches {f} {
6646 global findtype findstring
6647 if {$findtype == [mc "Regexp"]} {
6648 set matches [regexp -indices -all -inline $findstring $f]
6651 if {$findtype == [mc "IgnCase"]} {
6652 set f [string tolower $f]
6653 set fs [string tolower $fs]
6657 set l [string length $fs]
6658 while {[set j [string first $fs $f $i]] >= 0} {
6659 lappend matches [list $j [expr {$j+$l-1}]]
6660 set i [expr {$j + $l}]
6666 proc dofind {{dirn 1} {wrap 1}} {
6667 global findstring findstartline findcurline selectedline numcommits
6668 global gdttype filehighlight fh_serial find_dirn findallowwrap
6670 if {[info exists find_dirn]} {
6671 if {$find_dirn == $dirn} return
6675 if {$findstring eq {} || $numcommits == 0} return
6676 if {$selectedline eq {}} {
6677 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6679 set findstartline $selectedline
6681 set findcurline $findstartline
6682 nowbusy finding [mc "Searching"]
6683 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6684 after cancel do_file_hl $fh_serial
6685 do_file_hl $fh_serial
6688 set findallowwrap $wrap
6692 proc stopfinding {} {
6693 global find_dirn findcurline fprogcoord
6695 if {[info exists find_dirn]} {
6706 global commitdata commitinfo numcommits findpattern findloc
6707 global findstartline findcurline findallowwrap
6708 global find_dirn gdttype fhighlights fprogcoord
6709 global curview varcorder vrownum varccommits vrowmod
6711 if {![info exists find_dirn]} {
6714 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6717 if {$find_dirn > 0} {
6719 if {$l >= $numcommits} {
6722 if {$l <= $findstartline} {
6723 set lim [expr {$findstartline + 1}]
6726 set moretodo $findallowwrap
6733 if {$l >= $findstartline} {
6734 set lim [expr {$findstartline - 1}]
6737 set moretodo $findallowwrap
6740 set n [expr {($lim - $l) * $find_dirn}]
6745 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6746 update_arcrows $curview
6750 set ai [bsearch $vrownum($curview) $l]
6751 set a [lindex $varcorder($curview) $ai]
6752 set arow [lindex $vrownum($curview) $ai]
6753 set ids [lindex $varccommits($curview,$a)]
6754 set arowend [expr {$arow + [llength $ids]}]
6755 if {$gdttype eq [mc "containing:"]} {
6756 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6757 if {$l < $arow || $l >= $arowend} {
6759 set a [lindex $varcorder($curview) $ai]
6760 set arow [lindex $vrownum($curview) $ai]
6761 set ids [lindex $varccommits($curview,$a)]
6762 set arowend [expr {$arow + [llength $ids]}]
6764 set id [lindex $ids [expr {$l - $arow}]]
6765 # shouldn't happen unless git log doesn't give all the commits...
6766 if {![info exists commitdata($id)] ||
6767 ![doesmatch $commitdata($id)]} {
6770 if {![info exists commitinfo($id)]} {
6773 set info $commitinfo($id)
6774 foreach f $info ty $fldtypes {
6775 if {$ty eq ""} continue
6776 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6785 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6786 if {$l < $arow || $l >= $arowend} {
6788 set a [lindex $varcorder($curview) $ai]
6789 set arow [lindex $vrownum($curview) $ai]
6790 set ids [lindex $varccommits($curview,$a)]
6791 set arowend [expr {$arow + [llength $ids]}]
6793 set id [lindex $ids [expr {$l - $arow}]]
6794 if {![info exists fhighlights($id)]} {
6795 # this sets fhighlights($id) to -1
6796 askfilehighlight $l $id
6798 if {$fhighlights($id) > 0} {
6802 if {$fhighlights($id) < 0} {
6805 set findcurline [expr {$l - $find_dirn}]
6810 if {$found || ($domore && !$moretodo)} {
6826 set findcurline [expr {$l - $find_dirn}]
6828 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6832 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6837 proc findselectline {l} {
6838 global findloc commentend ctext findcurline markingmatches gdttype
6840 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6843 if {$markingmatches &&
6844 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6845 # highlight the matches in the comments
6846 set f [$ctext get 1.0 $commentend]
6847 set matches [findmatches $f]
6848 foreach match $matches {
6849 set start [lindex $match 0]
6850 set end [expr {[lindex $match 1] + 1}]
6851 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6857 # mark the bits of a headline or author that match a find string
6858 proc markmatches {canv l str tag matches font row} {
6861 set bbox [$canv bbox $tag]
6862 set x0 [lindex $bbox 0]
6863 set y0 [lindex $bbox 1]
6864 set y1 [lindex $bbox 3]
6865 foreach match $matches {
6866 set start [lindex $match 0]
6867 set end [lindex $match 1]
6868 if {$start > $end} continue
6869 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6870 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6871 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6872 [expr {$x0+$xlen+2}] $y1 \
6873 -outline {} -tags [list match$l matches] -fill yellow]
6875 if {$row == $selectedline} {
6876 $canv raise $t secsel
6881 proc unmarkmatches {} {
6882 global markingmatches
6884 allcanvs delete matches
6885 set markingmatches 0
6889 proc selcanvline {w x y} {
6890 global canv canvy0 ctext linespc
6892 set ymax [lindex [$canv cget -scrollregion] 3]
6893 if {$ymax == {}} return
6894 set yfrac [lindex [$canv yview] 0]
6895 set y [expr {$y + $yfrac * $ymax}]
6896 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6901 set xmax [lindex [$canv cget -scrollregion] 2]
6902 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6903 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6909 proc commit_descriptor {p} {
6911 if {![info exists commitinfo($p)]} {
6915 if {[llength $commitinfo($p)] > 1} {
6916 set l [lindex $commitinfo($p) 0]
6921 # append some text to the ctext widget, and make any SHA1 ID
6922 # that we know about be a clickable link.
6923 proc appendwithlinks {text tags} {
6924 global ctext linknum curview
6926 set start [$ctext index "end - 1c"]
6927 $ctext insert end $text $tags
6928 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6932 set linkid [string range $text $s $e]
6934 $ctext tag delete link$linknum
6935 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6936 setlink $linkid link$linknum
6941 proc setlink {id lk} {
6942 global curview ctext pendinglinks
6945 if {[string range $id 0 1] eq "-g"} {
6946 set id [string range $id 2 end]
6950 if {[string length $id] < 40} {
6951 set matches [longid $id]
6952 if {[llength $matches] > 0} {
6953 if {[llength $matches] > 1} return
6955 set id [lindex $matches 0]
6958 set known [commitinview $id $curview]
6961 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6962 $ctext tag bind $lk <1> [list selbyid $id]
6963 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6964 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6966 lappend pendinglinks($id) $lk
6967 interestedin $id {makelink %P}
6971 proc appendshortlink {id {pre {}} {post {}}} {
6972 global ctext linknum
6974 $ctext insert end $pre
6975 $ctext tag delete link$linknum
6976 $ctext insert end [string range $id 0 7] link$linknum
6977 $ctext insert end $post
6978 setlink $id link$linknum
6982 proc makelink {id} {
6985 if {![info exists pendinglinks($id)]} return
6986 foreach lk $pendinglinks($id) {
6989 unset pendinglinks($id)
6992 proc linkcursor {w inc} {
6993 global linkentercount curtextcursor
6995 if {[incr linkentercount $inc] > 0} {
6996 $w configure -cursor hand2
6998 $w configure -cursor $curtextcursor
6999 if {$linkentercount < 0} {
7000 set linkentercount 0
7005 proc viewnextline {dir} {
7009 set ymax [lindex [$canv cget -scrollregion] 3]
7010 set wnow [$canv yview]
7011 set wtop [expr {[lindex $wnow 0] * $ymax}]
7012 set newtop [expr {$wtop + $dir * $linespc}]
7015 } elseif {$newtop > $ymax} {
7018 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7021 # add a list of tag or branch names at position pos
7022 # returns the number of names inserted
7023 proc appendrefs {pos ids var} {
7024 global ctext linknum curview $var maxrefs mainheadid
7026 if {[catch {$ctext index $pos}]} {
7029 $ctext conf -state normal
7030 $ctext delete $pos "$pos lineend"
7033 foreach tag [set $var\($id\)] {
7034 lappend tags [list $tag $id]
7039 set tags [lsort -index 0 -decreasing $tags]
7042 if {[llength $tags] > $maxrefs} {
7043 # If we are displaying heads, and there are too many,
7044 # see if there are some important heads to display.
7045 # Currently this means "master" and the current head.
7047 if {$var eq "idheads"} {
7050 set hname [lindex $ti 0]
7051 set id [lindex $ti 1]
7052 if {($hname eq "master" || $id eq $mainheadid) &&
7053 [llength $itags] < $maxrefs} {
7062 set str [mc "and many more"]
7067 $ctext insert $pos "$str ([llength $tags])"
7068 set nutags [llength $tags]
7073 set id [lindex $ti 1]
7076 $ctext tag delete $lk
7077 $ctext insert $pos $sep
7078 $ctext insert $pos [lindex $ti 0] $lk
7082 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7083 $ctext conf -state disabled
7084 return [expr {[llength $tags] + $nutags}]
7087 # called when we have finished computing the nearby tags
7088 proc dispneartags {delay} {
7089 global selectedline currentid showneartags tagphase
7091 if {$selectedline eq {} || !$showneartags} return
7092 after cancel dispnexttag
7094 after 200 dispnexttag
7097 after idle dispnexttag
7102 proc dispnexttag {} {
7103 global selectedline currentid showneartags tagphase ctext
7105 if {$selectedline eq {} || !$showneartags} return
7106 switch -- $tagphase {
7108 set dtags [desctags $currentid]
7110 appendrefs precedes $dtags idtags
7114 set atags [anctags $currentid]
7116 appendrefs follows $atags idtags
7120 set dheads [descheads $currentid]
7121 if {$dheads ne {}} {
7122 if {[appendrefs branch $dheads idheads] > 1
7123 && [$ctext get "branch -3c"] eq "h"} {
7124 # turn "Branch" into "Branches"
7125 $ctext conf -state normal
7126 $ctext insert "branch -2c" "es"
7127 $ctext conf -state disabled
7132 if {[incr tagphase] <= 2} {
7133 after idle dispnexttag
7137 proc make_secsel {id} {
7138 global linehtag linentag linedtag canv canv2 canv3
7140 if {![info exists linehtag($id)]} return
7142 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7143 -tags secsel -fill [$canv cget -selectbackground]]
7145 $canv2 delete secsel
7146 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7147 -tags secsel -fill [$canv2 cget -selectbackground]]
7149 $canv3 delete secsel
7150 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7151 -tags secsel -fill [$canv3 cget -selectbackground]]
7155 proc make_idmark {id} {
7156 global linehtag canv fgcolor
7158 if {![info exists linehtag($id)]} return
7160 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7161 -tags markid -outline $fgcolor]
7165 proc selectline {l isnew {desired_loc {}}} {
7166 global canv ctext commitinfo selectedline
7167 global canvy0 linespc parents children curview
7168 global currentid sha1entry
7169 global commentend idtags linknum
7170 global mergemax numcommits pending_select
7171 global cmitmode showneartags allcommits
7172 global targetrow targetid lastscrollrows
7173 global autoselect autosellen jump_to_here
7176 catch {unset pending_select}
7181 if {$l < 0 || $l >= $numcommits} return
7182 set id [commitonrow $l]
7187 if {$lastscrollrows < $numcommits} {
7191 set y [expr {$canvy0 + $l * $linespc}]
7192 set ymax [lindex [$canv cget -scrollregion] 3]
7193 set ytop [expr {$y - $linespc - 1}]
7194 set ybot [expr {$y + $linespc + 1}]
7195 set wnow [$canv yview]
7196 set wtop [expr {[lindex $wnow 0] * $ymax}]
7197 set wbot [expr {[lindex $wnow 1] * $ymax}]
7198 set wh [expr {$wbot - $wtop}]
7200 if {$ytop < $wtop} {
7201 if {$ybot < $wtop} {
7202 set newtop [expr {$y - $wh / 2.0}]
7205 if {$newtop > $wtop - $linespc} {
7206 set newtop [expr {$wtop - $linespc}]
7209 } elseif {$ybot > $wbot} {
7210 if {$ytop > $wbot} {
7211 set newtop [expr {$y - $wh / 2.0}]
7213 set newtop [expr {$ybot - $wh}]
7214 if {$newtop < $wtop + $linespc} {
7215 set newtop [expr {$wtop + $linespc}]
7219 if {$newtop != $wtop} {
7223 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7230 addtohistory [list selbyid $id 0] savecmitpos
7233 $sha1entry delete 0 end
7234 $sha1entry insert 0 $id
7236 $sha1entry selection range 0 $autosellen
7240 $ctext conf -state normal
7243 if {![info exists commitinfo($id)]} {
7246 set info $commitinfo($id)
7247 set date [formatdate [lindex $info 2]]
7248 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7249 set date [formatdate [lindex $info 4]]
7250 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7251 if {[info exists idtags($id)]} {
7252 $ctext insert end [mc "Tags:"]
7253 foreach tag $idtags($id) {
7254 $ctext insert end " $tag"
7256 $ctext insert end "\n"
7260 set olds $parents($curview,$id)
7261 if {[llength $olds] > 1} {
7264 if {$np >= $mergemax} {
7269 $ctext insert end "[mc "Parent"]: " $tag
7270 appendwithlinks [commit_descriptor $p] {}
7275 append headers "[mc "Parent"]: [commit_descriptor $p]"
7279 foreach c $children($curview,$id) {
7280 append headers "[mc "Child"]: [commit_descriptor $c]"
7283 # make anything that looks like a SHA1 ID be a clickable link
7284 appendwithlinks $headers {}
7285 if {$showneartags} {
7286 if {![info exists allcommits]} {
7289 $ctext insert end "[mc "Branch"]: "
7290 $ctext mark set branch "end -1c"
7291 $ctext mark gravity branch left
7292 $ctext insert end "\n[mc "Follows"]: "
7293 $ctext mark set follows "end -1c"
7294 $ctext mark gravity follows left
7295 $ctext insert end "\n[mc "Precedes"]: "
7296 $ctext mark set precedes "end -1c"
7297 $ctext mark gravity precedes left
7298 $ctext insert end "\n"
7301 $ctext insert end "\n"
7302 set comment [lindex $info 5]
7303 if {[string first "\r" $comment] >= 0} {
7304 set comment [string map {"\r" "\n "} $comment]
7306 appendwithlinks $comment {comment}
7308 $ctext tag remove found 1.0 end
7309 $ctext conf -state disabled
7310 set commentend [$ctext index "end - 1c"]
7312 set jump_to_here $desired_loc
7313 init_flist [mc "Comments"]
7314 if {$cmitmode eq "tree"} {
7316 } elseif {$vinlinediff($curview) == 1} {
7318 } elseif {[llength $olds] <= 1} {
7325 proc selfirstline {} {
7330 proc sellastline {} {
7333 set l [expr {$numcommits - 1}]
7337 proc selnextline {dir} {
7340 if {$selectedline eq {}} return
7341 set l [expr {$selectedline + $dir}]
7346 proc selnextpage {dir} {
7347 global canv linespc selectedline numcommits
7349 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7353 allcanvs yview scroll [expr {$dir * $lpp}] units
7355 if {$selectedline eq {}} return
7356 set l [expr {$selectedline + $dir * $lpp}]
7359 } elseif {$l >= $numcommits} {
7360 set l [expr $numcommits - 1]
7366 proc unselectline {} {
7367 global selectedline currentid
7370 catch {unset currentid}
7371 allcanvs delete secsel
7375 proc reselectline {} {
7378 if {$selectedline ne {}} {
7379 selectline $selectedline 0
7383 proc addtohistory {cmd {saveproc {}}} {
7384 global history historyindex curview
7388 set elt [list $curview $cmd $saveproc {}]
7389 if {$historyindex > 0
7390 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7394 if {$historyindex < [llength $history]} {
7395 set history [lreplace $history $historyindex end $elt]
7397 lappend history $elt
7400 if {$historyindex > 1} {
7401 .tf.bar.leftbut conf -state normal
7403 .tf.bar.leftbut conf -state disabled
7405 .tf.bar.rightbut conf -state disabled
7408 # save the scrolling position of the diff display pane
7409 proc save_position {} {
7410 global historyindex history
7412 if {$historyindex < 1} return
7413 set hi [expr {$historyindex - 1}]
7414 set fn [lindex $history $hi 2]
7416 lset history $hi 3 [eval $fn]
7420 proc unset_posvars {} {
7423 if {[info exists last_posvars]} {
7424 foreach {var val} $last_posvars {
7433 global curview last_posvars
7435 set view [lindex $elt 0]
7436 set cmd [lindex $elt 1]
7437 set pv [lindex $elt 3]
7438 if {$curview != $view} {
7442 foreach {var val} $pv {
7446 set last_posvars $pv
7451 global history historyindex
7454 if {$historyindex > 1} {
7456 incr historyindex -1
7457 godo [lindex $history [expr {$historyindex - 1}]]
7458 .tf.bar.rightbut conf -state normal
7460 if {$historyindex <= 1} {
7461 .tf.bar.leftbut conf -state disabled
7466 global history historyindex
7469 if {$historyindex < [llength $history]} {
7471 set cmd [lindex $history $historyindex]
7474 .tf.bar.leftbut conf -state normal
7476 if {$historyindex >= [llength $history]} {
7477 .tf.bar.rightbut conf -state disabled
7482 global treefilelist treeidlist diffids diffmergeid treepending
7483 global nullid nullid2
7486 catch {unset diffmergeid}
7487 if {![info exists treefilelist($id)]} {
7488 if {![info exists treepending]} {
7489 if {$id eq $nullid} {
7490 set cmd [list | git ls-files]
7491 } elseif {$id eq $nullid2} {
7492 set cmd [list | git ls-files --stage -t]
7494 set cmd [list | git ls-tree -r $id]
7496 if {[catch {set gtf [open $cmd r]}]} {
7500 set treefilelist($id) {}
7501 set treeidlist($id) {}
7502 fconfigure $gtf -blocking 0 -encoding binary
7503 filerun $gtf [list gettreeline $gtf $id]
7510 proc gettreeline {gtf id} {
7511 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7514 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7515 if {$diffids eq $nullid} {
7518 set i [string first "\t" $line]
7519 if {$i < 0} continue
7520 set fname [string range $line [expr {$i+1}] end]
7521 set line [string range $line 0 [expr {$i-1}]]
7522 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7523 set sha1 [lindex $line 2]
7524 lappend treeidlist($id) $sha1
7526 if {[string index $fname 0] eq "\""} {
7527 set fname [lindex $fname 0]
7529 set fname [encoding convertfrom $fname]
7530 lappend treefilelist($id) $fname
7533 return [expr {$nl >= 1000? 2: 1}]
7537 if {$cmitmode ne "tree"} {
7538 if {![info exists diffmergeid]} {
7539 gettreediffs $diffids
7541 } elseif {$id ne $diffids} {
7550 global treefilelist treeidlist diffids nullid nullid2
7551 global ctext_file_names ctext_file_lines
7552 global ctext commentend
7554 set i [lsearch -exact $treefilelist($diffids) $f]
7556 puts "oops, $f not in list for id $diffids"
7559 if {$diffids eq $nullid} {
7560 if {[catch {set bf [open $f r]} err]} {
7561 puts "oops, can't read $f: $err"
7565 set blob [lindex $treeidlist($diffids) $i]
7566 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7567 puts "oops, error reading blob $blob: $err"
7571 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7572 filerun $bf [list getblobline $bf $diffids]
7573 $ctext config -state normal
7574 clear_ctext $commentend
7575 lappend ctext_file_names $f
7576 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7577 $ctext insert end "\n"
7578 $ctext insert end "$f\n" filesep
7579 $ctext config -state disabled
7580 $ctext yview $commentend
7584 proc getblobline {bf id} {
7585 global diffids cmitmode ctext
7587 if {$id ne $diffids || $cmitmode ne "tree"} {
7591 $ctext config -state normal
7593 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7594 $ctext insert end "$line\n"
7597 global jump_to_here ctext_file_names commentend
7599 # delete last newline
7600 $ctext delete "end - 2c" "end - 1c"
7602 if {$jump_to_here ne {} &&
7603 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7604 set lnum [expr {[lindex $jump_to_here 1] +
7605 [lindex [split $commentend .] 0]}]
7606 mark_ctext_line $lnum
7608 $ctext config -state disabled
7611 $ctext config -state disabled
7612 return [expr {$nl >= 1000? 2: 1}]
7615 proc mark_ctext_line {lnum} {
7616 global ctext markbgcolor
7618 $ctext tag delete omark
7619 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7620 $ctext tag conf omark -background $markbgcolor
7624 proc mergediff {id} {
7626 global diffids treediffs
7627 global parents curview
7631 set treediffs($id) {}
7632 set np [llength $parents($curview,$id)]
7637 proc startdiff {ids} {
7638 global treediffs diffids treepending diffmergeid nullid nullid2
7642 catch {unset diffmergeid}
7643 if {![info exists treediffs($ids)] ||
7644 [lsearch -exact $ids $nullid] >= 0 ||
7645 [lsearch -exact $ids $nullid2] >= 0} {
7646 if {![info exists treepending]} {
7654 proc showinlinediff {ids} {
7655 global commitinfo commitdata ctext
7658 set info $commitinfo($ids)
7659 set diff [lindex $info 7]
7660 set difflines [split $diff "\n"]
7666 foreach line $difflines {
7667 if {![string compare -length 5 "diff " $line]} {
7669 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7670 # offset also accounts for the b/ prefix
7671 lappend treediff [string range $line 6 end]
7676 set treediffs($ids) $treediff
7679 $ctext conf -state normal
7680 foreach line $difflines {
7681 parseblobdiffline $ids $line
7683 maybe_scroll_ctext 1
7684 $ctext conf -state disabled
7687 # If the filename (name) is under any of the passed filter paths
7688 # then return true to include the file in the listing.
7689 proc path_filter {filter name} {
7690 set worktree [gitworktree]
7692 set fq_p [file normalize $p]
7693 set fq_n [file normalize [file join $worktree $name]]
7694 if {[string match [file normalize $fq_p]* $fq_n]} {
7701 proc addtocflist {ids} {
7704 add_flist $treediffs($ids)
7708 proc diffcmd {ids flags} {
7709 global log_showroot nullid nullid2
7711 set i [lsearch -exact $ids $nullid]
7712 set j [lsearch -exact $ids $nullid2]
7714 if {[llength $ids] > 1 && $j < 0} {
7715 # comparing working directory with some specific revision
7716 set cmd [concat | git diff-index $flags]
7718 lappend cmd -R [lindex $ids 1]
7720 lappend cmd [lindex $ids 0]
7723 # comparing working directory with index
7724 set cmd [concat | git diff-files $flags]
7729 } elseif {$j >= 0} {
7730 set cmd [concat | git diff-index --cached $flags]
7731 if {[llength $ids] > 1} {
7732 # comparing index with specific revision
7734 lappend cmd -R [lindex $ids 1]
7736 lappend cmd [lindex $ids 0]
7739 # comparing index with HEAD
7743 if {$log_showroot} {
7744 lappend flags --root
7746 set cmd [concat | git diff-tree -r $flags $ids]
7751 proc gettreediffs {ids} {
7752 global treediff treepending limitdiffs vfilelimit curview
7754 set cmd [diffcmd $ids {--no-commit-id}]
7755 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7756 set cmd [concat $cmd -- $vfilelimit($curview)]
7758 if {[catch {set gdtf [open $cmd r]}]} return
7760 set treepending $ids
7762 fconfigure $gdtf -blocking 0 -encoding binary
7763 filerun $gdtf [list gettreediffline $gdtf $ids]
7766 proc gettreediffline {gdtf ids} {
7767 global treediff treediffs treepending diffids diffmergeid
7768 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7773 if {$perfile_attrs} {
7774 # cache_gitattr is slow, and even slower on win32 where we
7775 # have to invoke it for only about 30 paths at a time
7777 if {[tk windowingsystem] == "win32"} {
7781 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7782 set i [string first "\t" $line]
7784 set file [string range $line [expr {$i+1}] end]
7785 if {[string index $file 0] eq "\""} {
7786 set file [lindex $file 0]
7788 set file [encoding convertfrom $file]
7789 if {$file ne [lindex $treediff end]} {
7790 lappend treediff $file
7791 lappend sublist $file
7795 if {$perfile_attrs} {
7796 cache_gitattr encoding $sublist
7799 return [expr {$nr >= $max? 2: 1}]
7802 set treediffs($ids) $treediff
7804 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7806 } elseif {$ids != $diffids} {
7807 if {![info exists diffmergeid]} {
7808 gettreediffs $diffids
7816 # empty string or positive integer
7817 proc diffcontextvalidate {v} {
7818 return [regexp {^(|[1-9][0-9]*)$} $v]
7821 proc diffcontextchange {n1 n2 op} {
7822 global diffcontextstring diffcontext
7824 if {[string is integer -strict $diffcontextstring]} {
7825 if {$diffcontextstring >= 0} {
7826 set diffcontext $diffcontextstring
7832 proc changeignorespace {} {
7836 proc changeworddiff {name ix op} {
7840 proc initblobdiffvars {} {
7841 global diffencoding targetline diffnparents
7842 global diffinhdr currdiffsubmod diffseehere
7846 set diffencoding [get_path_encoding {}]
7847 set currdiffsubmod ""
7851 proc getblobdiffs {ids} {
7852 global blobdifffd diffids env
7857 global limitdiffs vfilelimit curview
7861 if {[package vcompare $git_version "1.6.1"] >= 0} {
7862 set textconv "--textconv"
7865 if {[package vcompare $git_version "1.6.6"] >= 0} {
7866 set submodule "--submodule"
7868 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7872 if {$worddiff ne [mc "Line diff"]} {
7873 append cmd " --word-diff=porcelain"
7875 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7876 set cmd [concat $cmd -- $vfilelimit($curview)]
7878 if {[catch {set bdf [open $cmd r]} err]} {
7879 error_popup [mc "Error getting diffs: %s" $err]
7882 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7883 set blobdifffd($ids) $bdf
7885 filerun $bdf [list getblobdiffline $bdf $diffids]
7888 proc savecmitpos {} {
7889 global ctext cmitmode
7891 if {$cmitmode eq "tree"} {
7894 return [list target_scrollpos [$ctext index @0,0]]
7897 proc savectextpos {} {
7900 return [list target_scrollpos [$ctext index @0,0]]
7903 proc maybe_scroll_ctext {ateof} {
7904 global ctext target_scrollpos
7906 if {![info exists target_scrollpos]} return
7908 set nlines [expr {[winfo height $ctext]
7909 / [font metrics textfont -linespace]}]
7910 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7912 $ctext yview $target_scrollpos
7913 unset target_scrollpos
7916 proc setinlist {var i val} {
7919 while {[llength [set $var]] < $i} {
7922 if {[llength [set $var]] == $i} {
7929 proc makediffhdr {fname ids} {
7930 global ctext curdiffstart treediffs diffencoding
7931 global ctext_file_names jump_to_here targetline diffline
7933 set fname [encoding convertfrom $fname]
7934 set diffencoding [get_path_encoding $fname]
7935 set i [lsearch -exact $treediffs($ids) $fname]
7937 setinlist difffilestart $i $curdiffstart
7939 lset ctext_file_names end $fname
7940 set l [expr {(78 - [string length $fname]) / 2}]
7941 set pad [string range "----------------------------------------" 1 $l]
7942 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7944 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7945 set targetline [lindex $jump_to_here 1]
7950 proc blobdiffmaybeseehere {ateof} {
7952 if {$diffseehere >= 0} {
7953 mark_ctext_line [lindex [split $diffseehere .] 0]
7955 maybe_scroll_ctext $ateof
7958 proc getblobdiffline {bdf ids} {
7959 global diffids blobdifffd
7963 $ctext conf -state normal
7964 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7965 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7969 parseblobdiffline $ids $line
7971 $ctext conf -state disabled
7972 blobdiffmaybeseehere [eof $bdf]
7977 return [expr {$nr >= 1000? 2: 1}]
7980 proc parseblobdiffline {ids line} {
7981 global ctext curdiffstart
7982 global diffnexthead diffnextnote difffilestart
7983 global ctext_file_names ctext_file_lines
7984 global diffinhdr treediffs mergemax diffnparents
7985 global diffencoding jump_to_here targetline diffline currdiffsubmod
7986 global worddiff diffseehere
7988 if {![string compare -length 5 "diff " $line]} {
7989 if {![regexp {^diff (--cc|--git) } $line m type]} {
7990 set line [encoding convertfrom $line]
7991 $ctext insert end "$line\n" hunksep
7994 # start of a new file
7996 $ctext insert end "\n"
7997 set curdiffstart [$ctext index "end - 1c"]
7998 lappend ctext_file_names ""
7999 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8000 $ctext insert end "\n" filesep
8002 if {$type eq "--cc"} {
8003 # start of a new file in a merge diff
8004 set fname [string range $line 10 end]
8005 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
8006 lappend treediffs($ids) $fname
8007 add_flist [list $fname]
8011 set line [string range $line 11 end]
8012 # If the name hasn't changed the length will be odd,
8013 # the middle char will be a space, and the two bits either
8014 # side will be a/name and b/name, or "a/name" and "b/name".
8015 # If the name has changed we'll get "rename from" and
8016 # "rename to" or "copy from" and "copy to" lines following
8017 # this, and we'll use them to get the filenames.
8018 # This complexity is necessary because spaces in the
8019 # filename(s) don't get escaped.
8020 set l [string length $line]
8021 set i [expr {$l / 2}]
8022 if {!(($l & 1) && [string index $line $i] eq " " &&
8023 [string range $line 2 [expr {$i - 1}]] eq \
8024 [string range $line [expr {$i + 3}] end])} {
8027 # unescape if quoted and chop off the a/ from the front
8028 if {[string index $line 0] eq "\""} {
8029 set fname [string range [lindex $line 0] 2 end]
8031 set fname [string range $line 2 [expr {$i - 1}]]
8034 makediffhdr $fname $ids
8036 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8037 set fname [encoding convertfrom [string range $line 16 end]]
8038 $ctext insert end "\n"
8039 set curdiffstart [$ctext index "end - 1c"]
8040 lappend ctext_file_names $fname
8041 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8042 $ctext insert end "$line\n" filesep
8043 set i [lsearch -exact $treediffs($ids) $fname]
8045 setinlist difffilestart $i $curdiffstart
8048 } elseif {![string compare -length 2 "@@" $line]} {
8049 regexp {^@@+} $line ats
8050 set line [encoding convertfrom $diffencoding $line]
8051 $ctext insert end "$line\n" hunksep
8052 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8055 set diffnparents [expr {[string length $ats] - 1}]
8058 } elseif {![string compare -length 10 "Submodule " $line]} {
8059 # start of a new submodule
8060 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8061 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8063 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8065 if {$currdiffsubmod != $fname} {
8066 $ctext insert end "\n"; # Add newline after commit message
8068 set curdiffstart [$ctext index "end - 1c"]
8069 lappend ctext_file_names ""
8070 if {$currdiffsubmod != $fname} {
8071 lappend ctext_file_lines $fname
8072 makediffhdr $fname $ids
8073 set currdiffsubmod $fname
8074 $ctext insert end "\n$line\n" filesep
8076 $ctext insert end "$line\n" filesep
8078 } elseif {![string compare -length 3 " >" $line]} {
8079 set $currdiffsubmod ""
8080 set line [encoding convertfrom $diffencoding $line]
8081 $ctext insert end "$line\n" dresult
8082 } elseif {![string compare -length 3 " <" $line]} {
8083 set $currdiffsubmod ""
8084 set line [encoding convertfrom $diffencoding $line]
8085 $ctext insert end "$line\n" d0
8086 } elseif {$diffinhdr} {
8087 if {![string compare -length 12 "rename from " $line]} {
8088 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8089 if {[string index $fname 0] eq "\""} {
8090 set fname [lindex $fname 0]
8092 set fname [encoding convertfrom $fname]
8093 set i [lsearch -exact $treediffs($ids) $fname]
8095 setinlist difffilestart $i $curdiffstart
8097 } elseif {![string compare -length 10 $line "rename to "] ||
8098 ![string compare -length 8 $line "copy to "]} {
8099 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8100 if {[string index $fname 0] eq "\""} {
8101 set fname [lindex $fname 0]
8103 makediffhdr $fname $ids
8104 } elseif {[string compare -length 3 $line "---"] == 0} {
8107 } elseif {[string compare -length 3 $line "+++"] == 0} {
8111 $ctext insert end "$line\n" filesep
8114 set line [string map {\x1A ^Z} \
8115 [encoding convertfrom $diffencoding $line]]
8116 # parse the prefix - one ' ', '-' or '+' for each parent
8117 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8118 set tag [expr {$diffnparents > 1? "m": "d"}]
8119 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8120 set words_pre_markup ""
8121 set words_post_markup ""
8122 if {[string trim $prefix " -+"] eq {}} {
8123 # prefix only has " ", "-" and "+" in it: normal diff line
8124 set num [string first "-" $prefix]
8126 set line [string range $line 1 end]
8129 # removed line, first parent with line is $num
8130 if {$num >= $mergemax} {
8133 if {$dowords && $worddiff eq [mc "Markup words"]} {
8134 $ctext insert end "\[-$line-\]" $tag$num
8136 $ctext insert end "$line" $tag$num
8139 $ctext insert end "\n" $tag$num
8143 if {[string first "+" $prefix] >= 0} {
8145 lappend tags ${tag}result
8146 if {$diffnparents > 1} {
8147 set num [string first " " $prefix]
8149 if {$num >= $mergemax} {
8155 set words_pre_markup "{+"
8156 set words_post_markup "+}"
8158 if {$targetline ne {}} {
8159 if {$diffline == $targetline} {
8160 set diffseehere [$ctext index "end - 1 chars"]
8166 if {$dowords && $worddiff eq [mc "Markup words"]} {
8167 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8169 $ctext insert end "$line" $tags
8172 $ctext insert end "\n" $tags
8175 } elseif {$dowords && $prefix eq "~"} {
8176 $ctext insert end "\n" {}
8178 # "\ No newline at end of file",
8179 # or something else we don't recognize
8180 $ctext insert end "$line\n" hunksep
8185 proc changediffdisp {} {
8186 global ctext diffelide
8188 $ctext tag conf d0 -elide [lindex $diffelide 0]
8189 $ctext tag conf dresult -elide [lindex $diffelide 1]
8192 proc highlightfile {cline} {
8193 global cflist cflist_top
8195 if {![info exists cflist_top]} return
8197 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8198 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8199 $cflist see $cline.0
8200 set cflist_top $cline
8203 proc highlightfile_for_scrollpos {topidx} {
8204 global cmitmode difffilestart
8206 if {$cmitmode eq "tree"} return
8207 if {![info exists difffilestart]} return
8209 set top [lindex [split $topidx .] 0]
8210 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8213 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8218 global difffilestart ctext cmitmode
8220 if {$cmitmode eq "tree"} return
8222 set here [$ctext index @0,0]
8223 foreach loc $difffilestart {
8224 if {[$ctext compare $loc >= $here]} {
8234 global difffilestart ctext cmitmode
8236 if {$cmitmode eq "tree"} return
8237 set here [$ctext index @0,0]
8238 foreach loc $difffilestart {
8239 if {[$ctext compare $loc > $here]} {
8246 proc clear_ctext {{first 1.0}} {
8247 global ctext smarktop smarkbot
8248 global ctext_file_names ctext_file_lines
8251 set l [lindex [split $first .] 0]
8252 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8255 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8258 $ctext delete $first end
8259 if {$first eq "1.0"} {
8260 catch {unset pendinglinks}
8262 set ctext_file_names {}
8263 set ctext_file_lines {}
8266 proc settabs {{firstab {}}} {
8267 global firsttabstop tabstop ctext have_tk85
8269 if {$firstab ne {} && $have_tk85} {
8270 set firsttabstop $firstab
8272 set w [font measure textfont "0"]
8273 if {$firsttabstop != 0} {
8274 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8275 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8276 } elseif {$have_tk85 || $tabstop != 8} {
8277 $ctext conf -tabs [expr {$tabstop * $w}]
8279 $ctext conf -tabs {}
8283 proc incrsearch {name ix op} {
8284 global ctext searchstring searchdirn
8286 if {[catch {$ctext index anchor}]} {
8287 # no anchor set, use start of selection, or of visible area
8288 set sel [$ctext tag ranges sel]
8290 $ctext mark set anchor [lindex $sel 0]
8291 } elseif {$searchdirn eq "-forwards"} {
8292 $ctext mark set anchor @0,0
8294 $ctext mark set anchor @0,[winfo height $ctext]
8297 if {$searchstring ne {}} {
8298 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8301 set mend "$here + $mlen c"
8302 $ctext tag remove sel 1.0 end
8303 $ctext tag add sel $here $mend
8304 suppress_highlighting_file_for_current_scrollpos
8305 highlightfile_for_scrollpos $here
8308 rehighlight_search_results
8312 global sstring ctext searchstring searchdirn
8315 $sstring icursor end
8316 set searchdirn -forwards
8317 if {$searchstring ne {}} {
8318 set sel [$ctext tag ranges sel]
8320 set start "[lindex $sel 0] + 1c"
8321 } elseif {[catch {set start [$ctext index anchor]}]} {
8324 set match [$ctext search -count mlen -- $searchstring $start]
8325 $ctext tag remove sel 1.0 end
8331 suppress_highlighting_file_for_current_scrollpos
8332 highlightfile_for_scrollpos $match
8333 set mend "$match + $mlen c"
8334 $ctext tag add sel $match $mend
8335 $ctext mark unset anchor
8336 rehighlight_search_results
8340 proc dosearchback {} {
8341 global sstring ctext searchstring searchdirn
8344 $sstring icursor end
8345 set searchdirn -backwards
8346 if {$searchstring ne {}} {
8347 set sel [$ctext tag ranges sel]
8349 set start [lindex $sel 0]
8350 } elseif {[catch {set start [$ctext index anchor]}]} {
8351 set start @0,[winfo height $ctext]
8353 set match [$ctext search -backwards -count ml -- $searchstring $start]
8354 $ctext tag remove sel 1.0 end
8360 suppress_highlighting_file_for_current_scrollpos
8361 highlightfile_for_scrollpos $match
8362 set mend "$match + $ml c"
8363 $ctext tag add sel $match $mend
8364 $ctext mark unset anchor
8365 rehighlight_search_results
8369 proc rehighlight_search_results {} {
8370 global ctext searchstring
8372 $ctext tag remove found 1.0 end
8373 $ctext tag remove currentsearchhit 1.0 end
8375 if {$searchstring ne {}} {
8380 proc searchmark {first last} {
8381 global ctext searchstring
8383 set sel [$ctext tag ranges sel]
8387 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8388 if {$match eq {}} break
8389 set mend "$match + $mlen c"
8390 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8391 $ctext tag add currentsearchhit $match $mend
8393 $ctext tag add found $match $mend
8398 proc searchmarkvisible {doall} {
8399 global ctext smarktop smarkbot
8401 set topline [lindex [split [$ctext index @0,0] .] 0]
8402 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8403 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8404 # no overlap with previous
8405 searchmark $topline $botline
8406 set smarktop $topline
8407 set smarkbot $botline
8409 if {$topline < $smarktop} {
8410 searchmark $topline [expr {$smarktop-1}]
8411 set smarktop $topline
8413 if {$botline > $smarkbot} {
8414 searchmark [expr {$smarkbot+1}] $botline
8415 set smarkbot $botline
8420 proc suppress_highlighting_file_for_current_scrollpos {} {
8421 global ctext suppress_highlighting_file_for_this_scrollpos
8423 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8426 proc scrolltext {f0 f1} {
8427 global searchstring cmitmode ctext
8428 global suppress_highlighting_file_for_this_scrollpos
8430 set topidx [$ctext index @0,0]
8431 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8432 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8433 highlightfile_for_scrollpos $topidx
8436 catch {unset suppress_highlighting_file_for_this_scrollpos}
8438 .bleft.bottom.sb set $f0 $f1
8439 if {$searchstring ne {}} {
8445 global linespc charspc canvx0 canvy0
8446 global xspc1 xspc2 lthickness
8448 set linespc [font metrics mainfont -linespace]
8449 set charspc [font measure mainfont "m"]
8450 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8451 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8452 set lthickness [expr {int($linespc / 9) + 1}]
8453 set xspc1(0) $linespc
8461 set ymax [lindex [$canv cget -scrollregion] 3]
8462 if {$ymax eq {} || $ymax == 0} return
8463 set span [$canv yview]
8466 allcanvs yview moveto [lindex $span 0]
8468 if {$selectedline ne {}} {
8469 selectline $selectedline 0
8470 allcanvs yview moveto [lindex $span 0]
8474 proc parsefont {f n} {
8477 set fontattr($f,family) [lindex $n 0]
8479 if {$s eq {} || $s == 0} {
8482 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8484 set fontattr($f,size) $s
8485 set fontattr($f,weight) normal
8486 set fontattr($f,slant) roman
8487 foreach style [lrange $n 2 end] {
8490 "bold" {set fontattr($f,weight) $style}
8492 "italic" {set fontattr($f,slant) $style}
8497 proc fontflags {f {isbold 0}} {
8500 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8501 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8502 -slant $fontattr($f,slant)]
8508 set n [list $fontattr($f,family) $fontattr($f,size)]
8509 if {$fontattr($f,weight) eq "bold"} {
8512 if {$fontattr($f,slant) eq "italic"} {
8518 proc incrfont {inc} {
8519 global mainfont textfont ctext canv cflist showrefstop
8520 global stopped entries fontattr
8523 set s $fontattr(mainfont,size)
8528 set fontattr(mainfont,size) $s
8529 font config mainfont -size $s
8530 font config mainfontbold -size $s
8531 set mainfont [fontname mainfont]
8532 set s $fontattr(textfont,size)
8537 set fontattr(textfont,size) $s
8538 font config textfont -size $s
8539 font config textfontbold -size $s
8540 set textfont [fontname textfont]
8547 global sha1entry sha1string
8548 if {[string length $sha1string] == 40} {
8549 $sha1entry delete 0 end
8553 proc sha1change {n1 n2 op} {
8554 global sha1string currentid sha1but
8555 if {$sha1string == {}
8556 || ([info exists currentid] && $sha1string == $currentid)} {
8561 if {[$sha1but cget -state] == $state} return
8562 if {$state == "normal"} {
8563 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8565 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8569 proc gotocommit {} {
8570 global sha1string tagids headids curview varcid
8572 if {$sha1string == {}
8573 || ([info exists currentid] && $sha1string == $currentid)} return
8574 if {[info exists tagids($sha1string)]} {
8575 set id $tagids($sha1string)
8576 } elseif {[info exists headids($sha1string)]} {
8577 set id $headids($sha1string)
8579 set id [string tolower $sha1string]
8580 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8581 set matches [longid $id]
8582 if {$matches ne {}} {
8583 if {[llength $matches] > 1} {
8584 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8587 set id [lindex $matches 0]
8590 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8591 error_popup [mc "Revision %s is not known" $sha1string]
8596 if {[commitinview $id $curview]} {
8597 selectline [rowofcommit $id] 1
8600 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8601 set msg [mc "SHA1 id %s is not known" $sha1string]
8603 set msg [mc "Revision %s is not in the current view" $sha1string]
8608 proc lineenter {x y id} {
8609 global hoverx hovery hoverid hovertimer
8610 global commitinfo canv
8612 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8616 if {[info exists hovertimer]} {
8617 after cancel $hovertimer
8619 set hovertimer [after 500 linehover]
8623 proc linemotion {x y id} {
8624 global hoverx hovery hoverid hovertimer
8626 if {[info exists hoverid] && $id == $hoverid} {
8629 if {[info exists hovertimer]} {
8630 after cancel $hovertimer
8632 set hovertimer [after 500 linehover]
8636 proc lineleave {id} {
8637 global hoverid hovertimer canv
8639 if {[info exists hoverid] && $id == $hoverid} {
8641 if {[info exists hovertimer]} {
8642 after cancel $hovertimer
8650 global hoverx hovery hoverid hovertimer
8651 global canv linespc lthickness
8652 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8656 set text [lindex $commitinfo($hoverid) 0]
8657 set ymax [lindex [$canv cget -scrollregion] 3]
8658 if {$ymax == {}} return
8659 set yfrac [lindex [$canv yview] 0]
8660 set x [expr {$hoverx + 2 * $linespc}]
8661 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8662 set x0 [expr {$x - 2 * $lthickness}]
8663 set y0 [expr {$y - 2 * $lthickness}]
8664 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8665 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8666 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8667 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8668 -width 1 -tags hover]
8670 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8671 -font mainfont -fill $linehoverfgcolor]
8675 proc clickisonarrow {id y} {
8678 set ranges [rowranges $id]
8679 set thresh [expr {2 * $lthickness + 6}]
8680 set n [expr {[llength $ranges] - 1}]
8681 for {set i 1} {$i < $n} {incr i} {
8682 set row [lindex $ranges $i]
8683 if {abs([yc $row] - $y) < $thresh} {
8690 proc arrowjump {id n y} {
8693 # 1 <-> 2, 3 <-> 4, etc...
8694 set n [expr {(($n - 1) ^ 1) + 1}]
8695 set row [lindex [rowranges $id] $n]
8697 set ymax [lindex [$canv cget -scrollregion] 3]
8698 if {$ymax eq {} || $ymax <= 0} return
8699 set view [$canv yview]
8700 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8701 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8705 allcanvs yview moveto $yfrac
8708 proc lineclick {x y id isnew} {
8709 global ctext commitinfo children canv thickerline curview
8711 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8716 # draw this line thicker than normal
8720 set ymax [lindex [$canv cget -scrollregion] 3]
8721 if {$ymax eq {}} return
8722 set yfrac [lindex [$canv yview] 0]
8723 set y [expr {$y + $yfrac * $ymax}]
8725 set dirn [clickisonarrow $id $y]
8727 arrowjump $id $dirn $y
8732 addtohistory [list lineclick $x $y $id 0] savectextpos
8734 # fill the details pane with info about this line
8735 $ctext conf -state normal
8738 $ctext insert end "[mc "Parent"]:\t"
8739 $ctext insert end $id link0
8741 set info $commitinfo($id)
8742 $ctext insert end "\n\t[lindex $info 0]\n"
8743 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8744 set date [formatdate [lindex $info 2]]
8745 $ctext insert end "\t[mc "Date"]:\t$date\n"
8746 set kids $children($curview,$id)
8748 $ctext insert end "\n[mc "Children"]:"
8750 foreach child $kids {
8752 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8753 set info $commitinfo($child)
8754 $ctext insert end "\n\t"
8755 $ctext insert end $child link$i
8756 setlink $child link$i
8757 $ctext insert end "\n\t[lindex $info 0]"
8758 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8759 set date [formatdate [lindex $info 2]]
8760 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8763 maybe_scroll_ctext 1
8764 $ctext conf -state disabled
8768 proc normalline {} {
8770 if {[info exists thickerline]} {
8777 proc selbyid {id {isnew 1}} {
8779 if {[commitinview $id $curview]} {
8780 selectline [rowofcommit $id] $isnew
8786 if {![info exists startmstime]} {
8787 set startmstime [clock clicks -milliseconds]
8789 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8792 proc rowmenu {x y id} {
8793 global rowctxmenu selectedline rowmenuid curview
8794 global nullid nullid2 fakerowmenu mainhead markedid
8798 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8803 if {[info exists markedid] && $markedid ne $id} {
8808 if {$id ne $nullid && $id ne $nullid2} {
8809 set menu $rowctxmenu
8810 if {$mainhead ne {}} {
8811 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8813 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8815 $menu entryconfigure 9 -state $mstate
8816 $menu entryconfigure 10 -state $mstate
8817 $menu entryconfigure 11 -state $mstate
8819 set menu $fakerowmenu
8821 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8822 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8823 $menu entryconfigure [mca "Make patch"] -state $state
8824 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8825 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8826 tk_popup $menu $x $y
8830 global rowmenuid markedid canv
8832 set markedid $rowmenuid
8833 make_idmark $markedid
8839 if {[info exists markedid]} {
8844 proc replace_by_kids {l r} {
8845 global curview children
8847 set id [commitonrow $r]
8848 set l [lreplace $l 0 0]
8849 foreach kid $children($curview,$id) {
8850 lappend l [rowofcommit $kid]
8852 return [lsort -integer -decreasing -unique $l]
8855 proc find_common_desc {} {
8856 global markedid rowmenuid curview children
8858 if {![info exists markedid]} return
8859 if {![commitinview $markedid $curview] ||
8860 ![commitinview $rowmenuid $curview]} return
8861 #set t1 [clock clicks -milliseconds]
8862 set l1 [list [rowofcommit $markedid]]
8863 set l2 [list [rowofcommit $rowmenuid]]
8865 set r1 [lindex $l1 0]
8866 set r2 [lindex $l2 0]
8867 if {$r1 eq {} || $r2 eq {}} break
8873 set l1 [replace_by_kids $l1 $r1]
8875 set l2 [replace_by_kids $l2 $r2]
8878 #set t2 [clock clicks -milliseconds]
8879 #puts "took [expr {$t2-$t1}]ms"
8882 proc compare_commits {} {
8883 global markedid rowmenuid curview children
8885 if {![info exists markedid]} return
8886 if {![commitinview $markedid $curview]} return
8887 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8888 do_cmp_commits $markedid $rowmenuid
8891 proc getpatchid {id} {
8894 if {![info exists patchids($id)]} {
8895 set cmd [diffcmd [list $id] {-p --root}]
8896 # trim off the initial "|"
8897 set cmd [lrange $cmd 1 end]
8899 set x [eval exec $cmd | git patch-id]
8900 set patchids($id) [lindex $x 0]
8902 set patchids($id) "error"
8905 return $patchids($id)
8908 proc do_cmp_commits {a b} {
8909 global ctext curview parents children patchids commitinfo
8911 $ctext conf -state normal
8914 for {set i 0} {$i < 100} {incr i} {
8917 if {[llength $parents($curview,$a)] > 1} {
8918 appendshortlink $a [mc "Skipping merge commit "] "\n"
8921 set patcha [getpatchid $a]
8923 if {[llength $parents($curview,$b)] > 1} {
8924 appendshortlink $b [mc "Skipping merge commit "] "\n"
8927 set patchb [getpatchid $b]
8929 if {!$skipa && !$skipb} {
8930 set heada [lindex $commitinfo($a) 0]
8931 set headb [lindex $commitinfo($b) 0]
8932 if {$patcha eq "error"} {
8933 appendshortlink $a [mc "Error getting patch ID for "] \
8934 [mc " - stopping\n"]
8937 if {$patchb eq "error"} {
8938 appendshortlink $b [mc "Error getting patch ID for "] \
8939 [mc " - stopping\n"]
8942 if {$patcha eq $patchb} {
8943 if {$heada eq $headb} {
8944 appendshortlink $a [mc "Commit "]
8945 appendshortlink $b " == " " $heada\n"
8947 appendshortlink $a [mc "Commit "] " $heada\n"
8948 appendshortlink $b [mc " is the same patch as\n "] \
8954 $ctext insert end "\n"
8955 appendshortlink $a [mc "Commit "] " $heada\n"
8956 appendshortlink $b [mc " differs from\n "] \
8958 $ctext insert end [mc "Diff of commits:\n\n"]
8959 $ctext conf -state disabled
8966 set kids [real_children $curview,$a]
8967 if {[llength $kids] != 1} {
8968 $ctext insert end "\n"
8969 appendshortlink $a [mc "Commit "] \
8970 [mc " has %s children - stopping\n" [llength $kids]]
8973 set a [lindex $kids 0]
8976 set kids [real_children $curview,$b]
8977 if {[llength $kids] != 1} {
8978 appendshortlink $b [mc "Commit "] \
8979 [mc " has %s children - stopping\n" [llength $kids]]
8982 set b [lindex $kids 0]
8985 $ctext conf -state disabled
8988 proc diffcommits {a b} {
8989 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8991 set tmpdir [gitknewtmpdir]
8992 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8993 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8995 exec git diff-tree -p --pretty $a >$fna
8996 exec git diff-tree -p --pretty $b >$fnb
8998 error_popup [mc "Error writing commit to file: %s" $err]
9002 set fd [open "| diff -U$diffcontext $fna $fnb" r]
9004 error_popup [mc "Error diffing commits: %s" $err]
9007 set diffids [list commits $a $b]
9008 set blobdifffd($diffids) $fd
9010 set currdiffsubmod ""
9011 filerun $fd [list getblobdiffline $fd $diffids]
9014 proc diffvssel {dirn} {
9015 global rowmenuid selectedline
9017 if {$selectedline eq {}} return
9019 set oldid [commitonrow $selectedline]
9020 set newid $rowmenuid
9022 set oldid $rowmenuid
9023 set newid [commitonrow $selectedline]
9025 addtohistory [list doseldiff $oldid $newid] savectextpos
9026 doseldiff $oldid $newid
9029 proc diffvsmark {dirn} {
9030 global rowmenuid markedid
9032 if {![info exists markedid]} return
9035 set newid $rowmenuid
9037 set oldid $rowmenuid
9040 addtohistory [list doseldiff $oldid $newid] savectextpos
9041 doseldiff $oldid $newid
9044 proc doseldiff {oldid newid} {
9048 $ctext conf -state normal
9050 init_flist [mc "Top"]
9051 $ctext insert end "[mc "From"] "
9052 $ctext insert end $oldid link0
9053 setlink $oldid link0
9054 $ctext insert end "\n "
9055 $ctext insert end [lindex $commitinfo($oldid) 0]
9056 $ctext insert end "\n\n[mc "To"] "
9057 $ctext insert end $newid link1
9058 setlink $newid link1
9059 $ctext insert end "\n "
9060 $ctext insert end [lindex $commitinfo($newid) 0]
9061 $ctext insert end "\n"
9062 $ctext conf -state disabled
9063 $ctext tag remove found 1.0 end
9064 startdiff [list $oldid $newid]
9068 global rowmenuid currentid commitinfo patchtop patchnum NS
9070 if {![info exists currentid]} return
9071 set oldid $currentid
9072 set oldhead [lindex $commitinfo($oldid) 0]
9073 set newid $rowmenuid
9074 set newhead [lindex $commitinfo($newid) 0]
9077 catch {destroy $top}
9079 make_transient $top .
9080 ${NS}::label $top.title -text [mc "Generate patch"]
9081 grid $top.title - -pady 10
9082 ${NS}::label $top.from -text [mc "From:"]
9083 ${NS}::entry $top.fromsha1 -width 40
9084 $top.fromsha1 insert 0 $oldid
9085 $top.fromsha1 conf -state readonly
9086 grid $top.from $top.fromsha1 -sticky w
9087 ${NS}::entry $top.fromhead -width 60
9088 $top.fromhead insert 0 $oldhead
9089 $top.fromhead conf -state readonly
9090 grid x $top.fromhead -sticky w
9091 ${NS}::label $top.to -text [mc "To:"]
9092 ${NS}::entry $top.tosha1 -width 40
9093 $top.tosha1 insert 0 $newid
9094 $top.tosha1 conf -state readonly
9095 grid $top.to $top.tosha1 -sticky w
9096 ${NS}::entry $top.tohead -width 60
9097 $top.tohead insert 0 $newhead
9098 $top.tohead conf -state readonly
9099 grid x $top.tohead -sticky w
9100 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9101 grid $top.rev x -pady 10 -padx 5
9102 ${NS}::label $top.flab -text [mc "Output file:"]
9103 ${NS}::entry $top.fname -width 60
9104 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9106 grid $top.flab $top.fname -sticky w
9107 ${NS}::frame $top.buts
9108 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9109 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9110 bind $top <Key-Return> mkpatchgo
9111 bind $top <Key-Escape> mkpatchcan
9112 grid $top.buts.gen $top.buts.can
9113 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9114 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9115 grid $top.buts - -pady 10 -sticky ew
9119 proc mkpatchrev {} {
9122 set oldid [$patchtop.fromsha1 get]
9123 set oldhead [$patchtop.fromhead get]
9124 set newid [$patchtop.tosha1 get]
9125 set newhead [$patchtop.tohead get]
9126 foreach e [list fromsha1 fromhead tosha1 tohead] \
9127 v [list $newid $newhead $oldid $oldhead] {
9128 $patchtop.$e conf -state normal
9129 $patchtop.$e delete 0 end
9130 $patchtop.$e insert 0 $v
9131 $patchtop.$e conf -state readonly
9136 global patchtop nullid nullid2
9138 set oldid [$patchtop.fromsha1 get]
9139 set newid [$patchtop.tosha1 get]
9140 set fname [$patchtop.fname get]
9141 set cmd [diffcmd [list $oldid $newid] -p]
9142 # trim off the initial "|"
9143 set cmd [lrange $cmd 1 end]
9144 lappend cmd >$fname &
9145 if {[catch {eval exec $cmd} err]} {
9146 error_popup "[mc "Error creating patch:"] $err" $patchtop
9148 catch {destroy $patchtop}
9152 proc mkpatchcan {} {
9155 catch {destroy $patchtop}
9160 global rowmenuid mktagtop commitinfo NS
9164 catch {destroy $top}
9166 make_transient $top .
9167 ${NS}::label $top.title -text [mc "Create tag"]
9168 grid $top.title - -pady 10
9169 ${NS}::label $top.id -text [mc "ID:"]
9170 ${NS}::entry $top.sha1 -width 40
9171 $top.sha1 insert 0 $rowmenuid
9172 $top.sha1 conf -state readonly
9173 grid $top.id $top.sha1 -sticky w
9174 ${NS}::entry $top.head -width 60
9175 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9176 $top.head conf -state readonly
9177 grid x $top.head -sticky w
9178 ${NS}::label $top.tlab -text [mc "Tag name:"]
9179 ${NS}::entry $top.tag -width 60
9180 grid $top.tlab $top.tag -sticky w
9181 ${NS}::label $top.op -text [mc "Tag message is optional"]
9182 grid $top.op -columnspan 2 -sticky we
9183 ${NS}::label $top.mlab -text [mc "Tag message:"]
9184 ${NS}::entry $top.msg -width 60
9185 grid $top.mlab $top.msg -sticky w
9186 ${NS}::frame $top.buts
9187 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9188 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9189 bind $top <Key-Return> mktaggo
9190 bind $top <Key-Escape> mktagcan
9191 grid $top.buts.gen $top.buts.can
9192 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9193 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9194 grid $top.buts - -pady 10 -sticky ew
9199 global mktagtop env tagids idtags
9201 set id [$mktagtop.sha1 get]
9202 set tag [$mktagtop.tag get]
9203 set msg [$mktagtop.msg get]
9205 error_popup [mc "No tag name specified"] $mktagtop
9208 if {[info exists tagids($tag)]} {
9209 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9214 exec git tag -a -m $msg $tag $id
9216 exec git tag $tag $id
9219 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9223 set tagids($tag) $id
9224 lappend idtags($id) $tag
9232 proc redrawtags {id} {
9233 global canv linehtag idpos currentid curview cmitlisted markedid
9234 global canvxmax iddrawn circleitem mainheadid circlecolors
9235 global mainheadcirclecolor
9237 if {![commitinview $id $curview]} return
9238 if {![info exists iddrawn($id)]} return
9239 set row [rowofcommit $id]
9240 if {$id eq $mainheadid} {
9241 set ofill $mainheadcirclecolor
9243 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9245 $canv itemconf $circleitem($row) -fill $ofill
9246 $canv delete tag.$id
9247 set xt [eval drawtags $id $idpos($id)]
9248 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9249 set text [$canv itemcget $linehtag($id) -text]
9250 set font [$canv itemcget $linehtag($id) -font]
9251 set xr [expr {$xt + [font measure $font $text]}]
9252 if {$xr > $canvxmax} {
9256 if {[info exists currentid] && $currentid == $id} {
9259 if {[info exists markedid] && $markedid eq $id} {
9267 catch {destroy $mktagtop}
9272 if {![domktag]} return
9276 proc writecommit {} {
9277 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9279 set top .writecommit
9281 catch {destroy $top}
9283 make_transient $top .
9284 ${NS}::label $top.title -text [mc "Write commit to file"]
9285 grid $top.title - -pady 10
9286 ${NS}::label $top.id -text [mc "ID:"]
9287 ${NS}::entry $top.sha1 -width 40
9288 $top.sha1 insert 0 $rowmenuid
9289 $top.sha1 conf -state readonly
9290 grid $top.id $top.sha1 -sticky w
9291 ${NS}::entry $top.head -width 60
9292 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9293 $top.head conf -state readonly
9294 grid x $top.head -sticky w
9295 ${NS}::label $top.clab -text [mc "Command:"]
9296 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9297 grid $top.clab $top.cmd -sticky w -pady 10
9298 ${NS}::label $top.flab -text [mc "Output file:"]
9299 ${NS}::entry $top.fname -width 60
9300 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9301 grid $top.flab $top.fname -sticky w
9302 ${NS}::frame $top.buts
9303 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9304 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9305 bind $top <Key-Return> wrcomgo
9306 bind $top <Key-Escape> wrcomcan
9307 grid $top.buts.gen $top.buts.can
9308 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9309 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9310 grid $top.buts - -pady 10 -sticky ew
9317 set id [$wrcomtop.sha1 get]
9318 set cmd "echo $id | [$wrcomtop.cmd get]"
9319 set fname [$wrcomtop.fname get]
9320 if {[catch {exec sh -c $cmd >$fname &} err]} {
9321 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9323 catch {destroy $wrcomtop}
9330 catch {destroy $wrcomtop}
9335 global rowmenuid mkbrtop NS
9338 catch {destroy $top}
9340 make_transient $top .
9341 ${NS}::label $top.title -text [mc "Create new branch"]
9342 grid $top.title - -pady 10
9343 ${NS}::label $top.id -text [mc "ID:"]
9344 ${NS}::entry $top.sha1 -width 40
9345 $top.sha1 insert 0 $rowmenuid
9346 $top.sha1 conf -state readonly
9347 grid $top.id $top.sha1 -sticky w
9348 ${NS}::label $top.nlab -text [mc "Name:"]
9349 ${NS}::entry $top.name -width 40
9350 grid $top.nlab $top.name -sticky w
9351 ${NS}::frame $top.buts
9352 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9353 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9354 bind $top <Key-Return> [list mkbrgo $top]
9355 bind $top <Key-Escape> "catch {destroy $top}"
9356 grid $top.buts.go $top.buts.can
9357 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9358 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9359 grid $top.buts - -pady 10 -sticky ew
9364 global headids idheads
9366 set name [$top.name get]
9367 set id [$top.sha1 get]
9371 error_popup [mc "Please specify a name for the new branch"] $top
9374 if {[info exists headids($name)]} {
9375 if {![confirm_popup [mc \
9376 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9379 set old_id $headids($name)
9382 catch {destroy $top}
9383 lappend cmdargs $name $id
9387 eval exec git branch $cmdargs
9393 if {$old_id ne {}} {
9399 set headids($name) $id
9400 lappend idheads($id) $name
9409 proc exec_citool {tool_args {baseid {}}} {
9410 global commitinfo env
9412 set save_env [array get env GIT_AUTHOR_*]
9414 if {$baseid ne {}} {
9415 if {![info exists commitinfo($baseid)]} {
9418 set author [lindex $commitinfo($baseid) 1]
9419 set date [lindex $commitinfo($baseid) 2]
9420 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9421 $author author name email]
9423 set env(GIT_AUTHOR_NAME) $name
9424 set env(GIT_AUTHOR_EMAIL) $email
9425 set env(GIT_AUTHOR_DATE) $date
9429 eval exec git citool $tool_args &
9431 array unset env GIT_AUTHOR_*
9432 array set env $save_env
9435 proc cherrypick {} {
9436 global rowmenuid curview
9437 global mainhead mainheadid
9440 set oldhead [exec git rev-parse HEAD]
9441 set dheads [descheads $rowmenuid]
9442 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9443 set ok [confirm_popup [mc "Commit %s is already\
9444 included in branch %s -- really re-apply it?" \
9445 [string range $rowmenuid 0 7] $mainhead]]
9448 nowbusy cherrypick [mc "Cherry-picking"]
9450 # Unfortunately git-cherry-pick writes stuff to stderr even when
9451 # no error occurs, and exec takes that as an indication of error...
9452 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9455 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9457 error_popup [mc "Cherry-pick failed because of local changes\
9458 to file '%s'.\nPlease commit, reset or stash\
9459 your changes and try again." $fname]
9460 } elseif {[regexp -line \
9461 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9463 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9464 conflict.\nDo you wish to run git citool to\
9466 # Force citool to read MERGE_MSG
9467 file delete [file join $gitdir "GITGUI_MSG"]
9468 exec_citool {} $rowmenuid
9476 set newhead [exec git rev-parse HEAD]
9477 if {$newhead eq $oldhead} {
9479 error_popup [mc "No changes committed"]
9482 addnewchild $newhead $oldhead
9483 if {[commitinview $oldhead $curview]} {
9484 # XXX this isn't right if we have a path limit...
9485 insertrow $newhead $oldhead $curview
9486 if {$mainhead ne {}} {
9487 movehead $newhead $mainhead
9488 movedhead $newhead $mainhead
9490 set mainheadid $newhead
9499 global rowmenuid curview
9500 global mainhead mainheadid
9503 set oldhead [exec git rev-parse HEAD]
9504 set dheads [descheads $rowmenuid]
9505 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9506 set ok [confirm_popup [mc "Commit %s is not\
9507 included in branch %s -- really revert it?" \
9508 [string range $rowmenuid 0 7] $mainhead]]
9511 nowbusy revert [mc "Reverting"]
9514 if [catch {exec git revert --no-edit $rowmenuid} err] {
9516 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9518 regsub {\n( |\t)+} $files "\n" files
9519 error_popup [mc "Revert failed because of local changes to\
9520 the following files:%s Please commit, reset or stash \
9521 your changes and try again." $files]
9522 } elseif [regexp {error: could not revert} $err] {
9523 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9524 Do you wish to run git citool to resolve it?"]] {
9525 # Force citool to read MERGE_MSG
9526 file delete [file join $gitdir "GITGUI_MSG"]
9527 exec_citool {} $rowmenuid
9529 } else { error_popup $err }
9534 set newhead [exec git rev-parse HEAD]
9535 if { $newhead eq $oldhead } {
9537 error_popup [mc "No changes committed"]
9541 addnewchild $newhead $oldhead
9543 if [commitinview $oldhead $curview] {
9544 # XXX this isn't right if we have a path limit...
9545 insertrow $newhead $oldhead $curview
9546 if {$mainhead ne {}} {
9547 movehead $newhead $mainhead
9548 movedhead $newhead $mainhead
9550 set mainheadid $newhead
9560 global mainhead rowmenuid confirm_ok resettype NS
9563 set w ".confirmreset"
9566 wm title $w [mc "Confirm reset"]
9567 ${NS}::label $w.m -text \
9568 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9569 pack $w.m -side top -fill x -padx 20 -pady 20
9570 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9572 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9573 -text [mc "Soft: Leave working tree and index untouched"]
9574 grid $w.f.soft -sticky w
9575 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9576 -text [mc "Mixed: Leave working tree untouched, reset index"]
9577 grid $w.f.mixed -sticky w
9578 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9579 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9580 grid $w.f.hard -sticky w
9581 pack $w.f -side top -fill x -padx 4
9582 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9583 pack $w.ok -side left -fill x -padx 20 -pady 20
9584 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9585 bind $w <Key-Escape> [list destroy $w]
9586 pack $w.cancel -side right -fill x -padx 20 -pady 20
9587 bind $w <Visibility> "grab $w; focus $w"
9589 if {!$confirm_ok} return
9590 if {[catch {set fd [open \
9591 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9595 filerun $fd [list readresetstat $fd]
9596 nowbusy reset [mc "Resetting"]
9601 proc readresetstat {fd} {
9602 global mainhead mainheadid showlocalchanges rprogcoord
9604 if {[gets $fd line] >= 0} {
9605 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9606 set rprogcoord [expr {1.0 * $m / $n}]
9614 if {[catch {close $fd} err]} {
9617 set oldhead $mainheadid
9618 set newhead [exec git rev-parse HEAD]
9619 if {$newhead ne $oldhead} {
9620 movehead $newhead $mainhead
9621 movedhead $newhead $mainhead
9622 set mainheadid $newhead
9626 if {$showlocalchanges} {
9632 # context menu for a head
9633 proc headmenu {x y id head} {
9634 global headmenuid headmenuhead headctxmenu mainhead
9638 set headmenuhead $head
9640 if {[string match "remotes/*" $head]} {
9643 if {$head eq $mainhead} {
9646 $headctxmenu entryconfigure 0 -state $state
9647 $headctxmenu entryconfigure 1 -state $state
9648 tk_popup $headctxmenu $x $y
9652 global headmenuid headmenuhead headids
9653 global showlocalchanges
9655 # check the tree is clean first??
9656 nowbusy checkout [mc "Checking out"]
9660 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9664 if {$showlocalchanges} {
9668 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9672 proc readcheckoutstat {fd newhead newheadid} {
9673 global mainhead mainheadid headids showlocalchanges progresscoords
9674 global viewmainheadid curview
9676 if {[gets $fd line] >= 0} {
9677 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9678 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9683 set progresscoords {0 0}
9686 if {[catch {close $fd} err]} {
9689 set oldmainid $mainheadid
9690 set mainhead $newhead
9691 set mainheadid $newheadid
9692 set viewmainheadid($curview) $newheadid
9693 redrawtags $oldmainid
9694 redrawtags $newheadid
9696 if {$showlocalchanges} {
9702 global headmenuid headmenuhead mainhead
9705 set head $headmenuhead
9707 # this check shouldn't be needed any more...
9708 if {$head eq $mainhead} {
9709 error_popup [mc "Cannot delete the currently checked-out branch"]
9712 set dheads [descheads $id]
9713 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9714 # the stuff on this branch isn't on any other branch
9715 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9716 branch.\nReally delete branch %s?" $head $head]]} return
9720 if {[catch {exec git branch -D $head} err]} {
9725 removehead $id $head
9726 removedhead $id $head
9733 # Display a list of tags and heads
9735 global showrefstop bgcolor fgcolor selectbgcolor NS
9736 global bglist fglist reflistfilter reflist maincursor
9739 set showrefstop $top
9740 if {[winfo exists $top]} {
9746 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9747 make_transient $top .
9748 text $top.list -background $bgcolor -foreground $fgcolor \
9749 -selectbackground $selectbgcolor -font mainfont \
9750 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9751 -width 30 -height 20 -cursor $maincursor \
9752 -spacing1 1 -spacing3 1 -state disabled
9753 $top.list tag configure highlight -background $selectbgcolor
9754 lappend bglist $top.list
9755 lappend fglist $top.list
9756 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9757 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9758 grid $top.list $top.ysb -sticky nsew
9759 grid $top.xsb x -sticky ew
9761 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9762 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9763 set reflistfilter "*"
9764 trace add variable reflistfilter write reflistfilter_change
9765 pack $top.f.e -side right -fill x -expand 1
9766 pack $top.f.l -side left
9767 grid $top.f - -sticky ew -pady 2
9768 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9769 bind $top <Key-Escape> [list destroy $top]
9771 grid columnconfigure $top 0 -weight 1
9772 grid rowconfigure $top 0 -weight 1
9773 bind $top.list <1> {break}
9774 bind $top.list <B1-Motion> {break}
9775 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9780 proc sel_reflist {w x y} {
9781 global showrefstop reflist headids tagids otherrefids
9783 if {![winfo exists $showrefstop]} return
9784 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9785 set ref [lindex $reflist [expr {$l-1}]]
9786 set n [lindex $ref 0]
9787 switch -- [lindex $ref 1] {
9788 "H" {selbyid $headids($n)}
9789 "T" {selbyid $tagids($n)}
9790 "o" {selbyid $otherrefids($n)}
9792 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9795 proc unsel_reflist {} {
9798 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9799 $showrefstop.list tag remove highlight 0.0 end
9802 proc reflistfilter_change {n1 n2 op} {
9803 global reflistfilter
9805 after cancel refill_reflist
9806 after 200 refill_reflist
9809 proc refill_reflist {} {
9810 global reflist reflistfilter showrefstop headids tagids otherrefids
9813 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9815 foreach n [array names headids] {
9816 if {[string match $reflistfilter $n]} {
9817 if {[commitinview $headids($n) $curview]} {
9818 lappend refs [list $n H]
9820 interestedin $headids($n) {run refill_reflist}
9824 foreach n [array names tagids] {
9825 if {[string match $reflistfilter $n]} {
9826 if {[commitinview $tagids($n) $curview]} {
9827 lappend refs [list $n T]
9829 interestedin $tagids($n) {run refill_reflist}
9833 foreach n [array names otherrefids] {
9834 if {[string match $reflistfilter $n]} {
9835 if {[commitinview $otherrefids($n) $curview]} {
9836 lappend refs [list $n o]
9838 interestedin $otherrefids($n) {run refill_reflist}
9842 set refs [lsort -index 0 $refs]
9843 if {$refs eq $reflist} return
9845 # Update the contents of $showrefstop.list according to the
9846 # differences between $reflist (old) and $refs (new)
9847 $showrefstop.list conf -state normal
9848 $showrefstop.list insert end "\n"
9851 while {$i < [llength $reflist] || $j < [llength $refs]} {
9852 if {$i < [llength $reflist]} {
9853 if {$j < [llength $refs]} {
9854 set cmp [string compare [lindex $reflist $i 0] \
9855 [lindex $refs $j 0]]
9857 set cmp [string compare [lindex $reflist $i 1] \
9858 [lindex $refs $j 1]]
9868 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9876 set l [expr {$j + 1}]
9877 $showrefstop.list image create $l.0 -align baseline \
9878 -image reficon-[lindex $refs $j 1] -padx 2
9879 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9885 # delete last newline
9886 $showrefstop.list delete end-2c end-1c
9887 $showrefstop.list conf -state disabled
9890 # Stuff for finding nearby tags
9891 proc getallcommits {} {
9892 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9893 global idheads idtags idotherrefs allparents tagobjid
9896 if {![info exists allcommits]} {
9902 set allccache [file join $gitdir "gitk.cache"]
9904 set f [open $allccache r]
9913 set cmd [list | git rev-list --parents]
9914 set allcupdate [expr {$seeds ne {}}]
9918 set refs [concat [array names idheads] [array names idtags] \
9919 [array names idotherrefs]]
9922 foreach name [array names tagobjid] {
9923 lappend tagobjs $tagobjid($name)
9925 foreach id [lsort -unique $refs] {
9926 if {![info exists allparents($id)] &&
9927 [lsearch -exact $tagobjs $id] < 0} {
9938 set fd [open [concat $cmd $ids] r]
9939 fconfigure $fd -blocking 0
9942 filerun $fd [list getallclines $fd]
9948 # Since most commits have 1 parent and 1 child, we group strings of
9949 # such commits into "arcs" joining branch/merge points (BMPs), which
9950 # are commits that either don't have 1 parent or don't have 1 child.
9952 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9953 # arcout(id) - outgoing arcs for BMP
9954 # arcids(a) - list of IDs on arc including end but not start
9955 # arcstart(a) - BMP ID at start of arc
9956 # arcend(a) - BMP ID at end of arc
9957 # growing(a) - arc a is still growing
9958 # arctags(a) - IDs out of arcids (excluding end) that have tags
9959 # archeads(a) - IDs out of arcids (excluding end) that have heads
9960 # The start of an arc is at the descendent end, so "incoming" means
9961 # coming from descendents, and "outgoing" means going towards ancestors.
9963 proc getallclines {fd} {
9964 global allparents allchildren idtags idheads nextarc
9965 global arcnos arcids arctags arcout arcend arcstart archeads growing
9966 global seeds allcommits cachedarcs allcupdate
9969 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9970 set id [lindex $line 0]
9971 if {[info exists allparents($id)]} {
9976 set olds [lrange $line 1 end]
9977 set allparents($id) $olds
9978 if {![info exists allchildren($id)]} {
9979 set allchildren($id) {}
9984 if {[llength $olds] == 1 && [llength $a] == 1} {
9985 lappend arcids($a) $id
9986 if {[info exists idtags($id)]} {
9987 lappend arctags($a) $id
9989 if {[info exists idheads($id)]} {
9990 lappend archeads($a) $id
9992 if {[info exists allparents($olds)]} {
9993 # seen parent already
9994 if {![info exists arcout($olds)]} {
9997 lappend arcids($a) $olds
9998 set arcend($a) $olds
10001 lappend allchildren($olds) $id
10002 lappend arcnos($olds) $a
10006 foreach a $arcnos($id) {
10007 lappend arcids($a) $id
10014 lappend allchildren($p) $id
10015 set a [incr nextarc]
10016 set arcstart($a) $id
10017 set archeads($a) {}
10019 set archeads($a) {}
10023 if {[info exists allparents($p)]} {
10024 # seen it already, may need to make a new branch
10025 if {![info exists arcout($p)]} {
10028 lappend arcids($a) $p
10032 lappend arcnos($p) $a
10034 set arcout($id) $ao
10037 global cached_dheads cached_dtags cached_atags
10038 catch {unset cached_dheads}
10039 catch {unset cached_dtags}
10040 catch {unset cached_atags}
10043 return [expr {$nid >= 1000? 2: 1}]
10047 fconfigure $fd -blocking 1
10050 # got an error reading the list of commits
10051 # if we were updating, try rereading the whole thing again
10057 error_popup "[mc "Error reading commit topology information;\
10058 branch and preceding/following tag information\
10059 will be incomplete."]\n($err)"
10062 if {[incr allcommits -1] == 0} {
10072 proc recalcarc {a} {
10073 global arctags archeads arcids idtags idheads
10077 foreach id [lrange $arcids($a) 0 end-1] {
10078 if {[info exists idtags($id)]} {
10081 if {[info exists idheads($id)]} {
10085 set arctags($a) $at
10086 set archeads($a) $ah
10089 proc splitarc {p} {
10090 global arcnos arcids nextarc arctags archeads idtags idheads
10091 global arcstart arcend arcout allparents growing
10094 if {[llength $a] != 1} {
10095 puts "oops splitarc called but [llength $a] arcs already"
10098 set a [lindex $a 0]
10099 set i [lsearch -exact $arcids($a) $p]
10101 puts "oops splitarc $p not in arc $a"
10104 set na [incr nextarc]
10105 if {[info exists arcend($a)]} {
10106 set arcend($na) $arcend($a)
10108 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10109 set j [lsearch -exact $arcnos($l) $a]
10110 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10112 set tail [lrange $arcids($a) [expr {$i+1}] end]
10113 set arcids($a) [lrange $arcids($a) 0 $i]
10115 set arcstart($na) $p
10117 set arcids($na) $tail
10118 if {[info exists growing($a)]} {
10124 if {[llength $arcnos($id)] == 1} {
10125 set arcnos($id) $na
10127 set j [lsearch -exact $arcnos($id) $a]
10128 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10132 # reconstruct tags and heads lists
10133 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10137 set arctags($na) {}
10138 set archeads($na) {}
10142 # Update things for a new commit added that is a child of one
10143 # existing commit. Used when cherry-picking.
10144 proc addnewchild {id p} {
10145 global allparents allchildren idtags nextarc
10146 global arcnos arcids arctags arcout arcend arcstart archeads growing
10147 global seeds allcommits
10149 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10150 set allparents($id) [list $p]
10151 set allchildren($id) {}
10154 lappend allchildren($p) $id
10155 set a [incr nextarc]
10156 set arcstart($a) $id
10157 set archeads($a) {}
10159 set arcids($a) [list $p]
10161 if {![info exists arcout($p)]} {
10164 lappend arcnos($p) $a
10165 set arcout($id) [list $a]
10168 # This implements a cache for the topology information.
10169 # The cache saves, for each arc, the start and end of the arc,
10170 # the ids on the arc, and the outgoing arcs from the end.
10171 proc readcache {f} {
10172 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10173 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10177 set lim $cachedarcs
10178 if {$lim - $a > 500} {
10179 set lim [expr {$a + 500}]
10183 # finish reading the cache and setting up arctags, etc.
10185 if {$line ne "1"} {error "bad final version"}
10187 foreach id [array names idtags] {
10188 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10189 [llength $allparents($id)] == 1} {
10190 set a [lindex $arcnos($id) 0]
10191 if {$arctags($a) eq {}} {
10196 foreach id [array names idheads] {
10197 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10198 [llength $allparents($id)] == 1} {
10199 set a [lindex $arcnos($id) 0]
10200 if {$archeads($a) eq {}} {
10205 foreach id [lsort -unique $possible_seeds] {
10206 if {$arcnos($id) eq {}} {
10212 while {[incr a] <= $lim} {
10214 if {[llength $line] != 3} {error "bad line"}
10215 set s [lindex $line 0]
10216 set arcstart($a) $s
10217 lappend arcout($s) $a
10218 if {![info exists arcnos($s)]} {
10219 lappend possible_seeds $s
10222 set e [lindex $line 1]
10227 if {![info exists arcout($e)]} {
10231 set arcids($a) [lindex $line 2]
10232 foreach id $arcids($a) {
10233 lappend allparents($s) $id
10235 lappend arcnos($id) $a
10237 if {![info exists allparents($s)]} {
10238 set allparents($s) {}
10241 set archeads($a) {}
10243 set nextarc [expr {$a - 1}]
10255 proc getcache {f} {
10256 global nextarc cachedarcs possible_seeds
10260 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10261 # make sure it's an integer
10262 set cachedarcs [expr {int([lindex $line 1])}]
10263 if {$cachedarcs < 0} {error "bad number of arcs"}
10265 set possible_seeds {}
10273 proc dropcache {err} {
10274 global allcwait nextarc cachedarcs seeds
10276 #puts "dropping cache ($err)"
10277 foreach v {arcnos arcout arcids arcstart arcend growing \
10278 arctags archeads allparents allchildren} {
10289 proc writecache {f} {
10290 global cachearc cachedarcs allccache
10291 global arcstart arcend arcnos arcids arcout
10294 set lim $cachedarcs
10295 if {$lim - $a > 1000} {
10296 set lim [expr {$a + 1000}]
10299 while {[incr a] <= $lim} {
10300 if {[info exists arcend($a)]} {
10301 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10303 puts $f [list $arcstart($a) {} $arcids($a)]
10308 catch {file delete $allccache}
10309 #puts "writing cache failed ($err)"
10312 set cachearc [expr {$a - 1}]
10313 if {$a > $cachedarcs} {
10321 proc savecache {} {
10322 global nextarc cachedarcs cachearc allccache
10324 if {$nextarc == $cachedarcs} return
10326 set cachedarcs $nextarc
10328 set f [open $allccache w]
10329 puts $f [list 1 $cachedarcs]
10334 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10335 # or 0 if neither is true.
10336 proc anc_or_desc {a b} {
10337 global arcout arcstart arcend arcnos cached_isanc
10339 if {$arcnos($a) eq $arcnos($b)} {
10340 # Both are on the same arc(s); either both are the same BMP,
10341 # or if one is not a BMP, the other is also not a BMP or is
10342 # the BMP at end of the arc (and it only has 1 incoming arc).
10343 # Or both can be BMPs with no incoming arcs.
10344 if {$a eq $b || $arcnos($a) eq {}} {
10347 # assert {[llength $arcnos($a)] == 1}
10348 set arc [lindex $arcnos($a) 0]
10349 set i [lsearch -exact $arcids($arc) $a]
10350 set j [lsearch -exact $arcids($arc) $b]
10351 if {$i < 0 || $i > $j} {
10358 if {![info exists arcout($a)]} {
10359 set arc [lindex $arcnos($a) 0]
10360 if {[info exists arcend($arc)]} {
10361 set aend $arcend($arc)
10365 set a $arcstart($arc)
10369 if {![info exists arcout($b)]} {
10370 set arc [lindex $arcnos($b) 0]
10371 if {[info exists arcend($arc)]} {
10372 set bend $arcend($arc)
10376 set b $arcstart($arc)
10386 if {[info exists cached_isanc($a,$bend)]} {
10387 if {$cached_isanc($a,$bend)} {
10391 if {[info exists cached_isanc($b,$aend)]} {
10392 if {$cached_isanc($b,$aend)} {
10395 if {[info exists cached_isanc($a,$bend)]} {
10400 set todo [list $a $b]
10403 for {set i 0} {$i < [llength $todo]} {incr i} {
10404 set x [lindex $todo $i]
10405 if {$anc($x) eq {}} {
10408 foreach arc $arcnos($x) {
10409 set xd $arcstart($arc)
10410 if {$xd eq $bend} {
10411 set cached_isanc($a,$bend) 1
10412 set cached_isanc($b,$aend) 0
10414 } elseif {$xd eq $aend} {
10415 set cached_isanc($b,$aend) 1
10416 set cached_isanc($a,$bend) 0
10419 if {![info exists anc($xd)]} {
10420 set anc($xd) $anc($x)
10422 } elseif {$anc($xd) ne $anc($x)} {
10427 set cached_isanc($a,$bend) 0
10428 set cached_isanc($b,$aend) 0
10432 # This identifies whether $desc has an ancestor that is
10433 # a growing tip of the graph and which is not an ancestor of $anc
10434 # and returns 0 if so and 1 if not.
10435 # If we subsequently discover a tag on such a growing tip, and that
10436 # turns out to be a descendent of $anc (which it could, since we
10437 # don't necessarily see children before parents), then $desc
10438 # isn't a good choice to display as a descendent tag of
10439 # $anc (since it is the descendent of another tag which is
10440 # a descendent of $anc). Similarly, $anc isn't a good choice to
10441 # display as a ancestor tag of $desc.
10443 proc is_certain {desc anc} {
10444 global arcnos arcout arcstart arcend growing problems
10447 if {[llength $arcnos($anc)] == 1} {
10448 # tags on the same arc are certain
10449 if {$arcnos($desc) eq $arcnos($anc)} {
10452 if {![info exists arcout($anc)]} {
10453 # if $anc is partway along an arc, use the start of the arc instead
10454 set a [lindex $arcnos($anc) 0]
10455 set anc $arcstart($a)
10458 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10461 set a [lindex $arcnos($desc) 0]
10467 set anclist [list $x]
10471 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10472 set x [lindex $anclist $i]
10477 foreach a $arcout($x) {
10478 if {[info exists growing($a)]} {
10479 if {![info exists growanc($x)] && $dl($x)} {
10485 if {[info exists dl($y)]} {
10489 if {![info exists done($y)]} {
10492 if {[info exists growanc($x)]} {
10496 for {set k 0} {$k < [llength $xl]} {incr k} {
10497 set z [lindex $xl $k]
10498 foreach c $arcout($z) {
10499 if {[info exists arcend($c)]} {
10501 if {[info exists dl($v)] && $dl($v)} {
10503 if {![info exists done($v)]} {
10506 if {[info exists growanc($v)]} {
10516 } elseif {$y eq $anc || !$dl($x)} {
10527 foreach x [array names growanc] {
10536 proc validate_arctags {a} {
10537 global arctags idtags
10540 set na $arctags($a)
10541 foreach id $arctags($a) {
10543 if {![info exists idtags($id)]} {
10544 set na [lreplace $na $i $i]
10548 set arctags($a) $na
10551 proc validate_archeads {a} {
10552 global archeads idheads
10555 set na $archeads($a)
10556 foreach id $archeads($a) {
10558 if {![info exists idheads($id)]} {
10559 set na [lreplace $na $i $i]
10563 set archeads($a) $na
10566 # Return the list of IDs that have tags that are descendents of id,
10567 # ignoring IDs that are descendents of IDs already reported.
10568 proc desctags {id} {
10569 global arcnos arcstart arcids arctags idtags allparents
10570 global growing cached_dtags
10572 if {![info exists allparents($id)]} {
10575 set t1 [clock clicks -milliseconds]
10577 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10578 # part-way along an arc; check that arc first
10579 set a [lindex $arcnos($id) 0]
10580 if {$arctags($a) ne {}} {
10581 validate_arctags $a
10582 set i [lsearch -exact $arcids($a) $id]
10584 foreach t $arctags($a) {
10585 set j [lsearch -exact $arcids($a) $t]
10586 if {$j >= $i} break
10593 set id $arcstart($a)
10594 if {[info exists idtags($id)]} {
10598 if {[info exists cached_dtags($id)]} {
10599 return $cached_dtags($id)
10603 set todo [list $id]
10606 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10607 set id [lindex $todo $i]
10609 set ta [info exists hastaggedancestor($id)]
10613 # ignore tags on starting node
10614 if {!$ta && $i > 0} {
10615 if {[info exists idtags($id)]} {
10616 set tagloc($id) $id
10618 } elseif {[info exists cached_dtags($id)]} {
10619 set tagloc($id) $cached_dtags($id)
10623 foreach a $arcnos($id) {
10624 set d $arcstart($a)
10625 if {!$ta && $arctags($a) ne {}} {
10626 validate_arctags $a
10627 if {$arctags($a) ne {}} {
10628 lappend tagloc($id) [lindex $arctags($a) end]
10631 if {$ta || $arctags($a) ne {}} {
10632 set tomark [list $d]
10633 for {set j 0} {$j < [llength $tomark]} {incr j} {
10634 set dd [lindex $tomark $j]
10635 if {![info exists hastaggedancestor($dd)]} {
10636 if {[info exists done($dd)]} {
10637 foreach b $arcnos($dd) {
10638 lappend tomark $arcstart($b)
10640 if {[info exists tagloc($dd)]} {
10643 } elseif {[info exists queued($dd)]} {
10646 set hastaggedancestor($dd) 1
10650 if {![info exists queued($d)]} {
10653 if {![info exists hastaggedancestor($d)]} {
10660 foreach id [array names tagloc] {
10661 if {![info exists hastaggedancestor($id)]} {
10662 foreach t $tagloc($id) {
10663 if {[lsearch -exact $tags $t] < 0} {
10669 set t2 [clock clicks -milliseconds]
10672 # remove tags that are descendents of other tags
10673 for {set i 0} {$i < [llength $tags]} {incr i} {
10674 set a [lindex $tags $i]
10675 for {set j 0} {$j < $i} {incr j} {
10676 set b [lindex $tags $j]
10677 set r [anc_or_desc $a $b]
10679 set tags [lreplace $tags $j $j]
10682 } elseif {$r == -1} {
10683 set tags [lreplace $tags $i $i]
10690 if {[array names growing] ne {}} {
10691 # graph isn't finished, need to check if any tag could get
10692 # eclipsed by another tag coming later. Simply ignore any
10693 # tags that could later get eclipsed.
10696 if {[is_certain $t $origid]} {
10700 if {$tags eq $ctags} {
10701 set cached_dtags($origid) $tags
10706 set cached_dtags($origid) $tags
10708 set t3 [clock clicks -milliseconds]
10709 if {0 && $t3 - $t1 >= 100} {
10710 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10711 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10716 proc anctags {id} {
10717 global arcnos arcids arcout arcend arctags idtags allparents
10718 global growing cached_atags
10720 if {![info exists allparents($id)]} {
10723 set t1 [clock clicks -milliseconds]
10725 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10726 # part-way along an arc; check that arc first
10727 set a [lindex $arcnos($id) 0]
10728 if {$arctags($a) ne {}} {
10729 validate_arctags $a
10730 set i [lsearch -exact $arcids($a) $id]
10731 foreach t $arctags($a) {
10732 set j [lsearch -exact $arcids($a) $t]
10738 if {![info exists arcend($a)]} {
10742 if {[info exists idtags($id)]} {
10746 if {[info exists cached_atags($id)]} {
10747 return $cached_atags($id)
10751 set todo [list $id]
10755 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10756 set id [lindex $todo $i]
10758 set td [info exists hastaggeddescendent($id)]
10762 # ignore tags on starting node
10763 if {!$td && $i > 0} {
10764 if {[info exists idtags($id)]} {
10765 set tagloc($id) $id
10767 } elseif {[info exists cached_atags($id)]} {
10768 set tagloc($id) $cached_atags($id)
10772 foreach a $arcout($id) {
10773 if {!$td && $arctags($a) ne {}} {
10774 validate_arctags $a
10775 if {$arctags($a) ne {}} {
10776 lappend tagloc($id) [lindex $arctags($a) 0]
10779 if {![info exists arcend($a)]} continue
10781 if {$td || $arctags($a) ne {}} {
10782 set tomark [list $d]
10783 for {set j 0} {$j < [llength $tomark]} {incr j} {
10784 set dd [lindex $tomark $j]
10785 if {![info exists hastaggeddescendent($dd)]} {
10786 if {[info exists done($dd)]} {
10787 foreach b $arcout($dd) {
10788 if {[info exists arcend($b)]} {
10789 lappend tomark $arcend($b)
10792 if {[info exists tagloc($dd)]} {
10795 } elseif {[info exists queued($dd)]} {
10798 set hastaggeddescendent($dd) 1
10802 if {![info exists queued($d)]} {
10805 if {![info exists hastaggeddescendent($d)]} {
10811 set t2 [clock clicks -milliseconds]
10814 foreach id [array names tagloc] {
10815 if {![info exists hastaggeddescendent($id)]} {
10816 foreach t $tagloc($id) {
10817 if {[lsearch -exact $tags $t] < 0} {
10824 # remove tags that are ancestors of other tags
10825 for {set i 0} {$i < [llength $tags]} {incr i} {
10826 set a [lindex $tags $i]
10827 for {set j 0} {$j < $i} {incr j} {
10828 set b [lindex $tags $j]
10829 set r [anc_or_desc $a $b]
10831 set tags [lreplace $tags $j $j]
10834 } elseif {$r == 1} {
10835 set tags [lreplace $tags $i $i]
10842 if {[array names growing] ne {}} {
10843 # graph isn't finished, need to check if any tag could get
10844 # eclipsed by another tag coming later. Simply ignore any
10845 # tags that could later get eclipsed.
10848 if {[is_certain $origid $t]} {
10852 if {$tags eq $ctags} {
10853 set cached_atags($origid) $tags
10858 set cached_atags($origid) $tags
10860 set t3 [clock clicks -milliseconds]
10861 if {0 && $t3 - $t1 >= 100} {
10862 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10863 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10868 # Return the list of IDs that have heads that are descendents of id,
10869 # including id itself if it has a head.
10870 proc descheads {id} {
10871 global arcnos arcstart arcids archeads idheads cached_dheads
10872 global allparents arcout
10874 if {![info exists allparents($id)]} {
10878 if {![info exists arcout($id)]} {
10879 # part-way along an arc; check it first
10880 set a [lindex $arcnos($id) 0]
10881 if {$archeads($a) ne {}} {
10882 validate_archeads $a
10883 set i [lsearch -exact $arcids($a) $id]
10884 foreach t $archeads($a) {
10885 set j [lsearch -exact $arcids($a) $t]
10890 set id $arcstart($a)
10893 set todo [list $id]
10896 for {set i 0} {$i < [llength $todo]} {incr i} {
10897 set id [lindex $todo $i]
10898 if {[info exists cached_dheads($id)]} {
10899 set ret [concat $ret $cached_dheads($id)]
10901 if {[info exists idheads($id)]} {
10904 foreach a $arcnos($id) {
10905 if {$archeads($a) ne {}} {
10906 validate_archeads $a
10907 if {$archeads($a) ne {}} {
10908 set ret [concat $ret $archeads($a)]
10911 set d $arcstart($a)
10912 if {![info exists seen($d)]} {
10919 set ret [lsort -unique $ret]
10920 set cached_dheads($origid) $ret
10921 return [concat $ret $aret]
10924 proc addedtag {id} {
10925 global arcnos arcout cached_dtags cached_atags
10927 if {![info exists arcnos($id)]} return
10928 if {![info exists arcout($id)]} {
10929 recalcarc [lindex $arcnos($id) 0]
10931 catch {unset cached_dtags}
10932 catch {unset cached_atags}
10935 proc addedhead {hid head} {
10936 global arcnos arcout cached_dheads
10938 if {![info exists arcnos($hid)]} return
10939 if {![info exists arcout($hid)]} {
10940 recalcarc [lindex $arcnos($hid) 0]
10942 catch {unset cached_dheads}
10945 proc removedhead {hid head} {
10946 global cached_dheads
10948 catch {unset cached_dheads}
10951 proc movedhead {hid head} {
10952 global arcnos arcout cached_dheads
10954 if {![info exists arcnos($hid)]} return
10955 if {![info exists arcout($hid)]} {
10956 recalcarc [lindex $arcnos($hid) 0]
10958 catch {unset cached_dheads}
10961 proc changedrefs {} {
10962 global cached_dheads cached_dtags cached_atags cached_tagcontent
10963 global arctags archeads arcnos arcout idheads idtags
10965 foreach id [concat [array names idheads] [array names idtags]] {
10966 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10967 set a [lindex $arcnos($id) 0]
10968 if {![info exists donearc($a)]} {
10974 catch {unset cached_tagcontent}
10975 catch {unset cached_dtags}
10976 catch {unset cached_atags}
10977 catch {unset cached_dheads}
10980 proc rereadrefs {} {
10981 global idtags idheads idotherrefs mainheadid
10983 set refids [concat [array names idtags] \
10984 [array names idheads] [array names idotherrefs]]
10985 foreach id $refids {
10986 if {![info exists ref($id)]} {
10987 set ref($id) [listrefs $id]
10990 set oldmainhead $mainheadid
10993 set refids [lsort -unique [concat $refids [array names idtags] \
10994 [array names idheads] [array names idotherrefs]]]
10995 foreach id $refids {
10996 set v [listrefs $id]
10997 if {![info exists ref($id)] || $ref($id) != $v} {
11001 if {$oldmainhead ne $mainheadid} {
11002 redrawtags $oldmainhead
11003 redrawtags $mainheadid
11008 proc listrefs {id} {
11009 global idtags idheads idotherrefs
11012 if {[info exists idtags($id)]} {
11016 if {[info exists idheads($id)]} {
11017 set y $idheads($id)
11020 if {[info exists idotherrefs($id)]} {
11021 set z $idotherrefs($id)
11023 return [list $x $y $z]
11026 proc add_tag_ctext {tag} {
11027 global ctext cached_tagcontent tagids
11029 if {![info exists cached_tagcontent($tag)]} {
11031 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11034 $ctext insert end "[mc "Tag"]: $tag\n" bold
11035 if {[info exists cached_tagcontent($tag)]} {
11036 set text $cached_tagcontent($tag)
11038 set text "[mc "Id"]: $tagids($tag)"
11040 appendwithlinks $text {}
11043 proc showtag {tag isnew} {
11044 global ctext cached_tagcontent tagids linknum tagobjid
11047 addtohistory [list showtag $tag 0] savectextpos
11049 $ctext conf -state normal
11054 maybe_scroll_ctext 1
11055 $ctext conf -state disabled
11059 proc showtags {id isnew} {
11060 global idtags ctext linknum
11063 addtohistory [list showtags $id 0] savectextpos
11065 $ctext conf -state normal
11070 foreach tag $idtags($id) {
11071 $ctext insert end $sep
11075 maybe_scroll_ctext 1
11076 $ctext conf -state disabled
11088 if {[info exists gitktmpdir]} {
11089 catch {file delete -force $gitktmpdir}
11093 proc mkfontdisp {font top which} {
11094 global fontattr fontpref $font NS use_ttk
11096 set fontpref($font) [set $font]
11097 ${NS}::button $top.${font}but -text $which \
11098 -command [list choosefont $font $which]
11099 ${NS}::label $top.$font -relief flat -font $font \
11100 -text $fontattr($font,family) -justify left
11101 grid x $top.${font}but $top.$font -sticky w
11104 proc choosefont {font which} {
11105 global fontparam fontlist fonttop fontattr
11108 set fontparam(which) $which
11109 set fontparam(font) $font
11110 set fontparam(family) [font actual $font -family]
11111 set fontparam(size) $fontattr($font,size)
11112 set fontparam(weight) $fontattr($font,weight)
11113 set fontparam(slant) $fontattr($font,slant)
11116 if {![winfo exists $top]} {
11118 eval font config sample [font actual $font]
11120 make_transient $top $prefstop
11121 wm title $top [mc "Gitk font chooser"]
11122 ${NS}::label $top.l -textvariable fontparam(which)
11123 pack $top.l -side top
11124 set fontlist [lsort [font families]]
11125 ${NS}::frame $top.f
11126 listbox $top.f.fam -listvariable fontlist \
11127 -yscrollcommand [list $top.f.sb set]
11128 bind $top.f.fam <<ListboxSelect>> selfontfam
11129 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11130 pack $top.f.sb -side right -fill y
11131 pack $top.f.fam -side left -fill both -expand 1
11132 pack $top.f -side top -fill both -expand 1
11133 ${NS}::frame $top.g
11134 spinbox $top.g.size -from 4 -to 40 -width 4 \
11135 -textvariable fontparam(size) \
11136 -validatecommand {string is integer -strict %s}
11137 checkbutton $top.g.bold -padx 5 \
11138 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11139 -variable fontparam(weight) -onvalue bold -offvalue normal
11140 checkbutton $top.g.ital -padx 5 \
11141 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11142 -variable fontparam(slant) -onvalue italic -offvalue roman
11143 pack $top.g.size $top.g.bold $top.g.ital -side left
11144 pack $top.g -side top
11145 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11147 $top.c create text 100 25 -anchor center -text $which -font sample \
11148 -fill black -tags text
11149 bind $top.c <Configure> [list centertext $top.c]
11150 pack $top.c -side top -fill x
11151 ${NS}::frame $top.buts
11152 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11153 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11154 bind $top <Key-Return> fontok
11155 bind $top <Key-Escape> fontcan
11156 grid $top.buts.ok $top.buts.can
11157 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11158 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11159 pack $top.buts -side bottom -fill x
11160 trace add variable fontparam write chg_fontparam
11163 $top.c itemconf text -text $which
11165 set i [lsearch -exact $fontlist $fontparam(family)]
11167 $top.f.fam selection set $i
11172 proc centertext {w} {
11173 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11177 global fontparam fontpref prefstop
11179 set f $fontparam(font)
11180 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11181 if {$fontparam(weight) eq "bold"} {
11182 lappend fontpref($f) "bold"
11184 if {$fontparam(slant) eq "italic"} {
11185 lappend fontpref($f) "italic"
11187 set w $prefstop.notebook.fonts.$f
11188 $w conf -text $fontparam(family) -font $fontpref($f)
11194 global fonttop fontparam
11196 if {[info exists fonttop]} {
11197 catch {destroy $fonttop}
11198 catch {font delete sample}
11204 if {[package vsatisfies [package provide Tk] 8.6]} {
11205 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11206 # function to make use of it.
11207 proc choosefont {font which} {
11208 tk fontchooser configure -title $which -font $font \
11209 -command [list on_choosefont $font $which]
11210 tk fontchooser show
11212 proc on_choosefont {font which newfont} {
11214 puts stderr "$font $newfont"
11215 array set f [font actual $newfont]
11216 set fontparam(which) $which
11217 set fontparam(font) $font
11218 set fontparam(family) $f(-family)
11219 set fontparam(size) $f(-size)
11220 set fontparam(weight) $f(-weight)
11221 set fontparam(slant) $f(-slant)
11226 proc selfontfam {} {
11227 global fonttop fontparam
11229 set i [$fonttop.f.fam curselection]
11231 set fontparam(family) [$fonttop.f.fam get $i]
11235 proc chg_fontparam {v sub op} {
11238 font config sample -$sub $fontparam($sub)
11241 # Create a property sheet tab page
11242 proc create_prefs_page {w} {
11244 set parent [join [lrange [split $w .] 0 end-1] .]
11245 if {[winfo class $parent] eq "TNotebook"} {
11248 ${NS}::labelframe $w
11252 proc prefspage_general {notebook} {
11253 global NS maxwidth maxgraphpct showneartags showlocalchanges
11254 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11255 global hideremotes want_ttk have_ttk maxrefs
11257 set page [create_prefs_page $notebook.general]
11259 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11260 grid $page.ldisp - -sticky w -pady 10
11261 ${NS}::label $page.spacer -text " "
11262 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11263 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11264 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11265 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11266 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11267 grid x $page.maxpctl $page.maxpct -sticky w
11268 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11269 -variable showlocalchanges
11270 grid x $page.showlocal -sticky w
11271 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11272 -variable autoselect
11273 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11274 grid x $page.autoselect $page.autosellen -sticky w
11275 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11276 -variable hideremotes
11277 grid x $page.hideremotes -sticky w
11279 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11280 grid $page.ddisp - -sticky w -pady 10
11281 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11282 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11283 grid x $page.tabstopl $page.tabstop -sticky w
11284 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11285 -variable showneartags
11286 grid x $page.ntag -sticky w
11287 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11288 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11289 grid x $page.maxrefsl $page.maxrefs -sticky w
11290 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11291 -variable limitdiffs
11292 grid x $page.ldiff -sticky w
11293 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11294 -variable perfile_attrs
11295 grid x $page.lattr -sticky w
11297 ${NS}::entry $page.extdifft -textvariable extdifftool
11298 ${NS}::frame $page.extdifff
11299 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11300 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11301 pack $page.extdifff.l $page.extdifff.b -side left
11302 pack configure $page.extdifff.l -padx 10
11303 grid x $page.extdifff $page.extdifft -sticky ew
11305 ${NS}::label $page.lgen -text [mc "General options"]
11306 grid $page.lgen - -sticky w -pady 10
11307 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11308 -text [mc "Use themed widgets"]
11310 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11312 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11314 grid x $page.want_ttk $page.ttk_note -sticky w
11318 proc prefspage_colors {notebook} {
11319 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11321 set page [create_prefs_page $notebook.colors]
11323 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11324 grid $page.cdisp - -sticky w -pady 10
11325 label $page.ui -padx 40 -relief sunk -background $uicolor
11326 ${NS}::button $page.uibut -text [mc "Interface"] \
11327 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11328 grid x $page.uibut $page.ui -sticky w
11329 label $page.bg -padx 40 -relief sunk -background $bgcolor
11330 ${NS}::button $page.bgbut -text [mc "Background"] \
11331 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11332 grid x $page.bgbut $page.bg -sticky w
11333 label $page.fg -padx 40 -relief sunk -background $fgcolor
11334 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11335 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11336 grid x $page.fgbut $page.fg -sticky w
11337 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11338 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11339 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11340 [list $ctext tag conf d0 -foreground]]
11341 grid x $page.diffoldbut $page.diffold -sticky w
11342 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11343 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11344 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11345 [list $ctext tag conf dresult -foreground]]
11346 grid x $page.diffnewbut $page.diffnew -sticky w
11347 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11348 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11349 -command [list choosecolor diffcolors 2 $page.hunksep \
11350 [mc "diff hunk header"] \
11351 [list $ctext tag conf hunksep -foreground]]
11352 grid x $page.hunksepbut $page.hunksep -sticky w
11353 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11354 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11355 -command [list choosecolor markbgcolor {} $page.markbgsep \
11356 [mc "marked line background"] \
11357 [list $ctext tag conf omark -background]]
11358 grid x $page.markbgbut $page.markbgsep -sticky w
11359 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11360 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11361 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11362 grid x $page.selbgbut $page.selbgsep -sticky w
11366 proc prefspage_fonts {notebook} {
11368 set page [create_prefs_page $notebook.fonts]
11369 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11370 grid $page.cfont - -sticky w -pady 10
11371 mkfontdisp mainfont $page [mc "Main font"]
11372 mkfontdisp textfont $page [mc "Diff display font"]
11373 mkfontdisp uifont $page [mc "User interface font"]
11378 global maxwidth maxgraphpct use_ttk NS
11379 global oldprefs prefstop showneartags showlocalchanges
11380 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11381 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11382 global hideremotes want_ttk have_ttk
11386 if {[winfo exists $top]} {
11390 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11391 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11392 set oldprefs($v) [set $v]
11395 wm title $top [mc "Gitk preferences"]
11396 make_transient $top .
11398 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11399 set notebook [ttk::notebook $top.notebook]
11401 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11404 lappend pages [prefspage_general $notebook] [mc "General"]
11405 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11406 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11408 foreach {page title} $pages {
11409 if {$use_notebook} {
11410 $notebook add $page -text $title
11412 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11413 -text $title -command [list raise $page]]
11414 $page configure -text $title
11415 grid $btn -row 0 -column [incr col] -sticky w
11416 grid $page -row 1 -column 0 -sticky news -columnspan 100
11420 if {!$use_notebook} {
11421 grid columnconfigure $notebook 0 -weight 1
11422 grid rowconfigure $notebook 1 -weight 1
11423 raise [lindex $pages 0]
11426 grid $notebook -sticky news -padx 2 -pady 2
11427 grid rowconfigure $top 0 -weight 1
11428 grid columnconfigure $top 0 -weight 1
11430 ${NS}::frame $top.buts
11431 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11432 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11433 bind $top <Key-Return> prefsok
11434 bind $top <Key-Escape> prefscan
11435 grid $top.buts.ok $top.buts.can
11436 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11437 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11438 grid $top.buts - - -pady 10 -sticky ew
11439 grid columnconfigure $top 2 -weight 1
11440 bind $top <Visibility> [list focus $top.buts.ok]
11443 proc choose_extdiff {} {
11446 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11448 set extdifftool $prog
11452 proc choosecolor {v vi w x cmd} {
11455 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11456 -title [mc "Gitk: choose color for %s" $x]]
11457 if {$c eq {}} return
11458 $w conf -background $c
11463 proc setselbg {c} {
11464 global bglist cflist
11465 foreach w $bglist {
11466 $w configure -selectbackground $c
11468 $cflist tag configure highlight \
11469 -background [$cflist cget -selectbackground]
11470 allcanvs itemconf secsel -fill $c
11473 # This sets the background color and the color scheme for the whole UI.
11474 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11475 # if we don't specify one ourselves, which makes the checkbuttons and
11476 # radiobuttons look bad. This chooses white for selectColor if the
11477 # background color is light, or black if it is dark.
11479 if {[tk windowingsystem] eq "win32"} { return }
11480 set bg [winfo rgb . $c]
11482 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11485 tk_setPalette background $c selectColor $selc
11491 foreach w $bglist {
11492 $w conf -background $c
11499 foreach w $fglist {
11500 $w conf -foreground $c
11502 allcanvs itemconf text -fill $c
11503 $canv itemconf circle -outline $c
11504 $canv itemconf markid -outline $c
11508 global oldprefs prefstop
11510 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11511 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11513 set $v $oldprefs($v)
11515 catch {destroy $prefstop}
11521 global maxwidth maxgraphpct
11522 global oldprefs prefstop showneartags showlocalchanges
11523 global fontpref mainfont textfont uifont
11524 global limitdiffs treediffs perfile_attrs
11527 catch {destroy $prefstop}
11531 if {$mainfont ne $fontpref(mainfont)} {
11532 set mainfont $fontpref(mainfont)
11533 parsefont mainfont $mainfont
11534 eval font configure mainfont [fontflags mainfont]
11535 eval font configure mainfontbold [fontflags mainfont 1]
11539 if {$textfont ne $fontpref(textfont)} {
11540 set textfont $fontpref(textfont)
11541 parsefont textfont $textfont
11542 eval font configure textfont [fontflags textfont]
11543 eval font configure textfontbold [fontflags textfont 1]
11545 if {$uifont ne $fontpref(uifont)} {
11546 set uifont $fontpref(uifont)
11547 parsefont uifont $uifont
11548 eval font configure uifont [fontflags uifont]
11551 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11552 if {$showlocalchanges} {
11558 if {$limitdiffs != $oldprefs(limitdiffs) ||
11559 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11560 # treediffs elements are limited by path;
11561 # won't have encodings cached if perfile_attrs was just turned on
11562 catch {unset treediffs}
11564 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11565 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11567 } elseif {$showneartags != $oldprefs(showneartags) ||
11568 $limitdiffs != $oldprefs(limitdiffs)} {
11571 if {$hideremotes != $oldprefs(hideremotes)} {
11576 proc formatdate {d} {
11577 global datetimeformat
11579 set d [clock format [lindex $d 0] -format $datetimeformat]
11584 # This list of encoding names and aliases is distilled from
11585 # http://www.iana.org/assignments/character-sets.
11586 # Not all of them are supported by Tcl.
11587 set encoding_aliases {
11588 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11589 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11590 { ISO-10646-UTF-1 csISO10646UTF1 }
11591 { ISO_646.basic:1983 ref csISO646basic1983 }
11592 { INVARIANT csINVARIANT }
11593 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11594 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11595 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11596 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11597 { NATS-DANO iso-ir-9-1 csNATSDANO }
11598 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11599 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11600 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11601 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11602 { ISO-2022-KR csISO2022KR }
11604 { ISO-2022-JP csISO2022JP }
11605 { ISO-2022-JP-2 csISO2022JP2 }
11606 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11607 csISO13JISC6220jp }
11608 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11609 { IT iso-ir-15 ISO646-IT csISO15Italian }
11610 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11611 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11612 { greek7-old iso-ir-18 csISO18Greek7Old }
11613 { latin-greek iso-ir-19 csISO19LatinGreek }
11614 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11615 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11616 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11617 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11618 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11619 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11620 { INIS iso-ir-49 csISO49INIS }
11621 { INIS-8 iso-ir-50 csISO50INIS8 }
11622 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11623 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11624 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11625 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11626 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11627 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11628 csISO60Norwegian1 }
11629 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11630 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11631 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11632 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11633 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11634 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11635 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11636 { greek7 iso-ir-88 csISO88Greek7 }
11637 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11638 { iso-ir-90 csISO90 }
11639 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11640 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11641 csISO92JISC62991984b }
11642 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11643 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11644 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11645 csISO95JIS62291984handadd }
11646 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11647 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11648 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11649 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11650 CP819 csISOLatin1 }
11651 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11652 { T.61-7bit iso-ir-102 csISO102T617bit }
11653 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11654 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11655 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11656 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11657 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11658 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11659 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11660 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11661 arabic csISOLatinArabic }
11662 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11663 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11664 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11665 greek greek8 csISOLatinGreek }
11666 { T.101-G2 iso-ir-128 csISO128T101G2 }
11667 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11669 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11670 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11671 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11672 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11673 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11674 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11675 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11676 csISOLatinCyrillic }
11677 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11678 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11679 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11680 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11681 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11682 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11683 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11684 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11685 { ISO_10367-box iso-ir-155 csISO10367Box }
11686 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11687 { latin-lap lap iso-ir-158 csISO158Lap }
11688 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11689 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11692 { JIS_X0201 X0201 csHalfWidthKatakana }
11693 { KSC5636 ISO646-KR csKSC5636 }
11694 { ISO-10646-UCS-2 csUnicode }
11695 { ISO-10646-UCS-4 csUCS4 }
11696 { DEC-MCS dec csDECMCS }
11697 { hp-roman8 roman8 r8 csHPRoman8 }
11698 { macintosh mac csMacintosh }
11699 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11701 { IBM038 EBCDIC-INT cp038 csIBM038 }
11702 { IBM273 CP273 csIBM273 }
11703 { IBM274 EBCDIC-BE CP274 csIBM274 }
11704 { IBM275 EBCDIC-BR cp275 csIBM275 }
11705 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11706 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11707 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11708 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11709 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11710 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11711 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11712 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11713 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11714 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11715 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11716 { IBM437 cp437 437 csPC8CodePage437 }
11717 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11718 { IBM775 cp775 csPC775Baltic }
11719 { IBM850 cp850 850 csPC850Multilingual }
11720 { IBM851 cp851 851 csIBM851 }
11721 { IBM852 cp852 852 csPCp852 }
11722 { IBM855 cp855 855 csIBM855 }
11723 { IBM857 cp857 857 csIBM857 }
11724 { IBM860 cp860 860 csIBM860 }
11725 { IBM861 cp861 861 cp-is csIBM861 }
11726 { IBM862 cp862 862 csPC862LatinHebrew }
11727 { IBM863 cp863 863 csIBM863 }
11728 { IBM864 cp864 csIBM864 }
11729 { IBM865 cp865 865 csIBM865 }
11730 { IBM866 cp866 866 csIBM866 }
11731 { IBM868 CP868 cp-ar csIBM868 }
11732 { IBM869 cp869 869 cp-gr csIBM869 }
11733 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11734 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11735 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11736 { IBM891 cp891 csIBM891 }
11737 { IBM903 cp903 csIBM903 }
11738 { IBM904 cp904 904 csIBBM904 }
11739 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11740 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11741 { IBM1026 CP1026 csIBM1026 }
11742 { EBCDIC-AT-DE csIBMEBCDICATDE }
11743 { EBCDIC-AT-DE-A csEBCDICATDEA }
11744 { EBCDIC-CA-FR csEBCDICCAFR }
11745 { EBCDIC-DK-NO csEBCDICDKNO }
11746 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11747 { EBCDIC-FI-SE csEBCDICFISE }
11748 { EBCDIC-FI-SE-A csEBCDICFISEA }
11749 { EBCDIC-FR csEBCDICFR }
11750 { EBCDIC-IT csEBCDICIT }
11751 { EBCDIC-PT csEBCDICPT }
11752 { EBCDIC-ES csEBCDICES }
11753 { EBCDIC-ES-A csEBCDICESA }
11754 { EBCDIC-ES-S csEBCDICESS }
11755 { EBCDIC-UK csEBCDICUK }
11756 { EBCDIC-US csEBCDICUS }
11757 { UNKNOWN-8BIT csUnknown8BiT }
11758 { MNEMONIC csMnemonic }
11760 { VISCII csVISCII }
11763 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11764 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11765 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11766 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11767 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11768 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11769 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11770 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11771 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11772 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11773 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11774 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11775 { IBM1047 IBM-1047 }
11776 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11777 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11778 { UNICODE-1-1 csUnicode11 }
11779 { CESU-8 csCESU-8 }
11780 { BOCU-1 csBOCU-1 }
11781 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11782 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11784 { ISO-8859-15 ISO_8859-15 Latin-9 }
11785 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11786 { GBK CP936 MS936 windows-936 }
11787 { JIS_Encoding csJISEncoding }
11788 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11789 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11791 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11792 { ISO-10646-UCS-Basic csUnicodeASCII }
11793 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11794 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11795 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11796 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11797 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11798 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11799 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11800 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11801 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11802 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11803 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11804 { Ventura-US csVenturaUS }
11805 { Ventura-International csVenturaInternational }
11806 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11807 { PC8-Turkish csPC8Turkish }
11808 { IBM-Symbols csIBMSymbols }
11809 { IBM-Thai csIBMThai }
11810 { HP-Legal csHPLegal }
11811 { HP-Pi-font csHPPiFont }
11812 { HP-Math8 csHPMath8 }
11813 { Adobe-Symbol-Encoding csHPPSMath }
11814 { HP-DeskTop csHPDesktop }
11815 { Ventura-Math csVenturaMath }
11816 { Microsoft-Publishing csMicrosoftPublishing }
11817 { Windows-31J csWindows31J }
11818 { GB2312 csGB2312 }
11822 proc tcl_encoding {enc} {
11823 global encoding_aliases tcl_encoding_cache
11824 if {[info exists tcl_encoding_cache($enc)]} {
11825 return $tcl_encoding_cache($enc)
11827 set names [encoding names]
11828 set lcnames [string tolower $names]
11829 set enc [string tolower $enc]
11830 set i [lsearch -exact $lcnames $enc]
11832 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11833 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11834 set i [lsearch -exact $lcnames $encx]
11838 foreach l $encoding_aliases {
11839 set ll [string tolower $l]
11840 if {[lsearch -exact $ll $enc] < 0} continue
11841 # look through the aliases for one that tcl knows about
11843 set i [lsearch -exact $lcnames $e]
11845 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11846 set i [lsearch -exact $lcnames $ex]
11856 set tclenc [lindex $names $i]
11858 set tcl_encoding_cache($enc) $tclenc
11862 proc gitattr {path attr default} {
11863 global path_attr_cache
11864 if {[info exists path_attr_cache($attr,$path)]} {
11865 set r $path_attr_cache($attr,$path)
11867 set r "unspecified"
11868 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11869 regexp "(.*): $attr: (.*)" $line m f r
11871 set path_attr_cache($attr,$path) $r
11873 if {$r eq "unspecified"} {
11879 proc cache_gitattr {attr pathlist} {
11880 global path_attr_cache
11882 foreach path $pathlist {
11883 if {![info exists path_attr_cache($attr,$path)]} {
11884 lappend newlist $path
11888 if {[tk windowingsystem] == "win32"} {
11889 # windows has a 32k limit on the arguments to a command...
11892 while {$newlist ne {}} {
11893 set head [lrange $newlist 0 [expr {$lim - 1}]]
11894 set newlist [lrange $newlist $lim end]
11895 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11896 foreach row [split $rlist "\n"] {
11897 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11898 if {[string index $path 0] eq "\""} {
11899 set path [encoding convertfrom [lindex $path 0]]
11901 set path_attr_cache($attr,$path) $value
11908 proc get_path_encoding {path} {
11909 global gui_encoding perfile_attrs
11910 set tcl_enc $gui_encoding
11911 if {$path ne {} && $perfile_attrs} {
11912 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11920 # First check that Tcl/Tk is recent enough
11921 if {[catch {package require Tk 8.4} err]} {
11922 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11923 Gitk requires at least Tcl/Tk 8.4." list
11927 # on OSX bring the current Wish process window to front
11928 if {[tk windowingsystem] eq "aqua"} {
11929 exec osascript -e [format {
11930 tell application "System Events"
11931 set frontmost of processes whose unix id is %d to true
11936 # Unset GIT_TRACE var if set
11937 if { [info exists ::env(GIT_TRACE)] } {
11938 unset ::env(GIT_TRACE)
11942 set wrcomcmd "git diff-tree --stdin -p --pretty"
11946 set gitencoding [exec git config --get i18n.commitencoding]
11949 set gitencoding [exec git config --get i18n.logoutputencoding]
11951 if {$gitencoding == ""} {
11952 set gitencoding "utf-8"
11954 set tclencoding [tcl_encoding $gitencoding]
11955 if {$tclencoding == {}} {
11956 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11959 set gui_encoding [encoding system]
11961 set enc [exec git config --get gui.encoding]
11963 set tclenc [tcl_encoding $enc]
11964 if {$tclenc ne {}} {
11965 set gui_encoding $tclenc
11967 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11972 set log_showroot true
11974 set log_showroot [exec git config --bool --get log.showroot]
11977 if {[tk windowingsystem] eq "aqua"} {
11978 set mainfont {{Lucida Grande} 9}
11979 set textfont {Monaco 9}
11980 set uifont {{Lucida Grande} 9 bold}
11981 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11983 set mainfont {sans 9}
11984 set textfont {monospace 9}
11985 set uifont {sans 9 bold}
11987 set mainfont {Helvetica 9}
11988 set textfont {Courier 9}
11989 set uifont {Helvetica 9 bold}
11992 set findmergefiles 0
12000 set cmitmode "patch"
12001 set wrapcomment "none"
12006 set showlocalchanges 1
12008 set datetimeformat "%Y-%m-%d %H:%M:%S"
12011 set perfile_attrs 0
12014 if {[tk windowingsystem] eq "aqua"} {
12015 set extdifftool "opendiff"
12017 set extdifftool "meld"
12020 set colors {green red blue magenta darkgrey brown orange}
12021 if {[tk windowingsystem] eq "win32"} {
12022 set uicolor SystemButtonFace
12023 set uifgcolor SystemButtonText
12024 set uifgdisabledcolor SystemDisabledText
12025 set bgcolor SystemWindow
12026 set fgcolor SystemWindowText
12027 set selectbgcolor SystemHighlight
12030 set uifgcolor black
12031 set uifgdisabledcolor "#999"
12034 set selectbgcolor gray85
12036 set diffcolors {red "#00a000" blue}
12038 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12041 set markbgcolor "#e0e0ff"
12043 set headbgcolor green
12044 set headfgcolor black
12045 set headoutlinecolor black
12046 set remotebgcolor #ffddaa
12047 set tagbgcolor yellow
12048 set tagfgcolor black
12049 set tagoutlinecolor black
12050 set reflinecolor black
12051 set filesepbgcolor #aaaaaa
12052 set filesepfgcolor black
12053 set linehoverbgcolor #ffff80
12054 set linehoverfgcolor black
12055 set linehoveroutlinecolor black
12056 set mainheadcirclecolor yellow
12057 set workingfilescirclecolor red
12058 set indexcirclecolor green
12059 set circlecolors {white blue gray blue blue}
12060 set linkfgcolor blue
12061 set circleoutlinecolor $fgcolor
12062 set foundbgcolor yellow
12063 set currentsearchhitbgcolor orange
12065 # button for popping up context menus
12066 if {[tk windowingsystem] eq "aqua"} {
12067 set ctxbut <Button-2>
12069 set ctxbut <Button-3>
12072 ## For msgcat loading, first locate the installation location.
12073 if { [info exists ::env(GITK_MSGSDIR)] } {
12074 ## Msgsdir was manually set in the environment.
12075 set gitk_msgsdir $::env(GITK_MSGSDIR)
12077 ## Let's guess the prefix from argv0.
12078 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12079 set gitk_libdir [file join $gitk_prefix share gitk lib]
12080 set gitk_msgsdir [file join $gitk_libdir msgs]
12084 ## Internationalization (i18n) through msgcat and gettext. See
12085 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12086 package require msgcat
12087 namespace import ::msgcat::mc
12088 ## And eventually load the actual message catalog
12089 ::msgcat::mcload $gitk_msgsdir
12092 # follow the XDG base directory specification by default. See
12093 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12094 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12095 # XDG_CONFIG_HOME environment variable is set
12096 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12097 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12099 # default XDG_CONFIG_HOME
12100 set config_file "~/.config/git/gitk"
12101 set config_file_tmp "~/.config/git/gitk-tmp"
12103 if {![file exists $config_file]} {
12104 # for backward compatibility use the old config file if it exists
12105 if {[file exists "~/.gitk"]} {
12106 set config_file "~/.gitk"
12107 set config_file_tmp "~/.gitk-tmp"
12108 } elseif {![file exists [file dirname $config_file]]} {
12109 file mkdir [file dirname $config_file]
12112 source $config_file
12115 parsefont mainfont $mainfont
12116 eval font create mainfont [fontflags mainfont]
12117 eval font create mainfontbold [fontflags mainfont 1]
12119 parsefont textfont $textfont
12120 eval font create textfont [fontflags textfont]
12121 eval font create textfontbold [fontflags textfont 1]
12123 parsefont uifont $uifont
12124 eval font create uifont [fontflags uifont]
12130 # check that we can find a .git directory somewhere...
12131 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12132 show_error {} . [mc "Cannot find a git repository here."]
12137 set selectheadid {}
12140 set cmdline_files {}
12142 set revtreeargscmd {}
12143 foreach arg $argv {
12144 switch -glob -- $arg {
12147 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12150 "--select-commit=*" {
12151 set selecthead [string range $arg 16 end]
12154 set revtreeargscmd [string range $arg 10 end]
12157 lappend revtreeargs $arg
12163 if {$selecthead eq "HEAD"} {
12167 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12168 # no -- on command line, but some arguments (other than --argscmd)
12170 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12171 set cmdline_files [split $f "\n"]
12172 set n [llength $cmdline_files]
12173 set revtreeargs [lrange $revtreeargs 0 end-$n]
12174 # Unfortunately git rev-parse doesn't produce an error when
12175 # something is both a revision and a filename. To be consistent
12176 # with git log and git rev-list, check revtreeargs for filenames.
12177 foreach arg $revtreeargs {
12178 if {[file exists $arg]} {
12179 show_error {} . [mc "Ambiguous argument '%s': both revision\
12180 and filename" $arg]
12185 # unfortunately we get both stdout and stderr in $err,
12186 # so look for "fatal:".
12187 set i [string first "fatal:" $err]
12189 set err [string range $err [expr {$i + 6}] end]
12191 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12196 set nullid "0000000000000000000000000000000000000000"
12197 set nullid2 "0000000000000000000000000000000000000001"
12198 set nullfile "/dev/null"
12200 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12201 if {![info exists have_ttk]} {
12202 set have_ttk [llength [info commands ::ttk::style]]
12204 set use_ttk [expr {$have_ttk && $want_ttk}]
12205 set NS [expr {$use_ttk ? "ttk" : ""}]
12207 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12210 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12211 set show_notes "--show-notes"
12221 set highlight_paths {}
12223 set searchdirn -forwards
12226 set diffelide {0 0}
12227 set markingmatches 0
12228 set linkentercount 0
12229 set need_redisplay 0
12236 set selectedhlview [mc "None"]
12237 set highlight_related [mc "None"]
12238 set highlight_files {}
12239 set viewfiles(0) {}
12242 set viewargscmd(0) {}
12244 set selectedline {}
12252 set hasworktree [hasworktree]
12254 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12255 set cdup [exec git rev-parse --show-cdup]
12257 set worktree [exec git rev-parse --show-toplevel]
12261 image create photo gitlogo -width 16 -height 16
12263 image create photo gitlogominus -width 4 -height 2
12264 gitlogominus put #C00000 -to 0 0 4 2
12265 gitlogo copy gitlogominus -to 1 5
12266 gitlogo copy gitlogominus -to 6 5
12267 gitlogo copy gitlogominus -to 11 5
12268 image delete gitlogominus
12270 image create photo gitlogoplus -width 4 -height 4
12271 gitlogoplus put #008000 -to 1 0 3 4
12272 gitlogoplus put #008000 -to 0 1 4 3
12273 gitlogo copy gitlogoplus -to 1 9
12274 gitlogo copy gitlogoplus -to 6 9
12275 gitlogo copy gitlogoplus -to 11 9
12276 image delete gitlogoplus
12278 image create photo gitlogo32 -width 32 -height 32
12279 gitlogo32 copy gitlogo -zoom 2 2
12281 wm iconphoto . -default gitlogo gitlogo32
12283 # wait for the window to become visible
12284 tkwait visibility .
12285 wm title . "$appname: [reponame]"
12289 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12290 # create a view for the files/dirs specified on the command line
12294 set viewname(1) [mc "Command line"]
12295 set viewfiles(1) $cmdline_files
12296 set viewargs(1) $revtreeargs
12297 set viewargscmd(1) $revtreeargscmd
12301 .bar.view entryconf [mca "Edit view..."] -state normal
12302 .bar.view entryconf [mca "Delete view"] -state normal
12305 if {[info exists permviews]} {
12306 foreach v $permviews {
12309 set viewname($n) [lindex $v 0]
12310 set viewfiles($n) [lindex $v 1]
12311 set viewargs($n) [lindex $v 2]
12312 set viewargscmd($n) [lindex $v 3]
12318 if {[tk windowingsystem] eq "win32"} {
12326 # indent-tabs-mode: t