Merge branch 'master' of git://ozlabs.org/~paulus/gitk
[git/mingw/j6t.git] / gitk
blobb81402d8873d13b0df59c9448cdec5695ad0d57a
1 #!/bin/sh
2 # Tcl ignores the next line -*- tcl -*- \
3 exec wish "$0" -- "$@"
5 # Copyright © 2005-2014 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.
10 package require Tk
12 proc hasworktree {} {
13 return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
14 [exec git rev-parse --is-inside-git-dir] == "false"}]
17 proc reponame {} {
18 global gitdir
19 set n [file normalize $gitdir]
20 if {[string match "*/.git" $n]} {
21 set n [string range $n 0 end-5]
23 return [file tail $n]
26 proc gitworktree {} {
27 variable _gitworktree
28 if {[info exists _gitworktree]} {
29 return $_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]]
43 return $_gitworktree
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.
51 proc run args {
52 global isonrunq runq currunq
54 set script $args
55 if {[info exists isonrunq($script)]} return
56 if {$runq eq {} && ![info exists currunq]} {
57 after idle dorunq
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} {
68 global runq currunq
70 fileevent $fd readable {}
71 if {$runq eq {} && ![info exists currunq]} {
72 after idle dorunq
74 lappend runq [list $fd $script]
77 proc nukefile {fd} {
78 global runq
80 for {set i 0} {$i < [llength $runq]} {} {
81 if {[lindex $runq $i 0] eq $fd} {
82 set runq [lreplace $runq $i $i]
83 } else {
84 incr i
89 proc dorunq {} {
90 global isonrunq runq currunq
92 set tstart [clock clicks -milliseconds]
93 set t0 $tstart
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]
100 unset currunq
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]
108 } else {
109 fileevent $fd readable [list filereadable $fd $script]
111 } elseif {$fd eq {}} {
112 unset isonrunq($script)
114 set t0 $t1
115 if {$t1 - $tstart >= 80} break
117 if {$runq ne {}} {
118 after idle dorunq
122 proc reg_instance {fd} {
123 global commfd leftover loginstance
125 set i [incr loginstance]
126 set commfd($i) $fd
127 set leftover($i) {}
128 return $i
131 proc unmerged_files {files} {
132 global nr_unmerged
134 # find the list of unmerged files
135 set mlist {}
136 set nr_unmerged 0
137 if {[catch {
138 set fd [open "| git ls-files -u" r]
139 } err]} {
140 show_error {} . "[mc "Couldn't get list of unmerged files:"] $err"
141 exit 1
143 while {[gets $fd line] >= 0} {
144 set i [string first "\t" $line]
145 if {$i < 0} continue
146 set fname [string range $line [expr {$i+1}] end]
147 if {[lsearch -exact $mlist $fname] >= 0} continue
148 incr nr_unmerged
149 if {$files eq {} || [path_filter $files $fname]} {
150 lappend mlist $fname
153 catch {close $fd}
154 return $mlist
157 proc parseviewargs {n arglist} {
158 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
159 global vinlinediff
160 global worddiff git_version
162 set vdatemode($n) 0
163 set vmergeonly($n) 0
164 set vinlinediff($n) 0
165 set glflags {}
166 set diffargs {}
167 set nextisval 0
168 set revargs {}
169 set origargs $arglist
170 set allknown 1
171 set filtered 0
172 set i -1
173 foreach arg $arglist {
174 incr i
175 if {$nextisval} {
176 lappend glflags $arg
177 set nextisval 0
178 continue
180 switch -glob -- $arg {
181 "-d" -
182 "--date-order" {
183 set vdatemode($n) 1
184 # remove from origargs in case we hit an unknown option
185 set origargs [lreplace $origargs $i $i]
186 incr i -1
188 "-[puabwcrRBMC]" -
189 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
190 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
191 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
192 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
193 "--ignore-space-change" - "-U*" - "--unified=*" {
194 # These request or affect diff output, which we don't want.
195 # Some could be used to set our defaults for diff display.
196 lappend diffargs $arg
198 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
199 "--name-only" - "--name-status" - "--color" -
200 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
201 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
202 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
203 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
204 "--objects" - "--objects-edge" - "--reverse" {
205 # These cause our parsing of git log's output to fail, or else
206 # they're options we want to set ourselves, so ignore them.
208 "--color-words*" - "--word-diff=color" {
209 # These trigger a word diff in the console interface,
210 # so help the user by enabling our own support
211 if {[package vcompare $git_version "1.7.2"] >= 0} {
212 set worddiff [mc "Color words"]
215 "--word-diff*" {
216 if {[package vcompare $git_version "1.7.2"] >= 0} {
217 set worddiff [mc "Markup words"]
220 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
221 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
222 "--full-history" - "--dense" - "--sparse" -
223 "--follow" - "--left-right" - "--encoding=*" {
224 # These are harmless, and some are even useful
225 lappend glflags $arg
227 "--diff-filter=*" - "--no-merges" - "--unpacked" -
228 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
229 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
230 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
231 "--remove-empty" - "--first-parent" - "--cherry-pick" -
232 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
233 "--simplify-by-decoration" {
234 # These mean that we get a subset of the commits
235 set filtered 1
236 lappend glflags $arg
238 "-L*" {
239 # Line-log with 'stuck' argument (unstuck form is
240 # not supported)
241 set filtered 1
242 set vinlinediff($n) 1
243 set allknown 0
244 lappend glflags $arg
246 "-n" {
247 # This appears to be the only one that has a value as a
248 # separate word following it
249 set filtered 1
250 set nextisval 1
251 lappend glflags $arg
253 "--not" - "--all" {
254 lappend revargs $arg
256 "--merge" {
257 set vmergeonly($n) 1
258 # git rev-parse doesn't understand --merge
259 lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD
261 "--no-replace-objects" {
262 set env(GIT_NO_REPLACE_OBJECTS) "1"
264 "-*" {
265 # Other flag arguments including -<n>
266 if {[string is digit -strict [string range $arg 1 end]]} {
267 set filtered 1
268 } else {
269 # a flag argument that we don't recognize;
270 # that means we can't optimize
271 set allknown 0
273 lappend glflags $arg
275 default {
276 # Non-flag arguments specify commits or ranges of commits
277 if {[string match "*...*" $arg]} {
278 lappend revargs --gitk-symmetric-diff-marker
280 lappend revargs $arg
284 set vdflags($n) $diffargs
285 set vflags($n) $glflags
286 set vrevs($n) $revargs
287 set vfiltered($n) $filtered
288 set vorigargs($n) $origargs
289 return $allknown
292 proc parseviewrevs {view revs} {
293 global vposids vnegids
295 if {$revs eq {}} {
296 set revs HEAD
297 } elseif {[lsearch -exact $revs --all] >= 0} {
298 lappend revs HEAD
300 if {[catch {set ids [eval exec git rev-parse $revs]} err]} {
301 # we get stdout followed by stderr in $err
302 # for an unknown rev, git rev-parse echoes it and then errors out
303 set errlines [split $err "\n"]
304 set badrev {}
305 for {set l 0} {$l < [llength $errlines]} {incr l} {
306 set line [lindex $errlines $l]
307 if {!([string length $line] == 40 && [string is xdigit $line])} {
308 if {[string match "fatal:*" $line]} {
309 if {[string match "fatal: ambiguous argument*" $line]
310 && $badrev ne {}} {
311 if {[llength $badrev] == 1} {
312 set err "unknown revision $badrev"
313 } else {
314 set err "unknown revisions: [join $badrev ", "]"
316 } else {
317 set err [join [lrange $errlines $l end] "\n"]
319 break
321 lappend badrev $line
324 error_popup "[mc "Error parsing revisions:"] $err"
325 return {}
327 set ret {}
328 set pos {}
329 set neg {}
330 set sdm 0
331 foreach id [split $ids "\n"] {
332 if {$id eq "--gitk-symmetric-diff-marker"} {
333 set sdm 4
334 } elseif {[string match "^*" $id]} {
335 if {$sdm != 1} {
336 lappend ret $id
337 if {$sdm == 3} {
338 set sdm 0
341 lappend neg [string range $id 1 end]
342 } else {
343 if {$sdm != 2} {
344 lappend ret $id
345 } else {
346 lset ret end $id...[lindex $ret end]
348 lappend pos $id
350 incr sdm -1
352 set vposids($view) $pos
353 set vnegids($view) $neg
354 return $ret
357 # Start off a git log process and arrange to read its output
358 proc start_rev_list {view} {
359 global startmsecs commitidx viewcomplete curview
360 global tclencoding
361 global viewargs viewargscmd viewfiles vfilelimit
362 global showlocalchanges
363 global viewactive viewinstances vmergeonly
364 global mainheadid viewmainheadid viewmainheadid_orig
365 global vcanopt vflags vrevs vorigargs
366 global show_notes
368 set startmsecs [clock clicks -milliseconds]
369 set commitidx($view) 0
370 # these are set this way for the error exits
371 set viewcomplete($view) 1
372 set viewactive($view) 0
373 varcinit $view
375 set args $viewargs($view)
376 if {$viewargscmd($view) ne {}} {
377 if {[catch {
378 set str [exec sh -c $viewargscmd($view)]
379 } err]} {
380 error_popup "[mc "Error executing --argscmd command:"] $err"
381 return 0
383 set args [concat $args [split $str "\n"]]
385 set vcanopt($view) [parseviewargs $view $args]
387 set files $viewfiles($view)
388 if {$vmergeonly($view)} {
389 set files [unmerged_files $files]
390 if {$files eq {}} {
391 global nr_unmerged
392 if {$nr_unmerged == 0} {
393 error_popup [mc "No files selected: --merge specified but\
394 no files are unmerged."]
395 } else {
396 error_popup [mc "No files selected: --merge specified but\
397 no unmerged files are within file limit."]
399 return 0
402 set vfilelimit($view) $files
404 if {$vcanopt($view)} {
405 set revs [parseviewrevs $view $vrevs($view)]
406 if {$revs eq {}} {
407 return 0
409 set args [concat $vflags($view) $revs]
410 } else {
411 set args $vorigargs($view)
414 if {[catch {
415 set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
416 --parents --boundary $args "--" $files] r]
417 } err]} {
418 error_popup "[mc "Error executing git log:"] $err"
419 return 0
421 set i [reg_instance $fd]
422 set viewinstances($view) [list $i]
423 set viewmainheadid($view) $mainheadid
424 set viewmainheadid_orig($view) $mainheadid
425 if {$files ne {} && $mainheadid ne {}} {
426 get_viewmainhead $view
428 if {$showlocalchanges && $viewmainheadid($view) ne {}} {
429 interestedin $viewmainheadid($view) dodiffindex
431 fconfigure $fd -blocking 0 -translation lf -eofchar {}
432 if {$tclencoding != {}} {
433 fconfigure $fd -encoding $tclencoding
435 filerun $fd [list getcommitlines $fd $i $view 0]
436 nowbusy $view [mc "Reading"]
437 set viewcomplete($view) 0
438 set viewactive($view) 1
439 return 1
442 proc stop_instance {inst} {
443 global commfd leftover
445 set fd $commfd($inst)
446 catch {
447 set pid [pid $fd]
449 if {$::tcl_platform(platform) eq {windows}} {
450 exec taskkill /pid $pid
451 } else {
452 exec kill $pid
455 catch {close $fd}
456 nukefile $fd
457 unset commfd($inst)
458 unset leftover($inst)
461 proc stop_backends {} {
462 global commfd
464 foreach inst [array names commfd] {
465 stop_instance $inst
469 proc stop_rev_list {view} {
470 global viewinstances
472 foreach inst $viewinstances($view) {
473 stop_instance $inst
475 set viewinstances($view) {}
478 proc reset_pending_select {selid} {
479 global pending_select mainheadid selectheadid
481 if {$selid ne {}} {
482 set pending_select $selid
483 } elseif {$selectheadid ne {}} {
484 set pending_select $selectheadid
485 } else {
486 set pending_select $mainheadid
490 proc getcommits {selid} {
491 global canv curview need_redisplay viewactive
493 initlayout
494 if {[start_rev_list $curview]} {
495 reset_pending_select $selid
496 show_status [mc "Reading commits..."]
497 set need_redisplay 1
498 } else {
499 show_status [mc "No commits selected"]
503 proc updatecommits {} {
504 global curview vcanopt vorigargs vfilelimit viewinstances
505 global viewactive viewcomplete tclencoding
506 global startmsecs showneartags showlocalchanges
507 global mainheadid viewmainheadid viewmainheadid_orig pending_select
508 global hasworktree
509 global varcid vposids vnegids vflags vrevs
510 global show_notes
512 set hasworktree [hasworktree]
513 rereadrefs
514 set view $curview
515 if {$mainheadid ne $viewmainheadid_orig($view)} {
516 if {$showlocalchanges} {
517 dohidelocalchanges
519 set viewmainheadid($view) $mainheadid
520 set viewmainheadid_orig($view) $mainheadid
521 if {$vfilelimit($view) ne {}} {
522 get_viewmainhead $view
525 if {$showlocalchanges} {
526 doshowlocalchanges
528 if {$vcanopt($view)} {
529 set oldpos $vposids($view)
530 set oldneg $vnegids($view)
531 set revs [parseviewrevs $view $vrevs($view)]
532 if {$revs eq {}} {
533 return
535 # note: getting the delta when negative refs change is hard,
536 # and could require multiple git log invocations, so in that
537 # case we ask git log for all the commits (not just the delta)
538 if {$oldneg eq $vnegids($view)} {
539 set newrevs {}
540 set npos 0
541 # take out positive refs that we asked for before or
542 # that we have already seen
543 foreach rev $revs {
544 if {[string length $rev] == 40} {
545 if {[lsearch -exact $oldpos $rev] < 0
546 && ![info exists varcid($view,$rev)]} {
547 lappend newrevs $rev
548 incr npos
550 } else {
551 lappend $newrevs $rev
554 if {$npos == 0} return
555 set revs $newrevs
556 set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
558 set args [concat $vflags($view) $revs --not $oldpos]
559 } else {
560 set args $vorigargs($view)
562 if {[catch {
563 set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
564 --parents --boundary $args "--" $vfilelimit($view)] r]
565 } err]} {
566 error_popup "[mc "Error executing git log:"] $err"
567 return
569 if {$viewactive($view) == 0} {
570 set startmsecs [clock clicks -milliseconds]
572 set i [reg_instance $fd]
573 lappend viewinstances($view) $i
574 fconfigure $fd -blocking 0 -translation lf -eofchar {}
575 if {$tclencoding != {}} {
576 fconfigure $fd -encoding $tclencoding
578 filerun $fd [list getcommitlines $fd $i $view 1]
579 incr viewactive($view)
580 set viewcomplete($view) 0
581 reset_pending_select {}
582 nowbusy $view [mc "Reading"]
583 if {$showneartags} {
584 getallcommits
588 proc reloadcommits {} {
589 global curview viewcomplete selectedline currentid thickerline
590 global showneartags treediffs commitinterest cached_commitrow
591 global targetid
593 set selid {}
594 if {$selectedline ne {}} {
595 set selid $currentid
598 if {!$viewcomplete($curview)} {
599 stop_rev_list $curview
601 resetvarcs $curview
602 set selectedline {}
603 catch {unset currentid}
604 catch {unset thickerline}
605 catch {unset treediffs}
606 readrefs
607 changedrefs
608 if {$showneartags} {
609 getallcommits
611 clear_display
612 catch {unset commitinterest}
613 catch {unset cached_commitrow}
614 catch {unset targetid}
615 setcanvscroll
616 getcommits $selid
617 return 0
620 # This makes a string representation of a positive integer which
621 # sorts as a string in numerical order
622 proc strrep {n} {
623 if {$n < 16} {
624 return [format "%x" $n]
625 } elseif {$n < 256} {
626 return [format "x%.2x" $n]
627 } elseif {$n < 65536} {
628 return [format "y%.4x" $n]
630 return [format "z%.8x" $n]
633 # Procedures used in reordering commits from git log (without
634 # --topo-order) into the order for display.
636 proc varcinit {view} {
637 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
638 global vtokmod varcmod vrowmod varcix vlastins
640 set varcstart($view) {{}}
641 set vupptr($view) {0}
642 set vdownptr($view) {0}
643 set vleftptr($view) {0}
644 set vbackptr($view) {0}
645 set varctok($view) {{}}
646 set varcrow($view) {{}}
647 set vtokmod($view) {}
648 set varcmod($view) 0
649 set vrowmod($view) 0
650 set varcix($view) {{}}
651 set vlastins($view) {0}
654 proc resetvarcs {view} {
655 global varcid varccommits parents children vseedcount ordertok
656 global vshortids
658 foreach vid [array names varcid $view,*] {
659 unset varcid($vid)
660 unset children($vid)
661 unset parents($vid)
663 foreach vid [array names vshortids $view,*] {
664 unset vshortids($vid)
666 # some commits might have children but haven't been seen yet
667 foreach vid [array names children $view,*] {
668 unset children($vid)
670 foreach va [array names varccommits $view,*] {
671 unset varccommits($va)
673 foreach vd [array names vseedcount $view,*] {
674 unset vseedcount($vd)
676 catch {unset ordertok}
679 # returns a list of the commits with no children
680 proc seeds {v} {
681 global vdownptr vleftptr varcstart
683 set ret {}
684 set a [lindex $vdownptr($v) 0]
685 while {$a != 0} {
686 lappend ret [lindex $varcstart($v) $a]
687 set a [lindex $vleftptr($v) $a]
689 return $ret
692 proc newvarc {view id} {
693 global varcid varctok parents children vdatemode
694 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
695 global commitdata commitinfo vseedcount varccommits vlastins
697 set a [llength $varctok($view)]
698 set vid $view,$id
699 if {[llength $children($vid)] == 0 || $vdatemode($view)} {
700 if {![info exists commitinfo($id)]} {
701 parsecommit $id $commitdata($id) 1
703 set cdate [lindex [lindex $commitinfo($id) 4] 0]
704 if {![string is integer -strict $cdate]} {
705 set cdate 0
707 if {![info exists vseedcount($view,$cdate)]} {
708 set vseedcount($view,$cdate) -1
710 set c [incr vseedcount($view,$cdate)]
711 set cdate [expr {$cdate ^ 0xffffffff}]
712 set tok "s[strrep $cdate][strrep $c]"
713 } else {
714 set tok {}
716 set ka 0
717 if {[llength $children($vid)] > 0} {
718 set kid [lindex $children($vid) end]
719 set k $varcid($view,$kid)
720 if {[string compare [lindex $varctok($view) $k] $tok] > 0} {
721 set ki $kid
722 set ka $k
723 set tok [lindex $varctok($view) $k]
726 if {$ka != 0} {
727 set i [lsearch -exact $parents($view,$ki) $id]
728 set j [expr {[llength $parents($view,$ki)] - 1 - $i}]
729 append tok [strrep $j]
731 set c [lindex $vlastins($view) $ka]
732 if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} {
733 set c $ka
734 set b [lindex $vdownptr($view) $ka]
735 } else {
736 set b [lindex $vleftptr($view) $c]
738 while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} {
739 set c $b
740 set b [lindex $vleftptr($view) $c]
742 if {$c == $ka} {
743 lset vdownptr($view) $ka $a
744 lappend vbackptr($view) 0
745 } else {
746 lset vleftptr($view) $c $a
747 lappend vbackptr($view) $c
749 lset vlastins($view) $ka $a
750 lappend vupptr($view) $ka
751 lappend vleftptr($view) $b
752 if {$b != 0} {
753 lset vbackptr($view) $b $a
755 lappend varctok($view) $tok
756 lappend varcstart($view) $id
757 lappend vdownptr($view) 0
758 lappend varcrow($view) {}
759 lappend varcix($view) {}
760 set varccommits($view,$a) {}
761 lappend vlastins($view) 0
762 return $a
765 proc splitvarc {p v} {
766 global varcid varcstart varccommits varctok vtokmod
767 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
769 set oa $varcid($v,$p)
770 set otok [lindex $varctok($v) $oa]
771 set ac $varccommits($v,$oa)
772 set i [lsearch -exact $varccommits($v,$oa) $p]
773 if {$i <= 0} return
774 set na [llength $varctok($v)]
775 # "%" sorts before "0"...
776 set tok "$otok%[strrep $i]"
777 lappend varctok($v) $tok
778 lappend varcrow($v) {}
779 lappend varcix($v) {}
780 set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]]
781 set varccommits($v,$na) [lrange $ac $i end]
782 lappend varcstart($v) $p
783 foreach id $varccommits($v,$na) {
784 set varcid($v,$id) $na
786 lappend vdownptr($v) [lindex $vdownptr($v) $oa]
787 lappend vlastins($v) [lindex $vlastins($v) $oa]
788 lset vdownptr($v) $oa $na
789 lset vlastins($v) $oa 0
790 lappend vupptr($v) $oa
791 lappend vleftptr($v) 0
792 lappend vbackptr($v) 0
793 for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} {
794 lset vupptr($v) $b $na
796 if {[string compare $otok $vtokmod($v)] <= 0} {
797 modify_arc $v $oa
801 proc renumbervarc {a v} {
802 global parents children varctok varcstart varccommits
803 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
805 set t1 [clock clicks -milliseconds]
806 set todo {}
807 set isrelated($a) 1
808 set kidchanged($a) 1
809 set ntot 0
810 while {$a != 0} {
811 if {[info exists isrelated($a)]} {
812 lappend todo $a
813 set id [lindex $varccommits($v,$a) end]
814 foreach p $parents($v,$id) {
815 if {[info exists varcid($v,$p)]} {
816 set isrelated($varcid($v,$p)) 1
820 incr ntot
821 set b [lindex $vdownptr($v) $a]
822 if {$b == 0} {
823 while {$a != 0} {
824 set b [lindex $vleftptr($v) $a]
825 if {$b != 0} break
826 set a [lindex $vupptr($v) $a]
829 set a $b
831 foreach a $todo {
832 if {![info exists kidchanged($a)]} continue
833 set id [lindex $varcstart($v) $a]
834 if {[llength $children($v,$id)] > 1} {
835 set children($v,$id) [lsort -command [list vtokcmp $v] \
836 $children($v,$id)]
838 set oldtok [lindex $varctok($v) $a]
839 if {!$vdatemode($v)} {
840 set tok {}
841 } else {
842 set tok $oldtok
844 set ka 0
845 set kid [last_real_child $v,$id]
846 if {$kid ne {}} {
847 set k $varcid($v,$kid)
848 if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
849 set ki $kid
850 set ka $k
851 set tok [lindex $varctok($v) $k]
854 if {$ka != 0} {
855 set i [lsearch -exact $parents($v,$ki) $id]
856 set j [expr {[llength $parents($v,$ki)] - 1 - $i}]
857 append tok [strrep $j]
859 if {$tok eq $oldtok} {
860 continue
862 set id [lindex $varccommits($v,$a) end]
863 foreach p $parents($v,$id) {
864 if {[info exists varcid($v,$p)]} {
865 set kidchanged($varcid($v,$p)) 1
866 } else {
867 set sortkids($p) 1
870 lset varctok($v) $a $tok
871 set b [lindex $vupptr($v) $a]
872 if {$b != $ka} {
873 if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} {
874 modify_arc $v $ka
876 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
877 modify_arc $v $b
879 set c [lindex $vbackptr($v) $a]
880 set d [lindex $vleftptr($v) $a]
881 if {$c == 0} {
882 lset vdownptr($v) $b $d
883 } else {
884 lset vleftptr($v) $c $d
886 if {$d != 0} {
887 lset vbackptr($v) $d $c
889 if {[lindex $vlastins($v) $b] == $a} {
890 lset vlastins($v) $b $c
892 lset vupptr($v) $a $ka
893 set c [lindex $vlastins($v) $ka]
894 if {$c == 0 || \
895 [string compare $tok [lindex $varctok($v) $c]] < 0} {
896 set c $ka
897 set b [lindex $vdownptr($v) $ka]
898 } else {
899 set b [lindex $vleftptr($v) $c]
901 while {$b != 0 && \
902 [string compare $tok [lindex $varctok($v) $b]] >= 0} {
903 set c $b
904 set b [lindex $vleftptr($v) $c]
906 if {$c == $ka} {
907 lset vdownptr($v) $ka $a
908 lset vbackptr($v) $a 0
909 } else {
910 lset vleftptr($v) $c $a
911 lset vbackptr($v) $a $c
913 lset vleftptr($v) $a $b
914 if {$b != 0} {
915 lset vbackptr($v) $b $a
917 lset vlastins($v) $ka $a
920 foreach id [array names sortkids] {
921 if {[llength $children($v,$id)] > 1} {
922 set children($v,$id) [lsort -command [list vtokcmp $v] \
923 $children($v,$id)]
926 set t2 [clock clicks -milliseconds]
927 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
930 # Fix up the graph after we have found out that in view $v,
931 # $p (a commit that we have already seen) is actually the parent
932 # of the last commit in arc $a.
933 proc fix_reversal {p a v} {
934 global varcid varcstart varctok vupptr
936 set pa $varcid($v,$p)
937 if {$p ne [lindex $varcstart($v) $pa]} {
938 splitvarc $p $v
939 set pa $varcid($v,$p)
941 # seeds always need to be renumbered
942 if {[lindex $vupptr($v) $pa] == 0 ||
943 [string compare [lindex $varctok($v) $a] \
944 [lindex $varctok($v) $pa]] > 0} {
945 renumbervarc $pa $v
949 proc insertrow {id p v} {
950 global cmitlisted children parents varcid varctok vtokmod
951 global varccommits ordertok commitidx numcommits curview
952 global targetid targetrow vshortids
954 readcommit $id
955 set vid $v,$id
956 set cmitlisted($vid) 1
957 set children($vid) {}
958 set parents($vid) [list $p]
959 set a [newvarc $v $id]
960 set varcid($vid) $a
961 lappend vshortids($v,[string range $id 0 3]) $id
962 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
963 modify_arc $v $a
965 lappend varccommits($v,$a) $id
966 set vp $v,$p
967 if {[llength [lappend children($vp) $id]] > 1} {
968 set children($vp) [lsort -command [list vtokcmp $v] $children($vp)]
969 catch {unset ordertok}
971 fix_reversal $p $a $v
972 incr commitidx($v)
973 if {$v == $curview} {
974 set numcommits $commitidx($v)
975 setcanvscroll
976 if {[info exists targetid]} {
977 if {![comes_before $targetid $p]} {
978 incr targetrow
984 proc insertfakerow {id p} {
985 global varcid varccommits parents children cmitlisted
986 global commitidx varctok vtokmod targetid targetrow curview numcommits
988 set v $curview
989 set a $varcid($v,$p)
990 set i [lsearch -exact $varccommits($v,$a) $p]
991 if {$i < 0} {
992 puts "oops: insertfakerow can't find [shortids $p] on arc $a"
993 return
995 set children($v,$id) {}
996 set parents($v,$id) [list $p]
997 set varcid($v,$id) $a
998 lappend children($v,$p) $id
999 set cmitlisted($v,$id) 1
1000 set numcommits [incr commitidx($v)]
1001 # note we deliberately don't update varcstart($v) even if $i == 0
1002 set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
1003 modify_arc $v $a $i
1004 if {[info exists targetid]} {
1005 if {![comes_before $targetid $p]} {
1006 incr targetrow
1009 setcanvscroll
1010 drawvisible
1013 proc removefakerow {id} {
1014 global varcid varccommits parents children commitidx
1015 global varctok vtokmod cmitlisted currentid selectedline
1016 global targetid curview numcommits
1018 set v $curview
1019 if {[llength $parents($v,$id)] != 1} {
1020 puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1021 return
1023 set p [lindex $parents($v,$id) 0]
1024 set a $varcid($v,$id)
1025 set i [lsearch -exact $varccommits($v,$a) $id]
1026 if {$i < 0} {
1027 puts "oops: removefakerow can't find [shortids $id] on arc $a"
1028 return
1030 unset varcid($v,$id)
1031 set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i]
1032 unset parents($v,$id)
1033 unset children($v,$id)
1034 unset cmitlisted($v,$id)
1035 set numcommits [incr commitidx($v) -1]
1036 set j [lsearch -exact $children($v,$p) $id]
1037 if {$j >= 0} {
1038 set children($v,$p) [lreplace $children($v,$p) $j $j]
1040 modify_arc $v $a $i
1041 if {[info exist currentid] && $id eq $currentid} {
1042 unset currentid
1043 set selectedline {}
1045 if {[info exists targetid] && $targetid eq $id} {
1046 set targetid $p
1048 setcanvscroll
1049 drawvisible
1052 proc real_children {vp} {
1053 global children nullid nullid2
1055 set kids {}
1056 foreach id $children($vp) {
1057 if {$id ne $nullid && $id ne $nullid2} {
1058 lappend kids $id
1061 return $kids
1064 proc first_real_child {vp} {
1065 global children nullid nullid2
1067 foreach id $children($vp) {
1068 if {$id ne $nullid && $id ne $nullid2} {
1069 return $id
1072 return {}
1075 proc last_real_child {vp} {
1076 global children nullid nullid2
1078 set kids $children($vp)
1079 for {set i [llength $kids]} {[incr i -1] >= 0} {} {
1080 set id [lindex $kids $i]
1081 if {$id ne $nullid && $id ne $nullid2} {
1082 return $id
1085 return {}
1088 proc vtokcmp {v a b} {
1089 global varctok varcid
1091 return [string compare [lindex $varctok($v) $varcid($v,$a)] \
1092 [lindex $varctok($v) $varcid($v,$b)]]
1095 # This assumes that if lim is not given, the caller has checked that
1096 # arc a's token is less than $vtokmod($v)
1097 proc modify_arc {v a {lim {}}} {
1098 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
1100 if {$lim ne {}} {
1101 set c [string compare [lindex $varctok($v) $a] $vtokmod($v)]
1102 if {$c > 0} return
1103 if {$c == 0} {
1104 set r [lindex $varcrow($v) $a]
1105 if {$r ne {} && $vrowmod($v) <= $r + $lim} return
1108 set vtokmod($v) [lindex $varctok($v) $a]
1109 set varcmod($v) $a
1110 if {$v == $curview} {
1111 while {$a != 0 && [lindex $varcrow($v) $a] eq {}} {
1112 set a [lindex $vupptr($v) $a]
1113 set lim {}
1115 set r 0
1116 if {$a != 0} {
1117 if {$lim eq {}} {
1118 set lim [llength $varccommits($v,$a)]
1120 set r [expr {[lindex $varcrow($v) $a] + $lim}]
1122 set vrowmod($v) $r
1123 undolayout $r
1127 proc update_arcrows {v} {
1128 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
1129 global varcid vrownum varcorder varcix varccommits
1130 global vupptr vdownptr vleftptr varctok
1131 global displayorder parentlist curview cached_commitrow
1133 if {$vrowmod($v) == $commitidx($v)} return
1134 if {$v == $curview} {
1135 if {[llength $displayorder] > $vrowmod($v)} {
1136 set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]]
1137 set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]]
1139 catch {unset cached_commitrow}
1141 set narctot [expr {[llength $varctok($v)] - 1}]
1142 set a $varcmod($v)
1143 while {$a != 0 && [lindex $varcix($v) $a] eq {}} {
1144 # go up the tree until we find something that has a row number,
1145 # or we get to a seed
1146 set a [lindex $vupptr($v) $a]
1148 if {$a == 0} {
1149 set a [lindex $vdownptr($v) 0]
1150 if {$a == 0} return
1151 set vrownum($v) {0}
1152 set varcorder($v) [list $a]
1153 lset varcix($v) $a 0
1154 lset varcrow($v) $a 0
1155 set arcn 0
1156 set row 0
1157 } else {
1158 set arcn [lindex $varcix($v) $a]
1159 if {[llength $vrownum($v)] > $arcn + 1} {
1160 set vrownum($v) [lrange $vrownum($v) 0 $arcn]
1161 set varcorder($v) [lrange $varcorder($v) 0 $arcn]
1163 set row [lindex $varcrow($v) $a]
1165 while {1} {
1166 set p $a
1167 incr row [llength $varccommits($v,$a)]
1168 # go down if possible
1169 set b [lindex $vdownptr($v) $a]
1170 if {$b == 0} {
1171 # if not, go left, or go up until we can go left
1172 while {$a != 0} {
1173 set b [lindex $vleftptr($v) $a]
1174 if {$b != 0} break
1175 set a [lindex $vupptr($v) $a]
1177 if {$a == 0} break
1179 set a $b
1180 incr arcn
1181 lappend vrownum($v) $row
1182 lappend varcorder($v) $a
1183 lset varcix($v) $a $arcn
1184 lset varcrow($v) $a $row
1186 set vtokmod($v) [lindex $varctok($v) $p]
1187 set varcmod($v) $p
1188 set vrowmod($v) $row
1189 if {[info exists currentid]} {
1190 set selectedline [rowofcommit $currentid]
1194 # Test whether view $v contains commit $id
1195 proc commitinview {id v} {
1196 global varcid
1198 return [info exists varcid($v,$id)]
1201 # Return the row number for commit $id in the current view
1202 proc rowofcommit {id} {
1203 global varcid varccommits varcrow curview cached_commitrow
1204 global varctok vtokmod
1206 set v $curview
1207 if {![info exists varcid($v,$id)]} {
1208 puts "oops rowofcommit no arc for [shortids $id]"
1209 return {}
1211 set a $varcid($v,$id)
1212 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
1213 update_arcrows $v
1215 if {[info exists cached_commitrow($id)]} {
1216 return $cached_commitrow($id)
1218 set i [lsearch -exact $varccommits($v,$a) $id]
1219 if {$i < 0} {
1220 puts "oops didn't find commit [shortids $id] in arc $a"
1221 return {}
1223 incr i [lindex $varcrow($v) $a]
1224 set cached_commitrow($id) $i
1225 return $i
1228 # Returns 1 if a is on an earlier row than b, otherwise 0
1229 proc comes_before {a b} {
1230 global varcid varctok curview
1232 set v $curview
1233 if {$a eq $b || ![info exists varcid($v,$a)] || \
1234 ![info exists varcid($v,$b)]} {
1235 return 0
1237 if {$varcid($v,$a) != $varcid($v,$b)} {
1238 return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
1239 [lindex $varctok($v) $varcid($v,$b)]] < 0}]
1241 return [expr {[rowofcommit $a] < [rowofcommit $b]}]
1244 proc bsearch {l elt} {
1245 if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
1246 return 0
1248 set lo 0
1249 set hi [llength $l]
1250 while {$hi - $lo > 1} {
1251 set mid [expr {int(($lo + $hi) / 2)}]
1252 set t [lindex $l $mid]
1253 if {$elt < $t} {
1254 set hi $mid
1255 } elseif {$elt > $t} {
1256 set lo $mid
1257 } else {
1258 return $mid
1261 return $lo
1264 # Make sure rows $start..$end-1 are valid in displayorder and parentlist
1265 proc make_disporder {start end} {
1266 global vrownum curview commitidx displayorder parentlist
1267 global varccommits varcorder parents vrowmod varcrow
1268 global d_valid_start d_valid_end
1270 if {$end > $vrowmod($curview)} {
1271 update_arcrows $curview
1273 set ai [bsearch $vrownum($curview) $start]
1274 set start [lindex $vrownum($curview) $ai]
1275 set narc [llength $vrownum($curview)]
1276 for {set r $start} {$ai < $narc && $r < $end} {incr ai} {
1277 set a [lindex $varcorder($curview) $ai]
1278 set l [llength $displayorder]
1279 set al [llength $varccommits($curview,$a)]
1280 if {$l < $r + $al} {
1281 if {$l < $r} {
1282 set pad [ntimes [expr {$r - $l}] {}]
1283 set displayorder [concat $displayorder $pad]
1284 set parentlist [concat $parentlist $pad]
1285 } elseif {$l > $r} {
1286 set displayorder [lrange $displayorder 0 [expr {$r - 1}]]
1287 set parentlist [lrange $parentlist 0 [expr {$r - 1}]]
1289 foreach id $varccommits($curview,$a) {
1290 lappend displayorder $id
1291 lappend parentlist $parents($curview,$id)
1293 } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} {
1294 set i $r
1295 foreach id $varccommits($curview,$a) {
1296 lset displayorder $i $id
1297 lset parentlist $i $parents($curview,$id)
1298 incr i
1301 incr r $al
1305 proc commitonrow {row} {
1306 global displayorder
1308 set id [lindex $displayorder $row]
1309 if {$id eq {}} {
1310 make_disporder $row [expr {$row + 1}]
1311 set id [lindex $displayorder $row]
1313 return $id
1316 proc closevarcs {v} {
1317 global varctok varccommits varcid parents children
1318 global cmitlisted commitidx vtokmod
1320 set missing_parents 0
1321 set scripts {}
1322 set narcs [llength $varctok($v)]
1323 for {set a 1} {$a < $narcs} {incr a} {
1324 set id [lindex $varccommits($v,$a) end]
1325 foreach p $parents($v,$id) {
1326 if {[info exists varcid($v,$p)]} continue
1327 # add p as a new commit
1328 incr missing_parents
1329 set cmitlisted($v,$p) 0
1330 set parents($v,$p) {}
1331 if {[llength $children($v,$p)] == 1 &&
1332 [llength $parents($v,$id)] == 1} {
1333 set b $a
1334 } else {
1335 set b [newvarc $v $p]
1337 set varcid($v,$p) $b
1338 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
1339 modify_arc $v $b
1341 lappend varccommits($v,$b) $p
1342 incr commitidx($v)
1343 set scripts [check_interest $p $scripts]
1346 if {$missing_parents > 0} {
1347 foreach s $scripts {
1348 eval $s
1353 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1354 # Assumes we already have an arc for $rwid.
1355 proc rewrite_commit {v id rwid} {
1356 global children parents varcid varctok vtokmod varccommits
1358 foreach ch $children($v,$id) {
1359 # make $rwid be $ch's parent in place of $id
1360 set i [lsearch -exact $parents($v,$ch) $id]
1361 if {$i < 0} {
1362 puts "oops rewrite_commit didn't find $id in parent list for $ch"
1364 set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid]
1365 # add $ch to $rwid's children and sort the list if necessary
1366 if {[llength [lappend children($v,$rwid) $ch]] > 1} {
1367 set children($v,$rwid) [lsort -command [list vtokcmp $v] \
1368 $children($v,$rwid)]
1370 # fix the graph after joining $id to $rwid
1371 set a $varcid($v,$ch)
1372 fix_reversal $rwid $a $v
1373 # parentlist is wrong for the last element of arc $a
1374 # even if displayorder is right, hence the 3rd arg here
1375 modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}]
1379 # Mechanism for registering a command to be executed when we come
1380 # across a particular commit. To handle the case when only the
1381 # prefix of the commit is known, the commitinterest array is now
1382 # indexed by the first 4 characters of the ID. Each element is a
1383 # list of id, cmd pairs.
1384 proc interestedin {id cmd} {
1385 global commitinterest
1387 lappend commitinterest([string range $id 0 3]) $id $cmd
1390 proc check_interest {id scripts} {
1391 global commitinterest
1393 set prefix [string range $id 0 3]
1394 if {[info exists commitinterest($prefix)]} {
1395 set newlist {}
1396 foreach {i script} $commitinterest($prefix) {
1397 if {[string match "$i*" $id]} {
1398 lappend scripts [string map [list "%I" $id "%P" $i] $script]
1399 } else {
1400 lappend newlist $i $script
1403 if {$newlist ne {}} {
1404 set commitinterest($prefix) $newlist
1405 } else {
1406 unset commitinterest($prefix)
1409 return $scripts
1412 proc getcommitlines {fd inst view updating} {
1413 global cmitlisted leftover
1414 global commitidx commitdata vdatemode
1415 global parents children curview hlview
1416 global idpending ordertok
1417 global varccommits varcid varctok vtokmod vfilelimit vshortids
1419 set stuff [read $fd 500000]
1420 # git log doesn't terminate the last commit with a null...
1421 if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} {
1422 set stuff "\0"
1424 if {$stuff == {}} {
1425 if {![eof $fd]} {
1426 return 1
1428 global commfd viewcomplete viewactive viewname
1429 global viewinstances
1430 unset commfd($inst)
1431 set i [lsearch -exact $viewinstances($view) $inst]
1432 if {$i >= 0} {
1433 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
1435 # set it blocking so we wait for the process to terminate
1436 fconfigure $fd -blocking 1
1437 if {[catch {close $fd} err]} {
1438 set fv {}
1439 if {$view != $curview} {
1440 set fv " for the \"$viewname($view)\" view"
1442 if {[string range $err 0 4] == "usage"} {
1443 set err "Gitk: error reading commits$fv:\
1444 bad arguments to git log."
1445 if {$viewname($view) eq "Command line"} {
1446 append err \
1447 " (Note: arguments to gitk are passed to git log\
1448 to allow selection of commits to be displayed.)"
1450 } else {
1451 set err "Error reading commits$fv: $err"
1453 error_popup $err
1455 if {[incr viewactive($view) -1] <= 0} {
1456 set viewcomplete($view) 1
1457 # Check if we have seen any ids listed as parents that haven't
1458 # appeared in the list
1459 closevarcs $view
1460 notbusy $view
1462 if {$view == $curview} {
1463 run chewcommits
1465 return 0
1467 set start 0
1468 set gotsome 0
1469 set scripts {}
1470 while 1 {
1471 set i [string first "\0" $stuff $start]
1472 if {$i < 0} {
1473 append leftover($inst) [string range $stuff $start end]
1474 break
1476 if {$start == 0} {
1477 set cmit $leftover($inst)
1478 append cmit [string range $stuff 0 [expr {$i - 1}]]
1479 set leftover($inst) {}
1480 } else {
1481 set cmit [string range $stuff $start [expr {$i - 1}]]
1483 set start [expr {$i + 1}]
1484 set j [string first "\n" $cmit]
1485 set ok 0
1486 set listed 1
1487 if {$j >= 0 && [string match "commit *" $cmit]} {
1488 set ids [string range $cmit 7 [expr {$j - 1}]]
1489 if {[string match {[-^<>]*} $ids]} {
1490 switch -- [string index $ids 0] {
1491 "-" {set listed 0}
1492 "^" {set listed 2}
1493 "<" {set listed 3}
1494 ">" {set listed 4}
1496 set ids [string range $ids 1 end]
1498 set ok 1
1499 foreach id $ids {
1500 if {[string length $id] != 40} {
1501 set ok 0
1502 break
1506 if {!$ok} {
1507 set shortcmit $cmit
1508 if {[string length $shortcmit] > 80} {
1509 set shortcmit "[string range $shortcmit 0 80]..."
1511 error_popup "[mc "Can't parse git log output:"] {$shortcmit}"
1512 exit 1
1514 set id [lindex $ids 0]
1515 set vid $view,$id
1517 lappend vshortids($view,[string range $id 0 3]) $id
1519 if {!$listed && $updating && ![info exists varcid($vid)] &&
1520 $vfilelimit($view) ne {}} {
1521 # git log doesn't rewrite parents for unlisted commits
1522 # when doing path limiting, so work around that here
1523 # by working out the rewritten parent with git rev-list
1524 # and if we already know about it, using the rewritten
1525 # parent as a substitute parent for $id's children.
1526 if {![catch {
1527 set rwid [exec git rev-list --first-parent --max-count=1 \
1528 $id -- $vfilelimit($view)]
1529 }]} {
1530 if {$rwid ne {} && [info exists varcid($view,$rwid)]} {
1531 # use $rwid in place of $id
1532 rewrite_commit $view $id $rwid
1533 continue
1538 set a 0
1539 if {[info exists varcid($vid)]} {
1540 if {$cmitlisted($vid) || !$listed} continue
1541 set a $varcid($vid)
1543 if {$listed} {
1544 set olds [lrange $ids 1 end]
1545 } else {
1546 set olds {}
1548 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
1549 set cmitlisted($vid) $listed
1550 set parents($vid) $olds
1551 if {![info exists children($vid)]} {
1552 set children($vid) {}
1553 } elseif {$a == 0 && [llength $children($vid)] == 1} {
1554 set k [lindex $children($vid) 0]
1555 if {[llength $parents($view,$k)] == 1 &&
1556 (!$vdatemode($view) ||
1557 $varcid($view,$k) == [llength $varctok($view)] - 1)} {
1558 set a $varcid($view,$k)
1561 if {$a == 0} {
1562 # new arc
1563 set a [newvarc $view $id]
1565 if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} {
1566 modify_arc $view $a
1568 if {![info exists varcid($vid)]} {
1569 set varcid($vid) $a
1570 lappend varccommits($view,$a) $id
1571 incr commitidx($view)
1574 set i 0
1575 foreach p $olds {
1576 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
1577 set vp $view,$p
1578 if {[llength [lappend children($vp) $id]] > 1 &&
1579 [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} {
1580 set children($vp) [lsort -command [list vtokcmp $view] \
1581 $children($vp)]
1582 catch {unset ordertok}
1584 if {[info exists varcid($view,$p)]} {
1585 fix_reversal $p $a $view
1588 incr i
1591 set scripts [check_interest $id $scripts]
1592 set gotsome 1
1594 if {$gotsome} {
1595 global numcommits hlview
1597 if {$view == $curview} {
1598 set numcommits $commitidx($view)
1599 run chewcommits
1601 if {[info exists hlview] && $view == $hlview} {
1602 # we never actually get here...
1603 run vhighlightmore
1605 foreach s $scripts {
1606 eval $s
1609 return 2
1612 proc chewcommits {} {
1613 global curview hlview viewcomplete
1614 global pending_select
1616 layoutmore
1617 if {$viewcomplete($curview)} {
1618 global commitidx varctok
1619 global numcommits startmsecs
1621 if {[info exists pending_select]} {
1622 update
1623 reset_pending_select {}
1625 if {[commitinview $pending_select $curview]} {
1626 selectline [rowofcommit $pending_select] 1
1627 } else {
1628 set row [first_real_row]
1629 selectline $row 1
1632 if {$commitidx($curview) > 0} {
1633 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1634 #puts "overall $ms ms for $numcommits commits"
1635 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1636 } else {
1637 show_status [mc "No commits selected"]
1639 notbusy layout
1641 return 0
1644 proc do_readcommit {id} {
1645 global tclencoding
1647 # Invoke git-log to handle automatic encoding conversion
1648 set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
1649 # Read the results using i18n.logoutputencoding
1650 fconfigure $fd -translation lf -eofchar {}
1651 if {$tclencoding != {}} {
1652 fconfigure $fd -encoding $tclencoding
1654 set contents [read $fd]
1655 close $fd
1656 # Remove the heading line
1657 regsub {^commit [0-9a-f]+\n} $contents {} contents
1659 return $contents
1662 proc readcommit {id} {
1663 if {[catch {set contents [do_readcommit $id]}]} return
1664 parsecommit $id $contents 1
1667 proc parsecommit {id contents listed} {
1668 global commitinfo
1670 set inhdr 1
1671 set comment {}
1672 set headline {}
1673 set auname {}
1674 set audate {}
1675 set comname {}
1676 set comdate {}
1677 set hdrend [string first "\n\n" $contents]
1678 if {$hdrend < 0} {
1679 # should never happen...
1680 set hdrend [string length $contents]
1682 set header [string range $contents 0 [expr {$hdrend - 1}]]
1683 set comment [string range $contents [expr {$hdrend + 2}] end]
1684 foreach line [split $header "\n"] {
1685 set line [split $line " "]
1686 set tag [lindex $line 0]
1687 if {$tag == "author"} {
1688 set audate [lrange $line end-1 end]
1689 set auname [join [lrange $line 1 end-2] " "]
1690 } elseif {$tag == "committer"} {
1691 set comdate [lrange $line end-1 end]
1692 set comname [join [lrange $line 1 end-2] " "]
1695 set headline {}
1696 # take the first non-blank line of the comment as the headline
1697 set headline [string trimleft $comment]
1698 set i [string first "\n" $headline]
1699 if {$i >= 0} {
1700 set headline [string range $headline 0 $i]
1702 set headline [string trimright $headline]
1703 set i [string first "\r" $headline]
1704 if {$i >= 0} {
1705 set headline [string trimright [string range $headline 0 $i]]
1707 if {!$listed} {
1708 # git log indents the comment by 4 spaces;
1709 # if we got this via git cat-file, add the indentation
1710 set newcomment {}
1711 foreach line [split $comment "\n"] {
1712 append newcomment " "
1713 append newcomment $line
1714 append newcomment "\n"
1716 set comment $newcomment
1718 set hasnote [string first "\nNotes:\n" $contents]
1719 set diff ""
1720 # If there is diff output shown in the git-log stream, split it
1721 # out. But get rid of the empty line that always precedes the
1722 # diff.
1723 set i [string first "\n\ndiff" $comment]
1724 if {$i >= 0} {
1725 set diff [string range $comment $i+1 end]
1726 set comment [string range $comment 0 $i-1]
1728 set commitinfo($id) [list $headline $auname $audate \
1729 $comname $comdate $comment $hasnote $diff]
1732 proc getcommit {id} {
1733 global commitdata commitinfo
1735 if {[info exists commitdata($id)]} {
1736 parsecommit $id $commitdata($id) 1
1737 } else {
1738 readcommit $id
1739 if {![info exists commitinfo($id)]} {
1740 set commitinfo($id) [list [mc "No commit information available"]]
1743 return 1
1746 # Expand an abbreviated commit ID to a list of full 40-char IDs that match
1747 # and are present in the current view.
1748 # This is fairly slow...
1749 proc longid {prefix} {
1750 global varcid curview vshortids
1752 set ids {}
1753 if {[string length $prefix] >= 4} {
1754 set vshortid $curview,[string range $prefix 0 3]
1755 if {[info exists vshortids($vshortid)]} {
1756 foreach id $vshortids($vshortid) {
1757 if {[string match "$prefix*" $id]} {
1758 if {[lsearch -exact $ids $id] < 0} {
1759 lappend ids $id
1760 if {[llength $ids] >= 2} break
1765 } else {
1766 foreach match [array names varcid "$curview,$prefix*"] {
1767 lappend ids [lindex [split $match ","] 1]
1768 if {[llength $ids] >= 2} break
1771 return $ids
1774 proc readrefs {} {
1775 global tagids idtags headids idheads tagobjid
1776 global otherrefids idotherrefs mainhead mainheadid
1777 global selecthead selectheadid
1778 global hideremotes
1780 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
1781 catch {unset $v}
1783 set refd [open [list | git show-ref -d] r]
1784 while {[gets $refd line] >= 0} {
1785 if {[string index $line 40] ne " "} continue
1786 set id [string range $line 0 39]
1787 set ref [string range $line 41 end]
1788 if {![string match "refs/*" $ref]} continue
1789 set name [string range $ref 5 end]
1790 if {[string match "remotes/*" $name]} {
1791 if {![string match "*/HEAD" $name] && !$hideremotes} {
1792 set headids($name) $id
1793 lappend idheads($id) $name
1795 } elseif {[string match "heads/*" $name]} {
1796 set name [string range $name 6 end]
1797 set headids($name) $id
1798 lappend idheads($id) $name
1799 } elseif {[string match "tags/*" $name]} {
1800 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1801 # which is what we want since the former is the commit ID
1802 set name [string range $name 5 end]
1803 if {[string match "*^{}" $name]} {
1804 set name [string range $name 0 end-3]
1805 } else {
1806 set tagobjid($name) $id
1808 set tagids($name) $id
1809 lappend idtags($id) $name
1810 } else {
1811 set otherrefids($name) $id
1812 lappend idotherrefs($id) $name
1815 catch {close $refd}
1816 set mainhead {}
1817 set mainheadid {}
1818 catch {
1819 set mainheadid [exec git rev-parse HEAD]
1820 set thehead [exec git symbolic-ref HEAD]
1821 if {[string match "refs/heads/*" $thehead]} {
1822 set mainhead [string range $thehead 11 end]
1825 set selectheadid {}
1826 if {$selecthead ne {}} {
1827 catch {
1828 set selectheadid [exec git rev-parse --verify $selecthead]
1833 # skip over fake commits
1834 proc first_real_row {} {
1835 global nullid nullid2 numcommits
1837 for {set row 0} {$row < $numcommits} {incr row} {
1838 set id [commitonrow $row]
1839 if {$id ne $nullid && $id ne $nullid2} {
1840 break
1843 return $row
1846 # update things for a head moved to a child of its previous location
1847 proc movehead {id name} {
1848 global headids idheads
1850 removehead $headids($name) $name
1851 set headids($name) $id
1852 lappend idheads($id) $name
1855 # update things when a head has been removed
1856 proc removehead {id name} {
1857 global headids idheads
1859 if {$idheads($id) eq $name} {
1860 unset idheads($id)
1861 } else {
1862 set i [lsearch -exact $idheads($id) $name]
1863 if {$i >= 0} {
1864 set idheads($id) [lreplace $idheads($id) $i $i]
1867 unset headids($name)
1870 proc ttk_toplevel {w args} {
1871 global use_ttk
1872 eval [linsert $args 0 ::toplevel $w]
1873 if {$use_ttk} {
1874 place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1
1876 return $w
1879 proc make_transient {window origin} {
1880 global have_tk85
1882 # In MacOS Tk 8.4 transient appears to work by setting
1883 # overrideredirect, which is utterly useless, since the
1884 # windows get no border, and are not even kept above
1885 # the parent.
1886 if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return
1888 wm transient $window $origin
1890 # Windows fails to place transient windows normally, so
1891 # schedule a callback to center them on the parent.
1892 if {[tk windowingsystem] eq {win32}} {
1893 after idle [list tk::PlaceWindow $window widget $origin]
1897 proc show_error {w top msg {mc mc}} {
1898 global NS
1899 if {![info exists NS]} {set NS ""}
1900 if {[wm state $top] eq "withdrawn"} { wm deiconify $top }
1901 message $w.m -text $msg -justify center -aspect 400
1902 pack $w.m -side top -fill x -padx 20 -pady 20
1903 ${NS}::button $w.ok -default active -text [$mc OK] -command "destroy $top"
1904 pack $w.ok -side bottom -fill x
1905 bind $top <Visibility> "grab $top; focus $top"
1906 bind $top <Key-Return> "destroy $top"
1907 bind $top <Key-space> "destroy $top"
1908 bind $top <Key-Escape> "destroy $top"
1909 tkwait window $top
1912 proc error_popup {msg {owner .}} {
1913 if {[tk windowingsystem] eq "win32"} {
1914 tk_messageBox -icon error -type ok -title [wm title .] \
1915 -parent $owner -message $msg
1916 } else {
1917 set w .error
1918 ttk_toplevel $w
1919 make_transient $w $owner
1920 show_error $w $w $msg
1924 proc confirm_popup {msg {owner .}} {
1925 global confirm_ok NS
1926 set confirm_ok 0
1927 set w .confirm
1928 ttk_toplevel $w
1929 make_transient $w $owner
1930 message $w.m -text $msg -justify center -aspect 400
1931 pack $w.m -side top -fill x -padx 20 -pady 20
1932 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
1933 pack $w.ok -side left -fill x
1934 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
1935 pack $w.cancel -side right -fill x
1936 bind $w <Visibility> "grab $w; focus $w"
1937 bind $w <Key-Return> "set confirm_ok 1; destroy $w"
1938 bind $w <Key-space> "set confirm_ok 1; destroy $w"
1939 bind $w <Key-Escape> "destroy $w"
1940 tk::PlaceWindow $w widget $owner
1941 tkwait window $w
1942 return $confirm_ok
1945 proc setoptions {} {
1946 if {[tk windowingsystem] ne "win32"} {
1947 option add *Panedwindow.showHandle 1 startupFile
1948 option add *Panedwindow.sashRelief raised startupFile
1949 if {[tk windowingsystem] ne "aqua"} {
1950 option add *Menu.font uifont startupFile
1952 } else {
1953 option add *Menu.TearOff 0 startupFile
1955 option add *Button.font uifont startupFile
1956 option add *Checkbutton.font uifont startupFile
1957 option add *Radiobutton.font uifont startupFile
1958 option add *Menubutton.font uifont startupFile
1959 option add *Label.font uifont startupFile
1960 option add *Message.font uifont startupFile
1961 option add *Entry.font textfont startupFile
1962 option add *Text.font textfont startupFile
1963 option add *Labelframe.font uifont startupFile
1964 option add *Spinbox.font textfont startupFile
1965 option add *Listbox.font mainfont startupFile
1968 # Make a menu and submenus.
1969 # m is the window name for the menu, items is the list of menu items to add.
1970 # Each item is a list {mc label type description options...}
1971 # mc is ignored; it's so we can put mc there to alert xgettext
1972 # label is the string that appears in the menu
1973 # type is cascade, command or radiobutton (should add checkbutton)
1974 # description depends on type; it's the sublist for cascade, the
1975 # command to invoke for command, or {variable value} for radiobutton
1976 proc makemenu {m items} {
1977 menu $m
1978 if {[tk windowingsystem] eq {aqua}} {
1979 set Meta1 Cmd
1980 } else {
1981 set Meta1 Ctrl
1983 foreach i $items {
1984 set name [mc [lindex $i 1]]
1985 set type [lindex $i 2]
1986 set thing [lindex $i 3]
1987 set params [list $type]
1988 if {$name ne {}} {
1989 set u [string first "&" [string map {&& x} $name]]
1990 lappend params -label [string map {&& & & {}} $name]
1991 if {$u >= 0} {
1992 lappend params -underline $u
1995 switch -- $type {
1996 "cascade" {
1997 set submenu [string tolower [string map {& ""} [lindex $i 1]]]
1998 lappend params -menu $m.$submenu
2000 "command" {
2001 lappend params -command $thing
2003 "radiobutton" {
2004 lappend params -variable [lindex $thing 0] \
2005 -value [lindex $thing 1]
2008 set tail [lrange $i 4 end]
2009 regsub -all {\yMeta1\y} $tail $Meta1 tail
2010 eval $m add $params $tail
2011 if {$type eq "cascade"} {
2012 makemenu $m.$submenu $thing
2017 # translate string and remove ampersands
2018 proc mca {str} {
2019 return [string map {&& & & {}} [mc $str]]
2022 proc cleardropsel {w} {
2023 $w selection clear
2025 proc makedroplist {w varname args} {
2026 global use_ttk
2027 if {$use_ttk} {
2028 set width 0
2029 foreach label $args {
2030 set cx [string length $label]
2031 if {$cx > $width} {set width $cx}
2033 set gm [ttk::combobox $w -width $width -state readonly\
2034 -textvariable $varname -values $args \
2035 -exportselection false]
2036 bind $gm <<ComboboxSelected>> [list $gm selection clear]
2037 } else {
2038 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
2040 return $gm
2043 proc makewindow {} {
2044 global canv canv2 canv3 linespc charspc ctext cflist cscroll
2045 global tabstop
2046 global findtype findtypemenu findloc findstring fstring geometry
2047 global entries sha1entry sha1string sha1but
2048 global diffcontextstring diffcontext
2049 global ignorespace
2050 global maincursor textcursor curtextcursor
2051 global rowctxmenu fakerowmenu mergemax wrapcomment
2052 global highlight_files gdttype
2053 global searchstring sstring
2054 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
2055 global uifgcolor uifgdisabledcolor
2056 global filesepbgcolor filesepfgcolor
2057 global mergecolors foundbgcolor currentsearchhitbgcolor
2058 global headctxmenu progresscanv progressitem progresscoords statusw
2059 global fprogitem fprogcoord lastprogupdate progupdatepending
2060 global rprogitem rprogcoord rownumsel numcommits
2061 global have_tk85 use_ttk NS
2062 global git_version
2063 global worddiff
2065 # The "mc" arguments here are purely so that xgettext
2066 # sees the following string as needing to be translated
2067 set file {
2068 mc "File" cascade {
2069 {mc "Update" command updatecommits -accelerator F5}
2070 {mc "Reload" command reloadcommits -accelerator Shift-F5}
2071 {mc "Reread references" command rereadrefs}
2072 {mc "List references" command showrefs -accelerator F2}
2073 {xx "" separator}
2074 {mc "Start git gui" command {exec git gui &}}
2075 {xx "" separator}
2076 {mc "Quit" command doquit -accelerator Meta1-Q}
2078 set edit {
2079 mc "Edit" cascade {
2080 {mc "Preferences" command doprefs}
2082 set view {
2083 mc "View" cascade {
2084 {mc "New view..." command {newview 0} -accelerator Shift-F4}
2085 {mc "Edit view..." command editview -state disabled -accelerator F4}
2086 {mc "Delete view" command delview -state disabled}
2087 {xx "" separator}
2088 {mc "All files" radiobutton {selectedview 0} -command {showview 0}}
2090 if {[tk windowingsystem] ne "aqua"} {
2091 set help {
2092 mc "Help" cascade {
2093 {mc "About gitk" command about}
2094 {mc "Key bindings" command keys}
2096 set bar [list $file $edit $view $help]
2097 } else {
2098 proc ::tk::mac::ShowPreferences {} {doprefs}
2099 proc ::tk::mac::Quit {} {doquit}
2100 lset file end [lreplace [lindex $file end] end-1 end]
2101 set apple {
2102 xx "Apple" cascade {
2103 {mc "About gitk" command about}
2104 {xx "" separator}
2106 set help {
2107 mc "Help" cascade {
2108 {mc "Key bindings" command keys}
2110 set bar [list $apple $file $view $help]
2112 makemenu .bar $bar
2113 . configure -menu .bar
2115 if {$use_ttk} {
2116 # cover the non-themed toplevel with a themed frame.
2117 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2120 # the gui has upper and lower half, parts of a paned window.
2121 ${NS}::panedwindow .ctop -orient vertical
2123 # possibly use assumed geometry
2124 if {![info exists geometry(pwsash0)]} {
2125 set geometry(topheight) [expr {15 * $linespc}]
2126 set geometry(topwidth) [expr {80 * $charspc}]
2127 set geometry(botheight) [expr {15 * $linespc}]
2128 set geometry(botwidth) [expr {50 * $charspc}]
2129 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2130 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
2133 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
2134 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2135 ${NS}::frame .tf.histframe
2136 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2137 if {!$use_ttk} {
2138 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
2141 # create three canvases
2142 set cscroll .tf.histframe.csb
2143 set canv .tf.histframe.pwclist.canv
2144 canvas $canv \
2145 -selectbackground $selectbgcolor \
2146 -background $bgcolor -bd 0 \
2147 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
2148 .tf.histframe.pwclist add $canv
2149 set canv2 .tf.histframe.pwclist.canv2
2150 canvas $canv2 \
2151 -selectbackground $selectbgcolor \
2152 -background $bgcolor -bd 0 -yscrollincr $linespc
2153 .tf.histframe.pwclist add $canv2
2154 set canv3 .tf.histframe.pwclist.canv3
2155 canvas $canv3 \
2156 -selectbackground $selectbgcolor \
2157 -background $bgcolor -bd 0 -yscrollincr $linespc
2158 .tf.histframe.pwclist add $canv3
2159 if {$use_ttk} {
2160 bind .tf.histframe.pwclist <Map> {
2161 bind %W <Map> {}
2162 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2163 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2165 } else {
2166 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2167 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
2170 # a scroll bar to rule them
2171 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2172 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
2173 pack $cscroll -side right -fill y
2174 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2175 lappend bglist $canv $canv2 $canv3
2176 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2178 # we have two button bars at bottom of top frame. Bar 1
2179 ${NS}::frame .tf.bar
2180 ${NS}::frame .tf.lbar -height 15
2182 set sha1entry .tf.bar.sha1
2183 set entries $sha1entry
2184 set sha1but .tf.bar.sha1label
2185 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
2186 -command gotocommit -width 8
2187 $sha1but conf -disabledforeground [$sha1but cget -foreground]
2188 pack .tf.bar.sha1label -side left
2189 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
2190 trace add variable sha1string write sha1change
2191 pack $sha1entry -side left -pady 2
2193 set bm_left_data {
2194 #define left_width 16
2195 #define left_height 16
2196 static unsigned char left_bits[] = {
2197 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2198 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2199 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
2201 set bm_right_data {
2202 #define right_width 16
2203 #define right_height 16
2204 static unsigned char right_bits[] = {
2205 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2206 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2207 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
2209 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2210 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2211 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2212 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
2214 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2215 if {$use_ttk} {
2216 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
2217 } else {
2218 .tf.bar.leftbut configure -image bm-left
2220 pack .tf.bar.leftbut -side left -fill y
2221 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2222 if {$use_ttk} {
2223 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
2224 } else {
2225 .tf.bar.rightbut configure -image bm-right
2227 pack .tf.bar.rightbut -side left -fill y
2229 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
2230 set rownumsel {}
2231 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
2232 -relief sunken -anchor e
2233 ${NS}::label .tf.bar.rowlabel2 -text "/"
2234 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
2235 -relief sunken -anchor e
2236 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
2237 -side left
2238 if {!$use_ttk} {
2239 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2241 global selectedline
2242 trace add variable selectedline write selectedline_change
2244 # Status label and progress bar
2245 set statusw .tf.bar.status
2246 ${NS}::label $statusw -width 15 -relief sunken
2247 pack $statusw -side left -padx 5
2248 if {$use_ttk} {
2249 set progresscanv [ttk::progressbar .tf.bar.progress]
2250 } else {
2251 set h [expr {[font metrics uifont -linespace] + 2}]
2252 set progresscanv .tf.bar.progress
2253 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2254 set progressitem [$progresscanv create rect -1 0 0 $h -fill green]
2255 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2256 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
2258 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
2259 set progresscoords {0 0}
2260 set fprogcoord 0
2261 set rprogcoord 0
2262 bind $progresscanv <Configure> adjustprogress
2263 set lastprogupdate [clock clicks -milliseconds]
2264 set progupdatepending 0
2266 # build up the bottom bar of upper window
2267 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
2269 set bm_down_data {
2270 #define down_width 16
2271 #define down_height 16
2272 static unsigned char down_bits[] = {
2273 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2274 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2275 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2276 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
2278 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2279 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2280 .tf.lbar.fnext configure -image bm-down
2282 set bm_up_data {
2283 #define up_width 16
2284 #define up_height 16
2285 static unsigned char up_bits[] = {
2286 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2287 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2288 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2289 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
2291 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2292 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2293 .tf.lbar.fprev configure -image bm-up
2295 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
2297 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
2298 -side left -fill y
2299 set gdttype [mc "containing:"]
2300 set gm [makedroplist .tf.lbar.gdttype gdttype \
2301 [mc "containing:"] \
2302 [mc "touching paths:"] \
2303 [mc "adding/removing string:"] \
2304 [mc "changing lines matching:"]]
2305 trace add variable gdttype write gdttype_change
2306 pack .tf.lbar.gdttype -side left -fill y
2308 set findstring {}
2309 set fstring .tf.lbar.findstring
2310 lappend entries $fstring
2311 ${NS}::entry $fstring -width 30 -textvariable findstring
2312 trace add variable findstring write find_change
2313 set findtype [mc "Exact"]
2314 set findtypemenu [makedroplist .tf.lbar.findtype \
2315 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
2316 trace add variable findtype write findcom_change
2317 set findloc [mc "All fields"]
2318 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
2319 [mc "Comments"] [mc "Author"] [mc "Committer"]
2320 trace add variable findloc write find_change
2321 pack .tf.lbar.findloc -side right
2322 pack .tf.lbar.findtype -side right
2323 pack $fstring -side left -expand 1 -fill x
2325 # Finish putting the upper half of the viewer together
2326 pack .tf.lbar -in .tf -side bottom -fill x
2327 pack .tf.bar -in .tf -side bottom -fill x
2328 pack .tf.histframe -fill both -side top -expand 1
2329 .ctop add .tf
2330 if {!$use_ttk} {
2331 .ctop paneconfigure .tf -height $geometry(topheight)
2332 .ctop paneconfigure .tf -width $geometry(topwidth)
2335 # now build up the bottom
2336 ${NS}::panedwindow .pwbottom -orient horizontal
2338 # lower left, a text box over search bar, scroll bar to the right
2339 # if we know window height, then that will set the lower text height, otherwise
2340 # we set lower text height which will drive window height
2341 if {[info exists geometry(main)]} {
2342 ${NS}::frame .bleft -width $geometry(botwidth)
2343 } else {
2344 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
2346 ${NS}::frame .bleft.top
2347 ${NS}::frame .bleft.mid
2348 ${NS}::frame .bleft.bottom
2350 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
2351 pack .bleft.top.search -side left -padx 5
2352 set sstring .bleft.top.sstring
2353 set searchstring ""
2354 ${NS}::entry $sstring -width 20 -textvariable searchstring
2355 lappend entries $sstring
2356 trace add variable searchstring write incrsearch
2357 pack $sstring -side left -expand 1 -fill x
2358 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
2359 -command changediffdisp -variable diffelide -value {0 0}
2360 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
2361 -command changediffdisp -variable diffelide -value {0 1}
2362 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
2363 -command changediffdisp -variable diffelide -value {1 0}
2364 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
2365 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
2366 spinbox .bleft.mid.diffcontext -width 5 \
2367 -from 0 -increment 1 -to 10000000 \
2368 -validate all -validatecommand "diffcontextvalidate %P" \
2369 -textvariable diffcontextstring
2370 .bleft.mid.diffcontext set $diffcontext
2371 trace add variable diffcontextstring write diffcontextchange
2372 lappend entries .bleft.mid.diffcontext
2373 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left
2374 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
2375 -command changeignorespace -variable ignorespace
2376 pack .bleft.mid.ignspace -side left -padx 5
2378 set worddiff [mc "Line diff"]
2379 if {[package vcompare $git_version "1.7.2"] >= 0} {
2380 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2381 [mc "Markup words"] [mc "Color words"]
2382 trace add variable worddiff write changeworddiff
2383 pack .bleft.mid.worddiff -side left -padx 5
2386 set ctext .bleft.bottom.ctext
2387 text $ctext -background $bgcolor -foreground $fgcolor \
2388 -state disabled -font textfont \
2389 -yscrollcommand scrolltext -wrap none \
2390 -xscrollcommand ".bleft.bottom.sbhorizontal set"
2391 if {$have_tk85} {
2392 $ctext conf -tabstyle wordprocessor
2394 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2395 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
2396 pack .bleft.top -side top -fill x
2397 pack .bleft.mid -side top -fill x
2398 grid $ctext .bleft.bottom.sb -sticky nsew
2399 grid .bleft.bottom.sbhorizontal -sticky ew
2400 grid columnconfigure .bleft.bottom 0 -weight 1
2401 grid rowconfigure .bleft.bottom 0 -weight 1
2402 grid rowconfigure .bleft.bottom 1 -weight 0
2403 pack .bleft.bottom -side top -fill both -expand 1
2404 lappend bglist $ctext
2405 lappend fglist $ctext
2407 $ctext tag conf comment -wrap $wrapcomment
2408 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
2409 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2410 $ctext tag conf d0 -fore [lindex $diffcolors 0]
2411 $ctext tag conf dresult -fore [lindex $diffcolors 1]
2412 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2413 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2414 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2415 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2416 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2417 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2418 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2419 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2420 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2421 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2422 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2423 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2424 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2425 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2426 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2427 $ctext tag conf m15 -fore [lindex $mergecolors 15]
2428 $ctext tag conf mmax -fore darkgrey
2429 set mergemax 16
2430 $ctext tag conf mresult -font textfontbold
2431 $ctext tag conf msep -font textfontbold
2432 $ctext tag conf found -back $foundbgcolor
2433 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
2434 $ctext tag conf wwrap -wrap word -lmargin2 1c
2435 $ctext tag conf bold -font textfontbold
2437 .pwbottom add .bleft
2438 if {!$use_ttk} {
2439 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
2442 # lower right
2443 ${NS}::frame .bright
2444 ${NS}::frame .bright.mode
2445 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
2446 -command reselectline -variable cmitmode -value "patch"
2447 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
2448 -command reselectline -variable cmitmode -value "tree"
2449 grid .bright.mode.patch .bright.mode.tree -sticky ew
2450 pack .bright.mode -side top -fill x
2451 set cflist .bright.cfiles
2452 set indent [font measure mainfont "nn"]
2453 text $cflist \
2454 -selectbackground $selectbgcolor \
2455 -background $bgcolor -foreground $fgcolor \
2456 -font mainfont \
2457 -tabs [list $indent [expr {2 * $indent}]] \
2458 -yscrollcommand ".bright.sb set" \
2459 -cursor [. cget -cursor] \
2460 -spacing1 1 -spacing3 1
2461 lappend bglist $cflist
2462 lappend fglist $cflist
2463 ${NS}::scrollbar .bright.sb -command "$cflist yview"
2464 pack .bright.sb -side right -fill y
2465 pack $cflist -side left -fill both -expand 1
2466 $cflist tag configure highlight \
2467 -background [$cflist cget -selectbackground]
2468 $cflist tag configure bold -font mainfontbold
2470 .pwbottom add .bright
2471 .ctop add .pwbottom
2473 # restore window width & height if known
2474 if {[info exists geometry(main)]} {
2475 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2476 if {$w > [winfo screenwidth .]} {
2477 set w [winfo screenwidth .]
2479 if {$h > [winfo screenheight .]} {
2480 set h [winfo screenheight .]
2482 wm geometry . "${w}x$h"
2486 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2487 wm state . $geometry(state)
2490 if {[tk windowingsystem] eq {aqua}} {
2491 set M1B M1
2492 set ::BM "3"
2493 } else {
2494 set M1B Control
2495 set ::BM "2"
2498 if {$use_ttk} {
2499 bind .ctop <Map> {
2500 bind %W <Map> {}
2501 %W sashpos 0 $::geometry(topheight)
2503 bind .pwbottom <Map> {
2504 bind %W <Map> {}
2505 %W sashpos 0 $::geometry(botwidth)
2509 bind .pwbottom <Configure> {resizecdetpanes %W %w}
2510 pack .ctop -fill both -expand 1
2511 bindall <1> {selcanvline %W %x %y}
2512 #bindall <B1-Motion> {selcanvline %W %x %y}
2513 if {[tk windowingsystem] == "win32"} {
2514 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2515 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2516 } else {
2517 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2518 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2519 if {[tk windowingsystem] eq "aqua"} {
2520 bindall <MouseWheel> {
2521 set delta [expr {- (%D)}]
2522 allcanvs yview scroll $delta units
2524 bindall <Shift-MouseWheel> {
2525 set delta [expr {- (%D)}]
2526 $canv xview scroll $delta units
2530 bindall <$::BM> "canvscan mark %W %x %y"
2531 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
2532 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2533 bind . <$M1B-Key-w> doquit
2534 bindkey <Home> selfirstline
2535 bindkey <End> sellastline
2536 bind . <Key-Up> "selnextline -1"
2537 bind . <Key-Down> "selnextline 1"
2538 bind . <Shift-Key-Up> "dofind -1 0"
2539 bind . <Shift-Key-Down> "dofind 1 0"
2540 bindkey <Key-Right> "goforw"
2541 bindkey <Key-Left> "goback"
2542 bind . <Key-Prior> "selnextpage -1"
2543 bind . <Key-Next> "selnextpage 1"
2544 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2545 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2546 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2547 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2548 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2549 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
2550 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2551 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2552 bindkey <Key-space> "$ctext yview scroll 1 pages"
2553 bindkey p "selnextline -1"
2554 bindkey n "selnextline 1"
2555 bindkey z "goback"
2556 bindkey x "goforw"
2557 bindkey k "selnextline -1"
2558 bindkey j "selnextline 1"
2559 bindkey h "goback"
2560 bindkey l "goforw"
2561 bindkey b prevfile
2562 bindkey d "$ctext yview scroll 18 units"
2563 bindkey u "$ctext yview scroll -18 units"
2564 bindkey / {focus $fstring}
2565 bindkey <Key-KP_Divide> {focus $fstring}
2566 bindkey <Key-Return> {dofind 1 1}
2567 bindkey ? {dofind -1 1}
2568 bindkey f nextfile
2569 bind . <F5> updatecommits
2570 bindmodfunctionkey Shift 5 reloadcommits
2571 bind . <F2> showrefs
2572 bindmodfunctionkey Shift 4 {newview 0}
2573 bind . <F4> edit_or_newview
2574 bind . <$M1B-q> doquit
2575 bind . <$M1B-f> {dofind 1 1}
2576 bind . <$M1B-g> {dofind 1 0}
2577 bind . <$M1B-r> dosearchback
2578 bind . <$M1B-s> dosearch
2579 bind . <$M1B-equal> {incrfont 1}
2580 bind . <$M1B-plus> {incrfont 1}
2581 bind . <$M1B-KP_Add> {incrfont 1}
2582 bind . <$M1B-minus> {incrfont -1}
2583 bind . <$M1B-KP_Subtract> {incrfont -1}
2584 wm protocol . WM_DELETE_WINDOW doquit
2585 bind . <Destroy> {stop_backends}
2586 bind . <Button-1> "click %W"
2587 bind $fstring <Key-Return> {dofind 1 1}
2588 bind $sha1entry <Key-Return> {gotocommit; break}
2589 bind $sha1entry <<PasteSelection>> clearsha1
2590 bind $sha1entry <<Paste>> clearsha1
2591 bind $cflist <1> {sel_flist %W %x %y; break}
2592 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
2593 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
2594 global ctxbut
2595 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2596 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2597 bind $ctext <Button-1> {focus %W}
2598 bind $ctext <<Selection>> rehighlight_search_results
2599 for {set i 1} {$i < 10} {incr i} {
2600 bind . <$M1B-Key-$i> [list go_to_parent $i]
2603 set maincursor [. cget -cursor]
2604 set textcursor [$ctext cget -cursor]
2605 set curtextcursor $textcursor
2607 set rowctxmenu .rowctxmenu
2608 makemenu $rowctxmenu {
2609 {mc "Diff this -> selected" command {diffvssel 0}}
2610 {mc "Diff selected -> this" command {diffvssel 1}}
2611 {mc "Make patch" command mkpatch}
2612 {mc "Create tag" command mktag}
2613 {mc "Write commit to file" command writecommit}
2614 {mc "Create new branch" command mkbranch}
2615 {mc "Cherry-pick this commit" command cherrypick}
2616 {mc "Reset HEAD branch to here" command resethead}
2617 {mc "Mark this commit" command markhere}
2618 {mc "Return to mark" command gotomark}
2619 {mc "Find descendant of this and mark" command find_common_desc}
2620 {mc "Compare with marked commit" command compare_commits}
2621 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2622 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2623 {mc "Revert this commit" command revert}
2625 $rowctxmenu configure -tearoff 0
2627 set fakerowmenu .fakerowmenu
2628 makemenu $fakerowmenu {
2629 {mc "Diff this -> selected" command {diffvssel 0}}
2630 {mc "Diff selected -> this" command {diffvssel 1}}
2631 {mc "Make patch" command mkpatch}
2632 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2633 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2635 $fakerowmenu configure -tearoff 0
2637 set headctxmenu .headctxmenu
2638 makemenu $headctxmenu {
2639 {mc "Check out this branch" command cobranch}
2640 {mc "Remove this branch" command rmbranch}
2642 $headctxmenu configure -tearoff 0
2644 global flist_menu
2645 set flist_menu .flistctxmenu
2646 makemenu $flist_menu {
2647 {mc "Highlight this too" command {flist_hl 0}}
2648 {mc "Highlight this only" command {flist_hl 1}}
2649 {mc "External diff" command {external_diff}}
2650 {mc "Blame parent commit" command {external_blame 1}}
2652 $flist_menu configure -tearoff 0
2654 global diff_menu
2655 set diff_menu .diffctxmenu
2656 makemenu $diff_menu {
2657 {mc "Show origin of this line" command show_line_source}
2658 {mc "Run git gui blame on this line" command {external_blame_diff}}
2660 $diff_menu configure -tearoff 0
2663 # Windows sends all mouse wheel events to the current focused window, not
2664 # the one where the mouse hovers, so bind those events here and redirect
2665 # to the correct window
2666 proc windows_mousewheel_redirector {W X Y D} {
2667 global canv canv2 canv3
2668 set w [winfo containing -displayof $W $X $Y]
2669 if {$w ne ""} {
2670 set u [expr {$D < 0 ? 5 : -5}]
2671 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2672 allcanvs yview scroll $u units
2673 } else {
2674 catch {
2675 $w yview scroll $u units
2681 # Update row number label when selectedline changes
2682 proc selectedline_change {n1 n2 op} {
2683 global selectedline rownumsel
2685 if {$selectedline eq {}} {
2686 set rownumsel {}
2687 } else {
2688 set rownumsel [expr {$selectedline + 1}]
2692 # mouse-2 makes all windows scan vertically, but only the one
2693 # the cursor is in scans horizontally
2694 proc canvscan {op w x y} {
2695 global canv canv2 canv3
2696 foreach c [list $canv $canv2 $canv3] {
2697 if {$c == $w} {
2698 $c scan $op $x $y
2699 } else {
2700 $c scan $op 0 $y
2705 proc scrollcanv {cscroll f0 f1} {
2706 $cscroll set $f0 $f1
2707 drawvisible
2708 flushhighlights
2711 # when we make a key binding for the toplevel, make sure
2712 # it doesn't get triggered when that key is pressed in the
2713 # find string entry widget.
2714 proc bindkey {ev script} {
2715 global entries
2716 bind . $ev $script
2717 set escript [bind Entry $ev]
2718 if {$escript == {}} {
2719 set escript [bind Entry <Key>]
2721 foreach e $entries {
2722 bind $e $ev "$escript; break"
2726 proc bindmodfunctionkey {mod n script} {
2727 bind . <$mod-F$n> $script
2728 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2731 # set the focus back to the toplevel for any click outside
2732 # the entry widgets
2733 proc click {w} {
2734 global ctext entries
2735 foreach e [concat $entries $ctext] {
2736 if {$w == $e} return
2738 focus .
2741 # Adjust the progress bar for a change in requested extent or canvas size
2742 proc adjustprogress {} {
2743 global progresscanv progressitem progresscoords
2744 global fprogitem fprogcoord lastprogupdate progupdatepending
2745 global rprogitem rprogcoord use_ttk
2747 if {$use_ttk} {
2748 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2749 return
2752 set w [expr {[winfo width $progresscanv] - 4}]
2753 set x0 [expr {$w * [lindex $progresscoords 0]}]
2754 set x1 [expr {$w * [lindex $progresscoords 1]}]
2755 set h [winfo height $progresscanv]
2756 $progresscanv coords $progressitem $x0 0 $x1 $h
2757 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
2758 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
2759 set now [clock clicks -milliseconds]
2760 if {$now >= $lastprogupdate + 100} {
2761 set progupdatepending 0
2762 update
2763 } elseif {!$progupdatepending} {
2764 set progupdatepending 1
2765 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
2769 proc doprogupdate {} {
2770 global lastprogupdate progupdatepending
2772 if {$progupdatepending} {
2773 set progupdatepending 0
2774 set lastprogupdate [clock clicks -milliseconds]
2775 update
2779 proc savestuff {w} {
2780 global viewname viewfiles viewargs viewargscmd viewperm nextviewnum
2781 global use_ttk
2782 global stuffsaved
2783 global config_file config_file_tmp
2784 global config_variables
2786 if {$stuffsaved} return
2787 if {![winfo viewable .]} return
2788 catch {
2789 if {[file exists $config_file_tmp]} {
2790 file delete -force $config_file_tmp
2792 set f [open $config_file_tmp w]
2793 if {$::tcl_platform(platform) eq {windows}} {
2794 file attributes $config_file_tmp -hidden true
2796 foreach var_name $config_variables {
2797 upvar #0 $var_name var
2798 puts $f [list set $var_name $var]
2801 puts $f "set geometry(main) [wm geometry .]"
2802 puts $f "set geometry(state) [wm state .]"
2803 puts $f "set geometry(topwidth) [winfo width .tf]"
2804 puts $f "set geometry(topheight) [winfo height .tf]"
2805 if {$use_ttk} {
2806 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2807 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2808 } else {
2809 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2810 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2812 puts $f "set geometry(botwidth) [winfo width .bleft]"
2813 puts $f "set geometry(botheight) [winfo height .bleft]"
2815 puts -nonewline $f "set permviews {"
2816 for {set v 0} {$v < $nextviewnum} {incr v} {
2817 if {$viewperm($v)} {
2818 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}"
2821 puts $f "}"
2822 close $f
2823 file rename -force $config_file_tmp $config_file
2825 set stuffsaved 1
2828 proc resizeclistpanes {win w} {
2829 global oldwidth use_ttk
2830 if {[info exists oldwidth($win)]} {
2831 if {$use_ttk} {
2832 set s0 [$win sashpos 0]
2833 set s1 [$win sashpos 1]
2834 } else {
2835 set s0 [$win sash coord 0]
2836 set s1 [$win sash coord 1]
2838 if {$w < 60} {
2839 set sash0 [expr {int($w/2 - 2)}]
2840 set sash1 [expr {int($w*5/6 - 2)}]
2841 } else {
2842 set factor [expr {1.0 * $w / $oldwidth($win)}]
2843 set sash0 [expr {int($factor * [lindex $s0 0])}]
2844 set sash1 [expr {int($factor * [lindex $s1 0])}]
2845 if {$sash0 < 30} {
2846 set sash0 30
2848 if {$sash1 < $sash0 + 20} {
2849 set sash1 [expr {$sash0 + 20}]
2851 if {$sash1 > $w - 10} {
2852 set sash1 [expr {$w - 10}]
2853 if {$sash0 > $sash1 - 20} {
2854 set sash0 [expr {$sash1 - 20}]
2858 if {$use_ttk} {
2859 $win sashpos 0 $sash0
2860 $win sashpos 1 $sash1
2861 } else {
2862 $win sash place 0 $sash0 [lindex $s0 1]
2863 $win sash place 1 $sash1 [lindex $s1 1]
2866 set oldwidth($win) $w
2869 proc resizecdetpanes {win w} {
2870 global oldwidth use_ttk
2871 if {[info exists oldwidth($win)]} {
2872 if {$use_ttk} {
2873 set s0 [$win sashpos 0]
2874 } else {
2875 set s0 [$win sash coord 0]
2877 if {$w < 60} {
2878 set sash0 [expr {int($w*3/4 - 2)}]
2879 } else {
2880 set factor [expr {1.0 * $w / $oldwidth($win)}]
2881 set sash0 [expr {int($factor * [lindex $s0 0])}]
2882 if {$sash0 < 45} {
2883 set sash0 45
2885 if {$sash0 > $w - 15} {
2886 set sash0 [expr {$w - 15}]
2889 if {$use_ttk} {
2890 $win sashpos 0 $sash0
2891 } else {
2892 $win sash place 0 $sash0 [lindex $s0 1]
2895 set oldwidth($win) $w
2898 proc allcanvs args {
2899 global canv canv2 canv3
2900 eval $canv $args
2901 eval $canv2 $args
2902 eval $canv3 $args
2905 proc bindall {event action} {
2906 global canv canv2 canv3
2907 bind $canv $event $action
2908 bind $canv2 $event $action
2909 bind $canv3 $event $action
2912 proc about {} {
2913 global uifont NS
2914 set w .about
2915 if {[winfo exists $w]} {
2916 raise $w
2917 return
2919 ttk_toplevel $w
2920 wm title $w [mc "About gitk"]
2921 make_transient $w .
2922 message $w.m -text [mc "
2923 Gitk - a commit viewer for git
2925 Copyright \u00a9 2005-2014 Paul Mackerras
2927 Use and redistribute under the terms of the GNU General Public License"] \
2928 -justify center -aspect 400 -border 2 -bg white -relief groove
2929 pack $w.m -side top -fill x -padx 2 -pady 2
2930 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2931 pack $w.ok -side bottom
2932 bind $w <Visibility> "focus $w.ok"
2933 bind $w <Key-Escape> "destroy $w"
2934 bind $w <Key-Return> "destroy $w"
2935 tk::PlaceWindow $w widget .
2938 proc keys {} {
2939 global NS
2940 set w .keys
2941 if {[winfo exists $w]} {
2942 raise $w
2943 return
2945 if {[tk windowingsystem] eq {aqua}} {
2946 set M1T Cmd
2947 } else {
2948 set M1T Ctrl
2950 ttk_toplevel $w
2951 wm title $w [mc "Gitk key bindings"]
2952 make_transient $w .
2953 message $w.m -text "
2954 [mc "Gitk key bindings:"]
2956 [mc "<%s-Q> Quit" $M1T]
2957 [mc "<%s-W> Close window" $M1T]
2958 [mc "<Home> Move to first commit"]
2959 [mc "<End> Move to last commit"]
2960 [mc "<Up>, p, k Move up one commit"]
2961 [mc "<Down>, n, j Move down one commit"]
2962 [mc "<Left>, z, h Go back in history list"]
2963 [mc "<Right>, x, l Go forward in history list"]
2964 [mc "<%s-n> Go to n-th parent of current commit in history list" $M1T]
2965 [mc "<PageUp> Move up one page in commit list"]
2966 [mc "<PageDown> Move down one page in commit list"]
2967 [mc "<%s-Home> Scroll to top of commit list" $M1T]
2968 [mc "<%s-End> Scroll to bottom of commit list" $M1T]
2969 [mc "<%s-Up> Scroll commit list up one line" $M1T]
2970 [mc "<%s-Down> Scroll commit list down one line" $M1T]
2971 [mc "<%s-PageUp> Scroll commit list up one page" $M1T]
2972 [mc "<%s-PageDown> Scroll commit list down one page" $M1T]
2973 [mc "<Shift-Up> Find backwards (upwards, later commits)"]
2974 [mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
2975 [mc "<Delete>, b Scroll diff view up one page"]
2976 [mc "<Backspace> Scroll diff view up one page"]
2977 [mc "<Space> Scroll diff view down one page"]
2978 [mc "u Scroll diff view up 18 lines"]
2979 [mc "d Scroll diff view down 18 lines"]
2980 [mc "<%s-F> Find" $M1T]
2981 [mc "<%s-G> Move to next find hit" $M1T]
2982 [mc "<Return> Move to next find hit"]
2983 [mc "/ Focus the search box"]
2984 [mc "? Move to previous find hit"]
2985 [mc "f Scroll diff view to next file"]
2986 [mc "<%s-S> Search for next hit in diff view" $M1T]
2987 [mc "<%s-R> Search for previous hit in diff view" $M1T]
2988 [mc "<%s-KP+> Increase font size" $M1T]
2989 [mc "<%s-plus> Increase font size" $M1T]
2990 [mc "<%s-KP-> Decrease font size" $M1T]
2991 [mc "<%s-minus> Decrease font size" $M1T]
2992 [mc "<F5> Update"]
2994 -justify left -bg white -border 2 -relief groove
2995 pack $w.m -side top -fill both -padx 2 -pady 2
2996 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
2997 bind $w <Key-Escape> [list destroy $w]
2998 pack $w.ok -side bottom
2999 bind $w <Visibility> "focus $w.ok"
3000 bind $w <Key-Escape> "destroy $w"
3001 bind $w <Key-Return> "destroy $w"
3004 # Procedures for manipulating the file list window at the
3005 # bottom right of the overall window.
3007 proc treeview {w l openlevs} {
3008 global treecontents treediropen treeheight treeparent treeindex
3010 set ix 0
3011 set treeindex() 0
3012 set lev 0
3013 set prefix {}
3014 set prefixend -1
3015 set prefendstack {}
3016 set htstack {}
3017 set ht 0
3018 set treecontents() {}
3019 $w conf -state normal
3020 foreach f $l {
3021 while {[string range $f 0 $prefixend] ne $prefix} {
3022 if {$lev <= $openlevs} {
3023 $w mark set e:$treeindex($prefix) "end -1c"
3024 $w mark gravity e:$treeindex($prefix) left
3026 set treeheight($prefix) $ht
3027 incr ht [lindex $htstack end]
3028 set htstack [lreplace $htstack end end]
3029 set prefixend [lindex $prefendstack end]
3030 set prefendstack [lreplace $prefendstack end end]
3031 set prefix [string range $prefix 0 $prefixend]
3032 incr lev -1
3034 set tail [string range $f [expr {$prefixend+1}] end]
3035 while {[set slash [string first "/" $tail]] >= 0} {
3036 lappend htstack $ht
3037 set ht 0
3038 lappend prefendstack $prefixend
3039 incr prefixend [expr {$slash + 1}]
3040 set d [string range $tail 0 $slash]
3041 lappend treecontents($prefix) $d
3042 set oldprefix $prefix
3043 append prefix $d
3044 set treecontents($prefix) {}
3045 set treeindex($prefix) [incr ix]
3046 set treeparent($prefix) $oldprefix
3047 set tail [string range $tail [expr {$slash+1}] end]
3048 if {$lev <= $openlevs} {
3049 set ht 1
3050 set treediropen($prefix) [expr {$lev < $openlevs}]
3051 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3052 $w mark set d:$ix "end -1c"
3053 $w mark gravity d:$ix left
3054 set str "\n"
3055 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3056 $w insert end $str
3057 $w image create end -align center -image $bm -padx 1 \
3058 -name a:$ix
3059 $w insert end $d [highlight_tag $prefix]
3060 $w mark set s:$ix "end -1c"
3061 $w mark gravity s:$ix left
3063 incr lev
3065 if {$tail ne {}} {
3066 if {$lev <= $openlevs} {
3067 incr ht
3068 set str "\n"
3069 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3070 $w insert end $str
3071 $w insert end $tail [highlight_tag $f]
3073 lappend treecontents($prefix) $tail
3076 while {$htstack ne {}} {
3077 set treeheight($prefix) $ht
3078 incr ht [lindex $htstack end]
3079 set htstack [lreplace $htstack end end]
3080 set prefixend [lindex $prefendstack end]
3081 set prefendstack [lreplace $prefendstack end end]
3082 set prefix [string range $prefix 0 $prefixend]
3084 $w conf -state disabled
3087 proc linetoelt {l} {
3088 global treeheight treecontents
3090 set y 2
3091 set prefix {}
3092 while {1} {
3093 foreach e $treecontents($prefix) {
3094 if {$y == $l} {
3095 return "$prefix$e"
3097 set n 1
3098 if {[string index $e end] eq "/"} {
3099 set n $treeheight($prefix$e)
3100 if {$y + $n > $l} {
3101 append prefix $e
3102 incr y
3103 break
3106 incr y $n
3111 proc highlight_tree {y prefix} {
3112 global treeheight treecontents cflist
3114 foreach e $treecontents($prefix) {
3115 set path $prefix$e
3116 if {[highlight_tag $path] ne {}} {
3117 $cflist tag add bold $y.0 "$y.0 lineend"
3119 incr y
3120 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3121 set y [highlight_tree $y $path]
3124 return $y
3127 proc treeclosedir {w dir} {
3128 global treediropen treeheight treeparent treeindex
3130 set ix $treeindex($dir)
3131 $w conf -state normal
3132 $w delete s:$ix e:$ix
3133 set treediropen($dir) 0
3134 $w image configure a:$ix -image tri-rt
3135 $w conf -state disabled
3136 set n [expr {1 - $treeheight($dir)}]
3137 while {$dir ne {}} {
3138 incr treeheight($dir) $n
3139 set dir $treeparent($dir)
3143 proc treeopendir {w dir} {
3144 global treediropen treeheight treeparent treecontents treeindex
3146 set ix $treeindex($dir)
3147 $w conf -state normal
3148 $w image configure a:$ix -image tri-dn
3149 $w mark set e:$ix s:$ix
3150 $w mark gravity e:$ix right
3151 set lev 0
3152 set str "\n"
3153 set n [llength $treecontents($dir)]
3154 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
3155 incr lev
3156 append str "\t"
3157 incr treeheight($x) $n
3159 foreach e $treecontents($dir) {
3160 set de $dir$e
3161 if {[string index $e end] eq "/"} {
3162 set iy $treeindex($de)
3163 $w mark set d:$iy e:$ix
3164 $w mark gravity d:$iy left
3165 $w insert e:$ix $str
3166 set treediropen($de) 0
3167 $w image create e:$ix -align center -image tri-rt -padx 1 \
3168 -name a:$iy
3169 $w insert e:$ix $e [highlight_tag $de]
3170 $w mark set s:$iy e:$ix
3171 $w mark gravity s:$iy left
3172 set treeheight($de) 1
3173 } else {
3174 $w insert e:$ix $str
3175 $w insert e:$ix $e [highlight_tag $de]
3178 $w mark gravity e:$ix right
3179 $w conf -state disabled
3180 set treediropen($dir) 1
3181 set top [lindex [split [$w index @0,0] .] 0]
3182 set ht [$w cget -height]
3183 set l [lindex [split [$w index s:$ix] .] 0]
3184 if {$l < $top} {
3185 $w yview $l.0
3186 } elseif {$l + $n + 1 > $top + $ht} {
3187 set top [expr {$l + $n + 2 - $ht}]
3188 if {$l < $top} {
3189 set top $l
3191 $w yview $top.0
3195 proc treeclick {w x y} {
3196 global treediropen cmitmode ctext cflist cflist_top
3198 if {$cmitmode ne "tree"} return
3199 if {![info exists cflist_top]} return
3200 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3201 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3202 $cflist tag add highlight $l.0 "$l.0 lineend"
3203 set cflist_top $l
3204 if {$l == 1} {
3205 $ctext yview 1.0
3206 return
3208 set e [linetoelt $l]
3209 if {[string index $e end] ne "/"} {
3210 showfile $e
3211 } elseif {$treediropen($e)} {
3212 treeclosedir $w $e
3213 } else {
3214 treeopendir $w $e
3218 proc setfilelist {id} {
3219 global treefilelist cflist jump_to_here
3221 treeview $cflist $treefilelist($id) 0
3222 if {$jump_to_here ne {}} {
3223 set f [lindex $jump_to_here 0]
3224 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3225 showfile $f
3230 image create bitmap tri-rt -background black -foreground blue -data {
3231 #define tri-rt_width 13
3232 #define tri-rt_height 13
3233 static unsigned char tri-rt_bits[] = {
3234 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3235 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3236 0x00, 0x00};
3237 } -maskdata {
3238 #define tri-rt-mask_width 13
3239 #define tri-rt-mask_height 13
3240 static unsigned char tri-rt-mask_bits[] = {
3241 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3242 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3243 0x08, 0x00};
3245 image create bitmap tri-dn -background black -foreground blue -data {
3246 #define tri-dn_width 13
3247 #define tri-dn_height 13
3248 static unsigned char tri-dn_bits[] = {
3249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3250 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3251 0x00, 0x00};
3252 } -maskdata {
3253 #define tri-dn-mask_width 13
3254 #define tri-dn-mask_height 13
3255 static unsigned char tri-dn-mask_bits[] = {
3256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3257 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3258 0x00, 0x00};
3261 image create bitmap reficon-T -background black -foreground yellow -data {
3262 #define tagicon_width 13
3263 #define tagicon_height 9
3264 static unsigned char tagicon_bits[] = {
3265 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3266 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3267 } -maskdata {
3268 #define tagicon-mask_width 13
3269 #define tagicon-mask_height 9
3270 static unsigned char tagicon-mask_bits[] = {
3271 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3272 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3274 set rectdata {
3275 #define headicon_width 13
3276 #define headicon_height 9
3277 static unsigned char headicon_bits[] = {
3278 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3279 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3281 set rectmask {
3282 #define headicon-mask_width 13
3283 #define headicon-mask_height 9
3284 static unsigned char headicon-mask_bits[] = {
3285 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3286 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3288 image create bitmap reficon-H -background black -foreground green \
3289 -data $rectdata -maskdata $rectmask
3290 image create bitmap reficon-o -background black -foreground "#ddddff" \
3291 -data $rectdata -maskdata $rectmask
3293 proc init_flist {first} {
3294 global cflist cflist_top difffilestart
3296 $cflist conf -state normal
3297 $cflist delete 0.0 end
3298 if {$first ne {}} {
3299 $cflist insert end $first
3300 set cflist_top 1
3301 $cflist tag add highlight 1.0 "1.0 lineend"
3302 } else {
3303 catch {unset cflist_top}
3305 $cflist conf -state disabled
3306 set difffilestart {}
3309 proc highlight_tag {f} {
3310 global highlight_paths
3312 foreach p $highlight_paths {
3313 if {[string match $p $f]} {
3314 return "bold"
3317 return {}
3320 proc highlight_filelist {} {
3321 global cmitmode cflist
3323 $cflist conf -state normal
3324 if {$cmitmode ne "tree"} {
3325 set end [lindex [split [$cflist index end] .] 0]
3326 for {set l 2} {$l < $end} {incr l} {
3327 set line [$cflist get $l.0 "$l.0 lineend"]
3328 if {[highlight_tag $line] ne {}} {
3329 $cflist tag add bold $l.0 "$l.0 lineend"
3332 } else {
3333 highlight_tree 2 {}
3335 $cflist conf -state disabled
3338 proc unhighlight_filelist {} {
3339 global cflist
3341 $cflist conf -state normal
3342 $cflist tag remove bold 1.0 end
3343 $cflist conf -state disabled
3346 proc add_flist {fl} {
3347 global cflist
3349 $cflist conf -state normal
3350 foreach f $fl {
3351 $cflist insert end "\n"
3352 $cflist insert end $f [highlight_tag $f]
3354 $cflist conf -state disabled
3357 proc sel_flist {w x y} {
3358 global ctext difffilestart cflist cflist_top cmitmode
3360 if {$cmitmode eq "tree"} return
3361 if {![info exists cflist_top]} return
3362 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3363 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3364 $cflist tag add highlight $l.0 "$l.0 lineend"
3365 set cflist_top $l
3366 if {$l == 1} {
3367 $ctext yview 1.0
3368 } else {
3369 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
3371 suppress_highlighting_file_for_current_scrollpos
3374 proc pop_flist_menu {w X Y x y} {
3375 global ctext cflist cmitmode flist_menu flist_menu_file
3376 global treediffs diffids
3378 stopfinding
3379 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3380 if {$l <= 1} return
3381 if {$cmitmode eq "tree"} {
3382 set e [linetoelt $l]
3383 if {[string index $e end] eq "/"} return
3384 } else {
3385 set e [lindex $treediffs($diffids) [expr {$l-2}]]
3387 set flist_menu_file $e
3388 set xdiffstate "normal"
3389 if {$cmitmode eq "tree"} {
3390 set xdiffstate "disabled"
3392 # Disable "External diff" item in tree mode
3393 $flist_menu entryconf 2 -state $xdiffstate
3394 tk_popup $flist_menu $X $Y
3397 proc find_ctext_fileinfo {line} {
3398 global ctext_file_names ctext_file_lines
3400 set ok [bsearch $ctext_file_lines $line]
3401 set tline [lindex $ctext_file_lines $ok]
3403 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3404 return {}
3405 } else {
3406 return [list [lindex $ctext_file_names $ok] $tline]
3410 proc pop_diff_menu {w X Y x y} {
3411 global ctext diff_menu flist_menu_file
3412 global diff_menu_txtpos diff_menu_line
3413 global diff_menu_filebase
3415 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3416 set diff_menu_line [lindex $diff_menu_txtpos 0]
3417 # don't pop up the menu on hunk-separator or file-separator lines
3418 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
3419 return
3421 stopfinding
3422 set f [find_ctext_fileinfo $diff_menu_line]
3423 if {$f eq {}} return
3424 set flist_menu_file [lindex $f 0]
3425 set diff_menu_filebase [lindex $f 1]
3426 tk_popup $diff_menu $X $Y
3429 proc flist_hl {only} {
3430 global flist_menu_file findstring gdttype
3432 set x [shellquote $flist_menu_file]
3433 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
3434 set findstring $x
3435 } else {
3436 append findstring " " $x
3438 set gdttype [mc "touching paths:"]
3441 proc gitknewtmpdir {} {
3442 global diffnum gitktmpdir gitdir env
3444 if {![info exists gitktmpdir]} {
3445 if {[info exists env(GITK_TMPDIR)]} {
3446 set tmpdir $env(GITK_TMPDIR)
3447 } elseif {[info exists env(TMPDIR)]} {
3448 set tmpdir $env(TMPDIR)
3449 } else {
3450 set tmpdir $gitdir
3452 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
3453 if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} {
3454 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3456 if {[catch {file mkdir $gitktmpdir} err]} {
3457 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3458 unset gitktmpdir
3459 return {}
3461 set diffnum 0
3463 incr diffnum
3464 set diffdir [file join $gitktmpdir $diffnum]
3465 if {[catch {file mkdir $diffdir} err]} {
3466 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3467 return {}
3469 return $diffdir
3472 proc save_file_from_commit {filename output what} {
3473 global nullfile
3475 if {[catch {exec git show $filename -- > $output} err]} {
3476 if {[string match "fatal: bad revision *" $err]} {
3477 return $nullfile
3479 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3480 return {}
3482 return $output
3485 proc external_diff_get_one_file {diffid filename diffdir} {
3486 global nullid nullid2 nullfile
3487 global worktree
3489 if {$diffid == $nullid} {
3490 set difffile [file join $worktree $filename]
3491 if {[file exists $difffile]} {
3492 return $difffile
3494 return $nullfile
3496 if {$diffid == $nullid2} {
3497 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3498 return [save_file_from_commit :$filename $difffile index]
3500 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3501 return [save_file_from_commit $diffid:$filename $difffile \
3502 "revision $diffid"]
3505 proc external_diff {} {
3506 global nullid nullid2
3507 global flist_menu_file
3508 global diffids
3509 global extdifftool
3511 if {[llength $diffids] == 1} {
3512 # no reference commit given
3513 set diffidto [lindex $diffids 0]
3514 if {$diffidto eq $nullid} {
3515 # diffing working copy with index
3516 set diffidfrom $nullid2
3517 } elseif {$diffidto eq $nullid2} {
3518 # diffing index with HEAD
3519 set diffidfrom "HEAD"
3520 } else {
3521 # use first parent commit
3522 global parentlist selectedline
3523 set diffidfrom [lindex $parentlist $selectedline 0]
3525 } else {
3526 set diffidfrom [lindex $diffids 0]
3527 set diffidto [lindex $diffids 1]
3530 # make sure that several diffs wont collide
3531 set diffdir [gitknewtmpdir]
3532 if {$diffdir eq {}} return
3534 # gather files to diff
3535 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3536 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3538 if {$difffromfile ne {} && $difftofile ne {}} {
3539 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3540 if {[catch {set fl [open |$cmd r]} err]} {
3541 file delete -force $diffdir
3542 error_popup "$extdifftool: [mc "command failed:"] $err"
3543 } else {
3544 fconfigure $fl -blocking 0
3545 filerun $fl [list delete_at_eof $fl $diffdir]
3550 proc find_hunk_blamespec {base line} {
3551 global ctext
3553 # Find and parse the hunk header
3554 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3555 if {$s_lix eq {}} return
3557 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3558 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
3559 s_line old_specs osz osz1 new_line nsz]} {
3560 return
3563 # base lines for the parents
3564 set base_lines [list $new_line]
3565 foreach old_spec [lrange [split $old_specs " "] 1 end] {
3566 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3567 old_spec old_line osz]} {
3568 return
3570 lappend base_lines $old_line
3573 # Now scan the lines to determine offset within the hunk
3574 set max_parent [expr {[llength $base_lines]-2}]
3575 set dline 0
3576 set s_lno [lindex [split $s_lix "."] 0]
3578 # Determine if the line is removed
3579 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3580 if {[string match {[-+ ]*} $chunk]} {
3581 set removed_idx [string first "-" $chunk]
3582 # Choose a parent index
3583 if {$removed_idx >= 0} {
3584 set parent $removed_idx
3585 } else {
3586 set unchanged_idx [string first " " $chunk]
3587 if {$unchanged_idx >= 0} {
3588 set parent $unchanged_idx
3589 } else {
3590 # blame the current commit
3591 set parent -1
3594 # then count other lines that belong to it
3595 for {set i $line} {[incr i -1] > $s_lno} {} {
3596 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3597 # Determine if the line is removed
3598 set removed_idx [string first "-" $chunk]
3599 if {$parent >= 0} {
3600 set code [string index $chunk $parent]
3601 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3602 incr dline
3604 } else {
3605 if {$removed_idx < 0} {
3606 incr dline
3610 incr parent
3611 } else {
3612 set parent 0
3615 incr dline [lindex $base_lines $parent]
3616 return [list $parent $dline]
3619 proc external_blame_diff {} {
3620 global currentid cmitmode
3621 global diff_menu_txtpos diff_menu_line
3622 global diff_menu_filebase flist_menu_file
3624 if {$cmitmode eq "tree"} {
3625 set parent_idx 0
3626 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3627 } else {
3628 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3629 if {$hinfo ne {}} {
3630 set parent_idx [lindex $hinfo 0]
3631 set line [lindex $hinfo 1]
3632 } else {
3633 set parent_idx 0
3634 set line 0
3638 external_blame $parent_idx $line
3641 # Find the SHA1 ID of the blob for file $fname in the index
3642 # at stage 0 or 2
3643 proc index_sha1 {fname} {
3644 set f [open [list | git ls-files -s $fname] r]
3645 while {[gets $f line] >= 0} {
3646 set info [lindex [split $line "\t"] 0]
3647 set stage [lindex $info 2]
3648 if {$stage eq "0" || $stage eq "2"} {
3649 close $f
3650 return [lindex $info 1]
3653 close $f
3654 return {}
3657 # Turn an absolute path into one relative to the current directory
3658 proc make_relative {f} {
3659 if {[file pathtype $f] eq "relative"} {
3660 return $f
3662 set elts [file split $f]
3663 set here [file split [pwd]]
3664 set ei 0
3665 set hi 0
3666 set res {}
3667 foreach d $here {
3668 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3669 lappend res ".."
3670 } else {
3671 incr ei
3673 incr hi
3675 set elts [concat $res [lrange $elts $ei end]]
3676 return [eval file join $elts]
3679 proc external_blame {parent_idx {line {}}} {
3680 global flist_menu_file cdup
3681 global nullid nullid2
3682 global parentlist selectedline currentid
3684 if {$parent_idx > 0} {
3685 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
3686 } else {
3687 set base_commit $currentid
3690 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
3691 error_popup [mc "No such commit"]
3692 return
3695 set cmdline [list git gui blame]
3696 if {$line ne {} && $line > 1} {
3697 lappend cmdline "--line=$line"
3699 set f [file join $cdup $flist_menu_file]
3700 # Unfortunately it seems git gui blame doesn't like
3701 # being given an absolute path...
3702 set f [make_relative $f]
3703 lappend cmdline $base_commit $f
3704 if {[catch {eval exec $cmdline &} err]} {
3705 error_popup "[mc "git gui blame: command failed:"] $err"
3709 proc show_line_source {} {
3710 global cmitmode currentid parents curview blamestuff blameinst
3711 global diff_menu_line diff_menu_filebase flist_menu_file
3712 global nullid nullid2 gitdir cdup
3714 set from_index {}
3715 if {$cmitmode eq "tree"} {
3716 set id $currentid
3717 set line [expr {$diff_menu_line - $diff_menu_filebase}]
3718 } else {
3719 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3720 if {$h eq {}} return
3721 set pi [lindex $h 0]
3722 if {$pi == 0} {
3723 mark_ctext_line $diff_menu_line
3724 return
3726 incr pi -1
3727 if {$currentid eq $nullid} {
3728 if {$pi > 0} {
3729 # must be a merge in progress...
3730 if {[catch {
3731 # get the last line from .git/MERGE_HEAD
3732 set f [open [file join $gitdir MERGE_HEAD] r]
3733 set id [lindex [split [read $f] "\n"] end-1]
3734 close $f
3735 } err]} {
3736 error_popup [mc "Couldn't read merge head: %s" $err]
3737 return
3739 } elseif {$parents($curview,$currentid) eq $nullid2} {
3740 # need to do the blame from the index
3741 if {[catch {
3742 set from_index [index_sha1 $flist_menu_file]
3743 } err]} {
3744 error_popup [mc "Error reading index: %s" $err]
3745 return
3747 } else {
3748 set id $parents($curview,$currentid)
3750 } else {
3751 set id [lindex $parents($curview,$currentid) $pi]
3753 set line [lindex $h 1]
3755 set blameargs {}
3756 if {$from_index ne {}} {
3757 lappend blameargs | git cat-file blob $from_index
3759 lappend blameargs | git blame -p -L$line,+1
3760 if {$from_index ne {}} {
3761 lappend blameargs --contents -
3762 } else {
3763 lappend blameargs $id
3765 lappend blameargs -- [file join $cdup $flist_menu_file]
3766 if {[catch {
3767 set f [open $blameargs r]
3768 } err]} {
3769 error_popup [mc "Couldn't start git blame: %s" $err]
3770 return
3772 nowbusy blaming [mc "Searching"]
3773 fconfigure $f -blocking 0
3774 set i [reg_instance $f]
3775 set blamestuff($i) {}
3776 set blameinst $i
3777 filerun $f [list read_line_source $f $i]
3780 proc stopblaming {} {
3781 global blameinst
3783 if {[info exists blameinst]} {
3784 stop_instance $blameinst
3785 unset blameinst
3786 notbusy blaming
3790 proc read_line_source {fd inst} {
3791 global blamestuff curview commfd blameinst nullid nullid2
3793 while {[gets $fd line] >= 0} {
3794 lappend blamestuff($inst) $line
3796 if {![eof $fd]} {
3797 return 1
3799 unset commfd($inst)
3800 unset blameinst
3801 notbusy blaming
3802 fconfigure $fd -blocking 1
3803 if {[catch {close $fd} err]} {
3804 error_popup [mc "Error running git blame: %s" $err]
3805 return 0
3808 set fname {}
3809 set line [split [lindex $blamestuff($inst) 0] " "]
3810 set id [lindex $line 0]
3811 set lnum [lindex $line 1]
3812 if {[string length $id] == 40 && [string is xdigit $id] &&
3813 [string is digit -strict $lnum]} {
3814 # look for "filename" line
3815 foreach l $blamestuff($inst) {
3816 if {[string match "filename *" $l]} {
3817 set fname [string range $l 9 end]
3818 break
3822 if {$fname ne {}} {
3823 # all looks good, select it
3824 if {$id eq $nullid} {
3825 # blame uses all-zeroes to mean not committed,
3826 # which would mean a change in the index
3827 set id $nullid2
3829 if {[commitinview $id $curview]} {
3830 selectline [rowofcommit $id] 1 [list $fname $lnum] 1
3831 } else {
3832 error_popup [mc "That line comes from commit %s, \
3833 which is not in this view" [shortids $id]]
3835 } else {
3836 puts "oops couldn't parse git blame output"
3838 return 0
3841 # delete $dir when we see eof on $f (presumably because the child has exited)
3842 proc delete_at_eof {f dir} {
3843 while {[gets $f line] >= 0} {}
3844 if {[eof $f]} {
3845 if {[catch {close $f} err]} {
3846 error_popup "[mc "External diff viewer failed:"] $err"
3848 file delete -force $dir
3849 return 0
3851 return 1
3854 # Functions for adding and removing shell-type quoting
3856 proc shellquote {str} {
3857 if {![string match "*\['\"\\ \t]*" $str]} {
3858 return $str
3860 if {![string match "*\['\"\\]*" $str]} {
3861 return "\"$str\""
3863 if {![string match "*'*" $str]} {
3864 return "'$str'"
3866 return "\"[string map {\" \\\" \\ \\\\} $str]\""
3869 proc shellarglist {l} {
3870 set str {}
3871 foreach a $l {
3872 if {$str ne {}} {
3873 append str " "
3875 append str [shellquote $a]
3877 return $str
3880 proc shelldequote {str} {
3881 set ret {}
3882 set used -1
3883 while {1} {
3884 incr used
3885 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
3886 append ret [string range $str $used end]
3887 set used [string length $str]
3888 break
3890 set first [lindex $first 0]
3891 set ch [string index $str $first]
3892 if {$first > $used} {
3893 append ret [string range $str $used [expr {$first - 1}]]
3894 set used $first
3896 if {$ch eq " " || $ch eq "\t"} break
3897 incr used
3898 if {$ch eq "'"} {
3899 set first [string first "'" $str $used]
3900 if {$first < 0} {
3901 error "unmatched single-quote"
3903 append ret [string range $str $used [expr {$first - 1}]]
3904 set used $first
3905 continue
3907 if {$ch eq "\\"} {
3908 if {$used >= [string length $str]} {
3909 error "trailing backslash"
3911 append ret [string index $str $used]
3912 continue
3914 # here ch == "\""
3915 while {1} {
3916 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
3917 error "unmatched double-quote"
3919 set first [lindex $first 0]
3920 set ch [string index $str $first]
3921 if {$first > $used} {
3922 append ret [string range $str $used [expr {$first - 1}]]
3923 set used $first
3925 if {$ch eq "\""} break
3926 incr used
3927 append ret [string index $str $used]
3928 incr used
3931 return [list $used $ret]
3934 proc shellsplit {str} {
3935 set l {}
3936 while {1} {
3937 set str [string trimleft $str]
3938 if {$str eq {}} break
3939 set dq [shelldequote $str]
3940 set n [lindex $dq 0]
3941 set word [lindex $dq 1]
3942 set str [string range $str $n end]
3943 lappend l $word
3945 return $l
3948 # Code to implement multiple views
3950 proc newview {ishighlight} {
3951 global nextviewnum newviewname newishighlight
3952 global revtreeargs viewargscmd newviewopts curview
3954 set newishighlight $ishighlight
3955 set top .gitkview
3956 if {[winfo exists $top]} {
3957 raise $top
3958 return
3960 decode_view_opts $nextviewnum $revtreeargs
3961 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
3962 set newviewopts($nextviewnum,perm) 0
3963 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
3964 vieweditor $top $nextviewnum [mc "Gitk view definition"]
3967 set known_view_options {
3968 {perm b . {} {mc "Remember this view"}}
3969 {reflabel l + {} {mc "References (space separated list):"}}
3970 {refs t15 .. {} {mc "Branches & tags:"}}
3971 {allrefs b *. "--all" {mc "All refs"}}
3972 {branches b . "--branches" {mc "All (local) branches"}}
3973 {tags b . "--tags" {mc "All tags"}}
3974 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
3975 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
3976 {author t15 .. "--author=*" {mc "Author:"}}
3977 {committer t15 . "--committer=*" {mc "Committer:"}}
3978 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
3979 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
3980 {changes_l l + {} {mc "Changes to Files:"}}
3981 {pickaxe_s r0 . {} {mc "Fixed String"}}
3982 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
3983 {pickaxe t15 .. "-S*" {mc "Search string:"}}
3984 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
3985 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
3986 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
3987 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
3988 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
3989 {skip t10 . "--skip=*" {mc "Number to skip:"}}
3990 {misc_lbl l + {} {mc "Miscellaneous options:"}}
3991 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
3992 {lright b . "--left-right" {mc "Mark branch sides"}}
3993 {first b . "--first-parent" {mc "Limit to first parent"}}
3994 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
3995 {args t50 *. {} {mc "Additional arguments to git log:"}}
3996 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
3997 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
4000 # Convert $newviewopts($n, ...) into args for git log.
4001 proc encode_view_opts {n} {
4002 global known_view_options newviewopts
4004 set rargs [list]
4005 foreach opt $known_view_options {
4006 set patterns [lindex $opt 3]
4007 if {$patterns eq {}} continue
4008 set pattern [lindex $patterns 0]
4010 if {[lindex $opt 1] eq "b"} {
4011 set val $newviewopts($n,[lindex $opt 0])
4012 if {$val} {
4013 lappend rargs $pattern
4015 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4016 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4017 set val $newviewopts($n,$button_id)
4018 if {$val eq $value} {
4019 lappend rargs $pattern
4021 } else {
4022 set val $newviewopts($n,[lindex $opt 0])
4023 set val [string trim $val]
4024 if {$val ne {}} {
4025 set pfix [string range $pattern 0 end-1]
4026 lappend rargs $pfix$val
4030 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
4031 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4034 # Fill $newviewopts($n, ...) based on args for git log.
4035 proc decode_view_opts {n view_args} {
4036 global known_view_options newviewopts
4038 foreach opt $known_view_options {
4039 set id [lindex $opt 0]
4040 if {[lindex $opt 1] eq "b"} {
4041 # Checkboxes
4042 set val 0
4043 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
4044 # Radiobuttons
4045 regexp {^(.*_)} $id uselessvar id
4046 set val 0
4047 } else {
4048 # Text fields
4049 set val {}
4051 set newviewopts($n,$id) $val
4053 set oargs [list]
4054 set refargs [list]
4055 foreach arg $view_args {
4056 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4057 && ![info exists found(limit)]} {
4058 set newviewopts($n,limit) $cnt
4059 set found(limit) 1
4060 continue
4062 catch { unset val }
4063 foreach opt $known_view_options {
4064 set id [lindex $opt 0]
4065 if {[info exists found($id)]} continue
4066 foreach pattern [lindex $opt 3] {
4067 if {![string match $pattern $arg]} continue
4068 if {[lindex $opt 1] eq "b"} {
4069 # Check buttons
4070 set val 1
4071 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4072 # Radio buttons
4073 regexp {^(.*_)} $id uselessvar id
4074 set val $num
4075 } else {
4076 # Text input fields
4077 set size [string length $pattern]
4078 set val [string range $arg [expr {$size-1}] end]
4080 set newviewopts($n,$id) $val
4081 set found($id) 1
4082 break
4084 if {[info exists val]} break
4086 if {[info exists val]} continue
4087 if {[regexp {^-} $arg]} {
4088 lappend oargs $arg
4089 } else {
4090 lappend refargs $arg
4093 set newviewopts($n,refs) [shellarglist $refargs]
4094 set newviewopts($n,args) [shellarglist $oargs]
4097 proc edit_or_newview {} {
4098 global curview
4100 if {$curview > 0} {
4101 editview
4102 } else {
4103 newview 0
4107 proc editview {} {
4108 global curview
4109 global viewname viewperm newviewname newviewopts
4110 global viewargs viewargscmd
4112 set top .gitkvedit-$curview
4113 if {[winfo exists $top]} {
4114 raise $top
4115 return
4117 decode_view_opts $curview $viewargs($curview)
4118 set newviewname($curview) $viewname($curview)
4119 set newviewopts($curview,perm) $viewperm($curview)
4120 set newviewopts($curview,cmd) $viewargscmd($curview)
4121 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
4124 proc vieweditor {top n title} {
4125 global newviewname newviewopts viewfiles bgcolor
4126 global known_view_options NS
4128 ttk_toplevel $top
4129 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
4130 make_transient $top .
4132 # View name
4133 ${NS}::frame $top.nfr
4134 ${NS}::label $top.nl -text [mc "View Name"]
4135 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
4136 pack $top.nfr -in $top -fill x -pady 5 -padx 3
4137 pack $top.nl -in $top.nfr -side left -padx {0 5}
4138 pack $top.name -in $top.nfr -side left -padx {0 25}
4140 # View options
4141 set cframe $top.nfr
4142 set cexpand 0
4143 set cnt 0
4144 foreach opt $known_view_options {
4145 set id [lindex $opt 0]
4146 set type [lindex $opt 1]
4147 set flags [lindex $opt 2]
4148 set title [eval [lindex $opt 4]]
4149 set lxpad 0
4151 if {$flags eq "+" || $flags eq "*"} {
4152 set cframe $top.fr$cnt
4153 incr cnt
4154 ${NS}::frame $cframe
4155 pack $cframe -in $top -fill x -pady 3 -padx 3
4156 set cexpand [expr {$flags eq "*"}]
4157 } elseif {$flags eq ".." || $flags eq "*."} {
4158 set cframe $top.fr$cnt
4159 incr cnt
4160 ${NS}::frame $cframe
4161 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4162 set cexpand [expr {$flags eq "*."}]
4163 } else {
4164 set lxpad 5
4167 if {$type eq "l"} {
4168 ${NS}::label $cframe.l_$id -text $title
4169 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
4170 } elseif {$type eq "b"} {
4171 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4172 pack $cframe.c_$id -in $cframe -side left \
4173 -padx [list $lxpad 0] -expand $cexpand -anchor w
4174 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4175 regexp {^(.*_)} $id uselessvar button_id
4176 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4177 pack $cframe.c_$id -in $cframe -side left \
4178 -padx [list $lxpad 0] -expand $cexpand -anchor w
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 left -padx [list $lxpad 0]
4184 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4185 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4186 ${NS}::label $cframe.l_$id -text $title
4187 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4188 -textvariable newviewopts($n,$id)
4189 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4190 pack $cframe.e_$id -in $cframe -side top -fill x
4191 } elseif {$type eq "path"} {
4192 ${NS}::label $top.l -text $title
4193 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4194 text $top.t -width 40 -height 5 -background $bgcolor
4195 if {[info exists viewfiles($n)]} {
4196 foreach f $viewfiles($n) {
4197 $top.t insert end $f
4198 $top.t insert end "\n"
4200 $top.t delete {end - 1c} end
4201 $top.t mark set insert 0.0
4203 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4207 ${NS}::frame $top.buts
4208 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4209 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4210 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
4211 bind $top <Control-Return> [list newviewok $top $n]
4212 bind $top <F5> [list newviewok $top $n 1]
4213 bind $top <Escape> [list destroy $top]
4214 grid $top.buts.ok $top.buts.apply $top.buts.can
4215 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4216 grid columnconfigure $top.buts 1 -weight 1 -uniform a
4217 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4218 pack $top.buts -in $top -side top -fill x
4219 focus $top.t
4222 proc doviewmenu {m first cmd op argv} {
4223 set nmenu [$m index end]
4224 for {set i $first} {$i <= $nmenu} {incr i} {
4225 if {[$m entrycget $i -command] eq $cmd} {
4226 eval $m $op $i $argv
4227 break
4232 proc allviewmenus {n op args} {
4233 # global viewhlmenu
4235 doviewmenu .bar.view 5 [list showview $n] $op $args
4236 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
4239 proc newviewok {top n {apply 0}} {
4240 global nextviewnum newviewperm newviewname newishighlight
4241 global viewname viewfiles viewperm selectedview curview
4242 global viewargs viewargscmd newviewopts viewhlmenu
4244 if {[catch {
4245 set newargs [encode_view_opts $n]
4246 } err]} {
4247 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4248 return
4250 set files {}
4251 foreach f [split [$top.t get 0.0 end] "\n"] {
4252 set ft [string trim $f]
4253 if {$ft ne {}} {
4254 lappend files $ft
4257 if {![info exists viewfiles($n)]} {
4258 # creating a new view
4259 incr nextviewnum
4260 set viewname($n) $newviewname($n)
4261 set viewperm($n) $newviewopts($n,perm)
4262 set viewfiles($n) $files
4263 set viewargs($n) $newargs
4264 set viewargscmd($n) $newviewopts($n,cmd)
4265 addviewmenu $n
4266 if {!$newishighlight} {
4267 run showview $n
4268 } else {
4269 run addvhighlight $n
4271 } else {
4272 # editing an existing view
4273 set viewperm($n) $newviewopts($n,perm)
4274 if {$newviewname($n) ne $viewname($n)} {
4275 set viewname($n) $newviewname($n)
4276 doviewmenu .bar.view 5 [list showview $n] \
4277 entryconf [list -label $viewname($n)]
4278 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4279 # entryconf [list -label $viewname($n) -value $viewname($n)]
4281 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4282 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4283 set viewfiles($n) $files
4284 set viewargs($n) $newargs
4285 set viewargscmd($n) $newviewopts($n,cmd)
4286 if {$curview == $n} {
4287 run reloadcommits
4291 if {$apply} return
4292 catch {destroy $top}
4295 proc delview {} {
4296 global curview viewperm hlview selectedhlview
4298 if {$curview == 0} return
4299 if {[info exists hlview] && $hlview == $curview} {
4300 set selectedhlview [mc "None"]
4301 unset hlview
4303 allviewmenus $curview delete
4304 set viewperm($curview) 0
4305 showview 0
4308 proc addviewmenu {n} {
4309 global viewname viewhlmenu
4311 .bar.view add radiobutton -label $viewname($n) \
4312 -command [list showview $n] -variable selectedview -value $n
4313 #$viewhlmenu add radiobutton -label $viewname($n) \
4314 # -command [list addvhighlight $n] -variable selectedhlview
4317 proc showview {n} {
4318 global curview cached_commitrow ordertok
4319 global displayorder parentlist rowidlist rowisopt rowfinal
4320 global colormap rowtextx nextcolor canvxmax
4321 global numcommits viewcomplete
4322 global selectedline currentid canv canvy0
4323 global treediffs
4324 global pending_select mainheadid
4325 global commitidx
4326 global selectedview
4327 global hlview selectedhlview commitinterest
4329 if {$n == $curview} return
4330 set selid {}
4331 set ymax [lindex [$canv cget -scrollregion] 3]
4332 set span [$canv yview]
4333 set ytop [expr {[lindex $span 0] * $ymax}]
4334 set ybot [expr {[lindex $span 1] * $ymax}]
4335 set yscreen [expr {($ybot - $ytop) / 2}]
4336 if {$selectedline ne {}} {
4337 set selid $currentid
4338 set y [yc $selectedline]
4339 if {$ytop < $y && $y < $ybot} {
4340 set yscreen [expr {$y - $ytop}]
4342 } elseif {[info exists pending_select]} {
4343 set selid $pending_select
4344 unset pending_select
4346 unselectline
4347 normalline
4348 catch {unset treediffs}
4349 clear_display
4350 if {[info exists hlview] && $hlview == $n} {
4351 unset hlview
4352 set selectedhlview [mc "None"]
4354 catch {unset commitinterest}
4355 catch {unset cached_commitrow}
4356 catch {unset ordertok}
4358 set curview $n
4359 set selectedview $n
4360 .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4361 .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
4363 run refill_reflist
4364 if {![info exists viewcomplete($n)]} {
4365 getcommits $selid
4366 return
4369 set displayorder {}
4370 set parentlist {}
4371 set rowidlist {}
4372 set rowisopt {}
4373 set rowfinal {}
4374 set numcommits $commitidx($n)
4376 catch {unset colormap}
4377 catch {unset rowtextx}
4378 set nextcolor 0
4379 set canvxmax [$canv cget -width]
4380 set curview $n
4381 set row 0
4382 setcanvscroll
4383 set yf 0
4384 set row {}
4385 if {$selid ne {} && [commitinview $selid $n]} {
4386 set row [rowofcommit $selid]
4387 # try to get the selected row in the same position on the screen
4388 set ymax [lindex [$canv cget -scrollregion] 3]
4389 set ytop [expr {[yc $row] - $yscreen}]
4390 if {$ytop < 0} {
4391 set ytop 0
4393 set yf [expr {$ytop * 1.0 / $ymax}]
4395 allcanvs yview moveto $yf
4396 drawvisible
4397 if {$row ne {}} {
4398 selectline $row 0
4399 } elseif {!$viewcomplete($n)} {
4400 reset_pending_select $selid
4401 } else {
4402 reset_pending_select {}
4404 if {[commitinview $pending_select $curview]} {
4405 selectline [rowofcommit $pending_select] 1
4406 } else {
4407 set row [first_real_row]
4408 if {$row < $numcommits} {
4409 selectline $row 0
4413 if {!$viewcomplete($n)} {
4414 if {$numcommits == 0} {
4415 show_status [mc "Reading commits..."]
4417 } elseif {$numcommits == 0} {
4418 show_status [mc "No commits selected"]
4422 # Stuff relating to the highlighting facility
4424 proc ishighlighted {id} {
4425 global vhighlights fhighlights nhighlights rhighlights
4427 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
4428 return $nhighlights($id)
4430 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
4431 return $vhighlights($id)
4433 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
4434 return $fhighlights($id)
4436 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
4437 return $rhighlights($id)
4439 return 0
4442 proc bolden {id font} {
4443 global canv linehtag currentid boldids need_redisplay markedid
4445 # need_redisplay = 1 means the display is stale and about to be redrawn
4446 if {$need_redisplay} return
4447 lappend boldids $id
4448 $canv itemconf $linehtag($id) -font $font
4449 if {[info exists currentid] && $id eq $currentid} {
4450 $canv delete secsel
4451 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4452 -outline {{}} -tags secsel \
4453 -fill [$canv cget -selectbackground]]
4454 $canv lower $t
4456 if {[info exists markedid] && $id eq $markedid} {
4457 make_idmark $id
4461 proc bolden_name {id font} {
4462 global canv2 linentag currentid boldnameids need_redisplay
4464 if {$need_redisplay} return
4465 lappend boldnameids $id
4466 $canv2 itemconf $linentag($id) -font $font
4467 if {[info exists currentid] && $id eq $currentid} {
4468 $canv2 delete secsel
4469 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4470 -outline {{}} -tags secsel \
4471 -fill [$canv2 cget -selectbackground]]
4472 $canv2 lower $t
4476 proc unbolden {} {
4477 global boldids
4479 set stillbold {}
4480 foreach id $boldids {
4481 if {![ishighlighted $id]} {
4482 bolden $id mainfont
4483 } else {
4484 lappend stillbold $id
4487 set boldids $stillbold
4490 proc addvhighlight {n} {
4491 global hlview viewcomplete curview vhl_done commitidx
4493 if {[info exists hlview]} {
4494 delvhighlight
4496 set hlview $n
4497 if {$n != $curview && ![info exists viewcomplete($n)]} {
4498 start_rev_list $n
4500 set vhl_done $commitidx($hlview)
4501 if {$vhl_done > 0} {
4502 drawvisible
4506 proc delvhighlight {} {
4507 global hlview vhighlights
4509 if {![info exists hlview]} return
4510 unset hlview
4511 catch {unset vhighlights}
4512 unbolden
4515 proc vhighlightmore {} {
4516 global hlview vhl_done commitidx vhighlights curview
4518 set max $commitidx($hlview)
4519 set vr [visiblerows]
4520 set r0 [lindex $vr 0]
4521 set r1 [lindex $vr 1]
4522 for {set i $vhl_done} {$i < $max} {incr i} {
4523 set id [commitonrow $i $hlview]
4524 if {[commitinview $id $curview]} {
4525 set row [rowofcommit $id]
4526 if {$r0 <= $row && $row <= $r1} {
4527 if {![highlighted $row]} {
4528 bolden $id mainfontbold
4530 set vhighlights($id) 1
4534 set vhl_done $max
4535 return 0
4538 proc askvhighlight {row id} {
4539 global hlview vhighlights iddrawn
4541 if {[commitinview $id $hlview]} {
4542 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4543 bolden $id mainfontbold
4545 set vhighlights($id) 1
4546 } else {
4547 set vhighlights($id) 0
4551 proc hfiles_change {} {
4552 global highlight_files filehighlight fhighlights fh_serial
4553 global highlight_paths
4555 if {[info exists filehighlight]} {
4556 # delete previous highlights
4557 catch {close $filehighlight}
4558 unset filehighlight
4559 catch {unset fhighlights}
4560 unbolden
4561 unhighlight_filelist
4563 set highlight_paths {}
4564 after cancel do_file_hl $fh_serial
4565 incr fh_serial
4566 if {$highlight_files ne {}} {
4567 after 300 do_file_hl $fh_serial
4571 proc gdttype_change {name ix op} {
4572 global gdttype highlight_files findstring findpattern
4574 stopfinding
4575 if {$findstring ne {}} {
4576 if {$gdttype eq [mc "containing:"]} {
4577 if {$highlight_files ne {}} {
4578 set highlight_files {}
4579 hfiles_change
4581 findcom_change
4582 } else {
4583 if {$findpattern ne {}} {
4584 set findpattern {}
4585 findcom_change
4587 set highlight_files $findstring
4588 hfiles_change
4590 drawvisible
4592 # enable/disable findtype/findloc menus too
4595 proc find_change {name ix op} {
4596 global gdttype findstring highlight_files
4598 stopfinding
4599 if {$gdttype eq [mc "containing:"]} {
4600 findcom_change
4601 } else {
4602 if {$highlight_files ne $findstring} {
4603 set highlight_files $findstring
4604 hfiles_change
4607 drawvisible
4610 proc findcom_change args {
4611 global nhighlights boldnameids
4612 global findpattern findtype findstring gdttype
4614 stopfinding
4615 # delete previous highlights, if any
4616 foreach id $boldnameids {
4617 bolden_name $id mainfont
4619 set boldnameids {}
4620 catch {unset nhighlights}
4621 unbolden
4622 unmarkmatches
4623 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
4624 set findpattern {}
4625 } elseif {$findtype eq [mc "Regexp"]} {
4626 set findpattern $findstring
4627 } else {
4628 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4629 $findstring]
4630 set findpattern "*$e*"
4634 proc makepatterns {l} {
4635 set ret {}
4636 foreach e $l {
4637 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4638 if {[string index $ee end] eq "/"} {
4639 lappend ret "$ee*"
4640 } else {
4641 lappend ret $ee
4642 lappend ret "$ee/*"
4645 return $ret
4648 proc do_file_hl {serial} {
4649 global highlight_files filehighlight highlight_paths gdttype fhl_list
4650 global cdup findtype
4652 if {$gdttype eq [mc "touching paths:"]} {
4653 # If "exact" match then convert backslashes to forward slashes.
4654 # Most useful to support Windows-flavoured file paths.
4655 if {$findtype eq [mc "Exact"]} {
4656 set highlight_files [string map {"\\" "/"} $highlight_files]
4658 if {[catch {set paths [shellsplit $highlight_files]}]} return
4659 set highlight_paths [makepatterns $paths]
4660 highlight_filelist
4661 set relative_paths {}
4662 foreach path $paths {
4663 lappend relative_paths [file join $cdup $path]
4665 set gdtargs [concat -- $relative_paths]
4666 } elseif {$gdttype eq [mc "adding/removing string:"]} {
4667 set gdtargs [list "-S$highlight_files"]
4668 } elseif {$gdttype eq [mc "changing lines matching:"]} {
4669 set gdtargs [list "-G$highlight_files"]
4670 } else {
4671 # must be "containing:", i.e. we're searching commit info
4672 return
4674 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
4675 set filehighlight [open $cmd r+]
4676 fconfigure $filehighlight -blocking 0
4677 filerun $filehighlight readfhighlight
4678 set fhl_list {}
4679 drawvisible
4680 flushhighlights
4683 proc flushhighlights {} {
4684 global filehighlight fhl_list
4686 if {[info exists filehighlight]} {
4687 lappend fhl_list {}
4688 puts $filehighlight ""
4689 flush $filehighlight
4693 proc askfilehighlight {row id} {
4694 global filehighlight fhighlights fhl_list
4696 lappend fhl_list $id
4697 set fhighlights($id) -1
4698 puts $filehighlight $id
4701 proc readfhighlight {} {
4702 global filehighlight fhighlights curview iddrawn
4703 global fhl_list find_dirn
4705 if {![info exists filehighlight]} {
4706 return 0
4708 set nr 0
4709 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
4710 set line [string trim $line]
4711 set i [lsearch -exact $fhl_list $line]
4712 if {$i < 0} continue
4713 for {set j 0} {$j < $i} {incr j} {
4714 set id [lindex $fhl_list $j]
4715 set fhighlights($id) 0
4717 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4718 if {$line eq {}} continue
4719 if {![commitinview $line $curview]} continue
4720 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4721 bolden $line mainfontbold
4723 set fhighlights($line) 1
4725 if {[eof $filehighlight]} {
4726 # strange...
4727 puts "oops, git diff-tree died"
4728 catch {close $filehighlight}
4729 unset filehighlight
4730 return 0
4732 if {[info exists find_dirn]} {
4733 run findmore
4735 return 1
4738 proc doesmatch {f} {
4739 global findtype findpattern
4741 if {$findtype eq [mc "Regexp"]} {
4742 return [regexp $findpattern $f]
4743 } elseif {$findtype eq [mc "IgnCase"]} {
4744 return [string match -nocase $findpattern $f]
4745 } else {
4746 return [string match $findpattern $f]
4750 proc askfindhighlight {row id} {
4751 global nhighlights commitinfo iddrawn
4752 global findloc
4753 global markingmatches
4755 if {![info exists commitinfo($id)]} {
4756 getcommit $id
4758 set info $commitinfo($id)
4759 set isbold 0
4760 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
4761 foreach f $info ty $fldtypes {
4762 if {$ty eq ""} continue
4763 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4764 [doesmatch $f]} {
4765 if {$ty eq [mc "Author"]} {
4766 set isbold 2
4767 break
4769 set isbold 1
4772 if {$isbold && [info exists iddrawn($id)]} {
4773 if {![ishighlighted $id]} {
4774 bolden $id mainfontbold
4775 if {$isbold > 1} {
4776 bolden_name $id mainfontbold
4779 if {$markingmatches} {
4780 markrowmatches $row $id
4783 set nhighlights($id) $isbold
4786 proc markrowmatches {row id} {
4787 global canv canv2 linehtag linentag commitinfo findloc
4789 set headline [lindex $commitinfo($id) 0]
4790 set author [lindex $commitinfo($id) 1]
4791 $canv delete match$row
4792 $canv2 delete match$row
4793 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
4794 set m [findmatches $headline]
4795 if {$m ne {}} {
4796 markmatches $canv $row $headline $linehtag($id) $m \
4797 [$canv itemcget $linehtag($id) -font] $row
4800 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
4801 set m [findmatches $author]
4802 if {$m ne {}} {
4803 markmatches $canv2 $row $author $linentag($id) $m \
4804 [$canv2 itemcget $linentag($id) -font] $row
4809 proc vrel_change {name ix op} {
4810 global highlight_related
4812 rhighlight_none
4813 if {$highlight_related ne [mc "None"]} {
4814 run drawvisible
4818 # prepare for testing whether commits are descendents or ancestors of a
4819 proc rhighlight_sel {a} {
4820 global descendent desc_todo ancestor anc_todo
4821 global highlight_related
4823 catch {unset descendent}
4824 set desc_todo [list $a]
4825 catch {unset ancestor}
4826 set anc_todo [list $a]
4827 if {$highlight_related ne [mc "None"]} {
4828 rhighlight_none
4829 run drawvisible
4833 proc rhighlight_none {} {
4834 global rhighlights
4836 catch {unset rhighlights}
4837 unbolden
4840 proc is_descendent {a} {
4841 global curview children descendent desc_todo
4843 set v $curview
4844 set la [rowofcommit $a]
4845 set todo $desc_todo
4846 set leftover {}
4847 set done 0
4848 for {set i 0} {$i < [llength $todo]} {incr i} {
4849 set do [lindex $todo $i]
4850 if {[rowofcommit $do] < $la} {
4851 lappend leftover $do
4852 continue
4854 foreach nk $children($v,$do) {
4855 if {![info exists descendent($nk)]} {
4856 set descendent($nk) 1
4857 lappend todo $nk
4858 if {$nk eq $a} {
4859 set done 1
4863 if {$done} {
4864 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4865 return
4868 set descendent($a) 0
4869 set desc_todo $leftover
4872 proc is_ancestor {a} {
4873 global curview parents ancestor anc_todo
4875 set v $curview
4876 set la [rowofcommit $a]
4877 set todo $anc_todo
4878 set leftover {}
4879 set done 0
4880 for {set i 0} {$i < [llength $todo]} {incr i} {
4881 set do [lindex $todo $i]
4882 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
4883 lappend leftover $do
4884 continue
4886 foreach np $parents($v,$do) {
4887 if {![info exists ancestor($np)]} {
4888 set ancestor($np) 1
4889 lappend todo $np
4890 if {$np eq $a} {
4891 set done 1
4895 if {$done} {
4896 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
4897 return
4900 set ancestor($a) 0
4901 set anc_todo $leftover
4904 proc askrelhighlight {row id} {
4905 global descendent highlight_related iddrawn rhighlights
4906 global selectedline ancestor
4908 if {$selectedline eq {}} return
4909 set isbold 0
4910 if {$highlight_related eq [mc "Descendant"] ||
4911 $highlight_related eq [mc "Not descendant"]} {
4912 if {![info exists descendent($id)]} {
4913 is_descendent $id
4915 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
4916 set isbold 1
4918 } elseif {$highlight_related eq [mc "Ancestor"] ||
4919 $highlight_related eq [mc "Not ancestor"]} {
4920 if {![info exists ancestor($id)]} {
4921 is_ancestor $id
4923 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
4924 set isbold 1
4927 if {[info exists iddrawn($id)]} {
4928 if {$isbold && ![ishighlighted $id]} {
4929 bolden $id mainfontbold
4932 set rhighlights($id) $isbold
4935 # Graph layout functions
4937 proc shortids {ids} {
4938 set res {}
4939 foreach id $ids {
4940 if {[llength $id] > 1} {
4941 lappend res [shortids $id]
4942 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
4943 lappend res [string range $id 0 7]
4944 } else {
4945 lappend res $id
4948 return $res
4951 proc ntimes {n o} {
4952 set ret {}
4953 set o [list $o]
4954 for {set mask 1} {$mask <= $n} {incr mask $mask} {
4955 if {($n & $mask) != 0} {
4956 set ret [concat $ret $o]
4958 set o [concat $o $o]
4960 return $ret
4963 proc ordertoken {id} {
4964 global ordertok curview varcid varcstart varctok curview parents children
4965 global nullid nullid2
4967 if {[info exists ordertok($id)]} {
4968 return $ordertok($id)
4970 set origid $id
4971 set todo {}
4972 while {1} {
4973 if {[info exists varcid($curview,$id)]} {
4974 set a $varcid($curview,$id)
4975 set p [lindex $varcstart($curview) $a]
4976 } else {
4977 set p [lindex $children($curview,$id) 0]
4979 if {[info exists ordertok($p)]} {
4980 set tok $ordertok($p)
4981 break
4983 set id [first_real_child $curview,$p]
4984 if {$id eq {}} {
4985 # it's a root
4986 set tok [lindex $varctok($curview) $varcid($curview,$p)]
4987 break
4989 if {[llength $parents($curview,$id)] == 1} {
4990 lappend todo [list $p {}]
4991 } else {
4992 set j [lsearch -exact $parents($curview,$id) $p]
4993 if {$j < 0} {
4994 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
4996 lappend todo [list $p [strrep $j]]
4999 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
5000 set p [lindex $todo $i 0]
5001 append tok [lindex $todo $i 1]
5002 set ordertok($p) $tok
5004 set ordertok($origid) $tok
5005 return $tok
5008 # Work out where id should go in idlist so that order-token
5009 # values increase from left to right
5010 proc idcol {idlist id {i 0}} {
5011 set t [ordertoken $id]
5012 if {$i < 0} {
5013 set i 0
5015 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
5016 if {$i > [llength $idlist]} {
5017 set i [llength $idlist]
5019 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5020 incr i
5021 } else {
5022 if {$t > [ordertoken [lindex $idlist $i]]} {
5023 while {[incr i] < [llength $idlist] &&
5024 $t >= [ordertoken [lindex $idlist $i]]} {}
5027 return $i
5030 proc initlayout {} {
5031 global rowidlist rowisopt rowfinal displayorder parentlist
5032 global numcommits canvxmax canv
5033 global nextcolor
5034 global colormap rowtextx
5036 set numcommits 0
5037 set displayorder {}
5038 set parentlist {}
5039 set nextcolor 0
5040 set rowidlist {}
5041 set rowisopt {}
5042 set rowfinal {}
5043 set canvxmax [$canv cget -width]
5044 catch {unset colormap}
5045 catch {unset rowtextx}
5046 setcanvscroll
5049 proc setcanvscroll {} {
5050 global canv canv2 canv3 numcommits linespc canvxmax canvy0
5051 global lastscrollset lastscrollrows
5053 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5054 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5055 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5056 $canv3 conf -scrollregion [list 0 0 0 $ymax]
5057 set lastscrollset [clock clicks -milliseconds]
5058 set lastscrollrows $numcommits
5061 proc visiblerows {} {
5062 global canv numcommits linespc
5064 set ymax [lindex [$canv cget -scrollregion] 3]
5065 if {$ymax eq {} || $ymax == 0} return
5066 set f [$canv yview]
5067 set y0 [expr {int([lindex $f 0] * $ymax)}]
5068 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5069 if {$r0 < 0} {
5070 set r0 0
5072 set y1 [expr {int([lindex $f 1] * $ymax)}]
5073 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5074 if {$r1 >= $numcommits} {
5075 set r1 [expr {$numcommits - 1}]
5077 return [list $r0 $r1]
5080 proc layoutmore {} {
5081 global commitidx viewcomplete curview
5082 global numcommits pending_select curview
5083 global lastscrollset lastscrollrows
5085 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
5086 [clock clicks -milliseconds] - $lastscrollset > 500} {
5087 setcanvscroll
5089 if {[info exists pending_select] &&
5090 [commitinview $pending_select $curview]} {
5091 update
5092 selectline [rowofcommit $pending_select] 1
5094 drawvisible
5097 # With path limiting, we mightn't get the actual HEAD commit,
5098 # so ask git rev-list what is the first ancestor of HEAD that
5099 # touches a file in the path limit.
5100 proc get_viewmainhead {view} {
5101 global viewmainheadid vfilelimit viewinstances mainheadid
5103 catch {
5104 set rfd [open [concat | git rev-list -1 $mainheadid \
5105 -- $vfilelimit($view)] r]
5106 set j [reg_instance $rfd]
5107 lappend viewinstances($view) $j
5108 fconfigure $rfd -blocking 0
5109 filerun $rfd [list getviewhead $rfd $j $view]
5110 set viewmainheadid($curview) {}
5114 # git rev-list should give us just 1 line to use as viewmainheadid($view)
5115 proc getviewhead {fd inst view} {
5116 global viewmainheadid commfd curview viewinstances showlocalchanges
5118 set id {}
5119 if {[gets $fd line] < 0} {
5120 if {![eof $fd]} {
5121 return 1
5123 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
5124 set id $line
5126 set viewmainheadid($view) $id
5127 close $fd
5128 unset commfd($inst)
5129 set i [lsearch -exact $viewinstances($view) $inst]
5130 if {$i >= 0} {
5131 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
5133 if {$showlocalchanges && $id ne {} && $view == $curview} {
5134 doshowlocalchanges
5136 return 0
5139 proc doshowlocalchanges {} {
5140 global curview viewmainheadid
5142 if {$viewmainheadid($curview) eq {}} return
5143 if {[commitinview $viewmainheadid($curview) $curview]} {
5144 dodiffindex
5145 } else {
5146 interestedin $viewmainheadid($curview) dodiffindex
5150 proc dohidelocalchanges {} {
5151 global nullid nullid2 lserial curview
5153 if {[commitinview $nullid $curview]} {
5154 removefakerow $nullid
5156 if {[commitinview $nullid2 $curview]} {
5157 removefakerow $nullid2
5159 incr lserial
5162 # spawn off a process to do git diff-index --cached HEAD
5163 proc dodiffindex {} {
5164 global lserial showlocalchanges vfilelimit curview
5165 global hasworktree git_version
5167 if {!$showlocalchanges || !$hasworktree} return
5168 incr lserial
5169 if {[package vcompare $git_version "1.7.2"] >= 0} {
5170 set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
5171 } else {
5172 set cmd "|git diff-index --cached HEAD"
5174 if {$vfilelimit($curview) ne {}} {
5175 set cmd [concat $cmd -- $vfilelimit($curview)]
5177 set fd [open $cmd r]
5178 fconfigure $fd -blocking 0
5179 set i [reg_instance $fd]
5180 filerun $fd [list readdiffindex $fd $lserial $i]
5183 proc readdiffindex {fd serial inst} {
5184 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5185 global vfilelimit
5187 set isdiff 1
5188 if {[gets $fd line] < 0} {
5189 if {![eof $fd]} {
5190 return 1
5192 set isdiff 0
5194 # we only need to see one line and we don't really care what it says...
5195 stop_instance $inst
5197 if {$serial != $lserial} {
5198 return 0
5201 # now see if there are any local changes not checked in to the index
5202 set cmd "|git diff-files"
5203 if {$vfilelimit($curview) ne {}} {
5204 set cmd [concat $cmd -- $vfilelimit($curview)]
5206 set fd [open $cmd r]
5207 fconfigure $fd -blocking 0
5208 set i [reg_instance $fd]
5209 filerun $fd [list readdifffiles $fd $serial $i]
5211 if {$isdiff && ![commitinview $nullid2 $curview]} {
5212 # add the line for the changes in the index to the graph
5213 set hl [mc "Local changes checked in to index but not committed"]
5214 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5215 set commitdata($nullid2) "\n $hl\n"
5216 if {[commitinview $nullid $curview]} {
5217 removefakerow $nullid
5219 insertfakerow $nullid2 $viewmainheadid($curview)
5220 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
5221 if {[commitinview $nullid $curview]} {
5222 removefakerow $nullid
5224 removefakerow $nullid2
5226 return 0
5229 proc readdifffiles {fd serial inst} {
5230 global viewmainheadid nullid nullid2 curview
5231 global commitinfo commitdata lserial
5233 set isdiff 1
5234 if {[gets $fd line] < 0} {
5235 if {![eof $fd]} {
5236 return 1
5238 set isdiff 0
5240 # we only need to see one line and we don't really care what it says...
5241 stop_instance $inst
5243 if {$serial != $lserial} {
5244 return 0
5247 if {$isdiff && ![commitinview $nullid $curview]} {
5248 # add the line for the local diff to the graph
5249 set hl [mc "Local uncommitted changes, not checked in to index"]
5250 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5251 set commitdata($nullid) "\n $hl\n"
5252 if {[commitinview $nullid2 $curview]} {
5253 set p $nullid2
5254 } else {
5255 set p $viewmainheadid($curview)
5257 insertfakerow $nullid $p
5258 } elseif {!$isdiff && [commitinview $nullid $curview]} {
5259 removefakerow $nullid
5261 return 0
5264 proc nextuse {id row} {
5265 global curview children
5267 if {[info exists children($curview,$id)]} {
5268 foreach kid $children($curview,$id) {
5269 if {![commitinview $kid $curview]} {
5270 return -1
5272 if {[rowofcommit $kid] > $row} {
5273 return [rowofcommit $kid]
5277 if {[commitinview $id $curview]} {
5278 return [rowofcommit $id]
5280 return -1
5283 proc prevuse {id row} {
5284 global curview children
5286 set ret -1
5287 if {[info exists children($curview,$id)]} {
5288 foreach kid $children($curview,$id) {
5289 if {![commitinview $kid $curview]} break
5290 if {[rowofcommit $kid] < $row} {
5291 set ret [rowofcommit $kid]
5295 return $ret
5298 proc make_idlist {row} {
5299 global displayorder parentlist uparrowlen downarrowlen mingaplen
5300 global commitidx curview children
5302 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5303 if {$r < 0} {
5304 set r 0
5306 set ra [expr {$row - $downarrowlen}]
5307 if {$ra < 0} {
5308 set ra 0
5310 set rb [expr {$row + $uparrowlen}]
5311 if {$rb > $commitidx($curview)} {
5312 set rb $commitidx($curview)
5314 make_disporder $r [expr {$rb + 1}]
5315 set ids {}
5316 for {} {$r < $ra} {incr r} {
5317 set nextid [lindex $displayorder [expr {$r + 1}]]
5318 foreach p [lindex $parentlist $r] {
5319 if {$p eq $nextid} continue
5320 set rn [nextuse $p $r]
5321 if {$rn >= $row &&
5322 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5323 lappend ids [list [ordertoken $p] $p]
5327 for {} {$r < $row} {incr r} {
5328 set nextid [lindex $displayorder [expr {$r + 1}]]
5329 foreach p [lindex $parentlist $r] {
5330 if {$p eq $nextid} continue
5331 set rn [nextuse $p $r]
5332 if {$rn < 0 || $rn >= $row} {
5333 lappend ids [list [ordertoken $p] $p]
5337 set id [lindex $displayorder $row]
5338 lappend ids [list [ordertoken $id] $id]
5339 while {$r < $rb} {
5340 foreach p [lindex $parentlist $r] {
5341 set firstkid [lindex $children($curview,$p) 0]
5342 if {[rowofcommit $firstkid] < $row} {
5343 lappend ids [list [ordertoken $p] $p]
5346 incr r
5347 set id [lindex $displayorder $r]
5348 if {$id ne {}} {
5349 set firstkid [lindex $children($curview,$id) 0]
5350 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5351 lappend ids [list [ordertoken $id] $id]
5355 set idlist {}
5356 foreach idx [lsort -unique $ids] {
5357 lappend idlist [lindex $idx 1]
5359 return $idlist
5362 proc rowsequal {a b} {
5363 while {[set i [lsearch -exact $a {}]] >= 0} {
5364 set a [lreplace $a $i $i]
5366 while {[set i [lsearch -exact $b {}]] >= 0} {
5367 set b [lreplace $b $i $i]
5369 return [expr {$a eq $b}]
5372 proc makeupline {id row rend col} {
5373 global rowidlist uparrowlen downarrowlen mingaplen
5375 for {set r $rend} {1} {set r $rstart} {
5376 set rstart [prevuse $id $r]
5377 if {$rstart < 0} return
5378 if {$rstart < $row} break
5380 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
5381 set rstart [expr {$rend - $uparrowlen - 1}]
5383 for {set r $rstart} {[incr r] <= $row} {} {
5384 set idlist [lindex $rowidlist $r]
5385 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5386 set col [idcol $idlist $id $col]
5387 lset rowidlist $r [linsert $idlist $col $id]
5388 changedrow $r
5393 proc layoutrows {row endrow} {
5394 global rowidlist rowisopt rowfinal displayorder
5395 global uparrowlen downarrowlen maxwidth mingaplen
5396 global children parentlist
5397 global commitidx viewcomplete curview
5399 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
5400 set idlist {}
5401 if {$row > 0} {
5402 set rm1 [expr {$row - 1}]
5403 foreach id [lindex $rowidlist $rm1] {
5404 if {$id ne {}} {
5405 lappend idlist $id
5408 set final [lindex $rowfinal $rm1]
5410 for {} {$row < $endrow} {incr row} {
5411 set rm1 [expr {$row - 1}]
5412 if {$rm1 < 0 || $idlist eq {}} {
5413 set idlist [make_idlist $row]
5414 set final 1
5415 } else {
5416 set id [lindex $displayorder $rm1]
5417 set col [lsearch -exact $idlist $id]
5418 set idlist [lreplace $idlist $col $col]
5419 foreach p [lindex $parentlist $rm1] {
5420 if {[lsearch -exact $idlist $p] < 0} {
5421 set col [idcol $idlist $p $col]
5422 set idlist [linsert $idlist $col $p]
5423 # if not the first child, we have to insert a line going up
5424 if {$id ne [lindex $children($curview,$p) 0]} {
5425 makeupline $p $rm1 $row $col
5429 set id [lindex $displayorder $row]
5430 if {$row > $downarrowlen} {
5431 set termrow [expr {$row - $downarrowlen - 1}]
5432 foreach p [lindex $parentlist $termrow] {
5433 set i [lsearch -exact $idlist $p]
5434 if {$i < 0} continue
5435 set nr [nextuse $p $termrow]
5436 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5437 set idlist [lreplace $idlist $i $i]
5441 set col [lsearch -exact $idlist $id]
5442 if {$col < 0} {
5443 set col [idcol $idlist $id]
5444 set idlist [linsert $idlist $col $id]
5445 if {$children($curview,$id) ne {}} {
5446 makeupline $id $rm1 $row $col
5449 set r [expr {$row + $uparrowlen - 1}]
5450 if {$r < $commitidx($curview)} {
5451 set x $col
5452 foreach p [lindex $parentlist $r] {
5453 if {[lsearch -exact $idlist $p] >= 0} continue
5454 set fk [lindex $children($curview,$p) 0]
5455 if {[rowofcommit $fk] < $row} {
5456 set x [idcol $idlist $p $x]
5457 set idlist [linsert $idlist $x $p]
5460 if {[incr r] < $commitidx($curview)} {
5461 set p [lindex $displayorder $r]
5462 if {[lsearch -exact $idlist $p] < 0} {
5463 set fk [lindex $children($curview,$p) 0]
5464 if {$fk ne {} && [rowofcommit $fk] < $row} {
5465 set x [idcol $idlist $p $x]
5466 set idlist [linsert $idlist $x $p]
5472 if {$final && !$viewcomplete($curview) &&
5473 $row + $uparrowlen + $mingaplen + $downarrowlen
5474 >= $commitidx($curview)} {
5475 set final 0
5477 set l [llength $rowidlist]
5478 if {$row == $l} {
5479 lappend rowidlist $idlist
5480 lappend rowisopt 0
5481 lappend rowfinal $final
5482 } elseif {$row < $l} {
5483 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5484 lset rowidlist $row $idlist
5485 changedrow $row
5487 lset rowfinal $row $final
5488 } else {
5489 set pad [ntimes [expr {$row - $l}] {}]
5490 set rowidlist [concat $rowidlist $pad]
5491 lappend rowidlist $idlist
5492 set rowfinal [concat $rowfinal $pad]
5493 lappend rowfinal $final
5494 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5497 return $row
5500 proc changedrow {row} {
5501 global displayorder iddrawn rowisopt need_redisplay
5503 set l [llength $rowisopt]
5504 if {$row < $l} {
5505 lset rowisopt $row 0
5506 if {$row + 1 < $l} {
5507 lset rowisopt [expr {$row + 1}] 0
5508 if {$row + 2 < $l} {
5509 lset rowisopt [expr {$row + 2}] 0
5513 set id [lindex $displayorder $row]
5514 if {[info exists iddrawn($id)]} {
5515 set need_redisplay 1
5519 proc insert_pad {row col npad} {
5520 global rowidlist
5522 set pad [ntimes $npad {}]
5523 set idlist [lindex $rowidlist $row]
5524 set bef [lrange $idlist 0 [expr {$col - 1}]]
5525 set aft [lrange $idlist $col end]
5526 set i [lsearch -exact $aft {}]
5527 if {$i > 0} {
5528 set aft [lreplace $aft $i $i]
5530 lset rowidlist $row [concat $bef $pad $aft]
5531 changedrow $row
5534 proc optimize_rows {row col endrow} {
5535 global rowidlist rowisopt displayorder curview children
5537 if {$row < 1} {
5538 set row 1
5540 for {} {$row < $endrow} {incr row; set col 0} {
5541 if {[lindex $rowisopt $row]} continue
5542 set haspad 0
5543 set y0 [expr {$row - 1}]
5544 set ym [expr {$row - 2}]
5545 set idlist [lindex $rowidlist $row]
5546 set previdlist [lindex $rowidlist $y0]
5547 if {$idlist eq {} || $previdlist eq {}} continue
5548 if {$ym >= 0} {
5549 set pprevidlist [lindex $rowidlist $ym]
5550 if {$pprevidlist eq {}} continue
5551 } else {
5552 set pprevidlist {}
5554 set x0 -1
5555 set xm -1
5556 for {} {$col < [llength $idlist]} {incr col} {
5557 set id [lindex $idlist $col]
5558 if {[lindex $previdlist $col] eq $id} continue
5559 if {$id eq {}} {
5560 set haspad 1
5561 continue
5563 set x0 [lsearch -exact $previdlist $id]
5564 if {$x0 < 0} continue
5565 set z [expr {$x0 - $col}]
5566 set isarrow 0
5567 set z0 {}
5568 if {$ym >= 0} {
5569 set xm [lsearch -exact $pprevidlist $id]
5570 if {$xm >= 0} {
5571 set z0 [expr {$xm - $x0}]
5574 if {$z0 eq {}} {
5575 # if row y0 is the first child of $id then it's not an arrow
5576 if {[lindex $children($curview,$id) 0] ne
5577 [lindex $displayorder $y0]} {
5578 set isarrow 1
5581 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5582 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5583 set isarrow 1
5585 # Looking at lines from this row to the previous row,
5586 # make them go straight up if they end in an arrow on
5587 # the previous row; otherwise make them go straight up
5588 # or at 45 degrees.
5589 if {$z < -1 || ($z < 0 && $isarrow)} {
5590 # Line currently goes left too much;
5591 # insert pads in the previous row, then optimize it
5592 set npad [expr {-1 - $z + $isarrow}]
5593 insert_pad $y0 $x0 $npad
5594 if {$y0 > 0} {
5595 optimize_rows $y0 $x0 $row
5597 set previdlist [lindex $rowidlist $y0]
5598 set x0 [lsearch -exact $previdlist $id]
5599 set z [expr {$x0 - $col}]
5600 if {$z0 ne {}} {
5601 set pprevidlist [lindex $rowidlist $ym]
5602 set xm [lsearch -exact $pprevidlist $id]
5603 set z0 [expr {$xm - $x0}]
5605 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5606 # Line currently goes right too much;
5607 # insert pads in this line
5608 set npad [expr {$z - 1 + $isarrow}]
5609 insert_pad $row $col $npad
5610 set idlist [lindex $rowidlist $row]
5611 incr col $npad
5612 set z [expr {$x0 - $col}]
5613 set haspad 1
5615 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5616 # this line links to its first child on row $row-2
5617 set id [lindex $displayorder $ym]
5618 set xc [lsearch -exact $pprevidlist $id]
5619 if {$xc >= 0} {
5620 set z0 [expr {$xc - $x0}]
5623 # avoid lines jigging left then immediately right
5624 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5625 insert_pad $y0 $x0 1
5626 incr x0
5627 optimize_rows $y0 $x0 $row
5628 set previdlist [lindex $rowidlist $y0]
5631 if {!$haspad} {
5632 # Find the first column that doesn't have a line going right
5633 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5634 set id [lindex $idlist $col]
5635 if {$id eq {}} break
5636 set x0 [lsearch -exact $previdlist $id]
5637 if {$x0 < 0} {
5638 # check if this is the link to the first child
5639 set kid [lindex $displayorder $y0]
5640 if {[lindex $children($curview,$id) 0] eq $kid} {
5641 # it is, work out offset to child
5642 set x0 [lsearch -exact $previdlist $kid]
5645 if {$x0 <= $col} break
5647 # Insert a pad at that column as long as it has a line and
5648 # isn't the last column
5649 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5650 set idlist [linsert $idlist $col {}]
5651 lset rowidlist $row $idlist
5652 changedrow $row
5658 proc xc {row col} {
5659 global canvx0 linespc
5660 return [expr {$canvx0 + $col * $linespc}]
5663 proc yc {row} {
5664 global canvy0 linespc
5665 return [expr {$canvy0 + $row * $linespc}]
5668 proc linewidth {id} {
5669 global thickerline lthickness
5671 set wid $lthickness
5672 if {[info exists thickerline] && $id eq $thickerline} {
5673 set wid [expr {2 * $lthickness}]
5675 return $wid
5678 proc rowranges {id} {
5679 global curview children uparrowlen downarrowlen
5680 global rowidlist
5682 set kids $children($curview,$id)
5683 if {$kids eq {}} {
5684 return {}
5686 set ret {}
5687 lappend kids $id
5688 foreach child $kids {
5689 if {![commitinview $child $curview]} break
5690 set row [rowofcommit $child]
5691 if {![info exists prev]} {
5692 lappend ret [expr {$row + 1}]
5693 } else {
5694 if {$row <= $prevrow} {
5695 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5697 # see if the line extends the whole way from prevrow to row
5698 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5699 [lsearch -exact [lindex $rowidlist \
5700 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5701 # it doesn't, see where it ends
5702 set r [expr {$prevrow + $downarrowlen}]
5703 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5704 while {[incr r -1] > $prevrow &&
5705 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5706 } else {
5707 while {[incr r] <= $row &&
5708 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5709 incr r -1
5711 lappend ret $r
5712 # see where it starts up again
5713 set r [expr {$row - $uparrowlen}]
5714 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5715 while {[incr r] < $row &&
5716 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5717 } else {
5718 while {[incr r -1] >= $prevrow &&
5719 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5720 incr r
5722 lappend ret $r
5725 if {$child eq $id} {
5726 lappend ret $row
5728 set prev $child
5729 set prevrow $row
5731 return $ret
5734 proc drawlineseg {id row endrow arrowlow} {
5735 global rowidlist displayorder iddrawn linesegs
5736 global canv colormap linespc curview maxlinelen parentlist
5738 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5739 set le [expr {$row + 1}]
5740 set arrowhigh 1
5741 while {1} {
5742 set c [lsearch -exact [lindex $rowidlist $le] $id]
5743 if {$c < 0} {
5744 incr le -1
5745 break
5747 lappend cols $c
5748 set x [lindex $displayorder $le]
5749 if {$x eq $id} {
5750 set arrowhigh 0
5751 break
5753 if {[info exists iddrawn($x)] || $le == $endrow} {
5754 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5755 if {$c >= 0} {
5756 lappend cols $c
5757 set arrowhigh 0
5759 break
5761 incr le
5763 if {$le <= $row} {
5764 return $row
5767 set lines {}
5768 set i 0
5769 set joinhigh 0
5770 if {[info exists linesegs($id)]} {
5771 set lines $linesegs($id)
5772 foreach li $lines {
5773 set r0 [lindex $li 0]
5774 if {$r0 > $row} {
5775 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5776 set joinhigh 1
5778 break
5780 incr i
5783 set joinlow 0
5784 if {$i > 0} {
5785 set li [lindex $lines [expr {$i-1}]]
5786 set r1 [lindex $li 1]
5787 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5788 set joinlow 1
5792 set x [lindex $cols [expr {$le - $row}]]
5793 set xp [lindex $cols [expr {$le - 1 - $row}]]
5794 set dir [expr {$xp - $x}]
5795 if {$joinhigh} {
5796 set ith [lindex $lines $i 2]
5797 set coords [$canv coords $ith]
5798 set ah [$canv itemcget $ith -arrow]
5799 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5800 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5801 if {$x2 ne {} && $x - $x2 == $dir} {
5802 set coords [lrange $coords 0 end-2]
5804 } else {
5805 set coords [list [xc $le $x] [yc $le]]
5807 if {$joinlow} {
5808 set itl [lindex $lines [expr {$i-1}] 2]
5809 set al [$canv itemcget $itl -arrow]
5810 set arrowlow [expr {$al eq "last" || $al eq "both"}]
5811 } elseif {$arrowlow} {
5812 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5813 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5814 set arrowlow 0
5817 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5818 for {set y $le} {[incr y -1] > $row} {} {
5819 set x $xp
5820 set xp [lindex $cols [expr {$y - 1 - $row}]]
5821 set ndir [expr {$xp - $x}]
5822 if {$dir != $ndir || $xp < 0} {
5823 lappend coords [xc $y $x] [yc $y]
5825 set dir $ndir
5827 if {!$joinlow} {
5828 if {$xp < 0} {
5829 # join parent line to first child
5830 set ch [lindex $displayorder $row]
5831 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5832 if {$xc < 0} {
5833 puts "oops: drawlineseg: child $ch not on row $row"
5834 } elseif {$xc != $x} {
5835 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5836 set d [expr {int(0.5 * $linespc)}]
5837 set x1 [xc $row $x]
5838 if {$xc < $x} {
5839 set x2 [expr {$x1 - $d}]
5840 } else {
5841 set x2 [expr {$x1 + $d}]
5843 set y2 [yc $row]
5844 set y1 [expr {$y2 + $d}]
5845 lappend coords $x1 $y1 $x2 $y2
5846 } elseif {$xc < $x - 1} {
5847 lappend coords [xc $row [expr {$x-1}]] [yc $row]
5848 } elseif {$xc > $x + 1} {
5849 lappend coords [xc $row [expr {$x+1}]] [yc $row]
5851 set x $xc
5853 lappend coords [xc $row $x] [yc $row]
5854 } else {
5855 set xn [xc $row $xp]
5856 set yn [yc $row]
5857 lappend coords $xn $yn
5859 if {!$joinhigh} {
5860 assigncolor $id
5861 set t [$canv create line $coords -width [linewidth $id] \
5862 -fill $colormap($id) -tags lines.$id -arrow $arrow]
5863 $canv lower $t
5864 bindline $t $id
5865 set lines [linsert $lines $i [list $row $le $t]]
5866 } else {
5867 $canv coords $ith $coords
5868 if {$arrow ne $ah} {
5869 $canv itemconf $ith -arrow $arrow
5871 lset lines $i 0 $row
5873 } else {
5874 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
5875 set ndir [expr {$xo - $xp}]
5876 set clow [$canv coords $itl]
5877 if {$dir == $ndir} {
5878 set clow [lrange $clow 2 end]
5880 set coords [concat $coords $clow]
5881 if {!$joinhigh} {
5882 lset lines [expr {$i-1}] 1 $le
5883 } else {
5884 # coalesce two pieces
5885 $canv delete $ith
5886 set b [lindex $lines [expr {$i-1}] 0]
5887 set e [lindex $lines $i 1]
5888 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
5890 $canv coords $itl $coords
5891 if {$arrow ne $al} {
5892 $canv itemconf $itl -arrow $arrow
5896 set linesegs($id) $lines
5897 return $le
5900 proc drawparentlinks {id row} {
5901 global rowidlist canv colormap curview parentlist
5902 global idpos linespc
5904 set rowids [lindex $rowidlist $row]
5905 set col [lsearch -exact $rowids $id]
5906 if {$col < 0} return
5907 set olds [lindex $parentlist $row]
5908 set row2 [expr {$row + 1}]
5909 set x [xc $row $col]
5910 set y [yc $row]
5911 set y2 [yc $row2]
5912 set d [expr {int(0.5 * $linespc)}]
5913 set ymid [expr {$y + $d}]
5914 set ids [lindex $rowidlist $row2]
5915 # rmx = right-most X coord used
5916 set rmx 0
5917 foreach p $olds {
5918 set i [lsearch -exact $ids $p]
5919 if {$i < 0} {
5920 puts "oops, parent $p of $id not in list"
5921 continue
5923 set x2 [xc $row2 $i]
5924 if {$x2 > $rmx} {
5925 set rmx $x2
5927 set j [lsearch -exact $rowids $p]
5928 if {$j < 0} {
5929 # drawlineseg will do this one for us
5930 continue
5932 assigncolor $p
5933 # should handle duplicated parents here...
5934 set coords [list $x $y]
5935 if {$i != $col} {
5936 # if attaching to a vertical segment, draw a smaller
5937 # slant for visual distinctness
5938 if {$i == $j} {
5939 if {$i < $col} {
5940 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
5941 } else {
5942 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
5944 } elseif {$i < $col && $i < $j} {
5945 # segment slants towards us already
5946 lappend coords [xc $row $j] $y
5947 } else {
5948 if {$i < $col - 1} {
5949 lappend coords [expr {$x2 + $linespc}] $y
5950 } elseif {$i > $col + 1} {
5951 lappend coords [expr {$x2 - $linespc}] $y
5953 lappend coords $x2 $y2
5955 } else {
5956 lappend coords $x2 $y2
5958 set t [$canv create line $coords -width [linewidth $p] \
5959 -fill $colormap($p) -tags lines.$p]
5960 $canv lower $t
5961 bindline $t $p
5963 if {$rmx > [lindex $idpos($id) 1]} {
5964 lset idpos($id) 1 $rmx
5965 redrawtags $id
5969 proc drawlines {id} {
5970 global canv
5972 $canv itemconf lines.$id -width [linewidth $id]
5975 proc drawcmittext {id row col} {
5976 global linespc canv canv2 canv3 fgcolor curview
5977 global cmitlisted commitinfo rowidlist parentlist
5978 global rowtextx idpos idtags idheads idotherrefs
5979 global linehtag linentag linedtag selectedline
5980 global canvxmax boldids boldnameids fgcolor markedid
5981 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5982 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
5983 global circleoutlinecolor
5985 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
5986 set listed $cmitlisted($curview,$id)
5987 if {$id eq $nullid} {
5988 set ofill $workingfilescirclecolor
5989 } elseif {$id eq $nullid2} {
5990 set ofill $indexcirclecolor
5991 } elseif {$id eq $mainheadid} {
5992 set ofill $mainheadcirclecolor
5993 } else {
5994 set ofill [lindex $circlecolors $listed]
5996 set x [xc $row $col]
5997 set y [yc $row]
5998 set orad [expr {$linespc / 3}]
5999 if {$listed <= 2} {
6000 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6001 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6002 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6003 } elseif {$listed == 3} {
6004 # triangle pointing left for left-side commits
6005 set t [$canv create polygon \
6006 [expr {$x - $orad}] $y \
6007 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6008 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6009 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6010 } else {
6011 # triangle pointing right for right-side commits
6012 set t [$canv create polygon \
6013 [expr {$x + $orad - 1}] $y \
6014 [expr {$x - $orad}] [expr {$y - $orad}] \
6015 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6016 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
6018 set circleitem($row) $t
6019 $canv raise $t
6020 $canv bind $t <1> {selcanvline {} %x %y}
6021 set rmx [llength [lindex $rowidlist $row]]
6022 set olds [lindex $parentlist $row]
6023 if {$olds ne {}} {
6024 set nextids [lindex $rowidlist [expr {$row + 1}]]
6025 foreach p $olds {
6026 set i [lsearch -exact $nextids $p]
6027 if {$i > $rmx} {
6028 set rmx $i
6032 set xt [xc $row $rmx]
6033 set rowtextx($row) $xt
6034 set idpos($id) [list $x $xt $y]
6035 if {[info exists idtags($id)] || [info exists idheads($id)]
6036 || [info exists idotherrefs($id)]} {
6037 set xt [drawtags $id $x $xt $y]
6039 if {[lindex $commitinfo($id) 6] > 0} {
6040 set xt [drawnotesign $xt $y]
6042 set headline [lindex $commitinfo($id) 0]
6043 set name [lindex $commitinfo($id) 1]
6044 set date [lindex $commitinfo($id) 2]
6045 set date [formatdate $date]
6046 set font mainfont
6047 set nfont mainfont
6048 set isbold [ishighlighted $id]
6049 if {$isbold > 0} {
6050 lappend boldids $id
6051 set font mainfontbold
6052 if {$isbold > 1} {
6053 lappend boldnameids $id
6054 set nfont mainfontbold
6057 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
6058 -text $headline -font $font -tags text]
6059 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6060 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
6061 -text $name -font $nfont -tags text]
6062 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
6063 -text $date -font mainfont -tags text]
6064 if {$selectedline == $row} {
6065 make_secsel $id
6067 if {[info exists markedid] && $markedid eq $id} {
6068 make_idmark $id
6070 set xr [expr {$xt + [font measure $font $headline]}]
6071 if {$xr > $canvxmax} {
6072 set canvxmax $xr
6073 setcanvscroll
6077 proc drawcmitrow {row} {
6078 global displayorder rowidlist nrows_drawn
6079 global iddrawn markingmatches
6080 global commitinfo numcommits
6081 global filehighlight fhighlights findpattern nhighlights
6082 global hlview vhighlights
6083 global highlight_related rhighlights
6085 if {$row >= $numcommits} return
6087 set id [lindex $displayorder $row]
6088 if {[info exists hlview] && ![info exists vhighlights($id)]} {
6089 askvhighlight $row $id
6091 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
6092 askfilehighlight $row $id
6094 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
6095 askfindhighlight $row $id
6097 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
6098 askrelhighlight $row $id
6100 if {![info exists iddrawn($id)]} {
6101 set col [lsearch -exact [lindex $rowidlist $row] $id]
6102 if {$col < 0} {
6103 puts "oops, row $row id $id not in list"
6104 return
6106 if {![info exists commitinfo($id)]} {
6107 getcommit $id
6109 assigncolor $id
6110 drawcmittext $id $row $col
6111 set iddrawn($id) 1
6112 incr nrows_drawn
6114 if {$markingmatches} {
6115 markrowmatches $row $id
6119 proc drawcommits {row {endrow {}}} {
6120 global numcommits iddrawn displayorder curview need_redisplay
6121 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
6123 if {$row < 0} {
6124 set row 0
6126 if {$endrow eq {}} {
6127 set endrow $row
6129 if {$endrow >= $numcommits} {
6130 set endrow [expr {$numcommits - 1}]
6133 set rl1 [expr {$row - $downarrowlen - 3}]
6134 if {$rl1 < 0} {
6135 set rl1 0
6137 set ro1 [expr {$row - 3}]
6138 if {$ro1 < 0} {
6139 set ro1 0
6141 set r2 [expr {$endrow + $uparrowlen + 3}]
6142 if {$r2 > $numcommits} {
6143 set r2 $numcommits
6145 for {set r $rl1} {$r < $r2} {incr r} {
6146 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6147 if {$rl1 < $r} {
6148 layoutrows $rl1 $r
6150 set rl1 [expr {$r + 1}]
6153 if {$rl1 < $r} {
6154 layoutrows $rl1 $r
6156 optimize_rows $ro1 0 $r2
6157 if {$need_redisplay || $nrows_drawn > 2000} {
6158 clear_display
6161 # make the lines join to already-drawn rows either side
6162 set r [expr {$row - 1}]
6163 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
6164 set r $row
6166 set er [expr {$endrow + 1}]
6167 if {$er >= $numcommits ||
6168 ![info exists iddrawn([lindex $displayorder $er])]} {
6169 set er $endrow
6171 for {} {$r <= $er} {incr r} {
6172 set id [lindex $displayorder $r]
6173 set wasdrawn [info exists iddrawn($id)]
6174 drawcmitrow $r
6175 if {$r == $er} break
6176 set nextid [lindex $displayorder [expr {$r + 1}]]
6177 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6178 drawparentlinks $id $r
6180 set rowids [lindex $rowidlist $r]
6181 foreach lid $rowids {
6182 if {$lid eq {}} continue
6183 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6184 if {$lid eq $id} {
6185 # see if this is the first child of any of its parents
6186 foreach p [lindex $parentlist $r] {
6187 if {[lsearch -exact $rowids $p] < 0} {
6188 # make this line extend up to the child
6189 set lineend($p) [drawlineseg $p $r $er 0]
6192 } else {
6193 set lineend($lid) [drawlineseg $lid $r $er 1]
6199 proc undolayout {row} {
6200 global uparrowlen mingaplen downarrowlen
6201 global rowidlist rowisopt rowfinal need_redisplay
6203 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6204 if {$r < 0} {
6205 set r 0
6207 if {[llength $rowidlist] > $r} {
6208 incr r -1
6209 set rowidlist [lrange $rowidlist 0 $r]
6210 set rowfinal [lrange $rowfinal 0 $r]
6211 set rowisopt [lrange $rowisopt 0 $r]
6212 set need_redisplay 1
6213 run drawvisible
6217 proc drawvisible {} {
6218 global canv linespc curview vrowmod selectedline targetrow targetid
6219 global need_redisplay cscroll numcommits
6221 set fs [$canv yview]
6222 set ymax [lindex [$canv cget -scrollregion] 3]
6223 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
6224 set f0 [lindex $fs 0]
6225 set f1 [lindex $fs 1]
6226 set y0 [expr {int($f0 * $ymax)}]
6227 set y1 [expr {int($f1 * $ymax)}]
6229 if {[info exists targetid]} {
6230 if {[commitinview $targetid $curview]} {
6231 set r [rowofcommit $targetid]
6232 if {$r != $targetrow} {
6233 # Fix up the scrollregion and change the scrolling position
6234 # now that our target row has moved.
6235 set diff [expr {($r - $targetrow) * $linespc}]
6236 set targetrow $r
6237 setcanvscroll
6238 set ymax [lindex [$canv cget -scrollregion] 3]
6239 incr y0 $diff
6240 incr y1 $diff
6241 set f0 [expr {$y0 / $ymax}]
6242 set f1 [expr {$y1 / $ymax}]
6243 allcanvs yview moveto $f0
6244 $cscroll set $f0 $f1
6245 set need_redisplay 1
6247 } else {
6248 unset targetid
6252 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6253 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6254 if {$endrow >= $vrowmod($curview)} {
6255 update_arcrows $curview
6257 if {$selectedline ne {} &&
6258 $row <= $selectedline && $selectedline <= $endrow} {
6259 set targetrow $selectedline
6260 } elseif {[info exists targetid]} {
6261 set targetrow [expr {int(($row + $endrow) / 2)}]
6263 if {[info exists targetrow]} {
6264 if {$targetrow >= $numcommits} {
6265 set targetrow [expr {$numcommits - 1}]
6267 set targetid [commitonrow $targetrow]
6269 drawcommits $row $endrow
6272 proc clear_display {} {
6273 global iddrawn linesegs need_redisplay nrows_drawn
6274 global vhighlights fhighlights nhighlights rhighlights
6275 global linehtag linentag linedtag boldids boldnameids
6277 allcanvs delete all
6278 catch {unset iddrawn}
6279 catch {unset linesegs}
6280 catch {unset linehtag}
6281 catch {unset linentag}
6282 catch {unset linedtag}
6283 set boldids {}
6284 set boldnameids {}
6285 catch {unset vhighlights}
6286 catch {unset fhighlights}
6287 catch {unset nhighlights}
6288 catch {unset rhighlights}
6289 set need_redisplay 0
6290 set nrows_drawn 0
6293 proc findcrossings {id} {
6294 global rowidlist parentlist numcommits displayorder
6296 set cross {}
6297 set ccross {}
6298 foreach {s e} [rowranges $id] {
6299 if {$e >= $numcommits} {
6300 set e [expr {$numcommits - 1}]
6302 if {$e <= $s} continue
6303 for {set row $e} {[incr row -1] >= $s} {} {
6304 set x [lsearch -exact [lindex $rowidlist $row] $id]
6305 if {$x < 0} break
6306 set olds [lindex $parentlist $row]
6307 set kid [lindex $displayorder $row]
6308 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6309 if {$kidx < 0} continue
6310 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6311 foreach p $olds {
6312 set px [lsearch -exact $nextrow $p]
6313 if {$px < 0} continue
6314 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6315 if {[lsearch -exact $ccross $p] >= 0} continue
6316 if {$x == $px + ($kidx < $px? -1: 1)} {
6317 lappend ccross $p
6318 } elseif {[lsearch -exact $cross $p] < 0} {
6319 lappend cross $p
6325 return [concat $ccross {{}} $cross]
6328 proc assigncolor {id} {
6329 global colormap colors nextcolor
6330 global parents children children curview
6332 if {[info exists colormap($id)]} return
6333 set ncolors [llength $colors]
6334 if {[info exists children($curview,$id)]} {
6335 set kids $children($curview,$id)
6336 } else {
6337 set kids {}
6339 if {[llength $kids] == 1} {
6340 set child [lindex $kids 0]
6341 if {[info exists colormap($child)]
6342 && [llength $parents($curview,$child)] == 1} {
6343 set colormap($id) $colormap($child)
6344 return
6347 set badcolors {}
6348 set origbad {}
6349 foreach x [findcrossings $id] {
6350 if {$x eq {}} {
6351 # delimiter between corner crossings and other crossings
6352 if {[llength $badcolors] >= $ncolors - 1} break
6353 set origbad $badcolors
6355 if {[info exists colormap($x)]
6356 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6357 lappend badcolors $colormap($x)
6360 if {[llength $badcolors] >= $ncolors} {
6361 set badcolors $origbad
6363 set origbad $badcolors
6364 if {[llength $badcolors] < $ncolors - 1} {
6365 foreach child $kids {
6366 if {[info exists colormap($child)]
6367 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6368 lappend badcolors $colormap($child)
6370 foreach p $parents($curview,$child) {
6371 if {[info exists colormap($p)]
6372 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6373 lappend badcolors $colormap($p)
6377 if {[llength $badcolors] >= $ncolors} {
6378 set badcolors $origbad
6381 for {set i 0} {$i <= $ncolors} {incr i} {
6382 set c [lindex $colors $nextcolor]
6383 if {[incr nextcolor] >= $ncolors} {
6384 set nextcolor 0
6386 if {[lsearch -exact $badcolors $c]} break
6388 set colormap($id) $c
6391 proc bindline {t id} {
6392 global canv
6394 $canv bind $t <Enter> "lineenter %x %y $id"
6395 $canv bind $t <Motion> "linemotion %x %y $id"
6396 $canv bind $t <Leave> "lineleave $id"
6397 $canv bind $t <Button-1> "lineclick %x %y $id 1"
6400 proc graph_pane_width {} {
6401 global use_ttk
6403 if {$use_ttk} {
6404 set g [.tf.histframe.pwclist sashpos 0]
6405 } else {
6406 set g [.tf.histframe.pwclist sash coord 0]
6408 return [lindex $g 0]
6411 proc totalwidth {l font extra} {
6412 set tot 0
6413 foreach str $l {
6414 set tot [expr {$tot + [font measure $font $str] + $extra}]
6416 return $tot
6419 proc drawtags {id x xt y1} {
6420 global idtags idheads idotherrefs mainhead
6421 global linespc lthickness
6422 global canv rowtextx curview fgcolor bgcolor ctxbut
6423 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6424 global tagbgcolor tagfgcolor tagoutlinecolor
6425 global reflinecolor
6427 set marks {}
6428 set ntags 0
6429 set nheads 0
6430 set singletag 0
6431 set maxtags 3
6432 set maxtagpct 25
6433 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6434 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6435 set extra [expr {$delta + $lthickness + $linespc}]
6437 if {[info exists idtags($id)]} {
6438 set marks $idtags($id)
6439 set ntags [llength $marks]
6440 if {$ntags > $maxtags ||
6441 [totalwidth $marks mainfont $extra] > $maxwidth} {
6442 # show just a single "n tags..." tag
6443 set singletag 1
6444 if {$ntags == 1} {
6445 set marks [list "tag..."]
6446 } else {
6447 set marks [list [format "%d tags..." $ntags]]
6449 set ntags 1
6452 if {[info exists idheads($id)]} {
6453 set marks [concat $marks $idheads($id)]
6454 set nheads [llength $idheads($id)]
6456 if {[info exists idotherrefs($id)]} {
6457 set marks [concat $marks $idotherrefs($id)]
6459 if {$marks eq {}} {
6460 return $xt
6463 set yt [expr {$y1 - 0.5 * $linespc}]
6464 set yb [expr {$yt + $linespc - 1}]
6465 set xvals {}
6466 set wvals {}
6467 set i -1
6468 foreach tag $marks {
6469 incr i
6470 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6471 set wid [font measure mainfontbold $tag]
6472 } else {
6473 set wid [font measure mainfont $tag]
6475 lappend xvals $xt
6476 lappend wvals $wid
6477 set xt [expr {$xt + $wid + $extra}]
6479 set yl [expr {$y1 - $lthickness}]
6480 set t [$canv create line $x $yl [lindex $xvals end] $yl \
6481 -width $lthickness -fill $reflinecolor -tags tag.$id]
6482 $canv lower $t
6483 foreach tag $marks x $xvals wid $wvals {
6484 set tag_quoted [string map {% %%} $tag]
6485 set xl [expr {$x + $delta}]
6486 set xr [expr {$x + $delta + $wid + $lthickness}]
6487 set font mainfont
6488 if {[incr ntags -1] >= 0} {
6489 # draw a tag
6490 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6491 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6492 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6493 -tags tag.$id]
6494 if {$singletag} {
6495 set tagclick [list showtags $id 1]
6496 } else {
6497 set tagclick [list showtag $tag_quoted 1]
6499 $canv bind $t <1> $tagclick
6500 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6501 } else {
6502 # draw a head or other ref
6503 if {[incr nheads -1] >= 0} {
6504 set col $headbgcolor
6505 if {$tag eq $mainhead} {
6506 set font mainfontbold
6508 } else {
6509 set col "#ddddff"
6511 set xl [expr {$xl - $delta/2}]
6512 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6513 -width 1 -outline black -fill $col -tags tag.$id
6514 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6515 set rwid [font measure mainfont $remoteprefix]
6516 set xi [expr {$x + 1}]
6517 set yti [expr {$yt + 1}]
6518 set xri [expr {$x + $rwid}]
6519 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6520 -width 0 -fill $remotebgcolor -tags tag.$id
6523 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6524 -font $font -tags [list tag.$id text]]
6525 if {$ntags >= 0} {
6526 $canv bind $t <1> $tagclick
6527 } elseif {$nheads >= 0} {
6528 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6531 return $xt
6534 proc drawnotesign {xt y} {
6535 global linespc canv fgcolor
6537 set orad [expr {$linespc / 3}]
6538 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
6539 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6540 -fill yellow -outline $fgcolor -width 1 -tags circle]
6541 set xt [expr {$xt + $orad * 3}]
6542 return $xt
6545 proc xcoord {i level ln} {
6546 global canvx0 xspc1 xspc2
6548 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6549 if {$i > 0 && $i == $level} {
6550 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
6551 } elseif {$i > $level} {
6552 set x [expr {$x + $xspc2 - $xspc1($ln)}]
6554 return $x
6557 proc show_status {msg} {
6558 global canv fgcolor
6560 clear_display
6561 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
6562 -tags text -fill $fgcolor
6565 # Don't change the text pane cursor if it is currently the hand cursor,
6566 # showing that we are over a sha1 ID link.
6567 proc settextcursor {c} {
6568 global ctext curtextcursor
6570 if {[$ctext cget -cursor] == $curtextcursor} {
6571 $ctext config -cursor $c
6573 set curtextcursor $c
6576 proc nowbusy {what {name {}}} {
6577 global isbusy busyname statusw
6579 if {[array names isbusy] eq {}} {
6580 . config -cursor watch
6581 settextcursor watch
6583 set isbusy($what) 1
6584 set busyname($what) $name
6585 if {$name ne {}} {
6586 $statusw conf -text $name
6590 proc notbusy {what} {
6591 global isbusy maincursor textcursor busyname statusw
6593 catch {
6594 unset isbusy($what)
6595 if {$busyname($what) ne {} &&
6596 [$statusw cget -text] eq $busyname($what)} {
6597 $statusw conf -text {}
6600 if {[array names isbusy] eq {}} {
6601 . config -cursor $maincursor
6602 settextcursor $textcursor
6606 proc findmatches {f} {
6607 global findtype findstring
6608 if {$findtype == [mc "Regexp"]} {
6609 set matches [regexp -indices -all -inline $findstring $f]
6610 } else {
6611 set fs $findstring
6612 if {$findtype == [mc "IgnCase"]} {
6613 set f [string tolower $f]
6614 set fs [string tolower $fs]
6616 set matches {}
6617 set i 0
6618 set l [string length $fs]
6619 while {[set j [string first $fs $f $i]] >= 0} {
6620 lappend matches [list $j [expr {$j+$l-1}]]
6621 set i [expr {$j + $l}]
6624 return $matches
6627 proc dofind {{dirn 1} {wrap 1}} {
6628 global findstring findstartline findcurline selectedline numcommits
6629 global gdttype filehighlight fh_serial find_dirn findallowwrap
6631 if {[info exists find_dirn]} {
6632 if {$find_dirn == $dirn} return
6633 stopfinding
6635 focus .
6636 if {$findstring eq {} || $numcommits == 0} return
6637 if {$selectedline eq {}} {
6638 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
6639 } else {
6640 set findstartline $selectedline
6642 set findcurline $findstartline
6643 nowbusy finding [mc "Searching"]
6644 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
6645 after cancel do_file_hl $fh_serial
6646 do_file_hl $fh_serial
6648 set find_dirn $dirn
6649 set findallowwrap $wrap
6650 run findmore
6653 proc stopfinding {} {
6654 global find_dirn findcurline fprogcoord
6656 if {[info exists find_dirn]} {
6657 unset find_dirn
6658 unset findcurline
6659 notbusy finding
6660 set fprogcoord 0
6661 adjustprogress
6663 stopblaming
6666 proc findmore {} {
6667 global commitdata commitinfo numcommits findpattern findloc
6668 global findstartline findcurline findallowwrap
6669 global find_dirn gdttype fhighlights fprogcoord
6670 global curview varcorder vrownum varccommits vrowmod
6672 if {![info exists find_dirn]} {
6673 return 0
6675 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
6676 set l $findcurline
6677 set moretodo 0
6678 if {$find_dirn > 0} {
6679 incr l
6680 if {$l >= $numcommits} {
6681 set l 0
6683 if {$l <= $findstartline} {
6684 set lim [expr {$findstartline + 1}]
6685 } else {
6686 set lim $numcommits
6687 set moretodo $findallowwrap
6689 } else {
6690 if {$l == 0} {
6691 set l $numcommits
6693 incr l -1
6694 if {$l >= $findstartline} {
6695 set lim [expr {$findstartline - 1}]
6696 } else {
6697 set lim -1
6698 set moretodo $findallowwrap
6701 set n [expr {($lim - $l) * $find_dirn}]
6702 if {$n > 500} {
6703 set n 500
6704 set moretodo 1
6706 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
6707 update_arcrows $curview
6709 set found 0
6710 set domore 1
6711 set ai [bsearch $vrownum($curview) $l]
6712 set a [lindex $varcorder($curview) $ai]
6713 set arow [lindex $vrownum($curview) $ai]
6714 set ids [lindex $varccommits($curview,$a)]
6715 set arowend [expr {$arow + [llength $ids]}]
6716 if {$gdttype eq [mc "containing:"]} {
6717 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6718 if {$l < $arow || $l >= $arowend} {
6719 incr ai $find_dirn
6720 set a [lindex $varcorder($curview) $ai]
6721 set arow [lindex $vrownum($curview) $ai]
6722 set ids [lindex $varccommits($curview,$a)]
6723 set arowend [expr {$arow + [llength $ids]}]
6725 set id [lindex $ids [expr {$l - $arow}]]
6726 # shouldn't happen unless git log doesn't give all the commits...
6727 if {![info exists commitdata($id)] ||
6728 ![doesmatch $commitdata($id)]} {
6729 continue
6731 if {![info exists commitinfo($id)]} {
6732 getcommit $id
6734 set info $commitinfo($id)
6735 foreach f $info ty $fldtypes {
6736 if {$ty eq ""} continue
6737 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6738 [doesmatch $f]} {
6739 set found 1
6740 break
6743 if {$found} break
6745 } else {
6746 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6747 if {$l < $arow || $l >= $arowend} {
6748 incr ai $find_dirn
6749 set a [lindex $varcorder($curview) $ai]
6750 set arow [lindex $vrownum($curview) $ai]
6751 set ids [lindex $varccommits($curview,$a)]
6752 set arowend [expr {$arow + [llength $ids]}]
6754 set id [lindex $ids [expr {$l - $arow}]]
6755 if {![info exists fhighlights($id)]} {
6756 # this sets fhighlights($id) to -1
6757 askfilehighlight $l $id
6759 if {$fhighlights($id) > 0} {
6760 set found $domore
6761 break
6763 if {$fhighlights($id) < 0} {
6764 if {$domore} {
6765 set domore 0
6766 set findcurline [expr {$l - $find_dirn}]
6771 if {$found || ($domore && !$moretodo)} {
6772 unset findcurline
6773 unset find_dirn
6774 notbusy finding
6775 set fprogcoord 0
6776 adjustprogress
6777 if {$found} {
6778 findselectline $l
6779 } else {
6780 bell
6782 return 0
6784 if {!$domore} {
6785 flushhighlights
6786 } else {
6787 set findcurline [expr {$l - $find_dirn}]
6789 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
6790 if {$n < 0} {
6791 incr n $numcommits
6793 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6794 adjustprogress
6795 return $domore
6798 proc findselectline {l} {
6799 global findloc commentend ctext findcurline markingmatches gdttype
6801 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
6802 set findcurline $l
6803 selectline $l 1
6804 if {$markingmatches &&
6805 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6806 # highlight the matches in the comments
6807 set f [$ctext get 1.0 $commentend]
6808 set matches [findmatches $f]
6809 foreach match $matches {
6810 set start [lindex $match 0]
6811 set end [expr {[lindex $match 1] + 1}]
6812 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6815 drawvisible
6818 # mark the bits of a headline or author that match a find string
6819 proc markmatches {canv l str tag matches font row} {
6820 global selectedline
6822 set bbox [$canv bbox $tag]
6823 set x0 [lindex $bbox 0]
6824 set y0 [lindex $bbox 1]
6825 set y1 [lindex $bbox 3]
6826 foreach match $matches {
6827 set start [lindex $match 0]
6828 set end [lindex $match 1]
6829 if {$start > $end} continue
6830 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6831 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6832 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6833 [expr {$x0+$xlen+2}] $y1 \
6834 -outline {} -tags [list match$l matches] -fill yellow]
6835 $canv lower $t
6836 if {$row == $selectedline} {
6837 $canv raise $t secsel
6842 proc unmarkmatches {} {
6843 global markingmatches
6845 allcanvs delete matches
6846 set markingmatches 0
6847 stopfinding
6850 proc selcanvline {w x y} {
6851 global canv canvy0 ctext linespc
6852 global rowtextx
6853 set ymax [lindex [$canv cget -scrollregion] 3]
6854 if {$ymax == {}} return
6855 set yfrac [lindex [$canv yview] 0]
6856 set y [expr {$y + $yfrac * $ymax}]
6857 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
6858 if {$l < 0} {
6859 set l 0
6861 if {$w eq $canv} {
6862 set xmax [lindex [$canv cget -scrollregion] 2]
6863 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
6864 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
6866 unmarkmatches
6867 selectline $l 1
6870 proc commit_descriptor {p} {
6871 global commitinfo
6872 if {![info exists commitinfo($p)]} {
6873 getcommit $p
6875 set l "..."
6876 if {[llength $commitinfo($p)] > 1} {
6877 set l [lindex $commitinfo($p) 0]
6879 return "$p ($l)\n"
6882 # append some text to the ctext widget, and make any SHA1 ID
6883 # that we know about be a clickable link.
6884 proc appendwithlinks {text tags} {
6885 global ctext linknum curview
6887 set start [$ctext index "end - 1c"]
6888 $ctext insert end $text $tags
6889 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
6890 foreach l $links {
6891 set s [lindex $l 0]
6892 set e [lindex $l 1]
6893 set linkid [string range $text $s $e]
6894 incr e
6895 $ctext tag delete link$linknum
6896 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
6897 setlink $linkid link$linknum
6898 incr linknum
6902 proc setlink {id lk} {
6903 global curview ctext pendinglinks
6904 global linkfgcolor
6906 if {[string range $id 0 1] eq "-g"} {
6907 set id [string range $id 2 end]
6910 set known 0
6911 if {[string length $id] < 40} {
6912 set matches [longid $id]
6913 if {[llength $matches] > 0} {
6914 if {[llength $matches] > 1} return
6915 set known 1
6916 set id [lindex $matches 0]
6918 } else {
6919 set known [commitinview $id $curview]
6921 if {$known} {
6922 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
6923 $ctext tag bind $lk <1> [list selbyid $id]
6924 $ctext tag bind $lk <Enter> {linkcursor %W 1}
6925 $ctext tag bind $lk <Leave> {linkcursor %W -1}
6926 } else {
6927 lappend pendinglinks($id) $lk
6928 interestedin $id {makelink %P}
6932 proc appendshortlink {id {pre {}} {post {}}} {
6933 global ctext linknum
6935 $ctext insert end $pre
6936 $ctext tag delete link$linknum
6937 $ctext insert end [string range $id 0 7] link$linknum
6938 $ctext insert end $post
6939 setlink $id link$linknum
6940 incr linknum
6943 proc makelink {id} {
6944 global pendinglinks
6946 if {![info exists pendinglinks($id)]} return
6947 foreach lk $pendinglinks($id) {
6948 setlink $id $lk
6950 unset pendinglinks($id)
6953 proc linkcursor {w inc} {
6954 global linkentercount curtextcursor
6956 if {[incr linkentercount $inc] > 0} {
6957 $w configure -cursor hand2
6958 } else {
6959 $w configure -cursor $curtextcursor
6960 if {$linkentercount < 0} {
6961 set linkentercount 0
6966 proc viewnextline {dir} {
6967 global canv linespc
6969 $canv delete hover
6970 set ymax [lindex [$canv cget -scrollregion] 3]
6971 set wnow [$canv yview]
6972 set wtop [expr {[lindex $wnow 0] * $ymax}]
6973 set newtop [expr {$wtop + $dir * $linespc}]
6974 if {$newtop < 0} {
6975 set newtop 0
6976 } elseif {$newtop > $ymax} {
6977 set newtop $ymax
6979 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
6982 # add a list of tag or branch names at position pos
6983 # returns the number of names inserted
6984 proc appendrefs {pos ids var} {
6985 global ctext linknum curview $var maxrefs visiblerefs mainheadid
6987 if {[catch {$ctext index $pos}]} {
6988 return 0
6990 $ctext conf -state normal
6991 $ctext delete $pos "$pos lineend"
6992 set tags {}
6993 foreach id $ids {
6994 foreach tag [set $var\($id\)] {
6995 lappend tags [list $tag $id]
6999 set sep {}
7000 set tags [lsort -index 0 -decreasing $tags]
7001 set nutags 0
7003 if {[llength $tags] > $maxrefs} {
7004 # If we are displaying heads, and there are too many,
7005 # see if there are some important heads to display.
7006 # Currently that are the current head and heads listed in $visiblerefs option
7007 set itags {}
7008 if {$var eq "idheads"} {
7009 set utags {}
7010 foreach ti $tags {
7011 set hname [lindex $ti 0]
7012 set id [lindex $ti 1]
7013 if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) &&
7014 [llength $itags] < $maxrefs} {
7015 lappend itags $ti
7016 } else {
7017 lappend utags $ti
7020 set tags $utags
7022 if {$itags ne {}} {
7023 set str [mc "and many more"]
7024 set sep " "
7025 } else {
7026 set str [mc "many"]
7028 $ctext insert $pos "$str ([llength $tags])"
7029 set nutags [llength $tags]
7030 set tags $itags
7033 foreach ti $tags {
7034 set id [lindex $ti 1]
7035 set lk link$linknum
7036 incr linknum
7037 $ctext tag delete $lk
7038 $ctext insert $pos $sep
7039 $ctext insert $pos [lindex $ti 0] $lk
7040 setlink $id $lk
7041 set sep ", "
7043 $ctext tag add wwrap "$pos linestart" "$pos lineend"
7044 $ctext conf -state disabled
7045 return [expr {[llength $tags] + $nutags}]
7048 # called when we have finished computing the nearby tags
7049 proc dispneartags {delay} {
7050 global selectedline currentid showneartags tagphase
7052 if {$selectedline eq {} || !$showneartags} return
7053 after cancel dispnexttag
7054 if {$delay} {
7055 after 200 dispnexttag
7056 set tagphase -1
7057 } else {
7058 after idle dispnexttag
7059 set tagphase 0
7063 proc dispnexttag {} {
7064 global selectedline currentid showneartags tagphase ctext
7066 if {$selectedline eq {} || !$showneartags} return
7067 switch -- $tagphase {
7069 set dtags [desctags $currentid]
7070 if {$dtags ne {}} {
7071 appendrefs precedes $dtags idtags
7075 set atags [anctags $currentid]
7076 if {$atags ne {}} {
7077 appendrefs follows $atags idtags
7081 set dheads [descheads $currentid]
7082 if {$dheads ne {}} {
7083 if {[appendrefs branch $dheads idheads] > 1
7084 && [$ctext get "branch -3c"] eq "h"} {
7085 # turn "Branch" into "Branches"
7086 $ctext conf -state normal
7087 $ctext insert "branch -2c" "es"
7088 $ctext conf -state disabled
7093 if {[incr tagphase] <= 2} {
7094 after idle dispnexttag
7098 proc make_secsel {id} {
7099 global linehtag linentag linedtag canv canv2 canv3
7101 if {![info exists linehtag($id)]} return
7102 $canv delete secsel
7103 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
7104 -tags secsel -fill [$canv cget -selectbackground]]
7105 $canv lower $t
7106 $canv2 delete secsel
7107 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
7108 -tags secsel -fill [$canv2 cget -selectbackground]]
7109 $canv2 lower $t
7110 $canv3 delete secsel
7111 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
7112 -tags secsel -fill [$canv3 cget -selectbackground]]
7113 $canv3 lower $t
7116 proc make_idmark {id} {
7117 global linehtag canv fgcolor
7119 if {![info exists linehtag($id)]} return
7120 $canv delete markid
7121 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
7122 -tags markid -outline $fgcolor]
7123 $canv raise $t
7126 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
7127 global canv ctext commitinfo selectedline
7128 global canvy0 linespc parents children curview
7129 global currentid sha1entry
7130 global commentend idtags linknum
7131 global mergemax numcommits pending_select
7132 global cmitmode showneartags allcommits
7133 global targetrow targetid lastscrollrows
7134 global autoselect autosellen jump_to_here
7135 global vinlinediff
7137 catch {unset pending_select}
7138 $canv delete hover
7139 normalline
7140 unsel_reflist
7141 stopfinding
7142 if {$l < 0 || $l >= $numcommits} return
7143 set id [commitonrow $l]
7144 set targetid $id
7145 set targetrow $l
7146 set selectedline $l
7147 set currentid $id
7148 if {$lastscrollrows < $numcommits} {
7149 setcanvscroll
7152 if {$cmitmode ne "patch" && $switch_to_patch} {
7153 set cmitmode "patch"
7156 set y [expr {$canvy0 + $l * $linespc}]
7157 set ymax [lindex [$canv cget -scrollregion] 3]
7158 set ytop [expr {$y - $linespc - 1}]
7159 set ybot [expr {$y + $linespc + 1}]
7160 set wnow [$canv yview]
7161 set wtop [expr {[lindex $wnow 0] * $ymax}]
7162 set wbot [expr {[lindex $wnow 1] * $ymax}]
7163 set wh [expr {$wbot - $wtop}]
7164 set newtop $wtop
7165 if {$ytop < $wtop} {
7166 if {$ybot < $wtop} {
7167 set newtop [expr {$y - $wh / 2.0}]
7168 } else {
7169 set newtop $ytop
7170 if {$newtop > $wtop - $linespc} {
7171 set newtop [expr {$wtop - $linespc}]
7174 } elseif {$ybot > $wbot} {
7175 if {$ytop > $wbot} {
7176 set newtop [expr {$y - $wh / 2.0}]
7177 } else {
7178 set newtop [expr {$ybot - $wh}]
7179 if {$newtop < $wtop + $linespc} {
7180 set newtop [expr {$wtop + $linespc}]
7184 if {$newtop != $wtop} {
7185 if {$newtop < 0} {
7186 set newtop 0
7188 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7189 drawvisible
7192 make_secsel $id
7194 if {$isnew} {
7195 addtohistory [list selbyid $id 0] savecmitpos
7198 $sha1entry delete 0 end
7199 $sha1entry insert 0 $id
7200 if {$autoselect} {
7201 $sha1entry selection range 0 $autosellen
7203 rhighlight_sel $id
7205 $ctext conf -state normal
7206 clear_ctext
7207 set linknum 0
7208 if {![info exists commitinfo($id)]} {
7209 getcommit $id
7211 set info $commitinfo($id)
7212 set date [formatdate [lindex $info 2]]
7213 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
7214 set date [formatdate [lindex $info 4]]
7215 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
7216 if {[info exists idtags($id)]} {
7217 $ctext insert end [mc "Tags:"]
7218 foreach tag $idtags($id) {
7219 $ctext insert end " $tag"
7221 $ctext insert end "\n"
7224 set headers {}
7225 set olds $parents($curview,$id)
7226 if {[llength $olds] > 1} {
7227 set np 0
7228 foreach p $olds {
7229 if {$np >= $mergemax} {
7230 set tag mmax
7231 } else {
7232 set tag m$np
7234 $ctext insert end "[mc "Parent"]: " $tag
7235 appendwithlinks [commit_descriptor $p] {}
7236 incr np
7238 } else {
7239 foreach p $olds {
7240 append headers "[mc "Parent"]: [commit_descriptor $p]"
7244 foreach c $children($curview,$id) {
7245 append headers "[mc "Child"]: [commit_descriptor $c]"
7248 # make anything that looks like a SHA1 ID be a clickable link
7249 appendwithlinks $headers {}
7250 if {$showneartags} {
7251 if {![info exists allcommits]} {
7252 getallcommits
7254 $ctext insert end "[mc "Branch"]: "
7255 $ctext mark set branch "end -1c"
7256 $ctext mark gravity branch left
7257 $ctext insert end "\n[mc "Follows"]: "
7258 $ctext mark set follows "end -1c"
7259 $ctext mark gravity follows left
7260 $ctext insert end "\n[mc "Precedes"]: "
7261 $ctext mark set precedes "end -1c"
7262 $ctext mark gravity precedes left
7263 $ctext insert end "\n"
7264 dispneartags 1
7266 $ctext insert end "\n"
7267 set comment [lindex $info 5]
7268 if {[string first "\r" $comment] >= 0} {
7269 set comment [string map {"\r" "\n "} $comment]
7271 appendwithlinks $comment {comment}
7273 $ctext tag remove found 1.0 end
7274 $ctext conf -state disabled
7275 set commentend [$ctext index "end - 1c"]
7277 set jump_to_here $desired_loc
7278 init_flist [mc "Comments"]
7279 if {$cmitmode eq "tree"} {
7280 gettree $id
7281 } elseif {$vinlinediff($curview) == 1} {
7282 showinlinediff $id
7283 } elseif {[llength $olds] <= 1} {
7284 startdiff $id
7285 } else {
7286 mergediff $id
7290 proc selfirstline {} {
7291 unmarkmatches
7292 selectline 0 1
7295 proc sellastline {} {
7296 global numcommits
7297 unmarkmatches
7298 set l [expr {$numcommits - 1}]
7299 selectline $l 1
7302 proc selnextline {dir} {
7303 global selectedline
7304 focus .
7305 if {$selectedline eq {}} return
7306 set l [expr {$selectedline + $dir}]
7307 unmarkmatches
7308 selectline $l 1
7311 proc selnextpage {dir} {
7312 global canv linespc selectedline numcommits
7314 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7315 if {$lpp < 1} {
7316 set lpp 1
7318 allcanvs yview scroll [expr {$dir * $lpp}] units
7319 drawvisible
7320 if {$selectedline eq {}} return
7321 set l [expr {$selectedline + $dir * $lpp}]
7322 if {$l < 0} {
7323 set l 0
7324 } elseif {$l >= $numcommits} {
7325 set l [expr $numcommits - 1]
7327 unmarkmatches
7328 selectline $l 1
7331 proc unselectline {} {
7332 global selectedline currentid
7334 set selectedline {}
7335 catch {unset currentid}
7336 allcanvs delete secsel
7337 rhighlight_none
7340 proc reselectline {} {
7341 global selectedline
7343 if {$selectedline ne {}} {
7344 selectline $selectedline 0
7348 proc addtohistory {cmd {saveproc {}}} {
7349 global history historyindex curview
7351 unset_posvars
7352 save_position
7353 set elt [list $curview $cmd $saveproc {}]
7354 if {$historyindex > 0
7355 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7356 return
7359 if {$historyindex < [llength $history]} {
7360 set history [lreplace $history $historyindex end $elt]
7361 } else {
7362 lappend history $elt
7364 incr historyindex
7365 if {$historyindex > 1} {
7366 .tf.bar.leftbut conf -state normal
7367 } else {
7368 .tf.bar.leftbut conf -state disabled
7370 .tf.bar.rightbut conf -state disabled
7373 # save the scrolling position of the diff display pane
7374 proc save_position {} {
7375 global historyindex history
7377 if {$historyindex < 1} return
7378 set hi [expr {$historyindex - 1}]
7379 set fn [lindex $history $hi 2]
7380 if {$fn ne {}} {
7381 lset history $hi 3 [eval $fn]
7385 proc unset_posvars {} {
7386 global last_posvars
7388 if {[info exists last_posvars]} {
7389 foreach {var val} $last_posvars {
7390 global $var
7391 catch {unset $var}
7393 unset last_posvars
7397 proc godo {elt} {
7398 global curview last_posvars
7400 set view [lindex $elt 0]
7401 set cmd [lindex $elt 1]
7402 set pv [lindex $elt 3]
7403 if {$curview != $view} {
7404 showview $view
7406 unset_posvars
7407 foreach {var val} $pv {
7408 global $var
7409 set $var $val
7411 set last_posvars $pv
7412 eval $cmd
7415 proc goback {} {
7416 global history historyindex
7417 focus .
7419 if {$historyindex > 1} {
7420 save_position
7421 incr historyindex -1
7422 godo [lindex $history [expr {$historyindex - 1}]]
7423 .tf.bar.rightbut conf -state normal
7425 if {$historyindex <= 1} {
7426 .tf.bar.leftbut conf -state disabled
7430 proc goforw {} {
7431 global history historyindex
7432 focus .
7434 if {$historyindex < [llength $history]} {
7435 save_position
7436 set cmd [lindex $history $historyindex]
7437 incr historyindex
7438 godo $cmd
7439 .tf.bar.leftbut conf -state normal
7441 if {$historyindex >= [llength $history]} {
7442 .tf.bar.rightbut conf -state disabled
7446 proc go_to_parent {i} {
7447 global parents curview targetid
7448 set ps $parents($curview,$targetid)
7449 if {[llength $ps] >= $i} {
7450 selbyid [lindex $ps [expr $i - 1]]
7454 proc gettree {id} {
7455 global treefilelist treeidlist diffids diffmergeid treepending
7456 global nullid nullid2
7458 set diffids $id
7459 catch {unset diffmergeid}
7460 if {![info exists treefilelist($id)]} {
7461 if {![info exists treepending]} {
7462 if {$id eq $nullid} {
7463 set cmd [list | git ls-files]
7464 } elseif {$id eq $nullid2} {
7465 set cmd [list | git ls-files --stage -t]
7466 } else {
7467 set cmd [list | git ls-tree -r $id]
7469 if {[catch {set gtf [open $cmd r]}]} {
7470 return
7472 set treepending $id
7473 set treefilelist($id) {}
7474 set treeidlist($id) {}
7475 fconfigure $gtf -blocking 0 -encoding binary
7476 filerun $gtf [list gettreeline $gtf $id]
7478 } else {
7479 setfilelist $id
7483 proc gettreeline {gtf id} {
7484 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
7486 set nl 0
7487 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
7488 if {$diffids eq $nullid} {
7489 set fname $line
7490 } else {
7491 set i [string first "\t" $line]
7492 if {$i < 0} continue
7493 set fname [string range $line [expr {$i+1}] end]
7494 set line [string range $line 0 [expr {$i-1}]]
7495 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7496 set sha1 [lindex $line 2]
7497 lappend treeidlist($id) $sha1
7499 if {[string index $fname 0] eq "\""} {
7500 set fname [lindex $fname 0]
7502 set fname [encoding convertfrom $fname]
7503 lappend treefilelist($id) $fname
7505 if {![eof $gtf]} {
7506 return [expr {$nl >= 1000? 2: 1}]
7508 close $gtf
7509 unset treepending
7510 if {$cmitmode ne "tree"} {
7511 if {![info exists diffmergeid]} {
7512 gettreediffs $diffids
7514 } elseif {$id ne $diffids} {
7515 gettree $diffids
7516 } else {
7517 setfilelist $id
7519 return 0
7522 proc showfile {f} {
7523 global treefilelist treeidlist diffids nullid nullid2
7524 global ctext_file_names ctext_file_lines
7525 global ctext commentend
7527 set i [lsearch -exact $treefilelist($diffids) $f]
7528 if {$i < 0} {
7529 puts "oops, $f not in list for id $diffids"
7530 return
7532 if {$diffids eq $nullid} {
7533 if {[catch {set bf [open $f r]} err]} {
7534 puts "oops, can't read $f: $err"
7535 return
7537 } else {
7538 set blob [lindex $treeidlist($diffids) $i]
7539 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7540 puts "oops, error reading blob $blob: $err"
7541 return
7544 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
7545 filerun $bf [list getblobline $bf $diffids]
7546 $ctext config -state normal
7547 clear_ctext $commentend
7548 lappend ctext_file_names $f
7549 lappend ctext_file_lines [lindex [split $commentend "."] 0]
7550 $ctext insert end "\n"
7551 $ctext insert end "$f\n" filesep
7552 $ctext config -state disabled
7553 $ctext yview $commentend
7554 settabs 0
7557 proc getblobline {bf id} {
7558 global diffids cmitmode ctext
7560 if {$id ne $diffids || $cmitmode ne "tree"} {
7561 catch {close $bf}
7562 return 0
7564 $ctext config -state normal
7565 set nl 0
7566 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
7567 $ctext insert end "$line\n"
7569 if {[eof $bf]} {
7570 global jump_to_here ctext_file_names commentend
7572 # delete last newline
7573 $ctext delete "end - 2c" "end - 1c"
7574 close $bf
7575 if {$jump_to_here ne {} &&
7576 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7577 set lnum [expr {[lindex $jump_to_here 1] +
7578 [lindex [split $commentend .] 0]}]
7579 mark_ctext_line $lnum
7581 $ctext config -state disabled
7582 return 0
7584 $ctext config -state disabled
7585 return [expr {$nl >= 1000? 2: 1}]
7588 proc mark_ctext_line {lnum} {
7589 global ctext markbgcolor
7591 $ctext tag delete omark
7592 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
7593 $ctext tag conf omark -background $markbgcolor
7594 $ctext see $lnum.0
7597 proc mergediff {id} {
7598 global diffmergeid
7599 global diffids treediffs
7600 global parents curview
7602 set diffmergeid $id
7603 set diffids $id
7604 set treediffs($id) {}
7605 set np [llength $parents($curview,$id)]
7606 settabs $np
7607 getblobdiffs $id
7610 proc startdiff {ids} {
7611 global treediffs diffids treepending diffmergeid nullid nullid2
7613 settabs 1
7614 set diffids $ids
7615 catch {unset diffmergeid}
7616 if {![info exists treediffs($ids)] ||
7617 [lsearch -exact $ids $nullid] >= 0 ||
7618 [lsearch -exact $ids $nullid2] >= 0} {
7619 if {![info exists treepending]} {
7620 gettreediffs $ids
7622 } else {
7623 addtocflist $ids
7627 proc showinlinediff {ids} {
7628 global commitinfo commitdata ctext
7629 global treediffs
7631 set info $commitinfo($ids)
7632 set diff [lindex $info 7]
7633 set difflines [split $diff "\n"]
7635 initblobdiffvars
7636 set treediff {}
7638 set inhdr 0
7639 foreach line $difflines {
7640 if {![string compare -length 5 "diff " $line]} {
7641 set inhdr 1
7642 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7643 # offset also accounts for the b/ prefix
7644 lappend treediff [string range $line 6 end]
7645 set inhdr 0
7649 set treediffs($ids) $treediff
7650 add_flist $treediff
7652 $ctext conf -state normal
7653 foreach line $difflines {
7654 parseblobdiffline $ids $line
7656 maybe_scroll_ctext 1
7657 $ctext conf -state disabled
7660 # If the filename (name) is under any of the passed filter paths
7661 # then return true to include the file in the listing.
7662 proc path_filter {filter name} {
7663 set worktree [gitworktree]
7664 foreach p $filter {
7665 set fq_p [file normalize $p]
7666 set fq_n [file normalize [file join $worktree $name]]
7667 if {[string match [file normalize $fq_p]* $fq_n]} {
7668 return 1
7671 return 0
7674 proc addtocflist {ids} {
7675 global treediffs
7677 add_flist $treediffs($ids)
7678 getblobdiffs $ids
7681 proc diffcmd {ids flags} {
7682 global log_showroot nullid nullid2 git_version
7684 set i [lsearch -exact $ids $nullid]
7685 set j [lsearch -exact $ids $nullid2]
7686 if {$i >= 0} {
7687 if {[llength $ids] > 1 && $j < 0} {
7688 # comparing working directory with some specific revision
7689 set cmd [concat | git diff-index $flags]
7690 if {$i == 0} {
7691 lappend cmd -R [lindex $ids 1]
7692 } else {
7693 lappend cmd [lindex $ids 0]
7695 } else {
7696 # comparing working directory with index
7697 set cmd [concat | git diff-files $flags]
7698 if {$j == 1} {
7699 lappend cmd -R
7702 } elseif {$j >= 0} {
7703 if {[package vcompare $git_version "1.7.2"] >= 0} {
7704 set flags "$flags --ignore-submodules=dirty"
7706 set cmd [concat | git diff-index --cached $flags]
7707 if {[llength $ids] > 1} {
7708 # comparing index with specific revision
7709 if {$j == 0} {
7710 lappend cmd -R [lindex $ids 1]
7711 } else {
7712 lappend cmd [lindex $ids 0]
7714 } else {
7715 # comparing index with HEAD
7716 lappend cmd HEAD
7718 } else {
7719 if {$log_showroot} {
7720 lappend flags --root
7722 set cmd [concat | git diff-tree -r $flags $ids]
7724 return $cmd
7727 proc gettreediffs {ids} {
7728 global treediff treepending limitdiffs vfilelimit curview
7730 set cmd [diffcmd $ids {--no-commit-id}]
7731 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7732 set cmd [concat $cmd -- $vfilelimit($curview)]
7734 if {[catch {set gdtf [open $cmd r]}]} return
7736 set treepending $ids
7737 set treediff {}
7738 fconfigure $gdtf -blocking 0 -encoding binary
7739 filerun $gdtf [list gettreediffline $gdtf $ids]
7742 proc gettreediffline {gdtf ids} {
7743 global treediff treediffs treepending diffids diffmergeid
7744 global cmitmode vfilelimit curview limitdiffs perfile_attrs
7746 set nr 0
7747 set sublist {}
7748 set max 1000
7749 if {$perfile_attrs} {
7750 # cache_gitattr is slow, and even slower on win32 where we
7751 # have to invoke it for only about 30 paths at a time
7752 set max 500
7753 if {[tk windowingsystem] == "win32"} {
7754 set max 120
7757 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
7758 set i [string first "\t" $line]
7759 if {$i >= 0} {
7760 set file [string range $line [expr {$i+1}] end]
7761 if {[string index $file 0] eq "\""} {
7762 set file [lindex $file 0]
7764 set file [encoding convertfrom $file]
7765 if {$file ne [lindex $treediff end]} {
7766 lappend treediff $file
7767 lappend sublist $file
7771 if {$perfile_attrs} {
7772 cache_gitattr encoding $sublist
7774 if {![eof $gdtf]} {
7775 return [expr {$nr >= $max? 2: 1}]
7777 close $gdtf
7778 set treediffs($ids) $treediff
7779 unset treepending
7780 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
7781 gettree $diffids
7782 } elseif {$ids != $diffids} {
7783 if {![info exists diffmergeid]} {
7784 gettreediffs $diffids
7786 } else {
7787 addtocflist $ids
7789 return 0
7792 # empty string or positive integer
7793 proc diffcontextvalidate {v} {
7794 return [regexp {^(|[1-9][0-9]*)$} $v]
7797 proc diffcontextchange {n1 n2 op} {
7798 global diffcontextstring diffcontext
7800 if {[string is integer -strict $diffcontextstring]} {
7801 if {$diffcontextstring >= 0} {
7802 set diffcontext $diffcontextstring
7803 reselectline
7808 proc changeignorespace {} {
7809 reselectline
7812 proc changeworddiff {name ix op} {
7813 reselectline
7816 proc initblobdiffvars {} {
7817 global diffencoding targetline diffnparents
7818 global diffinhdr currdiffsubmod diffseehere
7819 set targetline {}
7820 set diffnparents 0
7821 set diffinhdr 0
7822 set diffencoding [get_path_encoding {}]
7823 set currdiffsubmod ""
7824 set diffseehere -1
7827 proc getblobdiffs {ids} {
7828 global blobdifffd diffids env
7829 global treediffs
7830 global diffcontext
7831 global ignorespace
7832 global worddiff
7833 global limitdiffs vfilelimit curview
7834 global git_version
7836 set textconv {}
7837 if {[package vcompare $git_version "1.6.1"] >= 0} {
7838 set textconv "--textconv"
7840 set submodule {}
7841 if {[package vcompare $git_version "1.6.6"] >= 0} {
7842 set submodule "--submodule"
7844 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
7845 if {$ignorespace} {
7846 append cmd " -w"
7848 if {$worddiff ne [mc "Line diff"]} {
7849 append cmd " --word-diff=porcelain"
7851 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7852 set cmd [concat $cmd -- $vfilelimit($curview)]
7854 if {[catch {set bdf [open $cmd r]} err]} {
7855 error_popup [mc "Error getting diffs: %s" $err]
7856 return
7858 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7859 set blobdifffd($ids) $bdf
7860 initblobdiffvars
7861 filerun $bdf [list getblobdiffline $bdf $diffids]
7864 proc savecmitpos {} {
7865 global ctext cmitmode
7867 if {$cmitmode eq "tree"} {
7868 return {}
7870 return [list target_scrollpos [$ctext index @0,0]]
7873 proc savectextpos {} {
7874 global ctext
7876 return [list target_scrollpos [$ctext index @0,0]]
7879 proc maybe_scroll_ctext {ateof} {
7880 global ctext target_scrollpos
7882 if {![info exists target_scrollpos]} return
7883 if {!$ateof} {
7884 set nlines [expr {[winfo height $ctext]
7885 / [font metrics textfont -linespace]}]
7886 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
7888 $ctext yview $target_scrollpos
7889 unset target_scrollpos
7892 proc setinlist {var i val} {
7893 global $var
7895 while {[llength [set $var]] < $i} {
7896 lappend $var {}
7898 if {[llength [set $var]] == $i} {
7899 lappend $var $val
7900 } else {
7901 lset $var $i $val
7905 proc makediffhdr {fname ids} {
7906 global ctext curdiffstart treediffs diffencoding
7907 global ctext_file_names jump_to_here targetline diffline
7909 set fname [encoding convertfrom $fname]
7910 set diffencoding [get_path_encoding $fname]
7911 set i [lsearch -exact $treediffs($ids) $fname]
7912 if {$i >= 0} {
7913 setinlist difffilestart $i $curdiffstart
7915 lset ctext_file_names end $fname
7916 set l [expr {(78 - [string length $fname]) / 2}]
7917 set pad [string range "----------------------------------------" 1 $l]
7918 $ctext insert $curdiffstart "$pad $fname $pad" filesep
7919 set targetline {}
7920 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
7921 set targetline [lindex $jump_to_here 1]
7923 set diffline 0
7926 proc blobdiffmaybeseehere {ateof} {
7927 global diffseehere
7928 if {$diffseehere >= 0} {
7929 mark_ctext_line [lindex [split $diffseehere .] 0]
7931 maybe_scroll_ctext $ateof
7934 proc getblobdiffline {bdf ids} {
7935 global diffids blobdifffd
7936 global ctext
7938 set nr 0
7939 $ctext conf -state normal
7940 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
7941 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7942 catch {close $bdf}
7943 return 0
7945 parseblobdiffline $ids $line
7947 $ctext conf -state disabled
7948 blobdiffmaybeseehere [eof $bdf]
7949 if {[eof $bdf]} {
7950 catch {close $bdf}
7951 return 0
7953 return [expr {$nr >= 1000? 2: 1}]
7956 proc parseblobdiffline {ids line} {
7957 global ctext curdiffstart
7958 global diffnexthead diffnextnote difffilestart
7959 global ctext_file_names ctext_file_lines
7960 global diffinhdr treediffs mergemax diffnparents
7961 global diffencoding jump_to_here targetline diffline currdiffsubmod
7962 global worddiff diffseehere
7964 if {![string compare -length 5 "diff " $line]} {
7965 if {![regexp {^diff (--cc|--git) } $line m type]} {
7966 set line [encoding convertfrom $line]
7967 $ctext insert end "$line\n" hunksep
7968 continue
7970 # start of a new file
7971 set diffinhdr 1
7972 $ctext insert end "\n"
7973 set curdiffstart [$ctext index "end - 1c"]
7974 lappend ctext_file_names ""
7975 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
7976 $ctext insert end "\n" filesep
7978 if {$type eq "--cc"} {
7979 # start of a new file in a merge diff
7980 set fname [string range $line 10 end]
7981 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
7982 lappend treediffs($ids) $fname
7983 add_flist [list $fname]
7986 } else {
7987 set line [string range $line 11 end]
7988 # If the name hasn't changed the length will be odd,
7989 # the middle char will be a space, and the two bits either
7990 # side will be a/name and b/name, or "a/name" and "b/name".
7991 # If the name has changed we'll get "rename from" and
7992 # "rename to" or "copy from" and "copy to" lines following
7993 # this, and we'll use them to get the filenames.
7994 # This complexity is necessary because spaces in the
7995 # filename(s) don't get escaped.
7996 set l [string length $line]
7997 set i [expr {$l / 2}]
7998 if {!(($l & 1) && [string index $line $i] eq " " &&
7999 [string range $line 2 [expr {$i - 1}]] eq \
8000 [string range $line [expr {$i + 3}] end])} {
8001 return
8003 # unescape if quoted and chop off the a/ from the front
8004 if {[string index $line 0] eq "\""} {
8005 set fname [string range [lindex $line 0] 2 end]
8006 } else {
8007 set fname [string range $line 2 [expr {$i - 1}]]
8010 makediffhdr $fname $ids
8012 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
8013 set fname [encoding convertfrom [string range $line 16 end]]
8014 $ctext insert end "\n"
8015 set curdiffstart [$ctext index "end - 1c"]
8016 lappend ctext_file_names $fname
8017 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8018 $ctext insert end "$line\n" filesep
8019 set i [lsearch -exact $treediffs($ids) $fname]
8020 if {$i >= 0} {
8021 setinlist difffilestart $i $curdiffstart
8024 } elseif {![string compare -length 2 "@@" $line]} {
8025 regexp {^@@+} $line ats
8026 set line [encoding convertfrom $diffencoding $line]
8027 $ctext insert end "$line\n" hunksep
8028 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8029 set diffline $nl
8031 set diffnparents [expr {[string length $ats] - 1}]
8032 set diffinhdr 0
8034 } elseif {![string compare -length 10 "Submodule " $line]} {
8035 # start of a new submodule
8036 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8037 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8038 } else {
8039 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8041 if {$currdiffsubmod != $fname} {
8042 $ctext insert end "\n"; # Add newline after commit message
8044 set curdiffstart [$ctext index "end - 1c"]
8045 lappend ctext_file_names ""
8046 if {$currdiffsubmod != $fname} {
8047 lappend ctext_file_lines $fname
8048 makediffhdr $fname $ids
8049 set currdiffsubmod $fname
8050 $ctext insert end "\n$line\n" filesep
8051 } else {
8052 $ctext insert end "$line\n" filesep
8054 } elseif {![string compare -length 3 " >" $line]} {
8055 set $currdiffsubmod ""
8056 set line [encoding convertfrom $diffencoding $line]
8057 $ctext insert end "$line\n" dresult
8058 } elseif {![string compare -length 3 " <" $line]} {
8059 set $currdiffsubmod ""
8060 set line [encoding convertfrom $diffencoding $line]
8061 $ctext insert end "$line\n" d0
8062 } elseif {$diffinhdr} {
8063 if {![string compare -length 12 "rename from " $line]} {
8064 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8065 if {[string index $fname 0] eq "\""} {
8066 set fname [lindex $fname 0]
8068 set fname [encoding convertfrom $fname]
8069 set i [lsearch -exact $treediffs($ids) $fname]
8070 if {$i >= 0} {
8071 setinlist difffilestart $i $curdiffstart
8073 } elseif {![string compare -length 10 $line "rename to "] ||
8074 ![string compare -length 8 $line "copy to "]} {
8075 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8076 if {[string index $fname 0] eq "\""} {
8077 set fname [lindex $fname 0]
8079 makediffhdr $fname $ids
8080 } elseif {[string compare -length 3 $line "---"] == 0} {
8081 # do nothing
8082 return
8083 } elseif {[string compare -length 3 $line "+++"] == 0} {
8084 set diffinhdr 0
8085 return
8087 $ctext insert end "$line\n" filesep
8089 } else {
8090 set line [string map {\x1A ^Z} \
8091 [encoding convertfrom $diffencoding $line]]
8092 # parse the prefix - one ' ', '-' or '+' for each parent
8093 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8094 set tag [expr {$diffnparents > 1? "m": "d"}]
8095 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8096 set words_pre_markup ""
8097 set words_post_markup ""
8098 if {[string trim $prefix " -+"] eq {}} {
8099 # prefix only has " ", "-" and "+" in it: normal diff line
8100 set num [string first "-" $prefix]
8101 if {$dowords} {
8102 set line [string range $line 1 end]
8104 if {$num >= 0} {
8105 # removed line, first parent with line is $num
8106 if {$num >= $mergemax} {
8107 set num "max"
8109 if {$dowords && $worddiff eq [mc "Markup words"]} {
8110 $ctext insert end "\[-$line-\]" $tag$num
8111 } else {
8112 $ctext insert end "$line" $tag$num
8114 if {!$dowords} {
8115 $ctext insert end "\n" $tag$num
8117 } else {
8118 set tags {}
8119 if {[string first "+" $prefix] >= 0} {
8120 # added line
8121 lappend tags ${tag}result
8122 if {$diffnparents > 1} {
8123 set num [string first " " $prefix]
8124 if {$num >= 0} {
8125 if {$num >= $mergemax} {
8126 set num "max"
8128 lappend tags m$num
8131 set words_pre_markup "{+"
8132 set words_post_markup "+}"
8134 if {$targetline ne {}} {
8135 if {$diffline == $targetline} {
8136 set diffseehere [$ctext index "end - 1 chars"]
8137 set targetline {}
8138 } else {
8139 incr diffline
8142 if {$dowords && $worddiff eq [mc "Markup words"]} {
8143 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8144 } else {
8145 $ctext insert end "$line" $tags
8147 if {!$dowords} {
8148 $ctext insert end "\n" $tags
8151 } elseif {$dowords && $prefix eq "~"} {
8152 $ctext insert end "\n" {}
8153 } else {
8154 # "\ No newline at end of file",
8155 # or something else we don't recognize
8156 $ctext insert end "$line\n" hunksep
8161 proc changediffdisp {} {
8162 global ctext diffelide
8164 $ctext tag conf d0 -elide [lindex $diffelide 0]
8165 $ctext tag conf dresult -elide [lindex $diffelide 1]
8168 proc highlightfile {cline} {
8169 global cflist cflist_top
8171 if {![info exists cflist_top]} return
8173 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8174 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8175 $cflist see $cline.0
8176 set cflist_top $cline
8179 proc highlightfile_for_scrollpos {topidx} {
8180 global cmitmode difffilestart
8182 if {$cmitmode eq "tree"} return
8183 if {![info exists difffilestart]} return
8185 set top [lindex [split $topidx .] 0]
8186 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
8187 highlightfile 0
8188 } else {
8189 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
8193 proc prevfile {} {
8194 global difffilestart ctext cmitmode
8196 if {$cmitmode eq "tree"} return
8197 set prev 0.0
8198 set here [$ctext index @0,0]
8199 foreach loc $difffilestart {
8200 if {[$ctext compare $loc >= $here]} {
8201 $ctext yview $prev
8202 return
8204 set prev $loc
8206 $ctext yview $prev
8209 proc nextfile {} {
8210 global difffilestart ctext cmitmode
8212 if {$cmitmode eq "tree"} return
8213 set here [$ctext index @0,0]
8214 foreach loc $difffilestart {
8215 if {[$ctext compare $loc > $here]} {
8216 $ctext yview $loc
8217 return
8222 proc clear_ctext {{first 1.0}} {
8223 global ctext smarktop smarkbot
8224 global ctext_file_names ctext_file_lines
8225 global pendinglinks
8227 set l [lindex [split $first .] 0]
8228 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
8229 set smarktop $l
8231 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
8232 set smarkbot $l
8234 $ctext delete $first end
8235 if {$first eq "1.0"} {
8236 catch {unset pendinglinks}
8238 set ctext_file_names {}
8239 set ctext_file_lines {}
8242 proc settabs {{firstab {}}} {
8243 global firsttabstop tabstop ctext have_tk85
8245 if {$firstab ne {} && $have_tk85} {
8246 set firsttabstop $firstab
8248 set w [font measure textfont "0"]
8249 if {$firsttabstop != 0} {
8250 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8251 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
8252 } elseif {$have_tk85 || $tabstop != 8} {
8253 $ctext conf -tabs [expr {$tabstop * $w}]
8254 } else {
8255 $ctext conf -tabs {}
8259 proc incrsearch {name ix op} {
8260 global ctext searchstring searchdirn
8262 if {[catch {$ctext index anchor}]} {
8263 # no anchor set, use start of selection, or of visible area
8264 set sel [$ctext tag ranges sel]
8265 if {$sel ne {}} {
8266 $ctext mark set anchor [lindex $sel 0]
8267 } elseif {$searchdirn eq "-forwards"} {
8268 $ctext mark set anchor @0,0
8269 } else {
8270 $ctext mark set anchor @0,[winfo height $ctext]
8273 if {$searchstring ne {}} {
8274 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8275 if {$here ne {}} {
8276 $ctext see $here
8277 set mend "$here + $mlen c"
8278 $ctext tag remove sel 1.0 end
8279 $ctext tag add sel $here $mend
8280 suppress_highlighting_file_for_current_scrollpos
8281 highlightfile_for_scrollpos $here
8284 rehighlight_search_results
8287 proc dosearch {} {
8288 global sstring ctext searchstring searchdirn
8290 focus $sstring
8291 $sstring icursor end
8292 set searchdirn -forwards
8293 if {$searchstring ne {}} {
8294 set sel [$ctext tag ranges sel]
8295 if {$sel ne {}} {
8296 set start "[lindex $sel 0] + 1c"
8297 } elseif {[catch {set start [$ctext index anchor]}]} {
8298 set start "@0,0"
8300 set match [$ctext search -count mlen -- $searchstring $start]
8301 $ctext tag remove sel 1.0 end
8302 if {$match eq {}} {
8303 bell
8304 return
8306 $ctext see $match
8307 suppress_highlighting_file_for_current_scrollpos
8308 highlightfile_for_scrollpos $match
8309 set mend "$match + $mlen c"
8310 $ctext tag add sel $match $mend
8311 $ctext mark unset anchor
8312 rehighlight_search_results
8316 proc dosearchback {} {
8317 global sstring ctext searchstring searchdirn
8319 focus $sstring
8320 $sstring icursor end
8321 set searchdirn -backwards
8322 if {$searchstring ne {}} {
8323 set sel [$ctext tag ranges sel]
8324 if {$sel ne {}} {
8325 set start [lindex $sel 0]
8326 } elseif {[catch {set start [$ctext index anchor]}]} {
8327 set start @0,[winfo height $ctext]
8329 set match [$ctext search -backwards -count ml -- $searchstring $start]
8330 $ctext tag remove sel 1.0 end
8331 if {$match eq {}} {
8332 bell
8333 return
8335 $ctext see $match
8336 suppress_highlighting_file_for_current_scrollpos
8337 highlightfile_for_scrollpos $match
8338 set mend "$match + $ml c"
8339 $ctext tag add sel $match $mend
8340 $ctext mark unset anchor
8341 rehighlight_search_results
8345 proc rehighlight_search_results {} {
8346 global ctext searchstring
8348 $ctext tag remove found 1.0 end
8349 $ctext tag remove currentsearchhit 1.0 end
8351 if {$searchstring ne {}} {
8352 searchmarkvisible 1
8356 proc searchmark {first last} {
8357 global ctext searchstring
8359 set sel [$ctext tag ranges sel]
8361 set mend $first.0
8362 while {1} {
8363 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8364 if {$match eq {}} break
8365 set mend "$match + $mlen c"
8366 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8367 $ctext tag add currentsearchhit $match $mend
8368 } else {
8369 $ctext tag add found $match $mend
8374 proc searchmarkvisible {doall} {
8375 global ctext smarktop smarkbot
8377 set topline [lindex [split [$ctext index @0,0] .] 0]
8378 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8379 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
8380 # no overlap with previous
8381 searchmark $topline $botline
8382 set smarktop $topline
8383 set smarkbot $botline
8384 } else {
8385 if {$topline < $smarktop} {
8386 searchmark $topline [expr {$smarktop-1}]
8387 set smarktop $topline
8389 if {$botline > $smarkbot} {
8390 searchmark [expr {$smarkbot+1}] $botline
8391 set smarkbot $botline
8396 proc suppress_highlighting_file_for_current_scrollpos {} {
8397 global ctext suppress_highlighting_file_for_this_scrollpos
8399 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8402 proc scrolltext {f0 f1} {
8403 global searchstring cmitmode ctext
8404 global suppress_highlighting_file_for_this_scrollpos
8406 set topidx [$ctext index @0,0]
8407 if {![info exists suppress_highlighting_file_for_this_scrollpos]
8408 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8409 highlightfile_for_scrollpos $topidx
8412 catch {unset suppress_highlighting_file_for_this_scrollpos}
8414 .bleft.bottom.sb set $f0 $f1
8415 if {$searchstring ne {}} {
8416 searchmarkvisible 0
8420 proc setcoords {} {
8421 global linespc charspc canvx0 canvy0
8422 global xspc1 xspc2 lthickness
8424 set linespc [font metrics mainfont -linespace]
8425 set charspc [font measure mainfont "m"]
8426 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8427 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
8428 set lthickness [expr {int($linespc / 9) + 1}]
8429 set xspc1(0) $linespc
8430 set xspc2 $linespc
8433 proc redisplay {} {
8434 global canv
8435 global selectedline
8437 set ymax [lindex [$canv cget -scrollregion] 3]
8438 if {$ymax eq {} || $ymax == 0} return
8439 set span [$canv yview]
8440 clear_display
8441 setcanvscroll
8442 allcanvs yview moveto [lindex $span 0]
8443 drawvisible
8444 if {$selectedline ne {}} {
8445 selectline $selectedline 0
8446 allcanvs yview moveto [lindex $span 0]
8450 proc parsefont {f n} {
8451 global fontattr
8453 set fontattr($f,family) [lindex $n 0]
8454 set s [lindex $n 1]
8455 if {$s eq {} || $s == 0} {
8456 set s 10
8457 } elseif {$s < 0} {
8458 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
8460 set fontattr($f,size) $s
8461 set fontattr($f,weight) normal
8462 set fontattr($f,slant) roman
8463 foreach style [lrange $n 2 end] {
8464 switch -- $style {
8465 "normal" -
8466 "bold" {set fontattr($f,weight) $style}
8467 "roman" -
8468 "italic" {set fontattr($f,slant) $style}
8473 proc fontflags {f {isbold 0}} {
8474 global fontattr
8476 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
8477 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8478 -slant $fontattr($f,slant)]
8481 proc fontname {f} {
8482 global fontattr
8484 set n [list $fontattr($f,family) $fontattr($f,size)]
8485 if {$fontattr($f,weight) eq "bold"} {
8486 lappend n "bold"
8488 if {$fontattr($f,slant) eq "italic"} {
8489 lappend n "italic"
8491 return $n
8494 proc incrfont {inc} {
8495 global mainfont textfont ctext canv cflist showrefstop
8496 global stopped entries fontattr
8498 unmarkmatches
8499 set s $fontattr(mainfont,size)
8500 incr s $inc
8501 if {$s < 1} {
8502 set s 1
8504 set fontattr(mainfont,size) $s
8505 font config mainfont -size $s
8506 font config mainfontbold -size $s
8507 set mainfont [fontname mainfont]
8508 set s $fontattr(textfont,size)
8509 incr s $inc
8510 if {$s < 1} {
8511 set s 1
8513 set fontattr(textfont,size) $s
8514 font config textfont -size $s
8515 font config textfontbold -size $s
8516 set textfont [fontname textfont]
8517 setcoords
8518 settabs
8519 redisplay
8522 proc clearsha1 {} {
8523 global sha1entry sha1string
8524 if {[string length $sha1string] == 40} {
8525 $sha1entry delete 0 end
8529 proc sha1change {n1 n2 op} {
8530 global sha1string currentid sha1but
8531 if {$sha1string == {}
8532 || ([info exists currentid] && $sha1string == $currentid)} {
8533 set state disabled
8534 } else {
8535 set state normal
8537 if {[$sha1but cget -state] == $state} return
8538 if {$state == "normal"} {
8539 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
8540 } else {
8541 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
8545 proc gotocommit {} {
8546 global sha1string tagids headids curview varcid
8548 if {$sha1string == {}
8549 || ([info exists currentid] && $sha1string == $currentid)} return
8550 if {[info exists tagids($sha1string)]} {
8551 set id $tagids($sha1string)
8552 } elseif {[info exists headids($sha1string)]} {
8553 set id $headids($sha1string)
8554 } else {
8555 set id [string tolower $sha1string]
8556 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8557 set matches [longid $id]
8558 if {$matches ne {}} {
8559 if {[llength $matches] > 1} {
8560 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8561 return
8563 set id [lindex $matches 0]
8565 } else {
8566 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8567 error_popup [mc "Revision %s is not known" $sha1string]
8568 return
8572 if {[commitinview $id $curview]} {
8573 selectline [rowofcommit $id] 1
8574 return
8576 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
8577 set msg [mc "SHA1 id %s is not known" $sha1string]
8578 } else {
8579 set msg [mc "Revision %s is not in the current view" $sha1string]
8581 error_popup $msg
8584 proc lineenter {x y id} {
8585 global hoverx hovery hoverid hovertimer
8586 global commitinfo canv
8588 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8589 set hoverx $x
8590 set hovery $y
8591 set hoverid $id
8592 if {[info exists hovertimer]} {
8593 after cancel $hovertimer
8595 set hovertimer [after 500 linehover]
8596 $canv delete hover
8599 proc linemotion {x y id} {
8600 global hoverx hovery hoverid hovertimer
8602 if {[info exists hoverid] && $id == $hoverid} {
8603 set hoverx $x
8604 set hovery $y
8605 if {[info exists hovertimer]} {
8606 after cancel $hovertimer
8608 set hovertimer [after 500 linehover]
8612 proc lineleave {id} {
8613 global hoverid hovertimer canv
8615 if {[info exists hoverid] && $id == $hoverid} {
8616 $canv delete hover
8617 if {[info exists hovertimer]} {
8618 after cancel $hovertimer
8619 unset hovertimer
8621 unset hoverid
8625 proc linehover {} {
8626 global hoverx hovery hoverid hovertimer
8627 global canv linespc lthickness
8628 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8630 global commitinfo
8632 set text [lindex $commitinfo($hoverid) 0]
8633 set ymax [lindex [$canv cget -scrollregion] 3]
8634 if {$ymax == {}} return
8635 set yfrac [lindex [$canv yview] 0]
8636 set x [expr {$hoverx + 2 * $linespc}]
8637 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8638 set x0 [expr {$x - 2 * $lthickness}]
8639 set y0 [expr {$y - 2 * $lthickness}]
8640 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
8641 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8642 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
8643 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8644 -width 1 -tags hover]
8645 $canv raise $t
8646 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
8647 -font mainfont -fill $linehoverfgcolor]
8648 $canv raise $t
8651 proc clickisonarrow {id y} {
8652 global lthickness
8654 set ranges [rowranges $id]
8655 set thresh [expr {2 * $lthickness + 6}]
8656 set n [expr {[llength $ranges] - 1}]
8657 for {set i 1} {$i < $n} {incr i} {
8658 set row [lindex $ranges $i]
8659 if {abs([yc $row] - $y) < $thresh} {
8660 return $i
8663 return {}
8666 proc arrowjump {id n y} {
8667 global canv
8669 # 1 <-> 2, 3 <-> 4, etc...
8670 set n [expr {(($n - 1) ^ 1) + 1}]
8671 set row [lindex [rowranges $id] $n]
8672 set yt [yc $row]
8673 set ymax [lindex [$canv cget -scrollregion] 3]
8674 if {$ymax eq {} || $ymax <= 0} return
8675 set view [$canv yview]
8676 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8677 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8678 if {$yfrac < 0} {
8679 set yfrac 0
8681 allcanvs yview moveto $yfrac
8684 proc lineclick {x y id isnew} {
8685 global ctext commitinfo children canv thickerline curview
8687 if {![info exists commitinfo($id)] && ![getcommit $id]} return
8688 unmarkmatches
8689 unselectline
8690 normalline
8691 $canv delete hover
8692 # draw this line thicker than normal
8693 set thickerline $id
8694 drawlines $id
8695 if {$isnew} {
8696 set ymax [lindex [$canv cget -scrollregion] 3]
8697 if {$ymax eq {}} return
8698 set yfrac [lindex [$canv yview] 0]
8699 set y [expr {$y + $yfrac * $ymax}]
8701 set dirn [clickisonarrow $id $y]
8702 if {$dirn ne {}} {
8703 arrowjump $id $dirn $y
8704 return
8707 if {$isnew} {
8708 addtohistory [list lineclick $x $y $id 0] savectextpos
8710 # fill the details pane with info about this line
8711 $ctext conf -state normal
8712 clear_ctext
8713 settabs 0
8714 $ctext insert end "[mc "Parent"]:\t"
8715 $ctext insert end $id link0
8716 setlink $id link0
8717 set info $commitinfo($id)
8718 $ctext insert end "\n\t[lindex $info 0]\n"
8719 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
8720 set date [formatdate [lindex $info 2]]
8721 $ctext insert end "\t[mc "Date"]:\t$date\n"
8722 set kids $children($curview,$id)
8723 if {$kids ne {}} {
8724 $ctext insert end "\n[mc "Children"]:"
8725 set i 0
8726 foreach child $kids {
8727 incr i
8728 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8729 set info $commitinfo($child)
8730 $ctext insert end "\n\t"
8731 $ctext insert end $child link$i
8732 setlink $child link$i
8733 $ctext insert end "\n\t[lindex $info 0]"
8734 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8735 set date [formatdate [lindex $info 2]]
8736 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8739 maybe_scroll_ctext 1
8740 $ctext conf -state disabled
8741 init_flist {}
8744 proc normalline {} {
8745 global thickerline
8746 if {[info exists thickerline]} {
8747 set id $thickerline
8748 unset thickerline
8749 drawlines $id
8753 proc selbyid {id {isnew 1}} {
8754 global curview
8755 if {[commitinview $id $curview]} {
8756 selectline [rowofcommit $id] $isnew
8760 proc mstime {} {
8761 global startmstime
8762 if {![info exists startmstime]} {
8763 set startmstime [clock clicks -milliseconds]
8765 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8768 proc rowmenu {x y id} {
8769 global rowctxmenu selectedline rowmenuid curview
8770 global nullid nullid2 fakerowmenu mainhead markedid
8772 stopfinding
8773 set rowmenuid $id
8774 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
8775 set state disabled
8776 } else {
8777 set state normal
8779 if {[info exists markedid] && $markedid ne $id} {
8780 set mstate normal
8781 } else {
8782 set mstate disabled
8784 if {$id ne $nullid && $id ne $nullid2} {
8785 set menu $rowctxmenu
8786 if {$mainhead ne {}} {
8787 $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal
8788 } else {
8789 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8791 $menu entryconfigure 9 -state $mstate
8792 $menu entryconfigure 10 -state $mstate
8793 $menu entryconfigure 11 -state $mstate
8794 } else {
8795 set menu $fakerowmenu
8797 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8798 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8799 $menu entryconfigure [mca "Make patch"] -state $state
8800 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8801 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
8802 tk_popup $menu $x $y
8805 proc markhere {} {
8806 global rowmenuid markedid canv
8808 set markedid $rowmenuid
8809 make_idmark $markedid
8812 proc gotomark {} {
8813 global markedid
8815 if {[info exists markedid]} {
8816 selbyid $markedid
8820 proc replace_by_kids {l r} {
8821 global curview children
8823 set id [commitonrow $r]
8824 set l [lreplace $l 0 0]
8825 foreach kid $children($curview,$id) {
8826 lappend l [rowofcommit $kid]
8828 return [lsort -integer -decreasing -unique $l]
8831 proc find_common_desc {} {
8832 global markedid rowmenuid curview children
8834 if {![info exists markedid]} return
8835 if {![commitinview $markedid $curview] ||
8836 ![commitinview $rowmenuid $curview]} return
8837 #set t1 [clock clicks -milliseconds]
8838 set l1 [list [rowofcommit $markedid]]
8839 set l2 [list [rowofcommit $rowmenuid]]
8840 while 1 {
8841 set r1 [lindex $l1 0]
8842 set r2 [lindex $l2 0]
8843 if {$r1 eq {} || $r2 eq {}} break
8844 if {$r1 == $r2} {
8845 selectline $r1 1
8846 break
8848 if {$r1 > $r2} {
8849 set l1 [replace_by_kids $l1 $r1]
8850 } else {
8851 set l2 [replace_by_kids $l2 $r2]
8854 #set t2 [clock clicks -milliseconds]
8855 #puts "took [expr {$t2-$t1}]ms"
8858 proc compare_commits {} {
8859 global markedid rowmenuid curview children
8861 if {![info exists markedid]} return
8862 if {![commitinview $markedid $curview]} return
8863 addtohistory [list do_cmp_commits $markedid $rowmenuid]
8864 do_cmp_commits $markedid $rowmenuid
8867 proc getpatchid {id} {
8868 global patchids
8870 if {![info exists patchids($id)]} {
8871 set cmd [diffcmd [list $id] {-p --root}]
8872 # trim off the initial "|"
8873 set cmd [lrange $cmd 1 end]
8874 if {[catch {
8875 set x [eval exec $cmd | git patch-id]
8876 set patchids($id) [lindex $x 0]
8877 }]} {
8878 set patchids($id) "error"
8881 return $patchids($id)
8884 proc do_cmp_commits {a b} {
8885 global ctext curview parents children patchids commitinfo
8887 $ctext conf -state normal
8888 clear_ctext
8889 init_flist {}
8890 for {set i 0} {$i < 100} {incr i} {
8891 set skipa 0
8892 set skipb 0
8893 if {[llength $parents($curview,$a)] > 1} {
8894 appendshortlink $a [mc "Skipping merge commit "] "\n"
8895 set skipa 1
8896 } else {
8897 set patcha [getpatchid $a]
8899 if {[llength $parents($curview,$b)] > 1} {
8900 appendshortlink $b [mc "Skipping merge commit "] "\n"
8901 set skipb 1
8902 } else {
8903 set patchb [getpatchid $b]
8905 if {!$skipa && !$skipb} {
8906 set heada [lindex $commitinfo($a) 0]
8907 set headb [lindex $commitinfo($b) 0]
8908 if {$patcha eq "error"} {
8909 appendshortlink $a [mc "Error getting patch ID for "] \
8910 [mc " - stopping\n"]
8911 break
8913 if {$patchb eq "error"} {
8914 appendshortlink $b [mc "Error getting patch ID for "] \
8915 [mc " - stopping\n"]
8916 break
8918 if {$patcha eq $patchb} {
8919 if {$heada eq $headb} {
8920 appendshortlink $a [mc "Commit "]
8921 appendshortlink $b " == " " $heada\n"
8922 } else {
8923 appendshortlink $a [mc "Commit "] " $heada\n"
8924 appendshortlink $b [mc " is the same patch as\n "] \
8925 " $headb\n"
8927 set skipa 1
8928 set skipb 1
8929 } else {
8930 $ctext insert end "\n"
8931 appendshortlink $a [mc "Commit "] " $heada\n"
8932 appendshortlink $b [mc " differs from\n "] \
8933 " $headb\n"
8934 $ctext insert end [mc "Diff of commits:\n\n"]
8935 $ctext conf -state disabled
8936 update
8937 diffcommits $a $b
8938 return
8941 if {$skipa} {
8942 set kids [real_children $curview,$a]
8943 if {[llength $kids] != 1} {
8944 $ctext insert end "\n"
8945 appendshortlink $a [mc "Commit "] \
8946 [mc " has %s children - stopping\n" [llength $kids]]
8947 break
8949 set a [lindex $kids 0]
8951 if {$skipb} {
8952 set kids [real_children $curview,$b]
8953 if {[llength $kids] != 1} {
8954 appendshortlink $b [mc "Commit "] \
8955 [mc " has %s children - stopping\n" [llength $kids]]
8956 break
8958 set b [lindex $kids 0]
8961 $ctext conf -state disabled
8964 proc diffcommits {a b} {
8965 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8967 set tmpdir [gitknewtmpdir]
8968 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8969 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8970 if {[catch {
8971 exec git diff-tree -p --pretty $a >$fna
8972 exec git diff-tree -p --pretty $b >$fnb
8973 } err]} {
8974 error_popup [mc "Error writing commit to file: %s" $err]
8975 return
8977 if {[catch {
8978 set fd [open "| diff -U$diffcontext $fna $fnb" r]
8979 } err]} {
8980 error_popup [mc "Error diffing commits: %s" $err]
8981 return
8983 set diffids [list commits $a $b]
8984 set blobdifffd($diffids) $fd
8985 set diffinhdr 0
8986 set currdiffsubmod ""
8987 filerun $fd [list getblobdiffline $fd $diffids]
8990 proc diffvssel {dirn} {
8991 global rowmenuid selectedline
8993 if {$selectedline eq {}} return
8994 if {$dirn} {
8995 set oldid [commitonrow $selectedline]
8996 set newid $rowmenuid
8997 } else {
8998 set oldid $rowmenuid
8999 set newid [commitonrow $selectedline]
9001 addtohistory [list doseldiff $oldid $newid] savectextpos
9002 doseldiff $oldid $newid
9005 proc diffvsmark {dirn} {
9006 global rowmenuid markedid
9008 if {![info exists markedid]} return
9009 if {$dirn} {
9010 set oldid $markedid
9011 set newid $rowmenuid
9012 } else {
9013 set oldid $rowmenuid
9014 set newid $markedid
9016 addtohistory [list doseldiff $oldid $newid] savectextpos
9017 doseldiff $oldid $newid
9020 proc doseldiff {oldid newid} {
9021 global ctext
9022 global commitinfo
9024 $ctext conf -state normal
9025 clear_ctext
9026 init_flist [mc "Top"]
9027 $ctext insert end "[mc "From"] "
9028 $ctext insert end $oldid link0
9029 setlink $oldid link0
9030 $ctext insert end "\n "
9031 $ctext insert end [lindex $commitinfo($oldid) 0]
9032 $ctext insert end "\n\n[mc "To"] "
9033 $ctext insert end $newid link1
9034 setlink $newid link1
9035 $ctext insert end "\n "
9036 $ctext insert end [lindex $commitinfo($newid) 0]
9037 $ctext insert end "\n"
9038 $ctext conf -state disabled
9039 $ctext tag remove found 1.0 end
9040 startdiff [list $oldid $newid]
9043 proc mkpatch {} {
9044 global rowmenuid currentid commitinfo patchtop patchnum NS
9046 if {![info exists currentid]} return
9047 set oldid $currentid
9048 set oldhead [lindex $commitinfo($oldid) 0]
9049 set newid $rowmenuid
9050 set newhead [lindex $commitinfo($newid) 0]
9051 set top .patch
9052 set patchtop $top
9053 catch {destroy $top}
9054 ttk_toplevel $top
9055 make_transient $top .
9056 ${NS}::label $top.title -text [mc "Generate patch"]
9057 grid $top.title - -pady 10
9058 ${NS}::label $top.from -text [mc "From:"]
9059 ${NS}::entry $top.fromsha1 -width 40
9060 $top.fromsha1 insert 0 $oldid
9061 $top.fromsha1 conf -state readonly
9062 grid $top.from $top.fromsha1 -sticky w
9063 ${NS}::entry $top.fromhead -width 60
9064 $top.fromhead insert 0 $oldhead
9065 $top.fromhead conf -state readonly
9066 grid x $top.fromhead -sticky w
9067 ${NS}::label $top.to -text [mc "To:"]
9068 ${NS}::entry $top.tosha1 -width 40
9069 $top.tosha1 insert 0 $newid
9070 $top.tosha1 conf -state readonly
9071 grid $top.to $top.tosha1 -sticky w
9072 ${NS}::entry $top.tohead -width 60
9073 $top.tohead insert 0 $newhead
9074 $top.tohead conf -state readonly
9075 grid x $top.tohead -sticky w
9076 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9077 grid $top.rev x -pady 10 -padx 5
9078 ${NS}::label $top.flab -text [mc "Output file:"]
9079 ${NS}::entry $top.fname -width 60
9080 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9081 incr patchnum
9082 grid $top.flab $top.fname -sticky w
9083 ${NS}::frame $top.buts
9084 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9085 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
9086 bind $top <Key-Return> mkpatchgo
9087 bind $top <Key-Escape> mkpatchcan
9088 grid $top.buts.gen $top.buts.can
9089 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9090 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9091 grid $top.buts - -pady 10 -sticky ew
9092 focus $top.fname
9095 proc mkpatchrev {} {
9096 global patchtop
9098 set oldid [$patchtop.fromsha1 get]
9099 set oldhead [$patchtop.fromhead get]
9100 set newid [$patchtop.tosha1 get]
9101 set newhead [$patchtop.tohead get]
9102 foreach e [list fromsha1 fromhead tosha1 tohead] \
9103 v [list $newid $newhead $oldid $oldhead] {
9104 $patchtop.$e conf -state normal
9105 $patchtop.$e delete 0 end
9106 $patchtop.$e insert 0 $v
9107 $patchtop.$e conf -state readonly
9111 proc mkpatchgo {} {
9112 global patchtop nullid nullid2
9114 set oldid [$patchtop.fromsha1 get]
9115 set newid [$patchtop.tosha1 get]
9116 set fname [$patchtop.fname get]
9117 set cmd [diffcmd [list $oldid $newid] -p]
9118 # trim off the initial "|"
9119 set cmd [lrange $cmd 1 end]
9120 lappend cmd >$fname &
9121 if {[catch {eval exec $cmd} err]} {
9122 error_popup "[mc "Error creating patch:"] $err" $patchtop
9124 catch {destroy $patchtop}
9125 unset patchtop
9128 proc mkpatchcan {} {
9129 global patchtop
9131 catch {destroy $patchtop}
9132 unset patchtop
9135 proc mktag {} {
9136 global rowmenuid mktagtop commitinfo NS
9138 set top .maketag
9139 set mktagtop $top
9140 catch {destroy $top}
9141 ttk_toplevel $top
9142 make_transient $top .
9143 ${NS}::label $top.title -text [mc "Create tag"]
9144 grid $top.title - -pady 10
9145 ${NS}::label $top.id -text [mc "ID:"]
9146 ${NS}::entry $top.sha1 -width 40
9147 $top.sha1 insert 0 $rowmenuid
9148 $top.sha1 conf -state readonly
9149 grid $top.id $top.sha1 -sticky w
9150 ${NS}::entry $top.head -width 60
9151 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9152 $top.head conf -state readonly
9153 grid x $top.head -sticky w
9154 ${NS}::label $top.tlab -text [mc "Tag name:"]
9155 ${NS}::entry $top.tag -width 60
9156 grid $top.tlab $top.tag -sticky w
9157 ${NS}::label $top.op -text [mc "Tag message is optional"]
9158 grid $top.op -columnspan 2 -sticky we
9159 ${NS}::label $top.mlab -text [mc "Tag message:"]
9160 ${NS}::entry $top.msg -width 60
9161 grid $top.mlab $top.msg -sticky w
9162 ${NS}::frame $top.buts
9163 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9164 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
9165 bind $top <Key-Return> mktaggo
9166 bind $top <Key-Escape> mktagcan
9167 grid $top.buts.gen $top.buts.can
9168 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9169 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9170 grid $top.buts - -pady 10 -sticky ew
9171 focus $top.tag
9174 proc domktag {} {
9175 global mktagtop env tagids idtags
9177 set id [$mktagtop.sha1 get]
9178 set tag [$mktagtop.tag get]
9179 set msg [$mktagtop.msg get]
9180 if {$tag == {}} {
9181 error_popup [mc "No tag name specified"] $mktagtop
9182 return 0
9184 if {[info exists tagids($tag)]} {
9185 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9186 return 0
9188 if {[catch {
9189 if {$msg != {}} {
9190 exec git tag -a -m $msg $tag $id
9191 } else {
9192 exec git tag $tag $id
9194 } err]} {
9195 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9196 return 0
9199 set tagids($tag) $id
9200 lappend idtags($id) $tag
9201 redrawtags $id
9202 addedtag $id
9203 dispneartags 0
9204 run refill_reflist
9205 return 1
9208 proc redrawtags {id} {
9209 global canv linehtag idpos currentid curview cmitlisted markedid
9210 global canvxmax iddrawn circleitem mainheadid circlecolors
9211 global mainheadcirclecolor
9213 if {![commitinview $id $curview]} return
9214 if {![info exists iddrawn($id)]} return
9215 set row [rowofcommit $id]
9216 if {$id eq $mainheadid} {
9217 set ofill $mainheadcirclecolor
9218 } else {
9219 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
9221 $canv itemconf $circleitem($row) -fill $ofill
9222 $canv delete tag.$id
9223 set xt [eval drawtags $id $idpos($id)]
9224 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9225 set text [$canv itemcget $linehtag($id) -text]
9226 set font [$canv itemcget $linehtag($id) -font]
9227 set xr [expr {$xt + [font measure $font $text]}]
9228 if {$xr > $canvxmax} {
9229 set canvxmax $xr
9230 setcanvscroll
9232 if {[info exists currentid] && $currentid == $id} {
9233 make_secsel $id
9235 if {[info exists markedid] && $markedid eq $id} {
9236 make_idmark $id
9240 proc mktagcan {} {
9241 global mktagtop
9243 catch {destroy $mktagtop}
9244 unset mktagtop
9247 proc mktaggo {} {
9248 if {![domktag]} return
9249 mktagcan
9252 proc writecommit {} {
9253 global rowmenuid wrcomtop commitinfo wrcomcmd NS
9255 set top .writecommit
9256 set wrcomtop $top
9257 catch {destroy $top}
9258 ttk_toplevel $top
9259 make_transient $top .
9260 ${NS}::label $top.title -text [mc "Write commit to file"]
9261 grid $top.title - -pady 10
9262 ${NS}::label $top.id -text [mc "ID:"]
9263 ${NS}::entry $top.sha1 -width 40
9264 $top.sha1 insert 0 $rowmenuid
9265 $top.sha1 conf -state readonly
9266 grid $top.id $top.sha1 -sticky w
9267 ${NS}::entry $top.head -width 60
9268 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9269 $top.head conf -state readonly
9270 grid x $top.head -sticky w
9271 ${NS}::label $top.clab -text [mc "Command:"]
9272 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
9273 grid $top.clab $top.cmd -sticky w -pady 10
9274 ${NS}::label $top.flab -text [mc "Output file:"]
9275 ${NS}::entry $top.fname -width 60
9276 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9277 grid $top.flab $top.fname -sticky w
9278 ${NS}::frame $top.buts
9279 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9280 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
9281 bind $top <Key-Return> wrcomgo
9282 bind $top <Key-Escape> wrcomcan
9283 grid $top.buts.gen $top.buts.can
9284 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9285 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9286 grid $top.buts - -pady 10 -sticky ew
9287 focus $top.fname
9290 proc wrcomgo {} {
9291 global wrcomtop
9293 set id [$wrcomtop.sha1 get]
9294 set cmd "echo $id | [$wrcomtop.cmd get]"
9295 set fname [$wrcomtop.fname get]
9296 if {[catch {exec sh -c $cmd >$fname &} err]} {
9297 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
9299 catch {destroy $wrcomtop}
9300 unset wrcomtop
9303 proc wrcomcan {} {
9304 global wrcomtop
9306 catch {destroy $wrcomtop}
9307 unset wrcomtop
9310 proc mkbranch {} {
9311 global rowmenuid mkbrtop NS
9313 set top .makebranch
9314 catch {destroy $top}
9315 ttk_toplevel $top
9316 make_transient $top .
9317 ${NS}::label $top.title -text [mc "Create new branch"]
9318 grid $top.title - -pady 10
9319 ${NS}::label $top.id -text [mc "ID:"]
9320 ${NS}::entry $top.sha1 -width 40
9321 $top.sha1 insert 0 $rowmenuid
9322 $top.sha1 conf -state readonly
9323 grid $top.id $top.sha1 -sticky w
9324 ${NS}::label $top.nlab -text [mc "Name:"]
9325 ${NS}::entry $top.name -width 40
9326 grid $top.nlab $top.name -sticky w
9327 ${NS}::frame $top.buts
9328 ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top]
9329 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9330 bind $top <Key-Return> [list mkbrgo $top]
9331 bind $top <Key-Escape> "catch {destroy $top}"
9332 grid $top.buts.go $top.buts.can
9333 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9334 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9335 grid $top.buts - -pady 10 -sticky ew
9336 focus $top.name
9339 proc mkbrgo {top} {
9340 global headids idheads
9342 set name [$top.name get]
9343 set id [$top.sha1 get]
9344 set cmdargs {}
9345 set old_id {}
9346 if {$name eq {}} {
9347 error_popup [mc "Please specify a name for the new branch"] $top
9348 return
9350 if {[info exists headids($name)]} {
9351 if {![confirm_popup [mc \
9352 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9353 return
9355 set old_id $headids($name)
9356 lappend cmdargs -f
9358 catch {destroy $top}
9359 lappend cmdargs $name $id
9360 nowbusy newbranch
9361 update
9362 if {[catch {
9363 eval exec git branch $cmdargs
9364 } err]} {
9365 notbusy newbranch
9366 error_popup $err
9367 } else {
9368 notbusy newbranch
9369 if {$old_id ne {}} {
9370 movehead $id $name
9371 movedhead $id $name
9372 redrawtags $old_id
9373 redrawtags $id
9374 } else {
9375 set headids($name) $id
9376 lappend idheads($id) $name
9377 addedhead $id $name
9378 redrawtags $id
9380 dispneartags 0
9381 run refill_reflist
9385 proc exec_citool {tool_args {baseid {}}} {
9386 global commitinfo env
9388 set save_env [array get env GIT_AUTHOR_*]
9390 if {$baseid ne {}} {
9391 if {![info exists commitinfo($baseid)]} {
9392 getcommit $baseid
9394 set author [lindex $commitinfo($baseid) 1]
9395 set date [lindex $commitinfo($baseid) 2]
9396 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9397 $author author name email]
9398 && $date ne {}} {
9399 set env(GIT_AUTHOR_NAME) $name
9400 set env(GIT_AUTHOR_EMAIL) $email
9401 set env(GIT_AUTHOR_DATE) $date
9405 eval exec git citool $tool_args &
9407 array unset env GIT_AUTHOR_*
9408 array set env $save_env
9411 proc cherrypick {} {
9412 global rowmenuid curview
9413 global mainhead mainheadid
9414 global gitdir
9416 set oldhead [exec git rev-parse HEAD]
9417 set dheads [descheads $rowmenuid]
9418 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
9419 set ok [confirm_popup [mc "Commit %s is already\
9420 included in branch %s -- really re-apply it?" \
9421 [string range $rowmenuid 0 7] $mainhead]]
9422 if {!$ok} return
9424 nowbusy cherrypick [mc "Cherry-picking"]
9425 update
9426 # Unfortunately git-cherry-pick writes stuff to stderr even when
9427 # no error occurs, and exec takes that as an indication of error...
9428 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
9429 notbusy cherrypick
9430 if {[regexp -line \
9431 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9432 $err msg fname]} {
9433 error_popup [mc "Cherry-pick failed because of local changes\
9434 to file '%s'.\nPlease commit, reset or stash\
9435 your changes and try again." $fname]
9436 } elseif {[regexp -line \
9437 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9438 $err]} {
9439 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9440 conflict.\nDo you wish to run git citool to\
9441 resolve it?"]]} {
9442 # Force citool to read MERGE_MSG
9443 file delete [file join $gitdir "GITGUI_MSG"]
9444 exec_citool {} $rowmenuid
9446 } else {
9447 error_popup $err
9449 run updatecommits
9450 return
9452 set newhead [exec git rev-parse HEAD]
9453 if {$newhead eq $oldhead} {
9454 notbusy cherrypick
9455 error_popup [mc "No changes committed"]
9456 return
9458 addnewchild $newhead $oldhead
9459 if {[commitinview $oldhead $curview]} {
9460 # XXX this isn't right if we have a path limit...
9461 insertrow $newhead $oldhead $curview
9462 if {$mainhead ne {}} {
9463 movehead $newhead $mainhead
9464 movedhead $newhead $mainhead
9466 set mainheadid $newhead
9467 redrawtags $oldhead
9468 redrawtags $newhead
9469 selbyid $newhead
9471 notbusy cherrypick
9474 proc revert {} {
9475 global rowmenuid curview
9476 global mainhead mainheadid
9477 global gitdir
9479 set oldhead [exec git rev-parse HEAD]
9480 set dheads [descheads $rowmenuid]
9481 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9482 set ok [confirm_popup [mc "Commit %s is not\
9483 included in branch %s -- really revert it?" \
9484 [string range $rowmenuid 0 7] $mainhead]]
9485 if {!$ok} return
9487 nowbusy revert [mc "Reverting"]
9488 update
9490 if [catch {exec git revert --no-edit $rowmenuid} err] {
9491 notbusy revert
9492 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9493 $err match files] {
9494 regsub {\n( |\t)+} $files "\n" files
9495 error_popup [mc "Revert failed because of local changes to\
9496 the following files:%s Please commit, reset or stash \
9497 your changes and try again." $files]
9498 } elseif [regexp {error: could not revert} $err] {
9499 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9500 Do you wish to run git citool to resolve it?"]] {
9501 # Force citool to read MERGE_MSG
9502 file delete [file join $gitdir "GITGUI_MSG"]
9503 exec_citool {} $rowmenuid
9505 } else { error_popup $err }
9506 run updatecommits
9507 return
9510 set newhead [exec git rev-parse HEAD]
9511 if { $newhead eq $oldhead } {
9512 notbusy revert
9513 error_popup [mc "No changes committed"]
9514 return
9517 addnewchild $newhead $oldhead
9519 if [commitinview $oldhead $curview] {
9520 # XXX this isn't right if we have a path limit...
9521 insertrow $newhead $oldhead $curview
9522 if {$mainhead ne {}} {
9523 movehead $newhead $mainhead
9524 movedhead $newhead $mainhead
9526 set mainheadid $newhead
9527 redrawtags $oldhead
9528 redrawtags $newhead
9529 selbyid $newhead
9532 notbusy revert
9535 proc resethead {} {
9536 global mainhead rowmenuid confirm_ok resettype NS
9538 set confirm_ok 0
9539 set w ".confirmreset"
9540 ttk_toplevel $w
9541 make_transient $w .
9542 wm title $w [mc "Confirm reset"]
9543 ${NS}::label $w.m -text \
9544 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
9545 pack $w.m -side top -fill x -padx 20 -pady 20
9546 ${NS}::labelframe $w.f -text [mc "Reset type:"]
9547 set resettype mixed
9548 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
9549 -text [mc "Soft: Leave working tree and index untouched"]
9550 grid $w.f.soft -sticky w
9551 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
9552 -text [mc "Mixed: Leave working tree untouched, reset index"]
9553 grid $w.f.mixed -sticky w
9554 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
9555 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
9556 grid $w.f.hard -sticky w
9557 pack $w.f -side top -fill x -padx 4
9558 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
9559 pack $w.ok -side left -fill x -padx 20 -pady 20
9560 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
9561 bind $w <Key-Escape> [list destroy $w]
9562 pack $w.cancel -side right -fill x -padx 20 -pady 20
9563 bind $w <Visibility> "grab $w; focus $w"
9564 tkwait window $w
9565 if {!$confirm_ok} return
9566 if {[catch {set fd [open \
9567 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9568 error_popup $err
9569 } else {
9570 dohidelocalchanges
9571 filerun $fd [list readresetstat $fd]
9572 nowbusy reset [mc "Resetting"]
9573 selbyid $rowmenuid
9577 proc readresetstat {fd} {
9578 global mainhead mainheadid showlocalchanges rprogcoord
9580 if {[gets $fd line] >= 0} {
9581 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9582 set rprogcoord [expr {1.0 * $m / $n}]
9583 adjustprogress
9585 return 1
9587 set rprogcoord 0
9588 adjustprogress
9589 notbusy reset
9590 if {[catch {close $fd} err]} {
9591 error_popup $err
9593 set oldhead $mainheadid
9594 set newhead [exec git rev-parse HEAD]
9595 if {$newhead ne $oldhead} {
9596 movehead $newhead $mainhead
9597 movedhead $newhead $mainhead
9598 set mainheadid $newhead
9599 redrawtags $oldhead
9600 redrawtags $newhead
9602 if {$showlocalchanges} {
9603 doshowlocalchanges
9605 return 0
9608 # context menu for a head
9609 proc headmenu {x y id head} {
9610 global headmenuid headmenuhead headctxmenu mainhead
9612 stopfinding
9613 set headmenuid $id
9614 set headmenuhead $head
9615 set state normal
9616 if {[string match "remotes/*" $head]} {
9617 set state disabled
9619 if {$head eq $mainhead} {
9620 set state disabled
9622 $headctxmenu entryconfigure 0 -state $state
9623 $headctxmenu entryconfigure 1 -state $state
9624 tk_popup $headctxmenu $x $y
9627 proc cobranch {} {
9628 global headmenuid headmenuhead headids
9629 global showlocalchanges
9631 # check the tree is clean first??
9632 nowbusy checkout [mc "Checking out"]
9633 update
9634 dohidelocalchanges
9635 if {[catch {
9636 set fd [open [list | git checkout $headmenuhead 2>@1] r]
9637 } err]} {
9638 notbusy checkout
9639 error_popup $err
9640 if {$showlocalchanges} {
9641 dodiffindex
9643 } else {
9644 filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid]
9648 proc readcheckoutstat {fd newhead newheadid} {
9649 global mainhead mainheadid headids showlocalchanges progresscoords
9650 global viewmainheadid curview
9652 if {[gets $fd line] >= 0} {
9653 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9654 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9655 adjustprogress
9657 return 1
9659 set progresscoords {0 0}
9660 adjustprogress
9661 notbusy checkout
9662 if {[catch {close $fd} err]} {
9663 error_popup $err
9665 set oldmainid $mainheadid
9666 set mainhead $newhead
9667 set mainheadid $newheadid
9668 set viewmainheadid($curview) $newheadid
9669 redrawtags $oldmainid
9670 redrawtags $newheadid
9671 selbyid $newheadid
9672 if {$showlocalchanges} {
9673 dodiffindex
9677 proc rmbranch {} {
9678 global headmenuid headmenuhead mainhead
9679 global idheads
9681 set head $headmenuhead
9682 set id $headmenuid
9683 # this check shouldn't be needed any more...
9684 if {$head eq $mainhead} {
9685 error_popup [mc "Cannot delete the currently checked-out branch"]
9686 return
9688 set dheads [descheads $id]
9689 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
9690 # the stuff on this branch isn't on any other branch
9691 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
9692 branch.\nReally delete branch %s?" $head $head]]} return
9694 nowbusy rmbranch
9695 update
9696 if {[catch {exec git branch -D $head} err]} {
9697 notbusy rmbranch
9698 error_popup $err
9699 return
9701 removehead $id $head
9702 removedhead $id $head
9703 redrawtags $id
9704 notbusy rmbranch
9705 dispneartags 0
9706 run refill_reflist
9709 # Display a list of tags and heads
9710 proc showrefs {} {
9711 global showrefstop bgcolor fgcolor selectbgcolor NS
9712 global bglist fglist reflistfilter reflist maincursor
9714 set top .showrefs
9715 set showrefstop $top
9716 if {[winfo exists $top]} {
9717 raise $top
9718 refill_reflist
9719 return
9721 ttk_toplevel $top
9722 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
9723 make_transient $top .
9724 text $top.list -background $bgcolor -foreground $fgcolor \
9725 -selectbackground $selectbgcolor -font mainfont \
9726 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
9727 -width 30 -height 20 -cursor $maincursor \
9728 -spacing1 1 -spacing3 1 -state disabled
9729 $top.list tag configure highlight -background $selectbgcolor
9730 lappend bglist $top.list
9731 lappend fglist $top.list
9732 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
9733 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
9734 grid $top.list $top.ysb -sticky nsew
9735 grid $top.xsb x -sticky ew
9736 ${NS}::frame $top.f
9737 ${NS}::label $top.f.l -text "[mc "Filter"]: "
9738 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
9739 set reflistfilter "*"
9740 trace add variable reflistfilter write reflistfilter_change
9741 pack $top.f.e -side right -fill x -expand 1
9742 pack $top.f.l -side left
9743 grid $top.f - -sticky ew -pady 2
9744 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
9745 bind $top <Key-Escape> [list destroy $top]
9746 grid $top.close -
9747 grid columnconfigure $top 0 -weight 1
9748 grid rowconfigure $top 0 -weight 1
9749 bind $top.list <1> {break}
9750 bind $top.list <B1-Motion> {break}
9751 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
9752 set reflist {}
9753 refill_reflist
9756 proc sel_reflist {w x y} {
9757 global showrefstop reflist headids tagids otherrefids
9759 if {![winfo exists $showrefstop]} return
9760 set l [lindex [split [$w index "@$x,$y"] "."] 0]
9761 set ref [lindex $reflist [expr {$l-1}]]
9762 set n [lindex $ref 0]
9763 switch -- [lindex $ref 1] {
9764 "H" {selbyid $headids($n)}
9765 "T" {selbyid $tagids($n)}
9766 "o" {selbyid $otherrefids($n)}
9768 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
9771 proc unsel_reflist {} {
9772 global showrefstop
9774 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9775 $showrefstop.list tag remove highlight 0.0 end
9778 proc reflistfilter_change {n1 n2 op} {
9779 global reflistfilter
9781 after cancel refill_reflist
9782 after 200 refill_reflist
9785 proc refill_reflist {} {
9786 global reflist reflistfilter showrefstop headids tagids otherrefids
9787 global curview
9789 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
9790 set refs {}
9791 foreach n [array names headids] {
9792 if {[string match $reflistfilter $n]} {
9793 if {[commitinview $headids($n) $curview]} {
9794 lappend refs [list $n H]
9795 } else {
9796 interestedin $headids($n) {run refill_reflist}
9800 foreach n [array names tagids] {
9801 if {[string match $reflistfilter $n]} {
9802 if {[commitinview $tagids($n) $curview]} {
9803 lappend refs [list $n T]
9804 } else {
9805 interestedin $tagids($n) {run refill_reflist}
9809 foreach n [array names otherrefids] {
9810 if {[string match $reflistfilter $n]} {
9811 if {[commitinview $otherrefids($n) $curview]} {
9812 lappend refs [list $n o]
9813 } else {
9814 interestedin $otherrefids($n) {run refill_reflist}
9818 set refs [lsort -index 0 $refs]
9819 if {$refs eq $reflist} return
9821 # Update the contents of $showrefstop.list according to the
9822 # differences between $reflist (old) and $refs (new)
9823 $showrefstop.list conf -state normal
9824 $showrefstop.list insert end "\n"
9825 set i 0
9826 set j 0
9827 while {$i < [llength $reflist] || $j < [llength $refs]} {
9828 if {$i < [llength $reflist]} {
9829 if {$j < [llength $refs]} {
9830 set cmp [string compare [lindex $reflist $i 0] \
9831 [lindex $refs $j 0]]
9832 if {$cmp == 0} {
9833 set cmp [string compare [lindex $reflist $i 1] \
9834 [lindex $refs $j 1]]
9836 } else {
9837 set cmp -1
9839 } else {
9840 set cmp 1
9842 switch -- $cmp {
9843 -1 {
9844 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
9845 incr i
9848 incr i
9849 incr j
9852 set l [expr {$j + 1}]
9853 $showrefstop.list image create $l.0 -align baseline \
9854 -image reficon-[lindex $refs $j 1] -padx 2
9855 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
9856 incr j
9860 set reflist $refs
9861 # delete last newline
9862 $showrefstop.list delete end-2c end-1c
9863 $showrefstop.list conf -state disabled
9866 # Stuff for finding nearby tags
9867 proc getallcommits {} {
9868 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
9869 global idheads idtags idotherrefs allparents tagobjid
9870 global gitdir
9872 if {![info exists allcommits]} {
9873 set nextarc 0
9874 set allcommits 0
9875 set seeds {}
9876 set allcwait 0
9877 set cachedarcs 0
9878 set allccache [file join $gitdir "gitk.cache"]
9879 if {![catch {
9880 set f [open $allccache r]
9881 set allcwait 1
9882 getcache $f
9883 }]} return
9886 if {$allcwait} {
9887 return
9889 set cmd [list | git rev-list --parents]
9890 set allcupdate [expr {$seeds ne {}}]
9891 if {!$allcupdate} {
9892 set ids "--all"
9893 } else {
9894 set refs [concat [array names idheads] [array names idtags] \
9895 [array names idotherrefs]]
9896 set ids {}
9897 set tagobjs {}
9898 foreach name [array names tagobjid] {
9899 lappend tagobjs $tagobjid($name)
9901 foreach id [lsort -unique $refs] {
9902 if {![info exists allparents($id)] &&
9903 [lsearch -exact $tagobjs $id] < 0} {
9904 lappend ids $id
9907 if {$ids ne {}} {
9908 foreach id $seeds {
9909 lappend ids "^$id"
9913 if {$ids ne {}} {
9914 set fd [open [concat $cmd $ids] r]
9915 fconfigure $fd -blocking 0
9916 incr allcommits
9917 nowbusy allcommits
9918 filerun $fd [list getallclines $fd]
9919 } else {
9920 dispneartags 0
9924 # Since most commits have 1 parent and 1 child, we group strings of
9925 # such commits into "arcs" joining branch/merge points (BMPs), which
9926 # are commits that either don't have 1 parent or don't have 1 child.
9928 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
9929 # arcout(id) - outgoing arcs for BMP
9930 # arcids(a) - list of IDs on arc including end but not start
9931 # arcstart(a) - BMP ID at start of arc
9932 # arcend(a) - BMP ID at end of arc
9933 # growing(a) - arc a is still growing
9934 # arctags(a) - IDs out of arcids (excluding end) that have tags
9935 # archeads(a) - IDs out of arcids (excluding end) that have heads
9936 # The start of an arc is at the descendent end, so "incoming" means
9937 # coming from descendents, and "outgoing" means going towards ancestors.
9939 proc getallclines {fd} {
9940 global allparents allchildren idtags idheads nextarc
9941 global arcnos arcids arctags arcout arcend arcstart archeads growing
9942 global seeds allcommits cachedarcs allcupdate
9944 set nid 0
9945 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
9946 set id [lindex $line 0]
9947 if {[info exists allparents($id)]} {
9948 # seen it already
9949 continue
9951 set cachedarcs 0
9952 set olds [lrange $line 1 end]
9953 set allparents($id) $olds
9954 if {![info exists allchildren($id)]} {
9955 set allchildren($id) {}
9956 set arcnos($id) {}
9957 lappend seeds $id
9958 } else {
9959 set a $arcnos($id)
9960 if {[llength $olds] == 1 && [llength $a] == 1} {
9961 lappend arcids($a) $id
9962 if {[info exists idtags($id)]} {
9963 lappend arctags($a) $id
9965 if {[info exists idheads($id)]} {
9966 lappend archeads($a) $id
9968 if {[info exists allparents($olds)]} {
9969 # seen parent already
9970 if {![info exists arcout($olds)]} {
9971 splitarc $olds
9973 lappend arcids($a) $olds
9974 set arcend($a) $olds
9975 unset growing($a)
9977 lappend allchildren($olds) $id
9978 lappend arcnos($olds) $a
9979 continue
9982 foreach a $arcnos($id) {
9983 lappend arcids($a) $id
9984 set arcend($a) $id
9985 unset growing($a)
9988 set ao {}
9989 foreach p $olds {
9990 lappend allchildren($p) $id
9991 set a [incr nextarc]
9992 set arcstart($a) $id
9993 set archeads($a) {}
9994 set arctags($a) {}
9995 set archeads($a) {}
9996 set arcids($a) {}
9997 lappend ao $a
9998 set growing($a) 1
9999 if {[info exists allparents($p)]} {
10000 # seen it already, may need to make a new branch
10001 if {![info exists arcout($p)]} {
10002 splitarc $p
10004 lappend arcids($a) $p
10005 set arcend($a) $p
10006 unset growing($a)
10008 lappend arcnos($p) $a
10010 set arcout($id) $ao
10012 if {$nid > 0} {
10013 global cached_dheads cached_dtags cached_atags
10014 catch {unset cached_dheads}
10015 catch {unset cached_dtags}
10016 catch {unset cached_atags}
10018 if {![eof $fd]} {
10019 return [expr {$nid >= 1000? 2: 1}]
10021 set cacheok 1
10022 if {[catch {
10023 fconfigure $fd -blocking 1
10024 close $fd
10025 } err]} {
10026 # got an error reading the list of commits
10027 # if we were updating, try rereading the whole thing again
10028 if {$allcupdate} {
10029 incr allcommits -1
10030 dropcache $err
10031 return
10033 error_popup "[mc "Error reading commit topology information;\
10034 branch and preceding/following tag information\
10035 will be incomplete."]\n($err)"
10036 set cacheok 0
10038 if {[incr allcommits -1] == 0} {
10039 notbusy allcommits
10040 if {$cacheok} {
10041 run savecache
10044 dispneartags 0
10045 return 0
10048 proc recalcarc {a} {
10049 global arctags archeads arcids idtags idheads
10051 set at {}
10052 set ah {}
10053 foreach id [lrange $arcids($a) 0 end-1] {
10054 if {[info exists idtags($id)]} {
10055 lappend at $id
10057 if {[info exists idheads($id)]} {
10058 lappend ah $id
10061 set arctags($a) $at
10062 set archeads($a) $ah
10065 proc splitarc {p} {
10066 global arcnos arcids nextarc arctags archeads idtags idheads
10067 global arcstart arcend arcout allparents growing
10069 set a $arcnos($p)
10070 if {[llength $a] != 1} {
10071 puts "oops splitarc called but [llength $a] arcs already"
10072 return
10074 set a [lindex $a 0]
10075 set i [lsearch -exact $arcids($a) $p]
10076 if {$i < 0} {
10077 puts "oops splitarc $p not in arc $a"
10078 return
10080 set na [incr nextarc]
10081 if {[info exists arcend($a)]} {
10082 set arcend($na) $arcend($a)
10083 } else {
10084 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10085 set j [lsearch -exact $arcnos($l) $a]
10086 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
10088 set tail [lrange $arcids($a) [expr {$i+1}] end]
10089 set arcids($a) [lrange $arcids($a) 0 $i]
10090 set arcend($a) $p
10091 set arcstart($na) $p
10092 set arcout($p) $na
10093 set arcids($na) $tail
10094 if {[info exists growing($a)]} {
10095 set growing($na) 1
10096 unset growing($a)
10099 foreach id $tail {
10100 if {[llength $arcnos($id)] == 1} {
10101 set arcnos($id) $na
10102 } else {
10103 set j [lsearch -exact $arcnos($id) $a]
10104 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10108 # reconstruct tags and heads lists
10109 if {$arctags($a) ne {} || $archeads($a) ne {}} {
10110 recalcarc $a
10111 recalcarc $na
10112 } else {
10113 set arctags($na) {}
10114 set archeads($na) {}
10118 # Update things for a new commit added that is a child of one
10119 # existing commit. Used when cherry-picking.
10120 proc addnewchild {id p} {
10121 global allparents allchildren idtags nextarc
10122 global arcnos arcids arctags arcout arcend arcstart archeads growing
10123 global seeds allcommits
10125 if {![info exists allcommits] || ![info exists arcnos($p)]} return
10126 set allparents($id) [list $p]
10127 set allchildren($id) {}
10128 set arcnos($id) {}
10129 lappend seeds $id
10130 lappend allchildren($p) $id
10131 set a [incr nextarc]
10132 set arcstart($a) $id
10133 set archeads($a) {}
10134 set arctags($a) {}
10135 set arcids($a) [list $p]
10136 set arcend($a) $p
10137 if {![info exists arcout($p)]} {
10138 splitarc $p
10140 lappend arcnos($p) $a
10141 set arcout($id) [list $a]
10144 # This implements a cache for the topology information.
10145 # The cache saves, for each arc, the start and end of the arc,
10146 # the ids on the arc, and the outgoing arcs from the end.
10147 proc readcache {f} {
10148 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10149 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10150 global allcwait
10152 set a $nextarc
10153 set lim $cachedarcs
10154 if {$lim - $a > 500} {
10155 set lim [expr {$a + 500}]
10157 if {[catch {
10158 if {$a == $lim} {
10159 # finish reading the cache and setting up arctags, etc.
10160 set line [gets $f]
10161 if {$line ne "1"} {error "bad final version"}
10162 close $f
10163 foreach id [array names idtags] {
10164 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10165 [llength $allparents($id)] == 1} {
10166 set a [lindex $arcnos($id) 0]
10167 if {$arctags($a) eq {}} {
10168 recalcarc $a
10172 foreach id [array names idheads] {
10173 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10174 [llength $allparents($id)] == 1} {
10175 set a [lindex $arcnos($id) 0]
10176 if {$archeads($a) eq {}} {
10177 recalcarc $a
10181 foreach id [lsort -unique $possible_seeds] {
10182 if {$arcnos($id) eq {}} {
10183 lappend seeds $id
10186 set allcwait 0
10187 } else {
10188 while {[incr a] <= $lim} {
10189 set line [gets $f]
10190 if {[llength $line] != 3} {error "bad line"}
10191 set s [lindex $line 0]
10192 set arcstart($a) $s
10193 lappend arcout($s) $a
10194 if {![info exists arcnos($s)]} {
10195 lappend possible_seeds $s
10196 set arcnos($s) {}
10198 set e [lindex $line 1]
10199 if {$e eq {}} {
10200 set growing($a) 1
10201 } else {
10202 set arcend($a) $e
10203 if {![info exists arcout($e)]} {
10204 set arcout($e) {}
10207 set arcids($a) [lindex $line 2]
10208 foreach id $arcids($a) {
10209 lappend allparents($s) $id
10210 set s $id
10211 lappend arcnos($id) $a
10213 if {![info exists allparents($s)]} {
10214 set allparents($s) {}
10216 set arctags($a) {}
10217 set archeads($a) {}
10219 set nextarc [expr {$a - 1}]
10221 } err]} {
10222 dropcache $err
10223 return 0
10225 if {!$allcwait} {
10226 getallcommits
10228 return $allcwait
10231 proc getcache {f} {
10232 global nextarc cachedarcs possible_seeds
10234 if {[catch {
10235 set line [gets $f]
10236 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10237 # make sure it's an integer
10238 set cachedarcs [expr {int([lindex $line 1])}]
10239 if {$cachedarcs < 0} {error "bad number of arcs"}
10240 set nextarc 0
10241 set possible_seeds {}
10242 run readcache $f
10243 } err]} {
10244 dropcache $err
10246 return 0
10249 proc dropcache {err} {
10250 global allcwait nextarc cachedarcs seeds
10252 #puts "dropping cache ($err)"
10253 foreach v {arcnos arcout arcids arcstart arcend growing \
10254 arctags archeads allparents allchildren} {
10255 global $v
10256 catch {unset $v}
10258 set allcwait 0
10259 set nextarc 0
10260 set cachedarcs 0
10261 set seeds {}
10262 getallcommits
10265 proc writecache {f} {
10266 global cachearc cachedarcs allccache
10267 global arcstart arcend arcnos arcids arcout
10269 set a $cachearc
10270 set lim $cachedarcs
10271 if {$lim - $a > 1000} {
10272 set lim [expr {$a + 1000}]
10274 if {[catch {
10275 while {[incr a] <= $lim} {
10276 if {[info exists arcend($a)]} {
10277 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10278 } else {
10279 puts $f [list $arcstart($a) {} $arcids($a)]
10282 } err]} {
10283 catch {close $f}
10284 catch {file delete $allccache}
10285 #puts "writing cache failed ($err)"
10286 return 0
10288 set cachearc [expr {$a - 1}]
10289 if {$a > $cachedarcs} {
10290 puts $f "1"
10291 close $f
10292 return 0
10294 return 1
10297 proc savecache {} {
10298 global nextarc cachedarcs cachearc allccache
10300 if {$nextarc == $cachedarcs} return
10301 set cachearc 0
10302 set cachedarcs $nextarc
10303 catch {
10304 set f [open $allccache w]
10305 puts $f [list 1 $cachedarcs]
10306 run writecache $f
10310 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10311 # or 0 if neither is true.
10312 proc anc_or_desc {a b} {
10313 global arcout arcstart arcend arcnos cached_isanc
10315 if {$arcnos($a) eq $arcnos($b)} {
10316 # Both are on the same arc(s); either both are the same BMP,
10317 # or if one is not a BMP, the other is also not a BMP or is
10318 # the BMP at end of the arc (and it only has 1 incoming arc).
10319 # Or both can be BMPs with no incoming arcs.
10320 if {$a eq $b || $arcnos($a) eq {}} {
10321 return 0
10323 # assert {[llength $arcnos($a)] == 1}
10324 set arc [lindex $arcnos($a) 0]
10325 set i [lsearch -exact $arcids($arc) $a]
10326 set j [lsearch -exact $arcids($arc) $b]
10327 if {$i < 0 || $i > $j} {
10328 return 1
10329 } else {
10330 return -1
10334 if {![info exists arcout($a)]} {
10335 set arc [lindex $arcnos($a) 0]
10336 if {[info exists arcend($arc)]} {
10337 set aend $arcend($arc)
10338 } else {
10339 set aend {}
10341 set a $arcstart($arc)
10342 } else {
10343 set aend $a
10345 if {![info exists arcout($b)]} {
10346 set arc [lindex $arcnos($b) 0]
10347 if {[info exists arcend($arc)]} {
10348 set bend $arcend($arc)
10349 } else {
10350 set bend {}
10352 set b $arcstart($arc)
10353 } else {
10354 set bend $b
10356 if {$a eq $bend} {
10357 return 1
10359 if {$b eq $aend} {
10360 return -1
10362 if {[info exists cached_isanc($a,$bend)]} {
10363 if {$cached_isanc($a,$bend)} {
10364 return 1
10367 if {[info exists cached_isanc($b,$aend)]} {
10368 if {$cached_isanc($b,$aend)} {
10369 return -1
10371 if {[info exists cached_isanc($a,$bend)]} {
10372 return 0
10376 set todo [list $a $b]
10377 set anc($a) a
10378 set anc($b) b
10379 for {set i 0} {$i < [llength $todo]} {incr i} {
10380 set x [lindex $todo $i]
10381 if {$anc($x) eq {}} {
10382 continue
10384 foreach arc $arcnos($x) {
10385 set xd $arcstart($arc)
10386 if {$xd eq $bend} {
10387 set cached_isanc($a,$bend) 1
10388 set cached_isanc($b,$aend) 0
10389 return 1
10390 } elseif {$xd eq $aend} {
10391 set cached_isanc($b,$aend) 1
10392 set cached_isanc($a,$bend) 0
10393 return -1
10395 if {![info exists anc($xd)]} {
10396 set anc($xd) $anc($x)
10397 lappend todo $xd
10398 } elseif {$anc($xd) ne $anc($x)} {
10399 set anc($xd) {}
10403 set cached_isanc($a,$bend) 0
10404 set cached_isanc($b,$aend) 0
10405 return 0
10408 # This identifies whether $desc has an ancestor that is
10409 # a growing tip of the graph and which is not an ancestor of $anc
10410 # and returns 0 if so and 1 if not.
10411 # If we subsequently discover a tag on such a growing tip, and that
10412 # turns out to be a descendent of $anc (which it could, since we
10413 # don't necessarily see children before parents), then $desc
10414 # isn't a good choice to display as a descendent tag of
10415 # $anc (since it is the descendent of another tag which is
10416 # a descendent of $anc). Similarly, $anc isn't a good choice to
10417 # display as a ancestor tag of $desc.
10419 proc is_certain {desc anc} {
10420 global arcnos arcout arcstart arcend growing problems
10422 set certain {}
10423 if {[llength $arcnos($anc)] == 1} {
10424 # tags on the same arc are certain
10425 if {$arcnos($desc) eq $arcnos($anc)} {
10426 return 1
10428 if {![info exists arcout($anc)]} {
10429 # if $anc is partway along an arc, use the start of the arc instead
10430 set a [lindex $arcnos($anc) 0]
10431 set anc $arcstart($a)
10434 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
10435 set x $desc
10436 } else {
10437 set a [lindex $arcnos($desc) 0]
10438 set x $arcend($a)
10440 if {$x == $anc} {
10441 return 1
10443 set anclist [list $x]
10444 set dl($x) 1
10445 set nnh 1
10446 set ngrowanc 0
10447 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
10448 set x [lindex $anclist $i]
10449 if {$dl($x)} {
10450 incr nnh -1
10452 set done($x) 1
10453 foreach a $arcout($x) {
10454 if {[info exists growing($a)]} {
10455 if {![info exists growanc($x)] && $dl($x)} {
10456 set growanc($x) 1
10457 incr ngrowanc
10459 } else {
10460 set y $arcend($a)
10461 if {[info exists dl($y)]} {
10462 if {$dl($y)} {
10463 if {!$dl($x)} {
10464 set dl($y) 0
10465 if {![info exists done($y)]} {
10466 incr nnh -1
10468 if {[info exists growanc($x)]} {
10469 incr ngrowanc -1
10471 set xl [list $y]
10472 for {set k 0} {$k < [llength $xl]} {incr k} {
10473 set z [lindex $xl $k]
10474 foreach c $arcout($z) {
10475 if {[info exists arcend($c)]} {
10476 set v $arcend($c)
10477 if {[info exists dl($v)] && $dl($v)} {
10478 set dl($v) 0
10479 if {![info exists done($v)]} {
10480 incr nnh -1
10482 if {[info exists growanc($v)]} {
10483 incr ngrowanc -1
10485 lappend xl $v
10492 } elseif {$y eq $anc || !$dl($x)} {
10493 set dl($y) 0
10494 lappend anclist $y
10495 } else {
10496 set dl($y) 1
10497 lappend anclist $y
10498 incr nnh
10503 foreach x [array names growanc] {
10504 if {$dl($x)} {
10505 return 0
10507 return 0
10509 return 1
10512 proc validate_arctags {a} {
10513 global arctags idtags
10515 set i -1
10516 set na $arctags($a)
10517 foreach id $arctags($a) {
10518 incr i
10519 if {![info exists idtags($id)]} {
10520 set na [lreplace $na $i $i]
10521 incr i -1
10524 set arctags($a) $na
10527 proc validate_archeads {a} {
10528 global archeads idheads
10530 set i -1
10531 set na $archeads($a)
10532 foreach id $archeads($a) {
10533 incr i
10534 if {![info exists idheads($id)]} {
10535 set na [lreplace $na $i $i]
10536 incr i -1
10539 set archeads($a) $na
10542 # Return the list of IDs that have tags that are descendents of id,
10543 # ignoring IDs that are descendents of IDs already reported.
10544 proc desctags {id} {
10545 global arcnos arcstart arcids arctags idtags allparents
10546 global growing cached_dtags
10548 if {![info exists allparents($id)]} {
10549 return {}
10551 set t1 [clock clicks -milliseconds]
10552 set argid $id
10553 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10554 # part-way along an arc; check that arc first
10555 set a [lindex $arcnos($id) 0]
10556 if {$arctags($a) ne {}} {
10557 validate_arctags $a
10558 set i [lsearch -exact $arcids($a) $id]
10559 set tid {}
10560 foreach t $arctags($a) {
10561 set j [lsearch -exact $arcids($a) $t]
10562 if {$j >= $i} break
10563 set tid $t
10565 if {$tid ne {}} {
10566 return $tid
10569 set id $arcstart($a)
10570 if {[info exists idtags($id)]} {
10571 return $id
10574 if {[info exists cached_dtags($id)]} {
10575 return $cached_dtags($id)
10578 set origid $id
10579 set todo [list $id]
10580 set queued($id) 1
10581 set nc 1
10582 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10583 set id [lindex $todo $i]
10584 set done($id) 1
10585 set ta [info exists hastaggedancestor($id)]
10586 if {!$ta} {
10587 incr nc -1
10589 # ignore tags on starting node
10590 if {!$ta && $i > 0} {
10591 if {[info exists idtags($id)]} {
10592 set tagloc($id) $id
10593 set ta 1
10594 } elseif {[info exists cached_dtags($id)]} {
10595 set tagloc($id) $cached_dtags($id)
10596 set ta 1
10599 foreach a $arcnos($id) {
10600 set d $arcstart($a)
10601 if {!$ta && $arctags($a) ne {}} {
10602 validate_arctags $a
10603 if {$arctags($a) ne {}} {
10604 lappend tagloc($id) [lindex $arctags($a) end]
10607 if {$ta || $arctags($a) ne {}} {
10608 set tomark [list $d]
10609 for {set j 0} {$j < [llength $tomark]} {incr j} {
10610 set dd [lindex $tomark $j]
10611 if {![info exists hastaggedancestor($dd)]} {
10612 if {[info exists done($dd)]} {
10613 foreach b $arcnos($dd) {
10614 lappend tomark $arcstart($b)
10616 if {[info exists tagloc($dd)]} {
10617 unset tagloc($dd)
10619 } elseif {[info exists queued($dd)]} {
10620 incr nc -1
10622 set hastaggedancestor($dd) 1
10626 if {![info exists queued($d)]} {
10627 lappend todo $d
10628 set queued($d) 1
10629 if {![info exists hastaggedancestor($d)]} {
10630 incr nc
10635 set tags {}
10636 foreach id [array names tagloc] {
10637 if {![info exists hastaggedancestor($id)]} {
10638 foreach t $tagloc($id) {
10639 if {[lsearch -exact $tags $t] < 0} {
10640 lappend tags $t
10645 set t2 [clock clicks -milliseconds]
10646 set loopix $i
10648 # remove tags that are descendents of other tags
10649 for {set i 0} {$i < [llength $tags]} {incr i} {
10650 set a [lindex $tags $i]
10651 for {set j 0} {$j < $i} {incr j} {
10652 set b [lindex $tags $j]
10653 set r [anc_or_desc $a $b]
10654 if {$r == 1} {
10655 set tags [lreplace $tags $j $j]
10656 incr j -1
10657 incr i -1
10658 } elseif {$r == -1} {
10659 set tags [lreplace $tags $i $i]
10660 incr i -1
10661 break
10666 if {[array names growing] ne {}} {
10667 # graph isn't finished, need to check if any tag could get
10668 # eclipsed by another tag coming later. Simply ignore any
10669 # tags that could later get eclipsed.
10670 set ctags {}
10671 foreach t $tags {
10672 if {[is_certain $t $origid]} {
10673 lappend ctags $t
10676 if {$tags eq $ctags} {
10677 set cached_dtags($origid) $tags
10678 } else {
10679 set tags $ctags
10681 } else {
10682 set cached_dtags($origid) $tags
10684 set t3 [clock clicks -milliseconds]
10685 if {0 && $t3 - $t1 >= 100} {
10686 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
10687 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10689 return $tags
10692 proc anctags {id} {
10693 global arcnos arcids arcout arcend arctags idtags allparents
10694 global growing cached_atags
10696 if {![info exists allparents($id)]} {
10697 return {}
10699 set t1 [clock clicks -milliseconds]
10700 set argid $id
10701 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
10702 # part-way along an arc; check that arc first
10703 set a [lindex $arcnos($id) 0]
10704 if {$arctags($a) ne {}} {
10705 validate_arctags $a
10706 set i [lsearch -exact $arcids($a) $id]
10707 foreach t $arctags($a) {
10708 set j [lsearch -exact $arcids($a) $t]
10709 if {$j > $i} {
10710 return $t
10714 if {![info exists arcend($a)]} {
10715 return {}
10717 set id $arcend($a)
10718 if {[info exists idtags($id)]} {
10719 return $id
10722 if {[info exists cached_atags($id)]} {
10723 return $cached_atags($id)
10726 set origid $id
10727 set todo [list $id]
10728 set queued($id) 1
10729 set taglist {}
10730 set nc 1
10731 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
10732 set id [lindex $todo $i]
10733 set done($id) 1
10734 set td [info exists hastaggeddescendent($id)]
10735 if {!$td} {
10736 incr nc -1
10738 # ignore tags on starting node
10739 if {!$td && $i > 0} {
10740 if {[info exists idtags($id)]} {
10741 set tagloc($id) $id
10742 set td 1
10743 } elseif {[info exists cached_atags($id)]} {
10744 set tagloc($id) $cached_atags($id)
10745 set td 1
10748 foreach a $arcout($id) {
10749 if {!$td && $arctags($a) ne {}} {
10750 validate_arctags $a
10751 if {$arctags($a) ne {}} {
10752 lappend tagloc($id) [lindex $arctags($a) 0]
10755 if {![info exists arcend($a)]} continue
10756 set d $arcend($a)
10757 if {$td || $arctags($a) ne {}} {
10758 set tomark [list $d]
10759 for {set j 0} {$j < [llength $tomark]} {incr j} {
10760 set dd [lindex $tomark $j]
10761 if {![info exists hastaggeddescendent($dd)]} {
10762 if {[info exists done($dd)]} {
10763 foreach b $arcout($dd) {
10764 if {[info exists arcend($b)]} {
10765 lappend tomark $arcend($b)
10768 if {[info exists tagloc($dd)]} {
10769 unset tagloc($dd)
10771 } elseif {[info exists queued($dd)]} {
10772 incr nc -1
10774 set hastaggeddescendent($dd) 1
10778 if {![info exists queued($d)]} {
10779 lappend todo $d
10780 set queued($d) 1
10781 if {![info exists hastaggeddescendent($d)]} {
10782 incr nc
10787 set t2 [clock clicks -milliseconds]
10788 set loopix $i
10789 set tags {}
10790 foreach id [array names tagloc] {
10791 if {![info exists hastaggeddescendent($id)]} {
10792 foreach t $tagloc($id) {
10793 if {[lsearch -exact $tags $t] < 0} {
10794 lappend tags $t
10800 # remove tags that are ancestors of other tags
10801 for {set i 0} {$i < [llength $tags]} {incr i} {
10802 set a [lindex $tags $i]
10803 for {set j 0} {$j < $i} {incr j} {
10804 set b [lindex $tags $j]
10805 set r [anc_or_desc $a $b]
10806 if {$r == -1} {
10807 set tags [lreplace $tags $j $j]
10808 incr j -1
10809 incr i -1
10810 } elseif {$r == 1} {
10811 set tags [lreplace $tags $i $i]
10812 incr i -1
10813 break
10818 if {[array names growing] ne {}} {
10819 # graph isn't finished, need to check if any tag could get
10820 # eclipsed by another tag coming later. Simply ignore any
10821 # tags that could later get eclipsed.
10822 set ctags {}
10823 foreach t $tags {
10824 if {[is_certain $origid $t]} {
10825 lappend ctags $t
10828 if {$tags eq $ctags} {
10829 set cached_atags($origid) $tags
10830 } else {
10831 set tags $ctags
10833 } else {
10834 set cached_atags($origid) $tags
10836 set t3 [clock clicks -milliseconds]
10837 if {0 && $t3 - $t1 >= 100} {
10838 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
10839 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
10841 return $tags
10844 # Return the list of IDs that have heads that are descendents of id,
10845 # including id itself if it has a head.
10846 proc descheads {id} {
10847 global arcnos arcstart arcids archeads idheads cached_dheads
10848 global allparents arcout
10850 if {![info exists allparents($id)]} {
10851 return {}
10853 set aret {}
10854 if {![info exists arcout($id)]} {
10855 # part-way along an arc; check it first
10856 set a [lindex $arcnos($id) 0]
10857 if {$archeads($a) ne {}} {
10858 validate_archeads $a
10859 set i [lsearch -exact $arcids($a) $id]
10860 foreach t $archeads($a) {
10861 set j [lsearch -exact $arcids($a) $t]
10862 if {$j > $i} break
10863 lappend aret $t
10866 set id $arcstart($a)
10868 set origid $id
10869 set todo [list $id]
10870 set seen($id) 1
10871 set ret {}
10872 for {set i 0} {$i < [llength $todo]} {incr i} {
10873 set id [lindex $todo $i]
10874 if {[info exists cached_dheads($id)]} {
10875 set ret [concat $ret $cached_dheads($id)]
10876 } else {
10877 if {[info exists idheads($id)]} {
10878 lappend ret $id
10880 foreach a $arcnos($id) {
10881 if {$archeads($a) ne {}} {
10882 validate_archeads $a
10883 if {$archeads($a) ne {}} {
10884 set ret [concat $ret $archeads($a)]
10887 set d $arcstart($a)
10888 if {![info exists seen($d)]} {
10889 lappend todo $d
10890 set seen($d) 1
10895 set ret [lsort -unique $ret]
10896 set cached_dheads($origid) $ret
10897 return [concat $ret $aret]
10900 proc addedtag {id} {
10901 global arcnos arcout cached_dtags cached_atags
10903 if {![info exists arcnos($id)]} return
10904 if {![info exists arcout($id)]} {
10905 recalcarc [lindex $arcnos($id) 0]
10907 catch {unset cached_dtags}
10908 catch {unset cached_atags}
10911 proc addedhead {hid head} {
10912 global arcnos arcout cached_dheads
10914 if {![info exists arcnos($hid)]} return
10915 if {![info exists arcout($hid)]} {
10916 recalcarc [lindex $arcnos($hid) 0]
10918 catch {unset cached_dheads}
10921 proc removedhead {hid head} {
10922 global cached_dheads
10924 catch {unset cached_dheads}
10927 proc movedhead {hid head} {
10928 global arcnos arcout cached_dheads
10930 if {![info exists arcnos($hid)]} return
10931 if {![info exists arcout($hid)]} {
10932 recalcarc [lindex $arcnos($hid) 0]
10934 catch {unset cached_dheads}
10937 proc changedrefs {} {
10938 global cached_dheads cached_dtags cached_atags cached_tagcontent
10939 global arctags archeads arcnos arcout idheads idtags
10941 foreach id [concat [array names idheads] [array names idtags]] {
10942 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
10943 set a [lindex $arcnos($id) 0]
10944 if {![info exists donearc($a)]} {
10945 recalcarc $a
10946 set donearc($a) 1
10950 catch {unset cached_tagcontent}
10951 catch {unset cached_dtags}
10952 catch {unset cached_atags}
10953 catch {unset cached_dheads}
10956 proc rereadrefs {} {
10957 global idtags idheads idotherrefs mainheadid
10959 set refids [concat [array names idtags] \
10960 [array names idheads] [array names idotherrefs]]
10961 foreach id $refids {
10962 if {![info exists ref($id)]} {
10963 set ref($id) [listrefs $id]
10966 set oldmainhead $mainheadid
10967 readrefs
10968 changedrefs
10969 set refids [lsort -unique [concat $refids [array names idtags] \
10970 [array names idheads] [array names idotherrefs]]]
10971 foreach id $refids {
10972 set v [listrefs $id]
10973 if {![info exists ref($id)] || $ref($id) != $v} {
10974 redrawtags $id
10977 if {$oldmainhead ne $mainheadid} {
10978 redrawtags $oldmainhead
10979 redrawtags $mainheadid
10981 run refill_reflist
10984 proc listrefs {id} {
10985 global idtags idheads idotherrefs
10987 set x {}
10988 if {[info exists idtags($id)]} {
10989 set x $idtags($id)
10991 set y {}
10992 if {[info exists idheads($id)]} {
10993 set y $idheads($id)
10995 set z {}
10996 if {[info exists idotherrefs($id)]} {
10997 set z $idotherrefs($id)
10999 return [list $x $y $z]
11002 proc add_tag_ctext {tag} {
11003 global ctext cached_tagcontent tagids
11005 if {![info exists cached_tagcontent($tag)]} {
11006 catch {
11007 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11010 $ctext insert end "[mc "Tag"]: $tag\n" bold
11011 if {[info exists cached_tagcontent($tag)]} {
11012 set text $cached_tagcontent($tag)
11013 } else {
11014 set text "[mc "Id"]: $tagids($tag)"
11016 appendwithlinks $text {}
11019 proc showtag {tag isnew} {
11020 global ctext cached_tagcontent tagids linknum tagobjid
11022 if {$isnew} {
11023 addtohistory [list showtag $tag 0] savectextpos
11025 $ctext conf -state normal
11026 clear_ctext
11027 settabs 0
11028 set linknum 0
11029 add_tag_ctext $tag
11030 maybe_scroll_ctext 1
11031 $ctext conf -state disabled
11032 init_flist {}
11035 proc showtags {id isnew} {
11036 global idtags ctext linknum
11038 if {$isnew} {
11039 addtohistory [list showtags $id 0] savectextpos
11041 $ctext conf -state normal
11042 clear_ctext
11043 settabs 0
11044 set linknum 0
11045 set sep {}
11046 foreach tag $idtags($id) {
11047 $ctext insert end $sep
11048 add_tag_ctext $tag
11049 set sep "\n\n"
11051 maybe_scroll_ctext 1
11052 $ctext conf -state disabled
11053 init_flist {}
11056 proc doquit {} {
11057 global stopped
11058 global gitktmpdir
11060 set stopped 100
11061 savestuff .
11062 destroy .
11064 if {[info exists gitktmpdir]} {
11065 catch {file delete -force $gitktmpdir}
11069 proc mkfontdisp {font top which} {
11070 global fontattr fontpref $font NS use_ttk
11072 set fontpref($font) [set $font]
11073 ${NS}::button $top.${font}but -text $which \
11074 -command [list choosefont $font $which]
11075 ${NS}::label $top.$font -relief flat -font $font \
11076 -text $fontattr($font,family) -justify left
11077 grid x $top.${font}but $top.$font -sticky w
11080 proc choosefont {font which} {
11081 global fontparam fontlist fonttop fontattr
11082 global prefstop NS
11084 set fontparam(which) $which
11085 set fontparam(font) $font
11086 set fontparam(family) [font actual $font -family]
11087 set fontparam(size) $fontattr($font,size)
11088 set fontparam(weight) $fontattr($font,weight)
11089 set fontparam(slant) $fontattr($font,slant)
11090 set top .gitkfont
11091 set fonttop $top
11092 if {![winfo exists $top]} {
11093 font create sample
11094 eval font config sample [font actual $font]
11095 ttk_toplevel $top
11096 make_transient $top $prefstop
11097 wm title $top [mc "Gitk font chooser"]
11098 ${NS}::label $top.l -textvariable fontparam(which)
11099 pack $top.l -side top
11100 set fontlist [lsort [font families]]
11101 ${NS}::frame $top.f
11102 listbox $top.f.fam -listvariable fontlist \
11103 -yscrollcommand [list $top.f.sb set]
11104 bind $top.f.fam <<ListboxSelect>> selfontfam
11105 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11106 pack $top.f.sb -side right -fill y
11107 pack $top.f.fam -side left -fill both -expand 1
11108 pack $top.f -side top -fill both -expand 1
11109 ${NS}::frame $top.g
11110 spinbox $top.g.size -from 4 -to 40 -width 4 \
11111 -textvariable fontparam(size) \
11112 -validatecommand {string is integer -strict %s}
11113 checkbutton $top.g.bold -padx 5 \
11114 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11115 -variable fontparam(weight) -onvalue bold -offvalue normal
11116 checkbutton $top.g.ital -padx 5 \
11117 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11118 -variable fontparam(slant) -onvalue italic -offvalue roman
11119 pack $top.g.size $top.g.bold $top.g.ital -side left
11120 pack $top.g -side top
11121 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11122 -background white
11123 $top.c create text 100 25 -anchor center -text $which -font sample \
11124 -fill black -tags text
11125 bind $top.c <Configure> [list centertext $top.c]
11126 pack $top.c -side top -fill x
11127 ${NS}::frame $top.buts
11128 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11129 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11130 bind $top <Key-Return> fontok
11131 bind $top <Key-Escape> fontcan
11132 grid $top.buts.ok $top.buts.can
11133 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11134 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11135 pack $top.buts -side bottom -fill x
11136 trace add variable fontparam write chg_fontparam
11137 } else {
11138 raise $top
11139 $top.c itemconf text -text $which
11141 set i [lsearch -exact $fontlist $fontparam(family)]
11142 if {$i >= 0} {
11143 $top.f.fam selection set $i
11144 $top.f.fam see $i
11148 proc centertext {w} {
11149 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11152 proc fontok {} {
11153 global fontparam fontpref prefstop
11155 set f $fontparam(font)
11156 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11157 if {$fontparam(weight) eq "bold"} {
11158 lappend fontpref($f) "bold"
11160 if {$fontparam(slant) eq "italic"} {
11161 lappend fontpref($f) "italic"
11163 set w $prefstop.notebook.fonts.$f
11164 $w conf -text $fontparam(family) -font $fontpref($f)
11166 fontcan
11169 proc fontcan {} {
11170 global fonttop fontparam
11172 if {[info exists fonttop]} {
11173 catch {destroy $fonttop}
11174 catch {font delete sample}
11175 unset fonttop
11176 unset fontparam
11180 if {[package vsatisfies [package provide Tk] 8.6]} {
11181 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11182 # function to make use of it.
11183 proc choosefont {font which} {
11184 tk fontchooser configure -title $which -font $font \
11185 -command [list on_choosefont $font $which]
11186 tk fontchooser show
11188 proc on_choosefont {font which newfont} {
11189 global fontparam
11190 puts stderr "$font $newfont"
11191 array set f [font actual $newfont]
11192 set fontparam(which) $which
11193 set fontparam(font) $font
11194 set fontparam(family) $f(-family)
11195 set fontparam(size) $f(-size)
11196 set fontparam(weight) $f(-weight)
11197 set fontparam(slant) $f(-slant)
11198 fontok
11202 proc selfontfam {} {
11203 global fonttop fontparam
11205 set i [$fonttop.f.fam curselection]
11206 if {$i ne {}} {
11207 set fontparam(family) [$fonttop.f.fam get $i]
11211 proc chg_fontparam {v sub op} {
11212 global fontparam
11214 font config sample -$sub $fontparam($sub)
11217 # Create a property sheet tab page
11218 proc create_prefs_page {w} {
11219 global NS
11220 set parent [join [lrange [split $w .] 0 end-1] .]
11221 if {[winfo class $parent] eq "TNotebook"} {
11222 ${NS}::frame $w
11223 } else {
11224 ${NS}::labelframe $w
11228 proc prefspage_general {notebook} {
11229 global NS maxwidth maxgraphpct showneartags showlocalchanges
11230 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11231 global hideremotes want_ttk have_ttk maxrefs
11233 set page [create_prefs_page $notebook.general]
11235 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11236 grid $page.ldisp - -sticky w -pady 10
11237 ${NS}::label $page.spacer -text " "
11238 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11239 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11240 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
11241 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11242 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11243 grid x $page.maxpctl $page.maxpct -sticky w
11244 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
11245 -variable showlocalchanges
11246 grid x $page.showlocal -sticky w
11247 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
11248 -variable autoselect
11249 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11250 grid x $page.autoselect $page.autosellen -sticky w
11251 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
11252 -variable hideremotes
11253 grid x $page.hideremotes -sticky w
11255 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11256 grid $page.ddisp - -sticky w -pady 10
11257 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11258 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11259 grid x $page.tabstopl $page.tabstop -sticky w
11260 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
11261 -variable showneartags
11262 grid x $page.ntag -sticky w
11263 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11264 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11265 grid x $page.maxrefsl $page.maxrefs -sticky w
11266 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
11267 -variable limitdiffs
11268 grid x $page.ldiff -sticky w
11269 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
11270 -variable perfile_attrs
11271 grid x $page.lattr -sticky w
11273 ${NS}::entry $page.extdifft -textvariable extdifftool
11274 ${NS}::frame $page.extdifff
11275 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11276 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11277 pack $page.extdifff.l $page.extdifff.b -side left
11278 pack configure $page.extdifff.l -padx 10
11279 grid x $page.extdifff $page.extdifft -sticky ew
11281 ${NS}::label $page.lgen -text [mc "General options"]
11282 grid $page.lgen - -sticky w -pady 10
11283 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
11284 -text [mc "Use themed widgets"]
11285 if {$have_ttk} {
11286 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
11287 } else {
11288 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
11290 grid x $page.want_ttk $page.ttk_note -sticky w
11291 return $page
11294 proc prefspage_colors {notebook} {
11295 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11297 set page [create_prefs_page $notebook.colors]
11299 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11300 grid $page.cdisp - -sticky w -pady 10
11301 label $page.ui -padx 40 -relief sunk -background $uicolor
11302 ${NS}::button $page.uibut -text [mc "Interface"] \
11303 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11304 grid x $page.uibut $page.ui -sticky w
11305 label $page.bg -padx 40 -relief sunk -background $bgcolor
11306 ${NS}::button $page.bgbut -text [mc "Background"] \
11307 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
11308 grid x $page.bgbut $page.bg -sticky w
11309 label $page.fg -padx 40 -relief sunk -background $fgcolor
11310 ${NS}::button $page.fgbut -text [mc "Foreground"] \
11311 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
11312 grid x $page.fgbut $page.fg -sticky w
11313 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11314 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
11315 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11316 [list $ctext tag conf d0 -foreground]]
11317 grid x $page.diffoldbut $page.diffold -sticky w
11318 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11319 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
11320 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11321 [list $ctext tag conf dresult -foreground]]
11322 grid x $page.diffnewbut $page.diffnew -sticky w
11323 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11324 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
11325 -command [list choosecolor diffcolors 2 $page.hunksep \
11326 [mc "diff hunk header"] \
11327 [list $ctext tag conf hunksep -foreground]]
11328 grid x $page.hunksepbut $page.hunksep -sticky w
11329 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11330 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
11331 -command [list choosecolor markbgcolor {} $page.markbgsep \
11332 [mc "marked line background"] \
11333 [list $ctext tag conf omark -background]]
11334 grid x $page.markbgbut $page.markbgsep -sticky w
11335 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11336 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
11337 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
11338 grid x $page.selbgbut $page.selbgsep -sticky w
11339 return $page
11342 proc prefspage_fonts {notebook} {
11343 global NS
11344 set page [create_prefs_page $notebook.fonts]
11345 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11346 grid $page.cfont - -sticky w -pady 10
11347 mkfontdisp mainfont $page [mc "Main font"]
11348 mkfontdisp textfont $page [mc "Diff display font"]
11349 mkfontdisp uifont $page [mc "User interface font"]
11350 return $page
11353 proc doprefs {} {
11354 global maxwidth maxgraphpct use_ttk NS
11355 global oldprefs prefstop showneartags showlocalchanges
11356 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
11357 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11358 global hideremotes want_ttk have_ttk
11360 set top .gitkprefs
11361 set prefstop $top
11362 if {[winfo exists $top]} {
11363 raise $top
11364 return
11366 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11367 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11368 set oldprefs($v) [set $v]
11370 ttk_toplevel $top
11371 wm title $top [mc "Gitk preferences"]
11372 make_transient $top .
11374 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
11375 set notebook [ttk::notebook $top.notebook]
11376 } else {
11377 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
11380 lappend pages [prefspage_general $notebook] [mc "General"]
11381 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11382 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
11383 set col 0
11384 foreach {page title} $pages {
11385 if {$use_notebook} {
11386 $notebook add $page -text $title
11387 } else {
11388 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11389 -text $title -command [list raise $page]]
11390 $page configure -text $title
11391 grid $btn -row 0 -column [incr col] -sticky w
11392 grid $page -row 1 -column 0 -sticky news -columnspan 100
11396 if {!$use_notebook} {
11397 grid columnconfigure $notebook 0 -weight 1
11398 grid rowconfigure $notebook 1 -weight 1
11399 raise [lindex $pages 0]
11402 grid $notebook -sticky news -padx 2 -pady 2
11403 grid rowconfigure $top 0 -weight 1
11404 grid columnconfigure $top 0 -weight 1
11406 ${NS}::frame $top.buts
11407 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11408 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
11409 bind $top <Key-Return> prefsok
11410 bind $top <Key-Escape> prefscan
11411 grid $top.buts.ok $top.buts.can
11412 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11413 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11414 grid $top.buts - - -pady 10 -sticky ew
11415 grid columnconfigure $top 2 -weight 1
11416 bind $top <Visibility> [list focus $top.buts.ok]
11419 proc choose_extdiff {} {
11420 global extdifftool
11422 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
11423 if {$prog ne {}} {
11424 set extdifftool $prog
11428 proc choosecolor {v vi w x cmd} {
11429 global $v
11431 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
11432 -title [mc "Gitk: choose color for %s" $x]]
11433 if {$c eq {}} return
11434 $w conf -background $c
11435 lset $v $vi $c
11436 eval $cmd $c
11439 proc setselbg {c} {
11440 global bglist cflist
11441 foreach w $bglist {
11442 $w configure -selectbackground $c
11444 $cflist tag configure highlight \
11445 -background [$cflist cget -selectbackground]
11446 allcanvs itemconf secsel -fill $c
11449 # This sets the background color and the color scheme for the whole UI.
11450 # For some reason, tk_setPalette chooses a nasty dark red for selectColor
11451 # if we don't specify one ourselves, which makes the checkbuttons and
11452 # radiobuttons look bad. This chooses white for selectColor if the
11453 # background color is light, or black if it is dark.
11454 proc setui {c} {
11455 if {[tk windowingsystem] eq "win32"} { return }
11456 set bg [winfo rgb . $c]
11457 set selc black
11458 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
11459 set selc white
11461 tk_setPalette background $c selectColor $selc
11464 proc setbg {c} {
11465 global bglist
11467 foreach w $bglist {
11468 $w conf -background $c
11472 proc setfg {c} {
11473 global fglist canv
11475 foreach w $fglist {
11476 $w conf -foreground $c
11478 allcanvs itemconf text -fill $c
11479 $canv itemconf circle -outline $c
11480 $canv itemconf markid -outline $c
11483 proc prefscan {} {
11484 global oldprefs prefstop
11486 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11487 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11488 global $v
11489 set $v $oldprefs($v)
11491 catch {destroy $prefstop}
11492 unset prefstop
11493 fontcan
11496 proc prefsok {} {
11497 global maxwidth maxgraphpct
11498 global oldprefs prefstop showneartags showlocalchanges
11499 global fontpref mainfont textfont uifont
11500 global limitdiffs treediffs perfile_attrs
11501 global hideremotes
11503 catch {destroy $prefstop}
11504 unset prefstop
11505 fontcan
11506 set fontchanged 0
11507 if {$mainfont ne $fontpref(mainfont)} {
11508 set mainfont $fontpref(mainfont)
11509 parsefont mainfont $mainfont
11510 eval font configure mainfont [fontflags mainfont]
11511 eval font configure mainfontbold [fontflags mainfont 1]
11512 setcoords
11513 set fontchanged 1
11515 if {$textfont ne $fontpref(textfont)} {
11516 set textfont $fontpref(textfont)
11517 parsefont textfont $textfont
11518 eval font configure textfont [fontflags textfont]
11519 eval font configure textfontbold [fontflags textfont 1]
11521 if {$uifont ne $fontpref(uifont)} {
11522 set uifont $fontpref(uifont)
11523 parsefont uifont $uifont
11524 eval font configure uifont [fontflags uifont]
11526 settabs
11527 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
11528 if {$showlocalchanges} {
11529 doshowlocalchanges
11530 } else {
11531 dohidelocalchanges
11534 if {$limitdiffs != $oldprefs(limitdiffs) ||
11535 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11536 # treediffs elements are limited by path;
11537 # won't have encodings cached if perfile_attrs was just turned on
11538 catch {unset treediffs}
11540 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
11541 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11542 redisplay
11543 } elseif {$showneartags != $oldprefs(showneartags) ||
11544 $limitdiffs != $oldprefs(limitdiffs)} {
11545 reselectline
11547 if {$hideremotes != $oldprefs(hideremotes)} {
11548 rereadrefs
11552 proc formatdate {d} {
11553 global datetimeformat
11554 if {$d ne {}} {
11555 # If $datetimeformat includes a timezone, display in the
11556 # timezone of the argument. Otherwise, display in local time.
11557 if {[string match {*%[zZ]*} $datetimeformat]} {
11558 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11559 # Tcl < 8.5 does not support -timezone. Emulate it by
11560 # setting TZ (e.g. TZ=<-0430>+04:30).
11561 global env
11562 if {[info exists env(TZ)]} {
11563 set savedTZ $env(TZ)
11565 set zone [lindex $d 1]
11566 set sign [string map {+ - - +} [string index $zone 0]]
11567 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11568 set d [clock format [lindex $d 0] -format $datetimeformat]
11569 if {[info exists savedTZ]} {
11570 set env(TZ) $savedTZ
11571 } else {
11572 unset env(TZ)
11575 } else {
11576 set d [clock format [lindex $d 0] -format $datetimeformat]
11579 return $d
11582 # This list of encoding names and aliases is distilled from
11583 # http://www.iana.org/assignments/character-sets.
11584 # Not all of them are supported by Tcl.
11585 set encoding_aliases {
11586 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11587 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11588 { ISO-10646-UTF-1 csISO10646UTF1 }
11589 { ISO_646.basic:1983 ref csISO646basic1983 }
11590 { INVARIANT csINVARIANT }
11591 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11592 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11593 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11594 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11595 { NATS-DANO iso-ir-9-1 csNATSDANO }
11596 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11597 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11598 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11599 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11600 { ISO-2022-KR csISO2022KR }
11601 { EUC-KR csEUCKR }
11602 { ISO-2022-JP csISO2022JP }
11603 { ISO-2022-JP-2 csISO2022JP2 }
11604 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11605 csISO13JISC6220jp }
11606 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11607 { IT iso-ir-15 ISO646-IT csISO15Italian }
11608 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11609 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11610 { greek7-old iso-ir-18 csISO18Greek7Old }
11611 { latin-greek iso-ir-19 csISO19LatinGreek }
11612 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11613 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11614 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11615 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11616 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11617 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11618 { INIS iso-ir-49 csISO49INIS }
11619 { INIS-8 iso-ir-50 csISO50INIS8 }
11620 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11621 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11622 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11623 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11624 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11625 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11626 csISO60Norwegian1 }
11627 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11628 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11629 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11630 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11631 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11632 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11633 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11634 { greek7 iso-ir-88 csISO88Greek7 }
11635 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11636 { iso-ir-90 csISO90 }
11637 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11638 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11639 csISO92JISC62991984b }
11640 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11641 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11642 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11643 csISO95JIS62291984handadd }
11644 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11645 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11646 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11647 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11648 CP819 csISOLatin1 }
11649 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11650 { T.61-7bit iso-ir-102 csISO102T617bit }
11651 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11652 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
11653 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
11654 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
11655 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
11656 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
11657 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
11658 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
11659 arabic csISOLatinArabic }
11660 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
11661 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
11662 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
11663 greek greek8 csISOLatinGreek }
11664 { T.101-G2 iso-ir-128 csISO128T101G2 }
11665 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
11666 csISOLatinHebrew }
11667 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
11668 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
11669 { CSN_369103 iso-ir-139 csISO139CSN369103 }
11670 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
11671 { ISO_6937-2-add iso-ir-142 csISOTextComm }
11672 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
11673 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
11674 csISOLatinCyrillic }
11675 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
11676 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
11677 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
11678 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
11679 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
11680 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
11681 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
11682 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
11683 { ISO_10367-box iso-ir-155 csISO10367Box }
11684 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
11685 { latin-lap lap iso-ir-158 csISO158Lap }
11686 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
11687 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
11688 { us-dk csUSDK }
11689 { dk-us csDKUS }
11690 { JIS_X0201 X0201 csHalfWidthKatakana }
11691 { KSC5636 ISO646-KR csKSC5636 }
11692 { ISO-10646-UCS-2 csUnicode }
11693 { ISO-10646-UCS-4 csUCS4 }
11694 { DEC-MCS dec csDECMCS }
11695 { hp-roman8 roman8 r8 csHPRoman8 }
11696 { macintosh mac csMacintosh }
11697 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
11698 csIBM037 }
11699 { IBM038 EBCDIC-INT cp038 csIBM038 }
11700 { IBM273 CP273 csIBM273 }
11701 { IBM274 EBCDIC-BE CP274 csIBM274 }
11702 { IBM275 EBCDIC-BR cp275 csIBM275 }
11703 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
11704 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
11705 { IBM280 CP280 ebcdic-cp-it csIBM280 }
11706 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
11707 { IBM284 CP284 ebcdic-cp-es csIBM284 }
11708 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
11709 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
11710 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
11711 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
11712 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
11713 { IBM424 cp424 ebcdic-cp-he csIBM424 }
11714 { IBM437 cp437 437 csPC8CodePage437 }
11715 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
11716 { IBM775 cp775 csPC775Baltic }
11717 { IBM850 cp850 850 csPC850Multilingual }
11718 { IBM851 cp851 851 csIBM851 }
11719 { IBM852 cp852 852 csPCp852 }
11720 { IBM855 cp855 855 csIBM855 }
11721 { IBM857 cp857 857 csIBM857 }
11722 { IBM860 cp860 860 csIBM860 }
11723 { IBM861 cp861 861 cp-is csIBM861 }
11724 { IBM862 cp862 862 csPC862LatinHebrew }
11725 { IBM863 cp863 863 csIBM863 }
11726 { IBM864 cp864 csIBM864 }
11727 { IBM865 cp865 865 csIBM865 }
11728 { IBM866 cp866 866 csIBM866 }
11729 { IBM868 CP868 cp-ar csIBM868 }
11730 { IBM869 cp869 869 cp-gr csIBM869 }
11731 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
11732 { IBM871 CP871 ebcdic-cp-is csIBM871 }
11733 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
11734 { IBM891 cp891 csIBM891 }
11735 { IBM903 cp903 csIBM903 }
11736 { IBM904 cp904 904 csIBBM904 }
11737 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
11738 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
11739 { IBM1026 CP1026 csIBM1026 }
11740 { EBCDIC-AT-DE csIBMEBCDICATDE }
11741 { EBCDIC-AT-DE-A csEBCDICATDEA }
11742 { EBCDIC-CA-FR csEBCDICCAFR }
11743 { EBCDIC-DK-NO csEBCDICDKNO }
11744 { EBCDIC-DK-NO-A csEBCDICDKNOA }
11745 { EBCDIC-FI-SE csEBCDICFISE }
11746 { EBCDIC-FI-SE-A csEBCDICFISEA }
11747 { EBCDIC-FR csEBCDICFR }
11748 { EBCDIC-IT csEBCDICIT }
11749 { EBCDIC-PT csEBCDICPT }
11750 { EBCDIC-ES csEBCDICES }
11751 { EBCDIC-ES-A csEBCDICESA }
11752 { EBCDIC-ES-S csEBCDICESS }
11753 { EBCDIC-UK csEBCDICUK }
11754 { EBCDIC-US csEBCDICUS }
11755 { UNKNOWN-8BIT csUnknown8BiT }
11756 { MNEMONIC csMnemonic }
11757 { MNEM csMnem }
11758 { VISCII csVISCII }
11759 { VIQR csVIQR }
11760 { KOI8-R csKOI8R }
11761 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
11762 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
11763 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
11764 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
11765 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
11766 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
11767 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
11768 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
11769 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
11770 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
11771 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
11772 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
11773 { IBM1047 IBM-1047 }
11774 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
11775 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
11776 { UNICODE-1-1 csUnicode11 }
11777 { CESU-8 csCESU-8 }
11778 { BOCU-1 csBOCU-1 }
11779 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
11780 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
11781 l8 }
11782 { ISO-8859-15 ISO_8859-15 Latin-9 }
11783 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
11784 { GBK CP936 MS936 windows-936 }
11785 { JIS_Encoding csJISEncoding }
11786 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
11787 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
11788 EUC-JP }
11789 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
11790 { ISO-10646-UCS-Basic csUnicodeASCII }
11791 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
11792 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
11793 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
11794 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
11795 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
11796 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
11797 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
11798 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
11799 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
11800 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
11801 { Adobe-Standard-Encoding csAdobeStandardEncoding }
11802 { Ventura-US csVenturaUS }
11803 { Ventura-International csVenturaInternational }
11804 { PC8-Danish-Norwegian csPC8DanishNorwegian }
11805 { PC8-Turkish csPC8Turkish }
11806 { IBM-Symbols csIBMSymbols }
11807 { IBM-Thai csIBMThai }
11808 { HP-Legal csHPLegal }
11809 { HP-Pi-font csHPPiFont }
11810 { HP-Math8 csHPMath8 }
11811 { Adobe-Symbol-Encoding csHPPSMath }
11812 { HP-DeskTop csHPDesktop }
11813 { Ventura-Math csVenturaMath }
11814 { Microsoft-Publishing csMicrosoftPublishing }
11815 { Windows-31J csWindows31J }
11816 { GB2312 csGB2312 }
11817 { Big5 csBig5 }
11820 proc tcl_encoding {enc} {
11821 global encoding_aliases tcl_encoding_cache
11822 if {[info exists tcl_encoding_cache($enc)]} {
11823 return $tcl_encoding_cache($enc)
11825 set names [encoding names]
11826 set lcnames [string tolower $names]
11827 set enc [string tolower $enc]
11828 set i [lsearch -exact $lcnames $enc]
11829 if {$i < 0} {
11830 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
11831 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
11832 set i [lsearch -exact $lcnames $encx]
11835 if {$i < 0} {
11836 foreach l $encoding_aliases {
11837 set ll [string tolower $l]
11838 if {[lsearch -exact $ll $enc] < 0} continue
11839 # look through the aliases for one that tcl knows about
11840 foreach e $ll {
11841 set i [lsearch -exact $lcnames $e]
11842 if {$i < 0} {
11843 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
11844 set i [lsearch -exact $lcnames $ex]
11847 if {$i >= 0} break
11849 break
11852 set tclenc {}
11853 if {$i >= 0} {
11854 set tclenc [lindex $names $i]
11856 set tcl_encoding_cache($enc) $tclenc
11857 return $tclenc
11860 proc gitattr {path attr default} {
11861 global path_attr_cache
11862 if {[info exists path_attr_cache($attr,$path)]} {
11863 set r $path_attr_cache($attr,$path)
11864 } else {
11865 set r "unspecified"
11866 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
11867 regexp "(.*): $attr: (.*)" $line m f r
11869 set path_attr_cache($attr,$path) $r
11871 if {$r eq "unspecified"} {
11872 return $default
11874 return $r
11877 proc cache_gitattr {attr pathlist} {
11878 global path_attr_cache
11879 set newlist {}
11880 foreach path $pathlist {
11881 if {![info exists path_attr_cache($attr,$path)]} {
11882 lappend newlist $path
11885 set lim 1000
11886 if {[tk windowingsystem] == "win32"} {
11887 # windows has a 32k limit on the arguments to a command...
11888 set lim 30
11890 while {$newlist ne {}} {
11891 set head [lrange $newlist 0 [expr {$lim - 1}]]
11892 set newlist [lrange $newlist $lim end]
11893 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
11894 foreach row [split $rlist "\n"] {
11895 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
11896 if {[string index $path 0] eq "\""} {
11897 set path [encoding convertfrom [lindex $path 0]]
11899 set path_attr_cache($attr,$path) $value
11906 proc get_path_encoding {path} {
11907 global gui_encoding perfile_attrs
11908 set tcl_enc $gui_encoding
11909 if {$path ne {} && $perfile_attrs} {
11910 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
11911 if {$enc2 ne {}} {
11912 set tcl_enc $enc2
11915 return $tcl_enc
11918 # First check that Tcl/Tk is recent enough
11919 if {[catch {package require Tk 8.4} err]} {
11920 show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
11921 Gitk requires at least Tcl/Tk 8.4." list
11922 exit 1
11925 # on OSX bring the current Wish process window to front
11926 if {[tk windowingsystem] eq "aqua"} {
11927 exec osascript -e [format {
11928 tell application "System Events"
11929 set frontmost of processes whose unix id is %d to true
11930 end tell
11931 } [pid] ]
11934 # Unset GIT_TRACE var if set
11935 if { [info exists ::env(GIT_TRACE)] } {
11936 unset ::env(GIT_TRACE)
11939 # defaults...
11940 set wrcomcmd "git diff-tree --stdin -p --pretty"
11942 set gitencoding {}
11943 catch {
11944 set gitencoding [exec git config --get i18n.commitencoding]
11946 catch {
11947 set gitencoding [exec git config --get i18n.logoutputencoding]
11949 if {$gitencoding == ""} {
11950 set gitencoding "utf-8"
11952 set tclencoding [tcl_encoding $gitencoding]
11953 if {$tclencoding == {}} {
11954 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
11957 set gui_encoding [encoding system]
11958 catch {
11959 set enc [exec git config --get gui.encoding]
11960 if {$enc ne {}} {
11961 set tclenc [tcl_encoding $enc]
11962 if {$tclenc ne {}} {
11963 set gui_encoding $tclenc
11964 } else {
11965 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
11970 set log_showroot true
11971 catch {
11972 set log_showroot [exec git config --bool --get log.showroot]
11975 if {[tk windowingsystem] eq "aqua"} {
11976 set mainfont {{Lucida Grande} 9}
11977 set textfont {Monaco 9}
11978 set uifont {{Lucida Grande} 9 bold}
11979 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
11980 # fontconfig!
11981 set mainfont {sans 9}
11982 set textfont {monospace 9}
11983 set uifont {sans 9 bold}
11984 } else {
11985 set mainfont {Helvetica 9}
11986 set textfont {Courier 9}
11987 set uifont {Helvetica 9 bold}
11989 set tabstop 8
11990 set findmergefiles 0
11991 set maxgraphpct 50
11992 set maxwidth 16
11993 set revlistorder 0
11994 set fastdate 0
11995 set uparrowlen 5
11996 set downarrowlen 5
11997 set mingaplen 100
11998 set cmitmode "patch"
11999 set wrapcomment "none"
12000 set showneartags 1
12001 set hideremotes 0
12002 set maxrefs 20
12003 set visiblerefs {"master"}
12004 set maxlinelen 200
12005 set showlocalchanges 1
12006 set limitdiffs 1
12007 set datetimeformat "%Y-%m-%d %H:%M:%S"
12008 set autoselect 1
12009 set autosellen 40
12010 set perfile_attrs 0
12011 set want_ttk 1
12013 if {[tk windowingsystem] eq "aqua"} {
12014 set extdifftool "opendiff"
12015 } else {
12016 set extdifftool "meld"
12019 set colors {green red blue magenta darkgrey brown orange}
12020 if {[tk windowingsystem] eq "win32"} {
12021 set uicolor SystemButtonFace
12022 set uifgcolor SystemButtonText
12023 set uifgdisabledcolor SystemDisabledText
12024 set bgcolor SystemWindow
12025 set fgcolor SystemWindowText
12026 set selectbgcolor SystemHighlight
12027 } else {
12028 set uicolor grey85
12029 set uifgcolor black
12030 set uifgdisabledcolor "#999"
12031 set bgcolor white
12032 set fgcolor black
12033 set selectbgcolor gray85
12035 set diffcolors {red "#00a000" blue}
12036 set diffcontext 3
12037 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
12038 set ignorespace 0
12039 set worddiff ""
12040 set markbgcolor "#e0e0ff"
12042 set headbgcolor green
12043 set headfgcolor black
12044 set headoutlinecolor black
12045 set remotebgcolor #ffddaa
12046 set tagbgcolor yellow
12047 set tagfgcolor black
12048 set tagoutlinecolor black
12049 set reflinecolor black
12050 set filesepbgcolor #aaaaaa
12051 set filesepfgcolor black
12052 set linehoverbgcolor #ffff80
12053 set linehoverfgcolor black
12054 set linehoveroutlinecolor black
12055 set mainheadcirclecolor yellow
12056 set workingfilescirclecolor red
12057 set indexcirclecolor green
12058 set circlecolors {white blue gray blue blue}
12059 set linkfgcolor blue
12060 set circleoutlinecolor $fgcolor
12061 set foundbgcolor yellow
12062 set currentsearchhitbgcolor orange
12064 # button for popping up context menus
12065 if {[tk windowingsystem] eq "aqua"} {
12066 set ctxbut <Button-2>
12067 } else {
12068 set ctxbut <Button-3>
12071 ## For msgcat loading, first locate the installation location.
12072 if { [info exists ::env(GITK_MSGSDIR)] } {
12073 ## Msgsdir was manually set in the environment.
12074 set gitk_msgsdir $::env(GITK_MSGSDIR)
12075 } else {
12076 ## Let's guess the prefix from argv0.
12077 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12078 set gitk_libdir [file join $gitk_prefix share gitk lib]
12079 set gitk_msgsdir [file join $gitk_libdir msgs]
12080 unset gitk_prefix
12083 ## Internationalization (i18n) through msgcat and gettext. See
12084 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12085 package require msgcat
12086 namespace import ::msgcat::mc
12087 ## And eventually load the actual message catalog
12088 ::msgcat::mcload $gitk_msgsdir
12090 catch {
12091 # follow the XDG base directory specification by default. See
12092 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12093 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
12094 # XDG_CONFIG_HOME environment variable is set
12095 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12096 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
12097 } else {
12098 # default XDG_CONFIG_HOME
12099 set config_file "~/.config/git/gitk"
12100 set config_file_tmp "~/.config/git/gitk-tmp"
12102 if {![file exists $config_file]} {
12103 # for backward compatibility use the old config file if it exists
12104 if {[file exists "~/.gitk"]} {
12105 set config_file "~/.gitk"
12106 set config_file_tmp "~/.gitk-tmp"
12107 } elseif {![file exists [file dirname $config_file]]} {
12108 file mkdir [file dirname $config_file]
12111 source $config_file
12114 set config_variables {
12115 mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12116 cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12117 hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12118 bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12119 markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
12120 extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
12121 remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
12122 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12123 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
12124 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor
12127 parsefont mainfont $mainfont
12128 eval font create mainfont [fontflags mainfont]
12129 eval font create mainfontbold [fontflags mainfont 1]
12131 parsefont textfont $textfont
12132 eval font create textfont [fontflags textfont]
12133 eval font create textfontbold [fontflags textfont 1]
12135 parsefont uifont $uifont
12136 eval font create uifont [fontflags uifont]
12138 setui $uicolor
12140 setoptions
12142 # check that we can find a .git directory somewhere...
12143 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
12144 show_error {} . [mc "Cannot find a git repository here."]
12145 exit 1
12148 set selecthead {}
12149 set selectheadid {}
12151 set revtreeargs {}
12152 set cmdline_files {}
12153 set i 0
12154 set revtreeargscmd {}
12155 foreach arg $argv {
12156 switch -glob -- $arg {
12157 "" { }
12158 "--" {
12159 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12160 break
12162 "--select-commit=*" {
12163 set selecthead [string range $arg 16 end]
12165 "--argscmd=*" {
12166 set revtreeargscmd [string range $arg 10 end]
12168 default {
12169 lappend revtreeargs $arg
12172 incr i
12175 if {$selecthead eq "HEAD"} {
12176 set selecthead {}
12179 if {$i >= [llength $argv] && $revtreeargs ne {}} {
12180 # no -- on command line, but some arguments (other than --argscmd)
12181 if {[catch {
12182 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12183 set cmdline_files [split $f "\n"]
12184 set n [llength $cmdline_files]
12185 set revtreeargs [lrange $revtreeargs 0 end-$n]
12186 # Unfortunately git rev-parse doesn't produce an error when
12187 # something is both a revision and a filename. To be consistent
12188 # with git log and git rev-list, check revtreeargs for filenames.
12189 foreach arg $revtreeargs {
12190 if {[file exists $arg]} {
12191 show_error {} . [mc "Ambiguous argument '%s': both revision\
12192 and filename" $arg]
12193 exit 1
12196 } err]} {
12197 # unfortunately we get both stdout and stderr in $err,
12198 # so look for "fatal:".
12199 set i [string first "fatal:" $err]
12200 if {$i > 0} {
12201 set err [string range $err [expr {$i + 6}] end]
12203 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12204 exit 1
12208 set nullid "0000000000000000000000000000000000000000"
12209 set nullid2 "0000000000000000000000000000000000000001"
12210 set nullfile "/dev/null"
12212 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12213 if {![info exists have_ttk]} {
12214 set have_ttk [llength [info commands ::ttk::style]]
12216 set use_ttk [expr {$have_ttk && $want_ttk}]
12217 set NS [expr {$use_ttk ? "ttk" : ""}]
12219 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
12221 set show_notes {}
12222 if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12223 set show_notes "--show-notes"
12226 set appname "gitk"
12228 set runq {}
12229 set history {}
12230 set historyindex 0
12231 set fh_serial 0
12232 set nhl_names {}
12233 set highlight_paths {}
12234 set findpattern {}
12235 set searchdirn -forwards
12236 set boldids {}
12237 set boldnameids {}
12238 set diffelide {0 0}
12239 set markingmatches 0
12240 set linkentercount 0
12241 set need_redisplay 0
12242 set nrows_drawn 0
12243 set firsttabstop 0
12245 set nextviewnum 1
12246 set curview 0
12247 set selectedview 0
12248 set selectedhlview [mc "None"]
12249 set highlight_related [mc "None"]
12250 set highlight_files {}
12251 set viewfiles(0) {}
12252 set viewperm(0) 0
12253 set viewargs(0) {}
12254 set viewargscmd(0) {}
12256 set selectedline {}
12257 set numcommits 0
12258 set loginstance 0
12259 set cmdlineok 0
12260 set stopped 0
12261 set stuffsaved 0
12262 set patchnum 0
12263 set lserial 0
12264 set hasworktree [hasworktree]
12265 set cdup {}
12266 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
12267 set cdup [exec git rev-parse --show-cdup]
12269 set worktree [exec git rev-parse --show-toplevel]
12270 setcoords
12271 makewindow
12272 catch {
12273 image create photo gitlogo -width 16 -height 16
12275 image create photo gitlogominus -width 4 -height 2
12276 gitlogominus put #C00000 -to 0 0 4 2
12277 gitlogo copy gitlogominus -to 1 5
12278 gitlogo copy gitlogominus -to 6 5
12279 gitlogo copy gitlogominus -to 11 5
12280 image delete gitlogominus
12282 image create photo gitlogoplus -width 4 -height 4
12283 gitlogoplus put #008000 -to 1 0 3 4
12284 gitlogoplus put #008000 -to 0 1 4 3
12285 gitlogo copy gitlogoplus -to 1 9
12286 gitlogo copy gitlogoplus -to 6 9
12287 gitlogo copy gitlogoplus -to 11 9
12288 image delete gitlogoplus
12290 image create photo gitlogo32 -width 32 -height 32
12291 gitlogo32 copy gitlogo -zoom 2 2
12293 wm iconphoto . -default gitlogo gitlogo32
12295 # wait for the window to become visible
12296 tkwait visibility .
12297 wm title . "$appname: [reponame]"
12298 update
12299 readrefs
12301 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
12302 # create a view for the files/dirs specified on the command line
12303 set curview 1
12304 set selectedview 1
12305 set nextviewnum 2
12306 set viewname(1) [mc "Command line"]
12307 set viewfiles(1) $cmdline_files
12308 set viewargs(1) $revtreeargs
12309 set viewargscmd(1) $revtreeargscmd
12310 set viewperm(1) 0
12311 set vdatemode(1) 0
12312 addviewmenu 1
12313 .bar.view entryconf [mca "Edit view..."] -state normal
12314 .bar.view entryconf [mca "Delete view"] -state normal
12317 if {[info exists permviews]} {
12318 foreach v $permviews {
12319 set n $nextviewnum
12320 incr nextviewnum
12321 set viewname($n) [lindex $v 0]
12322 set viewfiles($n) [lindex $v 1]
12323 set viewargs($n) [lindex $v 2]
12324 set viewargscmd($n) [lindex $v 3]
12325 set viewperm($n) 1
12326 addviewmenu $n
12330 if {[tk windowingsystem] eq "win32"} {
12331 focus -force .
12334 getcommits {}
12336 # Local variables:
12337 # mode: tcl
12338 # indent-tabs-mode: t
12339 # tab-width: 8
12340 # End: