2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2011 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 set n
[file normalize
$gitdir]
20 if {[string match
"*/.git" $n]} {
21 set n
[string range
$n 0 end-5
]
28 if {[info exists _gitworktree
]} {
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
37 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
38 if {$_gitworktree eq
""} {
39 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
49 # run before X event handlers, so reading from a fast source can
50 # make the GUI completely unresponsive.
52 global isonrunq runq currunq
55 if {[info exists isonrunq
($script)]} return
56 if {$runq eq
{} && ![info exists currunq
]} {
59 lappend runq
[list
{} $script]
60 set isonrunq
($script) 1
63 proc filerun
{fd
script} {
64 fileevent
$fd readable
[list filereadable
$fd $script]
67 proc filereadable
{fd
script} {
70 fileevent
$fd readable
{}
71 if {$runq eq
{} && ![info exists currunq
]} {
74 lappend runq
[list
$fd $script]
80 for {set i
0} {$i < [llength
$runq]} {} {
81 if {[lindex
$runq $i 0] eq
$fd} {
82 set runq
[lreplace
$runq $i $i]
90 global isonrunq runq currunq
92 set tstart
[clock clicks
-milliseconds]
94 while {[llength
$runq] > 0} {
95 set fd
[lindex
$runq 0 0]
96 set script [lindex
$runq 0 1]
97 set currunq
[lindex
$runq 0]
98 set runq
[lrange
$runq 1 end
]
99 set repeat
[eval $script]
101 set t1
[clock clicks
-milliseconds]
102 set t
[expr {$t1 - $t0}]
103 if {$repeat ne
{} && $repeat} {
104 if {$fd eq
{} ||
$repeat == 2} {
105 # script returns 1 if it wants to be readded
106 # file readers return 2 if they could do more straight away
107 lappend runq
[list
$fd $script]
109 fileevent
$fd readable
[list filereadable
$fd $script]
111 } elseif
{$fd eq
{}} {
112 unset isonrunq
($script)
115 if {$t1 - $tstart >= 80} break
122 proc reg_instance
{fd
} {
123 global commfd leftover loginstance
125 set i
[incr loginstance
]
131 proc unmerged_files
{files
} {
134 # find the list of unmerged files
138 set fd
[open
"| git ls-files -u" r
]
140 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
149 if {$files eq {} || [path_filter $files $fname]} {
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
160 global worddiff git_version
164 set vinlinediff($n) 0
169 set origargs $arglist
173 foreach arg $arglist {
180 switch -glob -- $arg {
184 # remove from origargs in case we hit an unknown option
185 set origargs [lreplace $origargs $i $i]
189 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
190 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
191 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
192 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
193 "--ignore-space-change" - "-U*" - "--unified=*" {
194 # These request or affect diff output, which we don't want.
195 # Some could be used to set our defaults for diff display.
196 lappend diffargs
$arg
198 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
199 "--name-only" - "--name-status" - "--color" -
200 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
201 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
202 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
203 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
204 "--objects" - "--objects-edge" - "--reverse" {
205 # These cause our parsing of git log's output to fail, or else
206 # they're options we want to set ourselves, so ignore them.
208 "--color-words*" - "--word-diff=color" {
209 # These trigger a word diff in the console interface,
210 # so help the user by enabling our own support
211 if {[package vcompare
$git_version "1.7.2"] >= 0} {
212 set worddiff
[mc
"Color words"]
216 if {[package vcompare
$git_version "1.7.2"] >= 0} {
217 set worddiff
[mc
"Markup words"]
220 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
221 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
222 "--full-history" - "--dense" - "--sparse" -
223 "--follow" - "--left-right" - "--encoding=*" {
224 # These are harmless, and some are even useful
227 "--diff-filter=*" - "--no-merges" - "--unpacked" -
228 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
229 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
230 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
231 "--remove-empty" - "--first-parent" - "--cherry-pick" -
232 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
233 "--simplify-by-decoration" {
234 # These mean that we get a subset of the commits
239 # Line-log with 'stuck' argument (unstuck form is
242 set vinlinediff
($n) 1
247 # This appears to be the only one that has a value as a
248 # separate word following it
258 # git rev-parse doesn't understand --merge
259 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
261 "--no-replace-objects" {
262 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
265 # Other flag arguments including -<n>
266 if {[string is digit
-strict [string range
$arg 1 end
]]} {
269 # a flag argument that we don't recognize;
270 # that means we can't optimize
276 # Non-flag arguments specify commits or ranges of commits
277 if {[string match
"*...*" $arg]} {
278 lappend revargs
--gitk-symmetric-diff-marker
284 set vdflags
($n) $diffargs
285 set vflags
($n) $glflags
286 set vrevs
($n) $revargs
287 set vfiltered
($n) $filtered
288 set vorigargs
($n) $origargs
292 proc parseviewrevs
{view revs
} {
293 global vposids vnegids
298 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
299 # we get stdout followed by stderr in $err
300 # for an unknown rev, git rev-parse echoes it and then errors out
301 set errlines
[split $err "\n"]
303 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
304 set line
[lindex
$errlines $l]
305 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
306 if {[string match
"fatal:*" $line]} {
307 if {[string match
"fatal: ambiguous argument*" $line]
309 if {[llength
$badrev] == 1} {
310 set err
"unknown revision $badrev"
312 set err
"unknown revisions: [join $badrev ", "]"
315 set err
[join [lrange
$errlines $l end
] "\n"]
322 error_popup
"[mc "Error parsing revisions
:"] $err"
329 foreach id
[split $ids "\n"] {
330 if {$id eq
"--gitk-symmetric-diff-marker"} {
332 } elseif
{[string match
"^*" $id]} {
339 lappend neg
[string range
$id 1 end
]
344 lset ret end
$id...
[lindex
$ret end
]
350 set vposids
($view) $pos
351 set vnegids
($view) $neg
355 # Start off a git log process and arrange to read its output
356 proc start_rev_list
{view
} {
357 global startmsecs commitidx viewcomplete curview
359 global viewargs viewargscmd viewfiles vfilelimit
360 global showlocalchanges
361 global viewactive viewinstances vmergeonly
362 global mainheadid viewmainheadid viewmainheadid_orig
363 global vcanopt vflags vrevs vorigargs
366 set startmsecs
[clock clicks
-milliseconds]
367 set commitidx
($view) 0
368 # these are set this way for the error exits
369 set viewcomplete
($view) 1
370 set viewactive
($view) 0
373 set args
$viewargs($view)
374 if {$viewargscmd($view) ne
{}} {
376 set str
[exec sh
-c $viewargscmd($view)]
378 error_popup
"[mc "Error executing
--argscmd command:"] $err"
381 set args
[concat
$args [split $str "\n"]]
383 set vcanopt
($view) [parseviewargs
$view $args]
385 set files
$viewfiles($view)
386 if {$vmergeonly($view)} {
387 set files
[unmerged_files
$files]
390 if {$nr_unmerged == 0} {
391 error_popup
[mc
"No files selected: --merge specified but\
392 no files are unmerged."]
394 error_popup
[mc
"No files selected: --merge specified but\
395 no unmerged files are within file limit."]
400 set vfilelimit
($view) $files
402 if {$vcanopt($view)} {
403 set revs
[parseviewrevs
$view $vrevs($view)]
407 set args
[concat
$vflags($view) $revs]
409 set args
$vorigargs($view)
413 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
414 --parents --boundary $args "--" $files] r
]
416 error_popup
"[mc "Error executing git log
:"] $err"
419 set i
[reg_instance
$fd]
420 set viewinstances
($view) [list
$i]
421 set viewmainheadid
($view) $mainheadid
422 set viewmainheadid_orig
($view) $mainheadid
423 if {$files ne
{} && $mainheadid ne
{}} {
424 get_viewmainhead
$view
426 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
427 interestedin
$viewmainheadid($view) dodiffindex
429 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
430 if {$tclencoding != {}} {
431 fconfigure
$fd -encoding $tclencoding
433 filerun
$fd [list getcommitlines
$fd $i $view 0]
434 nowbusy
$view [mc
"Reading"]
435 set viewcomplete
($view) 0
436 set viewactive
($view) 1
440 proc stop_instance
{inst
} {
441 global commfd leftover
443 set fd
$commfd($inst)
447 if {$
::tcl_platform
(platform
) eq
{windows
}} {
456 unset leftover
($inst)
459 proc stop_backends
{} {
462 foreach inst
[array names commfd
] {
467 proc stop_rev_list
{view
} {
470 foreach inst
$viewinstances($view) {
473 set viewinstances
($view) {}
476 proc reset_pending_select
{selid
} {
477 global pending_select mainheadid selectheadid
480 set pending_select
$selid
481 } elseif
{$selectheadid ne
{}} {
482 set pending_select
$selectheadid
484 set pending_select
$mainheadid
488 proc getcommits
{selid
} {
489 global canv curview need_redisplay viewactive
492 if {[start_rev_list
$curview]} {
493 reset_pending_select
$selid
494 show_status
[mc
"Reading commits..."]
497 show_status
[mc
"No commits selected"]
501 proc updatecommits
{} {
502 global curview vcanopt vorigargs vfilelimit viewinstances
503 global viewactive viewcomplete tclencoding
504 global startmsecs showneartags showlocalchanges
505 global mainheadid viewmainheadid viewmainheadid_orig pending_select
507 global varcid vposids vnegids vflags vrevs
510 set hasworktree
[hasworktree
]
513 if {$mainheadid ne
$viewmainheadid_orig($view)} {
514 if {$showlocalchanges} {
517 set viewmainheadid
($view) $mainheadid
518 set viewmainheadid_orig
($view) $mainheadid
519 if {$vfilelimit($view) ne
{}} {
520 get_viewmainhead
$view
523 if {$showlocalchanges} {
526 if {$vcanopt($view)} {
527 set oldpos
$vposids($view)
528 set oldneg
$vnegids($view)
529 set revs
[parseviewrevs
$view $vrevs($view)]
533 # note: getting the delta when negative refs change is hard,
534 # and could require multiple git log invocations, so in that
535 # case we ask git log for all the commits (not just the delta)
536 if {$oldneg eq
$vnegids($view)} {
539 # take out positive refs that we asked for before or
540 # that we have already seen
542 if {[string length
$rev] == 40} {
543 if {[lsearch
-exact $oldpos $rev] < 0
544 && ![info exists varcid
($view,$rev)]} {
549 lappend
$newrevs $rev
552 if {$npos == 0} return
554 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
556 set args
[concat
$vflags($view) $revs --not $oldpos]
558 set args
$vorigargs($view)
561 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
562 --parents --boundary $args "--" $vfilelimit($view)] r
]
564 error_popup
"[mc "Error executing git log
:"] $err"
567 if {$viewactive($view) == 0} {
568 set startmsecs
[clock clicks
-milliseconds]
570 set i
[reg_instance
$fd]
571 lappend viewinstances
($view) $i
572 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
573 if {$tclencoding != {}} {
574 fconfigure
$fd -encoding $tclencoding
576 filerun
$fd [list getcommitlines
$fd $i $view 1]
577 incr viewactive
($view)
578 set viewcomplete
($view) 0
579 reset_pending_select
{}
580 nowbusy
$view [mc
"Reading"]
586 proc reloadcommits
{} {
587 global curview viewcomplete selectedline currentid thickerline
588 global showneartags treediffs commitinterest cached_commitrow
592 if {$selectedline ne
{}} {
596 if {!$viewcomplete($curview)} {
597 stop_rev_list
$curview
601 catch
{unset currentid
}
602 catch
{unset thickerline
}
603 catch
{unset treediffs
}
610 catch
{unset commitinterest
}
611 catch
{unset cached_commitrow
}
612 catch
{unset targetid
}
618 # This makes a string representation of a positive integer which
619 # sorts as a string in numerical order
622 return [format
"%x" $n]
623 } elseif
{$n < 256} {
624 return [format
"x%.2x" $n]
625 } elseif
{$n < 65536} {
626 return [format
"y%.4x" $n]
628 return [format
"z%.8x" $n]
631 # Procedures used in reordering commits from git log (without
632 # --topo-order) into the order for display.
634 proc varcinit
{view
} {
635 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
636 global vtokmod varcmod vrowmod varcix vlastins
638 set varcstart
($view) {{}}
639 set vupptr
($view) {0}
640 set vdownptr
($view) {0}
641 set vleftptr
($view) {0}
642 set vbackptr
($view) {0}
643 set varctok
($view) {{}}
644 set varcrow
($view) {{}}
645 set vtokmod
($view) {}
648 set varcix
($view) {{}}
649 set vlastins
($view) {0}
652 proc resetvarcs
{view
} {
653 global varcid varccommits parents children vseedcount ordertok
656 foreach vid
[array names varcid
$view,*] {
661 foreach vid
[array names vshortids
$view,*] {
662 unset vshortids
($vid)
664 # some commits might have children but haven't been seen yet
665 foreach vid
[array names children
$view,*] {
668 foreach va
[array names varccommits
$view,*] {
669 unset varccommits
($va)
671 foreach vd
[array names vseedcount
$view,*] {
672 unset vseedcount
($vd)
674 catch
{unset ordertok
}
677 # returns a list of the commits with no children
679 global vdownptr vleftptr varcstart
682 set a
[lindex
$vdownptr($v) 0]
684 lappend ret
[lindex
$varcstart($v) $a]
685 set a
[lindex
$vleftptr($v) $a]
690 proc newvarc
{view id
} {
691 global varcid varctok parents children vdatemode
692 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
693 global commitdata commitinfo vseedcount varccommits vlastins
695 set a
[llength
$varctok($view)]
697 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
698 if {![info exists commitinfo
($id)]} {
699 parsecommit
$id $commitdata($id) 1
701 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
702 if {![string is integer
-strict $cdate]} {
705 if {![info exists vseedcount
($view,$cdate)]} {
706 set vseedcount
($view,$cdate) -1
708 set c
[incr vseedcount
($view,$cdate)]
709 set cdate
[expr {$cdate ^
0xffffffff}]
710 set tok
"s[strrep $cdate][strrep $c]"
715 if {[llength
$children($vid)] > 0} {
716 set kid
[lindex
$children($vid) end
]
717 set k
$varcid($view,$kid)
718 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
721 set tok
[lindex
$varctok($view) $k]
725 set i
[lsearch
-exact $parents($view,$ki) $id]
726 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
727 append tok
[strrep
$j]
729 set c
[lindex
$vlastins($view) $ka]
730 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
732 set b
[lindex
$vdownptr($view) $ka]
734 set b
[lindex
$vleftptr($view) $c]
736 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
738 set b
[lindex
$vleftptr($view) $c]
741 lset vdownptr
($view) $ka $a
742 lappend vbackptr
($view) 0
744 lset vleftptr
($view) $c $a
745 lappend vbackptr
($view) $c
747 lset vlastins
($view) $ka $a
748 lappend vupptr
($view) $ka
749 lappend vleftptr
($view) $b
751 lset vbackptr
($view) $b $a
753 lappend varctok
($view) $tok
754 lappend varcstart
($view) $id
755 lappend vdownptr
($view) 0
756 lappend varcrow
($view) {}
757 lappend varcix
($view) {}
758 set varccommits
($view,$a) {}
759 lappend vlastins
($view) 0
763 proc splitvarc
{p v
} {
764 global varcid varcstart varccommits varctok vtokmod
765 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
767 set oa
$varcid($v,$p)
768 set otok
[lindex
$varctok($v) $oa]
769 set ac
$varccommits($v,$oa)
770 set i
[lsearch
-exact $varccommits($v,$oa) $p]
772 set na
[llength
$varctok($v)]
773 # "%" sorts before "0"...
774 set tok
"$otok%[strrep $i]"
775 lappend varctok
($v) $tok
776 lappend varcrow
($v) {}
777 lappend varcix
($v) {}
778 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
779 set varccommits
($v,$na) [lrange
$ac $i end
]
780 lappend varcstart
($v) $p
781 foreach id
$varccommits($v,$na) {
782 set varcid
($v,$id) $na
784 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
785 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
786 lset vdownptr
($v) $oa $na
787 lset vlastins
($v) $oa 0
788 lappend vupptr
($v) $oa
789 lappend vleftptr
($v) 0
790 lappend vbackptr
($v) 0
791 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
792 lset vupptr
($v) $b $na
794 if {[string compare
$otok $vtokmod($v)] <= 0} {
799 proc renumbervarc
{a v
} {
800 global parents children varctok varcstart varccommits
801 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
803 set t1
[clock clicks
-milliseconds]
809 if {[info exists isrelated
($a)]} {
811 set id
[lindex
$varccommits($v,$a) end
]
812 foreach p
$parents($v,$id) {
813 if {[info exists varcid
($v,$p)]} {
814 set isrelated
($varcid($v,$p)) 1
819 set b
[lindex
$vdownptr($v) $a]
822 set b
[lindex
$vleftptr($v) $a]
824 set a
[lindex
$vupptr($v) $a]
830 if {![info exists kidchanged
($a)]} continue
831 set id
[lindex
$varcstart($v) $a]
832 if {[llength
$children($v,$id)] > 1} {
833 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
836 set oldtok
[lindex
$varctok($v) $a]
837 if {!$vdatemode($v)} {
843 set kid
[last_real_child
$v,$id]
845 set k
$varcid($v,$kid)
846 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
849 set tok
[lindex
$varctok($v) $k]
853 set i
[lsearch
-exact $parents($v,$ki) $id]
854 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
855 append tok
[strrep
$j]
857 if {$tok eq
$oldtok} {
860 set id
[lindex
$varccommits($v,$a) end
]
861 foreach p
$parents($v,$id) {
862 if {[info exists varcid
($v,$p)]} {
863 set kidchanged
($varcid($v,$p)) 1
868 lset varctok
($v) $a $tok
869 set b
[lindex
$vupptr($v) $a]
871 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
874 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
877 set c
[lindex
$vbackptr($v) $a]
878 set d
[lindex
$vleftptr($v) $a]
880 lset vdownptr
($v) $b $d
882 lset vleftptr
($v) $c $d
885 lset vbackptr
($v) $d $c
887 if {[lindex
$vlastins($v) $b] == $a} {
888 lset vlastins
($v) $b $c
890 lset vupptr
($v) $a $ka
891 set c
[lindex
$vlastins($v) $ka]
893 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
895 set b
[lindex
$vdownptr($v) $ka]
897 set b
[lindex
$vleftptr($v) $c]
900 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
902 set b
[lindex
$vleftptr($v) $c]
905 lset vdownptr
($v) $ka $a
906 lset vbackptr
($v) $a 0
908 lset vleftptr
($v) $c $a
909 lset vbackptr
($v) $a $c
911 lset vleftptr
($v) $a $b
913 lset vbackptr
($v) $b $a
915 lset vlastins
($v) $ka $a
918 foreach id
[array names sortkids
] {
919 if {[llength
$children($v,$id)] > 1} {
920 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
924 set t2
[clock clicks
-milliseconds]
925 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
928 # Fix up the graph after we have found out that in view $v,
929 # $p (a commit that we have already seen) is actually the parent
930 # of the last commit in arc $a.
931 proc fix_reversal
{p a v
} {
932 global varcid varcstart varctok vupptr
934 set pa
$varcid($v,$p)
935 if {$p ne
[lindex
$varcstart($v) $pa]} {
937 set pa
$varcid($v,$p)
939 # seeds always need to be renumbered
940 if {[lindex
$vupptr($v) $pa] == 0 ||
941 [string compare
[lindex
$varctok($v) $a] \
942 [lindex
$varctok($v) $pa]] > 0} {
947 proc insertrow
{id p v
} {
948 global cmitlisted children parents varcid varctok vtokmod
949 global varccommits ordertok commitidx numcommits curview
950 global targetid targetrow vshortids
954 set cmitlisted
($vid) 1
955 set children
($vid) {}
956 set parents
($vid) [list
$p]
957 set a
[newvarc
$v $id]
959 lappend vshortids
($v,[string range
$id 0 3]) $id
960 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
963 lappend varccommits
($v,$a) $id
965 if {[llength
[lappend children
($vp) $id]] > 1} {
966 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
967 catch
{unset ordertok
}
969 fix_reversal
$p $a $v
971 if {$v == $curview} {
972 set numcommits
$commitidx($v)
974 if {[info exists targetid
]} {
975 if {![comes_before
$targetid $p]} {
982 proc insertfakerow
{id p
} {
983 global varcid varccommits parents children cmitlisted
984 global commitidx varctok vtokmod targetid targetrow curview numcommits
988 set i
[lsearch
-exact $varccommits($v,$a) $p]
990 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
993 set children
($v,$id) {}
994 set parents
($v,$id) [list
$p]
995 set varcid
($v,$id) $a
996 lappend children
($v,$p) $id
997 set cmitlisted
($v,$id) 1
998 set numcommits
[incr commitidx
($v)]
999 # note we deliberately don't update varcstart($v) even if $i == 0
1000 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
1002 if {[info exists targetid
]} {
1003 if {![comes_before
$targetid $p]} {
1011 proc removefakerow
{id
} {
1012 global varcid varccommits parents children commitidx
1013 global varctok vtokmod cmitlisted currentid selectedline
1014 global targetid curview numcommits
1017 if {[llength
$parents($v,$id)] != 1} {
1018 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1021 set p
[lindex
$parents($v,$id) 0]
1022 set a
$varcid($v,$id)
1023 set i
[lsearch
-exact $varccommits($v,$a) $id]
1025 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1028 unset varcid
($v,$id)
1029 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1030 unset parents
($v,$id)
1031 unset children
($v,$id)
1032 unset cmitlisted
($v,$id)
1033 set numcommits
[incr commitidx
($v) -1]
1034 set j
[lsearch
-exact $children($v,$p) $id]
1036 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1039 if {[info exist currentid
] && $id eq
$currentid} {
1043 if {[info exists targetid
] && $targetid eq
$id} {
1050 proc real_children
{vp
} {
1051 global children nullid nullid2
1054 foreach id
$children($vp) {
1055 if {$id ne
$nullid && $id ne
$nullid2} {
1062 proc first_real_child
{vp
} {
1063 global children nullid nullid2
1065 foreach id
$children($vp) {
1066 if {$id ne
$nullid && $id ne
$nullid2} {
1073 proc last_real_child
{vp
} {
1074 global children nullid nullid2
1076 set kids
$children($vp)
1077 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1078 set id
[lindex
$kids $i]
1079 if {$id ne
$nullid && $id ne
$nullid2} {
1086 proc vtokcmp
{v a b
} {
1087 global varctok varcid
1089 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1090 [lindex
$varctok($v) $varcid($v,$b)]]
1093 # This assumes that if lim is not given, the caller has checked that
1094 # arc a's token is less than $vtokmod($v)
1095 proc modify_arc
{v a
{lim
{}}} {
1096 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1099 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1102 set r
[lindex
$varcrow($v) $a]
1103 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1106 set vtokmod
($v) [lindex
$varctok($v) $a]
1108 if {$v == $curview} {
1109 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1110 set a
[lindex
$vupptr($v) $a]
1116 set lim
[llength
$varccommits($v,$a)]
1118 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1125 proc update_arcrows
{v
} {
1126 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1127 global varcid vrownum varcorder varcix varccommits
1128 global vupptr vdownptr vleftptr varctok
1129 global displayorder parentlist curview cached_commitrow
1131 if {$vrowmod($v) == $commitidx($v)} return
1132 if {$v == $curview} {
1133 if {[llength
$displayorder] > $vrowmod($v)} {
1134 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1135 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1137 catch
{unset cached_commitrow
}
1139 set narctot
[expr {[llength
$varctok($v)] - 1}]
1141 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1142 # go up the tree until we find something that has a row number,
1143 # or we get to a seed
1144 set a
[lindex
$vupptr($v) $a]
1147 set a
[lindex
$vdownptr($v) 0]
1150 set varcorder
($v) [list
$a]
1151 lset varcix
($v) $a 0
1152 lset varcrow
($v) $a 0
1156 set arcn
[lindex
$varcix($v) $a]
1157 if {[llength
$vrownum($v)] > $arcn + 1} {
1158 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1159 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1161 set row
[lindex
$varcrow($v) $a]
1165 incr row
[llength
$varccommits($v,$a)]
1166 # go down if possible
1167 set b
[lindex
$vdownptr($v) $a]
1169 # if not, go left, or go up until we can go left
1171 set b
[lindex
$vleftptr($v) $a]
1173 set a
[lindex
$vupptr($v) $a]
1179 lappend vrownum
($v) $row
1180 lappend varcorder
($v) $a
1181 lset varcix
($v) $a $arcn
1182 lset varcrow
($v) $a $row
1184 set vtokmod
($v) [lindex
$varctok($v) $p]
1186 set vrowmod
($v) $row
1187 if {[info exists currentid
]} {
1188 set selectedline
[rowofcommit
$currentid]
1192 # Test whether view $v contains commit $id
1193 proc commitinview
{id v
} {
1196 return [info exists varcid
($v,$id)]
1199 # Return the row number for commit $id in the current view
1200 proc rowofcommit
{id
} {
1201 global varcid varccommits varcrow curview cached_commitrow
1202 global varctok vtokmod
1205 if {![info exists varcid
($v,$id)]} {
1206 puts
"oops rowofcommit no arc for [shortids $id]"
1209 set a
$varcid($v,$id)
1210 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1213 if {[info exists cached_commitrow
($id)]} {
1214 return $cached_commitrow($id)
1216 set i
[lsearch
-exact $varccommits($v,$a) $id]
1218 puts
"oops didn't find commit [shortids $id] in arc $a"
1221 incr i
[lindex
$varcrow($v) $a]
1222 set cached_commitrow
($id) $i
1226 # Returns 1 if a is on an earlier row than b, otherwise 0
1227 proc comes_before
{a b
} {
1228 global varcid varctok curview
1231 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1232 ![info exists varcid
($v,$b)]} {
1235 if {$varcid($v,$a) != $varcid($v,$b)} {
1236 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1237 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1239 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1242 proc bsearch
{l elt
} {
1243 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1248 while {$hi - $lo > 1} {
1249 set mid
[expr {int
(($lo + $hi) / 2)}]
1250 set t
[lindex
$l $mid]
1253 } elseif
{$elt > $t} {
1262 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1263 proc make_disporder
{start end
} {
1264 global vrownum curview commitidx displayorder parentlist
1265 global varccommits varcorder parents vrowmod varcrow
1266 global d_valid_start d_valid_end
1268 if {$end > $vrowmod($curview)} {
1269 update_arcrows
$curview
1271 set ai
[bsearch
$vrownum($curview) $start]
1272 set start
[lindex
$vrownum($curview) $ai]
1273 set narc
[llength
$vrownum($curview)]
1274 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1275 set a
[lindex
$varcorder($curview) $ai]
1276 set l
[llength
$displayorder]
1277 set al
[llength
$varccommits($curview,$a)]
1278 if {$l < $r + $al} {
1280 set pad
[ntimes
[expr {$r - $l}] {}]
1281 set displayorder
[concat
$displayorder $pad]
1282 set parentlist
[concat
$parentlist $pad]
1283 } elseif
{$l > $r} {
1284 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1285 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1287 foreach id
$varccommits($curview,$a) {
1288 lappend displayorder
$id
1289 lappend parentlist
$parents($curview,$id)
1291 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1293 foreach id
$varccommits($curview,$a) {
1294 lset displayorder
$i $id
1295 lset parentlist
$i $parents($curview,$id)
1303 proc commitonrow
{row
} {
1306 set id
[lindex
$displayorder $row]
1308 make_disporder
$row [expr {$row + 1}]
1309 set id
[lindex
$displayorder $row]
1314 proc closevarcs
{v
} {
1315 global varctok varccommits varcid parents children
1316 global cmitlisted commitidx vtokmod
1318 set missing_parents
0
1320 set narcs
[llength
$varctok($v)]
1321 for {set a
1} {$a < $narcs} {incr a
} {
1322 set id
[lindex
$varccommits($v,$a) end
]
1323 foreach p
$parents($v,$id) {
1324 if {[info exists varcid
($v,$p)]} continue
1325 # add p as a new commit
1326 incr missing_parents
1327 set cmitlisted
($v,$p) 0
1328 set parents
($v,$p) {}
1329 if {[llength
$children($v,$p)] == 1 &&
1330 [llength
$parents($v,$id)] == 1} {
1333 set b
[newvarc
$v $p]
1335 set varcid
($v,$p) $b
1336 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1339 lappend varccommits
($v,$b) $p
1341 set scripts
[check_interest
$p $scripts]
1344 if {$missing_parents > 0} {
1345 foreach s
$scripts {
1351 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1352 # Assumes we already have an arc for $rwid.
1353 proc rewrite_commit
{v id rwid
} {
1354 global children parents varcid varctok vtokmod varccommits
1356 foreach ch
$children($v,$id) {
1357 # make $rwid be $ch's parent in place of $id
1358 set i
[lsearch
-exact $parents($v,$ch) $id]
1360 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1362 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1363 # add $ch to $rwid's children and sort the list if necessary
1364 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1365 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1366 $children($v,$rwid)]
1368 # fix the graph after joining $id to $rwid
1369 set a
$varcid($v,$ch)
1370 fix_reversal
$rwid $a $v
1371 # parentlist is wrong for the last element of arc $a
1372 # even if displayorder is right, hence the 3rd arg here
1373 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1377 # Mechanism for registering a command to be executed when we come
1378 # across a particular commit. To handle the case when only the
1379 # prefix of the commit is known, the commitinterest array is now
1380 # indexed by the first 4 characters of the ID. Each element is a
1381 # list of id, cmd pairs.
1382 proc interestedin
{id cmd
} {
1383 global commitinterest
1385 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1388 proc check_interest
{id scripts
} {
1389 global commitinterest
1391 set prefix
[string range
$id 0 3]
1392 if {[info exists commitinterest
($prefix)]} {
1394 foreach
{i
script} $commitinterest($prefix) {
1395 if {[string match
"$i*" $id]} {
1396 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1398 lappend newlist
$i $script
1401 if {$newlist ne
{}} {
1402 set commitinterest
($prefix) $newlist
1404 unset commitinterest
($prefix)
1410 proc getcommitlines
{fd inst view updating
} {
1411 global cmitlisted leftover
1412 global commitidx commitdata vdatemode
1413 global parents children curview hlview
1414 global idpending ordertok
1415 global varccommits varcid varctok vtokmod vfilelimit vshortids
1417 set stuff
[read $fd 500000]
1418 # git log doesn't terminate the last commit with a null...
1419 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1426 global commfd viewcomplete viewactive viewname
1427 global viewinstances
1429 set i
[lsearch
-exact $viewinstances($view) $inst]
1431 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1433 # set it blocking so we wait for the process to terminate
1434 fconfigure
$fd -blocking 1
1435 if {[catch
{close
$fd} err
]} {
1437 if {$view != $curview} {
1438 set fv
" for the \"$viewname($view)\" view"
1440 if {[string range
$err 0 4] == "usage"} {
1441 set err
"Gitk: error reading commits$fv:\
1442 bad arguments to git log."
1443 if {$viewname($view) eq
"Command line"} {
1445 " (Note: arguments to gitk are passed to git log\
1446 to allow selection of commits to be displayed.)"
1449 set err
"Error reading commits$fv: $err"
1453 if {[incr viewactive
($view) -1] <= 0} {
1454 set viewcomplete
($view) 1
1455 # Check if we have seen any ids listed as parents that haven't
1456 # appeared in the list
1460 if {$view == $curview} {
1469 set i
[string first
"\0" $stuff $start]
1471 append leftover
($inst) [string range
$stuff $start end
]
1475 set cmit
$leftover($inst)
1476 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1477 set leftover
($inst) {}
1479 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1481 set start
[expr {$i + 1}]
1482 set j
[string first
"\n" $cmit]
1485 if {$j >= 0 && [string match
"commit *" $cmit]} {
1486 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1487 if {[string match
{[-^
<>]*} $ids]} {
1488 switch
-- [string index
$ids 0] {
1494 set ids
[string range
$ids 1 end
]
1498 if {[string length
$id] != 40} {
1506 if {[string length
$shortcmit] > 80} {
1507 set shortcmit
"[string range $shortcmit 0 80]..."
1509 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1512 set id [lindex $ids 0]
1515 lappend vshortids($view,[string range $id 0 3]) $id
1517 if {!$listed && $updating && ![info exists varcid($vid)] &&
1518 $vfilelimit($view) ne {}} {
1519 # git log doesn't rewrite parents
for unlisted commits
1520 # when doing path limiting, so work around that here
1521 # by working out the rewritten parent with git rev-list
1522 # and if we already know about it, using the rewritten
1523 # parent as a substitute parent for $id's children.
1525 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1526 $id -- $vfilelimit($view)]
1528 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1529 # use $rwid in place of $id
1530 rewrite_commit
$view $id $rwid
1537 if {[info exists varcid
($vid)]} {
1538 if {$cmitlisted($vid) ||
!$listed} continue
1542 set olds
[lrange
$ids 1 end
]
1546 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1547 set cmitlisted
($vid) $listed
1548 set parents
($vid) $olds
1549 if {![info exists children
($vid)]} {
1550 set children
($vid) {}
1551 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1552 set k
[lindex
$children($vid) 0]
1553 if {[llength
$parents($view,$k)] == 1 &&
1554 (!$vdatemode($view) ||
1555 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1556 set a
$varcid($view,$k)
1561 set a
[newvarc
$view $id]
1563 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1566 if {![info exists varcid
($vid)]} {
1568 lappend varccommits
($view,$a) $id
1569 incr commitidx
($view)
1574 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1576 if {[llength
[lappend children
($vp) $id]] > 1 &&
1577 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1578 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1580 catch
{unset ordertok
}
1582 if {[info exists varcid
($view,$p)]} {
1583 fix_reversal
$p $a $view
1589 set scripts
[check_interest
$id $scripts]
1593 global numcommits hlview
1595 if {$view == $curview} {
1596 set numcommits
$commitidx($view)
1599 if {[info exists hlview
] && $view == $hlview} {
1600 # we never actually get here...
1603 foreach s
$scripts {
1610 proc chewcommits
{} {
1611 global curview hlview viewcomplete
1612 global pending_select
1615 if {$viewcomplete($curview)} {
1616 global commitidx varctok
1617 global numcommits startmsecs
1619 if {[info exists pending_select
]} {
1621 reset_pending_select
{}
1623 if {[commitinview
$pending_select $curview]} {
1624 selectline
[rowofcommit
$pending_select] 1
1626 set row
[first_real_row
]
1630 if {$commitidx($curview) > 0} {
1631 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1632 #puts "overall $ms ms for $numcommits commits"
1633 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1635 show_status
[mc
"No commits selected"]
1642 proc do_readcommit
{id
} {
1645 # Invoke git-log to handle automatic encoding conversion
1646 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1647 # Read the results using i18n.logoutputencoding
1648 fconfigure
$fd -translation lf
-eofchar {}
1649 if {$tclencoding != {}} {
1650 fconfigure
$fd -encoding $tclencoding
1652 set contents
[read $fd]
1654 # Remove the heading line
1655 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1660 proc readcommit
{id
} {
1661 if {[catch
{set contents
[do_readcommit
$id]}]} return
1662 parsecommit
$id $contents 1
1665 proc parsecommit
{id contents listed
} {
1675 set hdrend
[string first
"\n\n" $contents]
1677 # should never happen...
1678 set hdrend
[string length
$contents]
1680 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1681 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1682 foreach line
[split $header "\n"] {
1683 set line
[split $line " "]
1684 set tag
[lindex
$line 0]
1685 if {$tag == "author"} {
1686 set audate
[lrange
$line end-1 end
]
1687 set auname
[join [lrange
$line 1 end-2
] " "]
1688 } elseif
{$tag == "committer"} {
1689 set comdate
[lrange
$line end-1 end
]
1690 set comname
[join [lrange
$line 1 end-2
] " "]
1694 # take the first non-blank line of the comment as the headline
1695 set headline
[string trimleft
$comment]
1696 set i
[string first
"\n" $headline]
1698 set headline
[string range
$headline 0 $i]
1700 set headline
[string trimright
$headline]
1701 set i
[string first
"\r" $headline]
1703 set headline
[string trimright
[string range
$headline 0 $i]]
1706 # git log indents the comment by 4 spaces;
1707 # if we got this via git cat-file, add the indentation
1709 foreach line
[split $comment "\n"] {
1710 append newcomment
" "
1711 append newcomment
$line
1712 append newcomment
"\n"
1714 set comment
$newcomment
1716 set hasnote
[string first
"\nNotes:\n" $contents]
1718 # If there is diff output shown in the git-log stream, split it
1719 # out. But get rid of the empty line that always precedes the
1721 set i
[string first
"\n\ndiff" $comment]
1723 set diff [string range
$comment $i+1 end
]
1724 set comment
[string range
$comment 0 $i-1]
1726 set commitinfo
($id) [list
$headline $auname $audate \
1727 $comname $comdate $comment $hasnote $diff]
1730 proc getcommit
{id
} {
1731 global commitdata commitinfo
1733 if {[info exists commitdata
($id)]} {
1734 parsecommit
$id $commitdata($id) 1
1737 if {![info exists commitinfo
($id)]} {
1738 set commitinfo
($id) [list
[mc
"No commit information available"]]
1744 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1745 # and are present in the current view.
1746 # This is fairly slow...
1747 proc longid
{prefix
} {
1748 global varcid curview vshortids
1751 if {[string length
$prefix] >= 4} {
1752 set vshortid
$curview,[string range
$prefix 0 3]
1753 if {[info exists vshortids
($vshortid)]} {
1754 foreach id
$vshortids($vshortid) {
1755 if {[string match
"$prefix*" $id]} {
1756 if {[lsearch
-exact $ids $id] < 0} {
1758 if {[llength
$ids] >= 2} break
1764 foreach match
[array names varcid
"$curview,$prefix*"] {
1765 lappend ids
[lindex
[split $match ","] 1]
1766 if {[llength
$ids] >= 2} break
1773 global tagids idtags headids idheads tagobjid
1774 global otherrefids idotherrefs mainhead mainheadid
1775 global selecthead selectheadid
1778 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1781 set refd
[open
[list | git show-ref
-d] r
]
1782 while {[gets
$refd line
] >= 0} {
1783 if {[string index
$line 40] ne
" "} continue
1784 set id
[string range
$line 0 39]
1785 set ref
[string range
$line 41 end
]
1786 if {![string match
"refs/*" $ref]} continue
1787 set name
[string range
$ref 5 end
]
1788 if {[string match
"remotes/*" $name]} {
1789 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1790 set headids
($name) $id
1791 lappend idheads
($id) $name
1793 } elseif
{[string match
"heads/*" $name]} {
1794 set name
[string range
$name 6 end
]
1795 set headids
($name) $id
1796 lappend idheads
($id) $name
1797 } elseif
{[string match
"tags/*" $name]} {
1798 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1799 # which is what we want since the former is the commit ID
1800 set name
[string range
$name 5 end
]
1801 if {[string match
"*^{}" $name]} {
1802 set name
[string range
$name 0 end-3
]
1804 set tagobjid
($name) $id
1806 set tagids
($name) $id
1807 lappend idtags
($id) $name
1809 set otherrefids
($name) $id
1810 lappend idotherrefs
($id) $name
1817 set mainheadid
[exec git rev-parse HEAD
]
1818 set thehead
[exec git symbolic-ref HEAD
]
1819 if {[string match
"refs/heads/*" $thehead]} {
1820 set mainhead
[string range
$thehead 11 end
]
1824 if {$selecthead ne
{}} {
1826 set selectheadid
[exec git rev-parse
--verify $selecthead]
1831 # skip over fake commits
1832 proc first_real_row
{} {
1833 global nullid nullid2 numcommits
1835 for {set row
0} {$row < $numcommits} {incr row
} {
1836 set id
[commitonrow
$row]
1837 if {$id ne
$nullid && $id ne
$nullid2} {
1844 # update things for a head moved to a child of its previous location
1845 proc movehead
{id name
} {
1846 global headids idheads
1848 removehead
$headids($name) $name
1849 set headids
($name) $id
1850 lappend idheads
($id) $name
1853 # update things when a head has been removed
1854 proc removehead
{id name
} {
1855 global headids idheads
1857 if {$idheads($id) eq
$name} {
1860 set i
[lsearch
-exact $idheads($id) $name]
1862 set idheads
($id) [lreplace
$idheads($id) $i $i]
1865 unset headids
($name)
1868 proc ttk_toplevel
{w args
} {
1870 eval [linsert
$args 0 ::toplevel
$w]
1872 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1877 proc make_transient
{window origin
} {
1880 # In MacOS Tk 8.4 transient appears to work by setting
1881 # overrideredirect, which is utterly useless, since the
1882 # windows get no border, and are not even kept above
1884 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1886 wm transient
$window $origin
1888 # Windows fails to place transient windows normally, so
1889 # schedule a callback to center them on the parent.
1890 if {[tk windowingsystem
] eq
{win32
}} {
1891 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1895 proc show_error
{w top msg
{mc mc
}} {
1897 if {![info exists NS
]} {set NS
""}
1898 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1899 message
$w.m
-text $msg -justify center
-aspect 400
1900 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1901 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1902 pack
$w.ok
-side bottom
-fill x
1903 bind $top <Visibility
> "grab $top; focus $top"
1904 bind $top <Key-Return
> "destroy $top"
1905 bind $top <Key-space
> "destroy $top"
1906 bind $top <Key-Escape
> "destroy $top"
1910 proc error_popup
{msg
{owner .
}} {
1911 if {[tk windowingsystem
] eq
"win32"} {
1912 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1913 -parent $owner -message $msg
1917 make_transient
$w $owner
1918 show_error
$w $w $msg
1922 proc confirm_popup
{msg
{owner .
}} {
1923 global confirm_ok NS
1927 make_transient
$w $owner
1928 message
$w.m
-text $msg -justify center
-aspect 400
1929 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1930 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1931 pack
$w.ok
-side left
-fill x
1932 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1933 pack
$w.cancel
-side right
-fill x
1934 bind $w <Visibility
> "grab $w; focus $w"
1935 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1936 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1937 bind $w <Key-Escape
> "destroy $w"
1938 tk
::PlaceWindow
$w widget
$owner
1943 proc setoptions
{} {
1944 if {[tk windowingsystem
] ne
"win32"} {
1945 option add
*Panedwindow.showHandle
1 startupFile
1946 option add
*Panedwindow.sashRelief raised startupFile
1947 if {[tk windowingsystem
] ne
"aqua"} {
1948 option add
*Menu.font uifont startupFile
1951 option add
*Menu.TearOff
0 startupFile
1953 option add
*Button.font uifont startupFile
1954 option add
*Checkbutton.font uifont startupFile
1955 option add
*Radiobutton.font uifont startupFile
1956 option add
*Menubutton.font uifont startupFile
1957 option add
*Label.font uifont startupFile
1958 option add
*Message.font uifont startupFile
1959 option add
*Entry.font textfont startupFile
1960 option add
*Text.font textfont startupFile
1961 option add
*Labelframe.font uifont startupFile
1962 option add
*Spinbox.font textfont startupFile
1963 option add
*Listbox.font mainfont startupFile
1966 # Make a menu and submenus.
1967 # m is the window name for the menu, items is the list of menu items to add.
1968 # Each item is a list {mc label type description options...}
1969 # mc is ignored; it's so we can put mc there to alert xgettext
1970 # label is the string that appears in the menu
1971 # type is cascade, command or radiobutton (should add checkbutton)
1972 # description depends on type; it's the sublist for cascade, the
1973 # command to invoke for command, or {variable value} for radiobutton
1974 proc makemenu
{m items
} {
1976 if {[tk windowingsystem
] eq
{aqua
}} {
1982 set name
[mc
[lindex
$i 1]]
1983 set type [lindex
$i 2]
1984 set thing
[lindex
$i 3]
1985 set params
[list
$type]
1987 set u
[string first
"&" [string map
{&& x
} $name]]
1988 lappend params
-label [string map
{&& & & {}} $name]
1990 lappend params
-underline $u
1995 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1996 lappend params
-menu $m.
$submenu
1999 lappend params
-command $thing
2002 lappend params
-variable [lindex
$thing 0] \
2003 -value [lindex
$thing 1]
2006 set tail [lrange
$i 4 end
]
2007 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2008 eval $m add
$params $tail
2009 if {$type eq
"cascade"} {
2010 makemenu
$m.
$submenu $thing
2015 # translate string and remove ampersands
2017 return [string map
{&& & & {}} [mc
$str]]
2020 proc cleardropsel
{w
} {
2023 proc makedroplist
{w varname args
} {
2027 foreach label
$args {
2028 set cx
[string length
$label]
2029 if {$cx > $width} {set width
$cx}
2031 set gm
[ttk
::combobox
$w -width $width -state readonly\
2032 -textvariable $varname -values $args \
2033 -exportselection false
]
2034 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2036 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2041 proc makewindow {} {
2042 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2044 global findtype findtypemenu findloc findstring fstring geometry
2045 global entries sha1entry sha1string sha1but
2046 global diffcontextstring diffcontext
2048 global maincursor textcursor curtextcursor
2049 global rowctxmenu fakerowmenu mergemax wrapcomment
2050 global highlight_files gdttype
2051 global searchstring sstring
2052 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2053 global uifgcolor uifgdisabledcolor
2054 global filesepbgcolor filesepfgcolor
2055 global mergecolors foundbgcolor currentsearchhitbgcolor
2056 global headctxmenu progresscanv progressitem progresscoords statusw
2057 global fprogitem fprogcoord lastprogupdate progupdatepending
2058 global rprogitem rprogcoord rownumsel numcommits
2059 global have_tk85 use_ttk NS
2063 # The "mc" arguments here are purely so that xgettext
2064 # sees the following string as needing to be translated
2067 {mc "Update" command updatecommits -accelerator F5}
2068 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2069 {mc "Reread references" command rereadrefs}
2070 {mc "List references" command showrefs -accelerator F2}
2072 {mc "Start git gui" command {exec git gui &}}
2074 {mc "Quit" command doquit -accelerator Meta1-Q}
2078 {mc "Preferences" command doprefs}
2082 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2083 {mc "Edit view..." command editview -state disabled -accelerator F4}
2084 {mc "Delete view" command delview -state disabled}
2086 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2088 if {[tk windowingsystem] ne "aqua"} {
2091 {mc "About gitk" command about}
2092 {mc "Key bindings" command keys}
2094 set bar [list $file $edit $view $help]
2096 proc ::tk::mac::ShowPreferences {} {doprefs}
2097 proc ::tk::mac::Quit {} {doquit}
2098 lset file end [lreplace [lindex $file end] end-1 end]
2100 xx "Apple" cascade {
2101 {mc "About gitk" command about}
2106 {mc "Key bindings" command keys}
2108 set bar [list $apple $file $view $help]
2111 . configure -menu .bar
2114 # cover the non-themed toplevel with a themed frame.
2115 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2118 # the gui has upper and lower half, parts of a paned window.
2119 ${NS}::panedwindow .ctop -orient vertical
2121 # possibly use assumed geometry
2122 if {![info exists geometry(pwsash0)]} {
2123 set geometry(topheight) [expr {15 * $linespc}]
2124 set geometry(topwidth) [expr {80 * $charspc}]
2125 set geometry(botheight) [expr {15 * $linespc}]
2126 set geometry(botwidth) [expr {50 * $charspc}]
2127 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2128 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2131 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2132 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2133 ${NS}::frame .tf.histframe
2134 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2136 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2139 # create three canvases
2140 set cscroll .tf.histframe.csb
2141 set canv .tf.histframe.pwclist.canv
2143 -selectbackground $selectbgcolor \
2144 -background $bgcolor -bd 0 \
2145 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2146 .tf.histframe.pwclist add $canv
2147 set canv2 .tf.histframe.pwclist.canv2
2149 -selectbackground $selectbgcolor \
2150 -background $bgcolor -bd 0 -yscrollincr $linespc
2151 .tf.histframe.pwclist add $canv2
2152 set canv3 .tf.histframe.pwclist.canv3
2154 -selectbackground $selectbgcolor \
2155 -background $bgcolor -bd 0 -yscrollincr $linespc
2156 .tf.histframe.pwclist add $canv3
2158 bind .tf.histframe.pwclist <Map> {
2160 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2161 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2164 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2165 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2168 # a scroll bar to rule them
2169 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2170 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2171 pack $cscroll -side right -fill y
2172 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2173 lappend bglist $canv $canv2 $canv3
2174 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2176 # we have two button bars at bottom of top frame. Bar 1
2177 ${NS}::frame .tf.bar
2178 ${NS}::frame .tf.lbar -height 15
2180 set sha1entry .tf.bar.sha1
2181 set entries $sha1entry
2182 set sha1but .tf.bar.sha1label
2183 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2184 -command gotocommit -width 8
2185 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2186 pack .tf.bar.sha1label -side left
2187 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2188 trace add variable sha1string write sha1change
2189 pack $sha1entry -side left -pady 2
2192 #define left_width 16
2193 #define left_height 16
2194 static unsigned char left_bits[] = {
2195 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2196 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2197 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2200 #define right_width 16
2201 #define right_height 16
2202 static unsigned char right_bits[] = {
2203 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2204 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2205 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2207 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2208 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2209 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2210 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2212 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2214 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2216 .tf.bar.leftbut configure -image bm-left
2218 pack .tf.bar.leftbut -side left -fill y
2219 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2221 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2223 .tf.bar.rightbut configure -image bm-right
2225 pack .tf.bar.rightbut -side left -fill y
2227 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2229 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2230 -relief sunken -anchor e
2231 ${NS}::label .tf.bar.rowlabel2 -text "/"
2232 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2233 -relief sunken -anchor e
2234 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2237 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2240 trace add variable selectedline write selectedline_change
2242 # Status label and progress bar
2243 set statusw .tf.bar.status
2244 ${NS}::label $statusw -width 15 -relief sunken
2245 pack $statusw -side left -padx 5
2247 set progresscanv [ttk::progressbar .tf.bar.progress]
2249 set h [expr {[font metrics uifont -linespace] + 2}]
2250 set progresscanv .tf.bar.progress
2251 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2252 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2253 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2254 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2256 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2257 set progresscoords {0 0}
2260 bind $progresscanv <Configure> adjustprogress
2261 set lastprogupdate [clock clicks -milliseconds]
2262 set progupdatepending 0
2264 # build up the bottom bar of upper window
2265 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2266 ${NS}::button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
2267 ${NS}::button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
2268 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2269 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2271 set gdttype [mc "containing:"]
2272 set gm [makedroplist .tf.lbar.gdttype gdttype \
2273 [mc "containing:"] \
2274 [mc "touching paths:"] \
2275 [mc "adding/removing string:"] \
2276 [mc "changing lines matching:"]]
2277 trace add variable gdttype write gdttype_change
2278 pack .tf.lbar.gdttype -side left -fill y
2281 set fstring .tf.lbar.findstring
2282 lappend entries $fstring
2283 ${NS}::entry $fstring -width 30 -textvariable findstring
2284 trace add variable findstring write find_change
2285 set findtype [mc "Exact"]
2286 set findtypemenu [makedroplist .tf.lbar.findtype \
2287 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2288 trace add variable findtype write findcom_change
2289 set findloc [mc "All fields"]
2290 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2291 [mc "Comments"] [mc "Author"] [mc "Committer"]
2292 trace add variable findloc write find_change
2293 pack .tf.lbar.findloc -side right
2294 pack .tf.lbar.findtype -side right
2295 pack $fstring -side left -expand 1 -fill x
2297 # Finish putting the upper half of the viewer together
2298 pack .tf.lbar -in .tf -side bottom -fill x
2299 pack .tf.bar -in .tf -side bottom -fill x
2300 pack .tf.histframe -fill both -side top -expand 1
2303 .ctop paneconfigure .tf -height $geometry(topheight)
2304 .ctop paneconfigure .tf -width $geometry(topwidth)
2307 # now build up the bottom
2308 ${NS}::panedwindow .pwbottom -orient horizontal
2310 # lower left, a text box over search bar, scroll bar to the right
2311 # if we know window height, then that will set the lower text height, otherwise
2312 # we set lower text height which will drive window height
2313 if {[info exists geometry(main)]} {
2314 ${NS}::frame .bleft -width $geometry(botwidth)
2316 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2318 ${NS}::frame .bleft.top
2319 ${NS}::frame .bleft.mid
2320 ${NS}::frame .bleft.bottom
2322 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2323 pack .bleft.top.search -side left -padx 5
2324 set sstring .bleft.top.sstring
2326 ${NS}::entry $sstring -width 20 -textvariable searchstring
2327 lappend entries $sstring
2328 trace add variable searchstring write incrsearch
2329 pack $sstring -side left -expand 1 -fill x
2330 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2331 -command changediffdisp -variable diffelide -value {0 0}
2332 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2333 -command changediffdisp -variable diffelide -value {0 1}
2334 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2335 -command changediffdisp -variable diffelide -value {1 0}
2336 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2337 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2338 spinbox .bleft.mid.diffcontext -width 5 \
2339 -from 0 -increment 1 -to 10000000 \
2340 -validate all -validatecommand "diffcontextvalidate %P" \
2341 -textvariable diffcontextstring
2342 .bleft.mid.diffcontext set $diffcontext
2343 trace add variable diffcontextstring write diffcontextchange
2344 lappend entries .bleft.mid.diffcontext
2345 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2346 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2347 -command changeignorespace -variable ignorespace
2348 pack .bleft.mid.ignspace -side left -padx 5
2350 set worddiff [mc "Line diff"]
2351 if {[package vcompare $git_version "1.7.2"] >= 0} {
2352 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2353 [mc "Markup words"] [mc "Color words"]
2354 trace add variable worddiff write changeworddiff
2355 pack .bleft.mid.worddiff -side left -padx 5
2358 set ctext .bleft.bottom.ctext
2359 text $ctext -background $bgcolor -foreground $fgcolor \
2360 -state disabled -font textfont \
2361 -yscrollcommand scrolltext -wrap none \
2362 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2364 $ctext conf -tabstyle wordprocessor
2366 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2367 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2368 pack .bleft.top -side top -fill x
2369 pack .bleft.mid -side top -fill x
2370 grid $ctext .bleft.bottom.sb -sticky nsew
2371 grid .bleft.bottom.sbhorizontal -sticky ew
2372 grid columnconfigure .bleft.bottom 0 -weight 1
2373 grid rowconfigure .bleft.bottom 0 -weight 1
2374 grid rowconfigure .bleft.bottom 1 -weight 0
2375 pack .bleft.bottom -side top -fill both -expand 1
2376 lappend bglist $ctext
2377 lappend fglist $ctext
2379 $ctext tag conf comment -wrap $wrapcomment
2380 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2381 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2382 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2383 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2384 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2385 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2386 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2387 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2388 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2389 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2390 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2391 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2392 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2393 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2394 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2395 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2396 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2397 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2398 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2399 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2400 $ctext tag conf mmax -fore darkgrey
2402 $ctext tag conf mresult -font textfontbold
2403 $ctext tag conf msep -font textfontbold
2404 $ctext tag conf found -back $foundbgcolor
2405 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2406 $ctext tag conf wwrap -wrap word
2407 $ctext tag conf bold -font textfontbold
2409 .pwbottom add .bleft
2411 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2415 ${NS}::frame .bright
2416 ${NS}::frame .bright.mode
2417 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2418 -command reselectline -variable cmitmode -value "patch"
2419 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2420 -command reselectline -variable cmitmode -value "tree"
2421 grid .bright.mode.patch .bright.mode.tree -sticky ew
2422 pack .bright.mode -side top -fill x
2423 set cflist .bright.cfiles
2424 set indent [font measure mainfont "nn"]
2426 -selectbackground $selectbgcolor \
2427 -background $bgcolor -foreground $fgcolor \
2429 -tabs [list $indent [expr {2 * $indent}]] \
2430 -yscrollcommand ".bright.sb set" \
2431 -cursor [. cget -cursor] \
2432 -spacing1 1 -spacing3 1
2433 lappend bglist $cflist
2434 lappend fglist $cflist
2435 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2436 pack .bright.sb -side right -fill y
2437 pack $cflist -side left -fill both -expand 1
2438 $cflist tag configure highlight \
2439 -background [$cflist cget -selectbackground]
2440 $cflist tag configure bold -font mainfontbold
2442 .pwbottom add .bright
2445 # restore window width & height if known
2446 if {[info exists geometry(main)]} {
2447 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2448 if {$w > [winfo screenwidth .]} {
2449 set w [winfo screenwidth .]
2451 if {$h > [winfo screenheight .]} {
2452 set h [winfo screenheight .]
2454 wm geometry . "${w}x$h"
2458 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2459 wm state . $geometry(state)
2462 if {[tk windowingsystem] eq {aqua}} {
2473 %W sashpos 0 $::geometry(topheight)
2475 bind .pwbottom <Map> {
2477 %W sashpos 0 $::geometry(botwidth)
2481 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2482 pack .ctop -fill both -expand 1
2483 bindall <1> {selcanvline %W %x %y}
2484 #bindall <B1-Motion> {selcanvline %W %x %y}
2485 if {[tk windowingsystem] == "win32"} {
2486 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2487 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2489 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2490 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2491 if {[tk windowingsystem] eq "aqua"} {
2492 bindall <MouseWheel> {
2493 set delta [expr {- (%D)}]
2494 allcanvs yview scroll $delta units
2496 bindall <Shift-MouseWheel> {
2497 set delta [expr {- (%D)}]
2498 $canv xview scroll $delta units
2502 bindall <$::BM> "canvscan mark %W %x %y"
2503 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2504 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2505 bind . <$M1B-Key-w> doquit
2506 bindkey <Home> selfirstline
2507 bindkey <End> sellastline
2508 bind . <Key-Up> "selnextline -1"
2509 bind . <Key-Down> "selnextline 1"
2510 bind . <Shift-Key-Up> "dofind -1 0"
2511 bind . <Shift-Key-Down> "dofind 1 0"
2512 bindkey <Key-Right> "goforw"
2513 bindkey <Key-Left> "goback"
2514 bind . <Key-Prior> "selnextpage -1"
2515 bind . <Key-Next> "selnextpage 1"
2516 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2517 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2518 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2519 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2520 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2521 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2522 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2523 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2524 bindkey <Key-space> "$ctext yview scroll 1 pages"
2525 bindkey p "selnextline -1"
2526 bindkey n "selnextline 1"
2529 bindkey k "selnextline -1"
2530 bindkey j "selnextline 1"
2534 bindkey d "$ctext yview scroll 18 units"
2535 bindkey u "$ctext yview scroll -18 units"
2536 bindkey / {focus $fstring}
2537 bindkey <Key-KP_Divide> {focus $fstring}
2538 bindkey <Key-Return> {dofind 1 1}
2539 bindkey ? {dofind -1 1}
2541 bind . <F5> updatecommits
2542 bindmodfunctionkey Shift 5 reloadcommits
2543 bind . <F2> showrefs
2544 bindmodfunctionkey Shift 4 {newview 0}
2545 bind . <F4> edit_or_newview
2546 bind . <$M1B-q> doquit
2547 bind . <$M1B-f> {dofind 1 1}
2548 bind . <$M1B-g> {dofind 1 0}
2549 bind . <$M1B-r> dosearchback
2550 bind . <$M1B-s> dosearch
2551 bind . <$M1B-equal> {incrfont 1}
2552 bind . <$M1B-plus> {incrfont 1}
2553 bind . <$M1B-KP_Add> {incrfont 1}
2554 bind . <$M1B-minus> {incrfont -1}
2555 bind . <$M1B-KP_Subtract> {incrfont -1}
2556 wm protocol . WM_DELETE_WINDOW doquit
2557 bind . <Destroy> {stop_backends}
2558 bind . <Button-1> "click %W"
2559 bind $fstring <Key-Return> {dofind 1 1}
2560 bind $sha1entry <Key-Return> {gotocommit; break}
2561 bind $sha1entry <<PasteSelection>> clearsha1
2562 bind $cflist <1> {sel_flist %W %x %y; break}
2563 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2564 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2566 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2567 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2568 bind $ctext <Button-1> {focus %W}
2569 bind $ctext <<Selection>> rehighlight_search_results
2571 set maincursor [. cget -cursor]
2572 set textcursor [$ctext cget -cursor]
2573 set curtextcursor $textcursor
2575 set rowctxmenu .rowctxmenu
2576 makemenu $rowctxmenu {
2577 {mc "Diff this -> selected" command {diffvssel 0}}
2578 {mc "Diff selected -> this" command {diffvssel 1}}
2579 {mc "Make patch" command mkpatch}
2580 {mc "Create tag" command mktag}
2581 {mc "Write commit to file" command writecommit}
2582 {mc "Create new branch" command mkbranch}
2583 {mc "Cherry-pick this commit" command cherrypick}
2584 {mc "Reset HEAD branch to here" command resethead}
2585 {mc "Mark this commit" command markhere}
2586 {mc "Return to mark" command gotomark}
2587 {mc "Find descendant of this and mark" command find_common_desc}
2588 {mc "Compare with marked commit" command compare_commits}
2589 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2590 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2591 {mc "Revert this commit" command revert}
2593 $rowctxmenu configure -tearoff 0
2595 set fakerowmenu .fakerowmenu
2596 makemenu $fakerowmenu {
2597 {mc "Diff this -> selected" command {diffvssel 0}}
2598 {mc "Diff selected -> this" command {diffvssel 1}}
2599 {mc "Make patch" command mkpatch}
2600 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2601 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2603 $fakerowmenu configure -tearoff 0
2605 set headctxmenu .headctxmenu
2606 makemenu $headctxmenu {
2607 {mc "Check out this branch" command cobranch}
2608 {mc "Remove this branch" command rmbranch}
2610 $headctxmenu configure -tearoff 0
2613 set flist_menu .flistctxmenu
2614 makemenu $flist_menu {
2615 {mc "Highlight this too" command {flist_hl 0}}
2616 {mc "Highlight this only" command {flist_hl 1}}
2617 {mc "External diff" command {external_diff}}
2618 {mc "Blame parent commit" command {external_blame 1}}
2620 $flist_menu configure -tearoff 0
2623 set diff_menu .diffctxmenu
2624 makemenu $diff_menu {
2625 {mc "Show origin of this line" command show_line_source}
2626 {mc "Run git gui blame on this line" command {external_blame_diff}}
2628 $diff_menu configure -tearoff 0
2631 # Windows sends all mouse wheel events to the current focused window, not
2632 # the one where the mouse hovers, so bind those events here and redirect
2633 # to the correct window
2634 proc windows_mousewheel_redirector {W X Y D} {
2635 global canv canv2 canv3
2636 set w [winfo containing -displayof $W $X $Y]
2638 set u [expr {$D < 0 ? 5 : -5}]
2639 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2640 allcanvs yview scroll $u units
2643 $w yview scroll $u units
2649 # Update row number label when selectedline changes
2650 proc selectedline_change {n1 n2 op} {
2651 global selectedline rownumsel
2653 if {$selectedline eq {}} {
2656 set rownumsel [expr {$selectedline + 1}]
2660 # mouse-2 makes all windows scan vertically, but only the one
2661 # the cursor is in scans horizontally
2662 proc canvscan {op w x y} {
2663 global canv canv2 canv3
2664 foreach c [list $canv $canv2 $canv3] {
2673 proc scrollcanv {cscroll f0 f1} {
2674 $cscroll set $f0 $f1
2679 # when we make a key binding for the toplevel, make sure
2680 # it doesn't get triggered when that key is pressed in the
2681 # find string entry widget.
2682 proc bindkey {ev script} {
2685 set escript [bind Entry $ev]
2686 if {$escript == {}} {
2687 set escript [bind Entry <Key>]
2689 foreach e $entries {
2690 bind $e $ev "$escript; break"
2694 proc bindmodfunctionkey {mod n script} {
2695 bind . <$mod-F$n> $script
2696 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2699 # set the focus back to the toplevel for any click outside
2702 global ctext entries
2703 foreach e [concat $entries $ctext] {
2704 if {$w == $e} return
2709 # Adjust the progress bar for a change in requested extent or canvas size
2710 proc adjustprogress {} {
2711 global progresscanv progressitem progresscoords
2712 global fprogitem fprogcoord lastprogupdate progupdatepending
2713 global rprogitem rprogcoord use_ttk
2716 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2720 set w [expr {[winfo width $progresscanv] - 4}]
2721 set x0 [expr {$w * [lindex $progresscoords 0]}]
2722 set x1 [expr {$w * [lindex $progresscoords 1]}]
2723 set h [winfo height $progresscanv]
2724 $progresscanv coords $progressitem $x0 0 $x1 $h
2725 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2726 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2727 set now [clock clicks -milliseconds]
2728 if {$now >= $lastprogupdate + 100} {
2729 set progupdatepending 0
2731 } elseif {!$progupdatepending} {
2732 set progupdatepending 1
2733 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2737 proc doprogupdate {} {
2738 global lastprogupdate progupdatepending
2740 if {$progupdatepending} {
2741 set progupdatepending 0
2742 set lastprogupdate [clock clicks -milliseconds]
2747 proc savestuff {w} {
2748 global canv canv2 canv3 mainfont textfont uifont tabstop
2749 global stuffsaved findmergefiles maxgraphpct
2750 global maxwidth showneartags showlocalchanges
2751 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2752 global cmitmode wrapcomment datetimeformat limitdiffs
2753 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2754 global uifgcolor uifgdisabledcolor
2755 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2756 global tagbgcolor tagfgcolor tagoutlinecolor
2757 global reflinecolor filesepbgcolor filesepfgcolor
2758 global mergecolors foundbgcolor currentsearchhitbgcolor
2759 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2760 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2761 global linkfgcolor circleoutlinecolor
2762 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2763 global hideremotes want_ttk maxrefs
2765 if {$stuffsaved} return
2766 if {![winfo viewable .]} return
2768 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2769 set f [open "~/.gitk-new" w]
2770 if {$::tcl_platform(platform) eq {windows}} {
2771 file attributes "~/.gitk-new" -hidden true
2773 puts $f [list set mainfont $mainfont]
2774 puts $f [list set textfont $textfont]
2775 puts $f [list set uifont $uifont]
2776 puts $f [list set tabstop $tabstop]
2777 puts $f [list set findmergefiles $findmergefiles]
2778 puts $f [list set maxgraphpct $maxgraphpct]
2779 puts $f [list set maxwidth $maxwidth]
2780 puts $f [list set cmitmode $cmitmode]
2781 puts $f [list set wrapcomment $wrapcomment]
2782 puts $f [list set autoselect $autoselect]
2783 puts $f [list set autosellen $autosellen]
2784 puts $f [list set showneartags $showneartags]
2785 puts $f [list set maxrefs $maxrefs]
2786 puts $f [list set hideremotes $hideremotes]
2787 puts $f [list set showlocalchanges $showlocalchanges]
2788 puts $f [list set datetimeformat $datetimeformat]
2789 puts $f [list set limitdiffs $limitdiffs]
2790 puts $f [list set uicolor $uicolor]
2791 puts $f [list set want_ttk $want_ttk]
2792 puts $f [list set bgcolor $bgcolor]
2793 puts $f [list set fgcolor $fgcolor]
2794 puts $f [list set uifgcolor $uifgcolor]
2795 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2796 puts $f [list set colors $colors]
2797 puts $f [list set diffcolors $diffcolors]
2798 puts $f [list set mergecolors $mergecolors]
2799 puts $f [list set markbgcolor $markbgcolor]
2800 puts $f [list set diffcontext $diffcontext]
2801 puts $f [list set selectbgcolor $selectbgcolor]
2802 puts $f [list set foundbgcolor $foundbgcolor]
2803 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2804 puts $f [list set extdifftool $extdifftool]
2805 puts $f [list set perfile_attrs $perfile_attrs]
2806 puts $f [list set headbgcolor $headbgcolor]
2807 puts $f [list set headfgcolor $headfgcolor]
2808 puts $f [list set headoutlinecolor $headoutlinecolor]
2809 puts $f [list set remotebgcolor $remotebgcolor]
2810 puts $f [list set tagbgcolor $tagbgcolor]
2811 puts $f [list set tagfgcolor $tagfgcolor]
2812 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2813 puts $f [list set reflinecolor $reflinecolor]
2814 puts $f [list set filesepbgcolor $filesepbgcolor]
2815 puts $f [list set filesepfgcolor $filesepfgcolor]
2816 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2817 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2818 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2819 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2820 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2821 puts $f [list set indexcirclecolor $indexcirclecolor]
2822 puts $f [list set circlecolors $circlecolors]
2823 puts $f [list set linkfgcolor $linkfgcolor]
2824 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2826 puts $f "set geometry(main) [wm geometry .]"
2827 puts $f "set geometry(state) [wm state .]"
2828 puts $f "set geometry(topwidth) [winfo width .tf]"
2829 puts $f "set geometry(topheight) [winfo height .tf]"
2831 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2832 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2834 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2835 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2837 puts $f "set geometry(botwidth) [winfo width .bleft]"
2838 puts $f "set geometry(botheight) [winfo height .bleft]"
2840 puts -nonewline $f "set permviews {"
2841 for {set v 0} {$v < $nextviewnum} {incr v} {
2842 if {$viewperm($v)} {
2843 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2848 file rename -force "~/.gitk-new" "~/.gitk"
2853 proc resizeclistpanes {win w} {
2854 global oldwidth use_ttk
2855 if {[info exists oldwidth($win)]} {
2857 set s0 [$win sashpos 0]
2858 set s1 [$win sashpos 1]
2860 set s0 [$win sash coord 0]
2861 set s1 [$win sash coord 1]
2864 set sash0 [expr {int($w/2 - 2)}]
2865 set sash1 [expr {int($w*5/6 - 2)}]
2867 set factor [expr {1.0 * $w / $oldwidth($win)}]
2868 set sash0 [expr {int($factor * [lindex $s0 0])}]
2869 set sash1 [expr {int($factor * [lindex $s1 0])}]
2873 if {$sash1 < $sash0 + 20} {
2874 set sash1 [expr {$sash0 + 20}]
2876 if {$sash1 > $w - 10} {
2877 set sash1 [expr {$w - 10}]
2878 if {$sash0 > $sash1 - 20} {
2879 set sash0 [expr {$sash1 - 20}]
2884 $win sashpos 0 $sash0
2885 $win sashpos 1 $sash1
2887 $win sash place 0 $sash0 [lindex $s0 1]
2888 $win sash place 1 $sash1 [lindex $s1 1]
2891 set oldwidth($win) $w
2894 proc resizecdetpanes {win w} {
2895 global oldwidth use_ttk
2896 if {[info exists oldwidth($win)]} {
2898 set s0 [$win sashpos 0]
2900 set s0 [$win sash coord 0]
2903 set sash0 [expr {int($w*3/4 - 2)}]
2905 set factor [expr {1.0 * $w / $oldwidth($win)}]
2906 set sash0 [expr {int($factor * [lindex $s0 0])}]
2910 if {$sash0 > $w - 15} {
2911 set sash0 [expr {$w - 15}]
2915 $win sashpos 0 $sash0
2917 $win sash place 0 $sash0 [lindex $s0 1]
2920 set oldwidth($win) $w
2923 proc allcanvs args {
2924 global canv canv2 canv3
2930 proc bindall {event action} {
2931 global canv canv2 canv3
2932 bind $canv $event $action
2933 bind $canv2 $event $action
2934 bind $canv3 $event $action
2940 if {[winfo exists $w]} {
2945 wm title $w [mc "About gitk"]
2947 message $w.m -text [mc "
2948 Gitk - a commit viewer for git
2950 Copyright \u00a9 2005-2011 Paul Mackerras
2952 Use and redistribute under the terms of the GNU General Public License"] \
2953 -justify center -aspect 400 -border 2 -bg white -relief groove
2954 pack $w.m -side top -fill x -padx 2 -pady 2
2955 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2956 pack $w.ok -side bottom
2957 bind $w <Visibility> "focus $w.ok"
2958 bind $w <Key-Escape> "destroy $w"
2959 bind $w <Key-Return> "destroy $w"
2960 tk::PlaceWindow $w widget .
2966 if {[winfo exists $w]} {
2970 if {[tk windowingsystem] eq {aqua}} {
2976 wm title $w [mc "Gitk key bindings"]
2978 message $w.m -text "
2979 [mc "Gitk key bindings:"]
2981 [mc "<%s-Q> Quit" $M1T]
2982 [mc "<%s-W> Close window" $M1T]
2983 [mc "<Home> Move to first commit"]
2984 [mc "<End> Move to last commit"]
2985 [mc "<Up>, p, k Move up one commit"]
2986 [mc "<Down>, n, j Move down one commit"]
2987 [mc "<Left>, z, h Go back in history list"]
2988 [mc "<Right>, x, l Go forward in history list"]
2989 [mc "<PageUp> Move up one page in commit list"]
2990 [mc "<PageDown> Move down one page in commit list"]
2991 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2992 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2993 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2994 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2995 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2996 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2997 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2998 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2999 [mc "<Delete>, b Scroll diff view up one page"]
3000 [mc "<Backspace> Scroll diff view up one page"]
3001 [mc "<Space> Scroll diff view down one page"]
3002 [mc "u Scroll diff view up 18 lines"]
3003 [mc "d Scroll diff view down 18 lines"]
3004 [mc "<%s-F> Find" $M1T]
3005 [mc "<%s-G> Move to next find hit" $M1T]
3006 [mc "<Return> Move to next find hit"]
3007 [mc "/ Focus the search box"]
3008 [mc "? Move to previous find hit"]
3009 [mc "f Scroll diff view to next file"]
3010 [mc "<%s-S> Search for next hit in diff view" $M1T]
3011 [mc "<%s-R> Search for previous hit in diff view" $M1T]
3012 [mc "<%s-KP+> Increase font size" $M1T]
3013 [mc "<%s-plus> Increase font size" $M1T]
3014 [mc "<%s-KP-> Decrease font size" $M1T]
3015 [mc "<%s-minus> Decrease font size" $M1T]
3018 -justify left -bg white -border 2 -relief groove
3019 pack $w.m -side top -fill both -padx 2 -pady 2
3020 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3021 bind $w <Key-Escape> [list destroy $w]
3022 pack $w.ok -side bottom
3023 bind $w <Visibility> "focus $w.ok"
3024 bind $w <Key-Escape> "destroy $w"
3025 bind $w <Key-Return> "destroy $w"
3028 # Procedures for manipulating the file list window at the
3029 # bottom right of the overall window.
3031 proc treeview {w l openlevs} {
3032 global treecontents treediropen treeheight treeparent treeindex
3042 set treecontents() {}
3043 $w conf -state normal
3045 while {[string range $f 0 $prefixend] ne $prefix} {
3046 if {$lev <= $openlevs} {
3047 $w mark set e:$treeindex($prefix) "end -1c"
3048 $w mark gravity e:$treeindex($prefix) left
3050 set treeheight($prefix) $ht
3051 incr ht [lindex $htstack end]
3052 set htstack [lreplace $htstack end end]
3053 set prefixend [lindex $prefendstack end]
3054 set prefendstack [lreplace $prefendstack end end]
3055 set prefix [string range $prefix 0 $prefixend]
3058 set tail [string range $f [expr {$prefixend+1}] end]
3059 while {[set slash [string first "/" $tail]] >= 0} {
3062 lappend prefendstack $prefixend
3063 incr prefixend [expr {$slash + 1}]
3064 set d [string range $tail 0 $slash]
3065 lappend treecontents($prefix) $d
3066 set oldprefix $prefix
3068 set treecontents($prefix) {}
3069 set treeindex($prefix) [incr ix]
3070 set treeparent($prefix) $oldprefix
3071 set tail [string range $tail [expr {$slash+1}] end]
3072 if {$lev <= $openlevs} {
3074 set treediropen($prefix) [expr {$lev < $openlevs}]
3075 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3076 $w mark set d:$ix "end -1c"
3077 $w mark gravity d:$ix left
3079 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3081 $w image create end -align center -image $bm -padx 1 \
3083 $w insert end $d [highlight_tag $prefix]
3084 $w mark set s:$ix "end -1c"
3085 $w mark gravity s:$ix left
3090 if {$lev <= $openlevs} {
3093 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3095 $w insert end $tail [highlight_tag $f]
3097 lappend treecontents($prefix) $tail
3100 while {$htstack ne {}} {
3101 set treeheight($prefix) $ht
3102 incr ht [lindex $htstack end]
3103 set htstack [lreplace $htstack end end]
3104 set prefixend [lindex $prefendstack end]
3105 set prefendstack [lreplace $prefendstack end end]
3106 set prefix [string range $prefix 0 $prefixend]
3108 $w conf -state disabled
3111 proc linetoelt {l} {
3112 global treeheight treecontents
3117 foreach e $treecontents($prefix) {
3122 if {[string index $e end] eq "/"} {
3123 set n $treeheight($prefix$e)
3135 proc highlight_tree {y prefix} {
3136 global treeheight treecontents cflist
3138 foreach e $treecontents($prefix) {
3140 if {[highlight_tag $path] ne {}} {
3141 $cflist tag add bold $y.0 "$y.0 lineend"
3144 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3145 set y [highlight_tree $y $path]
3151 proc treeclosedir {w dir} {
3152 global treediropen treeheight treeparent treeindex
3154 set ix $treeindex($dir)
3155 $w conf -state normal
3156 $w delete s:$ix e:$ix
3157 set treediropen($dir) 0
3158 $w image configure a:$ix -image tri-rt
3159 $w conf -state disabled
3160 set n [expr {1 - $treeheight($dir)}]
3161 while {$dir ne {}} {
3162 incr treeheight($dir) $n
3163 set dir $treeparent($dir)
3167 proc treeopendir {w dir} {
3168 global treediropen treeheight treeparent treecontents treeindex
3170 set ix $treeindex($dir)
3171 $w conf -state normal
3172 $w image configure a:$ix -image tri-dn
3173 $w mark set e:$ix s:$ix
3174 $w mark gravity e:$ix right
3177 set n [llength $treecontents($dir)]
3178 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3181 incr treeheight($x) $n
3183 foreach e $treecontents($dir) {
3185 if {[string index $e end] eq "/"} {
3186 set iy $treeindex($de)
3187 $w mark set d:$iy e:$ix
3188 $w mark gravity d:$iy left
3189 $w insert e:$ix $str
3190 set treediropen($de) 0
3191 $w image create e:$ix -align center -image tri-rt -padx 1 \
3193 $w insert e:$ix $e [highlight_tag $de]
3194 $w mark set s:$iy e:$ix
3195 $w mark gravity s:$iy left
3196 set treeheight($de) 1
3198 $w insert e:$ix $str
3199 $w insert e:$ix $e [highlight_tag $de]
3202 $w mark gravity e:$ix right
3203 $w conf -state disabled
3204 set treediropen($dir) 1
3205 set top [lindex [split [$w index @0,0] .] 0]
3206 set ht [$w cget -height]
3207 set l [lindex [split [$w index s:$ix] .] 0]
3210 } elseif {$l + $n + 1 > $top + $ht} {
3211 set top [expr {$l + $n + 2 - $ht}]
3219 proc treeclick {w x y} {
3220 global treediropen cmitmode ctext cflist cflist_top
3222 if {$cmitmode ne "tree"} return
3223 if {![info exists cflist_top]} return
3224 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3225 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3226 $cflist tag add highlight $l.0 "$l.0 lineend"
3232 set e [linetoelt $l]
3233 if {[string index $e end] ne "/"} {
3235 } elseif {$treediropen($e)} {
3242 proc setfilelist {id} {
3243 global treefilelist cflist jump_to_here
3245 treeview $cflist $treefilelist($id) 0
3246 if {$jump_to_here ne {}} {
3247 set f [lindex $jump_to_here 0]
3248 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3254 image create bitmap tri-rt -background black -foreground blue -data {
3255 #define tri-rt_width 13
3256 #define tri-rt_height 13
3257 static unsigned char tri-rt_bits[] = {
3258 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3259 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3262 #define tri-rt-mask_width 13
3263 #define tri-rt-mask_height 13
3264 static unsigned char tri-rt-mask_bits[] = {
3265 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3266 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3269 image create bitmap tri-dn -background black -foreground blue -data {
3270 #define tri-dn_width 13
3271 #define tri-dn_height 13
3272 static unsigned char tri-dn_bits[] = {
3273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3274 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3277 #define tri-dn-mask_width 13
3278 #define tri-dn-mask_height 13
3279 static unsigned char tri-dn-mask_bits[] = {
3280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3281 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3285 image create bitmap reficon-T -background black -foreground yellow -data {
3286 #define tagicon_width 13
3287 #define tagicon_height 9
3288 static unsigned char tagicon_bits[] = {
3289 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3290 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3292 #define tagicon-mask_width 13
3293 #define tagicon-mask_height 9
3294 static unsigned char tagicon-mask_bits[] = {
3295 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3296 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3299 #define headicon_width 13
3300 #define headicon_height 9
3301 static unsigned char headicon_bits[] = {
3302 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3303 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3306 #define headicon-mask_width 13
3307 #define headicon-mask_height 9
3308 static unsigned char headicon-mask_bits[] = {
3309 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3310 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3312 image create bitmap reficon-H -background black -foreground green \
3313 -data $rectdata -maskdata $rectmask
3314 image create bitmap reficon-o -background black -foreground "#ddddff" \
3315 -data $rectdata -maskdata $rectmask
3317 proc init_flist {first} {
3318 global cflist cflist_top difffilestart
3320 $cflist conf -state normal
3321 $cflist delete 0.0 end
3323 $cflist insert end $first
3325 $cflist tag add highlight 1.0 "1.0 lineend"
3327 catch {unset cflist_top}
3329 $cflist conf -state disabled
3330 set difffilestart {}
3333 proc highlight_tag {f} {
3334 global highlight_paths
3336 foreach p $highlight_paths {
3337 if {[string match $p $f]} {
3344 proc highlight_filelist {} {
3345 global cmitmode cflist
3347 $cflist conf -state normal
3348 if {$cmitmode ne "tree"} {
3349 set end [lindex [split [$cflist index end] .] 0]
3350 for {set l 2} {$l < $end} {incr l} {
3351 set line [$cflist get $l.0 "$l.0 lineend"]
3352 if {[highlight_tag $line] ne {}} {
3353 $cflist tag add bold $l.0 "$l.0 lineend"
3359 $cflist conf -state disabled
3362 proc unhighlight_filelist {} {
3365 $cflist conf -state normal
3366 $cflist tag remove bold 1.0 end
3367 $cflist conf -state disabled
3370 proc add_flist {fl} {
3373 $cflist conf -state normal
3375 $cflist insert end "\n"
3376 $cflist insert end $f [highlight_tag $f]
3378 $cflist conf -state disabled
3381 proc sel_flist {w x y} {
3382 global ctext difffilestart cflist cflist_top cmitmode
3384 if {$cmitmode eq "tree"} return
3385 if {![info exists cflist_top]} return
3386 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3387 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3388 $cflist tag add highlight $l.0 "$l.0 lineend"
3393 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3395 suppress_highlighting_file_for_current_scrollpos
3398 proc pop_flist_menu {w X Y x y} {
3399 global ctext cflist cmitmode flist_menu flist_menu_file
3400 global treediffs diffids
3403 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3405 if {$cmitmode eq "tree"} {
3406 set e [linetoelt $l]
3407 if {[string index $e end] eq "/"} return
3409 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3411 set flist_menu_file $e
3412 set xdiffstate "normal"
3413 if {$cmitmode eq "tree"} {
3414 set xdiffstate "disabled"
3416 # Disable "External diff" item in tree mode
3417 $flist_menu entryconf 2 -state $xdiffstate
3418 tk_popup $flist_menu $X $Y
3421 proc find_ctext_fileinfo {line} {
3422 global ctext_file_names ctext_file_lines
3424 set ok [bsearch $ctext_file_lines $line]
3425 set tline [lindex $ctext_file_lines $ok]
3427 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3430 return [list [lindex $ctext_file_names $ok] $tline]
3434 proc pop_diff_menu {w X Y x y} {
3435 global ctext diff_menu flist_menu_file
3436 global diff_menu_txtpos diff_menu_line
3437 global diff_menu_filebase
3439 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3440 set diff_menu_line [lindex $diff_menu_txtpos 0]
3441 # don't pop up the menu on hunk-separator or file-separator lines
3442 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3446 set f [find_ctext_fileinfo $diff_menu_line]
3447 if {$f eq {}} return
3448 set flist_menu_file [lindex $f 0]
3449 set diff_menu_filebase [lindex $f 1]
3450 tk_popup $diff_menu $X $Y
3453 proc flist_hl {only} {
3454 global flist_menu_file findstring gdttype
3456 set x [shellquote $flist_menu_file]
3457 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3460 append findstring " " $x
3462 set gdttype [mc "touching paths:"]
3465 proc gitknewtmpdir {} {
3466 global diffnum gitktmpdir gitdir
3468 if {![info exists gitktmpdir]} {
3469 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3470 if {[catch {file mkdir $gitktmpdir} err]} {
3471 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3478 set diffdir [file join $gitktmpdir $diffnum]
3479 if {[catch {file mkdir $diffdir} err]} {
3480 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3486 proc save_file_from_commit {filename output what} {
3489 if {[catch {exec git show $filename -- > $output} err]} {
3490 if {[string match "fatal: bad revision *" $err]} {
3493 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3499 proc external_diff_get_one_file {diffid filename diffdir} {
3500 global nullid nullid2 nullfile
3503 if {$diffid == $nullid} {
3504 set difffile [file join $worktree $filename]
3505 if {[file exists $difffile]} {
3510 if {$diffid == $nullid2} {
3511 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3512 return [save_file_from_commit :$filename $difffile index]
3514 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3515 return [save_file_from_commit $diffid:$filename $difffile \
3519 proc external_diff {} {
3520 global nullid nullid2
3521 global flist_menu_file
3525 if {[llength $diffids] == 1} {
3526 # no reference commit given
3527 set diffidto [lindex $diffids 0]
3528 if {$diffidto eq $nullid} {
3529 # diffing working copy with index
3530 set diffidfrom $nullid2
3531 } elseif {$diffidto eq $nullid2} {
3532 # diffing index with HEAD
3533 set diffidfrom "HEAD"
3535 # use first parent commit
3536 global parentlist selectedline
3537 set diffidfrom [lindex $parentlist $selectedline 0]
3540 set diffidfrom [lindex $diffids 0]
3541 set diffidto [lindex $diffids 1]
3544 # make sure that several diffs wont collide
3545 set diffdir [gitknewtmpdir]
3546 if {$diffdir eq {}} return
3548 # gather files to diff
3549 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3550 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3552 if {$difffromfile ne {} && $difftofile ne {}} {
3553 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3554 if {[catch {set fl [open |$cmd r]} err]} {
3555 file delete -force $diffdir
3556 error_popup "$extdifftool: [mc "command failed:"] $err"
3558 fconfigure $fl -blocking 0
3559 filerun $fl [list delete_at_eof $fl $diffdir]
3564 proc find_hunk_blamespec {base line} {
3567 # Find and parse the hunk header
3568 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3569 if {$s_lix eq {}} return
3571 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3572 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3573 s_line old_specs osz osz1 new_line nsz]} {
3577 # base lines for the parents
3578 set base_lines [list $new_line]
3579 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3580 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3581 old_spec old_line osz]} {
3584 lappend base_lines $old_line
3587 # Now scan the lines to determine offset within the hunk
3588 set max_parent [expr {[llength $base_lines]-2}]
3590 set s_lno [lindex [split $s_lix "."] 0]
3592 # Determine if the line is removed
3593 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3594 if {[string match {[-+ ]*} $chunk]} {
3595 set removed_idx [string first "-" $chunk]
3596 # Choose a parent index
3597 if {$removed_idx >= 0} {
3598 set parent $removed_idx
3600 set unchanged_idx [string first " " $chunk]
3601 if {$unchanged_idx >= 0} {
3602 set parent $unchanged_idx
3604 # blame the current commit
3608 # then count other lines that belong to it
3609 for {set i $line} {[incr i -1] > $s_lno} {} {
3610 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3611 # Determine if the line is removed
3612 set removed_idx [string first "-" $chunk]
3614 set code [string index $chunk $parent]
3615 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3619 if {$removed_idx < 0} {
3629 incr dline [lindex $base_lines $parent]
3630 return [list $parent $dline]
3633 proc external_blame_diff {} {
3634 global currentid cmitmode
3635 global diff_menu_txtpos diff_menu_line
3636 global diff_menu_filebase flist_menu_file
3638 if {$cmitmode eq "tree"} {
3640 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3642 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3644 set parent_idx [lindex $hinfo 0]
3645 set line [lindex $hinfo 1]
3652 external_blame $parent_idx $line
3655 # Find the SHA1 ID of the blob for file $fname in the index
3657 proc index_sha1 {fname} {
3658 set f [open [list | git ls-files -s $fname] r]
3659 while {[gets $f line] >= 0} {
3660 set info [lindex [split $line "\t"] 0]
3661 set stage [lindex $info 2]
3662 if {$stage eq "0" || $stage eq "2"} {
3664 return [lindex $info 1]
3671 # Turn an absolute path into one relative to the current directory
3672 proc make_relative {f} {
3673 if {[file pathtype $f] eq "relative"} {
3676 set elts [file split $f]
3677 set here [file split [pwd]]
3682 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3689 set elts [concat $res [lrange $elts $ei end]]
3690 return [eval file join $elts]
3693 proc external_blame {parent_idx {line {}}} {
3694 global flist_menu_file cdup
3695 global nullid nullid2
3696 global parentlist selectedline currentid
3698 if {$parent_idx > 0} {
3699 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3701 set base_commit $currentid
3704 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3705 error_popup [mc "No such commit"]
3709 set cmdline [list git gui blame]
3710 if {$line ne {} && $line > 1} {
3711 lappend cmdline "--line=$line"
3713 set f [file join $cdup $flist_menu_file]
3714 # Unfortunately it seems git gui blame doesn't like
3715 # being given an absolute path...
3716 set f [make_relative $f]
3717 lappend cmdline $base_commit $f
3718 if {[catch {eval exec $cmdline &} err]} {
3719 error_popup "[mc "git gui blame: command failed:"] $err"
3723 proc show_line_source {} {
3724 global cmitmode currentid parents curview blamestuff blameinst
3725 global diff_menu_line diff_menu_filebase flist_menu_file
3726 global nullid nullid2 gitdir cdup
3729 if {$cmitmode eq "tree"} {
3731 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3733 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3734 if {$h eq {}} return
3735 set pi [lindex $h 0]
3737 mark_ctext_line $diff_menu_line
3741 if {$currentid eq $nullid} {
3743 # must be a merge in progress...
3745 # get the last line from .git/MERGE_HEAD
3746 set f [open [file join $gitdir MERGE_HEAD] r]
3747 set id [lindex [split [read $f] "\n"] end-1]
3750 error_popup [mc "Couldn't read merge head: %s" $err]
3753 } elseif {$parents($curview,$currentid) eq $nullid2} {
3754 # need to do the blame from the index
3756 set from_index [index_sha1 $flist_menu_file]
3758 error_popup [mc "Error reading index: %s" $err]
3762 set id $parents($curview,$currentid)
3765 set id [lindex $parents($curview,$currentid) $pi]
3767 set line [lindex $h 1]
3770 if {$from_index ne {}} {
3771 lappend blameargs | git cat-file blob $from_index
3773 lappend blameargs | git blame -p -L$line,+1
3774 if {$from_index ne {}} {
3775 lappend blameargs --contents -
3777 lappend blameargs $id
3779 lappend blameargs -- [file join $cdup $flist_menu_file]
3781 set f [open $blameargs r]
3783 error_popup [mc "Couldn't start git blame: %s" $err]
3786 nowbusy blaming [mc "Searching"]
3787 fconfigure $f -blocking 0
3788 set i [reg_instance $f]
3789 set blamestuff($i) {}
3791 filerun $f [list read_line_source $f $i]
3794 proc stopblaming {} {
3797 if {[info exists blameinst]} {
3798 stop_instance $blameinst
3804 proc read_line_source {fd inst} {
3805 global blamestuff curview commfd blameinst nullid nullid2
3807 while {[gets $fd line] >= 0} {
3808 lappend blamestuff($inst) $line
3816 fconfigure $fd -blocking 1
3817 if {[catch {close $fd} err]} {
3818 error_popup [mc "Error running git blame: %s" $err]
3823 set line [split [lindex $blamestuff($inst) 0] " "]
3824 set id [lindex $line 0]
3825 set lnum [lindex $line 1]
3826 if {[string length $id] == 40 && [string is xdigit $id] &&
3827 [string is digit -strict $lnum]} {
3828 # look for "filename" line
3829 foreach l $blamestuff($inst) {
3830 if {[string match "filename *" $l]} {
3831 set fname [string range $l 9 end]
3837 # all looks good, select it
3838 if {$id eq $nullid} {
3839 # blame uses all-zeroes to mean not committed,
3840 # which would mean a change in the index
3843 if {[commitinview $id $curview]} {
3844 selectline [rowofcommit $id] 1 [list $fname $lnum]
3846 error_popup [mc "That line comes from commit %s, \
3847 which is not in this view" [shortids $id]]
3850 puts "oops couldn't parse git blame output"
3855 # delete $dir when we see eof on $f (presumably because the child has exited)
3856 proc delete_at_eof {f dir} {
3857 while {[gets $f line] >= 0} {}
3859 if {[catch {close $f} err]} {
3860 error_popup "[mc "External diff viewer failed:"] $err"
3862 file delete -force $dir
3868 # Functions for adding and removing shell-type quoting
3870 proc shellquote {str} {
3871 if {![string match "*\['\"\\ \t]*" $str]} {
3874 if {![string match "*\['\"\\]*" $str]} {
3877 if {![string match "*'*" $str]} {
3880 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3883 proc shellarglist {l} {
3889 append str [shellquote $a]
3894 proc shelldequote {str} {
3899 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3900 append ret [string range $str $used end]
3901 set used [string length $str]
3904 set first [lindex $first 0]
3905 set ch [string index $str $first]
3906 if {$first > $used} {
3907 append ret [string range $str $used [expr {$first - 1}]]
3910 if {$ch eq " " || $ch eq "\t"} break
3913 set first [string first "'" $str $used]
3915 error "unmatched single-quote"
3917 append ret [string range $str $used [expr {$first - 1}]]
3922 if {$used >= [string length $str]} {
3923 error "trailing backslash"
3925 append ret [string index $str $used]
3930 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3931 error "unmatched double-quote"
3933 set first [lindex $first 0]
3934 set ch [string index $str $first]
3935 if {$first > $used} {
3936 append ret [string range $str $used [expr {$first - 1}]]
3939 if {$ch eq "\""} break
3941 append ret [string index $str $used]
3945 return [list $used $ret]
3948 proc shellsplit {str} {
3951 set str [string trimleft $str]
3952 if {$str eq {}} break
3953 set dq [shelldequote $str]
3954 set n [lindex $dq 0]
3955 set word [lindex $dq 1]
3956 set str [string range $str $n end]
3962 # Code to implement multiple views
3964 proc newview {ishighlight} {
3965 global nextviewnum newviewname newishighlight
3966 global revtreeargs viewargscmd newviewopts curview
3968 set newishighlight $ishighlight
3970 if {[winfo exists $top]} {
3974 decode_view_opts $nextviewnum $revtreeargs
3975 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3976 set newviewopts($nextviewnum,perm) 0
3977 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3978 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3981 set known_view_options {
3982 {perm b . {} {mc "Remember this view"}}
3983 {reflabel l + {} {mc "References (space separated list):"}}
3984 {refs t15 .. {} {mc "Branches & tags:"}}
3985 {allrefs b *. "--all" {mc "All refs"}}
3986 {branches b . "--branches" {mc "All (local) branches"}}
3987 {tags b . "--tags" {mc "All tags"}}
3988 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3989 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3990 {author t15 .. "--author=*" {mc "Author:"}}
3991 {committer t15 . "--committer=*" {mc "Committer:"}}
3992 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3993 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3994 {changes_l l + {} {mc "Changes to Files:"}}
3995 {pickaxe_s r0 . {} {mc "Fixed String"}}
3996 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3997 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3998 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3999 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
4000 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
4001 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
4002 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
4003 {skip t10 . "--skip=*" {mc "Number to skip:"}}
4004 {misc_lbl l + {} {mc "Miscellaneous options:"}}
4005 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
4006 {lright b . "--left-right" {mc "Mark branch sides"}}
4007 {first b . "--first-parent" {mc "Limit to first parent"}}
4008 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
4009 {args t50 *. {} {mc "Additional arguments to git log:"}}
4010 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4011 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4014 # Convert $newviewopts($n, ...) into args for git log.
4015 proc encode_view_opts {n} {
4016 global known_view_options newviewopts
4019 foreach opt $known_view_options {
4020 set patterns [lindex $opt 3]
4021 if {$patterns eq {}} continue
4022 set pattern [lindex $patterns 0]
4024 if {[lindex $opt 1] eq "b"} {
4025 set val $newviewopts($n,[lindex $opt 0])
4027 lappend rargs $pattern
4029 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4030 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4031 set val $newviewopts($n,$button_id)
4032 if {$val eq $value} {
4033 lappend rargs $pattern
4036 set val $newviewopts($n,[lindex $opt 0])
4037 set val [string trim $val]
4039 set pfix [string range $pattern 0 end-1]
4040 lappend rargs $pfix$val
4044 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4045 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4048 # Fill $newviewopts($n, ...) based on args for git log.
4049 proc decode_view_opts {n view_args} {
4050 global known_view_options newviewopts
4052 foreach opt $known_view_options {
4053 set id [lindex $opt 0]
4054 if {[lindex $opt 1] eq "b"} {
4057 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4059 regexp {^(.*_)} $id uselessvar id
4065 set newviewopts($n,$id) $val
4069 foreach arg $view_args {
4070 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4071 && ![info exists found(limit)]} {
4072 set newviewopts($n,limit) $cnt
4077 foreach opt $known_view_options {
4078 set id [lindex $opt 0]
4079 if {[info exists found($id)]} continue
4080 foreach pattern [lindex $opt 3] {
4081 if {![string match $pattern $arg]} continue
4082 if {[lindex $opt 1] eq "b"} {
4085 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4087 regexp {^(.*_)} $id uselessvar id
4091 set size [string length $pattern]
4092 set val [string range $arg [expr {$size-1}] end]
4094 set newviewopts($n,$id) $val
4098 if {[info exists val]} break
4100 if {[info exists val]} continue
4101 if {[regexp {^-} $arg]} {
4104 lappend refargs $arg
4107 set newviewopts($n,refs) [shellarglist $refargs]
4108 set newviewopts($n,args) [shellarglist $oargs]
4111 proc edit_or_newview {} {
4123 global viewname viewperm newviewname newviewopts
4124 global viewargs viewargscmd
4126 set top .gitkvedit-$curview
4127 if {[winfo exists $top]} {
4131 decode_view_opts $curview $viewargs($curview)
4132 set newviewname($curview) $viewname($curview)
4133 set newviewopts($curview,perm) $viewperm($curview)
4134 set newviewopts($curview,cmd) $viewargscmd($curview)
4135 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4138 proc vieweditor {top n title} {
4139 global newviewname newviewopts viewfiles bgcolor
4140 global known_view_options NS
4143 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4144 make_transient $top .
4147 ${NS}::frame $top.nfr
4148 ${NS}::label $top.nl -text [mc "View Name"]
4149 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4150 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4151 pack $top.nl -in $top.nfr -side left -padx {0 5}
4152 pack $top.name -in $top.nfr -side left -padx {0 25}
4158 foreach opt $known_view_options {
4159 set id [lindex $opt 0]
4160 set type [lindex $opt 1]
4161 set flags [lindex $opt 2]
4162 set title [eval [lindex $opt 4]]
4165 if {$flags eq "+" || $flags eq "*"} {
4166 set cframe $top.fr$cnt
4168 ${NS}::frame $cframe
4169 pack $cframe -in $top -fill x -pady 3 -padx 3
4170 set cexpand [expr {$flags eq "*"}]
4171 } elseif {$flags eq ".." || $flags eq "*."} {
4172 set cframe $top.fr$cnt
4174 ${NS}::frame $cframe
4175 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4176 set cexpand [expr {$flags eq "*."}]
4182 ${NS}::label $cframe.l_$id -text $title
4183 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4184 } elseif {$type eq "b"} {
4185 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4186 pack $cframe.c_$id -in $cframe -side left \
4187 -padx [list $lxpad 0] -expand $cexpand -anchor w
4188 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4189 regexp {^(.*_)} $id uselessvar button_id
4190 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4191 pack $cframe.c_$id -in $cframe -side left \
4192 -padx [list $lxpad 0] -expand $cexpand -anchor w
4193 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4194 ${NS}::label $cframe.l_$id -text $title
4195 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4196 -textvariable newviewopts($n,$id)
4197 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4198 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4199 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4200 ${NS}::label $cframe.l_$id -text $title
4201 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4202 -textvariable newviewopts($n,$id)
4203 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4204 pack $cframe.e_$id -in $cframe -side top -fill x
4205 } elseif {$type eq "path"} {
4206 ${NS}::label $top.l -text $title
4207 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4208 text $top.t -width 40 -height 5 -background $bgcolor
4209 if {[info exists viewfiles($n)]} {
4210 foreach f $viewfiles($n) {
4211 $top.t insert end $f
4212 $top.t insert end "\n"
4214 $top.t delete {end - 1c} end
4215 $top.t mark set insert 0.0
4217 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4221 ${NS}::frame $top.buts
4222 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4223 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4224 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4225 bind $top <Control-Return> [list newviewok $top $n]
4226 bind $top <F5> [list newviewok $top $n 1]
4227 bind $top <Escape> [list destroy $top]
4228 grid $top.buts.ok $top.buts.apply $top.buts.can
4229 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4230 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4231 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4232 pack $top.buts -in $top -side top -fill x
4236 proc doviewmenu {m first cmd op argv} {
4237 set nmenu [$m index end]
4238 for {set i $first} {$i <= $nmenu} {incr i} {
4239 if {[$m entrycget $i -command] eq $cmd} {
4240 eval $m $op $i $argv
4246 proc allviewmenus {n op args} {
4249 doviewmenu .bar.view 5 [list showview $n] $op $args
4250 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4253 proc newviewok {top n {apply 0}} {
4254 global nextviewnum newviewperm newviewname newishighlight
4255 global viewname viewfiles viewperm selectedview curview
4256 global viewargs viewargscmd newviewopts viewhlmenu
4259 set newargs [encode_view_opts $n]
4261 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4265 foreach f [split [$top.t get 0.0 end] "\n"] {
4266 set ft [string trim $f]
4271 if {![info exists viewfiles($n)]} {
4272 # creating a new view
4274 set viewname($n) $newviewname($n)
4275 set viewperm($n) $newviewopts($n,perm)
4276 set viewfiles($n) $files
4277 set viewargs($n) $newargs
4278 set viewargscmd($n) $newviewopts($n,cmd)
4280 if {!$newishighlight} {
4283 run addvhighlight $n
4286 # editing an existing view
4287 set viewperm($n) $newviewopts($n,perm)
4288 if {$newviewname($n) ne $viewname($n)} {
4289 set viewname($n) $newviewname($n)
4290 doviewmenu .bar.view 5 [list showview $n] \
4291 entryconf [list -label $viewname($n)]
4292 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4293 # entryconf [list -label $viewname($n) -value $viewname($n)]
4295 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4296 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4297 set viewfiles($n) $files
4298 set viewargs($n) $newargs
4299 set viewargscmd($n) $newviewopts($n,cmd)
4300 if {$curview == $n} {
4306 catch {destroy $top}
4310 global curview viewperm hlview selectedhlview
4312 if {$curview == 0} return
4313 if {[info exists hlview] && $hlview == $curview} {
4314 set selectedhlview [mc "None"]
4317 allviewmenus $curview delete
4318 set viewperm($curview) 0
4322 proc addviewmenu {n} {
4323 global viewname viewhlmenu
4325 .bar.view add radiobutton -label $viewname($n) \
4326 -command [list showview $n] -variable selectedview -value $n
4327 #$viewhlmenu add radiobutton -label $viewname($n) \
4328 # -command [list addvhighlight $n] -variable selectedhlview
4332 global curview cached_commitrow ordertok
4333 global displayorder parentlist rowidlist rowisopt rowfinal
4334 global colormap rowtextx nextcolor canvxmax
4335 global numcommits viewcomplete
4336 global selectedline currentid canv canvy0
4338 global pending_select mainheadid
4341 global hlview selectedhlview commitinterest
4343 if {$n == $curview} return
4345 set ymax [lindex [$canv cget -scrollregion] 3]
4346 set span [$canv yview]
4347 set ytop [expr {[lindex $span 0] * $ymax}]
4348 set ybot [expr {[lindex $span 1] * $ymax}]
4349 set yscreen [expr {($ybot - $ytop) / 2}]
4350 if {$selectedline ne {}} {
4351 set selid $currentid
4352 set y [yc $selectedline]
4353 if {$ytop < $y && $y < $ybot} {
4354 set yscreen [expr {$y - $ytop}]
4356 } elseif {[info exists pending_select]} {
4357 set selid $pending_select
4358 unset pending_select
4362 catch {unset treediffs}
4364 if {[info exists hlview] && $hlview == $n} {
4366 set selectedhlview [mc "None"]
4368 catch {unset commitinterest}
4369 catch {unset cached_commitrow}
4370 catch {unset ordertok}
4374 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4375 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4378 if {![info exists viewcomplete($n)]} {
4388 set numcommits $commitidx($n)
4390 catch {unset colormap}
4391 catch {unset rowtextx}
4393 set canvxmax [$canv cget -width]
4399 if {$selid ne {} && [commitinview $selid $n]} {
4400 set row [rowofcommit $selid]
4401 # try to get the selected row in the same position on the screen
4402 set ymax [lindex [$canv cget -scrollregion] 3]
4403 set ytop [expr {[yc $row] - $yscreen}]
4407 set yf [expr {$ytop * 1.0 / $ymax}]
4409 allcanvs yview moveto $yf
4413 } elseif {!$viewcomplete($n)} {
4414 reset_pending_select $selid
4416 reset_pending_select {}
4418 if {[commitinview $pending_select $curview]} {
4419 selectline [rowofcommit $pending_select] 1
4421 set row [first_real_row]
4422 if {$row < $numcommits} {
4427 if {!$viewcomplete($n)} {
4428 if {$numcommits == 0} {
4429 show_status [mc "Reading commits..."]
4431 } elseif {$numcommits == 0} {
4432 show_status [mc "No commits selected"]
4436 # Stuff relating to the highlighting facility
4438 proc ishighlighted {id} {
4439 global vhighlights fhighlights nhighlights rhighlights
4441 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4442 return $nhighlights($id)
4444 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4445 return $vhighlights($id)
4447 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4448 return $fhighlights($id)
4450 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4451 return $rhighlights($id)
4456 proc bolden {id font} {
4457 global canv linehtag currentid boldids need_redisplay markedid
4459 # need_redisplay = 1 means the display is stale and about to be redrawn
4460 if {$need_redisplay} return
4462 $canv itemconf $linehtag($id) -font $font
4463 if {[info exists currentid] && $id eq $currentid} {
4465 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4466 -outline {{}} -tags secsel \
4467 -fill [$canv cget -selectbackground]]
4470 if {[info exists markedid] && $id eq $markedid} {
4475 proc bolden_name {id font} {
4476 global canv2 linentag currentid boldnameids need_redisplay
4478 if {$need_redisplay} return
4479 lappend boldnameids $id
4480 $canv2 itemconf $linentag($id) -font $font
4481 if {[info exists currentid] && $id eq $currentid} {
4482 $canv2 delete secsel
4483 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4484 -outline {{}} -tags secsel \
4485 -fill [$canv2 cget -selectbackground]]
4494 foreach id $boldids {
4495 if {![ishighlighted $id]} {
4498 lappend stillbold $id
4501 set boldids $stillbold
4504 proc addvhighlight {n} {
4505 global hlview viewcomplete curview vhl_done commitidx
4507 if {[info exists hlview]} {
4511 if {$n != $curview && ![info exists viewcomplete($n)]} {
4514 set vhl_done $commitidx($hlview)
4515 if {$vhl_done > 0} {
4520 proc delvhighlight {} {
4521 global hlview vhighlights
4523 if {![info exists hlview]} return
4525 catch {unset vhighlights}
4529 proc vhighlightmore {} {
4530 global hlview vhl_done commitidx vhighlights curview
4532 set max $commitidx($hlview)
4533 set vr [visiblerows]
4534 set r0 [lindex $vr 0]
4535 set r1 [lindex $vr 1]
4536 for {set i $vhl_done} {$i < $max} {incr i} {
4537 set id [commitonrow $i $hlview]
4538 if {[commitinview $id $curview]} {
4539 set row [rowofcommit $id]
4540 if {$r0 <= $row && $row <= $r1} {
4541 if {![highlighted $row]} {
4542 bolden $id mainfontbold
4544 set vhighlights($id) 1
4552 proc askvhighlight {row id} {
4553 global hlview vhighlights iddrawn
4555 if {[commitinview $id $hlview]} {
4556 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4557 bolden $id mainfontbold
4559 set vhighlights($id) 1
4561 set vhighlights($id) 0
4565 proc hfiles_change {} {
4566 global highlight_files filehighlight fhighlights fh_serial
4567 global highlight_paths
4569 if {[info exists filehighlight]} {
4570 # delete previous highlights
4571 catch {close $filehighlight}
4573 catch {unset fhighlights}
4575 unhighlight_filelist
4577 set highlight_paths {}
4578 after cancel do_file_hl $fh_serial
4580 if {$highlight_files ne {}} {
4581 after 300 do_file_hl $fh_serial
4585 proc gdttype_change {name ix op} {
4586 global gdttype highlight_files findstring findpattern
4589 if {$findstring ne {}} {
4590 if {$gdttype eq [mc "containing:"]} {
4591 if {$highlight_files ne {}} {
4592 set highlight_files {}
4597 if {$findpattern ne {}} {
4601 set highlight_files $findstring
4606 # enable/disable findtype/findloc menus too
4609 proc find_change {name ix op} {
4610 global gdttype findstring highlight_files
4613 if {$gdttype eq [mc "containing:"]} {
4616 if {$highlight_files ne $findstring} {
4617 set highlight_files $findstring
4624 proc findcom_change args {
4625 global nhighlights boldnameids
4626 global findpattern findtype findstring gdttype
4629 # delete previous highlights, if any
4630 foreach id $boldnameids {
4631 bolden_name $id mainfont
4634 catch {unset nhighlights}
4637 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4639 } elseif {$findtype eq [mc "Regexp"]} {
4640 set findpattern $findstring
4642 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4644 set findpattern "*$e*"
4648 proc makepatterns {l} {
4651 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4652 if {[string index $ee end] eq "/"} {
4662 proc do_file_hl {serial} {
4663 global highlight_files filehighlight highlight_paths gdttype fhl_list
4664 global cdup findtype
4666 if {$gdttype eq [mc "touching paths:"]} {
4667 # If "exact" match then convert backslashes to forward slashes.
4668 # Most useful to support Windows-flavoured file paths.
4669 if {$findtype eq [mc "Exact"]} {
4670 set highlight_files [string map {"\\" "/"} $highlight_files]
4672 if {[catch {set paths [shellsplit $highlight_files]}]} return
4673 set highlight_paths [makepatterns $paths]
4675 set relative_paths {}
4676 foreach path $paths {
4677 lappend relative_paths [file join $cdup $path]
4679 set gdtargs [concat -- $relative_paths]
4680 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4681 set gdtargs [list "-S$highlight_files"]
4682 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4683 set gdtargs [list "-G$highlight_files"]
4685 # must be "containing:", i.e. we're searching commit info
4688 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4689 set filehighlight [open $cmd r+]
4690 fconfigure $filehighlight -blocking 0
4691 filerun $filehighlight readfhighlight
4697 proc flushhighlights {} {
4698 global filehighlight fhl_list
4700 if {[info exists filehighlight]} {
4702 puts $filehighlight ""
4703 flush $filehighlight
4707 proc askfilehighlight {row id} {
4708 global filehighlight fhighlights fhl_list
4710 lappend fhl_list $id
4711 set fhighlights($id) -1
4712 puts $filehighlight $id
4715 proc readfhighlight {} {
4716 global filehighlight fhighlights curview iddrawn
4717 global fhl_list find_dirn
4719 if {![info exists filehighlight]} {
4723 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4724 set line [string trim $line]
4725 set i [lsearch -exact $fhl_list $line]
4726 if {$i < 0} continue
4727 for {set j 0} {$j < $i} {incr j} {
4728 set id [lindex $fhl_list $j]
4729 set fhighlights($id) 0
4731 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4732 if {$line eq {}} continue
4733 if {![commitinview $line $curview]} continue
4734 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4735 bolden $line mainfontbold
4737 set fhighlights($line) 1
4739 if {[eof $filehighlight]} {
4741 puts "oops, git diff-tree died"
4742 catch {close $filehighlight}
4746 if {[info exists find_dirn]} {
4752 proc doesmatch {f} {
4753 global findtype findpattern
4755 if {$findtype eq [mc "Regexp"]} {
4756 return [regexp $findpattern $f]
4757 } elseif {$findtype eq [mc "IgnCase"]} {
4758 return [string match -nocase $findpattern $f]
4760 return [string match $findpattern $f]
4764 proc askfindhighlight {row id} {
4765 global nhighlights commitinfo iddrawn
4767 global markingmatches
4769 if {![info exists commitinfo($id)]} {
4772 set info $commitinfo($id)
4774 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4775 foreach f $info ty $fldtypes {
4776 if {$ty eq ""} continue
4777 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4779 if {$ty eq [mc "Author"]} {
4786 if {$isbold && [info exists iddrawn($id)]} {
4787 if {![ishighlighted $id]} {
4788 bolden $id mainfontbold
4790 bolden_name $id mainfontbold
4793 if {$markingmatches} {
4794 markrowmatches $row $id
4797 set nhighlights($id) $isbold
4800 proc markrowmatches {row id} {
4801 global canv canv2 linehtag linentag commitinfo findloc
4803 set headline [lindex $commitinfo($id) 0]
4804 set author [lindex $commitinfo($id) 1]
4805 $canv delete match$row
4806 $canv2 delete match$row
4807 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4808 set m [findmatches $headline]
4810 markmatches $canv $row $headline $linehtag($id) $m \
4811 [$canv itemcget $linehtag($id) -font] $row
4814 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4815 set m [findmatches $author]
4817 markmatches $canv2 $row $author $linentag($id) $m \
4818 [$canv2 itemcget $linentag($id) -font] $row
4823 proc vrel_change {name ix op} {
4824 global highlight_related
4827 if {$highlight_related ne [mc "None"]} {
4832 # prepare for testing whether commits are descendents or ancestors of a
4833 proc rhighlight_sel {a} {
4834 global descendent desc_todo ancestor anc_todo
4835 global highlight_related
4837 catch {unset descendent}
4838 set desc_todo [list $a]
4839 catch {unset ancestor}
4840 set anc_todo [list $a]
4841 if {$highlight_related ne [mc "None"]} {
4847 proc rhighlight_none {} {
4850 catch {unset rhighlights}
4854 proc is_descendent {a} {
4855 global curview children descendent desc_todo
4858 set la [rowofcommit $a]
4862 for {set i 0} {$i < [llength $todo]} {incr i} {
4863 set do [lindex $todo $i]
4864 if {[rowofcommit $do] < $la} {
4865 lappend leftover $do
4868 foreach nk $children($v,$do) {
4869 if {![info exists descendent($nk)]} {
4870 set descendent($nk) 1
4878 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4882 set descendent($a) 0
4883 set desc_todo $leftover
4886 proc is_ancestor {a} {
4887 global curview parents ancestor anc_todo
4890 set la [rowofcommit $a]
4894 for {set i 0} {$i < [llength $todo]} {incr i} {
4895 set do [lindex $todo $i]
4896 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4897 lappend leftover $do
4900 foreach np $parents($v,$do) {
4901 if {![info exists ancestor($np)]} {
4910 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4915 set anc_todo $leftover
4918 proc askrelhighlight {row id} {
4919 global descendent highlight_related iddrawn rhighlights
4920 global selectedline ancestor
4922 if {$selectedline eq {}} return
4924 if {$highlight_related eq [mc "Descendant"] ||
4925 $highlight_related eq [mc "Not descendant"]} {
4926 if {![info exists descendent($id)]} {
4929 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4932 } elseif {$highlight_related eq [mc "Ancestor"] ||
4933 $highlight_related eq [mc "Not ancestor"]} {
4934 if {![info exists ancestor($id)]} {
4937 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4941 if {[info exists iddrawn($id)]} {
4942 if {$isbold && ![ishighlighted $id]} {
4943 bolden $id mainfontbold
4946 set rhighlights($id) $isbold
4949 # Graph layout functions
4951 proc shortids {ids} {
4954 if {[llength $id] > 1} {
4955 lappend res [shortids $id]
4956 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4957 lappend res [string range $id 0 7]
4968 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4969 if {($n & $mask) != 0} {
4970 set ret [concat $ret $o]
4972 set o [concat $o $o]
4977 proc ordertoken {id} {
4978 global ordertok curview varcid varcstart varctok curview parents children
4979 global nullid nullid2
4981 if {[info exists ordertok($id)]} {
4982 return $ordertok($id)
4987 if {[info exists varcid($curview,$id)]} {
4988 set a $varcid($curview,$id)
4989 set p [lindex $varcstart($curview) $a]
4991 set p [lindex $children($curview,$id) 0]
4993 if {[info exists ordertok($p)]} {
4994 set tok $ordertok($p)
4997 set id [first_real_child $curview,$p]
5000 set tok [lindex $varctok($curview) $varcid($curview,$p)]
5003 if {[llength $parents($curview,$id)] == 1} {
5004 lappend todo [list $p {}]
5006 set j [lsearch -exact $parents($curview,$id) $p]
5008 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5010 lappend todo [list $p [strrep $j]]
5013 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5014 set p [lindex $todo $i 0]
5015 append tok [lindex $todo $i 1]
5016 set ordertok($p) $tok
5018 set ordertok($origid) $tok
5022 # Work out where id should go in idlist so that order-token
5023 # values increase from left to right
5024 proc idcol {idlist id {i 0}} {
5025 set t [ordertoken $id]
5029 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5030 if {$i > [llength $idlist]} {
5031 set i [llength $idlist]
5033 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5036 if {$t > [ordertoken [lindex $idlist $i]]} {
5037 while {[incr i] < [llength $idlist] &&
5038 $t >= [ordertoken [lindex $idlist $i]]} {}
5044 proc initlayout {} {
5045 global rowidlist rowisopt rowfinal displayorder parentlist
5046 global numcommits canvxmax canv
5048 global colormap rowtextx
5057 set canvxmax [$canv cget -width]
5058 catch {unset colormap}
5059 catch {unset rowtextx}
5063 proc setcanvscroll {} {
5064 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5065 global lastscrollset lastscrollrows
5067 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5068 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5069 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5070 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5071 set lastscrollset [clock clicks -milliseconds]
5072 set lastscrollrows $numcommits
5075 proc visiblerows {} {
5076 global canv numcommits linespc
5078 set ymax [lindex [$canv cget -scrollregion] 3]
5079 if {$ymax eq {} || $ymax == 0} return
5081 set y0 [expr {int([lindex $f 0] * $ymax)}]
5082 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5086 set y1 [expr {int([lindex $f 1] * $ymax)}]
5087 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5088 if {$r1 >= $numcommits} {
5089 set r1 [expr {$numcommits - 1}]
5091 return [list $r0 $r1]
5094 proc layoutmore {} {
5095 global commitidx viewcomplete curview
5096 global numcommits pending_select curview
5097 global lastscrollset lastscrollrows
5099 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5100 [clock clicks -milliseconds] - $lastscrollset > 500} {
5103 if {[info exists pending_select] &&
5104 [commitinview $pending_select $curview]} {
5106 selectline [rowofcommit $pending_select] 1
5111 # With path limiting, we mightn't get the actual HEAD commit,
5112 # so ask git rev-list what is the first ancestor of HEAD that
5113 # touches a file in the path limit.
5114 proc get_viewmainhead {view} {
5115 global viewmainheadid vfilelimit viewinstances mainheadid
5118 set rfd [open [concat | git rev-list -1 $mainheadid \
5119 -- $vfilelimit($view)] r]
5120 set j [reg_instance $rfd]
5121 lappend viewinstances($view) $j
5122 fconfigure $rfd -blocking 0
5123 filerun $rfd [list getviewhead $rfd $j $view]
5124 set viewmainheadid($curview) {}
5128 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5129 proc getviewhead {fd inst view} {
5130 global viewmainheadid commfd curview viewinstances showlocalchanges
5133 if {[gets $fd line] < 0} {
5137 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5140 set viewmainheadid($view) $id
5143 set i [lsearch -exact $viewinstances($view) $inst]
5145 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5147 if {$showlocalchanges && $id ne {} && $view == $curview} {
5153 proc doshowlocalchanges {} {
5154 global curview viewmainheadid
5156 if {$viewmainheadid($curview) eq {}} return
5157 if {[commitinview $viewmainheadid($curview) $curview]} {
5160 interestedin $viewmainheadid($curview) dodiffindex
5164 proc dohidelocalchanges {} {
5165 global nullid nullid2 lserial curview
5167 if {[commitinview $nullid $curview]} {
5168 removefakerow $nullid
5170 if {[commitinview $nullid2 $curview]} {
5171 removefakerow $nullid2
5176 # spawn off a process to do git diff-index --cached HEAD
5177 proc dodiffindex {} {
5178 global lserial showlocalchanges vfilelimit curview
5181 if {!$showlocalchanges || !$hasworktree} return
5183 set cmd "|git diff-index --cached HEAD"
5184 if {$vfilelimit($curview) ne {}} {
5185 set cmd [concat $cmd -- $vfilelimit($curview)]
5187 set fd [open $cmd r]
5188 fconfigure $fd -blocking 0
5189 set i [reg_instance $fd]
5190 filerun $fd [list readdiffindex $fd $lserial $i]
5193 proc readdiffindex {fd serial inst} {
5194 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5198 if {[gets $fd line] < 0} {
5204 # we only need to see one line and we don't really care what it says...
5207 if {$serial != $lserial} {
5211 # now see if there are any local changes not checked in to the index
5212 set cmd "|git diff-files"
5213 if {$vfilelimit($curview) ne {}} {
5214 set cmd [concat $cmd -- $vfilelimit($curview)]
5216 set fd [open $cmd r]
5217 fconfigure $fd -blocking 0
5218 set i [reg_instance $fd]
5219 filerun $fd [list readdifffiles $fd $serial $i]
5221 if {$isdiff && ![commitinview $nullid2 $curview]} {
5222 # add the line for the changes in the index to the graph
5223 set hl [mc "Local changes checked in to index but not committed"]
5224 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5225 set commitdata($nullid2) "\n $hl\n"
5226 if {[commitinview $nullid $curview]} {
5227 removefakerow $nullid
5229 insertfakerow $nullid2 $viewmainheadid($curview)
5230 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5231 if {[commitinview $nullid $curview]} {
5232 removefakerow $nullid
5234 removefakerow $nullid2
5239 proc readdifffiles {fd serial inst} {
5240 global viewmainheadid nullid nullid2 curview
5241 global commitinfo commitdata lserial
5244 if {[gets $fd line] < 0} {
5250 # we only need to see one line and we don't really care what it says...
5253 if {$serial != $lserial} {
5257 if {$isdiff && ![commitinview $nullid $curview]} {
5258 # add the line for the local diff to the graph
5259 set hl [mc "Local uncommitted changes, not checked in to index"]
5260 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5261 set commitdata($nullid) "\n $hl\n"
5262 if {[commitinview $nullid2 $curview]} {
5265 set p $viewmainheadid($curview)
5267 insertfakerow $nullid $p
5268 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5269 removefakerow $nullid
5274 proc nextuse {id row} {
5275 global curview children
5277 if {[info exists children($curview,$id)]} {
5278 foreach kid $children($curview,$id) {
5279 if {![commitinview $kid $curview]} {
5282 if {[rowofcommit $kid] > $row} {
5283 return [rowofcommit $kid]
5287 if {[commitinview $id $curview]} {
5288 return [rowofcommit $id]
5293 proc prevuse {id row} {
5294 global curview children
5297 if {[info exists children($curview,$id)]} {
5298 foreach kid $children($curview,$id) {
5299 if {![commitinview $kid $curview]} break
5300 if {[rowofcommit $kid] < $row} {
5301 set ret [rowofcommit $kid]
5308 proc make_idlist {row} {
5309 global displayorder parentlist uparrowlen downarrowlen mingaplen
5310 global commitidx curview children
5312 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5316 set ra [expr {$row - $downarrowlen}]
5320 set rb [expr {$row + $uparrowlen}]
5321 if {$rb > $commitidx($curview)} {
5322 set rb $commitidx($curview)
5324 make_disporder $r [expr {$rb + 1}]
5326 for {} {$r < $ra} {incr r} {
5327 set nextid [lindex $displayorder [expr {$r + 1}]]
5328 foreach p [lindex $parentlist $r] {
5329 if {$p eq $nextid} continue
5330 set rn [nextuse $p $r]
5332 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5333 lappend ids [list [ordertoken $p] $p]
5337 for {} {$r < $row} {incr r} {
5338 set nextid [lindex $displayorder [expr {$r + 1}]]
5339 foreach p [lindex $parentlist $r] {
5340 if {$p eq $nextid} continue
5341 set rn [nextuse $p $r]
5342 if {$rn < 0 || $rn >= $row} {
5343 lappend ids [list [ordertoken $p] $p]
5347 set id [lindex $displayorder $row]
5348 lappend ids [list [ordertoken $id] $id]
5350 foreach p [lindex $parentlist $r] {
5351 set firstkid [lindex $children($curview,$p) 0]
5352 if {[rowofcommit $firstkid] < $row} {
5353 lappend ids [list [ordertoken $p] $p]
5357 set id [lindex $displayorder $r]
5359 set firstkid [lindex $children($curview,$id) 0]
5360 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5361 lappend ids [list [ordertoken $id] $id]
5366 foreach idx [lsort -unique $ids] {
5367 lappend idlist [lindex $idx 1]
5372 proc rowsequal {a b} {
5373 while {[set i [lsearch -exact $a {}]] >= 0} {
5374 set a [lreplace $a $i $i]
5376 while {[set i [lsearch -exact $b {}]] >= 0} {
5377 set b [lreplace $b $i $i]
5379 return [expr {$a eq $b}]
5382 proc makeupline {id row rend col} {
5383 global rowidlist uparrowlen downarrowlen mingaplen
5385 for {set r $rend} {1} {set r $rstart} {
5386 set rstart [prevuse $id $r]
5387 if {$rstart < 0} return
5388 if {$rstart < $row} break
5390 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5391 set rstart [expr {$rend - $uparrowlen - 1}]
5393 for {set r $rstart} {[incr r] <= $row} {} {
5394 set idlist [lindex $rowidlist $r]
5395 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5396 set col [idcol $idlist $id $col]
5397 lset rowidlist $r [linsert $idlist $col $id]
5403 proc layoutrows {row endrow} {
5404 global rowidlist rowisopt rowfinal displayorder
5405 global uparrowlen downarrowlen maxwidth mingaplen
5406 global children parentlist
5407 global commitidx viewcomplete curview
5409 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5412 set rm1 [expr {$row - 1}]
5413 foreach id [lindex $rowidlist $rm1] {
5418 set final [lindex $rowfinal $rm1]
5420 for {} {$row < $endrow} {incr row} {
5421 set rm1 [expr {$row - 1}]
5422 if {$rm1 < 0 || $idlist eq {}} {
5423 set idlist [make_idlist $row]
5426 set id [lindex $displayorder $rm1]
5427 set col [lsearch -exact $idlist $id]
5428 set idlist [lreplace $idlist $col $col]
5429 foreach p [lindex $parentlist $rm1] {
5430 if {[lsearch -exact $idlist $p] < 0} {
5431 set col [idcol $idlist $p $col]
5432 set idlist [linsert $idlist $col $p]
5433 # if not the first child, we have to insert a line going up
5434 if {$id ne [lindex $children($curview,$p) 0]} {
5435 makeupline $p $rm1 $row $col
5439 set id [lindex $displayorder $row]
5440 if {$row > $downarrowlen} {
5441 set termrow [expr {$row - $downarrowlen - 1}]
5442 foreach p [lindex $parentlist $termrow] {
5443 set i [lsearch -exact $idlist $p]
5444 if {$i < 0} continue
5445 set nr [nextuse $p $termrow]
5446 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5447 set idlist [lreplace $idlist $i $i]
5451 set col [lsearch -exact $idlist $id]
5453 set col [idcol $idlist $id]
5454 set idlist [linsert $idlist $col $id]
5455 if {$children($curview,$id) ne {}} {
5456 makeupline $id $rm1 $row $col
5459 set r [expr {$row + $uparrowlen - 1}]
5460 if {$r < $commitidx($curview)} {
5462 foreach p [lindex $parentlist $r] {
5463 if {[lsearch -exact $idlist $p] >= 0} continue
5464 set fk [lindex $children($curview,$p) 0]
5465 if {[rowofcommit $fk] < $row} {
5466 set x [idcol $idlist $p $x]
5467 set idlist [linsert $idlist $x $p]
5470 if {[incr r] < $commitidx($curview)} {
5471 set p [lindex $displayorder $r]
5472 if {[lsearch -exact $idlist $p] < 0} {
5473 set fk [lindex $children($curview,$p) 0]
5474 if {$fk ne {} && [rowofcommit $fk] < $row} {
5475 set x [idcol $idlist $p $x]
5476 set idlist [linsert $idlist $x $p]
5482 if {$final && !$viewcomplete($curview) &&
5483 $row + $uparrowlen + $mingaplen + $downarrowlen
5484 >= $commitidx($curview)} {
5487 set l [llength $rowidlist]
5489 lappend rowidlist $idlist
5491 lappend rowfinal $final
5492 } elseif {$row < $l} {
5493 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5494 lset rowidlist $row $idlist
5497 lset rowfinal $row $final
5499 set pad [ntimes [expr {$row - $l}] {}]
5500 set rowidlist [concat $rowidlist $pad]
5501 lappend rowidlist $idlist
5502 set rowfinal [concat $rowfinal $pad]
5503 lappend rowfinal $final
5504 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5510 proc changedrow {row} {
5511 global displayorder iddrawn rowisopt need_redisplay
5513 set l [llength $rowisopt]
5515 lset rowisopt $row 0
5516 if {$row + 1 < $l} {
5517 lset rowisopt [expr {$row + 1}] 0
5518 if {$row + 2 < $l} {
5519 lset rowisopt [expr {$row + 2}] 0
5523 set id [lindex $displayorder $row]
5524 if {[info exists iddrawn($id)]} {
5525 set need_redisplay 1
5529 proc insert_pad {row col npad} {
5532 set pad [ntimes $npad {}]
5533 set idlist [lindex $rowidlist $row]
5534 set bef [lrange $idlist 0 [expr {$col - 1}]]
5535 set aft [lrange $idlist $col end]
5536 set i [lsearch -exact $aft {}]
5538 set aft [lreplace $aft $i $i]
5540 lset rowidlist $row [concat $bef $pad $aft]
5544 proc optimize_rows {row col endrow} {
5545 global rowidlist rowisopt displayorder curview children
5550 for {} {$row < $endrow} {incr row; set col 0} {
5551 if {[lindex $rowisopt $row]} continue
5553 set y0 [expr {$row - 1}]
5554 set ym [expr {$row - 2}]
5555 set idlist [lindex $rowidlist $row]
5556 set previdlist [lindex $rowidlist $y0]
5557 if {$idlist eq {} || $previdlist eq {}} continue
5559 set pprevidlist [lindex $rowidlist $ym]
5560 if {$pprevidlist eq {}} continue
5566 for {} {$col < [llength $idlist]} {incr col} {
5567 set id [lindex $idlist $col]
5568 if {[lindex $previdlist $col] eq $id} continue
5573 set x0 [lsearch -exact $previdlist $id]
5574 if {$x0 < 0} continue
5575 set z [expr {$x0 - $col}]
5579 set xm [lsearch -exact $pprevidlist $id]
5581 set z0 [expr {$xm - $x0}]
5585 # if row y0 is the first child of $id then it's not an arrow
5586 if {[lindex $children($curview,$id) 0] ne
5587 [lindex $displayorder $y0]} {
5591 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5592 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5595 # Looking at lines from this row to the previous row,
5596 # make them go straight up if they end in an arrow on
5597 # the previous row; otherwise make them go straight up
5599 if {$z < -1 || ($z < 0 && $isarrow)} {
5600 # Line currently goes left too much;
5601 # insert pads in the previous row, then optimize it
5602 set npad [expr {-1 - $z + $isarrow}]
5603 insert_pad $y0 $x0 $npad
5605 optimize_rows $y0 $x0 $row
5607 set previdlist [lindex $rowidlist $y0]
5608 set x0 [lsearch -exact $previdlist $id]
5609 set z [expr {$x0 - $col}]
5611 set pprevidlist [lindex $rowidlist $ym]
5612 set xm [lsearch -exact $pprevidlist $id]
5613 set z0 [expr {$xm - $x0}]
5615 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5616 # Line currently goes right too much;
5617 # insert pads in this line
5618 set npad [expr {$z - 1 + $isarrow}]
5619 insert_pad $row $col $npad
5620 set idlist [lindex $rowidlist $row]
5622 set z [expr {$x0 - $col}]
5625 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5626 # this line links to its first child on row $row-2
5627 set id [lindex $displayorder $ym]
5628 set xc [lsearch -exact $pprevidlist $id]
5630 set z0 [expr {$xc - $x0}]
5633 # avoid lines jigging left then immediately right
5634 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5635 insert_pad $y0 $x0 1
5637 optimize_rows $y0 $x0 $row
5638 set previdlist [lindex $rowidlist $y0]
5642 # Find the first column that doesn't have a line going right
5643 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5644 set id [lindex $idlist $col]
5645 if {$id eq {}} break
5646 set x0 [lsearch -exact $previdlist $id]
5648 # check if this is the link to the first child
5649 set kid [lindex $displayorder $y0]
5650 if {[lindex $children($curview,$id) 0] eq $kid} {
5651 # it is, work out offset to child
5652 set x0 [lsearch -exact $previdlist $kid]
5655 if {$x0 <= $col} break
5657 # Insert a pad at that column as long as it has a line and
5658 # isn't the last column
5659 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5660 set idlist [linsert $idlist $col {}]
5661 lset rowidlist $row $idlist
5669 global canvx0 linespc
5670 return [expr {$canvx0 + $col * $linespc}]
5674 global canvy0 linespc
5675 return [expr {$canvy0 + $row * $linespc}]
5678 proc linewidth {id} {
5679 global thickerline lthickness
5682 if {[info exists thickerline] && $id eq $thickerline} {
5683 set wid [expr {2 * $lthickness}]
5688 proc rowranges {id} {
5689 global curview children uparrowlen downarrowlen
5692 set kids $children($curview,$id)
5698 foreach child $kids {
5699 if {![commitinview $child $curview]} break
5700 set row [rowofcommit $child]
5701 if {![info exists prev]} {
5702 lappend ret [expr {$row + 1}]
5704 if {$row <= $prevrow} {
5705 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5707 # see if the line extends the whole way from prevrow to row
5708 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5709 [lsearch -exact [lindex $rowidlist \
5710 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5711 # it doesn't, see where it ends
5712 set r [expr {$prevrow + $downarrowlen}]
5713 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5714 while {[incr r -1] > $prevrow &&
5715 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5717 while {[incr r] <= $row &&
5718 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5722 # see where it starts up again
5723 set r [expr {$row - $uparrowlen}]
5724 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5725 while {[incr r] < $row &&
5726 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5728 while {[incr r -1] >= $prevrow &&
5729 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5735 if {$child eq $id} {
5744 proc drawlineseg {id row endrow arrowlow} {
5745 global rowidlist displayorder iddrawn linesegs
5746 global canv colormap linespc curview maxlinelen parentlist
5748 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5749 set le [expr {$row + 1}]
5752 set c [lsearch -exact [lindex $rowidlist $le] $id]
5758 set x [lindex $displayorder $le]
5763 if {[info exists iddrawn($x)] || $le == $endrow} {
5764 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5780 if {[info exists linesegs($id)]} {
5781 set lines $linesegs($id)
5783 set r0 [lindex $li 0]
5785 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5795 set li [lindex $lines [expr {$i-1}]]
5796 set r1 [lindex $li 1]
5797 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5802 set x [lindex $cols [expr {$le - $row}]]
5803 set xp [lindex $cols [expr {$le - 1 - $row}]]
5804 set dir [expr {$xp - $x}]
5806 set ith [lindex $lines $i 2]
5807 set coords [$canv coords $ith]
5808 set ah [$canv itemcget $ith -arrow]
5809 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5810 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5811 if {$x2 ne {} && $x - $x2 == $dir} {
5812 set coords [lrange $coords 0 end-2]
5815 set coords [list [xc $le $x] [yc $le]]
5818 set itl [lindex $lines [expr {$i-1}] 2]
5819 set al [$canv itemcget $itl -arrow]
5820 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5821 } elseif {$arrowlow} {
5822 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5823 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5827 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5828 for {set y $le} {[incr y -1] > $row} {} {
5830 set xp [lindex $cols [expr {$y - 1 - $row}]]
5831 set ndir [expr {$xp - $x}]
5832 if {$dir != $ndir || $xp < 0} {
5833 lappend coords [xc $y $x] [yc $y]
5839 # join parent line to first child
5840 set ch [lindex $displayorder $row]
5841 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5843 puts "oops: drawlineseg: child $ch not on row $row"
5844 } elseif {$xc != $x} {
5845 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5846 set d [expr {int(0.5 * $linespc)}]
5849 set x2 [expr {$x1 - $d}]
5851 set x2 [expr {$x1 + $d}]
5854 set y1 [expr {$y2 + $d}]
5855 lappend coords $x1 $y1 $x2 $y2
5856 } elseif {$xc < $x - 1} {
5857 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5858 } elseif {$xc > $x + 1} {
5859 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5863 lappend coords [xc $row $x] [yc $row]
5865 set xn [xc $row $xp]
5867 lappend coords $xn $yn
5871 set t [$canv create line $coords -width [linewidth $id] \
5872 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5875 set lines [linsert $lines $i [list $row $le $t]]
5877 $canv coords $ith $coords
5878 if {$arrow ne $ah} {
5879 $canv itemconf $ith -arrow $arrow
5881 lset lines $i 0 $row
5884 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5885 set ndir [expr {$xo - $xp}]
5886 set clow [$canv coords $itl]
5887 if {$dir == $ndir} {
5888 set clow [lrange $clow 2 end]
5890 set coords [concat $coords $clow]
5892 lset lines [expr {$i-1}] 1 $le
5894 # coalesce two pieces
5896 set b [lindex $lines [expr {$i-1}] 0]
5897 set e [lindex $lines $i 1]
5898 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5900 $canv coords $itl $coords
5901 if {$arrow ne $al} {
5902 $canv itemconf $itl -arrow $arrow
5906 set linesegs($id) $lines
5910 proc drawparentlinks {id row} {
5911 global rowidlist canv colormap curview parentlist
5912 global idpos linespc
5914 set rowids [lindex $rowidlist $row]
5915 set col [lsearch -exact $rowids $id]
5916 if {$col < 0} return
5917 set olds [lindex $parentlist $row]
5918 set row2 [expr {$row + 1}]
5919 set x [xc $row $col]
5922 set d [expr {int(0.5 * $linespc)}]
5923 set ymid [expr {$y + $d}]
5924 set ids [lindex $rowidlist $row2]
5925 # rmx = right-most X coord used
5928 set i [lsearch -exact $ids $p]
5930 puts "oops, parent $p of $id not in list"
5933 set x2 [xc $row2 $i]
5937 set j [lsearch -exact $rowids $p]
5939 # drawlineseg will do this one for us
5943 # should handle duplicated parents here...
5944 set coords [list $x $y]
5946 # if attaching to a vertical segment, draw a smaller
5947 # slant for visual distinctness
5950 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5952 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5954 } elseif {$i < $col && $i < $j} {
5955 # segment slants towards us already
5956 lappend coords [xc $row $j] $y
5958 if {$i < $col - 1} {
5959 lappend coords [expr {$x2 + $linespc}] $y
5960 } elseif {$i > $col + 1} {
5961 lappend coords [expr {$x2 - $linespc}] $y
5963 lappend coords $x2 $y2
5966 lappend coords $x2 $y2
5968 set t [$canv create line $coords -width [linewidth $p] \
5969 -fill $colormap($p) -tags lines.$p]
5973 if {$rmx > [lindex $idpos($id) 1]} {
5974 lset idpos($id) 1 $rmx
5979 proc drawlines {id} {
5982 $canv itemconf lines.$id -width [linewidth $id]
5985 proc drawcmittext {id row col} {
5986 global linespc canv canv2 canv3 fgcolor curview
5987 global cmitlisted commitinfo rowidlist parentlist
5988 global rowtextx idpos idtags idheads idotherrefs
5989 global linehtag linentag linedtag selectedline
5990 global canvxmax boldids boldnameids fgcolor markedid
5991 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5992 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5993 global circleoutlinecolor
5995 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5996 set listed $cmitlisted($curview,$id)
5997 if {$id eq $nullid} {
5998 set ofill $workingfilescirclecolor
5999 } elseif {$id eq $nullid2} {
6000 set ofill $indexcirclecolor
6001 } elseif {$id eq $mainheadid} {
6002 set ofill $mainheadcirclecolor
6004 set ofill [lindex $circlecolors $listed]
6006 set x [xc $row $col]
6008 set orad [expr {$linespc / 3}]
6010 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6011 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6012 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6013 } elseif {$listed == 3} {
6014 # triangle pointing left for left-side commits
6015 set t [$canv create polygon \
6016 [expr {$x - $orad}] $y \
6017 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6018 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6019 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6021 # triangle pointing right for right-side commits
6022 set t [$canv create polygon \
6023 [expr {$x + $orad - 1}] $y \
6024 [expr {$x - $orad}] [expr {$y - $orad}] \
6025 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6026 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6028 set circleitem($row) $t
6030 $canv bind $t <1> {selcanvline {} %x %y}
6031 set rmx [llength [lindex $rowidlist $row]]
6032 set olds [lindex $parentlist $row]
6034 set nextids [lindex $rowidlist [expr {$row + 1}]]
6036 set i [lsearch -exact $nextids $p]
6042 set xt [xc $row $rmx]
6043 set rowtextx($row) $xt
6044 set idpos($id) [list $x $xt $y]
6045 if {[info exists idtags($id)] || [info exists idheads($id)]
6046 || [info exists idotherrefs($id)]} {
6047 set xt [drawtags $id $x $xt $y]
6049 if {[lindex $commitinfo($id) 6] > 0} {
6050 set xt [drawnotesign $xt $y]
6052 set headline [lindex $commitinfo($id) 0]
6053 set name [lindex $commitinfo($id) 1]
6054 set date [lindex $commitinfo($id) 2]
6055 set date [formatdate $date]
6058 set isbold [ishighlighted $id]
6061 set font mainfontbold
6063 lappend boldnameids $id
6064 set nfont mainfontbold
6067 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6068 -text $headline -font $font -tags text]
6069 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6070 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6071 -text $name -font $nfont -tags text]
6072 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6073 -text $date -font mainfont -tags text]
6074 if {$selectedline == $row} {
6077 if {[info exists markedid] && $markedid eq $id} {
6080 set xr [expr {$xt + [font measure $font $headline]}]
6081 if {$xr > $canvxmax} {
6087 proc drawcmitrow {row} {
6088 global displayorder rowidlist nrows_drawn
6089 global iddrawn markingmatches
6090 global commitinfo numcommits
6091 global filehighlight fhighlights findpattern nhighlights
6092 global hlview vhighlights
6093 global highlight_related rhighlights
6095 if {$row >= $numcommits} return
6097 set id [lindex $displayorder $row]
6098 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6099 askvhighlight $row $id
6101 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6102 askfilehighlight $row $id
6104 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6105 askfindhighlight $row $id
6107 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6108 askrelhighlight $row $id
6110 if {![info exists iddrawn($id)]} {
6111 set col [lsearch -exact [lindex $rowidlist $row] $id]
6113 puts "oops, row $row id $id not in list"
6116 if {![info exists commitinfo($id)]} {
6120 drawcmittext $id $row $col
6124 if {$markingmatches} {
6125 markrowmatches $row $id
6129 proc drawcommits {row {endrow {}}} {
6130 global numcommits iddrawn displayorder curview need_redisplay
6131 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6136 if {$endrow eq {}} {
6139 if {$endrow >= $numcommits} {
6140 set endrow [expr {$numcommits - 1}]
6143 set rl1 [expr {$row - $downarrowlen - 3}]
6147 set ro1 [expr {$row - 3}]
6151 set r2 [expr {$endrow + $uparrowlen + 3}]
6152 if {$r2 > $numcommits} {
6155 for {set r $rl1} {$r < $r2} {incr r} {
6156 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6160 set rl1 [expr {$r + 1}]
6166 optimize_rows $ro1 0 $r2
6167 if {$need_redisplay || $nrows_drawn > 2000} {
6171 # make the lines join to already-drawn rows either side
6172 set r [expr {$row - 1}]
6173 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6176 set er [expr {$endrow + 1}]
6177 if {$er >= $numcommits ||
6178 ![info exists iddrawn([lindex $displayorder $er])]} {
6181 for {} {$r <= $er} {incr r} {
6182 set id [lindex $displayorder $r]
6183 set wasdrawn [info exists iddrawn($id)]
6185 if {$r == $er} break
6186 set nextid [lindex $displayorder [expr {$r + 1}]]
6187 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6188 drawparentlinks $id $r
6190 set rowids [lindex $rowidlist $r]
6191 foreach lid $rowids {
6192 if {$lid eq {}} continue
6193 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6195 # see if this is the first child of any of its parents
6196 foreach p [lindex $parentlist $r] {
6197 if {[lsearch -exact $rowids $p] < 0} {
6198 # make this line extend up to the child
6199 set lineend($p) [drawlineseg $p $r $er 0]
6203 set lineend($lid) [drawlineseg $lid $r $er 1]
6209 proc undolayout {row} {
6210 global uparrowlen mingaplen downarrowlen
6211 global rowidlist rowisopt rowfinal need_redisplay
6213 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6217 if {[llength $rowidlist] > $r} {
6219 set rowidlist [lrange $rowidlist 0 $r]
6220 set rowfinal [lrange $rowfinal 0 $r]
6221 set rowisopt [lrange $rowisopt 0 $r]
6222 set need_redisplay 1
6227 proc drawvisible {} {
6228 global canv linespc curview vrowmod selectedline targetrow targetid
6229 global need_redisplay cscroll numcommits
6231 set fs [$canv yview]
6232 set ymax [lindex [$canv cget -scrollregion] 3]
6233 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6234 set f0 [lindex $fs 0]
6235 set f1 [lindex $fs 1]
6236 set y0 [expr {int($f0 * $ymax)}]
6237 set y1 [expr {int($f1 * $ymax)}]
6239 if {[info exists targetid]} {
6240 if {[commitinview $targetid $curview]} {
6241 set r [rowofcommit $targetid]
6242 if {$r != $targetrow} {
6243 # Fix up the scrollregion and change the scrolling position
6244 # now that our target row has moved.
6245 set diff [expr {($r - $targetrow) * $linespc}]
6248 set ymax [lindex [$canv cget -scrollregion] 3]
6251 set f0 [expr {$y0 / $ymax}]
6252 set f1 [expr {$y1 / $ymax}]
6253 allcanvs yview moveto $f0
6254 $cscroll set $f0 $f1
6255 set need_redisplay 1
6262 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6263 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6264 if {$endrow >= $vrowmod($curview)} {
6265 update_arcrows $curview
6267 if {$selectedline ne {} &&
6268 $row <= $selectedline && $selectedline <= $endrow} {
6269 set targetrow $selectedline
6270 } elseif {[info exists targetid]} {
6271 set targetrow [expr {int(($row + $endrow) / 2)}]
6273 if {[info exists targetrow]} {
6274 if {$targetrow >= $numcommits} {
6275 set targetrow [expr {$numcommits - 1}]
6277 set targetid [commitonrow $targetrow]
6279 drawcommits $row $endrow
6282 proc clear_display {} {
6283 global iddrawn linesegs need_redisplay nrows_drawn
6284 global vhighlights fhighlights nhighlights rhighlights
6285 global linehtag linentag linedtag boldids boldnameids
6288 catch {unset iddrawn}
6289 catch {unset linesegs}
6290 catch {unset linehtag}
6291 catch {unset linentag}
6292 catch {unset linedtag}
6295 catch {unset vhighlights}
6296 catch {unset fhighlights}
6297 catch {unset nhighlights}
6298 catch {unset rhighlights}
6299 set need_redisplay 0
6303 proc findcrossings {id} {
6304 global rowidlist parentlist numcommits displayorder
6308 foreach {s e} [rowranges $id] {
6309 if {$e >= $numcommits} {
6310 set e [expr {$numcommits - 1}]
6312 if {$e <= $s} continue
6313 for {set row $e} {[incr row -1] >= $s} {} {
6314 set x [lsearch -exact [lindex $rowidlist $row] $id]
6316 set olds [lindex $parentlist $row]
6317 set kid [lindex $displayorder $row]
6318 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6319 if {$kidx < 0} continue
6320 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6322 set px [lsearch -exact $nextrow $p]
6323 if {$px < 0} continue
6324 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6325 if {[lsearch -exact $ccross $p] >= 0} continue
6326 if {$x == $px + ($kidx < $px? -1: 1)} {
6328 } elseif {[lsearch -exact $cross $p] < 0} {
6335 return [concat $ccross {{}} $cross]
6338 proc assigncolor {id} {
6339 global colormap colors nextcolor
6340 global parents children children curview
6342 if {[info exists colormap($id)]} return
6343 set ncolors [llength $colors]
6344 if {[info exists children($curview,$id)]} {
6345 set kids $children($curview,$id)
6349 if {[llength $kids] == 1} {
6350 set child [lindex $kids 0]
6351 if {[info exists colormap($child)]
6352 && [llength $parents($curview,$child)] == 1} {
6353 set colormap($id) $colormap($child)
6359 foreach x [findcrossings $id] {
6361 # delimiter between corner crossings and other crossings
6362 if {[llength $badcolors] >= $ncolors - 1} break
6363 set origbad $badcolors
6365 if {[info exists colormap($x)]
6366 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6367 lappend badcolors $colormap($x)
6370 if {[llength $badcolors] >= $ncolors} {
6371 set badcolors $origbad
6373 set origbad $badcolors
6374 if {[llength $badcolors] < $ncolors - 1} {
6375 foreach child $kids {
6376 if {[info exists colormap($child)]
6377 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6378 lappend badcolors $colormap($child)
6380 foreach p $parents($curview,$child) {
6381 if {[info exists colormap($p)]
6382 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6383 lappend badcolors $colormap($p)
6387 if {[llength $badcolors] >= $ncolors} {
6388 set badcolors $origbad
6391 for {set i 0} {$i <= $ncolors} {incr i} {
6392 set c [lindex $colors $nextcolor]
6393 if {[incr nextcolor] >= $ncolors} {
6396 if {[lsearch -exact $badcolors $c]} break
6398 set colormap($id) $c
6401 proc bindline {t id} {
6404 $canv bind $t <Enter> "lineenter %x %y $id"
6405 $canv bind $t <Motion> "linemotion %x %y $id"
6406 $canv bind $t <Leave> "lineleave $id"
6407 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6410 proc graph_pane_width {} {
6414 set g [.tf.histframe.pwclist sashpos 0]
6416 set g [.tf.histframe.pwclist sash coord 0]
6418 return [lindex $g 0]
6421 proc totalwidth {l font extra} {
6424 set tot [expr {$tot + [font measure $font $str] + $extra}]
6429 proc drawtags {id x xt y1} {
6430 global idtags idheads idotherrefs mainhead
6431 global linespc lthickness
6432 global canv rowtextx curview fgcolor bgcolor ctxbut
6433 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6434 global tagbgcolor tagfgcolor tagoutlinecolor
6443 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6444 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6445 set extra [expr {$delta + $lthickness + $linespc}]
6447 if {[info exists idtags($id)]} {
6448 set marks $idtags($id)
6449 set ntags [llength $marks]
6450 if {$ntags > $maxtags ||
6451 [totalwidth $marks mainfont $extra] > $maxwidth} {
6452 # show just a single "n tags..." tag
6455 set marks [list "tag..."]
6457 set marks [list [format "%d tags..." $ntags]]
6462 if {[info exists idheads($id)]} {
6463 set marks [concat $marks $idheads($id)]
6464 set nheads [llength $idheads($id)]
6466 if {[info exists idotherrefs($id)]} {
6467 set marks [concat $marks $idotherrefs($id)]
6473 set yt [expr {$y1 - 0.5 * $linespc}]
6474 set yb [expr {$yt + $linespc - 1}]
6478 foreach tag $marks {
6480 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6481 set wid [font measure mainfontbold $tag]
6483 set wid [font measure mainfont $tag]
6487 set xt [expr {$xt + $wid + $extra}]
6489 set yl [expr {$y1 - $lthickness}]
6490 set t [$canv create line $x $yl [lindex $xvals end] $yl \
6491 -width $lthickness -fill $reflinecolor -tags tag.$id]
6493 foreach tag $marks x $xvals wid $wvals {
6494 set tag_quoted [string map {% %%} $tag]
6495 set xl [expr {$x + $delta}]
6496 set xr [expr {$x + $delta + $wid + $lthickness}]
6498 if {[incr ntags -1] >= 0} {
6500 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6501 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6502 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6505 set tagclick [list showtags $id 1]
6507 set tagclick [list showtag $tag_quoted 1]
6509 $canv bind $t <1> $tagclick
6510 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6512 # draw a head or other ref
6513 if {[incr nheads -1] >= 0} {
6514 set col $headbgcolor
6515 if {$tag eq $mainhead} {
6516 set font mainfontbold
6521 set xl [expr {$xl - $delta/2}]
6522 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6523 -width 1 -outline black -fill $col -tags tag.$id
6524 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6525 set rwid [font measure mainfont $remoteprefix]
6526 set xi [expr {$x + 1}]
6527 set yti [expr {$yt + 1}]
6528 set xri [expr {$x + $rwid}]
6529 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6530 -width 0 -fill $remotebgcolor -tags tag.$id
6533 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6534 -font $font -tags [list tag.$id text]]
6536 $canv bind $t <1> $tagclick
6537 } elseif {$nheads >= 0} {
6538 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6544 proc drawnotesign {xt y} {
6545 global linespc canv fgcolor
6547 set orad [expr {$linespc / 3}]
6548 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6549 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6550 -fill yellow -outline $fgcolor -width 1 -tags circle]
6551 set xt [expr {$xt + $orad * 3}]
6555 proc xcoord {i level ln} {
6556 global canvx0 xspc1 xspc2
6558 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6559 if {$i > 0 && $i == $level} {
6560 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6561 } elseif {$i > $level} {
6562 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6567 proc show_status {msg} {
6571 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6572 -tags text -fill $fgcolor
6575 # Don't change the text pane cursor if it is currently the hand cursor,
6576 # showing that we are over a sha1 ID link.
6577 proc settextcursor {c} {
6578 global ctext curtextcursor
6580 if {[$ctext cget -cursor] == $curtextcursor} {
6581 $ctext config -cursor $c
6583 set curtextcursor $c
6586 proc nowbusy {what {name {}}} {
6587 global isbusy busyname statusw
6589 if {[array names isbusy] eq {}} {
6590 . config -cursor watch
6594 set busyname($what) $name
6596 $statusw conf -text $name
6600 proc notbusy {what} {
6601 global isbusy maincursor textcursor busyname statusw
6605 if {$busyname($what) ne {} &&
6606 [$statusw cget -text] eq $busyname($what)} {
6607 $statusw conf -text {}
6610 if {[array names isbusy] eq {}} {
6611 . config -cursor $maincursor
6612 settextcursor $textcursor
6616 proc findmatches {f} {
6617 global findtype findstring
6618 if {$findtype == [mc "Regexp"]} {
6619 set matches [regexp -indices -all -inline $findstring $f]
6622 if {$findtype == [mc "IgnCase"]} {
6623 set f [string tolower $f]
6624 set fs [string tolower $fs]
6628 set l [string length $fs]
6629 while {[set j [string first $fs $f $i]] >= 0} {
6630 lappend matches [list $j [expr {$j+$l-1}]]
6631 set i [expr {$j + $l}]
6637 proc dofind {{dirn 1} {wrap 1}} {
6638 global findstring findstartline findcurline selectedline numcommits
6639 global gdttype filehighlight fh_serial find_dirn findallowwrap
6641 if {[info exists find_dirn]} {
6642 if {$find_dirn == $dirn} return
6646 if {$findstring eq {} || $numcommits == 0} return
6647 if {$selectedline eq {}} {
6648 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6650 set findstartline $selectedline
6652 set findcurline $findstartline
6653 nowbusy finding [mc "Searching"]
6654 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6655 after cancel do_file_hl $fh_serial
6656 do_file_hl $fh_serial
6659 set findallowwrap $wrap
6663 proc stopfinding {} {
6664 global find_dirn findcurline fprogcoord
6666 if {[info exists find_dirn]} {
6677 global commitdata commitinfo numcommits findpattern findloc
6678 global findstartline findcurline findallowwrap
6679 global find_dirn gdttype fhighlights fprogcoord
6680 global curview varcorder vrownum varccommits vrowmod
6682 if {![info exists find_dirn]} {
6685 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6688 if {$find_dirn > 0} {
6690 if {$l >= $numcommits} {
6693 if {$l <= $findstartline} {
6694 set lim [expr {$findstartline + 1}]
6697 set moretodo $findallowwrap
6704 if {$l >= $findstartline} {
6705 set lim [expr {$findstartline - 1}]
6708 set moretodo $findallowwrap
6711 set n [expr {($lim - $l) * $find_dirn}]
6716 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6717 update_arcrows $curview
6721 set ai [bsearch $vrownum($curview) $l]
6722 set a [lindex $varcorder($curview) $ai]
6723 set arow [lindex $vrownum($curview) $ai]
6724 set ids [lindex $varccommits($curview,$a)]
6725 set arowend [expr {$arow + [llength $ids]}]
6726 if {$gdttype eq [mc "containing:"]} {
6727 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6728 if {$l < $arow || $l >= $arowend} {
6730 set a [lindex $varcorder($curview) $ai]
6731 set arow [lindex $vrownum($curview) $ai]
6732 set ids [lindex $varccommits($curview,$a)]
6733 set arowend [expr {$arow + [llength $ids]}]
6735 set id [lindex $ids [expr {$l - $arow}]]
6736 # shouldn't happen unless git log doesn't give all the commits...
6737 if {![info exists commitdata($id)] ||
6738 ![doesmatch $commitdata($id)]} {
6741 if {![info exists commitinfo($id)]} {
6744 set info $commitinfo($id)
6745 foreach f $info ty $fldtypes {
6746 if {$ty eq ""} continue
6747 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6756 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6757 if {$l < $arow || $l >= $arowend} {
6759 set a [lindex $varcorder($curview) $ai]
6760 set arow [lindex $vrownum($curview) $ai]
6761 set ids [lindex $varccommits($curview,$a)]
6762 set arowend [expr {$arow + [llength $ids]}]
6764 set id [lindex $ids [expr {$l - $arow}]]
6765 if {![info exists fhighlights($id)]} {
6766 # this sets fhighlights($id) to -1
6767 askfilehighlight $l $id
6769 if {$fhighlights($id) > 0} {
6773 if {$fhighlights($id) < 0} {
6776 set findcurline [expr {$l - $find_dirn}]
6781 if {$found || ($domore && !$moretodo)} {
6797 set findcurline [expr {$l - $find_dirn}]
6799 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6803 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6808 proc findselectline {l} {
6809 global findloc commentend ctext findcurline markingmatches gdttype
6811 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6814 if {$markingmatches &&
6815 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6816 # highlight the matches in the comments
6817 set f [$ctext get 1.0 $commentend]
6818 set matches [findmatches $f]
6819 foreach match $matches {
6820 set start [lindex $match 0]
6821 set end [expr {[lindex $match 1] + 1}]
6822 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6828 # mark the bits of a headline or author that match a find string
6829 proc markmatches {canv l str tag matches font row} {
6832 set bbox [$canv bbox $tag]
6833 set x0 [lindex $bbox 0]
6834 set y0 [lindex $bbox 1]
6835 set y1 [lindex $bbox 3]
6836 foreach match $matches {
6837 set start [lindex $match 0]
6838 set end [lindex $match 1]
6839 if {$start > $end} continue
6840 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6841 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6842 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6843 [expr {$x0+$xlen+2}] $y1 \
6844 -outline {} -tags [list match$l matches] -fill yellow]
6846 if {$row == $selectedline} {
6847 $canv raise $t secsel
6852 proc unmarkmatches {} {
6853 global markingmatches
6855 allcanvs delete matches
6856 set markingmatches 0
6860 proc selcanvline {w x y} {
6861 global canv canvy0 ctext linespc
6863 set ymax [lindex [$canv cget -scrollregion] 3]
6864 if {$ymax == {}} return
6865 set yfrac [lindex [$canv yview] 0]
6866 set y [expr {$y + $yfrac * $ymax}]
6867 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6872 set xmax [lindex [$canv cget -scrollregion] 2]
6873 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6874 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6880 proc commit_descriptor {p} {
6882 if {![info exists commitinfo($p)]} {
6886 if {[llength $commitinfo($p)] > 1} {
6887 set l [lindex $commitinfo($p) 0]
6892 # append some text to the ctext widget, and make any SHA1 ID
6893 # that we know about be a clickable link.
6894 proc appendwithlinks {text tags} {
6895 global ctext linknum curview
6897 set start [$ctext index "end - 1c"]
6898 $ctext insert end $text $tags
6899 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6903 set linkid [string range $text $s $e]
6905 $ctext tag delete link$linknum
6906 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6907 setlink $linkid link$linknum
6912 proc setlink {id lk} {
6913 global curview ctext pendinglinks
6916 if {[string range $id 0 1] eq "-g"} {
6917 set id [string range $id 2 end]
6921 if {[string length $id] < 40} {
6922 set matches [longid $id]
6923 if {[llength $matches] > 0} {
6924 if {[llength $matches] > 1} return
6926 set id [lindex $matches 0]
6929 set known [commitinview $id $curview]
6932 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6933 $ctext tag bind $lk <1> [list selbyid $id]
6934 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6935 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6937 lappend pendinglinks($id) $lk
6938 interestedin $id {makelink %P}
6942 proc appendshortlink {id {pre {}} {post {}}} {
6943 global ctext linknum
6945 $ctext insert end $pre
6946 $ctext tag delete link$linknum
6947 $ctext insert end [string range $id 0 7] link$linknum
6948 $ctext insert end $post
6949 setlink $id link$linknum
6953 proc makelink {id} {
6956 if {![info exists pendinglinks($id)]} return
6957 foreach lk $pendinglinks($id) {
6960 unset pendinglinks($id)
6963 proc linkcursor {w inc} {
6964 global linkentercount curtextcursor
6966 if {[incr linkentercount $inc] > 0} {
6967 $w configure -cursor hand2
6969 $w configure -cursor $curtextcursor
6970 if {$linkentercount < 0} {
6971 set linkentercount 0
6976 proc viewnextline {dir} {
6980 set ymax [lindex [$canv cget -scrollregion] 3]
6981 set wnow [$canv yview]
6982 set wtop [expr {[lindex $wnow 0] * $ymax}]
6983 set newtop [expr {$wtop + $dir * $linespc}]
6986 } elseif {$newtop > $ymax} {
6989 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6992 # add a list of tag or branch names at position pos
6993 # returns the number of names inserted
6994 proc appendrefs {pos ids var} {
6995 global ctext linknum curview $var maxrefs mainheadid
6997 if {[catch {$ctext index $pos}]} {
7000 $ctext conf -state normal
7001 $ctext delete $pos "$pos lineend"
7004 foreach tag [set $var\($id\)] {
7005 lappend tags [list $tag $id]
7010 set tags [lsort -index 0 -decreasing $tags]
7013 if {[llength $tags] > $maxrefs} {
7014 # If we are displaying heads, and there are too many,
7015 # see if there are some important heads to display.
7016 # Currently this means "master" and the current head.
7018 if {$var eq "idheads"} {
7021 set hname [lindex $ti 0]
7022 set id [lindex $ti 1]
7023 if {($hname eq "master" || $id eq $mainheadid) &&
7024 [llength $itags] < $maxrefs} {
7033 set str [mc "and many more"]
7038 $ctext insert $pos "$str ([llength $tags])"
7039 set nutags [llength $tags]
7044 set id [lindex $ti 1]
7047 $ctext tag delete $lk
7048 $ctext insert $pos $sep
7049 $ctext insert $pos [lindex $ti 0] $lk
7053 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7054 $ctext conf -state disabled
7055 return [expr {[llength $tags] + $nutags}]
7058 # called when we have finished computing the nearby tags
7059 proc dispneartags {delay} {
7060 global selectedline currentid showneartags tagphase
7062 if {$selectedline eq {} || !$showneartags} return
7063 after cancel dispnexttag
7065 after 200 dispnexttag
7068 after idle dispnexttag
7073 proc dispnexttag {} {
7074 global selectedline currentid showneartags tagphase ctext
7076 if {$selectedline eq {} || !$showneartags} return
7077 switch -- $tagphase {
7079 set dtags [desctags $currentid]
7081 appendrefs precedes $dtags idtags
7085 set atags [anctags $currentid]
7087 appendrefs follows $atags idtags
7091 set dheads [descheads $currentid]
7092 if {$dheads ne {}} {
7093 if {[appendrefs branch $dheads idheads] > 1
7094 && [$ctext get "branch -3c"] eq "h"} {
7095 # turn "Branch" into "Branches"
7096 $ctext conf -state normal
7097 $ctext insert "branch -2c" "es"
7098 $ctext conf -state disabled
7103 if {[incr tagphase] <= 2} {
7104 after idle dispnexttag
7108 proc make_secsel {id} {
7109 global linehtag linentag linedtag canv canv2 canv3
7111 if {![info exists linehtag($id)]} return
7113 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7114 -tags secsel -fill [$canv cget -selectbackground]]
7116 $canv2 delete secsel
7117 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7118 -tags secsel -fill [$canv2 cget -selectbackground]]
7120 $canv3 delete secsel
7121 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7122 -tags secsel -fill [$canv3 cget -selectbackground]]
7126 proc make_idmark {id} {
7127 global linehtag canv fgcolor
7129 if {![info exists linehtag($id)]} return
7131 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7132 -tags markid -outline $fgcolor]
7136 proc selectline {l isnew {desired_loc {}}} {
7137 global canv ctext commitinfo selectedline
7138 global canvy0 linespc parents children curview
7139 global currentid sha1entry
7140 global commentend idtags linknum
7141 global mergemax numcommits pending_select
7142 global cmitmode showneartags allcommits
7143 global targetrow targetid lastscrollrows
7144 global autoselect autosellen jump_to_here
7147 catch {unset pending_select}
7152 if {$l < 0 || $l >= $numcommits} return
7153 set id [commitonrow $l]
7158 if {$lastscrollrows < $numcommits} {
7162 set y [expr {$canvy0 + $l * $linespc}]
7163 set ymax [lindex [$canv cget -scrollregion] 3]
7164 set ytop [expr {$y - $linespc - 1}]
7165 set ybot [expr {$y + $linespc + 1}]
7166 set wnow [$canv yview]
7167 set wtop [expr {[lindex $wnow 0] * $ymax}]
7168 set wbot [expr {[lindex $wnow 1] * $ymax}]
7169 set wh [expr {$wbot - $wtop}]
7171 if {$ytop < $wtop} {
7172 if {$ybot < $wtop} {
7173 set newtop [expr {$y - $wh / 2.0}]
7176 if {$newtop > $wtop - $linespc} {
7177 set newtop [expr {$wtop - $linespc}]
7180 } elseif {$ybot > $wbot} {
7181 if {$ytop > $wbot} {
7182 set newtop [expr {$y - $wh / 2.0}]
7184 set newtop [expr {$ybot - $wh}]
7185 if {$newtop < $wtop + $linespc} {
7186 set newtop [expr {$wtop + $linespc}]
7190 if {$newtop != $wtop} {
7194 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7201 addtohistory [list selbyid $id 0] savecmitpos
7204 $sha1entry delete 0 end
7205 $sha1entry insert 0 $id
7207 $sha1entry selection range 0 $autosellen
7211 $ctext conf -state normal
7214 if {![info exists commitinfo($id)]} {
7217 set info $commitinfo($id)
7218 set date [formatdate [lindex $info 2]]
7219 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7220 set date [formatdate [lindex $info 4]]
7221 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7222 if {[info exists idtags($id)]} {
7223 $ctext insert end [mc "Tags:"]
7224 foreach tag $idtags($id) {
7225 $ctext insert end " $tag"
7227 $ctext insert end "\n"
7231 set olds $parents($curview,$id)
7232 if {[llength $olds] > 1} {
7235 if {$np >= $mergemax} {
7240 $ctext insert end "[mc "Parent"]: " $tag
7241 appendwithlinks [commit_descriptor $p] {}
7246 append headers "[mc "Parent"]: [commit_descriptor $p]"
7250 foreach c $children($curview,$id) {
7251 append headers "[mc "Child"]: [commit_descriptor $c]"
7254 # make anything that looks like a SHA1 ID be a clickable link
7255 appendwithlinks $headers {}
7256 if {$showneartags} {
7257 if {![info exists allcommits]} {
7260 $ctext insert end "[mc "Branch"]: "
7261 $ctext mark set branch "end -1c"
7262 $ctext mark gravity branch left
7263 $ctext insert end "\n[mc "Follows"]: "
7264 $ctext mark set follows "end -1c"
7265 $ctext mark gravity follows left
7266 $ctext insert end "\n[mc "Precedes"]: "
7267 $ctext mark set precedes "end -1c"
7268 $ctext mark gravity precedes left
7269 $ctext insert end "\n"
7272 $ctext insert end "\n"
7273 set comment [lindex $info 5]
7274 if {[string first "\r" $comment] >= 0} {
7275 set comment [string map {"\r" "\n "} $comment]
7277 appendwithlinks $comment {comment}
7279 $ctext tag remove found 1.0 end
7280 $ctext conf -state disabled
7281 set commentend [$ctext index "end - 1c"]
7283 set jump_to_here $desired_loc
7284 init_flist [mc "Comments"]
7285 if {$cmitmode eq "tree"} {
7287 } elseif {$vinlinediff($curview) == 1} {
7289 } elseif {[llength $olds] <= 1} {
7296 proc selfirstline {} {
7301 proc sellastline {} {
7304 set l [expr {$numcommits - 1}]
7308 proc selnextline {dir} {
7311 if {$selectedline eq {}} return
7312 set l [expr {$selectedline + $dir}]
7317 proc selnextpage {dir} {
7318 global canv linespc selectedline numcommits
7320 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7324 allcanvs yview scroll [expr {$dir * $lpp}] units
7326 if {$selectedline eq {}} return
7327 set l [expr {$selectedline + $dir * $lpp}]
7330 } elseif {$l >= $numcommits} {
7331 set l [expr $numcommits - 1]
7337 proc unselectline {} {
7338 global selectedline currentid
7341 catch {unset currentid}
7342 allcanvs delete secsel
7346 proc reselectline {} {
7349 if {$selectedline ne {}} {
7350 selectline $selectedline 0
7354 proc addtohistory {cmd {saveproc {}}} {
7355 global history historyindex curview
7359 set elt [list $curview $cmd $saveproc {}]
7360 if {$historyindex > 0
7361 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7365 if {$historyindex < [llength $history]} {
7366 set history [lreplace $history $historyindex end $elt]
7368 lappend history $elt
7371 if {$historyindex > 1} {
7372 .tf.bar.leftbut conf -state normal
7374 .tf.bar.leftbut conf -state disabled
7376 .tf.bar.rightbut conf -state disabled
7379 # save the scrolling position of the diff display pane
7380 proc save_position {} {
7381 global historyindex history
7383 if {$historyindex < 1} return
7384 set hi [expr {$historyindex - 1}]
7385 set fn [lindex $history $hi 2]
7387 lset history $hi 3 [eval $fn]
7391 proc unset_posvars {} {
7394 if {[info exists last_posvars]} {
7395 foreach {var val} $last_posvars {
7404 global curview last_posvars
7406 set view [lindex $elt 0]
7407 set cmd [lindex $elt 1]
7408 set pv [lindex $elt 3]
7409 if {$curview != $view} {
7413 foreach {var val} $pv {
7417 set last_posvars $pv
7422 global history historyindex
7425 if {$historyindex > 1} {
7427 incr historyindex -1
7428 godo [lindex $history [expr {$historyindex - 1}]]
7429 .tf.bar.rightbut conf -state normal
7431 if {$historyindex <= 1} {
7432 .tf.bar.leftbut conf -state disabled
7437 global history historyindex
7440 if {$historyindex < [llength $history]} {
7442 set cmd [lindex $history $historyindex]
7445 .tf.bar.leftbut conf -state normal
7447 if {$historyindex >= [llength $history]} {
7448 .tf.bar.rightbut conf -state disabled
7453 global treefilelist treeidlist diffids diffmergeid treepending
7454 global nullid nullid2
7457 catch {unset diffmergeid}
7458 if {![info exists treefilelist($id)]} {
7459 if {![info exists treepending]} {
7460 if {$id eq $nullid} {
7461 set cmd [list | git ls-files]
7462 } elseif {$id eq $nullid2} {
7463 set cmd [list | git ls-files --stage -t]
7465 set cmd [list | git ls-tree -r $id]
7467 if {[catch {set gtf [open $cmd r]}]} {
7471 set treefilelist($id) {}
7472 set treeidlist($id) {}
7473 fconfigure $gtf -blocking 0 -encoding binary
7474 filerun $gtf [list gettreeline $gtf $id]
7481 proc gettreeline {gtf id} {
7482 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7485 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7486 if {$diffids eq $nullid} {
7489 set i [string first "\t" $line]
7490 if {$i < 0} continue
7491 set fname [string range $line [expr {$i+1}] end]
7492 set line [string range $line 0 [expr {$i-1}]]
7493 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7494 set sha1 [lindex $line 2]
7495 lappend treeidlist($id) $sha1
7497 if {[string index $fname 0] eq "\""} {
7498 set fname [lindex $fname 0]
7500 set fname [encoding convertfrom $fname]
7501 lappend treefilelist($id) $fname
7504 return [expr {$nl >= 1000? 2: 1}]
7508 if {$cmitmode ne "tree"} {
7509 if {![info exists diffmergeid]} {
7510 gettreediffs $diffids
7512 } elseif {$id ne $diffids} {
7521 global treefilelist treeidlist diffids nullid nullid2
7522 global ctext_file_names ctext_file_lines
7523 global ctext commentend
7525 set i [lsearch -exact $treefilelist($diffids) $f]
7527 puts "oops, $f not in list for id $diffids"
7530 if {$diffids eq $nullid} {
7531 if {[catch {set bf [open $f r]} err]} {
7532 puts "oops, can't read $f: $err"
7536 set blob [lindex $treeidlist($diffids) $i]
7537 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7538 puts "oops, error reading blob $blob: $err"
7542 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7543 filerun $bf [list getblobline $bf $diffids]
7544 $ctext config -state normal
7545 clear_ctext $commentend
7546 lappend ctext_file_names $f
7547 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7548 $ctext insert end "\n"
7549 $ctext insert end "$f\n" filesep
7550 $ctext config -state disabled
7551 $ctext yview $commentend
7555 proc getblobline {bf id} {
7556 global diffids cmitmode ctext
7558 if {$id ne $diffids || $cmitmode ne "tree"} {
7562 $ctext config -state normal
7564 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7565 $ctext insert end "$line\n"
7568 global jump_to_here ctext_file_names commentend
7570 # delete last newline
7571 $ctext delete "end - 2c" "end - 1c"
7573 if {$jump_to_here ne {} &&
7574 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7575 set lnum [expr {[lindex $jump_to_here 1] +
7576 [lindex [split $commentend .] 0]}]
7577 mark_ctext_line $lnum
7579 $ctext config -state disabled
7582 $ctext config -state disabled
7583 return [expr {$nl >= 1000? 2: 1}]
7586 proc mark_ctext_line {lnum} {
7587 global ctext markbgcolor
7589 $ctext tag delete omark
7590 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7591 $ctext tag conf omark -background $markbgcolor
7595 proc mergediff {id} {
7597 global diffids treediffs
7598 global parents curview
7602 set treediffs($id) {}
7603 set np [llength $parents($curview,$id)]
7608 proc startdiff {ids} {
7609 global treediffs diffids treepending diffmergeid nullid nullid2
7613 catch {unset diffmergeid}
7614 if {![info exists treediffs($ids)] ||
7615 [lsearch -exact $ids $nullid] >= 0 ||
7616 [lsearch -exact $ids $nullid2] >= 0} {
7617 if {![info exists treepending]} {
7625 proc showinlinediff {ids} {
7626 global commitinfo commitdata ctext
7629 set info $commitinfo($ids)
7630 set diff [lindex $info 7]
7631 set difflines [split $diff "\n"]
7637 foreach line $difflines {
7638 if {![string compare -length 5 "diff " $line]} {
7640 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7641 # offset also accounts for the b/ prefix
7642 lappend treediff [string range $line 6 end]
7647 set treediffs($ids) $treediff
7650 $ctext conf -state normal
7651 foreach line $difflines {
7652 parseblobdiffline $ids $line
7654 maybe_scroll_ctext 1
7655 $ctext conf -state disabled
7658 # If the filename (name) is under any of the passed filter paths
7659 # then return true to include the file in the listing.
7660 proc path_filter {filter name} {
7661 set worktree [gitworktree]
7663 set fq_p [file normalize $p]
7664 set fq_n [file normalize [file join $worktree $name]]
7665 if {[string match [file normalize $fq_p]* $fq_n]} {
7672 proc addtocflist {ids} {
7675 add_flist $treediffs($ids)
7679 proc diffcmd {ids flags} {
7680 global log_showroot nullid nullid2
7682 set i [lsearch -exact $ids $nullid]
7683 set j [lsearch -exact $ids $nullid2]
7685 if {[llength $ids] > 1 && $j < 0} {
7686 # comparing working directory with some specific revision
7687 set cmd [concat | git diff-index $flags]
7689 lappend cmd -R [lindex $ids 1]
7691 lappend cmd [lindex $ids 0]
7694 # comparing working directory with index
7695 set cmd [concat | git diff-files $flags]
7700 } elseif {$j >= 0} {
7701 set cmd [concat | git diff-index --cached $flags]
7702 if {[llength $ids] > 1} {
7703 # comparing index with specific revision
7705 lappend cmd -R [lindex $ids 1]
7707 lappend cmd [lindex $ids 0]
7710 # comparing index with HEAD
7714 if {$log_showroot} {
7715 lappend flags --root
7717 set cmd [concat | git diff-tree -r $flags $ids]
7722 proc gettreediffs {ids} {
7723 global treediff treepending limitdiffs vfilelimit curview
7725 set cmd [diffcmd $ids {--no-commit-id}]
7726 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7727 set cmd [concat $cmd -- $vfilelimit($curview)]
7729 if {[catch {set gdtf [open $cmd r]}]} return
7731 set treepending $ids
7733 fconfigure $gdtf -blocking 0 -encoding binary
7734 filerun $gdtf [list gettreediffline $gdtf $ids]
7737 proc gettreediffline {gdtf ids} {
7738 global treediff treediffs treepending diffids diffmergeid
7739 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7744 if {$perfile_attrs} {
7745 # cache_gitattr is slow, and even slower on win32 where we
7746 # have to invoke it for only about 30 paths at a time
7748 if {[tk windowingsystem] == "win32"} {
7752 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7753 set i [string first "\t" $line]
7755 set file [string range $line [expr {$i+1}] end]
7756 if {[string index $file 0] eq "\""} {
7757 set file [lindex $file 0]
7759 set file [encoding convertfrom $file]
7760 if {$file ne [lindex $treediff end]} {
7761 lappend treediff $file
7762 lappend sublist $file
7766 if {$perfile_attrs} {
7767 cache_gitattr encoding $sublist
7770 return [expr {$nr >= $max? 2: 1}]
7773 set treediffs($ids) $treediff
7775 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7777 } elseif {$ids != $diffids} {
7778 if {![info exists diffmergeid]} {
7779 gettreediffs $diffids
7787 # empty string or positive integer
7788 proc diffcontextvalidate {v} {
7789 return [regexp {^(|[1-9][0-9]*)$} $v]
7792 proc diffcontextchange {n1 n2 op} {
7793 global diffcontextstring diffcontext
7795 if {[string is integer -strict $diffcontextstring]} {
7796 if {$diffcontextstring >= 0} {
7797 set diffcontext $diffcontextstring
7803 proc changeignorespace {} {
7807 proc changeworddiff {name ix op} {
7811 proc initblobdiffvars {} {
7812 global diffencoding targetline diffnparents
7813 global diffinhdr currdiffsubmod diffseehere
7817 set diffencoding [get_path_encoding {}]
7818 set currdiffsubmod ""
7822 proc getblobdiffs {ids} {
7823 global blobdifffd diffids env
7828 global limitdiffs vfilelimit curview
7832 if {[package vcompare $git_version "1.6.1"] >= 0} {
7833 set textconv "--textconv"
7836 if {[package vcompare $git_version "1.6.6"] >= 0} {
7837 set submodule "--submodule"
7839 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7843 if {$worddiff ne [mc "Line diff"]} {
7844 append cmd " --word-diff=porcelain"
7846 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7847 set cmd [concat $cmd -- $vfilelimit($curview)]
7849 if {[catch {set bdf [open $cmd r]} err]} {
7850 error_popup [mc "Error getting diffs: %s" $err]
7853 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7854 set blobdifffd($ids) $bdf
7856 filerun $bdf [list getblobdiffline $bdf $diffids]
7859 proc savecmitpos {} {
7860 global ctext cmitmode
7862 if {$cmitmode eq "tree"} {
7865 return [list target_scrollpos [$ctext index @0,0]]
7868 proc savectextpos {} {
7871 return [list target_scrollpos [$ctext index @0,0]]
7874 proc maybe_scroll_ctext {ateof} {
7875 global ctext target_scrollpos
7877 if {![info exists target_scrollpos]} return
7879 set nlines [expr {[winfo height $ctext]
7880 / [font metrics textfont -linespace]}]
7881 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7883 $ctext yview $target_scrollpos
7884 unset target_scrollpos
7887 proc setinlist {var i val} {
7890 while {[llength [set $var]] < $i} {
7893 if {[llength [set $var]] == $i} {
7900 proc makediffhdr {fname ids} {
7901 global ctext curdiffstart treediffs diffencoding
7902 global ctext_file_names jump_to_here targetline diffline
7904 set fname [encoding convertfrom $fname]
7905 set diffencoding [get_path_encoding $fname]
7906 set i [lsearch -exact $treediffs($ids) $fname]
7908 setinlist difffilestart $i $curdiffstart
7910 lset ctext_file_names end $fname
7911 set l [expr {(78 - [string length $fname]) / 2}]
7912 set pad [string range "----------------------------------------" 1 $l]
7913 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7915 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7916 set targetline [lindex $jump_to_here 1]
7921 proc blobdiffmaybeseehere {ateof} {
7923 if {$diffseehere >= 0} {
7924 mark_ctext_line [lindex [split $diffseehere .] 0]
7926 maybe_scroll_ctext ateof
7929 proc getblobdiffline {bdf ids} {
7930 global diffids blobdifffd
7934 $ctext conf -state normal
7935 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7936 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7940 parseblobdiffline $ids $line
7942 $ctext conf -state disabled
7943 blobdiffmaybeseehere [eof $bdf]
7948 return [expr {$nr >= 1000? 2: 1}]
7951 proc parseblobdiffline {ids line} {
7952 global ctext curdiffstart
7953 global diffnexthead diffnextnote difffilestart
7954 global ctext_file_names ctext_file_lines
7955 global diffinhdr treediffs mergemax diffnparents
7956 global diffencoding jump_to_here targetline diffline currdiffsubmod
7957 global worddiff diffseehere
7959 if {![string compare -length 5 "diff " $line]} {
7960 if {![regexp {^diff (--cc|--git) } $line m type]} {
7961 set line [encoding convertfrom $line]
7962 $ctext insert end "$line\n" hunksep
7965 # start of a new file
7967 $ctext insert end "\n"
7968 set curdiffstart [$ctext index "end - 1c"]
7969 lappend ctext_file_names ""
7970 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7971 $ctext insert end "\n" filesep
7973 if {$type eq "--cc"} {
7974 # start of a new file in a merge diff
7975 set fname [string range $line 10 end]
7976 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7977 lappend treediffs($ids) $fname
7978 add_flist [list $fname]
7982 set line [string range $line 11 end]
7983 # If the name hasn't changed the length will be odd,
7984 # the middle char will be a space, and the two bits either
7985 # side will be a/name and b/name, or "a/name" and "b/name".
7986 # If the name has changed we'll get "rename from" and
7987 # "rename to" or "copy from" and "copy to" lines following
7988 # this, and we'll use them to get the filenames.
7989 # This complexity is necessary because spaces in the
7990 # filename(s) don't get escaped.
7991 set l [string length $line]
7992 set i [expr {$l / 2}]
7993 if {!(($l & 1) && [string index $line $i] eq " " &&
7994 [string range $line 2 [expr {$i - 1}]] eq \
7995 [string range $line [expr {$i + 3}] end])} {
7998 # unescape if quoted and chop off the a/ from the front
7999 if {[string index $line 0] eq "\""} {
8000 set fname [string range [lindex $line 0] 2 end]
8002 set fname [string range $line 2 [expr {$i - 1}]]
8005 makediffhdr $fname $ids
8007 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8008 set fname [encoding convertfrom [string range $line 16 end]]
8009 $ctext insert end "\n"
8010 set curdiffstart [$ctext index "end - 1c"]
8011 lappend ctext_file_names $fname
8012 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8013 $ctext insert end "$line\n" filesep
8014 set i [lsearch -exact $treediffs($ids) $fname]
8016 setinlist difffilestart $i $curdiffstart
8019 } elseif {![string compare -length 2 "@@" $line]} {
8020 regexp {^@@+} $line ats
8021 set line [encoding convertfrom $diffencoding $line]
8022 $ctext insert end "$line\n" hunksep
8023 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8026 set diffnparents [expr {[string length $ats] - 1}]
8029 } elseif {![string compare -length 10 "Submodule " $line]} {
8030 # start of a new submodule
8031 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8032 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8034 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8036 if {$currdiffsubmod != $fname} {
8037 $ctext insert end "\n"; # Add newline after commit message
8039 set curdiffstart [$ctext index "end - 1c"]
8040 lappend ctext_file_names ""
8041 if {$currdiffsubmod != $fname} {
8042 lappend ctext_file_lines $fname
8043 makediffhdr $fname $ids
8044 set currdiffsubmod $fname
8045 $ctext insert end "\n$line\n" filesep
8047 $ctext insert end "$line\n" filesep
8049 } elseif {![string compare -length 3 " >" $line]} {
8050 set $currdiffsubmod ""
8051 set line [encoding convertfrom $diffencoding $line]
8052 $ctext insert end "$line\n" dresult
8053 } elseif {![string compare -length 3 " <" $line]} {
8054 set $currdiffsubmod ""
8055 set line [encoding convertfrom $diffencoding $line]
8056 $ctext insert end "$line\n" d0
8057 } elseif {$diffinhdr} {
8058 if {![string compare -length 12 "rename from " $line]} {
8059 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8060 if {[string index $fname 0] eq "\""} {
8061 set fname [lindex $fname 0]
8063 set fname [encoding convertfrom $fname]
8064 set i [lsearch -exact $treediffs($ids) $fname]
8066 setinlist difffilestart $i $curdiffstart
8068 } elseif {![string compare -length 10 $line "rename to "] ||
8069 ![string compare -length 8 $line "copy to "]} {
8070 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8071 if {[string index $fname 0] eq "\""} {
8072 set fname [lindex $fname 0]
8074 makediffhdr $fname $ids
8075 } elseif {[string compare -length 3 $line "---"] == 0} {
8078 } elseif {[string compare -length 3 $line "+++"] == 0} {
8082 $ctext insert end "$line\n" filesep
8085 set line [string map {\x1A ^Z} \
8086 [encoding convertfrom $diffencoding $line]]
8087 # parse the prefix - one ' ', '-' or '+' for each parent
8088 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8089 set tag [expr {$diffnparents > 1? "m": "d"}]
8090 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8091 set words_pre_markup ""
8092 set words_post_markup ""
8093 if {[string trim $prefix " -+"] eq {}} {
8094 # prefix only has " ", "-" and "+" in it: normal diff line
8095 set num [string first "-" $prefix]
8097 set line [string range $line 1 end]
8100 # removed line, first parent with line is $num
8101 if {$num >= $mergemax} {
8104 if {$dowords && $worddiff eq [mc "Markup words"]} {
8105 $ctext insert end "\[-$line-\]" $tag$num
8107 $ctext insert end "$line" $tag$num
8110 $ctext insert end "\n" $tag$num
8114 if {[string first "+" $prefix] >= 0} {
8116 lappend tags ${tag}result
8117 if {$diffnparents > 1} {
8118 set num [string first " " $prefix]
8120 if {$num >= $mergemax} {
8126 set words_pre_markup "{+"
8127 set words_post_markup "+}"
8129 if {$targetline ne {}} {
8130 if {$diffline == $targetline} {
8131 set diffseehere [$ctext index "end - 1 chars"]
8137 if {$dowords && $worddiff eq [mc "Markup words"]} {
8138 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8140 $ctext insert end "$line" $tags
8143 $ctext insert end "\n" $tags
8146 } elseif {$dowords && $prefix eq "~"} {
8147 $ctext insert end "\n" {}
8149 # "\ No newline at end of file",
8150 # or something else we don't recognize
8151 $ctext insert end "$line\n" hunksep
8156 proc changediffdisp {} {
8157 global ctext diffelide
8159 $ctext tag conf d0 -elide [lindex $diffelide 0]
8160 $ctext tag conf dresult -elide [lindex $diffelide 1]
8163 proc highlightfile {cline} {
8164 global cflist cflist_top
8166 if {![info exists cflist_top]} return
8168 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8169 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8170 $cflist see $cline.0
8171 set cflist_top $cline
8174 proc highlightfile_for_scrollpos {topidx} {
8175 global cmitmode difffilestart
8177 if {$cmitmode eq "tree"} return
8178 if {![info exists difffilestart]} return
8180 set top [lindex [split $topidx .] 0]
8181 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8184 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8189 global difffilestart ctext cmitmode
8191 if {$cmitmode eq "tree"} return
8193 set here [$ctext index @0,0]
8194 foreach loc $difffilestart {
8195 if {[$ctext compare $loc >= $here]} {
8205 global difffilestart ctext cmitmode
8207 if {$cmitmode eq "tree"} return
8208 set here [$ctext index @0,0]
8209 foreach loc $difffilestart {
8210 if {[$ctext compare $loc > $here]} {
8217 proc clear_ctext {{first 1.0}} {
8218 global ctext smarktop smarkbot
8219 global ctext_file_names ctext_file_lines
8222 set l [lindex [split $first .] 0]
8223 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8226 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8229 $ctext delete $first end
8230 if {$first eq "1.0"} {
8231 catch {unset pendinglinks}
8233 set ctext_file_names {}
8234 set ctext_file_lines {}
8237 proc settabs {{firstab {}}} {
8238 global firsttabstop tabstop ctext have_tk85
8240 if {$firstab ne {} && $have_tk85} {
8241 set firsttabstop $firstab
8243 set w [font measure textfont "0"]
8244 if {$firsttabstop != 0} {
8245 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8246 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8247 } elseif {$have_tk85 || $tabstop != 8} {
8248 $ctext conf -tabs [expr {$tabstop * $w}]
8250 $ctext conf -tabs {}
8254 proc incrsearch {name ix op} {
8255 global ctext searchstring searchdirn
8257 if {[catch {$ctext index anchor}]} {
8258 # no anchor set, use start of selection, or of visible area
8259 set sel [$ctext tag ranges sel]
8261 $ctext mark set anchor [lindex $sel 0]
8262 } elseif {$searchdirn eq "-forwards"} {
8263 $ctext mark set anchor @0,0
8265 $ctext mark set anchor @0,[winfo height $ctext]
8268 if {$searchstring ne {}} {
8269 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8272 set mend "$here + $mlen c"
8273 $ctext tag remove sel 1.0 end
8274 $ctext tag add sel $here $mend
8275 suppress_highlighting_file_for_current_scrollpos
8276 highlightfile_for_scrollpos $here
8279 rehighlight_search_results
8283 global sstring ctext searchstring searchdirn
8286 $sstring icursor end
8287 set searchdirn -forwards
8288 if {$searchstring ne {}} {
8289 set sel [$ctext tag ranges sel]
8291 set start "[lindex $sel 0] + 1c"
8292 } elseif {[catch {set start [$ctext index anchor]}]} {
8295 set match [$ctext search -count mlen -- $searchstring $start]
8296 $ctext tag remove sel 1.0 end
8302 suppress_highlighting_file_for_current_scrollpos
8303 highlightfile_for_scrollpos $match
8304 set mend "$match + $mlen c"
8305 $ctext tag add sel $match $mend
8306 $ctext mark unset anchor
8307 rehighlight_search_results
8311 proc dosearchback {} {
8312 global sstring ctext searchstring searchdirn
8315 $sstring icursor end
8316 set searchdirn -backwards
8317 if {$searchstring ne {}} {
8318 set sel [$ctext tag ranges sel]
8320 set start [lindex $sel 0]
8321 } elseif {[catch {set start [$ctext index anchor]}]} {
8322 set start @0,[winfo height $ctext]
8324 set match [$ctext search -backwards -count ml -- $searchstring $start]
8325 $ctext tag remove sel 1.0 end
8331 suppress_highlighting_file_for_current_scrollpos
8332 highlightfile_for_scrollpos $match
8333 set mend "$match + $ml c"
8334 $ctext tag add sel $match $mend
8335 $ctext mark unset anchor
8336 rehighlight_search_results
8340 proc rehighlight_search_results {} {
8341 global ctext searchstring
8343 $ctext tag remove found 1.0 end
8344 $ctext tag remove currentsearchhit 1.0 end
8346 if {$searchstring ne {}} {
8351 proc searchmark {first last} {
8352 global ctext searchstring
8354 set sel [$ctext tag ranges sel]
8358 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8359 if {$match eq {}} break
8360 set mend "$match + $mlen c"
8361 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8362 $ctext tag add currentsearchhit $match $mend
8364 $ctext tag add found $match $mend
8369 proc searchmarkvisible {doall} {
8370 global ctext smarktop smarkbot
8372 set topline [lindex [split [$ctext index @0,0] .] 0]
8373 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8374 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8375 # no overlap with previous
8376 searchmark $topline $botline
8377 set smarktop $topline
8378 set smarkbot $botline
8380 if {$topline < $smarktop} {
8381 searchmark $topline [expr {$smarktop-1}]
8382 set smarktop $topline
8384 if {$botline > $smarkbot} {
8385 searchmark [expr {$smarkbot+1}] $botline
8386 set smarkbot $botline
8391 proc suppress_highlighting_file_for_current_scrollpos {} {
8392 global ctext suppress_highlighting_file_for_this_scrollpos
8394 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8397 proc scrolltext {f0 f1} {
8398 global searchstring cmitmode ctext
8399 global suppress_highlighting_file_for_this_scrollpos
8401 set topidx [$ctext index @0,0]
8402 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8403 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8404 highlightfile_for_scrollpos $topidx
8407 catch {unset suppress_highlighting_file_for_this_scrollpos}
8409 .bleft.bottom.sb set $f0 $f1
8410 if {$searchstring ne {}} {
8416 global linespc charspc canvx0 canvy0
8417 global xspc1 xspc2 lthickness
8419 set linespc [font metrics mainfont -linespace]
8420 set charspc [font measure mainfont "m"]
8421 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8422 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8423 set lthickness [expr {int($linespc / 9) + 1}]
8424 set xspc1(0) $linespc
8432 set ymax [lindex [$canv cget -scrollregion] 3]
8433 if {$ymax eq {} || $ymax == 0} return
8434 set span [$canv yview]
8437 allcanvs yview moveto [lindex $span 0]
8439 if {$selectedline ne {}} {
8440 selectline $selectedline 0
8441 allcanvs yview moveto [lindex $span 0]
8445 proc parsefont {f n} {
8448 set fontattr($f,family) [lindex $n 0]
8450 if {$s eq {} || $s == 0} {
8453 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8455 set fontattr($f,size) $s
8456 set fontattr($f,weight) normal
8457 set fontattr($f,slant) roman
8458 foreach style [lrange $n 2 end] {
8461 "bold" {set fontattr($f,weight) $style}
8463 "italic" {set fontattr($f,slant) $style}
8468 proc fontflags {f {isbold 0}} {
8471 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8472 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8473 -slant $fontattr($f,slant)]
8479 set n [list $fontattr($f,family) $fontattr($f,size)]
8480 if {$fontattr($f,weight) eq "bold"} {
8483 if {$fontattr($f,slant) eq "italic"} {
8489 proc incrfont {inc} {
8490 global mainfont textfont ctext canv cflist showrefstop
8491 global stopped entries fontattr
8494 set s $fontattr(mainfont,size)
8499 set fontattr(mainfont,size) $s
8500 font config mainfont -size $s
8501 font config mainfontbold -size $s
8502 set mainfont [fontname mainfont]
8503 set s $fontattr(textfont,size)
8508 set fontattr(textfont,size) $s
8509 font config textfont -size $s
8510 font config textfontbold -size $s
8511 set textfont [fontname textfont]
8518 global sha1entry sha1string
8519 if {[string length $sha1string] == 40} {
8520 $sha1entry delete 0 end
8524 proc sha1change {n1 n2 op} {
8525 global sha1string currentid sha1but
8526 if {$sha1string == {}
8527 || ([info exists currentid] && $sha1string == $currentid)} {
8532 if {[$sha1but cget -state] == $state} return
8533 if {$state == "normal"} {
8534 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8536 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8540 proc gotocommit {} {
8541 global sha1string tagids headids curview varcid
8543 if {$sha1string == {}
8544 || ([info exists currentid] && $sha1string == $currentid)} return
8545 if {[info exists tagids($sha1string)]} {
8546 set id $tagids($sha1string)
8547 } elseif {[info exists headids($sha1string)]} {
8548 set id $headids($sha1string)
8550 set id [string tolower $sha1string]
8551 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8552 set matches [longid $id]
8553 if {$matches ne {}} {
8554 if {[llength $matches] > 1} {
8555 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8558 set id [lindex $matches 0]
8561 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8562 error_popup [mc "Revision %s is not known" $sha1string]
8567 if {[commitinview $id $curview]} {
8568 selectline [rowofcommit $id] 1
8571 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8572 set msg [mc "SHA1 id %s is not known" $sha1string]
8574 set msg [mc "Revision %s is not in the current view" $sha1string]
8579 proc lineenter {x y id} {
8580 global hoverx hovery hoverid hovertimer
8581 global commitinfo canv
8583 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8587 if {[info exists hovertimer]} {
8588 after cancel $hovertimer
8590 set hovertimer [after 500 linehover]
8594 proc linemotion {x y id} {
8595 global hoverx hovery hoverid hovertimer
8597 if {[info exists hoverid] && $id == $hoverid} {
8600 if {[info exists hovertimer]} {
8601 after cancel $hovertimer
8603 set hovertimer [after 500 linehover]
8607 proc lineleave {id} {
8608 global hoverid hovertimer canv
8610 if {[info exists hoverid] && $id == $hoverid} {
8612 if {[info exists hovertimer]} {
8613 after cancel $hovertimer
8621 global hoverx hovery hoverid hovertimer
8622 global canv linespc lthickness
8623 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8627 set text [lindex $commitinfo($hoverid) 0]
8628 set ymax [lindex [$canv cget -scrollregion] 3]
8629 if {$ymax == {}} return
8630 set yfrac [lindex [$canv yview] 0]
8631 set x [expr {$hoverx + 2 * $linespc}]
8632 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8633 set x0 [expr {$x - 2 * $lthickness}]
8634 set y0 [expr {$y - 2 * $lthickness}]
8635 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8636 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8637 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8638 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8639 -width 1 -tags hover]
8641 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8642 -font mainfont -fill $linehoverfgcolor]
8646 proc clickisonarrow {id y} {
8649 set ranges [rowranges $id]
8650 set thresh [expr {2 * $lthickness + 6}]
8651 set n [expr {[llength $ranges] - 1}]
8652 for {set i 1} {$i < $n} {incr i} {
8653 set row [lindex $ranges $i]
8654 if {abs([yc $row] - $y) < $thresh} {
8661 proc arrowjump {id n y} {
8664 # 1 <-> 2, 3 <-> 4, etc...
8665 set n [expr {(($n - 1) ^ 1) + 1}]
8666 set row [lindex [rowranges $id] $n]
8668 set ymax [lindex [$canv cget -scrollregion] 3]
8669 if {$ymax eq {} || $ymax <= 0} return
8670 set view [$canv yview]
8671 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8672 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8676 allcanvs yview moveto $yfrac
8679 proc lineclick {x y id isnew} {
8680 global ctext commitinfo children canv thickerline curview
8682 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8687 # draw this line thicker than normal
8691 set ymax [lindex [$canv cget -scrollregion] 3]
8692 if {$ymax eq {}} return
8693 set yfrac [lindex [$canv yview] 0]
8694 set y [expr {$y + $yfrac * $ymax}]
8696 set dirn [clickisonarrow $id $y]
8698 arrowjump $id $dirn $y
8703 addtohistory [list lineclick $x $y $id 0] savectextpos
8705 # fill the details pane with info about this line
8706 $ctext conf -state normal
8709 $ctext insert end "[mc "Parent"]:\t"
8710 $ctext insert end $id link0
8712 set info $commitinfo($id)
8713 $ctext insert end "\n\t[lindex $info 0]\n"
8714 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8715 set date [formatdate [lindex $info 2]]
8716 $ctext insert end "\t[mc "Date"]:\t$date\n"
8717 set kids $children($curview,$id)
8719 $ctext insert end "\n[mc "Children"]:"
8721 foreach child $kids {
8723 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8724 set info $commitinfo($child)
8725 $ctext insert end "\n\t"
8726 $ctext insert end $child link$i
8727 setlink $child link$i
8728 $ctext insert end "\n\t[lindex $info 0]"
8729 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8730 set date [formatdate [lindex $info 2]]
8731 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8734 maybe_scroll_ctext 1
8735 $ctext conf -state disabled
8739 proc normalline {} {
8741 if {[info exists thickerline]} {
8748 proc selbyid {id {isnew 1}} {
8750 if {[commitinview $id $curview]} {
8751 selectline [rowofcommit $id] $isnew
8757 if {![info exists startmstime]} {
8758 set startmstime [clock clicks -milliseconds]
8760 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8763 proc rowmenu {x y id} {
8764 global rowctxmenu selectedline rowmenuid curview
8765 global nullid nullid2 fakerowmenu mainhead markedid
8769 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8774 if {[info exists markedid] && $markedid ne $id} {
8779 if {$id ne $nullid && $id ne $nullid2} {
8780 set menu $rowctxmenu
8781 if {$mainhead ne {}} {
8782 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8784 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8786 $menu entryconfigure 9 -state $mstate
8787 $menu entryconfigure 10 -state $mstate
8788 $menu entryconfigure 11 -state $mstate
8790 set menu $fakerowmenu
8792 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8793 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8794 $menu entryconfigure [mca "Make patch"] -state $state
8795 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8796 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8797 tk_popup $menu $x $y
8801 global rowmenuid markedid canv
8803 set markedid $rowmenuid
8804 make_idmark $markedid
8810 if {[info exists markedid]} {
8815 proc replace_by_kids {l r} {
8816 global curview children
8818 set id [commitonrow $r]
8819 set l [lreplace $l 0 0]
8820 foreach kid $children($curview,$id) {
8821 lappend l [rowofcommit $kid]
8823 return [lsort -integer -decreasing -unique $l]
8826 proc find_common_desc {} {
8827 global markedid rowmenuid curview children
8829 if {![info exists markedid]} return
8830 if {![commitinview $markedid $curview] ||
8831 ![commitinview $rowmenuid $curview]} return
8832 #set t1 [clock clicks -milliseconds]
8833 set l1 [list [rowofcommit $markedid]]
8834 set l2 [list [rowofcommit $rowmenuid]]
8836 set r1 [lindex $l1 0]
8837 set r2 [lindex $l2 0]
8838 if {$r1 eq {} || $r2 eq {}} break
8844 set l1 [replace_by_kids $l1 $r1]
8846 set l2 [replace_by_kids $l2 $r2]
8849 #set t2 [clock clicks -milliseconds]
8850 #puts "took [expr {$t2-$t1}]ms"
8853 proc compare_commits {} {
8854 global markedid rowmenuid curview children
8856 if {![info exists markedid]} return
8857 if {![commitinview $markedid $curview]} return
8858 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8859 do_cmp_commits $markedid $rowmenuid
8862 proc getpatchid {id} {
8865 if {![info exists patchids($id)]} {
8866 set cmd [diffcmd [list $id] {-p --root}]
8867 # trim off the initial "|"
8868 set cmd [lrange $cmd 1 end]
8870 set x [eval exec $cmd | git patch-id]
8871 set patchids($id) [lindex $x 0]
8873 set patchids($id) "error"
8876 return $patchids($id)
8879 proc do_cmp_commits {a b} {
8880 global ctext curview parents children patchids commitinfo
8882 $ctext conf -state normal
8885 for {set i 0} {$i < 100} {incr i} {
8888 if {[llength $parents($curview,$a)] > 1} {
8889 appendshortlink $a [mc "Skipping merge commit "] "\n"
8892 set patcha [getpatchid $a]
8894 if {[llength $parents($curview,$b)] > 1} {
8895 appendshortlink $b [mc "Skipping merge commit "] "\n"
8898 set patchb [getpatchid $b]
8900 if {!$skipa && !$skipb} {
8901 set heada [lindex $commitinfo($a) 0]
8902 set headb [lindex $commitinfo($b) 0]
8903 if {$patcha eq "error"} {
8904 appendshortlink $a [mc "Error getting patch ID for "] \
8905 [mc " - stopping\n"]
8908 if {$patchb eq "error"} {
8909 appendshortlink $b [mc "Error getting patch ID for "] \
8910 [mc " - stopping\n"]
8913 if {$patcha eq $patchb} {
8914 if {$heada eq $headb} {
8915 appendshortlink $a [mc "Commit "]
8916 appendshortlink $b " == " " $heada\n"
8918 appendshortlink $a [mc "Commit "] " $heada\n"
8919 appendshortlink $b [mc " is the same patch as\n "] \
8925 $ctext insert end "\n"
8926 appendshortlink $a [mc "Commit "] " $heada\n"
8927 appendshortlink $b [mc " differs from\n "] \
8929 $ctext insert end [mc "Diff of commits:\n\n"]
8930 $ctext conf -state disabled
8937 set kids [real_children $curview,$a]
8938 if {[llength $kids] != 1} {
8939 $ctext insert end "\n"
8940 appendshortlink $a [mc "Commit "] \
8941 [mc " has %s children - stopping\n" [llength $kids]]
8944 set a [lindex $kids 0]
8947 set kids [real_children $curview,$b]
8948 if {[llength $kids] != 1} {
8949 appendshortlink $b [mc "Commit "] \
8950 [mc " has %s children - stopping\n" [llength $kids]]
8953 set b [lindex $kids 0]
8956 $ctext conf -state disabled
8959 proc diffcommits {a b} {
8960 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8962 set tmpdir [gitknewtmpdir]
8963 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8964 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8966 exec git diff-tree -p --pretty $a >$fna
8967 exec git diff-tree -p --pretty $b >$fnb
8969 error_popup [mc "Error writing commit to file: %s" $err]
8973 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8975 error_popup [mc "Error diffing commits: %s" $err]
8978 set diffids [list commits $a $b]
8979 set blobdifffd($diffids) $fd
8981 set currdiffsubmod ""
8982 filerun $fd [list getblobdiffline $fd $diffids]
8985 proc diffvssel {dirn} {
8986 global rowmenuid selectedline
8988 if {$selectedline eq {}} return
8990 set oldid [commitonrow $selectedline]
8991 set newid $rowmenuid
8993 set oldid $rowmenuid
8994 set newid [commitonrow $selectedline]
8996 addtohistory [list doseldiff $oldid $newid] savectextpos
8997 doseldiff $oldid $newid
9000 proc diffvsmark {dirn} {
9001 global rowmenuid markedid
9003 if {![info exists markedid]} return
9006 set newid $rowmenuid
9008 set oldid $rowmenuid
9011 addtohistory [list doseldiff $oldid $newid] savectextpos
9012 doseldiff $oldid $newid
9015 proc doseldiff {oldid newid} {
9019 $ctext conf -state normal
9021 init_flist [mc "Top"]
9022 $ctext insert end "[mc "From"] "
9023 $ctext insert end $oldid link0
9024 setlink $oldid link0
9025 $ctext insert end "\n "
9026 $ctext insert end [lindex $commitinfo($oldid) 0]
9027 $ctext insert end "\n\n[mc "To"] "
9028 $ctext insert end $newid link1
9029 setlink $newid link1
9030 $ctext insert end "\n "
9031 $ctext insert end [lindex $commitinfo($newid) 0]
9032 $ctext insert end "\n"
9033 $ctext conf -state disabled
9034 $ctext tag remove found 1.0 end
9035 startdiff [list $oldid $newid]
9039 global rowmenuid currentid commitinfo patchtop patchnum NS
9041 if {![info exists currentid]} return
9042 set oldid $currentid
9043 set oldhead [lindex $commitinfo($oldid) 0]
9044 set newid $rowmenuid
9045 set newhead [lindex $commitinfo($newid) 0]
9048 catch {destroy $top}
9050 make_transient $top .
9051 ${NS}::label $top.title -text [mc "Generate patch"]
9052 grid $top.title - -pady 10
9053 ${NS}::label $top.from -text [mc "From:"]
9054 ${NS}::entry $top.fromsha1 -width 40
9055 $top.fromsha1 insert 0 $oldid
9056 $top.fromsha1 conf -state readonly
9057 grid $top.from $top.fromsha1 -sticky w
9058 ${NS}::entry $top.fromhead -width 60
9059 $top.fromhead insert 0 $oldhead
9060 $top.fromhead conf -state readonly
9061 grid x $top.fromhead -sticky w
9062 ${NS}::label $top.to -text [mc "To:"]
9063 ${NS}::entry $top.tosha1 -width 40
9064 $top.tosha1 insert 0 $newid
9065 $top.tosha1 conf -state readonly
9066 grid $top.to $top.tosha1 -sticky w
9067 ${NS}::entry $top.tohead -width 60
9068 $top.tohead insert 0 $newhead
9069 $top.tohead conf -state readonly
9070 grid x $top.tohead -sticky w
9071 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9072 grid $top.rev x -pady 10 -padx 5
9073 ${NS}::label $top.flab -text [mc "Output file:"]
9074 ${NS}::entry $top.fname -width 60
9075 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9077 grid $top.flab $top.fname -sticky w
9078 ${NS}::frame $top.buts
9079 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9080 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9081 bind $top <Key-Return> mkpatchgo
9082 bind $top <Key-Escape> mkpatchcan
9083 grid $top.buts.gen $top.buts.can
9084 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9085 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9086 grid $top.buts - -pady 10 -sticky ew
9090 proc mkpatchrev {} {
9093 set oldid [$patchtop.fromsha1 get]
9094 set oldhead [$patchtop.fromhead get]
9095 set newid [$patchtop.tosha1 get]
9096 set newhead [$patchtop.tohead get]
9097 foreach e [list fromsha1 fromhead tosha1 tohead] \
9098 v [list $newid $newhead $oldid $oldhead] {
9099 $patchtop.$e conf -state normal
9100 $patchtop.$e delete 0 end
9101 $patchtop.$e insert 0 $v
9102 $patchtop.$e conf -state readonly
9107 global patchtop nullid nullid2
9109 set oldid [$patchtop.fromsha1 get]
9110 set newid [$patchtop.tosha1 get]
9111 set fname [$patchtop.fname get]
9112 set cmd [diffcmd [list $oldid $newid] -p]
9113 # trim off the initial "|"
9114 set cmd [lrange $cmd 1 end]
9115 lappend cmd >$fname &
9116 if {[catch {eval exec $cmd} err]} {
9117 error_popup "[mc "Error creating patch:"] $err" $patchtop
9119 catch {destroy $patchtop}
9123 proc mkpatchcan {} {
9126 catch {destroy $patchtop}
9131 global rowmenuid mktagtop commitinfo NS
9135 catch {destroy $top}
9137 make_transient $top .
9138 ${NS}::label $top.title -text [mc "Create tag"]
9139 grid $top.title - -pady 10
9140 ${NS}::label $top.id -text [mc "ID:"]
9141 ${NS}::entry $top.sha1 -width 40
9142 $top.sha1 insert 0 $rowmenuid
9143 $top.sha1 conf -state readonly
9144 grid $top.id $top.sha1 -sticky w
9145 ${NS}::entry $top.head -width 60
9146 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9147 $top.head conf -state readonly
9148 grid x $top.head -sticky w
9149 ${NS}::label $top.tlab -text [mc "Tag name:"]
9150 ${NS}::entry $top.tag -width 60
9151 grid $top.tlab $top.tag -sticky w
9152 ${NS}::label $top.op -text [mc "Tag message is optional"]
9153 grid $top.op -columnspan 2 -sticky we
9154 ${NS}::label $top.mlab -text [mc "Tag message:"]
9155 ${NS}::entry $top.msg -width 60
9156 grid $top.mlab $top.msg -sticky w
9157 ${NS}::frame $top.buts
9158 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9159 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9160 bind $top <Key-Return> mktaggo
9161 bind $top <Key-Escape> mktagcan
9162 grid $top.buts.gen $top.buts.can
9163 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9164 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9165 grid $top.buts - -pady 10 -sticky ew
9170 global mktagtop env tagids idtags
9172 set id [$mktagtop.sha1 get]
9173 set tag [$mktagtop.tag get]
9174 set msg [$mktagtop.msg get]
9176 error_popup [mc "No tag name specified"] $mktagtop
9179 if {[info exists tagids($tag)]} {
9180 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9185 exec git tag -a -m $msg $tag $id
9187 exec git tag $tag $id
9190 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9194 set tagids($tag) $id
9195 lappend idtags($id) $tag
9203 proc redrawtags {id} {
9204 global canv linehtag idpos currentid curview cmitlisted markedid
9205 global canvxmax iddrawn circleitem mainheadid circlecolors
9206 global mainheadcirclecolor
9208 if {![commitinview $id $curview]} return
9209 if {![info exists iddrawn($id)]} return
9210 set row [rowofcommit $id]
9211 if {$id eq $mainheadid} {
9212 set ofill $mainheadcirclecolor
9214 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9216 $canv itemconf $circleitem($row) -fill $ofill
9217 $canv delete tag.$id
9218 set xt [eval drawtags $id $idpos($id)]
9219 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9220 set text [$canv itemcget $linehtag($id) -text]
9221 set font [$canv itemcget $linehtag($id) -font]
9222 set xr [expr {$xt + [font measure $font $text]}]
9223 if {$xr > $canvxmax} {
9227 if {[info exists currentid] && $currentid == $id} {
9230 if {[info exists markedid] && $markedid eq $id} {
9238 catch {destroy $mktagtop}
9243 if {![domktag]} return
9247 proc writecommit {} {
9248 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9250 set top .writecommit
9252 catch {destroy $top}
9254 make_transient $top .
9255 ${NS}::label $top.title -text [mc "Write commit to file"]
9256 grid $top.title - -pady 10
9257 ${NS}::label $top.id -text [mc "ID:"]
9258 ${NS}::entry $top.sha1 -width 40
9259 $top.sha1 insert 0 $rowmenuid
9260 $top.sha1 conf -state readonly
9261 grid $top.id $top.sha1 -sticky w
9262 ${NS}::entry $top.head -width 60
9263 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9264 $top.head conf -state readonly
9265 grid x $top.head -sticky w
9266 ${NS}::label $top.clab -text [mc "Command:"]
9267 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9268 grid $top.clab $top.cmd -sticky w -pady 10
9269 ${NS}::label $top.flab -text [mc "Output file:"]
9270 ${NS}::entry $top.fname -width 60
9271 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9272 grid $top.flab $top.fname -sticky w
9273 ${NS}::frame $top.buts
9274 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9275 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9276 bind $top <Key-Return> wrcomgo
9277 bind $top <Key-Escape> wrcomcan
9278 grid $top.buts.gen $top.buts.can
9279 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9280 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9281 grid $top.buts - -pady 10 -sticky ew
9288 set id [$wrcomtop.sha1 get]
9289 set cmd "echo $id | [$wrcomtop.cmd get]"
9290 set fname [$wrcomtop.fname get]
9291 if {[catch {exec sh -c $cmd >$fname &} err]} {
9292 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9294 catch {destroy $wrcomtop}
9301 catch {destroy $wrcomtop}
9306 global rowmenuid mkbrtop NS
9309 catch {destroy $top}
9311 make_transient $top .
9312 ${NS}::label $top.title -text [mc "Create new branch"]
9313 grid $top.title - -pady 10
9314 ${NS}::label $top.id -text [mc "ID:"]
9315 ${NS}::entry $top.sha1 -width 40
9316 $top.sha1 insert 0 $rowmenuid
9317 $top.sha1 conf -state readonly
9318 grid $top.id $top.sha1 -sticky w
9319 ${NS}::label $top.nlab -text [mc "Name:"]
9320 ${NS}::entry $top.name -width 40
9321 grid $top.nlab $top.name -sticky w
9322 ${NS}::frame $top.buts
9323 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9324 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9325 bind $top <Key-Return> [list mkbrgo $top]
9326 bind $top <Key-Escape> "catch {destroy $top}"
9327 grid $top.buts.go $top.buts.can
9328 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9329 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9330 grid $top.buts - -pady 10 -sticky ew
9335 global headids idheads
9337 set name [$top.name get]
9338 set id [$top.sha1 get]
9342 error_popup [mc "Please specify a name for the new branch"] $top
9345 if {[info exists headids($name)]} {
9346 if {![confirm_popup [mc \
9347 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9350 set old_id $headids($name)
9353 catch {destroy $top}
9354 lappend cmdargs $name $id
9358 eval exec git branch $cmdargs
9364 if {$old_id ne {}} {
9370 set headids($name) $id
9371 lappend idheads($id) $name
9380 proc exec_citool {tool_args {baseid {}}} {
9381 global commitinfo env
9383 set save_env [array get env GIT_AUTHOR_*]
9385 if {$baseid ne {}} {
9386 if {![info exists commitinfo($baseid)]} {
9389 set author [lindex $commitinfo($baseid) 1]
9390 set date [lindex $commitinfo($baseid) 2]
9391 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9392 $author author name email]
9394 set env(GIT_AUTHOR_NAME) $name
9395 set env(GIT_AUTHOR_EMAIL) $email
9396 set env(GIT_AUTHOR_DATE) $date
9400 eval exec git citool $tool_args &
9402 array unset env GIT_AUTHOR_*
9403 array set env $save_env
9406 proc cherrypick {} {
9407 global rowmenuid curview
9408 global mainhead mainheadid
9411 set oldhead [exec git rev-parse HEAD]
9412 set dheads [descheads $rowmenuid]
9413 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9414 set ok [confirm_popup [mc "Commit %s is already\
9415 included in branch %s -- really re-apply it?" \
9416 [string range $rowmenuid 0 7] $mainhead]]
9419 nowbusy cherrypick [mc "Cherry-picking"]
9421 # Unfortunately git-cherry-pick writes stuff to stderr even when
9422 # no error occurs, and exec takes that as an indication of error...
9423 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9426 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9428 error_popup [mc "Cherry-pick failed because of local changes\
9429 to file '%s'.\nPlease commit, reset or stash\
9430 your changes and try again." $fname]
9431 } elseif {[regexp -line \
9432 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9434 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9435 conflict.\nDo you wish to run git citool to\
9437 # Force citool to read MERGE_MSG
9438 file delete [file join $gitdir "GITGUI_MSG"]
9439 exec_citool {} $rowmenuid
9447 set newhead [exec git rev-parse HEAD]
9448 if {$newhead eq $oldhead} {
9450 error_popup [mc "No changes committed"]
9453 addnewchild $newhead $oldhead
9454 if {[commitinview $oldhead $curview]} {
9455 # XXX this isn't right if we have a path limit...
9456 insertrow $newhead $oldhead $curview
9457 if {$mainhead ne {}} {
9458 movehead $newhead $mainhead
9459 movedhead $newhead $mainhead
9461 set mainheadid $newhead
9470 global rowmenuid curview
9471 global mainhead mainheadid
9474 set oldhead [exec git rev-parse HEAD]
9475 set dheads [descheads $rowmenuid]
9476 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9477 set ok [confirm_popup [mc "Commit %s is not\
9478 included in branch %s -- really revert it?" \
9479 [string range $rowmenuid 0 7] $mainhead]]
9482 nowbusy revert [mc "Reverting"]
9485 if [catch {exec git revert --no-edit $rowmenuid} err] {
9487 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9489 regsub {\n( |\t)+} $files "\n" files
9490 error_popup [mc "Revert failed because of local changes to\
9491 the following files:%s Please commit, reset or stash \
9492 your changes and try again." $files]
9493 } elseif [regexp {error: could not revert} $err] {
9494 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9495 Do you wish to run git citool to resolve it?"]] {
9496 # Force citool to read MERGE_MSG
9497 file delete [file join $gitdir "GITGUI_MSG"]
9498 exec_citool {} $rowmenuid
9500 } else { error_popup $err }
9505 set newhead [exec git rev-parse HEAD]
9506 if { $newhead eq $oldhead } {
9508 error_popup [mc "No changes committed"]
9512 addnewchild $newhead $oldhead
9514 if [commitinview $oldhead $curview] {
9515 # XXX this isn't right if we have a path limit...
9516 insertrow $newhead $oldhead $curview
9517 if {$mainhead ne {}} {
9518 movehead $newhead $mainhead
9519 movedhead $newhead $mainhead
9521 set mainheadid $newhead
9531 global mainhead rowmenuid confirm_ok resettype NS
9534 set w ".confirmreset"
9537 wm title $w [mc "Confirm reset"]
9538 ${NS}::label $w.m -text \
9539 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9540 pack $w.m -side top -fill x -padx 20 -pady 20
9541 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9543 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9544 -text [mc "Soft: Leave working tree and index untouched"]
9545 grid $w.f.soft -sticky w
9546 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9547 -text [mc "Mixed: Leave working tree untouched, reset index"]
9548 grid $w.f.mixed -sticky w
9549 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9550 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9551 grid $w.f.hard -sticky w
9552 pack $w.f -side top -fill x -padx 4
9553 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9554 pack $w.ok -side left -fill x -padx 20 -pady 20
9555 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9556 bind $w <Key-Escape> [list destroy $w]
9557 pack $w.cancel -side right -fill x -padx 20 -pady 20
9558 bind $w <Visibility> "grab $w; focus $w"
9560 if {!$confirm_ok} return
9561 if {[catch {set fd [open \
9562 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9566 filerun $fd [list readresetstat $fd]
9567 nowbusy reset [mc "Resetting"]
9572 proc readresetstat {fd} {
9573 global mainhead mainheadid showlocalchanges rprogcoord
9575 if {[gets $fd line] >= 0} {
9576 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9577 set rprogcoord [expr {1.0 * $m / $n}]
9585 if {[catch {close $fd} err]} {
9588 set oldhead $mainheadid
9589 set newhead [exec git rev-parse HEAD]
9590 if {$newhead ne $oldhead} {
9591 movehead $newhead $mainhead
9592 movedhead $newhead $mainhead
9593 set mainheadid $newhead
9597 if {$showlocalchanges} {
9603 # context menu for a head
9604 proc headmenu {x y id head} {
9605 global headmenuid headmenuhead headctxmenu mainhead
9609 set headmenuhead $head
9611 if {[string match "remotes/*" $head]} {
9614 if {$head eq $mainhead} {
9617 $headctxmenu entryconfigure 0 -state $state
9618 $headctxmenu entryconfigure 1 -state $state
9619 tk_popup $headctxmenu $x $y
9623 global headmenuid headmenuhead headids
9624 global showlocalchanges
9626 # check the tree is clean first??
9627 nowbusy checkout [mc "Checking out"]
9631 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9635 if {$showlocalchanges} {
9639 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9643 proc readcheckoutstat {fd newhead newheadid} {
9644 global mainhead mainheadid headids showlocalchanges progresscoords
9645 global viewmainheadid curview
9647 if {[gets $fd line] >= 0} {
9648 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9649 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9654 set progresscoords {0 0}
9657 if {[catch {close $fd} err]} {
9660 set oldmainid $mainheadid
9661 set mainhead $newhead
9662 set mainheadid $newheadid
9663 set viewmainheadid($curview) $newheadid
9664 redrawtags $oldmainid
9665 redrawtags $newheadid
9667 if {$showlocalchanges} {
9673 global headmenuid headmenuhead mainhead
9676 set head $headmenuhead
9678 # this check shouldn't be needed any more...
9679 if {$head eq $mainhead} {
9680 error_popup [mc "Cannot delete the currently checked-out branch"]
9683 set dheads [descheads $id]
9684 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9685 # the stuff on this branch isn't on any other branch
9686 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9687 branch.\nReally delete branch %s?" $head $head]]} return
9691 if {[catch {exec git branch -D $head} err]} {
9696 removehead $id $head
9697 removedhead $id $head
9704 # Display a list of tags and heads
9706 global showrefstop bgcolor fgcolor selectbgcolor NS
9707 global bglist fglist reflistfilter reflist maincursor
9710 set showrefstop $top
9711 if {[winfo exists $top]} {
9717 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9718 make_transient $top .
9719 text $top.list -background $bgcolor -foreground $fgcolor \
9720 -selectbackground $selectbgcolor -font mainfont \
9721 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9722 -width 30 -height 20 -cursor $maincursor \
9723 -spacing1 1 -spacing3 1 -state disabled
9724 $top.list tag configure highlight -background $selectbgcolor
9725 lappend bglist $top.list
9726 lappend fglist $top.list
9727 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9728 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9729 grid $top.list $top.ysb -sticky nsew
9730 grid $top.xsb x -sticky ew
9732 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9733 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9734 set reflistfilter "*"
9735 trace add variable reflistfilter write reflistfilter_change
9736 pack $top.f.e -side right -fill x -expand 1
9737 pack $top.f.l -side left
9738 grid $top.f - -sticky ew -pady 2
9739 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9740 bind $top <Key-Escape> [list destroy $top]
9742 grid columnconfigure $top 0 -weight 1
9743 grid rowconfigure $top 0 -weight 1
9744 bind $top.list <1> {break}
9745 bind $top.list <B1-Motion> {break}
9746 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9751 proc sel_reflist {w x y} {
9752 global showrefstop reflist headids tagids otherrefids
9754 if {![winfo exists $showrefstop]} return
9755 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9756 set ref [lindex $reflist [expr {$l-1}]]
9757 set n [lindex $ref 0]
9758 switch -- [lindex $ref 1] {
9759 "H" {selbyid $headids($n)}
9760 "T" {selbyid $tagids($n)}
9761 "o" {selbyid $otherrefids($n)}
9763 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9766 proc unsel_reflist {} {
9769 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9770 $showrefstop.list tag remove highlight 0.0 end
9773 proc reflistfilter_change {n1 n2 op} {
9774 global reflistfilter
9776 after cancel refill_reflist
9777 after 200 refill_reflist
9780 proc refill_reflist {} {
9781 global reflist reflistfilter showrefstop headids tagids otherrefids
9784 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9786 foreach n [array names headids] {
9787 if {[string match $reflistfilter $n]} {
9788 if {[commitinview $headids($n) $curview]} {
9789 lappend refs [list $n H]
9791 interestedin $headids($n) {run refill_reflist}
9795 foreach n [array names tagids] {
9796 if {[string match $reflistfilter $n]} {
9797 if {[commitinview $tagids($n) $curview]} {
9798 lappend refs [list $n T]
9800 interestedin $tagids($n) {run refill_reflist}
9804 foreach n [array names otherrefids] {
9805 if {[string match $reflistfilter $n]} {
9806 if {[commitinview $otherrefids($n) $curview]} {
9807 lappend refs [list $n o]
9809 interestedin $otherrefids($n) {run refill_reflist}
9813 set refs [lsort -index 0 $refs]
9814 if {$refs eq $reflist} return
9816 # Update the contents of $showrefstop.list according to the
9817 # differences between $reflist (old) and $refs (new)
9818 $showrefstop.list conf -state normal
9819 $showrefstop.list insert end "\n"
9822 while {$i < [llength $reflist] || $j < [llength $refs]} {
9823 if {$i < [llength $reflist]} {
9824 if {$j < [llength $refs]} {
9825 set cmp [string compare [lindex $reflist $i 0] \
9826 [lindex $refs $j 0]]
9828 set cmp [string compare [lindex $reflist $i 1] \
9829 [lindex $refs $j 1]]
9839 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9847 set l [expr {$j + 1}]
9848 $showrefstop.list image create $l.0 -align baseline \
9849 -image reficon-[lindex $refs $j 1] -padx 2
9850 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9856 # delete last newline
9857 $showrefstop.list delete end-2c end-1c
9858 $showrefstop.list conf -state disabled
9861 # Stuff for finding nearby tags
9862 proc getallcommits {} {
9863 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9864 global idheads idtags idotherrefs allparents tagobjid
9867 if {![info exists allcommits]} {
9873 set allccache [file join $gitdir "gitk.cache"]
9875 set f [open $allccache r]
9884 set cmd [list | git rev-list --parents]
9885 set allcupdate [expr {$seeds ne {}}]
9889 set refs [concat [array names idheads] [array names idtags] \
9890 [array names idotherrefs]]
9893 foreach name [array names tagobjid] {
9894 lappend tagobjs $tagobjid($name)
9896 foreach id [lsort -unique $refs] {
9897 if {![info exists allparents($id)] &&
9898 [lsearch -exact $tagobjs $id] < 0} {
9909 set fd [open [concat $cmd $ids] r]
9910 fconfigure $fd -blocking 0
9913 filerun $fd [list getallclines $fd]
9919 # Since most commits have 1 parent and 1 child, we group strings of
9920 # such commits into "arcs" joining branch/merge points (BMPs), which
9921 # are commits that either don't have 1 parent or don't have 1 child.
9923 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9924 # arcout(id) - outgoing arcs for BMP
9925 # arcids(a) - list of IDs on arc including end but not start
9926 # arcstart(a) - BMP ID at start of arc
9927 # arcend(a) - BMP ID at end of arc
9928 # growing(a) - arc a is still growing
9929 # arctags(a) - IDs out of arcids (excluding end) that have tags
9930 # archeads(a) - IDs out of arcids (excluding end) that have heads
9931 # The start of an arc is at the descendent end, so "incoming" means
9932 # coming from descendents, and "outgoing" means going towards ancestors.
9934 proc getallclines {fd} {
9935 global allparents allchildren idtags idheads nextarc
9936 global arcnos arcids arctags arcout arcend arcstart archeads growing
9937 global seeds allcommits cachedarcs allcupdate
9940 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9941 set id [lindex $line 0]
9942 if {[info exists allparents($id)]} {
9947 set olds [lrange $line 1 end]
9948 set allparents($id) $olds
9949 if {![info exists allchildren($id)]} {
9950 set allchildren($id) {}
9955 if {[llength $olds] == 1 && [llength $a] == 1} {
9956 lappend arcids($a) $id
9957 if {[info exists idtags($id)]} {
9958 lappend arctags($a) $id
9960 if {[info exists idheads($id)]} {
9961 lappend archeads($a) $id
9963 if {[info exists allparents($olds)]} {
9964 # seen parent already
9965 if {![info exists arcout($olds)]} {
9968 lappend arcids($a) $olds
9969 set arcend($a) $olds
9972 lappend allchildren($olds) $id
9973 lappend arcnos($olds) $a
9977 foreach a $arcnos($id) {
9978 lappend arcids($a) $id
9985 lappend allchildren($p) $id
9986 set a [incr nextarc]
9987 set arcstart($a) $id
9994 if {[info exists allparents($p)]} {
9995 # seen it already, may need to make a new branch
9996 if {![info exists arcout($p)]} {
9999 lappend arcids($a) $p
10003 lappend arcnos($p) $a
10005 set arcout($id) $ao
10008 global cached_dheads cached_dtags cached_atags
10009 catch {unset cached_dheads}
10010 catch {unset cached_dtags}
10011 catch {unset cached_atags}
10014 return [expr {$nid >= 1000? 2: 1}]
10018 fconfigure $fd -blocking 1
10021 # got an error reading the list of commits
10022 # if we were updating, try rereading the whole thing again
10028 error_popup "[mc "Error reading commit topology information;\
10029 branch and preceding/following tag information\
10030 will be incomplete."]\n($err)"
10033 if {[incr allcommits -1] == 0} {
10043 proc recalcarc {a} {
10044 global arctags archeads arcids idtags idheads
10048 foreach id [lrange $arcids($a) 0 end-1] {
10049 if {[info exists idtags($id)]} {
10052 if {[info exists idheads($id)]} {
10056 set arctags($a) $at
10057 set archeads($a) $ah
10060 proc splitarc {p} {
10061 global arcnos arcids nextarc arctags archeads idtags idheads
10062 global arcstart arcend arcout allparents growing
10065 if {[llength $a] != 1} {
10066 puts "oops splitarc called but [llength $a] arcs already"
10069 set a [lindex $a 0]
10070 set i [lsearch -exact $arcids($a) $p]
10072 puts "oops splitarc $p not in arc $a"
10075 set na [incr nextarc]
10076 if {[info exists arcend($a)]} {
10077 set arcend($na) $arcend($a)
10079 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10080 set j [lsearch -exact $arcnos($l) $a]
10081 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10083 set tail [lrange $arcids($a) [expr {$i+1}] end]
10084 set arcids($a) [lrange $arcids($a) 0 $i]
10086 set arcstart($na) $p
10088 set arcids($na) $tail
10089 if {[info exists growing($a)]} {
10095 if {[llength $arcnos($id)] == 1} {
10096 set arcnos($id) $na
10098 set j [lsearch -exact $arcnos($id) $a]
10099 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10103 # reconstruct tags and heads lists
10104 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10108 set arctags($na) {}
10109 set archeads($na) {}
10113 # Update things for a new commit added that is a child of one
10114 # existing commit. Used when cherry-picking.
10115 proc addnewchild {id p} {
10116 global allparents allchildren idtags nextarc
10117 global arcnos arcids arctags arcout arcend arcstart archeads growing
10118 global seeds allcommits
10120 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10121 set allparents($id) [list $p]
10122 set allchildren($id) {}
10125 lappend allchildren($p) $id
10126 set a [incr nextarc]
10127 set arcstart($a) $id
10128 set archeads($a) {}
10130 set arcids($a) [list $p]
10132 if {![info exists arcout($p)]} {
10135 lappend arcnos($p) $a
10136 set arcout($id) [list $a]
10139 # This implements a cache for the topology information.
10140 # The cache saves, for each arc, the start and end of the arc,
10141 # the ids on the arc, and the outgoing arcs from the end.
10142 proc readcache {f} {
10143 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10144 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10148 set lim $cachedarcs
10149 if {$lim - $a > 500} {
10150 set lim [expr {$a + 500}]
10154 # finish reading the cache and setting up arctags, etc.
10156 if {$line ne "1"} {error "bad final version"}
10158 foreach id [array names idtags] {
10159 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10160 [llength $allparents($id)] == 1} {
10161 set a [lindex $arcnos($id) 0]
10162 if {$arctags($a) eq {}} {
10167 foreach id [array names idheads] {
10168 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10169 [llength $allparents($id)] == 1} {
10170 set a [lindex $arcnos($id) 0]
10171 if {$archeads($a) eq {}} {
10176 foreach id [lsort -unique $possible_seeds] {
10177 if {$arcnos($id) eq {}} {
10183 while {[incr a] <= $lim} {
10185 if {[llength $line] != 3} {error "bad line"}
10186 set s [lindex $line 0]
10187 set arcstart($a) $s
10188 lappend arcout($s) $a
10189 if {![info exists arcnos($s)]} {
10190 lappend possible_seeds $s
10193 set e [lindex $line 1]
10198 if {![info exists arcout($e)]} {
10202 set arcids($a) [lindex $line 2]
10203 foreach id $arcids($a) {
10204 lappend allparents($s) $id
10206 lappend arcnos($id) $a
10208 if {![info exists allparents($s)]} {
10209 set allparents($s) {}
10212 set archeads($a) {}
10214 set nextarc [expr {$a - 1}]
10226 proc getcache {f} {
10227 global nextarc cachedarcs possible_seeds
10231 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10232 # make sure it's an integer
10233 set cachedarcs [expr {int([lindex $line 1])}]
10234 if {$cachedarcs < 0} {error "bad number of arcs"}
10236 set possible_seeds {}
10244 proc dropcache {err} {
10245 global allcwait nextarc cachedarcs seeds
10247 #puts "dropping cache ($err)"
10248 foreach v {arcnos arcout arcids arcstart arcend growing \
10249 arctags archeads allparents allchildren} {
10260 proc writecache {f} {
10261 global cachearc cachedarcs allccache
10262 global arcstart arcend arcnos arcids arcout
10265 set lim $cachedarcs
10266 if {$lim - $a > 1000} {
10267 set lim [expr {$a + 1000}]
10270 while {[incr a] <= $lim} {
10271 if {[info exists arcend($a)]} {
10272 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10274 puts $f [list $arcstart($a) {} $arcids($a)]
10279 catch {file delete $allccache}
10280 #puts "writing cache failed ($err)"
10283 set cachearc [expr {$a - 1}]
10284 if {$a > $cachedarcs} {
10292 proc savecache {} {
10293 global nextarc cachedarcs cachearc allccache
10295 if {$nextarc == $cachedarcs} return
10297 set cachedarcs $nextarc
10299 set f [open $allccache w]
10300 puts $f [list 1 $cachedarcs]
10305 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10306 # or 0 if neither is true.
10307 proc anc_or_desc {a b} {
10308 global arcout arcstart arcend arcnos cached_isanc
10310 if {$arcnos($a) eq $arcnos($b)} {
10311 # Both are on the same arc(s); either both are the same BMP,
10312 # or if one is not a BMP, the other is also not a BMP or is
10313 # the BMP at end of the arc (and it only has 1 incoming arc).
10314 # Or both can be BMPs with no incoming arcs.
10315 if {$a eq $b || $arcnos($a) eq {}} {
10318 # assert {[llength $arcnos($a)] == 1}
10319 set arc [lindex $arcnos($a) 0]
10320 set i [lsearch -exact $arcids($arc) $a]
10321 set j [lsearch -exact $arcids($arc) $b]
10322 if {$i < 0 || $i > $j} {
10329 if {![info exists arcout($a)]} {
10330 set arc [lindex $arcnos($a) 0]
10331 if {[info exists arcend($arc)]} {
10332 set aend $arcend($arc)
10336 set a $arcstart($arc)
10340 if {![info exists arcout($b)]} {
10341 set arc [lindex $arcnos($b) 0]
10342 if {[info exists arcend($arc)]} {
10343 set bend $arcend($arc)
10347 set b $arcstart($arc)
10357 if {[info exists cached_isanc($a,$bend)]} {
10358 if {$cached_isanc($a,$bend)} {
10362 if {[info exists cached_isanc($b,$aend)]} {
10363 if {$cached_isanc($b,$aend)} {
10366 if {[info exists cached_isanc($a,$bend)]} {
10371 set todo [list $a $b]
10374 for {set i 0} {$i < [llength $todo]} {incr i} {
10375 set x [lindex $todo $i]
10376 if {$anc($x) eq {}} {
10379 foreach arc $arcnos($x) {
10380 set xd $arcstart($arc)
10381 if {$xd eq $bend} {
10382 set cached_isanc($a,$bend) 1
10383 set cached_isanc($b,$aend) 0
10385 } elseif {$xd eq $aend} {
10386 set cached_isanc($b,$aend) 1
10387 set cached_isanc($a,$bend) 0
10390 if {![info exists anc($xd)]} {
10391 set anc($xd) $anc($x)
10393 } elseif {$anc($xd) ne $anc($x)} {
10398 set cached_isanc($a,$bend) 0
10399 set cached_isanc($b,$aend) 0
10403 # This identifies whether $desc has an ancestor that is
10404 # a growing tip of the graph and which is not an ancestor of $anc
10405 # and returns 0 if so and 1 if not.
10406 # If we subsequently discover a tag on such a growing tip, and that
10407 # turns out to be a descendent of $anc (which it could, since we
10408 # don't necessarily see children before parents), then $desc
10409 # isn't a good choice to display as a descendent tag of
10410 # $anc (since it is the descendent of another tag which is
10411 # a descendent of $anc). Similarly, $anc isn't a good choice to
10412 # display as a ancestor tag of $desc.
10414 proc is_certain {desc anc} {
10415 global arcnos arcout arcstart arcend growing problems
10418 if {[llength $arcnos($anc)] == 1} {
10419 # tags on the same arc are certain
10420 if {$arcnos($desc) eq $arcnos($anc)} {
10423 if {![info exists arcout($anc)]} {
10424 # if $anc is partway along an arc, use the start of the arc instead
10425 set a [lindex $arcnos($anc) 0]
10426 set anc $arcstart($a)
10429 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10432 set a [lindex $arcnos($desc) 0]
10438 set anclist [list $x]
10442 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10443 set x [lindex $anclist $i]
10448 foreach a $arcout($x) {
10449 if {[info exists growing($a)]} {
10450 if {![info exists growanc($x)] && $dl($x)} {
10456 if {[info exists dl($y)]} {
10460 if {![info exists done($y)]} {
10463 if {[info exists growanc($x)]} {
10467 for {set k 0} {$k < [llength $xl]} {incr k} {
10468 set z [lindex $xl $k]
10469 foreach c $arcout($z) {
10470 if {[info exists arcend($c)]} {
10472 if {[info exists dl($v)] && $dl($v)} {
10474 if {![info exists done($v)]} {
10477 if {[info exists growanc($v)]} {
10487 } elseif {$y eq $anc || !$dl($x)} {
10498 foreach x [array names growanc] {
10507 proc validate_arctags {a} {
10508 global arctags idtags
10511 set na $arctags($a)
10512 foreach id $arctags($a) {
10514 if {![info exists idtags($id)]} {
10515 set na [lreplace $na $i $i]
10519 set arctags($a) $na
10522 proc validate_archeads {a} {
10523 global archeads idheads
10526 set na $archeads($a)
10527 foreach id $archeads($a) {
10529 if {![info exists idheads($id)]} {
10530 set na [lreplace $na $i $i]
10534 set archeads($a) $na
10537 # Return the list of IDs that have tags that are descendents of id,
10538 # ignoring IDs that are descendents of IDs already reported.
10539 proc desctags {id} {
10540 global arcnos arcstart arcids arctags idtags allparents
10541 global growing cached_dtags
10543 if {![info exists allparents($id)]} {
10546 set t1 [clock clicks -milliseconds]
10548 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10549 # part-way along an arc; check that arc first
10550 set a [lindex $arcnos($id) 0]
10551 if {$arctags($a) ne {}} {
10552 validate_arctags $a
10553 set i [lsearch -exact $arcids($a) $id]
10555 foreach t $arctags($a) {
10556 set j [lsearch -exact $arcids($a) $t]
10557 if {$j >= $i} break
10564 set id $arcstart($a)
10565 if {[info exists idtags($id)]} {
10569 if {[info exists cached_dtags($id)]} {
10570 return $cached_dtags($id)
10574 set todo [list $id]
10577 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10578 set id [lindex $todo $i]
10580 set ta [info exists hastaggedancestor($id)]
10584 # ignore tags on starting node
10585 if {!$ta && $i > 0} {
10586 if {[info exists idtags($id)]} {
10587 set tagloc($id) $id
10589 } elseif {[info exists cached_dtags($id)]} {
10590 set tagloc($id) $cached_dtags($id)
10594 foreach a $arcnos($id) {
10595 set d $arcstart($a)
10596 if {!$ta && $arctags($a) ne {}} {
10597 validate_arctags $a
10598 if {$arctags($a) ne {}} {
10599 lappend tagloc($id) [lindex $arctags($a) end]
10602 if {$ta || $arctags($a) ne {}} {
10603 set tomark [list $d]
10604 for {set j 0} {$j < [llength $tomark]} {incr j} {
10605 set dd [lindex $tomark $j]
10606 if {![info exists hastaggedancestor($dd)]} {
10607 if {[info exists done($dd)]} {
10608 foreach b $arcnos($dd) {
10609 lappend tomark $arcstart($b)
10611 if {[info exists tagloc($dd)]} {
10614 } elseif {[info exists queued($dd)]} {
10617 set hastaggedancestor($dd) 1
10621 if {![info exists queued($d)]} {
10624 if {![info exists hastaggedancestor($d)]} {
10631 foreach id [array names tagloc] {
10632 if {![info exists hastaggedancestor($id)]} {
10633 foreach t $tagloc($id) {
10634 if {[lsearch -exact $tags $t] < 0} {
10640 set t2 [clock clicks -milliseconds]
10643 # remove tags that are descendents of other tags
10644 for {set i 0} {$i < [llength $tags]} {incr i} {
10645 set a [lindex $tags $i]
10646 for {set j 0} {$j < $i} {incr j} {
10647 set b [lindex $tags $j]
10648 set r [anc_or_desc $a $b]
10650 set tags [lreplace $tags $j $j]
10653 } elseif {$r == -1} {
10654 set tags [lreplace $tags $i $i]
10661 if {[array names growing] ne {}} {
10662 # graph isn't finished, need to check if any tag could get
10663 # eclipsed by another tag coming later. Simply ignore any
10664 # tags that could later get eclipsed.
10667 if {[is_certain $t $origid]} {
10671 if {$tags eq $ctags} {
10672 set cached_dtags($origid) $tags
10677 set cached_dtags($origid) $tags
10679 set t3 [clock clicks -milliseconds]
10680 if {0 && $t3 - $t1 >= 100} {
10681 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10682 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10687 proc anctags {id} {
10688 global arcnos arcids arcout arcend arctags idtags allparents
10689 global growing cached_atags
10691 if {![info exists allparents($id)]} {
10694 set t1 [clock clicks -milliseconds]
10696 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10697 # part-way along an arc; check that arc first
10698 set a [lindex $arcnos($id) 0]
10699 if {$arctags($a) ne {}} {
10700 validate_arctags $a
10701 set i [lsearch -exact $arcids($a) $id]
10702 foreach t $arctags($a) {
10703 set j [lsearch -exact $arcids($a) $t]
10709 if {![info exists arcend($a)]} {
10713 if {[info exists idtags($id)]} {
10717 if {[info exists cached_atags($id)]} {
10718 return $cached_atags($id)
10722 set todo [list $id]
10726 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10727 set id [lindex $todo $i]
10729 set td [info exists hastaggeddescendent($id)]
10733 # ignore tags on starting node
10734 if {!$td && $i > 0} {
10735 if {[info exists idtags($id)]} {
10736 set tagloc($id) $id
10738 } elseif {[info exists cached_atags($id)]} {
10739 set tagloc($id) $cached_atags($id)
10743 foreach a $arcout($id) {
10744 if {!$td && $arctags($a) ne {}} {
10745 validate_arctags $a
10746 if {$arctags($a) ne {}} {
10747 lappend tagloc($id) [lindex $arctags($a) 0]
10750 if {![info exists arcend($a)]} continue
10752 if {$td || $arctags($a) ne {}} {
10753 set tomark [list $d]
10754 for {set j 0} {$j < [llength $tomark]} {incr j} {
10755 set dd [lindex $tomark $j]
10756 if {![info exists hastaggeddescendent($dd)]} {
10757 if {[info exists done($dd)]} {
10758 foreach b $arcout($dd) {
10759 if {[info exists arcend($b)]} {
10760 lappend tomark $arcend($b)
10763 if {[info exists tagloc($dd)]} {
10766 } elseif {[info exists queued($dd)]} {
10769 set hastaggeddescendent($dd) 1
10773 if {![info exists queued($d)]} {
10776 if {![info exists hastaggeddescendent($d)]} {
10782 set t2 [clock clicks -milliseconds]
10785 foreach id [array names tagloc] {
10786 if {![info exists hastaggeddescendent($id)]} {
10787 foreach t $tagloc($id) {
10788 if {[lsearch -exact $tags $t] < 0} {
10795 # remove tags that are ancestors of other tags
10796 for {set i 0} {$i < [llength $tags]} {incr i} {
10797 set a [lindex $tags $i]
10798 for {set j 0} {$j < $i} {incr j} {
10799 set b [lindex $tags $j]
10800 set r [anc_or_desc $a $b]
10802 set tags [lreplace $tags $j $j]
10805 } elseif {$r == 1} {
10806 set tags [lreplace $tags $i $i]
10813 if {[array names growing] ne {}} {
10814 # graph isn't finished, need to check if any tag could get
10815 # eclipsed by another tag coming later. Simply ignore any
10816 # tags that could later get eclipsed.
10819 if {[is_certain $origid $t]} {
10823 if {$tags eq $ctags} {
10824 set cached_atags($origid) $tags
10829 set cached_atags($origid) $tags
10831 set t3 [clock clicks -milliseconds]
10832 if {0 && $t3 - $t1 >= 100} {
10833 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10834 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10839 # Return the list of IDs that have heads that are descendents of id,
10840 # including id itself if it has a head.
10841 proc descheads {id} {
10842 global arcnos arcstart arcids archeads idheads cached_dheads
10843 global allparents arcout
10845 if {![info exists allparents($id)]} {
10849 if {![info exists arcout($id)]} {
10850 # part-way along an arc; check it first
10851 set a [lindex $arcnos($id) 0]
10852 if {$archeads($a) ne {}} {
10853 validate_archeads $a
10854 set i [lsearch -exact $arcids($a) $id]
10855 foreach t $archeads($a) {
10856 set j [lsearch -exact $arcids($a) $t]
10861 set id $arcstart($a)
10864 set todo [list $id]
10867 for {set i 0} {$i < [llength $todo]} {incr i} {
10868 set id [lindex $todo $i]
10869 if {[info exists cached_dheads($id)]} {
10870 set ret [concat $ret $cached_dheads($id)]
10872 if {[info exists idheads($id)]} {
10875 foreach a $arcnos($id) {
10876 if {$archeads($a) ne {}} {
10877 validate_archeads $a
10878 if {$archeads($a) ne {}} {
10879 set ret [concat $ret $archeads($a)]
10882 set d $arcstart($a)
10883 if {![info exists seen($d)]} {
10890 set ret [lsort -unique $ret]
10891 set cached_dheads($origid) $ret
10892 return [concat $ret $aret]
10895 proc addedtag {id} {
10896 global arcnos arcout cached_dtags cached_atags
10898 if {![info exists arcnos($id)]} return
10899 if {![info exists arcout($id)]} {
10900 recalcarc [lindex $arcnos($id) 0]
10902 catch {unset cached_dtags}
10903 catch {unset cached_atags}
10906 proc addedhead {hid head} {
10907 global arcnos arcout cached_dheads
10909 if {![info exists arcnos($hid)]} return
10910 if {![info exists arcout($hid)]} {
10911 recalcarc [lindex $arcnos($hid) 0]
10913 catch {unset cached_dheads}
10916 proc removedhead {hid head} {
10917 global cached_dheads
10919 catch {unset cached_dheads}
10922 proc movedhead {hid head} {
10923 global arcnos arcout cached_dheads
10925 if {![info exists arcnos($hid)]} return
10926 if {![info exists arcout($hid)]} {
10927 recalcarc [lindex $arcnos($hid) 0]
10929 catch {unset cached_dheads}
10932 proc changedrefs {} {
10933 global cached_dheads cached_dtags cached_atags cached_tagcontent
10934 global arctags archeads arcnos arcout idheads idtags
10936 foreach id [concat [array names idheads] [array names idtags]] {
10937 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10938 set a [lindex $arcnos($id) 0]
10939 if {![info exists donearc($a)]} {
10945 catch {unset cached_tagcontent}
10946 catch {unset cached_dtags}
10947 catch {unset cached_atags}
10948 catch {unset cached_dheads}
10951 proc rereadrefs {} {
10952 global idtags idheads idotherrefs mainheadid
10954 set refids [concat [array names idtags] \
10955 [array names idheads] [array names idotherrefs]]
10956 foreach id $refids {
10957 if {![info exists ref($id)]} {
10958 set ref($id) [listrefs $id]
10961 set oldmainhead $mainheadid
10964 set refids [lsort -unique [concat $refids [array names idtags] \
10965 [array names idheads] [array names idotherrefs]]]
10966 foreach id $refids {
10967 set v [listrefs $id]
10968 if {![info exists ref($id)] || $ref($id) != $v} {
10972 if {$oldmainhead ne $mainheadid} {
10973 redrawtags $oldmainhead
10974 redrawtags $mainheadid
10979 proc listrefs {id} {
10980 global idtags idheads idotherrefs
10983 if {[info exists idtags($id)]} {
10987 if {[info exists idheads($id)]} {
10988 set y $idheads($id)
10991 if {[info exists idotherrefs($id)]} {
10992 set z $idotherrefs($id)
10994 return [list $x $y $z]
10997 proc add_tag_ctext {tag} {
10998 global ctext cached_tagcontent tagids
11000 if {![info exists cached_tagcontent($tag)]} {
11002 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11005 $ctext insert end "[mc "Tag"]: $tag\n" bold
11006 if {[info exists cached_tagcontent($tag)]} {
11007 set text $cached_tagcontent($tag)
11009 set text "[mc "Id"]: $tagids($tag)"
11011 appendwithlinks $text {}
11014 proc showtag {tag isnew} {
11015 global ctext cached_tagcontent tagids linknum tagobjid
11018 addtohistory [list showtag $tag 0] savectextpos
11020 $ctext conf -state normal
11025 maybe_scroll_ctext 1
11026 $ctext conf -state disabled
11030 proc showtags {id isnew} {
11031 global idtags ctext linknum
11034 addtohistory [list showtags $id 0] savectextpos
11036 $ctext conf -state normal
11041 foreach tag $idtags($id) {
11042 $ctext insert end $sep
11046 maybe_scroll_ctext 1
11047 $ctext conf -state disabled
11059 if {[info exists gitktmpdir]} {
11060 catch {file delete -force $gitktmpdir}
11064 proc mkfontdisp {font top which} {
11065 global fontattr fontpref $font NS use_ttk
11067 set fontpref($font) [set $font]
11068 ${NS}::button $top.${font}but -text $which \
11069 -command [list choosefont $font $which]
11070 ${NS}::label $top.$font -relief flat -font $font \
11071 -text $fontattr($font,family) -justify left
11072 grid x $top.${font}but $top.$font -sticky w
11075 proc choosefont {font which} {
11076 global fontparam fontlist fonttop fontattr
11079 set fontparam(which) $which
11080 set fontparam(font) $font
11081 set fontparam(family) [font actual $font -family]
11082 set fontparam(size) $fontattr($font,size)
11083 set fontparam(weight) $fontattr($font,weight)
11084 set fontparam(slant) $fontattr($font,slant)
11087 if {![winfo exists $top]} {
11089 eval font config sample [font actual $font]
11091 make_transient $top $prefstop
11092 wm title $top [mc "Gitk font chooser"]
11093 ${NS}::label $top.l -textvariable fontparam(which)
11094 pack $top.l -side top
11095 set fontlist [lsort [font families]]
11096 ${NS}::frame $top.f
11097 listbox $top.f.fam -listvariable fontlist \
11098 -yscrollcommand [list $top.f.sb set]
11099 bind $top.f.fam <<ListboxSelect>> selfontfam
11100 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11101 pack $top.f.sb -side right -fill y
11102 pack $top.f.fam -side left -fill both -expand 1
11103 pack $top.f -side top -fill both -expand 1
11104 ${NS}::frame $top.g
11105 spinbox $top.g.size -from 4 -to 40 -width 4 \
11106 -textvariable fontparam(size) \
11107 -validatecommand {string is integer -strict %s}
11108 checkbutton $top.g.bold -padx 5 \
11109 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11110 -variable fontparam(weight) -onvalue bold -offvalue normal
11111 checkbutton $top.g.ital -padx 5 \
11112 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11113 -variable fontparam(slant) -onvalue italic -offvalue roman
11114 pack $top.g.size $top.g.bold $top.g.ital -side left
11115 pack $top.g -side top
11116 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11118 $top.c create text 100 25 -anchor center -text $which -font sample \
11119 -fill black -tags text
11120 bind $top.c <Configure> [list centertext $top.c]
11121 pack $top.c -side top -fill x
11122 ${NS}::frame $top.buts
11123 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11124 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11125 bind $top <Key-Return> fontok
11126 bind $top <Key-Escape> fontcan
11127 grid $top.buts.ok $top.buts.can
11128 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11129 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11130 pack $top.buts -side bottom -fill x
11131 trace add variable fontparam write chg_fontparam
11134 $top.c itemconf text -text $which
11136 set i [lsearch -exact $fontlist $fontparam(family)]
11138 $top.f.fam selection set $i
11143 proc centertext {w} {
11144 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11148 global fontparam fontpref prefstop
11150 set f $fontparam(font)
11151 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11152 if {$fontparam(weight) eq "bold"} {
11153 lappend fontpref($f) "bold"
11155 if {$fontparam(slant) eq "italic"} {
11156 lappend fontpref($f) "italic"
11158 set w $prefstop.notebook.fonts.$f
11159 $w conf -text $fontparam(family) -font $fontpref($f)
11165 global fonttop fontparam
11167 if {[info exists fonttop]} {
11168 catch {destroy $fonttop}
11169 catch {font delete sample}
11175 if {[package vsatisfies [package provide Tk] 8.6]} {
11176 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11177 # function to make use of it.
11178 proc choosefont {font which} {
11179 tk fontchooser configure -title $which -font $font \
11180 -command [list on_choosefont $font $which]
11181 tk fontchooser show
11183 proc on_choosefont {font which newfont} {
11185 puts stderr "$font $newfont"
11186 array set f [font actual $newfont]
11187 set fontparam(which) $which
11188 set fontparam(font) $font
11189 set fontparam(family) $f(-family)
11190 set fontparam(size) $f(-size)
11191 set fontparam(weight) $f(-weight)
11192 set fontparam(slant) $f(-slant)
11197 proc selfontfam {} {
11198 global fonttop fontparam
11200 set i [$fonttop.f.fam curselection]
11202 set fontparam(family) [$fonttop.f.fam get $i]
11206 proc chg_fontparam {v sub op} {
11209 font config sample -$sub $fontparam($sub)
11212 # Create a property sheet tab page
11213 proc create_prefs_page {w} {
11215 set parent [join [lrange [split $w .] 0 end-1] .]
11216 if {[winfo class $parent] eq "TNotebook"} {
11219 ${NS}::labelframe $w
11223 proc prefspage_general {notebook} {
11224 global NS maxwidth maxgraphpct showneartags showlocalchanges
11225 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11226 global hideremotes want_ttk have_ttk maxrefs
11228 set page [create_prefs_page $notebook.general]
11230 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11231 grid $page.ldisp - -sticky w -pady 10
11232 ${NS}::label $page.spacer -text " "
11233 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11234 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11235 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11236 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11237 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11238 grid x $page.maxpctl $page.maxpct -sticky w
11239 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11240 -variable showlocalchanges
11241 grid x $page.showlocal -sticky w
11242 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11243 -variable autoselect
11244 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11245 grid x $page.autoselect $page.autosellen -sticky w
11246 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11247 -variable hideremotes
11248 grid x $page.hideremotes -sticky w
11250 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11251 grid $page.ddisp - -sticky w -pady 10
11252 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11253 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11254 grid x $page.tabstopl $page.tabstop -sticky w
11255 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11256 -variable showneartags
11257 grid x $page.ntag -sticky w
11258 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11259 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11260 grid x $page.maxrefsl $page.maxrefs -sticky w
11261 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11262 -variable limitdiffs
11263 grid x $page.ldiff -sticky w
11264 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11265 -variable perfile_attrs
11266 grid x $page.lattr -sticky w
11268 ${NS}::entry $page.extdifft -textvariable extdifftool
11269 ${NS}::frame $page.extdifff
11270 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11271 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11272 pack $page.extdifff.l $page.extdifff.b -side left
11273 pack configure $page.extdifff.l -padx 10
11274 grid x $page.extdifff $page.extdifft -sticky ew
11276 ${NS}::label $page.lgen -text [mc "General options"]
11277 grid $page.lgen - -sticky w -pady 10
11278 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11279 -text [mc "Use themed widgets"]
11281 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11283 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11285 grid x $page.want_ttk $page.ttk_note -sticky w
11289 proc prefspage_colors {notebook} {
11290 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11292 set page [create_prefs_page $notebook.colors]
11294 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11295 grid $page.cdisp - -sticky w -pady 10
11296 label $page.ui -padx 40 -relief sunk -background $uicolor
11297 ${NS}::button $page.uibut -text [mc "Interface"] \
11298 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11299 grid x $page.uibut $page.ui -sticky w
11300 label $page.bg -padx 40 -relief sunk -background $bgcolor
11301 ${NS}::button $page.bgbut -text [mc "Background"] \
11302 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11303 grid x $page.bgbut $page.bg -sticky w
11304 label $page.fg -padx 40 -relief sunk -background $fgcolor
11305 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11306 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11307 grid x $page.fgbut $page.fg -sticky w
11308 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11309 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11310 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11311 [list $ctext tag conf d0 -foreground]]
11312 grid x $page.diffoldbut $page.diffold -sticky w
11313 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11314 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11315 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11316 [list $ctext tag conf dresult -foreground]]
11317 grid x $page.diffnewbut $page.diffnew -sticky w
11318 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11319 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11320 -command [list choosecolor diffcolors 2 $page.hunksep \
11321 [mc "diff hunk header"] \
11322 [list $ctext tag conf hunksep -foreground]]
11323 grid x $page.hunksepbut $page.hunksep -sticky w
11324 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11325 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11326 -command [list choosecolor markbgcolor {} $page.markbgsep \
11327 [mc "marked line background"] \
11328 [list $ctext tag conf omark -background]]
11329 grid x $page.markbgbut $page.markbgsep -sticky w
11330 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11331 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11332 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11333 grid x $page.selbgbut $page.selbgsep -sticky w
11337 proc prefspage_fonts {notebook} {
11339 set page [create_prefs_page $notebook.fonts]
11340 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11341 grid $page.cfont - -sticky w -pady 10
11342 mkfontdisp mainfont $page [mc "Main font"]
11343 mkfontdisp textfont $page [mc "Diff display font"]
11344 mkfontdisp uifont $page [mc "User interface font"]
11349 global maxwidth maxgraphpct use_ttk NS
11350 global oldprefs prefstop showneartags showlocalchanges
11351 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11352 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11353 global hideremotes want_ttk have_ttk
11357 if {[winfo exists $top]} {
11361 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11362 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11363 set oldprefs($v) [set $v]
11366 wm title $top [mc "Gitk preferences"]
11367 make_transient $top .
11369 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11370 set notebook [ttk::notebook $top.notebook]
11372 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11375 lappend pages [prefspage_general $notebook] [mc "General"]
11376 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11377 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11379 foreach {page title} $pages {
11380 if {$use_notebook} {
11381 $notebook add $page -text $title
11383 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11384 -text $title -command [list raise $page]]
11385 $page configure -text $title
11386 grid $btn -row 0 -column [incr col] -sticky w
11387 grid $page -row 1 -column 0 -sticky news -columnspan 100
11391 if {!$use_notebook} {
11392 grid columnconfigure $notebook 0 -weight 1
11393 grid rowconfigure $notebook 1 -weight 1
11394 raise [lindex $pages 0]
11397 grid $notebook -sticky news -padx 2 -pady 2
11398 grid rowconfigure $top 0 -weight 1
11399 grid columnconfigure $top 0 -weight 1
11401 ${NS}::frame $top.buts
11402 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11403 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11404 bind $top <Key-Return> prefsok
11405 bind $top <Key-Escape> prefscan
11406 grid $top.buts.ok $top.buts.can
11407 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11408 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11409 grid $top.buts - - -pady 10 -sticky ew
11410 grid columnconfigure $top 2 -weight 1
11411 bind $top <Visibility> [list focus $top.buts.ok]
11414 proc choose_extdiff {} {
11417 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11419 set extdifftool $prog
11423 proc choosecolor {v vi w x cmd} {
11426 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11427 -title [mc "Gitk: choose color for %s" $x]]
11428 if {$c eq {}} return
11429 $w conf -background $c
11434 proc setselbg {c} {
11435 global bglist cflist
11436 foreach w $bglist {
11437 $w configure -selectbackground $c
11439 $cflist tag configure highlight \
11440 -background [$cflist cget -selectbackground]
11441 allcanvs itemconf secsel -fill $c
11444 # This sets the background color and the color scheme for the whole UI.
11445 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11446 # if we don't specify one ourselves, which makes the checkbuttons and
11447 # radiobuttons look bad. This chooses white for selectColor if the
11448 # background color is light, or black if it is dark.
11450 if {[tk windowingsystem] eq "win32"} { return }
11451 set bg [winfo rgb . $c]
11453 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11456 tk_setPalette background $c selectColor $selc
11462 foreach w $bglist {
11463 $w conf -background $c
11470 foreach w $fglist {
11471 $w conf -foreground $c
11473 allcanvs itemconf text -fill $c
11474 $canv itemconf circle -outline $c
11475 $canv itemconf markid -outline $c
11479 global oldprefs prefstop
11481 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11482 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11484 set $v $oldprefs($v)
11486 catch {destroy $prefstop}
11492 global maxwidth maxgraphpct
11493 global oldprefs prefstop showneartags showlocalchanges
11494 global fontpref mainfont textfont uifont
11495 global limitdiffs treediffs perfile_attrs
11498 catch {destroy $prefstop}
11502 if {$mainfont ne $fontpref(mainfont)} {
11503 set mainfont $fontpref(mainfont)
11504 parsefont mainfont $mainfont
11505 eval font configure mainfont [fontflags mainfont]
11506 eval font configure mainfontbold [fontflags mainfont 1]
11510 if {$textfont ne $fontpref(textfont)} {
11511 set textfont $fontpref(textfont)
11512 parsefont textfont $textfont
11513 eval font configure textfont [fontflags textfont]
11514 eval font configure textfontbold [fontflags textfont 1]
11516 if {$uifont ne $fontpref(uifont)} {
11517 set uifont $fontpref(uifont)
11518 parsefont uifont $uifont
11519 eval font configure uifont [fontflags uifont]
11522 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11523 if {$showlocalchanges} {
11529 if {$limitdiffs != $oldprefs(limitdiffs) ||
11530 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11531 # treediffs elements are limited by path;
11532 # won't have encodings cached if perfile_attrs was just turned on
11533 catch {unset treediffs}
11535 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11536 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11538 } elseif {$showneartags != $oldprefs(showneartags) ||
11539 $limitdiffs != $oldprefs(limitdiffs)} {
11542 if {$hideremotes != $oldprefs(hideremotes)} {
11547 proc formatdate {d} {
11548 global datetimeformat
11550 set d [clock format [lindex $d 0] -format $datetimeformat]
11555 # This list of encoding names and aliases is distilled from
11556 # http://www.iana.org/assignments/character-sets.
11557 # Not all of them are supported by Tcl.
11558 set encoding_aliases {
11559 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11560 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11561 { ISO-10646-UTF-1 csISO10646UTF1 }
11562 { ISO_646.basic:1983 ref csISO646basic1983 }
11563 { INVARIANT csINVARIANT }
11564 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11565 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11566 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11567 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11568 { NATS-DANO iso-ir-9-1 csNATSDANO }
11569 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11570 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11571 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11572 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11573 { ISO-2022-KR csISO2022KR }
11575 { ISO-2022-JP csISO2022JP }
11576 { ISO-2022-JP-2 csISO2022JP2 }
11577 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11578 csISO13JISC6220jp }
11579 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11580 { IT iso-ir-15 ISO646-IT csISO15Italian }
11581 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11582 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11583 { greek7-old iso-ir-18 csISO18Greek7Old }
11584 { latin-greek iso-ir-19 csISO19LatinGreek }
11585 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11586 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11587 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11588 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11589 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11590 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11591 { INIS iso-ir-49 csISO49INIS }
11592 { INIS-8 iso-ir-50 csISO50INIS8 }
11593 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11594 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11595 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11596 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11597 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11598 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11599 csISO60Norwegian1 }
11600 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11601 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11602 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11603 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11604 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11605 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11606 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11607 { greek7 iso-ir-88 csISO88Greek7 }
11608 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11609 { iso-ir-90 csISO90 }
11610 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11611 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11612 csISO92JISC62991984b }
11613 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11614 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11615 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11616 csISO95JIS62291984handadd }
11617 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11618 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11619 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11620 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11621 CP819 csISOLatin1 }
11622 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11623 { T.61-7bit iso-ir-102 csISO102T617bit }
11624 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11625 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11626 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11627 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11628 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11629 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11630 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11631 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11632 arabic csISOLatinArabic }
11633 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11634 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11635 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11636 greek greek8 csISOLatinGreek }
11637 { T.101-G2 iso-ir-128 csISO128T101G2 }
11638 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11640 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11641 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11642 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11643 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11644 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11645 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11646 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11647 csISOLatinCyrillic }
11648 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11649 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11650 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11651 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11652 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11653 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11654 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11655 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11656 { ISO_10367-box iso-ir-155 csISO10367Box }
11657 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11658 { latin-lap lap iso-ir-158 csISO158Lap }
11659 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11660 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11663 { JIS_X0201 X0201 csHalfWidthKatakana }
11664 { KSC5636 ISO646-KR csKSC5636 }
11665 { ISO-10646-UCS-2 csUnicode }
11666 { ISO-10646-UCS-4 csUCS4 }
11667 { DEC-MCS dec csDECMCS }
11668 { hp-roman8 roman8 r8 csHPRoman8 }
11669 { macintosh mac csMacintosh }
11670 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11672 { IBM038 EBCDIC-INT cp038 csIBM038 }
11673 { IBM273 CP273 csIBM273 }
11674 { IBM274 EBCDIC-BE CP274 csIBM274 }
11675 { IBM275 EBCDIC-BR cp275 csIBM275 }
11676 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11677 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11678 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11679 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11680 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11681 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11682 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11683 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11684 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11685 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11686 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11687 { IBM437 cp437 437 csPC8CodePage437 }
11688 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11689 { IBM775 cp775 csPC775Baltic }
11690 { IBM850 cp850 850 csPC850Multilingual }
11691 { IBM851 cp851 851 csIBM851 }
11692 { IBM852 cp852 852 csPCp852 }
11693 { IBM855 cp855 855 csIBM855 }
11694 { IBM857 cp857 857 csIBM857 }
11695 { IBM860 cp860 860 csIBM860 }
11696 { IBM861 cp861 861 cp-is csIBM861 }
11697 { IBM862 cp862 862 csPC862LatinHebrew }
11698 { IBM863 cp863 863 csIBM863 }
11699 { IBM864 cp864 csIBM864 }
11700 { IBM865 cp865 865 csIBM865 }
11701 { IBM866 cp866 866 csIBM866 }
11702 { IBM868 CP868 cp-ar csIBM868 }
11703 { IBM869 cp869 869 cp-gr csIBM869 }
11704 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11705 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11706 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11707 { IBM891 cp891 csIBM891 }
11708 { IBM903 cp903 csIBM903 }
11709 { IBM904 cp904 904 csIBBM904 }
11710 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11711 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11712 { IBM1026 CP1026 csIBM1026 }
11713 { EBCDIC-AT-DE csIBMEBCDICATDE }
11714 { EBCDIC-AT-DE-A csEBCDICATDEA }
11715 { EBCDIC-CA-FR csEBCDICCAFR }
11716 { EBCDIC-DK-NO csEBCDICDKNO }
11717 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11718 { EBCDIC-FI-SE csEBCDICFISE }
11719 { EBCDIC-FI-SE-A csEBCDICFISEA }
11720 { EBCDIC-FR csEBCDICFR }
11721 { EBCDIC-IT csEBCDICIT }
11722 { EBCDIC-PT csEBCDICPT }
11723 { EBCDIC-ES csEBCDICES }
11724 { EBCDIC-ES-A csEBCDICESA }
11725 { EBCDIC-ES-S csEBCDICESS }
11726 { EBCDIC-UK csEBCDICUK }
11727 { EBCDIC-US csEBCDICUS }
11728 { UNKNOWN-8BIT csUnknown8BiT }
11729 { MNEMONIC csMnemonic }
11731 { VISCII csVISCII }
11734 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11735 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11736 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11737 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11738 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11739 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11740 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11741 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11742 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11743 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11744 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11745 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11746 { IBM1047 IBM-1047 }
11747 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11748 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11749 { UNICODE-1-1 csUnicode11 }
11750 { CESU-8 csCESU-8 }
11751 { BOCU-1 csBOCU-1 }
11752 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11753 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11755 { ISO-8859-15 ISO_8859-15 Latin-9 }
11756 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11757 { GBK CP936 MS936 windows-936 }
11758 { JIS_Encoding csJISEncoding }
11759 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11760 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11762 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11763 { ISO-10646-UCS-Basic csUnicodeASCII }
11764 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11765 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11766 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11767 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11768 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11769 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11770 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11771 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11772 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11773 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11774 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11775 { Ventura-US csVenturaUS }
11776 { Ventura-International csVenturaInternational }
11777 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11778 { PC8-Turkish csPC8Turkish }
11779 { IBM-Symbols csIBMSymbols }
11780 { IBM-Thai csIBMThai }
11781 { HP-Legal csHPLegal }
11782 { HP-Pi-font csHPPiFont }
11783 { HP-Math8 csHPMath8 }
11784 { Adobe-Symbol-Encoding csHPPSMath }
11785 { HP-DeskTop csHPDesktop }
11786 { Ventura-Math csVenturaMath }
11787 { Microsoft-Publishing csMicrosoftPublishing }
11788 { Windows-31J csWindows31J }
11789 { GB2312 csGB2312 }
11793 proc tcl_encoding {enc} {
11794 global encoding_aliases tcl_encoding_cache
11795 if {[info exists tcl_encoding_cache($enc)]} {
11796 return $tcl_encoding_cache($enc)
11798 set names [encoding names]
11799 set lcnames [string tolower $names]
11800 set enc [string tolower $enc]
11801 set i [lsearch -exact $lcnames $enc]
11803 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11804 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11805 set i [lsearch -exact $lcnames $encx]
11809 foreach l $encoding_aliases {
11810 set ll [string tolower $l]
11811 if {[lsearch -exact $ll $enc] < 0} continue
11812 # look through the aliases for one that tcl knows about
11814 set i [lsearch -exact $lcnames $e]
11816 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11817 set i [lsearch -exact $lcnames $ex]
11827 set tclenc [lindex $names $i]
11829 set tcl_encoding_cache($enc) $tclenc
11833 proc gitattr {path attr default} {
11834 global path_attr_cache
11835 if {[info exists path_attr_cache($attr,$path)]} {
11836 set r $path_attr_cache($attr,$path)
11838 set r "unspecified"
11839 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11840 regexp "(.*): $attr: (.*)" $line m f r
11842 set path_attr_cache($attr,$path) $r
11844 if {$r eq "unspecified"} {
11850 proc cache_gitattr {attr pathlist} {
11851 global path_attr_cache
11853 foreach path $pathlist {
11854 if {![info exists path_attr_cache($attr,$path)]} {
11855 lappend newlist $path
11859 if {[tk windowingsystem] == "win32"} {
11860 # windows has a 32k limit on the arguments to a command...
11863 while {$newlist ne {}} {
11864 set head [lrange $newlist 0 [expr {$lim - 1}]]
11865 set newlist [lrange $newlist $lim end]
11866 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11867 foreach row [split $rlist "\n"] {
11868 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11869 if {[string index $path 0] eq "\""} {
11870 set path [encoding convertfrom [lindex $path 0]]
11872 set path_attr_cache($attr,$path) $value
11879 proc get_path_encoding {path} {
11880 global gui_encoding perfile_attrs
11881 set tcl_enc $gui_encoding
11882 if {$path ne {} && $perfile_attrs} {
11883 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11891 # First check that Tcl/Tk is recent enough
11892 if {[catch {package require Tk 8.4} err]} {
11893 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11894 Gitk requires at least Tcl/Tk 8.4." list
11898 # on OSX bring the current Wish process window to front
11899 if {[tk windowingsystem] eq "aqua"} {
11900 exec osascript -e [format {
11901 tell application "System Events"
11902 set frontmost of processes whose unix id is %d to true
11907 # Unset GIT_TRACE var if set
11908 if { [info exists ::env(GIT_TRACE)] } {
11909 unset ::env(GIT_TRACE)
11913 set wrcomcmd "git diff-tree --stdin -p --pretty"
11917 set gitencoding [exec git config --get i18n.commitencoding]
11920 set gitencoding [exec git config --get i18n.logoutputencoding]
11922 if {$gitencoding == ""} {
11923 set gitencoding "utf-8"
11925 set tclencoding [tcl_encoding $gitencoding]
11926 if {$tclencoding == {}} {
11927 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11930 set gui_encoding [encoding system]
11932 set enc [exec git config --get gui.encoding]
11934 set tclenc [tcl_encoding $enc]
11935 if {$tclenc ne {}} {
11936 set gui_encoding $tclenc
11938 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11943 set log_showroot true
11945 set log_showroot [exec git config --bool --get log.showroot]
11948 if {[tk windowingsystem] eq "aqua"} {
11949 set mainfont {{Lucida Grande} 9}
11950 set textfont {Monaco 9}
11951 set uifont {{Lucida Grande} 9 bold}
11952 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11954 set mainfont {sans 9}
11955 set textfont {monospace 9}
11956 set uifont {sans 9 bold}
11958 set mainfont {Helvetica 9}
11959 set textfont {Courier 9}
11960 set uifont {Helvetica 9 bold}
11963 set findmergefiles 0
11971 set cmitmode "patch"
11972 set wrapcomment "none"
11977 set showlocalchanges 1
11979 set datetimeformat "%Y-%m-%d %H:%M:%S"
11982 set perfile_attrs 0
11985 if {[tk windowingsystem] eq "aqua"} {
11986 set extdifftool "opendiff"
11988 set extdifftool "meld"
11991 set colors {green red blue magenta darkgrey brown orange}
11992 if {[tk windowingsystem] eq "win32"} {
11993 set uicolor SystemButtonFace
11994 set uifgcolor SystemButtonText
11995 set uifgdisabledcolor SystemDisabledText
11996 set bgcolor SystemWindow
11997 set fgcolor SystemWindowText
11998 set selectbgcolor SystemHighlight
12001 set uifgcolor black
12002 set uifgdisabledcolor "#999"
12005 set selectbgcolor gray85
12007 set diffcolors {red "#00a000" blue}
12009 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12012 set markbgcolor "#e0e0ff"
12014 set headbgcolor green
12015 set headfgcolor black
12016 set headoutlinecolor black
12017 set remotebgcolor #ffddaa
12018 set tagbgcolor yellow
12019 set tagfgcolor black
12020 set tagoutlinecolor black
12021 set reflinecolor black
12022 set filesepbgcolor #aaaaaa
12023 set filesepfgcolor black
12024 set linehoverbgcolor #ffff80
12025 set linehoverfgcolor black
12026 set linehoveroutlinecolor black
12027 set mainheadcirclecolor yellow
12028 set workingfilescirclecolor red
12029 set indexcirclecolor green
12030 set circlecolors {white blue gray blue blue}
12031 set linkfgcolor blue
12032 set circleoutlinecolor $fgcolor
12033 set foundbgcolor yellow
12034 set currentsearchhitbgcolor orange
12036 # button for popping up context menus
12037 if {[tk windowingsystem] eq "aqua"} {
12038 set ctxbut <Button-2>
12040 set ctxbut <Button-3>
12043 ## For msgcat loading, first locate the installation location.
12044 if { [info exists ::env(GITK_MSGSDIR)] } {
12045 ## Msgsdir was manually set in the environment.
12046 set gitk_msgsdir $::env(GITK_MSGSDIR)
12048 ## Let's guess the prefix from argv0.
12049 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12050 set gitk_libdir [file join $gitk_prefix share gitk lib]
12051 set gitk_msgsdir [file join $gitk_libdir msgs]
12055 ## Internationalization (i18n) through msgcat and gettext. See
12056 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12057 package require msgcat
12058 namespace import ::msgcat::mc
12059 ## And eventually load the actual message catalog
12060 ::msgcat::mcload $gitk_msgsdir
12062 catch {source ~/.gitk}
12064 parsefont mainfont $mainfont
12065 eval font create mainfont [fontflags mainfont]
12066 eval font create mainfontbold [fontflags mainfont 1]
12068 parsefont textfont $textfont
12069 eval font create textfont [fontflags textfont]
12070 eval font create textfontbold [fontflags textfont 1]
12072 parsefont uifont $uifont
12073 eval font create uifont [fontflags uifont]
12079 # check that we can find a .git directory somewhere...
12080 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12081 show_error {} . [mc "Cannot find a git repository here."]
12086 set selectheadid {}
12089 set cmdline_files {}
12091 set revtreeargscmd {}
12092 foreach arg $argv {
12093 switch -glob -- $arg {
12096 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12099 "--select-commit=*" {
12100 set selecthead [string range $arg 16 end]
12103 set revtreeargscmd [string range $arg 10 end]
12106 lappend revtreeargs $arg
12112 if {$selecthead eq "HEAD"} {
12116 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12117 # no -- on command line, but some arguments (other than --argscmd)
12119 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12120 set cmdline_files [split $f "\n"]
12121 set n [llength $cmdline_files]
12122 set revtreeargs [lrange $revtreeargs 0 end-$n]
12123 # Unfortunately git rev-parse doesn't produce an error when
12124 # something is both a revision and a filename. To be consistent
12125 # with git log and git rev-list, check revtreeargs for filenames.
12126 foreach arg $revtreeargs {
12127 if {[file exists $arg]} {
12128 show_error {} . [mc "Ambiguous argument '%s': both revision\
12129 and filename" $arg]
12134 # unfortunately we get both stdout and stderr in $err,
12135 # so look for "fatal:".
12136 set i [string first "fatal:" $err]
12138 set err [string range $err [expr {$i + 6}] end]
12140 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12145 set nullid "0000000000000000000000000000000000000000"
12146 set nullid2 "0000000000000000000000000000000000000001"
12147 set nullfile "/dev/null"
12149 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12150 if {![info exists have_ttk]} {
12151 set have_ttk [llength [info commands ::ttk::style]]
12153 set use_ttk [expr {$have_ttk && $want_ttk}]
12154 set NS [expr {$use_ttk ? "ttk" : ""}]
12156 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12159 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12160 set show_notes "--show-notes"
12170 set highlight_paths {}
12172 set searchdirn -forwards
12175 set diffelide {0 0}
12176 set markingmatches 0
12177 set linkentercount 0
12178 set need_redisplay 0
12185 set selectedhlview [mc "None"]
12186 set highlight_related [mc "None"]
12187 set highlight_files {}
12188 set viewfiles(0) {}
12191 set viewargscmd(0) {}
12193 set selectedline {}
12201 set hasworktree [hasworktree]
12203 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12204 set cdup [exec git rev-parse --show-cdup]
12206 set worktree [exec git rev-parse --show-toplevel]
12210 image create photo gitlogo -width 16 -height 16
12212 image create photo gitlogominus -width 4 -height 2
12213 gitlogominus put #C00000 -to 0 0 4 2
12214 gitlogo copy gitlogominus -to 1 5
12215 gitlogo copy gitlogominus -to 6 5
12216 gitlogo copy gitlogominus -to 11 5
12217 image delete gitlogominus
12219 image create photo gitlogoplus -width 4 -height 4
12220 gitlogoplus put #008000 -to 1 0 3 4
12221 gitlogoplus put #008000 -to 0 1 4 3
12222 gitlogo copy gitlogoplus -to 1 9
12223 gitlogo copy gitlogoplus -to 6 9
12224 gitlogo copy gitlogoplus -to 11 9
12225 image delete gitlogoplus
12227 image create photo gitlogo32 -width 32 -height 32
12228 gitlogo32 copy gitlogo -zoom 2 2
12230 wm iconphoto . -default gitlogo gitlogo32
12232 # wait for the window to become visible
12233 tkwait visibility .
12234 wm title . "$appname: [reponame]"
12238 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12239 # create a view for the files/dirs specified on the command line
12243 set viewname(1) [mc "Command line"]
12244 set viewfiles(1) $cmdline_files
12245 set viewargs(1) $revtreeargs
12246 set viewargscmd(1) $revtreeargscmd
12250 .bar.view entryconf [mca "Edit view..."] -state normal
12251 .bar.view entryconf [mca "Delete view"] -state normal
12254 if {[info exists permviews]} {
12255 foreach v $permviews {
12258 set viewname($n) [lindex $v 0]
12259 set viewfiles($n) [lindex $v 1]
12260 set viewargs($n) [lindex $v 2]
12261 set viewargscmd($n) [lindex $v 3]
12267 if {[tk windowingsystem] eq "win32"} {
12275 # indent-tabs-mode: t