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 file rename -force "~/.gitk-new" "~/.gitk"
2833 proc resizeclistpanes {win w} {
2834 global oldwidth use_ttk
2835 if {[info exists oldwidth($win)]} {
2837 set s0 [$win sashpos 0]
2838 set s1 [$win sashpos 1]
2840 set s0 [$win sash coord 0]
2841 set s1 [$win sash coord 1]
2844 set sash0 [expr {int($w/2 - 2)}]
2845 set sash1 [expr {int($w*5/6 - 2)}]
2847 set factor [expr {1.0 * $w / $oldwidth($win)}]
2848 set sash0 [expr {int($factor * [lindex $s0 0])}]
2849 set sash1 [expr {int($factor * [lindex $s1 0])}]
2853 if {$sash1 < $sash0 + 20} {
2854 set sash1 [expr {$sash0 + 20}]
2856 if {$sash1 > $w - 10} {
2857 set sash1 [expr {$w - 10}]
2858 if {$sash0 > $sash1 - 20} {
2859 set sash0 [expr {$sash1 - 20}]
2864 $win sashpos 0 $sash0
2865 $win sashpos 1 $sash1
2867 $win sash place 0 $sash0 [lindex $s0 1]
2868 $win sash place 1 $sash1 [lindex $s1 1]
2871 set oldwidth($win) $w
2874 proc resizecdetpanes {win w} {
2875 global oldwidth use_ttk
2876 if {[info exists oldwidth($win)]} {
2878 set s0 [$win sashpos 0]
2880 set s0 [$win sash coord 0]
2883 set sash0 [expr {int($w*3/4 - 2)}]
2885 set factor [expr {1.0 * $w / $oldwidth($win)}]
2886 set sash0 [expr {int($factor * [lindex $s0 0])}]
2890 if {$sash0 > $w - 15} {
2891 set sash0 [expr {$w - 15}]
2895 $win sashpos 0 $sash0
2897 $win sash place 0 $sash0 [lindex $s0 1]
2900 set oldwidth($win) $w
2903 proc allcanvs args {
2904 global canv canv2 canv3
2910 proc bindall {event action} {
2911 global canv canv2 canv3
2912 bind $canv $event $action
2913 bind $canv2 $event $action
2914 bind $canv3 $event $action
2920 if {[winfo exists $w]} {
2925 wm title $w [mc "About gitk"]
2927 message $w.m -text [mc "
2928 Gitk - a commit viewer for git
2930 Copyright \u00a9 2005-2011 Paul Mackerras
2932 Use and redistribute under the terms of the GNU General Public License"] \
2933 -justify center -aspect 400 -border 2 -bg white -relief groove
2934 pack $w.m -side top -fill x -padx 2 -pady 2
2935 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2936 pack $w.ok -side bottom
2937 bind $w <Visibility> "focus $w.ok"
2938 bind $w <Key-Escape> "destroy $w"
2939 bind $w <Key-Return> "destroy $w"
2940 tk::PlaceWindow $w widget .
2946 if {[winfo exists $w]} {
2950 if {[tk windowingsystem] eq {aqua}} {
2956 wm title $w [mc "Gitk key bindings"]
2958 message $w.m -text "
2959 [mc "Gitk key bindings:"]
2961 [mc "<%s-Q> Quit" $M1T]
2962 [mc "<%s-W> Close window" $M1T]
2963 [mc "<Home> Move to first commit"]
2964 [mc "<End> Move to last commit"]
2965 [mc "<Up>, p, k Move up one commit"]
2966 [mc "<Down>, n, j Move down one commit"]
2967 [mc "<Left>, z, h Go back in history list"]
2968 [mc "<Right>, x, l Go forward in history list"]
2969 [mc "<PageUp> Move up one page in commit list"]
2970 [mc "<PageDown> Move down one page in commit list"]
2971 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2972 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2973 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2974 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2975 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2976 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2977 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2978 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2979 [mc "<Delete>, b Scroll diff view up one page"]
2980 [mc "<Backspace> Scroll diff view up one page"]
2981 [mc "<Space> Scroll diff view down one page"]
2982 [mc "u Scroll diff view up 18 lines"]
2983 [mc "d Scroll diff view down 18 lines"]
2984 [mc "<%s-F> Find" $M1T]
2985 [mc "<%s-G> Move to next find hit" $M1T]
2986 [mc "<Return> Move to next find hit"]
2987 [mc "/ Focus the search box"]
2988 [mc "? Move to previous find hit"]
2989 [mc "f Scroll diff view to next file"]
2990 [mc "<%s-S> Search for next hit in diff view" $M1T]
2991 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2992 [mc "<%s-KP+> Increase font size" $M1T]
2993 [mc "<%s-plus> Increase font size" $M1T]
2994 [mc "<%s-KP-> Decrease font size" $M1T]
2995 [mc "<%s-minus> Decrease font size" $M1T]
2998 -justify left -bg white -border 2 -relief groove
2999 pack $w.m -side top -fill both -padx 2 -pady 2
3000 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
3001 bind $w <Key-Escape> [list destroy $w]
3002 pack $w.ok -side bottom
3003 bind $w <Visibility> "focus $w.ok"
3004 bind $w <Key-Escape> "destroy $w"
3005 bind $w <Key-Return> "destroy $w"
3008 # Procedures for manipulating the file list window at the
3009 # bottom right of the overall window.
3011 proc treeview {w l openlevs} {
3012 global treecontents treediropen treeheight treeparent treeindex
3022 set treecontents() {}
3023 $w conf -state normal
3025 while {[string range $f 0 $prefixend] ne $prefix} {
3026 if {$lev <= $openlevs} {
3027 $w mark set e:$treeindex($prefix) "end -1c"
3028 $w mark gravity e:$treeindex($prefix) left
3030 set treeheight($prefix) $ht
3031 incr ht [lindex $htstack end]
3032 set htstack [lreplace $htstack end end]
3033 set prefixend [lindex $prefendstack end]
3034 set prefendstack [lreplace $prefendstack end end]
3035 set prefix [string range $prefix 0 $prefixend]
3038 set tail [string range $f [expr {$prefixend+1}] end]
3039 while {[set slash [string first "/" $tail]] >= 0} {
3042 lappend prefendstack $prefixend
3043 incr prefixend [expr {$slash + 1}]
3044 set d [string range $tail 0 $slash]
3045 lappend treecontents($prefix) $d
3046 set oldprefix $prefix
3048 set treecontents($prefix) {}
3049 set treeindex($prefix) [incr ix]
3050 set treeparent($prefix) $oldprefix
3051 set tail [string range $tail [expr {$slash+1}] end]
3052 if {$lev <= $openlevs} {
3054 set treediropen($prefix) [expr {$lev < $openlevs}]
3055 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3056 $w mark set d:$ix "end -1c"
3057 $w mark gravity d:$ix left
3059 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3061 $w image create end -align center -image $bm -padx 1 \
3063 $w insert end $d [highlight_tag $prefix]
3064 $w mark set s:$ix "end -1c"
3065 $w mark gravity s:$ix left
3070 if {$lev <= $openlevs} {
3073 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3075 $w insert end $tail [highlight_tag $f]
3077 lappend treecontents($prefix) $tail
3080 while {$htstack ne {}} {
3081 set treeheight($prefix) $ht
3082 incr ht [lindex $htstack end]
3083 set htstack [lreplace $htstack end end]
3084 set prefixend [lindex $prefendstack end]
3085 set prefendstack [lreplace $prefendstack end end]
3086 set prefix [string range $prefix 0 $prefixend]
3088 $w conf -state disabled
3091 proc linetoelt {l} {
3092 global treeheight treecontents
3097 foreach e $treecontents($prefix) {
3102 if {[string index $e end] eq "/"} {
3103 set n $treeheight($prefix$e)
3115 proc highlight_tree {y prefix} {
3116 global treeheight treecontents cflist
3118 foreach e $treecontents($prefix) {
3120 if {[highlight_tag $path] ne {}} {
3121 $cflist tag add bold $y.0 "$y.0 lineend"
3124 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3125 set y [highlight_tree $y $path]
3131 proc treeclosedir {w dir} {
3132 global treediropen treeheight treeparent treeindex
3134 set ix $treeindex($dir)
3135 $w conf -state normal
3136 $w delete s:$ix e:$ix
3137 set treediropen($dir) 0
3138 $w image configure a:$ix -image tri-rt
3139 $w conf -state disabled
3140 set n [expr {1 - $treeheight($dir)}]
3141 while {$dir ne {}} {
3142 incr treeheight($dir) $n
3143 set dir $treeparent($dir)
3147 proc treeopendir {w dir} {
3148 global treediropen treeheight treeparent treecontents treeindex
3150 set ix $treeindex($dir)
3151 $w conf -state normal
3152 $w image configure a:$ix -image tri-dn
3153 $w mark set e:$ix s:$ix
3154 $w mark gravity e:$ix right
3157 set n [llength $treecontents($dir)]
3158 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3161 incr treeheight($x) $n
3163 foreach e $treecontents($dir) {
3165 if {[string index $e end] eq "/"} {
3166 set iy $treeindex($de)
3167 $w mark set d:$iy e:$ix
3168 $w mark gravity d:$iy left
3169 $w insert e:$ix $str
3170 set treediropen($de) 0
3171 $w image create e:$ix -align center -image tri-rt -padx 1 \
3173 $w insert e:$ix $e [highlight_tag $de]
3174 $w mark set s:$iy e:$ix
3175 $w mark gravity s:$iy left
3176 set treeheight($de) 1
3178 $w insert e:$ix $str
3179 $w insert e:$ix $e [highlight_tag $de]
3182 $w mark gravity e:$ix right
3183 $w conf -state disabled
3184 set treediropen($dir) 1
3185 set top [lindex [split [$w index @0,0] .] 0]
3186 set ht [$w cget -height]
3187 set l [lindex [split [$w index s:$ix] .] 0]
3190 } elseif {$l + $n + 1 > $top + $ht} {
3191 set top [expr {$l + $n + 2 - $ht}]
3199 proc treeclick {w x y} {
3200 global treediropen cmitmode ctext cflist cflist_top
3202 if {$cmitmode ne "tree"} return
3203 if {![info exists cflist_top]} return
3204 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3205 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3206 $cflist tag add highlight $l.0 "$l.0 lineend"
3212 set e [linetoelt $l]
3213 if {[string index $e end] ne "/"} {
3215 } elseif {$treediropen($e)} {
3222 proc setfilelist {id} {
3223 global treefilelist cflist jump_to_here
3225 treeview $cflist $treefilelist($id) 0
3226 if {$jump_to_here ne {}} {
3227 set f [lindex $jump_to_here 0]
3228 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3234 image create bitmap tri-rt -background black -foreground blue -data {
3235 #define tri-rt_width 13
3236 #define tri-rt_height 13
3237 static unsigned char tri-rt_bits[] = {
3238 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3239 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3242 #define tri-rt-mask_width 13
3243 #define tri-rt-mask_height 13
3244 static unsigned char tri-rt-mask_bits[] = {
3245 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3246 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3249 image create bitmap tri-dn -background black -foreground blue -data {
3250 #define tri-dn_width 13
3251 #define tri-dn_height 13
3252 static unsigned char tri-dn_bits[] = {
3253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3254 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3257 #define tri-dn-mask_width 13
3258 #define tri-dn-mask_height 13
3259 static unsigned char tri-dn-mask_bits[] = {
3260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3261 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3265 image create bitmap reficon-T -background black -foreground yellow -data {
3266 #define tagicon_width 13
3267 #define tagicon_height 9
3268 static unsigned char tagicon_bits[] = {
3269 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3270 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3272 #define tagicon-mask_width 13
3273 #define tagicon-mask_height 9
3274 static unsigned char tagicon-mask_bits[] = {
3275 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3276 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3279 #define headicon_width 13
3280 #define headicon_height 9
3281 static unsigned char headicon_bits[] = {
3282 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3283 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3286 #define headicon-mask_width 13
3287 #define headicon-mask_height 9
3288 static unsigned char headicon-mask_bits[] = {
3289 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3290 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3292 image create bitmap reficon-H -background black -foreground green \
3293 -data $rectdata -maskdata $rectmask
3294 image create bitmap reficon-o -background black -foreground "#ddddff" \
3295 -data $rectdata -maskdata $rectmask
3297 proc init_flist {first} {
3298 global cflist cflist_top difffilestart
3300 $cflist conf -state normal
3301 $cflist delete 0.0 end
3303 $cflist insert end $first
3305 $cflist tag add highlight 1.0 "1.0 lineend"
3307 catch {unset cflist_top}
3309 $cflist conf -state disabled
3310 set difffilestart {}
3313 proc highlight_tag {f} {
3314 global highlight_paths
3316 foreach p $highlight_paths {
3317 if {[string match $p $f]} {
3324 proc highlight_filelist {} {
3325 global cmitmode cflist
3327 $cflist conf -state normal
3328 if {$cmitmode ne "tree"} {
3329 set end [lindex [split [$cflist index end] .] 0]
3330 for {set l 2} {$l < $end} {incr l} {
3331 set line [$cflist get $l.0 "$l.0 lineend"]
3332 if {[highlight_tag $line] ne {}} {
3333 $cflist tag add bold $l.0 "$l.0 lineend"
3339 $cflist conf -state disabled
3342 proc unhighlight_filelist {} {
3345 $cflist conf -state normal
3346 $cflist tag remove bold 1.0 end
3347 $cflist conf -state disabled
3350 proc add_flist {fl} {
3353 $cflist conf -state normal
3355 $cflist insert end "\n"
3356 $cflist insert end $f [highlight_tag $f]
3358 $cflist conf -state disabled
3361 proc sel_flist {w x y} {
3362 global ctext difffilestart cflist cflist_top cmitmode
3364 if {$cmitmode eq "tree"} return
3365 if {![info exists cflist_top]} return
3366 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3367 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3368 $cflist tag add highlight $l.0 "$l.0 lineend"
3373 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3375 suppress_highlighting_file_for_current_scrollpos
3378 proc pop_flist_menu {w X Y x y} {
3379 global ctext cflist cmitmode flist_menu flist_menu_file
3380 global treediffs diffids
3383 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3385 if {$cmitmode eq "tree"} {
3386 set e [linetoelt $l]
3387 if {[string index $e end] eq "/"} return
3389 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3391 set flist_menu_file $e
3392 set xdiffstate "normal"
3393 if {$cmitmode eq "tree"} {
3394 set xdiffstate "disabled"
3396 # Disable "External diff" item in tree mode
3397 $flist_menu entryconf 2 -state $xdiffstate
3398 tk_popup $flist_menu $X $Y
3401 proc find_ctext_fileinfo {line} {
3402 global ctext_file_names ctext_file_lines
3404 set ok [bsearch $ctext_file_lines $line]
3405 set tline [lindex $ctext_file_lines $ok]
3407 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3410 return [list [lindex $ctext_file_names $ok] $tline]
3414 proc pop_diff_menu {w X Y x y} {
3415 global ctext diff_menu flist_menu_file
3416 global diff_menu_txtpos diff_menu_line
3417 global diff_menu_filebase
3419 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3420 set diff_menu_line [lindex $diff_menu_txtpos 0]
3421 # don't pop up the menu on hunk-separator or file-separator lines
3422 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3426 set f [find_ctext_fileinfo $diff_menu_line]
3427 if {$f eq {}} return
3428 set flist_menu_file [lindex $f 0]
3429 set diff_menu_filebase [lindex $f 1]
3430 tk_popup $diff_menu $X $Y
3433 proc flist_hl {only} {
3434 global flist_menu_file findstring gdttype
3436 set x [shellquote $flist_menu_file]
3437 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3440 append findstring " " $x
3442 set gdttype [mc "touching paths:"]
3445 proc gitknewtmpdir {} {
3446 global diffnum gitktmpdir gitdir
3448 if {![info exists gitktmpdir]} {
3449 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3450 if {[catch {file mkdir $gitktmpdir} err]} {
3451 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3458 set diffdir [file join $gitktmpdir $diffnum]
3459 if {[catch {file mkdir $diffdir} err]} {
3460 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3466 proc save_file_from_commit {filename output what} {
3469 if {[catch {exec git show $filename -- > $output} err]} {
3470 if {[string match "fatal: bad revision *" $err]} {
3473 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3479 proc external_diff_get_one_file {diffid filename diffdir} {
3480 global nullid nullid2 nullfile
3483 if {$diffid == $nullid} {
3484 set difffile [file join $worktree $filename]
3485 if {[file exists $difffile]} {
3490 if {$diffid == $nullid2} {
3491 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3492 return [save_file_from_commit :$filename $difffile index]
3494 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3495 return [save_file_from_commit $diffid:$filename $difffile \
3499 proc external_diff {} {
3500 global nullid nullid2
3501 global flist_menu_file
3505 if {[llength $diffids] == 1} {
3506 # no reference commit given
3507 set diffidto [lindex $diffids 0]
3508 if {$diffidto eq $nullid} {
3509 # diffing working copy with index
3510 set diffidfrom $nullid2
3511 } elseif {$diffidto eq $nullid2} {
3512 # diffing index with HEAD
3513 set diffidfrom "HEAD"
3515 # use first parent commit
3516 global parentlist selectedline
3517 set diffidfrom [lindex $parentlist $selectedline 0]
3520 set diffidfrom [lindex $diffids 0]
3521 set diffidto [lindex $diffids 1]
3524 # make sure that several diffs wont collide
3525 set diffdir [gitknewtmpdir]
3526 if {$diffdir eq {}} return
3528 # gather files to diff
3529 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3530 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3532 if {$difffromfile ne {} && $difftofile ne {}} {
3533 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3534 if {[catch {set fl [open |$cmd r]} err]} {
3535 file delete -force $diffdir
3536 error_popup "$extdifftool: [mc "command failed:"] $err"
3538 fconfigure $fl -blocking 0
3539 filerun $fl [list delete_at_eof $fl $diffdir]
3544 proc find_hunk_blamespec {base line} {
3547 # Find and parse the hunk header
3548 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3549 if {$s_lix eq {}} return
3551 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3552 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3553 s_line old_specs osz osz1 new_line nsz]} {
3557 # base lines for the parents
3558 set base_lines [list $new_line]
3559 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3560 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3561 old_spec old_line osz]} {
3564 lappend base_lines $old_line
3567 # Now scan the lines to determine offset within the hunk
3568 set max_parent [expr {[llength $base_lines]-2}]
3570 set s_lno [lindex [split $s_lix "."] 0]
3572 # Determine if the line is removed
3573 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3574 if {[string match {[-+ ]*} $chunk]} {
3575 set removed_idx [string first "-" $chunk]
3576 # Choose a parent index
3577 if {$removed_idx >= 0} {
3578 set parent $removed_idx
3580 set unchanged_idx [string first " " $chunk]
3581 if {$unchanged_idx >= 0} {
3582 set parent $unchanged_idx
3584 # blame the current commit
3588 # then count other lines that belong to it
3589 for {set i $line} {[incr i -1] > $s_lno} {} {
3590 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3591 # Determine if the line is removed
3592 set removed_idx [string first "-" $chunk]
3594 set code [string index $chunk $parent]
3595 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3599 if {$removed_idx < 0} {
3609 incr dline [lindex $base_lines $parent]
3610 return [list $parent $dline]
3613 proc external_blame_diff {} {
3614 global currentid cmitmode
3615 global diff_menu_txtpos diff_menu_line
3616 global diff_menu_filebase flist_menu_file
3618 if {$cmitmode eq "tree"} {
3620 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3622 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3624 set parent_idx [lindex $hinfo 0]
3625 set line [lindex $hinfo 1]
3632 external_blame $parent_idx $line
3635 # Find the SHA1 ID of the blob for file $fname in the index
3637 proc index_sha1 {fname} {
3638 set f [open [list | git ls-files -s $fname] r]
3639 while {[gets $f line] >= 0} {
3640 set info [lindex [split $line "\t"] 0]
3641 set stage [lindex $info 2]
3642 if {$stage eq "0" || $stage eq "2"} {
3644 return [lindex $info 1]
3651 # Turn an absolute path into one relative to the current directory
3652 proc make_relative {f} {
3653 if {[file pathtype $f] eq "relative"} {
3656 set elts [file split $f]
3657 set here [file split [pwd]]
3662 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3669 set elts [concat $res [lrange $elts $ei end]]
3670 return [eval file join $elts]
3673 proc external_blame {parent_idx {line {}}} {
3674 global flist_menu_file cdup
3675 global nullid nullid2
3676 global parentlist selectedline currentid
3678 if {$parent_idx > 0} {
3679 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3681 set base_commit $currentid
3684 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3685 error_popup [mc "No such commit"]
3689 set cmdline [list git gui blame]
3690 if {$line ne {} && $line > 1} {
3691 lappend cmdline "--line=$line"
3693 set f [file join $cdup $flist_menu_file]
3694 # Unfortunately it seems git gui blame doesn't like
3695 # being given an absolute path...
3696 set f [make_relative $f]
3697 lappend cmdline $base_commit $f
3698 if {[catch {eval exec $cmdline &} err]} {
3699 error_popup "[mc "git gui blame: command failed:"] $err"
3703 proc show_line_source {} {
3704 global cmitmode currentid parents curview blamestuff blameinst
3705 global diff_menu_line diff_menu_filebase flist_menu_file
3706 global nullid nullid2 gitdir cdup
3709 if {$cmitmode eq "tree"} {
3711 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3713 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3714 if {$h eq {}} return
3715 set pi [lindex $h 0]
3717 mark_ctext_line $diff_menu_line
3721 if {$currentid eq $nullid} {
3723 # must be a merge in progress...
3725 # get the last line from .git/MERGE_HEAD
3726 set f [open [file join $gitdir MERGE_HEAD] r]
3727 set id [lindex [split [read $f] "\n"] end-1]
3730 error_popup [mc "Couldn't read merge head: %s" $err]
3733 } elseif {$parents($curview,$currentid) eq $nullid2} {
3734 # need to do the blame from the index
3736 set from_index [index_sha1 $flist_menu_file]
3738 error_popup [mc "Error reading index: %s" $err]
3742 set id $parents($curview,$currentid)
3745 set id [lindex $parents($curview,$currentid) $pi]
3747 set line [lindex $h 1]
3750 if {$from_index ne {}} {
3751 lappend blameargs | git cat-file blob $from_index
3753 lappend blameargs | git blame -p -L$line,+1
3754 if {$from_index ne {}} {
3755 lappend blameargs --contents -
3757 lappend blameargs $id
3759 lappend blameargs -- [file join $cdup $flist_menu_file]
3761 set f [open $blameargs r]
3763 error_popup [mc "Couldn't start git blame: %s" $err]
3766 nowbusy blaming [mc "Searching"]
3767 fconfigure $f -blocking 0
3768 set i [reg_instance $f]
3769 set blamestuff($i) {}
3771 filerun $f [list read_line_source $f $i]
3774 proc stopblaming {} {
3777 if {[info exists blameinst]} {
3778 stop_instance $blameinst
3784 proc read_line_source {fd inst} {
3785 global blamestuff curview commfd blameinst nullid nullid2
3787 while {[gets $fd line] >= 0} {
3788 lappend blamestuff($inst) $line
3796 fconfigure $fd -blocking 1
3797 if {[catch {close $fd} err]} {
3798 error_popup [mc "Error running git blame: %s" $err]
3803 set line [split [lindex $blamestuff($inst) 0] " "]
3804 set id [lindex $line 0]
3805 set lnum [lindex $line 1]
3806 if {[string length $id] == 40 && [string is xdigit $id] &&
3807 [string is digit -strict $lnum]} {
3808 # look for "filename" line
3809 foreach l $blamestuff($inst) {
3810 if {[string match "filename *" $l]} {
3811 set fname [string range $l 9 end]
3817 # all looks good, select it
3818 if {$id eq $nullid} {
3819 # blame uses all-zeroes to mean not committed,
3820 # which would mean a change in the index
3823 if {[commitinview $id $curview]} {
3824 selectline [rowofcommit $id] 1 [list $fname $lnum]
3826 error_popup [mc "That line comes from commit %s, \
3827 which is not in this view" [shortids $id]]
3830 puts "oops couldn't parse git blame output"
3835 # delete $dir when we see eof on $f (presumably because the child has exited)
3836 proc delete_at_eof {f dir} {
3837 while {[gets $f line] >= 0} {}
3839 if {[catch {close $f} err]} {
3840 error_popup "[mc "External diff viewer failed:"] $err"
3842 file delete -force $dir
3848 # Functions for adding and removing shell-type quoting
3850 proc shellquote {str} {
3851 if {![string match "*\['\"\\ \t]*" $str]} {
3854 if {![string match "*\['\"\\]*" $str]} {
3857 if {![string match "*'*" $str]} {
3860 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3863 proc shellarglist {l} {
3869 append str [shellquote $a]
3874 proc shelldequote {str} {
3879 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3880 append ret [string range $str $used end]
3881 set used [string length $str]
3884 set first [lindex $first 0]
3885 set ch [string index $str $first]
3886 if {$first > $used} {
3887 append ret [string range $str $used [expr {$first - 1}]]
3890 if {$ch eq " " || $ch eq "\t"} break
3893 set first [string first "'" $str $used]
3895 error "unmatched single-quote"
3897 append ret [string range $str $used [expr {$first - 1}]]
3902 if {$used >= [string length $str]} {
3903 error "trailing backslash"
3905 append ret [string index $str $used]
3910 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3911 error "unmatched double-quote"
3913 set first [lindex $first 0]
3914 set ch [string index $str $first]
3915 if {$first > $used} {
3916 append ret [string range $str $used [expr {$first - 1}]]
3919 if {$ch eq "\""} break
3921 append ret [string index $str $used]
3925 return [list $used $ret]
3928 proc shellsplit {str} {
3931 set str [string trimleft $str]
3932 if {$str eq {}} break
3933 set dq [shelldequote $str]
3934 set n [lindex $dq 0]
3935 set word [lindex $dq 1]
3936 set str [string range $str $n end]
3942 # Code to implement multiple views
3944 proc newview {ishighlight} {
3945 global nextviewnum newviewname newishighlight
3946 global revtreeargs viewargscmd newviewopts curview
3948 set newishighlight $ishighlight
3950 if {[winfo exists $top]} {
3954 decode_view_opts $nextviewnum $revtreeargs
3955 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3956 set newviewopts($nextviewnum,perm) 0
3957 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3958 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3961 set known_view_options {
3962 {perm b . {} {mc "Remember this view"}}
3963 {reflabel l + {} {mc "References (space separated list):"}}
3964 {refs t15 .. {} {mc "Branches & tags:"}}
3965 {allrefs b *. "--all" {mc "All refs"}}
3966 {branches b . "--branches" {mc "All (local) branches"}}
3967 {tags b . "--tags" {mc "All tags"}}
3968 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3969 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3970 {author t15 .. "--author=*" {mc "Author:"}}
3971 {committer t15 . "--committer=*" {mc "Committer:"}}
3972 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3973 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3974 {changes_l l + {} {mc "Changes to Files:"}}
3975 {pickaxe_s r0 . {} {mc "Fixed String"}}
3976 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3977 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3978 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3979 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3980 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3981 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3982 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3983 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3984 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3985 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3986 {lright b . "--left-right" {mc "Mark branch sides"}}
3987 {first b . "--first-parent" {mc "Limit to first parent"}}
3988 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3989 {args t50 *. {} {mc "Additional arguments to git log:"}}
3990 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3991 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
3994 # Convert $newviewopts($n, ...) into args for git log.
3995 proc encode_view_opts {n} {
3996 global known_view_options newviewopts
3999 foreach opt $known_view_options {
4000 set patterns [lindex $opt 3]
4001 if {$patterns eq {}} continue
4002 set pattern [lindex $patterns 0]
4004 if {[lindex $opt 1] eq "b"} {
4005 set val $newviewopts($n,[lindex $opt 0])
4007 lappend rargs $pattern
4009 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4010 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4011 set val $newviewopts($n,$button_id)
4012 if {$val eq $value} {
4013 lappend rargs $pattern
4016 set val $newviewopts($n,[lindex $opt 0])
4017 set val [string trim $val]
4019 set pfix [string range $pattern 0 end-1]
4020 lappend rargs $pfix$val
4024 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4025 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4028 # Fill $newviewopts($n, ...) based on args for git log.
4029 proc decode_view_opts {n view_args} {
4030 global known_view_options newviewopts
4032 foreach opt $known_view_options {
4033 set id [lindex $opt 0]
4034 if {[lindex $opt 1] eq "b"} {
4037 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4039 regexp {^(.*_)} $id uselessvar id
4045 set newviewopts($n,$id) $val
4049 foreach arg $view_args {
4050 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4051 && ![info exists found(limit)]} {
4052 set newviewopts($n,limit) $cnt
4057 foreach opt $known_view_options {
4058 set id [lindex $opt 0]
4059 if {[info exists found($id)]} continue
4060 foreach pattern [lindex $opt 3] {
4061 if {![string match $pattern $arg]} continue
4062 if {[lindex $opt 1] eq "b"} {
4065 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4067 regexp {^(.*_)} $id uselessvar id
4071 set size [string length $pattern]
4072 set val [string range $arg [expr {$size-1}] end]
4074 set newviewopts($n,$id) $val
4078 if {[info exists val]} break
4080 if {[info exists val]} continue
4081 if {[regexp {^-} $arg]} {
4084 lappend refargs $arg
4087 set newviewopts($n,refs) [shellarglist $refargs]
4088 set newviewopts($n,args) [shellarglist $oargs]
4091 proc edit_or_newview {} {
4103 global viewname viewperm newviewname newviewopts
4104 global viewargs viewargscmd
4106 set top .gitkvedit-$curview
4107 if {[winfo exists $top]} {
4111 decode_view_opts $curview $viewargs($curview)
4112 set newviewname($curview) $viewname($curview)
4113 set newviewopts($curview,perm) $viewperm($curview)
4114 set newviewopts($curview,cmd) $viewargscmd($curview)
4115 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4118 proc vieweditor {top n title} {
4119 global newviewname newviewopts viewfiles bgcolor
4120 global known_view_options NS
4123 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4124 make_transient $top .
4127 ${NS}::frame $top.nfr
4128 ${NS}::label $top.nl -text [mc "View Name"]
4129 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4130 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4131 pack $top.nl -in $top.nfr -side left -padx {0 5}
4132 pack $top.name -in $top.nfr -side left -padx {0 25}
4138 foreach opt $known_view_options {
4139 set id [lindex $opt 0]
4140 set type [lindex $opt 1]
4141 set flags [lindex $opt 2]
4142 set title [eval [lindex $opt 4]]
4145 if {$flags eq "+" || $flags eq "*"} {
4146 set cframe $top.fr$cnt
4148 ${NS}::frame $cframe
4149 pack $cframe -in $top -fill x -pady 3 -padx 3
4150 set cexpand [expr {$flags eq "*"}]
4151 } elseif {$flags eq ".." || $flags eq "*."} {
4152 set cframe $top.fr$cnt
4154 ${NS}::frame $cframe
4155 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4156 set cexpand [expr {$flags eq "*."}]
4162 ${NS}::label $cframe.l_$id -text $title
4163 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4164 } elseif {$type eq "b"} {
4165 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4166 pack $cframe.c_$id -in $cframe -side left \
4167 -padx [list $lxpad 0] -expand $cexpand -anchor w
4168 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4169 regexp {^(.*_)} $id uselessvar button_id
4170 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4171 pack $cframe.c_$id -in $cframe -side left \
4172 -padx [list $lxpad 0] -expand $cexpand -anchor w
4173 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4174 ${NS}::label $cframe.l_$id -text $title
4175 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4176 -textvariable newviewopts($n,$id)
4177 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4178 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4179 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4180 ${NS}::label $cframe.l_$id -text $title
4181 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4182 -textvariable newviewopts($n,$id)
4183 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4184 pack $cframe.e_$id -in $cframe -side top -fill x
4185 } elseif {$type eq "path"} {
4186 ${NS}::label $top.l -text $title
4187 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4188 text $top.t -width 40 -height 5 -background $bgcolor
4189 if {[info exists viewfiles($n)]} {
4190 foreach f $viewfiles($n) {
4191 $top.t insert end $f
4192 $top.t insert end "\n"
4194 $top.t delete {end - 1c} end
4195 $top.t mark set insert 0.0
4197 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4201 ${NS}::frame $top.buts
4202 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4203 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4204 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4205 bind $top <Control-Return> [list newviewok $top $n]
4206 bind $top <F5> [list newviewok $top $n 1]
4207 bind $top <Escape> [list destroy $top]
4208 grid $top.buts.ok $top.buts.apply $top.buts.can
4209 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4210 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4211 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4212 pack $top.buts -in $top -side top -fill x
4216 proc doviewmenu {m first cmd op argv} {
4217 set nmenu [$m index end]
4218 for {set i $first} {$i <= $nmenu} {incr i} {
4219 if {[$m entrycget $i -command] eq $cmd} {
4220 eval $m $op $i $argv
4226 proc allviewmenus {n op args} {
4229 doviewmenu .bar.view 5 [list showview $n] $op $args
4230 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4233 proc newviewok {top n {apply 0}} {
4234 global nextviewnum newviewperm newviewname newishighlight
4235 global viewname viewfiles viewperm selectedview curview
4236 global viewargs viewargscmd newviewopts viewhlmenu
4239 set newargs [encode_view_opts $n]
4241 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4245 foreach f [split [$top.t get 0.0 end] "\n"] {
4246 set ft [string trim $f]
4251 if {![info exists viewfiles($n)]} {
4252 # creating a new view
4254 set viewname($n) $newviewname($n)
4255 set viewperm($n) $newviewopts($n,perm)
4256 set viewfiles($n) $files
4257 set viewargs($n) $newargs
4258 set viewargscmd($n) $newviewopts($n,cmd)
4260 if {!$newishighlight} {
4263 run addvhighlight $n
4266 # editing an existing view
4267 set viewperm($n) $newviewopts($n,perm)
4268 if {$newviewname($n) ne $viewname($n)} {
4269 set viewname($n) $newviewname($n)
4270 doviewmenu .bar.view 5 [list showview $n] \
4271 entryconf [list -label $viewname($n)]
4272 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4273 # entryconf [list -label $viewname($n) -value $viewname($n)]
4275 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4276 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4277 set viewfiles($n) $files
4278 set viewargs($n) $newargs
4279 set viewargscmd($n) $newviewopts($n,cmd)
4280 if {$curview == $n} {
4286 catch {destroy $top}
4290 global curview viewperm hlview selectedhlview
4292 if {$curview == 0} return
4293 if {[info exists hlview] && $hlview == $curview} {
4294 set selectedhlview [mc "None"]
4297 allviewmenus $curview delete
4298 set viewperm($curview) 0
4302 proc addviewmenu {n} {
4303 global viewname viewhlmenu
4305 .bar.view add radiobutton -label $viewname($n) \
4306 -command [list showview $n] -variable selectedview -value $n
4307 #$viewhlmenu add radiobutton -label $viewname($n) \
4308 # -command [list addvhighlight $n] -variable selectedhlview
4312 global curview cached_commitrow ordertok
4313 global displayorder parentlist rowidlist rowisopt rowfinal
4314 global colormap rowtextx nextcolor canvxmax
4315 global numcommits viewcomplete
4316 global selectedline currentid canv canvy0
4318 global pending_select mainheadid
4321 global hlview selectedhlview commitinterest
4323 if {$n == $curview} return
4325 set ymax [lindex [$canv cget -scrollregion] 3]
4326 set span [$canv yview]
4327 set ytop [expr {[lindex $span 0] * $ymax}]
4328 set ybot [expr {[lindex $span 1] * $ymax}]
4329 set yscreen [expr {($ybot - $ytop) / 2}]
4330 if {$selectedline ne {}} {
4331 set selid $currentid
4332 set y [yc $selectedline]
4333 if {$ytop < $y && $y < $ybot} {
4334 set yscreen [expr {$y - $ytop}]
4336 } elseif {[info exists pending_select]} {
4337 set selid $pending_select
4338 unset pending_select
4342 catch {unset treediffs}
4344 if {[info exists hlview] && $hlview == $n} {
4346 set selectedhlview [mc "None"]
4348 catch {unset commitinterest}
4349 catch {unset cached_commitrow}
4350 catch {unset ordertok}
4354 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4355 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4358 if {![info exists viewcomplete($n)]} {
4368 set numcommits $commitidx($n)
4370 catch {unset colormap}
4371 catch {unset rowtextx}
4373 set canvxmax [$canv cget -width]
4379 if {$selid ne {} && [commitinview $selid $n]} {
4380 set row [rowofcommit $selid]
4381 # try to get the selected row in the same position on the screen
4382 set ymax [lindex [$canv cget -scrollregion] 3]
4383 set ytop [expr {[yc $row] - $yscreen}]
4387 set yf [expr {$ytop * 1.0 / $ymax}]
4389 allcanvs yview moveto $yf
4393 } elseif {!$viewcomplete($n)} {
4394 reset_pending_select $selid
4396 reset_pending_select {}
4398 if {[commitinview $pending_select $curview]} {
4399 selectline [rowofcommit $pending_select] 1
4401 set row [first_real_row]
4402 if {$row < $numcommits} {
4407 if {!$viewcomplete($n)} {
4408 if {$numcommits == 0} {
4409 show_status [mc "Reading commits..."]
4411 } elseif {$numcommits == 0} {
4412 show_status [mc "No commits selected"]
4416 # Stuff relating to the highlighting facility
4418 proc ishighlighted {id} {
4419 global vhighlights fhighlights nhighlights rhighlights
4421 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4422 return $nhighlights($id)
4424 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4425 return $vhighlights($id)
4427 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4428 return $fhighlights($id)
4430 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4431 return $rhighlights($id)
4436 proc bolden {id font} {
4437 global canv linehtag currentid boldids need_redisplay markedid
4439 # need_redisplay = 1 means the display is stale and about to be redrawn
4440 if {$need_redisplay} return
4442 $canv itemconf $linehtag($id) -font $font
4443 if {[info exists currentid] && $id eq $currentid} {
4445 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4446 -outline {{}} -tags secsel \
4447 -fill [$canv cget -selectbackground]]
4450 if {[info exists markedid] && $id eq $markedid} {
4455 proc bolden_name {id font} {
4456 global canv2 linentag currentid boldnameids need_redisplay
4458 if {$need_redisplay} return
4459 lappend boldnameids $id
4460 $canv2 itemconf $linentag($id) -font $font
4461 if {[info exists currentid] && $id eq $currentid} {
4462 $canv2 delete secsel
4463 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4464 -outline {{}} -tags secsel \
4465 -fill [$canv2 cget -selectbackground]]
4474 foreach id $boldids {
4475 if {![ishighlighted $id]} {
4478 lappend stillbold $id
4481 set boldids $stillbold
4484 proc addvhighlight {n} {
4485 global hlview viewcomplete curview vhl_done commitidx
4487 if {[info exists hlview]} {
4491 if {$n != $curview && ![info exists viewcomplete($n)]} {
4494 set vhl_done $commitidx($hlview)
4495 if {$vhl_done > 0} {
4500 proc delvhighlight {} {
4501 global hlview vhighlights
4503 if {![info exists hlview]} return
4505 catch {unset vhighlights}
4509 proc vhighlightmore {} {
4510 global hlview vhl_done commitidx vhighlights curview
4512 set max $commitidx($hlview)
4513 set vr [visiblerows]
4514 set r0 [lindex $vr 0]
4515 set r1 [lindex $vr 1]
4516 for {set i $vhl_done} {$i < $max} {incr i} {
4517 set id [commitonrow $i $hlview]
4518 if {[commitinview $id $curview]} {
4519 set row [rowofcommit $id]
4520 if {$r0 <= $row && $row <= $r1} {
4521 if {![highlighted $row]} {
4522 bolden $id mainfontbold
4524 set vhighlights($id) 1
4532 proc askvhighlight {row id} {
4533 global hlview vhighlights iddrawn
4535 if {[commitinview $id $hlview]} {
4536 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4537 bolden $id mainfontbold
4539 set vhighlights($id) 1
4541 set vhighlights($id) 0
4545 proc hfiles_change {} {
4546 global highlight_files filehighlight fhighlights fh_serial
4547 global highlight_paths
4549 if {[info exists filehighlight]} {
4550 # delete previous highlights
4551 catch {close $filehighlight}
4553 catch {unset fhighlights}
4555 unhighlight_filelist
4557 set highlight_paths {}
4558 after cancel do_file_hl $fh_serial
4560 if {$highlight_files ne {}} {
4561 after 300 do_file_hl $fh_serial
4565 proc gdttype_change {name ix op} {
4566 global gdttype highlight_files findstring findpattern
4569 if {$findstring ne {}} {
4570 if {$gdttype eq [mc "containing:"]} {
4571 if {$highlight_files ne {}} {
4572 set highlight_files {}
4577 if {$findpattern ne {}} {
4581 set highlight_files $findstring
4586 # enable/disable findtype/findloc menus too
4589 proc find_change {name ix op} {
4590 global gdttype findstring highlight_files
4593 if {$gdttype eq [mc "containing:"]} {
4596 if {$highlight_files ne $findstring} {
4597 set highlight_files $findstring
4604 proc findcom_change args {
4605 global nhighlights boldnameids
4606 global findpattern findtype findstring gdttype
4609 # delete previous highlights, if any
4610 foreach id $boldnameids {
4611 bolden_name $id mainfont
4614 catch {unset nhighlights}
4617 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4619 } elseif {$findtype eq [mc "Regexp"]} {
4620 set findpattern $findstring
4622 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4624 set findpattern "*$e*"
4628 proc makepatterns {l} {
4631 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4632 if {[string index $ee end] eq "/"} {
4642 proc do_file_hl {serial} {
4643 global highlight_files filehighlight highlight_paths gdttype fhl_list
4644 global cdup findtype
4646 if {$gdttype eq [mc "touching paths:"]} {
4647 # If "exact" match then convert backslashes to forward slashes.
4648 # Most useful to support Windows-flavoured file paths.
4649 if {$findtype eq [mc "Exact"]} {
4650 set highlight_files [string map {"\\" "/"} $highlight_files]
4652 if {[catch {set paths [shellsplit $highlight_files]}]} return
4653 set highlight_paths [makepatterns $paths]
4655 set relative_paths {}
4656 foreach path $paths {
4657 lappend relative_paths [file join $cdup $path]
4659 set gdtargs [concat -- $relative_paths]
4660 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4661 set gdtargs [list "-S$highlight_files"]
4662 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4663 set gdtargs [list "-G$highlight_files"]
4665 # must be "containing:", i.e. we're searching commit info
4668 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4669 set filehighlight [open $cmd r+]
4670 fconfigure $filehighlight -blocking 0
4671 filerun $filehighlight readfhighlight
4677 proc flushhighlights {} {
4678 global filehighlight fhl_list
4680 if {[info exists filehighlight]} {
4682 puts $filehighlight ""
4683 flush $filehighlight
4687 proc askfilehighlight {row id} {
4688 global filehighlight fhighlights fhl_list
4690 lappend fhl_list $id
4691 set fhighlights($id) -1
4692 puts $filehighlight $id
4695 proc readfhighlight {} {
4696 global filehighlight fhighlights curview iddrawn
4697 global fhl_list find_dirn
4699 if {![info exists filehighlight]} {
4703 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4704 set line [string trim $line]
4705 set i [lsearch -exact $fhl_list $line]
4706 if {$i < 0} continue
4707 for {set j 0} {$j < $i} {incr j} {
4708 set id [lindex $fhl_list $j]
4709 set fhighlights($id) 0
4711 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4712 if {$line eq {}} continue
4713 if {![commitinview $line $curview]} continue
4714 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4715 bolden $line mainfontbold
4717 set fhighlights($line) 1
4719 if {[eof $filehighlight]} {
4721 puts "oops, git diff-tree died"
4722 catch {close $filehighlight}
4726 if {[info exists find_dirn]} {
4732 proc doesmatch {f} {
4733 global findtype findpattern
4735 if {$findtype eq [mc "Regexp"]} {
4736 return [regexp $findpattern $f]
4737 } elseif {$findtype eq [mc "IgnCase"]} {
4738 return [string match -nocase $findpattern $f]
4740 return [string match $findpattern $f]
4744 proc askfindhighlight {row id} {
4745 global nhighlights commitinfo iddrawn
4747 global markingmatches
4749 if {![info exists commitinfo($id)]} {
4752 set info $commitinfo($id)
4754 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4755 foreach f $info ty $fldtypes {
4756 if {$ty eq ""} continue
4757 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4759 if {$ty eq [mc "Author"]} {
4766 if {$isbold && [info exists iddrawn($id)]} {
4767 if {![ishighlighted $id]} {
4768 bolden $id mainfontbold
4770 bolden_name $id mainfontbold
4773 if {$markingmatches} {
4774 markrowmatches $row $id
4777 set nhighlights($id) $isbold
4780 proc markrowmatches {row id} {
4781 global canv canv2 linehtag linentag commitinfo findloc
4783 set headline [lindex $commitinfo($id) 0]
4784 set author [lindex $commitinfo($id) 1]
4785 $canv delete match$row
4786 $canv2 delete match$row
4787 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4788 set m [findmatches $headline]
4790 markmatches $canv $row $headline $linehtag($id) $m \
4791 [$canv itemcget $linehtag($id) -font] $row
4794 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4795 set m [findmatches $author]
4797 markmatches $canv2 $row $author $linentag($id) $m \
4798 [$canv2 itemcget $linentag($id) -font] $row
4803 proc vrel_change {name ix op} {
4804 global highlight_related
4807 if {$highlight_related ne [mc "None"]} {
4812 # prepare for testing whether commits are descendents or ancestors of a
4813 proc rhighlight_sel {a} {
4814 global descendent desc_todo ancestor anc_todo
4815 global highlight_related
4817 catch {unset descendent}
4818 set desc_todo [list $a]
4819 catch {unset ancestor}
4820 set anc_todo [list $a]
4821 if {$highlight_related ne [mc "None"]} {
4827 proc rhighlight_none {} {
4830 catch {unset rhighlights}
4834 proc is_descendent {a} {
4835 global curview children descendent desc_todo
4838 set la [rowofcommit $a]
4842 for {set i 0} {$i < [llength $todo]} {incr i} {
4843 set do [lindex $todo $i]
4844 if {[rowofcommit $do] < $la} {
4845 lappend leftover $do
4848 foreach nk $children($v,$do) {
4849 if {![info exists descendent($nk)]} {
4850 set descendent($nk) 1
4858 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4862 set descendent($a) 0
4863 set desc_todo $leftover
4866 proc is_ancestor {a} {
4867 global curview parents ancestor anc_todo
4870 set la [rowofcommit $a]
4874 for {set i 0} {$i < [llength $todo]} {incr i} {
4875 set do [lindex $todo $i]
4876 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4877 lappend leftover $do
4880 foreach np $parents($v,$do) {
4881 if {![info exists ancestor($np)]} {
4890 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4895 set anc_todo $leftover
4898 proc askrelhighlight {row id} {
4899 global descendent highlight_related iddrawn rhighlights
4900 global selectedline ancestor
4902 if {$selectedline eq {}} return
4904 if {$highlight_related eq [mc "Descendant"] ||
4905 $highlight_related eq [mc "Not descendant"]} {
4906 if {![info exists descendent($id)]} {
4909 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4912 } elseif {$highlight_related eq [mc "Ancestor"] ||
4913 $highlight_related eq [mc "Not ancestor"]} {
4914 if {![info exists ancestor($id)]} {
4917 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4921 if {[info exists iddrawn($id)]} {
4922 if {$isbold && ![ishighlighted $id]} {
4923 bolden $id mainfontbold
4926 set rhighlights($id) $isbold
4929 # Graph layout functions
4931 proc shortids {ids} {
4934 if {[llength $id] > 1} {
4935 lappend res [shortids $id]
4936 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4937 lappend res [string range $id 0 7]
4948 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4949 if {($n & $mask) != 0} {
4950 set ret [concat $ret $o]
4952 set o [concat $o $o]
4957 proc ordertoken {id} {
4958 global ordertok curview varcid varcstart varctok curview parents children
4959 global nullid nullid2
4961 if {[info exists ordertok($id)]} {
4962 return $ordertok($id)
4967 if {[info exists varcid($curview,$id)]} {
4968 set a $varcid($curview,$id)
4969 set p [lindex $varcstart($curview) $a]
4971 set p [lindex $children($curview,$id) 0]
4973 if {[info exists ordertok($p)]} {
4974 set tok $ordertok($p)
4977 set id [first_real_child $curview,$p]
4980 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4983 if {[llength $parents($curview,$id)] == 1} {
4984 lappend todo [list $p {}]
4986 set j [lsearch -exact $parents($curview,$id) $p]
4988 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4990 lappend todo [list $p [strrep $j]]
4993 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
4994 set p [lindex $todo $i 0]
4995 append tok [lindex $todo $i 1]
4996 set ordertok($p) $tok
4998 set ordertok($origid) $tok
5002 # Work out where id should go in idlist so that order-token
5003 # values increase from left to right
5004 proc idcol {idlist id {i 0}} {
5005 set t [ordertoken $id]
5009 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5010 if {$i > [llength $idlist]} {
5011 set i [llength $idlist]
5013 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5016 if {$t > [ordertoken [lindex $idlist $i]]} {
5017 while {[incr i] < [llength $idlist] &&
5018 $t >= [ordertoken [lindex $idlist $i]]} {}
5024 proc initlayout {} {
5025 global rowidlist rowisopt rowfinal displayorder parentlist
5026 global numcommits canvxmax canv
5028 global colormap rowtextx
5037 set canvxmax [$canv cget -width]
5038 catch {unset colormap}
5039 catch {unset rowtextx}
5043 proc setcanvscroll {} {
5044 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5045 global lastscrollset lastscrollrows
5047 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5048 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5049 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5050 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5051 set lastscrollset [clock clicks -milliseconds]
5052 set lastscrollrows $numcommits
5055 proc visiblerows {} {
5056 global canv numcommits linespc
5058 set ymax [lindex [$canv cget -scrollregion] 3]
5059 if {$ymax eq {} || $ymax == 0} return
5061 set y0 [expr {int([lindex $f 0] * $ymax)}]
5062 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5066 set y1 [expr {int([lindex $f 1] * $ymax)}]
5067 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5068 if {$r1 >= $numcommits} {
5069 set r1 [expr {$numcommits - 1}]
5071 return [list $r0 $r1]
5074 proc layoutmore {} {
5075 global commitidx viewcomplete curview
5076 global numcommits pending_select curview
5077 global lastscrollset lastscrollrows
5079 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5080 [clock clicks -milliseconds] - $lastscrollset > 500} {
5083 if {[info exists pending_select] &&
5084 [commitinview $pending_select $curview]} {
5086 selectline [rowofcommit $pending_select] 1
5091 # With path limiting, we mightn't get the actual HEAD commit,
5092 # so ask git rev-list what is the first ancestor of HEAD that
5093 # touches a file in the path limit.
5094 proc get_viewmainhead {view} {
5095 global viewmainheadid vfilelimit viewinstances mainheadid
5098 set rfd [open [concat | git rev-list -1 $mainheadid \
5099 -- $vfilelimit($view)] r]
5100 set j [reg_instance $rfd]
5101 lappend viewinstances($view) $j
5102 fconfigure $rfd -blocking 0
5103 filerun $rfd [list getviewhead $rfd $j $view]
5104 set viewmainheadid($curview) {}
5108 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5109 proc getviewhead {fd inst view} {
5110 global viewmainheadid commfd curview viewinstances showlocalchanges
5113 if {[gets $fd line] < 0} {
5117 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5120 set viewmainheadid($view) $id
5123 set i [lsearch -exact $viewinstances($view) $inst]
5125 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5127 if {$showlocalchanges && $id ne {} && $view == $curview} {
5133 proc doshowlocalchanges {} {
5134 global curview viewmainheadid
5136 if {$viewmainheadid($curview) eq {}} return
5137 if {[commitinview $viewmainheadid($curview) $curview]} {
5140 interestedin $viewmainheadid($curview) dodiffindex
5144 proc dohidelocalchanges {} {
5145 global nullid nullid2 lserial curview
5147 if {[commitinview $nullid $curview]} {
5148 removefakerow $nullid
5150 if {[commitinview $nullid2 $curview]} {
5151 removefakerow $nullid2
5156 # spawn off a process to do git diff-index --cached HEAD
5157 proc dodiffindex {} {
5158 global lserial showlocalchanges vfilelimit curview
5161 if {!$showlocalchanges || !$hasworktree} return
5163 set cmd "|git diff-index --cached HEAD"
5164 if {$vfilelimit($curview) ne {}} {
5165 set cmd [concat $cmd -- $vfilelimit($curview)]
5167 set fd [open $cmd r]
5168 fconfigure $fd -blocking 0
5169 set i [reg_instance $fd]
5170 filerun $fd [list readdiffindex $fd $lserial $i]
5173 proc readdiffindex {fd serial inst} {
5174 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5178 if {[gets $fd line] < 0} {
5184 # we only need to see one line and we don't really care what it says...
5187 if {$serial != $lserial} {
5191 # now see if there are any local changes not checked in to the index
5192 set cmd "|git diff-files"
5193 if {$vfilelimit($curview) ne {}} {
5194 set cmd [concat $cmd -- $vfilelimit($curview)]
5196 set fd [open $cmd r]
5197 fconfigure $fd -blocking 0
5198 set i [reg_instance $fd]
5199 filerun $fd [list readdifffiles $fd $serial $i]
5201 if {$isdiff && ![commitinview $nullid2 $curview]} {
5202 # add the line for the changes in the index to the graph
5203 set hl [mc "Local changes checked in to index but not committed"]
5204 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5205 set commitdata($nullid2) "\n $hl\n"
5206 if {[commitinview $nullid $curview]} {
5207 removefakerow $nullid
5209 insertfakerow $nullid2 $viewmainheadid($curview)
5210 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5211 if {[commitinview $nullid $curview]} {
5212 removefakerow $nullid
5214 removefakerow $nullid2
5219 proc readdifffiles {fd serial inst} {
5220 global viewmainheadid nullid nullid2 curview
5221 global commitinfo commitdata lserial
5224 if {[gets $fd line] < 0} {
5230 # we only need to see one line and we don't really care what it says...
5233 if {$serial != $lserial} {
5237 if {$isdiff && ![commitinview $nullid $curview]} {
5238 # add the line for the local diff to the graph
5239 set hl [mc "Local uncommitted changes, not checked in to index"]
5240 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5241 set commitdata($nullid) "\n $hl\n"
5242 if {[commitinview $nullid2 $curview]} {
5245 set p $viewmainheadid($curview)
5247 insertfakerow $nullid $p
5248 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5249 removefakerow $nullid
5254 proc nextuse {id row} {
5255 global curview children
5257 if {[info exists children($curview,$id)]} {
5258 foreach kid $children($curview,$id) {
5259 if {![commitinview $kid $curview]} {
5262 if {[rowofcommit $kid] > $row} {
5263 return [rowofcommit $kid]
5267 if {[commitinview $id $curview]} {
5268 return [rowofcommit $id]
5273 proc prevuse {id row} {
5274 global curview children
5277 if {[info exists children($curview,$id)]} {
5278 foreach kid $children($curview,$id) {
5279 if {![commitinview $kid $curview]} break
5280 if {[rowofcommit $kid] < $row} {
5281 set ret [rowofcommit $kid]
5288 proc make_idlist {row} {
5289 global displayorder parentlist uparrowlen downarrowlen mingaplen
5290 global commitidx curview children
5292 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5296 set ra [expr {$row - $downarrowlen}]
5300 set rb [expr {$row + $uparrowlen}]
5301 if {$rb > $commitidx($curview)} {
5302 set rb $commitidx($curview)
5304 make_disporder $r [expr {$rb + 1}]
5306 for {} {$r < $ra} {incr r} {
5307 set nextid [lindex $displayorder [expr {$r + 1}]]
5308 foreach p [lindex $parentlist $r] {
5309 if {$p eq $nextid} continue
5310 set rn [nextuse $p $r]
5312 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5313 lappend ids [list [ordertoken $p] $p]
5317 for {} {$r < $row} {incr r} {
5318 set nextid [lindex $displayorder [expr {$r + 1}]]
5319 foreach p [lindex $parentlist $r] {
5320 if {$p eq $nextid} continue
5321 set rn [nextuse $p $r]
5322 if {$rn < 0 || $rn >= $row} {
5323 lappend ids [list [ordertoken $p] $p]
5327 set id [lindex $displayorder $row]
5328 lappend ids [list [ordertoken $id] $id]
5330 foreach p [lindex $parentlist $r] {
5331 set firstkid [lindex $children($curview,$p) 0]
5332 if {[rowofcommit $firstkid] < $row} {
5333 lappend ids [list [ordertoken $p] $p]
5337 set id [lindex $displayorder $r]
5339 set firstkid [lindex $children($curview,$id) 0]
5340 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5341 lappend ids [list [ordertoken $id] $id]
5346 foreach idx [lsort -unique $ids] {
5347 lappend idlist [lindex $idx 1]
5352 proc rowsequal {a b} {
5353 while {[set i [lsearch -exact $a {}]] >= 0} {
5354 set a [lreplace $a $i $i]
5356 while {[set i [lsearch -exact $b {}]] >= 0} {
5357 set b [lreplace $b $i $i]
5359 return [expr {$a eq $b}]
5362 proc makeupline {id row rend col} {
5363 global rowidlist uparrowlen downarrowlen mingaplen
5365 for {set r $rend} {1} {set r $rstart} {
5366 set rstart [prevuse $id $r]
5367 if {$rstart < 0} return
5368 if {$rstart < $row} break
5370 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5371 set rstart [expr {$rend - $uparrowlen - 1}]
5373 for {set r $rstart} {[incr r] <= $row} {} {
5374 set idlist [lindex $rowidlist $r]
5375 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5376 set col [idcol $idlist $id $col]
5377 lset rowidlist $r [linsert $idlist $col $id]
5383 proc layoutrows {row endrow} {
5384 global rowidlist rowisopt rowfinal displayorder
5385 global uparrowlen downarrowlen maxwidth mingaplen
5386 global children parentlist
5387 global commitidx viewcomplete curview
5389 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5392 set rm1 [expr {$row - 1}]
5393 foreach id [lindex $rowidlist $rm1] {
5398 set final [lindex $rowfinal $rm1]
5400 for {} {$row < $endrow} {incr row} {
5401 set rm1 [expr {$row - 1}]
5402 if {$rm1 < 0 || $idlist eq {}} {
5403 set idlist [make_idlist $row]
5406 set id [lindex $displayorder $rm1]
5407 set col [lsearch -exact $idlist $id]
5408 set idlist [lreplace $idlist $col $col]
5409 foreach p [lindex $parentlist $rm1] {
5410 if {[lsearch -exact $idlist $p] < 0} {
5411 set col [idcol $idlist $p $col]
5412 set idlist [linsert $idlist $col $p]
5413 # if not the first child, we have to insert a line going up
5414 if {$id ne [lindex $children($curview,$p) 0]} {
5415 makeupline $p $rm1 $row $col
5419 set id [lindex $displayorder $row]
5420 if {$row > $downarrowlen} {
5421 set termrow [expr {$row - $downarrowlen - 1}]
5422 foreach p [lindex $parentlist $termrow] {
5423 set i [lsearch -exact $idlist $p]
5424 if {$i < 0} continue
5425 set nr [nextuse $p $termrow]
5426 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5427 set idlist [lreplace $idlist $i $i]
5431 set col [lsearch -exact $idlist $id]
5433 set col [idcol $idlist $id]
5434 set idlist [linsert $idlist $col $id]
5435 if {$children($curview,$id) ne {}} {
5436 makeupline $id $rm1 $row $col
5439 set r [expr {$row + $uparrowlen - 1}]
5440 if {$r < $commitidx($curview)} {
5442 foreach p [lindex $parentlist $r] {
5443 if {[lsearch -exact $idlist $p] >= 0} continue
5444 set fk [lindex $children($curview,$p) 0]
5445 if {[rowofcommit $fk] < $row} {
5446 set x [idcol $idlist $p $x]
5447 set idlist [linsert $idlist $x $p]
5450 if {[incr r] < $commitidx($curview)} {
5451 set p [lindex $displayorder $r]
5452 if {[lsearch -exact $idlist $p] < 0} {
5453 set fk [lindex $children($curview,$p) 0]
5454 if {$fk ne {} && [rowofcommit $fk] < $row} {
5455 set x [idcol $idlist $p $x]
5456 set idlist [linsert $idlist $x $p]
5462 if {$final && !$viewcomplete($curview) &&
5463 $row + $uparrowlen + $mingaplen + $downarrowlen
5464 >= $commitidx($curview)} {
5467 set l [llength $rowidlist]
5469 lappend rowidlist $idlist
5471 lappend rowfinal $final
5472 } elseif {$row < $l} {
5473 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5474 lset rowidlist $row $idlist
5477 lset rowfinal $row $final
5479 set pad [ntimes [expr {$row - $l}] {}]
5480 set rowidlist [concat $rowidlist $pad]
5481 lappend rowidlist $idlist
5482 set rowfinal [concat $rowfinal $pad]
5483 lappend rowfinal $final
5484 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5490 proc changedrow {row} {
5491 global displayorder iddrawn rowisopt need_redisplay
5493 set l [llength $rowisopt]
5495 lset rowisopt $row 0
5496 if {$row + 1 < $l} {
5497 lset rowisopt [expr {$row + 1}] 0
5498 if {$row + 2 < $l} {
5499 lset rowisopt [expr {$row + 2}] 0
5503 set id [lindex $displayorder $row]
5504 if {[info exists iddrawn($id)]} {
5505 set need_redisplay 1
5509 proc insert_pad {row col npad} {
5512 set pad [ntimes $npad {}]
5513 set idlist [lindex $rowidlist $row]
5514 set bef [lrange $idlist 0 [expr {$col - 1}]]
5515 set aft [lrange $idlist $col end]
5516 set i [lsearch -exact $aft {}]
5518 set aft [lreplace $aft $i $i]
5520 lset rowidlist $row [concat $bef $pad $aft]
5524 proc optimize_rows {row col endrow} {
5525 global rowidlist rowisopt displayorder curview children
5530 for {} {$row < $endrow} {incr row; set col 0} {
5531 if {[lindex $rowisopt $row]} continue
5533 set y0 [expr {$row - 1}]
5534 set ym [expr {$row - 2}]
5535 set idlist [lindex $rowidlist $row]
5536 set previdlist [lindex $rowidlist $y0]
5537 if {$idlist eq {} || $previdlist eq {}} continue
5539 set pprevidlist [lindex $rowidlist $ym]
5540 if {$pprevidlist eq {}} continue
5546 for {} {$col < [llength $idlist]} {incr col} {
5547 set id [lindex $idlist $col]
5548 if {[lindex $previdlist $col] eq $id} continue
5553 set x0 [lsearch -exact $previdlist $id]
5554 if {$x0 < 0} continue
5555 set z [expr {$x0 - $col}]
5559 set xm [lsearch -exact $pprevidlist $id]
5561 set z0 [expr {$xm - $x0}]
5565 # if row y0 is the first child of $id then it's not an arrow
5566 if {[lindex $children($curview,$id) 0] ne
5567 [lindex $displayorder $y0]} {
5571 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5572 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5575 # Looking at lines from this row to the previous row,
5576 # make them go straight up if they end in an arrow on
5577 # the previous row; otherwise make them go straight up
5579 if {$z < -1 || ($z < 0 && $isarrow)} {
5580 # Line currently goes left too much;
5581 # insert pads in the previous row, then optimize it
5582 set npad [expr {-1 - $z + $isarrow}]
5583 insert_pad $y0 $x0 $npad
5585 optimize_rows $y0 $x0 $row
5587 set previdlist [lindex $rowidlist $y0]
5588 set x0 [lsearch -exact $previdlist $id]
5589 set z [expr {$x0 - $col}]
5591 set pprevidlist [lindex $rowidlist $ym]
5592 set xm [lsearch -exact $pprevidlist $id]
5593 set z0 [expr {$xm - $x0}]
5595 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5596 # Line currently goes right too much;
5597 # insert pads in this line
5598 set npad [expr {$z - 1 + $isarrow}]
5599 insert_pad $row $col $npad
5600 set idlist [lindex $rowidlist $row]
5602 set z [expr {$x0 - $col}]
5605 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5606 # this line links to its first child on row $row-2
5607 set id [lindex $displayorder $ym]
5608 set xc [lsearch -exact $pprevidlist $id]
5610 set z0 [expr {$xc - $x0}]
5613 # avoid lines jigging left then immediately right
5614 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5615 insert_pad $y0 $x0 1
5617 optimize_rows $y0 $x0 $row
5618 set previdlist [lindex $rowidlist $y0]
5622 # Find the first column that doesn't have a line going right
5623 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5624 set id [lindex $idlist $col]
5625 if {$id eq {}} break
5626 set x0 [lsearch -exact $previdlist $id]
5628 # check if this is the link to the first child
5629 set kid [lindex $displayorder $y0]
5630 if {[lindex $children($curview,$id) 0] eq $kid} {
5631 # it is, work out offset to child
5632 set x0 [lsearch -exact $previdlist $kid]
5635 if {$x0 <= $col} break
5637 # Insert a pad at that column as long as it has a line and
5638 # isn't the last column
5639 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5640 set idlist [linsert $idlist $col {}]
5641 lset rowidlist $row $idlist
5649 global canvx0 linespc
5650 return [expr {$canvx0 + $col * $linespc}]
5654 global canvy0 linespc
5655 return [expr {$canvy0 + $row * $linespc}]
5658 proc linewidth {id} {
5659 global thickerline lthickness
5662 if {[info exists thickerline] && $id eq $thickerline} {
5663 set wid [expr {2 * $lthickness}]
5668 proc rowranges {id} {
5669 global curview children uparrowlen downarrowlen
5672 set kids $children($curview,$id)
5678 foreach child $kids {
5679 if {![commitinview $child $curview]} break
5680 set row [rowofcommit $child]
5681 if {![info exists prev]} {
5682 lappend ret [expr {$row + 1}]
5684 if {$row <= $prevrow} {
5685 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5687 # see if the line extends the whole way from prevrow to row
5688 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5689 [lsearch -exact [lindex $rowidlist \
5690 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5691 # it doesn't, see where it ends
5692 set r [expr {$prevrow + $downarrowlen}]
5693 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5694 while {[incr r -1] > $prevrow &&
5695 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5697 while {[incr r] <= $row &&
5698 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5702 # see where it starts up again
5703 set r [expr {$row - $uparrowlen}]
5704 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5705 while {[incr r] < $row &&
5706 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5708 while {[incr r -1] >= $prevrow &&
5709 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5715 if {$child eq $id} {
5724 proc drawlineseg {id row endrow arrowlow} {
5725 global rowidlist displayorder iddrawn linesegs
5726 global canv colormap linespc curview maxlinelen parentlist
5728 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5729 set le [expr {$row + 1}]
5732 set c [lsearch -exact [lindex $rowidlist $le] $id]
5738 set x [lindex $displayorder $le]
5743 if {[info exists iddrawn($x)] || $le == $endrow} {
5744 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5760 if {[info exists linesegs($id)]} {
5761 set lines $linesegs($id)
5763 set r0 [lindex $li 0]
5765 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5775 set li [lindex $lines [expr {$i-1}]]
5776 set r1 [lindex $li 1]
5777 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5782 set x [lindex $cols [expr {$le - $row}]]
5783 set xp [lindex $cols [expr {$le - 1 - $row}]]
5784 set dir [expr {$xp - $x}]
5786 set ith [lindex $lines $i 2]
5787 set coords [$canv coords $ith]
5788 set ah [$canv itemcget $ith -arrow]
5789 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5790 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5791 if {$x2 ne {} && $x - $x2 == $dir} {
5792 set coords [lrange $coords 0 end-2]
5795 set coords [list [xc $le $x] [yc $le]]
5798 set itl [lindex $lines [expr {$i-1}] 2]
5799 set al [$canv itemcget $itl -arrow]
5800 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5801 } elseif {$arrowlow} {
5802 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5803 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5807 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5808 for {set y $le} {[incr y -1] > $row} {} {
5810 set xp [lindex $cols [expr {$y - 1 - $row}]]
5811 set ndir [expr {$xp - $x}]
5812 if {$dir != $ndir || $xp < 0} {
5813 lappend coords [xc $y $x] [yc $y]
5819 # join parent line to first child
5820 set ch [lindex $displayorder $row]
5821 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5823 puts "oops: drawlineseg: child $ch not on row $row"
5824 } elseif {$xc != $x} {
5825 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5826 set d [expr {int(0.5 * $linespc)}]
5829 set x2 [expr {$x1 - $d}]
5831 set x2 [expr {$x1 + $d}]
5834 set y1 [expr {$y2 + $d}]
5835 lappend coords $x1 $y1 $x2 $y2
5836 } elseif {$xc < $x - 1} {
5837 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5838 } elseif {$xc > $x + 1} {
5839 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5843 lappend coords [xc $row $x] [yc $row]
5845 set xn [xc $row $xp]
5847 lappend coords $xn $yn
5851 set t [$canv create line $coords -width [linewidth $id] \
5852 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5855 set lines [linsert $lines $i [list $row $le $t]]
5857 $canv coords $ith $coords
5858 if {$arrow ne $ah} {
5859 $canv itemconf $ith -arrow $arrow
5861 lset lines $i 0 $row
5864 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5865 set ndir [expr {$xo - $xp}]
5866 set clow [$canv coords $itl]
5867 if {$dir == $ndir} {
5868 set clow [lrange $clow 2 end]
5870 set coords [concat $coords $clow]
5872 lset lines [expr {$i-1}] 1 $le
5874 # coalesce two pieces
5876 set b [lindex $lines [expr {$i-1}] 0]
5877 set e [lindex $lines $i 1]
5878 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5880 $canv coords $itl $coords
5881 if {$arrow ne $al} {
5882 $canv itemconf $itl -arrow $arrow
5886 set linesegs($id) $lines
5890 proc drawparentlinks {id row} {
5891 global rowidlist canv colormap curview parentlist
5892 global idpos linespc
5894 set rowids [lindex $rowidlist $row]
5895 set col [lsearch -exact $rowids $id]
5896 if {$col < 0} return
5897 set olds [lindex $parentlist $row]
5898 set row2 [expr {$row + 1}]
5899 set x [xc $row $col]
5902 set d [expr {int(0.5 * $linespc)}]
5903 set ymid [expr {$y + $d}]
5904 set ids [lindex $rowidlist $row2]
5905 # rmx = right-most X coord used
5908 set i [lsearch -exact $ids $p]
5910 puts "oops, parent $p of $id not in list"
5913 set x2 [xc $row2 $i]
5917 set j [lsearch -exact $rowids $p]
5919 # drawlineseg will do this one for us
5923 # should handle duplicated parents here...
5924 set coords [list $x $y]
5926 # if attaching to a vertical segment, draw a smaller
5927 # slant for visual distinctness
5930 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5932 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5934 } elseif {$i < $col && $i < $j} {
5935 # segment slants towards us already
5936 lappend coords [xc $row $j] $y
5938 if {$i < $col - 1} {
5939 lappend coords [expr {$x2 + $linespc}] $y
5940 } elseif {$i > $col + 1} {
5941 lappend coords [expr {$x2 - $linespc}] $y
5943 lappend coords $x2 $y2
5946 lappend coords $x2 $y2
5948 set t [$canv create line $coords -width [linewidth $p] \
5949 -fill $colormap($p) -tags lines.$p]
5953 if {$rmx > [lindex $idpos($id) 1]} {
5954 lset idpos($id) 1 $rmx
5959 proc drawlines {id} {
5962 $canv itemconf lines.$id -width [linewidth $id]
5965 proc drawcmittext {id row col} {
5966 global linespc canv canv2 canv3 fgcolor curview
5967 global cmitlisted commitinfo rowidlist parentlist
5968 global rowtextx idpos idtags idheads idotherrefs
5969 global linehtag linentag linedtag selectedline
5970 global canvxmax boldids boldnameids fgcolor markedid
5971 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5972 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5973 global circleoutlinecolor
5975 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5976 set listed $cmitlisted($curview,$id)
5977 if {$id eq $nullid} {
5978 set ofill $workingfilescirclecolor
5979 } elseif {$id eq $nullid2} {
5980 set ofill $indexcirclecolor
5981 } elseif {$id eq $mainheadid} {
5982 set ofill $mainheadcirclecolor
5984 set ofill [lindex $circlecolors $listed]
5986 set x [xc $row $col]
5988 set orad [expr {$linespc / 3}]
5990 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
5991 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5992 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
5993 } elseif {$listed == 3} {
5994 # triangle pointing left for left-side commits
5995 set t [$canv create polygon \
5996 [expr {$x - $orad}] $y \
5997 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
5998 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
5999 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6001 # triangle pointing right for right-side commits
6002 set t [$canv create polygon \
6003 [expr {$x + $orad - 1}] $y \
6004 [expr {$x - $orad}] [expr {$y - $orad}] \
6005 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6006 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6008 set circleitem($row) $t
6010 $canv bind $t <1> {selcanvline {} %x %y}
6011 set rmx [llength [lindex $rowidlist $row]]
6012 set olds [lindex $parentlist $row]
6014 set nextids [lindex $rowidlist [expr {$row + 1}]]
6016 set i [lsearch -exact $nextids $p]
6022 set xt [xc $row $rmx]
6023 set rowtextx($row) $xt
6024 set idpos($id) [list $x $xt $y]
6025 if {[info exists idtags($id)] || [info exists idheads($id)]
6026 || [info exists idotherrefs($id)]} {
6027 set xt [drawtags $id $x $xt $y]
6029 if {[lindex $commitinfo($id) 6] > 0} {
6030 set xt [drawnotesign $xt $y]
6032 set headline [lindex $commitinfo($id) 0]
6033 set name [lindex $commitinfo($id) 1]
6034 set date [lindex $commitinfo($id) 2]
6035 set date [formatdate $date]
6038 set isbold [ishighlighted $id]
6041 set font mainfontbold
6043 lappend boldnameids $id
6044 set nfont mainfontbold
6047 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6048 -text $headline -font $font -tags text]
6049 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6050 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6051 -text $name -font $nfont -tags text]
6052 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6053 -text $date -font mainfont -tags text]
6054 if {$selectedline == $row} {
6057 if {[info exists markedid] && $markedid eq $id} {
6060 set xr [expr {$xt + [font measure $font $headline]}]
6061 if {$xr > $canvxmax} {
6067 proc drawcmitrow {row} {
6068 global displayorder rowidlist nrows_drawn
6069 global iddrawn markingmatches
6070 global commitinfo numcommits
6071 global filehighlight fhighlights findpattern nhighlights
6072 global hlview vhighlights
6073 global highlight_related rhighlights
6075 if {$row >= $numcommits} return
6077 set id [lindex $displayorder $row]
6078 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6079 askvhighlight $row $id
6081 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6082 askfilehighlight $row $id
6084 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6085 askfindhighlight $row $id
6087 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6088 askrelhighlight $row $id
6090 if {![info exists iddrawn($id)]} {
6091 set col [lsearch -exact [lindex $rowidlist $row] $id]
6093 puts "oops, row $row id $id not in list"
6096 if {![info exists commitinfo($id)]} {
6100 drawcmittext $id $row $col
6104 if {$markingmatches} {
6105 markrowmatches $row $id
6109 proc drawcommits {row {endrow {}}} {
6110 global numcommits iddrawn displayorder curview need_redisplay
6111 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6116 if {$endrow eq {}} {
6119 if {$endrow >= $numcommits} {
6120 set endrow [expr {$numcommits - 1}]
6123 set rl1 [expr {$row - $downarrowlen - 3}]
6127 set ro1 [expr {$row - 3}]
6131 set r2 [expr {$endrow + $uparrowlen + 3}]
6132 if {$r2 > $numcommits} {
6135 for {set r $rl1} {$r < $r2} {incr r} {
6136 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6140 set rl1 [expr {$r + 1}]
6146 optimize_rows $ro1 0 $r2
6147 if {$need_redisplay || $nrows_drawn > 2000} {
6151 # make the lines join to already-drawn rows either side
6152 set r [expr {$row - 1}]
6153 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6156 set er [expr {$endrow + 1}]
6157 if {$er >= $numcommits ||
6158 ![info exists iddrawn([lindex $displayorder $er])]} {
6161 for {} {$r <= $er} {incr r} {
6162 set id [lindex $displayorder $r]
6163 set wasdrawn [info exists iddrawn($id)]
6165 if {$r == $er} break
6166 set nextid [lindex $displayorder [expr {$r + 1}]]
6167 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6168 drawparentlinks $id $r
6170 set rowids [lindex $rowidlist $r]
6171 foreach lid $rowids {
6172 if {$lid eq {}} continue
6173 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6175 # see if this is the first child of any of its parents
6176 foreach p [lindex $parentlist $r] {
6177 if {[lsearch -exact $rowids $p] < 0} {
6178 # make this line extend up to the child
6179 set lineend($p) [drawlineseg $p $r $er 0]
6183 set lineend($lid) [drawlineseg $lid $r $er 1]
6189 proc undolayout {row} {
6190 global uparrowlen mingaplen downarrowlen
6191 global rowidlist rowisopt rowfinal need_redisplay
6193 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6197 if {[llength $rowidlist] > $r} {
6199 set rowidlist [lrange $rowidlist 0 $r]
6200 set rowfinal [lrange $rowfinal 0 $r]
6201 set rowisopt [lrange $rowisopt 0 $r]
6202 set need_redisplay 1
6207 proc drawvisible {} {
6208 global canv linespc curview vrowmod selectedline targetrow targetid
6209 global need_redisplay cscroll numcommits
6211 set fs [$canv yview]
6212 set ymax [lindex [$canv cget -scrollregion] 3]
6213 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6214 set f0 [lindex $fs 0]
6215 set f1 [lindex $fs 1]
6216 set y0 [expr {int($f0 * $ymax)}]
6217 set y1 [expr {int($f1 * $ymax)}]
6219 if {[info exists targetid]} {
6220 if {[commitinview $targetid $curview]} {
6221 set r [rowofcommit $targetid]
6222 if {$r != $targetrow} {
6223 # Fix up the scrollregion and change the scrolling position
6224 # now that our target row has moved.
6225 set diff [expr {($r - $targetrow) * $linespc}]
6228 set ymax [lindex [$canv cget -scrollregion] 3]
6231 set f0 [expr {$y0 / $ymax}]
6232 set f1 [expr {$y1 / $ymax}]
6233 allcanvs yview moveto $f0
6234 $cscroll set $f0 $f1
6235 set need_redisplay 1
6242 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6243 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6244 if {$endrow >= $vrowmod($curview)} {
6245 update_arcrows $curview
6247 if {$selectedline ne {} &&
6248 $row <= $selectedline && $selectedline <= $endrow} {
6249 set targetrow $selectedline
6250 } elseif {[info exists targetid]} {
6251 set targetrow [expr {int(($row + $endrow) / 2)}]
6253 if {[info exists targetrow]} {
6254 if {$targetrow >= $numcommits} {
6255 set targetrow [expr {$numcommits - 1}]
6257 set targetid [commitonrow $targetrow]
6259 drawcommits $row $endrow
6262 proc clear_display {} {
6263 global iddrawn linesegs need_redisplay nrows_drawn
6264 global vhighlights fhighlights nhighlights rhighlights
6265 global linehtag linentag linedtag boldids boldnameids
6268 catch {unset iddrawn}
6269 catch {unset linesegs}
6270 catch {unset linehtag}
6271 catch {unset linentag}
6272 catch {unset linedtag}
6275 catch {unset vhighlights}
6276 catch {unset fhighlights}
6277 catch {unset nhighlights}
6278 catch {unset rhighlights}
6279 set need_redisplay 0
6283 proc findcrossings {id} {
6284 global rowidlist parentlist numcommits displayorder
6288 foreach {s e} [rowranges $id] {
6289 if {$e >= $numcommits} {
6290 set e [expr {$numcommits - 1}]
6292 if {$e <= $s} continue
6293 for {set row $e} {[incr row -1] >= $s} {} {
6294 set x [lsearch -exact [lindex $rowidlist $row] $id]
6296 set olds [lindex $parentlist $row]
6297 set kid [lindex $displayorder $row]
6298 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6299 if {$kidx < 0} continue
6300 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6302 set px [lsearch -exact $nextrow $p]
6303 if {$px < 0} continue
6304 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6305 if {[lsearch -exact $ccross $p] >= 0} continue
6306 if {$x == $px + ($kidx < $px? -1: 1)} {
6308 } elseif {[lsearch -exact $cross $p] < 0} {
6315 return [concat $ccross {{}} $cross]
6318 proc assigncolor {id} {
6319 global colormap colors nextcolor
6320 global parents children children curview
6322 if {[info exists colormap($id)]} return
6323 set ncolors [llength $colors]
6324 if {[info exists children($curview,$id)]} {
6325 set kids $children($curview,$id)
6329 if {[llength $kids] == 1} {
6330 set child [lindex $kids 0]
6331 if {[info exists colormap($child)]
6332 && [llength $parents($curview,$child)] == 1} {
6333 set colormap($id) $colormap($child)
6339 foreach x [findcrossings $id] {
6341 # delimiter between corner crossings and other crossings
6342 if {[llength $badcolors] >= $ncolors - 1} break
6343 set origbad $badcolors
6345 if {[info exists colormap($x)]
6346 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6347 lappend badcolors $colormap($x)
6350 if {[llength $badcolors] >= $ncolors} {
6351 set badcolors $origbad
6353 set origbad $badcolors
6354 if {[llength $badcolors] < $ncolors - 1} {
6355 foreach child $kids {
6356 if {[info exists colormap($child)]
6357 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6358 lappend badcolors $colormap($child)
6360 foreach p $parents($curview,$child) {
6361 if {[info exists colormap($p)]
6362 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6363 lappend badcolors $colormap($p)
6367 if {[llength $badcolors] >= $ncolors} {
6368 set badcolors $origbad
6371 for {set i 0} {$i <= $ncolors} {incr i} {
6372 set c [lindex $colors $nextcolor]
6373 if {[incr nextcolor] >= $ncolors} {
6376 if {[lsearch -exact $badcolors $c]} break
6378 set colormap($id) $c
6381 proc bindline {t id} {
6384 $canv bind $t <Enter> "lineenter %x %y $id"
6385 $canv bind $t <Motion> "linemotion %x %y $id"
6386 $canv bind $t <Leave> "lineleave $id"
6387 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6390 proc drawtags {id x xt y1} {
6391 global idtags idheads idotherrefs mainhead
6392 global linespc lthickness
6393 global canv rowtextx curview fgcolor bgcolor ctxbut
6394 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6395 global tagbgcolor tagfgcolor tagoutlinecolor
6401 if {[info exists idtags($id)]} {
6402 set marks $idtags($id)
6403 set ntags [llength $marks]
6405 if {[info exists idheads($id)]} {
6406 set marks [concat $marks $idheads($id)]
6407 set nheads [llength $idheads($id)]
6409 if {[info exists idotherrefs($id)]} {
6410 set marks [concat $marks $idotherrefs($id)]
6416 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6417 set yt [expr {$y1 - 0.5 * $linespc}]
6418 set yb [expr {$yt + $linespc - 1}]
6422 foreach tag $marks {
6424 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6425 set wid [font measure mainfontbold $tag]
6427 set wid [font measure mainfont $tag]
6431 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
6433 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
6434 -width $lthickness -fill $reflinecolor -tags tag.$id]
6436 foreach tag $marks x $xvals wid $wvals {
6437 set tag_quoted [string map {% %%} $tag]
6438 set xl [expr {$x + $delta}]
6439 set xr [expr {$x + $delta + $wid + $lthickness}]
6441 if {[incr ntags -1] >= 0} {
6443 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6444 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6445 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6447 $canv bind $t <1> [list showtag $tag_quoted 1]
6448 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6450 # draw a head or other ref
6451 if {[incr nheads -1] >= 0} {
6452 set col $headbgcolor
6453 if {$tag eq $mainhead} {
6454 set font mainfontbold
6459 set xl [expr {$xl - $delta/2}]
6460 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6461 -width 1 -outline black -fill $col -tags tag.$id
6462 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6463 set rwid [font measure mainfont $remoteprefix]
6464 set xi [expr {$x + 1}]
6465 set yti [expr {$yt + 1}]
6466 set xri [expr {$x + $rwid}]
6467 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6468 -width 0 -fill $remotebgcolor -tags tag.$id
6471 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6472 -font $font -tags [list tag.$id text]]
6474 $canv bind $t <1> [list showtag $tag_quoted 1]
6475 } elseif {$nheads >= 0} {
6476 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6482 proc drawnotesign {xt y} {
6483 global linespc canv fgcolor
6485 set orad [expr {$linespc / 3}]
6486 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6487 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6488 -fill yellow -outline $fgcolor -width 1 -tags circle]
6489 set xt [expr {$xt + $orad * 3}]
6493 proc xcoord {i level ln} {
6494 global canvx0 xspc1 xspc2
6496 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6497 if {$i > 0 && $i == $level} {
6498 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6499 } elseif {$i > $level} {
6500 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6505 proc show_status {msg} {
6509 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6510 -tags text -fill $fgcolor
6513 # Don't change the text pane cursor if it is currently the hand cursor,
6514 # showing that we are over a sha1 ID link.
6515 proc settextcursor {c} {
6516 global ctext curtextcursor
6518 if {[$ctext cget -cursor] == $curtextcursor} {
6519 $ctext config -cursor $c
6521 set curtextcursor $c
6524 proc nowbusy {what {name {}}} {
6525 global isbusy busyname statusw
6527 if {[array names isbusy] eq {}} {
6528 . config -cursor watch
6532 set busyname($what) $name
6534 $statusw conf -text $name
6538 proc notbusy {what} {
6539 global isbusy maincursor textcursor busyname statusw
6543 if {$busyname($what) ne {} &&
6544 [$statusw cget -text] eq $busyname($what)} {
6545 $statusw conf -text {}
6548 if {[array names isbusy] eq {}} {
6549 . config -cursor $maincursor
6550 settextcursor $textcursor
6554 proc findmatches {f} {
6555 global findtype findstring
6556 if {$findtype == [mc "Regexp"]} {
6557 set matches [regexp -indices -all -inline $findstring $f]
6560 if {$findtype == [mc "IgnCase"]} {
6561 set f [string tolower $f]
6562 set fs [string tolower $fs]
6566 set l [string length $fs]
6567 while {[set j [string first $fs $f $i]] >= 0} {
6568 lappend matches [list $j [expr {$j+$l-1}]]
6569 set i [expr {$j + $l}]
6575 proc dofind {{dirn 1} {wrap 1}} {
6576 global findstring findstartline findcurline selectedline numcommits
6577 global gdttype filehighlight fh_serial find_dirn findallowwrap
6579 if {[info exists find_dirn]} {
6580 if {$find_dirn == $dirn} return
6584 if {$findstring eq {} || $numcommits == 0} return
6585 if {$selectedline eq {}} {
6586 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6588 set findstartline $selectedline
6590 set findcurline $findstartline
6591 nowbusy finding [mc "Searching"]
6592 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6593 after cancel do_file_hl $fh_serial
6594 do_file_hl $fh_serial
6597 set findallowwrap $wrap
6601 proc stopfinding {} {
6602 global find_dirn findcurline fprogcoord
6604 if {[info exists find_dirn]} {
6615 global commitdata commitinfo numcommits findpattern findloc
6616 global findstartline findcurline findallowwrap
6617 global find_dirn gdttype fhighlights fprogcoord
6618 global curview varcorder vrownum varccommits vrowmod
6620 if {![info exists find_dirn]} {
6623 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6626 if {$find_dirn > 0} {
6628 if {$l >= $numcommits} {
6631 if {$l <= $findstartline} {
6632 set lim [expr {$findstartline + 1}]
6635 set moretodo $findallowwrap
6642 if {$l >= $findstartline} {
6643 set lim [expr {$findstartline - 1}]
6646 set moretodo $findallowwrap
6649 set n [expr {($lim - $l) * $find_dirn}]
6654 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6655 update_arcrows $curview
6659 set ai [bsearch $vrownum($curview) $l]
6660 set a [lindex $varcorder($curview) $ai]
6661 set arow [lindex $vrownum($curview) $ai]
6662 set ids [lindex $varccommits($curview,$a)]
6663 set arowend [expr {$arow + [llength $ids]}]
6664 if {$gdttype eq [mc "containing:"]} {
6665 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6666 if {$l < $arow || $l >= $arowend} {
6668 set a [lindex $varcorder($curview) $ai]
6669 set arow [lindex $vrownum($curview) $ai]
6670 set ids [lindex $varccommits($curview,$a)]
6671 set arowend [expr {$arow + [llength $ids]}]
6673 set id [lindex $ids [expr {$l - $arow}]]
6674 # shouldn't happen unless git log doesn't give all the commits...
6675 if {![info exists commitdata($id)] ||
6676 ![doesmatch $commitdata($id)]} {
6679 if {![info exists commitinfo($id)]} {
6682 set info $commitinfo($id)
6683 foreach f $info ty $fldtypes {
6684 if {$ty eq ""} continue
6685 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6694 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6695 if {$l < $arow || $l >= $arowend} {
6697 set a [lindex $varcorder($curview) $ai]
6698 set arow [lindex $vrownum($curview) $ai]
6699 set ids [lindex $varccommits($curview,$a)]
6700 set arowend [expr {$arow + [llength $ids]}]
6702 set id [lindex $ids [expr {$l - $arow}]]
6703 if {![info exists fhighlights($id)]} {
6704 # this sets fhighlights($id) to -1
6705 askfilehighlight $l $id
6707 if {$fhighlights($id) > 0} {
6711 if {$fhighlights($id) < 0} {
6714 set findcurline [expr {$l - $find_dirn}]
6719 if {$found || ($domore && !$moretodo)} {
6735 set findcurline [expr {$l - $find_dirn}]
6737 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6741 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6746 proc findselectline {l} {
6747 global findloc commentend ctext findcurline markingmatches gdttype
6749 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6752 if {$markingmatches &&
6753 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6754 # highlight the matches in the comments
6755 set f [$ctext get 1.0 $commentend]
6756 set matches [findmatches $f]
6757 foreach match $matches {
6758 set start [lindex $match 0]
6759 set end [expr {[lindex $match 1] + 1}]
6760 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6766 # mark the bits of a headline or author that match a find string
6767 proc markmatches {canv l str tag matches font row} {
6770 set bbox [$canv bbox $tag]
6771 set x0 [lindex $bbox 0]
6772 set y0 [lindex $bbox 1]
6773 set y1 [lindex $bbox 3]
6774 foreach match $matches {
6775 set start [lindex $match 0]
6776 set end [lindex $match 1]
6777 if {$start > $end} continue
6778 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6779 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6780 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6781 [expr {$x0+$xlen+2}] $y1 \
6782 -outline {} -tags [list match$l matches] -fill yellow]
6784 if {$row == $selectedline} {
6785 $canv raise $t secsel
6790 proc unmarkmatches {} {
6791 global markingmatches
6793 allcanvs delete matches
6794 set markingmatches 0
6798 proc selcanvline {w x y} {
6799 global canv canvy0 ctext linespc
6801 set ymax [lindex [$canv cget -scrollregion] 3]
6802 if {$ymax == {}} return
6803 set yfrac [lindex [$canv yview] 0]
6804 set y [expr {$y + $yfrac * $ymax}]
6805 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6810 set xmax [lindex [$canv cget -scrollregion] 2]
6811 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6812 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6818 proc commit_descriptor {p} {
6820 if {![info exists commitinfo($p)]} {
6824 if {[llength $commitinfo($p)] > 1} {
6825 set l [lindex $commitinfo($p) 0]
6830 # append some text to the ctext widget, and make any SHA1 ID
6831 # that we know about be a clickable link.
6832 proc appendwithlinks {text tags} {
6833 global ctext linknum curview
6835 set start [$ctext index "end - 1c"]
6836 $ctext insert end $text $tags
6837 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6841 set linkid [string range $text $s $e]
6843 $ctext tag delete link$linknum
6844 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6845 setlink $linkid link$linknum
6850 proc setlink {id lk} {
6851 global curview ctext pendinglinks
6854 if {[string range $id 0 1] eq "-g"} {
6855 set id [string range $id 2 end]
6859 if {[string length $id] < 40} {
6860 set matches [longid $id]
6861 if {[llength $matches] > 0} {
6862 if {[llength $matches] > 1} return
6864 set id [lindex $matches 0]
6867 set known [commitinview $id $curview]
6870 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6871 $ctext tag bind $lk <1> [list selbyid $id]
6872 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6873 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6875 lappend pendinglinks($id) $lk
6876 interestedin $id {makelink %P}
6880 proc appendshortlink {id {pre {}} {post {}}} {
6881 global ctext linknum
6883 $ctext insert end $pre
6884 $ctext tag delete link$linknum
6885 $ctext insert end [string range $id 0 7] link$linknum
6886 $ctext insert end $post
6887 setlink $id link$linknum
6891 proc makelink {id} {
6894 if {![info exists pendinglinks($id)]} return
6895 foreach lk $pendinglinks($id) {
6898 unset pendinglinks($id)
6901 proc linkcursor {w inc} {
6902 global linkentercount curtextcursor
6904 if {[incr linkentercount $inc] > 0} {
6905 $w configure -cursor hand2
6907 $w configure -cursor $curtextcursor
6908 if {$linkentercount < 0} {
6909 set linkentercount 0
6914 proc viewnextline {dir} {
6918 set ymax [lindex [$canv cget -scrollregion] 3]
6919 set wnow [$canv yview]
6920 set wtop [expr {[lindex $wnow 0] * $ymax}]
6921 set newtop [expr {$wtop + $dir * $linespc}]
6924 } elseif {$newtop > $ymax} {
6927 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6930 # add a list of tag or branch names at position pos
6931 # returns the number of names inserted
6932 proc appendrefs {pos ids var} {
6933 global ctext linknum curview $var maxrefs mainheadid
6935 if {[catch {$ctext index $pos}]} {
6938 $ctext conf -state normal
6939 $ctext delete $pos "$pos lineend"
6942 foreach tag [set $var\($id\)] {
6943 lappend tags [list $tag $id]
6948 set tags [lsort -index 0 -decreasing $tags]
6951 if {[llength $tags] > $maxrefs} {
6952 # If we are displaying heads, and there are too many,
6953 # see if there are some important heads to display.
6954 # Currently this means "master" and the current head.
6956 if {$var eq "idheads"} {
6959 set hname [lindex $ti 0]
6960 set id [lindex $ti 1]
6961 if {($hname eq "master" || $id eq $mainheadid) &&
6962 [llength $itags] < $maxrefs} {
6971 set str [mc "and many more"]
6976 $ctext insert $pos "$str ([llength $tags])"
6977 set nutags [llength $tags]
6982 set id [lindex $ti 1]
6985 $ctext tag delete $lk
6986 $ctext insert $pos $sep
6987 $ctext insert $pos [lindex $ti 0] $lk
6991 $ctext tag add wwrap "$pos linestart" "$pos lineend"
6992 $ctext conf -state disabled
6993 return [expr {[llength $tags] + $nutags}]
6996 # called when we have finished computing the nearby tags
6997 proc dispneartags {delay} {
6998 global selectedline currentid showneartags tagphase
7000 if {$selectedline eq {} || !$showneartags} return
7001 after cancel dispnexttag
7003 after 200 dispnexttag
7006 after idle dispnexttag
7011 proc dispnexttag {} {
7012 global selectedline currentid showneartags tagphase ctext
7014 if {$selectedline eq {} || !$showneartags} return
7015 switch -- $tagphase {
7017 set dtags [desctags $currentid]
7019 appendrefs precedes $dtags idtags
7023 set atags [anctags $currentid]
7025 appendrefs follows $atags idtags
7029 set dheads [descheads $currentid]
7030 if {$dheads ne {}} {
7031 if {[appendrefs branch $dheads idheads] > 1
7032 && [$ctext get "branch -3c"] eq "h"} {
7033 # turn "Branch" into "Branches"
7034 $ctext conf -state normal
7035 $ctext insert "branch -2c" "es"
7036 $ctext conf -state disabled
7041 if {[incr tagphase] <= 2} {
7042 after idle dispnexttag
7046 proc make_secsel {id} {
7047 global linehtag linentag linedtag canv canv2 canv3
7049 if {![info exists linehtag($id)]} return
7051 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7052 -tags secsel -fill [$canv cget -selectbackground]]
7054 $canv2 delete secsel
7055 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7056 -tags secsel -fill [$canv2 cget -selectbackground]]
7058 $canv3 delete secsel
7059 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7060 -tags secsel -fill [$canv3 cget -selectbackground]]
7064 proc make_idmark {id} {
7065 global linehtag canv fgcolor
7067 if {![info exists linehtag($id)]} return
7069 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7070 -tags markid -outline $fgcolor]
7074 proc selectline {l isnew {desired_loc {}}} {
7075 global canv ctext commitinfo selectedline
7076 global canvy0 linespc parents children curview
7077 global currentid sha1entry
7078 global commentend idtags linknum
7079 global mergemax numcommits pending_select
7080 global cmitmode showneartags allcommits
7081 global targetrow targetid lastscrollrows
7082 global autoselect autosellen jump_to_here
7084 catch {unset pending_select}
7089 if {$l < 0 || $l >= $numcommits} return
7090 set id [commitonrow $l]
7095 if {$lastscrollrows < $numcommits} {
7099 set y [expr {$canvy0 + $l * $linespc}]
7100 set ymax [lindex [$canv cget -scrollregion] 3]
7101 set ytop [expr {$y - $linespc - 1}]
7102 set ybot [expr {$y + $linespc + 1}]
7103 set wnow [$canv yview]
7104 set wtop [expr {[lindex $wnow 0] * $ymax}]
7105 set wbot [expr {[lindex $wnow 1] * $ymax}]
7106 set wh [expr {$wbot - $wtop}]
7108 if {$ytop < $wtop} {
7109 if {$ybot < $wtop} {
7110 set newtop [expr {$y - $wh / 2.0}]
7113 if {$newtop > $wtop - $linespc} {
7114 set newtop [expr {$wtop - $linespc}]
7117 } elseif {$ybot > $wbot} {
7118 if {$ytop > $wbot} {
7119 set newtop [expr {$y - $wh / 2.0}]
7121 set newtop [expr {$ybot - $wh}]
7122 if {$newtop < $wtop + $linespc} {
7123 set newtop [expr {$wtop + $linespc}]
7127 if {$newtop != $wtop} {
7131 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7138 addtohistory [list selbyid $id 0] savecmitpos
7141 $sha1entry delete 0 end
7142 $sha1entry insert 0 $id
7144 $sha1entry selection range 0 $autosellen
7148 $ctext conf -state normal
7151 if {![info exists commitinfo($id)]} {
7154 set info $commitinfo($id)
7155 set date [formatdate [lindex $info 2]]
7156 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7157 set date [formatdate [lindex $info 4]]
7158 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7159 if {[info exists idtags($id)]} {
7160 $ctext insert end [mc "Tags:"]
7161 foreach tag $idtags($id) {
7162 $ctext insert end " $tag"
7164 $ctext insert end "\n"
7168 set olds $parents($curview,$id)
7169 if {[llength $olds] > 1} {
7172 if {$np >= $mergemax} {
7177 $ctext insert end "[mc "Parent"]: " $tag
7178 appendwithlinks [commit_descriptor $p] {}
7183 append headers "[mc "Parent"]: [commit_descriptor $p]"
7187 foreach c $children($curview,$id) {
7188 append headers "[mc "Child"]: [commit_descriptor $c]"
7191 # make anything that looks like a SHA1 ID be a clickable link
7192 appendwithlinks $headers {}
7193 if {$showneartags} {
7194 if {![info exists allcommits]} {
7197 $ctext insert end "[mc "Branch"]: "
7198 $ctext mark set branch "end -1c"
7199 $ctext mark gravity branch left
7200 $ctext insert end "\n[mc "Follows"]: "
7201 $ctext mark set follows "end -1c"
7202 $ctext mark gravity follows left
7203 $ctext insert end "\n[mc "Precedes"]: "
7204 $ctext mark set precedes "end -1c"
7205 $ctext mark gravity precedes left
7206 $ctext insert end "\n"
7209 $ctext insert end "\n"
7210 set comment [lindex $info 5]
7211 if {[string first "\r" $comment] >= 0} {
7212 set comment [string map {"\r" "\n "} $comment]
7214 appendwithlinks $comment {comment}
7216 $ctext tag remove found 1.0 end
7217 $ctext conf -state disabled
7218 set commentend [$ctext index "end - 1c"]
7220 set jump_to_here $desired_loc
7221 init_flist [mc "Comments"]
7222 if {$cmitmode eq "tree"} {
7224 } elseif {[llength $olds] <= 1} {
7231 proc selfirstline {} {
7236 proc sellastline {} {
7239 set l [expr {$numcommits - 1}]
7243 proc selnextline {dir} {
7246 if {$selectedline eq {}} return
7247 set l [expr {$selectedline + $dir}]
7252 proc selnextpage {dir} {
7253 global canv linespc selectedline numcommits
7255 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7259 allcanvs yview scroll [expr {$dir * $lpp}] units
7261 if {$selectedline eq {}} return
7262 set l [expr {$selectedline + $dir * $lpp}]
7265 } elseif {$l >= $numcommits} {
7266 set l [expr $numcommits - 1]
7272 proc unselectline {} {
7273 global selectedline currentid
7276 catch {unset currentid}
7277 allcanvs delete secsel
7281 proc reselectline {} {
7284 if {$selectedline ne {}} {
7285 selectline $selectedline 0
7289 proc addtohistory {cmd {saveproc {}}} {
7290 global history historyindex curview
7294 set elt [list $curview $cmd $saveproc {}]
7295 if {$historyindex > 0
7296 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7300 if {$historyindex < [llength $history]} {
7301 set history [lreplace $history $historyindex end $elt]
7303 lappend history $elt
7306 if {$historyindex > 1} {
7307 .tf.bar.leftbut conf -state normal
7309 .tf.bar.leftbut conf -state disabled
7311 .tf.bar.rightbut conf -state disabled
7314 # save the scrolling position of the diff display pane
7315 proc save_position {} {
7316 global historyindex history
7318 if {$historyindex < 1} return
7319 set hi [expr {$historyindex - 1}]
7320 set fn [lindex $history $hi 2]
7322 lset history $hi 3 [eval $fn]
7326 proc unset_posvars {} {
7329 if {[info exists last_posvars]} {
7330 foreach {var val} $last_posvars {
7339 global curview last_posvars
7341 set view [lindex $elt 0]
7342 set cmd [lindex $elt 1]
7343 set pv [lindex $elt 3]
7344 if {$curview != $view} {
7348 foreach {var val} $pv {
7352 set last_posvars $pv
7357 global history historyindex
7360 if {$historyindex > 1} {
7362 incr historyindex -1
7363 godo [lindex $history [expr {$historyindex - 1}]]
7364 .tf.bar.rightbut conf -state normal
7366 if {$historyindex <= 1} {
7367 .tf.bar.leftbut conf -state disabled
7372 global history historyindex
7375 if {$historyindex < [llength $history]} {
7377 set cmd [lindex $history $historyindex]
7380 .tf.bar.leftbut conf -state normal
7382 if {$historyindex >= [llength $history]} {
7383 .tf.bar.rightbut conf -state disabled
7388 global treefilelist treeidlist diffids diffmergeid treepending
7389 global nullid nullid2
7392 catch {unset diffmergeid}
7393 if {![info exists treefilelist($id)]} {
7394 if {![info exists treepending]} {
7395 if {$id eq $nullid} {
7396 set cmd [list | git ls-files]
7397 } elseif {$id eq $nullid2} {
7398 set cmd [list | git ls-files --stage -t]
7400 set cmd [list | git ls-tree -r $id]
7402 if {[catch {set gtf [open $cmd r]}]} {
7406 set treefilelist($id) {}
7407 set treeidlist($id) {}
7408 fconfigure $gtf -blocking 0 -encoding binary
7409 filerun $gtf [list gettreeline $gtf $id]
7416 proc gettreeline {gtf id} {
7417 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7420 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7421 if {$diffids eq $nullid} {
7424 set i [string first "\t" $line]
7425 if {$i < 0} continue
7426 set fname [string range $line [expr {$i+1}] end]
7427 set line [string range $line 0 [expr {$i-1}]]
7428 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7429 set sha1 [lindex $line 2]
7430 lappend treeidlist($id) $sha1
7432 if {[string index $fname 0] eq "\""} {
7433 set fname [lindex $fname 0]
7435 set fname [encoding convertfrom $fname]
7436 lappend treefilelist($id) $fname
7439 return [expr {$nl >= 1000? 2: 1}]
7443 if {$cmitmode ne "tree"} {
7444 if {![info exists diffmergeid]} {
7445 gettreediffs $diffids
7447 } elseif {$id ne $diffids} {
7456 global treefilelist treeidlist diffids nullid nullid2
7457 global ctext_file_names ctext_file_lines
7458 global ctext commentend
7460 set i [lsearch -exact $treefilelist($diffids) $f]
7462 puts "oops, $f not in list for id $diffids"
7465 if {$diffids eq $nullid} {
7466 if {[catch {set bf [open $f r]} err]} {
7467 puts "oops, can't read $f: $err"
7471 set blob [lindex $treeidlist($diffids) $i]
7472 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7473 puts "oops, error reading blob $blob: $err"
7477 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7478 filerun $bf [list getblobline $bf $diffids]
7479 $ctext config -state normal
7480 clear_ctext $commentend
7481 lappend ctext_file_names $f
7482 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7483 $ctext insert end "\n"
7484 $ctext insert end "$f\n" filesep
7485 $ctext config -state disabled
7486 $ctext yview $commentend
7490 proc getblobline {bf id} {
7491 global diffids cmitmode ctext
7493 if {$id ne $diffids || $cmitmode ne "tree"} {
7497 $ctext config -state normal
7499 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7500 $ctext insert end "$line\n"
7503 global jump_to_here ctext_file_names commentend
7505 # delete last newline
7506 $ctext delete "end - 2c" "end - 1c"
7508 if {$jump_to_here ne {} &&
7509 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7510 set lnum [expr {[lindex $jump_to_here 1] +
7511 [lindex [split $commentend .] 0]}]
7512 mark_ctext_line $lnum
7514 $ctext config -state disabled
7517 $ctext config -state disabled
7518 return [expr {$nl >= 1000? 2: 1}]
7521 proc mark_ctext_line {lnum} {
7522 global ctext markbgcolor
7524 $ctext tag delete omark
7525 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7526 $ctext tag conf omark -background $markbgcolor
7530 proc mergediff {id} {
7532 global diffids treediffs
7533 global parents curview
7537 set treediffs($id) {}
7538 set np [llength $parents($curview,$id)]
7543 proc startdiff {ids} {
7544 global treediffs diffids treepending diffmergeid nullid nullid2
7548 catch {unset diffmergeid}
7549 if {![info exists treediffs($ids)] ||
7550 [lsearch -exact $ids $nullid] >= 0 ||
7551 [lsearch -exact $ids $nullid2] >= 0} {
7552 if {![info exists treepending]} {
7560 # If the filename (name) is under any of the passed filter paths
7561 # then return true to include the file in the listing.
7562 proc path_filter {filter name} {
7563 set worktree [gitworktree]
7565 set fq_p [file normalize $p]
7566 set fq_n [file normalize [file join $worktree $name]]
7567 if {[string match [file normalize $fq_p]* $fq_n]} {
7574 proc addtocflist {ids} {
7577 add_flist $treediffs($ids)
7581 proc diffcmd {ids flags} {
7582 global log_showroot nullid nullid2
7584 set i [lsearch -exact $ids $nullid]
7585 set j [lsearch -exact $ids $nullid2]
7587 if {[llength $ids] > 1 && $j < 0} {
7588 # comparing working directory with some specific revision
7589 set cmd [concat | git diff-index $flags]
7591 lappend cmd -R [lindex $ids 1]
7593 lappend cmd [lindex $ids 0]
7596 # comparing working directory with index
7597 set cmd [concat | git diff-files $flags]
7602 } elseif {$j >= 0} {
7603 set cmd [concat | git diff-index --cached $flags]
7604 if {[llength $ids] > 1} {
7605 # comparing index with specific revision
7607 lappend cmd -R [lindex $ids 1]
7609 lappend cmd [lindex $ids 0]
7612 # comparing index with HEAD
7616 if {$log_showroot} {
7617 lappend flags --root
7619 set cmd [concat | git diff-tree -r $flags $ids]
7624 proc gettreediffs {ids} {
7625 global treediff treepending limitdiffs vfilelimit curview
7627 set cmd [diffcmd $ids {--no-commit-id}]
7628 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7629 set cmd [concat $cmd -- $vfilelimit($curview)]
7631 if {[catch {set gdtf [open $cmd r]}]} return
7633 set treepending $ids
7635 fconfigure $gdtf -blocking 0 -encoding binary
7636 filerun $gdtf [list gettreediffline $gdtf $ids]
7639 proc gettreediffline {gdtf ids} {
7640 global treediff treediffs treepending diffids diffmergeid
7641 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7646 if {$perfile_attrs} {
7647 # cache_gitattr is slow, and even slower on win32 where we
7648 # have to invoke it for only about 30 paths at a time
7650 if {[tk windowingsystem] == "win32"} {
7654 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7655 set i [string first "\t" $line]
7657 set file [string range $line [expr {$i+1}] end]
7658 if {[string index $file 0] eq "\""} {
7659 set file [lindex $file 0]
7661 set file [encoding convertfrom $file]
7662 if {$file ne [lindex $treediff end]} {
7663 lappend treediff $file
7664 lappend sublist $file
7668 if {$perfile_attrs} {
7669 cache_gitattr encoding $sublist
7672 return [expr {$nr >= $max? 2: 1}]
7675 set treediffs($ids) $treediff
7677 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7679 } elseif {$ids != $diffids} {
7680 if {![info exists diffmergeid]} {
7681 gettreediffs $diffids
7689 # empty string or positive integer
7690 proc diffcontextvalidate {v} {
7691 return [regexp {^(|[1-9][0-9]*)$} $v]
7694 proc diffcontextchange {n1 n2 op} {
7695 global diffcontextstring diffcontext
7697 if {[string is integer -strict $diffcontextstring]} {
7698 if {$diffcontextstring >= 0} {
7699 set diffcontext $diffcontextstring
7705 proc changeignorespace {} {
7709 proc changeworddiff {name ix op} {
7713 proc getblobdiffs {ids} {
7714 global blobdifffd diffids env
7715 global diffinhdr treediffs
7719 global limitdiffs vfilelimit curview
7720 global diffencoding targetline diffnparents
7721 global git_version currdiffsubmod
7724 if {[package vcompare $git_version "1.6.1"] >= 0} {
7725 set textconv "--textconv"
7728 if {[package vcompare $git_version "1.6.6"] >= 0} {
7729 set submodule "--submodule"
7731 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7735 if {$worddiff ne [mc "Line diff"]} {
7736 append cmd " --word-diff=porcelain"
7738 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7739 set cmd [concat $cmd -- $vfilelimit($curview)]
7741 if {[catch {set bdf [open $cmd r]} err]} {
7742 error_popup [mc "Error getting diffs: %s" $err]
7748 set diffencoding [get_path_encoding {}]
7749 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7750 set blobdifffd($ids) $bdf
7751 set currdiffsubmod ""
7752 filerun $bdf [list getblobdiffline $bdf $diffids]
7755 proc savecmitpos {} {
7756 global ctext cmitmode
7758 if {$cmitmode eq "tree"} {
7761 return [list target_scrollpos [$ctext index @0,0]]
7764 proc savectextpos {} {
7767 return [list target_scrollpos [$ctext index @0,0]]
7770 proc maybe_scroll_ctext {ateof} {
7771 global ctext target_scrollpos
7773 if {![info exists target_scrollpos]} return
7775 set nlines [expr {[winfo height $ctext]
7776 / [font metrics textfont -linespace]}]
7777 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7779 $ctext yview $target_scrollpos
7780 unset target_scrollpos
7783 proc setinlist {var i val} {
7786 while {[llength [set $var]] < $i} {
7789 if {[llength [set $var]] == $i} {
7796 proc makediffhdr {fname ids} {
7797 global ctext curdiffstart treediffs diffencoding
7798 global ctext_file_names jump_to_here targetline diffline
7800 set fname [encoding convertfrom $fname]
7801 set diffencoding [get_path_encoding $fname]
7802 set i [lsearch -exact $treediffs($ids) $fname]
7804 setinlist difffilestart $i $curdiffstart
7806 lset ctext_file_names end $fname
7807 set l [expr {(78 - [string length $fname]) / 2}]
7808 set pad [string range "----------------------------------------" 1 $l]
7809 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7811 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7812 set targetline [lindex $jump_to_here 1]
7817 proc getblobdiffline {bdf ids} {
7818 global diffids blobdifffd ctext curdiffstart
7819 global diffnexthead diffnextnote difffilestart
7820 global ctext_file_names ctext_file_lines
7821 global diffinhdr treediffs mergemax diffnparents
7822 global diffencoding jump_to_here targetline diffline currdiffsubmod
7826 $ctext conf -state normal
7827 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7828 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7832 if {![string compare -length 5 "diff " $line]} {
7833 if {![regexp {^diff (--cc|--git) } $line m type]} {
7834 set line [encoding convertfrom $line]
7835 $ctext insert end "$line\n" hunksep
7838 # start of a new file
7840 $ctext insert end "\n"
7841 set curdiffstart [$ctext index "end - 1c"]
7842 lappend ctext_file_names ""
7843 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7844 $ctext insert end "\n" filesep
7846 if {$type eq "--cc"} {
7847 # start of a new file in a merge diff
7848 set fname [string range $line 10 end]
7849 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7850 lappend treediffs($ids) $fname
7851 add_flist [list $fname]
7855 set line [string range $line 11 end]
7856 # If the name hasn't changed the length will be odd,
7857 # the middle char will be a space, and the two bits either
7858 # side will be a/name and b/name, or "a/name" and "b/name".
7859 # If the name has changed we'll get "rename from" and
7860 # "rename to" or "copy from" and "copy to" lines following
7861 # this, and we'll use them to get the filenames.
7862 # This complexity is necessary because spaces in the
7863 # filename(s) don't get escaped.
7864 set l [string length $line]
7865 set i [expr {$l / 2}]
7866 if {!(($l & 1) && [string index $line $i] eq " " &&
7867 [string range $line 2 [expr {$i - 1}]] eq \
7868 [string range $line [expr {$i + 3}] end])} {
7871 # unescape if quoted and chop off the a/ from the front
7872 if {[string index $line 0] eq "\""} {
7873 set fname [string range [lindex $line 0] 2 end]
7875 set fname [string range $line 2 [expr {$i - 1}]]
7878 makediffhdr $fname $ids
7880 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
7881 set fname [encoding convertfrom [string range $line 16 end]]
7882 $ctext insert end "\n"
7883 set curdiffstart [$ctext index "end - 1c"]
7884 lappend ctext_file_names $fname
7885 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7886 $ctext insert end "$line\n" filesep
7887 set i [lsearch -exact $treediffs($ids) $fname]
7889 setinlist difffilestart $i $curdiffstart
7892 } elseif {![string compare -length 2 "@@" $line]} {
7893 regexp {^@@+} $line ats
7894 set line [encoding convertfrom $diffencoding $line]
7895 $ctext insert end "$line\n" hunksep
7896 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
7899 set diffnparents [expr {[string length $ats] - 1}]
7902 } elseif {![string compare -length 10 "Submodule " $line]} {
7903 # start of a new submodule
7904 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7905 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7907 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7909 if {$currdiffsubmod != $fname} {
7910 $ctext insert end "\n"; # Add newline after commit message
7912 set curdiffstart [$ctext index "end - 1c"]
7913 lappend ctext_file_names ""
7914 if {$currdiffsubmod != $fname} {
7915 lappend ctext_file_lines $fname
7916 makediffhdr $fname $ids
7917 set currdiffsubmod $fname
7918 $ctext insert end "\n$line\n" filesep
7920 $ctext insert end "$line\n" filesep
7922 } elseif {![string compare -length 3 " >" $line]} {
7923 set $currdiffsubmod ""
7924 set line [encoding convertfrom $diffencoding $line]
7925 $ctext insert end "$line\n" dresult
7926 } elseif {![string compare -length 3 " <" $line]} {
7927 set $currdiffsubmod ""
7928 set line [encoding convertfrom $diffencoding $line]
7929 $ctext insert end "$line\n" d0
7930 } elseif {$diffinhdr} {
7931 if {![string compare -length 12 "rename from " $line]} {
7932 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
7933 if {[string index $fname 0] eq "\""} {
7934 set fname [lindex $fname 0]
7936 set fname [encoding convertfrom $fname]
7937 set i [lsearch -exact $treediffs($ids) $fname]
7939 setinlist difffilestart $i $curdiffstart
7941 } elseif {![string compare -length 10 $line "rename to "] ||
7942 ![string compare -length 8 $line "copy to "]} {
7943 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
7944 if {[string index $fname 0] eq "\""} {
7945 set fname [lindex $fname 0]
7947 makediffhdr $fname $ids
7948 } elseif {[string compare -length 3 $line "---"] == 0} {
7951 } elseif {[string compare -length 3 $line "+++"] == 0} {
7955 set line [encoding convertfrom $line]
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 cmd [concat $cmd $ids]
9795 # The maximum command line length for the CreateProcess function is 32767 characters, see
9796 # http://blogs.msdn.com/oldnewthing/archive/2003/12/10/56028.aspx
9797 # Be a little conservative in case Tcl adds some more stuff to the command line we do not
9798 # know about and truncate the command line at a SHA1-boundary below 32000 characters.
9799 if {[tk windowingsystem] == "win32" &&
9800 [string length $cmd] > 32000} {
9801 set ndx [string last " " $cmd 32000]
9803 set cmd [string range $cmd 0 $ndx]
9806 set fd [open $cmd r]
9807 fconfigure $fd -blocking 0
9810 filerun $fd [list getallclines $fd]
9816 # Since most commits have 1 parent and 1 child, we group strings of
9817 # such commits into "arcs" joining branch/merge points (BMPs), which
9818 # are commits that either don't have 1 parent or don't have 1 child.
9820 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9821 # arcout(id) - outgoing arcs for BMP
9822 # arcids(a) - list of IDs on arc including end but not start
9823 # arcstart(a) - BMP ID at start of arc
9824 # arcend(a) - BMP ID at end of arc
9825 # growing(a) - arc a is still growing
9826 # arctags(a) - IDs out of arcids (excluding end) that have tags
9827 # archeads(a) - IDs out of arcids (excluding end) that have heads
9828 # The start of an arc is at the descendent end, so "incoming" means
9829 # coming from descendents, and "outgoing" means going towards ancestors.
9831 proc getallclines {fd} {
9832 global allparents allchildren idtags idheads nextarc
9833 global arcnos arcids arctags arcout arcend arcstart archeads growing
9834 global seeds allcommits cachedarcs allcupdate
9837 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9838 set id [lindex $line 0]
9839 if {[info exists allparents($id)]} {
9844 set olds [lrange $line 1 end]
9845 set allparents($id) $olds
9846 if {![info exists allchildren($id)]} {
9847 set allchildren($id) {}
9852 if {[llength $olds] == 1 && [llength $a] == 1} {
9853 lappend arcids($a) $id
9854 if {[info exists idtags($id)]} {
9855 lappend arctags($a) $id
9857 if {[info exists idheads($id)]} {
9858 lappend archeads($a) $id
9860 if {[info exists allparents($olds)]} {
9861 # seen parent already
9862 if {![info exists arcout($olds)]} {
9865 lappend arcids($a) $olds
9866 set arcend($a) $olds
9869 lappend allchildren($olds) $id
9870 lappend arcnos($olds) $a
9874 foreach a $arcnos($id) {
9875 lappend arcids($a) $id
9882 lappend allchildren($p) $id
9883 set a [incr nextarc]
9884 set arcstart($a) $id
9891 if {[info exists allparents($p)]} {
9892 # seen it already, may need to make a new branch
9893 if {![info exists arcout($p)]} {
9896 lappend arcids($a) $p
9900 lappend arcnos($p) $a
9905 global cached_dheads cached_dtags cached_atags
9906 catch {unset cached_dheads}
9907 catch {unset cached_dtags}
9908 catch {unset cached_atags}
9911 return [expr {$nid >= 1000? 2: 1}]
9915 fconfigure $fd -blocking 1
9918 # got an error reading the list of commits
9919 # if we were updating, try rereading the whole thing again
9925 error_popup "[mc "Error reading commit topology information;\
9926 branch and preceding/following tag information\
9927 will be incomplete."]\n($err)"
9930 if {[incr allcommits -1] == 0} {
9940 proc recalcarc {a} {
9941 global arctags archeads arcids idtags idheads
9945 foreach id [lrange $arcids($a) 0 end-1] {
9946 if {[info exists idtags($id)]} {
9949 if {[info exists idheads($id)]} {
9954 set archeads($a) $ah
9958 global arcnos arcids nextarc arctags archeads idtags idheads
9959 global arcstart arcend arcout allparents growing
9962 if {[llength $a] != 1} {
9963 puts "oops splitarc called but [llength $a] arcs already"
9967 set i [lsearch -exact $arcids($a) $p]
9969 puts "oops splitarc $p not in arc $a"
9972 set na [incr nextarc]
9973 if {[info exists arcend($a)]} {
9974 set arcend($na) $arcend($a)
9976 set l [lindex $allparents([lindex $arcids($a) end]) 0]
9977 set j [lsearch -exact $arcnos($l) $a]
9978 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
9980 set tail [lrange $arcids($a) [expr {$i+1}] end]
9981 set arcids($a) [lrange $arcids($a) 0 $i]
9983 set arcstart($na) $p
9985 set arcids($na) $tail
9986 if {[info exists growing($a)]} {
9992 if {[llength $arcnos($id)] == 1} {
9995 set j [lsearch -exact $arcnos($id) $a]
9996 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10000 # reconstruct tags and heads lists
10001 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10005 set arctags($na) {}
10006 set archeads($na) {}
10010 # Update things for a new commit added that is a child of one
10011 # existing commit. Used when cherry-picking.
10012 proc addnewchild {id p} {
10013 global allparents allchildren idtags nextarc
10014 global arcnos arcids arctags arcout arcend arcstart archeads growing
10015 global seeds allcommits
10017 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10018 set allparents($id) [list $p]
10019 set allchildren($id) {}
10022 lappend allchildren($p) $id
10023 set a [incr nextarc]
10024 set arcstart($a) $id
10025 set archeads($a) {}
10027 set arcids($a) [list $p]
10029 if {![info exists arcout($p)]} {
10032 lappend arcnos($p) $a
10033 set arcout($id) [list $a]
10036 # This implements a cache for the topology information.
10037 # The cache saves, for each arc, the start and end of the arc,
10038 # the ids on the arc, and the outgoing arcs from the end.
10039 proc readcache {f} {
10040 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10041 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10045 set lim $cachedarcs
10046 if {$lim - $a > 500} {
10047 set lim [expr {$a + 500}]
10051 # finish reading the cache and setting up arctags, etc.
10053 if {$line ne "1"} {error "bad final version"}
10055 foreach id [array names idtags] {
10056 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10057 [llength $allparents($id)] == 1} {
10058 set a [lindex $arcnos($id) 0]
10059 if {$arctags($a) eq {}} {
10064 foreach id [array names idheads] {
10065 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10066 [llength $allparents($id)] == 1} {
10067 set a [lindex $arcnos($id) 0]
10068 if {$archeads($a) eq {}} {
10073 foreach id [lsort -unique $possible_seeds] {
10074 if {$arcnos($id) eq {}} {
10080 while {[incr a] <= $lim} {
10082 if {[llength $line] != 3} {error "bad line"}
10083 set s [lindex $line 0]
10084 set arcstart($a) $s
10085 lappend arcout($s) $a
10086 if {![info exists arcnos($s)]} {
10087 lappend possible_seeds $s
10090 set e [lindex $line 1]
10095 if {![info exists arcout($e)]} {
10099 set arcids($a) [lindex $line 2]
10100 foreach id $arcids($a) {
10101 lappend allparents($s) $id
10103 lappend arcnos($id) $a
10105 if {![info exists allparents($s)]} {
10106 set allparents($s) {}
10109 set archeads($a) {}
10111 set nextarc [expr {$a - 1}]
10123 proc getcache {f} {
10124 global nextarc cachedarcs possible_seeds
10128 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10129 # make sure it's an integer
10130 set cachedarcs [expr {int([lindex $line 1])}]
10131 if {$cachedarcs < 0} {error "bad number of arcs"}
10133 set possible_seeds {}
10141 proc dropcache {err} {
10142 global allcwait nextarc cachedarcs seeds
10144 #puts "dropping cache ($err)"
10145 foreach v {arcnos arcout arcids arcstart arcend growing \
10146 arctags archeads allparents allchildren} {
10157 proc writecache {f} {
10158 global cachearc cachedarcs allccache
10159 global arcstart arcend arcnos arcids arcout
10162 set lim $cachedarcs
10163 if {$lim - $a > 1000} {
10164 set lim [expr {$a + 1000}]
10167 while {[incr a] <= $lim} {
10168 if {[info exists arcend($a)]} {
10169 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10171 puts $f [list $arcstart($a) {} $arcids($a)]
10176 catch {file delete $allccache}
10177 #puts "writing cache failed ($err)"
10180 set cachearc [expr {$a - 1}]
10181 if {$a > $cachedarcs} {
10189 proc savecache {} {
10190 global nextarc cachedarcs cachearc allccache
10192 if {$nextarc == $cachedarcs} return
10194 set cachedarcs $nextarc
10196 set f [open $allccache w]
10197 puts $f [list 1 $cachedarcs]
10202 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10203 # or 0 if neither is true.
10204 proc anc_or_desc {a b} {
10205 global arcout arcstart arcend arcnos cached_isanc
10207 if {$arcnos($a) eq $arcnos($b)} {
10208 # Both are on the same arc(s); either both are the same BMP,
10209 # or if one is not a BMP, the other is also not a BMP or is
10210 # the BMP at end of the arc (and it only has 1 incoming arc).
10211 # Or both can be BMPs with no incoming arcs.
10212 if {$a eq $b || $arcnos($a) eq {}} {
10215 # assert {[llength $arcnos($a)] == 1}
10216 set arc [lindex $arcnos($a) 0]
10217 set i [lsearch -exact $arcids($arc) $a]
10218 set j [lsearch -exact $arcids($arc) $b]
10219 if {$i < 0 || $i > $j} {
10226 if {![info exists arcout($a)]} {
10227 set arc [lindex $arcnos($a) 0]
10228 if {[info exists arcend($arc)]} {
10229 set aend $arcend($arc)
10233 set a $arcstart($arc)
10237 if {![info exists arcout($b)]} {
10238 set arc [lindex $arcnos($b) 0]
10239 if {[info exists arcend($arc)]} {
10240 set bend $arcend($arc)
10244 set b $arcstart($arc)
10254 if {[info exists cached_isanc($a,$bend)]} {
10255 if {$cached_isanc($a,$bend)} {
10259 if {[info exists cached_isanc($b,$aend)]} {
10260 if {$cached_isanc($b,$aend)} {
10263 if {[info exists cached_isanc($a,$bend)]} {
10268 set todo [list $a $b]
10271 for {set i 0} {$i < [llength $todo]} {incr i} {
10272 set x [lindex $todo $i]
10273 if {$anc($x) eq {}} {
10276 foreach arc $arcnos($x) {
10277 set xd $arcstart($arc)
10278 if {$xd eq $bend} {
10279 set cached_isanc($a,$bend) 1
10280 set cached_isanc($b,$aend) 0
10282 } elseif {$xd eq $aend} {
10283 set cached_isanc($b,$aend) 1
10284 set cached_isanc($a,$bend) 0
10287 if {![info exists anc($xd)]} {
10288 set anc($xd) $anc($x)
10290 } elseif {$anc($xd) ne $anc($x)} {
10295 set cached_isanc($a,$bend) 0
10296 set cached_isanc($b,$aend) 0
10300 # This identifies whether $desc has an ancestor that is
10301 # a growing tip of the graph and which is not an ancestor of $anc
10302 # and returns 0 if so and 1 if not.
10303 # If we subsequently discover a tag on such a growing tip, and that
10304 # turns out to be a descendent of $anc (which it could, since we
10305 # don't necessarily see children before parents), then $desc
10306 # isn't a good choice to display as a descendent tag of
10307 # $anc (since it is the descendent of another tag which is
10308 # a descendent of $anc). Similarly, $anc isn't a good choice to
10309 # display as a ancestor tag of $desc.
10311 proc is_certain {desc anc} {
10312 global arcnos arcout arcstart arcend growing problems
10315 if {[llength $arcnos($anc)] == 1} {
10316 # tags on the same arc are certain
10317 if {$arcnos($desc) eq $arcnos($anc)} {
10320 if {![info exists arcout($anc)]} {
10321 # if $anc is partway along an arc, use the start of the arc instead
10322 set a [lindex $arcnos($anc) 0]
10323 set anc $arcstart($a)
10326 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10329 set a [lindex $arcnos($desc) 0]
10335 set anclist [list $x]
10339 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10340 set x [lindex $anclist $i]
10345 foreach a $arcout($x) {
10346 if {[info exists growing($a)]} {
10347 if {![info exists growanc($x)] && $dl($x)} {
10353 if {[info exists dl($y)]} {
10357 if {![info exists done($y)]} {
10360 if {[info exists growanc($x)]} {
10364 for {set k 0} {$k < [llength $xl]} {incr k} {
10365 set z [lindex $xl $k]
10366 foreach c $arcout($z) {
10367 if {[info exists arcend($c)]} {
10369 if {[info exists dl($v)] && $dl($v)} {
10371 if {![info exists done($v)]} {
10374 if {[info exists growanc($v)]} {
10384 } elseif {$y eq $anc || !$dl($x)} {
10395 foreach x [array names growanc] {
10404 proc validate_arctags {a} {
10405 global arctags idtags
10408 set na $arctags($a)
10409 foreach id $arctags($a) {
10411 if {![info exists idtags($id)]} {
10412 set na [lreplace $na $i $i]
10416 set arctags($a) $na
10419 proc validate_archeads {a} {
10420 global archeads idheads
10423 set na $archeads($a)
10424 foreach id $archeads($a) {
10426 if {![info exists idheads($id)]} {
10427 set na [lreplace $na $i $i]
10431 set archeads($a) $na
10434 # Return the list of IDs that have tags that are descendents of id,
10435 # ignoring IDs that are descendents of IDs already reported.
10436 proc desctags {id} {
10437 global arcnos arcstart arcids arctags idtags allparents
10438 global growing cached_dtags
10440 if {![info exists allparents($id)]} {
10443 set t1 [clock clicks -milliseconds]
10445 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10446 # part-way along an arc; check that arc first
10447 set a [lindex $arcnos($id) 0]
10448 if {$arctags($a) ne {}} {
10449 validate_arctags $a
10450 set i [lsearch -exact $arcids($a) $id]
10452 foreach t $arctags($a) {
10453 set j [lsearch -exact $arcids($a) $t]
10454 if {$j >= $i} break
10461 set id $arcstart($a)
10462 if {[info exists idtags($id)]} {
10466 if {[info exists cached_dtags($id)]} {
10467 return $cached_dtags($id)
10471 set todo [list $id]
10474 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10475 set id [lindex $todo $i]
10477 set ta [info exists hastaggedancestor($id)]
10481 # ignore tags on starting node
10482 if {!$ta && $i > 0} {
10483 if {[info exists idtags($id)]} {
10484 set tagloc($id) $id
10486 } elseif {[info exists cached_dtags($id)]} {
10487 set tagloc($id) $cached_dtags($id)
10491 foreach a $arcnos($id) {
10492 set d $arcstart($a)
10493 if {!$ta && $arctags($a) ne {}} {
10494 validate_arctags $a
10495 if {$arctags($a) ne {}} {
10496 lappend tagloc($id) [lindex $arctags($a) end]
10499 if {$ta || $arctags($a) ne {}} {
10500 set tomark [list $d]
10501 for {set j 0} {$j < [llength $tomark]} {incr j} {
10502 set dd [lindex $tomark $j]
10503 if {![info exists hastaggedancestor($dd)]} {
10504 if {[info exists done($dd)]} {
10505 foreach b $arcnos($dd) {
10506 lappend tomark $arcstart($b)
10508 if {[info exists tagloc($dd)]} {
10511 } elseif {[info exists queued($dd)]} {
10514 set hastaggedancestor($dd) 1
10518 if {![info exists queued($d)]} {
10521 if {![info exists hastaggedancestor($d)]} {
10528 foreach id [array names tagloc] {
10529 if {![info exists hastaggedancestor($id)]} {
10530 foreach t $tagloc($id) {
10531 if {[lsearch -exact $tags $t] < 0} {
10537 set t2 [clock clicks -milliseconds]
10540 # remove tags that are descendents of other tags
10541 for {set i 0} {$i < [llength $tags]} {incr i} {
10542 set a [lindex $tags $i]
10543 for {set j 0} {$j < $i} {incr j} {
10544 set b [lindex $tags $j]
10545 set r [anc_or_desc $a $b]
10547 set tags [lreplace $tags $j $j]
10550 } elseif {$r == -1} {
10551 set tags [lreplace $tags $i $i]
10558 if {[array names growing] ne {}} {
10559 # graph isn't finished, need to check if any tag could get
10560 # eclipsed by another tag coming later. Simply ignore any
10561 # tags that could later get eclipsed.
10564 if {[is_certain $t $origid]} {
10568 if {$tags eq $ctags} {
10569 set cached_dtags($origid) $tags
10574 set cached_dtags($origid) $tags
10576 set t3 [clock clicks -milliseconds]
10577 if {0 && $t3 - $t1 >= 100} {
10578 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10579 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10584 proc anctags {id} {
10585 global arcnos arcids arcout arcend arctags idtags allparents
10586 global growing cached_atags
10588 if {![info exists allparents($id)]} {
10591 set t1 [clock clicks -milliseconds]
10593 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10594 # part-way along an arc; check that arc first
10595 set a [lindex $arcnos($id) 0]
10596 if {$arctags($a) ne {}} {
10597 validate_arctags $a
10598 set i [lsearch -exact $arcids($a) $id]
10599 foreach t $arctags($a) {
10600 set j [lsearch -exact $arcids($a) $t]
10606 if {![info exists arcend($a)]} {
10610 if {[info exists idtags($id)]} {
10614 if {[info exists cached_atags($id)]} {
10615 return $cached_atags($id)
10619 set todo [list $id]
10623 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10624 set id [lindex $todo $i]
10626 set td [info exists hastaggeddescendent($id)]
10630 # ignore tags on starting node
10631 if {!$td && $i > 0} {
10632 if {[info exists idtags($id)]} {
10633 set tagloc($id) $id
10635 } elseif {[info exists cached_atags($id)]} {
10636 set tagloc($id) $cached_atags($id)
10640 foreach a $arcout($id) {
10641 if {!$td && $arctags($a) ne {}} {
10642 validate_arctags $a
10643 if {$arctags($a) ne {}} {
10644 lappend tagloc($id) [lindex $arctags($a) 0]
10647 if {![info exists arcend($a)]} continue
10649 if {$td || $arctags($a) ne {}} {
10650 set tomark [list $d]
10651 for {set j 0} {$j < [llength $tomark]} {incr j} {
10652 set dd [lindex $tomark $j]
10653 if {![info exists hastaggeddescendent($dd)]} {
10654 if {[info exists done($dd)]} {
10655 foreach b $arcout($dd) {
10656 if {[info exists arcend($b)]} {
10657 lappend tomark $arcend($b)
10660 if {[info exists tagloc($dd)]} {
10663 } elseif {[info exists queued($dd)]} {
10666 set hastaggeddescendent($dd) 1
10670 if {![info exists queued($d)]} {
10673 if {![info exists hastaggeddescendent($d)]} {
10679 set t2 [clock clicks -milliseconds]
10682 foreach id [array names tagloc] {
10683 if {![info exists hastaggeddescendent($id)]} {
10684 foreach t $tagloc($id) {
10685 if {[lsearch -exact $tags $t] < 0} {
10692 # remove tags that are ancestors of other tags
10693 for {set i 0} {$i < [llength $tags]} {incr i} {
10694 set a [lindex $tags $i]
10695 for {set j 0} {$j < $i} {incr j} {
10696 set b [lindex $tags $j]
10697 set r [anc_or_desc $a $b]
10699 set tags [lreplace $tags $j $j]
10702 } elseif {$r == 1} {
10703 set tags [lreplace $tags $i $i]
10710 if {[array names growing] ne {}} {
10711 # graph isn't finished, need to check if any tag could get
10712 # eclipsed by another tag coming later. Simply ignore any
10713 # tags that could later get eclipsed.
10716 if {[is_certain $origid $t]} {
10720 if {$tags eq $ctags} {
10721 set cached_atags($origid) $tags
10726 set cached_atags($origid) $tags
10728 set t3 [clock clicks -milliseconds]
10729 if {0 && $t3 - $t1 >= 100} {
10730 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10731 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10736 # Return the list of IDs that have heads that are descendents of id,
10737 # including id itself if it has a head.
10738 proc descheads {id} {
10739 global arcnos arcstart arcids archeads idheads cached_dheads
10740 global allparents arcout
10742 if {![info exists allparents($id)]} {
10746 if {![info exists arcout($id)]} {
10747 # part-way along an arc; check it first
10748 set a [lindex $arcnos($id) 0]
10749 if {$archeads($a) ne {}} {
10750 validate_archeads $a
10751 set i [lsearch -exact $arcids($a) $id]
10752 foreach t $archeads($a) {
10753 set j [lsearch -exact $arcids($a) $t]
10758 set id $arcstart($a)
10761 set todo [list $id]
10764 for {set i 0} {$i < [llength $todo]} {incr i} {
10765 set id [lindex $todo $i]
10766 if {[info exists cached_dheads($id)]} {
10767 set ret [concat $ret $cached_dheads($id)]
10769 if {[info exists idheads($id)]} {
10772 foreach a $arcnos($id) {
10773 if {$archeads($a) ne {}} {
10774 validate_archeads $a
10775 if {$archeads($a) ne {}} {
10776 set ret [concat $ret $archeads($a)]
10779 set d $arcstart($a)
10780 if {![info exists seen($d)]} {
10787 set ret [lsort -unique $ret]
10788 set cached_dheads($origid) $ret
10789 return [concat $ret $aret]
10792 proc addedtag {id} {
10793 global arcnos arcout cached_dtags cached_atags
10795 if {![info exists arcnos($id)]} return
10796 if {![info exists arcout($id)]} {
10797 recalcarc [lindex $arcnos($id) 0]
10799 catch {unset cached_dtags}
10800 catch {unset cached_atags}
10803 proc addedhead {hid head} {
10804 global arcnos arcout cached_dheads
10806 if {![info exists arcnos($hid)]} return
10807 if {![info exists arcout($hid)]} {
10808 recalcarc [lindex $arcnos($hid) 0]
10810 catch {unset cached_dheads}
10813 proc removedhead {hid head} {
10814 global cached_dheads
10816 catch {unset cached_dheads}
10819 proc movedhead {hid head} {
10820 global arcnos arcout cached_dheads
10822 if {![info exists arcnos($hid)]} return
10823 if {![info exists arcout($hid)]} {
10824 recalcarc [lindex $arcnos($hid) 0]
10826 catch {unset cached_dheads}
10829 proc changedrefs {} {
10830 global cached_dheads cached_dtags cached_atags cached_tagcontent
10831 global arctags archeads arcnos arcout idheads idtags
10833 foreach id [concat [array names idheads] [array names idtags]] {
10834 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10835 set a [lindex $arcnos($id) 0]
10836 if {![info exists donearc($a)]} {
10842 catch {unset cached_tagcontent}
10843 catch {unset cached_dtags}
10844 catch {unset cached_atags}
10845 catch {unset cached_dheads}
10848 proc rereadrefs {} {
10849 global idtags idheads idotherrefs mainheadid
10851 set refids [concat [array names idtags] \
10852 [array names idheads] [array names idotherrefs]]
10853 foreach id $refids {
10854 if {![info exists ref($id)]} {
10855 set ref($id) [listrefs $id]
10858 set oldmainhead $mainheadid
10861 set refids [lsort -unique [concat $refids [array names idtags] \
10862 [array names idheads] [array names idotherrefs]]]
10863 foreach id $refids {
10864 set v [listrefs $id]
10865 if {![info exists ref($id)] || $ref($id) != $v} {
10869 if {$oldmainhead ne $mainheadid} {
10870 redrawtags $oldmainhead
10871 redrawtags $mainheadid
10876 proc listrefs {id} {
10877 global idtags idheads idotherrefs
10880 if {[info exists idtags($id)]} {
10884 if {[info exists idheads($id)]} {
10885 set y $idheads($id)
10888 if {[info exists idotherrefs($id)]} {
10889 set z $idotherrefs($id)
10891 return [list $x $y $z]
10894 proc showtag {tag isnew} {
10895 global ctext cached_tagcontent tagids linknum tagobjid
10898 addtohistory [list showtag $tag 0] savectextpos
10900 $ctext conf -state normal
10904 if {![info exists cached_tagcontent($tag)]} {
10906 set cached_tagcontent($tag) [exec git cat-file -p $tag]
10909 if {[info exists cached_tagcontent($tag)]} {
10910 set text $cached_tagcontent($tag)
10912 set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)"
10914 appendwithlinks $text {}
10915 maybe_scroll_ctext 1
10916 $ctext conf -state disabled
10928 if {[info exists gitktmpdir]} {
10929 catch {file delete -force $gitktmpdir}
10933 proc mkfontdisp {font top which} {
10934 global fontattr fontpref $font NS use_ttk
10936 set fontpref($font) [set $font]
10937 ${NS}::button $top.${font}but -text $which \
10938 -command [list choosefont $font $which]
10939 ${NS}::label $top.$font -relief flat -font $font \
10940 -text $fontattr($font,family) -justify left
10941 grid x $top.${font}but $top.$font -sticky w
10944 proc choosefont {font which} {
10945 global fontparam fontlist fonttop fontattr
10948 set fontparam(which) $which
10949 set fontparam(font) $font
10950 set fontparam(family) [font actual $font -family]
10951 set fontparam(size) $fontattr($font,size)
10952 set fontparam(weight) $fontattr($font,weight)
10953 set fontparam(slant) $fontattr($font,slant)
10956 if {![winfo exists $top]} {
10958 eval font config sample [font actual $font]
10960 make_transient $top $prefstop
10961 wm title $top [mc "Gitk font chooser"]
10962 ${NS}::label $top.l -textvariable fontparam(which)
10963 pack $top.l -side top
10964 set fontlist [lsort [font families]]
10965 ${NS}::frame $top.f
10966 listbox $top.f.fam -listvariable fontlist \
10967 -yscrollcommand [list $top.f.sb set]
10968 bind $top.f.fam <<ListboxSelect>> selfontfam
10969 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
10970 pack $top.f.sb -side right -fill y
10971 pack $top.f.fam -side left -fill both -expand 1
10972 pack $top.f -side top -fill both -expand 1
10973 ${NS}::frame $top.g
10974 spinbox $top.g.size -from 4 -to 40 -width 4 \
10975 -textvariable fontparam(size) \
10976 -validatecommand {string is integer -strict %s}
10977 checkbutton $top.g.bold -padx 5 \
10978 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
10979 -variable fontparam(weight) -onvalue bold -offvalue normal
10980 checkbutton $top.g.ital -padx 5 \
10981 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
10982 -variable fontparam(slant) -onvalue italic -offvalue roman
10983 pack $top.g.size $top.g.bold $top.g.ital -side left
10984 pack $top.g -side top
10985 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
10987 $top.c create text 100 25 -anchor center -text $which -font sample \
10988 -fill black -tags text
10989 bind $top.c <Configure> [list centertext $top.c]
10990 pack $top.c -side top -fill x
10991 ${NS}::frame $top.buts
10992 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
10993 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
10994 bind $top <Key-Return> fontok
10995 bind $top <Key-Escape> fontcan
10996 grid $top.buts.ok $top.buts.can
10997 grid columnconfigure $top.buts 0 -weight 1 -uniform a
10998 grid columnconfigure $top.buts 1 -weight 1 -uniform a
10999 pack $top.buts -side bottom -fill x
11000 trace add variable fontparam write chg_fontparam
11003 $top.c itemconf text -text $which
11005 set i [lsearch -exact $fontlist $fontparam(family)]
11007 $top.f.fam selection set $i
11012 proc centertext {w} {
11013 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11017 global fontparam fontpref prefstop
11019 set f $fontparam(font)
11020 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11021 if {$fontparam(weight) eq "bold"} {
11022 lappend fontpref($f) "bold"
11024 if {$fontparam(slant) eq "italic"} {
11025 lappend fontpref($f) "italic"
11027 set w $prefstop.notebook.fonts.$f
11028 $w conf -text $fontparam(family) -font $fontpref($f)
11034 global fonttop fontparam
11036 if {[info exists fonttop]} {
11037 catch {destroy $fonttop}
11038 catch {font delete sample}
11044 if {[package vsatisfies [package provide Tk] 8.6]} {
11045 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11046 # function to make use of it.
11047 proc choosefont {font which} {
11048 tk fontchooser configure -title $which -font $font \
11049 -command [list on_choosefont $font $which]
11050 tk fontchooser show
11052 proc on_choosefont {font which newfont} {
11054 puts stderr "$font $newfont"
11055 array set f [font actual $newfont]
11056 set fontparam(which) $which
11057 set fontparam(font) $font
11058 set fontparam(family) $f(-family)
11059 set fontparam(size) $f(-size)
11060 set fontparam(weight) $f(-weight)
11061 set fontparam(slant) $f(-slant)
11066 proc selfontfam {} {
11067 global fonttop fontparam
11069 set i [$fonttop.f.fam curselection]
11071 set fontparam(family) [$fonttop.f.fam get $i]
11075 proc chg_fontparam {v sub op} {
11078 font config sample -$sub $fontparam($sub)
11081 # Create a property sheet tab page
11082 proc create_prefs_page {w} {
11084 set parent [join [lrange [split $w .] 0 end-1] .]
11085 if {[winfo class $parent] eq "TNotebook"} {
11088 ${NS}::labelframe $w
11092 proc prefspage_general {notebook} {
11093 global NS maxwidth maxgraphpct showneartags showlocalchanges
11094 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11095 global hideremotes want_ttk have_ttk maxrefs
11097 set page [create_prefs_page $notebook.general]
11099 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11100 grid $page.ldisp - -sticky w -pady 10
11101 ${NS}::label $page.spacer -text " "
11102 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11103 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11104 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11105 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11106 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11107 grid x $page.maxpctl $page.maxpct -sticky w
11108 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11109 -variable showlocalchanges
11110 grid x $page.showlocal -sticky w
11111 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11112 -variable autoselect
11113 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11114 grid x $page.autoselect $page.autosellen -sticky w
11115 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11116 -variable hideremotes
11117 grid x $page.hideremotes -sticky w
11119 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11120 grid $page.ddisp - -sticky w -pady 10
11121 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11122 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11123 grid x $page.tabstopl $page.tabstop -sticky w
11124 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11125 -variable showneartags
11126 grid x $page.ntag -sticky w
11127 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11128 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11129 grid x $page.maxrefsl $page.maxrefs -sticky w
11130 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11131 -variable limitdiffs
11132 grid x $page.ldiff -sticky w
11133 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11134 -variable perfile_attrs
11135 grid x $page.lattr -sticky w
11137 ${NS}::entry $page.extdifft -textvariable extdifftool
11138 ${NS}::frame $page.extdifff
11139 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11140 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11141 pack $page.extdifff.l $page.extdifff.b -side left
11142 pack configure $page.extdifff.l -padx 10
11143 grid x $page.extdifff $page.extdifft -sticky ew
11145 ${NS}::label $page.lgen -text [mc "General options"]
11146 grid $page.lgen - -sticky w -pady 10
11147 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11148 -text [mc "Use themed widgets"]
11150 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11152 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11154 grid x $page.want_ttk $page.ttk_note -sticky w
11158 proc prefspage_colors {notebook} {
11159 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11161 set page [create_prefs_page $notebook.colors]
11163 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11164 grid $page.cdisp - -sticky w -pady 10
11165 label $page.ui -padx 40 -relief sunk -background $uicolor
11166 ${NS}::button $page.uibut -text [mc "Interface"] \
11167 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11168 grid x $page.uibut $page.ui -sticky w
11169 label $page.bg -padx 40 -relief sunk -background $bgcolor
11170 ${NS}::button $page.bgbut -text [mc "Background"] \
11171 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11172 grid x $page.bgbut $page.bg -sticky w
11173 label $page.fg -padx 40 -relief sunk -background $fgcolor
11174 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11175 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11176 grid x $page.fgbut $page.fg -sticky w
11177 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11178 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11179 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11180 [list $ctext tag conf d0 -foreground]]
11181 grid x $page.diffoldbut $page.diffold -sticky w
11182 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11183 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11184 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11185 [list $ctext tag conf dresult -foreground]]
11186 grid x $page.diffnewbut $page.diffnew -sticky w
11187 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11188 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11189 -command [list choosecolor diffcolors 2 $page.hunksep \
11190 [mc "diff hunk header"] \
11191 [list $ctext tag conf hunksep -foreground]]
11192 grid x $page.hunksepbut $page.hunksep -sticky w
11193 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11194 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11195 -command [list choosecolor markbgcolor {} $page.markbgsep \
11196 [mc "marked line background"] \
11197 [list $ctext tag conf omark -background]]
11198 grid x $page.markbgbut $page.markbgsep -sticky w
11199 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11200 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11201 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11202 grid x $page.selbgbut $page.selbgsep -sticky w
11206 proc prefspage_fonts {notebook} {
11208 set page [create_prefs_page $notebook.fonts]
11209 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11210 grid $page.cfont - -sticky w -pady 10
11211 mkfontdisp mainfont $page [mc "Main font"]
11212 mkfontdisp textfont $page [mc "Diff display font"]
11213 mkfontdisp uifont $page [mc "User interface font"]
11218 global maxwidth maxgraphpct use_ttk NS
11219 global oldprefs prefstop showneartags showlocalchanges
11220 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11221 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11222 global hideremotes want_ttk have_ttk
11226 if {[winfo exists $top]} {
11230 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11231 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11232 set oldprefs($v) [set $v]
11235 wm title $top [mc "Gitk preferences"]
11236 make_transient $top .
11238 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11239 set notebook [ttk::notebook $top.notebook]
11241 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11244 lappend pages [prefspage_general $notebook] [mc "General"]
11245 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11246 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11248 foreach {page title} $pages {
11249 if {$use_notebook} {
11250 $notebook add $page -text $title
11252 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11253 -text $title -command [list raise $page]]
11254 $page configure -text $title
11255 grid $btn -row 0 -column [incr col] -sticky w
11256 grid $page -row 1 -column 0 -sticky news -columnspan 100
11260 if {!$use_notebook} {
11261 grid columnconfigure $notebook 0 -weight 1
11262 grid rowconfigure $notebook 1 -weight 1
11263 raise [lindex $pages 0]
11266 grid $notebook -sticky news -padx 2 -pady 2
11267 grid rowconfigure $top 0 -weight 1
11268 grid columnconfigure $top 0 -weight 1
11270 ${NS}::frame $top.buts
11271 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11272 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11273 bind $top <Key-Return> prefsok
11274 bind $top <Key-Escape> prefscan
11275 grid $top.buts.ok $top.buts.can
11276 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11277 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11278 grid $top.buts - - -pady 10 -sticky ew
11279 grid columnconfigure $top 2 -weight 1
11280 bind $top <Visibility> [list focus $top.buts.ok]
11283 proc choose_extdiff {} {
11286 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11288 set extdifftool $prog
11292 proc choosecolor {v vi w x cmd} {
11295 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11296 -title [mc "Gitk: choose color for %s" $x]]
11297 if {$c eq {}} return
11298 $w conf -background $c
11303 proc setselbg {c} {
11304 global bglist cflist
11305 foreach w $bglist {
11306 $w configure -selectbackground $c
11308 $cflist tag configure highlight \
11309 -background [$cflist cget -selectbackground]
11310 allcanvs itemconf secsel -fill $c
11313 # This sets the background color and the color scheme for the whole UI.
11314 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11315 # if we don't specify one ourselves, which makes the checkbuttons and
11316 # radiobuttons look bad. This chooses white for selectColor if the
11317 # background color is light, or black if it is dark.
11319 if {[tk windowingsystem] eq "win32"} { return }
11320 set bg [winfo rgb . $c]
11322 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11325 tk_setPalette background $c selectColor $selc
11331 foreach w $bglist {
11332 $w conf -background $c
11339 foreach w $fglist {
11340 $w conf -foreground $c
11342 allcanvs itemconf text -fill $c
11343 $canv itemconf circle -outline $c
11344 $canv itemconf markid -outline $c
11348 global oldprefs prefstop
11350 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11351 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11353 set $v $oldprefs($v)
11355 catch {destroy $prefstop}
11361 global maxwidth maxgraphpct
11362 global oldprefs prefstop showneartags showlocalchanges
11363 global fontpref mainfont textfont uifont
11364 global limitdiffs treediffs perfile_attrs
11367 catch {destroy $prefstop}
11371 if {$mainfont ne $fontpref(mainfont)} {
11372 set mainfont $fontpref(mainfont)
11373 parsefont mainfont $mainfont
11374 eval font configure mainfont [fontflags mainfont]
11375 eval font configure mainfontbold [fontflags mainfont 1]
11379 if {$textfont ne $fontpref(textfont)} {
11380 set textfont $fontpref(textfont)
11381 parsefont textfont $textfont
11382 eval font configure textfont [fontflags textfont]
11383 eval font configure textfontbold [fontflags textfont 1]
11385 if {$uifont ne $fontpref(uifont)} {
11386 set uifont $fontpref(uifont)
11387 parsefont uifont $uifont
11388 eval font configure uifont [fontflags uifont]
11391 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11392 if {$showlocalchanges} {
11398 if {$limitdiffs != $oldprefs(limitdiffs) ||
11399 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11400 # treediffs elements are limited by path;
11401 # won't have encodings cached if perfile_attrs was just turned on
11402 catch {unset treediffs}
11404 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11405 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11407 } elseif {$showneartags != $oldprefs(showneartags) ||
11408 $limitdiffs != $oldprefs(limitdiffs)} {
11411 if {$hideremotes != $oldprefs(hideremotes)} {
11416 proc formatdate {d} {
11417 global datetimeformat
11419 set d [clock format [lindex $d 0] -format $datetimeformat]
11424 # This list of encoding names and aliases is distilled from
11425 # http://www.iana.org/assignments/character-sets.
11426 # Not all of them are supported by Tcl.
11427 set encoding_aliases {
11428 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11429 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11430 { ISO-10646-UTF-1 csISO10646UTF1 }
11431 { ISO_646.basic:1983 ref csISO646basic1983 }
11432 { INVARIANT csINVARIANT }
11433 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11434 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11435 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11436 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11437 { NATS-DANO iso-ir-9-1 csNATSDANO }
11438 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11439 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11440 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11441 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11442 { ISO-2022-KR csISO2022KR }
11444 { ISO-2022-JP csISO2022JP }
11445 { ISO-2022-JP-2 csISO2022JP2 }
11446 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11447 csISO13JISC6220jp }
11448 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11449 { IT iso-ir-15 ISO646-IT csISO15Italian }
11450 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11451 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11452 { greek7-old iso-ir-18 csISO18Greek7Old }
11453 { latin-greek iso-ir-19 csISO19LatinGreek }
11454 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11455 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11456 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11457 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11458 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11459 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11460 { INIS iso-ir-49 csISO49INIS }
11461 { INIS-8 iso-ir-50 csISO50INIS8 }
11462 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11463 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11464 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11465 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11466 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11467 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11468 csISO60Norwegian1 }
11469 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11470 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11471 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11472 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11473 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11474 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11475 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11476 { greek7 iso-ir-88 csISO88Greek7 }
11477 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11478 { iso-ir-90 csISO90 }
11479 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11480 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11481 csISO92JISC62991984b }
11482 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11483 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11484 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11485 csISO95JIS62291984handadd }
11486 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11487 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11488 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11489 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11490 CP819 csISOLatin1 }
11491 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11492 { T.61-7bit iso-ir-102 csISO102T617bit }
11493 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11494 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11495 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11496 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11497 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11498 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11499 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11500 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11501 arabic csISOLatinArabic }
11502 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11503 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11504 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11505 greek greek8 csISOLatinGreek }
11506 { T.101-G2 iso-ir-128 csISO128T101G2 }
11507 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11509 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11510 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11511 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11512 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11513 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11514 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11515 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11516 csISOLatinCyrillic }
11517 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11518 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11519 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11520 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11521 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11522 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11523 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11524 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11525 { ISO_10367-box iso-ir-155 csISO10367Box }
11526 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11527 { latin-lap lap iso-ir-158 csISO158Lap }
11528 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11529 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11532 { JIS_X0201 X0201 csHalfWidthKatakana }
11533 { KSC5636 ISO646-KR csKSC5636 }
11534 { ISO-10646-UCS-2 csUnicode }
11535 { ISO-10646-UCS-4 csUCS4 }
11536 { DEC-MCS dec csDECMCS }
11537 { hp-roman8 roman8 r8 csHPRoman8 }
11538 { macintosh mac csMacintosh }
11539 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11541 { IBM038 EBCDIC-INT cp038 csIBM038 }
11542 { IBM273 CP273 csIBM273 }
11543 { IBM274 EBCDIC-BE CP274 csIBM274 }
11544 { IBM275 EBCDIC-BR cp275 csIBM275 }
11545 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11546 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11547 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11548 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11549 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11550 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11551 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11552 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11553 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11554 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11555 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11556 { IBM437 cp437 437 csPC8CodePage437 }
11557 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11558 { IBM775 cp775 csPC775Baltic }
11559 { IBM850 cp850 850 csPC850Multilingual }
11560 { IBM851 cp851 851 csIBM851 }
11561 { IBM852 cp852 852 csPCp852 }
11562 { IBM855 cp855 855 csIBM855 }
11563 { IBM857 cp857 857 csIBM857 }
11564 { IBM860 cp860 860 csIBM860 }
11565 { IBM861 cp861 861 cp-is csIBM861 }
11566 { IBM862 cp862 862 csPC862LatinHebrew }
11567 { IBM863 cp863 863 csIBM863 }
11568 { IBM864 cp864 csIBM864 }
11569 { IBM865 cp865 865 csIBM865 }
11570 { IBM866 cp866 866 csIBM866 }
11571 { IBM868 CP868 cp-ar csIBM868 }
11572 { IBM869 cp869 869 cp-gr csIBM869 }
11573 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11574 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11575 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11576 { IBM891 cp891 csIBM891 }
11577 { IBM903 cp903 csIBM903 }
11578 { IBM904 cp904 904 csIBBM904 }
11579 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11580 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11581 { IBM1026 CP1026 csIBM1026 }
11582 { EBCDIC-AT-DE csIBMEBCDICATDE }
11583 { EBCDIC-AT-DE-A csEBCDICATDEA }
11584 { EBCDIC-CA-FR csEBCDICCAFR }
11585 { EBCDIC-DK-NO csEBCDICDKNO }
11586 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11587 { EBCDIC-FI-SE csEBCDICFISE }
11588 { EBCDIC-FI-SE-A csEBCDICFISEA }
11589 { EBCDIC-FR csEBCDICFR }
11590 { EBCDIC-IT csEBCDICIT }
11591 { EBCDIC-PT csEBCDICPT }
11592 { EBCDIC-ES csEBCDICES }
11593 { EBCDIC-ES-A csEBCDICESA }
11594 { EBCDIC-ES-S csEBCDICESS }
11595 { EBCDIC-UK csEBCDICUK }
11596 { EBCDIC-US csEBCDICUS }
11597 { UNKNOWN-8BIT csUnknown8BiT }
11598 { MNEMONIC csMnemonic }
11600 { VISCII csVISCII }
11603 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11604 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11605 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11606 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11607 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11608 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11609 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11610 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11611 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11612 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11613 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11614 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11615 { IBM1047 IBM-1047 }
11616 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11617 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11618 { UNICODE-1-1 csUnicode11 }
11619 { CESU-8 csCESU-8 }
11620 { BOCU-1 csBOCU-1 }
11621 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11622 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11624 { ISO-8859-15 ISO_8859-15 Latin-9 }
11625 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11626 { GBK CP936 MS936 windows-936 }
11627 { JIS_Encoding csJISEncoding }
11628 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11629 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11631 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11632 { ISO-10646-UCS-Basic csUnicodeASCII }
11633 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11634 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11635 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11636 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11637 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11638 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11639 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11640 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11641 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11642 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11643 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11644 { Ventura-US csVenturaUS }
11645 { Ventura-International csVenturaInternational }
11646 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11647 { PC8-Turkish csPC8Turkish }
11648 { IBM-Symbols csIBMSymbols }
11649 { IBM-Thai csIBMThai }
11650 { HP-Legal csHPLegal }
11651 { HP-Pi-font csHPPiFont }
11652 { HP-Math8 csHPMath8 }
11653 { Adobe-Symbol-Encoding csHPPSMath }
11654 { HP-DeskTop csHPDesktop }
11655 { Ventura-Math csVenturaMath }
11656 { Microsoft-Publishing csMicrosoftPublishing }
11657 { Windows-31J csWindows31J }
11658 { GB2312 csGB2312 }
11662 proc tcl_encoding {enc} {
11663 global encoding_aliases tcl_encoding_cache
11664 if {[info exists tcl_encoding_cache($enc)]} {
11665 return $tcl_encoding_cache($enc)
11667 set names [encoding names]
11668 set lcnames [string tolower $names]
11669 set enc [string tolower $enc]
11670 set i [lsearch -exact $lcnames $enc]
11672 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11673 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11674 set i [lsearch -exact $lcnames $encx]
11678 foreach l $encoding_aliases {
11679 set ll [string tolower $l]
11680 if {[lsearch -exact $ll $enc] < 0} continue
11681 # look through the aliases for one that tcl knows about
11683 set i [lsearch -exact $lcnames $e]
11685 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11686 set i [lsearch -exact $lcnames $ex]
11696 set tclenc [lindex $names $i]
11698 set tcl_encoding_cache($enc) $tclenc
11702 proc gitattr {path attr default} {
11703 global path_attr_cache
11704 if {[info exists path_attr_cache($attr,$path)]} {
11705 set r $path_attr_cache($attr,$path)
11707 set r "unspecified"
11708 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11709 regexp "(.*): $attr: (.*)" $line m f r
11711 set path_attr_cache($attr,$path) $r
11713 if {$r eq "unspecified"} {
11719 proc cache_gitattr {attr pathlist} {
11720 global path_attr_cache
11722 foreach path $pathlist {
11723 if {![info exists path_attr_cache($attr,$path)]} {
11724 lappend newlist $path
11728 if {[tk windowingsystem] == "win32"} {
11729 # windows has a 32k limit on the arguments to a command...
11732 while {$newlist ne {}} {
11733 set head [lrange $newlist 0 [expr {$lim - 1}]]
11734 set newlist [lrange $newlist $lim end]
11735 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11736 foreach row [split $rlist "\n"] {
11737 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11738 if {[string index $path 0] eq "\""} {
11739 set path [encoding convertfrom [lindex $path 0]]
11741 set path_attr_cache($attr,$path) $value
11748 proc get_path_encoding {path} {
11749 global gui_encoding perfile_attrs
11750 set tcl_enc $gui_encoding
11751 if {$path ne {} && $perfile_attrs} {
11752 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11760 # First check that Tcl/Tk is recent enough
11761 if {[catch {package require Tk 8.4} err]} {
11762 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11763 Gitk requires at least Tcl/Tk 8.4." list
11767 # on OSX bring the current Wish process window to front
11768 if {[tk windowingsystem] eq "aqua"} {
11769 exec osascript -e [format {
11770 tell application "System Events"
11771 set frontmost of processes whose unix id is %d to true
11776 # Unset GIT_TRACE var if set
11777 if { [info exists ::env(GIT_TRACE)] } {
11778 unset ::env(GIT_TRACE)
11782 set wrcomcmd "git diff-tree --stdin -p --pretty"
11786 set gitencoding [exec git config --get i18n.commitencoding]
11789 set gitencoding [exec git config --get i18n.logoutputencoding]
11791 if {$gitencoding == ""} {
11792 set gitencoding "utf-8"
11794 set tclencoding [tcl_encoding $gitencoding]
11795 if {$tclencoding == {}} {
11796 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11799 set gui_encoding [encoding system]
11801 set enc [exec git config --get gui.encoding]
11803 set tclenc [tcl_encoding $enc]
11804 if {$tclenc ne {}} {
11805 set gui_encoding $tclenc
11807 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11812 set log_showroot true
11814 set log_showroot [exec git config --bool --get log.showroot]
11817 if {[tk windowingsystem] eq "aqua"} {
11818 set mainfont {{Lucida Grande} 9}
11819 set textfont {Monaco 9}
11820 set uifont {{Lucida Grande} 9 bold}
11821 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11823 set mainfont {sans 9}
11824 set textfont {monospace 9}
11825 set uifont {sans 9 bold}
11827 set mainfont {Helvetica 9}
11828 set textfont {Courier 9}
11829 set uifont {Helvetica 9 bold}
11832 set findmergefiles 0
11840 set cmitmode "patch"
11841 set wrapcomment "none"
11846 set showlocalchanges 1
11848 set datetimeformat "%Y-%m-%d %H:%M:%S"
11851 set perfile_attrs 0
11854 if {[tk windowingsystem] eq "aqua"} {
11855 set extdifftool "opendiff"
11857 set extdifftool "meld"
11860 set colors {green red blue magenta darkgrey brown orange}
11861 if {[tk windowingsystem] eq "win32"} {
11862 set uicolor SystemButtonFace
11863 set uifgcolor SystemButtonText
11864 set uifgdisabledcolor SystemDisabledText
11865 set bgcolor SystemWindow
11866 set fgcolor SystemWindowText
11867 set selectbgcolor SystemHighlight
11870 set uifgcolor black
11871 set uifgdisabledcolor "#999"
11874 set selectbgcolor gray85
11876 set diffcolors {red "#00a000" blue}
11878 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
11881 set markbgcolor "#e0e0ff"
11883 set headbgcolor green
11884 set headfgcolor black
11885 set headoutlinecolor black
11886 set remotebgcolor #ffddaa
11887 set tagbgcolor yellow
11888 set tagfgcolor black
11889 set tagoutlinecolor black
11890 set reflinecolor black
11891 set filesepbgcolor #aaaaaa
11892 set filesepfgcolor black
11893 set linehoverbgcolor #ffff80
11894 set linehoverfgcolor black
11895 set linehoveroutlinecolor black
11896 set mainheadcirclecolor yellow
11897 set workingfilescirclecolor red
11898 set indexcirclecolor green
11899 set circlecolors {white blue gray blue blue}
11900 set linkfgcolor blue
11901 set circleoutlinecolor $fgcolor
11902 set foundbgcolor yellow
11903 set currentsearchhitbgcolor orange
11905 # button for popping up context menus
11906 if {[tk windowingsystem] eq "aqua"} {
11907 set ctxbut <Button-2>
11909 set ctxbut <Button-3>
11912 ## For msgcat loading, first locate the installation location.
11913 if { [info exists ::env(GITK_MSGSDIR)] } {
11914 ## Msgsdir was manually set in the environment.
11915 set gitk_msgsdir $::env(GITK_MSGSDIR)
11917 ## Let's guess the prefix from argv0.
11918 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
11919 set gitk_libdir [file join $gitk_prefix share gitk lib]
11920 set gitk_msgsdir [file join $gitk_libdir msgs]
11924 ## Internationalization (i18n) through msgcat and gettext. See
11925 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
11926 package require msgcat
11927 namespace import ::msgcat::mc
11928 ## And eventually load the actual message catalog
11929 ::msgcat::mcload $gitk_msgsdir
11931 catch {source ~/.gitk}
11933 parsefont mainfont $mainfont
11934 eval font create mainfont [fontflags mainfont]
11935 eval font create mainfontbold [fontflags mainfont 1]
11937 parsefont textfont $textfont
11938 eval font create textfont [fontflags textfont]
11939 eval font create textfontbold [fontflags textfont 1]
11941 parsefont uifont $uifont
11942 eval font create uifont [fontflags uifont]
11948 # check that we can find a .git directory somewhere...
11949 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
11950 show_error {} . [mc "Cannot find a git repository here."]
11955 set selectheadid {}
11958 set cmdline_files {}
11960 set revtreeargscmd {}
11961 foreach arg $argv {
11962 switch -glob -- $arg {
11965 set cmdline_files [lrange $argv [expr {$i + 1}] end]
11968 "--select-commit=*" {
11969 set selecthead [string range $arg 16 end]
11972 set revtreeargscmd [string range $arg 10 end]
11975 lappend revtreeargs $arg
11981 if {$selecthead eq "HEAD"} {
11985 if {$i >= [llength $argv] && $revtreeargs ne {}} {
11986 # no -- on command line, but some arguments (other than --argscmd)
11988 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
11989 set cmdline_files [split $f "\n"]
11990 set n [llength $cmdline_files]
11991 set revtreeargs [lrange $revtreeargs 0 end-$n]
11992 # Unfortunately git rev-parse doesn't produce an error when
11993 # something is both a revision and a filename. To be consistent
11994 # with git log and git rev-list, check revtreeargs for filenames.
11995 foreach arg $revtreeargs {
11996 if {[file exists $arg]} {
11997 show_error {} . [mc "Ambiguous argument '%s': both revision\
11998 and filename" $arg]
12003 # unfortunately we get both stdout and stderr in $err,
12004 # so look for "fatal:".
12005 set i [string first "fatal:" $err]
12007 set err [string range $err [expr {$i + 6}] end]
12009 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12014 set nullid "0000000000000000000000000000000000000000"
12015 set nullid2 "0000000000000000000000000000000000000001"
12016 set nullfile "/dev/null"
12018 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12019 if {![info exists have_ttk]} {
12020 set have_ttk [llength [info commands ::ttk::style]]
12022 set use_ttk [expr {$have_ttk && $want_ttk}]
12023 set NS [expr {$use_ttk ? "ttk" : ""}]
12025 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12028 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12029 set show_notes "--show-notes"
12039 set highlight_paths {}
12041 set searchdirn -forwards
12044 set diffelide {0 0}
12045 set markingmatches 0
12046 set linkentercount 0
12047 set need_redisplay 0
12054 set selectedhlview [mc "None"]
12055 set highlight_related [mc "None"]
12056 set highlight_files {}
12057 set viewfiles(0) {}
12060 set viewargscmd(0) {}
12062 set selectedline {}
12070 set hasworktree [hasworktree]
12072 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12073 set cdup [exec git rev-parse --show-cdup]
12075 set worktree [exec git rev-parse --show-toplevel]
12079 image create photo gitlogo -width 16 -height 16
12081 image create photo gitlogominus -width 4 -height 2
12082 gitlogominus put #C00000 -to 0 0 4 2
12083 gitlogo copy gitlogominus -to 1 5
12084 gitlogo copy gitlogominus -to 6 5
12085 gitlogo copy gitlogominus -to 11 5
12086 image delete gitlogominus
12088 image create photo gitlogoplus -width 4 -height 4
12089 gitlogoplus put #008000 -to 1 0 3 4
12090 gitlogoplus put #008000 -to 0 1 4 3
12091 gitlogo copy gitlogoplus -to 1 9
12092 gitlogo copy gitlogoplus -to 6 9
12093 gitlogo copy gitlogoplus -to 11 9
12094 image delete gitlogoplus
12096 image create photo gitlogo32 -width 32 -height 32
12097 gitlogo32 copy gitlogo -zoom 2 2
12099 wm iconphoto . -default gitlogo gitlogo32
12101 # wait for the window to become visible
12102 tkwait visibility .
12103 wm title . "$appname: [reponame]"
12107 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12108 # create a view for the files/dirs specified on the command line
12112 set viewname(1) [mc "Command line"]
12113 set viewfiles(1) $cmdline_files
12114 set viewargs(1) $revtreeargs
12115 set viewargscmd(1) $revtreeargscmd
12119 .bar.view entryconf [mca "Edit view..."] -state normal
12120 .bar.view entryconf [mca "Delete view"] -state normal
12123 if {[info exists permviews]} {
12124 foreach v $permviews {
12127 set viewname($n) [lindex $v 0]
12128 set viewfiles($n) [lindex $v 1]
12129 set viewargs($n) [lindex $v 2]
12130 set viewargscmd($n) [lindex $v 3]
12136 if {[tk windowingsystem] eq "win32"} {
12144 # indent-tabs-mode: t