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
297 } elseif
{[lsearch
-exact $revs --all] >= 0} {
300 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
301 # we get stdout followed by stderr in $err
302 # for an unknown rev, git rev-parse echoes it and then errors out
303 set errlines
[split $err "\n"]
305 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
306 set line
[lindex
$errlines $l]
307 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
308 if {[string match
"fatal:*" $line]} {
309 if {[string match
"fatal: ambiguous argument*" $line]
311 if {[llength
$badrev] == 1} {
312 set err
"unknown revision $badrev"
314 set err
"unknown revisions: [join $badrev ", "]"
317 set err
[join [lrange
$errlines $l end
] "\n"]
324 error_popup
"[mc "Error parsing revisions
:"] $err"
331 foreach id
[split $ids "\n"] {
332 if {$id eq
"--gitk-symmetric-diff-marker"} {
334 } elseif
{[string match
"^*" $id]} {
341 lappend neg
[string range
$id 1 end
]
346 lset ret end
$id...
[lindex
$ret end
]
352 set vposids
($view) $pos
353 set vnegids
($view) $neg
357 # Start off a git log process and arrange to read its output
358 proc start_rev_list
{view
} {
359 global startmsecs commitidx viewcomplete curview
361 global viewargs viewargscmd viewfiles vfilelimit
362 global showlocalchanges
363 global viewactive viewinstances vmergeonly
364 global mainheadid viewmainheadid viewmainheadid_orig
365 global vcanopt vflags vrevs vorigargs
368 set startmsecs
[clock clicks
-milliseconds]
369 set commitidx
($view) 0
370 # these are set this way for the error exits
371 set viewcomplete
($view) 1
372 set viewactive
($view) 0
375 set args
$viewargs($view)
376 if {$viewargscmd($view) ne
{}} {
378 set str
[exec sh
-c $viewargscmd($view)]
380 error_popup
"[mc "Error executing
--argscmd command:"] $err"
383 set args
[concat
$args [split $str "\n"]]
385 set vcanopt
($view) [parseviewargs
$view $args]
387 set files
$viewfiles($view)
388 if {$vmergeonly($view)} {
389 set files
[unmerged_files
$files]
392 if {$nr_unmerged == 0} {
393 error_popup
[mc
"No files selected: --merge specified but\
394 no files are unmerged."]
396 error_popup
[mc
"No files selected: --merge specified but\
397 no unmerged files are within file limit."]
402 set vfilelimit
($view) $files
404 if {$vcanopt($view)} {
405 set revs
[parseviewrevs
$view $vrevs($view)]
409 set args
[concat
$vflags($view) $revs]
411 set args
$vorigargs($view)
415 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
416 --parents --boundary $args "--" $files] r
]
418 error_popup
"[mc "Error executing git log
:"] $err"
421 set i
[reg_instance
$fd]
422 set viewinstances
($view) [list
$i]
423 set viewmainheadid
($view) $mainheadid
424 set viewmainheadid_orig
($view) $mainheadid
425 if {$files ne
{} && $mainheadid ne
{}} {
426 get_viewmainhead
$view
428 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
429 interestedin
$viewmainheadid($view) dodiffindex
431 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
432 if {$tclencoding != {}} {
433 fconfigure
$fd -encoding $tclencoding
435 filerun
$fd [list getcommitlines
$fd $i $view 0]
436 nowbusy
$view [mc
"Reading"]
437 set viewcomplete
($view) 0
438 set viewactive
($view) 1
442 proc stop_instance
{inst
} {
443 global commfd leftover
445 set fd
$commfd($inst)
449 if {$
::tcl_platform
(platform
) eq
{windows
}} {
450 exec taskkill
/pid
$pid
458 unset leftover
($inst)
461 proc stop_backends
{} {
464 foreach inst
[array names commfd
] {
469 proc stop_rev_list
{view
} {
472 foreach inst
$viewinstances($view) {
475 set viewinstances
($view) {}
478 proc reset_pending_select
{selid
} {
479 global pending_select mainheadid selectheadid
482 set pending_select
$selid
483 } elseif
{$selectheadid ne
{}} {
484 set pending_select
$selectheadid
486 set pending_select
$mainheadid
490 proc getcommits
{selid
} {
491 global canv curview need_redisplay viewactive
494 if {[start_rev_list
$curview]} {
495 reset_pending_select
$selid
496 show_status
[mc
"Reading commits..."]
499 show_status
[mc
"No commits selected"]
503 proc updatecommits
{} {
504 global curview vcanopt vorigargs vfilelimit viewinstances
505 global viewactive viewcomplete tclencoding
506 global startmsecs showneartags showlocalchanges
507 global mainheadid viewmainheadid viewmainheadid_orig pending_select
509 global varcid vposids vnegids vflags vrevs
512 set hasworktree
[hasworktree
]
515 if {$mainheadid ne
$viewmainheadid_orig($view)} {
516 if {$showlocalchanges} {
519 set viewmainheadid
($view) $mainheadid
520 set viewmainheadid_orig
($view) $mainheadid
521 if {$vfilelimit($view) ne
{}} {
522 get_viewmainhead
$view
525 if {$showlocalchanges} {
528 if {$vcanopt($view)} {
529 set oldpos
$vposids($view)
530 set oldneg
$vnegids($view)
531 set revs
[parseviewrevs
$view $vrevs($view)]
535 # note: getting the delta when negative refs change is hard,
536 # and could require multiple git log invocations, so in that
537 # case we ask git log for all the commits (not just the delta)
538 if {$oldneg eq
$vnegids($view)} {
541 # take out positive refs that we asked for before or
542 # that we have already seen
544 if {[string length
$rev] == 40} {
545 if {[lsearch
-exact $oldpos $rev] < 0
546 && ![info exists varcid
($view,$rev)]} {
551 lappend
$newrevs $rev
554 if {$npos == 0} return
556 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
558 set args
[concat
$vflags($view) $revs --not $oldpos]
560 set args
$vorigargs($view)
563 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
564 --parents --boundary $args "--" $vfilelimit($view)] r
]
566 error_popup
"[mc "Error executing git log
:"] $err"
569 if {$viewactive($view) == 0} {
570 set startmsecs
[clock clicks
-milliseconds]
572 set i
[reg_instance
$fd]
573 lappend viewinstances
($view) $i
574 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
575 if {$tclencoding != {}} {
576 fconfigure
$fd -encoding $tclencoding
578 filerun
$fd [list getcommitlines
$fd $i $view 1]
579 incr viewactive
($view)
580 set viewcomplete
($view) 0
581 reset_pending_select
{}
582 nowbusy
$view [mc
"Reading"]
588 proc reloadcommits
{} {
589 global curview viewcomplete selectedline currentid thickerline
590 global showneartags treediffs commitinterest cached_commitrow
594 if {$selectedline ne
{}} {
598 if {!$viewcomplete($curview)} {
599 stop_rev_list
$curview
603 catch
{unset currentid
}
604 catch
{unset thickerline
}
605 catch
{unset treediffs
}
612 catch
{unset commitinterest
}
613 catch
{unset cached_commitrow
}
614 catch
{unset targetid
}
620 # This makes a string representation of a positive integer which
621 # sorts as a string in numerical order
624 return [format
"%x" $n]
625 } elseif
{$n < 256} {
626 return [format
"x%.2x" $n]
627 } elseif
{$n < 65536} {
628 return [format
"y%.4x" $n]
630 return [format
"z%.8x" $n]
633 # Procedures used in reordering commits from git log (without
634 # --topo-order) into the order for display.
636 proc varcinit
{view
} {
637 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
638 global vtokmod varcmod vrowmod varcix vlastins
640 set varcstart
($view) {{}}
641 set vupptr
($view) {0}
642 set vdownptr
($view) {0}
643 set vleftptr
($view) {0}
644 set vbackptr
($view) {0}
645 set varctok
($view) {{}}
646 set varcrow
($view) {{}}
647 set vtokmod
($view) {}
650 set varcix
($view) {{}}
651 set vlastins
($view) {0}
654 proc resetvarcs
{view
} {
655 global varcid varccommits parents children vseedcount ordertok
658 foreach vid
[array names varcid
$view,*] {
663 foreach vid
[array names vshortids
$view,*] {
664 unset vshortids
($vid)
666 # some commits might have children but haven't been seen yet
667 foreach vid
[array names children
$view,*] {
670 foreach va
[array names varccommits
$view,*] {
671 unset varccommits
($va)
673 foreach vd
[array names vseedcount
$view,*] {
674 unset vseedcount
($vd)
676 catch
{unset ordertok
}
679 # returns a list of the commits with no children
681 global vdownptr vleftptr varcstart
684 set a
[lindex
$vdownptr($v) 0]
686 lappend ret
[lindex
$varcstart($v) $a]
687 set a
[lindex
$vleftptr($v) $a]
692 proc newvarc
{view id
} {
693 global varcid varctok parents children vdatemode
694 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
695 global commitdata commitinfo vseedcount varccommits vlastins
697 set a
[llength
$varctok($view)]
699 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
700 if {![info exists commitinfo
($id)]} {
701 parsecommit
$id $commitdata($id) 1
703 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
704 if {![string is integer
-strict $cdate]} {
707 if {![info exists vseedcount
($view,$cdate)]} {
708 set vseedcount
($view,$cdate) -1
710 set c
[incr vseedcount
($view,$cdate)]
711 set cdate
[expr {$cdate ^
0xffffffff}]
712 set tok
"s[strrep $cdate][strrep $c]"
717 if {[llength
$children($vid)] > 0} {
718 set kid
[lindex
$children($vid) end
]
719 set k
$varcid($view,$kid)
720 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
723 set tok
[lindex
$varctok($view) $k]
727 set i
[lsearch
-exact $parents($view,$ki) $id]
728 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
729 append tok
[strrep
$j]
731 set c
[lindex
$vlastins($view) $ka]
732 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
734 set b
[lindex
$vdownptr($view) $ka]
736 set b
[lindex
$vleftptr($view) $c]
738 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
740 set b
[lindex
$vleftptr($view) $c]
743 lset vdownptr
($view) $ka $a
744 lappend vbackptr
($view) 0
746 lset vleftptr
($view) $c $a
747 lappend vbackptr
($view) $c
749 lset vlastins
($view) $ka $a
750 lappend vupptr
($view) $ka
751 lappend vleftptr
($view) $b
753 lset vbackptr
($view) $b $a
755 lappend varctok
($view) $tok
756 lappend varcstart
($view) $id
757 lappend vdownptr
($view) 0
758 lappend varcrow
($view) {}
759 lappend varcix
($view) {}
760 set varccommits
($view,$a) {}
761 lappend vlastins
($view) 0
765 proc splitvarc
{p v
} {
766 global varcid varcstart varccommits varctok vtokmod
767 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
769 set oa
$varcid($v,$p)
770 set otok
[lindex
$varctok($v) $oa]
771 set ac
$varccommits($v,$oa)
772 set i
[lsearch
-exact $varccommits($v,$oa) $p]
774 set na
[llength
$varctok($v)]
775 # "%" sorts before "0"...
776 set tok
"$otok%[strrep $i]"
777 lappend varctok
($v) $tok
778 lappend varcrow
($v) {}
779 lappend varcix
($v) {}
780 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
781 set varccommits
($v,$na) [lrange
$ac $i end
]
782 lappend varcstart
($v) $p
783 foreach id
$varccommits($v,$na) {
784 set varcid
($v,$id) $na
786 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
787 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
788 lset vdownptr
($v) $oa $na
789 lset vlastins
($v) $oa 0
790 lappend vupptr
($v) $oa
791 lappend vleftptr
($v) 0
792 lappend vbackptr
($v) 0
793 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
794 lset vupptr
($v) $b $na
796 if {[string compare
$otok $vtokmod($v)] <= 0} {
801 proc renumbervarc
{a v
} {
802 global parents children varctok varcstart varccommits
803 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
805 set t1
[clock clicks
-milliseconds]
811 if {[info exists isrelated
($a)]} {
813 set id
[lindex
$varccommits($v,$a) end
]
814 foreach p
$parents($v,$id) {
815 if {[info exists varcid
($v,$p)]} {
816 set isrelated
($varcid($v,$p)) 1
821 set b
[lindex
$vdownptr($v) $a]
824 set b
[lindex
$vleftptr($v) $a]
826 set a
[lindex
$vupptr($v) $a]
832 if {![info exists kidchanged
($a)]} continue
833 set id
[lindex
$varcstart($v) $a]
834 if {[llength
$children($v,$id)] > 1} {
835 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
838 set oldtok
[lindex
$varctok($v) $a]
839 if {!$vdatemode($v)} {
845 set kid
[last_real_child
$v,$id]
847 set k
$varcid($v,$kid)
848 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
851 set tok
[lindex
$varctok($v) $k]
855 set i
[lsearch
-exact $parents($v,$ki) $id]
856 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
857 append tok
[strrep
$j]
859 if {$tok eq
$oldtok} {
862 set id
[lindex
$varccommits($v,$a) end
]
863 foreach p
$parents($v,$id) {
864 if {[info exists varcid
($v,$p)]} {
865 set kidchanged
($varcid($v,$p)) 1
870 lset varctok
($v) $a $tok
871 set b
[lindex
$vupptr($v) $a]
873 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
876 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
879 set c
[lindex
$vbackptr($v) $a]
880 set d
[lindex
$vleftptr($v) $a]
882 lset vdownptr
($v) $b $d
884 lset vleftptr
($v) $c $d
887 lset vbackptr
($v) $d $c
889 if {[lindex
$vlastins($v) $b] == $a} {
890 lset vlastins
($v) $b $c
892 lset vupptr
($v) $a $ka
893 set c
[lindex
$vlastins($v) $ka]
895 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
897 set b
[lindex
$vdownptr($v) $ka]
899 set b
[lindex
$vleftptr($v) $c]
902 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
904 set b
[lindex
$vleftptr($v) $c]
907 lset vdownptr
($v) $ka $a
908 lset vbackptr
($v) $a 0
910 lset vleftptr
($v) $c $a
911 lset vbackptr
($v) $a $c
913 lset vleftptr
($v) $a $b
915 lset vbackptr
($v) $b $a
917 lset vlastins
($v) $ka $a
920 foreach id
[array names sortkids
] {
921 if {[llength
$children($v,$id)] > 1} {
922 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
926 set t2
[clock clicks
-milliseconds]
927 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
930 # Fix up the graph after we have found out that in view $v,
931 # $p (a commit that we have already seen) is actually the parent
932 # of the last commit in arc $a.
933 proc fix_reversal
{p a v
} {
934 global varcid varcstart varctok vupptr
936 set pa
$varcid($v,$p)
937 if {$p ne
[lindex
$varcstart($v) $pa]} {
939 set pa
$varcid($v,$p)
941 # seeds always need to be renumbered
942 if {[lindex
$vupptr($v) $pa] == 0 ||
943 [string compare
[lindex
$varctok($v) $a] \
944 [lindex
$varctok($v) $pa]] > 0} {
949 proc insertrow
{id p v
} {
950 global cmitlisted children parents varcid varctok vtokmod
951 global varccommits ordertok commitidx numcommits curview
952 global targetid targetrow vshortids
956 set cmitlisted
($vid) 1
957 set children
($vid) {}
958 set parents
($vid) [list
$p]
959 set a
[newvarc
$v $id]
961 lappend vshortids
($v,[string range
$id 0 3]) $id
962 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
965 lappend varccommits
($v,$a) $id
967 if {[llength
[lappend children
($vp) $id]] > 1} {
968 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
969 catch
{unset ordertok
}
971 fix_reversal
$p $a $v
973 if {$v == $curview} {
974 set numcommits
$commitidx($v)
976 if {[info exists targetid
]} {
977 if {![comes_before
$targetid $p]} {
984 proc insertfakerow
{id p
} {
985 global varcid varccommits parents children cmitlisted
986 global commitidx varctok vtokmod targetid targetrow curview numcommits
990 set i
[lsearch
-exact $varccommits($v,$a) $p]
992 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
995 set children
($v,$id) {}
996 set parents
($v,$id) [list
$p]
997 set varcid
($v,$id) $a
998 lappend children
($v,$p) $id
999 set cmitlisted
($v,$id) 1
1000 set numcommits
[incr commitidx
($v)]
1001 # note we deliberately don't update varcstart($v) even if $i == 0
1002 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
1004 if {[info exists targetid
]} {
1005 if {![comes_before
$targetid $p]} {
1013 proc removefakerow
{id
} {
1014 global varcid varccommits parents children commitidx
1015 global varctok vtokmod cmitlisted currentid selectedline
1016 global targetid curview numcommits
1019 if {[llength
$parents($v,$id)] != 1} {
1020 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1023 set p
[lindex
$parents($v,$id) 0]
1024 set a
$varcid($v,$id)
1025 set i
[lsearch
-exact $varccommits($v,$a) $id]
1027 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1030 unset varcid
($v,$id)
1031 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1032 unset parents
($v,$id)
1033 unset children
($v,$id)
1034 unset cmitlisted
($v,$id)
1035 set numcommits
[incr commitidx
($v) -1]
1036 set j
[lsearch
-exact $children($v,$p) $id]
1038 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1041 if {[info exist currentid
] && $id eq
$currentid} {
1045 if {[info exists targetid
] && $targetid eq
$id} {
1052 proc real_children
{vp
} {
1053 global children nullid nullid2
1056 foreach id
$children($vp) {
1057 if {$id ne
$nullid && $id ne
$nullid2} {
1064 proc first_real_child
{vp
} {
1065 global children nullid nullid2
1067 foreach id
$children($vp) {
1068 if {$id ne
$nullid && $id ne
$nullid2} {
1075 proc last_real_child
{vp
} {
1076 global children nullid nullid2
1078 set kids
$children($vp)
1079 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1080 set id
[lindex
$kids $i]
1081 if {$id ne
$nullid && $id ne
$nullid2} {
1088 proc vtokcmp
{v a b
} {
1089 global varctok varcid
1091 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1092 [lindex
$varctok($v) $varcid($v,$b)]]
1095 # This assumes that if lim is not given, the caller has checked that
1096 # arc a's token is less than $vtokmod($v)
1097 proc modify_arc
{v a
{lim
{}}} {
1098 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1101 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1104 set r
[lindex
$varcrow($v) $a]
1105 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1108 set vtokmod
($v) [lindex
$varctok($v) $a]
1110 if {$v == $curview} {
1111 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1112 set a
[lindex
$vupptr($v) $a]
1118 set lim
[llength
$varccommits($v,$a)]
1120 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1127 proc update_arcrows
{v
} {
1128 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1129 global varcid vrownum varcorder varcix varccommits
1130 global vupptr vdownptr vleftptr varctok
1131 global displayorder parentlist curview cached_commitrow
1133 if {$vrowmod($v) == $commitidx($v)} return
1134 if {$v == $curview} {
1135 if {[llength
$displayorder] > $vrowmod($v)} {
1136 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1137 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1139 catch
{unset cached_commitrow
}
1141 set narctot
[expr {[llength
$varctok($v)] - 1}]
1143 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1144 # go up the tree until we find something that has a row number,
1145 # or we get to a seed
1146 set a
[lindex
$vupptr($v) $a]
1149 set a
[lindex
$vdownptr($v) 0]
1152 set varcorder
($v) [list
$a]
1153 lset varcix
($v) $a 0
1154 lset varcrow
($v) $a 0
1158 set arcn
[lindex
$varcix($v) $a]
1159 if {[llength
$vrownum($v)] > $arcn + 1} {
1160 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1161 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1163 set row
[lindex
$varcrow($v) $a]
1167 incr row
[llength
$varccommits($v,$a)]
1168 # go down if possible
1169 set b
[lindex
$vdownptr($v) $a]
1171 # if not, go left, or go up until we can go left
1173 set b
[lindex
$vleftptr($v) $a]
1175 set a
[lindex
$vupptr($v) $a]
1181 lappend vrownum
($v) $row
1182 lappend varcorder
($v) $a
1183 lset varcix
($v) $a $arcn
1184 lset varcrow
($v) $a $row
1186 set vtokmod
($v) [lindex
$varctok($v) $p]
1188 set vrowmod
($v) $row
1189 if {[info exists currentid
]} {
1190 set selectedline
[rowofcommit
$currentid]
1194 # Test whether view $v contains commit $id
1195 proc commitinview
{id v
} {
1198 return [info exists varcid
($v,$id)]
1201 # Return the row number for commit $id in the current view
1202 proc rowofcommit
{id
} {
1203 global varcid varccommits varcrow curview cached_commitrow
1204 global varctok vtokmod
1207 if {![info exists varcid
($v,$id)]} {
1208 puts
"oops rowofcommit no arc for [shortids $id]"
1211 set a
$varcid($v,$id)
1212 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1215 if {[info exists cached_commitrow
($id)]} {
1216 return $cached_commitrow($id)
1218 set i
[lsearch
-exact $varccommits($v,$a) $id]
1220 puts
"oops didn't find commit [shortids $id] in arc $a"
1223 incr i
[lindex
$varcrow($v) $a]
1224 set cached_commitrow
($id) $i
1228 # Returns 1 if a is on an earlier row than b, otherwise 0
1229 proc comes_before
{a b
} {
1230 global varcid varctok curview
1233 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1234 ![info exists varcid
($v,$b)]} {
1237 if {$varcid($v,$a) != $varcid($v,$b)} {
1238 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1239 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1241 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1244 proc bsearch
{l elt
} {
1245 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1250 while {$hi - $lo > 1} {
1251 set mid
[expr {int
(($lo + $hi) / 2)}]
1252 set t
[lindex
$l $mid]
1255 } elseif
{$elt > $t} {
1264 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1265 proc make_disporder
{start end
} {
1266 global vrownum curview commitidx displayorder parentlist
1267 global varccommits varcorder parents vrowmod varcrow
1268 global d_valid_start d_valid_end
1270 if {$end > $vrowmod($curview)} {
1271 update_arcrows
$curview
1273 set ai
[bsearch
$vrownum($curview) $start]
1274 set start
[lindex
$vrownum($curview) $ai]
1275 set narc
[llength
$vrownum($curview)]
1276 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1277 set a
[lindex
$varcorder($curview) $ai]
1278 set l
[llength
$displayorder]
1279 set al
[llength
$varccommits($curview,$a)]
1280 if {$l < $r + $al} {
1282 set pad
[ntimes
[expr {$r - $l}] {}]
1283 set displayorder
[concat
$displayorder $pad]
1284 set parentlist
[concat
$parentlist $pad]
1285 } elseif
{$l > $r} {
1286 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1287 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1289 foreach id
$varccommits($curview,$a) {
1290 lappend displayorder
$id
1291 lappend parentlist
$parents($curview,$id)
1293 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1295 foreach id
$varccommits($curview,$a) {
1296 lset displayorder
$i $id
1297 lset parentlist
$i $parents($curview,$id)
1305 proc commitonrow
{row
} {
1308 set id
[lindex
$displayorder $row]
1310 make_disporder
$row [expr {$row + 1}]
1311 set id
[lindex
$displayorder $row]
1316 proc closevarcs
{v
} {
1317 global varctok varccommits varcid parents children
1318 global cmitlisted commitidx vtokmod
1320 set missing_parents
0
1322 set narcs
[llength
$varctok($v)]
1323 for {set a
1} {$a < $narcs} {incr a
} {
1324 set id
[lindex
$varccommits($v,$a) end
]
1325 foreach p
$parents($v,$id) {
1326 if {[info exists varcid
($v,$p)]} continue
1327 # add p as a new commit
1328 incr missing_parents
1329 set cmitlisted
($v,$p) 0
1330 set parents
($v,$p) {}
1331 if {[llength
$children($v,$p)] == 1 &&
1332 [llength
$parents($v,$id)] == 1} {
1335 set b
[newvarc
$v $p]
1337 set varcid
($v,$p) $b
1338 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1341 lappend varccommits
($v,$b) $p
1343 set scripts
[check_interest
$p $scripts]
1346 if {$missing_parents > 0} {
1347 foreach s
$scripts {
1353 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1354 # Assumes we already have an arc for $rwid.
1355 proc rewrite_commit
{v id rwid
} {
1356 global children parents varcid varctok vtokmod varccommits
1358 foreach ch
$children($v,$id) {
1359 # make $rwid be $ch's parent in place of $id
1360 set i
[lsearch
-exact $parents($v,$ch) $id]
1362 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1364 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1365 # add $ch to $rwid's children and sort the list if necessary
1366 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1367 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1368 $children($v,$rwid)]
1370 # fix the graph after joining $id to $rwid
1371 set a
$varcid($v,$ch)
1372 fix_reversal
$rwid $a $v
1373 # parentlist is wrong for the last element of arc $a
1374 # even if displayorder is right, hence the 3rd arg here
1375 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1379 # Mechanism for registering a command to be executed when we come
1380 # across a particular commit. To handle the case when only the
1381 # prefix of the commit is known, the commitinterest array is now
1382 # indexed by the first 4 characters of the ID. Each element is a
1383 # list of id, cmd pairs.
1384 proc interestedin
{id cmd
} {
1385 global commitinterest
1387 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1390 proc check_interest
{id scripts
} {
1391 global commitinterest
1393 set prefix
[string range
$id 0 3]
1394 if {[info exists commitinterest
($prefix)]} {
1396 foreach
{i
script} $commitinterest($prefix) {
1397 if {[string match
"$i*" $id]} {
1398 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1400 lappend newlist
$i $script
1403 if {$newlist ne
{}} {
1404 set commitinterest
($prefix) $newlist
1406 unset commitinterest
($prefix)
1412 proc getcommitlines
{fd inst view updating
} {
1413 global cmitlisted leftover
1414 global commitidx commitdata vdatemode
1415 global parents children curview hlview
1416 global idpending ordertok
1417 global varccommits varcid varctok vtokmod vfilelimit vshortids
1419 set stuff
[read $fd 500000]
1420 # git log doesn't terminate the last commit with a null...
1421 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1428 global commfd viewcomplete viewactive viewname
1429 global viewinstances
1431 set i
[lsearch
-exact $viewinstances($view) $inst]
1433 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1435 # set it blocking so we wait for the process to terminate
1436 fconfigure
$fd -blocking 1
1437 if {[catch
{close
$fd} err
]} {
1439 if {$view != $curview} {
1440 set fv
" for the \"$viewname($view)\" view"
1442 if {[string range
$err 0 4] == "usage"} {
1443 set err
"Gitk: error reading commits$fv:\
1444 bad arguments to git log."
1445 if {$viewname($view) eq
"Command line"} {
1447 " (Note: arguments to gitk are passed to git log\
1448 to allow selection of commits to be displayed.)"
1451 set err
"Error reading commits$fv: $err"
1455 if {[incr viewactive
($view) -1] <= 0} {
1456 set viewcomplete
($view) 1
1457 # Check if we have seen any ids listed as parents that haven't
1458 # appeared in the list
1462 if {$view == $curview} {
1471 set i
[string first
"\0" $stuff $start]
1473 append leftover
($inst) [string range
$stuff $start end
]
1477 set cmit
$leftover($inst)
1478 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1479 set leftover
($inst) {}
1481 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1483 set start
[expr {$i + 1}]
1484 set j
[string first
"\n" $cmit]
1487 if {$j >= 0 && [string match
"commit *" $cmit]} {
1488 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1489 if {[string match
{[-^
<>]*} $ids]} {
1490 switch
-- [string index
$ids 0] {
1496 set ids
[string range
$ids 1 end
]
1500 if {[string length
$id] != 40} {
1508 if {[string length
$shortcmit] > 80} {
1509 set shortcmit
"[string range $shortcmit 0 80]..."
1511 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1514 set id [lindex $ids 0]
1517 lappend vshortids($view,[string range $id 0 3]) $id
1519 if {!$listed && $updating && ![info exists varcid($vid)] &&
1520 $vfilelimit($view) ne {}} {
1521 # git log doesn't rewrite parents
for unlisted commits
1522 # when doing path limiting, so work around that here
1523 # by working out the rewritten parent with git rev-list
1524 # and if we already know about it, using the rewritten
1525 # parent as a substitute parent for $id's children.
1527 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1528 $id -- $vfilelimit($view)]
1530 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1531 # use $rwid in place of $id
1532 rewrite_commit
$view $id $rwid
1539 if {[info exists varcid
($vid)]} {
1540 if {$cmitlisted($vid) ||
!$listed} continue
1544 set olds
[lrange
$ids 1 end
]
1548 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1549 set cmitlisted
($vid) $listed
1550 set parents
($vid) $olds
1551 if {![info exists children
($vid)]} {
1552 set children
($vid) {}
1553 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1554 set k
[lindex
$children($vid) 0]
1555 if {[llength
$parents($view,$k)] == 1 &&
1556 (!$vdatemode($view) ||
1557 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1558 set a
$varcid($view,$k)
1563 set a
[newvarc
$view $id]
1565 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1568 if {![info exists varcid
($vid)]} {
1570 lappend varccommits
($view,$a) $id
1571 incr commitidx
($view)
1576 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1578 if {[llength
[lappend children
($vp) $id]] > 1 &&
1579 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1580 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1582 catch
{unset ordertok
}
1584 if {[info exists varcid
($view,$p)]} {
1585 fix_reversal
$p $a $view
1591 set scripts
[check_interest
$id $scripts]
1595 global numcommits hlview
1597 if {$view == $curview} {
1598 set numcommits
$commitidx($view)
1601 if {[info exists hlview
] && $view == $hlview} {
1602 # we never actually get here...
1605 foreach s
$scripts {
1612 proc chewcommits
{} {
1613 global curview hlview viewcomplete
1614 global pending_select
1617 if {$viewcomplete($curview)} {
1618 global commitidx varctok
1619 global numcommits startmsecs
1621 if {[info exists pending_select
]} {
1623 reset_pending_select
{}
1625 if {[commitinview
$pending_select $curview]} {
1626 selectline
[rowofcommit
$pending_select] 1
1628 set row
[first_real_row
]
1632 if {$commitidx($curview) > 0} {
1633 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1634 #puts "overall $ms ms for $numcommits commits"
1635 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1637 show_status
[mc
"No commits selected"]
1644 proc do_readcommit
{id
} {
1647 # Invoke git-log to handle automatic encoding conversion
1648 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1649 # Read the results using i18n.logoutputencoding
1650 fconfigure
$fd -translation lf
-eofchar {}
1651 if {$tclencoding != {}} {
1652 fconfigure
$fd -encoding $tclencoding
1654 set contents
[read $fd]
1656 # Remove the heading line
1657 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1662 proc readcommit
{id
} {
1663 if {[catch
{set contents
[do_readcommit
$id]}]} return
1664 parsecommit
$id $contents 1
1667 proc parsecommit
{id contents listed
} {
1677 set hdrend
[string first
"\n\n" $contents]
1679 # should never happen...
1680 set hdrend
[string length
$contents]
1682 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1683 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1684 foreach line
[split $header "\n"] {
1685 set line
[split $line " "]
1686 set tag
[lindex
$line 0]
1687 if {$tag == "author"} {
1688 set audate
[lrange
$line end-1 end
]
1689 set auname
[join [lrange
$line 1 end-2
] " "]
1690 } elseif
{$tag == "committer"} {
1691 set comdate
[lrange
$line end-1 end
]
1692 set comname
[join [lrange
$line 1 end-2
] " "]
1696 # take the first non-blank line of the comment as the headline
1697 set headline
[string trimleft
$comment]
1698 set i
[string first
"\n" $headline]
1700 set headline
[string range
$headline 0 $i]
1702 set headline
[string trimright
$headline]
1703 set i
[string first
"\r" $headline]
1705 set headline
[string trimright
[string range
$headline 0 $i]]
1708 # git log indents the comment by 4 spaces;
1709 # if we got this via git cat-file, add the indentation
1711 foreach line
[split $comment "\n"] {
1712 append newcomment
" "
1713 append newcomment
$line
1714 append newcomment
"\n"
1716 set comment
$newcomment
1718 set hasnote
[string first
"\nNotes:\n" $contents]
1720 # If there is diff output shown in the git-log stream, split it
1721 # out. But get rid of the empty line that always precedes the
1723 set i
[string first
"\n\ndiff" $comment]
1725 set diff [string range
$comment $i+1 end
]
1726 set comment
[string range
$comment 0 $i-1]
1728 set commitinfo
($id) [list
$headline $auname $audate \
1729 $comname $comdate $comment $hasnote $diff]
1732 proc getcommit
{id
} {
1733 global commitdata commitinfo
1735 if {[info exists commitdata
($id)]} {
1736 parsecommit
$id $commitdata($id) 1
1739 if {![info exists commitinfo
($id)]} {
1740 set commitinfo
($id) [list
[mc
"No commit information available"]]
1746 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1747 # and are present in the current view.
1748 # This is fairly slow...
1749 proc longid
{prefix
} {
1750 global varcid curview vshortids
1753 if {[string length
$prefix] >= 4} {
1754 set vshortid
$curview,[string range
$prefix 0 3]
1755 if {[info exists vshortids
($vshortid)]} {
1756 foreach id
$vshortids($vshortid) {
1757 if {[string match
"$prefix*" $id]} {
1758 if {[lsearch
-exact $ids $id] < 0} {
1760 if {[llength
$ids] >= 2} break
1766 foreach match
[array names varcid
"$curview,$prefix*"] {
1767 lappend ids
[lindex
[split $match ","] 1]
1768 if {[llength
$ids] >= 2} break
1775 global tagids idtags headids idheads tagobjid
1776 global otherrefids idotherrefs mainhead mainheadid
1777 global selecthead selectheadid
1780 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1783 set refd
[open
[list | git show-ref
-d] r
]
1784 while {[gets
$refd line
] >= 0} {
1785 if {[string index
$line 40] ne
" "} continue
1786 set id
[string range
$line 0 39]
1787 set ref
[string range
$line 41 end
]
1788 if {![string match
"refs/*" $ref]} continue
1789 set name
[string range
$ref 5 end
]
1790 if {[string match
"remotes/*" $name]} {
1791 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1792 set headids
($name) $id
1793 lappend idheads
($id) $name
1795 } elseif
{[string match
"heads/*" $name]} {
1796 set name
[string range
$name 6 end
]
1797 set headids
($name) $id
1798 lappend idheads
($id) $name
1799 } elseif
{[string match
"tags/*" $name]} {
1800 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1801 # which is what we want since the former is the commit ID
1802 set name
[string range
$name 5 end
]
1803 if {[string match
"*^{}" $name]} {
1804 set name
[string range
$name 0 end-3
]
1806 set tagobjid
($name) $id
1808 set tagids
($name) $id
1809 lappend idtags
($id) $name
1811 set otherrefids
($name) $id
1812 lappend idotherrefs
($id) $name
1819 set mainheadid
[exec git rev-parse HEAD
]
1820 set thehead
[exec git symbolic-ref HEAD
]
1821 if {[string match
"refs/heads/*" $thehead]} {
1822 set mainhead
[string range
$thehead 11 end
]
1826 if {$selecthead ne
{}} {
1828 set selectheadid
[exec git rev-parse
--verify $selecthead]
1833 # skip over fake commits
1834 proc first_real_row
{} {
1835 global nullid nullid2 numcommits
1837 for {set row
0} {$row < $numcommits} {incr row
} {
1838 set id
[commitonrow
$row]
1839 if {$id ne
$nullid && $id ne
$nullid2} {
1846 # update things for a head moved to a child of its previous location
1847 proc movehead
{id name
} {
1848 global headids idheads
1850 removehead
$headids($name) $name
1851 set headids
($name) $id
1852 lappend idheads
($id) $name
1855 # update things when a head has been removed
1856 proc removehead
{id name
} {
1857 global headids idheads
1859 if {$idheads($id) eq
$name} {
1862 set i
[lsearch
-exact $idheads($id) $name]
1864 set idheads
($id) [lreplace
$idheads($id) $i $i]
1867 unset headids
($name)
1870 proc ttk_toplevel
{w args
} {
1872 eval [linsert
$args 0 ::toplevel
$w]
1874 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1879 proc make_transient
{window origin
} {
1882 # In MacOS Tk 8.4 transient appears to work by setting
1883 # overrideredirect, which is utterly useless, since the
1884 # windows get no border, and are not even kept above
1886 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1888 wm transient
$window $origin
1890 # Windows fails to place transient windows normally, so
1891 # schedule a callback to center them on the parent.
1892 if {[tk windowingsystem
] eq
{win32
}} {
1893 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1897 proc show_error
{w top msg
{mc mc
}} {
1899 if {![info exists NS
]} {set NS
""}
1900 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1901 message
$w.m
-text $msg -justify center
-aspect 400
1902 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1903 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1904 pack
$w.ok
-side bottom
-fill x
1905 bind $top <Visibility
> "grab $top; focus $top"
1906 bind $top <Key-Return
> "destroy $top"
1907 bind $top <Key-space
> "destroy $top"
1908 bind $top <Key-Escape
> "destroy $top"
1912 proc error_popup
{msg
{owner .
}} {
1913 if {[tk windowingsystem
] eq
"win32"} {
1914 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1915 -parent $owner -message $msg
1919 make_transient
$w $owner
1920 show_error
$w $w $msg
1924 proc confirm_popup
{msg
{owner .
}} {
1925 global confirm_ok NS
1929 make_transient
$w $owner
1930 message
$w.m
-text $msg -justify center
-aspect 400
1931 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1932 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1933 pack
$w.ok
-side left
-fill x
1934 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1935 pack
$w.cancel
-side right
-fill x
1936 bind $w <Visibility
> "grab $w; focus $w"
1937 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1938 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1939 bind $w <Key-Escape
> "destroy $w"
1940 tk
::PlaceWindow
$w widget
$owner
1945 proc setoptions
{} {
1946 if {[tk windowingsystem
] ne
"win32"} {
1947 option add
*Panedwindow.showHandle
1 startupFile
1948 option add
*Panedwindow.sashRelief raised startupFile
1949 if {[tk windowingsystem
] ne
"aqua"} {
1950 option add
*Menu.font uifont startupFile
1953 option add
*Menu.TearOff
0 startupFile
1955 option add
*Button.font uifont startupFile
1956 option add
*Checkbutton.font uifont startupFile
1957 option add
*Radiobutton.font uifont startupFile
1958 option add
*Menubutton.font uifont startupFile
1959 option add
*Label.font uifont startupFile
1960 option add
*Message.font uifont startupFile
1961 option add
*Entry.font textfont startupFile
1962 option add
*Text.font textfont startupFile
1963 option add
*Labelframe.font uifont startupFile
1964 option add
*Spinbox.font textfont startupFile
1965 option add
*Listbox.font mainfont startupFile
1968 # Make a menu and submenus.
1969 # m is the window name for the menu, items is the list of menu items to add.
1970 # Each item is a list {mc label type description options...}
1971 # mc is ignored; it's so we can put mc there to alert xgettext
1972 # label is the string that appears in the menu
1973 # type is cascade, command or radiobutton (should add checkbutton)
1974 # description depends on type; it's the sublist for cascade, the
1975 # command to invoke for command, or {variable value} for radiobutton
1976 proc makemenu
{m items
} {
1978 if {[tk windowingsystem
] eq
{aqua
}} {
1984 set name
[mc
[lindex
$i 1]]
1985 set type [lindex
$i 2]
1986 set thing
[lindex
$i 3]
1987 set params
[list
$type]
1989 set u
[string first
"&" [string map
{&& x
} $name]]
1990 lappend params
-label [string map
{&& & & {}} $name]
1992 lappend params
-underline $u
1997 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1998 lappend params
-menu $m.
$submenu
2001 lappend params
-command $thing
2004 lappend params
-variable [lindex
$thing 0] \
2005 -value [lindex
$thing 1]
2008 set tail [lrange
$i 4 end
]
2009 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2010 eval $m add
$params $tail
2011 if {$type eq
"cascade"} {
2012 makemenu
$m.
$submenu $thing
2017 # translate string and remove ampersands
2019 return [string map
{&& & & {}} [mc
$str]]
2022 proc cleardropsel
{w
} {
2025 proc makedroplist
{w varname args
} {
2029 foreach label
$args {
2030 set cx
[string length
$label]
2031 if {$cx > $width} {set width
$cx}
2033 set gm
[ttk
::combobox
$w -width $width -state readonly\
2034 -textvariable $varname -values $args \
2035 -exportselection false
]
2036 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2038 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2043 proc makewindow {} {
2044 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2046 global findtype findtypemenu findloc findstring fstring geometry
2047 global entries sha1entry sha1string sha1but
2048 global diffcontextstring diffcontext
2050 global maincursor textcursor curtextcursor
2051 global rowctxmenu fakerowmenu mergemax wrapcomment
2052 global highlight_files gdttype
2053 global searchstring sstring
2054 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2055 global uifgcolor uifgdisabledcolor
2056 global filesepbgcolor filesepfgcolor
2057 global mergecolors foundbgcolor currentsearchhitbgcolor
2058 global headctxmenu progresscanv progressitem progresscoords statusw
2059 global fprogitem fprogcoord lastprogupdate progupdatepending
2060 global rprogitem rprogcoord rownumsel numcommits
2061 global have_tk85 use_ttk NS
2065 # The "mc" arguments here are purely so that xgettext
2066 # sees the following string as needing to be translated
2069 {mc "Update" command updatecommits -accelerator F5}
2070 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2071 {mc "Reread references" command rereadrefs}
2072 {mc "List references" command showrefs -accelerator F2}
2074 {mc "Start git gui" command {exec git gui &}}
2076 {mc "Quit" command doquit -accelerator Meta1-Q}
2080 {mc "Preferences" command doprefs}
2084 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2085 {mc "Edit view..." command editview -state disabled -accelerator F4}
2086 {mc "Delete view" command delview -state disabled}
2088 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2090 if {[tk windowingsystem] ne "aqua"} {
2093 {mc "About gitk" command about}
2094 {mc "Key bindings" command keys}
2096 set bar [list $file $edit $view $help]
2098 proc ::tk::mac::ShowPreferences {} {doprefs}
2099 proc ::tk::mac::Quit {} {doquit}
2100 lset file end [lreplace [lindex $file end] end-1 end]
2102 xx "Apple" cascade {
2103 {mc "About gitk" command about}
2108 {mc "Key bindings" command keys}
2110 set bar [list $apple $file $view $help]
2113 . configure -menu .bar
2116 # cover the non-themed toplevel with a themed frame.
2117 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2120 # the gui has upper and lower half, parts of a paned window.
2121 ${NS}::panedwindow .ctop -orient vertical
2123 # possibly use assumed geometry
2124 if {![info exists geometry(pwsash0)]} {
2125 set geometry(topheight) [expr {15 * $linespc}]
2126 set geometry(topwidth) [expr {80 * $charspc}]
2127 set geometry(botheight) [expr {15 * $linespc}]
2128 set geometry(botwidth) [expr {50 * $charspc}]
2129 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2130 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2133 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2134 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2135 ${NS}::frame .tf.histframe
2136 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2138 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2141 # create three canvases
2142 set cscroll .tf.histframe.csb
2143 set canv .tf.histframe.pwclist.canv
2145 -selectbackground $selectbgcolor \
2146 -background $bgcolor -bd 0 \
2147 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2148 .tf.histframe.pwclist add $canv
2149 set canv2 .tf.histframe.pwclist.canv2
2151 -selectbackground $selectbgcolor \
2152 -background $bgcolor -bd 0 -yscrollincr $linespc
2153 .tf.histframe.pwclist add $canv2
2154 set canv3 .tf.histframe.pwclist.canv3
2156 -selectbackground $selectbgcolor \
2157 -background $bgcolor -bd 0 -yscrollincr $linespc
2158 .tf.histframe.pwclist add $canv3
2160 bind .tf.histframe.pwclist <Map> {
2162 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2163 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2166 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2167 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2170 # a scroll bar to rule them
2171 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2172 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2173 pack $cscroll -side right -fill y
2174 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2175 lappend bglist $canv $canv2 $canv3
2176 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2178 # we have two button bars at bottom of top frame. Bar 1
2179 ${NS}::frame .tf.bar
2180 ${NS}::frame .tf.lbar -height 15
2182 set sha1entry .tf.bar.sha1
2183 set entries $sha1entry
2184 set sha1but .tf.bar.sha1label
2185 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2186 -command gotocommit -width 8
2187 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2188 pack .tf.bar.sha1label -side left
2189 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2190 trace add variable sha1string write sha1change
2191 pack $sha1entry -side left -pady 2
2194 #define left_width 16
2195 #define left_height 16
2196 static unsigned char left_bits[] = {
2197 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2198 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2199 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2202 #define right_width 16
2203 #define right_height 16
2204 static unsigned char right_bits[] = {
2205 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2206 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2207 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2209 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2210 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2211 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2212 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2214 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2216 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2218 .tf.bar.leftbut configure -image bm-left
2220 pack .tf.bar.leftbut -side left -fill y
2221 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2223 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2225 .tf.bar.rightbut configure -image bm-right
2227 pack .tf.bar.rightbut -side left -fill y
2229 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2231 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2232 -relief sunken -anchor e
2233 ${NS}::label .tf.bar.rowlabel2 -text "/"
2234 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2235 -relief sunken -anchor e
2236 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2239 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2242 trace add variable selectedline write selectedline_change
2244 # Status label and progress bar
2245 set statusw .tf.bar.status
2246 ${NS}::label $statusw -width 15 -relief sunken
2247 pack $statusw -side left -padx 5
2249 set progresscanv [ttk::progressbar .tf.bar.progress]
2251 set h [expr {[font metrics uifont -linespace] + 2}]
2252 set progresscanv .tf.bar.progress
2253 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2254 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2255 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2256 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2258 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2259 set progresscoords {0 0}
2262 bind $progresscanv <Configure> adjustprogress
2263 set lastprogupdate [clock clicks -milliseconds]
2264 set progupdatepending 0
2266 # build up the bottom bar of upper window
2267 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2270 #define down_width 16
2271 #define down_height 16
2272 static unsigned char down_bits[] = {
2273 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2274 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2275 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2276 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
2278 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2279 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2280 .tf.lbar.fnext configure -image bm-down
2284 #define up_height 16
2285 static unsigned char up_bits[] = {
2286 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2287 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2288 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2289 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
2291 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2292 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2293 .tf.lbar.fprev configure -image bm-up
2295 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2297 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2299 set gdttype [mc "containing:"]
2300 set gm [makedroplist .tf.lbar.gdttype gdttype \
2301 [mc "containing:"] \
2302 [mc "touching paths:"] \
2303 [mc "adding/removing string:"] \
2304 [mc "changing lines matching:"]]
2305 trace add variable gdttype write gdttype_change
2306 pack .tf.lbar.gdttype -side left -fill y
2309 set fstring .tf.lbar.findstring
2310 lappend entries $fstring
2311 ${NS}::entry $fstring -width 30 -textvariable findstring
2312 trace add variable findstring write find_change
2313 set findtype [mc "Exact"]
2314 set findtypemenu [makedroplist .tf.lbar.findtype \
2315 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2316 trace add variable findtype write findcom_change
2317 set findloc [mc "All fields"]
2318 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2319 [mc "Comments"] [mc "Author"] [mc "Committer"]
2320 trace add variable findloc write find_change
2321 pack .tf.lbar.findloc -side right
2322 pack .tf.lbar.findtype -side right
2323 pack $fstring -side left -expand 1 -fill x
2325 # Finish putting the upper half of the viewer together
2326 pack .tf.lbar -in .tf -side bottom -fill x
2327 pack .tf.bar -in .tf -side bottom -fill x
2328 pack .tf.histframe -fill both -side top -expand 1
2331 .ctop paneconfigure .tf -height $geometry(topheight)
2332 .ctop paneconfigure .tf -width $geometry(topwidth)
2335 # now build up the bottom
2336 ${NS}::panedwindow .pwbottom -orient horizontal
2338 # lower left, a text box over search bar, scroll bar to the right
2339 # if we know window height, then that will set the lower text height, otherwise
2340 # we set lower text height which will drive window height
2341 if {[info exists geometry(main)]} {
2342 ${NS}::frame .bleft -width $geometry(botwidth)
2344 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2346 ${NS}::frame .bleft.top
2347 ${NS}::frame .bleft.mid
2348 ${NS}::frame .bleft.bottom
2350 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2351 pack .bleft.top.search -side left -padx 5
2352 set sstring .bleft.top.sstring
2354 ${NS}::entry $sstring -width 20 -textvariable searchstring
2355 lappend entries $sstring
2356 trace add variable searchstring write incrsearch
2357 pack $sstring -side left -expand 1 -fill x
2358 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2359 -command changediffdisp -variable diffelide -value {0 0}
2360 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2361 -command changediffdisp -variable diffelide -value {0 1}
2362 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2363 -command changediffdisp -variable diffelide -value {1 0}
2364 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2365 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2366 spinbox .bleft.mid.diffcontext -width 5 \
2367 -from 0 -increment 1 -to 10000000 \
2368 -validate all -validatecommand "diffcontextvalidate %P" \
2369 -textvariable diffcontextstring
2370 .bleft.mid.diffcontext set $diffcontext
2371 trace add variable diffcontextstring write diffcontextchange
2372 lappend entries .bleft.mid.diffcontext
2373 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2374 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2375 -command changeignorespace -variable ignorespace
2376 pack .bleft.mid.ignspace -side left -padx 5
2378 set worddiff [mc "Line diff"]
2379 if {[package vcompare $git_version "1.7.2"] >= 0} {
2380 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2381 [mc "Markup words"] [mc "Color words"]
2382 trace add variable worddiff write changeworddiff
2383 pack .bleft.mid.worddiff -side left -padx 5
2386 set ctext .bleft.bottom.ctext
2387 text $ctext -background $bgcolor -foreground $fgcolor \
2388 -state disabled -font textfont \
2389 -yscrollcommand scrolltext -wrap none \
2390 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2392 $ctext conf -tabstyle wordprocessor
2394 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2395 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2396 pack .bleft.top -side top -fill x
2397 pack .bleft.mid -side top -fill x
2398 grid $ctext .bleft.bottom.sb -sticky nsew
2399 grid .bleft.bottom.sbhorizontal -sticky ew
2400 grid columnconfigure .bleft.bottom 0 -weight 1
2401 grid rowconfigure .bleft.bottom 0 -weight 1
2402 grid rowconfigure .bleft.bottom 1 -weight 0
2403 pack .bleft.bottom -side top -fill both -expand 1
2404 lappend bglist $ctext
2405 lappend fglist $ctext
2407 $ctext tag conf comment -wrap $wrapcomment
2408 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2409 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2410 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2411 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2412 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2413 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2414 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2415 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2416 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2417 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2418 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2419 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2420 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2421 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2422 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2423 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2424 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2425 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2426 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2427 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2428 $ctext tag conf mmax -fore darkgrey
2430 $ctext tag conf mresult -font textfontbold
2431 $ctext tag conf msep -font textfontbold
2432 $ctext tag conf found -back $foundbgcolor
2433 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2434 $ctext tag conf wwrap -wrap word -lmargin2 1c
2435 $ctext tag conf bold -font textfontbold
2437 .pwbottom add .bleft
2439 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2443 ${NS}::frame .bright
2444 ${NS}::frame .bright.mode
2445 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2446 -command reselectline -variable cmitmode -value "patch"
2447 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2448 -command reselectline -variable cmitmode -value "tree"
2449 grid .bright.mode.patch .bright.mode.tree -sticky ew
2450 pack .bright.mode -side top -fill x
2451 set cflist .bright.cfiles
2452 set indent [font measure mainfont "nn"]
2454 -selectbackground $selectbgcolor \
2455 -background $bgcolor -foreground $fgcolor \
2457 -tabs [list $indent [expr {2 * $indent}]] \
2458 -yscrollcommand ".bright.sb set" \
2459 -cursor [. cget -cursor] \
2460 -spacing1 1 -spacing3 1
2461 lappend bglist $cflist
2462 lappend fglist $cflist
2463 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2464 pack .bright.sb -side right -fill y
2465 pack $cflist -side left -fill both -expand 1
2466 $cflist tag configure highlight \
2467 -background [$cflist cget -selectbackground]
2468 $cflist tag configure bold -font mainfontbold
2470 .pwbottom add .bright
2473 # restore window width & height if known
2474 if {[info exists geometry(main)]} {
2475 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2476 if {$w > [winfo screenwidth .]} {
2477 set w [winfo screenwidth .]
2479 if {$h > [winfo screenheight .]} {
2480 set h [winfo screenheight .]
2482 wm geometry . "${w}x$h"
2486 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2487 wm state . $geometry(state)
2490 if {[tk windowingsystem] eq {aqua}} {
2501 %W sashpos 0 $::geometry(topheight)
2503 bind .pwbottom <Map> {
2505 %W sashpos 0 $::geometry(botwidth)
2509 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2510 pack .ctop -fill both -expand 1
2511 bindall <1> {selcanvline %W %x %y}
2512 #bindall <B1-Motion> {selcanvline %W %x %y}
2513 if {[tk windowingsystem] == "win32"} {
2514 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2515 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2517 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2518 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2519 if {[tk windowingsystem] eq "aqua"} {
2520 bindall <MouseWheel> {
2521 set delta [expr {- (%D)}]
2522 allcanvs yview scroll $delta units
2524 bindall <Shift-MouseWheel> {
2525 set delta [expr {- (%D)}]
2526 $canv xview scroll $delta units
2530 bindall <$::BM> "canvscan mark %W %x %y"
2531 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2532 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2533 bind . <$M1B-Key-w> doquit
2534 bindkey <Home> selfirstline
2535 bindkey <End> sellastline
2536 bind . <Key-Up> "selnextline -1"
2537 bind . <Key-Down> "selnextline 1"
2538 bind . <Shift-Key-Up> "dofind -1 0"
2539 bind . <Shift-Key-Down> "dofind 1 0"
2540 bindkey <Key-Right> "goforw"
2541 bindkey <Key-Left> "goback"
2542 bind . <Key-Prior> "selnextpage -1"
2543 bind . <Key-Next> "selnextpage 1"
2544 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2545 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2546 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2547 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2548 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2549 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2550 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2551 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2552 bindkey <Key-space> "$ctext yview scroll 1 pages"
2553 bindkey p "selnextline -1"
2554 bindkey n "selnextline 1"
2557 bindkey k "selnextline -1"
2558 bindkey j "selnextline 1"
2562 bindkey d "$ctext yview scroll 18 units"
2563 bindkey u "$ctext yview scroll -18 units"
2564 bindkey / {focus $fstring}
2565 bindkey <Key-KP_Divide> {focus $fstring}
2566 bindkey <Key-Return> {dofind 1 1}
2567 bindkey ? {dofind -1 1}
2569 bind . <F5> updatecommits
2570 bindmodfunctionkey Shift 5 reloadcommits
2571 bind . <F2> showrefs
2572 bindmodfunctionkey Shift 4 {newview 0}
2573 bind . <F4> edit_or_newview
2574 bind . <$M1B-q> doquit
2575 bind . <$M1B-f> {dofind 1 1}
2576 bind . <$M1B-g> {dofind 1 0}
2577 bind . <$M1B-r> dosearchback
2578 bind . <$M1B-s> dosearch
2579 bind . <$M1B-equal> {incrfont 1}
2580 bind . <$M1B-plus> {incrfont 1}
2581 bind . <$M1B-KP_Add> {incrfont 1}
2582 bind . <$M1B-minus> {incrfont -1}
2583 bind . <$M1B-KP_Subtract> {incrfont -1}
2584 wm protocol . WM_DELETE_WINDOW doquit
2585 bind . <Destroy> {stop_backends}
2586 bind . <Button-1> "click %W"
2587 bind $fstring <Key-Return> {dofind 1 1}
2588 bind $sha1entry <Key-Return> {gotocommit; break}
2589 bind $sha1entry <<PasteSelection>> clearsha1
2590 bind $sha1entry <<Paste>> clearsha1
2591 bind $cflist <1> {sel_flist %W %x %y; break}
2592 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2593 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2595 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2596 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2597 bind $ctext <Button-1> {focus %W}
2598 bind $ctext <<Selection>> rehighlight_search_results
2599 for {set i 1} {$i < 10} {incr i} {
2600 bind . <$M1B-Key-$i> [list go_to_parent $i]
2603 set maincursor [. cget -cursor]
2604 set textcursor [$ctext cget -cursor]
2605 set curtextcursor $textcursor
2607 set rowctxmenu .rowctxmenu
2608 makemenu $rowctxmenu {
2609 {mc "Diff this -> selected" command {diffvssel 0}}
2610 {mc "Diff selected -> this" command {diffvssel 1}}
2611 {mc "Make patch" command mkpatch}
2612 {mc "Create tag" command mktag}
2613 {mc "Write commit to file" command writecommit}
2614 {mc "Create new branch" command mkbranch}
2615 {mc "Cherry-pick this commit" command cherrypick}
2616 {mc "Reset HEAD branch to here" command resethead}
2617 {mc "Mark this commit" command markhere}
2618 {mc "Return to mark" command gotomark}
2619 {mc "Find descendant of this and mark" command find_common_desc}
2620 {mc "Compare with marked commit" command compare_commits}
2621 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2622 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2623 {mc "Revert this commit" command revert}
2625 $rowctxmenu configure -tearoff 0
2627 set fakerowmenu .fakerowmenu
2628 makemenu $fakerowmenu {
2629 {mc "Diff this -> selected" command {diffvssel 0}}
2630 {mc "Diff selected -> this" command {diffvssel 1}}
2631 {mc "Make patch" command mkpatch}
2632 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2633 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2635 $fakerowmenu configure -tearoff 0
2637 set headctxmenu .headctxmenu
2638 makemenu $headctxmenu {
2639 {mc "Check out this branch" command cobranch}
2640 {mc "Remove this branch" command rmbranch}
2642 $headctxmenu configure -tearoff 0
2645 set flist_menu .flistctxmenu
2646 makemenu $flist_menu {
2647 {mc "Highlight this too" command {flist_hl 0}}
2648 {mc "Highlight this only" command {flist_hl 1}}
2649 {mc "External diff" command {external_diff}}
2650 {mc "Blame parent commit" command {external_blame 1}}
2652 $flist_menu configure -tearoff 0
2655 set diff_menu .diffctxmenu
2656 makemenu $diff_menu {
2657 {mc "Show origin of this line" command show_line_source}
2658 {mc "Run git gui blame on this line" command {external_blame_diff}}
2660 $diff_menu configure -tearoff 0
2663 # Windows sends all mouse wheel events to the current focused window, not
2664 # the one where the mouse hovers, so bind those events here and redirect
2665 # to the correct window
2666 proc windows_mousewheel_redirector {W X Y D} {
2667 global canv canv2 canv3
2668 set w [winfo containing -displayof $W $X $Y]
2670 set u [expr {$D < 0 ? 5 : -5}]
2671 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2672 allcanvs yview scroll $u units
2675 $w yview scroll $u units
2681 # Update row number label when selectedline changes
2682 proc selectedline_change {n1 n2 op} {
2683 global selectedline rownumsel
2685 if {$selectedline eq {}} {
2688 set rownumsel [expr {$selectedline + 1}]
2692 # mouse-2 makes all windows scan vertically, but only the one
2693 # the cursor is in scans horizontally
2694 proc canvscan {op w x y} {
2695 global canv canv2 canv3
2696 foreach c [list $canv $canv2 $canv3] {
2705 proc scrollcanv {cscroll f0 f1} {
2706 $cscroll set $f0 $f1
2711 # when we make a key binding for the toplevel, make sure
2712 # it doesn't get triggered when that key is pressed in the
2713 # find string entry widget.
2714 proc bindkey {ev script} {
2717 set escript [bind Entry $ev]
2718 if {$escript == {}} {
2719 set escript [bind Entry <Key>]
2721 foreach e $entries {
2722 bind $e $ev "$escript; break"
2726 proc bindmodfunctionkey {mod n script} {
2727 bind . <$mod-F$n> $script
2728 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2731 # set the focus back to the toplevel for any click outside
2734 global ctext entries
2735 foreach e [concat $entries $ctext] {
2736 if {$w == $e} return
2741 # Adjust the progress bar for a change in requested extent or canvas size
2742 proc adjustprogress {} {
2743 global progresscanv progressitem progresscoords
2744 global fprogitem fprogcoord lastprogupdate progupdatepending
2745 global rprogitem rprogcoord use_ttk
2748 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2752 set w [expr {[winfo width $progresscanv] - 4}]
2753 set x0 [expr {$w * [lindex $progresscoords 0]}]
2754 set x1 [expr {$w * [lindex $progresscoords 1]}]
2755 set h [winfo height $progresscanv]
2756 $progresscanv coords $progressitem $x0 0 $x1 $h
2757 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2758 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2759 set now [clock clicks -milliseconds]
2760 if {$now >= $lastprogupdate + 100} {
2761 set progupdatepending 0
2763 } elseif {!$progupdatepending} {
2764 set progupdatepending 1
2765 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2769 proc doprogupdate {} {
2770 global lastprogupdate progupdatepending
2772 if {$progupdatepending} {
2773 set progupdatepending 0
2774 set lastprogupdate [clock clicks -milliseconds]
2779 proc savestuff {w} {
2780 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2783 global config_file config_file_tmp
2784 global config_variables
2786 if {$stuffsaved} return
2787 if {![winfo viewable .]} return
2789 if {[file exists $config_file_tmp]} {
2790 file delete -force $config_file_tmp
2792 set f [open $config_file_tmp w]
2793 if {$::tcl_platform(platform) eq {windows}} {
2794 file attributes $config_file_tmp -hidden true
2796 foreach var_name $config_variables {
2797 upvar #0 $var_name var
2798 puts $f [list set $var_name $var]
2801 puts $f "set geometry(main) [wm geometry .]"
2802 puts $f "set geometry(state) [wm state .]"
2803 puts $f "set geometry(topwidth) [winfo width .tf]"
2804 puts $f "set geometry(topheight) [winfo height .tf]"
2806 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2807 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2809 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2810 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2812 puts $f "set geometry(botwidth) [winfo width .bleft]"
2813 puts $f "set geometry(botheight) [winfo height .bleft]"
2815 puts -nonewline $f "set permviews {"
2816 for {set v 0} {$v < $nextviewnum} {incr v} {
2817 if {$viewperm($v)} {
2818 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2823 file rename -force $config_file_tmp $config_file
2828 proc resizeclistpanes {win w} {
2829 global oldwidth use_ttk
2830 if {[info exists oldwidth($win)]} {
2832 set s0 [$win sashpos 0]
2833 set s1 [$win sashpos 1]
2835 set s0 [$win sash coord 0]
2836 set s1 [$win sash coord 1]
2839 set sash0 [expr {int($w/2 - 2)}]
2840 set sash1 [expr {int($w*5/6 - 2)}]
2842 set factor [expr {1.0 * $w / $oldwidth($win)}]
2843 set sash0 [expr {int($factor * [lindex $s0 0])}]
2844 set sash1 [expr {int($factor * [lindex $s1 0])}]
2848 if {$sash1 < $sash0 + 20} {
2849 set sash1 [expr {$sash0 + 20}]
2851 if {$sash1 > $w - 10} {
2852 set sash1 [expr {$w - 10}]
2853 if {$sash0 > $sash1 - 20} {
2854 set sash0 [expr {$sash1 - 20}]
2859 $win sashpos 0 $sash0
2860 $win sashpos 1 $sash1
2862 $win sash place 0 $sash0 [lindex $s0 1]
2863 $win sash place 1 $sash1 [lindex $s1 1]
2866 set oldwidth($win) $w
2869 proc resizecdetpanes {win w} {
2870 global oldwidth use_ttk
2871 if {[info exists oldwidth($win)]} {
2873 set s0 [$win sashpos 0]
2875 set s0 [$win sash coord 0]
2878 set sash0 [expr {int($w*3/4 - 2)}]
2880 set factor [expr {1.0 * $w / $oldwidth($win)}]
2881 set sash0 [expr {int($factor * [lindex $s0 0])}]
2885 if {$sash0 > $w - 15} {
2886 set sash0 [expr {$w - 15}]
2890 $win sashpos 0 $sash0
2892 $win sash place 0 $sash0 [lindex $s0 1]
2895 set oldwidth($win) $w
2898 proc allcanvs args {
2899 global canv canv2 canv3
2905 proc bindall {event action} {
2906 global canv canv2 canv3
2907 bind $canv $event $action
2908 bind $canv2 $event $action
2909 bind $canv3 $event $action
2915 if {[winfo exists $w]} {
2920 wm title $w [mc "About gitk"]
2922 message $w.m -text [mc "
2923 Gitk - a commit viewer for git
2925 Copyright \u00a9 2005-2014 Paul Mackerras
2927 Use and redistribute under the terms of the GNU General Public License"] \
2928 -justify center -aspect 400 -border 2 -bg white -relief groove
2929 pack $w.m -side top -fill x -padx 2 -pady 2
2930 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2931 pack $w.ok -side bottom
2932 bind $w <Visibility> "focus $w.ok"
2933 bind $w <Key-Escape> "destroy $w"
2934 bind $w <Key-Return> "destroy $w"
2935 tk::PlaceWindow $w widget .
2941 if {[winfo exists $w]} {
2945 if {[tk windowingsystem] eq {aqua}} {
2951 wm title $w [mc "Gitk key bindings"]
2953 message $w.m -text "
2954 [mc "Gitk key bindings:"]
2956 [mc "<%s-Q> Quit" $M1T]
2957 [mc "<%s-W> Close window" $M1T]
2958 [mc "<Home> Move to first commit"]
2959 [mc "<End> Move to last commit"]
2960 [mc "<Up>, p, k Move up one commit"]
2961 [mc "<Down>, n, j Move down one commit"]
2962 [mc "<Left>, z, h Go back in history list"]
2963 [mc "<Right>, x, l Go forward in history list"]
2964 [mc "<%s-n> Go to n-th parent of current commit in history list" $M1T]
2965 [mc "<PageUp> Move up one page in commit list"]
2966 [mc "<PageDown> Move down one page in commit list"]
2967 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2968 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2969 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2970 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2971 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2972 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2973 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2974 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2975 [mc "<Delete>, b Scroll diff view up one page"]
2976 [mc "<Backspace> Scroll diff view up one page"]
2977 [mc "<Space> Scroll diff view down one page"]
2978 [mc "u Scroll diff view up 18 lines"]
2979 [mc "d Scroll diff view down 18 lines"]
2980 [mc "<%s-F> Find" $M1T]
2981 [mc "<%s-G> Move to next find hit" $M1T]
2982 [mc "<Return> Move to next find hit"]
2983 [mc "/ Focus the search box"]
2984 [mc "? Move to previous find hit"]
2985 [mc "f Scroll diff view to next file"]
2986 [mc "<%s-S> Search for next hit in diff view" $M1T]
2987 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2988 [mc "<%s-KP+> Increase font size" $M1T]
2989 [mc "<%s-plus> Increase font size" $M1T]
2990 [mc "<%s-KP-> Decrease font size" $M1T]
2991 [mc "<%s-minus> Decrease font size" $M1T]
2994 -justify left -bg white -border 2 -relief groove
2995 pack $w.m -side top -fill both -padx 2 -pady 2
2996 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2997 bind $w <Key-Escape> [list destroy $w]
2998 pack $w.ok -side bottom
2999 bind $w <Visibility> "focus $w.ok"
3000 bind $w <Key-Escape> "destroy $w"
3001 bind $w <Key-Return> "destroy $w"
3004 # Procedures for manipulating the file list window at the
3005 # bottom right of the overall window.
3007 proc treeview {w l openlevs} {
3008 global treecontents treediropen treeheight treeparent treeindex
3018 set treecontents() {}
3019 $w conf -state normal
3021 while {[string range $f 0 $prefixend] ne $prefix} {
3022 if {$lev <= $openlevs} {
3023 $w mark set e:$treeindex($prefix) "end -1c"
3024 $w mark gravity e:$treeindex($prefix) left
3026 set treeheight($prefix) $ht
3027 incr ht [lindex $htstack end]
3028 set htstack [lreplace $htstack end end]
3029 set prefixend [lindex $prefendstack end]
3030 set prefendstack [lreplace $prefendstack end end]
3031 set prefix [string range $prefix 0 $prefixend]
3034 set tail [string range $f [expr {$prefixend+1}] end]
3035 while {[set slash [string first "/" $tail]] >= 0} {
3038 lappend prefendstack $prefixend
3039 incr prefixend [expr {$slash + 1}]
3040 set d [string range $tail 0 $slash]
3041 lappend treecontents($prefix) $d
3042 set oldprefix $prefix
3044 set treecontents($prefix) {}
3045 set treeindex($prefix) [incr ix]
3046 set treeparent($prefix) $oldprefix
3047 set tail [string range $tail [expr {$slash+1}] end]
3048 if {$lev <= $openlevs} {
3050 set treediropen($prefix) [expr {$lev < $openlevs}]
3051 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3052 $w mark set d:$ix "end -1c"
3053 $w mark gravity d:$ix left
3055 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3057 $w image create end -align center -image $bm -padx 1 \
3059 $w insert end $d [highlight_tag $prefix]
3060 $w mark set s:$ix "end -1c"
3061 $w mark gravity s:$ix left
3066 if {$lev <= $openlevs} {
3069 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3071 $w insert end $tail [highlight_tag $f]
3073 lappend treecontents($prefix) $tail
3076 while {$htstack ne {}} {
3077 set treeheight($prefix) $ht
3078 incr ht [lindex $htstack end]
3079 set htstack [lreplace $htstack end end]
3080 set prefixend [lindex $prefendstack end]
3081 set prefendstack [lreplace $prefendstack end end]
3082 set prefix [string range $prefix 0 $prefixend]
3084 $w conf -state disabled
3087 proc linetoelt {l} {
3088 global treeheight treecontents
3093 foreach e $treecontents($prefix) {
3098 if {[string index $e end] eq "/"} {
3099 set n $treeheight($prefix$e)
3111 proc highlight_tree {y prefix} {
3112 global treeheight treecontents cflist
3114 foreach e $treecontents($prefix) {
3116 if {[highlight_tag $path] ne {}} {
3117 $cflist tag add bold $y.0 "$y.0 lineend"
3120 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3121 set y [highlight_tree $y $path]
3127 proc treeclosedir {w dir} {
3128 global treediropen treeheight treeparent treeindex
3130 set ix $treeindex($dir)
3131 $w conf -state normal
3132 $w delete s:$ix e:$ix
3133 set treediropen($dir) 0
3134 $w image configure a:$ix -image tri-rt
3135 $w conf -state disabled
3136 set n [expr {1 - $treeheight($dir)}]
3137 while {$dir ne {}} {
3138 incr treeheight($dir) $n
3139 set dir $treeparent($dir)
3143 proc treeopendir {w dir} {
3144 global treediropen treeheight treeparent treecontents treeindex
3146 set ix $treeindex($dir)
3147 $w conf -state normal
3148 $w image configure a:$ix -image tri-dn
3149 $w mark set e:$ix s:$ix
3150 $w mark gravity e:$ix right
3153 set n [llength $treecontents($dir)]
3154 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3157 incr treeheight($x) $n
3159 foreach e $treecontents($dir) {
3161 if {[string index $e end] eq "/"} {
3162 set iy $treeindex($de)
3163 $w mark set d:$iy e:$ix
3164 $w mark gravity d:$iy left
3165 $w insert e:$ix $str
3166 set treediropen($de) 0
3167 $w image create e:$ix -align center -image tri-rt -padx 1 \
3169 $w insert e:$ix $e [highlight_tag $de]
3170 $w mark set s:$iy e:$ix
3171 $w mark gravity s:$iy left
3172 set treeheight($de) 1
3174 $w insert e:$ix $str
3175 $w insert e:$ix $e [highlight_tag $de]
3178 $w mark gravity e:$ix right
3179 $w conf -state disabled
3180 set treediropen($dir) 1
3181 set top [lindex [split [$w index @0,0] .] 0]
3182 set ht [$w cget -height]
3183 set l [lindex [split [$w index s:$ix] .] 0]
3186 } elseif {$l + $n + 1 > $top + $ht} {
3187 set top [expr {$l + $n + 2 - $ht}]
3195 proc treeclick {w x y} {
3196 global treediropen cmitmode ctext cflist cflist_top
3198 if {$cmitmode ne "tree"} return
3199 if {![info exists cflist_top]} return
3200 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3201 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3202 $cflist tag add highlight $l.0 "$l.0 lineend"
3208 set e [linetoelt $l]
3209 if {[string index $e end] ne "/"} {
3211 } elseif {$treediropen($e)} {
3218 proc setfilelist {id} {
3219 global treefilelist cflist jump_to_here
3221 treeview $cflist $treefilelist($id) 0
3222 if {$jump_to_here ne {}} {
3223 set f [lindex $jump_to_here 0]
3224 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3230 image create bitmap tri-rt -background black -foreground blue -data {
3231 #define tri-rt_width 13
3232 #define tri-rt_height 13
3233 static unsigned char tri-rt_bits[] = {
3234 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3235 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3238 #define tri-rt-mask_width 13
3239 #define tri-rt-mask_height 13
3240 static unsigned char tri-rt-mask_bits[] = {
3241 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3242 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3245 image create bitmap tri-dn -background black -foreground blue -data {
3246 #define tri-dn_width 13
3247 #define tri-dn_height 13
3248 static unsigned char tri-dn_bits[] = {
3249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3250 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3253 #define tri-dn-mask_width 13
3254 #define tri-dn-mask_height 13
3255 static unsigned char tri-dn-mask_bits[] = {
3256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3257 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3261 image create bitmap reficon-T -background black -foreground yellow -data {
3262 #define tagicon_width 13
3263 #define tagicon_height 9
3264 static unsigned char tagicon_bits[] = {
3265 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3266 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3268 #define tagicon-mask_width 13
3269 #define tagicon-mask_height 9
3270 static unsigned char tagicon-mask_bits[] = {
3271 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3272 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3275 #define headicon_width 13
3276 #define headicon_height 9
3277 static unsigned char headicon_bits[] = {
3278 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3279 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3282 #define headicon-mask_width 13
3283 #define headicon-mask_height 9
3284 static unsigned char headicon-mask_bits[] = {
3285 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3286 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3288 image create bitmap reficon-H -background black -foreground green \
3289 -data $rectdata -maskdata $rectmask
3290 image create bitmap reficon-o -background black -foreground "#ddddff" \
3291 -data $rectdata -maskdata $rectmask
3293 proc init_flist {first} {
3294 global cflist cflist_top difffilestart
3296 $cflist conf -state normal
3297 $cflist delete 0.0 end
3299 $cflist insert end $first
3301 $cflist tag add highlight 1.0 "1.0 lineend"
3303 catch {unset cflist_top}
3305 $cflist conf -state disabled
3306 set difffilestart {}
3309 proc highlight_tag {f} {
3310 global highlight_paths
3312 foreach p $highlight_paths {
3313 if {[string match $p $f]} {
3320 proc highlight_filelist {} {
3321 global cmitmode cflist
3323 $cflist conf -state normal
3324 if {$cmitmode ne "tree"} {
3325 set end [lindex [split [$cflist index end] .] 0]
3326 for {set l 2} {$l < $end} {incr l} {
3327 set line [$cflist get $l.0 "$l.0 lineend"]
3328 if {[highlight_tag $line] ne {}} {
3329 $cflist tag add bold $l.0 "$l.0 lineend"
3335 $cflist conf -state disabled
3338 proc unhighlight_filelist {} {
3341 $cflist conf -state normal
3342 $cflist tag remove bold 1.0 end
3343 $cflist conf -state disabled
3346 proc add_flist {fl} {
3349 $cflist conf -state normal
3351 $cflist insert end "\n"
3352 $cflist insert end $f [highlight_tag $f]
3354 $cflist conf -state disabled
3357 proc sel_flist {w x y} {
3358 global ctext difffilestart cflist cflist_top cmitmode
3360 if {$cmitmode eq "tree"} return
3361 if {![info exists cflist_top]} return
3362 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3363 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3364 $cflist tag add highlight $l.0 "$l.0 lineend"
3369 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3371 suppress_highlighting_file_for_current_scrollpos
3374 proc pop_flist_menu {w X Y x y} {
3375 global ctext cflist cmitmode flist_menu flist_menu_file
3376 global treediffs diffids
3379 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3381 if {$cmitmode eq "tree"} {
3382 set e [linetoelt $l]
3383 if {[string index $e end] eq "/"} return
3385 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3387 set flist_menu_file $e
3388 set xdiffstate "normal"
3389 if {$cmitmode eq "tree"} {
3390 set xdiffstate "disabled"
3392 # Disable "External diff" item in tree mode
3393 $flist_menu entryconf 2 -state $xdiffstate
3394 tk_popup $flist_menu $X $Y
3397 proc find_ctext_fileinfo {line} {
3398 global ctext_file_names ctext_file_lines
3400 set ok [bsearch $ctext_file_lines $line]
3401 set tline [lindex $ctext_file_lines $ok]
3403 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3406 return [list [lindex $ctext_file_names $ok] $tline]
3410 proc pop_diff_menu {w X Y x y} {
3411 global ctext diff_menu flist_menu_file
3412 global diff_menu_txtpos diff_menu_line
3413 global diff_menu_filebase
3415 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3416 set diff_menu_line [lindex $diff_menu_txtpos 0]
3417 # don't pop up the menu on hunk-separator or file-separator lines
3418 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3422 set f [find_ctext_fileinfo $diff_menu_line]
3423 if {$f eq {}} return
3424 set flist_menu_file [lindex $f 0]
3425 set diff_menu_filebase [lindex $f 1]
3426 tk_popup $diff_menu $X $Y
3429 proc flist_hl {only} {
3430 global flist_menu_file findstring gdttype
3432 set x [shellquote $flist_menu_file]
3433 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3436 append findstring " " $x
3438 set gdttype [mc "touching paths:"]
3441 proc gitknewtmpdir {} {
3442 global diffnum gitktmpdir gitdir env
3444 if {![info exists gitktmpdir]} {
3445 if {[info exists env(GITK_TMPDIR)]} {
3446 set tmpdir $env(GITK_TMPDIR)
3447 } elseif {[info exists env(TMPDIR)]} {
3448 set tmpdir $env(TMPDIR)
3452 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
3453 if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} {
3454 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3456 if {[catch {file mkdir $gitktmpdir} err]} {
3457 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3464 set diffdir [file join $gitktmpdir $diffnum]
3465 if {[catch {file mkdir $diffdir} err]} {
3466 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3472 proc save_file_from_commit {filename output what} {
3475 if {[catch {exec git show $filename -- > $output} err]} {
3476 if {[string match "fatal: bad revision *" $err]} {
3479 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3485 proc external_diff_get_one_file {diffid filename diffdir} {
3486 global nullid nullid2 nullfile
3489 if {$diffid == $nullid} {
3490 set difffile [file join $worktree $filename]
3491 if {[file exists $difffile]} {
3496 if {$diffid == $nullid2} {
3497 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3498 return [save_file_from_commit :$filename $difffile index]
3500 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3501 return [save_file_from_commit $diffid:$filename $difffile \
3505 proc external_diff {} {
3506 global nullid nullid2
3507 global flist_menu_file
3511 if {[llength $diffids] == 1} {
3512 # no reference commit given
3513 set diffidto [lindex $diffids 0]
3514 if {$diffidto eq $nullid} {
3515 # diffing working copy with index
3516 set diffidfrom $nullid2
3517 } elseif {$diffidto eq $nullid2} {
3518 # diffing index with HEAD
3519 set diffidfrom "HEAD"
3521 # use first parent commit
3522 global parentlist selectedline
3523 set diffidfrom [lindex $parentlist $selectedline 0]
3526 set diffidfrom [lindex $diffids 0]
3527 set diffidto [lindex $diffids 1]
3530 # make sure that several diffs wont collide
3531 set diffdir [gitknewtmpdir]
3532 if {$diffdir eq {}} return
3534 # gather files to diff
3535 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3536 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3538 if {$difffromfile ne {} && $difftofile ne {}} {
3539 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3540 if {[catch {set fl [open |$cmd r]} err]} {
3541 file delete -force $diffdir
3542 error_popup "$extdifftool: [mc "command failed:"] $err"
3544 fconfigure $fl -blocking 0
3545 filerun $fl [list delete_at_eof $fl $diffdir]
3550 proc find_hunk_blamespec {base line} {
3553 # Find and parse the hunk header
3554 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3555 if {$s_lix eq {}} return
3557 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3558 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3559 s_line old_specs osz osz1 new_line nsz]} {
3563 # base lines for the parents
3564 set base_lines [list $new_line]
3565 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3566 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3567 old_spec old_line osz]} {
3570 lappend base_lines $old_line
3573 # Now scan the lines to determine offset within the hunk
3574 set max_parent [expr {[llength $base_lines]-2}]
3576 set s_lno [lindex [split $s_lix "."] 0]
3578 # Determine if the line is removed
3579 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3580 if {[string match {[-+ ]*} $chunk]} {
3581 set removed_idx [string first "-" $chunk]
3582 # Choose a parent index
3583 if {$removed_idx >= 0} {
3584 set parent $removed_idx
3586 set unchanged_idx [string first " " $chunk]
3587 if {$unchanged_idx >= 0} {
3588 set parent $unchanged_idx
3590 # blame the current commit
3594 # then count other lines that belong to it
3595 for {set i $line} {[incr i -1] > $s_lno} {} {
3596 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3597 # Determine if the line is removed
3598 set removed_idx [string first "-" $chunk]
3600 set code [string index $chunk $parent]
3601 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3605 if {$removed_idx < 0} {
3615 incr dline [lindex $base_lines $parent]
3616 return [list $parent $dline]
3619 proc external_blame_diff {} {
3620 global currentid cmitmode
3621 global diff_menu_txtpos diff_menu_line
3622 global diff_menu_filebase flist_menu_file
3624 if {$cmitmode eq "tree"} {
3626 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3628 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3630 set parent_idx [lindex $hinfo 0]
3631 set line [lindex $hinfo 1]
3638 external_blame $parent_idx $line
3641 # Find the SHA1 ID of the blob for file $fname in the index
3643 proc index_sha1 {fname} {
3644 set f [open [list | git ls-files -s $fname] r]
3645 while {[gets $f line] >= 0} {
3646 set info [lindex [split $line "\t"] 0]
3647 set stage [lindex $info 2]
3648 if {$stage eq "0" || $stage eq "2"} {
3650 return [lindex $info 1]
3657 # Turn an absolute path into one relative to the current directory
3658 proc make_relative {f} {
3659 if {[file pathtype $f] eq "relative"} {
3662 set elts [file split $f]
3663 set here [file split [pwd]]
3668 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3675 set elts [concat $res [lrange $elts $ei end]]
3676 return [eval file join $elts]
3679 proc external_blame {parent_idx {line {}}} {
3680 global flist_menu_file cdup
3681 global nullid nullid2
3682 global parentlist selectedline currentid
3684 if {$parent_idx > 0} {
3685 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3687 set base_commit $currentid
3690 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3691 error_popup [mc "No such commit"]
3695 set cmdline [list git gui blame]
3696 if {$line ne {} && $line > 1} {
3697 lappend cmdline "--line=$line"
3699 set f [file join $cdup $flist_menu_file]
3700 # Unfortunately it seems git gui blame doesn't like
3701 # being given an absolute path...
3702 set f [make_relative $f]
3703 lappend cmdline $base_commit $f
3704 if {[catch {eval exec $cmdline &} err]} {
3705 error_popup "[mc "git gui blame: command failed:"] $err"
3709 proc show_line_source {} {
3710 global cmitmode currentid parents curview blamestuff blameinst
3711 global diff_menu_line diff_menu_filebase flist_menu_file
3712 global nullid nullid2 gitdir cdup
3715 if {$cmitmode eq "tree"} {
3717 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3719 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3720 if {$h eq {}} return
3721 set pi [lindex $h 0]
3723 mark_ctext_line $diff_menu_line
3727 if {$currentid eq $nullid} {
3729 # must be a merge in progress...
3731 # get the last line from .git/MERGE_HEAD
3732 set f [open [file join $gitdir MERGE_HEAD] r]
3733 set id [lindex [split [read $f] "\n"] end-1]
3736 error_popup [mc "Couldn't read merge head: %s" $err]
3739 } elseif {$parents($curview,$currentid) eq $nullid2} {
3740 # need to do the blame from the index
3742 set from_index [index_sha1 $flist_menu_file]
3744 error_popup [mc "Error reading index: %s" $err]
3748 set id $parents($curview,$currentid)
3751 set id [lindex $parents($curview,$currentid) $pi]
3753 set line [lindex $h 1]
3756 if {$from_index ne {}} {
3757 lappend blameargs | git cat-file blob $from_index
3759 lappend blameargs | git blame -p -L$line,+1
3760 if {$from_index ne {}} {
3761 lappend blameargs --contents -
3763 lappend blameargs $id
3765 lappend blameargs -- [file join $cdup $flist_menu_file]
3767 set f [open $blameargs r]
3769 error_popup [mc "Couldn't start git blame: %s" $err]
3772 nowbusy blaming [mc "Searching"]
3773 fconfigure $f -blocking 0
3774 set i [reg_instance $f]
3775 set blamestuff($i) {}
3777 filerun $f [list read_line_source $f $i]
3780 proc stopblaming {} {
3783 if {[info exists blameinst]} {
3784 stop_instance $blameinst
3790 proc read_line_source {fd inst} {
3791 global blamestuff curview commfd blameinst nullid nullid2
3793 while {[gets $fd line] >= 0} {
3794 lappend blamestuff($inst) $line
3802 fconfigure $fd -blocking 1
3803 if {[catch {close $fd} err]} {
3804 error_popup [mc "Error running git blame: %s" $err]
3809 set line [split [lindex $blamestuff($inst) 0] " "]
3810 set id [lindex $line 0]
3811 set lnum [lindex $line 1]
3812 if {[string length $id] == 40 && [string is xdigit $id] &&
3813 [string is digit -strict $lnum]} {
3814 # look for "filename" line
3815 foreach l $blamestuff($inst) {
3816 if {[string match "filename *" $l]} {
3817 set fname [string range $l 9 end]
3823 # all looks good, select it
3824 if {$id eq $nullid} {
3825 # blame uses all-zeroes to mean not committed,
3826 # which would mean a change in the index
3829 if {[commitinview $id $curview]} {
3830 selectline [rowofcommit $id] 1 [list $fname $lnum] 1
3832 error_popup [mc "That line comes from commit %s, \
3833 which is not in this view" [shortids $id]]
3836 puts "oops couldn't parse git blame output"
3841 # delete $dir when we see eof on $f (presumably because the child has exited)
3842 proc delete_at_eof {f dir} {
3843 while {[gets $f line] >= 0} {}
3845 if {[catch {close $f} err]} {
3846 error_popup "[mc "External diff viewer failed:"] $err"
3848 file delete -force $dir
3854 # Functions for adding and removing shell-type quoting
3856 proc shellquote {str} {
3857 if {![string match "*\['\"\\ \t]*" $str]} {
3860 if {![string match "*\['\"\\]*" $str]} {
3863 if {![string match "*'*" $str]} {
3866 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3869 proc shellarglist {l} {
3875 append str [shellquote $a]
3880 proc shelldequote {str} {
3885 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3886 append ret [string range $str $used end]
3887 set used [string length $str]
3890 set first [lindex $first 0]
3891 set ch [string index $str $first]
3892 if {$first > $used} {
3893 append ret [string range $str $used [expr {$first - 1}]]
3896 if {$ch eq " " || $ch eq "\t"} break
3899 set first [string first "'" $str $used]
3901 error "unmatched single-quote"
3903 append ret [string range $str $used [expr {$first - 1}]]
3908 if {$used >= [string length $str]} {
3909 error "trailing backslash"
3911 append ret [string index $str $used]
3916 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3917 error "unmatched double-quote"
3919 set first [lindex $first 0]
3920 set ch [string index $str $first]
3921 if {$first > $used} {
3922 append ret [string range $str $used [expr {$first - 1}]]
3925 if {$ch eq "\""} break
3927 append ret [string index $str $used]
3931 return [list $used $ret]
3934 proc shellsplit {str} {
3937 set str [string trimleft $str]
3938 if {$str eq {}} break
3939 set dq [shelldequote $str]
3940 set n [lindex $dq 0]
3941 set word [lindex $dq 1]
3942 set str [string range $str $n end]
3948 # Code to implement multiple views
3950 proc newview {ishighlight} {
3951 global nextviewnum newviewname newishighlight
3952 global revtreeargs viewargscmd newviewopts curview
3954 set newishighlight $ishighlight
3956 if {[winfo exists $top]} {
3960 decode_view_opts $nextviewnum $revtreeargs
3961 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3962 set newviewopts($nextviewnum,perm) 0
3963 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3964 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3967 set known_view_options {
3968 {perm b . {} {mc "Remember this view"}}
3969 {reflabel l + {} {mc "References (space separated list):"}}
3970 {refs t15 .. {} {mc "Branches & tags:"}}
3971 {allrefs b *. "--all" {mc "All refs"}}
3972 {branches b . "--branches" {mc "All (local) branches"}}
3973 {tags b . "--tags" {mc "All tags"}}
3974 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3975 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3976 {author t15 .. "--author=*" {mc "Author:"}}
3977 {committer t15 . "--committer=*" {mc "Committer:"}}
3978 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3979 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3980 {changes_l l + {} {mc "Changes to Files:"}}
3981 {pickaxe_s r0 . {} {mc "Fixed String"}}
3982 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3983 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3984 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3985 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3986 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3987 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3988 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3989 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3990 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3991 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3992 {lright b . "--left-right" {mc "Mark branch sides"}}
3993 {first b . "--first-parent" {mc "Limit to first parent"}}
3994 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3995 {args t50 *. {} {mc "Additional arguments to git log:"}}
3996 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3997 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4000 # Convert $newviewopts($n, ...) into args for git log.
4001 proc encode_view_opts {n} {
4002 global known_view_options newviewopts
4005 foreach opt $known_view_options {
4006 set patterns [lindex $opt 3]
4007 if {$patterns eq {}} continue
4008 set pattern [lindex $patterns 0]
4010 if {[lindex $opt 1] eq "b"} {
4011 set val $newviewopts($n,[lindex $opt 0])
4013 lappend rargs $pattern
4015 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4016 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4017 set val $newviewopts($n,$button_id)
4018 if {$val eq $value} {
4019 lappend rargs $pattern
4022 set val $newviewopts($n,[lindex $opt 0])
4023 set val [string trim $val]
4025 set pfix [string range $pattern 0 end-1]
4026 lappend rargs $pfix$val
4030 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4031 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4034 # Fill $newviewopts($n, ...) based on args for git log.
4035 proc decode_view_opts {n view_args} {
4036 global known_view_options newviewopts
4038 foreach opt $known_view_options {
4039 set id [lindex $opt 0]
4040 if {[lindex $opt 1] eq "b"} {
4043 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4045 regexp {^(.*_)} $id uselessvar id
4051 set newviewopts($n,$id) $val
4055 foreach arg $view_args {
4056 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4057 && ![info exists found(limit)]} {
4058 set newviewopts($n,limit) $cnt
4063 foreach opt $known_view_options {
4064 set id [lindex $opt 0]
4065 if {[info exists found($id)]} continue
4066 foreach pattern [lindex $opt 3] {
4067 if {![string match $pattern $arg]} continue
4068 if {[lindex $opt 1] eq "b"} {
4071 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4073 regexp {^(.*_)} $id uselessvar id
4077 set size [string length $pattern]
4078 set val [string range $arg [expr {$size-1}] end]
4080 set newviewopts($n,$id) $val
4084 if {[info exists val]} break
4086 if {[info exists val]} continue
4087 if {[regexp {^-} $arg]} {
4090 lappend refargs $arg
4093 set newviewopts($n,refs) [shellarglist $refargs]
4094 set newviewopts($n,args) [shellarglist $oargs]
4097 proc edit_or_newview {} {
4109 global viewname viewperm newviewname newviewopts
4110 global viewargs viewargscmd
4112 set top .gitkvedit-$curview
4113 if {[winfo exists $top]} {
4117 decode_view_opts $curview $viewargs($curview)
4118 set newviewname($curview) $viewname($curview)
4119 set newviewopts($curview,perm) $viewperm($curview)
4120 set newviewopts($curview,cmd) $viewargscmd($curview)
4121 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4124 proc vieweditor {top n title} {
4125 global newviewname newviewopts viewfiles bgcolor
4126 global known_view_options NS
4129 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4130 make_transient $top .
4133 ${NS}::frame $top.nfr
4134 ${NS}::label $top.nl -text [mc "View Name"]
4135 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4136 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4137 pack $top.nl -in $top.nfr -side left -padx {0 5}
4138 pack $top.name -in $top.nfr -side left -padx {0 25}
4144 foreach opt $known_view_options {
4145 set id [lindex $opt 0]
4146 set type [lindex $opt 1]
4147 set flags [lindex $opt 2]
4148 set title [eval [lindex $opt 4]]
4151 if {$flags eq "+" || $flags eq "*"} {
4152 set cframe $top.fr$cnt
4154 ${NS}::frame $cframe
4155 pack $cframe -in $top -fill x -pady 3 -padx 3
4156 set cexpand [expr {$flags eq "*"}]
4157 } elseif {$flags eq ".." || $flags eq "*."} {
4158 set cframe $top.fr$cnt
4160 ${NS}::frame $cframe
4161 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4162 set cexpand [expr {$flags eq "*."}]
4168 ${NS}::label $cframe.l_$id -text $title
4169 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4170 } elseif {$type eq "b"} {
4171 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4172 pack $cframe.c_$id -in $cframe -side left \
4173 -padx [list $lxpad 0] -expand $cexpand -anchor w
4174 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4175 regexp {^(.*_)} $id uselessvar button_id
4176 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4177 pack $cframe.c_$id -in $cframe -side left \
4178 -padx [list $lxpad 0] -expand $cexpand -anchor w
4179 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4180 ${NS}::label $cframe.l_$id -text $title
4181 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4182 -textvariable newviewopts($n,$id)
4183 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4184 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4185 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4186 ${NS}::label $cframe.l_$id -text $title
4187 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4188 -textvariable newviewopts($n,$id)
4189 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4190 pack $cframe.e_$id -in $cframe -side top -fill x
4191 } elseif {$type eq "path"} {
4192 ${NS}::label $top.l -text $title
4193 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4194 text $top.t -width 40 -height 5 -background $bgcolor
4195 if {[info exists viewfiles($n)]} {
4196 foreach f $viewfiles($n) {
4197 $top.t insert end $f
4198 $top.t insert end "\n"
4200 $top.t delete {end - 1c} end
4201 $top.t mark set insert 0.0
4203 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4207 ${NS}::frame $top.buts
4208 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4209 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4210 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4211 bind $top <Control-Return> [list newviewok $top $n]
4212 bind $top <F5> [list newviewok $top $n 1]
4213 bind $top <Escape> [list destroy $top]
4214 grid $top.buts.ok $top.buts.apply $top.buts.can
4215 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4216 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4217 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4218 pack $top.buts -in $top -side top -fill x
4222 proc doviewmenu {m first cmd op argv} {
4223 set nmenu [$m index end]
4224 for {set i $first} {$i <= $nmenu} {incr i} {
4225 if {[$m entrycget $i -command] eq $cmd} {
4226 eval $m $op $i $argv
4232 proc allviewmenus {n op args} {
4235 doviewmenu .bar.view 5 [list showview $n] $op $args
4236 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4239 proc newviewok {top n {apply 0}} {
4240 global nextviewnum newviewperm newviewname newishighlight
4241 global viewname viewfiles viewperm selectedview curview
4242 global viewargs viewargscmd newviewopts viewhlmenu
4245 set newargs [encode_view_opts $n]
4247 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4251 foreach f [split [$top.t get 0.0 end] "\n"] {
4252 set ft [string trim $f]
4257 if {![info exists viewfiles($n)]} {
4258 # creating a new view
4260 set viewname($n) $newviewname($n)
4261 set viewperm($n) $newviewopts($n,perm)
4262 set viewfiles($n) $files
4263 set viewargs($n) $newargs
4264 set viewargscmd($n) $newviewopts($n,cmd)
4266 if {!$newishighlight} {
4269 run addvhighlight $n
4272 # editing an existing view
4273 set viewperm($n) $newviewopts($n,perm)
4274 if {$newviewname($n) ne $viewname($n)} {
4275 set viewname($n) $newviewname($n)
4276 doviewmenu .bar.view 5 [list showview $n] \
4277 entryconf [list -label $viewname($n)]
4278 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4279 # entryconf [list -label $viewname($n) -value $viewname($n)]
4281 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4282 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4283 set viewfiles($n) $files
4284 set viewargs($n) $newargs
4285 set viewargscmd($n) $newviewopts($n,cmd)
4286 if {$curview == $n} {
4292 catch {destroy $top}
4296 global curview viewperm hlview selectedhlview
4298 if {$curview == 0} return
4299 if {[info exists hlview] && $hlview == $curview} {
4300 set selectedhlview [mc "None"]
4303 allviewmenus $curview delete
4304 set viewperm($curview) 0
4308 proc addviewmenu {n} {
4309 global viewname viewhlmenu
4311 .bar.view add radiobutton -label $viewname($n) \
4312 -command [list showview $n] -variable selectedview -value $n
4313 #$viewhlmenu add radiobutton -label $viewname($n) \
4314 # -command [list addvhighlight $n] -variable selectedhlview
4318 global curview cached_commitrow ordertok
4319 global displayorder parentlist rowidlist rowisopt rowfinal
4320 global colormap rowtextx nextcolor canvxmax
4321 global numcommits viewcomplete
4322 global selectedline currentid canv canvy0
4324 global pending_select mainheadid
4327 global hlview selectedhlview commitinterest
4329 if {$n == $curview} return
4331 set ymax [lindex [$canv cget -scrollregion] 3]
4332 set span [$canv yview]
4333 set ytop [expr {[lindex $span 0] * $ymax}]
4334 set ybot [expr {[lindex $span 1] * $ymax}]
4335 set yscreen [expr {($ybot - $ytop) / 2}]
4336 if {$selectedline ne {}} {
4337 set selid $currentid
4338 set y [yc $selectedline]
4339 if {$ytop < $y && $y < $ybot} {
4340 set yscreen [expr {$y - $ytop}]
4342 } elseif {[info exists pending_select]} {
4343 set selid $pending_select
4344 unset pending_select
4348 catch {unset treediffs}
4350 if {[info exists hlview] && $hlview == $n} {
4352 set selectedhlview [mc "None"]
4354 catch {unset commitinterest}
4355 catch {unset cached_commitrow}
4356 catch {unset ordertok}
4360 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4361 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4364 if {![info exists viewcomplete($n)]} {
4374 set numcommits $commitidx($n)
4376 catch {unset colormap}
4377 catch {unset rowtextx}
4379 set canvxmax [$canv cget -width]
4385 if {$selid ne {} && [commitinview $selid $n]} {
4386 set row [rowofcommit $selid]
4387 # try to get the selected row in the same position on the screen
4388 set ymax [lindex [$canv cget -scrollregion] 3]
4389 set ytop [expr {[yc $row] - $yscreen}]
4393 set yf [expr {$ytop * 1.0 / $ymax}]
4395 allcanvs yview moveto $yf
4399 } elseif {!$viewcomplete($n)} {
4400 reset_pending_select $selid
4402 reset_pending_select {}
4404 if {[commitinview $pending_select $curview]} {
4405 selectline [rowofcommit $pending_select] 1
4407 set row [first_real_row]
4408 if {$row < $numcommits} {
4413 if {!$viewcomplete($n)} {
4414 if {$numcommits == 0} {
4415 show_status [mc "Reading commits..."]
4417 } elseif {$numcommits == 0} {
4418 show_status [mc "No commits selected"]
4422 # Stuff relating to the highlighting facility
4424 proc ishighlighted {id} {
4425 global vhighlights fhighlights nhighlights rhighlights
4427 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4428 return $nhighlights($id)
4430 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4431 return $vhighlights($id)
4433 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4434 return $fhighlights($id)
4436 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4437 return $rhighlights($id)
4442 proc bolden {id font} {
4443 global canv linehtag currentid boldids need_redisplay markedid
4445 # need_redisplay = 1 means the display is stale and about to be redrawn
4446 if {$need_redisplay} return
4448 $canv itemconf $linehtag($id) -font $font
4449 if {[info exists currentid] && $id eq $currentid} {
4451 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4452 -outline {{}} -tags secsel \
4453 -fill [$canv cget -selectbackground]]
4456 if {[info exists markedid] && $id eq $markedid} {
4461 proc bolden_name {id font} {
4462 global canv2 linentag currentid boldnameids need_redisplay
4464 if {$need_redisplay} return
4465 lappend boldnameids $id
4466 $canv2 itemconf $linentag($id) -font $font
4467 if {[info exists currentid] && $id eq $currentid} {
4468 $canv2 delete secsel
4469 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4470 -outline {{}} -tags secsel \
4471 -fill [$canv2 cget -selectbackground]]
4480 foreach id $boldids {
4481 if {![ishighlighted $id]} {
4484 lappend stillbold $id
4487 set boldids $stillbold
4490 proc addvhighlight {n} {
4491 global hlview viewcomplete curview vhl_done commitidx
4493 if {[info exists hlview]} {
4497 if {$n != $curview && ![info exists viewcomplete($n)]} {
4500 set vhl_done $commitidx($hlview)
4501 if {$vhl_done > 0} {
4506 proc delvhighlight {} {
4507 global hlview vhighlights
4509 if {![info exists hlview]} return
4511 catch {unset vhighlights}
4515 proc vhighlightmore {} {
4516 global hlview vhl_done commitidx vhighlights curview
4518 set max $commitidx($hlview)
4519 set vr [visiblerows]
4520 set r0 [lindex $vr 0]
4521 set r1 [lindex $vr 1]
4522 for {set i $vhl_done} {$i < $max} {incr i} {
4523 set id [commitonrow $i $hlview]
4524 if {[commitinview $id $curview]} {
4525 set row [rowofcommit $id]
4526 if {$r0 <= $row && $row <= $r1} {
4527 if {![highlighted $row]} {
4528 bolden $id mainfontbold
4530 set vhighlights($id) 1
4538 proc askvhighlight {row id} {
4539 global hlview vhighlights iddrawn
4541 if {[commitinview $id $hlview]} {
4542 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4543 bolden $id mainfontbold
4545 set vhighlights($id) 1
4547 set vhighlights($id) 0
4551 proc hfiles_change {} {
4552 global highlight_files filehighlight fhighlights fh_serial
4553 global highlight_paths
4555 if {[info exists filehighlight]} {
4556 # delete previous highlights
4557 catch {close $filehighlight}
4559 catch {unset fhighlights}
4561 unhighlight_filelist
4563 set highlight_paths {}
4564 after cancel do_file_hl $fh_serial
4566 if {$highlight_files ne {}} {
4567 after 300 do_file_hl $fh_serial
4571 proc gdttype_change {name ix op} {
4572 global gdttype highlight_files findstring findpattern
4575 if {$findstring ne {}} {
4576 if {$gdttype eq [mc "containing:"]} {
4577 if {$highlight_files ne {}} {
4578 set highlight_files {}
4583 if {$findpattern ne {}} {
4587 set highlight_files $findstring
4592 # enable/disable findtype/findloc menus too
4595 proc find_change {name ix op} {
4596 global gdttype findstring highlight_files
4599 if {$gdttype eq [mc "containing:"]} {
4602 if {$highlight_files ne $findstring} {
4603 set highlight_files $findstring
4610 proc findcom_change args {
4611 global nhighlights boldnameids
4612 global findpattern findtype findstring gdttype
4615 # delete previous highlights, if any
4616 foreach id $boldnameids {
4617 bolden_name $id mainfont
4620 catch {unset nhighlights}
4623 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4625 } elseif {$findtype eq [mc "Regexp"]} {
4626 set findpattern $findstring
4628 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4630 set findpattern "*$e*"
4634 proc makepatterns {l} {
4637 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4638 if {[string index $ee end] eq "/"} {
4648 proc do_file_hl {serial} {
4649 global highlight_files filehighlight highlight_paths gdttype fhl_list
4650 global cdup findtype
4652 if {$gdttype eq [mc "touching paths:"]} {
4653 # If "exact" match then convert backslashes to forward slashes.
4654 # Most useful to support Windows-flavoured file paths.
4655 if {$findtype eq [mc "Exact"]} {
4656 set highlight_files [string map {"\\" "/"} $highlight_files]
4658 if {[catch {set paths [shellsplit $highlight_files]}]} return
4659 set highlight_paths [makepatterns $paths]
4661 set relative_paths {}
4662 foreach path $paths {
4663 lappend relative_paths [file join $cdup $path]
4665 set gdtargs [concat -- $relative_paths]
4666 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4667 set gdtargs [list "-S$highlight_files"]
4668 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4669 set gdtargs [list "-G$highlight_files"]
4671 # must be "containing:", i.e. we're searching commit info
4674 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4675 set filehighlight [open $cmd r+]
4676 fconfigure $filehighlight -blocking 0
4677 filerun $filehighlight readfhighlight
4683 proc flushhighlights {} {
4684 global filehighlight fhl_list
4686 if {[info exists filehighlight]} {
4688 puts $filehighlight ""
4689 flush $filehighlight
4693 proc askfilehighlight {row id} {
4694 global filehighlight fhighlights fhl_list
4696 lappend fhl_list $id
4697 set fhighlights($id) -1
4698 puts $filehighlight $id
4701 proc readfhighlight {} {
4702 global filehighlight fhighlights curview iddrawn
4703 global fhl_list find_dirn
4705 if {![info exists filehighlight]} {
4709 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4710 set line [string trim $line]
4711 set i [lsearch -exact $fhl_list $line]
4712 if {$i < 0} continue
4713 for {set j 0} {$j < $i} {incr j} {
4714 set id [lindex $fhl_list $j]
4715 set fhighlights($id) 0
4717 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4718 if {$line eq {}} continue
4719 if {![commitinview $line $curview]} continue
4720 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4721 bolden $line mainfontbold
4723 set fhighlights($line) 1
4725 if {[eof $filehighlight]} {
4727 puts "oops, git diff-tree died"
4728 catch {close $filehighlight}
4732 if {[info exists find_dirn]} {
4738 proc doesmatch {f} {
4739 global findtype findpattern
4741 if {$findtype eq [mc "Regexp"]} {
4742 return [regexp $findpattern $f]
4743 } elseif {$findtype eq [mc "IgnCase"]} {
4744 return [string match -nocase $findpattern $f]
4746 return [string match $findpattern $f]
4750 proc askfindhighlight {row id} {
4751 global nhighlights commitinfo iddrawn
4753 global markingmatches
4755 if {![info exists commitinfo($id)]} {
4758 set info $commitinfo($id)
4760 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4761 foreach f $info ty $fldtypes {
4762 if {$ty eq ""} continue
4763 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4765 if {$ty eq [mc "Author"]} {
4772 if {$isbold && [info exists iddrawn($id)]} {
4773 if {![ishighlighted $id]} {
4774 bolden $id mainfontbold
4776 bolden_name $id mainfontbold
4779 if {$markingmatches} {
4780 markrowmatches $row $id
4783 set nhighlights($id) $isbold
4786 proc markrowmatches {row id} {
4787 global canv canv2 linehtag linentag commitinfo findloc
4789 set headline [lindex $commitinfo($id) 0]
4790 set author [lindex $commitinfo($id) 1]
4791 $canv delete match$row
4792 $canv2 delete match$row
4793 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4794 set m [findmatches $headline]
4796 markmatches $canv $row $headline $linehtag($id) $m \
4797 [$canv itemcget $linehtag($id) -font] $row
4800 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4801 set m [findmatches $author]
4803 markmatches $canv2 $row $author $linentag($id) $m \
4804 [$canv2 itemcget $linentag($id) -font] $row
4809 proc vrel_change {name ix op} {
4810 global highlight_related
4813 if {$highlight_related ne [mc "None"]} {
4818 # prepare for testing whether commits are descendents or ancestors of a
4819 proc rhighlight_sel {a} {
4820 global descendent desc_todo ancestor anc_todo
4821 global highlight_related
4823 catch {unset descendent}
4824 set desc_todo [list $a]
4825 catch {unset ancestor}
4826 set anc_todo [list $a]
4827 if {$highlight_related ne [mc "None"]} {
4833 proc rhighlight_none {} {
4836 catch {unset rhighlights}
4840 proc is_descendent {a} {
4841 global curview children descendent desc_todo
4844 set la [rowofcommit $a]
4848 for {set i 0} {$i < [llength $todo]} {incr i} {
4849 set do [lindex $todo $i]
4850 if {[rowofcommit $do] < $la} {
4851 lappend leftover $do
4854 foreach nk $children($v,$do) {
4855 if {![info exists descendent($nk)]} {
4856 set descendent($nk) 1
4864 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4868 set descendent($a) 0
4869 set desc_todo $leftover
4872 proc is_ancestor {a} {
4873 global curview parents ancestor anc_todo
4876 set la [rowofcommit $a]
4880 for {set i 0} {$i < [llength $todo]} {incr i} {
4881 set do [lindex $todo $i]
4882 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4883 lappend leftover $do
4886 foreach np $parents($v,$do) {
4887 if {![info exists ancestor($np)]} {
4896 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4901 set anc_todo $leftover
4904 proc askrelhighlight {row id} {
4905 global descendent highlight_related iddrawn rhighlights
4906 global selectedline ancestor
4908 if {$selectedline eq {}} return
4910 if {$highlight_related eq [mc "Descendant"] ||
4911 $highlight_related eq [mc "Not descendant"]} {
4912 if {![info exists descendent($id)]} {
4915 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4918 } elseif {$highlight_related eq [mc "Ancestor"] ||
4919 $highlight_related eq [mc "Not ancestor"]} {
4920 if {![info exists ancestor($id)]} {
4923 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4927 if {[info exists iddrawn($id)]} {
4928 if {$isbold && ![ishighlighted $id]} {
4929 bolden $id mainfontbold
4932 set rhighlights($id) $isbold
4935 # Graph layout functions
4937 proc shortids {ids} {
4940 if {[llength $id] > 1} {
4941 lappend res [shortids $id]
4942 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4943 lappend res [string range $id 0 7]
4954 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4955 if {($n & $mask) != 0} {
4956 set ret [concat $ret $o]
4958 set o [concat $o $o]
4963 proc ordertoken {id} {
4964 global ordertok curview varcid varcstart varctok curview parents children
4965 global nullid nullid2
4967 if {[info exists ordertok($id)]} {
4968 return $ordertok($id)
4973 if {[info exists varcid($curview,$id)]} {
4974 set a $varcid($curview,$id)
4975 set p [lindex $varcstart($curview) $a]
4977 set p [lindex $children($curview,$id) 0]
4979 if {[info exists ordertok($p)]} {
4980 set tok $ordertok($p)
4983 set id [first_real_child $curview,$p]
4986 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4989 if {[llength $parents($curview,$id)] == 1} {
4990 lappend todo [list $p {}]
4992 set j [lsearch -exact $parents($curview,$id) $p]
4994 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4996 lappend todo [list $p [strrep $j]]
4999 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5000 set p [lindex $todo $i 0]
5001 append tok [lindex $todo $i 1]
5002 set ordertok($p) $tok
5004 set ordertok($origid) $tok
5008 # Work out where id should go in idlist so that order-token
5009 # values increase from left to right
5010 proc idcol {idlist id {i 0}} {
5011 set t [ordertoken $id]
5015 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5016 if {$i > [llength $idlist]} {
5017 set i [llength $idlist]
5019 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5022 if {$t > [ordertoken [lindex $idlist $i]]} {
5023 while {[incr i] < [llength $idlist] &&
5024 $t >= [ordertoken [lindex $idlist $i]]} {}
5030 proc initlayout {} {
5031 global rowidlist rowisopt rowfinal displayorder parentlist
5032 global numcommits canvxmax canv
5034 global colormap rowtextx
5043 set canvxmax [$canv cget -width]
5044 catch {unset colormap}
5045 catch {unset rowtextx}
5049 proc setcanvscroll {} {
5050 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5051 global lastscrollset lastscrollrows
5053 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5054 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5055 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5056 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5057 set lastscrollset [clock clicks -milliseconds]
5058 set lastscrollrows $numcommits
5061 proc visiblerows {} {
5062 global canv numcommits linespc
5064 set ymax [lindex [$canv cget -scrollregion] 3]
5065 if {$ymax eq {} || $ymax == 0} return
5067 set y0 [expr {int([lindex $f 0] * $ymax)}]
5068 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5072 set y1 [expr {int([lindex $f 1] * $ymax)}]
5073 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5074 if {$r1 >= $numcommits} {
5075 set r1 [expr {$numcommits - 1}]
5077 return [list $r0 $r1]
5080 proc layoutmore {} {
5081 global commitidx viewcomplete curview
5082 global numcommits pending_select curview
5083 global lastscrollset lastscrollrows
5085 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5086 [clock clicks -milliseconds] - $lastscrollset > 500} {
5089 if {[info exists pending_select] &&
5090 [commitinview $pending_select $curview]} {
5092 selectline [rowofcommit $pending_select] 1
5097 # With path limiting, we mightn't get the actual HEAD commit,
5098 # so ask git rev-list what is the first ancestor of HEAD that
5099 # touches a file in the path limit.
5100 proc get_viewmainhead {view} {
5101 global viewmainheadid vfilelimit viewinstances mainheadid
5104 set rfd [open [concat | git rev-list -1 $mainheadid \
5105 -- $vfilelimit($view)] r]
5106 set j [reg_instance $rfd]
5107 lappend viewinstances($view) $j
5108 fconfigure $rfd -blocking 0
5109 filerun $rfd [list getviewhead $rfd $j $view]
5110 set viewmainheadid($curview) {}
5114 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5115 proc getviewhead {fd inst view} {
5116 global viewmainheadid commfd curview viewinstances showlocalchanges
5119 if {[gets $fd line] < 0} {
5123 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5126 set viewmainheadid($view) $id
5129 set i [lsearch -exact $viewinstances($view) $inst]
5131 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5133 if {$showlocalchanges && $id ne {} && $view == $curview} {
5139 proc doshowlocalchanges {} {
5140 global curview viewmainheadid
5142 if {$viewmainheadid($curview) eq {}} return
5143 if {[commitinview $viewmainheadid($curview) $curview]} {
5146 interestedin $viewmainheadid($curview) dodiffindex
5150 proc dohidelocalchanges {} {
5151 global nullid nullid2 lserial curview
5153 if {[commitinview $nullid $curview]} {
5154 removefakerow $nullid
5156 if {[commitinview $nullid2 $curview]} {
5157 removefakerow $nullid2
5162 # spawn off a process to do git diff-index --cached HEAD
5163 proc dodiffindex {} {
5164 global lserial showlocalchanges vfilelimit curview
5165 global hasworktree git_version
5167 if {!$showlocalchanges || !$hasworktree} return
5169 if {[package vcompare $git_version "1.7.2"] >= 0} {
5170 set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
5172 set cmd "|git diff-index --cached HEAD"
5174 if {$vfilelimit($curview) ne {}} {
5175 set cmd [concat $cmd -- $vfilelimit($curview)]
5177 set fd [open $cmd r]
5178 fconfigure $fd -blocking 0
5179 set i [reg_instance $fd]
5180 filerun $fd [list readdiffindex $fd $lserial $i]
5183 proc readdiffindex {fd serial inst} {
5184 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5188 if {[gets $fd line] < 0} {
5194 # we only need to see one line and we don't really care what it says...
5197 if {$serial != $lserial} {
5201 # now see if there are any local changes not checked in to the index
5202 set cmd "|git diff-files"
5203 if {$vfilelimit($curview) ne {}} {
5204 set cmd [concat $cmd -- $vfilelimit($curview)]
5206 set fd [open $cmd r]
5207 fconfigure $fd -blocking 0
5208 set i [reg_instance $fd]
5209 filerun $fd [list readdifffiles $fd $serial $i]
5211 if {$isdiff && ![commitinview $nullid2 $curview]} {
5212 # add the line for the changes in the index to the graph
5213 set hl [mc "Local changes checked in to index but not committed"]
5214 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5215 set commitdata($nullid2) "\n $hl\n"
5216 if {[commitinview $nullid $curview]} {
5217 removefakerow $nullid
5219 insertfakerow $nullid2 $viewmainheadid($curview)
5220 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5221 if {[commitinview $nullid $curview]} {
5222 removefakerow $nullid
5224 removefakerow $nullid2
5229 proc readdifffiles {fd serial inst} {
5230 global viewmainheadid nullid nullid2 curview
5231 global commitinfo commitdata lserial
5234 if {[gets $fd line] < 0} {
5240 # we only need to see one line and we don't really care what it says...
5243 if {$serial != $lserial} {
5247 if {$isdiff && ![commitinview $nullid $curview]} {
5248 # add the line for the local diff to the graph
5249 set hl [mc "Local uncommitted changes, not checked in to index"]
5250 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5251 set commitdata($nullid) "\n $hl\n"
5252 if {[commitinview $nullid2 $curview]} {
5255 set p $viewmainheadid($curview)
5257 insertfakerow $nullid $p
5258 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5259 removefakerow $nullid
5264 proc nextuse {id row} {
5265 global curview children
5267 if {[info exists children($curview,$id)]} {
5268 foreach kid $children($curview,$id) {
5269 if {![commitinview $kid $curview]} {
5272 if {[rowofcommit $kid] > $row} {
5273 return [rowofcommit $kid]
5277 if {[commitinview $id $curview]} {
5278 return [rowofcommit $id]
5283 proc prevuse {id row} {
5284 global curview children
5287 if {[info exists children($curview,$id)]} {
5288 foreach kid $children($curview,$id) {
5289 if {![commitinview $kid $curview]} break
5290 if {[rowofcommit $kid] < $row} {
5291 set ret [rowofcommit $kid]
5298 proc make_idlist {row} {
5299 global displayorder parentlist uparrowlen downarrowlen mingaplen
5300 global commitidx curview children
5302 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5306 set ra [expr {$row - $downarrowlen}]
5310 set rb [expr {$row + $uparrowlen}]
5311 if {$rb > $commitidx($curview)} {
5312 set rb $commitidx($curview)
5314 make_disporder $r [expr {$rb + 1}]
5316 for {} {$r < $ra} {incr r} {
5317 set nextid [lindex $displayorder [expr {$r + 1}]]
5318 foreach p [lindex $parentlist $r] {
5319 if {$p eq $nextid} continue
5320 set rn [nextuse $p $r]
5322 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5323 lappend ids [list [ordertoken $p] $p]
5327 for {} {$r < $row} {incr r} {
5328 set nextid [lindex $displayorder [expr {$r + 1}]]
5329 foreach p [lindex $parentlist $r] {
5330 if {$p eq $nextid} continue
5331 set rn [nextuse $p $r]
5332 if {$rn < 0 || $rn >= $row} {
5333 lappend ids [list [ordertoken $p] $p]
5337 set id [lindex $displayorder $row]
5338 lappend ids [list [ordertoken $id] $id]
5340 foreach p [lindex $parentlist $r] {
5341 set firstkid [lindex $children($curview,$p) 0]
5342 if {[rowofcommit $firstkid] < $row} {
5343 lappend ids [list [ordertoken $p] $p]
5347 set id [lindex $displayorder $r]
5349 set firstkid [lindex $children($curview,$id) 0]
5350 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5351 lappend ids [list [ordertoken $id] $id]
5356 foreach idx [lsort -unique $ids] {
5357 lappend idlist [lindex $idx 1]
5362 proc rowsequal {a b} {
5363 while {[set i [lsearch -exact $a {}]] >= 0} {
5364 set a [lreplace $a $i $i]
5366 while {[set i [lsearch -exact $b {}]] >= 0} {
5367 set b [lreplace $b $i $i]
5369 return [expr {$a eq $b}]
5372 proc makeupline {id row rend col} {
5373 global rowidlist uparrowlen downarrowlen mingaplen
5375 for {set r $rend} {1} {set r $rstart} {
5376 set rstart [prevuse $id $r]
5377 if {$rstart < 0} return
5378 if {$rstart < $row} break
5380 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5381 set rstart [expr {$rend - $uparrowlen - 1}]
5383 for {set r $rstart} {[incr r] <= $row} {} {
5384 set idlist [lindex $rowidlist $r]
5385 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5386 set col [idcol $idlist $id $col]
5387 lset rowidlist $r [linsert $idlist $col $id]
5393 proc layoutrows {row endrow} {
5394 global rowidlist rowisopt rowfinal displayorder
5395 global uparrowlen downarrowlen maxwidth mingaplen
5396 global children parentlist
5397 global commitidx viewcomplete curview
5399 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5402 set rm1 [expr {$row - 1}]
5403 foreach id [lindex $rowidlist $rm1] {
5408 set final [lindex $rowfinal $rm1]
5410 for {} {$row < $endrow} {incr row} {
5411 set rm1 [expr {$row - 1}]
5412 if {$rm1 < 0 || $idlist eq {}} {
5413 set idlist [make_idlist $row]
5416 set id [lindex $displayorder $rm1]
5417 set col [lsearch -exact $idlist $id]
5418 set idlist [lreplace $idlist $col $col]
5419 foreach p [lindex $parentlist $rm1] {
5420 if {[lsearch -exact $idlist $p] < 0} {
5421 set col [idcol $idlist $p $col]
5422 set idlist [linsert $idlist $col $p]
5423 # if not the first child, we have to insert a line going up
5424 if {$id ne [lindex $children($curview,$p) 0]} {
5425 makeupline $p $rm1 $row $col
5429 set id [lindex $displayorder $row]
5430 if {$row > $downarrowlen} {
5431 set termrow [expr {$row - $downarrowlen - 1}]
5432 foreach p [lindex $parentlist $termrow] {
5433 set i [lsearch -exact $idlist $p]
5434 if {$i < 0} continue
5435 set nr [nextuse $p $termrow]
5436 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5437 set idlist [lreplace $idlist $i $i]
5441 set col [lsearch -exact $idlist $id]
5443 set col [idcol $idlist $id]
5444 set idlist [linsert $idlist $col $id]
5445 if {$children($curview,$id) ne {}} {
5446 makeupline $id $rm1 $row $col
5449 set r [expr {$row + $uparrowlen - 1}]
5450 if {$r < $commitidx($curview)} {
5452 foreach p [lindex $parentlist $r] {
5453 if {[lsearch -exact $idlist $p] >= 0} continue
5454 set fk [lindex $children($curview,$p) 0]
5455 if {[rowofcommit $fk] < $row} {
5456 set x [idcol $idlist $p $x]
5457 set idlist [linsert $idlist $x $p]
5460 if {[incr r] < $commitidx($curview)} {
5461 set p [lindex $displayorder $r]
5462 if {[lsearch -exact $idlist $p] < 0} {
5463 set fk [lindex $children($curview,$p) 0]
5464 if {$fk ne {} && [rowofcommit $fk] < $row} {
5465 set x [idcol $idlist $p $x]
5466 set idlist [linsert $idlist $x $p]
5472 if {$final && !$viewcomplete($curview) &&
5473 $row + $uparrowlen + $mingaplen + $downarrowlen
5474 >= $commitidx($curview)} {
5477 set l [llength $rowidlist]
5479 lappend rowidlist $idlist
5481 lappend rowfinal $final
5482 } elseif {$row < $l} {
5483 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5484 lset rowidlist $row $idlist
5487 lset rowfinal $row $final
5489 set pad [ntimes [expr {$row - $l}] {}]
5490 set rowidlist [concat $rowidlist $pad]
5491 lappend rowidlist $idlist
5492 set rowfinal [concat $rowfinal $pad]
5493 lappend rowfinal $final
5494 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5500 proc changedrow {row} {
5501 global displayorder iddrawn rowisopt need_redisplay
5503 set l [llength $rowisopt]
5505 lset rowisopt $row 0
5506 if {$row + 1 < $l} {
5507 lset rowisopt [expr {$row + 1}] 0
5508 if {$row + 2 < $l} {
5509 lset rowisopt [expr {$row + 2}] 0
5513 set id [lindex $displayorder $row]
5514 if {[info exists iddrawn($id)]} {
5515 set need_redisplay 1
5519 proc insert_pad {row col npad} {
5522 set pad [ntimes $npad {}]
5523 set idlist [lindex $rowidlist $row]
5524 set bef [lrange $idlist 0 [expr {$col - 1}]]
5525 set aft [lrange $idlist $col end]
5526 set i [lsearch -exact $aft {}]
5528 set aft [lreplace $aft $i $i]
5530 lset rowidlist $row [concat $bef $pad $aft]
5534 proc optimize_rows {row col endrow} {
5535 global rowidlist rowisopt displayorder curview children
5540 for {} {$row < $endrow} {incr row; set col 0} {
5541 if {[lindex $rowisopt $row]} continue
5543 set y0 [expr {$row - 1}]
5544 set ym [expr {$row - 2}]
5545 set idlist [lindex $rowidlist $row]
5546 set previdlist [lindex $rowidlist $y0]
5547 if {$idlist eq {} || $previdlist eq {}} continue
5549 set pprevidlist [lindex $rowidlist $ym]
5550 if {$pprevidlist eq {}} continue
5556 for {} {$col < [llength $idlist]} {incr col} {
5557 set id [lindex $idlist $col]
5558 if {[lindex $previdlist $col] eq $id} continue
5563 set x0 [lsearch -exact $previdlist $id]
5564 if {$x0 < 0} continue
5565 set z [expr {$x0 - $col}]
5569 set xm [lsearch -exact $pprevidlist $id]
5571 set z0 [expr {$xm - $x0}]
5575 # if row y0 is the first child of $id then it's not an arrow
5576 if {[lindex $children($curview,$id) 0] ne
5577 [lindex $displayorder $y0]} {
5581 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5582 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5585 # Looking at lines from this row to the previous row,
5586 # make them go straight up if they end in an arrow on
5587 # the previous row; otherwise make them go straight up
5589 if {$z < -1 || ($z < 0 && $isarrow)} {
5590 # Line currently goes left too much;
5591 # insert pads in the previous row, then optimize it
5592 set npad [expr {-1 - $z + $isarrow}]
5593 insert_pad $y0 $x0 $npad
5595 optimize_rows $y0 $x0 $row
5597 set previdlist [lindex $rowidlist $y0]
5598 set x0 [lsearch -exact $previdlist $id]
5599 set z [expr {$x0 - $col}]
5601 set pprevidlist [lindex $rowidlist $ym]
5602 set xm [lsearch -exact $pprevidlist $id]
5603 set z0 [expr {$xm - $x0}]
5605 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5606 # Line currently goes right too much;
5607 # insert pads in this line
5608 set npad [expr {$z - 1 + $isarrow}]
5609 insert_pad $row $col $npad
5610 set idlist [lindex $rowidlist $row]
5612 set z [expr {$x0 - $col}]
5615 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5616 # this line links to its first child on row $row-2
5617 set id [lindex $displayorder $ym]
5618 set xc [lsearch -exact $pprevidlist $id]
5620 set z0 [expr {$xc - $x0}]
5623 # avoid lines jigging left then immediately right
5624 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5625 insert_pad $y0 $x0 1
5627 optimize_rows $y0 $x0 $row
5628 set previdlist [lindex $rowidlist $y0]
5632 # Find the first column that doesn't have a line going right
5633 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5634 set id [lindex $idlist $col]
5635 if {$id eq {}} break
5636 set x0 [lsearch -exact $previdlist $id]
5638 # check if this is the link to the first child
5639 set kid [lindex $displayorder $y0]
5640 if {[lindex $children($curview,$id) 0] eq $kid} {
5641 # it is, work out offset to child
5642 set x0 [lsearch -exact $previdlist $kid]
5645 if {$x0 <= $col} break
5647 # Insert a pad at that column as long as it has a line and
5648 # isn't the last column
5649 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5650 set idlist [linsert $idlist $col {}]
5651 lset rowidlist $row $idlist
5659 global canvx0 linespc
5660 return [expr {$canvx0 + $col * $linespc}]
5664 global canvy0 linespc
5665 return [expr {$canvy0 + $row * $linespc}]
5668 proc linewidth {id} {
5669 global thickerline lthickness
5672 if {[info exists thickerline] && $id eq $thickerline} {
5673 set wid [expr {2 * $lthickness}]
5678 proc rowranges {id} {
5679 global curview children uparrowlen downarrowlen
5682 set kids $children($curview,$id)
5688 foreach child $kids {
5689 if {![commitinview $child $curview]} break
5690 set row [rowofcommit $child]
5691 if {![info exists prev]} {
5692 lappend ret [expr {$row + 1}]
5694 if {$row <= $prevrow} {
5695 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5697 # see if the line extends the whole way from prevrow to row
5698 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5699 [lsearch -exact [lindex $rowidlist \
5700 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5701 # it doesn't, see where it ends
5702 set r [expr {$prevrow + $downarrowlen}]
5703 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5704 while {[incr r -1] > $prevrow &&
5705 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5707 while {[incr r] <= $row &&
5708 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5712 # see where it starts up again
5713 set r [expr {$row - $uparrowlen}]
5714 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5715 while {[incr r] < $row &&
5716 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5718 while {[incr r -1] >= $prevrow &&
5719 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5725 if {$child eq $id} {
5734 proc drawlineseg {id row endrow arrowlow} {
5735 global rowidlist displayorder iddrawn linesegs
5736 global canv colormap linespc curview maxlinelen parentlist
5738 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5739 set le [expr {$row + 1}]
5742 set c [lsearch -exact [lindex $rowidlist $le] $id]
5748 set x [lindex $displayorder $le]
5753 if {[info exists iddrawn($x)] || $le == $endrow} {
5754 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5770 if {[info exists linesegs($id)]} {
5771 set lines $linesegs($id)
5773 set r0 [lindex $li 0]
5775 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5785 set li [lindex $lines [expr {$i-1}]]
5786 set r1 [lindex $li 1]
5787 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5792 set x [lindex $cols [expr {$le - $row}]]
5793 set xp [lindex $cols [expr {$le - 1 - $row}]]
5794 set dir [expr {$xp - $x}]
5796 set ith [lindex $lines $i 2]
5797 set coords [$canv coords $ith]
5798 set ah [$canv itemcget $ith -arrow]
5799 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5800 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5801 if {$x2 ne {} && $x - $x2 == $dir} {
5802 set coords [lrange $coords 0 end-2]
5805 set coords [list [xc $le $x] [yc $le]]
5808 set itl [lindex $lines [expr {$i-1}] 2]
5809 set al [$canv itemcget $itl -arrow]
5810 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5811 } elseif {$arrowlow} {
5812 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5813 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5817 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5818 for {set y $le} {[incr y -1] > $row} {} {
5820 set xp [lindex $cols [expr {$y - 1 - $row}]]
5821 set ndir [expr {$xp - $x}]
5822 if {$dir != $ndir || $xp < 0} {
5823 lappend coords [xc $y $x] [yc $y]
5829 # join parent line to first child
5830 set ch [lindex $displayorder $row]
5831 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5833 puts "oops: drawlineseg: child $ch not on row $row"
5834 } elseif {$xc != $x} {
5835 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5836 set d [expr {int(0.5 * $linespc)}]
5839 set x2 [expr {$x1 - $d}]
5841 set x2 [expr {$x1 + $d}]
5844 set y1 [expr {$y2 + $d}]
5845 lappend coords $x1 $y1 $x2 $y2
5846 } elseif {$xc < $x - 1} {
5847 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5848 } elseif {$xc > $x + 1} {
5849 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5853 lappend coords [xc $row $x] [yc $row]
5855 set xn [xc $row $xp]
5857 lappend coords $xn $yn
5861 set t [$canv create line $coords -width [linewidth $id] \
5862 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5865 set lines [linsert $lines $i [list $row $le $t]]
5867 $canv coords $ith $coords
5868 if {$arrow ne $ah} {
5869 $canv itemconf $ith -arrow $arrow
5871 lset lines $i 0 $row
5874 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5875 set ndir [expr {$xo - $xp}]
5876 set clow [$canv coords $itl]
5877 if {$dir == $ndir} {
5878 set clow [lrange $clow 2 end]
5880 set coords [concat $coords $clow]
5882 lset lines [expr {$i-1}] 1 $le
5884 # coalesce two pieces
5886 set b [lindex $lines [expr {$i-1}] 0]
5887 set e [lindex $lines $i 1]
5888 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5890 $canv coords $itl $coords
5891 if {$arrow ne $al} {
5892 $canv itemconf $itl -arrow $arrow
5896 set linesegs($id) $lines
5900 proc drawparentlinks {id row} {
5901 global rowidlist canv colormap curview parentlist
5902 global idpos linespc
5904 set rowids [lindex $rowidlist $row]
5905 set col [lsearch -exact $rowids $id]
5906 if {$col < 0} return
5907 set olds [lindex $parentlist $row]
5908 set row2 [expr {$row + 1}]
5909 set x [xc $row $col]
5912 set d [expr {int(0.5 * $linespc)}]
5913 set ymid [expr {$y + $d}]
5914 set ids [lindex $rowidlist $row2]
5915 # rmx = right-most X coord used
5918 set i [lsearch -exact $ids $p]
5920 puts "oops, parent $p of $id not in list"
5923 set x2 [xc $row2 $i]
5927 set j [lsearch -exact $rowids $p]
5929 # drawlineseg will do this one for us
5933 # should handle duplicated parents here...
5934 set coords [list $x $y]
5936 # if attaching to a vertical segment, draw a smaller
5937 # slant for visual distinctness
5940 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5942 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5944 } elseif {$i < $col && $i < $j} {
5945 # segment slants towards us already
5946 lappend coords [xc $row $j] $y
5948 if {$i < $col - 1} {
5949 lappend coords [expr {$x2 + $linespc}] $y
5950 } elseif {$i > $col + 1} {
5951 lappend coords [expr {$x2 - $linespc}] $y
5953 lappend coords $x2 $y2
5956 lappend coords $x2 $y2
5958 set t [$canv create line $coords -width [linewidth $p] \
5959 -fill $colormap($p) -tags lines.$p]
5963 if {$rmx > [lindex $idpos($id) 1]} {
5964 lset idpos($id) 1 $rmx
5969 proc drawlines {id} {
5972 $canv itemconf lines.$id -width [linewidth $id]
5975 proc drawcmittext {id row col} {
5976 global linespc canv canv2 canv3 fgcolor curview
5977 global cmitlisted commitinfo rowidlist parentlist
5978 global rowtextx idpos idtags idheads idotherrefs
5979 global linehtag linentag linedtag selectedline
5980 global canvxmax boldids boldnameids fgcolor markedid
5981 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5982 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5983 global circleoutlinecolor
5985 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5986 set listed $cmitlisted($curview,$id)
5987 if {$id eq $nullid} {
5988 set ofill $workingfilescirclecolor
5989 } elseif {$id eq $nullid2} {
5990 set ofill $indexcirclecolor
5991 } elseif {$id eq $mainheadid} {
5992 set ofill $mainheadcirclecolor
5994 set ofill [lindex $circlecolors $listed]
5996 set x [xc $row $col]
5998 set orad [expr {$linespc / 3}]
6000 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6001 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6002 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6003 } elseif {$listed == 3} {
6004 # triangle pointing left for left-side commits
6005 set t [$canv create polygon \
6006 [expr {$x - $orad}] $y \
6007 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6008 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6009 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6011 # triangle pointing right for right-side commits
6012 set t [$canv create polygon \
6013 [expr {$x + $orad - 1}] $y \
6014 [expr {$x - $orad}] [expr {$y - $orad}] \
6015 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6016 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6018 set circleitem($row) $t
6020 $canv bind $t <1> {selcanvline {} %x %y}
6021 set rmx [llength [lindex $rowidlist $row]]
6022 set olds [lindex $parentlist $row]
6024 set nextids [lindex $rowidlist [expr {$row + 1}]]
6026 set i [lsearch -exact $nextids $p]
6032 set xt [xc $row $rmx]
6033 set rowtextx($row) $xt
6034 set idpos($id) [list $x $xt $y]
6035 if {[info exists idtags($id)] || [info exists idheads($id)]
6036 || [info exists idotherrefs($id)]} {
6037 set xt [drawtags $id $x $xt $y]
6039 if {[lindex $commitinfo($id) 6] > 0} {
6040 set xt [drawnotesign $xt $y]
6042 set headline [lindex $commitinfo($id) 0]
6043 set name [lindex $commitinfo($id) 1]
6044 set date [lindex $commitinfo($id) 2]
6045 set date [formatdate $date]
6048 set isbold [ishighlighted $id]
6051 set font mainfontbold
6053 lappend boldnameids $id
6054 set nfont mainfontbold
6057 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6058 -text $headline -font $font -tags text]
6059 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6060 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6061 -text $name -font $nfont -tags text]
6062 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6063 -text $date -font mainfont -tags text]
6064 if {$selectedline == $row} {
6067 if {[info exists markedid] && $markedid eq $id} {
6070 set xr [expr {$xt + [font measure $font $headline]}]
6071 if {$xr > $canvxmax} {
6077 proc drawcmitrow {row} {
6078 global displayorder rowidlist nrows_drawn
6079 global iddrawn markingmatches
6080 global commitinfo numcommits
6081 global filehighlight fhighlights findpattern nhighlights
6082 global hlview vhighlights
6083 global highlight_related rhighlights
6085 if {$row >= $numcommits} return
6087 set id [lindex $displayorder $row]
6088 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6089 askvhighlight $row $id
6091 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6092 askfilehighlight $row $id
6094 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6095 askfindhighlight $row $id
6097 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6098 askrelhighlight $row $id
6100 if {![info exists iddrawn($id)]} {
6101 set col [lsearch -exact [lindex $rowidlist $row] $id]
6103 puts "oops, row $row id $id not in list"
6106 if {![info exists commitinfo($id)]} {
6110 drawcmittext $id $row $col
6114 if {$markingmatches} {
6115 markrowmatches $row $id
6119 proc drawcommits {row {endrow {}}} {
6120 global numcommits iddrawn displayorder curview need_redisplay
6121 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6126 if {$endrow eq {}} {
6129 if {$endrow >= $numcommits} {
6130 set endrow [expr {$numcommits - 1}]
6133 set rl1 [expr {$row - $downarrowlen - 3}]
6137 set ro1 [expr {$row - 3}]
6141 set r2 [expr {$endrow + $uparrowlen + 3}]
6142 if {$r2 > $numcommits} {
6145 for {set r $rl1} {$r < $r2} {incr r} {
6146 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6150 set rl1 [expr {$r + 1}]
6156 optimize_rows $ro1 0 $r2
6157 if {$need_redisplay || $nrows_drawn > 2000} {
6161 # make the lines join to already-drawn rows either side
6162 set r [expr {$row - 1}]
6163 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6166 set er [expr {$endrow + 1}]
6167 if {$er >= $numcommits ||
6168 ![info exists iddrawn([lindex $displayorder $er])]} {
6171 for {} {$r <= $er} {incr r} {
6172 set id [lindex $displayorder $r]
6173 set wasdrawn [info exists iddrawn($id)]
6175 if {$r == $er} break
6176 set nextid [lindex $displayorder [expr {$r + 1}]]
6177 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6178 drawparentlinks $id $r
6180 set rowids [lindex $rowidlist $r]
6181 foreach lid $rowids {
6182 if {$lid eq {}} continue
6183 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6185 # see if this is the first child of any of its parents
6186 foreach p [lindex $parentlist $r] {
6187 if {[lsearch -exact $rowids $p] < 0} {
6188 # make this line extend up to the child
6189 set lineend($p) [drawlineseg $p $r $er 0]
6193 set lineend($lid) [drawlineseg $lid $r $er 1]
6199 proc undolayout {row} {
6200 global uparrowlen mingaplen downarrowlen
6201 global rowidlist rowisopt rowfinal need_redisplay
6203 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6207 if {[llength $rowidlist] > $r} {
6209 set rowidlist [lrange $rowidlist 0 $r]
6210 set rowfinal [lrange $rowfinal 0 $r]
6211 set rowisopt [lrange $rowisopt 0 $r]
6212 set need_redisplay 1
6217 proc drawvisible {} {
6218 global canv linespc curview vrowmod selectedline targetrow targetid
6219 global need_redisplay cscroll numcommits
6221 set fs [$canv yview]
6222 set ymax [lindex [$canv cget -scrollregion] 3]
6223 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6224 set f0 [lindex $fs 0]
6225 set f1 [lindex $fs 1]
6226 set y0 [expr {int($f0 * $ymax)}]
6227 set y1 [expr {int($f1 * $ymax)}]
6229 if {[info exists targetid]} {
6230 if {[commitinview $targetid $curview]} {
6231 set r [rowofcommit $targetid]
6232 if {$r != $targetrow} {
6233 # Fix up the scrollregion and change the scrolling position
6234 # now that our target row has moved.
6235 set diff [expr {($r - $targetrow) * $linespc}]
6238 set ymax [lindex [$canv cget -scrollregion] 3]
6241 set f0 [expr {$y0 / $ymax}]
6242 set f1 [expr {$y1 / $ymax}]
6243 allcanvs yview moveto $f0
6244 $cscroll set $f0 $f1
6245 set need_redisplay 1
6252 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6253 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6254 if {$endrow >= $vrowmod($curview)} {
6255 update_arcrows $curview
6257 if {$selectedline ne {} &&
6258 $row <= $selectedline && $selectedline <= $endrow} {
6259 set targetrow $selectedline
6260 } elseif {[info exists targetid]} {
6261 set targetrow [expr {int(($row + $endrow) / 2)}]
6263 if {[info exists targetrow]} {
6264 if {$targetrow >= $numcommits} {
6265 set targetrow [expr {$numcommits - 1}]
6267 set targetid [commitonrow $targetrow]
6269 drawcommits $row $endrow
6272 proc clear_display {} {
6273 global iddrawn linesegs need_redisplay nrows_drawn
6274 global vhighlights fhighlights nhighlights rhighlights
6275 global linehtag linentag linedtag boldids boldnameids
6278 catch {unset iddrawn}
6279 catch {unset linesegs}
6280 catch {unset linehtag}
6281 catch {unset linentag}
6282 catch {unset linedtag}
6285 catch {unset vhighlights}
6286 catch {unset fhighlights}
6287 catch {unset nhighlights}
6288 catch {unset rhighlights}
6289 set need_redisplay 0
6293 proc findcrossings {id} {
6294 global rowidlist parentlist numcommits displayorder
6298 foreach {s e} [rowranges $id] {
6299 if {$e >= $numcommits} {
6300 set e [expr {$numcommits - 1}]
6302 if {$e <= $s} continue
6303 for {set row $e} {[incr row -1] >= $s} {} {
6304 set x [lsearch -exact [lindex $rowidlist $row] $id]
6306 set olds [lindex $parentlist $row]
6307 set kid [lindex $displayorder $row]
6308 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6309 if {$kidx < 0} continue
6310 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6312 set px [lsearch -exact $nextrow $p]
6313 if {$px < 0} continue
6314 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6315 if {[lsearch -exact $ccross $p] >= 0} continue
6316 if {$x == $px + ($kidx < $px? -1: 1)} {
6318 } elseif {[lsearch -exact $cross $p] < 0} {
6325 return [concat $ccross {{}} $cross]
6328 proc assigncolor {id} {
6329 global colormap colors nextcolor
6330 global parents children children curview
6332 if {[info exists colormap($id)]} return
6333 set ncolors [llength $colors]
6334 if {[info exists children($curview,$id)]} {
6335 set kids $children($curview,$id)
6339 if {[llength $kids] == 1} {
6340 set child [lindex $kids 0]
6341 if {[info exists colormap($child)]
6342 && [llength $parents($curview,$child)] == 1} {
6343 set colormap($id) $colormap($child)
6349 foreach x [findcrossings $id] {
6351 # delimiter between corner crossings and other crossings
6352 if {[llength $badcolors] >= $ncolors - 1} break
6353 set origbad $badcolors
6355 if {[info exists colormap($x)]
6356 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6357 lappend badcolors $colormap($x)
6360 if {[llength $badcolors] >= $ncolors} {
6361 set badcolors $origbad
6363 set origbad $badcolors
6364 if {[llength $badcolors] < $ncolors - 1} {
6365 foreach child $kids {
6366 if {[info exists colormap($child)]
6367 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6368 lappend badcolors $colormap($child)
6370 foreach p $parents($curview,$child) {
6371 if {[info exists colormap($p)]
6372 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6373 lappend badcolors $colormap($p)
6377 if {[llength $badcolors] >= $ncolors} {
6378 set badcolors $origbad
6381 for {set i 0} {$i <= $ncolors} {incr i} {
6382 set c [lindex $colors $nextcolor]
6383 if {[incr nextcolor] >= $ncolors} {
6386 if {[lsearch -exact $badcolors $c]} break
6388 set colormap($id) $c
6391 proc bindline {t id} {
6394 $canv bind $t <Enter> "lineenter %x %y $id"
6395 $canv bind $t <Motion> "linemotion %x %y $id"
6396 $canv bind $t <Leave> "lineleave $id"
6397 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6400 proc graph_pane_width {} {
6404 set g [.tf.histframe.pwclist sashpos 0]
6406 set g [.tf.histframe.pwclist sash coord 0]
6408 return [lindex $g 0]
6411 proc totalwidth {l font extra} {
6414 set tot [expr {$tot + [font measure $font $str] + $extra}]
6419 proc drawtags {id x xt y1} {
6420 global idtags idheads idotherrefs mainhead
6421 global linespc lthickness
6422 global canv rowtextx curview fgcolor bgcolor ctxbut
6423 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6424 global tagbgcolor tagfgcolor tagoutlinecolor
6433 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6434 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6435 set extra [expr {$delta + $lthickness + $linespc}]
6437 if {[info exists idtags($id)]} {
6438 set marks $idtags($id)
6439 set ntags [llength $marks]
6440 if {$ntags > $maxtags ||
6441 [totalwidth $marks mainfont $extra] > $maxwidth} {
6442 # show just a single "n tags..." tag
6445 set marks [list "tag..."]
6447 set marks [list [format "%d tags..." $ntags]]
6452 if {[info exists idheads($id)]} {
6453 set marks [concat $marks $idheads($id)]
6454 set nheads [llength $idheads($id)]
6456 if {[info exists idotherrefs($id)]} {
6457 set marks [concat $marks $idotherrefs($id)]
6463 set yt [expr {$y1 - 0.5 * $linespc}]
6464 set yb [expr {$yt + $linespc - 1}]
6468 foreach tag $marks {
6470 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6471 set wid [font measure mainfontbold $tag]
6473 set wid [font measure mainfont $tag]
6477 set xt [expr {$xt + $wid + $extra}]
6479 set yl [expr {$y1 - $lthickness}]
6480 set t [$canv create line $x $yl [lindex $xvals end] $yl \
6481 -width $lthickness -fill $reflinecolor -tags tag.$id]
6483 foreach tag $marks x $xvals wid $wvals {
6484 set tag_quoted [string map {% %%} $tag]
6485 set xl [expr {$x + $delta}]
6486 set xr [expr {$x + $delta + $wid + $lthickness}]
6488 if {[incr ntags -1] >= 0} {
6490 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6491 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6492 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6495 set tagclick [list showtags $id 1]
6497 set tagclick [list showtag $tag_quoted 1]
6499 $canv bind $t <1> $tagclick
6500 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6502 # draw a head or other ref
6503 if {[incr nheads -1] >= 0} {
6504 set col $headbgcolor
6505 if {$tag eq $mainhead} {
6506 set font mainfontbold
6511 set xl [expr {$xl - $delta/2}]
6512 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6513 -width 1 -outline black -fill $col -tags tag.$id
6514 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6515 set rwid [font measure mainfont $remoteprefix]
6516 set xi [expr {$x + 1}]
6517 set yti [expr {$yt + 1}]
6518 set xri [expr {$x + $rwid}]
6519 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6520 -width 0 -fill $remotebgcolor -tags tag.$id
6523 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6524 -font $font -tags [list tag.$id text]]
6526 $canv bind $t <1> $tagclick
6527 } elseif {$nheads >= 0} {
6528 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6534 proc drawnotesign {xt y} {
6535 global linespc canv fgcolor
6537 set orad [expr {$linespc / 3}]
6538 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6539 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6540 -fill yellow -outline $fgcolor -width 1 -tags circle]
6541 set xt [expr {$xt + $orad * 3}]
6545 proc xcoord {i level ln} {
6546 global canvx0 xspc1 xspc2
6548 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6549 if {$i > 0 && $i == $level} {
6550 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6551 } elseif {$i > $level} {
6552 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6557 proc show_status {msg} {
6561 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6562 -tags text -fill $fgcolor
6565 # Don't change the text pane cursor if it is currently the hand cursor,
6566 # showing that we are over a sha1 ID link.
6567 proc settextcursor {c} {
6568 global ctext curtextcursor
6570 if {[$ctext cget -cursor] == $curtextcursor} {
6571 $ctext config -cursor $c
6573 set curtextcursor $c
6576 proc nowbusy {what {name {}}} {
6577 global isbusy busyname statusw
6579 if {[array names isbusy] eq {}} {
6580 . config -cursor watch
6584 set busyname($what) $name
6586 $statusw conf -text $name
6590 proc notbusy {what} {
6591 global isbusy maincursor textcursor busyname statusw
6595 if {$busyname($what) ne {} &&
6596 [$statusw cget -text] eq $busyname($what)} {
6597 $statusw conf -text {}
6600 if {[array names isbusy] eq {}} {
6601 . config -cursor $maincursor
6602 settextcursor $textcursor
6606 proc findmatches {f} {
6607 global findtype findstring
6608 if {$findtype == [mc "Regexp"]} {
6609 set matches [regexp -indices -all -inline $findstring $f]
6612 if {$findtype == [mc "IgnCase"]} {
6613 set f [string tolower $f]
6614 set fs [string tolower $fs]
6618 set l [string length $fs]
6619 while {[set j [string first $fs $f $i]] >= 0} {
6620 lappend matches [list $j [expr {$j+$l-1}]]
6621 set i [expr {$j + $l}]
6627 proc dofind {{dirn 1} {wrap 1}} {
6628 global findstring findstartline findcurline selectedline numcommits
6629 global gdttype filehighlight fh_serial find_dirn findallowwrap
6631 if {[info exists find_dirn]} {
6632 if {$find_dirn == $dirn} return
6636 if {$findstring eq {} || $numcommits == 0} return
6637 if {$selectedline eq {}} {
6638 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6640 set findstartline $selectedline
6642 set findcurline $findstartline
6643 nowbusy finding [mc "Searching"]
6644 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6645 after cancel do_file_hl $fh_serial
6646 do_file_hl $fh_serial
6649 set findallowwrap $wrap
6653 proc stopfinding {} {
6654 global find_dirn findcurline fprogcoord
6656 if {[info exists find_dirn]} {
6667 global commitdata commitinfo numcommits findpattern findloc
6668 global findstartline findcurline findallowwrap
6669 global find_dirn gdttype fhighlights fprogcoord
6670 global curview varcorder vrownum varccommits vrowmod
6672 if {![info exists find_dirn]} {
6675 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6678 if {$find_dirn > 0} {
6680 if {$l >= $numcommits} {
6683 if {$l <= $findstartline} {
6684 set lim [expr {$findstartline + 1}]
6687 set moretodo $findallowwrap
6694 if {$l >= $findstartline} {
6695 set lim [expr {$findstartline - 1}]
6698 set moretodo $findallowwrap
6701 set n [expr {($lim - $l) * $find_dirn}]
6706 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6707 update_arcrows $curview
6711 set ai [bsearch $vrownum($curview) $l]
6712 set a [lindex $varcorder($curview) $ai]
6713 set arow [lindex $vrownum($curview) $ai]
6714 set ids [lindex $varccommits($curview,$a)]
6715 set arowend [expr {$arow + [llength $ids]}]
6716 if {$gdttype eq [mc "containing:"]} {
6717 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6718 if {$l < $arow || $l >= $arowend} {
6720 set a [lindex $varcorder($curview) $ai]
6721 set arow [lindex $vrownum($curview) $ai]
6722 set ids [lindex $varccommits($curview,$a)]
6723 set arowend [expr {$arow + [llength $ids]}]
6725 set id [lindex $ids [expr {$l - $arow}]]
6726 # shouldn't happen unless git log doesn't give all the commits...
6727 if {![info exists commitdata($id)] ||
6728 ![doesmatch $commitdata($id)]} {
6731 if {![info exists commitinfo($id)]} {
6734 set info $commitinfo($id)
6735 foreach f $info ty $fldtypes {
6736 if {$ty eq ""} continue
6737 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6746 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6747 if {$l < $arow || $l >= $arowend} {
6749 set a [lindex $varcorder($curview) $ai]
6750 set arow [lindex $vrownum($curview) $ai]
6751 set ids [lindex $varccommits($curview,$a)]
6752 set arowend [expr {$arow + [llength $ids]}]
6754 set id [lindex $ids [expr {$l - $arow}]]
6755 if {![info exists fhighlights($id)]} {
6756 # this sets fhighlights($id) to -1
6757 askfilehighlight $l $id
6759 if {$fhighlights($id) > 0} {
6763 if {$fhighlights($id) < 0} {
6766 set findcurline [expr {$l - $find_dirn}]
6771 if {$found || ($domore && !$moretodo)} {
6787 set findcurline [expr {$l - $find_dirn}]
6789 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6793 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6798 proc findselectline {l} {
6799 global findloc commentend ctext findcurline markingmatches gdttype
6801 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6804 if {$markingmatches &&
6805 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6806 # highlight the matches in the comments
6807 set f [$ctext get 1.0 $commentend]
6808 set matches [findmatches $f]
6809 foreach match $matches {
6810 set start [lindex $match 0]
6811 set end [expr {[lindex $match 1] + 1}]
6812 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6818 # mark the bits of a headline or author that match a find string
6819 proc markmatches {canv l str tag matches font row} {
6822 set bbox [$canv bbox $tag]
6823 set x0 [lindex $bbox 0]
6824 set y0 [lindex $bbox 1]
6825 set y1 [lindex $bbox 3]
6826 foreach match $matches {
6827 set start [lindex $match 0]
6828 set end [lindex $match 1]
6829 if {$start > $end} continue
6830 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6831 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6832 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6833 [expr {$x0+$xlen+2}] $y1 \
6834 -outline {} -tags [list match$l matches] -fill yellow]
6836 if {$row == $selectedline} {
6837 $canv raise $t secsel
6842 proc unmarkmatches {} {
6843 global markingmatches
6845 allcanvs delete matches
6846 set markingmatches 0
6850 proc selcanvline {w x y} {
6851 global canv canvy0 ctext linespc
6853 set ymax [lindex [$canv cget -scrollregion] 3]
6854 if {$ymax == {}} return
6855 set yfrac [lindex [$canv yview] 0]
6856 set y [expr {$y + $yfrac * $ymax}]
6857 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6862 set xmax [lindex [$canv cget -scrollregion] 2]
6863 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6864 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6870 proc commit_descriptor {p} {
6872 if {![info exists commitinfo($p)]} {
6876 if {[llength $commitinfo($p)] > 1} {
6877 set l [lindex $commitinfo($p) 0]
6882 # append some text to the ctext widget, and make any SHA1 ID
6883 # that we know about be a clickable link.
6884 proc appendwithlinks {text tags} {
6885 global ctext linknum curview
6887 set start [$ctext index "end - 1c"]
6888 $ctext insert end $text $tags
6889 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6893 set linkid [string range $text $s $e]
6895 $ctext tag delete link$linknum
6896 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6897 setlink $linkid link$linknum
6902 proc setlink {id lk} {
6903 global curview ctext pendinglinks
6906 if {[string range $id 0 1] eq "-g"} {
6907 set id [string range $id 2 end]
6911 if {[string length $id] < 40} {
6912 set matches [longid $id]
6913 if {[llength $matches] > 0} {
6914 if {[llength $matches] > 1} return
6916 set id [lindex $matches 0]
6919 set known [commitinview $id $curview]
6922 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6923 $ctext tag bind $lk <1> [list selbyid $id]
6924 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6925 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6927 lappend pendinglinks($id) $lk
6928 interestedin $id {makelink %P}
6932 proc appendshortlink {id {pre {}} {post {}}} {
6933 global ctext linknum
6935 $ctext insert end $pre
6936 $ctext tag delete link$linknum
6937 $ctext insert end [string range $id 0 7] link$linknum
6938 $ctext insert end $post
6939 setlink $id link$linknum
6943 proc makelink {id} {
6946 if {![info exists pendinglinks($id)]} return
6947 foreach lk $pendinglinks($id) {
6950 unset pendinglinks($id)
6953 proc linkcursor {w inc} {
6954 global linkentercount curtextcursor
6956 if {[incr linkentercount $inc] > 0} {
6957 $w configure -cursor hand2
6959 $w configure -cursor $curtextcursor
6960 if {$linkentercount < 0} {
6961 set linkentercount 0
6966 proc viewnextline {dir} {
6970 set ymax [lindex [$canv cget -scrollregion] 3]
6971 set wnow [$canv yview]
6972 set wtop [expr {[lindex $wnow 0] * $ymax}]
6973 set newtop [expr {$wtop + $dir * $linespc}]
6976 } elseif {$newtop > $ymax} {
6979 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6982 # add a list of tag or branch names at position pos
6983 # returns the number of names inserted
6984 proc appendrefs {pos ids var} {
6985 global ctext linknum curview $var maxrefs visiblerefs mainheadid
6987 if {[catch {$ctext index $pos}]} {
6990 $ctext conf -state normal
6991 $ctext delete $pos "$pos lineend"
6994 foreach tag [set $var\($id\)] {
6995 lappend tags [list $tag $id]
7000 set tags [lsort -index 0 -decreasing $tags]
7003 if {[llength $tags] > $maxrefs} {
7004 # If we are displaying heads, and there are too many,
7005 # see if there are some important heads to display.
7006 # Currently that are the current head and heads listed in $visiblerefs option
7008 if {$var eq "idheads"} {
7011 set hname [lindex $ti 0]
7012 set id [lindex $ti 1]
7013 if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) &&
7014 [llength $itags] < $maxrefs} {
7023 set str [mc "and many more"]
7028 $ctext insert $pos "$str ([llength $tags])"
7029 set nutags [llength $tags]
7034 set id [lindex $ti 1]
7037 $ctext tag delete $lk
7038 $ctext insert $pos $sep
7039 $ctext insert $pos [lindex $ti 0] $lk
7043 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7044 $ctext conf -state disabled
7045 return [expr {[llength $tags] + $nutags}]
7048 # called when we have finished computing the nearby tags
7049 proc dispneartags {delay} {
7050 global selectedline currentid showneartags tagphase
7052 if {$selectedline eq {} || !$showneartags} return
7053 after cancel dispnexttag
7055 after 200 dispnexttag
7058 after idle dispnexttag
7063 proc dispnexttag {} {
7064 global selectedline currentid showneartags tagphase ctext
7066 if {$selectedline eq {} || !$showneartags} return
7067 switch -- $tagphase {
7069 set dtags [desctags $currentid]
7071 appendrefs precedes $dtags idtags
7075 set atags [anctags $currentid]
7077 appendrefs follows $atags idtags
7081 set dheads [descheads $currentid]
7082 if {$dheads ne {}} {
7083 if {[appendrefs branch $dheads idheads] > 1
7084 && [$ctext get "branch -3c"] eq "h"} {
7085 # turn "Branch" into "Branches"
7086 $ctext conf -state normal
7087 $ctext insert "branch -2c" "es"
7088 $ctext conf -state disabled
7093 if {[incr tagphase] <= 2} {
7094 after idle dispnexttag
7098 proc make_secsel {id} {
7099 global linehtag linentag linedtag canv canv2 canv3
7101 if {![info exists linehtag($id)]} return
7103 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7104 -tags secsel -fill [$canv cget -selectbackground]]
7106 $canv2 delete secsel
7107 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7108 -tags secsel -fill [$canv2 cget -selectbackground]]
7110 $canv3 delete secsel
7111 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7112 -tags secsel -fill [$canv3 cget -selectbackground]]
7116 proc make_idmark {id} {
7117 global linehtag canv fgcolor
7119 if {![info exists linehtag($id)]} return
7121 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7122 -tags markid -outline $fgcolor]
7126 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7127 global canv ctext commitinfo selectedline
7128 global canvy0 linespc parents children curview
7129 global currentid sha1entry
7130 global commentend idtags linknum
7131 global mergemax numcommits pending_select
7132 global cmitmode showneartags allcommits
7133 global targetrow targetid lastscrollrows
7134 global autoselect autosellen jump_to_here
7137 catch {unset pending_select}
7142 if {$l < 0 || $l >= $numcommits} return
7143 set id [commitonrow $l]
7148 if {$lastscrollrows < $numcommits} {
7152 if {$cmitmode ne "patch" && $switch_to_patch} {
7153 set cmitmode "patch"
7156 set y [expr {$canvy0 + $l * $linespc}]
7157 set ymax [lindex [$canv cget -scrollregion] 3]
7158 set ytop [expr {$y - $linespc - 1}]
7159 set ybot [expr {$y + $linespc + 1}]
7160 set wnow [$canv yview]
7161 set wtop [expr {[lindex $wnow 0] * $ymax}]
7162 set wbot [expr {[lindex $wnow 1] * $ymax}]
7163 set wh [expr {$wbot - $wtop}]
7165 if {$ytop < $wtop} {
7166 if {$ybot < $wtop} {
7167 set newtop [expr {$y - $wh / 2.0}]
7170 if {$newtop > $wtop - $linespc} {
7171 set newtop [expr {$wtop - $linespc}]
7174 } elseif {$ybot > $wbot} {
7175 if {$ytop > $wbot} {
7176 set newtop [expr {$y - $wh / 2.0}]
7178 set newtop [expr {$ybot - $wh}]
7179 if {$newtop < $wtop + $linespc} {
7180 set newtop [expr {$wtop + $linespc}]
7184 if {$newtop != $wtop} {
7188 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7195 addtohistory [list selbyid $id 0] savecmitpos
7198 $sha1entry delete 0 end
7199 $sha1entry insert 0 $id
7201 $sha1entry selection range 0 $autosellen
7205 $ctext conf -state normal
7208 if {![info exists commitinfo($id)]} {
7211 set info $commitinfo($id)
7212 set date [formatdate [lindex $info 2]]
7213 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7214 set date [formatdate [lindex $info 4]]
7215 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7216 if {[info exists idtags($id)]} {
7217 $ctext insert end [mc "Tags:"]
7218 foreach tag $idtags($id) {
7219 $ctext insert end " $tag"
7221 $ctext insert end "\n"
7225 set olds $parents($curview,$id)
7226 if {[llength $olds] > 1} {
7229 if {$np >= $mergemax} {
7234 $ctext insert end "[mc "Parent"]: " $tag
7235 appendwithlinks [commit_descriptor $p] {}
7240 append headers "[mc "Parent"]: [commit_descriptor $p]"
7244 foreach c $children($curview,$id) {
7245 append headers "[mc "Child"]: [commit_descriptor $c]"
7248 # make anything that looks like a SHA1 ID be a clickable link
7249 appendwithlinks $headers {}
7250 if {$showneartags} {
7251 if {![info exists allcommits]} {
7254 $ctext insert end "[mc "Branch"]: "
7255 $ctext mark set branch "end -1c"
7256 $ctext mark gravity branch left
7257 $ctext insert end "\n[mc "Follows"]: "
7258 $ctext mark set follows "end -1c"
7259 $ctext mark gravity follows left
7260 $ctext insert end "\n[mc "Precedes"]: "
7261 $ctext mark set precedes "end -1c"
7262 $ctext mark gravity precedes left
7263 $ctext insert end "\n"
7266 $ctext insert end "\n"
7267 set comment [lindex $info 5]
7268 if {[string first "\r" $comment] >= 0} {
7269 set comment [string map {"\r" "\n "} $comment]
7271 appendwithlinks $comment {comment}
7273 $ctext tag remove found 1.0 end
7274 $ctext conf -state disabled
7275 set commentend [$ctext index "end - 1c"]
7277 set jump_to_here $desired_loc
7278 init_flist [mc "Comments"]
7279 if {$cmitmode eq "tree"} {
7281 } elseif {$vinlinediff($curview) == 1} {
7283 } elseif {[llength $olds] <= 1} {
7290 proc selfirstline {} {
7295 proc sellastline {} {
7298 set l [expr {$numcommits - 1}]
7302 proc selnextline {dir} {
7305 if {$selectedline eq {}} return
7306 set l [expr {$selectedline + $dir}]
7311 proc selnextpage {dir} {
7312 global canv linespc selectedline numcommits
7314 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7318 allcanvs yview scroll [expr {$dir * $lpp}] units
7320 if {$selectedline eq {}} return
7321 set l [expr {$selectedline + $dir * $lpp}]
7324 } elseif {$l >= $numcommits} {
7325 set l [expr $numcommits - 1]
7331 proc unselectline {} {
7332 global selectedline currentid
7335 catch {unset currentid}
7336 allcanvs delete secsel
7340 proc reselectline {} {
7343 if {$selectedline ne {}} {
7344 selectline $selectedline 0
7348 proc addtohistory {cmd {saveproc {}}} {
7349 global history historyindex curview
7353 set elt [list $curview $cmd $saveproc {}]
7354 if {$historyindex > 0
7355 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7359 if {$historyindex < [llength $history]} {
7360 set history [lreplace $history $historyindex end $elt]
7362 lappend history $elt
7365 if {$historyindex > 1} {
7366 .tf.bar.leftbut conf -state normal
7368 .tf.bar.leftbut conf -state disabled
7370 .tf.bar.rightbut conf -state disabled
7373 # save the scrolling position of the diff display pane
7374 proc save_position {} {
7375 global historyindex history
7377 if {$historyindex < 1} return
7378 set hi [expr {$historyindex - 1}]
7379 set fn [lindex $history $hi 2]
7381 lset history $hi 3 [eval $fn]
7385 proc unset_posvars {} {
7388 if {[info exists last_posvars]} {
7389 foreach {var val} $last_posvars {
7398 global curview last_posvars
7400 set view [lindex $elt 0]
7401 set cmd [lindex $elt 1]
7402 set pv [lindex $elt 3]
7403 if {$curview != $view} {
7407 foreach {var val} $pv {
7411 set last_posvars $pv
7416 global history historyindex
7419 if {$historyindex > 1} {
7421 incr historyindex -1
7422 godo [lindex $history [expr {$historyindex - 1}]]
7423 .tf.bar.rightbut conf -state normal
7425 if {$historyindex <= 1} {
7426 .tf.bar.leftbut conf -state disabled
7431 global history historyindex
7434 if {$historyindex < [llength $history]} {
7436 set cmd [lindex $history $historyindex]
7439 .tf.bar.leftbut conf -state normal
7441 if {$historyindex >= [llength $history]} {
7442 .tf.bar.rightbut conf -state disabled
7446 proc go_to_parent {i} {
7447 global parents curview targetid
7448 set ps $parents($curview,$targetid)
7449 if {[llength $ps] >= $i} {
7450 selbyid [lindex $ps [expr $i - 1]]
7455 global treefilelist treeidlist diffids diffmergeid treepending
7456 global nullid nullid2
7459 catch {unset diffmergeid}
7460 if {![info exists treefilelist($id)]} {
7461 if {![info exists treepending]} {
7462 if {$id eq $nullid} {
7463 set cmd [list | git ls-files]
7464 } elseif {$id eq $nullid2} {
7465 set cmd [list | git ls-files --stage -t]
7467 set cmd [list | git ls-tree -r $id]
7469 if {[catch {set gtf [open $cmd r]}]} {
7473 set treefilelist($id) {}
7474 set treeidlist($id) {}
7475 fconfigure $gtf -blocking 0 -encoding binary
7476 filerun $gtf [list gettreeline $gtf $id]
7483 proc gettreeline {gtf id} {
7484 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7487 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7488 if {$diffids eq $nullid} {
7491 set i [string first "\t" $line]
7492 if {$i < 0} continue
7493 set fname [string range $line [expr {$i+1}] end]
7494 set line [string range $line 0 [expr {$i-1}]]
7495 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7496 set sha1 [lindex $line 2]
7497 lappend treeidlist($id) $sha1
7499 if {[string index $fname 0] eq "\""} {
7500 set fname [lindex $fname 0]
7502 set fname [encoding convertfrom $fname]
7503 lappend treefilelist($id) $fname
7506 return [expr {$nl >= 1000? 2: 1}]
7510 if {$cmitmode ne "tree"} {
7511 if {![info exists diffmergeid]} {
7512 gettreediffs $diffids
7514 } elseif {$id ne $diffids} {
7523 global treefilelist treeidlist diffids nullid nullid2
7524 global ctext_file_names ctext_file_lines
7525 global ctext commentend
7527 set i [lsearch -exact $treefilelist($diffids) $f]
7529 puts "oops, $f not in list for id $diffids"
7532 if {$diffids eq $nullid} {
7533 if {[catch {set bf [open $f r]} err]} {
7534 puts "oops, can't read $f: $err"
7538 set blob [lindex $treeidlist($diffids) $i]
7539 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7540 puts "oops, error reading blob $blob: $err"
7544 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7545 filerun $bf [list getblobline $bf $diffids]
7546 $ctext config -state normal
7547 clear_ctext $commentend
7548 lappend ctext_file_names $f
7549 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7550 $ctext insert end "\n"
7551 $ctext insert end "$f\n" filesep
7552 $ctext config -state disabled
7553 $ctext yview $commentend
7557 proc getblobline {bf id} {
7558 global diffids cmitmode ctext
7560 if {$id ne $diffids || $cmitmode ne "tree"} {
7564 $ctext config -state normal
7566 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7567 $ctext insert end "$line\n"
7570 global jump_to_here ctext_file_names commentend
7572 # delete last newline
7573 $ctext delete "end - 2c" "end - 1c"
7575 if {$jump_to_here ne {} &&
7576 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7577 set lnum [expr {[lindex $jump_to_here 1] +
7578 [lindex [split $commentend .] 0]}]
7579 mark_ctext_line $lnum
7581 $ctext config -state disabled
7584 $ctext config -state disabled
7585 return [expr {$nl >= 1000? 2: 1}]
7588 proc mark_ctext_line {lnum} {
7589 global ctext markbgcolor
7591 $ctext tag delete omark
7592 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7593 $ctext tag conf omark -background $markbgcolor
7597 proc mergediff {id} {
7599 global diffids treediffs
7600 global parents curview
7604 set treediffs($id) {}
7605 set np [llength $parents($curview,$id)]
7610 proc startdiff {ids} {
7611 global treediffs diffids treepending diffmergeid nullid nullid2
7615 catch {unset diffmergeid}
7616 if {![info exists treediffs($ids)] ||
7617 [lsearch -exact $ids $nullid] >= 0 ||
7618 [lsearch -exact $ids $nullid2] >= 0} {
7619 if {![info exists treepending]} {
7627 proc showinlinediff {ids} {
7628 global commitinfo commitdata ctext
7631 set info $commitinfo($ids)
7632 set diff [lindex $info 7]
7633 set difflines [split $diff "\n"]
7639 foreach line $difflines {
7640 if {![string compare -length 5 "diff " $line]} {
7642 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7643 # offset also accounts for the b/ prefix
7644 lappend treediff [string range $line 6 end]
7649 set treediffs($ids) $treediff
7652 $ctext conf -state normal
7653 foreach line $difflines {
7654 parseblobdiffline $ids $line
7656 maybe_scroll_ctext 1
7657 $ctext conf -state disabled
7660 # If the filename (name) is under any of the passed filter paths
7661 # then return true to include the file in the listing.
7662 proc path_filter {filter name} {
7663 set worktree [gitworktree]
7665 set fq_p [file normalize $p]
7666 set fq_n [file normalize [file join $worktree $name]]
7667 if {[string match [file normalize $fq_p]* $fq_n]} {
7674 proc addtocflist {ids} {
7677 add_flist $treediffs($ids)
7681 proc diffcmd {ids flags} {
7682 global log_showroot nullid nullid2 git_version
7684 set i [lsearch -exact $ids $nullid]
7685 set j [lsearch -exact $ids $nullid2]
7687 if {[llength $ids] > 1 && $j < 0} {
7688 # comparing working directory with some specific revision
7689 set cmd [concat | git diff-index $flags]
7691 lappend cmd -R [lindex $ids 1]
7693 lappend cmd [lindex $ids 0]
7696 # comparing working directory with index
7697 set cmd [concat | git diff-files $flags]
7702 } elseif {$j >= 0} {
7703 if {[package vcompare $git_version "1.7.2"] >= 0} {
7704 set flags "$flags --ignore-submodules=dirty"
7706 set cmd [concat | git diff-index --cached $flags]
7707 if {[llength $ids] > 1} {
7708 # comparing index with specific revision
7710 lappend cmd -R [lindex $ids 1]
7712 lappend cmd [lindex $ids 0]
7715 # comparing index with HEAD
7719 if {$log_showroot} {
7720 lappend flags --root
7722 set cmd [concat | git diff-tree -r $flags $ids]
7727 proc gettreediffs {ids} {
7728 global treediff treepending limitdiffs vfilelimit curview
7730 set cmd [diffcmd $ids {--no-commit-id}]
7731 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7732 set cmd [concat $cmd -- $vfilelimit($curview)]
7734 if {[catch {set gdtf [open $cmd r]}]} return
7736 set treepending $ids
7738 fconfigure $gdtf -blocking 0 -encoding binary
7739 filerun $gdtf [list gettreediffline $gdtf $ids]
7742 proc gettreediffline {gdtf ids} {
7743 global treediff treediffs treepending diffids diffmergeid
7744 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7749 if {$perfile_attrs} {
7750 # cache_gitattr is slow, and even slower on win32 where we
7751 # have to invoke it for only about 30 paths at a time
7753 if {[tk windowingsystem] == "win32"} {
7757 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7758 set i [string first "\t" $line]
7760 set file [string range $line [expr {$i+1}] end]
7761 if {[string index $file 0] eq "\""} {
7762 set file [lindex $file 0]
7764 set file [encoding convertfrom $file]
7765 if {$file ne [lindex $treediff end]} {
7766 lappend treediff $file
7767 lappend sublist $file
7771 if {$perfile_attrs} {
7772 cache_gitattr encoding $sublist
7775 return [expr {$nr >= $max? 2: 1}]
7778 set treediffs($ids) $treediff
7780 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7782 } elseif {$ids != $diffids} {
7783 if {![info exists diffmergeid]} {
7784 gettreediffs $diffids
7792 # empty string or positive integer
7793 proc diffcontextvalidate {v} {
7794 return [regexp {^(|[1-9][0-9]*)$} $v]
7797 proc diffcontextchange {n1 n2 op} {
7798 global diffcontextstring diffcontext
7800 if {[string is integer -strict $diffcontextstring]} {
7801 if {$diffcontextstring >= 0} {
7802 set diffcontext $diffcontextstring
7808 proc changeignorespace {} {
7812 proc changeworddiff {name ix op} {
7816 proc initblobdiffvars {} {
7817 global diffencoding targetline diffnparents
7818 global diffinhdr currdiffsubmod diffseehere
7822 set diffencoding [get_path_encoding {}]
7823 set currdiffsubmod ""
7827 proc getblobdiffs {ids} {
7828 global blobdifffd diffids env
7833 global limitdiffs vfilelimit curview
7837 if {[package vcompare $git_version "1.6.1"] >= 0} {
7838 set textconv "--textconv"
7841 if {[package vcompare $git_version "1.6.6"] >= 0} {
7842 set submodule "--submodule"
7844 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7848 if {$worddiff ne [mc "Line diff"]} {
7849 append cmd " --word-diff=porcelain"
7851 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7852 set cmd [concat $cmd -- $vfilelimit($curview)]
7854 if {[catch {set bdf [open $cmd r]} err]} {
7855 error_popup [mc "Error getting diffs: %s" $err]
7858 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7859 set blobdifffd($ids) $bdf
7861 filerun $bdf [list getblobdiffline $bdf $diffids]
7864 proc savecmitpos {} {
7865 global ctext cmitmode
7867 if {$cmitmode eq "tree"} {
7870 return [list target_scrollpos [$ctext index @0,0]]
7873 proc savectextpos {} {
7876 return [list target_scrollpos [$ctext index @0,0]]
7879 proc maybe_scroll_ctext {ateof} {
7880 global ctext target_scrollpos
7882 if {![info exists target_scrollpos]} return
7884 set nlines [expr {[winfo height $ctext]
7885 / [font metrics textfont -linespace]}]
7886 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7888 $ctext yview $target_scrollpos
7889 unset target_scrollpos
7892 proc setinlist {var i val} {
7895 while {[llength [set $var]] < $i} {
7898 if {[llength [set $var]] == $i} {
7905 proc makediffhdr {fname ids} {
7906 global ctext curdiffstart treediffs diffencoding
7907 global ctext_file_names jump_to_here targetline diffline
7909 set fname [encoding convertfrom $fname]
7910 set diffencoding [get_path_encoding $fname]
7911 set i [lsearch -exact $treediffs($ids) $fname]
7913 setinlist difffilestart $i $curdiffstart
7915 lset ctext_file_names end $fname
7916 set l [expr {(78 - [string length $fname]) / 2}]
7917 set pad [string range "----------------------------------------" 1 $l]
7918 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7920 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7921 set targetline [lindex $jump_to_here 1]
7926 proc blobdiffmaybeseehere {ateof} {
7928 if {$diffseehere >= 0} {
7929 mark_ctext_line [lindex [split $diffseehere .] 0]
7931 maybe_scroll_ctext $ateof
7934 proc getblobdiffline {bdf ids} {
7935 global diffids blobdifffd
7939 $ctext conf -state normal
7940 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7941 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7945 parseblobdiffline $ids $line
7947 $ctext conf -state disabled
7948 blobdiffmaybeseehere [eof $bdf]
7953 return [expr {$nr >= 1000? 2: 1}]
7956 proc parseblobdiffline {ids line} {
7957 global ctext curdiffstart
7958 global diffnexthead diffnextnote difffilestart
7959 global ctext_file_names ctext_file_lines
7960 global diffinhdr treediffs mergemax diffnparents
7961 global diffencoding jump_to_here targetline diffline currdiffsubmod
7962 global worddiff diffseehere
7964 if {![string compare -length 5 "diff " $line]} {
7965 if {![regexp {^diff (--cc|--git) } $line m type]} {
7966 set line [encoding convertfrom $line]
7967 $ctext insert end "$line\n" hunksep
7970 # start of a new file
7972 $ctext insert end "\n"
7973 set curdiffstart [$ctext index "end - 1c"]
7974 lappend ctext_file_names ""
7975 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7976 $ctext insert end "\n" filesep
7978 if {$type eq "--cc"} {
7979 # start of a new file in a merge diff
7980 set fname [string range $line 10 end]
7981 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7982 lappend treediffs($ids) $fname
7983 add_flist [list $fname]
7987 set line [string range $line 11 end]
7988 # If the name hasn't changed the length will be odd,
7989 # the middle char will be a space, and the two bits either
7990 # side will be a/name and b/name, or "a/name" and "b/name".
7991 # If the name has changed we'll get "rename from" and
7992 # "rename to" or "copy from" and "copy to" lines following
7993 # this, and we'll use them to get the filenames.
7994 # This complexity is necessary because spaces in the
7995 # filename(s) don't get escaped.
7996 set l [string length $line]
7997 set i [expr {$l / 2}]
7998 if {!(($l & 1) && [string index $line $i] eq " " &&
7999 [string range $line 2 [expr {$i - 1}]] eq \
8000 [string range $line [expr {$i + 3}] end])} {
8003 # unescape if quoted and chop off the a/ from the front
8004 if {[string index $line 0] eq "\""} {
8005 set fname [string range [lindex $line 0] 2 end]
8007 set fname [string range $line 2 [expr {$i - 1}]]
8010 makediffhdr $fname $ids
8012 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8013 set fname [encoding convertfrom [string range $line 16 end]]
8014 $ctext insert end "\n"
8015 set curdiffstart [$ctext index "end - 1c"]
8016 lappend ctext_file_names $fname
8017 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8018 $ctext insert end "$line\n" filesep
8019 set i [lsearch -exact $treediffs($ids) $fname]
8021 setinlist difffilestart $i $curdiffstart
8024 } elseif {![string compare -length 2 "@@" $line]} {
8025 regexp {^@@+} $line ats
8026 set line [encoding convertfrom $diffencoding $line]
8027 $ctext insert end "$line\n" hunksep
8028 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8031 set diffnparents [expr {[string length $ats] - 1}]
8034 } elseif {![string compare -length 10 "Submodule " $line]} {
8035 # start of a new submodule
8036 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8037 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8039 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8041 if {$currdiffsubmod != $fname} {
8042 $ctext insert end "\n"; # Add newline after commit message
8044 set curdiffstart [$ctext index "end - 1c"]
8045 lappend ctext_file_names ""
8046 if {$currdiffsubmod != $fname} {
8047 lappend ctext_file_lines $fname
8048 makediffhdr $fname $ids
8049 set currdiffsubmod $fname
8050 $ctext insert end "\n$line\n" filesep
8052 $ctext insert end "$line\n" filesep
8054 } elseif {![string compare -length 3 " >" $line]} {
8055 set $currdiffsubmod ""
8056 set line [encoding convertfrom $diffencoding $line]
8057 $ctext insert end "$line\n" dresult
8058 } elseif {![string compare -length 3 " <" $line]} {
8059 set $currdiffsubmod ""
8060 set line [encoding convertfrom $diffencoding $line]
8061 $ctext insert end "$line\n" d0
8062 } elseif {$diffinhdr} {
8063 if {![string compare -length 12 "rename from " $line]} {
8064 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8065 if {[string index $fname 0] eq "\""} {
8066 set fname [lindex $fname 0]
8068 set fname [encoding convertfrom $fname]
8069 set i [lsearch -exact $treediffs($ids) $fname]
8071 setinlist difffilestart $i $curdiffstart
8073 } elseif {![string compare -length 10 $line "rename to "] ||
8074 ![string compare -length 8 $line "copy to "]} {
8075 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8076 if {[string index $fname 0] eq "\""} {
8077 set fname [lindex $fname 0]
8079 makediffhdr $fname $ids
8080 } elseif {[string compare -length 3 $line "---"] == 0} {
8083 } elseif {[string compare -length 3 $line "+++"] == 0} {
8087 $ctext insert end "$line\n" filesep
8090 set line [string map {\x1A ^Z} \
8091 [encoding convertfrom $diffencoding $line]]
8092 # parse the prefix - one ' ', '-' or '+' for each parent
8093 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8094 set tag [expr {$diffnparents > 1? "m": "d"}]
8095 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8096 set words_pre_markup ""
8097 set words_post_markup ""
8098 if {[string trim $prefix " -+"] eq {}} {
8099 # prefix only has " ", "-" and "+" in it: normal diff line
8100 set num [string first "-" $prefix]
8102 set line [string range $line 1 end]
8105 # removed line, first parent with line is $num
8106 if {$num >= $mergemax} {
8109 if {$dowords && $worddiff eq [mc "Markup words"]} {
8110 $ctext insert end "\[-$line-\]" $tag$num
8112 $ctext insert end "$line" $tag$num
8115 $ctext insert end "\n" $tag$num
8119 if {[string first "+" $prefix] >= 0} {
8121 lappend tags ${tag}result
8122 if {$diffnparents > 1} {
8123 set num [string first " " $prefix]
8125 if {$num >= $mergemax} {
8131 set words_pre_markup "{+"
8132 set words_post_markup "+}"
8134 if {$targetline ne {}} {
8135 if {$diffline == $targetline} {
8136 set diffseehere [$ctext index "end - 1 chars"]
8142 if {$dowords && $worddiff eq [mc "Markup words"]} {
8143 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8145 $ctext insert end "$line" $tags
8148 $ctext insert end "\n" $tags
8151 } elseif {$dowords && $prefix eq "~"} {
8152 $ctext insert end "\n" {}
8154 # "\ No newline at end of file",
8155 # or something else we don't recognize
8156 $ctext insert end "$line\n" hunksep
8161 proc changediffdisp {} {
8162 global ctext diffelide
8164 $ctext tag conf d0 -elide [lindex $diffelide 0]
8165 $ctext tag conf dresult -elide [lindex $diffelide 1]
8168 proc highlightfile {cline} {
8169 global cflist cflist_top
8171 if {![info exists cflist_top]} return
8173 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8174 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8175 $cflist see $cline.0
8176 set cflist_top $cline
8179 proc highlightfile_for_scrollpos {topidx} {
8180 global cmitmode difffilestart
8182 if {$cmitmode eq "tree"} return
8183 if {![info exists difffilestart]} return
8185 set top [lindex [split $topidx .] 0]
8186 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8189 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8194 global difffilestart ctext cmitmode
8196 if {$cmitmode eq "tree"} return
8198 set here [$ctext index @0,0]
8199 foreach loc $difffilestart {
8200 if {[$ctext compare $loc >= $here]} {
8210 global difffilestart ctext cmitmode
8212 if {$cmitmode eq "tree"} return
8213 set here [$ctext index @0,0]
8214 foreach loc $difffilestart {
8215 if {[$ctext compare $loc > $here]} {
8222 proc clear_ctext {{first 1.0}} {
8223 global ctext smarktop smarkbot
8224 global ctext_file_names ctext_file_lines
8227 set l [lindex [split $first .] 0]
8228 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8231 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8234 $ctext delete $first end
8235 if {$first eq "1.0"} {
8236 catch {unset pendinglinks}
8238 set ctext_file_names {}
8239 set ctext_file_lines {}
8242 proc settabs {{firstab {}}} {
8243 global firsttabstop tabstop ctext have_tk85
8245 if {$firstab ne {} && $have_tk85} {
8246 set firsttabstop $firstab
8248 set w [font measure textfont "0"]
8249 if {$firsttabstop != 0} {
8250 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8251 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8252 } elseif {$have_tk85 || $tabstop != 8} {
8253 $ctext conf -tabs [expr {$tabstop * $w}]
8255 $ctext conf -tabs {}
8259 proc incrsearch {name ix op} {
8260 global ctext searchstring searchdirn
8262 if {[catch {$ctext index anchor}]} {
8263 # no anchor set, use start of selection, or of visible area
8264 set sel [$ctext tag ranges sel]
8266 $ctext mark set anchor [lindex $sel 0]
8267 } elseif {$searchdirn eq "-forwards"} {
8268 $ctext mark set anchor @0,0
8270 $ctext mark set anchor @0,[winfo height $ctext]
8273 if {$searchstring ne {}} {
8274 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8277 set mend "$here + $mlen c"
8278 $ctext tag remove sel 1.0 end
8279 $ctext tag add sel $here $mend
8280 suppress_highlighting_file_for_current_scrollpos
8281 highlightfile_for_scrollpos $here
8284 rehighlight_search_results
8288 global sstring ctext searchstring searchdirn
8291 $sstring icursor end
8292 set searchdirn -forwards
8293 if {$searchstring ne {}} {
8294 set sel [$ctext tag ranges sel]
8296 set start "[lindex $sel 0] + 1c"
8297 } elseif {[catch {set start [$ctext index anchor]}]} {
8300 set match [$ctext search -count mlen -- $searchstring $start]
8301 $ctext tag remove sel 1.0 end
8307 suppress_highlighting_file_for_current_scrollpos
8308 highlightfile_for_scrollpos $match
8309 set mend "$match + $mlen c"
8310 $ctext tag add sel $match $mend
8311 $ctext mark unset anchor
8312 rehighlight_search_results
8316 proc dosearchback {} {
8317 global sstring ctext searchstring searchdirn
8320 $sstring icursor end
8321 set searchdirn -backwards
8322 if {$searchstring ne {}} {
8323 set sel [$ctext tag ranges sel]
8325 set start [lindex $sel 0]
8326 } elseif {[catch {set start [$ctext index anchor]}]} {
8327 set start @0,[winfo height $ctext]
8329 set match [$ctext search -backwards -count ml -- $searchstring $start]
8330 $ctext tag remove sel 1.0 end
8336 suppress_highlighting_file_for_current_scrollpos
8337 highlightfile_for_scrollpos $match
8338 set mend "$match + $ml c"
8339 $ctext tag add sel $match $mend
8340 $ctext mark unset anchor
8341 rehighlight_search_results
8345 proc rehighlight_search_results {} {
8346 global ctext searchstring
8348 $ctext tag remove found 1.0 end
8349 $ctext tag remove currentsearchhit 1.0 end
8351 if {$searchstring ne {}} {
8356 proc searchmark {first last} {
8357 global ctext searchstring
8359 set sel [$ctext tag ranges sel]
8363 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8364 if {$match eq {}} break
8365 set mend "$match + $mlen c"
8366 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8367 $ctext tag add currentsearchhit $match $mend
8369 $ctext tag add found $match $mend
8374 proc searchmarkvisible {doall} {
8375 global ctext smarktop smarkbot
8377 set topline [lindex [split [$ctext index @0,0] .] 0]
8378 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8379 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8380 # no overlap with previous
8381 searchmark $topline $botline
8382 set smarktop $topline
8383 set smarkbot $botline
8385 if {$topline < $smarktop} {
8386 searchmark $topline [expr {$smarktop-1}]
8387 set smarktop $topline
8389 if {$botline > $smarkbot} {
8390 searchmark [expr {$smarkbot+1}] $botline
8391 set smarkbot $botline
8396 proc suppress_highlighting_file_for_current_scrollpos {} {
8397 global ctext suppress_highlighting_file_for_this_scrollpos
8399 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8402 proc scrolltext {f0 f1} {
8403 global searchstring cmitmode ctext
8404 global suppress_highlighting_file_for_this_scrollpos
8406 set topidx [$ctext index @0,0]
8407 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8408 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8409 highlightfile_for_scrollpos $topidx
8412 catch {unset suppress_highlighting_file_for_this_scrollpos}
8414 .bleft.bottom.sb set $f0 $f1
8415 if {$searchstring ne {}} {
8421 global linespc charspc canvx0 canvy0
8422 global xspc1 xspc2 lthickness
8424 set linespc [font metrics mainfont -linespace]
8425 set charspc [font measure mainfont "m"]
8426 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8427 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8428 set lthickness [expr {int($linespc / 9) + 1}]
8429 set xspc1(0) $linespc
8437 set ymax [lindex [$canv cget -scrollregion] 3]
8438 if {$ymax eq {} || $ymax == 0} return
8439 set span [$canv yview]
8442 allcanvs yview moveto [lindex $span 0]
8444 if {$selectedline ne {}} {
8445 selectline $selectedline 0
8446 allcanvs yview moveto [lindex $span 0]
8450 proc parsefont {f n} {
8453 set fontattr($f,family) [lindex $n 0]
8455 if {$s eq {} || $s == 0} {
8458 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8460 set fontattr($f,size) $s
8461 set fontattr($f,weight) normal
8462 set fontattr($f,slant) roman
8463 foreach style [lrange $n 2 end] {
8466 "bold" {set fontattr($f,weight) $style}
8468 "italic" {set fontattr($f,slant) $style}
8473 proc fontflags {f {isbold 0}} {
8476 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8477 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8478 -slant $fontattr($f,slant)]
8484 set n [list $fontattr($f,family) $fontattr($f,size)]
8485 if {$fontattr($f,weight) eq "bold"} {
8488 if {$fontattr($f,slant) eq "italic"} {
8494 proc incrfont {inc} {
8495 global mainfont textfont ctext canv cflist showrefstop
8496 global stopped entries fontattr
8499 set s $fontattr(mainfont,size)
8504 set fontattr(mainfont,size) $s
8505 font config mainfont -size $s
8506 font config mainfontbold -size $s
8507 set mainfont [fontname mainfont]
8508 set s $fontattr(textfont,size)
8513 set fontattr(textfont,size) $s
8514 font config textfont -size $s
8515 font config textfontbold -size $s
8516 set textfont [fontname textfont]
8523 global sha1entry sha1string
8524 if {[string length $sha1string] == 40} {
8525 $sha1entry delete 0 end
8529 proc sha1change {n1 n2 op} {
8530 global sha1string currentid sha1but
8531 if {$sha1string == {}
8532 || ([info exists currentid] && $sha1string == $currentid)} {
8537 if {[$sha1but cget -state] == $state} return
8538 if {$state == "normal"} {
8539 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8541 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8545 proc gotocommit {} {
8546 global sha1string tagids headids curview varcid
8548 if {$sha1string == {}
8549 || ([info exists currentid] && $sha1string == $currentid)} return
8550 if {[info exists tagids($sha1string)]} {
8551 set id $tagids($sha1string)
8552 } elseif {[info exists headids($sha1string)]} {
8553 set id $headids($sha1string)
8555 set id [string tolower $sha1string]
8556 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8557 set matches [longid $id]
8558 if {$matches ne {}} {
8559 if {[llength $matches] > 1} {
8560 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8563 set id [lindex $matches 0]
8566 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8567 error_popup [mc "Revision %s is not known" $sha1string]
8572 if {[commitinview $id $curview]} {
8573 selectline [rowofcommit $id] 1
8576 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8577 set msg [mc "SHA1 id %s is not known" $sha1string]
8579 set msg [mc "Revision %s is not in the current view" $sha1string]
8584 proc lineenter {x y id} {
8585 global hoverx hovery hoverid hovertimer
8586 global commitinfo canv
8588 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8592 if {[info exists hovertimer]} {
8593 after cancel $hovertimer
8595 set hovertimer [after 500 linehover]
8599 proc linemotion {x y id} {
8600 global hoverx hovery hoverid hovertimer
8602 if {[info exists hoverid] && $id == $hoverid} {
8605 if {[info exists hovertimer]} {
8606 after cancel $hovertimer
8608 set hovertimer [after 500 linehover]
8612 proc lineleave {id} {
8613 global hoverid hovertimer canv
8615 if {[info exists hoverid] && $id == $hoverid} {
8617 if {[info exists hovertimer]} {
8618 after cancel $hovertimer
8626 global hoverx hovery hoverid hovertimer
8627 global canv linespc lthickness
8628 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8632 set text [lindex $commitinfo($hoverid) 0]
8633 set ymax [lindex [$canv cget -scrollregion] 3]
8634 if {$ymax == {}} return
8635 set yfrac [lindex [$canv yview] 0]
8636 set x [expr {$hoverx + 2 * $linespc}]
8637 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8638 set x0 [expr {$x - 2 * $lthickness}]
8639 set y0 [expr {$y - 2 * $lthickness}]
8640 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8641 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8642 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8643 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8644 -width 1 -tags hover]
8646 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8647 -font mainfont -fill $linehoverfgcolor]
8651 proc clickisonarrow {id y} {
8654 set ranges [rowranges $id]
8655 set thresh [expr {2 * $lthickness + 6}]
8656 set n [expr {[llength $ranges] - 1}]
8657 for {set i 1} {$i < $n} {incr i} {
8658 set row [lindex $ranges $i]
8659 if {abs([yc $row] - $y) < $thresh} {
8666 proc arrowjump {id n y} {
8669 # 1 <-> 2, 3 <-> 4, etc...
8670 set n [expr {(($n - 1) ^ 1) + 1}]
8671 set row [lindex [rowranges $id] $n]
8673 set ymax [lindex [$canv cget -scrollregion] 3]
8674 if {$ymax eq {} || $ymax <= 0} return
8675 set view [$canv yview]
8676 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8677 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8681 allcanvs yview moveto $yfrac
8684 proc lineclick {x y id isnew} {
8685 global ctext commitinfo children canv thickerline curview
8687 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8692 # draw this line thicker than normal
8696 set ymax [lindex [$canv cget -scrollregion] 3]
8697 if {$ymax eq {}} return
8698 set yfrac [lindex [$canv yview] 0]
8699 set y [expr {$y + $yfrac * $ymax}]
8701 set dirn [clickisonarrow $id $y]
8703 arrowjump $id $dirn $y
8708 addtohistory [list lineclick $x $y $id 0] savectextpos
8710 # fill the details pane with info about this line
8711 $ctext conf -state normal
8714 $ctext insert end "[mc "Parent"]:\t"
8715 $ctext insert end $id link0
8717 set info $commitinfo($id)
8718 $ctext insert end "\n\t[lindex $info 0]\n"
8719 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8720 set date [formatdate [lindex $info 2]]
8721 $ctext insert end "\t[mc "Date"]:\t$date\n"
8722 set kids $children($curview,$id)
8724 $ctext insert end "\n[mc "Children"]:"
8726 foreach child $kids {
8728 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8729 set info $commitinfo($child)
8730 $ctext insert end "\n\t"
8731 $ctext insert end $child link$i
8732 setlink $child link$i
8733 $ctext insert end "\n\t[lindex $info 0]"
8734 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8735 set date [formatdate [lindex $info 2]]
8736 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8739 maybe_scroll_ctext 1
8740 $ctext conf -state disabled
8744 proc normalline {} {
8746 if {[info exists thickerline]} {
8753 proc selbyid {id {isnew 1}} {
8755 if {[commitinview $id $curview]} {
8756 selectline [rowofcommit $id] $isnew
8762 if {![info exists startmstime]} {
8763 set startmstime [clock clicks -milliseconds]
8765 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8768 proc rowmenu {x y id} {
8769 global rowctxmenu selectedline rowmenuid curview
8770 global nullid nullid2 fakerowmenu mainhead markedid
8774 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8779 if {[info exists markedid] && $markedid ne $id} {
8784 if {$id ne $nullid && $id ne $nullid2} {
8785 set menu $rowctxmenu
8786 if {$mainhead ne {}} {
8787 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8789 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8791 $menu entryconfigure 9 -state $mstate
8792 $menu entryconfigure 10 -state $mstate
8793 $menu entryconfigure 11 -state $mstate
8795 set menu $fakerowmenu
8797 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8798 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8799 $menu entryconfigure [mca "Make patch"] -state $state
8800 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8801 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8802 tk_popup $menu $x $y
8806 global rowmenuid markedid canv
8808 set markedid $rowmenuid
8809 make_idmark $markedid
8815 if {[info exists markedid]} {
8820 proc replace_by_kids {l r} {
8821 global curview children
8823 set id [commitonrow $r]
8824 set l [lreplace $l 0 0]
8825 foreach kid $children($curview,$id) {
8826 lappend l [rowofcommit $kid]
8828 return [lsort -integer -decreasing -unique $l]
8831 proc find_common_desc {} {
8832 global markedid rowmenuid curview children
8834 if {![info exists markedid]} return
8835 if {![commitinview $markedid $curview] ||
8836 ![commitinview $rowmenuid $curview]} return
8837 #set t1 [clock clicks -milliseconds]
8838 set l1 [list [rowofcommit $markedid]]
8839 set l2 [list [rowofcommit $rowmenuid]]
8841 set r1 [lindex $l1 0]
8842 set r2 [lindex $l2 0]
8843 if {$r1 eq {} || $r2 eq {}} break
8849 set l1 [replace_by_kids $l1 $r1]
8851 set l2 [replace_by_kids $l2 $r2]
8854 #set t2 [clock clicks -milliseconds]
8855 #puts "took [expr {$t2-$t1}]ms"
8858 proc compare_commits {} {
8859 global markedid rowmenuid curview children
8861 if {![info exists markedid]} return
8862 if {![commitinview $markedid $curview]} return
8863 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8864 do_cmp_commits $markedid $rowmenuid
8867 proc getpatchid {id} {
8870 if {![info exists patchids($id)]} {
8871 set cmd [diffcmd [list $id] {-p --root}]
8872 # trim off the initial "|"
8873 set cmd [lrange $cmd 1 end]
8875 set x [eval exec $cmd | git patch-id]
8876 set patchids($id) [lindex $x 0]
8878 set patchids($id) "error"
8881 return $patchids($id)
8884 proc do_cmp_commits {a b} {
8885 global ctext curview parents children patchids commitinfo
8887 $ctext conf -state normal
8890 for {set i 0} {$i < 100} {incr i} {
8893 if {[llength $parents($curview,$a)] > 1} {
8894 appendshortlink $a [mc "Skipping merge commit "] "\n"
8897 set patcha [getpatchid $a]
8899 if {[llength $parents($curview,$b)] > 1} {
8900 appendshortlink $b [mc "Skipping merge commit "] "\n"
8903 set patchb [getpatchid $b]
8905 if {!$skipa && !$skipb} {
8906 set heada [lindex $commitinfo($a) 0]
8907 set headb [lindex $commitinfo($b) 0]
8908 if {$patcha eq "error"} {
8909 appendshortlink $a [mc "Error getting patch ID for "] \
8910 [mc " - stopping\n"]
8913 if {$patchb eq "error"} {
8914 appendshortlink $b [mc "Error getting patch ID for "] \
8915 [mc " - stopping\n"]
8918 if {$patcha eq $patchb} {
8919 if {$heada eq $headb} {
8920 appendshortlink $a [mc "Commit "]
8921 appendshortlink $b " == " " $heada\n"
8923 appendshortlink $a [mc "Commit "] " $heada\n"
8924 appendshortlink $b [mc " is the same patch as\n "] \
8930 $ctext insert end "\n"
8931 appendshortlink $a [mc "Commit "] " $heada\n"
8932 appendshortlink $b [mc " differs from\n "] \
8934 $ctext insert end [mc "Diff of commits:\n\n"]
8935 $ctext conf -state disabled
8942 set kids [real_children $curview,$a]
8943 if {[llength $kids] != 1} {
8944 $ctext insert end "\n"
8945 appendshortlink $a [mc "Commit "] \
8946 [mc " has %s children - stopping\n" [llength $kids]]
8949 set a [lindex $kids 0]
8952 set kids [real_children $curview,$b]
8953 if {[llength $kids] != 1} {
8954 appendshortlink $b [mc "Commit "] \
8955 [mc " has %s children - stopping\n" [llength $kids]]
8958 set b [lindex $kids 0]
8961 $ctext conf -state disabled
8964 proc diffcommits {a b} {
8965 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8967 set tmpdir [gitknewtmpdir]
8968 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8969 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8971 exec git diff-tree -p --pretty $a >$fna
8972 exec git diff-tree -p --pretty $b >$fnb
8974 error_popup [mc "Error writing commit to file: %s" $err]
8978 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8980 error_popup [mc "Error diffing commits: %s" $err]
8983 set diffids [list commits $a $b]
8984 set blobdifffd($diffids) $fd
8986 set currdiffsubmod ""
8987 filerun $fd [list getblobdiffline $fd $diffids]
8990 proc diffvssel {dirn} {
8991 global rowmenuid selectedline
8993 if {$selectedline eq {}} return
8995 set oldid [commitonrow $selectedline]
8996 set newid $rowmenuid
8998 set oldid $rowmenuid
8999 set newid [commitonrow $selectedline]
9001 addtohistory [list doseldiff $oldid $newid] savectextpos
9002 doseldiff $oldid $newid
9005 proc diffvsmark {dirn} {
9006 global rowmenuid markedid
9008 if {![info exists markedid]} return
9011 set newid $rowmenuid
9013 set oldid $rowmenuid
9016 addtohistory [list doseldiff $oldid $newid] savectextpos
9017 doseldiff $oldid $newid
9020 proc doseldiff {oldid newid} {
9024 $ctext conf -state normal
9026 init_flist [mc "Top"]
9027 $ctext insert end "[mc "From"] "
9028 $ctext insert end $oldid link0
9029 setlink $oldid link0
9030 $ctext insert end "\n "
9031 $ctext insert end [lindex $commitinfo($oldid) 0]
9032 $ctext insert end "\n\n[mc "To"] "
9033 $ctext insert end $newid link1
9034 setlink $newid link1
9035 $ctext insert end "\n "
9036 $ctext insert end [lindex $commitinfo($newid) 0]
9037 $ctext insert end "\n"
9038 $ctext conf -state disabled
9039 $ctext tag remove found 1.0 end
9040 startdiff [list $oldid $newid]
9044 global rowmenuid currentid commitinfo patchtop patchnum NS
9046 if {![info exists currentid]} return
9047 set oldid $currentid
9048 set oldhead [lindex $commitinfo($oldid) 0]
9049 set newid $rowmenuid
9050 set newhead [lindex $commitinfo($newid) 0]
9053 catch {destroy $top}
9055 make_transient $top .
9056 ${NS}::label $top.title -text [mc "Generate patch"]
9057 grid $top.title - -pady 10
9058 ${NS}::label $top.from -text [mc "From:"]
9059 ${NS}::entry $top.fromsha1 -width 40
9060 $top.fromsha1 insert 0 $oldid
9061 $top.fromsha1 conf -state readonly
9062 grid $top.from $top.fromsha1 -sticky w
9063 ${NS}::entry $top.fromhead -width 60
9064 $top.fromhead insert 0 $oldhead
9065 $top.fromhead conf -state readonly
9066 grid x $top.fromhead -sticky w
9067 ${NS}::label $top.to -text [mc "To:"]
9068 ${NS}::entry $top.tosha1 -width 40
9069 $top.tosha1 insert 0 $newid
9070 $top.tosha1 conf -state readonly
9071 grid $top.to $top.tosha1 -sticky w
9072 ${NS}::entry $top.tohead -width 60
9073 $top.tohead insert 0 $newhead
9074 $top.tohead conf -state readonly
9075 grid x $top.tohead -sticky w
9076 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9077 grid $top.rev x -pady 10 -padx 5
9078 ${NS}::label $top.flab -text [mc "Output file:"]
9079 ${NS}::entry $top.fname -width 60
9080 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9082 grid $top.flab $top.fname -sticky w
9083 ${NS}::frame $top.buts
9084 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9085 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9086 bind $top <Key-Return> mkpatchgo
9087 bind $top <Key-Escape> mkpatchcan
9088 grid $top.buts.gen $top.buts.can
9089 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9090 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9091 grid $top.buts - -pady 10 -sticky ew
9095 proc mkpatchrev {} {
9098 set oldid [$patchtop.fromsha1 get]
9099 set oldhead [$patchtop.fromhead get]
9100 set newid [$patchtop.tosha1 get]
9101 set newhead [$patchtop.tohead get]
9102 foreach e [list fromsha1 fromhead tosha1 tohead] \
9103 v [list $newid $newhead $oldid $oldhead] {
9104 $patchtop.$e conf -state normal
9105 $patchtop.$e delete 0 end
9106 $patchtop.$e insert 0 $v
9107 $patchtop.$e conf -state readonly
9112 global patchtop nullid nullid2
9114 set oldid [$patchtop.fromsha1 get]
9115 set newid [$patchtop.tosha1 get]
9116 set fname [$patchtop.fname get]
9117 set cmd [diffcmd [list $oldid $newid] -p]
9118 # trim off the initial "|"
9119 set cmd [lrange $cmd 1 end]
9120 lappend cmd >$fname &
9121 if {[catch {eval exec $cmd} err]} {
9122 error_popup "[mc "Error creating patch:"] $err" $patchtop
9124 catch {destroy $patchtop}
9128 proc mkpatchcan {} {
9131 catch {destroy $patchtop}
9136 global rowmenuid mktagtop commitinfo NS
9140 catch {destroy $top}
9142 make_transient $top .
9143 ${NS}::label $top.title -text [mc "Create tag"]
9144 grid $top.title - -pady 10
9145 ${NS}::label $top.id -text [mc "ID:"]
9146 ${NS}::entry $top.sha1 -width 40
9147 $top.sha1 insert 0 $rowmenuid
9148 $top.sha1 conf -state readonly
9149 grid $top.id $top.sha1 -sticky w
9150 ${NS}::entry $top.head -width 60
9151 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9152 $top.head conf -state readonly
9153 grid x $top.head -sticky w
9154 ${NS}::label $top.tlab -text [mc "Tag name:"]
9155 ${NS}::entry $top.tag -width 60
9156 grid $top.tlab $top.tag -sticky w
9157 ${NS}::label $top.op -text [mc "Tag message is optional"]
9158 grid $top.op -columnspan 2 -sticky we
9159 ${NS}::label $top.mlab -text [mc "Tag message:"]
9160 ${NS}::entry $top.msg -width 60
9161 grid $top.mlab $top.msg -sticky w
9162 ${NS}::frame $top.buts
9163 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9164 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9165 bind $top <Key-Return> mktaggo
9166 bind $top <Key-Escape> mktagcan
9167 grid $top.buts.gen $top.buts.can
9168 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9169 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9170 grid $top.buts - -pady 10 -sticky ew
9175 global mktagtop env tagids idtags
9177 set id [$mktagtop.sha1 get]
9178 set tag [$mktagtop.tag get]
9179 set msg [$mktagtop.msg get]
9181 error_popup [mc "No tag name specified"] $mktagtop
9184 if {[info exists tagids($tag)]} {
9185 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9190 exec git tag -a -m $msg $tag $id
9192 exec git tag $tag $id
9195 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9199 set tagids($tag) $id
9200 lappend idtags($id) $tag
9208 proc redrawtags {id} {
9209 global canv linehtag idpos currentid curview cmitlisted markedid
9210 global canvxmax iddrawn circleitem mainheadid circlecolors
9211 global mainheadcirclecolor
9213 if {![commitinview $id $curview]} return
9214 if {![info exists iddrawn($id)]} return
9215 set row [rowofcommit $id]
9216 if {$id eq $mainheadid} {
9217 set ofill $mainheadcirclecolor
9219 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9221 $canv itemconf $circleitem($row) -fill $ofill
9222 $canv delete tag.$id
9223 set xt [eval drawtags $id $idpos($id)]
9224 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9225 set text [$canv itemcget $linehtag($id) -text]
9226 set font [$canv itemcget $linehtag($id) -font]
9227 set xr [expr {$xt + [font measure $font $text]}]
9228 if {$xr > $canvxmax} {
9232 if {[info exists currentid] && $currentid == $id} {
9235 if {[info exists markedid] && $markedid eq $id} {
9243 catch {destroy $mktagtop}
9248 if {![domktag]} return
9252 proc writecommit {} {
9253 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9255 set top .writecommit
9257 catch {destroy $top}
9259 make_transient $top .
9260 ${NS}::label $top.title -text [mc "Write commit to file"]
9261 grid $top.title - -pady 10
9262 ${NS}::label $top.id -text [mc "ID:"]
9263 ${NS}::entry $top.sha1 -width 40
9264 $top.sha1 insert 0 $rowmenuid
9265 $top.sha1 conf -state readonly
9266 grid $top.id $top.sha1 -sticky w
9267 ${NS}::entry $top.head -width 60
9268 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9269 $top.head conf -state readonly
9270 grid x $top.head -sticky w
9271 ${NS}::label $top.clab -text [mc "Command:"]
9272 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9273 grid $top.clab $top.cmd -sticky w -pady 10
9274 ${NS}::label $top.flab -text [mc "Output file:"]
9275 ${NS}::entry $top.fname -width 60
9276 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9277 grid $top.flab $top.fname -sticky w
9278 ${NS}::frame $top.buts
9279 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9280 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9281 bind $top <Key-Return> wrcomgo
9282 bind $top <Key-Escape> wrcomcan
9283 grid $top.buts.gen $top.buts.can
9284 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9285 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9286 grid $top.buts - -pady 10 -sticky ew
9293 set id [$wrcomtop.sha1 get]
9294 set cmd "echo $id | [$wrcomtop.cmd get]"
9295 set fname [$wrcomtop.fname get]
9296 if {[catch {exec sh -c $cmd >$fname &} err]} {
9297 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9299 catch {destroy $wrcomtop}
9306 catch {destroy $wrcomtop}
9311 global rowmenuid mkbrtop NS
9314 catch {destroy $top}
9316 make_transient $top .
9317 ${NS}::label $top.title -text [mc "Create new branch"]
9318 grid $top.title - -pady 10
9319 ${NS}::label $top.id -text [mc "ID:"]
9320 ${NS}::entry $top.sha1 -width 40
9321 $top.sha1 insert 0 $rowmenuid
9322 $top.sha1 conf -state readonly
9323 grid $top.id $top.sha1 -sticky w
9324 ${NS}::label $top.nlab -text [mc "Name:"]
9325 ${NS}::entry $top.name -width 40
9326 grid $top.nlab $top.name -sticky w
9327 ${NS}::frame $top.buts
9328 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9329 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9330 bind $top <Key-Return> [list mkbrgo $top]
9331 bind $top <Key-Escape> "catch {destroy $top}"
9332 grid $top.buts.go $top.buts.can
9333 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9334 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9335 grid $top.buts - -pady 10 -sticky ew
9340 global headids idheads
9342 set name [$top.name get]
9343 set id [$top.sha1 get]
9347 error_popup [mc "Please specify a name for the new branch"] $top
9350 if {[info exists headids($name)]} {
9351 if {![confirm_popup [mc \
9352 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9355 set old_id $headids($name)
9358 catch {destroy $top}
9359 lappend cmdargs $name $id
9363 eval exec git branch $cmdargs
9369 if {$old_id ne {}} {
9375 set headids($name) $id
9376 lappend idheads($id) $name
9385 proc exec_citool {tool_args {baseid {}}} {
9386 global commitinfo env
9388 set save_env [array get env GIT_AUTHOR_*]
9390 if {$baseid ne {}} {
9391 if {![info exists commitinfo($baseid)]} {
9394 set author [lindex $commitinfo($baseid) 1]
9395 set date [lindex $commitinfo($baseid) 2]
9396 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9397 $author author name email]
9399 set env(GIT_AUTHOR_NAME) $name
9400 set env(GIT_AUTHOR_EMAIL) $email
9401 set env(GIT_AUTHOR_DATE) $date
9405 eval exec git citool $tool_args &
9407 array unset env GIT_AUTHOR_*
9408 array set env $save_env
9411 proc cherrypick {} {
9412 global rowmenuid curview
9413 global mainhead mainheadid
9416 set oldhead [exec git rev-parse HEAD]
9417 set dheads [descheads $rowmenuid]
9418 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9419 set ok [confirm_popup [mc "Commit %s is already\
9420 included in branch %s -- really re-apply it?" \
9421 [string range $rowmenuid 0 7] $mainhead]]
9424 nowbusy cherrypick [mc "Cherry-picking"]
9426 # Unfortunately git-cherry-pick writes stuff to stderr even when
9427 # no error occurs, and exec takes that as an indication of error...
9428 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9431 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9433 error_popup [mc "Cherry-pick failed because of local changes\
9434 to file '%s'.\nPlease commit, reset or stash\
9435 your changes and try again." $fname]
9436 } elseif {[regexp -line \
9437 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9439 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9440 conflict.\nDo you wish to run git citool to\
9442 # Force citool to read MERGE_MSG
9443 file delete [file join $gitdir "GITGUI_MSG"]
9444 exec_citool {} $rowmenuid
9452 set newhead [exec git rev-parse HEAD]
9453 if {$newhead eq $oldhead} {
9455 error_popup [mc "No changes committed"]
9458 addnewchild $newhead $oldhead
9459 if {[commitinview $oldhead $curview]} {
9460 # XXX this isn't right if we have a path limit...
9461 insertrow $newhead $oldhead $curview
9462 if {$mainhead ne {}} {
9463 movehead $newhead $mainhead
9464 movedhead $newhead $mainhead
9466 set mainheadid $newhead
9475 global rowmenuid curview
9476 global mainhead mainheadid
9479 set oldhead [exec git rev-parse HEAD]
9480 set dheads [descheads $rowmenuid]
9481 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9482 set ok [confirm_popup [mc "Commit %s is not\
9483 included in branch %s -- really revert it?" \
9484 [string range $rowmenuid 0 7] $mainhead]]
9487 nowbusy revert [mc "Reverting"]
9490 if [catch {exec git revert --no-edit $rowmenuid} err] {
9492 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9494 regsub {\n( |\t)+} $files "\n" files
9495 error_popup [mc "Revert failed because of local changes to\
9496 the following files:%s Please commit, reset or stash \
9497 your changes and try again." $files]
9498 } elseif [regexp {error: could not revert} $err] {
9499 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9500 Do you wish to run git citool to resolve it?"]] {
9501 # Force citool to read MERGE_MSG
9502 file delete [file join $gitdir "GITGUI_MSG"]
9503 exec_citool {} $rowmenuid
9505 } else { error_popup $err }
9510 set newhead [exec git rev-parse HEAD]
9511 if { $newhead eq $oldhead } {
9513 error_popup [mc "No changes committed"]
9517 addnewchild $newhead $oldhead
9519 if [commitinview $oldhead $curview] {
9520 # XXX this isn't right if we have a path limit...
9521 insertrow $newhead $oldhead $curview
9522 if {$mainhead ne {}} {
9523 movehead $newhead $mainhead
9524 movedhead $newhead $mainhead
9526 set mainheadid $newhead
9536 global mainhead rowmenuid confirm_ok resettype NS
9539 set w ".confirmreset"
9542 wm title $w [mc "Confirm reset"]
9543 ${NS}::label $w.m -text \
9544 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9545 pack $w.m -side top -fill x -padx 20 -pady 20
9546 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9548 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9549 -text [mc "Soft: Leave working tree and index untouched"]
9550 grid $w.f.soft -sticky w
9551 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9552 -text [mc "Mixed: Leave working tree untouched, reset index"]
9553 grid $w.f.mixed -sticky w
9554 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9555 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9556 grid $w.f.hard -sticky w
9557 pack $w.f -side top -fill x -padx 4
9558 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9559 pack $w.ok -side left -fill x -padx 20 -pady 20
9560 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9561 bind $w <Key-Escape> [list destroy $w]
9562 pack $w.cancel -side right -fill x -padx 20 -pady 20
9563 bind $w <Visibility> "grab $w; focus $w"
9565 if {!$confirm_ok} return
9566 if {[catch {set fd [open \
9567 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9571 filerun $fd [list readresetstat $fd]
9572 nowbusy reset [mc "Resetting"]
9577 proc readresetstat {fd} {
9578 global mainhead mainheadid showlocalchanges rprogcoord
9580 if {[gets $fd line] >= 0} {
9581 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9582 set rprogcoord [expr {1.0 * $m / $n}]
9590 if {[catch {close $fd} err]} {
9593 set oldhead $mainheadid
9594 set newhead [exec git rev-parse HEAD]
9595 if {$newhead ne $oldhead} {
9596 movehead $newhead $mainhead
9597 movedhead $newhead $mainhead
9598 set mainheadid $newhead
9602 if {$showlocalchanges} {
9608 # context menu for a head
9609 proc headmenu {x y id head} {
9610 global headmenuid headmenuhead headctxmenu mainhead
9614 set headmenuhead $head
9616 if {[string match "remotes/*" $head]} {
9619 if {$head eq $mainhead} {
9622 $headctxmenu entryconfigure 0 -state $state
9623 $headctxmenu entryconfigure 1 -state $state
9624 tk_popup $headctxmenu $x $y
9628 global headmenuid headmenuhead headids
9629 global showlocalchanges
9631 # check the tree is clean first??
9632 nowbusy checkout [mc "Checking out"]
9636 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9640 if {$showlocalchanges} {
9644 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9648 proc readcheckoutstat {fd newhead newheadid} {
9649 global mainhead mainheadid headids showlocalchanges progresscoords
9650 global viewmainheadid curview
9652 if {[gets $fd line] >= 0} {
9653 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9654 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9659 set progresscoords {0 0}
9662 if {[catch {close $fd} err]} {
9665 set oldmainid $mainheadid
9666 set mainhead $newhead
9667 set mainheadid $newheadid
9668 set viewmainheadid($curview) $newheadid
9669 redrawtags $oldmainid
9670 redrawtags $newheadid
9672 if {$showlocalchanges} {
9678 global headmenuid headmenuhead mainhead
9681 set head $headmenuhead
9683 # this check shouldn't be needed any more...
9684 if {$head eq $mainhead} {
9685 error_popup [mc "Cannot delete the currently checked-out branch"]
9688 set dheads [descheads $id]
9689 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9690 # the stuff on this branch isn't on any other branch
9691 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9692 branch.\nReally delete branch %s?" $head $head]]} return
9696 if {[catch {exec git branch -D $head} err]} {
9701 removehead $id $head
9702 removedhead $id $head
9709 # Display a list of tags and heads
9711 global showrefstop bgcolor fgcolor selectbgcolor NS
9712 global bglist fglist reflistfilter reflist maincursor
9715 set showrefstop $top
9716 if {[winfo exists $top]} {
9722 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9723 make_transient $top .
9724 text $top.list -background $bgcolor -foreground $fgcolor \
9725 -selectbackground $selectbgcolor -font mainfont \
9726 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9727 -width 30 -height 20 -cursor $maincursor \
9728 -spacing1 1 -spacing3 1 -state disabled
9729 $top.list tag configure highlight -background $selectbgcolor
9730 lappend bglist $top.list
9731 lappend fglist $top.list
9732 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9733 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9734 grid $top.list $top.ysb -sticky nsew
9735 grid $top.xsb x -sticky ew
9737 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9738 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9739 set reflistfilter "*"
9740 trace add variable reflistfilter write reflistfilter_change
9741 pack $top.f.e -side right -fill x -expand 1
9742 pack $top.f.l -side left
9743 grid $top.f - -sticky ew -pady 2
9744 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9745 bind $top <Key-Escape> [list destroy $top]
9747 grid columnconfigure $top 0 -weight 1
9748 grid rowconfigure $top 0 -weight 1
9749 bind $top.list <1> {break}
9750 bind $top.list <B1-Motion> {break}
9751 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9756 proc sel_reflist {w x y} {
9757 global showrefstop reflist headids tagids otherrefids
9759 if {![winfo exists $showrefstop]} return
9760 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9761 set ref [lindex $reflist [expr {$l-1}]]
9762 set n [lindex $ref 0]
9763 switch -- [lindex $ref 1] {
9764 "H" {selbyid $headids($n)}
9765 "T" {selbyid $tagids($n)}
9766 "o" {selbyid $otherrefids($n)}
9768 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9771 proc unsel_reflist {} {
9774 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9775 $showrefstop.list tag remove highlight 0.0 end
9778 proc reflistfilter_change {n1 n2 op} {
9779 global reflistfilter
9781 after cancel refill_reflist
9782 after 200 refill_reflist
9785 proc refill_reflist {} {
9786 global reflist reflistfilter showrefstop headids tagids otherrefids
9789 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9791 foreach n [array names headids] {
9792 if {[string match $reflistfilter $n]} {
9793 if {[commitinview $headids($n) $curview]} {
9794 lappend refs [list $n H]
9796 interestedin $headids($n) {run refill_reflist}
9800 foreach n [array names tagids] {
9801 if {[string match $reflistfilter $n]} {
9802 if {[commitinview $tagids($n) $curview]} {
9803 lappend refs [list $n T]
9805 interestedin $tagids($n) {run refill_reflist}
9809 foreach n [array names otherrefids] {
9810 if {[string match $reflistfilter $n]} {
9811 if {[commitinview $otherrefids($n) $curview]} {
9812 lappend refs [list $n o]
9814 interestedin $otherrefids($n) {run refill_reflist}
9818 set refs [lsort -index 0 $refs]
9819 if {$refs eq $reflist} return
9821 # Update the contents of $showrefstop.list according to the
9822 # differences between $reflist (old) and $refs (new)
9823 $showrefstop.list conf -state normal
9824 $showrefstop.list insert end "\n"
9827 while {$i < [llength $reflist] || $j < [llength $refs]} {
9828 if {$i < [llength $reflist]} {
9829 if {$j < [llength $refs]} {
9830 set cmp [string compare [lindex $reflist $i 0] \
9831 [lindex $refs $j 0]]
9833 set cmp [string compare [lindex $reflist $i 1] \
9834 [lindex $refs $j 1]]
9844 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9852 set l [expr {$j + 1}]
9853 $showrefstop.list image create $l.0 -align baseline \
9854 -image reficon-[lindex $refs $j 1] -padx 2
9855 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9861 # delete last newline
9862 $showrefstop.list delete end-2c end-1c
9863 $showrefstop.list conf -state disabled
9866 # Stuff for finding nearby tags
9867 proc getallcommits {} {
9868 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9869 global idheads idtags idotherrefs allparents tagobjid
9872 if {![info exists allcommits]} {
9878 set allccache [file join $gitdir "gitk.cache"]
9880 set f [open $allccache r]
9889 set cmd [list | git rev-list --parents]
9890 set allcupdate [expr {$seeds ne {}}]
9894 set refs [concat [array names idheads] [array names idtags] \
9895 [array names idotherrefs]]
9898 foreach name [array names tagobjid] {
9899 lappend tagobjs $tagobjid($name)
9901 foreach id [lsort -unique $refs] {
9902 if {![info exists allparents($id)] &&
9903 [lsearch -exact $tagobjs $id] < 0} {
9914 set fd [open [concat $cmd $ids] r]
9915 fconfigure $fd -blocking 0
9918 filerun $fd [list getallclines $fd]
9924 # Since most commits have 1 parent and 1 child, we group strings of
9925 # such commits into "arcs" joining branch/merge points (BMPs), which
9926 # are commits that either don't have 1 parent or don't have 1 child.
9928 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9929 # arcout(id) - outgoing arcs for BMP
9930 # arcids(a) - list of IDs on arc including end but not start
9931 # arcstart(a) - BMP ID at start of arc
9932 # arcend(a) - BMP ID at end of arc
9933 # growing(a) - arc a is still growing
9934 # arctags(a) - IDs out of arcids (excluding end) that have tags
9935 # archeads(a) - IDs out of arcids (excluding end) that have heads
9936 # The start of an arc is at the descendent end, so "incoming" means
9937 # coming from descendents, and "outgoing" means going towards ancestors.
9939 proc getallclines {fd} {
9940 global allparents allchildren idtags idheads nextarc
9941 global arcnos arcids arctags arcout arcend arcstart archeads growing
9942 global seeds allcommits cachedarcs allcupdate
9945 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9946 set id [lindex $line 0]
9947 if {[info exists allparents($id)]} {
9952 set olds [lrange $line 1 end]
9953 set allparents($id) $olds
9954 if {![info exists allchildren($id)]} {
9955 set allchildren($id) {}
9960 if {[llength $olds] == 1 && [llength $a] == 1} {
9961 lappend arcids($a) $id
9962 if {[info exists idtags($id)]} {
9963 lappend arctags($a) $id
9965 if {[info exists idheads($id)]} {
9966 lappend archeads($a) $id
9968 if {[info exists allparents($olds)]} {
9969 # seen parent already
9970 if {![info exists arcout($olds)]} {
9973 lappend arcids($a) $olds
9974 set arcend($a) $olds
9977 lappend allchildren($olds) $id
9978 lappend arcnos($olds) $a
9982 foreach a $arcnos($id) {
9983 lappend arcids($a) $id
9990 lappend allchildren($p) $id
9991 set a [incr nextarc]
9992 set arcstart($a) $id
9999 if {[info exists allparents($p)]} {
10000 # seen it already, may need to make a new branch
10001 if {![info exists arcout($p)]} {
10004 lappend arcids($a) $p
10008 lappend arcnos($p) $a
10010 set arcout($id) $ao
10013 global cached_dheads cached_dtags cached_atags
10014 catch {unset cached_dheads}
10015 catch {unset cached_dtags}
10016 catch {unset cached_atags}
10019 return [expr {$nid >= 1000? 2: 1}]
10023 fconfigure $fd -blocking 1
10026 # got an error reading the list of commits
10027 # if we were updating, try rereading the whole thing again
10033 error_popup "[mc "Error reading commit topology information;\
10034 branch and preceding/following tag information\
10035 will be incomplete."]\n($err)"
10038 if {[incr allcommits -1] == 0} {
10048 proc recalcarc {a} {
10049 global arctags archeads arcids idtags idheads
10053 foreach id [lrange $arcids($a) 0 end-1] {
10054 if {[info exists idtags($id)]} {
10057 if {[info exists idheads($id)]} {
10061 set arctags($a) $at
10062 set archeads($a) $ah
10065 proc splitarc {p} {
10066 global arcnos arcids nextarc arctags archeads idtags idheads
10067 global arcstart arcend arcout allparents growing
10070 if {[llength $a] != 1} {
10071 puts "oops splitarc called but [llength $a] arcs already"
10074 set a [lindex $a 0]
10075 set i [lsearch -exact $arcids($a) $p]
10077 puts "oops splitarc $p not in arc $a"
10080 set na [incr nextarc]
10081 if {[info exists arcend($a)]} {
10082 set arcend($na) $arcend($a)
10084 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10085 set j [lsearch -exact $arcnos($l) $a]
10086 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10088 set tail [lrange $arcids($a) [expr {$i+1}] end]
10089 set arcids($a) [lrange $arcids($a) 0 $i]
10091 set arcstart($na) $p
10093 set arcids($na) $tail
10094 if {[info exists growing($a)]} {
10100 if {[llength $arcnos($id)] == 1} {
10101 set arcnos($id) $na
10103 set j [lsearch -exact $arcnos($id) $a]
10104 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10108 # reconstruct tags and heads lists
10109 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10113 set arctags($na) {}
10114 set archeads($na) {}
10118 # Update things for a new commit added that is a child of one
10119 # existing commit. Used when cherry-picking.
10120 proc addnewchild {id p} {
10121 global allparents allchildren idtags nextarc
10122 global arcnos arcids arctags arcout arcend arcstart archeads growing
10123 global seeds allcommits
10125 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10126 set allparents($id) [list $p]
10127 set allchildren($id) {}
10130 lappend allchildren($p) $id
10131 set a [incr nextarc]
10132 set arcstart($a) $id
10133 set archeads($a) {}
10135 set arcids($a) [list $p]
10137 if {![info exists arcout($p)]} {
10140 lappend arcnos($p) $a
10141 set arcout($id) [list $a]
10144 # This implements a cache for the topology information.
10145 # The cache saves, for each arc, the start and end of the arc,
10146 # the ids on the arc, and the outgoing arcs from the end.
10147 proc readcache {f} {
10148 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10149 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10153 set lim $cachedarcs
10154 if {$lim - $a > 500} {
10155 set lim [expr {$a + 500}]
10159 # finish reading the cache and setting up arctags, etc.
10161 if {$line ne "1"} {error "bad final version"}
10163 foreach id [array names idtags] {
10164 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10165 [llength $allparents($id)] == 1} {
10166 set a [lindex $arcnos($id) 0]
10167 if {$arctags($a) eq {}} {
10172 foreach id [array names idheads] {
10173 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10174 [llength $allparents($id)] == 1} {
10175 set a [lindex $arcnos($id) 0]
10176 if {$archeads($a) eq {}} {
10181 foreach id [lsort -unique $possible_seeds] {
10182 if {$arcnos($id) eq {}} {
10188 while {[incr a] <= $lim} {
10190 if {[llength $line] != 3} {error "bad line"}
10191 set s [lindex $line 0]
10192 set arcstart($a) $s
10193 lappend arcout($s) $a
10194 if {![info exists arcnos($s)]} {
10195 lappend possible_seeds $s
10198 set e [lindex $line 1]
10203 if {![info exists arcout($e)]} {
10207 set arcids($a) [lindex $line 2]
10208 foreach id $arcids($a) {
10209 lappend allparents($s) $id
10211 lappend arcnos($id) $a
10213 if {![info exists allparents($s)]} {
10214 set allparents($s) {}
10217 set archeads($a) {}
10219 set nextarc [expr {$a - 1}]
10231 proc getcache {f} {
10232 global nextarc cachedarcs possible_seeds
10236 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10237 # make sure it's an integer
10238 set cachedarcs [expr {int([lindex $line 1])}]
10239 if {$cachedarcs < 0} {error "bad number of arcs"}
10241 set possible_seeds {}
10249 proc dropcache {err} {
10250 global allcwait nextarc cachedarcs seeds
10252 #puts "dropping cache ($err)"
10253 foreach v {arcnos arcout arcids arcstart arcend growing \
10254 arctags archeads allparents allchildren} {
10265 proc writecache {f} {
10266 global cachearc cachedarcs allccache
10267 global arcstart arcend arcnos arcids arcout
10270 set lim $cachedarcs
10271 if {$lim - $a > 1000} {
10272 set lim [expr {$a + 1000}]
10275 while {[incr a] <= $lim} {
10276 if {[info exists arcend($a)]} {
10277 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10279 puts $f [list $arcstart($a) {} $arcids($a)]
10284 catch {file delete $allccache}
10285 #puts "writing cache failed ($err)"
10288 set cachearc [expr {$a - 1}]
10289 if {$a > $cachedarcs} {
10297 proc savecache {} {
10298 global nextarc cachedarcs cachearc allccache
10300 if {$nextarc == $cachedarcs} return
10302 set cachedarcs $nextarc
10304 set f [open $allccache w]
10305 puts $f [list 1 $cachedarcs]
10310 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10311 # or 0 if neither is true.
10312 proc anc_or_desc {a b} {
10313 global arcout arcstart arcend arcnos cached_isanc
10315 if {$arcnos($a) eq $arcnos($b)} {
10316 # Both are on the same arc(s); either both are the same BMP,
10317 # or if one is not a BMP, the other is also not a BMP or is
10318 # the BMP at end of the arc (and it only has 1 incoming arc).
10319 # Or both can be BMPs with no incoming arcs.
10320 if {$a eq $b || $arcnos($a) eq {}} {
10323 # assert {[llength $arcnos($a)] == 1}
10324 set arc [lindex $arcnos($a) 0]
10325 set i [lsearch -exact $arcids($arc) $a]
10326 set j [lsearch -exact $arcids($arc) $b]
10327 if {$i < 0 || $i > $j} {
10334 if {![info exists arcout($a)]} {
10335 set arc [lindex $arcnos($a) 0]
10336 if {[info exists arcend($arc)]} {
10337 set aend $arcend($arc)
10341 set a $arcstart($arc)
10345 if {![info exists arcout($b)]} {
10346 set arc [lindex $arcnos($b) 0]
10347 if {[info exists arcend($arc)]} {
10348 set bend $arcend($arc)
10352 set b $arcstart($arc)
10362 if {[info exists cached_isanc($a,$bend)]} {
10363 if {$cached_isanc($a,$bend)} {
10367 if {[info exists cached_isanc($b,$aend)]} {
10368 if {$cached_isanc($b,$aend)} {
10371 if {[info exists cached_isanc($a,$bend)]} {
10376 set todo [list $a $b]
10379 for {set i 0} {$i < [llength $todo]} {incr i} {
10380 set x [lindex $todo $i]
10381 if {$anc($x) eq {}} {
10384 foreach arc $arcnos($x) {
10385 set xd $arcstart($arc)
10386 if {$xd eq $bend} {
10387 set cached_isanc($a,$bend) 1
10388 set cached_isanc($b,$aend) 0
10390 } elseif {$xd eq $aend} {
10391 set cached_isanc($b,$aend) 1
10392 set cached_isanc($a,$bend) 0
10395 if {![info exists anc($xd)]} {
10396 set anc($xd) $anc($x)
10398 } elseif {$anc($xd) ne $anc($x)} {
10403 set cached_isanc($a,$bend) 0
10404 set cached_isanc($b,$aend) 0
10408 # This identifies whether $desc has an ancestor that is
10409 # a growing tip of the graph and which is not an ancestor of $anc
10410 # and returns 0 if so and 1 if not.
10411 # If we subsequently discover a tag on such a growing tip, and that
10412 # turns out to be a descendent of $anc (which it could, since we
10413 # don't necessarily see children before parents), then $desc
10414 # isn't a good choice to display as a descendent tag of
10415 # $anc (since it is the descendent of another tag which is
10416 # a descendent of $anc). Similarly, $anc isn't a good choice to
10417 # display as a ancestor tag of $desc.
10419 proc is_certain {desc anc} {
10420 global arcnos arcout arcstart arcend growing problems
10423 if {[llength $arcnos($anc)] == 1} {
10424 # tags on the same arc are certain
10425 if {$arcnos($desc) eq $arcnos($anc)} {
10428 if {![info exists arcout($anc)]} {
10429 # if $anc is partway along an arc, use the start of the arc instead
10430 set a [lindex $arcnos($anc) 0]
10431 set anc $arcstart($a)
10434 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10437 set a [lindex $arcnos($desc) 0]
10443 set anclist [list $x]
10447 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10448 set x [lindex $anclist $i]
10453 foreach a $arcout($x) {
10454 if {[info exists growing($a)]} {
10455 if {![info exists growanc($x)] && $dl($x)} {
10461 if {[info exists dl($y)]} {
10465 if {![info exists done($y)]} {
10468 if {[info exists growanc($x)]} {
10472 for {set k 0} {$k < [llength $xl]} {incr k} {
10473 set z [lindex $xl $k]
10474 foreach c $arcout($z) {
10475 if {[info exists arcend($c)]} {
10477 if {[info exists dl($v)] && $dl($v)} {
10479 if {![info exists done($v)]} {
10482 if {[info exists growanc($v)]} {
10492 } elseif {$y eq $anc || !$dl($x)} {
10503 foreach x [array names growanc] {
10512 proc validate_arctags {a} {
10513 global arctags idtags
10516 set na $arctags($a)
10517 foreach id $arctags($a) {
10519 if {![info exists idtags($id)]} {
10520 set na [lreplace $na $i $i]
10524 set arctags($a) $na
10527 proc validate_archeads {a} {
10528 global archeads idheads
10531 set na $archeads($a)
10532 foreach id $archeads($a) {
10534 if {![info exists idheads($id)]} {
10535 set na [lreplace $na $i $i]
10539 set archeads($a) $na
10542 # Return the list of IDs that have tags that are descendents of id,
10543 # ignoring IDs that are descendents of IDs already reported.
10544 proc desctags {id} {
10545 global arcnos arcstart arcids arctags idtags allparents
10546 global growing cached_dtags
10548 if {![info exists allparents($id)]} {
10551 set t1 [clock clicks -milliseconds]
10553 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10554 # part-way along an arc; check that arc first
10555 set a [lindex $arcnos($id) 0]
10556 if {$arctags($a) ne {}} {
10557 validate_arctags $a
10558 set i [lsearch -exact $arcids($a) $id]
10560 foreach t $arctags($a) {
10561 set j [lsearch -exact $arcids($a) $t]
10562 if {$j >= $i} break
10569 set id $arcstart($a)
10570 if {[info exists idtags($id)]} {
10574 if {[info exists cached_dtags($id)]} {
10575 return $cached_dtags($id)
10579 set todo [list $id]
10582 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10583 set id [lindex $todo $i]
10585 set ta [info exists hastaggedancestor($id)]
10589 # ignore tags on starting node
10590 if {!$ta && $i > 0} {
10591 if {[info exists idtags($id)]} {
10592 set tagloc($id) $id
10594 } elseif {[info exists cached_dtags($id)]} {
10595 set tagloc($id) $cached_dtags($id)
10599 foreach a $arcnos($id) {
10600 set d $arcstart($a)
10601 if {!$ta && $arctags($a) ne {}} {
10602 validate_arctags $a
10603 if {$arctags($a) ne {}} {
10604 lappend tagloc($id) [lindex $arctags($a) end]
10607 if {$ta || $arctags($a) ne {}} {
10608 set tomark [list $d]
10609 for {set j 0} {$j < [llength $tomark]} {incr j} {
10610 set dd [lindex $tomark $j]
10611 if {![info exists hastaggedancestor($dd)]} {
10612 if {[info exists done($dd)]} {
10613 foreach b $arcnos($dd) {
10614 lappend tomark $arcstart($b)
10616 if {[info exists tagloc($dd)]} {
10619 } elseif {[info exists queued($dd)]} {
10622 set hastaggedancestor($dd) 1
10626 if {![info exists queued($d)]} {
10629 if {![info exists hastaggedancestor($d)]} {
10636 foreach id [array names tagloc] {
10637 if {![info exists hastaggedancestor($id)]} {
10638 foreach t $tagloc($id) {
10639 if {[lsearch -exact $tags $t] < 0} {
10645 set t2 [clock clicks -milliseconds]
10648 # remove tags that are descendents of other tags
10649 for {set i 0} {$i < [llength $tags]} {incr i} {
10650 set a [lindex $tags $i]
10651 for {set j 0} {$j < $i} {incr j} {
10652 set b [lindex $tags $j]
10653 set r [anc_or_desc $a $b]
10655 set tags [lreplace $tags $j $j]
10658 } elseif {$r == -1} {
10659 set tags [lreplace $tags $i $i]
10666 if {[array names growing] ne {}} {
10667 # graph isn't finished, need to check if any tag could get
10668 # eclipsed by another tag coming later. Simply ignore any
10669 # tags that could later get eclipsed.
10672 if {[is_certain $t $origid]} {
10676 if {$tags eq $ctags} {
10677 set cached_dtags($origid) $tags
10682 set cached_dtags($origid) $tags
10684 set t3 [clock clicks -milliseconds]
10685 if {0 && $t3 - $t1 >= 100} {
10686 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10687 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10692 proc anctags {id} {
10693 global arcnos arcids arcout arcend arctags idtags allparents
10694 global growing cached_atags
10696 if {![info exists allparents($id)]} {
10699 set t1 [clock clicks -milliseconds]
10701 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10702 # part-way along an arc; check that arc first
10703 set a [lindex $arcnos($id) 0]
10704 if {$arctags($a) ne {}} {
10705 validate_arctags $a
10706 set i [lsearch -exact $arcids($a) $id]
10707 foreach t $arctags($a) {
10708 set j [lsearch -exact $arcids($a) $t]
10714 if {![info exists arcend($a)]} {
10718 if {[info exists idtags($id)]} {
10722 if {[info exists cached_atags($id)]} {
10723 return $cached_atags($id)
10727 set todo [list $id]
10731 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10732 set id [lindex $todo $i]
10734 set td [info exists hastaggeddescendent($id)]
10738 # ignore tags on starting node
10739 if {!$td && $i > 0} {
10740 if {[info exists idtags($id)]} {
10741 set tagloc($id) $id
10743 } elseif {[info exists cached_atags($id)]} {
10744 set tagloc($id) $cached_atags($id)
10748 foreach a $arcout($id) {
10749 if {!$td && $arctags($a) ne {}} {
10750 validate_arctags $a
10751 if {$arctags($a) ne {}} {
10752 lappend tagloc($id) [lindex $arctags($a) 0]
10755 if {![info exists arcend($a)]} continue
10757 if {$td || $arctags($a) ne {}} {
10758 set tomark [list $d]
10759 for {set j 0} {$j < [llength $tomark]} {incr j} {
10760 set dd [lindex $tomark $j]
10761 if {![info exists hastaggeddescendent($dd)]} {
10762 if {[info exists done($dd)]} {
10763 foreach b $arcout($dd) {
10764 if {[info exists arcend($b)]} {
10765 lappend tomark $arcend($b)
10768 if {[info exists tagloc($dd)]} {
10771 } elseif {[info exists queued($dd)]} {
10774 set hastaggeddescendent($dd) 1
10778 if {![info exists queued($d)]} {
10781 if {![info exists hastaggeddescendent($d)]} {
10787 set t2 [clock clicks -milliseconds]
10790 foreach id [array names tagloc] {
10791 if {![info exists hastaggeddescendent($id)]} {
10792 foreach t $tagloc($id) {
10793 if {[lsearch -exact $tags $t] < 0} {
10800 # remove tags that are ancestors of other tags
10801 for {set i 0} {$i < [llength $tags]} {incr i} {
10802 set a [lindex $tags $i]
10803 for {set j 0} {$j < $i} {incr j} {
10804 set b [lindex $tags $j]
10805 set r [anc_or_desc $a $b]
10807 set tags [lreplace $tags $j $j]
10810 } elseif {$r == 1} {
10811 set tags [lreplace $tags $i $i]
10818 if {[array names growing] ne {}} {
10819 # graph isn't finished, need to check if any tag could get
10820 # eclipsed by another tag coming later. Simply ignore any
10821 # tags that could later get eclipsed.
10824 if {[is_certain $origid $t]} {
10828 if {$tags eq $ctags} {
10829 set cached_atags($origid) $tags
10834 set cached_atags($origid) $tags
10836 set t3 [clock clicks -milliseconds]
10837 if {0 && $t3 - $t1 >= 100} {
10838 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10839 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10844 # Return the list of IDs that have heads that are descendents of id,
10845 # including id itself if it has a head.
10846 proc descheads {id} {
10847 global arcnos arcstart arcids archeads idheads cached_dheads
10848 global allparents arcout
10850 if {![info exists allparents($id)]} {
10854 if {![info exists arcout($id)]} {
10855 # part-way along an arc; check it first
10856 set a [lindex $arcnos($id) 0]
10857 if {$archeads($a) ne {}} {
10858 validate_archeads $a
10859 set i [lsearch -exact $arcids($a) $id]
10860 foreach t $archeads($a) {
10861 set j [lsearch -exact $arcids($a) $t]
10866 set id $arcstart($a)
10869 set todo [list $id]
10872 for {set i 0} {$i < [llength $todo]} {incr i} {
10873 set id [lindex $todo $i]
10874 if {[info exists cached_dheads($id)]} {
10875 set ret [concat $ret $cached_dheads($id)]
10877 if {[info exists idheads($id)]} {
10880 foreach a $arcnos($id) {
10881 if {$archeads($a) ne {}} {
10882 validate_archeads $a
10883 if {$archeads($a) ne {}} {
10884 set ret [concat $ret $archeads($a)]
10887 set d $arcstart($a)
10888 if {![info exists seen($d)]} {
10895 set ret [lsort -unique $ret]
10896 set cached_dheads($origid) $ret
10897 return [concat $ret $aret]
10900 proc addedtag {id} {
10901 global arcnos arcout cached_dtags cached_atags
10903 if {![info exists arcnos($id)]} return
10904 if {![info exists arcout($id)]} {
10905 recalcarc [lindex $arcnos($id) 0]
10907 catch {unset cached_dtags}
10908 catch {unset cached_atags}
10911 proc addedhead {hid head} {
10912 global arcnos arcout cached_dheads
10914 if {![info exists arcnos($hid)]} return
10915 if {![info exists arcout($hid)]} {
10916 recalcarc [lindex $arcnos($hid) 0]
10918 catch {unset cached_dheads}
10921 proc removedhead {hid head} {
10922 global cached_dheads
10924 catch {unset cached_dheads}
10927 proc movedhead {hid head} {
10928 global arcnos arcout cached_dheads
10930 if {![info exists arcnos($hid)]} return
10931 if {![info exists arcout($hid)]} {
10932 recalcarc [lindex $arcnos($hid) 0]
10934 catch {unset cached_dheads}
10937 proc changedrefs {} {
10938 global cached_dheads cached_dtags cached_atags cached_tagcontent
10939 global arctags archeads arcnos arcout idheads idtags
10941 foreach id [concat [array names idheads] [array names idtags]] {
10942 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10943 set a [lindex $arcnos($id) 0]
10944 if {![info exists donearc($a)]} {
10950 catch {unset cached_tagcontent}
10951 catch {unset cached_dtags}
10952 catch {unset cached_atags}
10953 catch {unset cached_dheads}
10956 proc rereadrefs {} {
10957 global idtags idheads idotherrefs mainheadid
10959 set refids [concat [array names idtags] \
10960 [array names idheads] [array names idotherrefs]]
10961 foreach id $refids {
10962 if {![info exists ref($id)]} {
10963 set ref($id) [listrefs $id]
10966 set oldmainhead $mainheadid
10969 set refids [lsort -unique [concat $refids [array names idtags] \
10970 [array names idheads] [array names idotherrefs]]]
10971 foreach id $refids {
10972 set v [listrefs $id]
10973 if {![info exists ref($id)] || $ref($id) != $v} {
10977 if {$oldmainhead ne $mainheadid} {
10978 redrawtags $oldmainhead
10979 redrawtags $mainheadid
10984 proc listrefs {id} {
10985 global idtags idheads idotherrefs
10988 if {[info exists idtags($id)]} {
10992 if {[info exists idheads($id)]} {
10993 set y $idheads($id)
10996 if {[info exists idotherrefs($id)]} {
10997 set z $idotherrefs($id)
10999 return [list $x $y $z]
11002 proc add_tag_ctext {tag} {
11003 global ctext cached_tagcontent tagids
11005 if {![info exists cached_tagcontent($tag)]} {
11007 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11010 $ctext insert end "[mc "Tag"]: $tag\n" bold
11011 if {[info exists cached_tagcontent($tag)]} {
11012 set text $cached_tagcontent($tag)
11014 set text "[mc "Id"]: $tagids($tag)"
11016 appendwithlinks $text {}
11019 proc showtag {tag isnew} {
11020 global ctext cached_tagcontent tagids linknum tagobjid
11023 addtohistory [list showtag $tag 0] savectextpos
11025 $ctext conf -state normal
11030 maybe_scroll_ctext 1
11031 $ctext conf -state disabled
11035 proc showtags {id isnew} {
11036 global idtags ctext linknum
11039 addtohistory [list showtags $id 0] savectextpos
11041 $ctext conf -state normal
11046 foreach tag $idtags($id) {
11047 $ctext insert end $sep
11051 maybe_scroll_ctext 1
11052 $ctext conf -state disabled
11064 if {[info exists gitktmpdir]} {
11065 catch {file delete -force $gitktmpdir}
11069 proc mkfontdisp {font top which} {
11070 global fontattr fontpref $font NS use_ttk
11072 set fontpref($font) [set $font]
11073 ${NS}::button $top.${font}but -text $which \
11074 -command [list choosefont $font $which]
11075 ${NS}::label $top.$font -relief flat -font $font \
11076 -text $fontattr($font,family) -justify left
11077 grid x $top.${font}but $top.$font -sticky w
11080 proc choosefont {font which} {
11081 global fontparam fontlist fonttop fontattr
11084 set fontparam(which) $which
11085 set fontparam(font) $font
11086 set fontparam(family) [font actual $font -family]
11087 set fontparam(size) $fontattr($font,size)
11088 set fontparam(weight) $fontattr($font,weight)
11089 set fontparam(slant) $fontattr($font,slant)
11092 if {![winfo exists $top]} {
11094 eval font config sample [font actual $font]
11096 make_transient $top $prefstop
11097 wm title $top [mc "Gitk font chooser"]
11098 ${NS}::label $top.l -textvariable fontparam(which)
11099 pack $top.l -side top
11100 set fontlist [lsort [font families]]
11101 ${NS}::frame $top.f
11102 listbox $top.f.fam -listvariable fontlist \
11103 -yscrollcommand [list $top.f.sb set]
11104 bind $top.f.fam <<ListboxSelect>> selfontfam
11105 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11106 pack $top.f.sb -side right -fill y
11107 pack $top.f.fam -side left -fill both -expand 1
11108 pack $top.f -side top -fill both -expand 1
11109 ${NS}::frame $top.g
11110 spinbox $top.g.size -from 4 -to 40 -width 4 \
11111 -textvariable fontparam(size) \
11112 -validatecommand {string is integer -strict %s}
11113 checkbutton $top.g.bold -padx 5 \
11114 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11115 -variable fontparam(weight) -onvalue bold -offvalue normal
11116 checkbutton $top.g.ital -padx 5 \
11117 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11118 -variable fontparam(slant) -onvalue italic -offvalue roman
11119 pack $top.g.size $top.g.bold $top.g.ital -side left
11120 pack $top.g -side top
11121 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11123 $top.c create text 100 25 -anchor center -text $which -font sample \
11124 -fill black -tags text
11125 bind $top.c <Configure> [list centertext $top.c]
11126 pack $top.c -side top -fill x
11127 ${NS}::frame $top.buts
11128 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11129 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11130 bind $top <Key-Return> fontok
11131 bind $top <Key-Escape> fontcan
11132 grid $top.buts.ok $top.buts.can
11133 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11134 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11135 pack $top.buts -side bottom -fill x
11136 trace add variable fontparam write chg_fontparam
11139 $top.c itemconf text -text $which
11141 set i [lsearch -exact $fontlist $fontparam(family)]
11143 $top.f.fam selection set $i
11148 proc centertext {w} {
11149 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11153 global fontparam fontpref prefstop
11155 set f $fontparam(font)
11156 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11157 if {$fontparam(weight) eq "bold"} {
11158 lappend fontpref($f) "bold"
11160 if {$fontparam(slant) eq "italic"} {
11161 lappend fontpref($f) "italic"
11163 set w $prefstop.notebook.fonts.$f
11164 $w conf -text $fontparam(family) -font $fontpref($f)
11170 global fonttop fontparam
11172 if {[info exists fonttop]} {
11173 catch {destroy $fonttop}
11174 catch {font delete sample}
11180 if {[package vsatisfies [package provide Tk] 8.6]} {
11181 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11182 # function to make use of it.
11183 proc choosefont {font which} {
11184 tk fontchooser configure -title $which -font $font \
11185 -command [list on_choosefont $font $which]
11186 tk fontchooser show
11188 proc on_choosefont {font which newfont} {
11190 puts stderr "$font $newfont"
11191 array set f [font actual $newfont]
11192 set fontparam(which) $which
11193 set fontparam(font) $font
11194 set fontparam(family) $f(-family)
11195 set fontparam(size) $f(-size)
11196 set fontparam(weight) $f(-weight)
11197 set fontparam(slant) $f(-slant)
11202 proc selfontfam {} {
11203 global fonttop fontparam
11205 set i [$fonttop.f.fam curselection]
11207 set fontparam(family) [$fonttop.f.fam get $i]
11211 proc chg_fontparam {v sub op} {
11214 font config sample -$sub $fontparam($sub)
11217 # Create a property sheet tab page
11218 proc create_prefs_page {w} {
11220 set parent [join [lrange [split $w .] 0 end-1] .]
11221 if {[winfo class $parent] eq "TNotebook"} {
11224 ${NS}::labelframe $w
11228 proc prefspage_general {notebook} {
11229 global NS maxwidth maxgraphpct showneartags showlocalchanges
11230 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11231 global hideremotes want_ttk have_ttk maxrefs
11233 set page [create_prefs_page $notebook.general]
11235 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11236 grid $page.ldisp - -sticky w -pady 10
11237 ${NS}::label $page.spacer -text " "
11238 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11239 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11240 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11241 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11242 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11243 grid x $page.maxpctl $page.maxpct -sticky w
11244 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11245 -variable showlocalchanges
11246 grid x $page.showlocal -sticky w
11247 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11248 -variable autoselect
11249 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11250 grid x $page.autoselect $page.autosellen -sticky w
11251 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11252 -variable hideremotes
11253 grid x $page.hideremotes -sticky w
11255 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11256 grid $page.ddisp - -sticky w -pady 10
11257 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11258 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11259 grid x $page.tabstopl $page.tabstop -sticky w
11260 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11261 -variable showneartags
11262 grid x $page.ntag -sticky w
11263 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11264 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11265 grid x $page.maxrefsl $page.maxrefs -sticky w
11266 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11267 -variable limitdiffs
11268 grid x $page.ldiff -sticky w
11269 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11270 -variable perfile_attrs
11271 grid x $page.lattr -sticky w
11273 ${NS}::entry $page.extdifft -textvariable extdifftool
11274 ${NS}::frame $page.extdifff
11275 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11276 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11277 pack $page.extdifff.l $page.extdifff.b -side left
11278 pack configure $page.extdifff.l -padx 10
11279 grid x $page.extdifff $page.extdifft -sticky ew
11281 ${NS}::label $page.lgen -text [mc "General options"]
11282 grid $page.lgen - -sticky w -pady 10
11283 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11284 -text [mc "Use themed widgets"]
11286 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11288 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11290 grid x $page.want_ttk $page.ttk_note -sticky w
11294 proc prefspage_colors {notebook} {
11295 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11297 set page [create_prefs_page $notebook.colors]
11299 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11300 grid $page.cdisp - -sticky w -pady 10
11301 label $page.ui -padx 40 -relief sunk -background $uicolor
11302 ${NS}::button $page.uibut -text [mc "Interface"] \
11303 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11304 grid x $page.uibut $page.ui -sticky w
11305 label $page.bg -padx 40 -relief sunk -background $bgcolor
11306 ${NS}::button $page.bgbut -text [mc "Background"] \
11307 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11308 grid x $page.bgbut $page.bg -sticky w
11309 label $page.fg -padx 40 -relief sunk -background $fgcolor
11310 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11311 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11312 grid x $page.fgbut $page.fg -sticky w
11313 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11314 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11315 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11316 [list $ctext tag conf d0 -foreground]]
11317 grid x $page.diffoldbut $page.diffold -sticky w
11318 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11319 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11320 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11321 [list $ctext tag conf dresult -foreground]]
11322 grid x $page.diffnewbut $page.diffnew -sticky w
11323 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11324 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11325 -command [list choosecolor diffcolors 2 $page.hunksep \
11326 [mc "diff hunk header"] \
11327 [list $ctext tag conf hunksep -foreground]]
11328 grid x $page.hunksepbut $page.hunksep -sticky w
11329 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11330 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11331 -command [list choosecolor markbgcolor {} $page.markbgsep \
11332 [mc "marked line background"] \
11333 [list $ctext tag conf omark -background]]
11334 grid x $page.markbgbut $page.markbgsep -sticky w
11335 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11336 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11337 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11338 grid x $page.selbgbut $page.selbgsep -sticky w
11342 proc prefspage_fonts {notebook} {
11344 set page [create_prefs_page $notebook.fonts]
11345 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11346 grid $page.cfont - -sticky w -pady 10
11347 mkfontdisp mainfont $page [mc "Main font"]
11348 mkfontdisp textfont $page [mc "Diff display font"]
11349 mkfontdisp uifont $page [mc "User interface font"]
11354 global maxwidth maxgraphpct use_ttk NS
11355 global oldprefs prefstop showneartags showlocalchanges
11356 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11357 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11358 global hideremotes want_ttk have_ttk
11362 if {[winfo exists $top]} {
11366 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11367 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11368 set oldprefs($v) [set $v]
11371 wm title $top [mc "Gitk preferences"]
11372 make_transient $top .
11374 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11375 set notebook [ttk::notebook $top.notebook]
11377 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11380 lappend pages [prefspage_general $notebook] [mc "General"]
11381 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11382 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11384 foreach {page title} $pages {
11385 if {$use_notebook} {
11386 $notebook add $page -text $title
11388 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11389 -text $title -command [list raise $page]]
11390 $page configure -text $title
11391 grid $btn -row 0 -column [incr col] -sticky w
11392 grid $page -row 1 -column 0 -sticky news -columnspan 100
11396 if {!$use_notebook} {
11397 grid columnconfigure $notebook 0 -weight 1
11398 grid rowconfigure $notebook 1 -weight 1
11399 raise [lindex $pages 0]
11402 grid $notebook -sticky news -padx 2 -pady 2
11403 grid rowconfigure $top 0 -weight 1
11404 grid columnconfigure $top 0 -weight 1
11406 ${NS}::frame $top.buts
11407 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11408 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11409 bind $top <Key-Return> prefsok
11410 bind $top <Key-Escape> prefscan
11411 grid $top.buts.ok $top.buts.can
11412 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11413 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11414 grid $top.buts - - -pady 10 -sticky ew
11415 grid columnconfigure $top 2 -weight 1
11416 bind $top <Visibility> [list focus $top.buts.ok]
11419 proc choose_extdiff {} {
11422 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11424 set extdifftool $prog
11428 proc choosecolor {v vi w x cmd} {
11431 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11432 -title [mc "Gitk: choose color for %s" $x]]
11433 if {$c eq {}} return
11434 $w conf -background $c
11439 proc setselbg {c} {
11440 global bglist cflist
11441 foreach w $bglist {
11442 $w configure -selectbackground $c
11444 $cflist tag configure highlight \
11445 -background [$cflist cget -selectbackground]
11446 allcanvs itemconf secsel -fill $c
11449 # This sets the background color and the color scheme for the whole UI.
11450 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11451 # if we don't specify one ourselves, which makes the checkbuttons and
11452 # radiobuttons look bad. This chooses white for selectColor if the
11453 # background color is light, or black if it is dark.
11455 if {[tk windowingsystem] eq "win32"} { return }
11456 set bg [winfo rgb . $c]
11458 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11461 tk_setPalette background $c selectColor $selc
11467 foreach w $bglist {
11468 $w conf -background $c
11475 foreach w $fglist {
11476 $w conf -foreground $c
11478 allcanvs itemconf text -fill $c
11479 $canv itemconf circle -outline $c
11480 $canv itemconf markid -outline $c
11484 global oldprefs prefstop
11486 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11487 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11489 set $v $oldprefs($v)
11491 catch {destroy $prefstop}
11497 global maxwidth maxgraphpct
11498 global oldprefs prefstop showneartags showlocalchanges
11499 global fontpref mainfont textfont uifont
11500 global limitdiffs treediffs perfile_attrs
11503 catch {destroy $prefstop}
11507 if {$mainfont ne $fontpref(mainfont)} {
11508 set mainfont $fontpref(mainfont)
11509 parsefont mainfont $mainfont
11510 eval font configure mainfont [fontflags mainfont]
11511 eval font configure mainfontbold [fontflags mainfont 1]
11515 if {$textfont ne $fontpref(textfont)} {
11516 set textfont $fontpref(textfont)
11517 parsefont textfont $textfont
11518 eval font configure textfont [fontflags textfont]
11519 eval font configure textfontbold [fontflags textfont 1]
11521 if {$uifont ne $fontpref(uifont)} {
11522 set uifont $fontpref(uifont)
11523 parsefont uifont $uifont
11524 eval font configure uifont [fontflags uifont]
11527 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11528 if {$showlocalchanges} {
11534 if {$limitdiffs != $oldprefs(limitdiffs) ||
11535 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11536 # treediffs elements are limited by path;
11537 # won't have encodings cached if perfile_attrs was just turned on
11538 catch {unset treediffs}
11540 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11541 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11543 } elseif {$showneartags != $oldprefs(showneartags) ||
11544 $limitdiffs != $oldprefs(limitdiffs)} {
11547 if {$hideremotes != $oldprefs(hideremotes)} {
11552 proc formatdate {d} {
11553 global datetimeformat
11555 # If $datetimeformat includes a timezone, display in the
11556 # timezone of the argument. Otherwise, display in local time.
11557 if {[string match {*%[zZ]*} $datetimeformat]} {
11558 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11559 # Tcl < 8.5 does not support -timezone. Emulate it by
11560 # setting TZ (e.g. TZ=<-0430>+04:30).
11562 if {[info exists env(TZ)]} {
11563 set savedTZ $env(TZ)
11565 set zone [lindex $d 1]
11566 set sign [string map {+ - - +} [string index $zone 0]]
11567 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11568 set d [clock format [lindex $d 0] -format $datetimeformat]
11569 if {[info exists savedTZ]} {
11570 set env(TZ) $savedTZ
11576 set d [clock format [lindex $d 0] -format $datetimeformat]
11582 # This list of encoding names and aliases is distilled from
11583 # http://www.iana.org/assignments/character-sets.
11584 # Not all of them are supported by Tcl.
11585 set encoding_aliases {
11586 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11587 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11588 { ISO-10646-UTF-1 csISO10646UTF1 }
11589 { ISO_646.basic:1983 ref csISO646basic1983 }
11590 { INVARIANT csINVARIANT }
11591 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11592 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11593 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11594 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11595 { NATS-DANO iso-ir-9-1 csNATSDANO }
11596 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11597 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11598 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11599 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11600 { ISO-2022-KR csISO2022KR }
11602 { ISO-2022-JP csISO2022JP }
11603 { ISO-2022-JP-2 csISO2022JP2 }
11604 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11605 csISO13JISC6220jp }
11606 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11607 { IT iso-ir-15 ISO646-IT csISO15Italian }
11608 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11609 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11610 { greek7-old iso-ir-18 csISO18Greek7Old }
11611 { latin-greek iso-ir-19 csISO19LatinGreek }
11612 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11613 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11614 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11615 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11616 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11617 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11618 { INIS iso-ir-49 csISO49INIS }
11619 { INIS-8 iso-ir-50 csISO50INIS8 }
11620 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11621 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11622 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11623 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11624 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11625 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11626 csISO60Norwegian1 }
11627 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11628 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11629 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11630 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11631 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11632 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11633 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11634 { greek7 iso-ir-88 csISO88Greek7 }
11635 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11636 { iso-ir-90 csISO90 }
11637 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11638 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11639 csISO92JISC62991984b }
11640 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11641 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11642 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11643 csISO95JIS62291984handadd }
11644 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11645 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11646 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11647 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11648 CP819 csISOLatin1 }
11649 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11650 { T.61-7bit iso-ir-102 csISO102T617bit }
11651 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11652 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11653 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11654 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11655 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11656 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11657 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11658 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11659 arabic csISOLatinArabic }
11660 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11661 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11662 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11663 greek greek8 csISOLatinGreek }
11664 { T.101-G2 iso-ir-128 csISO128T101G2 }
11665 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11667 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11668 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11669 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11670 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11671 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11672 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11673 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11674 csISOLatinCyrillic }
11675 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11676 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11677 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11678 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11679 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11680 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11681 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11682 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11683 { ISO_10367-box iso-ir-155 csISO10367Box }
11684 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11685 { latin-lap lap iso-ir-158 csISO158Lap }
11686 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11687 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11690 { JIS_X0201 X0201 csHalfWidthKatakana }
11691 { KSC5636 ISO646-KR csKSC5636 }
11692 { ISO-10646-UCS-2 csUnicode }
11693 { ISO-10646-UCS-4 csUCS4 }
11694 { DEC-MCS dec csDECMCS }
11695 { hp-roman8 roman8 r8 csHPRoman8 }
11696 { macintosh mac csMacintosh }
11697 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11699 { IBM038 EBCDIC-INT cp038 csIBM038 }
11700 { IBM273 CP273 csIBM273 }
11701 { IBM274 EBCDIC-BE CP274 csIBM274 }
11702 { IBM275 EBCDIC-BR cp275 csIBM275 }
11703 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11704 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11705 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11706 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11707 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11708 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11709 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11710 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11711 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11712 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11713 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11714 { IBM437 cp437 437 csPC8CodePage437 }
11715 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11716 { IBM775 cp775 csPC775Baltic }
11717 { IBM850 cp850 850 csPC850Multilingual }
11718 { IBM851 cp851 851 csIBM851 }
11719 { IBM852 cp852 852 csPCp852 }
11720 { IBM855 cp855 855 csIBM855 }
11721 { IBM857 cp857 857 csIBM857 }
11722 { IBM860 cp860 860 csIBM860 }
11723 { IBM861 cp861 861 cp-is csIBM861 }
11724 { IBM862 cp862 862 csPC862LatinHebrew }
11725 { IBM863 cp863 863 csIBM863 }
11726 { IBM864 cp864 csIBM864 }
11727 { IBM865 cp865 865 csIBM865 }
11728 { IBM866 cp866 866 csIBM866 }
11729 { IBM868 CP868 cp-ar csIBM868 }
11730 { IBM869 cp869 869 cp-gr csIBM869 }
11731 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11732 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11733 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11734 { IBM891 cp891 csIBM891 }
11735 { IBM903 cp903 csIBM903 }
11736 { IBM904 cp904 904 csIBBM904 }
11737 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11738 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11739 { IBM1026 CP1026 csIBM1026 }
11740 { EBCDIC-AT-DE csIBMEBCDICATDE }
11741 { EBCDIC-AT-DE-A csEBCDICATDEA }
11742 { EBCDIC-CA-FR csEBCDICCAFR }
11743 { EBCDIC-DK-NO csEBCDICDKNO }
11744 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11745 { EBCDIC-FI-SE csEBCDICFISE }
11746 { EBCDIC-FI-SE-A csEBCDICFISEA }
11747 { EBCDIC-FR csEBCDICFR }
11748 { EBCDIC-IT csEBCDICIT }
11749 { EBCDIC-PT csEBCDICPT }
11750 { EBCDIC-ES csEBCDICES }
11751 { EBCDIC-ES-A csEBCDICESA }
11752 { EBCDIC-ES-S csEBCDICESS }
11753 { EBCDIC-UK csEBCDICUK }
11754 { EBCDIC-US csEBCDICUS }
11755 { UNKNOWN-8BIT csUnknown8BiT }
11756 { MNEMONIC csMnemonic }
11758 { VISCII csVISCII }
11761 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11762 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11763 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11764 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11765 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11766 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11767 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11768 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11769 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11770 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11771 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11772 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11773 { IBM1047 IBM-1047 }
11774 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11775 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11776 { UNICODE-1-1 csUnicode11 }
11777 { CESU-8 csCESU-8 }
11778 { BOCU-1 csBOCU-1 }
11779 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11780 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11782 { ISO-8859-15 ISO_8859-15 Latin-9 }
11783 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11784 { GBK CP936 MS936 windows-936 }
11785 { JIS_Encoding csJISEncoding }
11786 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11787 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11789 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11790 { ISO-10646-UCS-Basic csUnicodeASCII }
11791 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11792 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11793 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11794 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11795 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11796 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11797 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11798 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11799 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11800 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11801 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11802 { Ventura-US csVenturaUS }
11803 { Ventura-International csVenturaInternational }
11804 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11805 { PC8-Turkish csPC8Turkish }
11806 { IBM-Symbols csIBMSymbols }
11807 { IBM-Thai csIBMThai }
11808 { HP-Legal csHPLegal }
11809 { HP-Pi-font csHPPiFont }
11810 { HP-Math8 csHPMath8 }
11811 { Adobe-Symbol-Encoding csHPPSMath }
11812 { HP-DeskTop csHPDesktop }
11813 { Ventura-Math csVenturaMath }
11814 { Microsoft-Publishing csMicrosoftPublishing }
11815 { Windows-31J csWindows31J }
11816 { GB2312 csGB2312 }
11820 proc tcl_encoding {enc} {
11821 global encoding_aliases tcl_encoding_cache
11822 if {[info exists tcl_encoding_cache($enc)]} {
11823 return $tcl_encoding_cache($enc)
11825 set names [encoding names]
11826 set lcnames [string tolower $names]
11827 set enc [string tolower $enc]
11828 set i [lsearch -exact $lcnames $enc]
11830 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11831 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11832 set i [lsearch -exact $lcnames $encx]
11836 foreach l $encoding_aliases {
11837 set ll [string tolower $l]
11838 if {[lsearch -exact $ll $enc] < 0} continue
11839 # look through the aliases for one that tcl knows about
11841 set i [lsearch -exact $lcnames $e]
11843 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11844 set i [lsearch -exact $lcnames $ex]
11854 set tclenc [lindex $names $i]
11856 set tcl_encoding_cache($enc) $tclenc
11860 proc gitattr {path attr default} {
11861 global path_attr_cache
11862 if {[info exists path_attr_cache($attr,$path)]} {
11863 set r $path_attr_cache($attr,$path)
11865 set r "unspecified"
11866 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11867 regexp "(.*): $attr: (.*)" $line m f r
11869 set path_attr_cache($attr,$path) $r
11871 if {$r eq "unspecified"} {
11877 proc cache_gitattr {attr pathlist} {
11878 global path_attr_cache
11880 foreach path $pathlist {
11881 if {![info exists path_attr_cache($attr,$path)]} {
11882 lappend newlist $path
11886 if {[tk windowingsystem] == "win32"} {
11887 # windows has a 32k limit on the arguments to a command...
11890 while {$newlist ne {}} {
11891 set head [lrange $newlist 0 [expr {$lim - 1}]]
11892 set newlist [lrange $newlist $lim end]
11893 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11894 foreach row [split $rlist "\n"] {
11895 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11896 if {[string index $path 0] eq "\""} {
11897 set path [encoding convertfrom [lindex $path 0]]
11899 set path_attr_cache($attr,$path) $value
11906 proc get_path_encoding {path} {
11907 global gui_encoding perfile_attrs
11908 set tcl_enc $gui_encoding
11909 if {$path ne {} && $perfile_attrs} {
11910 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11918 # First check that Tcl/Tk is recent enough
11919 if {[catch {package require Tk 8.4} err]} {
11920 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11921 Gitk requires at least Tcl/Tk 8.4." list
11925 # on OSX bring the current Wish process window to front
11926 if {[tk windowingsystem] eq "aqua"} {
11927 exec osascript -e [format {
11928 tell application "System Events"
11929 set frontmost of processes whose unix id is %d to true
11934 # Unset GIT_TRACE var if set
11935 if { [info exists ::env(GIT_TRACE)] } {
11936 unset ::env(GIT_TRACE)
11940 set wrcomcmd "git diff-tree --stdin -p --pretty"
11944 set gitencoding [exec git config --get i18n.commitencoding]
11947 set gitencoding [exec git config --get i18n.logoutputencoding]
11949 if {$gitencoding == ""} {
11950 set gitencoding "utf-8"
11952 set tclencoding [tcl_encoding $gitencoding]
11953 if {$tclencoding == {}} {
11954 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11957 set gui_encoding [encoding system]
11959 set enc [exec git config --get gui.encoding]
11961 set tclenc [tcl_encoding $enc]
11962 if {$tclenc ne {}} {
11963 set gui_encoding $tclenc
11965 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11970 set log_showroot true
11972 set log_showroot [exec git config --bool --get log.showroot]
11975 if {[tk windowingsystem] eq "aqua"} {
11976 set mainfont {{Lucida Grande} 9}
11977 set textfont {Monaco 9}
11978 set uifont {{Lucida Grande} 9 bold}
11979 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11981 set mainfont {sans 9}
11982 set textfont {monospace 9}
11983 set uifont {sans 9 bold}
11985 set mainfont {Helvetica 9}
11986 set textfont {Courier 9}
11987 set uifont {Helvetica 9 bold}
11990 set findmergefiles 0
11998 set cmitmode "patch"
11999 set wrapcomment "none"
12003 set visiblerefs {"master"}
12005 set showlocalchanges 1
12007 set datetimeformat "%Y-%m-%d %H:%M:%S"
12010 set perfile_attrs 0
12013 if {[tk windowingsystem] eq "aqua"} {
12014 set extdifftool "opendiff"
12016 set extdifftool "meld"
12019 set colors {green red blue magenta darkgrey brown orange}
12020 if {[tk windowingsystem] eq "win32"} {
12021 set uicolor SystemButtonFace
12022 set uifgcolor SystemButtonText
12023 set uifgdisabledcolor SystemDisabledText
12024 set bgcolor SystemWindow
12025 set fgcolor SystemWindowText
12026 set selectbgcolor SystemHighlight
12029 set uifgcolor black
12030 set uifgdisabledcolor "#999"
12033 set selectbgcolor gray85
12035 set diffcolors {red "#00a000" blue}
12037 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12040 set markbgcolor "#e0e0ff"
12042 set headbgcolor green
12043 set headfgcolor black
12044 set headoutlinecolor black
12045 set remotebgcolor #ffddaa
12046 set tagbgcolor yellow
12047 set tagfgcolor black
12048 set tagoutlinecolor black
12049 set reflinecolor black
12050 set filesepbgcolor #aaaaaa
12051 set filesepfgcolor black
12052 set linehoverbgcolor #ffff80
12053 set linehoverfgcolor black
12054 set linehoveroutlinecolor black
12055 set mainheadcirclecolor yellow
12056 set workingfilescirclecolor red
12057 set indexcirclecolor green
12058 set circlecolors {white blue gray blue blue}
12059 set linkfgcolor blue
12060 set circleoutlinecolor $fgcolor
12061 set foundbgcolor yellow
12062 set currentsearchhitbgcolor orange
12064 # button for popping up context menus
12065 if {[tk windowingsystem] eq "aqua"} {
12066 set ctxbut <Button-2>
12068 set ctxbut <Button-3>
12071 ## For msgcat loading, first locate the installation location.
12072 if { [info exists ::env(GITK_MSGSDIR)] } {
12073 ## Msgsdir was manually set in the environment.
12074 set gitk_msgsdir $::env(GITK_MSGSDIR)
12076 ## Let's guess the prefix from argv0.
12077 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12078 set gitk_libdir [file join $gitk_prefix share gitk lib]
12079 set gitk_msgsdir [file join $gitk_libdir msgs]
12083 ## Internationalization (i18n) through msgcat and gettext. See
12084 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12085 package require msgcat
12086 namespace import ::msgcat::mc
12087 ## And eventually load the actual message catalog
12088 ::msgcat::mcload $gitk_msgsdir
12091 # follow the XDG base directory specification by default. See
12092 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12093 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12094 # XDG_CONFIG_HOME environment variable is set
12095 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12096 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12098 # default XDG_CONFIG_HOME
12099 set config_file "~/.config/git/gitk"
12100 set config_file_tmp "~/.config/git/gitk-tmp"
12102 if {![file exists $config_file]} {
12103 # for backward compatibility use the old config file if it exists
12104 if {[file exists "~/.gitk"]} {
12105 set config_file "~/.gitk"
12106 set config_file_tmp "~/.gitk-tmp"
12107 } elseif {![file exists [file dirname $config_file]]} {
12108 file mkdir [file dirname $config_file]
12111 source $config_file
12114 set config_variables {
12115 mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12116 cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12117 hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12118 bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12119 markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
12120 extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
12121 remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
12122 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12123 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
12124 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
12127 parsefont mainfont $mainfont
12128 eval font create mainfont [fontflags mainfont]
12129 eval font create mainfontbold [fontflags mainfont 1]
12131 parsefont textfont $textfont
12132 eval font create textfont [fontflags textfont]
12133 eval font create textfontbold [fontflags textfont 1]
12135 parsefont uifont $uifont
12136 eval font create uifont [fontflags uifont]
12142 # check that we can find a .git directory somewhere...
12143 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12144 show_error {} . [mc "Cannot find a git repository here."]
12149 set selectheadid {}
12152 set cmdline_files {}
12154 set revtreeargscmd {}
12155 foreach arg $argv {
12156 switch -glob -- $arg {
12159 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12162 "--select-commit=*" {
12163 set selecthead [string range $arg 16 end]
12166 set revtreeargscmd [string range $arg 10 end]
12169 lappend revtreeargs $arg
12175 if {$selecthead eq "HEAD"} {
12179 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12180 # no -- on command line, but some arguments (other than --argscmd)
12182 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12183 set cmdline_files [split $f "\n"]
12184 set n [llength $cmdline_files]
12185 set revtreeargs [lrange $revtreeargs 0 end-$n]
12186 # Unfortunately git rev-parse doesn't produce an error when
12187 # something is both a revision and a filename. To be consistent
12188 # with git log and git rev-list, check revtreeargs for filenames.
12189 foreach arg $revtreeargs {
12190 if {[file exists $arg]} {
12191 show_error {} . [mc "Ambiguous argument '%s': both revision\
12192 and filename" $arg]
12197 # unfortunately we get both stdout and stderr in $err,
12198 # so look for "fatal:".
12199 set i [string first "fatal:" $err]
12201 set err [string range $err [expr {$i + 6}] end]
12203 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12208 set nullid "0000000000000000000000000000000000000000"
12209 set nullid2 "0000000000000000000000000000000000000001"
12210 set nullfile "/dev/null"
12212 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12213 if {![info exists have_ttk]} {
12214 set have_ttk [llength [info commands ::ttk::style]]
12216 set use_ttk [expr {$have_ttk && $want_ttk}]
12217 set NS [expr {$use_ttk ? "ttk" : ""}]
12219 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12222 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12223 set show_notes "--show-notes"
12233 set highlight_paths {}
12235 set searchdirn -forwards
12238 set diffelide {0 0}
12239 set markingmatches 0
12240 set linkentercount 0
12241 set need_redisplay 0
12248 set selectedhlview [mc "None"]
12249 set highlight_related [mc "None"]
12250 set highlight_files {}
12251 set viewfiles(0) {}
12254 set viewargscmd(0) {}
12256 set selectedline {}
12264 set hasworktree [hasworktree]
12266 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12267 set cdup [exec git rev-parse --show-cdup]
12269 set worktree [exec git rev-parse --show-toplevel]
12273 image create photo gitlogo -width 16 -height 16
12275 image create photo gitlogominus -width 4 -height 2
12276 gitlogominus put #C00000 -to 0 0 4 2
12277 gitlogo copy gitlogominus -to 1 5
12278 gitlogo copy gitlogominus -to 6 5
12279 gitlogo copy gitlogominus -to 11 5
12280 image delete gitlogominus
12282 image create photo gitlogoplus -width 4 -height 4
12283 gitlogoplus put #008000 -to 1 0 3 4
12284 gitlogoplus put #008000 -to 0 1 4 3
12285 gitlogo copy gitlogoplus -to 1 9
12286 gitlogo copy gitlogoplus -to 6 9
12287 gitlogo copy gitlogoplus -to 11 9
12288 image delete gitlogoplus
12290 image create photo gitlogo32 -width 32 -height 32
12291 gitlogo32 copy gitlogo -zoom 2 2
12293 wm iconphoto . -default gitlogo gitlogo32
12295 # wait for the window to become visible
12296 tkwait visibility .
12297 wm title . "$appname: [reponame]"
12301 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12302 # create a view for the files/dirs specified on the command line
12306 set viewname(1) [mc "Command line"]
12307 set viewfiles(1) $cmdline_files
12308 set viewargs(1) $revtreeargs
12309 set viewargscmd(1) $revtreeargscmd
12313 .bar.view entryconf [mca "Edit view..."] -state normal
12314 .bar.view entryconf [mca "Delete view"] -state normal
12317 if {[info exists permviews]} {
12318 foreach v $permviews {
12321 set viewname($n) [lindex $v 0]
12322 set viewfiles($n) [lindex $v 1]
12323 set viewargs($n) [lindex $v 2]
12324 set viewargscmd($n) [lindex $v 3]
12330 if {[tk windowingsystem] eq "win32"} {
12338 # indent-tabs-mode: t