2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2009 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.
14 if {[info exists env
(GIT_DIR
)]} {
17 return [exec git rev-parse
--git-dir]
21 # A simple scheduler for compute-intensive stuff.
22 # The aim is to make sure that event handlers for GUI actions can
23 # run at least every 50-100 ms. Unfortunately fileevent handlers are
24 # run before X event handlers, so reading from a fast source can
25 # make the GUI completely unresponsive.
27 global isonrunq runq currunq
30 if {[info exists isonrunq
($script)]} return
31 if {$runq eq
{} && ![info exists currunq
]} {
34 lappend runq
[list
{} $script]
35 set isonrunq
($script) 1
38 proc filerun
{fd
script} {
39 fileevent
$fd readable
[list filereadable
$fd $script]
42 proc filereadable
{fd
script} {
45 fileevent
$fd readable
{}
46 if {$runq eq
{} && ![info exists currunq
]} {
49 lappend runq
[list
$fd $script]
55 for {set i
0} {$i < [llength
$runq]} {} {
56 if {[lindex
$runq $i 0] eq
$fd} {
57 set runq
[lreplace
$runq $i $i]
65 global isonrunq runq currunq
67 set tstart
[clock clicks
-milliseconds]
69 while {[llength
$runq] > 0} {
70 set fd
[lindex
$runq 0 0]
71 set script [lindex
$runq 0 1]
72 set currunq
[lindex
$runq 0]
73 set runq
[lrange
$runq 1 end
]
74 set repeat
[eval $script]
76 set t1
[clock clicks
-milliseconds]
77 set t
[expr {$t1 - $t0}]
78 if {$repeat ne
{} && $repeat} {
79 if {$fd eq
{} ||
$repeat == 2} {
80 # script returns 1 if it wants to be readded
81 # file readers return 2 if they could do more straight away
82 lappend runq
[list
$fd $script]
84 fileevent
$fd readable
[list filereadable
$fd $script]
86 } elseif
{$fd eq
{}} {
87 unset isonrunq
($script)
90 if {$t1 - $tstart >= 80} break
97 proc reg_instance
{fd
} {
98 global commfd leftover loginstance
100 set i
[incr loginstance
]
106 proc unmerged_files
{files
} {
109 # find the list of unmerged files
113 set fd
[open
"| git ls-files -u" r
]
115 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
118 while {[gets $fd line] >= 0} {
119 set i [string first "\t" $line]
121 set fname [string range $line [expr {$i+1}] end]
122 if {[lsearch -exact $mlist $fname] >= 0} continue
124 if {$files eq {} || [path_filter $files $fname]} {
132 proc parseviewargs {n arglist} {
133 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
134 global worddiff git_version
142 set origargs $arglist
146 foreach arg $arglist {
153 switch -glob -- $arg {
157 # remove from origargs in case we hit an unknown option
158 set origargs [lreplace $origargs $i $i]
162 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
163 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
164 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
165 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
166 "--ignore-space-change" - "-U*" - "--unified=*" {
167 # These request or affect diff output, which we don't want.
168 # Some could be used to set our defaults for diff display.
169 lappend diffargs
$arg
171 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
172 "--name-only" - "--name-status" - "--color" -
173 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
174 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
175 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
176 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
177 "--objects" - "--objects-edge" - "--reverse" {
178 # These cause our parsing of git log's output to fail, or else
179 # they're options we want to set ourselves, so ignore them.
181 "--color-words*" - "--word-diff=color" {
182 # These trigger a word diff in the console interface,
183 # so help the user by enabling our own support
184 if {[package vcompare
$git_version "1.7.2"] >= 0} {
185 set worddiff
[mc
"Color words"]
189 if {[package vcompare
$git_version "1.7.2"] >= 0} {
190 set worddiff
[mc
"Markup words"]
193 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
194 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
195 "--full-history" - "--dense" - "--sparse" -
196 "--follow" - "--left-right" - "--encoding=*" {
197 # These are harmless, and some are even useful
200 "--diff-filter=*" - "--no-merges" - "--unpacked" -
201 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
202 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
203 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
204 "--remove-empty" - "--first-parent" - "--cherry-pick" -
205 "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
206 "--simplify-by-decoration" {
207 # These mean that we get a subset of the commits
212 # This appears to be the only one that has a value as a
213 # separate word following it
223 # git rev-parse doesn't understand --merge
224 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
226 "--no-replace-objects" {
227 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
230 # Other flag arguments including -<n>
231 if {[string is digit
-strict [string range
$arg 1 end
]]} {
234 # a flag argument that we don't recognize;
235 # that means we can't optimize
241 # Non-flag arguments specify commits or ranges of commits
242 if {[string match
"*...*" $arg]} {
243 lappend revargs
--gitk-symmetric-diff-marker
249 set vdflags
($n) $diffargs
250 set vflags
($n) $glflags
251 set vrevs
($n) $revargs
252 set vfiltered
($n) $filtered
253 set vorigargs
($n) $origargs
257 proc parseviewrevs
{view revs
} {
258 global vposids vnegids
263 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
264 # we get stdout followed by stderr in $err
265 # for an unknown rev, git rev-parse echoes it and then errors out
266 set errlines
[split $err "\n"]
268 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
269 set line
[lindex
$errlines $l]
270 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
271 if {[string match
"fatal:*" $line]} {
272 if {[string match
"fatal: ambiguous argument*" $line]
274 if {[llength
$badrev] == 1} {
275 set err
"unknown revision $badrev"
277 set err
"unknown revisions: [join $badrev ", "]"
280 set err
[join [lrange
$errlines $l end
] "\n"]
287 error_popup
"[mc "Error parsing revisions
:"] $err"
294 foreach id
[split $ids "\n"] {
295 if {$id eq
"--gitk-symmetric-diff-marker"} {
297 } elseif
{[string match
"^*" $id]} {
304 lappend neg
[string range
$id 1 end
]
309 lset ret end
$id...
[lindex
$ret end
]
315 set vposids
($view) $pos
316 set vnegids
($view) $neg
320 # Start off a git log process and arrange to read its output
321 proc start_rev_list
{view
} {
322 global startmsecs commitidx viewcomplete curview
324 global viewargs viewargscmd viewfiles vfilelimit
325 global showlocalchanges
326 global viewactive viewinstances vmergeonly
327 global mainheadid viewmainheadid viewmainheadid_orig
328 global vcanopt vflags vrevs vorigargs
331 set startmsecs
[clock clicks
-milliseconds]
332 set commitidx
($view) 0
333 # these are set this way for the error exits
334 set viewcomplete
($view) 1
335 set viewactive
($view) 0
338 set args
$viewargs($view)
339 if {$viewargscmd($view) ne
{}} {
341 set str
[exec sh
-c $viewargscmd($view)]
343 error_popup
"[mc "Error executing
--argscmd command:"] $err"
346 set args
[concat
$args [split $str "\n"]]
348 set vcanopt
($view) [parseviewargs
$view $args]
350 set files
$viewfiles($view)
351 if {$vmergeonly($view)} {
352 set files
[unmerged_files
$files]
355 if {$nr_unmerged == 0} {
356 error_popup
[mc
"No files selected: --merge specified but\
357 no files are unmerged."]
359 error_popup
[mc
"No files selected: --merge specified but\
360 no unmerged files are within file limit."]
365 set vfilelimit
($view) $files
367 if {$vcanopt($view)} {
368 set revs
[parseviewrevs
$view $vrevs($view)]
372 set args
[concat
$vflags($view) $revs]
374 set args
$vorigargs($view)
378 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
379 --parents --boundary $args "--" $files] r
]
381 error_popup
"[mc "Error executing git log
:"] $err"
384 set i
[reg_instance
$fd]
385 set viewinstances
($view) [list
$i]
386 set viewmainheadid
($view) $mainheadid
387 set viewmainheadid_orig
($view) $mainheadid
388 if {$files ne
{} && $mainheadid ne
{}} {
389 get_viewmainhead
$view
391 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
392 interestedin
$viewmainheadid($view) dodiffindex
394 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
395 if {$tclencoding != {}} {
396 fconfigure
$fd -encoding $tclencoding
398 filerun
$fd [list getcommitlines
$fd $i $view 0]
399 nowbusy
$view [mc
"Reading"]
400 set viewcomplete
($view) 0
401 set viewactive
($view) 1
405 proc stop_instance
{inst
} {
406 global commfd leftover
408 set fd
$commfd($inst)
412 if {$
::tcl_platform
(platform
) eq
{windows
}} {
421 unset leftover
($inst)
424 proc stop_backends
{} {
427 foreach inst
[array names commfd
] {
432 proc stop_rev_list
{view
} {
435 foreach inst
$viewinstances($view) {
438 set viewinstances
($view) {}
441 proc reset_pending_select
{selid
} {
442 global pending_select mainheadid selectheadid
445 set pending_select
$selid
446 } elseif
{$selectheadid ne
{}} {
447 set pending_select
$selectheadid
449 set pending_select
$mainheadid
453 proc getcommits
{selid
} {
454 global canv curview need_redisplay viewactive
457 if {[start_rev_list
$curview]} {
458 reset_pending_select
$selid
459 show_status
[mc
"Reading commits..."]
462 show_status
[mc
"No commits selected"]
466 proc updatecommits
{} {
467 global curview vcanopt vorigargs vfilelimit viewinstances
468 global viewactive viewcomplete tclencoding
469 global startmsecs showneartags showlocalchanges
470 global mainheadid viewmainheadid viewmainheadid_orig pending_select
472 global varcid vposids vnegids vflags vrevs
475 set isworktree
[expr {[exec git rev-parse
--is-inside-work-tree] == "true"}]
478 if {$mainheadid ne
$viewmainheadid_orig($view)} {
479 if {$showlocalchanges} {
482 set viewmainheadid
($view) $mainheadid
483 set viewmainheadid_orig
($view) $mainheadid
484 if {$vfilelimit($view) ne
{}} {
485 get_viewmainhead
$view
488 if {$showlocalchanges} {
491 if {$vcanopt($view)} {
492 set oldpos
$vposids($view)
493 set oldneg
$vnegids($view)
494 set revs
[parseviewrevs
$view $vrevs($view)]
498 # note: getting the delta when negative refs change is hard,
499 # and could require multiple git log invocations, so in that
500 # case we ask git log for all the commits (not just the delta)
501 if {$oldneg eq
$vnegids($view)} {
504 # take out positive refs that we asked for before or
505 # that we have already seen
507 if {[string length
$rev] == 40} {
508 if {[lsearch
-exact $oldpos $rev] < 0
509 && ![info exists varcid
($view,$rev)]} {
514 lappend
$newrevs $rev
517 if {$npos == 0} return
519 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
521 set args
[concat
$vflags($view) $revs --not $oldpos]
523 set args
$vorigargs($view)
526 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
527 --parents --boundary $args "--" $vfilelimit($view)] r
]
529 error_popup
"[mc "Error executing git log
:"] $err"
532 if {$viewactive($view) == 0} {
533 set startmsecs
[clock clicks
-milliseconds]
535 set i
[reg_instance
$fd]
536 lappend viewinstances
($view) $i
537 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
538 if {$tclencoding != {}} {
539 fconfigure
$fd -encoding $tclencoding
541 filerun
$fd [list getcommitlines
$fd $i $view 1]
542 incr viewactive
($view)
543 set viewcomplete
($view) 0
544 reset_pending_select
{}
545 nowbusy
$view [mc
"Reading"]
551 proc reloadcommits
{} {
552 global curview viewcomplete selectedline currentid thickerline
553 global showneartags treediffs commitinterest cached_commitrow
557 if {$selectedline ne
{}} {
561 if {!$viewcomplete($curview)} {
562 stop_rev_list
$curview
566 catch
{unset currentid
}
567 catch
{unset thickerline
}
568 catch
{unset treediffs
}
575 catch
{unset commitinterest
}
576 catch
{unset cached_commitrow
}
577 catch
{unset targetid
}
583 # This makes a string representation of a positive integer which
584 # sorts as a string in numerical order
587 return [format
"%x" $n]
588 } elseif
{$n < 256} {
589 return [format
"x%.2x" $n]
590 } elseif
{$n < 65536} {
591 return [format
"y%.4x" $n]
593 return [format
"z%.8x" $n]
596 # Procedures used in reordering commits from git log (without
597 # --topo-order) into the order for display.
599 proc varcinit
{view
} {
600 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
601 global vtokmod varcmod vrowmod varcix vlastins
603 set varcstart
($view) {{}}
604 set vupptr
($view) {0}
605 set vdownptr
($view) {0}
606 set vleftptr
($view) {0}
607 set vbackptr
($view) {0}
608 set varctok
($view) {{}}
609 set varcrow
($view) {{}}
610 set vtokmod
($view) {}
613 set varcix
($view) {{}}
614 set vlastins
($view) {0}
617 proc resetvarcs
{view
} {
618 global varcid varccommits parents children vseedcount ordertok
620 foreach vid
[array names varcid
$view,*] {
625 # some commits might have children but haven't been seen yet
626 foreach vid
[array names children
$view,*] {
629 foreach va
[array names varccommits
$view,*] {
630 unset varccommits
($va)
632 foreach vd
[array names vseedcount
$view,*] {
633 unset vseedcount
($vd)
635 catch
{unset ordertok
}
638 # returns a list of the commits with no children
640 global vdownptr vleftptr varcstart
643 set a
[lindex
$vdownptr($v) 0]
645 lappend ret
[lindex
$varcstart($v) $a]
646 set a
[lindex
$vleftptr($v) $a]
651 proc newvarc
{view id
} {
652 global varcid varctok parents children vdatemode
653 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
654 global commitdata commitinfo vseedcount varccommits vlastins
656 set a
[llength
$varctok($view)]
658 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
659 if {![info exists commitinfo
($id)]} {
660 parsecommit
$id $commitdata($id) 1
662 set cdate
[lindex
$commitinfo($id) 4]
663 if {![string is integer
-strict $cdate]} {
666 if {![info exists vseedcount
($view,$cdate)]} {
667 set vseedcount
($view,$cdate) -1
669 set c
[incr vseedcount
($view,$cdate)]
670 set cdate
[expr {$cdate ^
0xffffffff}]
671 set tok
"s[strrep $cdate][strrep $c]"
676 if {[llength
$children($vid)] > 0} {
677 set kid
[lindex
$children($vid) end
]
678 set k
$varcid($view,$kid)
679 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
682 set tok
[lindex
$varctok($view) $k]
686 set i
[lsearch
-exact $parents($view,$ki) $id]
687 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
688 append tok
[strrep
$j]
690 set c
[lindex
$vlastins($view) $ka]
691 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
693 set b
[lindex
$vdownptr($view) $ka]
695 set b
[lindex
$vleftptr($view) $c]
697 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
699 set b
[lindex
$vleftptr($view) $c]
702 lset vdownptr
($view) $ka $a
703 lappend vbackptr
($view) 0
705 lset vleftptr
($view) $c $a
706 lappend vbackptr
($view) $c
708 lset vlastins
($view) $ka $a
709 lappend vupptr
($view) $ka
710 lappend vleftptr
($view) $b
712 lset vbackptr
($view) $b $a
714 lappend varctok
($view) $tok
715 lappend varcstart
($view) $id
716 lappend vdownptr
($view) 0
717 lappend varcrow
($view) {}
718 lappend varcix
($view) {}
719 set varccommits
($view,$a) {}
720 lappend vlastins
($view) 0
724 proc splitvarc
{p v
} {
725 global varcid varcstart varccommits varctok vtokmod
726 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
728 set oa
$varcid($v,$p)
729 set otok
[lindex
$varctok($v) $oa]
730 set ac
$varccommits($v,$oa)
731 set i
[lsearch
-exact $varccommits($v,$oa) $p]
733 set na
[llength
$varctok($v)]
734 # "%" sorts before "0"...
735 set tok
"$otok%[strrep $i]"
736 lappend varctok
($v) $tok
737 lappend varcrow
($v) {}
738 lappend varcix
($v) {}
739 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
740 set varccommits
($v,$na) [lrange
$ac $i end
]
741 lappend varcstart
($v) $p
742 foreach id
$varccommits($v,$na) {
743 set varcid
($v,$id) $na
745 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
746 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
747 lset vdownptr
($v) $oa $na
748 lset vlastins
($v) $oa 0
749 lappend vupptr
($v) $oa
750 lappend vleftptr
($v) 0
751 lappend vbackptr
($v) 0
752 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
753 lset vupptr
($v) $b $na
755 if {[string compare
$otok $vtokmod($v)] <= 0} {
760 proc renumbervarc
{a v
} {
761 global parents children varctok varcstart varccommits
762 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
764 set t1
[clock clicks
-milliseconds]
770 if {[info exists isrelated
($a)]} {
772 set id
[lindex
$varccommits($v,$a) end
]
773 foreach p
$parents($v,$id) {
774 if {[info exists varcid
($v,$p)]} {
775 set isrelated
($varcid($v,$p)) 1
780 set b
[lindex
$vdownptr($v) $a]
783 set b
[lindex
$vleftptr($v) $a]
785 set a
[lindex
$vupptr($v) $a]
791 if {![info exists kidchanged
($a)]} continue
792 set id
[lindex
$varcstart($v) $a]
793 if {[llength
$children($v,$id)] > 1} {
794 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
797 set oldtok
[lindex
$varctok($v) $a]
798 if {!$vdatemode($v)} {
804 set kid
[last_real_child
$v,$id]
806 set k
$varcid($v,$kid)
807 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
810 set tok
[lindex
$varctok($v) $k]
814 set i
[lsearch
-exact $parents($v,$ki) $id]
815 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
816 append tok
[strrep
$j]
818 if {$tok eq
$oldtok} {
821 set id
[lindex
$varccommits($v,$a) end
]
822 foreach p
$parents($v,$id) {
823 if {[info exists varcid
($v,$p)]} {
824 set kidchanged
($varcid($v,$p)) 1
829 lset varctok
($v) $a $tok
830 set b
[lindex
$vupptr($v) $a]
832 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
835 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
838 set c
[lindex
$vbackptr($v) $a]
839 set d
[lindex
$vleftptr($v) $a]
841 lset vdownptr
($v) $b $d
843 lset vleftptr
($v) $c $d
846 lset vbackptr
($v) $d $c
848 if {[lindex
$vlastins($v) $b] == $a} {
849 lset vlastins
($v) $b $c
851 lset vupptr
($v) $a $ka
852 set c
[lindex
$vlastins($v) $ka]
854 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
856 set b
[lindex
$vdownptr($v) $ka]
858 set b
[lindex
$vleftptr($v) $c]
861 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
863 set b
[lindex
$vleftptr($v) $c]
866 lset vdownptr
($v) $ka $a
867 lset vbackptr
($v) $a 0
869 lset vleftptr
($v) $c $a
870 lset vbackptr
($v) $a $c
872 lset vleftptr
($v) $a $b
874 lset vbackptr
($v) $b $a
876 lset vlastins
($v) $ka $a
879 foreach id
[array names sortkids
] {
880 if {[llength
$children($v,$id)] > 1} {
881 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
885 set t2
[clock clicks
-milliseconds]
886 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
889 # Fix up the graph after we have found out that in view $v,
890 # $p (a commit that we have already seen) is actually the parent
891 # of the last commit in arc $a.
892 proc fix_reversal
{p a v
} {
893 global varcid varcstart varctok vupptr
895 set pa
$varcid($v,$p)
896 if {$p ne
[lindex
$varcstart($v) $pa]} {
898 set pa
$varcid($v,$p)
900 # seeds always need to be renumbered
901 if {[lindex
$vupptr($v) $pa] == 0 ||
902 [string compare
[lindex
$varctok($v) $a] \
903 [lindex
$varctok($v) $pa]] > 0} {
908 proc insertrow
{id p v
} {
909 global cmitlisted children parents varcid varctok vtokmod
910 global varccommits ordertok commitidx numcommits curview
911 global targetid targetrow
915 set cmitlisted
($vid) 1
916 set children
($vid) {}
917 set parents
($vid) [list
$p]
918 set a
[newvarc
$v $id]
920 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
923 lappend varccommits
($v,$a) $id
925 if {[llength
[lappend children
($vp) $id]] > 1} {
926 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
927 catch
{unset ordertok
}
929 fix_reversal
$p $a $v
931 if {$v == $curview} {
932 set numcommits
$commitidx($v)
934 if {[info exists targetid
]} {
935 if {![comes_before
$targetid $p]} {
942 proc insertfakerow
{id p
} {
943 global varcid varccommits parents children cmitlisted
944 global commitidx varctok vtokmod targetid targetrow curview numcommits
948 set i
[lsearch
-exact $varccommits($v,$a) $p]
950 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
953 set children
($v,$id) {}
954 set parents
($v,$id) [list
$p]
955 set varcid
($v,$id) $a
956 lappend children
($v,$p) $id
957 set cmitlisted
($v,$id) 1
958 set numcommits
[incr commitidx
($v)]
959 # note we deliberately don't update varcstart($v) even if $i == 0
960 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
962 if {[info exists targetid
]} {
963 if {![comes_before
$targetid $p]} {
971 proc removefakerow
{id
} {
972 global varcid varccommits parents children commitidx
973 global varctok vtokmod cmitlisted currentid selectedline
974 global targetid curview numcommits
977 if {[llength
$parents($v,$id)] != 1} {
978 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
981 set p
[lindex
$parents($v,$id) 0]
982 set a
$varcid($v,$id)
983 set i
[lsearch
-exact $varccommits($v,$a) $id]
985 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
989 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
990 unset parents
($v,$id)
991 unset children
($v,$id)
992 unset cmitlisted
($v,$id)
993 set numcommits
[incr commitidx
($v) -1]
994 set j
[lsearch
-exact $children($v,$p) $id]
996 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
999 if {[info exist currentid
] && $id eq
$currentid} {
1003 if {[info exists targetid
] && $targetid eq
$id} {
1010 proc real_children
{vp
} {
1011 global children nullid nullid2
1014 foreach id
$children($vp) {
1015 if {$id ne
$nullid && $id ne
$nullid2} {
1022 proc first_real_child
{vp
} {
1023 global children nullid nullid2
1025 foreach id
$children($vp) {
1026 if {$id ne
$nullid && $id ne
$nullid2} {
1033 proc last_real_child
{vp
} {
1034 global children nullid nullid2
1036 set kids
$children($vp)
1037 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1038 set id
[lindex
$kids $i]
1039 if {$id ne
$nullid && $id ne
$nullid2} {
1046 proc vtokcmp
{v a b
} {
1047 global varctok varcid
1049 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1050 [lindex
$varctok($v) $varcid($v,$b)]]
1053 # This assumes that if lim is not given, the caller has checked that
1054 # arc a's token is less than $vtokmod($v)
1055 proc modify_arc
{v a
{lim
{}}} {
1056 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1059 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1062 set r
[lindex
$varcrow($v) $a]
1063 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1066 set vtokmod
($v) [lindex
$varctok($v) $a]
1068 if {$v == $curview} {
1069 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1070 set a
[lindex
$vupptr($v) $a]
1076 set lim
[llength
$varccommits($v,$a)]
1078 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1085 proc update_arcrows
{v
} {
1086 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1087 global varcid vrownum varcorder varcix varccommits
1088 global vupptr vdownptr vleftptr varctok
1089 global displayorder parentlist curview cached_commitrow
1091 if {$vrowmod($v) == $commitidx($v)} return
1092 if {$v == $curview} {
1093 if {[llength
$displayorder] > $vrowmod($v)} {
1094 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1095 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1097 catch
{unset cached_commitrow
}
1099 set narctot
[expr {[llength
$varctok($v)] - 1}]
1101 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1102 # go up the tree until we find something that has a row number,
1103 # or we get to a seed
1104 set a
[lindex
$vupptr($v) $a]
1107 set a
[lindex
$vdownptr($v) 0]
1110 set varcorder
($v) [list
$a]
1111 lset varcix
($v) $a 0
1112 lset varcrow
($v) $a 0
1116 set arcn
[lindex
$varcix($v) $a]
1117 if {[llength
$vrownum($v)] > $arcn + 1} {
1118 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1119 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1121 set row
[lindex
$varcrow($v) $a]
1125 incr row
[llength
$varccommits($v,$a)]
1126 # go down if possible
1127 set b
[lindex
$vdownptr($v) $a]
1129 # if not, go left, or go up until we can go left
1131 set b
[lindex
$vleftptr($v) $a]
1133 set a
[lindex
$vupptr($v) $a]
1139 lappend vrownum
($v) $row
1140 lappend varcorder
($v) $a
1141 lset varcix
($v) $a $arcn
1142 lset varcrow
($v) $a $row
1144 set vtokmod
($v) [lindex
$varctok($v) $p]
1146 set vrowmod
($v) $row
1147 if {[info exists currentid
]} {
1148 set selectedline
[rowofcommit
$currentid]
1152 # Test whether view $v contains commit $id
1153 proc commitinview
{id v
} {
1156 return [info exists varcid
($v,$id)]
1159 # Return the row number for commit $id in the current view
1160 proc rowofcommit
{id
} {
1161 global varcid varccommits varcrow curview cached_commitrow
1162 global varctok vtokmod
1165 if {![info exists varcid
($v,$id)]} {
1166 puts
"oops rowofcommit no arc for [shortids $id]"
1169 set a
$varcid($v,$id)
1170 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1173 if {[info exists cached_commitrow
($id)]} {
1174 return $cached_commitrow($id)
1176 set i
[lsearch
-exact $varccommits($v,$a) $id]
1178 puts
"oops didn't find commit [shortids $id] in arc $a"
1181 incr i
[lindex
$varcrow($v) $a]
1182 set cached_commitrow
($id) $i
1186 # Returns 1 if a is on an earlier row than b, otherwise 0
1187 proc comes_before
{a b
} {
1188 global varcid varctok curview
1191 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1192 ![info exists varcid
($v,$b)]} {
1195 if {$varcid($v,$a) != $varcid($v,$b)} {
1196 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1197 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1199 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1202 proc bsearch
{l elt
} {
1203 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1208 while {$hi - $lo > 1} {
1209 set mid
[expr {int
(($lo + $hi) / 2)}]
1210 set t
[lindex
$l $mid]
1213 } elseif
{$elt > $t} {
1222 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1223 proc make_disporder
{start end
} {
1224 global vrownum curview commitidx displayorder parentlist
1225 global varccommits varcorder parents vrowmod varcrow
1226 global d_valid_start d_valid_end
1228 if {$end > $vrowmod($curview)} {
1229 update_arcrows
$curview
1231 set ai
[bsearch
$vrownum($curview) $start]
1232 set start
[lindex
$vrownum($curview) $ai]
1233 set narc
[llength
$vrownum($curview)]
1234 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1235 set a
[lindex
$varcorder($curview) $ai]
1236 set l
[llength
$displayorder]
1237 set al
[llength
$varccommits($curview,$a)]
1238 if {$l < $r + $al} {
1240 set pad
[ntimes
[expr {$r - $l}] {}]
1241 set displayorder
[concat
$displayorder $pad]
1242 set parentlist
[concat
$parentlist $pad]
1243 } elseif
{$l > $r} {
1244 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1245 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1247 foreach id
$varccommits($curview,$a) {
1248 lappend displayorder
$id
1249 lappend parentlist
$parents($curview,$id)
1251 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1253 foreach id
$varccommits($curview,$a) {
1254 lset displayorder
$i $id
1255 lset parentlist
$i $parents($curview,$id)
1263 proc commitonrow
{row
} {
1266 set id
[lindex
$displayorder $row]
1268 make_disporder
$row [expr {$row + 1}]
1269 set id
[lindex
$displayorder $row]
1274 proc closevarcs
{v
} {
1275 global varctok varccommits varcid parents children
1276 global cmitlisted commitidx vtokmod
1278 set missing_parents
0
1280 set narcs
[llength
$varctok($v)]
1281 for {set a
1} {$a < $narcs} {incr a
} {
1282 set id
[lindex
$varccommits($v,$a) end
]
1283 foreach p
$parents($v,$id) {
1284 if {[info exists varcid
($v,$p)]} continue
1285 # add p as a new commit
1286 incr missing_parents
1287 set cmitlisted
($v,$p) 0
1288 set parents
($v,$p) {}
1289 if {[llength
$children($v,$p)] == 1 &&
1290 [llength
$parents($v,$id)] == 1} {
1293 set b
[newvarc
$v $p]
1295 set varcid
($v,$p) $b
1296 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1299 lappend varccommits
($v,$b) $p
1301 set scripts
[check_interest
$p $scripts]
1304 if {$missing_parents > 0} {
1305 foreach s
$scripts {
1311 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1312 # Assumes we already have an arc for $rwid.
1313 proc rewrite_commit
{v id rwid
} {
1314 global children parents varcid varctok vtokmod varccommits
1316 foreach ch
$children($v,$id) {
1317 # make $rwid be $ch's parent in place of $id
1318 set i
[lsearch
-exact $parents($v,$ch) $id]
1320 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1322 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1323 # add $ch to $rwid's children and sort the list if necessary
1324 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1325 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1326 $children($v,$rwid)]
1328 # fix the graph after joining $id to $rwid
1329 set a
$varcid($v,$ch)
1330 fix_reversal
$rwid $a $v
1331 # parentlist is wrong for the last element of arc $a
1332 # even if displayorder is right, hence the 3rd arg here
1333 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1337 # Mechanism for registering a command to be executed when we come
1338 # across a particular commit. To handle the case when only the
1339 # prefix of the commit is known, the commitinterest array is now
1340 # indexed by the first 4 characters of the ID. Each element is a
1341 # list of id, cmd pairs.
1342 proc interestedin
{id cmd
} {
1343 global commitinterest
1345 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1348 proc check_interest
{id scripts
} {
1349 global commitinterest
1351 set prefix
[string range
$id 0 3]
1352 if {[info exists commitinterest
($prefix)]} {
1354 foreach
{i
script} $commitinterest($prefix) {
1355 if {[string match
"$i*" $id]} {
1356 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1358 lappend newlist
$i $script
1361 if {$newlist ne
{}} {
1362 set commitinterest
($prefix) $newlist
1364 unset commitinterest
($prefix)
1370 proc getcommitlines
{fd inst view updating
} {
1371 global cmitlisted leftover
1372 global commitidx commitdata vdatemode
1373 global parents children curview hlview
1374 global idpending ordertok
1375 global varccommits varcid varctok vtokmod vfilelimit
1377 set stuff
[read $fd 500000]
1378 # git log doesn't terminate the last commit with a null...
1379 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1386 global commfd viewcomplete viewactive viewname
1387 global viewinstances
1389 set i
[lsearch
-exact $viewinstances($view) $inst]
1391 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1393 # set it blocking so we wait for the process to terminate
1394 fconfigure
$fd -blocking 1
1395 if {[catch
{close
$fd} err
]} {
1397 if {$view != $curview} {
1398 set fv
" for the \"$viewname($view)\" view"
1400 if {[string range
$err 0 4] == "usage"} {
1401 set err
"Gitk: error reading commits$fv:\
1402 bad arguments to git log."
1403 if {$viewname($view) eq
"Command line"} {
1405 " (Note: arguments to gitk are passed to git log\
1406 to allow selection of commits to be displayed.)"
1409 set err
"Error reading commits$fv: $err"
1413 if {[incr viewactive
($view) -1] <= 0} {
1414 set viewcomplete
($view) 1
1415 # Check if we have seen any ids listed as parents that haven't
1416 # appeared in the list
1420 if {$view == $curview} {
1429 set i
[string first
"\0" $stuff $start]
1431 append leftover
($inst) [string range
$stuff $start end
]
1435 set cmit
$leftover($inst)
1436 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1437 set leftover
($inst) {}
1439 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1441 set start
[expr {$i + 1}]
1442 set j
[string first
"\n" $cmit]
1445 if {$j >= 0 && [string match
"commit *" $cmit]} {
1446 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1447 if {[string match
{[-^
<>]*} $ids]} {
1448 switch
-- [string index
$ids 0] {
1454 set ids
[string range
$ids 1 end
]
1458 if {[string length
$id] != 40} {
1466 if {[string length
$shortcmit] > 80} {
1467 set shortcmit
"[string range $shortcmit 0 80]..."
1469 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1472 set id [lindex $ids 0]
1475 if {!$listed && $updating && ![info exists varcid($vid)] &&
1476 $vfilelimit($view) ne {}} {
1477 # git log doesn't rewrite parents
for unlisted commits
1478 # when doing path limiting, so work around that here
1479 # by working out the rewritten parent with git rev-list
1480 # and if we already know about it, using the rewritten
1481 # parent as a substitute parent for $id's children.
1483 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1484 $id -- $vfilelimit($view)]
1486 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1487 # use $rwid in place of $id
1488 rewrite_commit
$view $id $rwid
1495 if {[info exists varcid
($vid)]} {
1496 if {$cmitlisted($vid) ||
!$listed} continue
1500 set olds
[lrange
$ids 1 end
]
1504 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1505 set cmitlisted
($vid) $listed
1506 set parents
($vid) $olds
1507 if {![info exists children
($vid)]} {
1508 set children
($vid) {}
1509 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1510 set k
[lindex
$children($vid) 0]
1511 if {[llength
$parents($view,$k)] == 1 &&
1512 (!$vdatemode($view) ||
1513 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1514 set a
$varcid($view,$k)
1519 set a
[newvarc
$view $id]
1521 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1524 if {![info exists varcid
($vid)]} {
1526 lappend varccommits
($view,$a) $id
1527 incr commitidx
($view)
1532 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1534 if {[llength
[lappend children
($vp) $id]] > 1 &&
1535 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1536 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1538 catch
{unset ordertok
}
1540 if {[info exists varcid
($view,$p)]} {
1541 fix_reversal
$p $a $view
1547 set scripts
[check_interest
$id $scripts]
1551 global numcommits hlview
1553 if {$view == $curview} {
1554 set numcommits
$commitidx($view)
1557 if {[info exists hlview
] && $view == $hlview} {
1558 # we never actually get here...
1561 foreach s
$scripts {
1568 proc chewcommits
{} {
1569 global curview hlview viewcomplete
1570 global pending_select
1573 if {$viewcomplete($curview)} {
1574 global commitidx varctok
1575 global numcommits startmsecs
1577 if {[info exists pending_select
]} {
1579 reset_pending_select
{}
1581 if {[commitinview
$pending_select $curview]} {
1582 selectline
[rowofcommit
$pending_select] 1
1584 set row
[first_real_row
]
1588 if {$commitidx($curview) > 0} {
1589 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1590 #puts "overall $ms ms for $numcommits commits"
1591 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1593 show_status
[mc
"No commits selected"]
1600 proc do_readcommit
{id
} {
1603 # Invoke git-log to handle automatic encoding conversion
1604 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1605 # Read the results using i18n.logoutputencoding
1606 fconfigure
$fd -translation lf
-eofchar {}
1607 if {$tclencoding != {}} {
1608 fconfigure
$fd -encoding $tclencoding
1610 set contents
[read $fd]
1612 # Remove the heading line
1613 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1618 proc readcommit
{id
} {
1619 if {[catch
{set contents
[do_readcommit
$id]}]} return
1620 parsecommit
$id $contents 1
1623 proc parsecommit
{id contents listed
} {
1633 set hdrend
[string first
"\n\n" $contents]
1635 # should never happen...
1636 set hdrend
[string length
$contents]
1638 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1639 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1640 foreach line
[split $header "\n"] {
1641 set line
[split $line " "]
1642 set tag
[lindex
$line 0]
1643 if {$tag == "author"} {
1644 set audate
[lindex
$line end-1
]
1645 set auname
[join [lrange
$line 1 end-2
] " "]
1646 } elseif
{$tag == "committer"} {
1647 set comdate
[lindex
$line end-1
]
1648 set comname
[join [lrange
$line 1 end-2
] " "]
1652 # take the first non-blank line of the comment as the headline
1653 set headline
[string trimleft
$comment]
1654 set i
[string first
"\n" $headline]
1656 set headline
[string range
$headline 0 $i]
1658 set headline
[string trimright
$headline]
1659 set i
[string first
"\r" $headline]
1661 set headline
[string trimright
[string range
$headline 0 $i]]
1664 # git log indents the comment by 4 spaces;
1665 # if we got this via git cat-file, add the indentation
1667 foreach line
[split $comment "\n"] {
1668 append newcomment
" "
1669 append newcomment
$line
1670 append newcomment
"\n"
1672 set comment
$newcomment
1674 set commitinfo
($id) [list
$headline $auname $audate \
1675 $comname $comdate $comment]
1678 proc getcommit
{id
} {
1679 global commitdata commitinfo
1681 if {[info exists commitdata
($id)]} {
1682 parsecommit
$id $commitdata($id) 1
1685 if {![info exists commitinfo
($id)]} {
1686 set commitinfo
($id) [list
[mc
"No commit information available"]]
1692 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1693 # and are present in the current view.
1694 # This is fairly slow...
1695 proc longid
{prefix
} {
1696 global varcid curview
1699 foreach match
[array names varcid
"$curview,$prefix*"] {
1700 lappend ids
[lindex
[split $match ","] 1]
1706 global tagids idtags headids idheads tagobjid
1707 global otherrefids idotherrefs mainhead mainheadid
1708 global selecthead selectheadid
1711 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1714 set refd
[open
[list | git show-ref
-d] r
]
1715 while {[gets
$refd line
] >= 0} {
1716 if {[string index
$line 40] ne
" "} continue
1717 set id
[string range
$line 0 39]
1718 set ref
[string range
$line 41 end
]
1719 if {![string match
"refs/*" $ref]} continue
1720 set name
[string range
$ref 5 end
]
1721 if {[string match
"remotes/*" $name]} {
1722 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1723 set headids
($name) $id
1724 lappend idheads
($id) $name
1726 } elseif
{[string match
"heads/*" $name]} {
1727 set name
[string range
$name 6 end
]
1728 set headids
($name) $id
1729 lappend idheads
($id) $name
1730 } elseif
{[string match
"tags/*" $name]} {
1731 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1732 # which is what we want since the former is the commit ID
1733 set name
[string range
$name 5 end
]
1734 if {[string match
"*^{}" $name]} {
1735 set name
[string range
$name 0 end-3
]
1737 set tagobjid
($name) $id
1739 set tagids
($name) $id
1740 lappend idtags
($id) $name
1742 set otherrefids
($name) $id
1743 lappend idotherrefs
($id) $name
1750 set mainheadid
[exec git rev-parse HEAD
]
1751 set thehead
[exec git symbolic-ref HEAD
]
1752 if {[string match
"refs/heads/*" $thehead]} {
1753 set mainhead
[string range
$thehead 11 end
]
1757 if {$selecthead ne
{}} {
1759 set selectheadid
[exec git rev-parse
--verify $selecthead]
1764 # skip over fake commits
1765 proc first_real_row
{} {
1766 global nullid nullid2 numcommits
1768 for {set row
0} {$row < $numcommits} {incr row
} {
1769 set id
[commitonrow
$row]
1770 if {$id ne
$nullid && $id ne
$nullid2} {
1777 # update things for a head moved to a child of its previous location
1778 proc movehead
{id name
} {
1779 global headids idheads
1781 removehead
$headids($name) $name
1782 set headids
($name) $id
1783 lappend idheads
($id) $name
1786 # update things when a head has been removed
1787 proc removehead
{id name
} {
1788 global headids idheads
1790 if {$idheads($id) eq
$name} {
1793 set i
[lsearch
-exact $idheads($id) $name]
1795 set idheads
($id) [lreplace
$idheads($id) $i $i]
1798 unset headids
($name)
1801 proc ttk_toplevel
{w args
} {
1803 eval [linsert
$args 0 ::toplevel
$w]
1805 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1810 proc make_transient
{window origin
} {
1813 # In MacOS Tk 8.4 transient appears to work by setting
1814 # overrideredirect, which is utterly useless, since the
1815 # windows get no border, and are not even kept above
1817 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1819 wm transient
$window $origin
1821 # Windows fails to place transient windows normally, so
1822 # schedule a callback to center them on the parent.
1823 if {[tk windowingsystem
] eq
{win32
}} {
1824 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1828 proc show_error
{w top msg
{mc mc
}} {
1830 if {![info exists NS
]} {set NS
""}
1831 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1832 message
$w.m
-text $msg -justify center
-aspect 400
1833 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1834 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1835 pack
$w.ok
-side bottom
-fill x
1836 bind $top <Visibility
> "grab $top; focus $top"
1837 bind $top <Key-Return
> "destroy $top"
1838 bind $top <Key-space
> "destroy $top"
1839 bind $top <Key-Escape
> "destroy $top"
1843 proc error_popup
{msg
{owner .
}} {
1844 if {[tk windowingsystem
] eq
"win32"} {
1845 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1846 -parent $owner -message $msg
1850 make_transient
$w $owner
1851 show_error
$w $w $msg
1855 proc confirm_popup
{msg
{owner .
}} {
1856 global confirm_ok NS
1860 make_transient
$w $owner
1861 message
$w.m
-text $msg -justify center
-aspect 400
1862 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1863 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1864 pack
$w.ok
-side left
-fill x
1865 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1866 pack
$w.cancel
-side right
-fill x
1867 bind $w <Visibility
> "grab $w; focus $w"
1868 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1869 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1870 bind $w <Key-Escape
> "destroy $w"
1871 tk
::PlaceWindow
$w widget
$owner
1876 proc setoptions
{} {
1877 if {[tk windowingsystem
] ne
"win32"} {
1878 option add
*Panedwindow.showHandle
1 startupFile
1879 option add
*Panedwindow.sashRelief raised startupFile
1880 if {[tk windowingsystem
] ne
"aqua"} {
1881 option add
*Menu.font uifont startupFile
1884 option add
*Menu.TearOff
0 startupFile
1886 option add
*Button.font uifont startupFile
1887 option add
*Checkbutton.font uifont startupFile
1888 option add
*Radiobutton.font uifont startupFile
1889 option add
*Menubutton.font uifont startupFile
1890 option add
*Label.font uifont startupFile
1891 option add
*Message.font uifont startupFile
1892 option add
*Entry.font textfont startupFile
1893 option add
*Text.font textfont startupFile
1894 option add
*Labelframe.font uifont startupFile
1895 option add
*Spinbox.font textfont startupFile
1896 option add
*Listbox.font mainfont startupFile
1899 # Make a menu and submenus.
1900 # m is the window name for the menu, items is the list of menu items to add.
1901 # Each item is a list {mc label type description options...}
1902 # mc is ignored; it's so we can put mc there to alert xgettext
1903 # label is the string that appears in the menu
1904 # type is cascade, command or radiobutton (should add checkbutton)
1905 # description depends on type; it's the sublist for cascade, the
1906 # command to invoke for command, or {variable value} for radiobutton
1907 proc makemenu
{m items
} {
1909 if {[tk windowingsystem
] eq
{aqua
}} {
1915 set name
[mc
[lindex
$i 1]]
1916 set type [lindex
$i 2]
1917 set thing
[lindex
$i 3]
1918 set params
[list
$type]
1920 set u
[string first
"&" [string map
{&& x
} $name]]
1921 lappend params
-label [string map
{&& & & {}} $name]
1923 lappend params
-underline $u
1928 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1929 lappend params
-menu $m.
$submenu
1932 lappend params
-command $thing
1935 lappend params
-variable [lindex
$thing 0] \
1936 -value [lindex
$thing 1]
1939 set tail [lrange
$i 4 end
]
1940 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
1941 eval $m add
$params $tail
1942 if {$type eq
"cascade"} {
1943 makemenu
$m.
$submenu $thing
1948 # translate string and remove ampersands
1950 return [string map
{&& & & {}} [mc
$str]]
1953 proc makedroplist
{w varname args
} {
1957 foreach label
$args {
1958 set cx
[string length
$label]
1959 if {$cx > $width} {set width
$cx}
1961 set gm
[ttk
::combobox
$w -width $width -state readonly\
1962 -textvariable $varname -values $args]
1964 set gm
[eval [linsert
$args 0 tk_optionMenu
$w $varname]]
1969 proc makewindow
{} {
1970 global canv canv2 canv3 linespc charspc ctext cflist cscroll
1972 global findtype findtypemenu findloc findstring fstring geometry
1973 global entries sha1entry sha1string sha1but
1974 global diffcontextstring diffcontext
1976 global maincursor textcursor curtextcursor
1977 global rowctxmenu fakerowmenu mergemax wrapcomment
1978 global highlight_files gdttype
1979 global searchstring sstring
1980 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
1981 global headctxmenu progresscanv progressitem progresscoords statusw
1982 global fprogitem fprogcoord lastprogupdate progupdatepending
1983 global rprogitem rprogcoord rownumsel numcommits
1984 global have_tk85 use_ttk NS
1988 # The "mc" arguments here are purely so that xgettext
1989 # sees the following string as needing to be translated
1992 {mc
"Update" command updatecommits
-accelerator F5
}
1993 {mc
"Reload" command reloadcommits
-accelerator Meta1-F5
}
1994 {mc
"Reread references" command rereadrefs
}
1995 {mc
"List references" command showrefs
-accelerator F2
}
1997 {mc
"Start git gui" command {exec git gui
&}}
1999 {mc
"Quit" command doquit
-accelerator Meta1-Q
}
2003 {mc
"Preferences" command doprefs
}
2007 {mc
"New view..." command {newview
0} -accelerator Shift-F4
}
2008 {mc
"Edit view..." command editview
-state disabled
-accelerator F4
}
2009 {mc
"Delete view" command delview
-state disabled
}
2011 {mc
"All files" radiobutton
{selectedview
0} -command {showview
0}}
2013 if {[tk windowingsystem
] ne
"aqua"} {
2016 {mc
"About gitk" command about
}
2017 {mc
"Key bindings" command keys
}
2019 set bar
[list
$file $edit $view $help]
2021 proc
::tk
::mac
::ShowPreferences
{} {doprefs
}
2022 proc
::tk
::mac
::Quit
{} {doquit
}
2023 lset
file end
[lreplace
[lindex
$file end
] end-1 end
]
2025 xx
"Apple" cascade
{
2026 {mc
"About gitk" command about
}
2031 {mc
"Key bindings" command keys
}
2033 set bar
[list
$apple $file $view $help]
2036 . configure
-menu .bar
2039 # cover the non-themed toplevel with a themed frame.
2040 place
[ttk
::frame ._main_background
] -x 0 -y 0 -relwidth 1 -relheight 1
2043 # the gui has upper and lower half, parts of a paned window.
2044 ${NS}::panedwindow .ctop
-orient vertical
2046 # possibly use assumed geometry
2047 if {![info exists geometry
(pwsash0
)]} {
2048 set geometry
(topheight
) [expr {15 * $linespc}]
2049 set geometry
(topwidth
) [expr {80 * $charspc}]
2050 set geometry
(botheight
) [expr {15 * $linespc}]
2051 set geometry
(botwidth
) [expr {50 * $charspc}]
2052 set geometry
(pwsash0
) [list
[expr {40 * $charspc}] 2]
2053 set geometry
(pwsash1
) [list
[expr {60 * $charspc}] 2]
2056 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2057 ${NS}::frame .tf
-height $geometry(topheight
) -width $geometry(topwidth
)
2058 ${NS}::frame .tf.histframe
2059 ${NS}::panedwindow .tf.histframe.pwclist
-orient horizontal
2061 .tf.histframe.pwclist configure
-sashpad 0 -handlesize 4
2064 # create three canvases
2065 set cscroll .tf.histframe.csb
2066 set canv .tf.histframe.pwclist.canv
2068 -selectbackground $selectbgcolor \
2069 -background $bgcolor -bd 0 \
2070 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2071 .tf.histframe.pwclist add
$canv
2072 set canv2 .tf.histframe.pwclist.canv2
2074 -selectbackground $selectbgcolor \
2075 -background $bgcolor -bd 0 -yscrollincr $linespc
2076 .tf.histframe.pwclist add
$canv2
2077 set canv3 .tf.histframe.pwclist.canv3
2079 -selectbackground $selectbgcolor \
2080 -background $bgcolor -bd 0 -yscrollincr $linespc
2081 .tf.histframe.pwclist add
$canv3
2083 bind .tf.histframe.pwclist
<Map
> {
2085 .tf.histframe.pwclist sashpos
1 [lindex $
::geometry
(pwsash1
) 0]
2086 .tf.histframe.pwclist sashpos
0 [lindex $
::geometry
(pwsash0
) 0]
2089 eval .tf.histframe.pwclist sash place
0 $geometry(pwsash0
)
2090 eval .tf.histframe.pwclist sash place
1 $geometry(pwsash1
)
2093 # a scroll bar to rule them
2094 ${NS}::scrollbar
$cscroll -command {allcanvs yview
}
2095 if {!$use_ttk} {$cscroll configure
-highlightthickness 0}
2096 pack
$cscroll -side right
-fill y
2097 bind .tf.histframe.pwclist
<Configure
> {resizeclistpanes
%W
%w
}
2098 lappend bglist
$canv $canv2 $canv3
2099 pack .tf.histframe.pwclist
-fill both
-expand 1 -side left
2101 # we have two button bars at bottom of top frame. Bar 1
2102 ${NS}::frame .tf.bar
2103 ${NS}::frame .tf.lbar
-height 15
2105 set sha1entry .tf.bar.sha1
2106 set entries
$sha1entry
2107 set sha1but .tf.bar.sha1label
2108 button
$sha1but -text "[mc "SHA1 ID
:"] " -state disabled
-relief flat \
2109 -command gotocommit
-width 8
2110 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
2111 pack .tf.bar.sha1label
-side left
2112 ${NS}::entry
$sha1entry -width 40 -font textfont
-textvariable sha1string
2113 trace add variable sha1string
write sha1change
2114 pack
$sha1entry -side left
-pady 2
2116 image create bitmap bm-left
-data {
2117 #define left_width 16
2118 #define left_height 16
2119 static unsigned char left_bits
[] = {
2120 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2121 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2122 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2124 image create bitmap bm-right
-data {
2125 #define right_width 16
2126 #define right_height 16
2127 static unsigned char right_bits
[] = {
2128 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2129 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2130 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2132 ${NS}::button .tf.bar.leftbut
-image bm-left
-command goback \
2133 -state disabled
-width 26
2134 pack .tf.bar.leftbut
-side left
-fill y
2135 ${NS}::button .tf.bar.rightbut
-image bm-right
-command goforw \
2136 -state disabled
-width 26
2137 pack .tf.bar.rightbut
-side left
-fill y
2139 ${NS}::label .tf.bar.rowlabel
-text [mc
"Row"]
2141 ${NS}::label .tf.bar.rownum
-width 7 -textvariable rownumsel \
2142 -relief sunken
-anchor e
2143 ${NS}::label .tf.bar.rowlabel2
-text "/"
2144 ${NS}::label .tf.bar.numcommits
-width 7 -textvariable numcommits \
2145 -relief sunken
-anchor e
2146 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2149 foreach w
{rownum numcommits
} {.tf.bar.
$w configure
-font textfont
}
2152 trace add variable selectedline
write selectedline_change
2154 # Status label and progress bar
2155 set statusw .tf.bar.status
2156 ${NS}::label
$statusw -width 15 -relief sunken
2157 pack
$statusw -side left
-padx 5
2159 set progresscanv
[ttk
::progressbar .tf.bar.progress
]
2161 set h
[expr {[font metrics uifont
-linespace] + 2}]
2162 set progresscanv .tf.bar.progress
2163 canvas
$progresscanv -relief sunken
-height $h -borderwidth 2
2164 set progressitem
[$progresscanv create rect
-1 0 0 $h -fill green
]
2165 set fprogitem
[$progresscanv create rect
-1 0 0 $h -fill yellow
]
2166 set rprogitem
[$progresscanv create rect
-1 0 0 $h -fill red
]
2168 pack
$progresscanv -side right
-expand 1 -fill x
-padx {0 2}
2169 set progresscoords
{0 0}
2172 bind $progresscanv <Configure
> adjustprogress
2173 set lastprogupdate
[clock clicks
-milliseconds]
2174 set progupdatepending
0
2176 # build up the bottom bar of upper window
2177 ${NS}::label .tf.lbar.flabel
-text "[mc "Find
"] "
2178 ${NS}::button .tf.lbar.fnext
-text [mc
"next"] -command {dofind
1 1}
2179 ${NS}::button .tf.lbar.fprev
-text [mc
"prev"] -command {dofind
-1 1}
2180 ${NS}::label .tf.lbar.flab2
-text " [mc "commit
"] "
2181 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2183 set gdttype
[mc
"containing:"]
2184 set gm
[makedroplist .tf.lbar.gdttype gdttype \
2185 [mc
"containing:"] \
2186 [mc
"touching paths:"] \
2187 [mc
"adding/removing string:"]]
2188 trace add variable gdttype
write gdttype_change
2189 pack .tf.lbar.gdttype
-side left
-fill y
2192 set fstring .tf.lbar.findstring
2193 lappend entries
$fstring
2194 ${NS}::entry
$fstring -width 30 -textvariable findstring
2195 trace add variable findstring
write find_change
2196 set findtype
[mc
"Exact"]
2197 set findtypemenu
[makedroplist .tf.lbar.findtype \
2198 findtype
[mc
"Exact"] [mc
"IgnCase"] [mc
"Regexp"]]
2199 trace add variable findtype
write findcom_change
2200 set findloc
[mc
"All fields"]
2201 makedroplist .tf.lbar.findloc findloc
[mc
"All fields"] [mc
"Headline"] \
2202 [mc
"Comments"] [mc
"Author"] [mc
"Committer"]
2203 trace add variable findloc
write find_change
2204 pack .tf.lbar.findloc
-side right
2205 pack .tf.lbar.findtype
-side right
2206 pack
$fstring -side left
-expand 1 -fill x
2208 # Finish putting the upper half of the viewer together
2209 pack .tf.lbar
-in .tf
-side bottom
-fill x
2210 pack .tf.bar
-in .tf
-side bottom
-fill x
2211 pack .tf.histframe
-fill both
-side top
-expand 1
2214 .ctop paneconfigure .tf
-height $geometry(topheight
)
2215 .ctop paneconfigure .tf
-width $geometry(topwidth
)
2218 # now build up the bottom
2219 ${NS}::panedwindow .pwbottom
-orient horizontal
2221 # lower left, a text box over search bar, scroll bar to the right
2222 # if we know window height, then that will set the lower text height, otherwise
2223 # we set lower text height which will drive window height
2224 if {[info exists geometry
(main
)]} {
2225 ${NS}::frame .bleft
-width $geometry(botwidth
)
2227 ${NS}::frame .bleft
-width $geometry(botwidth
) -height $geometry(botheight
)
2229 ${NS}::frame .bleft.top
2230 ${NS}::frame .bleft.mid
2231 ${NS}::frame .bleft.bottom
2233 ${NS}::button .bleft.top.search
-text [mc
"Search"] -command dosearch
2234 pack .bleft.top.search
-side left
-padx 5
2235 set sstring .bleft.top.sstring
2237 ${NS}::entry
$sstring -width 20 -textvariable searchstring
2238 lappend entries
$sstring
2239 trace add variable searchstring
write incrsearch
2240 pack
$sstring -side left
-expand 1 -fill x
2241 ${NS}::radiobutton .bleft.mid.
diff -text [mc
"Diff"] \
2242 -command changediffdisp
-variable diffelide
-value {0 0}
2243 ${NS}::radiobutton .bleft.mid.old
-text [mc
"Old version"] \
2244 -command changediffdisp
-variable diffelide
-value {0 1}
2245 ${NS}::radiobutton .bleft.mid.new
-text [mc
"New version"] \
2246 -command changediffdisp
-variable diffelide
-value {1 0}
2247 ${NS}::label .bleft.mid.labeldiffcontext
-text " [mc "Lines of context
"]: "
2248 pack .bleft.mid.
diff .bleft.mid.old .bleft.mid.new
-side left
2249 spinbox .bleft.mid.diffcontext
-width 5 \
2250 -from 0 -increment 1 -to 10000000 \
2251 -validate all
-validatecommand "diffcontextvalidate %P" \
2252 -textvariable diffcontextstring
2253 .bleft.mid.diffcontext
set $diffcontext
2254 trace add variable diffcontextstring
write diffcontextchange
2255 lappend entries .bleft.mid.diffcontext
2256 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext
-side left
2257 ${NS}::checkbutton .bleft.mid.ignspace
-text [mc
"Ignore space change"] \
2258 -command changeignorespace
-variable ignorespace
2259 pack .bleft.mid.ignspace
-side left
-padx 5
2261 set worddiff
[mc
"Line diff"]
2262 if {[package vcompare
$git_version "1.7.2"] >= 0} {
2263 makedroplist .bleft.mid.worddiff worddiff
[mc
"Line diff"] \
2264 [mc
"Markup words"] [mc
"Color words"]
2265 trace add variable worddiff
write changeworddiff
2266 pack .bleft.mid.worddiff
-side left
-padx 5
2269 set ctext .bleft.bottom.ctext
2270 text
$ctext -background $bgcolor -foreground $fgcolor \
2271 -state disabled
-font textfont \
2272 -yscrollcommand scrolltext
-wrap none \
2273 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2275 $ctext conf
-tabstyle wordprocessor
2277 ${NS}::scrollbar .bleft.bottom.sb
-command "$ctext yview"
2278 ${NS}::scrollbar .bleft.bottom.sbhorizontal
-command "$ctext xview" -orient h
2279 pack .bleft.top
-side top
-fill x
2280 pack .bleft.mid
-side top
-fill x
2281 grid
$ctext .bleft.bottom.sb
-sticky nsew
2282 grid .bleft.bottom.sbhorizontal
-sticky ew
2283 grid columnconfigure .bleft.bottom
0 -weight 1
2284 grid rowconfigure .bleft.bottom
0 -weight 1
2285 grid rowconfigure .bleft.bottom
1 -weight 0
2286 pack .bleft.bottom
-side top
-fill both
-expand 1
2287 lappend bglist
$ctext
2288 lappend fglist
$ctext
2290 $ctext tag conf comment
-wrap $wrapcomment
2291 $ctext tag conf filesep
-font textfontbold
-back "#aaaaaa"
2292 $ctext tag conf hunksep
-fore [lindex
$diffcolors 2]
2293 $ctext tag conf d0
-fore [lindex
$diffcolors 0]
2294 $ctext tag conf dresult
-fore [lindex
$diffcolors 1]
2295 $ctext tag conf m0
-fore red
2296 $ctext tag conf m1
-fore blue
2297 $ctext tag conf m2
-fore green
2298 $ctext tag conf m3
-fore purple
2299 $ctext tag conf
m4 -fore brown
2300 $ctext tag conf m5
-fore "#009090"
2301 $ctext tag conf m6
-fore magenta
2302 $ctext tag conf m7
-fore "#808000"
2303 $ctext tag conf m8
-fore "#009000"
2304 $ctext tag conf m9
-fore "#ff0080"
2305 $ctext tag conf m10
-fore cyan
2306 $ctext tag conf m11
-fore "#b07070"
2307 $ctext tag conf m12
-fore "#70b0f0"
2308 $ctext tag conf m13
-fore "#70f0b0"
2309 $ctext tag conf m14
-fore "#f0b070"
2310 $ctext tag conf m15
-fore "#ff70b0"
2311 $ctext tag conf mmax
-fore darkgrey
2313 $ctext tag conf mresult
-font textfontbold
2314 $ctext tag conf msep
-font textfontbold
2315 $ctext tag conf found
-back yellow
2317 .pwbottom add .bleft
2319 .pwbottom paneconfigure .bleft
-width $geometry(botwidth
)
2323 ${NS}::frame .bright
2324 ${NS}::frame .bright.mode
2325 ${NS}::radiobutton .bright.mode.
patch -text [mc
"Patch"] \
2326 -command reselectline
-variable cmitmode
-value "patch"
2327 ${NS}::radiobutton .bright.mode.tree
-text [mc
"Tree"] \
2328 -command reselectline
-variable cmitmode
-value "tree"
2329 grid .bright.mode.
patch .bright.mode.tree
-sticky ew
2330 pack .bright.mode
-side top
-fill x
2331 set cflist .bright.cfiles
2332 set indent
[font measure mainfont
"nn"]
2334 -selectbackground $selectbgcolor \
2335 -background $bgcolor -foreground $fgcolor \
2337 -tabs [list
$indent [expr {2 * $indent}]] \
2338 -yscrollcommand ".bright.sb set" \
2339 -cursor [. cget
-cursor] \
2340 -spacing1 1 -spacing3 1
2341 lappend bglist
$cflist
2342 lappend fglist
$cflist
2343 ${NS}::scrollbar .bright.sb
-command "$cflist yview"
2344 pack .bright.sb
-side right
-fill y
2345 pack
$cflist -side left
-fill both
-expand 1
2346 $cflist tag configure highlight \
2347 -background [$cflist cget
-selectbackground]
2348 $cflist tag configure bold
-font mainfontbold
2350 .pwbottom add .bright
2353 # restore window width & height if known
2354 if {[info exists geometry
(main
)]} {
2355 if {[scan
$geometry(main
) "%dx%d" w h
] >= 2} {
2356 if {$w > [winfo screenwidth .
]} {
2357 set w
[winfo screenwidth .
]
2359 if {$h > [winfo screenheight .
]} {
2360 set h
[winfo screenheight .
]
2362 wm geometry .
"${w}x$h"
2366 if {[info exists geometry
(state
)] && $geometry(state
) eq
"zoomed"} {
2367 wm state .
$geometry(state
)
2370 if {[tk windowingsystem
] eq
{aqua
}} {
2381 %W sashpos
0 $
::geometry
(topheight
)
2383 bind .pwbottom
<Map
> {
2385 %W sashpos
0 $
::geometry
(botwidth
)
2389 bind .pwbottom
<Configure
> {resizecdetpanes
%W
%w
}
2390 pack .ctop
-fill both
-expand 1
2391 bindall
<1> {selcanvline
%W
%x
%y
}
2392 #bindall <B1-Motion> {selcanvline %W %x %y}
2393 if {[tk windowingsystem
] == "win32"} {
2394 bind .
<MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
}
2395 bind $ctext <MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
; break }
2397 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
2398 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
2399 if {[tk windowingsystem
] eq
"aqua"} {
2400 bindall
<MouseWheel
> {
2401 set delta
[expr {- (%D
)}]
2402 allcanvs yview scroll
$delta units
2404 bindall
<Shift-MouseWheel
> {
2405 set delta
[expr {- (%D
)}]
2406 $canv xview scroll
$delta units
2410 bindall
<$
::BM
> "canvscan mark %W %x %y"
2411 bindall
<B$
::BM-Motion
> "canvscan dragto %W %x %y"
2412 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
2413 bind .
<$M1B-Key-w> doquit
2414 bindkey
<Home
> selfirstline
2415 bindkey
<End
> sellastline
2416 bind .
<Key-Up
> "selnextline -1"
2417 bind .
<Key-Down
> "selnextline 1"
2418 bind .
<Shift-Key-Up
> "dofind -1 0"
2419 bind .
<Shift-Key-Down
> "dofind 1 0"
2420 bindkey
<Key-Right
> "goforw"
2421 bindkey
<Key-Left
> "goback"
2422 bind .
<Key-Prior
> "selnextpage -1"
2423 bind .
<Key-Next
> "selnextpage 1"
2424 bind .
<$M1B-Home> "allcanvs yview moveto 0.0"
2425 bind .
<$M1B-End> "allcanvs yview moveto 1.0"
2426 bind .
<$M1B-Key-Up> "allcanvs yview scroll -1 units"
2427 bind .
<$M1B-Key-Down> "allcanvs yview scroll 1 units"
2428 bind .
<$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2429 bind .
<$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2430 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
2431 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
2432 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
2433 bindkey p
"selnextline -1"
2434 bindkey n
"selnextline 1"
2437 bindkey i
"selnextline -1"
2438 bindkey k
"selnextline 1"
2442 bindkey d
"$ctext yview scroll 18 units"
2443 bindkey u
"$ctext yview scroll -18 units"
2444 bindkey
/ {focus
$fstring}
2445 bindkey
<Key-KP_Divide
> {focus
$fstring}
2446 bindkey
<Key-Return
> {dofind
1 1}
2447 bindkey ?
{dofind
-1 1}
2449 bind .
<F5
> updatecommits
2450 bind .
<$M1B-F5> reloadcommits
2451 bind .
<F2
> showrefs
2452 bind .
<Shift-F4
> {newview
0}
2453 catch
{ bind .
<Shift-Key-XF86_Switch_VT_4
> {newview
0} }
2454 bind .
<F4
> edit_or_newview
2455 bind .
<$M1B-q> doquit
2456 bind .
<$M1B-f> {dofind
1 1}
2457 bind .
<$M1B-g> {dofind
1 0}
2458 bind .
<$M1B-r> dosearchback
2459 bind .
<$M1B-s> dosearch
2460 bind .
<$M1B-equal> {incrfont
1}
2461 bind .
<$M1B-plus> {incrfont
1}
2462 bind .
<$M1B-KP_Add> {incrfont
1}
2463 bind .
<$M1B-minus> {incrfont
-1}
2464 bind .
<$M1B-KP_Subtract> {incrfont
-1}
2465 wm protocol . WM_DELETE_WINDOW doquit
2466 bind .
<Destroy
> {stop_backends
}
2467 bind .
<Button-1
> "click %W"
2468 bind $fstring <Key-Return
> {dofind
1 1}
2469 bind $sha1entry <Key-Return
> {gotocommit
; break}
2470 bind $sha1entry <<PasteSelection>> clearsha1
2471 bind $cflist <1> {sel_flist %W %x %y; break}
2472 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2473 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2475 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2476 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2477 bind $ctext <Button-1> {focus %W}
2479 set maincursor [. cget -cursor]
2480 set textcursor [$ctext cget -cursor]
2481 set curtextcursor $textcursor
2483 set rowctxmenu .rowctxmenu
2484 makemenu $rowctxmenu {
2485 {mc "Diff this -> selected" command {diffvssel 0}}
2486 {mc "Diff selected -> this" command {diffvssel 1}}
2487 {mc "Make patch" command mkpatch}
2488 {mc "Create tag" command mktag}
2489 {mc "Write commit to file" command writecommit}
2490 {mc "Create new branch" command mkbranch}
2491 {mc "Cherry-pick this commit" command cherrypick}
2492 {mc "Reset HEAD branch to here" command resethead}
2493 {mc "Mark this commit" command markhere}
2494 {mc "Return to mark" command gotomark}
2495 {mc "Find descendant of this and mark" command find_common_desc}
2496 {mc "Compare with marked commit" command compare_commits}
2498 $rowctxmenu configure -tearoff 0
2500 set fakerowmenu .fakerowmenu
2501 makemenu $fakerowmenu {
2502 {mc "Diff this -> selected" command {diffvssel 0}}
2503 {mc "Diff selected -> this" command {diffvssel 1}}
2504 {mc "Make patch" command mkpatch}
2506 $fakerowmenu configure -tearoff 0
2508 set headctxmenu .headctxmenu
2509 makemenu $headctxmenu {
2510 {mc "Check out this branch" command cobranch}
2511 {mc "Remove this branch" command rmbranch}
2513 $headctxmenu configure -tearoff 0
2516 set flist_menu .flistctxmenu
2517 makemenu $flist_menu {
2518 {mc "Highlight this too" command {flist_hl 0}}
2519 {mc "Highlight this only" command {flist_hl 1}}
2520 {mc "External diff" command {external_diff}}
2521 {mc "Blame parent commit" command {external_blame 1}}
2523 $flist_menu configure -tearoff 0
2526 set diff_menu .diffctxmenu
2527 makemenu $diff_menu {
2528 {mc "Show origin of this line" command show_line_source}
2529 {mc "Run git gui blame on this line" command {external_blame_diff}}
2531 $diff_menu configure -tearoff 0
2534 # Windows sends all mouse wheel events to the current focused window, not
2535 # the one where the mouse hovers, so bind those events here and redirect
2536 # to the correct window
2537 proc windows_mousewheel_redirector {W X Y D} {
2538 global canv canv2 canv3
2539 set w [winfo containing -displayof $W $X $Y]
2541 set u [expr {$D < 0 ? 5 : -5}]
2542 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2543 allcanvs yview scroll $u units
2546 $w yview scroll $u units
2552 # Update row number label when selectedline changes
2553 proc selectedline_change {n1 n2 op} {
2554 global selectedline rownumsel
2556 if {$selectedline eq {}} {
2559 set rownumsel [expr {$selectedline + 1}]
2563 # mouse-2 makes all windows scan vertically, but only the one
2564 # the cursor is in scans horizontally
2565 proc canvscan {op w x y} {
2566 global canv canv2 canv3
2567 foreach c [list $canv $canv2 $canv3] {
2576 proc scrollcanv {cscroll f0 f1} {
2577 $cscroll set $f0 $f1
2582 # when we make a key binding for the toplevel, make sure
2583 # it doesn't get triggered when that key is pressed in the
2584 # find string entry widget.
2585 proc bindkey {ev script} {
2588 set escript [bind Entry $ev]
2589 if {$escript == {}} {
2590 set escript [bind Entry <Key>]
2592 foreach e $entries {
2593 bind $e $ev "$escript; break"
2597 # set the focus back to the toplevel for any click outside
2600 global ctext entries
2601 foreach e [concat $entries $ctext] {
2602 if {$w == $e} return
2607 # Adjust the progress bar for a change in requested extent or canvas size
2608 proc adjustprogress {} {
2609 global progresscanv progressitem progresscoords
2610 global fprogitem fprogcoord lastprogupdate progupdatepending
2611 global rprogitem rprogcoord use_ttk
2614 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2618 set w [expr {[winfo width $progresscanv] - 4}]
2619 set x0 [expr {$w * [lindex $progresscoords 0]}]
2620 set x1 [expr {$w * [lindex $progresscoords 1]}]
2621 set h [winfo height $progresscanv]
2622 $progresscanv coords $progressitem $x0 0 $x1 $h
2623 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2624 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2625 set now [clock clicks -milliseconds]
2626 if {$now >= $lastprogupdate + 100} {
2627 set progupdatepending 0
2629 } elseif {!$progupdatepending} {
2630 set progupdatepending 1
2631 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2635 proc doprogupdate {} {
2636 global lastprogupdate progupdatepending
2638 if {$progupdatepending} {
2639 set progupdatepending 0
2640 set lastprogupdate [clock clicks -milliseconds]
2645 proc savestuff {w} {
2646 global canv canv2 canv3 mainfont textfont uifont tabstop
2647 global stuffsaved findmergefiles maxgraphpct
2648 global maxwidth showneartags showlocalchanges
2649 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2650 global cmitmode wrapcomment datetimeformat limitdiffs
2651 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2652 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2653 global hideremotes want_ttk
2655 if {$stuffsaved} return
2656 if {![winfo viewable .]} return
2658 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2659 set f [open "~/.gitk-new" w]
2660 if {$::tcl_platform(platform) eq {windows}} {
2661 file attributes "~/.gitk-new" -hidden true
2663 puts $f [list set mainfont $mainfont]
2664 puts $f [list set textfont $textfont]
2665 puts $f [list set uifont $uifont]
2666 puts $f [list set tabstop $tabstop]
2667 puts $f [list set findmergefiles $findmergefiles]
2668 puts $f [list set maxgraphpct $maxgraphpct]
2669 puts $f [list set maxwidth $maxwidth]
2670 puts $f [list set cmitmode $cmitmode]
2671 puts $f [list set wrapcomment $wrapcomment]
2672 puts $f [list set autoselect $autoselect]
2673 puts $f [list set autosellen $autosellen]
2674 puts $f [list set showneartags $showneartags]
2675 puts $f [list set hideremotes $hideremotes]
2676 puts $f [list set showlocalchanges $showlocalchanges]
2677 puts $f [list set datetimeformat $datetimeformat]
2678 puts $f [list set limitdiffs $limitdiffs]
2679 puts $f [list set uicolor $uicolor]
2680 puts $f [list set want_ttk $want_ttk]
2681 puts $f [list set bgcolor $bgcolor]
2682 puts $f [list set fgcolor $fgcolor]
2683 puts $f [list set colors $colors]
2684 puts $f [list set diffcolors $diffcolors]
2685 puts $f [list set markbgcolor $markbgcolor]
2686 puts $f [list set diffcontext $diffcontext]
2687 puts $f [list set selectbgcolor $selectbgcolor]
2688 puts $f [list set extdifftool $extdifftool]
2689 puts $f [list set perfile_attrs $perfile_attrs]
2691 puts $f "set geometry(main) [wm geometry .]"
2692 puts $f "set geometry(state) [wm state .]"
2693 puts $f "set geometry(topwidth) [winfo width .tf]"
2694 puts $f "set geometry(topheight) [winfo height .tf]"
2696 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2697 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2699 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2700 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2702 puts $f "set geometry(botwidth) [winfo width .bleft]"
2703 puts $f "set geometry(botheight) [winfo height .bleft]"
2705 puts -nonewline $f "set permviews {"
2706 for {set v 0} {$v < $nextviewnum} {incr v} {
2707 if {$viewperm($v)} {
2708 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2713 file rename -force "~/.gitk-new" "~/.gitk"
2718 proc resizeclistpanes {win w} {
2719 global oldwidth use_ttk
2720 if {[info exists oldwidth($win)]} {
2722 set s0 [$win sashpos 0]
2723 set s1 [$win sashpos 1]
2725 set s0 [$win sash coord 0]
2726 set s1 [$win sash coord 1]
2729 set sash0 [expr {int($w/2 - 2)}]
2730 set sash1 [expr {int($w*5/6 - 2)}]
2732 set factor [expr {1.0 * $w / $oldwidth($win)}]
2733 set sash0 [expr {int($factor * [lindex $s0 0])}]
2734 set sash1 [expr {int($factor * [lindex $s1 0])}]
2738 if {$sash1 < $sash0 + 20} {
2739 set sash1 [expr {$sash0 + 20}]
2741 if {$sash1 > $w - 10} {
2742 set sash1 [expr {$w - 10}]
2743 if {$sash0 > $sash1 - 20} {
2744 set sash0 [expr {$sash1 - 20}]
2749 $win sashpos 0 $sash0
2750 $win sashpos 1 $sash1
2752 $win sash place 0 $sash0 [lindex $s0 1]
2753 $win sash place 1 $sash1 [lindex $s1 1]
2756 set oldwidth($win) $w
2759 proc resizecdetpanes {win w} {
2760 global oldwidth use_ttk
2761 if {[info exists oldwidth($win)]} {
2763 set s0 [$win sashpos 0]
2765 set s0 [$win sash coord 0]
2768 set sash0 [expr {int($w*3/4 - 2)}]
2770 set factor [expr {1.0 * $w / $oldwidth($win)}]
2771 set sash0 [expr {int($factor * [lindex $s0 0])}]
2775 if {$sash0 > $w - 15} {
2776 set sash0 [expr {$w - 15}]
2780 $win sashpos 0 $sash0
2782 $win sash place 0 $sash0 [lindex $s0 1]
2785 set oldwidth($win) $w
2788 proc allcanvs args {
2789 global canv canv2 canv3
2795 proc bindall {event action} {
2796 global canv canv2 canv3
2797 bind $canv $event $action
2798 bind $canv2 $event $action
2799 bind $canv3 $event $action
2805 if {[winfo exists $w]} {
2810 wm title $w [mc "About gitk"]
2812 message $w.m -text [mc "
2813 Gitk - a commit viewer for git
2815 Copyright \u00a9 2005-2010 Paul Mackerras
2817 Use and redistribute under the terms of the GNU General Public License"] \
2818 -justify center -aspect 400 -border 2 -bg white -relief groove
2819 pack $w.m -side top -fill x -padx 2 -pady 2
2820 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2821 pack $w.ok -side bottom
2822 bind $w <Visibility> "focus $w.ok"
2823 bind $w <Key-Escape> "destroy $w"
2824 bind $w <Key-Return> "destroy $w"
2825 tk::PlaceWindow $w widget .
2831 if {[winfo exists $w]} {
2835 if {[tk windowingsystem] eq {aqua}} {
2841 wm title $w [mc "Gitk key bindings"]
2843 message $w.m -text "
2844 [mc "Gitk key bindings:"]
2846 [mc "<%s-Q> Quit" $M1T]
2847 [mc "<%s-W> Close window" $M1T]
2848 [mc "<Home> Move to first commit"]
2849 [mc "<End> Move to last commit"]
2850 [mc "<Up>, p, i Move up one commit"]
2851 [mc "<Down>, n, k Move down one commit"]
2852 [mc "<Left>, z, j Go back in history list"]
2853 [mc "<Right>, x, l Go forward in history list"]
2854 [mc "<PageUp> Move up one page in commit list"]
2855 [mc "<PageDown> Move down one page in commit list"]
2856 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2857 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2858 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2859 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2860 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2861 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2862 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2863 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2864 [mc "<Delete>, b Scroll diff view up one page"]
2865 [mc "<Backspace> Scroll diff view up one page"]
2866 [mc "<Space> Scroll diff view down one page"]
2867 [mc "u Scroll diff view up 18 lines"]
2868 [mc "d Scroll diff view down 18 lines"]
2869 [mc "<%s-F> Find" $M1T]
2870 [mc "<%s-G> Move to next find hit" $M1T]
2871 [mc "<Return> Move to next find hit"]
2872 [mc "/ Focus the search box"]
2873 [mc "? Move to previous find hit"]
2874 [mc "f Scroll diff view to next file"]
2875 [mc "<%s-S> Search for next hit in diff view" $M1T]
2876 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2877 [mc "<%s-KP+> Increase font size" $M1T]
2878 [mc "<%s-plus> Increase font size" $M1T]
2879 [mc "<%s-KP-> Decrease font size" $M1T]
2880 [mc "<%s-minus> Decrease font size" $M1T]
2883 -justify left -bg white -border 2 -relief groove
2884 pack $w.m -side top -fill both -padx 2 -pady 2
2885 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2886 bind $w <Key-Escape> [list destroy $w]
2887 pack $w.ok -side bottom
2888 bind $w <Visibility> "focus $w.ok"
2889 bind $w <Key-Escape> "destroy $w"
2890 bind $w <Key-Return> "destroy $w"
2893 # Procedures for manipulating the file list window at the
2894 # bottom right of the overall window.
2896 proc treeview {w l openlevs} {
2897 global treecontents treediropen treeheight treeparent treeindex
2907 set treecontents() {}
2908 $w conf -state normal
2910 while {[string range $f 0 $prefixend] ne $prefix} {
2911 if {$lev <= $openlevs} {
2912 $w mark set e:$treeindex($prefix) "end -1c"
2913 $w mark gravity e:$treeindex($prefix) left
2915 set treeheight($prefix) $ht
2916 incr ht [lindex $htstack end]
2917 set htstack [lreplace $htstack end end]
2918 set prefixend [lindex $prefendstack end]
2919 set prefendstack [lreplace $prefendstack end end]
2920 set prefix [string range $prefix 0 $prefixend]
2923 set tail [string range $f [expr {$prefixend+1}] end]
2924 while {[set slash [string first "/" $tail]] >= 0} {
2927 lappend prefendstack $prefixend
2928 incr prefixend [expr {$slash + 1}]
2929 set d [string range $tail 0 $slash]
2930 lappend treecontents($prefix) $d
2931 set oldprefix $prefix
2933 set treecontents($prefix) {}
2934 set treeindex($prefix) [incr ix]
2935 set treeparent($prefix) $oldprefix
2936 set tail [string range $tail [expr {$slash+1}] end]
2937 if {$lev <= $openlevs} {
2939 set treediropen($prefix) [expr {$lev < $openlevs}]
2940 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
2941 $w mark set d:$ix "end -1c"
2942 $w mark gravity d:$ix left
2944 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2946 $w image create end -align center -image $bm -padx 1 \
2948 $w insert end $d [highlight_tag $prefix]
2949 $w mark set s:$ix "end -1c"
2950 $w mark gravity s:$ix left
2955 if {$lev <= $openlevs} {
2958 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2960 $w insert end $tail [highlight_tag $f]
2962 lappend treecontents($prefix) $tail
2965 while {$htstack ne {}} {
2966 set treeheight($prefix) $ht
2967 incr ht [lindex $htstack end]
2968 set htstack [lreplace $htstack end end]
2969 set prefixend [lindex $prefendstack end]
2970 set prefendstack [lreplace $prefendstack end end]
2971 set prefix [string range $prefix 0 $prefixend]
2973 $w conf -state disabled
2976 proc linetoelt {l} {
2977 global treeheight treecontents
2982 foreach e $treecontents($prefix) {
2987 if {[string index $e end] eq "/"} {
2988 set n $treeheight($prefix$e)
3000 proc highlight_tree {y prefix} {
3001 global treeheight treecontents cflist
3003 foreach e $treecontents($prefix) {
3005 if {[highlight_tag $path] ne {}} {
3006 $cflist tag add bold $y.0 "$y.0 lineend"
3009 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3010 set y [highlight_tree $y $path]
3016 proc treeclosedir {w dir} {
3017 global treediropen treeheight treeparent treeindex
3019 set ix $treeindex($dir)
3020 $w conf -state normal
3021 $w delete s:$ix e:$ix
3022 set treediropen($dir) 0
3023 $w image configure a:$ix -image tri-rt
3024 $w conf -state disabled
3025 set n [expr {1 - $treeheight($dir)}]
3026 while {$dir ne {}} {
3027 incr treeheight($dir) $n
3028 set dir $treeparent($dir)
3032 proc treeopendir {w dir} {
3033 global treediropen treeheight treeparent treecontents treeindex
3035 set ix $treeindex($dir)
3036 $w conf -state normal
3037 $w image configure a:$ix -image tri-dn
3038 $w mark set e:$ix s:$ix
3039 $w mark gravity e:$ix right
3042 set n [llength $treecontents($dir)]
3043 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3046 incr treeheight($x) $n
3048 foreach e $treecontents($dir) {
3050 if {[string index $e end] eq "/"} {
3051 set iy $treeindex($de)
3052 $w mark set d:$iy e:$ix
3053 $w mark gravity d:$iy left
3054 $w insert e:$ix $str
3055 set treediropen($de) 0
3056 $w image create e:$ix -align center -image tri-rt -padx 1 \
3058 $w insert e:$ix $e [highlight_tag $de]
3059 $w mark set s:$iy e:$ix
3060 $w mark gravity s:$iy left
3061 set treeheight($de) 1
3063 $w insert e:$ix $str
3064 $w insert e:$ix $e [highlight_tag $de]
3067 $w mark gravity e:$ix right
3068 $w conf -state disabled
3069 set treediropen($dir) 1
3070 set top [lindex [split [$w index @0,0] .] 0]
3071 set ht [$w cget -height]
3072 set l [lindex [split [$w index s:$ix] .] 0]
3075 } elseif {$l + $n + 1 > $top + $ht} {
3076 set top [expr {$l + $n + 2 - $ht}]
3084 proc treeclick {w x y} {
3085 global treediropen cmitmode ctext cflist cflist_top
3087 if {$cmitmode ne "tree"} return
3088 if {![info exists cflist_top]} return
3089 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3090 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3091 $cflist tag add highlight $l.0 "$l.0 lineend"
3097 set e [linetoelt $l]
3098 if {[string index $e end] ne "/"} {
3100 } elseif {$treediropen($e)} {
3107 proc setfilelist {id} {
3108 global treefilelist cflist jump_to_here
3110 treeview $cflist $treefilelist($id) 0
3111 if {$jump_to_here ne {}} {
3112 set f [lindex $jump_to_here 0]
3113 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3119 image create bitmap tri-rt -background black -foreground blue -data {
3120 #define tri-rt_width 13
3121 #define tri-rt_height 13
3122 static unsigned char tri-rt_bits[] = {
3123 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3124 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3127 #define tri-rt-mask_width 13
3128 #define tri-rt-mask_height 13
3129 static unsigned char tri-rt-mask_bits[] = {
3130 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3131 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3134 image create bitmap tri-dn -background black -foreground blue -data {
3135 #define tri-dn_width 13
3136 #define tri-dn_height 13
3137 static unsigned char tri-dn_bits[] = {
3138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3139 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3142 #define tri-dn-mask_width 13
3143 #define tri-dn-mask_height 13
3144 static unsigned char tri-dn-mask_bits[] = {
3145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3146 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3150 image create bitmap reficon-T -background black -foreground yellow -data {
3151 #define tagicon_width 13
3152 #define tagicon_height 9
3153 static unsigned char tagicon_bits[] = {
3154 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3155 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3157 #define tagicon-mask_width 13
3158 #define tagicon-mask_height 9
3159 static unsigned char tagicon-mask_bits[] = {
3160 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3161 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3164 #define headicon_width 13
3165 #define headicon_height 9
3166 static unsigned char headicon_bits[] = {
3167 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3168 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3171 #define headicon-mask_width 13
3172 #define headicon-mask_height 9
3173 static unsigned char headicon-mask_bits[] = {
3174 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3175 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3177 image create bitmap reficon-H -background black -foreground green \
3178 -data $rectdata -maskdata $rectmask
3179 image create bitmap reficon-o -background black -foreground "#ddddff" \
3180 -data $rectdata -maskdata $rectmask
3182 proc init_flist {first} {
3183 global cflist cflist_top difffilestart
3185 $cflist conf -state normal
3186 $cflist delete 0.0 end
3188 $cflist insert end $first
3190 $cflist tag add highlight 1.0 "1.0 lineend"
3192 catch {unset cflist_top}
3194 $cflist conf -state disabled
3195 set difffilestart {}
3198 proc highlight_tag {f} {
3199 global highlight_paths
3201 foreach p $highlight_paths {
3202 if {[string match $p $f]} {
3209 proc highlight_filelist {} {
3210 global cmitmode cflist
3212 $cflist conf -state normal
3213 if {$cmitmode ne "tree"} {
3214 set end [lindex [split [$cflist index end] .] 0]
3215 for {set l 2} {$l < $end} {incr l} {
3216 set line [$cflist get $l.0 "$l.0 lineend"]
3217 if {[highlight_tag $line] ne {}} {
3218 $cflist tag add bold $l.0 "$l.0 lineend"
3224 $cflist conf -state disabled
3227 proc unhighlight_filelist {} {
3230 $cflist conf -state normal
3231 $cflist tag remove bold 1.0 end
3232 $cflist conf -state disabled
3235 proc add_flist {fl} {
3238 $cflist conf -state normal
3240 $cflist insert end "\n"
3241 $cflist insert end $f [highlight_tag $f]
3243 $cflist conf -state disabled
3246 proc sel_flist {w x y} {
3247 global ctext difffilestart cflist cflist_top cmitmode
3249 if {$cmitmode eq "tree"} return
3250 if {![info exists cflist_top]} return
3251 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3252 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3253 $cflist tag add highlight $l.0 "$l.0 lineend"
3258 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3262 proc pop_flist_menu {w X Y x y} {
3263 global ctext cflist cmitmode flist_menu flist_menu_file
3264 global treediffs diffids
3267 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3269 if {$cmitmode eq "tree"} {
3270 set e [linetoelt $l]
3271 if {[string index $e end] eq "/"} return
3273 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3275 set flist_menu_file $e
3276 set xdiffstate "normal"
3277 if {$cmitmode eq "tree"} {
3278 set xdiffstate "disabled"
3280 # Disable "External diff" item in tree mode
3281 $flist_menu entryconf 2 -state $xdiffstate
3282 tk_popup $flist_menu $X $Y
3285 proc find_ctext_fileinfo {line} {
3286 global ctext_file_names ctext_file_lines
3288 set ok [bsearch $ctext_file_lines $line]
3289 set tline [lindex $ctext_file_lines $ok]
3291 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3294 return [list [lindex $ctext_file_names $ok] $tline]
3298 proc pop_diff_menu {w X Y x y} {
3299 global ctext diff_menu flist_menu_file
3300 global diff_menu_txtpos diff_menu_line
3301 global diff_menu_filebase
3303 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3304 set diff_menu_line [lindex $diff_menu_txtpos 0]
3305 # don't pop up the menu on hunk-separator or file-separator lines
3306 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3310 set f [find_ctext_fileinfo $diff_menu_line]
3311 if {$f eq {}} return
3312 set flist_menu_file [lindex $f 0]
3313 set diff_menu_filebase [lindex $f 1]
3314 tk_popup $diff_menu $X $Y
3317 proc flist_hl {only} {
3318 global flist_menu_file findstring gdttype
3320 set x [shellquote $flist_menu_file]
3321 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3324 append findstring " " $x
3326 set gdttype [mc "touching paths:"]
3329 proc gitknewtmpdir {} {
3330 global diffnum gitktmpdir gitdir
3332 if {![info exists gitktmpdir]} {
3333 set gitktmpdir [file join [file dirname $gitdir] \
3334 [format ".gitk-tmp.%s" [pid]]]
3335 if {[catch {file mkdir $gitktmpdir} err]} {
3336 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3343 set diffdir [file join $gitktmpdir $diffnum]
3344 if {[catch {file mkdir $diffdir} err]} {
3345 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3351 proc save_file_from_commit {filename output what} {
3354 if {[catch {exec git show $filename -- > $output} err]} {
3355 if {[string match "fatal: bad revision *" $err]} {
3358 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3364 proc external_diff_get_one_file {diffid filename diffdir} {
3365 global nullid nullid2 nullfile
3368 if {$diffid == $nullid} {
3369 set difffile [file join [file dirname $gitdir] $filename]
3370 if {[file exists $difffile]} {
3375 if {$diffid == $nullid2} {
3376 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3377 return [save_file_from_commit :$filename $difffile index]
3379 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3380 return [save_file_from_commit $diffid:$filename $difffile \
3384 proc external_diff {} {
3385 global nullid nullid2
3386 global flist_menu_file
3390 if {[llength $diffids] == 1} {
3391 # no reference commit given
3392 set diffidto [lindex $diffids 0]
3393 if {$diffidto eq $nullid} {
3394 # diffing working copy with index
3395 set diffidfrom $nullid2
3396 } elseif {$diffidto eq $nullid2} {
3397 # diffing index with HEAD
3398 set diffidfrom "HEAD"
3400 # use first parent commit
3401 global parentlist selectedline
3402 set diffidfrom [lindex $parentlist $selectedline 0]
3405 set diffidfrom [lindex $diffids 0]
3406 set diffidto [lindex $diffids 1]
3409 # make sure that several diffs wont collide
3410 set diffdir [gitknewtmpdir]
3411 if {$diffdir eq {}} return
3413 # gather files to diff
3414 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3415 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3417 if {$difffromfile ne {} && $difftofile ne {}} {
3418 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3419 if {[catch {set fl [open |$cmd r]} err]} {
3420 file delete -force $diffdir
3421 error_popup "$extdifftool: [mc "command failed:"] $err"
3423 fconfigure $fl -blocking 0
3424 filerun $fl [list delete_at_eof $fl $diffdir]
3429 proc find_hunk_blamespec {base line} {
3432 # Find and parse the hunk header
3433 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3434 if {$s_lix eq {}} return
3436 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3437 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3438 s_line old_specs osz osz1 new_line nsz]} {
3442 # base lines for the parents
3443 set base_lines [list $new_line]
3444 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3445 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3446 old_spec old_line osz]} {
3449 lappend base_lines $old_line
3452 # Now scan the lines to determine offset within the hunk
3453 set max_parent [expr {[llength $base_lines]-2}]
3455 set s_lno [lindex [split $s_lix "."] 0]
3457 # Determine if the line is removed
3458 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3459 if {[string match {[-+ ]*} $chunk]} {
3460 set removed_idx [string first "-" $chunk]
3461 # Choose a parent index
3462 if {$removed_idx >= 0} {
3463 set parent $removed_idx
3465 set unchanged_idx [string first " " $chunk]
3466 if {$unchanged_idx >= 0} {
3467 set parent $unchanged_idx
3469 # blame the current commit
3473 # then count other lines that belong to it
3474 for {set i $line} {[incr i -1] > $s_lno} {} {
3475 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3476 # Determine if the line is removed
3477 set removed_idx [string first "-" $chunk]
3479 set code [string index $chunk $parent]
3480 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3484 if {$removed_idx < 0} {
3494 incr dline [lindex $base_lines $parent]
3495 return [list $parent $dline]
3498 proc external_blame_diff {} {
3499 global currentid cmitmode
3500 global diff_menu_txtpos diff_menu_line
3501 global diff_menu_filebase flist_menu_file
3503 if {$cmitmode eq "tree"} {
3505 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3507 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3509 set parent_idx [lindex $hinfo 0]
3510 set line [lindex $hinfo 1]
3517 external_blame $parent_idx $line
3520 # Find the SHA1 ID of the blob for file $fname in the index
3522 proc index_sha1 {fname} {
3523 set f [open [list | git ls-files -s $fname] r]
3524 while {[gets $f line] >= 0} {
3525 set info [lindex [split $line "\t"] 0]
3526 set stage [lindex $info 2]
3527 if {$stage eq "0" || $stage eq "2"} {
3529 return [lindex $info 1]
3536 # Turn an absolute path into one relative to the current directory
3537 proc make_relative {f} {
3538 if {[file pathtype $f] eq "relative"} {
3541 set elts [file split $f]
3542 set here [file split [pwd]]
3547 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3554 set elts [concat $res [lrange $elts $ei end]]
3555 return [eval file join $elts]
3558 proc external_blame {parent_idx {line {}}} {
3559 global flist_menu_file gitdir
3560 global nullid nullid2
3561 global parentlist selectedline currentid
3563 if {$parent_idx > 0} {
3564 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3566 set base_commit $currentid
3569 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3570 error_popup [mc "No such commit"]
3574 set cmdline [list git gui blame]
3575 if {$line ne {} && $line > 1} {
3576 lappend cmdline "--line=$line"
3578 set f [file join [file dirname $gitdir] $flist_menu_file]
3579 # Unfortunately it seems git gui blame doesn't like
3580 # being given an absolute path...
3581 set f [make_relative $f]
3582 lappend cmdline $base_commit $f
3583 if {[catch {eval exec $cmdline &} err]} {
3584 error_popup "[mc "git gui blame: command failed:"] $err"
3588 proc show_line_source {} {
3589 global cmitmode currentid parents curview blamestuff blameinst
3590 global diff_menu_line diff_menu_filebase flist_menu_file
3591 global nullid nullid2 gitdir
3594 if {$cmitmode eq "tree"} {
3596 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3598 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3599 if {$h eq {}} return
3600 set pi [lindex $h 0]
3602 mark_ctext_line $diff_menu_line
3606 if {$currentid eq $nullid} {
3608 # must be a merge in progress...
3610 # get the last line from .git/MERGE_HEAD
3611 set f [open [file join $gitdir MERGE_HEAD] r]
3612 set id [lindex [split [read $f] "\n"] end-1]
3615 error_popup [mc "Couldn't read merge head: %s" $err]
3618 } elseif {$parents($curview,$currentid) eq $nullid2} {
3619 # need to do the blame from the index
3621 set from_index [index_sha1 $flist_menu_file]
3623 error_popup [mc "Error reading index: %s" $err]
3627 set id $parents($curview,$currentid)
3630 set id [lindex $parents($curview,$currentid) $pi]
3632 set line [lindex $h 1]
3635 if {$from_index ne {}} {
3636 lappend blameargs | git cat-file blob $from_index
3638 lappend blameargs | git blame -p -L$line,+1
3639 if {$from_index ne {}} {
3640 lappend blameargs --contents -
3642 lappend blameargs $id
3644 lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file]
3646 set f [open $blameargs r]
3648 error_popup [mc "Couldn't start git blame: %s" $err]
3651 nowbusy blaming [mc "Searching"]
3652 fconfigure $f -blocking 0
3653 set i [reg_instance $f]
3654 set blamestuff($i) {}
3656 filerun $f [list read_line_source $f $i]
3659 proc stopblaming {} {
3662 if {[info exists blameinst]} {
3663 stop_instance $blameinst
3669 proc read_line_source {fd inst} {
3670 global blamestuff curview commfd blameinst nullid nullid2
3672 while {[gets $fd line] >= 0} {
3673 lappend blamestuff($inst) $line
3681 fconfigure $fd -blocking 1
3682 if {[catch {close $fd} err]} {
3683 error_popup [mc "Error running git blame: %s" $err]
3688 set line [split [lindex $blamestuff($inst) 0] " "]
3689 set id [lindex $line 0]
3690 set lnum [lindex $line 1]
3691 if {[string length $id] == 40 && [string is xdigit $id] &&
3692 [string is digit -strict $lnum]} {
3693 # look for "filename" line
3694 foreach l $blamestuff($inst) {
3695 if {[string match "filename *" $l]} {
3696 set fname [string range $l 9 end]
3702 # all looks good, select it
3703 if {$id eq $nullid} {
3704 # blame uses all-zeroes to mean not committed,
3705 # which would mean a change in the index
3708 if {[commitinview $id $curview]} {
3709 selectline [rowofcommit $id] 1 [list $fname $lnum]
3711 error_popup [mc "That line comes from commit %s, \
3712 which is not in this view" [shortids $id]]
3715 puts "oops couldn't parse git blame output"
3720 # delete $dir when we see eof on $f (presumably because the child has exited)
3721 proc delete_at_eof {f dir} {
3722 while {[gets $f line] >= 0} {}
3724 if {[catch {close $f} err]} {
3725 error_popup "[mc "External diff viewer failed:"] $err"
3727 file delete -force $dir
3733 # Functions for adding and removing shell-type quoting
3735 proc shellquote {str} {
3736 if {![string match "*\['\"\\ \t]*" $str]} {
3739 if {![string match "*\['\"\\]*" $str]} {
3742 if {![string match "*'*" $str]} {
3745 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3748 proc shellarglist {l} {
3754 append str [shellquote $a]
3759 proc shelldequote {str} {
3764 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3765 append ret [string range $str $used end]
3766 set used [string length $str]
3769 set first [lindex $first 0]
3770 set ch [string index $str $first]
3771 if {$first > $used} {
3772 append ret [string range $str $used [expr {$first - 1}]]
3775 if {$ch eq " " || $ch eq "\t"} break
3778 set first [string first "'" $str $used]
3780 error "unmatched single-quote"
3782 append ret [string range $str $used [expr {$first - 1}]]
3787 if {$used >= [string length $str]} {
3788 error "trailing backslash"
3790 append ret [string index $str $used]
3795 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3796 error "unmatched double-quote"
3798 set first [lindex $first 0]
3799 set ch [string index $str $first]
3800 if {$first > $used} {
3801 append ret [string range $str $used [expr {$first - 1}]]
3804 if {$ch eq "\""} break
3806 append ret [string index $str $used]
3810 return [list $used $ret]
3813 proc shellsplit {str} {
3816 set str [string trimleft $str]
3817 if {$str eq {}} break
3818 set dq [shelldequote $str]
3819 set n [lindex $dq 0]
3820 set word [lindex $dq 1]
3821 set str [string range $str $n end]
3827 # Code to implement multiple views
3829 proc newview {ishighlight} {
3830 global nextviewnum newviewname newishighlight
3831 global revtreeargs viewargscmd newviewopts curview
3833 set newishighlight $ishighlight
3835 if {[winfo exists $top]} {
3839 decode_view_opts $nextviewnum $revtreeargs
3840 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3841 set newviewopts($nextviewnum,perm) 0
3842 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3843 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3846 set known_view_options {
3847 {perm b . {} {mc "Remember this view"}}
3848 {reflabel l + {} {mc "References (space separated list):"}}
3849 {refs t15 .. {} {mc "Branches & tags:"}}
3850 {allrefs b *. "--all" {mc "All refs"}}
3851 {branches b . "--branches" {mc "All (local) branches"}}
3852 {tags b . "--tags" {mc "All tags"}}
3853 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3854 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3855 {author t15 .. "--author=*" {mc "Author:"}}
3856 {committer t15 . "--committer=*" {mc "Committer:"}}
3857 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3858 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3859 {changes_l l + {} {mc "Changes to Files:"}}
3860 {pickaxe_s r0 . {} {mc "Fixed String"}}
3861 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3862 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3863 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3864 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3865 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3866 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3867 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3868 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3869 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3870 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3871 {lright b . "--left-right" {mc "Mark branch sides"}}
3872 {first b . "--first-parent" {mc "Limit to first parent"}}
3873 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3874 {args t50 *. {} {mc "Additional arguments to git log:"}}
3875 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3876 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3879 # Convert $newviewopts($n, ...) into args for git log.
3880 proc encode_view_opts {n} {
3881 global known_view_options newviewopts
3884 foreach opt $known_view_options {
3885 set patterns [lindex $opt 3]
3886 if {$patterns eq {}} continue
3887 set pattern [lindex $patterns 0]
3889 if {[lindex $opt 1] eq "b"} {
3890 set val $newviewopts($n,[lindex $opt 0])
3892 lappend rargs $pattern
3894 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
3895 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
3896 set val $newviewopts($n,$button_id)
3897 if {$val eq $value} {
3898 lappend rargs $pattern
3901 set val $newviewopts($n,[lindex $opt 0])
3902 set val [string trim $val]
3904 set pfix [string range $pattern 0 end-1]
3905 lappend rargs $pfix$val
3909 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
3910 return [concat $rargs [shellsplit $newviewopts($n,args)]]
3913 # Fill $newviewopts($n, ...) based on args for git log.
3914 proc decode_view_opts {n view_args} {
3915 global known_view_options newviewopts
3917 foreach opt $known_view_options {
3918 set id [lindex $opt 0]
3919 if {[lindex $opt 1] eq "b"} {
3922 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
3924 regexp {^(.*_)} $id uselessvar id
3930 set newviewopts($n,$id) $val
3934 foreach arg $view_args {
3935 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
3936 && ![info exists found(limit)]} {
3937 set newviewopts($n,limit) $cnt
3942 foreach opt $known_view_options {
3943 set id [lindex $opt 0]
3944 if {[info exists found($id)]} continue
3945 foreach pattern [lindex $opt 3] {
3946 if {![string match $pattern $arg]} continue
3947 if {[lindex $opt 1] eq "b"} {
3950 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
3952 regexp {^(.*_)} $id uselessvar id
3956 set size [string length $pattern]
3957 set val [string range $arg [expr {$size-1}] end]
3959 set newviewopts($n,$id) $val
3963 if {[info exists val]} break
3965 if {[info exists val]} continue
3966 if {[regexp {^-} $arg]} {
3969 lappend refargs $arg
3972 set newviewopts($n,refs) [shellarglist $refargs]
3973 set newviewopts($n,args) [shellarglist $oargs]
3976 proc edit_or_newview {} {
3988 global viewname viewperm newviewname newviewopts
3989 global viewargs viewargscmd
3991 set top .gitkvedit-$curview
3992 if {[winfo exists $top]} {
3996 decode_view_opts $curview $viewargs($curview)
3997 set newviewname($curview) $viewname($curview)
3998 set newviewopts($curview,perm) $viewperm($curview)
3999 set newviewopts($curview,cmd) $viewargscmd($curview)
4000 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4003 proc vieweditor {top n title} {
4004 global newviewname newviewopts viewfiles bgcolor
4005 global known_view_options NS
4008 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4009 make_transient $top .
4012 ${NS}::frame $top.nfr
4013 ${NS}::label $top.nl -text [mc "View Name"]
4014 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4015 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4016 pack $top.nl -in $top.nfr -side left -padx {0 5}
4017 pack $top.name -in $top.nfr -side left -padx {0 25}
4023 foreach opt $known_view_options {
4024 set id [lindex $opt 0]
4025 set type [lindex $opt 1]
4026 set flags [lindex $opt 2]
4027 set title [eval [lindex $opt 4]]
4030 if {$flags eq "+" || $flags eq "*"} {
4031 set cframe $top.fr$cnt
4033 ${NS}::frame $cframe
4034 pack $cframe -in $top -fill x -pady 3 -padx 3
4035 set cexpand [expr {$flags eq "*"}]
4036 } elseif {$flags eq ".." || $flags eq "*."} {
4037 set cframe $top.fr$cnt
4039 ${NS}::frame $cframe
4040 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4041 set cexpand [expr {$flags eq "*."}]
4047 ${NS}::label $cframe.l_$id -text $title
4048 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4049 } elseif {$type eq "b"} {
4050 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4051 pack $cframe.c_$id -in $cframe -side left \
4052 -padx [list $lxpad 0] -expand $cexpand -anchor w
4053 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4054 regexp {^(.*_)} $id uselessvar button_id
4055 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4056 pack $cframe.c_$id -in $cframe -side left \
4057 -padx [list $lxpad 0] -expand $cexpand -anchor w
4058 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4059 ${NS}::label $cframe.l_$id -text $title
4060 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4061 -textvariable newviewopts($n,$id)
4062 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4063 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4064 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4065 ${NS}::label $cframe.l_$id -text $title
4066 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4067 -textvariable newviewopts($n,$id)
4068 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4069 pack $cframe.e_$id -in $cframe -side top -fill x
4070 } elseif {$type eq "path"} {
4071 ${NS}::label $top.l -text $title
4072 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4073 text $top.t -width 40 -height 5 -background $bgcolor
4074 if {[info exists viewfiles($n)]} {
4075 foreach f $viewfiles($n) {
4076 $top.t insert end $f
4077 $top.t insert end "\n"
4079 $top.t delete {end - 1c} end
4080 $top.t mark set insert 0.0
4082 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4086 ${NS}::frame $top.buts
4087 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4088 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4089 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4090 bind $top <Control-Return> [list newviewok $top $n]
4091 bind $top <F5> [list newviewok $top $n 1]
4092 bind $top <Escape> [list destroy $top]
4093 grid $top.buts.ok $top.buts.apply $top.buts.can
4094 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4095 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4096 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4097 pack $top.buts -in $top -side top -fill x
4101 proc doviewmenu {m first cmd op argv} {
4102 set nmenu [$m index end]
4103 for {set i $first} {$i <= $nmenu} {incr i} {
4104 if {[$m entrycget $i -command] eq $cmd} {
4105 eval $m $op $i $argv
4111 proc allviewmenus {n op args} {
4114 doviewmenu .bar.view 5 [list showview $n] $op $args
4115 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4118 proc newviewok {top n {apply 0}} {
4119 global nextviewnum newviewperm newviewname newishighlight
4120 global viewname viewfiles viewperm selectedview curview
4121 global viewargs viewargscmd newviewopts viewhlmenu
4124 set newargs [encode_view_opts $n]
4126 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4130 foreach f [split [$top.t get 0.0 end] "\n"] {
4131 set ft [string trim $f]
4136 if {![info exists viewfiles($n)]} {
4137 # creating a new view
4139 set viewname($n) $newviewname($n)
4140 set viewperm($n) $newviewopts($n,perm)
4141 set viewfiles($n) $files
4142 set viewargs($n) $newargs
4143 set viewargscmd($n) $newviewopts($n,cmd)
4145 if {!$newishighlight} {
4148 run addvhighlight $n
4151 # editing an existing view
4152 set viewperm($n) $newviewopts($n,perm)
4153 if {$newviewname($n) ne $viewname($n)} {
4154 set viewname($n) $newviewname($n)
4155 doviewmenu .bar.view 5 [list showview $n] \
4156 entryconf [list -label $viewname($n)]
4157 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4158 # entryconf [list -label $viewname($n) -value $viewname($n)]
4160 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4161 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4162 set viewfiles($n) $files
4163 set viewargs($n) $newargs
4164 set viewargscmd($n) $newviewopts($n,cmd)
4165 if {$curview == $n} {
4171 catch {destroy $top}
4175 global curview viewperm hlview selectedhlview
4177 if {$curview == 0} return
4178 if {[info exists hlview] && $hlview == $curview} {
4179 set selectedhlview [mc "None"]
4182 allviewmenus $curview delete
4183 set viewperm($curview) 0
4187 proc addviewmenu {n} {
4188 global viewname viewhlmenu
4190 .bar.view add radiobutton -label $viewname($n) \
4191 -command [list showview $n] -variable selectedview -value $n
4192 #$viewhlmenu add radiobutton -label $viewname($n) \
4193 # -command [list addvhighlight $n] -variable selectedhlview
4197 global curview cached_commitrow ordertok
4198 global displayorder parentlist rowidlist rowisopt rowfinal
4199 global colormap rowtextx nextcolor canvxmax
4200 global numcommits viewcomplete
4201 global selectedline currentid canv canvy0
4203 global pending_select mainheadid
4206 global hlview selectedhlview commitinterest
4208 if {$n == $curview} return
4210 set ymax [lindex [$canv cget -scrollregion] 3]
4211 set span [$canv yview]
4212 set ytop [expr {[lindex $span 0] * $ymax}]
4213 set ybot [expr {[lindex $span 1] * $ymax}]
4214 set yscreen [expr {($ybot - $ytop) / 2}]
4215 if {$selectedline ne {}} {
4216 set selid $currentid
4217 set y [yc $selectedline]
4218 if {$ytop < $y && $y < $ybot} {
4219 set yscreen [expr {$y - $ytop}]
4221 } elseif {[info exists pending_select]} {
4222 set selid $pending_select
4223 unset pending_select
4227 catch {unset treediffs}
4229 if {[info exists hlview] && $hlview == $n} {
4231 set selectedhlview [mc "None"]
4233 catch {unset commitinterest}
4234 catch {unset cached_commitrow}
4235 catch {unset ordertok}
4239 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4240 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4243 if {![info exists viewcomplete($n)]} {
4253 set numcommits $commitidx($n)
4255 catch {unset colormap}
4256 catch {unset rowtextx}
4258 set canvxmax [$canv cget -width]
4264 if {$selid ne {} && [commitinview $selid $n]} {
4265 set row [rowofcommit $selid]
4266 # try to get the selected row in the same position on the screen
4267 set ymax [lindex [$canv cget -scrollregion] 3]
4268 set ytop [expr {[yc $row] - $yscreen}]
4272 set yf [expr {$ytop * 1.0 / $ymax}]
4274 allcanvs yview moveto $yf
4278 } elseif {!$viewcomplete($n)} {
4279 reset_pending_select $selid
4281 reset_pending_select {}
4283 if {[commitinview $pending_select $curview]} {
4284 selectline [rowofcommit $pending_select] 1
4286 set row [first_real_row]
4287 if {$row < $numcommits} {
4292 if {!$viewcomplete($n)} {
4293 if {$numcommits == 0} {
4294 show_status [mc "Reading commits..."]
4296 } elseif {$numcommits == 0} {
4297 show_status [mc "No commits selected"]
4301 # Stuff relating to the highlighting facility
4303 proc ishighlighted {id} {
4304 global vhighlights fhighlights nhighlights rhighlights
4306 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4307 return $nhighlights($id)
4309 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4310 return $vhighlights($id)
4312 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4313 return $fhighlights($id)
4315 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4316 return $rhighlights($id)
4321 proc bolden {id font} {
4322 global canv linehtag currentid boldids need_redisplay markedid
4324 # need_redisplay = 1 means the display is stale and about to be redrawn
4325 if {$need_redisplay} return
4327 $canv itemconf $linehtag($id) -font $font
4328 if {[info exists currentid] && $id eq $currentid} {
4330 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4331 -outline {{}} -tags secsel \
4332 -fill [$canv cget -selectbackground]]
4335 if {[info exists markedid] && $id eq $markedid} {
4340 proc bolden_name {id font} {
4341 global canv2 linentag currentid boldnameids need_redisplay
4343 if {$need_redisplay} return
4344 lappend boldnameids $id
4345 $canv2 itemconf $linentag($id) -font $font
4346 if {[info exists currentid] && $id eq $currentid} {
4347 $canv2 delete secsel
4348 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4349 -outline {{}} -tags secsel \
4350 -fill [$canv2 cget -selectbackground]]
4359 foreach id $boldids {
4360 if {![ishighlighted $id]} {
4363 lappend stillbold $id
4366 set boldids $stillbold
4369 proc addvhighlight {n} {
4370 global hlview viewcomplete curview vhl_done commitidx
4372 if {[info exists hlview]} {
4376 if {$n != $curview && ![info exists viewcomplete($n)]} {
4379 set vhl_done $commitidx($hlview)
4380 if {$vhl_done > 0} {
4385 proc delvhighlight {} {
4386 global hlview vhighlights
4388 if {![info exists hlview]} return
4390 catch {unset vhighlights}
4394 proc vhighlightmore {} {
4395 global hlview vhl_done commitidx vhighlights curview
4397 set max $commitidx($hlview)
4398 set vr [visiblerows]
4399 set r0 [lindex $vr 0]
4400 set r1 [lindex $vr 1]
4401 for {set i $vhl_done} {$i < $max} {incr i} {
4402 set id [commitonrow $i $hlview]
4403 if {[commitinview $id $curview]} {
4404 set row [rowofcommit $id]
4405 if {$r0 <= $row && $row <= $r1} {
4406 if {![highlighted $row]} {
4407 bolden $id mainfontbold
4409 set vhighlights($id) 1
4417 proc askvhighlight {row id} {
4418 global hlview vhighlights iddrawn
4420 if {[commitinview $id $hlview]} {
4421 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4422 bolden $id mainfontbold
4424 set vhighlights($id) 1
4426 set vhighlights($id) 0
4430 proc hfiles_change {} {
4431 global highlight_files filehighlight fhighlights fh_serial
4432 global highlight_paths
4434 if {[info exists filehighlight]} {
4435 # delete previous highlights
4436 catch {close $filehighlight}
4438 catch {unset fhighlights}
4440 unhighlight_filelist
4442 set highlight_paths {}
4443 after cancel do_file_hl $fh_serial
4445 if {$highlight_files ne {}} {
4446 after 300 do_file_hl $fh_serial
4450 proc gdttype_change {name ix op} {
4451 global gdttype highlight_files findstring findpattern
4454 if {$findstring ne {}} {
4455 if {$gdttype eq [mc "containing:"]} {
4456 if {$highlight_files ne {}} {
4457 set highlight_files {}
4462 if {$findpattern ne {}} {
4466 set highlight_files $findstring
4471 # enable/disable findtype/findloc menus too
4474 proc find_change {name ix op} {
4475 global gdttype findstring highlight_files
4478 if {$gdttype eq [mc "containing:"]} {
4481 if {$highlight_files ne $findstring} {
4482 set highlight_files $findstring
4489 proc findcom_change args {
4490 global nhighlights boldnameids
4491 global findpattern findtype findstring gdttype
4494 # delete previous highlights, if any
4495 foreach id $boldnameids {
4496 bolden_name $id mainfont
4499 catch {unset nhighlights}
4502 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4504 } elseif {$findtype eq [mc "Regexp"]} {
4505 set findpattern $findstring
4507 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4509 set findpattern "*$e*"
4513 proc makepatterns {l} {
4516 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4517 if {[string index $ee end] eq "/"} {
4527 proc do_file_hl {serial} {
4528 global highlight_files filehighlight highlight_paths gdttype fhl_list
4530 if {$gdttype eq [mc "touching paths:"]} {
4531 if {[catch {set paths [shellsplit $highlight_files]}]} return
4532 set highlight_paths [makepatterns $paths]
4534 set gdtargs [concat -- $paths]
4535 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4536 set gdtargs [list "-S$highlight_files"]
4538 # must be "containing:", i.e. we're searching commit info
4541 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4542 set filehighlight [open $cmd r+]
4543 fconfigure $filehighlight -blocking 0
4544 filerun $filehighlight readfhighlight
4550 proc flushhighlights {} {
4551 global filehighlight fhl_list
4553 if {[info exists filehighlight]} {
4555 puts $filehighlight ""
4556 flush $filehighlight
4560 proc askfilehighlight {row id} {
4561 global filehighlight fhighlights fhl_list
4563 lappend fhl_list $id
4564 set fhighlights($id) -1
4565 puts $filehighlight $id
4568 proc readfhighlight {} {
4569 global filehighlight fhighlights curview iddrawn
4570 global fhl_list find_dirn
4572 if {![info exists filehighlight]} {
4576 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4577 set line [string trim $line]
4578 set i [lsearch -exact $fhl_list $line]
4579 if {$i < 0} continue
4580 for {set j 0} {$j < $i} {incr j} {
4581 set id [lindex $fhl_list $j]
4582 set fhighlights($id) 0
4584 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4585 if {$line eq {}} continue
4586 if {![commitinview $line $curview]} continue
4587 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4588 bolden $line mainfontbold
4590 set fhighlights($line) 1
4592 if {[eof $filehighlight]} {
4594 puts "oops, git diff-tree died"
4595 catch {close $filehighlight}
4599 if {[info exists find_dirn]} {
4605 proc doesmatch {f} {
4606 global findtype findpattern
4608 if {$findtype eq [mc "Regexp"]} {
4609 return [regexp $findpattern $f]
4610 } elseif {$findtype eq [mc "IgnCase"]} {
4611 return [string match -nocase $findpattern $f]
4613 return [string match $findpattern $f]
4617 proc askfindhighlight {row id} {
4618 global nhighlights commitinfo iddrawn
4620 global markingmatches
4622 if {![info exists commitinfo($id)]} {
4625 set info $commitinfo($id)
4627 set fldtypes [list [mc Headline] [mc Author] [mc Date] [mc Committer] [mc CDate] [mc Comments]]
4628 foreach f $info ty $fldtypes {
4629 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4631 if {$ty eq [mc "Author"]} {
4638 if {$isbold && [info exists iddrawn($id)]} {
4639 if {![ishighlighted $id]} {
4640 bolden $id mainfontbold
4642 bolden_name $id mainfontbold
4645 if {$markingmatches} {
4646 markrowmatches $row $id
4649 set nhighlights($id) $isbold
4652 proc markrowmatches {row id} {
4653 global canv canv2 linehtag linentag commitinfo findloc
4655 set headline [lindex $commitinfo($id) 0]
4656 set author [lindex $commitinfo($id) 1]
4657 $canv delete match$row
4658 $canv2 delete match$row
4659 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4660 set m [findmatches $headline]
4662 markmatches $canv $row $headline $linehtag($id) $m \
4663 [$canv itemcget $linehtag($id) -font] $row
4666 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4667 set m [findmatches $author]
4669 markmatches $canv2 $row $author $linentag($id) $m \
4670 [$canv2 itemcget $linentag($id) -font] $row
4675 proc vrel_change {name ix op} {
4676 global highlight_related
4679 if {$highlight_related ne [mc "None"]} {
4684 # prepare for testing whether commits are descendents or ancestors of a
4685 proc rhighlight_sel {a} {
4686 global descendent desc_todo ancestor anc_todo
4687 global highlight_related
4689 catch {unset descendent}
4690 set desc_todo [list $a]
4691 catch {unset ancestor}
4692 set anc_todo [list $a]
4693 if {$highlight_related ne [mc "None"]} {
4699 proc rhighlight_none {} {
4702 catch {unset rhighlights}
4706 proc is_descendent {a} {
4707 global curview children descendent desc_todo
4710 set la [rowofcommit $a]
4714 for {set i 0} {$i < [llength $todo]} {incr i} {
4715 set do [lindex $todo $i]
4716 if {[rowofcommit $do] < $la} {
4717 lappend leftover $do
4720 foreach nk $children($v,$do) {
4721 if {![info exists descendent($nk)]} {
4722 set descendent($nk) 1
4730 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4734 set descendent($a) 0
4735 set desc_todo $leftover
4738 proc is_ancestor {a} {
4739 global curview parents ancestor anc_todo
4742 set la [rowofcommit $a]
4746 for {set i 0} {$i < [llength $todo]} {incr i} {
4747 set do [lindex $todo $i]
4748 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4749 lappend leftover $do
4752 foreach np $parents($v,$do) {
4753 if {![info exists ancestor($np)]} {
4762 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4767 set anc_todo $leftover
4770 proc askrelhighlight {row id} {
4771 global descendent highlight_related iddrawn rhighlights
4772 global selectedline ancestor
4774 if {$selectedline eq {}} return
4776 if {$highlight_related eq [mc "Descendant"] ||
4777 $highlight_related eq [mc "Not descendant"]} {
4778 if {![info exists descendent($id)]} {
4781 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4784 } elseif {$highlight_related eq [mc "Ancestor"] ||
4785 $highlight_related eq [mc "Not ancestor"]} {
4786 if {![info exists ancestor($id)]} {
4789 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4793 if {[info exists iddrawn($id)]} {
4794 if {$isbold && ![ishighlighted $id]} {
4795 bolden $id mainfontbold
4798 set rhighlights($id) $isbold
4801 # Graph layout functions
4803 proc shortids {ids} {
4806 if {[llength $id] > 1} {
4807 lappend res [shortids $id]
4808 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4809 lappend res [string range $id 0 7]
4820 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4821 if {($n & $mask) != 0} {
4822 set ret [concat $ret $o]
4824 set o [concat $o $o]
4829 proc ordertoken {id} {
4830 global ordertok curview varcid varcstart varctok curview parents children
4831 global nullid nullid2
4833 if {[info exists ordertok($id)]} {
4834 return $ordertok($id)
4839 if {[info exists varcid($curview,$id)]} {
4840 set a $varcid($curview,$id)
4841 set p [lindex $varcstart($curview) $a]
4843 set p [lindex $children($curview,$id) 0]
4845 if {[info exists ordertok($p)]} {
4846 set tok $ordertok($p)
4849 set id [first_real_child $curview,$p]
4852 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4855 if {[llength $parents($curview,$id)] == 1} {
4856 lappend todo [list $p {}]
4858 set j [lsearch -exact $parents($curview,$id) $p]
4860 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4862 lappend todo [list $p [strrep $j]]
4865 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4866 set p [lindex $todo $i 0]
4867 append tok [lindex $todo $i 1]
4868 set ordertok($p) $tok
4870 set ordertok($origid) $tok
4874 # Work out where id should go in idlist so that order-token
4875 # values increase from left to right
4876 proc idcol {idlist id {i 0}} {
4877 set t [ordertoken $id]
4881 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4882 if {$i > [llength $idlist]} {
4883 set i [llength $idlist]
4885 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4888 if {$t > [ordertoken [lindex $idlist $i]]} {
4889 while {[incr i] < [llength $idlist] &&
4890 $t >= [ordertoken [lindex $idlist $i]]} {}
4896 proc initlayout {} {
4897 global rowidlist rowisopt rowfinal displayorder parentlist
4898 global numcommits canvxmax canv
4900 global colormap rowtextx
4909 set canvxmax [$canv cget -width]
4910 catch {unset colormap}
4911 catch {unset rowtextx}
4915 proc setcanvscroll {} {
4916 global canv canv2 canv3 numcommits linespc canvxmax canvy0
4917 global lastscrollset lastscrollrows
4919 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
4920 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
4921 $canv2 conf -scrollregion [list 0 0 0 $ymax]
4922 $canv3 conf -scrollregion [list 0 0 0 $ymax]
4923 set lastscrollset [clock clicks -milliseconds]
4924 set lastscrollrows $numcommits
4927 proc visiblerows {} {
4928 global canv numcommits linespc
4930 set ymax [lindex [$canv cget -scrollregion] 3]
4931 if {$ymax eq {} || $ymax == 0} return
4933 set y0 [expr {int([lindex $f 0] * $ymax)}]
4934 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
4938 set y1 [expr {int([lindex $f 1] * $ymax)}]
4939 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
4940 if {$r1 >= $numcommits} {
4941 set r1 [expr {$numcommits - 1}]
4943 return [list $r0 $r1]
4946 proc layoutmore {} {
4947 global commitidx viewcomplete curview
4948 global numcommits pending_select curview
4949 global lastscrollset lastscrollrows
4951 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
4952 [clock clicks -milliseconds] - $lastscrollset > 500} {
4955 if {[info exists pending_select] &&
4956 [commitinview $pending_select $curview]} {
4958 selectline [rowofcommit $pending_select] 1
4963 # With path limiting, we mightn't get the actual HEAD commit,
4964 # so ask git rev-list what is the first ancestor of HEAD that
4965 # touches a file in the path limit.
4966 proc get_viewmainhead {view} {
4967 global viewmainheadid vfilelimit viewinstances mainheadid
4970 set rfd [open [concat | git rev-list -1 $mainheadid \
4971 -- $vfilelimit($view)] r]
4972 set j [reg_instance $rfd]
4973 lappend viewinstances($view) $j
4974 fconfigure $rfd -blocking 0
4975 filerun $rfd [list getviewhead $rfd $j $view]
4976 set viewmainheadid($curview) {}
4980 # git rev-list should give us just 1 line to use as viewmainheadid($view)
4981 proc getviewhead {fd inst view} {
4982 global viewmainheadid commfd curview viewinstances showlocalchanges
4985 if {[gets $fd line] < 0} {
4989 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
4992 set viewmainheadid($view) $id
4995 set i [lsearch -exact $viewinstances($view) $inst]
4997 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
4999 if {$showlocalchanges && $id ne {} && $view == $curview} {
5005 proc doshowlocalchanges {} {
5006 global curview viewmainheadid
5008 if {$viewmainheadid($curview) eq {}} return
5009 if {[commitinview $viewmainheadid($curview) $curview]} {
5012 interestedin $viewmainheadid($curview) dodiffindex
5016 proc dohidelocalchanges {} {
5017 global nullid nullid2 lserial curview
5019 if {[commitinview $nullid $curview]} {
5020 removefakerow $nullid
5022 if {[commitinview $nullid2 $curview]} {
5023 removefakerow $nullid2
5028 # spawn off a process to do git diff-index --cached HEAD
5029 proc dodiffindex {} {
5030 global lserial showlocalchanges vfilelimit curview
5033 if {!$showlocalchanges || !$isworktree} return
5035 set cmd "|git diff-index --cached HEAD"
5036 if {$vfilelimit($curview) ne {}} {
5037 set cmd [concat $cmd -- $vfilelimit($curview)]
5039 set fd [open $cmd r]
5040 fconfigure $fd -blocking 0
5041 set i [reg_instance $fd]
5042 filerun $fd [list readdiffindex $fd $lserial $i]
5045 proc readdiffindex {fd serial inst} {
5046 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5050 if {[gets $fd line] < 0} {
5056 # we only need to see one line and we don't really care what it says...
5059 if {$serial != $lserial} {
5063 # now see if there are any local changes not checked in to the index
5064 set cmd "|git diff-files"
5065 if {$vfilelimit($curview) ne {}} {
5066 set cmd [concat $cmd -- $vfilelimit($curview)]
5068 set fd [open $cmd r]
5069 fconfigure $fd -blocking 0
5070 set i [reg_instance $fd]
5071 filerun $fd [list readdifffiles $fd $serial $i]
5073 if {$isdiff && ![commitinview $nullid2 $curview]} {
5074 # add the line for the changes in the index to the graph
5075 set hl [mc "Local changes checked in to index but not committed"]
5076 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5077 set commitdata($nullid2) "\n $hl\n"
5078 if {[commitinview $nullid $curview]} {
5079 removefakerow $nullid
5081 insertfakerow $nullid2 $viewmainheadid($curview)
5082 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5083 if {[commitinview $nullid $curview]} {
5084 removefakerow $nullid
5086 removefakerow $nullid2
5091 proc readdifffiles {fd serial inst} {
5092 global viewmainheadid nullid nullid2 curview
5093 global commitinfo commitdata lserial
5096 if {[gets $fd line] < 0} {
5102 # we only need to see one line and we don't really care what it says...
5105 if {$serial != $lserial} {
5109 if {$isdiff && ![commitinview $nullid $curview]} {
5110 # add the line for the local diff to the graph
5111 set hl [mc "Local uncommitted changes, not checked in to index"]
5112 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5113 set commitdata($nullid) "\n $hl\n"
5114 if {[commitinview $nullid2 $curview]} {
5117 set p $viewmainheadid($curview)
5119 insertfakerow $nullid $p
5120 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5121 removefakerow $nullid
5126 proc nextuse {id row} {
5127 global curview children
5129 if {[info exists children($curview,$id)]} {
5130 foreach kid $children($curview,$id) {
5131 if {![commitinview $kid $curview]} {
5134 if {[rowofcommit $kid] > $row} {
5135 return [rowofcommit $kid]
5139 if {[commitinview $id $curview]} {
5140 return [rowofcommit $id]
5145 proc prevuse {id row} {
5146 global curview children
5149 if {[info exists children($curview,$id)]} {
5150 foreach kid $children($curview,$id) {
5151 if {![commitinview $kid $curview]} break
5152 if {[rowofcommit $kid] < $row} {
5153 set ret [rowofcommit $kid]
5160 proc make_idlist {row} {
5161 global displayorder parentlist uparrowlen downarrowlen mingaplen
5162 global commitidx curview children
5164 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5168 set ra [expr {$row - $downarrowlen}]
5172 set rb [expr {$row + $uparrowlen}]
5173 if {$rb > $commitidx($curview)} {
5174 set rb $commitidx($curview)
5176 make_disporder $r [expr {$rb + 1}]
5178 for {} {$r < $ra} {incr r} {
5179 set nextid [lindex $displayorder [expr {$r + 1}]]
5180 foreach p [lindex $parentlist $r] {
5181 if {$p eq $nextid} continue
5182 set rn [nextuse $p $r]
5184 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5185 lappend ids [list [ordertoken $p] $p]
5189 for {} {$r < $row} {incr r} {
5190 set nextid [lindex $displayorder [expr {$r + 1}]]
5191 foreach p [lindex $parentlist $r] {
5192 if {$p eq $nextid} continue
5193 set rn [nextuse $p $r]
5194 if {$rn < 0 || $rn >= $row} {
5195 lappend ids [list [ordertoken $p] $p]
5199 set id [lindex $displayorder $row]
5200 lappend ids [list [ordertoken $id] $id]
5202 foreach p [lindex $parentlist $r] {
5203 set firstkid [lindex $children($curview,$p) 0]
5204 if {[rowofcommit $firstkid] < $row} {
5205 lappend ids [list [ordertoken $p] $p]
5209 set id [lindex $displayorder $r]
5211 set firstkid [lindex $children($curview,$id) 0]
5212 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5213 lappend ids [list [ordertoken $id] $id]
5218 foreach idx [lsort -unique $ids] {
5219 lappend idlist [lindex $idx 1]
5224 proc rowsequal {a b} {
5225 while {[set i [lsearch -exact $a {}]] >= 0} {
5226 set a [lreplace $a $i $i]
5228 while {[set i [lsearch -exact $b {}]] >= 0} {
5229 set b [lreplace $b $i $i]
5231 return [expr {$a eq $b}]
5234 proc makeupline {id row rend col} {
5235 global rowidlist uparrowlen downarrowlen mingaplen
5237 for {set r $rend} {1} {set r $rstart} {
5238 set rstart [prevuse $id $r]
5239 if {$rstart < 0} return
5240 if {$rstart < $row} break
5242 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5243 set rstart [expr {$rend - $uparrowlen - 1}]
5245 for {set r $rstart} {[incr r] <= $row} {} {
5246 set idlist [lindex $rowidlist $r]
5247 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5248 set col [idcol $idlist $id $col]
5249 lset rowidlist $r [linsert $idlist $col $id]
5255 proc layoutrows {row endrow} {
5256 global rowidlist rowisopt rowfinal displayorder
5257 global uparrowlen downarrowlen maxwidth mingaplen
5258 global children parentlist
5259 global commitidx viewcomplete curview
5261 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5264 set rm1 [expr {$row - 1}]
5265 foreach id [lindex $rowidlist $rm1] {
5270 set final [lindex $rowfinal $rm1]
5272 for {} {$row < $endrow} {incr row} {
5273 set rm1 [expr {$row - 1}]
5274 if {$rm1 < 0 || $idlist eq {}} {
5275 set idlist [make_idlist $row]
5278 set id [lindex $displayorder $rm1]
5279 set col [lsearch -exact $idlist $id]
5280 set idlist [lreplace $idlist $col $col]
5281 foreach p [lindex $parentlist $rm1] {
5282 if {[lsearch -exact $idlist $p] < 0} {
5283 set col [idcol $idlist $p $col]
5284 set idlist [linsert $idlist $col $p]
5285 # if not the first child, we have to insert a line going up
5286 if {$id ne [lindex $children($curview,$p) 0]} {
5287 makeupline $p $rm1 $row $col
5291 set id [lindex $displayorder $row]
5292 if {$row > $downarrowlen} {
5293 set termrow [expr {$row - $downarrowlen - 1}]
5294 foreach p [lindex $parentlist $termrow] {
5295 set i [lsearch -exact $idlist $p]
5296 if {$i < 0} continue
5297 set nr [nextuse $p $termrow]
5298 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5299 set idlist [lreplace $idlist $i $i]
5303 set col [lsearch -exact $idlist $id]
5305 set col [idcol $idlist $id]
5306 set idlist [linsert $idlist $col $id]
5307 if {$children($curview,$id) ne {}} {
5308 makeupline $id $rm1 $row $col
5311 set r [expr {$row + $uparrowlen - 1}]
5312 if {$r < $commitidx($curview)} {
5314 foreach p [lindex $parentlist $r] {
5315 if {[lsearch -exact $idlist $p] >= 0} continue
5316 set fk [lindex $children($curview,$p) 0]
5317 if {[rowofcommit $fk] < $row} {
5318 set x [idcol $idlist $p $x]
5319 set idlist [linsert $idlist $x $p]
5322 if {[incr r] < $commitidx($curview)} {
5323 set p [lindex $displayorder $r]
5324 if {[lsearch -exact $idlist $p] < 0} {
5325 set fk [lindex $children($curview,$p) 0]
5326 if {$fk ne {} && [rowofcommit $fk] < $row} {
5327 set x [idcol $idlist $p $x]
5328 set idlist [linsert $idlist $x $p]
5334 if {$final && !$viewcomplete($curview) &&
5335 $row + $uparrowlen + $mingaplen + $downarrowlen
5336 >= $commitidx($curview)} {
5339 set l [llength $rowidlist]
5341 lappend rowidlist $idlist
5343 lappend rowfinal $final
5344 } elseif {$row < $l} {
5345 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5346 lset rowidlist $row $idlist
5349 lset rowfinal $row $final
5351 set pad [ntimes [expr {$row - $l}] {}]
5352 set rowidlist [concat $rowidlist $pad]
5353 lappend rowidlist $idlist
5354 set rowfinal [concat $rowfinal $pad]
5355 lappend rowfinal $final
5356 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5362 proc changedrow {row} {
5363 global displayorder iddrawn rowisopt need_redisplay
5365 set l [llength $rowisopt]
5367 lset rowisopt $row 0
5368 if {$row + 1 < $l} {
5369 lset rowisopt [expr {$row + 1}] 0
5370 if {$row + 2 < $l} {
5371 lset rowisopt [expr {$row + 2}] 0
5375 set id [lindex $displayorder $row]
5376 if {[info exists iddrawn($id)]} {
5377 set need_redisplay 1
5381 proc insert_pad {row col npad} {
5384 set pad [ntimes $npad {}]
5385 set idlist [lindex $rowidlist $row]
5386 set bef [lrange $idlist 0 [expr {$col - 1}]]
5387 set aft [lrange $idlist $col end]
5388 set i [lsearch -exact $aft {}]
5390 set aft [lreplace $aft $i $i]
5392 lset rowidlist $row [concat $bef $pad $aft]
5396 proc optimize_rows {row col endrow} {
5397 global rowidlist rowisopt displayorder curview children
5402 for {} {$row < $endrow} {incr row; set col 0} {
5403 if {[lindex $rowisopt $row]} continue
5405 set y0 [expr {$row - 1}]
5406 set ym [expr {$row - 2}]
5407 set idlist [lindex $rowidlist $row]
5408 set previdlist [lindex $rowidlist $y0]
5409 if {$idlist eq {} || $previdlist eq {}} continue
5411 set pprevidlist [lindex $rowidlist $ym]
5412 if {$pprevidlist eq {}} continue
5418 for {} {$col < [llength $idlist]} {incr col} {
5419 set id [lindex $idlist $col]
5420 if {[lindex $previdlist $col] eq $id} continue
5425 set x0 [lsearch -exact $previdlist $id]
5426 if {$x0 < 0} continue
5427 set z [expr {$x0 - $col}]
5431 set xm [lsearch -exact $pprevidlist $id]
5433 set z0 [expr {$xm - $x0}]
5437 # if row y0 is the first child of $id then it's not an arrow
5438 if {[lindex $children($curview,$id) 0] ne
5439 [lindex $displayorder $y0]} {
5443 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5444 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5447 # Looking at lines from this row to the previous row,
5448 # make them go straight up if they end in an arrow on
5449 # the previous row; otherwise make them go straight up
5451 if {$z < -1 || ($z < 0 && $isarrow)} {
5452 # Line currently goes left too much;
5453 # insert pads in the previous row, then optimize it
5454 set npad [expr {-1 - $z + $isarrow}]
5455 insert_pad $y0 $x0 $npad
5457 optimize_rows $y0 $x0 $row
5459 set previdlist [lindex $rowidlist $y0]
5460 set x0 [lsearch -exact $previdlist $id]
5461 set z [expr {$x0 - $col}]
5463 set pprevidlist [lindex $rowidlist $ym]
5464 set xm [lsearch -exact $pprevidlist $id]
5465 set z0 [expr {$xm - $x0}]
5467 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5468 # Line currently goes right too much;
5469 # insert pads in this line
5470 set npad [expr {$z - 1 + $isarrow}]
5471 insert_pad $row $col $npad
5472 set idlist [lindex $rowidlist $row]
5474 set z [expr {$x0 - $col}]
5477 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5478 # this line links to its first child on row $row-2
5479 set id [lindex $displayorder $ym]
5480 set xc [lsearch -exact $pprevidlist $id]
5482 set z0 [expr {$xc - $x0}]
5485 # avoid lines jigging left then immediately right
5486 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5487 insert_pad $y0 $x0 1
5489 optimize_rows $y0 $x0 $row
5490 set previdlist [lindex $rowidlist $y0]
5494 # Find the first column that doesn't have a line going right
5495 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5496 set id [lindex $idlist $col]
5497 if {$id eq {}} break
5498 set x0 [lsearch -exact $previdlist $id]
5500 # check if this is the link to the first child
5501 set kid [lindex $displayorder $y0]
5502 if {[lindex $children($curview,$id) 0] eq $kid} {
5503 # it is, work out offset to child
5504 set x0 [lsearch -exact $previdlist $kid]
5507 if {$x0 <= $col} break
5509 # Insert a pad at that column as long as it has a line and
5510 # isn't the last column
5511 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5512 set idlist [linsert $idlist $col {}]
5513 lset rowidlist $row $idlist
5521 global canvx0 linespc
5522 return [expr {$canvx0 + $col * $linespc}]
5526 global canvy0 linespc
5527 return [expr {$canvy0 + $row * $linespc}]
5530 proc linewidth {id} {
5531 global thickerline lthickness
5534 if {[info exists thickerline] && $id eq $thickerline} {
5535 set wid [expr {2 * $lthickness}]
5540 proc rowranges {id} {
5541 global curview children uparrowlen downarrowlen
5544 set kids $children($curview,$id)
5550 foreach child $kids {
5551 if {![commitinview $child $curview]} break
5552 set row [rowofcommit $child]
5553 if {![info exists prev]} {
5554 lappend ret [expr {$row + 1}]
5556 if {$row <= $prevrow} {
5557 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5559 # see if the line extends the whole way from prevrow to row
5560 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5561 [lsearch -exact [lindex $rowidlist \
5562 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5563 # it doesn't, see where it ends
5564 set r [expr {$prevrow + $downarrowlen}]
5565 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5566 while {[incr r -1] > $prevrow &&
5567 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5569 while {[incr r] <= $row &&
5570 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5574 # see where it starts up again
5575 set r [expr {$row - $uparrowlen}]
5576 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5577 while {[incr r] < $row &&
5578 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5580 while {[incr r -1] >= $prevrow &&
5581 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5587 if {$child eq $id} {
5596 proc drawlineseg {id row endrow arrowlow} {
5597 global rowidlist displayorder iddrawn linesegs
5598 global canv colormap linespc curview maxlinelen parentlist
5600 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5601 set le [expr {$row + 1}]
5604 set c [lsearch -exact [lindex $rowidlist $le] $id]
5610 set x [lindex $displayorder $le]
5615 if {[info exists iddrawn($x)] || $le == $endrow} {
5616 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5632 if {[info exists linesegs($id)]} {
5633 set lines $linesegs($id)
5635 set r0 [lindex $li 0]
5637 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5647 set li [lindex $lines [expr {$i-1}]]
5648 set r1 [lindex $li 1]
5649 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5654 set x [lindex $cols [expr {$le - $row}]]
5655 set xp [lindex $cols [expr {$le - 1 - $row}]]
5656 set dir [expr {$xp - $x}]
5658 set ith [lindex $lines $i 2]
5659 set coords [$canv coords $ith]
5660 set ah [$canv itemcget $ith -arrow]
5661 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5662 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5663 if {$x2 ne {} && $x - $x2 == $dir} {
5664 set coords [lrange $coords 0 end-2]
5667 set coords [list [xc $le $x] [yc $le]]
5670 set itl [lindex $lines [expr {$i-1}] 2]
5671 set al [$canv itemcget $itl -arrow]
5672 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5673 } elseif {$arrowlow} {
5674 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5675 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5679 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5680 for {set y $le} {[incr y -1] > $row} {} {
5682 set xp [lindex $cols [expr {$y - 1 - $row}]]
5683 set ndir [expr {$xp - $x}]
5684 if {$dir != $ndir || $xp < 0} {
5685 lappend coords [xc $y $x] [yc $y]
5691 # join parent line to first child
5692 set ch [lindex $displayorder $row]
5693 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5695 puts "oops: drawlineseg: child $ch not on row $row"
5696 } elseif {$xc != $x} {
5697 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5698 set d [expr {int(0.5 * $linespc)}]
5701 set x2 [expr {$x1 - $d}]
5703 set x2 [expr {$x1 + $d}]
5706 set y1 [expr {$y2 + $d}]
5707 lappend coords $x1 $y1 $x2 $y2
5708 } elseif {$xc < $x - 1} {
5709 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5710 } elseif {$xc > $x + 1} {
5711 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5715 lappend coords [xc $row $x] [yc $row]
5717 set xn [xc $row $xp]
5719 lappend coords $xn $yn
5723 set t [$canv create line $coords -width [linewidth $id] \
5724 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5727 set lines [linsert $lines $i [list $row $le $t]]
5729 $canv coords $ith $coords
5730 if {$arrow ne $ah} {
5731 $canv itemconf $ith -arrow $arrow
5733 lset lines $i 0 $row
5736 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5737 set ndir [expr {$xo - $xp}]
5738 set clow [$canv coords $itl]
5739 if {$dir == $ndir} {
5740 set clow [lrange $clow 2 end]
5742 set coords [concat $coords $clow]
5744 lset lines [expr {$i-1}] 1 $le
5746 # coalesce two pieces
5748 set b [lindex $lines [expr {$i-1}] 0]
5749 set e [lindex $lines $i 1]
5750 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5752 $canv coords $itl $coords
5753 if {$arrow ne $al} {
5754 $canv itemconf $itl -arrow $arrow
5758 set linesegs($id) $lines
5762 proc drawparentlinks {id row} {
5763 global rowidlist canv colormap curview parentlist
5764 global idpos linespc
5766 set rowids [lindex $rowidlist $row]
5767 set col [lsearch -exact $rowids $id]
5768 if {$col < 0} return
5769 set olds [lindex $parentlist $row]
5770 set row2 [expr {$row + 1}]
5771 set x [xc $row $col]
5774 set d [expr {int(0.5 * $linespc)}]
5775 set ymid [expr {$y + $d}]
5776 set ids [lindex $rowidlist $row2]
5777 # rmx = right-most X coord used
5780 set i [lsearch -exact $ids $p]
5782 puts "oops, parent $p of $id not in list"
5785 set x2 [xc $row2 $i]
5789 set j [lsearch -exact $rowids $p]
5791 # drawlineseg will do this one for us
5795 # should handle duplicated parents here...
5796 set coords [list $x $y]
5798 # if attaching to a vertical segment, draw a smaller
5799 # slant for visual distinctness
5802 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5804 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5806 } elseif {$i < $col && $i < $j} {
5807 # segment slants towards us already
5808 lappend coords [xc $row $j] $y
5810 if {$i < $col - 1} {
5811 lappend coords [expr {$x2 + $linespc}] $y
5812 } elseif {$i > $col + 1} {
5813 lappend coords [expr {$x2 - $linespc}] $y
5815 lappend coords $x2 $y2
5818 lappend coords $x2 $y2
5820 set t [$canv create line $coords -width [linewidth $p] \
5821 -fill $colormap($p) -tags lines.$p]
5825 if {$rmx > [lindex $idpos($id) 1]} {
5826 lset idpos($id) 1 $rmx
5831 proc drawlines {id} {
5834 $canv itemconf lines.$id -width [linewidth $id]
5837 proc drawcmittext {id row col} {
5838 global linespc canv canv2 canv3 fgcolor curview
5839 global cmitlisted commitinfo rowidlist parentlist
5840 global rowtextx idpos idtags idheads idotherrefs
5841 global linehtag linentag linedtag selectedline
5842 global canvxmax boldids boldnameids fgcolor markedid
5843 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5845 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5846 set listed $cmitlisted($curview,$id)
5847 if {$id eq $nullid} {
5849 } elseif {$id eq $nullid2} {
5851 } elseif {$id eq $mainheadid} {
5854 set ofill [lindex $circlecolors $listed]
5856 set x [xc $row $col]
5858 set orad [expr {$linespc / 3}]
5860 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5861 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5862 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5863 } elseif {$listed == 3} {
5864 # triangle pointing left for left-side commits
5865 set t [$canv create polygon \
5866 [expr {$x - $orad}] $y \
5867 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5868 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5869 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5871 # triangle pointing right for right-side commits
5872 set t [$canv create polygon \
5873 [expr {$x + $orad - 1}] $y \
5874 [expr {$x - $orad}] [expr {$y - $orad}] \
5875 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5876 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5878 set circleitem($row) $t
5880 $canv bind $t <1> {selcanvline {} %x %y}
5881 set rmx [llength [lindex $rowidlist $row]]
5882 set olds [lindex $parentlist $row]
5884 set nextids [lindex $rowidlist [expr {$row + 1}]]
5886 set i [lsearch -exact $nextids $p]
5892 set xt [xc $row $rmx]
5893 set rowtextx($row) $xt
5894 set idpos($id) [list $x $xt $y]
5895 if {[info exists idtags($id)] || [info exists idheads($id)]
5896 || [info exists idotherrefs($id)]} {
5897 set xt [drawtags $id $x $xt $y]
5899 set headline [lindex $commitinfo($id) 0]
5900 set name [lindex $commitinfo($id) 1]
5901 set date [lindex $commitinfo($id) 2]
5902 set date [formatdate $date]
5905 set isbold [ishighlighted $id]
5908 set font mainfontbold
5910 lappend boldnameids $id
5911 set nfont mainfontbold
5914 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
5915 -text $headline -font $font -tags text]
5916 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
5917 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5918 -text $name -font $nfont -tags text]
5919 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5920 -text $date -font mainfont -tags text]
5921 if {$selectedline == $row} {
5924 if {[info exists markedid] && $markedid eq $id} {
5927 set xr [expr {$xt + [font measure $font $headline]}]
5928 if {$xr > $canvxmax} {
5934 proc drawcmitrow {row} {
5935 global displayorder rowidlist nrows_drawn
5936 global iddrawn markingmatches
5937 global commitinfo numcommits
5938 global filehighlight fhighlights findpattern nhighlights
5939 global hlview vhighlights
5940 global highlight_related rhighlights
5942 if {$row >= $numcommits} return
5944 set id [lindex $displayorder $row]
5945 if {[info exists hlview] && ![info exists vhighlights($id)]} {
5946 askvhighlight $row $id
5948 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
5949 askfilehighlight $row $id
5951 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
5952 askfindhighlight $row $id
5954 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
5955 askrelhighlight $row $id
5957 if {![info exists iddrawn($id)]} {
5958 set col [lsearch -exact [lindex $rowidlist $row] $id]
5960 puts "oops, row $row id $id not in list"
5963 if {![info exists commitinfo($id)]} {
5967 drawcmittext $id $row $col
5971 if {$markingmatches} {
5972 markrowmatches $row $id
5976 proc drawcommits {row {endrow {}}} {
5977 global numcommits iddrawn displayorder curview need_redisplay
5978 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
5983 if {$endrow eq {}} {
5986 if {$endrow >= $numcommits} {
5987 set endrow [expr {$numcommits - 1}]
5990 set rl1 [expr {$row - $downarrowlen - 3}]
5994 set ro1 [expr {$row - 3}]
5998 set r2 [expr {$endrow + $uparrowlen + 3}]
5999 if {$r2 > $numcommits} {
6002 for {set r $rl1} {$r < $r2} {incr r} {
6003 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6007 set rl1 [expr {$r + 1}]
6013 optimize_rows $ro1 0 $r2
6014 if {$need_redisplay || $nrows_drawn > 2000} {
6018 # make the lines join to already-drawn rows either side
6019 set r [expr {$row - 1}]
6020 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6023 set er [expr {$endrow + 1}]
6024 if {$er >= $numcommits ||
6025 ![info exists iddrawn([lindex $displayorder $er])]} {
6028 for {} {$r <= $er} {incr r} {
6029 set id [lindex $displayorder $r]
6030 set wasdrawn [info exists iddrawn($id)]
6032 if {$r == $er} break
6033 set nextid [lindex $displayorder [expr {$r + 1}]]
6034 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6035 drawparentlinks $id $r
6037 set rowids [lindex $rowidlist $r]
6038 foreach lid $rowids {
6039 if {$lid eq {}} continue
6040 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6042 # see if this is the first child of any of its parents
6043 foreach p [lindex $parentlist $r] {
6044 if {[lsearch -exact $rowids $p] < 0} {
6045 # make this line extend up to the child
6046 set lineend($p) [drawlineseg $p $r $er 0]
6050 set lineend($lid) [drawlineseg $lid $r $er 1]
6056 proc undolayout {row} {
6057 global uparrowlen mingaplen downarrowlen
6058 global rowidlist rowisopt rowfinal need_redisplay
6060 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6064 if {[llength $rowidlist] > $r} {
6066 set rowidlist [lrange $rowidlist 0 $r]
6067 set rowfinal [lrange $rowfinal 0 $r]
6068 set rowisopt [lrange $rowisopt 0 $r]
6069 set need_redisplay 1
6074 proc drawvisible {} {
6075 global canv linespc curview vrowmod selectedline targetrow targetid
6076 global need_redisplay cscroll numcommits
6078 set fs [$canv yview]
6079 set ymax [lindex [$canv cget -scrollregion] 3]
6080 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6081 set f0 [lindex $fs 0]
6082 set f1 [lindex $fs 1]
6083 set y0 [expr {int($f0 * $ymax)}]
6084 set y1 [expr {int($f1 * $ymax)}]
6086 if {[info exists targetid]} {
6087 if {[commitinview $targetid $curview]} {
6088 set r [rowofcommit $targetid]
6089 if {$r != $targetrow} {
6090 # Fix up the scrollregion and change the scrolling position
6091 # now that our target row has moved.
6092 set diff [expr {($r - $targetrow) * $linespc}]
6095 set ymax [lindex [$canv cget -scrollregion] 3]
6098 set f0 [expr {$y0 / $ymax}]
6099 set f1 [expr {$y1 / $ymax}]
6100 allcanvs yview moveto $f0
6101 $cscroll set $f0 $f1
6102 set need_redisplay 1
6109 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6110 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6111 if {$endrow >= $vrowmod($curview)} {
6112 update_arcrows $curview
6114 if {$selectedline ne {} &&
6115 $row <= $selectedline && $selectedline <= $endrow} {
6116 set targetrow $selectedline
6117 } elseif {[info exists targetid]} {
6118 set targetrow [expr {int(($row + $endrow) / 2)}]
6120 if {[info exists targetrow]} {
6121 if {$targetrow >= $numcommits} {
6122 set targetrow [expr {$numcommits - 1}]
6124 set targetid [commitonrow $targetrow]
6126 drawcommits $row $endrow
6129 proc clear_display {} {
6130 global iddrawn linesegs need_redisplay nrows_drawn
6131 global vhighlights fhighlights nhighlights rhighlights
6132 global linehtag linentag linedtag boldids boldnameids
6135 catch {unset iddrawn}
6136 catch {unset linesegs}
6137 catch {unset linehtag}
6138 catch {unset linentag}
6139 catch {unset linedtag}
6142 catch {unset vhighlights}
6143 catch {unset fhighlights}
6144 catch {unset nhighlights}
6145 catch {unset rhighlights}
6146 set need_redisplay 0
6150 proc findcrossings {id} {
6151 global rowidlist parentlist numcommits displayorder
6155 foreach {s e} [rowranges $id] {
6156 if {$e >= $numcommits} {
6157 set e [expr {$numcommits - 1}]
6159 if {$e <= $s} continue
6160 for {set row $e} {[incr row -1] >= $s} {} {
6161 set x [lsearch -exact [lindex $rowidlist $row] $id]
6163 set olds [lindex $parentlist $row]
6164 set kid [lindex $displayorder $row]
6165 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6166 if {$kidx < 0} continue
6167 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6169 set px [lsearch -exact $nextrow $p]
6170 if {$px < 0} continue
6171 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6172 if {[lsearch -exact $ccross $p] >= 0} continue
6173 if {$x == $px + ($kidx < $px? -1: 1)} {
6175 } elseif {[lsearch -exact $cross $p] < 0} {
6182 return [concat $ccross {{}} $cross]
6185 proc assigncolor {id} {
6186 global colormap colors nextcolor
6187 global parents children children curview
6189 if {[info exists colormap($id)]} return
6190 set ncolors [llength $colors]
6191 if {[info exists children($curview,$id)]} {
6192 set kids $children($curview,$id)
6196 if {[llength $kids] == 1} {
6197 set child [lindex $kids 0]
6198 if {[info exists colormap($child)]
6199 && [llength $parents($curview,$child)] == 1} {
6200 set colormap($id) $colormap($child)
6206 foreach x [findcrossings $id] {
6208 # delimiter between corner crossings and other crossings
6209 if {[llength $badcolors] >= $ncolors - 1} break
6210 set origbad $badcolors
6212 if {[info exists colormap($x)]
6213 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6214 lappend badcolors $colormap($x)
6217 if {[llength $badcolors] >= $ncolors} {
6218 set badcolors $origbad
6220 set origbad $badcolors
6221 if {[llength $badcolors] < $ncolors - 1} {
6222 foreach child $kids {
6223 if {[info exists colormap($child)]
6224 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6225 lappend badcolors $colormap($child)
6227 foreach p $parents($curview,$child) {
6228 if {[info exists colormap($p)]
6229 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6230 lappend badcolors $colormap($p)
6234 if {[llength $badcolors] >= $ncolors} {
6235 set badcolors $origbad
6238 for {set i 0} {$i <= $ncolors} {incr i} {
6239 set c [lindex $colors $nextcolor]
6240 if {[incr nextcolor] >= $ncolors} {
6243 if {[lsearch -exact $badcolors $c]} break
6245 set colormap($id) $c
6248 proc bindline {t id} {
6251 $canv bind $t <Enter> "lineenter %x %y $id"
6252 $canv bind $t <Motion> "linemotion %x %y $id"
6253 $canv bind $t <Leave> "lineleave $id"
6254 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6257 proc drawtags {id x xt y1} {
6258 global idtags idheads idotherrefs mainhead
6259 global linespc lthickness
6260 global canv rowtextx curview fgcolor bgcolor ctxbut
6265 if {[info exists idtags($id)]} {
6266 set marks $idtags($id)
6267 set ntags [llength $marks]
6269 if {[info exists idheads($id)]} {
6270 set marks [concat $marks $idheads($id)]
6271 set nheads [llength $idheads($id)]
6273 if {[info exists idotherrefs($id)]} {
6274 set marks [concat $marks $idotherrefs($id)]
6280 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6281 set yt [expr {$y1 - 0.5 * $linespc}]
6282 set yb [expr {$yt + $linespc - 1}]
6286 foreach tag $marks {
6288 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6289 set wid [font measure mainfontbold $tag]
6291 set wid [font measure mainfont $tag]
6295 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6297 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6298 -width $lthickness -fill black -tags tag.$id]
6300 foreach tag $marks x $xvals wid $wvals {
6301 set tag_quoted [string map {% %%} $tag]
6302 set xl [expr {$x + $delta}]
6303 set xr [expr {$x + $delta + $wid + $lthickness}]
6305 if {[incr ntags -1] >= 0} {
6307 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6308 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6309 -width 1 -outline black -fill yellow -tags tag.$id]
6310 $canv bind $t <1> [list showtag $tag_quoted 1]
6311 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6313 # draw a head or other ref
6314 if {[incr nheads -1] >= 0} {
6316 if {$tag eq $mainhead} {
6317 set font mainfontbold
6322 set xl [expr {$xl - $delta/2}]
6323 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6324 -width 1 -outline black -fill $col -tags tag.$id
6325 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6326 set rwid [font measure mainfont $remoteprefix]
6327 set xi [expr {$x + 1}]
6328 set yti [expr {$yt + 1}]
6329 set xri [expr {$x + $rwid}]
6330 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6331 -width 0 -fill "#ffddaa" -tags tag.$id
6334 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
6335 -font $font -tags [list tag.$id text]]
6337 $canv bind $t <1> [list showtag $tag_quoted 1]
6338 } elseif {$nheads >= 0} {
6339 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6345 proc xcoord {i level ln} {
6346 global canvx0 xspc1 xspc2
6348 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6349 if {$i > 0 && $i == $level} {
6350 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6351 } elseif {$i > $level} {
6352 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6357 proc show_status {msg} {
6361 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6362 -tags text -fill $fgcolor
6365 # Don't change the text pane cursor if it is currently the hand cursor,
6366 # showing that we are over a sha1 ID link.
6367 proc settextcursor {c} {
6368 global ctext curtextcursor
6370 if {[$ctext cget -cursor] == $curtextcursor} {
6371 $ctext config -cursor $c
6373 set curtextcursor $c
6376 proc nowbusy {what {name {}}} {
6377 global isbusy busyname statusw
6379 if {[array names isbusy] eq {}} {
6380 . config -cursor watch
6384 set busyname($what) $name
6386 $statusw conf -text $name
6390 proc notbusy {what} {
6391 global isbusy maincursor textcursor busyname statusw
6395 if {$busyname($what) ne {} &&
6396 [$statusw cget -text] eq $busyname($what)} {
6397 $statusw conf -text {}
6400 if {[array names isbusy] eq {}} {
6401 . config -cursor $maincursor
6402 settextcursor $textcursor
6406 proc findmatches {f} {
6407 global findtype findstring
6408 if {$findtype == [mc "Regexp"]} {
6409 set matches [regexp -indices -all -inline $findstring $f]
6412 if {$findtype == [mc "IgnCase"]} {
6413 set f [string tolower $f]
6414 set fs [string tolower $fs]
6418 set l [string length $fs]
6419 while {[set j [string first $fs $f $i]] >= 0} {
6420 lappend matches [list $j [expr {$j+$l-1}]]
6421 set i [expr {$j + $l}]
6427 proc dofind {{dirn 1} {wrap 1}} {
6428 global findstring findstartline findcurline selectedline numcommits
6429 global gdttype filehighlight fh_serial find_dirn findallowwrap
6431 if {[info exists find_dirn]} {
6432 if {$find_dirn == $dirn} return
6436 if {$findstring eq {} || $numcommits == 0} return
6437 if {$selectedline eq {}} {
6438 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6440 set findstartline $selectedline
6442 set findcurline $findstartline
6443 nowbusy finding [mc "Searching"]
6444 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6445 after cancel do_file_hl $fh_serial
6446 do_file_hl $fh_serial
6449 set findallowwrap $wrap
6453 proc stopfinding {} {
6454 global find_dirn findcurline fprogcoord
6456 if {[info exists find_dirn]} {
6467 global commitdata commitinfo numcommits findpattern findloc
6468 global findstartline findcurline findallowwrap
6469 global find_dirn gdttype fhighlights fprogcoord
6470 global curview varcorder vrownum varccommits vrowmod
6472 if {![info exists find_dirn]} {
6475 set fldtypes [list [mc "Headline"] [mc "Author"] [mc "Date"] [mc "Committer"] [mc "CDate"] [mc "Comments"]]
6478 if {$find_dirn > 0} {
6480 if {$l >= $numcommits} {
6483 if {$l <= $findstartline} {
6484 set lim [expr {$findstartline + 1}]
6487 set moretodo $findallowwrap
6494 if {$l >= $findstartline} {
6495 set lim [expr {$findstartline - 1}]
6498 set moretodo $findallowwrap
6501 set n [expr {($lim - $l) * $find_dirn}]
6506 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6507 update_arcrows $curview
6511 set ai [bsearch $vrownum($curview) $l]
6512 set a [lindex $varcorder($curview) $ai]
6513 set arow [lindex $vrownum($curview) $ai]
6514 set ids [lindex $varccommits($curview,$a)]
6515 set arowend [expr {$arow + [llength $ids]}]
6516 if {$gdttype eq [mc "containing:"]} {
6517 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6518 if {$l < $arow || $l >= $arowend} {
6520 set a [lindex $varcorder($curview) $ai]
6521 set arow [lindex $vrownum($curview) $ai]
6522 set ids [lindex $varccommits($curview,$a)]
6523 set arowend [expr {$arow + [llength $ids]}]
6525 set id [lindex $ids [expr {$l - $arow}]]
6526 # shouldn't happen unless git log doesn't give all the commits...
6527 if {![info exists commitdata($id)] ||
6528 ![doesmatch $commitdata($id)]} {
6531 if {![info exists commitinfo($id)]} {
6534 set info $commitinfo($id)
6535 foreach f $info ty $fldtypes {
6536 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6545 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6546 if {$l < $arow || $l >= $arowend} {
6548 set a [lindex $varcorder($curview) $ai]
6549 set arow [lindex $vrownum($curview) $ai]
6550 set ids [lindex $varccommits($curview,$a)]
6551 set arowend [expr {$arow + [llength $ids]}]
6553 set id [lindex $ids [expr {$l - $arow}]]
6554 if {![info exists fhighlights($id)]} {
6555 # this sets fhighlights($id) to -1
6556 askfilehighlight $l $id
6558 if {$fhighlights($id) > 0} {
6562 if {$fhighlights($id) < 0} {
6565 set findcurline [expr {$l - $find_dirn}]
6570 if {$found || ($domore && !$moretodo)} {
6586 set findcurline [expr {$l - $find_dirn}]
6588 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6592 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6597 proc findselectline {l} {
6598 global findloc commentend ctext findcurline markingmatches gdttype
6600 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6603 if {$markingmatches &&
6604 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6605 # highlight the matches in the comments
6606 set f [$ctext get 1.0 $commentend]
6607 set matches [findmatches $f]
6608 foreach match $matches {
6609 set start [lindex $match 0]
6610 set end [expr {[lindex $match 1] + 1}]
6611 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6617 # mark the bits of a headline or author that match a find string
6618 proc markmatches {canv l str tag matches font row} {
6621 set bbox [$canv bbox $tag]
6622 set x0 [lindex $bbox 0]
6623 set y0 [lindex $bbox 1]
6624 set y1 [lindex $bbox 3]
6625 foreach match $matches {
6626 set start [lindex $match 0]
6627 set end [lindex $match 1]
6628 if {$start > $end} continue
6629 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6630 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6631 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6632 [expr {$x0+$xlen+2}] $y1 \
6633 -outline {} -tags [list match$l matches] -fill yellow]
6635 if {$row == $selectedline} {
6636 $canv raise $t secsel
6641 proc unmarkmatches {} {
6642 global markingmatches
6644 allcanvs delete matches
6645 set markingmatches 0
6649 proc selcanvline {w x y} {
6650 global canv canvy0 ctext linespc
6652 set ymax [lindex [$canv cget -scrollregion] 3]
6653 if {$ymax == {}} return
6654 set yfrac [lindex [$canv yview] 0]
6655 set y [expr {$y + $yfrac * $ymax}]
6656 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6661 set xmax [lindex [$canv cget -scrollregion] 2]
6662 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6663 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6669 proc commit_descriptor {p} {
6671 if {![info exists commitinfo($p)]} {
6675 if {[llength $commitinfo($p)] > 1} {
6676 set l [lindex $commitinfo($p) 0]
6681 # append some text to the ctext widget, and make any SHA1 ID
6682 # that we know about be a clickable link.
6683 proc appendwithlinks {text tags} {
6684 global ctext linknum curview
6686 set start [$ctext index "end - 1c"]
6687 $ctext insert end $text $tags
6688 set links [regexp -indices -all -inline {\m[0-9a-f]{6,40}\M} $text]
6692 set linkid [string range $text $s $e]
6694 $ctext tag delete link$linknum
6695 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6696 setlink $linkid link$linknum
6701 proc setlink {id lk} {
6702 global curview ctext pendinglinks
6705 if {[string length $id] < 40} {
6706 set matches [longid $id]
6707 if {[llength $matches] > 0} {
6708 if {[llength $matches] > 1} return
6710 set id [lindex $matches 0]
6713 set known [commitinview $id $curview]
6716 $ctext tag conf $lk -foreground blue -underline 1
6717 $ctext tag bind $lk <1> [list selbyid $id]
6718 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6719 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6721 lappend pendinglinks($id) $lk
6722 interestedin $id {makelink %P}
6726 proc appendshortlink {id {pre {}} {post {}}} {
6727 global ctext linknum
6729 $ctext insert end $pre
6730 $ctext tag delete link$linknum
6731 $ctext insert end [string range $id 0 7] link$linknum
6732 $ctext insert end $post
6733 setlink $id link$linknum
6737 proc makelink {id} {
6740 if {![info exists pendinglinks($id)]} return
6741 foreach lk $pendinglinks($id) {
6744 unset pendinglinks($id)
6747 proc linkcursor {w inc} {
6748 global linkentercount curtextcursor
6750 if {[incr linkentercount $inc] > 0} {
6751 $w configure -cursor hand2
6753 $w configure -cursor $curtextcursor
6754 if {$linkentercount < 0} {
6755 set linkentercount 0
6760 proc viewnextline {dir} {
6764 set ymax [lindex [$canv cget -scrollregion] 3]
6765 set wnow [$canv yview]
6766 set wtop [expr {[lindex $wnow 0] * $ymax}]
6767 set newtop [expr {$wtop + $dir * $linespc}]
6770 } elseif {$newtop > $ymax} {
6773 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6776 # add a list of tag or branch names at position pos
6777 # returns the number of names inserted
6778 proc appendrefs {pos ids var} {
6779 global ctext linknum curview $var maxrefs
6781 if {[catch {$ctext index $pos}]} {
6784 $ctext conf -state normal
6785 $ctext delete $pos "$pos lineend"
6788 foreach tag [set $var\($id\)] {
6789 lappend tags [list $tag $id]
6792 if {[llength $tags] > $maxrefs} {
6793 $ctext insert $pos "[mc "many"] ([llength $tags])"
6795 set tags [lsort -index 0 -decreasing $tags]
6798 set id [lindex $ti 1]
6801 $ctext tag delete $lk
6802 $ctext insert $pos $sep
6803 $ctext insert $pos [lindex $ti 0] $lk
6808 $ctext conf -state disabled
6809 return [llength $tags]
6812 # called when we have finished computing the nearby tags
6813 proc dispneartags {delay} {
6814 global selectedline currentid showneartags tagphase
6816 if {$selectedline eq {} || !$showneartags} return
6817 after cancel dispnexttag
6819 after 200 dispnexttag
6822 after idle dispnexttag
6827 proc dispnexttag {} {
6828 global selectedline currentid showneartags tagphase ctext
6830 if {$selectedline eq {} || !$showneartags} return
6831 switch -- $tagphase {
6833 set dtags [desctags $currentid]
6835 appendrefs precedes $dtags idtags
6839 set atags [anctags $currentid]
6841 appendrefs follows $atags idtags
6845 set dheads [descheads $currentid]
6846 if {$dheads ne {}} {
6847 if {[appendrefs branch $dheads idheads] > 1
6848 && [$ctext get "branch -3c"] eq "h"} {
6849 # turn "Branch" into "Branches"
6850 $ctext conf -state normal
6851 $ctext insert "branch -2c" "es"
6852 $ctext conf -state disabled
6857 if {[incr tagphase] <= 2} {
6858 after idle dispnexttag
6862 proc make_secsel {id} {
6863 global linehtag linentag linedtag canv canv2 canv3
6865 if {![info exists linehtag($id)]} return
6867 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
6868 -tags secsel -fill [$canv cget -selectbackground]]
6870 $canv2 delete secsel
6871 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
6872 -tags secsel -fill [$canv2 cget -selectbackground]]
6874 $canv3 delete secsel
6875 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
6876 -tags secsel -fill [$canv3 cget -selectbackground]]
6880 proc make_idmark {id} {
6881 global linehtag canv fgcolor
6883 if {![info exists linehtag($id)]} return
6885 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
6886 -tags markid -outline $fgcolor]
6890 proc selectline {l isnew {desired_loc {}}} {
6891 global canv ctext commitinfo selectedline
6892 global canvy0 linespc parents children curview
6893 global currentid sha1entry
6894 global commentend idtags linknum
6895 global mergemax numcommits pending_select
6896 global cmitmode showneartags allcommits
6897 global targetrow targetid lastscrollrows
6898 global autoselect autosellen jump_to_here
6900 catch {unset pending_select}
6905 if {$l < 0 || $l >= $numcommits} return
6906 set id [commitonrow $l]
6911 if {$lastscrollrows < $numcommits} {
6915 set y [expr {$canvy0 + $l * $linespc}]
6916 set ymax [lindex [$canv cget -scrollregion] 3]
6917 set ytop [expr {$y - $linespc - 1}]
6918 set ybot [expr {$y + $linespc + 1}]
6919 set wnow [$canv yview]
6920 set wtop [expr {[lindex $wnow 0] * $ymax}]
6921 set wbot [expr {[lindex $wnow 1] * $ymax}]
6922 set wh [expr {$wbot - $wtop}]
6924 if {$ytop < $wtop} {
6925 if {$ybot < $wtop} {
6926 set newtop [expr {$y - $wh / 2.0}]
6929 if {$newtop > $wtop - $linespc} {
6930 set newtop [expr {$wtop - $linespc}]
6933 } elseif {$ybot > $wbot} {
6934 if {$ytop > $wbot} {
6935 set newtop [expr {$y - $wh / 2.0}]
6937 set newtop [expr {$ybot - $wh}]
6938 if {$newtop < $wtop + $linespc} {
6939 set newtop [expr {$wtop + $linespc}]
6943 if {$newtop != $wtop} {
6947 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6954 addtohistory [list selbyid $id 0] savecmitpos
6957 $sha1entry delete 0 end
6958 $sha1entry insert 0 $id
6960 $sha1entry selection range 0 $autosellen
6964 $ctext conf -state normal
6967 if {![info exists commitinfo($id)]} {
6970 set info $commitinfo($id)
6971 set date [formatdate [lindex $info 2]]
6972 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
6973 set date [formatdate [lindex $info 4]]
6974 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
6975 if {[info exists idtags($id)]} {
6976 $ctext insert end [mc "Tags:"]
6977 foreach tag $idtags($id) {
6978 $ctext insert end " $tag"
6980 $ctext insert end "\n"
6984 set olds $parents($curview,$id)
6985 if {[llength $olds] > 1} {
6988 if {$np >= $mergemax} {
6993 $ctext insert end "[mc "Parent"]: " $tag
6994 appendwithlinks [commit_descriptor $p] {}
6999 append headers "[mc "Parent"]: [commit_descriptor $p]"
7003 foreach c $children($curview,$id) {
7004 append headers "[mc "Child"]: [commit_descriptor $c]"
7007 # make anything that looks like a SHA1 ID be a clickable link
7008 appendwithlinks $headers {}
7009 if {$showneartags} {
7010 if {![info exists allcommits]} {
7013 $ctext insert end "[mc "Branch"]: "
7014 $ctext mark set branch "end -1c"
7015 $ctext mark gravity branch left
7016 $ctext insert end "\n[mc "Follows"]: "
7017 $ctext mark set follows "end -1c"
7018 $ctext mark gravity follows left
7019 $ctext insert end "\n[mc "Precedes"]: "
7020 $ctext mark set precedes "end -1c"
7021 $ctext mark gravity precedes left
7022 $ctext insert end "\n"
7025 $ctext insert end "\n"
7026 set comment [lindex $info 5]
7027 if {[string first "\r" $comment] >= 0} {
7028 set comment [string map {"\r" "\n "} $comment]
7030 appendwithlinks $comment {comment}
7032 $ctext tag remove found 1.0 end
7033 $ctext conf -state disabled
7034 set commentend [$ctext index "end - 1c"]
7036 set jump_to_here $desired_loc
7037 init_flist [mc "Comments"]
7038 if {$cmitmode eq "tree"} {
7040 } elseif {[llength $olds] <= 1} {
7047 proc selfirstline {} {
7052 proc sellastline {} {
7055 set l [expr {$numcommits - 1}]
7059 proc selnextline {dir} {
7062 if {$selectedline eq {}} return
7063 set l [expr {$selectedline + $dir}]
7068 proc selnextpage {dir} {
7069 global canv linespc selectedline numcommits
7071 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7075 allcanvs yview scroll [expr {$dir * $lpp}] units
7077 if {$selectedline eq {}} return
7078 set l [expr {$selectedline + $dir * $lpp}]
7081 } elseif {$l >= $numcommits} {
7082 set l [expr $numcommits - 1]
7088 proc unselectline {} {
7089 global selectedline currentid
7092 catch {unset currentid}
7093 allcanvs delete secsel
7097 proc reselectline {} {
7100 if {$selectedline ne {}} {
7101 selectline $selectedline 0
7105 proc addtohistory {cmd {saveproc {}}} {
7106 global history historyindex curview
7110 set elt [list $curview $cmd $saveproc {}]
7111 if {$historyindex > 0
7112 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7116 if {$historyindex < [llength $history]} {
7117 set history [lreplace $history $historyindex end $elt]
7119 lappend history $elt
7122 if {$historyindex > 1} {
7123 .tf.bar.leftbut conf -state normal
7125 .tf.bar.leftbut conf -state disabled
7127 .tf.bar.rightbut conf -state disabled
7130 # save the scrolling position of the diff display pane
7131 proc save_position {} {
7132 global historyindex history
7134 if {$historyindex < 1} return
7135 set hi [expr {$historyindex - 1}]
7136 set fn [lindex $history $hi 2]
7138 lset history $hi 3 [eval $fn]
7142 proc unset_posvars {} {
7145 if {[info exists last_posvars]} {
7146 foreach {var val} $last_posvars {
7155 global curview last_posvars
7157 set view [lindex $elt 0]
7158 set cmd [lindex $elt 1]
7159 set pv [lindex $elt 3]
7160 if {$curview != $view} {
7164 foreach {var val} $pv {
7168 set last_posvars $pv
7173 global history historyindex
7176 if {$historyindex > 1} {
7178 incr historyindex -1
7179 godo [lindex $history [expr {$historyindex - 1}]]
7180 .tf.bar.rightbut conf -state normal
7182 if {$historyindex <= 1} {
7183 .tf.bar.leftbut conf -state disabled
7188 global history historyindex
7191 if {$historyindex < [llength $history]} {
7193 set cmd [lindex $history $historyindex]
7196 .tf.bar.leftbut conf -state normal
7198 if {$historyindex >= [llength $history]} {
7199 .tf.bar.rightbut conf -state disabled
7204 global treefilelist treeidlist diffids diffmergeid treepending
7205 global nullid nullid2
7208 catch {unset diffmergeid}
7209 if {![info exists treefilelist($id)]} {
7210 if {![info exists treepending]} {
7211 if {$id eq $nullid} {
7212 set cmd [list | git ls-files]
7213 } elseif {$id eq $nullid2} {
7214 set cmd [list | git ls-files --stage -t]
7216 set cmd [list | git ls-tree -r $id]
7218 if {[catch {set gtf [open $cmd r]}]} {
7222 set treefilelist($id) {}
7223 set treeidlist($id) {}
7224 fconfigure $gtf -blocking 0 -encoding binary
7225 filerun $gtf [list gettreeline $gtf $id]
7232 proc gettreeline {gtf id} {
7233 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7236 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7237 if {$diffids eq $nullid} {
7240 set i [string first "\t" $line]
7241 if {$i < 0} continue
7242 set fname [string range $line [expr {$i+1}] end]
7243 set line [string range $line 0 [expr {$i-1}]]
7244 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7245 set sha1 [lindex $line 2]
7246 lappend treeidlist($id) $sha1
7248 if {[string index $fname 0] eq "\""} {
7249 set fname [lindex $fname 0]
7251 set fname [encoding convertfrom $fname]
7252 lappend treefilelist($id) $fname
7255 return [expr {$nl >= 1000? 2: 1}]
7259 if {$cmitmode ne "tree"} {
7260 if {![info exists diffmergeid]} {
7261 gettreediffs $diffids
7263 } elseif {$id ne $diffids} {
7272 global treefilelist treeidlist diffids nullid nullid2
7273 global ctext_file_names ctext_file_lines
7274 global ctext commentend
7276 set i [lsearch -exact $treefilelist($diffids) $f]
7278 puts "oops, $f not in list for id $diffids"
7281 if {$diffids eq $nullid} {
7282 if {[catch {set bf [open $f r]} err]} {
7283 puts "oops, can't read $f: $err"
7287 set blob [lindex $treeidlist($diffids) $i]
7288 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7289 puts "oops, error reading blob $blob: $err"
7293 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7294 filerun $bf [list getblobline $bf $diffids]
7295 $ctext config -state normal
7296 clear_ctext $commentend
7297 lappend ctext_file_names $f
7298 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7299 $ctext insert end "\n"
7300 $ctext insert end "$f\n" filesep
7301 $ctext config -state disabled
7302 $ctext yview $commentend
7306 proc getblobline {bf id} {
7307 global diffids cmitmode ctext
7309 if {$id ne $diffids || $cmitmode ne "tree"} {
7313 $ctext config -state normal
7315 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7316 $ctext insert end "$line\n"
7319 global jump_to_here ctext_file_names commentend
7321 # delete last newline
7322 $ctext delete "end - 2c" "end - 1c"
7324 if {$jump_to_here ne {} &&
7325 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7326 set lnum [expr {[lindex $jump_to_here 1] +
7327 [lindex [split $commentend .] 0]}]
7328 mark_ctext_line $lnum
7330 $ctext config -state disabled
7333 $ctext config -state disabled
7334 return [expr {$nl >= 1000? 2: 1}]
7337 proc mark_ctext_line {lnum} {
7338 global ctext markbgcolor
7340 $ctext tag delete omark
7341 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7342 $ctext tag conf omark -background $markbgcolor
7346 proc mergediff {id} {
7348 global diffids treediffs
7349 global parents curview
7353 set treediffs($id) {}
7354 set np [llength $parents($curview,$id)]
7359 proc startdiff {ids} {
7360 global treediffs diffids treepending diffmergeid nullid nullid2
7364 catch {unset diffmergeid}
7365 if {![info exists treediffs($ids)] ||
7366 [lsearch -exact $ids $nullid] >= 0 ||
7367 [lsearch -exact $ids $nullid2] >= 0} {
7368 if {![info exists treepending]} {
7376 proc path_filter {filter name} {
7378 set l [string length $p]
7379 if {[string index $p end] eq "/"} {
7380 if {[string compare -length $l $p $name] == 0} {
7384 if {[string compare -length $l $p $name] == 0 &&
7385 ([string length $name] == $l ||
7386 [string index $name $l] eq "/")} {
7394 proc addtocflist {ids} {
7397 add_flist $treediffs($ids)
7401 proc diffcmd {ids flags} {
7402 global nullid nullid2
7404 set i [lsearch -exact $ids $nullid]
7405 set j [lsearch -exact $ids $nullid2]
7407 if {[llength $ids] > 1 && $j < 0} {
7408 # comparing working directory with some specific revision
7409 set cmd [concat | git diff-index $flags]
7411 lappend cmd -R [lindex $ids 1]
7413 lappend cmd [lindex $ids 0]
7416 # comparing working directory with index
7417 set cmd [concat | git diff-files $flags]
7422 } elseif {$j >= 0} {
7423 set cmd [concat | git diff-index --cached $flags]
7424 if {[llength $ids] > 1} {
7425 # comparing index with specific revision
7427 lappend cmd -R [lindex $ids 1]
7429 lappend cmd [lindex $ids 0]
7432 # comparing index with HEAD
7436 set cmd [concat | git diff-tree -r $flags $ids]
7441 proc gettreediffs {ids} {
7442 global treediff treepending
7444 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
7446 set treepending $ids
7448 fconfigure $gdtf -blocking 0 -encoding binary
7449 filerun $gdtf [list gettreediffline $gdtf $ids]
7452 proc gettreediffline {gdtf ids} {
7453 global treediff treediffs treepending diffids diffmergeid
7454 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7459 if {$perfile_attrs} {
7460 # cache_gitattr is slow, and even slower on win32 where we
7461 # have to invoke it for only about 30 paths at a time
7463 if {[tk windowingsystem] == "win32"} {
7467 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7468 set i [string first "\t" $line]
7470 set file [string range $line [expr {$i+1}] end]
7471 if {[string index $file 0] eq "\""} {
7472 set file [lindex $file 0]
7474 set file [encoding convertfrom $file]
7475 if {$file ne [lindex $treediff end]} {
7476 lappend treediff $file
7477 lappend sublist $file
7481 if {$perfile_attrs} {
7482 cache_gitattr encoding $sublist
7485 return [expr {$nr >= $max? 2: 1}]
7488 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7490 foreach f $treediff {
7491 if {[path_filter $vfilelimit($curview) $f]} {
7495 set treediffs($ids) $flist
7497 set treediffs($ids) $treediff
7500 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7502 } elseif {$ids != $diffids} {
7503 if {![info exists diffmergeid]} {
7504 gettreediffs $diffids
7512 # empty string or positive integer
7513 proc diffcontextvalidate {v} {
7514 return [regexp {^(|[1-9][0-9]*)$} $v]
7517 proc diffcontextchange {n1 n2 op} {
7518 global diffcontextstring diffcontext
7520 if {[string is integer -strict $diffcontextstring]} {
7521 if {$diffcontextstring >= 0} {
7522 set diffcontext $diffcontextstring
7528 proc changeignorespace {} {
7532 proc changeworddiff {name ix op} {
7536 proc getblobdiffs {ids} {
7537 global blobdifffd diffids env
7538 global diffinhdr treediffs
7542 global limitdiffs vfilelimit curview
7543 global diffencoding targetline diffnparents
7544 global git_version currdiffsubmod
7547 if {[package vcompare $git_version "1.6.1"] >= 0} {
7548 set textconv "--textconv"
7551 if {[package vcompare $git_version "1.6.6"] >= 0} {
7552 set submodule "--submodule"
7554 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7558 if {$worddiff ne [mc "Line diff"]} {
7559 append cmd " --word-diff=porcelain"
7561 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7562 set cmd [concat $cmd -- $vfilelimit($curview)]
7564 if {[catch {set bdf [open $cmd r]} err]} {
7565 error_popup [mc "Error getting diffs: %s" $err]
7571 set diffencoding [get_path_encoding {}]
7572 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7573 set blobdifffd($ids) $bdf
7574 set currdiffsubmod ""
7575 filerun $bdf [list getblobdiffline $bdf $diffids]
7578 proc savecmitpos {} {
7579 global ctext cmitmode
7581 if {$cmitmode eq "tree"} {
7584 return [list target_scrollpos [$ctext index @0,0]]
7587 proc savectextpos {} {
7590 return [list target_scrollpos [$ctext index @0,0]]
7593 proc maybe_scroll_ctext {ateof} {
7594 global ctext target_scrollpos
7596 if {![info exists target_scrollpos]} return
7598 set nlines [expr {[winfo height $ctext]
7599 / [font metrics textfont -linespace]}]
7600 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7602 $ctext yview $target_scrollpos
7603 unset target_scrollpos
7606 proc setinlist {var i val} {
7609 while {[llength [set $var]] < $i} {
7612 if {[llength [set $var]] == $i} {
7619 proc makediffhdr {fname ids} {
7620 global ctext curdiffstart treediffs diffencoding
7621 global ctext_file_names jump_to_here targetline diffline
7623 set fname [encoding convertfrom $fname]
7624 set diffencoding [get_path_encoding $fname]
7625 set i [lsearch -exact $treediffs($ids) $fname]
7627 setinlist difffilestart $i $curdiffstart
7629 lset ctext_file_names end $fname
7630 set l [expr {(78 - [string length $fname]) / 2}]
7631 set pad [string range "----------------------------------------" 1 $l]
7632 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7634 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7635 set targetline [lindex $jump_to_here 1]
7640 proc getblobdiffline {bdf ids} {
7641 global diffids blobdifffd ctext curdiffstart
7642 global diffnexthead diffnextnote difffilestart
7643 global ctext_file_names ctext_file_lines
7644 global diffinhdr treediffs mergemax diffnparents
7645 global diffencoding jump_to_here targetline diffline currdiffsubmod
7649 $ctext conf -state normal
7650 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7651 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7655 if {![string compare -length 5 "diff " $line]} {
7656 if {![regexp {^diff (--cc|--git) } $line m type]} {
7657 set line [encoding convertfrom $line]
7658 $ctext insert end "$line\n" hunksep
7661 # start of a new file
7663 $ctext insert end "\n"
7664 set curdiffstart [$ctext index "end - 1c"]
7665 lappend ctext_file_names ""
7666 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7667 $ctext insert end "\n" filesep
7669 if {$type eq "--cc"} {
7670 # start of a new file in a merge diff
7671 set fname [string range $line 10 end]
7672 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7673 lappend treediffs($ids) $fname
7674 add_flist [list $fname]
7678 set line [string range $line 11 end]
7679 # If the name hasn't changed the length will be odd,
7680 # the middle char will be a space, and the two bits either
7681 # side will be a/name and b/name, or "a/name" and "b/name".
7682 # If the name has changed we'll get "rename from" and
7683 # "rename to" or "copy from" and "copy to" lines following
7684 # this, and we'll use them to get the filenames.
7685 # This complexity is necessary because spaces in the
7686 # filename(s) don't get escaped.
7687 set l [string length $line]
7688 set i [expr {$l / 2}]
7689 if {!(($l & 1) && [string index $line $i] eq " " &&
7690 [string range $line 2 [expr {$i - 1}]] eq \
7691 [string range $line [expr {$i + 3}] end])} {
7694 # unescape if quoted and chop off the a/ from the front
7695 if {[string index $line 0] eq "\""} {
7696 set fname [string range [lindex $line 0] 2 end]
7698 set fname [string range $line 2 [expr {$i - 1}]]
7701 makediffhdr $fname $ids
7703 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7704 set fname [encoding convertfrom [string range $line 16 end]]
7705 $ctext insert end "\n"
7706 set curdiffstart [$ctext index "end - 1c"]
7707 lappend ctext_file_names $fname
7708 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7709 $ctext insert end "$line\n" filesep
7710 set i [lsearch -exact $treediffs($ids) $fname]
7712 setinlist difffilestart $i $curdiffstart
7715 } elseif {![string compare -length 2 "@@" $line]} {
7716 regexp {^@@+} $line ats
7717 set line [encoding convertfrom $diffencoding $line]
7718 $ctext insert end "$line\n" hunksep
7719 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7722 set diffnparents [expr {[string length $ats] - 1}]
7725 } elseif {![string compare -length 10 "Submodule " $line]} {
7726 # start of a new submodule
7727 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7728 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7730 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7732 if {$currdiffsubmod != $fname} {
7733 $ctext insert end "\n"; # Add newline after commit message
7735 set curdiffstart [$ctext index "end - 1c"]
7736 lappend ctext_file_names ""
7737 if {$currdiffsubmod != $fname} {
7738 lappend ctext_file_lines $fname
7739 makediffhdr $fname $ids
7740 set currdiffsubmod $fname
7741 $ctext insert end "\n$line\n" filesep
7743 $ctext insert end "$line\n" filesep
7745 } elseif {![string compare -length 3 " >" $line]} {
7746 set $currdiffsubmod ""
7747 set line [encoding convertfrom $diffencoding $line]
7748 $ctext insert end "$line\n" dresult
7749 } elseif {![string compare -length 3 " <" $line]} {
7750 set $currdiffsubmod ""
7751 set line [encoding convertfrom $diffencoding $line]
7752 $ctext insert end "$line\n" d0
7753 } elseif {$diffinhdr} {
7754 if {![string compare -length 12 "rename from " $line]} {
7755 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7756 if {[string index $fname 0] eq "\""} {
7757 set fname [lindex $fname 0]
7759 set fname [encoding convertfrom $fname]
7760 set i [lsearch -exact $treediffs($ids) $fname]
7762 setinlist difffilestart $i $curdiffstart
7764 } elseif {![string compare -length 10 $line "rename to "] ||
7765 ![string compare -length 8 $line "copy to "]} {
7766 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7767 if {[string index $fname 0] eq "\""} {
7768 set fname [lindex $fname 0]
7770 makediffhdr $fname $ids
7771 } elseif {[string compare -length 3 $line "---"] == 0} {
7774 } elseif {[string compare -length 3 $line "+++"] == 0} {
7778 $ctext insert end "$line\n" filesep
7781 set line [string map {\x1A ^Z} \
7782 [encoding convertfrom $diffencoding $line]]
7783 # parse the prefix - one ' ', '-' or '+' for each parent
7784 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7785 set tag [expr {$diffnparents > 1? "m": "d"}]
7786 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7787 set words_pre_markup ""
7788 set words_post_markup ""
7789 if {[string trim $prefix " -+"] eq {}} {
7790 # prefix only has " ", "-" and "+" in it: normal diff line
7791 set num [string first "-" $prefix]
7793 set line [string range $line 1 end]
7796 # removed line, first parent with line is $num
7797 if {$num >= $mergemax} {
7800 if {$dowords && $worddiff eq [mc "Markup words"]} {
7801 $ctext insert end "\[-$line-\]" $tag$num
7803 $ctext insert end "$line" $tag$num
7806 $ctext insert end "\n" $tag$num
7810 if {[string first "+" $prefix] >= 0} {
7812 lappend tags ${tag}result
7813 if {$diffnparents > 1} {
7814 set num [string first " " $prefix]
7816 if {$num >= $mergemax} {
7822 set words_pre_markup "{+"
7823 set words_post_markup "+}"
7825 if {$targetline ne {}} {
7826 if {$diffline == $targetline} {
7827 set seehere [$ctext index "end - 1 chars"]
7833 if {$dowords && $worddiff eq [mc "Markup words"]} {
7834 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
7836 $ctext insert end "$line" $tags
7839 $ctext insert end "\n" $tags
7842 } elseif {$dowords && $prefix eq "~"} {
7843 $ctext insert end "\n" {}
7845 # "\ No newline at end of file",
7846 # or something else we don't recognize
7847 $ctext insert end "$line\n" hunksep
7851 if {[info exists seehere]} {
7852 mark_ctext_line [lindex [split $seehere .] 0]
7854 maybe_scroll_ctext [eof $bdf]
7855 $ctext conf -state disabled
7860 return [expr {$nr >= 1000? 2: 1}]
7863 proc changediffdisp {} {
7864 global ctext diffelide
7866 $ctext tag conf d0 -elide [lindex $diffelide 0]
7867 $ctext tag conf dresult -elide [lindex $diffelide 1]
7870 proc highlightfile {loc cline} {
7871 global ctext cflist cflist_top
7874 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
7875 $cflist tag add highlight $cline.0 "$cline.0 lineend"
7876 $cflist see $cline.0
7877 set cflist_top $cline
7881 global difffilestart ctext cmitmode
7883 if {$cmitmode eq "tree"} return
7886 set here [$ctext index @0,0]
7887 foreach loc $difffilestart {
7888 if {[$ctext compare $loc >= $here]} {
7889 highlightfile $prev $prevline
7895 highlightfile $prev $prevline
7899 global difffilestart ctext cmitmode
7901 if {$cmitmode eq "tree"} return
7902 set here [$ctext index @0,0]
7904 foreach loc $difffilestart {
7906 if {[$ctext compare $loc > $here]} {
7907 highlightfile $loc $line
7913 proc clear_ctext {{first 1.0}} {
7914 global ctext smarktop smarkbot
7915 global ctext_file_names ctext_file_lines
7918 set l [lindex [split $first .] 0]
7919 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
7922 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
7925 $ctext delete $first end
7926 if {$first eq "1.0"} {
7927 catch {unset pendinglinks}
7929 set ctext_file_names {}
7930 set ctext_file_lines {}
7933 proc settabs {{firstab {}}} {
7934 global firsttabstop tabstop ctext have_tk85
7936 if {$firstab ne {} && $have_tk85} {
7937 set firsttabstop $firstab
7939 set w [font measure textfont "0"]
7940 if {$firsttabstop != 0} {
7941 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
7942 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
7943 } elseif {$have_tk85 || $tabstop != 8} {
7944 $ctext conf -tabs [expr {$tabstop * $w}]
7946 $ctext conf -tabs {}
7950 proc incrsearch {name ix op} {
7951 global ctext searchstring searchdirn
7953 $ctext tag remove found 1.0 end
7954 if {[catch {$ctext index anchor}]} {
7955 # no anchor set, use start of selection, or of visible area
7956 set sel [$ctext tag ranges sel]
7958 $ctext mark set anchor [lindex $sel 0]
7959 } elseif {$searchdirn eq "-forwards"} {
7960 $ctext mark set anchor @0,0
7962 $ctext mark set anchor @0,[winfo height $ctext]
7965 if {$searchstring ne {}} {
7966 set here [$ctext search $searchdirn -- $searchstring anchor]
7975 global sstring ctext searchstring searchdirn
7978 $sstring icursor end
7979 set searchdirn -forwards
7980 if {$searchstring ne {}} {
7981 set sel [$ctext tag ranges sel]
7983 set start "[lindex $sel 0] + 1c"
7984 } elseif {[catch {set start [$ctext index anchor]}]} {
7987 set match [$ctext search -count mlen -- $searchstring $start]
7988 $ctext tag remove sel 1.0 end
7994 set mend "$match + $mlen c"
7995 $ctext tag add sel $match $mend
7996 $ctext mark unset anchor
8000 proc dosearchback {} {
8001 global sstring ctext searchstring searchdirn
8004 $sstring icursor end
8005 set searchdirn -backwards
8006 if {$searchstring ne {}} {
8007 set sel [$ctext tag ranges sel]
8009 set start [lindex $sel 0]
8010 } elseif {[catch {set start [$ctext index anchor]}]} {
8011 set start @0,[winfo height $ctext]
8013 set match [$ctext search -backwards -count ml -- $searchstring $start]
8014 $ctext tag remove sel 1.0 end
8020 set mend "$match + $ml c"
8021 $ctext tag add sel $match $mend
8022 $ctext mark unset anchor
8026 proc searchmark {first last} {
8027 global ctext searchstring
8031 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8032 if {$match eq {}} break
8033 set mend "$match + $mlen c"
8034 $ctext tag add found $match $mend
8038 proc searchmarkvisible {doall} {
8039 global ctext smarktop smarkbot
8041 set topline [lindex [split [$ctext index @0,0] .] 0]
8042 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8043 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8044 # no overlap with previous
8045 searchmark $topline $botline
8046 set smarktop $topline
8047 set smarkbot $botline
8049 if {$topline < $smarktop} {
8050 searchmark $topline [expr {$smarktop-1}]
8051 set smarktop $topline
8053 if {$botline > $smarkbot} {
8054 searchmark [expr {$smarkbot+1}] $botline
8055 set smarkbot $botline
8060 proc scrolltext {f0 f1} {
8063 .bleft.bottom.sb set $f0 $f1
8064 if {$searchstring ne {}} {
8070 global linespc charspc canvx0 canvy0
8071 global xspc1 xspc2 lthickness
8073 set linespc [font metrics mainfont -linespace]
8074 set charspc [font measure mainfont "m"]
8075 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8076 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8077 set lthickness [expr {int($linespc / 9) + 1}]
8078 set xspc1(0) $linespc
8086 set ymax [lindex [$canv cget -scrollregion] 3]
8087 if {$ymax eq {} || $ymax == 0} return
8088 set span [$canv yview]
8091 allcanvs yview moveto [lindex $span 0]
8093 if {$selectedline ne {}} {
8094 selectline $selectedline 0
8095 allcanvs yview moveto [lindex $span 0]
8099 proc parsefont {f n} {
8102 set fontattr($f,family) [lindex $n 0]
8104 if {$s eq {} || $s == 0} {
8107 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8109 set fontattr($f,size) $s
8110 set fontattr($f,weight) normal
8111 set fontattr($f,slant) roman
8112 foreach style [lrange $n 2 end] {
8115 "bold" {set fontattr($f,weight) $style}
8117 "italic" {set fontattr($f,slant) $style}
8122 proc fontflags {f {isbold 0}} {
8125 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8126 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8127 -slant $fontattr($f,slant)]
8133 set n [list $fontattr($f,family) $fontattr($f,size)]
8134 if {$fontattr($f,weight) eq "bold"} {
8137 if {$fontattr($f,slant) eq "italic"} {
8143 proc incrfont {inc} {
8144 global mainfont textfont ctext canv cflist showrefstop
8145 global stopped entries fontattr
8148 set s $fontattr(mainfont,size)
8153 set fontattr(mainfont,size) $s
8154 font config mainfont -size $s
8155 font config mainfontbold -size $s
8156 set mainfont [fontname mainfont]
8157 set s $fontattr(textfont,size)
8162 set fontattr(textfont,size) $s
8163 font config textfont -size $s
8164 font config textfontbold -size $s
8165 set textfont [fontname textfont]
8172 global sha1entry sha1string
8173 if {[string length $sha1string] == 40} {
8174 $sha1entry delete 0 end
8178 proc sha1change {n1 n2 op} {
8179 global sha1string currentid sha1but
8180 if {$sha1string == {}
8181 || ([info exists currentid] && $sha1string == $currentid)} {
8186 if {[$sha1but cget -state] == $state} return
8187 if {$state == "normal"} {
8188 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8190 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8194 proc gotocommit {} {
8195 global sha1string tagids headids curview varcid
8197 if {$sha1string == {}
8198 || ([info exists currentid] && $sha1string == $currentid)} return
8199 if {[info exists tagids($sha1string)]} {
8200 set id $tagids($sha1string)
8201 } elseif {[info exists headids($sha1string)]} {
8202 set id $headids($sha1string)
8204 set id [string tolower $sha1string]
8205 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8206 set matches [longid $id]
8207 if {$matches ne {}} {
8208 if {[llength $matches] > 1} {
8209 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8212 set id [lindex $matches 0]
8215 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8216 error_popup [mc "Revision %s is not known" $sha1string]
8221 if {[commitinview $id $curview]} {
8222 selectline [rowofcommit $id] 1
8225 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8226 set msg [mc "SHA1 id %s is not known" $sha1string]
8228 set msg [mc "Revision %s is not in the current view" $sha1string]
8233 proc lineenter {x y id} {
8234 global hoverx hovery hoverid hovertimer
8235 global commitinfo canv
8237 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8241 if {[info exists hovertimer]} {
8242 after cancel $hovertimer
8244 set hovertimer [after 500 linehover]
8248 proc linemotion {x y id} {
8249 global hoverx hovery hoverid hovertimer
8251 if {[info exists hoverid] && $id == $hoverid} {
8254 if {[info exists hovertimer]} {
8255 after cancel $hovertimer
8257 set hovertimer [after 500 linehover]
8261 proc lineleave {id} {
8262 global hoverid hovertimer canv
8264 if {[info exists hoverid] && $id == $hoverid} {
8266 if {[info exists hovertimer]} {
8267 after cancel $hovertimer
8275 global hoverx hovery hoverid hovertimer
8276 global canv linespc lthickness
8279 set text [lindex $commitinfo($hoverid) 0]
8280 set ymax [lindex [$canv cget -scrollregion] 3]
8281 if {$ymax == {}} return
8282 set yfrac [lindex [$canv yview] 0]
8283 set x [expr {$hoverx + 2 * $linespc}]
8284 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8285 set x0 [expr {$x - 2 * $lthickness}]
8286 set y0 [expr {$y - 2 * $lthickness}]
8287 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8288 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8289 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8290 -fill \#ffff80 -outline black -width 1 -tags hover]
8292 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8297 proc clickisonarrow {id y} {
8300 set ranges [rowranges $id]
8301 set thresh [expr {2 * $lthickness + 6}]
8302 set n [expr {[llength $ranges] - 1}]
8303 for {set i 1} {$i < $n} {incr i} {
8304 set row [lindex $ranges $i]
8305 if {abs([yc $row] - $y) < $thresh} {
8312 proc arrowjump {id n y} {
8315 # 1 <-> 2, 3 <-> 4, etc...
8316 set n [expr {(($n - 1) ^ 1) + 1}]
8317 set row [lindex [rowranges $id] $n]
8319 set ymax [lindex [$canv cget -scrollregion] 3]
8320 if {$ymax eq {} || $ymax <= 0} return
8321 set view [$canv yview]
8322 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8323 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8327 allcanvs yview moveto $yfrac
8330 proc lineclick {x y id isnew} {
8331 global ctext commitinfo children canv thickerline curview
8333 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8338 # draw this line thicker than normal
8342 set ymax [lindex [$canv cget -scrollregion] 3]
8343 if {$ymax eq {}} return
8344 set yfrac [lindex [$canv yview] 0]
8345 set y [expr {$y + $yfrac * $ymax}]
8347 set dirn [clickisonarrow $id $y]
8349 arrowjump $id $dirn $y
8354 addtohistory [list lineclick $x $y $id 0] savectextpos
8356 # fill the details pane with info about this line
8357 $ctext conf -state normal
8360 $ctext insert end "[mc "Parent"]:\t"
8361 $ctext insert end $id link0
8363 set info $commitinfo($id)
8364 $ctext insert end "\n\t[lindex $info 0]\n"
8365 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8366 set date [formatdate [lindex $info 2]]
8367 $ctext insert end "\t[mc "Date"]:\t$date\n"
8368 set kids $children($curview,$id)
8370 $ctext insert end "\n[mc "Children"]:"
8372 foreach child $kids {
8374 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8375 set info $commitinfo($child)
8376 $ctext insert end "\n\t"
8377 $ctext insert end $child link$i
8378 setlink $child link$i
8379 $ctext insert end "\n\t[lindex $info 0]"
8380 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8381 set date [formatdate [lindex $info 2]]
8382 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8385 maybe_scroll_ctext 1
8386 $ctext conf -state disabled
8390 proc normalline {} {
8392 if {[info exists thickerline]} {
8399 proc selbyid {id {isnew 1}} {
8401 if {[commitinview $id $curview]} {
8402 selectline [rowofcommit $id] $isnew
8408 if {![info exists startmstime]} {
8409 set startmstime [clock clicks -milliseconds]
8411 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8414 proc rowmenu {x y id} {
8415 global rowctxmenu selectedline rowmenuid curview
8416 global nullid nullid2 fakerowmenu mainhead markedid
8420 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8425 if {$id ne $nullid && $id ne $nullid2} {
8426 set menu $rowctxmenu
8427 if {$mainhead ne {}} {
8428 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8430 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8432 if {[info exists markedid] && $markedid ne $id} {
8433 $menu entryconfigure 9 -state normal
8434 $menu entryconfigure 10 -state normal
8435 $menu entryconfigure 11 -state normal
8437 $menu entryconfigure 9 -state disabled
8438 $menu entryconfigure 10 -state disabled
8439 $menu entryconfigure 11 -state disabled
8442 set menu $fakerowmenu
8444 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8445 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8446 $menu entryconfigure [mca "Make patch"] -state $state
8447 tk_popup $menu $x $y
8451 global rowmenuid markedid canv
8453 set markedid $rowmenuid
8454 make_idmark $markedid
8460 if {[info exists markedid]} {
8465 proc replace_by_kids {l r} {
8466 global curview children
8468 set id [commitonrow $r]
8469 set l [lreplace $l 0 0]
8470 foreach kid $children($curview,$id) {
8471 lappend l [rowofcommit $kid]
8473 return [lsort -integer -decreasing -unique $l]
8476 proc find_common_desc {} {
8477 global markedid rowmenuid curview children
8479 if {![info exists markedid]} return
8480 if {![commitinview $markedid $curview] ||
8481 ![commitinview $rowmenuid $curview]} return
8482 #set t1 [clock clicks -milliseconds]
8483 set l1 [list [rowofcommit $markedid]]
8484 set l2 [list [rowofcommit $rowmenuid]]
8486 set r1 [lindex $l1 0]
8487 set r2 [lindex $l2 0]
8488 if {$r1 eq {} || $r2 eq {}} break
8494 set l1 [replace_by_kids $l1 $r1]
8496 set l2 [replace_by_kids $l2 $r2]
8499 #set t2 [clock clicks -milliseconds]
8500 #puts "took [expr {$t2-$t1}]ms"
8503 proc compare_commits {} {
8504 global markedid rowmenuid curview children
8506 if {![info exists markedid]} return
8507 if {![commitinview $markedid $curview]} return
8508 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8509 do_cmp_commits $markedid $rowmenuid
8512 proc getpatchid {id} {
8515 if {![info exists patchids($id)]} {
8516 set cmd [diffcmd [list $id] {-p --root}]
8517 # trim off the initial "|"
8518 set cmd [lrange $cmd 1 end]
8520 set x [eval exec $cmd | git patch-id]
8521 set patchids($id) [lindex $x 0]
8523 set patchids($id) "error"
8526 return $patchids($id)
8529 proc do_cmp_commits {a b} {
8530 global ctext curview parents children patchids commitinfo
8532 $ctext conf -state normal
8535 for {set i 0} {$i < 100} {incr i} {
8538 if {[llength $parents($curview,$a)] > 1} {
8539 appendshortlink $a [mc "Skipping merge commit "] "\n"
8542 set patcha [getpatchid $a]
8544 if {[llength $parents($curview,$b)] > 1} {
8545 appendshortlink $b [mc "Skipping merge commit "] "\n"
8548 set patchb [getpatchid $b]
8550 if {!$skipa && !$skipb} {
8551 set heada [lindex $commitinfo($a) 0]
8552 set headb [lindex $commitinfo($b) 0]
8553 if {$patcha eq "error"} {
8554 appendshortlink $a [mc "Error getting patch ID for "] \
8555 [mc " - stopping\n"]
8558 if {$patchb eq "error"} {
8559 appendshortlink $b [mc "Error getting patch ID for "] \
8560 [mc " - stopping\n"]
8563 if {$patcha eq $patchb} {
8564 if {$heada eq $headb} {
8565 appendshortlink $a [mc "Commit "]
8566 appendshortlink $b " == " " $heada\n"
8568 appendshortlink $a [mc "Commit "] " $heada\n"
8569 appendshortlink $b [mc " is the same patch as\n "] \
8575 $ctext insert end "\n"
8576 appendshortlink $a [mc "Commit "] " $heada\n"
8577 appendshortlink $b [mc " differs from\n "] \
8579 $ctext insert end [mc "Diff of commits:\n\n"]
8580 $ctext conf -state disabled
8587 set kids [real_children $curview,$a]
8588 if {[llength $kids] != 1} {
8589 $ctext insert end "\n"
8590 appendshortlink $a [mc "Commit "] \
8591 [mc " has %s children - stopping\n" [llength $kids]]
8594 set a [lindex $kids 0]
8597 set kids [real_children $curview,$b]
8598 if {[llength $kids] != 1} {
8599 appendshortlink $b [mc "Commit "] \
8600 [mc " has %s children - stopping\n" [llength $kids]]
8603 set b [lindex $kids 0]
8606 $ctext conf -state disabled
8609 proc diffcommits {a b} {
8610 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8612 set tmpdir [gitknewtmpdir]
8613 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8614 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8616 exec git diff-tree -p --pretty $a >$fna
8617 exec git diff-tree -p --pretty $b >$fnb
8619 error_popup [mc "Error writing commit to file: %s" $err]
8623 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8625 error_popup [mc "Error diffing commits: %s" $err]
8628 set diffids [list commits $a $b]
8629 set blobdifffd($diffids) $fd
8631 set currdiffsubmod ""
8632 filerun $fd [list getblobdiffline $fd $diffids]
8635 proc diffvssel {dirn} {
8636 global rowmenuid selectedline
8638 if {$selectedline eq {}} return
8640 set oldid [commitonrow $selectedline]
8641 set newid $rowmenuid
8643 set oldid $rowmenuid
8644 set newid [commitonrow $selectedline]
8646 addtohistory [list doseldiff $oldid $newid] savectextpos
8647 doseldiff $oldid $newid
8650 proc doseldiff {oldid newid} {
8654 $ctext conf -state normal
8656 init_flist [mc "Top"]
8657 $ctext insert end "[mc "From"] "
8658 $ctext insert end $oldid link0
8659 setlink $oldid link0
8660 $ctext insert end "\n "
8661 $ctext insert end [lindex $commitinfo($oldid) 0]
8662 $ctext insert end "\n\n[mc "To"] "
8663 $ctext insert end $newid link1
8664 setlink $newid link1
8665 $ctext insert end "\n "
8666 $ctext insert end [lindex $commitinfo($newid) 0]
8667 $ctext insert end "\n"
8668 $ctext conf -state disabled
8669 $ctext tag remove found 1.0 end
8670 startdiff [list $oldid $newid]
8674 global rowmenuid currentid commitinfo patchtop patchnum NS
8676 if {![info exists currentid]} return
8677 set oldid $currentid
8678 set oldhead [lindex $commitinfo($oldid) 0]
8679 set newid $rowmenuid
8680 set newhead [lindex $commitinfo($newid) 0]
8683 catch {destroy $top}
8685 make_transient $top .
8686 ${NS}::label $top.title -text [mc "Generate patch"]
8687 grid $top.title - -pady 10
8688 ${NS}::label $top.from -text [mc "From:"]
8689 ${NS}::entry $top.fromsha1 -width 40
8690 $top.fromsha1 insert 0 $oldid
8691 $top.fromsha1 conf -state readonly
8692 grid $top.from $top.fromsha1 -sticky w
8693 ${NS}::entry $top.fromhead -width 60
8694 $top.fromhead insert 0 $oldhead
8695 $top.fromhead conf -state readonly
8696 grid x $top.fromhead -sticky w
8697 ${NS}::label $top.to -text [mc "To:"]
8698 ${NS}::entry $top.tosha1 -width 40
8699 $top.tosha1 insert 0 $newid
8700 $top.tosha1 conf -state readonly
8701 grid $top.to $top.tosha1 -sticky w
8702 ${NS}::entry $top.tohead -width 60
8703 $top.tohead insert 0 $newhead
8704 $top.tohead conf -state readonly
8705 grid x $top.tohead -sticky w
8706 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
8707 grid $top.rev x -pady 10 -padx 5
8708 ${NS}::label $top.flab -text [mc "Output file:"]
8709 ${NS}::entry $top.fname -width 60
8710 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8712 grid $top.flab $top.fname -sticky w
8713 ${NS}::frame $top.buts
8714 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8715 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8716 bind $top <Key-Return> mkpatchgo
8717 bind $top <Key-Escape> mkpatchcan
8718 grid $top.buts.gen $top.buts.can
8719 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8720 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8721 grid $top.buts - -pady 10 -sticky ew
8725 proc mkpatchrev {} {
8728 set oldid [$patchtop.fromsha1 get]
8729 set oldhead [$patchtop.fromhead get]
8730 set newid [$patchtop.tosha1 get]
8731 set newhead [$patchtop.tohead get]
8732 foreach e [list fromsha1 fromhead tosha1 tohead] \
8733 v [list $newid $newhead $oldid $oldhead] {
8734 $patchtop.$e conf -state normal
8735 $patchtop.$e delete 0 end
8736 $patchtop.$e insert 0 $v
8737 $patchtop.$e conf -state readonly
8742 global patchtop nullid nullid2
8744 set oldid [$patchtop.fromsha1 get]
8745 set newid [$patchtop.tosha1 get]
8746 set fname [$patchtop.fname get]
8747 set cmd [diffcmd [list $oldid $newid] -p]
8748 # trim off the initial "|"
8749 set cmd [lrange $cmd 1 end]
8750 lappend cmd >$fname &
8751 if {[catch {eval exec $cmd} err]} {
8752 error_popup "[mc "Error creating patch:"] $err" $patchtop
8754 catch {destroy $patchtop}
8758 proc mkpatchcan {} {
8761 catch {destroy $patchtop}
8766 global rowmenuid mktagtop commitinfo NS
8770 catch {destroy $top}
8772 make_transient $top .
8773 ${NS}::label $top.title -text [mc "Create tag"]
8774 grid $top.title - -pady 10
8775 ${NS}::label $top.id -text [mc "ID:"]
8776 ${NS}::entry $top.sha1 -width 40
8777 $top.sha1 insert 0 $rowmenuid
8778 $top.sha1 conf -state readonly
8779 grid $top.id $top.sha1 -sticky w
8780 ${NS}::entry $top.head -width 60
8781 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8782 $top.head conf -state readonly
8783 grid x $top.head -sticky w
8784 ${NS}::label $top.tlab -text [mc "Tag name:"]
8785 ${NS}::entry $top.tag -width 60
8786 grid $top.tlab $top.tag -sticky w
8787 ${NS}::label $top.op -text [mc "Tag message is optional"]
8788 grid $top.op -columnspan 2 -sticky we
8789 ${NS}::label $top.mlab -text [mc "Tag message:"]
8790 ${NS}::entry $top.msg -width 60
8791 grid $top.mlab $top.msg -sticky w
8792 ${NS}::frame $top.buts
8793 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
8794 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
8795 bind $top <Key-Return> mktaggo
8796 bind $top <Key-Escape> mktagcan
8797 grid $top.buts.gen $top.buts.can
8798 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8799 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8800 grid $top.buts - -pady 10 -sticky ew
8805 global mktagtop env tagids idtags
8807 set id [$mktagtop.sha1 get]
8808 set tag [$mktagtop.tag get]
8809 set msg [$mktagtop.msg get]
8811 error_popup [mc "No tag name specified"] $mktagtop
8814 if {[info exists tagids($tag)]} {
8815 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
8820 exec git tag -a -m $msg $tag $id
8822 exec git tag $tag $id
8825 error_popup "[mc "Error creating tag:"] $err" $mktagtop
8829 set tagids($tag) $id
8830 lappend idtags($id) $tag
8838 proc redrawtags {id} {
8839 global canv linehtag idpos currentid curview cmitlisted markedid
8840 global canvxmax iddrawn circleitem mainheadid circlecolors
8842 if {![commitinview $id $curview]} return
8843 if {![info exists iddrawn($id)]} return
8844 set row [rowofcommit $id]
8845 if {$id eq $mainheadid} {
8848 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
8850 $canv itemconf $circleitem($row) -fill $ofill
8851 $canv delete tag.$id
8852 set xt [eval drawtags $id $idpos($id)]
8853 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
8854 set text [$canv itemcget $linehtag($id) -text]
8855 set font [$canv itemcget $linehtag($id) -font]
8856 set xr [expr {$xt + [font measure $font $text]}]
8857 if {$xr > $canvxmax} {
8861 if {[info exists currentid] && $currentid == $id} {
8864 if {[info exists markedid] && $markedid eq $id} {
8872 catch {destroy $mktagtop}
8877 if {![domktag]} return
8881 proc writecommit {} {
8882 global rowmenuid wrcomtop commitinfo wrcomcmd NS
8884 set top .writecommit
8886 catch {destroy $top}
8888 make_transient $top .
8889 ${NS}::label $top.title -text [mc "Write commit to file"]
8890 grid $top.title - -pady 10
8891 ${NS}::label $top.id -text [mc "ID:"]
8892 ${NS}::entry $top.sha1 -width 40
8893 $top.sha1 insert 0 $rowmenuid
8894 $top.sha1 conf -state readonly
8895 grid $top.id $top.sha1 -sticky w
8896 ${NS}::entry $top.head -width 60
8897 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8898 $top.head conf -state readonly
8899 grid x $top.head -sticky w
8900 ${NS}::label $top.clab -text [mc "Command:"]
8901 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
8902 grid $top.clab $top.cmd -sticky w -pady 10
8903 ${NS}::label $top.flab -text [mc "Output file:"]
8904 ${NS}::entry $top.fname -width 60
8905 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
8906 grid $top.flab $top.fname -sticky w
8907 ${NS}::frame $top.buts
8908 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
8909 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
8910 bind $top <Key-Return> wrcomgo
8911 bind $top <Key-Escape> wrcomcan
8912 grid $top.buts.gen $top.buts.can
8913 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8914 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8915 grid $top.buts - -pady 10 -sticky ew
8922 set id [$wrcomtop.sha1 get]
8923 set cmd "echo $id | [$wrcomtop.cmd get]"
8924 set fname [$wrcomtop.fname get]
8925 if {[catch {exec sh -c $cmd >$fname &} err]} {
8926 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
8928 catch {destroy $wrcomtop}
8935 catch {destroy $wrcomtop}
8940 global rowmenuid mkbrtop NS
8943 catch {destroy $top}
8945 make_transient $top .
8946 ${NS}::label $top.title -text [mc "Create new branch"]
8947 grid $top.title - -pady 10
8948 ${NS}::label $top.id -text [mc "ID:"]
8949 ${NS}::entry $top.sha1 -width 40
8950 $top.sha1 insert 0 $rowmenuid
8951 $top.sha1 conf -state readonly
8952 grid $top.id $top.sha1 -sticky w
8953 ${NS}::label $top.nlab -text [mc "Name:"]
8954 ${NS}::entry $top.name -width 40
8955 grid $top.nlab $top.name -sticky w
8956 ${NS}::frame $top.buts
8957 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
8958 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
8959 bind $top <Key-Return> [list mkbrgo $top]
8960 bind $top <Key-Escape> "catch {destroy $top}"
8961 grid $top.buts.go $top.buts.can
8962 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8963 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8964 grid $top.buts - -pady 10 -sticky ew
8969 global headids idheads
8971 set name [$top.name get]
8972 set id [$top.sha1 get]
8976 error_popup [mc "Please specify a name for the new branch"] $top
8979 if {[info exists headids($name)]} {
8980 if {![confirm_popup [mc \
8981 "Branch '%s' already exists. Overwrite?" $name] $top]} {
8984 set old_id $headids($name)
8987 catch {destroy $top}
8988 lappend cmdargs $name $id
8992 eval exec git branch $cmdargs
8998 if {$old_id ne {}} {
9004 set headids($name) $id
9005 lappend idheads($id) $name
9014 proc exec_citool {tool_args {baseid {}}} {
9015 global commitinfo env
9017 set save_env [array get env GIT_AUTHOR_*]
9019 if {$baseid ne {}} {
9020 if {![info exists commitinfo($baseid)]} {
9023 set author [lindex $commitinfo($baseid) 1]
9024 set date [lindex $commitinfo($baseid) 2]
9025 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9026 $author author name email]
9028 set env(GIT_AUTHOR_NAME) $name
9029 set env(GIT_AUTHOR_EMAIL) $email
9030 set env(GIT_AUTHOR_DATE) $date
9034 eval exec git citool $tool_args &
9036 array unset env GIT_AUTHOR_*
9037 array set env $save_env
9040 proc cherrypick {} {
9041 global rowmenuid curview
9042 global mainhead mainheadid
9044 set oldhead [exec git rev-parse HEAD]
9045 set dheads [descheads $rowmenuid]
9046 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9047 set ok [confirm_popup [mc "Commit %s is already\
9048 included in branch %s -- really re-apply it?" \
9049 [string range $rowmenuid 0 7] $mainhead]]
9052 nowbusy cherrypick [mc "Cherry-picking"]
9054 # Unfortunately git-cherry-pick writes stuff to stderr even when
9055 # no error occurs, and exec takes that as an indication of error...
9056 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9059 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9061 error_popup [mc "Cherry-pick failed because of local changes\
9062 to file '%s'.\nPlease commit, reset or stash\
9063 your changes and try again." $fname]
9064 } elseif {[regexp -line \
9065 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9067 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9068 conflict.\nDo you wish to run git citool to\
9070 # Force citool to read MERGE_MSG
9071 file delete [file join [gitdir] "GITGUI_MSG"]
9072 exec_citool {} $rowmenuid
9080 set newhead [exec git rev-parse HEAD]
9081 if {$newhead eq $oldhead} {
9083 error_popup [mc "No changes committed"]
9086 addnewchild $newhead $oldhead
9087 if {[commitinview $oldhead $curview]} {
9088 # XXX this isn't right if we have a path limit...
9089 insertrow $newhead $oldhead $curview
9090 if {$mainhead ne {}} {
9091 movehead $newhead $mainhead
9092 movedhead $newhead $mainhead
9094 set mainheadid $newhead
9103 global mainhead rowmenuid confirm_ok resettype NS
9106 set w ".confirmreset"
9109 wm title $w [mc "Confirm reset"]
9110 ${NS}::label $w.m -text \
9111 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9112 pack $w.m -side top -fill x -padx 20 -pady 20
9113 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9115 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9116 -text [mc "Soft: Leave working tree and index untouched"]
9117 grid $w.f.soft -sticky w
9118 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9119 -text [mc "Mixed: Leave working tree untouched, reset index"]
9120 grid $w.f.mixed -sticky w
9121 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9122 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9123 grid $w.f.hard -sticky w
9124 pack $w.f -side top -fill x -padx 4
9125 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9126 pack $w.ok -side left -fill x -padx 20 -pady 20
9127 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9128 bind $w <Key-Escape> [list destroy $w]
9129 pack $w.cancel -side right -fill x -padx 20 -pady 20
9130 bind $w <Visibility> "grab $w; focus $w"
9132 if {!$confirm_ok} return
9133 if {[catch {set fd [open \
9134 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9138 filerun $fd [list readresetstat $fd]
9139 nowbusy reset [mc "Resetting"]
9144 proc readresetstat {fd} {
9145 global mainhead mainheadid showlocalchanges rprogcoord
9147 if {[gets $fd line] >= 0} {
9148 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9149 set rprogcoord [expr {1.0 * $m / $n}]
9157 if {[catch {close $fd} err]} {
9160 set oldhead $mainheadid
9161 set newhead [exec git rev-parse HEAD]
9162 if {$newhead ne $oldhead} {
9163 movehead $newhead $mainhead
9164 movedhead $newhead $mainhead
9165 set mainheadid $newhead
9169 if {$showlocalchanges} {
9175 # context menu for a head
9176 proc headmenu {x y id head} {
9177 global headmenuid headmenuhead headctxmenu mainhead
9181 set headmenuhead $head
9183 if {[string match "remotes/*" $head]} {
9186 if {$head eq $mainhead} {
9189 $headctxmenu entryconfigure 0 -state $state
9190 $headctxmenu entryconfigure 1 -state $state
9191 tk_popup $headctxmenu $x $y
9195 global headmenuid headmenuhead headids
9196 global showlocalchanges
9198 # check the tree is clean first??
9199 nowbusy checkout [mc "Checking out"]
9203 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9207 if {$showlocalchanges} {
9211 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9215 proc readcheckoutstat {fd newhead newheadid} {
9216 global mainhead mainheadid headids showlocalchanges progresscoords
9217 global viewmainheadid curview
9219 if {[gets $fd line] >= 0} {
9220 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9221 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9226 set progresscoords {0 0}
9229 if {[catch {close $fd} err]} {
9232 set oldmainid $mainheadid
9233 set mainhead $newhead
9234 set mainheadid $newheadid
9235 set viewmainheadid($curview) $newheadid
9236 redrawtags $oldmainid
9237 redrawtags $newheadid
9239 if {$showlocalchanges} {
9245 global headmenuid headmenuhead mainhead
9248 set head $headmenuhead
9250 # this check shouldn't be needed any more...
9251 if {$head eq $mainhead} {
9252 error_popup [mc "Cannot delete the currently checked-out branch"]
9255 set dheads [descheads $id]
9256 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9257 # the stuff on this branch isn't on any other branch
9258 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9259 branch.\nReally delete branch %s?" $head $head]]} return
9263 if {[catch {exec git branch -D $head} err]} {
9268 removehead $id $head
9269 removedhead $id $head
9276 # Display a list of tags and heads
9278 global showrefstop bgcolor fgcolor selectbgcolor NS
9279 global bglist fglist reflistfilter reflist maincursor
9282 set showrefstop $top
9283 if {[winfo exists $top]} {
9289 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9290 make_transient $top .
9291 text $top.list -background $bgcolor -foreground $fgcolor \
9292 -selectbackground $selectbgcolor -font mainfont \
9293 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9294 -width 30 -height 20 -cursor $maincursor \
9295 -spacing1 1 -spacing3 1 -state disabled
9296 $top.list tag configure highlight -background $selectbgcolor
9297 lappend bglist $top.list
9298 lappend fglist $top.list
9299 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9300 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9301 grid $top.list $top.ysb -sticky nsew
9302 grid $top.xsb x -sticky ew
9304 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9305 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9306 set reflistfilter "*"
9307 trace add variable reflistfilter write reflistfilter_change
9308 pack $top.f.e -side right -fill x -expand 1
9309 pack $top.f.l -side left
9310 grid $top.f - -sticky ew -pady 2
9311 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9312 bind $top <Key-Escape> [list destroy $top]
9314 grid columnconfigure $top 0 -weight 1
9315 grid rowconfigure $top 0 -weight 1
9316 bind $top.list <1> {break}
9317 bind $top.list <B1-Motion> {break}
9318 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9323 proc sel_reflist {w x y} {
9324 global showrefstop reflist headids tagids otherrefids
9326 if {![winfo exists $showrefstop]} return
9327 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9328 set ref [lindex $reflist [expr {$l-1}]]
9329 set n [lindex $ref 0]
9330 switch -- [lindex $ref 1] {
9331 "H" {selbyid $headids($n)}
9332 "T" {selbyid $tagids($n)}
9333 "o" {selbyid $otherrefids($n)}
9335 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9338 proc unsel_reflist {} {
9341 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9342 $showrefstop.list tag remove highlight 0.0 end
9345 proc reflistfilter_change {n1 n2 op} {
9346 global reflistfilter
9348 after cancel refill_reflist
9349 after 200 refill_reflist
9352 proc refill_reflist {} {
9353 global reflist reflistfilter showrefstop headids tagids otherrefids
9356 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9358 foreach n [array names headids] {
9359 if {[string match $reflistfilter $n]} {
9360 if {[commitinview $headids($n) $curview]} {
9361 lappend refs [list $n H]
9363 interestedin $headids($n) {run refill_reflist}
9367 foreach n [array names tagids] {
9368 if {[string match $reflistfilter $n]} {
9369 if {[commitinview $tagids($n) $curview]} {
9370 lappend refs [list $n T]
9372 interestedin $tagids($n) {run refill_reflist}
9376 foreach n [array names otherrefids] {
9377 if {[string match $reflistfilter $n]} {
9378 if {[commitinview $otherrefids($n) $curview]} {
9379 lappend refs [list $n o]
9381 interestedin $otherrefids($n) {run refill_reflist}
9385 set refs [lsort -index 0 $refs]
9386 if {$refs eq $reflist} return
9388 # Update the contents of $showrefstop.list according to the
9389 # differences between $reflist (old) and $refs (new)
9390 $showrefstop.list conf -state normal
9391 $showrefstop.list insert end "\n"
9394 while {$i < [llength $reflist] || $j < [llength $refs]} {
9395 if {$i < [llength $reflist]} {
9396 if {$j < [llength $refs]} {
9397 set cmp [string compare [lindex $reflist $i 0] \
9398 [lindex $refs $j 0]]
9400 set cmp [string compare [lindex $reflist $i 1] \
9401 [lindex $refs $j 1]]
9411 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9419 set l [expr {$j + 1}]
9420 $showrefstop.list image create $l.0 -align baseline \
9421 -image reficon-[lindex $refs $j 1] -padx 2
9422 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9428 # delete last newline
9429 $showrefstop.list delete end-2c end-1c
9430 $showrefstop.list conf -state disabled
9433 # Stuff for finding nearby tags
9434 proc getallcommits {} {
9435 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9436 global idheads idtags idotherrefs allparents tagobjid
9438 if {![info exists allcommits]} {
9444 set allccache [file join [gitdir] "gitk.cache"]
9446 set f [open $allccache r]
9455 set cmd [list | git rev-list --parents]
9456 set allcupdate [expr {$seeds ne {}}]
9460 set refs [concat [array names idheads] [array names idtags] \
9461 [array names idotherrefs]]
9464 foreach name [array names tagobjid] {
9465 lappend tagobjs $tagobjid($name)
9467 foreach id [lsort -unique $refs] {
9468 if {![info exists allparents($id)] &&
9469 [lsearch -exact $tagobjs $id] < 0} {
9480 set fd [open [concat $cmd $ids] r]
9481 fconfigure $fd -blocking 0
9484 filerun $fd [list getallclines $fd]
9490 # Since most commits have 1 parent and 1 child, we group strings of
9491 # such commits into "arcs" joining branch/merge points (BMPs), which
9492 # are commits that either don't have 1 parent or don't have 1 child.
9494 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9495 # arcout(id) - outgoing arcs for BMP
9496 # arcids(a) - list of IDs on arc including end but not start
9497 # arcstart(a) - BMP ID at start of arc
9498 # arcend(a) - BMP ID at end of arc
9499 # growing(a) - arc a is still growing
9500 # arctags(a) - IDs out of arcids (excluding end) that have tags
9501 # archeads(a) - IDs out of arcids (excluding end) that have heads
9502 # The start of an arc is at the descendent end, so "incoming" means
9503 # coming from descendents, and "outgoing" means going towards ancestors.
9505 proc getallclines {fd} {
9506 global allparents allchildren idtags idheads nextarc
9507 global arcnos arcids arctags arcout arcend arcstart archeads growing
9508 global seeds allcommits cachedarcs allcupdate
9511 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9512 set id [lindex $line 0]
9513 if {[info exists allparents($id)]} {
9518 set olds [lrange $line 1 end]
9519 set allparents($id) $olds
9520 if {![info exists allchildren($id)]} {
9521 set allchildren($id) {}
9526 if {[llength $olds] == 1 && [llength $a] == 1} {
9527 lappend arcids($a) $id
9528 if {[info exists idtags($id)]} {
9529 lappend arctags($a) $id
9531 if {[info exists idheads($id)]} {
9532 lappend archeads($a) $id
9534 if {[info exists allparents($olds)]} {
9535 # seen parent already
9536 if {![info exists arcout($olds)]} {
9539 lappend arcids($a) $olds
9540 set arcend($a) $olds
9543 lappend allchildren($olds) $id
9544 lappend arcnos($olds) $a
9548 foreach a $arcnos($id) {
9549 lappend arcids($a) $id
9556 lappend allchildren($p) $id
9557 set a [incr nextarc]
9558 set arcstart($a) $id
9565 if {[info exists allparents($p)]} {
9566 # seen it already, may need to make a new branch
9567 if {![info exists arcout($p)]} {
9570 lappend arcids($a) $p
9574 lappend arcnos($p) $a
9579 global cached_dheads cached_dtags cached_atags
9580 catch {unset cached_dheads}
9581 catch {unset cached_dtags}
9582 catch {unset cached_atags}
9585 return [expr {$nid >= 1000? 2: 1}]
9589 fconfigure $fd -blocking 1
9592 # got an error reading the list of commits
9593 # if we were updating, try rereading the whole thing again
9599 error_popup "[mc "Error reading commit topology information;\
9600 branch and preceding/following tag information\
9601 will be incomplete."]\n($err)"
9604 if {[incr allcommits -1] == 0} {
9614 proc recalcarc {a} {
9615 global arctags archeads arcids idtags idheads
9619 foreach id [lrange $arcids($a) 0 end-1] {
9620 if {[info exists idtags($id)]} {
9623 if {[info exists idheads($id)]} {
9628 set archeads($a) $ah
9632 global arcnos arcids nextarc arctags archeads idtags idheads
9633 global arcstart arcend arcout allparents growing
9636 if {[llength $a] != 1} {
9637 puts "oops splitarc called but [llength $a] arcs already"
9641 set i [lsearch -exact $arcids($a) $p]
9643 puts "oops splitarc $p not in arc $a"
9646 set na [incr nextarc]
9647 if {[info exists arcend($a)]} {
9648 set arcend($na) $arcend($a)
9650 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9651 set j [lsearch -exact $arcnos($l) $a]
9652 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9654 set tail [lrange $arcids($a) [expr {$i+1}] end]
9655 set arcids($a) [lrange $arcids($a) 0 $i]
9657 set arcstart($na) $p
9659 set arcids($na) $tail
9660 if {[info exists growing($a)]} {
9666 if {[llength $arcnos($id)] == 1} {
9669 set j [lsearch -exact $arcnos($id) $a]
9670 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9674 # reconstruct tags and heads lists
9675 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9680 set archeads($na) {}
9684 # Update things for a new commit added that is a child of one
9685 # existing commit. Used when cherry-picking.
9686 proc addnewchild {id p} {
9687 global allparents allchildren idtags nextarc
9688 global arcnos arcids arctags arcout arcend arcstart archeads growing
9689 global seeds allcommits
9691 if {![info exists allcommits] || ![info exists arcnos($p)]} return
9692 set allparents($id) [list $p]
9693 set allchildren($id) {}
9696 lappend allchildren($p) $id
9697 set a [incr nextarc]
9698 set arcstart($a) $id
9701 set arcids($a) [list $p]
9703 if {![info exists arcout($p)]} {
9706 lappend arcnos($p) $a
9707 set arcout($id) [list $a]
9710 # This implements a cache for the topology information.
9711 # The cache saves, for each arc, the start and end of the arc,
9712 # the ids on the arc, and the outgoing arcs from the end.
9713 proc readcache {f} {
9714 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
9715 global idtags idheads allparents cachedarcs possible_seeds seeds growing
9720 if {$lim - $a > 500} {
9721 set lim [expr {$a + 500}]
9725 # finish reading the cache and setting up arctags, etc.
9727 if {$line ne "1"} {error "bad final version"}
9729 foreach id [array names idtags] {
9730 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9731 [llength $allparents($id)] == 1} {
9732 set a [lindex $arcnos($id) 0]
9733 if {$arctags($a) eq {}} {
9738 foreach id [array names idheads] {
9739 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9740 [llength $allparents($id)] == 1} {
9741 set a [lindex $arcnos($id) 0]
9742 if {$archeads($a) eq {}} {
9747 foreach id [lsort -unique $possible_seeds] {
9748 if {$arcnos($id) eq {}} {
9754 while {[incr a] <= $lim} {
9756 if {[llength $line] != 3} {error "bad line"}
9757 set s [lindex $line 0]
9759 lappend arcout($s) $a
9760 if {![info exists arcnos($s)]} {
9761 lappend possible_seeds $s
9764 set e [lindex $line 1]
9769 if {![info exists arcout($e)]} {
9773 set arcids($a) [lindex $line 2]
9774 foreach id $arcids($a) {
9775 lappend allparents($s) $id
9777 lappend arcnos($id) $a
9779 if {![info exists allparents($s)]} {
9780 set allparents($s) {}
9785 set nextarc [expr {$a - 1}]
9798 global nextarc cachedarcs possible_seeds
9802 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
9803 # make sure it's an integer
9804 set cachedarcs [expr {int([lindex $line 1])}]
9805 if {$cachedarcs < 0} {error "bad number of arcs"}
9807 set possible_seeds {}
9815 proc dropcache {err} {
9816 global allcwait nextarc cachedarcs seeds
9818 #puts "dropping cache ($err)"
9819 foreach v {arcnos arcout arcids arcstart arcend growing \
9820 arctags archeads allparents allchildren} {
9831 proc writecache {f} {
9832 global cachearc cachedarcs allccache
9833 global arcstart arcend arcnos arcids arcout
9837 if {$lim - $a > 1000} {
9838 set lim [expr {$a + 1000}]
9841 while {[incr a] <= $lim} {
9842 if {[info exists arcend($a)]} {
9843 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
9845 puts $f [list $arcstart($a) {} $arcids($a)]
9850 catch {file delete $allccache}
9851 #puts "writing cache failed ($err)"
9854 set cachearc [expr {$a - 1}]
9855 if {$a > $cachedarcs} {
9864 global nextarc cachedarcs cachearc allccache
9866 if {$nextarc == $cachedarcs} return
9868 set cachedarcs $nextarc
9870 set f [open $allccache w]
9871 puts $f [list 1 $cachedarcs]
9876 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
9877 # or 0 if neither is true.
9878 proc anc_or_desc {a b} {
9879 global arcout arcstart arcend arcnos cached_isanc
9881 if {$arcnos($a) eq $arcnos($b)} {
9882 # Both are on the same arc(s); either both are the same BMP,
9883 # or if one is not a BMP, the other is also not a BMP or is
9884 # the BMP at end of the arc (and it only has 1 incoming arc).
9885 # Or both can be BMPs with no incoming arcs.
9886 if {$a eq $b || $arcnos($a) eq {}} {
9889 # assert {[llength $arcnos($a)] == 1}
9890 set arc [lindex $arcnos($a) 0]
9891 set i [lsearch -exact $arcids($arc) $a]
9892 set j [lsearch -exact $arcids($arc) $b]
9893 if {$i < 0 || $i > $j} {
9900 if {![info exists arcout($a)]} {
9901 set arc [lindex $arcnos($a) 0]
9902 if {[info exists arcend($arc)]} {
9903 set aend $arcend($arc)
9907 set a $arcstart($arc)
9911 if {![info exists arcout($b)]} {
9912 set arc [lindex $arcnos($b) 0]
9913 if {[info exists arcend($arc)]} {
9914 set bend $arcend($arc)
9918 set b $arcstart($arc)
9928 if {[info exists cached_isanc($a,$bend)]} {
9929 if {$cached_isanc($a,$bend)} {
9933 if {[info exists cached_isanc($b,$aend)]} {
9934 if {$cached_isanc($b,$aend)} {
9937 if {[info exists cached_isanc($a,$bend)]} {
9942 set todo [list $a $b]
9945 for {set i 0} {$i < [llength $todo]} {incr i} {
9946 set x [lindex $todo $i]
9947 if {$anc($x) eq {}} {
9950 foreach arc $arcnos($x) {
9951 set xd $arcstart($arc)
9953 set cached_isanc($a,$bend) 1
9954 set cached_isanc($b,$aend) 0
9956 } elseif {$xd eq $aend} {
9957 set cached_isanc($b,$aend) 1
9958 set cached_isanc($a,$bend) 0
9961 if {![info exists anc($xd)]} {
9962 set anc($xd) $anc($x)
9964 } elseif {$anc($xd) ne $anc($x)} {
9969 set cached_isanc($a,$bend) 0
9970 set cached_isanc($b,$aend) 0
9974 # This identifies whether $desc has an ancestor that is
9975 # a growing tip of the graph and which is not an ancestor of $anc
9976 # and returns 0 if so and 1 if not.
9977 # If we subsequently discover a tag on such a growing tip, and that
9978 # turns out to be a descendent of $anc (which it could, since we
9979 # don't necessarily see children before parents), then $desc
9980 # isn't a good choice to display as a descendent tag of
9981 # $anc (since it is the descendent of another tag which is
9982 # a descendent of $anc). Similarly, $anc isn't a good choice to
9983 # display as a ancestor tag of $desc.
9985 proc is_certain {desc anc} {
9986 global arcnos arcout arcstart arcend growing problems
9989 if {[llength $arcnos($anc)] == 1} {
9990 # tags on the same arc are certain
9991 if {$arcnos($desc) eq $arcnos($anc)} {
9994 if {![info exists arcout($anc)]} {
9995 # if $anc is partway along an arc, use the start of the arc instead
9996 set a [lindex $arcnos($anc) 0]
9997 set anc $arcstart($a)
10000 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10003 set a [lindex $arcnos($desc) 0]
10009 set anclist [list $x]
10013 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10014 set x [lindex $anclist $i]
10019 foreach a $arcout($x) {
10020 if {[info exists growing($a)]} {
10021 if {![info exists growanc($x)] && $dl($x)} {
10027 if {[info exists dl($y)]} {
10031 if {![info exists done($y)]} {
10034 if {[info exists growanc($x)]} {
10038 for {set k 0} {$k < [llength $xl]} {incr k} {
10039 set z [lindex $xl $k]
10040 foreach c $arcout($z) {
10041 if {[info exists arcend($c)]} {
10043 if {[info exists dl($v)] && $dl($v)} {
10045 if {![info exists done($v)]} {
10048 if {[info exists growanc($v)]} {
10058 } elseif {$y eq $anc || !$dl($x)} {
10069 foreach x [array names growanc] {
10078 proc validate_arctags {a} {
10079 global arctags idtags
10082 set na $arctags($a)
10083 foreach id $arctags($a) {
10085 if {![info exists idtags($id)]} {
10086 set na [lreplace $na $i $i]
10090 set arctags($a) $na
10093 proc validate_archeads {a} {
10094 global archeads idheads
10097 set na $archeads($a)
10098 foreach id $archeads($a) {
10100 if {![info exists idheads($id)]} {
10101 set na [lreplace $na $i $i]
10105 set archeads($a) $na
10108 # Return the list of IDs that have tags that are descendents of id,
10109 # ignoring IDs that are descendents of IDs already reported.
10110 proc desctags {id} {
10111 global arcnos arcstart arcids arctags idtags allparents
10112 global growing cached_dtags
10114 if {![info exists allparents($id)]} {
10117 set t1 [clock clicks -milliseconds]
10119 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10120 # part-way along an arc; check that arc first
10121 set a [lindex $arcnos($id) 0]
10122 if {$arctags($a) ne {}} {
10123 validate_arctags $a
10124 set i [lsearch -exact $arcids($a) $id]
10126 foreach t $arctags($a) {
10127 set j [lsearch -exact $arcids($a) $t]
10128 if {$j >= $i} break
10135 set id $arcstart($a)
10136 if {[info exists idtags($id)]} {
10140 if {[info exists cached_dtags($id)]} {
10141 return $cached_dtags($id)
10145 set todo [list $id]
10148 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10149 set id [lindex $todo $i]
10151 set ta [info exists hastaggedancestor($id)]
10155 # ignore tags on starting node
10156 if {!$ta && $i > 0} {
10157 if {[info exists idtags($id)]} {
10158 set tagloc($id) $id
10160 } elseif {[info exists cached_dtags($id)]} {
10161 set tagloc($id) $cached_dtags($id)
10165 foreach a $arcnos($id) {
10166 set d $arcstart($a)
10167 if {!$ta && $arctags($a) ne {}} {
10168 validate_arctags $a
10169 if {$arctags($a) ne {}} {
10170 lappend tagloc($id) [lindex $arctags($a) end]
10173 if {$ta || $arctags($a) ne {}} {
10174 set tomark [list $d]
10175 for {set j 0} {$j < [llength $tomark]} {incr j} {
10176 set dd [lindex $tomark $j]
10177 if {![info exists hastaggedancestor($dd)]} {
10178 if {[info exists done($dd)]} {
10179 foreach b $arcnos($dd) {
10180 lappend tomark $arcstart($b)
10182 if {[info exists tagloc($dd)]} {
10185 } elseif {[info exists queued($dd)]} {
10188 set hastaggedancestor($dd) 1
10192 if {![info exists queued($d)]} {
10195 if {![info exists hastaggedancestor($d)]} {
10202 foreach id [array names tagloc] {
10203 if {![info exists hastaggedancestor($id)]} {
10204 foreach t $tagloc($id) {
10205 if {[lsearch -exact $tags $t] < 0} {
10211 set t2 [clock clicks -milliseconds]
10214 # remove tags that are descendents of other tags
10215 for {set i 0} {$i < [llength $tags]} {incr i} {
10216 set a [lindex $tags $i]
10217 for {set j 0} {$j < $i} {incr j} {
10218 set b [lindex $tags $j]
10219 set r [anc_or_desc $a $b]
10221 set tags [lreplace $tags $j $j]
10224 } elseif {$r == -1} {
10225 set tags [lreplace $tags $i $i]
10232 if {[array names growing] ne {}} {
10233 # graph isn't finished, need to check if any tag could get
10234 # eclipsed by another tag coming later. Simply ignore any
10235 # tags that could later get eclipsed.
10238 if {[is_certain $t $origid]} {
10242 if {$tags eq $ctags} {
10243 set cached_dtags($origid) $tags
10248 set cached_dtags($origid) $tags
10250 set t3 [clock clicks -milliseconds]
10251 if {0 && $t3 - $t1 >= 100} {
10252 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10253 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10258 proc anctags {id} {
10259 global arcnos arcids arcout arcend arctags idtags allparents
10260 global growing cached_atags
10262 if {![info exists allparents($id)]} {
10265 set t1 [clock clicks -milliseconds]
10267 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10268 # part-way along an arc; check that arc first
10269 set a [lindex $arcnos($id) 0]
10270 if {$arctags($a) ne {}} {
10271 validate_arctags $a
10272 set i [lsearch -exact $arcids($a) $id]
10273 foreach t $arctags($a) {
10274 set j [lsearch -exact $arcids($a) $t]
10280 if {![info exists arcend($a)]} {
10284 if {[info exists idtags($id)]} {
10288 if {[info exists cached_atags($id)]} {
10289 return $cached_atags($id)
10293 set todo [list $id]
10297 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10298 set id [lindex $todo $i]
10300 set td [info exists hastaggeddescendent($id)]
10304 # ignore tags on starting node
10305 if {!$td && $i > 0} {
10306 if {[info exists idtags($id)]} {
10307 set tagloc($id) $id
10309 } elseif {[info exists cached_atags($id)]} {
10310 set tagloc($id) $cached_atags($id)
10314 foreach a $arcout($id) {
10315 if {!$td && $arctags($a) ne {}} {
10316 validate_arctags $a
10317 if {$arctags($a) ne {}} {
10318 lappend tagloc($id) [lindex $arctags($a) 0]
10321 if {![info exists arcend($a)]} continue
10323 if {$td || $arctags($a) ne {}} {
10324 set tomark [list $d]
10325 for {set j 0} {$j < [llength $tomark]} {incr j} {
10326 set dd [lindex $tomark $j]
10327 if {![info exists hastaggeddescendent($dd)]} {
10328 if {[info exists done($dd)]} {
10329 foreach b $arcout($dd) {
10330 if {[info exists arcend($b)]} {
10331 lappend tomark $arcend($b)
10334 if {[info exists tagloc($dd)]} {
10337 } elseif {[info exists queued($dd)]} {
10340 set hastaggeddescendent($dd) 1
10344 if {![info exists queued($d)]} {
10347 if {![info exists hastaggeddescendent($d)]} {
10353 set t2 [clock clicks -milliseconds]
10356 foreach id [array names tagloc] {
10357 if {![info exists hastaggeddescendent($id)]} {
10358 foreach t $tagloc($id) {
10359 if {[lsearch -exact $tags $t] < 0} {
10366 # remove tags that are ancestors of other tags
10367 for {set i 0} {$i < [llength $tags]} {incr i} {
10368 set a [lindex $tags $i]
10369 for {set j 0} {$j < $i} {incr j} {
10370 set b [lindex $tags $j]
10371 set r [anc_or_desc $a $b]
10373 set tags [lreplace $tags $j $j]
10376 } elseif {$r == 1} {
10377 set tags [lreplace $tags $i $i]
10384 if {[array names growing] ne {}} {
10385 # graph isn't finished, need to check if any tag could get
10386 # eclipsed by another tag coming later. Simply ignore any
10387 # tags that could later get eclipsed.
10390 if {[is_certain $origid $t]} {
10394 if {$tags eq $ctags} {
10395 set cached_atags($origid) $tags
10400 set cached_atags($origid) $tags
10402 set t3 [clock clicks -milliseconds]
10403 if {0 && $t3 - $t1 >= 100} {
10404 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10405 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10410 # Return the list of IDs that have heads that are descendents of id,
10411 # including id itself if it has a head.
10412 proc descheads {id} {
10413 global arcnos arcstart arcids archeads idheads cached_dheads
10416 if {![info exists allparents($id)]} {
10420 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10421 # part-way along an arc; check it first
10422 set a [lindex $arcnos($id) 0]
10423 if {$archeads($a) ne {}} {
10424 validate_archeads $a
10425 set i [lsearch -exact $arcids($a) $id]
10426 foreach t $archeads($a) {
10427 set j [lsearch -exact $arcids($a) $t]
10432 set id $arcstart($a)
10435 set todo [list $id]
10438 for {set i 0} {$i < [llength $todo]} {incr i} {
10439 set id [lindex $todo $i]
10440 if {[info exists cached_dheads($id)]} {
10441 set ret [concat $ret $cached_dheads($id)]
10443 if {[info exists idheads($id)]} {
10446 foreach a $arcnos($id) {
10447 if {$archeads($a) ne {}} {
10448 validate_archeads $a
10449 if {$archeads($a) ne {}} {
10450 set ret [concat $ret $archeads($a)]
10453 set d $arcstart($a)
10454 if {![info exists seen($d)]} {
10461 set ret [lsort -unique $ret]
10462 set cached_dheads($origid) $ret
10463 return [concat $ret $aret]
10466 proc addedtag {id} {
10467 global arcnos arcout cached_dtags cached_atags
10469 if {![info exists arcnos($id)]} return
10470 if {![info exists arcout($id)]} {
10471 recalcarc [lindex $arcnos($id) 0]
10473 catch {unset cached_dtags}
10474 catch {unset cached_atags}
10477 proc addedhead {hid head} {
10478 global arcnos arcout cached_dheads
10480 if {![info exists arcnos($hid)]} return
10481 if {![info exists arcout($hid)]} {
10482 recalcarc [lindex $arcnos($hid) 0]
10484 catch {unset cached_dheads}
10487 proc removedhead {hid head} {
10488 global cached_dheads
10490 catch {unset cached_dheads}
10493 proc movedhead {hid head} {
10494 global arcnos arcout cached_dheads
10496 if {![info exists arcnos($hid)]} return
10497 if {![info exists arcout($hid)]} {
10498 recalcarc [lindex $arcnos($hid) 0]
10500 catch {unset cached_dheads}
10503 proc changedrefs {} {
10504 global cached_dheads cached_dtags cached_atags
10505 global arctags archeads arcnos arcout idheads idtags
10507 foreach id [concat [array names idheads] [array names idtags]] {
10508 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10509 set a [lindex $arcnos($id) 0]
10510 if {![info exists donearc($a)]} {
10516 catch {unset cached_dtags}
10517 catch {unset cached_atags}
10518 catch {unset cached_dheads}
10521 proc rereadrefs {} {
10522 global idtags idheads idotherrefs mainheadid
10524 set refids [concat [array names idtags] \
10525 [array names idheads] [array names idotherrefs]]
10526 foreach id $refids {
10527 if {![info exists ref($id)]} {
10528 set ref($id) [listrefs $id]
10531 set oldmainhead $mainheadid
10534 set refids [lsort -unique [concat $refids [array names idtags] \
10535 [array names idheads] [array names idotherrefs]]]
10536 foreach id $refids {
10537 set v [listrefs $id]
10538 if {![info exists ref($id)] || $ref($id) != $v} {
10542 if {$oldmainhead ne $mainheadid} {
10543 redrawtags $oldmainhead
10544 redrawtags $mainheadid
10549 proc listrefs {id} {
10550 global idtags idheads idotherrefs
10553 if {[info exists idtags($id)]} {
10557 if {[info exists idheads($id)]} {
10558 set y $idheads($id)
10561 if {[info exists idotherrefs($id)]} {
10562 set z $idotherrefs($id)
10564 return [list $x $y $z]
10567 proc showtag {tag isnew} {
10568 global ctext tagcontents tagids linknum tagobjid
10571 addtohistory [list showtag $tag 0] savectextpos
10573 $ctext conf -state normal
10577 if {![info exists tagcontents($tag)]} {
10579 set tagcontents($tag) [exec git cat-file tag $tag]
10582 if {[info exists tagcontents($tag)]} {
10583 set text $tagcontents($tag)
10585 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10587 appendwithlinks $text {}
10588 maybe_scroll_ctext 1
10589 $ctext conf -state disabled
10601 if {[info exists gitktmpdir]} {
10602 catch {file delete -force $gitktmpdir}
10606 proc mkfontdisp {font top which} {
10607 global fontattr fontpref $font NS use_ttk
10609 set fontpref($font) [set $font]
10610 ${NS}::button $top.${font}but -text $which \
10611 -command [list choosefont $font $which]
10612 ${NS}::label $top.$font -relief flat -font $font \
10613 -text $fontattr($font,family) -justify left
10614 grid x $top.${font}but $top.$font -sticky w
10617 proc choosefont {font which} {
10618 global fontparam fontlist fonttop fontattr
10621 set fontparam(which) $which
10622 set fontparam(font) $font
10623 set fontparam(family) [font actual $font -family]
10624 set fontparam(size) $fontattr($font,size)
10625 set fontparam(weight) $fontattr($font,weight)
10626 set fontparam(slant) $fontattr($font,slant)
10629 if {![winfo exists $top]} {
10631 eval font config sample [font actual $font]
10633 make_transient $top $prefstop
10634 wm title $top [mc "Gitk font chooser"]
10635 ${NS}::label $top.l -textvariable fontparam(which)
10636 pack $top.l -side top
10637 set fontlist [lsort [font families]]
10638 ${NS}::frame $top.f
10639 listbox $top.f.fam -listvariable fontlist \
10640 -yscrollcommand [list $top.f.sb set]
10641 bind $top.f.fam <<ListboxSelect>> selfontfam
10642 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10643 pack $top.f.sb -side right -fill y
10644 pack $top.f.fam -side left -fill both -expand 1
10645 pack $top.f -side top -fill both -expand 1
10646 ${NS}::frame $top.g
10647 spinbox $top.g.size -from 4 -to 40 -width 4 \
10648 -textvariable fontparam(size) \
10649 -validatecommand {string is integer -strict %s}
10650 checkbutton $top.g.bold -padx 5 \
10651 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10652 -variable fontparam(weight) -onvalue bold -offvalue normal
10653 checkbutton $top.g.ital -padx 5 \
10654 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10655 -variable fontparam(slant) -onvalue italic -offvalue roman
10656 pack $top.g.size $top.g.bold $top.g.ital -side left
10657 pack $top.g -side top
10658 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10660 $top.c create text 100 25 -anchor center -text $which -font sample \
10661 -fill black -tags text
10662 bind $top.c <Configure> [list centertext $top.c]
10663 pack $top.c -side top -fill x
10664 ${NS}::frame $top.buts
10665 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10666 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10667 bind $top <Key-Return> fontok
10668 bind $top <Key-Escape> fontcan
10669 grid $top.buts.ok $top.buts.can
10670 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10671 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10672 pack $top.buts -side bottom -fill x
10673 trace add variable fontparam write chg_fontparam
10676 $top.c itemconf text -text $which
10678 set i [lsearch -exact $fontlist $fontparam(family)]
10680 $top.f.fam selection set $i
10685 proc centertext {w} {
10686 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
10690 global fontparam fontpref prefstop
10692 set f $fontparam(font)
10693 set fontpref($f) [list $fontparam(family) $fontparam(size)]
10694 if {$fontparam(weight) eq "bold"} {
10695 lappend fontpref($f) "bold"
10697 if {$fontparam(slant) eq "italic"} {
10698 lappend fontpref($f) "italic"
10701 $w conf -text $fontparam(family) -font $fontpref($f)
10707 global fonttop fontparam
10709 if {[info exists fonttop]} {
10710 catch {destroy $fonttop}
10711 catch {font delete sample}
10717 if {[package vsatisfies [package provide Tk] 8.6]} {
10718 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
10719 # function to make use of it.
10720 proc choosefont {font which} {
10721 tk fontchooser configure -title $which -font $font \
10722 -command [list on_choosefont $font $which]
10723 tk fontchooser show
10725 proc on_choosefont {font which newfont} {
10727 puts stderr "$font $newfont"
10728 array set f [font actual $newfont]
10729 set fontparam(which) $which
10730 set fontparam(font) $font
10731 set fontparam(family) $f(-family)
10732 set fontparam(size) $f(-size)
10733 set fontparam(weight) $f(-weight)
10734 set fontparam(slant) $f(-slant)
10739 proc selfontfam {} {
10740 global fonttop fontparam
10742 set i [$fonttop.f.fam curselection]
10744 set fontparam(family) [$fonttop.f.fam get $i]
10748 proc chg_fontparam {v sub op} {
10751 font config sample -$sub $fontparam($sub)
10755 global maxwidth maxgraphpct use_ttk NS
10756 global oldprefs prefstop showneartags showlocalchanges
10757 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
10758 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
10759 global hideremotes want_ttk have_ttk
10763 if {[winfo exists $top]} {
10767 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
10768 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
10769 set oldprefs($v) [set $v]
10772 wm title $top [mc "Gitk preferences"]
10773 make_transient $top .
10774 ${NS}::label $top.ldisp -text [mc "Commit list display options"]
10775 grid $top.ldisp - -sticky w -pady 10
10776 ${NS}::label $top.spacer -text " "
10777 ${NS}::label $top.maxwidthl -text [mc "Maximum graph width (lines)"]
10778 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
10779 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
10780 ${NS}::label $top.maxpctl -text [mc "Maximum graph width (% of pane)"]
10781 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
10782 grid x $top.maxpctl $top.maxpct -sticky w
10783 ${NS}::checkbutton $top.showlocal -text [mc "Show local changes"] \
10784 -variable showlocalchanges
10785 grid x $top.showlocal -sticky w
10786 ${NS}::checkbutton $top.autoselect -text [mc "Auto-select SHA1 (length)"] \
10787 -variable autoselect
10788 spinbox $top.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
10789 grid x $top.autoselect $top.autosellen -sticky w
10790 ${NS}::checkbutton $top.hideremotes -text [mc "Hide remote refs"] \
10791 -variable hideremotes
10792 grid x $top.hideremotes -sticky w
10794 ${NS}::label $top.ddisp -text [mc "Diff display options"]
10795 grid $top.ddisp - -sticky w -pady 10
10796 ${NS}::label $top.tabstopl -text [mc "Tab spacing"]
10797 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
10798 grid x $top.tabstopl $top.tabstop -sticky w
10799 ${NS}::checkbutton $top.ntag -text [mc "Display nearby tags"] \
10800 -variable showneartags
10801 grid x $top.ntag -sticky w
10802 ${NS}::checkbutton $top.ldiff -text [mc "Limit diffs to listed paths"] \
10803 -variable limitdiffs
10804 grid x $top.ldiff -sticky w
10805 ${NS}::checkbutton $top.lattr -text [mc "Support per-file encodings"] \
10806 -variable perfile_attrs
10807 grid x $top.lattr -sticky w
10809 ${NS}::entry $top.extdifft -textvariable extdifftool
10810 ${NS}::frame $top.extdifff
10811 ${NS}::label $top.extdifff.l -text [mc "External diff tool" ]
10812 ${NS}::button $top.extdifff.b -text [mc "Choose..."] -command choose_extdiff
10813 pack $top.extdifff.l $top.extdifff.b -side left
10814 pack configure $top.extdifff.l -padx 10
10815 grid x $top.extdifff $top.extdifft -sticky ew
10817 ${NS}::label $top.lgen -text [mc "General options"]
10818 grid $top.lgen - -sticky w -pady 10
10819 ${NS}::checkbutton $top.want_ttk -variable want_ttk \
10820 -text [mc "Use themed widgets"]
10822 ${NS}::label $top.ttk_note -text [mc "(change requires restart)"]
10824 ${NS}::label $top.ttk_note -text [mc "(currently unavailable)"]
10826 grid x $top.want_ttk $top.ttk_note -sticky w
10828 ${NS}::label $top.cdisp -text [mc "Colors: press to choose"]
10829 grid $top.cdisp - -sticky w -pady 10
10830 label $top.ui -padx 40 -relief sunk -background $uicolor
10831 ${NS}::button $top.uibut -text [mc "Interface"] \
10832 -command [list choosecolor uicolor {} $top.ui [mc "interface"] setui]
10833 grid x $top.uibut $top.ui -sticky w
10834 label $top.bg -padx 40 -relief sunk -background $bgcolor
10835 ${NS}::button $top.bgbut -text [mc "Background"] \
10836 -command [list choosecolor bgcolor {} $top.bg [mc "background"] setbg]
10837 grid x $top.bgbut $top.bg -sticky w
10838 label $top.fg -padx 40 -relief sunk -background $fgcolor
10839 ${NS}::button $top.fgbut -text [mc "Foreground"] \
10840 -command [list choosecolor fgcolor {} $top.fg [mc "foreground"] setfg]
10841 grid x $top.fgbut $top.fg -sticky w
10842 label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
10843 ${NS}::button $top.diffoldbut -text [mc "Diff: old lines"] \
10844 -command [list choosecolor diffcolors 0 $top.diffold [mc "diff old lines"] \
10845 [list $ctext tag conf d0 -foreground]]
10846 grid x $top.diffoldbut $top.diffold -sticky w
10847 label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
10848 ${NS}::button $top.diffnewbut -text [mc "Diff: new lines"] \
10849 -command [list choosecolor diffcolors 1 $top.diffnew [mc "diff new lines"] \
10850 [list $ctext tag conf dresult -foreground]]
10851 grid x $top.diffnewbut $top.diffnew -sticky w
10852 label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
10853 ${NS}::button $top.hunksepbut -text [mc "Diff: hunk header"] \
10854 -command [list choosecolor diffcolors 2 $top.hunksep \
10855 [mc "diff hunk header"] \
10856 [list $ctext tag conf hunksep -foreground]]
10857 grid x $top.hunksepbut $top.hunksep -sticky w
10858 label $top.markbgsep -padx 40 -relief sunk -background $markbgcolor
10859 ${NS}::button $top.markbgbut -text [mc "Marked line bg"] \
10860 -command [list choosecolor markbgcolor {} $top.markbgsep \
10861 [mc "marked line background"] \
10862 [list $ctext tag conf omark -background]]
10863 grid x $top.markbgbut $top.markbgsep -sticky w
10864 label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor
10865 ${NS}::button $top.selbgbut -text [mc "Select bg"] \
10866 -command [list choosecolor selectbgcolor {} $top.selbgsep [mc "background"] setselbg]
10867 grid x $top.selbgbut $top.selbgsep -sticky w
10869 ${NS}::label $top.cfont -text [mc "Fonts: press to choose"]
10870 grid $top.cfont - -sticky w -pady 10
10871 mkfontdisp mainfont $top [mc "Main font"]
10872 mkfontdisp textfont $top [mc "Diff display font"]
10873 mkfontdisp uifont $top [mc "User interface font"]
10875 ${NS}::frame $top.buts
10876 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
10877 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
10878 bind $top <Key-Return> prefsok
10879 bind $top <Key-Escape> prefscan
10880 grid $top.buts.ok $top.buts.can
10881 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10882 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10883 grid $top.buts - - -pady 10 -sticky ew
10884 grid columnconfigure $top 2 -weight 1
10885 bind $top <Visibility> "focus $top.buts.ok"
10888 proc choose_extdiff {} {
10891 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
10893 set extdifftool $prog
10897 proc choosecolor {v vi w x cmd} {
10900 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
10901 -title [mc "Gitk: choose color for %s" $x]]
10902 if {$c eq {}} return
10903 $w conf -background $c
10908 proc setselbg {c} {
10909 global bglist cflist
10910 foreach w $bglist {
10911 $w configure -selectbackground $c
10913 $cflist tag configure highlight \
10914 -background [$cflist cget -selectbackground]
10915 allcanvs itemconf secsel -fill $c
10918 # This sets the background color and the color scheme for the whole UI.
10919 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
10920 # if we don't specify one ourselves, which makes the checkbuttons and
10921 # radiobuttons look bad. This chooses white for selectColor if the
10922 # background color is light, or black if it is dark.
10924 if {[tk windowingsystem] eq "win32"} { return }
10925 set bg [winfo rgb . $c]
10927 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
10930 tk_setPalette background $c selectColor $selc
10936 foreach w $bglist {
10937 $w conf -background $c
10944 foreach w $fglist {
10945 $w conf -foreground $c
10947 allcanvs itemconf text -fill $c
10948 $canv itemconf circle -outline $c
10949 $canv itemconf markid -outline $c
10953 global oldprefs prefstop
10955 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
10956 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
10958 set $v $oldprefs($v)
10960 catch {destroy $prefstop}
10966 global maxwidth maxgraphpct
10967 global oldprefs prefstop showneartags showlocalchanges
10968 global fontpref mainfont textfont uifont
10969 global limitdiffs treediffs perfile_attrs
10972 catch {destroy $prefstop}
10976 if {$mainfont ne $fontpref(mainfont)} {
10977 set mainfont $fontpref(mainfont)
10978 parsefont mainfont $mainfont
10979 eval font configure mainfont [fontflags mainfont]
10980 eval font configure mainfontbold [fontflags mainfont 1]
10984 if {$textfont ne $fontpref(textfont)} {
10985 set textfont $fontpref(textfont)
10986 parsefont textfont $textfont
10987 eval font configure textfont [fontflags textfont]
10988 eval font configure textfontbold [fontflags textfont 1]
10990 if {$uifont ne $fontpref(uifont)} {
10991 set uifont $fontpref(uifont)
10992 parsefont uifont $uifont
10993 eval font configure uifont [fontflags uifont]
10996 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
10997 if {$showlocalchanges} {
11003 if {$limitdiffs != $oldprefs(limitdiffs) ||
11004 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11005 # treediffs elements are limited by path;
11006 # won't have encodings cached if perfile_attrs was just turned on
11007 catch {unset treediffs}
11009 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11010 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11012 } elseif {$showneartags != $oldprefs(showneartags) ||
11013 $limitdiffs != $oldprefs(limitdiffs)} {
11016 if {$hideremotes != $oldprefs(hideremotes)} {
11021 proc formatdate {d} {
11022 global datetimeformat
11024 set d [clock format $d -format $datetimeformat]
11029 # This list of encoding names and aliases is distilled from
11030 # http://www.iana.org/assignments/character-sets.
11031 # Not all of them are supported by Tcl.
11032 set encoding_aliases {
11033 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11034 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11035 { ISO-10646-UTF-1 csISO10646UTF1 }
11036 { ISO_646.basic:1983 ref csISO646basic1983 }
11037 { INVARIANT csINVARIANT }
11038 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11039 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11040 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11041 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11042 { NATS-DANO iso-ir-9-1 csNATSDANO }
11043 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11044 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11045 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11046 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11047 { ISO-2022-KR csISO2022KR }
11049 { ISO-2022-JP csISO2022JP }
11050 { ISO-2022-JP-2 csISO2022JP2 }
11051 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11052 csISO13JISC6220jp }
11053 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11054 { IT iso-ir-15 ISO646-IT csISO15Italian }
11055 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11056 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11057 { greek7-old iso-ir-18 csISO18Greek7Old }
11058 { latin-greek iso-ir-19 csISO19LatinGreek }
11059 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11060 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11061 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11062 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11063 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11064 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11065 { INIS iso-ir-49 csISO49INIS }
11066 { INIS-8 iso-ir-50 csISO50INIS8 }
11067 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11068 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11069 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11070 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11071 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11072 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11073 csISO60Norwegian1 }
11074 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11075 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11076 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11077 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11078 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11079 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11080 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11081 { greek7 iso-ir-88 csISO88Greek7 }
11082 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11083 { iso-ir-90 csISO90 }
11084 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11085 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11086 csISO92JISC62991984b }
11087 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11088 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11089 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11090 csISO95JIS62291984handadd }
11091 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11092 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11093 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11094 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11095 CP819 csISOLatin1 }
11096 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11097 { T.61-7bit iso-ir-102 csISO102T617bit }
11098 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11099 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11100 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11101 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11102 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11103 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11104 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11105 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11106 arabic csISOLatinArabic }
11107 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11108 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11109 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11110 greek greek8 csISOLatinGreek }
11111 { T.101-G2 iso-ir-128 csISO128T101G2 }
11112 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11114 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11115 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11116 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11117 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11118 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11119 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11120 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11121 csISOLatinCyrillic }
11122 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11123 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11124 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11125 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11126 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11127 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11128 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11129 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11130 { ISO_10367-box iso-ir-155 csISO10367Box }
11131 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11132 { latin-lap lap iso-ir-158 csISO158Lap }
11133 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11134 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11137 { JIS_X0201 X0201 csHalfWidthKatakana }
11138 { KSC5636 ISO646-KR csKSC5636 }
11139 { ISO-10646-UCS-2 csUnicode }
11140 { ISO-10646-UCS-4 csUCS4 }
11141 { DEC-MCS dec csDECMCS }
11142 { hp-roman8 roman8 r8 csHPRoman8 }
11143 { macintosh mac csMacintosh }
11144 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11146 { IBM038 EBCDIC-INT cp038 csIBM038 }
11147 { IBM273 CP273 csIBM273 }
11148 { IBM274 EBCDIC-BE CP274 csIBM274 }
11149 { IBM275 EBCDIC-BR cp275 csIBM275 }
11150 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11151 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11152 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11153 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11154 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11155 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11156 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11157 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11158 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11159 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11160 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11161 { IBM437 cp437 437 csPC8CodePage437 }
11162 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11163 { IBM775 cp775 csPC775Baltic }
11164 { IBM850 cp850 850 csPC850Multilingual }
11165 { IBM851 cp851 851 csIBM851 }
11166 { IBM852 cp852 852 csPCp852 }
11167 { IBM855 cp855 855 csIBM855 }
11168 { IBM857 cp857 857 csIBM857 }
11169 { IBM860 cp860 860 csIBM860 }
11170 { IBM861 cp861 861 cp-is csIBM861 }
11171 { IBM862 cp862 862 csPC862LatinHebrew }
11172 { IBM863 cp863 863 csIBM863 }
11173 { IBM864 cp864 csIBM864 }
11174 { IBM865 cp865 865 csIBM865 }
11175 { IBM866 cp866 866 csIBM866 }
11176 { IBM868 CP868 cp-ar csIBM868 }
11177 { IBM869 cp869 869 cp-gr csIBM869 }
11178 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11179 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11180 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11181 { IBM891 cp891 csIBM891 }
11182 { IBM903 cp903 csIBM903 }
11183 { IBM904 cp904 904 csIBBM904 }
11184 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11185 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11186 { IBM1026 CP1026 csIBM1026 }
11187 { EBCDIC-AT-DE csIBMEBCDICATDE }
11188 { EBCDIC-AT-DE-A csEBCDICATDEA }
11189 { EBCDIC-CA-FR csEBCDICCAFR }
11190 { EBCDIC-DK-NO csEBCDICDKNO }
11191 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11192 { EBCDIC-FI-SE csEBCDICFISE }
11193 { EBCDIC-FI-SE-A csEBCDICFISEA }
11194 { EBCDIC-FR csEBCDICFR }
11195 { EBCDIC-IT csEBCDICIT }
11196 { EBCDIC-PT csEBCDICPT }
11197 { EBCDIC-ES csEBCDICES }
11198 { EBCDIC-ES-A csEBCDICESA }
11199 { EBCDIC-ES-S csEBCDICESS }
11200 { EBCDIC-UK csEBCDICUK }
11201 { EBCDIC-US csEBCDICUS }
11202 { UNKNOWN-8BIT csUnknown8BiT }
11203 { MNEMONIC csMnemonic }
11205 { VISCII csVISCII }
11208 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11209 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11210 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11211 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11212 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11213 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11214 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11215 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11216 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11217 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11218 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11219 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11220 { IBM1047 IBM-1047 }
11221 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11222 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11223 { UNICODE-1-1 csUnicode11 }
11224 { CESU-8 csCESU-8 }
11225 { BOCU-1 csBOCU-1 }
11226 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11227 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11229 { ISO-8859-15 ISO_8859-15 Latin-9 }
11230 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11231 { GBK CP936 MS936 windows-936 }
11232 { JIS_Encoding csJISEncoding }
11233 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11234 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11236 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11237 { ISO-10646-UCS-Basic csUnicodeASCII }
11238 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11239 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11240 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11241 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11242 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11243 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11244 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11245 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11246 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11247 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11248 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11249 { Ventura-US csVenturaUS }
11250 { Ventura-International csVenturaInternational }
11251 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11252 { PC8-Turkish csPC8Turkish }
11253 { IBM-Symbols csIBMSymbols }
11254 { IBM-Thai csIBMThai }
11255 { HP-Legal csHPLegal }
11256 { HP-Pi-font csHPPiFont }
11257 { HP-Math8 csHPMath8 }
11258 { Adobe-Symbol-Encoding csHPPSMath }
11259 { HP-DeskTop csHPDesktop }
11260 { Ventura-Math csVenturaMath }
11261 { Microsoft-Publishing csMicrosoftPublishing }
11262 { Windows-31J csWindows31J }
11263 { GB2312 csGB2312 }
11267 proc tcl_encoding {enc} {
11268 global encoding_aliases tcl_encoding_cache
11269 if {[info exists tcl_encoding_cache($enc)]} {
11270 return $tcl_encoding_cache($enc)
11272 set names [encoding names]
11273 set lcnames [string tolower $names]
11274 set enc [string tolower $enc]
11275 set i [lsearch -exact $lcnames $enc]
11277 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11278 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11279 set i [lsearch -exact $lcnames $encx]
11283 foreach l $encoding_aliases {
11284 set ll [string tolower $l]
11285 if {[lsearch -exact $ll $enc] < 0} continue
11286 # look through the aliases for one that tcl knows about
11288 set i [lsearch -exact $lcnames $e]
11290 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11291 set i [lsearch -exact $lcnames $ex]
11301 set tclenc [lindex $names $i]
11303 set tcl_encoding_cache($enc) $tclenc
11307 proc gitattr {path attr default} {
11308 global path_attr_cache
11309 if {[info exists path_attr_cache($attr,$path)]} {
11310 set r $path_attr_cache($attr,$path)
11312 set r "unspecified"
11313 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11314 regexp "(.*): $attr: (.*)" $line m f r
11316 set path_attr_cache($attr,$path) $r
11318 if {$r eq "unspecified"} {
11324 proc cache_gitattr {attr pathlist} {
11325 global path_attr_cache
11327 foreach path $pathlist {
11328 if {![info exists path_attr_cache($attr,$path)]} {
11329 lappend newlist $path
11333 if {[tk windowingsystem] == "win32"} {
11334 # windows has a 32k limit on the arguments to a command...
11337 while {$newlist ne {}} {
11338 set head [lrange $newlist 0 [expr {$lim - 1}]]
11339 set newlist [lrange $newlist $lim end]
11340 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11341 foreach row [split $rlist "\n"] {
11342 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11343 if {[string index $path 0] eq "\""} {
11344 set path [encoding convertfrom [lindex $path 0]]
11346 set path_attr_cache($attr,$path) $value
11353 proc get_path_encoding {path} {
11354 global gui_encoding perfile_attrs
11355 set tcl_enc $gui_encoding
11356 if {$path ne {} && $perfile_attrs} {
11357 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11365 # First check that Tcl/Tk is recent enough
11366 if {[catch {package require Tk 8.4} err]} {
11367 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11368 Gitk requires at least Tcl/Tk 8.4." list
11373 set wrcomcmd "git diff-tree --stdin -p --pretty"
11377 set gitencoding [exec git config --get i18n.commitencoding]
11380 set gitencoding [exec git config --get i18n.logoutputencoding]
11382 if {$gitencoding == ""} {
11383 set gitencoding "utf-8"
11385 set tclencoding [tcl_encoding $gitencoding]
11386 if {$tclencoding == {}} {
11387 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11390 set gui_encoding [encoding system]
11392 set enc [exec git config --get gui.encoding]
11394 set tclenc [tcl_encoding $enc]
11395 if {$tclenc ne {}} {
11396 set gui_encoding $tclenc
11398 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11403 if {[tk windowingsystem] eq "aqua"} {
11404 set mainfont {{Lucida Grande} 9}
11405 set textfont {Monaco 9}
11406 set uifont {{Lucida Grande} 9 bold}
11408 set mainfont {Helvetica 9}
11409 set textfont {Courier 9}
11410 set uifont {Helvetica 9 bold}
11413 set findmergefiles 0
11421 set cmitmode "patch"
11422 set wrapcomment "none"
11427 set showlocalchanges 1
11429 set datetimeformat "%Y-%m-%d %H:%M:%S"
11432 set perfile_attrs 0
11435 if {[tk windowingsystem] eq "aqua"} {
11436 set extdifftool "opendiff"
11438 set extdifftool "meld"
11441 set colors {green red blue magenta darkgrey brown orange}
11442 if {[tk windowingsystem] eq "win32"} {
11443 set uicolor SystemButtonFace
11444 set bgcolor SystemWindow
11445 set fgcolor SystemButtonText
11446 set selectbgcolor SystemHighlight
11451 set selectbgcolor gray85
11453 set diffcolors {red "#00a000" blue}
11457 set markbgcolor "#e0e0ff"
11459 set circlecolors {white blue gray blue blue}
11461 # button for popping up context menus
11462 if {[tk windowingsystem] eq "aqua"} {
11463 set ctxbut <Button-2>
11465 set ctxbut <Button-3>
11468 ## For msgcat loading, first locate the installation location.
11469 if { [info exists ::env(GITK_MSGSDIR)] } {
11470 ## Msgsdir was manually set in the environment.
11471 set gitk_msgsdir $::env(GITK_MSGSDIR)
11473 ## Let's guess the prefix from argv0.
11474 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11475 set gitk_libdir [file join $gitk_prefix share gitk lib]
11476 set gitk_msgsdir [file join $gitk_libdir msgs]
11480 ## Internationalization (i18n) through msgcat and gettext. See
11481 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11482 package require msgcat
11483 namespace import ::msgcat::mc
11484 ## And eventually load the actual message catalog
11485 ::msgcat::mcload $gitk_msgsdir
11487 catch {source ~/.gitk}
11489 parsefont mainfont $mainfont
11490 eval font create mainfont [fontflags mainfont]
11491 eval font create mainfontbold [fontflags mainfont 1]
11493 parsefont textfont $textfont
11494 eval font create textfont [fontflags textfont]
11495 eval font create textfontbold [fontflags textfont 1]
11497 parsefont uifont $uifont
11498 eval font create uifont [fontflags uifont]
11504 # check that we can find a .git directory somewhere...
11505 if {[catch {set gitdir [gitdir]}]} {
11506 show_error {} . [mc "Cannot find a git repository here."]
11509 if {![file isdirectory $gitdir]} {
11510 show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir]
11515 set selectheadid {}
11518 set cmdline_files {}
11520 set revtreeargscmd {}
11521 foreach arg $argv {
11522 switch -glob -- $arg {
11525 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11528 "--select-commit=*" {
11529 set selecthead [string range $arg 16 end]
11532 set revtreeargscmd [string range $arg 10 end]
11535 lappend revtreeargs $arg
11541 if {$selecthead eq "HEAD"} {
11545 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11546 # no -- on command line, but some arguments (other than --argscmd)
11548 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11549 set cmdline_files [split $f "\n"]
11550 set n [llength $cmdline_files]
11551 set revtreeargs [lrange $revtreeargs 0 end-$n]
11552 # Unfortunately git rev-parse doesn't produce an error when
11553 # something is both a revision and a filename. To be consistent
11554 # with git log and git rev-list, check revtreeargs for filenames.
11555 foreach arg $revtreeargs {
11556 if {[file exists $arg]} {
11557 show_error {} . [mc "Ambiguous argument '%s': both revision\
11558 and filename" $arg]
11563 # unfortunately we get both stdout and stderr in $err,
11564 # so look for "fatal:".
11565 set i [string first "fatal:" $err]
11567 set err [string range $err [expr {$i + 6}] end]
11569 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
11574 set nullid "0000000000000000000000000000000000000000"
11575 set nullid2 "0000000000000000000000000000000000000001"
11576 set nullfile "/dev/null"
11578 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
11579 if {![info exists have_ttk]} {
11580 set have_ttk [llength [info commands ::ttk::style]]
11582 set use_ttk [expr {$have_ttk && $want_ttk}]
11583 set NS [expr {$use_ttk ? "ttk" : ""}]
11585 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
11588 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
11589 set show_notes "--show-notes"
11597 set highlight_paths {}
11599 set searchdirn -forwards
11602 set diffelide {0 0}
11603 set markingmatches 0
11604 set linkentercount 0
11605 set need_redisplay 0
11612 set selectedhlview [mc "None"]
11613 set highlight_related [mc "None"]
11614 set highlight_files {}
11615 set viewfiles(0) {}
11618 set viewargscmd(0) {}
11620 set selectedline {}
11628 set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}]
11632 image create photo gitlogo -width 16 -height 16
11634 image create photo gitlogominus -width 4 -height 2
11635 gitlogominus put #C00000 -to 0 0 4 2
11636 gitlogo copy gitlogominus -to 1 5
11637 gitlogo copy gitlogominus -to 6 5
11638 gitlogo copy gitlogominus -to 11 5
11639 image delete gitlogominus
11641 image create photo gitlogoplus -width 4 -height 4
11642 gitlogoplus put #008000 -to 1 0 3 4
11643 gitlogoplus put #008000 -to 0 1 4 3
11644 gitlogo copy gitlogoplus -to 1 9
11645 gitlogo copy gitlogoplus -to 6 9
11646 gitlogo copy gitlogoplus -to 11 9
11647 image delete gitlogoplus
11649 image create photo gitlogo32 -width 32 -height 32
11650 gitlogo32 copy gitlogo -zoom 2 2
11652 wm iconphoto . -default gitlogo gitlogo32
11654 # wait for the window to become visible
11655 tkwait visibility .
11656 wm title . "[file tail $argv0]: [file tail [pwd]]"
11660 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
11661 # create a view for the files/dirs specified on the command line
11665 set viewname(1) [mc "Command line"]
11666 set viewfiles(1) $cmdline_files
11667 set viewargs(1) $revtreeargs
11668 set viewargscmd(1) $revtreeargscmd
11672 .bar.view entryconf [mca "Edit view..."] -state normal
11673 .bar.view entryconf [mca "Delete view"] -state normal
11676 if {[info exists permviews]} {
11677 foreach v $permviews {
11680 set viewname($n) [lindex $v 0]
11681 set viewfiles($n) [lindex $v 1]
11682 set viewargs($n) [lindex $v 2]
11683 set viewargscmd($n) [lindex $v 3]
11689 if {[tk windowingsystem] eq "win32"} {
11697 # indent-tabs-mode: t