2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2011 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 set n
[file normalize
$gitdir]
20 if {[string match
"*/.git" $n]} {
21 set n
[string range
$n 0 end-5
]
28 if {[info exists _gitworktree
]} {
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
37 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
38 if {$_gitworktree eq
""} {
39 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
49 # run before X event handlers, so reading from a fast source can
50 # make the GUI completely unresponsive.
52 global isonrunq runq currunq
55 if {[info exists isonrunq
($script)]} return
56 if {$runq eq
{} && ![info exists currunq
]} {
59 lappend runq
[list
{} $script]
60 set isonrunq
($script) 1
63 proc filerun
{fd
script} {
64 fileevent
$fd readable
[list filereadable
$fd $script]
67 proc filereadable
{fd
script} {
70 fileevent
$fd readable
{}
71 if {$runq eq
{} && ![info exists currunq
]} {
74 lappend runq
[list
$fd $script]
80 for {set i
0} {$i < [llength
$runq]} {} {
81 if {[lindex
$runq $i 0] eq
$fd} {
82 set runq
[lreplace
$runq $i $i]
90 global isonrunq runq currunq
92 set tstart
[clock clicks
-milliseconds]
94 while {[llength
$runq] > 0} {
95 set fd
[lindex
$runq 0 0]
96 set script [lindex
$runq 0 1]
97 set currunq
[lindex
$runq 0]
98 set runq
[lrange
$runq 1 end
]
99 set repeat
[eval $script]
101 set t1
[clock clicks
-milliseconds]
102 set t
[expr {$t1 - $t0}]
103 if {$repeat ne
{} && $repeat} {
104 if {$fd eq
{} ||
$repeat == 2} {
105 # script returns 1 if it wants to be readded
106 # file readers return 2 if they could do more straight away
107 lappend runq
[list
$fd $script]
109 fileevent
$fd readable
[list filereadable
$fd $script]
111 } elseif
{$fd eq
{}} {
112 unset isonrunq
($script)
115 if {$t1 - $tstart >= 80} break
122 proc reg_instance
{fd
} {
123 global commfd leftover loginstance
125 set i
[incr loginstance
]
131 proc unmerged_files
{files
} {
134 # find the list of unmerged files
138 set fd
[open
"| git ls-files -u" r
]
140 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
149 if {$files eq {} || [path_filter $files $fname]} {
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
160 global worddiff git_version
164 set vinlinediff($n) 0
169 set origargs $arglist
173 foreach arg $arglist {
180 switch -glob -- $arg {
184 # remove from origargs in case we hit an unknown option
185 set origargs [lreplace $origargs $i $i]
189 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
190 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
191 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
192 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
193 "--ignore-space-change" - "-U*" - "--unified=*" {
194 # These request or affect diff output, which we don't want.
195 # Some could be used to set our defaults for diff display.
196 lappend diffargs
$arg
198 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
199 "--name-only" - "--name-status" - "--color" -
200 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
201 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
202 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
203 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
204 "--objects" - "--objects-edge" - "--reverse" {
205 # These cause our parsing of git log's output to fail, or else
206 # they're options we want to set ourselves, so ignore them.
208 "--color-words*" - "--word-diff=color" {
209 # These trigger a word diff in the console interface,
210 # so help the user by enabling our own support
211 if {[package vcompare
$git_version "1.7.2"] >= 0} {
212 set worddiff
[mc
"Color words"]
216 if {[package vcompare
$git_version "1.7.2"] >= 0} {
217 set worddiff
[mc
"Markup words"]
220 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
221 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
222 "--full-history" - "--dense" - "--sparse" -
223 "--follow" - "--left-right" - "--encoding=*" {
224 # These are harmless, and some are even useful
227 "--diff-filter=*" - "--no-merges" - "--unpacked" -
228 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
229 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
230 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
231 "--remove-empty" - "--first-parent" - "--cherry-pick" -
232 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
233 "--simplify-by-decoration" {
234 # These mean that we get a subset of the commits
239 # This appears to be the only one that has a value as a
240 # separate word following it
250 # git rev-parse doesn't understand --merge
251 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
253 "--no-replace-objects" {
254 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
257 # Other flag arguments including -<n>
258 if {[string is digit
-strict [string range
$arg 1 end
]]} {
261 # a flag argument that we don't recognize;
262 # that means we can't optimize
268 # Non-flag arguments specify commits or ranges of commits
269 if {[string match
"*...*" $arg]} {
270 lappend revargs
--gitk-symmetric-diff-marker
276 set vdflags
($n) $diffargs
277 set vflags
($n) $glflags
278 set vrevs
($n) $revargs
279 set vfiltered
($n) $filtered
280 set vorigargs
($n) $origargs
284 proc parseviewrevs
{view revs
} {
285 global vposids vnegids
290 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
291 # we get stdout followed by stderr in $err
292 # for an unknown rev, git rev-parse echoes it and then errors out
293 set errlines
[split $err "\n"]
295 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
296 set line
[lindex
$errlines $l]
297 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
298 if {[string match
"fatal:*" $line]} {
299 if {[string match
"fatal: ambiguous argument*" $line]
301 if {[llength
$badrev] == 1} {
302 set err
"unknown revision $badrev"
304 set err
"unknown revisions: [join $badrev ", "]"
307 set err
[join [lrange
$errlines $l end
] "\n"]
314 error_popup
"[mc "Error parsing revisions
:"] $err"
321 foreach id
[split $ids "\n"] {
322 if {$id eq
"--gitk-symmetric-diff-marker"} {
324 } elseif
{[string match
"^*" $id]} {
331 lappend neg
[string range
$id 1 end
]
336 lset ret end
$id...
[lindex
$ret end
]
342 set vposids
($view) $pos
343 set vnegids
($view) $neg
347 # Start off a git log process and arrange to read its output
348 proc start_rev_list
{view
} {
349 global startmsecs commitidx viewcomplete curview
351 global viewargs viewargscmd viewfiles vfilelimit
352 global showlocalchanges
353 global viewactive viewinstances vmergeonly
354 global mainheadid viewmainheadid viewmainheadid_orig
355 global vcanopt vflags vrevs vorigargs
358 set startmsecs
[clock clicks
-milliseconds]
359 set commitidx
($view) 0
360 # these are set this way for the error exits
361 set viewcomplete
($view) 1
362 set viewactive
($view) 0
365 set args
$viewargs($view)
366 if {$viewargscmd($view) ne
{}} {
368 set str
[exec sh
-c $viewargscmd($view)]
370 error_popup
"[mc "Error executing
--argscmd command:"] $err"
373 set args
[concat
$args [split $str "\n"]]
375 set vcanopt
($view) [parseviewargs
$view $args]
377 set files
$viewfiles($view)
378 if {$vmergeonly($view)} {
379 set files
[unmerged_files
$files]
382 if {$nr_unmerged == 0} {
383 error_popup
[mc
"No files selected: --merge specified but\
384 no files are unmerged."]
386 error_popup
[mc
"No files selected: --merge specified but\
387 no unmerged files are within file limit."]
392 set vfilelimit
($view) $files
394 if {$vcanopt($view)} {
395 set revs
[parseviewrevs
$view $vrevs($view)]
399 set args
[concat
$vflags($view) $revs]
401 set args
$vorigargs($view)
405 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
406 --parents --boundary $args "--" $files] r
]
408 error_popup
"[mc "Error executing git log
:"] $err"
411 set i
[reg_instance
$fd]
412 set viewinstances
($view) [list
$i]
413 set viewmainheadid
($view) $mainheadid
414 set viewmainheadid_orig
($view) $mainheadid
415 if {$files ne
{} && $mainheadid ne
{}} {
416 get_viewmainhead
$view
418 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
419 interestedin
$viewmainheadid($view) dodiffindex
421 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
422 if {$tclencoding != {}} {
423 fconfigure
$fd -encoding $tclencoding
425 filerun
$fd [list getcommitlines
$fd $i $view 0]
426 nowbusy
$view [mc
"Reading"]
427 set viewcomplete
($view) 0
428 set viewactive
($view) 1
432 proc stop_instance
{inst
} {
433 global commfd leftover
435 set fd
$commfd($inst)
439 if {$
::tcl_platform
(platform
) eq
{windows
}} {
448 unset leftover
($inst)
451 proc stop_backends
{} {
454 foreach inst
[array names commfd
] {
459 proc stop_rev_list
{view
} {
462 foreach inst
$viewinstances($view) {
465 set viewinstances
($view) {}
468 proc reset_pending_select
{selid
} {
469 global pending_select mainheadid selectheadid
472 set pending_select
$selid
473 } elseif
{$selectheadid ne
{}} {
474 set pending_select
$selectheadid
476 set pending_select
$mainheadid
480 proc getcommits
{selid
} {
481 global canv curview need_redisplay viewactive
484 if {[start_rev_list
$curview]} {
485 reset_pending_select
$selid
486 show_status
[mc
"Reading commits..."]
489 show_status
[mc
"No commits selected"]
493 proc updatecommits
{} {
494 global curview vcanopt vorigargs vfilelimit viewinstances
495 global viewactive viewcomplete tclencoding
496 global startmsecs showneartags showlocalchanges
497 global mainheadid viewmainheadid viewmainheadid_orig pending_select
499 global varcid vposids vnegids vflags vrevs
502 set hasworktree
[hasworktree
]
505 if {$mainheadid ne
$viewmainheadid_orig($view)} {
506 if {$showlocalchanges} {
509 set viewmainheadid
($view) $mainheadid
510 set viewmainheadid_orig
($view) $mainheadid
511 if {$vfilelimit($view) ne
{}} {
512 get_viewmainhead
$view
515 if {$showlocalchanges} {
518 if {$vcanopt($view)} {
519 set oldpos
$vposids($view)
520 set oldneg
$vnegids($view)
521 set revs
[parseviewrevs
$view $vrevs($view)]
525 # note: getting the delta when negative refs change is hard,
526 # and could require multiple git log invocations, so in that
527 # case we ask git log for all the commits (not just the delta)
528 if {$oldneg eq
$vnegids($view)} {
531 # take out positive refs that we asked for before or
532 # that we have already seen
534 if {[string length
$rev] == 40} {
535 if {[lsearch
-exact $oldpos $rev] < 0
536 && ![info exists varcid
($view,$rev)]} {
541 lappend
$newrevs $rev
544 if {$npos == 0} return
546 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
548 set args
[concat
$vflags($view) $revs --not $oldpos]
550 set args
$vorigargs($view)
553 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
554 --parents --boundary $args "--" $vfilelimit($view)] r
]
556 error_popup
"[mc "Error executing git log
:"] $err"
559 if {$viewactive($view) == 0} {
560 set startmsecs
[clock clicks
-milliseconds]
562 set i
[reg_instance
$fd]
563 lappend viewinstances
($view) $i
564 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
565 if {$tclencoding != {}} {
566 fconfigure
$fd -encoding $tclencoding
568 filerun
$fd [list getcommitlines
$fd $i $view 1]
569 incr viewactive
($view)
570 set viewcomplete
($view) 0
571 reset_pending_select
{}
572 nowbusy
$view [mc
"Reading"]
578 proc reloadcommits
{} {
579 global curview viewcomplete selectedline currentid thickerline
580 global showneartags treediffs commitinterest cached_commitrow
584 if {$selectedline ne
{}} {
588 if {!$viewcomplete($curview)} {
589 stop_rev_list
$curview
593 catch
{unset currentid
}
594 catch
{unset thickerline
}
595 catch
{unset treediffs
}
602 catch
{unset commitinterest
}
603 catch
{unset cached_commitrow
}
604 catch
{unset targetid
}
610 # This makes a string representation of a positive integer which
611 # sorts as a string in numerical order
614 return [format
"%x" $n]
615 } elseif
{$n < 256} {
616 return [format
"x%.2x" $n]
617 } elseif
{$n < 65536} {
618 return [format
"y%.4x" $n]
620 return [format
"z%.8x" $n]
623 # Procedures used in reordering commits from git log (without
624 # --topo-order) into the order for display.
626 proc varcinit
{view
} {
627 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
628 global vtokmod varcmod vrowmod varcix vlastins
630 set varcstart
($view) {{}}
631 set vupptr
($view) {0}
632 set vdownptr
($view) {0}
633 set vleftptr
($view) {0}
634 set vbackptr
($view) {0}
635 set varctok
($view) {{}}
636 set varcrow
($view) {{}}
637 set vtokmod
($view) {}
640 set varcix
($view) {{}}
641 set vlastins
($view) {0}
644 proc resetvarcs
{view
} {
645 global varcid varccommits parents children vseedcount ordertok
648 foreach vid
[array names varcid
$view,*] {
653 foreach vid
[array names vshortids
$view,*] {
654 unset vshortids
($vid)
656 # some commits might have children but haven't been seen yet
657 foreach vid
[array names children
$view,*] {
660 foreach va
[array names varccommits
$view,*] {
661 unset varccommits
($va)
663 foreach vd
[array names vseedcount
$view,*] {
664 unset vseedcount
($vd)
666 catch
{unset ordertok
}
669 # returns a list of the commits with no children
671 global vdownptr vleftptr varcstart
674 set a
[lindex
$vdownptr($v) 0]
676 lappend ret
[lindex
$varcstart($v) $a]
677 set a
[lindex
$vleftptr($v) $a]
682 proc newvarc
{view id
} {
683 global varcid varctok parents children vdatemode
684 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
685 global commitdata commitinfo vseedcount varccommits vlastins
687 set a
[llength
$varctok($view)]
689 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
690 if {![info exists commitinfo
($id)]} {
691 parsecommit
$id $commitdata($id) 1
693 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
694 if {![string is integer
-strict $cdate]} {
697 if {![info exists vseedcount
($view,$cdate)]} {
698 set vseedcount
($view,$cdate) -1
700 set c
[incr vseedcount
($view,$cdate)]
701 set cdate
[expr {$cdate ^
0xffffffff}]
702 set tok
"s[strrep $cdate][strrep $c]"
707 if {[llength
$children($vid)] > 0} {
708 set kid
[lindex
$children($vid) end
]
709 set k
$varcid($view,$kid)
710 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
713 set tok
[lindex
$varctok($view) $k]
717 set i
[lsearch
-exact $parents($view,$ki) $id]
718 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
719 append tok
[strrep
$j]
721 set c
[lindex
$vlastins($view) $ka]
722 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
724 set b
[lindex
$vdownptr($view) $ka]
726 set b
[lindex
$vleftptr($view) $c]
728 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
730 set b
[lindex
$vleftptr($view) $c]
733 lset vdownptr
($view) $ka $a
734 lappend vbackptr
($view) 0
736 lset vleftptr
($view) $c $a
737 lappend vbackptr
($view) $c
739 lset vlastins
($view) $ka $a
740 lappend vupptr
($view) $ka
741 lappend vleftptr
($view) $b
743 lset vbackptr
($view) $b $a
745 lappend varctok
($view) $tok
746 lappend varcstart
($view) $id
747 lappend vdownptr
($view) 0
748 lappend varcrow
($view) {}
749 lappend varcix
($view) {}
750 set varccommits
($view,$a) {}
751 lappend vlastins
($view) 0
755 proc splitvarc
{p v
} {
756 global varcid varcstart varccommits varctok vtokmod
757 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
759 set oa
$varcid($v,$p)
760 set otok
[lindex
$varctok($v) $oa]
761 set ac
$varccommits($v,$oa)
762 set i
[lsearch
-exact $varccommits($v,$oa) $p]
764 set na
[llength
$varctok($v)]
765 # "%" sorts before "0"...
766 set tok
"$otok%[strrep $i]"
767 lappend varctok
($v) $tok
768 lappend varcrow
($v) {}
769 lappend varcix
($v) {}
770 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
771 set varccommits
($v,$na) [lrange
$ac $i end
]
772 lappend varcstart
($v) $p
773 foreach id
$varccommits($v,$na) {
774 set varcid
($v,$id) $na
776 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
777 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
778 lset vdownptr
($v) $oa $na
779 lset vlastins
($v) $oa 0
780 lappend vupptr
($v) $oa
781 lappend vleftptr
($v) 0
782 lappend vbackptr
($v) 0
783 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
784 lset vupptr
($v) $b $na
786 if {[string compare
$otok $vtokmod($v)] <= 0} {
791 proc renumbervarc
{a v
} {
792 global parents children varctok varcstart varccommits
793 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
795 set t1
[clock clicks
-milliseconds]
801 if {[info exists isrelated
($a)]} {
803 set id
[lindex
$varccommits($v,$a) end
]
804 foreach p
$parents($v,$id) {
805 if {[info exists varcid
($v,$p)]} {
806 set isrelated
($varcid($v,$p)) 1
811 set b
[lindex
$vdownptr($v) $a]
814 set b
[lindex
$vleftptr($v) $a]
816 set a
[lindex
$vupptr($v) $a]
822 if {![info exists kidchanged
($a)]} continue
823 set id
[lindex
$varcstart($v) $a]
824 if {[llength
$children($v,$id)] > 1} {
825 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
828 set oldtok
[lindex
$varctok($v) $a]
829 if {!$vdatemode($v)} {
835 set kid
[last_real_child
$v,$id]
837 set k
$varcid($v,$kid)
838 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
841 set tok
[lindex
$varctok($v) $k]
845 set i
[lsearch
-exact $parents($v,$ki) $id]
846 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
847 append tok
[strrep
$j]
849 if {$tok eq
$oldtok} {
852 set id
[lindex
$varccommits($v,$a) end
]
853 foreach p
$parents($v,$id) {
854 if {[info exists varcid
($v,$p)]} {
855 set kidchanged
($varcid($v,$p)) 1
860 lset varctok
($v) $a $tok
861 set b
[lindex
$vupptr($v) $a]
863 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
866 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
869 set c
[lindex
$vbackptr($v) $a]
870 set d
[lindex
$vleftptr($v) $a]
872 lset vdownptr
($v) $b $d
874 lset vleftptr
($v) $c $d
877 lset vbackptr
($v) $d $c
879 if {[lindex
$vlastins($v) $b] == $a} {
880 lset vlastins
($v) $b $c
882 lset vupptr
($v) $a $ka
883 set c
[lindex
$vlastins($v) $ka]
885 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
887 set b
[lindex
$vdownptr($v) $ka]
889 set b
[lindex
$vleftptr($v) $c]
892 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
894 set b
[lindex
$vleftptr($v) $c]
897 lset vdownptr
($v) $ka $a
898 lset vbackptr
($v) $a 0
900 lset vleftptr
($v) $c $a
901 lset vbackptr
($v) $a $c
903 lset vleftptr
($v) $a $b
905 lset vbackptr
($v) $b $a
907 lset vlastins
($v) $ka $a
910 foreach id
[array names sortkids
] {
911 if {[llength
$children($v,$id)] > 1} {
912 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
916 set t2
[clock clicks
-milliseconds]
917 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
920 # Fix up the graph after we have found out that in view $v,
921 # $p (a commit that we have already seen) is actually the parent
922 # of the last commit in arc $a.
923 proc fix_reversal
{p a v
} {
924 global varcid varcstart varctok vupptr
926 set pa
$varcid($v,$p)
927 if {$p ne
[lindex
$varcstart($v) $pa]} {
929 set pa
$varcid($v,$p)
931 # seeds always need to be renumbered
932 if {[lindex
$vupptr($v) $pa] == 0 ||
933 [string compare
[lindex
$varctok($v) $a] \
934 [lindex
$varctok($v) $pa]] > 0} {
939 proc insertrow
{id p v
} {
940 global cmitlisted children parents varcid varctok vtokmod
941 global varccommits ordertok commitidx numcommits curview
942 global targetid targetrow vshortids
946 set cmitlisted
($vid) 1
947 set children
($vid) {}
948 set parents
($vid) [list
$p]
949 set a
[newvarc
$v $id]
951 lappend vshortids
($v,[string range
$id 0 3]) $id
952 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
955 lappend varccommits
($v,$a) $id
957 if {[llength
[lappend children
($vp) $id]] > 1} {
958 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
959 catch
{unset ordertok
}
961 fix_reversal
$p $a $v
963 if {$v == $curview} {
964 set numcommits
$commitidx($v)
966 if {[info exists targetid
]} {
967 if {![comes_before
$targetid $p]} {
974 proc insertfakerow
{id p
} {
975 global varcid varccommits parents children cmitlisted
976 global commitidx varctok vtokmod targetid targetrow curview numcommits
980 set i
[lsearch
-exact $varccommits($v,$a) $p]
982 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
985 set children
($v,$id) {}
986 set parents
($v,$id) [list
$p]
987 set varcid
($v,$id) $a
988 lappend children
($v,$p) $id
989 set cmitlisted
($v,$id) 1
990 set numcommits
[incr commitidx
($v)]
991 # note we deliberately don't update varcstart($v) even if $i == 0
992 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
994 if {[info exists targetid
]} {
995 if {![comes_before
$targetid $p]} {
1003 proc removefakerow
{id
} {
1004 global varcid varccommits parents children commitidx
1005 global varctok vtokmod cmitlisted currentid selectedline
1006 global targetid curview numcommits
1009 if {[llength
$parents($v,$id)] != 1} {
1010 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1013 set p
[lindex
$parents($v,$id) 0]
1014 set a
$varcid($v,$id)
1015 set i
[lsearch
-exact $varccommits($v,$a) $id]
1017 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1020 unset varcid
($v,$id)
1021 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1022 unset parents
($v,$id)
1023 unset children
($v,$id)
1024 unset cmitlisted
($v,$id)
1025 set numcommits
[incr commitidx
($v) -1]
1026 set j
[lsearch
-exact $children($v,$p) $id]
1028 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1031 if {[info exist currentid
] && $id eq
$currentid} {
1035 if {[info exists targetid
] && $targetid eq
$id} {
1042 proc real_children
{vp
} {
1043 global children nullid nullid2
1046 foreach id
$children($vp) {
1047 if {$id ne
$nullid && $id ne
$nullid2} {
1054 proc first_real_child
{vp
} {
1055 global children nullid nullid2
1057 foreach id
$children($vp) {
1058 if {$id ne
$nullid && $id ne
$nullid2} {
1065 proc last_real_child
{vp
} {
1066 global children nullid nullid2
1068 set kids
$children($vp)
1069 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1070 set id
[lindex
$kids $i]
1071 if {$id ne
$nullid && $id ne
$nullid2} {
1078 proc vtokcmp
{v a b
} {
1079 global varctok varcid
1081 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1082 [lindex
$varctok($v) $varcid($v,$b)]]
1085 # This assumes that if lim is not given, the caller has checked that
1086 # arc a's token is less than $vtokmod($v)
1087 proc modify_arc
{v a
{lim
{}}} {
1088 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1091 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1094 set r
[lindex
$varcrow($v) $a]
1095 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1098 set vtokmod
($v) [lindex
$varctok($v) $a]
1100 if {$v == $curview} {
1101 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1102 set a
[lindex
$vupptr($v) $a]
1108 set lim
[llength
$varccommits($v,$a)]
1110 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1117 proc update_arcrows
{v
} {
1118 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1119 global varcid vrownum varcorder varcix varccommits
1120 global vupptr vdownptr vleftptr varctok
1121 global displayorder parentlist curview cached_commitrow
1123 if {$vrowmod($v) == $commitidx($v)} return
1124 if {$v == $curview} {
1125 if {[llength
$displayorder] > $vrowmod($v)} {
1126 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1127 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1129 catch
{unset cached_commitrow
}
1131 set narctot
[expr {[llength
$varctok($v)] - 1}]
1133 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1134 # go up the tree until we find something that has a row number,
1135 # or we get to a seed
1136 set a
[lindex
$vupptr($v) $a]
1139 set a
[lindex
$vdownptr($v) 0]
1142 set varcorder
($v) [list
$a]
1143 lset varcix
($v) $a 0
1144 lset varcrow
($v) $a 0
1148 set arcn
[lindex
$varcix($v) $a]
1149 if {[llength
$vrownum($v)] > $arcn + 1} {
1150 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1151 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1153 set row
[lindex
$varcrow($v) $a]
1157 incr row
[llength
$varccommits($v,$a)]
1158 # go down if possible
1159 set b
[lindex
$vdownptr($v) $a]
1161 # if not, go left, or go up until we can go left
1163 set b
[lindex
$vleftptr($v) $a]
1165 set a
[lindex
$vupptr($v) $a]
1171 lappend vrownum
($v) $row
1172 lappend varcorder
($v) $a
1173 lset varcix
($v) $a $arcn
1174 lset varcrow
($v) $a $row
1176 set vtokmod
($v) [lindex
$varctok($v) $p]
1178 set vrowmod
($v) $row
1179 if {[info exists currentid
]} {
1180 set selectedline
[rowofcommit
$currentid]
1184 # Test whether view $v contains commit $id
1185 proc commitinview
{id v
} {
1188 return [info exists varcid
($v,$id)]
1191 # Return the row number for commit $id in the current view
1192 proc rowofcommit
{id
} {
1193 global varcid varccommits varcrow curview cached_commitrow
1194 global varctok vtokmod
1197 if {![info exists varcid
($v,$id)]} {
1198 puts
"oops rowofcommit no arc for [shortids $id]"
1201 set a
$varcid($v,$id)
1202 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1205 if {[info exists cached_commitrow
($id)]} {
1206 return $cached_commitrow($id)
1208 set i
[lsearch
-exact $varccommits($v,$a) $id]
1210 puts
"oops didn't find commit [shortids $id] in arc $a"
1213 incr i
[lindex
$varcrow($v) $a]
1214 set cached_commitrow
($id) $i
1218 # Returns 1 if a is on an earlier row than b, otherwise 0
1219 proc comes_before
{a b
} {
1220 global varcid varctok curview
1223 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1224 ![info exists varcid
($v,$b)]} {
1227 if {$varcid($v,$a) != $varcid($v,$b)} {
1228 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1229 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1231 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1234 proc bsearch
{l elt
} {
1235 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1240 while {$hi - $lo > 1} {
1241 set mid
[expr {int
(($lo + $hi) / 2)}]
1242 set t
[lindex
$l $mid]
1245 } elseif
{$elt > $t} {
1254 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1255 proc make_disporder
{start end
} {
1256 global vrownum curview commitidx displayorder parentlist
1257 global varccommits varcorder parents vrowmod varcrow
1258 global d_valid_start d_valid_end
1260 if {$end > $vrowmod($curview)} {
1261 update_arcrows
$curview
1263 set ai
[bsearch
$vrownum($curview) $start]
1264 set start
[lindex
$vrownum($curview) $ai]
1265 set narc
[llength
$vrownum($curview)]
1266 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1267 set a
[lindex
$varcorder($curview) $ai]
1268 set l
[llength
$displayorder]
1269 set al
[llength
$varccommits($curview,$a)]
1270 if {$l < $r + $al} {
1272 set pad
[ntimes
[expr {$r - $l}] {}]
1273 set displayorder
[concat
$displayorder $pad]
1274 set parentlist
[concat
$parentlist $pad]
1275 } elseif
{$l > $r} {
1276 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1277 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1279 foreach id
$varccommits($curview,$a) {
1280 lappend displayorder
$id
1281 lappend parentlist
$parents($curview,$id)
1283 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1285 foreach id
$varccommits($curview,$a) {
1286 lset displayorder
$i $id
1287 lset parentlist
$i $parents($curview,$id)
1295 proc commitonrow
{row
} {
1298 set id
[lindex
$displayorder $row]
1300 make_disporder
$row [expr {$row + 1}]
1301 set id
[lindex
$displayorder $row]
1306 proc closevarcs
{v
} {
1307 global varctok varccommits varcid parents children
1308 global cmitlisted commitidx vtokmod
1310 set missing_parents
0
1312 set narcs
[llength
$varctok($v)]
1313 for {set a
1} {$a < $narcs} {incr a
} {
1314 set id
[lindex
$varccommits($v,$a) end
]
1315 foreach p
$parents($v,$id) {
1316 if {[info exists varcid
($v,$p)]} continue
1317 # add p as a new commit
1318 incr missing_parents
1319 set cmitlisted
($v,$p) 0
1320 set parents
($v,$p) {}
1321 if {[llength
$children($v,$p)] == 1 &&
1322 [llength
$parents($v,$id)] == 1} {
1325 set b
[newvarc
$v $p]
1327 set varcid
($v,$p) $b
1328 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1331 lappend varccommits
($v,$b) $p
1333 set scripts
[check_interest
$p $scripts]
1336 if {$missing_parents > 0} {
1337 foreach s
$scripts {
1343 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1344 # Assumes we already have an arc for $rwid.
1345 proc rewrite_commit
{v id rwid
} {
1346 global children parents varcid varctok vtokmod varccommits
1348 foreach ch
$children($v,$id) {
1349 # make $rwid be $ch's parent in place of $id
1350 set i
[lsearch
-exact $parents($v,$ch) $id]
1352 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1354 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1355 # add $ch to $rwid's children and sort the list if necessary
1356 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1357 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1358 $children($v,$rwid)]
1360 # fix the graph after joining $id to $rwid
1361 set a
$varcid($v,$ch)
1362 fix_reversal
$rwid $a $v
1363 # parentlist is wrong for the last element of arc $a
1364 # even if displayorder is right, hence the 3rd arg here
1365 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1369 # Mechanism for registering a command to be executed when we come
1370 # across a particular commit. To handle the case when only the
1371 # prefix of the commit is known, the commitinterest array is now
1372 # indexed by the first 4 characters of the ID. Each element is a
1373 # list of id, cmd pairs.
1374 proc interestedin
{id cmd
} {
1375 global commitinterest
1377 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1380 proc check_interest
{id scripts
} {
1381 global commitinterest
1383 set prefix
[string range
$id 0 3]
1384 if {[info exists commitinterest
($prefix)]} {
1386 foreach
{i
script} $commitinterest($prefix) {
1387 if {[string match
"$i*" $id]} {
1388 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1390 lappend newlist
$i $script
1393 if {$newlist ne
{}} {
1394 set commitinterest
($prefix) $newlist
1396 unset commitinterest
($prefix)
1402 proc getcommitlines
{fd inst view updating
} {
1403 global cmitlisted leftover
1404 global commitidx commitdata vdatemode
1405 global parents children curview hlview
1406 global idpending ordertok
1407 global varccommits varcid varctok vtokmod vfilelimit vshortids
1409 set stuff
[read $fd 500000]
1410 # git log doesn't terminate the last commit with a null...
1411 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1418 global commfd viewcomplete viewactive viewname
1419 global viewinstances
1421 set i
[lsearch
-exact $viewinstances($view) $inst]
1423 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1425 # set it blocking so we wait for the process to terminate
1426 fconfigure
$fd -blocking 1
1427 if {[catch
{close
$fd} err
]} {
1429 if {$view != $curview} {
1430 set fv
" for the \"$viewname($view)\" view"
1432 if {[string range
$err 0 4] == "usage"} {
1433 set err
"Gitk: error reading commits$fv:\
1434 bad arguments to git log."
1435 if {$viewname($view) eq
"Command line"} {
1437 " (Note: arguments to gitk are passed to git log\
1438 to allow selection of commits to be displayed.)"
1441 set err
"Error reading commits$fv: $err"
1445 if {[incr viewactive
($view) -1] <= 0} {
1446 set viewcomplete
($view) 1
1447 # Check if we have seen any ids listed as parents that haven't
1448 # appeared in the list
1452 if {$view == $curview} {
1461 set i
[string first
"\0" $stuff $start]
1463 append leftover
($inst) [string range
$stuff $start end
]
1467 set cmit
$leftover($inst)
1468 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1469 set leftover
($inst) {}
1471 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1473 set start
[expr {$i + 1}]
1474 set j
[string first
"\n" $cmit]
1477 if {$j >= 0 && [string match
"commit *" $cmit]} {
1478 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1479 if {[string match
{[-^
<>]*} $ids]} {
1480 switch
-- [string index
$ids 0] {
1486 set ids
[string range
$ids 1 end
]
1490 if {[string length
$id] != 40} {
1498 if {[string length
$shortcmit] > 80} {
1499 set shortcmit
"[string range $shortcmit 0 80]..."
1501 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1504 set id [lindex $ids 0]
1507 lappend vshortids($view,[string range $id 0 3]) $id
1509 if {!$listed && $updating && ![info exists varcid($vid)] &&
1510 $vfilelimit($view) ne {}} {
1511 # git log doesn't rewrite parents
for unlisted commits
1512 # when doing path limiting, so work around that here
1513 # by working out the rewritten parent with git rev-list
1514 # and if we already know about it, using the rewritten
1515 # parent as a substitute parent for $id's children.
1517 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1518 $id -- $vfilelimit($view)]
1520 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1521 # use $rwid in place of $id
1522 rewrite_commit
$view $id $rwid
1529 if {[info exists varcid
($vid)]} {
1530 if {$cmitlisted($vid) ||
!$listed} continue
1534 set olds
[lrange
$ids 1 end
]
1538 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1539 set cmitlisted
($vid) $listed
1540 set parents
($vid) $olds
1541 if {![info exists children
($vid)]} {
1542 set children
($vid) {}
1543 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1544 set k
[lindex
$children($vid) 0]
1545 if {[llength
$parents($view,$k)] == 1 &&
1546 (!$vdatemode($view) ||
1547 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1548 set a
$varcid($view,$k)
1553 set a
[newvarc
$view $id]
1555 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1558 if {![info exists varcid
($vid)]} {
1560 lappend varccommits
($view,$a) $id
1561 incr commitidx
($view)
1566 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1568 if {[llength
[lappend children
($vp) $id]] > 1 &&
1569 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1570 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1572 catch
{unset ordertok
}
1574 if {[info exists varcid
($view,$p)]} {
1575 fix_reversal
$p $a $view
1581 set scripts
[check_interest
$id $scripts]
1585 global numcommits hlview
1587 if {$view == $curview} {
1588 set numcommits
$commitidx($view)
1591 if {[info exists hlview
] && $view == $hlview} {
1592 # we never actually get here...
1595 foreach s
$scripts {
1602 proc chewcommits
{} {
1603 global curview hlview viewcomplete
1604 global pending_select
1607 if {$viewcomplete($curview)} {
1608 global commitidx varctok
1609 global numcommits startmsecs
1611 if {[info exists pending_select
]} {
1613 reset_pending_select
{}
1615 if {[commitinview
$pending_select $curview]} {
1616 selectline
[rowofcommit
$pending_select] 1
1618 set row
[first_real_row
]
1622 if {$commitidx($curview) > 0} {
1623 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1624 #puts "overall $ms ms for $numcommits commits"
1625 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1627 show_status
[mc
"No commits selected"]
1634 proc do_readcommit
{id
} {
1637 # Invoke git-log to handle automatic encoding conversion
1638 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1639 # Read the results using i18n.logoutputencoding
1640 fconfigure
$fd -translation lf
-eofchar {}
1641 if {$tclencoding != {}} {
1642 fconfigure
$fd -encoding $tclencoding
1644 set contents
[read $fd]
1646 # Remove the heading line
1647 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1652 proc readcommit
{id
} {
1653 if {[catch
{set contents
[do_readcommit
$id]}]} return
1654 parsecommit
$id $contents 1
1657 proc parsecommit
{id contents listed
} {
1667 set hdrend
[string first
"\n\n" $contents]
1669 # should never happen...
1670 set hdrend
[string length
$contents]
1672 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1673 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1674 foreach line
[split $header "\n"] {
1675 set line
[split $line " "]
1676 set tag
[lindex
$line 0]
1677 if {$tag == "author"} {
1678 set audate
[lrange
$line end-1 end
]
1679 set auname
[join [lrange
$line 1 end-2
] " "]
1680 } elseif
{$tag == "committer"} {
1681 set comdate
[lrange
$line end-1 end
]
1682 set comname
[join [lrange
$line 1 end-2
] " "]
1686 # take the first non-blank line of the comment as the headline
1687 set headline
[string trimleft
$comment]
1688 set i
[string first
"\n" $headline]
1690 set headline
[string range
$headline 0 $i]
1692 set headline
[string trimright
$headline]
1693 set i
[string first
"\r" $headline]
1695 set headline
[string trimright
[string range
$headline 0 $i]]
1698 # git log indents the comment by 4 spaces;
1699 # if we got this via git cat-file, add the indentation
1701 foreach line
[split $comment "\n"] {
1702 append newcomment
" "
1703 append newcomment
$line
1704 append newcomment
"\n"
1706 set comment
$newcomment
1708 set hasnote
[string first
"\nNotes:\n" $contents]
1710 # If there is diff output shown in the git-log stream, split it
1711 # out. But get rid of the empty line that always precedes the
1713 set i
[string first
"\n\ndiff" $comment]
1715 set diff [string range
$comment $i+1 end
]
1716 set comment
[string range
$comment 0 $i-1]
1718 set commitinfo
($id) [list
$headline $auname $audate \
1719 $comname $comdate $comment $hasnote $diff]
1722 proc getcommit
{id
} {
1723 global commitdata commitinfo
1725 if {[info exists commitdata
($id)]} {
1726 parsecommit
$id $commitdata($id) 1
1729 if {![info exists commitinfo
($id)]} {
1730 set commitinfo
($id) [list
[mc
"No commit information available"]]
1736 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1737 # and are present in the current view.
1738 # This is fairly slow...
1739 proc longid
{prefix
} {
1740 global varcid curview vshortids
1743 if {[string length
$prefix] >= 4} {
1744 set vshortid
$curview,[string range
$prefix 0 3]
1745 if {[info exists vshortids
($vshortid)]} {
1746 foreach id
$vshortids($vshortid) {
1747 if {[string match
"$prefix*" $id]} {
1748 if {[lsearch
-exact $ids $id] < 0} {
1750 if {[llength
$ids] >= 2} break
1756 foreach match
[array names varcid
"$curview,$prefix*"] {
1757 lappend ids
[lindex
[split $match ","] 1]
1758 if {[llength
$ids] >= 2} break
1765 global tagids idtags headids idheads tagobjid
1766 global otherrefids idotherrefs mainhead mainheadid
1767 global selecthead selectheadid
1770 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1773 set refd
[open
[list | git show-ref
-d] r
]
1774 while {[gets
$refd line
] >= 0} {
1775 if {[string index
$line 40] ne
" "} continue
1776 set id
[string range
$line 0 39]
1777 set ref
[string range
$line 41 end
]
1778 if {![string match
"refs/*" $ref]} continue
1779 set name
[string range
$ref 5 end
]
1780 if {[string match
"remotes/*" $name]} {
1781 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1782 set headids
($name) $id
1783 lappend idheads
($id) $name
1785 } elseif
{[string match
"heads/*" $name]} {
1786 set name
[string range
$name 6 end
]
1787 set headids
($name) $id
1788 lappend idheads
($id) $name
1789 } elseif
{[string match
"tags/*" $name]} {
1790 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1791 # which is what we want since the former is the commit ID
1792 set name
[string range
$name 5 end
]
1793 if {[string match
"*^{}" $name]} {
1794 set name
[string range
$name 0 end-3
]
1796 set tagobjid
($name) $id
1798 set tagids
($name) $id
1799 lappend idtags
($id) $name
1801 set otherrefids
($name) $id
1802 lappend idotherrefs
($id) $name
1809 set mainheadid
[exec git rev-parse HEAD
]
1810 set thehead
[exec git symbolic-ref HEAD
]
1811 if {[string match
"refs/heads/*" $thehead]} {
1812 set mainhead
[string range
$thehead 11 end
]
1816 if {$selecthead ne
{}} {
1818 set selectheadid
[exec git rev-parse
--verify $selecthead]
1823 # skip over fake commits
1824 proc first_real_row
{} {
1825 global nullid nullid2 numcommits
1827 for {set row
0} {$row < $numcommits} {incr row
} {
1828 set id
[commitonrow
$row]
1829 if {$id ne
$nullid && $id ne
$nullid2} {
1836 # update things for a head moved to a child of its previous location
1837 proc movehead
{id name
} {
1838 global headids idheads
1840 removehead
$headids($name) $name
1841 set headids
($name) $id
1842 lappend idheads
($id) $name
1845 # update things when a head has been removed
1846 proc removehead
{id name
} {
1847 global headids idheads
1849 if {$idheads($id) eq
$name} {
1852 set i
[lsearch
-exact $idheads($id) $name]
1854 set idheads
($id) [lreplace
$idheads($id) $i $i]
1857 unset headids
($name)
1860 proc ttk_toplevel
{w args
} {
1862 eval [linsert
$args 0 ::toplevel
$w]
1864 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1869 proc make_transient
{window origin
} {
1872 # In MacOS Tk 8.4 transient appears to work by setting
1873 # overrideredirect, which is utterly useless, since the
1874 # windows get no border, and are not even kept above
1876 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1878 wm transient
$window $origin
1880 # Windows fails to place transient windows normally, so
1881 # schedule a callback to center them on the parent.
1882 if {[tk windowingsystem
] eq
{win32
}} {
1883 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1887 proc show_error
{w top msg
{mc mc
}} {
1889 if {![info exists NS
]} {set NS
""}
1890 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1891 message
$w.m
-text $msg -justify center
-aspect 400
1892 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1893 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1894 pack
$w.ok
-side bottom
-fill x
1895 bind $top <Visibility
> "grab $top; focus $top"
1896 bind $top <Key-Return
> "destroy $top"
1897 bind $top <Key-space
> "destroy $top"
1898 bind $top <Key-Escape
> "destroy $top"
1902 proc error_popup
{msg
{owner .
}} {
1903 if {[tk windowingsystem
] eq
"win32"} {
1904 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1905 -parent $owner -message $msg
1909 make_transient
$w $owner
1910 show_error
$w $w $msg
1914 proc confirm_popup
{msg
{owner .
}} {
1915 global confirm_ok NS
1919 make_transient
$w $owner
1920 message
$w.m
-text $msg -justify center
-aspect 400
1921 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1922 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1923 pack
$w.ok
-side left
-fill x
1924 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1925 pack
$w.cancel
-side right
-fill x
1926 bind $w <Visibility
> "grab $w; focus $w"
1927 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1928 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1929 bind $w <Key-Escape
> "destroy $w"
1930 tk
::PlaceWindow
$w widget
$owner
1935 proc setoptions
{} {
1936 if {[tk windowingsystem
] ne
"win32"} {
1937 option add
*Panedwindow.showHandle
1 startupFile
1938 option add
*Panedwindow.sashRelief raised startupFile
1939 if {[tk windowingsystem
] ne
"aqua"} {
1940 option add
*Menu.font uifont startupFile
1943 option add
*Menu.TearOff
0 startupFile
1945 option add
*Button.font uifont startupFile
1946 option add
*Checkbutton.font uifont startupFile
1947 option add
*Radiobutton.font uifont startupFile
1948 option add
*Menubutton.font uifont startupFile
1949 option add
*Label.font uifont startupFile
1950 option add
*Message.font uifont startupFile
1951 option add
*Entry.font textfont startupFile
1952 option add
*Text.font textfont startupFile
1953 option add
*Labelframe.font uifont startupFile
1954 option add
*Spinbox.font textfont startupFile
1955 option add
*Listbox.font mainfont startupFile
1958 # Make a menu and submenus.
1959 # m is the window name for the menu, items is the list of menu items to add.
1960 # Each item is a list {mc label type description options...}
1961 # mc is ignored; it's so we can put mc there to alert xgettext
1962 # label is the string that appears in the menu
1963 # type is cascade, command or radiobutton (should add checkbutton)
1964 # description depends on type; it's the sublist for cascade, the
1965 # command to invoke for command, or {variable value} for radiobutton
1966 proc makemenu
{m items
} {
1968 if {[tk windowingsystem
] eq
{aqua
}} {
1974 set name
[mc
[lindex
$i 1]]
1975 set type [lindex
$i 2]
1976 set thing
[lindex
$i 3]
1977 set params
[list
$type]
1979 set u
[string first
"&" [string map
{&& x
} $name]]
1980 lappend params
-label [string map
{&& & & {}} $name]
1982 lappend params
-underline $u
1987 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1988 lappend params
-menu $m.
$submenu
1991 lappend params
-command $thing
1994 lappend params
-variable [lindex
$thing 0] \
1995 -value [lindex
$thing 1]
1998 set tail [lrange
$i 4 end
]
1999 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
2000 eval $m add
$params $tail
2001 if {$type eq
"cascade"} {
2002 makemenu
$m.
$submenu $thing
2007 # translate string and remove ampersands
2009 return [string map
{&& & & {}} [mc
$str]]
2012 proc cleardropsel
{w
} {
2015 proc makedroplist
{w varname args
} {
2019 foreach label
$args {
2020 set cx
[string length
$label]
2021 if {$cx > $width} {set width
$cx}
2023 set gm
[ttk
::combobox
$w -width $width -state readonly\
2024 -textvariable $varname -values $args \
2025 -exportselection false
]
2026 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2028 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2033 proc makewindow {} {
2034 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2036 global findtype findtypemenu findloc findstring fstring geometry
2037 global entries sha1entry sha1string sha1but
2038 global diffcontextstring diffcontext
2040 global maincursor textcursor curtextcursor
2041 global rowctxmenu fakerowmenu mergemax wrapcomment
2042 global highlight_files gdttype
2043 global searchstring sstring
2044 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2045 global uifgcolor uifgdisabledcolor
2046 global filesepbgcolor filesepfgcolor
2047 global mergecolors foundbgcolor currentsearchhitbgcolor
2048 global headctxmenu progresscanv progressitem progresscoords statusw
2049 global fprogitem fprogcoord lastprogupdate progupdatepending
2050 global rprogitem rprogcoord rownumsel numcommits
2051 global have_tk85 use_ttk NS
2055 # The "mc" arguments here are purely so that xgettext
2056 # sees the following string as needing to be translated
2059 {mc "Update" command updatecommits -accelerator F5}
2060 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2061 {mc "Reread references" command rereadrefs}
2062 {mc "List references" command showrefs -accelerator F2}
2064 {mc "Start git gui" command {exec git gui &}}
2066 {mc "Quit" command doquit -accelerator Meta1-Q}
2070 {mc "Preferences" command doprefs}
2074 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2075 {mc "Edit view..." command editview -state disabled -accelerator F4}
2076 {mc "Delete view" command delview -state disabled}
2078 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2080 if {[tk windowingsystem] ne "aqua"} {
2083 {mc "About gitk" command about}
2084 {mc "Key bindings" command keys}
2086 set bar [list $file $edit $view $help]
2088 proc ::tk::mac::ShowPreferences {} {doprefs}
2089 proc ::tk::mac::Quit {} {doquit}
2090 lset file end [lreplace [lindex $file end] end-1 end]
2092 xx "Apple" cascade {
2093 {mc "About gitk" command about}
2098 {mc "Key bindings" command keys}
2100 set bar [list $apple $file $view $help]
2103 . configure -menu .bar
2106 # cover the non-themed toplevel with a themed frame.
2107 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2110 # the gui has upper and lower half, parts of a paned window.
2111 ${NS}::panedwindow .ctop -orient vertical
2113 # possibly use assumed geometry
2114 if {![info exists geometry(pwsash0)]} {
2115 set geometry(topheight) [expr {15 * $linespc}]
2116 set geometry(topwidth) [expr {80 * $charspc}]
2117 set geometry(botheight) [expr {15 * $linespc}]
2118 set geometry(botwidth) [expr {50 * $charspc}]
2119 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2120 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2123 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2124 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2125 ${NS}::frame .tf.histframe
2126 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2128 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2131 # create three canvases
2132 set cscroll .tf.histframe.csb
2133 set canv .tf.histframe.pwclist.canv
2135 -selectbackground $selectbgcolor \
2136 -background $bgcolor -bd 0 \
2137 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2138 .tf.histframe.pwclist add $canv
2139 set canv2 .tf.histframe.pwclist.canv2
2141 -selectbackground $selectbgcolor \
2142 -background $bgcolor -bd 0 -yscrollincr $linespc
2143 .tf.histframe.pwclist add $canv2
2144 set canv3 .tf.histframe.pwclist.canv3
2146 -selectbackground $selectbgcolor \
2147 -background $bgcolor -bd 0 -yscrollincr $linespc
2148 .tf.histframe.pwclist add $canv3
2150 bind .tf.histframe.pwclist <Map> {
2152 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2153 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2156 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2157 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2160 # a scroll bar to rule them
2161 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2162 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2163 pack $cscroll -side right -fill y
2164 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2165 lappend bglist $canv $canv2 $canv3
2166 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2168 # we have two button bars at bottom of top frame. Bar 1
2169 ${NS}::frame .tf.bar
2170 ${NS}::frame .tf.lbar -height 15
2172 set sha1entry .tf.bar.sha1
2173 set entries $sha1entry
2174 set sha1but .tf.bar.sha1label
2175 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2176 -command gotocommit -width 8
2177 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2178 pack .tf.bar.sha1label -side left
2179 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2180 trace add variable sha1string write sha1change
2181 pack $sha1entry -side left -pady 2
2184 #define left_width 16
2185 #define left_height 16
2186 static unsigned char left_bits[] = {
2187 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2188 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2189 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2192 #define right_width 16
2193 #define right_height 16
2194 static unsigned char right_bits[] = {
2195 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2196 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2197 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2199 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2200 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2201 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2202 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2204 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2206 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2208 .tf.bar.leftbut configure -image bm-left
2210 pack .tf.bar.leftbut -side left -fill y
2211 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2213 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2215 .tf.bar.rightbut configure -image bm-right
2217 pack .tf.bar.rightbut -side left -fill y
2219 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2221 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2222 -relief sunken -anchor e
2223 ${NS}::label .tf.bar.rowlabel2 -text "/"
2224 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2225 -relief sunken -anchor e
2226 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2229 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2232 trace add variable selectedline write selectedline_change
2234 # Status label and progress bar
2235 set statusw .tf.bar.status
2236 ${NS}::label $statusw -width 15 -relief sunken
2237 pack $statusw -side left -padx 5
2239 set progresscanv [ttk::progressbar .tf.bar.progress]
2241 set h [expr {[font metrics uifont -linespace] + 2}]
2242 set progresscanv .tf.bar.progress
2243 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2244 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2245 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2246 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2248 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2249 set progresscoords {0 0}
2252 bind $progresscanv <Configure> adjustprogress
2253 set lastprogupdate [clock clicks -milliseconds]
2254 set progupdatepending 0
2256 # build up the bottom bar of upper window
2257 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2258 ${NS}::button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
2259 ${NS}::button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
2260 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2261 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2263 set gdttype [mc "containing:"]
2264 set gm [makedroplist .tf.lbar.gdttype gdttype \
2265 [mc "containing:"] \
2266 [mc "touching paths:"] \
2267 [mc "adding/removing string:"] \
2268 [mc "changing lines matching:"]]
2269 trace add variable gdttype write gdttype_change
2270 pack .tf.lbar.gdttype -side left -fill y
2273 set fstring .tf.lbar.findstring
2274 lappend entries $fstring
2275 ${NS}::entry $fstring -width 30 -textvariable findstring
2276 trace add variable findstring write find_change
2277 set findtype [mc "Exact"]
2278 set findtypemenu [makedroplist .tf.lbar.findtype \
2279 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2280 trace add variable findtype write findcom_change
2281 set findloc [mc "All fields"]
2282 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2283 [mc "Comments"] [mc "Author"] [mc "Committer"]
2284 trace add variable findloc write find_change
2285 pack .tf.lbar.findloc -side right
2286 pack .tf.lbar.findtype -side right
2287 pack $fstring -side left -expand 1 -fill x
2289 # Finish putting the upper half of the viewer together
2290 pack .tf.lbar -in .tf -side bottom -fill x
2291 pack .tf.bar -in .tf -side bottom -fill x
2292 pack .tf.histframe -fill both -side top -expand 1
2295 .ctop paneconfigure .tf -height $geometry(topheight)
2296 .ctop paneconfigure .tf -width $geometry(topwidth)
2299 # now build up the bottom
2300 ${NS}::panedwindow .pwbottom -orient horizontal
2302 # lower left, a text box over search bar, scroll bar to the right
2303 # if we know window height, then that will set the lower text height, otherwise
2304 # we set lower text height which will drive window height
2305 if {[info exists geometry(main)]} {
2306 ${NS}::frame .bleft -width $geometry(botwidth)
2308 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2310 ${NS}::frame .bleft.top
2311 ${NS}::frame .bleft.mid
2312 ${NS}::frame .bleft.bottom
2314 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2315 pack .bleft.top.search -side left -padx 5
2316 set sstring .bleft.top.sstring
2318 ${NS}::entry $sstring -width 20 -textvariable searchstring
2319 lappend entries $sstring
2320 trace add variable searchstring write incrsearch
2321 pack $sstring -side left -expand 1 -fill x
2322 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2323 -command changediffdisp -variable diffelide -value {0 0}
2324 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2325 -command changediffdisp -variable diffelide -value {0 1}
2326 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2327 -command changediffdisp -variable diffelide -value {1 0}
2328 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2329 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2330 spinbox .bleft.mid.diffcontext -width 5 \
2331 -from 0 -increment 1 -to 10000000 \
2332 -validate all -validatecommand "diffcontextvalidate %P" \
2333 -textvariable diffcontextstring
2334 .bleft.mid.diffcontext set $diffcontext
2335 trace add variable diffcontextstring write diffcontextchange
2336 lappend entries .bleft.mid.diffcontext
2337 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2338 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2339 -command changeignorespace -variable ignorespace
2340 pack .bleft.mid.ignspace -side left -padx 5
2342 set worddiff [mc "Line diff"]
2343 if {[package vcompare $git_version "1.7.2"] >= 0} {
2344 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2345 [mc "Markup words"] [mc "Color words"]
2346 trace add variable worddiff write changeworddiff
2347 pack .bleft.mid.worddiff -side left -padx 5
2350 set ctext .bleft.bottom.ctext
2351 text $ctext -background $bgcolor -foreground $fgcolor \
2352 -state disabled -font textfont \
2353 -yscrollcommand scrolltext -wrap none \
2354 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2356 $ctext conf -tabstyle wordprocessor
2358 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2359 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2360 pack .bleft.top -side top -fill x
2361 pack .bleft.mid -side top -fill x
2362 grid $ctext .bleft.bottom.sb -sticky nsew
2363 grid .bleft.bottom.sbhorizontal -sticky ew
2364 grid columnconfigure .bleft.bottom 0 -weight 1
2365 grid rowconfigure .bleft.bottom 0 -weight 1
2366 grid rowconfigure .bleft.bottom 1 -weight 0
2367 pack .bleft.bottom -side top -fill both -expand 1
2368 lappend bglist $ctext
2369 lappend fglist $ctext
2371 $ctext tag conf comment -wrap $wrapcomment
2372 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2373 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2374 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2375 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2376 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2377 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2378 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2379 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2380 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2381 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2382 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2383 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2384 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2385 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2386 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2387 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2388 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2389 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2390 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2391 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2392 $ctext tag conf mmax -fore darkgrey
2394 $ctext tag conf mresult -font textfontbold
2395 $ctext tag conf msep -font textfontbold
2396 $ctext tag conf found -back $foundbgcolor
2397 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2398 $ctext tag conf wwrap -wrap word
2399 $ctext tag conf bold -font textfontbold
2401 .pwbottom add .bleft
2403 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2407 ${NS}::frame .bright
2408 ${NS}::frame .bright.mode
2409 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2410 -command reselectline -variable cmitmode -value "patch"
2411 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2412 -command reselectline -variable cmitmode -value "tree"
2413 grid .bright.mode.patch .bright.mode.tree -sticky ew
2414 pack .bright.mode -side top -fill x
2415 set cflist .bright.cfiles
2416 set indent [font measure mainfont "nn"]
2418 -selectbackground $selectbgcolor \
2419 -background $bgcolor -foreground $fgcolor \
2421 -tabs [list $indent [expr {2 * $indent}]] \
2422 -yscrollcommand ".bright.sb set" \
2423 -cursor [. cget -cursor] \
2424 -spacing1 1 -spacing3 1
2425 lappend bglist $cflist
2426 lappend fglist $cflist
2427 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2428 pack .bright.sb -side right -fill y
2429 pack $cflist -side left -fill both -expand 1
2430 $cflist tag configure highlight \
2431 -background [$cflist cget -selectbackground]
2432 $cflist tag configure bold -font mainfontbold
2434 .pwbottom add .bright
2437 # restore window width & height if known
2438 if {[info exists geometry(main)]} {
2439 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2440 if {$w > [winfo screenwidth .]} {
2441 set w [winfo screenwidth .]
2443 if {$h > [winfo screenheight .]} {
2444 set h [winfo screenheight .]
2446 wm geometry . "${w}x$h"
2450 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2451 wm state . $geometry(state)
2454 if {[tk windowingsystem] eq {aqua}} {
2465 %W sashpos 0 $::geometry(topheight)
2467 bind .pwbottom <Map> {
2469 %W sashpos 0 $::geometry(botwidth)
2473 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2474 pack .ctop -fill both -expand 1
2475 bindall <1> {selcanvline %W %x %y}
2476 #bindall <B1-Motion> {selcanvline %W %x %y}
2477 if {[tk windowingsystem] == "win32"} {
2478 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2479 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2481 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2482 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2483 if {[tk windowingsystem] eq "aqua"} {
2484 bindall <MouseWheel> {
2485 set delta [expr {- (%D)}]
2486 allcanvs yview scroll $delta units
2488 bindall <Shift-MouseWheel> {
2489 set delta [expr {- (%D)}]
2490 $canv xview scroll $delta units
2494 bindall <$::BM> "canvscan mark %W %x %y"
2495 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2496 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2497 bind . <$M1B-Key-w> doquit
2498 bindkey <Home> selfirstline
2499 bindkey <End> sellastline
2500 bind . <Key-Up> "selnextline -1"
2501 bind . <Key-Down> "selnextline 1"
2502 bind . <Shift-Key-Up> "dofind -1 0"
2503 bind . <Shift-Key-Down> "dofind 1 0"
2504 bindkey <Key-Right> "goforw"
2505 bindkey <Key-Left> "goback"
2506 bind . <Key-Prior> "selnextpage -1"
2507 bind . <Key-Next> "selnextpage 1"
2508 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2509 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2510 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2511 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2512 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2513 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2514 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2515 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2516 bindkey <Key-space> "$ctext yview scroll 1 pages"
2517 bindkey p "selnextline -1"
2518 bindkey n "selnextline 1"
2521 bindkey k "selnextline -1"
2522 bindkey j "selnextline 1"
2526 bindkey d "$ctext yview scroll 18 units"
2527 bindkey u "$ctext yview scroll -18 units"
2528 bindkey / {focus $fstring}
2529 bindkey <Key-KP_Divide> {focus $fstring}
2530 bindkey <Key-Return> {dofind 1 1}
2531 bindkey ? {dofind -1 1}
2533 bind . <F5> updatecommits
2534 bindmodfunctionkey Shift 5 reloadcommits
2535 bind . <F2> showrefs
2536 bindmodfunctionkey Shift 4 {newview 0}
2537 bind . <F4> edit_or_newview
2538 bind . <$M1B-q> doquit
2539 bind . <$M1B-f> {dofind 1 1}
2540 bind . <$M1B-g> {dofind 1 0}
2541 bind . <$M1B-r> dosearchback
2542 bind . <$M1B-s> dosearch
2543 bind . <$M1B-equal> {incrfont 1}
2544 bind . <$M1B-plus> {incrfont 1}
2545 bind . <$M1B-KP_Add> {incrfont 1}
2546 bind . <$M1B-minus> {incrfont -1}
2547 bind . <$M1B-KP_Subtract> {incrfont -1}
2548 wm protocol . WM_DELETE_WINDOW doquit
2549 bind . <Destroy> {stop_backends}
2550 bind . <Button-1> "click %W"
2551 bind $fstring <Key-Return> {dofind 1 1}
2552 bind $sha1entry <Key-Return> {gotocommit; break}
2553 bind $sha1entry <<PasteSelection>> clearsha1
2554 bind $cflist <1> {sel_flist %W %x %y; break}
2555 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2556 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2558 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2559 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2560 bind $ctext <Button-1> {focus %W}
2561 bind $ctext <<Selection>> rehighlight_search_results
2563 set maincursor [. cget -cursor]
2564 set textcursor [$ctext cget -cursor]
2565 set curtextcursor $textcursor
2567 set rowctxmenu .rowctxmenu
2568 makemenu $rowctxmenu {
2569 {mc "Diff this -> selected" command {diffvssel 0}}
2570 {mc "Diff selected -> this" command {diffvssel 1}}
2571 {mc "Make patch" command mkpatch}
2572 {mc "Create tag" command mktag}
2573 {mc "Write commit to file" command writecommit}
2574 {mc "Create new branch" command mkbranch}
2575 {mc "Cherry-pick this commit" command cherrypick}
2576 {mc "Reset HEAD branch to here" command resethead}
2577 {mc "Mark this commit" command markhere}
2578 {mc "Return to mark" command gotomark}
2579 {mc "Find descendant of this and mark" command find_common_desc}
2580 {mc "Compare with marked commit" command compare_commits}
2581 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2582 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2583 {mc "Revert this commit" command revert}
2585 $rowctxmenu configure -tearoff 0
2587 set fakerowmenu .fakerowmenu
2588 makemenu $fakerowmenu {
2589 {mc "Diff this -> selected" command {diffvssel 0}}
2590 {mc "Diff selected -> this" command {diffvssel 1}}
2591 {mc "Make patch" command mkpatch}
2592 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2593 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2595 $fakerowmenu configure -tearoff 0
2597 set headctxmenu .headctxmenu
2598 makemenu $headctxmenu {
2599 {mc "Check out this branch" command cobranch}
2600 {mc "Remove this branch" command rmbranch}
2602 $headctxmenu configure -tearoff 0
2605 set flist_menu .flistctxmenu
2606 makemenu $flist_menu {
2607 {mc "Highlight this too" command {flist_hl 0}}
2608 {mc "Highlight this only" command {flist_hl 1}}
2609 {mc "External diff" command {external_diff}}
2610 {mc "Blame parent commit" command {external_blame 1}}
2612 $flist_menu configure -tearoff 0
2615 set diff_menu .diffctxmenu
2616 makemenu $diff_menu {
2617 {mc "Show origin of this line" command show_line_source}
2618 {mc "Run git gui blame on this line" command {external_blame_diff}}
2620 $diff_menu configure -tearoff 0
2623 # Windows sends all mouse wheel events to the current focused window, not
2624 # the one where the mouse hovers, so bind those events here and redirect
2625 # to the correct window
2626 proc windows_mousewheel_redirector {W X Y D} {
2627 global canv canv2 canv3
2628 set w [winfo containing -displayof $W $X $Y]
2630 set u [expr {$D < 0 ? 5 : -5}]
2631 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2632 allcanvs yview scroll $u units
2635 $w yview scroll $u units
2641 # Update row number label when selectedline changes
2642 proc selectedline_change {n1 n2 op} {
2643 global selectedline rownumsel
2645 if {$selectedline eq {}} {
2648 set rownumsel [expr {$selectedline + 1}]
2652 # mouse-2 makes all windows scan vertically, but only the one
2653 # the cursor is in scans horizontally
2654 proc canvscan {op w x y} {
2655 global canv canv2 canv3
2656 foreach c [list $canv $canv2 $canv3] {
2665 proc scrollcanv {cscroll f0 f1} {
2666 $cscroll set $f0 $f1
2671 # when we make a key binding for the toplevel, make sure
2672 # it doesn't get triggered when that key is pressed in the
2673 # find string entry widget.
2674 proc bindkey {ev script} {
2677 set escript [bind Entry $ev]
2678 if {$escript == {}} {
2679 set escript [bind Entry <Key>]
2681 foreach e $entries {
2682 bind $e $ev "$escript; break"
2686 proc bindmodfunctionkey {mod n script} {
2687 bind . <$mod-F$n> $script
2688 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2691 # set the focus back to the toplevel for any click outside
2694 global ctext entries
2695 foreach e [concat $entries $ctext] {
2696 if {$w == $e} return
2701 # Adjust the progress bar for a change in requested extent or canvas size
2702 proc adjustprogress {} {
2703 global progresscanv progressitem progresscoords
2704 global fprogitem fprogcoord lastprogupdate progupdatepending
2705 global rprogitem rprogcoord use_ttk
2708 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2712 set w [expr {[winfo width $progresscanv] - 4}]
2713 set x0 [expr {$w * [lindex $progresscoords 0]}]
2714 set x1 [expr {$w * [lindex $progresscoords 1]}]
2715 set h [winfo height $progresscanv]
2716 $progresscanv coords $progressitem $x0 0 $x1 $h
2717 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2718 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2719 set now [clock clicks -milliseconds]
2720 if {$now >= $lastprogupdate + 100} {
2721 set progupdatepending 0
2723 } elseif {!$progupdatepending} {
2724 set progupdatepending 1
2725 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2729 proc doprogupdate {} {
2730 global lastprogupdate progupdatepending
2732 if {$progupdatepending} {
2733 set progupdatepending 0
2734 set lastprogupdate [clock clicks -milliseconds]
2739 proc savestuff {w} {
2740 global canv canv2 canv3 mainfont textfont uifont tabstop
2741 global stuffsaved findmergefiles maxgraphpct
2742 global maxwidth showneartags showlocalchanges
2743 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2744 global cmitmode wrapcomment datetimeformat limitdiffs
2745 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2746 global uifgcolor uifgdisabledcolor
2747 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2748 global tagbgcolor tagfgcolor tagoutlinecolor
2749 global reflinecolor filesepbgcolor filesepfgcolor
2750 global mergecolors foundbgcolor currentsearchhitbgcolor
2751 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2752 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2753 global linkfgcolor circleoutlinecolor
2754 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2755 global hideremotes want_ttk maxrefs
2757 if {$stuffsaved} return
2758 if {![winfo viewable .]} return
2760 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2761 set f [open "~/.gitk-new" w]
2762 if {$::tcl_platform(platform) eq {windows}} {
2763 file attributes "~/.gitk-new" -hidden true
2765 puts $f [list set mainfont $mainfont]
2766 puts $f [list set textfont $textfont]
2767 puts $f [list set uifont $uifont]
2768 puts $f [list set tabstop $tabstop]
2769 puts $f [list set findmergefiles $findmergefiles]
2770 puts $f [list set maxgraphpct $maxgraphpct]
2771 puts $f [list set maxwidth $maxwidth]
2772 puts $f [list set cmitmode $cmitmode]
2773 puts $f [list set wrapcomment $wrapcomment]
2774 puts $f [list set autoselect $autoselect]
2775 puts $f [list set autosellen $autosellen]
2776 puts $f [list set showneartags $showneartags]
2777 puts $f [list set maxrefs $maxrefs]
2778 puts $f [list set hideremotes $hideremotes]
2779 puts $f [list set showlocalchanges $showlocalchanges]
2780 puts $f [list set datetimeformat $datetimeformat]
2781 puts $f [list set limitdiffs $limitdiffs]
2782 puts $f [list set uicolor $uicolor]
2783 puts $f [list set want_ttk $want_ttk]
2784 puts $f [list set bgcolor $bgcolor]
2785 puts $f [list set fgcolor $fgcolor]
2786 puts $f [list set uifgcolor $uifgcolor]
2787 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2788 puts $f [list set colors $colors]
2789 puts $f [list set diffcolors $diffcolors]
2790 puts $f [list set mergecolors $mergecolors]
2791 puts $f [list set markbgcolor $markbgcolor]
2792 puts $f [list set diffcontext $diffcontext]
2793 puts $f [list set selectbgcolor $selectbgcolor]
2794 puts $f [list set foundbgcolor $foundbgcolor]
2795 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2796 puts $f [list set extdifftool $extdifftool]
2797 puts $f [list set perfile_attrs $perfile_attrs]
2798 puts $f [list set headbgcolor $headbgcolor]
2799 puts $f [list set headfgcolor $headfgcolor]
2800 puts $f [list set headoutlinecolor $headoutlinecolor]
2801 puts $f [list set remotebgcolor $remotebgcolor]
2802 puts $f [list set tagbgcolor $tagbgcolor]
2803 puts $f [list set tagfgcolor $tagfgcolor]
2804 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2805 puts $f [list set reflinecolor $reflinecolor]
2806 puts $f [list set filesepbgcolor $filesepbgcolor]
2807 puts $f [list set filesepfgcolor $filesepfgcolor]
2808 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2809 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2810 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2811 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2812 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2813 puts $f [list set indexcirclecolor $indexcirclecolor]
2814 puts $f [list set circlecolors $circlecolors]
2815 puts $f [list set linkfgcolor $linkfgcolor]
2816 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2818 puts $f "set geometry(main) [wm geometry .]"
2819 puts $f "set geometry(state) [wm state .]"
2820 puts $f "set geometry(topwidth) [winfo width .tf]"
2821 puts $f "set geometry(topheight) [winfo height .tf]"
2823 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2824 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2826 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2827 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2829 puts $f "set geometry(botwidth) [winfo width .bleft]"
2830 puts $f "set geometry(botheight) [winfo height .bleft]"
2832 puts -nonewline $f "set permviews {"
2833 for {set v 0} {$v < $nextviewnum} {incr v} {
2834 if {$viewperm($v)} {
2835 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2840 file rename -force "~/.gitk-new" "~/.gitk"
2845 proc resizeclistpanes {win w} {
2846 global oldwidth use_ttk
2847 if {[info exists oldwidth($win)]} {
2849 set s0 [$win sashpos 0]
2850 set s1 [$win sashpos 1]
2852 set s0 [$win sash coord 0]
2853 set s1 [$win sash coord 1]
2856 set sash0 [expr {int($w/2 - 2)}]
2857 set sash1 [expr {int($w*5/6 - 2)}]
2859 set factor [expr {1.0 * $w / $oldwidth($win)}]
2860 set sash0 [expr {int($factor * [lindex $s0 0])}]
2861 set sash1 [expr {int($factor * [lindex $s1 0])}]
2865 if {$sash1 < $sash0 + 20} {
2866 set sash1 [expr {$sash0 + 20}]
2868 if {$sash1 > $w - 10} {
2869 set sash1 [expr {$w - 10}]
2870 if {$sash0 > $sash1 - 20} {
2871 set sash0 [expr {$sash1 - 20}]
2876 $win sashpos 0 $sash0
2877 $win sashpos 1 $sash1
2879 $win sash place 0 $sash0 [lindex $s0 1]
2880 $win sash place 1 $sash1 [lindex $s1 1]
2883 set oldwidth($win) $w
2886 proc resizecdetpanes {win w} {
2887 global oldwidth use_ttk
2888 if {[info exists oldwidth($win)]} {
2890 set s0 [$win sashpos 0]
2892 set s0 [$win sash coord 0]
2895 set sash0 [expr {int($w*3/4 - 2)}]
2897 set factor [expr {1.0 * $w / $oldwidth($win)}]
2898 set sash0 [expr {int($factor * [lindex $s0 0])}]
2902 if {$sash0 > $w - 15} {
2903 set sash0 [expr {$w - 15}]
2907 $win sashpos 0 $sash0
2909 $win sash place 0 $sash0 [lindex $s0 1]
2912 set oldwidth($win) $w
2915 proc allcanvs args {
2916 global canv canv2 canv3
2922 proc bindall {event action} {
2923 global canv canv2 canv3
2924 bind $canv $event $action
2925 bind $canv2 $event $action
2926 bind $canv3 $event $action
2932 if {[winfo exists $w]} {
2937 wm title $w [mc "About gitk"]
2939 message $w.m -text [mc "
2940 Gitk - a commit viewer for git
2942 Copyright \u00a9 2005-2011 Paul Mackerras
2944 Use and redistribute under the terms of the GNU General Public License"] \
2945 -justify center -aspect 400 -border 2 -bg white -relief groove
2946 pack $w.m -side top -fill x -padx 2 -pady 2
2947 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2948 pack $w.ok -side bottom
2949 bind $w <Visibility> "focus $w.ok"
2950 bind $w <Key-Escape> "destroy $w"
2951 bind $w <Key-Return> "destroy $w"
2952 tk::PlaceWindow $w widget .
2958 if {[winfo exists $w]} {
2962 if {[tk windowingsystem] eq {aqua}} {
2968 wm title $w [mc "Gitk key bindings"]
2970 message $w.m -text "
2971 [mc "Gitk key bindings:"]
2973 [mc "<%s-Q> Quit" $M1T]
2974 [mc "<%s-W> Close window" $M1T]
2975 [mc "<Home> Move to first commit"]
2976 [mc "<End> Move to last commit"]
2977 [mc "<Up>, p, k Move up one commit"]
2978 [mc "<Down>, n, j Move down one commit"]
2979 [mc "<Left>, z, h Go back in history list"]
2980 [mc "<Right>, x, l Go forward in history list"]
2981 [mc "<PageUp> Move up one page in commit list"]
2982 [mc "<PageDown> Move down one page in commit list"]
2983 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2984 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2985 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2986 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2987 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2988 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2989 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2990 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2991 [mc "<Delete>, b Scroll diff view up one page"]
2992 [mc "<Backspace> Scroll diff view up one page"]
2993 [mc "<Space> Scroll diff view down one page"]
2994 [mc "u Scroll diff view up 18 lines"]
2995 [mc "d Scroll diff view down 18 lines"]
2996 [mc "<%s-F> Find" $M1T]
2997 [mc "<%s-G> Move to next find hit" $M1T]
2998 [mc "<Return> Move to next find hit"]
2999 [mc "/ Focus the search box"]
3000 [mc "? Move to previous find hit"]
3001 [mc "f Scroll diff view to next file"]
3002 [mc "<%s-S> Search for next hit in diff view" $M1T]
3003 [mc "<%s-R> Search for previous hit in diff view" $M1T]
3004 [mc "<%s-KP+> Increase font size" $M1T]
3005 [mc "<%s-plus> Increase font size" $M1T]
3006 [mc "<%s-KP-> Decrease font size" $M1T]
3007 [mc "<%s-minus> Decrease font size" $M1T]
3010 -justify left -bg white -border 2 -relief groove
3011 pack $w.m -side top -fill both -padx 2 -pady 2
3012 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3013 bind $w <Key-Escape> [list destroy $w]
3014 pack $w.ok -side bottom
3015 bind $w <Visibility> "focus $w.ok"
3016 bind $w <Key-Escape> "destroy $w"
3017 bind $w <Key-Return> "destroy $w"
3020 # Procedures for manipulating the file list window at the
3021 # bottom right of the overall window.
3023 proc treeview {w l openlevs} {
3024 global treecontents treediropen treeheight treeparent treeindex
3034 set treecontents() {}
3035 $w conf -state normal
3037 while {[string range $f 0 $prefixend] ne $prefix} {
3038 if {$lev <= $openlevs} {
3039 $w mark set e:$treeindex($prefix) "end -1c"
3040 $w mark gravity e:$treeindex($prefix) left
3042 set treeheight($prefix) $ht
3043 incr ht [lindex $htstack end]
3044 set htstack [lreplace $htstack end end]
3045 set prefixend [lindex $prefendstack end]
3046 set prefendstack [lreplace $prefendstack end end]
3047 set prefix [string range $prefix 0 $prefixend]
3050 set tail [string range $f [expr {$prefixend+1}] end]
3051 while {[set slash [string first "/" $tail]] >= 0} {
3054 lappend prefendstack $prefixend
3055 incr prefixend [expr {$slash + 1}]
3056 set d [string range $tail 0 $slash]
3057 lappend treecontents($prefix) $d
3058 set oldprefix $prefix
3060 set treecontents($prefix) {}
3061 set treeindex($prefix) [incr ix]
3062 set treeparent($prefix) $oldprefix
3063 set tail [string range $tail [expr {$slash+1}] end]
3064 if {$lev <= $openlevs} {
3066 set treediropen($prefix) [expr {$lev < $openlevs}]
3067 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3068 $w mark set d:$ix "end -1c"
3069 $w mark gravity d:$ix left
3071 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3073 $w image create end -align center -image $bm -padx 1 \
3075 $w insert end $d [highlight_tag $prefix]
3076 $w mark set s:$ix "end -1c"
3077 $w mark gravity s:$ix left
3082 if {$lev <= $openlevs} {
3085 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3087 $w insert end $tail [highlight_tag $f]
3089 lappend treecontents($prefix) $tail
3092 while {$htstack ne {}} {
3093 set treeheight($prefix) $ht
3094 incr ht [lindex $htstack end]
3095 set htstack [lreplace $htstack end end]
3096 set prefixend [lindex $prefendstack end]
3097 set prefendstack [lreplace $prefendstack end end]
3098 set prefix [string range $prefix 0 $prefixend]
3100 $w conf -state disabled
3103 proc linetoelt {l} {
3104 global treeheight treecontents
3109 foreach e $treecontents($prefix) {
3114 if {[string index $e end] eq "/"} {
3115 set n $treeheight($prefix$e)
3127 proc highlight_tree {y prefix} {
3128 global treeheight treecontents cflist
3130 foreach e $treecontents($prefix) {
3132 if {[highlight_tag $path] ne {}} {
3133 $cflist tag add bold $y.0 "$y.0 lineend"
3136 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3137 set y [highlight_tree $y $path]
3143 proc treeclosedir {w dir} {
3144 global treediropen treeheight treeparent treeindex
3146 set ix $treeindex($dir)
3147 $w conf -state normal
3148 $w delete s:$ix e:$ix
3149 set treediropen($dir) 0
3150 $w image configure a:$ix -image tri-rt
3151 $w conf -state disabled
3152 set n [expr {1 - $treeheight($dir)}]
3153 while {$dir ne {}} {
3154 incr treeheight($dir) $n
3155 set dir $treeparent($dir)
3159 proc treeopendir {w dir} {
3160 global treediropen treeheight treeparent treecontents treeindex
3162 set ix $treeindex($dir)
3163 $w conf -state normal
3164 $w image configure a:$ix -image tri-dn
3165 $w mark set e:$ix s:$ix
3166 $w mark gravity e:$ix right
3169 set n [llength $treecontents($dir)]
3170 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3173 incr treeheight($x) $n
3175 foreach e $treecontents($dir) {
3177 if {[string index $e end] eq "/"} {
3178 set iy $treeindex($de)
3179 $w mark set d:$iy e:$ix
3180 $w mark gravity d:$iy left
3181 $w insert e:$ix $str
3182 set treediropen($de) 0
3183 $w image create e:$ix -align center -image tri-rt -padx 1 \
3185 $w insert e:$ix $e [highlight_tag $de]
3186 $w mark set s:$iy e:$ix
3187 $w mark gravity s:$iy left
3188 set treeheight($de) 1
3190 $w insert e:$ix $str
3191 $w insert e:$ix $e [highlight_tag $de]
3194 $w mark gravity e:$ix right
3195 $w conf -state disabled
3196 set treediropen($dir) 1
3197 set top [lindex [split [$w index @0,0] .] 0]
3198 set ht [$w cget -height]
3199 set l [lindex [split [$w index s:$ix] .] 0]
3202 } elseif {$l + $n + 1 > $top + $ht} {
3203 set top [expr {$l + $n + 2 - $ht}]
3211 proc treeclick {w x y} {
3212 global treediropen cmitmode ctext cflist cflist_top
3214 if {$cmitmode ne "tree"} return
3215 if {![info exists cflist_top]} return
3216 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3217 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3218 $cflist tag add highlight $l.0 "$l.0 lineend"
3224 set e [linetoelt $l]
3225 if {[string index $e end] ne "/"} {
3227 } elseif {$treediropen($e)} {
3234 proc setfilelist {id} {
3235 global treefilelist cflist jump_to_here
3237 treeview $cflist $treefilelist($id) 0
3238 if {$jump_to_here ne {}} {
3239 set f [lindex $jump_to_here 0]
3240 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3246 image create bitmap tri-rt -background black -foreground blue -data {
3247 #define tri-rt_width 13
3248 #define tri-rt_height 13
3249 static unsigned char tri-rt_bits[] = {
3250 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3251 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3254 #define tri-rt-mask_width 13
3255 #define tri-rt-mask_height 13
3256 static unsigned char tri-rt-mask_bits[] = {
3257 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3258 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3261 image create bitmap tri-dn -background black -foreground blue -data {
3262 #define tri-dn_width 13
3263 #define tri-dn_height 13
3264 static unsigned char tri-dn_bits[] = {
3265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3266 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3269 #define tri-dn-mask_width 13
3270 #define tri-dn-mask_height 13
3271 static unsigned char tri-dn-mask_bits[] = {
3272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3273 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3277 image create bitmap reficon-T -background black -foreground yellow -data {
3278 #define tagicon_width 13
3279 #define tagicon_height 9
3280 static unsigned char tagicon_bits[] = {
3281 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3282 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3284 #define tagicon-mask_width 13
3285 #define tagicon-mask_height 9
3286 static unsigned char tagicon-mask_bits[] = {
3287 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3288 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3291 #define headicon_width 13
3292 #define headicon_height 9
3293 static unsigned char headicon_bits[] = {
3294 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3295 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3298 #define headicon-mask_width 13
3299 #define headicon-mask_height 9
3300 static unsigned char headicon-mask_bits[] = {
3301 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3302 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3304 image create bitmap reficon-H -background black -foreground green \
3305 -data $rectdata -maskdata $rectmask
3306 image create bitmap reficon-o -background black -foreground "#ddddff" \
3307 -data $rectdata -maskdata $rectmask
3309 proc init_flist {first} {
3310 global cflist cflist_top difffilestart
3312 $cflist conf -state normal
3313 $cflist delete 0.0 end
3315 $cflist insert end $first
3317 $cflist tag add highlight 1.0 "1.0 lineend"
3319 catch {unset cflist_top}
3321 $cflist conf -state disabled
3322 set difffilestart {}
3325 proc highlight_tag {f} {
3326 global highlight_paths
3328 foreach p $highlight_paths {
3329 if {[string match $p $f]} {
3336 proc highlight_filelist {} {
3337 global cmitmode cflist
3339 $cflist conf -state normal
3340 if {$cmitmode ne "tree"} {
3341 set end [lindex [split [$cflist index end] .] 0]
3342 for {set l 2} {$l < $end} {incr l} {
3343 set line [$cflist get $l.0 "$l.0 lineend"]
3344 if {[highlight_tag $line] ne {}} {
3345 $cflist tag add bold $l.0 "$l.0 lineend"
3351 $cflist conf -state disabled
3354 proc unhighlight_filelist {} {
3357 $cflist conf -state normal
3358 $cflist tag remove bold 1.0 end
3359 $cflist conf -state disabled
3362 proc add_flist {fl} {
3365 $cflist conf -state normal
3367 $cflist insert end "\n"
3368 $cflist insert end $f [highlight_tag $f]
3370 $cflist conf -state disabled
3373 proc sel_flist {w x y} {
3374 global ctext difffilestart cflist cflist_top cmitmode
3376 if {$cmitmode eq "tree"} return
3377 if {![info exists cflist_top]} return
3378 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3379 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3380 $cflist tag add highlight $l.0 "$l.0 lineend"
3385 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3387 suppress_highlighting_file_for_current_scrollpos
3390 proc pop_flist_menu {w X Y x y} {
3391 global ctext cflist cmitmode flist_menu flist_menu_file
3392 global treediffs diffids
3395 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3397 if {$cmitmode eq "tree"} {
3398 set e [linetoelt $l]
3399 if {[string index $e end] eq "/"} return
3401 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3403 set flist_menu_file $e
3404 set xdiffstate "normal"
3405 if {$cmitmode eq "tree"} {
3406 set xdiffstate "disabled"
3408 # Disable "External diff" item in tree mode
3409 $flist_menu entryconf 2 -state $xdiffstate
3410 tk_popup $flist_menu $X $Y
3413 proc find_ctext_fileinfo {line} {
3414 global ctext_file_names ctext_file_lines
3416 set ok [bsearch $ctext_file_lines $line]
3417 set tline [lindex $ctext_file_lines $ok]
3419 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3422 return [list [lindex $ctext_file_names $ok] $tline]
3426 proc pop_diff_menu {w X Y x y} {
3427 global ctext diff_menu flist_menu_file
3428 global diff_menu_txtpos diff_menu_line
3429 global diff_menu_filebase
3431 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3432 set diff_menu_line [lindex $diff_menu_txtpos 0]
3433 # don't pop up the menu on hunk-separator or file-separator lines
3434 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3438 set f [find_ctext_fileinfo $diff_menu_line]
3439 if {$f eq {}} return
3440 set flist_menu_file [lindex $f 0]
3441 set diff_menu_filebase [lindex $f 1]
3442 tk_popup $diff_menu $X $Y
3445 proc flist_hl {only} {
3446 global flist_menu_file findstring gdttype
3448 set x [shellquote $flist_menu_file]
3449 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3452 append findstring " " $x
3454 set gdttype [mc "touching paths:"]
3457 proc gitknewtmpdir {} {
3458 global diffnum gitktmpdir gitdir
3460 if {![info exists gitktmpdir]} {
3461 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3462 if {[catch {file mkdir $gitktmpdir} err]} {
3463 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3470 set diffdir [file join $gitktmpdir $diffnum]
3471 if {[catch {file mkdir $diffdir} err]} {
3472 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3478 proc save_file_from_commit {filename output what} {
3481 if {[catch {exec git show $filename -- > $output} err]} {
3482 if {[string match "fatal: bad revision *" $err]} {
3485 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3491 proc external_diff_get_one_file {diffid filename diffdir} {
3492 global nullid nullid2 nullfile
3495 if {$diffid == $nullid} {
3496 set difffile [file join $worktree $filename]
3497 if {[file exists $difffile]} {
3502 if {$diffid == $nullid2} {
3503 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3504 return [save_file_from_commit :$filename $difffile index]
3506 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3507 return [save_file_from_commit $diffid:$filename $difffile \
3511 proc external_diff {} {
3512 global nullid nullid2
3513 global flist_menu_file
3517 if {[llength $diffids] == 1} {
3518 # no reference commit given
3519 set diffidto [lindex $diffids 0]
3520 if {$diffidto eq $nullid} {
3521 # diffing working copy with index
3522 set diffidfrom $nullid2
3523 } elseif {$diffidto eq $nullid2} {
3524 # diffing index with HEAD
3525 set diffidfrom "HEAD"
3527 # use first parent commit
3528 global parentlist selectedline
3529 set diffidfrom [lindex $parentlist $selectedline 0]
3532 set diffidfrom [lindex $diffids 0]
3533 set diffidto [lindex $diffids 1]
3536 # make sure that several diffs wont collide
3537 set diffdir [gitknewtmpdir]
3538 if {$diffdir eq {}} return
3540 # gather files to diff
3541 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3542 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3544 if {$difffromfile ne {} && $difftofile ne {}} {
3545 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3546 if {[catch {set fl [open |$cmd r]} err]} {
3547 file delete -force $diffdir
3548 error_popup "$extdifftool: [mc "command failed:"] $err"
3550 fconfigure $fl -blocking 0
3551 filerun $fl [list delete_at_eof $fl $diffdir]
3556 proc find_hunk_blamespec {base line} {
3559 # Find and parse the hunk header
3560 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3561 if {$s_lix eq {}} return
3563 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3564 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3565 s_line old_specs osz osz1 new_line nsz]} {
3569 # base lines for the parents
3570 set base_lines [list $new_line]
3571 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3572 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3573 old_spec old_line osz]} {
3576 lappend base_lines $old_line
3579 # Now scan the lines to determine offset within the hunk
3580 set max_parent [expr {[llength $base_lines]-2}]
3582 set s_lno [lindex [split $s_lix "."] 0]
3584 # Determine if the line is removed
3585 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3586 if {[string match {[-+ ]*} $chunk]} {
3587 set removed_idx [string first "-" $chunk]
3588 # Choose a parent index
3589 if {$removed_idx >= 0} {
3590 set parent $removed_idx
3592 set unchanged_idx [string first " " $chunk]
3593 if {$unchanged_idx >= 0} {
3594 set parent $unchanged_idx
3596 # blame the current commit
3600 # then count other lines that belong to it
3601 for {set i $line} {[incr i -1] > $s_lno} {} {
3602 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3603 # Determine if the line is removed
3604 set removed_idx [string first "-" $chunk]
3606 set code [string index $chunk $parent]
3607 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3611 if {$removed_idx < 0} {
3621 incr dline [lindex $base_lines $parent]
3622 return [list $parent $dline]
3625 proc external_blame_diff {} {
3626 global currentid cmitmode
3627 global diff_menu_txtpos diff_menu_line
3628 global diff_menu_filebase flist_menu_file
3630 if {$cmitmode eq "tree"} {
3632 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3634 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3636 set parent_idx [lindex $hinfo 0]
3637 set line [lindex $hinfo 1]
3644 external_blame $parent_idx $line
3647 # Find the SHA1 ID of the blob for file $fname in the index
3649 proc index_sha1 {fname} {
3650 set f [open [list | git ls-files -s $fname] r]
3651 while {[gets $f line] >= 0} {
3652 set info [lindex [split $line "\t"] 0]
3653 set stage [lindex $info 2]
3654 if {$stage eq "0" || $stage eq "2"} {
3656 return [lindex $info 1]
3663 # Turn an absolute path into one relative to the current directory
3664 proc make_relative {f} {
3665 if {[file pathtype $f] eq "relative"} {
3668 set elts [file split $f]
3669 set here [file split [pwd]]
3674 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3681 set elts [concat $res [lrange $elts $ei end]]
3682 return [eval file join $elts]
3685 proc external_blame {parent_idx {line {}}} {
3686 global flist_menu_file cdup
3687 global nullid nullid2
3688 global parentlist selectedline currentid
3690 if {$parent_idx > 0} {
3691 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3693 set base_commit $currentid
3696 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3697 error_popup [mc "No such commit"]
3701 set cmdline [list git gui blame]
3702 if {$line ne {} && $line > 1} {
3703 lappend cmdline "--line=$line"
3705 set f [file join $cdup $flist_menu_file]
3706 # Unfortunately it seems git gui blame doesn't like
3707 # being given an absolute path...
3708 set f [make_relative $f]
3709 lappend cmdline $base_commit $f
3710 if {[catch {eval exec $cmdline &} err]} {
3711 error_popup "[mc "git gui blame: command failed:"] $err"
3715 proc show_line_source {} {
3716 global cmitmode currentid parents curview blamestuff blameinst
3717 global diff_menu_line diff_menu_filebase flist_menu_file
3718 global nullid nullid2 gitdir cdup
3721 if {$cmitmode eq "tree"} {
3723 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3725 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3726 if {$h eq {}} return
3727 set pi [lindex $h 0]
3729 mark_ctext_line $diff_menu_line
3733 if {$currentid eq $nullid} {
3735 # must be a merge in progress...
3737 # get the last line from .git/MERGE_HEAD
3738 set f [open [file join $gitdir MERGE_HEAD] r]
3739 set id [lindex [split [read $f] "\n"] end-1]
3742 error_popup [mc "Couldn't read merge head: %s" $err]
3745 } elseif {$parents($curview,$currentid) eq $nullid2} {
3746 # need to do the blame from the index
3748 set from_index [index_sha1 $flist_menu_file]
3750 error_popup [mc "Error reading index: %s" $err]
3754 set id $parents($curview,$currentid)
3757 set id [lindex $parents($curview,$currentid) $pi]
3759 set line [lindex $h 1]
3762 if {$from_index ne {}} {
3763 lappend blameargs | git cat-file blob $from_index
3765 lappend blameargs | git blame -p -L$line,+1
3766 if {$from_index ne {}} {
3767 lappend blameargs --contents -
3769 lappend blameargs $id
3771 lappend blameargs -- [file join $cdup $flist_menu_file]
3773 set f [open $blameargs r]
3775 error_popup [mc "Couldn't start git blame: %s" $err]
3778 nowbusy blaming [mc "Searching"]
3779 fconfigure $f -blocking 0
3780 set i [reg_instance $f]
3781 set blamestuff($i) {}
3783 filerun $f [list read_line_source $f $i]
3786 proc stopblaming {} {
3789 if {[info exists blameinst]} {
3790 stop_instance $blameinst
3796 proc read_line_source {fd inst} {
3797 global blamestuff curview commfd blameinst nullid nullid2
3799 while {[gets $fd line] >= 0} {
3800 lappend blamestuff($inst) $line
3808 fconfigure $fd -blocking 1
3809 if {[catch {close $fd} err]} {
3810 error_popup [mc "Error running git blame: %s" $err]
3815 set line [split [lindex $blamestuff($inst) 0] " "]
3816 set id [lindex $line 0]
3817 set lnum [lindex $line 1]
3818 if {[string length $id] == 40 && [string is xdigit $id] &&
3819 [string is digit -strict $lnum]} {
3820 # look for "filename" line
3821 foreach l $blamestuff($inst) {
3822 if {[string match "filename *" $l]} {
3823 set fname [string range $l 9 end]
3829 # all looks good, select it
3830 if {$id eq $nullid} {
3831 # blame uses all-zeroes to mean not committed,
3832 # which would mean a change in the index
3835 if {[commitinview $id $curview]} {
3836 selectline [rowofcommit $id] 1 [list $fname $lnum]
3838 error_popup [mc "That line comes from commit %s, \
3839 which is not in this view" [shortids $id]]
3842 puts "oops couldn't parse git blame output"
3847 # delete $dir when we see eof on $f (presumably because the child has exited)
3848 proc delete_at_eof {f dir} {
3849 while {[gets $f line] >= 0} {}
3851 if {[catch {close $f} err]} {
3852 error_popup "[mc "External diff viewer failed:"] $err"
3854 file delete -force $dir
3860 # Functions for adding and removing shell-type quoting
3862 proc shellquote {str} {
3863 if {![string match "*\['\"\\ \t]*" $str]} {
3866 if {![string match "*\['\"\\]*" $str]} {
3869 if {![string match "*'*" $str]} {
3872 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3875 proc shellarglist {l} {
3881 append str [shellquote $a]
3886 proc shelldequote {str} {
3891 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3892 append ret [string range $str $used end]
3893 set used [string length $str]
3896 set first [lindex $first 0]
3897 set ch [string index $str $first]
3898 if {$first > $used} {
3899 append ret [string range $str $used [expr {$first - 1}]]
3902 if {$ch eq " " || $ch eq "\t"} break
3905 set first [string first "'" $str $used]
3907 error "unmatched single-quote"
3909 append ret [string range $str $used [expr {$first - 1}]]
3914 if {$used >= [string length $str]} {
3915 error "trailing backslash"
3917 append ret [string index $str $used]
3922 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3923 error "unmatched double-quote"
3925 set first [lindex $first 0]
3926 set ch [string index $str $first]
3927 if {$first > $used} {
3928 append ret [string range $str $used [expr {$first - 1}]]
3931 if {$ch eq "\""} break
3933 append ret [string index $str $used]
3937 return [list $used $ret]
3940 proc shellsplit {str} {
3943 set str [string trimleft $str]
3944 if {$str eq {}} break
3945 set dq [shelldequote $str]
3946 set n [lindex $dq 0]
3947 set word [lindex $dq 1]
3948 set str [string range $str $n end]
3954 # Code to implement multiple views
3956 proc newview {ishighlight} {
3957 global nextviewnum newviewname newishighlight
3958 global revtreeargs viewargscmd newviewopts curview
3960 set newishighlight $ishighlight
3962 if {[winfo exists $top]} {
3966 decode_view_opts $nextviewnum $revtreeargs
3967 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3968 set newviewopts($nextviewnum,perm) 0
3969 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3970 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3973 set known_view_options {
3974 {perm b . {} {mc "Remember this view"}}
3975 {reflabel l + {} {mc "References (space separated list):"}}
3976 {refs t15 .. {} {mc "Branches & tags:"}}
3977 {allrefs b *. "--all" {mc "All refs"}}
3978 {branches b . "--branches" {mc "All (local) branches"}}
3979 {tags b . "--tags" {mc "All tags"}}
3980 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3981 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3982 {author t15 .. "--author=*" {mc "Author:"}}
3983 {committer t15 . "--committer=*" {mc "Committer:"}}
3984 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3985 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3986 {changes_l l + {} {mc "Changes to Files:"}}
3987 {pickaxe_s r0 . {} {mc "Fixed String"}}
3988 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3989 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3990 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3991 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3992 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3993 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3994 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3995 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3996 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3997 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3998 {lright b . "--left-right" {mc "Mark branch sides"}}
3999 {first b . "--first-parent" {mc "Limit to first parent"}}
4000 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
4001 {args t50 *. {} {mc "Additional arguments to git log:"}}
4002 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4003 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4006 # Convert $newviewopts($n, ...) into args for git log.
4007 proc encode_view_opts {n} {
4008 global known_view_options newviewopts
4011 foreach opt $known_view_options {
4012 set patterns [lindex $opt 3]
4013 if {$patterns eq {}} continue
4014 set pattern [lindex $patterns 0]
4016 if {[lindex $opt 1] eq "b"} {
4017 set val $newviewopts($n,[lindex $opt 0])
4019 lappend rargs $pattern
4021 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4022 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4023 set val $newviewopts($n,$button_id)
4024 if {$val eq $value} {
4025 lappend rargs $pattern
4028 set val $newviewopts($n,[lindex $opt 0])
4029 set val [string trim $val]
4031 set pfix [string range $pattern 0 end-1]
4032 lappend rargs $pfix$val
4036 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4037 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4040 # Fill $newviewopts($n, ...) based on args for git log.
4041 proc decode_view_opts {n view_args} {
4042 global known_view_options newviewopts
4044 foreach opt $known_view_options {
4045 set id [lindex $opt 0]
4046 if {[lindex $opt 1] eq "b"} {
4049 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4051 regexp {^(.*_)} $id uselessvar id
4057 set newviewopts($n,$id) $val
4061 foreach arg $view_args {
4062 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4063 && ![info exists found(limit)]} {
4064 set newviewopts($n,limit) $cnt
4069 foreach opt $known_view_options {
4070 set id [lindex $opt 0]
4071 if {[info exists found($id)]} continue
4072 foreach pattern [lindex $opt 3] {
4073 if {![string match $pattern $arg]} continue
4074 if {[lindex $opt 1] eq "b"} {
4077 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4079 regexp {^(.*_)} $id uselessvar id
4083 set size [string length $pattern]
4084 set val [string range $arg [expr {$size-1}] end]
4086 set newviewopts($n,$id) $val
4090 if {[info exists val]} break
4092 if {[info exists val]} continue
4093 if {[regexp {^-} $arg]} {
4096 lappend refargs $arg
4099 set newviewopts($n,refs) [shellarglist $refargs]
4100 set newviewopts($n,args) [shellarglist $oargs]
4103 proc edit_or_newview {} {
4115 global viewname viewperm newviewname newviewopts
4116 global viewargs viewargscmd
4118 set top .gitkvedit-$curview
4119 if {[winfo exists $top]} {
4123 decode_view_opts $curview $viewargs($curview)
4124 set newviewname($curview) $viewname($curview)
4125 set newviewopts($curview,perm) $viewperm($curview)
4126 set newviewopts($curview,cmd) $viewargscmd($curview)
4127 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4130 proc vieweditor {top n title} {
4131 global newviewname newviewopts viewfiles bgcolor
4132 global known_view_options NS
4135 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4136 make_transient $top .
4139 ${NS}::frame $top.nfr
4140 ${NS}::label $top.nl -text [mc "View Name"]
4141 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4142 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4143 pack $top.nl -in $top.nfr -side left -padx {0 5}
4144 pack $top.name -in $top.nfr -side left -padx {0 25}
4150 foreach opt $known_view_options {
4151 set id [lindex $opt 0]
4152 set type [lindex $opt 1]
4153 set flags [lindex $opt 2]
4154 set title [eval [lindex $opt 4]]
4157 if {$flags eq "+" || $flags eq "*"} {
4158 set cframe $top.fr$cnt
4160 ${NS}::frame $cframe
4161 pack $cframe -in $top -fill x -pady 3 -padx 3
4162 set cexpand [expr {$flags eq "*"}]
4163 } elseif {$flags eq ".." || $flags eq "*."} {
4164 set cframe $top.fr$cnt
4166 ${NS}::frame $cframe
4167 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4168 set cexpand [expr {$flags eq "*."}]
4174 ${NS}::label $cframe.l_$id -text $title
4175 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4176 } elseif {$type eq "b"} {
4177 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4178 pack $cframe.c_$id -in $cframe -side left \
4179 -padx [list $lxpad 0] -expand $cexpand -anchor w
4180 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4181 regexp {^(.*_)} $id uselessvar button_id
4182 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4183 pack $cframe.c_$id -in $cframe -side left \
4184 -padx [list $lxpad 0] -expand $cexpand -anchor w
4185 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4186 ${NS}::label $cframe.l_$id -text $title
4187 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4188 -textvariable newviewopts($n,$id)
4189 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4190 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4191 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4192 ${NS}::label $cframe.l_$id -text $title
4193 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4194 -textvariable newviewopts($n,$id)
4195 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4196 pack $cframe.e_$id -in $cframe -side top -fill x
4197 } elseif {$type eq "path"} {
4198 ${NS}::label $top.l -text $title
4199 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4200 text $top.t -width 40 -height 5 -background $bgcolor
4201 if {[info exists viewfiles($n)]} {
4202 foreach f $viewfiles($n) {
4203 $top.t insert end $f
4204 $top.t insert end "\n"
4206 $top.t delete {end - 1c} end
4207 $top.t mark set insert 0.0
4209 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4213 ${NS}::frame $top.buts
4214 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4215 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4216 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4217 bind $top <Control-Return> [list newviewok $top $n]
4218 bind $top <F5> [list newviewok $top $n 1]
4219 bind $top <Escape> [list destroy $top]
4220 grid $top.buts.ok $top.buts.apply $top.buts.can
4221 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4222 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4223 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4224 pack $top.buts -in $top -side top -fill x
4228 proc doviewmenu {m first cmd op argv} {
4229 set nmenu [$m index end]
4230 for {set i $first} {$i <= $nmenu} {incr i} {
4231 if {[$m entrycget $i -command] eq $cmd} {
4232 eval $m $op $i $argv
4238 proc allviewmenus {n op args} {
4241 doviewmenu .bar.view 5 [list showview $n] $op $args
4242 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4245 proc newviewok {top n {apply 0}} {
4246 global nextviewnum newviewperm newviewname newishighlight
4247 global viewname viewfiles viewperm selectedview curview
4248 global viewargs viewargscmd newviewopts viewhlmenu
4251 set newargs [encode_view_opts $n]
4253 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4257 foreach f [split [$top.t get 0.0 end] "\n"] {
4258 set ft [string trim $f]
4263 if {![info exists viewfiles($n)]} {
4264 # creating a new view
4266 set viewname($n) $newviewname($n)
4267 set viewperm($n) $newviewopts($n,perm)
4268 set viewfiles($n) $files
4269 set viewargs($n) $newargs
4270 set viewargscmd($n) $newviewopts($n,cmd)
4272 if {!$newishighlight} {
4275 run addvhighlight $n
4278 # editing an existing view
4279 set viewperm($n) $newviewopts($n,perm)
4280 if {$newviewname($n) ne $viewname($n)} {
4281 set viewname($n) $newviewname($n)
4282 doviewmenu .bar.view 5 [list showview $n] \
4283 entryconf [list -label $viewname($n)]
4284 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4285 # entryconf [list -label $viewname($n) -value $viewname($n)]
4287 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4288 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4289 set viewfiles($n) $files
4290 set viewargs($n) $newargs
4291 set viewargscmd($n) $newviewopts($n,cmd)
4292 if {$curview == $n} {
4298 catch {destroy $top}
4302 global curview viewperm hlview selectedhlview
4304 if {$curview == 0} return
4305 if {[info exists hlview] && $hlview == $curview} {
4306 set selectedhlview [mc "None"]
4309 allviewmenus $curview delete
4310 set viewperm($curview) 0
4314 proc addviewmenu {n} {
4315 global viewname viewhlmenu
4317 .bar.view add radiobutton -label $viewname($n) \
4318 -command [list showview $n] -variable selectedview -value $n
4319 #$viewhlmenu add radiobutton -label $viewname($n) \
4320 # -command [list addvhighlight $n] -variable selectedhlview
4324 global curview cached_commitrow ordertok
4325 global displayorder parentlist rowidlist rowisopt rowfinal
4326 global colormap rowtextx nextcolor canvxmax
4327 global numcommits viewcomplete
4328 global selectedline currentid canv canvy0
4330 global pending_select mainheadid
4333 global hlview selectedhlview commitinterest
4335 if {$n == $curview} return
4337 set ymax [lindex [$canv cget -scrollregion] 3]
4338 set span [$canv yview]
4339 set ytop [expr {[lindex $span 0] * $ymax}]
4340 set ybot [expr {[lindex $span 1] * $ymax}]
4341 set yscreen [expr {($ybot - $ytop) / 2}]
4342 if {$selectedline ne {}} {
4343 set selid $currentid
4344 set y [yc $selectedline]
4345 if {$ytop < $y && $y < $ybot} {
4346 set yscreen [expr {$y - $ytop}]
4348 } elseif {[info exists pending_select]} {
4349 set selid $pending_select
4350 unset pending_select
4354 catch {unset treediffs}
4356 if {[info exists hlview] && $hlview == $n} {
4358 set selectedhlview [mc "None"]
4360 catch {unset commitinterest}
4361 catch {unset cached_commitrow}
4362 catch {unset ordertok}
4366 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4367 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4370 if {![info exists viewcomplete($n)]} {
4380 set numcommits $commitidx($n)
4382 catch {unset colormap}
4383 catch {unset rowtextx}
4385 set canvxmax [$canv cget -width]
4391 if {$selid ne {} && [commitinview $selid $n]} {
4392 set row [rowofcommit $selid]
4393 # try to get the selected row in the same position on the screen
4394 set ymax [lindex [$canv cget -scrollregion] 3]
4395 set ytop [expr {[yc $row] - $yscreen}]
4399 set yf [expr {$ytop * 1.0 / $ymax}]
4401 allcanvs yview moveto $yf
4405 } elseif {!$viewcomplete($n)} {
4406 reset_pending_select $selid
4408 reset_pending_select {}
4410 if {[commitinview $pending_select $curview]} {
4411 selectline [rowofcommit $pending_select] 1
4413 set row [first_real_row]
4414 if {$row < $numcommits} {
4419 if {!$viewcomplete($n)} {
4420 if {$numcommits == 0} {
4421 show_status [mc "Reading commits..."]
4423 } elseif {$numcommits == 0} {
4424 show_status [mc "No commits selected"]
4428 # Stuff relating to the highlighting facility
4430 proc ishighlighted {id} {
4431 global vhighlights fhighlights nhighlights rhighlights
4433 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4434 return $nhighlights($id)
4436 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4437 return $vhighlights($id)
4439 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4440 return $fhighlights($id)
4442 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4443 return $rhighlights($id)
4448 proc bolden {id font} {
4449 global canv linehtag currentid boldids need_redisplay markedid
4451 # need_redisplay = 1 means the display is stale and about to be redrawn
4452 if {$need_redisplay} return
4454 $canv itemconf $linehtag($id) -font $font
4455 if {[info exists currentid] && $id eq $currentid} {
4457 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4458 -outline {{}} -tags secsel \
4459 -fill [$canv cget -selectbackground]]
4462 if {[info exists markedid] && $id eq $markedid} {
4467 proc bolden_name {id font} {
4468 global canv2 linentag currentid boldnameids need_redisplay
4470 if {$need_redisplay} return
4471 lappend boldnameids $id
4472 $canv2 itemconf $linentag($id) -font $font
4473 if {[info exists currentid] && $id eq $currentid} {
4474 $canv2 delete secsel
4475 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4476 -outline {{}} -tags secsel \
4477 -fill [$canv2 cget -selectbackground]]
4486 foreach id $boldids {
4487 if {![ishighlighted $id]} {
4490 lappend stillbold $id
4493 set boldids $stillbold
4496 proc addvhighlight {n} {
4497 global hlview viewcomplete curview vhl_done commitidx
4499 if {[info exists hlview]} {
4503 if {$n != $curview && ![info exists viewcomplete($n)]} {
4506 set vhl_done $commitidx($hlview)
4507 if {$vhl_done > 0} {
4512 proc delvhighlight {} {
4513 global hlview vhighlights
4515 if {![info exists hlview]} return
4517 catch {unset vhighlights}
4521 proc vhighlightmore {} {
4522 global hlview vhl_done commitidx vhighlights curview
4524 set max $commitidx($hlview)
4525 set vr [visiblerows]
4526 set r0 [lindex $vr 0]
4527 set r1 [lindex $vr 1]
4528 for {set i $vhl_done} {$i < $max} {incr i} {
4529 set id [commitonrow $i $hlview]
4530 if {[commitinview $id $curview]} {
4531 set row [rowofcommit $id]
4532 if {$r0 <= $row && $row <= $r1} {
4533 if {![highlighted $row]} {
4534 bolden $id mainfontbold
4536 set vhighlights($id) 1
4544 proc askvhighlight {row id} {
4545 global hlview vhighlights iddrawn
4547 if {[commitinview $id $hlview]} {
4548 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4549 bolden $id mainfontbold
4551 set vhighlights($id) 1
4553 set vhighlights($id) 0
4557 proc hfiles_change {} {
4558 global highlight_files filehighlight fhighlights fh_serial
4559 global highlight_paths
4561 if {[info exists filehighlight]} {
4562 # delete previous highlights
4563 catch {close $filehighlight}
4565 catch {unset fhighlights}
4567 unhighlight_filelist
4569 set highlight_paths {}
4570 after cancel do_file_hl $fh_serial
4572 if {$highlight_files ne {}} {
4573 after 300 do_file_hl $fh_serial
4577 proc gdttype_change {name ix op} {
4578 global gdttype highlight_files findstring findpattern
4581 if {$findstring ne {}} {
4582 if {$gdttype eq [mc "containing:"]} {
4583 if {$highlight_files ne {}} {
4584 set highlight_files {}
4589 if {$findpattern ne {}} {
4593 set highlight_files $findstring
4598 # enable/disable findtype/findloc menus too
4601 proc find_change {name ix op} {
4602 global gdttype findstring highlight_files
4605 if {$gdttype eq [mc "containing:"]} {
4608 if {$highlight_files ne $findstring} {
4609 set highlight_files $findstring
4616 proc findcom_change args {
4617 global nhighlights boldnameids
4618 global findpattern findtype findstring gdttype
4621 # delete previous highlights, if any
4622 foreach id $boldnameids {
4623 bolden_name $id mainfont
4626 catch {unset nhighlights}
4629 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4631 } elseif {$findtype eq [mc "Regexp"]} {
4632 set findpattern $findstring
4634 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4636 set findpattern "*$e*"
4640 proc makepatterns {l} {
4643 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4644 if {[string index $ee end] eq "/"} {
4654 proc do_file_hl {serial} {
4655 global highlight_files filehighlight highlight_paths gdttype fhl_list
4656 global cdup findtype
4658 if {$gdttype eq [mc "touching paths:"]} {
4659 # If "exact" match then convert backslashes to forward slashes.
4660 # Most useful to support Windows-flavoured file paths.
4661 if {$findtype eq [mc "Exact"]} {
4662 set highlight_files [string map {"\\" "/"} $highlight_files]
4664 if {[catch {set paths [shellsplit $highlight_files]}]} return
4665 set highlight_paths [makepatterns $paths]
4667 set relative_paths {}
4668 foreach path $paths {
4669 lappend relative_paths [file join $cdup $path]
4671 set gdtargs [concat -- $relative_paths]
4672 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4673 set gdtargs [list "-S$highlight_files"]
4674 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4675 set gdtargs [list "-G$highlight_files"]
4677 # must be "containing:", i.e. we're searching commit info
4680 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4681 set filehighlight [open $cmd r+]
4682 fconfigure $filehighlight -blocking 0
4683 filerun $filehighlight readfhighlight
4689 proc flushhighlights {} {
4690 global filehighlight fhl_list
4692 if {[info exists filehighlight]} {
4694 puts $filehighlight ""
4695 flush $filehighlight
4699 proc askfilehighlight {row id} {
4700 global filehighlight fhighlights fhl_list
4702 lappend fhl_list $id
4703 set fhighlights($id) -1
4704 puts $filehighlight $id
4707 proc readfhighlight {} {
4708 global filehighlight fhighlights curview iddrawn
4709 global fhl_list find_dirn
4711 if {![info exists filehighlight]} {
4715 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4716 set line [string trim $line]
4717 set i [lsearch -exact $fhl_list $line]
4718 if {$i < 0} continue
4719 for {set j 0} {$j < $i} {incr j} {
4720 set id [lindex $fhl_list $j]
4721 set fhighlights($id) 0
4723 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4724 if {$line eq {}} continue
4725 if {![commitinview $line $curview]} continue
4726 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4727 bolden $line mainfontbold
4729 set fhighlights($line) 1
4731 if {[eof $filehighlight]} {
4733 puts "oops, git diff-tree died"
4734 catch {close $filehighlight}
4738 if {[info exists find_dirn]} {
4744 proc doesmatch {f} {
4745 global findtype findpattern
4747 if {$findtype eq [mc "Regexp"]} {
4748 return [regexp $findpattern $f]
4749 } elseif {$findtype eq [mc "IgnCase"]} {
4750 return [string match -nocase $findpattern $f]
4752 return [string match $findpattern $f]
4756 proc askfindhighlight {row id} {
4757 global nhighlights commitinfo iddrawn
4759 global markingmatches
4761 if {![info exists commitinfo($id)]} {
4764 set info $commitinfo($id)
4766 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4767 foreach f $info ty $fldtypes {
4768 if {$ty eq ""} continue
4769 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4771 if {$ty eq [mc "Author"]} {
4778 if {$isbold && [info exists iddrawn($id)]} {
4779 if {![ishighlighted $id]} {
4780 bolden $id mainfontbold
4782 bolden_name $id mainfontbold
4785 if {$markingmatches} {
4786 markrowmatches $row $id
4789 set nhighlights($id) $isbold
4792 proc markrowmatches {row id} {
4793 global canv canv2 linehtag linentag commitinfo findloc
4795 set headline [lindex $commitinfo($id) 0]
4796 set author [lindex $commitinfo($id) 1]
4797 $canv delete match$row
4798 $canv2 delete match$row
4799 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4800 set m [findmatches $headline]
4802 markmatches $canv $row $headline $linehtag($id) $m \
4803 [$canv itemcget $linehtag($id) -font] $row
4806 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4807 set m [findmatches $author]
4809 markmatches $canv2 $row $author $linentag($id) $m \
4810 [$canv2 itemcget $linentag($id) -font] $row
4815 proc vrel_change {name ix op} {
4816 global highlight_related
4819 if {$highlight_related ne [mc "None"]} {
4824 # prepare for testing whether commits are descendents or ancestors of a
4825 proc rhighlight_sel {a} {
4826 global descendent desc_todo ancestor anc_todo
4827 global highlight_related
4829 catch {unset descendent}
4830 set desc_todo [list $a]
4831 catch {unset ancestor}
4832 set anc_todo [list $a]
4833 if {$highlight_related ne [mc "None"]} {
4839 proc rhighlight_none {} {
4842 catch {unset rhighlights}
4846 proc is_descendent {a} {
4847 global curview children descendent desc_todo
4850 set la [rowofcommit $a]
4854 for {set i 0} {$i < [llength $todo]} {incr i} {
4855 set do [lindex $todo $i]
4856 if {[rowofcommit $do] < $la} {
4857 lappend leftover $do
4860 foreach nk $children($v,$do) {
4861 if {![info exists descendent($nk)]} {
4862 set descendent($nk) 1
4870 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4874 set descendent($a) 0
4875 set desc_todo $leftover
4878 proc is_ancestor {a} {
4879 global curview parents ancestor anc_todo
4882 set la [rowofcommit $a]
4886 for {set i 0} {$i < [llength $todo]} {incr i} {
4887 set do [lindex $todo $i]
4888 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4889 lappend leftover $do
4892 foreach np $parents($v,$do) {
4893 if {![info exists ancestor($np)]} {
4902 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4907 set anc_todo $leftover
4910 proc askrelhighlight {row id} {
4911 global descendent highlight_related iddrawn rhighlights
4912 global selectedline ancestor
4914 if {$selectedline eq {}} return
4916 if {$highlight_related eq [mc "Descendant"] ||
4917 $highlight_related eq [mc "Not descendant"]} {
4918 if {![info exists descendent($id)]} {
4921 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4924 } elseif {$highlight_related eq [mc "Ancestor"] ||
4925 $highlight_related eq [mc "Not ancestor"]} {
4926 if {![info exists ancestor($id)]} {
4929 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4933 if {[info exists iddrawn($id)]} {
4934 if {$isbold && ![ishighlighted $id]} {
4935 bolden $id mainfontbold
4938 set rhighlights($id) $isbold
4941 # Graph layout functions
4943 proc shortids {ids} {
4946 if {[llength $id] > 1} {
4947 lappend res [shortids $id]
4948 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4949 lappend res [string range $id 0 7]
4960 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4961 if {($n & $mask) != 0} {
4962 set ret [concat $ret $o]
4964 set o [concat $o $o]
4969 proc ordertoken {id} {
4970 global ordertok curview varcid varcstart varctok curview parents children
4971 global nullid nullid2
4973 if {[info exists ordertok($id)]} {
4974 return $ordertok($id)
4979 if {[info exists varcid($curview,$id)]} {
4980 set a $varcid($curview,$id)
4981 set p [lindex $varcstart($curview) $a]
4983 set p [lindex $children($curview,$id) 0]
4985 if {[info exists ordertok($p)]} {
4986 set tok $ordertok($p)
4989 set id [first_real_child $curview,$p]
4992 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4995 if {[llength $parents($curview,$id)] == 1} {
4996 lappend todo [list $p {}]
4998 set j [lsearch -exact $parents($curview,$id) $p]
5000 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5002 lappend todo [list $p [strrep $j]]
5005 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5006 set p [lindex $todo $i 0]
5007 append tok [lindex $todo $i 1]
5008 set ordertok($p) $tok
5010 set ordertok($origid) $tok
5014 # Work out where id should go in idlist so that order-token
5015 # values increase from left to right
5016 proc idcol {idlist id {i 0}} {
5017 set t [ordertoken $id]
5021 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5022 if {$i > [llength $idlist]} {
5023 set i [llength $idlist]
5025 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5028 if {$t > [ordertoken [lindex $idlist $i]]} {
5029 while {[incr i] < [llength $idlist] &&
5030 $t >= [ordertoken [lindex $idlist $i]]} {}
5036 proc initlayout {} {
5037 global rowidlist rowisopt rowfinal displayorder parentlist
5038 global numcommits canvxmax canv
5040 global colormap rowtextx
5049 set canvxmax [$canv cget -width]
5050 catch {unset colormap}
5051 catch {unset rowtextx}
5055 proc setcanvscroll {} {
5056 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5057 global lastscrollset lastscrollrows
5059 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5060 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5061 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5062 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5063 set lastscrollset [clock clicks -milliseconds]
5064 set lastscrollrows $numcommits
5067 proc visiblerows {} {
5068 global canv numcommits linespc
5070 set ymax [lindex [$canv cget -scrollregion] 3]
5071 if {$ymax eq {} || $ymax == 0} return
5073 set y0 [expr {int([lindex $f 0] * $ymax)}]
5074 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5078 set y1 [expr {int([lindex $f 1] * $ymax)}]
5079 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5080 if {$r1 >= $numcommits} {
5081 set r1 [expr {$numcommits - 1}]
5083 return [list $r0 $r1]
5086 proc layoutmore {} {
5087 global commitidx viewcomplete curview
5088 global numcommits pending_select curview
5089 global lastscrollset lastscrollrows
5091 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5092 [clock clicks -milliseconds] - $lastscrollset > 500} {
5095 if {[info exists pending_select] &&
5096 [commitinview $pending_select $curview]} {
5098 selectline [rowofcommit $pending_select] 1
5103 # With path limiting, we mightn't get the actual HEAD commit,
5104 # so ask git rev-list what is the first ancestor of HEAD that
5105 # touches a file in the path limit.
5106 proc get_viewmainhead {view} {
5107 global viewmainheadid vfilelimit viewinstances mainheadid
5110 set rfd [open [concat | git rev-list -1 $mainheadid \
5111 -- $vfilelimit($view)] r]
5112 set j [reg_instance $rfd]
5113 lappend viewinstances($view) $j
5114 fconfigure $rfd -blocking 0
5115 filerun $rfd [list getviewhead $rfd $j $view]
5116 set viewmainheadid($curview) {}
5120 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5121 proc getviewhead {fd inst view} {
5122 global viewmainheadid commfd curview viewinstances showlocalchanges
5125 if {[gets $fd line] < 0} {
5129 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5132 set viewmainheadid($view) $id
5135 set i [lsearch -exact $viewinstances($view) $inst]
5137 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5139 if {$showlocalchanges && $id ne {} && $view == $curview} {
5145 proc doshowlocalchanges {} {
5146 global curview viewmainheadid
5148 if {$viewmainheadid($curview) eq {}} return
5149 if {[commitinview $viewmainheadid($curview) $curview]} {
5152 interestedin $viewmainheadid($curview) dodiffindex
5156 proc dohidelocalchanges {} {
5157 global nullid nullid2 lserial curview
5159 if {[commitinview $nullid $curview]} {
5160 removefakerow $nullid
5162 if {[commitinview $nullid2 $curview]} {
5163 removefakerow $nullid2
5168 # spawn off a process to do git diff-index --cached HEAD
5169 proc dodiffindex {} {
5170 global lserial showlocalchanges vfilelimit curview
5173 if {!$showlocalchanges || !$hasworktree} return
5175 set cmd "|git diff-index --cached HEAD"
5176 if {$vfilelimit($curview) ne {}} {
5177 set cmd [concat $cmd -- $vfilelimit($curview)]
5179 set fd [open $cmd r]
5180 fconfigure $fd -blocking 0
5181 set i [reg_instance $fd]
5182 filerun $fd [list readdiffindex $fd $lserial $i]
5185 proc readdiffindex {fd serial inst} {
5186 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5190 if {[gets $fd line] < 0} {
5196 # we only need to see one line and we don't really care what it says...
5199 if {$serial != $lserial} {
5203 # now see if there are any local changes not checked in to the index
5204 set cmd "|git diff-files"
5205 if {$vfilelimit($curview) ne {}} {
5206 set cmd [concat $cmd -- $vfilelimit($curview)]
5208 set fd [open $cmd r]
5209 fconfigure $fd -blocking 0
5210 set i [reg_instance $fd]
5211 filerun $fd [list readdifffiles $fd $serial $i]
5213 if {$isdiff && ![commitinview $nullid2 $curview]} {
5214 # add the line for the changes in the index to the graph
5215 set hl [mc "Local changes checked in to index but not committed"]
5216 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5217 set commitdata($nullid2) "\n $hl\n"
5218 if {[commitinview $nullid $curview]} {
5219 removefakerow $nullid
5221 insertfakerow $nullid2 $viewmainheadid($curview)
5222 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5223 if {[commitinview $nullid $curview]} {
5224 removefakerow $nullid
5226 removefakerow $nullid2
5231 proc readdifffiles {fd serial inst} {
5232 global viewmainheadid nullid nullid2 curview
5233 global commitinfo commitdata lserial
5236 if {[gets $fd line] < 0} {
5242 # we only need to see one line and we don't really care what it says...
5245 if {$serial != $lserial} {
5249 if {$isdiff && ![commitinview $nullid $curview]} {
5250 # add the line for the local diff to the graph
5251 set hl [mc "Local uncommitted changes, not checked in to index"]
5252 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5253 set commitdata($nullid) "\n $hl\n"
5254 if {[commitinview $nullid2 $curview]} {
5257 set p $viewmainheadid($curview)
5259 insertfakerow $nullid $p
5260 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5261 removefakerow $nullid
5266 proc nextuse {id row} {
5267 global curview children
5269 if {[info exists children($curview,$id)]} {
5270 foreach kid $children($curview,$id) {
5271 if {![commitinview $kid $curview]} {
5274 if {[rowofcommit $kid] > $row} {
5275 return [rowofcommit $kid]
5279 if {[commitinview $id $curview]} {
5280 return [rowofcommit $id]
5285 proc prevuse {id row} {
5286 global curview children
5289 if {[info exists children($curview,$id)]} {
5290 foreach kid $children($curview,$id) {
5291 if {![commitinview $kid $curview]} break
5292 if {[rowofcommit $kid] < $row} {
5293 set ret [rowofcommit $kid]
5300 proc make_idlist {row} {
5301 global displayorder parentlist uparrowlen downarrowlen mingaplen
5302 global commitidx curview children
5304 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5308 set ra [expr {$row - $downarrowlen}]
5312 set rb [expr {$row + $uparrowlen}]
5313 if {$rb > $commitidx($curview)} {
5314 set rb $commitidx($curview)
5316 make_disporder $r [expr {$rb + 1}]
5318 for {} {$r < $ra} {incr r} {
5319 set nextid [lindex $displayorder [expr {$r + 1}]]
5320 foreach p [lindex $parentlist $r] {
5321 if {$p eq $nextid} continue
5322 set rn [nextuse $p $r]
5324 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5325 lappend ids [list [ordertoken $p] $p]
5329 for {} {$r < $row} {incr r} {
5330 set nextid [lindex $displayorder [expr {$r + 1}]]
5331 foreach p [lindex $parentlist $r] {
5332 if {$p eq $nextid} continue
5333 set rn [nextuse $p $r]
5334 if {$rn < 0 || $rn >= $row} {
5335 lappend ids [list [ordertoken $p] $p]
5339 set id [lindex $displayorder $row]
5340 lappend ids [list [ordertoken $id] $id]
5342 foreach p [lindex $parentlist $r] {
5343 set firstkid [lindex $children($curview,$p) 0]
5344 if {[rowofcommit $firstkid] < $row} {
5345 lappend ids [list [ordertoken $p] $p]
5349 set id [lindex $displayorder $r]
5351 set firstkid [lindex $children($curview,$id) 0]
5352 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5353 lappend ids [list [ordertoken $id] $id]
5358 foreach idx [lsort -unique $ids] {
5359 lappend idlist [lindex $idx 1]
5364 proc rowsequal {a b} {
5365 while {[set i [lsearch -exact $a {}]] >= 0} {
5366 set a [lreplace $a $i $i]
5368 while {[set i [lsearch -exact $b {}]] >= 0} {
5369 set b [lreplace $b $i $i]
5371 return [expr {$a eq $b}]
5374 proc makeupline {id row rend col} {
5375 global rowidlist uparrowlen downarrowlen mingaplen
5377 for {set r $rend} {1} {set r $rstart} {
5378 set rstart [prevuse $id $r]
5379 if {$rstart < 0} return
5380 if {$rstart < $row} break
5382 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5383 set rstart [expr {$rend - $uparrowlen - 1}]
5385 for {set r $rstart} {[incr r] <= $row} {} {
5386 set idlist [lindex $rowidlist $r]
5387 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5388 set col [idcol $idlist $id $col]
5389 lset rowidlist $r [linsert $idlist $col $id]
5395 proc layoutrows {row endrow} {
5396 global rowidlist rowisopt rowfinal displayorder
5397 global uparrowlen downarrowlen maxwidth mingaplen
5398 global children parentlist
5399 global commitidx viewcomplete curview
5401 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5404 set rm1 [expr {$row - 1}]
5405 foreach id [lindex $rowidlist $rm1] {
5410 set final [lindex $rowfinal $rm1]
5412 for {} {$row < $endrow} {incr row} {
5413 set rm1 [expr {$row - 1}]
5414 if {$rm1 < 0 || $idlist eq {}} {
5415 set idlist [make_idlist $row]
5418 set id [lindex $displayorder $rm1]
5419 set col [lsearch -exact $idlist $id]
5420 set idlist [lreplace $idlist $col $col]
5421 foreach p [lindex $parentlist $rm1] {
5422 if {[lsearch -exact $idlist $p] < 0} {
5423 set col [idcol $idlist $p $col]
5424 set idlist [linsert $idlist $col $p]
5425 # if not the first child, we have to insert a line going up
5426 if {$id ne [lindex $children($curview,$p) 0]} {
5427 makeupline $p $rm1 $row $col
5431 set id [lindex $displayorder $row]
5432 if {$row > $downarrowlen} {
5433 set termrow [expr {$row - $downarrowlen - 1}]
5434 foreach p [lindex $parentlist $termrow] {
5435 set i [lsearch -exact $idlist $p]
5436 if {$i < 0} continue
5437 set nr [nextuse $p $termrow]
5438 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5439 set idlist [lreplace $idlist $i $i]
5443 set col [lsearch -exact $idlist $id]
5445 set col [idcol $idlist $id]
5446 set idlist [linsert $idlist $col $id]
5447 if {$children($curview,$id) ne {}} {
5448 makeupline $id $rm1 $row $col
5451 set r [expr {$row + $uparrowlen - 1}]
5452 if {$r < $commitidx($curview)} {
5454 foreach p [lindex $parentlist $r] {
5455 if {[lsearch -exact $idlist $p] >= 0} continue
5456 set fk [lindex $children($curview,$p) 0]
5457 if {[rowofcommit $fk] < $row} {
5458 set x [idcol $idlist $p $x]
5459 set idlist [linsert $idlist $x $p]
5462 if {[incr r] < $commitidx($curview)} {
5463 set p [lindex $displayorder $r]
5464 if {[lsearch -exact $idlist $p] < 0} {
5465 set fk [lindex $children($curview,$p) 0]
5466 if {$fk ne {} && [rowofcommit $fk] < $row} {
5467 set x [idcol $idlist $p $x]
5468 set idlist [linsert $idlist $x $p]
5474 if {$final && !$viewcomplete($curview) &&
5475 $row + $uparrowlen + $mingaplen + $downarrowlen
5476 >= $commitidx($curview)} {
5479 set l [llength $rowidlist]
5481 lappend rowidlist $idlist
5483 lappend rowfinal $final
5484 } elseif {$row < $l} {
5485 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5486 lset rowidlist $row $idlist
5489 lset rowfinal $row $final
5491 set pad [ntimes [expr {$row - $l}] {}]
5492 set rowidlist [concat $rowidlist $pad]
5493 lappend rowidlist $idlist
5494 set rowfinal [concat $rowfinal $pad]
5495 lappend rowfinal $final
5496 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5502 proc changedrow {row} {
5503 global displayorder iddrawn rowisopt need_redisplay
5505 set l [llength $rowisopt]
5507 lset rowisopt $row 0
5508 if {$row + 1 < $l} {
5509 lset rowisopt [expr {$row + 1}] 0
5510 if {$row + 2 < $l} {
5511 lset rowisopt [expr {$row + 2}] 0
5515 set id [lindex $displayorder $row]
5516 if {[info exists iddrawn($id)]} {
5517 set need_redisplay 1
5521 proc insert_pad {row col npad} {
5524 set pad [ntimes $npad {}]
5525 set idlist [lindex $rowidlist $row]
5526 set bef [lrange $idlist 0 [expr {$col - 1}]]
5527 set aft [lrange $idlist $col end]
5528 set i [lsearch -exact $aft {}]
5530 set aft [lreplace $aft $i $i]
5532 lset rowidlist $row [concat $bef $pad $aft]
5536 proc optimize_rows {row col endrow} {
5537 global rowidlist rowisopt displayorder curview children
5542 for {} {$row < $endrow} {incr row; set col 0} {
5543 if {[lindex $rowisopt $row]} continue
5545 set y0 [expr {$row - 1}]
5546 set ym [expr {$row - 2}]
5547 set idlist [lindex $rowidlist $row]
5548 set previdlist [lindex $rowidlist $y0]
5549 if {$idlist eq {} || $previdlist eq {}} continue
5551 set pprevidlist [lindex $rowidlist $ym]
5552 if {$pprevidlist eq {}} continue
5558 for {} {$col < [llength $idlist]} {incr col} {
5559 set id [lindex $idlist $col]
5560 if {[lindex $previdlist $col] eq $id} continue
5565 set x0 [lsearch -exact $previdlist $id]
5566 if {$x0 < 0} continue
5567 set z [expr {$x0 - $col}]
5571 set xm [lsearch -exact $pprevidlist $id]
5573 set z0 [expr {$xm - $x0}]
5577 # if row y0 is the first child of $id then it's not an arrow
5578 if {[lindex $children($curview,$id) 0] ne
5579 [lindex $displayorder $y0]} {
5583 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5584 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5587 # Looking at lines from this row to the previous row,
5588 # make them go straight up if they end in an arrow on
5589 # the previous row; otherwise make them go straight up
5591 if {$z < -1 || ($z < 0 && $isarrow)} {
5592 # Line currently goes left too much;
5593 # insert pads in the previous row, then optimize it
5594 set npad [expr {-1 - $z + $isarrow}]
5595 insert_pad $y0 $x0 $npad
5597 optimize_rows $y0 $x0 $row
5599 set previdlist [lindex $rowidlist $y0]
5600 set x0 [lsearch -exact $previdlist $id]
5601 set z [expr {$x0 - $col}]
5603 set pprevidlist [lindex $rowidlist $ym]
5604 set xm [lsearch -exact $pprevidlist $id]
5605 set z0 [expr {$xm - $x0}]
5607 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5608 # Line currently goes right too much;
5609 # insert pads in this line
5610 set npad [expr {$z - 1 + $isarrow}]
5611 insert_pad $row $col $npad
5612 set idlist [lindex $rowidlist $row]
5614 set z [expr {$x0 - $col}]
5617 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5618 # this line links to its first child on row $row-2
5619 set id [lindex $displayorder $ym]
5620 set xc [lsearch -exact $pprevidlist $id]
5622 set z0 [expr {$xc - $x0}]
5625 # avoid lines jigging left then immediately right
5626 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5627 insert_pad $y0 $x0 1
5629 optimize_rows $y0 $x0 $row
5630 set previdlist [lindex $rowidlist $y0]
5634 # Find the first column that doesn't have a line going right
5635 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5636 set id [lindex $idlist $col]
5637 if {$id eq {}} break
5638 set x0 [lsearch -exact $previdlist $id]
5640 # check if this is the link to the first child
5641 set kid [lindex $displayorder $y0]
5642 if {[lindex $children($curview,$id) 0] eq $kid} {
5643 # it is, work out offset to child
5644 set x0 [lsearch -exact $previdlist $kid]
5647 if {$x0 <= $col} break
5649 # Insert a pad at that column as long as it has a line and
5650 # isn't the last column
5651 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5652 set idlist [linsert $idlist $col {}]
5653 lset rowidlist $row $idlist
5661 global canvx0 linespc
5662 return [expr {$canvx0 + $col * $linespc}]
5666 global canvy0 linespc
5667 return [expr {$canvy0 + $row * $linespc}]
5670 proc linewidth {id} {
5671 global thickerline lthickness
5674 if {[info exists thickerline] && $id eq $thickerline} {
5675 set wid [expr {2 * $lthickness}]
5680 proc rowranges {id} {
5681 global curview children uparrowlen downarrowlen
5684 set kids $children($curview,$id)
5690 foreach child $kids {
5691 if {![commitinview $child $curview]} break
5692 set row [rowofcommit $child]
5693 if {![info exists prev]} {
5694 lappend ret [expr {$row + 1}]
5696 if {$row <= $prevrow} {
5697 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5699 # see if the line extends the whole way from prevrow to row
5700 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5701 [lsearch -exact [lindex $rowidlist \
5702 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5703 # it doesn't, see where it ends
5704 set r [expr {$prevrow + $downarrowlen}]
5705 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5706 while {[incr r -1] > $prevrow &&
5707 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5709 while {[incr r] <= $row &&
5710 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5714 # see where it starts up again
5715 set r [expr {$row - $uparrowlen}]
5716 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5717 while {[incr r] < $row &&
5718 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5720 while {[incr r -1] >= $prevrow &&
5721 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5727 if {$child eq $id} {
5736 proc drawlineseg {id row endrow arrowlow} {
5737 global rowidlist displayorder iddrawn linesegs
5738 global canv colormap linespc curview maxlinelen parentlist
5740 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5741 set le [expr {$row + 1}]
5744 set c [lsearch -exact [lindex $rowidlist $le] $id]
5750 set x [lindex $displayorder $le]
5755 if {[info exists iddrawn($x)] || $le == $endrow} {
5756 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5772 if {[info exists linesegs($id)]} {
5773 set lines $linesegs($id)
5775 set r0 [lindex $li 0]
5777 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5787 set li [lindex $lines [expr {$i-1}]]
5788 set r1 [lindex $li 1]
5789 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5794 set x [lindex $cols [expr {$le - $row}]]
5795 set xp [lindex $cols [expr {$le - 1 - $row}]]
5796 set dir [expr {$xp - $x}]
5798 set ith [lindex $lines $i 2]
5799 set coords [$canv coords $ith]
5800 set ah [$canv itemcget $ith -arrow]
5801 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5802 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5803 if {$x2 ne {} && $x - $x2 == $dir} {
5804 set coords [lrange $coords 0 end-2]
5807 set coords [list [xc $le $x] [yc $le]]
5810 set itl [lindex $lines [expr {$i-1}] 2]
5811 set al [$canv itemcget $itl -arrow]
5812 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5813 } elseif {$arrowlow} {
5814 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5815 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5819 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5820 for {set y $le} {[incr y -1] > $row} {} {
5822 set xp [lindex $cols [expr {$y - 1 - $row}]]
5823 set ndir [expr {$xp - $x}]
5824 if {$dir != $ndir || $xp < 0} {
5825 lappend coords [xc $y $x] [yc $y]
5831 # join parent line to first child
5832 set ch [lindex $displayorder $row]
5833 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5835 puts "oops: drawlineseg: child $ch not on row $row"
5836 } elseif {$xc != $x} {
5837 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5838 set d [expr {int(0.5 * $linespc)}]
5841 set x2 [expr {$x1 - $d}]
5843 set x2 [expr {$x1 + $d}]
5846 set y1 [expr {$y2 + $d}]
5847 lappend coords $x1 $y1 $x2 $y2
5848 } elseif {$xc < $x - 1} {
5849 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5850 } elseif {$xc > $x + 1} {
5851 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5855 lappend coords [xc $row $x] [yc $row]
5857 set xn [xc $row $xp]
5859 lappend coords $xn $yn
5863 set t [$canv create line $coords -width [linewidth $id] \
5864 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5867 set lines [linsert $lines $i [list $row $le $t]]
5869 $canv coords $ith $coords
5870 if {$arrow ne $ah} {
5871 $canv itemconf $ith -arrow $arrow
5873 lset lines $i 0 $row
5876 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5877 set ndir [expr {$xo - $xp}]
5878 set clow [$canv coords $itl]
5879 if {$dir == $ndir} {
5880 set clow [lrange $clow 2 end]
5882 set coords [concat $coords $clow]
5884 lset lines [expr {$i-1}] 1 $le
5886 # coalesce two pieces
5888 set b [lindex $lines [expr {$i-1}] 0]
5889 set e [lindex $lines $i 1]
5890 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5892 $canv coords $itl $coords
5893 if {$arrow ne $al} {
5894 $canv itemconf $itl -arrow $arrow
5898 set linesegs($id) $lines
5902 proc drawparentlinks {id row} {
5903 global rowidlist canv colormap curview parentlist
5904 global idpos linespc
5906 set rowids [lindex $rowidlist $row]
5907 set col [lsearch -exact $rowids $id]
5908 if {$col < 0} return
5909 set olds [lindex $parentlist $row]
5910 set row2 [expr {$row + 1}]
5911 set x [xc $row $col]
5914 set d [expr {int(0.5 * $linespc)}]
5915 set ymid [expr {$y + $d}]
5916 set ids [lindex $rowidlist $row2]
5917 # rmx = right-most X coord used
5920 set i [lsearch -exact $ids $p]
5922 puts "oops, parent $p of $id not in list"
5925 set x2 [xc $row2 $i]
5929 set j [lsearch -exact $rowids $p]
5931 # drawlineseg will do this one for us
5935 # should handle duplicated parents here...
5936 set coords [list $x $y]
5938 # if attaching to a vertical segment, draw a smaller
5939 # slant for visual distinctness
5942 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5944 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5946 } elseif {$i < $col && $i < $j} {
5947 # segment slants towards us already
5948 lappend coords [xc $row $j] $y
5950 if {$i < $col - 1} {
5951 lappend coords [expr {$x2 + $linespc}] $y
5952 } elseif {$i > $col + 1} {
5953 lappend coords [expr {$x2 - $linespc}] $y
5955 lappend coords $x2 $y2
5958 lappend coords $x2 $y2
5960 set t [$canv create line $coords -width [linewidth $p] \
5961 -fill $colormap($p) -tags lines.$p]
5965 if {$rmx > [lindex $idpos($id) 1]} {
5966 lset idpos($id) 1 $rmx
5971 proc drawlines {id} {
5974 $canv itemconf lines.$id -width [linewidth $id]
5977 proc drawcmittext {id row col} {
5978 global linespc canv canv2 canv3 fgcolor curview
5979 global cmitlisted commitinfo rowidlist parentlist
5980 global rowtextx idpos idtags idheads idotherrefs
5981 global linehtag linentag linedtag selectedline
5982 global canvxmax boldids boldnameids fgcolor markedid
5983 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5984 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5985 global circleoutlinecolor
5987 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5988 set listed $cmitlisted($curview,$id)
5989 if {$id eq $nullid} {
5990 set ofill $workingfilescirclecolor
5991 } elseif {$id eq $nullid2} {
5992 set ofill $indexcirclecolor
5993 } elseif {$id eq $mainheadid} {
5994 set ofill $mainheadcirclecolor
5996 set ofill [lindex $circlecolors $listed]
5998 set x [xc $row $col]
6000 set orad [expr {$linespc / 3}]
6002 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6003 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6004 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6005 } elseif {$listed == 3} {
6006 # triangle pointing left for left-side commits
6007 set t [$canv create polygon \
6008 [expr {$x - $orad}] $y \
6009 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6010 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6011 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6013 # triangle pointing right for right-side commits
6014 set t [$canv create polygon \
6015 [expr {$x + $orad - 1}] $y \
6016 [expr {$x - $orad}] [expr {$y - $orad}] \
6017 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6018 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6020 set circleitem($row) $t
6022 $canv bind $t <1> {selcanvline {} %x %y}
6023 set rmx [llength [lindex $rowidlist $row]]
6024 set olds [lindex $parentlist $row]
6026 set nextids [lindex $rowidlist [expr {$row + 1}]]
6028 set i [lsearch -exact $nextids $p]
6034 set xt [xc $row $rmx]
6035 set rowtextx($row) $xt
6036 set idpos($id) [list $x $xt $y]
6037 if {[info exists idtags($id)] || [info exists idheads($id)]
6038 || [info exists idotherrefs($id)]} {
6039 set xt [drawtags $id $x $xt $y]
6041 if {[lindex $commitinfo($id) 6] > 0} {
6042 set xt [drawnotesign $xt $y]
6044 set headline [lindex $commitinfo($id) 0]
6045 set name [lindex $commitinfo($id) 1]
6046 set date [lindex $commitinfo($id) 2]
6047 set date [formatdate $date]
6050 set isbold [ishighlighted $id]
6053 set font mainfontbold
6055 lappend boldnameids $id
6056 set nfont mainfontbold
6059 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6060 -text $headline -font $font -tags text]
6061 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6062 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6063 -text $name -font $nfont -tags text]
6064 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6065 -text $date -font mainfont -tags text]
6066 if {$selectedline == $row} {
6069 if {[info exists markedid] && $markedid eq $id} {
6072 set xr [expr {$xt + [font measure $font $headline]}]
6073 if {$xr > $canvxmax} {
6079 proc drawcmitrow {row} {
6080 global displayorder rowidlist nrows_drawn
6081 global iddrawn markingmatches
6082 global commitinfo numcommits
6083 global filehighlight fhighlights findpattern nhighlights
6084 global hlview vhighlights
6085 global highlight_related rhighlights
6087 if {$row >= $numcommits} return
6089 set id [lindex $displayorder $row]
6090 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6091 askvhighlight $row $id
6093 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6094 askfilehighlight $row $id
6096 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6097 askfindhighlight $row $id
6099 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6100 askrelhighlight $row $id
6102 if {![info exists iddrawn($id)]} {
6103 set col [lsearch -exact [lindex $rowidlist $row] $id]
6105 puts "oops, row $row id $id not in list"
6108 if {![info exists commitinfo($id)]} {
6112 drawcmittext $id $row $col
6116 if {$markingmatches} {
6117 markrowmatches $row $id
6121 proc drawcommits {row {endrow {}}} {
6122 global numcommits iddrawn displayorder curview need_redisplay
6123 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6128 if {$endrow eq {}} {
6131 if {$endrow >= $numcommits} {
6132 set endrow [expr {$numcommits - 1}]
6135 set rl1 [expr {$row - $downarrowlen - 3}]
6139 set ro1 [expr {$row - 3}]
6143 set r2 [expr {$endrow + $uparrowlen + 3}]
6144 if {$r2 > $numcommits} {
6147 for {set r $rl1} {$r < $r2} {incr r} {
6148 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6152 set rl1 [expr {$r + 1}]
6158 optimize_rows $ro1 0 $r2
6159 if {$need_redisplay || $nrows_drawn > 2000} {
6163 # make the lines join to already-drawn rows either side
6164 set r [expr {$row - 1}]
6165 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6168 set er [expr {$endrow + 1}]
6169 if {$er >= $numcommits ||
6170 ![info exists iddrawn([lindex $displayorder $er])]} {
6173 for {} {$r <= $er} {incr r} {
6174 set id [lindex $displayorder $r]
6175 set wasdrawn [info exists iddrawn($id)]
6177 if {$r == $er} break
6178 set nextid [lindex $displayorder [expr {$r + 1}]]
6179 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6180 drawparentlinks $id $r
6182 set rowids [lindex $rowidlist $r]
6183 foreach lid $rowids {
6184 if {$lid eq {}} continue
6185 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6187 # see if this is the first child of any of its parents
6188 foreach p [lindex $parentlist $r] {
6189 if {[lsearch -exact $rowids $p] < 0} {
6190 # make this line extend up to the child
6191 set lineend($p) [drawlineseg $p $r $er 0]
6195 set lineend($lid) [drawlineseg $lid $r $er 1]
6201 proc undolayout {row} {
6202 global uparrowlen mingaplen downarrowlen
6203 global rowidlist rowisopt rowfinal need_redisplay
6205 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6209 if {[llength $rowidlist] > $r} {
6211 set rowidlist [lrange $rowidlist 0 $r]
6212 set rowfinal [lrange $rowfinal 0 $r]
6213 set rowisopt [lrange $rowisopt 0 $r]
6214 set need_redisplay 1
6219 proc drawvisible {} {
6220 global canv linespc curview vrowmod selectedline targetrow targetid
6221 global need_redisplay cscroll numcommits
6223 set fs [$canv yview]
6224 set ymax [lindex [$canv cget -scrollregion] 3]
6225 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6226 set f0 [lindex $fs 0]
6227 set f1 [lindex $fs 1]
6228 set y0 [expr {int($f0 * $ymax)}]
6229 set y1 [expr {int($f1 * $ymax)}]
6231 if {[info exists targetid]} {
6232 if {[commitinview $targetid $curview]} {
6233 set r [rowofcommit $targetid]
6234 if {$r != $targetrow} {
6235 # Fix up the scrollregion and change the scrolling position
6236 # now that our target row has moved.
6237 set diff [expr {($r - $targetrow) * $linespc}]
6240 set ymax [lindex [$canv cget -scrollregion] 3]
6243 set f0 [expr {$y0 / $ymax}]
6244 set f1 [expr {$y1 / $ymax}]
6245 allcanvs yview moveto $f0
6246 $cscroll set $f0 $f1
6247 set need_redisplay 1
6254 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6255 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6256 if {$endrow >= $vrowmod($curview)} {
6257 update_arcrows $curview
6259 if {$selectedline ne {} &&
6260 $row <= $selectedline && $selectedline <= $endrow} {
6261 set targetrow $selectedline
6262 } elseif {[info exists targetid]} {
6263 set targetrow [expr {int(($row + $endrow) / 2)}]
6265 if {[info exists targetrow]} {
6266 if {$targetrow >= $numcommits} {
6267 set targetrow [expr {$numcommits - 1}]
6269 set targetid [commitonrow $targetrow]
6271 drawcommits $row $endrow
6274 proc clear_display {} {
6275 global iddrawn linesegs need_redisplay nrows_drawn
6276 global vhighlights fhighlights nhighlights rhighlights
6277 global linehtag linentag linedtag boldids boldnameids
6280 catch {unset iddrawn}
6281 catch {unset linesegs}
6282 catch {unset linehtag}
6283 catch {unset linentag}
6284 catch {unset linedtag}
6287 catch {unset vhighlights}
6288 catch {unset fhighlights}
6289 catch {unset nhighlights}
6290 catch {unset rhighlights}
6291 set need_redisplay 0
6295 proc findcrossings {id} {
6296 global rowidlist parentlist numcommits displayorder
6300 foreach {s e} [rowranges $id] {
6301 if {$e >= $numcommits} {
6302 set e [expr {$numcommits - 1}]
6304 if {$e <= $s} continue
6305 for {set row $e} {[incr row -1] >= $s} {} {
6306 set x [lsearch -exact [lindex $rowidlist $row] $id]
6308 set olds [lindex $parentlist $row]
6309 set kid [lindex $displayorder $row]
6310 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6311 if {$kidx < 0} continue
6312 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6314 set px [lsearch -exact $nextrow $p]
6315 if {$px < 0} continue
6316 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6317 if {[lsearch -exact $ccross $p] >= 0} continue
6318 if {$x == $px + ($kidx < $px? -1: 1)} {
6320 } elseif {[lsearch -exact $cross $p] < 0} {
6327 return [concat $ccross {{}} $cross]
6330 proc assigncolor {id} {
6331 global colormap colors nextcolor
6332 global parents children children curview
6334 if {[info exists colormap($id)]} return
6335 set ncolors [llength $colors]
6336 if {[info exists children($curview,$id)]} {
6337 set kids $children($curview,$id)
6341 if {[llength $kids] == 1} {
6342 set child [lindex $kids 0]
6343 if {[info exists colormap($child)]
6344 && [llength $parents($curview,$child)] == 1} {
6345 set colormap($id) $colormap($child)
6351 foreach x [findcrossings $id] {
6353 # delimiter between corner crossings and other crossings
6354 if {[llength $badcolors] >= $ncolors - 1} break
6355 set origbad $badcolors
6357 if {[info exists colormap($x)]
6358 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6359 lappend badcolors $colormap($x)
6362 if {[llength $badcolors] >= $ncolors} {
6363 set badcolors $origbad
6365 set origbad $badcolors
6366 if {[llength $badcolors] < $ncolors - 1} {
6367 foreach child $kids {
6368 if {[info exists colormap($child)]
6369 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6370 lappend badcolors $colormap($child)
6372 foreach p $parents($curview,$child) {
6373 if {[info exists colormap($p)]
6374 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6375 lappend badcolors $colormap($p)
6379 if {[llength $badcolors] >= $ncolors} {
6380 set badcolors $origbad
6383 for {set i 0} {$i <= $ncolors} {incr i} {
6384 set c [lindex $colors $nextcolor]
6385 if {[incr nextcolor] >= $ncolors} {
6388 if {[lsearch -exact $badcolors $c]} break
6390 set colormap($id) $c
6393 proc bindline {t id} {
6396 $canv bind $t <Enter> "lineenter %x %y $id"
6397 $canv bind $t <Motion> "linemotion %x %y $id"
6398 $canv bind $t <Leave> "lineleave $id"
6399 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6402 proc graph_pane_width {} {
6406 set g [.tf.histframe.pwclist sashpos 0]
6408 set g [.tf.histframe.pwclist sash coord 0]
6410 return [lindex $g 0]
6413 proc totalwidth {l font extra} {
6416 set tot [expr {$tot + [font measure $font $str] + $extra}]
6421 proc drawtags {id x xt y1} {
6422 global idtags idheads idotherrefs mainhead
6423 global linespc lthickness
6424 global canv rowtextx curview fgcolor bgcolor ctxbut
6425 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6426 global tagbgcolor tagfgcolor tagoutlinecolor
6435 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6436 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6437 set extra [expr {$delta + $lthickness + $linespc}]
6439 if {[info exists idtags($id)]} {
6440 set marks $idtags($id)
6441 set ntags [llength $marks]
6442 if {$ntags > $maxtags ||
6443 [totalwidth $marks mainfont $extra] > $maxwidth} {
6444 # show just a single "n tags..." tag
6447 set marks [list "tag..."]
6449 set marks [list [format "%d tags..." $ntags]]
6454 if {[info exists idheads($id)]} {
6455 set marks [concat $marks $idheads($id)]
6456 set nheads [llength $idheads($id)]
6458 if {[info exists idotherrefs($id)]} {
6459 set marks [concat $marks $idotherrefs($id)]
6465 set yt [expr {$y1 - 0.5 * $linespc}]
6466 set yb [expr {$yt + $linespc - 1}]
6470 foreach tag $marks {
6472 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6473 set wid [font measure mainfontbold $tag]
6475 set wid [font measure mainfont $tag]
6479 set xt [expr {$xt + $wid + $extra}]
6481 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6482 -width $lthickness -fill $reflinecolor -tags tag.$id]
6484 foreach tag $marks x $xvals wid $wvals {
6485 set tag_quoted [string map {% %%} $tag]
6486 set xl [expr {$x + $delta}]
6487 set xr [expr {$x + $delta + $wid + $lthickness}]
6489 if {[incr ntags -1] >= 0} {
6491 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6492 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6493 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6496 set tagclick [list showtags $id 1]
6498 set tagclick [list showtag $tag_quoted 1]
6500 $canv bind $t <1> $tagclick
6501 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6503 # draw a head or other ref
6504 if {[incr nheads -1] >= 0} {
6505 set col $headbgcolor
6506 if {$tag eq $mainhead} {
6507 set font mainfontbold
6512 set xl [expr {$xl - $delta/2}]
6513 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6514 -width 1 -outline black -fill $col -tags tag.$id
6515 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6516 set rwid [font measure mainfont $remoteprefix]
6517 set xi [expr {$x + 1}]
6518 set yti [expr {$yt + 1}]
6519 set xri [expr {$x + $rwid}]
6520 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6521 -width 0 -fill $remotebgcolor -tags tag.$id
6524 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6525 -font $font -tags [list tag.$id text]]
6527 $canv bind $t <1> $tagclick
6528 } elseif {$nheads >= 0} {
6529 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6535 proc drawnotesign {xt y} {
6536 global linespc canv fgcolor
6538 set orad [expr {$linespc / 3}]
6539 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6540 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6541 -fill yellow -outline $fgcolor -width 1 -tags circle]
6542 set xt [expr {$xt + $orad * 3}]
6546 proc xcoord {i level ln} {
6547 global canvx0 xspc1 xspc2
6549 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6550 if {$i > 0 && $i == $level} {
6551 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6552 } elseif {$i > $level} {
6553 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6558 proc show_status {msg} {
6562 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6563 -tags text -fill $fgcolor
6566 # Don't change the text pane cursor if it is currently the hand cursor,
6567 # showing that we are over a sha1 ID link.
6568 proc settextcursor {c} {
6569 global ctext curtextcursor
6571 if {[$ctext cget -cursor] == $curtextcursor} {
6572 $ctext config -cursor $c
6574 set curtextcursor $c
6577 proc nowbusy {what {name {}}} {
6578 global isbusy busyname statusw
6580 if {[array names isbusy] eq {}} {
6581 . config -cursor watch
6585 set busyname($what) $name
6587 $statusw conf -text $name
6591 proc notbusy {what} {
6592 global isbusy maincursor textcursor busyname statusw
6596 if {$busyname($what) ne {} &&
6597 [$statusw cget -text] eq $busyname($what)} {
6598 $statusw conf -text {}
6601 if {[array names isbusy] eq {}} {
6602 . config -cursor $maincursor
6603 settextcursor $textcursor
6607 proc findmatches {f} {
6608 global findtype findstring
6609 if {$findtype == [mc "Regexp"]} {
6610 set matches [regexp -indices -all -inline $findstring $f]
6613 if {$findtype == [mc "IgnCase"]} {
6614 set f [string tolower $f]
6615 set fs [string tolower $fs]
6619 set l [string length $fs]
6620 while {[set j [string first $fs $f $i]] >= 0} {
6621 lappend matches [list $j [expr {$j+$l-1}]]
6622 set i [expr {$j + $l}]
6628 proc dofind {{dirn 1} {wrap 1}} {
6629 global findstring findstartline findcurline selectedline numcommits
6630 global gdttype filehighlight fh_serial find_dirn findallowwrap
6632 if {[info exists find_dirn]} {
6633 if {$find_dirn == $dirn} return
6637 if {$findstring eq {} || $numcommits == 0} return
6638 if {$selectedline eq {}} {
6639 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6641 set findstartline $selectedline
6643 set findcurline $findstartline
6644 nowbusy finding [mc "Searching"]
6645 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6646 after cancel do_file_hl $fh_serial
6647 do_file_hl $fh_serial
6650 set findallowwrap $wrap
6654 proc stopfinding {} {
6655 global find_dirn findcurline fprogcoord
6657 if {[info exists find_dirn]} {
6668 global commitdata commitinfo numcommits findpattern findloc
6669 global findstartline findcurline findallowwrap
6670 global find_dirn gdttype fhighlights fprogcoord
6671 global curview varcorder vrownum varccommits vrowmod
6673 if {![info exists find_dirn]} {
6676 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6679 if {$find_dirn > 0} {
6681 if {$l >= $numcommits} {
6684 if {$l <= $findstartline} {
6685 set lim [expr {$findstartline + 1}]
6688 set moretodo $findallowwrap
6695 if {$l >= $findstartline} {
6696 set lim [expr {$findstartline - 1}]
6699 set moretodo $findallowwrap
6702 set n [expr {($lim - $l) * $find_dirn}]
6707 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6708 update_arcrows $curview
6712 set ai [bsearch $vrownum($curview) $l]
6713 set a [lindex $varcorder($curview) $ai]
6714 set arow [lindex $vrownum($curview) $ai]
6715 set ids [lindex $varccommits($curview,$a)]
6716 set arowend [expr {$arow + [llength $ids]}]
6717 if {$gdttype eq [mc "containing:"]} {
6718 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6719 if {$l < $arow || $l >= $arowend} {
6721 set a [lindex $varcorder($curview) $ai]
6722 set arow [lindex $vrownum($curview) $ai]
6723 set ids [lindex $varccommits($curview,$a)]
6724 set arowend [expr {$arow + [llength $ids]}]
6726 set id [lindex $ids [expr {$l - $arow}]]
6727 # shouldn't happen unless git log doesn't give all the commits...
6728 if {![info exists commitdata($id)] ||
6729 ![doesmatch $commitdata($id)]} {
6732 if {![info exists commitinfo($id)]} {
6735 set info $commitinfo($id)
6736 foreach f $info ty $fldtypes {
6737 if {$ty eq ""} continue
6738 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6747 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6748 if {$l < $arow || $l >= $arowend} {
6750 set a [lindex $varcorder($curview) $ai]
6751 set arow [lindex $vrownum($curview) $ai]
6752 set ids [lindex $varccommits($curview,$a)]
6753 set arowend [expr {$arow + [llength $ids]}]
6755 set id [lindex $ids [expr {$l - $arow}]]
6756 if {![info exists fhighlights($id)]} {
6757 # this sets fhighlights($id) to -1
6758 askfilehighlight $l $id
6760 if {$fhighlights($id) > 0} {
6764 if {$fhighlights($id) < 0} {
6767 set findcurline [expr {$l - $find_dirn}]
6772 if {$found || ($domore && !$moretodo)} {
6788 set findcurline [expr {$l - $find_dirn}]
6790 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6794 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6799 proc findselectline {l} {
6800 global findloc commentend ctext findcurline markingmatches gdttype
6802 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6805 if {$markingmatches &&
6806 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6807 # highlight the matches in the comments
6808 set f [$ctext get 1.0 $commentend]
6809 set matches [findmatches $f]
6810 foreach match $matches {
6811 set start [lindex $match 0]
6812 set end [expr {[lindex $match 1] + 1}]
6813 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6819 # mark the bits of a headline or author that match a find string
6820 proc markmatches {canv l str tag matches font row} {
6823 set bbox [$canv bbox $tag]
6824 set x0 [lindex $bbox 0]
6825 set y0 [lindex $bbox 1]
6826 set y1 [lindex $bbox 3]
6827 foreach match $matches {
6828 set start [lindex $match 0]
6829 set end [lindex $match 1]
6830 if {$start > $end} continue
6831 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6832 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6833 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6834 [expr {$x0+$xlen+2}] $y1 \
6835 -outline {} -tags [list match$l matches] -fill yellow]
6837 if {$row == $selectedline} {
6838 $canv raise $t secsel
6843 proc unmarkmatches {} {
6844 global markingmatches
6846 allcanvs delete matches
6847 set markingmatches 0
6851 proc selcanvline {w x y} {
6852 global canv canvy0 ctext linespc
6854 set ymax [lindex [$canv cget -scrollregion] 3]
6855 if {$ymax == {}} return
6856 set yfrac [lindex [$canv yview] 0]
6857 set y [expr {$y + $yfrac * $ymax}]
6858 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6863 set xmax [lindex [$canv cget -scrollregion] 2]
6864 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6865 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6871 proc commit_descriptor {p} {
6873 if {![info exists commitinfo($p)]} {
6877 if {[llength $commitinfo($p)] > 1} {
6878 set l [lindex $commitinfo($p) 0]
6883 # append some text to the ctext widget, and make any SHA1 ID
6884 # that we know about be a clickable link.
6885 proc appendwithlinks {text tags} {
6886 global ctext linknum curview
6888 set start [$ctext index "end - 1c"]
6889 $ctext insert end $text $tags
6890 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6894 set linkid [string range $text $s $e]
6896 $ctext tag delete link$linknum
6897 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6898 setlink $linkid link$linknum
6903 proc setlink {id lk} {
6904 global curview ctext pendinglinks
6907 if {[string range $id 0 1] eq "-g"} {
6908 set id [string range $id 2 end]
6912 if {[string length $id] < 40} {
6913 set matches [longid $id]
6914 if {[llength $matches] > 0} {
6915 if {[llength $matches] > 1} return
6917 set id [lindex $matches 0]
6920 set known [commitinview $id $curview]
6923 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6924 $ctext tag bind $lk <1> [list selbyid $id]
6925 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6926 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6928 lappend pendinglinks($id) $lk
6929 interestedin $id {makelink %P}
6933 proc appendshortlink {id {pre {}} {post {}}} {
6934 global ctext linknum
6936 $ctext insert end $pre
6937 $ctext tag delete link$linknum
6938 $ctext insert end [string range $id 0 7] link$linknum
6939 $ctext insert end $post
6940 setlink $id link$linknum
6944 proc makelink {id} {
6947 if {![info exists pendinglinks($id)]} return
6948 foreach lk $pendinglinks($id) {
6951 unset pendinglinks($id)
6954 proc linkcursor {w inc} {
6955 global linkentercount curtextcursor
6957 if {[incr linkentercount $inc] > 0} {
6958 $w configure -cursor hand2
6960 $w configure -cursor $curtextcursor
6961 if {$linkentercount < 0} {
6962 set linkentercount 0
6967 proc viewnextline {dir} {
6971 set ymax [lindex [$canv cget -scrollregion] 3]
6972 set wnow [$canv yview]
6973 set wtop [expr {[lindex $wnow 0] * $ymax}]
6974 set newtop [expr {$wtop + $dir * $linespc}]
6977 } elseif {$newtop > $ymax} {
6980 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6983 # add a list of tag or branch names at position pos
6984 # returns the number of names inserted
6985 proc appendrefs {pos ids var} {
6986 global ctext linknum curview $var maxrefs mainheadid
6988 if {[catch {$ctext index $pos}]} {
6991 $ctext conf -state normal
6992 $ctext delete $pos "$pos lineend"
6995 foreach tag [set $var\($id\)] {
6996 lappend tags [list $tag $id]
7001 set tags [lsort -index 0 -decreasing $tags]
7004 if {[llength $tags] > $maxrefs} {
7005 # If we are displaying heads, and there are too many,
7006 # see if there are some important heads to display.
7007 # Currently this means "master" and the current head.
7009 if {$var eq "idheads"} {
7012 set hname [lindex $ti 0]
7013 set id [lindex $ti 1]
7014 if {($hname eq "master" || $id eq $mainheadid) &&
7015 [llength $itags] < $maxrefs} {
7024 set str [mc "and many more"]
7029 $ctext insert $pos "$str ([llength $tags])"
7030 set nutags [llength $tags]
7035 set id [lindex $ti 1]
7038 $ctext tag delete $lk
7039 $ctext insert $pos $sep
7040 $ctext insert $pos [lindex $ti 0] $lk
7044 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7045 $ctext conf -state disabled
7046 return [expr {[llength $tags] + $nutags}]
7049 # called when we have finished computing the nearby tags
7050 proc dispneartags {delay} {
7051 global selectedline currentid showneartags tagphase
7053 if {$selectedline eq {} || !$showneartags} return
7054 after cancel dispnexttag
7056 after 200 dispnexttag
7059 after idle dispnexttag
7064 proc dispnexttag {} {
7065 global selectedline currentid showneartags tagphase ctext
7067 if {$selectedline eq {} || !$showneartags} return
7068 switch -- $tagphase {
7070 set dtags [desctags $currentid]
7072 appendrefs precedes $dtags idtags
7076 set atags [anctags $currentid]
7078 appendrefs follows $atags idtags
7082 set dheads [descheads $currentid]
7083 if {$dheads ne {}} {
7084 if {[appendrefs branch $dheads idheads] > 1
7085 && [$ctext get "branch -3c"] eq "h"} {
7086 # turn "Branch" into "Branches"
7087 $ctext conf -state normal
7088 $ctext insert "branch -2c" "es"
7089 $ctext conf -state disabled
7094 if {[incr tagphase] <= 2} {
7095 after idle dispnexttag
7099 proc make_secsel {id} {
7100 global linehtag linentag linedtag canv canv2 canv3
7102 if {![info exists linehtag($id)]} return
7104 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7105 -tags secsel -fill [$canv cget -selectbackground]]
7107 $canv2 delete secsel
7108 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7109 -tags secsel -fill [$canv2 cget -selectbackground]]
7111 $canv3 delete secsel
7112 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7113 -tags secsel -fill [$canv3 cget -selectbackground]]
7117 proc make_idmark {id} {
7118 global linehtag canv fgcolor
7120 if {![info exists linehtag($id)]} return
7122 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7123 -tags markid -outline $fgcolor]
7127 proc selectline {l isnew {desired_loc {}}} {
7128 global canv ctext commitinfo selectedline
7129 global canvy0 linespc parents children curview
7130 global currentid sha1entry
7131 global commentend idtags linknum
7132 global mergemax numcommits pending_select
7133 global cmitmode showneartags allcommits
7134 global targetrow targetid lastscrollrows
7135 global autoselect autosellen jump_to_here
7138 catch {unset pending_select}
7143 if {$l < 0 || $l >= $numcommits} return
7144 set id [commitonrow $l]
7149 if {$lastscrollrows < $numcommits} {
7153 set y [expr {$canvy0 + $l * $linespc}]
7154 set ymax [lindex [$canv cget -scrollregion] 3]
7155 set ytop [expr {$y - $linespc - 1}]
7156 set ybot [expr {$y + $linespc + 1}]
7157 set wnow [$canv yview]
7158 set wtop [expr {[lindex $wnow 0] * $ymax}]
7159 set wbot [expr {[lindex $wnow 1] * $ymax}]
7160 set wh [expr {$wbot - $wtop}]
7162 if {$ytop < $wtop} {
7163 if {$ybot < $wtop} {
7164 set newtop [expr {$y - $wh / 2.0}]
7167 if {$newtop > $wtop - $linespc} {
7168 set newtop [expr {$wtop - $linespc}]
7171 } elseif {$ybot > $wbot} {
7172 if {$ytop > $wbot} {
7173 set newtop [expr {$y - $wh / 2.0}]
7175 set newtop [expr {$ybot - $wh}]
7176 if {$newtop < $wtop + $linespc} {
7177 set newtop [expr {$wtop + $linespc}]
7181 if {$newtop != $wtop} {
7185 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7192 addtohistory [list selbyid $id 0] savecmitpos
7195 $sha1entry delete 0 end
7196 $sha1entry insert 0 $id
7198 $sha1entry selection range 0 $autosellen
7202 $ctext conf -state normal
7205 if {![info exists commitinfo($id)]} {
7208 set info $commitinfo($id)
7209 set date [formatdate [lindex $info 2]]
7210 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7211 set date [formatdate [lindex $info 4]]
7212 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7213 if {[info exists idtags($id)]} {
7214 $ctext insert end [mc "Tags:"]
7215 foreach tag $idtags($id) {
7216 $ctext insert end " $tag"
7218 $ctext insert end "\n"
7222 set olds $parents($curview,$id)
7223 if {[llength $olds] > 1} {
7226 if {$np >= $mergemax} {
7231 $ctext insert end "[mc "Parent"]: " $tag
7232 appendwithlinks [commit_descriptor $p] {}
7237 append headers "[mc "Parent"]: [commit_descriptor $p]"
7241 foreach c $children($curview,$id) {
7242 append headers "[mc "Child"]: [commit_descriptor $c]"
7245 # make anything that looks like a SHA1 ID be a clickable link
7246 appendwithlinks $headers {}
7247 if {$showneartags} {
7248 if {![info exists allcommits]} {
7251 $ctext insert end "[mc "Branch"]: "
7252 $ctext mark set branch "end -1c"
7253 $ctext mark gravity branch left
7254 $ctext insert end "\n[mc "Follows"]: "
7255 $ctext mark set follows "end -1c"
7256 $ctext mark gravity follows left
7257 $ctext insert end "\n[mc "Precedes"]: "
7258 $ctext mark set precedes "end -1c"
7259 $ctext mark gravity precedes left
7260 $ctext insert end "\n"
7263 $ctext insert end "\n"
7264 set comment [lindex $info 5]
7265 if {[string first "\r" $comment] >= 0} {
7266 set comment [string map {"\r" "\n "} $comment]
7268 appendwithlinks $comment {comment}
7270 $ctext tag remove found 1.0 end
7271 $ctext conf -state disabled
7272 set commentend [$ctext index "end - 1c"]
7274 set jump_to_here $desired_loc
7275 init_flist [mc "Comments"]
7276 if {$cmitmode eq "tree"} {
7278 } elseif {$vinlinediff($curview) == 1} {
7280 } elseif {[llength $olds] <= 1} {
7287 proc selfirstline {} {
7292 proc sellastline {} {
7295 set l [expr {$numcommits - 1}]
7299 proc selnextline {dir} {
7302 if {$selectedline eq {}} return
7303 set l [expr {$selectedline + $dir}]
7308 proc selnextpage {dir} {
7309 global canv linespc selectedline numcommits
7311 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7315 allcanvs yview scroll [expr {$dir * $lpp}] units
7317 if {$selectedline eq {}} return
7318 set l [expr {$selectedline + $dir * $lpp}]
7321 } elseif {$l >= $numcommits} {
7322 set l [expr $numcommits - 1]
7328 proc unselectline {} {
7329 global selectedline currentid
7332 catch {unset currentid}
7333 allcanvs delete secsel
7337 proc reselectline {} {
7340 if {$selectedline ne {}} {
7341 selectline $selectedline 0
7345 proc addtohistory {cmd {saveproc {}}} {
7346 global history historyindex curview
7350 set elt [list $curview $cmd $saveproc {}]
7351 if {$historyindex > 0
7352 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7356 if {$historyindex < [llength $history]} {
7357 set history [lreplace $history $historyindex end $elt]
7359 lappend history $elt
7362 if {$historyindex > 1} {
7363 .tf.bar.leftbut conf -state normal
7365 .tf.bar.leftbut conf -state disabled
7367 .tf.bar.rightbut conf -state disabled
7370 # save the scrolling position of the diff display pane
7371 proc save_position {} {
7372 global historyindex history
7374 if {$historyindex < 1} return
7375 set hi [expr {$historyindex - 1}]
7376 set fn [lindex $history $hi 2]
7378 lset history $hi 3 [eval $fn]
7382 proc unset_posvars {} {
7385 if {[info exists last_posvars]} {
7386 foreach {var val} $last_posvars {
7395 global curview last_posvars
7397 set view [lindex $elt 0]
7398 set cmd [lindex $elt 1]
7399 set pv [lindex $elt 3]
7400 if {$curview != $view} {
7404 foreach {var val} $pv {
7408 set last_posvars $pv
7413 global history historyindex
7416 if {$historyindex > 1} {
7418 incr historyindex -1
7419 godo [lindex $history [expr {$historyindex - 1}]]
7420 .tf.bar.rightbut conf -state normal
7422 if {$historyindex <= 1} {
7423 .tf.bar.leftbut conf -state disabled
7428 global history historyindex
7431 if {$historyindex < [llength $history]} {
7433 set cmd [lindex $history $historyindex]
7436 .tf.bar.leftbut conf -state normal
7438 if {$historyindex >= [llength $history]} {
7439 .tf.bar.rightbut conf -state disabled
7444 global treefilelist treeidlist diffids diffmergeid treepending
7445 global nullid nullid2
7448 catch {unset diffmergeid}
7449 if {![info exists treefilelist($id)]} {
7450 if {![info exists treepending]} {
7451 if {$id eq $nullid} {
7452 set cmd [list | git ls-files]
7453 } elseif {$id eq $nullid2} {
7454 set cmd [list | git ls-files --stage -t]
7456 set cmd [list | git ls-tree -r $id]
7458 if {[catch {set gtf [open $cmd r]}]} {
7462 set treefilelist($id) {}
7463 set treeidlist($id) {}
7464 fconfigure $gtf -blocking 0 -encoding binary
7465 filerun $gtf [list gettreeline $gtf $id]
7472 proc gettreeline {gtf id} {
7473 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7476 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7477 if {$diffids eq $nullid} {
7480 set i [string first "\t" $line]
7481 if {$i < 0} continue
7482 set fname [string range $line [expr {$i+1}] end]
7483 set line [string range $line 0 [expr {$i-1}]]
7484 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7485 set sha1 [lindex $line 2]
7486 lappend treeidlist($id) $sha1
7488 if {[string index $fname 0] eq "\""} {
7489 set fname [lindex $fname 0]
7491 set fname [encoding convertfrom $fname]
7492 lappend treefilelist($id) $fname
7495 return [expr {$nl >= 1000? 2: 1}]
7499 if {$cmitmode ne "tree"} {
7500 if {![info exists diffmergeid]} {
7501 gettreediffs $diffids
7503 } elseif {$id ne $diffids} {
7512 global treefilelist treeidlist diffids nullid nullid2
7513 global ctext_file_names ctext_file_lines
7514 global ctext commentend
7516 set i [lsearch -exact $treefilelist($diffids) $f]
7518 puts "oops, $f not in list for id $diffids"
7521 if {$diffids eq $nullid} {
7522 if {[catch {set bf [open $f r]} err]} {
7523 puts "oops, can't read $f: $err"
7527 set blob [lindex $treeidlist($diffids) $i]
7528 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7529 puts "oops, error reading blob $blob: $err"
7533 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7534 filerun $bf [list getblobline $bf $diffids]
7535 $ctext config -state normal
7536 clear_ctext $commentend
7537 lappend ctext_file_names $f
7538 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7539 $ctext insert end "\n"
7540 $ctext insert end "$f\n" filesep
7541 $ctext config -state disabled
7542 $ctext yview $commentend
7546 proc getblobline {bf id} {
7547 global diffids cmitmode ctext
7549 if {$id ne $diffids || $cmitmode ne "tree"} {
7553 $ctext config -state normal
7555 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7556 $ctext insert end "$line\n"
7559 global jump_to_here ctext_file_names commentend
7561 # delete last newline
7562 $ctext delete "end - 2c" "end - 1c"
7564 if {$jump_to_here ne {} &&
7565 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7566 set lnum [expr {[lindex $jump_to_here 1] +
7567 [lindex [split $commentend .] 0]}]
7568 mark_ctext_line $lnum
7570 $ctext config -state disabled
7573 $ctext config -state disabled
7574 return [expr {$nl >= 1000? 2: 1}]
7577 proc mark_ctext_line {lnum} {
7578 global ctext markbgcolor
7580 $ctext tag delete omark
7581 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7582 $ctext tag conf omark -background $markbgcolor
7586 proc mergediff {id} {
7588 global diffids treediffs
7589 global parents curview
7593 set treediffs($id) {}
7594 set np [llength $parents($curview,$id)]
7599 proc startdiff {ids} {
7600 global treediffs diffids treepending diffmergeid nullid nullid2
7604 catch {unset diffmergeid}
7605 if {![info exists treediffs($ids)] ||
7606 [lsearch -exact $ids $nullid] >= 0 ||
7607 [lsearch -exact $ids $nullid2] >= 0} {
7608 if {![info exists treepending]} {
7616 proc showinlinediff {ids} {
7617 global commitinfo commitdata ctext
7620 set info $commitinfo($ids)
7621 set diff [lindex $info 7]
7622 set difflines [split $diff "\n"]
7628 foreach line $difflines {
7629 if {![string compare -length 5 "diff " $line]} {
7631 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7632 # offset also accounts for the b/ prefix
7633 lappend treediff [string range $line 6 end]
7638 set treediffs($ids) $treediff
7641 $ctext conf -state normal
7642 foreach line $difflines {
7643 parseblobdiffline $ids $line
7645 maybe_scroll_ctext 1
7646 $ctext conf -state disabled
7649 # If the filename (name) is under any of the passed filter paths
7650 # then return true to include the file in the listing.
7651 proc path_filter {filter name} {
7652 set worktree [gitworktree]
7654 set fq_p [file normalize $p]
7655 set fq_n [file normalize [file join $worktree $name]]
7656 if {[string match [file normalize $fq_p]* $fq_n]} {
7663 proc addtocflist {ids} {
7666 add_flist $treediffs($ids)
7670 proc diffcmd {ids flags} {
7671 global log_showroot nullid nullid2
7673 set i [lsearch -exact $ids $nullid]
7674 set j [lsearch -exact $ids $nullid2]
7676 if {[llength $ids] > 1 && $j < 0} {
7677 # comparing working directory with some specific revision
7678 set cmd [concat | git diff-index $flags]
7680 lappend cmd -R [lindex $ids 1]
7682 lappend cmd [lindex $ids 0]
7685 # comparing working directory with index
7686 set cmd [concat | git diff-files $flags]
7691 } elseif {$j >= 0} {
7692 set cmd [concat | git diff-index --cached $flags]
7693 if {[llength $ids] > 1} {
7694 # comparing index with specific revision
7696 lappend cmd -R [lindex $ids 1]
7698 lappend cmd [lindex $ids 0]
7701 # comparing index with HEAD
7705 if {$log_showroot} {
7706 lappend flags --root
7708 set cmd [concat | git diff-tree -r $flags $ids]
7713 proc gettreediffs {ids} {
7714 global treediff treepending limitdiffs vfilelimit curview
7716 set cmd [diffcmd $ids {--no-commit-id}]
7717 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7718 set cmd [concat $cmd -- $vfilelimit($curview)]
7720 if {[catch {set gdtf [open $cmd r]}]} return
7722 set treepending $ids
7724 fconfigure $gdtf -blocking 0 -encoding binary
7725 filerun $gdtf [list gettreediffline $gdtf $ids]
7728 proc gettreediffline {gdtf ids} {
7729 global treediff treediffs treepending diffids diffmergeid
7730 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7735 if {$perfile_attrs} {
7736 # cache_gitattr is slow, and even slower on win32 where we
7737 # have to invoke it for only about 30 paths at a time
7739 if {[tk windowingsystem] == "win32"} {
7743 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7744 set i [string first "\t" $line]
7746 set file [string range $line [expr {$i+1}] end]
7747 if {[string index $file 0] eq "\""} {
7748 set file [lindex $file 0]
7750 set file [encoding convertfrom $file]
7751 if {$file ne [lindex $treediff end]} {
7752 lappend treediff $file
7753 lappend sublist $file
7757 if {$perfile_attrs} {
7758 cache_gitattr encoding $sublist
7761 return [expr {$nr >= $max? 2: 1}]
7764 set treediffs($ids) $treediff
7766 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7768 } elseif {$ids != $diffids} {
7769 if {![info exists diffmergeid]} {
7770 gettreediffs $diffids
7778 # empty string or positive integer
7779 proc diffcontextvalidate {v} {
7780 return [regexp {^(|[1-9][0-9]*)$} $v]
7783 proc diffcontextchange {n1 n2 op} {
7784 global diffcontextstring diffcontext
7786 if {[string is integer -strict $diffcontextstring]} {
7787 if {$diffcontextstring >= 0} {
7788 set diffcontext $diffcontextstring
7794 proc changeignorespace {} {
7798 proc changeworddiff {name ix op} {
7802 proc initblobdiffvars {} {
7803 global diffencoding targetline diffnparents
7804 global diffinhdr currdiffsubmod diffseehere
7808 set diffencoding [get_path_encoding {}]
7809 set currdiffsubmod ""
7813 proc getblobdiffs {ids} {
7814 global blobdifffd diffids env
7819 global limitdiffs vfilelimit curview
7823 if {[package vcompare $git_version "1.6.1"] >= 0} {
7824 set textconv "--textconv"
7827 if {[package vcompare $git_version "1.6.6"] >= 0} {
7828 set submodule "--submodule"
7830 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7834 if {$worddiff ne [mc "Line diff"]} {
7835 append cmd " --word-diff=porcelain"
7837 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7838 set cmd [concat $cmd -- $vfilelimit($curview)]
7840 if {[catch {set bdf [open $cmd r]} err]} {
7841 error_popup [mc "Error getting diffs: %s" $err]
7844 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7845 set blobdifffd($ids) $bdf
7847 filerun $bdf [list getblobdiffline $bdf $diffids]
7850 proc savecmitpos {} {
7851 global ctext cmitmode
7853 if {$cmitmode eq "tree"} {
7856 return [list target_scrollpos [$ctext index @0,0]]
7859 proc savectextpos {} {
7862 return [list target_scrollpos [$ctext index @0,0]]
7865 proc maybe_scroll_ctext {ateof} {
7866 global ctext target_scrollpos
7868 if {![info exists target_scrollpos]} return
7870 set nlines [expr {[winfo height $ctext]
7871 / [font metrics textfont -linespace]}]
7872 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7874 $ctext yview $target_scrollpos
7875 unset target_scrollpos
7878 proc setinlist {var i val} {
7881 while {[llength [set $var]] < $i} {
7884 if {[llength [set $var]] == $i} {
7891 proc makediffhdr {fname ids} {
7892 global ctext curdiffstart treediffs diffencoding
7893 global ctext_file_names jump_to_here targetline diffline
7895 set fname [encoding convertfrom $fname]
7896 set diffencoding [get_path_encoding $fname]
7897 set i [lsearch -exact $treediffs($ids) $fname]
7899 setinlist difffilestart $i $curdiffstart
7901 lset ctext_file_names end $fname
7902 set l [expr {(78 - [string length $fname]) / 2}]
7903 set pad [string range "----------------------------------------" 1 $l]
7904 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7906 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7907 set targetline [lindex $jump_to_here 1]
7912 proc blobdiffmaybeseehere {ateof} {
7914 if {$diffseehere >= 0} {
7915 mark_ctext_line [lindex [split $diffseehere .] 0]
7917 maybe_scroll_ctext ateof
7920 proc getblobdiffline {bdf ids} {
7921 global diffids blobdifffd
7925 $ctext conf -state normal
7926 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7927 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7931 parseblobdiffline $ids $line
7933 $ctext conf -state disabled
7934 blobdiffmaybeseehere [eof $bdf]
7939 return [expr {$nr >= 1000? 2: 1}]
7942 proc parseblobdiffline {ids line} {
7943 global ctext curdiffstart
7944 global diffnexthead diffnextnote difffilestart
7945 global ctext_file_names ctext_file_lines
7946 global diffinhdr treediffs mergemax diffnparents
7947 global diffencoding jump_to_here targetline diffline currdiffsubmod
7948 global worddiff diffseehere
7950 if {![string compare -length 5 "diff " $line]} {
7951 if {![regexp {^diff (--cc|--git) } $line m type]} {
7952 set line [encoding convertfrom $line]
7953 $ctext insert end "$line\n" hunksep
7956 # start of a new file
7958 $ctext insert end "\n"
7959 set curdiffstart [$ctext index "end - 1c"]
7960 lappend ctext_file_names ""
7961 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7962 $ctext insert end "\n" filesep
7964 if {$type eq "--cc"} {
7965 # start of a new file in a merge diff
7966 set fname [string range $line 10 end]
7967 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7968 lappend treediffs($ids) $fname
7969 add_flist [list $fname]
7973 set line [string range $line 11 end]
7974 # If the name hasn't changed the length will be odd,
7975 # the middle char will be a space, and the two bits either
7976 # side will be a/name and b/name, or "a/name" and "b/name".
7977 # If the name has changed we'll get "rename from" and
7978 # "rename to" or "copy from" and "copy to" lines following
7979 # this, and we'll use them to get the filenames.
7980 # This complexity is necessary because spaces in the
7981 # filename(s) don't get escaped.
7982 set l [string length $line]
7983 set i [expr {$l / 2}]
7984 if {!(($l & 1) && [string index $line $i] eq " " &&
7985 [string range $line 2 [expr {$i - 1}]] eq \
7986 [string range $line [expr {$i + 3}] end])} {
7989 # unescape if quoted and chop off the a/ from the front
7990 if {[string index $line 0] eq "\""} {
7991 set fname [string range [lindex $line 0] 2 end]
7993 set fname [string range $line 2 [expr {$i - 1}]]
7996 makediffhdr $fname $ids
7998 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7999 set fname [encoding convertfrom [string range $line 16 end]]
8000 $ctext insert end "\n"
8001 set curdiffstart [$ctext index "end - 1c"]
8002 lappend ctext_file_names $fname
8003 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8004 $ctext insert end "$line\n" filesep
8005 set i [lsearch -exact $treediffs($ids) $fname]
8007 setinlist difffilestart $i $curdiffstart
8010 } elseif {![string compare -length 2 "@@" $line]} {
8011 regexp {^@@+} $line ats
8012 set line [encoding convertfrom $diffencoding $line]
8013 $ctext insert end "$line\n" hunksep
8014 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8017 set diffnparents [expr {[string length $ats] - 1}]
8020 } elseif {![string compare -length 10 "Submodule " $line]} {
8021 # start of a new submodule
8022 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8023 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8025 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8027 if {$currdiffsubmod != $fname} {
8028 $ctext insert end "\n"; # Add newline after commit message
8030 set curdiffstart [$ctext index "end - 1c"]
8031 lappend ctext_file_names ""
8032 if {$currdiffsubmod != $fname} {
8033 lappend ctext_file_lines $fname
8034 makediffhdr $fname $ids
8035 set currdiffsubmod $fname
8036 $ctext insert end "\n$line\n" filesep
8038 $ctext insert end "$line\n" filesep
8040 } elseif {![string compare -length 3 " >" $line]} {
8041 set $currdiffsubmod ""
8042 set line [encoding convertfrom $diffencoding $line]
8043 $ctext insert end "$line\n" dresult
8044 } elseif {![string compare -length 3 " <" $line]} {
8045 set $currdiffsubmod ""
8046 set line [encoding convertfrom $diffencoding $line]
8047 $ctext insert end "$line\n" d0
8048 } elseif {$diffinhdr} {
8049 if {![string compare -length 12 "rename from " $line]} {
8050 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8051 if {[string index $fname 0] eq "\""} {
8052 set fname [lindex $fname 0]
8054 set fname [encoding convertfrom $fname]
8055 set i [lsearch -exact $treediffs($ids) $fname]
8057 setinlist difffilestart $i $curdiffstart
8059 } elseif {![string compare -length 10 $line "rename to "] ||
8060 ![string compare -length 8 $line "copy to "]} {
8061 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8062 if {[string index $fname 0] eq "\""} {
8063 set fname [lindex $fname 0]
8065 makediffhdr $fname $ids
8066 } elseif {[string compare -length 3 $line "---"] == 0} {
8069 } elseif {[string compare -length 3 $line "+++"] == 0} {
8073 $ctext insert end "$line\n" filesep
8076 set line [string map {\x1A ^Z} \
8077 [encoding convertfrom $diffencoding $line]]
8078 # parse the prefix - one ' ', '-' or '+' for each parent
8079 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8080 set tag [expr {$diffnparents > 1? "m": "d"}]
8081 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8082 set words_pre_markup ""
8083 set words_post_markup ""
8084 if {[string trim $prefix " -+"] eq {}} {
8085 # prefix only has " ", "-" and "+" in it: normal diff line
8086 set num [string first "-" $prefix]
8088 set line [string range $line 1 end]
8091 # removed line, first parent with line is $num
8092 if {$num >= $mergemax} {
8095 if {$dowords && $worddiff eq [mc "Markup words"]} {
8096 $ctext insert end "\[-$line-\]" $tag$num
8098 $ctext insert end "$line" $tag$num
8101 $ctext insert end "\n" $tag$num
8105 if {[string first "+" $prefix] >= 0} {
8107 lappend tags ${tag}result
8108 if {$diffnparents > 1} {
8109 set num [string first " " $prefix]
8111 if {$num >= $mergemax} {
8117 set words_pre_markup "{+"
8118 set words_post_markup "+}"
8120 if {$targetline ne {}} {
8121 if {$diffline == $targetline} {
8122 set diffseehere [$ctext index "end - 1 chars"]
8128 if {$dowords && $worddiff eq [mc "Markup words"]} {
8129 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8131 $ctext insert end "$line" $tags
8134 $ctext insert end "\n" $tags
8137 } elseif {$dowords && $prefix eq "~"} {
8138 $ctext insert end "\n" {}
8140 # "\ No newline at end of file",
8141 # or something else we don't recognize
8142 $ctext insert end "$line\n" hunksep
8147 proc changediffdisp {} {
8148 global ctext diffelide
8150 $ctext tag conf d0 -elide [lindex $diffelide 0]
8151 $ctext tag conf dresult -elide [lindex $diffelide 1]
8154 proc highlightfile {cline} {
8155 global cflist cflist_top
8157 if {![info exists cflist_top]} return
8159 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8160 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8161 $cflist see $cline.0
8162 set cflist_top $cline
8165 proc highlightfile_for_scrollpos {topidx} {
8166 global cmitmode difffilestart
8168 if {$cmitmode eq "tree"} return
8169 if {![info exists difffilestart]} return
8171 set top [lindex [split $topidx .] 0]
8172 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8175 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8180 global difffilestart ctext cmitmode
8182 if {$cmitmode eq "tree"} return
8184 set here [$ctext index @0,0]
8185 foreach loc $difffilestart {
8186 if {[$ctext compare $loc >= $here]} {
8196 global difffilestart ctext cmitmode
8198 if {$cmitmode eq "tree"} return
8199 set here [$ctext index @0,0]
8200 foreach loc $difffilestart {
8201 if {[$ctext compare $loc > $here]} {
8208 proc clear_ctext {{first 1.0}} {
8209 global ctext smarktop smarkbot
8210 global ctext_file_names ctext_file_lines
8213 set l [lindex [split $first .] 0]
8214 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8217 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8220 $ctext delete $first end
8221 if {$first eq "1.0"} {
8222 catch {unset pendinglinks}
8224 set ctext_file_names {}
8225 set ctext_file_lines {}
8228 proc settabs {{firstab {}}} {
8229 global firsttabstop tabstop ctext have_tk85
8231 if {$firstab ne {} && $have_tk85} {
8232 set firsttabstop $firstab
8234 set w [font measure textfont "0"]
8235 if {$firsttabstop != 0} {
8236 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8237 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8238 } elseif {$have_tk85 || $tabstop != 8} {
8239 $ctext conf -tabs [expr {$tabstop * $w}]
8241 $ctext conf -tabs {}
8245 proc incrsearch {name ix op} {
8246 global ctext searchstring searchdirn
8248 if {[catch {$ctext index anchor}]} {
8249 # no anchor set, use start of selection, or of visible area
8250 set sel [$ctext tag ranges sel]
8252 $ctext mark set anchor [lindex $sel 0]
8253 } elseif {$searchdirn eq "-forwards"} {
8254 $ctext mark set anchor @0,0
8256 $ctext mark set anchor @0,[winfo height $ctext]
8259 if {$searchstring ne {}} {
8260 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8263 set mend "$here + $mlen c"
8264 $ctext tag remove sel 1.0 end
8265 $ctext tag add sel $here $mend
8266 suppress_highlighting_file_for_current_scrollpos
8267 highlightfile_for_scrollpos $here
8270 rehighlight_search_results
8274 global sstring ctext searchstring searchdirn
8277 $sstring icursor end
8278 set searchdirn -forwards
8279 if {$searchstring ne {}} {
8280 set sel [$ctext tag ranges sel]
8282 set start "[lindex $sel 0] + 1c"
8283 } elseif {[catch {set start [$ctext index anchor]}]} {
8286 set match [$ctext search -count mlen -- $searchstring $start]
8287 $ctext tag remove sel 1.0 end
8293 suppress_highlighting_file_for_current_scrollpos
8294 highlightfile_for_scrollpos $match
8295 set mend "$match + $mlen c"
8296 $ctext tag add sel $match $mend
8297 $ctext mark unset anchor
8298 rehighlight_search_results
8302 proc dosearchback {} {
8303 global sstring ctext searchstring searchdirn
8306 $sstring icursor end
8307 set searchdirn -backwards
8308 if {$searchstring ne {}} {
8309 set sel [$ctext tag ranges sel]
8311 set start [lindex $sel 0]
8312 } elseif {[catch {set start [$ctext index anchor]}]} {
8313 set start @0,[winfo height $ctext]
8315 set match [$ctext search -backwards -count ml -- $searchstring $start]
8316 $ctext tag remove sel 1.0 end
8322 suppress_highlighting_file_for_current_scrollpos
8323 highlightfile_for_scrollpos $match
8324 set mend "$match + $ml c"
8325 $ctext tag add sel $match $mend
8326 $ctext mark unset anchor
8327 rehighlight_search_results
8331 proc rehighlight_search_results {} {
8332 global ctext searchstring
8334 $ctext tag remove found 1.0 end
8335 $ctext tag remove currentsearchhit 1.0 end
8337 if {$searchstring ne {}} {
8342 proc searchmark {first last} {
8343 global ctext searchstring
8345 set sel [$ctext tag ranges sel]
8349 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8350 if {$match eq {}} break
8351 set mend "$match + $mlen c"
8352 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8353 $ctext tag add currentsearchhit $match $mend
8355 $ctext tag add found $match $mend
8360 proc searchmarkvisible {doall} {
8361 global ctext smarktop smarkbot
8363 set topline [lindex [split [$ctext index @0,0] .] 0]
8364 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8365 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8366 # no overlap with previous
8367 searchmark $topline $botline
8368 set smarktop $topline
8369 set smarkbot $botline
8371 if {$topline < $smarktop} {
8372 searchmark $topline [expr {$smarktop-1}]
8373 set smarktop $topline
8375 if {$botline > $smarkbot} {
8376 searchmark [expr {$smarkbot+1}] $botline
8377 set smarkbot $botline
8382 proc suppress_highlighting_file_for_current_scrollpos {} {
8383 global ctext suppress_highlighting_file_for_this_scrollpos
8385 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8388 proc scrolltext {f0 f1} {
8389 global searchstring cmitmode ctext
8390 global suppress_highlighting_file_for_this_scrollpos
8392 set topidx [$ctext index @0,0]
8393 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8394 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8395 highlightfile_for_scrollpos $topidx
8398 catch {unset suppress_highlighting_file_for_this_scrollpos}
8400 .bleft.bottom.sb set $f0 $f1
8401 if {$searchstring ne {}} {
8407 global linespc charspc canvx0 canvy0
8408 global xspc1 xspc2 lthickness
8410 set linespc [font metrics mainfont -linespace]
8411 set charspc [font measure mainfont "m"]
8412 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8413 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8414 set lthickness [expr {int($linespc / 9) + 1}]
8415 set xspc1(0) $linespc
8423 set ymax [lindex [$canv cget -scrollregion] 3]
8424 if {$ymax eq {} || $ymax == 0} return
8425 set span [$canv yview]
8428 allcanvs yview moveto [lindex $span 0]
8430 if {$selectedline ne {}} {
8431 selectline $selectedline 0
8432 allcanvs yview moveto [lindex $span 0]
8436 proc parsefont {f n} {
8439 set fontattr($f,family) [lindex $n 0]
8441 if {$s eq {} || $s == 0} {
8444 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8446 set fontattr($f,size) $s
8447 set fontattr($f,weight) normal
8448 set fontattr($f,slant) roman
8449 foreach style [lrange $n 2 end] {
8452 "bold" {set fontattr($f,weight) $style}
8454 "italic" {set fontattr($f,slant) $style}
8459 proc fontflags {f {isbold 0}} {
8462 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8463 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8464 -slant $fontattr($f,slant)]
8470 set n [list $fontattr($f,family) $fontattr($f,size)]
8471 if {$fontattr($f,weight) eq "bold"} {
8474 if {$fontattr($f,slant) eq "italic"} {
8480 proc incrfont {inc} {
8481 global mainfont textfont ctext canv cflist showrefstop
8482 global stopped entries fontattr
8485 set s $fontattr(mainfont,size)
8490 set fontattr(mainfont,size) $s
8491 font config mainfont -size $s
8492 font config mainfontbold -size $s
8493 set mainfont [fontname mainfont]
8494 set s $fontattr(textfont,size)
8499 set fontattr(textfont,size) $s
8500 font config textfont -size $s
8501 font config textfontbold -size $s
8502 set textfont [fontname textfont]
8509 global sha1entry sha1string
8510 if {[string length $sha1string] == 40} {
8511 $sha1entry delete 0 end
8515 proc sha1change {n1 n2 op} {
8516 global sha1string currentid sha1but
8517 if {$sha1string == {}
8518 || ([info exists currentid] && $sha1string == $currentid)} {
8523 if {[$sha1but cget -state] == $state} return
8524 if {$state == "normal"} {
8525 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8527 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8531 proc gotocommit {} {
8532 global sha1string tagids headids curview varcid
8534 if {$sha1string == {}
8535 || ([info exists currentid] && $sha1string == $currentid)} return
8536 if {[info exists tagids($sha1string)]} {
8537 set id $tagids($sha1string)
8538 } elseif {[info exists headids($sha1string)]} {
8539 set id $headids($sha1string)
8541 set id [string tolower $sha1string]
8542 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8543 set matches [longid $id]
8544 if {$matches ne {}} {
8545 if {[llength $matches] > 1} {
8546 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8549 set id [lindex $matches 0]
8552 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8553 error_popup [mc "Revision %s is not known" $sha1string]
8558 if {[commitinview $id $curview]} {
8559 selectline [rowofcommit $id] 1
8562 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8563 set msg [mc "SHA1 id %s is not known" $sha1string]
8565 set msg [mc "Revision %s is not in the current view" $sha1string]
8570 proc lineenter {x y id} {
8571 global hoverx hovery hoverid hovertimer
8572 global commitinfo canv
8574 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8578 if {[info exists hovertimer]} {
8579 after cancel $hovertimer
8581 set hovertimer [after 500 linehover]
8585 proc linemotion {x y id} {
8586 global hoverx hovery hoverid hovertimer
8588 if {[info exists hoverid] && $id == $hoverid} {
8591 if {[info exists hovertimer]} {
8592 after cancel $hovertimer
8594 set hovertimer [after 500 linehover]
8598 proc lineleave {id} {
8599 global hoverid hovertimer canv
8601 if {[info exists hoverid] && $id == $hoverid} {
8603 if {[info exists hovertimer]} {
8604 after cancel $hovertimer
8612 global hoverx hovery hoverid hovertimer
8613 global canv linespc lthickness
8614 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8618 set text [lindex $commitinfo($hoverid) 0]
8619 set ymax [lindex [$canv cget -scrollregion] 3]
8620 if {$ymax == {}} return
8621 set yfrac [lindex [$canv yview] 0]
8622 set x [expr {$hoverx + 2 * $linespc}]
8623 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8624 set x0 [expr {$x - 2 * $lthickness}]
8625 set y0 [expr {$y - 2 * $lthickness}]
8626 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8627 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8628 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8629 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8630 -width 1 -tags hover]
8632 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8633 -font mainfont -fill $linehoverfgcolor]
8637 proc clickisonarrow {id y} {
8640 set ranges [rowranges $id]
8641 set thresh [expr {2 * $lthickness + 6}]
8642 set n [expr {[llength $ranges] - 1}]
8643 for {set i 1} {$i < $n} {incr i} {
8644 set row [lindex $ranges $i]
8645 if {abs([yc $row] - $y) < $thresh} {
8652 proc arrowjump {id n y} {
8655 # 1 <-> 2, 3 <-> 4, etc...
8656 set n [expr {(($n - 1) ^ 1) + 1}]
8657 set row [lindex [rowranges $id] $n]
8659 set ymax [lindex [$canv cget -scrollregion] 3]
8660 if {$ymax eq {} || $ymax <= 0} return
8661 set view [$canv yview]
8662 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8663 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8667 allcanvs yview moveto $yfrac
8670 proc lineclick {x y id isnew} {
8671 global ctext commitinfo children canv thickerline curview
8673 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8678 # draw this line thicker than normal
8682 set ymax [lindex [$canv cget -scrollregion] 3]
8683 if {$ymax eq {}} return
8684 set yfrac [lindex [$canv yview] 0]
8685 set y [expr {$y + $yfrac * $ymax}]
8687 set dirn [clickisonarrow $id $y]
8689 arrowjump $id $dirn $y
8694 addtohistory [list lineclick $x $y $id 0] savectextpos
8696 # fill the details pane with info about this line
8697 $ctext conf -state normal
8700 $ctext insert end "[mc "Parent"]:\t"
8701 $ctext insert end $id link0
8703 set info $commitinfo($id)
8704 $ctext insert end "\n\t[lindex $info 0]\n"
8705 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8706 set date [formatdate [lindex $info 2]]
8707 $ctext insert end "\t[mc "Date"]:\t$date\n"
8708 set kids $children($curview,$id)
8710 $ctext insert end "\n[mc "Children"]:"
8712 foreach child $kids {
8714 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8715 set info $commitinfo($child)
8716 $ctext insert end "\n\t"
8717 $ctext insert end $child link$i
8718 setlink $child link$i
8719 $ctext insert end "\n\t[lindex $info 0]"
8720 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8721 set date [formatdate [lindex $info 2]]
8722 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8725 maybe_scroll_ctext 1
8726 $ctext conf -state disabled
8730 proc normalline {} {
8732 if {[info exists thickerline]} {
8739 proc selbyid {id {isnew 1}} {
8741 if {[commitinview $id $curview]} {
8742 selectline [rowofcommit $id] $isnew
8748 if {![info exists startmstime]} {
8749 set startmstime [clock clicks -milliseconds]
8751 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8754 proc rowmenu {x y id} {
8755 global rowctxmenu selectedline rowmenuid curview
8756 global nullid nullid2 fakerowmenu mainhead markedid
8760 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8765 if {[info exists markedid] && $markedid ne $id} {
8770 if {$id ne $nullid && $id ne $nullid2} {
8771 set menu $rowctxmenu
8772 if {$mainhead ne {}} {
8773 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8775 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8777 $menu entryconfigure 9 -state $mstate
8778 $menu entryconfigure 10 -state $mstate
8779 $menu entryconfigure 11 -state $mstate
8781 set menu $fakerowmenu
8783 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8784 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8785 $menu entryconfigure [mca "Make patch"] -state $state
8786 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8787 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8788 tk_popup $menu $x $y
8792 global rowmenuid markedid canv
8794 set markedid $rowmenuid
8795 make_idmark $markedid
8801 if {[info exists markedid]} {
8806 proc replace_by_kids {l r} {
8807 global curview children
8809 set id [commitonrow $r]
8810 set l [lreplace $l 0 0]
8811 foreach kid $children($curview,$id) {
8812 lappend l [rowofcommit $kid]
8814 return [lsort -integer -decreasing -unique $l]
8817 proc find_common_desc {} {
8818 global markedid rowmenuid curview children
8820 if {![info exists markedid]} return
8821 if {![commitinview $markedid $curview] ||
8822 ![commitinview $rowmenuid $curview]} return
8823 #set t1 [clock clicks -milliseconds]
8824 set l1 [list [rowofcommit $markedid]]
8825 set l2 [list [rowofcommit $rowmenuid]]
8827 set r1 [lindex $l1 0]
8828 set r2 [lindex $l2 0]
8829 if {$r1 eq {} || $r2 eq {}} break
8835 set l1 [replace_by_kids $l1 $r1]
8837 set l2 [replace_by_kids $l2 $r2]
8840 #set t2 [clock clicks -milliseconds]
8841 #puts "took [expr {$t2-$t1}]ms"
8844 proc compare_commits {} {
8845 global markedid rowmenuid curview children
8847 if {![info exists markedid]} return
8848 if {![commitinview $markedid $curview]} return
8849 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8850 do_cmp_commits $markedid $rowmenuid
8853 proc getpatchid {id} {
8856 if {![info exists patchids($id)]} {
8857 set cmd [diffcmd [list $id] {-p --root}]
8858 # trim off the initial "|"
8859 set cmd [lrange $cmd 1 end]
8861 set x [eval exec $cmd | git patch-id]
8862 set patchids($id) [lindex $x 0]
8864 set patchids($id) "error"
8867 return $patchids($id)
8870 proc do_cmp_commits {a b} {
8871 global ctext curview parents children patchids commitinfo
8873 $ctext conf -state normal
8876 for {set i 0} {$i < 100} {incr i} {
8879 if {[llength $parents($curview,$a)] > 1} {
8880 appendshortlink $a [mc "Skipping merge commit "] "\n"
8883 set patcha [getpatchid $a]
8885 if {[llength $parents($curview,$b)] > 1} {
8886 appendshortlink $b [mc "Skipping merge commit "] "\n"
8889 set patchb [getpatchid $b]
8891 if {!$skipa && !$skipb} {
8892 set heada [lindex $commitinfo($a) 0]
8893 set headb [lindex $commitinfo($b) 0]
8894 if {$patcha eq "error"} {
8895 appendshortlink $a [mc "Error getting patch ID for "] \
8896 [mc " - stopping\n"]
8899 if {$patchb eq "error"} {
8900 appendshortlink $b [mc "Error getting patch ID for "] \
8901 [mc " - stopping\n"]
8904 if {$patcha eq $patchb} {
8905 if {$heada eq $headb} {
8906 appendshortlink $a [mc "Commit "]
8907 appendshortlink $b " == " " $heada\n"
8909 appendshortlink $a [mc "Commit "] " $heada\n"
8910 appendshortlink $b [mc " is the same patch as\n "] \
8916 $ctext insert end "\n"
8917 appendshortlink $a [mc "Commit "] " $heada\n"
8918 appendshortlink $b [mc " differs from\n "] \
8920 $ctext insert end [mc "Diff of commits:\n\n"]
8921 $ctext conf -state disabled
8928 set kids [real_children $curview,$a]
8929 if {[llength $kids] != 1} {
8930 $ctext insert end "\n"
8931 appendshortlink $a [mc "Commit "] \
8932 [mc " has %s children - stopping\n" [llength $kids]]
8935 set a [lindex $kids 0]
8938 set kids [real_children $curview,$b]
8939 if {[llength $kids] != 1} {
8940 appendshortlink $b [mc "Commit "] \
8941 [mc " has %s children - stopping\n" [llength $kids]]
8944 set b [lindex $kids 0]
8947 $ctext conf -state disabled
8950 proc diffcommits {a b} {
8951 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8953 set tmpdir [gitknewtmpdir]
8954 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8955 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8957 exec git diff-tree -p --pretty $a >$fna
8958 exec git diff-tree -p --pretty $b >$fnb
8960 error_popup [mc "Error writing commit to file: %s" $err]
8964 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8966 error_popup [mc "Error diffing commits: %s" $err]
8969 set diffids [list commits $a $b]
8970 set blobdifffd($diffids) $fd
8972 set currdiffsubmod ""
8973 filerun $fd [list getblobdiffline $fd $diffids]
8976 proc diffvssel {dirn} {
8977 global rowmenuid selectedline
8979 if {$selectedline eq {}} return
8981 set oldid [commitonrow $selectedline]
8982 set newid $rowmenuid
8984 set oldid $rowmenuid
8985 set newid [commitonrow $selectedline]
8987 addtohistory [list doseldiff $oldid $newid] savectextpos
8988 doseldiff $oldid $newid
8991 proc diffvsmark {dirn} {
8992 global rowmenuid markedid
8994 if {![info exists markedid]} return
8997 set newid $rowmenuid
8999 set oldid $rowmenuid
9002 addtohistory [list doseldiff $oldid $newid] savectextpos
9003 doseldiff $oldid $newid
9006 proc doseldiff {oldid newid} {
9010 $ctext conf -state normal
9012 init_flist [mc "Top"]
9013 $ctext insert end "[mc "From"] "
9014 $ctext insert end $oldid link0
9015 setlink $oldid link0
9016 $ctext insert end "\n "
9017 $ctext insert end [lindex $commitinfo($oldid) 0]
9018 $ctext insert end "\n\n[mc "To"] "
9019 $ctext insert end $newid link1
9020 setlink $newid link1
9021 $ctext insert end "\n "
9022 $ctext insert end [lindex $commitinfo($newid) 0]
9023 $ctext insert end "\n"
9024 $ctext conf -state disabled
9025 $ctext tag remove found 1.0 end
9026 startdiff [list $oldid $newid]
9030 global rowmenuid currentid commitinfo patchtop patchnum NS
9032 if {![info exists currentid]} return
9033 set oldid $currentid
9034 set oldhead [lindex $commitinfo($oldid) 0]
9035 set newid $rowmenuid
9036 set newhead [lindex $commitinfo($newid) 0]
9039 catch {destroy $top}
9041 make_transient $top .
9042 ${NS}::label $top.title -text [mc "Generate patch"]
9043 grid $top.title - -pady 10
9044 ${NS}::label $top.from -text [mc "From:"]
9045 ${NS}::entry $top.fromsha1 -width 40
9046 $top.fromsha1 insert 0 $oldid
9047 $top.fromsha1 conf -state readonly
9048 grid $top.from $top.fromsha1 -sticky w
9049 ${NS}::entry $top.fromhead -width 60
9050 $top.fromhead insert 0 $oldhead
9051 $top.fromhead conf -state readonly
9052 grid x $top.fromhead -sticky w
9053 ${NS}::label $top.to -text [mc "To:"]
9054 ${NS}::entry $top.tosha1 -width 40
9055 $top.tosha1 insert 0 $newid
9056 $top.tosha1 conf -state readonly
9057 grid $top.to $top.tosha1 -sticky w
9058 ${NS}::entry $top.tohead -width 60
9059 $top.tohead insert 0 $newhead
9060 $top.tohead conf -state readonly
9061 grid x $top.tohead -sticky w
9062 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9063 grid $top.rev x -pady 10 -padx 5
9064 ${NS}::label $top.flab -text [mc "Output file:"]
9065 ${NS}::entry $top.fname -width 60
9066 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9068 grid $top.flab $top.fname -sticky w
9069 ${NS}::frame $top.buts
9070 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9071 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9072 bind $top <Key-Return> mkpatchgo
9073 bind $top <Key-Escape> mkpatchcan
9074 grid $top.buts.gen $top.buts.can
9075 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9076 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9077 grid $top.buts - -pady 10 -sticky ew
9081 proc mkpatchrev {} {
9084 set oldid [$patchtop.fromsha1 get]
9085 set oldhead [$patchtop.fromhead get]
9086 set newid [$patchtop.tosha1 get]
9087 set newhead [$patchtop.tohead get]
9088 foreach e [list fromsha1 fromhead tosha1 tohead] \
9089 v [list $newid $newhead $oldid $oldhead] {
9090 $patchtop.$e conf -state normal
9091 $patchtop.$e delete 0 end
9092 $patchtop.$e insert 0 $v
9093 $patchtop.$e conf -state readonly
9098 global patchtop nullid nullid2
9100 set oldid [$patchtop.fromsha1 get]
9101 set newid [$patchtop.tosha1 get]
9102 set fname [$patchtop.fname get]
9103 set cmd [diffcmd [list $oldid $newid] -p]
9104 # trim off the initial "|"
9105 set cmd [lrange $cmd 1 end]
9106 lappend cmd >$fname &
9107 if {[catch {eval exec $cmd} err]} {
9108 error_popup "[mc "Error creating patch:"] $err" $patchtop
9110 catch {destroy $patchtop}
9114 proc mkpatchcan {} {
9117 catch {destroy $patchtop}
9122 global rowmenuid mktagtop commitinfo NS
9126 catch {destroy $top}
9128 make_transient $top .
9129 ${NS}::label $top.title -text [mc "Create tag"]
9130 grid $top.title - -pady 10
9131 ${NS}::label $top.id -text [mc "ID:"]
9132 ${NS}::entry $top.sha1 -width 40
9133 $top.sha1 insert 0 $rowmenuid
9134 $top.sha1 conf -state readonly
9135 grid $top.id $top.sha1 -sticky w
9136 ${NS}::entry $top.head -width 60
9137 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9138 $top.head conf -state readonly
9139 grid x $top.head -sticky w
9140 ${NS}::label $top.tlab -text [mc "Tag name:"]
9141 ${NS}::entry $top.tag -width 60
9142 grid $top.tlab $top.tag -sticky w
9143 ${NS}::label $top.op -text [mc "Tag message is optional"]
9144 grid $top.op -columnspan 2 -sticky we
9145 ${NS}::label $top.mlab -text [mc "Tag message:"]
9146 ${NS}::entry $top.msg -width 60
9147 grid $top.mlab $top.msg -sticky w
9148 ${NS}::frame $top.buts
9149 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9150 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9151 bind $top <Key-Return> mktaggo
9152 bind $top <Key-Escape> mktagcan
9153 grid $top.buts.gen $top.buts.can
9154 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9155 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9156 grid $top.buts - -pady 10 -sticky ew
9161 global mktagtop env tagids idtags
9163 set id [$mktagtop.sha1 get]
9164 set tag [$mktagtop.tag get]
9165 set msg [$mktagtop.msg get]
9167 error_popup [mc "No tag name specified"] $mktagtop
9170 if {[info exists tagids($tag)]} {
9171 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9176 exec git tag -a -m $msg $tag $id
9178 exec git tag $tag $id
9181 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9185 set tagids($tag) $id
9186 lappend idtags($id) $tag
9194 proc redrawtags {id} {
9195 global canv linehtag idpos currentid curview cmitlisted markedid
9196 global canvxmax iddrawn circleitem mainheadid circlecolors
9197 global mainheadcirclecolor
9199 if {![commitinview $id $curview]} return
9200 if {![info exists iddrawn($id)]} return
9201 set row [rowofcommit $id]
9202 if {$id eq $mainheadid} {
9203 set ofill $mainheadcirclecolor
9205 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9207 $canv itemconf $circleitem($row) -fill $ofill
9208 $canv delete tag.$id
9209 set xt [eval drawtags $id $idpos($id)]
9210 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9211 set text [$canv itemcget $linehtag($id) -text]
9212 set font [$canv itemcget $linehtag($id) -font]
9213 set xr [expr {$xt + [font measure $font $text]}]
9214 if {$xr > $canvxmax} {
9218 if {[info exists currentid] && $currentid == $id} {
9221 if {[info exists markedid] && $markedid eq $id} {
9229 catch {destroy $mktagtop}
9234 if {![domktag]} return
9238 proc writecommit {} {
9239 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9241 set top .writecommit
9243 catch {destroy $top}
9245 make_transient $top .
9246 ${NS}::label $top.title -text [mc "Write commit to file"]
9247 grid $top.title - -pady 10
9248 ${NS}::label $top.id -text [mc "ID:"]
9249 ${NS}::entry $top.sha1 -width 40
9250 $top.sha1 insert 0 $rowmenuid
9251 $top.sha1 conf -state readonly
9252 grid $top.id $top.sha1 -sticky w
9253 ${NS}::entry $top.head -width 60
9254 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9255 $top.head conf -state readonly
9256 grid x $top.head -sticky w
9257 ${NS}::label $top.clab -text [mc "Command:"]
9258 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9259 grid $top.clab $top.cmd -sticky w -pady 10
9260 ${NS}::label $top.flab -text [mc "Output file:"]
9261 ${NS}::entry $top.fname -width 60
9262 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9263 grid $top.flab $top.fname -sticky w
9264 ${NS}::frame $top.buts
9265 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9266 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9267 bind $top <Key-Return> wrcomgo
9268 bind $top <Key-Escape> wrcomcan
9269 grid $top.buts.gen $top.buts.can
9270 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9271 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9272 grid $top.buts - -pady 10 -sticky ew
9279 set id [$wrcomtop.sha1 get]
9280 set cmd "echo $id | [$wrcomtop.cmd get]"
9281 set fname [$wrcomtop.fname get]
9282 if {[catch {exec sh -c $cmd >$fname &} err]} {
9283 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9285 catch {destroy $wrcomtop}
9292 catch {destroy $wrcomtop}
9297 global rowmenuid mkbrtop NS
9300 catch {destroy $top}
9302 make_transient $top .
9303 ${NS}::label $top.title -text [mc "Create new branch"]
9304 grid $top.title - -pady 10
9305 ${NS}::label $top.id -text [mc "ID:"]
9306 ${NS}::entry $top.sha1 -width 40
9307 $top.sha1 insert 0 $rowmenuid
9308 $top.sha1 conf -state readonly
9309 grid $top.id $top.sha1 -sticky w
9310 ${NS}::label $top.nlab -text [mc "Name:"]
9311 ${NS}::entry $top.name -width 40
9312 grid $top.nlab $top.name -sticky w
9313 ${NS}::frame $top.buts
9314 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9315 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9316 bind $top <Key-Return> [list mkbrgo $top]
9317 bind $top <Key-Escape> "catch {destroy $top}"
9318 grid $top.buts.go $top.buts.can
9319 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9320 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9321 grid $top.buts - -pady 10 -sticky ew
9326 global headids idheads
9328 set name [$top.name get]
9329 set id [$top.sha1 get]
9333 error_popup [mc "Please specify a name for the new branch"] $top
9336 if {[info exists headids($name)]} {
9337 if {![confirm_popup [mc \
9338 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9341 set old_id $headids($name)
9344 catch {destroy $top}
9345 lappend cmdargs $name $id
9349 eval exec git branch $cmdargs
9355 if {$old_id ne {}} {
9361 set headids($name) $id
9362 lappend idheads($id) $name
9371 proc exec_citool {tool_args {baseid {}}} {
9372 global commitinfo env
9374 set save_env [array get env GIT_AUTHOR_*]
9376 if {$baseid ne {}} {
9377 if {![info exists commitinfo($baseid)]} {
9380 set author [lindex $commitinfo($baseid) 1]
9381 set date [lindex $commitinfo($baseid) 2]
9382 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9383 $author author name email]
9385 set env(GIT_AUTHOR_NAME) $name
9386 set env(GIT_AUTHOR_EMAIL) $email
9387 set env(GIT_AUTHOR_DATE) $date
9391 eval exec git citool $tool_args &
9393 array unset env GIT_AUTHOR_*
9394 array set env $save_env
9397 proc cherrypick {} {
9398 global rowmenuid curview
9399 global mainhead mainheadid
9402 set oldhead [exec git rev-parse HEAD]
9403 set dheads [descheads $rowmenuid]
9404 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9405 set ok [confirm_popup [mc "Commit %s is already\
9406 included in branch %s -- really re-apply it?" \
9407 [string range $rowmenuid 0 7] $mainhead]]
9410 nowbusy cherrypick [mc "Cherry-picking"]
9412 # Unfortunately git-cherry-pick writes stuff to stderr even when
9413 # no error occurs, and exec takes that as an indication of error...
9414 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9417 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9419 error_popup [mc "Cherry-pick failed because of local changes\
9420 to file '%s'.\nPlease commit, reset or stash\
9421 your changes and try again." $fname]
9422 } elseif {[regexp -line \
9423 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9425 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9426 conflict.\nDo you wish to run git citool to\
9428 # Force citool to read MERGE_MSG
9429 file delete [file join $gitdir "GITGUI_MSG"]
9430 exec_citool {} $rowmenuid
9438 set newhead [exec git rev-parse HEAD]
9439 if {$newhead eq $oldhead} {
9441 error_popup [mc "No changes committed"]
9444 addnewchild $newhead $oldhead
9445 if {[commitinview $oldhead $curview]} {
9446 # XXX this isn't right if we have a path limit...
9447 insertrow $newhead $oldhead $curview
9448 if {$mainhead ne {}} {
9449 movehead $newhead $mainhead
9450 movedhead $newhead $mainhead
9452 set mainheadid $newhead
9461 global rowmenuid curview
9462 global mainhead mainheadid
9465 set oldhead [exec git rev-parse HEAD]
9466 set dheads [descheads $rowmenuid]
9467 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9468 set ok [confirm_popup [mc "Commit %s is not\
9469 included in branch %s -- really revert it?" \
9470 [string range $rowmenuid 0 7] $mainhead]]
9473 nowbusy revert [mc "Reverting"]
9476 if [catch {exec git revert --no-edit $rowmenuid} err] {
9478 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9480 regsub {\n( |\t)+} $files "\n" files
9481 error_popup [mc "Revert failed because of local changes to\
9482 the following files:%s Please commit, reset or stash \
9483 your changes and try again." $files]
9484 } elseif [regexp {error: could not revert} $err] {
9485 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9486 Do you wish to run git citool to resolve it?"]] {
9487 # Force citool to read MERGE_MSG
9488 file delete [file join $gitdir "GITGUI_MSG"]
9489 exec_citool {} $rowmenuid
9491 } else { error_popup $err }
9496 set newhead [exec git rev-parse HEAD]
9497 if { $newhead eq $oldhead } {
9499 error_popup [mc "No changes committed"]
9503 addnewchild $newhead $oldhead
9505 if [commitinview $oldhead $curview] {
9506 # XXX this isn't right if we have a path limit...
9507 insertrow $newhead $oldhead $curview
9508 if {$mainhead ne {}} {
9509 movehead $newhead $mainhead
9510 movedhead $newhead $mainhead
9512 set mainheadid $newhead
9522 global mainhead rowmenuid confirm_ok resettype NS
9525 set w ".confirmreset"
9528 wm title $w [mc "Confirm reset"]
9529 ${NS}::label $w.m -text \
9530 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9531 pack $w.m -side top -fill x -padx 20 -pady 20
9532 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9534 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9535 -text [mc "Soft: Leave working tree and index untouched"]
9536 grid $w.f.soft -sticky w
9537 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9538 -text [mc "Mixed: Leave working tree untouched, reset index"]
9539 grid $w.f.mixed -sticky w
9540 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9541 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9542 grid $w.f.hard -sticky w
9543 pack $w.f -side top -fill x -padx 4
9544 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9545 pack $w.ok -side left -fill x -padx 20 -pady 20
9546 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9547 bind $w <Key-Escape> [list destroy $w]
9548 pack $w.cancel -side right -fill x -padx 20 -pady 20
9549 bind $w <Visibility> "grab $w; focus $w"
9551 if {!$confirm_ok} return
9552 if {[catch {set fd [open \
9553 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9557 filerun $fd [list readresetstat $fd]
9558 nowbusy reset [mc "Resetting"]
9563 proc readresetstat {fd} {
9564 global mainhead mainheadid showlocalchanges rprogcoord
9566 if {[gets $fd line] >= 0} {
9567 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9568 set rprogcoord [expr {1.0 * $m / $n}]
9576 if {[catch {close $fd} err]} {
9579 set oldhead $mainheadid
9580 set newhead [exec git rev-parse HEAD]
9581 if {$newhead ne $oldhead} {
9582 movehead $newhead $mainhead
9583 movedhead $newhead $mainhead
9584 set mainheadid $newhead
9588 if {$showlocalchanges} {
9594 # context menu for a head
9595 proc headmenu {x y id head} {
9596 global headmenuid headmenuhead headctxmenu mainhead
9600 set headmenuhead $head
9602 if {[string match "remotes/*" $head]} {
9605 if {$head eq $mainhead} {
9608 $headctxmenu entryconfigure 0 -state $state
9609 $headctxmenu entryconfigure 1 -state $state
9610 tk_popup $headctxmenu $x $y
9614 global headmenuid headmenuhead headids
9615 global showlocalchanges
9617 # check the tree is clean first??
9618 nowbusy checkout [mc "Checking out"]
9622 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9626 if {$showlocalchanges} {
9630 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9634 proc readcheckoutstat {fd newhead newheadid} {
9635 global mainhead mainheadid headids showlocalchanges progresscoords
9636 global viewmainheadid curview
9638 if {[gets $fd line] >= 0} {
9639 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9640 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9645 set progresscoords {0 0}
9648 if {[catch {close $fd} err]} {
9651 set oldmainid $mainheadid
9652 set mainhead $newhead
9653 set mainheadid $newheadid
9654 set viewmainheadid($curview) $newheadid
9655 redrawtags $oldmainid
9656 redrawtags $newheadid
9658 if {$showlocalchanges} {
9664 global headmenuid headmenuhead mainhead
9667 set head $headmenuhead
9669 # this check shouldn't be needed any more...
9670 if {$head eq $mainhead} {
9671 error_popup [mc "Cannot delete the currently checked-out branch"]
9674 set dheads [descheads $id]
9675 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9676 # the stuff on this branch isn't on any other branch
9677 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9678 branch.\nReally delete branch %s?" $head $head]]} return
9682 if {[catch {exec git branch -D $head} err]} {
9687 removehead $id $head
9688 removedhead $id $head
9695 # Display a list of tags and heads
9697 global showrefstop bgcolor fgcolor selectbgcolor NS
9698 global bglist fglist reflistfilter reflist maincursor
9701 set showrefstop $top
9702 if {[winfo exists $top]} {
9708 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9709 make_transient $top .
9710 text $top.list -background $bgcolor -foreground $fgcolor \
9711 -selectbackground $selectbgcolor -font mainfont \
9712 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9713 -width 30 -height 20 -cursor $maincursor \
9714 -spacing1 1 -spacing3 1 -state disabled
9715 $top.list tag configure highlight -background $selectbgcolor
9716 lappend bglist $top.list
9717 lappend fglist $top.list
9718 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9719 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9720 grid $top.list $top.ysb -sticky nsew
9721 grid $top.xsb x -sticky ew
9723 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9724 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9725 set reflistfilter "*"
9726 trace add variable reflistfilter write reflistfilter_change
9727 pack $top.f.e -side right -fill x -expand 1
9728 pack $top.f.l -side left
9729 grid $top.f - -sticky ew -pady 2
9730 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9731 bind $top <Key-Escape> [list destroy $top]
9733 grid columnconfigure $top 0 -weight 1
9734 grid rowconfigure $top 0 -weight 1
9735 bind $top.list <1> {break}
9736 bind $top.list <B1-Motion> {break}
9737 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9742 proc sel_reflist {w x y} {
9743 global showrefstop reflist headids tagids otherrefids
9745 if {![winfo exists $showrefstop]} return
9746 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9747 set ref [lindex $reflist [expr {$l-1}]]
9748 set n [lindex $ref 0]
9749 switch -- [lindex $ref 1] {
9750 "H" {selbyid $headids($n)}
9751 "T" {selbyid $tagids($n)}
9752 "o" {selbyid $otherrefids($n)}
9754 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9757 proc unsel_reflist {} {
9760 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9761 $showrefstop.list tag remove highlight 0.0 end
9764 proc reflistfilter_change {n1 n2 op} {
9765 global reflistfilter
9767 after cancel refill_reflist
9768 after 200 refill_reflist
9771 proc refill_reflist {} {
9772 global reflist reflistfilter showrefstop headids tagids otherrefids
9775 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9777 foreach n [array names headids] {
9778 if {[string match $reflistfilter $n]} {
9779 if {[commitinview $headids($n) $curview]} {
9780 lappend refs [list $n H]
9782 interestedin $headids($n) {run refill_reflist}
9786 foreach n [array names tagids] {
9787 if {[string match $reflistfilter $n]} {
9788 if {[commitinview $tagids($n) $curview]} {
9789 lappend refs [list $n T]
9791 interestedin $tagids($n) {run refill_reflist}
9795 foreach n [array names otherrefids] {
9796 if {[string match $reflistfilter $n]} {
9797 if {[commitinview $otherrefids($n) $curview]} {
9798 lappend refs [list $n o]
9800 interestedin $otherrefids($n) {run refill_reflist}
9804 set refs [lsort -index 0 $refs]
9805 if {$refs eq $reflist} return
9807 # Update the contents of $showrefstop.list according to the
9808 # differences between $reflist (old) and $refs (new)
9809 $showrefstop.list conf -state normal
9810 $showrefstop.list insert end "\n"
9813 while {$i < [llength $reflist] || $j < [llength $refs]} {
9814 if {$i < [llength $reflist]} {
9815 if {$j < [llength $refs]} {
9816 set cmp [string compare [lindex $reflist $i 0] \
9817 [lindex $refs $j 0]]
9819 set cmp [string compare [lindex $reflist $i 1] \
9820 [lindex $refs $j 1]]
9830 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9838 set l [expr {$j + 1}]
9839 $showrefstop.list image create $l.0 -align baseline \
9840 -image reficon-[lindex $refs $j 1] -padx 2
9841 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9847 # delete last newline
9848 $showrefstop.list delete end-2c end-1c
9849 $showrefstop.list conf -state disabled
9852 # Stuff for finding nearby tags
9853 proc getallcommits {} {
9854 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9855 global idheads idtags idotherrefs allparents tagobjid
9858 if {![info exists allcommits]} {
9864 set allccache [file join $gitdir "gitk.cache"]
9866 set f [open $allccache r]
9875 set cmd [list | git rev-list --parents]
9876 set allcupdate [expr {$seeds ne {}}]
9880 set refs [concat [array names idheads] [array names idtags] \
9881 [array names idotherrefs]]
9884 foreach name [array names tagobjid] {
9885 lappend tagobjs $tagobjid($name)
9887 foreach id [lsort -unique $refs] {
9888 if {![info exists allparents($id)] &&
9889 [lsearch -exact $tagobjs $id] < 0} {
9900 set fd [open [concat $cmd $ids] r]
9901 fconfigure $fd -blocking 0
9904 filerun $fd [list getallclines $fd]
9910 # Since most commits have 1 parent and 1 child, we group strings of
9911 # such commits into "arcs" joining branch/merge points (BMPs), which
9912 # are commits that either don't have 1 parent or don't have 1 child.
9914 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9915 # arcout(id) - outgoing arcs for BMP
9916 # arcids(a) - list of IDs on arc including end but not start
9917 # arcstart(a) - BMP ID at start of arc
9918 # arcend(a) - BMP ID at end of arc
9919 # growing(a) - arc a is still growing
9920 # arctags(a) - IDs out of arcids (excluding end) that have tags
9921 # archeads(a) - IDs out of arcids (excluding end) that have heads
9922 # The start of an arc is at the descendent end, so "incoming" means
9923 # coming from descendents, and "outgoing" means going towards ancestors.
9925 proc getallclines {fd} {
9926 global allparents allchildren idtags idheads nextarc
9927 global arcnos arcids arctags arcout arcend arcstart archeads growing
9928 global seeds allcommits cachedarcs allcupdate
9931 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9932 set id [lindex $line 0]
9933 if {[info exists allparents($id)]} {
9938 set olds [lrange $line 1 end]
9939 set allparents($id) $olds
9940 if {![info exists allchildren($id)]} {
9941 set allchildren($id) {}
9946 if {[llength $olds] == 1 && [llength $a] == 1} {
9947 lappend arcids($a) $id
9948 if {[info exists idtags($id)]} {
9949 lappend arctags($a) $id
9951 if {[info exists idheads($id)]} {
9952 lappend archeads($a) $id
9954 if {[info exists allparents($olds)]} {
9955 # seen parent already
9956 if {![info exists arcout($olds)]} {
9959 lappend arcids($a) $olds
9960 set arcend($a) $olds
9963 lappend allchildren($olds) $id
9964 lappend arcnos($olds) $a
9968 foreach a $arcnos($id) {
9969 lappend arcids($a) $id
9976 lappend allchildren($p) $id
9977 set a [incr nextarc]
9978 set arcstart($a) $id
9985 if {[info exists allparents($p)]} {
9986 # seen it already, may need to make a new branch
9987 if {![info exists arcout($p)]} {
9990 lappend arcids($a) $p
9994 lappend arcnos($p) $a
9999 global cached_dheads cached_dtags cached_atags
10000 catch {unset cached_dheads}
10001 catch {unset cached_dtags}
10002 catch {unset cached_atags}
10005 return [expr {$nid >= 1000? 2: 1}]
10009 fconfigure $fd -blocking 1
10012 # got an error reading the list of commits
10013 # if we were updating, try rereading the whole thing again
10019 error_popup "[mc "Error reading commit topology information;\
10020 branch and preceding/following tag information\
10021 will be incomplete."]\n($err)"
10024 if {[incr allcommits -1] == 0} {
10034 proc recalcarc {a} {
10035 global arctags archeads arcids idtags idheads
10039 foreach id [lrange $arcids($a) 0 end-1] {
10040 if {[info exists idtags($id)]} {
10043 if {[info exists idheads($id)]} {
10047 set arctags($a) $at
10048 set archeads($a) $ah
10051 proc splitarc {p} {
10052 global arcnos arcids nextarc arctags archeads idtags idheads
10053 global arcstart arcend arcout allparents growing
10056 if {[llength $a] != 1} {
10057 puts "oops splitarc called but [llength $a] arcs already"
10060 set a [lindex $a 0]
10061 set i [lsearch -exact $arcids($a) $p]
10063 puts "oops splitarc $p not in arc $a"
10066 set na [incr nextarc]
10067 if {[info exists arcend($a)]} {
10068 set arcend($na) $arcend($a)
10070 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10071 set j [lsearch -exact $arcnos($l) $a]
10072 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10074 set tail [lrange $arcids($a) [expr {$i+1}] end]
10075 set arcids($a) [lrange $arcids($a) 0 $i]
10077 set arcstart($na) $p
10079 set arcids($na) $tail
10080 if {[info exists growing($a)]} {
10086 if {[llength $arcnos($id)] == 1} {
10087 set arcnos($id) $na
10089 set j [lsearch -exact $arcnos($id) $a]
10090 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10094 # reconstruct tags and heads lists
10095 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10099 set arctags($na) {}
10100 set archeads($na) {}
10104 # Update things for a new commit added that is a child of one
10105 # existing commit. Used when cherry-picking.
10106 proc addnewchild {id p} {
10107 global allparents allchildren idtags nextarc
10108 global arcnos arcids arctags arcout arcend arcstart archeads growing
10109 global seeds allcommits
10111 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10112 set allparents($id) [list $p]
10113 set allchildren($id) {}
10116 lappend allchildren($p) $id
10117 set a [incr nextarc]
10118 set arcstart($a) $id
10119 set archeads($a) {}
10121 set arcids($a) [list $p]
10123 if {![info exists arcout($p)]} {
10126 lappend arcnos($p) $a
10127 set arcout($id) [list $a]
10130 # This implements a cache for the topology information.
10131 # The cache saves, for each arc, the start and end of the arc,
10132 # the ids on the arc, and the outgoing arcs from the end.
10133 proc readcache {f} {
10134 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10135 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10139 set lim $cachedarcs
10140 if {$lim - $a > 500} {
10141 set lim [expr {$a + 500}]
10145 # finish reading the cache and setting up arctags, etc.
10147 if {$line ne "1"} {error "bad final version"}
10149 foreach id [array names idtags] {
10150 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10151 [llength $allparents($id)] == 1} {
10152 set a [lindex $arcnos($id) 0]
10153 if {$arctags($a) eq {}} {
10158 foreach id [array names idheads] {
10159 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10160 [llength $allparents($id)] == 1} {
10161 set a [lindex $arcnos($id) 0]
10162 if {$archeads($a) eq {}} {
10167 foreach id [lsort -unique $possible_seeds] {
10168 if {$arcnos($id) eq {}} {
10174 while {[incr a] <= $lim} {
10176 if {[llength $line] != 3} {error "bad line"}
10177 set s [lindex $line 0]
10178 set arcstart($a) $s
10179 lappend arcout($s) $a
10180 if {![info exists arcnos($s)]} {
10181 lappend possible_seeds $s
10184 set e [lindex $line 1]
10189 if {![info exists arcout($e)]} {
10193 set arcids($a) [lindex $line 2]
10194 foreach id $arcids($a) {
10195 lappend allparents($s) $id
10197 lappend arcnos($id) $a
10199 if {![info exists allparents($s)]} {
10200 set allparents($s) {}
10203 set archeads($a) {}
10205 set nextarc [expr {$a - 1}]
10217 proc getcache {f} {
10218 global nextarc cachedarcs possible_seeds
10222 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10223 # make sure it's an integer
10224 set cachedarcs [expr {int([lindex $line 1])}]
10225 if {$cachedarcs < 0} {error "bad number of arcs"}
10227 set possible_seeds {}
10235 proc dropcache {err} {
10236 global allcwait nextarc cachedarcs seeds
10238 #puts "dropping cache ($err)"
10239 foreach v {arcnos arcout arcids arcstart arcend growing \
10240 arctags archeads allparents allchildren} {
10251 proc writecache {f} {
10252 global cachearc cachedarcs allccache
10253 global arcstart arcend arcnos arcids arcout
10256 set lim $cachedarcs
10257 if {$lim - $a > 1000} {
10258 set lim [expr {$a + 1000}]
10261 while {[incr a] <= $lim} {
10262 if {[info exists arcend($a)]} {
10263 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10265 puts $f [list $arcstart($a) {} $arcids($a)]
10270 catch {file delete $allccache}
10271 #puts "writing cache failed ($err)"
10274 set cachearc [expr {$a - 1}]
10275 if {$a > $cachedarcs} {
10283 proc savecache {} {
10284 global nextarc cachedarcs cachearc allccache
10286 if {$nextarc == $cachedarcs} return
10288 set cachedarcs $nextarc
10290 set f [open $allccache w]
10291 puts $f [list 1 $cachedarcs]
10296 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10297 # or 0 if neither is true.
10298 proc anc_or_desc {a b} {
10299 global arcout arcstart arcend arcnos cached_isanc
10301 if {$arcnos($a) eq $arcnos($b)} {
10302 # Both are on the same arc(s); either both are the same BMP,
10303 # or if one is not a BMP, the other is also not a BMP or is
10304 # the BMP at end of the arc (and it only has 1 incoming arc).
10305 # Or both can be BMPs with no incoming arcs.
10306 if {$a eq $b || $arcnos($a) eq {}} {
10309 # assert {[llength $arcnos($a)] == 1}
10310 set arc [lindex $arcnos($a) 0]
10311 set i [lsearch -exact $arcids($arc) $a]
10312 set j [lsearch -exact $arcids($arc) $b]
10313 if {$i < 0 || $i > $j} {
10320 if {![info exists arcout($a)]} {
10321 set arc [lindex $arcnos($a) 0]
10322 if {[info exists arcend($arc)]} {
10323 set aend $arcend($arc)
10327 set a $arcstart($arc)
10331 if {![info exists arcout($b)]} {
10332 set arc [lindex $arcnos($b) 0]
10333 if {[info exists arcend($arc)]} {
10334 set bend $arcend($arc)
10338 set b $arcstart($arc)
10348 if {[info exists cached_isanc($a,$bend)]} {
10349 if {$cached_isanc($a,$bend)} {
10353 if {[info exists cached_isanc($b,$aend)]} {
10354 if {$cached_isanc($b,$aend)} {
10357 if {[info exists cached_isanc($a,$bend)]} {
10362 set todo [list $a $b]
10365 for {set i 0} {$i < [llength $todo]} {incr i} {
10366 set x [lindex $todo $i]
10367 if {$anc($x) eq {}} {
10370 foreach arc $arcnos($x) {
10371 set xd $arcstart($arc)
10372 if {$xd eq $bend} {
10373 set cached_isanc($a,$bend) 1
10374 set cached_isanc($b,$aend) 0
10376 } elseif {$xd eq $aend} {
10377 set cached_isanc($b,$aend) 1
10378 set cached_isanc($a,$bend) 0
10381 if {![info exists anc($xd)]} {
10382 set anc($xd) $anc($x)
10384 } elseif {$anc($xd) ne $anc($x)} {
10389 set cached_isanc($a,$bend) 0
10390 set cached_isanc($b,$aend) 0
10394 # This identifies whether $desc has an ancestor that is
10395 # a growing tip of the graph and which is not an ancestor of $anc
10396 # and returns 0 if so and 1 if not.
10397 # If we subsequently discover a tag on such a growing tip, and that
10398 # turns out to be a descendent of $anc (which it could, since we
10399 # don't necessarily see children before parents), then $desc
10400 # isn't a good choice to display as a descendent tag of
10401 # $anc (since it is the descendent of another tag which is
10402 # a descendent of $anc). Similarly, $anc isn't a good choice to
10403 # display as a ancestor tag of $desc.
10405 proc is_certain {desc anc} {
10406 global arcnos arcout arcstart arcend growing problems
10409 if {[llength $arcnos($anc)] == 1} {
10410 # tags on the same arc are certain
10411 if {$arcnos($desc) eq $arcnos($anc)} {
10414 if {![info exists arcout($anc)]} {
10415 # if $anc is partway along an arc, use the start of the arc instead
10416 set a [lindex $arcnos($anc) 0]
10417 set anc $arcstart($a)
10420 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10423 set a [lindex $arcnos($desc) 0]
10429 set anclist [list $x]
10433 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10434 set x [lindex $anclist $i]
10439 foreach a $arcout($x) {
10440 if {[info exists growing($a)]} {
10441 if {![info exists growanc($x)] && $dl($x)} {
10447 if {[info exists dl($y)]} {
10451 if {![info exists done($y)]} {
10454 if {[info exists growanc($x)]} {
10458 for {set k 0} {$k < [llength $xl]} {incr k} {
10459 set z [lindex $xl $k]
10460 foreach c $arcout($z) {
10461 if {[info exists arcend($c)]} {
10463 if {[info exists dl($v)] && $dl($v)} {
10465 if {![info exists done($v)]} {
10468 if {[info exists growanc($v)]} {
10478 } elseif {$y eq $anc || !$dl($x)} {
10489 foreach x [array names growanc] {
10498 proc validate_arctags {a} {
10499 global arctags idtags
10502 set na $arctags($a)
10503 foreach id $arctags($a) {
10505 if {![info exists idtags($id)]} {
10506 set na [lreplace $na $i $i]
10510 set arctags($a) $na
10513 proc validate_archeads {a} {
10514 global archeads idheads
10517 set na $archeads($a)
10518 foreach id $archeads($a) {
10520 if {![info exists idheads($id)]} {
10521 set na [lreplace $na $i $i]
10525 set archeads($a) $na
10528 # Return the list of IDs that have tags that are descendents of id,
10529 # ignoring IDs that are descendents of IDs already reported.
10530 proc desctags {id} {
10531 global arcnos arcstart arcids arctags idtags allparents
10532 global growing cached_dtags
10534 if {![info exists allparents($id)]} {
10537 set t1 [clock clicks -milliseconds]
10539 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10540 # part-way along an arc; check that arc first
10541 set a [lindex $arcnos($id) 0]
10542 if {$arctags($a) ne {}} {
10543 validate_arctags $a
10544 set i [lsearch -exact $arcids($a) $id]
10546 foreach t $arctags($a) {
10547 set j [lsearch -exact $arcids($a) $t]
10548 if {$j >= $i} break
10555 set id $arcstart($a)
10556 if {[info exists idtags($id)]} {
10560 if {[info exists cached_dtags($id)]} {
10561 return $cached_dtags($id)
10565 set todo [list $id]
10568 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10569 set id [lindex $todo $i]
10571 set ta [info exists hastaggedancestor($id)]
10575 # ignore tags on starting node
10576 if {!$ta && $i > 0} {
10577 if {[info exists idtags($id)]} {
10578 set tagloc($id) $id
10580 } elseif {[info exists cached_dtags($id)]} {
10581 set tagloc($id) $cached_dtags($id)
10585 foreach a $arcnos($id) {
10586 set d $arcstart($a)
10587 if {!$ta && $arctags($a) ne {}} {
10588 validate_arctags $a
10589 if {$arctags($a) ne {}} {
10590 lappend tagloc($id) [lindex $arctags($a) end]
10593 if {$ta || $arctags($a) ne {}} {
10594 set tomark [list $d]
10595 for {set j 0} {$j < [llength $tomark]} {incr j} {
10596 set dd [lindex $tomark $j]
10597 if {![info exists hastaggedancestor($dd)]} {
10598 if {[info exists done($dd)]} {
10599 foreach b $arcnos($dd) {
10600 lappend tomark $arcstart($b)
10602 if {[info exists tagloc($dd)]} {
10605 } elseif {[info exists queued($dd)]} {
10608 set hastaggedancestor($dd) 1
10612 if {![info exists queued($d)]} {
10615 if {![info exists hastaggedancestor($d)]} {
10622 foreach id [array names tagloc] {
10623 if {![info exists hastaggedancestor($id)]} {
10624 foreach t $tagloc($id) {
10625 if {[lsearch -exact $tags $t] < 0} {
10631 set t2 [clock clicks -milliseconds]
10634 # remove tags that are descendents of other tags
10635 for {set i 0} {$i < [llength $tags]} {incr i} {
10636 set a [lindex $tags $i]
10637 for {set j 0} {$j < $i} {incr j} {
10638 set b [lindex $tags $j]
10639 set r [anc_or_desc $a $b]
10641 set tags [lreplace $tags $j $j]
10644 } elseif {$r == -1} {
10645 set tags [lreplace $tags $i $i]
10652 if {[array names growing] ne {}} {
10653 # graph isn't finished, need to check if any tag could get
10654 # eclipsed by another tag coming later. Simply ignore any
10655 # tags that could later get eclipsed.
10658 if {[is_certain $t $origid]} {
10662 if {$tags eq $ctags} {
10663 set cached_dtags($origid) $tags
10668 set cached_dtags($origid) $tags
10670 set t3 [clock clicks -milliseconds]
10671 if {0 && $t3 - $t1 >= 100} {
10672 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10673 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10678 proc anctags {id} {
10679 global arcnos arcids arcout arcend arctags idtags allparents
10680 global growing cached_atags
10682 if {![info exists allparents($id)]} {
10685 set t1 [clock clicks -milliseconds]
10687 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10688 # part-way along an arc; check that arc first
10689 set a [lindex $arcnos($id) 0]
10690 if {$arctags($a) ne {}} {
10691 validate_arctags $a
10692 set i [lsearch -exact $arcids($a) $id]
10693 foreach t $arctags($a) {
10694 set j [lsearch -exact $arcids($a) $t]
10700 if {![info exists arcend($a)]} {
10704 if {[info exists idtags($id)]} {
10708 if {[info exists cached_atags($id)]} {
10709 return $cached_atags($id)
10713 set todo [list $id]
10717 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10718 set id [lindex $todo $i]
10720 set td [info exists hastaggeddescendent($id)]
10724 # ignore tags on starting node
10725 if {!$td && $i > 0} {
10726 if {[info exists idtags($id)]} {
10727 set tagloc($id) $id
10729 } elseif {[info exists cached_atags($id)]} {
10730 set tagloc($id) $cached_atags($id)
10734 foreach a $arcout($id) {
10735 if {!$td && $arctags($a) ne {}} {
10736 validate_arctags $a
10737 if {$arctags($a) ne {}} {
10738 lappend tagloc($id) [lindex $arctags($a) 0]
10741 if {![info exists arcend($a)]} continue
10743 if {$td || $arctags($a) ne {}} {
10744 set tomark [list $d]
10745 for {set j 0} {$j < [llength $tomark]} {incr j} {
10746 set dd [lindex $tomark $j]
10747 if {![info exists hastaggeddescendent($dd)]} {
10748 if {[info exists done($dd)]} {
10749 foreach b $arcout($dd) {
10750 if {[info exists arcend($b)]} {
10751 lappend tomark $arcend($b)
10754 if {[info exists tagloc($dd)]} {
10757 } elseif {[info exists queued($dd)]} {
10760 set hastaggeddescendent($dd) 1
10764 if {![info exists queued($d)]} {
10767 if {![info exists hastaggeddescendent($d)]} {
10773 set t2 [clock clicks -milliseconds]
10776 foreach id [array names tagloc] {
10777 if {![info exists hastaggeddescendent($id)]} {
10778 foreach t $tagloc($id) {
10779 if {[lsearch -exact $tags $t] < 0} {
10786 # remove tags that are ancestors of other tags
10787 for {set i 0} {$i < [llength $tags]} {incr i} {
10788 set a [lindex $tags $i]
10789 for {set j 0} {$j < $i} {incr j} {
10790 set b [lindex $tags $j]
10791 set r [anc_or_desc $a $b]
10793 set tags [lreplace $tags $j $j]
10796 } elseif {$r == 1} {
10797 set tags [lreplace $tags $i $i]
10804 if {[array names growing] ne {}} {
10805 # graph isn't finished, need to check if any tag could get
10806 # eclipsed by another tag coming later. Simply ignore any
10807 # tags that could later get eclipsed.
10810 if {[is_certain $origid $t]} {
10814 if {$tags eq $ctags} {
10815 set cached_atags($origid) $tags
10820 set cached_atags($origid) $tags
10822 set t3 [clock clicks -milliseconds]
10823 if {0 && $t3 - $t1 >= 100} {
10824 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10825 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10830 # Return the list of IDs that have heads that are descendents of id,
10831 # including id itself if it has a head.
10832 proc descheads {id} {
10833 global arcnos arcstart arcids archeads idheads cached_dheads
10834 global allparents arcout
10836 if {![info exists allparents($id)]} {
10840 if {![info exists arcout($id)]} {
10841 # part-way along an arc; check it first
10842 set a [lindex $arcnos($id) 0]
10843 if {$archeads($a) ne {}} {
10844 validate_archeads $a
10845 set i [lsearch -exact $arcids($a) $id]
10846 foreach t $archeads($a) {
10847 set j [lsearch -exact $arcids($a) $t]
10852 set id $arcstart($a)
10855 set todo [list $id]
10858 for {set i 0} {$i < [llength $todo]} {incr i} {
10859 set id [lindex $todo $i]
10860 if {[info exists cached_dheads($id)]} {
10861 set ret [concat $ret $cached_dheads($id)]
10863 if {[info exists idheads($id)]} {
10866 foreach a $arcnos($id) {
10867 if {$archeads($a) ne {}} {
10868 validate_archeads $a
10869 if {$archeads($a) ne {}} {
10870 set ret [concat $ret $archeads($a)]
10873 set d $arcstart($a)
10874 if {![info exists seen($d)]} {
10881 set ret [lsort -unique $ret]
10882 set cached_dheads($origid) $ret
10883 return [concat $ret $aret]
10886 proc addedtag {id} {
10887 global arcnos arcout cached_dtags cached_atags
10889 if {![info exists arcnos($id)]} return
10890 if {![info exists arcout($id)]} {
10891 recalcarc [lindex $arcnos($id) 0]
10893 catch {unset cached_dtags}
10894 catch {unset cached_atags}
10897 proc addedhead {hid head} {
10898 global arcnos arcout cached_dheads
10900 if {![info exists arcnos($hid)]} return
10901 if {![info exists arcout($hid)]} {
10902 recalcarc [lindex $arcnos($hid) 0]
10904 catch {unset cached_dheads}
10907 proc removedhead {hid head} {
10908 global cached_dheads
10910 catch {unset cached_dheads}
10913 proc movedhead {hid head} {
10914 global arcnos arcout cached_dheads
10916 if {![info exists arcnos($hid)]} return
10917 if {![info exists arcout($hid)]} {
10918 recalcarc [lindex $arcnos($hid) 0]
10920 catch {unset cached_dheads}
10923 proc changedrefs {} {
10924 global cached_dheads cached_dtags cached_atags cached_tagcontent
10925 global arctags archeads arcnos arcout idheads idtags
10927 foreach id [concat [array names idheads] [array names idtags]] {
10928 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10929 set a [lindex $arcnos($id) 0]
10930 if {![info exists donearc($a)]} {
10936 catch {unset cached_tagcontent}
10937 catch {unset cached_dtags}
10938 catch {unset cached_atags}
10939 catch {unset cached_dheads}
10942 proc rereadrefs {} {
10943 global idtags idheads idotherrefs mainheadid
10945 set refids [concat [array names idtags] \
10946 [array names idheads] [array names idotherrefs]]
10947 foreach id $refids {
10948 if {![info exists ref($id)]} {
10949 set ref($id) [listrefs $id]
10952 set oldmainhead $mainheadid
10955 set refids [lsort -unique [concat $refids [array names idtags] \
10956 [array names idheads] [array names idotherrefs]]]
10957 foreach id $refids {
10958 set v [listrefs $id]
10959 if {![info exists ref($id)] || $ref($id) != $v} {
10963 if {$oldmainhead ne $mainheadid} {
10964 redrawtags $oldmainhead
10965 redrawtags $mainheadid
10970 proc listrefs {id} {
10971 global idtags idheads idotherrefs
10974 if {[info exists idtags($id)]} {
10978 if {[info exists idheads($id)]} {
10979 set y $idheads($id)
10982 if {[info exists idotherrefs($id)]} {
10983 set z $idotherrefs($id)
10985 return [list $x $y $z]
10988 proc add_tag_ctext {tag} {
10989 global ctext cached_tagcontent tagids
10991 if {![info exists cached_tagcontent($tag)]} {
10993 set cached_tagcontent($tag) [exec git cat-file -p $tag]
10996 $ctext insert end "[mc "Tag"]: $tag\n" bold
10997 if {[info exists cached_tagcontent($tag)]} {
10998 set text $cached_tagcontent($tag)
11000 set text "[mc "Id"]: $tagids($tag)"
11002 appendwithlinks $text {}
11005 proc showtag {tag isnew} {
11006 global ctext cached_tagcontent tagids linknum tagobjid
11009 addtohistory [list showtag $tag 0] savectextpos
11011 $ctext conf -state normal
11016 maybe_scroll_ctext 1
11017 $ctext conf -state disabled
11021 proc showtags {id isnew} {
11022 global idtags ctext linknum
11025 addtohistory [list showtags $id 0] savectextpos
11027 $ctext conf -state normal
11032 foreach tag $idtags($id) {
11033 $ctext insert end $sep
11037 maybe_scroll_ctext 1
11038 $ctext conf -state disabled
11050 if {[info exists gitktmpdir]} {
11051 catch {file delete -force $gitktmpdir}
11055 proc mkfontdisp {font top which} {
11056 global fontattr fontpref $font NS use_ttk
11058 set fontpref($font) [set $font]
11059 ${NS}::button $top.${font}but -text $which \
11060 -command [list choosefont $font $which]
11061 ${NS}::label $top.$font -relief flat -font $font \
11062 -text $fontattr($font,family) -justify left
11063 grid x $top.${font}but $top.$font -sticky w
11066 proc choosefont {font which} {
11067 global fontparam fontlist fonttop fontattr
11070 set fontparam(which) $which
11071 set fontparam(font) $font
11072 set fontparam(family) [font actual $font -family]
11073 set fontparam(size) $fontattr($font,size)
11074 set fontparam(weight) $fontattr($font,weight)
11075 set fontparam(slant) $fontattr($font,slant)
11078 if {![winfo exists $top]} {
11080 eval font config sample [font actual $font]
11082 make_transient $top $prefstop
11083 wm title $top [mc "Gitk font chooser"]
11084 ${NS}::label $top.l -textvariable fontparam(which)
11085 pack $top.l -side top
11086 set fontlist [lsort [font families]]
11087 ${NS}::frame $top.f
11088 listbox $top.f.fam -listvariable fontlist \
11089 -yscrollcommand [list $top.f.sb set]
11090 bind $top.f.fam <<ListboxSelect>> selfontfam
11091 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11092 pack $top.f.sb -side right -fill y
11093 pack $top.f.fam -side left -fill both -expand 1
11094 pack $top.f -side top -fill both -expand 1
11095 ${NS}::frame $top.g
11096 spinbox $top.g.size -from 4 -to 40 -width 4 \
11097 -textvariable fontparam(size) \
11098 -validatecommand {string is integer -strict %s}
11099 checkbutton $top.g.bold -padx 5 \
11100 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11101 -variable fontparam(weight) -onvalue bold -offvalue normal
11102 checkbutton $top.g.ital -padx 5 \
11103 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11104 -variable fontparam(slant) -onvalue italic -offvalue roman
11105 pack $top.g.size $top.g.bold $top.g.ital -side left
11106 pack $top.g -side top
11107 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11109 $top.c create text 100 25 -anchor center -text $which -font sample \
11110 -fill black -tags text
11111 bind $top.c <Configure> [list centertext $top.c]
11112 pack $top.c -side top -fill x
11113 ${NS}::frame $top.buts
11114 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11115 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11116 bind $top <Key-Return> fontok
11117 bind $top <Key-Escape> fontcan
11118 grid $top.buts.ok $top.buts.can
11119 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11120 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11121 pack $top.buts -side bottom -fill x
11122 trace add variable fontparam write chg_fontparam
11125 $top.c itemconf text -text $which
11127 set i [lsearch -exact $fontlist $fontparam(family)]
11129 $top.f.fam selection set $i
11134 proc centertext {w} {
11135 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11139 global fontparam fontpref prefstop
11141 set f $fontparam(font)
11142 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11143 if {$fontparam(weight) eq "bold"} {
11144 lappend fontpref($f) "bold"
11146 if {$fontparam(slant) eq "italic"} {
11147 lappend fontpref($f) "italic"
11149 set w $prefstop.notebook.fonts.$f
11150 $w conf -text $fontparam(family) -font $fontpref($f)
11156 global fonttop fontparam
11158 if {[info exists fonttop]} {
11159 catch {destroy $fonttop}
11160 catch {font delete sample}
11166 if {[package vsatisfies [package provide Tk] 8.6]} {
11167 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11168 # function to make use of it.
11169 proc choosefont {font which} {
11170 tk fontchooser configure -title $which -font $font \
11171 -command [list on_choosefont $font $which]
11172 tk fontchooser show
11174 proc on_choosefont {font which newfont} {
11176 puts stderr "$font $newfont"
11177 array set f [font actual $newfont]
11178 set fontparam(which) $which
11179 set fontparam(font) $font
11180 set fontparam(family) $f(-family)
11181 set fontparam(size) $f(-size)
11182 set fontparam(weight) $f(-weight)
11183 set fontparam(slant) $f(-slant)
11188 proc selfontfam {} {
11189 global fonttop fontparam
11191 set i [$fonttop.f.fam curselection]
11193 set fontparam(family) [$fonttop.f.fam get $i]
11197 proc chg_fontparam {v sub op} {
11200 font config sample -$sub $fontparam($sub)
11203 # Create a property sheet tab page
11204 proc create_prefs_page {w} {
11206 set parent [join [lrange [split $w .] 0 end-1] .]
11207 if {[winfo class $parent] eq "TNotebook"} {
11210 ${NS}::labelframe $w
11214 proc prefspage_general {notebook} {
11215 global NS maxwidth maxgraphpct showneartags showlocalchanges
11216 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11217 global hideremotes want_ttk have_ttk maxrefs
11219 set page [create_prefs_page $notebook.general]
11221 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11222 grid $page.ldisp - -sticky w -pady 10
11223 ${NS}::label $page.spacer -text " "
11224 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11225 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11226 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11227 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11228 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11229 grid x $page.maxpctl $page.maxpct -sticky w
11230 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11231 -variable showlocalchanges
11232 grid x $page.showlocal -sticky w
11233 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11234 -variable autoselect
11235 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11236 grid x $page.autoselect $page.autosellen -sticky w
11237 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11238 -variable hideremotes
11239 grid x $page.hideremotes -sticky w
11241 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11242 grid $page.ddisp - -sticky w -pady 10
11243 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11244 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11245 grid x $page.tabstopl $page.tabstop -sticky w
11246 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11247 -variable showneartags
11248 grid x $page.ntag -sticky w
11249 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11250 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11251 grid x $page.maxrefsl $page.maxrefs -sticky w
11252 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11253 -variable limitdiffs
11254 grid x $page.ldiff -sticky w
11255 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11256 -variable perfile_attrs
11257 grid x $page.lattr -sticky w
11259 ${NS}::entry $page.extdifft -textvariable extdifftool
11260 ${NS}::frame $page.extdifff
11261 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11262 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11263 pack $page.extdifff.l $page.extdifff.b -side left
11264 pack configure $page.extdifff.l -padx 10
11265 grid x $page.extdifff $page.extdifft -sticky ew
11267 ${NS}::label $page.lgen -text [mc "General options"]
11268 grid $page.lgen - -sticky w -pady 10
11269 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11270 -text [mc "Use themed widgets"]
11272 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11274 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11276 grid x $page.want_ttk $page.ttk_note -sticky w
11280 proc prefspage_colors {notebook} {
11281 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11283 set page [create_prefs_page $notebook.colors]
11285 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11286 grid $page.cdisp - -sticky w -pady 10
11287 label $page.ui -padx 40 -relief sunk -background $uicolor
11288 ${NS}::button $page.uibut -text [mc "Interface"] \
11289 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11290 grid x $page.uibut $page.ui -sticky w
11291 label $page.bg -padx 40 -relief sunk -background $bgcolor
11292 ${NS}::button $page.bgbut -text [mc "Background"] \
11293 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11294 grid x $page.bgbut $page.bg -sticky w
11295 label $page.fg -padx 40 -relief sunk -background $fgcolor
11296 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11297 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11298 grid x $page.fgbut $page.fg -sticky w
11299 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11300 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11301 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11302 [list $ctext tag conf d0 -foreground]]
11303 grid x $page.diffoldbut $page.diffold -sticky w
11304 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11305 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11306 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11307 [list $ctext tag conf dresult -foreground]]
11308 grid x $page.diffnewbut $page.diffnew -sticky w
11309 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11310 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11311 -command [list choosecolor diffcolors 2 $page.hunksep \
11312 [mc "diff hunk header"] \
11313 [list $ctext tag conf hunksep -foreground]]
11314 grid x $page.hunksepbut $page.hunksep -sticky w
11315 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11316 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11317 -command [list choosecolor markbgcolor {} $page.markbgsep \
11318 [mc "marked line background"] \
11319 [list $ctext tag conf omark -background]]
11320 grid x $page.markbgbut $page.markbgsep -sticky w
11321 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11322 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11323 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11324 grid x $page.selbgbut $page.selbgsep -sticky w
11328 proc prefspage_fonts {notebook} {
11330 set page [create_prefs_page $notebook.fonts]
11331 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11332 grid $page.cfont - -sticky w -pady 10
11333 mkfontdisp mainfont $page [mc "Main font"]
11334 mkfontdisp textfont $page [mc "Diff display font"]
11335 mkfontdisp uifont $page [mc "User interface font"]
11340 global maxwidth maxgraphpct use_ttk NS
11341 global oldprefs prefstop showneartags showlocalchanges
11342 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11343 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11344 global hideremotes want_ttk have_ttk
11348 if {[winfo exists $top]} {
11352 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11353 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11354 set oldprefs($v) [set $v]
11357 wm title $top [mc "Gitk preferences"]
11358 make_transient $top .
11360 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11361 set notebook [ttk::notebook $top.notebook]
11363 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11366 lappend pages [prefspage_general $notebook] [mc "General"]
11367 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11368 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11370 foreach {page title} $pages {
11371 if {$use_notebook} {
11372 $notebook add $page -text $title
11374 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11375 -text $title -command [list raise $page]]
11376 $page configure -text $title
11377 grid $btn -row 0 -column [incr col] -sticky w
11378 grid $page -row 1 -column 0 -sticky news -columnspan 100
11382 if {!$use_notebook} {
11383 grid columnconfigure $notebook 0 -weight 1
11384 grid rowconfigure $notebook 1 -weight 1
11385 raise [lindex $pages 0]
11388 grid $notebook -sticky news -padx 2 -pady 2
11389 grid rowconfigure $top 0 -weight 1
11390 grid columnconfigure $top 0 -weight 1
11392 ${NS}::frame $top.buts
11393 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11394 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11395 bind $top <Key-Return> prefsok
11396 bind $top <Key-Escape> prefscan
11397 grid $top.buts.ok $top.buts.can
11398 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11399 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11400 grid $top.buts - - -pady 10 -sticky ew
11401 grid columnconfigure $top 2 -weight 1
11402 bind $top <Visibility> [list focus $top.buts.ok]
11405 proc choose_extdiff {} {
11408 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11410 set extdifftool $prog
11414 proc choosecolor {v vi w x cmd} {
11417 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11418 -title [mc "Gitk: choose color for %s" $x]]
11419 if {$c eq {}} return
11420 $w conf -background $c
11425 proc setselbg {c} {
11426 global bglist cflist
11427 foreach w $bglist {
11428 $w configure -selectbackground $c
11430 $cflist tag configure highlight \
11431 -background [$cflist cget -selectbackground]
11432 allcanvs itemconf secsel -fill $c
11435 # This sets the background color and the color scheme for the whole UI.
11436 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11437 # if we don't specify one ourselves, which makes the checkbuttons and
11438 # radiobuttons look bad. This chooses white for selectColor if the
11439 # background color is light, or black if it is dark.
11441 if {[tk windowingsystem] eq "win32"} { return }
11442 set bg [winfo rgb . $c]
11444 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11447 tk_setPalette background $c selectColor $selc
11453 foreach w $bglist {
11454 $w conf -background $c
11461 foreach w $fglist {
11462 $w conf -foreground $c
11464 allcanvs itemconf text -fill $c
11465 $canv itemconf circle -outline $c
11466 $canv itemconf markid -outline $c
11470 global oldprefs prefstop
11472 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11473 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11475 set $v $oldprefs($v)
11477 catch {destroy $prefstop}
11483 global maxwidth maxgraphpct
11484 global oldprefs prefstop showneartags showlocalchanges
11485 global fontpref mainfont textfont uifont
11486 global limitdiffs treediffs perfile_attrs
11489 catch {destroy $prefstop}
11493 if {$mainfont ne $fontpref(mainfont)} {
11494 set mainfont $fontpref(mainfont)
11495 parsefont mainfont $mainfont
11496 eval font configure mainfont [fontflags mainfont]
11497 eval font configure mainfontbold [fontflags mainfont 1]
11501 if {$textfont ne $fontpref(textfont)} {
11502 set textfont $fontpref(textfont)
11503 parsefont textfont $textfont
11504 eval font configure textfont [fontflags textfont]
11505 eval font configure textfontbold [fontflags textfont 1]
11507 if {$uifont ne $fontpref(uifont)} {
11508 set uifont $fontpref(uifont)
11509 parsefont uifont $uifont
11510 eval font configure uifont [fontflags uifont]
11513 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11514 if {$showlocalchanges} {
11520 if {$limitdiffs != $oldprefs(limitdiffs) ||
11521 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11522 # treediffs elements are limited by path;
11523 # won't have encodings cached if perfile_attrs was just turned on
11524 catch {unset treediffs}
11526 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11527 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11529 } elseif {$showneartags != $oldprefs(showneartags) ||
11530 $limitdiffs != $oldprefs(limitdiffs)} {
11533 if {$hideremotes != $oldprefs(hideremotes)} {
11538 proc formatdate {d} {
11539 global datetimeformat
11541 set d [clock format [lindex $d 0] -format $datetimeformat]
11546 # This list of encoding names and aliases is distilled from
11547 # http://www.iana.org/assignments/character-sets.
11548 # Not all of them are supported by Tcl.
11549 set encoding_aliases {
11550 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11551 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11552 { ISO-10646-UTF-1 csISO10646UTF1 }
11553 { ISO_646.basic:1983 ref csISO646basic1983 }
11554 { INVARIANT csINVARIANT }
11555 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11556 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11557 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11558 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11559 { NATS-DANO iso-ir-9-1 csNATSDANO }
11560 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11561 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11562 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11563 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11564 { ISO-2022-KR csISO2022KR }
11566 { ISO-2022-JP csISO2022JP }
11567 { ISO-2022-JP-2 csISO2022JP2 }
11568 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11569 csISO13JISC6220jp }
11570 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11571 { IT iso-ir-15 ISO646-IT csISO15Italian }
11572 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11573 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11574 { greek7-old iso-ir-18 csISO18Greek7Old }
11575 { latin-greek iso-ir-19 csISO19LatinGreek }
11576 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11577 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11578 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11579 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11580 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11581 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11582 { INIS iso-ir-49 csISO49INIS }
11583 { INIS-8 iso-ir-50 csISO50INIS8 }
11584 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11585 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11586 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11587 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11588 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11589 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11590 csISO60Norwegian1 }
11591 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11592 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11593 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11594 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11595 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11596 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11597 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11598 { greek7 iso-ir-88 csISO88Greek7 }
11599 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11600 { iso-ir-90 csISO90 }
11601 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11602 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11603 csISO92JISC62991984b }
11604 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11605 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11606 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11607 csISO95JIS62291984handadd }
11608 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11609 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11610 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11611 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11612 CP819 csISOLatin1 }
11613 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11614 { T.61-7bit iso-ir-102 csISO102T617bit }
11615 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11616 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11617 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11618 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11619 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11620 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11621 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11622 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11623 arabic csISOLatinArabic }
11624 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11625 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11626 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11627 greek greek8 csISOLatinGreek }
11628 { T.101-G2 iso-ir-128 csISO128T101G2 }
11629 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11631 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11632 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11633 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11634 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11635 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11636 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11637 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11638 csISOLatinCyrillic }
11639 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11640 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11641 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11642 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11643 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11644 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11645 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11646 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11647 { ISO_10367-box iso-ir-155 csISO10367Box }
11648 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11649 { latin-lap lap iso-ir-158 csISO158Lap }
11650 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11651 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11654 { JIS_X0201 X0201 csHalfWidthKatakana }
11655 { KSC5636 ISO646-KR csKSC5636 }
11656 { ISO-10646-UCS-2 csUnicode }
11657 { ISO-10646-UCS-4 csUCS4 }
11658 { DEC-MCS dec csDECMCS }
11659 { hp-roman8 roman8 r8 csHPRoman8 }
11660 { macintosh mac csMacintosh }
11661 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11663 { IBM038 EBCDIC-INT cp038 csIBM038 }
11664 { IBM273 CP273 csIBM273 }
11665 { IBM274 EBCDIC-BE CP274 csIBM274 }
11666 { IBM275 EBCDIC-BR cp275 csIBM275 }
11667 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11668 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11669 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11670 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11671 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11672 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11673 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11674 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11675 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11676 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11677 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11678 { IBM437 cp437 437 csPC8CodePage437 }
11679 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11680 { IBM775 cp775 csPC775Baltic }
11681 { IBM850 cp850 850 csPC850Multilingual }
11682 { IBM851 cp851 851 csIBM851 }
11683 { IBM852 cp852 852 csPCp852 }
11684 { IBM855 cp855 855 csIBM855 }
11685 { IBM857 cp857 857 csIBM857 }
11686 { IBM860 cp860 860 csIBM860 }
11687 { IBM861 cp861 861 cp-is csIBM861 }
11688 { IBM862 cp862 862 csPC862LatinHebrew }
11689 { IBM863 cp863 863 csIBM863 }
11690 { IBM864 cp864 csIBM864 }
11691 { IBM865 cp865 865 csIBM865 }
11692 { IBM866 cp866 866 csIBM866 }
11693 { IBM868 CP868 cp-ar csIBM868 }
11694 { IBM869 cp869 869 cp-gr csIBM869 }
11695 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11696 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11697 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11698 { IBM891 cp891 csIBM891 }
11699 { IBM903 cp903 csIBM903 }
11700 { IBM904 cp904 904 csIBBM904 }
11701 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11702 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11703 { IBM1026 CP1026 csIBM1026 }
11704 { EBCDIC-AT-DE csIBMEBCDICATDE }
11705 { EBCDIC-AT-DE-A csEBCDICATDEA }
11706 { EBCDIC-CA-FR csEBCDICCAFR }
11707 { EBCDIC-DK-NO csEBCDICDKNO }
11708 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11709 { EBCDIC-FI-SE csEBCDICFISE }
11710 { EBCDIC-FI-SE-A csEBCDICFISEA }
11711 { EBCDIC-FR csEBCDICFR }
11712 { EBCDIC-IT csEBCDICIT }
11713 { EBCDIC-PT csEBCDICPT }
11714 { EBCDIC-ES csEBCDICES }
11715 { EBCDIC-ES-A csEBCDICESA }
11716 { EBCDIC-ES-S csEBCDICESS }
11717 { EBCDIC-UK csEBCDICUK }
11718 { EBCDIC-US csEBCDICUS }
11719 { UNKNOWN-8BIT csUnknown8BiT }
11720 { MNEMONIC csMnemonic }
11722 { VISCII csVISCII }
11725 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11726 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11727 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11728 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11729 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11730 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11731 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11732 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11733 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11734 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11735 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11736 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11737 { IBM1047 IBM-1047 }
11738 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11739 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11740 { UNICODE-1-1 csUnicode11 }
11741 { CESU-8 csCESU-8 }
11742 { BOCU-1 csBOCU-1 }
11743 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11744 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11746 { ISO-8859-15 ISO_8859-15 Latin-9 }
11747 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11748 { GBK CP936 MS936 windows-936 }
11749 { JIS_Encoding csJISEncoding }
11750 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11751 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11753 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11754 { ISO-10646-UCS-Basic csUnicodeASCII }
11755 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11756 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11757 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11758 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11759 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11760 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11761 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11762 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11763 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11764 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11765 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11766 { Ventura-US csVenturaUS }
11767 { Ventura-International csVenturaInternational }
11768 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11769 { PC8-Turkish csPC8Turkish }
11770 { IBM-Symbols csIBMSymbols }
11771 { IBM-Thai csIBMThai }
11772 { HP-Legal csHPLegal }
11773 { HP-Pi-font csHPPiFont }
11774 { HP-Math8 csHPMath8 }
11775 { Adobe-Symbol-Encoding csHPPSMath }
11776 { HP-DeskTop csHPDesktop }
11777 { Ventura-Math csVenturaMath }
11778 { Microsoft-Publishing csMicrosoftPublishing }
11779 { Windows-31J csWindows31J }
11780 { GB2312 csGB2312 }
11784 proc tcl_encoding {enc} {
11785 global encoding_aliases tcl_encoding_cache
11786 if {[info exists tcl_encoding_cache($enc)]} {
11787 return $tcl_encoding_cache($enc)
11789 set names [encoding names]
11790 set lcnames [string tolower $names]
11791 set enc [string tolower $enc]
11792 set i [lsearch -exact $lcnames $enc]
11794 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11795 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11796 set i [lsearch -exact $lcnames $encx]
11800 foreach l $encoding_aliases {
11801 set ll [string tolower $l]
11802 if {[lsearch -exact $ll $enc] < 0} continue
11803 # look through the aliases for one that tcl knows about
11805 set i [lsearch -exact $lcnames $e]
11807 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11808 set i [lsearch -exact $lcnames $ex]
11818 set tclenc [lindex $names $i]
11820 set tcl_encoding_cache($enc) $tclenc
11824 proc gitattr {path attr default} {
11825 global path_attr_cache
11826 if {[info exists path_attr_cache($attr,$path)]} {
11827 set r $path_attr_cache($attr,$path)
11829 set r "unspecified"
11830 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11831 regexp "(.*): $attr: (.*)" $line m f r
11833 set path_attr_cache($attr,$path) $r
11835 if {$r eq "unspecified"} {
11841 proc cache_gitattr {attr pathlist} {
11842 global path_attr_cache
11844 foreach path $pathlist {
11845 if {![info exists path_attr_cache($attr,$path)]} {
11846 lappend newlist $path
11850 if {[tk windowingsystem] == "win32"} {
11851 # windows has a 32k limit on the arguments to a command...
11854 while {$newlist ne {}} {
11855 set head [lrange $newlist 0 [expr {$lim - 1}]]
11856 set newlist [lrange $newlist $lim end]
11857 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11858 foreach row [split $rlist "\n"] {
11859 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11860 if {[string index $path 0] eq "\""} {
11861 set path [encoding convertfrom [lindex $path 0]]
11863 set path_attr_cache($attr,$path) $value
11870 proc get_path_encoding {path} {
11871 global gui_encoding perfile_attrs
11872 set tcl_enc $gui_encoding
11873 if {$path ne {} && $perfile_attrs} {
11874 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11882 # First check that Tcl/Tk is recent enough
11883 if {[catch {package require Tk 8.4} err]} {
11884 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11885 Gitk requires at least Tcl/Tk 8.4." list
11889 # on OSX bring the current Wish process window to front
11890 if {[tk windowingsystem] eq "aqua"} {
11891 exec osascript -e [format {
11892 tell application "System Events"
11893 set frontmost of processes whose unix id is %d to true
11898 # Unset GIT_TRACE var if set
11899 if { [info exists ::env(GIT_TRACE)] } {
11900 unset ::env(GIT_TRACE)
11904 set wrcomcmd "git diff-tree --stdin -p --pretty"
11908 set gitencoding [exec git config --get i18n.commitencoding]
11911 set gitencoding [exec git config --get i18n.logoutputencoding]
11913 if {$gitencoding == ""} {
11914 set gitencoding "utf-8"
11916 set tclencoding [tcl_encoding $gitencoding]
11917 if {$tclencoding == {}} {
11918 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11921 set gui_encoding [encoding system]
11923 set enc [exec git config --get gui.encoding]
11925 set tclenc [tcl_encoding $enc]
11926 if {$tclenc ne {}} {
11927 set gui_encoding $tclenc
11929 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11934 set log_showroot true
11936 set log_showroot [exec git config --bool --get log.showroot]
11939 if {[tk windowingsystem] eq "aqua"} {
11940 set mainfont {{Lucida Grande} 9}
11941 set textfont {Monaco 9}
11942 set uifont {{Lucida Grande} 9 bold}
11943 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11945 set mainfont {sans 9}
11946 set textfont {monospace 9}
11947 set uifont {sans 9 bold}
11949 set mainfont {Helvetica 9}
11950 set textfont {Courier 9}
11951 set uifont {Helvetica 9 bold}
11954 set findmergefiles 0
11962 set cmitmode "patch"
11963 set wrapcomment "none"
11968 set showlocalchanges 1
11970 set datetimeformat "%Y-%m-%d %H:%M:%S"
11973 set perfile_attrs 0
11976 if {[tk windowingsystem] eq "aqua"} {
11977 set extdifftool "opendiff"
11979 set extdifftool "meld"
11982 set colors {green red blue magenta darkgrey brown orange}
11983 if {[tk windowingsystem] eq "win32"} {
11984 set uicolor SystemButtonFace
11985 set uifgcolor SystemButtonText
11986 set uifgdisabledcolor SystemDisabledText
11987 set bgcolor SystemWindow
11988 set fgcolor SystemWindowText
11989 set selectbgcolor SystemHighlight
11992 set uifgcolor black
11993 set uifgdisabledcolor "#999"
11996 set selectbgcolor gray85
11998 set diffcolors {red "#00a000" blue}
12000 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12003 set markbgcolor "#e0e0ff"
12005 set headbgcolor green
12006 set headfgcolor black
12007 set headoutlinecolor black
12008 set remotebgcolor #ffddaa
12009 set tagbgcolor yellow
12010 set tagfgcolor black
12011 set tagoutlinecolor black
12012 set reflinecolor black
12013 set filesepbgcolor #aaaaaa
12014 set filesepfgcolor black
12015 set linehoverbgcolor #ffff80
12016 set linehoverfgcolor black
12017 set linehoveroutlinecolor black
12018 set mainheadcirclecolor yellow
12019 set workingfilescirclecolor red
12020 set indexcirclecolor green
12021 set circlecolors {white blue gray blue blue}
12022 set linkfgcolor blue
12023 set circleoutlinecolor $fgcolor
12024 set foundbgcolor yellow
12025 set currentsearchhitbgcolor orange
12027 # button for popping up context menus
12028 if {[tk windowingsystem] eq "aqua"} {
12029 set ctxbut <Button-2>
12031 set ctxbut <Button-3>
12034 ## For msgcat loading, first locate the installation location.
12035 if { [info exists ::env(GITK_MSGSDIR)] } {
12036 ## Msgsdir was manually set in the environment.
12037 set gitk_msgsdir $::env(GITK_MSGSDIR)
12039 ## Let's guess the prefix from argv0.
12040 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12041 set gitk_libdir [file join $gitk_prefix share gitk lib]
12042 set gitk_msgsdir [file join $gitk_libdir msgs]
12046 ## Internationalization (i18n) through msgcat and gettext. See
12047 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12048 package require msgcat
12049 namespace import ::msgcat::mc
12050 ## And eventually load the actual message catalog
12051 ::msgcat::mcload $gitk_msgsdir
12053 catch {source ~/.gitk}
12055 parsefont mainfont $mainfont
12056 eval font create mainfont [fontflags mainfont]
12057 eval font create mainfontbold [fontflags mainfont 1]
12059 parsefont textfont $textfont
12060 eval font create textfont [fontflags textfont]
12061 eval font create textfontbold [fontflags textfont 1]
12063 parsefont uifont $uifont
12064 eval font create uifont [fontflags uifont]
12070 # check that we can find a .git directory somewhere...
12071 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12072 show_error {} . [mc "Cannot find a git repository here."]
12077 set selectheadid {}
12080 set cmdline_files {}
12082 set revtreeargscmd {}
12083 foreach arg $argv {
12084 switch -glob -- $arg {
12087 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12090 "--select-commit=*" {
12091 set selecthead [string range $arg 16 end]
12094 set revtreeargscmd [string range $arg 10 end]
12097 lappend revtreeargs $arg
12103 if {$selecthead eq "HEAD"} {
12107 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12108 # no -- on command line, but some arguments (other than --argscmd)
12110 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12111 set cmdline_files [split $f "\n"]
12112 set n [llength $cmdline_files]
12113 set revtreeargs [lrange $revtreeargs 0 end-$n]
12114 # Unfortunately git rev-parse doesn't produce an error when
12115 # something is both a revision and a filename. To be consistent
12116 # with git log and git rev-list, check revtreeargs for filenames.
12117 foreach arg $revtreeargs {
12118 if {[file exists $arg]} {
12119 show_error {} . [mc "Ambiguous argument '%s': both revision\
12120 and filename" $arg]
12125 # unfortunately we get both stdout and stderr in $err,
12126 # so look for "fatal:".
12127 set i [string first "fatal:" $err]
12129 set err [string range $err [expr {$i + 6}] end]
12131 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12136 set nullid "0000000000000000000000000000000000000000"
12137 set nullid2 "0000000000000000000000000000000000000001"
12138 set nullfile "/dev/null"
12140 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12141 if {![info exists have_ttk]} {
12142 set have_ttk [llength [info commands ::ttk::style]]
12144 set use_ttk [expr {$have_ttk && $want_ttk}]
12145 set NS [expr {$use_ttk ? "ttk" : ""}]
12147 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12150 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12151 set show_notes "--show-notes"
12161 set highlight_paths {}
12163 set searchdirn -forwards
12166 set diffelide {0 0}
12167 set markingmatches 0
12168 set linkentercount 0
12169 set need_redisplay 0
12176 set selectedhlview [mc "None"]
12177 set highlight_related [mc "None"]
12178 set highlight_files {}
12179 set viewfiles(0) {}
12182 set viewargscmd(0) {}
12184 set selectedline {}
12192 set hasworktree [hasworktree]
12194 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12195 set cdup [exec git rev-parse --show-cdup]
12197 set worktree [exec git rev-parse --show-toplevel]
12201 image create photo gitlogo -width 16 -height 16
12203 image create photo gitlogominus -width 4 -height 2
12204 gitlogominus put #C00000 -to 0 0 4 2
12205 gitlogo copy gitlogominus -to 1 5
12206 gitlogo copy gitlogominus -to 6 5
12207 gitlogo copy gitlogominus -to 11 5
12208 image delete gitlogominus
12210 image create photo gitlogoplus -width 4 -height 4
12211 gitlogoplus put #008000 -to 1 0 3 4
12212 gitlogoplus put #008000 -to 0 1 4 3
12213 gitlogo copy gitlogoplus -to 1 9
12214 gitlogo copy gitlogoplus -to 6 9
12215 gitlogo copy gitlogoplus -to 11 9
12216 image delete gitlogoplus
12218 image create photo gitlogo32 -width 32 -height 32
12219 gitlogo32 copy gitlogo -zoom 2 2
12221 wm iconphoto . -default gitlogo gitlogo32
12223 # wait for the window to become visible
12224 tkwait visibility .
12225 wm title . "$appname: [reponame]"
12229 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12230 # create a view for the files/dirs specified on the command line
12234 set viewname(1) [mc "Command line"]
12235 set viewfiles(1) $cmdline_files
12236 set viewargs(1) $revtreeargs
12237 set viewargscmd(1) $revtreeargscmd
12241 .bar.view entryconf [mca "Edit view..."] -state normal
12242 .bar.view entryconf [mca "Delete view"] -state normal
12245 if {[info exists permviews]} {
12246 foreach v $permviews {
12249 set viewname($n) [lindex $v 0]
12250 set viewfiles($n) [lindex $v 1]
12251 set viewargs($n) [lindex $v 2]
12252 set viewargscmd($n) [lindex $v 3]
12258 if {[tk windowingsystem] eq "win32"} {
12266 # indent-tabs-mode: t