2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2011 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 if {[info exists _gitworktree
]} {
22 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
23 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
24 # try to set work tree from environment, core.worktree or use
25 # cdup to obtain a relative path to the top of the worktree. If
26 # run from the top, the ./ prefix ensures normalize expands pwd.
27 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
28 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
29 if {$_gitworktree eq
""} {
30 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
37 # A simple scheduler for compute-intensive stuff.
38 # The aim is to make sure that event handlers for GUI actions can
39 # run at least every 50-100 ms. Unfortunately fileevent handlers are
40 # run before X event handlers, so reading from a fast source can
41 # make the GUI completely unresponsive.
43 global isonrunq runq currunq
46 if {[info exists isonrunq
($script)]} return
47 if {$runq eq
{} && ![info exists currunq
]} {
50 lappend runq
[list
{} $script]
51 set isonrunq
($script) 1
54 proc filerun
{fd
script} {
55 fileevent
$fd readable
[list filereadable
$fd $script]
58 proc filereadable
{fd
script} {
61 fileevent
$fd readable
{}
62 if {$runq eq
{} && ![info exists currunq
]} {
65 lappend runq
[list
$fd $script]
71 for {set i
0} {$i < [llength
$runq]} {} {
72 if {[lindex
$runq $i 0] eq
$fd} {
73 set runq
[lreplace
$runq $i $i]
81 global isonrunq runq currunq
83 set tstart
[clock clicks
-milliseconds]
85 while {[llength
$runq] > 0} {
86 set fd
[lindex
$runq 0 0]
87 set script [lindex
$runq 0 1]
88 set currunq
[lindex
$runq 0]
89 set runq
[lrange
$runq 1 end
]
90 set repeat
[eval $script]
92 set t1
[clock clicks
-milliseconds]
93 set t
[expr {$t1 - $t0}]
94 if {$repeat ne
{} && $repeat} {
95 if {$fd eq
{} ||
$repeat == 2} {
96 # script returns 1 if it wants to be readded
97 # file readers return 2 if they could do more straight away
98 lappend runq
[list
$fd $script]
100 fileevent
$fd readable
[list filereadable
$fd $script]
102 } elseif
{$fd eq
{}} {
103 unset isonrunq
($script)
106 if {$t1 - $tstart >= 80} break
113 proc reg_instance
{fd
} {
114 global commfd leftover loginstance
116 set i
[incr loginstance
]
122 proc unmerged_files
{files
} {
125 # find the list of unmerged files
129 set fd
[open
"| git ls-files -u" r
]
131 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
134 while {[gets $fd line] >= 0} {
135 set i [string first "\t" $line]
137 set fname [string range $line [expr {$i+1}] end]
138 if {[lsearch -exact $mlist $fname] >= 0} continue
140 if {$files eq {} || [path_filter $files $fname]} {
148 proc parseviewargs {n arglist} {
149 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
150 global worddiff git_version
158 set origargs $arglist
162 foreach arg $arglist {
169 switch -glob -- $arg {
173 # remove from origargs in case we hit an unknown option
174 set origargs [lreplace $origargs $i $i]
178 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
179 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
180 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
181 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
182 "--ignore-space-change" - "-U*" - "--unified=*" {
183 # These request or affect diff output, which we don't want.
184 # Some could be used to set our defaults for diff display.
185 lappend diffargs
$arg
187 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
188 "--name-only" - "--name-status" - "--color" -
189 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
190 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
191 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
192 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
193 "--objects" - "--objects-edge" - "--reverse" {
194 # These cause our parsing of git log's output to fail, or else
195 # they're options we want to set ourselves, so ignore them.
197 "--color-words*" - "--word-diff=color" {
198 # These trigger a word diff in the console interface,
199 # so help the user by enabling our own support
200 if {[package vcompare
$git_version "1.7.2"] >= 0} {
201 set worddiff
[mc
"Color words"]
205 if {[package vcompare
$git_version "1.7.2"] >= 0} {
206 set worddiff
[mc
"Markup words"]
209 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
210 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
211 "--full-history" - "--dense" - "--sparse" -
212 "--follow" - "--left-right" - "--encoding=*" {
213 # These are harmless, and some are even useful
216 "--diff-filter=*" - "--no-merges" - "--unpacked" -
217 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
218 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
219 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
220 "--remove-empty" - "--first-parent" - "--cherry-pick" -
221 "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
222 "--simplify-by-decoration" {
223 # These mean that we get a subset of the commits
228 # This appears to be the only one that has a value as a
229 # separate word following it
239 # git rev-parse doesn't understand --merge
240 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
242 "--no-replace-objects" {
243 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
246 # Other flag arguments including -<n>
247 if {[string is digit
-strict [string range
$arg 1 end
]]} {
250 # a flag argument that we don't recognize;
251 # that means we can't optimize
257 # Non-flag arguments specify commits or ranges of commits
258 if {[string match
"*...*" $arg]} {
259 lappend revargs
--gitk-symmetric-diff-marker
265 set vdflags
($n) $diffargs
266 set vflags
($n) $glflags
267 set vrevs
($n) $revargs
268 set vfiltered
($n) $filtered
269 set vorigargs
($n) $origargs
273 proc parseviewrevs
{view revs
} {
274 global vposids vnegids
279 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
280 # we get stdout followed by stderr in $err
281 # for an unknown rev, git rev-parse echoes it and then errors out
282 set errlines
[split $err "\n"]
284 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
285 set line
[lindex
$errlines $l]
286 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
287 if {[string match
"fatal:*" $line]} {
288 if {[string match
"fatal: ambiguous argument*" $line]
290 if {[llength
$badrev] == 1} {
291 set err
"unknown revision $badrev"
293 set err
"unknown revisions: [join $badrev ", "]"
296 set err
[join [lrange
$errlines $l end
] "\n"]
303 error_popup
"[mc "Error parsing revisions
:"] $err"
310 foreach id
[split $ids "\n"] {
311 if {$id eq
"--gitk-symmetric-diff-marker"} {
313 } elseif
{[string match
"^*" $id]} {
320 lappend neg
[string range
$id 1 end
]
325 lset ret end
$id...
[lindex
$ret end
]
331 set vposids
($view) $pos
332 set vnegids
($view) $neg
336 # Start off a git log process and arrange to read its output
337 proc start_rev_list
{view
} {
338 global startmsecs commitidx viewcomplete curview
340 global viewargs viewargscmd viewfiles vfilelimit
341 global showlocalchanges
342 global viewactive viewinstances vmergeonly
343 global mainheadid viewmainheadid viewmainheadid_orig
344 global vcanopt vflags vrevs vorigargs
347 set startmsecs
[clock clicks
-milliseconds]
348 set commitidx
($view) 0
349 # these are set this way for the error exits
350 set viewcomplete
($view) 1
351 set viewactive
($view) 0
354 set args
$viewargs($view)
355 if {$viewargscmd($view) ne
{}} {
357 set str
[exec sh
-c $viewargscmd($view)]
359 error_popup
"[mc "Error executing
--argscmd command:"] $err"
362 set args
[concat
$args [split $str "\n"]]
364 set vcanopt
($view) [parseviewargs
$view $args]
366 set files
$viewfiles($view)
367 if {$vmergeonly($view)} {
368 set files
[unmerged_files
$files]
371 if {$nr_unmerged == 0} {
372 error_popup
[mc
"No files selected: --merge specified but\
373 no files are unmerged."]
375 error_popup
[mc
"No files selected: --merge specified but\
376 no unmerged files are within file limit."]
381 set vfilelimit
($view) $files
383 if {$vcanopt($view)} {
384 set revs
[parseviewrevs
$view $vrevs($view)]
388 set args
[limit_arg_length
[concat
$vflags($view) $revs]]
390 set args
$vorigargs($view)
394 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
395 --parents --boundary $args "--" $files] r
]
397 error_popup
"[mc "Error executing git log
:"] $err"
400 set i
[reg_instance
$fd]
401 set viewinstances
($view) [list
$i]
402 set viewmainheadid
($view) $mainheadid
403 set viewmainheadid_orig
($view) $mainheadid
404 if {$files ne
{} && $mainheadid ne
{}} {
405 get_viewmainhead
$view
407 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
408 interestedin
$viewmainheadid($view) dodiffindex
410 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
411 if {$tclencoding != {}} {
412 fconfigure
$fd -encoding $tclencoding
414 filerun
$fd [list getcommitlines
$fd $i $view 0]
415 nowbusy
$view [mc
"Reading"]
416 set viewcomplete
($view) 0
417 set viewactive
($view) 1
421 proc stop_instance
{inst
} {
422 global commfd leftover
424 set fd
$commfd($inst)
428 if {$
::tcl_platform
(platform
) eq
{windows
}} {
437 unset leftover
($inst)
440 proc stop_backends
{} {
443 foreach inst
[array names commfd
] {
448 proc stop_rev_list
{view
} {
451 foreach inst
$viewinstances($view) {
454 set viewinstances
($view) {}
457 proc reset_pending_select
{selid
} {
458 global pending_select mainheadid selectheadid
461 set pending_select
$selid
462 } elseif
{$selectheadid ne
{}} {
463 set pending_select
$selectheadid
465 set pending_select
$mainheadid
469 proc getcommits
{selid
} {
470 global canv curview need_redisplay viewactive
473 if {[start_rev_list
$curview]} {
474 reset_pending_select
$selid
475 show_status
[mc
"Reading commits..."]
478 show_status
[mc
"No commits selected"]
482 proc updatecommits
{} {
483 global curview vcanopt vorigargs vfilelimit viewinstances
484 global viewactive viewcomplete tclencoding
485 global startmsecs showneartags showlocalchanges
486 global mainheadid viewmainheadid viewmainheadid_orig pending_select
488 global varcid vposids vnegids vflags vrevs
491 set hasworktree
[hasworktree
]
494 if {$mainheadid ne
$viewmainheadid_orig($view)} {
495 if {$showlocalchanges} {
498 set viewmainheadid
($view) $mainheadid
499 set viewmainheadid_orig
($view) $mainheadid
500 if {$vfilelimit($view) ne
{}} {
501 get_viewmainhead
$view
504 if {$showlocalchanges} {
507 if {$vcanopt($view)} {
508 set oldpos
$vposids($view)
509 set oldneg
$vnegids($view)
510 set revs
[parseviewrevs
$view $vrevs($view)]
514 # note: getting the delta when negative refs change is hard,
515 # and could require multiple git log invocations, so in that
516 # case we ask git log for all the commits (not just the delta)
517 if {$oldneg eq
$vnegids($view)} {
520 # take out positive refs that we asked for before or
521 # that we have already seen
523 if {[string length
$rev] == 40} {
524 if {[lsearch
-exact $oldpos $rev] < 0
525 && ![info exists varcid
($view,$rev)]} {
530 lappend
$newrevs $rev
533 if {$npos == 0} return
535 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
537 set args
[concat
$vflags($view) $revs --not $oldpos]
539 set args
$vorigargs($view)
542 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
543 --parents --boundary $args "--" $vfilelimit($view)] r
]
545 error_popup
"[mc "Error executing git log
:"] $err"
548 if {$viewactive($view) == 0} {
549 set startmsecs
[clock clicks
-milliseconds]
551 set i
[reg_instance
$fd]
552 lappend viewinstances
($view) $i
553 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
554 if {$tclencoding != {}} {
555 fconfigure
$fd -encoding $tclencoding
557 filerun
$fd [list getcommitlines
$fd $i $view 1]
558 incr viewactive
($view)
559 set viewcomplete
($view) 0
560 reset_pending_select
{}
561 nowbusy
$view [mc
"Reading"]
567 proc reloadcommits
{} {
568 global curview viewcomplete selectedline currentid thickerline
569 global showneartags treediffs commitinterest cached_commitrow
573 if {$selectedline ne
{}} {
577 if {!$viewcomplete($curview)} {
578 stop_rev_list
$curview
582 catch
{unset currentid
}
583 catch
{unset thickerline
}
584 catch
{unset treediffs
}
591 catch
{unset commitinterest
}
592 catch
{unset cached_commitrow
}
593 catch
{unset targetid
}
599 # This makes a string representation of a positive integer which
600 # sorts as a string in numerical order
603 return [format
"%x" $n]
604 } elseif
{$n < 256} {
605 return [format
"x%.2x" $n]
606 } elseif
{$n < 65536} {
607 return [format
"y%.4x" $n]
609 return [format
"z%.8x" $n]
612 # Procedures used in reordering commits from git log (without
613 # --topo-order) into the order for display.
615 proc varcinit
{view
} {
616 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
617 global vtokmod varcmod vrowmod varcix vlastins
619 set varcstart
($view) {{}}
620 set vupptr
($view) {0}
621 set vdownptr
($view) {0}
622 set vleftptr
($view) {0}
623 set vbackptr
($view) {0}
624 set varctok
($view) {{}}
625 set varcrow
($view) {{}}
626 set vtokmod
($view) {}
629 set varcix
($view) {{}}
630 set vlastins
($view) {0}
633 proc resetvarcs
{view
} {
634 global varcid varccommits parents children vseedcount ordertok
636 foreach vid
[array names varcid
$view,*] {
641 # some commits might have children but haven't been seen yet
642 foreach vid
[array names children
$view,*] {
645 foreach va
[array names varccommits
$view,*] {
646 unset varccommits
($va)
648 foreach vd
[array names vseedcount
$view,*] {
649 unset vseedcount
($vd)
651 catch
{unset ordertok
}
654 # returns a list of the commits with no children
656 global vdownptr vleftptr varcstart
659 set a
[lindex
$vdownptr($v) 0]
661 lappend ret
[lindex
$varcstart($v) $a]
662 set a
[lindex
$vleftptr($v) $a]
667 proc newvarc
{view id
} {
668 global varcid varctok parents children vdatemode
669 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
670 global commitdata commitinfo vseedcount varccommits vlastins
672 set a
[llength
$varctok($view)]
674 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
675 if {![info exists commitinfo
($id)]} {
676 parsecommit
$id $commitdata($id) 1
678 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
679 if {![string is integer
-strict $cdate]} {
682 if {![info exists vseedcount
($view,$cdate)]} {
683 set vseedcount
($view,$cdate) -1
685 set c
[incr vseedcount
($view,$cdate)]
686 set cdate
[expr {$cdate ^
0xffffffff}]
687 set tok
"s[strrep $cdate][strrep $c]"
692 if {[llength
$children($vid)] > 0} {
693 set kid
[lindex
$children($vid) end
]
694 set k
$varcid($view,$kid)
695 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
698 set tok
[lindex
$varctok($view) $k]
702 set i
[lsearch
-exact $parents($view,$ki) $id]
703 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
704 append tok
[strrep
$j]
706 set c
[lindex
$vlastins($view) $ka]
707 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
709 set b
[lindex
$vdownptr($view) $ka]
711 set b
[lindex
$vleftptr($view) $c]
713 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
715 set b
[lindex
$vleftptr($view) $c]
718 lset vdownptr
($view) $ka $a
719 lappend vbackptr
($view) 0
721 lset vleftptr
($view) $c $a
722 lappend vbackptr
($view) $c
724 lset vlastins
($view) $ka $a
725 lappend vupptr
($view) $ka
726 lappend vleftptr
($view) $b
728 lset vbackptr
($view) $b $a
730 lappend varctok
($view) $tok
731 lappend varcstart
($view) $id
732 lappend vdownptr
($view) 0
733 lappend varcrow
($view) {}
734 lappend varcix
($view) {}
735 set varccommits
($view,$a) {}
736 lappend vlastins
($view) 0
740 proc splitvarc
{p v
} {
741 global varcid varcstart varccommits varctok vtokmod
742 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
744 set oa
$varcid($v,$p)
745 set otok
[lindex
$varctok($v) $oa]
746 set ac
$varccommits($v,$oa)
747 set i
[lsearch
-exact $varccommits($v,$oa) $p]
749 set na
[llength
$varctok($v)]
750 # "%" sorts before "0"...
751 set tok
"$otok%[strrep $i]"
752 lappend varctok
($v) $tok
753 lappend varcrow
($v) {}
754 lappend varcix
($v) {}
755 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
756 set varccommits
($v,$na) [lrange
$ac $i end
]
757 lappend varcstart
($v) $p
758 foreach id
$varccommits($v,$na) {
759 set varcid
($v,$id) $na
761 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
762 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
763 lset vdownptr
($v) $oa $na
764 lset vlastins
($v) $oa 0
765 lappend vupptr
($v) $oa
766 lappend vleftptr
($v) 0
767 lappend vbackptr
($v) 0
768 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
769 lset vupptr
($v) $b $na
771 if {[string compare
$otok $vtokmod($v)] <= 0} {
776 proc renumbervarc
{a v
} {
777 global parents children varctok varcstart varccommits
778 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
780 set t1
[clock clicks
-milliseconds]
786 if {[info exists isrelated
($a)]} {
788 set id
[lindex
$varccommits($v,$a) end
]
789 foreach p
$parents($v,$id) {
790 if {[info exists varcid
($v,$p)]} {
791 set isrelated
($varcid($v,$p)) 1
796 set b
[lindex
$vdownptr($v) $a]
799 set b
[lindex
$vleftptr($v) $a]
801 set a
[lindex
$vupptr($v) $a]
807 if {![info exists kidchanged
($a)]} continue
808 set id
[lindex
$varcstart($v) $a]
809 if {[llength
$children($v,$id)] > 1} {
810 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
813 set oldtok
[lindex
$varctok($v) $a]
814 if {!$vdatemode($v)} {
820 set kid
[last_real_child
$v,$id]
822 set k
$varcid($v,$kid)
823 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
826 set tok
[lindex
$varctok($v) $k]
830 set i
[lsearch
-exact $parents($v,$ki) $id]
831 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
832 append tok
[strrep
$j]
834 if {$tok eq
$oldtok} {
837 set id
[lindex
$varccommits($v,$a) end
]
838 foreach p
$parents($v,$id) {
839 if {[info exists varcid
($v,$p)]} {
840 set kidchanged
($varcid($v,$p)) 1
845 lset varctok
($v) $a $tok
846 set b
[lindex
$vupptr($v) $a]
848 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
851 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
854 set c
[lindex
$vbackptr($v) $a]
855 set d
[lindex
$vleftptr($v) $a]
857 lset vdownptr
($v) $b $d
859 lset vleftptr
($v) $c $d
862 lset vbackptr
($v) $d $c
864 if {[lindex
$vlastins($v) $b] == $a} {
865 lset vlastins
($v) $b $c
867 lset vupptr
($v) $a $ka
868 set c
[lindex
$vlastins($v) $ka]
870 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
872 set b
[lindex
$vdownptr($v) $ka]
874 set b
[lindex
$vleftptr($v) $c]
877 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
879 set b
[lindex
$vleftptr($v) $c]
882 lset vdownptr
($v) $ka $a
883 lset vbackptr
($v) $a 0
885 lset vleftptr
($v) $c $a
886 lset vbackptr
($v) $a $c
888 lset vleftptr
($v) $a $b
890 lset vbackptr
($v) $b $a
892 lset vlastins
($v) $ka $a
895 foreach id
[array names sortkids
] {
896 if {[llength
$children($v,$id)] > 1} {
897 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
901 set t2
[clock clicks
-milliseconds]
902 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
905 # Fix up the graph after we have found out that in view $v,
906 # $p (a commit that we have already seen) is actually the parent
907 # of the last commit in arc $a.
908 proc fix_reversal
{p a v
} {
909 global varcid varcstart varctok vupptr
911 set pa
$varcid($v,$p)
912 if {$p ne
[lindex
$varcstart($v) $pa]} {
914 set pa
$varcid($v,$p)
916 # seeds always need to be renumbered
917 if {[lindex
$vupptr($v) $pa] == 0 ||
918 [string compare
[lindex
$varctok($v) $a] \
919 [lindex
$varctok($v) $pa]] > 0} {
924 proc insertrow
{id p v
} {
925 global cmitlisted children parents varcid varctok vtokmod
926 global varccommits ordertok commitidx numcommits curview
927 global targetid targetrow
931 set cmitlisted
($vid) 1
932 set children
($vid) {}
933 set parents
($vid) [list
$p]
934 set a
[newvarc
$v $id]
936 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
939 lappend varccommits
($v,$a) $id
941 if {[llength
[lappend children
($vp) $id]] > 1} {
942 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
943 catch
{unset ordertok
}
945 fix_reversal
$p $a $v
947 if {$v == $curview} {
948 set numcommits
$commitidx($v)
950 if {[info exists targetid
]} {
951 if {![comes_before
$targetid $p]} {
958 proc insertfakerow
{id p
} {
959 global varcid varccommits parents children cmitlisted
960 global commitidx varctok vtokmod targetid targetrow curview numcommits
964 set i
[lsearch
-exact $varccommits($v,$a) $p]
966 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
969 set children
($v,$id) {}
970 set parents
($v,$id) [list
$p]
971 set varcid
($v,$id) $a
972 lappend children
($v,$p) $id
973 set cmitlisted
($v,$id) 1
974 set numcommits
[incr commitidx
($v)]
975 # note we deliberately don't update varcstart($v) even if $i == 0
976 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
978 if {[info exists targetid
]} {
979 if {![comes_before
$targetid $p]} {
987 proc removefakerow
{id
} {
988 global varcid varccommits parents children commitidx
989 global varctok vtokmod cmitlisted currentid selectedline
990 global targetid curview numcommits
993 if {[llength
$parents($v,$id)] != 1} {
994 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
997 set p
[lindex
$parents($v,$id) 0]
998 set a
$varcid($v,$id)
999 set i
[lsearch
-exact $varccommits($v,$a) $id]
1001 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1004 unset varcid
($v,$id)
1005 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1006 unset parents
($v,$id)
1007 unset children
($v,$id)
1008 unset cmitlisted
($v,$id)
1009 set numcommits
[incr commitidx
($v) -1]
1010 set j
[lsearch
-exact $children($v,$p) $id]
1012 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1015 if {[info exist currentid
] && $id eq
$currentid} {
1019 if {[info exists targetid
] && $targetid eq
$id} {
1026 proc real_children
{vp
} {
1027 global children nullid nullid2
1030 foreach id
$children($vp) {
1031 if {$id ne
$nullid && $id ne
$nullid2} {
1038 proc first_real_child
{vp
} {
1039 global children nullid nullid2
1041 foreach id
$children($vp) {
1042 if {$id ne
$nullid && $id ne
$nullid2} {
1049 proc last_real_child
{vp
} {
1050 global children nullid nullid2
1052 set kids
$children($vp)
1053 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1054 set id
[lindex
$kids $i]
1055 if {$id ne
$nullid && $id ne
$nullid2} {
1062 proc vtokcmp
{v a b
} {
1063 global varctok varcid
1065 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1066 [lindex
$varctok($v) $varcid($v,$b)]]
1069 # This assumes that if lim is not given, the caller has checked that
1070 # arc a's token is less than $vtokmod($v)
1071 proc modify_arc
{v a
{lim
{}}} {
1072 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1075 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1078 set r
[lindex
$varcrow($v) $a]
1079 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1082 set vtokmod
($v) [lindex
$varctok($v) $a]
1084 if {$v == $curview} {
1085 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1086 set a
[lindex
$vupptr($v) $a]
1092 set lim
[llength
$varccommits($v,$a)]
1094 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1101 proc update_arcrows
{v
} {
1102 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1103 global varcid vrownum varcorder varcix varccommits
1104 global vupptr vdownptr vleftptr varctok
1105 global displayorder parentlist curview cached_commitrow
1107 if {$vrowmod($v) == $commitidx($v)} return
1108 if {$v == $curview} {
1109 if {[llength
$displayorder] > $vrowmod($v)} {
1110 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1111 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1113 catch
{unset cached_commitrow
}
1115 set narctot
[expr {[llength
$varctok($v)] - 1}]
1117 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1118 # go up the tree until we find something that has a row number,
1119 # or we get to a seed
1120 set a
[lindex
$vupptr($v) $a]
1123 set a
[lindex
$vdownptr($v) 0]
1126 set varcorder
($v) [list
$a]
1127 lset varcix
($v) $a 0
1128 lset varcrow
($v) $a 0
1132 set arcn
[lindex
$varcix($v) $a]
1133 if {[llength
$vrownum($v)] > $arcn + 1} {
1134 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1135 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1137 set row
[lindex
$varcrow($v) $a]
1141 incr row
[llength
$varccommits($v,$a)]
1142 # go down if possible
1143 set b
[lindex
$vdownptr($v) $a]
1145 # if not, go left, or go up until we can go left
1147 set b
[lindex
$vleftptr($v) $a]
1149 set a
[lindex
$vupptr($v) $a]
1155 lappend vrownum
($v) $row
1156 lappend varcorder
($v) $a
1157 lset varcix
($v) $a $arcn
1158 lset varcrow
($v) $a $row
1160 set vtokmod
($v) [lindex
$varctok($v) $p]
1162 set vrowmod
($v) $row
1163 if {[info exists currentid
]} {
1164 set selectedline
[rowofcommit
$currentid]
1168 # Test whether view $v contains commit $id
1169 proc commitinview
{id v
} {
1172 return [info exists varcid
($v,$id)]
1175 # Return the row number for commit $id in the current view
1176 proc rowofcommit
{id
} {
1177 global varcid varccommits varcrow curview cached_commitrow
1178 global varctok vtokmod
1181 if {![info exists varcid
($v,$id)]} {
1182 puts
"oops rowofcommit no arc for [shortids $id]"
1185 set a
$varcid($v,$id)
1186 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1189 if {[info exists cached_commitrow
($id)]} {
1190 return $cached_commitrow($id)
1192 set i
[lsearch
-exact $varccommits($v,$a) $id]
1194 puts
"oops didn't find commit [shortids $id] in arc $a"
1197 incr i
[lindex
$varcrow($v) $a]
1198 set cached_commitrow
($id) $i
1202 # Returns 1 if a is on an earlier row than b, otherwise 0
1203 proc comes_before
{a b
} {
1204 global varcid varctok curview
1207 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1208 ![info exists varcid
($v,$b)]} {
1211 if {$varcid($v,$a) != $varcid($v,$b)} {
1212 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1213 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1215 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1218 proc bsearch
{l elt
} {
1219 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1224 while {$hi - $lo > 1} {
1225 set mid
[expr {int
(($lo + $hi) / 2)}]
1226 set t
[lindex
$l $mid]
1229 } elseif
{$elt > $t} {
1238 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1239 proc make_disporder
{start end
} {
1240 global vrownum curview commitidx displayorder parentlist
1241 global varccommits varcorder parents vrowmod varcrow
1242 global d_valid_start d_valid_end
1244 if {$end > $vrowmod($curview)} {
1245 update_arcrows
$curview
1247 set ai
[bsearch
$vrownum($curview) $start]
1248 set start
[lindex
$vrownum($curview) $ai]
1249 set narc
[llength
$vrownum($curview)]
1250 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1251 set a
[lindex
$varcorder($curview) $ai]
1252 set l
[llength
$displayorder]
1253 set al
[llength
$varccommits($curview,$a)]
1254 if {$l < $r + $al} {
1256 set pad
[ntimes
[expr {$r - $l}] {}]
1257 set displayorder
[concat
$displayorder $pad]
1258 set parentlist
[concat
$parentlist $pad]
1259 } elseif
{$l > $r} {
1260 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1261 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1263 foreach id
$varccommits($curview,$a) {
1264 lappend displayorder
$id
1265 lappend parentlist
$parents($curview,$id)
1267 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1269 foreach id
$varccommits($curview,$a) {
1270 lset displayorder
$i $id
1271 lset parentlist
$i $parents($curview,$id)
1279 proc commitonrow
{row
} {
1282 set id
[lindex
$displayorder $row]
1284 make_disporder
$row [expr {$row + 1}]
1285 set id
[lindex
$displayorder $row]
1290 proc closevarcs
{v
} {
1291 global varctok varccommits varcid parents children
1292 global cmitlisted commitidx vtokmod
1294 set missing_parents
0
1296 set narcs
[llength
$varctok($v)]
1297 for {set a
1} {$a < $narcs} {incr a
} {
1298 set id
[lindex
$varccommits($v,$a) end
]
1299 foreach p
$parents($v,$id) {
1300 if {[info exists varcid
($v,$p)]} continue
1301 # add p as a new commit
1302 incr missing_parents
1303 set cmitlisted
($v,$p) 0
1304 set parents
($v,$p) {}
1305 if {[llength
$children($v,$p)] == 1 &&
1306 [llength
$parents($v,$id)] == 1} {
1309 set b
[newvarc
$v $p]
1311 set varcid
($v,$p) $b
1312 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1315 lappend varccommits
($v,$b) $p
1317 set scripts
[check_interest
$p $scripts]
1320 if {$missing_parents > 0} {
1321 foreach s
$scripts {
1327 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1328 # Assumes we already have an arc for $rwid.
1329 proc rewrite_commit
{v id rwid
} {
1330 global children parents varcid varctok vtokmod varccommits
1332 foreach ch
$children($v,$id) {
1333 # make $rwid be $ch's parent in place of $id
1334 set i
[lsearch
-exact $parents($v,$ch) $id]
1336 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1338 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1339 # add $ch to $rwid's children and sort the list if necessary
1340 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1341 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1342 $children($v,$rwid)]
1344 # fix the graph after joining $id to $rwid
1345 set a
$varcid($v,$ch)
1346 fix_reversal
$rwid $a $v
1347 # parentlist is wrong for the last element of arc $a
1348 # even if displayorder is right, hence the 3rd arg here
1349 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1353 # Mechanism for registering a command to be executed when we come
1354 # across a particular commit. To handle the case when only the
1355 # prefix of the commit is known, the commitinterest array is now
1356 # indexed by the first 4 characters of the ID. Each element is a
1357 # list of id, cmd pairs.
1358 proc interestedin
{id cmd
} {
1359 global commitinterest
1361 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1364 proc check_interest
{id scripts
} {
1365 global commitinterest
1367 set prefix
[string range
$id 0 3]
1368 if {[info exists commitinterest
($prefix)]} {
1370 foreach
{i
script} $commitinterest($prefix) {
1371 if {[string match
"$i*" $id]} {
1372 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1374 lappend newlist
$i $script
1377 if {$newlist ne
{}} {
1378 set commitinterest
($prefix) $newlist
1380 unset commitinterest
($prefix)
1386 proc getcommitlines
{fd inst view updating
} {
1387 global cmitlisted leftover
1388 global commitidx commitdata vdatemode
1389 global parents children curview hlview
1390 global idpending ordertok
1391 global varccommits varcid varctok vtokmod vfilelimit
1393 set stuff
[read $fd 500000]
1394 # git log doesn't terminate the last commit with a null...
1395 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1402 global commfd viewcomplete viewactive viewname
1403 global viewinstances
1405 set i
[lsearch
-exact $viewinstances($view) $inst]
1407 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1409 # set it blocking so we wait for the process to terminate
1410 fconfigure
$fd -blocking 1
1411 if {[catch
{close
$fd} err
]} {
1413 if {$view != $curview} {
1414 set fv
" for the \"$viewname($view)\" view"
1416 if {[string range
$err 0 4] == "usage"} {
1417 set err
"Gitk: error reading commits$fv:\
1418 bad arguments to git log."
1419 if {$viewname($view) eq
"Command line"} {
1421 " (Note: arguments to gitk are passed to git log\
1422 to allow selection of commits to be displayed.)"
1425 set err
"Error reading commits$fv: $err"
1429 if {[incr viewactive
($view) -1] <= 0} {
1430 set viewcomplete
($view) 1
1431 # Check if we have seen any ids listed as parents that haven't
1432 # appeared in the list
1436 if {$view == $curview} {
1445 set i
[string first
"\0" $stuff $start]
1447 append leftover
($inst) [string range
$stuff $start end
]
1451 set cmit
$leftover($inst)
1452 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1453 set leftover
($inst) {}
1455 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1457 set start
[expr {$i + 1}]
1458 set j
[string first
"\n" $cmit]
1461 if {$j >= 0 && [string match
"commit *" $cmit]} {
1462 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1463 if {[string match
{[-^
<>]*} $ids]} {
1464 switch
-- [string index
$ids 0] {
1470 set ids
[string range
$ids 1 end
]
1474 if {[string length
$id] != 40} {
1482 if {[string length
$shortcmit] > 80} {
1483 set shortcmit
"[string range $shortcmit 0 80]..."
1485 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1488 set id [lindex $ids 0]
1491 if {!$listed && $updating && ![info exists varcid($vid)] &&
1492 $vfilelimit($view) ne {}} {
1493 # git log doesn't rewrite parents
for unlisted commits
1494 # when doing path limiting, so work around that here
1495 # by working out the rewritten parent with git rev-list
1496 # and if we already know about it, using the rewritten
1497 # parent as a substitute parent for $id's children.
1499 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1500 $id -- $vfilelimit($view)]
1502 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1503 # use $rwid in place of $id
1504 rewrite_commit
$view $id $rwid
1511 if {[info exists varcid
($vid)]} {
1512 if {$cmitlisted($vid) ||
!$listed} continue
1516 set olds
[lrange
$ids 1 end
]
1520 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1521 set cmitlisted
($vid) $listed
1522 set parents
($vid) $olds
1523 if {![info exists children
($vid)]} {
1524 set children
($vid) {}
1525 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1526 set k
[lindex
$children($vid) 0]
1527 if {[llength
$parents($view,$k)] == 1 &&
1528 (!$vdatemode($view) ||
1529 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1530 set a
$varcid($view,$k)
1535 set a
[newvarc
$view $id]
1537 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1540 if {![info exists varcid
($vid)]} {
1542 lappend varccommits
($view,$a) $id
1543 incr commitidx
($view)
1548 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1550 if {[llength
[lappend children
($vp) $id]] > 1 &&
1551 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1552 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1554 catch
{unset ordertok
}
1556 if {[info exists varcid
($view,$p)]} {
1557 fix_reversal
$p $a $view
1563 set scripts
[check_interest
$id $scripts]
1567 global numcommits hlview
1569 if {$view == $curview} {
1570 set numcommits
$commitidx($view)
1573 if {[info exists hlview
] && $view == $hlview} {
1574 # we never actually get here...
1577 foreach s
$scripts {
1584 proc chewcommits
{} {
1585 global curview hlview viewcomplete
1586 global pending_select
1589 if {$viewcomplete($curview)} {
1590 global commitidx varctok
1591 global numcommits startmsecs
1593 if {[info exists pending_select
]} {
1595 reset_pending_select
{}
1597 if {[commitinview
$pending_select $curview]} {
1598 selectline
[rowofcommit
$pending_select] 1
1600 set row
[first_real_row
]
1604 if {$commitidx($curview) > 0} {
1605 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1606 #puts "overall $ms ms for $numcommits commits"
1607 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1609 show_status
[mc
"No commits selected"]
1616 proc do_readcommit
{id
} {
1619 # Invoke git-log to handle automatic encoding conversion
1620 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1621 # Read the results using i18n.logoutputencoding
1622 fconfigure
$fd -translation lf
-eofchar {}
1623 if {$tclencoding != {}} {
1624 fconfigure
$fd -encoding $tclencoding
1626 set contents
[read $fd]
1628 # Remove the heading line
1629 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1634 proc readcommit
{id
} {
1635 if {[catch
{set contents
[do_readcommit
$id]}]} return
1636 parsecommit
$id $contents 1
1639 proc parsecommit
{id contents listed
} {
1649 set hdrend
[string first
"\n\n" $contents]
1651 # should never happen...
1652 set hdrend
[string length
$contents]
1654 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1655 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1656 foreach line
[split $header "\n"] {
1657 set line
[split $line " "]
1658 set tag
[lindex
$line 0]
1659 if {$tag == "author"} {
1660 set audate
[lrange
$line end-1 end
]
1661 set auname
[join [lrange
$line 1 end-2
] " "]
1662 } elseif
{$tag == "committer"} {
1663 set comdate
[lrange
$line end-1 end
]
1664 set comname
[join [lrange
$line 1 end-2
] " "]
1668 # take the first non-blank line of the comment as the headline
1669 set headline
[string trimleft
$comment]
1670 set i
[string first
"\n" $headline]
1672 set headline
[string range
$headline 0 $i]
1674 set headline
[string trimright
$headline]
1675 set i
[string first
"\r" $headline]
1677 set headline
[string trimright
[string range
$headline 0 $i]]
1680 # git log indents the comment by 4 spaces;
1681 # if we got this via git cat-file, add the indentation
1683 foreach line
[split $comment "\n"] {
1684 append newcomment
" "
1685 append newcomment
$line
1686 append newcomment
"\n"
1688 set comment
$newcomment
1690 set hasnote
[string first
"\nNotes:\n" $contents]
1691 set commitinfo
($id) [list
$headline $auname $audate \
1692 $comname $comdate $comment $hasnote]
1695 proc getcommit
{id
} {
1696 global commitdata commitinfo
1698 if {[info exists commitdata
($id)]} {
1699 parsecommit
$id $commitdata($id) 1
1702 if {![info exists commitinfo
($id)]} {
1703 set commitinfo
($id) [list
[mc
"No commit information available"]]
1709 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1710 # and are present in the current view.
1711 # This is fairly slow...
1712 proc longid
{prefix
} {
1713 global varcid curview
1716 foreach match
[array names varcid
"$curview,$prefix*"] {
1717 lappend ids
[lindex
[split $match ","] 1]
1723 global tagids idtags headids idheads tagobjid
1724 global otherrefids idotherrefs mainhead mainheadid
1725 global selecthead selectheadid
1728 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1731 set refd
[open
[list | git show-ref
-d] r
]
1732 while {[gets
$refd line
] >= 0} {
1733 if {[string index
$line 40] ne
" "} continue
1734 set id
[string range
$line 0 39]
1735 set ref
[string range
$line 41 end
]
1736 if {![string match
"refs/*" $ref]} continue
1737 set name
[string range
$ref 5 end
]
1738 if {[string match
"remotes/*" $name]} {
1739 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1740 set headids
($name) $id
1741 lappend idheads
($id) $name
1743 } elseif
{[string match
"heads/*" $name]} {
1744 set name
[string range
$name 6 end
]
1745 set headids
($name) $id
1746 lappend idheads
($id) $name
1747 } elseif
{[string match
"tags/*" $name]} {
1748 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1749 # which is what we want since the former is the commit ID
1750 set name
[string range
$name 5 end
]
1751 if {[string match
"*^{}" $name]} {
1752 set name
[string range
$name 0 end-3
]
1754 set tagobjid
($name) $id
1756 set tagids
($name) $id
1757 lappend idtags
($id) $name
1759 set otherrefids
($name) $id
1760 lappend idotherrefs
($id) $name
1767 set mainheadid
[exec git rev-parse HEAD
]
1768 set thehead
[exec git symbolic-ref HEAD
]
1769 if {[string match
"refs/heads/*" $thehead]} {
1770 set mainhead
[string range
$thehead 11 end
]
1774 if {$selecthead ne
{}} {
1776 set selectheadid
[exec git rev-parse
--verify $selecthead]
1781 # skip over fake commits
1782 proc first_real_row
{} {
1783 global nullid nullid2 numcommits
1785 for {set row
0} {$row < $numcommits} {incr row
} {
1786 set id
[commitonrow
$row]
1787 if {$id ne
$nullid && $id ne
$nullid2} {
1794 # update things for a head moved to a child of its previous location
1795 proc movehead
{id name
} {
1796 global headids idheads
1798 removehead
$headids($name) $name
1799 set headids
($name) $id
1800 lappend idheads
($id) $name
1803 # update things when a head has been removed
1804 proc removehead
{id name
} {
1805 global headids idheads
1807 if {$idheads($id) eq
$name} {
1810 set i
[lsearch
-exact $idheads($id) $name]
1812 set idheads
($id) [lreplace
$idheads($id) $i $i]
1815 unset headids
($name)
1818 proc ttk_toplevel
{w args
} {
1820 eval [linsert
$args 0 ::toplevel
$w]
1822 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1827 proc make_transient
{window origin
} {
1830 # In MacOS Tk 8.4 transient appears to work by setting
1831 # overrideredirect, which is utterly useless, since the
1832 # windows get no border, and are not even kept above
1834 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1836 wm transient
$window $origin
1838 # Windows fails to place transient windows normally, so
1839 # schedule a callback to center them on the parent.
1840 if {[tk windowingsystem
] eq
{win32
}} {
1841 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1845 proc show_error
{w top msg
{mc mc
}} {
1847 if {![info exists NS
]} {set NS
""}
1848 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1849 message
$w.m
-text $msg -justify center
-aspect 400
1850 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1851 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1852 pack
$w.ok
-side bottom
-fill x
1853 bind $top <Visibility
> "grab $top; focus $top"
1854 bind $top <Key-Return
> "destroy $top"
1855 bind $top <Key-space
> "destroy $top"
1856 bind $top <Key-Escape
> "destroy $top"
1860 proc error_popup
{msg
{owner .
}} {
1861 if {[tk windowingsystem
] eq
"win32"} {
1862 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1863 -parent $owner -message $msg
1867 make_transient
$w $owner
1868 show_error
$w $w $msg
1872 proc confirm_popup
{msg
{owner .
}} {
1873 global confirm_ok NS
1877 make_transient
$w $owner
1878 message
$w.m
-text $msg -justify center
-aspect 400
1879 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1880 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1881 pack
$w.ok
-side left
-fill x
1882 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1883 pack
$w.cancel
-side right
-fill x
1884 bind $w <Visibility
> "grab $w; focus $w"
1885 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1886 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1887 bind $w <Key-Escape
> "destroy $w"
1888 tk
::PlaceWindow
$w widget
$owner
1893 proc setoptions
{} {
1894 if {[tk windowingsystem
] ne
"win32"} {
1895 option add
*Panedwindow.showHandle
1 startupFile
1896 option add
*Panedwindow.sashRelief raised startupFile
1897 if {[tk windowingsystem
] ne
"aqua"} {
1898 option add
*Menu.font uifont startupFile
1901 option add
*Menu.TearOff
0 startupFile
1903 option add
*Button.font uifont startupFile
1904 option add
*Checkbutton.font uifont startupFile
1905 option add
*Radiobutton.font uifont startupFile
1906 option add
*Menubutton.font uifont startupFile
1907 option add
*Label.font uifont startupFile
1908 option add
*Message.font uifont startupFile
1909 option add
*Entry.font textfont startupFile
1910 option add
*Text.font textfont startupFile
1911 option add
*Labelframe.font uifont startupFile
1912 option add
*Spinbox.font textfont startupFile
1913 option add
*Listbox.font mainfont startupFile
1916 # Make a menu and submenus.
1917 # m is the window name for the menu, items is the list of menu items to add.
1918 # Each item is a list {mc label type description options...}
1919 # mc is ignored; it's so we can put mc there to alert xgettext
1920 # label is the string that appears in the menu
1921 # type is cascade, command or radiobutton (should add checkbutton)
1922 # description depends on type; it's the sublist for cascade, the
1923 # command to invoke for command, or {variable value} for radiobutton
1924 proc makemenu
{m items
} {
1926 if {[tk windowingsystem
] eq
{aqua
}} {
1932 set name
[mc
[lindex
$i 1]]
1933 set type [lindex
$i 2]
1934 set thing
[lindex
$i 3]
1935 set params
[list
$type]
1937 set u
[string first
"&" [string map
{&& x
} $name]]
1938 lappend params
-label [string map
{&& & & {}} $name]
1940 lappend params
-underline $u
1945 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1946 lappend params
-menu $m.
$submenu
1949 lappend params
-command $thing
1952 lappend params
-variable [lindex
$thing 0] \
1953 -value [lindex
$thing 1]
1956 set tail [lrange
$i 4 end
]
1957 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
1958 eval $m add
$params $tail
1959 if {$type eq
"cascade"} {
1960 makemenu
$m.
$submenu $thing
1965 # translate string and remove ampersands
1967 return [string map
{&& & & {}} [mc
$str]]
1970 proc makedroplist
{w varname args
} {
1974 foreach label
$args {
1975 set cx
[string length
$label]
1976 if {$cx > $width} {set width
$cx}
1978 set gm
[ttk
::combobox
$w -width $width -state readonly\
1979 -textvariable $varname -values $args]
1981 set gm
[eval [linsert
$args 0 tk_optionMenu
$w $varname]]
1986 proc makewindow
{} {
1987 global canv canv2 canv3 linespc charspc ctext cflist cscroll
1989 global findtype findtypemenu findloc findstring fstring geometry
1990 global entries sha1entry sha1string sha1but
1991 global diffcontextstring diffcontext
1993 global maincursor textcursor curtextcursor
1994 global rowctxmenu fakerowmenu mergemax wrapcomment
1995 global highlight_files gdttype
1996 global searchstring sstring
1997 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
1998 global headctxmenu progresscanv progressitem progresscoords statusw
1999 global fprogitem fprogcoord lastprogupdate progupdatepending
2000 global rprogitem rprogcoord rownumsel numcommits
2001 global have_tk85 use_ttk NS
2005 # The "mc" arguments here are purely so that xgettext
2006 # sees the following string as needing to be translated
2009 {mc
"Update" command updatecommits
-accelerator F5
}
2010 {mc
"Reload" command reloadcommits
-accelerator Meta1-F5
}
2011 {mc
"Reread references" command rereadrefs
}
2012 {mc
"List references" command showrefs
-accelerator F2
}
2014 {mc
"Start git gui" command {exec git gui
&}}
2016 {mc
"Quit" command doquit
-accelerator Meta1-Q
}
2020 {mc
"Preferences" command doprefs
}
2024 {mc
"New view..." command {newview
0} -accelerator Shift-F4
}
2025 {mc
"Edit view..." command editview
-state disabled
-accelerator F4
}
2026 {mc
"Delete view" command delview
-state disabled
}
2028 {mc
"All files" radiobutton
{selectedview
0} -command {showview
0}}
2030 if {[tk windowingsystem
] ne
"aqua"} {
2033 {mc
"About gitk" command about
}
2034 {mc
"Key bindings" command keys
}
2036 set bar
[list
$file $edit $view $help]
2038 proc
::tk
::mac
::ShowPreferences
{} {doprefs
}
2039 proc
::tk
::mac
::Quit
{} {doquit
}
2040 lset
file end
[lreplace
[lindex
$file end
] end-1 end
]
2042 xx
"Apple" cascade
{
2043 {mc
"About gitk" command about
}
2048 {mc
"Key bindings" command keys
}
2050 set bar
[list
$apple $file $view $help]
2053 . configure
-menu .bar
2056 # cover the non-themed toplevel with a themed frame.
2057 place
[ttk
::frame ._main_background
] -x 0 -y 0 -relwidth 1 -relheight 1
2060 # the gui has upper and lower half, parts of a paned window.
2061 ${NS}::panedwindow .ctop
-orient vertical
2063 # possibly use assumed geometry
2064 if {![info exists geometry
(pwsash0
)]} {
2065 set geometry
(topheight
) [expr {15 * $linespc}]
2066 set geometry
(topwidth
) [expr {80 * $charspc}]
2067 set geometry
(botheight
) [expr {15 * $linespc}]
2068 set geometry
(botwidth
) [expr {50 * $charspc}]
2069 set geometry
(pwsash0
) [list
[expr {40 * $charspc}] 2]
2070 set geometry
(pwsash1
) [list
[expr {60 * $charspc}] 2]
2073 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2074 ${NS}::frame .tf
-height $geometry(topheight
) -width $geometry(topwidth
)
2075 ${NS}::frame .tf.histframe
2076 ${NS}::panedwindow .tf.histframe.pwclist
-orient horizontal
2078 .tf.histframe.pwclist configure
-sashpad 0 -handlesize 4
2081 # create three canvases
2082 set cscroll .tf.histframe.csb
2083 set canv .tf.histframe.pwclist.canv
2085 -selectbackground $selectbgcolor \
2086 -background $bgcolor -bd 0 \
2087 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2088 .tf.histframe.pwclist add
$canv
2089 set canv2 .tf.histframe.pwclist.canv2
2091 -selectbackground $selectbgcolor \
2092 -background $bgcolor -bd 0 -yscrollincr $linespc
2093 .tf.histframe.pwclist add
$canv2
2094 set canv3 .tf.histframe.pwclist.canv3
2096 -selectbackground $selectbgcolor \
2097 -background $bgcolor -bd 0 -yscrollincr $linespc
2098 .tf.histframe.pwclist add
$canv3
2100 bind .tf.histframe.pwclist
<Map
> {
2102 .tf.histframe.pwclist sashpos
1 [lindex $
::geometry
(pwsash1
) 0]
2103 .tf.histframe.pwclist sashpos
0 [lindex $
::geometry
(pwsash0
) 0]
2106 eval .tf.histframe.pwclist sash place
0 $geometry(pwsash0
)
2107 eval .tf.histframe.pwclist sash place
1 $geometry(pwsash1
)
2110 # a scroll bar to rule them
2111 ${NS}::scrollbar
$cscroll -command {allcanvs yview
}
2112 if {!$use_ttk} {$cscroll configure
-highlightthickness 0}
2113 pack
$cscroll -side right
-fill y
2114 bind .tf.histframe.pwclist
<Configure
> {resizeclistpanes
%W
%w
}
2115 lappend bglist
$canv $canv2 $canv3
2116 pack .tf.histframe.pwclist
-fill both
-expand 1 -side left
2118 # we have two button bars at bottom of top frame. Bar 1
2119 ${NS}::frame .tf.bar
2120 ${NS}::frame .tf.lbar
-height 15
2122 set sha1entry .tf.bar.sha1
2123 set entries
$sha1entry
2124 set sha1but .tf.bar.sha1label
2125 button
$sha1but -text "[mc "SHA1 ID
:"] " -state disabled
-relief flat \
2126 -command gotocommit
-width 8
2127 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
2128 pack .tf.bar.sha1label
-side left
2129 ${NS}::entry
$sha1entry -width 40 -font textfont
-textvariable sha1string
2130 trace add variable sha1string
write sha1change
2131 pack
$sha1entry -side left
-pady 2
2133 image create bitmap bm-left
-data {
2134 #define left_width 16
2135 #define left_height 16
2136 static unsigned char left_bits
[] = {
2137 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2138 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2139 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2141 image create bitmap bm-right
-data {
2142 #define right_width 16
2143 #define right_height 16
2144 static unsigned char right_bits
[] = {
2145 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2146 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2147 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2149 ${NS}::button .tf.bar.leftbut
-image bm-left
-command goback \
2150 -state disabled
-width 26
2151 pack .tf.bar.leftbut
-side left
-fill y
2152 ${NS}::button .tf.bar.rightbut
-image bm-right
-command goforw \
2153 -state disabled
-width 26
2154 pack .tf.bar.rightbut
-side left
-fill y
2156 ${NS}::label .tf.bar.rowlabel
-text [mc
"Row"]
2158 ${NS}::label .tf.bar.rownum
-width 7 -textvariable rownumsel \
2159 -relief sunken
-anchor e
2160 ${NS}::label .tf.bar.rowlabel2
-text "/"
2161 ${NS}::label .tf.bar.numcommits
-width 7 -textvariable numcommits \
2162 -relief sunken
-anchor e
2163 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2166 foreach w
{rownum numcommits
} {.tf.bar.
$w configure
-font textfont
}
2169 trace add variable selectedline
write selectedline_change
2171 # Status label and progress bar
2172 set statusw .tf.bar.status
2173 ${NS}::label
$statusw -width 15 -relief sunken
2174 pack
$statusw -side left
-padx 5
2176 set progresscanv
[ttk
::progressbar .tf.bar.progress
]
2178 set h
[expr {[font metrics uifont
-linespace] + 2}]
2179 set progresscanv .tf.bar.progress
2180 canvas
$progresscanv -relief sunken
-height $h -borderwidth 2
2181 set progressitem
[$progresscanv create rect
-1 0 0 $h -fill green
]
2182 set fprogitem
[$progresscanv create rect
-1 0 0 $h -fill yellow
]
2183 set rprogitem
[$progresscanv create rect
-1 0 0 $h -fill red
]
2185 pack
$progresscanv -side right
-expand 1 -fill x
-padx {0 2}
2186 set progresscoords
{0 0}
2189 bind $progresscanv <Configure
> adjustprogress
2190 set lastprogupdate
[clock clicks
-milliseconds]
2191 set progupdatepending
0
2193 # build up the bottom bar of upper window
2194 ${NS}::label .tf.lbar.flabel
-text "[mc "Find
"] "
2195 ${NS}::button .tf.lbar.fnext
-text [mc
"next"] -command {dofind
1 1}
2196 ${NS}::button .tf.lbar.fprev
-text [mc
"prev"] -command {dofind
-1 1}
2197 ${NS}::label .tf.lbar.flab2
-text " [mc "commit
"] "
2198 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2200 set gdttype
[mc
"containing:"]
2201 set gm
[makedroplist .tf.lbar.gdttype gdttype \
2202 [mc
"containing:"] \
2203 [mc
"touching paths:"] \
2204 [mc
"adding/removing string:"]]
2205 trace add variable gdttype
write gdttype_change
2206 pack .tf.lbar.gdttype
-side left
-fill y
2209 set fstring .tf.lbar.findstring
2210 lappend entries
$fstring
2211 ${NS}::entry
$fstring -width 30 -textvariable findstring
2212 trace add variable findstring
write find_change
2213 set findtype
[mc
"Exact"]
2214 set findtypemenu
[makedroplist .tf.lbar.findtype \
2215 findtype
[mc
"Exact"] [mc
"IgnCase"] [mc
"Regexp"]]
2216 trace add variable findtype
write findcom_change
2217 set findloc
[mc
"All fields"]
2218 makedroplist .tf.lbar.findloc findloc
[mc
"All fields"] [mc
"Headline"] \
2219 [mc
"Comments"] [mc
"Author"] [mc
"Committer"]
2220 trace add variable findloc
write find_change
2221 pack .tf.lbar.findloc
-side right
2222 pack .tf.lbar.findtype
-side right
2223 pack
$fstring -side left
-expand 1 -fill x
2225 # Finish putting the upper half of the viewer together
2226 pack .tf.lbar
-in .tf
-side bottom
-fill x
2227 pack .tf.bar
-in .tf
-side bottom
-fill x
2228 pack .tf.histframe
-fill both
-side top
-expand 1
2231 .ctop paneconfigure .tf
-height $geometry(topheight
)
2232 .ctop paneconfigure .tf
-width $geometry(topwidth
)
2235 # now build up the bottom
2236 ${NS}::panedwindow .pwbottom
-orient horizontal
2238 # lower left, a text box over search bar, scroll bar to the right
2239 # if we know window height, then that will set the lower text height, otherwise
2240 # we set lower text height which will drive window height
2241 if {[info exists geometry
(main
)]} {
2242 ${NS}::frame .bleft
-width $geometry(botwidth
)
2244 ${NS}::frame .bleft
-width $geometry(botwidth
) -height $geometry(botheight
)
2246 ${NS}::frame .bleft.top
2247 ${NS}::frame .bleft.mid
2248 ${NS}::frame .bleft.bottom
2250 ${NS}::button .bleft.top.search
-text [mc
"Search"] -command dosearch
2251 pack .bleft.top.search
-side left
-padx 5
2252 set sstring .bleft.top.sstring
2254 ${NS}::entry
$sstring -width 20 -textvariable searchstring
2255 lappend entries
$sstring
2256 trace add variable searchstring
write incrsearch
2257 pack
$sstring -side left
-expand 1 -fill x
2258 ${NS}::radiobutton .bleft.mid.
diff -text [mc
"Diff"] \
2259 -command changediffdisp
-variable diffelide
-value {0 0}
2260 ${NS}::radiobutton .bleft.mid.old
-text [mc
"Old version"] \
2261 -command changediffdisp
-variable diffelide
-value {0 1}
2262 ${NS}::radiobutton .bleft.mid.new
-text [mc
"New version"] \
2263 -command changediffdisp
-variable diffelide
-value {1 0}
2264 ${NS}::label .bleft.mid.labeldiffcontext
-text " [mc "Lines of context
"]: "
2265 pack .bleft.mid.
diff .bleft.mid.old .bleft.mid.new
-side left
2266 spinbox .bleft.mid.diffcontext
-width 5 \
2267 -from 0 -increment 1 -to 10000000 \
2268 -validate all
-validatecommand "diffcontextvalidate %P" \
2269 -textvariable diffcontextstring
2270 .bleft.mid.diffcontext
set $diffcontext
2271 trace add variable diffcontextstring
write diffcontextchange
2272 lappend entries .bleft.mid.diffcontext
2273 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext
-side left
2274 ${NS}::checkbutton .bleft.mid.ignspace
-text [mc
"Ignore space change"] \
2275 -command changeignorespace
-variable ignorespace
2276 pack .bleft.mid.ignspace
-side left
-padx 5
2278 set worddiff
[mc
"Line diff"]
2279 if {[package vcompare
$git_version "1.7.2"] >= 0} {
2280 makedroplist .bleft.mid.worddiff worddiff
[mc
"Line diff"] \
2281 [mc
"Markup words"] [mc
"Color words"]
2282 trace add variable worddiff
write changeworddiff
2283 pack .bleft.mid.worddiff
-side left
-padx 5
2286 set ctext .bleft.bottom.ctext
2287 text
$ctext -background $bgcolor -foreground $fgcolor \
2288 -state disabled
-font textfont \
2289 -yscrollcommand scrolltext
-wrap none \
2290 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2292 $ctext conf
-tabstyle wordprocessor
2294 ${NS}::scrollbar .bleft.bottom.sb
-command "$ctext yview"
2295 ${NS}::scrollbar .bleft.bottom.sbhorizontal
-command "$ctext xview" -orient h
2296 pack .bleft.top
-side top
-fill x
2297 pack .bleft.mid
-side top
-fill x
2298 grid
$ctext .bleft.bottom.sb
-sticky nsew
2299 grid .bleft.bottom.sbhorizontal
-sticky ew
2300 grid columnconfigure .bleft.bottom
0 -weight 1
2301 grid rowconfigure .bleft.bottom
0 -weight 1
2302 grid rowconfigure .bleft.bottom
1 -weight 0
2303 pack .bleft.bottom
-side top
-fill both
-expand 1
2304 lappend bglist
$ctext
2305 lappend fglist
$ctext
2307 $ctext tag conf comment
-wrap $wrapcomment
2308 $ctext tag conf filesep
-font textfontbold
-back "#aaaaaa"
2309 $ctext tag conf hunksep
-fore [lindex
$diffcolors 2]
2310 $ctext tag conf d0
-fore [lindex
$diffcolors 0]
2311 $ctext tag conf dresult
-fore [lindex
$diffcolors 1]
2312 $ctext tag conf m0
-fore red
2313 $ctext tag conf m1
-fore blue
2314 $ctext tag conf m2
-fore green
2315 $ctext tag conf m3
-fore purple
2316 $ctext tag conf
m4 -fore brown
2317 $ctext tag conf m5
-fore "#009090"
2318 $ctext tag conf m6
-fore magenta
2319 $ctext tag conf m7
-fore "#808000"
2320 $ctext tag conf m8
-fore "#009000"
2321 $ctext tag conf m9
-fore "#ff0080"
2322 $ctext tag conf m10
-fore cyan
2323 $ctext tag conf m11
-fore "#b07070"
2324 $ctext tag conf m12
-fore "#70b0f0"
2325 $ctext tag conf m13
-fore "#70f0b0"
2326 $ctext tag conf m14
-fore "#f0b070"
2327 $ctext tag conf m15
-fore "#ff70b0"
2328 $ctext tag conf mmax
-fore darkgrey
2330 $ctext tag conf mresult
-font textfontbold
2331 $ctext tag conf msep
-font textfontbold
2332 $ctext tag conf found
-back yellow
2334 .pwbottom add .bleft
2336 .pwbottom paneconfigure .bleft
-width $geometry(botwidth
)
2340 ${NS}::frame .bright
2341 ${NS}::frame .bright.mode
2342 ${NS}::radiobutton .bright.mode.
patch -text [mc
"Patch"] \
2343 -command reselectline
-variable cmitmode
-value "patch"
2344 ${NS}::radiobutton .bright.mode.tree
-text [mc
"Tree"] \
2345 -command reselectline
-variable cmitmode
-value "tree"
2346 grid .bright.mode.
patch .bright.mode.tree
-sticky ew
2347 pack .bright.mode
-side top
-fill x
2348 set cflist .bright.cfiles
2349 set indent
[font measure mainfont
"nn"]
2351 -selectbackground $selectbgcolor \
2352 -background $bgcolor -foreground $fgcolor \
2354 -tabs [list
$indent [expr {2 * $indent}]] \
2355 -yscrollcommand ".bright.sb set" \
2356 -cursor [. cget
-cursor] \
2357 -spacing1 1 -spacing3 1
2358 lappend bglist
$cflist
2359 lappend fglist
$cflist
2360 ${NS}::scrollbar .bright.sb
-command "$cflist yview"
2361 pack .bright.sb
-side right
-fill y
2362 pack
$cflist -side left
-fill both
-expand 1
2363 $cflist tag configure highlight \
2364 -background [$cflist cget
-selectbackground]
2365 $cflist tag configure bold
-font mainfontbold
2367 .pwbottom add .bright
2370 # restore window width & height if known
2371 if {[info exists geometry
(main
)]} {
2372 if {[scan
$geometry(main
) "%dx%d" w h
] >= 2} {
2373 if {$w > [winfo screenwidth .
]} {
2374 set w
[winfo screenwidth .
]
2376 if {$h > [winfo screenheight .
]} {
2377 set h
[winfo screenheight .
]
2379 wm geometry .
"${w}x$h"
2383 if {[info exists geometry
(state
)] && $geometry(state
) eq
"zoomed"} {
2384 wm state .
$geometry(state
)
2387 if {[tk windowingsystem
] eq
{aqua
}} {
2398 %W sashpos
0 $
::geometry
(topheight
)
2400 bind .pwbottom
<Map
> {
2402 %W sashpos
0 $
::geometry
(botwidth
)
2406 bind .pwbottom
<Configure
> {resizecdetpanes
%W
%w
}
2407 pack .ctop
-fill both
-expand 1
2408 bindall
<1> {selcanvline
%W
%x
%y
}
2409 #bindall <B1-Motion> {selcanvline %W %x %y}
2410 if {[tk windowingsystem
] == "win32"} {
2411 bind .
<MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
}
2412 bind $ctext <MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
; break }
2414 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
2415 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
2416 if {[tk windowingsystem
] eq
"aqua"} {
2417 bindall
<MouseWheel
> {
2418 set delta
[expr {- (%D
)}]
2419 allcanvs yview scroll
$delta units
2421 bindall
<Shift-MouseWheel
> {
2422 set delta
[expr {- (%D
)}]
2423 $canv xview scroll
$delta units
2427 bindall
<$
::BM
> "canvscan mark %W %x %y"
2428 bindall
<B$
::BM-Motion
> "canvscan dragto %W %x %y"
2429 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
2430 bind .
<$M1B-Key-w> doquit
2431 bindkey
<Home
> selfirstline
2432 bindkey
<End
> sellastline
2433 bind .
<Key-Up
> "selnextline -1"
2434 bind .
<Key-Down
> "selnextline 1"
2435 bind .
<Shift-Key-Up
> "dofind -1 0"
2436 bind .
<Shift-Key-Down
> "dofind 1 0"
2437 bindkey
<Key-Right
> "goforw"
2438 bindkey
<Key-Left
> "goback"
2439 bind .
<Key-Prior
> "selnextpage -1"
2440 bind .
<Key-Next
> "selnextpage 1"
2441 bind .
<$M1B-Home> "allcanvs yview moveto 0.0"
2442 bind .
<$M1B-End> "allcanvs yview moveto 1.0"
2443 bind .
<$M1B-Key-Up> "allcanvs yview scroll -1 units"
2444 bind .
<$M1B-Key-Down> "allcanvs yview scroll 1 units"
2445 bind .
<$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2446 bind .
<$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2447 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
2448 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
2449 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
2450 bindkey p
"selnextline -1"
2451 bindkey n
"selnextline 1"
2454 bindkey k
"selnextline -1"
2455 bindkey j
"selnextline 1"
2459 bindkey d
"$ctext yview scroll 18 units"
2460 bindkey u
"$ctext yview scroll -18 units"
2461 bindkey
/ {focus
$fstring}
2462 bindkey
<Key-KP_Divide
> {focus
$fstring}
2463 bindkey
<Key-Return
> {dofind
1 1}
2464 bindkey ?
{dofind
-1 1}
2466 bind .
<F5
> updatecommits
2467 bind .
<$M1B-F5> reloadcommits
2468 bind .
<F2
> showrefs
2469 bind .
<Shift-F4
> {newview
0}
2470 catch
{ bind .
<Shift-Key-XF86_Switch_VT_4
> {newview
0} }
2471 bind .
<F4
> edit_or_newview
2472 bind .
<$M1B-q> doquit
2473 bind .
<$M1B-f> {dofind
1 1}
2474 bind .
<$M1B-g> {dofind
1 0}
2475 bind .
<$M1B-r> dosearchback
2476 bind .
<$M1B-s> dosearch
2477 bind .
<$M1B-equal> {incrfont
1}
2478 bind .
<$M1B-plus> {incrfont
1}
2479 bind .
<$M1B-KP_Add> {incrfont
1}
2480 bind .
<$M1B-minus> {incrfont
-1}
2481 bind .
<$M1B-KP_Subtract> {incrfont
-1}
2482 wm protocol . WM_DELETE_WINDOW doquit
2483 bind .
<Destroy
> {stop_backends
}
2484 bind .
<Button-1
> "click %W"
2485 bind $fstring <Key-Return
> {dofind
1 1}
2486 bind $sha1entry <Key-Return
> {gotocommit
; break}
2487 bind $sha1entry <<PasteSelection>> clearsha1
2488 bind $cflist <1> {sel_flist %W %x %y; break}
2489 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2490 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2492 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2493 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2494 bind $ctext <Button-1> {focus %W}
2496 set maincursor [. cget -cursor]
2497 set textcursor [$ctext cget -cursor]
2498 set curtextcursor $textcursor
2500 set rowctxmenu .rowctxmenu
2501 makemenu $rowctxmenu {
2502 {mc "Diff this -> selected" command {diffvssel 0}}
2503 {mc "Diff selected -> this" command {diffvssel 1}}
2504 {mc "Make patch" command mkpatch}
2505 {mc "Create tag" command mktag}
2506 {mc "Write commit to file" command writecommit}
2507 {mc "Create new branch" command mkbranch}
2508 {mc "Cherry-pick this commit" command cherrypick}
2509 {mc "Reset HEAD branch to here" command resethead}
2510 {mc "Mark this commit" command markhere}
2511 {mc "Return to mark" command gotomark}
2512 {mc "Find descendant of this and mark" command find_common_desc}
2513 {mc "Compare with marked commit" command compare_commits}
2515 $rowctxmenu configure -tearoff 0
2517 set fakerowmenu .fakerowmenu
2518 makemenu $fakerowmenu {
2519 {mc "Diff this -> selected" command {diffvssel 0}}
2520 {mc "Diff selected -> this" command {diffvssel 1}}
2521 {mc "Make patch" command mkpatch}
2523 $fakerowmenu configure -tearoff 0
2525 set headctxmenu .headctxmenu
2526 makemenu $headctxmenu {
2527 {mc "Check out this branch" command cobranch}
2528 {mc "Remove this branch" command rmbranch}
2530 $headctxmenu configure -tearoff 0
2533 set flist_menu .flistctxmenu
2534 makemenu $flist_menu {
2535 {mc "Highlight this too" command {flist_hl 0}}
2536 {mc "Highlight this only" command {flist_hl 1}}
2537 {mc "External diff" command {external_diff}}
2538 {mc "Blame parent commit" command {external_blame 1}}
2540 $flist_menu configure -tearoff 0
2543 set diff_menu .diffctxmenu
2544 makemenu $diff_menu {
2545 {mc "Show origin of this line" command show_line_source}
2546 {mc "Run git gui blame on this line" command {external_blame_diff}}
2548 $diff_menu configure -tearoff 0
2551 # Windows sends all mouse wheel events to the current focused window, not
2552 # the one where the mouse hovers, so bind those events here and redirect
2553 # to the correct window
2554 proc windows_mousewheel_redirector {W X Y D} {
2555 global canv canv2 canv3
2556 set w [winfo containing -displayof $W $X $Y]
2558 set u [expr {$D < 0 ? 5 : -5}]
2559 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2560 allcanvs yview scroll $u units
2563 $w yview scroll $u units
2569 # Update row number label when selectedline changes
2570 proc selectedline_change {n1 n2 op} {
2571 global selectedline rownumsel
2573 if {$selectedline eq {}} {
2576 set rownumsel [expr {$selectedline + 1}]
2580 # mouse-2 makes all windows scan vertically, but only the one
2581 # the cursor is in scans horizontally
2582 proc canvscan {op w x y} {
2583 global canv canv2 canv3
2584 foreach c [list $canv $canv2 $canv3] {
2593 proc scrollcanv {cscroll f0 f1} {
2594 $cscroll set $f0 $f1
2599 # when we make a key binding for the toplevel, make sure
2600 # it doesn't get triggered when that key is pressed in the
2601 # find string entry widget.
2602 proc bindkey {ev script} {
2605 set escript [bind Entry $ev]
2606 if {$escript == {}} {
2607 set escript [bind Entry <Key>]
2609 foreach e $entries {
2610 bind $e $ev "$escript; break"
2614 # set the focus back to the toplevel for any click outside
2617 global ctext entries
2618 foreach e [concat $entries $ctext] {
2619 if {$w == $e} return
2624 # Adjust the progress bar for a change in requested extent or canvas size
2625 proc adjustprogress {} {
2626 global progresscanv progressitem progresscoords
2627 global fprogitem fprogcoord lastprogupdate progupdatepending
2628 global rprogitem rprogcoord use_ttk
2631 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2635 set w [expr {[winfo width $progresscanv] - 4}]
2636 set x0 [expr {$w * [lindex $progresscoords 0]}]
2637 set x1 [expr {$w * [lindex $progresscoords 1]}]
2638 set h [winfo height $progresscanv]
2639 $progresscanv coords $progressitem $x0 0 $x1 $h
2640 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2641 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2642 set now [clock clicks -milliseconds]
2643 if {$now >= $lastprogupdate + 100} {
2644 set progupdatepending 0
2646 } elseif {!$progupdatepending} {
2647 set progupdatepending 1
2648 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2652 proc doprogupdate {} {
2653 global lastprogupdate progupdatepending
2655 if {$progupdatepending} {
2656 set progupdatepending 0
2657 set lastprogupdate [clock clicks -milliseconds]
2662 proc savestuff {w} {
2663 global canv canv2 canv3 mainfont textfont uifont tabstop
2664 global stuffsaved findmergefiles maxgraphpct
2665 global maxwidth showneartags showlocalchanges
2666 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2667 global cmitmode wrapcomment datetimeformat limitdiffs
2668 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2669 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2670 global hideremotes want_ttk
2672 if {$stuffsaved} return
2673 if {![winfo viewable .]} return
2675 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2676 set f [open "~/.gitk-new" w]
2677 if {$::tcl_platform(platform) eq {windows}} {
2678 file attributes "~/.gitk-new" -hidden true
2680 puts $f [list set mainfont $mainfont]
2681 puts $f [list set textfont $textfont]
2682 puts $f [list set uifont $uifont]
2683 puts $f [list set tabstop $tabstop]
2684 puts $f [list set findmergefiles $findmergefiles]
2685 puts $f [list set maxgraphpct $maxgraphpct]
2686 puts $f [list set maxwidth $maxwidth]
2687 puts $f [list set cmitmode $cmitmode]
2688 puts $f [list set wrapcomment $wrapcomment]
2689 puts $f [list set autoselect $autoselect]
2690 puts $f [list set autosellen $autosellen]
2691 puts $f [list set showneartags $showneartags]
2692 puts $f [list set hideremotes $hideremotes]
2693 puts $f [list set showlocalchanges $showlocalchanges]
2694 puts $f [list set datetimeformat $datetimeformat]
2695 puts $f [list set limitdiffs $limitdiffs]
2696 puts $f [list set uicolor $uicolor]
2697 puts $f [list set want_ttk $want_ttk]
2698 puts $f [list set bgcolor $bgcolor]
2699 puts $f [list set fgcolor $fgcolor]
2700 puts $f [list set colors $colors]
2701 puts $f [list set diffcolors $diffcolors]
2702 puts $f [list set markbgcolor $markbgcolor]
2703 puts $f [list set diffcontext $diffcontext]
2704 puts $f [list set selectbgcolor $selectbgcolor]
2705 puts $f [list set extdifftool $extdifftool]
2706 puts $f [list set perfile_attrs $perfile_attrs]
2708 puts $f "set geometry(main) [wm geometry .]"
2709 puts $f "set geometry(state) [wm state .]"
2710 puts $f "set geometry(topwidth) [winfo width .tf]"
2711 puts $f "set geometry(topheight) [winfo height .tf]"
2713 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2714 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2716 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2717 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2719 puts $f "set geometry(botwidth) [winfo width .bleft]"
2720 puts $f "set geometry(botheight) [winfo height .bleft]"
2722 puts -nonewline $f "set permviews {"
2723 for {set v 0} {$v < $nextviewnum} {incr v} {
2724 if {$viewperm($v)} {
2725 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2730 file rename -force "~/.gitk-new" "~/.gitk"
2735 proc resizeclistpanes {win w} {
2736 global oldwidth use_ttk
2737 if {[info exists oldwidth($win)]} {
2739 set s0 [$win sashpos 0]
2740 set s1 [$win sashpos 1]
2742 set s0 [$win sash coord 0]
2743 set s1 [$win sash coord 1]
2746 set sash0 [expr {int($w/2 - 2)}]
2747 set sash1 [expr {int($w*5/6 - 2)}]
2749 set factor [expr {1.0 * $w / $oldwidth($win)}]
2750 set sash0 [expr {int($factor * [lindex $s0 0])}]
2751 set sash1 [expr {int($factor * [lindex $s1 0])}]
2755 if {$sash1 < $sash0 + 20} {
2756 set sash1 [expr {$sash0 + 20}]
2758 if {$sash1 > $w - 10} {
2759 set sash1 [expr {$w - 10}]
2760 if {$sash0 > $sash1 - 20} {
2761 set sash0 [expr {$sash1 - 20}]
2766 $win sashpos 0 $sash0
2767 $win sashpos 1 $sash1
2769 $win sash place 0 $sash0 [lindex $s0 1]
2770 $win sash place 1 $sash1 [lindex $s1 1]
2773 set oldwidth($win) $w
2776 proc resizecdetpanes {win w} {
2777 global oldwidth use_ttk
2778 if {[info exists oldwidth($win)]} {
2780 set s0 [$win sashpos 0]
2782 set s0 [$win sash coord 0]
2785 set sash0 [expr {int($w*3/4 - 2)}]
2787 set factor [expr {1.0 * $w / $oldwidth($win)}]
2788 set sash0 [expr {int($factor * [lindex $s0 0])}]
2792 if {$sash0 > $w - 15} {
2793 set sash0 [expr {$w - 15}]
2797 $win sashpos 0 $sash0
2799 $win sash place 0 $sash0 [lindex $s0 1]
2802 set oldwidth($win) $w
2805 proc allcanvs args {
2806 global canv canv2 canv3
2812 proc bindall {event action} {
2813 global canv canv2 canv3
2814 bind $canv $event $action
2815 bind $canv2 $event $action
2816 bind $canv3 $event $action
2822 if {[winfo exists $w]} {
2827 wm title $w [mc "About gitk"]
2829 message $w.m -text [mc "
2830 Gitk - a commit viewer for git
2832 Copyright \u00a9 2005-2011 Paul Mackerras
2834 Use and redistribute under the terms of the GNU General Public License"] \
2835 -justify center -aspect 400 -border 2 -bg white -relief groove
2836 pack $w.m -side top -fill x -padx 2 -pady 2
2837 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2838 pack $w.ok -side bottom
2839 bind $w <Visibility> "focus $w.ok"
2840 bind $w <Key-Escape> "destroy $w"
2841 bind $w <Key-Return> "destroy $w"
2842 tk::PlaceWindow $w widget .
2848 if {[winfo exists $w]} {
2852 if {[tk windowingsystem] eq {aqua}} {
2858 wm title $w [mc "Gitk key bindings"]
2860 message $w.m -text "
2861 [mc "Gitk key bindings:"]
2863 [mc "<%s-Q> Quit" $M1T]
2864 [mc "<%s-W> Close window" $M1T]
2865 [mc "<Home> Move to first commit"]
2866 [mc "<End> Move to last commit"]
2867 [mc "<Up>, p, k Move up one commit"]
2868 [mc "<Down>, n, j Move down one commit"]
2869 [mc "<Left>, z, h Go back in history list"]
2870 [mc "<Right>, x, l Go forward in history list"]
2871 [mc "<PageUp> Move up one page in commit list"]
2872 [mc "<PageDown> Move down one page in commit list"]
2873 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2874 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2875 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2876 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2877 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2878 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2879 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2880 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2881 [mc "<Delete>, b Scroll diff view up one page"]
2882 [mc "<Backspace> Scroll diff view up one page"]
2883 [mc "<Space> Scroll diff view down one page"]
2884 [mc "u Scroll diff view up 18 lines"]
2885 [mc "d Scroll diff view down 18 lines"]
2886 [mc "<%s-F> Find" $M1T]
2887 [mc "<%s-G> Move to next find hit" $M1T]
2888 [mc "<Return> Move to next find hit"]
2889 [mc "/ Focus the search box"]
2890 [mc "? Move to previous find hit"]
2891 [mc "f Scroll diff view to next file"]
2892 [mc "<%s-S> Search for next hit in diff view" $M1T]
2893 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2894 [mc "<%s-KP+> Increase font size" $M1T]
2895 [mc "<%s-plus> Increase font size" $M1T]
2896 [mc "<%s-KP-> Decrease font size" $M1T]
2897 [mc "<%s-minus> Decrease font size" $M1T]
2900 -justify left -bg white -border 2 -relief groove
2901 pack $w.m -side top -fill both -padx 2 -pady 2
2902 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2903 bind $w <Key-Escape> [list destroy $w]
2904 pack $w.ok -side bottom
2905 bind $w <Visibility> "focus $w.ok"
2906 bind $w <Key-Escape> "destroy $w"
2907 bind $w <Key-Return> "destroy $w"
2910 # Procedures for manipulating the file list window at the
2911 # bottom right of the overall window.
2913 proc treeview {w l openlevs} {
2914 global treecontents treediropen treeheight treeparent treeindex
2924 set treecontents() {}
2925 $w conf -state normal
2927 while {[string range $f 0 $prefixend] ne $prefix} {
2928 if {$lev <= $openlevs} {
2929 $w mark set e:$treeindex($prefix) "end -1c"
2930 $w mark gravity e:$treeindex($prefix) left
2932 set treeheight($prefix) $ht
2933 incr ht [lindex $htstack end]
2934 set htstack [lreplace $htstack end end]
2935 set prefixend [lindex $prefendstack end]
2936 set prefendstack [lreplace $prefendstack end end]
2937 set prefix [string range $prefix 0 $prefixend]
2940 set tail [string range $f [expr {$prefixend+1}] end]
2941 while {[set slash [string first "/" $tail]] >= 0} {
2944 lappend prefendstack $prefixend
2945 incr prefixend [expr {$slash + 1}]
2946 set d [string range $tail 0 $slash]
2947 lappend treecontents($prefix) $d
2948 set oldprefix $prefix
2950 set treecontents($prefix) {}
2951 set treeindex($prefix) [incr ix]
2952 set treeparent($prefix) $oldprefix
2953 set tail [string range $tail [expr {$slash+1}] end]
2954 if {$lev <= $openlevs} {
2956 set treediropen($prefix) [expr {$lev < $openlevs}]
2957 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
2958 $w mark set d:$ix "end -1c"
2959 $w mark gravity d:$ix left
2961 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2963 $w image create end -align center -image $bm -padx 1 \
2965 $w insert end $d [highlight_tag $prefix]
2966 $w mark set s:$ix "end -1c"
2967 $w mark gravity s:$ix left
2972 if {$lev <= $openlevs} {
2975 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
2977 $w insert end $tail [highlight_tag $f]
2979 lappend treecontents($prefix) $tail
2982 while {$htstack ne {}} {
2983 set treeheight($prefix) $ht
2984 incr ht [lindex $htstack end]
2985 set htstack [lreplace $htstack end end]
2986 set prefixend [lindex $prefendstack end]
2987 set prefendstack [lreplace $prefendstack end end]
2988 set prefix [string range $prefix 0 $prefixend]
2990 $w conf -state disabled
2993 proc linetoelt {l} {
2994 global treeheight treecontents
2999 foreach e $treecontents($prefix) {
3004 if {[string index $e end] eq "/"} {
3005 set n $treeheight($prefix$e)
3017 proc highlight_tree {y prefix} {
3018 global treeheight treecontents cflist
3020 foreach e $treecontents($prefix) {
3022 if {[highlight_tag $path] ne {}} {
3023 $cflist tag add bold $y.0 "$y.0 lineend"
3026 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3027 set y [highlight_tree $y $path]
3033 proc treeclosedir {w dir} {
3034 global treediropen treeheight treeparent treeindex
3036 set ix $treeindex($dir)
3037 $w conf -state normal
3038 $w delete s:$ix e:$ix
3039 set treediropen($dir) 0
3040 $w image configure a:$ix -image tri-rt
3041 $w conf -state disabled
3042 set n [expr {1 - $treeheight($dir)}]
3043 while {$dir ne {}} {
3044 incr treeheight($dir) $n
3045 set dir $treeparent($dir)
3049 proc treeopendir {w dir} {
3050 global treediropen treeheight treeparent treecontents treeindex
3052 set ix $treeindex($dir)
3053 $w conf -state normal
3054 $w image configure a:$ix -image tri-dn
3055 $w mark set e:$ix s:$ix
3056 $w mark gravity e:$ix right
3059 set n [llength $treecontents($dir)]
3060 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3063 incr treeheight($x) $n
3065 foreach e $treecontents($dir) {
3067 if {[string index $e end] eq "/"} {
3068 set iy $treeindex($de)
3069 $w mark set d:$iy e:$ix
3070 $w mark gravity d:$iy left
3071 $w insert e:$ix $str
3072 set treediropen($de) 0
3073 $w image create e:$ix -align center -image tri-rt -padx 1 \
3075 $w insert e:$ix $e [highlight_tag $de]
3076 $w mark set s:$iy e:$ix
3077 $w mark gravity s:$iy left
3078 set treeheight($de) 1
3080 $w insert e:$ix $str
3081 $w insert e:$ix $e [highlight_tag $de]
3084 $w mark gravity e:$ix right
3085 $w conf -state disabled
3086 set treediropen($dir) 1
3087 set top [lindex [split [$w index @0,0] .] 0]
3088 set ht [$w cget -height]
3089 set l [lindex [split [$w index s:$ix] .] 0]
3092 } elseif {$l + $n + 1 > $top + $ht} {
3093 set top [expr {$l + $n + 2 - $ht}]
3101 proc treeclick {w x y} {
3102 global treediropen cmitmode ctext cflist cflist_top
3104 if {$cmitmode ne "tree"} return
3105 if {![info exists cflist_top]} return
3106 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3107 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3108 $cflist tag add highlight $l.0 "$l.0 lineend"
3114 set e [linetoelt $l]
3115 if {[string index $e end] ne "/"} {
3117 } elseif {$treediropen($e)} {
3124 proc setfilelist {id} {
3125 global treefilelist cflist jump_to_here
3127 treeview $cflist $treefilelist($id) 0
3128 if {$jump_to_here ne {}} {
3129 set f [lindex $jump_to_here 0]
3130 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3136 image create bitmap tri-rt -background black -foreground blue -data {
3137 #define tri-rt_width 13
3138 #define tri-rt_height 13
3139 static unsigned char tri-rt_bits[] = {
3140 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3141 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3144 #define tri-rt-mask_width 13
3145 #define tri-rt-mask_height 13
3146 static unsigned char tri-rt-mask_bits[] = {
3147 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3148 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3151 image create bitmap tri-dn -background black -foreground blue -data {
3152 #define tri-dn_width 13
3153 #define tri-dn_height 13
3154 static unsigned char tri-dn_bits[] = {
3155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3156 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3159 #define tri-dn-mask_width 13
3160 #define tri-dn-mask_height 13
3161 static unsigned char tri-dn-mask_bits[] = {
3162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3163 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3167 image create bitmap reficon-T -background black -foreground yellow -data {
3168 #define tagicon_width 13
3169 #define tagicon_height 9
3170 static unsigned char tagicon_bits[] = {
3171 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3172 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3174 #define tagicon-mask_width 13
3175 #define tagicon-mask_height 9
3176 static unsigned char tagicon-mask_bits[] = {
3177 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3178 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3181 #define headicon_width 13
3182 #define headicon_height 9
3183 static unsigned char headicon_bits[] = {
3184 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3185 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3188 #define headicon-mask_width 13
3189 #define headicon-mask_height 9
3190 static unsigned char headicon-mask_bits[] = {
3191 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3192 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3194 image create bitmap reficon-H -background black -foreground green \
3195 -data $rectdata -maskdata $rectmask
3196 image create bitmap reficon-o -background black -foreground "#ddddff" \
3197 -data $rectdata -maskdata $rectmask
3199 proc init_flist {first} {
3200 global cflist cflist_top difffilestart
3202 $cflist conf -state normal
3203 $cflist delete 0.0 end
3205 $cflist insert end $first
3207 $cflist tag add highlight 1.0 "1.0 lineend"
3209 catch {unset cflist_top}
3211 $cflist conf -state disabled
3212 set difffilestart {}
3215 proc highlight_tag {f} {
3216 global highlight_paths
3218 foreach p $highlight_paths {
3219 if {[string match $p $f]} {
3226 proc highlight_filelist {} {
3227 global cmitmode cflist
3229 $cflist conf -state normal
3230 if {$cmitmode ne "tree"} {
3231 set end [lindex [split [$cflist index end] .] 0]
3232 for {set l 2} {$l < $end} {incr l} {
3233 set line [$cflist get $l.0 "$l.0 lineend"]
3234 if {[highlight_tag $line] ne {}} {
3235 $cflist tag add bold $l.0 "$l.0 lineend"
3241 $cflist conf -state disabled
3244 proc unhighlight_filelist {} {
3247 $cflist conf -state normal
3248 $cflist tag remove bold 1.0 end
3249 $cflist conf -state disabled
3252 proc add_flist {fl} {
3255 $cflist conf -state normal
3257 $cflist insert end "\n"
3258 $cflist insert end $f [highlight_tag $f]
3260 $cflist conf -state disabled
3263 proc sel_flist {w x y} {
3264 global ctext difffilestart cflist cflist_top cmitmode
3266 if {$cmitmode eq "tree"} return
3267 if {![info exists cflist_top]} return
3268 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3269 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3270 $cflist tag add highlight $l.0 "$l.0 lineend"
3275 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3279 proc pop_flist_menu {w X Y x y} {
3280 global ctext cflist cmitmode flist_menu flist_menu_file
3281 global treediffs diffids
3284 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3286 if {$cmitmode eq "tree"} {
3287 set e [linetoelt $l]
3288 if {[string index $e end] eq "/"} return
3290 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3292 set flist_menu_file $e
3293 set xdiffstate "normal"
3294 if {$cmitmode eq "tree"} {
3295 set xdiffstate "disabled"
3297 # Disable "External diff" item in tree mode
3298 $flist_menu entryconf 2 -state $xdiffstate
3299 tk_popup $flist_menu $X $Y
3302 proc find_ctext_fileinfo {line} {
3303 global ctext_file_names ctext_file_lines
3305 set ok [bsearch $ctext_file_lines $line]
3306 set tline [lindex $ctext_file_lines $ok]
3308 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3311 return [list [lindex $ctext_file_names $ok] $tline]
3315 proc pop_diff_menu {w X Y x y} {
3316 global ctext diff_menu flist_menu_file
3317 global diff_menu_txtpos diff_menu_line
3318 global diff_menu_filebase
3320 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3321 set diff_menu_line [lindex $diff_menu_txtpos 0]
3322 # don't pop up the menu on hunk-separator or file-separator lines
3323 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3327 set f [find_ctext_fileinfo $diff_menu_line]
3328 if {$f eq {}} return
3329 set flist_menu_file [lindex $f 0]
3330 set diff_menu_filebase [lindex $f 1]
3331 tk_popup $diff_menu $X $Y
3334 proc flist_hl {only} {
3335 global flist_menu_file findstring gdttype
3337 set x [shellquote $flist_menu_file]
3338 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3341 append findstring " " $x
3343 set gdttype [mc "touching paths:"]
3346 proc gitknewtmpdir {} {
3347 global diffnum gitktmpdir gitdir
3349 if {![info exists gitktmpdir]} {
3350 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3351 if {[catch {file mkdir $gitktmpdir} err]} {
3352 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3359 set diffdir [file join $gitktmpdir $diffnum]
3360 if {[catch {file mkdir $diffdir} err]} {
3361 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3367 proc save_file_from_commit {filename output what} {
3370 if {[catch {exec git show $filename -- > $output} err]} {
3371 if {[string match "fatal: bad revision *" $err]} {
3374 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3380 proc external_diff_get_one_file {diffid filename diffdir} {
3381 global nullid nullid2 nullfile
3384 if {$diffid == $nullid} {
3385 set difffile [file join $worktree $filename]
3386 if {[file exists $difffile]} {
3391 if {$diffid == $nullid2} {
3392 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3393 return [save_file_from_commit :$filename $difffile index]
3395 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3396 return [save_file_from_commit $diffid:$filename $difffile \
3400 proc external_diff {} {
3401 global nullid nullid2
3402 global flist_menu_file
3406 if {[llength $diffids] == 1} {
3407 # no reference commit given
3408 set diffidto [lindex $diffids 0]
3409 if {$diffidto eq $nullid} {
3410 # diffing working copy with index
3411 set diffidfrom $nullid2
3412 } elseif {$diffidto eq $nullid2} {
3413 # diffing index with HEAD
3414 set diffidfrom "HEAD"
3416 # use first parent commit
3417 global parentlist selectedline
3418 set diffidfrom [lindex $parentlist $selectedline 0]
3421 set diffidfrom [lindex $diffids 0]
3422 set diffidto [lindex $diffids 1]
3425 # make sure that several diffs wont collide
3426 set diffdir [gitknewtmpdir]
3427 if {$diffdir eq {}} return
3429 # gather files to diff
3430 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3431 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3433 if {$difffromfile ne {} && $difftofile ne {}} {
3434 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3435 if {[catch {set fl [open |$cmd r]} err]} {
3436 file delete -force $diffdir
3437 error_popup "$extdifftool: [mc "command failed:"] $err"
3439 fconfigure $fl -blocking 0
3440 filerun $fl [list delete_at_eof $fl $diffdir]
3445 proc find_hunk_blamespec {base line} {
3448 # Find and parse the hunk header
3449 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3450 if {$s_lix eq {}} return
3452 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3453 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3454 s_line old_specs osz osz1 new_line nsz]} {
3458 # base lines for the parents
3459 set base_lines [list $new_line]
3460 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3461 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3462 old_spec old_line osz]} {
3465 lappend base_lines $old_line
3468 # Now scan the lines to determine offset within the hunk
3469 set max_parent [expr {[llength $base_lines]-2}]
3471 set s_lno [lindex [split $s_lix "."] 0]
3473 # Determine if the line is removed
3474 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3475 if {[string match {[-+ ]*} $chunk]} {
3476 set removed_idx [string first "-" $chunk]
3477 # Choose a parent index
3478 if {$removed_idx >= 0} {
3479 set parent $removed_idx
3481 set unchanged_idx [string first " " $chunk]
3482 if {$unchanged_idx >= 0} {
3483 set parent $unchanged_idx
3485 # blame the current commit
3489 # then count other lines that belong to it
3490 for {set i $line} {[incr i -1] > $s_lno} {} {
3491 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3492 # Determine if the line is removed
3493 set removed_idx [string first "-" $chunk]
3495 set code [string index $chunk $parent]
3496 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3500 if {$removed_idx < 0} {
3510 incr dline [lindex $base_lines $parent]
3511 return [list $parent $dline]
3514 proc external_blame_diff {} {
3515 global currentid cmitmode
3516 global diff_menu_txtpos diff_menu_line
3517 global diff_menu_filebase flist_menu_file
3519 if {$cmitmode eq "tree"} {
3521 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3523 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3525 set parent_idx [lindex $hinfo 0]
3526 set line [lindex $hinfo 1]
3533 external_blame $parent_idx $line
3536 # Find the SHA1 ID of the blob for file $fname in the index
3538 proc index_sha1 {fname} {
3539 set f [open [list | git ls-files -s $fname] r]
3540 while {[gets $f line] >= 0} {
3541 set info [lindex [split $line "\t"] 0]
3542 set stage [lindex $info 2]
3543 if {$stage eq "0" || $stage eq "2"} {
3545 return [lindex $info 1]
3552 # Turn an absolute path into one relative to the current directory
3553 proc make_relative {f} {
3554 if {[file pathtype $f] eq "relative"} {
3557 set elts [file split $f]
3558 set here [file split [pwd]]
3563 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3570 set elts [concat $res [lrange $elts $ei end]]
3571 return [eval file join $elts]
3574 proc external_blame {parent_idx {line {}}} {
3575 global flist_menu_file cdup
3576 global nullid nullid2
3577 global parentlist selectedline currentid
3579 if {$parent_idx > 0} {
3580 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3582 set base_commit $currentid
3585 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3586 error_popup [mc "No such commit"]
3590 set cmdline [list git gui blame]
3591 if {$line ne {} && $line > 1} {
3592 lappend cmdline "--line=$line"
3594 set f [file join $cdup $flist_menu_file]
3595 # Unfortunately it seems git gui blame doesn't like
3596 # being given an absolute path...
3597 set f [make_relative $f]
3598 lappend cmdline $base_commit $f
3599 if {[catch {eval exec $cmdline &} err]} {
3600 error_popup "[mc "git gui blame: command failed:"] $err"
3604 proc show_line_source {} {
3605 global cmitmode currentid parents curview blamestuff blameinst
3606 global diff_menu_line diff_menu_filebase flist_menu_file
3607 global nullid nullid2 gitdir cdup
3610 if {$cmitmode eq "tree"} {
3612 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3614 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3615 if {$h eq {}} return
3616 set pi [lindex $h 0]
3618 mark_ctext_line $diff_menu_line
3622 if {$currentid eq $nullid} {
3624 # must be a merge in progress...
3626 # get the last line from .git/MERGE_HEAD
3627 set f [open [file join $gitdir MERGE_HEAD] r]
3628 set id [lindex [split [read $f] "\n"] end-1]
3631 error_popup [mc "Couldn't read merge head: %s" $err]
3634 } elseif {$parents($curview,$currentid) eq $nullid2} {
3635 # need to do the blame from the index
3637 set from_index [index_sha1 $flist_menu_file]
3639 error_popup [mc "Error reading index: %s" $err]
3643 set id $parents($curview,$currentid)
3646 set id [lindex $parents($curview,$currentid) $pi]
3648 set line [lindex $h 1]
3651 if {$from_index ne {}} {
3652 lappend blameargs | git cat-file blob $from_index
3654 lappend blameargs | git blame -p -L$line,+1
3655 if {$from_index ne {}} {
3656 lappend blameargs --contents -
3658 lappend blameargs $id
3660 lappend blameargs -- [file join $cdup $flist_menu_file]
3662 set f [open $blameargs r]
3664 error_popup [mc "Couldn't start git blame: %s" $err]
3667 nowbusy blaming [mc "Searching"]
3668 fconfigure $f -blocking 0
3669 set i [reg_instance $f]
3670 set blamestuff($i) {}
3672 filerun $f [list read_line_source $f $i]
3675 proc stopblaming {} {
3678 if {[info exists blameinst]} {
3679 stop_instance $blameinst
3685 proc read_line_source {fd inst} {
3686 global blamestuff curview commfd blameinst nullid nullid2
3688 while {[gets $fd line] >= 0} {
3689 lappend blamestuff($inst) $line
3697 fconfigure $fd -blocking 1
3698 if {[catch {close $fd} err]} {
3699 error_popup [mc "Error running git blame: %s" $err]
3704 set line [split [lindex $blamestuff($inst) 0] " "]
3705 set id [lindex $line 0]
3706 set lnum [lindex $line 1]
3707 if {[string length $id] == 40 && [string is xdigit $id] &&
3708 [string is digit -strict $lnum]} {
3709 # look for "filename" line
3710 foreach l $blamestuff($inst) {
3711 if {[string match "filename *" $l]} {
3712 set fname [string range $l 9 end]
3718 # all looks good, select it
3719 if {$id eq $nullid} {
3720 # blame uses all-zeroes to mean not committed,
3721 # which would mean a change in the index
3724 if {[commitinview $id $curview]} {
3725 selectline [rowofcommit $id] 1 [list $fname $lnum]
3727 error_popup [mc "That line comes from commit %s, \
3728 which is not in this view" [shortids $id]]
3731 puts "oops couldn't parse git blame output"
3736 # delete $dir when we see eof on $f (presumably because the child has exited)
3737 proc delete_at_eof {f dir} {
3738 while {[gets $f line] >= 0} {}
3740 if {[catch {close $f} err]} {
3741 error_popup "[mc "External diff viewer failed:"] $err"
3743 file delete -force $dir
3749 # Functions for adding and removing shell-type quoting
3751 proc shellquote {str} {
3752 if {![string match "*\['\"\\ \t]*" $str]} {
3755 if {![string match "*\['\"\\]*" $str]} {
3758 if {![string match "*'*" $str]} {
3761 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3764 proc shellarglist {l} {
3770 append str [shellquote $a]
3775 proc shelldequote {str} {
3780 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3781 append ret [string range $str $used end]
3782 set used [string length $str]
3785 set first [lindex $first 0]
3786 set ch [string index $str $first]
3787 if {$first > $used} {
3788 append ret [string range $str $used [expr {$first - 1}]]
3791 if {$ch eq " " || $ch eq "\t"} break
3794 set first [string first "'" $str $used]
3796 error "unmatched single-quote"
3798 append ret [string range $str $used [expr {$first - 1}]]
3803 if {$used >= [string length $str]} {
3804 error "trailing backslash"
3806 append ret [string index $str $used]
3811 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3812 error "unmatched double-quote"
3814 set first [lindex $first 0]
3815 set ch [string index $str $first]
3816 if {$first > $used} {
3817 append ret [string range $str $used [expr {$first - 1}]]
3820 if {$ch eq "\""} break
3822 append ret [string index $str $used]
3826 return [list $used $ret]
3829 proc shellsplit {str} {
3832 set str [string trimleft $str]
3833 if {$str eq {}} break
3834 set dq [shelldequote $str]
3835 set n [lindex $dq 0]
3836 set word [lindex $dq 1]
3837 set str [string range $str $n end]
3843 # Code to implement multiple views
3845 proc newview {ishighlight} {
3846 global nextviewnum newviewname newishighlight
3847 global revtreeargs viewargscmd newviewopts curview
3849 set newishighlight $ishighlight
3851 if {[winfo exists $top]} {
3855 decode_view_opts $nextviewnum $revtreeargs
3856 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3857 set newviewopts($nextviewnum,perm) 0
3858 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3859 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3862 set known_view_options {
3863 {perm b . {} {mc "Remember this view"}}
3864 {reflabel l + {} {mc "References (space separated list):"}}
3865 {refs t15 .. {} {mc "Branches & tags:"}}
3866 {allrefs b *. "--all" {mc "All refs"}}
3867 {branches b . "--branches" {mc "All (local) branches"}}
3868 {tags b . "--tags" {mc "All tags"}}
3869 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3870 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3871 {author t15 .. "--author=*" {mc "Author:"}}
3872 {committer t15 . "--committer=*" {mc "Committer:"}}
3873 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3874 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3875 {changes_l l + {} {mc "Changes to Files:"}}
3876 {pickaxe_s r0 . {} {mc "Fixed String"}}
3877 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3878 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3879 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3880 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3881 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3882 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3883 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3884 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3885 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3886 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3887 {lright b . "--left-right" {mc "Mark branch sides"}}
3888 {first b . "--first-parent" {mc "Limit to first parent"}}
3889 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3890 {args t50 *. {} {mc "Additional arguments to git log:"}}
3891 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3892 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3895 # Convert $newviewopts($n, ...) into args for git log.
3896 proc encode_view_opts {n} {
3897 global known_view_options newviewopts
3900 foreach opt $known_view_options {
3901 set patterns [lindex $opt 3]
3902 if {$patterns eq {}} continue
3903 set pattern [lindex $patterns 0]
3905 if {[lindex $opt 1] eq "b"} {
3906 set val $newviewopts($n,[lindex $opt 0])
3908 lappend rargs $pattern
3910 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
3911 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
3912 set val $newviewopts($n,$button_id)
3913 if {$val eq $value} {
3914 lappend rargs $pattern
3917 set val $newviewopts($n,[lindex $opt 0])
3918 set val [string trim $val]
3920 set pfix [string range $pattern 0 end-1]
3921 lappend rargs $pfix$val
3925 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
3926 return [concat $rargs [shellsplit $newviewopts($n,args)]]
3929 # Fill $newviewopts($n, ...) based on args for git log.
3930 proc decode_view_opts {n view_args} {
3931 global known_view_options newviewopts
3933 foreach opt $known_view_options {
3934 set id [lindex $opt 0]
3935 if {[lindex $opt 1] eq "b"} {
3938 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
3940 regexp {^(.*_)} $id uselessvar id
3946 set newviewopts($n,$id) $val
3950 foreach arg $view_args {
3951 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
3952 && ![info exists found(limit)]} {
3953 set newviewopts($n,limit) $cnt
3958 foreach opt $known_view_options {
3959 set id [lindex $opt 0]
3960 if {[info exists found($id)]} continue
3961 foreach pattern [lindex $opt 3] {
3962 if {![string match $pattern $arg]} continue
3963 if {[lindex $opt 1] eq "b"} {
3966 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
3968 regexp {^(.*_)} $id uselessvar id
3972 set size [string length $pattern]
3973 set val [string range $arg [expr {$size-1}] end]
3975 set newviewopts($n,$id) $val
3979 if {[info exists val]} break
3981 if {[info exists val]} continue
3982 if {[regexp {^-} $arg]} {
3985 lappend refargs $arg
3988 set newviewopts($n,refs) [shellarglist $refargs]
3989 set newviewopts($n,args) [shellarglist $oargs]
3992 proc edit_or_newview {} {
4004 global viewname viewperm newviewname newviewopts
4005 global viewargs viewargscmd
4007 set top .gitkvedit-$curview
4008 if {[winfo exists $top]} {
4012 decode_view_opts $curview $viewargs($curview)
4013 set newviewname($curview) $viewname($curview)
4014 set newviewopts($curview,perm) $viewperm($curview)
4015 set newviewopts($curview,cmd) $viewargscmd($curview)
4016 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4019 proc vieweditor {top n title} {
4020 global newviewname newviewopts viewfiles bgcolor
4021 global known_view_options NS
4024 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4025 make_transient $top .
4028 ${NS}::frame $top.nfr
4029 ${NS}::label $top.nl -text [mc "View Name"]
4030 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4031 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4032 pack $top.nl -in $top.nfr -side left -padx {0 5}
4033 pack $top.name -in $top.nfr -side left -padx {0 25}
4039 foreach opt $known_view_options {
4040 set id [lindex $opt 0]
4041 set type [lindex $opt 1]
4042 set flags [lindex $opt 2]
4043 set title [eval [lindex $opt 4]]
4046 if {$flags eq "+" || $flags eq "*"} {
4047 set cframe $top.fr$cnt
4049 ${NS}::frame $cframe
4050 pack $cframe -in $top -fill x -pady 3 -padx 3
4051 set cexpand [expr {$flags eq "*"}]
4052 } elseif {$flags eq ".." || $flags eq "*."} {
4053 set cframe $top.fr$cnt
4055 ${NS}::frame $cframe
4056 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4057 set cexpand [expr {$flags eq "*."}]
4063 ${NS}::label $cframe.l_$id -text $title
4064 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4065 } elseif {$type eq "b"} {
4066 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4067 pack $cframe.c_$id -in $cframe -side left \
4068 -padx [list $lxpad 0] -expand $cexpand -anchor w
4069 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4070 regexp {^(.*_)} $id uselessvar button_id
4071 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4072 pack $cframe.c_$id -in $cframe -side left \
4073 -padx [list $lxpad 0] -expand $cexpand -anchor w
4074 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4075 ${NS}::label $cframe.l_$id -text $title
4076 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4077 -textvariable newviewopts($n,$id)
4078 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4079 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4080 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4081 ${NS}::label $cframe.l_$id -text $title
4082 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4083 -textvariable newviewopts($n,$id)
4084 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4085 pack $cframe.e_$id -in $cframe -side top -fill x
4086 } elseif {$type eq "path"} {
4087 ${NS}::label $top.l -text $title
4088 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4089 text $top.t -width 40 -height 5 -background $bgcolor
4090 if {[info exists viewfiles($n)]} {
4091 foreach f $viewfiles($n) {
4092 $top.t insert end $f
4093 $top.t insert end "\n"
4095 $top.t delete {end - 1c} end
4096 $top.t mark set insert 0.0
4098 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4102 ${NS}::frame $top.buts
4103 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4104 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4105 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4106 bind $top <Control-Return> [list newviewok $top $n]
4107 bind $top <F5> [list newviewok $top $n 1]
4108 bind $top <Escape> [list destroy $top]
4109 grid $top.buts.ok $top.buts.apply $top.buts.can
4110 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4111 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4112 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4113 pack $top.buts -in $top -side top -fill x
4117 proc doviewmenu {m first cmd op argv} {
4118 set nmenu [$m index end]
4119 for {set i $first} {$i <= $nmenu} {incr i} {
4120 if {[$m entrycget $i -command] eq $cmd} {
4121 eval $m $op $i $argv
4127 proc allviewmenus {n op args} {
4130 doviewmenu .bar.view 5 [list showview $n] $op $args
4131 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4134 proc newviewok {top n {apply 0}} {
4135 global nextviewnum newviewperm newviewname newishighlight
4136 global viewname viewfiles viewperm selectedview curview
4137 global viewargs viewargscmd newviewopts viewhlmenu
4140 set newargs [encode_view_opts $n]
4142 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4146 foreach f [split [$top.t get 0.0 end] "\n"] {
4147 set ft [string trim $f]
4152 if {![info exists viewfiles($n)]} {
4153 # creating a new view
4155 set viewname($n) $newviewname($n)
4156 set viewperm($n) $newviewopts($n,perm)
4157 set viewfiles($n) $files
4158 set viewargs($n) $newargs
4159 set viewargscmd($n) $newviewopts($n,cmd)
4161 if {!$newishighlight} {
4164 run addvhighlight $n
4167 # editing an existing view
4168 set viewperm($n) $newviewopts($n,perm)
4169 if {$newviewname($n) ne $viewname($n)} {
4170 set viewname($n) $newviewname($n)
4171 doviewmenu .bar.view 5 [list showview $n] \
4172 entryconf [list -label $viewname($n)]
4173 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4174 # entryconf [list -label $viewname($n) -value $viewname($n)]
4176 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4177 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4178 set viewfiles($n) $files
4179 set viewargs($n) $newargs
4180 set viewargscmd($n) $newviewopts($n,cmd)
4181 if {$curview == $n} {
4187 catch {destroy $top}
4191 global curview viewperm hlview selectedhlview
4193 if {$curview == 0} return
4194 if {[info exists hlview] && $hlview == $curview} {
4195 set selectedhlview [mc "None"]
4198 allviewmenus $curview delete
4199 set viewperm($curview) 0
4203 proc addviewmenu {n} {
4204 global viewname viewhlmenu
4206 .bar.view add radiobutton -label $viewname($n) \
4207 -command [list showview $n] -variable selectedview -value $n
4208 #$viewhlmenu add radiobutton -label $viewname($n) \
4209 # -command [list addvhighlight $n] -variable selectedhlview
4213 global curview cached_commitrow ordertok
4214 global displayorder parentlist rowidlist rowisopt rowfinal
4215 global colormap rowtextx nextcolor canvxmax
4216 global numcommits viewcomplete
4217 global selectedline currentid canv canvy0
4219 global pending_select mainheadid
4222 global hlview selectedhlview commitinterest
4224 if {$n == $curview} return
4226 set ymax [lindex [$canv cget -scrollregion] 3]
4227 set span [$canv yview]
4228 set ytop [expr {[lindex $span 0] * $ymax}]
4229 set ybot [expr {[lindex $span 1] * $ymax}]
4230 set yscreen [expr {($ybot - $ytop) / 2}]
4231 if {$selectedline ne {}} {
4232 set selid $currentid
4233 set y [yc $selectedline]
4234 if {$ytop < $y && $y < $ybot} {
4235 set yscreen [expr {$y - $ytop}]
4237 } elseif {[info exists pending_select]} {
4238 set selid $pending_select
4239 unset pending_select
4243 catch {unset treediffs}
4245 if {[info exists hlview] && $hlview == $n} {
4247 set selectedhlview [mc "None"]
4249 catch {unset commitinterest}
4250 catch {unset cached_commitrow}
4251 catch {unset ordertok}
4255 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4256 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4259 if {![info exists viewcomplete($n)]} {
4269 set numcommits $commitidx($n)
4271 catch {unset colormap}
4272 catch {unset rowtextx}
4274 set canvxmax [$canv cget -width]
4280 if {$selid ne {} && [commitinview $selid $n]} {
4281 set row [rowofcommit $selid]
4282 # try to get the selected row in the same position on the screen
4283 set ymax [lindex [$canv cget -scrollregion] 3]
4284 set ytop [expr {[yc $row] - $yscreen}]
4288 set yf [expr {$ytop * 1.0 / $ymax}]
4290 allcanvs yview moveto $yf
4294 } elseif {!$viewcomplete($n)} {
4295 reset_pending_select $selid
4297 reset_pending_select {}
4299 if {[commitinview $pending_select $curview]} {
4300 selectline [rowofcommit $pending_select] 1
4302 set row [first_real_row]
4303 if {$row < $numcommits} {
4308 if {!$viewcomplete($n)} {
4309 if {$numcommits == 0} {
4310 show_status [mc "Reading commits..."]
4312 } elseif {$numcommits == 0} {
4313 show_status [mc "No commits selected"]
4317 # Stuff relating to the highlighting facility
4319 proc ishighlighted {id} {
4320 global vhighlights fhighlights nhighlights rhighlights
4322 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4323 return $nhighlights($id)
4325 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4326 return $vhighlights($id)
4328 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4329 return $fhighlights($id)
4331 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4332 return $rhighlights($id)
4337 proc bolden {id font} {
4338 global canv linehtag currentid boldids need_redisplay markedid
4340 # need_redisplay = 1 means the display is stale and about to be redrawn
4341 if {$need_redisplay} return
4343 $canv itemconf $linehtag($id) -font $font
4344 if {[info exists currentid] && $id eq $currentid} {
4346 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4347 -outline {{}} -tags secsel \
4348 -fill [$canv cget -selectbackground]]
4351 if {[info exists markedid] && $id eq $markedid} {
4356 proc bolden_name {id font} {
4357 global canv2 linentag currentid boldnameids need_redisplay
4359 if {$need_redisplay} return
4360 lappend boldnameids $id
4361 $canv2 itemconf $linentag($id) -font $font
4362 if {[info exists currentid] && $id eq $currentid} {
4363 $canv2 delete secsel
4364 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4365 -outline {{}} -tags secsel \
4366 -fill [$canv2 cget -selectbackground]]
4375 foreach id $boldids {
4376 if {![ishighlighted $id]} {
4379 lappend stillbold $id
4382 set boldids $stillbold
4385 proc addvhighlight {n} {
4386 global hlview viewcomplete curview vhl_done commitidx
4388 if {[info exists hlview]} {
4392 if {$n != $curview && ![info exists viewcomplete($n)]} {
4395 set vhl_done $commitidx($hlview)
4396 if {$vhl_done > 0} {
4401 proc delvhighlight {} {
4402 global hlview vhighlights
4404 if {![info exists hlview]} return
4406 catch {unset vhighlights}
4410 proc vhighlightmore {} {
4411 global hlview vhl_done commitidx vhighlights curview
4413 set max $commitidx($hlview)
4414 set vr [visiblerows]
4415 set r0 [lindex $vr 0]
4416 set r1 [lindex $vr 1]
4417 for {set i $vhl_done} {$i < $max} {incr i} {
4418 set id [commitonrow $i $hlview]
4419 if {[commitinview $id $curview]} {
4420 set row [rowofcommit $id]
4421 if {$r0 <= $row && $row <= $r1} {
4422 if {![highlighted $row]} {
4423 bolden $id mainfontbold
4425 set vhighlights($id) 1
4433 proc askvhighlight {row id} {
4434 global hlview vhighlights iddrawn
4436 if {[commitinview $id $hlview]} {
4437 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4438 bolden $id mainfontbold
4440 set vhighlights($id) 1
4442 set vhighlights($id) 0
4446 proc hfiles_change {} {
4447 global highlight_files filehighlight fhighlights fh_serial
4448 global highlight_paths
4450 if {[info exists filehighlight]} {
4451 # delete previous highlights
4452 catch {close $filehighlight}
4454 catch {unset fhighlights}
4456 unhighlight_filelist
4458 set highlight_paths {}
4459 after cancel do_file_hl $fh_serial
4461 if {$highlight_files ne {}} {
4462 after 300 do_file_hl $fh_serial
4466 proc gdttype_change {name ix op} {
4467 global gdttype highlight_files findstring findpattern
4470 if {$findstring ne {}} {
4471 if {$gdttype eq [mc "containing:"]} {
4472 if {$highlight_files ne {}} {
4473 set highlight_files {}
4478 if {$findpattern ne {}} {
4482 set highlight_files $findstring
4487 # enable/disable findtype/findloc menus too
4490 proc find_change {name ix op} {
4491 global gdttype findstring highlight_files
4494 if {$gdttype eq [mc "containing:"]} {
4497 if {$highlight_files ne $findstring} {
4498 set highlight_files $findstring
4505 proc findcom_change args {
4506 global nhighlights boldnameids
4507 global findpattern findtype findstring gdttype
4510 # delete previous highlights, if any
4511 foreach id $boldnameids {
4512 bolden_name $id mainfont
4515 catch {unset nhighlights}
4518 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4520 } elseif {$findtype eq [mc "Regexp"]} {
4521 set findpattern $findstring
4523 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4525 set findpattern "*$e*"
4529 proc makepatterns {l} {
4532 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4533 if {[string index $ee end] eq "/"} {
4543 proc do_file_hl {serial} {
4544 global highlight_files filehighlight highlight_paths gdttype fhl_list
4545 global cdup findtype
4547 if {$gdttype eq [mc "touching paths:"]} {
4548 # If "exact" match then convert backslashes to forward slashes.
4549 # Most useful to support Windows-flavoured file paths.
4550 if {$findtype eq [mc "Exact"]} {
4551 set highlight_files [string map {"\\" "/"} $highlight_files]
4553 if {[catch {set paths [shellsplit $highlight_files]}]} return
4554 set highlight_paths [makepatterns $paths]
4556 set relative_paths {}
4557 foreach path $paths {
4558 lappend relative_paths [file join $cdup $path]
4560 set gdtargs [concat -- $relative_paths]
4561 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4562 set gdtargs [list "-S$highlight_files"]
4564 # must be "containing:", i.e. we're searching commit info
4567 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4568 set filehighlight [open $cmd r+]
4569 fconfigure $filehighlight -blocking 0
4570 filerun $filehighlight readfhighlight
4576 proc flushhighlights {} {
4577 global filehighlight fhl_list
4579 if {[info exists filehighlight]} {
4581 puts $filehighlight ""
4582 flush $filehighlight
4586 proc askfilehighlight {row id} {
4587 global filehighlight fhighlights fhl_list
4589 lappend fhl_list $id
4590 set fhighlights($id) -1
4591 puts $filehighlight $id
4594 proc readfhighlight {} {
4595 global filehighlight fhighlights curview iddrawn
4596 global fhl_list find_dirn
4598 if {![info exists filehighlight]} {
4602 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4603 set line [string trim $line]
4604 set i [lsearch -exact $fhl_list $line]
4605 if {$i < 0} continue
4606 for {set j 0} {$j < $i} {incr j} {
4607 set id [lindex $fhl_list $j]
4608 set fhighlights($id) 0
4610 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4611 if {$line eq {}} continue
4612 if {![commitinview $line $curview]} continue
4613 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4614 bolden $line mainfontbold
4616 set fhighlights($line) 1
4618 if {[eof $filehighlight]} {
4620 puts "oops, git diff-tree died"
4621 catch {close $filehighlight}
4625 if {[info exists find_dirn]} {
4631 proc doesmatch {f} {
4632 global findtype findpattern
4634 if {$findtype eq [mc "Regexp"]} {
4635 return [regexp $findpattern $f]
4636 } elseif {$findtype eq [mc "IgnCase"]} {
4637 return [string match -nocase $findpattern $f]
4639 return [string match $findpattern $f]
4643 proc askfindhighlight {row id} {
4644 global nhighlights commitinfo iddrawn
4646 global markingmatches
4648 if {![info exists commitinfo($id)]} {
4651 set info $commitinfo($id)
4653 set fldtypes [list [mc Headline] [mc Author] [mc Date] [mc Committer] [mc CDate] [mc Comments]]
4654 foreach f $info ty $fldtypes {
4655 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4657 if {$ty eq [mc "Author"]} {
4664 if {$isbold && [info exists iddrawn($id)]} {
4665 if {![ishighlighted $id]} {
4666 bolden $id mainfontbold
4668 bolden_name $id mainfontbold
4671 if {$markingmatches} {
4672 markrowmatches $row $id
4675 set nhighlights($id) $isbold
4678 proc markrowmatches {row id} {
4679 global canv canv2 linehtag linentag commitinfo findloc
4681 set headline [lindex $commitinfo($id) 0]
4682 set author [lindex $commitinfo($id) 1]
4683 $canv delete match$row
4684 $canv2 delete match$row
4685 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4686 set m [findmatches $headline]
4688 markmatches $canv $row $headline $linehtag($id) $m \
4689 [$canv itemcget $linehtag($id) -font] $row
4692 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4693 set m [findmatches $author]
4695 markmatches $canv2 $row $author $linentag($id) $m \
4696 [$canv2 itemcget $linentag($id) -font] $row
4701 proc vrel_change {name ix op} {
4702 global highlight_related
4705 if {$highlight_related ne [mc "None"]} {
4710 # prepare for testing whether commits are descendents or ancestors of a
4711 proc rhighlight_sel {a} {
4712 global descendent desc_todo ancestor anc_todo
4713 global highlight_related
4715 catch {unset descendent}
4716 set desc_todo [list $a]
4717 catch {unset ancestor}
4718 set anc_todo [list $a]
4719 if {$highlight_related ne [mc "None"]} {
4725 proc rhighlight_none {} {
4728 catch {unset rhighlights}
4732 proc is_descendent {a} {
4733 global curview children descendent desc_todo
4736 set la [rowofcommit $a]
4740 for {set i 0} {$i < [llength $todo]} {incr i} {
4741 set do [lindex $todo $i]
4742 if {[rowofcommit $do] < $la} {
4743 lappend leftover $do
4746 foreach nk $children($v,$do) {
4747 if {![info exists descendent($nk)]} {
4748 set descendent($nk) 1
4756 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4760 set descendent($a) 0
4761 set desc_todo $leftover
4764 proc is_ancestor {a} {
4765 global curview parents ancestor anc_todo
4768 set la [rowofcommit $a]
4772 for {set i 0} {$i < [llength $todo]} {incr i} {
4773 set do [lindex $todo $i]
4774 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4775 lappend leftover $do
4778 foreach np $parents($v,$do) {
4779 if {![info exists ancestor($np)]} {
4788 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4793 set anc_todo $leftover
4796 proc askrelhighlight {row id} {
4797 global descendent highlight_related iddrawn rhighlights
4798 global selectedline ancestor
4800 if {$selectedline eq {}} return
4802 if {$highlight_related eq [mc "Descendant"] ||
4803 $highlight_related eq [mc "Not descendant"]} {
4804 if {![info exists descendent($id)]} {
4807 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4810 } elseif {$highlight_related eq [mc "Ancestor"] ||
4811 $highlight_related eq [mc "Not ancestor"]} {
4812 if {![info exists ancestor($id)]} {
4815 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4819 if {[info exists iddrawn($id)]} {
4820 if {$isbold && ![ishighlighted $id]} {
4821 bolden $id mainfontbold
4824 set rhighlights($id) $isbold
4827 # Graph layout functions
4829 proc shortids {ids} {
4832 if {[llength $id] > 1} {
4833 lappend res [shortids $id]
4834 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4835 lappend res [string range $id 0 7]
4846 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4847 if {($n & $mask) != 0} {
4848 set ret [concat $ret $o]
4850 set o [concat $o $o]
4855 proc ordertoken {id} {
4856 global ordertok curview varcid varcstart varctok curview parents children
4857 global nullid nullid2
4859 if {[info exists ordertok($id)]} {
4860 return $ordertok($id)
4865 if {[info exists varcid($curview,$id)]} {
4866 set a $varcid($curview,$id)
4867 set p [lindex $varcstart($curview) $a]
4869 set p [lindex $children($curview,$id) 0]
4871 if {[info exists ordertok($p)]} {
4872 set tok $ordertok($p)
4875 set id [first_real_child $curview,$p]
4878 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4881 if {[llength $parents($curview,$id)] == 1} {
4882 lappend todo [list $p {}]
4884 set j [lsearch -exact $parents($curview,$id) $p]
4886 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4888 lappend todo [list $p [strrep $j]]
4891 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4892 set p [lindex $todo $i 0]
4893 append tok [lindex $todo $i 1]
4894 set ordertok($p) $tok
4896 set ordertok($origid) $tok
4900 # Work out where id should go in idlist so that order-token
4901 # values increase from left to right
4902 proc idcol {idlist id {i 0}} {
4903 set t [ordertoken $id]
4907 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4908 if {$i > [llength $idlist]} {
4909 set i [llength $idlist]
4911 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4914 if {$t > [ordertoken [lindex $idlist $i]]} {
4915 while {[incr i] < [llength $idlist] &&
4916 $t >= [ordertoken [lindex $idlist $i]]} {}
4922 proc initlayout {} {
4923 global rowidlist rowisopt rowfinal displayorder parentlist
4924 global numcommits canvxmax canv
4926 global colormap rowtextx
4935 set canvxmax [$canv cget -width]
4936 catch {unset colormap}
4937 catch {unset rowtextx}
4941 proc setcanvscroll {} {
4942 global canv canv2 canv3 numcommits linespc canvxmax canvy0
4943 global lastscrollset lastscrollrows
4945 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
4946 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
4947 $canv2 conf -scrollregion [list 0 0 0 $ymax]
4948 $canv3 conf -scrollregion [list 0 0 0 $ymax]
4949 set lastscrollset [clock clicks -milliseconds]
4950 set lastscrollrows $numcommits
4953 proc visiblerows {} {
4954 global canv numcommits linespc
4956 set ymax [lindex [$canv cget -scrollregion] 3]
4957 if {$ymax eq {} || $ymax == 0} return
4959 set y0 [expr {int([lindex $f 0] * $ymax)}]
4960 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
4964 set y1 [expr {int([lindex $f 1] * $ymax)}]
4965 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
4966 if {$r1 >= $numcommits} {
4967 set r1 [expr {$numcommits - 1}]
4969 return [list $r0 $r1]
4972 proc layoutmore {} {
4973 global commitidx viewcomplete curview
4974 global numcommits pending_select curview
4975 global lastscrollset lastscrollrows
4977 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
4978 [clock clicks -milliseconds] - $lastscrollset > 500} {
4981 if {[info exists pending_select] &&
4982 [commitinview $pending_select $curview]} {
4984 selectline [rowofcommit $pending_select] 1
4989 # With path limiting, we mightn't get the actual HEAD commit,
4990 # so ask git rev-list what is the first ancestor of HEAD that
4991 # touches a file in the path limit.
4992 proc get_viewmainhead {view} {
4993 global viewmainheadid vfilelimit viewinstances mainheadid
4996 set rfd [open [concat | git rev-list -1 $mainheadid \
4997 -- $vfilelimit($view)] r]
4998 set j [reg_instance $rfd]
4999 lappend viewinstances($view) $j
5000 fconfigure $rfd -blocking 0
5001 filerun $rfd [list getviewhead $rfd $j $view]
5002 set viewmainheadid($curview) {}
5006 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5007 proc getviewhead {fd inst view} {
5008 global viewmainheadid commfd curview viewinstances showlocalchanges
5011 if {[gets $fd line] < 0} {
5015 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5018 set viewmainheadid($view) $id
5021 set i [lsearch -exact $viewinstances($view) $inst]
5023 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5025 if {$showlocalchanges && $id ne {} && $view == $curview} {
5031 proc doshowlocalchanges {} {
5032 global curview viewmainheadid
5034 if {$viewmainheadid($curview) eq {}} return
5035 if {[commitinview $viewmainheadid($curview) $curview]} {
5038 interestedin $viewmainheadid($curview) dodiffindex
5042 proc dohidelocalchanges {} {
5043 global nullid nullid2 lserial curview
5045 if {[commitinview $nullid $curview]} {
5046 removefakerow $nullid
5048 if {[commitinview $nullid2 $curview]} {
5049 removefakerow $nullid2
5054 # spawn off a process to do git diff-index --cached HEAD
5055 proc dodiffindex {} {
5056 global lserial showlocalchanges vfilelimit curview
5059 if {!$showlocalchanges || !$hasworktree} return
5061 set cmd "|git diff-index --cached HEAD"
5062 if {$vfilelimit($curview) ne {}} {
5063 set cmd [concat $cmd -- $vfilelimit($curview)]
5065 set fd [open $cmd r]
5066 fconfigure $fd -blocking 0
5067 set i [reg_instance $fd]
5068 filerun $fd [list readdiffindex $fd $lserial $i]
5071 proc readdiffindex {fd serial inst} {
5072 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5076 if {[gets $fd line] < 0} {
5082 # we only need to see one line and we don't really care what it says...
5085 if {$serial != $lserial} {
5089 # now see if there are any local changes not checked in to the index
5090 set cmd "|git diff-files"
5091 if {$vfilelimit($curview) ne {}} {
5092 set cmd [concat $cmd -- $vfilelimit($curview)]
5094 set fd [open $cmd r]
5095 fconfigure $fd -blocking 0
5096 set i [reg_instance $fd]
5097 filerun $fd [list readdifffiles $fd $serial $i]
5099 if {$isdiff && ![commitinview $nullid2 $curview]} {
5100 # add the line for the changes in the index to the graph
5101 set hl [mc "Local changes checked in to index but not committed"]
5102 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5103 set commitdata($nullid2) "\n $hl\n"
5104 if {[commitinview $nullid $curview]} {
5105 removefakerow $nullid
5107 insertfakerow $nullid2 $viewmainheadid($curview)
5108 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5109 if {[commitinview $nullid $curview]} {
5110 removefakerow $nullid
5112 removefakerow $nullid2
5117 proc readdifffiles {fd serial inst} {
5118 global viewmainheadid nullid nullid2 curview
5119 global commitinfo commitdata lserial
5122 if {[gets $fd line] < 0} {
5128 # we only need to see one line and we don't really care what it says...
5131 if {$serial != $lserial} {
5135 if {$isdiff && ![commitinview $nullid $curview]} {
5136 # add the line for the local diff to the graph
5137 set hl [mc "Local uncommitted changes, not checked in to index"]
5138 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5139 set commitdata($nullid) "\n $hl\n"
5140 if {[commitinview $nullid2 $curview]} {
5143 set p $viewmainheadid($curview)
5145 insertfakerow $nullid $p
5146 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5147 removefakerow $nullid
5152 proc nextuse {id row} {
5153 global curview children
5155 if {[info exists children($curview,$id)]} {
5156 foreach kid $children($curview,$id) {
5157 if {![commitinview $kid $curview]} {
5160 if {[rowofcommit $kid] > $row} {
5161 return [rowofcommit $kid]
5165 if {[commitinview $id $curview]} {
5166 return [rowofcommit $id]
5171 proc prevuse {id row} {
5172 global curview children
5175 if {[info exists children($curview,$id)]} {
5176 foreach kid $children($curview,$id) {
5177 if {![commitinview $kid $curview]} break
5178 if {[rowofcommit $kid] < $row} {
5179 set ret [rowofcommit $kid]
5186 proc make_idlist {row} {
5187 global displayorder parentlist uparrowlen downarrowlen mingaplen
5188 global commitidx curview children
5190 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5194 set ra [expr {$row - $downarrowlen}]
5198 set rb [expr {$row + $uparrowlen}]
5199 if {$rb > $commitidx($curview)} {
5200 set rb $commitidx($curview)
5202 make_disporder $r [expr {$rb + 1}]
5204 for {} {$r < $ra} {incr r} {
5205 set nextid [lindex $displayorder [expr {$r + 1}]]
5206 foreach p [lindex $parentlist $r] {
5207 if {$p eq $nextid} continue
5208 set rn [nextuse $p $r]
5210 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5211 lappend ids [list [ordertoken $p] $p]
5215 for {} {$r < $row} {incr r} {
5216 set nextid [lindex $displayorder [expr {$r + 1}]]
5217 foreach p [lindex $parentlist $r] {
5218 if {$p eq $nextid} continue
5219 set rn [nextuse $p $r]
5220 if {$rn < 0 || $rn >= $row} {
5221 lappend ids [list [ordertoken $p] $p]
5225 set id [lindex $displayorder $row]
5226 lappend ids [list [ordertoken $id] $id]
5228 foreach p [lindex $parentlist $r] {
5229 set firstkid [lindex $children($curview,$p) 0]
5230 if {[rowofcommit $firstkid] < $row} {
5231 lappend ids [list [ordertoken $p] $p]
5235 set id [lindex $displayorder $r]
5237 set firstkid [lindex $children($curview,$id) 0]
5238 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5239 lappend ids [list [ordertoken $id] $id]
5244 foreach idx [lsort -unique $ids] {
5245 lappend idlist [lindex $idx 1]
5250 proc rowsequal {a b} {
5251 while {[set i [lsearch -exact $a {}]] >= 0} {
5252 set a [lreplace $a $i $i]
5254 while {[set i [lsearch -exact $b {}]] >= 0} {
5255 set b [lreplace $b $i $i]
5257 return [expr {$a eq $b}]
5260 proc makeupline {id row rend col} {
5261 global rowidlist uparrowlen downarrowlen mingaplen
5263 for {set r $rend} {1} {set r $rstart} {
5264 set rstart [prevuse $id $r]
5265 if {$rstart < 0} return
5266 if {$rstart < $row} break
5268 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5269 set rstart [expr {$rend - $uparrowlen - 1}]
5271 for {set r $rstart} {[incr r] <= $row} {} {
5272 set idlist [lindex $rowidlist $r]
5273 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5274 set col [idcol $idlist $id $col]
5275 lset rowidlist $r [linsert $idlist $col $id]
5281 proc layoutrows {row endrow} {
5282 global rowidlist rowisopt rowfinal displayorder
5283 global uparrowlen downarrowlen maxwidth mingaplen
5284 global children parentlist
5285 global commitidx viewcomplete curview
5287 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5290 set rm1 [expr {$row - 1}]
5291 foreach id [lindex $rowidlist $rm1] {
5296 set final [lindex $rowfinal $rm1]
5298 for {} {$row < $endrow} {incr row} {
5299 set rm1 [expr {$row - 1}]
5300 if {$rm1 < 0 || $idlist eq {}} {
5301 set idlist [make_idlist $row]
5304 set id [lindex $displayorder $rm1]
5305 set col [lsearch -exact $idlist $id]
5306 set idlist [lreplace $idlist $col $col]
5307 foreach p [lindex $parentlist $rm1] {
5308 if {[lsearch -exact $idlist $p] < 0} {
5309 set col [idcol $idlist $p $col]
5310 set idlist [linsert $idlist $col $p]
5311 # if not the first child, we have to insert a line going up
5312 if {$id ne [lindex $children($curview,$p) 0]} {
5313 makeupline $p $rm1 $row $col
5317 set id [lindex $displayorder $row]
5318 if {$row > $downarrowlen} {
5319 set termrow [expr {$row - $downarrowlen - 1}]
5320 foreach p [lindex $parentlist $termrow] {
5321 set i [lsearch -exact $idlist $p]
5322 if {$i < 0} continue
5323 set nr [nextuse $p $termrow]
5324 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5325 set idlist [lreplace $idlist $i $i]
5329 set col [lsearch -exact $idlist $id]
5331 set col [idcol $idlist $id]
5332 set idlist [linsert $idlist $col $id]
5333 if {$children($curview,$id) ne {}} {
5334 makeupline $id $rm1 $row $col
5337 set r [expr {$row + $uparrowlen - 1}]
5338 if {$r < $commitidx($curview)} {
5340 foreach p [lindex $parentlist $r] {
5341 if {[lsearch -exact $idlist $p] >= 0} continue
5342 set fk [lindex $children($curview,$p) 0]
5343 if {[rowofcommit $fk] < $row} {
5344 set x [idcol $idlist $p $x]
5345 set idlist [linsert $idlist $x $p]
5348 if {[incr r] < $commitidx($curview)} {
5349 set p [lindex $displayorder $r]
5350 if {[lsearch -exact $idlist $p] < 0} {
5351 set fk [lindex $children($curview,$p) 0]
5352 if {$fk ne {} && [rowofcommit $fk] < $row} {
5353 set x [idcol $idlist $p $x]
5354 set idlist [linsert $idlist $x $p]
5360 if {$final && !$viewcomplete($curview) &&
5361 $row + $uparrowlen + $mingaplen + $downarrowlen
5362 >= $commitidx($curview)} {
5365 set l [llength $rowidlist]
5367 lappend rowidlist $idlist
5369 lappend rowfinal $final
5370 } elseif {$row < $l} {
5371 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5372 lset rowidlist $row $idlist
5375 lset rowfinal $row $final
5377 set pad [ntimes [expr {$row - $l}] {}]
5378 set rowidlist [concat $rowidlist $pad]
5379 lappend rowidlist $idlist
5380 set rowfinal [concat $rowfinal $pad]
5381 lappend rowfinal $final
5382 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5388 proc changedrow {row} {
5389 global displayorder iddrawn rowisopt need_redisplay
5391 set l [llength $rowisopt]
5393 lset rowisopt $row 0
5394 if {$row + 1 < $l} {
5395 lset rowisopt [expr {$row + 1}] 0
5396 if {$row + 2 < $l} {
5397 lset rowisopt [expr {$row + 2}] 0
5401 set id [lindex $displayorder $row]
5402 if {[info exists iddrawn($id)]} {
5403 set need_redisplay 1
5407 proc insert_pad {row col npad} {
5410 set pad [ntimes $npad {}]
5411 set idlist [lindex $rowidlist $row]
5412 set bef [lrange $idlist 0 [expr {$col - 1}]]
5413 set aft [lrange $idlist $col end]
5414 set i [lsearch -exact $aft {}]
5416 set aft [lreplace $aft $i $i]
5418 lset rowidlist $row [concat $bef $pad $aft]
5422 proc optimize_rows {row col endrow} {
5423 global rowidlist rowisopt displayorder curview children
5428 for {} {$row < $endrow} {incr row; set col 0} {
5429 if {[lindex $rowisopt $row]} continue
5431 set y0 [expr {$row - 1}]
5432 set ym [expr {$row - 2}]
5433 set idlist [lindex $rowidlist $row]
5434 set previdlist [lindex $rowidlist $y0]
5435 if {$idlist eq {} || $previdlist eq {}} continue
5437 set pprevidlist [lindex $rowidlist $ym]
5438 if {$pprevidlist eq {}} continue
5444 for {} {$col < [llength $idlist]} {incr col} {
5445 set id [lindex $idlist $col]
5446 if {[lindex $previdlist $col] eq $id} continue
5451 set x0 [lsearch -exact $previdlist $id]
5452 if {$x0 < 0} continue
5453 set z [expr {$x0 - $col}]
5457 set xm [lsearch -exact $pprevidlist $id]
5459 set z0 [expr {$xm - $x0}]
5463 # if row y0 is the first child of $id then it's not an arrow
5464 if {[lindex $children($curview,$id) 0] ne
5465 [lindex $displayorder $y0]} {
5469 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5470 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5473 # Looking at lines from this row to the previous row,
5474 # make them go straight up if they end in an arrow on
5475 # the previous row; otherwise make them go straight up
5477 if {$z < -1 || ($z < 0 && $isarrow)} {
5478 # Line currently goes left too much;
5479 # insert pads in the previous row, then optimize it
5480 set npad [expr {-1 - $z + $isarrow}]
5481 insert_pad $y0 $x0 $npad
5483 optimize_rows $y0 $x0 $row
5485 set previdlist [lindex $rowidlist $y0]
5486 set x0 [lsearch -exact $previdlist $id]
5487 set z [expr {$x0 - $col}]
5489 set pprevidlist [lindex $rowidlist $ym]
5490 set xm [lsearch -exact $pprevidlist $id]
5491 set z0 [expr {$xm - $x0}]
5493 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5494 # Line currently goes right too much;
5495 # insert pads in this line
5496 set npad [expr {$z - 1 + $isarrow}]
5497 insert_pad $row $col $npad
5498 set idlist [lindex $rowidlist $row]
5500 set z [expr {$x0 - $col}]
5503 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5504 # this line links to its first child on row $row-2
5505 set id [lindex $displayorder $ym]
5506 set xc [lsearch -exact $pprevidlist $id]
5508 set z0 [expr {$xc - $x0}]
5511 # avoid lines jigging left then immediately right
5512 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5513 insert_pad $y0 $x0 1
5515 optimize_rows $y0 $x0 $row
5516 set previdlist [lindex $rowidlist $y0]
5520 # Find the first column that doesn't have a line going right
5521 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5522 set id [lindex $idlist $col]
5523 if {$id eq {}} break
5524 set x0 [lsearch -exact $previdlist $id]
5526 # check if this is the link to the first child
5527 set kid [lindex $displayorder $y0]
5528 if {[lindex $children($curview,$id) 0] eq $kid} {
5529 # it is, work out offset to child
5530 set x0 [lsearch -exact $previdlist $kid]
5533 if {$x0 <= $col} break
5535 # Insert a pad at that column as long as it has a line and
5536 # isn't the last column
5537 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5538 set idlist [linsert $idlist $col {}]
5539 lset rowidlist $row $idlist
5547 global canvx0 linespc
5548 return [expr {$canvx0 + $col * $linespc}]
5552 global canvy0 linespc
5553 return [expr {$canvy0 + $row * $linespc}]
5556 proc linewidth {id} {
5557 global thickerline lthickness
5560 if {[info exists thickerline] && $id eq $thickerline} {
5561 set wid [expr {2 * $lthickness}]
5566 proc rowranges {id} {
5567 global curview children uparrowlen downarrowlen
5570 set kids $children($curview,$id)
5576 foreach child $kids {
5577 if {![commitinview $child $curview]} break
5578 set row [rowofcommit $child]
5579 if {![info exists prev]} {
5580 lappend ret [expr {$row + 1}]
5582 if {$row <= $prevrow} {
5583 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5585 # see if the line extends the whole way from prevrow to row
5586 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5587 [lsearch -exact [lindex $rowidlist \
5588 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5589 # it doesn't, see where it ends
5590 set r [expr {$prevrow + $downarrowlen}]
5591 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5592 while {[incr r -1] > $prevrow &&
5593 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5595 while {[incr r] <= $row &&
5596 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5600 # see where it starts up again
5601 set r [expr {$row - $uparrowlen}]
5602 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5603 while {[incr r] < $row &&
5604 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5606 while {[incr r -1] >= $prevrow &&
5607 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5613 if {$child eq $id} {
5622 proc drawlineseg {id row endrow arrowlow} {
5623 global rowidlist displayorder iddrawn linesegs
5624 global canv colormap linespc curview maxlinelen parentlist
5626 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5627 set le [expr {$row + 1}]
5630 set c [lsearch -exact [lindex $rowidlist $le] $id]
5636 set x [lindex $displayorder $le]
5641 if {[info exists iddrawn($x)] || $le == $endrow} {
5642 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5658 if {[info exists linesegs($id)]} {
5659 set lines $linesegs($id)
5661 set r0 [lindex $li 0]
5663 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5673 set li [lindex $lines [expr {$i-1}]]
5674 set r1 [lindex $li 1]
5675 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5680 set x [lindex $cols [expr {$le - $row}]]
5681 set xp [lindex $cols [expr {$le - 1 - $row}]]
5682 set dir [expr {$xp - $x}]
5684 set ith [lindex $lines $i 2]
5685 set coords [$canv coords $ith]
5686 set ah [$canv itemcget $ith -arrow]
5687 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5688 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5689 if {$x2 ne {} && $x - $x2 == $dir} {
5690 set coords [lrange $coords 0 end-2]
5693 set coords [list [xc $le $x] [yc $le]]
5696 set itl [lindex $lines [expr {$i-1}] 2]
5697 set al [$canv itemcget $itl -arrow]
5698 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5699 } elseif {$arrowlow} {
5700 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5701 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5705 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5706 for {set y $le} {[incr y -1] > $row} {} {
5708 set xp [lindex $cols [expr {$y - 1 - $row}]]
5709 set ndir [expr {$xp - $x}]
5710 if {$dir != $ndir || $xp < 0} {
5711 lappend coords [xc $y $x] [yc $y]
5717 # join parent line to first child
5718 set ch [lindex $displayorder $row]
5719 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5721 puts "oops: drawlineseg: child $ch not on row $row"
5722 } elseif {$xc != $x} {
5723 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5724 set d [expr {int(0.5 * $linespc)}]
5727 set x2 [expr {$x1 - $d}]
5729 set x2 [expr {$x1 + $d}]
5732 set y1 [expr {$y2 + $d}]
5733 lappend coords $x1 $y1 $x2 $y2
5734 } elseif {$xc < $x - 1} {
5735 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5736 } elseif {$xc > $x + 1} {
5737 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5741 lappend coords [xc $row $x] [yc $row]
5743 set xn [xc $row $xp]
5745 lappend coords $xn $yn
5749 set t [$canv create line $coords -width [linewidth $id] \
5750 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5753 set lines [linsert $lines $i [list $row $le $t]]
5755 $canv coords $ith $coords
5756 if {$arrow ne $ah} {
5757 $canv itemconf $ith -arrow $arrow
5759 lset lines $i 0 $row
5762 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5763 set ndir [expr {$xo - $xp}]
5764 set clow [$canv coords $itl]
5765 if {$dir == $ndir} {
5766 set clow [lrange $clow 2 end]
5768 set coords [concat $coords $clow]
5770 lset lines [expr {$i-1}] 1 $le
5772 # coalesce two pieces
5774 set b [lindex $lines [expr {$i-1}] 0]
5775 set e [lindex $lines $i 1]
5776 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5778 $canv coords $itl $coords
5779 if {$arrow ne $al} {
5780 $canv itemconf $itl -arrow $arrow
5784 set linesegs($id) $lines
5788 proc drawparentlinks {id row} {
5789 global rowidlist canv colormap curview parentlist
5790 global idpos linespc
5792 set rowids [lindex $rowidlist $row]
5793 set col [lsearch -exact $rowids $id]
5794 if {$col < 0} return
5795 set olds [lindex $parentlist $row]
5796 set row2 [expr {$row + 1}]
5797 set x [xc $row $col]
5800 set d [expr {int(0.5 * $linespc)}]
5801 set ymid [expr {$y + $d}]
5802 set ids [lindex $rowidlist $row2]
5803 # rmx = right-most X coord used
5806 set i [lsearch -exact $ids $p]
5808 puts "oops, parent $p of $id not in list"
5811 set x2 [xc $row2 $i]
5815 set j [lsearch -exact $rowids $p]
5817 # drawlineseg will do this one for us
5821 # should handle duplicated parents here...
5822 set coords [list $x $y]
5824 # if attaching to a vertical segment, draw a smaller
5825 # slant for visual distinctness
5828 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5830 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5832 } elseif {$i < $col && $i < $j} {
5833 # segment slants towards us already
5834 lappend coords [xc $row $j] $y
5836 if {$i < $col - 1} {
5837 lappend coords [expr {$x2 + $linespc}] $y
5838 } elseif {$i > $col + 1} {
5839 lappend coords [expr {$x2 - $linespc}] $y
5841 lappend coords $x2 $y2
5844 lappend coords $x2 $y2
5846 set t [$canv create line $coords -width [linewidth $p] \
5847 -fill $colormap($p) -tags lines.$p]
5851 if {$rmx > [lindex $idpos($id) 1]} {
5852 lset idpos($id) 1 $rmx
5857 proc drawlines {id} {
5860 $canv itemconf lines.$id -width [linewidth $id]
5863 proc drawcmittext {id row col} {
5864 global linespc canv canv2 canv3 fgcolor curview
5865 global cmitlisted commitinfo rowidlist parentlist
5866 global rowtextx idpos idtags idheads idotherrefs
5867 global linehtag linentag linedtag selectedline
5868 global canvxmax boldids boldnameids fgcolor markedid
5869 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5871 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5872 set listed $cmitlisted($curview,$id)
5873 if {$id eq $nullid} {
5875 } elseif {$id eq $nullid2} {
5877 } elseif {$id eq $mainheadid} {
5880 set ofill [lindex $circlecolors $listed]
5882 set x [xc $row $col]
5884 set orad [expr {$linespc / 3}]
5886 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5887 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5888 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5889 } elseif {$listed == 3} {
5890 # triangle pointing left for left-side commits
5891 set t [$canv create polygon \
5892 [expr {$x - $orad}] $y \
5893 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5894 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5895 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5897 # triangle pointing right for right-side commits
5898 set t [$canv create polygon \
5899 [expr {$x + $orad - 1}] $y \
5900 [expr {$x - $orad}] [expr {$y - $orad}] \
5901 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5902 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5904 set circleitem($row) $t
5906 $canv bind $t <1> {selcanvline {} %x %y}
5907 set rmx [llength [lindex $rowidlist $row]]
5908 set olds [lindex $parentlist $row]
5910 set nextids [lindex $rowidlist [expr {$row + 1}]]
5912 set i [lsearch -exact $nextids $p]
5918 set xt [xc $row $rmx]
5919 set rowtextx($row) $xt
5920 set idpos($id) [list $x $xt $y]
5921 if {[info exists idtags($id)] || [info exists idheads($id)]
5922 || [info exists idotherrefs($id)]} {
5923 set xt [drawtags $id $x $xt $y]
5925 if {[lindex $commitinfo($id) 6] > 0} {
5926 set xt [drawnotesign $xt $y]
5928 set headline [lindex $commitinfo($id) 0]
5929 set name [lindex $commitinfo($id) 1]
5930 set date [lindex $commitinfo($id) 2]
5931 set date [formatdate $date]
5934 set isbold [ishighlighted $id]
5937 set font mainfontbold
5939 lappend boldnameids $id
5940 set nfont mainfontbold
5943 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
5944 -text $headline -font $font -tags text]
5945 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
5946 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
5947 -text $name -font $nfont -tags text]
5948 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
5949 -text $date -font mainfont -tags text]
5950 if {$selectedline == $row} {
5953 if {[info exists markedid] && $markedid eq $id} {
5956 set xr [expr {$xt + [font measure $font $headline]}]
5957 if {$xr > $canvxmax} {
5963 proc drawcmitrow {row} {
5964 global displayorder rowidlist nrows_drawn
5965 global iddrawn markingmatches
5966 global commitinfo numcommits
5967 global filehighlight fhighlights findpattern nhighlights
5968 global hlview vhighlights
5969 global highlight_related rhighlights
5971 if {$row >= $numcommits} return
5973 set id [lindex $displayorder $row]
5974 if {[info exists hlview] && ![info exists vhighlights($id)]} {
5975 askvhighlight $row $id
5977 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
5978 askfilehighlight $row $id
5980 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
5981 askfindhighlight $row $id
5983 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
5984 askrelhighlight $row $id
5986 if {![info exists iddrawn($id)]} {
5987 set col [lsearch -exact [lindex $rowidlist $row] $id]
5989 puts "oops, row $row id $id not in list"
5992 if {![info exists commitinfo($id)]} {
5996 drawcmittext $id $row $col
6000 if {$markingmatches} {
6001 markrowmatches $row $id
6005 proc drawcommits {row {endrow {}}} {
6006 global numcommits iddrawn displayorder curview need_redisplay
6007 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6012 if {$endrow eq {}} {
6015 if {$endrow >= $numcommits} {
6016 set endrow [expr {$numcommits - 1}]
6019 set rl1 [expr {$row - $downarrowlen - 3}]
6023 set ro1 [expr {$row - 3}]
6027 set r2 [expr {$endrow + $uparrowlen + 3}]
6028 if {$r2 > $numcommits} {
6031 for {set r $rl1} {$r < $r2} {incr r} {
6032 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6036 set rl1 [expr {$r + 1}]
6042 optimize_rows $ro1 0 $r2
6043 if {$need_redisplay || $nrows_drawn > 2000} {
6047 # make the lines join to already-drawn rows either side
6048 set r [expr {$row - 1}]
6049 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6052 set er [expr {$endrow + 1}]
6053 if {$er >= $numcommits ||
6054 ![info exists iddrawn([lindex $displayorder $er])]} {
6057 for {} {$r <= $er} {incr r} {
6058 set id [lindex $displayorder $r]
6059 set wasdrawn [info exists iddrawn($id)]
6061 if {$r == $er} break
6062 set nextid [lindex $displayorder [expr {$r + 1}]]
6063 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6064 drawparentlinks $id $r
6066 set rowids [lindex $rowidlist $r]
6067 foreach lid $rowids {
6068 if {$lid eq {}} continue
6069 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6071 # see if this is the first child of any of its parents
6072 foreach p [lindex $parentlist $r] {
6073 if {[lsearch -exact $rowids $p] < 0} {
6074 # make this line extend up to the child
6075 set lineend($p) [drawlineseg $p $r $er 0]
6079 set lineend($lid) [drawlineseg $lid $r $er 1]
6085 proc undolayout {row} {
6086 global uparrowlen mingaplen downarrowlen
6087 global rowidlist rowisopt rowfinal need_redisplay
6089 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6093 if {[llength $rowidlist] > $r} {
6095 set rowidlist [lrange $rowidlist 0 $r]
6096 set rowfinal [lrange $rowfinal 0 $r]
6097 set rowisopt [lrange $rowisopt 0 $r]
6098 set need_redisplay 1
6103 proc drawvisible {} {
6104 global canv linespc curview vrowmod selectedline targetrow targetid
6105 global need_redisplay cscroll numcommits
6107 set fs [$canv yview]
6108 set ymax [lindex [$canv cget -scrollregion] 3]
6109 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6110 set f0 [lindex $fs 0]
6111 set f1 [lindex $fs 1]
6112 set y0 [expr {int($f0 * $ymax)}]
6113 set y1 [expr {int($f1 * $ymax)}]
6115 if {[info exists targetid]} {
6116 if {[commitinview $targetid $curview]} {
6117 set r [rowofcommit $targetid]
6118 if {$r != $targetrow} {
6119 # Fix up the scrollregion and change the scrolling position
6120 # now that our target row has moved.
6121 set diff [expr {($r - $targetrow) * $linespc}]
6124 set ymax [lindex [$canv cget -scrollregion] 3]
6127 set f0 [expr {$y0 / $ymax}]
6128 set f1 [expr {$y1 / $ymax}]
6129 allcanvs yview moveto $f0
6130 $cscroll set $f0 $f1
6131 set need_redisplay 1
6138 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6139 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6140 if {$endrow >= $vrowmod($curview)} {
6141 update_arcrows $curview
6143 if {$selectedline ne {} &&
6144 $row <= $selectedline && $selectedline <= $endrow} {
6145 set targetrow $selectedline
6146 } elseif {[info exists targetid]} {
6147 set targetrow [expr {int(($row + $endrow) / 2)}]
6149 if {[info exists targetrow]} {
6150 if {$targetrow >= $numcommits} {
6151 set targetrow [expr {$numcommits - 1}]
6153 set targetid [commitonrow $targetrow]
6155 drawcommits $row $endrow
6158 proc clear_display {} {
6159 global iddrawn linesegs need_redisplay nrows_drawn
6160 global vhighlights fhighlights nhighlights rhighlights
6161 global linehtag linentag linedtag boldids boldnameids
6164 catch {unset iddrawn}
6165 catch {unset linesegs}
6166 catch {unset linehtag}
6167 catch {unset linentag}
6168 catch {unset linedtag}
6171 catch {unset vhighlights}
6172 catch {unset fhighlights}
6173 catch {unset nhighlights}
6174 catch {unset rhighlights}
6175 set need_redisplay 0
6179 proc findcrossings {id} {
6180 global rowidlist parentlist numcommits displayorder
6184 foreach {s e} [rowranges $id] {
6185 if {$e >= $numcommits} {
6186 set e [expr {$numcommits - 1}]
6188 if {$e <= $s} continue
6189 for {set row $e} {[incr row -1] >= $s} {} {
6190 set x [lsearch -exact [lindex $rowidlist $row] $id]
6192 set olds [lindex $parentlist $row]
6193 set kid [lindex $displayorder $row]
6194 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6195 if {$kidx < 0} continue
6196 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6198 set px [lsearch -exact $nextrow $p]
6199 if {$px < 0} continue
6200 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6201 if {[lsearch -exact $ccross $p] >= 0} continue
6202 if {$x == $px + ($kidx < $px? -1: 1)} {
6204 } elseif {[lsearch -exact $cross $p] < 0} {
6211 return [concat $ccross {{}} $cross]
6214 proc assigncolor {id} {
6215 global colormap colors nextcolor
6216 global parents children children curview
6218 if {[info exists colormap($id)]} return
6219 set ncolors [llength $colors]
6220 if {[info exists children($curview,$id)]} {
6221 set kids $children($curview,$id)
6225 if {[llength $kids] == 1} {
6226 set child [lindex $kids 0]
6227 if {[info exists colormap($child)]
6228 && [llength $parents($curview,$child)] == 1} {
6229 set colormap($id) $colormap($child)
6235 foreach x [findcrossings $id] {
6237 # delimiter between corner crossings and other crossings
6238 if {[llength $badcolors] >= $ncolors - 1} break
6239 set origbad $badcolors
6241 if {[info exists colormap($x)]
6242 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6243 lappend badcolors $colormap($x)
6246 if {[llength $badcolors] >= $ncolors} {
6247 set badcolors $origbad
6249 set origbad $badcolors
6250 if {[llength $badcolors] < $ncolors - 1} {
6251 foreach child $kids {
6252 if {[info exists colormap($child)]
6253 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6254 lappend badcolors $colormap($child)
6256 foreach p $parents($curview,$child) {
6257 if {[info exists colormap($p)]
6258 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6259 lappend badcolors $colormap($p)
6263 if {[llength $badcolors] >= $ncolors} {
6264 set badcolors $origbad
6267 for {set i 0} {$i <= $ncolors} {incr i} {
6268 set c [lindex $colors $nextcolor]
6269 if {[incr nextcolor] >= $ncolors} {
6272 if {[lsearch -exact $badcolors $c]} break
6274 set colormap($id) $c
6277 proc bindline {t id} {
6280 $canv bind $t <Enter> "lineenter %x %y $id"
6281 $canv bind $t <Motion> "linemotion %x %y $id"
6282 $canv bind $t <Leave> "lineleave $id"
6283 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6286 proc drawtags {id x xt y1} {
6287 global idtags idheads idotherrefs mainhead
6288 global linespc lthickness
6289 global canv rowtextx curview fgcolor bgcolor ctxbut
6294 if {[info exists idtags($id)]} {
6295 set marks $idtags($id)
6296 set ntags [llength $marks]
6298 if {[info exists idheads($id)]} {
6299 set marks [concat $marks $idheads($id)]
6300 set nheads [llength $idheads($id)]
6302 if {[info exists idotherrefs($id)]} {
6303 set marks [concat $marks $idotherrefs($id)]
6309 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6310 set yt [expr {$y1 - 0.5 * $linespc}]
6311 set yb [expr {$yt + $linespc - 1}]
6315 foreach tag $marks {
6317 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6318 set wid [font measure mainfontbold $tag]
6320 set wid [font measure mainfont $tag]
6324 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6326 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6327 -width $lthickness -fill black -tags tag.$id]
6329 foreach tag $marks x $xvals wid $wvals {
6330 set tag_quoted [string map {% %%} $tag]
6331 set xl [expr {$x + $delta}]
6332 set xr [expr {$x + $delta + $wid + $lthickness}]
6334 if {[incr ntags -1] >= 0} {
6336 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6337 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6338 -width 1 -outline black -fill yellow -tags tag.$id]
6339 $canv bind $t <1> [list showtag $tag_quoted 1]
6340 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6342 # draw a head or other ref
6343 if {[incr nheads -1] >= 0} {
6345 if {$tag eq $mainhead} {
6346 set font mainfontbold
6351 set xl [expr {$xl - $delta/2}]
6352 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6353 -width 1 -outline black -fill $col -tags tag.$id
6354 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6355 set rwid [font measure mainfont $remoteprefix]
6356 set xi [expr {$x + 1}]
6357 set yti [expr {$yt + 1}]
6358 set xri [expr {$x + $rwid}]
6359 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6360 -width 0 -fill "#ffddaa" -tags tag.$id
6363 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
6364 -font $font -tags [list tag.$id text]]
6366 $canv bind $t <1> [list showtag $tag_quoted 1]
6367 } elseif {$nheads >= 0} {
6368 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6374 proc drawnotesign {xt y} {
6375 global linespc canv fgcolor
6377 set orad [expr {$linespc / 3}]
6378 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6379 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6380 -fill yellow -outline $fgcolor -width 1 -tags circle]
6381 set xt [expr {$xt + $orad * 3}]
6385 proc xcoord {i level ln} {
6386 global canvx0 xspc1 xspc2
6388 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6389 if {$i > 0 && $i == $level} {
6390 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6391 } elseif {$i > $level} {
6392 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6397 proc show_status {msg} {
6401 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6402 -tags text -fill $fgcolor
6405 # Don't change the text pane cursor if it is currently the hand cursor,
6406 # showing that we are over a sha1 ID link.
6407 proc settextcursor {c} {
6408 global ctext curtextcursor
6410 if {[$ctext cget -cursor] == $curtextcursor} {
6411 $ctext config -cursor $c
6413 set curtextcursor $c
6416 proc nowbusy {what {name {}}} {
6417 global isbusy busyname statusw
6419 if {[array names isbusy] eq {}} {
6420 . config -cursor watch
6424 set busyname($what) $name
6426 $statusw conf -text $name
6430 proc notbusy {what} {
6431 global isbusy maincursor textcursor busyname statusw
6435 if {$busyname($what) ne {} &&
6436 [$statusw cget -text] eq $busyname($what)} {
6437 $statusw conf -text {}
6440 if {[array names isbusy] eq {}} {
6441 . config -cursor $maincursor
6442 settextcursor $textcursor
6446 proc findmatches {f} {
6447 global findtype findstring
6448 if {$findtype == [mc "Regexp"]} {
6449 set matches [regexp -indices -all -inline $findstring $f]
6452 if {$findtype == [mc "IgnCase"]} {
6453 set f [string tolower $f]
6454 set fs [string tolower $fs]
6458 set l [string length $fs]
6459 while {[set j [string first $fs $f $i]] >= 0} {
6460 lappend matches [list $j [expr {$j+$l-1}]]
6461 set i [expr {$j + $l}]
6467 proc dofind {{dirn 1} {wrap 1}} {
6468 global findstring findstartline findcurline selectedline numcommits
6469 global gdttype filehighlight fh_serial find_dirn findallowwrap
6471 if {[info exists find_dirn]} {
6472 if {$find_dirn == $dirn} return
6476 if {$findstring eq {} || $numcommits == 0} return
6477 if {$selectedline eq {}} {
6478 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6480 set findstartline $selectedline
6482 set findcurline $findstartline
6483 nowbusy finding [mc "Searching"]
6484 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6485 after cancel do_file_hl $fh_serial
6486 do_file_hl $fh_serial
6489 set findallowwrap $wrap
6493 proc stopfinding {} {
6494 global find_dirn findcurline fprogcoord
6496 if {[info exists find_dirn]} {
6507 global commitdata commitinfo numcommits findpattern findloc
6508 global findstartline findcurline findallowwrap
6509 global find_dirn gdttype fhighlights fprogcoord
6510 global curview varcorder vrownum varccommits vrowmod
6512 if {![info exists find_dirn]} {
6515 set fldtypes [list [mc "Headline"] [mc "Author"] [mc "Date"] [mc "Committer"] [mc "CDate"] [mc "Comments"]]
6518 if {$find_dirn > 0} {
6520 if {$l >= $numcommits} {
6523 if {$l <= $findstartline} {
6524 set lim [expr {$findstartline + 1}]
6527 set moretodo $findallowwrap
6534 if {$l >= $findstartline} {
6535 set lim [expr {$findstartline - 1}]
6538 set moretodo $findallowwrap
6541 set n [expr {($lim - $l) * $find_dirn}]
6546 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6547 update_arcrows $curview
6551 set ai [bsearch $vrownum($curview) $l]
6552 set a [lindex $varcorder($curview) $ai]
6553 set arow [lindex $vrownum($curview) $ai]
6554 set ids [lindex $varccommits($curview,$a)]
6555 set arowend [expr {$arow + [llength $ids]}]
6556 if {$gdttype eq [mc "containing:"]} {
6557 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6558 if {$l < $arow || $l >= $arowend} {
6560 set a [lindex $varcorder($curview) $ai]
6561 set arow [lindex $vrownum($curview) $ai]
6562 set ids [lindex $varccommits($curview,$a)]
6563 set arowend [expr {$arow + [llength $ids]}]
6565 set id [lindex $ids [expr {$l - $arow}]]
6566 # shouldn't happen unless git log doesn't give all the commits...
6567 if {![info exists commitdata($id)] ||
6568 ![doesmatch $commitdata($id)]} {
6571 if {![info exists commitinfo($id)]} {
6574 set info $commitinfo($id)
6575 foreach f $info ty $fldtypes {
6576 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6585 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6586 if {$l < $arow || $l >= $arowend} {
6588 set a [lindex $varcorder($curview) $ai]
6589 set arow [lindex $vrownum($curview) $ai]
6590 set ids [lindex $varccommits($curview,$a)]
6591 set arowend [expr {$arow + [llength $ids]}]
6593 set id [lindex $ids [expr {$l - $arow}]]
6594 if {![info exists fhighlights($id)]} {
6595 # this sets fhighlights($id) to -1
6596 askfilehighlight $l $id
6598 if {$fhighlights($id) > 0} {
6602 if {$fhighlights($id) < 0} {
6605 set findcurline [expr {$l - $find_dirn}]
6610 if {$found || ($domore && !$moretodo)} {
6626 set findcurline [expr {$l - $find_dirn}]
6628 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6632 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6637 proc findselectline {l} {
6638 global findloc commentend ctext findcurline markingmatches gdttype
6640 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6643 if {$markingmatches &&
6644 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6645 # highlight the matches in the comments
6646 set f [$ctext get 1.0 $commentend]
6647 set matches [findmatches $f]
6648 foreach match $matches {
6649 set start [lindex $match 0]
6650 set end [expr {[lindex $match 1] + 1}]
6651 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6657 # mark the bits of a headline or author that match a find string
6658 proc markmatches {canv l str tag matches font row} {
6661 set bbox [$canv bbox $tag]
6662 set x0 [lindex $bbox 0]
6663 set y0 [lindex $bbox 1]
6664 set y1 [lindex $bbox 3]
6665 foreach match $matches {
6666 set start [lindex $match 0]
6667 set end [lindex $match 1]
6668 if {$start > $end} continue
6669 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6670 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6671 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6672 [expr {$x0+$xlen+2}] $y1 \
6673 -outline {} -tags [list match$l matches] -fill yellow]
6675 if {$row == $selectedline} {
6676 $canv raise $t secsel
6681 proc unmarkmatches {} {
6682 global markingmatches
6684 allcanvs delete matches
6685 set markingmatches 0
6689 proc selcanvline {w x y} {
6690 global canv canvy0 ctext linespc
6692 set ymax [lindex [$canv cget -scrollregion] 3]
6693 if {$ymax == {}} return
6694 set yfrac [lindex [$canv yview] 0]
6695 set y [expr {$y + $yfrac * $ymax}]
6696 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6701 set xmax [lindex [$canv cget -scrollregion] 2]
6702 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6703 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6709 proc commit_descriptor {p} {
6711 if {![info exists commitinfo($p)]} {
6715 if {[llength $commitinfo($p)] > 1} {
6716 set l [lindex $commitinfo($p) 0]
6721 # append some text to the ctext widget, and make any SHA1 ID
6722 # that we know about be a clickable link.
6723 proc appendwithlinks {text tags} {
6724 global ctext linknum curview
6726 set start [$ctext index "end - 1c"]
6727 $ctext insert end $text $tags
6728 set links [regexp -indices -all -inline {\m[0-9a-f]{6,40}\M} $text]
6732 set linkid [string range $text $s $e]
6734 $ctext tag delete link$linknum
6735 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6736 setlink $linkid link$linknum
6741 proc setlink {id lk} {
6742 global curview ctext pendinglinks
6745 if {[string length $id] < 40} {
6746 set matches [longid $id]
6747 if {[llength $matches] > 0} {
6748 if {[llength $matches] > 1} return
6750 set id [lindex $matches 0]
6753 set known [commitinview $id $curview]
6756 $ctext tag conf $lk -foreground blue -underline 1
6757 $ctext tag bind $lk <1> [list selbyid $id]
6758 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6759 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6761 lappend pendinglinks($id) $lk
6762 interestedin $id {makelink %P}
6766 proc appendshortlink {id {pre {}} {post {}}} {
6767 global ctext linknum
6769 $ctext insert end $pre
6770 $ctext tag delete link$linknum
6771 $ctext insert end [string range $id 0 7] link$linknum
6772 $ctext insert end $post
6773 setlink $id link$linknum
6777 proc makelink {id} {
6780 if {![info exists pendinglinks($id)]} return
6781 foreach lk $pendinglinks($id) {
6784 unset pendinglinks($id)
6787 proc linkcursor {w inc} {
6788 global linkentercount curtextcursor
6790 if {[incr linkentercount $inc] > 0} {
6791 $w configure -cursor hand2
6793 $w configure -cursor $curtextcursor
6794 if {$linkentercount < 0} {
6795 set linkentercount 0
6800 proc viewnextline {dir} {
6804 set ymax [lindex [$canv cget -scrollregion] 3]
6805 set wnow [$canv yview]
6806 set wtop [expr {[lindex $wnow 0] * $ymax}]
6807 set newtop [expr {$wtop + $dir * $linespc}]
6810 } elseif {$newtop > $ymax} {
6813 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6816 # add a list of tag or branch names at position pos
6817 # returns the number of names inserted
6818 proc appendrefs {pos ids var} {
6819 global ctext linknum curview $var maxrefs
6821 if {[catch {$ctext index $pos}]} {
6824 $ctext conf -state normal
6825 $ctext delete $pos "$pos lineend"
6828 foreach tag [set $var\($id\)] {
6829 lappend tags [list $tag $id]
6832 if {[llength $tags] > $maxrefs} {
6833 $ctext insert $pos "[mc "many"] ([llength $tags])"
6835 set tags [lsort -index 0 -decreasing $tags]
6838 set id [lindex $ti 1]
6841 $ctext tag delete $lk
6842 $ctext insert $pos $sep
6843 $ctext insert $pos [lindex $ti 0] $lk
6848 $ctext conf -state disabled
6849 return [llength $tags]
6852 # called when we have finished computing the nearby tags
6853 proc dispneartags {delay} {
6854 global selectedline currentid showneartags tagphase
6856 if {$selectedline eq {} || !$showneartags} return
6857 after cancel dispnexttag
6859 after 200 dispnexttag
6862 after idle dispnexttag
6867 proc dispnexttag {} {
6868 global selectedline currentid showneartags tagphase ctext
6870 if {$selectedline eq {} || !$showneartags} return
6871 switch -- $tagphase {
6873 set dtags [desctags $currentid]
6875 appendrefs precedes $dtags idtags
6879 set atags [anctags $currentid]
6881 appendrefs follows $atags idtags
6885 set dheads [descheads $currentid]
6886 if {$dheads ne {}} {
6887 if {[appendrefs branch $dheads idheads] > 1
6888 && [$ctext get "branch -3c"] eq "h"} {
6889 # turn "Branch" into "Branches"
6890 $ctext conf -state normal
6891 $ctext insert "branch -2c" "es"
6892 $ctext conf -state disabled
6897 if {[incr tagphase] <= 2} {
6898 after idle dispnexttag
6902 proc make_secsel {id} {
6903 global linehtag linentag linedtag canv canv2 canv3
6905 if {![info exists linehtag($id)]} return
6907 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
6908 -tags secsel -fill [$canv cget -selectbackground]]
6910 $canv2 delete secsel
6911 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
6912 -tags secsel -fill [$canv2 cget -selectbackground]]
6914 $canv3 delete secsel
6915 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
6916 -tags secsel -fill [$canv3 cget -selectbackground]]
6920 proc make_idmark {id} {
6921 global linehtag canv fgcolor
6923 if {![info exists linehtag($id)]} return
6925 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
6926 -tags markid -outline $fgcolor]
6930 proc selectline {l isnew {desired_loc {}}} {
6931 global canv ctext commitinfo selectedline
6932 global canvy0 linespc parents children curview
6933 global currentid sha1entry
6934 global commentend idtags linknum
6935 global mergemax numcommits pending_select
6936 global cmitmode showneartags allcommits
6937 global targetrow targetid lastscrollrows
6938 global autoselect autosellen jump_to_here
6940 catch {unset pending_select}
6945 if {$l < 0 || $l >= $numcommits} return
6946 set id [commitonrow $l]
6951 if {$lastscrollrows < $numcommits} {
6955 set y [expr {$canvy0 + $l * $linespc}]
6956 set ymax [lindex [$canv cget -scrollregion] 3]
6957 set ytop [expr {$y - $linespc - 1}]
6958 set ybot [expr {$y + $linespc + 1}]
6959 set wnow [$canv yview]
6960 set wtop [expr {[lindex $wnow 0] * $ymax}]
6961 set wbot [expr {[lindex $wnow 1] * $ymax}]
6962 set wh [expr {$wbot - $wtop}]
6964 if {$ytop < $wtop} {
6965 if {$ybot < $wtop} {
6966 set newtop [expr {$y - $wh / 2.0}]
6969 if {$newtop > $wtop - $linespc} {
6970 set newtop [expr {$wtop - $linespc}]
6973 } elseif {$ybot > $wbot} {
6974 if {$ytop > $wbot} {
6975 set newtop [expr {$y - $wh / 2.0}]
6977 set newtop [expr {$ybot - $wh}]
6978 if {$newtop < $wtop + $linespc} {
6979 set newtop [expr {$wtop + $linespc}]
6983 if {$newtop != $wtop} {
6987 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6994 addtohistory [list selbyid $id 0] savecmitpos
6997 $sha1entry delete 0 end
6998 $sha1entry insert 0 $id
7000 $sha1entry selection range 0 $autosellen
7004 $ctext conf -state normal
7007 if {![info exists commitinfo($id)]} {
7010 set info $commitinfo($id)
7011 set date [formatdate [lindex $info 2]]
7012 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7013 set date [formatdate [lindex $info 4]]
7014 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7015 if {[info exists idtags($id)]} {
7016 $ctext insert end [mc "Tags:"]
7017 foreach tag $idtags($id) {
7018 $ctext insert end " $tag"
7020 $ctext insert end "\n"
7024 set olds $parents($curview,$id)
7025 if {[llength $olds] > 1} {
7028 if {$np >= $mergemax} {
7033 $ctext insert end "[mc "Parent"]: " $tag
7034 appendwithlinks [commit_descriptor $p] {}
7039 append headers "[mc "Parent"]: [commit_descriptor $p]"
7043 foreach c $children($curview,$id) {
7044 append headers "[mc "Child"]: [commit_descriptor $c]"
7047 # make anything that looks like a SHA1 ID be a clickable link
7048 appendwithlinks $headers {}
7049 if {$showneartags} {
7050 if {![info exists allcommits]} {
7053 $ctext insert end "[mc "Branch"]: "
7054 $ctext mark set branch "end -1c"
7055 $ctext mark gravity branch left
7056 $ctext insert end "\n[mc "Follows"]: "
7057 $ctext mark set follows "end -1c"
7058 $ctext mark gravity follows left
7059 $ctext insert end "\n[mc "Precedes"]: "
7060 $ctext mark set precedes "end -1c"
7061 $ctext mark gravity precedes left
7062 $ctext insert end "\n"
7065 $ctext insert end "\n"
7066 set comment [lindex $info 5]
7067 if {[string first "\r" $comment] >= 0} {
7068 set comment [string map {"\r" "\n "} $comment]
7070 appendwithlinks $comment {comment}
7072 $ctext tag remove found 1.0 end
7073 $ctext conf -state disabled
7074 set commentend [$ctext index "end - 1c"]
7076 set jump_to_here $desired_loc
7077 init_flist [mc "Comments"]
7078 if {$cmitmode eq "tree"} {
7080 } elseif {[llength $olds] <= 1} {
7087 proc selfirstline {} {
7092 proc sellastline {} {
7095 set l [expr {$numcommits - 1}]
7099 proc selnextline {dir} {
7102 if {$selectedline eq {}} return
7103 set l [expr {$selectedline + $dir}]
7108 proc selnextpage {dir} {
7109 global canv linespc selectedline numcommits
7111 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7115 allcanvs yview scroll [expr {$dir * $lpp}] units
7117 if {$selectedline eq {}} return
7118 set l [expr {$selectedline + $dir * $lpp}]
7121 } elseif {$l >= $numcommits} {
7122 set l [expr $numcommits - 1]
7128 proc unselectline {} {
7129 global selectedline currentid
7132 catch {unset currentid}
7133 allcanvs delete secsel
7137 proc reselectline {} {
7140 if {$selectedline ne {}} {
7141 selectline $selectedline 0
7145 proc addtohistory {cmd {saveproc {}}} {
7146 global history historyindex curview
7150 set elt [list $curview $cmd $saveproc {}]
7151 if {$historyindex > 0
7152 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7156 if {$historyindex < [llength $history]} {
7157 set history [lreplace $history $historyindex end $elt]
7159 lappend history $elt
7162 if {$historyindex > 1} {
7163 .tf.bar.leftbut conf -state normal
7165 .tf.bar.leftbut conf -state disabled
7167 .tf.bar.rightbut conf -state disabled
7170 # save the scrolling position of the diff display pane
7171 proc save_position {} {
7172 global historyindex history
7174 if {$historyindex < 1} return
7175 set hi [expr {$historyindex - 1}]
7176 set fn [lindex $history $hi 2]
7178 lset history $hi 3 [eval $fn]
7182 proc unset_posvars {} {
7185 if {[info exists last_posvars]} {
7186 foreach {var val} $last_posvars {
7195 global curview last_posvars
7197 set view [lindex $elt 0]
7198 set cmd [lindex $elt 1]
7199 set pv [lindex $elt 3]
7200 if {$curview != $view} {
7204 foreach {var val} $pv {
7208 set last_posvars $pv
7213 global history historyindex
7216 if {$historyindex > 1} {
7218 incr historyindex -1
7219 godo [lindex $history [expr {$historyindex - 1}]]
7220 .tf.bar.rightbut conf -state normal
7222 if {$historyindex <= 1} {
7223 .tf.bar.leftbut conf -state disabled
7228 global history historyindex
7231 if {$historyindex < [llength $history]} {
7233 set cmd [lindex $history $historyindex]
7236 .tf.bar.leftbut conf -state normal
7238 if {$historyindex >= [llength $history]} {
7239 .tf.bar.rightbut conf -state disabled
7244 global treefilelist treeidlist diffids diffmergeid treepending
7245 global nullid nullid2
7248 catch {unset diffmergeid}
7249 if {![info exists treefilelist($id)]} {
7250 if {![info exists treepending]} {
7251 if {$id eq $nullid} {
7252 set cmd [list | git ls-files]
7253 } elseif {$id eq $nullid2} {
7254 set cmd [list | git ls-files --stage -t]
7256 set cmd [list | git ls-tree -r $id]
7258 if {[catch {set gtf [open $cmd r]}]} {
7262 set treefilelist($id) {}
7263 set treeidlist($id) {}
7264 fconfigure $gtf -blocking 0 -encoding binary
7265 filerun $gtf [list gettreeline $gtf $id]
7272 proc gettreeline {gtf id} {
7273 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7276 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7277 if {$diffids eq $nullid} {
7280 set i [string first "\t" $line]
7281 if {$i < 0} continue
7282 set fname [string range $line [expr {$i+1}] end]
7283 set line [string range $line 0 [expr {$i-1}]]
7284 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7285 set sha1 [lindex $line 2]
7286 lappend treeidlist($id) $sha1
7288 if {[string index $fname 0] eq "\""} {
7289 set fname [lindex $fname 0]
7291 set fname [encoding convertfrom $fname]
7292 lappend treefilelist($id) $fname
7295 return [expr {$nl >= 1000? 2: 1}]
7299 if {$cmitmode ne "tree"} {
7300 if {![info exists diffmergeid]} {
7301 gettreediffs $diffids
7303 } elseif {$id ne $diffids} {
7312 global treefilelist treeidlist diffids nullid nullid2
7313 global ctext_file_names ctext_file_lines
7314 global ctext commentend
7316 set i [lsearch -exact $treefilelist($diffids) $f]
7318 puts "oops, $f not in list for id $diffids"
7321 if {$diffids eq $nullid} {
7322 if {[catch {set bf [open $f r]} err]} {
7323 puts "oops, can't read $f: $err"
7327 set blob [lindex $treeidlist($diffids) $i]
7328 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7329 puts "oops, error reading blob $blob: $err"
7333 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7334 filerun $bf [list getblobline $bf $diffids]
7335 $ctext config -state normal
7336 clear_ctext $commentend
7337 lappend ctext_file_names $f
7338 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7339 $ctext insert end "\n"
7340 $ctext insert end "$f\n" filesep
7341 $ctext config -state disabled
7342 $ctext yview $commentend
7346 proc getblobline {bf id} {
7347 global diffids cmitmode ctext
7349 if {$id ne $diffids || $cmitmode ne "tree"} {
7353 $ctext config -state normal
7355 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7356 $ctext insert end "$line\n"
7359 global jump_to_here ctext_file_names commentend
7361 # delete last newline
7362 $ctext delete "end - 2c" "end - 1c"
7364 if {$jump_to_here ne {} &&
7365 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7366 set lnum [expr {[lindex $jump_to_here 1] +
7367 [lindex [split $commentend .] 0]}]
7368 mark_ctext_line $lnum
7370 $ctext config -state disabled
7373 $ctext config -state disabled
7374 return [expr {$nl >= 1000? 2: 1}]
7377 proc mark_ctext_line {lnum} {
7378 global ctext markbgcolor
7380 $ctext tag delete omark
7381 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7382 $ctext tag conf omark -background $markbgcolor
7386 proc mergediff {id} {
7388 global diffids treediffs
7389 global parents curview
7393 set treediffs($id) {}
7394 set np [llength $parents($curview,$id)]
7399 proc startdiff {ids} {
7400 global treediffs diffids treepending diffmergeid nullid nullid2
7404 catch {unset diffmergeid}
7405 if {![info exists treediffs($ids)] ||
7406 [lsearch -exact $ids $nullid] >= 0 ||
7407 [lsearch -exact $ids $nullid2] >= 0} {
7408 if {![info exists treepending]} {
7416 # If the filename (name) is under any of the passed filter paths
7417 # then return true to include the file in the listing.
7418 proc path_filter {filter name} {
7419 set worktree [gitworktree]
7421 set fq_p [file normalize $p]
7422 set fq_n [file normalize [file join $worktree $name]]
7423 if {[string match [file normalize $fq_p]* $fq_n]} {
7430 proc addtocflist {ids} {
7433 add_flist $treediffs($ids)
7437 proc diffcmd {ids flags} {
7438 global nullid nullid2
7440 set i [lsearch -exact $ids $nullid]
7441 set j [lsearch -exact $ids $nullid2]
7443 if {[llength $ids] > 1 && $j < 0} {
7444 # comparing working directory with some specific revision
7445 set cmd [concat | git diff-index $flags]
7447 lappend cmd -R [lindex $ids 1]
7449 lappend cmd [lindex $ids 0]
7452 # comparing working directory with index
7453 set cmd [concat | git diff-files $flags]
7458 } elseif {$j >= 0} {
7459 set cmd [concat | git diff-index --cached $flags]
7460 if {[llength $ids] > 1} {
7461 # comparing index with specific revision
7463 lappend cmd -R [lindex $ids 1]
7465 lappend cmd [lindex $ids 0]
7468 # comparing index with HEAD
7472 set cmd [concat | git diff-tree -r $flags $ids]
7477 proc gettreediffs {ids} {
7478 global treediff treepending
7480 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
7482 set treepending $ids
7484 fconfigure $gdtf -blocking 0 -encoding binary
7485 filerun $gdtf [list gettreediffline $gdtf $ids]
7488 proc gettreediffline {gdtf ids} {
7489 global treediff treediffs treepending diffids diffmergeid
7490 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7495 if {$perfile_attrs} {
7496 # cache_gitattr is slow, and even slower on win32 where we
7497 # have to invoke it for only about 30 paths at a time
7499 if {[tk windowingsystem] == "win32"} {
7503 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7504 set i [string first "\t" $line]
7506 set file [string range $line [expr {$i+1}] end]
7507 if {[string index $file 0] eq "\""} {
7508 set file [lindex $file 0]
7510 set file [encoding convertfrom $file]
7511 if {$file ne [lindex $treediff end]} {
7512 lappend treediff $file
7513 lappend sublist $file
7517 if {$perfile_attrs} {
7518 cache_gitattr encoding $sublist
7521 return [expr {$nr >= $max? 2: 1}]
7524 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7526 foreach f $treediff {
7527 if {[path_filter $vfilelimit($curview) $f]} {
7531 set treediffs($ids) $flist
7533 set treediffs($ids) $treediff
7536 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7538 } elseif {$ids != $diffids} {
7539 if {![info exists diffmergeid]} {
7540 gettreediffs $diffids
7548 # empty string or positive integer
7549 proc diffcontextvalidate {v} {
7550 return [regexp {^(|[1-9][0-9]*)$} $v]
7553 proc diffcontextchange {n1 n2 op} {
7554 global diffcontextstring diffcontext
7556 if {[string is integer -strict $diffcontextstring]} {
7557 if {$diffcontextstring >= 0} {
7558 set diffcontext $diffcontextstring
7564 proc changeignorespace {} {
7568 proc changeworddiff {name ix op} {
7572 proc getblobdiffs {ids} {
7573 global blobdifffd diffids env
7574 global diffinhdr treediffs
7578 global limitdiffs vfilelimit curview
7579 global diffencoding targetline diffnparents
7580 global git_version currdiffsubmod
7583 if {[package vcompare $git_version "1.6.1"] >= 0} {
7584 set textconv "--textconv"
7587 if {[package vcompare $git_version "1.6.6"] >= 0} {
7588 set submodule "--submodule"
7590 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7594 if {$worddiff ne [mc "Line diff"]} {
7595 append cmd " --word-diff=porcelain"
7597 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7598 set cmd [concat $cmd -- $vfilelimit($curview)]
7600 if {[catch {set bdf [open $cmd r]} err]} {
7601 error_popup [mc "Error getting diffs: %s" $err]
7607 set diffencoding [get_path_encoding {}]
7608 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7609 set blobdifffd($ids) $bdf
7610 set currdiffsubmod ""
7611 filerun $bdf [list getblobdiffline $bdf $diffids]
7614 proc savecmitpos {} {
7615 global ctext cmitmode
7617 if {$cmitmode eq "tree"} {
7620 return [list target_scrollpos [$ctext index @0,0]]
7623 proc savectextpos {} {
7626 return [list target_scrollpos [$ctext index @0,0]]
7629 proc maybe_scroll_ctext {ateof} {
7630 global ctext target_scrollpos
7632 if {![info exists target_scrollpos]} return
7634 set nlines [expr {[winfo height $ctext]
7635 / [font metrics textfont -linespace]}]
7636 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7638 $ctext yview $target_scrollpos
7639 unset target_scrollpos
7642 proc setinlist {var i val} {
7645 while {[llength [set $var]] < $i} {
7648 if {[llength [set $var]] == $i} {
7655 proc makediffhdr {fname ids} {
7656 global ctext curdiffstart treediffs diffencoding
7657 global ctext_file_names jump_to_here targetline diffline
7659 set fname [encoding convertfrom $fname]
7660 set diffencoding [get_path_encoding $fname]
7661 set i [lsearch -exact $treediffs($ids) $fname]
7663 setinlist difffilestart $i $curdiffstart
7665 lset ctext_file_names end $fname
7666 set l [expr {(78 - [string length $fname]) / 2}]
7667 set pad [string range "----------------------------------------" 1 $l]
7668 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7670 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7671 set targetline [lindex $jump_to_here 1]
7676 proc getblobdiffline {bdf ids} {
7677 global diffids blobdifffd ctext curdiffstart
7678 global diffnexthead diffnextnote difffilestart
7679 global ctext_file_names ctext_file_lines
7680 global diffinhdr treediffs mergemax diffnparents
7681 global diffencoding jump_to_here targetline diffline currdiffsubmod
7685 $ctext conf -state normal
7686 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7687 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7691 if {![string compare -length 5 "diff " $line]} {
7692 if {![regexp {^diff (--cc|--git) } $line m type]} {
7693 set line [encoding convertfrom $line]
7694 $ctext insert end "$line\n" hunksep
7697 # start of a new file
7699 $ctext insert end "\n"
7700 set curdiffstart [$ctext index "end - 1c"]
7701 lappend ctext_file_names ""
7702 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7703 $ctext insert end "\n" filesep
7705 if {$type eq "--cc"} {
7706 # start of a new file in a merge diff
7707 set fname [string range $line 10 end]
7708 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7709 lappend treediffs($ids) $fname
7710 add_flist [list $fname]
7714 set line [string range $line 11 end]
7715 # If the name hasn't changed the length will be odd,
7716 # the middle char will be a space, and the two bits either
7717 # side will be a/name and b/name, or "a/name" and "b/name".
7718 # If the name has changed we'll get "rename from" and
7719 # "rename to" or "copy from" and "copy to" lines following
7720 # this, and we'll use them to get the filenames.
7721 # This complexity is necessary because spaces in the
7722 # filename(s) don't get escaped.
7723 set l [string length $line]
7724 set i [expr {$l / 2}]
7725 if {!(($l & 1) && [string index $line $i] eq " " &&
7726 [string range $line 2 [expr {$i - 1}]] eq \
7727 [string range $line [expr {$i + 3}] end])} {
7730 # unescape if quoted and chop off the a/ from the front
7731 if {[string index $line 0] eq "\""} {
7732 set fname [string range [lindex $line 0] 2 end]
7734 set fname [string range $line 2 [expr {$i - 1}]]
7737 makediffhdr $fname $ids
7739 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7740 set fname [encoding convertfrom [string range $line 16 end]]
7741 $ctext insert end "\n"
7742 set curdiffstart [$ctext index "end - 1c"]
7743 lappend ctext_file_names $fname
7744 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7745 $ctext insert end "$line\n" filesep
7746 set i [lsearch -exact $treediffs($ids) $fname]
7748 setinlist difffilestart $i $curdiffstart
7751 } elseif {![string compare -length 2 "@@" $line]} {
7752 regexp {^@@+} $line ats
7753 set line [encoding convertfrom $diffencoding $line]
7754 $ctext insert end "$line\n" hunksep
7755 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7758 set diffnparents [expr {[string length $ats] - 1}]
7761 } elseif {![string compare -length 10 "Submodule " $line]} {
7762 # start of a new submodule
7763 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7764 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7766 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7768 if {$currdiffsubmod != $fname} {
7769 $ctext insert end "\n"; # Add newline after commit message
7771 set curdiffstart [$ctext index "end - 1c"]
7772 lappend ctext_file_names ""
7773 if {$currdiffsubmod != $fname} {
7774 lappend ctext_file_lines $fname
7775 makediffhdr $fname $ids
7776 set currdiffsubmod $fname
7777 $ctext insert end "\n$line\n" filesep
7779 $ctext insert end "$line\n" filesep
7781 } elseif {![string compare -length 3 " >" $line]} {
7782 set $currdiffsubmod ""
7783 set line [encoding convertfrom $diffencoding $line]
7784 $ctext insert end "$line\n" dresult
7785 } elseif {![string compare -length 3 " <" $line]} {
7786 set $currdiffsubmod ""
7787 set line [encoding convertfrom $diffencoding $line]
7788 $ctext insert end "$line\n" d0
7789 } elseif {$diffinhdr} {
7790 if {![string compare -length 12 "rename from " $line]} {
7791 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7792 if {[string index $fname 0] eq "\""} {
7793 set fname [lindex $fname 0]
7795 set fname [encoding convertfrom $fname]
7796 set i [lsearch -exact $treediffs($ids) $fname]
7798 setinlist difffilestart $i $curdiffstart
7800 } elseif {![string compare -length 10 $line "rename to "] ||
7801 ![string compare -length 8 $line "copy to "]} {
7802 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7803 if {[string index $fname 0] eq "\""} {
7804 set fname [lindex $fname 0]
7806 makediffhdr $fname $ids
7807 } elseif {[string compare -length 3 $line "---"] == 0} {
7810 } elseif {[string compare -length 3 $line "+++"] == 0} {
7814 $ctext insert end "$line\n" filesep
7817 set line [string map {\x1A ^Z} \
7818 [encoding convertfrom $diffencoding $line]]
7819 # parse the prefix - one ' ', '-' or '+' for each parent
7820 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7821 set tag [expr {$diffnparents > 1? "m": "d"}]
7822 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7823 set words_pre_markup ""
7824 set words_post_markup ""
7825 if {[string trim $prefix " -+"] eq {}} {
7826 # prefix only has " ", "-" and "+" in it: normal diff line
7827 set num [string first "-" $prefix]
7829 set line [string range $line 1 end]
7832 # removed line, first parent with line is $num
7833 if {$num >= $mergemax} {
7836 if {$dowords && $worddiff eq [mc "Markup words"]} {
7837 $ctext insert end "\[-$line-\]" $tag$num
7839 $ctext insert end "$line" $tag$num
7842 $ctext insert end "\n" $tag$num
7846 if {[string first "+" $prefix] >= 0} {
7848 lappend tags ${tag}result
7849 if {$diffnparents > 1} {
7850 set num [string first " " $prefix]
7852 if {$num >= $mergemax} {
7858 set words_pre_markup "{+"
7859 set words_post_markup "+}"
7861 if {$targetline ne {}} {
7862 if {$diffline == $targetline} {
7863 set seehere [$ctext index "end - 1 chars"]
7869 if {$dowords && $worddiff eq [mc "Markup words"]} {
7870 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
7872 $ctext insert end "$line" $tags
7875 $ctext insert end "\n" $tags
7878 } elseif {$dowords && $prefix eq "~"} {
7879 $ctext insert end "\n" {}
7881 # "\ No newline at end of file",
7882 # or something else we don't recognize
7883 $ctext insert end "$line\n" hunksep
7887 if {[info exists seehere]} {
7888 mark_ctext_line [lindex [split $seehere .] 0]
7890 maybe_scroll_ctext [eof $bdf]
7891 $ctext conf -state disabled
7896 return [expr {$nr >= 1000? 2: 1}]
7899 proc changediffdisp {} {
7900 global ctext diffelide
7902 $ctext tag conf d0 -elide [lindex $diffelide 0]
7903 $ctext tag conf dresult -elide [lindex $diffelide 1]
7906 proc highlightfile {loc cline} {
7907 global ctext cflist cflist_top
7910 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
7911 $cflist tag add highlight $cline.0 "$cline.0 lineend"
7912 $cflist see $cline.0
7913 set cflist_top $cline
7917 global difffilestart ctext cmitmode
7919 if {$cmitmode eq "tree"} return
7922 set here [$ctext index @0,0]
7923 foreach loc $difffilestart {
7924 if {[$ctext compare $loc >= $here]} {
7925 highlightfile $prev $prevline
7931 highlightfile $prev $prevline
7935 global difffilestart ctext cmitmode
7937 if {$cmitmode eq "tree"} return
7938 set here [$ctext index @0,0]
7940 foreach loc $difffilestart {
7942 if {[$ctext compare $loc > $here]} {
7943 highlightfile $loc $line
7949 proc clear_ctext {{first 1.0}} {
7950 global ctext smarktop smarkbot
7951 global ctext_file_names ctext_file_lines
7954 set l [lindex [split $first .] 0]
7955 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
7958 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
7961 $ctext delete $first end
7962 if {$first eq "1.0"} {
7963 catch {unset pendinglinks}
7965 set ctext_file_names {}
7966 set ctext_file_lines {}
7969 proc settabs {{firstab {}}} {
7970 global firsttabstop tabstop ctext have_tk85
7972 if {$firstab ne {} && $have_tk85} {
7973 set firsttabstop $firstab
7975 set w [font measure textfont "0"]
7976 if {$firsttabstop != 0} {
7977 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
7978 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
7979 } elseif {$have_tk85 || $tabstop != 8} {
7980 $ctext conf -tabs [expr {$tabstop * $w}]
7982 $ctext conf -tabs {}
7986 proc incrsearch {name ix op} {
7987 global ctext searchstring searchdirn
7989 $ctext tag remove found 1.0 end
7990 if {[catch {$ctext index anchor}]} {
7991 # no anchor set, use start of selection, or of visible area
7992 set sel [$ctext tag ranges sel]
7994 $ctext mark set anchor [lindex $sel 0]
7995 } elseif {$searchdirn eq "-forwards"} {
7996 $ctext mark set anchor @0,0
7998 $ctext mark set anchor @0,[winfo height $ctext]
8001 if {$searchstring ne {}} {
8002 set here [$ctext search $searchdirn -- $searchstring anchor]
8011 global sstring ctext searchstring searchdirn
8014 $sstring icursor end
8015 set searchdirn -forwards
8016 if {$searchstring ne {}} {
8017 set sel [$ctext tag ranges sel]
8019 set start "[lindex $sel 0] + 1c"
8020 } elseif {[catch {set start [$ctext index anchor]}]} {
8023 set match [$ctext search -count mlen -- $searchstring $start]
8024 $ctext tag remove sel 1.0 end
8030 set mend "$match + $mlen c"
8031 $ctext tag add sel $match $mend
8032 $ctext mark unset anchor
8036 proc dosearchback {} {
8037 global sstring ctext searchstring searchdirn
8040 $sstring icursor end
8041 set searchdirn -backwards
8042 if {$searchstring ne {}} {
8043 set sel [$ctext tag ranges sel]
8045 set start [lindex $sel 0]
8046 } elseif {[catch {set start [$ctext index anchor]}]} {
8047 set start @0,[winfo height $ctext]
8049 set match [$ctext search -backwards -count ml -- $searchstring $start]
8050 $ctext tag remove sel 1.0 end
8056 set mend "$match + $ml c"
8057 $ctext tag add sel $match $mend
8058 $ctext mark unset anchor
8062 proc searchmark {first last} {
8063 global ctext searchstring
8067 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8068 if {$match eq {}} break
8069 set mend "$match + $mlen c"
8070 $ctext tag add found $match $mend
8074 proc searchmarkvisible {doall} {
8075 global ctext smarktop smarkbot
8077 set topline [lindex [split [$ctext index @0,0] .] 0]
8078 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8079 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8080 # no overlap with previous
8081 searchmark $topline $botline
8082 set smarktop $topline
8083 set smarkbot $botline
8085 if {$topline < $smarktop} {
8086 searchmark $topline [expr {$smarktop-1}]
8087 set smarktop $topline
8089 if {$botline > $smarkbot} {
8090 searchmark [expr {$smarkbot+1}] $botline
8091 set smarkbot $botline
8096 proc scrolltext {f0 f1} {
8099 .bleft.bottom.sb set $f0 $f1
8100 if {$searchstring ne {}} {
8106 global linespc charspc canvx0 canvy0
8107 global xspc1 xspc2 lthickness
8109 set linespc [font metrics mainfont -linespace]
8110 set charspc [font measure mainfont "m"]
8111 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8112 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8113 set lthickness [expr {int($linespc / 9) + 1}]
8114 set xspc1(0) $linespc
8122 set ymax [lindex [$canv cget -scrollregion] 3]
8123 if {$ymax eq {} || $ymax == 0} return
8124 set span [$canv yview]
8127 allcanvs yview moveto [lindex $span 0]
8129 if {$selectedline ne {}} {
8130 selectline $selectedline 0
8131 allcanvs yview moveto [lindex $span 0]
8135 proc parsefont {f n} {
8138 set fontattr($f,family) [lindex $n 0]
8140 if {$s eq {} || $s == 0} {
8143 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8145 set fontattr($f,size) $s
8146 set fontattr($f,weight) normal
8147 set fontattr($f,slant) roman
8148 foreach style [lrange $n 2 end] {
8151 "bold" {set fontattr($f,weight) $style}
8153 "italic" {set fontattr($f,slant) $style}
8158 proc fontflags {f {isbold 0}} {
8161 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8162 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8163 -slant $fontattr($f,slant)]
8169 set n [list $fontattr($f,family) $fontattr($f,size)]
8170 if {$fontattr($f,weight) eq "bold"} {
8173 if {$fontattr($f,slant) eq "italic"} {
8179 proc incrfont {inc} {
8180 global mainfont textfont ctext canv cflist showrefstop
8181 global stopped entries fontattr
8184 set s $fontattr(mainfont,size)
8189 set fontattr(mainfont,size) $s
8190 font config mainfont -size $s
8191 font config mainfontbold -size $s
8192 set mainfont [fontname mainfont]
8193 set s $fontattr(textfont,size)
8198 set fontattr(textfont,size) $s
8199 font config textfont -size $s
8200 font config textfontbold -size $s
8201 set textfont [fontname textfont]
8208 global sha1entry sha1string
8209 if {[string length $sha1string] == 40} {
8210 $sha1entry delete 0 end
8214 proc sha1change {n1 n2 op} {
8215 global sha1string currentid sha1but
8216 if {$sha1string == {}
8217 || ([info exists currentid] && $sha1string == $currentid)} {
8222 if {[$sha1but cget -state] == $state} return
8223 if {$state == "normal"} {
8224 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8226 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8230 proc gotocommit {} {
8231 global sha1string tagids headids curview varcid
8233 if {$sha1string == {}
8234 || ([info exists currentid] && $sha1string == $currentid)} return
8235 if {[info exists tagids($sha1string)]} {
8236 set id $tagids($sha1string)
8237 } elseif {[info exists headids($sha1string)]} {
8238 set id $headids($sha1string)
8240 set id [string tolower $sha1string]
8241 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8242 set matches [longid $id]
8243 if {$matches ne {}} {
8244 if {[llength $matches] > 1} {
8245 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8248 set id [lindex $matches 0]
8251 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8252 error_popup [mc "Revision %s is not known" $sha1string]
8257 if {[commitinview $id $curview]} {
8258 selectline [rowofcommit $id] 1
8261 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8262 set msg [mc "SHA1 id %s is not known" $sha1string]
8264 set msg [mc "Revision %s is not in the current view" $sha1string]
8269 proc lineenter {x y id} {
8270 global hoverx hovery hoverid hovertimer
8271 global commitinfo canv
8273 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8277 if {[info exists hovertimer]} {
8278 after cancel $hovertimer
8280 set hovertimer [after 500 linehover]
8284 proc linemotion {x y id} {
8285 global hoverx hovery hoverid hovertimer
8287 if {[info exists hoverid] && $id == $hoverid} {
8290 if {[info exists hovertimer]} {
8291 after cancel $hovertimer
8293 set hovertimer [after 500 linehover]
8297 proc lineleave {id} {
8298 global hoverid hovertimer canv
8300 if {[info exists hoverid] && $id == $hoverid} {
8302 if {[info exists hovertimer]} {
8303 after cancel $hovertimer
8311 global hoverx hovery hoverid hovertimer
8312 global canv linespc lthickness
8315 set text [lindex $commitinfo($hoverid) 0]
8316 set ymax [lindex [$canv cget -scrollregion] 3]
8317 if {$ymax == {}} return
8318 set yfrac [lindex [$canv yview] 0]
8319 set x [expr {$hoverx + 2 * $linespc}]
8320 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8321 set x0 [expr {$x - 2 * $lthickness}]
8322 set y0 [expr {$y - 2 * $lthickness}]
8323 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8324 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8325 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8326 -fill \#ffff80 -outline black -width 1 -tags hover]
8328 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8333 proc clickisonarrow {id y} {
8336 set ranges [rowranges $id]
8337 set thresh [expr {2 * $lthickness + 6}]
8338 set n [expr {[llength $ranges] - 1}]
8339 for {set i 1} {$i < $n} {incr i} {
8340 set row [lindex $ranges $i]
8341 if {abs([yc $row] - $y) < $thresh} {
8348 proc arrowjump {id n y} {
8351 # 1 <-> 2, 3 <-> 4, etc...
8352 set n [expr {(($n - 1) ^ 1) + 1}]
8353 set row [lindex [rowranges $id] $n]
8355 set ymax [lindex [$canv cget -scrollregion] 3]
8356 if {$ymax eq {} || $ymax <= 0} return
8357 set view [$canv yview]
8358 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8359 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8363 allcanvs yview moveto $yfrac
8366 proc lineclick {x y id isnew} {
8367 global ctext commitinfo children canv thickerline curview
8369 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8374 # draw this line thicker than normal
8378 set ymax [lindex [$canv cget -scrollregion] 3]
8379 if {$ymax eq {}} return
8380 set yfrac [lindex [$canv yview] 0]
8381 set y [expr {$y + $yfrac * $ymax}]
8383 set dirn [clickisonarrow $id $y]
8385 arrowjump $id $dirn $y
8390 addtohistory [list lineclick $x $y $id 0] savectextpos
8392 # fill the details pane with info about this line
8393 $ctext conf -state normal
8396 $ctext insert end "[mc "Parent"]:\t"
8397 $ctext insert end $id link0
8399 set info $commitinfo($id)
8400 $ctext insert end "\n\t[lindex $info 0]\n"
8401 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8402 set date [formatdate [lindex $info 2]]
8403 $ctext insert end "\t[mc "Date"]:\t$date\n"
8404 set kids $children($curview,$id)
8406 $ctext insert end "\n[mc "Children"]:"
8408 foreach child $kids {
8410 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8411 set info $commitinfo($child)
8412 $ctext insert end "\n\t"
8413 $ctext insert end $child link$i
8414 setlink $child link$i
8415 $ctext insert end "\n\t[lindex $info 0]"
8416 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8417 set date [formatdate [lindex $info 2]]
8418 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8421 maybe_scroll_ctext 1
8422 $ctext conf -state disabled
8426 proc normalline {} {
8428 if {[info exists thickerline]} {
8435 proc selbyid {id {isnew 1}} {
8437 if {[commitinview $id $curview]} {
8438 selectline [rowofcommit $id] $isnew
8444 if {![info exists startmstime]} {
8445 set startmstime [clock clicks -milliseconds]
8447 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8450 proc rowmenu {x y id} {
8451 global rowctxmenu selectedline rowmenuid curview
8452 global nullid nullid2 fakerowmenu mainhead markedid
8456 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8461 if {$id ne $nullid && $id ne $nullid2} {
8462 set menu $rowctxmenu
8463 if {$mainhead ne {}} {
8464 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8466 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8468 if {[info exists markedid] && $markedid ne $id} {
8469 $menu entryconfigure 9 -state normal
8470 $menu entryconfigure 10 -state normal
8471 $menu entryconfigure 11 -state normal
8473 $menu entryconfigure 9 -state disabled
8474 $menu entryconfigure 10 -state disabled
8475 $menu entryconfigure 11 -state disabled
8478 set menu $fakerowmenu
8480 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8481 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8482 $menu entryconfigure [mca "Make patch"] -state $state
8483 tk_popup $menu $x $y
8487 global rowmenuid markedid canv
8489 set markedid $rowmenuid
8490 make_idmark $markedid
8496 if {[info exists markedid]} {
8501 proc replace_by_kids {l r} {
8502 global curview children
8504 set id [commitonrow $r]
8505 set l [lreplace $l 0 0]
8506 foreach kid $children($curview,$id) {
8507 lappend l [rowofcommit $kid]
8509 return [lsort -integer -decreasing -unique $l]
8512 proc find_common_desc {} {
8513 global markedid rowmenuid curview children
8515 if {![info exists markedid]} return
8516 if {![commitinview $markedid $curview] ||
8517 ![commitinview $rowmenuid $curview]} return
8518 #set t1 [clock clicks -milliseconds]
8519 set l1 [list [rowofcommit $markedid]]
8520 set l2 [list [rowofcommit $rowmenuid]]
8522 set r1 [lindex $l1 0]
8523 set r2 [lindex $l2 0]
8524 if {$r1 eq {} || $r2 eq {}} break
8530 set l1 [replace_by_kids $l1 $r1]
8532 set l2 [replace_by_kids $l2 $r2]
8535 #set t2 [clock clicks -milliseconds]
8536 #puts "took [expr {$t2-$t1}]ms"
8539 proc compare_commits {} {
8540 global markedid rowmenuid curview children
8542 if {![info exists markedid]} return
8543 if {![commitinview $markedid $curview]} return
8544 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8545 do_cmp_commits $markedid $rowmenuid
8548 proc getpatchid {id} {
8551 if {![info exists patchids($id)]} {
8552 set cmd [diffcmd [list $id] {-p --root}]
8553 # trim off the initial "|"
8554 set cmd [lrange $cmd 1 end]
8556 set x [eval exec $cmd | git patch-id]
8557 set patchids($id) [lindex $x 0]
8559 set patchids($id) "error"
8562 return $patchids($id)
8565 proc do_cmp_commits {a b} {
8566 global ctext curview parents children patchids commitinfo
8568 $ctext conf -state normal
8571 for {set i 0} {$i < 100} {incr i} {
8574 if {[llength $parents($curview,$a)] > 1} {
8575 appendshortlink $a [mc "Skipping merge commit "] "\n"
8578 set patcha [getpatchid $a]
8580 if {[llength $parents($curview,$b)] > 1} {
8581 appendshortlink $b [mc "Skipping merge commit "] "\n"
8584 set patchb [getpatchid $b]
8586 if {!$skipa && !$skipb} {
8587 set heada [lindex $commitinfo($a) 0]
8588 set headb [lindex $commitinfo($b) 0]
8589 if {$patcha eq "error"} {
8590 appendshortlink $a [mc "Error getting patch ID for "] \
8591 [mc " - stopping\n"]
8594 if {$patchb eq "error"} {
8595 appendshortlink $b [mc "Error getting patch ID for "] \
8596 [mc " - stopping\n"]
8599 if {$patcha eq $patchb} {
8600 if {$heada eq $headb} {
8601 appendshortlink $a [mc "Commit "]
8602 appendshortlink $b " == " " $heada\n"
8604 appendshortlink $a [mc "Commit "] " $heada\n"
8605 appendshortlink $b [mc " is the same patch as\n "] \
8611 $ctext insert end "\n"
8612 appendshortlink $a [mc "Commit "] " $heada\n"
8613 appendshortlink $b [mc " differs from\n "] \
8615 $ctext insert end [mc "Diff of commits:\n\n"]
8616 $ctext conf -state disabled
8623 set kids [real_children $curview,$a]
8624 if {[llength $kids] != 1} {
8625 $ctext insert end "\n"
8626 appendshortlink $a [mc "Commit "] \
8627 [mc " has %s children - stopping\n" [llength $kids]]
8630 set a [lindex $kids 0]
8633 set kids [real_children $curview,$b]
8634 if {[llength $kids] != 1} {
8635 appendshortlink $b [mc "Commit "] \
8636 [mc " has %s children - stopping\n" [llength $kids]]
8639 set b [lindex $kids 0]
8642 $ctext conf -state disabled
8645 proc diffcommits {a b} {
8646 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8648 set tmpdir [gitknewtmpdir]
8649 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8650 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8652 exec git diff-tree -p --pretty $a >$fna
8653 exec git diff-tree -p --pretty $b >$fnb
8655 error_popup [mc "Error writing commit to file: %s" $err]
8659 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8661 error_popup [mc "Error diffing commits: %s" $err]
8664 set diffids [list commits $a $b]
8665 set blobdifffd($diffids) $fd
8667 set currdiffsubmod ""
8668 filerun $fd [list getblobdiffline $fd $diffids]
8671 proc diffvssel {dirn} {
8672 global rowmenuid selectedline
8674 if {$selectedline eq {}} return
8676 set oldid [commitonrow $selectedline]
8677 set newid $rowmenuid
8679 set oldid $rowmenuid
8680 set newid [commitonrow $selectedline]
8682 addtohistory [list doseldiff $oldid $newid] savectextpos
8683 doseldiff $oldid $newid
8686 proc doseldiff {oldid newid} {
8690 $ctext conf -state normal
8692 init_flist [mc "Top"]
8693 $ctext insert end "[mc "From"] "
8694 $ctext insert end $oldid link0
8695 setlink $oldid link0
8696 $ctext insert end "\n "
8697 $ctext insert end [lindex $commitinfo($oldid) 0]
8698 $ctext insert end "\n\n[mc "To"] "
8699 $ctext insert end $newid link1
8700 setlink $newid link1
8701 $ctext insert end "\n "
8702 $ctext insert end [lindex $commitinfo($newid) 0]
8703 $ctext insert end "\n"
8704 $ctext conf -state disabled
8705 $ctext tag remove found 1.0 end
8706 startdiff [list $oldid $newid]
8710 global rowmenuid currentid commitinfo patchtop patchnum NS
8712 if {![info exists currentid]} return
8713 set oldid $currentid
8714 set oldhead [lindex $commitinfo($oldid) 0]
8715 set newid $rowmenuid
8716 set newhead [lindex $commitinfo($newid) 0]
8719 catch {destroy $top}
8721 make_transient $top .
8722 ${NS}::label $top.title -text [mc "Generate patch"]
8723 grid $top.title - -pady 10
8724 ${NS}::label $top.from -text [mc "From:"]
8725 ${NS}::entry $top.fromsha1 -width 40
8726 $top.fromsha1 insert 0 $oldid
8727 $top.fromsha1 conf -state readonly
8728 grid $top.from $top.fromsha1 -sticky w
8729 ${NS}::entry $top.fromhead -width 60
8730 $top.fromhead insert 0 $oldhead
8731 $top.fromhead conf -state readonly
8732 grid x $top.fromhead -sticky w
8733 ${NS}::label $top.to -text [mc "To:"]
8734 ${NS}::entry $top.tosha1 -width 40
8735 $top.tosha1 insert 0 $newid
8736 $top.tosha1 conf -state readonly
8737 grid $top.to $top.tosha1 -sticky w
8738 ${NS}::entry $top.tohead -width 60
8739 $top.tohead insert 0 $newhead
8740 $top.tohead conf -state readonly
8741 grid x $top.tohead -sticky w
8742 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
8743 grid $top.rev x -pady 10 -padx 5
8744 ${NS}::label $top.flab -text [mc "Output file:"]
8745 ${NS}::entry $top.fname -width 60
8746 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8748 grid $top.flab $top.fname -sticky w
8749 ${NS}::frame $top.buts
8750 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8751 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8752 bind $top <Key-Return> mkpatchgo
8753 bind $top <Key-Escape> mkpatchcan
8754 grid $top.buts.gen $top.buts.can
8755 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8756 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8757 grid $top.buts - -pady 10 -sticky ew
8761 proc mkpatchrev {} {
8764 set oldid [$patchtop.fromsha1 get]
8765 set oldhead [$patchtop.fromhead get]
8766 set newid [$patchtop.tosha1 get]
8767 set newhead [$patchtop.tohead get]
8768 foreach e [list fromsha1 fromhead tosha1 tohead] \
8769 v [list $newid $newhead $oldid $oldhead] {
8770 $patchtop.$e conf -state normal
8771 $patchtop.$e delete 0 end
8772 $patchtop.$e insert 0 $v
8773 $patchtop.$e conf -state readonly
8778 global patchtop nullid nullid2
8780 set oldid [$patchtop.fromsha1 get]
8781 set newid [$patchtop.tosha1 get]
8782 set fname [$patchtop.fname get]
8783 set cmd [diffcmd [list $oldid $newid] -p]
8784 # trim off the initial "|"
8785 set cmd [lrange $cmd 1 end]
8786 lappend cmd >$fname &
8787 if {[catch {eval exec $cmd} err]} {
8788 error_popup "[mc "Error creating patch:"] $err" $patchtop
8790 catch {destroy $patchtop}
8794 proc mkpatchcan {} {
8797 catch {destroy $patchtop}
8802 global rowmenuid mktagtop commitinfo NS
8806 catch {destroy $top}
8808 make_transient $top .
8809 ${NS}::label $top.title -text [mc "Create tag"]
8810 grid $top.title - -pady 10
8811 ${NS}::label $top.id -text [mc "ID:"]
8812 ${NS}::entry $top.sha1 -width 40
8813 $top.sha1 insert 0 $rowmenuid
8814 $top.sha1 conf -state readonly
8815 grid $top.id $top.sha1 -sticky w
8816 ${NS}::entry $top.head -width 60
8817 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8818 $top.head conf -state readonly
8819 grid x $top.head -sticky w
8820 ${NS}::label $top.tlab -text [mc "Tag name:"]
8821 ${NS}::entry $top.tag -width 60
8822 grid $top.tlab $top.tag -sticky w
8823 ${NS}::label $top.op -text [mc "Tag message is optional"]
8824 grid $top.op -columnspan 2 -sticky we
8825 ${NS}::label $top.mlab -text [mc "Tag message:"]
8826 ${NS}::entry $top.msg -width 60
8827 grid $top.mlab $top.msg -sticky w
8828 ${NS}::frame $top.buts
8829 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
8830 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
8831 bind $top <Key-Return> mktaggo
8832 bind $top <Key-Escape> mktagcan
8833 grid $top.buts.gen $top.buts.can
8834 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8835 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8836 grid $top.buts - -pady 10 -sticky ew
8841 global mktagtop env tagids idtags
8843 set id [$mktagtop.sha1 get]
8844 set tag [$mktagtop.tag get]
8845 set msg [$mktagtop.msg get]
8847 error_popup [mc "No tag name specified"] $mktagtop
8850 if {[info exists tagids($tag)]} {
8851 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
8856 exec git tag -a -m $msg $tag $id
8858 exec git tag $tag $id
8861 error_popup "[mc "Error creating tag:"] $err" $mktagtop
8865 set tagids($tag) $id
8866 lappend idtags($id) $tag
8874 proc redrawtags {id} {
8875 global canv linehtag idpos currentid curview cmitlisted markedid
8876 global canvxmax iddrawn circleitem mainheadid circlecolors
8878 if {![commitinview $id $curview]} return
8879 if {![info exists iddrawn($id)]} return
8880 set row [rowofcommit $id]
8881 if {$id eq $mainheadid} {
8884 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
8886 $canv itemconf $circleitem($row) -fill $ofill
8887 $canv delete tag.$id
8888 set xt [eval drawtags $id $idpos($id)]
8889 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
8890 set text [$canv itemcget $linehtag($id) -text]
8891 set font [$canv itemcget $linehtag($id) -font]
8892 set xr [expr {$xt + [font measure $font $text]}]
8893 if {$xr > $canvxmax} {
8897 if {[info exists currentid] && $currentid == $id} {
8900 if {[info exists markedid] && $markedid eq $id} {
8908 catch {destroy $mktagtop}
8913 if {![domktag]} return
8917 proc writecommit {} {
8918 global rowmenuid wrcomtop commitinfo wrcomcmd NS
8920 set top .writecommit
8922 catch {destroy $top}
8924 make_transient $top .
8925 ${NS}::label $top.title -text [mc "Write commit to file"]
8926 grid $top.title - -pady 10
8927 ${NS}::label $top.id -text [mc "ID:"]
8928 ${NS}::entry $top.sha1 -width 40
8929 $top.sha1 insert 0 $rowmenuid
8930 $top.sha1 conf -state readonly
8931 grid $top.id $top.sha1 -sticky w
8932 ${NS}::entry $top.head -width 60
8933 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8934 $top.head conf -state readonly
8935 grid x $top.head -sticky w
8936 ${NS}::label $top.clab -text [mc "Command:"]
8937 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
8938 grid $top.clab $top.cmd -sticky w -pady 10
8939 ${NS}::label $top.flab -text [mc "Output file:"]
8940 ${NS}::entry $top.fname -width 60
8941 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
8942 grid $top.flab $top.fname -sticky w
8943 ${NS}::frame $top.buts
8944 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
8945 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
8946 bind $top <Key-Return> wrcomgo
8947 bind $top <Key-Escape> wrcomcan
8948 grid $top.buts.gen $top.buts.can
8949 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8950 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8951 grid $top.buts - -pady 10 -sticky ew
8958 set id [$wrcomtop.sha1 get]
8959 set cmd "echo $id | [$wrcomtop.cmd get]"
8960 set fname [$wrcomtop.fname get]
8961 if {[catch {exec sh -c $cmd >$fname &} err]} {
8962 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
8964 catch {destroy $wrcomtop}
8971 catch {destroy $wrcomtop}
8976 global rowmenuid mkbrtop NS
8979 catch {destroy $top}
8981 make_transient $top .
8982 ${NS}::label $top.title -text [mc "Create new branch"]
8983 grid $top.title - -pady 10
8984 ${NS}::label $top.id -text [mc "ID:"]
8985 ${NS}::entry $top.sha1 -width 40
8986 $top.sha1 insert 0 $rowmenuid
8987 $top.sha1 conf -state readonly
8988 grid $top.id $top.sha1 -sticky w
8989 ${NS}::label $top.nlab -text [mc "Name:"]
8990 ${NS}::entry $top.name -width 40
8991 grid $top.nlab $top.name -sticky w
8992 ${NS}::frame $top.buts
8993 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
8994 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
8995 bind $top <Key-Return> [list mkbrgo $top]
8996 bind $top <Key-Escape> "catch {destroy $top}"
8997 grid $top.buts.go $top.buts.can
8998 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8999 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9000 grid $top.buts - -pady 10 -sticky ew
9005 global headids idheads
9007 set name [$top.name get]
9008 set id [$top.sha1 get]
9012 error_popup [mc "Please specify a name for the new branch"] $top
9015 if {[info exists headids($name)]} {
9016 if {![confirm_popup [mc \
9017 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9020 set old_id $headids($name)
9023 catch {destroy $top}
9024 lappend cmdargs $name $id
9028 eval exec git branch $cmdargs
9034 if {$old_id ne {}} {
9040 set headids($name) $id
9041 lappend idheads($id) $name
9050 proc exec_citool {tool_args {baseid {}}} {
9051 global commitinfo env
9053 set save_env [array get env GIT_AUTHOR_*]
9055 if {$baseid ne {}} {
9056 if {![info exists commitinfo($baseid)]} {
9059 set author [lindex $commitinfo($baseid) 1]
9060 set date [lindex $commitinfo($baseid) 2]
9061 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9062 $author author name email]
9064 set env(GIT_AUTHOR_NAME) $name
9065 set env(GIT_AUTHOR_EMAIL) $email
9066 set env(GIT_AUTHOR_DATE) $date
9070 eval exec git citool $tool_args &
9072 array unset env GIT_AUTHOR_*
9073 array set env $save_env
9076 proc cherrypick {} {
9077 global rowmenuid curview
9078 global mainhead mainheadid
9081 set oldhead [exec git rev-parse HEAD]
9082 set dheads [descheads $rowmenuid]
9083 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9084 set ok [confirm_popup [mc "Commit %s is already\
9085 included in branch %s -- really re-apply it?" \
9086 [string range $rowmenuid 0 7] $mainhead]]
9089 nowbusy cherrypick [mc "Cherry-picking"]
9091 # Unfortunately git-cherry-pick writes stuff to stderr even when
9092 # no error occurs, and exec takes that as an indication of error...
9093 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9096 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9098 error_popup [mc "Cherry-pick failed because of local changes\
9099 to file '%s'.\nPlease commit, reset or stash\
9100 your changes and try again." $fname]
9101 } elseif {[regexp -line \
9102 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9104 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9105 conflict.\nDo you wish to run git citool to\
9107 # Force citool to read MERGE_MSG
9108 file delete [file join $gitdir "GITGUI_MSG"]
9109 exec_citool {} $rowmenuid
9117 set newhead [exec git rev-parse HEAD]
9118 if {$newhead eq $oldhead} {
9120 error_popup [mc "No changes committed"]
9123 addnewchild $newhead $oldhead
9124 if {[commitinview $oldhead $curview]} {
9125 # XXX this isn't right if we have a path limit...
9126 insertrow $newhead $oldhead $curview
9127 if {$mainhead ne {}} {
9128 movehead $newhead $mainhead
9129 movedhead $newhead $mainhead
9131 set mainheadid $newhead
9140 global mainhead rowmenuid confirm_ok resettype NS
9143 set w ".confirmreset"
9146 wm title $w [mc "Confirm reset"]
9147 ${NS}::label $w.m -text \
9148 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9149 pack $w.m -side top -fill x -padx 20 -pady 20
9150 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9152 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9153 -text [mc "Soft: Leave working tree and index untouched"]
9154 grid $w.f.soft -sticky w
9155 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9156 -text [mc "Mixed: Leave working tree untouched, reset index"]
9157 grid $w.f.mixed -sticky w
9158 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9159 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9160 grid $w.f.hard -sticky w
9161 pack $w.f -side top -fill x -padx 4
9162 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9163 pack $w.ok -side left -fill x -padx 20 -pady 20
9164 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9165 bind $w <Key-Escape> [list destroy $w]
9166 pack $w.cancel -side right -fill x -padx 20 -pady 20
9167 bind $w <Visibility> "grab $w; focus $w"
9169 if {!$confirm_ok} return
9170 if {[catch {set fd [open \
9171 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9175 filerun $fd [list readresetstat $fd]
9176 nowbusy reset [mc "Resetting"]
9181 proc readresetstat {fd} {
9182 global mainhead mainheadid showlocalchanges rprogcoord
9184 if {[gets $fd line] >= 0} {
9185 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9186 set rprogcoord [expr {1.0 * $m / $n}]
9194 if {[catch {close $fd} err]} {
9197 set oldhead $mainheadid
9198 set newhead [exec git rev-parse HEAD]
9199 if {$newhead ne $oldhead} {
9200 movehead $newhead $mainhead
9201 movedhead $newhead $mainhead
9202 set mainheadid $newhead
9206 if {$showlocalchanges} {
9212 # context menu for a head
9213 proc headmenu {x y id head} {
9214 global headmenuid headmenuhead headctxmenu mainhead
9218 set headmenuhead $head
9220 if {[string match "remotes/*" $head]} {
9223 if {$head eq $mainhead} {
9226 $headctxmenu entryconfigure 0 -state $state
9227 $headctxmenu entryconfigure 1 -state $state
9228 tk_popup $headctxmenu $x $y
9232 global headmenuid headmenuhead headids
9233 global showlocalchanges
9235 # check the tree is clean first??
9236 nowbusy checkout [mc "Checking out"]
9240 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9244 if {$showlocalchanges} {
9248 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9252 proc readcheckoutstat {fd newhead newheadid} {
9253 global mainhead mainheadid headids showlocalchanges progresscoords
9254 global viewmainheadid curview
9256 if {[gets $fd line] >= 0} {
9257 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9258 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9263 set progresscoords {0 0}
9266 if {[catch {close $fd} err]} {
9269 set oldmainid $mainheadid
9270 set mainhead $newhead
9271 set mainheadid $newheadid
9272 set viewmainheadid($curview) $newheadid
9273 redrawtags $oldmainid
9274 redrawtags $newheadid
9276 if {$showlocalchanges} {
9282 global headmenuid headmenuhead mainhead
9285 set head $headmenuhead
9287 # this check shouldn't be needed any more...
9288 if {$head eq $mainhead} {
9289 error_popup [mc "Cannot delete the currently checked-out branch"]
9292 set dheads [descheads $id]
9293 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9294 # the stuff on this branch isn't on any other branch
9295 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9296 branch.\nReally delete branch %s?" $head $head]]} return
9300 if {[catch {exec git branch -D $head} err]} {
9305 removehead $id $head
9306 removedhead $id $head
9313 # Display a list of tags and heads
9315 global showrefstop bgcolor fgcolor selectbgcolor NS
9316 global bglist fglist reflistfilter reflist maincursor
9319 set showrefstop $top
9320 if {[winfo exists $top]} {
9326 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9327 make_transient $top .
9328 text $top.list -background $bgcolor -foreground $fgcolor \
9329 -selectbackground $selectbgcolor -font mainfont \
9330 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9331 -width 30 -height 20 -cursor $maincursor \
9332 -spacing1 1 -spacing3 1 -state disabled
9333 $top.list tag configure highlight -background $selectbgcolor
9334 lappend bglist $top.list
9335 lappend fglist $top.list
9336 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9337 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9338 grid $top.list $top.ysb -sticky nsew
9339 grid $top.xsb x -sticky ew
9341 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9342 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9343 set reflistfilter "*"
9344 trace add variable reflistfilter write reflistfilter_change
9345 pack $top.f.e -side right -fill x -expand 1
9346 pack $top.f.l -side left
9347 grid $top.f - -sticky ew -pady 2
9348 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9349 bind $top <Key-Escape> [list destroy $top]
9351 grid columnconfigure $top 0 -weight 1
9352 grid rowconfigure $top 0 -weight 1
9353 bind $top.list <1> {break}
9354 bind $top.list <B1-Motion> {break}
9355 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9360 proc sel_reflist {w x y} {
9361 global showrefstop reflist headids tagids otherrefids
9363 if {![winfo exists $showrefstop]} return
9364 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9365 set ref [lindex $reflist [expr {$l-1}]]
9366 set n [lindex $ref 0]
9367 switch -- [lindex $ref 1] {
9368 "H" {selbyid $headids($n)}
9369 "T" {selbyid $tagids($n)}
9370 "o" {selbyid $otherrefids($n)}
9372 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9375 proc unsel_reflist {} {
9378 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9379 $showrefstop.list tag remove highlight 0.0 end
9382 proc reflistfilter_change {n1 n2 op} {
9383 global reflistfilter
9385 after cancel refill_reflist
9386 after 200 refill_reflist
9389 proc refill_reflist {} {
9390 global reflist reflistfilter showrefstop headids tagids otherrefids
9393 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9395 foreach n [array names headids] {
9396 if {[string match $reflistfilter $n]} {
9397 if {[commitinview $headids($n) $curview]} {
9398 lappend refs [list $n H]
9400 interestedin $headids($n) {run refill_reflist}
9404 foreach n [array names tagids] {
9405 if {[string match $reflistfilter $n]} {
9406 if {[commitinview $tagids($n) $curview]} {
9407 lappend refs [list $n T]
9409 interestedin $tagids($n) {run refill_reflist}
9413 foreach n [array names otherrefids] {
9414 if {[string match $reflistfilter $n]} {
9415 if {[commitinview $otherrefids($n) $curview]} {
9416 lappend refs [list $n o]
9418 interestedin $otherrefids($n) {run refill_reflist}
9422 set refs [lsort -index 0 $refs]
9423 if {$refs eq $reflist} return
9425 # Update the contents of $showrefstop.list according to the
9426 # differences between $reflist (old) and $refs (new)
9427 $showrefstop.list conf -state normal
9428 $showrefstop.list insert end "\n"
9431 while {$i < [llength $reflist] || $j < [llength $refs]} {
9432 if {$i < [llength $reflist]} {
9433 if {$j < [llength $refs]} {
9434 set cmp [string compare [lindex $reflist $i 0] \
9435 [lindex $refs $j 0]]
9437 set cmp [string compare [lindex $reflist $i 1] \
9438 [lindex $refs $j 1]]
9448 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9456 set l [expr {$j + 1}]
9457 $showrefstop.list image create $l.0 -align baseline \
9458 -image reficon-[lindex $refs $j 1] -padx 2
9459 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9465 # delete last newline
9466 $showrefstop.list delete end-2c end-1c
9467 $showrefstop.list conf -state disabled
9470 # Stuff for finding nearby tags
9471 proc getallcommits {} {
9472 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9473 global idheads idtags idotherrefs allparents tagobjid
9476 if {![info exists allcommits]} {
9482 set allccache [file join $gitdir "gitk.cache"]
9484 set f [open $allccache r]
9493 set cmd [list | git rev-list --parents]
9494 set allcupdate [expr {$seeds ne {}}]
9498 set refs [concat [array names idheads] [array names idtags] \
9499 [array names idotherrefs]]
9502 foreach name [array names tagobjid] {
9503 lappend tagobjs $tagobjid($name)
9505 foreach id [lsort -unique $refs] {
9506 if {![info exists allparents($id)] &&
9507 [lsearch -exact $tagobjs $id] < 0} {
9518 set cmd [limit_arg_length [concat $cmd $ids]]
9519 set fd [open $cmd r]
9520 fconfigure $fd -blocking 0
9523 filerun $fd [list getallclines $fd]
9529 # The maximum command line length for the CreateProcess function is 32767 characters, see
9530 # http://blogs.msdn.com/oldnewthing/archive/2003/12/10/56028.aspx
9531 # Be a little conservative in case Tcl adds some more stuff to the command line we do not
9532 # know about and truncate the command line at a SHA1-boundary below 32000 characters.
9533 proc limit_arg_length {cmd} {
9534 if {[tk windowingsystem] == "win32" &&
9535 [string length $cmd] > 32000} {
9536 set ndx [string last " " $cmd 32000]
9538 return [string range $cmd 0 $ndx]
9544 # Since most commits have 1 parent and 1 child, we group strings of
9545 # such commits into "arcs" joining branch/merge points (BMPs), which
9546 # are commits that either don't have 1 parent or don't have 1 child.
9548 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9549 # arcout(id) - outgoing arcs for BMP
9550 # arcids(a) - list of IDs on arc including end but not start
9551 # arcstart(a) - BMP ID at start of arc
9552 # arcend(a) - BMP ID at end of arc
9553 # growing(a) - arc a is still growing
9554 # arctags(a) - IDs out of arcids (excluding end) that have tags
9555 # archeads(a) - IDs out of arcids (excluding end) that have heads
9556 # The start of an arc is at the descendent end, so "incoming" means
9557 # coming from descendents, and "outgoing" means going towards ancestors.
9559 proc getallclines {fd} {
9560 global allparents allchildren idtags idheads nextarc
9561 global arcnos arcids arctags arcout arcend arcstart archeads growing
9562 global seeds allcommits cachedarcs allcupdate
9565 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9566 set id [lindex $line 0]
9567 if {[info exists allparents($id)]} {
9572 set olds [lrange $line 1 end]
9573 set allparents($id) $olds
9574 if {![info exists allchildren($id)]} {
9575 set allchildren($id) {}
9580 if {[llength $olds] == 1 && [llength $a] == 1} {
9581 lappend arcids($a) $id
9582 if {[info exists idtags($id)]} {
9583 lappend arctags($a) $id
9585 if {[info exists idheads($id)]} {
9586 lappend archeads($a) $id
9588 if {[info exists allparents($olds)]} {
9589 # seen parent already
9590 if {![info exists arcout($olds)]} {
9593 lappend arcids($a) $olds
9594 set arcend($a) $olds
9597 lappend allchildren($olds) $id
9598 lappend arcnos($olds) $a
9602 foreach a $arcnos($id) {
9603 lappend arcids($a) $id
9610 lappend allchildren($p) $id
9611 set a [incr nextarc]
9612 set arcstart($a) $id
9619 if {[info exists allparents($p)]} {
9620 # seen it already, may need to make a new branch
9621 if {![info exists arcout($p)]} {
9624 lappend arcids($a) $p
9628 lappend arcnos($p) $a
9633 global cached_dheads cached_dtags cached_atags
9634 catch {unset cached_dheads}
9635 catch {unset cached_dtags}
9636 catch {unset cached_atags}
9639 return [expr {$nid >= 1000? 2: 1}]
9643 fconfigure $fd -blocking 1
9646 # got an error reading the list of commits
9647 # if we were updating, try rereading the whole thing again
9653 error_popup "[mc "Error reading commit topology information;\
9654 branch and preceding/following tag information\
9655 will be incomplete."]\n($err)"
9658 if {[incr allcommits -1] == 0} {
9668 proc recalcarc {a} {
9669 global arctags archeads arcids idtags idheads
9673 foreach id [lrange $arcids($a) 0 end-1] {
9674 if {[info exists idtags($id)]} {
9677 if {[info exists idheads($id)]} {
9682 set archeads($a) $ah
9686 global arcnos arcids nextarc arctags archeads idtags idheads
9687 global arcstart arcend arcout allparents growing
9690 if {[llength $a] != 1} {
9691 puts "oops splitarc called but [llength $a] arcs already"
9695 set i [lsearch -exact $arcids($a) $p]
9697 puts "oops splitarc $p not in arc $a"
9700 set na [incr nextarc]
9701 if {[info exists arcend($a)]} {
9702 set arcend($na) $arcend($a)
9704 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9705 set j [lsearch -exact $arcnos($l) $a]
9706 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9708 set tail [lrange $arcids($a) [expr {$i+1}] end]
9709 set arcids($a) [lrange $arcids($a) 0 $i]
9711 set arcstart($na) $p
9713 set arcids($na) $tail
9714 if {[info exists growing($a)]} {
9720 if {[llength $arcnos($id)] == 1} {
9723 set j [lsearch -exact $arcnos($id) $a]
9724 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9728 # reconstruct tags and heads lists
9729 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9734 set archeads($na) {}
9738 # Update things for a new commit added that is a child of one
9739 # existing commit. Used when cherry-picking.
9740 proc addnewchild {id p} {
9741 global allparents allchildren idtags nextarc
9742 global arcnos arcids arctags arcout arcend arcstart archeads growing
9743 global seeds allcommits
9745 if {![info exists allcommits] || ![info exists arcnos($p)]} return
9746 set allparents($id) [list $p]
9747 set allchildren($id) {}
9750 lappend allchildren($p) $id
9751 set a [incr nextarc]
9752 set arcstart($a) $id
9755 set arcids($a) [list $p]
9757 if {![info exists arcout($p)]} {
9760 lappend arcnos($p) $a
9761 set arcout($id) [list $a]
9764 # This implements a cache for the topology information.
9765 # The cache saves, for each arc, the start and end of the arc,
9766 # the ids on the arc, and the outgoing arcs from the end.
9767 proc readcache {f} {
9768 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
9769 global idtags idheads allparents cachedarcs possible_seeds seeds growing
9774 if {$lim - $a > 500} {
9775 set lim [expr {$a + 500}]
9779 # finish reading the cache and setting up arctags, etc.
9781 if {$line ne "1"} {error "bad final version"}
9783 foreach id [array names idtags] {
9784 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9785 [llength $allparents($id)] == 1} {
9786 set a [lindex $arcnos($id) 0]
9787 if {$arctags($a) eq {}} {
9792 foreach id [array names idheads] {
9793 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9794 [llength $allparents($id)] == 1} {
9795 set a [lindex $arcnos($id) 0]
9796 if {$archeads($a) eq {}} {
9801 foreach id [lsort -unique $possible_seeds] {
9802 if {$arcnos($id) eq {}} {
9808 while {[incr a] <= $lim} {
9810 if {[llength $line] != 3} {error "bad line"}
9811 set s [lindex $line 0]
9813 lappend arcout($s) $a
9814 if {![info exists arcnos($s)]} {
9815 lappend possible_seeds $s
9818 set e [lindex $line 1]
9823 if {![info exists arcout($e)]} {
9827 set arcids($a) [lindex $line 2]
9828 foreach id $arcids($a) {
9829 lappend allparents($s) $id
9831 lappend arcnos($id) $a
9833 if {![info exists allparents($s)]} {
9834 set allparents($s) {}
9839 set nextarc [expr {$a - 1}]
9852 global nextarc cachedarcs possible_seeds
9856 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
9857 # make sure it's an integer
9858 set cachedarcs [expr {int([lindex $line 1])}]
9859 if {$cachedarcs < 0} {error "bad number of arcs"}
9861 set possible_seeds {}
9869 proc dropcache {err} {
9870 global allcwait nextarc cachedarcs seeds
9872 #puts "dropping cache ($err)"
9873 foreach v {arcnos arcout arcids arcstart arcend growing \
9874 arctags archeads allparents allchildren} {
9885 proc writecache {f} {
9886 global cachearc cachedarcs allccache
9887 global arcstart arcend arcnos arcids arcout
9891 if {$lim - $a > 1000} {
9892 set lim [expr {$a + 1000}]
9895 while {[incr a] <= $lim} {
9896 if {[info exists arcend($a)]} {
9897 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
9899 puts $f [list $arcstart($a) {} $arcids($a)]
9904 catch {file delete $allccache}
9905 #puts "writing cache failed ($err)"
9908 set cachearc [expr {$a - 1}]
9909 if {$a > $cachedarcs} {
9918 global nextarc cachedarcs cachearc allccache
9920 if {$nextarc == $cachedarcs} return
9922 set cachedarcs $nextarc
9924 set f [open $allccache w]
9925 puts $f [list 1 $cachedarcs]
9930 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
9931 # or 0 if neither is true.
9932 proc anc_or_desc {a b} {
9933 global arcout arcstart arcend arcnos cached_isanc
9935 if {$arcnos($a) eq $arcnos($b)} {
9936 # Both are on the same arc(s); either both are the same BMP,
9937 # or if one is not a BMP, the other is also not a BMP or is
9938 # the BMP at end of the arc (and it only has 1 incoming arc).
9939 # Or both can be BMPs with no incoming arcs.
9940 if {$a eq $b || $arcnos($a) eq {}} {
9943 # assert {[llength $arcnos($a)] == 1}
9944 set arc [lindex $arcnos($a) 0]
9945 set i [lsearch -exact $arcids($arc) $a]
9946 set j [lsearch -exact $arcids($arc) $b]
9947 if {$i < 0 || $i > $j} {
9954 if {![info exists arcout($a)]} {
9955 set arc [lindex $arcnos($a) 0]
9956 if {[info exists arcend($arc)]} {
9957 set aend $arcend($arc)
9961 set a $arcstart($arc)
9965 if {![info exists arcout($b)]} {
9966 set arc [lindex $arcnos($b) 0]
9967 if {[info exists arcend($arc)]} {
9968 set bend $arcend($arc)
9972 set b $arcstart($arc)
9982 if {[info exists cached_isanc($a,$bend)]} {
9983 if {$cached_isanc($a,$bend)} {
9987 if {[info exists cached_isanc($b,$aend)]} {
9988 if {$cached_isanc($b,$aend)} {
9991 if {[info exists cached_isanc($a,$bend)]} {
9996 set todo [list $a $b]
9999 for {set i 0} {$i < [llength $todo]} {incr i} {
10000 set x [lindex $todo $i]
10001 if {$anc($x) eq {}} {
10004 foreach arc $arcnos($x) {
10005 set xd $arcstart($arc)
10006 if {$xd eq $bend} {
10007 set cached_isanc($a,$bend) 1
10008 set cached_isanc($b,$aend) 0
10010 } elseif {$xd eq $aend} {
10011 set cached_isanc($b,$aend) 1
10012 set cached_isanc($a,$bend) 0
10015 if {![info exists anc($xd)]} {
10016 set anc($xd) $anc($x)
10018 } elseif {$anc($xd) ne $anc($x)} {
10023 set cached_isanc($a,$bend) 0
10024 set cached_isanc($b,$aend) 0
10028 # This identifies whether $desc has an ancestor that is
10029 # a growing tip of the graph and which is not an ancestor of $anc
10030 # and returns 0 if so and 1 if not.
10031 # If we subsequently discover a tag on such a growing tip, and that
10032 # turns out to be a descendent of $anc (which it could, since we
10033 # don't necessarily see children before parents), then $desc
10034 # isn't a good choice to display as a descendent tag of
10035 # $anc (since it is the descendent of another tag which is
10036 # a descendent of $anc). Similarly, $anc isn't a good choice to
10037 # display as a ancestor tag of $desc.
10039 proc is_certain {desc anc} {
10040 global arcnos arcout arcstart arcend growing problems
10043 if {[llength $arcnos($anc)] == 1} {
10044 # tags on the same arc are certain
10045 if {$arcnos($desc) eq $arcnos($anc)} {
10048 if {![info exists arcout($anc)]} {
10049 # if $anc is partway along an arc, use the start of the arc instead
10050 set a [lindex $arcnos($anc) 0]
10051 set anc $arcstart($a)
10054 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10057 set a [lindex $arcnos($desc) 0]
10063 set anclist [list $x]
10067 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10068 set x [lindex $anclist $i]
10073 foreach a $arcout($x) {
10074 if {[info exists growing($a)]} {
10075 if {![info exists growanc($x)] && $dl($x)} {
10081 if {[info exists dl($y)]} {
10085 if {![info exists done($y)]} {
10088 if {[info exists growanc($x)]} {
10092 for {set k 0} {$k < [llength $xl]} {incr k} {
10093 set z [lindex $xl $k]
10094 foreach c $arcout($z) {
10095 if {[info exists arcend($c)]} {
10097 if {[info exists dl($v)] && $dl($v)} {
10099 if {![info exists done($v)]} {
10102 if {[info exists growanc($v)]} {
10112 } elseif {$y eq $anc || !$dl($x)} {
10123 foreach x [array names growanc] {
10132 proc validate_arctags {a} {
10133 global arctags idtags
10136 set na $arctags($a)
10137 foreach id $arctags($a) {
10139 if {![info exists idtags($id)]} {
10140 set na [lreplace $na $i $i]
10144 set arctags($a) $na
10147 proc validate_archeads {a} {
10148 global archeads idheads
10151 set na $archeads($a)
10152 foreach id $archeads($a) {
10154 if {![info exists idheads($id)]} {
10155 set na [lreplace $na $i $i]
10159 set archeads($a) $na
10162 # Return the list of IDs that have tags that are descendents of id,
10163 # ignoring IDs that are descendents of IDs already reported.
10164 proc desctags {id} {
10165 global arcnos arcstart arcids arctags idtags allparents
10166 global growing cached_dtags
10168 if {![info exists allparents($id)]} {
10171 set t1 [clock clicks -milliseconds]
10173 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10174 # part-way along an arc; check that arc first
10175 set a [lindex $arcnos($id) 0]
10176 if {$arctags($a) ne {}} {
10177 validate_arctags $a
10178 set i [lsearch -exact $arcids($a) $id]
10180 foreach t $arctags($a) {
10181 set j [lsearch -exact $arcids($a) $t]
10182 if {$j >= $i} break
10189 set id $arcstart($a)
10190 if {[info exists idtags($id)]} {
10194 if {[info exists cached_dtags($id)]} {
10195 return $cached_dtags($id)
10199 set todo [list $id]
10202 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10203 set id [lindex $todo $i]
10205 set ta [info exists hastaggedancestor($id)]
10209 # ignore tags on starting node
10210 if {!$ta && $i > 0} {
10211 if {[info exists idtags($id)]} {
10212 set tagloc($id) $id
10214 } elseif {[info exists cached_dtags($id)]} {
10215 set tagloc($id) $cached_dtags($id)
10219 foreach a $arcnos($id) {
10220 set d $arcstart($a)
10221 if {!$ta && $arctags($a) ne {}} {
10222 validate_arctags $a
10223 if {$arctags($a) ne {}} {
10224 lappend tagloc($id) [lindex $arctags($a) end]
10227 if {$ta || $arctags($a) ne {}} {
10228 set tomark [list $d]
10229 for {set j 0} {$j < [llength $tomark]} {incr j} {
10230 set dd [lindex $tomark $j]
10231 if {![info exists hastaggedancestor($dd)]} {
10232 if {[info exists done($dd)]} {
10233 foreach b $arcnos($dd) {
10234 lappend tomark $arcstart($b)
10236 if {[info exists tagloc($dd)]} {
10239 } elseif {[info exists queued($dd)]} {
10242 set hastaggedancestor($dd) 1
10246 if {![info exists queued($d)]} {
10249 if {![info exists hastaggedancestor($d)]} {
10256 foreach id [array names tagloc] {
10257 if {![info exists hastaggedancestor($id)]} {
10258 foreach t $tagloc($id) {
10259 if {[lsearch -exact $tags $t] < 0} {
10265 set t2 [clock clicks -milliseconds]
10268 # remove tags that are descendents of other tags
10269 for {set i 0} {$i < [llength $tags]} {incr i} {
10270 set a [lindex $tags $i]
10271 for {set j 0} {$j < $i} {incr j} {
10272 set b [lindex $tags $j]
10273 set r [anc_or_desc $a $b]
10275 set tags [lreplace $tags $j $j]
10278 } elseif {$r == -1} {
10279 set tags [lreplace $tags $i $i]
10286 if {[array names growing] ne {}} {
10287 # graph isn't finished, need to check if any tag could get
10288 # eclipsed by another tag coming later. Simply ignore any
10289 # tags that could later get eclipsed.
10292 if {[is_certain $t $origid]} {
10296 if {$tags eq $ctags} {
10297 set cached_dtags($origid) $tags
10302 set cached_dtags($origid) $tags
10304 set t3 [clock clicks -milliseconds]
10305 if {0 && $t3 - $t1 >= 100} {
10306 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10307 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10312 proc anctags {id} {
10313 global arcnos arcids arcout arcend arctags idtags allparents
10314 global growing cached_atags
10316 if {![info exists allparents($id)]} {
10319 set t1 [clock clicks -milliseconds]
10321 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10322 # part-way along an arc; check that arc first
10323 set a [lindex $arcnos($id) 0]
10324 if {$arctags($a) ne {}} {
10325 validate_arctags $a
10326 set i [lsearch -exact $arcids($a) $id]
10327 foreach t $arctags($a) {
10328 set j [lsearch -exact $arcids($a) $t]
10334 if {![info exists arcend($a)]} {
10338 if {[info exists idtags($id)]} {
10342 if {[info exists cached_atags($id)]} {
10343 return $cached_atags($id)
10347 set todo [list $id]
10351 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10352 set id [lindex $todo $i]
10354 set td [info exists hastaggeddescendent($id)]
10358 # ignore tags on starting node
10359 if {!$td && $i > 0} {
10360 if {[info exists idtags($id)]} {
10361 set tagloc($id) $id
10363 } elseif {[info exists cached_atags($id)]} {
10364 set tagloc($id) $cached_atags($id)
10368 foreach a $arcout($id) {
10369 if {!$td && $arctags($a) ne {}} {
10370 validate_arctags $a
10371 if {$arctags($a) ne {}} {
10372 lappend tagloc($id) [lindex $arctags($a) 0]
10375 if {![info exists arcend($a)]} continue
10377 if {$td || $arctags($a) ne {}} {
10378 set tomark [list $d]
10379 for {set j 0} {$j < [llength $tomark]} {incr j} {
10380 set dd [lindex $tomark $j]
10381 if {![info exists hastaggeddescendent($dd)]} {
10382 if {[info exists done($dd)]} {
10383 foreach b $arcout($dd) {
10384 if {[info exists arcend($b)]} {
10385 lappend tomark $arcend($b)
10388 if {[info exists tagloc($dd)]} {
10391 } elseif {[info exists queued($dd)]} {
10394 set hastaggeddescendent($dd) 1
10398 if {![info exists queued($d)]} {
10401 if {![info exists hastaggeddescendent($d)]} {
10407 set t2 [clock clicks -milliseconds]
10410 foreach id [array names tagloc] {
10411 if {![info exists hastaggeddescendent($id)]} {
10412 foreach t $tagloc($id) {
10413 if {[lsearch -exact $tags $t] < 0} {
10420 # remove tags that are ancestors of other tags
10421 for {set i 0} {$i < [llength $tags]} {incr i} {
10422 set a [lindex $tags $i]
10423 for {set j 0} {$j < $i} {incr j} {
10424 set b [lindex $tags $j]
10425 set r [anc_or_desc $a $b]
10427 set tags [lreplace $tags $j $j]
10430 } elseif {$r == 1} {
10431 set tags [lreplace $tags $i $i]
10438 if {[array names growing] ne {}} {
10439 # graph isn't finished, need to check if any tag could get
10440 # eclipsed by another tag coming later. Simply ignore any
10441 # tags that could later get eclipsed.
10444 if {[is_certain $origid $t]} {
10448 if {$tags eq $ctags} {
10449 set cached_atags($origid) $tags
10454 set cached_atags($origid) $tags
10456 set t3 [clock clicks -milliseconds]
10457 if {0 && $t3 - $t1 >= 100} {
10458 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10459 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10464 # Return the list of IDs that have heads that are descendents of id,
10465 # including id itself if it has a head.
10466 proc descheads {id} {
10467 global arcnos arcstart arcids archeads idheads cached_dheads
10470 if {![info exists allparents($id)]} {
10474 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10475 # part-way along an arc; check it first
10476 set a [lindex $arcnos($id) 0]
10477 if {$archeads($a) ne {}} {
10478 validate_archeads $a
10479 set i [lsearch -exact $arcids($a) $id]
10480 foreach t $archeads($a) {
10481 set j [lsearch -exact $arcids($a) $t]
10486 set id $arcstart($a)
10489 set todo [list $id]
10492 for {set i 0} {$i < [llength $todo]} {incr i} {
10493 set id [lindex $todo $i]
10494 if {[info exists cached_dheads($id)]} {
10495 set ret [concat $ret $cached_dheads($id)]
10497 if {[info exists idheads($id)]} {
10500 foreach a $arcnos($id) {
10501 if {$archeads($a) ne {}} {
10502 validate_archeads $a
10503 if {$archeads($a) ne {}} {
10504 set ret [concat $ret $archeads($a)]
10507 set d $arcstart($a)
10508 if {![info exists seen($d)]} {
10515 set ret [lsort -unique $ret]
10516 set cached_dheads($origid) $ret
10517 return [concat $ret $aret]
10520 proc addedtag {id} {
10521 global arcnos arcout cached_dtags cached_atags
10523 if {![info exists arcnos($id)]} return
10524 if {![info exists arcout($id)]} {
10525 recalcarc [lindex $arcnos($id) 0]
10527 catch {unset cached_dtags}
10528 catch {unset cached_atags}
10531 proc addedhead {hid head} {
10532 global arcnos arcout cached_dheads
10534 if {![info exists arcnos($hid)]} return
10535 if {![info exists arcout($hid)]} {
10536 recalcarc [lindex $arcnos($hid) 0]
10538 catch {unset cached_dheads}
10541 proc removedhead {hid head} {
10542 global cached_dheads
10544 catch {unset cached_dheads}
10547 proc movedhead {hid head} {
10548 global arcnos arcout cached_dheads
10550 if {![info exists arcnos($hid)]} return
10551 if {![info exists arcout($hid)]} {
10552 recalcarc [lindex $arcnos($hid) 0]
10554 catch {unset cached_dheads}
10557 proc changedrefs {} {
10558 global cached_dheads cached_dtags cached_atags
10559 global arctags archeads arcnos arcout idheads idtags
10561 foreach id [concat [array names idheads] [array names idtags]] {
10562 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10563 set a [lindex $arcnos($id) 0]
10564 if {![info exists donearc($a)]} {
10570 catch {unset cached_dtags}
10571 catch {unset cached_atags}
10572 catch {unset cached_dheads}
10575 proc rereadrefs {} {
10576 global idtags idheads idotherrefs mainheadid
10578 set refids [concat [array names idtags] \
10579 [array names idheads] [array names idotherrefs]]
10580 foreach id $refids {
10581 if {![info exists ref($id)]} {
10582 set ref($id) [listrefs $id]
10585 set oldmainhead $mainheadid
10588 set refids [lsort -unique [concat $refids [array names idtags] \
10589 [array names idheads] [array names idotherrefs]]]
10590 foreach id $refids {
10591 set v [listrefs $id]
10592 if {![info exists ref($id)] || $ref($id) != $v} {
10596 if {$oldmainhead ne $mainheadid} {
10597 redrawtags $oldmainhead
10598 redrawtags $mainheadid
10603 proc listrefs {id} {
10604 global idtags idheads idotherrefs
10607 if {[info exists idtags($id)]} {
10611 if {[info exists idheads($id)]} {
10612 set y $idheads($id)
10615 if {[info exists idotherrefs($id)]} {
10616 set z $idotherrefs($id)
10618 return [list $x $y $z]
10621 proc showtag {tag isnew} {
10622 global ctext tagcontents tagids linknum tagobjid
10625 addtohistory [list showtag $tag 0] savectextpos
10627 $ctext conf -state normal
10631 if {![info exists tagcontents($tag)]} {
10633 set tagcontents($tag) [exec git cat-file tag $tag]
10636 if {[info exists tagcontents($tag)]} {
10637 set text $tagcontents($tag)
10639 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10641 appendwithlinks $text {}
10642 maybe_scroll_ctext 1
10643 $ctext conf -state disabled
10655 if {[info exists gitktmpdir]} {
10656 catch {file delete -force $gitktmpdir}
10660 proc mkfontdisp {font top which} {
10661 global fontattr fontpref $font NS use_ttk
10663 set fontpref($font) [set $font]
10664 ${NS}::button $top.${font}but -text $which \
10665 -command [list choosefont $font $which]
10666 ${NS}::label $top.$font -relief flat -font $font \
10667 -text $fontattr($font,family) -justify left
10668 grid x $top.${font}but $top.$font -sticky w
10671 proc choosefont {font which} {
10672 global fontparam fontlist fonttop fontattr
10675 set fontparam(which) $which
10676 set fontparam(font) $font
10677 set fontparam(family) [font actual $font -family]
10678 set fontparam(size) $fontattr($font,size)
10679 set fontparam(weight) $fontattr($font,weight)
10680 set fontparam(slant) $fontattr($font,slant)
10683 if {![winfo exists $top]} {
10685 eval font config sample [font actual $font]
10687 make_transient $top $prefstop
10688 wm title $top [mc "Gitk font chooser"]
10689 ${NS}::label $top.l -textvariable fontparam(which)
10690 pack $top.l -side top
10691 set fontlist [lsort [font families]]
10692 ${NS}::frame $top.f
10693 listbox $top.f.fam -listvariable fontlist \
10694 -yscrollcommand [list $top.f.sb set]
10695 bind $top.f.fam <<ListboxSelect>> selfontfam
10696 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10697 pack $top.f.sb -side right -fill y
10698 pack $top.f.fam -side left -fill both -expand 1
10699 pack $top.f -side top -fill both -expand 1
10700 ${NS}::frame $top.g
10701 spinbox $top.g.size -from 4 -to 40 -width 4 \
10702 -textvariable fontparam(size) \
10703 -validatecommand {string is integer -strict %s}
10704 checkbutton $top.g.bold -padx 5 \
10705 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10706 -variable fontparam(weight) -onvalue bold -offvalue normal
10707 checkbutton $top.g.ital -padx 5 \
10708 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10709 -variable fontparam(slant) -onvalue italic -offvalue roman
10710 pack $top.g.size $top.g.bold $top.g.ital -side left
10711 pack $top.g -side top
10712 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10714 $top.c create text 100 25 -anchor center -text $which -font sample \
10715 -fill black -tags text
10716 bind $top.c <Configure> [list centertext $top.c]
10717 pack $top.c -side top -fill x
10718 ${NS}::frame $top.buts
10719 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10720 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10721 bind $top <Key-Return> fontok
10722 bind $top <Key-Escape> fontcan
10723 grid $top.buts.ok $top.buts.can
10724 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10725 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10726 pack $top.buts -side bottom -fill x
10727 trace add variable fontparam write chg_fontparam
10730 $top.c itemconf text -text $which
10732 set i [lsearch -exact $fontlist $fontparam(family)]
10734 $top.f.fam selection set $i
10739 proc centertext {w} {
10740 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
10744 global fontparam fontpref prefstop
10746 set f $fontparam(font)
10747 set fontpref($f) [list $fontparam(family) $fontparam(size)]
10748 if {$fontparam(weight) eq "bold"} {
10749 lappend fontpref($f) "bold"
10751 if {$fontparam(slant) eq "italic"} {
10752 lappend fontpref($f) "italic"
10754 set w $prefstop.notebook.fonts.$f
10755 $w conf -text $fontparam(family) -font $fontpref($f)
10761 global fonttop fontparam
10763 if {[info exists fonttop]} {
10764 catch {destroy $fonttop}
10765 catch {font delete sample}
10771 if {[package vsatisfies [package provide Tk] 8.6]} {
10772 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
10773 # function to make use of it.
10774 proc choosefont {font which} {
10775 tk fontchooser configure -title $which -font $font \
10776 -command [list on_choosefont $font $which]
10777 tk fontchooser show
10779 proc on_choosefont {font which newfont} {
10781 puts stderr "$font $newfont"
10782 array set f [font actual $newfont]
10783 set fontparam(which) $which
10784 set fontparam(font) $font
10785 set fontparam(family) $f(-family)
10786 set fontparam(size) $f(-size)
10787 set fontparam(weight) $f(-weight)
10788 set fontparam(slant) $f(-slant)
10793 proc selfontfam {} {
10794 global fonttop fontparam
10796 set i [$fonttop.f.fam curselection]
10798 set fontparam(family) [$fonttop.f.fam get $i]
10802 proc chg_fontparam {v sub op} {
10805 font config sample -$sub $fontparam($sub)
10808 # Create a property sheet tab page
10809 proc create_prefs_page {w} {
10811 set parent [join [lrange [split $w .] 0 end-1] .]
10812 if {[winfo class $parent] eq "TNotebook"} {
10815 ${NS}::labelframe $w
10819 proc prefspage_general {notebook} {
10820 global NS maxwidth maxgraphpct showneartags showlocalchanges
10821 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
10822 global hideremotes want_ttk have_ttk
10824 set page [create_prefs_page $notebook.general]
10826 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
10827 grid $page.ldisp - -sticky w -pady 10
10828 ${NS}::label $page.spacer -text " "
10829 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
10830 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
10831 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
10832 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
10833 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
10834 grid x $page.maxpctl $page.maxpct -sticky w
10835 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
10836 -variable showlocalchanges
10837 grid x $page.showlocal -sticky w
10838 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
10839 -variable autoselect
10840 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
10841 grid x $page.autoselect $page.autosellen -sticky w
10842 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
10843 -variable hideremotes
10844 grid x $page.hideremotes -sticky w
10846 ${NS}::label $page.ddisp -text [mc "Diff display options"]
10847 grid $page.ddisp - -sticky w -pady 10
10848 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
10849 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
10850 grid x $page.tabstopl $page.tabstop -sticky w
10851 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags"] \
10852 -variable showneartags
10853 grid x $page.ntag -sticky w
10854 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
10855 -variable limitdiffs
10856 grid x $page.ldiff -sticky w
10857 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
10858 -variable perfile_attrs
10859 grid x $page.lattr -sticky w
10861 ${NS}::entry $page.extdifft -textvariable extdifftool
10862 ${NS}::frame $page.extdifff
10863 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
10864 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
10865 pack $page.extdifff.l $page.extdifff.b -side left
10866 pack configure $page.extdifff.l -padx 10
10867 grid x $page.extdifff $page.extdifft -sticky ew
10869 ${NS}::label $page.lgen -text [mc "General options"]
10870 grid $page.lgen - -sticky w -pady 10
10871 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
10872 -text [mc "Use themed widgets"]
10874 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
10876 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
10878 grid x $page.want_ttk $page.ttk_note -sticky w
10882 proc prefspage_colors {notebook} {
10883 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
10885 set page [create_prefs_page $notebook.colors]
10887 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
10888 grid $page.cdisp - -sticky w -pady 10
10889 label $page.ui -padx 40 -relief sunk -background $uicolor
10890 ${NS}::button $page.uibut -text [mc "Interface"] \
10891 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
10892 grid x $page.uibut $page.ui -sticky w
10893 label $page.bg -padx 40 -relief sunk -background $bgcolor
10894 ${NS}::button $page.bgbut -text [mc "Background"] \
10895 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
10896 grid x $page.bgbut $page.bg -sticky w
10897 label $page.fg -padx 40 -relief sunk -background $fgcolor
10898 ${NS}::button $page.fgbut -text [mc "Foreground"] \
10899 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
10900 grid x $page.fgbut $page.fg -sticky w
10901 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
10902 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
10903 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
10904 [list $ctext tag conf d0 -foreground]]
10905 grid x $page.diffoldbut $page.diffold -sticky w
10906 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
10907 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
10908 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
10909 [list $ctext tag conf dresult -foreground]]
10910 grid x $page.diffnewbut $page.diffnew -sticky w
10911 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
10912 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
10913 -command [list choosecolor diffcolors 2 $page.hunksep \
10914 [mc "diff hunk header"] \
10915 [list $ctext tag conf hunksep -foreground]]
10916 grid x $page.hunksepbut $page.hunksep -sticky w
10917 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
10918 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
10919 -command [list choosecolor markbgcolor {} $page.markbgsep \
10920 [mc "marked line background"] \
10921 [list $ctext tag conf omark -background]]
10922 grid x $page.markbgbut $page.markbgsep -sticky w
10923 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
10924 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
10925 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
10926 grid x $page.selbgbut $page.selbgsep -sticky w
10930 proc prefspage_fonts {notebook} {
10932 set page [create_prefs_page $notebook.fonts]
10933 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
10934 grid $page.cfont - -sticky w -pady 10
10935 mkfontdisp mainfont $page [mc "Main font"]
10936 mkfontdisp textfont $page [mc "Diff display font"]
10937 mkfontdisp uifont $page [mc "User interface font"]
10942 global maxwidth maxgraphpct use_ttk NS
10943 global oldprefs prefstop showneartags showlocalchanges
10944 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
10945 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
10946 global hideremotes want_ttk have_ttk
10950 if {[winfo exists $top]} {
10954 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
10955 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
10956 set oldprefs($v) [set $v]
10959 wm title $top [mc "Gitk preferences"]
10960 make_transient $top .
10962 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
10963 set notebook [ttk::notebook $top.notebook]
10965 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
10968 lappend pages [prefspage_general $notebook] [mc "General"]
10969 lappend pages [prefspage_colors $notebook] [mc "Colors"]
10970 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
10971 foreach {page title} $pages {
10972 if {$use_notebook} {
10973 $notebook add $page -text $title
10975 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
10976 -text $title -command [list raise $page]]
10977 $page configure -text $title
10978 grid $btn -row 0 -column [incr col] -sticky w
10979 grid $page -row 1 -column 0 -sticky news -columnspan 100
10983 if {!$use_notebook} {
10984 grid columnconfigure $notebook 0 -weight 1
10985 grid rowconfigure $notebook 1 -weight 1
10986 raise [lindex $pages 0]
10989 grid $notebook -sticky news -padx 2 -pady 2
10990 grid rowconfigure $top 0 -weight 1
10991 grid columnconfigure $top 0 -weight 1
10993 ${NS}::frame $top.buts
10994 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
10995 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
10996 bind $top <Key-Return> prefsok
10997 bind $top <Key-Escape> prefscan
10998 grid $top.buts.ok $top.buts.can
10999 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11000 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11001 grid $top.buts - - -pady 10 -sticky ew
11002 grid columnconfigure $top 2 -weight 1
11003 bind $top <Visibility> [list focus $top.buts.ok]
11006 proc choose_extdiff {} {
11009 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11011 set extdifftool $prog
11015 proc choosecolor {v vi w x cmd} {
11018 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11019 -title [mc "Gitk: choose color for %s" $x]]
11020 if {$c eq {}} return
11021 $w conf -background $c
11026 proc setselbg {c} {
11027 global bglist cflist
11028 foreach w $bglist {
11029 $w configure -selectbackground $c
11031 $cflist tag configure highlight \
11032 -background [$cflist cget -selectbackground]
11033 allcanvs itemconf secsel -fill $c
11036 # This sets the background color and the color scheme for the whole UI.
11037 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11038 # if we don't specify one ourselves, which makes the checkbuttons and
11039 # radiobuttons look bad. This chooses white for selectColor if the
11040 # background color is light, or black if it is dark.
11042 if {[tk windowingsystem] eq "win32"} { return }
11043 set bg [winfo rgb . $c]
11045 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11048 tk_setPalette background $c selectColor $selc
11054 foreach w $bglist {
11055 $w conf -background $c
11062 foreach w $fglist {
11063 $w conf -foreground $c
11065 allcanvs itemconf text -fill $c
11066 $canv itemconf circle -outline $c
11067 $canv itemconf markid -outline $c
11071 global oldprefs prefstop
11073 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11074 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11076 set $v $oldprefs($v)
11078 catch {destroy $prefstop}
11084 global maxwidth maxgraphpct
11085 global oldprefs prefstop showneartags showlocalchanges
11086 global fontpref mainfont textfont uifont
11087 global limitdiffs treediffs perfile_attrs
11090 catch {destroy $prefstop}
11094 if {$mainfont ne $fontpref(mainfont)} {
11095 set mainfont $fontpref(mainfont)
11096 parsefont mainfont $mainfont
11097 eval font configure mainfont [fontflags mainfont]
11098 eval font configure mainfontbold [fontflags mainfont 1]
11102 if {$textfont ne $fontpref(textfont)} {
11103 set textfont $fontpref(textfont)
11104 parsefont textfont $textfont
11105 eval font configure textfont [fontflags textfont]
11106 eval font configure textfontbold [fontflags textfont 1]
11108 if {$uifont ne $fontpref(uifont)} {
11109 set uifont $fontpref(uifont)
11110 parsefont uifont $uifont
11111 eval font configure uifont [fontflags uifont]
11114 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11115 if {$showlocalchanges} {
11121 if {$limitdiffs != $oldprefs(limitdiffs) ||
11122 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11123 # treediffs elements are limited by path;
11124 # won't have encodings cached if perfile_attrs was just turned on
11125 catch {unset treediffs}
11127 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11128 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11130 } elseif {$showneartags != $oldprefs(showneartags) ||
11131 $limitdiffs != $oldprefs(limitdiffs)} {
11134 if {$hideremotes != $oldprefs(hideremotes)} {
11139 proc formatdate {d} {
11140 global datetimeformat
11142 set d [clock format [lindex $d 0] -format $datetimeformat]
11147 # This list of encoding names and aliases is distilled from
11148 # http://www.iana.org/assignments/character-sets.
11149 # Not all of them are supported by Tcl.
11150 set encoding_aliases {
11151 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11152 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11153 { ISO-10646-UTF-1 csISO10646UTF1 }
11154 { ISO_646.basic:1983 ref csISO646basic1983 }
11155 { INVARIANT csINVARIANT }
11156 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11157 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11158 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11159 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11160 { NATS-DANO iso-ir-9-1 csNATSDANO }
11161 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11162 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11163 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11164 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11165 { ISO-2022-KR csISO2022KR }
11167 { ISO-2022-JP csISO2022JP }
11168 { ISO-2022-JP-2 csISO2022JP2 }
11169 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11170 csISO13JISC6220jp }
11171 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11172 { IT iso-ir-15 ISO646-IT csISO15Italian }
11173 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11174 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11175 { greek7-old iso-ir-18 csISO18Greek7Old }
11176 { latin-greek iso-ir-19 csISO19LatinGreek }
11177 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11178 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11179 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11180 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11181 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11182 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11183 { INIS iso-ir-49 csISO49INIS }
11184 { INIS-8 iso-ir-50 csISO50INIS8 }
11185 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11186 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11187 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11188 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11189 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11190 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11191 csISO60Norwegian1 }
11192 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11193 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11194 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11195 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11196 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11197 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11198 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11199 { greek7 iso-ir-88 csISO88Greek7 }
11200 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11201 { iso-ir-90 csISO90 }
11202 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11203 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11204 csISO92JISC62991984b }
11205 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11206 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11207 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11208 csISO95JIS62291984handadd }
11209 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11210 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11211 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11212 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11213 CP819 csISOLatin1 }
11214 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11215 { T.61-7bit iso-ir-102 csISO102T617bit }
11216 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11217 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11218 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11219 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11220 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11221 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11222 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11223 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11224 arabic csISOLatinArabic }
11225 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11226 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11227 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11228 greek greek8 csISOLatinGreek }
11229 { T.101-G2 iso-ir-128 csISO128T101G2 }
11230 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11232 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11233 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11234 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11235 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11236 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11237 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11238 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11239 csISOLatinCyrillic }
11240 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11241 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11242 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11243 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11244 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11245 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11246 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11247 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11248 { ISO_10367-box iso-ir-155 csISO10367Box }
11249 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11250 { latin-lap lap iso-ir-158 csISO158Lap }
11251 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11252 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11255 { JIS_X0201 X0201 csHalfWidthKatakana }
11256 { KSC5636 ISO646-KR csKSC5636 }
11257 { ISO-10646-UCS-2 csUnicode }
11258 { ISO-10646-UCS-4 csUCS4 }
11259 { DEC-MCS dec csDECMCS }
11260 { hp-roman8 roman8 r8 csHPRoman8 }
11261 { macintosh mac csMacintosh }
11262 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11264 { IBM038 EBCDIC-INT cp038 csIBM038 }
11265 { IBM273 CP273 csIBM273 }
11266 { IBM274 EBCDIC-BE CP274 csIBM274 }
11267 { IBM275 EBCDIC-BR cp275 csIBM275 }
11268 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11269 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11270 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11271 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11272 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11273 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11274 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11275 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11276 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11277 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11278 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11279 { IBM437 cp437 437 csPC8CodePage437 }
11280 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11281 { IBM775 cp775 csPC775Baltic }
11282 { IBM850 cp850 850 csPC850Multilingual }
11283 { IBM851 cp851 851 csIBM851 }
11284 { IBM852 cp852 852 csPCp852 }
11285 { IBM855 cp855 855 csIBM855 }
11286 { IBM857 cp857 857 csIBM857 }
11287 { IBM860 cp860 860 csIBM860 }
11288 { IBM861 cp861 861 cp-is csIBM861 }
11289 { IBM862 cp862 862 csPC862LatinHebrew }
11290 { IBM863 cp863 863 csIBM863 }
11291 { IBM864 cp864 csIBM864 }
11292 { IBM865 cp865 865 csIBM865 }
11293 { IBM866 cp866 866 csIBM866 }
11294 { IBM868 CP868 cp-ar csIBM868 }
11295 { IBM869 cp869 869 cp-gr csIBM869 }
11296 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11297 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11298 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11299 { IBM891 cp891 csIBM891 }
11300 { IBM903 cp903 csIBM903 }
11301 { IBM904 cp904 904 csIBBM904 }
11302 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11303 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11304 { IBM1026 CP1026 csIBM1026 }
11305 { EBCDIC-AT-DE csIBMEBCDICATDE }
11306 { EBCDIC-AT-DE-A csEBCDICATDEA }
11307 { EBCDIC-CA-FR csEBCDICCAFR }
11308 { EBCDIC-DK-NO csEBCDICDKNO }
11309 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11310 { EBCDIC-FI-SE csEBCDICFISE }
11311 { EBCDIC-FI-SE-A csEBCDICFISEA }
11312 { EBCDIC-FR csEBCDICFR }
11313 { EBCDIC-IT csEBCDICIT }
11314 { EBCDIC-PT csEBCDICPT }
11315 { EBCDIC-ES csEBCDICES }
11316 { EBCDIC-ES-A csEBCDICESA }
11317 { EBCDIC-ES-S csEBCDICESS }
11318 { EBCDIC-UK csEBCDICUK }
11319 { EBCDIC-US csEBCDICUS }
11320 { UNKNOWN-8BIT csUnknown8BiT }
11321 { MNEMONIC csMnemonic }
11323 { VISCII csVISCII }
11326 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11327 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11328 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11329 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11330 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11331 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11332 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11333 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11334 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11335 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11336 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11337 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11338 { IBM1047 IBM-1047 }
11339 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11340 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11341 { UNICODE-1-1 csUnicode11 }
11342 { CESU-8 csCESU-8 }
11343 { BOCU-1 csBOCU-1 }
11344 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11345 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11347 { ISO-8859-15 ISO_8859-15 Latin-9 }
11348 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11349 { GBK CP936 MS936 windows-936 }
11350 { JIS_Encoding csJISEncoding }
11351 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11352 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11354 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11355 { ISO-10646-UCS-Basic csUnicodeASCII }
11356 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11357 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11358 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11359 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11360 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11361 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11362 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11363 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11364 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11365 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11366 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11367 { Ventura-US csVenturaUS }
11368 { Ventura-International csVenturaInternational }
11369 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11370 { PC8-Turkish csPC8Turkish }
11371 { IBM-Symbols csIBMSymbols }
11372 { IBM-Thai csIBMThai }
11373 { HP-Legal csHPLegal }
11374 { HP-Pi-font csHPPiFont }
11375 { HP-Math8 csHPMath8 }
11376 { Adobe-Symbol-Encoding csHPPSMath }
11377 { HP-DeskTop csHPDesktop }
11378 { Ventura-Math csVenturaMath }
11379 { Microsoft-Publishing csMicrosoftPublishing }
11380 { Windows-31J csWindows31J }
11381 { GB2312 csGB2312 }
11385 proc tcl_encoding {enc} {
11386 global encoding_aliases tcl_encoding_cache
11387 if {[info exists tcl_encoding_cache($enc)]} {
11388 return $tcl_encoding_cache($enc)
11390 set names [encoding names]
11391 set lcnames [string tolower $names]
11392 set enc [string tolower $enc]
11393 set i [lsearch -exact $lcnames $enc]
11395 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11396 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11397 set i [lsearch -exact $lcnames $encx]
11401 foreach l $encoding_aliases {
11402 set ll [string tolower $l]
11403 if {[lsearch -exact $ll $enc] < 0} continue
11404 # look through the aliases for one that tcl knows about
11406 set i [lsearch -exact $lcnames $e]
11408 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11409 set i [lsearch -exact $lcnames $ex]
11419 set tclenc [lindex $names $i]
11421 set tcl_encoding_cache($enc) $tclenc
11425 proc gitattr {path attr default} {
11426 global path_attr_cache
11427 if {[info exists path_attr_cache($attr,$path)]} {
11428 set r $path_attr_cache($attr,$path)
11430 set r "unspecified"
11431 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11432 regexp "(.*): $attr: (.*)" $line m f r
11434 set path_attr_cache($attr,$path) $r
11436 if {$r eq "unspecified"} {
11442 proc cache_gitattr {attr pathlist} {
11443 global path_attr_cache
11445 foreach path $pathlist {
11446 if {![info exists path_attr_cache($attr,$path)]} {
11447 lappend newlist $path
11451 if {[tk windowingsystem] == "win32"} {
11452 # windows has a 32k limit on the arguments to a command...
11455 while {$newlist ne {}} {
11456 set head [lrange $newlist 0 [expr {$lim - 1}]]
11457 set newlist [lrange $newlist $lim end]
11458 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11459 foreach row [split $rlist "\n"] {
11460 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11461 if {[string index $path 0] eq "\""} {
11462 set path [encoding convertfrom [lindex $path 0]]
11464 set path_attr_cache($attr,$path) $value
11471 proc get_path_encoding {path} {
11472 global gui_encoding perfile_attrs
11473 set tcl_enc $gui_encoding
11474 if {$path ne {} && $perfile_attrs} {
11475 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11483 # First check that Tcl/Tk is recent enough
11484 if {[catch {package require Tk 8.4} err]} {
11485 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11486 Gitk requires at least Tcl/Tk 8.4." list
11491 set wrcomcmd "git diff-tree --stdin -p --pretty"
11495 set gitencoding [exec git config --get i18n.commitencoding]
11498 set gitencoding [exec git config --get i18n.logoutputencoding]
11500 if {$gitencoding == ""} {
11501 set gitencoding "utf-8"
11503 set tclencoding [tcl_encoding $gitencoding]
11504 if {$tclencoding == {}} {
11505 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11508 set gui_encoding [encoding system]
11510 set enc [exec git config --get gui.encoding]
11512 set tclenc [tcl_encoding $enc]
11513 if {$tclenc ne {}} {
11514 set gui_encoding $tclenc
11516 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11521 if {[tk windowingsystem] eq "aqua"} {
11522 set mainfont {{Lucida Grande} 9}
11523 set textfont {Monaco 9}
11524 set uifont {{Lucida Grande} 9 bold}
11526 set mainfont {Helvetica 9}
11527 set textfont {Courier 9}
11528 set uifont {Helvetica 9 bold}
11531 set findmergefiles 0
11539 set cmitmode "patch"
11540 set wrapcomment "none"
11545 set showlocalchanges 1
11547 set datetimeformat "%Y-%m-%d %H:%M:%S"
11550 set perfile_attrs 0
11553 if {[tk windowingsystem] eq "aqua"} {
11554 set extdifftool "opendiff"
11556 set extdifftool "meld"
11559 set colors {green red blue magenta darkgrey brown orange}
11560 if {[tk windowingsystem] eq "win32"} {
11561 set uicolor SystemButtonFace
11562 set bgcolor SystemWindow
11563 set fgcolor SystemButtonText
11564 set selectbgcolor SystemHighlight
11569 set selectbgcolor gray85
11571 set diffcolors {red "#00a000" blue}
11575 set markbgcolor "#e0e0ff"
11577 set circlecolors {white blue gray blue blue}
11579 # button for popping up context menus
11580 if {[tk windowingsystem] eq "aqua"} {
11581 set ctxbut <Button-2>
11583 set ctxbut <Button-3>
11586 ## For msgcat loading, first locate the installation location.
11587 if { [info exists ::env(GITK_MSGSDIR)] } {
11588 ## Msgsdir was manually set in the environment.
11589 set gitk_msgsdir $::env(GITK_MSGSDIR)
11591 ## Let's guess the prefix from argv0.
11592 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11593 set gitk_libdir [file join $gitk_prefix share gitk lib]
11594 set gitk_msgsdir [file join $gitk_libdir msgs]
11598 ## Internationalization (i18n) through msgcat and gettext. See
11599 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11600 package require msgcat
11601 namespace import ::msgcat::mc
11602 ## And eventually load the actual message catalog
11603 ::msgcat::mcload $gitk_msgsdir
11605 catch {source ~/.gitk}
11607 parsefont mainfont $mainfont
11608 eval font create mainfont [fontflags mainfont]
11609 eval font create mainfontbold [fontflags mainfont 1]
11611 parsefont textfont $textfont
11612 eval font create textfont [fontflags textfont]
11613 eval font create textfontbold [fontflags textfont 1]
11615 parsefont uifont $uifont
11616 eval font create uifont [fontflags uifont]
11622 # check that we can find a .git directory somewhere...
11623 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
11624 show_error {} . [mc "Cannot find a git repository here."]
11629 set selectheadid {}
11632 set cmdline_files {}
11634 set revtreeargscmd {}
11635 foreach arg $argv {
11636 switch -glob -- $arg {
11639 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11642 "--select-commit=*" {
11643 set selecthead [string range $arg 16 end]
11646 set revtreeargscmd [string range $arg 10 end]
11649 lappend revtreeargs $arg
11655 if {$selecthead eq "HEAD"} {
11659 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11660 # no -- on command line, but some arguments (other than --argscmd)
11662 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11663 set cmdline_files [split $f "\n"]
11664 set n [llength $cmdline_files]
11665 set revtreeargs [lrange $revtreeargs 0 end-$n]
11666 # Unfortunately git rev-parse doesn't produce an error when
11667 # something is both a revision and a filename. To be consistent
11668 # with git log and git rev-list, check revtreeargs for filenames.
11669 foreach arg $revtreeargs {
11670 if {[file exists $arg]} {
11671 show_error {} . [mc "Ambiguous argument '%s': both revision\
11672 and filename" $arg]
11677 # unfortunately we get both stdout and stderr in $err,
11678 # so look for "fatal:".
11679 set i [string first "fatal:" $err]
11681 set err [string range $err [expr {$i + 6}] end]
11683 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
11688 set nullid "0000000000000000000000000000000000000000"
11689 set nullid2 "0000000000000000000000000000000000000001"
11690 set nullfile "/dev/null"
11692 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
11693 if {![info exists have_ttk]} {
11694 set have_ttk [llength [info commands ::ttk::style]]
11696 set use_ttk [expr {$have_ttk && $want_ttk}]
11697 set NS [expr {$use_ttk ? "ttk" : ""}]
11699 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
11702 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
11703 set show_notes "--show-notes"
11711 set highlight_paths {}
11713 set searchdirn -forwards
11716 set diffelide {0 0}
11717 set markingmatches 0
11718 set linkentercount 0
11719 set need_redisplay 0
11726 set selectedhlview [mc "None"]
11727 set highlight_related [mc "None"]
11728 set highlight_files {}
11729 set viewfiles(0) {}
11732 set viewargscmd(0) {}
11734 set selectedline {}
11742 set hasworktree [hasworktree]
11744 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
11745 set cdup [exec git rev-parse --show-cdup]
11747 set worktree [exec git rev-parse --show-toplevel]
11751 image create photo gitlogo -width 16 -height 16
11753 image create photo gitlogominus -width 4 -height 2
11754 gitlogominus put #C00000 -to 0 0 4 2
11755 gitlogo copy gitlogominus -to 1 5
11756 gitlogo copy gitlogominus -to 6 5
11757 gitlogo copy gitlogominus -to 11 5
11758 image delete gitlogominus
11760 image create photo gitlogoplus -width 4 -height 4
11761 gitlogoplus put #008000 -to 1 0 3 4
11762 gitlogoplus put #008000 -to 0 1 4 3
11763 gitlogo copy gitlogoplus -to 1 9
11764 gitlogo copy gitlogoplus -to 6 9
11765 gitlogo copy gitlogoplus -to 11 9
11766 image delete gitlogoplus
11768 image create photo gitlogo32 -width 32 -height 32
11769 gitlogo32 copy gitlogo -zoom 2 2
11771 wm iconphoto . -default gitlogo gitlogo32
11773 # wait for the window to become visible
11774 tkwait visibility .
11775 wm title . "[file tail $argv0]: [file tail [pwd]]"
11779 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
11780 # create a view for the files/dirs specified on the command line
11784 set viewname(1) [mc "Command line"]
11785 set viewfiles(1) $cmdline_files
11786 set viewargs(1) $revtreeargs
11787 set viewargscmd(1) $revtreeargscmd
11791 .bar.view entryconf [mca "Edit view..."] -state normal
11792 .bar.view entryconf [mca "Delete view"] -state normal
11795 if {[info exists permviews]} {
11796 foreach v $permviews {
11799 set viewname($n) [lindex $v 0]
11800 set viewfiles($n) [lindex $v 1]
11801 set viewargs($n) [lindex $v 2]
11802 set viewargscmd($n) [lindex $v 3]
11808 if {[tk windowingsystem] eq "win32"} {
11816 # indent-tabs-mode: t