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 makedroplist
{w varname args
} {
2005 foreach label
$args {
2006 set cx
[string length
$label]
2007 if {$cx > $width} {set width
$cx}
2009 set gm
[ttk
::combobox
$w -width $width -state readonly\
2010 -textvariable $varname -values $args]
2012 set gm
[eval [linsert
$args 0 tk_optionMenu
$w $varname]]
2017 proc makewindow
{} {
2018 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2020 global findtype findtypemenu findloc findstring fstring geometry
2021 global entries sha1entry sha1string sha1but
2022 global diffcontextstring diffcontext
2024 global maincursor textcursor curtextcursor
2025 global rowctxmenu fakerowmenu mergemax wrapcomment
2026 global highlight_files gdttype
2027 global searchstring sstring
2028 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2029 global headctxmenu progresscanv progressitem progresscoords statusw
2030 global fprogitem fprogcoord lastprogupdate progupdatepending
2031 global rprogitem rprogcoord rownumsel numcommits
2032 global have_tk85 use_ttk NS
2036 # The "mc" arguments here are purely so that xgettext
2037 # sees the following string as needing to be translated
2040 {mc
"Update" command updatecommits
-accelerator F5
}
2041 {mc
"Reload" command reloadcommits
-accelerator Shift-F5
}
2042 {mc
"Reread references" command rereadrefs
}
2043 {mc
"List references" command showrefs
-accelerator F2
}
2045 {mc
"Start git gui" command {exec git gui
&}}
2047 {mc
"Quit" command doquit
-accelerator Meta1-Q
}
2051 {mc
"Preferences" command doprefs
}
2055 {mc
"New view..." command {newview
0} -accelerator Shift-F4
}
2056 {mc
"Edit view..." command editview
-state disabled
-accelerator F4
}
2057 {mc
"Delete view" command delview
-state disabled
}
2059 {mc
"All files" radiobutton
{selectedview
0} -command {showview
0}}
2061 if {[tk windowingsystem
] ne
"aqua"} {
2064 {mc
"About gitk" command about
}
2065 {mc
"Key bindings" command keys
}
2067 set bar
[list
$file $edit $view $help]
2069 proc
::tk
::mac
::ShowPreferences
{} {doprefs
}
2070 proc
::tk
::mac
::Quit
{} {doquit
}
2071 lset
file end
[lreplace
[lindex
$file end
] end-1 end
]
2073 xx
"Apple" cascade
{
2074 {mc
"About gitk" command about
}
2079 {mc
"Key bindings" command keys
}
2081 set bar
[list
$apple $file $view $help]
2084 . configure
-menu .bar
2087 # cover the non-themed toplevel with a themed frame.
2088 place
[ttk
::frame ._main_background
] -x 0 -y 0 -relwidth 1 -relheight 1
2091 # the gui has upper and lower half, parts of a paned window.
2092 ${NS}::panedwindow .ctop
-orient vertical
2094 # possibly use assumed geometry
2095 if {![info exists geometry
(pwsash0
)]} {
2096 set geometry
(topheight
) [expr {15 * $linespc}]
2097 set geometry
(topwidth
) [expr {80 * $charspc}]
2098 set geometry
(botheight
) [expr {15 * $linespc}]
2099 set geometry
(botwidth
) [expr {50 * $charspc}]
2100 set geometry
(pwsash0
) [list
[expr {40 * $charspc}] 2]
2101 set geometry
(pwsash1
) [list
[expr {60 * $charspc}] 2]
2104 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2105 ${NS}::frame .tf
-height $geometry(topheight
) -width $geometry(topwidth
)
2106 ${NS}::frame .tf.histframe
2107 ${NS}::panedwindow .tf.histframe.pwclist
-orient horizontal
2109 .tf.histframe.pwclist configure
-sashpad 0 -handlesize 4
2112 # create three canvases
2113 set cscroll .tf.histframe.csb
2114 set canv .tf.histframe.pwclist.canv
2116 -selectbackground $selectbgcolor \
2117 -background $bgcolor -bd 0 \
2118 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2119 .tf.histframe.pwclist add
$canv
2120 set canv2 .tf.histframe.pwclist.canv2
2122 -selectbackground $selectbgcolor \
2123 -background $bgcolor -bd 0 -yscrollincr $linespc
2124 .tf.histframe.pwclist add
$canv2
2125 set canv3 .tf.histframe.pwclist.canv3
2127 -selectbackground $selectbgcolor \
2128 -background $bgcolor -bd 0 -yscrollincr $linespc
2129 .tf.histframe.pwclist add
$canv3
2131 bind .tf.histframe.pwclist
<Map
> {
2133 .tf.histframe.pwclist sashpos
1 [lindex $
::geometry
(pwsash1
) 0]
2134 .tf.histframe.pwclist sashpos
0 [lindex $
::geometry
(pwsash0
) 0]
2137 eval .tf.histframe.pwclist sash place
0 $geometry(pwsash0
)
2138 eval .tf.histframe.pwclist sash place
1 $geometry(pwsash1
)
2141 # a scroll bar to rule them
2142 ${NS}::scrollbar
$cscroll -command {allcanvs yview
}
2143 if {!$use_ttk} {$cscroll configure
-highlightthickness 0}
2144 pack
$cscroll -side right
-fill y
2145 bind .tf.histframe.pwclist
<Configure
> {resizeclistpanes
%W
%w
}
2146 lappend bglist
$canv $canv2 $canv3
2147 pack .tf.histframe.pwclist
-fill both
-expand 1 -side left
2149 # we have two button bars at bottom of top frame. Bar 1
2150 ${NS}::frame .tf.bar
2151 ${NS}::frame .tf.lbar
-height 15
2153 set sha1entry .tf.bar.sha1
2154 set entries
$sha1entry
2155 set sha1but .tf.bar.sha1label
2156 button
$sha1but -text "[mc "SHA1 ID
:"] " -state disabled
-relief flat \
2157 -command gotocommit
-width 8
2158 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
2159 pack .tf.bar.sha1label
-side left
2160 ${NS}::entry
$sha1entry -width 40 -font textfont
-textvariable sha1string
2161 trace add variable sha1string
write sha1change
2162 pack
$sha1entry -side left
-pady 2
2165 #define left_width 16
2166 #define left_height 16
2167 static unsigned char left_bits
[] = {
2168 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2169 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2170 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2173 #define right_width 16
2174 #define right_height 16
2175 static unsigned char right_bits
[] = {
2176 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2177 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2178 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2180 image create bitmap bm-left
-data $bm_left_data
2181 image create bitmap bm-left-gray
-data $bm_left_data -foreground "#999"
2182 image create bitmap bm-right
-data $bm_right_data
2183 image create bitmap bm-right-gray
-data $bm_right_data -foreground "#999"
2185 ${NS}::button .tf.bar.leftbut
-command goback
-state disabled
-width 26
2187 .tf.bar.leftbut configure
-image [list bm-left disabled bm-left-gray
]
2189 .tf.bar.leftbut configure
-image bm-left
2191 pack .tf.bar.leftbut
-side left
-fill y
2192 ${NS}::button .tf.bar.rightbut
-command goforw
-state disabled
-width 26
2194 .tf.bar.rightbut configure
-image [list bm-right disabled bm-right-gray
]
2196 .tf.bar.rightbut configure
-image bm-right
2198 pack .tf.bar.rightbut
-side left
-fill y
2200 ${NS}::label .tf.bar.rowlabel
-text [mc
"Row"]
2202 ${NS}::label .tf.bar.rownum
-width 7 -textvariable rownumsel \
2203 -relief sunken
-anchor e
2204 ${NS}::label .tf.bar.rowlabel2
-text "/"
2205 ${NS}::label .tf.bar.numcommits
-width 7 -textvariable numcommits \
2206 -relief sunken
-anchor e
2207 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2210 foreach w
{rownum numcommits
} {.tf.bar.
$w configure
-font textfont
}
2213 trace add variable selectedline
write selectedline_change
2215 # Status label and progress bar
2216 set statusw .tf.bar.status
2217 ${NS}::label
$statusw -width 15 -relief sunken
2218 pack
$statusw -side left
-padx 5
2220 set progresscanv
[ttk
::progressbar .tf.bar.progress
]
2222 set h
[expr {[font metrics uifont
-linespace] + 2}]
2223 set progresscanv .tf.bar.progress
2224 canvas
$progresscanv -relief sunken
-height $h -borderwidth 2
2225 set progressitem
[$progresscanv create rect
-1 0 0 $h -fill green
]
2226 set fprogitem
[$progresscanv create rect
-1 0 0 $h -fill yellow
]
2227 set rprogitem
[$progresscanv create rect
-1 0 0 $h -fill red
]
2229 pack
$progresscanv -side right
-expand 1 -fill x
-padx {0 2}
2230 set progresscoords
{0 0}
2233 bind $progresscanv <Configure
> adjustprogress
2234 set lastprogupdate
[clock clicks
-milliseconds]
2235 set progupdatepending
0
2237 # build up the bottom bar of upper window
2238 ${NS}::label .tf.lbar.flabel
-text "[mc "Find
"] "
2239 ${NS}::button .tf.lbar.fnext
-text [mc
"next"] -command {dofind
1 1}
2240 ${NS}::button .tf.lbar.fprev
-text [mc
"prev"] -command {dofind
-1 1}
2241 ${NS}::label .tf.lbar.flab2
-text " [mc "commit
"] "
2242 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2244 set gdttype
[mc
"containing:"]
2245 set gm
[makedroplist .tf.lbar.gdttype gdttype \
2246 [mc
"containing:"] \
2247 [mc
"touching paths:"] \
2248 [mc
"adding/removing string:"]]
2249 trace add variable gdttype
write gdttype_change
2250 pack .tf.lbar.gdttype
-side left
-fill y
2253 set fstring .tf.lbar.findstring
2254 lappend entries
$fstring
2255 ${NS}::entry
$fstring -width 30 -textvariable findstring
2256 trace add variable findstring
write find_change
2257 set findtype
[mc
"Exact"]
2258 set findtypemenu
[makedroplist .tf.lbar.findtype \
2259 findtype
[mc
"Exact"] [mc
"IgnCase"] [mc
"Regexp"]]
2260 trace add variable findtype
write findcom_change
2261 set findloc
[mc
"All fields"]
2262 makedroplist .tf.lbar.findloc findloc
[mc
"All fields"] [mc
"Headline"] \
2263 [mc
"Comments"] [mc
"Author"] [mc
"Committer"]
2264 trace add variable findloc
write find_change
2265 pack .tf.lbar.findloc
-side right
2266 pack .tf.lbar.findtype
-side right
2267 pack
$fstring -side left
-expand 1 -fill x
2269 # Finish putting the upper half of the viewer together
2270 pack .tf.lbar
-in .tf
-side bottom
-fill x
2271 pack .tf.bar
-in .tf
-side bottom
-fill x
2272 pack .tf.histframe
-fill both
-side top
-expand 1
2275 .ctop paneconfigure .tf
-height $geometry(topheight
)
2276 .ctop paneconfigure .tf
-width $geometry(topwidth
)
2279 # now build up the bottom
2280 ${NS}::panedwindow .pwbottom
-orient horizontal
2282 # lower left, a text box over search bar, scroll bar to the right
2283 # if we know window height, then that will set the lower text height, otherwise
2284 # we set lower text height which will drive window height
2285 if {[info exists geometry
(main
)]} {
2286 ${NS}::frame .bleft
-width $geometry(botwidth
)
2288 ${NS}::frame .bleft
-width $geometry(botwidth
) -height $geometry(botheight
)
2290 ${NS}::frame .bleft.top
2291 ${NS}::frame .bleft.mid
2292 ${NS}::frame .bleft.bottom
2294 ${NS}::button .bleft.top.search
-text [mc
"Search"] -command dosearch
2295 pack .bleft.top.search
-side left
-padx 5
2296 set sstring .bleft.top.sstring
2298 ${NS}::entry
$sstring -width 20 -textvariable searchstring
2299 lappend entries
$sstring
2300 trace add variable searchstring
write incrsearch
2301 pack
$sstring -side left
-expand 1 -fill x
2302 ${NS}::radiobutton .bleft.mid.
diff -text [mc
"Diff"] \
2303 -command changediffdisp
-variable diffelide
-value {0 0}
2304 ${NS}::radiobutton .bleft.mid.old
-text [mc
"Old version"] \
2305 -command changediffdisp
-variable diffelide
-value {0 1}
2306 ${NS}::radiobutton .bleft.mid.new
-text [mc
"New version"] \
2307 -command changediffdisp
-variable diffelide
-value {1 0}
2308 ${NS}::label .bleft.mid.labeldiffcontext
-text " [mc "Lines of context
"]: "
2309 pack .bleft.mid.
diff .bleft.mid.old .bleft.mid.new
-side left
2310 spinbox .bleft.mid.diffcontext
-width 5 \
2311 -from 0 -increment 1 -to 10000000 \
2312 -validate all
-validatecommand "diffcontextvalidate %P" \
2313 -textvariable diffcontextstring
2314 .bleft.mid.diffcontext
set $diffcontext
2315 trace add variable diffcontextstring
write diffcontextchange
2316 lappend entries .bleft.mid.diffcontext
2317 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext
-side left
2318 ${NS}::checkbutton .bleft.mid.ignspace
-text [mc
"Ignore space change"] \
2319 -command changeignorespace
-variable ignorespace
2320 pack .bleft.mid.ignspace
-side left
-padx 5
2322 set worddiff
[mc
"Line diff"]
2323 if {[package vcompare
$git_version "1.7.2"] >= 0} {
2324 makedroplist .bleft.mid.worddiff worddiff
[mc
"Line diff"] \
2325 [mc
"Markup words"] [mc
"Color words"]
2326 trace add variable worddiff
write changeworddiff
2327 pack .bleft.mid.worddiff
-side left
-padx 5
2330 set ctext .bleft.bottom.ctext
2331 text
$ctext -background $bgcolor -foreground $fgcolor \
2332 -state disabled
-font textfont \
2333 -yscrollcommand scrolltext
-wrap none \
2334 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2336 $ctext conf
-tabstyle wordprocessor
2338 ${NS}::scrollbar .bleft.bottom.sb
-command "$ctext yview"
2339 ${NS}::scrollbar .bleft.bottom.sbhorizontal
-command "$ctext xview" -orient h
2340 pack .bleft.top
-side top
-fill x
2341 pack .bleft.mid
-side top
-fill x
2342 grid
$ctext .bleft.bottom.sb
-sticky nsew
2343 grid .bleft.bottom.sbhorizontal
-sticky ew
2344 grid columnconfigure .bleft.bottom
0 -weight 1
2345 grid rowconfigure .bleft.bottom
0 -weight 1
2346 grid rowconfigure .bleft.bottom
1 -weight 0
2347 pack .bleft.bottom
-side top
-fill both
-expand 1
2348 lappend bglist
$ctext
2349 lappend fglist
$ctext
2351 $ctext tag conf comment
-wrap $wrapcomment
2352 $ctext tag conf filesep
-font textfontbold
-back "#aaaaaa"
2353 $ctext tag conf hunksep
-fore [lindex
$diffcolors 2]
2354 $ctext tag conf d0
-fore [lindex
$diffcolors 0]
2355 $ctext tag conf dresult
-fore [lindex
$diffcolors 1]
2356 $ctext tag conf m0
-fore red
2357 $ctext tag conf m1
-fore blue
2358 $ctext tag conf m2
-fore green
2359 $ctext tag conf m3
-fore purple
2360 $ctext tag conf
m4 -fore brown
2361 $ctext tag conf m5
-fore "#009090"
2362 $ctext tag conf m6
-fore magenta
2363 $ctext tag conf m7
-fore "#808000"
2364 $ctext tag conf m8
-fore "#009000"
2365 $ctext tag conf m9
-fore "#ff0080"
2366 $ctext tag conf m10
-fore cyan
2367 $ctext tag conf m11
-fore "#b07070"
2368 $ctext tag conf m12
-fore "#70b0f0"
2369 $ctext tag conf m13
-fore "#70f0b0"
2370 $ctext tag conf m14
-fore "#f0b070"
2371 $ctext tag conf m15
-fore "#ff70b0"
2372 $ctext tag conf mmax
-fore darkgrey
2374 $ctext tag conf mresult
-font textfontbold
2375 $ctext tag conf msep
-font textfontbold
2376 $ctext tag conf found
-back yellow
2377 $ctext tag conf currentsearchhit
-back orange
2378 $ctext tag conf wwrap
-wrap word
2380 .pwbottom add .bleft
2382 .pwbottom paneconfigure .bleft
-width $geometry(botwidth
)
2386 ${NS}::frame .bright
2387 ${NS}::frame .bright.mode
2388 ${NS}::radiobutton .bright.mode.
patch -text [mc
"Patch"] \
2389 -command reselectline
-variable cmitmode
-value "patch"
2390 ${NS}::radiobutton .bright.mode.tree
-text [mc
"Tree"] \
2391 -command reselectline
-variable cmitmode
-value "tree"
2392 grid .bright.mode.
patch .bright.mode.tree
-sticky ew
2393 pack .bright.mode
-side top
-fill x
2394 set cflist .bright.cfiles
2395 set indent
[font measure mainfont
"nn"]
2397 -selectbackground $selectbgcolor \
2398 -background $bgcolor -foreground $fgcolor \
2400 -tabs [list
$indent [expr {2 * $indent}]] \
2401 -yscrollcommand ".bright.sb set" \
2402 -cursor [. cget
-cursor] \
2403 -spacing1 1 -spacing3 1
2404 lappend bglist
$cflist
2405 lappend fglist
$cflist
2406 ${NS}::scrollbar .bright.sb
-command "$cflist yview"
2407 pack .bright.sb
-side right
-fill y
2408 pack
$cflist -side left
-fill both
-expand 1
2409 $cflist tag configure highlight \
2410 -background [$cflist cget
-selectbackground]
2411 $cflist tag configure bold
-font mainfontbold
2413 .pwbottom add .bright
2416 # restore window width & height if known
2417 if {[info exists geometry
(main
)]} {
2418 if {[scan
$geometry(main
) "%dx%d" w h
] >= 2} {
2419 if {$w > [winfo screenwidth .
]} {
2420 set w
[winfo screenwidth .
]
2422 if {$h > [winfo screenheight .
]} {
2423 set h
[winfo screenheight .
]
2425 wm geometry .
"${w}x$h"
2429 if {[info exists geometry
(state
)] && $geometry(state
) eq
"zoomed"} {
2430 wm state .
$geometry(state
)
2433 if {[tk windowingsystem
] eq
{aqua
}} {
2444 %W sashpos
0 $
::geometry
(topheight
)
2446 bind .pwbottom
<Map
> {
2448 %W sashpos
0 $
::geometry
(botwidth
)
2452 bind .pwbottom
<Configure
> {resizecdetpanes
%W
%w
}
2453 pack .ctop
-fill both
-expand 1
2454 bindall
<1> {selcanvline
%W
%x
%y
}
2455 #bindall <B1-Motion> {selcanvline %W %x %y}
2456 if {[tk windowingsystem
] == "win32"} {
2457 bind .
<MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
}
2458 bind $ctext <MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
; break }
2460 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
2461 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
2462 if {[tk windowingsystem
] eq
"aqua"} {
2463 bindall
<MouseWheel
> {
2464 set delta
[expr {- (%D
)}]
2465 allcanvs yview scroll
$delta units
2467 bindall
<Shift-MouseWheel
> {
2468 set delta
[expr {- (%D
)}]
2469 $canv xview scroll
$delta units
2473 bindall
<$
::BM
> "canvscan mark %W %x %y"
2474 bindall
<B$
::BM-Motion
> "canvscan dragto %W %x %y"
2475 bind all
<$M1B-Key-w> {destroy
[winfo toplevel
%W
]}
2476 bind .
<$M1B-Key-w> doquit
2477 bindkey
<Home
> selfirstline
2478 bindkey
<End
> sellastline
2479 bind .
<Key-Up
> "selnextline -1"
2480 bind .
<Key-Down
> "selnextline 1"
2481 bind .
<Shift-Key-Up
> "dofind -1 0"
2482 bind .
<Shift-Key-Down
> "dofind 1 0"
2483 bindkey
<Key-Right
> "goforw"
2484 bindkey
<Key-Left
> "goback"
2485 bind .
<Key-Prior
> "selnextpage -1"
2486 bind .
<Key-Next
> "selnextpage 1"
2487 bind .
<$M1B-Home> "allcanvs yview moveto 0.0"
2488 bind .
<$M1B-End> "allcanvs yview moveto 1.0"
2489 bind .
<$M1B-Key-Up> "allcanvs yview scroll -1 units"
2490 bind .
<$M1B-Key-Down> "allcanvs yview scroll 1 units"
2491 bind .
<$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2492 bind .
<$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2493 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
2494 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
2495 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
2496 bindkey p
"selnextline -1"
2497 bindkey n
"selnextline 1"
2500 bindkey k
"selnextline -1"
2501 bindkey j
"selnextline 1"
2505 bindkey d
"$ctext yview scroll 18 units"
2506 bindkey u
"$ctext yview scroll -18 units"
2507 bindkey
/ {focus
$fstring}
2508 bindkey
<Key-KP_Divide
> {focus
$fstring}
2509 bindkey
<Key-Return
> {dofind
1 1}
2510 bindkey ?
{dofind
-1 1}
2512 bind .
<F5
> updatecommits
2513 bindmodfunctionkey Shift
5 reloadcommits
2514 bind .
<F2
> showrefs
2515 bindmodfunctionkey Shift
4 {newview
0}
2516 bind .
<F4
> edit_or_newview
2517 bind .
<$M1B-q> doquit
2518 bind .
<$M1B-f> {dofind
1 1}
2519 bind .
<$M1B-g> {dofind
1 0}
2520 bind .
<$M1B-r> dosearchback
2521 bind .
<$M1B-s> dosearch
2522 bind .
<$M1B-equal> {incrfont
1}
2523 bind .
<$M1B-plus> {incrfont
1}
2524 bind .
<$M1B-KP_Add> {incrfont
1}
2525 bind .
<$M1B-minus> {incrfont
-1}
2526 bind .
<$M1B-KP_Subtract> {incrfont
-1}
2527 wm protocol . WM_DELETE_WINDOW doquit
2528 bind .
<Destroy
> {stop_backends
}
2529 bind .
<Button-1
> "click %W"
2530 bind $fstring <Key-Return
> {dofind
1 1}
2531 bind $sha1entry <Key-Return
> {gotocommit
; break}
2532 bind $sha1entry <<PasteSelection>> clearsha1
2533 bind $cflist <1> {sel_flist %W %x %y; break}
2534 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2535 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2537 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2538 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2539 bind $ctext <Button-1> {focus %W}
2540 bind $ctext <<Selection>> rehighlight_search_results
2542 set maincursor [. cget -cursor]
2543 set textcursor [$ctext cget -cursor]
2544 set curtextcursor $textcursor
2546 set rowctxmenu .rowctxmenu
2547 makemenu $rowctxmenu {
2548 {mc "Diff this -> selected" command {diffvssel 0}}
2549 {mc "Diff selected -> this" command {diffvssel 1}}
2550 {mc "Make patch" command mkpatch}
2551 {mc "Create tag" command mktag}
2552 {mc "Write commit to file" command writecommit}
2553 {mc "Create new branch" command mkbranch}
2554 {mc "Cherry-pick this commit" command cherrypick}
2555 {mc "Reset HEAD branch to here" command resethead}
2556 {mc "Mark this commit" command markhere}
2557 {mc "Return to mark" command gotomark}
2558 {mc "Find descendant of this and mark" command find_common_desc}
2559 {mc "Compare with marked commit" command compare_commits}
2560 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2561 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2563 $rowctxmenu configure -tearoff 0
2565 set fakerowmenu .fakerowmenu
2566 makemenu $fakerowmenu {
2567 {mc "Diff this -> selected" command {diffvssel 0}}
2568 {mc "Diff selected -> this" command {diffvssel 1}}
2569 {mc "Make patch" command mkpatch}
2570 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2571 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2573 $fakerowmenu configure -tearoff 0
2575 set headctxmenu .headctxmenu
2576 makemenu $headctxmenu {
2577 {mc "Check out this branch" command cobranch}
2578 {mc "Remove this branch" command rmbranch}
2580 $headctxmenu configure -tearoff 0
2583 set flist_menu .flistctxmenu
2584 makemenu $flist_menu {
2585 {mc "Highlight this too" command {flist_hl 0}}
2586 {mc "Highlight this only" command {flist_hl 1}}
2587 {mc "External diff" command {external_diff}}
2588 {mc "Blame parent commit" command {external_blame 1}}
2590 $flist_menu configure -tearoff 0
2593 set diff_menu .diffctxmenu
2594 makemenu $diff_menu {
2595 {mc "Show origin of this line" command show_line_source}
2596 {mc "Run git gui blame on this line" command {external_blame_diff}}
2598 $diff_menu configure -tearoff 0
2601 # Windows sends all mouse wheel events to the current focused window, not
2602 # the one where the mouse hovers, so bind those events here and redirect
2603 # to the correct window
2604 proc windows_mousewheel_redirector {W X Y D} {
2605 global canv canv2 canv3
2606 set w [winfo containing -displayof $W $X $Y]
2608 set u [expr {$D < 0 ? 5 : -5}]
2609 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2610 allcanvs yview scroll $u units
2613 $w yview scroll $u units
2619 # Update row number label when selectedline changes
2620 proc selectedline_change {n1 n2 op} {
2621 global selectedline rownumsel
2623 if {$selectedline eq {}} {
2626 set rownumsel [expr {$selectedline + 1}]
2630 # mouse-2 makes all windows scan vertically, but only the one
2631 # the cursor is in scans horizontally
2632 proc canvscan {op w x y} {
2633 global canv canv2 canv3
2634 foreach c [list $canv $canv2 $canv3] {
2643 proc scrollcanv {cscroll f0 f1} {
2644 $cscroll set $f0 $f1
2649 # when we make a key binding for the toplevel, make sure
2650 # it doesn't get triggered when that key is pressed in the
2651 # find string entry widget.
2652 proc bindkey {ev script} {
2655 set escript [bind Entry $ev]
2656 if {$escript == {}} {
2657 set escript [bind Entry <Key>]
2659 foreach e $entries {
2660 bind $e $ev "$escript; break"
2664 proc bindmodfunctionkey {mod n script} {
2665 bind . <$mod-F$n> $script
2666 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2669 # set the focus back to the toplevel for any click outside
2672 global ctext entries
2673 foreach e [concat $entries $ctext] {
2674 if {$w == $e} return
2679 # Adjust the progress bar for a change in requested extent or canvas size
2680 proc adjustprogress {} {
2681 global progresscanv progressitem progresscoords
2682 global fprogitem fprogcoord lastprogupdate progupdatepending
2683 global rprogitem rprogcoord use_ttk
2686 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2690 set w [expr {[winfo width $progresscanv] - 4}]
2691 set x0 [expr {$w * [lindex $progresscoords 0]}]
2692 set x1 [expr {$w * [lindex $progresscoords 1]}]
2693 set h [winfo height $progresscanv]
2694 $progresscanv coords $progressitem $x0 0 $x1 $h
2695 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2696 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2697 set now [clock clicks -milliseconds]
2698 if {$now >= $lastprogupdate + 100} {
2699 set progupdatepending 0
2701 } elseif {!$progupdatepending} {
2702 set progupdatepending 1
2703 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2707 proc doprogupdate {} {
2708 global lastprogupdate progupdatepending
2710 if {$progupdatepending} {
2711 set progupdatepending 0
2712 set lastprogupdate [clock clicks -milliseconds]
2717 proc savestuff {w} {
2718 global canv canv2 canv3 mainfont textfont uifont tabstop
2719 global stuffsaved findmergefiles maxgraphpct
2720 global maxwidth showneartags showlocalchanges
2721 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2722 global cmitmode wrapcomment datetimeformat limitdiffs
2723 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2724 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2725 global hideremotes want_ttk maxrefs
2727 if {$stuffsaved} return
2728 if {![winfo viewable .]} return
2730 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2731 set f [open "~/.gitk-new" w]
2732 if {$::tcl_platform(platform) eq {windows}} {
2733 file attributes "~/.gitk-new" -hidden true
2735 puts $f [list set mainfont $mainfont]
2736 puts $f [list set textfont $textfont]
2737 puts $f [list set uifont $uifont]
2738 puts $f [list set tabstop $tabstop]
2739 puts $f [list set findmergefiles $findmergefiles]
2740 puts $f [list set maxgraphpct $maxgraphpct]
2741 puts $f [list set maxwidth $maxwidth]
2742 puts $f [list set cmitmode $cmitmode]
2743 puts $f [list set wrapcomment $wrapcomment]
2744 puts $f [list set autoselect $autoselect]
2745 puts $f [list set autosellen $autosellen]
2746 puts $f [list set showneartags $showneartags]
2747 puts $f [list set maxrefs $maxrefs]
2748 puts $f [list set hideremotes $hideremotes]
2749 puts $f [list set showlocalchanges $showlocalchanges]
2750 puts $f [list set datetimeformat $datetimeformat]
2751 puts $f [list set limitdiffs $limitdiffs]
2752 puts $f [list set uicolor $uicolor]
2753 puts $f [list set want_ttk $want_ttk]
2754 puts $f [list set bgcolor $bgcolor]
2755 puts $f [list set fgcolor $fgcolor]
2756 puts $f [list set colors $colors]
2757 puts $f [list set diffcolors $diffcolors]
2758 puts $f [list set markbgcolor $markbgcolor]
2759 puts $f [list set diffcontext $diffcontext]
2760 puts $f [list set selectbgcolor $selectbgcolor]
2761 puts $f [list set extdifftool $extdifftool]
2762 puts $f [list set perfile_attrs $perfile_attrs]
2764 puts $f "set geometry(main) [wm geometry .]"
2765 puts $f "set geometry(state) [wm state .]"
2766 puts $f "set geometry(topwidth) [winfo width .tf]"
2767 puts $f "set geometry(topheight) [winfo height .tf]"
2769 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2770 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2772 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2773 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2775 puts $f "set geometry(botwidth) [winfo width .bleft]"
2776 puts $f "set geometry(botheight) [winfo height .bleft]"
2778 puts -nonewline $f "set permviews {"
2779 for {set v 0} {$v < $nextviewnum} {incr v} {
2780 if {$viewperm($v)} {
2781 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2786 file rename -force "~/.gitk-new" "~/.gitk"
2791 proc resizeclistpanes {win w} {
2792 global oldwidth use_ttk
2793 if {[info exists oldwidth($win)]} {
2795 set s0 [$win sashpos 0]
2796 set s1 [$win sashpos 1]
2798 set s0 [$win sash coord 0]
2799 set s1 [$win sash coord 1]
2802 set sash0 [expr {int($w/2 - 2)}]
2803 set sash1 [expr {int($w*5/6 - 2)}]
2805 set factor [expr {1.0 * $w / $oldwidth($win)}]
2806 set sash0 [expr {int($factor * [lindex $s0 0])}]
2807 set sash1 [expr {int($factor * [lindex $s1 0])}]
2811 if {$sash1 < $sash0 + 20} {
2812 set sash1 [expr {$sash0 + 20}]
2814 if {$sash1 > $w - 10} {
2815 set sash1 [expr {$w - 10}]
2816 if {$sash0 > $sash1 - 20} {
2817 set sash0 [expr {$sash1 - 20}]
2822 $win sashpos 0 $sash0
2823 $win sashpos 1 $sash1
2825 $win sash place 0 $sash0 [lindex $s0 1]
2826 $win sash place 1 $sash1 [lindex $s1 1]
2829 set oldwidth($win) $w
2832 proc resizecdetpanes {win w} {
2833 global oldwidth use_ttk
2834 if {[info exists oldwidth($win)]} {
2836 set s0 [$win sashpos 0]
2838 set s0 [$win sash coord 0]
2841 set sash0 [expr {int($w*3/4 - 2)}]
2843 set factor [expr {1.0 * $w / $oldwidth($win)}]
2844 set sash0 [expr {int($factor * [lindex $s0 0])}]
2848 if {$sash0 > $w - 15} {
2849 set sash0 [expr {$w - 15}]
2853 $win sashpos 0 $sash0
2855 $win sash place 0 $sash0 [lindex $s0 1]
2858 set oldwidth($win) $w
2861 proc allcanvs args {
2862 global canv canv2 canv3
2868 proc bindall {event action} {
2869 global canv canv2 canv3
2870 bind $canv $event $action
2871 bind $canv2 $event $action
2872 bind $canv3 $event $action
2878 if {[winfo exists $w]} {
2883 wm title $w [mc "About gitk"]
2885 message $w.m -text [mc "
2886 Gitk - a commit viewer for git
2888 Copyright \u00a9 2005-2011 Paul Mackerras
2890 Use and redistribute under the terms of the GNU General Public License"] \
2891 -justify center -aspect 400 -border 2 -bg white -relief groove
2892 pack $w.m -side top -fill x -padx 2 -pady 2
2893 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2894 pack $w.ok -side bottom
2895 bind $w <Visibility> "focus $w.ok"
2896 bind $w <Key-Escape> "destroy $w"
2897 bind $w <Key-Return> "destroy $w"
2898 tk::PlaceWindow $w widget .
2904 if {[winfo exists $w]} {
2908 if {[tk windowingsystem] eq {aqua}} {
2914 wm title $w [mc "Gitk key bindings"]
2916 message $w.m -text "
2917 [mc "Gitk key bindings:"]
2919 [mc "<%s-Q> Quit" $M1T]
2920 [mc "<%s-W> Close window" $M1T]
2921 [mc "<Home> Move to first commit"]
2922 [mc "<End> Move to last commit"]
2923 [mc "<Up>, p, k Move up one commit"]
2924 [mc "<Down>, n, j Move down one commit"]
2925 [mc "<Left>, z, h Go back in history list"]
2926 [mc "<Right>, x, l Go forward in history list"]
2927 [mc "<PageUp> Move up one page in commit list"]
2928 [mc "<PageDown> Move down one page in commit list"]
2929 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2930 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2931 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2932 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2933 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2934 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2935 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2936 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2937 [mc "<Delete>, b Scroll diff view up one page"]
2938 [mc "<Backspace> Scroll diff view up one page"]
2939 [mc "<Space> Scroll diff view down one page"]
2940 [mc "u Scroll diff view up 18 lines"]
2941 [mc "d Scroll diff view down 18 lines"]
2942 [mc "<%s-F> Find" $M1T]
2943 [mc "<%s-G> Move to next find hit" $M1T]
2944 [mc "<Return> Move to next find hit"]
2945 [mc "/ Focus the search box"]
2946 [mc "? Move to previous find hit"]
2947 [mc "f Scroll diff view to next file"]
2948 [mc "<%s-S> Search for next hit in diff view" $M1T]
2949 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2950 [mc "<%s-KP+> Increase font size" $M1T]
2951 [mc "<%s-plus> Increase font size" $M1T]
2952 [mc "<%s-KP-> Decrease font size" $M1T]
2953 [mc "<%s-minus> Decrease font size" $M1T]
2956 -justify left -bg white -border 2 -relief groove
2957 pack $w.m -side top -fill both -padx 2 -pady 2
2958 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2959 bind $w <Key-Escape> [list destroy $w]
2960 pack $w.ok -side bottom
2961 bind $w <Visibility> "focus $w.ok"
2962 bind $w <Key-Escape> "destroy $w"
2963 bind $w <Key-Return> "destroy $w"
2966 # Procedures for manipulating the file list window at the
2967 # bottom right of the overall window.
2969 proc treeview {w l openlevs} {
2970 global treecontents treediropen treeheight treeparent treeindex
2980 set treecontents() {}
2981 $w conf -state normal
2983 while {[string range $f 0 $prefixend] ne $prefix} {
2984 if {$lev <= $openlevs} {
2985 $w mark set e:$treeindex($prefix) "end -1c"
2986 $w mark gravity e:$treeindex($prefix) left
2988 set treeheight($prefix) $ht
2989 incr ht [lindex $htstack end]
2990 set htstack [lreplace $htstack end end]
2991 set prefixend [lindex $prefendstack end]
2992 set prefendstack [lreplace $prefendstack end end]
2993 set prefix [string range $prefix 0 $prefixend]
2996 set tail [string range $f [expr {$prefixend+1}] end]
2997 while {[set slash [string first "/" $tail]] >= 0} {
3000 lappend prefendstack $prefixend
3001 incr prefixend [expr {$slash + 1}]
3002 set d [string range $tail 0 $slash]
3003 lappend treecontents($prefix) $d
3004 set oldprefix $prefix
3006 set treecontents($prefix) {}
3007 set treeindex($prefix) [incr ix]
3008 set treeparent($prefix) $oldprefix
3009 set tail [string range $tail [expr {$slash+1}] end]
3010 if {$lev <= $openlevs} {
3012 set treediropen($prefix) [expr {$lev < $openlevs}]
3013 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3014 $w mark set d:$ix "end -1c"
3015 $w mark gravity d:$ix left
3017 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3019 $w image create end -align center -image $bm -padx 1 \
3021 $w insert end $d [highlight_tag $prefix]
3022 $w mark set s:$ix "end -1c"
3023 $w mark gravity s:$ix left
3028 if {$lev <= $openlevs} {
3031 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3033 $w insert end $tail [highlight_tag $f]
3035 lappend treecontents($prefix) $tail
3038 while {$htstack ne {}} {
3039 set treeheight($prefix) $ht
3040 incr ht [lindex $htstack end]
3041 set htstack [lreplace $htstack end end]
3042 set prefixend [lindex $prefendstack end]
3043 set prefendstack [lreplace $prefendstack end end]
3044 set prefix [string range $prefix 0 $prefixend]
3046 $w conf -state disabled
3049 proc linetoelt {l} {
3050 global treeheight treecontents
3055 foreach e $treecontents($prefix) {
3060 if {[string index $e end] eq "/"} {
3061 set n $treeheight($prefix$e)
3073 proc highlight_tree {y prefix} {
3074 global treeheight treecontents cflist
3076 foreach e $treecontents($prefix) {
3078 if {[highlight_tag $path] ne {}} {
3079 $cflist tag add bold $y.0 "$y.0 lineend"
3082 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3083 set y [highlight_tree $y $path]
3089 proc treeclosedir {w dir} {
3090 global treediropen treeheight treeparent treeindex
3092 set ix $treeindex($dir)
3093 $w conf -state normal
3094 $w delete s:$ix e:$ix
3095 set treediropen($dir) 0
3096 $w image configure a:$ix -image tri-rt
3097 $w conf -state disabled
3098 set n [expr {1 - $treeheight($dir)}]
3099 while {$dir ne {}} {
3100 incr treeheight($dir) $n
3101 set dir $treeparent($dir)
3105 proc treeopendir {w dir} {
3106 global treediropen treeheight treeparent treecontents treeindex
3108 set ix $treeindex($dir)
3109 $w conf -state normal
3110 $w image configure a:$ix -image tri-dn
3111 $w mark set e:$ix s:$ix
3112 $w mark gravity e:$ix right
3115 set n [llength $treecontents($dir)]
3116 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3119 incr treeheight($x) $n
3121 foreach e $treecontents($dir) {
3123 if {[string index $e end] eq "/"} {
3124 set iy $treeindex($de)
3125 $w mark set d:$iy e:$ix
3126 $w mark gravity d:$iy left
3127 $w insert e:$ix $str
3128 set treediropen($de) 0
3129 $w image create e:$ix -align center -image tri-rt -padx 1 \
3131 $w insert e:$ix $e [highlight_tag $de]
3132 $w mark set s:$iy e:$ix
3133 $w mark gravity s:$iy left
3134 set treeheight($de) 1
3136 $w insert e:$ix $str
3137 $w insert e:$ix $e [highlight_tag $de]
3140 $w mark gravity e:$ix right
3141 $w conf -state disabled
3142 set treediropen($dir) 1
3143 set top [lindex [split [$w index @0,0] .] 0]
3144 set ht [$w cget -height]
3145 set l [lindex [split [$w index s:$ix] .] 0]
3148 } elseif {$l + $n + 1 > $top + $ht} {
3149 set top [expr {$l + $n + 2 - $ht}]
3157 proc treeclick {w x y} {
3158 global treediropen cmitmode ctext cflist cflist_top
3160 if {$cmitmode ne "tree"} return
3161 if {![info exists cflist_top]} return
3162 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3163 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3164 $cflist tag add highlight $l.0 "$l.0 lineend"
3170 set e [linetoelt $l]
3171 if {[string index $e end] ne "/"} {
3173 } elseif {$treediropen($e)} {
3180 proc setfilelist {id} {
3181 global treefilelist cflist jump_to_here
3183 treeview $cflist $treefilelist($id) 0
3184 if {$jump_to_here ne {}} {
3185 set f [lindex $jump_to_here 0]
3186 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3192 image create bitmap tri-rt -background black -foreground blue -data {
3193 #define tri-rt_width 13
3194 #define tri-rt_height 13
3195 static unsigned char tri-rt_bits[] = {
3196 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3197 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3200 #define tri-rt-mask_width 13
3201 #define tri-rt-mask_height 13
3202 static unsigned char tri-rt-mask_bits[] = {
3203 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3204 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3207 image create bitmap tri-dn -background black -foreground blue -data {
3208 #define tri-dn_width 13
3209 #define tri-dn_height 13
3210 static unsigned char tri-dn_bits[] = {
3211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3212 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3215 #define tri-dn-mask_width 13
3216 #define tri-dn-mask_height 13
3217 static unsigned char tri-dn-mask_bits[] = {
3218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3219 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3223 image create bitmap reficon-T -background black -foreground yellow -data {
3224 #define tagicon_width 13
3225 #define tagicon_height 9
3226 static unsigned char tagicon_bits[] = {
3227 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3228 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3230 #define tagicon-mask_width 13
3231 #define tagicon-mask_height 9
3232 static unsigned char tagicon-mask_bits[] = {
3233 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3234 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3237 #define headicon_width 13
3238 #define headicon_height 9
3239 static unsigned char headicon_bits[] = {
3240 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3241 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3244 #define headicon-mask_width 13
3245 #define headicon-mask_height 9
3246 static unsigned char headicon-mask_bits[] = {
3247 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3248 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3250 image create bitmap reficon-H -background black -foreground green \
3251 -data $rectdata -maskdata $rectmask
3252 image create bitmap reficon-o -background black -foreground "#ddddff" \
3253 -data $rectdata -maskdata $rectmask
3255 proc init_flist {first} {
3256 global cflist cflist_top difffilestart
3258 $cflist conf -state normal
3259 $cflist delete 0.0 end
3261 $cflist insert end $first
3263 $cflist tag add highlight 1.0 "1.0 lineend"
3265 catch {unset cflist_top}
3267 $cflist conf -state disabled
3268 set difffilestart {}
3271 proc highlight_tag {f} {
3272 global highlight_paths
3274 foreach p $highlight_paths {
3275 if {[string match $p $f]} {
3282 proc highlight_filelist {} {
3283 global cmitmode cflist
3285 $cflist conf -state normal
3286 if {$cmitmode ne "tree"} {
3287 set end [lindex [split [$cflist index end] .] 0]
3288 for {set l 2} {$l < $end} {incr l} {
3289 set line [$cflist get $l.0 "$l.0 lineend"]
3290 if {[highlight_tag $line] ne {}} {
3291 $cflist tag add bold $l.0 "$l.0 lineend"
3297 $cflist conf -state disabled
3300 proc unhighlight_filelist {} {
3303 $cflist conf -state normal
3304 $cflist tag remove bold 1.0 end
3305 $cflist conf -state disabled
3308 proc add_flist {fl} {
3311 $cflist conf -state normal
3313 $cflist insert end "\n"
3314 $cflist insert end $f [highlight_tag $f]
3316 $cflist conf -state disabled
3319 proc sel_flist {w x y} {
3320 global ctext difffilestart cflist cflist_top cmitmode
3322 if {$cmitmode eq "tree"} return
3323 if {![info exists cflist_top]} return
3324 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3325 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3326 $cflist tag add highlight $l.0 "$l.0 lineend"
3331 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3333 suppress_highlighting_file_for_current_scrollpos
3336 proc pop_flist_menu {w X Y x y} {
3337 global ctext cflist cmitmode flist_menu flist_menu_file
3338 global treediffs diffids
3341 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3343 if {$cmitmode eq "tree"} {
3344 set e [linetoelt $l]
3345 if {[string index $e end] eq "/"} return
3347 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3349 set flist_menu_file $e
3350 set xdiffstate "normal"
3351 if {$cmitmode eq "tree"} {
3352 set xdiffstate "disabled"
3354 # Disable "External diff" item in tree mode
3355 $flist_menu entryconf 2 -state $xdiffstate
3356 tk_popup $flist_menu $X $Y
3359 proc find_ctext_fileinfo {line} {
3360 global ctext_file_names ctext_file_lines
3362 set ok [bsearch $ctext_file_lines $line]
3363 set tline [lindex $ctext_file_lines $ok]
3365 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3368 return [list [lindex $ctext_file_names $ok] $tline]
3372 proc pop_diff_menu {w X Y x y} {
3373 global ctext diff_menu flist_menu_file
3374 global diff_menu_txtpos diff_menu_line
3375 global diff_menu_filebase
3377 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3378 set diff_menu_line [lindex $diff_menu_txtpos 0]
3379 # don't pop up the menu on hunk-separator or file-separator lines
3380 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3384 set f [find_ctext_fileinfo $diff_menu_line]
3385 if {$f eq {}} return
3386 set flist_menu_file [lindex $f 0]
3387 set diff_menu_filebase [lindex $f 1]
3388 tk_popup $diff_menu $X $Y
3391 proc flist_hl {only} {
3392 global flist_menu_file findstring gdttype
3394 set x [shellquote $flist_menu_file]
3395 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3398 append findstring " " $x
3400 set gdttype [mc "touching paths:"]
3403 proc gitknewtmpdir {} {
3404 global diffnum gitktmpdir gitdir
3406 if {![info exists gitktmpdir]} {
3407 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3408 if {[catch {file mkdir $gitktmpdir} err]} {
3409 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3416 set diffdir [file join $gitktmpdir $diffnum]
3417 if {[catch {file mkdir $diffdir} err]} {
3418 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3424 proc save_file_from_commit {filename output what} {
3427 if {[catch {exec git show $filename -- > $output} err]} {
3428 if {[string match "fatal: bad revision *" $err]} {
3431 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3437 proc external_diff_get_one_file {diffid filename diffdir} {
3438 global nullid nullid2 nullfile
3441 if {$diffid == $nullid} {
3442 set difffile [file join $worktree $filename]
3443 if {[file exists $difffile]} {
3448 if {$diffid == $nullid2} {
3449 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3450 return [save_file_from_commit :$filename $difffile index]
3452 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3453 return [save_file_from_commit $diffid:$filename $difffile \
3457 proc external_diff {} {
3458 global nullid nullid2
3459 global flist_menu_file
3463 if {[llength $diffids] == 1} {
3464 # no reference commit given
3465 set diffidto [lindex $diffids 0]
3466 if {$diffidto eq $nullid} {
3467 # diffing working copy with index
3468 set diffidfrom $nullid2
3469 } elseif {$diffidto eq $nullid2} {
3470 # diffing index with HEAD
3471 set diffidfrom "HEAD"
3473 # use first parent commit
3474 global parentlist selectedline
3475 set diffidfrom [lindex $parentlist $selectedline 0]
3478 set diffidfrom [lindex $diffids 0]
3479 set diffidto [lindex $diffids 1]
3482 # make sure that several diffs wont collide
3483 set diffdir [gitknewtmpdir]
3484 if {$diffdir eq {}} return
3486 # gather files to diff
3487 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3488 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3490 if {$difffromfile ne {} && $difftofile ne {}} {
3491 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3492 if {[catch {set fl [open |$cmd r]} err]} {
3493 file delete -force $diffdir
3494 error_popup "$extdifftool: [mc "command failed:"] $err"
3496 fconfigure $fl -blocking 0
3497 filerun $fl [list delete_at_eof $fl $diffdir]
3502 proc find_hunk_blamespec {base line} {
3505 # Find and parse the hunk header
3506 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3507 if {$s_lix eq {}} return
3509 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3510 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3511 s_line old_specs osz osz1 new_line nsz]} {
3515 # base lines for the parents
3516 set base_lines [list $new_line]
3517 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3518 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3519 old_spec old_line osz]} {
3522 lappend base_lines $old_line
3525 # Now scan the lines to determine offset within the hunk
3526 set max_parent [expr {[llength $base_lines]-2}]
3528 set s_lno [lindex [split $s_lix "."] 0]
3530 # Determine if the line is removed
3531 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3532 if {[string match {[-+ ]*} $chunk]} {
3533 set removed_idx [string first "-" $chunk]
3534 # Choose a parent index
3535 if {$removed_idx >= 0} {
3536 set parent $removed_idx
3538 set unchanged_idx [string first " " $chunk]
3539 if {$unchanged_idx >= 0} {
3540 set parent $unchanged_idx
3542 # blame the current commit
3546 # then count other lines that belong to it
3547 for {set i $line} {[incr i -1] > $s_lno} {} {
3548 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3549 # Determine if the line is removed
3550 set removed_idx [string first "-" $chunk]
3552 set code [string index $chunk $parent]
3553 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3557 if {$removed_idx < 0} {
3567 incr dline [lindex $base_lines $parent]
3568 return [list $parent $dline]
3571 proc external_blame_diff {} {
3572 global currentid cmitmode
3573 global diff_menu_txtpos diff_menu_line
3574 global diff_menu_filebase flist_menu_file
3576 if {$cmitmode eq "tree"} {
3578 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3580 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3582 set parent_idx [lindex $hinfo 0]
3583 set line [lindex $hinfo 1]
3590 external_blame $parent_idx $line
3593 # Find the SHA1 ID of the blob for file $fname in the index
3595 proc index_sha1 {fname} {
3596 set f [open [list | git ls-files -s $fname] r]
3597 while {[gets $f line] >= 0} {
3598 set info [lindex [split $line "\t"] 0]
3599 set stage [lindex $info 2]
3600 if {$stage eq "0" || $stage eq "2"} {
3602 return [lindex $info 1]
3609 # Turn an absolute path into one relative to the current directory
3610 proc make_relative {f} {
3611 if {[file pathtype $f] eq "relative"} {
3614 set elts [file split $f]
3615 set here [file split [pwd]]
3620 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3627 set elts [concat $res [lrange $elts $ei end]]
3628 return [eval file join $elts]
3631 proc external_blame {parent_idx {line {}}} {
3632 global flist_menu_file cdup
3633 global nullid nullid2
3634 global parentlist selectedline currentid
3636 if {$parent_idx > 0} {
3637 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3639 set base_commit $currentid
3642 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3643 error_popup [mc "No such commit"]
3647 set cmdline [list git gui blame]
3648 if {$line ne {} && $line > 1} {
3649 lappend cmdline "--line=$line"
3651 set f [file join $cdup $flist_menu_file]
3652 # Unfortunately it seems git gui blame doesn't like
3653 # being given an absolute path...
3654 set f [make_relative $f]
3655 lappend cmdline $base_commit $f
3656 if {[catch {eval exec $cmdline &} err]} {
3657 error_popup "[mc "git gui blame: command failed:"] $err"
3661 proc show_line_source {} {
3662 global cmitmode currentid parents curview blamestuff blameinst
3663 global diff_menu_line diff_menu_filebase flist_menu_file
3664 global nullid nullid2 gitdir cdup
3667 if {$cmitmode eq "tree"} {
3669 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3671 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3672 if {$h eq {}} return
3673 set pi [lindex $h 0]
3675 mark_ctext_line $diff_menu_line
3679 if {$currentid eq $nullid} {
3681 # must be a merge in progress...
3683 # get the last line from .git/MERGE_HEAD
3684 set f [open [file join $gitdir MERGE_HEAD] r]
3685 set id [lindex [split [read $f] "\n"] end-1]
3688 error_popup [mc "Couldn't read merge head: %s" $err]
3691 } elseif {$parents($curview,$currentid) eq $nullid2} {
3692 # need to do the blame from the index
3694 set from_index [index_sha1 $flist_menu_file]
3696 error_popup [mc "Error reading index: %s" $err]
3700 set id $parents($curview,$currentid)
3703 set id [lindex $parents($curview,$currentid) $pi]
3705 set line [lindex $h 1]
3708 if {$from_index ne {}} {
3709 lappend blameargs | git cat-file blob $from_index
3711 lappend blameargs | git blame -p -L$line,+1
3712 if {$from_index ne {}} {
3713 lappend blameargs --contents -
3715 lappend blameargs $id
3717 lappend blameargs -- [file join $cdup $flist_menu_file]
3719 set f [open $blameargs r]
3721 error_popup [mc "Couldn't start git blame: %s" $err]
3724 nowbusy blaming [mc "Searching"]
3725 fconfigure $f -blocking 0
3726 set i [reg_instance $f]
3727 set blamestuff($i) {}
3729 filerun $f [list read_line_source $f $i]
3732 proc stopblaming {} {
3735 if {[info exists blameinst]} {
3736 stop_instance $blameinst
3742 proc read_line_source {fd inst} {
3743 global blamestuff curview commfd blameinst nullid nullid2
3745 while {[gets $fd line] >= 0} {
3746 lappend blamestuff($inst) $line
3754 fconfigure $fd -blocking 1
3755 if {[catch {close $fd} err]} {
3756 error_popup [mc "Error running git blame: %s" $err]
3761 set line [split [lindex $blamestuff($inst) 0] " "]
3762 set id [lindex $line 0]
3763 set lnum [lindex $line 1]
3764 if {[string length $id] == 40 && [string is xdigit $id] &&
3765 [string is digit -strict $lnum]} {
3766 # look for "filename" line
3767 foreach l $blamestuff($inst) {
3768 if {[string match "filename *" $l]} {
3769 set fname [string range $l 9 end]
3775 # all looks good, select it
3776 if {$id eq $nullid} {
3777 # blame uses all-zeroes to mean not committed,
3778 # which would mean a change in the index
3781 if {[commitinview $id $curview]} {
3782 selectline [rowofcommit $id] 1 [list $fname $lnum]
3784 error_popup [mc "That line comes from commit %s, \
3785 which is not in this view" [shortids $id]]
3788 puts "oops couldn't parse git blame output"
3793 # delete $dir when we see eof on $f (presumably because the child has exited)
3794 proc delete_at_eof {f dir} {
3795 while {[gets $f line] >= 0} {}
3797 if {[catch {close $f} err]} {
3798 error_popup "[mc "External diff viewer failed:"] $err"
3800 file delete -force $dir
3806 # Functions for adding and removing shell-type quoting
3808 proc shellquote {str} {
3809 if {![string match "*\['\"\\ \t]*" $str]} {
3812 if {![string match "*\['\"\\]*" $str]} {
3815 if {![string match "*'*" $str]} {
3818 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3821 proc shellarglist {l} {
3827 append str [shellquote $a]
3832 proc shelldequote {str} {
3837 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3838 append ret [string range $str $used end]
3839 set used [string length $str]
3842 set first [lindex $first 0]
3843 set ch [string index $str $first]
3844 if {$first > $used} {
3845 append ret [string range $str $used [expr {$first - 1}]]
3848 if {$ch eq " " || $ch eq "\t"} break
3851 set first [string first "'" $str $used]
3853 error "unmatched single-quote"
3855 append ret [string range $str $used [expr {$first - 1}]]
3860 if {$used >= [string length $str]} {
3861 error "trailing backslash"
3863 append ret [string index $str $used]
3868 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3869 error "unmatched double-quote"
3871 set first [lindex $first 0]
3872 set ch [string index $str $first]
3873 if {$first > $used} {
3874 append ret [string range $str $used [expr {$first - 1}]]
3877 if {$ch eq "\""} break
3879 append ret [string index $str $used]
3883 return [list $used $ret]
3886 proc shellsplit {str} {
3889 set str [string trimleft $str]
3890 if {$str eq {}} break
3891 set dq [shelldequote $str]
3892 set n [lindex $dq 0]
3893 set word [lindex $dq 1]
3894 set str [string range $str $n end]
3900 # Code to implement multiple views
3902 proc newview {ishighlight} {
3903 global nextviewnum newviewname newishighlight
3904 global revtreeargs viewargscmd newviewopts curview
3906 set newishighlight $ishighlight
3908 if {[winfo exists $top]} {
3912 decode_view_opts $nextviewnum $revtreeargs
3913 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3914 set newviewopts($nextviewnum,perm) 0
3915 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3916 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3919 set known_view_options {
3920 {perm b . {} {mc "Remember this view"}}
3921 {reflabel l + {} {mc "References (space separated list):"}}
3922 {refs t15 .. {} {mc "Branches & tags:"}}
3923 {allrefs b *. "--all" {mc "All refs"}}
3924 {branches b . "--branches" {mc "All (local) branches"}}
3925 {tags b . "--tags" {mc "All tags"}}
3926 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3927 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3928 {author t15 .. "--author=*" {mc "Author:"}}
3929 {committer t15 . "--committer=*" {mc "Committer:"}}
3930 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3931 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3932 {changes_l l + {} {mc "Changes to Files:"}}
3933 {pickaxe_s r0 . {} {mc "Fixed String"}}
3934 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3935 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3936 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3937 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3938 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3939 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3940 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3941 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3942 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3943 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3944 {lright b . "--left-right" {mc "Mark branch sides"}}
3945 {first b . "--first-parent" {mc "Limit to first parent"}}
3946 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3947 {args t50 *. {} {mc "Additional arguments to git log:"}}
3948 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3949 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3952 # Convert $newviewopts($n, ...) into args for git log.
3953 proc encode_view_opts {n} {
3954 global known_view_options newviewopts
3957 foreach opt $known_view_options {
3958 set patterns [lindex $opt 3]
3959 if {$patterns eq {}} continue
3960 set pattern [lindex $patterns 0]
3962 if {[lindex $opt 1] eq "b"} {
3963 set val $newviewopts($n,[lindex $opt 0])
3965 lappend rargs $pattern
3967 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
3968 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
3969 set val $newviewopts($n,$button_id)
3970 if {$val eq $value} {
3971 lappend rargs $pattern
3974 set val $newviewopts($n,[lindex $opt 0])
3975 set val [string trim $val]
3977 set pfix [string range $pattern 0 end-1]
3978 lappend rargs $pfix$val
3982 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
3983 return [concat $rargs [shellsplit $newviewopts($n,args)]]
3986 # Fill $newviewopts($n, ...) based on args for git log.
3987 proc decode_view_opts {n view_args} {
3988 global known_view_options newviewopts
3990 foreach opt $known_view_options {
3991 set id [lindex $opt 0]
3992 if {[lindex $opt 1] eq "b"} {
3995 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
3997 regexp {^(.*_)} $id uselessvar id
4003 set newviewopts($n,$id) $val
4007 foreach arg $view_args {
4008 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4009 && ![info exists found(limit)]} {
4010 set newviewopts($n,limit) $cnt
4015 foreach opt $known_view_options {
4016 set id [lindex $opt 0]
4017 if {[info exists found($id)]} continue
4018 foreach pattern [lindex $opt 3] {
4019 if {![string match $pattern $arg]} continue
4020 if {[lindex $opt 1] eq "b"} {
4023 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4025 regexp {^(.*_)} $id uselessvar id
4029 set size [string length $pattern]
4030 set val [string range $arg [expr {$size-1}] end]
4032 set newviewopts($n,$id) $val
4036 if {[info exists val]} break
4038 if {[info exists val]} continue
4039 if {[regexp {^-} $arg]} {
4042 lappend refargs $arg
4045 set newviewopts($n,refs) [shellarglist $refargs]
4046 set newviewopts($n,args) [shellarglist $oargs]
4049 proc edit_or_newview {} {
4061 global viewname viewperm newviewname newviewopts
4062 global viewargs viewargscmd
4064 set top .gitkvedit-$curview
4065 if {[winfo exists $top]} {
4069 decode_view_opts $curview $viewargs($curview)
4070 set newviewname($curview) $viewname($curview)
4071 set newviewopts($curview,perm) $viewperm($curview)
4072 set newviewopts($curview,cmd) $viewargscmd($curview)
4073 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4076 proc vieweditor {top n title} {
4077 global newviewname newviewopts viewfiles bgcolor
4078 global known_view_options NS
4081 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4082 make_transient $top .
4085 ${NS}::frame $top.nfr
4086 ${NS}::label $top.nl -text [mc "View Name"]
4087 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4088 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4089 pack $top.nl -in $top.nfr -side left -padx {0 5}
4090 pack $top.name -in $top.nfr -side left -padx {0 25}
4096 foreach opt $known_view_options {
4097 set id [lindex $opt 0]
4098 set type [lindex $opt 1]
4099 set flags [lindex $opt 2]
4100 set title [eval [lindex $opt 4]]
4103 if {$flags eq "+" || $flags eq "*"} {
4104 set cframe $top.fr$cnt
4106 ${NS}::frame $cframe
4107 pack $cframe -in $top -fill x -pady 3 -padx 3
4108 set cexpand [expr {$flags eq "*"}]
4109 } elseif {$flags eq ".." || $flags eq "*."} {
4110 set cframe $top.fr$cnt
4112 ${NS}::frame $cframe
4113 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4114 set cexpand [expr {$flags eq "*."}]
4120 ${NS}::label $cframe.l_$id -text $title
4121 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4122 } elseif {$type eq "b"} {
4123 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4124 pack $cframe.c_$id -in $cframe -side left \
4125 -padx [list $lxpad 0] -expand $cexpand -anchor w
4126 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4127 regexp {^(.*_)} $id uselessvar button_id
4128 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4129 pack $cframe.c_$id -in $cframe -side left \
4130 -padx [list $lxpad 0] -expand $cexpand -anchor w
4131 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4132 ${NS}::label $cframe.l_$id -text $title
4133 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4134 -textvariable newviewopts($n,$id)
4135 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4136 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4137 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4138 ${NS}::label $cframe.l_$id -text $title
4139 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4140 -textvariable newviewopts($n,$id)
4141 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4142 pack $cframe.e_$id -in $cframe -side top -fill x
4143 } elseif {$type eq "path"} {
4144 ${NS}::label $top.l -text $title
4145 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4146 text $top.t -width 40 -height 5 -background $bgcolor
4147 if {[info exists viewfiles($n)]} {
4148 foreach f $viewfiles($n) {
4149 $top.t insert end $f
4150 $top.t insert end "\n"
4152 $top.t delete {end - 1c} end
4153 $top.t mark set insert 0.0
4155 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4159 ${NS}::frame $top.buts
4160 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4161 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4162 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4163 bind $top <Control-Return> [list newviewok $top $n]
4164 bind $top <F5> [list newviewok $top $n 1]
4165 bind $top <Escape> [list destroy $top]
4166 grid $top.buts.ok $top.buts.apply $top.buts.can
4167 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4168 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4169 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4170 pack $top.buts -in $top -side top -fill x
4174 proc doviewmenu {m first cmd op argv} {
4175 set nmenu [$m index end]
4176 for {set i $first} {$i <= $nmenu} {incr i} {
4177 if {[$m entrycget $i -command] eq $cmd} {
4178 eval $m $op $i $argv
4184 proc allviewmenus {n op args} {
4187 doviewmenu .bar.view 5 [list showview $n] $op $args
4188 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4191 proc newviewok {top n {apply 0}} {
4192 global nextviewnum newviewperm newviewname newishighlight
4193 global viewname viewfiles viewperm selectedview curview
4194 global viewargs viewargscmd newviewopts viewhlmenu
4197 set newargs [encode_view_opts $n]
4199 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4203 foreach f [split [$top.t get 0.0 end] "\n"] {
4204 set ft [string trim $f]
4209 if {![info exists viewfiles($n)]} {
4210 # creating a new view
4212 set viewname($n) $newviewname($n)
4213 set viewperm($n) $newviewopts($n,perm)
4214 set viewfiles($n) $files
4215 set viewargs($n) $newargs
4216 set viewargscmd($n) $newviewopts($n,cmd)
4218 if {!$newishighlight} {
4221 run addvhighlight $n
4224 # editing an existing view
4225 set viewperm($n) $newviewopts($n,perm)
4226 if {$newviewname($n) ne $viewname($n)} {
4227 set viewname($n) $newviewname($n)
4228 doviewmenu .bar.view 5 [list showview $n] \
4229 entryconf [list -label $viewname($n)]
4230 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4231 # entryconf [list -label $viewname($n) -value $viewname($n)]
4233 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4234 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4235 set viewfiles($n) $files
4236 set viewargs($n) $newargs
4237 set viewargscmd($n) $newviewopts($n,cmd)
4238 if {$curview == $n} {
4244 catch {destroy $top}
4248 global curview viewperm hlview selectedhlview
4250 if {$curview == 0} return
4251 if {[info exists hlview] && $hlview == $curview} {
4252 set selectedhlview [mc "None"]
4255 allviewmenus $curview delete
4256 set viewperm($curview) 0
4260 proc addviewmenu {n} {
4261 global viewname viewhlmenu
4263 .bar.view add radiobutton -label $viewname($n) \
4264 -command [list showview $n] -variable selectedview -value $n
4265 #$viewhlmenu add radiobutton -label $viewname($n) \
4266 # -command [list addvhighlight $n] -variable selectedhlview
4270 global curview cached_commitrow ordertok
4271 global displayorder parentlist rowidlist rowisopt rowfinal
4272 global colormap rowtextx nextcolor canvxmax
4273 global numcommits viewcomplete
4274 global selectedline currentid canv canvy0
4276 global pending_select mainheadid
4279 global hlview selectedhlview commitinterest
4281 if {$n == $curview} return
4283 set ymax [lindex [$canv cget -scrollregion] 3]
4284 set span [$canv yview]
4285 set ytop [expr {[lindex $span 0] * $ymax}]
4286 set ybot [expr {[lindex $span 1] * $ymax}]
4287 set yscreen [expr {($ybot - $ytop) / 2}]
4288 if {$selectedline ne {}} {
4289 set selid $currentid
4290 set y [yc $selectedline]
4291 if {$ytop < $y && $y < $ybot} {
4292 set yscreen [expr {$y - $ytop}]
4294 } elseif {[info exists pending_select]} {
4295 set selid $pending_select
4296 unset pending_select
4300 catch {unset treediffs}
4302 if {[info exists hlview] && $hlview == $n} {
4304 set selectedhlview [mc "None"]
4306 catch {unset commitinterest}
4307 catch {unset cached_commitrow}
4308 catch {unset ordertok}
4312 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4313 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4316 if {![info exists viewcomplete($n)]} {
4326 set numcommits $commitidx($n)
4328 catch {unset colormap}
4329 catch {unset rowtextx}
4331 set canvxmax [$canv cget -width]
4337 if {$selid ne {} && [commitinview $selid $n]} {
4338 set row [rowofcommit $selid]
4339 # try to get the selected row in the same position on the screen
4340 set ymax [lindex [$canv cget -scrollregion] 3]
4341 set ytop [expr {[yc $row] - $yscreen}]
4345 set yf [expr {$ytop * 1.0 / $ymax}]
4347 allcanvs yview moveto $yf
4351 } elseif {!$viewcomplete($n)} {
4352 reset_pending_select $selid
4354 reset_pending_select {}
4356 if {[commitinview $pending_select $curview]} {
4357 selectline [rowofcommit $pending_select] 1
4359 set row [first_real_row]
4360 if {$row < $numcommits} {
4365 if {!$viewcomplete($n)} {
4366 if {$numcommits == 0} {
4367 show_status [mc "Reading commits..."]
4369 } elseif {$numcommits == 0} {
4370 show_status [mc "No commits selected"]
4374 # Stuff relating to the highlighting facility
4376 proc ishighlighted {id} {
4377 global vhighlights fhighlights nhighlights rhighlights
4379 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4380 return $nhighlights($id)
4382 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4383 return $vhighlights($id)
4385 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4386 return $fhighlights($id)
4388 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4389 return $rhighlights($id)
4394 proc bolden {id font} {
4395 global canv linehtag currentid boldids need_redisplay markedid
4397 # need_redisplay = 1 means the display is stale and about to be redrawn
4398 if {$need_redisplay} return
4400 $canv itemconf $linehtag($id) -font $font
4401 if {[info exists currentid] && $id eq $currentid} {
4403 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4404 -outline {{}} -tags secsel \
4405 -fill [$canv cget -selectbackground]]
4408 if {[info exists markedid] && $id eq $markedid} {
4413 proc bolden_name {id font} {
4414 global canv2 linentag currentid boldnameids need_redisplay
4416 if {$need_redisplay} return
4417 lappend boldnameids $id
4418 $canv2 itemconf $linentag($id) -font $font
4419 if {[info exists currentid] && $id eq $currentid} {
4420 $canv2 delete secsel
4421 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4422 -outline {{}} -tags secsel \
4423 -fill [$canv2 cget -selectbackground]]
4432 foreach id $boldids {
4433 if {![ishighlighted $id]} {
4436 lappend stillbold $id
4439 set boldids $stillbold
4442 proc addvhighlight {n} {
4443 global hlview viewcomplete curview vhl_done commitidx
4445 if {[info exists hlview]} {
4449 if {$n != $curview && ![info exists viewcomplete($n)]} {
4452 set vhl_done $commitidx($hlview)
4453 if {$vhl_done > 0} {
4458 proc delvhighlight {} {
4459 global hlview vhighlights
4461 if {![info exists hlview]} return
4463 catch {unset vhighlights}
4467 proc vhighlightmore {} {
4468 global hlview vhl_done commitidx vhighlights curview
4470 set max $commitidx($hlview)
4471 set vr [visiblerows]
4472 set r0 [lindex $vr 0]
4473 set r1 [lindex $vr 1]
4474 for {set i $vhl_done} {$i < $max} {incr i} {
4475 set id [commitonrow $i $hlview]
4476 if {[commitinview $id $curview]} {
4477 set row [rowofcommit $id]
4478 if {$r0 <= $row && $row <= $r1} {
4479 if {![highlighted $row]} {
4480 bolden $id mainfontbold
4482 set vhighlights($id) 1
4490 proc askvhighlight {row id} {
4491 global hlview vhighlights iddrawn
4493 if {[commitinview $id $hlview]} {
4494 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4495 bolden $id mainfontbold
4497 set vhighlights($id) 1
4499 set vhighlights($id) 0
4503 proc hfiles_change {} {
4504 global highlight_files filehighlight fhighlights fh_serial
4505 global highlight_paths
4507 if {[info exists filehighlight]} {
4508 # delete previous highlights
4509 catch {close $filehighlight}
4511 catch {unset fhighlights}
4513 unhighlight_filelist
4515 set highlight_paths {}
4516 after cancel do_file_hl $fh_serial
4518 if {$highlight_files ne {}} {
4519 after 300 do_file_hl $fh_serial
4523 proc gdttype_change {name ix op} {
4524 global gdttype highlight_files findstring findpattern
4527 if {$findstring ne {}} {
4528 if {$gdttype eq [mc "containing:"]} {
4529 if {$highlight_files ne {}} {
4530 set highlight_files {}
4535 if {$findpattern ne {}} {
4539 set highlight_files $findstring
4544 # enable/disable findtype/findloc menus too
4547 proc find_change {name ix op} {
4548 global gdttype findstring highlight_files
4551 if {$gdttype eq [mc "containing:"]} {
4554 if {$highlight_files ne $findstring} {
4555 set highlight_files $findstring
4562 proc findcom_change args {
4563 global nhighlights boldnameids
4564 global findpattern findtype findstring gdttype
4567 # delete previous highlights, if any
4568 foreach id $boldnameids {
4569 bolden_name $id mainfont
4572 catch {unset nhighlights}
4575 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4577 } elseif {$findtype eq [mc "Regexp"]} {
4578 set findpattern $findstring
4580 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4582 set findpattern "*$e*"
4586 proc makepatterns {l} {
4589 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4590 if {[string index $ee end] eq "/"} {
4600 proc do_file_hl {serial} {
4601 global highlight_files filehighlight highlight_paths gdttype fhl_list
4602 global cdup findtype
4604 if {$gdttype eq [mc "touching paths:"]} {
4605 # If "exact" match then convert backslashes to forward slashes.
4606 # Most useful to support Windows-flavoured file paths.
4607 if {$findtype eq [mc "Exact"]} {
4608 set highlight_files [string map {"\\" "/"} $highlight_files]
4610 if {[catch {set paths [shellsplit $highlight_files]}]} return
4611 set highlight_paths [makepatterns $paths]
4613 set relative_paths {}
4614 foreach path $paths {
4615 lappend relative_paths [file join $cdup $path]
4617 set gdtargs [concat -- $relative_paths]
4618 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4619 set gdtargs [list "-S$highlight_files"]
4621 # must be "containing:", i.e. we're searching commit info
4624 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4625 set filehighlight [open $cmd r+]
4626 fconfigure $filehighlight -blocking 0
4627 filerun $filehighlight readfhighlight
4633 proc flushhighlights {} {
4634 global filehighlight fhl_list
4636 if {[info exists filehighlight]} {
4638 puts $filehighlight ""
4639 flush $filehighlight
4643 proc askfilehighlight {row id} {
4644 global filehighlight fhighlights fhl_list
4646 lappend fhl_list $id
4647 set fhighlights($id) -1
4648 puts $filehighlight $id
4651 proc readfhighlight {} {
4652 global filehighlight fhighlights curview iddrawn
4653 global fhl_list find_dirn
4655 if {![info exists filehighlight]} {
4659 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4660 set line [string trim $line]
4661 set i [lsearch -exact $fhl_list $line]
4662 if {$i < 0} continue
4663 for {set j 0} {$j < $i} {incr j} {
4664 set id [lindex $fhl_list $j]
4665 set fhighlights($id) 0
4667 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4668 if {$line eq {}} continue
4669 if {![commitinview $line $curview]} continue
4670 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4671 bolden $line mainfontbold
4673 set fhighlights($line) 1
4675 if {[eof $filehighlight]} {
4677 puts "oops, git diff-tree died"
4678 catch {close $filehighlight}
4682 if {[info exists find_dirn]} {
4688 proc doesmatch {f} {
4689 global findtype findpattern
4691 if {$findtype eq [mc "Regexp"]} {
4692 return [regexp $findpattern $f]
4693 } elseif {$findtype eq [mc "IgnCase"]} {
4694 return [string match -nocase $findpattern $f]
4696 return [string match $findpattern $f]
4700 proc askfindhighlight {row id} {
4701 global nhighlights commitinfo iddrawn
4703 global markingmatches
4705 if {![info exists commitinfo($id)]} {
4708 set info $commitinfo($id)
4710 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4711 foreach f $info ty $fldtypes {
4712 if {$ty eq ""} continue
4713 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4715 if {$ty eq [mc "Author"]} {
4722 if {$isbold && [info exists iddrawn($id)]} {
4723 if {![ishighlighted $id]} {
4724 bolden $id mainfontbold
4726 bolden_name $id mainfontbold
4729 if {$markingmatches} {
4730 markrowmatches $row $id
4733 set nhighlights($id) $isbold
4736 proc markrowmatches {row id} {
4737 global canv canv2 linehtag linentag commitinfo findloc
4739 set headline [lindex $commitinfo($id) 0]
4740 set author [lindex $commitinfo($id) 1]
4741 $canv delete match$row
4742 $canv2 delete match$row
4743 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4744 set m [findmatches $headline]
4746 markmatches $canv $row $headline $linehtag($id) $m \
4747 [$canv itemcget $linehtag($id) -font] $row
4750 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4751 set m [findmatches $author]
4753 markmatches $canv2 $row $author $linentag($id) $m \
4754 [$canv2 itemcget $linentag($id) -font] $row
4759 proc vrel_change {name ix op} {
4760 global highlight_related
4763 if {$highlight_related ne [mc "None"]} {
4768 # prepare for testing whether commits are descendents or ancestors of a
4769 proc rhighlight_sel {a} {
4770 global descendent desc_todo ancestor anc_todo
4771 global highlight_related
4773 catch {unset descendent}
4774 set desc_todo [list $a]
4775 catch {unset ancestor}
4776 set anc_todo [list $a]
4777 if {$highlight_related ne [mc "None"]} {
4783 proc rhighlight_none {} {
4786 catch {unset rhighlights}
4790 proc is_descendent {a} {
4791 global curview children descendent desc_todo
4794 set la [rowofcommit $a]
4798 for {set i 0} {$i < [llength $todo]} {incr i} {
4799 set do [lindex $todo $i]
4800 if {[rowofcommit $do] < $la} {
4801 lappend leftover $do
4804 foreach nk $children($v,$do) {
4805 if {![info exists descendent($nk)]} {
4806 set descendent($nk) 1
4814 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4818 set descendent($a) 0
4819 set desc_todo $leftover
4822 proc is_ancestor {a} {
4823 global curview parents ancestor anc_todo
4826 set la [rowofcommit $a]
4830 for {set i 0} {$i < [llength $todo]} {incr i} {
4831 set do [lindex $todo $i]
4832 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4833 lappend leftover $do
4836 foreach np $parents($v,$do) {
4837 if {![info exists ancestor($np)]} {
4846 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4851 set anc_todo $leftover
4854 proc askrelhighlight {row id} {
4855 global descendent highlight_related iddrawn rhighlights
4856 global selectedline ancestor
4858 if {$selectedline eq {}} return
4860 if {$highlight_related eq [mc "Descendant"] ||
4861 $highlight_related eq [mc "Not descendant"]} {
4862 if {![info exists descendent($id)]} {
4865 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4868 } elseif {$highlight_related eq [mc "Ancestor"] ||
4869 $highlight_related eq [mc "Not ancestor"]} {
4870 if {![info exists ancestor($id)]} {
4873 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4877 if {[info exists iddrawn($id)]} {
4878 if {$isbold && ![ishighlighted $id]} {
4879 bolden $id mainfontbold
4882 set rhighlights($id) $isbold
4885 # Graph layout functions
4887 proc shortids {ids} {
4890 if {[llength $id] > 1} {
4891 lappend res [shortids $id]
4892 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4893 lappend res [string range $id 0 7]
4904 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4905 if {($n & $mask) != 0} {
4906 set ret [concat $ret $o]
4908 set o [concat $o $o]
4913 proc ordertoken {id} {
4914 global ordertok curview varcid varcstart varctok curview parents children
4915 global nullid nullid2
4917 if {[info exists ordertok($id)]} {
4918 return $ordertok($id)
4923 if {[info exists varcid($curview,$id)]} {
4924 set a $varcid($curview,$id)
4925 set p [lindex $varcstart($curview) $a]
4927 set p [lindex $children($curview,$id) 0]
4929 if {[info exists ordertok($p)]} {
4930 set tok $ordertok($p)
4933 set id [first_real_child $curview,$p]
4936 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4939 if {[llength $parents($curview,$id)] == 1} {
4940 lappend todo [list $p {}]
4942 set j [lsearch -exact $parents($curview,$id) $p]
4944 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4946 lappend todo [list $p [strrep $j]]
4949 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4950 set p [lindex $todo $i 0]
4951 append tok [lindex $todo $i 1]
4952 set ordertok($p) $tok
4954 set ordertok($origid) $tok
4958 # Work out where id should go in idlist so that order-token
4959 # values increase from left to right
4960 proc idcol {idlist id {i 0}} {
4961 set t [ordertoken $id]
4965 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4966 if {$i > [llength $idlist]} {
4967 set i [llength $idlist]
4969 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4972 if {$t > [ordertoken [lindex $idlist $i]]} {
4973 while {[incr i] < [llength $idlist] &&
4974 $t >= [ordertoken [lindex $idlist $i]]} {}
4980 proc initlayout {} {
4981 global rowidlist rowisopt rowfinal displayorder parentlist
4982 global numcommits canvxmax canv
4984 global colormap rowtextx
4993 set canvxmax [$canv cget -width]
4994 catch {unset colormap}
4995 catch {unset rowtextx}
4999 proc setcanvscroll {} {
5000 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5001 global lastscrollset lastscrollrows
5003 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5004 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5005 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5006 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5007 set lastscrollset [clock clicks -milliseconds]
5008 set lastscrollrows $numcommits
5011 proc visiblerows {} {
5012 global canv numcommits linespc
5014 set ymax [lindex [$canv cget -scrollregion] 3]
5015 if {$ymax eq {} || $ymax == 0} return
5017 set y0 [expr {int([lindex $f 0] * $ymax)}]
5018 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5022 set y1 [expr {int([lindex $f 1] * $ymax)}]
5023 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5024 if {$r1 >= $numcommits} {
5025 set r1 [expr {$numcommits - 1}]
5027 return [list $r0 $r1]
5030 proc layoutmore {} {
5031 global commitidx viewcomplete curview
5032 global numcommits pending_select curview
5033 global lastscrollset lastscrollrows
5035 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5036 [clock clicks -milliseconds] - $lastscrollset > 500} {
5039 if {[info exists pending_select] &&
5040 [commitinview $pending_select $curview]} {
5042 selectline [rowofcommit $pending_select] 1
5047 # With path limiting, we mightn't get the actual HEAD commit,
5048 # so ask git rev-list what is the first ancestor of HEAD that
5049 # touches a file in the path limit.
5050 proc get_viewmainhead {view} {
5051 global viewmainheadid vfilelimit viewinstances mainheadid
5054 set rfd [open [concat | git rev-list -1 $mainheadid \
5055 -- $vfilelimit($view)] r]
5056 set j [reg_instance $rfd]
5057 lappend viewinstances($view) $j
5058 fconfigure $rfd -blocking 0
5059 filerun $rfd [list getviewhead $rfd $j $view]
5060 set viewmainheadid($curview) {}
5064 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5065 proc getviewhead {fd inst view} {
5066 global viewmainheadid commfd curview viewinstances showlocalchanges
5069 if {[gets $fd line] < 0} {
5073 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5076 set viewmainheadid($view) $id
5079 set i [lsearch -exact $viewinstances($view) $inst]
5081 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5083 if {$showlocalchanges && $id ne {} && $view == $curview} {
5089 proc doshowlocalchanges {} {
5090 global curview viewmainheadid
5092 if {$viewmainheadid($curview) eq {}} return
5093 if {[commitinview $viewmainheadid($curview) $curview]} {
5096 interestedin $viewmainheadid($curview) dodiffindex
5100 proc dohidelocalchanges {} {
5101 global nullid nullid2 lserial curview
5103 if {[commitinview $nullid $curview]} {
5104 removefakerow $nullid
5106 if {[commitinview $nullid2 $curview]} {
5107 removefakerow $nullid2
5112 # spawn off a process to do git diff-index --cached HEAD
5113 proc dodiffindex {} {
5114 global lserial showlocalchanges vfilelimit curview
5117 if {!$showlocalchanges || !$hasworktree} return
5119 set cmd "|git diff-index --cached HEAD"
5120 if {$vfilelimit($curview) ne {}} {
5121 set cmd [concat $cmd -- $vfilelimit($curview)]
5123 set fd [open $cmd r]
5124 fconfigure $fd -blocking 0
5125 set i [reg_instance $fd]
5126 filerun $fd [list readdiffindex $fd $lserial $i]
5129 proc readdiffindex {fd serial inst} {
5130 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5134 if {[gets $fd line] < 0} {
5140 # we only need to see one line and we don't really care what it says...
5143 if {$serial != $lserial} {
5147 # now see if there are any local changes not checked in to the index
5148 set cmd "|git diff-files"
5149 if {$vfilelimit($curview) ne {}} {
5150 set cmd [concat $cmd -- $vfilelimit($curview)]
5152 set fd [open $cmd r]
5153 fconfigure $fd -blocking 0
5154 set i [reg_instance $fd]
5155 filerun $fd [list readdifffiles $fd $serial $i]
5157 if {$isdiff && ![commitinview $nullid2 $curview]} {
5158 # add the line for the changes in the index to the graph
5159 set hl [mc "Local changes checked in to index but not committed"]
5160 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5161 set commitdata($nullid2) "\n $hl\n"
5162 if {[commitinview $nullid $curview]} {
5163 removefakerow $nullid
5165 insertfakerow $nullid2 $viewmainheadid($curview)
5166 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5167 if {[commitinview $nullid $curview]} {
5168 removefakerow $nullid
5170 removefakerow $nullid2
5175 proc readdifffiles {fd serial inst} {
5176 global viewmainheadid nullid nullid2 curview
5177 global commitinfo commitdata lserial
5180 if {[gets $fd line] < 0} {
5186 # we only need to see one line and we don't really care what it says...
5189 if {$serial != $lserial} {
5193 if {$isdiff && ![commitinview $nullid $curview]} {
5194 # add the line for the local diff to the graph
5195 set hl [mc "Local uncommitted changes, not checked in to index"]
5196 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5197 set commitdata($nullid) "\n $hl\n"
5198 if {[commitinview $nullid2 $curview]} {
5201 set p $viewmainheadid($curview)
5203 insertfakerow $nullid $p
5204 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5205 removefakerow $nullid
5210 proc nextuse {id row} {
5211 global curview children
5213 if {[info exists children($curview,$id)]} {
5214 foreach kid $children($curview,$id) {
5215 if {![commitinview $kid $curview]} {
5218 if {[rowofcommit $kid] > $row} {
5219 return [rowofcommit $kid]
5223 if {[commitinview $id $curview]} {
5224 return [rowofcommit $id]
5229 proc prevuse {id row} {
5230 global curview children
5233 if {[info exists children($curview,$id)]} {
5234 foreach kid $children($curview,$id) {
5235 if {![commitinview $kid $curview]} break
5236 if {[rowofcommit $kid] < $row} {
5237 set ret [rowofcommit $kid]
5244 proc make_idlist {row} {
5245 global displayorder parentlist uparrowlen downarrowlen mingaplen
5246 global commitidx curview children
5248 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5252 set ra [expr {$row - $downarrowlen}]
5256 set rb [expr {$row + $uparrowlen}]
5257 if {$rb > $commitidx($curview)} {
5258 set rb $commitidx($curview)
5260 make_disporder $r [expr {$rb + 1}]
5262 for {} {$r < $ra} {incr r} {
5263 set nextid [lindex $displayorder [expr {$r + 1}]]
5264 foreach p [lindex $parentlist $r] {
5265 if {$p eq $nextid} continue
5266 set rn [nextuse $p $r]
5268 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5269 lappend ids [list [ordertoken $p] $p]
5273 for {} {$r < $row} {incr r} {
5274 set nextid [lindex $displayorder [expr {$r + 1}]]
5275 foreach p [lindex $parentlist $r] {
5276 if {$p eq $nextid} continue
5277 set rn [nextuse $p $r]
5278 if {$rn < 0 || $rn >= $row} {
5279 lappend ids [list [ordertoken $p] $p]
5283 set id [lindex $displayorder $row]
5284 lappend ids [list [ordertoken $id] $id]
5286 foreach p [lindex $parentlist $r] {
5287 set firstkid [lindex $children($curview,$p) 0]
5288 if {[rowofcommit $firstkid] < $row} {
5289 lappend ids [list [ordertoken $p] $p]
5293 set id [lindex $displayorder $r]
5295 set firstkid [lindex $children($curview,$id) 0]
5296 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5297 lappend ids [list [ordertoken $id] $id]
5302 foreach idx [lsort -unique $ids] {
5303 lappend idlist [lindex $idx 1]
5308 proc rowsequal {a b} {
5309 while {[set i [lsearch -exact $a {}]] >= 0} {
5310 set a [lreplace $a $i $i]
5312 while {[set i [lsearch -exact $b {}]] >= 0} {
5313 set b [lreplace $b $i $i]
5315 return [expr {$a eq $b}]
5318 proc makeupline {id row rend col} {
5319 global rowidlist uparrowlen downarrowlen mingaplen
5321 for {set r $rend} {1} {set r $rstart} {
5322 set rstart [prevuse $id $r]
5323 if {$rstart < 0} return
5324 if {$rstart < $row} break
5326 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5327 set rstart [expr {$rend - $uparrowlen - 1}]
5329 for {set r $rstart} {[incr r] <= $row} {} {
5330 set idlist [lindex $rowidlist $r]
5331 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5332 set col [idcol $idlist $id $col]
5333 lset rowidlist $r [linsert $idlist $col $id]
5339 proc layoutrows {row endrow} {
5340 global rowidlist rowisopt rowfinal displayorder
5341 global uparrowlen downarrowlen maxwidth mingaplen
5342 global children parentlist
5343 global commitidx viewcomplete curview
5345 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5348 set rm1 [expr {$row - 1}]
5349 foreach id [lindex $rowidlist $rm1] {
5354 set final [lindex $rowfinal $rm1]
5356 for {} {$row < $endrow} {incr row} {
5357 set rm1 [expr {$row - 1}]
5358 if {$rm1 < 0 || $idlist eq {}} {
5359 set idlist [make_idlist $row]
5362 set id [lindex $displayorder $rm1]
5363 set col [lsearch -exact $idlist $id]
5364 set idlist [lreplace $idlist $col $col]
5365 foreach p [lindex $parentlist $rm1] {
5366 if {[lsearch -exact $idlist $p] < 0} {
5367 set col [idcol $idlist $p $col]
5368 set idlist [linsert $idlist $col $p]
5369 # if not the first child, we have to insert a line going up
5370 if {$id ne [lindex $children($curview,$p) 0]} {
5371 makeupline $p $rm1 $row $col
5375 set id [lindex $displayorder $row]
5376 if {$row > $downarrowlen} {
5377 set termrow [expr {$row - $downarrowlen - 1}]
5378 foreach p [lindex $parentlist $termrow] {
5379 set i [lsearch -exact $idlist $p]
5380 if {$i < 0} continue
5381 set nr [nextuse $p $termrow]
5382 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5383 set idlist [lreplace $idlist $i $i]
5387 set col [lsearch -exact $idlist $id]
5389 set col [idcol $idlist $id]
5390 set idlist [linsert $idlist $col $id]
5391 if {$children($curview,$id) ne {}} {
5392 makeupline $id $rm1 $row $col
5395 set r [expr {$row + $uparrowlen - 1}]
5396 if {$r < $commitidx($curview)} {
5398 foreach p [lindex $parentlist $r] {
5399 if {[lsearch -exact $idlist $p] >= 0} continue
5400 set fk [lindex $children($curview,$p) 0]
5401 if {[rowofcommit $fk] < $row} {
5402 set x [idcol $idlist $p $x]
5403 set idlist [linsert $idlist $x $p]
5406 if {[incr r] < $commitidx($curview)} {
5407 set p [lindex $displayorder $r]
5408 if {[lsearch -exact $idlist $p] < 0} {
5409 set fk [lindex $children($curview,$p) 0]
5410 if {$fk ne {} && [rowofcommit $fk] < $row} {
5411 set x [idcol $idlist $p $x]
5412 set idlist [linsert $idlist $x $p]
5418 if {$final && !$viewcomplete($curview) &&
5419 $row + $uparrowlen + $mingaplen + $downarrowlen
5420 >= $commitidx($curview)} {
5423 set l [llength $rowidlist]
5425 lappend rowidlist $idlist
5427 lappend rowfinal $final
5428 } elseif {$row < $l} {
5429 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5430 lset rowidlist $row $idlist
5433 lset rowfinal $row $final
5435 set pad [ntimes [expr {$row - $l}] {}]
5436 set rowidlist [concat $rowidlist $pad]
5437 lappend rowidlist $idlist
5438 set rowfinal [concat $rowfinal $pad]
5439 lappend rowfinal $final
5440 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5446 proc changedrow {row} {
5447 global displayorder iddrawn rowisopt need_redisplay
5449 set l [llength $rowisopt]
5451 lset rowisopt $row 0
5452 if {$row + 1 < $l} {
5453 lset rowisopt [expr {$row + 1}] 0
5454 if {$row + 2 < $l} {
5455 lset rowisopt [expr {$row + 2}] 0
5459 set id [lindex $displayorder $row]
5460 if {[info exists iddrawn($id)]} {
5461 set need_redisplay 1
5465 proc insert_pad {row col npad} {
5468 set pad [ntimes $npad {}]
5469 set idlist [lindex $rowidlist $row]
5470 set bef [lrange $idlist 0 [expr {$col - 1}]]
5471 set aft [lrange $idlist $col end]
5472 set i [lsearch -exact $aft {}]
5474 set aft [lreplace $aft $i $i]
5476 lset rowidlist $row [concat $bef $pad $aft]
5480 proc optimize_rows {row col endrow} {
5481 global rowidlist rowisopt displayorder curview children
5486 for {} {$row < $endrow} {incr row; set col 0} {
5487 if {[lindex $rowisopt $row]} continue
5489 set y0 [expr {$row - 1}]
5490 set ym [expr {$row - 2}]
5491 set idlist [lindex $rowidlist $row]
5492 set previdlist [lindex $rowidlist $y0]
5493 if {$idlist eq {} || $previdlist eq {}} continue
5495 set pprevidlist [lindex $rowidlist $ym]
5496 if {$pprevidlist eq {}} continue
5502 for {} {$col < [llength $idlist]} {incr col} {
5503 set id [lindex $idlist $col]
5504 if {[lindex $previdlist $col] eq $id} continue
5509 set x0 [lsearch -exact $previdlist $id]
5510 if {$x0 < 0} continue
5511 set z [expr {$x0 - $col}]
5515 set xm [lsearch -exact $pprevidlist $id]
5517 set z0 [expr {$xm - $x0}]
5521 # if row y0 is the first child of $id then it's not an arrow
5522 if {[lindex $children($curview,$id) 0] ne
5523 [lindex $displayorder $y0]} {
5527 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5528 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5531 # Looking at lines from this row to the previous row,
5532 # make them go straight up if they end in an arrow on
5533 # the previous row; otherwise make them go straight up
5535 if {$z < -1 || ($z < 0 && $isarrow)} {
5536 # Line currently goes left too much;
5537 # insert pads in the previous row, then optimize it
5538 set npad [expr {-1 - $z + $isarrow}]
5539 insert_pad $y0 $x0 $npad
5541 optimize_rows $y0 $x0 $row
5543 set previdlist [lindex $rowidlist $y0]
5544 set x0 [lsearch -exact $previdlist $id]
5545 set z [expr {$x0 - $col}]
5547 set pprevidlist [lindex $rowidlist $ym]
5548 set xm [lsearch -exact $pprevidlist $id]
5549 set z0 [expr {$xm - $x0}]
5551 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5552 # Line currently goes right too much;
5553 # insert pads in this line
5554 set npad [expr {$z - 1 + $isarrow}]
5555 insert_pad $row $col $npad
5556 set idlist [lindex $rowidlist $row]
5558 set z [expr {$x0 - $col}]
5561 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5562 # this line links to its first child on row $row-2
5563 set id [lindex $displayorder $ym]
5564 set xc [lsearch -exact $pprevidlist $id]
5566 set z0 [expr {$xc - $x0}]
5569 # avoid lines jigging left then immediately right
5570 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5571 insert_pad $y0 $x0 1
5573 optimize_rows $y0 $x0 $row
5574 set previdlist [lindex $rowidlist $y0]
5578 # Find the first column that doesn't have a line going right
5579 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5580 set id [lindex $idlist $col]
5581 if {$id eq {}} break
5582 set x0 [lsearch -exact $previdlist $id]
5584 # check if this is the link to the first child
5585 set kid [lindex $displayorder $y0]
5586 if {[lindex $children($curview,$id) 0] eq $kid} {
5587 # it is, work out offset to child
5588 set x0 [lsearch -exact $previdlist $kid]
5591 if {$x0 <= $col} break
5593 # Insert a pad at that column as long as it has a line and
5594 # isn't the last column
5595 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5596 set idlist [linsert $idlist $col {}]
5597 lset rowidlist $row $idlist
5605 global canvx0 linespc
5606 return [expr {$canvx0 + $col * $linespc}]
5610 global canvy0 linespc
5611 return [expr {$canvy0 + $row * $linespc}]
5614 proc linewidth {id} {
5615 global thickerline lthickness
5618 if {[info exists thickerline] && $id eq $thickerline} {
5619 set wid [expr {2 * $lthickness}]
5624 proc rowranges {id} {
5625 global curview children uparrowlen downarrowlen
5628 set kids $children($curview,$id)
5634 foreach child $kids {
5635 if {![commitinview $child $curview]} break
5636 set row [rowofcommit $child]
5637 if {![info exists prev]} {
5638 lappend ret [expr {$row + 1}]
5640 if {$row <= $prevrow} {
5641 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5643 # see if the line extends the whole way from prevrow to row
5644 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5645 [lsearch -exact [lindex $rowidlist \
5646 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5647 # it doesn't, see where it ends
5648 set r [expr {$prevrow + $downarrowlen}]
5649 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5650 while {[incr r -1] > $prevrow &&
5651 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5653 while {[incr r] <= $row &&
5654 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5658 # see where it starts up again
5659 set r [expr {$row - $uparrowlen}]
5660 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5661 while {[incr r] < $row &&
5662 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5664 while {[incr r -1] >= $prevrow &&
5665 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5671 if {$child eq $id} {
5680 proc drawlineseg {id row endrow arrowlow} {
5681 global rowidlist displayorder iddrawn linesegs
5682 global canv colormap linespc curview maxlinelen parentlist
5684 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5685 set le [expr {$row + 1}]
5688 set c [lsearch -exact [lindex $rowidlist $le] $id]
5694 set x [lindex $displayorder $le]
5699 if {[info exists iddrawn($x)] || $le == $endrow} {
5700 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5716 if {[info exists linesegs($id)]} {
5717 set lines $linesegs($id)
5719 set r0 [lindex $li 0]
5721 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5731 set li [lindex $lines [expr {$i-1}]]
5732 set r1 [lindex $li 1]
5733 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5738 set x [lindex $cols [expr {$le - $row}]]
5739 set xp [lindex $cols [expr {$le - 1 - $row}]]
5740 set dir [expr {$xp - $x}]
5742 set ith [lindex $lines $i 2]
5743 set coords [$canv coords $ith]
5744 set ah [$canv itemcget $ith -arrow]
5745 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5746 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5747 if {$x2 ne {} && $x - $x2 == $dir} {
5748 set coords [lrange $coords 0 end-2]
5751 set coords [list [xc $le $x] [yc $le]]
5754 set itl [lindex $lines [expr {$i-1}] 2]
5755 set al [$canv itemcget $itl -arrow]
5756 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5757 } elseif {$arrowlow} {
5758 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5759 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5763 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5764 for {set y $le} {[incr y -1] > $row} {} {
5766 set xp [lindex $cols [expr {$y - 1 - $row}]]
5767 set ndir [expr {$xp - $x}]
5768 if {$dir != $ndir || $xp < 0} {
5769 lappend coords [xc $y $x] [yc $y]
5775 # join parent line to first child
5776 set ch [lindex $displayorder $row]
5777 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5779 puts "oops: drawlineseg: child $ch not on row $row"
5780 } elseif {$xc != $x} {
5781 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5782 set d [expr {int(0.5 * $linespc)}]
5785 set x2 [expr {$x1 - $d}]
5787 set x2 [expr {$x1 + $d}]
5790 set y1 [expr {$y2 + $d}]
5791 lappend coords $x1 $y1 $x2 $y2
5792 } elseif {$xc < $x - 1} {
5793 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5794 } elseif {$xc > $x + 1} {
5795 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5799 lappend coords [xc $row $x] [yc $row]
5801 set xn [xc $row $xp]
5803 lappend coords $xn $yn
5807 set t [$canv create line $coords -width [linewidth $id] \
5808 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5811 set lines [linsert $lines $i [list $row $le $t]]
5813 $canv coords $ith $coords
5814 if {$arrow ne $ah} {
5815 $canv itemconf $ith -arrow $arrow
5817 lset lines $i 0 $row
5820 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5821 set ndir [expr {$xo - $xp}]
5822 set clow [$canv coords $itl]
5823 if {$dir == $ndir} {
5824 set clow [lrange $clow 2 end]
5826 set coords [concat $coords $clow]
5828 lset lines [expr {$i-1}] 1 $le
5830 # coalesce two pieces
5832 set b [lindex $lines [expr {$i-1}] 0]
5833 set e [lindex $lines $i 1]
5834 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5836 $canv coords $itl $coords
5837 if {$arrow ne $al} {
5838 $canv itemconf $itl -arrow $arrow
5842 set linesegs($id) $lines
5846 proc drawparentlinks {id row} {
5847 global rowidlist canv colormap curview parentlist
5848 global idpos linespc
5850 set rowids [lindex $rowidlist $row]
5851 set col [lsearch -exact $rowids $id]
5852 if {$col < 0} return
5853 set olds [lindex $parentlist $row]
5854 set row2 [expr {$row + 1}]
5855 set x [xc $row $col]
5858 set d [expr {int(0.5 * $linespc)}]
5859 set ymid [expr {$y + $d}]
5860 set ids [lindex $rowidlist $row2]
5861 # rmx = right-most X coord used
5864 set i [lsearch -exact $ids $p]
5866 puts "oops, parent $p of $id not in list"
5869 set x2 [xc $row2 $i]
5873 set j [lsearch -exact $rowids $p]
5875 # drawlineseg will do this one for us
5879 # should handle duplicated parents here...
5880 set coords [list $x $y]
5882 # if attaching to a vertical segment, draw a smaller
5883 # slant for visual distinctness
5886 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5888 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5890 } elseif {$i < $col && $i < $j} {
5891 # segment slants towards us already
5892 lappend coords [xc $row $j] $y
5894 if {$i < $col - 1} {
5895 lappend coords [expr {$x2 + $linespc}] $y
5896 } elseif {$i > $col + 1} {
5897 lappend coords [expr {$x2 - $linespc}] $y
5899 lappend coords $x2 $y2
5902 lappend coords $x2 $y2
5904 set t [$canv create line $coords -width [linewidth $p] \
5905 -fill $colormap($p) -tags lines.$p]
5909 if {$rmx > [lindex $idpos($id) 1]} {
5910 lset idpos($id) 1 $rmx
5915 proc drawlines {id} {
5918 $canv itemconf lines.$id -width [linewidth $id]
5921 proc drawcmittext {id row col} {
5922 global linespc canv canv2 canv3 fgcolor curview
5923 global cmitlisted commitinfo rowidlist parentlist
5924 global rowtextx idpos idtags idheads idotherrefs
5925 global linehtag linentag linedtag selectedline
5926 global canvxmax boldids boldnameids fgcolor markedid
5927 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5929 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5930 set listed $cmitlisted($curview,$id)
5931 if {$id eq $nullid} {
5933 } elseif {$id eq $nullid2} {
5935 } elseif {$id eq $mainheadid} {
5938 set ofill [lindex $circlecolors $listed]
5940 set x [xc $row $col]
5942 set orad [expr {$linespc / 3}]
5944 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5945 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5946 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5947 } elseif {$listed == 3} {
5948 # triangle pointing left for left-side commits
5949 set t [$canv create polygon \
5950 [expr {$x - $orad}] $y \
5951 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5952 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5953 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5955 # triangle pointing right for right-side commits
5956 set t [$canv create polygon \
5957 [expr {$x + $orad - 1}] $y \
5958 [expr {$x - $orad}] [expr {$y - $orad}] \
5959 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5960 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5962 set circleitem($row) $t
5964 $canv bind $t <1> {selcanvline {} %x %y}
5965 set rmx [llength [lindex $rowidlist $row]]
5966 set olds [lindex $parentlist $row]
5968 set nextids [lindex $rowidlist [expr {$row + 1}]]
5970 set i [lsearch -exact $nextids $p]
5976 set xt [xc $row $rmx]
5977 set rowtextx($row) $xt
5978 set idpos($id) [list $x $xt $y]
5979 if {[info exists idtags($id)] || [info exists idheads($id)]
5980 || [info exists idotherrefs($id)]} {
5981 set xt [drawtags $id $x $xt $y]
5983 if {[lindex $commitinfo($id) 6] > 0} {
5984 set xt [drawnotesign $xt $y]
5986 set headline [lindex $commitinfo($id) 0]
5987 set name [lindex $commitinfo($id) 1]
5988 set date [lindex $commitinfo($id) 2]
5989 set date [formatdate $date]
5992 set isbold [ishighlighted $id]
5995 set font mainfontbold
5997 lappend boldnameids $id
5998 set nfont mainfontbold
6001 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6002 -text $headline -font $font -tags text]
6003 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6004 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6005 -text $name -font $nfont -tags text]
6006 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6007 -text $date -font mainfont -tags text]
6008 if {$selectedline == $row} {
6011 if {[info exists markedid] && $markedid eq $id} {
6014 set xr [expr {$xt + [font measure $font $headline]}]
6015 if {$xr > $canvxmax} {
6021 proc drawcmitrow {row} {
6022 global displayorder rowidlist nrows_drawn
6023 global iddrawn markingmatches
6024 global commitinfo numcommits
6025 global filehighlight fhighlights findpattern nhighlights
6026 global hlview vhighlights
6027 global highlight_related rhighlights
6029 if {$row >= $numcommits} return
6031 set id [lindex $displayorder $row]
6032 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6033 askvhighlight $row $id
6035 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6036 askfilehighlight $row $id
6038 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6039 askfindhighlight $row $id
6041 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6042 askrelhighlight $row $id
6044 if {![info exists iddrawn($id)]} {
6045 set col [lsearch -exact [lindex $rowidlist $row] $id]
6047 puts "oops, row $row id $id not in list"
6050 if {![info exists commitinfo($id)]} {
6054 drawcmittext $id $row $col
6058 if {$markingmatches} {
6059 markrowmatches $row $id
6063 proc drawcommits {row {endrow {}}} {
6064 global numcommits iddrawn displayorder curview need_redisplay
6065 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6070 if {$endrow eq {}} {
6073 if {$endrow >= $numcommits} {
6074 set endrow [expr {$numcommits - 1}]
6077 set rl1 [expr {$row - $downarrowlen - 3}]
6081 set ro1 [expr {$row - 3}]
6085 set r2 [expr {$endrow + $uparrowlen + 3}]
6086 if {$r2 > $numcommits} {
6089 for {set r $rl1} {$r < $r2} {incr r} {
6090 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6094 set rl1 [expr {$r + 1}]
6100 optimize_rows $ro1 0 $r2
6101 if {$need_redisplay || $nrows_drawn > 2000} {
6105 # make the lines join to already-drawn rows either side
6106 set r [expr {$row - 1}]
6107 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6110 set er [expr {$endrow + 1}]
6111 if {$er >= $numcommits ||
6112 ![info exists iddrawn([lindex $displayorder $er])]} {
6115 for {} {$r <= $er} {incr r} {
6116 set id [lindex $displayorder $r]
6117 set wasdrawn [info exists iddrawn($id)]
6119 if {$r == $er} break
6120 set nextid [lindex $displayorder [expr {$r + 1}]]
6121 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6122 drawparentlinks $id $r
6124 set rowids [lindex $rowidlist $r]
6125 foreach lid $rowids {
6126 if {$lid eq {}} continue
6127 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6129 # see if this is the first child of any of its parents
6130 foreach p [lindex $parentlist $r] {
6131 if {[lsearch -exact $rowids $p] < 0} {
6132 # make this line extend up to the child
6133 set lineend($p) [drawlineseg $p $r $er 0]
6137 set lineend($lid) [drawlineseg $lid $r $er 1]
6143 proc undolayout {row} {
6144 global uparrowlen mingaplen downarrowlen
6145 global rowidlist rowisopt rowfinal need_redisplay
6147 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6151 if {[llength $rowidlist] > $r} {
6153 set rowidlist [lrange $rowidlist 0 $r]
6154 set rowfinal [lrange $rowfinal 0 $r]
6155 set rowisopt [lrange $rowisopt 0 $r]
6156 set need_redisplay 1
6161 proc drawvisible {} {
6162 global canv linespc curview vrowmod selectedline targetrow targetid
6163 global need_redisplay cscroll numcommits
6165 set fs [$canv yview]
6166 set ymax [lindex [$canv cget -scrollregion] 3]
6167 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6168 set f0 [lindex $fs 0]
6169 set f1 [lindex $fs 1]
6170 set y0 [expr {int($f0 * $ymax)}]
6171 set y1 [expr {int($f1 * $ymax)}]
6173 if {[info exists targetid]} {
6174 if {[commitinview $targetid $curview]} {
6175 set r [rowofcommit $targetid]
6176 if {$r != $targetrow} {
6177 # Fix up the scrollregion and change the scrolling position
6178 # now that our target row has moved.
6179 set diff [expr {($r - $targetrow) * $linespc}]
6182 set ymax [lindex [$canv cget -scrollregion] 3]
6185 set f0 [expr {$y0 / $ymax}]
6186 set f1 [expr {$y1 / $ymax}]
6187 allcanvs yview moveto $f0
6188 $cscroll set $f0 $f1
6189 set need_redisplay 1
6196 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6197 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6198 if {$endrow >= $vrowmod($curview)} {
6199 update_arcrows $curview
6201 if {$selectedline ne {} &&
6202 $row <= $selectedline && $selectedline <= $endrow} {
6203 set targetrow $selectedline
6204 } elseif {[info exists targetid]} {
6205 set targetrow [expr {int(($row + $endrow) / 2)}]
6207 if {[info exists targetrow]} {
6208 if {$targetrow >= $numcommits} {
6209 set targetrow [expr {$numcommits - 1}]
6211 set targetid [commitonrow $targetrow]
6213 drawcommits $row $endrow
6216 proc clear_display {} {
6217 global iddrawn linesegs need_redisplay nrows_drawn
6218 global vhighlights fhighlights nhighlights rhighlights
6219 global linehtag linentag linedtag boldids boldnameids
6222 catch {unset iddrawn}
6223 catch {unset linesegs}
6224 catch {unset linehtag}
6225 catch {unset linentag}
6226 catch {unset linedtag}
6229 catch {unset vhighlights}
6230 catch {unset fhighlights}
6231 catch {unset nhighlights}
6232 catch {unset rhighlights}
6233 set need_redisplay 0
6237 proc findcrossings {id} {
6238 global rowidlist parentlist numcommits displayorder
6242 foreach {s e} [rowranges $id] {
6243 if {$e >= $numcommits} {
6244 set e [expr {$numcommits - 1}]
6246 if {$e <= $s} continue
6247 for {set row $e} {[incr row -1] >= $s} {} {
6248 set x [lsearch -exact [lindex $rowidlist $row] $id]
6250 set olds [lindex $parentlist $row]
6251 set kid [lindex $displayorder $row]
6252 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6253 if {$kidx < 0} continue
6254 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6256 set px [lsearch -exact $nextrow $p]
6257 if {$px < 0} continue
6258 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6259 if {[lsearch -exact $ccross $p] >= 0} continue
6260 if {$x == $px + ($kidx < $px? -1: 1)} {
6262 } elseif {[lsearch -exact $cross $p] < 0} {
6269 return [concat $ccross {{}} $cross]
6272 proc assigncolor {id} {
6273 global colormap colors nextcolor
6274 global parents children children curview
6276 if {[info exists colormap($id)]} return
6277 set ncolors [llength $colors]
6278 if {[info exists children($curview,$id)]} {
6279 set kids $children($curview,$id)
6283 if {[llength $kids] == 1} {
6284 set child [lindex $kids 0]
6285 if {[info exists colormap($child)]
6286 && [llength $parents($curview,$child)] == 1} {
6287 set colormap($id) $colormap($child)
6293 foreach x [findcrossings $id] {
6295 # delimiter between corner crossings and other crossings
6296 if {[llength $badcolors] >= $ncolors - 1} break
6297 set origbad $badcolors
6299 if {[info exists colormap($x)]
6300 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6301 lappend badcolors $colormap($x)
6304 if {[llength $badcolors] >= $ncolors} {
6305 set badcolors $origbad
6307 set origbad $badcolors
6308 if {[llength $badcolors] < $ncolors - 1} {
6309 foreach child $kids {
6310 if {[info exists colormap($child)]
6311 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6312 lappend badcolors $colormap($child)
6314 foreach p $parents($curview,$child) {
6315 if {[info exists colormap($p)]
6316 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6317 lappend badcolors $colormap($p)
6321 if {[llength $badcolors] >= $ncolors} {
6322 set badcolors $origbad
6325 for {set i 0} {$i <= $ncolors} {incr i} {
6326 set c [lindex $colors $nextcolor]
6327 if {[incr nextcolor] >= $ncolors} {
6330 if {[lsearch -exact $badcolors $c]} break
6332 set colormap($id) $c
6335 proc bindline {t id} {
6338 $canv bind $t <Enter> "lineenter %x %y $id"
6339 $canv bind $t <Motion> "linemotion %x %y $id"
6340 $canv bind $t <Leave> "lineleave $id"
6341 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6344 proc drawtags {id x xt y1} {
6345 global idtags idheads idotherrefs mainhead
6346 global linespc lthickness
6347 global canv rowtextx curview fgcolor bgcolor ctxbut
6352 if {[info exists idtags($id)]} {
6353 set marks $idtags($id)
6354 set ntags [llength $marks]
6356 if {[info exists idheads($id)]} {
6357 set marks [concat $marks $idheads($id)]
6358 set nheads [llength $idheads($id)]
6360 if {[info exists idotherrefs($id)]} {
6361 set marks [concat $marks $idotherrefs($id)]
6367 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6368 set yt [expr {$y1 - 0.5 * $linespc}]
6369 set yb [expr {$yt + $linespc - 1}]
6373 foreach tag $marks {
6375 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6376 set wid [font measure mainfontbold $tag]
6378 set wid [font measure mainfont $tag]
6382 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6384 set yl [expr {$y1 - $lthickness}]
6385 set t [$canv create line $x $yl [lindex $xvals end] $yl \
6386 -width $lthickness -fill black -tags tag.$id]
6388 foreach tag $marks x $xvals wid $wvals {
6389 set tag_quoted [string map {% %%} $tag]
6390 set xl [expr {$x + $delta}]
6391 set xr [expr {$x + $delta + $wid + $lthickness}]
6393 if {[incr ntags -1] >= 0} {
6395 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6396 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6397 -width 1 -outline black -fill yellow -tags tag.$id]
6398 $canv bind $t <1> [list showtag $tag_quoted 1]
6399 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6401 # draw a head or other ref
6402 if {[incr nheads -1] >= 0} {
6404 if {$tag eq $mainhead} {
6405 set font mainfontbold
6410 set xl [expr {$xl - $delta/2}]
6411 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6412 -width 1 -outline black -fill $col -tags tag.$id
6413 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6414 set rwid [font measure mainfont $remoteprefix]
6415 set xi [expr {$x + 1}]
6416 set yti [expr {$yt + 1}]
6417 set xri [expr {$x + $rwid}]
6418 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6419 -width 0 -fill "#ffddaa" -tags tag.$id
6422 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
6423 -font $font -tags [list tag.$id text]]
6425 $canv bind $t <1> [list showtag $tag_quoted 1]
6426 } elseif {$nheads >= 0} {
6427 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6433 proc drawnotesign {xt y} {
6434 global linespc canv fgcolor
6436 set orad [expr {$linespc / 3}]
6437 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6438 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6439 -fill yellow -outline $fgcolor -width 1 -tags circle]
6440 set xt [expr {$xt + $orad * 3}]
6444 proc xcoord {i level ln} {
6445 global canvx0 xspc1 xspc2
6447 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6448 if {$i > 0 && $i == $level} {
6449 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6450 } elseif {$i > $level} {
6451 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6456 proc show_status {msg} {
6460 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6461 -tags text -fill $fgcolor
6464 # Don't change the text pane cursor if it is currently the hand cursor,
6465 # showing that we are over a sha1 ID link.
6466 proc settextcursor {c} {
6467 global ctext curtextcursor
6469 if {[$ctext cget -cursor] == $curtextcursor} {
6470 $ctext config -cursor $c
6472 set curtextcursor $c
6475 proc nowbusy {what {name {}}} {
6476 global isbusy busyname statusw
6478 if {[array names isbusy] eq {}} {
6479 . config -cursor watch
6483 set busyname($what) $name
6485 $statusw conf -text $name
6489 proc notbusy {what} {
6490 global isbusy maincursor textcursor busyname statusw
6494 if {$busyname($what) ne {} &&
6495 [$statusw cget -text] eq $busyname($what)} {
6496 $statusw conf -text {}
6499 if {[array names isbusy] eq {}} {
6500 . config -cursor $maincursor
6501 settextcursor $textcursor
6505 proc findmatches {f} {
6506 global findtype findstring
6507 if {$findtype == [mc "Regexp"]} {
6508 set matches [regexp -indices -all -inline $findstring $f]
6511 if {$findtype == [mc "IgnCase"]} {
6512 set f [string tolower $f]
6513 set fs [string tolower $fs]
6517 set l [string length $fs]
6518 while {[set j [string first $fs $f $i]] >= 0} {
6519 lappend matches [list $j [expr {$j+$l-1}]]
6520 set i [expr {$j + $l}]
6526 proc dofind {{dirn 1} {wrap 1}} {
6527 global findstring findstartline findcurline selectedline numcommits
6528 global gdttype filehighlight fh_serial find_dirn findallowwrap
6530 if {[info exists find_dirn]} {
6531 if {$find_dirn == $dirn} return
6535 if {$findstring eq {} || $numcommits == 0} return
6536 if {$selectedline eq {}} {
6537 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6539 set findstartline $selectedline
6541 set findcurline $findstartline
6542 nowbusy finding [mc "Searching"]
6543 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6544 after cancel do_file_hl $fh_serial
6545 do_file_hl $fh_serial
6548 set findallowwrap $wrap
6552 proc stopfinding {} {
6553 global find_dirn findcurline fprogcoord
6555 if {[info exists find_dirn]} {
6566 global commitdata commitinfo numcommits findpattern findloc
6567 global findstartline findcurline findallowwrap
6568 global find_dirn gdttype fhighlights fprogcoord
6569 global curview varcorder vrownum varccommits vrowmod
6571 if {![info exists find_dirn]} {
6574 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6577 if {$find_dirn > 0} {
6579 if {$l >= $numcommits} {
6582 if {$l <= $findstartline} {
6583 set lim [expr {$findstartline + 1}]
6586 set moretodo $findallowwrap
6593 if {$l >= $findstartline} {
6594 set lim [expr {$findstartline - 1}]
6597 set moretodo $findallowwrap
6600 set n [expr {($lim - $l) * $find_dirn}]
6605 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6606 update_arcrows $curview
6610 set ai [bsearch $vrownum($curview) $l]
6611 set a [lindex $varcorder($curview) $ai]
6612 set arow [lindex $vrownum($curview) $ai]
6613 set ids [lindex $varccommits($curview,$a)]
6614 set arowend [expr {$arow + [llength $ids]}]
6615 if {$gdttype eq [mc "containing:"]} {
6616 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6617 if {$l < $arow || $l >= $arowend} {
6619 set a [lindex $varcorder($curview) $ai]
6620 set arow [lindex $vrownum($curview) $ai]
6621 set ids [lindex $varccommits($curview,$a)]
6622 set arowend [expr {$arow + [llength $ids]}]
6624 set id [lindex $ids [expr {$l - $arow}]]
6625 # shouldn't happen unless git log doesn't give all the commits...
6626 if {![info exists commitdata($id)] ||
6627 ![doesmatch $commitdata($id)]} {
6630 if {![info exists commitinfo($id)]} {
6633 set info $commitinfo($id)
6634 foreach f $info ty $fldtypes {
6635 if {$ty eq ""} continue
6636 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6645 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6646 if {$l < $arow || $l >= $arowend} {
6648 set a [lindex $varcorder($curview) $ai]
6649 set arow [lindex $vrownum($curview) $ai]
6650 set ids [lindex $varccommits($curview,$a)]
6651 set arowend [expr {$arow + [llength $ids]}]
6653 set id [lindex $ids [expr {$l - $arow}]]
6654 if {![info exists fhighlights($id)]} {
6655 # this sets fhighlights($id) to -1
6656 askfilehighlight $l $id
6658 if {$fhighlights($id) > 0} {
6662 if {$fhighlights($id) < 0} {
6665 set findcurline [expr {$l - $find_dirn}]
6670 if {$found || ($domore && !$moretodo)} {
6686 set findcurline [expr {$l - $find_dirn}]
6688 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6692 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6697 proc findselectline {l} {
6698 global findloc commentend ctext findcurline markingmatches gdttype
6700 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6703 if {$markingmatches &&
6704 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6705 # highlight the matches in the comments
6706 set f [$ctext get 1.0 $commentend]
6707 set matches [findmatches $f]
6708 foreach match $matches {
6709 set start [lindex $match 0]
6710 set end [expr {[lindex $match 1] + 1}]
6711 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6717 # mark the bits of a headline or author that match a find string
6718 proc markmatches {canv l str tag matches font row} {
6721 set bbox [$canv bbox $tag]
6722 set x0 [lindex $bbox 0]
6723 set y0 [lindex $bbox 1]
6724 set y1 [lindex $bbox 3]
6725 foreach match $matches {
6726 set start [lindex $match 0]
6727 set end [lindex $match 1]
6728 if {$start > $end} continue
6729 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6730 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6731 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6732 [expr {$x0+$xlen+2}] $y1 \
6733 -outline {} -tags [list match$l matches] -fill yellow]
6735 if {$row == $selectedline} {
6736 $canv raise $t secsel
6741 proc unmarkmatches {} {
6742 global markingmatches
6744 allcanvs delete matches
6745 set markingmatches 0
6749 proc selcanvline {w x y} {
6750 global canv canvy0 ctext linespc
6752 set ymax [lindex [$canv cget -scrollregion] 3]
6753 if {$ymax == {}} return
6754 set yfrac [lindex [$canv yview] 0]
6755 set y [expr {$y + $yfrac * $ymax}]
6756 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6761 set xmax [lindex [$canv cget -scrollregion] 2]
6762 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6763 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6769 proc commit_descriptor {p} {
6771 if {![info exists commitinfo($p)]} {
6775 if {[llength $commitinfo($p)] > 1} {
6776 set l [lindex $commitinfo($p) 0]
6781 # append some text to the ctext widget, and make any SHA1 ID
6782 # that we know about be a clickable link.
6783 proc appendwithlinks {text tags} {
6784 global ctext linknum curview
6786 set start [$ctext index "end - 1c"]
6787 $ctext insert end $text $tags
6788 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6792 set linkid [string range $text $s $e]
6794 $ctext tag delete link$linknum
6795 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6796 setlink $linkid link$linknum
6801 proc setlink {id lk} {
6802 global curview ctext pendinglinks
6804 if {[string range $id 0 1] eq "-g"} {
6805 set id [string range $id 2 end]
6809 if {[string length $id] < 40} {
6810 set matches [longid $id]
6811 if {[llength $matches] > 0} {
6812 if {[llength $matches] > 1} return
6814 set id [lindex $matches 0]
6817 set known [commitinview $id $curview]
6820 $ctext tag conf $lk -foreground blue -underline 1
6821 $ctext tag bind $lk <1> [list selbyid $id]
6822 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6823 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6825 lappend pendinglinks($id) $lk
6826 interestedin $id {makelink %P}
6830 proc appendshortlink {id {pre {}} {post {}}} {
6831 global ctext linknum
6833 $ctext insert end $pre
6834 $ctext tag delete link$linknum
6835 $ctext insert end [string range $id 0 7] link$linknum
6836 $ctext insert end $post
6837 setlink $id link$linknum
6841 proc makelink {id} {
6844 if {![info exists pendinglinks($id)]} return
6845 foreach lk $pendinglinks($id) {
6848 unset pendinglinks($id)
6851 proc linkcursor {w inc} {
6852 global linkentercount curtextcursor
6854 if {[incr linkentercount $inc] > 0} {
6855 $w configure -cursor hand2
6857 $w configure -cursor $curtextcursor
6858 if {$linkentercount < 0} {
6859 set linkentercount 0
6864 proc viewnextline {dir} {
6868 set ymax [lindex [$canv cget -scrollregion] 3]
6869 set wnow [$canv yview]
6870 set wtop [expr {[lindex $wnow 0] * $ymax}]
6871 set newtop [expr {$wtop + $dir * $linespc}]
6874 } elseif {$newtop > $ymax} {
6877 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6880 # add a list of tag or branch names at position pos
6881 # returns the number of names inserted
6882 proc appendrefs {pos ids var} {
6883 global ctext linknum curview $var maxrefs mainheadid
6885 if {[catch {$ctext index $pos}]} {
6888 $ctext conf -state normal
6889 $ctext delete $pos "$pos lineend"
6892 foreach tag [set $var\($id\)] {
6893 lappend tags [list $tag $id]
6898 set tags [lsort -index 0 -decreasing $tags]
6901 if {[llength $tags] > $maxrefs} {
6902 # If we are displaying heads, and there are too many,
6903 # see if there are some important heads to display.
6904 # Currently this means "master" and the current head.
6906 if {$var eq "idheads"} {
6909 set hname [lindex $ti 0]
6910 set id [lindex $ti 1]
6911 if {($hname eq "master" || $id eq $mainheadid) &&
6912 [llength $itags] < $maxrefs} {
6921 set str [mc "and many more"]
6926 $ctext insert $pos "$str ([llength $tags])"
6927 set nutags [llength $tags]
6932 set id [lindex $ti 1]
6935 $ctext tag delete $lk
6936 $ctext insert $pos $sep
6937 $ctext insert $pos [lindex $ti 0] $lk
6941 $ctext tag add wwrap "$pos linestart" "$pos lineend"
6942 $ctext conf -state disabled
6943 return [expr {[llength $tags] + $nutags}]
6946 # called when we have finished computing the nearby tags
6947 proc dispneartags {delay} {
6948 global selectedline currentid showneartags tagphase
6950 if {$selectedline eq {} || !$showneartags} return
6951 after cancel dispnexttag
6953 after 200 dispnexttag
6956 after idle dispnexttag
6961 proc dispnexttag {} {
6962 global selectedline currentid showneartags tagphase ctext
6964 if {$selectedline eq {} || !$showneartags} return
6965 switch -- $tagphase {
6967 set dtags [desctags $currentid]
6969 appendrefs precedes $dtags idtags
6973 set atags [anctags $currentid]
6975 appendrefs follows $atags idtags
6979 set dheads [descheads $currentid]
6980 if {$dheads ne {}} {
6981 if {[appendrefs branch $dheads idheads] > 1
6982 && [$ctext get "branch -3c"] eq "h"} {
6983 # turn "Branch" into "Branches"
6984 $ctext conf -state normal
6985 $ctext insert "branch -2c" "es"
6986 $ctext conf -state disabled
6991 if {[incr tagphase] <= 2} {
6992 after idle dispnexttag
6996 proc make_secsel {id} {
6997 global linehtag linentag linedtag canv canv2 canv3
6999 if {![info exists linehtag($id)]} return
7001 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7002 -tags secsel -fill [$canv cget -selectbackground]]
7004 $canv2 delete secsel
7005 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7006 -tags secsel -fill [$canv2 cget -selectbackground]]
7008 $canv3 delete secsel
7009 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7010 -tags secsel -fill [$canv3 cget -selectbackground]]
7014 proc make_idmark {id} {
7015 global linehtag canv fgcolor
7017 if {![info exists linehtag($id)]} return
7019 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7020 -tags markid -outline $fgcolor]
7024 proc selectline {l isnew {desired_loc {}}} {
7025 global canv ctext commitinfo selectedline
7026 global canvy0 linespc parents children curview
7027 global currentid sha1entry
7028 global commentend idtags linknum
7029 global mergemax numcommits pending_select
7030 global cmitmode showneartags allcommits
7031 global targetrow targetid lastscrollrows
7032 global autoselect autosellen jump_to_here
7034 catch {unset pending_select}
7039 if {$l < 0 || $l >= $numcommits} return
7040 set id [commitonrow $l]
7045 if {$lastscrollrows < $numcommits} {
7049 set y [expr {$canvy0 + $l * $linespc}]
7050 set ymax [lindex [$canv cget -scrollregion] 3]
7051 set ytop [expr {$y - $linespc - 1}]
7052 set ybot [expr {$y + $linespc + 1}]
7053 set wnow [$canv yview]
7054 set wtop [expr {[lindex $wnow 0] * $ymax}]
7055 set wbot [expr {[lindex $wnow 1] * $ymax}]
7056 set wh [expr {$wbot - $wtop}]
7058 if {$ytop < $wtop} {
7059 if {$ybot < $wtop} {
7060 set newtop [expr {$y - $wh / 2.0}]
7063 if {$newtop > $wtop - $linespc} {
7064 set newtop [expr {$wtop - $linespc}]
7067 } elseif {$ybot > $wbot} {
7068 if {$ytop > $wbot} {
7069 set newtop [expr {$y - $wh / 2.0}]
7071 set newtop [expr {$ybot - $wh}]
7072 if {$newtop < $wtop + $linespc} {
7073 set newtop [expr {$wtop + $linespc}]
7077 if {$newtop != $wtop} {
7081 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7088 addtohistory [list selbyid $id 0] savecmitpos
7091 $sha1entry delete 0 end
7092 $sha1entry insert 0 $id
7094 $sha1entry selection range 0 $autosellen
7098 $ctext conf -state normal
7101 if {![info exists commitinfo($id)]} {
7104 set info $commitinfo($id)
7105 set date [formatdate [lindex $info 2]]
7106 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7107 set date [formatdate [lindex $info 4]]
7108 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7109 if {[info exists idtags($id)]} {
7110 $ctext insert end [mc "Tags:"]
7111 foreach tag $idtags($id) {
7112 $ctext insert end " $tag"
7114 $ctext insert end "\n"
7118 set olds $parents($curview,$id)
7119 if {[llength $olds] > 1} {
7122 if {$np >= $mergemax} {
7127 $ctext insert end "[mc "Parent"]: " $tag
7128 appendwithlinks [commit_descriptor $p] {}
7133 append headers "[mc "Parent"]: [commit_descriptor $p]"
7137 foreach c $children($curview,$id) {
7138 append headers "[mc "Child"]: [commit_descriptor $c]"
7141 # make anything that looks like a SHA1 ID be a clickable link
7142 appendwithlinks $headers {}
7143 if {$showneartags} {
7144 if {![info exists allcommits]} {
7147 $ctext insert end "[mc "Branch"]: "
7148 $ctext mark set branch "end -1c"
7149 $ctext mark gravity branch left
7150 $ctext insert end "\n[mc "Follows"]: "
7151 $ctext mark set follows "end -1c"
7152 $ctext mark gravity follows left
7153 $ctext insert end "\n[mc "Precedes"]: "
7154 $ctext mark set precedes "end -1c"
7155 $ctext mark gravity precedes left
7156 $ctext insert end "\n"
7159 $ctext insert end "\n"
7160 set comment [lindex $info 5]
7161 if {[string first "\r" $comment] >= 0} {
7162 set comment [string map {"\r" "\n "} $comment]
7164 appendwithlinks $comment {comment}
7166 $ctext tag remove found 1.0 end
7167 $ctext conf -state disabled
7168 set commentend [$ctext index "end - 1c"]
7170 set jump_to_here $desired_loc
7171 init_flist [mc "Comments"]
7172 if {$cmitmode eq "tree"} {
7174 } elseif {[llength $olds] <= 1} {
7181 proc selfirstline {} {
7186 proc sellastline {} {
7189 set l [expr {$numcommits - 1}]
7193 proc selnextline {dir} {
7196 if {$selectedline eq {}} return
7197 set l [expr {$selectedline + $dir}]
7202 proc selnextpage {dir} {
7203 global canv linespc selectedline numcommits
7205 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7209 allcanvs yview scroll [expr {$dir * $lpp}] units
7211 if {$selectedline eq {}} return
7212 set l [expr {$selectedline + $dir * $lpp}]
7215 } elseif {$l >= $numcommits} {
7216 set l [expr $numcommits - 1]
7222 proc unselectline {} {
7223 global selectedline currentid
7226 catch {unset currentid}
7227 allcanvs delete secsel
7231 proc reselectline {} {
7234 if {$selectedline ne {}} {
7235 selectline $selectedline 0
7239 proc addtohistory {cmd {saveproc {}}} {
7240 global history historyindex curview
7244 set elt [list $curview $cmd $saveproc {}]
7245 if {$historyindex > 0
7246 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7250 if {$historyindex < [llength $history]} {
7251 set history [lreplace $history $historyindex end $elt]
7253 lappend history $elt
7256 if {$historyindex > 1} {
7257 .tf.bar.leftbut conf -state normal
7259 .tf.bar.leftbut conf -state disabled
7261 .tf.bar.rightbut conf -state disabled
7264 # save the scrolling position of the diff display pane
7265 proc save_position {} {
7266 global historyindex history
7268 if {$historyindex < 1} return
7269 set hi [expr {$historyindex - 1}]
7270 set fn [lindex $history $hi 2]
7272 lset history $hi 3 [eval $fn]
7276 proc unset_posvars {} {
7279 if {[info exists last_posvars]} {
7280 foreach {var val} $last_posvars {
7289 global curview last_posvars
7291 set view [lindex $elt 0]
7292 set cmd [lindex $elt 1]
7293 set pv [lindex $elt 3]
7294 if {$curview != $view} {
7298 foreach {var val} $pv {
7302 set last_posvars $pv
7307 global history historyindex
7310 if {$historyindex > 1} {
7312 incr historyindex -1
7313 godo [lindex $history [expr {$historyindex - 1}]]
7314 .tf.bar.rightbut conf -state normal
7316 if {$historyindex <= 1} {
7317 .tf.bar.leftbut conf -state disabled
7322 global history historyindex
7325 if {$historyindex < [llength $history]} {
7327 set cmd [lindex $history $historyindex]
7330 .tf.bar.leftbut conf -state normal
7332 if {$historyindex >= [llength $history]} {
7333 .tf.bar.rightbut conf -state disabled
7338 global treefilelist treeidlist diffids diffmergeid treepending
7339 global nullid nullid2
7342 catch {unset diffmergeid}
7343 if {![info exists treefilelist($id)]} {
7344 if {![info exists treepending]} {
7345 if {$id eq $nullid} {
7346 set cmd [list | git ls-files]
7347 } elseif {$id eq $nullid2} {
7348 set cmd [list | git ls-files --stage -t]
7350 set cmd [list | git ls-tree -r $id]
7352 if {[catch {set gtf [open $cmd r]}]} {
7356 set treefilelist($id) {}
7357 set treeidlist($id) {}
7358 fconfigure $gtf -blocking 0 -encoding binary
7359 filerun $gtf [list gettreeline $gtf $id]
7366 proc gettreeline {gtf id} {
7367 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7370 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7371 if {$diffids eq $nullid} {
7374 set i [string first "\t" $line]
7375 if {$i < 0} continue
7376 set fname [string range $line [expr {$i+1}] end]
7377 set line [string range $line 0 [expr {$i-1}]]
7378 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7379 set sha1 [lindex $line 2]
7380 lappend treeidlist($id) $sha1
7382 if {[string index $fname 0] eq "\""} {
7383 set fname [lindex $fname 0]
7385 set fname [encoding convertfrom $fname]
7386 lappend treefilelist($id) $fname
7389 return [expr {$nl >= 1000? 2: 1}]
7393 if {$cmitmode ne "tree"} {
7394 if {![info exists diffmergeid]} {
7395 gettreediffs $diffids
7397 } elseif {$id ne $diffids} {
7406 global treefilelist treeidlist diffids nullid nullid2
7407 global ctext_file_names ctext_file_lines
7408 global ctext commentend
7410 set i [lsearch -exact $treefilelist($diffids) $f]
7412 puts "oops, $f not in list for id $diffids"
7415 if {$diffids eq $nullid} {
7416 if {[catch {set bf [open $f r]} err]} {
7417 puts "oops, can't read $f: $err"
7421 set blob [lindex $treeidlist($diffids) $i]
7422 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7423 puts "oops, error reading blob $blob: $err"
7427 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7428 filerun $bf [list getblobline $bf $diffids]
7429 $ctext config -state normal
7430 clear_ctext $commentend
7431 lappend ctext_file_names $f
7432 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7433 $ctext insert end "\n"
7434 $ctext insert end "$f\n" filesep
7435 $ctext config -state disabled
7436 $ctext yview $commentend
7440 proc getblobline {bf id} {
7441 global diffids cmitmode ctext
7443 if {$id ne $diffids || $cmitmode ne "tree"} {
7447 $ctext config -state normal
7449 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7450 $ctext insert end "$line\n"
7453 global jump_to_here ctext_file_names commentend
7455 # delete last newline
7456 $ctext delete "end - 2c" "end - 1c"
7458 if {$jump_to_here ne {} &&
7459 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7460 set lnum [expr {[lindex $jump_to_here 1] +
7461 [lindex [split $commentend .] 0]}]
7462 mark_ctext_line $lnum
7464 $ctext config -state disabled
7467 $ctext config -state disabled
7468 return [expr {$nl >= 1000? 2: 1}]
7471 proc mark_ctext_line {lnum} {
7472 global ctext markbgcolor
7474 $ctext tag delete omark
7475 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7476 $ctext tag conf omark -background $markbgcolor
7480 proc mergediff {id} {
7482 global diffids treediffs
7483 global parents curview
7487 set treediffs($id) {}
7488 set np [llength $parents($curview,$id)]
7493 proc startdiff {ids} {
7494 global treediffs diffids treepending diffmergeid nullid nullid2
7498 catch {unset diffmergeid}
7499 if {![info exists treediffs($ids)] ||
7500 [lsearch -exact $ids $nullid] >= 0 ||
7501 [lsearch -exact $ids $nullid2] >= 0} {
7502 if {![info exists treepending]} {
7510 # If the filename (name) is under any of the passed filter paths
7511 # then return true to include the file in the listing.
7512 proc path_filter {filter name} {
7513 set worktree [gitworktree]
7515 set fq_p [file normalize $p]
7516 set fq_n [file normalize [file join $worktree $name]]
7517 if {[string match [file normalize $fq_p]* $fq_n]} {
7524 proc addtocflist {ids} {
7527 add_flist $treediffs($ids)
7531 proc diffcmd {ids flags} {
7532 global log_showroot nullid nullid2
7534 set i [lsearch -exact $ids $nullid]
7535 set j [lsearch -exact $ids $nullid2]
7537 if {[llength $ids] > 1 && $j < 0} {
7538 # comparing working directory with some specific revision
7539 set cmd [concat | git diff-index $flags]
7541 lappend cmd -R [lindex $ids 1]
7543 lappend cmd [lindex $ids 0]
7546 # comparing working directory with index
7547 set cmd [concat | git diff-files $flags]
7552 } elseif {$j >= 0} {
7553 set cmd [concat | git diff-index --cached $flags]
7554 if {[llength $ids] > 1} {
7555 # comparing index with specific revision
7557 lappend cmd -R [lindex $ids 1]
7559 lappend cmd [lindex $ids 0]
7562 # comparing index with HEAD
7566 if {$log_showroot} {
7567 lappend flags --root
7569 set cmd [concat | git diff-tree -r $flags $ids]
7574 proc gettreediffs {ids} {
7575 global treediff treepending
7577 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
7579 set treepending $ids
7581 fconfigure $gdtf -blocking 0 -encoding binary
7582 filerun $gdtf [list gettreediffline $gdtf $ids]
7585 proc gettreediffline {gdtf ids} {
7586 global treediff treediffs treepending diffids diffmergeid
7587 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7592 if {$perfile_attrs} {
7593 # cache_gitattr is slow, and even slower on win32 where we
7594 # have to invoke it for only about 30 paths at a time
7596 if {[tk windowingsystem] == "win32"} {
7600 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7601 set i [string first "\t" $line]
7603 set file [string range $line [expr {$i+1}] end]
7604 if {[string index $file 0] eq "\""} {
7605 set file [lindex $file 0]
7607 set file [encoding convertfrom $file]
7608 if {$file ne [lindex $treediff end]} {
7609 lappend treediff $file
7610 lappend sublist $file
7614 if {$perfile_attrs} {
7615 cache_gitattr encoding $sublist
7618 return [expr {$nr >= $max? 2: 1}]
7621 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7623 foreach f $treediff {
7624 if {[path_filter $vfilelimit($curview) $f]} {
7628 set treediffs($ids) $flist
7630 set treediffs($ids) $treediff
7633 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7635 } elseif {$ids != $diffids} {
7636 if {![info exists diffmergeid]} {
7637 gettreediffs $diffids
7645 # empty string or positive integer
7646 proc diffcontextvalidate {v} {
7647 return [regexp {^(|[1-9][0-9]*)$} $v]
7650 proc diffcontextchange {n1 n2 op} {
7651 global diffcontextstring diffcontext
7653 if {[string is integer -strict $diffcontextstring]} {
7654 if {$diffcontextstring >= 0} {
7655 set diffcontext $diffcontextstring
7661 proc changeignorespace {} {
7665 proc changeworddiff {name ix op} {
7669 proc getblobdiffs {ids} {
7670 global blobdifffd diffids env
7671 global diffinhdr treediffs
7675 global limitdiffs vfilelimit curview
7676 global diffencoding targetline diffnparents
7677 global git_version currdiffsubmod
7680 if {[package vcompare $git_version "1.6.1"] >= 0} {
7681 set textconv "--textconv"
7684 if {[package vcompare $git_version "1.6.6"] >= 0} {
7685 set submodule "--submodule"
7687 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7691 if {$worddiff ne [mc "Line diff"]} {
7692 append cmd " --word-diff=porcelain"
7694 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7695 set cmd [concat $cmd -- $vfilelimit($curview)]
7697 if {[catch {set bdf [open $cmd r]} err]} {
7698 error_popup [mc "Error getting diffs: %s" $err]
7704 set diffencoding [get_path_encoding {}]
7705 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7706 set blobdifffd($ids) $bdf
7707 set currdiffsubmod ""
7708 filerun $bdf [list getblobdiffline $bdf $diffids]
7711 proc savecmitpos {} {
7712 global ctext cmitmode
7714 if {$cmitmode eq "tree"} {
7717 return [list target_scrollpos [$ctext index @0,0]]
7720 proc savectextpos {} {
7723 return [list target_scrollpos [$ctext index @0,0]]
7726 proc maybe_scroll_ctext {ateof} {
7727 global ctext target_scrollpos
7729 if {![info exists target_scrollpos]} return
7731 set nlines [expr {[winfo height $ctext]
7732 / [font metrics textfont -linespace]}]
7733 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7735 $ctext yview $target_scrollpos
7736 unset target_scrollpos
7739 proc setinlist {var i val} {
7742 while {[llength [set $var]] < $i} {
7745 if {[llength [set $var]] == $i} {
7752 proc makediffhdr {fname ids} {
7753 global ctext curdiffstart treediffs diffencoding
7754 global ctext_file_names jump_to_here targetline diffline
7756 set fname [encoding convertfrom $fname]
7757 set diffencoding [get_path_encoding $fname]
7758 set i [lsearch -exact $treediffs($ids) $fname]
7760 setinlist difffilestart $i $curdiffstart
7762 lset ctext_file_names end $fname
7763 set l [expr {(78 - [string length $fname]) / 2}]
7764 set pad [string range "----------------------------------------" 1 $l]
7765 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7767 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7768 set targetline [lindex $jump_to_here 1]
7773 proc getblobdiffline {bdf ids} {
7774 global diffids blobdifffd ctext curdiffstart
7775 global diffnexthead diffnextnote difffilestart
7776 global ctext_file_names ctext_file_lines
7777 global diffinhdr treediffs mergemax diffnparents
7778 global diffencoding jump_to_here targetline diffline currdiffsubmod
7782 $ctext conf -state normal
7783 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7784 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7788 if {![string compare -length 5 "diff " $line]} {
7789 if {![regexp {^diff (--cc|--git) } $line m type]} {
7790 set line [encoding convertfrom $line]
7791 $ctext insert end "$line\n" hunksep
7794 # start of a new file
7796 $ctext insert end "\n"
7797 set curdiffstart [$ctext index "end - 1c"]
7798 lappend ctext_file_names ""
7799 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7800 $ctext insert end "\n" filesep
7802 if {$type eq "--cc"} {
7803 # start of a new file in a merge diff
7804 set fname [string range $line 10 end]
7805 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7806 lappend treediffs($ids) $fname
7807 add_flist [list $fname]
7811 set line [string range $line 11 end]
7812 # If the name hasn't changed the length will be odd,
7813 # the middle char will be a space, and the two bits either
7814 # side will be a/name and b/name, or "a/name" and "b/name".
7815 # If the name has changed we'll get "rename from" and
7816 # "rename to" or "copy from" and "copy to" lines following
7817 # this, and we'll use them to get the filenames.
7818 # This complexity is necessary because spaces in the
7819 # filename(s) don't get escaped.
7820 set l [string length $line]
7821 set i [expr {$l / 2}]
7822 if {!(($l & 1) && [string index $line $i] eq " " &&
7823 [string range $line 2 [expr {$i - 1}]] eq \
7824 [string range $line [expr {$i + 3}] end])} {
7827 # unescape if quoted and chop off the a/ from the front
7828 if {[string index $line 0] eq "\""} {
7829 set fname [string range [lindex $line 0] 2 end]
7831 set fname [string range $line 2 [expr {$i - 1}]]
7834 makediffhdr $fname $ids
7836 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7837 set fname [encoding convertfrom [string range $line 16 end]]
7838 $ctext insert end "\n"
7839 set curdiffstart [$ctext index "end - 1c"]
7840 lappend ctext_file_names $fname
7841 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7842 $ctext insert end "$line\n" filesep
7843 set i [lsearch -exact $treediffs($ids) $fname]
7845 setinlist difffilestart $i $curdiffstart
7848 } elseif {![string compare -length 2 "@@" $line]} {
7849 regexp {^@@+} $line ats
7850 set line [encoding convertfrom $diffencoding $line]
7851 $ctext insert end "$line\n" hunksep
7852 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7855 set diffnparents [expr {[string length $ats] - 1}]
7858 } elseif {![string compare -length 10 "Submodule " $line]} {
7859 # start of a new submodule
7860 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7861 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7863 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7865 if {$currdiffsubmod != $fname} {
7866 $ctext insert end "\n"; # Add newline after commit message
7868 set curdiffstart [$ctext index "end - 1c"]
7869 lappend ctext_file_names ""
7870 if {$currdiffsubmod != $fname} {
7871 lappend ctext_file_lines $fname
7872 makediffhdr $fname $ids
7873 set currdiffsubmod $fname
7874 $ctext insert end "\n$line\n" filesep
7876 $ctext insert end "$line\n" filesep
7878 } elseif {![string compare -length 3 " >" $line]} {
7879 set $currdiffsubmod ""
7880 set line [encoding convertfrom $diffencoding $line]
7881 $ctext insert end "$line\n" dresult
7882 } elseif {![string compare -length 3 " <" $line]} {
7883 set $currdiffsubmod ""
7884 set line [encoding convertfrom $diffencoding $line]
7885 $ctext insert end "$line\n" d0
7886 } elseif {$diffinhdr} {
7887 if {![string compare -length 12 "rename from " $line]} {
7888 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7889 if {[string index $fname 0] eq "\""} {
7890 set fname [lindex $fname 0]
7892 set fname [encoding convertfrom $fname]
7893 set i [lsearch -exact $treediffs($ids) $fname]
7895 setinlist difffilestart $i $curdiffstart
7897 } elseif {![string compare -length 10 $line "rename to "] ||
7898 ![string compare -length 8 $line "copy to "]} {
7899 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7900 if {[string index $fname 0] eq "\""} {
7901 set fname [lindex $fname 0]
7903 makediffhdr $fname $ids
7904 } elseif {[string compare -length 3 $line "---"] == 0} {
7907 } elseif {[string compare -length 3 $line "+++"] == 0} {
7911 $ctext insert end "$line\n" filesep
7914 set line [string map {\x1A ^Z} \
7915 [encoding convertfrom $diffencoding $line]]
7916 # parse the prefix - one ' ', '-' or '+' for each parent
7917 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7918 set tag [expr {$diffnparents > 1? "m": "d"}]
7919 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7920 set words_pre_markup ""
7921 set words_post_markup ""
7922 if {[string trim $prefix " -+"] eq {}} {
7923 # prefix only has " ", "-" and "+" in it: normal diff line
7924 set num [string first "-" $prefix]
7926 set line [string range $line 1 end]
7929 # removed line, first parent with line is $num
7930 if {$num >= $mergemax} {
7933 if {$dowords && $worddiff eq [mc "Markup words"]} {
7934 $ctext insert end "\[-$line-\]" $tag$num
7936 $ctext insert end "$line" $tag$num
7939 $ctext insert end "\n" $tag$num
7943 if {[string first "+" $prefix] >= 0} {
7945 lappend tags ${tag}result
7946 if {$diffnparents > 1} {
7947 set num [string first " " $prefix]
7949 if {$num >= $mergemax} {
7955 set words_pre_markup "{+"
7956 set words_post_markup "+}"
7958 if {$targetline ne {}} {
7959 if {$diffline == $targetline} {
7960 set seehere [$ctext index "end - 1 chars"]
7966 if {$dowords && $worddiff eq [mc "Markup words"]} {
7967 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
7969 $ctext insert end "$line" $tags
7972 $ctext insert end "\n" $tags
7975 } elseif {$dowords && $prefix eq "~"} {
7976 $ctext insert end "\n" {}
7978 # "\ No newline at end of file",
7979 # or something else we don't recognize
7980 $ctext insert end "$line\n" hunksep
7984 if {[info exists seehere]} {
7985 mark_ctext_line [lindex [split $seehere .] 0]
7987 maybe_scroll_ctext [eof $bdf]
7988 $ctext conf -state disabled
7993 return [expr {$nr >= 1000? 2: 1}]
7996 proc changediffdisp {} {
7997 global ctext diffelide
7999 $ctext tag conf d0 -elide [lindex $diffelide 0]
8000 $ctext tag conf dresult -elide [lindex $diffelide 1]
8003 proc highlightfile {cline} {
8004 global cflist cflist_top
8006 if {![info exists cflist_top]} return
8008 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8009 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8010 $cflist see $cline.0
8011 set cflist_top $cline
8014 proc highlightfile_for_scrollpos {topidx} {
8015 global cmitmode difffilestart
8017 if {$cmitmode eq "tree"} return
8018 if {![info exists difffilestart]} return
8020 set top [lindex [split $topidx .] 0]
8021 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8024 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8029 global difffilestart ctext cmitmode
8031 if {$cmitmode eq "tree"} return
8033 set here [$ctext index @0,0]
8034 foreach loc $difffilestart {
8035 if {[$ctext compare $loc >= $here]} {
8045 global difffilestart ctext cmitmode
8047 if {$cmitmode eq "tree"} return
8048 set here [$ctext index @0,0]
8049 foreach loc $difffilestart {
8050 if {[$ctext compare $loc > $here]} {
8057 proc clear_ctext {{first 1.0}} {
8058 global ctext smarktop smarkbot
8059 global ctext_file_names ctext_file_lines
8062 set l [lindex [split $first .] 0]
8063 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8066 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8069 $ctext delete $first end
8070 if {$first eq "1.0"} {
8071 catch {unset pendinglinks}
8073 set ctext_file_names {}
8074 set ctext_file_lines {}
8077 proc settabs {{firstab {}}} {
8078 global firsttabstop tabstop ctext have_tk85
8080 if {$firstab ne {} && $have_tk85} {
8081 set firsttabstop $firstab
8083 set w [font measure textfont "0"]
8084 if {$firsttabstop != 0} {
8085 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8086 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8087 } elseif {$have_tk85 || $tabstop != 8} {
8088 $ctext conf -tabs [expr {$tabstop * $w}]
8090 $ctext conf -tabs {}
8094 proc incrsearch {name ix op} {
8095 global ctext searchstring searchdirn
8097 if {[catch {$ctext index anchor}]} {
8098 # no anchor set, use start of selection, or of visible area
8099 set sel [$ctext tag ranges sel]
8101 $ctext mark set anchor [lindex $sel 0]
8102 } elseif {$searchdirn eq "-forwards"} {
8103 $ctext mark set anchor @0,0
8105 $ctext mark set anchor @0,[winfo height $ctext]
8108 if {$searchstring ne {}} {
8109 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8112 set mend "$here + $mlen c"
8113 $ctext tag remove sel 1.0 end
8114 $ctext tag add sel $here $mend
8115 suppress_highlighting_file_for_current_scrollpos
8116 highlightfile_for_scrollpos $here
8119 rehighlight_search_results
8123 global sstring ctext searchstring searchdirn
8126 $sstring icursor end
8127 set searchdirn -forwards
8128 if {$searchstring ne {}} {
8129 set sel [$ctext tag ranges sel]
8131 set start "[lindex $sel 0] + 1c"
8132 } elseif {[catch {set start [$ctext index anchor]}]} {
8135 set match [$ctext search -count mlen -- $searchstring $start]
8136 $ctext tag remove sel 1.0 end
8142 suppress_highlighting_file_for_current_scrollpos
8143 highlightfile_for_scrollpos $match
8144 set mend "$match + $mlen c"
8145 $ctext tag add sel $match $mend
8146 $ctext mark unset anchor
8147 rehighlight_search_results
8151 proc dosearchback {} {
8152 global sstring ctext searchstring searchdirn
8155 $sstring icursor end
8156 set searchdirn -backwards
8157 if {$searchstring ne {}} {
8158 set sel [$ctext tag ranges sel]
8160 set start [lindex $sel 0]
8161 } elseif {[catch {set start [$ctext index anchor]}]} {
8162 set start @0,[winfo height $ctext]
8164 set match [$ctext search -backwards -count ml -- $searchstring $start]
8165 $ctext tag remove sel 1.0 end
8171 suppress_highlighting_file_for_current_scrollpos
8172 highlightfile_for_scrollpos $match
8173 set mend "$match + $ml c"
8174 $ctext tag add sel $match $mend
8175 $ctext mark unset anchor
8176 rehighlight_search_results
8180 proc rehighlight_search_results {} {
8181 global ctext searchstring
8183 $ctext tag remove found 1.0 end
8184 $ctext tag remove currentsearchhit 1.0 end
8186 if {$searchstring ne {}} {
8191 proc searchmark {first last} {
8192 global ctext searchstring
8194 set sel [$ctext tag ranges sel]
8198 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8199 if {$match eq {}} break
8200 set mend "$match + $mlen c"
8201 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8202 $ctext tag add currentsearchhit $match $mend
8204 $ctext tag add found $match $mend
8209 proc searchmarkvisible {doall} {
8210 global ctext smarktop smarkbot
8212 set topline [lindex [split [$ctext index @0,0] .] 0]
8213 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8214 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8215 # no overlap with previous
8216 searchmark $topline $botline
8217 set smarktop $topline
8218 set smarkbot $botline
8220 if {$topline < $smarktop} {
8221 searchmark $topline [expr {$smarktop-1}]
8222 set smarktop $topline
8224 if {$botline > $smarkbot} {
8225 searchmark [expr {$smarkbot+1}] $botline
8226 set smarkbot $botline
8231 proc suppress_highlighting_file_for_current_scrollpos {} {
8232 global ctext suppress_highlighting_file_for_this_scrollpos
8234 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8237 proc scrolltext {f0 f1} {
8238 global searchstring cmitmode ctext
8239 global suppress_highlighting_file_for_this_scrollpos
8241 set topidx [$ctext index @0,0]
8242 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8243 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8244 highlightfile_for_scrollpos $topidx
8247 catch {unset suppress_highlighting_file_for_this_scrollpos}
8249 .bleft.bottom.sb set $f0 $f1
8250 if {$searchstring ne {}} {
8256 global linespc charspc canvx0 canvy0
8257 global xspc1 xspc2 lthickness
8259 set linespc [font metrics mainfont -linespace]
8260 set charspc [font measure mainfont "m"]
8261 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8262 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8263 set lthickness [expr {int($linespc / 9) + 1}]
8264 set xspc1(0) $linespc
8272 set ymax [lindex [$canv cget -scrollregion] 3]
8273 if {$ymax eq {} || $ymax == 0} return
8274 set span [$canv yview]
8277 allcanvs yview moveto [lindex $span 0]
8279 if {$selectedline ne {}} {
8280 selectline $selectedline 0
8281 allcanvs yview moveto [lindex $span 0]
8285 proc parsefont {f n} {
8288 set fontattr($f,family) [lindex $n 0]
8290 if {$s eq {} || $s == 0} {
8293 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8295 set fontattr($f,size) $s
8296 set fontattr($f,weight) normal
8297 set fontattr($f,slant) roman
8298 foreach style [lrange $n 2 end] {
8301 "bold" {set fontattr($f,weight) $style}
8303 "italic" {set fontattr($f,slant) $style}
8308 proc fontflags {f {isbold 0}} {
8311 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8312 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8313 -slant $fontattr($f,slant)]
8319 set n [list $fontattr($f,family) $fontattr($f,size)]
8320 if {$fontattr($f,weight) eq "bold"} {
8323 if {$fontattr($f,slant) eq "italic"} {
8329 proc incrfont {inc} {
8330 global mainfont textfont ctext canv cflist showrefstop
8331 global stopped entries fontattr
8334 set s $fontattr(mainfont,size)
8339 set fontattr(mainfont,size) $s
8340 font config mainfont -size $s
8341 font config mainfontbold -size $s
8342 set mainfont [fontname mainfont]
8343 set s $fontattr(textfont,size)
8348 set fontattr(textfont,size) $s
8349 font config textfont -size $s
8350 font config textfontbold -size $s
8351 set textfont [fontname textfont]
8358 global sha1entry sha1string
8359 if {[string length $sha1string] == 40} {
8360 $sha1entry delete 0 end
8364 proc sha1change {n1 n2 op} {
8365 global sha1string currentid sha1but
8366 if {$sha1string == {}
8367 || ([info exists currentid] && $sha1string == $currentid)} {
8372 if {[$sha1but cget -state] == $state} return
8373 if {$state == "normal"} {
8374 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8376 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8380 proc gotocommit {} {
8381 global sha1string tagids headids curview varcid
8383 if {$sha1string == {}
8384 || ([info exists currentid] && $sha1string == $currentid)} return
8385 if {[info exists tagids($sha1string)]} {
8386 set id $tagids($sha1string)
8387 } elseif {[info exists headids($sha1string)]} {
8388 set id $headids($sha1string)
8390 set id [string tolower $sha1string]
8391 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8392 set matches [longid $id]
8393 if {$matches ne {}} {
8394 if {[llength $matches] > 1} {
8395 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8398 set id [lindex $matches 0]
8401 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8402 error_popup [mc "Revision %s is not known" $sha1string]
8407 if {[commitinview $id $curview]} {
8408 selectline [rowofcommit $id] 1
8411 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8412 set msg [mc "SHA1 id %s is not known" $sha1string]
8414 set msg [mc "Revision %s is not in the current view" $sha1string]
8419 proc lineenter {x y id} {
8420 global hoverx hovery hoverid hovertimer
8421 global commitinfo canv
8423 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8427 if {[info exists hovertimer]} {
8428 after cancel $hovertimer
8430 set hovertimer [after 500 linehover]
8434 proc linemotion {x y id} {
8435 global hoverx hovery hoverid hovertimer
8437 if {[info exists hoverid] && $id == $hoverid} {
8440 if {[info exists hovertimer]} {
8441 after cancel $hovertimer
8443 set hovertimer [after 500 linehover]
8447 proc lineleave {id} {
8448 global hoverid hovertimer canv
8450 if {[info exists hoverid] && $id == $hoverid} {
8452 if {[info exists hovertimer]} {
8453 after cancel $hovertimer
8461 global hoverx hovery hoverid hovertimer
8462 global canv linespc lthickness
8465 set text [lindex $commitinfo($hoverid) 0]
8466 set ymax [lindex [$canv cget -scrollregion] 3]
8467 if {$ymax == {}} return
8468 set yfrac [lindex [$canv yview] 0]
8469 set x [expr {$hoverx + 2 * $linespc}]
8470 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8471 set x0 [expr {$x - 2 * $lthickness}]
8472 set y0 [expr {$y - 2 * $lthickness}]
8473 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8474 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8475 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8476 -fill \#ffff80 -outline black -width 1 -tags hover]
8478 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8483 proc clickisonarrow {id y} {
8486 set ranges [rowranges $id]
8487 set thresh [expr {2 * $lthickness + 6}]
8488 set n [expr {[llength $ranges] - 1}]
8489 for {set i 1} {$i < $n} {incr i} {
8490 set row [lindex $ranges $i]
8491 if {abs([yc $row] - $y) < $thresh} {
8498 proc arrowjump {id n y} {
8501 # 1 <-> 2, 3 <-> 4, etc...
8502 set n [expr {(($n - 1) ^ 1) + 1}]
8503 set row [lindex [rowranges $id] $n]
8505 set ymax [lindex [$canv cget -scrollregion] 3]
8506 if {$ymax eq {} || $ymax <= 0} return
8507 set view [$canv yview]
8508 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8509 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8513 allcanvs yview moveto $yfrac
8516 proc lineclick {x y id isnew} {
8517 global ctext commitinfo children canv thickerline curview
8519 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8524 # draw this line thicker than normal
8528 set ymax [lindex [$canv cget -scrollregion] 3]
8529 if {$ymax eq {}} return
8530 set yfrac [lindex [$canv yview] 0]
8531 set y [expr {$y + $yfrac * $ymax}]
8533 set dirn [clickisonarrow $id $y]
8535 arrowjump $id $dirn $y
8540 addtohistory [list lineclick $x $y $id 0] savectextpos
8542 # fill the details pane with info about this line
8543 $ctext conf -state normal
8546 $ctext insert end "[mc "Parent"]:\t"
8547 $ctext insert end $id link0
8549 set info $commitinfo($id)
8550 $ctext insert end "\n\t[lindex $info 0]\n"
8551 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8552 set date [formatdate [lindex $info 2]]
8553 $ctext insert end "\t[mc "Date"]:\t$date\n"
8554 set kids $children($curview,$id)
8556 $ctext insert end "\n[mc "Children"]:"
8558 foreach child $kids {
8560 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8561 set info $commitinfo($child)
8562 $ctext insert end "\n\t"
8563 $ctext insert end $child link$i
8564 setlink $child link$i
8565 $ctext insert end "\n\t[lindex $info 0]"
8566 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8567 set date [formatdate [lindex $info 2]]
8568 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8571 maybe_scroll_ctext 1
8572 $ctext conf -state disabled
8576 proc normalline {} {
8578 if {[info exists thickerline]} {
8585 proc selbyid {id {isnew 1}} {
8587 if {[commitinview $id $curview]} {
8588 selectline [rowofcommit $id] $isnew
8594 if {![info exists startmstime]} {
8595 set startmstime [clock clicks -milliseconds]
8597 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8600 proc rowmenu {x y id} {
8601 global rowctxmenu selectedline rowmenuid curview
8602 global nullid nullid2 fakerowmenu mainhead markedid
8606 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8611 if {[info exists markedid] && $markedid ne $id} {
8616 if {$id ne $nullid && $id ne $nullid2} {
8617 set menu $rowctxmenu
8618 if {$mainhead ne {}} {
8619 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8621 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8623 $menu entryconfigure 9 -state $mstate
8624 $menu entryconfigure 10 -state $mstate
8625 $menu entryconfigure 11 -state $mstate
8627 set menu $fakerowmenu
8629 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8630 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8631 $menu entryconfigure [mca "Make patch"] -state $state
8632 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8633 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8634 tk_popup $menu $x $y
8638 global rowmenuid markedid canv
8640 set markedid $rowmenuid
8641 make_idmark $markedid
8647 if {[info exists markedid]} {
8652 proc replace_by_kids {l r} {
8653 global curview children
8655 set id [commitonrow $r]
8656 set l [lreplace $l 0 0]
8657 foreach kid $children($curview,$id) {
8658 lappend l [rowofcommit $kid]
8660 return [lsort -integer -decreasing -unique $l]
8663 proc find_common_desc {} {
8664 global markedid rowmenuid curview children
8666 if {![info exists markedid]} return
8667 if {![commitinview $markedid $curview] ||
8668 ![commitinview $rowmenuid $curview]} return
8669 #set t1 [clock clicks -milliseconds]
8670 set l1 [list [rowofcommit $markedid]]
8671 set l2 [list [rowofcommit $rowmenuid]]
8673 set r1 [lindex $l1 0]
8674 set r2 [lindex $l2 0]
8675 if {$r1 eq {} || $r2 eq {}} break
8681 set l1 [replace_by_kids $l1 $r1]
8683 set l2 [replace_by_kids $l2 $r2]
8686 #set t2 [clock clicks -milliseconds]
8687 #puts "took [expr {$t2-$t1}]ms"
8690 proc compare_commits {} {
8691 global markedid rowmenuid curview children
8693 if {![info exists markedid]} return
8694 if {![commitinview $markedid $curview]} return
8695 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8696 do_cmp_commits $markedid $rowmenuid
8699 proc getpatchid {id} {
8702 if {![info exists patchids($id)]} {
8703 set cmd [diffcmd [list $id] {-p --root}]
8704 # trim off the initial "|"
8705 set cmd [lrange $cmd 1 end]
8707 set x [eval exec $cmd | git patch-id]
8708 set patchids($id) [lindex $x 0]
8710 set patchids($id) "error"
8713 return $patchids($id)
8716 proc do_cmp_commits {a b} {
8717 global ctext curview parents children patchids commitinfo
8719 $ctext conf -state normal
8722 for {set i 0} {$i < 100} {incr i} {
8725 if {[llength $parents($curview,$a)] > 1} {
8726 appendshortlink $a [mc "Skipping merge commit "] "\n"
8729 set patcha [getpatchid $a]
8731 if {[llength $parents($curview,$b)] > 1} {
8732 appendshortlink $b [mc "Skipping merge commit "] "\n"
8735 set patchb [getpatchid $b]
8737 if {!$skipa && !$skipb} {
8738 set heada [lindex $commitinfo($a) 0]
8739 set headb [lindex $commitinfo($b) 0]
8740 if {$patcha eq "error"} {
8741 appendshortlink $a [mc "Error getting patch ID for "] \
8742 [mc " - stopping\n"]
8745 if {$patchb eq "error"} {
8746 appendshortlink $b [mc "Error getting patch ID for "] \
8747 [mc " - stopping\n"]
8750 if {$patcha eq $patchb} {
8751 if {$heada eq $headb} {
8752 appendshortlink $a [mc "Commit "]
8753 appendshortlink $b " == " " $heada\n"
8755 appendshortlink $a [mc "Commit "] " $heada\n"
8756 appendshortlink $b [mc " is the same patch as\n "] \
8762 $ctext insert end "\n"
8763 appendshortlink $a [mc "Commit "] " $heada\n"
8764 appendshortlink $b [mc " differs from\n "] \
8766 $ctext insert end [mc "Diff of commits:\n\n"]
8767 $ctext conf -state disabled
8774 set kids [real_children $curview,$a]
8775 if {[llength $kids] != 1} {
8776 $ctext insert end "\n"
8777 appendshortlink $a [mc "Commit "] \
8778 [mc " has %s children - stopping\n" [llength $kids]]
8781 set a [lindex $kids 0]
8784 set kids [real_children $curview,$b]
8785 if {[llength $kids] != 1} {
8786 appendshortlink $b [mc "Commit "] \
8787 [mc " has %s children - stopping\n" [llength $kids]]
8790 set b [lindex $kids 0]
8793 $ctext conf -state disabled
8796 proc diffcommits {a b} {
8797 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8799 set tmpdir [gitknewtmpdir]
8800 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8801 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8803 exec git diff-tree -p --pretty $a >$fna
8804 exec git diff-tree -p --pretty $b >$fnb
8806 error_popup [mc "Error writing commit to file: %s" $err]
8810 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8812 error_popup [mc "Error diffing commits: %s" $err]
8815 set diffids [list commits $a $b]
8816 set blobdifffd($diffids) $fd
8818 set currdiffsubmod ""
8819 filerun $fd [list getblobdiffline $fd $diffids]
8822 proc diffvssel {dirn} {
8823 global rowmenuid selectedline
8825 if {$selectedline eq {}} return
8827 set oldid [commitonrow $selectedline]
8828 set newid $rowmenuid
8830 set oldid $rowmenuid
8831 set newid [commitonrow $selectedline]
8833 addtohistory [list doseldiff $oldid $newid] savectextpos
8834 doseldiff $oldid $newid
8837 proc diffvsmark {dirn} {
8838 global rowmenuid markedid
8840 if {![info exists markedid]} return
8843 set newid $rowmenuid
8845 set oldid $rowmenuid
8848 addtohistory [list doseldiff $oldid $newid] savectextpos
8849 doseldiff $oldid $newid
8852 proc doseldiff {oldid newid} {
8856 $ctext conf -state normal
8858 init_flist [mc "Top"]
8859 $ctext insert end "[mc "From"] "
8860 $ctext insert end $oldid link0
8861 setlink $oldid link0
8862 $ctext insert end "\n "
8863 $ctext insert end [lindex $commitinfo($oldid) 0]
8864 $ctext insert end "\n\n[mc "To"] "
8865 $ctext insert end $newid link1
8866 setlink $newid link1
8867 $ctext insert end "\n "
8868 $ctext insert end [lindex $commitinfo($newid) 0]
8869 $ctext insert end "\n"
8870 $ctext conf -state disabled
8871 $ctext tag remove found 1.0 end
8872 startdiff [list $oldid $newid]
8876 global rowmenuid currentid commitinfo patchtop patchnum NS
8878 if {![info exists currentid]} return
8879 set oldid $currentid
8880 set oldhead [lindex $commitinfo($oldid) 0]
8881 set newid $rowmenuid
8882 set newhead [lindex $commitinfo($newid) 0]
8885 catch {destroy $top}
8887 make_transient $top .
8888 ${NS}::label $top.title -text [mc "Generate patch"]
8889 grid $top.title - -pady 10
8890 ${NS}::label $top.from -text [mc "From:"]
8891 ${NS}::entry $top.fromsha1 -width 40
8892 $top.fromsha1 insert 0 $oldid
8893 $top.fromsha1 conf -state readonly
8894 grid $top.from $top.fromsha1 -sticky w
8895 ${NS}::entry $top.fromhead -width 60
8896 $top.fromhead insert 0 $oldhead
8897 $top.fromhead conf -state readonly
8898 grid x $top.fromhead -sticky w
8899 ${NS}::label $top.to -text [mc "To:"]
8900 ${NS}::entry $top.tosha1 -width 40
8901 $top.tosha1 insert 0 $newid
8902 $top.tosha1 conf -state readonly
8903 grid $top.to $top.tosha1 -sticky w
8904 ${NS}::entry $top.tohead -width 60
8905 $top.tohead insert 0 $newhead
8906 $top.tohead conf -state readonly
8907 grid x $top.tohead -sticky w
8908 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
8909 grid $top.rev x -pady 10 -padx 5
8910 ${NS}::label $top.flab -text [mc "Output file:"]
8911 ${NS}::entry $top.fname -width 60
8912 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8914 grid $top.flab $top.fname -sticky w
8915 ${NS}::frame $top.buts
8916 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8917 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8918 bind $top <Key-Return> mkpatchgo
8919 bind $top <Key-Escape> mkpatchcan
8920 grid $top.buts.gen $top.buts.can
8921 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8922 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8923 grid $top.buts - -pady 10 -sticky ew
8927 proc mkpatchrev {} {
8930 set oldid [$patchtop.fromsha1 get]
8931 set oldhead [$patchtop.fromhead get]
8932 set newid [$patchtop.tosha1 get]
8933 set newhead [$patchtop.tohead get]
8934 foreach e [list fromsha1 fromhead tosha1 tohead] \
8935 v [list $newid $newhead $oldid $oldhead] {
8936 $patchtop.$e conf -state normal
8937 $patchtop.$e delete 0 end
8938 $patchtop.$e insert 0 $v
8939 $patchtop.$e conf -state readonly
8944 global patchtop nullid nullid2
8946 set oldid [$patchtop.fromsha1 get]
8947 set newid [$patchtop.tosha1 get]
8948 set fname [$patchtop.fname get]
8949 set cmd [diffcmd [list $oldid $newid] -p]
8950 # trim off the initial "|"
8951 set cmd [lrange $cmd 1 end]
8952 lappend cmd >$fname &
8953 if {[catch {eval exec $cmd} err]} {
8954 error_popup "[mc "Error creating patch:"] $err" $patchtop
8956 catch {destroy $patchtop}
8960 proc mkpatchcan {} {
8963 catch {destroy $patchtop}
8968 global rowmenuid mktagtop commitinfo NS
8972 catch {destroy $top}
8974 make_transient $top .
8975 ${NS}::label $top.title -text [mc "Create tag"]
8976 grid $top.title - -pady 10
8977 ${NS}::label $top.id -text [mc "ID:"]
8978 ${NS}::entry $top.sha1 -width 40
8979 $top.sha1 insert 0 $rowmenuid
8980 $top.sha1 conf -state readonly
8981 grid $top.id $top.sha1 -sticky w
8982 ${NS}::entry $top.head -width 60
8983 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
8984 $top.head conf -state readonly
8985 grid x $top.head -sticky w
8986 ${NS}::label $top.tlab -text [mc "Tag name:"]
8987 ${NS}::entry $top.tag -width 60
8988 grid $top.tlab $top.tag -sticky w
8989 ${NS}::label $top.op -text [mc "Tag message is optional"]
8990 grid $top.op -columnspan 2 -sticky we
8991 ${NS}::label $top.mlab -text [mc "Tag message:"]
8992 ${NS}::entry $top.msg -width 60
8993 grid $top.mlab $top.msg -sticky w
8994 ${NS}::frame $top.buts
8995 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
8996 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
8997 bind $top <Key-Return> mktaggo
8998 bind $top <Key-Escape> mktagcan
8999 grid $top.buts.gen $top.buts.can
9000 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9001 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9002 grid $top.buts - -pady 10 -sticky ew
9007 global mktagtop env tagids idtags
9009 set id [$mktagtop.sha1 get]
9010 set tag [$mktagtop.tag get]
9011 set msg [$mktagtop.msg get]
9013 error_popup [mc "No tag name specified"] $mktagtop
9016 if {[info exists tagids($tag)]} {
9017 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9022 exec git tag -a -m $msg $tag $id
9024 exec git tag $tag $id
9027 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9031 set tagids($tag) $id
9032 lappend idtags($id) $tag
9040 proc redrawtags {id} {
9041 global canv linehtag idpos currentid curview cmitlisted markedid
9042 global canvxmax iddrawn circleitem mainheadid circlecolors
9044 if {![commitinview $id $curview]} return
9045 if {![info exists iddrawn($id)]} return
9046 set row [rowofcommit $id]
9047 if {$id eq $mainheadid} {
9050 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9052 $canv itemconf $circleitem($row) -fill $ofill
9053 $canv delete tag.$id
9054 set xt [eval drawtags $id $idpos($id)]
9055 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9056 set text [$canv itemcget $linehtag($id) -text]
9057 set font [$canv itemcget $linehtag($id) -font]
9058 set xr [expr {$xt + [font measure $font $text]}]
9059 if {$xr > $canvxmax} {
9063 if {[info exists currentid] && $currentid == $id} {
9066 if {[info exists markedid] && $markedid eq $id} {
9074 catch {destroy $mktagtop}
9079 if {![domktag]} return
9083 proc writecommit {} {
9084 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9086 set top .writecommit
9088 catch {destroy $top}
9090 make_transient $top .
9091 ${NS}::label $top.title -text [mc "Write commit to file"]
9092 grid $top.title - -pady 10
9093 ${NS}::label $top.id -text [mc "ID:"]
9094 ${NS}::entry $top.sha1 -width 40
9095 $top.sha1 insert 0 $rowmenuid
9096 $top.sha1 conf -state readonly
9097 grid $top.id $top.sha1 -sticky w
9098 ${NS}::entry $top.head -width 60
9099 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9100 $top.head conf -state readonly
9101 grid x $top.head -sticky w
9102 ${NS}::label $top.clab -text [mc "Command:"]
9103 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9104 grid $top.clab $top.cmd -sticky w -pady 10
9105 ${NS}::label $top.flab -text [mc "Output file:"]
9106 ${NS}::entry $top.fname -width 60
9107 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9108 grid $top.flab $top.fname -sticky w
9109 ${NS}::frame $top.buts
9110 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9111 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9112 bind $top <Key-Return> wrcomgo
9113 bind $top <Key-Escape> wrcomcan
9114 grid $top.buts.gen $top.buts.can
9115 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9116 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9117 grid $top.buts - -pady 10 -sticky ew
9124 set id [$wrcomtop.sha1 get]
9125 set cmd "echo $id | [$wrcomtop.cmd get]"
9126 set fname [$wrcomtop.fname get]
9127 if {[catch {exec sh -c $cmd >$fname &} err]} {
9128 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9130 catch {destroy $wrcomtop}
9137 catch {destroy $wrcomtop}
9142 global rowmenuid mkbrtop NS
9145 catch {destroy $top}
9147 make_transient $top .
9148 ${NS}::label $top.title -text [mc "Create new branch"]
9149 grid $top.title - -pady 10
9150 ${NS}::label $top.id -text [mc "ID:"]
9151 ${NS}::entry $top.sha1 -width 40
9152 $top.sha1 insert 0 $rowmenuid
9153 $top.sha1 conf -state readonly
9154 grid $top.id $top.sha1 -sticky w
9155 ${NS}::label $top.nlab -text [mc "Name:"]
9156 ${NS}::entry $top.name -width 40
9157 grid $top.nlab $top.name -sticky w
9158 ${NS}::frame $top.buts
9159 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9160 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9161 bind $top <Key-Return> [list mkbrgo $top]
9162 bind $top <Key-Escape> "catch {destroy $top}"
9163 grid $top.buts.go $top.buts.can
9164 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9165 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9166 grid $top.buts - -pady 10 -sticky ew
9171 global headids idheads
9173 set name [$top.name get]
9174 set id [$top.sha1 get]
9178 error_popup [mc "Please specify a name for the new branch"] $top
9181 if {[info exists headids($name)]} {
9182 if {![confirm_popup [mc \
9183 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9186 set old_id $headids($name)
9189 catch {destroy $top}
9190 lappend cmdargs $name $id
9194 eval exec git branch $cmdargs
9200 if {$old_id ne {}} {
9206 set headids($name) $id
9207 lappend idheads($id) $name
9216 proc exec_citool {tool_args {baseid {}}} {
9217 global commitinfo env
9219 set save_env [array get env GIT_AUTHOR_*]
9221 if {$baseid ne {}} {
9222 if {![info exists commitinfo($baseid)]} {
9225 set author [lindex $commitinfo($baseid) 1]
9226 set date [lindex $commitinfo($baseid) 2]
9227 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9228 $author author name email]
9230 set env(GIT_AUTHOR_NAME) $name
9231 set env(GIT_AUTHOR_EMAIL) $email
9232 set env(GIT_AUTHOR_DATE) $date
9236 eval exec git citool $tool_args &
9238 array unset env GIT_AUTHOR_*
9239 array set env $save_env
9242 proc cherrypick {} {
9243 global rowmenuid curview
9244 global mainhead mainheadid
9247 set oldhead [exec git rev-parse HEAD]
9248 set dheads [descheads $rowmenuid]
9249 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9250 set ok [confirm_popup [mc "Commit %s is already\
9251 included in branch %s -- really re-apply it?" \
9252 [string range $rowmenuid 0 7] $mainhead]]
9255 nowbusy cherrypick [mc "Cherry-picking"]
9257 # Unfortunately git-cherry-pick writes stuff to stderr even when
9258 # no error occurs, and exec takes that as an indication of error...
9259 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9262 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9264 error_popup [mc "Cherry-pick failed because of local changes\
9265 to file '%s'.\nPlease commit, reset or stash\
9266 your changes and try again." $fname]
9267 } elseif {[regexp -line \
9268 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9270 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9271 conflict.\nDo you wish to run git citool to\
9273 # Force citool to read MERGE_MSG
9274 file delete [file join $gitdir "GITGUI_MSG"]
9275 exec_citool {} $rowmenuid
9283 set newhead [exec git rev-parse HEAD]
9284 if {$newhead eq $oldhead} {
9286 error_popup [mc "No changes committed"]
9289 addnewchild $newhead $oldhead
9290 if {[commitinview $oldhead $curview]} {
9291 # XXX this isn't right if we have a path limit...
9292 insertrow $newhead $oldhead $curview
9293 if {$mainhead ne {}} {
9294 movehead $newhead $mainhead
9295 movedhead $newhead $mainhead
9297 set mainheadid $newhead
9306 global mainhead rowmenuid confirm_ok resettype NS
9309 set w ".confirmreset"
9312 wm title $w [mc "Confirm reset"]
9313 ${NS}::label $w.m -text \
9314 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9315 pack $w.m -side top -fill x -padx 20 -pady 20
9316 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9318 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9319 -text [mc "Soft: Leave working tree and index untouched"]
9320 grid $w.f.soft -sticky w
9321 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9322 -text [mc "Mixed: Leave working tree untouched, reset index"]
9323 grid $w.f.mixed -sticky w
9324 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9325 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9326 grid $w.f.hard -sticky w
9327 pack $w.f -side top -fill x -padx 4
9328 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9329 pack $w.ok -side left -fill x -padx 20 -pady 20
9330 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9331 bind $w <Key-Escape> [list destroy $w]
9332 pack $w.cancel -side right -fill x -padx 20 -pady 20
9333 bind $w <Visibility> "grab $w; focus $w"
9335 if {!$confirm_ok} return
9336 if {[catch {set fd [open \
9337 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9341 filerun $fd [list readresetstat $fd]
9342 nowbusy reset [mc "Resetting"]
9347 proc readresetstat {fd} {
9348 global mainhead mainheadid showlocalchanges rprogcoord
9350 if {[gets $fd line] >= 0} {
9351 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9352 set rprogcoord [expr {1.0 * $m / $n}]
9360 if {[catch {close $fd} err]} {
9363 set oldhead $mainheadid
9364 set newhead [exec git rev-parse HEAD]
9365 if {$newhead ne $oldhead} {
9366 movehead $newhead $mainhead
9367 movedhead $newhead $mainhead
9368 set mainheadid $newhead
9372 if {$showlocalchanges} {
9378 # context menu for a head
9379 proc headmenu {x y id head} {
9380 global headmenuid headmenuhead headctxmenu mainhead
9384 set headmenuhead $head
9386 if {[string match "remotes/*" $head]} {
9389 if {$head eq $mainhead} {
9392 $headctxmenu entryconfigure 0 -state $state
9393 $headctxmenu entryconfigure 1 -state $state
9394 tk_popup $headctxmenu $x $y
9398 global headmenuid headmenuhead headids
9399 global showlocalchanges
9401 # check the tree is clean first??
9402 nowbusy checkout [mc "Checking out"]
9406 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9410 if {$showlocalchanges} {
9414 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9418 proc readcheckoutstat {fd newhead newheadid} {
9419 global mainhead mainheadid headids showlocalchanges progresscoords
9420 global viewmainheadid curview
9422 if {[gets $fd line] >= 0} {
9423 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9424 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9429 set progresscoords {0 0}
9432 if {[catch {close $fd} err]} {
9435 set oldmainid $mainheadid
9436 set mainhead $newhead
9437 set mainheadid $newheadid
9438 set viewmainheadid($curview) $newheadid
9439 redrawtags $oldmainid
9440 redrawtags $newheadid
9442 if {$showlocalchanges} {
9448 global headmenuid headmenuhead mainhead
9451 set head $headmenuhead
9453 # this check shouldn't be needed any more...
9454 if {$head eq $mainhead} {
9455 error_popup [mc "Cannot delete the currently checked-out branch"]
9458 set dheads [descheads $id]
9459 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9460 # the stuff on this branch isn't on any other branch
9461 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9462 branch.\nReally delete branch %s?" $head $head]]} return
9466 if {[catch {exec git branch -D $head} err]} {
9471 removehead $id $head
9472 removedhead $id $head
9479 # Display a list of tags and heads
9481 global showrefstop bgcolor fgcolor selectbgcolor NS
9482 global bglist fglist reflistfilter reflist maincursor
9485 set showrefstop $top
9486 if {[winfo exists $top]} {
9492 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9493 make_transient $top .
9494 text $top.list -background $bgcolor -foreground $fgcolor \
9495 -selectbackground $selectbgcolor -font mainfont \
9496 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9497 -width 30 -height 20 -cursor $maincursor \
9498 -spacing1 1 -spacing3 1 -state disabled
9499 $top.list tag configure highlight -background $selectbgcolor
9500 lappend bglist $top.list
9501 lappend fglist $top.list
9502 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9503 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9504 grid $top.list $top.ysb -sticky nsew
9505 grid $top.xsb x -sticky ew
9507 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9508 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9509 set reflistfilter "*"
9510 trace add variable reflistfilter write reflistfilter_change
9511 pack $top.f.e -side right -fill x -expand 1
9512 pack $top.f.l -side left
9513 grid $top.f - -sticky ew -pady 2
9514 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9515 bind $top <Key-Escape> [list destroy $top]
9517 grid columnconfigure $top 0 -weight 1
9518 grid rowconfigure $top 0 -weight 1
9519 bind $top.list <1> {break}
9520 bind $top.list <B1-Motion> {break}
9521 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9526 proc sel_reflist {w x y} {
9527 global showrefstop reflist headids tagids otherrefids
9529 if {![winfo exists $showrefstop]} return
9530 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9531 set ref [lindex $reflist [expr {$l-1}]]
9532 set n [lindex $ref 0]
9533 switch -- [lindex $ref 1] {
9534 "H" {selbyid $headids($n)}
9535 "T" {selbyid $tagids($n)}
9536 "o" {selbyid $otherrefids($n)}
9538 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9541 proc unsel_reflist {} {
9544 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9545 $showrefstop.list tag remove highlight 0.0 end
9548 proc reflistfilter_change {n1 n2 op} {
9549 global reflistfilter
9551 after cancel refill_reflist
9552 after 200 refill_reflist
9555 proc refill_reflist {} {
9556 global reflist reflistfilter showrefstop headids tagids otherrefids
9559 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9561 foreach n [array names headids] {
9562 if {[string match $reflistfilter $n]} {
9563 if {[commitinview $headids($n) $curview]} {
9564 lappend refs [list $n H]
9566 interestedin $headids($n) {run refill_reflist}
9570 foreach n [array names tagids] {
9571 if {[string match $reflistfilter $n]} {
9572 if {[commitinview $tagids($n) $curview]} {
9573 lappend refs [list $n T]
9575 interestedin $tagids($n) {run refill_reflist}
9579 foreach n [array names otherrefids] {
9580 if {[string match $reflistfilter $n]} {
9581 if {[commitinview $otherrefids($n) $curview]} {
9582 lappend refs [list $n o]
9584 interestedin $otherrefids($n) {run refill_reflist}
9588 set refs [lsort -index 0 $refs]
9589 if {$refs eq $reflist} return
9591 # Update the contents of $showrefstop.list according to the
9592 # differences between $reflist (old) and $refs (new)
9593 $showrefstop.list conf -state normal
9594 $showrefstop.list insert end "\n"
9597 while {$i < [llength $reflist] || $j < [llength $refs]} {
9598 if {$i < [llength $reflist]} {
9599 if {$j < [llength $refs]} {
9600 set cmp [string compare [lindex $reflist $i 0] \
9601 [lindex $refs $j 0]]
9603 set cmp [string compare [lindex $reflist $i 1] \
9604 [lindex $refs $j 1]]
9614 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9622 set l [expr {$j + 1}]
9623 $showrefstop.list image create $l.0 -align baseline \
9624 -image reficon-[lindex $refs $j 1] -padx 2
9625 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9631 # delete last newline
9632 $showrefstop.list delete end-2c end-1c
9633 $showrefstop.list conf -state disabled
9636 # Stuff for finding nearby tags
9637 proc getallcommits {} {
9638 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9639 global idheads idtags idotherrefs allparents tagobjid
9642 if {![info exists allcommits]} {
9648 set allccache [file join $gitdir "gitk.cache"]
9650 set f [open $allccache r]
9659 set cmd [list | git rev-list --parents]
9660 set allcupdate [expr {$seeds ne {}}]
9664 set refs [concat [array names idheads] [array names idtags] \
9665 [array names idotherrefs]]
9668 foreach name [array names tagobjid] {
9669 lappend tagobjs $tagobjid($name)
9671 foreach id [lsort -unique $refs] {
9672 if {![info exists allparents($id)] &&
9673 [lsearch -exact $tagobjs $id] < 0} {
9684 set fd [open [concat $cmd $ids] r]
9685 fconfigure $fd -blocking 0
9688 filerun $fd [list getallclines $fd]
9694 # Since most commits have 1 parent and 1 child, we group strings of
9695 # such commits into "arcs" joining branch/merge points (BMPs), which
9696 # are commits that either don't have 1 parent or don't have 1 child.
9698 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9699 # arcout(id) - outgoing arcs for BMP
9700 # arcids(a) - list of IDs on arc including end but not start
9701 # arcstart(a) - BMP ID at start of arc
9702 # arcend(a) - BMP ID at end of arc
9703 # growing(a) - arc a is still growing
9704 # arctags(a) - IDs out of arcids (excluding end) that have tags
9705 # archeads(a) - IDs out of arcids (excluding end) that have heads
9706 # The start of an arc is at the descendent end, so "incoming" means
9707 # coming from descendents, and "outgoing" means going towards ancestors.
9709 proc getallclines {fd} {
9710 global allparents allchildren idtags idheads nextarc
9711 global arcnos arcids arctags arcout arcend arcstart archeads growing
9712 global seeds allcommits cachedarcs allcupdate
9715 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9716 set id [lindex $line 0]
9717 if {[info exists allparents($id)]} {
9722 set olds [lrange $line 1 end]
9723 set allparents($id) $olds
9724 if {![info exists allchildren($id)]} {
9725 set allchildren($id) {}
9730 if {[llength $olds] == 1 && [llength $a] == 1} {
9731 lappend arcids($a) $id
9732 if {[info exists idtags($id)]} {
9733 lappend arctags($a) $id
9735 if {[info exists idheads($id)]} {
9736 lappend archeads($a) $id
9738 if {[info exists allparents($olds)]} {
9739 # seen parent already
9740 if {![info exists arcout($olds)]} {
9743 lappend arcids($a) $olds
9744 set arcend($a) $olds
9747 lappend allchildren($olds) $id
9748 lappend arcnos($olds) $a
9752 foreach a $arcnos($id) {
9753 lappend arcids($a) $id
9760 lappend allchildren($p) $id
9761 set a [incr nextarc]
9762 set arcstart($a) $id
9769 if {[info exists allparents($p)]} {
9770 # seen it already, may need to make a new branch
9771 if {![info exists arcout($p)]} {
9774 lappend arcids($a) $p
9778 lappend arcnos($p) $a
9783 global cached_dheads cached_dtags cached_atags
9784 catch {unset cached_dheads}
9785 catch {unset cached_dtags}
9786 catch {unset cached_atags}
9789 return [expr {$nid >= 1000? 2: 1}]
9793 fconfigure $fd -blocking 1
9796 # got an error reading the list of commits
9797 # if we were updating, try rereading the whole thing again
9803 error_popup "[mc "Error reading commit topology information;\
9804 branch and preceding/following tag information\
9805 will be incomplete."]\n($err)"
9808 if {[incr allcommits -1] == 0} {
9818 proc recalcarc {a} {
9819 global arctags archeads arcids idtags idheads
9823 foreach id [lrange $arcids($a) 0 end-1] {
9824 if {[info exists idtags($id)]} {
9827 if {[info exists idheads($id)]} {
9832 set archeads($a) $ah
9836 global arcnos arcids nextarc arctags archeads idtags idheads
9837 global arcstart arcend arcout allparents growing
9840 if {[llength $a] != 1} {
9841 puts "oops splitarc called but [llength $a] arcs already"
9845 set i [lsearch -exact $arcids($a) $p]
9847 puts "oops splitarc $p not in arc $a"
9850 set na [incr nextarc]
9851 if {[info exists arcend($a)]} {
9852 set arcend($na) $arcend($a)
9854 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9855 set j [lsearch -exact $arcnos($l) $a]
9856 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9858 set tail [lrange $arcids($a) [expr {$i+1}] end]
9859 set arcids($a) [lrange $arcids($a) 0 $i]
9861 set arcstart($na) $p
9863 set arcids($na) $tail
9864 if {[info exists growing($a)]} {
9870 if {[llength $arcnos($id)] == 1} {
9873 set j [lsearch -exact $arcnos($id) $a]
9874 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9878 # reconstruct tags and heads lists
9879 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9884 set archeads($na) {}
9888 # Update things for a new commit added that is a child of one
9889 # existing commit. Used when cherry-picking.
9890 proc addnewchild {id p} {
9891 global allparents allchildren idtags nextarc
9892 global arcnos arcids arctags arcout arcend arcstart archeads growing
9893 global seeds allcommits
9895 if {![info exists allcommits] || ![info exists arcnos($p)]} return
9896 set allparents($id) [list $p]
9897 set allchildren($id) {}
9900 lappend allchildren($p) $id
9901 set a [incr nextarc]
9902 set arcstart($a) $id
9905 set arcids($a) [list $p]
9907 if {![info exists arcout($p)]} {
9910 lappend arcnos($p) $a
9911 set arcout($id) [list $a]
9914 # This implements a cache for the topology information.
9915 # The cache saves, for each arc, the start and end of the arc,
9916 # the ids on the arc, and the outgoing arcs from the end.
9917 proc readcache {f} {
9918 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
9919 global idtags idheads allparents cachedarcs possible_seeds seeds growing
9924 if {$lim - $a > 500} {
9925 set lim [expr {$a + 500}]
9929 # finish reading the cache and setting up arctags, etc.
9931 if {$line ne "1"} {error "bad final version"}
9933 foreach id [array names idtags] {
9934 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9935 [llength $allparents($id)] == 1} {
9936 set a [lindex $arcnos($id) 0]
9937 if {$arctags($a) eq {}} {
9942 foreach id [array names idheads] {
9943 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
9944 [llength $allparents($id)] == 1} {
9945 set a [lindex $arcnos($id) 0]
9946 if {$archeads($a) eq {}} {
9951 foreach id [lsort -unique $possible_seeds] {
9952 if {$arcnos($id) eq {}} {
9958 while {[incr a] <= $lim} {
9960 if {[llength $line] != 3} {error "bad line"}
9961 set s [lindex $line 0]
9963 lappend arcout($s) $a
9964 if {![info exists arcnos($s)]} {
9965 lappend possible_seeds $s
9968 set e [lindex $line 1]
9973 if {![info exists arcout($e)]} {
9977 set arcids($a) [lindex $line 2]
9978 foreach id $arcids($a) {
9979 lappend allparents($s) $id
9981 lappend arcnos($id) $a
9983 if {![info exists allparents($s)]} {
9984 set allparents($s) {}
9989 set nextarc [expr {$a - 1}]
10001 proc getcache {f} {
10002 global nextarc cachedarcs possible_seeds
10006 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10007 # make sure it's an integer
10008 set cachedarcs [expr {int([lindex $line 1])}]
10009 if {$cachedarcs < 0} {error "bad number of arcs"}
10011 set possible_seeds {}
10019 proc dropcache {err} {
10020 global allcwait nextarc cachedarcs seeds
10022 #puts "dropping cache ($err)"
10023 foreach v {arcnos arcout arcids arcstart arcend growing \
10024 arctags archeads allparents allchildren} {
10035 proc writecache {f} {
10036 global cachearc cachedarcs allccache
10037 global arcstart arcend arcnos arcids arcout
10040 set lim $cachedarcs
10041 if {$lim - $a > 1000} {
10042 set lim [expr {$a + 1000}]
10045 while {[incr a] <= $lim} {
10046 if {[info exists arcend($a)]} {
10047 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10049 puts $f [list $arcstart($a) {} $arcids($a)]
10054 catch {file delete $allccache}
10055 #puts "writing cache failed ($err)"
10058 set cachearc [expr {$a - 1}]
10059 if {$a > $cachedarcs} {
10067 proc savecache {} {
10068 global nextarc cachedarcs cachearc allccache
10070 if {$nextarc == $cachedarcs} return
10072 set cachedarcs $nextarc
10074 set f [open $allccache w]
10075 puts $f [list 1 $cachedarcs]
10080 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10081 # or 0 if neither is true.
10082 proc anc_or_desc {a b} {
10083 global arcout arcstart arcend arcnos cached_isanc
10085 if {$arcnos($a) eq $arcnos($b)} {
10086 # Both are on the same arc(s); either both are the same BMP,
10087 # or if one is not a BMP, the other is also not a BMP or is
10088 # the BMP at end of the arc (and it only has 1 incoming arc).
10089 # Or both can be BMPs with no incoming arcs.
10090 if {$a eq $b || $arcnos($a) eq {}} {
10093 # assert {[llength $arcnos($a)] == 1}
10094 set arc [lindex $arcnos($a) 0]
10095 set i [lsearch -exact $arcids($arc) $a]
10096 set j [lsearch -exact $arcids($arc) $b]
10097 if {$i < 0 || $i > $j} {
10104 if {![info exists arcout($a)]} {
10105 set arc [lindex $arcnos($a) 0]
10106 if {[info exists arcend($arc)]} {
10107 set aend $arcend($arc)
10111 set a $arcstart($arc)
10115 if {![info exists arcout($b)]} {
10116 set arc [lindex $arcnos($b) 0]
10117 if {[info exists arcend($arc)]} {
10118 set bend $arcend($arc)
10122 set b $arcstart($arc)
10132 if {[info exists cached_isanc($a,$bend)]} {
10133 if {$cached_isanc($a,$bend)} {
10137 if {[info exists cached_isanc($b,$aend)]} {
10138 if {$cached_isanc($b,$aend)} {
10141 if {[info exists cached_isanc($a,$bend)]} {
10146 set todo [list $a $b]
10149 for {set i 0} {$i < [llength $todo]} {incr i} {
10150 set x [lindex $todo $i]
10151 if {$anc($x) eq {}} {
10154 foreach arc $arcnos($x) {
10155 set xd $arcstart($arc)
10156 if {$xd eq $bend} {
10157 set cached_isanc($a,$bend) 1
10158 set cached_isanc($b,$aend) 0
10160 } elseif {$xd eq $aend} {
10161 set cached_isanc($b,$aend) 1
10162 set cached_isanc($a,$bend) 0
10165 if {![info exists anc($xd)]} {
10166 set anc($xd) $anc($x)
10168 } elseif {$anc($xd) ne $anc($x)} {
10173 set cached_isanc($a,$bend) 0
10174 set cached_isanc($b,$aend) 0
10178 # This identifies whether $desc has an ancestor that is
10179 # a growing tip of the graph and which is not an ancestor of $anc
10180 # and returns 0 if so and 1 if not.
10181 # If we subsequently discover a tag on such a growing tip, and that
10182 # turns out to be a descendent of $anc (which it could, since we
10183 # don't necessarily see children before parents), then $desc
10184 # isn't a good choice to display as a descendent tag of
10185 # $anc (since it is the descendent of another tag which is
10186 # a descendent of $anc). Similarly, $anc isn't a good choice to
10187 # display as a ancestor tag of $desc.
10189 proc is_certain {desc anc} {
10190 global arcnos arcout arcstart arcend growing problems
10193 if {[llength $arcnos($anc)] == 1} {
10194 # tags on the same arc are certain
10195 if {$arcnos($desc) eq $arcnos($anc)} {
10198 if {![info exists arcout($anc)]} {
10199 # if $anc is partway along an arc, use the start of the arc instead
10200 set a [lindex $arcnos($anc) 0]
10201 set anc $arcstart($a)
10204 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10207 set a [lindex $arcnos($desc) 0]
10213 set anclist [list $x]
10217 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10218 set x [lindex $anclist $i]
10223 foreach a $arcout($x) {
10224 if {[info exists growing($a)]} {
10225 if {![info exists growanc($x)] && $dl($x)} {
10231 if {[info exists dl($y)]} {
10235 if {![info exists done($y)]} {
10238 if {[info exists growanc($x)]} {
10242 for {set k 0} {$k < [llength $xl]} {incr k} {
10243 set z [lindex $xl $k]
10244 foreach c $arcout($z) {
10245 if {[info exists arcend($c)]} {
10247 if {[info exists dl($v)] && $dl($v)} {
10249 if {![info exists done($v)]} {
10252 if {[info exists growanc($v)]} {
10262 } elseif {$y eq $anc || !$dl($x)} {
10273 foreach x [array names growanc] {
10282 proc validate_arctags {a} {
10283 global arctags idtags
10286 set na $arctags($a)
10287 foreach id $arctags($a) {
10289 if {![info exists idtags($id)]} {
10290 set na [lreplace $na $i $i]
10294 set arctags($a) $na
10297 proc validate_archeads {a} {
10298 global archeads idheads
10301 set na $archeads($a)
10302 foreach id $archeads($a) {
10304 if {![info exists idheads($id)]} {
10305 set na [lreplace $na $i $i]
10309 set archeads($a) $na
10312 # Return the list of IDs that have tags that are descendents of id,
10313 # ignoring IDs that are descendents of IDs already reported.
10314 proc desctags {id} {
10315 global arcnos arcstart arcids arctags idtags allparents
10316 global growing cached_dtags
10318 if {![info exists allparents($id)]} {
10321 set t1 [clock clicks -milliseconds]
10323 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10324 # part-way along an arc; check that arc first
10325 set a [lindex $arcnos($id) 0]
10326 if {$arctags($a) ne {}} {
10327 validate_arctags $a
10328 set i [lsearch -exact $arcids($a) $id]
10330 foreach t $arctags($a) {
10331 set j [lsearch -exact $arcids($a) $t]
10332 if {$j >= $i} break
10339 set id $arcstart($a)
10340 if {[info exists idtags($id)]} {
10344 if {[info exists cached_dtags($id)]} {
10345 return $cached_dtags($id)
10349 set todo [list $id]
10352 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10353 set id [lindex $todo $i]
10355 set ta [info exists hastaggedancestor($id)]
10359 # ignore tags on starting node
10360 if {!$ta && $i > 0} {
10361 if {[info exists idtags($id)]} {
10362 set tagloc($id) $id
10364 } elseif {[info exists cached_dtags($id)]} {
10365 set tagloc($id) $cached_dtags($id)
10369 foreach a $arcnos($id) {
10370 set d $arcstart($a)
10371 if {!$ta && $arctags($a) ne {}} {
10372 validate_arctags $a
10373 if {$arctags($a) ne {}} {
10374 lappend tagloc($id) [lindex $arctags($a) end]
10377 if {$ta || $arctags($a) ne {}} {
10378 set tomark [list $d]
10379 for {set j 0} {$j < [llength $tomark]} {incr j} {
10380 set dd [lindex $tomark $j]
10381 if {![info exists hastaggedancestor($dd)]} {
10382 if {[info exists done($dd)]} {
10383 foreach b $arcnos($dd) {
10384 lappend tomark $arcstart($b)
10386 if {[info exists tagloc($dd)]} {
10389 } elseif {[info exists queued($dd)]} {
10392 set hastaggedancestor($dd) 1
10396 if {![info exists queued($d)]} {
10399 if {![info exists hastaggedancestor($d)]} {
10406 foreach id [array names tagloc] {
10407 if {![info exists hastaggedancestor($id)]} {
10408 foreach t $tagloc($id) {
10409 if {[lsearch -exact $tags $t] < 0} {
10415 set t2 [clock clicks -milliseconds]
10418 # remove tags that are descendents of other tags
10419 for {set i 0} {$i < [llength $tags]} {incr i} {
10420 set a [lindex $tags $i]
10421 for {set j 0} {$j < $i} {incr j} {
10422 set b [lindex $tags $j]
10423 set r [anc_or_desc $a $b]
10425 set tags [lreplace $tags $j $j]
10428 } elseif {$r == -1} {
10429 set tags [lreplace $tags $i $i]
10436 if {[array names growing] ne {}} {
10437 # graph isn't finished, need to check if any tag could get
10438 # eclipsed by another tag coming later. Simply ignore any
10439 # tags that could later get eclipsed.
10442 if {[is_certain $t $origid]} {
10446 if {$tags eq $ctags} {
10447 set cached_dtags($origid) $tags
10452 set cached_dtags($origid) $tags
10454 set t3 [clock clicks -milliseconds]
10455 if {0 && $t3 - $t1 >= 100} {
10456 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10457 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10462 proc anctags {id} {
10463 global arcnos arcids arcout arcend arctags idtags allparents
10464 global growing cached_atags
10466 if {![info exists allparents($id)]} {
10469 set t1 [clock clicks -milliseconds]
10471 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10472 # part-way along an arc; check that arc first
10473 set a [lindex $arcnos($id) 0]
10474 if {$arctags($a) ne {}} {
10475 validate_arctags $a
10476 set i [lsearch -exact $arcids($a) $id]
10477 foreach t $arctags($a) {
10478 set j [lsearch -exact $arcids($a) $t]
10484 if {![info exists arcend($a)]} {
10488 if {[info exists idtags($id)]} {
10492 if {[info exists cached_atags($id)]} {
10493 return $cached_atags($id)
10497 set todo [list $id]
10501 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10502 set id [lindex $todo $i]
10504 set td [info exists hastaggeddescendent($id)]
10508 # ignore tags on starting node
10509 if {!$td && $i > 0} {
10510 if {[info exists idtags($id)]} {
10511 set tagloc($id) $id
10513 } elseif {[info exists cached_atags($id)]} {
10514 set tagloc($id) $cached_atags($id)
10518 foreach a $arcout($id) {
10519 if {!$td && $arctags($a) ne {}} {
10520 validate_arctags $a
10521 if {$arctags($a) ne {}} {
10522 lappend tagloc($id) [lindex $arctags($a) 0]
10525 if {![info exists arcend($a)]} continue
10527 if {$td || $arctags($a) ne {}} {
10528 set tomark [list $d]
10529 for {set j 0} {$j < [llength $tomark]} {incr j} {
10530 set dd [lindex $tomark $j]
10531 if {![info exists hastaggeddescendent($dd)]} {
10532 if {[info exists done($dd)]} {
10533 foreach b $arcout($dd) {
10534 if {[info exists arcend($b)]} {
10535 lappend tomark $arcend($b)
10538 if {[info exists tagloc($dd)]} {
10541 } elseif {[info exists queued($dd)]} {
10544 set hastaggeddescendent($dd) 1
10548 if {![info exists queued($d)]} {
10551 if {![info exists hastaggeddescendent($d)]} {
10557 set t2 [clock clicks -milliseconds]
10560 foreach id [array names tagloc] {
10561 if {![info exists hastaggeddescendent($id)]} {
10562 foreach t $tagloc($id) {
10563 if {[lsearch -exact $tags $t] < 0} {
10570 # remove tags that are ancestors of other tags
10571 for {set i 0} {$i < [llength $tags]} {incr i} {
10572 set a [lindex $tags $i]
10573 for {set j 0} {$j < $i} {incr j} {
10574 set b [lindex $tags $j]
10575 set r [anc_or_desc $a $b]
10577 set tags [lreplace $tags $j $j]
10580 } elseif {$r == 1} {
10581 set tags [lreplace $tags $i $i]
10588 if {[array names growing] ne {}} {
10589 # graph isn't finished, need to check if any tag could get
10590 # eclipsed by another tag coming later. Simply ignore any
10591 # tags that could later get eclipsed.
10594 if {[is_certain $origid $t]} {
10598 if {$tags eq $ctags} {
10599 set cached_atags($origid) $tags
10604 set cached_atags($origid) $tags
10606 set t3 [clock clicks -milliseconds]
10607 if {0 && $t3 - $t1 >= 100} {
10608 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10609 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10614 # Return the list of IDs that have heads that are descendents of id,
10615 # including id itself if it has a head.
10616 proc descheads {id} {
10617 global arcnos arcstart arcids archeads idheads cached_dheads
10618 global allparents arcout
10620 if {![info exists allparents($id)]} {
10624 if {![info exists arcout($id)]} {
10625 # part-way along an arc; check it first
10626 set a [lindex $arcnos($id) 0]
10627 if {$archeads($a) ne {}} {
10628 validate_archeads $a
10629 set i [lsearch -exact $arcids($a) $id]
10630 foreach t $archeads($a) {
10631 set j [lsearch -exact $arcids($a) $t]
10636 set id $arcstart($a)
10639 set todo [list $id]
10642 for {set i 0} {$i < [llength $todo]} {incr i} {
10643 set id [lindex $todo $i]
10644 if {[info exists cached_dheads($id)]} {
10645 set ret [concat $ret $cached_dheads($id)]
10647 if {[info exists idheads($id)]} {
10650 foreach a $arcnos($id) {
10651 if {$archeads($a) ne {}} {
10652 validate_archeads $a
10653 if {$archeads($a) ne {}} {
10654 set ret [concat $ret $archeads($a)]
10657 set d $arcstart($a)
10658 if {![info exists seen($d)]} {
10665 set ret [lsort -unique $ret]
10666 set cached_dheads($origid) $ret
10667 return [concat $ret $aret]
10670 proc addedtag {id} {
10671 global arcnos arcout cached_dtags cached_atags
10673 if {![info exists arcnos($id)]} return
10674 if {![info exists arcout($id)]} {
10675 recalcarc [lindex $arcnos($id) 0]
10677 catch {unset cached_dtags}
10678 catch {unset cached_atags}
10681 proc addedhead {hid head} {
10682 global arcnos arcout cached_dheads
10684 if {![info exists arcnos($hid)]} return
10685 if {![info exists arcout($hid)]} {
10686 recalcarc [lindex $arcnos($hid) 0]
10688 catch {unset cached_dheads}
10691 proc removedhead {hid head} {
10692 global cached_dheads
10694 catch {unset cached_dheads}
10697 proc movedhead {hid head} {
10698 global arcnos arcout cached_dheads
10700 if {![info exists arcnos($hid)]} return
10701 if {![info exists arcout($hid)]} {
10702 recalcarc [lindex $arcnos($hid) 0]
10704 catch {unset cached_dheads}
10707 proc changedrefs {} {
10708 global cached_dheads cached_dtags cached_atags cached_tagcontent
10709 global arctags archeads arcnos arcout idheads idtags
10711 foreach id [concat [array names idheads] [array names idtags]] {
10712 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10713 set a [lindex $arcnos($id) 0]
10714 if {![info exists donearc($a)]} {
10720 catch {unset cached_tagcontent}
10721 catch {unset cached_dtags}
10722 catch {unset cached_atags}
10723 catch {unset cached_dheads}
10726 proc rereadrefs {} {
10727 global idtags idheads idotherrefs mainheadid
10729 set refids [concat [array names idtags] \
10730 [array names idheads] [array names idotherrefs]]
10731 foreach id $refids {
10732 if {![info exists ref($id)]} {
10733 set ref($id) [listrefs $id]
10736 set oldmainhead $mainheadid
10739 set refids [lsort -unique [concat $refids [array names idtags] \
10740 [array names idheads] [array names idotherrefs]]]
10741 foreach id $refids {
10742 set v [listrefs $id]
10743 if {![info exists ref($id)] || $ref($id) != $v} {
10747 if {$oldmainhead ne $mainheadid} {
10748 redrawtags $oldmainhead
10749 redrawtags $mainheadid
10754 proc listrefs {id} {
10755 global idtags idheads idotherrefs
10758 if {[info exists idtags($id)]} {
10762 if {[info exists idheads($id)]} {
10763 set y $idheads($id)
10766 if {[info exists idotherrefs($id)]} {
10767 set z $idotherrefs($id)
10769 return [list $x $y $z]
10772 proc showtag {tag isnew} {
10773 global ctext cached_tagcontent tagids linknum tagobjid
10776 addtohistory [list showtag $tag 0] savectextpos
10778 $ctext conf -state normal
10782 if {![info exists cached_tagcontent($tag)]} {
10784 set cached_tagcontent($tag) [exec git cat-file tag $tag]
10787 if {[info exists cached_tagcontent($tag)]} {
10788 set text $cached_tagcontent($tag)
10790 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10792 appendwithlinks $text {}
10793 maybe_scroll_ctext 1
10794 $ctext conf -state disabled
10806 if {[info exists gitktmpdir]} {
10807 catch {file delete -force $gitktmpdir}
10811 proc mkfontdisp {font top which} {
10812 global fontattr fontpref $font NS use_ttk
10814 set fontpref($font) [set $font]
10815 ${NS}::button $top.${font}but -text $which \
10816 -command [list choosefont $font $which]
10817 ${NS}::label $top.$font -relief flat -font $font \
10818 -text $fontattr($font,family) -justify left
10819 grid x $top.${font}but $top.$font -sticky w
10822 proc choosefont {font which} {
10823 global fontparam fontlist fonttop fontattr
10826 set fontparam(which) $which
10827 set fontparam(font) $font
10828 set fontparam(family) [font actual $font -family]
10829 set fontparam(size) $fontattr($font,size)
10830 set fontparam(weight) $fontattr($font,weight)
10831 set fontparam(slant) $fontattr($font,slant)
10834 if {![winfo exists $top]} {
10836 eval font config sample [font actual $font]
10838 make_transient $top $prefstop
10839 wm title $top [mc "Gitk font chooser"]
10840 ${NS}::label $top.l -textvariable fontparam(which)
10841 pack $top.l -side top
10842 set fontlist [lsort [font families]]
10843 ${NS}::frame $top.f
10844 listbox $top.f.fam -listvariable fontlist \
10845 -yscrollcommand [list $top.f.sb set]
10846 bind $top.f.fam <<ListboxSelect>> selfontfam
10847 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10848 pack $top.f.sb -side right -fill y
10849 pack $top.f.fam -side left -fill both -expand 1
10850 pack $top.f -side top -fill both -expand 1
10851 ${NS}::frame $top.g
10852 spinbox $top.g.size -from 4 -to 40 -width 4 \
10853 -textvariable fontparam(size) \
10854 -validatecommand {string is integer -strict %s}
10855 checkbutton $top.g.bold -padx 5 \
10856 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10857 -variable fontparam(weight) -onvalue bold -offvalue normal
10858 checkbutton $top.g.ital -padx 5 \
10859 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10860 -variable fontparam(slant) -onvalue italic -offvalue roman
10861 pack $top.g.size $top.g.bold $top.g.ital -side left
10862 pack $top.g -side top
10863 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10865 $top.c create text 100 25 -anchor center -text $which -font sample \
10866 -fill black -tags text
10867 bind $top.c <Configure> [list centertext $top.c]
10868 pack $top.c -side top -fill x
10869 ${NS}::frame $top.buts
10870 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10871 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10872 bind $top <Key-Return> fontok
10873 bind $top <Key-Escape> fontcan
10874 grid $top.buts.ok $top.buts.can
10875 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10876 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10877 pack $top.buts -side bottom -fill x
10878 trace add variable fontparam write chg_fontparam
10881 $top.c itemconf text -text $which
10883 set i [lsearch -exact $fontlist $fontparam(family)]
10885 $top.f.fam selection set $i
10890 proc centertext {w} {
10891 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
10895 global fontparam fontpref prefstop
10897 set f $fontparam(font)
10898 set fontpref($f) [list $fontparam(family) $fontparam(size)]
10899 if {$fontparam(weight) eq "bold"} {
10900 lappend fontpref($f) "bold"
10902 if {$fontparam(slant) eq "italic"} {
10903 lappend fontpref($f) "italic"
10905 set w $prefstop.notebook.fonts.$f
10906 $w conf -text $fontparam(family) -font $fontpref($f)
10912 global fonttop fontparam
10914 if {[info exists fonttop]} {
10915 catch {destroy $fonttop}
10916 catch {font delete sample}
10922 if {[package vsatisfies [package provide Tk] 8.6]} {
10923 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
10924 # function to make use of it.
10925 proc choosefont {font which} {
10926 tk fontchooser configure -title $which -font $font \
10927 -command [list on_choosefont $font $which]
10928 tk fontchooser show
10930 proc on_choosefont {font which newfont} {
10932 puts stderr "$font $newfont"
10933 array set f [font actual $newfont]
10934 set fontparam(which) $which
10935 set fontparam(font) $font
10936 set fontparam(family) $f(-family)
10937 set fontparam(size) $f(-size)
10938 set fontparam(weight) $f(-weight)
10939 set fontparam(slant) $f(-slant)
10944 proc selfontfam {} {
10945 global fonttop fontparam
10947 set i [$fonttop.f.fam curselection]
10949 set fontparam(family) [$fonttop.f.fam get $i]
10953 proc chg_fontparam {v sub op} {
10956 font config sample -$sub $fontparam($sub)
10959 # Create a property sheet tab page
10960 proc create_prefs_page {w} {
10962 set parent [join [lrange [split $w .] 0 end-1] .]
10963 if {[winfo class $parent] eq "TNotebook"} {
10966 ${NS}::labelframe $w
10970 proc prefspage_general {notebook} {
10971 global NS maxwidth maxgraphpct showneartags showlocalchanges
10972 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
10973 global hideremotes want_ttk have_ttk maxrefs
10975 set page [create_prefs_page $notebook.general]
10977 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
10978 grid $page.ldisp - -sticky w -pady 10
10979 ${NS}::label $page.spacer -text " "
10980 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
10981 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
10982 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
10983 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
10984 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
10985 grid x $page.maxpctl $page.maxpct -sticky w
10986 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
10987 -variable showlocalchanges
10988 grid x $page.showlocal -sticky w
10989 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
10990 -variable autoselect
10991 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
10992 grid x $page.autoselect $page.autosellen -sticky w
10993 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
10994 -variable hideremotes
10995 grid x $page.hideremotes -sticky w
10997 ${NS}::label $page.ddisp -text [mc "Diff display options"]
10998 grid $page.ddisp - -sticky w -pady 10
10999 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11000 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11001 grid x $page.tabstopl $page.tabstop -sticky w
11002 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11003 -variable showneartags
11004 grid x $page.ntag -sticky w
11005 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11006 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11007 grid x $page.maxrefsl $page.maxrefs -sticky w
11008 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11009 -variable limitdiffs
11010 grid x $page.ldiff -sticky w
11011 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11012 -variable perfile_attrs
11013 grid x $page.lattr -sticky w
11015 ${NS}::entry $page.extdifft -textvariable extdifftool
11016 ${NS}::frame $page.extdifff
11017 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11018 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11019 pack $page.extdifff.l $page.extdifff.b -side left
11020 pack configure $page.extdifff.l -padx 10
11021 grid x $page.extdifff $page.extdifft -sticky ew
11023 ${NS}::label $page.lgen -text [mc "General options"]
11024 grid $page.lgen - -sticky w -pady 10
11025 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11026 -text [mc "Use themed widgets"]
11028 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11030 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11032 grid x $page.want_ttk $page.ttk_note -sticky w
11036 proc prefspage_colors {notebook} {
11037 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11039 set page [create_prefs_page $notebook.colors]
11041 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11042 grid $page.cdisp - -sticky w -pady 10
11043 label $page.ui -padx 40 -relief sunk -background $uicolor
11044 ${NS}::button $page.uibut -text [mc "Interface"] \
11045 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11046 grid x $page.uibut $page.ui -sticky w
11047 label $page.bg -padx 40 -relief sunk -background $bgcolor
11048 ${NS}::button $page.bgbut -text [mc "Background"] \
11049 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11050 grid x $page.bgbut $page.bg -sticky w
11051 label $page.fg -padx 40 -relief sunk -background $fgcolor
11052 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11053 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11054 grid x $page.fgbut $page.fg -sticky w
11055 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11056 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11057 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11058 [list $ctext tag conf d0 -foreground]]
11059 grid x $page.diffoldbut $page.diffold -sticky w
11060 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11061 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11062 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11063 [list $ctext tag conf dresult -foreground]]
11064 grid x $page.diffnewbut $page.diffnew -sticky w
11065 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11066 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11067 -command [list choosecolor diffcolors 2 $page.hunksep \
11068 [mc "diff hunk header"] \
11069 [list $ctext tag conf hunksep -foreground]]
11070 grid x $page.hunksepbut $page.hunksep -sticky w
11071 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11072 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11073 -command [list choosecolor markbgcolor {} $page.markbgsep \
11074 [mc "marked line background"] \
11075 [list $ctext tag conf omark -background]]
11076 grid x $page.markbgbut $page.markbgsep -sticky w
11077 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11078 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11079 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11080 grid x $page.selbgbut $page.selbgsep -sticky w
11084 proc prefspage_fonts {notebook} {
11086 set page [create_prefs_page $notebook.fonts]
11087 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11088 grid $page.cfont - -sticky w -pady 10
11089 mkfontdisp mainfont $page [mc "Main font"]
11090 mkfontdisp textfont $page [mc "Diff display font"]
11091 mkfontdisp uifont $page [mc "User interface font"]
11096 global maxwidth maxgraphpct use_ttk NS
11097 global oldprefs prefstop showneartags showlocalchanges
11098 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11099 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11100 global hideremotes want_ttk have_ttk
11104 if {[winfo exists $top]} {
11108 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11109 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11110 set oldprefs($v) [set $v]
11113 wm title $top [mc "Gitk preferences"]
11114 make_transient $top .
11116 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11117 set notebook [ttk::notebook $top.notebook]
11119 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11122 lappend pages [prefspage_general $notebook] [mc "General"]
11123 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11124 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11126 foreach {page title} $pages {
11127 if {$use_notebook} {
11128 $notebook add $page -text $title
11130 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11131 -text $title -command [list raise $page]]
11132 $page configure -text $title
11133 grid $btn -row 0 -column [incr col] -sticky w
11134 grid $page -row 1 -column 0 -sticky news -columnspan 100
11138 if {!$use_notebook} {
11139 grid columnconfigure $notebook 0 -weight 1
11140 grid rowconfigure $notebook 1 -weight 1
11141 raise [lindex $pages 0]
11144 grid $notebook -sticky news -padx 2 -pady 2
11145 grid rowconfigure $top 0 -weight 1
11146 grid columnconfigure $top 0 -weight 1
11148 ${NS}::frame $top.buts
11149 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11150 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11151 bind $top <Key-Return> prefsok
11152 bind $top <Key-Escape> prefscan
11153 grid $top.buts.ok $top.buts.can
11154 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11155 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11156 grid $top.buts - - -pady 10 -sticky ew
11157 grid columnconfigure $top 2 -weight 1
11158 bind $top <Visibility> [list focus $top.buts.ok]
11161 proc choose_extdiff {} {
11164 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11166 set extdifftool $prog
11170 proc choosecolor {v vi w x cmd} {
11173 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11174 -title [mc "Gitk: choose color for %s" $x]]
11175 if {$c eq {}} return
11176 $w conf -background $c
11181 proc setselbg {c} {
11182 global bglist cflist
11183 foreach w $bglist {
11184 $w configure -selectbackground $c
11186 $cflist tag configure highlight \
11187 -background [$cflist cget -selectbackground]
11188 allcanvs itemconf secsel -fill $c
11191 # This sets the background color and the color scheme for the whole UI.
11192 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11193 # if we don't specify one ourselves, which makes the checkbuttons and
11194 # radiobuttons look bad. This chooses white for selectColor if the
11195 # background color is light, or black if it is dark.
11197 if {[tk windowingsystem] eq "win32"} { return }
11198 set bg [winfo rgb . $c]
11200 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11203 tk_setPalette background $c selectColor $selc
11209 foreach w $bglist {
11210 $w conf -background $c
11217 foreach w $fglist {
11218 $w conf -foreground $c
11220 allcanvs itemconf text -fill $c
11221 $canv itemconf circle -outline $c
11222 $canv itemconf markid -outline $c
11226 global oldprefs prefstop
11228 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11229 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11231 set $v $oldprefs($v)
11233 catch {destroy $prefstop}
11239 global maxwidth maxgraphpct
11240 global oldprefs prefstop showneartags showlocalchanges
11241 global fontpref mainfont textfont uifont
11242 global limitdiffs treediffs perfile_attrs
11245 catch {destroy $prefstop}
11249 if {$mainfont ne $fontpref(mainfont)} {
11250 set mainfont $fontpref(mainfont)
11251 parsefont mainfont $mainfont
11252 eval font configure mainfont [fontflags mainfont]
11253 eval font configure mainfontbold [fontflags mainfont 1]
11257 if {$textfont ne $fontpref(textfont)} {
11258 set textfont $fontpref(textfont)
11259 parsefont textfont $textfont
11260 eval font configure textfont [fontflags textfont]
11261 eval font configure textfontbold [fontflags textfont 1]
11263 if {$uifont ne $fontpref(uifont)} {
11264 set uifont $fontpref(uifont)
11265 parsefont uifont $uifont
11266 eval font configure uifont [fontflags uifont]
11269 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11270 if {$showlocalchanges} {
11276 if {$limitdiffs != $oldprefs(limitdiffs) ||
11277 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11278 # treediffs elements are limited by path;
11279 # won't have encodings cached if perfile_attrs was just turned on
11280 catch {unset treediffs}
11282 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11283 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11285 } elseif {$showneartags != $oldprefs(showneartags) ||
11286 $limitdiffs != $oldprefs(limitdiffs)} {
11289 if {$hideremotes != $oldprefs(hideremotes)} {
11294 proc formatdate {d} {
11295 global datetimeformat
11297 set d [clock format [lindex $d 0] -format $datetimeformat]
11302 # This list of encoding names and aliases is distilled from
11303 # http://www.iana.org/assignments/character-sets.
11304 # Not all of them are supported by Tcl.
11305 set encoding_aliases {
11306 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11307 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11308 { ISO-10646-UTF-1 csISO10646UTF1 }
11309 { ISO_646.basic:1983 ref csISO646basic1983 }
11310 { INVARIANT csINVARIANT }
11311 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11312 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11313 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11314 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11315 { NATS-DANO iso-ir-9-1 csNATSDANO }
11316 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11317 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11318 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11319 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11320 { ISO-2022-KR csISO2022KR }
11322 { ISO-2022-JP csISO2022JP }
11323 { ISO-2022-JP-2 csISO2022JP2 }
11324 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11325 csISO13JISC6220jp }
11326 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11327 { IT iso-ir-15 ISO646-IT csISO15Italian }
11328 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11329 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11330 { greek7-old iso-ir-18 csISO18Greek7Old }
11331 { latin-greek iso-ir-19 csISO19LatinGreek }
11332 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11333 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11334 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11335 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11336 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11337 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11338 { INIS iso-ir-49 csISO49INIS }
11339 { INIS-8 iso-ir-50 csISO50INIS8 }
11340 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11341 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11342 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11343 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11344 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11345 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11346 csISO60Norwegian1 }
11347 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11348 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11349 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11350 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11351 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11352 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11353 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11354 { greek7 iso-ir-88 csISO88Greek7 }
11355 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11356 { iso-ir-90 csISO90 }
11357 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11358 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11359 csISO92JISC62991984b }
11360 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11361 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11362 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11363 csISO95JIS62291984handadd }
11364 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11365 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11366 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11367 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11368 CP819 csISOLatin1 }
11369 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11370 { T.61-7bit iso-ir-102 csISO102T617bit }
11371 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11372 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11373 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11374 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11375 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11376 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11377 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11378 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11379 arabic csISOLatinArabic }
11380 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11381 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11382 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11383 greek greek8 csISOLatinGreek }
11384 { T.101-G2 iso-ir-128 csISO128T101G2 }
11385 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11387 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11388 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11389 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11390 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11391 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11392 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11393 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11394 csISOLatinCyrillic }
11395 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11396 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11397 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11398 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11399 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11400 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11401 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11402 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11403 { ISO_10367-box iso-ir-155 csISO10367Box }
11404 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11405 { latin-lap lap iso-ir-158 csISO158Lap }
11406 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11407 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11410 { JIS_X0201 X0201 csHalfWidthKatakana }
11411 { KSC5636 ISO646-KR csKSC5636 }
11412 { ISO-10646-UCS-2 csUnicode }
11413 { ISO-10646-UCS-4 csUCS4 }
11414 { DEC-MCS dec csDECMCS }
11415 { hp-roman8 roman8 r8 csHPRoman8 }
11416 { macintosh mac csMacintosh }
11417 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11419 { IBM038 EBCDIC-INT cp038 csIBM038 }
11420 { IBM273 CP273 csIBM273 }
11421 { IBM274 EBCDIC-BE CP274 csIBM274 }
11422 { IBM275 EBCDIC-BR cp275 csIBM275 }
11423 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11424 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11425 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11426 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11427 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11428 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11429 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11430 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11431 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11432 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11433 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11434 { IBM437 cp437 437 csPC8CodePage437 }
11435 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11436 { IBM775 cp775 csPC775Baltic }
11437 { IBM850 cp850 850 csPC850Multilingual }
11438 { IBM851 cp851 851 csIBM851 }
11439 { IBM852 cp852 852 csPCp852 }
11440 { IBM855 cp855 855 csIBM855 }
11441 { IBM857 cp857 857 csIBM857 }
11442 { IBM860 cp860 860 csIBM860 }
11443 { IBM861 cp861 861 cp-is csIBM861 }
11444 { IBM862 cp862 862 csPC862LatinHebrew }
11445 { IBM863 cp863 863 csIBM863 }
11446 { IBM864 cp864 csIBM864 }
11447 { IBM865 cp865 865 csIBM865 }
11448 { IBM866 cp866 866 csIBM866 }
11449 { IBM868 CP868 cp-ar csIBM868 }
11450 { IBM869 cp869 869 cp-gr csIBM869 }
11451 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11452 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11453 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11454 { IBM891 cp891 csIBM891 }
11455 { IBM903 cp903 csIBM903 }
11456 { IBM904 cp904 904 csIBBM904 }
11457 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11458 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11459 { IBM1026 CP1026 csIBM1026 }
11460 { EBCDIC-AT-DE csIBMEBCDICATDE }
11461 { EBCDIC-AT-DE-A csEBCDICATDEA }
11462 { EBCDIC-CA-FR csEBCDICCAFR }
11463 { EBCDIC-DK-NO csEBCDICDKNO }
11464 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11465 { EBCDIC-FI-SE csEBCDICFISE }
11466 { EBCDIC-FI-SE-A csEBCDICFISEA }
11467 { EBCDIC-FR csEBCDICFR }
11468 { EBCDIC-IT csEBCDICIT }
11469 { EBCDIC-PT csEBCDICPT }
11470 { EBCDIC-ES csEBCDICES }
11471 { EBCDIC-ES-A csEBCDICESA }
11472 { EBCDIC-ES-S csEBCDICESS }
11473 { EBCDIC-UK csEBCDICUK }
11474 { EBCDIC-US csEBCDICUS }
11475 { UNKNOWN-8BIT csUnknown8BiT }
11476 { MNEMONIC csMnemonic }
11478 { VISCII csVISCII }
11481 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11482 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11483 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11484 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11485 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11486 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11487 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11488 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11489 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11490 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11491 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11492 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11493 { IBM1047 IBM-1047 }
11494 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11495 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11496 { UNICODE-1-1 csUnicode11 }
11497 { CESU-8 csCESU-8 }
11498 { BOCU-1 csBOCU-1 }
11499 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11500 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11502 { ISO-8859-15 ISO_8859-15 Latin-9 }
11503 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11504 { GBK CP936 MS936 windows-936 }
11505 { JIS_Encoding csJISEncoding }
11506 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11507 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11509 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11510 { ISO-10646-UCS-Basic csUnicodeASCII }
11511 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11512 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11513 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11514 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11515 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11516 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11517 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11518 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11519 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11520 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11521 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11522 { Ventura-US csVenturaUS }
11523 { Ventura-International csVenturaInternational }
11524 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11525 { PC8-Turkish csPC8Turkish }
11526 { IBM-Symbols csIBMSymbols }
11527 { IBM-Thai csIBMThai }
11528 { HP-Legal csHPLegal }
11529 { HP-Pi-font csHPPiFont }
11530 { HP-Math8 csHPMath8 }
11531 { Adobe-Symbol-Encoding csHPPSMath }
11532 { HP-DeskTop csHPDesktop }
11533 { Ventura-Math csVenturaMath }
11534 { Microsoft-Publishing csMicrosoftPublishing }
11535 { Windows-31J csWindows31J }
11536 { GB2312 csGB2312 }
11540 proc tcl_encoding {enc} {
11541 global encoding_aliases tcl_encoding_cache
11542 if {[info exists tcl_encoding_cache($enc)]} {
11543 return $tcl_encoding_cache($enc)
11545 set names [encoding names]
11546 set lcnames [string tolower $names]
11547 set enc [string tolower $enc]
11548 set i [lsearch -exact $lcnames $enc]
11550 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11551 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11552 set i [lsearch -exact $lcnames $encx]
11556 foreach l $encoding_aliases {
11557 set ll [string tolower $l]
11558 if {[lsearch -exact $ll $enc] < 0} continue
11559 # look through the aliases for one that tcl knows about
11561 set i [lsearch -exact $lcnames $e]
11563 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11564 set i [lsearch -exact $lcnames $ex]
11574 set tclenc [lindex $names $i]
11576 set tcl_encoding_cache($enc) $tclenc
11580 proc gitattr {path attr default} {
11581 global path_attr_cache
11582 if {[info exists path_attr_cache($attr,$path)]} {
11583 set r $path_attr_cache($attr,$path)
11585 set r "unspecified"
11586 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11587 regexp "(.*): $attr: (.*)" $line m f r
11589 set path_attr_cache($attr,$path) $r
11591 if {$r eq "unspecified"} {
11597 proc cache_gitattr {attr pathlist} {
11598 global path_attr_cache
11600 foreach path $pathlist {
11601 if {![info exists path_attr_cache($attr,$path)]} {
11602 lappend newlist $path
11606 if {[tk windowingsystem] == "win32"} {
11607 # windows has a 32k limit on the arguments to a command...
11610 while {$newlist ne {}} {
11611 set head [lrange $newlist 0 [expr {$lim - 1}]]
11612 set newlist [lrange $newlist $lim end]
11613 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11614 foreach row [split $rlist "\n"] {
11615 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11616 if {[string index $path 0] eq "\""} {
11617 set path [encoding convertfrom [lindex $path 0]]
11619 set path_attr_cache($attr,$path) $value
11626 proc get_path_encoding {path} {
11627 global gui_encoding perfile_attrs
11628 set tcl_enc $gui_encoding
11629 if {$path ne {} && $perfile_attrs} {
11630 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11638 # First check that Tcl/Tk is recent enough
11639 if {[catch {package require Tk 8.4} err]} {
11640 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11641 Gitk requires at least Tcl/Tk 8.4." list
11645 # Unset GIT_TRACE var if set
11646 if { [info exists ::env(GIT_TRACE)] } {
11647 unset ::env(GIT_TRACE)
11651 set wrcomcmd "git diff-tree --stdin -p --pretty"
11655 set gitencoding [exec git config --get i18n.commitencoding]
11658 set gitencoding [exec git config --get i18n.logoutputencoding]
11660 if {$gitencoding == ""} {
11661 set gitencoding "utf-8"
11663 set tclencoding [tcl_encoding $gitencoding]
11664 if {$tclencoding == {}} {
11665 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11668 set gui_encoding [encoding system]
11670 set enc [exec git config --get gui.encoding]
11672 set tclenc [tcl_encoding $enc]
11673 if {$tclenc ne {}} {
11674 set gui_encoding $tclenc
11676 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11681 set log_showroot true
11683 set log_showroot [exec git config --bool --get log.showroot]
11686 if {[tk windowingsystem] eq "aqua"} {
11687 set mainfont {{Lucida Grande} 9}
11688 set textfont {Monaco 9}
11689 set uifont {{Lucida Grande} 9 bold}
11690 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11692 set mainfont {sans 9}
11693 set textfont {monospace 9}
11694 set uifont {sans 9 bold}
11696 set mainfont {Helvetica 9}
11697 set textfont {Courier 9}
11698 set uifont {Helvetica 9 bold}
11701 set findmergefiles 0
11709 set cmitmode "patch"
11710 set wrapcomment "none"
11715 set showlocalchanges 1
11717 set datetimeformat "%Y-%m-%d %H:%M:%S"
11720 set perfile_attrs 0
11723 if {[tk windowingsystem] eq "aqua"} {
11724 set extdifftool "opendiff"
11726 set extdifftool "meld"
11729 set colors {green red blue magenta darkgrey brown orange}
11730 if {[tk windowingsystem] eq "win32"} {
11731 set uicolor SystemButtonFace
11732 set bgcolor SystemWindow
11733 set fgcolor SystemButtonText
11734 set selectbgcolor SystemHighlight
11739 set selectbgcolor gray85
11741 set diffcolors {red "#00a000" blue}
11745 set markbgcolor "#e0e0ff"
11747 set circlecolors {white blue gray blue blue}
11749 # button for popping up context menus
11750 if {[tk windowingsystem] eq "aqua"} {
11751 set ctxbut <Button-2>
11753 set ctxbut <Button-3>
11756 ## For msgcat loading, first locate the installation location.
11757 if { [info exists ::env(GITK_MSGSDIR)] } {
11758 ## Msgsdir was manually set in the environment.
11759 set gitk_msgsdir $::env(GITK_MSGSDIR)
11761 ## Let's guess the prefix from argv0.
11762 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11763 set gitk_libdir [file join $gitk_prefix share gitk lib]
11764 set gitk_msgsdir [file join $gitk_libdir msgs]
11768 ## Internationalization (i18n) through msgcat and gettext. See
11769 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11770 package require msgcat
11771 namespace import ::msgcat::mc
11772 ## And eventually load the actual message catalog
11773 ::msgcat::mcload $gitk_msgsdir
11775 catch {source ~/.gitk}
11777 parsefont mainfont $mainfont
11778 eval font create mainfont [fontflags mainfont]
11779 eval font create mainfontbold [fontflags mainfont 1]
11781 parsefont textfont $textfont
11782 eval font create textfont [fontflags textfont]
11783 eval font create textfontbold [fontflags textfont 1]
11785 parsefont uifont $uifont
11786 eval font create uifont [fontflags uifont]
11792 # check that we can find a .git directory somewhere...
11793 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
11794 show_error {} . [mc "Cannot find a git repository here."]
11799 set selectheadid {}
11802 set cmdline_files {}
11804 set revtreeargscmd {}
11805 foreach arg $argv {
11806 switch -glob -- $arg {
11809 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11812 "--select-commit=*" {
11813 set selecthead [string range $arg 16 end]
11816 set revtreeargscmd [string range $arg 10 end]
11819 lappend revtreeargs $arg
11825 if {$selecthead eq "HEAD"} {
11829 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11830 # no -- on command line, but some arguments (other than --argscmd)
11832 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11833 set cmdline_files [split $f "\n"]
11834 set n [llength $cmdline_files]
11835 set revtreeargs [lrange $revtreeargs 0 end-$n]
11836 # Unfortunately git rev-parse doesn't produce an error when
11837 # something is both a revision and a filename. To be consistent
11838 # with git log and git rev-list, check revtreeargs for filenames.
11839 foreach arg $revtreeargs {
11840 if {[file exists $arg]} {
11841 show_error {} . [mc "Ambiguous argument '%s': both revision\
11842 and filename" $arg]
11847 # unfortunately we get both stdout and stderr in $err,
11848 # so look for "fatal:".
11849 set i [string first "fatal:" $err]
11851 set err [string range $err [expr {$i + 6}] end]
11853 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
11858 set nullid "0000000000000000000000000000000000000000"
11859 set nullid2 "0000000000000000000000000000000000000001"
11860 set nullfile "/dev/null"
11862 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
11863 if {![info exists have_ttk]} {
11864 set have_ttk [llength [info commands ::ttk::style]]
11866 set use_ttk [expr {$have_ttk && $want_ttk}]
11867 set NS [expr {$use_ttk ? "ttk" : ""}]
11869 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
11872 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
11873 set show_notes "--show-notes"
11883 set highlight_paths {}
11885 set searchdirn -forwards
11888 set diffelide {0 0}
11889 set markingmatches 0
11890 set linkentercount 0
11891 set need_redisplay 0
11898 set selectedhlview [mc "None"]
11899 set highlight_related [mc "None"]
11900 set highlight_files {}
11901 set viewfiles(0) {}
11904 set viewargscmd(0) {}
11906 set selectedline {}
11914 set hasworktree [hasworktree]
11916 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
11917 set cdup [exec git rev-parse --show-cdup]
11919 set worktree [exec git rev-parse --show-toplevel]
11923 image create photo gitlogo -width 16 -height 16
11925 image create photo gitlogominus -width 4 -height 2
11926 gitlogominus put #C00000 -to 0 0 4 2
11927 gitlogo copy gitlogominus -to 1 5
11928 gitlogo copy gitlogominus -to 6 5
11929 gitlogo copy gitlogominus -to 11 5
11930 image delete gitlogominus
11932 image create photo gitlogoplus -width 4 -height 4
11933 gitlogoplus put #008000 -to 1 0 3 4
11934 gitlogoplus put #008000 -to 0 1 4 3
11935 gitlogo copy gitlogoplus -to 1 9
11936 gitlogo copy gitlogoplus -to 6 9
11937 gitlogo copy gitlogoplus -to 11 9
11938 image delete gitlogoplus
11940 image create photo gitlogo32 -width 32 -height 32
11941 gitlogo32 copy gitlogo -zoom 2 2
11943 wm iconphoto . -default gitlogo gitlogo32
11945 # wait for the window to become visible
11946 tkwait visibility .
11947 wm title . "$appname: [reponame]"
11951 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
11952 # create a view for the files/dirs specified on the command line
11956 set viewname(1) [mc "Command line"]
11957 set viewfiles(1) $cmdline_files
11958 set viewargs(1) $revtreeargs
11959 set viewargscmd(1) $revtreeargscmd
11963 .bar.view entryconf [mca "Edit view..."] -state normal
11964 .bar.view entryconf [mca "Delete view"] -state normal
11967 if {[info exists permviews]} {
11968 foreach v $permviews {
11971 set viewname($n) [lindex $v 0]
11972 set viewfiles($n) [lindex $v 1]
11973 set viewargs($n) [lindex $v 2]
11974 set viewargscmd($n) [lindex $v 3]
11980 if {[tk windowingsystem] eq "win32"} {
11988 # indent-tabs-mode: t