2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright © 2005-2011 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
13 return [expr {[exec git rev-parse
--is-bare-repository] == "false" &&
14 [exec git rev-parse
--is-inside-git-dir] == "false"}]
19 set n
[file normalize
$gitdir]
20 if {[string match
"*/.git" $n]} {
21 set n
[string range
$n 0 end-5
]
28 if {[info exists _gitworktree
]} {
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch
{set _gitworktree
[exec git rev-parse
--show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch
{ set _gitworktree
$env(GIT_WORK_TREE
) }]} {
37 catch
{set _gitworktree
[exec git config
--get core.worktree
]}
38 if {$_gitworktree eq
""} {
39 set _gitworktree
[file normalize .
/[exec git rev-parse
--show-cdup]]
46 # A simple scheduler for compute-intensive stuff.
47 # The aim is to make sure that event handlers for GUI actions can
48 # run at least every 50-100 ms. Unfortunately fileevent handlers are
49 # run before X event handlers, so reading from a fast source can
50 # make the GUI completely unresponsive.
52 global isonrunq runq currunq
55 if {[info exists isonrunq
($script)]} return
56 if {$runq eq
{} && ![info exists currunq
]} {
59 lappend runq
[list
{} $script]
60 set isonrunq
($script) 1
63 proc filerun
{fd
script} {
64 fileevent
$fd readable
[list filereadable
$fd $script]
67 proc filereadable
{fd
script} {
70 fileevent
$fd readable
{}
71 if {$runq eq
{} && ![info exists currunq
]} {
74 lappend runq
[list
$fd $script]
80 for {set i
0} {$i < [llength
$runq]} {} {
81 if {[lindex
$runq $i 0] eq
$fd} {
82 set runq
[lreplace
$runq $i $i]
90 global isonrunq runq currunq
92 set tstart
[clock clicks
-milliseconds]
94 while {[llength
$runq] > 0} {
95 set fd
[lindex
$runq 0 0]
96 set script [lindex
$runq 0 1]
97 set currunq
[lindex
$runq 0]
98 set runq
[lrange
$runq 1 end
]
99 set repeat
[eval $script]
101 set t1
[clock clicks
-milliseconds]
102 set t
[expr {$t1 - $t0}]
103 if {$repeat ne
{} && $repeat} {
104 if {$fd eq
{} ||
$repeat == 2} {
105 # script returns 1 if it wants to be readded
106 # file readers return 2 if they could do more straight away
107 lappend runq
[list
$fd $script]
109 fileevent
$fd readable
[list filereadable
$fd $script]
111 } elseif
{$fd eq
{}} {
112 unset isonrunq
($script)
115 if {$t1 - $tstart >= 80} break
122 proc reg_instance
{fd
} {
123 global commfd leftover loginstance
125 set i
[incr loginstance
]
131 proc unmerged_files
{files
} {
134 # find the list of unmerged files
138 set fd
[open
"| git ls-files -u" r
]
140 show_error
{} .
"[mc "Couldn
't get list of unmerged files:"] $err"
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
149 if {$files eq {} || [path_filter $files $fname]} {
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
159 global worddiff git_version
167 set origargs $arglist
171 foreach arg $arglist {
178 switch -glob -- $arg {
182 # remove from origargs in case we hit an unknown option
183 set origargs [lreplace $origargs $i $i]
187 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
188 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
189 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
190 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
191 "--ignore-space-change" - "-U*" - "--unified=*" {
192 # These request or affect diff output, which we don't want.
193 # Some could be used to set our defaults for diff display.
194 lappend diffargs
$arg
196 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
197 "--name-only" - "--name-status" - "--color" -
198 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
199 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
200 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
201 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
202 "--objects" - "--objects-edge" - "--reverse" {
203 # These cause our parsing of git log's output to fail, or else
204 # they're options we want to set ourselves, so ignore them.
206 "--color-words*" - "--word-diff=color" {
207 # These trigger a word diff in the console interface,
208 # so help the user by enabling our own support
209 if {[package vcompare
$git_version "1.7.2"] >= 0} {
210 set worddiff
[mc
"Color words"]
214 if {[package vcompare
$git_version "1.7.2"] >= 0} {
215 set worddiff
[mc
"Markup words"]
218 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
219 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
220 "--full-history" - "--dense" - "--sparse" -
221 "--follow" - "--left-right" - "--encoding=*" {
222 # These are harmless, and some are even useful
225 "--diff-filter=*" - "--no-merges" - "--unpacked" -
226 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
227 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
228 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
229 "--remove-empty" - "--first-parent" - "--cherry-pick" -
230 "-S*" - "--pickaxe-all" - "--pickaxe-regex" -
231 "--simplify-by-decoration" {
232 # These mean that we get a subset of the commits
237 # This appears to be the only one that has a value as a
238 # separate word following it
248 # git rev-parse doesn't understand --merge
249 lappend revargs
--gitk-symmetric-diff-marker MERGE_HEAD...HEAD
251 "--no-replace-objects" {
252 set env
(GIT_NO_REPLACE_OBJECTS
) "1"
255 # Other flag arguments including -<n>
256 if {[string is digit
-strict [string range
$arg 1 end
]]} {
259 # a flag argument that we don't recognize;
260 # that means we can't optimize
266 # Non-flag arguments specify commits or ranges of commits
267 if {[string match
"*...*" $arg]} {
268 lappend revargs
--gitk-symmetric-diff-marker
274 set vdflags
($n) $diffargs
275 set vflags
($n) $glflags
276 set vrevs
($n) $revargs
277 set vfiltered
($n) $filtered
278 set vorigargs
($n) $origargs
282 proc parseviewrevs
{view revs
} {
283 global vposids vnegids
288 if {[catch
{set ids
[eval exec git rev-parse
$revs]} err
]} {
289 # we get stdout followed by stderr in $err
290 # for an unknown rev, git rev-parse echoes it and then errors out
291 set errlines
[split $err "\n"]
293 for {set l
0} {$l < [llength
$errlines]} {incr l
} {
294 set line
[lindex
$errlines $l]
295 if {!([string length
$line] == 40 && [string is xdigit
$line])} {
296 if {[string match
"fatal:*" $line]} {
297 if {[string match
"fatal: ambiguous argument*" $line]
299 if {[llength
$badrev] == 1} {
300 set err
"unknown revision $badrev"
302 set err
"unknown revisions: [join $badrev ", "]"
305 set err
[join [lrange
$errlines $l end
] "\n"]
312 error_popup
"[mc "Error parsing revisions
:"] $err"
319 foreach id
[split $ids "\n"] {
320 if {$id eq
"--gitk-symmetric-diff-marker"} {
322 } elseif
{[string match
"^*" $id]} {
329 lappend neg
[string range
$id 1 end
]
334 lset ret end
$id...
[lindex
$ret end
]
340 set vposids
($view) $pos
341 set vnegids
($view) $neg
345 # Start off a git log process and arrange to read its output
346 proc start_rev_list
{view
} {
347 global startmsecs commitidx viewcomplete curview
349 global viewargs viewargscmd viewfiles vfilelimit
350 global showlocalchanges
351 global viewactive viewinstances vmergeonly
352 global mainheadid viewmainheadid viewmainheadid_orig
353 global vcanopt vflags vrevs vorigargs
356 set startmsecs
[clock clicks
-milliseconds]
357 set commitidx
($view) 0
358 # these are set this way for the error exits
359 set viewcomplete
($view) 1
360 set viewactive
($view) 0
363 set args
$viewargs($view)
364 if {$viewargscmd($view) ne
{}} {
366 set str
[exec sh
-c $viewargscmd($view)]
368 error_popup
"[mc "Error executing
--argscmd command:"] $err"
371 set args
[concat
$args [split $str "\n"]]
373 set vcanopt
($view) [parseviewargs
$view $args]
375 set files
$viewfiles($view)
376 if {$vmergeonly($view)} {
377 set files
[unmerged_files
$files]
380 if {$nr_unmerged == 0} {
381 error_popup
[mc
"No files selected: --merge specified but\
382 no files are unmerged."]
384 error_popup
[mc
"No files selected: --merge specified but\
385 no unmerged files are within file limit."]
390 set vfilelimit
($view) $files
392 if {$vcanopt($view)} {
393 set revs
[parseviewrevs
$view $vrevs($view)]
397 set args
[concat
$vflags($view) $revs]
399 set args
$vorigargs($view)
403 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
404 --parents --boundary $args "--" $files] r
]
406 error_popup
"[mc "Error executing git log
:"] $err"
409 set i
[reg_instance
$fd]
410 set viewinstances
($view) [list
$i]
411 set viewmainheadid
($view) $mainheadid
412 set viewmainheadid_orig
($view) $mainheadid
413 if {$files ne
{} && $mainheadid ne
{}} {
414 get_viewmainhead
$view
416 if {$showlocalchanges && $viewmainheadid($view) ne
{}} {
417 interestedin
$viewmainheadid($view) dodiffindex
419 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
420 if {$tclencoding != {}} {
421 fconfigure
$fd -encoding $tclencoding
423 filerun
$fd [list getcommitlines
$fd $i $view 0]
424 nowbusy
$view [mc
"Reading"]
425 set viewcomplete
($view) 0
426 set viewactive
($view) 1
430 proc stop_instance
{inst
} {
431 global commfd leftover
433 set fd
$commfd($inst)
437 if {$
::tcl_platform
(platform
) eq
{windows
}} {
446 unset leftover
($inst)
449 proc stop_backends
{} {
452 foreach inst
[array names commfd
] {
457 proc stop_rev_list
{view
} {
460 foreach inst
$viewinstances($view) {
463 set viewinstances
($view) {}
466 proc reset_pending_select
{selid
} {
467 global pending_select mainheadid selectheadid
470 set pending_select
$selid
471 } elseif
{$selectheadid ne
{}} {
472 set pending_select
$selectheadid
474 set pending_select
$mainheadid
478 proc getcommits
{selid
} {
479 global canv curview need_redisplay viewactive
482 if {[start_rev_list
$curview]} {
483 reset_pending_select
$selid
484 show_status
[mc
"Reading commits..."]
487 show_status
[mc
"No commits selected"]
491 proc updatecommits
{} {
492 global curview vcanopt vorigargs vfilelimit viewinstances
493 global viewactive viewcomplete tclencoding
494 global startmsecs showneartags showlocalchanges
495 global mainheadid viewmainheadid viewmainheadid_orig pending_select
497 global varcid vposids vnegids vflags vrevs
500 set hasworktree
[hasworktree
]
503 if {$mainheadid ne
$viewmainheadid_orig($view)} {
504 if {$showlocalchanges} {
507 set viewmainheadid
($view) $mainheadid
508 set viewmainheadid_orig
($view) $mainheadid
509 if {$vfilelimit($view) ne
{}} {
510 get_viewmainhead
$view
513 if {$showlocalchanges} {
516 if {$vcanopt($view)} {
517 set oldpos
$vposids($view)
518 set oldneg
$vnegids($view)
519 set revs
[parseviewrevs
$view $vrevs($view)]
523 # note: getting the delta when negative refs change is hard,
524 # and could require multiple git log invocations, so in that
525 # case we ask git log for all the commits (not just the delta)
526 if {$oldneg eq
$vnegids($view)} {
529 # take out positive refs that we asked for before or
530 # that we have already seen
532 if {[string length
$rev] == 40} {
533 if {[lsearch
-exact $oldpos $rev] < 0
534 && ![info exists varcid
($view,$rev)]} {
539 lappend
$newrevs $rev
542 if {$npos == 0} return
544 set vposids
($view) [lsort
-unique [concat
$oldpos $vposids($view)]]
546 set args
[concat
$vflags($view) $revs --not $oldpos]
548 set args
$vorigargs($view)
551 set fd
[open
[concat | git log
--no-color -z --pretty=raw
$show_notes \
552 --parents --boundary $args "--" $vfilelimit($view)] r
]
554 error_popup
"[mc "Error executing git log
:"] $err"
557 if {$viewactive($view) == 0} {
558 set startmsecs
[clock clicks
-milliseconds]
560 set i
[reg_instance
$fd]
561 lappend viewinstances
($view) $i
562 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
563 if {$tclencoding != {}} {
564 fconfigure
$fd -encoding $tclencoding
566 filerun
$fd [list getcommitlines
$fd $i $view 1]
567 incr viewactive
($view)
568 set viewcomplete
($view) 0
569 reset_pending_select
{}
570 nowbusy
$view [mc
"Reading"]
576 proc reloadcommits
{} {
577 global curview viewcomplete selectedline currentid thickerline
578 global showneartags treediffs commitinterest cached_commitrow
582 if {$selectedline ne
{}} {
586 if {!$viewcomplete($curview)} {
587 stop_rev_list
$curview
591 catch
{unset currentid
}
592 catch
{unset thickerline
}
593 catch
{unset treediffs
}
600 catch
{unset commitinterest
}
601 catch
{unset cached_commitrow
}
602 catch
{unset targetid
}
608 # This makes a string representation of a positive integer which
609 # sorts as a string in numerical order
612 return [format
"%x" $n]
613 } elseif
{$n < 256} {
614 return [format
"x%.2x" $n]
615 } elseif
{$n < 65536} {
616 return [format
"y%.4x" $n]
618 return [format
"z%.8x" $n]
621 # Procedures used in reordering commits from git log (without
622 # --topo-order) into the order for display.
624 proc varcinit
{view
} {
625 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
626 global vtokmod varcmod vrowmod varcix vlastins
628 set varcstart
($view) {{}}
629 set vupptr
($view) {0}
630 set vdownptr
($view) {0}
631 set vleftptr
($view) {0}
632 set vbackptr
($view) {0}
633 set varctok
($view) {{}}
634 set varcrow
($view) {{}}
635 set vtokmod
($view) {}
638 set varcix
($view) {{}}
639 set vlastins
($view) {0}
642 proc resetvarcs
{view
} {
643 global varcid varccommits parents children vseedcount ordertok
646 foreach vid
[array names varcid
$view,*] {
651 foreach vid
[array names vshortids
$view,*] {
652 unset vshortids
($vid)
654 # some commits might have children but haven't been seen yet
655 foreach vid
[array names children
$view,*] {
658 foreach va
[array names varccommits
$view,*] {
659 unset varccommits
($va)
661 foreach vd
[array names vseedcount
$view,*] {
662 unset vseedcount
($vd)
664 catch
{unset ordertok
}
667 # returns a list of the commits with no children
669 global vdownptr vleftptr varcstart
672 set a
[lindex
$vdownptr($v) 0]
674 lappend ret
[lindex
$varcstart($v) $a]
675 set a
[lindex
$vleftptr($v) $a]
680 proc newvarc
{view id
} {
681 global varcid varctok parents children vdatemode
682 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
683 global commitdata commitinfo vseedcount varccommits vlastins
685 set a
[llength
$varctok($view)]
687 if {[llength
$children($vid)] == 0 ||
$vdatemode($view)} {
688 if {![info exists commitinfo
($id)]} {
689 parsecommit
$id $commitdata($id) 1
691 set cdate
[lindex
[lindex
$commitinfo($id) 4] 0]
692 if {![string is integer
-strict $cdate]} {
695 if {![info exists vseedcount
($view,$cdate)]} {
696 set vseedcount
($view,$cdate) -1
698 set c
[incr vseedcount
($view,$cdate)]
699 set cdate
[expr {$cdate ^
0xffffffff}]
700 set tok
"s[strrep $cdate][strrep $c]"
705 if {[llength
$children($vid)] > 0} {
706 set kid
[lindex
$children($vid) end
]
707 set k
$varcid($view,$kid)
708 if {[string compare
[lindex
$varctok($view) $k] $tok] > 0} {
711 set tok
[lindex
$varctok($view) $k]
715 set i
[lsearch
-exact $parents($view,$ki) $id]
716 set j
[expr {[llength
$parents($view,$ki)] - 1 - $i}]
717 append tok
[strrep
$j]
719 set c
[lindex
$vlastins($view) $ka]
720 if {$c == 0 ||
[string compare
$tok [lindex
$varctok($view) $c]] < 0} {
722 set b
[lindex
$vdownptr($view) $ka]
724 set b
[lindex
$vleftptr($view) $c]
726 while {$b != 0 && [string compare
$tok [lindex
$varctok($view) $b]] >= 0} {
728 set b
[lindex
$vleftptr($view) $c]
731 lset vdownptr
($view) $ka $a
732 lappend vbackptr
($view) 0
734 lset vleftptr
($view) $c $a
735 lappend vbackptr
($view) $c
737 lset vlastins
($view) $ka $a
738 lappend vupptr
($view) $ka
739 lappend vleftptr
($view) $b
741 lset vbackptr
($view) $b $a
743 lappend varctok
($view) $tok
744 lappend varcstart
($view) $id
745 lappend vdownptr
($view) 0
746 lappend varcrow
($view) {}
747 lappend varcix
($view) {}
748 set varccommits
($view,$a) {}
749 lappend vlastins
($view) 0
753 proc splitvarc
{p v
} {
754 global varcid varcstart varccommits varctok vtokmod
755 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
757 set oa
$varcid($v,$p)
758 set otok
[lindex
$varctok($v) $oa]
759 set ac
$varccommits($v,$oa)
760 set i
[lsearch
-exact $varccommits($v,$oa) $p]
762 set na
[llength
$varctok($v)]
763 # "%" sorts before "0"...
764 set tok
"$otok%[strrep $i]"
765 lappend varctok
($v) $tok
766 lappend varcrow
($v) {}
767 lappend varcix
($v) {}
768 set varccommits
($v,$oa) [lrange
$ac 0 [expr {$i - 1}]]
769 set varccommits
($v,$na) [lrange
$ac $i end
]
770 lappend varcstart
($v) $p
771 foreach id
$varccommits($v,$na) {
772 set varcid
($v,$id) $na
774 lappend vdownptr
($v) [lindex
$vdownptr($v) $oa]
775 lappend vlastins
($v) [lindex
$vlastins($v) $oa]
776 lset vdownptr
($v) $oa $na
777 lset vlastins
($v) $oa 0
778 lappend vupptr
($v) $oa
779 lappend vleftptr
($v) 0
780 lappend vbackptr
($v) 0
781 for {set b
[lindex
$vdownptr($v) $na]} {$b != 0} {set b
[lindex
$vleftptr($v) $b]} {
782 lset vupptr
($v) $b $na
784 if {[string compare
$otok $vtokmod($v)] <= 0} {
789 proc renumbervarc
{a v
} {
790 global parents children varctok varcstart varccommits
791 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
793 set t1
[clock clicks
-milliseconds]
799 if {[info exists isrelated
($a)]} {
801 set id
[lindex
$varccommits($v,$a) end
]
802 foreach p
$parents($v,$id) {
803 if {[info exists varcid
($v,$p)]} {
804 set isrelated
($varcid($v,$p)) 1
809 set b
[lindex
$vdownptr($v) $a]
812 set b
[lindex
$vleftptr($v) $a]
814 set a
[lindex
$vupptr($v) $a]
820 if {![info exists kidchanged
($a)]} continue
821 set id
[lindex
$varcstart($v) $a]
822 if {[llength
$children($v,$id)] > 1} {
823 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
826 set oldtok
[lindex
$varctok($v) $a]
827 if {!$vdatemode($v)} {
833 set kid
[last_real_child
$v,$id]
835 set k
$varcid($v,$kid)
836 if {[string compare
[lindex
$varctok($v) $k] $tok] > 0} {
839 set tok
[lindex
$varctok($v) $k]
843 set i
[lsearch
-exact $parents($v,$ki) $id]
844 set j
[expr {[llength
$parents($v,$ki)] - 1 - $i}]
845 append tok
[strrep
$j]
847 if {$tok eq
$oldtok} {
850 set id
[lindex
$varccommits($v,$a) end
]
851 foreach p
$parents($v,$id) {
852 if {[info exists varcid
($v,$p)]} {
853 set kidchanged
($varcid($v,$p)) 1
858 lset varctok
($v) $a $tok
859 set b
[lindex
$vupptr($v) $a]
861 if {[string compare
[lindex
$varctok($v) $ka] $vtokmod($v)] < 0} {
864 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
867 set c
[lindex
$vbackptr($v) $a]
868 set d
[lindex
$vleftptr($v) $a]
870 lset vdownptr
($v) $b $d
872 lset vleftptr
($v) $c $d
875 lset vbackptr
($v) $d $c
877 if {[lindex
$vlastins($v) $b] == $a} {
878 lset vlastins
($v) $b $c
880 lset vupptr
($v) $a $ka
881 set c
[lindex
$vlastins($v) $ka]
883 [string compare
$tok [lindex
$varctok($v) $c]] < 0} {
885 set b
[lindex
$vdownptr($v) $ka]
887 set b
[lindex
$vleftptr($v) $c]
890 [string compare
$tok [lindex
$varctok($v) $b]] >= 0} {
892 set b
[lindex
$vleftptr($v) $c]
895 lset vdownptr
($v) $ka $a
896 lset vbackptr
($v) $a 0
898 lset vleftptr
($v) $c $a
899 lset vbackptr
($v) $a $c
901 lset vleftptr
($v) $a $b
903 lset vbackptr
($v) $b $a
905 lset vlastins
($v) $ka $a
908 foreach id
[array names sortkids
] {
909 if {[llength
$children($v,$id)] > 1} {
910 set children
($v,$id) [lsort
-command [list vtokcmp
$v] \
914 set t2
[clock clicks
-milliseconds]
915 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
918 # Fix up the graph after we have found out that in view $v,
919 # $p (a commit that we have already seen) is actually the parent
920 # of the last commit in arc $a.
921 proc fix_reversal
{p a v
} {
922 global varcid varcstart varctok vupptr
924 set pa
$varcid($v,$p)
925 if {$p ne
[lindex
$varcstart($v) $pa]} {
927 set pa
$varcid($v,$p)
929 # seeds always need to be renumbered
930 if {[lindex
$vupptr($v) $pa] == 0 ||
931 [string compare
[lindex
$varctok($v) $a] \
932 [lindex
$varctok($v) $pa]] > 0} {
937 proc insertrow
{id p v
} {
938 global cmitlisted children parents varcid varctok vtokmod
939 global varccommits ordertok commitidx numcommits curview
940 global targetid targetrow vshortids
944 set cmitlisted
($vid) 1
945 set children
($vid) {}
946 set parents
($vid) [list
$p]
947 set a
[newvarc
$v $id]
949 lappend vshortids
($v,[string range
$id 0 3]) $id
950 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] < 0} {
953 lappend varccommits
($v,$a) $id
955 if {[llength
[lappend children
($vp) $id]] > 1} {
956 set children
($vp) [lsort
-command [list vtokcmp
$v] $children($vp)]
957 catch
{unset ordertok
}
959 fix_reversal
$p $a $v
961 if {$v == $curview} {
962 set numcommits
$commitidx($v)
964 if {[info exists targetid
]} {
965 if {![comes_before
$targetid $p]} {
972 proc insertfakerow
{id p
} {
973 global varcid varccommits parents children cmitlisted
974 global commitidx varctok vtokmod targetid targetrow curview numcommits
978 set i
[lsearch
-exact $varccommits($v,$a) $p]
980 puts
"oops: insertfakerow can't find [shortids $p] on arc $a"
983 set children
($v,$id) {}
984 set parents
($v,$id) [list
$p]
985 set varcid
($v,$id) $a
986 lappend children
($v,$p) $id
987 set cmitlisted
($v,$id) 1
988 set numcommits
[incr commitidx
($v)]
989 # note we deliberately don't update varcstart($v) even if $i == 0
990 set varccommits
($v,$a) [linsert
$varccommits($v,$a) $i $id]
992 if {[info exists targetid
]} {
993 if {![comes_before
$targetid $p]} {
1001 proc removefakerow
{id
} {
1002 global varcid varccommits parents children commitidx
1003 global varctok vtokmod cmitlisted currentid selectedline
1004 global targetid curview numcommits
1007 if {[llength
$parents($v,$id)] != 1} {
1008 puts
"oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1011 set p
[lindex
$parents($v,$id) 0]
1012 set a
$varcid($v,$id)
1013 set i
[lsearch
-exact $varccommits($v,$a) $id]
1015 puts
"oops: removefakerow can't find [shortids $id] on arc $a"
1018 unset varcid
($v,$id)
1019 set varccommits
($v,$a) [lreplace
$varccommits($v,$a) $i $i]
1020 unset parents
($v,$id)
1021 unset children
($v,$id)
1022 unset cmitlisted
($v,$id)
1023 set numcommits
[incr commitidx
($v) -1]
1024 set j
[lsearch
-exact $children($v,$p) $id]
1026 set children
($v,$p) [lreplace
$children($v,$p) $j $j]
1029 if {[info exist currentid
] && $id eq
$currentid} {
1033 if {[info exists targetid
] && $targetid eq
$id} {
1040 proc real_children
{vp
} {
1041 global children nullid nullid2
1044 foreach id
$children($vp) {
1045 if {$id ne
$nullid && $id ne
$nullid2} {
1052 proc first_real_child
{vp
} {
1053 global children nullid nullid2
1055 foreach id
$children($vp) {
1056 if {$id ne
$nullid && $id ne
$nullid2} {
1063 proc last_real_child
{vp
} {
1064 global children nullid nullid2
1066 set kids
$children($vp)
1067 for {set i
[llength
$kids]} {[incr i
-1] >= 0} {} {
1068 set id
[lindex
$kids $i]
1069 if {$id ne
$nullid && $id ne
$nullid2} {
1076 proc vtokcmp
{v a b
} {
1077 global varctok varcid
1079 return [string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1080 [lindex
$varctok($v) $varcid($v,$b)]]
1083 # This assumes that if lim is not given, the caller has checked that
1084 # arc a's token is less than $vtokmod($v)
1085 proc modify_arc
{v a
{lim
{}}} {
1086 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1089 set c
[string compare
[lindex
$varctok($v) $a] $vtokmod($v)]
1092 set r
[lindex
$varcrow($v) $a]
1093 if {$r ne
{} && $vrowmod($v) <= $r + $lim} return
1096 set vtokmod
($v) [lindex
$varctok($v) $a]
1098 if {$v == $curview} {
1099 while {$a != 0 && [lindex
$varcrow($v) $a] eq
{}} {
1100 set a
[lindex
$vupptr($v) $a]
1106 set lim
[llength
$varccommits($v,$a)]
1108 set r
[expr {[lindex
$varcrow($v) $a] + $lim}]
1115 proc update_arcrows
{v
} {
1116 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1117 global varcid vrownum varcorder varcix varccommits
1118 global vupptr vdownptr vleftptr varctok
1119 global displayorder parentlist curview cached_commitrow
1121 if {$vrowmod($v) == $commitidx($v)} return
1122 if {$v == $curview} {
1123 if {[llength
$displayorder] > $vrowmod($v)} {
1124 set displayorder
[lrange
$displayorder 0 [expr {$vrowmod($v) - 1}]]
1125 set parentlist
[lrange
$parentlist 0 [expr {$vrowmod($v) - 1}]]
1127 catch
{unset cached_commitrow
}
1129 set narctot
[expr {[llength
$varctok($v)] - 1}]
1131 while {$a != 0 && [lindex
$varcix($v) $a] eq
{}} {
1132 # go up the tree until we find something that has a row number,
1133 # or we get to a seed
1134 set a
[lindex
$vupptr($v) $a]
1137 set a
[lindex
$vdownptr($v) 0]
1140 set varcorder
($v) [list
$a]
1141 lset varcix
($v) $a 0
1142 lset varcrow
($v) $a 0
1146 set arcn
[lindex
$varcix($v) $a]
1147 if {[llength
$vrownum($v)] > $arcn + 1} {
1148 set vrownum
($v) [lrange
$vrownum($v) 0 $arcn]
1149 set varcorder
($v) [lrange
$varcorder($v) 0 $arcn]
1151 set row
[lindex
$varcrow($v) $a]
1155 incr row
[llength
$varccommits($v,$a)]
1156 # go down if possible
1157 set b
[lindex
$vdownptr($v) $a]
1159 # if not, go left, or go up until we can go left
1161 set b
[lindex
$vleftptr($v) $a]
1163 set a
[lindex
$vupptr($v) $a]
1169 lappend vrownum
($v) $row
1170 lappend varcorder
($v) $a
1171 lset varcix
($v) $a $arcn
1172 lset varcrow
($v) $a $row
1174 set vtokmod
($v) [lindex
$varctok($v) $p]
1176 set vrowmod
($v) $row
1177 if {[info exists currentid
]} {
1178 set selectedline
[rowofcommit
$currentid]
1182 # Test whether view $v contains commit $id
1183 proc commitinview
{id v
} {
1186 return [info exists varcid
($v,$id)]
1189 # Return the row number for commit $id in the current view
1190 proc rowofcommit
{id
} {
1191 global varcid varccommits varcrow curview cached_commitrow
1192 global varctok vtokmod
1195 if {![info exists varcid
($v,$id)]} {
1196 puts
"oops rowofcommit no arc for [shortids $id]"
1199 set a
$varcid($v,$id)
1200 if {[string compare
[lindex
$varctok($v) $a] $vtokmod($v)] >= 0} {
1203 if {[info exists cached_commitrow
($id)]} {
1204 return $cached_commitrow($id)
1206 set i
[lsearch
-exact $varccommits($v,$a) $id]
1208 puts
"oops didn't find commit [shortids $id] in arc $a"
1211 incr i
[lindex
$varcrow($v) $a]
1212 set cached_commitrow
($id) $i
1216 # Returns 1 if a is on an earlier row than b, otherwise 0
1217 proc comes_before
{a b
} {
1218 global varcid varctok curview
1221 if {$a eq
$b ||
![info exists varcid
($v,$a)] || \
1222 ![info exists varcid
($v,$b)]} {
1225 if {$varcid($v,$a) != $varcid($v,$b)} {
1226 return [expr {[string compare
[lindex
$varctok($v) $varcid($v,$a)] \
1227 [lindex
$varctok($v) $varcid($v,$b)]] < 0}]
1229 return [expr {[rowofcommit
$a] < [rowofcommit
$b]}]
1232 proc bsearch
{l elt
} {
1233 if {[llength
$l] == 0 ||
$elt <= [lindex
$l 0]} {
1238 while {$hi - $lo > 1} {
1239 set mid
[expr {int
(($lo + $hi) / 2)}]
1240 set t
[lindex
$l $mid]
1243 } elseif
{$elt > $t} {
1252 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1253 proc make_disporder
{start end
} {
1254 global vrownum curview commitidx displayorder parentlist
1255 global varccommits varcorder parents vrowmod varcrow
1256 global d_valid_start d_valid_end
1258 if {$end > $vrowmod($curview)} {
1259 update_arcrows
$curview
1261 set ai
[bsearch
$vrownum($curview) $start]
1262 set start
[lindex
$vrownum($curview) $ai]
1263 set narc
[llength
$vrownum($curview)]
1264 for {set r
$start} {$ai < $narc && $r < $end} {incr ai
} {
1265 set a
[lindex
$varcorder($curview) $ai]
1266 set l
[llength
$displayorder]
1267 set al
[llength
$varccommits($curview,$a)]
1268 if {$l < $r + $al} {
1270 set pad
[ntimes
[expr {$r - $l}] {}]
1271 set displayorder
[concat
$displayorder $pad]
1272 set parentlist
[concat
$parentlist $pad]
1273 } elseif
{$l > $r} {
1274 set displayorder
[lrange
$displayorder 0 [expr {$r - 1}]]
1275 set parentlist
[lrange
$parentlist 0 [expr {$r - 1}]]
1277 foreach id
$varccommits($curview,$a) {
1278 lappend displayorder
$id
1279 lappend parentlist
$parents($curview,$id)
1281 } elseif
{[lindex
$displayorder [expr {$r + $al - 1}]] eq
{}} {
1283 foreach id
$varccommits($curview,$a) {
1284 lset displayorder
$i $id
1285 lset parentlist
$i $parents($curview,$id)
1293 proc commitonrow
{row
} {
1296 set id
[lindex
$displayorder $row]
1298 make_disporder
$row [expr {$row + 1}]
1299 set id
[lindex
$displayorder $row]
1304 proc closevarcs
{v
} {
1305 global varctok varccommits varcid parents children
1306 global cmitlisted commitidx vtokmod
1308 set missing_parents
0
1310 set narcs
[llength
$varctok($v)]
1311 for {set a
1} {$a < $narcs} {incr a
} {
1312 set id
[lindex
$varccommits($v,$a) end
]
1313 foreach p
$parents($v,$id) {
1314 if {[info exists varcid
($v,$p)]} continue
1315 # add p as a new commit
1316 incr missing_parents
1317 set cmitlisted
($v,$p) 0
1318 set parents
($v,$p) {}
1319 if {[llength
$children($v,$p)] == 1 &&
1320 [llength
$parents($v,$id)] == 1} {
1323 set b
[newvarc
$v $p]
1325 set varcid
($v,$p) $b
1326 if {[string compare
[lindex
$varctok($v) $b] $vtokmod($v)] < 0} {
1329 lappend varccommits
($v,$b) $p
1331 set scripts
[check_interest
$p $scripts]
1334 if {$missing_parents > 0} {
1335 foreach s
$scripts {
1341 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1342 # Assumes we already have an arc for $rwid.
1343 proc rewrite_commit
{v id rwid
} {
1344 global children parents varcid varctok vtokmod varccommits
1346 foreach ch
$children($v,$id) {
1347 # make $rwid be $ch's parent in place of $id
1348 set i
[lsearch
-exact $parents($v,$ch) $id]
1350 puts
"oops rewrite_commit didn't find $id in parent list for $ch"
1352 set parents
($v,$ch) [lreplace
$parents($v,$ch) $i $i $rwid]
1353 # add $ch to $rwid's children and sort the list if necessary
1354 if {[llength
[lappend children
($v,$rwid) $ch]] > 1} {
1355 set children
($v,$rwid) [lsort
-command [list vtokcmp
$v] \
1356 $children($v,$rwid)]
1358 # fix the graph after joining $id to $rwid
1359 set a
$varcid($v,$ch)
1360 fix_reversal
$rwid $a $v
1361 # parentlist is wrong for the last element of arc $a
1362 # even if displayorder is right, hence the 3rd arg here
1363 modify_arc
$v $a [expr {[llength
$varccommits($v,$a)] - 1}]
1367 # Mechanism for registering a command to be executed when we come
1368 # across a particular commit. To handle the case when only the
1369 # prefix of the commit is known, the commitinterest array is now
1370 # indexed by the first 4 characters of the ID. Each element is a
1371 # list of id, cmd pairs.
1372 proc interestedin
{id cmd
} {
1373 global commitinterest
1375 lappend commitinterest
([string range
$id 0 3]) $id $cmd
1378 proc check_interest
{id scripts
} {
1379 global commitinterest
1381 set prefix
[string range
$id 0 3]
1382 if {[info exists commitinterest
($prefix)]} {
1384 foreach
{i
script} $commitinterest($prefix) {
1385 if {[string match
"$i*" $id]} {
1386 lappend scripts
[string map
[list
"%I" $id "%P" $i] $script]
1388 lappend newlist
$i $script
1391 if {$newlist ne
{}} {
1392 set commitinterest
($prefix) $newlist
1394 unset commitinterest
($prefix)
1400 proc getcommitlines
{fd inst view updating
} {
1401 global cmitlisted leftover
1402 global commitidx commitdata vdatemode
1403 global parents children curview hlview
1404 global idpending ordertok
1405 global varccommits varcid varctok vtokmod vfilelimit vshortids
1407 set stuff
[read $fd 500000]
1408 # git log doesn't terminate the last commit with a null...
1409 if {$stuff == {} && $leftover($inst) ne
{} && [eof
$fd]} {
1416 global commfd viewcomplete viewactive viewname
1417 global viewinstances
1419 set i
[lsearch
-exact $viewinstances($view) $inst]
1421 set viewinstances
($view) [lreplace
$viewinstances($view) $i $i]
1423 # set it blocking so we wait for the process to terminate
1424 fconfigure
$fd -blocking 1
1425 if {[catch
{close
$fd} err
]} {
1427 if {$view != $curview} {
1428 set fv
" for the \"$viewname($view)\" view"
1430 if {[string range
$err 0 4] == "usage"} {
1431 set err
"Gitk: error reading commits$fv:\
1432 bad arguments to git log."
1433 if {$viewname($view) eq
"Command line"} {
1435 " (Note: arguments to gitk are passed to git log\
1436 to allow selection of commits to be displayed.)"
1439 set err
"Error reading commits$fv: $err"
1443 if {[incr viewactive
($view) -1] <= 0} {
1444 set viewcomplete
($view) 1
1445 # Check if we have seen any ids listed as parents that haven't
1446 # appeared in the list
1450 if {$view == $curview} {
1459 set i
[string first
"\0" $stuff $start]
1461 append leftover
($inst) [string range
$stuff $start end
]
1465 set cmit
$leftover($inst)
1466 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
1467 set leftover
($inst) {}
1469 set cmit
[string range
$stuff $start [expr {$i - 1}]]
1471 set start
[expr {$i + 1}]
1472 set j
[string first
"\n" $cmit]
1475 if {$j >= 0 && [string match
"commit *" $cmit]} {
1476 set ids
[string range
$cmit 7 [expr {$j - 1}]]
1477 if {[string match
{[-^
<>]*} $ids]} {
1478 switch
-- [string index
$ids 0] {
1484 set ids
[string range
$ids 1 end
]
1488 if {[string length
$id] != 40} {
1496 if {[string length
$shortcmit] > 80} {
1497 set shortcmit
"[string range $shortcmit 0 80]..."
1499 error_popup
"[mc "Can
't parse git log output:"] {$shortcmit}"
1502 set id [lindex $ids 0]
1505 lappend vshortids($view,[string range $id 0 3]) $id
1507 if {!$listed && $updating && ![info exists varcid($vid)] &&
1508 $vfilelimit($view) ne {}} {
1509 # git log doesn't rewrite parents
for unlisted commits
1510 # when doing path limiting, so work around that here
1511 # by working out the rewritten parent with git rev-list
1512 # and if we already know about it, using the rewritten
1513 # parent as a substitute parent for $id's children.
1515 set rwid
[exec git rev-list
--first-parent --max-count=1 \
1516 $id -- $vfilelimit($view)]
1518 if {$rwid ne
{} && [info exists varcid
($view,$rwid)]} {
1519 # use $rwid in place of $id
1520 rewrite_commit
$view $id $rwid
1527 if {[info exists varcid
($vid)]} {
1528 if {$cmitlisted($vid) ||
!$listed} continue
1532 set olds
[lrange
$ids 1 end
]
1536 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
1537 set cmitlisted
($vid) $listed
1538 set parents
($vid) $olds
1539 if {![info exists children
($vid)]} {
1540 set children
($vid) {}
1541 } elseif
{$a == 0 && [llength
$children($vid)] == 1} {
1542 set k
[lindex
$children($vid) 0]
1543 if {[llength
$parents($view,$k)] == 1 &&
1544 (!$vdatemode($view) ||
1545 $varcid($view,$k) == [llength
$varctok($view)] - 1)} {
1546 set a
$varcid($view,$k)
1551 set a
[newvarc
$view $id]
1553 if {[string compare
[lindex
$varctok($view) $a] $vtokmod($view)] < 0} {
1556 if {![info exists varcid
($vid)]} {
1558 lappend varccommits
($view,$a) $id
1559 incr commitidx
($view)
1564 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
1566 if {[llength
[lappend children
($vp) $id]] > 1 &&
1567 [vtokcmp
$view [lindex
$children($vp) end-1
] $id] > 0} {
1568 set children
($vp) [lsort
-command [list vtokcmp
$view] \
1570 catch
{unset ordertok
}
1572 if {[info exists varcid
($view,$p)]} {
1573 fix_reversal
$p $a $view
1579 set scripts
[check_interest
$id $scripts]
1583 global numcommits hlview
1585 if {$view == $curview} {
1586 set numcommits
$commitidx($view)
1589 if {[info exists hlview
] && $view == $hlview} {
1590 # we never actually get here...
1593 foreach s
$scripts {
1600 proc chewcommits
{} {
1601 global curview hlview viewcomplete
1602 global pending_select
1605 if {$viewcomplete($curview)} {
1606 global commitidx varctok
1607 global numcommits startmsecs
1609 if {[info exists pending_select
]} {
1611 reset_pending_select
{}
1613 if {[commitinview
$pending_select $curview]} {
1614 selectline
[rowofcommit
$pending_select] 1
1616 set row
[first_real_row
]
1620 if {$commitidx($curview) > 0} {
1621 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1622 #puts "overall $ms ms for $numcommits commits"
1623 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1625 show_status
[mc
"No commits selected"]
1632 proc do_readcommit
{id
} {
1635 # Invoke git-log to handle automatic encoding conversion
1636 set fd
[open
[concat | git log
--no-color --pretty=raw
-1 $id] r
]
1637 # Read the results using i18n.logoutputencoding
1638 fconfigure
$fd -translation lf
-eofchar {}
1639 if {$tclencoding != {}} {
1640 fconfigure
$fd -encoding $tclencoding
1642 set contents
[read $fd]
1644 # Remove the heading line
1645 regsub
{^commit
[0-9a-f]+\n} $contents {} contents
1650 proc readcommit
{id
} {
1651 if {[catch
{set contents
[do_readcommit
$id]}]} return
1652 parsecommit
$id $contents 1
1655 proc parsecommit
{id contents listed
} {
1665 set hdrend
[string first
"\n\n" $contents]
1667 # should never happen...
1668 set hdrend
[string length
$contents]
1670 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
1671 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
1672 foreach line
[split $header "\n"] {
1673 set line
[split $line " "]
1674 set tag
[lindex
$line 0]
1675 if {$tag == "author"} {
1676 set audate
[lrange
$line end-1 end
]
1677 set auname
[join [lrange
$line 1 end-2
] " "]
1678 } elseif
{$tag == "committer"} {
1679 set comdate
[lrange
$line end-1 end
]
1680 set comname
[join [lrange
$line 1 end-2
] " "]
1684 # take the first non-blank line of the comment as the headline
1685 set headline
[string trimleft
$comment]
1686 set i
[string first
"\n" $headline]
1688 set headline
[string range
$headline 0 $i]
1690 set headline
[string trimright
$headline]
1691 set i
[string first
"\r" $headline]
1693 set headline
[string trimright
[string range
$headline 0 $i]]
1696 # git log indents the comment by 4 spaces;
1697 # if we got this via git cat-file, add the indentation
1699 foreach line
[split $comment "\n"] {
1700 append newcomment
" "
1701 append newcomment
$line
1702 append newcomment
"\n"
1704 set comment
$newcomment
1706 set hasnote
[string first
"\nNotes:\n" $contents]
1707 set commitinfo
($id) [list
$headline $auname $audate \
1708 $comname $comdate $comment $hasnote]
1711 proc getcommit
{id
} {
1712 global commitdata commitinfo
1714 if {[info exists commitdata
($id)]} {
1715 parsecommit
$id $commitdata($id) 1
1718 if {![info exists commitinfo
($id)]} {
1719 set commitinfo
($id) [list
[mc
"No commit information available"]]
1725 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1726 # and are present in the current view.
1727 # This is fairly slow...
1728 proc longid
{prefix
} {
1729 global varcid curview vshortids
1732 if {[string length
$prefix] >= 4} {
1733 set vshortid
$curview,[string range
$prefix 0 3]
1734 if {[info exists vshortids
($vshortid)]} {
1735 foreach id
$vshortids($vshortid) {
1736 if {[string match
"$prefix*" $id]} {
1737 if {[lsearch
-exact $ids $id] < 0} {
1739 if {[llength
$ids] >= 2} break
1745 foreach match
[array names varcid
"$curview,$prefix*"] {
1746 lappend ids
[lindex
[split $match ","] 1]
1747 if {[llength
$ids] >= 2} break
1754 global tagids idtags headids idheads tagobjid
1755 global otherrefids idotherrefs mainhead mainheadid
1756 global selecthead selectheadid
1759 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
1762 set refd
[open
[list | git show-ref
-d] r
]
1763 while {[gets
$refd line
] >= 0} {
1764 if {[string index
$line 40] ne
" "} continue
1765 set id
[string range
$line 0 39]
1766 set ref
[string range
$line 41 end
]
1767 if {![string match
"refs/*" $ref]} continue
1768 set name
[string range
$ref 5 end
]
1769 if {[string match
"remotes/*" $name]} {
1770 if {![string match
"*/HEAD" $name] && !$hideremotes} {
1771 set headids
($name) $id
1772 lappend idheads
($id) $name
1774 } elseif
{[string match
"heads/*" $name]} {
1775 set name
[string range
$name 6 end
]
1776 set headids
($name) $id
1777 lappend idheads
($id) $name
1778 } elseif
{[string match
"tags/*" $name]} {
1779 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1780 # which is what we want since the former is the commit ID
1781 set name
[string range
$name 5 end
]
1782 if {[string match
"*^{}" $name]} {
1783 set name
[string range
$name 0 end-3
]
1785 set tagobjid
($name) $id
1787 set tagids
($name) $id
1788 lappend idtags
($id) $name
1790 set otherrefids
($name) $id
1791 lappend idotherrefs
($id) $name
1798 set mainheadid
[exec git rev-parse HEAD
]
1799 set thehead
[exec git symbolic-ref HEAD
]
1800 if {[string match
"refs/heads/*" $thehead]} {
1801 set mainhead
[string range
$thehead 11 end
]
1805 if {$selecthead ne
{}} {
1807 set selectheadid
[exec git rev-parse
--verify $selecthead]
1812 # skip over fake commits
1813 proc first_real_row
{} {
1814 global nullid nullid2 numcommits
1816 for {set row
0} {$row < $numcommits} {incr row
} {
1817 set id
[commitonrow
$row]
1818 if {$id ne
$nullid && $id ne
$nullid2} {
1825 # update things for a head moved to a child of its previous location
1826 proc movehead
{id name
} {
1827 global headids idheads
1829 removehead
$headids($name) $name
1830 set headids
($name) $id
1831 lappend idheads
($id) $name
1834 # update things when a head has been removed
1835 proc removehead
{id name
} {
1836 global headids idheads
1838 if {$idheads($id) eq
$name} {
1841 set i
[lsearch
-exact $idheads($id) $name]
1843 set idheads
($id) [lreplace
$idheads($id) $i $i]
1846 unset headids
($name)
1849 proc ttk_toplevel
{w args
} {
1851 eval [linsert
$args 0 ::toplevel
$w]
1853 place
[ttk
::frame
$w._toplevel_background
] -x 0 -y 0 -relwidth 1 -relheight 1
1858 proc make_transient
{window origin
} {
1861 # In MacOS Tk 8.4 transient appears to work by setting
1862 # overrideredirect, which is utterly useless, since the
1863 # windows get no border, and are not even kept above
1865 if {!$have_tk85 && [tk windowingsystem
] eq
{aqua
}} return
1867 wm transient
$window $origin
1869 # Windows fails to place transient windows normally, so
1870 # schedule a callback to center them on the parent.
1871 if {[tk windowingsystem
] eq
{win32
}} {
1872 after idle
[list tk
::PlaceWindow
$window widget
$origin]
1876 proc show_error
{w top msg
{mc mc
}} {
1878 if {![info exists NS
]} {set NS
""}
1879 if {[wm state
$top] eq
"withdrawn"} { wm deiconify
$top }
1880 message
$w.m
-text $msg -justify center
-aspect 400
1881 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1882 ${NS}::button
$w.ok
-default active
-text [$mc OK
] -command "destroy $top"
1883 pack
$w.ok
-side bottom
-fill x
1884 bind $top <Visibility
> "grab $top; focus $top"
1885 bind $top <Key-Return
> "destroy $top"
1886 bind $top <Key-space
> "destroy $top"
1887 bind $top <Key-Escape
> "destroy $top"
1891 proc error_popup
{msg
{owner .
}} {
1892 if {[tk windowingsystem
] eq
"win32"} {
1893 tk_messageBox
-icon error
-type ok
-title [wm title .
] \
1894 -parent $owner -message $msg
1898 make_transient
$w $owner
1899 show_error
$w $w $msg
1903 proc confirm_popup
{msg
{owner .
}} {
1904 global confirm_ok NS
1908 make_transient
$w $owner
1909 message
$w.m
-text $msg -justify center
-aspect 400
1910 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
1911 ${NS}::button
$w.ok
-text [mc OK
] -command "set confirm_ok 1; destroy $w"
1912 pack
$w.ok
-side left
-fill x
1913 ${NS}::button
$w.cancel
-text [mc Cancel
] -command "destroy $w"
1914 pack
$w.cancel
-side right
-fill x
1915 bind $w <Visibility
> "grab $w; focus $w"
1916 bind $w <Key-Return
> "set confirm_ok 1; destroy $w"
1917 bind $w <Key-space
> "set confirm_ok 1; destroy $w"
1918 bind $w <Key-Escape
> "destroy $w"
1919 tk
::PlaceWindow
$w widget
$owner
1924 proc setoptions
{} {
1925 if {[tk windowingsystem
] ne
"win32"} {
1926 option add
*Panedwindow.showHandle
1 startupFile
1927 option add
*Panedwindow.sashRelief raised startupFile
1928 if {[tk windowingsystem
] ne
"aqua"} {
1929 option add
*Menu.font uifont startupFile
1932 option add
*Menu.TearOff
0 startupFile
1934 option add
*Button.font uifont startupFile
1935 option add
*Checkbutton.font uifont startupFile
1936 option add
*Radiobutton.font uifont startupFile
1937 option add
*Menubutton.font uifont startupFile
1938 option add
*Label.font uifont startupFile
1939 option add
*Message.font uifont startupFile
1940 option add
*Entry.font textfont startupFile
1941 option add
*Text.font textfont startupFile
1942 option add
*Labelframe.font uifont startupFile
1943 option add
*Spinbox.font textfont startupFile
1944 option add
*Listbox.font mainfont startupFile
1947 # Make a menu and submenus.
1948 # m is the window name for the menu, items is the list of menu items to add.
1949 # Each item is a list {mc label type description options...}
1950 # mc is ignored; it's so we can put mc there to alert xgettext
1951 # label is the string that appears in the menu
1952 # type is cascade, command or radiobutton (should add checkbutton)
1953 # description depends on type; it's the sublist for cascade, the
1954 # command to invoke for command, or {variable value} for radiobutton
1955 proc makemenu
{m items
} {
1957 if {[tk windowingsystem
] eq
{aqua
}} {
1963 set name
[mc
[lindex
$i 1]]
1964 set type [lindex
$i 2]
1965 set thing
[lindex
$i 3]
1966 set params
[list
$type]
1968 set u
[string first
"&" [string map
{&& x
} $name]]
1969 lappend params
-label [string map
{&& & & {}} $name]
1971 lappend params
-underline $u
1976 set submenu
[string tolower
[string map
{& ""} [lindex
$i 1]]]
1977 lappend params
-menu $m.
$submenu
1980 lappend params
-command $thing
1983 lappend params
-variable [lindex
$thing 0] \
1984 -value [lindex
$thing 1]
1987 set tail [lrange
$i 4 end
]
1988 regsub
-all {\yMeta1\y
} $tail $Meta1 tail
1989 eval $m add
$params $tail
1990 if {$type eq
"cascade"} {
1991 makemenu
$m.
$submenu $thing
1996 # translate string and remove ampersands
1998 return [string map
{&& & & {}} [mc
$str]]
2001 proc cleardropsel
{w
} {
2004 proc makedroplist
{w varname args
} {
2008 foreach label
$args {
2009 set cx
[string length
$label]
2010 if {$cx > $width} {set width
$cx}
2012 set gm
[ttk
::combobox
$w -width $width -state readonly\
2013 -textvariable $varname -values $args \
2014 -exportselection false
]
2015 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2017 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2022 proc makewindow {} {
2023 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2025 global findtype findtypemenu findloc findstring fstring geometry
2026 global entries sha1entry sha1string sha1but
2027 global diffcontextstring diffcontext
2029 global maincursor textcursor curtextcursor
2030 global rowctxmenu fakerowmenu mergemax wrapcomment
2031 global highlight_files gdttype
2032 global searchstring sstring
2033 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2034 global uifgcolor uifgdisabledcolor
2035 global filesepbgcolor filesepfgcolor
2036 global mergecolors foundbgcolor currentsearchhitbgcolor
2037 global headctxmenu progresscanv progressitem progresscoords statusw
2038 global fprogitem fprogcoord lastprogupdate progupdatepending
2039 global rprogitem rprogcoord rownumsel numcommits
2040 global have_tk85 use_ttk NS
2044 # The "mc" arguments here are purely so that xgettext
2045 # sees the following string as needing to be translated
2048 {mc "Update" command updatecommits -accelerator F5}
2049 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2050 {mc "Reread references" command rereadrefs}
2051 {mc "List references" command showrefs -accelerator F2}
2053 {mc "Start git gui" command {exec git gui &}}
2055 {mc "Quit" command doquit -accelerator Meta1-Q}
2059 {mc "Preferences" command doprefs}
2063 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2064 {mc "Edit view..." command editview -state disabled -accelerator F4}
2065 {mc "Delete view" command delview -state disabled}
2067 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2069 if {[tk windowingsystem] ne "aqua"} {
2072 {mc "About gitk" command about}
2073 {mc "Key bindings" command keys}
2075 set bar [list $file $edit $view $help]
2077 proc ::tk::mac::ShowPreferences {} {doprefs}
2078 proc ::tk::mac::Quit {} {doquit}
2079 lset file end [lreplace [lindex $file end] end-1 end]
2081 xx "Apple" cascade {
2082 {mc "About gitk" command about}
2087 {mc "Key bindings" command keys}
2089 set bar [list $apple $file $view $help]
2092 . configure -menu .bar
2095 # cover the non-themed toplevel with a themed frame.
2096 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2099 # the gui has upper and lower half, parts of a paned window.
2100 ${NS}::panedwindow .ctop -orient vertical
2102 # possibly use assumed geometry
2103 if {![info exists geometry(pwsash0)]} {
2104 set geometry(topheight) [expr {15 * $linespc}]
2105 set geometry(topwidth) [expr {80 * $charspc}]
2106 set geometry(botheight) [expr {15 * $linespc}]
2107 set geometry(botwidth) [expr {50 * $charspc}]
2108 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2109 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2112 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2113 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2114 ${NS}::frame .tf.histframe
2115 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2117 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2120 # create three canvases
2121 set cscroll .tf.histframe.csb
2122 set canv .tf.histframe.pwclist.canv
2124 -selectbackground $selectbgcolor \
2125 -background $bgcolor -bd 0 \
2126 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2127 .tf.histframe.pwclist add $canv
2128 set canv2 .tf.histframe.pwclist.canv2
2130 -selectbackground $selectbgcolor \
2131 -background $bgcolor -bd 0 -yscrollincr $linespc
2132 .tf.histframe.pwclist add $canv2
2133 set canv3 .tf.histframe.pwclist.canv3
2135 -selectbackground $selectbgcolor \
2136 -background $bgcolor -bd 0 -yscrollincr $linespc
2137 .tf.histframe.pwclist add $canv3
2139 bind .tf.histframe.pwclist <Map> {
2141 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2142 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2145 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2146 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2149 # a scroll bar to rule them
2150 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2151 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2152 pack $cscroll -side right -fill y
2153 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2154 lappend bglist $canv $canv2 $canv3
2155 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2157 # we have two button bars at bottom of top frame. Bar 1
2158 ${NS}::frame .tf.bar
2159 ${NS}::frame .tf.lbar -height 15
2161 set sha1entry .tf.bar.sha1
2162 set entries $sha1entry
2163 set sha1but .tf.bar.sha1label
2164 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2165 -command gotocommit -width 8
2166 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2167 pack .tf.bar.sha1label -side left
2168 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2169 trace add variable sha1string write sha1change
2170 pack $sha1entry -side left -pady 2
2173 #define left_width 16
2174 #define left_height 16
2175 static unsigned char left_bits[] = {
2176 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2177 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2178 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2181 #define right_width 16
2182 #define right_height 16
2183 static unsigned char right_bits[] = {
2184 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2185 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2186 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2188 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2189 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2190 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2191 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2193 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2195 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2197 .tf.bar.leftbut configure -image bm-left
2199 pack .tf.bar.leftbut -side left -fill y
2200 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2202 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2204 .tf.bar.rightbut configure -image bm-right
2206 pack .tf.bar.rightbut -side left -fill y
2208 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2210 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2211 -relief sunken -anchor e
2212 ${NS}::label .tf.bar.rowlabel2 -text "/"
2213 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2214 -relief sunken -anchor e
2215 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2218 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2221 trace add variable selectedline write selectedline_change
2223 # Status label and progress bar
2224 set statusw .tf.bar.status
2225 ${NS}::label $statusw -width 15 -relief sunken
2226 pack $statusw -side left -padx 5
2228 set progresscanv [ttk::progressbar .tf.bar.progress]
2230 set h [expr {[font metrics uifont -linespace] + 2}]
2231 set progresscanv .tf.bar.progress
2232 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2233 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2234 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2235 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2237 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2238 set progresscoords {0 0}
2241 bind $progresscanv <Configure> adjustprogress
2242 set lastprogupdate [clock clicks -milliseconds]
2243 set progupdatepending 0
2245 # build up the bottom bar of upper window
2246 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2247 ${NS}::button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1}
2248 ${NS}::button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1}
2249 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2250 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2252 set gdttype [mc "containing:"]
2253 set gm [makedroplist .tf.lbar.gdttype gdttype \
2254 [mc "containing:"] \
2255 [mc "touching paths:"] \
2256 [mc "adding/removing string:"] \
2257 [mc "changing lines matching:"]]
2258 trace add variable gdttype write gdttype_change
2259 pack .tf.lbar.gdttype -side left -fill y
2262 set fstring .tf.lbar.findstring
2263 lappend entries $fstring
2264 ${NS}::entry $fstring -width 30 -textvariable findstring
2265 trace add variable findstring write find_change
2266 set findtype [mc "Exact"]
2267 set findtypemenu [makedroplist .tf.lbar.findtype \
2268 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2269 trace add variable findtype write findcom_change
2270 set findloc [mc "All fields"]
2271 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2272 [mc "Comments"] [mc "Author"] [mc "Committer"]
2273 trace add variable findloc write find_change
2274 pack .tf.lbar.findloc -side right
2275 pack .tf.lbar.findtype -side right
2276 pack $fstring -side left -expand 1 -fill x
2278 # Finish putting the upper half of the viewer together
2279 pack .tf.lbar -in .tf -side bottom -fill x
2280 pack .tf.bar -in .tf -side bottom -fill x
2281 pack .tf.histframe -fill both -side top -expand 1
2284 .ctop paneconfigure .tf -height $geometry(topheight)
2285 .ctop paneconfigure .tf -width $geometry(topwidth)
2288 # now build up the bottom
2289 ${NS}::panedwindow .pwbottom -orient horizontal
2291 # lower left, a text box over search bar, scroll bar to the right
2292 # if we know window height, then that will set the lower text height, otherwise
2293 # we set lower text height which will drive window height
2294 if {[info exists geometry(main)]} {
2295 ${NS}::frame .bleft -width $geometry(botwidth)
2297 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2299 ${NS}::frame .bleft.top
2300 ${NS}::frame .bleft.mid
2301 ${NS}::frame .bleft.bottom
2303 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2304 pack .bleft.top.search -side left -padx 5
2305 set sstring .bleft.top.sstring
2307 ${NS}::entry $sstring -width 20 -textvariable searchstring
2308 lappend entries $sstring
2309 trace add variable searchstring write incrsearch
2310 pack $sstring -side left -expand 1 -fill x
2311 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2312 -command changediffdisp -variable diffelide -value {0 0}
2313 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2314 -command changediffdisp -variable diffelide -value {0 1}
2315 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2316 -command changediffdisp -variable diffelide -value {1 0}
2317 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2318 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2319 spinbox .bleft.mid.diffcontext -width 5 \
2320 -from 0 -increment 1 -to 10000000 \
2321 -validate all -validatecommand "diffcontextvalidate %P" \
2322 -textvariable diffcontextstring
2323 .bleft.mid.diffcontext set $diffcontext
2324 trace add variable diffcontextstring write diffcontextchange
2325 lappend entries .bleft.mid.diffcontext
2326 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2327 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2328 -command changeignorespace -variable ignorespace
2329 pack .bleft.mid.ignspace -side left -padx 5
2331 set worddiff [mc "Line diff"]
2332 if {[package vcompare $git_version "1.7.2"] >= 0} {
2333 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2334 [mc "Markup words"] [mc "Color words"]
2335 trace add variable worddiff write changeworddiff
2336 pack .bleft.mid.worddiff -side left -padx 5
2339 set ctext .bleft.bottom.ctext
2340 text $ctext -background $bgcolor -foreground $fgcolor \
2341 -state disabled -font textfont \
2342 -yscrollcommand scrolltext -wrap none \
2343 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2345 $ctext conf -tabstyle wordprocessor
2347 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2348 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2349 pack .bleft.top -side top -fill x
2350 pack .bleft.mid -side top -fill x
2351 grid $ctext .bleft.bottom.sb -sticky nsew
2352 grid .bleft.bottom.sbhorizontal -sticky ew
2353 grid columnconfigure .bleft.bottom 0 -weight 1
2354 grid rowconfigure .bleft.bottom 0 -weight 1
2355 grid rowconfigure .bleft.bottom 1 -weight 0
2356 pack .bleft.bottom -side top -fill both -expand 1
2357 lappend bglist $ctext
2358 lappend fglist $ctext
2360 $ctext tag conf comment -wrap $wrapcomment
2361 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2362 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2363 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2364 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2365 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2366 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2367 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2368 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2369 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2370 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2371 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2372 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2373 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2374 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2375 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2376 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2377 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2378 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2379 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2380 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2381 $ctext tag conf mmax -fore darkgrey
2383 $ctext tag conf mresult -font textfontbold
2384 $ctext tag conf msep -font textfontbold
2385 $ctext tag conf found -back $foundbgcolor
2386 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2387 $ctext tag conf wwrap -wrap word
2389 .pwbottom add .bleft
2391 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2395 ${NS}::frame .bright
2396 ${NS}::frame .bright.mode
2397 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2398 -command reselectline -variable cmitmode -value "patch"
2399 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2400 -command reselectline -variable cmitmode -value "tree"
2401 grid .bright.mode.patch .bright.mode.tree -sticky ew
2402 pack .bright.mode -side top -fill x
2403 set cflist .bright.cfiles
2404 set indent [font measure mainfont "nn"]
2406 -selectbackground $selectbgcolor \
2407 -background $bgcolor -foreground $fgcolor \
2409 -tabs [list $indent [expr {2 * $indent}]] \
2410 -yscrollcommand ".bright.sb set" \
2411 -cursor [. cget -cursor] \
2412 -spacing1 1 -spacing3 1
2413 lappend bglist $cflist
2414 lappend fglist $cflist
2415 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2416 pack .bright.sb -side right -fill y
2417 pack $cflist -side left -fill both -expand 1
2418 $cflist tag configure highlight \
2419 -background [$cflist cget -selectbackground]
2420 $cflist tag configure bold -font mainfontbold
2422 .pwbottom add .bright
2425 # restore window width & height if known
2426 if {[info exists geometry(main)]} {
2427 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2428 if {$w > [winfo screenwidth .]} {
2429 set w [winfo screenwidth .]
2431 if {$h > [winfo screenheight .]} {
2432 set h [winfo screenheight .]
2434 wm geometry . "${w}x$h"
2438 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2439 wm state . $geometry(state)
2442 if {[tk windowingsystem] eq {aqua}} {
2453 %W sashpos 0 $::geometry(topheight)
2455 bind .pwbottom <Map> {
2457 %W sashpos 0 $::geometry(botwidth)
2461 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2462 pack .ctop -fill both -expand 1
2463 bindall <1> {selcanvline %W %x %y}
2464 #bindall <B1-Motion> {selcanvline %W %x %y}
2465 if {[tk windowingsystem] == "win32"} {
2466 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2467 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2469 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2470 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2471 if {[tk windowingsystem] eq "aqua"} {
2472 bindall <MouseWheel> {
2473 set delta [expr {- (%D)}]
2474 allcanvs yview scroll $delta units
2476 bindall <Shift-MouseWheel> {
2477 set delta [expr {- (%D)}]
2478 $canv xview scroll $delta units
2482 bindall <$::BM> "canvscan mark %W %x %y"
2483 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2484 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2485 bind . <$M1B-Key-w> doquit
2486 bindkey <Home> selfirstline
2487 bindkey <End> sellastline
2488 bind . <Key-Up> "selnextline -1"
2489 bind . <Key-Down> "selnextline 1"
2490 bind . <Shift-Key-Up> "dofind -1 0"
2491 bind . <Shift-Key-Down> "dofind 1 0"
2492 bindkey <Key-Right> "goforw"
2493 bindkey <Key-Left> "goback"
2494 bind . <Key-Prior> "selnextpage -1"
2495 bind . <Key-Next> "selnextpage 1"
2496 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2497 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2498 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2499 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2500 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2501 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2502 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2503 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2504 bindkey <Key-space> "$ctext yview scroll 1 pages"
2505 bindkey p "selnextline -1"
2506 bindkey n "selnextline 1"
2509 bindkey k "selnextline -1"
2510 bindkey j "selnextline 1"
2514 bindkey d "$ctext yview scroll 18 units"
2515 bindkey u "$ctext yview scroll -18 units"
2516 bindkey / {focus $fstring}
2517 bindkey <Key-KP_Divide> {focus $fstring}
2518 bindkey <Key-Return> {dofind 1 1}
2519 bindkey ? {dofind -1 1}
2521 bind . <F5> updatecommits
2522 bindmodfunctionkey Shift 5 reloadcommits
2523 bind . <F2> showrefs
2524 bindmodfunctionkey Shift 4 {newview 0}
2525 bind . <F4> edit_or_newview
2526 bind . <$M1B-q> doquit
2527 bind . <$M1B-f> {dofind 1 1}
2528 bind . <$M1B-g> {dofind 1 0}
2529 bind . <$M1B-r> dosearchback
2530 bind . <$M1B-s> dosearch
2531 bind . <$M1B-equal> {incrfont 1}
2532 bind . <$M1B-plus> {incrfont 1}
2533 bind . <$M1B-KP_Add> {incrfont 1}
2534 bind . <$M1B-minus> {incrfont -1}
2535 bind . <$M1B-KP_Subtract> {incrfont -1}
2536 wm protocol . WM_DELETE_WINDOW doquit
2537 bind . <Destroy> {stop_backends}
2538 bind . <Button-1> "click %W"
2539 bind $fstring <Key-Return> {dofind 1 1}
2540 bind $sha1entry <Key-Return> {gotocommit; break}
2541 bind $sha1entry <<PasteSelection>> clearsha1
2542 bind $cflist <1> {sel_flist %W %x %y; break}
2543 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2544 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2546 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2547 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2548 bind $ctext <Button-1> {focus %W}
2549 bind $ctext <<Selection>> rehighlight_search_results
2551 set maincursor [. cget -cursor]
2552 set textcursor [$ctext cget -cursor]
2553 set curtextcursor $textcursor
2555 set rowctxmenu .rowctxmenu
2556 makemenu $rowctxmenu {
2557 {mc "Diff this -> selected" command {diffvssel 0}}
2558 {mc "Diff selected -> this" command {diffvssel 1}}
2559 {mc "Make patch" command mkpatch}
2560 {mc "Create tag" command mktag}
2561 {mc "Write commit to file" command writecommit}
2562 {mc "Create new branch" command mkbranch}
2563 {mc "Cherry-pick this commit" command cherrypick}
2564 {mc "Reset HEAD branch to here" command resethead}
2565 {mc "Mark this commit" command markhere}
2566 {mc "Return to mark" command gotomark}
2567 {mc "Find descendant of this and mark" command find_common_desc}
2568 {mc "Compare with marked commit" command compare_commits}
2569 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2570 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2571 {mc "Revert this commit" command revert}
2573 $rowctxmenu configure -tearoff 0
2575 set fakerowmenu .fakerowmenu
2576 makemenu $fakerowmenu {
2577 {mc "Diff this -> selected" command {diffvssel 0}}
2578 {mc "Diff selected -> this" command {diffvssel 1}}
2579 {mc "Make patch" command mkpatch}
2580 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2581 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2583 $fakerowmenu configure -tearoff 0
2585 set headctxmenu .headctxmenu
2586 makemenu $headctxmenu {
2587 {mc "Check out this branch" command cobranch}
2588 {mc "Remove this branch" command rmbranch}
2590 $headctxmenu configure -tearoff 0
2593 set flist_menu .flistctxmenu
2594 makemenu $flist_menu {
2595 {mc "Highlight this too" command {flist_hl 0}}
2596 {mc "Highlight this only" command {flist_hl 1}}
2597 {mc "External diff" command {external_diff}}
2598 {mc "Blame parent commit" command {external_blame 1}}
2600 $flist_menu configure -tearoff 0
2603 set diff_menu .diffctxmenu
2604 makemenu $diff_menu {
2605 {mc "Show origin of this line" command show_line_source}
2606 {mc "Run git gui blame on this line" command {external_blame_diff}}
2608 $diff_menu configure -tearoff 0
2611 # Windows sends all mouse wheel events to the current focused window, not
2612 # the one where the mouse hovers, so bind those events here and redirect
2613 # to the correct window
2614 proc windows_mousewheel_redirector {W X Y D} {
2615 global canv canv2 canv3
2616 set w [winfo containing -displayof $W $X $Y]
2618 set u [expr {$D < 0 ? 5 : -5}]
2619 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2620 allcanvs yview scroll $u units
2623 $w yview scroll $u units
2629 # Update row number label when selectedline changes
2630 proc selectedline_change {n1 n2 op} {
2631 global selectedline rownumsel
2633 if {$selectedline eq {}} {
2636 set rownumsel [expr {$selectedline + 1}]
2640 # mouse-2 makes all windows scan vertically, but only the one
2641 # the cursor is in scans horizontally
2642 proc canvscan {op w x y} {
2643 global canv canv2 canv3
2644 foreach c [list $canv $canv2 $canv3] {
2653 proc scrollcanv {cscroll f0 f1} {
2654 $cscroll set $f0 $f1
2659 # when we make a key binding for the toplevel, make sure
2660 # it doesn't get triggered when that key is pressed in the
2661 # find string entry widget.
2662 proc bindkey {ev script} {
2665 set escript [bind Entry $ev]
2666 if {$escript == {}} {
2667 set escript [bind Entry <Key>]
2669 foreach e $entries {
2670 bind $e $ev "$escript; break"
2674 proc bindmodfunctionkey {mod n script} {
2675 bind . <$mod-F$n> $script
2676 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2679 # set the focus back to the toplevel for any click outside
2682 global ctext entries
2683 foreach e [concat $entries $ctext] {
2684 if {$w == $e} return
2689 # Adjust the progress bar for a change in requested extent or canvas size
2690 proc adjustprogress {} {
2691 global progresscanv progressitem progresscoords
2692 global fprogitem fprogcoord lastprogupdate progupdatepending
2693 global rprogitem rprogcoord use_ttk
2696 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2700 set w [expr {[winfo width $progresscanv] - 4}]
2701 set x0 [expr {$w * [lindex $progresscoords 0]}]
2702 set x1 [expr {$w * [lindex $progresscoords 1]}]
2703 set h [winfo height $progresscanv]
2704 $progresscanv coords $progressitem $x0 0 $x1 $h
2705 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2706 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2707 set now [clock clicks -milliseconds]
2708 if {$now >= $lastprogupdate + 100} {
2709 set progupdatepending 0
2711 } elseif {!$progupdatepending} {
2712 set progupdatepending 1
2713 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2717 proc doprogupdate {} {
2718 global lastprogupdate progupdatepending
2720 if {$progupdatepending} {
2721 set progupdatepending 0
2722 set lastprogupdate [clock clicks -milliseconds]
2727 proc savestuff {w} {
2728 global canv canv2 canv3 mainfont textfont uifont tabstop
2729 global stuffsaved findmergefiles maxgraphpct
2730 global maxwidth showneartags showlocalchanges
2731 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2732 global cmitmode wrapcomment datetimeformat limitdiffs
2733 global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor
2734 global uifgcolor uifgdisabledcolor
2735 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
2736 global tagbgcolor tagfgcolor tagoutlinecolor
2737 global reflinecolor filesepbgcolor filesepfgcolor
2738 global mergecolors foundbgcolor currentsearchhitbgcolor
2739 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor circlecolors
2740 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
2741 global linkfgcolor circleoutlinecolor
2742 global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk
2743 global hideremotes want_ttk maxrefs
2745 if {$stuffsaved} return
2746 if {![winfo viewable .]} return
2748 if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
2749 set f [open "~/.gitk-new" w]
2750 if {$::tcl_platform(platform) eq {windows}} {
2751 file attributes "~/.gitk-new" -hidden true
2753 puts $f [list set mainfont $mainfont]
2754 puts $f [list set textfont $textfont]
2755 puts $f [list set uifont $uifont]
2756 puts $f [list set tabstop $tabstop]
2757 puts $f [list set findmergefiles $findmergefiles]
2758 puts $f [list set maxgraphpct $maxgraphpct]
2759 puts $f [list set maxwidth $maxwidth]
2760 puts $f [list set cmitmode $cmitmode]
2761 puts $f [list set wrapcomment $wrapcomment]
2762 puts $f [list set autoselect $autoselect]
2763 puts $f [list set autosellen $autosellen]
2764 puts $f [list set showneartags $showneartags]
2765 puts $f [list set maxrefs $maxrefs]
2766 puts $f [list set hideremotes $hideremotes]
2767 puts $f [list set showlocalchanges $showlocalchanges]
2768 puts $f [list set datetimeformat $datetimeformat]
2769 puts $f [list set limitdiffs $limitdiffs]
2770 puts $f [list set uicolor $uicolor]
2771 puts $f [list set want_ttk $want_ttk]
2772 puts $f [list set bgcolor $bgcolor]
2773 puts $f [list set fgcolor $fgcolor]
2774 puts $f [list set uifgcolor $uifgcolor]
2775 puts $f [list set uifgdisabledcolor $uifgdisabledcolor]
2776 puts $f [list set colors $colors]
2777 puts $f [list set diffcolors $diffcolors]
2778 puts $f [list set mergecolors $mergecolors]
2779 puts $f [list set markbgcolor $markbgcolor]
2780 puts $f [list set diffcontext $diffcontext]
2781 puts $f [list set selectbgcolor $selectbgcolor]
2782 puts $f [list set foundbgcolor $foundbgcolor]
2783 puts $f [list set currentsearchhitbgcolor $currentsearchhitbgcolor]
2784 puts $f [list set extdifftool $extdifftool]
2785 puts $f [list set perfile_attrs $perfile_attrs]
2786 puts $f [list set headbgcolor $headbgcolor]
2787 puts $f [list set headfgcolor $headfgcolor]
2788 puts $f [list set headoutlinecolor $headoutlinecolor]
2789 puts $f [list set remotebgcolor $remotebgcolor]
2790 puts $f [list set tagbgcolor $tagbgcolor]
2791 puts $f [list set tagfgcolor $tagfgcolor]
2792 puts $f [list set tagoutlinecolor $tagoutlinecolor]
2793 puts $f [list set reflinecolor $reflinecolor]
2794 puts $f [list set filesepbgcolor $filesepbgcolor]
2795 puts $f [list set filesepfgcolor $filesepfgcolor]
2796 puts $f [list set linehoverbgcolor $linehoverbgcolor]
2797 puts $f [list set linehoverfgcolor $linehoverfgcolor]
2798 puts $f [list set linehoveroutlinecolor $linehoveroutlinecolor]
2799 puts $f [list set mainheadcirclecolor $mainheadcirclecolor]
2800 puts $f [list set workingfilescirclecolor $workingfilescirclecolor]
2801 puts $f [list set indexcirclecolor $indexcirclecolor]
2802 puts $f [list set circlecolors $circlecolors]
2803 puts $f [list set linkfgcolor $linkfgcolor]
2804 puts $f [list set circleoutlinecolor $circleoutlinecolor]
2806 puts $f "set geometry(main) [wm geometry .]"
2807 puts $f "set geometry(state) [wm state .]"
2808 puts $f "set geometry(topwidth) [winfo width .tf]"
2809 puts $f "set geometry(topheight) [winfo height .tf]"
2811 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2812 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2814 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2815 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2817 puts $f "set geometry(botwidth) [winfo width .bleft]"
2818 puts $f "set geometry(botheight) [winfo height .bleft]"
2820 puts -nonewline $f "set permviews {"
2821 for {set v 0} {$v < $nextviewnum} {incr v} {
2822 if {$viewperm($v)} {
2823 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2828 catch {file delete "~/.gitk"}
2829 file rename -force "~/.gitk-new" "~/.gitk"
2834 proc resizeclistpanes {win w} {
2835 global oldwidth use_ttk
2836 if {[info exists oldwidth($win)]} {
2838 set s0 [$win sashpos 0]
2839 set s1 [$win sashpos 1]
2841 set s0 [$win sash coord 0]
2842 set s1 [$win sash coord 1]
2845 set sash0 [expr {int($w/2 - 2)}]
2846 set sash1 [expr {int($w*5/6 - 2)}]
2848 set factor [expr {1.0 * $w / $oldwidth($win)}]
2849 set sash0 [expr {int($factor * [lindex $s0 0])}]
2850 set sash1 [expr {int($factor * [lindex $s1 0])}]
2854 if {$sash1 < $sash0 + 20} {
2855 set sash1 [expr {$sash0 + 20}]
2857 if {$sash1 > $w - 10} {
2858 set sash1 [expr {$w - 10}]
2859 if {$sash0 > $sash1 - 20} {
2860 set sash0 [expr {$sash1 - 20}]
2865 $win sashpos 0 $sash0
2866 $win sashpos 1 $sash1
2868 $win sash place 0 $sash0 [lindex $s0 1]
2869 $win sash place 1 $sash1 [lindex $s1 1]
2872 set oldwidth($win) $w
2875 proc resizecdetpanes {win w} {
2876 global oldwidth use_ttk
2877 if {[info exists oldwidth($win)]} {
2879 set s0 [$win sashpos 0]
2881 set s0 [$win sash coord 0]
2884 set sash0 [expr {int($w*3/4 - 2)}]
2886 set factor [expr {1.0 * $w / $oldwidth($win)}]
2887 set sash0 [expr {int($factor * [lindex $s0 0])}]
2891 if {$sash0 > $w - 15} {
2892 set sash0 [expr {$w - 15}]
2896 $win sashpos 0 $sash0
2898 $win sash place 0 $sash0 [lindex $s0 1]
2901 set oldwidth($win) $w
2904 proc allcanvs args {
2905 global canv canv2 canv3
2911 proc bindall {event action} {
2912 global canv canv2 canv3
2913 bind $canv $event $action
2914 bind $canv2 $event $action
2915 bind $canv3 $event $action
2921 if {[winfo exists $w]} {
2926 wm title $w [mc "About gitk"]
2928 message $w.m -text [mc "
2929 Gitk - a commit viewer for git
2931 Copyright \u00a9 2005-2011 Paul Mackerras
2933 Use and redistribute under the terms of the GNU General Public License"] \
2934 -justify center -aspect 400 -border 2 -bg white -relief groove
2935 pack $w.m -side top -fill x -padx 2 -pady 2
2936 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2937 pack $w.ok -side bottom
2938 bind $w <Visibility> "focus $w.ok"
2939 bind $w <Key-Escape> "destroy $w"
2940 bind $w <Key-Return> "destroy $w"
2941 tk::PlaceWindow $w widget .
2947 if {[winfo exists $w]} {
2951 if {[tk windowingsystem] eq {aqua}} {
2957 wm title $w [mc "Gitk key bindings"]
2959 message $w.m -text "
2960 [mc "Gitk key bindings:"]
2962 [mc "<%s-Q> Quit" $M1T]
2963 [mc "<%s-W> Close window" $M1T]
2964 [mc "<Home> Move to first commit"]
2965 [mc "<End> Move to last commit"]
2966 [mc "<Up>, p, k Move up one commit"]
2967 [mc "<Down>, n, j Move down one commit"]
2968 [mc "<Left>, z, h Go back in history list"]
2969 [mc "<Right>, x, l Go forward in history list"]
2970 [mc "<PageUp> Move up one page in commit list"]
2971 [mc "<PageDown> Move down one page in commit list"]
2972 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2973 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2974 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2975 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2976 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2977 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2978 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2979 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2980 [mc "<Delete>, b Scroll diff view up one page"]
2981 [mc "<Backspace> Scroll diff view up one page"]
2982 [mc "<Space> Scroll diff view down one page"]
2983 [mc "u Scroll diff view up 18 lines"]
2984 [mc "d Scroll diff view down 18 lines"]
2985 [mc "<%s-F> Find" $M1T]
2986 [mc "<%s-G> Move to next find hit" $M1T]
2987 [mc "<Return> Move to next find hit"]
2988 [mc "/ Focus the search box"]
2989 [mc "? Move to previous find hit"]
2990 [mc "f Scroll diff view to next file"]
2991 [mc "<%s-S> Search for next hit in diff view" $M1T]
2992 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2993 [mc "<%s-KP+> Increase font size" $M1T]
2994 [mc "<%s-plus> Increase font size" $M1T]
2995 [mc "<%s-KP-> Decrease font size" $M1T]
2996 [mc "<%s-minus> Decrease font size" $M1T]
2999 -justify left -bg white -border 2 -relief groove
3000 pack $w.m -side top -fill both -padx 2 -pady 2
3001 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3002 bind $w <Key-Escape> [list destroy $w]
3003 pack $w.ok -side bottom
3004 bind $w <Visibility> "focus $w.ok"
3005 bind $w <Key-Escape> "destroy $w"
3006 bind $w <Key-Return> "destroy $w"
3009 # Procedures for manipulating the file list window at the
3010 # bottom right of the overall window.
3012 proc treeview {w l openlevs} {
3013 global treecontents treediropen treeheight treeparent treeindex
3023 set treecontents() {}
3024 $w conf -state normal
3026 while {[string range $f 0 $prefixend] ne $prefix} {
3027 if {$lev <= $openlevs} {
3028 $w mark set e:$treeindex($prefix) "end -1c"
3029 $w mark gravity e:$treeindex($prefix) left
3031 set treeheight($prefix) $ht
3032 incr ht [lindex $htstack end]
3033 set htstack [lreplace $htstack end end]
3034 set prefixend [lindex $prefendstack end]
3035 set prefendstack [lreplace $prefendstack end end]
3036 set prefix [string range $prefix 0 $prefixend]
3039 set tail [string range $f [expr {$prefixend+1}] end]
3040 while {[set slash [string first "/" $tail]] >= 0} {
3043 lappend prefendstack $prefixend
3044 incr prefixend [expr {$slash + 1}]
3045 set d [string range $tail 0 $slash]
3046 lappend treecontents($prefix) $d
3047 set oldprefix $prefix
3049 set treecontents($prefix) {}
3050 set treeindex($prefix) [incr ix]
3051 set treeparent($prefix) $oldprefix
3052 set tail [string range $tail [expr {$slash+1}] end]
3053 if {$lev <= $openlevs} {
3055 set treediropen($prefix) [expr {$lev < $openlevs}]
3056 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3057 $w mark set d:$ix "end -1c"
3058 $w mark gravity d:$ix left
3060 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3062 $w image create end -align center -image $bm -padx 1 \
3064 $w insert end $d [highlight_tag $prefix]
3065 $w mark set s:$ix "end -1c"
3066 $w mark gravity s:$ix left
3071 if {$lev <= $openlevs} {
3074 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3076 $w insert end $tail [highlight_tag $f]
3078 lappend treecontents($prefix) $tail
3081 while {$htstack ne {}} {
3082 set treeheight($prefix) $ht
3083 incr ht [lindex $htstack end]
3084 set htstack [lreplace $htstack end end]
3085 set prefixend [lindex $prefendstack end]
3086 set prefendstack [lreplace $prefendstack end end]
3087 set prefix [string range $prefix 0 $prefixend]
3089 $w conf -state disabled
3092 proc linetoelt {l} {
3093 global treeheight treecontents
3098 foreach e $treecontents($prefix) {
3103 if {[string index $e end] eq "/"} {
3104 set n $treeheight($prefix$e)
3116 proc highlight_tree {y prefix} {
3117 global treeheight treecontents cflist
3119 foreach e $treecontents($prefix) {
3121 if {[highlight_tag $path] ne {}} {
3122 $cflist tag add bold $y.0 "$y.0 lineend"
3125 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3126 set y [highlight_tree $y $path]
3132 proc treeclosedir {w dir} {
3133 global treediropen treeheight treeparent treeindex
3135 set ix $treeindex($dir)
3136 $w conf -state normal
3137 $w delete s:$ix e:$ix
3138 set treediropen($dir) 0
3139 $w image configure a:$ix -image tri-rt
3140 $w conf -state disabled
3141 set n [expr {1 - $treeheight($dir)}]
3142 while {$dir ne {}} {
3143 incr treeheight($dir) $n
3144 set dir $treeparent($dir)
3148 proc treeopendir {w dir} {
3149 global treediropen treeheight treeparent treecontents treeindex
3151 set ix $treeindex($dir)
3152 $w conf -state normal
3153 $w image configure a:$ix -image tri-dn
3154 $w mark set e:$ix s:$ix
3155 $w mark gravity e:$ix right
3158 set n [llength $treecontents($dir)]
3159 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3162 incr treeheight($x) $n
3164 foreach e $treecontents($dir) {
3166 if {[string index $e end] eq "/"} {
3167 set iy $treeindex($de)
3168 $w mark set d:$iy e:$ix
3169 $w mark gravity d:$iy left
3170 $w insert e:$ix $str
3171 set treediropen($de) 0
3172 $w image create e:$ix -align center -image tri-rt -padx 1 \
3174 $w insert e:$ix $e [highlight_tag $de]
3175 $w mark set s:$iy e:$ix
3176 $w mark gravity s:$iy left
3177 set treeheight($de) 1
3179 $w insert e:$ix $str
3180 $w insert e:$ix $e [highlight_tag $de]
3183 $w mark gravity e:$ix right
3184 $w conf -state disabled
3185 set treediropen($dir) 1
3186 set top [lindex [split [$w index @0,0] .] 0]
3187 set ht [$w cget -height]
3188 set l [lindex [split [$w index s:$ix] .] 0]
3191 } elseif {$l + $n + 1 > $top + $ht} {
3192 set top [expr {$l + $n + 2 - $ht}]
3200 proc treeclick {w x y} {
3201 global treediropen cmitmode ctext cflist cflist_top
3203 if {$cmitmode ne "tree"} return
3204 if {![info exists cflist_top]} return
3205 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3206 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3207 $cflist tag add highlight $l.0 "$l.0 lineend"
3213 set e [linetoelt $l]
3214 if {[string index $e end] ne "/"} {
3216 } elseif {$treediropen($e)} {
3223 proc setfilelist {id} {
3224 global treefilelist cflist jump_to_here
3226 treeview $cflist $treefilelist($id) 0
3227 if {$jump_to_here ne {}} {
3228 set f [lindex $jump_to_here 0]
3229 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3235 image create bitmap tri-rt -background black -foreground blue -data {
3236 #define tri-rt_width 13
3237 #define tri-rt_height 13
3238 static unsigned char tri-rt_bits[] = {
3239 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3240 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3243 #define tri-rt-mask_width 13
3244 #define tri-rt-mask_height 13
3245 static unsigned char tri-rt-mask_bits[] = {
3246 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3247 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3250 image create bitmap tri-dn -background black -foreground blue -data {
3251 #define tri-dn_width 13
3252 #define tri-dn_height 13
3253 static unsigned char tri-dn_bits[] = {
3254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3255 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3258 #define tri-dn-mask_width 13
3259 #define tri-dn-mask_height 13
3260 static unsigned char tri-dn-mask_bits[] = {
3261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3262 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3266 image create bitmap reficon-T -background black -foreground yellow -data {
3267 #define tagicon_width 13
3268 #define tagicon_height 9
3269 static unsigned char tagicon_bits[] = {
3270 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3271 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3273 #define tagicon-mask_width 13
3274 #define tagicon-mask_height 9
3275 static unsigned char tagicon-mask_bits[] = {
3276 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3277 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3280 #define headicon_width 13
3281 #define headicon_height 9
3282 static unsigned char headicon_bits[] = {
3283 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3284 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3287 #define headicon-mask_width 13
3288 #define headicon-mask_height 9
3289 static unsigned char headicon-mask_bits[] = {
3290 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3291 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3293 image create bitmap reficon-H -background black -foreground green \
3294 -data $rectdata -maskdata $rectmask
3295 image create bitmap reficon-o -background black -foreground "#ddddff" \
3296 -data $rectdata -maskdata $rectmask
3298 proc init_flist {first} {
3299 global cflist cflist_top difffilestart
3301 $cflist conf -state normal
3302 $cflist delete 0.0 end
3304 $cflist insert end $first
3306 $cflist tag add highlight 1.0 "1.0 lineend"
3308 catch {unset cflist_top}
3310 $cflist conf -state disabled
3311 set difffilestart {}
3314 proc highlight_tag {f} {
3315 global highlight_paths
3317 foreach p $highlight_paths {
3318 if {[string match $p $f]} {
3325 proc highlight_filelist {} {
3326 global cmitmode cflist
3328 $cflist conf -state normal
3329 if {$cmitmode ne "tree"} {
3330 set end [lindex [split [$cflist index end] .] 0]
3331 for {set l 2} {$l < $end} {incr l} {
3332 set line [$cflist get $l.0 "$l.0 lineend"]
3333 if {[highlight_tag $line] ne {}} {
3334 $cflist tag add bold $l.0 "$l.0 lineend"
3340 $cflist conf -state disabled
3343 proc unhighlight_filelist {} {
3346 $cflist conf -state normal
3347 $cflist tag remove bold 1.0 end
3348 $cflist conf -state disabled
3351 proc add_flist {fl} {
3354 $cflist conf -state normal
3356 $cflist insert end "\n"
3357 $cflist insert end $f [highlight_tag $f]
3359 $cflist conf -state disabled
3362 proc sel_flist {w x y} {
3363 global ctext difffilestart cflist cflist_top cmitmode
3365 if {$cmitmode eq "tree"} return
3366 if {![info exists cflist_top]} return
3367 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3368 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3369 $cflist tag add highlight $l.0 "$l.0 lineend"
3374 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3376 suppress_highlighting_file_for_current_scrollpos
3379 proc pop_flist_menu {w X Y x y} {
3380 global ctext cflist cmitmode flist_menu flist_menu_file
3381 global treediffs diffids
3384 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3386 if {$cmitmode eq "tree"} {
3387 set e [linetoelt $l]
3388 if {[string index $e end] eq "/"} return
3390 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3392 set flist_menu_file $e
3393 set xdiffstate "normal"
3394 if {$cmitmode eq "tree"} {
3395 set xdiffstate "disabled"
3397 # Disable "External diff" item in tree mode
3398 $flist_menu entryconf 2 -state $xdiffstate
3399 tk_popup $flist_menu $X $Y
3402 proc find_ctext_fileinfo {line} {
3403 global ctext_file_names ctext_file_lines
3405 set ok [bsearch $ctext_file_lines $line]
3406 set tline [lindex $ctext_file_lines $ok]
3408 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3411 return [list [lindex $ctext_file_names $ok] $tline]
3415 proc pop_diff_menu {w X Y x y} {
3416 global ctext diff_menu flist_menu_file
3417 global diff_menu_txtpos diff_menu_line
3418 global diff_menu_filebase
3420 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3421 set diff_menu_line [lindex $diff_menu_txtpos 0]
3422 # don't pop up the menu on hunk-separator or file-separator lines
3423 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3427 set f [find_ctext_fileinfo $diff_menu_line]
3428 if {$f eq {}} return
3429 set flist_menu_file [lindex $f 0]
3430 set diff_menu_filebase [lindex $f 1]
3431 tk_popup $diff_menu $X $Y
3434 proc flist_hl {only} {
3435 global flist_menu_file findstring gdttype
3437 set x [shellquote $flist_menu_file]
3438 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3441 append findstring " " $x
3443 set gdttype [mc "touching paths:"]
3446 proc gitknewtmpdir {} {
3447 global diffnum gitktmpdir gitdir
3449 if {![info exists gitktmpdir]} {
3450 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3451 if {[catch {file mkdir $gitktmpdir} err]} {
3452 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3459 set diffdir [file join $gitktmpdir $diffnum]
3460 if {[catch {file mkdir $diffdir} err]} {
3461 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3467 proc save_file_from_commit {filename output what} {
3470 if {[catch {exec git show $filename -- > $output} err]} {
3471 if {[string match "fatal: bad revision *" $err]} {
3474 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3480 proc external_diff_get_one_file {diffid filename diffdir} {
3481 global nullid nullid2 nullfile
3484 if {$diffid == $nullid} {
3485 set difffile [file join $worktree $filename]
3486 if {[file exists $difffile]} {
3491 if {$diffid == $nullid2} {
3492 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3493 return [save_file_from_commit :$filename $difffile index]
3495 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3496 return [save_file_from_commit $diffid:$filename $difffile \
3500 proc external_diff {} {
3501 global nullid nullid2
3502 global flist_menu_file
3506 if {[llength $diffids] == 1} {
3507 # no reference commit given
3508 set diffidto [lindex $diffids 0]
3509 if {$diffidto eq $nullid} {
3510 # diffing working copy with index
3511 set diffidfrom $nullid2
3512 } elseif {$diffidto eq $nullid2} {
3513 # diffing index with HEAD
3514 set diffidfrom "HEAD"
3516 # use first parent commit
3517 global parentlist selectedline
3518 set diffidfrom [lindex $parentlist $selectedline 0]
3521 set diffidfrom [lindex $diffids 0]
3522 set diffidto [lindex $diffids 1]
3525 # make sure that several diffs wont collide
3526 set diffdir [gitknewtmpdir]
3527 if {$diffdir eq {}} return
3529 # gather files to diff
3530 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3531 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3533 if {$difffromfile ne {} && $difftofile ne {}} {
3534 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3535 if {[catch {set fl [open |$cmd r]} err]} {
3536 file delete -force $diffdir
3537 error_popup "$extdifftool: [mc "command failed:"] $err"
3539 fconfigure $fl -blocking 0
3540 filerun $fl [list delete_at_eof $fl $diffdir]
3545 proc find_hunk_blamespec {base line} {
3548 # Find and parse the hunk header
3549 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3550 if {$s_lix eq {}} return
3552 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3553 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3554 s_line old_specs osz osz1 new_line nsz]} {
3558 # base lines for the parents
3559 set base_lines [list $new_line]
3560 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3561 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3562 old_spec old_line osz]} {
3565 lappend base_lines $old_line
3568 # Now scan the lines to determine offset within the hunk
3569 set max_parent [expr {[llength $base_lines]-2}]
3571 set s_lno [lindex [split $s_lix "."] 0]
3573 # Determine if the line is removed
3574 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3575 if {[string match {[-+ ]*} $chunk]} {
3576 set removed_idx [string first "-" $chunk]
3577 # Choose a parent index
3578 if {$removed_idx >= 0} {
3579 set parent $removed_idx
3581 set unchanged_idx [string first " " $chunk]
3582 if {$unchanged_idx >= 0} {
3583 set parent $unchanged_idx
3585 # blame the current commit
3589 # then count other lines that belong to it
3590 for {set i $line} {[incr i -1] > $s_lno} {} {
3591 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3592 # Determine if the line is removed
3593 set removed_idx [string first "-" $chunk]
3595 set code [string index $chunk $parent]
3596 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3600 if {$removed_idx < 0} {
3610 incr dline [lindex $base_lines $parent]
3611 return [list $parent $dline]
3614 proc external_blame_diff {} {
3615 global currentid cmitmode
3616 global diff_menu_txtpos diff_menu_line
3617 global diff_menu_filebase flist_menu_file
3619 if {$cmitmode eq "tree"} {
3621 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3623 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3625 set parent_idx [lindex $hinfo 0]
3626 set line [lindex $hinfo 1]
3633 external_blame $parent_idx $line
3636 # Find the SHA1 ID of the blob for file $fname in the index
3638 proc index_sha1 {fname} {
3639 set f [open [list | git ls-files -s $fname] r]
3640 while {[gets $f line] >= 0} {
3641 set info [lindex [split $line "\t"] 0]
3642 set stage [lindex $info 2]
3643 if {$stage eq "0" || $stage eq "2"} {
3645 return [lindex $info 1]
3652 # Turn an absolute path into one relative to the current directory
3653 proc make_relative {f} {
3654 if {[file pathtype $f] eq "relative"} {
3657 set elts [file split $f]
3658 set here [file split [pwd]]
3663 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3670 set elts [concat $res [lrange $elts $ei end]]
3671 return [eval file join $elts]
3674 proc external_blame {parent_idx {line {}}} {
3675 global flist_menu_file cdup
3676 global nullid nullid2
3677 global parentlist selectedline currentid
3679 if {$parent_idx > 0} {
3680 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3682 set base_commit $currentid
3685 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3686 error_popup [mc "No such commit"]
3690 set cmdline [list git gui blame]
3691 if {$line ne {} && $line > 1} {
3692 lappend cmdline "--line=$line"
3694 set f [file join $cdup $flist_menu_file]
3695 # Unfortunately it seems git gui blame doesn't like
3696 # being given an absolute path...
3697 set f [make_relative $f]
3698 lappend cmdline $base_commit $f
3699 if {[catch {eval exec $cmdline &} err]} {
3700 error_popup "[mc "git gui blame: command failed:"] $err"
3704 proc show_line_source {} {
3705 global cmitmode currentid parents curview blamestuff blameinst
3706 global diff_menu_line diff_menu_filebase flist_menu_file
3707 global nullid nullid2 gitdir cdup
3710 if {$cmitmode eq "tree"} {
3712 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3714 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3715 if {$h eq {}} return
3716 set pi [lindex $h 0]
3718 mark_ctext_line $diff_menu_line
3722 if {$currentid eq $nullid} {
3724 # must be a merge in progress...
3726 # get the last line from .git/MERGE_HEAD
3727 set f [open [file join $gitdir MERGE_HEAD] r]
3728 set id [lindex [split [read $f] "\n"] end-1]
3731 error_popup [mc "Couldn't read merge head: %s" $err]
3734 } elseif {$parents($curview,$currentid) eq $nullid2} {
3735 # need to do the blame from the index
3737 set from_index [index_sha1 $flist_menu_file]
3739 error_popup [mc "Error reading index: %s" $err]
3743 set id $parents($curview,$currentid)
3746 set id [lindex $parents($curview,$currentid) $pi]
3748 set line [lindex $h 1]
3751 if {$from_index ne {}} {
3752 lappend blameargs | git cat-file blob $from_index
3754 lappend blameargs | git blame -p -L$line,+1
3755 if {$from_index ne {}} {
3756 lappend blameargs --contents -
3758 lappend blameargs $id
3760 lappend blameargs -- [file join $cdup $flist_menu_file]
3762 set f [open $blameargs r]
3764 error_popup [mc "Couldn't start git blame: %s" $err]
3767 nowbusy blaming [mc "Searching"]
3768 fconfigure $f -blocking 0
3769 set i [reg_instance $f]
3770 set blamestuff($i) {}
3772 filerun $f [list read_line_source $f $i]
3775 proc stopblaming {} {
3778 if {[info exists blameinst]} {
3779 stop_instance $blameinst
3785 proc read_line_source {fd inst} {
3786 global blamestuff curview commfd blameinst nullid nullid2
3788 while {[gets $fd line] >= 0} {
3789 lappend blamestuff($inst) $line
3797 fconfigure $fd -blocking 1
3798 if {[catch {close $fd} err]} {
3799 error_popup [mc "Error running git blame: %s" $err]
3804 set line [split [lindex $blamestuff($inst) 0] " "]
3805 set id [lindex $line 0]
3806 set lnum [lindex $line 1]
3807 if {[string length $id] == 40 && [string is xdigit $id] &&
3808 [string is digit -strict $lnum]} {
3809 # look for "filename" line
3810 foreach l $blamestuff($inst) {
3811 if {[string match "filename *" $l]} {
3812 set fname [string range $l 9 end]
3818 # all looks good, select it
3819 if {$id eq $nullid} {
3820 # blame uses all-zeroes to mean not committed,
3821 # which would mean a change in the index
3824 if {[commitinview $id $curview]} {
3825 selectline [rowofcommit $id] 1 [list $fname $lnum]
3827 error_popup [mc "That line comes from commit %s, \
3828 which is not in this view" [shortids $id]]
3831 puts "oops couldn't parse git blame output"
3836 # delete $dir when we see eof on $f (presumably because the child has exited)
3837 proc delete_at_eof {f dir} {
3838 while {[gets $f line] >= 0} {}
3840 if {[catch {close $f} err]} {
3841 error_popup "[mc "External diff viewer failed:"] $err"
3843 file delete -force $dir
3849 # Functions for adding and removing shell-type quoting
3851 proc shellquote {str} {
3852 if {![string match "*\['\"\\ \t]*" $str]} {
3855 if {![string match "*\['\"\\]*" $str]} {
3858 if {![string match "*'*" $str]} {
3861 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3864 proc shellarglist {l} {
3870 append str [shellquote $a]
3875 proc shelldequote {str} {
3880 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3881 append ret [string range $str $used end]
3882 set used [string length $str]
3885 set first [lindex $first 0]
3886 set ch [string index $str $first]
3887 if {$first > $used} {
3888 append ret [string range $str $used [expr {$first - 1}]]
3891 if {$ch eq " " || $ch eq "\t"} break
3894 set first [string first "'" $str $used]
3896 error "unmatched single-quote"
3898 append ret [string range $str $used [expr {$first - 1}]]
3903 if {$used >= [string length $str]} {
3904 error "trailing backslash"
3906 append ret [string index $str $used]
3911 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3912 error "unmatched double-quote"
3914 set first [lindex $first 0]
3915 set ch [string index $str $first]
3916 if {$first > $used} {
3917 append ret [string range $str $used [expr {$first - 1}]]
3920 if {$ch eq "\""} break
3922 append ret [string index $str $used]
3926 return [list $used $ret]
3929 proc shellsplit {str} {
3932 set str [string trimleft $str]
3933 if {$str eq {}} break
3934 set dq [shelldequote $str]
3935 set n [lindex $dq 0]
3936 set word [lindex $dq 1]
3937 set str [string range $str $n end]
3943 # Code to implement multiple views
3945 proc newview {ishighlight} {
3946 global nextviewnum newviewname newishighlight
3947 global revtreeargs viewargscmd newviewopts curview
3949 set newishighlight $ishighlight
3951 if {[winfo exists $top]} {
3955 decode_view_opts $nextviewnum $revtreeargs
3956 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3957 set newviewopts($nextviewnum,perm) 0
3958 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3959 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3962 set known_view_options {
3963 {perm b . {} {mc "Remember this view"}}
3964 {reflabel l + {} {mc "References (space separated list):"}}
3965 {refs t15 .. {} {mc "Branches & tags:"}}
3966 {allrefs b *. "--all" {mc "All refs"}}
3967 {branches b . "--branches" {mc "All (local) branches"}}
3968 {tags b . "--tags" {mc "All tags"}}
3969 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3970 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3971 {author t15 .. "--author=*" {mc "Author:"}}
3972 {committer t15 . "--committer=*" {mc "Committer:"}}
3973 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3974 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3975 {changes_l l + {} {mc "Changes to Files:"}}
3976 {pickaxe_s r0 . {} {mc "Fixed String"}}
3977 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3978 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3979 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3980 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3981 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3982 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3983 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3984 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3985 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3986 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3987 {lright b . "--left-right" {mc "Mark branch sides"}}
3988 {first b . "--first-parent" {mc "Limit to first parent"}}
3989 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3990 {args t50 *. {} {mc "Additional arguments to git log:"}}
3991 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3992 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3995 # Convert $newviewopts($n, ...) into args for git log.
3996 proc encode_view_opts {n} {
3997 global known_view_options newviewopts
4000 foreach opt $known_view_options {
4001 set patterns [lindex $opt 3]
4002 if {$patterns eq {}} continue
4003 set pattern [lindex $patterns 0]
4005 if {[lindex $opt 1] eq "b"} {
4006 set val $newviewopts($n,[lindex $opt 0])
4008 lappend rargs $pattern
4010 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4011 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4012 set val $newviewopts($n,$button_id)
4013 if {$val eq $value} {
4014 lappend rargs $pattern
4017 set val $newviewopts($n,[lindex $opt 0])
4018 set val [string trim $val]
4020 set pfix [string range $pattern 0 end-1]
4021 lappend rargs $pfix$val
4025 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4026 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4029 # Fill $newviewopts($n, ...) based on args for git log.
4030 proc decode_view_opts {n view_args} {
4031 global known_view_options newviewopts
4033 foreach opt $known_view_options {
4034 set id [lindex $opt 0]
4035 if {[lindex $opt 1] eq "b"} {
4038 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4040 regexp {^(.*_)} $id uselessvar id
4046 set newviewopts($n,$id) $val
4050 foreach arg $view_args {
4051 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4052 && ![info exists found(limit)]} {
4053 set newviewopts($n,limit) $cnt
4058 foreach opt $known_view_options {
4059 set id [lindex $opt 0]
4060 if {[info exists found($id)]} continue
4061 foreach pattern [lindex $opt 3] {
4062 if {![string match $pattern $arg]} continue
4063 if {[lindex $opt 1] eq "b"} {
4066 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4068 regexp {^(.*_)} $id uselessvar id
4072 set size [string length $pattern]
4073 set val [string range $arg [expr {$size-1}] end]
4075 set newviewopts($n,$id) $val
4079 if {[info exists val]} break
4081 if {[info exists val]} continue
4082 if {[regexp {^-} $arg]} {
4085 lappend refargs $arg
4088 set newviewopts($n,refs) [shellarglist $refargs]
4089 set newviewopts($n,args) [shellarglist $oargs]
4092 proc edit_or_newview {} {
4104 global viewname viewperm newviewname newviewopts
4105 global viewargs viewargscmd
4107 set top .gitkvedit-$curview
4108 if {[winfo exists $top]} {
4112 decode_view_opts $curview $viewargs($curview)
4113 set newviewname($curview) $viewname($curview)
4114 set newviewopts($curview,perm) $viewperm($curview)
4115 set newviewopts($curview,cmd) $viewargscmd($curview)
4116 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4119 proc vieweditor {top n title} {
4120 global newviewname newviewopts viewfiles bgcolor
4121 global known_view_options NS
4124 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4125 make_transient $top .
4128 ${NS}::frame $top.nfr
4129 ${NS}::label $top.nl -text [mc "View Name"]
4130 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4131 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4132 pack $top.nl -in $top.nfr -side left -padx {0 5}
4133 pack $top.name -in $top.nfr -side left -padx {0 25}
4139 foreach opt $known_view_options {
4140 set id [lindex $opt 0]
4141 set type [lindex $opt 1]
4142 set flags [lindex $opt 2]
4143 set title [eval [lindex $opt 4]]
4146 if {$flags eq "+" || $flags eq "*"} {
4147 set cframe $top.fr$cnt
4149 ${NS}::frame $cframe
4150 pack $cframe -in $top -fill x -pady 3 -padx 3
4151 set cexpand [expr {$flags eq "*"}]
4152 } elseif {$flags eq ".." || $flags eq "*."} {
4153 set cframe $top.fr$cnt
4155 ${NS}::frame $cframe
4156 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4157 set cexpand [expr {$flags eq "*."}]
4163 ${NS}::label $cframe.l_$id -text $title
4164 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4165 } elseif {$type eq "b"} {
4166 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4167 pack $cframe.c_$id -in $cframe -side left \
4168 -padx [list $lxpad 0] -expand $cexpand -anchor w
4169 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4170 regexp {^(.*_)} $id uselessvar button_id
4171 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4172 pack $cframe.c_$id -in $cframe -side left \
4173 -padx [list $lxpad 0] -expand $cexpand -anchor w
4174 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4175 ${NS}::label $cframe.l_$id -text $title
4176 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4177 -textvariable newviewopts($n,$id)
4178 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4179 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4180 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4181 ${NS}::label $cframe.l_$id -text $title
4182 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4183 -textvariable newviewopts($n,$id)
4184 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4185 pack $cframe.e_$id -in $cframe -side top -fill x
4186 } elseif {$type eq "path"} {
4187 ${NS}::label $top.l -text $title
4188 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4189 text $top.t -width 40 -height 5 -background $bgcolor
4190 if {[info exists viewfiles($n)]} {
4191 foreach f $viewfiles($n) {
4192 $top.t insert end $f
4193 $top.t insert end "\n"
4195 $top.t delete {end - 1c} end
4196 $top.t mark set insert 0.0
4198 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4202 ${NS}::frame $top.buts
4203 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4204 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4205 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4206 bind $top <Control-Return> [list newviewok $top $n]
4207 bind $top <F5> [list newviewok $top $n 1]
4208 bind $top <Escape> [list destroy $top]
4209 grid $top.buts.ok $top.buts.apply $top.buts.can
4210 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4211 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4212 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4213 pack $top.buts -in $top -side top -fill x
4217 proc doviewmenu {m first cmd op argv} {
4218 set nmenu [$m index end]
4219 for {set i $first} {$i <= $nmenu} {incr i} {
4220 if {[$m entrycget $i -command] eq $cmd} {
4221 eval $m $op $i $argv
4227 proc allviewmenus {n op args} {
4230 doviewmenu .bar.view 5 [list showview $n] $op $args
4231 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4234 proc newviewok {top n {apply 0}} {
4235 global nextviewnum newviewperm newviewname newishighlight
4236 global viewname viewfiles viewperm selectedview curview
4237 global viewargs viewargscmd newviewopts viewhlmenu
4240 set newargs [encode_view_opts $n]
4242 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4246 foreach f [split [$top.t get 0.0 end] "\n"] {
4247 set ft [string trim $f]
4252 if {![info exists viewfiles($n)]} {
4253 # creating a new view
4255 set viewname($n) $newviewname($n)
4256 set viewperm($n) $newviewopts($n,perm)
4257 set viewfiles($n) $files
4258 set viewargs($n) $newargs
4259 set viewargscmd($n) $newviewopts($n,cmd)
4261 if {!$newishighlight} {
4264 run addvhighlight $n
4267 # editing an existing view
4268 set viewperm($n) $newviewopts($n,perm)
4269 if {$newviewname($n) ne $viewname($n)} {
4270 set viewname($n) $newviewname($n)
4271 doviewmenu .bar.view 5 [list showview $n] \
4272 entryconf [list -label $viewname($n)]
4273 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4274 # entryconf [list -label $viewname($n) -value $viewname($n)]
4276 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4277 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4278 set viewfiles($n) $files
4279 set viewargs($n) $newargs
4280 set viewargscmd($n) $newviewopts($n,cmd)
4281 if {$curview == $n} {
4287 catch {destroy $top}
4291 global curview viewperm hlview selectedhlview
4293 if {$curview == 0} return
4294 if {[info exists hlview] && $hlview == $curview} {
4295 set selectedhlview [mc "None"]
4298 allviewmenus $curview delete
4299 set viewperm($curview) 0
4303 proc addviewmenu {n} {
4304 global viewname viewhlmenu
4306 .bar.view add radiobutton -label $viewname($n) \
4307 -command [list showview $n] -variable selectedview -value $n
4308 #$viewhlmenu add radiobutton -label $viewname($n) \
4309 # -command [list addvhighlight $n] -variable selectedhlview
4313 global curview cached_commitrow ordertok
4314 global displayorder parentlist rowidlist rowisopt rowfinal
4315 global colormap rowtextx nextcolor canvxmax
4316 global numcommits viewcomplete
4317 global selectedline currentid canv canvy0
4319 global pending_select mainheadid
4322 global hlview selectedhlview commitinterest
4324 if {$n == $curview} return
4326 set ymax [lindex [$canv cget -scrollregion] 3]
4327 set span [$canv yview]
4328 set ytop [expr {[lindex $span 0] * $ymax}]
4329 set ybot [expr {[lindex $span 1] * $ymax}]
4330 set yscreen [expr {($ybot - $ytop) / 2}]
4331 if {$selectedline ne {}} {
4332 set selid $currentid
4333 set y [yc $selectedline]
4334 if {$ytop < $y && $y < $ybot} {
4335 set yscreen [expr {$y - $ytop}]
4337 } elseif {[info exists pending_select]} {
4338 set selid $pending_select
4339 unset pending_select
4343 catch {unset treediffs}
4345 if {[info exists hlview] && $hlview == $n} {
4347 set selectedhlview [mc "None"]
4349 catch {unset commitinterest}
4350 catch {unset cached_commitrow}
4351 catch {unset ordertok}
4355 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4356 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4359 if {![info exists viewcomplete($n)]} {
4369 set numcommits $commitidx($n)
4371 catch {unset colormap}
4372 catch {unset rowtextx}
4374 set canvxmax [$canv cget -width]
4380 if {$selid ne {} && [commitinview $selid $n]} {
4381 set row [rowofcommit $selid]
4382 # try to get the selected row in the same position on the screen
4383 set ymax [lindex [$canv cget -scrollregion] 3]
4384 set ytop [expr {[yc $row] - $yscreen}]
4388 set yf [expr {$ytop * 1.0 / $ymax}]
4390 allcanvs yview moveto $yf
4394 } elseif {!$viewcomplete($n)} {
4395 reset_pending_select $selid
4397 reset_pending_select {}
4399 if {[commitinview $pending_select $curview]} {
4400 selectline [rowofcommit $pending_select] 1
4402 set row [first_real_row]
4403 if {$row < $numcommits} {
4408 if {!$viewcomplete($n)} {
4409 if {$numcommits == 0} {
4410 show_status [mc "Reading commits..."]
4412 } elseif {$numcommits == 0} {
4413 show_status [mc "No commits selected"]
4417 # Stuff relating to the highlighting facility
4419 proc ishighlighted {id} {
4420 global vhighlights fhighlights nhighlights rhighlights
4422 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4423 return $nhighlights($id)
4425 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4426 return $vhighlights($id)
4428 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4429 return $fhighlights($id)
4431 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4432 return $rhighlights($id)
4437 proc bolden {id font} {
4438 global canv linehtag currentid boldids need_redisplay markedid
4440 # need_redisplay = 1 means the display is stale and about to be redrawn
4441 if {$need_redisplay} return
4443 $canv itemconf $linehtag($id) -font $font
4444 if {[info exists currentid] && $id eq $currentid} {
4446 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4447 -outline {{}} -tags secsel \
4448 -fill [$canv cget -selectbackground]]
4451 if {[info exists markedid] && $id eq $markedid} {
4456 proc bolden_name {id font} {
4457 global canv2 linentag currentid boldnameids need_redisplay
4459 if {$need_redisplay} return
4460 lappend boldnameids $id
4461 $canv2 itemconf $linentag($id) -font $font
4462 if {[info exists currentid] && $id eq $currentid} {
4463 $canv2 delete secsel
4464 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4465 -outline {{}} -tags secsel \
4466 -fill [$canv2 cget -selectbackground]]
4475 foreach id $boldids {
4476 if {![ishighlighted $id]} {
4479 lappend stillbold $id
4482 set boldids $stillbold
4485 proc addvhighlight {n} {
4486 global hlview viewcomplete curview vhl_done commitidx
4488 if {[info exists hlview]} {
4492 if {$n != $curview && ![info exists viewcomplete($n)]} {
4495 set vhl_done $commitidx($hlview)
4496 if {$vhl_done > 0} {
4501 proc delvhighlight {} {
4502 global hlview vhighlights
4504 if {![info exists hlview]} return
4506 catch {unset vhighlights}
4510 proc vhighlightmore {} {
4511 global hlview vhl_done commitidx vhighlights curview
4513 set max $commitidx($hlview)
4514 set vr [visiblerows]
4515 set r0 [lindex $vr 0]
4516 set r1 [lindex $vr 1]
4517 for {set i $vhl_done} {$i < $max} {incr i} {
4518 set id [commitonrow $i $hlview]
4519 if {[commitinview $id $curview]} {
4520 set row [rowofcommit $id]
4521 if {$r0 <= $row && $row <= $r1} {
4522 if {![highlighted $row]} {
4523 bolden $id mainfontbold
4525 set vhighlights($id) 1
4533 proc askvhighlight {row id} {
4534 global hlview vhighlights iddrawn
4536 if {[commitinview $id $hlview]} {
4537 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4538 bolden $id mainfontbold
4540 set vhighlights($id) 1
4542 set vhighlights($id) 0
4546 proc hfiles_change {} {
4547 global highlight_files filehighlight fhighlights fh_serial
4548 global highlight_paths
4550 if {[info exists filehighlight]} {
4551 # delete previous highlights
4552 catch {close $filehighlight}
4554 catch {unset fhighlights}
4556 unhighlight_filelist
4558 set highlight_paths {}
4559 after cancel do_file_hl $fh_serial
4561 if {$highlight_files ne {}} {
4562 after 300 do_file_hl $fh_serial
4566 proc gdttype_change {name ix op} {
4567 global gdttype highlight_files findstring findpattern
4570 if {$findstring ne {}} {
4571 if {$gdttype eq [mc "containing:"]} {
4572 if {$highlight_files ne {}} {
4573 set highlight_files {}
4578 if {$findpattern ne {}} {
4582 set highlight_files $findstring
4587 # enable/disable findtype/findloc menus too
4590 proc find_change {name ix op} {
4591 global gdttype findstring highlight_files
4594 if {$gdttype eq [mc "containing:"]} {
4597 if {$highlight_files ne $findstring} {
4598 set highlight_files $findstring
4605 proc findcom_change args {
4606 global nhighlights boldnameids
4607 global findpattern findtype findstring gdttype
4610 # delete previous highlights, if any
4611 foreach id $boldnameids {
4612 bolden_name $id mainfont
4615 catch {unset nhighlights}
4618 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4620 } elseif {$findtype eq [mc "Regexp"]} {
4621 set findpattern $findstring
4623 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4625 set findpattern "*$e*"
4629 proc makepatterns {l} {
4632 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4633 if {[string index $ee end] eq "/"} {
4643 proc do_file_hl {serial} {
4644 global highlight_files filehighlight highlight_paths gdttype fhl_list
4645 global cdup findtype
4647 if {$gdttype eq [mc "touching paths:"]} {
4648 # If "exact" match then convert backslashes to forward slashes.
4649 # Most useful to support Windows-flavoured file paths.
4650 if {$findtype eq [mc "Exact"]} {
4651 set highlight_files [string map {"\\" "/"} $highlight_files]
4653 if {[catch {set paths [shellsplit $highlight_files]}]} return
4654 set highlight_paths [makepatterns $paths]
4656 set relative_paths {}
4657 foreach path $paths {
4658 lappend relative_paths [file join $cdup $path]
4660 set gdtargs [concat -- $relative_paths]
4661 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4662 set gdtargs [list "-S$highlight_files"]
4663 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4664 set gdtargs [list "-G$highlight_files"]
4666 # must be "containing:", i.e. we're searching commit info
4669 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4670 set filehighlight [open $cmd r+]
4671 fconfigure $filehighlight -blocking 0
4672 filerun $filehighlight readfhighlight
4678 proc flushhighlights {} {
4679 global filehighlight fhl_list
4681 if {[info exists filehighlight]} {
4683 puts $filehighlight ""
4684 flush $filehighlight
4688 proc askfilehighlight {row id} {
4689 global filehighlight fhighlights fhl_list
4691 lappend fhl_list $id
4692 set fhighlights($id) -1
4693 puts $filehighlight $id
4696 proc readfhighlight {} {
4697 global filehighlight fhighlights curview iddrawn
4698 global fhl_list find_dirn
4700 if {![info exists filehighlight]} {
4704 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4705 set line [string trim $line]
4706 set i [lsearch -exact $fhl_list $line]
4707 if {$i < 0} continue
4708 for {set j 0} {$j < $i} {incr j} {
4709 set id [lindex $fhl_list $j]
4710 set fhighlights($id) 0
4712 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4713 if {$line eq {}} continue
4714 if {![commitinview $line $curview]} continue
4715 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4716 bolden $line mainfontbold
4718 set fhighlights($line) 1
4720 if {[eof $filehighlight]} {
4722 puts "oops, git diff-tree died"
4723 catch {close $filehighlight}
4727 if {[info exists find_dirn]} {
4733 proc doesmatch {f} {
4734 global findtype findpattern
4736 if {$findtype eq [mc "Regexp"]} {
4737 return [regexp $findpattern $f]
4738 } elseif {$findtype eq [mc "IgnCase"]} {
4739 return [string match -nocase $findpattern $f]
4741 return [string match $findpattern $f]
4745 proc askfindhighlight {row id} {
4746 global nhighlights commitinfo iddrawn
4748 global markingmatches
4750 if {![info exists commitinfo($id)]} {
4753 set info $commitinfo($id)
4755 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4756 foreach f $info ty $fldtypes {
4757 if {$ty eq ""} continue
4758 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4760 if {$ty eq [mc "Author"]} {
4767 if {$isbold && [info exists iddrawn($id)]} {
4768 if {![ishighlighted $id]} {
4769 bolden $id mainfontbold
4771 bolden_name $id mainfontbold
4774 if {$markingmatches} {
4775 markrowmatches $row $id
4778 set nhighlights($id) $isbold
4781 proc markrowmatches {row id} {
4782 global canv canv2 linehtag linentag commitinfo findloc
4784 set headline [lindex $commitinfo($id) 0]
4785 set author [lindex $commitinfo($id) 1]
4786 $canv delete match$row
4787 $canv2 delete match$row
4788 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4789 set m [findmatches $headline]
4791 markmatches $canv $row $headline $linehtag($id) $m \
4792 [$canv itemcget $linehtag($id) -font] $row
4795 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4796 set m [findmatches $author]
4798 markmatches $canv2 $row $author $linentag($id) $m \
4799 [$canv2 itemcget $linentag($id) -font] $row
4804 proc vrel_change {name ix op} {
4805 global highlight_related
4808 if {$highlight_related ne [mc "None"]} {
4813 # prepare for testing whether commits are descendents or ancestors of a
4814 proc rhighlight_sel {a} {
4815 global descendent desc_todo ancestor anc_todo
4816 global highlight_related
4818 catch {unset descendent}
4819 set desc_todo [list $a]
4820 catch {unset ancestor}
4821 set anc_todo [list $a]
4822 if {$highlight_related ne [mc "None"]} {
4828 proc rhighlight_none {} {
4831 catch {unset rhighlights}
4835 proc is_descendent {a} {
4836 global curview children descendent desc_todo
4839 set la [rowofcommit $a]
4843 for {set i 0} {$i < [llength $todo]} {incr i} {
4844 set do [lindex $todo $i]
4845 if {[rowofcommit $do] < $la} {
4846 lappend leftover $do
4849 foreach nk $children($v,$do) {
4850 if {![info exists descendent($nk)]} {
4851 set descendent($nk) 1
4859 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4863 set descendent($a) 0
4864 set desc_todo $leftover
4867 proc is_ancestor {a} {
4868 global curview parents ancestor anc_todo
4871 set la [rowofcommit $a]
4875 for {set i 0} {$i < [llength $todo]} {incr i} {
4876 set do [lindex $todo $i]
4877 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4878 lappend leftover $do
4881 foreach np $parents($v,$do) {
4882 if {![info exists ancestor($np)]} {
4891 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4896 set anc_todo $leftover
4899 proc askrelhighlight {row id} {
4900 global descendent highlight_related iddrawn rhighlights
4901 global selectedline ancestor
4903 if {$selectedline eq {}} return
4905 if {$highlight_related eq [mc "Descendant"] ||
4906 $highlight_related eq [mc "Not descendant"]} {
4907 if {![info exists descendent($id)]} {
4910 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4913 } elseif {$highlight_related eq [mc "Ancestor"] ||
4914 $highlight_related eq [mc "Not ancestor"]} {
4915 if {![info exists ancestor($id)]} {
4918 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4922 if {[info exists iddrawn($id)]} {
4923 if {$isbold && ![ishighlighted $id]} {
4924 bolden $id mainfontbold
4927 set rhighlights($id) $isbold
4930 # Graph layout functions
4932 proc shortids {ids} {
4935 if {[llength $id] > 1} {
4936 lappend res [shortids $id]
4937 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4938 lappend res [string range $id 0 7]
4949 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4950 if {($n & $mask) != 0} {
4951 set ret [concat $ret $o]
4953 set o [concat $o $o]
4958 proc ordertoken {id} {
4959 global ordertok curview varcid varcstart varctok curview parents children
4960 global nullid nullid2
4962 if {[info exists ordertok($id)]} {
4963 return $ordertok($id)
4968 if {[info exists varcid($curview,$id)]} {
4969 set a $varcid($curview,$id)
4970 set p [lindex $varcstart($curview) $a]
4972 set p [lindex $children($curview,$id) 0]
4974 if {[info exists ordertok($p)]} {
4975 set tok $ordertok($p)
4978 set id [first_real_child $curview,$p]
4981 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4984 if {[llength $parents($curview,$id)] == 1} {
4985 lappend todo [list $p {}]
4987 set j [lsearch -exact $parents($curview,$id) $p]
4989 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4991 lappend todo [list $p [strrep $j]]
4994 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4995 set p [lindex $todo $i 0]
4996 append tok [lindex $todo $i 1]
4997 set ordertok($p) $tok
4999 set ordertok($origid) $tok
5003 # Work out where id should go in idlist so that order-token
5004 # values increase from left to right
5005 proc idcol {idlist id {i 0}} {
5006 set t [ordertoken $id]
5010 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5011 if {$i > [llength $idlist]} {
5012 set i [llength $idlist]
5014 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5017 if {$t > [ordertoken [lindex $idlist $i]]} {
5018 while {[incr i] < [llength $idlist] &&
5019 $t >= [ordertoken [lindex $idlist $i]]} {}
5025 proc initlayout {} {
5026 global rowidlist rowisopt rowfinal displayorder parentlist
5027 global numcommits canvxmax canv
5029 global colormap rowtextx
5038 set canvxmax [$canv cget -width]
5039 catch {unset colormap}
5040 catch {unset rowtextx}
5044 proc setcanvscroll {} {
5045 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5046 global lastscrollset lastscrollrows
5048 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5049 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5050 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5051 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5052 set lastscrollset [clock clicks -milliseconds]
5053 set lastscrollrows $numcommits
5056 proc visiblerows {} {
5057 global canv numcommits linespc
5059 set ymax [lindex [$canv cget -scrollregion] 3]
5060 if {$ymax eq {} || $ymax == 0} return
5062 set y0 [expr {int([lindex $f 0] * $ymax)}]
5063 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5067 set y1 [expr {int([lindex $f 1] * $ymax)}]
5068 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5069 if {$r1 >= $numcommits} {
5070 set r1 [expr {$numcommits - 1}]
5072 return [list $r0 $r1]
5075 proc layoutmore {} {
5076 global commitidx viewcomplete curview
5077 global numcommits pending_select curview
5078 global lastscrollset lastscrollrows
5080 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5081 [clock clicks -milliseconds] - $lastscrollset > 500} {
5084 if {[info exists pending_select] &&
5085 [commitinview $pending_select $curview]} {
5087 selectline [rowofcommit $pending_select] 1
5092 # With path limiting, we mightn't get the actual HEAD commit,
5093 # so ask git rev-list what is the first ancestor of HEAD that
5094 # touches a file in the path limit.
5095 proc get_viewmainhead {view} {
5096 global viewmainheadid vfilelimit viewinstances mainheadid
5099 set rfd [open [concat | git rev-list -1 $mainheadid \
5100 -- $vfilelimit($view)] r]
5101 set j [reg_instance $rfd]
5102 lappend viewinstances($view) $j
5103 fconfigure $rfd -blocking 0
5104 filerun $rfd [list getviewhead $rfd $j $view]
5105 set viewmainheadid($curview) {}
5109 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5110 proc getviewhead {fd inst view} {
5111 global viewmainheadid commfd curview viewinstances showlocalchanges
5114 if {[gets $fd line] < 0} {
5118 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5121 set viewmainheadid($view) $id
5124 set i [lsearch -exact $viewinstances($view) $inst]
5126 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5128 if {$showlocalchanges && $id ne {} && $view == $curview} {
5134 proc doshowlocalchanges {} {
5135 global curview viewmainheadid
5137 if {$viewmainheadid($curview) eq {}} return
5138 if {[commitinview $viewmainheadid($curview) $curview]} {
5141 interestedin $viewmainheadid($curview) dodiffindex
5145 proc dohidelocalchanges {} {
5146 global nullid nullid2 lserial curview
5148 if {[commitinview $nullid $curview]} {
5149 removefakerow $nullid
5151 if {[commitinview $nullid2 $curview]} {
5152 removefakerow $nullid2
5157 # spawn off a process to do git diff-index --cached HEAD
5158 proc dodiffindex {} {
5159 global lserial showlocalchanges vfilelimit curview
5162 if {!$showlocalchanges || !$hasworktree} return
5164 set cmd "|git diff-index --cached HEAD"
5165 if {$vfilelimit($curview) ne {}} {
5166 set cmd [concat $cmd -- $vfilelimit($curview)]
5168 set fd [open $cmd r]
5169 fconfigure $fd -blocking 0
5170 set i [reg_instance $fd]
5171 filerun $fd [list readdiffindex $fd $lserial $i]
5174 proc readdiffindex {fd serial inst} {
5175 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5179 if {[gets $fd line] < 0} {
5185 # we only need to see one line and we don't really care what it says...
5188 if {$serial != $lserial} {
5192 # now see if there are any local changes not checked in to the index
5193 set cmd "|git diff-files"
5194 if {$vfilelimit($curview) ne {}} {
5195 set cmd [concat $cmd -- $vfilelimit($curview)]
5197 set fd [open $cmd r]
5198 fconfigure $fd -blocking 0
5199 set i [reg_instance $fd]
5200 filerun $fd [list readdifffiles $fd $serial $i]
5202 if {$isdiff && ![commitinview $nullid2 $curview]} {
5203 # add the line for the changes in the index to the graph
5204 set hl [mc "Local changes checked in to index but not committed"]
5205 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5206 set commitdata($nullid2) "\n $hl\n"
5207 if {[commitinview $nullid $curview]} {
5208 removefakerow $nullid
5210 insertfakerow $nullid2 $viewmainheadid($curview)
5211 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5212 if {[commitinview $nullid $curview]} {
5213 removefakerow $nullid
5215 removefakerow $nullid2
5220 proc readdifffiles {fd serial inst} {
5221 global viewmainheadid nullid nullid2 curview
5222 global commitinfo commitdata lserial
5225 if {[gets $fd line] < 0} {
5231 # we only need to see one line and we don't really care what it says...
5234 if {$serial != $lserial} {
5238 if {$isdiff && ![commitinview $nullid $curview]} {
5239 # add the line for the local diff to the graph
5240 set hl [mc "Local uncommitted changes, not checked in to index"]
5241 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5242 set commitdata($nullid) "\n $hl\n"
5243 if {[commitinview $nullid2 $curview]} {
5246 set p $viewmainheadid($curview)
5248 insertfakerow $nullid $p
5249 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5250 removefakerow $nullid
5255 proc nextuse {id row} {
5256 global curview children
5258 if {[info exists children($curview,$id)]} {
5259 foreach kid $children($curview,$id) {
5260 if {![commitinview $kid $curview]} {
5263 if {[rowofcommit $kid] > $row} {
5264 return [rowofcommit $kid]
5268 if {[commitinview $id $curview]} {
5269 return [rowofcommit $id]
5274 proc prevuse {id row} {
5275 global curview children
5278 if {[info exists children($curview,$id)]} {
5279 foreach kid $children($curview,$id) {
5280 if {![commitinview $kid $curview]} break
5281 if {[rowofcommit $kid] < $row} {
5282 set ret [rowofcommit $kid]
5289 proc make_idlist {row} {
5290 global displayorder parentlist uparrowlen downarrowlen mingaplen
5291 global commitidx curview children
5293 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5297 set ra [expr {$row - $downarrowlen}]
5301 set rb [expr {$row + $uparrowlen}]
5302 if {$rb > $commitidx($curview)} {
5303 set rb $commitidx($curview)
5305 make_disporder $r [expr {$rb + 1}]
5307 for {} {$r < $ra} {incr r} {
5308 set nextid [lindex $displayorder [expr {$r + 1}]]
5309 foreach p [lindex $parentlist $r] {
5310 if {$p eq $nextid} continue
5311 set rn [nextuse $p $r]
5313 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5314 lappend ids [list [ordertoken $p] $p]
5318 for {} {$r < $row} {incr r} {
5319 set nextid [lindex $displayorder [expr {$r + 1}]]
5320 foreach p [lindex $parentlist $r] {
5321 if {$p eq $nextid} continue
5322 set rn [nextuse $p $r]
5323 if {$rn < 0 || $rn >= $row} {
5324 lappend ids [list [ordertoken $p] $p]
5328 set id [lindex $displayorder $row]
5329 lappend ids [list [ordertoken $id] $id]
5331 foreach p [lindex $parentlist $r] {
5332 set firstkid [lindex $children($curview,$p) 0]
5333 if {[rowofcommit $firstkid] < $row} {
5334 lappend ids [list [ordertoken $p] $p]
5338 set id [lindex $displayorder $r]
5340 set firstkid [lindex $children($curview,$id) 0]
5341 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5342 lappend ids [list [ordertoken $id] $id]
5347 foreach idx [lsort -unique $ids] {
5348 lappend idlist [lindex $idx 1]
5353 proc rowsequal {a b} {
5354 while {[set i [lsearch -exact $a {}]] >= 0} {
5355 set a [lreplace $a $i $i]
5357 while {[set i [lsearch -exact $b {}]] >= 0} {
5358 set b [lreplace $b $i $i]
5360 return [expr {$a eq $b}]
5363 proc makeupline {id row rend col} {
5364 global rowidlist uparrowlen downarrowlen mingaplen
5366 for {set r $rend} {1} {set r $rstart} {
5367 set rstart [prevuse $id $r]
5368 if {$rstart < 0} return
5369 if {$rstart < $row} break
5371 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5372 set rstart [expr {$rend - $uparrowlen - 1}]
5374 for {set r $rstart} {[incr r] <= $row} {} {
5375 set idlist [lindex $rowidlist $r]
5376 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5377 set col [idcol $idlist $id $col]
5378 lset rowidlist $r [linsert $idlist $col $id]
5384 proc layoutrows {row endrow} {
5385 global rowidlist rowisopt rowfinal displayorder
5386 global uparrowlen downarrowlen maxwidth mingaplen
5387 global children parentlist
5388 global commitidx viewcomplete curview
5390 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5393 set rm1 [expr {$row - 1}]
5394 foreach id [lindex $rowidlist $rm1] {
5399 set final [lindex $rowfinal $rm1]
5401 for {} {$row < $endrow} {incr row} {
5402 set rm1 [expr {$row - 1}]
5403 if {$rm1 < 0 || $idlist eq {}} {
5404 set idlist [make_idlist $row]
5407 set id [lindex $displayorder $rm1]
5408 set col [lsearch -exact $idlist $id]
5409 set idlist [lreplace $idlist $col $col]
5410 foreach p [lindex $parentlist $rm1] {
5411 if {[lsearch -exact $idlist $p] < 0} {
5412 set col [idcol $idlist $p $col]
5413 set idlist [linsert $idlist $col $p]
5414 # if not the first child, we have to insert a line going up
5415 if {$id ne [lindex $children($curview,$p) 0]} {
5416 makeupline $p $rm1 $row $col
5420 set id [lindex $displayorder $row]
5421 if {$row > $downarrowlen} {
5422 set termrow [expr {$row - $downarrowlen - 1}]
5423 foreach p [lindex $parentlist $termrow] {
5424 set i [lsearch -exact $idlist $p]
5425 if {$i < 0} continue
5426 set nr [nextuse $p $termrow]
5427 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5428 set idlist [lreplace $idlist $i $i]
5432 set col [lsearch -exact $idlist $id]
5434 set col [idcol $idlist $id]
5435 set idlist [linsert $idlist $col $id]
5436 if {$children($curview,$id) ne {}} {
5437 makeupline $id $rm1 $row $col
5440 set r [expr {$row + $uparrowlen - 1}]
5441 if {$r < $commitidx($curview)} {
5443 foreach p [lindex $parentlist $r] {
5444 if {[lsearch -exact $idlist $p] >= 0} continue
5445 set fk [lindex $children($curview,$p) 0]
5446 if {[rowofcommit $fk] < $row} {
5447 set x [idcol $idlist $p $x]
5448 set idlist [linsert $idlist $x $p]
5451 if {[incr r] < $commitidx($curview)} {
5452 set p [lindex $displayorder $r]
5453 if {[lsearch -exact $idlist $p] < 0} {
5454 set fk [lindex $children($curview,$p) 0]
5455 if {$fk ne {} && [rowofcommit $fk] < $row} {
5456 set x [idcol $idlist $p $x]
5457 set idlist [linsert $idlist $x $p]
5463 if {$final && !$viewcomplete($curview) &&
5464 $row + $uparrowlen + $mingaplen + $downarrowlen
5465 >= $commitidx($curview)} {
5468 set l [llength $rowidlist]
5470 lappend rowidlist $idlist
5472 lappend rowfinal $final
5473 } elseif {$row < $l} {
5474 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5475 lset rowidlist $row $idlist
5478 lset rowfinal $row $final
5480 set pad [ntimes [expr {$row - $l}] {}]
5481 set rowidlist [concat $rowidlist $pad]
5482 lappend rowidlist $idlist
5483 set rowfinal [concat $rowfinal $pad]
5484 lappend rowfinal $final
5485 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5491 proc changedrow {row} {
5492 global displayorder iddrawn rowisopt need_redisplay
5494 set l [llength $rowisopt]
5496 lset rowisopt $row 0
5497 if {$row + 1 < $l} {
5498 lset rowisopt [expr {$row + 1}] 0
5499 if {$row + 2 < $l} {
5500 lset rowisopt [expr {$row + 2}] 0
5504 set id [lindex $displayorder $row]
5505 if {[info exists iddrawn($id)]} {
5506 set need_redisplay 1
5510 proc insert_pad {row col npad} {
5513 set pad [ntimes $npad {}]
5514 set idlist [lindex $rowidlist $row]
5515 set bef [lrange $idlist 0 [expr {$col - 1}]]
5516 set aft [lrange $idlist $col end]
5517 set i [lsearch -exact $aft {}]
5519 set aft [lreplace $aft $i $i]
5521 lset rowidlist $row [concat $bef $pad $aft]
5525 proc optimize_rows {row col endrow} {
5526 global rowidlist rowisopt displayorder curview children
5531 for {} {$row < $endrow} {incr row; set col 0} {
5532 if {[lindex $rowisopt $row]} continue
5534 set y0 [expr {$row - 1}]
5535 set ym [expr {$row - 2}]
5536 set idlist [lindex $rowidlist $row]
5537 set previdlist [lindex $rowidlist $y0]
5538 if {$idlist eq {} || $previdlist eq {}} continue
5540 set pprevidlist [lindex $rowidlist $ym]
5541 if {$pprevidlist eq {}} continue
5547 for {} {$col < [llength $idlist]} {incr col} {
5548 set id [lindex $idlist $col]
5549 if {[lindex $previdlist $col] eq $id} continue
5554 set x0 [lsearch -exact $previdlist $id]
5555 if {$x0 < 0} continue
5556 set z [expr {$x0 - $col}]
5560 set xm [lsearch -exact $pprevidlist $id]
5562 set z0 [expr {$xm - $x0}]
5566 # if row y0 is the first child of $id then it's not an arrow
5567 if {[lindex $children($curview,$id) 0] ne
5568 [lindex $displayorder $y0]} {
5572 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5573 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5576 # Looking at lines from this row to the previous row,
5577 # make them go straight up if they end in an arrow on
5578 # the previous row; otherwise make them go straight up
5580 if {$z < -1 || ($z < 0 && $isarrow)} {
5581 # Line currently goes left too much;
5582 # insert pads in the previous row, then optimize it
5583 set npad [expr {-1 - $z + $isarrow}]
5584 insert_pad $y0 $x0 $npad
5586 optimize_rows $y0 $x0 $row
5588 set previdlist [lindex $rowidlist $y0]
5589 set x0 [lsearch -exact $previdlist $id]
5590 set z [expr {$x0 - $col}]
5592 set pprevidlist [lindex $rowidlist $ym]
5593 set xm [lsearch -exact $pprevidlist $id]
5594 set z0 [expr {$xm - $x0}]
5596 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5597 # Line currently goes right too much;
5598 # insert pads in this line
5599 set npad [expr {$z - 1 + $isarrow}]
5600 insert_pad $row $col $npad
5601 set idlist [lindex $rowidlist $row]
5603 set z [expr {$x0 - $col}]
5606 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5607 # this line links to its first child on row $row-2
5608 set id [lindex $displayorder $ym]
5609 set xc [lsearch -exact $pprevidlist $id]
5611 set z0 [expr {$xc - $x0}]
5614 # avoid lines jigging left then immediately right
5615 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5616 insert_pad $y0 $x0 1
5618 optimize_rows $y0 $x0 $row
5619 set previdlist [lindex $rowidlist $y0]
5623 # Find the first column that doesn't have a line going right
5624 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5625 set id [lindex $idlist $col]
5626 if {$id eq {}} break
5627 set x0 [lsearch -exact $previdlist $id]
5629 # check if this is the link to the first child
5630 set kid [lindex $displayorder $y0]
5631 if {[lindex $children($curview,$id) 0] eq $kid} {
5632 # it is, work out offset to child
5633 set x0 [lsearch -exact $previdlist $kid]
5636 if {$x0 <= $col} break
5638 # Insert a pad at that column as long as it has a line and
5639 # isn't the last column
5640 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5641 set idlist [linsert $idlist $col {}]
5642 lset rowidlist $row $idlist
5650 global canvx0 linespc
5651 return [expr {$canvx0 + $col * $linespc}]
5655 global canvy0 linespc
5656 return [expr {$canvy0 + $row * $linespc}]
5659 proc linewidth {id} {
5660 global thickerline lthickness
5663 if {[info exists thickerline] && $id eq $thickerline} {
5664 set wid [expr {2 * $lthickness}]
5669 proc rowranges {id} {
5670 global curview children uparrowlen downarrowlen
5673 set kids $children($curview,$id)
5679 foreach child $kids {
5680 if {![commitinview $child $curview]} break
5681 set row [rowofcommit $child]
5682 if {![info exists prev]} {
5683 lappend ret [expr {$row + 1}]
5685 if {$row <= $prevrow} {
5686 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5688 # see if the line extends the whole way from prevrow to row
5689 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5690 [lsearch -exact [lindex $rowidlist \
5691 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5692 # it doesn't, see where it ends
5693 set r [expr {$prevrow + $downarrowlen}]
5694 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5695 while {[incr r -1] > $prevrow &&
5696 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5698 while {[incr r] <= $row &&
5699 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5703 # see where it starts up again
5704 set r [expr {$row - $uparrowlen}]
5705 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5706 while {[incr r] < $row &&
5707 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5709 while {[incr r -1] >= $prevrow &&
5710 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5716 if {$child eq $id} {
5725 proc drawlineseg {id row endrow arrowlow} {
5726 global rowidlist displayorder iddrawn linesegs
5727 global canv colormap linespc curview maxlinelen parentlist
5729 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5730 set le [expr {$row + 1}]
5733 set c [lsearch -exact [lindex $rowidlist $le] $id]
5739 set x [lindex $displayorder $le]
5744 if {[info exists iddrawn($x)] || $le == $endrow} {
5745 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5761 if {[info exists linesegs($id)]} {
5762 set lines $linesegs($id)
5764 set r0 [lindex $li 0]
5766 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5776 set li [lindex $lines [expr {$i-1}]]
5777 set r1 [lindex $li 1]
5778 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5783 set x [lindex $cols [expr {$le - $row}]]
5784 set xp [lindex $cols [expr {$le - 1 - $row}]]
5785 set dir [expr {$xp - $x}]
5787 set ith [lindex $lines $i 2]
5788 set coords [$canv coords $ith]
5789 set ah [$canv itemcget $ith -arrow]
5790 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5791 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5792 if {$x2 ne {} && $x - $x2 == $dir} {
5793 set coords [lrange $coords 0 end-2]
5796 set coords [list [xc $le $x] [yc $le]]
5799 set itl [lindex $lines [expr {$i-1}] 2]
5800 set al [$canv itemcget $itl -arrow]
5801 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5802 } elseif {$arrowlow} {
5803 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5804 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5808 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5809 for {set y $le} {[incr y -1] > $row} {} {
5811 set xp [lindex $cols [expr {$y - 1 - $row}]]
5812 set ndir [expr {$xp - $x}]
5813 if {$dir != $ndir || $xp < 0} {
5814 lappend coords [xc $y $x] [yc $y]
5820 # join parent line to first child
5821 set ch [lindex $displayorder $row]
5822 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5824 puts "oops: drawlineseg: child $ch not on row $row"
5825 } elseif {$xc != $x} {
5826 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5827 set d [expr {int(0.5 * $linespc)}]
5830 set x2 [expr {$x1 - $d}]
5832 set x2 [expr {$x1 + $d}]
5835 set y1 [expr {$y2 + $d}]
5836 lappend coords $x1 $y1 $x2 $y2
5837 } elseif {$xc < $x - 1} {
5838 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5839 } elseif {$xc > $x + 1} {
5840 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5844 lappend coords [xc $row $x] [yc $row]
5846 set xn [xc $row $xp]
5848 lappend coords $xn $yn
5852 set t [$canv create line $coords -width [linewidth $id] \
5853 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5856 set lines [linsert $lines $i [list $row $le $t]]
5858 $canv coords $ith $coords
5859 if {$arrow ne $ah} {
5860 $canv itemconf $ith -arrow $arrow
5862 lset lines $i 0 $row
5865 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5866 set ndir [expr {$xo - $xp}]
5867 set clow [$canv coords $itl]
5868 if {$dir == $ndir} {
5869 set clow [lrange $clow 2 end]
5871 set coords [concat $coords $clow]
5873 lset lines [expr {$i-1}] 1 $le
5875 # coalesce two pieces
5877 set b [lindex $lines [expr {$i-1}] 0]
5878 set e [lindex $lines $i 1]
5879 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5881 $canv coords $itl $coords
5882 if {$arrow ne $al} {
5883 $canv itemconf $itl -arrow $arrow
5887 set linesegs($id) $lines
5891 proc drawparentlinks {id row} {
5892 global rowidlist canv colormap curview parentlist
5893 global idpos linespc
5895 set rowids [lindex $rowidlist $row]
5896 set col [lsearch -exact $rowids $id]
5897 if {$col < 0} return
5898 set olds [lindex $parentlist $row]
5899 set row2 [expr {$row + 1}]
5900 set x [xc $row $col]
5903 set d [expr {int(0.5 * $linespc)}]
5904 set ymid [expr {$y + $d}]
5905 set ids [lindex $rowidlist $row2]
5906 # rmx = right-most X coord used
5909 set i [lsearch -exact $ids $p]
5911 puts "oops, parent $p of $id not in list"
5914 set x2 [xc $row2 $i]
5918 set j [lsearch -exact $rowids $p]
5920 # drawlineseg will do this one for us
5924 # should handle duplicated parents here...
5925 set coords [list $x $y]
5927 # if attaching to a vertical segment, draw a smaller
5928 # slant for visual distinctness
5931 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5933 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5935 } elseif {$i < $col && $i < $j} {
5936 # segment slants towards us already
5937 lappend coords [xc $row $j] $y
5939 if {$i < $col - 1} {
5940 lappend coords [expr {$x2 + $linespc}] $y
5941 } elseif {$i > $col + 1} {
5942 lappend coords [expr {$x2 - $linespc}] $y
5944 lappend coords $x2 $y2
5947 lappend coords $x2 $y2
5949 set t [$canv create line $coords -width [linewidth $p] \
5950 -fill $colormap($p) -tags lines.$p]
5954 if {$rmx > [lindex $idpos($id) 1]} {
5955 lset idpos($id) 1 $rmx
5960 proc drawlines {id} {
5963 $canv itemconf lines.$id -width [linewidth $id]
5966 proc drawcmittext {id row col} {
5967 global linespc canv canv2 canv3 fgcolor curview
5968 global cmitlisted commitinfo rowidlist parentlist
5969 global rowtextx idpos idtags idheads idotherrefs
5970 global linehtag linentag linedtag selectedline
5971 global canvxmax boldids boldnameids fgcolor markedid
5972 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5973 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5974 global circleoutlinecolor
5976 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5977 set listed $cmitlisted($curview,$id)
5978 if {$id eq $nullid} {
5979 set ofill $workingfilescirclecolor
5980 } elseif {$id eq $nullid2} {
5981 set ofill $indexcirclecolor
5982 } elseif {$id eq $mainheadid} {
5983 set ofill $mainheadcirclecolor
5985 set ofill [lindex $circlecolors $listed]
5987 set x [xc $row $col]
5989 set orad [expr {$linespc / 3}]
5991 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5992 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5993 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
5994 } elseif {$listed == 3} {
5995 # triangle pointing left for left-side commits
5996 set t [$canv create polygon \
5997 [expr {$x - $orad}] $y \
5998 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5999 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6000 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6002 # triangle pointing right for right-side commits
6003 set t [$canv create polygon \
6004 [expr {$x + $orad - 1}] $y \
6005 [expr {$x - $orad}] [expr {$y - $orad}] \
6006 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6007 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6009 set circleitem($row) $t
6011 $canv bind $t <1> {selcanvline {} %x %y}
6012 set rmx [llength [lindex $rowidlist $row]]
6013 set olds [lindex $parentlist $row]
6015 set nextids [lindex $rowidlist [expr {$row + 1}]]
6017 set i [lsearch -exact $nextids $p]
6023 set xt [xc $row $rmx]
6024 set rowtextx($row) $xt
6025 set idpos($id) [list $x $xt $y]
6026 if {[info exists idtags($id)] || [info exists idheads($id)]
6027 || [info exists idotherrefs($id)]} {
6028 set xt [drawtags $id $x $xt $y]
6030 if {[lindex $commitinfo($id) 6] > 0} {
6031 set xt [drawnotesign $xt $y]
6033 set headline [lindex $commitinfo($id) 0]
6034 set name [lindex $commitinfo($id) 1]
6035 set date [lindex $commitinfo($id) 2]
6036 set date [formatdate $date]
6039 set isbold [ishighlighted $id]
6042 set font mainfontbold
6044 lappend boldnameids $id
6045 set nfont mainfontbold
6048 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6049 -text $headline -font $font -tags text]
6050 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6051 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6052 -text $name -font $nfont -tags text]
6053 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6054 -text $date -font mainfont -tags text]
6055 if {$selectedline == $row} {
6058 if {[info exists markedid] && $markedid eq $id} {
6061 set xr [expr {$xt + [font measure $font $headline]}]
6062 if {$xr > $canvxmax} {
6068 proc drawcmitrow {row} {
6069 global displayorder rowidlist nrows_drawn
6070 global iddrawn markingmatches
6071 global commitinfo numcommits
6072 global filehighlight fhighlights findpattern nhighlights
6073 global hlview vhighlights
6074 global highlight_related rhighlights
6076 if {$row >= $numcommits} return
6078 set id [lindex $displayorder $row]
6079 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6080 askvhighlight $row $id
6082 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6083 askfilehighlight $row $id
6085 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6086 askfindhighlight $row $id
6088 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6089 askrelhighlight $row $id
6091 if {![info exists iddrawn($id)]} {
6092 set col [lsearch -exact [lindex $rowidlist $row] $id]
6094 puts "oops, row $row id $id not in list"
6097 if {![info exists commitinfo($id)]} {
6101 drawcmittext $id $row $col
6105 if {$markingmatches} {
6106 markrowmatches $row $id
6110 proc drawcommits {row {endrow {}}} {
6111 global numcommits iddrawn displayorder curview need_redisplay
6112 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6117 if {$endrow eq {}} {
6120 if {$endrow >= $numcommits} {
6121 set endrow [expr {$numcommits - 1}]
6124 set rl1 [expr {$row - $downarrowlen - 3}]
6128 set ro1 [expr {$row - 3}]
6132 set r2 [expr {$endrow + $uparrowlen + 3}]
6133 if {$r2 > $numcommits} {
6136 for {set r $rl1} {$r < $r2} {incr r} {
6137 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6141 set rl1 [expr {$r + 1}]
6147 optimize_rows $ro1 0 $r2
6148 if {$need_redisplay || $nrows_drawn > 2000} {
6152 # make the lines join to already-drawn rows either side
6153 set r [expr {$row - 1}]
6154 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6157 set er [expr {$endrow + 1}]
6158 if {$er >= $numcommits ||
6159 ![info exists iddrawn([lindex $displayorder $er])]} {
6162 for {} {$r <= $er} {incr r} {
6163 set id [lindex $displayorder $r]
6164 set wasdrawn [info exists iddrawn($id)]
6166 if {$r == $er} break
6167 set nextid [lindex $displayorder [expr {$r + 1}]]
6168 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6169 drawparentlinks $id $r
6171 set rowids [lindex $rowidlist $r]
6172 foreach lid $rowids {
6173 if {$lid eq {}} continue
6174 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6176 # see if this is the first child of any of its parents
6177 foreach p [lindex $parentlist $r] {
6178 if {[lsearch -exact $rowids $p] < 0} {
6179 # make this line extend up to the child
6180 set lineend($p) [drawlineseg $p $r $er 0]
6184 set lineend($lid) [drawlineseg $lid $r $er 1]
6190 proc undolayout {row} {
6191 global uparrowlen mingaplen downarrowlen
6192 global rowidlist rowisopt rowfinal need_redisplay
6194 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6198 if {[llength $rowidlist] > $r} {
6200 set rowidlist [lrange $rowidlist 0 $r]
6201 set rowfinal [lrange $rowfinal 0 $r]
6202 set rowisopt [lrange $rowisopt 0 $r]
6203 set need_redisplay 1
6208 proc drawvisible {} {
6209 global canv linespc curview vrowmod selectedline targetrow targetid
6210 global need_redisplay cscroll numcommits
6212 set fs [$canv yview]
6213 set ymax [lindex [$canv cget -scrollregion] 3]
6214 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6215 set f0 [lindex $fs 0]
6216 set f1 [lindex $fs 1]
6217 set y0 [expr {int($f0 * $ymax)}]
6218 set y1 [expr {int($f1 * $ymax)}]
6220 if {[info exists targetid]} {
6221 if {[commitinview $targetid $curview]} {
6222 set r [rowofcommit $targetid]
6223 if {$r != $targetrow} {
6224 # Fix up the scrollregion and change the scrolling position
6225 # now that our target row has moved.
6226 set diff [expr {($r - $targetrow) * $linespc}]
6229 set ymax [lindex [$canv cget -scrollregion] 3]
6232 set f0 [expr {$y0 / $ymax}]
6233 set f1 [expr {$y1 / $ymax}]
6234 allcanvs yview moveto $f0
6235 $cscroll set $f0 $f1
6236 set need_redisplay 1
6243 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6244 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6245 if {$endrow >= $vrowmod($curview)} {
6246 update_arcrows $curview
6248 if {$selectedline ne {} &&
6249 $row <= $selectedline && $selectedline <= $endrow} {
6250 set targetrow $selectedline
6251 } elseif {[info exists targetid]} {
6252 set targetrow [expr {int(($row + $endrow) / 2)}]
6254 if {[info exists targetrow]} {
6255 if {$targetrow >= $numcommits} {
6256 set targetrow [expr {$numcommits - 1}]
6258 set targetid [commitonrow $targetrow]
6260 drawcommits $row $endrow
6263 proc clear_display {} {
6264 global iddrawn linesegs need_redisplay nrows_drawn
6265 global vhighlights fhighlights nhighlights rhighlights
6266 global linehtag linentag linedtag boldids boldnameids
6269 catch {unset iddrawn}
6270 catch {unset linesegs}
6271 catch {unset linehtag}
6272 catch {unset linentag}
6273 catch {unset linedtag}
6276 catch {unset vhighlights}
6277 catch {unset fhighlights}
6278 catch {unset nhighlights}
6279 catch {unset rhighlights}
6280 set need_redisplay 0
6284 proc findcrossings {id} {
6285 global rowidlist parentlist numcommits displayorder
6289 foreach {s e} [rowranges $id] {
6290 if {$e >= $numcommits} {
6291 set e [expr {$numcommits - 1}]
6293 if {$e <= $s} continue
6294 for {set row $e} {[incr row -1] >= $s} {} {
6295 set x [lsearch -exact [lindex $rowidlist $row] $id]
6297 set olds [lindex $parentlist $row]
6298 set kid [lindex $displayorder $row]
6299 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6300 if {$kidx < 0} continue
6301 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6303 set px [lsearch -exact $nextrow $p]
6304 if {$px < 0} continue
6305 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6306 if {[lsearch -exact $ccross $p] >= 0} continue
6307 if {$x == $px + ($kidx < $px? -1: 1)} {
6309 } elseif {[lsearch -exact $cross $p] < 0} {
6316 return [concat $ccross {{}} $cross]
6319 proc assigncolor {id} {
6320 global colormap colors nextcolor
6321 global parents children children curview
6323 if {[info exists colormap($id)]} return
6324 set ncolors [llength $colors]
6325 if {[info exists children($curview,$id)]} {
6326 set kids $children($curview,$id)
6330 if {[llength $kids] == 1} {
6331 set child [lindex $kids 0]
6332 if {[info exists colormap($child)]
6333 && [llength $parents($curview,$child)] == 1} {
6334 set colormap($id) $colormap($child)
6340 foreach x [findcrossings $id] {
6342 # delimiter between corner crossings and other crossings
6343 if {[llength $badcolors] >= $ncolors - 1} break
6344 set origbad $badcolors
6346 if {[info exists colormap($x)]
6347 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6348 lappend badcolors $colormap($x)
6351 if {[llength $badcolors] >= $ncolors} {
6352 set badcolors $origbad
6354 set origbad $badcolors
6355 if {[llength $badcolors] < $ncolors - 1} {
6356 foreach child $kids {
6357 if {[info exists colormap($child)]
6358 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6359 lappend badcolors $colormap($child)
6361 foreach p $parents($curview,$child) {
6362 if {[info exists colormap($p)]
6363 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6364 lappend badcolors $colormap($p)
6368 if {[llength $badcolors] >= $ncolors} {
6369 set badcolors $origbad
6372 for {set i 0} {$i <= $ncolors} {incr i} {
6373 set c [lindex $colors $nextcolor]
6374 if {[incr nextcolor] >= $ncolors} {
6377 if {[lsearch -exact $badcolors $c]} break
6379 set colormap($id) $c
6382 proc bindline {t id} {
6385 $canv bind $t <Enter> "lineenter %x %y $id"
6386 $canv bind $t <Motion> "linemotion %x %y $id"
6387 $canv bind $t <Leave> "lineleave $id"
6388 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6391 proc drawtags {id x xt y1} {
6392 global idtags idheads idotherrefs mainhead
6393 global linespc lthickness
6394 global canv rowtextx curview fgcolor bgcolor ctxbut
6395 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6396 global tagbgcolor tagfgcolor tagoutlinecolor
6402 if {[info exists idtags($id)]} {
6403 set marks $idtags($id)
6404 set ntags [llength $marks]
6406 if {[info exists idheads($id)]} {
6407 set marks [concat $marks $idheads($id)]
6408 set nheads [llength $idheads($id)]
6410 if {[info exists idotherrefs($id)]} {
6411 set marks [concat $marks $idotherrefs($id)]
6417 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6418 set yt [expr {$y1 - 0.5 * $linespc}]
6419 set yb [expr {$yt + $linespc - 1}]
6423 foreach tag $marks {
6425 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6426 set wid [font measure mainfontbold $tag]
6428 set wid [font measure mainfont $tag]
6432 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6434 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6435 -width $lthickness -fill $reflinecolor -tags tag.$id]
6437 foreach tag $marks x $xvals wid $wvals {
6438 set tag_quoted [string map {% %%} $tag]
6439 set xl [expr {$x + $delta}]
6440 set xr [expr {$x + $delta + $wid + $lthickness}]
6442 if {[incr ntags -1] >= 0} {
6444 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6445 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6446 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6448 $canv bind $t <1> [list showtag $tag_quoted 1]
6449 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6451 # draw a head or other ref
6452 if {[incr nheads -1] >= 0} {
6453 set col $headbgcolor
6454 if {$tag eq $mainhead} {
6455 set font mainfontbold
6460 set xl [expr {$xl - $delta/2}]
6461 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6462 -width 1 -outline black -fill $col -tags tag.$id
6463 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6464 set rwid [font measure mainfont $remoteprefix]
6465 set xi [expr {$x + 1}]
6466 set yti [expr {$yt + 1}]
6467 set xri [expr {$x + $rwid}]
6468 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6469 -width 0 -fill $remotebgcolor -tags tag.$id
6472 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6473 -font $font -tags [list tag.$id text]]
6475 $canv bind $t <1> [list showtag $tag_quoted 1]
6476 } elseif {$nheads >= 0} {
6477 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6483 proc drawnotesign {xt y} {
6484 global linespc canv fgcolor
6486 set orad [expr {$linespc / 3}]
6487 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6488 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6489 -fill yellow -outline $fgcolor -width 1 -tags circle]
6490 set xt [expr {$xt + $orad * 3}]
6494 proc xcoord {i level ln} {
6495 global canvx0 xspc1 xspc2
6497 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6498 if {$i > 0 && $i == $level} {
6499 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6500 } elseif {$i > $level} {
6501 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6506 proc show_status {msg} {
6510 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6511 -tags text -fill $fgcolor
6514 # Don't change the text pane cursor if it is currently the hand cursor,
6515 # showing that we are over a sha1 ID link.
6516 proc settextcursor {c} {
6517 global ctext curtextcursor
6519 if {[$ctext cget -cursor] == $curtextcursor} {
6520 $ctext config -cursor $c
6522 set curtextcursor $c
6525 proc nowbusy {what {name {}}} {
6526 global isbusy busyname statusw
6528 if {[array names isbusy] eq {}} {
6529 . config -cursor watch
6533 set busyname($what) $name
6535 $statusw conf -text $name
6539 proc notbusy {what} {
6540 global isbusy maincursor textcursor busyname statusw
6544 if {$busyname($what) ne {} &&
6545 [$statusw cget -text] eq $busyname($what)} {
6546 $statusw conf -text {}
6549 if {[array names isbusy] eq {}} {
6550 . config -cursor $maincursor
6551 settextcursor $textcursor
6555 proc findmatches {f} {
6556 global findtype findstring
6557 if {$findtype == [mc "Regexp"]} {
6558 set matches [regexp -indices -all -inline $findstring $f]
6561 if {$findtype == [mc "IgnCase"]} {
6562 set f [string tolower $f]
6563 set fs [string tolower $fs]
6567 set l [string length $fs]
6568 while {[set j [string first $fs $f $i]] >= 0} {
6569 lappend matches [list $j [expr {$j+$l-1}]]
6570 set i [expr {$j + $l}]
6576 proc dofind {{dirn 1} {wrap 1}} {
6577 global findstring findstartline findcurline selectedline numcommits
6578 global gdttype filehighlight fh_serial find_dirn findallowwrap
6580 if {[info exists find_dirn]} {
6581 if {$find_dirn == $dirn} return
6585 if {$findstring eq {} || $numcommits == 0} return
6586 if {$selectedline eq {}} {
6587 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6589 set findstartline $selectedline
6591 set findcurline $findstartline
6592 nowbusy finding [mc "Searching"]
6593 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6594 after cancel do_file_hl $fh_serial
6595 do_file_hl $fh_serial
6598 set findallowwrap $wrap
6602 proc stopfinding {} {
6603 global find_dirn findcurline fprogcoord
6605 if {[info exists find_dirn]} {
6616 global commitdata commitinfo numcommits findpattern findloc
6617 global findstartline findcurline findallowwrap
6618 global find_dirn gdttype fhighlights fprogcoord
6619 global curview varcorder vrownum varccommits vrowmod
6621 if {![info exists find_dirn]} {
6624 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6627 if {$find_dirn > 0} {
6629 if {$l >= $numcommits} {
6632 if {$l <= $findstartline} {
6633 set lim [expr {$findstartline + 1}]
6636 set moretodo $findallowwrap
6643 if {$l >= $findstartline} {
6644 set lim [expr {$findstartline - 1}]
6647 set moretodo $findallowwrap
6650 set n [expr {($lim - $l) * $find_dirn}]
6655 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6656 update_arcrows $curview
6660 set ai [bsearch $vrownum($curview) $l]
6661 set a [lindex $varcorder($curview) $ai]
6662 set arow [lindex $vrownum($curview) $ai]
6663 set ids [lindex $varccommits($curview,$a)]
6664 set arowend [expr {$arow + [llength $ids]}]
6665 if {$gdttype eq [mc "containing:"]} {
6666 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6667 if {$l < $arow || $l >= $arowend} {
6669 set a [lindex $varcorder($curview) $ai]
6670 set arow [lindex $vrownum($curview) $ai]
6671 set ids [lindex $varccommits($curview,$a)]
6672 set arowend [expr {$arow + [llength $ids]}]
6674 set id [lindex $ids [expr {$l - $arow}]]
6675 # shouldn't happen unless git log doesn't give all the commits...
6676 if {![info exists commitdata($id)] ||
6677 ![doesmatch $commitdata($id)]} {
6680 if {![info exists commitinfo($id)]} {
6683 set info $commitinfo($id)
6684 foreach f $info ty $fldtypes {
6685 if {$ty eq ""} continue
6686 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6695 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6696 if {$l < $arow || $l >= $arowend} {
6698 set a [lindex $varcorder($curview) $ai]
6699 set arow [lindex $vrownum($curview) $ai]
6700 set ids [lindex $varccommits($curview,$a)]
6701 set arowend [expr {$arow + [llength $ids]}]
6703 set id [lindex $ids [expr {$l - $arow}]]
6704 if {![info exists fhighlights($id)]} {
6705 # this sets fhighlights($id) to -1
6706 askfilehighlight $l $id
6708 if {$fhighlights($id) > 0} {
6712 if {$fhighlights($id) < 0} {
6715 set findcurline [expr {$l - $find_dirn}]
6720 if {$found || ($domore && !$moretodo)} {
6736 set findcurline [expr {$l - $find_dirn}]
6738 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6742 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6747 proc findselectline {l} {
6748 global findloc commentend ctext findcurline markingmatches gdttype
6750 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6753 if {$markingmatches &&
6754 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6755 # highlight the matches in the comments
6756 set f [$ctext get 1.0 $commentend]
6757 set matches [findmatches $f]
6758 foreach match $matches {
6759 set start [lindex $match 0]
6760 set end [expr {[lindex $match 1] + 1}]
6761 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6767 # mark the bits of a headline or author that match a find string
6768 proc markmatches {canv l str tag matches font row} {
6771 set bbox [$canv bbox $tag]
6772 set x0 [lindex $bbox 0]
6773 set y0 [lindex $bbox 1]
6774 set y1 [lindex $bbox 3]
6775 foreach match $matches {
6776 set start [lindex $match 0]
6777 set end [lindex $match 1]
6778 if {$start > $end} continue
6779 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6780 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6781 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6782 [expr {$x0+$xlen+2}] $y1 \
6783 -outline {} -tags [list match$l matches] -fill yellow]
6785 if {$row == $selectedline} {
6786 $canv raise $t secsel
6791 proc unmarkmatches {} {
6792 global markingmatches
6794 allcanvs delete matches
6795 set markingmatches 0
6799 proc selcanvline {w x y} {
6800 global canv canvy0 ctext linespc
6802 set ymax [lindex [$canv cget -scrollregion] 3]
6803 if {$ymax == {}} return
6804 set yfrac [lindex [$canv yview] 0]
6805 set y [expr {$y + $yfrac * $ymax}]
6806 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6811 set xmax [lindex [$canv cget -scrollregion] 2]
6812 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6813 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6819 proc commit_descriptor {p} {
6821 if {![info exists commitinfo($p)]} {
6825 if {[llength $commitinfo($p)] > 1} {
6826 set l [lindex $commitinfo($p) 0]
6831 # append some text to the ctext widget, and make any SHA1 ID
6832 # that we know about be a clickable link.
6833 proc appendwithlinks {text tags} {
6834 global ctext linknum curview
6836 set start [$ctext index "end - 1c"]
6837 $ctext insert end $text $tags
6838 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6842 set linkid [string range $text $s $e]
6844 $ctext tag delete link$linknum
6845 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6846 setlink $linkid link$linknum
6851 proc setlink {id lk} {
6852 global curview ctext pendinglinks
6855 if {[string range $id 0 1] eq "-g"} {
6856 set id [string range $id 2 end]
6860 if {[string length $id] < 40} {
6861 set matches [longid $id]
6862 if {[llength $matches] > 0} {
6863 if {[llength $matches] > 1} return
6865 set id [lindex $matches 0]
6868 set known [commitinview $id $curview]
6871 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6872 $ctext tag bind $lk <1> [list selbyid $id]
6873 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6874 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6876 lappend pendinglinks($id) $lk
6877 interestedin $id {makelink %P}
6881 proc appendshortlink {id {pre {}} {post {}}} {
6882 global ctext linknum
6884 $ctext insert end $pre
6885 $ctext tag delete link$linknum
6886 $ctext insert end [string range $id 0 7] link$linknum
6887 $ctext insert end $post
6888 setlink $id link$linknum
6892 proc makelink {id} {
6895 if {![info exists pendinglinks($id)]} return
6896 foreach lk $pendinglinks($id) {
6899 unset pendinglinks($id)
6902 proc linkcursor {w inc} {
6903 global linkentercount curtextcursor
6905 if {[incr linkentercount $inc] > 0} {
6906 $w configure -cursor hand2
6908 $w configure -cursor $curtextcursor
6909 if {$linkentercount < 0} {
6910 set linkentercount 0
6915 proc viewnextline {dir} {
6919 set ymax [lindex [$canv cget -scrollregion] 3]
6920 set wnow [$canv yview]
6921 set wtop [expr {[lindex $wnow 0] * $ymax}]
6922 set newtop [expr {$wtop + $dir * $linespc}]
6925 } elseif {$newtop > $ymax} {
6928 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6931 # add a list of tag or branch names at position pos
6932 # returns the number of names inserted
6933 proc appendrefs {pos ids var} {
6934 global ctext linknum curview $var maxrefs mainheadid
6936 if {[catch {$ctext index $pos}]} {
6939 $ctext conf -state normal
6940 $ctext delete $pos "$pos lineend"
6943 foreach tag [set $var\($id\)] {
6944 lappend tags [list $tag $id]
6949 set tags [lsort -index 0 -decreasing $tags]
6952 if {[llength $tags] > $maxrefs} {
6953 # If we are displaying heads, and there are too many,
6954 # see if there are some important heads to display.
6955 # Currently this means "master" and the current head.
6957 if {$var eq "idheads"} {
6960 set hname [lindex $ti 0]
6961 set id [lindex $ti 1]
6962 if {($hname eq "master" || $id eq $mainheadid) &&
6963 [llength $itags] < $maxrefs} {
6972 set str [mc "and many more"]
6977 $ctext insert $pos "$str ([llength $tags])"
6978 set nutags [llength $tags]
6983 set id [lindex $ti 1]
6986 $ctext tag delete $lk
6987 $ctext insert $pos $sep
6988 $ctext insert $pos [lindex $ti 0] $lk
6992 $ctext tag add wwrap "$pos linestart" "$pos lineend"
6993 $ctext conf -state disabled
6994 return [expr {[llength $tags] + $nutags}]
6997 # called when we have finished computing the nearby tags
6998 proc dispneartags {delay} {
6999 global selectedline currentid showneartags tagphase
7001 if {$selectedline eq {} || !$showneartags} return
7002 after cancel dispnexttag
7004 after 200 dispnexttag
7007 after idle dispnexttag
7012 proc dispnexttag {} {
7013 global selectedline currentid showneartags tagphase ctext
7015 if {$selectedline eq {} || !$showneartags} return
7016 switch -- $tagphase {
7018 set dtags [desctags $currentid]
7020 appendrefs precedes $dtags idtags
7024 set atags [anctags $currentid]
7026 appendrefs follows $atags idtags
7030 set dheads [descheads $currentid]
7031 if {$dheads ne {}} {
7032 if {[appendrefs branch $dheads idheads] > 1
7033 && [$ctext get "branch -3c"] eq "h"} {
7034 # turn "Branch" into "Branches"
7035 $ctext conf -state normal
7036 $ctext insert "branch -2c" "es"
7037 $ctext conf -state disabled
7042 if {[incr tagphase] <= 2} {
7043 after idle dispnexttag
7047 proc make_secsel {id} {
7048 global linehtag linentag linedtag canv canv2 canv3
7050 if {![info exists linehtag($id)]} return
7052 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7053 -tags secsel -fill [$canv cget -selectbackground]]
7055 $canv2 delete secsel
7056 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7057 -tags secsel -fill [$canv2 cget -selectbackground]]
7059 $canv3 delete secsel
7060 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7061 -tags secsel -fill [$canv3 cget -selectbackground]]
7065 proc make_idmark {id} {
7066 global linehtag canv fgcolor
7068 if {![info exists linehtag($id)]} return
7070 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7071 -tags markid -outline $fgcolor]
7075 proc selectline {l isnew {desired_loc {}}} {
7076 global canv ctext commitinfo selectedline
7077 global canvy0 linespc parents children curview
7078 global currentid sha1entry
7079 global commentend idtags linknum
7080 global mergemax numcommits pending_select
7081 global cmitmode showneartags allcommits
7082 global targetrow targetid lastscrollrows
7083 global autoselect autosellen jump_to_here
7085 catch {unset pending_select}
7090 if {$l < 0 || $l >= $numcommits} return
7091 set id [commitonrow $l]
7096 if {$lastscrollrows < $numcommits} {
7100 set y [expr {$canvy0 + $l * $linespc}]
7101 set ymax [lindex [$canv cget -scrollregion] 3]
7102 set ytop [expr {$y - $linespc - 1}]
7103 set ybot [expr {$y + $linespc + 1}]
7104 set wnow [$canv yview]
7105 set wtop [expr {[lindex $wnow 0] * $ymax}]
7106 set wbot [expr {[lindex $wnow 1] * $ymax}]
7107 set wh [expr {$wbot - $wtop}]
7109 if {$ytop < $wtop} {
7110 if {$ybot < $wtop} {
7111 set newtop [expr {$y - $wh / 2.0}]
7114 if {$newtop > $wtop - $linespc} {
7115 set newtop [expr {$wtop - $linespc}]
7118 } elseif {$ybot > $wbot} {
7119 if {$ytop > $wbot} {
7120 set newtop [expr {$y - $wh / 2.0}]
7122 set newtop [expr {$ybot - $wh}]
7123 if {$newtop < $wtop + $linespc} {
7124 set newtop [expr {$wtop + $linespc}]
7128 if {$newtop != $wtop} {
7132 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7139 addtohistory [list selbyid $id 0] savecmitpos
7142 $sha1entry delete 0 end
7143 $sha1entry insert 0 $id
7145 $sha1entry selection range 0 $autosellen
7149 $ctext conf -state normal
7152 if {![info exists commitinfo($id)]} {
7155 set info $commitinfo($id)
7156 set date [formatdate [lindex $info 2]]
7157 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7158 set date [formatdate [lindex $info 4]]
7159 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7160 if {[info exists idtags($id)]} {
7161 $ctext insert end [mc "Tags:"]
7162 foreach tag $idtags($id) {
7163 $ctext insert end " $tag"
7165 $ctext insert end "\n"
7169 set olds $parents($curview,$id)
7170 if {[llength $olds] > 1} {
7173 if {$np >= $mergemax} {
7178 $ctext insert end "[mc "Parent"]: " $tag
7179 appendwithlinks [commit_descriptor $p] {}
7184 append headers "[mc "Parent"]: [commit_descriptor $p]"
7188 foreach c $children($curview,$id) {
7189 append headers "[mc "Child"]: [commit_descriptor $c]"
7192 # make anything that looks like a SHA1 ID be a clickable link
7193 appendwithlinks $headers {}
7194 if {$showneartags} {
7195 if {![info exists allcommits]} {
7198 $ctext insert end "[mc "Branch"]: "
7199 $ctext mark set branch "end -1c"
7200 $ctext mark gravity branch left
7201 $ctext insert end "\n[mc "Follows"]: "
7202 $ctext mark set follows "end -1c"
7203 $ctext mark gravity follows left
7204 $ctext insert end "\n[mc "Precedes"]: "
7205 $ctext mark set precedes "end -1c"
7206 $ctext mark gravity precedes left
7207 $ctext insert end "\n"
7210 $ctext insert end "\n"
7211 set comment [lindex $info 5]
7212 if {[string first "\r" $comment] >= 0} {
7213 set comment [string map {"\r" "\n "} $comment]
7215 appendwithlinks $comment {comment}
7217 $ctext tag remove found 1.0 end
7218 $ctext conf -state disabled
7219 set commentend [$ctext index "end - 1c"]
7221 set jump_to_here $desired_loc
7222 init_flist [mc "Comments"]
7223 if {$cmitmode eq "tree"} {
7225 } elseif {[llength $olds] <= 1} {
7232 proc selfirstline {} {
7237 proc sellastline {} {
7240 set l [expr {$numcommits - 1}]
7244 proc selnextline {dir} {
7247 if {$selectedline eq {}} return
7248 set l [expr {$selectedline + $dir}]
7253 proc selnextpage {dir} {
7254 global canv linespc selectedline numcommits
7256 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7260 allcanvs yview scroll [expr {$dir * $lpp}] units
7262 if {$selectedline eq {}} return
7263 set l [expr {$selectedline + $dir * $lpp}]
7266 } elseif {$l >= $numcommits} {
7267 set l [expr $numcommits - 1]
7273 proc unselectline {} {
7274 global selectedline currentid
7277 catch {unset currentid}
7278 allcanvs delete secsel
7282 proc reselectline {} {
7285 if {$selectedline ne {}} {
7286 selectline $selectedline 0
7290 proc addtohistory {cmd {saveproc {}}} {
7291 global history historyindex curview
7295 set elt [list $curview $cmd $saveproc {}]
7296 if {$historyindex > 0
7297 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7301 if {$historyindex < [llength $history]} {
7302 set history [lreplace $history $historyindex end $elt]
7304 lappend history $elt
7307 if {$historyindex > 1} {
7308 .tf.bar.leftbut conf -state normal
7310 .tf.bar.leftbut conf -state disabled
7312 .tf.bar.rightbut conf -state disabled
7315 # save the scrolling position of the diff display pane
7316 proc save_position {} {
7317 global historyindex history
7319 if {$historyindex < 1} return
7320 set hi [expr {$historyindex - 1}]
7321 set fn [lindex $history $hi 2]
7323 lset history $hi 3 [eval $fn]
7327 proc unset_posvars {} {
7330 if {[info exists last_posvars]} {
7331 foreach {var val} $last_posvars {
7340 global curview last_posvars
7342 set view [lindex $elt 0]
7343 set cmd [lindex $elt 1]
7344 set pv [lindex $elt 3]
7345 if {$curview != $view} {
7349 foreach {var val} $pv {
7353 set last_posvars $pv
7358 global history historyindex
7361 if {$historyindex > 1} {
7363 incr historyindex -1
7364 godo [lindex $history [expr {$historyindex - 1}]]
7365 .tf.bar.rightbut conf -state normal
7367 if {$historyindex <= 1} {
7368 .tf.bar.leftbut conf -state disabled
7373 global history historyindex
7376 if {$historyindex < [llength $history]} {
7378 set cmd [lindex $history $historyindex]
7381 .tf.bar.leftbut conf -state normal
7383 if {$historyindex >= [llength $history]} {
7384 .tf.bar.rightbut conf -state disabled
7389 global treefilelist treeidlist diffids diffmergeid treepending
7390 global nullid nullid2
7393 catch {unset diffmergeid}
7394 if {![info exists treefilelist($id)]} {
7395 if {![info exists treepending]} {
7396 if {$id eq $nullid} {
7397 set cmd [list | git ls-files]
7398 } elseif {$id eq $nullid2} {
7399 set cmd [list | git ls-files --stage -t]
7401 set cmd [list | git ls-tree -r $id]
7403 if {[catch {set gtf [open $cmd r]}]} {
7407 set treefilelist($id) {}
7408 set treeidlist($id) {}
7409 fconfigure $gtf -blocking 0 -encoding binary
7410 filerun $gtf [list gettreeline $gtf $id]
7417 proc gettreeline {gtf id} {
7418 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7421 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7422 if {$diffids eq $nullid} {
7425 set i [string first "\t" $line]
7426 if {$i < 0} continue
7427 set fname [string range $line [expr {$i+1}] end]
7428 set line [string range $line 0 [expr {$i-1}]]
7429 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7430 set sha1 [lindex $line 2]
7431 lappend treeidlist($id) $sha1
7433 if {[string index $fname 0] eq "\""} {
7434 set fname [lindex $fname 0]
7436 set fname [encoding convertfrom $fname]
7437 lappend treefilelist($id) $fname
7440 return [expr {$nl >= 1000? 2: 1}]
7444 if {$cmitmode ne "tree"} {
7445 if {![info exists diffmergeid]} {
7446 gettreediffs $diffids
7448 } elseif {$id ne $diffids} {
7457 global treefilelist treeidlist diffids nullid nullid2
7458 global ctext_file_names ctext_file_lines
7459 global ctext commentend
7461 set i [lsearch -exact $treefilelist($diffids) $f]
7463 puts "oops, $f not in list for id $diffids"
7466 if {$diffids eq $nullid} {
7467 if {[catch {set bf [open $f r]} err]} {
7468 puts "oops, can't read $f: $err"
7472 set blob [lindex $treeidlist($diffids) $i]
7473 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7474 puts "oops, error reading blob $blob: $err"
7478 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7479 filerun $bf [list getblobline $bf $diffids]
7480 $ctext config -state normal
7481 clear_ctext $commentend
7482 lappend ctext_file_names $f
7483 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7484 $ctext insert end "\n"
7485 $ctext insert end "$f\n" filesep
7486 $ctext config -state disabled
7487 $ctext yview $commentend
7491 proc getblobline {bf id} {
7492 global diffids cmitmode ctext
7494 if {$id ne $diffids || $cmitmode ne "tree"} {
7498 $ctext config -state normal
7500 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7501 $ctext insert end "$line\n"
7504 global jump_to_here ctext_file_names commentend
7506 # delete last newline
7507 $ctext delete "end - 2c" "end - 1c"
7509 if {$jump_to_here ne {} &&
7510 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7511 set lnum [expr {[lindex $jump_to_here 1] +
7512 [lindex [split $commentend .] 0]}]
7513 mark_ctext_line $lnum
7515 $ctext config -state disabled
7518 $ctext config -state disabled
7519 return [expr {$nl >= 1000? 2: 1}]
7522 proc mark_ctext_line {lnum} {
7523 global ctext markbgcolor
7525 $ctext tag delete omark
7526 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7527 $ctext tag conf omark -background $markbgcolor
7531 proc mergediff {id} {
7533 global diffids treediffs
7534 global parents curview
7538 set treediffs($id) {}
7539 set np [llength $parents($curview,$id)]
7544 proc startdiff {ids} {
7545 global treediffs diffids treepending diffmergeid nullid nullid2
7549 catch {unset diffmergeid}
7550 if {![info exists treediffs($ids)] ||
7551 [lsearch -exact $ids $nullid] >= 0 ||
7552 [lsearch -exact $ids $nullid2] >= 0} {
7553 if {![info exists treepending]} {
7561 # If the filename (name) is under any of the passed filter paths
7562 # then return true to include the file in the listing.
7563 proc path_filter {filter name} {
7564 set worktree [gitworktree]
7566 set fq_p [file normalize $p]
7567 set fq_n [file normalize [file join $worktree $name]]
7568 if {[string match [file normalize $fq_p]* $fq_n]} {
7575 proc addtocflist {ids} {
7578 add_flist $treediffs($ids)
7582 proc diffcmd {ids flags} {
7583 global log_showroot nullid nullid2
7585 set i [lsearch -exact $ids $nullid]
7586 set j [lsearch -exact $ids $nullid2]
7588 if {[llength $ids] > 1 && $j < 0} {
7589 # comparing working directory with some specific revision
7590 set cmd [concat | git diff-index $flags]
7592 lappend cmd -R [lindex $ids 1]
7594 lappend cmd [lindex $ids 0]
7597 # comparing working directory with index
7598 set cmd [concat | git diff-files $flags]
7603 } elseif {$j >= 0} {
7604 set cmd [concat | git diff-index --cached $flags]
7605 if {[llength $ids] > 1} {
7606 # comparing index with specific revision
7608 lappend cmd -R [lindex $ids 1]
7610 lappend cmd [lindex $ids 0]
7613 # comparing index with HEAD
7617 if {$log_showroot} {
7618 lappend flags --root
7620 set cmd [concat | git diff-tree -r $flags $ids]
7625 proc gettreediffs {ids} {
7626 global treediff treepending limitdiffs vfilelimit curview
7628 set cmd [diffcmd $ids {--no-commit-id}]
7629 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7630 set cmd [concat $cmd -- $vfilelimit($curview)]
7632 if {[catch {set gdtf [open $cmd r]}]} return
7634 set treepending $ids
7636 fconfigure $gdtf -blocking 0 -encoding binary
7637 filerun $gdtf [list gettreediffline $gdtf $ids]
7640 proc gettreediffline {gdtf ids} {
7641 global treediff treediffs treepending diffids diffmergeid
7642 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7647 if {$perfile_attrs} {
7648 # cache_gitattr is slow, and even slower on win32 where we
7649 # have to invoke it for only about 30 paths at a time
7651 if {[tk windowingsystem] == "win32"} {
7655 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7656 set i [string first "\t" $line]
7658 set file [string range $line [expr {$i+1}] end]
7659 if {[string index $file 0] eq "\""} {
7660 set file [lindex $file 0]
7662 set file [encoding convertfrom $file]
7663 if {$file ne [lindex $treediff end]} {
7664 lappend treediff $file
7665 lappend sublist $file
7669 if {$perfile_attrs} {
7670 cache_gitattr encoding $sublist
7673 return [expr {$nr >= $max? 2: 1}]
7676 set treediffs($ids) $treediff
7678 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7680 } elseif {$ids != $diffids} {
7681 if {![info exists diffmergeid]} {
7682 gettreediffs $diffids
7690 # empty string or positive integer
7691 proc diffcontextvalidate {v} {
7692 return [regexp {^(|[1-9][0-9]*)$} $v]
7695 proc diffcontextchange {n1 n2 op} {
7696 global diffcontextstring diffcontext
7698 if {[string is integer -strict $diffcontextstring]} {
7699 if {$diffcontextstring >= 0} {
7700 set diffcontext $diffcontextstring
7706 proc changeignorespace {} {
7710 proc changeworddiff {name ix op} {
7714 proc getblobdiffs {ids} {
7715 global blobdifffd diffids env
7716 global diffinhdr treediffs
7720 global limitdiffs vfilelimit curview
7721 global diffencoding targetline diffnparents
7722 global git_version currdiffsubmod
7725 if {[package vcompare $git_version "1.6.1"] >= 0} {
7726 set textconv "--textconv"
7729 if {[package vcompare $git_version "1.6.6"] >= 0} {
7730 set submodule "--submodule"
7732 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7736 if {$worddiff ne [mc "Line diff"]} {
7737 append cmd " --word-diff=porcelain"
7739 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7740 set cmd [concat $cmd -- $vfilelimit($curview)]
7742 if {[catch {set bdf [open $cmd r]} err]} {
7743 error_popup [mc "Error getting diffs: %s" $err]
7749 set diffencoding [get_path_encoding {}]
7750 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7751 set blobdifffd($ids) $bdf
7752 set currdiffsubmod ""
7753 filerun $bdf [list getblobdiffline $bdf $diffids]
7756 proc savecmitpos {} {
7757 global ctext cmitmode
7759 if {$cmitmode eq "tree"} {
7762 return [list target_scrollpos [$ctext index @0,0]]
7765 proc savectextpos {} {
7768 return [list target_scrollpos [$ctext index @0,0]]
7771 proc maybe_scroll_ctext {ateof} {
7772 global ctext target_scrollpos
7774 if {![info exists target_scrollpos]} return
7776 set nlines [expr {[winfo height $ctext]
7777 / [font metrics textfont -linespace]}]
7778 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7780 $ctext yview $target_scrollpos
7781 unset target_scrollpos
7784 proc setinlist {var i val} {
7787 while {[llength [set $var]] < $i} {
7790 if {[llength [set $var]] == $i} {
7797 proc makediffhdr {fname ids} {
7798 global ctext curdiffstart treediffs diffencoding
7799 global ctext_file_names jump_to_here targetline diffline
7801 set fname [encoding convertfrom $fname]
7802 set diffencoding [get_path_encoding $fname]
7803 set i [lsearch -exact $treediffs($ids) $fname]
7805 setinlist difffilestart $i $curdiffstart
7807 lset ctext_file_names end $fname
7808 set l [expr {(78 - [string length $fname]) / 2}]
7809 set pad [string range "----------------------------------------" 1 $l]
7810 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7812 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7813 set targetline [lindex $jump_to_here 1]
7818 proc getblobdiffline {bdf ids} {
7819 global diffids blobdifffd ctext curdiffstart
7820 global diffnexthead diffnextnote difffilestart
7821 global ctext_file_names ctext_file_lines
7822 global diffinhdr treediffs mergemax diffnparents
7823 global diffencoding jump_to_here targetline diffline currdiffsubmod
7827 $ctext conf -state normal
7828 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7829 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7833 if {![string compare -length 5 "diff " $line]} {
7834 if {![regexp {^diff (--cc|--git) } $line m type]} {
7835 set line [encoding convertfrom $line]
7836 $ctext insert end "$line\n" hunksep
7839 # start of a new file
7841 $ctext insert end "\n"
7842 set curdiffstart [$ctext index "end - 1c"]
7843 lappend ctext_file_names ""
7844 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7845 $ctext insert end "\n" filesep
7847 if {$type eq "--cc"} {
7848 # start of a new file in a merge diff
7849 set fname [string range $line 10 end]
7850 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7851 lappend treediffs($ids) $fname
7852 add_flist [list $fname]
7856 set line [string range $line 11 end]
7857 # If the name hasn't changed the length will be odd,
7858 # the middle char will be a space, and the two bits either
7859 # side will be a/name and b/name, or "a/name" and "b/name".
7860 # If the name has changed we'll get "rename from" and
7861 # "rename to" or "copy from" and "copy to" lines following
7862 # this, and we'll use them to get the filenames.
7863 # This complexity is necessary because spaces in the
7864 # filename(s) don't get escaped.
7865 set l [string length $line]
7866 set i [expr {$l / 2}]
7867 if {!(($l & 1) && [string index $line $i] eq " " &&
7868 [string range $line 2 [expr {$i - 1}]] eq \
7869 [string range $line [expr {$i + 3}] end])} {
7872 # unescape if quoted and chop off the a/ from the front
7873 if {[string index $line 0] eq "\""} {
7874 set fname [string range [lindex $line 0] 2 end]
7876 set fname [string range $line 2 [expr {$i - 1}]]
7879 makediffhdr $fname $ids
7881 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7882 set fname [encoding convertfrom [string range $line 16 end]]
7883 $ctext insert end "\n"
7884 set curdiffstart [$ctext index "end - 1c"]
7885 lappend ctext_file_names $fname
7886 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7887 $ctext insert end "$line\n" filesep
7888 set i [lsearch -exact $treediffs($ids) $fname]
7890 setinlist difffilestart $i $curdiffstart
7893 } elseif {![string compare -length 2 "@@" $line]} {
7894 regexp {^@@+} $line ats
7895 set line [encoding convertfrom $diffencoding $line]
7896 $ctext insert end "$line\n" hunksep
7897 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7900 set diffnparents [expr {[string length $ats] - 1}]
7903 } elseif {![string compare -length 10 "Submodule " $line]} {
7904 # start of a new submodule
7905 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7906 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7908 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7910 if {$currdiffsubmod != $fname} {
7911 $ctext insert end "\n"; # Add newline after commit message
7913 set curdiffstart [$ctext index "end - 1c"]
7914 lappend ctext_file_names ""
7915 if {$currdiffsubmod != $fname} {
7916 lappend ctext_file_lines $fname
7917 makediffhdr $fname $ids
7918 set currdiffsubmod $fname
7919 $ctext insert end "\n$line\n" filesep
7921 $ctext insert end "$line\n" filesep
7923 } elseif {![string compare -length 3 " >" $line]} {
7924 set $currdiffsubmod ""
7925 set line [encoding convertfrom $diffencoding $line]
7926 $ctext insert end "$line\n" dresult
7927 } elseif {![string compare -length 3 " <" $line]} {
7928 set $currdiffsubmod ""
7929 set line [encoding convertfrom $diffencoding $line]
7930 $ctext insert end "$line\n" d0
7931 } elseif {$diffinhdr} {
7932 if {![string compare -length 12 "rename from " $line]} {
7933 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7934 if {[string index $fname 0] eq "\""} {
7935 set fname [lindex $fname 0]
7937 set fname [encoding convertfrom $fname]
7938 set i [lsearch -exact $treediffs($ids) $fname]
7940 setinlist difffilestart $i $curdiffstart
7942 } elseif {![string compare -length 10 $line "rename to "] ||
7943 ![string compare -length 8 $line "copy to "]} {
7944 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7945 if {[string index $fname 0] eq "\""} {
7946 set fname [lindex $fname 0]
7948 makediffhdr $fname $ids
7949 } elseif {[string compare -length 3 $line "---"] == 0} {
7952 } elseif {[string compare -length 3 $line "+++"] == 0} {
7956 $ctext insert end "$line\n" filesep
7959 set line [string map {\x1A ^Z} \
7960 [encoding convertfrom $diffencoding $line]]
7961 # parse the prefix - one ' ', '-' or '+' for each parent
7962 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
7963 set tag [expr {$diffnparents > 1? "m": "d"}]
7964 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
7965 set words_pre_markup ""
7966 set words_post_markup ""
7967 if {[string trim $prefix " -+"] eq {}} {
7968 # prefix only has " ", "-" and "+" in it: normal diff line
7969 set num [string first "-" $prefix]
7971 set line [string range $line 1 end]
7974 # removed line, first parent with line is $num
7975 if {$num >= $mergemax} {
7978 if {$dowords && $worddiff eq [mc "Markup words"]} {
7979 $ctext insert end "\[-$line-\]" $tag$num
7981 $ctext insert end "$line" $tag$num
7984 $ctext insert end "\n" $tag$num
7988 if {[string first "+" $prefix] >= 0} {
7990 lappend tags ${tag}result
7991 if {$diffnparents > 1} {
7992 set num [string first " " $prefix]
7994 if {$num >= $mergemax} {
8000 set words_pre_markup "{+"
8001 set words_post_markup "+}"
8003 if {$targetline ne {}} {
8004 if {$diffline == $targetline} {
8005 set seehere [$ctext index "end - 1 chars"]
8011 if {$dowords && $worddiff eq [mc "Markup words"]} {
8012 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8014 $ctext insert end "$line" $tags
8017 $ctext insert end "\n" $tags
8020 } elseif {$dowords && $prefix eq "~"} {
8021 $ctext insert end "\n" {}
8023 # "\ No newline at end of file",
8024 # or something else we don't recognize
8025 $ctext insert end "$line\n" hunksep
8029 if {[info exists seehere]} {
8030 mark_ctext_line [lindex [split $seehere .] 0]
8032 maybe_scroll_ctext [eof $bdf]
8033 $ctext conf -state disabled
8038 return [expr {$nr >= 1000? 2: 1}]
8041 proc changediffdisp {} {
8042 global ctext diffelide
8044 $ctext tag conf d0 -elide [lindex $diffelide 0]
8045 $ctext tag conf dresult -elide [lindex $diffelide 1]
8048 proc highlightfile {cline} {
8049 global cflist cflist_top
8051 if {![info exists cflist_top]} return
8053 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8054 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8055 $cflist see $cline.0
8056 set cflist_top $cline
8059 proc highlightfile_for_scrollpos {topidx} {
8060 global cmitmode difffilestart
8062 if {$cmitmode eq "tree"} return
8063 if {![info exists difffilestart]} return
8065 set top [lindex [split $topidx .] 0]
8066 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8069 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8074 global difffilestart ctext cmitmode
8076 if {$cmitmode eq "tree"} return
8078 set here [$ctext index @0,0]
8079 foreach loc $difffilestart {
8080 if {[$ctext compare $loc >= $here]} {
8090 global difffilestart ctext cmitmode
8092 if {$cmitmode eq "tree"} return
8093 set here [$ctext index @0,0]
8094 foreach loc $difffilestart {
8095 if {[$ctext compare $loc > $here]} {
8102 proc clear_ctext {{first 1.0}} {
8103 global ctext smarktop smarkbot
8104 global ctext_file_names ctext_file_lines
8107 set l [lindex [split $first .] 0]
8108 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8111 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8114 $ctext delete $first end
8115 if {$first eq "1.0"} {
8116 catch {unset pendinglinks}
8118 set ctext_file_names {}
8119 set ctext_file_lines {}
8122 proc settabs {{firstab {}}} {
8123 global firsttabstop tabstop ctext have_tk85
8125 if {$firstab ne {} && $have_tk85} {
8126 set firsttabstop $firstab
8128 set w [font measure textfont "0"]
8129 if {$firsttabstop != 0} {
8130 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8131 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8132 } elseif {$have_tk85 || $tabstop != 8} {
8133 $ctext conf -tabs [expr {$tabstop * $w}]
8135 $ctext conf -tabs {}
8139 proc incrsearch {name ix op} {
8140 global ctext searchstring searchdirn
8142 if {[catch {$ctext index anchor}]} {
8143 # no anchor set, use start of selection, or of visible area
8144 set sel [$ctext tag ranges sel]
8146 $ctext mark set anchor [lindex $sel 0]
8147 } elseif {$searchdirn eq "-forwards"} {
8148 $ctext mark set anchor @0,0
8150 $ctext mark set anchor @0,[winfo height $ctext]
8153 if {$searchstring ne {}} {
8154 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8157 set mend "$here + $mlen c"
8158 $ctext tag remove sel 1.0 end
8159 $ctext tag add sel $here $mend
8160 suppress_highlighting_file_for_current_scrollpos
8161 highlightfile_for_scrollpos $here
8164 rehighlight_search_results
8168 global sstring ctext searchstring searchdirn
8171 $sstring icursor end
8172 set searchdirn -forwards
8173 if {$searchstring ne {}} {
8174 set sel [$ctext tag ranges sel]
8176 set start "[lindex $sel 0] + 1c"
8177 } elseif {[catch {set start [$ctext index anchor]}]} {
8180 set match [$ctext search -count mlen -- $searchstring $start]
8181 $ctext tag remove sel 1.0 end
8187 suppress_highlighting_file_for_current_scrollpos
8188 highlightfile_for_scrollpos $match
8189 set mend "$match + $mlen c"
8190 $ctext tag add sel $match $mend
8191 $ctext mark unset anchor
8192 rehighlight_search_results
8196 proc dosearchback {} {
8197 global sstring ctext searchstring searchdirn
8200 $sstring icursor end
8201 set searchdirn -backwards
8202 if {$searchstring ne {}} {
8203 set sel [$ctext tag ranges sel]
8205 set start [lindex $sel 0]
8206 } elseif {[catch {set start [$ctext index anchor]}]} {
8207 set start @0,[winfo height $ctext]
8209 set match [$ctext search -backwards -count ml -- $searchstring $start]
8210 $ctext tag remove sel 1.0 end
8216 suppress_highlighting_file_for_current_scrollpos
8217 highlightfile_for_scrollpos $match
8218 set mend "$match + $ml c"
8219 $ctext tag add sel $match $mend
8220 $ctext mark unset anchor
8221 rehighlight_search_results
8225 proc rehighlight_search_results {} {
8226 global ctext searchstring
8228 $ctext tag remove found 1.0 end
8229 $ctext tag remove currentsearchhit 1.0 end
8231 if {$searchstring ne {}} {
8236 proc searchmark {first last} {
8237 global ctext searchstring
8239 set sel [$ctext tag ranges sel]
8243 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8244 if {$match eq {}} break
8245 set mend "$match + $mlen c"
8246 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8247 $ctext tag add currentsearchhit $match $mend
8249 $ctext tag add found $match $mend
8254 proc searchmarkvisible {doall} {
8255 global ctext smarktop smarkbot
8257 set topline [lindex [split [$ctext index @0,0] .] 0]
8258 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8259 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8260 # no overlap with previous
8261 searchmark $topline $botline
8262 set smarktop $topline
8263 set smarkbot $botline
8265 if {$topline < $smarktop} {
8266 searchmark $topline [expr {$smarktop-1}]
8267 set smarktop $topline
8269 if {$botline > $smarkbot} {
8270 searchmark [expr {$smarkbot+1}] $botline
8271 set smarkbot $botline
8276 proc suppress_highlighting_file_for_current_scrollpos {} {
8277 global ctext suppress_highlighting_file_for_this_scrollpos
8279 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8282 proc scrolltext {f0 f1} {
8283 global searchstring cmitmode ctext
8284 global suppress_highlighting_file_for_this_scrollpos
8286 set topidx [$ctext index @0,0]
8287 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8288 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8289 highlightfile_for_scrollpos $topidx
8292 catch {unset suppress_highlighting_file_for_this_scrollpos}
8294 .bleft.bottom.sb set $f0 $f1
8295 if {$searchstring ne {}} {
8301 global linespc charspc canvx0 canvy0
8302 global xspc1 xspc2 lthickness
8304 set linespc [font metrics mainfont -linespace]
8305 set charspc [font measure mainfont "m"]
8306 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8307 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8308 set lthickness [expr {int($linespc / 9) + 1}]
8309 set xspc1(0) $linespc
8317 set ymax [lindex [$canv cget -scrollregion] 3]
8318 if {$ymax eq {} || $ymax == 0} return
8319 set span [$canv yview]
8322 allcanvs yview moveto [lindex $span 0]
8324 if {$selectedline ne {}} {
8325 selectline $selectedline 0
8326 allcanvs yview moveto [lindex $span 0]
8330 proc parsefont {f n} {
8333 set fontattr($f,family) [lindex $n 0]
8335 if {$s eq {} || $s == 0} {
8338 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8340 set fontattr($f,size) $s
8341 set fontattr($f,weight) normal
8342 set fontattr($f,slant) roman
8343 foreach style [lrange $n 2 end] {
8346 "bold" {set fontattr($f,weight) $style}
8348 "italic" {set fontattr($f,slant) $style}
8353 proc fontflags {f {isbold 0}} {
8356 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8357 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8358 -slant $fontattr($f,slant)]
8364 set n [list $fontattr($f,family) $fontattr($f,size)]
8365 if {$fontattr($f,weight) eq "bold"} {
8368 if {$fontattr($f,slant) eq "italic"} {
8374 proc incrfont {inc} {
8375 global mainfont textfont ctext canv cflist showrefstop
8376 global stopped entries fontattr
8379 set s $fontattr(mainfont,size)
8384 set fontattr(mainfont,size) $s
8385 font config mainfont -size $s
8386 font config mainfontbold -size $s
8387 set mainfont [fontname mainfont]
8388 set s $fontattr(textfont,size)
8393 set fontattr(textfont,size) $s
8394 font config textfont -size $s
8395 font config textfontbold -size $s
8396 set textfont [fontname textfont]
8403 global sha1entry sha1string
8404 if {[string length $sha1string] == 40} {
8405 $sha1entry delete 0 end
8409 proc sha1change {n1 n2 op} {
8410 global sha1string currentid sha1but
8411 if {$sha1string == {}
8412 || ([info exists currentid] && $sha1string == $currentid)} {
8417 if {[$sha1but cget -state] == $state} return
8418 if {$state == "normal"} {
8419 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8421 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8425 proc gotocommit {} {
8426 global sha1string tagids headids curview varcid
8428 if {$sha1string == {}
8429 || ([info exists currentid] && $sha1string == $currentid)} return
8430 if {[info exists tagids($sha1string)]} {
8431 set id $tagids($sha1string)
8432 } elseif {[info exists headids($sha1string)]} {
8433 set id $headids($sha1string)
8435 set id [string tolower $sha1string]
8436 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8437 set matches [longid $id]
8438 if {$matches ne {}} {
8439 if {[llength $matches] > 1} {
8440 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8443 set id [lindex $matches 0]
8446 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8447 error_popup [mc "Revision %s is not known" $sha1string]
8452 if {[commitinview $id $curview]} {
8453 selectline [rowofcommit $id] 1
8456 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8457 set msg [mc "SHA1 id %s is not known" $sha1string]
8459 set msg [mc "Revision %s is not in the current view" $sha1string]
8464 proc lineenter {x y id} {
8465 global hoverx hovery hoverid hovertimer
8466 global commitinfo canv
8468 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8472 if {[info exists hovertimer]} {
8473 after cancel $hovertimer
8475 set hovertimer [after 500 linehover]
8479 proc linemotion {x y id} {
8480 global hoverx hovery hoverid hovertimer
8482 if {[info exists hoverid] && $id == $hoverid} {
8485 if {[info exists hovertimer]} {
8486 after cancel $hovertimer
8488 set hovertimer [after 500 linehover]
8492 proc lineleave {id} {
8493 global hoverid hovertimer canv
8495 if {[info exists hoverid] && $id == $hoverid} {
8497 if {[info exists hovertimer]} {
8498 after cancel $hovertimer
8506 global hoverx hovery hoverid hovertimer
8507 global canv linespc lthickness
8508 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8512 set text [lindex $commitinfo($hoverid) 0]
8513 set ymax [lindex [$canv cget -scrollregion] 3]
8514 if {$ymax == {}} return
8515 set yfrac [lindex [$canv yview] 0]
8516 set x [expr {$hoverx + 2 * $linespc}]
8517 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8518 set x0 [expr {$x - 2 * $lthickness}]
8519 set y0 [expr {$y - 2 * $lthickness}]
8520 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8521 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8522 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8523 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8524 -width 1 -tags hover]
8526 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8527 -font mainfont -fill $linehoverfgcolor]
8531 proc clickisonarrow {id y} {
8534 set ranges [rowranges $id]
8535 set thresh [expr {2 * $lthickness + 6}]
8536 set n [expr {[llength $ranges] - 1}]
8537 for {set i 1} {$i < $n} {incr i} {
8538 set row [lindex $ranges $i]
8539 if {abs([yc $row] - $y) < $thresh} {
8546 proc arrowjump {id n y} {
8549 # 1 <-> 2, 3 <-> 4, etc...
8550 set n [expr {(($n - 1) ^ 1) + 1}]
8551 set row [lindex [rowranges $id] $n]
8553 set ymax [lindex [$canv cget -scrollregion] 3]
8554 if {$ymax eq {} || $ymax <= 0} return
8555 set view [$canv yview]
8556 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8557 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8561 allcanvs yview moveto $yfrac
8564 proc lineclick {x y id isnew} {
8565 global ctext commitinfo children canv thickerline curview
8567 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8572 # draw this line thicker than normal
8576 set ymax [lindex [$canv cget -scrollregion] 3]
8577 if {$ymax eq {}} return
8578 set yfrac [lindex [$canv yview] 0]
8579 set y [expr {$y + $yfrac * $ymax}]
8581 set dirn [clickisonarrow $id $y]
8583 arrowjump $id $dirn $y
8588 addtohistory [list lineclick $x $y $id 0] savectextpos
8590 # fill the details pane with info about this line
8591 $ctext conf -state normal
8594 $ctext insert end "[mc "Parent"]:\t"
8595 $ctext insert end $id link0
8597 set info $commitinfo($id)
8598 $ctext insert end "\n\t[lindex $info 0]\n"
8599 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8600 set date [formatdate [lindex $info 2]]
8601 $ctext insert end "\t[mc "Date"]:\t$date\n"
8602 set kids $children($curview,$id)
8604 $ctext insert end "\n[mc "Children"]:"
8606 foreach child $kids {
8608 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8609 set info $commitinfo($child)
8610 $ctext insert end "\n\t"
8611 $ctext insert end $child link$i
8612 setlink $child link$i
8613 $ctext insert end "\n\t[lindex $info 0]"
8614 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8615 set date [formatdate [lindex $info 2]]
8616 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8619 maybe_scroll_ctext 1
8620 $ctext conf -state disabled
8624 proc normalline {} {
8626 if {[info exists thickerline]} {
8633 proc selbyid {id {isnew 1}} {
8635 if {[commitinview $id $curview]} {
8636 selectline [rowofcommit $id] $isnew
8642 if {![info exists startmstime]} {
8643 set startmstime [clock clicks -milliseconds]
8645 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8648 proc rowmenu {x y id} {
8649 global rowctxmenu selectedline rowmenuid curview
8650 global nullid nullid2 fakerowmenu mainhead markedid
8654 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8659 if {[info exists markedid] && $markedid ne $id} {
8664 if {$id ne $nullid && $id ne $nullid2} {
8665 set menu $rowctxmenu
8666 if {$mainhead ne {}} {
8667 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8669 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8671 $menu entryconfigure 9 -state $mstate
8672 $menu entryconfigure 10 -state $mstate
8673 $menu entryconfigure 11 -state $mstate
8675 set menu $fakerowmenu
8677 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8678 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8679 $menu entryconfigure [mca "Make patch"] -state $state
8680 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8681 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8682 tk_popup $menu $x $y
8686 global rowmenuid markedid canv
8688 set markedid $rowmenuid
8689 make_idmark $markedid
8695 if {[info exists markedid]} {
8700 proc replace_by_kids {l r} {
8701 global curview children
8703 set id [commitonrow $r]
8704 set l [lreplace $l 0 0]
8705 foreach kid $children($curview,$id) {
8706 lappend l [rowofcommit $kid]
8708 return [lsort -integer -decreasing -unique $l]
8711 proc find_common_desc {} {
8712 global markedid rowmenuid curview children
8714 if {![info exists markedid]} return
8715 if {![commitinview $markedid $curview] ||
8716 ![commitinview $rowmenuid $curview]} return
8717 #set t1 [clock clicks -milliseconds]
8718 set l1 [list [rowofcommit $markedid]]
8719 set l2 [list [rowofcommit $rowmenuid]]
8721 set r1 [lindex $l1 0]
8722 set r2 [lindex $l2 0]
8723 if {$r1 eq {} || $r2 eq {}} break
8729 set l1 [replace_by_kids $l1 $r1]
8731 set l2 [replace_by_kids $l2 $r2]
8734 #set t2 [clock clicks -milliseconds]
8735 #puts "took [expr {$t2-$t1}]ms"
8738 proc compare_commits {} {
8739 global markedid rowmenuid curview children
8741 if {![info exists markedid]} return
8742 if {![commitinview $markedid $curview]} return
8743 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8744 do_cmp_commits $markedid $rowmenuid
8747 proc getpatchid {id} {
8750 if {![info exists patchids($id)]} {
8751 set cmd [diffcmd [list $id] {-p --root}]
8752 # trim off the initial "|"
8753 set cmd [lrange $cmd 1 end]
8755 set x [eval exec $cmd | git patch-id]
8756 set patchids($id) [lindex $x 0]
8758 set patchids($id) "error"
8761 return $patchids($id)
8764 proc do_cmp_commits {a b} {
8765 global ctext curview parents children patchids commitinfo
8767 $ctext conf -state normal
8770 for {set i 0} {$i < 100} {incr i} {
8773 if {[llength $parents($curview,$a)] > 1} {
8774 appendshortlink $a [mc "Skipping merge commit "] "\n"
8777 set patcha [getpatchid $a]
8779 if {[llength $parents($curview,$b)] > 1} {
8780 appendshortlink $b [mc "Skipping merge commit "] "\n"
8783 set patchb [getpatchid $b]
8785 if {!$skipa && !$skipb} {
8786 set heada [lindex $commitinfo($a) 0]
8787 set headb [lindex $commitinfo($b) 0]
8788 if {$patcha eq "error"} {
8789 appendshortlink $a [mc "Error getting patch ID for "] \
8790 [mc " - stopping\n"]
8793 if {$patchb eq "error"} {
8794 appendshortlink $b [mc "Error getting patch ID for "] \
8795 [mc " - stopping\n"]
8798 if {$patcha eq $patchb} {
8799 if {$heada eq $headb} {
8800 appendshortlink $a [mc "Commit "]
8801 appendshortlink $b " == " " $heada\n"
8803 appendshortlink $a [mc "Commit "] " $heada\n"
8804 appendshortlink $b [mc " is the same patch as\n "] \
8810 $ctext insert end "\n"
8811 appendshortlink $a [mc "Commit "] " $heada\n"
8812 appendshortlink $b [mc " differs from\n "] \
8814 $ctext insert end [mc "Diff of commits:\n\n"]
8815 $ctext conf -state disabled
8822 set kids [real_children $curview,$a]
8823 if {[llength $kids] != 1} {
8824 $ctext insert end "\n"
8825 appendshortlink $a [mc "Commit "] \
8826 [mc " has %s children - stopping\n" [llength $kids]]
8829 set a [lindex $kids 0]
8832 set kids [real_children $curview,$b]
8833 if {[llength $kids] != 1} {
8834 appendshortlink $b [mc "Commit "] \
8835 [mc " has %s children - stopping\n" [llength $kids]]
8838 set b [lindex $kids 0]
8841 $ctext conf -state disabled
8844 proc diffcommits {a b} {
8845 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8847 set tmpdir [gitknewtmpdir]
8848 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8849 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8851 exec git diff-tree -p --pretty $a >$fna
8852 exec git diff-tree -p --pretty $b >$fnb
8854 error_popup [mc "Error writing commit to file: %s" $err]
8858 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8860 error_popup [mc "Error diffing commits: %s" $err]
8863 set diffids [list commits $a $b]
8864 set blobdifffd($diffids) $fd
8866 set currdiffsubmod ""
8867 filerun $fd [list getblobdiffline $fd $diffids]
8870 proc diffvssel {dirn} {
8871 global rowmenuid selectedline
8873 if {$selectedline eq {}} return
8875 set oldid [commitonrow $selectedline]
8876 set newid $rowmenuid
8878 set oldid $rowmenuid
8879 set newid [commitonrow $selectedline]
8881 addtohistory [list doseldiff $oldid $newid] savectextpos
8882 doseldiff $oldid $newid
8885 proc diffvsmark {dirn} {
8886 global rowmenuid markedid
8888 if {![info exists markedid]} return
8891 set newid $rowmenuid
8893 set oldid $rowmenuid
8896 addtohistory [list doseldiff $oldid $newid] savectextpos
8897 doseldiff $oldid $newid
8900 proc doseldiff {oldid newid} {
8904 $ctext conf -state normal
8906 init_flist [mc "Top"]
8907 $ctext insert end "[mc "From"] "
8908 $ctext insert end $oldid link0
8909 setlink $oldid link0
8910 $ctext insert end "\n "
8911 $ctext insert end [lindex $commitinfo($oldid) 0]
8912 $ctext insert end "\n\n[mc "To"] "
8913 $ctext insert end $newid link1
8914 setlink $newid link1
8915 $ctext insert end "\n "
8916 $ctext insert end [lindex $commitinfo($newid) 0]
8917 $ctext insert end "\n"
8918 $ctext conf -state disabled
8919 $ctext tag remove found 1.0 end
8920 startdiff [list $oldid $newid]
8924 global rowmenuid currentid commitinfo patchtop patchnum NS
8926 if {![info exists currentid]} return
8927 set oldid $currentid
8928 set oldhead [lindex $commitinfo($oldid) 0]
8929 set newid $rowmenuid
8930 set newhead [lindex $commitinfo($newid) 0]
8933 catch {destroy $top}
8935 make_transient $top .
8936 ${NS}::label $top.title -text [mc "Generate patch"]
8937 grid $top.title - -pady 10
8938 ${NS}::label $top.from -text [mc "From:"]
8939 ${NS}::entry $top.fromsha1 -width 40
8940 $top.fromsha1 insert 0 $oldid
8941 $top.fromsha1 conf -state readonly
8942 grid $top.from $top.fromsha1 -sticky w
8943 ${NS}::entry $top.fromhead -width 60
8944 $top.fromhead insert 0 $oldhead
8945 $top.fromhead conf -state readonly
8946 grid x $top.fromhead -sticky w
8947 ${NS}::label $top.to -text [mc "To:"]
8948 ${NS}::entry $top.tosha1 -width 40
8949 $top.tosha1 insert 0 $newid
8950 $top.tosha1 conf -state readonly
8951 grid $top.to $top.tosha1 -sticky w
8952 ${NS}::entry $top.tohead -width 60
8953 $top.tohead insert 0 $newhead
8954 $top.tohead conf -state readonly
8955 grid x $top.tohead -sticky w
8956 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
8957 grid $top.rev x -pady 10 -padx 5
8958 ${NS}::label $top.flab -text [mc "Output file:"]
8959 ${NS}::entry $top.fname -width 60
8960 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
8962 grid $top.flab $top.fname -sticky w
8963 ${NS}::frame $top.buts
8964 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
8965 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
8966 bind $top <Key-Return> mkpatchgo
8967 bind $top <Key-Escape> mkpatchcan
8968 grid $top.buts.gen $top.buts.can
8969 grid columnconfigure $top.buts 0 -weight 1 -uniform a
8970 grid columnconfigure $top.buts 1 -weight 1 -uniform a
8971 grid $top.buts - -pady 10 -sticky ew
8975 proc mkpatchrev {} {
8978 set oldid [$patchtop.fromsha1 get]
8979 set oldhead [$patchtop.fromhead get]
8980 set newid [$patchtop.tosha1 get]
8981 set newhead [$patchtop.tohead get]
8982 foreach e [list fromsha1 fromhead tosha1 tohead] \
8983 v [list $newid $newhead $oldid $oldhead] {
8984 $patchtop.$e conf -state normal
8985 $patchtop.$e delete 0 end
8986 $patchtop.$e insert 0 $v
8987 $patchtop.$e conf -state readonly
8992 global patchtop nullid nullid2
8994 set oldid [$patchtop.fromsha1 get]
8995 set newid [$patchtop.tosha1 get]
8996 set fname [$patchtop.fname get]
8997 set cmd [diffcmd [list $oldid $newid] -p]
8998 # trim off the initial "|"
8999 set cmd [lrange $cmd 1 end]
9000 lappend cmd >$fname &
9001 if {[catch {eval exec $cmd} err]} {
9002 error_popup "[mc "Error creating patch:"] $err" $patchtop
9004 catch {destroy $patchtop}
9008 proc mkpatchcan {} {
9011 catch {destroy $patchtop}
9016 global rowmenuid mktagtop commitinfo NS
9020 catch {destroy $top}
9022 make_transient $top .
9023 ${NS}::label $top.title -text [mc "Create tag"]
9024 grid $top.title - -pady 10
9025 ${NS}::label $top.id -text [mc "ID:"]
9026 ${NS}::entry $top.sha1 -width 40
9027 $top.sha1 insert 0 $rowmenuid
9028 $top.sha1 conf -state readonly
9029 grid $top.id $top.sha1 -sticky w
9030 ${NS}::entry $top.head -width 60
9031 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9032 $top.head conf -state readonly
9033 grid x $top.head -sticky w
9034 ${NS}::label $top.tlab -text [mc "Tag name:"]
9035 ${NS}::entry $top.tag -width 60
9036 grid $top.tlab $top.tag -sticky w
9037 ${NS}::label $top.op -text [mc "Tag message is optional"]
9038 grid $top.op -columnspan 2 -sticky we
9039 ${NS}::label $top.mlab -text [mc "Tag message:"]
9040 ${NS}::entry $top.msg -width 60
9041 grid $top.mlab $top.msg -sticky w
9042 ${NS}::frame $top.buts
9043 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9044 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9045 bind $top <Key-Return> mktaggo
9046 bind $top <Key-Escape> mktagcan
9047 grid $top.buts.gen $top.buts.can
9048 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9049 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9050 grid $top.buts - -pady 10 -sticky ew
9055 global mktagtop env tagids idtags
9057 set id [$mktagtop.sha1 get]
9058 set tag [$mktagtop.tag get]
9059 set msg [$mktagtop.msg get]
9061 error_popup [mc "No tag name specified"] $mktagtop
9064 if {[info exists tagids($tag)]} {
9065 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9070 exec git tag -a -m $msg $tag $id
9072 exec git tag $tag $id
9075 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9079 set tagids($tag) $id
9080 lappend idtags($id) $tag
9088 proc redrawtags {id} {
9089 global canv linehtag idpos currentid curview cmitlisted markedid
9090 global canvxmax iddrawn circleitem mainheadid circlecolors
9091 global mainheadcirclecolor
9093 if {![commitinview $id $curview]} return
9094 if {![info exists iddrawn($id)]} return
9095 set row [rowofcommit $id]
9096 if {$id eq $mainheadid} {
9097 set ofill $mainheadcirclecolor
9099 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9101 $canv itemconf $circleitem($row) -fill $ofill
9102 $canv delete tag.$id
9103 set xt [eval drawtags $id $idpos($id)]
9104 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9105 set text [$canv itemcget $linehtag($id) -text]
9106 set font [$canv itemcget $linehtag($id) -font]
9107 set xr [expr {$xt + [font measure $font $text]}]
9108 if {$xr > $canvxmax} {
9112 if {[info exists currentid] && $currentid == $id} {
9115 if {[info exists markedid] && $markedid eq $id} {
9123 catch {destroy $mktagtop}
9128 if {![domktag]} return
9132 proc writecommit {} {
9133 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9135 set top .writecommit
9137 catch {destroy $top}
9139 make_transient $top .
9140 ${NS}::label $top.title -text [mc "Write commit to file"]
9141 grid $top.title - -pady 10
9142 ${NS}::label $top.id -text [mc "ID:"]
9143 ${NS}::entry $top.sha1 -width 40
9144 $top.sha1 insert 0 $rowmenuid
9145 $top.sha1 conf -state readonly
9146 grid $top.id $top.sha1 -sticky w
9147 ${NS}::entry $top.head -width 60
9148 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9149 $top.head conf -state readonly
9150 grid x $top.head -sticky w
9151 ${NS}::label $top.clab -text [mc "Command:"]
9152 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9153 grid $top.clab $top.cmd -sticky w -pady 10
9154 ${NS}::label $top.flab -text [mc "Output file:"]
9155 ${NS}::entry $top.fname -width 60
9156 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9157 grid $top.flab $top.fname -sticky w
9158 ${NS}::frame $top.buts
9159 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9160 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9161 bind $top <Key-Return> wrcomgo
9162 bind $top <Key-Escape> wrcomcan
9163 grid $top.buts.gen $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
9173 set id [$wrcomtop.sha1 get]
9174 set cmd "echo $id | [$wrcomtop.cmd get]"
9175 set fname [$wrcomtop.fname get]
9176 if {[catch {exec sh -c $cmd >$fname &} err]} {
9177 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9179 catch {destroy $wrcomtop}
9186 catch {destroy $wrcomtop}
9191 global rowmenuid mkbrtop NS
9194 catch {destroy $top}
9196 make_transient $top .
9197 ${NS}::label $top.title -text [mc "Create new branch"]
9198 grid $top.title - -pady 10
9199 ${NS}::label $top.id -text [mc "ID:"]
9200 ${NS}::entry $top.sha1 -width 40
9201 $top.sha1 insert 0 $rowmenuid
9202 $top.sha1 conf -state readonly
9203 grid $top.id $top.sha1 -sticky w
9204 ${NS}::label $top.nlab -text [mc "Name:"]
9205 ${NS}::entry $top.name -width 40
9206 grid $top.nlab $top.name -sticky w
9207 ${NS}::frame $top.buts
9208 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9209 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9210 bind $top <Key-Return> [list mkbrgo $top]
9211 bind $top <Key-Escape> "catch {destroy $top}"
9212 grid $top.buts.go $top.buts.can
9213 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9214 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9215 grid $top.buts - -pady 10 -sticky ew
9220 global headids idheads
9222 set name [$top.name get]
9223 set id [$top.sha1 get]
9227 error_popup [mc "Please specify a name for the new branch"] $top
9230 if {[info exists headids($name)]} {
9231 if {![confirm_popup [mc \
9232 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9235 set old_id $headids($name)
9238 catch {destroy $top}
9239 lappend cmdargs $name $id
9243 eval exec git branch $cmdargs
9249 if {$old_id ne {}} {
9255 set headids($name) $id
9256 lappend idheads($id) $name
9265 proc exec_citool {tool_args {baseid {}}} {
9266 global commitinfo env
9268 set save_env [array get env GIT_AUTHOR_*]
9270 if {$baseid ne {}} {
9271 if {![info exists commitinfo($baseid)]} {
9274 set author [lindex $commitinfo($baseid) 1]
9275 set date [lindex $commitinfo($baseid) 2]
9276 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9277 $author author name email]
9279 set env(GIT_AUTHOR_NAME) $name
9280 set env(GIT_AUTHOR_EMAIL) $email
9281 set env(GIT_AUTHOR_DATE) $date
9285 eval exec git citool $tool_args &
9287 array unset env GIT_AUTHOR_*
9288 array set env $save_env
9291 proc cherrypick {} {
9292 global rowmenuid curview
9293 global mainhead mainheadid
9296 set oldhead [exec git rev-parse HEAD]
9297 set dheads [descheads $rowmenuid]
9298 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9299 set ok [confirm_popup [mc "Commit %s is already\
9300 included in branch %s -- really re-apply it?" \
9301 [string range $rowmenuid 0 7] $mainhead]]
9304 nowbusy cherrypick [mc "Cherry-picking"]
9306 # Unfortunately git-cherry-pick writes stuff to stderr even when
9307 # no error occurs, and exec takes that as an indication of error...
9308 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9311 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9313 error_popup [mc "Cherry-pick failed because of local changes\
9314 to file '%s'.\nPlease commit, reset or stash\
9315 your changes and try again." $fname]
9316 } elseif {[regexp -line \
9317 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9319 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9320 conflict.\nDo you wish to run git citool to\
9322 # Force citool to read MERGE_MSG
9323 file delete [file join $gitdir "GITGUI_MSG"]
9324 exec_citool {} $rowmenuid
9332 set newhead [exec git rev-parse HEAD]
9333 if {$newhead eq $oldhead} {
9335 error_popup [mc "No changes committed"]
9338 addnewchild $newhead $oldhead
9339 if {[commitinview $oldhead $curview]} {
9340 # XXX this isn't right if we have a path limit...
9341 insertrow $newhead $oldhead $curview
9342 if {$mainhead ne {}} {
9343 movehead $newhead $mainhead
9344 movedhead $newhead $mainhead
9346 set mainheadid $newhead
9355 global rowmenuid curview
9356 global mainhead mainheadid
9359 set oldhead [exec git rev-parse HEAD]
9360 set dheads [descheads $rowmenuid]
9361 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9362 set ok [confirm_popup [mc "Commit %s is not\
9363 included in branch %s -- really revert it?" \
9364 [string range $rowmenuid 0 7] $mainhead]]
9367 nowbusy revert [mc "Reverting"]
9370 if [catch {exec git revert --no-edit $rowmenuid} err] {
9372 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9374 regsub {\n( |\t)+} $files "\n" files
9375 error_popup [mc "Revert failed because of local changes to\
9376 the following files:%s Please commit, reset or stash \
9377 your changes and try again." $files]
9378 } elseif [regexp {error: could not revert} $err] {
9379 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9380 Do you wish to run git citool to resolve it?"]] {
9381 # Force citool to read MERGE_MSG
9382 file delete [file join $gitdir "GITGUI_MSG"]
9383 exec_citool {} $rowmenuid
9385 } else { error_popup $err }
9390 set newhead [exec git rev-parse HEAD]
9391 if { $newhead eq $oldhead } {
9393 error_popup [mc "No changes committed"]
9397 addnewchild $newhead $oldhead
9399 if [commitinview $oldhead $curview] {
9400 # XXX this isn't right if we have a path limit...
9401 insertrow $newhead $oldhead $curview
9402 if {$mainhead ne {}} {
9403 movehead $newhead $mainhead
9404 movedhead $newhead $mainhead
9406 set mainheadid $newhead
9416 global mainhead rowmenuid confirm_ok resettype NS
9419 set w ".confirmreset"
9422 wm title $w [mc "Confirm reset"]
9423 ${NS}::label $w.m -text \
9424 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9425 pack $w.m -side top -fill x -padx 20 -pady 20
9426 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9428 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9429 -text [mc "Soft: Leave working tree and index untouched"]
9430 grid $w.f.soft -sticky w
9431 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9432 -text [mc "Mixed: Leave working tree untouched, reset index"]
9433 grid $w.f.mixed -sticky w
9434 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9435 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9436 grid $w.f.hard -sticky w
9437 pack $w.f -side top -fill x -padx 4
9438 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9439 pack $w.ok -side left -fill x -padx 20 -pady 20
9440 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9441 bind $w <Key-Escape> [list destroy $w]
9442 pack $w.cancel -side right -fill x -padx 20 -pady 20
9443 bind $w <Visibility> "grab $w; focus $w"
9445 if {!$confirm_ok} return
9446 if {[catch {set fd [open \
9447 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9451 filerun $fd [list readresetstat $fd]
9452 nowbusy reset [mc "Resetting"]
9457 proc readresetstat {fd} {
9458 global mainhead mainheadid showlocalchanges rprogcoord
9460 if {[gets $fd line] >= 0} {
9461 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9462 set rprogcoord [expr {1.0 * $m / $n}]
9470 if {[catch {close $fd} err]} {
9473 set oldhead $mainheadid
9474 set newhead [exec git rev-parse HEAD]
9475 if {$newhead ne $oldhead} {
9476 movehead $newhead $mainhead
9477 movedhead $newhead $mainhead
9478 set mainheadid $newhead
9482 if {$showlocalchanges} {
9488 # context menu for a head
9489 proc headmenu {x y id head} {
9490 global headmenuid headmenuhead headctxmenu mainhead
9494 set headmenuhead $head
9496 if {[string match "remotes/*" $head]} {
9499 if {$head eq $mainhead} {
9502 $headctxmenu entryconfigure 0 -state $state
9503 $headctxmenu entryconfigure 1 -state $state
9504 tk_popup $headctxmenu $x $y
9508 global headmenuid headmenuhead headids
9509 global showlocalchanges
9511 # check the tree is clean first??
9512 nowbusy checkout [mc "Checking out"]
9516 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9520 if {$showlocalchanges} {
9524 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9528 proc readcheckoutstat {fd newhead newheadid} {
9529 global mainhead mainheadid headids showlocalchanges progresscoords
9530 global viewmainheadid curview
9532 if {[gets $fd line] >= 0} {
9533 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9534 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9539 set progresscoords {0 0}
9542 if {[catch {close $fd} err]} {
9545 set oldmainid $mainheadid
9546 set mainhead $newhead
9547 set mainheadid $newheadid
9548 set viewmainheadid($curview) $newheadid
9549 redrawtags $oldmainid
9550 redrawtags $newheadid
9552 if {$showlocalchanges} {
9558 global headmenuid headmenuhead mainhead
9561 set head $headmenuhead
9563 # this check shouldn't be needed any more...
9564 if {$head eq $mainhead} {
9565 error_popup [mc "Cannot delete the currently checked-out branch"]
9568 set dheads [descheads $id]
9569 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9570 # the stuff on this branch isn't on any other branch
9571 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9572 branch.\nReally delete branch %s?" $head $head]]} return
9576 if {[catch {exec git branch -D $head} err]} {
9581 removehead $id $head
9582 removedhead $id $head
9589 # Display a list of tags and heads
9591 global showrefstop bgcolor fgcolor selectbgcolor NS
9592 global bglist fglist reflistfilter reflist maincursor
9595 set showrefstop $top
9596 if {[winfo exists $top]} {
9602 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9603 make_transient $top .
9604 text $top.list -background $bgcolor -foreground $fgcolor \
9605 -selectbackground $selectbgcolor -font mainfont \
9606 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9607 -width 30 -height 20 -cursor $maincursor \
9608 -spacing1 1 -spacing3 1 -state disabled
9609 $top.list tag configure highlight -background $selectbgcolor
9610 lappend bglist $top.list
9611 lappend fglist $top.list
9612 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9613 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9614 grid $top.list $top.ysb -sticky nsew
9615 grid $top.xsb x -sticky ew
9617 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9618 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9619 set reflistfilter "*"
9620 trace add variable reflistfilter write reflistfilter_change
9621 pack $top.f.e -side right -fill x -expand 1
9622 pack $top.f.l -side left
9623 grid $top.f - -sticky ew -pady 2
9624 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9625 bind $top <Key-Escape> [list destroy $top]
9627 grid columnconfigure $top 0 -weight 1
9628 grid rowconfigure $top 0 -weight 1
9629 bind $top.list <1> {break}
9630 bind $top.list <B1-Motion> {break}
9631 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9636 proc sel_reflist {w x y} {
9637 global showrefstop reflist headids tagids otherrefids
9639 if {![winfo exists $showrefstop]} return
9640 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9641 set ref [lindex $reflist [expr {$l-1}]]
9642 set n [lindex $ref 0]
9643 switch -- [lindex $ref 1] {
9644 "H" {selbyid $headids($n)}
9645 "T" {selbyid $tagids($n)}
9646 "o" {selbyid $otherrefids($n)}
9648 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9651 proc unsel_reflist {} {
9654 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9655 $showrefstop.list tag remove highlight 0.0 end
9658 proc reflistfilter_change {n1 n2 op} {
9659 global reflistfilter
9661 after cancel refill_reflist
9662 after 200 refill_reflist
9665 proc refill_reflist {} {
9666 global reflist reflistfilter showrefstop headids tagids otherrefids
9669 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9671 foreach n [array names headids] {
9672 if {[string match $reflistfilter $n]} {
9673 if {[commitinview $headids($n) $curview]} {
9674 lappend refs [list $n H]
9676 interestedin $headids($n) {run refill_reflist}
9680 foreach n [array names tagids] {
9681 if {[string match $reflistfilter $n]} {
9682 if {[commitinview $tagids($n) $curview]} {
9683 lappend refs [list $n T]
9685 interestedin $tagids($n) {run refill_reflist}
9689 foreach n [array names otherrefids] {
9690 if {[string match $reflistfilter $n]} {
9691 if {[commitinview $otherrefids($n) $curview]} {
9692 lappend refs [list $n o]
9694 interestedin $otherrefids($n) {run refill_reflist}
9698 set refs [lsort -index 0 $refs]
9699 if {$refs eq $reflist} return
9701 # Update the contents of $showrefstop.list according to the
9702 # differences between $reflist (old) and $refs (new)
9703 $showrefstop.list conf -state normal
9704 $showrefstop.list insert end "\n"
9707 while {$i < [llength $reflist] || $j < [llength $refs]} {
9708 if {$i < [llength $reflist]} {
9709 if {$j < [llength $refs]} {
9710 set cmp [string compare [lindex $reflist $i 0] \
9711 [lindex $refs $j 0]]
9713 set cmp [string compare [lindex $reflist $i 1] \
9714 [lindex $refs $j 1]]
9724 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9732 set l [expr {$j + 1}]
9733 $showrefstop.list image create $l.0 -align baseline \
9734 -image reficon-[lindex $refs $j 1] -padx 2
9735 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9741 # delete last newline
9742 $showrefstop.list delete end-2c end-1c
9743 $showrefstop.list conf -state disabled
9746 # Stuff for finding nearby tags
9747 proc getallcommits {} {
9748 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9749 global idheads idtags idotherrefs allparents tagobjid
9752 if {![info exists allcommits]} {
9758 set allccache [file join $gitdir "gitk.cache"]
9760 set f [open $allccache r]
9769 set cmd [list | git rev-list --parents]
9770 set allcupdate [expr {$seeds ne {}}]
9774 set refs [concat [array names idheads] [array names idtags] \
9775 [array names idotherrefs]]
9778 foreach name [array names tagobjid] {
9779 lappend tagobjs $tagobjid($name)
9781 foreach id [lsort -unique $refs] {
9782 if {![info exists allparents($id)] &&
9783 [lsearch -exact $tagobjs $id] < 0} {
9794 set fd [open [concat $cmd $ids] r]
9795 fconfigure $fd -blocking 0
9798 filerun $fd [list getallclines $fd]
9804 # Since most commits have 1 parent and 1 child, we group strings of
9805 # such commits into "arcs" joining branch/merge points (BMPs), which
9806 # are commits that either don't have 1 parent or don't have 1 child.
9808 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9809 # arcout(id) - outgoing arcs for BMP
9810 # arcids(a) - list of IDs on arc including end but not start
9811 # arcstart(a) - BMP ID at start of arc
9812 # arcend(a) - BMP ID at end of arc
9813 # growing(a) - arc a is still growing
9814 # arctags(a) - IDs out of arcids (excluding end) that have tags
9815 # archeads(a) - IDs out of arcids (excluding end) that have heads
9816 # The start of an arc is at the descendent end, so "incoming" means
9817 # coming from descendents, and "outgoing" means going towards ancestors.
9819 proc getallclines {fd} {
9820 global allparents allchildren idtags idheads nextarc
9821 global arcnos arcids arctags arcout arcend arcstart archeads growing
9822 global seeds allcommits cachedarcs allcupdate
9825 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9826 set id [lindex $line 0]
9827 if {[info exists allparents($id)]} {
9832 set olds [lrange $line 1 end]
9833 set allparents($id) $olds
9834 if {![info exists allchildren($id)]} {
9835 set allchildren($id) {}
9840 if {[llength $olds] == 1 && [llength $a] == 1} {
9841 lappend arcids($a) $id
9842 if {[info exists idtags($id)]} {
9843 lappend arctags($a) $id
9845 if {[info exists idheads($id)]} {
9846 lappend archeads($a) $id
9848 if {[info exists allparents($olds)]} {
9849 # seen parent already
9850 if {![info exists arcout($olds)]} {
9853 lappend arcids($a) $olds
9854 set arcend($a) $olds
9857 lappend allchildren($olds) $id
9858 lappend arcnos($olds) $a
9862 foreach a $arcnos($id) {
9863 lappend arcids($a) $id
9870 lappend allchildren($p) $id
9871 set a [incr nextarc]
9872 set arcstart($a) $id
9879 if {[info exists allparents($p)]} {
9880 # seen it already, may need to make a new branch
9881 if {![info exists arcout($p)]} {
9884 lappend arcids($a) $p
9888 lappend arcnos($p) $a
9893 global cached_dheads cached_dtags cached_atags
9894 catch {unset cached_dheads}
9895 catch {unset cached_dtags}
9896 catch {unset cached_atags}
9899 return [expr {$nid >= 1000? 2: 1}]
9903 fconfigure $fd -blocking 1
9906 # got an error reading the list of commits
9907 # if we were updating, try rereading the whole thing again
9913 error_popup "[mc "Error reading commit topology information;\
9914 branch and preceding/following tag information\
9915 will be incomplete."]\n($err)"
9918 if {[incr allcommits -1] == 0} {
9928 proc recalcarc {a} {
9929 global arctags archeads arcids idtags idheads
9933 foreach id [lrange $arcids($a) 0 end-1] {
9934 if {[info exists idtags($id)]} {
9937 if {[info exists idheads($id)]} {
9942 set archeads($a) $ah
9946 global arcnos arcids nextarc arctags archeads idtags idheads
9947 global arcstart arcend arcout allparents growing
9950 if {[llength $a] != 1} {
9951 puts "oops splitarc called but [llength $a] arcs already"
9955 set i [lsearch -exact $arcids($a) $p]
9957 puts "oops splitarc $p not in arc $a"
9960 set na [incr nextarc]
9961 if {[info exists arcend($a)]} {
9962 set arcend($na) $arcend($a)
9964 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9965 set j [lsearch -exact $arcnos($l) $a]
9966 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9968 set tail [lrange $arcids($a) [expr {$i+1}] end]
9969 set arcids($a) [lrange $arcids($a) 0 $i]
9971 set arcstart($na) $p
9973 set arcids($na) $tail
9974 if {[info exists growing($a)]} {
9980 if {[llength $arcnos($id)] == 1} {
9983 set j [lsearch -exact $arcnos($id) $a]
9984 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
9988 # reconstruct tags and heads lists
9989 if {$arctags($a) ne {} || $archeads($a) ne {}} {
9994 set archeads($na) {}
9998 # Update things for a new commit added that is a child of one
9999 # existing commit. Used when cherry-picking.
10000 proc addnewchild {id p} {
10001 global allparents allchildren idtags nextarc
10002 global arcnos arcids arctags arcout arcend arcstart archeads growing
10003 global seeds allcommits
10005 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10006 set allparents($id) [list $p]
10007 set allchildren($id) {}
10010 lappend allchildren($p) $id
10011 set a [incr nextarc]
10012 set arcstart($a) $id
10013 set archeads($a) {}
10015 set arcids($a) [list $p]
10017 if {![info exists arcout($p)]} {
10020 lappend arcnos($p) $a
10021 set arcout($id) [list $a]
10024 # This implements a cache for the topology information.
10025 # The cache saves, for each arc, the start and end of the arc,
10026 # the ids on the arc, and the outgoing arcs from the end.
10027 proc readcache {f} {
10028 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10029 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10033 set lim $cachedarcs
10034 if {$lim - $a > 500} {
10035 set lim [expr {$a + 500}]
10039 # finish reading the cache and setting up arctags, etc.
10041 if {$line ne "1"} {error "bad final version"}
10043 foreach id [array names idtags] {
10044 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10045 [llength $allparents($id)] == 1} {
10046 set a [lindex $arcnos($id) 0]
10047 if {$arctags($a) eq {}} {
10052 foreach id [array names idheads] {
10053 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10054 [llength $allparents($id)] == 1} {
10055 set a [lindex $arcnos($id) 0]
10056 if {$archeads($a) eq {}} {
10061 foreach id [lsort -unique $possible_seeds] {
10062 if {$arcnos($id) eq {}} {
10068 while {[incr a] <= $lim} {
10070 if {[llength $line] != 3} {error "bad line"}
10071 set s [lindex $line 0]
10072 set arcstart($a) $s
10073 lappend arcout($s) $a
10074 if {![info exists arcnos($s)]} {
10075 lappend possible_seeds $s
10078 set e [lindex $line 1]
10083 if {![info exists arcout($e)]} {
10087 set arcids($a) [lindex $line 2]
10088 foreach id $arcids($a) {
10089 lappend allparents($s) $id
10091 lappend arcnos($id) $a
10093 if {![info exists allparents($s)]} {
10094 set allparents($s) {}
10097 set archeads($a) {}
10099 set nextarc [expr {$a - 1}]
10111 proc getcache {f} {
10112 global nextarc cachedarcs possible_seeds
10116 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10117 # make sure it's an integer
10118 set cachedarcs [expr {int([lindex $line 1])}]
10119 if {$cachedarcs < 0} {error "bad number of arcs"}
10121 set possible_seeds {}
10129 proc dropcache {err} {
10130 global allcwait nextarc cachedarcs seeds
10132 #puts "dropping cache ($err)"
10133 foreach v {arcnos arcout arcids arcstart arcend growing \
10134 arctags archeads allparents allchildren} {
10145 proc writecache {f} {
10146 global cachearc cachedarcs allccache
10147 global arcstart arcend arcnos arcids arcout
10150 set lim $cachedarcs
10151 if {$lim - $a > 1000} {
10152 set lim [expr {$a + 1000}]
10155 while {[incr a] <= $lim} {
10156 if {[info exists arcend($a)]} {
10157 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10159 puts $f [list $arcstart($a) {} $arcids($a)]
10164 catch {file delete $allccache}
10165 #puts "writing cache failed ($err)"
10168 set cachearc [expr {$a - 1}]
10169 if {$a > $cachedarcs} {
10177 proc savecache {} {
10178 global nextarc cachedarcs cachearc allccache
10180 if {$nextarc == $cachedarcs} return
10182 set cachedarcs $nextarc
10184 set f [open $allccache w]
10185 puts $f [list 1 $cachedarcs]
10190 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10191 # or 0 if neither is true.
10192 proc anc_or_desc {a b} {
10193 global arcout arcstart arcend arcnos cached_isanc
10195 if {$arcnos($a) eq $arcnos($b)} {
10196 # Both are on the same arc(s); either both are the same BMP,
10197 # or if one is not a BMP, the other is also not a BMP or is
10198 # the BMP at end of the arc (and it only has 1 incoming arc).
10199 # Or both can be BMPs with no incoming arcs.
10200 if {$a eq $b || $arcnos($a) eq {}} {
10203 # assert {[llength $arcnos($a)] == 1}
10204 set arc [lindex $arcnos($a) 0]
10205 set i [lsearch -exact $arcids($arc) $a]
10206 set j [lsearch -exact $arcids($arc) $b]
10207 if {$i < 0 || $i > $j} {
10214 if {![info exists arcout($a)]} {
10215 set arc [lindex $arcnos($a) 0]
10216 if {[info exists arcend($arc)]} {
10217 set aend $arcend($arc)
10221 set a $arcstart($arc)
10225 if {![info exists arcout($b)]} {
10226 set arc [lindex $arcnos($b) 0]
10227 if {[info exists arcend($arc)]} {
10228 set bend $arcend($arc)
10232 set b $arcstart($arc)
10242 if {[info exists cached_isanc($a,$bend)]} {
10243 if {$cached_isanc($a,$bend)} {
10247 if {[info exists cached_isanc($b,$aend)]} {
10248 if {$cached_isanc($b,$aend)} {
10251 if {[info exists cached_isanc($a,$bend)]} {
10256 set todo [list $a $b]
10259 for {set i 0} {$i < [llength $todo]} {incr i} {
10260 set x [lindex $todo $i]
10261 if {$anc($x) eq {}} {
10264 foreach arc $arcnos($x) {
10265 set xd $arcstart($arc)
10266 if {$xd eq $bend} {
10267 set cached_isanc($a,$bend) 1
10268 set cached_isanc($b,$aend) 0
10270 } elseif {$xd eq $aend} {
10271 set cached_isanc($b,$aend) 1
10272 set cached_isanc($a,$bend) 0
10275 if {![info exists anc($xd)]} {
10276 set anc($xd) $anc($x)
10278 } elseif {$anc($xd) ne $anc($x)} {
10283 set cached_isanc($a,$bend) 0
10284 set cached_isanc($b,$aend) 0
10288 # This identifies whether $desc has an ancestor that is
10289 # a growing tip of the graph and which is not an ancestor of $anc
10290 # and returns 0 if so and 1 if not.
10291 # If we subsequently discover a tag on such a growing tip, and that
10292 # turns out to be a descendent of $anc (which it could, since we
10293 # don't necessarily see children before parents), then $desc
10294 # isn't a good choice to display as a descendent tag of
10295 # $anc (since it is the descendent of another tag which is
10296 # a descendent of $anc). Similarly, $anc isn't a good choice to
10297 # display as a ancestor tag of $desc.
10299 proc is_certain {desc anc} {
10300 global arcnos arcout arcstart arcend growing problems
10303 if {[llength $arcnos($anc)] == 1} {
10304 # tags on the same arc are certain
10305 if {$arcnos($desc) eq $arcnos($anc)} {
10308 if {![info exists arcout($anc)]} {
10309 # if $anc is partway along an arc, use the start of the arc instead
10310 set a [lindex $arcnos($anc) 0]
10311 set anc $arcstart($a)
10314 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10317 set a [lindex $arcnos($desc) 0]
10323 set anclist [list $x]
10327 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10328 set x [lindex $anclist $i]
10333 foreach a $arcout($x) {
10334 if {[info exists growing($a)]} {
10335 if {![info exists growanc($x)] && $dl($x)} {
10341 if {[info exists dl($y)]} {
10345 if {![info exists done($y)]} {
10348 if {[info exists growanc($x)]} {
10352 for {set k 0} {$k < [llength $xl]} {incr k} {
10353 set z [lindex $xl $k]
10354 foreach c $arcout($z) {
10355 if {[info exists arcend($c)]} {
10357 if {[info exists dl($v)] && $dl($v)} {
10359 if {![info exists done($v)]} {
10362 if {[info exists growanc($v)]} {
10372 } elseif {$y eq $anc || !$dl($x)} {
10383 foreach x [array names growanc] {
10392 proc validate_arctags {a} {
10393 global arctags idtags
10396 set na $arctags($a)
10397 foreach id $arctags($a) {
10399 if {![info exists idtags($id)]} {
10400 set na [lreplace $na $i $i]
10404 set arctags($a) $na
10407 proc validate_archeads {a} {
10408 global archeads idheads
10411 set na $archeads($a)
10412 foreach id $archeads($a) {
10414 if {![info exists idheads($id)]} {
10415 set na [lreplace $na $i $i]
10419 set archeads($a) $na
10422 # Return the list of IDs that have tags that are descendents of id,
10423 # ignoring IDs that are descendents of IDs already reported.
10424 proc desctags {id} {
10425 global arcnos arcstart arcids arctags idtags allparents
10426 global growing cached_dtags
10428 if {![info exists allparents($id)]} {
10431 set t1 [clock clicks -milliseconds]
10433 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10434 # part-way along an arc; check that arc first
10435 set a [lindex $arcnos($id) 0]
10436 if {$arctags($a) ne {}} {
10437 validate_arctags $a
10438 set i [lsearch -exact $arcids($a) $id]
10440 foreach t $arctags($a) {
10441 set j [lsearch -exact $arcids($a) $t]
10442 if {$j >= $i} break
10449 set id $arcstart($a)
10450 if {[info exists idtags($id)]} {
10454 if {[info exists cached_dtags($id)]} {
10455 return $cached_dtags($id)
10459 set todo [list $id]
10462 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10463 set id [lindex $todo $i]
10465 set ta [info exists hastaggedancestor($id)]
10469 # ignore tags on starting node
10470 if {!$ta && $i > 0} {
10471 if {[info exists idtags($id)]} {
10472 set tagloc($id) $id
10474 } elseif {[info exists cached_dtags($id)]} {
10475 set tagloc($id) $cached_dtags($id)
10479 foreach a $arcnos($id) {
10480 set d $arcstart($a)
10481 if {!$ta && $arctags($a) ne {}} {
10482 validate_arctags $a
10483 if {$arctags($a) ne {}} {
10484 lappend tagloc($id) [lindex $arctags($a) end]
10487 if {$ta || $arctags($a) ne {}} {
10488 set tomark [list $d]
10489 for {set j 0} {$j < [llength $tomark]} {incr j} {
10490 set dd [lindex $tomark $j]
10491 if {![info exists hastaggedancestor($dd)]} {
10492 if {[info exists done($dd)]} {
10493 foreach b $arcnos($dd) {
10494 lappend tomark $arcstart($b)
10496 if {[info exists tagloc($dd)]} {
10499 } elseif {[info exists queued($dd)]} {
10502 set hastaggedancestor($dd) 1
10506 if {![info exists queued($d)]} {
10509 if {![info exists hastaggedancestor($d)]} {
10516 foreach id [array names tagloc] {
10517 if {![info exists hastaggedancestor($id)]} {
10518 foreach t $tagloc($id) {
10519 if {[lsearch -exact $tags $t] < 0} {
10525 set t2 [clock clicks -milliseconds]
10528 # remove tags that are descendents of other tags
10529 for {set i 0} {$i < [llength $tags]} {incr i} {
10530 set a [lindex $tags $i]
10531 for {set j 0} {$j < $i} {incr j} {
10532 set b [lindex $tags $j]
10533 set r [anc_or_desc $a $b]
10535 set tags [lreplace $tags $j $j]
10538 } elseif {$r == -1} {
10539 set tags [lreplace $tags $i $i]
10546 if {[array names growing] ne {}} {
10547 # graph isn't finished, need to check if any tag could get
10548 # eclipsed by another tag coming later. Simply ignore any
10549 # tags that could later get eclipsed.
10552 if {[is_certain $t $origid]} {
10556 if {$tags eq $ctags} {
10557 set cached_dtags($origid) $tags
10562 set cached_dtags($origid) $tags
10564 set t3 [clock clicks -milliseconds]
10565 if {0 && $t3 - $t1 >= 100} {
10566 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10567 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10572 proc anctags {id} {
10573 global arcnos arcids arcout arcend arctags idtags allparents
10574 global growing cached_atags
10576 if {![info exists allparents($id)]} {
10579 set t1 [clock clicks -milliseconds]
10581 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10582 # part-way along an arc; check that arc first
10583 set a [lindex $arcnos($id) 0]
10584 if {$arctags($a) ne {}} {
10585 validate_arctags $a
10586 set i [lsearch -exact $arcids($a) $id]
10587 foreach t $arctags($a) {
10588 set j [lsearch -exact $arcids($a) $t]
10594 if {![info exists arcend($a)]} {
10598 if {[info exists idtags($id)]} {
10602 if {[info exists cached_atags($id)]} {
10603 return $cached_atags($id)
10607 set todo [list $id]
10611 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10612 set id [lindex $todo $i]
10614 set td [info exists hastaggeddescendent($id)]
10618 # ignore tags on starting node
10619 if {!$td && $i > 0} {
10620 if {[info exists idtags($id)]} {
10621 set tagloc($id) $id
10623 } elseif {[info exists cached_atags($id)]} {
10624 set tagloc($id) $cached_atags($id)
10628 foreach a $arcout($id) {
10629 if {!$td && $arctags($a) ne {}} {
10630 validate_arctags $a
10631 if {$arctags($a) ne {}} {
10632 lappend tagloc($id) [lindex $arctags($a) 0]
10635 if {![info exists arcend($a)]} continue
10637 if {$td || $arctags($a) ne {}} {
10638 set tomark [list $d]
10639 for {set j 0} {$j < [llength $tomark]} {incr j} {
10640 set dd [lindex $tomark $j]
10641 if {![info exists hastaggeddescendent($dd)]} {
10642 if {[info exists done($dd)]} {
10643 foreach b $arcout($dd) {
10644 if {[info exists arcend($b)]} {
10645 lappend tomark $arcend($b)
10648 if {[info exists tagloc($dd)]} {
10651 } elseif {[info exists queued($dd)]} {
10654 set hastaggeddescendent($dd) 1
10658 if {![info exists queued($d)]} {
10661 if {![info exists hastaggeddescendent($d)]} {
10667 set t2 [clock clicks -milliseconds]
10670 foreach id [array names tagloc] {
10671 if {![info exists hastaggeddescendent($id)]} {
10672 foreach t $tagloc($id) {
10673 if {[lsearch -exact $tags $t] < 0} {
10680 # remove tags that are ancestors of other tags
10681 for {set i 0} {$i < [llength $tags]} {incr i} {
10682 set a [lindex $tags $i]
10683 for {set j 0} {$j < $i} {incr j} {
10684 set b [lindex $tags $j]
10685 set r [anc_or_desc $a $b]
10687 set tags [lreplace $tags $j $j]
10690 } elseif {$r == 1} {
10691 set tags [lreplace $tags $i $i]
10698 if {[array names growing] ne {}} {
10699 # graph isn't finished, need to check if any tag could get
10700 # eclipsed by another tag coming later. Simply ignore any
10701 # tags that could later get eclipsed.
10704 if {[is_certain $origid $t]} {
10708 if {$tags eq $ctags} {
10709 set cached_atags($origid) $tags
10714 set cached_atags($origid) $tags
10716 set t3 [clock clicks -milliseconds]
10717 if {0 && $t3 - $t1 >= 100} {
10718 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10719 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10724 # Return the list of IDs that have heads that are descendents of id,
10725 # including id itself if it has a head.
10726 proc descheads {id} {
10727 global arcnos arcstart arcids archeads idheads cached_dheads
10728 global allparents arcout
10730 if {![info exists allparents($id)]} {
10734 if {![info exists arcout($id)]} {
10735 # part-way along an arc; check it first
10736 set a [lindex $arcnos($id) 0]
10737 if {$archeads($a) ne {}} {
10738 validate_archeads $a
10739 set i [lsearch -exact $arcids($a) $id]
10740 foreach t $archeads($a) {
10741 set j [lsearch -exact $arcids($a) $t]
10746 set id $arcstart($a)
10749 set todo [list $id]
10752 for {set i 0} {$i < [llength $todo]} {incr i} {
10753 set id [lindex $todo $i]
10754 if {[info exists cached_dheads($id)]} {
10755 set ret [concat $ret $cached_dheads($id)]
10757 if {[info exists idheads($id)]} {
10760 foreach a $arcnos($id) {
10761 if {$archeads($a) ne {}} {
10762 validate_archeads $a
10763 if {$archeads($a) ne {}} {
10764 set ret [concat $ret $archeads($a)]
10767 set d $arcstart($a)
10768 if {![info exists seen($d)]} {
10775 set ret [lsort -unique $ret]
10776 set cached_dheads($origid) $ret
10777 return [concat $ret $aret]
10780 proc addedtag {id} {
10781 global arcnos arcout cached_dtags cached_atags
10783 if {![info exists arcnos($id)]} return
10784 if {![info exists arcout($id)]} {
10785 recalcarc [lindex $arcnos($id) 0]
10787 catch {unset cached_dtags}
10788 catch {unset cached_atags}
10791 proc addedhead {hid head} {
10792 global arcnos arcout cached_dheads
10794 if {![info exists arcnos($hid)]} return
10795 if {![info exists arcout($hid)]} {
10796 recalcarc [lindex $arcnos($hid) 0]
10798 catch {unset cached_dheads}
10801 proc removedhead {hid head} {
10802 global cached_dheads
10804 catch {unset cached_dheads}
10807 proc movedhead {hid head} {
10808 global arcnos arcout cached_dheads
10810 if {![info exists arcnos($hid)]} return
10811 if {![info exists arcout($hid)]} {
10812 recalcarc [lindex $arcnos($hid) 0]
10814 catch {unset cached_dheads}
10817 proc changedrefs {} {
10818 global cached_dheads cached_dtags cached_atags cached_tagcontent
10819 global arctags archeads arcnos arcout idheads idtags
10821 foreach id [concat [array names idheads] [array names idtags]] {
10822 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10823 set a [lindex $arcnos($id) 0]
10824 if {![info exists donearc($a)]} {
10830 catch {unset cached_tagcontent}
10831 catch {unset cached_dtags}
10832 catch {unset cached_atags}
10833 catch {unset cached_dheads}
10836 proc rereadrefs {} {
10837 global idtags idheads idotherrefs mainheadid
10839 set refids [concat [array names idtags] \
10840 [array names idheads] [array names idotherrefs]]
10841 foreach id $refids {
10842 if {![info exists ref($id)]} {
10843 set ref($id) [listrefs $id]
10846 set oldmainhead $mainheadid
10849 set refids [lsort -unique [concat $refids [array names idtags] \
10850 [array names idheads] [array names idotherrefs]]]
10851 foreach id $refids {
10852 set v [listrefs $id]
10853 if {![info exists ref($id)] || $ref($id) != $v} {
10857 if {$oldmainhead ne $mainheadid} {
10858 redrawtags $oldmainhead
10859 redrawtags $mainheadid
10864 proc listrefs {id} {
10865 global idtags idheads idotherrefs
10868 if {[info exists idtags($id)]} {
10872 if {[info exists idheads($id)]} {
10873 set y $idheads($id)
10876 if {[info exists idotherrefs($id)]} {
10877 set z $idotherrefs($id)
10879 return [list $x $y $z]
10882 proc showtag {tag isnew} {
10883 global ctext cached_tagcontent tagids linknum tagobjid
10886 addtohistory [list showtag $tag 0] savectextpos
10888 $ctext conf -state normal
10892 if {![info exists cached_tagcontent($tag)]} {
10894 set cached_tagcontent($tag) [exec git cat-file -p $tag]
10897 if {[info exists cached_tagcontent($tag)]} {
10898 set text $cached_tagcontent($tag)
10900 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10902 appendwithlinks $text {}
10903 maybe_scroll_ctext 1
10904 $ctext conf -state disabled
10916 if {[info exists gitktmpdir]} {
10917 catch {file delete -force $gitktmpdir}
10921 proc mkfontdisp {font top which} {
10922 global fontattr fontpref $font NS use_ttk
10924 set fontpref($font) [set $font]
10925 ${NS}::button $top.${font}but -text $which \
10926 -command [list choosefont $font $which]
10927 ${NS}::label $top.$font -relief flat -font $font \
10928 -text $fontattr($font,family) -justify left
10929 grid x $top.${font}but $top.$font -sticky w
10932 proc choosefont {font which} {
10933 global fontparam fontlist fonttop fontattr
10936 set fontparam(which) $which
10937 set fontparam(font) $font
10938 set fontparam(family) [font actual $font -family]
10939 set fontparam(size) $fontattr($font,size)
10940 set fontparam(weight) $fontattr($font,weight)
10941 set fontparam(slant) $fontattr($font,slant)
10944 if {![winfo exists $top]} {
10946 eval font config sample [font actual $font]
10948 make_transient $top $prefstop
10949 wm title $top [mc "Gitk font chooser"]
10950 ${NS}::label $top.l -textvariable fontparam(which)
10951 pack $top.l -side top
10952 set fontlist [lsort [font families]]
10953 ${NS}::frame $top.f
10954 listbox $top.f.fam -listvariable fontlist \
10955 -yscrollcommand [list $top.f.sb set]
10956 bind $top.f.fam <<ListboxSelect>> selfontfam
10957 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10958 pack $top.f.sb -side right -fill y
10959 pack $top.f.fam -side left -fill both -expand 1
10960 pack $top.f -side top -fill both -expand 1
10961 ${NS}::frame $top.g
10962 spinbox $top.g.size -from 4 -to 40 -width 4 \
10963 -textvariable fontparam(size) \
10964 -validatecommand {string is integer -strict %s}
10965 checkbutton $top.g.bold -padx 5 \
10966 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10967 -variable fontparam(weight) -onvalue bold -offvalue normal
10968 checkbutton $top.g.ital -padx 5 \
10969 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10970 -variable fontparam(slant) -onvalue italic -offvalue roman
10971 pack $top.g.size $top.g.bold $top.g.ital -side left
10972 pack $top.g -side top
10973 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10975 $top.c create text 100 25 -anchor center -text $which -font sample \
10976 -fill black -tags text
10977 bind $top.c <Configure> [list centertext $top.c]
10978 pack $top.c -side top -fill x
10979 ${NS}::frame $top.buts
10980 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10981 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10982 bind $top <Key-Return> fontok
10983 bind $top <Key-Escape> fontcan
10984 grid $top.buts.ok $top.buts.can
10985 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10986 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10987 pack $top.buts -side bottom -fill x
10988 trace add variable fontparam write chg_fontparam
10991 $top.c itemconf text -text $which
10993 set i [lsearch -exact $fontlist $fontparam(family)]
10995 $top.f.fam selection set $i
11000 proc centertext {w} {
11001 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11005 global fontparam fontpref prefstop
11007 set f $fontparam(font)
11008 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11009 if {$fontparam(weight) eq "bold"} {
11010 lappend fontpref($f) "bold"
11012 if {$fontparam(slant) eq "italic"} {
11013 lappend fontpref($f) "italic"
11015 set w $prefstop.notebook.fonts.$f
11016 $w conf -text $fontparam(family) -font $fontpref($f)
11022 global fonttop fontparam
11024 if {[info exists fonttop]} {
11025 catch {destroy $fonttop}
11026 catch {font delete sample}
11032 if {[package vsatisfies [package provide Tk] 8.6]} {
11033 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11034 # function to make use of it.
11035 proc choosefont {font which} {
11036 tk fontchooser configure -title $which -font $font \
11037 -command [list on_choosefont $font $which]
11038 tk fontchooser show
11040 proc on_choosefont {font which newfont} {
11042 puts stderr "$font $newfont"
11043 array set f [font actual $newfont]
11044 set fontparam(which) $which
11045 set fontparam(font) $font
11046 set fontparam(family) $f(-family)
11047 set fontparam(size) $f(-size)
11048 set fontparam(weight) $f(-weight)
11049 set fontparam(slant) $f(-slant)
11054 proc selfontfam {} {
11055 global fonttop fontparam
11057 set i [$fonttop.f.fam curselection]
11059 set fontparam(family) [$fonttop.f.fam get $i]
11063 proc chg_fontparam {v sub op} {
11066 font config sample -$sub $fontparam($sub)
11069 # Create a property sheet tab page
11070 proc create_prefs_page {w} {
11072 set parent [join [lrange [split $w .] 0 end-1] .]
11073 if {[winfo class $parent] eq "TNotebook"} {
11076 ${NS}::labelframe $w
11080 proc prefspage_general {notebook} {
11081 global NS maxwidth maxgraphpct showneartags showlocalchanges
11082 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11083 global hideremotes want_ttk have_ttk maxrefs
11085 set page [create_prefs_page $notebook.general]
11087 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11088 grid $page.ldisp - -sticky w -pady 10
11089 ${NS}::label $page.spacer -text " "
11090 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11091 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11092 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11093 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11094 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11095 grid x $page.maxpctl $page.maxpct -sticky w
11096 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11097 -variable showlocalchanges
11098 grid x $page.showlocal -sticky w
11099 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11100 -variable autoselect
11101 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11102 grid x $page.autoselect $page.autosellen -sticky w
11103 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11104 -variable hideremotes
11105 grid x $page.hideremotes -sticky w
11107 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11108 grid $page.ddisp - -sticky w -pady 10
11109 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11110 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11111 grid x $page.tabstopl $page.tabstop -sticky w
11112 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11113 -variable showneartags
11114 grid x $page.ntag -sticky w
11115 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11116 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11117 grid x $page.maxrefsl $page.maxrefs -sticky w
11118 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11119 -variable limitdiffs
11120 grid x $page.ldiff -sticky w
11121 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11122 -variable perfile_attrs
11123 grid x $page.lattr -sticky w
11125 ${NS}::entry $page.extdifft -textvariable extdifftool
11126 ${NS}::frame $page.extdifff
11127 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11128 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11129 pack $page.extdifff.l $page.extdifff.b -side left
11130 pack configure $page.extdifff.l -padx 10
11131 grid x $page.extdifff $page.extdifft -sticky ew
11133 ${NS}::label $page.lgen -text [mc "General options"]
11134 grid $page.lgen - -sticky w -pady 10
11135 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11136 -text [mc "Use themed widgets"]
11138 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11140 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11142 grid x $page.want_ttk $page.ttk_note -sticky w
11146 proc prefspage_colors {notebook} {
11147 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11149 set page [create_prefs_page $notebook.colors]
11151 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11152 grid $page.cdisp - -sticky w -pady 10
11153 label $page.ui -padx 40 -relief sunk -background $uicolor
11154 ${NS}::button $page.uibut -text [mc "Interface"] \
11155 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11156 grid x $page.uibut $page.ui -sticky w
11157 label $page.bg -padx 40 -relief sunk -background $bgcolor
11158 ${NS}::button $page.bgbut -text [mc "Background"] \
11159 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11160 grid x $page.bgbut $page.bg -sticky w
11161 label $page.fg -padx 40 -relief sunk -background $fgcolor
11162 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11163 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11164 grid x $page.fgbut $page.fg -sticky w
11165 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11166 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11167 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11168 [list $ctext tag conf d0 -foreground]]
11169 grid x $page.diffoldbut $page.diffold -sticky w
11170 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11171 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11172 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11173 [list $ctext tag conf dresult -foreground]]
11174 grid x $page.diffnewbut $page.diffnew -sticky w
11175 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11176 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11177 -command [list choosecolor diffcolors 2 $page.hunksep \
11178 [mc "diff hunk header"] \
11179 [list $ctext tag conf hunksep -foreground]]
11180 grid x $page.hunksepbut $page.hunksep -sticky w
11181 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11182 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11183 -command [list choosecolor markbgcolor {} $page.markbgsep \
11184 [mc "marked line background"] \
11185 [list $ctext tag conf omark -background]]
11186 grid x $page.markbgbut $page.markbgsep -sticky w
11187 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11188 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11189 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11190 grid x $page.selbgbut $page.selbgsep -sticky w
11194 proc prefspage_fonts {notebook} {
11196 set page [create_prefs_page $notebook.fonts]
11197 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11198 grid $page.cfont - -sticky w -pady 10
11199 mkfontdisp mainfont $page [mc "Main font"]
11200 mkfontdisp textfont $page [mc "Diff display font"]
11201 mkfontdisp uifont $page [mc "User interface font"]
11206 global maxwidth maxgraphpct use_ttk NS
11207 global oldprefs prefstop showneartags showlocalchanges
11208 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11209 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11210 global hideremotes want_ttk have_ttk
11214 if {[winfo exists $top]} {
11218 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11219 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11220 set oldprefs($v) [set $v]
11223 wm title $top [mc "Gitk preferences"]
11224 make_transient $top .
11226 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11227 set notebook [ttk::notebook $top.notebook]
11229 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11232 lappend pages [prefspage_general $notebook] [mc "General"]
11233 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11234 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11236 foreach {page title} $pages {
11237 if {$use_notebook} {
11238 $notebook add $page -text $title
11240 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11241 -text $title -command [list raise $page]]
11242 $page configure -text $title
11243 grid $btn -row 0 -column [incr col] -sticky w
11244 grid $page -row 1 -column 0 -sticky news -columnspan 100
11248 if {!$use_notebook} {
11249 grid columnconfigure $notebook 0 -weight 1
11250 grid rowconfigure $notebook 1 -weight 1
11251 raise [lindex $pages 0]
11254 grid $notebook -sticky news -padx 2 -pady 2
11255 grid rowconfigure $top 0 -weight 1
11256 grid columnconfigure $top 0 -weight 1
11258 ${NS}::frame $top.buts
11259 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11260 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11261 bind $top <Key-Return> prefsok
11262 bind $top <Key-Escape> prefscan
11263 grid $top.buts.ok $top.buts.can
11264 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11265 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11266 grid $top.buts - - -pady 10 -sticky ew
11267 grid columnconfigure $top 2 -weight 1
11268 bind $top <Visibility> [list focus $top.buts.ok]
11271 proc choose_extdiff {} {
11274 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11276 set extdifftool $prog
11280 proc choosecolor {v vi w x cmd} {
11283 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11284 -title [mc "Gitk: choose color for %s" $x]]
11285 if {$c eq {}} return
11286 $w conf -background $c
11291 proc setselbg {c} {
11292 global bglist cflist
11293 foreach w $bglist {
11294 $w configure -selectbackground $c
11296 $cflist tag configure highlight \
11297 -background [$cflist cget -selectbackground]
11298 allcanvs itemconf secsel -fill $c
11301 # This sets the background color and the color scheme for the whole UI.
11302 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11303 # if we don't specify one ourselves, which makes the checkbuttons and
11304 # radiobuttons look bad. This chooses white for selectColor if the
11305 # background color is light, or black if it is dark.
11307 if {[tk windowingsystem] eq "win32"} { return }
11308 set bg [winfo rgb . $c]
11310 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11313 tk_setPalette background $c selectColor $selc
11319 foreach w $bglist {
11320 $w conf -background $c
11327 foreach w $fglist {
11328 $w conf -foreground $c
11330 allcanvs itemconf text -fill $c
11331 $canv itemconf circle -outline $c
11332 $canv itemconf markid -outline $c
11336 global oldprefs prefstop
11338 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11339 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11341 set $v $oldprefs($v)
11343 catch {destroy $prefstop}
11349 global maxwidth maxgraphpct
11350 global oldprefs prefstop showneartags showlocalchanges
11351 global fontpref mainfont textfont uifont
11352 global limitdiffs treediffs perfile_attrs
11355 catch {destroy $prefstop}
11359 if {$mainfont ne $fontpref(mainfont)} {
11360 set mainfont $fontpref(mainfont)
11361 parsefont mainfont $mainfont
11362 eval font configure mainfont [fontflags mainfont]
11363 eval font configure mainfontbold [fontflags mainfont 1]
11367 if {$textfont ne $fontpref(textfont)} {
11368 set textfont $fontpref(textfont)
11369 parsefont textfont $textfont
11370 eval font configure textfont [fontflags textfont]
11371 eval font configure textfontbold [fontflags textfont 1]
11373 if {$uifont ne $fontpref(uifont)} {
11374 set uifont $fontpref(uifont)
11375 parsefont uifont $uifont
11376 eval font configure uifont [fontflags uifont]
11379 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11380 if {$showlocalchanges} {
11386 if {$limitdiffs != $oldprefs(limitdiffs) ||
11387 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11388 # treediffs elements are limited by path;
11389 # won't have encodings cached if perfile_attrs was just turned on
11390 catch {unset treediffs}
11392 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11393 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11395 } elseif {$showneartags != $oldprefs(showneartags) ||
11396 $limitdiffs != $oldprefs(limitdiffs)} {
11399 if {$hideremotes != $oldprefs(hideremotes)} {
11404 proc formatdate {d} {
11405 global datetimeformat
11407 set d [clock format [lindex $d 0] -format $datetimeformat]
11412 # This list of encoding names and aliases is distilled from
11413 # http://www.iana.org/assignments/character-sets.
11414 # Not all of them are supported by Tcl.
11415 set encoding_aliases {
11416 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11417 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11418 { ISO-10646-UTF-1 csISO10646UTF1 }
11419 { ISO_646.basic:1983 ref csISO646basic1983 }
11420 { INVARIANT csINVARIANT }
11421 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11422 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11423 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11424 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11425 { NATS-DANO iso-ir-9-1 csNATSDANO }
11426 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11427 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11428 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11429 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11430 { ISO-2022-KR csISO2022KR }
11432 { ISO-2022-JP csISO2022JP }
11433 { ISO-2022-JP-2 csISO2022JP2 }
11434 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11435 csISO13JISC6220jp }
11436 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11437 { IT iso-ir-15 ISO646-IT csISO15Italian }
11438 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11439 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11440 { greek7-old iso-ir-18 csISO18Greek7Old }
11441 { latin-greek iso-ir-19 csISO19LatinGreek }
11442 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11443 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11444 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11445 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11446 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11447 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11448 { INIS iso-ir-49 csISO49INIS }
11449 { INIS-8 iso-ir-50 csISO50INIS8 }
11450 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11451 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11452 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11453 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11454 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11455 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11456 csISO60Norwegian1 }
11457 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11458 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11459 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11460 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11461 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11462 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11463 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11464 { greek7 iso-ir-88 csISO88Greek7 }
11465 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11466 { iso-ir-90 csISO90 }
11467 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11468 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11469 csISO92JISC62991984b }
11470 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11471 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11472 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11473 csISO95JIS62291984handadd }
11474 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11475 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11476 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11477 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11478 CP819 csISOLatin1 }
11479 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11480 { T.61-7bit iso-ir-102 csISO102T617bit }
11481 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11482 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11483 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11484 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11485 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11486 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11487 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11488 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11489 arabic csISOLatinArabic }
11490 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11491 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11492 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11493 greek greek8 csISOLatinGreek }
11494 { T.101-G2 iso-ir-128 csISO128T101G2 }
11495 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11497 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11498 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11499 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11500 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11501 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11502 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11503 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11504 csISOLatinCyrillic }
11505 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11506 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11507 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11508 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11509 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11510 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11511 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11512 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11513 { ISO_10367-box iso-ir-155 csISO10367Box }
11514 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11515 { latin-lap lap iso-ir-158 csISO158Lap }
11516 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11517 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11520 { JIS_X0201 X0201 csHalfWidthKatakana }
11521 { KSC5636 ISO646-KR csKSC5636 }
11522 { ISO-10646-UCS-2 csUnicode }
11523 { ISO-10646-UCS-4 csUCS4 }
11524 { DEC-MCS dec csDECMCS }
11525 { hp-roman8 roman8 r8 csHPRoman8 }
11526 { macintosh mac csMacintosh }
11527 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11529 { IBM038 EBCDIC-INT cp038 csIBM038 }
11530 { IBM273 CP273 csIBM273 }
11531 { IBM274 EBCDIC-BE CP274 csIBM274 }
11532 { IBM275 EBCDIC-BR cp275 csIBM275 }
11533 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11534 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11535 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11536 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11537 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11538 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11539 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11540 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11541 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11542 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11543 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11544 { IBM437 cp437 437 csPC8CodePage437 }
11545 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11546 { IBM775 cp775 csPC775Baltic }
11547 { IBM850 cp850 850 csPC850Multilingual }
11548 { IBM851 cp851 851 csIBM851 }
11549 { IBM852 cp852 852 csPCp852 }
11550 { IBM855 cp855 855 csIBM855 }
11551 { IBM857 cp857 857 csIBM857 }
11552 { IBM860 cp860 860 csIBM860 }
11553 { IBM861 cp861 861 cp-is csIBM861 }
11554 { IBM862 cp862 862 csPC862LatinHebrew }
11555 { IBM863 cp863 863 csIBM863 }
11556 { IBM864 cp864 csIBM864 }
11557 { IBM865 cp865 865 csIBM865 }
11558 { IBM866 cp866 866 csIBM866 }
11559 { IBM868 CP868 cp-ar csIBM868 }
11560 { IBM869 cp869 869 cp-gr csIBM869 }
11561 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11562 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11563 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11564 { IBM891 cp891 csIBM891 }
11565 { IBM903 cp903 csIBM903 }
11566 { IBM904 cp904 904 csIBBM904 }
11567 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11568 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11569 { IBM1026 CP1026 csIBM1026 }
11570 { EBCDIC-AT-DE csIBMEBCDICATDE }
11571 { EBCDIC-AT-DE-A csEBCDICATDEA }
11572 { EBCDIC-CA-FR csEBCDICCAFR }
11573 { EBCDIC-DK-NO csEBCDICDKNO }
11574 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11575 { EBCDIC-FI-SE csEBCDICFISE }
11576 { EBCDIC-FI-SE-A csEBCDICFISEA }
11577 { EBCDIC-FR csEBCDICFR }
11578 { EBCDIC-IT csEBCDICIT }
11579 { EBCDIC-PT csEBCDICPT }
11580 { EBCDIC-ES csEBCDICES }
11581 { EBCDIC-ES-A csEBCDICESA }
11582 { EBCDIC-ES-S csEBCDICESS }
11583 { EBCDIC-UK csEBCDICUK }
11584 { EBCDIC-US csEBCDICUS }
11585 { UNKNOWN-8BIT csUnknown8BiT }
11586 { MNEMONIC csMnemonic }
11588 { VISCII csVISCII }
11591 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11592 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11593 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11594 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11595 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11596 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11597 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11598 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11599 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11600 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11601 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11602 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11603 { IBM1047 IBM-1047 }
11604 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11605 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11606 { UNICODE-1-1 csUnicode11 }
11607 { CESU-8 csCESU-8 }
11608 { BOCU-1 csBOCU-1 }
11609 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11610 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11612 { ISO-8859-15 ISO_8859-15 Latin-9 }
11613 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11614 { GBK CP936 MS936 windows-936 }
11615 { JIS_Encoding csJISEncoding }
11616 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11617 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11619 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11620 { ISO-10646-UCS-Basic csUnicodeASCII }
11621 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11622 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11623 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11624 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11625 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11626 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11627 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11628 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11629 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11630 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11631 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11632 { Ventura-US csVenturaUS }
11633 { Ventura-International csVenturaInternational }
11634 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11635 { PC8-Turkish csPC8Turkish }
11636 { IBM-Symbols csIBMSymbols }
11637 { IBM-Thai csIBMThai }
11638 { HP-Legal csHPLegal }
11639 { HP-Pi-font csHPPiFont }
11640 { HP-Math8 csHPMath8 }
11641 { Adobe-Symbol-Encoding csHPPSMath }
11642 { HP-DeskTop csHPDesktop }
11643 { Ventura-Math csVenturaMath }
11644 { Microsoft-Publishing csMicrosoftPublishing }
11645 { Windows-31J csWindows31J }
11646 { GB2312 csGB2312 }
11650 proc tcl_encoding {enc} {
11651 global encoding_aliases tcl_encoding_cache
11652 if {[info exists tcl_encoding_cache($enc)]} {
11653 return $tcl_encoding_cache($enc)
11655 set names [encoding names]
11656 set lcnames [string tolower $names]
11657 set enc [string tolower $enc]
11658 set i [lsearch -exact $lcnames $enc]
11660 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11661 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11662 set i [lsearch -exact $lcnames $encx]
11666 foreach l $encoding_aliases {
11667 set ll [string tolower $l]
11668 if {[lsearch -exact $ll $enc] < 0} continue
11669 # look through the aliases for one that tcl knows about
11671 set i [lsearch -exact $lcnames $e]
11673 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11674 set i [lsearch -exact $lcnames $ex]
11684 set tclenc [lindex $names $i]
11686 set tcl_encoding_cache($enc) $tclenc
11690 proc gitattr {path attr default} {
11691 global path_attr_cache
11692 if {[info exists path_attr_cache($attr,$path)]} {
11693 set r $path_attr_cache($attr,$path)
11695 set r "unspecified"
11696 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11697 regexp "(.*): $attr: (.*)" $line m f r
11699 set path_attr_cache($attr,$path) $r
11701 if {$r eq "unspecified"} {
11707 proc cache_gitattr {attr pathlist} {
11708 global path_attr_cache
11710 foreach path $pathlist {
11711 if {![info exists path_attr_cache($attr,$path)]} {
11712 lappend newlist $path
11716 if {[tk windowingsystem] == "win32"} {
11717 # windows has a 32k limit on the arguments to a command...
11720 while {$newlist ne {}} {
11721 set head [lrange $newlist 0 [expr {$lim - 1}]]
11722 set newlist [lrange $newlist $lim end]
11723 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11724 foreach row [split $rlist "\n"] {
11725 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11726 if {[string index $path 0] eq "\""} {
11727 set path [encoding convertfrom [lindex $path 0]]
11729 set path_attr_cache($attr,$path) $value
11736 proc get_path_encoding {path} {
11737 global gui_encoding perfile_attrs
11738 set tcl_enc $gui_encoding
11739 if {$path ne {} && $perfile_attrs} {
11740 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11748 # First check that Tcl/Tk is recent enough
11749 if {[catch {package require Tk 8.4} err]} {
11750 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11751 Gitk requires at least Tcl/Tk 8.4." list
11755 # on OSX bring the current Wish process window to front
11756 if {[tk windowingsystem] eq "aqua"} {
11757 exec osascript -e [format {
11758 tell application "System Events"
11759 set frontmost of processes whose unix id is %d to true
11764 # Unset GIT_TRACE var if set
11765 if { [info exists ::env(GIT_TRACE)] } {
11766 unset ::env(GIT_TRACE)
11770 set wrcomcmd "git diff-tree --stdin -p --pretty"
11774 set gitencoding [exec git config --get i18n.commitencoding]
11777 set gitencoding [exec git config --get i18n.logoutputencoding]
11779 if {$gitencoding == ""} {
11780 set gitencoding "utf-8"
11782 set tclencoding [tcl_encoding $gitencoding]
11783 if {$tclencoding == {}} {
11784 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11787 set gui_encoding [encoding system]
11789 set enc [exec git config --get gui.encoding]
11791 set tclenc [tcl_encoding $enc]
11792 if {$tclenc ne {}} {
11793 set gui_encoding $tclenc
11795 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11800 set log_showroot true
11802 set log_showroot [exec git config --bool --get log.showroot]
11805 if {[tk windowingsystem] eq "aqua"} {
11806 set mainfont {{Lucida Grande} 9}
11807 set textfont {Monaco 9}
11808 set uifont {{Lucida Grande} 9 bold}
11809 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11811 set mainfont {sans 9}
11812 set textfont {monospace 9}
11813 set uifont {sans 9 bold}
11815 set mainfont {Helvetica 9}
11816 set textfont {Courier 9}
11817 set uifont {Helvetica 9 bold}
11820 set findmergefiles 0
11828 set cmitmode "patch"
11829 set wrapcomment "none"
11834 set showlocalchanges 1
11836 set datetimeformat "%Y-%m-%d %H:%M:%S"
11839 set perfile_attrs 0
11842 if {[tk windowingsystem] eq "aqua"} {
11843 set extdifftool "opendiff"
11845 set extdifftool "meld"
11848 set colors {green red blue magenta darkgrey brown orange}
11849 if {[tk windowingsystem] eq "win32"} {
11850 set uicolor SystemButtonFace
11851 set uifgcolor SystemButtonText
11852 set uifgdisabledcolor SystemDisabledText
11853 set bgcolor SystemWindow
11854 set fgcolor SystemWindowText
11855 set selectbgcolor SystemHighlight
11858 set uifgcolor black
11859 set uifgdisabledcolor "#999"
11862 set selectbgcolor gray85
11864 set diffcolors {red "#00a000" blue}
11866 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
11869 set markbgcolor "#e0e0ff"
11871 set headbgcolor green
11872 set headfgcolor black
11873 set headoutlinecolor black
11874 set remotebgcolor #ffddaa
11875 set tagbgcolor yellow
11876 set tagfgcolor black
11877 set tagoutlinecolor black
11878 set reflinecolor black
11879 set filesepbgcolor #aaaaaa
11880 set filesepfgcolor black
11881 set linehoverbgcolor #ffff80
11882 set linehoverfgcolor black
11883 set linehoveroutlinecolor black
11884 set mainheadcirclecolor yellow
11885 set workingfilescirclecolor red
11886 set indexcirclecolor green
11887 set circlecolors {white blue gray blue blue}
11888 set linkfgcolor blue
11889 set circleoutlinecolor $fgcolor
11890 set foundbgcolor yellow
11891 set currentsearchhitbgcolor orange
11893 # button for popping up context menus
11894 if {[tk windowingsystem] eq "aqua"} {
11895 set ctxbut <Button-2>
11897 set ctxbut <Button-3>
11900 ## For msgcat loading, first locate the installation location.
11901 if { [info exists ::env(GITK_MSGSDIR)] } {
11902 ## Msgsdir was manually set in the environment.
11903 set gitk_msgsdir $::env(GITK_MSGSDIR)
11905 ## Let's guess the prefix from argv0.
11906 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11907 set gitk_libdir [file join $gitk_prefix share gitk lib]
11908 set gitk_msgsdir [file join $gitk_libdir msgs]
11912 ## Internationalization (i18n) through msgcat and gettext. See
11913 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11914 package require msgcat
11915 namespace import ::msgcat::mc
11916 ## And eventually load the actual message catalog
11917 ::msgcat::mcload $gitk_msgsdir
11919 catch {source ~/.gitk}
11921 parsefont mainfont $mainfont
11922 eval font create mainfont [fontflags mainfont]
11923 eval font create mainfontbold [fontflags mainfont 1]
11925 parsefont textfont $textfont
11926 eval font create textfont [fontflags textfont]
11927 eval font create textfontbold [fontflags textfont 1]
11929 parsefont uifont $uifont
11930 eval font create uifont [fontflags uifont]
11936 # check that we can find a .git directory somewhere...
11937 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
11938 show_error {} . [mc "Cannot find a git repository here."]
11943 set selectheadid {}
11946 set cmdline_files {}
11948 set revtreeargscmd {}
11949 foreach arg $argv {
11950 switch -glob -- $arg {
11953 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11956 "--select-commit=*" {
11957 set selecthead [string range $arg 16 end]
11960 set revtreeargscmd [string range $arg 10 end]
11963 lappend revtreeargs $arg
11969 if {$selecthead eq "HEAD"} {
11973 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11974 # no -- on command line, but some arguments (other than --argscmd)
11976 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11977 set cmdline_files [split $f "\n"]
11978 set n [llength $cmdline_files]
11979 set revtreeargs [lrange $revtreeargs 0 end-$n]
11980 # Unfortunately git rev-parse doesn't produce an error when
11981 # something is both a revision and a filename. To be consistent
11982 # with git log and git rev-list, check revtreeargs for filenames.
11983 foreach arg $revtreeargs {
11984 if {[file exists $arg]} {
11985 show_error {} . [mc "Ambiguous argument '%s': both revision\
11986 and filename" $arg]
11991 # unfortunately we get both stdout and stderr in $err,
11992 # so look for "fatal:".
11993 set i [string first "fatal:" $err]
11995 set err [string range $err [expr {$i + 6}] end]
11997 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12002 set nullid "0000000000000000000000000000000000000000"
12003 set nullid2 "0000000000000000000000000000000000000001"
12004 set nullfile "/dev/null"
12006 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12007 if {![info exists have_ttk]} {
12008 set have_ttk [llength [info commands ::ttk::style]]
12010 set use_ttk [expr {$have_ttk && $want_ttk}]
12011 set NS [expr {$use_ttk ? "ttk" : ""}]
12013 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12016 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12017 set show_notes "--show-notes"
12027 set highlight_paths {}
12029 set searchdirn -forwards
12032 set diffelide {0 0}
12033 set markingmatches 0
12034 set linkentercount 0
12035 set need_redisplay 0
12042 set selectedhlview [mc "None"]
12043 set highlight_related [mc "None"]
12044 set highlight_files {}
12045 set viewfiles(0) {}
12048 set viewargscmd(0) {}
12050 set selectedline {}
12058 set hasworktree [hasworktree]
12060 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12061 set cdup [exec git rev-parse --show-cdup]
12063 set worktree [exec git rev-parse --show-toplevel]
12067 image create photo gitlogo -width 16 -height 16
12069 image create photo gitlogominus -width 4 -height 2
12070 gitlogominus put #C00000 -to 0 0 4 2
12071 gitlogo copy gitlogominus -to 1 5
12072 gitlogo copy gitlogominus -to 6 5
12073 gitlogo copy gitlogominus -to 11 5
12074 image delete gitlogominus
12076 image create photo gitlogoplus -width 4 -height 4
12077 gitlogoplus put #008000 -to 1 0 3 4
12078 gitlogoplus put #008000 -to 0 1 4 3
12079 gitlogo copy gitlogoplus -to 1 9
12080 gitlogo copy gitlogoplus -to 6 9
12081 gitlogo copy gitlogoplus -to 11 9
12082 image delete gitlogoplus
12084 image create photo gitlogo32 -width 32 -height 32
12085 gitlogo32 copy gitlogo -zoom 2 2
12087 wm iconphoto . -default gitlogo gitlogo32
12089 # wait for the window to become visible
12090 tkwait visibility .
12091 wm title . "$appname: [reponame]"
12095 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12096 # create a view for the files/dirs specified on the command line
12100 set viewname(1) [mc "Command line"]
12101 set viewfiles(1) $cmdline_files
12102 set viewargs(1) $revtreeargs
12103 set viewargscmd(1) $revtreeargscmd
12107 .bar.view entryconf [mca "Edit view..."] -state normal
12108 .bar.view entryconf [mca "Delete view"] -state normal
12111 if {[info exists permviews]} {
12112 foreach v $permviews {
12115 set viewname($n) [lindex $v 0]
12116 set viewfiles($n) [lindex $v 1]
12117 set viewargs($n) [lindex $v 2]
12118 set viewargscmd($n) [lindex $v 3]
12124 if {[tk windowingsystem] eq "win32"} {
12132 # indent-tabs-mode: t