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
159 global worddiff git_version
167 set origargs $arglist
171 foreach arg $arglist {
178 switch -glob -- $arg {
182 # remove from origargs in case we hit an unknown option
183 set origargs [lreplace $origargs $i $i]
187 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
188 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
189 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
190 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
191 "--ignore-space-change" - "-U*" - "--unified=*" {
192 # These request or affect diff output, which we don't want.
193 # Some could be used to set our defaults for diff display.
194 lappend diffargs
$arg
196 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
197 "--name-only" - "--name-status" - "--color" -
198 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
199 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
200 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
201 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
202 "--objects" - "--objects-edge" - "--reverse" {
203 # These cause our parsing of git log's output to fail, or else
204 # they're options we want to set ourselves, so ignore them.
206 "--color-words*" - "--word-diff=color" {
207 # These trigger a word diff in the console interface,
208 # so help the user by enabling our own support
209 if {[package vcompare
$git_version "1.7.2"] >= 0} {
210 set worddiff
[mc
"Color words"]
214 if {[package vcompare
$git_version "1.7.2"] >= 0} {
215 set worddiff
[mc
"Markup words"]
218 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
219 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
220 "--full-history" - "--dense" - "--sparse" -
221 "--follow" - "--left-right" - "--encoding=*" {
222 # These are harmless, and some are even useful
225 "--diff-filter=*" - "--no-merges" - "--unpacked" -
226 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
227 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
228 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
229 "--remove-empty" - "--first-parent" - "--cherry-pick" -
230 "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
231 "--simplify-by-decoration" {
232 # These mean that we get a subset of the commits
237 # This appears to be the only one that has a value as a
238 # separate word following it
248 # git rev-parse doesn't understand --merge
249 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
251 "--no-replace-objects" {
252 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
255 # Other flag arguments including -<n>
256 if {[string is digit
-strict [string range
$arg 1 end
]]} {
259 # a flag argument that we don't recognize;
260 # that means we can't optimize
266 # Non-flag arguments specify commits or ranges of commits
267 if {[string match
"*...*" $arg]} {
268 lappend revargs
--gitk-symmetric-diff-marker
274 set vdflags
($n) $diffargs
275 set vflags
($n) $glflags
276 set vrevs
($n) $revargs
277 set vfiltered
($n) $filtered
278 set vorigargs
($n) $origargs
282 proc parseviewrevs
{view revs
} {
283 global vposids vnegids
288 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
289 # we get stdout followed by stderr in $err
290 # for an unknown rev, git rev-parse echoes it and then errors out
291 set errlines
[split $err "\n"]
293 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
294 set line
[lindex
$errlines $l]
295 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
296 if {[string match
"fatal:*" $line]} {
297 if {[string match
"fatal: ambiguous argument*" $line]
299 if {[llength
$badrev] == 1} {
300 set err
"unknown revision $badrev"
302 set err
"unknown revisions: [join $badrev ", "]"
305 set err
[join [lrange
$errlines $l end
] "\n"]
312 error_popup
"[mc "Error parsing revisions
:"] $err"
319 foreach id
[split $ids "\n"] {
320 if {$id eq
"--gitk-symmetric-diff-marker"} {
322 } elseif
{[string match
"^*" $id]} {
329 lappend neg
[string range
$id 1 end
]
334 lset ret end
$id...
[lindex
$ret end
]
340 set vposids
($view) $pos
341 set vnegids
($view) $neg
345 # Start off a git log process and arrange to read its output
346 proc start_rev_list
{view
} {
347 global startmsecs commitidx viewcomplete curview
349 global viewargs viewargscmd viewfiles vfilelimit
350 global showlocalchanges
351 global viewactive viewinstances vmergeonly
352 global mainheadid viewmainheadid viewmainheadid_orig
353 global vcanopt vflags vrevs vorigargs
356 set startmsecs
[clock clicks
-milliseconds]
357 set commitidx
($view) 0
358 # these are set this way for the error exits
359 set viewcomplete
($view) 1
360 set viewactive
($view) 0
363 set args
$viewargs($view)
364 if {$viewargscmd($view) ne
{}} {
366 set str
[exec sh
-c $viewargscmd($view)]
368 error_popup
"[mc "Error executing
--argscmd command:"] $err"
371 set args
[concat
$args [split $str "\n"]]
373 set vcanopt
($view) [parseviewargs
$view $args]
375 set files
$viewfiles($view)
376 if {$vmergeonly($view)} {
377 set files
[unmerged_files
$files]
380 if {$nr_unmerged == 0} {
381 error_popup
[mc
"No files selected: --merge specified but\
382 no files are unmerged."]
384 error_popup
[mc
"No files selected: --merge specified but\
385 no unmerged files are within file limit."]
390 set vfilelimit
($view) $files
392 if {$vcanopt($view)} {
393 set revs
[parseviewrevs
$view $vrevs($view)]
397 set args
[concat
$vflags($view) $revs]
399 set args
$vorigargs($view)
403 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
404 --parents --boundary $args "--" $files] r
]
406 error_popup
"[mc "Error executing git log
:"] $err"
409 set i
[reg_instance
$fd]
410 set viewinstances
($view) [list
$i]
411 set viewmainheadid
($view) $mainheadid
412 set viewmainheadid_orig
($view) $mainheadid
413 if {$files ne
{} && $mainheadid ne
{}} {
414 get_viewmainhead
$view
416 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
417 interestedin
$viewmainheadid($view) dodiffindex
419 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
420 if {$tclencoding != {}} {
421 fconfigure
$fd -encoding $tclencoding
423 filerun
$fd [list getcommitlines
$fd $i $view 0]
424 nowbusy
$view [mc
"Reading"]
425 set viewcomplete
($view) 0
426 set viewactive
($view) 1
430 proc stop_instance
{inst
} {
431 global commfd leftover
433 set fd
$commfd($inst)
437 if {$
::tcl_platform
(platform
) eq
{windows
}} {
446 unset leftover
($inst)
449 proc stop_backends
{} {
452 foreach inst
[array names commfd
] {
457 proc stop_rev_list
{view
} {
460 foreach inst
$viewinstances($view) {
463 set viewinstances
($view) {}
466 proc reset_pending_select
{selid
} {
467 global pending_select mainheadid selectheadid
470 set pending_select
$selid
471 } elseif
{$selectheadid ne
{}} {
472 set pending_select
$selectheadid
474 set pending_select
$mainheadid
478 proc getcommits
{selid
} {
479 global canv curview need_redisplay viewactive
482 if {[start_rev_list
$curview]} {
483 reset_pending_select
$selid
484 show_status
[mc
"Reading commits..."]
487 show_status
[mc
"No commits selected"]
491 proc updatecommits
{} {
492 global curview vcanopt vorigargs vfilelimit viewinstances
493 global viewactive viewcomplete tclencoding
494 global startmsecs showneartags showlocalchanges
495 global mainheadid viewmainheadid viewmainheadid_orig pending_select
497 global varcid vposids vnegids vflags vrevs
500 set hasworktree
[hasworktree
]
503 if {$mainheadid ne
$viewmainheadid_orig($view)} {
504 if {$showlocalchanges} {
507 set viewmainheadid
($view) $mainheadid
508 set viewmainheadid_orig
($view) $mainheadid
509 if {$vfilelimit($view) ne
{}} {
510 get_viewmainhead
$view
513 if {$showlocalchanges} {
516 if {$vcanopt($view)} {
517 set oldpos
$vposids($view)
518 set oldneg
$vnegids($view)
519 set revs
[parseviewrevs
$view $vrevs($view)]
523 # note: getting the delta when negative refs change is hard,
524 # and could require multiple git log invocations, so in that
525 # case we ask git log for all the commits (not just the delta)
526 if {$oldneg eq
$vnegids($view)} {
529 # take out positive refs that we asked for before or
530 # that we have already seen
532 if {[string length
$rev] == 40} {
533 if {[lsearch
-exact $oldpos $rev] < 0
534 && ![info exists varcid
($view,$rev)]} {
539 lappend
$newrevs $rev
542 if {$npos == 0} return
544 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
546 set args
[concat
$vflags($view) $revs --not $oldpos]
548 set args
$vorigargs($view)
551 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
552 --parents --boundary $args "--" $vfilelimit($view)] r
]
554 error_popup
"[mc "Error executing git log
:"] $err"
557 if {$viewactive($view) == 0} {
558 set startmsecs
[clock clicks
-milliseconds]
560 set i
[reg_instance
$fd]
561 lappend viewinstances
($view) $i
562 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
563 if {$tclencoding != {}} {
564 fconfigure
$fd -encoding $tclencoding
566 filerun
$fd [list getcommitlines
$fd $i $view 1]
567 incr viewactive
($view)
568 set viewcomplete
($view) 0
569 reset_pending_select
{}
570 nowbusy
$view [mc
"Reading"]
576 proc reloadcommits
{} {
577 global curview viewcomplete selectedline currentid thickerline
578 global showneartags treediffs commitinterest cached_commitrow
582 if {$selectedline ne
{}} {
586 if {!$viewcomplete($curview)} {
587 stop_rev_list
$curview
591 catch
{unset currentid
}
592 catch
{unset thickerline
}
593 catch
{unset treediffs
}
600 catch
{unset commitinterest
}
601 catch
{unset cached_commitrow
}
602 catch
{unset targetid
}
608 # This makes a string representation of a positive integer which
609 # sorts as a string in numerical order
612 return [format
"%x" $n]
613 } elseif
{$n < 256} {
614 return [format
"x%.2x" $n]
615 } elseif
{$n < 65536} {
616 return [format
"y%.4x" $n]
618 return [format
"z%.8x" $n]
621 # Procedures used in reordering commits from git log (without
622 # --topo-order) into the order for display.
624 proc varcinit
{view
} {
625 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
626 global vtokmod varcmod vrowmod varcix vlastins
628 set varcstart
($view) {{}}
629 set vupptr
($view) {0}
630 set vdownptr
($view) {0}
631 set vleftptr
($view) {0}
632 set vbackptr
($view) {0}
633 set varctok
($view) {{}}
634 set varcrow
($view) {{}}
635 set vtokmod
($view) {}
638 set varcix
($view) {{}}
639 set vlastins
($view) {0}
642 proc resetvarcs
{view
} {
643 global varcid varccommits parents children vseedcount ordertok
646 foreach vid
[array names varcid
$view,*] {
651 foreach vid
[array names vshortids
$view,*] {
652 unset vshortids
($vid)
654 # some commits might have children but haven't been seen yet
655 foreach vid
[array names children
$view,*] {
658 foreach va
[array names varccommits
$view,*] {
659 unset varccommits
($va)
661 foreach vd
[array names vseedcount
$view,*] {
662 unset vseedcount
($vd)
664 catch
{unset ordertok
}
667 # returns a list of the commits with no children
669 global vdownptr vleftptr varcstart
672 set a
[lindex
$vdownptr($v) 0]
674 lappend ret
[lindex
$varcstart($v) $a]
675 set a
[lindex
$vleftptr($v) $a]
680 proc newvarc
{view id
} {
681 global varcid varctok parents children vdatemode
682 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
683 global commitdata commitinfo vseedcount varccommits vlastins
685 set a
[llength
$varctok($view)]
687 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
688 if {![info exists commitinfo
($id)]} {
689 parsecommit
$id $commitdata($id) 1
691 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
692 if {![string is integer
-strict $cdate]} {
695 if {![info exists vseedcount
($view,$cdate)]} {
696 set vseedcount
($view,$cdate) -1
698 set c
[incr vseedcount
($view,$cdate)]
699 set cdate
[expr {$cdate ^
0xffffffff}]
700 set tok
"s[strrep $cdate][strrep $c]"
705 if {[llength
$children($vid)] > 0} {
706 set kid
[lindex
$children($vid) end
]
707 set k
$varcid($view,$kid)
708 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
711 set tok
[lindex
$varctok($view) $k]
715 set i
[lsearch
-exact $parents($view,$ki) $id]
716 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
717 append tok
[strrep
$j]
719 set c
[lindex
$vlastins($view) $ka]
720 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
722 set b
[lindex
$vdownptr($view) $ka]
724 set b
[lindex
$vleftptr($view) $c]
726 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
728 set b
[lindex
$vleftptr($view) $c]
731 lset vdownptr
($view) $ka $a
732 lappend vbackptr
($view) 0
734 lset vleftptr
($view) $c $a
735 lappend vbackptr
($view) $c
737 lset vlastins
($view) $ka $a
738 lappend vupptr
($view) $ka
739 lappend vleftptr
($view) $b
741 lset vbackptr
($view) $b $a
743 lappend varctok
($view) $tok
744 lappend varcstart
($view) $id
745 lappend vdownptr
($view) 0
746 lappend varcrow
($view) {}
747 lappend varcix
($view) {}
748 set varccommits
($view,$a) {}
749 lappend vlastins
($view) 0
753 proc splitvarc
{p v
} {
754 global varcid varcstart varccommits varctok vtokmod
755 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
757 set oa
$varcid($v,$p)
758 set otok
[lindex
$varctok($v) $oa]
759 set ac
$varccommits($v,$oa)
760 set i
[lsearch
-exact $varccommits($v,$oa) $p]
762 set na
[llength
$varctok($v)]
763 # "%" sorts before "0"...
764 set tok
"$otok%[strrep $i]"
765 lappend varctok
($v) $tok
766 lappend varcrow
($v) {}
767 lappend varcix
($v) {}
768 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
769 set varccommits
($v,$na) [lrange
$ac $i end
]
770 lappend varcstart
($v) $p
771 foreach id
$varccommits($v,$na) {
772 set varcid
($v,$id) $na
774 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
775 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
776 lset vdownptr
($v) $oa $na
777 lset vlastins
($v) $oa 0
778 lappend vupptr
($v) $oa
779 lappend vleftptr
($v) 0
780 lappend vbackptr
($v) 0
781 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
782 lset vupptr
($v) $b $na
784 if {[string compare
$otok $vtokmod($v)] <= 0} {
789 proc renumbervarc
{a v
} {
790 global parents children varctok varcstart varccommits
791 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
793 set t1
[clock clicks
-milliseconds]
799 if {[info exists isrelated
($a)]} {
801 set id
[lindex
$varccommits($v,$a) end
]
802 foreach p
$parents($v,$id) {
803 if {[info exists varcid
($v,$p)]} {
804 set isrelated
($varcid($v,$p)) 1
809 set b
[lindex
$vdownptr($v) $a]
812 set b
[lindex
$vleftptr($v) $a]
814 set a
[lindex
$vupptr($v) $a]
820 if {![info exists kidchanged
($a)]} continue
821 set id
[lindex
$varcstart($v) $a]
822 if {[llength
$children($v,$id)] > 1} {
823 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
826 set oldtok
[lindex
$varctok($v) $a]
827 if {!$vdatemode($v)} {
833 set kid
[last_real_child
$v,$id]
835 set k
$varcid($v,$kid)
836 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
839 set tok
[lindex
$varctok($v) $k]
843 set i
[lsearch
-exact $parents($v,$ki) $id]
844 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
845 append tok
[strrep
$j]
847 if {$tok eq
$oldtok} {
850 set id
[lindex
$varccommits($v,$a) end
]
851 foreach p
$parents($v,$id) {
852 if {[info exists varcid
($v,$p)]} {
853 set kidchanged
($varcid($v,$p)) 1
858 lset varctok
($v) $a $tok
859 set b
[lindex
$vupptr($v) $a]
861 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
864 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
867 set c
[lindex
$vbackptr($v) $a]
868 set d
[lindex
$vleftptr($v) $a]
870 lset vdownptr
($v) $b $d
872 lset vleftptr
($v) $c $d
875 lset vbackptr
($v) $d $c
877 if {[lindex
$vlastins($v) $b] == $a} {
878 lset vlastins
($v) $b $c
880 lset vupptr
($v) $a $ka
881 set c
[lindex
$vlastins($v) $ka]
883 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
885 set b
[lindex
$vdownptr($v) $ka]
887 set b
[lindex
$vleftptr($v) $c]
890 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
892 set b
[lindex
$vleftptr($v) $c]
895 lset vdownptr
($v) $ka $a
896 lset vbackptr
($v) $a 0
898 lset vleftptr
($v) $c $a
899 lset vbackptr
($v) $a $c
901 lset vleftptr
($v) $a $b
903 lset vbackptr
($v) $b $a
905 lset vlastins
($v) $ka $a
908 foreach id
[array names sortkids
] {
909 if {[llength
$children($v,$id)] > 1} {
910 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
914 set t2
[clock clicks
-milliseconds]
915 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
918 # Fix up the graph after we have found out that in view $v,
919 # $p (a commit that we have already seen) is actually the parent
920 # of the last commit in arc $a.
921 proc fix_reversal
{p a v
} {
922 global varcid varcstart varctok vupptr
924 set pa
$varcid($v,$p)
925 if {$p ne
[lindex
$varcstart($v) $pa]} {
927 set pa
$varcid($v,$p)
929 # seeds always need to be renumbered
930 if {[lindex
$vupptr($v) $pa] == 0 ||
931 [string compare
[lindex
$varctok($v) $a] \
932 [lindex
$varctok($v) $pa]] > 0} {
937 proc insertrow
{id p v
} {
938 global cmitlisted children parents varcid varctok vtokmod
939 global varccommits ordertok commitidx numcommits curview
940 global targetid targetrow vshortids
944 set cmitlisted
($vid) 1
945 set children
($vid) {}
946 set parents
($vid) [list
$p]
947 set a
[newvarc
$v $id]
949 lappend vshortids
($v,[string range
$id 0 3]) $id
950 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
953 lappend varccommits
($v,$a) $id
955 if {[llength
[lappend children
($vp) $id]] > 1} {
956 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
957 catch
{unset ordertok
}
959 fix_reversal
$p $a $v
961 if {$v == $curview} {
962 set numcommits
$commitidx($v)
964 if {[info exists targetid
]} {
965 if {![comes_before
$targetid $p]} {
972 proc insertfakerow
{id p
} {
973 global varcid varccommits parents children cmitlisted
974 global commitidx varctok vtokmod targetid targetrow curview numcommits
978 set i
[lsearch
-exact $varccommits($v,$a) $p]
980 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
983 set children
($v,$id) {}
984 set parents
($v,$id) [list
$p]
985 set varcid
($v,$id) $a
986 lappend children
($v,$p) $id
987 set cmitlisted
($v,$id) 1
988 set numcommits
[incr commitidx
($v)]
989 # note we deliberately don't update varcstart($v) even if $i == 0
990 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
992 if {[info exists targetid
]} {
993 if {![comes_before
$targetid $p]} {
1001 proc removefakerow
{id
} {
1002 global varcid varccommits parents children commitidx
1003 global varctok vtokmod cmitlisted currentid selectedline
1004 global targetid curview numcommits
1007 if {[llength
$parents($v,$id)] != 1} {
1008 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1011 set p
[lindex
$parents($v,$id) 0]
1012 set a
$varcid($v,$id)
1013 set i
[lsearch
-exact $varccommits($v,$a) $id]
1015 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1018 unset varcid
($v,$id)
1019 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1020 unset parents
($v,$id)
1021 unset children
($v,$id)
1022 unset cmitlisted
($v,$id)
1023 set numcommits
[incr commitidx
($v) -1]
1024 set j
[lsearch
-exact $children($v,$p) $id]
1026 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1029 if {[info exist currentid
] && $id eq
$currentid} {
1033 if {[info exists targetid
] && $targetid eq
$id} {
1040 proc real_children
{vp
} {
1041 global children nullid nullid2
1044 foreach id
$children($vp) {
1045 if {$id ne
$nullid && $id ne
$nullid2} {
1052 proc first_real_child
{vp
} {
1053 global children nullid nullid2
1055 foreach id
$children($vp) {
1056 if {$id ne
$nullid && $id ne
$nullid2} {
1063 proc last_real_child
{vp
} {
1064 global children nullid nullid2
1066 set kids
$children($vp)
1067 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1068 set id
[lindex
$kids $i]
1069 if {$id ne
$nullid && $id ne
$nullid2} {
1076 proc vtokcmp
{v a b
} {
1077 global varctok varcid
1079 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1080 [lindex
$varctok($v) $varcid($v,$b)]]
1083 # This assumes that if lim is not given, the caller has checked that
1084 # arc a's token is less than $vtokmod($v)
1085 proc modify_arc
{v a
{lim
{}}} {
1086 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1089 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1092 set r
[lindex
$varcrow($v) $a]
1093 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1096 set vtokmod
($v) [lindex
$varctok($v) $a]
1098 if {$v == $curview} {
1099 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1100 set a
[lindex
$vupptr($v) $a]
1106 set lim
[llength
$varccommits($v,$a)]
1108 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1115 proc update_arcrows
{v
} {
1116 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1117 global varcid vrownum varcorder varcix varccommits
1118 global vupptr vdownptr vleftptr varctok
1119 global displayorder parentlist curview cached_commitrow
1121 if {$vrowmod($v) == $commitidx($v)} return
1122 if {$v == $curview} {
1123 if {[llength
$displayorder] > $vrowmod($v)} {
1124 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1125 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1127 catch
{unset cached_commitrow
}
1129 set narctot
[expr {[llength
$varctok($v)] - 1}]
1131 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1132 # go up the tree until we find something that has a row number,
1133 # or we get to a seed
1134 set a
[lindex
$vupptr($v) $a]
1137 set a
[lindex
$vdownptr($v) 0]
1140 set varcorder
($v) [list
$a]
1141 lset varcix
($v) $a 0
1142 lset varcrow
($v) $a 0
1146 set arcn
[lindex
$varcix($v) $a]
1147 if {[llength
$vrownum($v)] > $arcn + 1} {
1148 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1149 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1151 set row
[lindex
$varcrow($v) $a]
1155 incr row
[llength
$varccommits($v,$a)]
1156 # go down if possible
1157 set b
[lindex
$vdownptr($v) $a]
1159 # if not, go left, or go up until we can go left
1161 set b
[lindex
$vleftptr($v) $a]
1163 set a
[lindex
$vupptr($v) $a]
1169 lappend vrownum
($v) $row
1170 lappend varcorder
($v) $a
1171 lset varcix
($v) $a $arcn
1172 lset varcrow
($v) $a $row
1174 set vtokmod
($v) [lindex
$varctok($v) $p]
1176 set vrowmod
($v) $row
1177 if {[info exists currentid
]} {
1178 set selectedline
[rowofcommit
$currentid]
1182 # Test whether view $v contains commit $id
1183 proc commitinview
{id v
} {
1186 return [info exists varcid
($v,$id)]
1189 # Return the row number for commit $id in the current view
1190 proc rowofcommit
{id
} {
1191 global varcid varccommits varcrow curview cached_commitrow
1192 global varctok vtokmod
1195 if {![info exists varcid
($v,$id)]} {
1196 puts
"oops rowofcommit no arc for [shortids $id]"
1199 set a
$varcid($v,$id)
1200 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1203 if {[info exists cached_commitrow
($id)]} {
1204 return $cached_commitrow($id)
1206 set i
[lsearch
-exact $varccommits($v,$a) $id]
1208 puts
"oops didn't find commit [shortids $id] in arc $a"
1211 incr i
[lindex
$varcrow($v) $a]
1212 set cached_commitrow
($id) $i
1216 # Returns 1 if a is on an earlier row than b, otherwise 0
1217 proc comes_before
{a b
} {
1218 global varcid varctok curview
1221 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1222 ![info exists varcid
($v,$b)]} {
1225 if {$varcid($v,$a) != $varcid($v,$b)} {
1226 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1227 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1229 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1232 proc bsearch
{l elt
} {
1233 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1238 while {$hi - $lo > 1} {
1239 set mid
[expr {int
(($lo + $hi) / 2)}]
1240 set t
[lindex
$l $mid]
1243 } elseif
{$elt > $t} {
1252 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1253 proc make_disporder
{start end
} {
1254 global vrownum curview commitidx displayorder parentlist
1255 global varccommits varcorder parents vrowmod varcrow
1256 global d_valid_start d_valid_end
1258 if {$end > $vrowmod($curview)} {
1259 update_arcrows
$curview
1261 set ai
[bsearch
$vrownum($curview) $start]
1262 set start
[lindex
$vrownum($curview) $ai]
1263 set narc
[llength
$vrownum($curview)]
1264 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1265 set a
[lindex
$varcorder($curview) $ai]
1266 set l
[llength
$displayorder]
1267 set al
[llength
$varccommits($curview,$a)]
1268 if {$l < $r + $al} {
1270 set pad
[ntimes
[expr {$r - $l}] {}]
1271 set displayorder
[concat
$displayorder $pad]
1272 set parentlist
[concat
$parentlist $pad]
1273 } elseif
{$l > $r} {
1274 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1275 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1277 foreach id
$varccommits($curview,$a) {
1278 lappend displayorder
$id
1279 lappend parentlist
$parents($curview,$id)
1281 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1283 foreach id
$varccommits($curview,$a) {
1284 lset displayorder
$i $id
1285 lset parentlist
$i $parents($curview,$id)
1293 proc commitonrow
{row
} {
1296 set id
[lindex
$displayorder $row]
1298 make_disporder
$row [expr {$row + 1}]
1299 set id
[lindex
$displayorder $row]
1304 proc closevarcs
{v
} {
1305 global varctok varccommits varcid parents children
1306 global cmitlisted commitidx vtokmod
1308 set missing_parents
0
1310 set narcs
[llength
$varctok($v)]
1311 for {set a
1} {$a < $narcs} {incr a
} {
1312 set id
[lindex
$varccommits($v,$a) end
]
1313 foreach p
$parents($v,$id) {
1314 if {[info exists varcid
($v,$p)]} continue
1315 # add p as a new commit
1316 incr missing_parents
1317 set cmitlisted
($v,$p) 0
1318 set parents
($v,$p) {}
1319 if {[llength
$children($v,$p)] == 1 &&
1320 [llength
$parents($v,$id)] == 1} {
1323 set b
[newvarc
$v $p]
1325 set varcid
($v,$p) $b
1326 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1329 lappend varccommits
($v,$b) $p
1331 set scripts
[check_interest
$p $scripts]
1334 if {$missing_parents > 0} {
1335 foreach s
$scripts {
1341 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1342 # Assumes we already have an arc for $rwid.
1343 proc rewrite_commit
{v id rwid
} {
1344 global children parents varcid varctok vtokmod varccommits
1346 foreach ch
$children($v,$id) {
1347 # make $rwid be $ch's parent in place of $id
1348 set i
[lsearch
-exact $parents($v,$ch) $id]
1350 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1352 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1353 # add $ch to $rwid's children and sort the list if necessary
1354 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1355 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1356 $children($v,$rwid)]
1358 # fix the graph after joining $id to $rwid
1359 set a
$varcid($v,$ch)
1360 fix_reversal
$rwid $a $v
1361 # parentlist is wrong for the last element of arc $a
1362 # even if displayorder is right, hence the 3rd arg here
1363 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1367 # Mechanism for registering a command to be executed when we come
1368 # across a particular commit. To handle the case when only the
1369 # prefix of the commit is known, the commitinterest array is now
1370 # indexed by the first 4 characters of the ID. Each element is a
1371 # list of id, cmd pairs.
1372 proc interestedin
{id cmd
} {
1373 global commitinterest
1375 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1378 proc check_interest
{id scripts
} {
1379 global commitinterest
1381 set prefix
[string range
$id 0 3]
1382 if {[info exists commitinterest
($prefix)]} {
1384 foreach
{i
script} $commitinterest($prefix) {
1385 if {[string match
"$i*" $id]} {
1386 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1388 lappend newlist
$i $script
1391 if {$newlist ne
{}} {
1392 set commitinterest
($prefix) $newlist
1394 unset commitinterest
($prefix)
1400 proc getcommitlines
{fd inst view updating
} {
1401 global cmitlisted leftover
1402 global commitidx commitdata vdatemode
1403 global parents children curview hlview
1404 global idpending ordertok
1405 global varccommits varcid varctok vtokmod vfilelimit vshortids
1407 set stuff
[read $fd 500000]
1408 # git log doesn't terminate the last commit with a null...
1409 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1416 global commfd viewcomplete viewactive viewname
1417 global viewinstances
1419 set i
[lsearch
-exact $viewinstances($view) $inst]
1421 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1423 # set it blocking so we wait for the process to terminate
1424 fconfigure
$fd -blocking 1
1425 if {[catch
{close
$fd} err
]} {
1427 if {$view != $curview} {
1428 set fv
" for the \"$viewname($view)\" view"
1430 if {[string range
$err 0 4] == "usage"} {
1431 set err
"Gitk: error reading commits$fv:\
1432 bad arguments to git log."
1433 if {$viewname($view) eq
"Command line"} {
1435 " (Note: arguments to gitk are passed to git log\
1436 to allow selection of commits to be displayed.)"
1439 set err
"Error reading commits$fv: $err"
1443 if {[incr viewactive
($view) -1] <= 0} {
1444 set viewcomplete
($view) 1
1445 # Check if we have seen any ids listed as parents that haven't
1446 # appeared in the list
1450 if {$view == $curview} {
1459 set i
[string first
"\0" $stuff $start]
1461 append leftover
($inst) [string range
$stuff $start end
]
1465 set cmit
$leftover($inst)
1466 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1467 set leftover
($inst) {}
1469 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1471 set start
[expr {$i + 1}]
1472 set j
[string first
"\n" $cmit]
1475 if {$j >= 0 && [string match
"commit *" $cmit]} {
1476 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1477 if {[string match
{[-^
<>]*} $ids]} {
1478 switch
-- [string index
$ids 0] {
1484 set ids
[string range
$ids 1 end
]
1488 if {[string length
$id] != 40} {
1496 if {[string length
$shortcmit] > 80} {
1497 set shortcmit
"[string range $shortcmit 0 80]..."
1499 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1502 set id [lindex $ids 0]
1505 lappend vshortids($view,[string range $id 0 3]) $id
1507 if {!$listed && $updating && ![info exists varcid($vid)] &&
1508 $vfilelimit($view) ne {}} {
1509 # git log doesn't rewrite parents
for unlisted commits
1510 # when doing path limiting, so work around that here
1511 # by working out the rewritten parent with git rev-list
1512 # and if we already know about it, using the rewritten
1513 # parent as a substitute parent for $id's children.
1515 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1516 $id -- $vfilelimit($view)]
1518 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1519 # use $rwid in place of $id
1520 rewrite_commit
$view $id $rwid
1527 if {[info exists varcid
($vid)]} {
1528 if {$cmitlisted($vid) ||
!$listed} continue
1532 set olds
[lrange
$ids 1 end
]
1536 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1537 set cmitlisted
($vid) $listed
1538 set parents
($vid) $olds
1539 if {![info exists children
($vid)]} {
1540 set children
($vid) {}
1541 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1542 set k
[lindex
$children($vid) 0]
1543 if {[llength
$parents($view,$k)] == 1 &&
1544 (!$vdatemode($view) ||
1545 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1546 set a
$varcid($view,$k)
1551 set a
[newvarc
$view $id]
1553 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1556 if {![info exists varcid
($vid)]} {
1558 lappend varccommits
($view,$a) $id
1559 incr commitidx
($view)
1564 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1566 if {[llength
[lappend children
($vp) $id]] > 1 &&
1567 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1568 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1570 catch
{unset ordertok
}
1572 if {[info exists varcid
($view,$p)]} {
1573 fix_reversal
$p $a $view
1579 set scripts
[check_interest
$id $scripts]
1583 global numcommits hlview
1585 if {$view == $curview} {
1586 set numcommits
$commitidx($view)
1589 if {[info exists hlview
] && $view == $hlview} {
1590 # we never actually get here...
1593 foreach s
$scripts {
1600 proc chewcommits
{} {
1601 global curview hlview viewcomplete
1602 global pending_select
1605 if {$viewcomplete($curview)} {
1606 global commitidx varctok
1607 global numcommits startmsecs
1609 if {[info exists pending_select
]} {
1611 reset_pending_select
{}
1613 if {[commitinview
$pending_select $curview]} {
1614 selectline
[rowofcommit
$pending_select] 1
1616 set row
[first_real_row
]
1620 if {$commitidx($curview) > 0} {
1621 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1622 #puts "overall $ms ms for $numcommits commits"
1623 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1625 show_status
[mc
"No commits selected"]
1632 proc do_readcommit
{id
} {
1635 # Invoke git-log to handle automatic encoding conversion
1636 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1637 # Read the results using i18n.logoutputencoding
1638 fconfigure
$fd -translation lf
-eofchar {}
1639 if {$tclencoding != {}} {
1640 fconfigure
$fd -encoding $tclencoding
1642 set contents
[read $fd]
1644 # Remove the heading line
1645 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1650 proc readcommit
{id
} {
1651 if {[catch
{set contents
[do_readcommit
$id]}]} return
1652 parsecommit
$id $contents 1
1655 proc parsecommit
{id contents listed
} {
1665 set hdrend
[string first
"\n\n" $contents]
1667 # should never happen...
1668 set hdrend
[string length
$contents]
1670 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1671 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1672 foreach line
[split $header "\n"] {
1673 set line
[split $line " "]
1674 set tag
[lindex
$line 0]
1675 if {$tag == "author"} {
1676 set audate
[lrange
$line end-1 end
]
1677 set auname
[join [lrange
$line 1 end-2
] " "]
1678 } elseif
{$tag == "committer"} {
1679 set comdate
[lrange
$line end-1 end
]
1680 set comname
[join [lrange
$line 1 end-2
] " "]
1684 # take the first non-blank line of the comment as the headline
1685 set headline
[string trimleft
$comment]
1686 set i
[string first
"\n" $headline]
1688 set headline
[string range
$headline 0 $i]
1690 set headline
[string trimright
$headline]
1691 set i
[string first
"\r" $headline]
1693 set headline
[string trimright
[string range
$headline 0 $i]]
1696 # git log indents the comment by 4 spaces;
1697 # if we got this via git cat-file, add the indentation
1699 foreach line
[split $comment "\n"] {
1700 append newcomment
" "
1701 append newcomment
$line
1702 append newcomment
"\n"
1704 set comment
$newcomment
1706 set hasnote
[string first
"\nNotes:\n" $contents]
1707 set commitinfo
($id) [list
$headline $auname $audate \
1708 $comname $comdate $comment $hasnote]
1711 proc getcommit
{id
} {
1712 global commitdata commitinfo
1714 if {[info exists commitdata
($id)]} {
1715 parsecommit
$id $commitdata($id) 1
1718 if {![info exists commitinfo
($id)]} {
1719 set commitinfo
($id) [list
[mc
"No commit information available"]]
1725 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1726 # and are present in the current view.
1727 # This is fairly slow...
1728 proc longid
{prefix
} {
1729 global varcid curview vshortids
1732 if {[string length
$prefix] >= 4} {
1733 set vshortid
$curview,[string range
$prefix 0 3]
1734 if {[info exists vshortids
($vshortid)]} {
1735 foreach id
$vshortids($vshortid) {
1736 if {[string match
"$prefix*" $id]} {
1737 if {[lsearch
-exact $ids $id] < 0} {
1739 if {[llength
$ids] >= 2} break
1745 foreach match
[array names varcid
"$curview,$prefix*"] {
1746 lappend ids
[lindex
[split $match ","] 1]
1747 if {[llength
$ids] >= 2} break
1754 global tagids idtags headids idheads tagobjid
1755 global otherrefids idotherrefs mainhead mainheadid
1756 global selecthead selectheadid
1759 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1762 set refd
[open
[list | git show-ref
-d] r
]
1763 while {[gets
$refd line
] >= 0} {
1764 if {[string index
$line 40] ne
" "} continue
1765 set id
[string range
$line 0 39]
1766 set ref
[string range
$line 41 end
]
1767 if {![string match
"refs/*" $ref]} continue
1768 set name
[string range
$ref 5 end
]
1769 if {[string match
"remotes/*" $name]} {
1770 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1771 set headids
($name) $id
1772 lappend idheads
($id) $name
1774 } elseif
{[string match
"heads/*" $name]} {
1775 set name
[string range
$name 6 end
]
1776 set headids
($name) $id
1777 lappend idheads
($id) $name
1778 } elseif
{[string match
"tags/*" $name]} {
1779 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1780 # which is what we want since the former is the commit ID
1781 set name
[string range
$name 5 end
]
1782 if {[string match
"*^{}" $name]} {
1783 set name
[string range
$name 0 end-3
]
1785 set tagobjid
($name) $id
1787 set tagids
($name) $id
1788 lappend idtags
($id) $name
1790 set otherrefids
($name) $id
1791 lappend idotherrefs
($id) $name
1798 set mainheadid
[exec git rev-parse HEAD
]
1799 set thehead
[exec git symbolic-ref HEAD
]
1800 if {[string match
"refs/heads/*" $thehead]} {
1801 set mainhead
[string range
$thehead 11 end
]
1805 if {$selecthead ne
{}} {
1807 set selectheadid
[exec git rev-parse
--verify $selecthead]
1812 # skip over fake commits
1813 proc first_real_row
{} {
1814 global nullid nullid2 numcommits
1816 for {set row
0} {$row < $numcommits} {incr row
} {
1817 set id
[commitonrow
$row]
1818 if {$id ne
$nullid && $id ne
$nullid2} {
1825 # update things for a head moved to a child of its previous location
1826 proc movehead
{id name
} {
1827 global headids idheads
1829 removehead
$headids($name) $name
1830 set headids
($name) $id
1831 lappend idheads
($id) $name
1834 # update things when a head has been removed
1835 proc removehead
{id name
} {
1836 global headids idheads
1838 if {$idheads($id) eq
$name} {
1841 set i
[lsearch
-exact $idheads($id) $name]
1843 set idheads
($id) [lreplace
$idheads($id) $i $i]
1846 unset headids
($name)
1849 proc ttk_toplevel
{w args
} {
1851 eval [linsert
$args 0 ::toplevel
$w]
1853 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1858 proc make_transient
{window origin
} {
1861 # In MacOS Tk 8.4 transient appears to work by setting
1862 # overrideredirect, which is utterly useless, since the
1863 # windows get no border, and are not even kept above
1865 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1867 wm transient
$window $origin
1869 # Windows fails to place transient windows normally, so
1870 # schedule a callback to center them on the parent.
1871 if {[tk windowingsystem
] eq
{win32
}} {
1872 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1876 proc show_error
{w top msg
{mc mc
}} {
1878 if {![info exists NS
]} {set NS
""}
1879 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1880 message
$w.m
-text $msg -justify center
-aspect 400
1881 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1882 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1883 pack
$w.ok
-side bottom
-fill x
1884 bind $top <Visibility
> "grab $top; focus $top"
1885 bind $top <Key-Return
> "destroy $top"
1886 bind $top <Key-space
> "destroy $top"
1887 bind $top <Key-Escape
> "destroy $top"
1891 proc error_popup
{msg
{owner .
}} {
1892 if {[tk windowingsystem
] eq
"win32"} {
1893 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1894 -parent $owner -message $msg
1898 make_transient
$w $owner
1899 show_error
$w $w $msg
1903 proc confirm_popup
{msg
{owner .
}} {
1904 global confirm_ok NS
1908 make_transient
$w $owner
1909 message
$w.m
-text $msg -justify center
-aspect 400
1910 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1911 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1912 pack
$w.ok
-side left
-fill x
1913 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1914 pack
$w.cancel
-side right
-fill x
1915 bind $w <Visibility
> "grab $w; focus $w"
1916 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1917 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1918 bind $w <Key-Escape
> "destroy $w"
1919 tk
::PlaceWindow
$w widget
$owner
1924 proc setoptions
{} {
1925 if {[tk windowingsystem
] ne
"win32"} {
1926 option add
*Panedwindow.showHandle
1 startupFile
1927 option add
*Panedwindow.sashRelief raised startupFile
1928 if {[tk windowingsystem
] ne
"aqua"} {
1929 option add
*Menu.font uifont startupFile
1932 option add
*Menu.TearOff
0 startupFile
1934 option add
*Button.font uifont startupFile
1935 option add
*Checkbutton.font uifont startupFile
1936 option add
*Radiobutton.font uifont startupFile
1937 option add
*Menubutton.font uifont startupFile
1938 option add
*Label.font uifont startupFile
1939 option add
*Message.font uifont startupFile
1940 option add
*Entry.font textfont startupFile
1941 option add
*Text.font textfont startupFile
1942 option add
*Labelframe.font uifont startupFile
1943 option add
*Spinbox.font textfont startupFile
1944 option add
*Listbox.font mainfont startupFile
1947 # Make a menu and submenus.
1948 # m is the window name for the menu, items is the list of menu items to add.
1949 # Each item is a list {mc label type description options...}
1950 # mc is ignored; it's so we can put mc there to alert xgettext
1951 # label is the string that appears in the menu
1952 # type is cascade, command or radiobutton (should add checkbutton)
1953 # description depends on type; it's the sublist for cascade, the
1954 # command to invoke for command, or {variable value} for radiobutton
1955 proc makemenu
{m items
} {
1957 if {[tk windowingsystem
] eq
{aqua
}} {
1963 set name
[mc
[lindex
$i 1]]
1964 set type [lindex
$i 2]
1965 set thing
[lindex
$i 3]
1966 set params
[list
$type]
1968 set u
[string first
"&" [string map
{&& x
} $name]]
1969 lappend params
-label [string map
{&& & & {}} $name]
1971 lappend params
-underline $u
1976 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1977 lappend params
-menu $m.
$submenu
1980 lappend params
-command $thing
1983 lappend params
-variable [lindex
$thing 0] \
1984 -value [lindex
$thing 1]
1987 set tail [lrange
$i 4 end
]
1988 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
1989 eval $m add
$params $tail
1990 if {$type eq
"cascade"} {
1991 makemenu
$m.
$submenu $thing
1996 # translate string and remove ampersands
1998 return [string map
{&& & & {}} [mc
$str]]
2001 proc cleardropsel
{w
} {
2004 proc makedroplist
{w varname args
} {
2008 foreach label
$args {
2009 set cx
[string length
$label]
2010 if {$cx > $width} {set width
$cx}
2012 set gm
[ttk
::combobox
$w -width $width -state readonly\
2013 -textvariable $varname -values $args \
2014 -exportselection false
]
2015 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2017 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2022 proc makewindow {} {
2023 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2025 global findtype findtypemenu findloc findstring fstring geometry
2026 global entries sha1entry sha1string sha1but
2027 global diffcontextstring diffcontext
2029 global maincursor textcursor curtextcursor
2030 global rowctxmenu fakerowmenu mergemax wrapcomment
2031 global highlight_files gdttype
2032 global searchstring sstring
2033 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2034 global uifgcolor uifgdisabledcolor
2035 global filesepbgcolor filesepfgcolor
2036 global mergecolors foundbgcolor currentsearchhitbgcolor
2037 global headctxmenu progresscanv progressitem progresscoords statusw
2038 global fprogitem fprogcoord lastprogupdate progupdatepending
2039 global rprogitem rprogcoord rownumsel numcommits
2040 global have_tk85 use_ttk NS
2044 # The "mc" arguments here are purely so that xgettext
2045 # sees the following string as needing to be translated
2048 {mc "Update" command updatecommits -accelerator F5}
2049 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2050 {mc "Reread references" command rereadrefs}
2051 {mc "List references" command showrefs -accelerator F2}
2053 {mc "Start git gui" command {exec git gui &}}
2055 {mc "Quit" command doquit -accelerator Meta1-Q}
2059 {mc "Preferences" command doprefs}
2063 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2064 {mc "Edit view..." command editview -state disabled -accelerator F4}
2065 {mc "Delete view" command delview -state disabled}
2067 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2069 if {[tk windowingsystem] ne "aqua"} {
2072 {mc "About gitk" command about}
2073 {mc "Key bindings" command keys}
2075 set bar [list $file $edit $view $help]
2077 proc ::tk::mac::ShowPreferences {} {doprefs}
2078 proc ::tk::mac::Quit {} {doquit}
2079 lset file end [lreplace [lindex $file end] end-1 end]
2081 xx "Apple" cascade {
2082 {mc "About gitk" command about}
2087 {mc "Key bindings" command keys}
2089 set bar [list $apple $file $view $help]
2092 . configure -menu .bar
2095 # cover the non-themed toplevel with a themed frame.
2096 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2099 # the gui has upper and lower half, parts of a paned window.
2100 ${NS}::panedwindow .ctop -orient vertical
2102 # possibly use assumed geometry
2103 if {![info exists geometry(pwsash0)]} {
2104 set geometry(topheight) [expr {15 * $linespc}]
2105 set geometry(topwidth) [expr {80 * $charspc}]
2106 set geometry(botheight) [expr {15 * $linespc}]
2107 set geometry(botwidth) [expr {50 * $charspc}]
2108 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2109 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2112 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2113 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2114 ${NS}::frame .tf.histframe
2115 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2117 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2120 # create three canvases
2121 set cscroll .tf.histframe.csb
2122 set canv .tf.histframe.pwclist.canv
2124 -selectbackground $selectbgcolor \
2125 -background $bgcolor -bd 0 \
2126 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2127 .tf.histframe.pwclist add $canv
2128 set canv2 .tf.histframe.pwclist.canv2
2130 -selectbackground $selectbgcolor \
2131 -background $bgcolor -bd 0 -yscrollincr $linespc
2132 .tf.histframe.pwclist add $canv2
2133 set canv3 .tf.histframe.pwclist.canv3
2135 -selectbackground $selectbgcolor \
2136 -background $bgcolor -bd 0 -yscrollincr $linespc
2137 .tf.histframe.pwclist add $canv3
2139 bind .tf.histframe.pwclist <Map> {
2141 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2142 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2145 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2146 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2149 # a scroll bar to rule them
2150 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2151 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2152 pack $cscroll -side right -fill y
2153 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2154 lappend bglist $canv $canv2 $canv3
2155 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2157 # we have two button bars at bottom of top frame. Bar 1
2158 ${NS}::frame .tf.bar
2159 ${NS}::frame .tf.lbar -height 15
2161 set sha1entry .tf.bar.sha1
2162 set entries $sha1entry
2163 set sha1but .tf.bar.sha1label
2164 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2165 -command gotocommit -width 8
2166 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2167 pack .tf.bar.sha1label -side left
2168 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2169 trace add variable sha1string write sha1change
2170 pack $sha1entry -side left -pady 2
2173 #define left_width 16
2174 #define left_height 16
2175 static unsigned char left_bits[] = {
2176 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2177 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2178 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2181 #define right_width 16
2182 #define right_height 16
2183 static unsigned char right_bits[] = {
2184 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2185 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2186 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2188 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2189 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2190 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2191 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2193 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2195 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2197 .tf.bar.leftbut configure -image bm-left
2199 pack .tf.bar.leftbut -side left -fill y
2200 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2202 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2204 .tf.bar.rightbut configure -image bm-right
2206 pack .tf.bar.rightbut -side left -fill y
2208 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2210 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2211 -relief sunken -anchor e
2212 ${NS}::label .tf.bar.rowlabel2 -text "/"
2213 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2214 -relief sunken -anchor e
2215 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2218 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2221 trace add variable selectedline write selectedline_change
2223 # Status label and progress bar
2224 set statusw .tf.bar.status
2225 ${NS}::label $statusw -width 15 -relief sunken
2226 pack $statusw -side left -padx 5
2228 set progresscanv [ttk::progressbar .tf.bar.progress]
2230 set h [expr {[font metrics uifont -linespace] + 2}]
2231 set progresscanv .tf.bar.progress
2232 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2233 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2234 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2235 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2237 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2238 set progresscoords {0 0}
2241 bind $progresscanv <Configure> adjustprogress
2242 set lastprogupdate [clock clicks -milliseconds]
2243 set progupdatepending 0
2245 # build up the bottom bar of upper window
2246 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2247 ${NS}::button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
2248 ${NS}::button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
2249 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2250 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2252 set gdttype [mc "containing:"]
2253 set gm [makedroplist .tf.lbar.gdttype gdttype \
2254 [mc "containing:"] \
2255 [mc "touching paths:"] \
2256 [mc "adding/removing string:"]]
2257 trace add variable gdttype write gdttype_change
2258 pack .tf.lbar.gdttype -side left -fill y
2261 set fstring .tf.lbar.findstring
2262 lappend entries $fstring
2263 ${NS}::entry $fstring -width 30 -textvariable findstring
2264 trace add variable findstring write find_change
2265 set findtype [mc "Exact"]
2266 set findtypemenu [makedroplist .tf.lbar.findtype \
2267 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2268 trace add variable findtype write findcom_change
2269 set findloc [mc "All fields"]
2270 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2271 [mc "Comments"] [mc "Author"] [mc "Committer"]
2272 trace add variable findloc write find_change
2273 pack .tf.lbar.findloc -side right
2274 pack .tf.lbar.findtype -side right
2275 pack $fstring -side left -expand 1 -fill x
2277 # Finish putting the upper half of the viewer together
2278 pack .tf.lbar -in .tf -side bottom -fill x
2279 pack .tf.bar -in .tf -side bottom -fill x
2280 pack .tf.histframe -fill both -side top -expand 1
2283 .ctop paneconfigure .tf -height $geometry(topheight)
2284 .ctop paneconfigure .tf -width $geometry(topwidth)
2287 # now build up the bottom
2288 ${NS}::panedwindow .pwbottom -orient horizontal
2290 # lower left, a text box over search bar, scroll bar to the right
2291 # if we know window height, then that will set the lower text height, otherwise
2292 # we set lower text height which will drive window height
2293 if {[info exists geometry(main)]} {
2294 ${NS}::frame .bleft -width $geometry(botwidth)
2296 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2298 ${NS}::frame .bleft.top
2299 ${NS}::frame .bleft.mid
2300 ${NS}::frame .bleft.bottom
2302 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2303 pack .bleft.top.search -side left -padx 5
2304 set sstring .bleft.top.sstring
2306 ${NS}::entry $sstring -width 20 -textvariable searchstring
2307 lappend entries $sstring
2308 trace add variable searchstring write incrsearch
2309 pack $sstring -side left -expand 1 -fill x
2310 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2311 -command changediffdisp -variable diffelide -value {0 0}
2312 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2313 -command changediffdisp -variable diffelide -value {0 1}
2314 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2315 -command changediffdisp -variable diffelide -value {1 0}
2316 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2317 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2318 spinbox .bleft.mid.diffcontext -width 5 \
2319 -from 0 -increment 1 -to 10000000 \
2320 -validate all -validatecommand "diffcontextvalidate %P" \
2321 -textvariable diffcontextstring
2322 .bleft.mid.diffcontext set $diffcontext
2323 trace add variable diffcontextstring write diffcontextchange
2324 lappend entries .bleft.mid.diffcontext
2325 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2326 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2327 -command changeignorespace -variable ignorespace
2328 pack .bleft.mid.ignspace -side left -padx 5
2330 set worddiff [mc "Line diff"]
2331 if {[package vcompare $git_version "1.7.2"] >= 0} {
2332 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2333 [mc "Markup words"] [mc "Color words"]
2334 trace add variable worddiff write changeworddiff
2335 pack .bleft.mid.worddiff -side left -padx 5
2338 set ctext .bleft.bottom.ctext
2339 text $ctext -background $bgcolor -foreground $fgcolor \
2340 -state disabled -font textfont \
2341 -yscrollcommand scrolltext -wrap none \
2342 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2344 $ctext conf -tabstyle wordprocessor
2346 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2347 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2348 pack .bleft.top -side top -fill x
2349 pack .bleft.mid -side top -fill x
2350 grid $ctext .bleft.bottom.sb -sticky nsew
2351 grid .bleft.bottom.sbhorizontal -sticky ew
2352 grid columnconfigure .bleft.bottom 0 -weight 1
2353 grid rowconfigure .bleft.bottom 0 -weight 1
2354 grid rowconfigure .bleft.bottom 1 -weight 0
2355 pack .bleft.bottom -side top -fill both -expand 1
2356 lappend bglist $ctext
2357 lappend fglist $ctext
2359 $ctext tag conf comment -wrap $wrapcomment
2360 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2361 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2362 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2363 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2364 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2365 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2366 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2367 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2368 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2369 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2370 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2371 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2372 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2373 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2374 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2375 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2376 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2377 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2378 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2379 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2380 $ctext tag conf mmax -fore darkgrey
2382 $ctext tag conf mresult -font textfontbold
2383 $ctext tag conf msep -font textfontbold
2384 $ctext tag conf found -back $foundbgcolor
2385 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2386 $ctext tag conf wwrap -wrap word
2388 .pwbottom add .bleft
2390 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2394 ${NS}::frame .bright
2395 ${NS}::frame .bright.mode
2396 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2397 -command reselectline -variable cmitmode -value "patch"
2398 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2399 -command reselectline -variable cmitmode -value "tree"
2400 grid .bright.mode.patch .bright.mode.tree -sticky ew
2401 pack .bright.mode -side top -fill x
2402 set cflist .bright.cfiles
2403 set indent [font measure mainfont "nn"]
2405 -selectbackground $selectbgcolor \
2406 -background $bgcolor -foreground $fgcolor \
2408 -tabs [list $indent [expr {2 * $indent}]] \
2409 -yscrollcommand ".bright.sb set" \
2410 -cursor [. cget -cursor] \
2411 -spacing1 1 -spacing3 1
2412 lappend bglist $cflist
2413 lappend fglist $cflist
2414 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2415 pack .bright.sb -side right -fill y
2416 pack $cflist -side left -fill both -expand 1
2417 $cflist tag configure highlight \
2418 -background [$cflist cget -selectbackground]
2419 $cflist tag configure bold -font mainfontbold
2421 .pwbottom add .bright
2424 # restore window width & height if known
2425 if {[info exists geometry(main)]} {
2426 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2427 if {$w > [winfo screenwidth .]} {
2428 set w [winfo screenwidth .]
2430 if {$h > [winfo screenheight .]} {
2431 set h [winfo screenheight .]
2433 wm geometry . "${w}x$h"
2437 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2438 wm state . $geometry(state)
2441 if {[tk windowingsystem] eq {aqua}} {
2452 %W sashpos 0 $::geometry(topheight)
2454 bind .pwbottom <Map> {
2456 %W sashpos 0 $::geometry(botwidth)
2460 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2461 pack .ctop -fill both -expand 1
2462 bindall <1> {selcanvline %W %x %y}
2463 #bindall <B1-Motion> {selcanvline %W %x %y}
2464 if {[tk windowingsystem] == "win32"} {
2465 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2466 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2468 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2469 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2470 if {[tk windowingsystem] eq "aqua"} {
2471 bindall <MouseWheel> {
2472 set delta [expr {- (%D)}]
2473 allcanvs yview scroll $delta units
2475 bindall <Shift-MouseWheel> {
2476 set delta [expr {- (%D)}]
2477 $canv xview scroll $delta units
2481 bindall <$::BM> "canvscan mark %W %x %y"
2482 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2483 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2484 bind . <$M1B-Key-w> doquit
2485 bindkey <Home> selfirstline
2486 bindkey <End> sellastline
2487 bind . <Key-Up> "selnextline -1"
2488 bind . <Key-Down> "selnextline 1"
2489 bind . <Shift-Key-Up> "dofind -1 0"
2490 bind . <Shift-Key-Down> "dofind 1 0"
2491 bindkey <Key-Right> "goforw"
2492 bindkey <Key-Left> "goback"
2493 bind . <Key-Prior> "selnextpage -1"
2494 bind . <Key-Next> "selnextpage 1"
2495 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2496 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2497 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2498 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2499 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2500 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2501 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2502 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2503 bindkey <Key-space> "$ctext yview scroll 1 pages"
2504 bindkey p "selnextline -1"
2505 bindkey n "selnextline 1"
2508 bindkey k "selnextline -1"
2509 bindkey j "selnextline 1"
2513 bindkey d "$ctext yview scroll 18 units"
2514 bindkey u "$ctext yview scroll -18 units"
2515 bindkey / {focus $fstring}
2516 bindkey <Key-KP_Divide> {focus $fstring}
2517 bindkey <Key-Return> {dofind 1 1}
2518 bindkey ? {dofind -1 1}
2520 bind . <F5> updatecommits
2521 bindmodfunctionkey Shift 5 reloadcommits
2522 bind . <F2> showrefs
2523 bindmodfunctionkey Shift 4 {newview 0}
2524 bind . <F4> edit_or_newview
2525 bind . <$M1B-q> doquit
2526 bind . <$M1B-f> {dofind 1 1}
2527 bind . <$M1B-g> {dofind 1 0}
2528 bind . <$M1B-r> dosearchback
2529 bind . <$M1B-s> dosearch
2530 bind . <$M1B-equal> {incrfont 1}
2531 bind . <$M1B-plus> {incrfont 1}
2532 bind . <$M1B-KP_Add> {incrfont 1}
2533 bind . <$M1B-minus> {incrfont -1}
2534 bind . <$M1B-KP_Subtract> {incrfont -1}
2535 wm protocol . WM_DELETE_WINDOW doquit
2536 bind . <Destroy> {stop_backends}
2537 bind . <Button-1> "click %W"
2538 bind $fstring <Key-Return> {dofind 1 1}
2539 bind $sha1entry <Key-Return> {gotocommit; break}
2540 bind $sha1entry <<PasteSelection>> clearsha1
2541 bind $cflist <1> {sel_flist %W %x %y; break}
2542 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2543 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2545 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2546 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2547 bind $ctext <Button-1> {focus %W}
2548 bind $ctext <<Selection>> rehighlight_search_results
2550 set maincursor [. cget -cursor]
2551 set textcursor [$ctext cget -cursor]
2552 set curtextcursor $textcursor
2554 set rowctxmenu .rowctxmenu
2555 makemenu $rowctxmenu {
2556 {mc "Diff this -> selected" command {diffvssel 0}}
2557 {mc "Diff selected -> this" command {diffvssel 1}}
2558 {mc "Make patch" command mkpatch}
2559 {mc "Create tag" command mktag}
2560 {mc "Write commit to file" command writecommit}
2561 {mc "Create new branch" command mkbranch}
2562 {mc "Cherry-pick this commit" command cherrypick}
2563 {mc "Reset HEAD branch to here" command resethead}
2564 {mc "Mark this commit" command markhere}
2565 {mc "Return to mark" command gotomark}
2566 {mc "Find descendant of this and mark" command find_common_desc}
2567 {mc "Compare with marked commit" command compare_commits}
2568 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2569 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2571 $rowctxmenu configure -tearoff 0
2573 set fakerowmenu .fakerowmenu
2574 makemenu $fakerowmenu {
2575 {mc "Diff this -> selected" command {diffvssel 0}}
2576 {mc "Diff selected -> this" command {diffvssel 1}}
2577 {mc "Make patch" command mkpatch}
2578 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2579 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2581 $fakerowmenu configure -tearoff 0
2583 set headctxmenu .headctxmenu
2584 makemenu $headctxmenu {
2585 {mc "Check out this branch" command cobranch}
2586 {mc "Remove this branch" command rmbranch}
2588 $headctxmenu configure -tearoff 0
2591 set flist_menu .flistctxmenu
2592 makemenu $flist_menu {
2593 {mc "Highlight this too" command {flist_hl 0}}
2594 {mc "Highlight this only" command {flist_hl 1}}
2595 {mc "External diff" command {external_diff}}
2596 {mc "Blame parent commit" command {external_blame 1}}
2598 $flist_menu configure -tearoff 0
2601 set diff_menu .diffctxmenu
2602 makemenu $diff_menu {
2603 {mc "Show origin of this line" command show_line_source}
2604 {mc "Run git gui blame on this line" command {external_blame_diff}}
2606 $diff_menu configure -tearoff 0
2609 # Windows sends all mouse wheel events to the current focused window, not
2610 # the one where the mouse hovers, so bind those events here and redirect
2611 # to the correct window
2612 proc windows_mousewheel_redirector {W X Y D} {
2613 global canv canv2 canv3
2614 set w [winfo containing -displayof $W $X $Y]
2616 set u [expr {$D < 0 ? 5 : -5}]
2617 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2618 allcanvs yview scroll $u units
2621 $w yview scroll $u units
2627 # Update row number label when selectedline changes
2628 proc selectedline_change {n1 n2 op} {
2629 global selectedline rownumsel
2631 if {$selectedline eq {}} {
2634 set rownumsel [expr {$selectedline + 1}]
2638 # mouse-2 makes all windows scan vertically, but only the one
2639 # the cursor is in scans horizontally
2640 proc canvscan {op w x y} {
2641 global canv canv2 canv3
2642 foreach c [list $canv $canv2 $canv3] {
2651 proc scrollcanv {cscroll f0 f1} {
2652 $cscroll set $f0 $f1
2657 # when we make a key binding for the toplevel, make sure
2658 # it doesn't get triggered when that key is pressed in the
2659 # find string entry widget.
2660 proc bindkey {ev script} {
2663 set escript [bind Entry $ev]
2664 if {$escript == {}} {
2665 set escript [bind Entry <Key>]
2667 foreach e $entries {
2668 bind $e $ev "$escript; break"
2672 proc bindmodfunctionkey {mod n script} {
2673 bind . <$mod-F$n> $script
2674 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2677 # set the focus back to the toplevel for any click outside
2680 global ctext entries
2681 foreach e [concat $entries $ctext] {
2682 if {$w == $e} return
2687 # Adjust the progress bar for a change in requested extent or canvas size
2688 proc adjustprogress {} {
2689 global progresscanv progressitem progresscoords
2690 global fprogitem fprogcoord lastprogupdate progupdatepending
2691 global rprogitem rprogcoord use_ttk
2694 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2698 set w [expr {[winfo width $progresscanv] - 4}]
2699 set x0 [expr {$w * [lindex $progresscoords 0]}]
2700 set x1 [expr {$w * [lindex $progresscoords 1]}]
2701 set h [winfo height $progresscanv]
2702 $progresscanv coords $progressitem $x0 0 $x1 $h
2703 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2704 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2705 set now [clock clicks -milliseconds]
2706 if {$now >= $lastprogupdate + 100} {
2707 set progupdatepending 0
2709 } elseif {!$progupdatepending} {
2710 set progupdatepending 1
2711 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2715 proc doprogupdate {} {
2716 global lastprogupdate progupdatepending
2718 if {$progupdatepending} {
2719 set progupdatepending 0
2720 set lastprogupdate [clock clicks -milliseconds]
2725 proc savestuff {w} {
2726 global canv canv2 canv3 mainfont textfont uifont tabstop
2727 global stuffsaved findmergefiles maxgraphpct
2728 global maxwidth showneartags showlocalchanges
2729 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2730 global cmitmode wrapcomment datetimeformat limitdiffs
2731 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2732 global uifgcolor uifgdisabledcolor
2733 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2734 global tagbgcolor tagfgcolor tagoutlinecolor
2735 global reflinecolor filesepbgcolor filesepfgcolor
2736 global mergecolors foundbgcolor currentsearchhitbgcolor
2737 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2738 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2739 global linkfgcolor circleoutlinecolor
2740 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2741 global hideremotes want_ttk maxrefs
2743 if {$stuffsaved} return
2744 if {![winfo viewable .]} return
2746 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2747 set f [open "~/.gitk-new" w]
2748 if {$::tcl_platform(platform) eq {windows}} {
2749 file attributes "~/.gitk-new" -hidden true
2751 puts $f [list set mainfont $mainfont]
2752 puts $f [list set textfont $textfont]
2753 puts $f [list set uifont $uifont]
2754 puts $f [list set tabstop $tabstop]
2755 puts $f [list set findmergefiles $findmergefiles]
2756 puts $f [list set maxgraphpct $maxgraphpct]
2757 puts $f [list set maxwidth $maxwidth]
2758 puts $f [list set cmitmode $cmitmode]
2759 puts $f [list set wrapcomment $wrapcomment]
2760 puts $f [list set autoselect $autoselect]
2761 puts $f [list set autosellen $autosellen]
2762 puts $f [list set showneartags $showneartags]
2763 puts $f [list set maxrefs $maxrefs]
2764 puts $f [list set hideremotes $hideremotes]
2765 puts $f [list set showlocalchanges $showlocalchanges]
2766 puts $f [list set datetimeformat $datetimeformat]
2767 puts $f [list set limitdiffs $limitdiffs]
2768 puts $f [list set uicolor $uicolor]
2769 puts $f [list set want_ttk $want_ttk]
2770 puts $f [list set bgcolor $bgcolor]
2771 puts $f [list set fgcolor $fgcolor]
2772 puts $f [list set uifgcolor $uifgcolor]
2773 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2774 puts $f [list set colors $colors]
2775 puts $f [list set diffcolors $diffcolors]
2776 puts $f [list set mergecolors $mergecolors]
2777 puts $f [list set markbgcolor $markbgcolor]
2778 puts $f [list set diffcontext $diffcontext]
2779 puts $f [list set selectbgcolor $selectbgcolor]
2780 puts $f [list set foundbgcolor $foundbgcolor]
2781 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2782 puts $f [list set extdifftool $extdifftool]
2783 puts $f [list set perfile_attrs $perfile_attrs]
2784 puts $f [list set headbgcolor $headbgcolor]
2785 puts $f [list set headfgcolor $headfgcolor]
2786 puts $f [list set headoutlinecolor $headoutlinecolor]
2787 puts $f [list set remotebgcolor $remotebgcolor]
2788 puts $f [list set tagbgcolor $tagbgcolor]
2789 puts $f [list set tagfgcolor $tagfgcolor]
2790 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2791 puts $f [list set reflinecolor $reflinecolor]
2792 puts $f [list set filesepbgcolor $filesepbgcolor]
2793 puts $f [list set filesepfgcolor $filesepfgcolor]
2794 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2795 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2796 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2797 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2798 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2799 puts $f [list set indexcirclecolor $indexcirclecolor]
2800 puts $f [list set circlecolors $circlecolors]
2801 puts $f [list set linkfgcolor $linkfgcolor]
2802 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2804 puts $f "set geometry(main) [wm geometry .]"
2805 puts $f "set geometry(state) [wm state .]"
2806 puts $f "set geometry(topwidth) [winfo width .tf]"
2807 puts $f "set geometry(topheight) [winfo height .tf]"
2809 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2810 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2812 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2813 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2815 puts $f "set geometry(botwidth) [winfo width .bleft]"
2816 puts $f "set geometry(botheight) [winfo height .bleft]"
2818 puts -nonewline $f "set permviews {"
2819 for {set v 0} {$v < $nextviewnum} {incr v} {
2820 if {$viewperm($v)} {
2821 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2826 file rename -force "~/.gitk-new" "~/.gitk"
2831 proc resizeclistpanes {win w} {
2832 global oldwidth use_ttk
2833 if {[info exists oldwidth($win)]} {
2835 set s0 [$win sashpos 0]
2836 set s1 [$win sashpos 1]
2838 set s0 [$win sash coord 0]
2839 set s1 [$win sash coord 1]
2842 set sash0 [expr {int($w/2 - 2)}]
2843 set sash1 [expr {int($w*5/6 - 2)}]
2845 set factor [expr {1.0 * $w / $oldwidth($win)}]
2846 set sash0 [expr {int($factor * [lindex $s0 0])}]
2847 set sash1 [expr {int($factor * [lindex $s1 0])}]
2851 if {$sash1 < $sash0 + 20} {
2852 set sash1 [expr {$sash0 + 20}]
2854 if {$sash1 > $w - 10} {
2855 set sash1 [expr {$w - 10}]
2856 if {$sash0 > $sash1 - 20} {
2857 set sash0 [expr {$sash1 - 20}]
2862 $win sashpos 0 $sash0
2863 $win sashpos 1 $sash1
2865 $win sash place 0 $sash0 [lindex $s0 1]
2866 $win sash place 1 $sash1 [lindex $s1 1]
2869 set oldwidth($win) $w
2872 proc resizecdetpanes {win w} {
2873 global oldwidth use_ttk
2874 if {[info exists oldwidth($win)]} {
2876 set s0 [$win sashpos 0]
2878 set s0 [$win sash coord 0]
2881 set sash0 [expr {int($w*3/4 - 2)}]
2883 set factor [expr {1.0 * $w / $oldwidth($win)}]
2884 set sash0 [expr {int($factor * [lindex $s0 0])}]
2888 if {$sash0 > $w - 15} {
2889 set sash0 [expr {$w - 15}]
2893 $win sashpos 0 $sash0
2895 $win sash place 0 $sash0 [lindex $s0 1]
2898 set oldwidth($win) $w
2901 proc allcanvs args {
2902 global canv canv2 canv3
2908 proc bindall {event action} {
2909 global canv canv2 canv3
2910 bind $canv $event $action
2911 bind $canv2 $event $action
2912 bind $canv3 $event $action
2918 if {[winfo exists $w]} {
2923 wm title $w [mc "About gitk"]
2925 message $w.m -text [mc "
2926 Gitk - a commit viewer for git
2928 Copyright \u00a9 2005-2011 Paul Mackerras
2930 Use and redistribute under the terms of the GNU General Public License"] \
2931 -justify center -aspect 400 -border 2 -bg white -relief groove
2932 pack $w.m -side top -fill x -padx 2 -pady 2
2933 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2934 pack $w.ok -side bottom
2935 bind $w <Visibility> "focus $w.ok"
2936 bind $w <Key-Escape> "destroy $w"
2937 bind $w <Key-Return> "destroy $w"
2938 tk::PlaceWindow $w widget .
2944 if {[winfo exists $w]} {
2948 if {[tk windowingsystem] eq {aqua}} {
2954 wm title $w [mc "Gitk key bindings"]
2956 message $w.m -text "
2957 [mc "Gitk key bindings:"]
2959 [mc "<%s-Q> Quit" $M1T]
2960 [mc "<%s-W> Close window" $M1T]
2961 [mc "<Home> Move to first commit"]
2962 [mc "<End> Move to last commit"]
2963 [mc "<Up>, p, k Move up one commit"]
2964 [mc "<Down>, n, j Move down one commit"]
2965 [mc "<Left>, z, h Go back in history list"]
2966 [mc "<Right>, x, l Go forward in history list"]
2967 [mc "<PageUp> Move up one page in commit list"]
2968 [mc "<PageDown> Move down one page in commit list"]
2969 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2970 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2971 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2972 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2973 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2974 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2975 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2976 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2977 [mc "<Delete>, b Scroll diff view up one page"]
2978 [mc "<Backspace> Scroll diff view up one page"]
2979 [mc "<Space> Scroll diff view down one page"]
2980 [mc "u Scroll diff view up 18 lines"]
2981 [mc "d Scroll diff view down 18 lines"]
2982 [mc "<%s-F> Find" $M1T]
2983 [mc "<%s-G> Move to next find hit" $M1T]
2984 [mc "<Return> Move to next find hit"]
2985 [mc "/ Focus the search box"]
2986 [mc "? Move to previous find hit"]
2987 [mc "f Scroll diff view to next file"]
2988 [mc "<%s-S> Search for next hit in diff view" $M1T]
2989 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2990 [mc "<%s-KP+> Increase font size" $M1T]
2991 [mc "<%s-plus> Increase font size" $M1T]
2992 [mc "<%s-KP-> Decrease font size" $M1T]
2993 [mc "<%s-minus> Decrease font size" $M1T]
2996 -justify left -bg white -border 2 -relief groove
2997 pack $w.m -side top -fill both -padx 2 -pady 2
2998 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2999 bind $w <Key-Escape> [list destroy $w]
3000 pack $w.ok -side bottom
3001 bind $w <Visibility> "focus $w.ok"
3002 bind $w <Key-Escape> "destroy $w"
3003 bind $w <Key-Return> "destroy $w"
3006 # Procedures for manipulating the file list window at the
3007 # bottom right of the overall window.
3009 proc treeview {w l openlevs} {
3010 global treecontents treediropen treeheight treeparent treeindex
3020 set treecontents() {}
3021 $w conf -state normal
3023 while {[string range $f 0 $prefixend] ne $prefix} {
3024 if {$lev <= $openlevs} {
3025 $w mark set e:$treeindex($prefix) "end -1c"
3026 $w mark gravity e:$treeindex($prefix) left
3028 set treeheight($prefix) $ht
3029 incr ht [lindex $htstack end]
3030 set htstack [lreplace $htstack end end]
3031 set prefixend [lindex $prefendstack end]
3032 set prefendstack [lreplace $prefendstack end end]
3033 set prefix [string range $prefix 0 $prefixend]
3036 set tail [string range $f [expr {$prefixend+1}] end]
3037 while {[set slash [string first "/" $tail]] >= 0} {
3040 lappend prefendstack $prefixend
3041 incr prefixend [expr {$slash + 1}]
3042 set d [string range $tail 0 $slash]
3043 lappend treecontents($prefix) $d
3044 set oldprefix $prefix
3046 set treecontents($prefix) {}
3047 set treeindex($prefix) [incr ix]
3048 set treeparent($prefix) $oldprefix
3049 set tail [string range $tail [expr {$slash+1}] end]
3050 if {$lev <= $openlevs} {
3052 set treediropen($prefix) [expr {$lev < $openlevs}]
3053 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3054 $w mark set d:$ix "end -1c"
3055 $w mark gravity d:$ix left
3057 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3059 $w image create end -align center -image $bm -padx 1 \
3061 $w insert end $d [highlight_tag $prefix]
3062 $w mark set s:$ix "end -1c"
3063 $w mark gravity s:$ix left
3068 if {$lev <= $openlevs} {
3071 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3073 $w insert end $tail [highlight_tag $f]
3075 lappend treecontents($prefix) $tail
3078 while {$htstack ne {}} {
3079 set treeheight($prefix) $ht
3080 incr ht [lindex $htstack end]
3081 set htstack [lreplace $htstack end end]
3082 set prefixend [lindex $prefendstack end]
3083 set prefendstack [lreplace $prefendstack end end]
3084 set prefix [string range $prefix 0 $prefixend]
3086 $w conf -state disabled
3089 proc linetoelt {l} {
3090 global treeheight treecontents
3095 foreach e $treecontents($prefix) {
3100 if {[string index $e end] eq "/"} {
3101 set n $treeheight($prefix$e)
3113 proc highlight_tree {y prefix} {
3114 global treeheight treecontents cflist
3116 foreach e $treecontents($prefix) {
3118 if {[highlight_tag $path] ne {}} {
3119 $cflist tag add bold $y.0 "$y.0 lineend"
3122 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3123 set y [highlight_tree $y $path]
3129 proc treeclosedir {w dir} {
3130 global treediropen treeheight treeparent treeindex
3132 set ix $treeindex($dir)
3133 $w conf -state normal
3134 $w delete s:$ix e:$ix
3135 set treediropen($dir) 0
3136 $w image configure a:$ix -image tri-rt
3137 $w conf -state disabled
3138 set n [expr {1 - $treeheight($dir)}]
3139 while {$dir ne {}} {
3140 incr treeheight($dir) $n
3141 set dir $treeparent($dir)
3145 proc treeopendir {w dir} {
3146 global treediropen treeheight treeparent treecontents treeindex
3148 set ix $treeindex($dir)
3149 $w conf -state normal
3150 $w image configure a:$ix -image tri-dn
3151 $w mark set e:$ix s:$ix
3152 $w mark gravity e:$ix right
3155 set n [llength $treecontents($dir)]
3156 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3159 incr treeheight($x) $n
3161 foreach e $treecontents($dir) {
3163 if {[string index $e end] eq "/"} {
3164 set iy $treeindex($de)
3165 $w mark set d:$iy e:$ix
3166 $w mark gravity d:$iy left
3167 $w insert e:$ix $str
3168 set treediropen($de) 0
3169 $w image create e:$ix -align center -image tri-rt -padx 1 \
3171 $w insert e:$ix $e [highlight_tag $de]
3172 $w mark set s:$iy e:$ix
3173 $w mark gravity s:$iy left
3174 set treeheight($de) 1
3176 $w insert e:$ix $str
3177 $w insert e:$ix $e [highlight_tag $de]
3180 $w mark gravity e:$ix right
3181 $w conf -state disabled
3182 set treediropen($dir) 1
3183 set top [lindex [split [$w index @0,0] .] 0]
3184 set ht [$w cget -height]
3185 set l [lindex [split [$w index s:$ix] .] 0]
3188 } elseif {$l + $n + 1 > $top + $ht} {
3189 set top [expr {$l + $n + 2 - $ht}]
3197 proc treeclick {w x y} {
3198 global treediropen cmitmode ctext cflist cflist_top
3200 if {$cmitmode ne "tree"} return
3201 if {![info exists cflist_top]} return
3202 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3203 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3204 $cflist tag add highlight $l.0 "$l.0 lineend"
3210 set e [linetoelt $l]
3211 if {[string index $e end] ne "/"} {
3213 } elseif {$treediropen($e)} {
3220 proc setfilelist {id} {
3221 global treefilelist cflist jump_to_here
3223 treeview $cflist $treefilelist($id) 0
3224 if {$jump_to_here ne {}} {
3225 set f [lindex $jump_to_here 0]
3226 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3232 image create bitmap tri-rt -background black -foreground blue -data {
3233 #define tri-rt_width 13
3234 #define tri-rt_height 13
3235 static unsigned char tri-rt_bits[] = {
3236 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3237 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3240 #define tri-rt-mask_width 13
3241 #define tri-rt-mask_height 13
3242 static unsigned char tri-rt-mask_bits[] = {
3243 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3244 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3247 image create bitmap tri-dn -background black -foreground blue -data {
3248 #define tri-dn_width 13
3249 #define tri-dn_height 13
3250 static unsigned char tri-dn_bits[] = {
3251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3252 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3255 #define tri-dn-mask_width 13
3256 #define tri-dn-mask_height 13
3257 static unsigned char tri-dn-mask_bits[] = {
3258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3259 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3263 image create bitmap reficon-T -background black -foreground yellow -data {
3264 #define tagicon_width 13
3265 #define tagicon_height 9
3266 static unsigned char tagicon_bits[] = {
3267 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3268 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3270 #define tagicon-mask_width 13
3271 #define tagicon-mask_height 9
3272 static unsigned char tagicon-mask_bits[] = {
3273 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3274 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3277 #define headicon_width 13
3278 #define headicon_height 9
3279 static unsigned char headicon_bits[] = {
3280 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3281 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3284 #define headicon-mask_width 13
3285 #define headicon-mask_height 9
3286 static unsigned char headicon-mask_bits[] = {
3287 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3288 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3290 image create bitmap reficon-H -background black -foreground green \
3291 -data $rectdata -maskdata $rectmask
3292 image create bitmap reficon-o -background black -foreground "#ddddff" \
3293 -data $rectdata -maskdata $rectmask
3295 proc init_flist {first} {
3296 global cflist cflist_top difffilestart
3298 $cflist conf -state normal
3299 $cflist delete 0.0 end
3301 $cflist insert end $first
3303 $cflist tag add highlight 1.0 "1.0 lineend"
3305 catch {unset cflist_top}
3307 $cflist conf -state disabled
3308 set difffilestart {}
3311 proc highlight_tag {f} {
3312 global highlight_paths
3314 foreach p $highlight_paths {
3315 if {[string match $p $f]} {
3322 proc highlight_filelist {} {
3323 global cmitmode cflist
3325 $cflist conf -state normal
3326 if {$cmitmode ne "tree"} {
3327 set end [lindex [split [$cflist index end] .] 0]
3328 for {set l 2} {$l < $end} {incr l} {
3329 set line [$cflist get $l.0 "$l.0 lineend"]
3330 if {[highlight_tag $line] ne {}} {
3331 $cflist tag add bold $l.0 "$l.0 lineend"
3337 $cflist conf -state disabled
3340 proc unhighlight_filelist {} {
3343 $cflist conf -state normal
3344 $cflist tag remove bold 1.0 end
3345 $cflist conf -state disabled
3348 proc add_flist {fl} {
3351 $cflist conf -state normal
3353 $cflist insert end "\n"
3354 $cflist insert end $f [highlight_tag $f]
3356 $cflist conf -state disabled
3359 proc sel_flist {w x y} {
3360 global ctext difffilestart cflist cflist_top cmitmode
3362 if {$cmitmode eq "tree"} return
3363 if {![info exists cflist_top]} return
3364 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3365 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3366 $cflist tag add highlight $l.0 "$l.0 lineend"
3371 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3373 suppress_highlighting_file_for_current_scrollpos
3376 proc pop_flist_menu {w X Y x y} {
3377 global ctext cflist cmitmode flist_menu flist_menu_file
3378 global treediffs diffids
3381 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3383 if {$cmitmode eq "tree"} {
3384 set e [linetoelt $l]
3385 if {[string index $e end] eq "/"} return
3387 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3389 set flist_menu_file $e
3390 set xdiffstate "normal"
3391 if {$cmitmode eq "tree"} {
3392 set xdiffstate "disabled"
3394 # Disable "External diff" item in tree mode
3395 $flist_menu entryconf 2 -state $xdiffstate
3396 tk_popup $flist_menu $X $Y
3399 proc find_ctext_fileinfo {line} {
3400 global ctext_file_names ctext_file_lines
3402 set ok [bsearch $ctext_file_lines $line]
3403 set tline [lindex $ctext_file_lines $ok]
3405 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3408 return [list [lindex $ctext_file_names $ok] $tline]
3412 proc pop_diff_menu {w X Y x y} {
3413 global ctext diff_menu flist_menu_file
3414 global diff_menu_txtpos diff_menu_line
3415 global diff_menu_filebase
3417 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3418 set diff_menu_line [lindex $diff_menu_txtpos 0]
3419 # don't pop up the menu on hunk-separator or file-separator lines
3420 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3424 set f [find_ctext_fileinfo $diff_menu_line]
3425 if {$f eq {}} return
3426 set flist_menu_file [lindex $f 0]
3427 set diff_menu_filebase [lindex $f 1]
3428 tk_popup $diff_menu $X $Y
3431 proc flist_hl {only} {
3432 global flist_menu_file findstring gdttype
3434 set x [shellquote $flist_menu_file]
3435 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3438 append findstring " " $x
3440 set gdttype [mc "touching paths:"]
3443 proc gitknewtmpdir {} {
3444 global diffnum gitktmpdir gitdir
3446 if {![info exists gitktmpdir]} {
3447 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3448 if {[catch {file mkdir $gitktmpdir} err]} {
3449 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3456 set diffdir [file join $gitktmpdir $diffnum]
3457 if {[catch {file mkdir $diffdir} err]} {
3458 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3464 proc save_file_from_commit {filename output what} {
3467 if {[catch {exec git show $filename -- > $output} err]} {
3468 if {[string match "fatal: bad revision *" $err]} {
3471 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3477 proc external_diff_get_one_file {diffid filename diffdir} {
3478 global nullid nullid2 nullfile
3481 if {$diffid == $nullid} {
3482 set difffile [file join $worktree $filename]
3483 if {[file exists $difffile]} {
3488 if {$diffid == $nullid2} {
3489 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3490 return [save_file_from_commit :$filename $difffile index]
3492 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3493 return [save_file_from_commit $diffid:$filename $difffile \
3497 proc external_diff {} {
3498 global nullid nullid2
3499 global flist_menu_file
3503 if {[llength $diffids] == 1} {
3504 # no reference commit given
3505 set diffidto [lindex $diffids 0]
3506 if {$diffidto eq $nullid} {
3507 # diffing working copy with index
3508 set diffidfrom $nullid2
3509 } elseif {$diffidto eq $nullid2} {
3510 # diffing index with HEAD
3511 set diffidfrom "HEAD"
3513 # use first parent commit
3514 global parentlist selectedline
3515 set diffidfrom [lindex $parentlist $selectedline 0]
3518 set diffidfrom [lindex $diffids 0]
3519 set diffidto [lindex $diffids 1]
3522 # make sure that several diffs wont collide
3523 set diffdir [gitknewtmpdir]
3524 if {$diffdir eq {}} return
3526 # gather files to diff
3527 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3528 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3530 if {$difffromfile ne {} && $difftofile ne {}} {
3531 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3532 if {[catch {set fl [open |$cmd r]} err]} {
3533 file delete -force $diffdir
3534 error_popup "$extdifftool: [mc "command failed:"] $err"
3536 fconfigure $fl -blocking 0
3537 filerun $fl [list delete_at_eof $fl $diffdir]
3542 proc find_hunk_blamespec {base line} {
3545 # Find and parse the hunk header
3546 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3547 if {$s_lix eq {}} return
3549 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3550 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3551 s_line old_specs osz osz1 new_line nsz]} {
3555 # base lines for the parents
3556 set base_lines [list $new_line]
3557 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3558 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3559 old_spec old_line osz]} {
3562 lappend base_lines $old_line
3565 # Now scan the lines to determine offset within the hunk
3566 set max_parent [expr {[llength $base_lines]-2}]
3568 set s_lno [lindex [split $s_lix "."] 0]
3570 # Determine if the line is removed
3571 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3572 if {[string match {[-+ ]*} $chunk]} {
3573 set removed_idx [string first "-" $chunk]
3574 # Choose a parent index
3575 if {$removed_idx >= 0} {
3576 set parent $removed_idx
3578 set unchanged_idx [string first " " $chunk]
3579 if {$unchanged_idx >= 0} {
3580 set parent $unchanged_idx
3582 # blame the current commit
3586 # then count other lines that belong to it
3587 for {set i $line} {[incr i -1] > $s_lno} {} {
3588 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3589 # Determine if the line is removed
3590 set removed_idx [string first "-" $chunk]
3592 set code [string index $chunk $parent]
3593 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3597 if {$removed_idx < 0} {
3607 incr dline [lindex $base_lines $parent]
3608 return [list $parent $dline]
3611 proc external_blame_diff {} {
3612 global currentid cmitmode
3613 global diff_menu_txtpos diff_menu_line
3614 global diff_menu_filebase flist_menu_file
3616 if {$cmitmode eq "tree"} {
3618 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3620 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3622 set parent_idx [lindex $hinfo 0]
3623 set line [lindex $hinfo 1]
3630 external_blame $parent_idx $line
3633 # Find the SHA1 ID of the blob for file $fname in the index
3635 proc index_sha1 {fname} {
3636 set f [open [list | git ls-files -s $fname] r]
3637 while {[gets $f line] >= 0} {
3638 set info [lindex [split $line "\t"] 0]
3639 set stage [lindex $info 2]
3640 if {$stage eq "0" || $stage eq "2"} {
3642 return [lindex $info 1]
3649 # Turn an absolute path into one relative to the current directory
3650 proc make_relative {f} {
3651 if {[file pathtype $f] eq "relative"} {
3654 set elts [file split $f]
3655 set here [file split [pwd]]
3660 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3667 set elts [concat $res [lrange $elts $ei end]]
3668 return [eval file join $elts]
3671 proc external_blame {parent_idx {line {}}} {
3672 global flist_menu_file cdup
3673 global nullid nullid2
3674 global parentlist selectedline currentid
3676 if {$parent_idx > 0} {
3677 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3679 set base_commit $currentid
3682 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3683 error_popup [mc "No such commit"]
3687 set cmdline [list git gui blame]
3688 if {$line ne {} && $line > 1} {
3689 lappend cmdline "--line=$line"
3691 set f [file join $cdup $flist_menu_file]
3692 # Unfortunately it seems git gui blame doesn't like
3693 # being given an absolute path...
3694 set f [make_relative $f]
3695 lappend cmdline $base_commit $f
3696 if {[catch {eval exec $cmdline &} err]} {
3697 error_popup "[mc "git gui blame: command failed:"] $err"
3701 proc show_line_source {} {
3702 global cmitmode currentid parents curview blamestuff blameinst
3703 global diff_menu_line diff_menu_filebase flist_menu_file
3704 global nullid nullid2 gitdir cdup
3707 if {$cmitmode eq "tree"} {
3709 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3711 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3712 if {$h eq {}} return
3713 set pi [lindex $h 0]
3715 mark_ctext_line $diff_menu_line
3719 if {$currentid eq $nullid} {
3721 # must be a merge in progress...
3723 # get the last line from .git/MERGE_HEAD
3724 set f [open [file join $gitdir MERGE_HEAD] r]
3725 set id [lindex [split [read $f] "\n"] end-1]
3728 error_popup [mc "Couldn't read merge head: %s" $err]
3731 } elseif {$parents($curview,$currentid) eq $nullid2} {
3732 # need to do the blame from the index
3734 set from_index [index_sha1 $flist_menu_file]
3736 error_popup [mc "Error reading index: %s" $err]
3740 set id $parents($curview,$currentid)
3743 set id [lindex $parents($curview,$currentid) $pi]
3745 set line [lindex $h 1]
3748 if {$from_index ne {}} {
3749 lappend blameargs | git cat-file blob $from_index
3751 lappend blameargs | git blame -p -L$line,+1
3752 if {$from_index ne {}} {
3753 lappend blameargs --contents -
3755 lappend blameargs $id
3757 lappend blameargs -- [file join $cdup $flist_menu_file]
3759 set f [open $blameargs r]
3761 error_popup [mc "Couldn't start git blame: %s" $err]
3764 nowbusy blaming [mc "Searching"]
3765 fconfigure $f -blocking 0
3766 set i [reg_instance $f]
3767 set blamestuff($i) {}
3769 filerun $f [list read_line_source $f $i]
3772 proc stopblaming {} {
3775 if {[info exists blameinst]} {
3776 stop_instance $blameinst
3782 proc read_line_source {fd inst} {
3783 global blamestuff curview commfd blameinst nullid nullid2
3785 while {[gets $fd line] >= 0} {
3786 lappend blamestuff($inst) $line
3794 fconfigure $fd -blocking 1
3795 if {[catch {close $fd} err]} {
3796 error_popup [mc "Error running git blame: %s" $err]
3801 set line [split [lindex $blamestuff($inst) 0] " "]
3802 set id [lindex $line 0]
3803 set lnum [lindex $line 1]
3804 if {[string length $id] == 40 && [string is xdigit $id] &&
3805 [string is digit -strict $lnum]} {
3806 # look for "filename" line
3807 foreach l $blamestuff($inst) {
3808 if {[string match "filename *" $l]} {
3809 set fname [string range $l 9 end]
3815 # all looks good, select it
3816 if {$id eq $nullid} {
3817 # blame uses all-zeroes to mean not committed,
3818 # which would mean a change in the index
3821 if {[commitinview $id $curview]} {
3822 selectline [rowofcommit $id] 1 [list $fname $lnum]
3824 error_popup [mc "That line comes from commit %s, \
3825 which is not in this view" [shortids $id]]
3828 puts "oops couldn't parse git blame output"
3833 # delete $dir when we see eof on $f (presumably because the child has exited)
3834 proc delete_at_eof {f dir} {
3835 while {[gets $f line] >= 0} {}
3837 if {[catch {close $f} err]} {
3838 error_popup "[mc "External diff viewer failed:"] $err"
3840 file delete -force $dir
3846 # Functions for adding and removing shell-type quoting
3848 proc shellquote {str} {
3849 if {![string match "*\['\"\\ \t]*" $str]} {
3852 if {![string match "*\['\"\\]*" $str]} {
3855 if {![string match "*'*" $str]} {
3858 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3861 proc shellarglist {l} {
3867 append str [shellquote $a]
3872 proc shelldequote {str} {
3877 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3878 append ret [string range $str $used end]
3879 set used [string length $str]
3882 set first [lindex $first 0]
3883 set ch [string index $str $first]
3884 if {$first > $used} {
3885 append ret [string range $str $used [expr {$first - 1}]]
3888 if {$ch eq " " || $ch eq "\t"} break
3891 set first [string first "'" $str $used]
3893 error "unmatched single-quote"
3895 append ret [string range $str $used [expr {$first - 1}]]
3900 if {$used >= [string length $str]} {
3901 error "trailing backslash"
3903 append ret [string index $str $used]
3908 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3909 error "unmatched double-quote"
3911 set first [lindex $first 0]
3912 set ch [string index $str $first]
3913 if {$first > $used} {
3914 append ret [string range $str $used [expr {$first - 1}]]
3917 if {$ch eq "\""} break
3919 append ret [string index $str $used]
3923 return [list $used $ret]
3926 proc shellsplit {str} {
3929 set str [string trimleft $str]
3930 if {$str eq {}} break
3931 set dq [shelldequote $str]
3932 set n [lindex $dq 0]
3933 set word [lindex $dq 1]
3934 set str [string range $str $n end]
3940 # Code to implement multiple views
3942 proc newview {ishighlight} {
3943 global nextviewnum newviewname newishighlight
3944 global revtreeargs viewargscmd newviewopts curview
3946 set newishighlight $ishighlight
3948 if {[winfo exists $top]} {
3952 decode_view_opts $nextviewnum $revtreeargs
3953 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3954 set newviewopts($nextviewnum,perm) 0
3955 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3956 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3959 set known_view_options {
3960 {perm b . {} {mc "Remember this view"}}
3961 {reflabel l + {} {mc "References (space separated list):"}}
3962 {refs t15 .. {} {mc "Branches & tags:"}}
3963 {allrefs b *. "--all" {mc "All refs"}}
3964 {branches b . "--branches" {mc "All (local) branches"}}
3965 {tags b . "--tags" {mc "All tags"}}
3966 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3967 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3968 {author t15 .. "--author=*" {mc "Author:"}}
3969 {committer t15 . "--committer=*" {mc "Committer:"}}
3970 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3971 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3972 {changes_l l + {} {mc "Changes to Files:"}}
3973 {pickaxe_s r0 . {} {mc "Fixed String"}}
3974 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3975 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3976 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3977 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3978 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3979 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3980 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3981 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3982 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3983 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3984 {lright b . "--left-right" {mc "Mark branch sides"}}
3985 {first b . "--first-parent" {mc "Limit to first parent"}}
3986 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3987 {args t50 *. {} {mc "Additional arguments to git log:"}}
3988 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3989 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3992 # Convert $newviewopts($n, ...) into args for git log.
3993 proc encode_view_opts {n} {
3994 global known_view_options newviewopts
3997 foreach opt $known_view_options {
3998 set patterns [lindex $opt 3]
3999 if {$patterns eq {}} continue
4000 set pattern [lindex $patterns 0]
4002 if {[lindex $opt 1] eq "b"} {
4003 set val $newviewopts($n,[lindex $opt 0])
4005 lappend rargs $pattern
4007 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4008 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4009 set val $newviewopts($n,$button_id)
4010 if {$val eq $value} {
4011 lappend rargs $pattern
4014 set val $newviewopts($n,[lindex $opt 0])
4015 set val [string trim $val]
4017 set pfix [string range $pattern 0 end-1]
4018 lappend rargs $pfix$val
4022 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4023 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4026 # Fill $newviewopts($n, ...) based on args for git log.
4027 proc decode_view_opts {n view_args} {
4028 global known_view_options newviewopts
4030 foreach opt $known_view_options {
4031 set id [lindex $opt 0]
4032 if {[lindex $opt 1] eq "b"} {
4035 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4037 regexp {^(.*_)} $id uselessvar id
4043 set newviewopts($n,$id) $val
4047 foreach arg $view_args {
4048 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4049 && ![info exists found(limit)]} {
4050 set newviewopts($n,limit) $cnt
4055 foreach opt $known_view_options {
4056 set id [lindex $opt 0]
4057 if {[info exists found($id)]} continue
4058 foreach pattern [lindex $opt 3] {
4059 if {![string match $pattern $arg]} continue
4060 if {[lindex $opt 1] eq "b"} {
4063 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4065 regexp {^(.*_)} $id uselessvar id
4069 set size [string length $pattern]
4070 set val [string range $arg [expr {$size-1}] end]
4072 set newviewopts($n,$id) $val
4076 if {[info exists val]} break
4078 if {[info exists val]} continue
4079 if {[regexp {^-} $arg]} {
4082 lappend refargs $arg
4085 set newviewopts($n,refs) [shellarglist $refargs]
4086 set newviewopts($n,args) [shellarglist $oargs]
4089 proc edit_or_newview {} {
4101 global viewname viewperm newviewname newviewopts
4102 global viewargs viewargscmd
4104 set top .gitkvedit-$curview
4105 if {[winfo exists $top]} {
4109 decode_view_opts $curview $viewargs($curview)
4110 set newviewname($curview) $viewname($curview)
4111 set newviewopts($curview,perm) $viewperm($curview)
4112 set newviewopts($curview,cmd) $viewargscmd($curview)
4113 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4116 proc vieweditor {top n title} {
4117 global newviewname newviewopts viewfiles bgcolor
4118 global known_view_options NS
4121 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4122 make_transient $top .
4125 ${NS}::frame $top.nfr
4126 ${NS}::label $top.nl -text [mc "View Name"]
4127 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4128 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4129 pack $top.nl -in $top.nfr -side left -padx {0 5}
4130 pack $top.name -in $top.nfr -side left -padx {0 25}
4136 foreach opt $known_view_options {
4137 set id [lindex $opt 0]
4138 set type [lindex $opt 1]
4139 set flags [lindex $opt 2]
4140 set title [eval [lindex $opt 4]]
4143 if {$flags eq "+" || $flags eq "*"} {
4144 set cframe $top.fr$cnt
4146 ${NS}::frame $cframe
4147 pack $cframe -in $top -fill x -pady 3 -padx 3
4148 set cexpand [expr {$flags eq "*"}]
4149 } elseif {$flags eq ".." || $flags eq "*."} {
4150 set cframe $top.fr$cnt
4152 ${NS}::frame $cframe
4153 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4154 set cexpand [expr {$flags eq "*."}]
4160 ${NS}::label $cframe.l_$id -text $title
4161 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4162 } elseif {$type eq "b"} {
4163 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4164 pack $cframe.c_$id -in $cframe -side left \
4165 -padx [list $lxpad 0] -expand $cexpand -anchor w
4166 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4167 regexp {^(.*_)} $id uselessvar button_id
4168 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4169 pack $cframe.c_$id -in $cframe -side left \
4170 -padx [list $lxpad 0] -expand $cexpand -anchor w
4171 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4172 ${NS}::label $cframe.l_$id -text $title
4173 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4174 -textvariable newviewopts($n,$id)
4175 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4176 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4177 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4178 ${NS}::label $cframe.l_$id -text $title
4179 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4180 -textvariable newviewopts($n,$id)
4181 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4182 pack $cframe.e_$id -in $cframe -side top -fill x
4183 } elseif {$type eq "path"} {
4184 ${NS}::label $top.l -text $title
4185 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4186 text $top.t -width 40 -height 5 -background $bgcolor
4187 if {[info exists viewfiles($n)]} {
4188 foreach f $viewfiles($n) {
4189 $top.t insert end $f
4190 $top.t insert end "\n"
4192 $top.t delete {end - 1c} end
4193 $top.t mark set insert 0.0
4195 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4199 ${NS}::frame $top.buts
4200 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4201 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4202 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4203 bind $top <Control-Return> [list newviewok $top $n]
4204 bind $top <F5> [list newviewok $top $n 1]
4205 bind $top <Escape> [list destroy $top]
4206 grid $top.buts.ok $top.buts.apply $top.buts.can
4207 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4208 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4209 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4210 pack $top.buts -in $top -side top -fill x
4214 proc doviewmenu {m first cmd op argv} {
4215 set nmenu [$m index end]
4216 for {set i $first} {$i <= $nmenu} {incr i} {
4217 if {[$m entrycget $i -command] eq $cmd} {
4218 eval $m $op $i $argv
4224 proc allviewmenus {n op args} {
4227 doviewmenu .bar.view 5 [list showview $n] $op $args
4228 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4231 proc newviewok {top n {apply 0}} {
4232 global nextviewnum newviewperm newviewname newishighlight
4233 global viewname viewfiles viewperm selectedview curview
4234 global viewargs viewargscmd newviewopts viewhlmenu
4237 set newargs [encode_view_opts $n]
4239 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4243 foreach f [split [$top.t get 0.0 end] "\n"] {
4244 set ft [string trim $f]
4249 if {![info exists viewfiles($n)]} {
4250 # creating a new view
4252 set viewname($n) $newviewname($n)
4253 set viewperm($n) $newviewopts($n,perm)
4254 set viewfiles($n) $files
4255 set viewargs($n) $newargs
4256 set viewargscmd($n) $newviewopts($n,cmd)
4258 if {!$newishighlight} {
4261 run addvhighlight $n
4264 # editing an existing view
4265 set viewperm($n) $newviewopts($n,perm)
4266 if {$newviewname($n) ne $viewname($n)} {
4267 set viewname($n) $newviewname($n)
4268 doviewmenu .bar.view 5 [list showview $n] \
4269 entryconf [list -label $viewname($n)]
4270 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4271 # entryconf [list -label $viewname($n) -value $viewname($n)]
4273 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4274 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4275 set viewfiles($n) $files
4276 set viewargs($n) $newargs
4277 set viewargscmd($n) $newviewopts($n,cmd)
4278 if {$curview == $n} {
4284 catch {destroy $top}
4288 global curview viewperm hlview selectedhlview
4290 if {$curview == 0} return
4291 if {[info exists hlview] && $hlview == $curview} {
4292 set selectedhlview [mc "None"]
4295 allviewmenus $curview delete
4296 set viewperm($curview) 0
4300 proc addviewmenu {n} {
4301 global viewname viewhlmenu
4303 .bar.view add radiobutton -label $viewname($n) \
4304 -command [list showview $n] -variable selectedview -value $n
4305 #$viewhlmenu add radiobutton -label $viewname($n) \
4306 # -command [list addvhighlight $n] -variable selectedhlview
4310 global curview cached_commitrow ordertok
4311 global displayorder parentlist rowidlist rowisopt rowfinal
4312 global colormap rowtextx nextcolor canvxmax
4313 global numcommits viewcomplete
4314 global selectedline currentid canv canvy0
4316 global pending_select mainheadid
4319 global hlview selectedhlview commitinterest
4321 if {$n == $curview} return
4323 set ymax [lindex [$canv cget -scrollregion] 3]
4324 set span [$canv yview]
4325 set ytop [expr {[lindex $span 0] * $ymax}]
4326 set ybot [expr {[lindex $span 1] * $ymax}]
4327 set yscreen [expr {($ybot - $ytop) / 2}]
4328 if {$selectedline ne {}} {
4329 set selid $currentid
4330 set y [yc $selectedline]
4331 if {$ytop < $y && $y < $ybot} {
4332 set yscreen [expr {$y - $ytop}]
4334 } elseif {[info exists pending_select]} {
4335 set selid $pending_select
4336 unset pending_select
4340 catch {unset treediffs}
4342 if {[info exists hlview] && $hlview == $n} {
4344 set selectedhlview [mc "None"]
4346 catch {unset commitinterest}
4347 catch {unset cached_commitrow}
4348 catch {unset ordertok}
4352 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4353 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4356 if {![info exists viewcomplete($n)]} {
4366 set numcommits $commitidx($n)
4368 catch {unset colormap}
4369 catch {unset rowtextx}
4371 set canvxmax [$canv cget -width]
4377 if {$selid ne {} && [commitinview $selid $n]} {
4378 set row [rowofcommit $selid]
4379 # try to get the selected row in the same position on the screen
4380 set ymax [lindex [$canv cget -scrollregion] 3]
4381 set ytop [expr {[yc $row] - $yscreen}]
4385 set yf [expr {$ytop * 1.0 / $ymax}]
4387 allcanvs yview moveto $yf
4391 } elseif {!$viewcomplete($n)} {
4392 reset_pending_select $selid
4394 reset_pending_select {}
4396 if {[commitinview $pending_select $curview]} {
4397 selectline [rowofcommit $pending_select] 1
4399 set row [first_real_row]
4400 if {$row < $numcommits} {
4405 if {!$viewcomplete($n)} {
4406 if {$numcommits == 0} {
4407 show_status [mc "Reading commits..."]
4409 } elseif {$numcommits == 0} {
4410 show_status [mc "No commits selected"]
4414 # Stuff relating to the highlighting facility
4416 proc ishighlighted {id} {
4417 global vhighlights fhighlights nhighlights rhighlights
4419 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4420 return $nhighlights($id)
4422 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4423 return $vhighlights($id)
4425 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4426 return $fhighlights($id)
4428 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4429 return $rhighlights($id)
4434 proc bolden {id font} {
4435 global canv linehtag currentid boldids need_redisplay markedid
4437 # need_redisplay = 1 means the display is stale and about to be redrawn
4438 if {$need_redisplay} return
4440 $canv itemconf $linehtag($id) -font $font
4441 if {[info exists currentid] && $id eq $currentid} {
4443 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4444 -outline {{}} -tags secsel \
4445 -fill [$canv cget -selectbackground]]
4448 if {[info exists markedid] && $id eq $markedid} {
4453 proc bolden_name {id font} {
4454 global canv2 linentag currentid boldnameids need_redisplay
4456 if {$need_redisplay} return
4457 lappend boldnameids $id
4458 $canv2 itemconf $linentag($id) -font $font
4459 if {[info exists currentid] && $id eq $currentid} {
4460 $canv2 delete secsel
4461 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4462 -outline {{}} -tags secsel \
4463 -fill [$canv2 cget -selectbackground]]
4472 foreach id $boldids {
4473 if {![ishighlighted $id]} {
4476 lappend stillbold $id
4479 set boldids $stillbold
4482 proc addvhighlight {n} {
4483 global hlview viewcomplete curview vhl_done commitidx
4485 if {[info exists hlview]} {
4489 if {$n != $curview && ![info exists viewcomplete($n)]} {
4492 set vhl_done $commitidx($hlview)
4493 if {$vhl_done > 0} {
4498 proc delvhighlight {} {
4499 global hlview vhighlights
4501 if {![info exists hlview]} return
4503 catch {unset vhighlights}
4507 proc vhighlightmore {} {
4508 global hlview vhl_done commitidx vhighlights curview
4510 set max $commitidx($hlview)
4511 set vr [visiblerows]
4512 set r0 [lindex $vr 0]
4513 set r1 [lindex $vr 1]
4514 for {set i $vhl_done} {$i < $max} {incr i} {
4515 set id [commitonrow $i $hlview]
4516 if {[commitinview $id $curview]} {
4517 set row [rowofcommit $id]
4518 if {$r0 <= $row && $row <= $r1} {
4519 if {![highlighted $row]} {
4520 bolden $id mainfontbold
4522 set vhighlights($id) 1
4530 proc askvhighlight {row id} {
4531 global hlview vhighlights iddrawn
4533 if {[commitinview $id $hlview]} {
4534 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4535 bolden $id mainfontbold
4537 set vhighlights($id) 1
4539 set vhighlights($id) 0
4543 proc hfiles_change {} {
4544 global highlight_files filehighlight fhighlights fh_serial
4545 global highlight_paths
4547 if {[info exists filehighlight]} {
4548 # delete previous highlights
4549 catch {close $filehighlight}
4551 catch {unset fhighlights}
4553 unhighlight_filelist
4555 set highlight_paths {}
4556 after cancel do_file_hl $fh_serial
4558 if {$highlight_files ne {}} {
4559 after 300 do_file_hl $fh_serial
4563 proc gdttype_change {name ix op} {
4564 global gdttype highlight_files findstring findpattern
4567 if {$findstring ne {}} {
4568 if {$gdttype eq [mc "containing:"]} {
4569 if {$highlight_files ne {}} {
4570 set highlight_files {}
4575 if {$findpattern ne {}} {
4579 set highlight_files $findstring
4584 # enable/disable findtype/findloc menus too
4587 proc find_change {name ix op} {
4588 global gdttype findstring highlight_files
4591 if {$gdttype eq [mc "containing:"]} {
4594 if {$highlight_files ne $findstring} {
4595 set highlight_files $findstring
4602 proc findcom_change args {
4603 global nhighlights boldnameids
4604 global findpattern findtype findstring gdttype
4607 # delete previous highlights, if any
4608 foreach id $boldnameids {
4609 bolden_name $id mainfont
4612 catch {unset nhighlights}
4615 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4617 } elseif {$findtype eq [mc "Regexp"]} {
4618 set findpattern $findstring
4620 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4622 set findpattern "*$e*"
4626 proc makepatterns {l} {
4629 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4630 if {[string index $ee end] eq "/"} {
4640 proc do_file_hl {serial} {
4641 global highlight_files filehighlight highlight_paths gdttype fhl_list
4642 global cdup findtype
4644 if {$gdttype eq [mc "touching paths:"]} {
4645 # If "exact" match then convert backslashes to forward slashes.
4646 # Most useful to support Windows-flavoured file paths.
4647 if {$findtype eq [mc "Exact"]} {
4648 set highlight_files [string map {"\\" "/"} $highlight_files]
4650 if {[catch {set paths [shellsplit $highlight_files]}]} return
4651 set highlight_paths [makepatterns $paths]
4653 set relative_paths {}
4654 foreach path $paths {
4655 lappend relative_paths [file join $cdup $path]
4657 set gdtargs [concat -- $relative_paths]
4658 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4659 set gdtargs [list "-S$highlight_files"]
4661 # must be "containing:", i.e. we're searching commit info
4664 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4665 set filehighlight [open $cmd r+]
4666 fconfigure $filehighlight -blocking 0
4667 filerun $filehighlight readfhighlight
4673 proc flushhighlights {} {
4674 global filehighlight fhl_list
4676 if {[info exists filehighlight]} {
4678 puts $filehighlight ""
4679 flush $filehighlight
4683 proc askfilehighlight {row id} {
4684 global filehighlight fhighlights fhl_list
4686 lappend fhl_list $id
4687 set fhighlights($id) -1
4688 puts $filehighlight $id
4691 proc readfhighlight {} {
4692 global filehighlight fhighlights curview iddrawn
4693 global fhl_list find_dirn
4695 if {![info exists filehighlight]} {
4699 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4700 set line [string trim $line]
4701 set i [lsearch -exact $fhl_list $line]
4702 if {$i < 0} continue
4703 for {set j 0} {$j < $i} {incr j} {
4704 set id [lindex $fhl_list $j]
4705 set fhighlights($id) 0
4707 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4708 if {$line eq {}} continue
4709 if {![commitinview $line $curview]} continue
4710 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4711 bolden $line mainfontbold
4713 set fhighlights($line) 1
4715 if {[eof $filehighlight]} {
4717 puts "oops, git diff-tree died"
4718 catch {close $filehighlight}
4722 if {[info exists find_dirn]} {
4728 proc doesmatch {f} {
4729 global findtype findpattern
4731 if {$findtype eq [mc "Regexp"]} {
4732 return [regexp $findpattern $f]
4733 } elseif {$findtype eq [mc "IgnCase"]} {
4734 return [string match -nocase $findpattern $f]
4736 return [string match $findpattern $f]
4740 proc askfindhighlight {row id} {
4741 global nhighlights commitinfo iddrawn
4743 global markingmatches
4745 if {![info exists commitinfo($id)]} {
4748 set info $commitinfo($id)
4750 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4751 foreach f $info ty $fldtypes {
4752 if {$ty eq ""} continue
4753 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4755 if {$ty eq [mc "Author"]} {
4762 if {$isbold && [info exists iddrawn($id)]} {
4763 if {![ishighlighted $id]} {
4764 bolden $id mainfontbold
4766 bolden_name $id mainfontbold
4769 if {$markingmatches} {
4770 markrowmatches $row $id
4773 set nhighlights($id) $isbold
4776 proc markrowmatches {row id} {
4777 global canv canv2 linehtag linentag commitinfo findloc
4779 set headline [lindex $commitinfo($id) 0]
4780 set author [lindex $commitinfo($id) 1]
4781 $canv delete match$row
4782 $canv2 delete match$row
4783 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4784 set m [findmatches $headline]
4786 markmatches $canv $row $headline $linehtag($id) $m \
4787 [$canv itemcget $linehtag($id) -font] $row
4790 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4791 set m [findmatches $author]
4793 markmatches $canv2 $row $author $linentag($id) $m \
4794 [$canv2 itemcget $linentag($id) -font] $row
4799 proc vrel_change {name ix op} {
4800 global highlight_related
4803 if {$highlight_related ne [mc "None"]} {
4808 # prepare for testing whether commits are descendents or ancestors of a
4809 proc rhighlight_sel {a} {
4810 global descendent desc_todo ancestor anc_todo
4811 global highlight_related
4813 catch {unset descendent}
4814 set desc_todo [list $a]
4815 catch {unset ancestor}
4816 set anc_todo [list $a]
4817 if {$highlight_related ne [mc "None"]} {
4823 proc rhighlight_none {} {
4826 catch {unset rhighlights}
4830 proc is_descendent {a} {
4831 global curview children descendent desc_todo
4834 set la [rowofcommit $a]
4838 for {set i 0} {$i < [llength $todo]} {incr i} {
4839 set do [lindex $todo $i]
4840 if {[rowofcommit $do] < $la} {
4841 lappend leftover $do
4844 foreach nk $children($v,$do) {
4845 if {![info exists descendent($nk)]} {
4846 set descendent($nk) 1
4854 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4858 set descendent($a) 0
4859 set desc_todo $leftover
4862 proc is_ancestor {a} {
4863 global curview parents ancestor anc_todo
4866 set la [rowofcommit $a]
4870 for {set i 0} {$i < [llength $todo]} {incr i} {
4871 set do [lindex $todo $i]
4872 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4873 lappend leftover $do
4876 foreach np $parents($v,$do) {
4877 if {![info exists ancestor($np)]} {
4886 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4891 set anc_todo $leftover
4894 proc askrelhighlight {row id} {
4895 global descendent highlight_related iddrawn rhighlights
4896 global selectedline ancestor
4898 if {$selectedline eq {}} return
4900 if {$highlight_related eq [mc "Descendant"] ||
4901 $highlight_related eq [mc "Not descendant"]} {
4902 if {![info exists descendent($id)]} {
4905 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4908 } elseif {$highlight_related eq [mc "Ancestor"] ||
4909 $highlight_related eq [mc "Not ancestor"]} {
4910 if {![info exists ancestor($id)]} {
4913 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4917 if {[info exists iddrawn($id)]} {
4918 if {$isbold && ![ishighlighted $id]} {
4919 bolden $id mainfontbold
4922 set rhighlights($id) $isbold
4925 # Graph layout functions
4927 proc shortids {ids} {
4930 if {[llength $id] > 1} {
4931 lappend res [shortids $id]
4932 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4933 lappend res [string range $id 0 7]
4944 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4945 if {($n & $mask) != 0} {
4946 set ret [concat $ret $o]
4948 set o [concat $o $o]
4953 proc ordertoken {id} {
4954 global ordertok curview varcid varcstart varctok curview parents children
4955 global nullid nullid2
4957 if {[info exists ordertok($id)]} {
4958 return $ordertok($id)
4963 if {[info exists varcid($curview,$id)]} {
4964 set a $varcid($curview,$id)
4965 set p [lindex $varcstart($curview) $a]
4967 set p [lindex $children($curview,$id) 0]
4969 if {[info exists ordertok($p)]} {
4970 set tok $ordertok($p)
4973 set id [first_real_child $curview,$p]
4976 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4979 if {[llength $parents($curview,$id)] == 1} {
4980 lappend todo [list $p {}]
4982 set j [lsearch -exact $parents($curview,$id) $p]
4984 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4986 lappend todo [list $p [strrep $j]]
4989 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4990 set p [lindex $todo $i 0]
4991 append tok [lindex $todo $i 1]
4992 set ordertok($p) $tok
4994 set ordertok($origid) $tok
4998 # Work out where id should go in idlist so that order-token
4999 # values increase from left to right
5000 proc idcol {idlist id {i 0}} {
5001 set t [ordertoken $id]
5005 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5006 if {$i > [llength $idlist]} {
5007 set i [llength $idlist]
5009 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5012 if {$t > [ordertoken [lindex $idlist $i]]} {
5013 while {[incr i] < [llength $idlist] &&
5014 $t >= [ordertoken [lindex $idlist $i]]} {}
5020 proc initlayout {} {
5021 global rowidlist rowisopt rowfinal displayorder parentlist
5022 global numcommits canvxmax canv
5024 global colormap rowtextx
5033 set canvxmax [$canv cget -width]
5034 catch {unset colormap}
5035 catch {unset rowtextx}
5039 proc setcanvscroll {} {
5040 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5041 global lastscrollset lastscrollrows
5043 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5044 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5045 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5046 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5047 set lastscrollset [clock clicks -milliseconds]
5048 set lastscrollrows $numcommits
5051 proc visiblerows {} {
5052 global canv numcommits linespc
5054 set ymax [lindex [$canv cget -scrollregion] 3]
5055 if {$ymax eq {} || $ymax == 0} return
5057 set y0 [expr {int([lindex $f 0] * $ymax)}]
5058 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5062 set y1 [expr {int([lindex $f 1] * $ymax)}]
5063 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5064 if {$r1 >= $numcommits} {
5065 set r1 [expr {$numcommits - 1}]
5067 return [list $r0 $r1]
5070 proc layoutmore {} {
5071 global commitidx viewcomplete curview
5072 global numcommits pending_select curview
5073 global lastscrollset lastscrollrows
5075 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5076 [clock clicks -milliseconds] - $lastscrollset > 500} {
5079 if {[info exists pending_select] &&
5080 [commitinview $pending_select $curview]} {
5082 selectline [rowofcommit $pending_select] 1
5087 # With path limiting, we mightn't get the actual HEAD commit,
5088 # so ask git rev-list what is the first ancestor of HEAD that
5089 # touches a file in the path limit.
5090 proc get_viewmainhead {view} {
5091 global viewmainheadid vfilelimit viewinstances mainheadid
5094 set rfd [open [concat | git rev-list -1 $mainheadid \
5095 -- $vfilelimit($view)] r]
5096 set j [reg_instance $rfd]
5097 lappend viewinstances($view) $j
5098 fconfigure $rfd -blocking 0
5099 filerun $rfd [list getviewhead $rfd $j $view]
5100 set viewmainheadid($curview) {}
5104 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5105 proc getviewhead {fd inst view} {
5106 global viewmainheadid commfd curview viewinstances showlocalchanges
5109 if {[gets $fd line] < 0} {
5113 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5116 set viewmainheadid($view) $id
5119 set i [lsearch -exact $viewinstances($view) $inst]
5121 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5123 if {$showlocalchanges && $id ne {} && $view == $curview} {
5129 proc doshowlocalchanges {} {
5130 global curview viewmainheadid
5132 if {$viewmainheadid($curview) eq {}} return
5133 if {[commitinview $viewmainheadid($curview) $curview]} {
5136 interestedin $viewmainheadid($curview) dodiffindex
5140 proc dohidelocalchanges {} {
5141 global nullid nullid2 lserial curview
5143 if {[commitinview $nullid $curview]} {
5144 removefakerow $nullid
5146 if {[commitinview $nullid2 $curview]} {
5147 removefakerow $nullid2
5152 # spawn off a process to do git diff-index --cached HEAD
5153 proc dodiffindex {} {
5154 global lserial showlocalchanges vfilelimit curview
5157 if {!$showlocalchanges || !$hasworktree} return
5159 set cmd "|git diff-index --cached HEAD"
5160 if {$vfilelimit($curview) ne {}} {
5161 set cmd [concat $cmd -- $vfilelimit($curview)]
5163 set fd [open $cmd r]
5164 fconfigure $fd -blocking 0
5165 set i [reg_instance $fd]
5166 filerun $fd [list readdiffindex $fd $lserial $i]
5169 proc readdiffindex {fd serial inst} {
5170 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5174 if {[gets $fd line] < 0} {
5180 # we only need to see one line and we don't really care what it says...
5183 if {$serial != $lserial} {
5187 # now see if there are any local changes not checked in to the index
5188 set cmd "|git diff-files"
5189 if {$vfilelimit($curview) ne {}} {
5190 set cmd [concat $cmd -- $vfilelimit($curview)]
5192 set fd [open $cmd r]
5193 fconfigure $fd -blocking 0
5194 set i [reg_instance $fd]
5195 filerun $fd [list readdifffiles $fd $serial $i]
5197 if {$isdiff && ![commitinview $nullid2 $curview]} {
5198 # add the line for the changes in the index to the graph
5199 set hl [mc "Local changes checked in to index but not committed"]
5200 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5201 set commitdata($nullid2) "\n $hl\n"
5202 if {[commitinview $nullid $curview]} {
5203 removefakerow $nullid
5205 insertfakerow $nullid2 $viewmainheadid($curview)
5206 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5207 if {[commitinview $nullid $curview]} {
5208 removefakerow $nullid
5210 removefakerow $nullid2
5215 proc readdifffiles {fd serial inst} {
5216 global viewmainheadid nullid nullid2 curview
5217 global commitinfo commitdata lserial
5220 if {[gets $fd line] < 0} {
5226 # we only need to see one line and we don't really care what it says...
5229 if {$serial != $lserial} {
5233 if {$isdiff && ![commitinview $nullid $curview]} {
5234 # add the line for the local diff to the graph
5235 set hl [mc "Local uncommitted changes, not checked in to index"]
5236 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5237 set commitdata($nullid) "\n $hl\n"
5238 if {[commitinview $nullid2 $curview]} {
5241 set p $viewmainheadid($curview)
5243 insertfakerow $nullid $p
5244 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5245 removefakerow $nullid
5250 proc nextuse {id row} {
5251 global curview children
5253 if {[info exists children($curview,$id)]} {
5254 foreach kid $children($curview,$id) {
5255 if {![commitinview $kid $curview]} {
5258 if {[rowofcommit $kid] > $row} {
5259 return [rowofcommit $kid]
5263 if {[commitinview $id $curview]} {
5264 return [rowofcommit $id]
5269 proc prevuse {id row} {
5270 global curview children
5273 if {[info exists children($curview,$id)]} {
5274 foreach kid $children($curview,$id) {
5275 if {![commitinview $kid $curview]} break
5276 if {[rowofcommit $kid] < $row} {
5277 set ret [rowofcommit $kid]
5284 proc make_idlist {row} {
5285 global displayorder parentlist uparrowlen downarrowlen mingaplen
5286 global commitidx curview children
5288 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5292 set ra [expr {$row - $downarrowlen}]
5296 set rb [expr {$row + $uparrowlen}]
5297 if {$rb > $commitidx($curview)} {
5298 set rb $commitidx($curview)
5300 make_disporder $r [expr {$rb + 1}]
5302 for {} {$r < $ra} {incr r} {
5303 set nextid [lindex $displayorder [expr {$r + 1}]]
5304 foreach p [lindex $parentlist $r] {
5305 if {$p eq $nextid} continue
5306 set rn [nextuse $p $r]
5308 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5309 lappend ids [list [ordertoken $p] $p]
5313 for {} {$r < $row} {incr r} {
5314 set nextid [lindex $displayorder [expr {$r + 1}]]
5315 foreach p [lindex $parentlist $r] {
5316 if {$p eq $nextid} continue
5317 set rn [nextuse $p $r]
5318 if {$rn < 0 || $rn >= $row} {
5319 lappend ids [list [ordertoken $p] $p]
5323 set id [lindex $displayorder $row]
5324 lappend ids [list [ordertoken $id] $id]
5326 foreach p [lindex $parentlist $r] {
5327 set firstkid [lindex $children($curview,$p) 0]
5328 if {[rowofcommit $firstkid] < $row} {
5329 lappend ids [list [ordertoken $p] $p]
5333 set id [lindex $displayorder $r]
5335 set firstkid [lindex $children($curview,$id) 0]
5336 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5337 lappend ids [list [ordertoken $id] $id]
5342 foreach idx [lsort -unique $ids] {
5343 lappend idlist [lindex $idx 1]
5348 proc rowsequal {a b} {
5349 while {[set i [lsearch -exact $a {}]] >= 0} {
5350 set a [lreplace $a $i $i]
5352 while {[set i [lsearch -exact $b {}]] >= 0} {
5353 set b [lreplace $b $i $i]
5355 return [expr {$a eq $b}]
5358 proc makeupline {id row rend col} {
5359 global rowidlist uparrowlen downarrowlen mingaplen
5361 for {set r $rend} {1} {set r $rstart} {
5362 set rstart [prevuse $id $r]
5363 if {$rstart < 0} return
5364 if {$rstart < $row} break
5366 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5367 set rstart [expr {$rend - $uparrowlen - 1}]
5369 for {set r $rstart} {[incr r] <= $row} {} {
5370 set idlist [lindex $rowidlist $r]
5371 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5372 set col [idcol $idlist $id $col]
5373 lset rowidlist $r [linsert $idlist $col $id]
5379 proc layoutrows {row endrow} {
5380 global rowidlist rowisopt rowfinal displayorder
5381 global uparrowlen downarrowlen maxwidth mingaplen
5382 global children parentlist
5383 global commitidx viewcomplete curview
5385 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5388 set rm1 [expr {$row - 1}]
5389 foreach id [lindex $rowidlist $rm1] {
5394 set final [lindex $rowfinal $rm1]
5396 for {} {$row < $endrow} {incr row} {
5397 set rm1 [expr {$row - 1}]
5398 if {$rm1 < 0 || $idlist eq {}} {
5399 set idlist [make_idlist $row]
5402 set id [lindex $displayorder $rm1]
5403 set col [lsearch -exact $idlist $id]
5404 set idlist [lreplace $idlist $col $col]
5405 foreach p [lindex $parentlist $rm1] {
5406 if {[lsearch -exact $idlist $p] < 0} {
5407 set col [idcol $idlist $p $col]
5408 set idlist [linsert $idlist $col $p]
5409 # if not the first child, we have to insert a line going up
5410 if {$id ne [lindex $children($curview,$p) 0]} {
5411 makeupline $p $rm1 $row $col
5415 set id [lindex $displayorder $row]
5416 if {$row > $downarrowlen} {
5417 set termrow [expr {$row - $downarrowlen - 1}]
5418 foreach p [lindex $parentlist $termrow] {
5419 set i [lsearch -exact $idlist $p]
5420 if {$i < 0} continue
5421 set nr [nextuse $p $termrow]
5422 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5423 set idlist [lreplace $idlist $i $i]
5427 set col [lsearch -exact $idlist $id]
5429 set col [idcol $idlist $id]
5430 set idlist [linsert $idlist $col $id]
5431 if {$children($curview,$id) ne {}} {
5432 makeupline $id $rm1 $row $col
5435 set r [expr {$row + $uparrowlen - 1}]
5436 if {$r < $commitidx($curview)} {
5438 foreach p [lindex $parentlist $r] {
5439 if {[lsearch -exact $idlist $p] >= 0} continue
5440 set fk [lindex $children($curview,$p) 0]
5441 if {[rowofcommit $fk] < $row} {
5442 set x [idcol $idlist $p $x]
5443 set idlist [linsert $idlist $x $p]
5446 if {[incr r] < $commitidx($curview)} {
5447 set p [lindex $displayorder $r]
5448 if {[lsearch -exact $idlist $p] < 0} {
5449 set fk [lindex $children($curview,$p) 0]
5450 if {$fk ne {} && [rowofcommit $fk] < $row} {
5451 set x [idcol $idlist $p $x]
5452 set idlist [linsert $idlist $x $p]
5458 if {$final && !$viewcomplete($curview) &&
5459 $row + $uparrowlen + $mingaplen + $downarrowlen
5460 >= $commitidx($curview)} {
5463 set l [llength $rowidlist]
5465 lappend rowidlist $idlist
5467 lappend rowfinal $final
5468 } elseif {$row < $l} {
5469 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5470 lset rowidlist $row $idlist
5473 lset rowfinal $row $final
5475 set pad [ntimes [expr {$row - $l}] {}]
5476 set rowidlist [concat $rowidlist $pad]
5477 lappend rowidlist $idlist
5478 set rowfinal [concat $rowfinal $pad]
5479 lappend rowfinal $final
5480 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5486 proc changedrow {row} {
5487 global displayorder iddrawn rowisopt need_redisplay
5489 set l [llength $rowisopt]
5491 lset rowisopt $row 0
5492 if {$row + 1 < $l} {
5493 lset rowisopt [expr {$row + 1}] 0
5494 if {$row + 2 < $l} {
5495 lset rowisopt [expr {$row + 2}] 0
5499 set id [lindex $displayorder $row]
5500 if {[info exists iddrawn($id)]} {
5501 set need_redisplay 1
5505 proc insert_pad {row col npad} {
5508 set pad [ntimes $npad {}]
5509 set idlist [lindex $rowidlist $row]
5510 set bef [lrange $idlist 0 [expr {$col - 1}]]
5511 set aft [lrange $idlist $col end]
5512 set i [lsearch -exact $aft {}]
5514 set aft [lreplace $aft $i $i]
5516 lset rowidlist $row [concat $bef $pad $aft]
5520 proc optimize_rows {row col endrow} {
5521 global rowidlist rowisopt displayorder curview children
5526 for {} {$row < $endrow} {incr row; set col 0} {
5527 if {[lindex $rowisopt $row]} continue
5529 set y0 [expr {$row - 1}]
5530 set ym [expr {$row - 2}]
5531 set idlist [lindex $rowidlist $row]
5532 set previdlist [lindex $rowidlist $y0]
5533 if {$idlist eq {} || $previdlist eq {}} continue
5535 set pprevidlist [lindex $rowidlist $ym]
5536 if {$pprevidlist eq {}} continue
5542 for {} {$col < [llength $idlist]} {incr col} {
5543 set id [lindex $idlist $col]
5544 if {[lindex $previdlist $col] eq $id} continue
5549 set x0 [lsearch -exact $previdlist $id]
5550 if {$x0 < 0} continue
5551 set z [expr {$x0 - $col}]
5555 set xm [lsearch -exact $pprevidlist $id]
5557 set z0 [expr {$xm - $x0}]
5561 # if row y0 is the first child of $id then it's not an arrow
5562 if {[lindex $children($curview,$id) 0] ne
5563 [lindex $displayorder $y0]} {
5567 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5568 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5571 # Looking at lines from this row to the previous row,
5572 # make them go straight up if they end in an arrow on
5573 # the previous row; otherwise make them go straight up
5575 if {$z < -1 || ($z < 0 && $isarrow)} {
5576 # Line currently goes left too much;
5577 # insert pads in the previous row, then optimize it
5578 set npad [expr {-1 - $z + $isarrow}]
5579 insert_pad $y0 $x0 $npad
5581 optimize_rows $y0 $x0 $row
5583 set previdlist [lindex $rowidlist $y0]
5584 set x0 [lsearch -exact $previdlist $id]
5585 set z [expr {$x0 - $col}]
5587 set pprevidlist [lindex $rowidlist $ym]
5588 set xm [lsearch -exact $pprevidlist $id]
5589 set z0 [expr {$xm - $x0}]
5591 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5592 # Line currently goes right too much;
5593 # insert pads in this line
5594 set npad [expr {$z - 1 + $isarrow}]
5595 insert_pad $row $col $npad
5596 set idlist [lindex $rowidlist $row]
5598 set z [expr {$x0 - $col}]
5601 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5602 # this line links to its first child on row $row-2
5603 set id [lindex $displayorder $ym]
5604 set xc [lsearch -exact $pprevidlist $id]
5606 set z0 [expr {$xc - $x0}]
5609 # avoid lines jigging left then immediately right
5610 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5611 insert_pad $y0 $x0 1
5613 optimize_rows $y0 $x0 $row
5614 set previdlist [lindex $rowidlist $y0]
5618 # Find the first column that doesn't have a line going right
5619 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5620 set id [lindex $idlist $col]
5621 if {$id eq {}} break
5622 set x0 [lsearch -exact $previdlist $id]
5624 # check if this is the link to the first child
5625 set kid [lindex $displayorder $y0]
5626 if {[lindex $children($curview,$id) 0] eq $kid} {
5627 # it is, work out offset to child
5628 set x0 [lsearch -exact $previdlist $kid]
5631 if {$x0 <= $col} break
5633 # Insert a pad at that column as long as it has a line and
5634 # isn't the last column
5635 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5636 set idlist [linsert $idlist $col {}]
5637 lset rowidlist $row $idlist
5645 global canvx0 linespc
5646 return [expr {$canvx0 + $col * $linespc}]
5650 global canvy0 linespc
5651 return [expr {$canvy0 + $row * $linespc}]
5654 proc linewidth {id} {
5655 global thickerline lthickness
5658 if {[info exists thickerline] && $id eq $thickerline} {
5659 set wid [expr {2 * $lthickness}]
5664 proc rowranges {id} {
5665 global curview children uparrowlen downarrowlen
5668 set kids $children($curview,$id)
5674 foreach child $kids {
5675 if {![commitinview $child $curview]} break
5676 set row [rowofcommit $child]
5677 if {![info exists prev]} {
5678 lappend ret [expr {$row + 1}]
5680 if {$row <= $prevrow} {
5681 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5683 # see if the line extends the whole way from prevrow to row
5684 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5685 [lsearch -exact [lindex $rowidlist \
5686 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5687 # it doesn't, see where it ends
5688 set r [expr {$prevrow + $downarrowlen}]
5689 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5690 while {[incr r -1] > $prevrow &&
5691 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5693 while {[incr r] <= $row &&
5694 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5698 # see where it starts up again
5699 set r [expr {$row - $uparrowlen}]
5700 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5701 while {[incr r] < $row &&
5702 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5704 while {[incr r -1] >= $prevrow &&
5705 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5711 if {$child eq $id} {
5720 proc drawlineseg {id row endrow arrowlow} {
5721 global rowidlist displayorder iddrawn linesegs
5722 global canv colormap linespc curview maxlinelen parentlist
5724 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5725 set le [expr {$row + 1}]
5728 set c [lsearch -exact [lindex $rowidlist $le] $id]
5734 set x [lindex $displayorder $le]
5739 if {[info exists iddrawn($x)] || $le == $endrow} {
5740 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5756 if {[info exists linesegs($id)]} {
5757 set lines $linesegs($id)
5759 set r0 [lindex $li 0]
5761 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5771 set li [lindex $lines [expr {$i-1}]]
5772 set r1 [lindex $li 1]
5773 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5778 set x [lindex $cols [expr {$le - $row}]]
5779 set xp [lindex $cols [expr {$le - 1 - $row}]]
5780 set dir [expr {$xp - $x}]
5782 set ith [lindex $lines $i 2]
5783 set coords [$canv coords $ith]
5784 set ah [$canv itemcget $ith -arrow]
5785 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5786 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5787 if {$x2 ne {} && $x - $x2 == $dir} {
5788 set coords [lrange $coords 0 end-2]
5791 set coords [list [xc $le $x] [yc $le]]
5794 set itl [lindex $lines [expr {$i-1}] 2]
5795 set al [$canv itemcget $itl -arrow]
5796 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5797 } elseif {$arrowlow} {
5798 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5799 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5803 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5804 for {set y $le} {[incr y -1] > $row} {} {
5806 set xp [lindex $cols [expr {$y - 1 - $row}]]
5807 set ndir [expr {$xp - $x}]
5808 if {$dir != $ndir || $xp < 0} {
5809 lappend coords [xc $y $x] [yc $y]
5815 # join parent line to first child
5816 set ch [lindex $displayorder $row]
5817 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5819 puts "oops: drawlineseg: child $ch not on row $row"
5820 } elseif {$xc != $x} {
5821 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5822 set d [expr {int(0.5 * $linespc)}]
5825 set x2 [expr {$x1 - $d}]
5827 set x2 [expr {$x1 + $d}]
5830 set y1 [expr {$y2 + $d}]
5831 lappend coords $x1 $y1 $x2 $y2
5832 } elseif {$xc < $x - 1} {
5833 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5834 } elseif {$xc > $x + 1} {
5835 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5839 lappend coords [xc $row $x] [yc $row]
5841 set xn [xc $row $xp]
5843 lappend coords $xn $yn
5847 set t [$canv create line $coords -width [linewidth $id] \
5848 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5851 set lines [linsert $lines $i [list $row $le $t]]
5853 $canv coords $ith $coords
5854 if {$arrow ne $ah} {
5855 $canv itemconf $ith -arrow $arrow
5857 lset lines $i 0 $row
5860 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5861 set ndir [expr {$xo - $xp}]
5862 set clow [$canv coords $itl]
5863 if {$dir == $ndir} {
5864 set clow [lrange $clow 2 end]
5866 set coords [concat $coords $clow]
5868 lset lines [expr {$i-1}] 1 $le
5870 # coalesce two pieces
5872 set b [lindex $lines [expr {$i-1}] 0]
5873 set e [lindex $lines $i 1]
5874 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5876 $canv coords $itl $coords
5877 if {$arrow ne $al} {
5878 $canv itemconf $itl -arrow $arrow
5882 set linesegs($id) $lines
5886 proc drawparentlinks {id row} {
5887 global rowidlist canv colormap curview parentlist
5888 global idpos linespc
5890 set rowids [lindex $rowidlist $row]
5891 set col [lsearch -exact $rowids $id]
5892 if {$col < 0} return
5893 set olds [lindex $parentlist $row]
5894 set row2 [expr {$row + 1}]
5895 set x [xc $row $col]
5898 set d [expr {int(0.5 * $linespc)}]
5899 set ymid [expr {$y + $d}]
5900 set ids [lindex $rowidlist $row2]
5901 # rmx = right-most X coord used
5904 set i [lsearch -exact $ids $p]
5906 puts "oops, parent $p of $id not in list"
5909 set x2 [xc $row2 $i]
5913 set j [lsearch -exact $rowids $p]
5915 # drawlineseg will do this one for us
5919 # should handle duplicated parents here...
5920 set coords [list $x $y]
5922 # if attaching to a vertical segment, draw a smaller
5923 # slant for visual distinctness
5926 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5928 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5930 } elseif {$i < $col && $i < $j} {
5931 # segment slants towards us already
5932 lappend coords [xc $row $j] $y
5934 if {$i < $col - 1} {
5935 lappend coords [expr {$x2 + $linespc}] $y
5936 } elseif {$i > $col + 1} {
5937 lappend coords [expr {$x2 - $linespc}] $y
5939 lappend coords $x2 $y2
5942 lappend coords $x2 $y2
5944 set t [$canv create line $coords -width [linewidth $p] \
5945 -fill $colormap($p) -tags lines.$p]
5949 if {$rmx > [lindex $idpos($id) 1]} {
5950 lset idpos($id) 1 $rmx
5955 proc drawlines {id} {
5958 $canv itemconf lines.$id -width [linewidth $id]
5961 proc drawcmittext {id row col} {
5962 global linespc canv canv2 canv3 fgcolor curview
5963 global cmitlisted commitinfo rowidlist parentlist
5964 global rowtextx idpos idtags idheads idotherrefs
5965 global linehtag linentag linedtag selectedline
5966 global canvxmax boldids boldnameids fgcolor markedid
5967 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5968 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5969 global circleoutlinecolor
5971 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5972 set listed $cmitlisted($curview,$id)
5973 if {$id eq $nullid} {
5974 set ofill $workingfilescirclecolor
5975 } elseif {$id eq $nullid2} {
5976 set ofill $indexcirclecolor
5977 } elseif {$id eq $mainheadid} {
5978 set ofill $mainheadcirclecolor
5980 set ofill [lindex $circlecolors $listed]
5982 set x [xc $row $col]
5984 set orad [expr {$linespc / 3}]
5986 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5987 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5988 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
5989 } elseif {$listed == 3} {
5990 # triangle pointing left for left-side commits
5991 set t [$canv create polygon \
5992 [expr {$x - $orad}] $y \
5993 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5994 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5995 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
5997 # triangle pointing right for right-side commits
5998 set t [$canv create polygon \
5999 [expr {$x + $orad - 1}] $y \
6000 [expr {$x - $orad}] [expr {$y - $orad}] \
6001 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6002 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6004 set circleitem($row) $t
6006 $canv bind $t <1> {selcanvline {} %x %y}
6007 set rmx [llength [lindex $rowidlist $row]]
6008 set olds [lindex $parentlist $row]
6010 set nextids [lindex $rowidlist [expr {$row + 1}]]
6012 set i [lsearch -exact $nextids $p]
6018 set xt [xc $row $rmx]
6019 set rowtextx($row) $xt
6020 set idpos($id) [list $x $xt $y]
6021 if {[info exists idtags($id)] || [info exists idheads($id)]
6022 || [info exists idotherrefs($id)]} {
6023 set xt [drawtags $id $x $xt $y]
6025 if {[lindex $commitinfo($id) 6] > 0} {
6026 set xt [drawnotesign $xt $y]
6028 set headline [lindex $commitinfo($id) 0]
6029 set name [lindex $commitinfo($id) 1]
6030 set date [lindex $commitinfo($id) 2]
6031 set date [formatdate $date]
6034 set isbold [ishighlighted $id]
6037 set font mainfontbold
6039 lappend boldnameids $id
6040 set nfont mainfontbold
6043 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6044 -text $headline -font $font -tags text]
6045 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6046 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6047 -text $name -font $nfont -tags text]
6048 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6049 -text $date -font mainfont -tags text]
6050 if {$selectedline == $row} {
6053 if {[info exists markedid] && $markedid eq $id} {
6056 set xr [expr {$xt + [font measure $font $headline]}]
6057 if {$xr > $canvxmax} {
6063 proc drawcmitrow {row} {
6064 global displayorder rowidlist nrows_drawn
6065 global iddrawn markingmatches
6066 global commitinfo numcommits
6067 global filehighlight fhighlights findpattern nhighlights
6068 global hlview vhighlights
6069 global highlight_related rhighlights
6071 if {$row >= $numcommits} return
6073 set id [lindex $displayorder $row]
6074 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6075 askvhighlight $row $id
6077 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6078 askfilehighlight $row $id
6080 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6081 askfindhighlight $row $id
6083 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6084 askrelhighlight $row $id
6086 if {![info exists iddrawn($id)]} {
6087 set col [lsearch -exact [lindex $rowidlist $row] $id]
6089 puts "oops, row $row id $id not in list"
6092 if {![info exists commitinfo($id)]} {
6096 drawcmittext $id $row $col
6100 if {$markingmatches} {
6101 markrowmatches $row $id
6105 proc drawcommits {row {endrow {}}} {
6106 global numcommits iddrawn displayorder curview need_redisplay
6107 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6112 if {$endrow eq {}} {
6115 if {$endrow >= $numcommits} {
6116 set endrow [expr {$numcommits - 1}]
6119 set rl1 [expr {$row - $downarrowlen - 3}]
6123 set ro1 [expr {$row - 3}]
6127 set r2 [expr {$endrow + $uparrowlen + 3}]
6128 if {$r2 > $numcommits} {
6131 for {set r $rl1} {$r < $r2} {incr r} {
6132 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6136 set rl1 [expr {$r + 1}]
6142 optimize_rows $ro1 0 $r2
6143 if {$need_redisplay || $nrows_drawn > 2000} {
6147 # make the lines join to already-drawn rows either side
6148 set r [expr {$row - 1}]
6149 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6152 set er [expr {$endrow + 1}]
6153 if {$er >= $numcommits ||
6154 ![info exists iddrawn([lindex $displayorder $er])]} {
6157 for {} {$r <= $er} {incr r} {
6158 set id [lindex $displayorder $r]
6159 set wasdrawn [info exists iddrawn($id)]
6161 if {$r == $er} break
6162 set nextid [lindex $displayorder [expr {$r + 1}]]
6163 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6164 drawparentlinks $id $r
6166 set rowids [lindex $rowidlist $r]
6167 foreach lid $rowids {
6168 if {$lid eq {}} continue
6169 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6171 # see if this is the first child of any of its parents
6172 foreach p [lindex $parentlist $r] {
6173 if {[lsearch -exact $rowids $p] < 0} {
6174 # make this line extend up to the child
6175 set lineend($p) [drawlineseg $p $r $er 0]
6179 set lineend($lid) [drawlineseg $lid $r $er 1]
6185 proc undolayout {row} {
6186 global uparrowlen mingaplen downarrowlen
6187 global rowidlist rowisopt rowfinal need_redisplay
6189 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6193 if {[llength $rowidlist] > $r} {
6195 set rowidlist [lrange $rowidlist 0 $r]
6196 set rowfinal [lrange $rowfinal 0 $r]
6197 set rowisopt [lrange $rowisopt 0 $r]
6198 set need_redisplay 1
6203 proc drawvisible {} {
6204 global canv linespc curview vrowmod selectedline targetrow targetid
6205 global need_redisplay cscroll numcommits
6207 set fs [$canv yview]
6208 set ymax [lindex [$canv cget -scrollregion] 3]
6209 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6210 set f0 [lindex $fs 0]
6211 set f1 [lindex $fs 1]
6212 set y0 [expr {int($f0 * $ymax)}]
6213 set y1 [expr {int($f1 * $ymax)}]
6215 if {[info exists targetid]} {
6216 if {[commitinview $targetid $curview]} {
6217 set r [rowofcommit $targetid]
6218 if {$r != $targetrow} {
6219 # Fix up the scrollregion and change the scrolling position
6220 # now that our target row has moved.
6221 set diff [expr {($r - $targetrow) * $linespc}]
6224 set ymax [lindex [$canv cget -scrollregion] 3]
6227 set f0 [expr {$y0 / $ymax}]
6228 set f1 [expr {$y1 / $ymax}]
6229 allcanvs yview moveto $f0
6230 $cscroll set $f0 $f1
6231 set need_redisplay 1
6238 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6239 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6240 if {$endrow >= $vrowmod($curview)} {
6241 update_arcrows $curview
6243 if {$selectedline ne {} &&
6244 $row <= $selectedline && $selectedline <= $endrow} {
6245 set targetrow $selectedline
6246 } elseif {[info exists targetid]} {
6247 set targetrow [expr {int(($row + $endrow) / 2)}]
6249 if {[info exists targetrow]} {
6250 if {$targetrow >= $numcommits} {
6251 set targetrow [expr {$numcommits - 1}]
6253 set targetid [commitonrow $targetrow]
6255 drawcommits $row $endrow
6258 proc clear_display {} {
6259 global iddrawn linesegs need_redisplay nrows_drawn
6260 global vhighlights fhighlights nhighlights rhighlights
6261 global linehtag linentag linedtag boldids boldnameids
6264 catch {unset iddrawn}
6265 catch {unset linesegs}
6266 catch {unset linehtag}
6267 catch {unset linentag}
6268 catch {unset linedtag}
6271 catch {unset vhighlights}
6272 catch {unset fhighlights}
6273 catch {unset nhighlights}
6274 catch {unset rhighlights}
6275 set need_redisplay 0
6279 proc findcrossings {id} {
6280 global rowidlist parentlist numcommits displayorder
6284 foreach {s e} [rowranges $id] {
6285 if {$e >= $numcommits} {
6286 set e [expr {$numcommits - 1}]
6288 if {$e <= $s} continue
6289 for {set row $e} {[incr row -1] >= $s} {} {
6290 set x [lsearch -exact [lindex $rowidlist $row] $id]
6292 set olds [lindex $parentlist $row]
6293 set kid [lindex $displayorder $row]
6294 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6295 if {$kidx < 0} continue
6296 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6298 set px [lsearch -exact $nextrow $p]
6299 if {$px < 0} continue
6300 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6301 if {[lsearch -exact $ccross $p] >= 0} continue
6302 if {$x == $px + ($kidx < $px? -1: 1)} {
6304 } elseif {[lsearch -exact $cross $p] < 0} {
6311 return [concat $ccross {{}} $cross]
6314 proc assigncolor {id} {
6315 global colormap colors nextcolor
6316 global parents children children curview
6318 if {[info exists colormap($id)]} return
6319 set ncolors [llength $colors]
6320 if {[info exists children($curview,$id)]} {
6321 set kids $children($curview,$id)
6325 if {[llength $kids] == 1} {
6326 set child [lindex $kids 0]
6327 if {[info exists colormap($child)]
6328 && [llength $parents($curview,$child)] == 1} {
6329 set colormap($id) $colormap($child)
6335 foreach x [findcrossings $id] {
6337 # delimiter between corner crossings and other crossings
6338 if {[llength $badcolors] >= $ncolors - 1} break
6339 set origbad $badcolors
6341 if {[info exists colormap($x)]
6342 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6343 lappend badcolors $colormap($x)
6346 if {[llength $badcolors] >= $ncolors} {
6347 set badcolors $origbad
6349 set origbad $badcolors
6350 if {[llength $badcolors] < $ncolors - 1} {
6351 foreach child $kids {
6352 if {[info exists colormap($child)]
6353 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6354 lappend badcolors $colormap($child)
6356 foreach p $parents($curview,$child) {
6357 if {[info exists colormap($p)]
6358 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6359 lappend badcolors $colormap($p)
6363 if {[llength $badcolors] >= $ncolors} {
6364 set badcolors $origbad
6367 for {set i 0} {$i <= $ncolors} {incr i} {
6368 set c [lindex $colors $nextcolor]
6369 if {[incr nextcolor] >= $ncolors} {
6372 if {[lsearch -exact $badcolors $c]} break
6374 set colormap($id) $c
6377 proc bindline {t id} {
6380 $canv bind $t <Enter> "lineenter %x %y $id"
6381 $canv bind $t <Motion> "linemotion %x %y $id"
6382 $canv bind $t <Leave> "lineleave $id"
6383 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6386 proc drawtags {id x xt y1} {
6387 global idtags idheads idotherrefs mainhead
6388 global linespc lthickness
6389 global canv rowtextx curview fgcolor bgcolor ctxbut
6390 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6391 global tagbgcolor tagfgcolor tagoutlinecolor
6397 if {[info exists idtags($id)]} {
6398 set marks $idtags($id)
6399 set ntags [llength $marks]
6401 if {[info exists idheads($id)]} {
6402 set marks [concat $marks $idheads($id)]
6403 set nheads [llength $idheads($id)]
6405 if {[info exists idotherrefs($id)]} {
6406 set marks [concat $marks $idotherrefs($id)]
6412 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6413 set yt [expr {$y1 - 0.5 * $linespc}]
6414 set yb [expr {$yt + $linespc - 1}]
6418 foreach tag $marks {
6420 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6421 set wid [font measure mainfontbold $tag]
6423 set wid [font measure mainfont $tag]
6427 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6429 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6430 -width $lthickness -fill $reflinecolor -tags tag.$id]
6432 foreach tag $marks x $xvals wid $wvals {
6433 set tag_quoted [string map {% %%} $tag]
6434 set xl [expr {$x + $delta}]
6435 set xr [expr {$x + $delta + $wid + $lthickness}]
6437 if {[incr ntags -1] >= 0} {
6439 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6440 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6441 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6443 $canv bind $t <1> [list showtag $tag_quoted 1]
6444 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6446 # draw a head or other ref
6447 if {[incr nheads -1] >= 0} {
6448 set col $headbgcolor
6449 if {$tag eq $mainhead} {
6450 set font mainfontbold
6455 set xl [expr {$xl - $delta/2}]
6456 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6457 -width 1 -outline black -fill $col -tags tag.$id
6458 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6459 set rwid [font measure mainfont $remoteprefix]
6460 set xi [expr {$x + 1}]
6461 set yti [expr {$yt + 1}]
6462 set xri [expr {$x + $rwid}]
6463 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6464 -width 0 -fill $remotebgcolor -tags tag.$id
6467 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6468 -font $font -tags [list tag.$id text]]
6470 $canv bind $t <1> [list showtag $tag_quoted 1]
6471 } elseif {$nheads >= 0} {
6472 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6478 proc drawnotesign {xt y} {
6479 global linespc canv fgcolor
6481 set orad [expr {$linespc / 3}]
6482 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6483 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6484 -fill yellow -outline $fgcolor -width 1 -tags circle]
6485 set xt [expr {$xt + $orad * 3}]
6489 proc xcoord {i level ln} {
6490 global canvx0 xspc1 xspc2
6492 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6493 if {$i > 0 && $i == $level} {
6494 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6495 } elseif {$i > $level} {
6496 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6501 proc show_status {msg} {
6505 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6506 -tags text -fill $fgcolor
6509 # Don't change the text pane cursor if it is currently the hand cursor,
6510 # showing that we are over a sha1 ID link.
6511 proc settextcursor {c} {
6512 global ctext curtextcursor
6514 if {[$ctext cget -cursor] == $curtextcursor} {
6515 $ctext config -cursor $c
6517 set curtextcursor $c
6520 proc nowbusy {what {name {}}} {
6521 global isbusy busyname statusw
6523 if {[array names isbusy] eq {}} {
6524 . config -cursor watch
6528 set busyname($what) $name
6530 $statusw conf -text $name
6534 proc notbusy {what} {
6535 global isbusy maincursor textcursor busyname statusw
6539 if {$busyname($what) ne {} &&
6540 [$statusw cget -text] eq $busyname($what)} {
6541 $statusw conf -text {}
6544 if {[array names isbusy] eq {}} {
6545 . config -cursor $maincursor
6546 settextcursor $textcursor
6550 proc findmatches {f} {
6551 global findtype findstring
6552 if {$findtype == [mc "Regexp"]} {
6553 set matches [regexp -indices -all -inline $findstring $f]
6556 if {$findtype == [mc "IgnCase"]} {
6557 set f [string tolower $f]
6558 set fs [string tolower $fs]
6562 set l [string length $fs]
6563 while {[set j [string first $fs $f $i]] >= 0} {
6564 lappend matches [list $j [expr {$j+$l-1}]]
6565 set i [expr {$j + $l}]
6571 proc dofind {{dirn 1} {wrap 1}} {
6572 global findstring findstartline findcurline selectedline numcommits
6573 global gdttype filehighlight fh_serial find_dirn findallowwrap
6575 if {[info exists find_dirn]} {
6576 if {$find_dirn == $dirn} return
6580 if {$findstring eq {} || $numcommits == 0} return
6581 if {$selectedline eq {}} {
6582 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6584 set findstartline $selectedline
6586 set findcurline $findstartline
6587 nowbusy finding [mc "Searching"]
6588 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6589 after cancel do_file_hl $fh_serial
6590 do_file_hl $fh_serial
6593 set findallowwrap $wrap
6597 proc stopfinding {} {
6598 global find_dirn findcurline fprogcoord
6600 if {[info exists find_dirn]} {
6611 global commitdata commitinfo numcommits findpattern findloc
6612 global findstartline findcurline findallowwrap
6613 global find_dirn gdttype fhighlights fprogcoord
6614 global curview varcorder vrownum varccommits vrowmod
6616 if {![info exists find_dirn]} {
6619 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6622 if {$find_dirn > 0} {
6624 if {$l >= $numcommits} {
6627 if {$l <= $findstartline} {
6628 set lim [expr {$findstartline + 1}]
6631 set moretodo $findallowwrap
6638 if {$l >= $findstartline} {
6639 set lim [expr {$findstartline - 1}]
6642 set moretodo $findallowwrap
6645 set n [expr {($lim - $l) * $find_dirn}]
6650 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6651 update_arcrows $curview
6655 set ai [bsearch $vrownum($curview) $l]
6656 set a [lindex $varcorder($curview) $ai]
6657 set arow [lindex $vrownum($curview) $ai]
6658 set ids [lindex $varccommits($curview,$a)]
6659 set arowend [expr {$arow + [llength $ids]}]
6660 if {$gdttype eq [mc "containing:"]} {
6661 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6662 if {$l < $arow || $l >= $arowend} {
6664 set a [lindex $varcorder($curview) $ai]
6665 set arow [lindex $vrownum($curview) $ai]
6666 set ids [lindex $varccommits($curview,$a)]
6667 set arowend [expr {$arow + [llength $ids]}]
6669 set id [lindex $ids [expr {$l - $arow}]]
6670 # shouldn't happen unless git log doesn't give all the commits...
6671 if {![info exists commitdata($id)] ||
6672 ![doesmatch $commitdata($id)]} {
6675 if {![info exists commitinfo($id)]} {
6678 set info $commitinfo($id)
6679 foreach f $info ty $fldtypes {
6680 if {$ty eq ""} continue
6681 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6690 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6691 if {$l < $arow || $l >= $arowend} {
6693 set a [lindex $varcorder($curview) $ai]
6694 set arow [lindex $vrownum($curview) $ai]
6695 set ids [lindex $varccommits($curview,$a)]
6696 set arowend [expr {$arow + [llength $ids]}]
6698 set id [lindex $ids [expr {$l - $arow}]]
6699 if {![info exists fhighlights($id)]} {
6700 # this sets fhighlights($id) to -1
6701 askfilehighlight $l $id
6703 if {$fhighlights($id) > 0} {
6707 if {$fhighlights($id) < 0} {
6710 set findcurline [expr {$l - $find_dirn}]
6715 if {$found || ($domore && !$moretodo)} {
6731 set findcurline [expr {$l - $find_dirn}]
6733 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6737 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6742 proc findselectline {l} {
6743 global findloc commentend ctext findcurline markingmatches gdttype
6745 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6748 if {$markingmatches &&
6749 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6750 # highlight the matches in the comments
6751 set f [$ctext get 1.0 $commentend]
6752 set matches [findmatches $f]
6753 foreach match $matches {
6754 set start [lindex $match 0]
6755 set end [expr {[lindex $match 1] + 1}]
6756 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6762 # mark the bits of a headline or author that match a find string
6763 proc markmatches {canv l str tag matches font row} {
6766 set bbox [$canv bbox $tag]
6767 set x0 [lindex $bbox 0]
6768 set y0 [lindex $bbox 1]
6769 set y1 [lindex $bbox 3]
6770 foreach match $matches {
6771 set start [lindex $match 0]
6772 set end [lindex $match 1]
6773 if {$start > $end} continue
6774 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6775 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6776 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6777 [expr {$x0+$xlen+2}] $y1 \
6778 -outline {} -tags [list match$l matches] -fill yellow]
6780 if {$row == $selectedline} {
6781 $canv raise $t secsel
6786 proc unmarkmatches {} {
6787 global markingmatches
6789 allcanvs delete matches
6790 set markingmatches 0
6794 proc selcanvline {w x y} {
6795 global canv canvy0 ctext linespc
6797 set ymax [lindex [$canv cget -scrollregion] 3]
6798 if {$ymax == {}} return
6799 set yfrac [lindex [$canv yview] 0]
6800 set y [expr {$y + $yfrac * $ymax}]
6801 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6806 set xmax [lindex [$canv cget -scrollregion] 2]
6807 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6808 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6814 proc commit_descriptor {p} {
6816 if {![info exists commitinfo($p)]} {
6820 if {[llength $commitinfo($p)] > 1} {
6821 set l [lindex $commitinfo($p) 0]
6826 # append some text to the ctext widget, and make any SHA1 ID
6827 # that we know about be a clickable link.
6828 proc appendwithlinks {text tags} {
6829 global ctext linknum curview
6831 set start [$ctext index "end - 1c"]
6832 $ctext insert end $text $tags
6833 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6837 set linkid [string range $text $s $e]
6839 $ctext tag delete link$linknum
6840 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6841 setlink $linkid link$linknum
6846 proc setlink {id lk} {
6847 global curview ctext pendinglinks
6850 if {[string range $id 0 1] eq "-g"} {
6851 set id [string range $id 2 end]
6855 if {[string length $id] < 40} {
6856 set matches [longid $id]
6857 if {[llength $matches] > 0} {
6858 if {[llength $matches] > 1} return
6860 set id [lindex $matches 0]
6863 set known [commitinview $id $curview]
6866 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6867 $ctext tag bind $lk <1> [list selbyid $id]
6868 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6869 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6871 lappend pendinglinks($id) $lk
6872 interestedin $id {makelink %P}
6876 proc appendshortlink {id {pre {}} {post {}}} {
6877 global ctext linknum
6879 $ctext insert end $pre
6880 $ctext tag delete link$linknum
6881 $ctext insert end [string range $id 0 7] link$linknum
6882 $ctext insert end $post
6883 setlink $id link$linknum
6887 proc makelink {id} {
6890 if {![info exists pendinglinks($id)]} return
6891 foreach lk $pendinglinks($id) {
6894 unset pendinglinks($id)
6897 proc linkcursor {w inc} {
6898 global linkentercount curtextcursor
6900 if {[incr linkentercount $inc] > 0} {
6901 $w configure -cursor hand2
6903 $w configure -cursor $curtextcursor
6904 if {$linkentercount < 0} {
6905 set linkentercount 0
6910 proc viewnextline {dir} {
6914 set ymax [lindex [$canv cget -scrollregion] 3]
6915 set wnow [$canv yview]
6916 set wtop [expr {[lindex $wnow 0] * $ymax}]
6917 set newtop [expr {$wtop + $dir * $linespc}]
6920 } elseif {$newtop > $ymax} {
6923 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6926 # add a list of tag or branch names at position pos
6927 # returns the number of names inserted
6928 proc appendrefs {pos ids var} {
6929 global ctext linknum curview $var maxrefs mainheadid
6931 if {[catch {$ctext index $pos}]} {
6934 $ctext conf -state normal
6935 $ctext delete $pos "$pos lineend"
6938 foreach tag [set $var\($id\)] {
6939 lappend tags [list $tag $id]
6944 set tags [lsort -index 0 -decreasing $tags]
6947 if {[llength $tags] > $maxrefs} {
6948 # If we are displaying heads, and there are too many,
6949 # see if there are some important heads to display.
6950 # Currently this means "master" and the current head.
6952 if {$var eq "idheads"} {
6955 set hname [lindex $ti 0]
6956 set id [lindex $ti 1]
6957 if {($hname eq "master" || $id eq $mainheadid) &&
6958 [llength $itags] < $maxrefs} {
6967 set str [mc "and many more"]
6972 $ctext insert $pos "$str ([llength $tags])"
6973 set nutags [llength $tags]
6978 set id [lindex $ti 1]
6981 $ctext tag delete $lk
6982 $ctext insert $pos $sep
6983 $ctext insert $pos [lindex $ti 0] $lk
6987 $ctext tag add wwrap "$pos linestart" "$pos lineend"
6988 $ctext conf -state disabled
6989 return [expr {[llength $tags] + $nutags}]
6992 # called when we have finished computing the nearby tags
6993 proc dispneartags {delay} {
6994 global selectedline currentid showneartags tagphase
6996 if {$selectedline eq {} || !$showneartags} return
6997 after cancel dispnexttag
6999 after 200 dispnexttag
7002 after idle dispnexttag
7007 proc dispnexttag {} {
7008 global selectedline currentid showneartags tagphase ctext
7010 if {$selectedline eq {} || !$showneartags} return
7011 switch -- $tagphase {
7013 set dtags [desctags $currentid]
7015 appendrefs precedes $dtags idtags
7019 set atags [anctags $currentid]
7021 appendrefs follows $atags idtags
7025 set dheads [descheads $currentid]
7026 if {$dheads ne {}} {
7027 if {[appendrefs branch $dheads idheads] > 1
7028 && [$ctext get "branch -3c"] eq "h"} {
7029 # turn "Branch" into "Branches"
7030 $ctext conf -state normal
7031 $ctext insert "branch -2c" "es"
7032 $ctext conf -state disabled
7037 if {[incr tagphase] <= 2} {
7038 after idle dispnexttag
7042 proc make_secsel {id} {
7043 global linehtag linentag linedtag canv canv2 canv3
7045 if {![info exists linehtag($id)]} return
7047 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7048 -tags secsel -fill [$canv cget -selectbackground]]
7050 $canv2 delete secsel
7051 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7052 -tags secsel -fill [$canv2 cget -selectbackground]]
7054 $canv3 delete secsel
7055 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7056 -tags secsel -fill [$canv3 cget -selectbackground]]
7060 proc make_idmark {id} {
7061 global linehtag canv fgcolor
7063 if {![info exists linehtag($id)]} return
7065 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7066 -tags markid -outline $fgcolor]
7070 proc selectline {l isnew {desired_loc {}}} {
7071 global canv ctext commitinfo selectedline
7072 global canvy0 linespc parents children curview
7073 global currentid sha1entry
7074 global commentend idtags linknum
7075 global mergemax numcommits pending_select
7076 global cmitmode showneartags allcommits
7077 global targetrow targetid lastscrollrows
7078 global autoselect autosellen jump_to_here
7080 catch {unset pending_select}
7085 if {$l < 0 || $l >= $numcommits} return
7086 set id [commitonrow $l]
7091 if {$lastscrollrows < $numcommits} {
7095 set y [expr {$canvy0 + $l * $linespc}]
7096 set ymax [lindex [$canv cget -scrollregion] 3]
7097 set ytop [expr {$y - $linespc - 1}]
7098 set ybot [expr {$y + $linespc + 1}]
7099 set wnow [$canv yview]
7100 set wtop [expr {[lindex $wnow 0] * $ymax}]
7101 set wbot [expr {[lindex $wnow 1] * $ymax}]
7102 set wh [expr {$wbot - $wtop}]
7104 if {$ytop < $wtop} {
7105 if {$ybot < $wtop} {
7106 set newtop [expr {$y - $wh / 2.0}]
7109 if {$newtop > $wtop - $linespc} {
7110 set newtop [expr {$wtop - $linespc}]
7113 } elseif {$ybot > $wbot} {
7114 if {$ytop > $wbot} {
7115 set newtop [expr {$y - $wh / 2.0}]
7117 set newtop [expr {$ybot - $wh}]
7118 if {$newtop < $wtop + $linespc} {
7119 set newtop [expr {$wtop + $linespc}]
7123 if {$newtop != $wtop} {
7127 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7134 addtohistory [list selbyid $id 0] savecmitpos
7137 $sha1entry delete 0 end
7138 $sha1entry insert 0 $id
7140 $sha1entry selection range 0 $autosellen
7144 $ctext conf -state normal
7147 if {![info exists commitinfo($id)]} {
7150 set info $commitinfo($id)
7151 set date [formatdate [lindex $info 2]]
7152 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7153 set date [formatdate [lindex $info 4]]
7154 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7155 if {[info exists idtags($id)]} {
7156 $ctext insert end [mc "Tags:"]
7157 foreach tag $idtags($id) {
7158 $ctext insert end " $tag"
7160 $ctext insert end "\n"
7164 set olds $parents($curview,$id)
7165 if {[llength $olds] > 1} {
7168 if {$np >= $mergemax} {
7173 $ctext insert end "[mc "Parent"]: " $tag
7174 appendwithlinks [commit_descriptor $p] {}
7179 append headers "[mc "Parent"]: [commit_descriptor $p]"
7183 foreach c $children($curview,$id) {
7184 append headers "[mc "Child"]: [commit_descriptor $c]"
7187 # make anything that looks like a SHA1 ID be a clickable link
7188 appendwithlinks $headers {}
7189 if {$showneartags} {
7190 if {![info exists allcommits]} {
7193 $ctext insert end "[mc "Branch"]: "
7194 $ctext mark set branch "end -1c"
7195 $ctext mark gravity branch left
7196 $ctext insert end "\n[mc "Follows"]: "
7197 $ctext mark set follows "end -1c"
7198 $ctext mark gravity follows left
7199 $ctext insert end "\n[mc "Precedes"]: "
7200 $ctext mark set precedes "end -1c"
7201 $ctext mark gravity precedes left
7202 $ctext insert end "\n"
7205 $ctext insert end "\n"
7206 set comment [lindex $info 5]
7207 if {[string first "\r" $comment] >= 0} {
7208 set comment [string map {"\r" "\n "} $comment]
7210 appendwithlinks $comment {comment}
7212 $ctext tag remove found 1.0 end
7213 $ctext conf -state disabled
7214 set commentend [$ctext index "end - 1c"]
7216 set jump_to_here $desired_loc
7217 init_flist [mc "Comments"]
7218 if {$cmitmode eq "tree"} {
7220 } elseif {[llength $olds] <= 1} {
7227 proc selfirstline {} {
7232 proc sellastline {} {
7235 set l [expr {$numcommits - 1}]
7239 proc selnextline {dir} {
7242 if {$selectedline eq {}} return
7243 set l [expr {$selectedline + $dir}]
7248 proc selnextpage {dir} {
7249 global canv linespc selectedline numcommits
7251 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7255 allcanvs yview scroll [expr {$dir * $lpp}] units
7257 if {$selectedline eq {}} return
7258 set l [expr {$selectedline + $dir * $lpp}]
7261 } elseif {$l >= $numcommits} {
7262 set l [expr $numcommits - 1]
7268 proc unselectline {} {
7269 global selectedline currentid
7272 catch {unset currentid}
7273 allcanvs delete secsel
7277 proc reselectline {} {
7280 if {$selectedline ne {}} {
7281 selectline $selectedline 0
7285 proc addtohistory {cmd {saveproc {}}} {
7286 global history historyindex curview
7290 set elt [list $curview $cmd $saveproc {}]
7291 if {$historyindex > 0
7292 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7296 if {$historyindex < [llength $history]} {
7297 set history [lreplace $history $historyindex end $elt]
7299 lappend history $elt
7302 if {$historyindex > 1} {
7303 .tf.bar.leftbut conf -state normal
7305 .tf.bar.leftbut conf -state disabled
7307 .tf.bar.rightbut conf -state disabled
7310 # save the scrolling position of the diff display pane
7311 proc save_position {} {
7312 global historyindex history
7314 if {$historyindex < 1} return
7315 set hi [expr {$historyindex - 1}]
7316 set fn [lindex $history $hi 2]
7318 lset history $hi 3 [eval $fn]
7322 proc unset_posvars {} {
7325 if {[info exists last_posvars]} {
7326 foreach {var val} $last_posvars {
7335 global curview last_posvars
7337 set view [lindex $elt 0]
7338 set cmd [lindex $elt 1]
7339 set pv [lindex $elt 3]
7340 if {$curview != $view} {
7344 foreach {var val} $pv {
7348 set last_posvars $pv
7353 global history historyindex
7356 if {$historyindex > 1} {
7358 incr historyindex -1
7359 godo [lindex $history [expr {$historyindex - 1}]]
7360 .tf.bar.rightbut conf -state normal
7362 if {$historyindex <= 1} {
7363 .tf.bar.leftbut conf -state disabled
7368 global history historyindex
7371 if {$historyindex < [llength $history]} {
7373 set cmd [lindex $history $historyindex]
7376 .tf.bar.leftbut conf -state normal
7378 if {$historyindex >= [llength $history]} {
7379 .tf.bar.rightbut conf -state disabled
7384 global treefilelist treeidlist diffids diffmergeid treepending
7385 global nullid nullid2
7388 catch {unset diffmergeid}
7389 if {![info exists treefilelist($id)]} {
7390 if {![info exists treepending]} {
7391 if {$id eq $nullid} {
7392 set cmd [list | git ls-files]
7393 } elseif {$id eq $nullid2} {
7394 set cmd [list | git ls-files --stage -t]
7396 set cmd [list | git ls-tree -r $id]
7398 if {[catch {set gtf [open $cmd r]}]} {
7402 set treefilelist($id) {}
7403 set treeidlist($id) {}
7404 fconfigure $gtf -blocking 0 -encoding binary
7405 filerun $gtf [list gettreeline $gtf $id]
7412 proc gettreeline {gtf id} {
7413 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7416 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7417 if {$diffids eq $nullid} {
7420 set i [string first "\t" $line]
7421 if {$i < 0} continue
7422 set fname [string range $line [expr {$i+1}] end]
7423 set line [string range $line 0 [expr {$i-1}]]
7424 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7425 set sha1 [lindex $line 2]
7426 lappend treeidlist($id) $sha1
7428 if {[string index $fname 0] eq "\""} {
7429 set fname [lindex $fname 0]
7431 set fname [encoding convertfrom $fname]
7432 lappend treefilelist($id) $fname
7435 return [expr {$nl >= 1000? 2: 1}]
7439 if {$cmitmode ne "tree"} {
7440 if {![info exists diffmergeid]} {
7441 gettreediffs $diffids
7443 } elseif {$id ne $diffids} {
7452 global treefilelist treeidlist diffids nullid nullid2
7453 global ctext_file_names ctext_file_lines
7454 global ctext commentend
7456 set i [lsearch -exact $treefilelist($diffids) $f]
7458 puts "oops, $f not in list for id $diffids"
7461 if {$diffids eq $nullid} {
7462 if {[catch {set bf [open $f r]} err]} {
7463 puts "oops, can't read $f: $err"
7467 set blob [lindex $treeidlist($diffids) $i]
7468 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7469 puts "oops, error reading blob $blob: $err"
7473 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7474 filerun $bf [list getblobline $bf $diffids]
7475 $ctext config -state normal
7476 clear_ctext $commentend
7477 lappend ctext_file_names $f
7478 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7479 $ctext insert end "\n"
7480 $ctext insert end "$f\n" filesep
7481 $ctext config -state disabled
7482 $ctext yview $commentend
7486 proc getblobline {bf id} {
7487 global diffids cmitmode ctext
7489 if {$id ne $diffids || $cmitmode ne "tree"} {
7493 $ctext config -state normal
7495 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7496 $ctext insert end "$line\n"
7499 global jump_to_here ctext_file_names commentend
7501 # delete last newline
7502 $ctext delete "end - 2c" "end - 1c"
7504 if {$jump_to_here ne {} &&
7505 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7506 set lnum [expr {[lindex $jump_to_here 1] +
7507 [lindex [split $commentend .] 0]}]
7508 mark_ctext_line $lnum
7510 $ctext config -state disabled
7513 $ctext config -state disabled
7514 return [expr {$nl >= 1000? 2: 1}]
7517 proc mark_ctext_line {lnum} {
7518 global ctext markbgcolor
7520 $ctext tag delete omark
7521 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7522 $ctext tag conf omark -background $markbgcolor
7526 proc mergediff {id} {
7528 global diffids treediffs
7529 global parents curview
7533 set treediffs($id) {}
7534 set np [llength $parents($curview,$id)]
7539 proc startdiff {ids} {
7540 global treediffs diffids treepending diffmergeid nullid nullid2
7544 catch {unset diffmergeid}
7545 if {![info exists treediffs($ids)] ||
7546 [lsearch -exact $ids $nullid] >= 0 ||
7547 [lsearch -exact $ids $nullid2] >= 0} {
7548 if {![info exists treepending]} {
7556 # If the filename (name) is under any of the passed filter paths
7557 # then return true to include the file in the listing.
7558 proc path_filter {filter name} {
7559 set worktree [gitworktree]
7561 set fq_p [file normalize $p]
7562 set fq_n [file normalize [file join $worktree $name]]
7563 if {[string match [file normalize $fq_p]* $fq_n]} {
7570 proc addtocflist {ids} {
7573 add_flist $treediffs($ids)
7577 proc diffcmd {ids flags} {
7578 global log_showroot nullid nullid2
7580 set i [lsearch -exact $ids $nullid]
7581 set j [lsearch -exact $ids $nullid2]
7583 if {[llength $ids] > 1 && $j < 0} {
7584 # comparing working directory with some specific revision
7585 set cmd [concat | git diff-index $flags]
7587 lappend cmd -R [lindex $ids 1]
7589 lappend cmd [lindex $ids 0]
7592 # comparing working directory with index
7593 set cmd [concat | git diff-files $flags]
7598 } elseif {$j >= 0} {
7599 set cmd [concat | git diff-index --cached $flags]
7600 if {[llength $ids] > 1} {
7601 # comparing index with specific revision
7603 lappend cmd -R [lindex $ids 1]
7605 lappend cmd [lindex $ids 0]
7608 # comparing index with HEAD
7612 if {$log_showroot} {
7613 lappend flags --root
7615 set cmd [concat | git diff-tree -r $flags $ids]
7620 proc gettreediffs {ids} {
7621 global treediff treepending
7623 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
7625 set treepending $ids
7627 fconfigure $gdtf -blocking 0 -encoding binary
7628 filerun $gdtf [list gettreediffline $gdtf $ids]
7631 proc gettreediffline {gdtf ids} {
7632 global treediff treediffs treepending diffids diffmergeid
7633 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7638 if {$perfile_attrs} {
7639 # cache_gitattr is slow, and even slower on win32 where we
7640 # have to invoke it for only about 30 paths at a time
7642 if {[tk windowingsystem] == "win32"} {
7646 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7647 set i [string first "\t" $line]
7649 set file [string range $line [expr {$i+1}] end]
7650 if {[string index $file 0] eq "\""} {
7651 set file [lindex $file 0]
7653 set file [encoding convertfrom $file]
7654 if {$file ne [lindex $treediff end]} {
7655 lappend treediff $file
7656 lappend sublist $file
7660 if {$perfile_attrs} {
7661 cache_gitattr encoding $sublist
7664 return [expr {$nr >= $max? 2: 1}]
7667 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7669 foreach f $treediff {
7670 if {[path_filter $vfilelimit($curview) $f]} {
7674 set treediffs($ids) $flist
7676 set treediffs($ids) $treediff
7679 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7681 } elseif {$ids != $diffids} {
7682 if {![info exists diffmergeid]} {
7683 gettreediffs $diffids
7691 # empty string or positive integer
7692 proc diffcontextvalidate {v} {
7693 return [regexp {^(|[1-9][0-9]*)$} $v]
7696 proc diffcontextchange {n1 n2 op} {
7697 global diffcontextstring diffcontext
7699 if {[string is integer -strict $diffcontextstring]} {
7700 if {$diffcontextstring >= 0} {
7701 set diffcontext $diffcontextstring
7707 proc changeignorespace {} {
7711 proc changeworddiff {name ix op} {
7715 proc getblobdiffs {ids} {
7716 global blobdifffd diffids env
7717 global diffinhdr treediffs
7721 global limitdiffs vfilelimit curview
7722 global diffencoding targetline diffnparents
7723 global git_version currdiffsubmod
7726 if {[package vcompare $git_version "1.6.1"] >= 0} {
7727 set textconv "--textconv"
7730 if {[package vcompare $git_version "1.6.6"] >= 0} {
7731 set submodule "--submodule"
7733 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7737 if {$worddiff ne [mc "Line diff"]} {
7738 append cmd " --word-diff=porcelain"
7740 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7741 set cmd [concat $cmd -- $vfilelimit($curview)]
7743 if {[catch {set bdf [open $cmd r]} err]} {
7744 error_popup [mc "Error getting diffs: %s" $err]
7750 set diffencoding [get_path_encoding {}]
7751 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7752 set blobdifffd($ids) $bdf
7753 set currdiffsubmod ""
7754 filerun $bdf [list getblobdiffline $bdf $diffids]
7757 proc savecmitpos {} {
7758 global ctext cmitmode
7760 if {$cmitmode eq "tree"} {
7763 return [list target_scrollpos [$ctext index @0,0]]
7766 proc savectextpos {} {
7769 return [list target_scrollpos [$ctext index @0,0]]
7772 proc maybe_scroll_ctext {ateof} {
7773 global ctext target_scrollpos
7775 if {![info exists target_scrollpos]} return
7777 set nlines [expr {[winfo height $ctext]
7778 / [font metrics textfont -linespace]}]
7779 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7781 $ctext yview $target_scrollpos
7782 unset target_scrollpos
7785 proc setinlist {var i val} {
7788 while {[llength [set $var]] < $i} {
7791 if {[llength [set $var]] == $i} {
7798 proc makediffhdr {fname ids} {
7799 global ctext curdiffstart treediffs diffencoding
7800 global ctext_file_names jump_to_here targetline diffline
7802 set fname [encoding convertfrom $fname]
7803 set diffencoding [get_path_encoding $fname]
7804 set i [lsearch -exact $treediffs($ids) $fname]
7806 setinlist difffilestart $i $curdiffstart
7808 lset ctext_file_names end $fname
7809 set l [expr {(78 - [string length $fname]) / 2}]
7810 set pad [string range "----------------------------------------" 1 $l]
7811 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7813 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7814 set targetline [lindex $jump_to_here 1]
7819 proc getblobdiffline {bdf ids} {
7820 global diffids blobdifffd ctext curdiffstart
7821 global diffnexthead diffnextnote difffilestart
7822 global ctext_file_names ctext_file_lines
7823 global diffinhdr treediffs mergemax diffnparents
7824 global diffencoding jump_to_here targetline diffline currdiffsubmod
7828 $ctext conf -state normal
7829 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7830 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7834 if {![string compare -length 5 "diff " $line]} {
7835 if {![regexp {^diff (--cc|--git) } $line m type]} {
7836 set line [encoding convertfrom $line]
7837 $ctext insert end "$line\n" hunksep
7840 # start of a new file
7842 $ctext insert end "\n"
7843 set curdiffstart [$ctext index "end - 1c"]
7844 lappend ctext_file_names ""
7845 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7846 $ctext insert end "\n" filesep
7848 if {$type eq "--cc"} {
7849 # start of a new file in a merge diff
7850 set fname [string range $line 10 end]
7851 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7852 lappend treediffs($ids) $fname
7853 add_flist [list $fname]
7857 set line [string range $line 11 end]
7858 # If the name hasn't changed the length will be odd,
7859 # the middle char will be a space, and the two bits either
7860 # side will be a/name and b/name, or "a/name" and "b/name".
7861 # If the name has changed we'll get "rename from" and
7862 # "rename to" or "copy from" and "copy to" lines following
7863 # this, and we'll use them to get the filenames.
7864 # This complexity is necessary because spaces in the
7865 # filename(s) don't get escaped.
7866 set l [string length $line]
7867 set i [expr {$l / 2}]
7868 if {!(($l & 1) && [string index $line $i] eq " " &&
7869 [string range $line 2 [expr {$i - 1}]] eq \
7870 [string range $line [expr {$i + 3}] end])} {
7873 # unescape if quoted and chop off the a/ from the front
7874 if {[string index $line 0] eq "\""} {
7875 set fname [string range [lindex $line 0] 2 end]
7877 set fname [string range $line 2 [expr {$i - 1}]]
7880 makediffhdr $fname $ids
7882 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7883 set fname [encoding convertfrom [string range $line 16 end]]
7884 $ctext insert end "\n"
7885 set curdiffstart [$ctext index "end - 1c"]
7886 lappend ctext_file_names $fname
7887 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7888 $ctext insert end "$line\n" filesep
7889 set i [lsearch -exact $treediffs($ids) $fname]
7891 setinlist difffilestart $i $curdiffstart
7894 } elseif {![string compare -length 2 "@@" $line]} {
7895 regexp {^@@+} $line ats
7896 set line [encoding convertfrom $diffencoding $line]
7897 $ctext insert end "$line\n" hunksep
7898 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7901 set diffnparents [expr {[string length $ats] - 1}]
7904 } elseif {![string compare -length 10 "Submodule " $line]} {
7905 # start of a new submodule
7906 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7907 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7909 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7911 if {$currdiffsubmod != $fname} {
7912 $ctext insert end "\n"; # Add newline after commit message
7914 set curdiffstart [$ctext index "end - 1c"]
7915 lappend ctext_file_names ""
7916 if {$currdiffsubmod != $fname} {
7917 lappend ctext_file_lines $fname
7918 makediffhdr $fname $ids
7919 set currdiffsubmod $fname
7920 $ctext insert end "\n$line\n" filesep
7922 $ctext insert end "$line\n" filesep
7924 } elseif {![string compare -length 3 " >" $line]} {
7925 set $currdiffsubmod ""
7926 set line [encoding convertfrom $diffencoding $line]
7927 $ctext insert end "$line\n" dresult
7928 } elseif {![string compare -length 3 " <" $line]} {
7929 set $currdiffsubmod ""
7930 set line [encoding convertfrom $diffencoding $line]
7931 $ctext insert end "$line\n" d0
7932 } elseif {$diffinhdr} {
7933 if {![string compare -length 12 "rename from " $line]} {
7934 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7935 if {[string index $fname 0] eq "\""} {
7936 set fname [lindex $fname 0]
7938 set fname [encoding convertfrom $fname]
7939 set i [lsearch -exact $treediffs($ids) $fname]
7941 setinlist difffilestart $i $curdiffstart
7943 } elseif {![string compare -length 10 $line "rename to "] ||
7944 ![string compare -length 8 $line "copy to "]} {
7945 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7946 if {[string index $fname 0] eq "\""} {
7947 set fname [lindex $fname 0]
7949 makediffhdr $fname $ids
7950 } elseif {[string compare -length 3 $line "---"] == 0} {
7953 } elseif {[string compare -length 3 $line "+++"] == 0} {
7957 $ctext insert end "$line\n" filesep
7960 set line [string map {\x1A ^Z} \
7961 [encoding convertfrom $diffencoding $line]]
7962 # parse the prefix - one ' ', '-' or '+' for each parent
7963 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7964 set tag [expr {$diffnparents > 1? "m": "d"}]
7965 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7966 set words_pre_markup ""
7967 set words_post_markup ""
7968 if {[string trim $prefix " -+"] eq {}} {
7969 # prefix only has " ", "-" and "+" in it: normal diff line
7970 set num [string first "-" $prefix]
7972 set line [string range $line 1 end]
7975 # removed line, first parent with line is $num
7976 if {$num >= $mergemax} {
7979 if {$dowords && $worddiff eq [mc "Markup words"]} {
7980 $ctext insert end "\[-$line-\]" $tag$num
7982 $ctext insert end "$line" $tag$num
7985 $ctext insert end "\n" $tag$num
7989 if {[string first "+" $prefix] >= 0} {
7991 lappend tags ${tag}result
7992 if {$diffnparents > 1} {
7993 set num [string first " " $prefix]
7995 if {$num >= $mergemax} {
8001 set words_pre_markup "{+"
8002 set words_post_markup "+}"
8004 if {$targetline ne {}} {
8005 if {$diffline == $targetline} {
8006 set seehere [$ctext index "end - 1 chars"]
8012 if {$dowords && $worddiff eq [mc "Markup words"]} {
8013 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8015 $ctext insert end "$line" $tags
8018 $ctext insert end "\n" $tags
8021 } elseif {$dowords && $prefix eq "~"} {
8022 $ctext insert end "\n" {}
8024 # "\ No newline at end of file",
8025 # or something else we don't recognize
8026 $ctext insert end "$line\n" hunksep
8030 if {[info exists seehere]} {
8031 mark_ctext_line [lindex [split $seehere .] 0]
8033 maybe_scroll_ctext [eof $bdf]
8034 $ctext conf -state disabled
8039 return [expr {$nr >= 1000? 2: 1}]
8042 proc changediffdisp {} {
8043 global ctext diffelide
8045 $ctext tag conf d0 -elide [lindex $diffelide 0]
8046 $ctext tag conf dresult -elide [lindex $diffelide 1]
8049 proc highlightfile {cline} {
8050 global cflist cflist_top
8052 if {![info exists cflist_top]} return
8054 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8055 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8056 $cflist see $cline.0
8057 set cflist_top $cline
8060 proc highlightfile_for_scrollpos {topidx} {
8061 global cmitmode difffilestart
8063 if {$cmitmode eq "tree"} return
8064 if {![info exists difffilestart]} return
8066 set top [lindex [split $topidx .] 0]
8067 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8070 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8075 global difffilestart ctext cmitmode
8077 if {$cmitmode eq "tree"} return
8079 set here [$ctext index @0,0]
8080 foreach loc $difffilestart {
8081 if {[$ctext compare $loc >= $here]} {
8091 global difffilestart ctext cmitmode
8093 if {$cmitmode eq "tree"} return
8094 set here [$ctext index @0,0]
8095 foreach loc $difffilestart {
8096 if {[$ctext compare $loc > $here]} {
8103 proc clear_ctext {{first 1.0}} {
8104 global ctext smarktop smarkbot
8105 global ctext_file_names ctext_file_lines
8108 set l [lindex [split $first .] 0]
8109 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8112 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8115 $ctext delete $first end
8116 if {$first eq "1.0"} {
8117 catch {unset pendinglinks}
8119 set ctext_file_names {}
8120 set ctext_file_lines {}
8123 proc settabs {{firstab {}}} {
8124 global firsttabstop tabstop ctext have_tk85
8126 if {$firstab ne {} && $have_tk85} {
8127 set firsttabstop $firstab
8129 set w [font measure textfont "0"]
8130 if {$firsttabstop != 0} {
8131 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8132 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8133 } elseif {$have_tk85 || $tabstop != 8} {
8134 $ctext conf -tabs [expr {$tabstop * $w}]
8136 $ctext conf -tabs {}
8140 proc incrsearch {name ix op} {
8141 global ctext searchstring searchdirn
8143 if {[catch {$ctext index anchor}]} {
8144 # no anchor set, use start of selection, or of visible area
8145 set sel [$ctext tag ranges sel]
8147 $ctext mark set anchor [lindex $sel 0]
8148 } elseif {$searchdirn eq "-forwards"} {
8149 $ctext mark set anchor @0,0
8151 $ctext mark set anchor @0,[winfo height $ctext]
8154 if {$searchstring ne {}} {
8155 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8158 set mend "$here + $mlen c"
8159 $ctext tag remove sel 1.0 end
8160 $ctext tag add sel $here $mend
8161 suppress_highlighting_file_for_current_scrollpos
8162 highlightfile_for_scrollpos $here
8165 rehighlight_search_results
8169 global sstring ctext searchstring searchdirn
8172 $sstring icursor end
8173 set searchdirn -forwards
8174 if {$searchstring ne {}} {
8175 set sel [$ctext tag ranges sel]
8177 set start "[lindex $sel 0] + 1c"
8178 } elseif {[catch {set start [$ctext index anchor]}]} {
8181 set match [$ctext search -count mlen -- $searchstring $start]
8182 $ctext tag remove sel 1.0 end
8188 suppress_highlighting_file_for_current_scrollpos
8189 highlightfile_for_scrollpos $match
8190 set mend "$match + $mlen c"
8191 $ctext tag add sel $match $mend
8192 $ctext mark unset anchor
8193 rehighlight_search_results
8197 proc dosearchback {} {
8198 global sstring ctext searchstring searchdirn
8201 $sstring icursor end
8202 set searchdirn -backwards
8203 if {$searchstring ne {}} {
8204 set sel [$ctext tag ranges sel]
8206 set start [lindex $sel 0]
8207 } elseif {[catch {set start [$ctext index anchor]}]} {
8208 set start @0,[winfo height $ctext]
8210 set match [$ctext search -backwards -count ml -- $searchstring $start]
8211 $ctext tag remove sel 1.0 end
8217 suppress_highlighting_file_for_current_scrollpos
8218 highlightfile_for_scrollpos $match
8219 set mend "$match + $ml c"
8220 $ctext tag add sel $match $mend
8221 $ctext mark unset anchor
8222 rehighlight_search_results
8226 proc rehighlight_search_results {} {
8227 global ctext searchstring
8229 $ctext tag remove found 1.0 end
8230 $ctext tag remove currentsearchhit 1.0 end
8232 if {$searchstring ne {}} {
8237 proc searchmark {first last} {
8238 global ctext searchstring
8240 set sel [$ctext tag ranges sel]
8244 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8245 if {$match eq {}} break
8246 set mend "$match + $mlen c"
8247 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8248 $ctext tag add currentsearchhit $match $mend
8250 $ctext tag add found $match $mend
8255 proc searchmarkvisible {doall} {
8256 global ctext smarktop smarkbot
8258 set topline [lindex [split [$ctext index @0,0] .] 0]
8259 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8260 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8261 # no overlap with previous
8262 searchmark $topline $botline
8263 set smarktop $topline
8264 set smarkbot $botline
8266 if {$topline < $smarktop} {
8267 searchmark $topline [expr {$smarktop-1}]
8268 set smarktop $topline
8270 if {$botline > $smarkbot} {
8271 searchmark [expr {$smarkbot+1}] $botline
8272 set smarkbot $botline
8277 proc suppress_highlighting_file_for_current_scrollpos {} {
8278 global ctext suppress_highlighting_file_for_this_scrollpos
8280 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8283 proc scrolltext {f0 f1} {
8284 global searchstring cmitmode ctext
8285 global suppress_highlighting_file_for_this_scrollpos
8287 set topidx [$ctext index @0,0]
8288 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8289 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8290 highlightfile_for_scrollpos $topidx
8293 catch {unset suppress_highlighting_file_for_this_scrollpos}
8295 .bleft.bottom.sb set $f0 $f1
8296 if {$searchstring ne {}} {
8302 global linespc charspc canvx0 canvy0
8303 global xspc1 xspc2 lthickness
8305 set linespc [font metrics mainfont -linespace]
8306 set charspc [font measure mainfont "m"]
8307 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8308 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8309 set lthickness [expr {int($linespc / 9) + 1}]
8310 set xspc1(0) $linespc
8318 set ymax [lindex [$canv cget -scrollregion] 3]
8319 if {$ymax eq {} || $ymax == 0} return
8320 set span [$canv yview]
8323 allcanvs yview moveto [lindex $span 0]
8325 if {$selectedline ne {}} {
8326 selectline $selectedline 0
8327 allcanvs yview moveto [lindex $span 0]
8331 proc parsefont {f n} {
8334 set fontattr($f,family) [lindex $n 0]
8336 if {$s eq {} || $s == 0} {
8339 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8341 set fontattr($f,size) $s
8342 set fontattr($f,weight) normal
8343 set fontattr($f,slant) roman
8344 foreach style [lrange $n 2 end] {
8347 "bold" {set fontattr($f,weight) $style}
8349 "italic" {set fontattr($f,slant) $style}
8354 proc fontflags {f {isbold 0}} {
8357 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8358 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8359 -slant $fontattr($f,slant)]
8365 set n [list $fontattr($f,family) $fontattr($f,size)]
8366 if {$fontattr($f,weight) eq "bold"} {
8369 if {$fontattr($f,slant) eq "italic"} {
8375 proc incrfont {inc} {
8376 global mainfont textfont ctext canv cflist showrefstop
8377 global stopped entries fontattr
8380 set s $fontattr(mainfont,size)
8385 set fontattr(mainfont,size) $s
8386 font config mainfont -size $s
8387 font config mainfontbold -size $s
8388 set mainfont [fontname mainfont]
8389 set s $fontattr(textfont,size)
8394 set fontattr(textfont,size) $s
8395 font config textfont -size $s
8396 font config textfontbold -size $s
8397 set textfont [fontname textfont]
8404 global sha1entry sha1string
8405 if {[string length $sha1string] == 40} {
8406 $sha1entry delete 0 end
8410 proc sha1change {n1 n2 op} {
8411 global sha1string currentid sha1but
8412 if {$sha1string == {}
8413 || ([info exists currentid] && $sha1string == $currentid)} {
8418 if {[$sha1but cget -state] == $state} return
8419 if {$state == "normal"} {
8420 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8422 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8426 proc gotocommit {} {
8427 global sha1string tagids headids curview varcid
8429 if {$sha1string == {}
8430 || ([info exists currentid] && $sha1string == $currentid)} return
8431 if {[info exists tagids($sha1string)]} {
8432 set id $tagids($sha1string)
8433 } elseif {[info exists headids($sha1string)]} {
8434 set id $headids($sha1string)
8436 set id [string tolower $sha1string]
8437 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8438 set matches [longid $id]
8439 if {$matches ne {}} {
8440 if {[llength $matches] > 1} {
8441 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8444 set id [lindex $matches 0]
8447 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8448 error_popup [mc "Revision %s is not known" $sha1string]
8453 if {[commitinview $id $curview]} {
8454 selectline [rowofcommit $id] 1
8457 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8458 set msg [mc "SHA1 id %s is not known" $sha1string]
8460 set msg [mc "Revision %s is not in the current view" $sha1string]
8465 proc lineenter {x y id} {
8466 global hoverx hovery hoverid hovertimer
8467 global commitinfo canv
8469 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8473 if {[info exists hovertimer]} {
8474 after cancel $hovertimer
8476 set hovertimer [after 500 linehover]
8480 proc linemotion {x y id} {
8481 global hoverx hovery hoverid hovertimer
8483 if {[info exists hoverid] && $id == $hoverid} {
8486 if {[info exists hovertimer]} {
8487 after cancel $hovertimer
8489 set hovertimer [after 500 linehover]
8493 proc lineleave {id} {
8494 global hoverid hovertimer canv
8496 if {[info exists hoverid] && $id == $hoverid} {
8498 if {[info exists hovertimer]} {
8499 after cancel $hovertimer
8507 global hoverx hovery hoverid hovertimer
8508 global canv linespc lthickness
8509 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8513 set text [lindex $commitinfo($hoverid) 0]
8514 set ymax [lindex [$canv cget -scrollregion] 3]
8515 if {$ymax == {}} return
8516 set yfrac [lindex [$canv yview] 0]
8517 set x [expr {$hoverx + 2 * $linespc}]
8518 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8519 set x0 [expr {$x - 2 * $lthickness}]
8520 set y0 [expr {$y - 2 * $lthickness}]
8521 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8522 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8523 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8524 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8525 -width 1 -tags hover]
8527 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8528 -font mainfont -fill $linehoverfgcolor]
8532 proc clickisonarrow {id y} {
8535 set ranges [rowranges $id]
8536 set thresh [expr {2 * $lthickness + 6}]
8537 set n [expr {[llength $ranges] - 1}]
8538 for {set i 1} {$i < $n} {incr i} {
8539 set row [lindex $ranges $i]
8540 if {abs([yc $row] - $y) < $thresh} {
8547 proc arrowjump {id n y} {
8550 # 1 <-> 2, 3 <-> 4, etc...
8551 set n [expr {(($n - 1) ^ 1) + 1}]
8552 set row [lindex [rowranges $id] $n]
8554 set ymax [lindex [$canv cget -scrollregion] 3]
8555 if {$ymax eq {} || $ymax <= 0} return
8556 set view [$canv yview]
8557 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8558 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8562 allcanvs yview moveto $yfrac
8565 proc lineclick {x y id isnew} {
8566 global ctext commitinfo children canv thickerline curview
8568 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8573 # draw this line thicker than normal
8577 set ymax [lindex [$canv cget -scrollregion] 3]
8578 if {$ymax eq {}} return
8579 set yfrac [lindex [$canv yview] 0]
8580 set y [expr {$y + $yfrac * $ymax}]
8582 set dirn [clickisonarrow $id $y]
8584 arrowjump $id $dirn $y
8589 addtohistory [list lineclick $x $y $id 0] savectextpos
8591 # fill the details pane with info about this line
8592 $ctext conf -state normal
8595 $ctext insert end "[mc "Parent"]:\t"
8596 $ctext insert end $id link0
8598 set info $commitinfo($id)
8599 $ctext insert end "\n\t[lindex $info 0]\n"
8600 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8601 set date [formatdate [lindex $info 2]]
8602 $ctext insert end "\t[mc "Date"]:\t$date\n"
8603 set kids $children($curview,$id)
8605 $ctext insert end "\n[mc "Children"]:"
8607 foreach child $kids {
8609 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8610 set info $commitinfo($child)
8611 $ctext insert end "\n\t"
8612 $ctext insert end $child link$i
8613 setlink $child link$i
8614 $ctext insert end "\n\t[lindex $info 0]"
8615 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8616 set date [formatdate [lindex $info 2]]
8617 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8620 maybe_scroll_ctext 1
8621 $ctext conf -state disabled
8625 proc normalline {} {
8627 if {[info exists thickerline]} {
8634 proc selbyid {id {isnew 1}} {
8636 if {[commitinview $id $curview]} {
8637 selectline [rowofcommit $id] $isnew
8643 if {![info exists startmstime]} {
8644 set startmstime [clock clicks -milliseconds]
8646 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8649 proc rowmenu {x y id} {
8650 global rowctxmenu selectedline rowmenuid curview
8651 global nullid nullid2 fakerowmenu mainhead markedid
8655 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8660 if {[info exists markedid] && $markedid ne $id} {
8665 if {$id ne $nullid && $id ne $nullid2} {
8666 set menu $rowctxmenu
8667 if {$mainhead ne {}} {
8668 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8670 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8672 $menu entryconfigure 9 -state $mstate
8673 $menu entryconfigure 10 -state $mstate
8674 $menu entryconfigure 11 -state $mstate
8676 set menu $fakerowmenu
8678 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8679 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8680 $menu entryconfigure [mca "Make patch"] -state $state
8681 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8682 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8683 tk_popup $menu $x $y
8687 global rowmenuid markedid canv
8689 set markedid $rowmenuid
8690 make_idmark $markedid
8696 if {[info exists markedid]} {
8701 proc replace_by_kids {l r} {
8702 global curview children
8704 set id [commitonrow $r]
8705 set l [lreplace $l 0 0]
8706 foreach kid $children($curview,$id) {
8707 lappend l [rowofcommit $kid]
8709 return [lsort -integer -decreasing -unique $l]
8712 proc find_common_desc {} {
8713 global markedid rowmenuid curview children
8715 if {![info exists markedid]} return
8716 if {![commitinview $markedid $curview] ||
8717 ![commitinview $rowmenuid $curview]} return
8718 #set t1 [clock clicks -milliseconds]
8719 set l1 [list [rowofcommit $markedid]]
8720 set l2 [list [rowofcommit $rowmenuid]]
8722 set r1 [lindex $l1 0]
8723 set r2 [lindex $l2 0]
8724 if {$r1 eq {} || $r2 eq {}} break
8730 set l1 [replace_by_kids $l1 $r1]
8732 set l2 [replace_by_kids $l2 $r2]
8735 #set t2 [clock clicks -milliseconds]
8736 #puts "took [expr {$t2-$t1}]ms"
8739 proc compare_commits {} {
8740 global markedid rowmenuid curview children
8742 if {![info exists markedid]} return
8743 if {![commitinview $markedid $curview]} return
8744 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8745 do_cmp_commits $markedid $rowmenuid
8748 proc getpatchid {id} {
8751 if {![info exists patchids($id)]} {
8752 set cmd [diffcmd [list $id] {-p --root}]
8753 # trim off the initial "|"
8754 set cmd [lrange $cmd 1 end]
8756 set x [eval exec $cmd | git patch-id]
8757 set patchids($id) [lindex $x 0]
8759 set patchids($id) "error"
8762 return $patchids($id)
8765 proc do_cmp_commits {a b} {
8766 global ctext curview parents children patchids commitinfo
8768 $ctext conf -state normal
8771 for {set i 0} {$i < 100} {incr i} {
8774 if {[llength $parents($curview,$a)] > 1} {
8775 appendshortlink $a [mc "Skipping merge commit "] "\n"
8778 set patcha [getpatchid $a]
8780 if {[llength $parents($curview,$b)] > 1} {
8781 appendshortlink $b [mc "Skipping merge commit "] "\n"
8784 set patchb [getpatchid $b]
8786 if {!$skipa && !$skipb} {
8787 set heada [lindex $commitinfo($a) 0]
8788 set headb [lindex $commitinfo($b) 0]
8789 if {$patcha eq "error"} {
8790 appendshortlink $a [mc "Error getting patch ID for "] \
8791 [mc " - stopping\n"]
8794 if {$patchb eq "error"} {
8795 appendshortlink $b [mc "Error getting patch ID for "] \
8796 [mc " - stopping\n"]
8799 if {$patcha eq $patchb} {
8800 if {$heada eq $headb} {
8801 appendshortlink $a [mc "Commit "]
8802 appendshortlink $b " == " " $heada\n"
8804 appendshortlink $a [mc "Commit "] " $heada\n"
8805 appendshortlink $b [mc " is the same patch as\n "] \
8811 $ctext insert end "\n"
8812 appendshortlink $a [mc "Commit "] " $heada\n"
8813 appendshortlink $b [mc " differs from\n "] \
8815 $ctext insert end [mc "Diff of commits:\n\n"]
8816 $ctext conf -state disabled
8823 set kids [real_children $curview,$a]
8824 if {[llength $kids] != 1} {
8825 $ctext insert end "\n"
8826 appendshortlink $a [mc "Commit "] \
8827 [mc " has %s children - stopping\n" [llength $kids]]
8830 set a [lindex $kids 0]
8833 set kids [real_children $curview,$b]
8834 if {[llength $kids] != 1} {
8835 appendshortlink $b [mc "Commit "] \
8836 [mc " has %s children - stopping\n" [llength $kids]]
8839 set b [lindex $kids 0]
8842 $ctext conf -state disabled
8845 proc diffcommits {a b} {
8846 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8848 set tmpdir [gitknewtmpdir]
8849 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8850 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8852 exec git diff-tree -p --pretty $a >$fna
8853 exec git diff-tree -p --pretty $b >$fnb
8855 error_popup [mc "Error writing commit to file: %s" $err]
8859 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8861 error_popup [mc "Error diffing commits: %s" $err]
8864 set diffids [list commits $a $b]
8865 set blobdifffd($diffids) $fd
8867 set currdiffsubmod ""
8868 filerun $fd [list getblobdiffline $fd $diffids]
8871 proc diffvssel {dirn} {
8872 global rowmenuid selectedline
8874 if {$selectedline eq {}} return
8876 set oldid [commitonrow $selectedline]
8877 set newid $rowmenuid
8879 set oldid $rowmenuid
8880 set newid [commitonrow $selectedline]
8882 addtohistory [list doseldiff $oldid $newid] savectextpos
8883 doseldiff $oldid $newid
8886 proc diffvsmark {dirn} {
8887 global rowmenuid markedid
8889 if {![info exists markedid]} return
8892 set newid $rowmenuid
8894 set oldid $rowmenuid
8897 addtohistory [list doseldiff $oldid $newid] savectextpos
8898 doseldiff $oldid $newid
8901 proc doseldiff {oldid newid} {
8905 $ctext conf -state normal
8907 init_flist [mc "Top"]
8908 $ctext insert end "[mc "From"] "
8909 $ctext insert end $oldid link0
8910 setlink $oldid link0
8911 $ctext insert end "\n "
8912 $ctext insert end [lindex $commitinfo($oldid) 0]
8913 $ctext insert end "\n\n[mc "To"] "
8914 $ctext insert end $newid link1
8915 setlink $newid link1
8916 $ctext insert end "\n "
8917 $ctext insert end [lindex $commitinfo($newid) 0]
8918 $ctext insert end "\n"
8919 $ctext conf -state disabled
8920 $ctext tag remove found 1.0 end
8921 startdiff [list $oldid $newid]
8925 global rowmenuid currentid commitinfo patchtop patchnum NS
8927 if {![info exists currentid]} return
8928 set oldid $currentid
8929 set oldhead [lindex $commitinfo($oldid) 0]
8930 set newid $rowmenuid
8931 set newhead [lindex $commitinfo($newid) 0]
8934 catch {destroy $top}
8936 make_transient $top .
8937 ${NS}::label $top.title -text [mc "Generate patch"]
8938 grid $top.title - -pady 10
8939 ${NS}::label $top.from -text [mc "From:"]
8940 ${NS}::entry $top.fromsha1 -width 40
8941 $top.fromsha1 insert 0 $oldid
8942 $top.fromsha1 conf -state readonly
8943 grid $top.from $top.fromsha1 -sticky w
8944 ${NS}::entry $top.fromhead -width 60
8945 $top.fromhead insert 0 $oldhead
8946 $top.fromhead conf -state readonly
8947 grid x $top.fromhead -sticky w
8948 ${NS}::label $top.to -text [mc "To:"]
8949 ${NS}::entry $top.tosha1 -width 40
8950 $top.tosha1 insert 0 $newid
8951 $top.tosha1 conf -state readonly
8952 grid $top.to $top.tosha1 -sticky w
8953 ${NS}::entry $top.tohead -width 60
8954 $top.tohead insert 0 $newhead
8955 $top.tohead conf -state readonly
8956 grid x $top.tohead -sticky w
8957 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
8958 grid $top.rev x -pady 10 -padx 5
8959 ${NS}::label $top.flab -text [mc "Output file:"]
8960 ${NS}::entry $top.fname -width 60
8961 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8963 grid $top.flab $top.fname -sticky w
8964 ${NS}::frame $top.buts
8965 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8966 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8967 bind $top <Key-Return> mkpatchgo
8968 bind $top <Key-Escape> mkpatchcan
8969 grid $top.buts.gen $top.buts.can
8970 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8971 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8972 grid $top.buts - -pady 10 -sticky ew
8976 proc mkpatchrev {} {
8979 set oldid [$patchtop.fromsha1 get]
8980 set oldhead [$patchtop.fromhead get]
8981 set newid [$patchtop.tosha1 get]
8982 set newhead [$patchtop.tohead get]
8983 foreach e [list fromsha1 fromhead tosha1 tohead] \
8984 v [list $newid $newhead $oldid $oldhead] {
8985 $patchtop.$e conf -state normal
8986 $patchtop.$e delete 0 end
8987 $patchtop.$e insert 0 $v
8988 $patchtop.$e conf -state readonly
8993 global patchtop nullid nullid2
8995 set oldid [$patchtop.fromsha1 get]
8996 set newid [$patchtop.tosha1 get]
8997 set fname [$patchtop.fname get]
8998 set cmd [diffcmd [list $oldid $newid] -p]
8999 # trim off the initial "|"
9000 set cmd [lrange $cmd 1 end]
9001 lappend cmd >$fname &
9002 if {[catch {eval exec $cmd} err]} {
9003 error_popup "[mc "Error creating patch:"] $err" $patchtop
9005 catch {destroy $patchtop}
9009 proc mkpatchcan {} {
9012 catch {destroy $patchtop}
9017 global rowmenuid mktagtop commitinfo NS
9021 catch {destroy $top}
9023 make_transient $top .
9024 ${NS}::label $top.title -text [mc "Create tag"]
9025 grid $top.title - -pady 10
9026 ${NS}::label $top.id -text [mc "ID:"]
9027 ${NS}::entry $top.sha1 -width 40
9028 $top.sha1 insert 0 $rowmenuid
9029 $top.sha1 conf -state readonly
9030 grid $top.id $top.sha1 -sticky w
9031 ${NS}::entry $top.head -width 60
9032 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9033 $top.head conf -state readonly
9034 grid x $top.head -sticky w
9035 ${NS}::label $top.tlab -text [mc "Tag name:"]
9036 ${NS}::entry $top.tag -width 60
9037 grid $top.tlab $top.tag -sticky w
9038 ${NS}::label $top.op -text [mc "Tag message is optional"]
9039 grid $top.op -columnspan 2 -sticky we
9040 ${NS}::label $top.mlab -text [mc "Tag message:"]
9041 ${NS}::entry $top.msg -width 60
9042 grid $top.mlab $top.msg -sticky w
9043 ${NS}::frame $top.buts
9044 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9045 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9046 bind $top <Key-Return> mktaggo
9047 bind $top <Key-Escape> mktagcan
9048 grid $top.buts.gen $top.buts.can
9049 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9050 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9051 grid $top.buts - -pady 10 -sticky ew
9056 global mktagtop env tagids idtags
9058 set id [$mktagtop.sha1 get]
9059 set tag [$mktagtop.tag get]
9060 set msg [$mktagtop.msg get]
9062 error_popup [mc "No tag name specified"] $mktagtop
9065 if {[info exists tagids($tag)]} {
9066 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9071 exec git tag -a -m $msg $tag $id
9073 exec git tag $tag $id
9076 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9080 set tagids($tag) $id
9081 lappend idtags($id) $tag
9089 proc redrawtags {id} {
9090 global canv linehtag idpos currentid curview cmitlisted markedid
9091 global canvxmax iddrawn circleitem mainheadid circlecolors
9092 global mainheadcirclecolor
9094 if {![commitinview $id $curview]} return
9095 if {![info exists iddrawn($id)]} return
9096 set row [rowofcommit $id]
9097 if {$id eq $mainheadid} {
9098 set ofill $mainheadcirclecolor
9100 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9102 $canv itemconf $circleitem($row) -fill $ofill
9103 $canv delete tag.$id
9104 set xt [eval drawtags $id $idpos($id)]
9105 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9106 set text [$canv itemcget $linehtag($id) -text]
9107 set font [$canv itemcget $linehtag($id) -font]
9108 set xr [expr {$xt + [font measure $font $text]}]
9109 if {$xr > $canvxmax} {
9113 if {[info exists currentid] && $currentid == $id} {
9116 if {[info exists markedid] && $markedid eq $id} {
9124 catch {destroy $mktagtop}
9129 if {![domktag]} return
9133 proc writecommit {} {
9134 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9136 set top .writecommit
9138 catch {destroy $top}
9140 make_transient $top .
9141 ${NS}::label $top.title -text [mc "Write commit to file"]
9142 grid $top.title - -pady 10
9143 ${NS}::label $top.id -text [mc "ID:"]
9144 ${NS}::entry $top.sha1 -width 40
9145 $top.sha1 insert 0 $rowmenuid
9146 $top.sha1 conf -state readonly
9147 grid $top.id $top.sha1 -sticky w
9148 ${NS}::entry $top.head -width 60
9149 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9150 $top.head conf -state readonly
9151 grid x $top.head -sticky w
9152 ${NS}::label $top.clab -text [mc "Command:"]
9153 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9154 grid $top.clab $top.cmd -sticky w -pady 10
9155 ${NS}::label $top.flab -text [mc "Output file:"]
9156 ${NS}::entry $top.fname -width 60
9157 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9158 grid $top.flab $top.fname -sticky w
9159 ${NS}::frame $top.buts
9160 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9161 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9162 bind $top <Key-Return> wrcomgo
9163 bind $top <Key-Escape> wrcomcan
9164 grid $top.buts.gen $top.buts.can
9165 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9166 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9167 grid $top.buts - -pady 10 -sticky ew
9174 set id [$wrcomtop.sha1 get]
9175 set cmd "echo $id | [$wrcomtop.cmd get]"
9176 set fname [$wrcomtop.fname get]
9177 if {[catch {exec sh -c $cmd >$fname &} err]} {
9178 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9180 catch {destroy $wrcomtop}
9187 catch {destroy $wrcomtop}
9192 global rowmenuid mkbrtop NS
9195 catch {destroy $top}
9197 make_transient $top .
9198 ${NS}::label $top.title -text [mc "Create new branch"]
9199 grid $top.title - -pady 10
9200 ${NS}::label $top.id -text [mc "ID:"]
9201 ${NS}::entry $top.sha1 -width 40
9202 $top.sha1 insert 0 $rowmenuid
9203 $top.sha1 conf -state readonly
9204 grid $top.id $top.sha1 -sticky w
9205 ${NS}::label $top.nlab -text [mc "Name:"]
9206 ${NS}::entry $top.name -width 40
9207 grid $top.nlab $top.name -sticky w
9208 ${NS}::frame $top.buts
9209 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9210 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9211 bind $top <Key-Return> [list mkbrgo $top]
9212 bind $top <Key-Escape> "catch {destroy $top}"
9213 grid $top.buts.go $top.buts.can
9214 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9215 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9216 grid $top.buts - -pady 10 -sticky ew
9221 global headids idheads
9223 set name [$top.name get]
9224 set id [$top.sha1 get]
9228 error_popup [mc "Please specify a name for the new branch"] $top
9231 if {[info exists headids($name)]} {
9232 if {![confirm_popup [mc \
9233 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9236 set old_id $headids($name)
9239 catch {destroy $top}
9240 lappend cmdargs $name $id
9244 eval exec git branch $cmdargs
9250 if {$old_id ne {}} {
9256 set headids($name) $id
9257 lappend idheads($id) $name
9266 proc exec_citool {tool_args {baseid {}}} {
9267 global commitinfo env
9269 set save_env [array get env GIT_AUTHOR_*]
9271 if {$baseid ne {}} {
9272 if {![info exists commitinfo($baseid)]} {
9275 set author [lindex $commitinfo($baseid) 1]
9276 set date [lindex $commitinfo($baseid) 2]
9277 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9278 $author author name email]
9280 set env(GIT_AUTHOR_NAME) $name
9281 set env(GIT_AUTHOR_EMAIL) $email
9282 set env(GIT_AUTHOR_DATE) $date
9286 eval exec git citool $tool_args &
9288 array unset env GIT_AUTHOR_*
9289 array set env $save_env
9292 proc cherrypick {} {
9293 global rowmenuid curview
9294 global mainhead mainheadid
9297 set oldhead [exec git rev-parse HEAD]
9298 set dheads [descheads $rowmenuid]
9299 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9300 set ok [confirm_popup [mc "Commit %s is already\
9301 included in branch %s -- really re-apply it?" \
9302 [string range $rowmenuid 0 7] $mainhead]]
9305 nowbusy cherrypick [mc "Cherry-picking"]
9307 # Unfortunately git-cherry-pick writes stuff to stderr even when
9308 # no error occurs, and exec takes that as an indication of error...
9309 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9312 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9314 error_popup [mc "Cherry-pick failed because of local changes\
9315 to file '%s'.\nPlease commit, reset or stash\
9316 your changes and try again." $fname]
9317 } elseif {[regexp -line \
9318 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9320 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9321 conflict.\nDo you wish to run git citool to\
9323 # Force citool to read MERGE_MSG
9324 file delete [file join $gitdir "GITGUI_MSG"]
9325 exec_citool {} $rowmenuid
9333 set newhead [exec git rev-parse HEAD]
9334 if {$newhead eq $oldhead} {
9336 error_popup [mc "No changes committed"]
9339 addnewchild $newhead $oldhead
9340 if {[commitinview $oldhead $curview]} {
9341 # XXX this isn't right if we have a path limit...
9342 insertrow $newhead $oldhead $curview
9343 if {$mainhead ne {}} {
9344 movehead $newhead $mainhead
9345 movedhead $newhead $mainhead
9347 set mainheadid $newhead
9356 global mainhead rowmenuid confirm_ok resettype NS
9359 set w ".confirmreset"
9362 wm title $w [mc "Confirm reset"]
9363 ${NS}::label $w.m -text \
9364 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9365 pack $w.m -side top -fill x -padx 20 -pady 20
9366 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9368 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9369 -text [mc "Soft: Leave working tree and index untouched"]
9370 grid $w.f.soft -sticky w
9371 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9372 -text [mc "Mixed: Leave working tree untouched, reset index"]
9373 grid $w.f.mixed -sticky w
9374 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9375 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9376 grid $w.f.hard -sticky w
9377 pack $w.f -side top -fill x -padx 4
9378 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9379 pack $w.ok -side left -fill x -padx 20 -pady 20
9380 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9381 bind $w <Key-Escape> [list destroy $w]
9382 pack $w.cancel -side right -fill x -padx 20 -pady 20
9383 bind $w <Visibility> "grab $w; focus $w"
9385 if {!$confirm_ok} return
9386 if {[catch {set fd [open \
9387 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9391 filerun $fd [list readresetstat $fd]
9392 nowbusy reset [mc "Resetting"]
9397 proc readresetstat {fd} {
9398 global mainhead mainheadid showlocalchanges rprogcoord
9400 if {[gets $fd line] >= 0} {
9401 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9402 set rprogcoord [expr {1.0 * $m / $n}]
9410 if {[catch {close $fd} err]} {
9413 set oldhead $mainheadid
9414 set newhead [exec git rev-parse HEAD]
9415 if {$newhead ne $oldhead} {
9416 movehead $newhead $mainhead
9417 movedhead $newhead $mainhead
9418 set mainheadid $newhead
9422 if {$showlocalchanges} {
9428 # context menu for a head
9429 proc headmenu {x y id head} {
9430 global headmenuid headmenuhead headctxmenu mainhead
9434 set headmenuhead $head
9436 if {[string match "remotes/*" $head]} {
9439 if {$head eq $mainhead} {
9442 $headctxmenu entryconfigure 0 -state $state
9443 $headctxmenu entryconfigure 1 -state $state
9444 tk_popup $headctxmenu $x $y
9448 global headmenuid headmenuhead headids
9449 global showlocalchanges
9451 # check the tree is clean first??
9452 nowbusy checkout [mc "Checking out"]
9456 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9460 if {$showlocalchanges} {
9464 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9468 proc readcheckoutstat {fd newhead newheadid} {
9469 global mainhead mainheadid headids showlocalchanges progresscoords
9470 global viewmainheadid curview
9472 if {[gets $fd line] >= 0} {
9473 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9474 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9479 set progresscoords {0 0}
9482 if {[catch {close $fd} err]} {
9485 set oldmainid $mainheadid
9486 set mainhead $newhead
9487 set mainheadid $newheadid
9488 set viewmainheadid($curview) $newheadid
9489 redrawtags $oldmainid
9490 redrawtags $newheadid
9492 if {$showlocalchanges} {
9498 global headmenuid headmenuhead mainhead
9501 set head $headmenuhead
9503 # this check shouldn't be needed any more...
9504 if {$head eq $mainhead} {
9505 error_popup [mc "Cannot delete the currently checked-out branch"]
9508 set dheads [descheads $id]
9509 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9510 # the stuff on this branch isn't on any other branch
9511 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9512 branch.\nReally delete branch %s?" $head $head]]} return
9516 if {[catch {exec git branch -D $head} err]} {
9521 removehead $id $head
9522 removedhead $id $head
9529 # Display a list of tags and heads
9531 global showrefstop bgcolor fgcolor selectbgcolor NS
9532 global bglist fglist reflistfilter reflist maincursor
9535 set showrefstop $top
9536 if {[winfo exists $top]} {
9542 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9543 make_transient $top .
9544 text $top.list -background $bgcolor -foreground $fgcolor \
9545 -selectbackground $selectbgcolor -font mainfont \
9546 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9547 -width 30 -height 20 -cursor $maincursor \
9548 -spacing1 1 -spacing3 1 -state disabled
9549 $top.list tag configure highlight -background $selectbgcolor
9550 lappend bglist $top.list
9551 lappend fglist $top.list
9552 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9553 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9554 grid $top.list $top.ysb -sticky nsew
9555 grid $top.xsb x -sticky ew
9557 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9558 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9559 set reflistfilter "*"
9560 trace add variable reflistfilter write reflistfilter_change
9561 pack $top.f.e -side right -fill x -expand 1
9562 pack $top.f.l -side left
9563 grid $top.f - -sticky ew -pady 2
9564 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9565 bind $top <Key-Escape> [list destroy $top]
9567 grid columnconfigure $top 0 -weight 1
9568 grid rowconfigure $top 0 -weight 1
9569 bind $top.list <1> {break}
9570 bind $top.list <B1-Motion> {break}
9571 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9576 proc sel_reflist {w x y} {
9577 global showrefstop reflist headids tagids otherrefids
9579 if {![winfo exists $showrefstop]} return
9580 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9581 set ref [lindex $reflist [expr {$l-1}]]
9582 set n [lindex $ref 0]
9583 switch -- [lindex $ref 1] {
9584 "H" {selbyid $headids($n)}
9585 "T" {selbyid $tagids($n)}
9586 "o" {selbyid $otherrefids($n)}
9588 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9591 proc unsel_reflist {} {
9594 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9595 $showrefstop.list tag remove highlight 0.0 end
9598 proc reflistfilter_change {n1 n2 op} {
9599 global reflistfilter
9601 after cancel refill_reflist
9602 after 200 refill_reflist
9605 proc refill_reflist {} {
9606 global reflist reflistfilter showrefstop headids tagids otherrefids
9609 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9611 foreach n [array names headids] {
9612 if {[string match $reflistfilter $n]} {
9613 if {[commitinview $headids($n) $curview]} {
9614 lappend refs [list $n H]
9616 interestedin $headids($n) {run refill_reflist}
9620 foreach n [array names tagids] {
9621 if {[string match $reflistfilter $n]} {
9622 if {[commitinview $tagids($n) $curview]} {
9623 lappend refs [list $n T]
9625 interestedin $tagids($n) {run refill_reflist}
9629 foreach n [array names otherrefids] {
9630 if {[string match $reflistfilter $n]} {
9631 if {[commitinview $otherrefids($n) $curview]} {
9632 lappend refs [list $n o]
9634 interestedin $otherrefids($n) {run refill_reflist}
9638 set refs [lsort -index 0 $refs]
9639 if {$refs eq $reflist} return
9641 # Update the contents of $showrefstop.list according to the
9642 # differences between $reflist (old) and $refs (new)
9643 $showrefstop.list conf -state normal
9644 $showrefstop.list insert end "\n"
9647 while {$i < [llength $reflist] || $j < [llength $refs]} {
9648 if {$i < [llength $reflist]} {
9649 if {$j < [llength $refs]} {
9650 set cmp [string compare [lindex $reflist $i 0] \
9651 [lindex $refs $j 0]]
9653 set cmp [string compare [lindex $reflist $i 1] \
9654 [lindex $refs $j 1]]
9664 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9672 set l [expr {$j + 1}]
9673 $showrefstop.list image create $l.0 -align baseline \
9674 -image reficon-[lindex $refs $j 1] -padx 2
9675 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9681 # delete last newline
9682 $showrefstop.list delete end-2c end-1c
9683 $showrefstop.list conf -state disabled
9686 # Stuff for finding nearby tags
9687 proc getallcommits {} {
9688 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9689 global idheads idtags idotherrefs allparents tagobjid
9692 if {![info exists allcommits]} {
9698 set allccache [file join $gitdir "gitk.cache"]
9700 set f [open $allccache r]
9709 set cmd [list | git rev-list --parents]
9710 set allcupdate [expr {$seeds ne {}}]
9714 set refs [concat [array names idheads] [array names idtags] \
9715 [array names idotherrefs]]
9718 foreach name [array names tagobjid] {
9719 lappend tagobjs $tagobjid($name)
9721 foreach id [lsort -unique $refs] {
9722 if {![info exists allparents($id)] &&
9723 [lsearch -exact $tagobjs $id] < 0} {
9734 set fd [open [concat $cmd $ids] r]
9735 fconfigure $fd -blocking 0
9738 filerun $fd [list getallclines $fd]
9744 # Since most commits have 1 parent and 1 child, we group strings of
9745 # such commits into "arcs" joining branch/merge points (BMPs), which
9746 # are commits that either don't have 1 parent or don't have 1 child.
9748 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9749 # arcout(id) - outgoing arcs for BMP
9750 # arcids(a) - list of IDs on arc including end but not start
9751 # arcstart(a) - BMP ID at start of arc
9752 # arcend(a) - BMP ID at end of arc
9753 # growing(a) - arc a is still growing
9754 # arctags(a) - IDs out of arcids (excluding end) that have tags
9755 # archeads(a) - IDs out of arcids (excluding end) that have heads
9756 # The start of an arc is at the descendent end, so "incoming" means
9757 # coming from descendents, and "outgoing" means going towards ancestors.
9759 proc getallclines {fd} {
9760 global allparents allchildren idtags idheads nextarc
9761 global arcnos arcids arctags arcout arcend arcstart archeads growing
9762 global seeds allcommits cachedarcs allcupdate
9765 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9766 set id [lindex $line 0]
9767 if {[info exists allparents($id)]} {
9772 set olds [lrange $line 1 end]
9773 set allparents($id) $olds
9774 if {![info exists allchildren($id)]} {
9775 set allchildren($id) {}
9780 if {[llength $olds] == 1 && [llength $a] == 1} {
9781 lappend arcids($a) $id
9782 if {[info exists idtags($id)]} {
9783 lappend arctags($a) $id
9785 if {[info exists idheads($id)]} {
9786 lappend archeads($a) $id
9788 if {[info exists allparents($olds)]} {
9789 # seen parent already
9790 if {![info exists arcout($olds)]} {
9793 lappend arcids($a) $olds
9794 set arcend($a) $olds
9797 lappend allchildren($olds) $id
9798 lappend arcnos($olds) $a
9802 foreach a $arcnos($id) {
9803 lappend arcids($a) $id
9810 lappend allchildren($p) $id
9811 set a [incr nextarc]
9812 set arcstart($a) $id
9819 if {[info exists allparents($p)]} {
9820 # seen it already, may need to make a new branch
9821 if {![info exists arcout($p)]} {
9824 lappend arcids($a) $p
9828 lappend arcnos($p) $a
9833 global cached_dheads cached_dtags cached_atags
9834 catch {unset cached_dheads}
9835 catch {unset cached_dtags}
9836 catch {unset cached_atags}
9839 return [expr {$nid >= 1000? 2: 1}]
9843 fconfigure $fd -blocking 1
9846 # got an error reading the list of commits
9847 # if we were updating, try rereading the whole thing again
9853 error_popup "[mc "Error reading commit topology information;\
9854 branch and preceding/following tag information\
9855 will be incomplete."]\n($err)"
9858 if {[incr allcommits -1] == 0} {
9868 proc recalcarc {a} {
9869 global arctags archeads arcids idtags idheads
9873 foreach id [lrange $arcids($a) 0 end-1] {
9874 if {[info exists idtags($id)]} {
9877 if {[info exists idheads($id)]} {
9882 set archeads($a) $ah
9886 global arcnos arcids nextarc arctags archeads idtags idheads
9887 global arcstart arcend arcout allparents growing
9890 if {[llength $a] != 1} {
9891 puts "oops splitarc called but [llength $a] arcs already"
9895 set i [lsearch -exact $arcids($a) $p]
9897 puts "oops splitarc $p not in arc $a"
9900 set na [incr nextarc]
9901 if {[info exists arcend($a)]} {
9902 set arcend($na) $arcend($a)
9904 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9905 set j [lsearch -exact $arcnos($l) $a]
9906 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9908 set tail [lrange $arcids($a) [expr {$i+1}] end]
9909 set arcids($a) [lrange $arcids($a) 0 $i]
9911 set arcstart($na) $p
9913 set arcids($na) $tail
9914 if {[info exists growing($a)]} {
9920 if {[llength $arcnos($id)] == 1} {
9923 set j [lsearch -exact $arcnos($id) $a]
9924 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9928 # reconstruct tags and heads lists
9929 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9934 set archeads($na) {}
9938 # Update things for a new commit added that is a child of one
9939 # existing commit. Used when cherry-picking.
9940 proc addnewchild {id p} {
9941 global allparents allchildren idtags nextarc
9942 global arcnos arcids arctags arcout arcend arcstart archeads growing
9943 global seeds allcommits
9945 if {![info exists allcommits] || ![info exists arcnos($p)]} return
9946 set allparents($id) [list $p]
9947 set allchildren($id) {}
9950 lappend allchildren($p) $id
9951 set a [incr nextarc]
9952 set arcstart($a) $id
9955 set arcids($a) [list $p]
9957 if {![info exists arcout($p)]} {
9960 lappend arcnos($p) $a
9961 set arcout($id) [list $a]
9964 # This implements a cache for the topology information.
9965 # The cache saves, for each arc, the start and end of the arc,
9966 # the ids on the arc, and the outgoing arcs from the end.
9967 proc readcache {f} {
9968 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
9969 global idtags idheads allparents cachedarcs possible_seeds seeds growing
9974 if {$lim - $a > 500} {
9975 set lim [expr {$a + 500}]
9979 # finish reading the cache and setting up arctags, etc.
9981 if {$line ne "1"} {error "bad final version"}
9983 foreach id [array names idtags] {
9984 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9985 [llength $allparents($id)] == 1} {
9986 set a [lindex $arcnos($id) 0]
9987 if {$arctags($a) eq {}} {
9992 foreach id [array names idheads] {
9993 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9994 [llength $allparents($id)] == 1} {
9995 set a [lindex $arcnos($id) 0]
9996 if {$archeads($a) eq {}} {
10001 foreach id [lsort -unique $possible_seeds] {
10002 if {$arcnos($id) eq {}} {
10008 while {[incr a] <= $lim} {
10010 if {[llength $line] != 3} {error "bad line"}
10011 set s [lindex $line 0]
10012 set arcstart($a) $s
10013 lappend arcout($s) $a
10014 if {![info exists arcnos($s)]} {
10015 lappend possible_seeds $s
10018 set e [lindex $line 1]
10023 if {![info exists arcout($e)]} {
10027 set arcids($a) [lindex $line 2]
10028 foreach id $arcids($a) {
10029 lappend allparents($s) $id
10031 lappend arcnos($id) $a
10033 if {![info exists allparents($s)]} {
10034 set allparents($s) {}
10037 set archeads($a) {}
10039 set nextarc [expr {$a - 1}]
10051 proc getcache {f} {
10052 global nextarc cachedarcs possible_seeds
10056 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10057 # make sure it's an integer
10058 set cachedarcs [expr {int([lindex $line 1])}]
10059 if {$cachedarcs < 0} {error "bad number of arcs"}
10061 set possible_seeds {}
10069 proc dropcache {err} {
10070 global allcwait nextarc cachedarcs seeds
10072 #puts "dropping cache ($err)"
10073 foreach v {arcnos arcout arcids arcstart arcend growing \
10074 arctags archeads allparents allchildren} {
10085 proc writecache {f} {
10086 global cachearc cachedarcs allccache
10087 global arcstart arcend arcnos arcids arcout
10090 set lim $cachedarcs
10091 if {$lim - $a > 1000} {
10092 set lim [expr {$a + 1000}]
10095 while {[incr a] <= $lim} {
10096 if {[info exists arcend($a)]} {
10097 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10099 puts $f [list $arcstart($a) {} $arcids($a)]
10104 catch {file delete $allccache}
10105 #puts "writing cache failed ($err)"
10108 set cachearc [expr {$a - 1}]
10109 if {$a > $cachedarcs} {
10117 proc savecache {} {
10118 global nextarc cachedarcs cachearc allccache
10120 if {$nextarc == $cachedarcs} return
10122 set cachedarcs $nextarc
10124 set f [open $allccache w]
10125 puts $f [list 1 $cachedarcs]
10130 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10131 # or 0 if neither is true.
10132 proc anc_or_desc {a b} {
10133 global arcout arcstart arcend arcnos cached_isanc
10135 if {$arcnos($a) eq $arcnos($b)} {
10136 # Both are on the same arc(s); either both are the same BMP,
10137 # or if one is not a BMP, the other is also not a BMP or is
10138 # the BMP at end of the arc (and it only has 1 incoming arc).
10139 # Or both can be BMPs with no incoming arcs.
10140 if {$a eq $b || $arcnos($a) eq {}} {
10143 # assert {[llength $arcnos($a)] == 1}
10144 set arc [lindex $arcnos($a) 0]
10145 set i [lsearch -exact $arcids($arc) $a]
10146 set j [lsearch -exact $arcids($arc) $b]
10147 if {$i < 0 || $i > $j} {
10154 if {![info exists arcout($a)]} {
10155 set arc [lindex $arcnos($a) 0]
10156 if {[info exists arcend($arc)]} {
10157 set aend $arcend($arc)
10161 set a $arcstart($arc)
10165 if {![info exists arcout($b)]} {
10166 set arc [lindex $arcnos($b) 0]
10167 if {[info exists arcend($arc)]} {
10168 set bend $arcend($arc)
10172 set b $arcstart($arc)
10182 if {[info exists cached_isanc($a,$bend)]} {
10183 if {$cached_isanc($a,$bend)} {
10187 if {[info exists cached_isanc($b,$aend)]} {
10188 if {$cached_isanc($b,$aend)} {
10191 if {[info exists cached_isanc($a,$bend)]} {
10196 set todo [list $a $b]
10199 for {set i 0} {$i < [llength $todo]} {incr i} {
10200 set x [lindex $todo $i]
10201 if {$anc($x) eq {}} {
10204 foreach arc $arcnos($x) {
10205 set xd $arcstart($arc)
10206 if {$xd eq $bend} {
10207 set cached_isanc($a,$bend) 1
10208 set cached_isanc($b,$aend) 0
10210 } elseif {$xd eq $aend} {
10211 set cached_isanc($b,$aend) 1
10212 set cached_isanc($a,$bend) 0
10215 if {![info exists anc($xd)]} {
10216 set anc($xd) $anc($x)
10218 } elseif {$anc($xd) ne $anc($x)} {
10223 set cached_isanc($a,$bend) 0
10224 set cached_isanc($b,$aend) 0
10228 # This identifies whether $desc has an ancestor that is
10229 # a growing tip of the graph and which is not an ancestor of $anc
10230 # and returns 0 if so and 1 if not.
10231 # If we subsequently discover a tag on such a growing tip, and that
10232 # turns out to be a descendent of $anc (which it could, since we
10233 # don't necessarily see children before parents), then $desc
10234 # isn't a good choice to display as a descendent tag of
10235 # $anc (since it is the descendent of another tag which is
10236 # a descendent of $anc). Similarly, $anc isn't a good choice to
10237 # display as a ancestor tag of $desc.
10239 proc is_certain {desc anc} {
10240 global arcnos arcout arcstart arcend growing problems
10243 if {[llength $arcnos($anc)] == 1} {
10244 # tags on the same arc are certain
10245 if {$arcnos($desc) eq $arcnos($anc)} {
10248 if {![info exists arcout($anc)]} {
10249 # if $anc is partway along an arc, use the start of the arc instead
10250 set a [lindex $arcnos($anc) 0]
10251 set anc $arcstart($a)
10254 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10257 set a [lindex $arcnos($desc) 0]
10263 set anclist [list $x]
10267 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10268 set x [lindex $anclist $i]
10273 foreach a $arcout($x) {
10274 if {[info exists growing($a)]} {
10275 if {![info exists growanc($x)] && $dl($x)} {
10281 if {[info exists dl($y)]} {
10285 if {![info exists done($y)]} {
10288 if {[info exists growanc($x)]} {
10292 for {set k 0} {$k < [llength $xl]} {incr k} {
10293 set z [lindex $xl $k]
10294 foreach c $arcout($z) {
10295 if {[info exists arcend($c)]} {
10297 if {[info exists dl($v)] && $dl($v)} {
10299 if {![info exists done($v)]} {
10302 if {[info exists growanc($v)]} {
10312 } elseif {$y eq $anc || !$dl($x)} {
10323 foreach x [array names growanc] {
10332 proc validate_arctags {a} {
10333 global arctags idtags
10336 set na $arctags($a)
10337 foreach id $arctags($a) {
10339 if {![info exists idtags($id)]} {
10340 set na [lreplace $na $i $i]
10344 set arctags($a) $na
10347 proc validate_archeads {a} {
10348 global archeads idheads
10351 set na $archeads($a)
10352 foreach id $archeads($a) {
10354 if {![info exists idheads($id)]} {
10355 set na [lreplace $na $i $i]
10359 set archeads($a) $na
10362 # Return the list of IDs that have tags that are descendents of id,
10363 # ignoring IDs that are descendents of IDs already reported.
10364 proc desctags {id} {
10365 global arcnos arcstart arcids arctags idtags allparents
10366 global growing cached_dtags
10368 if {![info exists allparents($id)]} {
10371 set t1 [clock clicks -milliseconds]
10373 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10374 # part-way along an arc; check that arc first
10375 set a [lindex $arcnos($id) 0]
10376 if {$arctags($a) ne {}} {
10377 validate_arctags $a
10378 set i [lsearch -exact $arcids($a) $id]
10380 foreach t $arctags($a) {
10381 set j [lsearch -exact $arcids($a) $t]
10382 if {$j >= $i} break
10389 set id $arcstart($a)
10390 if {[info exists idtags($id)]} {
10394 if {[info exists cached_dtags($id)]} {
10395 return $cached_dtags($id)
10399 set todo [list $id]
10402 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10403 set id [lindex $todo $i]
10405 set ta [info exists hastaggedancestor($id)]
10409 # ignore tags on starting node
10410 if {!$ta && $i > 0} {
10411 if {[info exists idtags($id)]} {
10412 set tagloc($id) $id
10414 } elseif {[info exists cached_dtags($id)]} {
10415 set tagloc($id) $cached_dtags($id)
10419 foreach a $arcnos($id) {
10420 set d $arcstart($a)
10421 if {!$ta && $arctags($a) ne {}} {
10422 validate_arctags $a
10423 if {$arctags($a) ne {}} {
10424 lappend tagloc($id) [lindex $arctags($a) end]
10427 if {$ta || $arctags($a) ne {}} {
10428 set tomark [list $d]
10429 for {set j 0} {$j < [llength $tomark]} {incr j} {
10430 set dd [lindex $tomark $j]
10431 if {![info exists hastaggedancestor($dd)]} {
10432 if {[info exists done($dd)]} {
10433 foreach b $arcnos($dd) {
10434 lappend tomark $arcstart($b)
10436 if {[info exists tagloc($dd)]} {
10439 } elseif {[info exists queued($dd)]} {
10442 set hastaggedancestor($dd) 1
10446 if {![info exists queued($d)]} {
10449 if {![info exists hastaggedancestor($d)]} {
10456 foreach id [array names tagloc] {
10457 if {![info exists hastaggedancestor($id)]} {
10458 foreach t $tagloc($id) {
10459 if {[lsearch -exact $tags $t] < 0} {
10465 set t2 [clock clicks -milliseconds]
10468 # remove tags that are descendents of other tags
10469 for {set i 0} {$i < [llength $tags]} {incr i} {
10470 set a [lindex $tags $i]
10471 for {set j 0} {$j < $i} {incr j} {
10472 set b [lindex $tags $j]
10473 set r [anc_or_desc $a $b]
10475 set tags [lreplace $tags $j $j]
10478 } elseif {$r == -1} {
10479 set tags [lreplace $tags $i $i]
10486 if {[array names growing] ne {}} {
10487 # graph isn't finished, need to check if any tag could get
10488 # eclipsed by another tag coming later. Simply ignore any
10489 # tags that could later get eclipsed.
10492 if {[is_certain $t $origid]} {
10496 if {$tags eq $ctags} {
10497 set cached_dtags($origid) $tags
10502 set cached_dtags($origid) $tags
10504 set t3 [clock clicks -milliseconds]
10505 if {0 && $t3 - $t1 >= 100} {
10506 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10507 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10512 proc anctags {id} {
10513 global arcnos arcids arcout arcend arctags idtags allparents
10514 global growing cached_atags
10516 if {![info exists allparents($id)]} {
10519 set t1 [clock clicks -milliseconds]
10521 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10522 # part-way along an arc; check that arc first
10523 set a [lindex $arcnos($id) 0]
10524 if {$arctags($a) ne {}} {
10525 validate_arctags $a
10526 set i [lsearch -exact $arcids($a) $id]
10527 foreach t $arctags($a) {
10528 set j [lsearch -exact $arcids($a) $t]
10534 if {![info exists arcend($a)]} {
10538 if {[info exists idtags($id)]} {
10542 if {[info exists cached_atags($id)]} {
10543 return $cached_atags($id)
10547 set todo [list $id]
10551 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10552 set id [lindex $todo $i]
10554 set td [info exists hastaggeddescendent($id)]
10558 # ignore tags on starting node
10559 if {!$td && $i > 0} {
10560 if {[info exists idtags($id)]} {
10561 set tagloc($id) $id
10563 } elseif {[info exists cached_atags($id)]} {
10564 set tagloc($id) $cached_atags($id)
10568 foreach a $arcout($id) {
10569 if {!$td && $arctags($a) ne {}} {
10570 validate_arctags $a
10571 if {$arctags($a) ne {}} {
10572 lappend tagloc($id) [lindex $arctags($a) 0]
10575 if {![info exists arcend($a)]} continue
10577 if {$td || $arctags($a) ne {}} {
10578 set tomark [list $d]
10579 for {set j 0} {$j < [llength $tomark]} {incr j} {
10580 set dd [lindex $tomark $j]
10581 if {![info exists hastaggeddescendent($dd)]} {
10582 if {[info exists done($dd)]} {
10583 foreach b $arcout($dd) {
10584 if {[info exists arcend($b)]} {
10585 lappend tomark $arcend($b)
10588 if {[info exists tagloc($dd)]} {
10591 } elseif {[info exists queued($dd)]} {
10594 set hastaggeddescendent($dd) 1
10598 if {![info exists queued($d)]} {
10601 if {![info exists hastaggeddescendent($d)]} {
10607 set t2 [clock clicks -milliseconds]
10610 foreach id [array names tagloc] {
10611 if {![info exists hastaggeddescendent($id)]} {
10612 foreach t $tagloc($id) {
10613 if {[lsearch -exact $tags $t] < 0} {
10620 # remove tags that are ancestors of other tags
10621 for {set i 0} {$i < [llength $tags]} {incr i} {
10622 set a [lindex $tags $i]
10623 for {set j 0} {$j < $i} {incr j} {
10624 set b [lindex $tags $j]
10625 set r [anc_or_desc $a $b]
10627 set tags [lreplace $tags $j $j]
10630 } elseif {$r == 1} {
10631 set tags [lreplace $tags $i $i]
10638 if {[array names growing] ne {}} {
10639 # graph isn't finished, need to check if any tag could get
10640 # eclipsed by another tag coming later. Simply ignore any
10641 # tags that could later get eclipsed.
10644 if {[is_certain $origid $t]} {
10648 if {$tags eq $ctags} {
10649 set cached_atags($origid) $tags
10654 set cached_atags($origid) $tags
10656 set t3 [clock clicks -milliseconds]
10657 if {0 && $t3 - $t1 >= 100} {
10658 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10659 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10664 # Return the list of IDs that have heads that are descendents of id,
10665 # including id itself if it has a head.
10666 proc descheads {id} {
10667 global arcnos arcstart arcids archeads idheads cached_dheads
10668 global allparents arcout
10670 if {![info exists allparents($id)]} {
10674 if {![info exists arcout($id)]} {
10675 # part-way along an arc; check it first
10676 set a [lindex $arcnos($id) 0]
10677 if {$archeads($a) ne {}} {
10678 validate_archeads $a
10679 set i [lsearch -exact $arcids($a) $id]
10680 foreach t $archeads($a) {
10681 set j [lsearch -exact $arcids($a) $t]
10686 set id $arcstart($a)
10689 set todo [list $id]
10692 for {set i 0} {$i < [llength $todo]} {incr i} {
10693 set id [lindex $todo $i]
10694 if {[info exists cached_dheads($id)]} {
10695 set ret [concat $ret $cached_dheads($id)]
10697 if {[info exists idheads($id)]} {
10700 foreach a $arcnos($id) {
10701 if {$archeads($a) ne {}} {
10702 validate_archeads $a
10703 if {$archeads($a) ne {}} {
10704 set ret [concat $ret $archeads($a)]
10707 set d $arcstart($a)
10708 if {![info exists seen($d)]} {
10715 set ret [lsort -unique $ret]
10716 set cached_dheads($origid) $ret
10717 return [concat $ret $aret]
10720 proc addedtag {id} {
10721 global arcnos arcout cached_dtags cached_atags
10723 if {![info exists arcnos($id)]} return
10724 if {![info exists arcout($id)]} {
10725 recalcarc [lindex $arcnos($id) 0]
10727 catch {unset cached_dtags}
10728 catch {unset cached_atags}
10731 proc addedhead {hid head} {
10732 global arcnos arcout cached_dheads
10734 if {![info exists arcnos($hid)]} return
10735 if {![info exists arcout($hid)]} {
10736 recalcarc [lindex $arcnos($hid) 0]
10738 catch {unset cached_dheads}
10741 proc removedhead {hid head} {
10742 global cached_dheads
10744 catch {unset cached_dheads}
10747 proc movedhead {hid head} {
10748 global arcnos arcout cached_dheads
10750 if {![info exists arcnos($hid)]} return
10751 if {![info exists arcout($hid)]} {
10752 recalcarc [lindex $arcnos($hid) 0]
10754 catch {unset cached_dheads}
10757 proc changedrefs {} {
10758 global cached_dheads cached_dtags cached_atags cached_tagcontent
10759 global arctags archeads arcnos arcout idheads idtags
10761 foreach id [concat [array names idheads] [array names idtags]] {
10762 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10763 set a [lindex $arcnos($id) 0]
10764 if {![info exists donearc($a)]} {
10770 catch {unset cached_tagcontent}
10771 catch {unset cached_dtags}
10772 catch {unset cached_atags}
10773 catch {unset cached_dheads}
10776 proc rereadrefs {} {
10777 global idtags idheads idotherrefs mainheadid
10779 set refids [concat [array names idtags] \
10780 [array names idheads] [array names idotherrefs]]
10781 foreach id $refids {
10782 if {![info exists ref($id)]} {
10783 set ref($id) [listrefs $id]
10786 set oldmainhead $mainheadid
10789 set refids [lsort -unique [concat $refids [array names idtags] \
10790 [array names idheads] [array names idotherrefs]]]
10791 foreach id $refids {
10792 set v [listrefs $id]
10793 if {![info exists ref($id)] || $ref($id) != $v} {
10797 if {$oldmainhead ne $mainheadid} {
10798 redrawtags $oldmainhead
10799 redrawtags $mainheadid
10804 proc listrefs {id} {
10805 global idtags idheads idotherrefs
10808 if {[info exists idtags($id)]} {
10812 if {[info exists idheads($id)]} {
10813 set y $idheads($id)
10816 if {[info exists idotherrefs($id)]} {
10817 set z $idotherrefs($id)
10819 return [list $x $y $z]
10822 proc showtag {tag isnew} {
10823 global ctext cached_tagcontent tagids linknum tagobjid
10826 addtohistory [list showtag $tag 0] savectextpos
10828 $ctext conf -state normal
10832 if {![info exists cached_tagcontent($tag)]} {
10834 set cached_tagcontent($tag) [exec git cat-file -p $tag]
10837 if {[info exists cached_tagcontent($tag)]} {
10838 set text $cached_tagcontent($tag)
10840 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10842 appendwithlinks $text {}
10843 maybe_scroll_ctext 1
10844 $ctext conf -state disabled
10856 if {[info exists gitktmpdir]} {
10857 catch {file delete -force $gitktmpdir}
10861 proc mkfontdisp {font top which} {
10862 global fontattr fontpref $font NS use_ttk
10864 set fontpref($font) [set $font]
10865 ${NS}::button $top.${font}but -text $which \
10866 -command [list choosefont $font $which]
10867 ${NS}::label $top.$font -relief flat -font $font \
10868 -text $fontattr($font,family) -justify left
10869 grid x $top.${font}but $top.$font -sticky w
10872 proc choosefont {font which} {
10873 global fontparam fontlist fonttop fontattr
10876 set fontparam(which) $which
10877 set fontparam(font) $font
10878 set fontparam(family) [font actual $font -family]
10879 set fontparam(size) $fontattr($font,size)
10880 set fontparam(weight) $fontattr($font,weight)
10881 set fontparam(slant) $fontattr($font,slant)
10884 if {![winfo exists $top]} {
10886 eval font config sample [font actual $font]
10888 make_transient $top $prefstop
10889 wm title $top [mc "Gitk font chooser"]
10890 ${NS}::label $top.l -textvariable fontparam(which)
10891 pack $top.l -side top
10892 set fontlist [lsort [font families]]
10893 ${NS}::frame $top.f
10894 listbox $top.f.fam -listvariable fontlist \
10895 -yscrollcommand [list $top.f.sb set]
10896 bind $top.f.fam <<ListboxSelect>> selfontfam
10897 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10898 pack $top.f.sb -side right -fill y
10899 pack $top.f.fam -side left -fill both -expand 1
10900 pack $top.f -side top -fill both -expand 1
10901 ${NS}::frame $top.g
10902 spinbox $top.g.size -from 4 -to 40 -width 4 \
10903 -textvariable fontparam(size) \
10904 -validatecommand {string is integer -strict %s}
10905 checkbutton $top.g.bold -padx 5 \
10906 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10907 -variable fontparam(weight) -onvalue bold -offvalue normal
10908 checkbutton $top.g.ital -padx 5 \
10909 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10910 -variable fontparam(slant) -onvalue italic -offvalue roman
10911 pack $top.g.size $top.g.bold $top.g.ital -side left
10912 pack $top.g -side top
10913 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10915 $top.c create text 100 25 -anchor center -text $which -font sample \
10916 -fill black -tags text
10917 bind $top.c <Configure> [list centertext $top.c]
10918 pack $top.c -side top -fill x
10919 ${NS}::frame $top.buts
10920 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10921 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10922 bind $top <Key-Return> fontok
10923 bind $top <Key-Escape> fontcan
10924 grid $top.buts.ok $top.buts.can
10925 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10926 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10927 pack $top.buts -side bottom -fill x
10928 trace add variable fontparam write chg_fontparam
10931 $top.c itemconf text -text $which
10933 set i [lsearch -exact $fontlist $fontparam(family)]
10935 $top.f.fam selection set $i
10940 proc centertext {w} {
10941 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
10945 global fontparam fontpref prefstop
10947 set f $fontparam(font)
10948 set fontpref($f) [list $fontparam(family) $fontparam(size)]
10949 if {$fontparam(weight) eq "bold"} {
10950 lappend fontpref($f) "bold"
10952 if {$fontparam(slant) eq "italic"} {
10953 lappend fontpref($f) "italic"
10955 set w $prefstop.notebook.fonts.$f
10956 $w conf -text $fontparam(family) -font $fontpref($f)
10962 global fonttop fontparam
10964 if {[info exists fonttop]} {
10965 catch {destroy $fonttop}
10966 catch {font delete sample}
10972 if {[package vsatisfies [package provide Tk] 8.6]} {
10973 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
10974 # function to make use of it.
10975 proc choosefont {font which} {
10976 tk fontchooser configure -title $which -font $font \
10977 -command [list on_choosefont $font $which]
10978 tk fontchooser show
10980 proc on_choosefont {font which newfont} {
10982 puts stderr "$font $newfont"
10983 array set f [font actual $newfont]
10984 set fontparam(which) $which
10985 set fontparam(font) $font
10986 set fontparam(family) $f(-family)
10987 set fontparam(size) $f(-size)
10988 set fontparam(weight) $f(-weight)
10989 set fontparam(slant) $f(-slant)
10994 proc selfontfam {} {
10995 global fonttop fontparam
10997 set i [$fonttop.f.fam curselection]
10999 set fontparam(family) [$fonttop.f.fam get $i]
11003 proc chg_fontparam {v sub op} {
11006 font config sample -$sub $fontparam($sub)
11009 # Create a property sheet tab page
11010 proc create_prefs_page {w} {
11012 set parent [join [lrange [split $w .] 0 end-1] .]
11013 if {[winfo class $parent] eq "TNotebook"} {
11016 ${NS}::labelframe $w
11020 proc prefspage_general {notebook} {
11021 global NS maxwidth maxgraphpct showneartags showlocalchanges
11022 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11023 global hideremotes want_ttk have_ttk maxrefs
11025 set page [create_prefs_page $notebook.general]
11027 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11028 grid $page.ldisp - -sticky w -pady 10
11029 ${NS}::label $page.spacer -text " "
11030 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11031 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11032 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11033 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11034 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11035 grid x $page.maxpctl $page.maxpct -sticky w
11036 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11037 -variable showlocalchanges
11038 grid x $page.showlocal -sticky w
11039 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11040 -variable autoselect
11041 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11042 grid x $page.autoselect $page.autosellen -sticky w
11043 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11044 -variable hideremotes
11045 grid x $page.hideremotes -sticky w
11047 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11048 grid $page.ddisp - -sticky w -pady 10
11049 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11050 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11051 grid x $page.tabstopl $page.tabstop -sticky w
11052 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11053 -variable showneartags
11054 grid x $page.ntag -sticky w
11055 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11056 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11057 grid x $page.maxrefsl $page.maxrefs -sticky w
11058 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11059 -variable limitdiffs
11060 grid x $page.ldiff -sticky w
11061 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11062 -variable perfile_attrs
11063 grid x $page.lattr -sticky w
11065 ${NS}::entry $page.extdifft -textvariable extdifftool
11066 ${NS}::frame $page.extdifff
11067 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11068 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11069 pack $page.extdifff.l $page.extdifff.b -side left
11070 pack configure $page.extdifff.l -padx 10
11071 grid x $page.extdifff $page.extdifft -sticky ew
11073 ${NS}::label $page.lgen -text [mc "General options"]
11074 grid $page.lgen - -sticky w -pady 10
11075 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11076 -text [mc "Use themed widgets"]
11078 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11080 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11082 grid x $page.want_ttk $page.ttk_note -sticky w
11086 proc prefspage_colors {notebook} {
11087 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11089 set page [create_prefs_page $notebook.colors]
11091 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11092 grid $page.cdisp - -sticky w -pady 10
11093 label $page.ui -padx 40 -relief sunk -background $uicolor
11094 ${NS}::button $page.uibut -text [mc "Interface"] \
11095 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11096 grid x $page.uibut $page.ui -sticky w
11097 label $page.bg -padx 40 -relief sunk -background $bgcolor
11098 ${NS}::button $page.bgbut -text [mc "Background"] \
11099 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11100 grid x $page.bgbut $page.bg -sticky w
11101 label $page.fg -padx 40 -relief sunk -background $fgcolor
11102 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11103 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11104 grid x $page.fgbut $page.fg -sticky w
11105 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11106 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11107 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11108 [list $ctext tag conf d0 -foreground]]
11109 grid x $page.diffoldbut $page.diffold -sticky w
11110 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11111 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11112 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11113 [list $ctext tag conf dresult -foreground]]
11114 grid x $page.diffnewbut $page.diffnew -sticky w
11115 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11116 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11117 -command [list choosecolor diffcolors 2 $page.hunksep \
11118 [mc "diff hunk header"] \
11119 [list $ctext tag conf hunksep -foreground]]
11120 grid x $page.hunksepbut $page.hunksep -sticky w
11121 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11122 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11123 -command [list choosecolor markbgcolor {} $page.markbgsep \
11124 [mc "marked line background"] \
11125 [list $ctext tag conf omark -background]]
11126 grid x $page.markbgbut $page.markbgsep -sticky w
11127 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11128 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11129 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11130 grid x $page.selbgbut $page.selbgsep -sticky w
11134 proc prefspage_fonts {notebook} {
11136 set page [create_prefs_page $notebook.fonts]
11137 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11138 grid $page.cfont - -sticky w -pady 10
11139 mkfontdisp mainfont $page [mc "Main font"]
11140 mkfontdisp textfont $page [mc "Diff display font"]
11141 mkfontdisp uifont $page [mc "User interface font"]
11146 global maxwidth maxgraphpct use_ttk NS
11147 global oldprefs prefstop showneartags showlocalchanges
11148 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11149 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11150 global hideremotes want_ttk have_ttk
11154 if {[winfo exists $top]} {
11158 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11159 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11160 set oldprefs($v) [set $v]
11163 wm title $top [mc "Gitk preferences"]
11164 make_transient $top .
11166 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11167 set notebook [ttk::notebook $top.notebook]
11169 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11172 lappend pages [prefspage_general $notebook] [mc "General"]
11173 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11174 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11176 foreach {page title} $pages {
11177 if {$use_notebook} {
11178 $notebook add $page -text $title
11180 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11181 -text $title -command [list raise $page]]
11182 $page configure -text $title
11183 grid $btn -row 0 -column [incr col] -sticky w
11184 grid $page -row 1 -column 0 -sticky news -columnspan 100
11188 if {!$use_notebook} {
11189 grid columnconfigure $notebook 0 -weight 1
11190 grid rowconfigure $notebook 1 -weight 1
11191 raise [lindex $pages 0]
11194 grid $notebook -sticky news -padx 2 -pady 2
11195 grid rowconfigure $top 0 -weight 1
11196 grid columnconfigure $top 0 -weight 1
11198 ${NS}::frame $top.buts
11199 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11200 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11201 bind $top <Key-Return> prefsok
11202 bind $top <Key-Escape> prefscan
11203 grid $top.buts.ok $top.buts.can
11204 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11205 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11206 grid $top.buts - - -pady 10 -sticky ew
11207 grid columnconfigure $top 2 -weight 1
11208 bind $top <Visibility> [list focus $top.buts.ok]
11211 proc choose_extdiff {} {
11214 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11216 set extdifftool $prog
11220 proc choosecolor {v vi w x cmd} {
11223 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11224 -title [mc "Gitk: choose color for %s" $x]]
11225 if {$c eq {}} return
11226 $w conf -background $c
11231 proc setselbg {c} {
11232 global bglist cflist
11233 foreach w $bglist {
11234 $w configure -selectbackground $c
11236 $cflist tag configure highlight \
11237 -background [$cflist cget -selectbackground]
11238 allcanvs itemconf secsel -fill $c
11241 # This sets the background color and the color scheme for the whole UI.
11242 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11243 # if we don't specify one ourselves, which makes the checkbuttons and
11244 # radiobuttons look bad. This chooses white for selectColor if the
11245 # background color is light, or black if it is dark.
11247 if {[tk windowingsystem] eq "win32"} { return }
11248 set bg [winfo rgb . $c]
11250 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11253 tk_setPalette background $c selectColor $selc
11259 foreach w $bglist {
11260 $w conf -background $c
11267 foreach w $fglist {
11268 $w conf -foreground $c
11270 allcanvs itemconf text -fill $c
11271 $canv itemconf circle -outline $c
11272 $canv itemconf markid -outline $c
11276 global oldprefs prefstop
11278 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11279 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11281 set $v $oldprefs($v)
11283 catch {destroy $prefstop}
11289 global maxwidth maxgraphpct
11290 global oldprefs prefstop showneartags showlocalchanges
11291 global fontpref mainfont textfont uifont
11292 global limitdiffs treediffs perfile_attrs
11295 catch {destroy $prefstop}
11299 if {$mainfont ne $fontpref(mainfont)} {
11300 set mainfont $fontpref(mainfont)
11301 parsefont mainfont $mainfont
11302 eval font configure mainfont [fontflags mainfont]
11303 eval font configure mainfontbold [fontflags mainfont 1]
11307 if {$textfont ne $fontpref(textfont)} {
11308 set textfont $fontpref(textfont)
11309 parsefont textfont $textfont
11310 eval font configure textfont [fontflags textfont]
11311 eval font configure textfontbold [fontflags textfont 1]
11313 if {$uifont ne $fontpref(uifont)} {
11314 set uifont $fontpref(uifont)
11315 parsefont uifont $uifont
11316 eval font configure uifont [fontflags uifont]
11319 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11320 if {$showlocalchanges} {
11326 if {$limitdiffs != $oldprefs(limitdiffs) ||
11327 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11328 # treediffs elements are limited by path;
11329 # won't have encodings cached if perfile_attrs was just turned on
11330 catch {unset treediffs}
11332 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11333 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11335 } elseif {$showneartags != $oldprefs(showneartags) ||
11336 $limitdiffs != $oldprefs(limitdiffs)} {
11339 if {$hideremotes != $oldprefs(hideremotes)} {
11344 proc formatdate {d} {
11345 global datetimeformat
11347 set d [clock format [lindex $d 0] -format $datetimeformat]
11352 # This list of encoding names and aliases is distilled from
11353 # http://www.iana.org/assignments/character-sets.
11354 # Not all of them are supported by Tcl.
11355 set encoding_aliases {
11356 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11357 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11358 { ISO-10646-UTF-1 csISO10646UTF1 }
11359 { ISO_646.basic:1983 ref csISO646basic1983 }
11360 { INVARIANT csINVARIANT }
11361 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11362 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11363 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11364 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11365 { NATS-DANO iso-ir-9-1 csNATSDANO }
11366 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11367 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11368 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11369 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11370 { ISO-2022-KR csISO2022KR }
11372 { ISO-2022-JP csISO2022JP }
11373 { ISO-2022-JP-2 csISO2022JP2 }
11374 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11375 csISO13JISC6220jp }
11376 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11377 { IT iso-ir-15 ISO646-IT csISO15Italian }
11378 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11379 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11380 { greek7-old iso-ir-18 csISO18Greek7Old }
11381 { latin-greek iso-ir-19 csISO19LatinGreek }
11382 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11383 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11384 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11385 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11386 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11387 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11388 { INIS iso-ir-49 csISO49INIS }
11389 { INIS-8 iso-ir-50 csISO50INIS8 }
11390 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11391 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11392 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11393 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11394 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11395 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11396 csISO60Norwegian1 }
11397 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11398 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11399 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11400 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11401 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11402 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11403 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11404 { greek7 iso-ir-88 csISO88Greek7 }
11405 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11406 { iso-ir-90 csISO90 }
11407 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11408 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11409 csISO92JISC62991984b }
11410 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11411 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11412 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11413 csISO95JIS62291984handadd }
11414 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11415 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11416 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11417 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11418 CP819 csISOLatin1 }
11419 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11420 { T.61-7bit iso-ir-102 csISO102T617bit }
11421 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11422 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11423 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11424 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11425 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11426 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11427 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11428 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11429 arabic csISOLatinArabic }
11430 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11431 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11432 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11433 greek greek8 csISOLatinGreek }
11434 { T.101-G2 iso-ir-128 csISO128T101G2 }
11435 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11437 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11438 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11439 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11440 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11441 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11442 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11443 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11444 csISOLatinCyrillic }
11445 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11446 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11447 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11448 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11449 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11450 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11451 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11452 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11453 { ISO_10367-box iso-ir-155 csISO10367Box }
11454 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11455 { latin-lap lap iso-ir-158 csISO158Lap }
11456 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11457 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11460 { JIS_X0201 X0201 csHalfWidthKatakana }
11461 { KSC5636 ISO646-KR csKSC5636 }
11462 { ISO-10646-UCS-2 csUnicode }
11463 { ISO-10646-UCS-4 csUCS4 }
11464 { DEC-MCS dec csDECMCS }
11465 { hp-roman8 roman8 r8 csHPRoman8 }
11466 { macintosh mac csMacintosh }
11467 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11469 { IBM038 EBCDIC-INT cp038 csIBM038 }
11470 { IBM273 CP273 csIBM273 }
11471 { IBM274 EBCDIC-BE CP274 csIBM274 }
11472 { IBM275 EBCDIC-BR cp275 csIBM275 }
11473 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11474 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11475 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11476 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11477 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11478 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11479 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11480 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11481 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11482 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11483 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11484 { IBM437 cp437 437 csPC8CodePage437 }
11485 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11486 { IBM775 cp775 csPC775Baltic }
11487 { IBM850 cp850 850 csPC850Multilingual }
11488 { IBM851 cp851 851 csIBM851 }
11489 { IBM852 cp852 852 csPCp852 }
11490 { IBM855 cp855 855 csIBM855 }
11491 { IBM857 cp857 857 csIBM857 }
11492 { IBM860 cp860 860 csIBM860 }
11493 { IBM861 cp861 861 cp-is csIBM861 }
11494 { IBM862 cp862 862 csPC862LatinHebrew }
11495 { IBM863 cp863 863 csIBM863 }
11496 { IBM864 cp864 csIBM864 }
11497 { IBM865 cp865 865 csIBM865 }
11498 { IBM866 cp866 866 csIBM866 }
11499 { IBM868 CP868 cp-ar csIBM868 }
11500 { IBM869 cp869 869 cp-gr csIBM869 }
11501 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11502 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11503 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11504 { IBM891 cp891 csIBM891 }
11505 { IBM903 cp903 csIBM903 }
11506 { IBM904 cp904 904 csIBBM904 }
11507 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11508 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11509 { IBM1026 CP1026 csIBM1026 }
11510 { EBCDIC-AT-DE csIBMEBCDICATDE }
11511 { EBCDIC-AT-DE-A csEBCDICATDEA }
11512 { EBCDIC-CA-FR csEBCDICCAFR }
11513 { EBCDIC-DK-NO csEBCDICDKNO }
11514 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11515 { EBCDIC-FI-SE csEBCDICFISE }
11516 { EBCDIC-FI-SE-A csEBCDICFISEA }
11517 { EBCDIC-FR csEBCDICFR }
11518 { EBCDIC-IT csEBCDICIT }
11519 { EBCDIC-PT csEBCDICPT }
11520 { EBCDIC-ES csEBCDICES }
11521 { EBCDIC-ES-A csEBCDICESA }
11522 { EBCDIC-ES-S csEBCDICESS }
11523 { EBCDIC-UK csEBCDICUK }
11524 { EBCDIC-US csEBCDICUS }
11525 { UNKNOWN-8BIT csUnknown8BiT }
11526 { MNEMONIC csMnemonic }
11528 { VISCII csVISCII }
11531 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11532 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11533 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11534 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11535 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11536 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11537 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11538 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11539 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11540 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11541 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11542 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11543 { IBM1047 IBM-1047 }
11544 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11545 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11546 { UNICODE-1-1 csUnicode11 }
11547 { CESU-8 csCESU-8 }
11548 { BOCU-1 csBOCU-1 }
11549 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11550 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11552 { ISO-8859-15 ISO_8859-15 Latin-9 }
11553 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11554 { GBK CP936 MS936 windows-936 }
11555 { JIS_Encoding csJISEncoding }
11556 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11557 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11559 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11560 { ISO-10646-UCS-Basic csUnicodeASCII }
11561 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11562 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11563 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11564 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11565 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11566 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11567 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11568 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11569 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11570 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11571 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11572 { Ventura-US csVenturaUS }
11573 { Ventura-International csVenturaInternational }
11574 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11575 { PC8-Turkish csPC8Turkish }
11576 { IBM-Symbols csIBMSymbols }
11577 { IBM-Thai csIBMThai }
11578 { HP-Legal csHPLegal }
11579 { HP-Pi-font csHPPiFont }
11580 { HP-Math8 csHPMath8 }
11581 { Adobe-Symbol-Encoding csHPPSMath }
11582 { HP-DeskTop csHPDesktop }
11583 { Ventura-Math csVenturaMath }
11584 { Microsoft-Publishing csMicrosoftPublishing }
11585 { Windows-31J csWindows31J }
11586 { GB2312 csGB2312 }
11590 proc tcl_encoding {enc} {
11591 global encoding_aliases tcl_encoding_cache
11592 if {[info exists tcl_encoding_cache($enc)]} {
11593 return $tcl_encoding_cache($enc)
11595 set names [encoding names]
11596 set lcnames [string tolower $names]
11597 set enc [string tolower $enc]
11598 set i [lsearch -exact $lcnames $enc]
11600 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11601 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11602 set i [lsearch -exact $lcnames $encx]
11606 foreach l $encoding_aliases {
11607 set ll [string tolower $l]
11608 if {[lsearch -exact $ll $enc] < 0} continue
11609 # look through the aliases for one that tcl knows about
11611 set i [lsearch -exact $lcnames $e]
11613 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11614 set i [lsearch -exact $lcnames $ex]
11624 set tclenc [lindex $names $i]
11626 set tcl_encoding_cache($enc) $tclenc
11630 proc gitattr {path attr default} {
11631 global path_attr_cache
11632 if {[info exists path_attr_cache($attr,$path)]} {
11633 set r $path_attr_cache($attr,$path)
11635 set r "unspecified"
11636 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11637 regexp "(.*): $attr: (.*)" $line m f r
11639 set path_attr_cache($attr,$path) $r
11641 if {$r eq "unspecified"} {
11647 proc cache_gitattr {attr pathlist} {
11648 global path_attr_cache
11650 foreach path $pathlist {
11651 if {![info exists path_attr_cache($attr,$path)]} {
11652 lappend newlist $path
11656 if {[tk windowingsystem] == "win32"} {
11657 # windows has a 32k limit on the arguments to a command...
11660 while {$newlist ne {}} {
11661 set head [lrange $newlist 0 [expr {$lim - 1}]]
11662 set newlist [lrange $newlist $lim end]
11663 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11664 foreach row [split $rlist "\n"] {
11665 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11666 if {[string index $path 0] eq "\""} {
11667 set path [encoding convertfrom [lindex $path 0]]
11669 set path_attr_cache($attr,$path) $value
11676 proc get_path_encoding {path} {
11677 global gui_encoding perfile_attrs
11678 set tcl_enc $gui_encoding
11679 if {$path ne {} && $perfile_attrs} {
11680 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11688 # First check that Tcl/Tk is recent enough
11689 if {[catch {package require Tk 8.4} err]} {
11690 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11691 Gitk requires at least Tcl/Tk 8.4." list
11695 # Unset GIT_TRACE var if set
11696 if { [info exists ::env(GIT_TRACE)] } {
11697 unset ::env(GIT_TRACE)
11701 set wrcomcmd "git diff-tree --stdin -p --pretty"
11705 set gitencoding [exec git config --get i18n.commitencoding]
11708 set gitencoding [exec git config --get i18n.logoutputencoding]
11710 if {$gitencoding == ""} {
11711 set gitencoding "utf-8"
11713 set tclencoding [tcl_encoding $gitencoding]
11714 if {$tclencoding == {}} {
11715 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11718 set gui_encoding [encoding system]
11720 set enc [exec git config --get gui.encoding]
11722 set tclenc [tcl_encoding $enc]
11723 if {$tclenc ne {}} {
11724 set gui_encoding $tclenc
11726 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11731 set log_showroot true
11733 set log_showroot [exec git config --bool --get log.showroot]
11736 if {[tk windowingsystem] eq "aqua"} {
11737 set mainfont {{Lucida Grande} 9}
11738 set textfont {Monaco 9}
11739 set uifont {{Lucida Grande} 9 bold}
11740 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11742 set mainfont {sans 9}
11743 set textfont {monospace 9}
11744 set uifont {sans 9 bold}
11746 set mainfont {Helvetica 9}
11747 set textfont {Courier 9}
11748 set uifont {Helvetica 9 bold}
11751 set findmergefiles 0
11759 set cmitmode "patch"
11760 set wrapcomment "none"
11765 set showlocalchanges 1
11767 set datetimeformat "%Y-%m-%d %H:%M:%S"
11770 set perfile_attrs 0
11773 if {[tk windowingsystem] eq "aqua"} {
11774 set extdifftool "opendiff"
11776 set extdifftool "meld"
11779 set colors {green red blue magenta darkgrey brown orange}
11780 if {[tk windowingsystem] eq "win32"} {
11781 set uicolor SystemButtonFace
11782 set uifgcolor SystemButtonText
11783 set uifgdisabledcolor SystemDisabledText
11784 set bgcolor SystemWindow
11785 set fgcolor SystemWindowText
11786 set selectbgcolor SystemHighlight
11789 set uifgcolor black
11790 set uifgdisabledcolor "#999"
11793 set selectbgcolor gray85
11795 set diffcolors {red "#00a000" blue}
11797 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
11800 set markbgcolor "#e0e0ff"
11802 set headbgcolor green
11803 set headfgcolor black
11804 set headoutlinecolor black
11805 set remotebgcolor #ffddaa
11806 set tagbgcolor yellow
11807 set tagfgcolor black
11808 set tagoutlinecolor black
11809 set reflinecolor black
11810 set filesepbgcolor #aaaaaa
11811 set filesepfgcolor black
11812 set linehoverbgcolor #ffff80
11813 set linehoverfgcolor black
11814 set linehoveroutlinecolor black
11815 set mainheadcirclecolor yellow
11816 set workingfilescirclecolor red
11817 set indexcirclecolor green
11818 set circlecolors {white blue gray blue blue}
11819 set linkfgcolor blue
11820 set circleoutlinecolor $fgcolor
11821 set foundbgcolor yellow
11822 set currentsearchhitbgcolor orange
11824 # button for popping up context menus
11825 if {[tk windowingsystem] eq "aqua"} {
11826 set ctxbut <Button-2>
11828 set ctxbut <Button-3>
11831 ## For msgcat loading, first locate the installation location.
11832 if { [info exists ::env(GITK_MSGSDIR)] } {
11833 ## Msgsdir was manually set in the environment.
11834 set gitk_msgsdir $::env(GITK_MSGSDIR)
11836 ## Let's guess the prefix from argv0.
11837 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11838 set gitk_libdir [file join $gitk_prefix share gitk lib]
11839 set gitk_msgsdir [file join $gitk_libdir msgs]
11843 ## Internationalization (i18n) through msgcat and gettext. See
11844 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11845 package require msgcat
11846 namespace import ::msgcat::mc
11847 ## And eventually load the actual message catalog
11848 ::msgcat::mcload $gitk_msgsdir
11850 catch {source ~/.gitk}
11852 parsefont mainfont $mainfont
11853 eval font create mainfont [fontflags mainfont]
11854 eval font create mainfontbold [fontflags mainfont 1]
11856 parsefont textfont $textfont
11857 eval font create textfont [fontflags textfont]
11858 eval font create textfontbold [fontflags textfont 1]
11860 parsefont uifont $uifont
11861 eval font create uifont [fontflags uifont]
11867 # check that we can find a .git directory somewhere...
11868 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
11869 show_error {} . [mc "Cannot find a git repository here."]
11874 set selectheadid {}
11877 set cmdline_files {}
11879 set revtreeargscmd {}
11880 foreach arg $argv {
11881 switch -glob -- $arg {
11884 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11887 "--select-commit=*" {
11888 set selecthead [string range $arg 16 end]
11891 set revtreeargscmd [string range $arg 10 end]
11894 lappend revtreeargs $arg
11900 if {$selecthead eq "HEAD"} {
11904 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11905 # no -- on command line, but some arguments (other than --argscmd)
11907 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11908 set cmdline_files [split $f "\n"]
11909 set n [llength $cmdline_files]
11910 set revtreeargs [lrange $revtreeargs 0 end-$n]
11911 # Unfortunately git rev-parse doesn't produce an error when
11912 # something is both a revision and a filename. To be consistent
11913 # with git log and git rev-list, check revtreeargs for filenames.
11914 foreach arg $revtreeargs {
11915 if {[file exists $arg]} {
11916 show_error {} . [mc "Ambiguous argument '%s': both revision\
11917 and filename" $arg]
11922 # unfortunately we get both stdout and stderr in $err,
11923 # so look for "fatal:".
11924 set i [string first "fatal:" $err]
11926 set err [string range $err [expr {$i + 6}] end]
11928 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
11933 set nullid "0000000000000000000000000000000000000000"
11934 set nullid2 "0000000000000000000000000000000000000001"
11935 set nullfile "/dev/null"
11937 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
11938 if {![info exists have_ttk]} {
11939 set have_ttk [llength [info commands ::ttk::style]]
11941 set use_ttk [expr {$have_ttk && $want_ttk}]
11942 set NS [expr {$use_ttk ? "ttk" : ""}]
11944 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
11947 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
11948 set show_notes "--show-notes"
11958 set highlight_paths {}
11960 set searchdirn -forwards
11963 set diffelide {0 0}
11964 set markingmatches 0
11965 set linkentercount 0
11966 set need_redisplay 0
11973 set selectedhlview [mc "None"]
11974 set highlight_related [mc "None"]
11975 set highlight_files {}
11976 set viewfiles(0) {}
11979 set viewargscmd(0) {}
11981 set selectedline {}
11989 set hasworktree [hasworktree]
11991 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
11992 set cdup [exec git rev-parse --show-cdup]
11994 set worktree [exec git rev-parse --show-toplevel]
11998 image create photo gitlogo -width 16 -height 16
12000 image create photo gitlogominus -width 4 -height 2
12001 gitlogominus put #C00000 -to 0 0 4 2
12002 gitlogo copy gitlogominus -to 1 5
12003 gitlogo copy gitlogominus -to 6 5
12004 gitlogo copy gitlogominus -to 11 5
12005 image delete gitlogominus
12007 image create photo gitlogoplus -width 4 -height 4
12008 gitlogoplus put #008000 -to 1 0 3 4
12009 gitlogoplus put #008000 -to 0 1 4 3
12010 gitlogo copy gitlogoplus -to 1 9
12011 gitlogo copy gitlogoplus -to 6 9
12012 gitlogo copy gitlogoplus -to 11 9
12013 image delete gitlogoplus
12015 image create photo gitlogo32 -width 32 -height 32
12016 gitlogo32 copy gitlogo -zoom 2 2
12018 wm iconphoto . -default gitlogo gitlogo32
12020 # wait for the window to become visible
12021 tkwait visibility .
12022 wm title . "$appname: [reponame]"
12026 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12027 # create a view for the files/dirs specified on the command line
12031 set viewname(1) [mc "Command line"]
12032 set viewfiles(1) $cmdline_files
12033 set viewargs(1) $revtreeargs
12034 set viewargscmd(1) $revtreeargscmd
12038 .bar.view entryconf [mca "Edit view..."] -state normal
12039 .bar.view entryconf [mca "Delete view"] -state normal
12042 if {[info exists permviews]} {
12043 foreach v $permviews {
12046 set viewname($n) [lindex $v 0]
12047 set viewfiles($n) [lindex $v 1]
12048 set viewargs($n) [lindex $v 2]
12049 set viewargscmd($n) [lindex $v 3]
12055 if {[tk windowingsystem] eq "win32"} {
12063 # indent-tabs-mode: t