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 catch {file delete "~/.gitk"}
2787 file rename -force "~/.gitk-new" "~/.gitk"
2792 proc resizeclistpanes {win w} {
2793 global oldwidth use_ttk
2794 if {[info exists oldwidth($win)]} {
2796 set s0 [$win sashpos 0]
2797 set s1 [$win sashpos 1]
2799 set s0 [$win sash coord 0]
2800 set s1 [$win sash coord 1]
2803 set sash0 [expr {int($w/2 - 2)}]
2804 set sash1 [expr {int($w*5/6 - 2)}]
2806 set factor [expr {1.0 * $w / $oldwidth($win)}]
2807 set sash0 [expr {int($factor * [lindex $s0 0])}]
2808 set sash1 [expr {int($factor * [lindex $s1 0])}]
2812 if {$sash1 < $sash0 + 20} {
2813 set sash1 [expr {$sash0 + 20}]
2815 if {$sash1 > $w - 10} {
2816 set sash1 [expr {$w - 10}]
2817 if {$sash0 > $sash1 - 20} {
2818 set sash0 [expr {$sash1 - 20}]
2823 $win sashpos 0 $sash0
2824 $win sashpos 1 $sash1
2826 $win sash place 0 $sash0 [lindex $s0 1]
2827 $win sash place 1 $sash1 [lindex $s1 1]
2830 set oldwidth($win) $w
2833 proc resizecdetpanes {win w} {
2834 global oldwidth use_ttk
2835 if {[info exists oldwidth($win)]} {
2837 set s0 [$win sashpos 0]
2839 set s0 [$win sash coord 0]
2842 set sash0 [expr {int($w*3/4 - 2)}]
2844 set factor [expr {1.0 * $w / $oldwidth($win)}]
2845 set sash0 [expr {int($factor * [lindex $s0 0])}]
2849 if {$sash0 > $w - 15} {
2850 set sash0 [expr {$w - 15}]
2854 $win sashpos 0 $sash0
2856 $win sash place 0 $sash0 [lindex $s0 1]
2859 set oldwidth($win) $w
2862 proc allcanvs args {
2863 global canv canv2 canv3
2869 proc bindall {event action} {
2870 global canv canv2 canv3
2871 bind $canv $event $action
2872 bind $canv2 $event $action
2873 bind $canv3 $event $action
2879 if {[winfo exists $w]} {
2884 wm title $w [mc "About gitk"]
2886 message $w.m -text [mc "
2887 Gitk - a commit viewer for git
2889 Copyright \u00a9 2005-2011 Paul Mackerras
2891 Use and redistribute under the terms of the GNU General Public License"] \
2892 -justify center -aspect 400 -border 2 -bg white -relief groove
2893 pack $w.m -side top -fill x -padx 2 -pady 2
2894 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2895 pack $w.ok -side bottom
2896 bind $w <Visibility> "focus $w.ok"
2897 bind $w <Key-Escape> "destroy $w"
2898 bind $w <Key-Return> "destroy $w"
2899 tk::PlaceWindow $w widget .
2905 if {[winfo exists $w]} {
2909 if {[tk windowingsystem] eq {aqua}} {
2915 wm title $w [mc "Gitk key bindings"]
2917 message $w.m -text "
2918 [mc "Gitk key bindings:"]
2920 [mc "<%s-Q> Quit" $M1T]
2921 [mc "<%s-W> Close window" $M1T]
2922 [mc "<Home> Move to first commit"]
2923 [mc "<End> Move to last commit"]
2924 [mc "<Up>, p, k Move up one commit"]
2925 [mc "<Down>, n, j Move down one commit"]
2926 [mc "<Left>, z, h Go back in history list"]
2927 [mc "<Right>, x, l Go forward in history list"]
2928 [mc "<PageUp> Move up one page in commit list"]
2929 [mc "<PageDown> Move down one page in commit list"]
2930 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2931 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2932 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2933 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2934 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2935 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2936 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2937 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2938 [mc "<Delete>, b Scroll diff view up one page"]
2939 [mc "<Backspace> Scroll diff view up one page"]
2940 [mc "<Space> Scroll diff view down one page"]
2941 [mc "u Scroll diff view up 18 lines"]
2942 [mc "d Scroll diff view down 18 lines"]
2943 [mc "<%s-F> Find" $M1T]
2944 [mc "<%s-G> Move to next find hit" $M1T]
2945 [mc "<Return> Move to next find hit"]
2946 [mc "/ Focus the search box"]
2947 [mc "? Move to previous find hit"]
2948 [mc "f Scroll diff view to next file"]
2949 [mc "<%s-S> Search for next hit in diff view" $M1T]
2950 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2951 [mc "<%s-KP+> Increase font size" $M1T]
2952 [mc "<%s-plus> Increase font size" $M1T]
2953 [mc "<%s-KP-> Decrease font size" $M1T]
2954 [mc "<%s-minus> Decrease font size" $M1T]
2957 -justify left -bg white -border 2 -relief groove
2958 pack $w.m -side top -fill both -padx 2 -pady 2
2959 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2960 bind $w <Key-Escape> [list destroy $w]
2961 pack $w.ok -side bottom
2962 bind $w <Visibility> "focus $w.ok"
2963 bind $w <Key-Escape> "destroy $w"
2964 bind $w <Key-Return> "destroy $w"
2967 # Procedures for manipulating the file list window at the
2968 # bottom right of the overall window.
2970 proc treeview {w l openlevs} {
2971 global treecontents treediropen treeheight treeparent treeindex
2981 set treecontents() {}
2982 $w conf -state normal
2984 while {[string range $f 0 $prefixend] ne $prefix} {
2985 if {$lev <= $openlevs} {
2986 $w mark set e:$treeindex($prefix) "end -1c"
2987 $w mark gravity e:$treeindex($prefix) left
2989 set treeheight($prefix) $ht
2990 incr ht [lindex $htstack end]
2991 set htstack [lreplace $htstack end end]
2992 set prefixend [lindex $prefendstack end]
2993 set prefendstack [lreplace $prefendstack end end]
2994 set prefix [string range $prefix 0 $prefixend]
2997 set tail [string range $f [expr {$prefixend+1}] end]
2998 while {[set slash [string first "/" $tail]] >= 0} {
3001 lappend prefendstack $prefixend
3002 incr prefixend [expr {$slash + 1}]
3003 set d [string range $tail 0 $slash]
3004 lappend treecontents($prefix) $d
3005 set oldprefix $prefix
3007 set treecontents($prefix) {}
3008 set treeindex($prefix) [incr ix]
3009 set treeparent($prefix) $oldprefix
3010 set tail [string range $tail [expr {$slash+1}] end]
3011 if {$lev <= $openlevs} {
3013 set treediropen($prefix) [expr {$lev < $openlevs}]
3014 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3015 $w mark set d:$ix "end -1c"
3016 $w mark gravity d:$ix left
3018 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3020 $w image create end -align center -image $bm -padx 1 \
3022 $w insert end $d [highlight_tag $prefix]
3023 $w mark set s:$ix "end -1c"
3024 $w mark gravity s:$ix left
3029 if {$lev <= $openlevs} {
3032 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3034 $w insert end $tail [highlight_tag $f]
3036 lappend treecontents($prefix) $tail
3039 while {$htstack ne {}} {
3040 set treeheight($prefix) $ht
3041 incr ht [lindex $htstack end]
3042 set htstack [lreplace $htstack end end]
3043 set prefixend [lindex $prefendstack end]
3044 set prefendstack [lreplace $prefendstack end end]
3045 set prefix [string range $prefix 0 $prefixend]
3047 $w conf -state disabled
3050 proc linetoelt {l} {
3051 global treeheight treecontents
3056 foreach e $treecontents($prefix) {
3061 if {[string index $e end] eq "/"} {
3062 set n $treeheight($prefix$e)
3074 proc highlight_tree {y prefix} {
3075 global treeheight treecontents cflist
3077 foreach e $treecontents($prefix) {
3079 if {[highlight_tag $path] ne {}} {
3080 $cflist tag add bold $y.0 "$y.0 lineend"
3083 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3084 set y [highlight_tree $y $path]
3090 proc treeclosedir {w dir} {
3091 global treediropen treeheight treeparent treeindex
3093 set ix $treeindex($dir)
3094 $w conf -state normal
3095 $w delete s:$ix e:$ix
3096 set treediropen($dir) 0
3097 $w image configure a:$ix -image tri-rt
3098 $w conf -state disabled
3099 set n [expr {1 - $treeheight($dir)}]
3100 while {$dir ne {}} {
3101 incr treeheight($dir) $n
3102 set dir $treeparent($dir)
3106 proc treeopendir {w dir} {
3107 global treediropen treeheight treeparent treecontents treeindex
3109 set ix $treeindex($dir)
3110 $w conf -state normal
3111 $w image configure a:$ix -image tri-dn
3112 $w mark set e:$ix s:$ix
3113 $w mark gravity e:$ix right
3116 set n [llength $treecontents($dir)]
3117 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3120 incr treeheight($x) $n
3122 foreach e $treecontents($dir) {
3124 if {[string index $e end] eq "/"} {
3125 set iy $treeindex($de)
3126 $w mark set d:$iy e:$ix
3127 $w mark gravity d:$iy left
3128 $w insert e:$ix $str
3129 set treediropen($de) 0
3130 $w image create e:$ix -align center -image tri-rt -padx 1 \
3132 $w insert e:$ix $e [highlight_tag $de]
3133 $w mark set s:$iy e:$ix
3134 $w mark gravity s:$iy left
3135 set treeheight($de) 1
3137 $w insert e:$ix $str
3138 $w insert e:$ix $e [highlight_tag $de]
3141 $w mark gravity e:$ix right
3142 $w conf -state disabled
3143 set treediropen($dir) 1
3144 set top [lindex [split [$w index @0,0] .] 0]
3145 set ht [$w cget -height]
3146 set l [lindex [split [$w index s:$ix] .] 0]
3149 } elseif {$l + $n + 1 > $top + $ht} {
3150 set top [expr {$l + $n + 2 - $ht}]
3158 proc treeclick {w x y} {
3159 global treediropen cmitmode ctext cflist cflist_top
3161 if {$cmitmode ne "tree"} return
3162 if {![info exists cflist_top]} return
3163 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3164 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3165 $cflist tag add highlight $l.0 "$l.0 lineend"
3171 set e [linetoelt $l]
3172 if {[string index $e end] ne "/"} {
3174 } elseif {$treediropen($e)} {
3181 proc setfilelist {id} {
3182 global treefilelist cflist jump_to_here
3184 treeview $cflist $treefilelist($id) 0
3185 if {$jump_to_here ne {}} {
3186 set f [lindex $jump_to_here 0]
3187 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3193 image create bitmap tri-rt -background black -foreground blue -data {
3194 #define tri-rt_width 13
3195 #define tri-rt_height 13
3196 static unsigned char tri-rt_bits[] = {
3197 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3198 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3201 #define tri-rt-mask_width 13
3202 #define tri-rt-mask_height 13
3203 static unsigned char tri-rt-mask_bits[] = {
3204 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3205 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3208 image create bitmap tri-dn -background black -foreground blue -data {
3209 #define tri-dn_width 13
3210 #define tri-dn_height 13
3211 static unsigned char tri-dn_bits[] = {
3212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3213 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3216 #define tri-dn-mask_width 13
3217 #define tri-dn-mask_height 13
3218 static unsigned char tri-dn-mask_bits[] = {
3219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3220 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3224 image create bitmap reficon-T -background black -foreground yellow -data {
3225 #define tagicon_width 13
3226 #define tagicon_height 9
3227 static unsigned char tagicon_bits[] = {
3228 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3229 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3231 #define tagicon-mask_width 13
3232 #define tagicon-mask_height 9
3233 static unsigned char tagicon-mask_bits[] = {
3234 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3235 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3238 #define headicon_width 13
3239 #define headicon_height 9
3240 static unsigned char headicon_bits[] = {
3241 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3242 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3245 #define headicon-mask_width 13
3246 #define headicon-mask_height 9
3247 static unsigned char headicon-mask_bits[] = {
3248 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3249 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3251 image create bitmap reficon-H -background black -foreground green \
3252 -data $rectdata -maskdata $rectmask
3253 image create bitmap reficon-o -background black -foreground "#ddddff" \
3254 -data $rectdata -maskdata $rectmask
3256 proc init_flist {first} {
3257 global cflist cflist_top difffilestart
3259 $cflist conf -state normal
3260 $cflist delete 0.0 end
3262 $cflist insert end $first
3264 $cflist tag add highlight 1.0 "1.0 lineend"
3266 catch {unset cflist_top}
3268 $cflist conf -state disabled
3269 set difffilestart {}
3272 proc highlight_tag {f} {
3273 global highlight_paths
3275 foreach p $highlight_paths {
3276 if {[string match $p $f]} {
3283 proc highlight_filelist {} {
3284 global cmitmode cflist
3286 $cflist conf -state normal
3287 if {$cmitmode ne "tree"} {
3288 set end [lindex [split [$cflist index end] .] 0]
3289 for {set l 2} {$l < $end} {incr l} {
3290 set line [$cflist get $l.0 "$l.0 lineend"]
3291 if {[highlight_tag $line] ne {}} {
3292 $cflist tag add bold $l.0 "$l.0 lineend"
3298 $cflist conf -state disabled
3301 proc unhighlight_filelist {} {
3304 $cflist conf -state normal
3305 $cflist tag remove bold 1.0 end
3306 $cflist conf -state disabled
3309 proc add_flist {fl} {
3312 $cflist conf -state normal
3314 $cflist insert end "\n"
3315 $cflist insert end $f [highlight_tag $f]
3317 $cflist conf -state disabled
3320 proc sel_flist {w x y} {
3321 global ctext difffilestart cflist cflist_top cmitmode
3323 if {$cmitmode eq "tree"} return
3324 if {![info exists cflist_top]} return
3325 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3326 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3327 $cflist tag add highlight $l.0 "$l.0 lineend"
3332 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3334 suppress_highlighting_file_for_current_scrollpos
3337 proc pop_flist_menu {w X Y x y} {
3338 global ctext cflist cmitmode flist_menu flist_menu_file
3339 global treediffs diffids
3342 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3344 if {$cmitmode eq "tree"} {
3345 set e [linetoelt $l]
3346 if {[string index $e end] eq "/"} return
3348 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3350 set flist_menu_file $e
3351 set xdiffstate "normal"
3352 if {$cmitmode eq "tree"} {
3353 set xdiffstate "disabled"
3355 # Disable "External diff" item in tree mode
3356 $flist_menu entryconf 2 -state $xdiffstate
3357 tk_popup $flist_menu $X $Y
3360 proc find_ctext_fileinfo {line} {
3361 global ctext_file_names ctext_file_lines
3363 set ok [bsearch $ctext_file_lines $line]
3364 set tline [lindex $ctext_file_lines $ok]
3366 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3369 return [list [lindex $ctext_file_names $ok] $tline]
3373 proc pop_diff_menu {w X Y x y} {
3374 global ctext diff_menu flist_menu_file
3375 global diff_menu_txtpos diff_menu_line
3376 global diff_menu_filebase
3378 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3379 set diff_menu_line [lindex $diff_menu_txtpos 0]
3380 # don't pop up the menu on hunk-separator or file-separator lines
3381 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3385 set f [find_ctext_fileinfo $diff_menu_line]
3386 if {$f eq {}} return
3387 set flist_menu_file [lindex $f 0]
3388 set diff_menu_filebase [lindex $f 1]
3389 tk_popup $diff_menu $X $Y
3392 proc flist_hl {only} {
3393 global flist_menu_file findstring gdttype
3395 set x [shellquote $flist_menu_file]
3396 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3399 append findstring " " $x
3401 set gdttype [mc "touching paths:"]
3404 proc gitknewtmpdir {} {
3405 global diffnum gitktmpdir gitdir
3407 if {![info exists gitktmpdir]} {
3408 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3409 if {[catch {file mkdir $gitktmpdir} err]} {
3410 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3417 set diffdir [file join $gitktmpdir $diffnum]
3418 if {[catch {file mkdir $diffdir} err]} {
3419 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3425 proc save_file_from_commit {filename output what} {
3428 if {[catch {exec git show $filename -- > $output} err]} {
3429 if {[string match "fatal: bad revision *" $err]} {
3432 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3438 proc external_diff_get_one_file {diffid filename diffdir} {
3439 global nullid nullid2 nullfile
3442 if {$diffid == $nullid} {
3443 set difffile [file join $worktree $filename]
3444 if {[file exists $difffile]} {
3449 if {$diffid == $nullid2} {
3450 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3451 return [save_file_from_commit :$filename $difffile index]
3453 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3454 return [save_file_from_commit $diffid:$filename $difffile \
3458 proc external_diff {} {
3459 global nullid nullid2
3460 global flist_menu_file
3464 if {[llength $diffids] == 1} {
3465 # no reference commit given
3466 set diffidto [lindex $diffids 0]
3467 if {$diffidto eq $nullid} {
3468 # diffing working copy with index
3469 set diffidfrom $nullid2
3470 } elseif {$diffidto eq $nullid2} {
3471 # diffing index with HEAD
3472 set diffidfrom "HEAD"
3474 # use first parent commit
3475 global parentlist selectedline
3476 set diffidfrom [lindex $parentlist $selectedline 0]
3479 set diffidfrom [lindex $diffids 0]
3480 set diffidto [lindex $diffids 1]
3483 # make sure that several diffs wont collide
3484 set diffdir [gitknewtmpdir]
3485 if {$diffdir eq {}} return
3487 # gather files to diff
3488 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3489 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3491 if {$difffromfile ne {} && $difftofile ne {}} {
3492 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3493 if {[catch {set fl [open |$cmd r]} err]} {
3494 file delete -force $diffdir
3495 error_popup "$extdifftool: [mc "command failed:"] $err"
3497 fconfigure $fl -blocking 0
3498 filerun $fl [list delete_at_eof $fl $diffdir]
3503 proc find_hunk_blamespec {base line} {
3506 # Find and parse the hunk header
3507 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3508 if {$s_lix eq {}} return
3510 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3511 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3512 s_line old_specs osz osz1 new_line nsz]} {
3516 # base lines for the parents
3517 set base_lines [list $new_line]
3518 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3519 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3520 old_spec old_line osz]} {
3523 lappend base_lines $old_line
3526 # Now scan the lines to determine offset within the hunk
3527 set max_parent [expr {[llength $base_lines]-2}]
3529 set s_lno [lindex [split $s_lix "."] 0]
3531 # Determine if the line is removed
3532 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3533 if {[string match {[-+ ]*} $chunk]} {
3534 set removed_idx [string first "-" $chunk]
3535 # Choose a parent index
3536 if {$removed_idx >= 0} {
3537 set parent $removed_idx
3539 set unchanged_idx [string first " " $chunk]
3540 if {$unchanged_idx >= 0} {
3541 set parent $unchanged_idx
3543 # blame the current commit
3547 # then count other lines that belong to it
3548 for {set i $line} {[incr i -1] > $s_lno} {} {
3549 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3550 # Determine if the line is removed
3551 set removed_idx [string first "-" $chunk]
3553 set code [string index $chunk $parent]
3554 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3558 if {$removed_idx < 0} {
3568 incr dline [lindex $base_lines $parent]
3569 return [list $parent $dline]
3572 proc external_blame_diff {} {
3573 global currentid cmitmode
3574 global diff_menu_txtpos diff_menu_line
3575 global diff_menu_filebase flist_menu_file
3577 if {$cmitmode eq "tree"} {
3579 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3581 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3583 set parent_idx [lindex $hinfo 0]
3584 set line [lindex $hinfo 1]
3591 external_blame $parent_idx $line
3594 # Find the SHA1 ID of the blob for file $fname in the index
3596 proc index_sha1 {fname} {
3597 set f [open [list | git ls-files -s $fname] r]
3598 while {[gets $f line] >= 0} {
3599 set info [lindex [split $line "\t"] 0]
3600 set stage [lindex $info 2]
3601 if {$stage eq "0" || $stage eq "2"} {
3603 return [lindex $info 1]
3610 # Turn an absolute path into one relative to the current directory
3611 proc make_relative {f} {
3612 if {[file pathtype $f] eq "relative"} {
3615 set elts [file split $f]
3616 set here [file split [pwd]]
3621 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3628 set elts [concat $res [lrange $elts $ei end]]
3629 return [eval file join $elts]
3632 proc external_blame {parent_idx {line {}}} {
3633 global flist_menu_file cdup
3634 global nullid nullid2
3635 global parentlist selectedline currentid
3637 if {$parent_idx > 0} {
3638 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3640 set base_commit $currentid
3643 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3644 error_popup [mc "No such commit"]
3648 set cmdline [list git gui blame]
3649 if {$line ne {} && $line > 1} {
3650 lappend cmdline "--line=$line"
3652 set f [file join $cdup $flist_menu_file]
3653 # Unfortunately it seems git gui blame doesn't like
3654 # being given an absolute path...
3655 set f [make_relative $f]
3656 lappend cmdline $base_commit $f
3657 if {[catch {eval exec $cmdline &} err]} {
3658 error_popup "[mc "git gui blame: command failed:"] $err"
3662 proc show_line_source {} {
3663 global cmitmode currentid parents curview blamestuff blameinst
3664 global diff_menu_line diff_menu_filebase flist_menu_file
3665 global nullid nullid2 gitdir cdup
3668 if {$cmitmode eq "tree"} {
3670 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3672 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3673 if {$h eq {}} return
3674 set pi [lindex $h 0]
3676 mark_ctext_line $diff_menu_line
3680 if {$currentid eq $nullid} {
3682 # must be a merge in progress...
3684 # get the last line from .git/MERGE_HEAD
3685 set f [open [file join $gitdir MERGE_HEAD] r]
3686 set id [lindex [split [read $f] "\n"] end-1]
3689 error_popup [mc "Couldn't read merge head: %s" $err]
3692 } elseif {$parents($curview,$currentid) eq $nullid2} {
3693 # need to do the blame from the index
3695 set from_index [index_sha1 $flist_menu_file]
3697 error_popup [mc "Error reading index: %s" $err]
3701 set id $parents($curview,$currentid)
3704 set id [lindex $parents($curview,$currentid) $pi]
3706 set line [lindex $h 1]
3709 if {$from_index ne {}} {
3710 lappend blameargs | git cat-file blob $from_index
3712 lappend blameargs | git blame -p -L$line,+1
3713 if {$from_index ne {}} {
3714 lappend blameargs --contents -
3716 lappend blameargs $id
3718 lappend blameargs -- [file join $cdup $flist_menu_file]
3720 set f [open $blameargs r]
3722 error_popup [mc "Couldn't start git blame: %s" $err]
3725 nowbusy blaming [mc "Searching"]
3726 fconfigure $f -blocking 0
3727 set i [reg_instance $f]
3728 set blamestuff($i) {}
3730 filerun $f [list read_line_source $f $i]
3733 proc stopblaming {} {
3736 if {[info exists blameinst]} {
3737 stop_instance $blameinst
3743 proc read_line_source {fd inst} {
3744 global blamestuff curview commfd blameinst nullid nullid2
3746 while {[gets $fd line] >= 0} {
3747 lappend blamestuff($inst) $line
3755 fconfigure $fd -blocking 1
3756 if {[catch {close $fd} err]} {
3757 error_popup [mc "Error running git blame: %s" $err]
3762 set line [split [lindex $blamestuff($inst) 0] " "]
3763 set id [lindex $line 0]
3764 set lnum [lindex $line 1]
3765 if {[string length $id] == 40 && [string is xdigit $id] &&
3766 [string is digit -strict $lnum]} {
3767 # look for "filename" line
3768 foreach l $blamestuff($inst) {
3769 if {[string match "filename *" $l]} {
3770 set fname [string range $l 9 end]
3776 # all looks good, select it
3777 if {$id eq $nullid} {
3778 # blame uses all-zeroes to mean not committed,
3779 # which would mean a change in the index
3782 if {[commitinview $id $curview]} {
3783 selectline [rowofcommit $id] 1 [list $fname $lnum]
3785 error_popup [mc "That line comes from commit %s, \
3786 which is not in this view" [shortids $id]]
3789 puts "oops couldn't parse git blame output"
3794 # delete $dir when we see eof on $f (presumably because the child has exited)
3795 proc delete_at_eof {f dir} {
3796 while {[gets $f line] >= 0} {}
3798 if {[catch {close $f} err]} {
3799 error_popup "[mc "External diff viewer failed:"] $err"
3801 file delete -force $dir
3807 # Functions for adding and removing shell-type quoting
3809 proc shellquote {str} {
3810 if {![string match "*\['\"\\ \t]*" $str]} {
3813 if {![string match "*\['\"\\]*" $str]} {
3816 if {![string match "*'*" $str]} {
3819 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3822 proc shellarglist {l} {
3828 append str [shellquote $a]
3833 proc shelldequote {str} {
3838 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3839 append ret [string range $str $used end]
3840 set used [string length $str]
3843 set first [lindex $first 0]
3844 set ch [string index $str $first]
3845 if {$first > $used} {
3846 append ret [string range $str $used [expr {$first - 1}]]
3849 if {$ch eq " " || $ch eq "\t"} break
3852 set first [string first "'" $str $used]
3854 error "unmatched single-quote"
3856 append ret [string range $str $used [expr {$first - 1}]]
3861 if {$used >= [string length $str]} {
3862 error "trailing backslash"
3864 append ret [string index $str $used]
3869 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3870 error "unmatched double-quote"
3872 set first [lindex $first 0]
3873 set ch [string index $str $first]
3874 if {$first > $used} {
3875 append ret [string range $str $used [expr {$first - 1}]]
3878 if {$ch eq "\""} break
3880 append ret [string index $str $used]
3884 return [list $used $ret]
3887 proc shellsplit {str} {
3890 set str [string trimleft $str]
3891 if {$str eq {}} break
3892 set dq [shelldequote $str]
3893 set n [lindex $dq 0]
3894 set word [lindex $dq 1]
3895 set str [string range $str $n end]
3901 # Code to implement multiple views
3903 proc newview {ishighlight} {
3904 global nextviewnum newviewname newishighlight
3905 global revtreeargs viewargscmd newviewopts curview
3907 set newishighlight $ishighlight
3909 if {[winfo exists $top]} {
3913 decode_view_opts $nextviewnum $revtreeargs
3914 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3915 set newviewopts($nextviewnum,perm) 0
3916 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3917 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3920 set known_view_options {
3921 {perm b . {} {mc "Remember this view"}}
3922 {reflabel l + {} {mc "References (space separated list):"}}
3923 {refs t15 .. {} {mc "Branches & tags:"}}
3924 {allrefs b *. "--all" {mc "All refs"}}
3925 {branches b . "--branches" {mc "All (local) branches"}}
3926 {tags b . "--tags" {mc "All tags"}}
3927 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3928 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3929 {author t15 .. "--author=*" {mc "Author:"}}
3930 {committer t15 . "--committer=*" {mc "Committer:"}}
3931 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3932 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3933 {changes_l l + {} {mc "Changes to Files:"}}
3934 {pickaxe_s r0 . {} {mc "Fixed String"}}
3935 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3936 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3937 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3938 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3939 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3940 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3941 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3942 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3943 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3944 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3945 {lright b . "--left-right" {mc "Mark branch sides"}}
3946 {first b . "--first-parent" {mc "Limit to first parent"}}
3947 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3948 {args t50 *. {} {mc "Additional arguments to git log:"}}
3949 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3950 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3953 # Convert $newviewopts($n, ...) into args for git log.
3954 proc encode_view_opts {n} {
3955 global known_view_options newviewopts
3958 foreach opt $known_view_options {
3959 set patterns [lindex $opt 3]
3960 if {$patterns eq {}} continue
3961 set pattern [lindex $patterns 0]
3963 if {[lindex $opt 1] eq "b"} {
3964 set val $newviewopts($n,[lindex $opt 0])
3966 lappend rargs $pattern
3968 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
3969 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
3970 set val $newviewopts($n,$button_id)
3971 if {$val eq $value} {
3972 lappend rargs $pattern
3975 set val $newviewopts($n,[lindex $opt 0])
3976 set val [string trim $val]
3978 set pfix [string range $pattern 0 end-1]
3979 lappend rargs $pfix$val
3983 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
3984 return [concat $rargs [shellsplit $newviewopts($n,args)]]
3987 # Fill $newviewopts($n, ...) based on args for git log.
3988 proc decode_view_opts {n view_args} {
3989 global known_view_options newviewopts
3991 foreach opt $known_view_options {
3992 set id [lindex $opt 0]
3993 if {[lindex $opt 1] eq "b"} {
3996 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
3998 regexp {^(.*_)} $id uselessvar id
4004 set newviewopts($n,$id) $val
4008 foreach arg $view_args {
4009 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4010 && ![info exists found(limit)]} {
4011 set newviewopts($n,limit) $cnt
4016 foreach opt $known_view_options {
4017 set id [lindex $opt 0]
4018 if {[info exists found($id)]} continue
4019 foreach pattern [lindex $opt 3] {
4020 if {![string match $pattern $arg]} continue
4021 if {[lindex $opt 1] eq "b"} {
4024 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4026 regexp {^(.*_)} $id uselessvar id
4030 set size [string length $pattern]
4031 set val [string range $arg [expr {$size-1}] end]
4033 set newviewopts($n,$id) $val
4037 if {[info exists val]} break
4039 if {[info exists val]} continue
4040 if {[regexp {^-} $arg]} {
4043 lappend refargs $arg
4046 set newviewopts($n,refs) [shellarglist $refargs]
4047 set newviewopts($n,args) [shellarglist $oargs]
4050 proc edit_or_newview {} {
4062 global viewname viewperm newviewname newviewopts
4063 global viewargs viewargscmd
4065 set top .gitkvedit-$curview
4066 if {[winfo exists $top]} {
4070 decode_view_opts $curview $viewargs($curview)
4071 set newviewname($curview) $viewname($curview)
4072 set newviewopts($curview,perm) $viewperm($curview)
4073 set newviewopts($curview,cmd) $viewargscmd($curview)
4074 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4077 proc vieweditor {top n title} {
4078 global newviewname newviewopts viewfiles bgcolor
4079 global known_view_options NS
4082 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4083 make_transient $top .
4086 ${NS}::frame $top.nfr
4087 ${NS}::label $top.nl -text [mc "View Name"]
4088 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4089 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4090 pack $top.nl -in $top.nfr -side left -padx {0 5}
4091 pack $top.name -in $top.nfr -side left -padx {0 25}
4097 foreach opt $known_view_options {
4098 set id [lindex $opt 0]
4099 set type [lindex $opt 1]
4100 set flags [lindex $opt 2]
4101 set title [eval [lindex $opt 4]]
4104 if {$flags eq "+" || $flags eq "*"} {
4105 set cframe $top.fr$cnt
4107 ${NS}::frame $cframe
4108 pack $cframe -in $top -fill x -pady 3 -padx 3
4109 set cexpand [expr {$flags eq "*"}]
4110 } elseif {$flags eq ".." || $flags eq "*."} {
4111 set cframe $top.fr$cnt
4113 ${NS}::frame $cframe
4114 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4115 set cexpand [expr {$flags eq "*."}]
4121 ${NS}::label $cframe.l_$id -text $title
4122 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4123 } elseif {$type eq "b"} {
4124 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4125 pack $cframe.c_$id -in $cframe -side left \
4126 -padx [list $lxpad 0] -expand $cexpand -anchor w
4127 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4128 regexp {^(.*_)} $id uselessvar button_id
4129 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4130 pack $cframe.c_$id -in $cframe -side left \
4131 -padx [list $lxpad 0] -expand $cexpand -anchor w
4132 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4133 ${NS}::label $cframe.l_$id -text $title
4134 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4135 -textvariable newviewopts($n,$id)
4136 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4137 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4138 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4139 ${NS}::label $cframe.l_$id -text $title
4140 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4141 -textvariable newviewopts($n,$id)
4142 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4143 pack $cframe.e_$id -in $cframe -side top -fill x
4144 } elseif {$type eq "path"} {
4145 ${NS}::label $top.l -text $title
4146 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4147 text $top.t -width 40 -height 5 -background $bgcolor
4148 if {[info exists viewfiles($n)]} {
4149 foreach f $viewfiles($n) {
4150 $top.t insert end $f
4151 $top.t insert end "\n"
4153 $top.t delete {end - 1c} end
4154 $top.t mark set insert 0.0
4156 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4160 ${NS}::frame $top.buts
4161 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4162 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4163 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4164 bind $top <Control-Return> [list newviewok $top $n]
4165 bind $top <F5> [list newviewok $top $n 1]
4166 bind $top <Escape> [list destroy $top]
4167 grid $top.buts.ok $top.buts.apply $top.buts.can
4168 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4169 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4170 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4171 pack $top.buts -in $top -side top -fill x
4175 proc doviewmenu {m first cmd op argv} {
4176 set nmenu [$m index end]
4177 for {set i $first} {$i <= $nmenu} {incr i} {
4178 if {[$m entrycget $i -command] eq $cmd} {
4179 eval $m $op $i $argv
4185 proc allviewmenus {n op args} {
4188 doviewmenu .bar.view 5 [list showview $n] $op $args
4189 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4192 proc newviewok {top n {apply 0}} {
4193 global nextviewnum newviewperm newviewname newishighlight
4194 global viewname viewfiles viewperm selectedview curview
4195 global viewargs viewargscmd newviewopts viewhlmenu
4198 set newargs [encode_view_opts $n]
4200 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4204 foreach f [split [$top.t get 0.0 end] "\n"] {
4205 set ft [string trim $f]
4210 if {![info exists viewfiles($n)]} {
4211 # creating a new view
4213 set viewname($n) $newviewname($n)
4214 set viewperm($n) $newviewopts($n,perm)
4215 set viewfiles($n) $files
4216 set viewargs($n) $newargs
4217 set viewargscmd($n) $newviewopts($n,cmd)
4219 if {!$newishighlight} {
4222 run addvhighlight $n
4225 # editing an existing view
4226 set viewperm($n) $newviewopts($n,perm)
4227 if {$newviewname($n) ne $viewname($n)} {
4228 set viewname($n) $newviewname($n)
4229 doviewmenu .bar.view 5 [list showview $n] \
4230 entryconf [list -label $viewname($n)]
4231 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4232 # entryconf [list -label $viewname($n) -value $viewname($n)]
4234 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4235 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4236 set viewfiles($n) $files
4237 set viewargs($n) $newargs
4238 set viewargscmd($n) $newviewopts($n,cmd)
4239 if {$curview == $n} {
4245 catch {destroy $top}
4249 global curview viewperm hlview selectedhlview
4251 if {$curview == 0} return
4252 if {[info exists hlview] && $hlview == $curview} {
4253 set selectedhlview [mc "None"]
4256 allviewmenus $curview delete
4257 set viewperm($curview) 0
4261 proc addviewmenu {n} {
4262 global viewname viewhlmenu
4264 .bar.view add radiobutton -label $viewname($n) \
4265 -command [list showview $n] -variable selectedview -value $n
4266 #$viewhlmenu add radiobutton -label $viewname($n) \
4267 # -command [list addvhighlight $n] -variable selectedhlview
4271 global curview cached_commitrow ordertok
4272 global displayorder parentlist rowidlist rowisopt rowfinal
4273 global colormap rowtextx nextcolor canvxmax
4274 global numcommits viewcomplete
4275 global selectedline currentid canv canvy0
4277 global pending_select mainheadid
4280 global hlview selectedhlview commitinterest
4282 if {$n == $curview} return
4284 set ymax [lindex [$canv cget -scrollregion] 3]
4285 set span [$canv yview]
4286 set ytop [expr {[lindex $span 0] * $ymax}]
4287 set ybot [expr {[lindex $span 1] * $ymax}]
4288 set yscreen [expr {($ybot - $ytop) / 2}]
4289 if {$selectedline ne {}} {
4290 set selid $currentid
4291 set y [yc $selectedline]
4292 if {$ytop < $y && $y < $ybot} {
4293 set yscreen [expr {$y - $ytop}]
4295 } elseif {[info exists pending_select]} {
4296 set selid $pending_select
4297 unset pending_select
4301 catch {unset treediffs}
4303 if {[info exists hlview] && $hlview == $n} {
4305 set selectedhlview [mc "None"]
4307 catch {unset commitinterest}
4308 catch {unset cached_commitrow}
4309 catch {unset ordertok}
4313 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4314 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4317 if {![info exists viewcomplete($n)]} {
4327 set numcommits $commitidx($n)
4329 catch {unset colormap}
4330 catch {unset rowtextx}
4332 set canvxmax [$canv cget -width]
4338 if {$selid ne {} && [commitinview $selid $n]} {
4339 set row [rowofcommit $selid]
4340 # try to get the selected row in the same position on the screen
4341 set ymax [lindex [$canv cget -scrollregion] 3]
4342 set ytop [expr {[yc $row] - $yscreen}]
4346 set yf [expr {$ytop * 1.0 / $ymax}]
4348 allcanvs yview moveto $yf
4352 } elseif {!$viewcomplete($n)} {
4353 reset_pending_select $selid
4355 reset_pending_select {}
4357 if {[commitinview $pending_select $curview]} {
4358 selectline [rowofcommit $pending_select] 1
4360 set row [first_real_row]
4361 if {$row < $numcommits} {
4366 if {!$viewcomplete($n)} {
4367 if {$numcommits == 0} {
4368 show_status [mc "Reading commits..."]
4370 } elseif {$numcommits == 0} {
4371 show_status [mc "No commits selected"]
4375 # Stuff relating to the highlighting facility
4377 proc ishighlighted {id} {
4378 global vhighlights fhighlights nhighlights rhighlights
4380 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4381 return $nhighlights($id)
4383 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4384 return $vhighlights($id)
4386 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4387 return $fhighlights($id)
4389 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4390 return $rhighlights($id)
4395 proc bolden {id font} {
4396 global canv linehtag currentid boldids need_redisplay markedid
4398 # need_redisplay = 1 means the display is stale and about to be redrawn
4399 if {$need_redisplay} return
4401 $canv itemconf $linehtag($id) -font $font
4402 if {[info exists currentid] && $id eq $currentid} {
4404 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4405 -outline {{}} -tags secsel \
4406 -fill [$canv cget -selectbackground]]
4409 if {[info exists markedid] && $id eq $markedid} {
4414 proc bolden_name {id font} {
4415 global canv2 linentag currentid boldnameids need_redisplay
4417 if {$need_redisplay} return
4418 lappend boldnameids $id
4419 $canv2 itemconf $linentag($id) -font $font
4420 if {[info exists currentid] && $id eq $currentid} {
4421 $canv2 delete secsel
4422 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4423 -outline {{}} -tags secsel \
4424 -fill [$canv2 cget -selectbackground]]
4433 foreach id $boldids {
4434 if {![ishighlighted $id]} {
4437 lappend stillbold $id
4440 set boldids $stillbold
4443 proc addvhighlight {n} {
4444 global hlview viewcomplete curview vhl_done commitidx
4446 if {[info exists hlview]} {
4450 if {$n != $curview && ![info exists viewcomplete($n)]} {
4453 set vhl_done $commitidx($hlview)
4454 if {$vhl_done > 0} {
4459 proc delvhighlight {} {
4460 global hlview vhighlights
4462 if {![info exists hlview]} return
4464 catch {unset vhighlights}
4468 proc vhighlightmore {} {
4469 global hlview vhl_done commitidx vhighlights curview
4471 set max $commitidx($hlview)
4472 set vr [visiblerows]
4473 set r0 [lindex $vr 0]
4474 set r1 [lindex $vr 1]
4475 for {set i $vhl_done} {$i < $max} {incr i} {
4476 set id [commitonrow $i $hlview]
4477 if {[commitinview $id $curview]} {
4478 set row [rowofcommit $id]
4479 if {$r0 <= $row && $row <= $r1} {
4480 if {![highlighted $row]} {
4481 bolden $id mainfontbold
4483 set vhighlights($id) 1
4491 proc askvhighlight {row id} {
4492 global hlview vhighlights iddrawn
4494 if {[commitinview $id $hlview]} {
4495 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4496 bolden $id mainfontbold
4498 set vhighlights($id) 1
4500 set vhighlights($id) 0
4504 proc hfiles_change {} {
4505 global highlight_files filehighlight fhighlights fh_serial
4506 global highlight_paths
4508 if {[info exists filehighlight]} {
4509 # delete previous highlights
4510 catch {close $filehighlight}
4512 catch {unset fhighlights}
4514 unhighlight_filelist
4516 set highlight_paths {}
4517 after cancel do_file_hl $fh_serial
4519 if {$highlight_files ne {}} {
4520 after 300 do_file_hl $fh_serial
4524 proc gdttype_change {name ix op} {
4525 global gdttype highlight_files findstring findpattern
4528 if {$findstring ne {}} {
4529 if {$gdttype eq [mc "containing:"]} {
4530 if {$highlight_files ne {}} {
4531 set highlight_files {}
4536 if {$findpattern ne {}} {
4540 set highlight_files $findstring
4545 # enable/disable findtype/findloc menus too
4548 proc find_change {name ix op} {
4549 global gdttype findstring highlight_files
4552 if {$gdttype eq [mc "containing:"]} {
4555 if {$highlight_files ne $findstring} {
4556 set highlight_files $findstring
4563 proc findcom_change args {
4564 global nhighlights boldnameids
4565 global findpattern findtype findstring gdttype
4568 # delete previous highlights, if any
4569 foreach id $boldnameids {
4570 bolden_name $id mainfont
4573 catch {unset nhighlights}
4576 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4578 } elseif {$findtype eq [mc "Regexp"]} {
4579 set findpattern $findstring
4581 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4583 set findpattern "*$e*"
4587 proc makepatterns {l} {
4590 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4591 if {[string index $ee end] eq "/"} {
4601 proc do_file_hl {serial} {
4602 global highlight_files filehighlight highlight_paths gdttype fhl_list
4603 global cdup findtype
4605 if {$gdttype eq [mc "touching paths:"]} {
4606 # If "exact" match then convert backslashes to forward slashes.
4607 # Most useful to support Windows-flavoured file paths.
4608 if {$findtype eq [mc "Exact"]} {
4609 set highlight_files [string map {"\\" "/"} $highlight_files]
4611 if {[catch {set paths [shellsplit $highlight_files]}]} return
4612 set highlight_paths [makepatterns $paths]
4614 set relative_paths {}
4615 foreach path $paths {
4616 lappend relative_paths [file join $cdup $path]
4618 set gdtargs [concat -- $relative_paths]
4619 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4620 set gdtargs [list "-S$highlight_files"]
4622 # must be "containing:", i.e. we're searching commit info
4625 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4626 set filehighlight [open $cmd r+]
4627 fconfigure $filehighlight -blocking 0
4628 filerun $filehighlight readfhighlight
4634 proc flushhighlights {} {
4635 global filehighlight fhl_list
4637 if {[info exists filehighlight]} {
4639 puts $filehighlight ""
4640 flush $filehighlight
4644 proc askfilehighlight {row id} {
4645 global filehighlight fhighlights fhl_list
4647 lappend fhl_list $id
4648 set fhighlights($id) -1
4649 puts $filehighlight $id
4652 proc readfhighlight {} {
4653 global filehighlight fhighlights curview iddrawn
4654 global fhl_list find_dirn
4656 if {![info exists filehighlight]} {
4660 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4661 set line [string trim $line]
4662 set i [lsearch -exact $fhl_list $line]
4663 if {$i < 0} continue
4664 for {set j 0} {$j < $i} {incr j} {
4665 set id [lindex $fhl_list $j]
4666 set fhighlights($id) 0
4668 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4669 if {$line eq {}} continue
4670 if {![commitinview $line $curview]} continue
4671 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4672 bolden $line mainfontbold
4674 set fhighlights($line) 1
4676 if {[eof $filehighlight]} {
4678 puts "oops, git diff-tree died"
4679 catch {close $filehighlight}
4683 if {[info exists find_dirn]} {
4689 proc doesmatch {f} {
4690 global findtype findpattern
4692 if {$findtype eq [mc "Regexp"]} {
4693 return [regexp $findpattern $f]
4694 } elseif {$findtype eq [mc "IgnCase"]} {
4695 return [string match -nocase $findpattern $f]
4697 return [string match $findpattern $f]
4701 proc askfindhighlight {row id} {
4702 global nhighlights commitinfo iddrawn
4704 global markingmatches
4706 if {![info exists commitinfo($id)]} {
4709 set info $commitinfo($id)
4711 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4712 foreach f $info ty $fldtypes {
4713 if {$ty eq ""} continue
4714 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4716 if {$ty eq [mc "Author"]} {
4723 if {$isbold && [info exists iddrawn($id)]} {
4724 if {![ishighlighted $id]} {
4725 bolden $id mainfontbold
4727 bolden_name $id mainfontbold
4730 if {$markingmatches} {
4731 markrowmatches $row $id
4734 set nhighlights($id) $isbold
4737 proc markrowmatches {row id} {
4738 global canv canv2 linehtag linentag commitinfo findloc
4740 set headline [lindex $commitinfo($id) 0]
4741 set author [lindex $commitinfo($id) 1]
4742 $canv delete match$row
4743 $canv2 delete match$row
4744 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4745 set m [findmatches $headline]
4747 markmatches $canv $row $headline $linehtag($id) $m \
4748 [$canv itemcget $linehtag($id) -font] $row
4751 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4752 set m [findmatches $author]
4754 markmatches $canv2 $row $author $linentag($id) $m \
4755 [$canv2 itemcget $linentag($id) -font] $row
4760 proc vrel_change {name ix op} {
4761 global highlight_related
4764 if {$highlight_related ne [mc "None"]} {
4769 # prepare for testing whether commits are descendents or ancestors of a
4770 proc rhighlight_sel {a} {
4771 global descendent desc_todo ancestor anc_todo
4772 global highlight_related
4774 catch {unset descendent}
4775 set desc_todo [list $a]
4776 catch {unset ancestor}
4777 set anc_todo [list $a]
4778 if {$highlight_related ne [mc "None"]} {
4784 proc rhighlight_none {} {
4787 catch {unset rhighlights}
4791 proc is_descendent {a} {
4792 global curview children descendent desc_todo
4795 set la [rowofcommit $a]
4799 for {set i 0} {$i < [llength $todo]} {incr i} {
4800 set do [lindex $todo $i]
4801 if {[rowofcommit $do] < $la} {
4802 lappend leftover $do
4805 foreach nk $children($v,$do) {
4806 if {![info exists descendent($nk)]} {
4807 set descendent($nk) 1
4815 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4819 set descendent($a) 0
4820 set desc_todo $leftover
4823 proc is_ancestor {a} {
4824 global curview parents ancestor anc_todo
4827 set la [rowofcommit $a]
4831 for {set i 0} {$i < [llength $todo]} {incr i} {
4832 set do [lindex $todo $i]
4833 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4834 lappend leftover $do
4837 foreach np $parents($v,$do) {
4838 if {![info exists ancestor($np)]} {
4847 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4852 set anc_todo $leftover
4855 proc askrelhighlight {row id} {
4856 global descendent highlight_related iddrawn rhighlights
4857 global selectedline ancestor
4859 if {$selectedline eq {}} return
4861 if {$highlight_related eq [mc "Descendant"] ||
4862 $highlight_related eq [mc "Not descendant"]} {
4863 if {![info exists descendent($id)]} {
4866 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4869 } elseif {$highlight_related eq [mc "Ancestor"] ||
4870 $highlight_related eq [mc "Not ancestor"]} {
4871 if {![info exists ancestor($id)]} {
4874 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4878 if {[info exists iddrawn($id)]} {
4879 if {$isbold && ![ishighlighted $id]} {
4880 bolden $id mainfontbold
4883 set rhighlights($id) $isbold
4886 # Graph layout functions
4888 proc shortids {ids} {
4891 if {[llength $id] > 1} {
4892 lappend res [shortids $id]
4893 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4894 lappend res [string range $id 0 7]
4905 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4906 if {($n & $mask) != 0} {
4907 set ret [concat $ret $o]
4909 set o [concat $o $o]
4914 proc ordertoken {id} {
4915 global ordertok curview varcid varcstart varctok curview parents children
4916 global nullid nullid2
4918 if {[info exists ordertok($id)]} {
4919 return $ordertok($id)
4924 if {[info exists varcid($curview,$id)]} {
4925 set a $varcid($curview,$id)
4926 set p [lindex $varcstart($curview) $a]
4928 set p [lindex $children($curview,$id) 0]
4930 if {[info exists ordertok($p)]} {
4931 set tok $ordertok($p)
4934 set id [first_real_child $curview,$p]
4937 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4940 if {[llength $parents($curview,$id)] == 1} {
4941 lappend todo [list $p {}]
4943 set j [lsearch -exact $parents($curview,$id) $p]
4945 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4947 lappend todo [list $p [strrep $j]]
4950 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4951 set p [lindex $todo $i 0]
4952 append tok [lindex $todo $i 1]
4953 set ordertok($p) $tok
4955 set ordertok($origid) $tok
4959 # Work out where id should go in idlist so that order-token
4960 # values increase from left to right
4961 proc idcol {idlist id {i 0}} {
4962 set t [ordertoken $id]
4966 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
4967 if {$i > [llength $idlist]} {
4968 set i [llength $idlist]
4970 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
4973 if {$t > [ordertoken [lindex $idlist $i]]} {
4974 while {[incr i] < [llength $idlist] &&
4975 $t >= [ordertoken [lindex $idlist $i]]} {}
4981 proc initlayout {} {
4982 global rowidlist rowisopt rowfinal displayorder parentlist
4983 global numcommits canvxmax canv
4985 global colormap rowtextx
4994 set canvxmax [$canv cget -width]
4995 catch {unset colormap}
4996 catch {unset rowtextx}
5000 proc setcanvscroll {} {
5001 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5002 global lastscrollset lastscrollrows
5004 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5005 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5006 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5007 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5008 set lastscrollset [clock clicks -milliseconds]
5009 set lastscrollrows $numcommits
5012 proc visiblerows {} {
5013 global canv numcommits linespc
5015 set ymax [lindex [$canv cget -scrollregion] 3]
5016 if {$ymax eq {} || $ymax == 0} return
5018 set y0 [expr {int([lindex $f 0] * $ymax)}]
5019 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5023 set y1 [expr {int([lindex $f 1] * $ymax)}]
5024 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5025 if {$r1 >= $numcommits} {
5026 set r1 [expr {$numcommits - 1}]
5028 return [list $r0 $r1]
5031 proc layoutmore {} {
5032 global commitidx viewcomplete curview
5033 global numcommits pending_select curview
5034 global lastscrollset lastscrollrows
5036 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5037 [clock clicks -milliseconds] - $lastscrollset > 500} {
5040 if {[info exists pending_select] &&
5041 [commitinview $pending_select $curview]} {
5043 selectline [rowofcommit $pending_select] 1
5048 # With path limiting, we mightn't get the actual HEAD commit,
5049 # so ask git rev-list what is the first ancestor of HEAD that
5050 # touches a file in the path limit.
5051 proc get_viewmainhead {view} {
5052 global viewmainheadid vfilelimit viewinstances mainheadid
5055 set rfd [open [concat | git rev-list -1 $mainheadid \
5056 -- $vfilelimit($view)] r]
5057 set j [reg_instance $rfd]
5058 lappend viewinstances($view) $j
5059 fconfigure $rfd -blocking 0
5060 filerun $rfd [list getviewhead $rfd $j $view]
5061 set viewmainheadid($curview) {}
5065 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5066 proc getviewhead {fd inst view} {
5067 global viewmainheadid commfd curview viewinstances showlocalchanges
5070 if {[gets $fd line] < 0} {
5074 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5077 set viewmainheadid($view) $id
5080 set i [lsearch -exact $viewinstances($view) $inst]
5082 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5084 if {$showlocalchanges && $id ne {} && $view == $curview} {
5090 proc doshowlocalchanges {} {
5091 global curview viewmainheadid
5093 if {$viewmainheadid($curview) eq {}} return
5094 if {[commitinview $viewmainheadid($curview) $curview]} {
5097 interestedin $viewmainheadid($curview) dodiffindex
5101 proc dohidelocalchanges {} {
5102 global nullid nullid2 lserial curview
5104 if {[commitinview $nullid $curview]} {
5105 removefakerow $nullid
5107 if {[commitinview $nullid2 $curview]} {
5108 removefakerow $nullid2
5113 # spawn off a process to do git diff-index --cached HEAD
5114 proc dodiffindex {} {
5115 global lserial showlocalchanges vfilelimit curview
5118 if {!$showlocalchanges || !$hasworktree} return
5120 set cmd "|git diff-index --cached HEAD"
5121 if {$vfilelimit($curview) ne {}} {
5122 set cmd [concat $cmd -- $vfilelimit($curview)]
5124 set fd [open $cmd r]
5125 fconfigure $fd -blocking 0
5126 set i [reg_instance $fd]
5127 filerun $fd [list readdiffindex $fd $lserial $i]
5130 proc readdiffindex {fd serial inst} {
5131 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5135 if {[gets $fd line] < 0} {
5141 # we only need to see one line and we don't really care what it says...
5144 if {$serial != $lserial} {
5148 # now see if there are any local changes not checked in to the index
5149 set cmd "|git diff-files"
5150 if {$vfilelimit($curview) ne {}} {
5151 set cmd [concat $cmd -- $vfilelimit($curview)]
5153 set fd [open $cmd r]
5154 fconfigure $fd -blocking 0
5155 set i [reg_instance $fd]
5156 filerun $fd [list readdifffiles $fd $serial $i]
5158 if {$isdiff && ![commitinview $nullid2 $curview]} {
5159 # add the line for the changes in the index to the graph
5160 set hl [mc "Local changes checked in to index but not committed"]
5161 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5162 set commitdata($nullid2) "\n $hl\n"
5163 if {[commitinview $nullid $curview]} {
5164 removefakerow $nullid
5166 insertfakerow $nullid2 $viewmainheadid($curview)
5167 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5168 if {[commitinview $nullid $curview]} {
5169 removefakerow $nullid
5171 removefakerow $nullid2
5176 proc readdifffiles {fd serial inst} {
5177 global viewmainheadid nullid nullid2 curview
5178 global commitinfo commitdata lserial
5181 if {[gets $fd line] < 0} {
5187 # we only need to see one line and we don't really care what it says...
5190 if {$serial != $lserial} {
5194 if {$isdiff && ![commitinview $nullid $curview]} {
5195 # add the line for the local diff to the graph
5196 set hl [mc "Local uncommitted changes, not checked in to index"]
5197 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5198 set commitdata($nullid) "\n $hl\n"
5199 if {[commitinview $nullid2 $curview]} {
5202 set p $viewmainheadid($curview)
5204 insertfakerow $nullid $p
5205 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5206 removefakerow $nullid
5211 proc nextuse {id row} {
5212 global curview children
5214 if {[info exists children($curview,$id)]} {
5215 foreach kid $children($curview,$id) {
5216 if {![commitinview $kid $curview]} {
5219 if {[rowofcommit $kid] > $row} {
5220 return [rowofcommit $kid]
5224 if {[commitinview $id $curview]} {
5225 return [rowofcommit $id]
5230 proc prevuse {id row} {
5231 global curview children
5234 if {[info exists children($curview,$id)]} {
5235 foreach kid $children($curview,$id) {
5236 if {![commitinview $kid $curview]} break
5237 if {[rowofcommit $kid] < $row} {
5238 set ret [rowofcommit $kid]
5245 proc make_idlist {row} {
5246 global displayorder parentlist uparrowlen downarrowlen mingaplen
5247 global commitidx curview children
5249 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5253 set ra [expr {$row - $downarrowlen}]
5257 set rb [expr {$row + $uparrowlen}]
5258 if {$rb > $commitidx($curview)} {
5259 set rb $commitidx($curview)
5261 make_disporder $r [expr {$rb + 1}]
5263 for {} {$r < $ra} {incr r} {
5264 set nextid [lindex $displayorder [expr {$r + 1}]]
5265 foreach p [lindex $parentlist $r] {
5266 if {$p eq $nextid} continue
5267 set rn [nextuse $p $r]
5269 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5270 lappend ids [list [ordertoken $p] $p]
5274 for {} {$r < $row} {incr r} {
5275 set nextid [lindex $displayorder [expr {$r + 1}]]
5276 foreach p [lindex $parentlist $r] {
5277 if {$p eq $nextid} continue
5278 set rn [nextuse $p $r]
5279 if {$rn < 0 || $rn >= $row} {
5280 lappend ids [list [ordertoken $p] $p]
5284 set id [lindex $displayorder $row]
5285 lappend ids [list [ordertoken $id] $id]
5287 foreach p [lindex $parentlist $r] {
5288 set firstkid [lindex $children($curview,$p) 0]
5289 if {[rowofcommit $firstkid] < $row} {
5290 lappend ids [list [ordertoken $p] $p]
5294 set id [lindex $displayorder $r]
5296 set firstkid [lindex $children($curview,$id) 0]
5297 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5298 lappend ids [list [ordertoken $id] $id]
5303 foreach idx [lsort -unique $ids] {
5304 lappend idlist [lindex $idx 1]
5309 proc rowsequal {a b} {
5310 while {[set i [lsearch -exact $a {}]] >= 0} {
5311 set a [lreplace $a $i $i]
5313 while {[set i [lsearch -exact $b {}]] >= 0} {
5314 set b [lreplace $b $i $i]
5316 return [expr {$a eq $b}]
5319 proc makeupline {id row rend col} {
5320 global rowidlist uparrowlen downarrowlen mingaplen
5322 for {set r $rend} {1} {set r $rstart} {
5323 set rstart [prevuse $id $r]
5324 if {$rstart < 0} return
5325 if {$rstart < $row} break
5327 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5328 set rstart [expr {$rend - $uparrowlen - 1}]
5330 for {set r $rstart} {[incr r] <= $row} {} {
5331 set idlist [lindex $rowidlist $r]
5332 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5333 set col [idcol $idlist $id $col]
5334 lset rowidlist $r [linsert $idlist $col $id]
5340 proc layoutrows {row endrow} {
5341 global rowidlist rowisopt rowfinal displayorder
5342 global uparrowlen downarrowlen maxwidth mingaplen
5343 global children parentlist
5344 global commitidx viewcomplete curview
5346 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5349 set rm1 [expr {$row - 1}]
5350 foreach id [lindex $rowidlist $rm1] {
5355 set final [lindex $rowfinal $rm1]
5357 for {} {$row < $endrow} {incr row} {
5358 set rm1 [expr {$row - 1}]
5359 if {$rm1 < 0 || $idlist eq {}} {
5360 set idlist [make_idlist $row]
5363 set id [lindex $displayorder $rm1]
5364 set col [lsearch -exact $idlist $id]
5365 set idlist [lreplace $idlist $col $col]
5366 foreach p [lindex $parentlist $rm1] {
5367 if {[lsearch -exact $idlist $p] < 0} {
5368 set col [idcol $idlist $p $col]
5369 set idlist [linsert $idlist $col $p]
5370 # if not the first child, we have to insert a line going up
5371 if {$id ne [lindex $children($curview,$p) 0]} {
5372 makeupline $p $rm1 $row $col
5376 set id [lindex $displayorder $row]
5377 if {$row > $downarrowlen} {
5378 set termrow [expr {$row - $downarrowlen - 1}]
5379 foreach p [lindex $parentlist $termrow] {
5380 set i [lsearch -exact $idlist $p]
5381 if {$i < 0} continue
5382 set nr [nextuse $p $termrow]
5383 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5384 set idlist [lreplace $idlist $i $i]
5388 set col [lsearch -exact $idlist $id]
5390 set col [idcol $idlist $id]
5391 set idlist [linsert $idlist $col $id]
5392 if {$children($curview,$id) ne {}} {
5393 makeupline $id $rm1 $row $col
5396 set r [expr {$row + $uparrowlen - 1}]
5397 if {$r < $commitidx($curview)} {
5399 foreach p [lindex $parentlist $r] {
5400 if {[lsearch -exact $idlist $p] >= 0} continue
5401 set fk [lindex $children($curview,$p) 0]
5402 if {[rowofcommit $fk] < $row} {
5403 set x [idcol $idlist $p $x]
5404 set idlist [linsert $idlist $x $p]
5407 if {[incr r] < $commitidx($curview)} {
5408 set p [lindex $displayorder $r]
5409 if {[lsearch -exact $idlist $p] < 0} {
5410 set fk [lindex $children($curview,$p) 0]
5411 if {$fk ne {} && [rowofcommit $fk] < $row} {
5412 set x [idcol $idlist $p $x]
5413 set idlist [linsert $idlist $x $p]
5419 if {$final && !$viewcomplete($curview) &&
5420 $row + $uparrowlen + $mingaplen + $downarrowlen
5421 >= $commitidx($curview)} {
5424 set l [llength $rowidlist]
5426 lappend rowidlist $idlist
5428 lappend rowfinal $final
5429 } elseif {$row < $l} {
5430 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5431 lset rowidlist $row $idlist
5434 lset rowfinal $row $final
5436 set pad [ntimes [expr {$row - $l}] {}]
5437 set rowidlist [concat $rowidlist $pad]
5438 lappend rowidlist $idlist
5439 set rowfinal [concat $rowfinal $pad]
5440 lappend rowfinal $final
5441 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5447 proc changedrow {row} {
5448 global displayorder iddrawn rowisopt need_redisplay
5450 set l [llength $rowisopt]
5452 lset rowisopt $row 0
5453 if {$row + 1 < $l} {
5454 lset rowisopt [expr {$row + 1}] 0
5455 if {$row + 2 < $l} {
5456 lset rowisopt [expr {$row + 2}] 0
5460 set id [lindex $displayorder $row]
5461 if {[info exists iddrawn($id)]} {
5462 set need_redisplay 1
5466 proc insert_pad {row col npad} {
5469 set pad [ntimes $npad {}]
5470 set idlist [lindex $rowidlist $row]
5471 set bef [lrange $idlist 0 [expr {$col - 1}]]
5472 set aft [lrange $idlist $col end]
5473 set i [lsearch -exact $aft {}]
5475 set aft [lreplace $aft $i $i]
5477 lset rowidlist $row [concat $bef $pad $aft]
5481 proc optimize_rows {row col endrow} {
5482 global rowidlist rowisopt displayorder curview children
5487 for {} {$row < $endrow} {incr row; set col 0} {
5488 if {[lindex $rowisopt $row]} continue
5490 set y0 [expr {$row - 1}]
5491 set ym [expr {$row - 2}]
5492 set idlist [lindex $rowidlist $row]
5493 set previdlist [lindex $rowidlist $y0]
5494 if {$idlist eq {} || $previdlist eq {}} continue
5496 set pprevidlist [lindex $rowidlist $ym]
5497 if {$pprevidlist eq {}} continue
5503 for {} {$col < [llength $idlist]} {incr col} {
5504 set id [lindex $idlist $col]
5505 if {[lindex $previdlist $col] eq $id} continue
5510 set x0 [lsearch -exact $previdlist $id]
5511 if {$x0 < 0} continue
5512 set z [expr {$x0 - $col}]
5516 set xm [lsearch -exact $pprevidlist $id]
5518 set z0 [expr {$xm - $x0}]
5522 # if row y0 is the first child of $id then it's not an arrow
5523 if {[lindex $children($curview,$id) 0] ne
5524 [lindex $displayorder $y0]} {
5528 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5529 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5532 # Looking at lines from this row to the previous row,
5533 # make them go straight up if they end in an arrow on
5534 # the previous row; otherwise make them go straight up
5536 if {$z < -1 || ($z < 0 && $isarrow)} {
5537 # Line currently goes left too much;
5538 # insert pads in the previous row, then optimize it
5539 set npad [expr {-1 - $z + $isarrow}]
5540 insert_pad $y0 $x0 $npad
5542 optimize_rows $y0 $x0 $row
5544 set previdlist [lindex $rowidlist $y0]
5545 set x0 [lsearch -exact $previdlist $id]
5546 set z [expr {$x0 - $col}]
5548 set pprevidlist [lindex $rowidlist $ym]
5549 set xm [lsearch -exact $pprevidlist $id]
5550 set z0 [expr {$xm - $x0}]
5552 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5553 # Line currently goes right too much;
5554 # insert pads in this line
5555 set npad [expr {$z - 1 + $isarrow}]
5556 insert_pad $row $col $npad
5557 set idlist [lindex $rowidlist $row]
5559 set z [expr {$x0 - $col}]
5562 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5563 # this line links to its first child on row $row-2
5564 set id [lindex $displayorder $ym]
5565 set xc [lsearch -exact $pprevidlist $id]
5567 set z0 [expr {$xc - $x0}]
5570 # avoid lines jigging left then immediately right
5571 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5572 insert_pad $y0 $x0 1
5574 optimize_rows $y0 $x0 $row
5575 set previdlist [lindex $rowidlist $y0]
5579 # Find the first column that doesn't have a line going right
5580 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5581 set id [lindex $idlist $col]
5582 if {$id eq {}} break
5583 set x0 [lsearch -exact $previdlist $id]
5585 # check if this is the link to the first child
5586 set kid [lindex $displayorder $y0]
5587 if {[lindex $children($curview,$id) 0] eq $kid} {
5588 # it is, work out offset to child
5589 set x0 [lsearch -exact $previdlist $kid]
5592 if {$x0 <= $col} break
5594 # Insert a pad at that column as long as it has a line and
5595 # isn't the last column
5596 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5597 set idlist [linsert $idlist $col {}]
5598 lset rowidlist $row $idlist
5606 global canvx0 linespc
5607 return [expr {$canvx0 + $col * $linespc}]
5611 global canvy0 linespc
5612 return [expr {$canvy0 + $row * $linespc}]
5615 proc linewidth {id} {
5616 global thickerline lthickness
5619 if {[info exists thickerline] && $id eq $thickerline} {
5620 set wid [expr {2 * $lthickness}]
5625 proc rowranges {id} {
5626 global curview children uparrowlen downarrowlen
5629 set kids $children($curview,$id)
5635 foreach child $kids {
5636 if {![commitinview $child $curview]} break
5637 set row [rowofcommit $child]
5638 if {![info exists prev]} {
5639 lappend ret [expr {$row + 1}]
5641 if {$row <= $prevrow} {
5642 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5644 # see if the line extends the whole way from prevrow to row
5645 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5646 [lsearch -exact [lindex $rowidlist \
5647 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5648 # it doesn't, see where it ends
5649 set r [expr {$prevrow + $downarrowlen}]
5650 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5651 while {[incr r -1] > $prevrow &&
5652 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5654 while {[incr r] <= $row &&
5655 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5659 # see where it starts up again
5660 set r [expr {$row - $uparrowlen}]
5661 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5662 while {[incr r] < $row &&
5663 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5665 while {[incr r -1] >= $prevrow &&
5666 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5672 if {$child eq $id} {
5681 proc drawlineseg {id row endrow arrowlow} {
5682 global rowidlist displayorder iddrawn linesegs
5683 global canv colormap linespc curview maxlinelen parentlist
5685 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5686 set le [expr {$row + 1}]
5689 set c [lsearch -exact [lindex $rowidlist $le] $id]
5695 set x [lindex $displayorder $le]
5700 if {[info exists iddrawn($x)] || $le == $endrow} {
5701 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5717 if {[info exists linesegs($id)]} {
5718 set lines $linesegs($id)
5720 set r0 [lindex $li 0]
5722 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5732 set li [lindex $lines [expr {$i-1}]]
5733 set r1 [lindex $li 1]
5734 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5739 set x [lindex $cols [expr {$le - $row}]]
5740 set xp [lindex $cols [expr {$le - 1 - $row}]]
5741 set dir [expr {$xp - $x}]
5743 set ith [lindex $lines $i 2]
5744 set coords [$canv coords $ith]
5745 set ah [$canv itemcget $ith -arrow]
5746 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5747 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5748 if {$x2 ne {} && $x - $x2 == $dir} {
5749 set coords [lrange $coords 0 end-2]
5752 set coords [list [xc $le $x] [yc $le]]
5755 set itl [lindex $lines [expr {$i-1}] 2]
5756 set al [$canv itemcget $itl -arrow]
5757 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5758 } elseif {$arrowlow} {
5759 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5760 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5764 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5765 for {set y $le} {[incr y -1] > $row} {} {
5767 set xp [lindex $cols [expr {$y - 1 - $row}]]
5768 set ndir [expr {$xp - $x}]
5769 if {$dir != $ndir || $xp < 0} {
5770 lappend coords [xc $y $x] [yc $y]
5776 # join parent line to first child
5777 set ch [lindex $displayorder $row]
5778 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5780 puts "oops: drawlineseg: child $ch not on row $row"
5781 } elseif {$xc != $x} {
5782 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5783 set d [expr {int(0.5 * $linespc)}]
5786 set x2 [expr {$x1 - $d}]
5788 set x2 [expr {$x1 + $d}]
5791 set y1 [expr {$y2 + $d}]
5792 lappend coords $x1 $y1 $x2 $y2
5793 } elseif {$xc < $x - 1} {
5794 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5795 } elseif {$xc > $x + 1} {
5796 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5800 lappend coords [xc $row $x] [yc $row]
5802 set xn [xc $row $xp]
5804 lappend coords $xn $yn
5808 set t [$canv create line $coords -width [linewidth $id] \
5809 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5812 set lines [linsert $lines $i [list $row $le $t]]
5814 $canv coords $ith $coords
5815 if {$arrow ne $ah} {
5816 $canv itemconf $ith -arrow $arrow
5818 lset lines $i 0 $row
5821 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5822 set ndir [expr {$xo - $xp}]
5823 set clow [$canv coords $itl]
5824 if {$dir == $ndir} {
5825 set clow [lrange $clow 2 end]
5827 set coords [concat $coords $clow]
5829 lset lines [expr {$i-1}] 1 $le
5831 # coalesce two pieces
5833 set b [lindex $lines [expr {$i-1}] 0]
5834 set e [lindex $lines $i 1]
5835 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5837 $canv coords $itl $coords
5838 if {$arrow ne $al} {
5839 $canv itemconf $itl -arrow $arrow
5843 set linesegs($id) $lines
5847 proc drawparentlinks {id row} {
5848 global rowidlist canv colormap curview parentlist
5849 global idpos linespc
5851 set rowids [lindex $rowidlist $row]
5852 set col [lsearch -exact $rowids $id]
5853 if {$col < 0} return
5854 set olds [lindex $parentlist $row]
5855 set row2 [expr {$row + 1}]
5856 set x [xc $row $col]
5859 set d [expr {int(0.5 * $linespc)}]
5860 set ymid [expr {$y + $d}]
5861 set ids [lindex $rowidlist $row2]
5862 # rmx = right-most X coord used
5865 set i [lsearch -exact $ids $p]
5867 puts "oops, parent $p of $id not in list"
5870 set x2 [xc $row2 $i]
5874 set j [lsearch -exact $rowids $p]
5876 # drawlineseg will do this one for us
5880 # should handle duplicated parents here...
5881 set coords [list $x $y]
5883 # if attaching to a vertical segment, draw a smaller
5884 # slant for visual distinctness
5887 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5889 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5891 } elseif {$i < $col && $i < $j} {
5892 # segment slants towards us already
5893 lappend coords [xc $row $j] $y
5895 if {$i < $col - 1} {
5896 lappend coords [expr {$x2 + $linespc}] $y
5897 } elseif {$i > $col + 1} {
5898 lappend coords [expr {$x2 - $linespc}] $y
5900 lappend coords $x2 $y2
5903 lappend coords $x2 $y2
5905 set t [$canv create line $coords -width [linewidth $p] \
5906 -fill $colormap($p) -tags lines.$p]
5910 if {$rmx > [lindex $idpos($id) 1]} {
5911 lset idpos($id) 1 $rmx
5916 proc drawlines {id} {
5919 $canv itemconf lines.$id -width [linewidth $id]
5922 proc drawcmittext {id row col} {
5923 global linespc canv canv2 canv3 fgcolor curview
5924 global cmitlisted commitinfo rowidlist parentlist
5925 global rowtextx idpos idtags idheads idotherrefs
5926 global linehtag linentag linedtag selectedline
5927 global canvxmax boldids boldnameids fgcolor markedid
5928 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5930 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5931 set listed $cmitlisted($curview,$id)
5932 if {$id eq $nullid} {
5934 } elseif {$id eq $nullid2} {
5936 } elseif {$id eq $mainheadid} {
5939 set ofill [lindex $circlecolors $listed]
5941 set x [xc $row $col]
5943 set orad [expr {$linespc / 3}]
5945 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5946 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5947 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5948 } elseif {$listed == 3} {
5949 # triangle pointing left for left-side commits
5950 set t [$canv create polygon \
5951 [expr {$x - $orad}] $y \
5952 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5953 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5954 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5956 # triangle pointing right for right-side commits
5957 set t [$canv create polygon \
5958 [expr {$x + $orad - 1}] $y \
5959 [expr {$x - $orad}] [expr {$y - $orad}] \
5960 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
5961 -fill $ofill -outline $fgcolor -width 1 -tags circle]
5963 set circleitem($row) $t
5965 $canv bind $t <1> {selcanvline {} %x %y}
5966 set rmx [llength [lindex $rowidlist $row]]
5967 set olds [lindex $parentlist $row]
5969 set nextids [lindex $rowidlist [expr {$row + 1}]]
5971 set i [lsearch -exact $nextids $p]
5977 set xt [xc $row $rmx]
5978 set rowtextx($row) $xt
5979 set idpos($id) [list $x $xt $y]
5980 if {[info exists idtags($id)] || [info exists idheads($id)]
5981 || [info exists idotherrefs($id)]} {
5982 set xt [drawtags $id $x $xt $y]
5984 if {[lindex $commitinfo($id) 6] > 0} {
5985 set xt [drawnotesign $xt $y]
5987 set headline [lindex $commitinfo($id) 0]
5988 set name [lindex $commitinfo($id) 1]
5989 set date [lindex $commitinfo($id) 2]
5990 set date [formatdate $date]
5993 set isbold [ishighlighted $id]
5996 set font mainfontbold
5998 lappend boldnameids $id
5999 set nfont mainfontbold
6002 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6003 -text $headline -font $font -tags text]
6004 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6005 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6006 -text $name -font $nfont -tags text]
6007 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6008 -text $date -font mainfont -tags text]
6009 if {$selectedline == $row} {
6012 if {[info exists markedid] && $markedid eq $id} {
6015 set xr [expr {$xt + [font measure $font $headline]}]
6016 if {$xr > $canvxmax} {
6022 proc drawcmitrow {row} {
6023 global displayorder rowidlist nrows_drawn
6024 global iddrawn markingmatches
6025 global commitinfo numcommits
6026 global filehighlight fhighlights findpattern nhighlights
6027 global hlview vhighlights
6028 global highlight_related rhighlights
6030 if {$row >= $numcommits} return
6032 set id [lindex $displayorder $row]
6033 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6034 askvhighlight $row $id
6036 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6037 askfilehighlight $row $id
6039 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6040 askfindhighlight $row $id
6042 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6043 askrelhighlight $row $id
6045 if {![info exists iddrawn($id)]} {
6046 set col [lsearch -exact [lindex $rowidlist $row] $id]
6048 puts "oops, row $row id $id not in list"
6051 if {![info exists commitinfo($id)]} {
6055 drawcmittext $id $row $col
6059 if {$markingmatches} {
6060 markrowmatches $row $id
6064 proc drawcommits {row {endrow {}}} {
6065 global numcommits iddrawn displayorder curview need_redisplay
6066 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6071 if {$endrow eq {}} {
6074 if {$endrow >= $numcommits} {
6075 set endrow [expr {$numcommits - 1}]
6078 set rl1 [expr {$row - $downarrowlen - 3}]
6082 set ro1 [expr {$row - 3}]
6086 set r2 [expr {$endrow + $uparrowlen + 3}]
6087 if {$r2 > $numcommits} {
6090 for {set r $rl1} {$r < $r2} {incr r} {
6091 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6095 set rl1 [expr {$r + 1}]
6101 optimize_rows $ro1 0 $r2
6102 if {$need_redisplay || $nrows_drawn > 2000} {
6106 # make the lines join to already-drawn rows either side
6107 set r [expr {$row - 1}]
6108 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6111 set er [expr {$endrow + 1}]
6112 if {$er >= $numcommits ||
6113 ![info exists iddrawn([lindex $displayorder $er])]} {
6116 for {} {$r <= $er} {incr r} {
6117 set id [lindex $displayorder $r]
6118 set wasdrawn [info exists iddrawn($id)]
6120 if {$r == $er} break
6121 set nextid [lindex $displayorder [expr {$r + 1}]]
6122 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6123 drawparentlinks $id $r
6125 set rowids [lindex $rowidlist $r]
6126 foreach lid $rowids {
6127 if {$lid eq {}} continue
6128 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6130 # see if this is the first child of any of its parents
6131 foreach p [lindex $parentlist $r] {
6132 if {[lsearch -exact $rowids $p] < 0} {
6133 # make this line extend up to the child
6134 set lineend($p) [drawlineseg $p $r $er 0]
6138 set lineend($lid) [drawlineseg $lid $r $er 1]
6144 proc undolayout {row} {
6145 global uparrowlen mingaplen downarrowlen
6146 global rowidlist rowisopt rowfinal need_redisplay
6148 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6152 if {[llength $rowidlist] > $r} {
6154 set rowidlist [lrange $rowidlist 0 $r]
6155 set rowfinal [lrange $rowfinal 0 $r]
6156 set rowisopt [lrange $rowisopt 0 $r]
6157 set need_redisplay 1
6162 proc drawvisible {} {
6163 global canv linespc curview vrowmod selectedline targetrow targetid
6164 global need_redisplay cscroll numcommits
6166 set fs [$canv yview]
6167 set ymax [lindex [$canv cget -scrollregion] 3]
6168 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6169 set f0 [lindex $fs 0]
6170 set f1 [lindex $fs 1]
6171 set y0 [expr {int($f0 * $ymax)}]
6172 set y1 [expr {int($f1 * $ymax)}]
6174 if {[info exists targetid]} {
6175 if {[commitinview $targetid $curview]} {
6176 set r [rowofcommit $targetid]
6177 if {$r != $targetrow} {
6178 # Fix up the scrollregion and change the scrolling position
6179 # now that our target row has moved.
6180 set diff [expr {($r - $targetrow) * $linespc}]
6183 set ymax [lindex [$canv cget -scrollregion] 3]
6186 set f0 [expr {$y0 / $ymax}]
6187 set f1 [expr {$y1 / $ymax}]
6188 allcanvs yview moveto $f0
6189 $cscroll set $f0 $f1
6190 set need_redisplay 1
6197 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6198 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6199 if {$endrow >= $vrowmod($curview)} {
6200 update_arcrows $curview
6202 if {$selectedline ne {} &&
6203 $row <= $selectedline && $selectedline <= $endrow} {
6204 set targetrow $selectedline
6205 } elseif {[info exists targetid]} {
6206 set targetrow [expr {int(($row + $endrow) / 2)}]
6208 if {[info exists targetrow]} {
6209 if {$targetrow >= $numcommits} {
6210 set targetrow [expr {$numcommits - 1}]
6212 set targetid [commitonrow $targetrow]
6214 drawcommits $row $endrow
6217 proc clear_display {} {
6218 global iddrawn linesegs need_redisplay nrows_drawn
6219 global vhighlights fhighlights nhighlights rhighlights
6220 global linehtag linentag linedtag boldids boldnameids
6223 catch {unset iddrawn}
6224 catch {unset linesegs}
6225 catch {unset linehtag}
6226 catch {unset linentag}
6227 catch {unset linedtag}
6230 catch {unset vhighlights}
6231 catch {unset fhighlights}
6232 catch {unset nhighlights}
6233 catch {unset rhighlights}
6234 set need_redisplay 0
6238 proc findcrossings {id} {
6239 global rowidlist parentlist numcommits displayorder
6243 foreach {s e} [rowranges $id] {
6244 if {$e >= $numcommits} {
6245 set e [expr {$numcommits - 1}]
6247 if {$e <= $s} continue
6248 for {set row $e} {[incr row -1] >= $s} {} {
6249 set x [lsearch -exact [lindex $rowidlist $row] $id]
6251 set olds [lindex $parentlist $row]
6252 set kid [lindex $displayorder $row]
6253 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6254 if {$kidx < 0} continue
6255 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6257 set px [lsearch -exact $nextrow $p]
6258 if {$px < 0} continue
6259 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6260 if {[lsearch -exact $ccross $p] >= 0} continue
6261 if {$x == $px + ($kidx < $px? -1: 1)} {
6263 } elseif {[lsearch -exact $cross $p] < 0} {
6270 return [concat $ccross {{}} $cross]
6273 proc assigncolor {id} {
6274 global colormap colors nextcolor
6275 global parents children children curview
6277 if {[info exists colormap($id)]} return
6278 set ncolors [llength $colors]
6279 if {[info exists children($curview,$id)]} {
6280 set kids $children($curview,$id)
6284 if {[llength $kids] == 1} {
6285 set child [lindex $kids 0]
6286 if {[info exists colormap($child)]
6287 && [llength $parents($curview,$child)] == 1} {
6288 set colormap($id) $colormap($child)
6294 foreach x [findcrossings $id] {
6296 # delimiter between corner crossings and other crossings
6297 if {[llength $badcolors] >= $ncolors - 1} break
6298 set origbad $badcolors
6300 if {[info exists colormap($x)]
6301 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6302 lappend badcolors $colormap($x)
6305 if {[llength $badcolors] >= $ncolors} {
6306 set badcolors $origbad
6308 set origbad $badcolors
6309 if {[llength $badcolors] < $ncolors - 1} {
6310 foreach child $kids {
6311 if {[info exists colormap($child)]
6312 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6313 lappend badcolors $colormap($child)
6315 foreach p $parents($curview,$child) {
6316 if {[info exists colormap($p)]
6317 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6318 lappend badcolors $colormap($p)
6322 if {[llength $badcolors] >= $ncolors} {
6323 set badcolors $origbad
6326 for {set i 0} {$i <= $ncolors} {incr i} {
6327 set c [lindex $colors $nextcolor]
6328 if {[incr nextcolor] >= $ncolors} {
6331 if {[lsearch -exact $badcolors $c]} break
6333 set colormap($id) $c
6336 proc bindline {t id} {
6339 $canv bind $t <Enter> "lineenter %x %y $id"
6340 $canv bind $t <Motion> "linemotion %x %y $id"
6341 $canv bind $t <Leave> "lineleave $id"
6342 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6345 proc drawtags {id x xt y1} {
6346 global idtags idheads idotherrefs mainhead
6347 global linespc lthickness
6348 global canv rowtextx curview fgcolor bgcolor ctxbut
6353 if {[info exists idtags($id)]} {
6354 set marks $idtags($id)
6355 set ntags [llength $marks]
6357 if {[info exists idheads($id)]} {
6358 set marks [concat $marks $idheads($id)]
6359 set nheads [llength $idheads($id)]
6361 if {[info exists idotherrefs($id)]} {
6362 set marks [concat $marks $idotherrefs($id)]
6368 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6369 set yt [expr {$y1 - 0.5 * $linespc}]
6370 set yb [expr {$yt + $linespc - 1}]
6374 foreach tag $marks {
6376 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6377 set wid [font measure mainfontbold $tag]
6379 set wid [font measure mainfont $tag]
6383 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6385 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
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