2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2005 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.
12 if {[info exists env(GIT_DIR)]} {
19 proc parse_args {rargs} {
23 set parse_args [concat --default HEAD $rargs]
24 set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"]
26 # if git-rev-parse failed for some reason...
30 set parsed_args $rargs
35 proc start_rev_list {rlargs} {
36 global startmsecs nextupdate ncmupdate
37 global commfd leftover tclencoding datemode
40 set startmsecs [clock clicks -milliseconds]
41 set nextupdate [expr {$startmsecs + 100}]
44 set order "--topo-order"
46 set order "--date-order"
49 set commfd [open [concat | git-rev-list --header $order \
52 puts stderr "Error executing git-rev-list: $err"
57 fconfigure $commfd -blocking 0 -translation lf
58 if {$tclencoding != {}} {
59 fconfigure $commfd -encoding $tclencoding
61 fileevent $commfd readable [list getcommitlines $commfd]
62 . config -cursor watch
66 proc getcommits {rargs} {
67 global phase canv mainfont
70 start_rev_list [parse_args $rargs]
72 $canv create text 3 3 -anchor nw -text "Reading commits..." \
73 -font $mainfont -tags textitems
76 proc getcommitlines {commfd} {
77 global commitlisted nextupdate
79 global displayorder commitidx commitrow commitdata
81 set stuff [read $commfd]
83 if {![eof $commfd]} return
84 # set it blocking so we wait for the process to terminate
85 fconfigure $commfd -blocking 1
86 if {![catch {close $commfd} err]} {
87 after idle finishcommits
90 if {[string range $err 0 4] == "usage"} {
92 "Gitk: error reading commits: bad arguments to git-rev-list.\
93 (Note: arguments to gitk are passed to git-rev-list\
94 to allow selection of commits to be displayed.)"
96 set err "Error reading commits: $err"
104 set i [string first "\0" $stuff $start]
106 append leftover [string range $stuff $start end]
111 append cmit [string range $stuff 0 [expr {$i - 1}]]
114 set cmit [string range $stuff $start [expr {$i - 1}]]
116 set start [expr {$i + 1}]
117 set j [string first "\n" $cmit]
120 set ids [string range $cmit 0 [expr {$j - 1}]]
123 if {[string length $id] != 40} {
131 if {[string length $shortcmit] > 80} {
132 set shortcmit "[string range $shortcmit 0 80]..."
134 error_popup "Can't parse git-rev-list output: {$shortcmit}"
137 set id [lindex $ids 0]
138 set olds [lrange $ids 1 end]
139 set commitlisted($id) 1
140 updatechildren $id [lrange $ids 1 end]
141 lappend commitdata [string range $cmit [expr {$j + 1}] end]
142 set commitrow($id) $commitidx
144 lappend displayorder $id
150 if {[clock clicks -milliseconds] >= $nextupdate} {
155 proc doupdate {reading} {
156 global commfd nextupdate numcommits ncmupdate
159 fileevent $commfd readable {}
162 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
163 if {$numcommits < 100} {
164 set ncmupdate [expr {$numcommits + 1}]
165 } elseif {$numcommits < 10000} {
166 set ncmupdate [expr {$numcommits + 10}]
168 set ncmupdate [expr {$numcommits + 100}]
171 fileevent $commfd readable [list getcommitlines $commfd]
175 proc readcommit {id} {
176 if {[catch {set contents [exec git-cat-file commit $id]}]} return
177 updatechildren $id {}
178 parsecommit $id $contents 0
181 proc updatecommits {rargs} {
183 foreach v {children nchildren parents nparents commitlisted
184 colormap selectedline matchinglines treediffs
185 mergefilelist currentid rowtextx commitrow
186 rowidlist rowoffsets idrowranges idrangedrawn iddrawn
187 linesegends crossings cornercrossings} {
196 proc updatechildren {id olds} {
197 global children nchildren parents nparents
199 if {![info exists nchildren($id)]} {
203 set parents($id) $olds
204 set nparents($id) [llength $olds]
206 if {![info exists nchildren($p)]} {
207 set children($p) [list $id]
209 } elseif {[lsearch -exact $children($p) $id] < 0} {
210 lappend children($p) $id
216 proc parsecommit {id contents listed} {
217 global commitinfo cdate
226 set hdrend [string first "\n\n" $contents]
228 # should never happen...
229 set hdrend [string length $contents]
231 set header [string range $contents 0 [expr {$hdrend - 1}]]
232 set comment [string range $contents [expr {$hdrend + 2}] end]
233 foreach line [split $header "\n"] {
234 set tag [lindex $line 0]
235 if {$tag == "author"} {
236 set audate [lindex $line end-1]
237 set auname [lrange $line 1 end-2]
238 } elseif {$tag == "committer"} {
239 set comdate [lindex $line end-1]
240 set comname [lrange $line 1 end-2]
244 # take the first line of the comment as the headline
245 set i [string first "\n" $comment]
247 set headline [string trim [string range $comment 0 $i]]
249 set headline $comment
252 # git-rev-list indents the comment by 4 spaces;
253 # if we got this via git-cat-file, add the indentation
255 foreach line [split $comment "\n"] {
256 append newcomment " "
257 append newcomment $line
258 append newcomment "\n"
260 set comment $newcomment
262 if {$comdate != {}} {
263 set cdate($id) $comdate
265 set commitinfo($id) [list $headline $auname $audate \
266 $comname $comdate $comment]
269 proc getcommit {id {row {}}} {
270 global commitdata commitrow commitinfo nparents
273 if {![info exists commitrow($id)]} {return 0}
274 set row $commitrow($id)
276 if {$row < [llength $commitdata]} {
277 parsecommit $id [lindex $commitdata $row] 1
280 if {![info exists commitinfo($id)]} {
281 set commitinfo($id) {"No commit information available"}
289 global tagids idtags headids idheads tagcontents
290 global otherrefids idotherrefs
292 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
295 set refd [open [list | git-ls-remote [gitdir]] r]
296 while {0 <= [set n [gets $refd line]]} {
297 if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
301 if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
305 if {$type == "tags"} {
306 set tagids($name) $id
307 lappend idtags($id) $name
312 set commit [exec git-rev-parse "$id^0"]
313 if {"$commit" != "$id"} {
314 set tagids($name) $commit
315 lappend idtags($commit) $name
319 set tagcontents($name) [exec git-cat-file tag "$id"]
321 } elseif { $type == "heads" } {
322 set headids($name) $id
323 lappend idheads($id) $name
325 set otherrefids($name) $id
326 lappend idotherrefs($id) $name
332 proc error_popup msg {
336 message $w.m -text $msg -justify center -aspect 400
337 pack $w.m -side top -fill x -padx 20 -pady 20
338 button $w.ok -text OK -command "destroy $w"
339 pack $w.ok -side bottom -fill x
340 bind $w <Visibility> "grab $w; focus $w"
341 bind $w <Key-Return> "destroy $w"
345 proc makewindow {rargs} {
346 global canv canv2 canv3 linespc charspc ctext cflist textfont
347 global findtype findtypemenu findloc findstring fstring geometry
348 global entries sha1entry sha1string sha1but
349 global maincursor textcursor curtextcursor
350 global rowctxmenu mergemax
353 .bar add cascade -label "File" -menu .bar.file
355 .bar.file add command -label "Update" -command [list updatecommits $rargs]
356 .bar.file add command -label "Reread references" -command rereadrefs
357 .bar.file add command -label "Quit" -command doquit
359 .bar add cascade -label "Edit" -menu .bar.edit
360 .bar.edit add command -label "Preferences" -command doprefs
362 .bar add cascade -label "Help" -menu .bar.help
363 .bar.help add command -label "About gitk" -command about
364 . configure -menu .bar
366 if {![info exists geometry(canv1)]} {
367 set geometry(canv1) [expr {45 * $charspc}]
368 set geometry(canv2) [expr {30 * $charspc}]
369 set geometry(canv3) [expr {15 * $charspc}]
370 set geometry(canvh) [expr {25 * $linespc + 4}]
371 set geometry(ctextw) 80
372 set geometry(ctexth) 30
373 set geometry(cflistw) 30
375 panedwindow .ctop -orient vertical
376 if {[info exists geometry(width)]} {
377 .ctop conf -width $geometry(width) -height $geometry(height)
378 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
379 set geometry(ctexth) [expr {($texth - 8) /
380 [font metrics $textfont -linespace]}]
384 pack .ctop.top.bar -side bottom -fill x
385 set cscroll .ctop.top.csb
386 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
387 pack $cscroll -side right -fill y
388 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
389 pack .ctop.top.clist -side top -fill both -expand 1
391 set canv .ctop.top.clist.canv
392 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
394 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
395 .ctop.top.clist add $canv
396 set canv2 .ctop.top.clist.canv2
397 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
398 -bg white -bd 0 -yscrollincr $linespc
399 .ctop.top.clist add $canv2
400 set canv3 .ctop.top.clist.canv3
401 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
402 -bg white -bd 0 -yscrollincr $linespc
403 .ctop.top.clist add $canv3
404 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
406 set sha1entry .ctop.top.bar.sha1
407 set entries $sha1entry
408 set sha1but .ctop.top.bar.sha1label
409 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
410 -command gotocommit -width 8
411 $sha1but conf -disabledforeground [$sha1but cget -foreground]
412 pack .ctop.top.bar.sha1label -side left
413 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
414 trace add variable sha1string write sha1change
415 pack $sha1entry -side left -pady 2
417 image create bitmap bm-left -data {
418 #define left_width 16
419 #define left_height 16
420 static unsigned char left_bits[] = {
421 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
422 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
423 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
425 image create bitmap bm-right -data {
426 #define right_width 16
427 #define right_height 16
428 static unsigned char right_bits[] = {
429 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
430 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
431 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
433 button .ctop.top.bar.leftbut -image bm-left -command goback \
434 -state disabled -width 26
435 pack .ctop.top.bar.leftbut -side left -fill y
436 button .ctop.top.bar.rightbut -image bm-right -command goforw \
437 -state disabled -width 26
438 pack .ctop.top.bar.rightbut -side left -fill y
440 button .ctop.top.bar.findbut -text "Find" -command dofind
441 pack .ctop.top.bar.findbut -side left
443 set fstring .ctop.top.bar.findstring
444 lappend entries $fstring
445 entry $fstring -width 30 -font $textfont -textvariable findstring
446 pack $fstring -side left -expand 1 -fill x
448 set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
449 findtype Exact IgnCase Regexp]
450 set findloc "All fields"
451 tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
452 Comments Author Committer Files Pickaxe
453 pack .ctop.top.bar.findloc -side right
454 pack .ctop.top.bar.findtype -side right
455 # for making sure type==Exact whenever loc==Pickaxe
456 trace add variable findloc write findlocchange
458 panedwindow .ctop.cdet -orient horizontal
460 frame .ctop.cdet.left
461 set ctext .ctop.cdet.left.ctext
462 text $ctext -bg white -state disabled -font $textfont \
463 -width $geometry(ctextw) -height $geometry(ctexth) \
464 -yscrollcommand ".ctop.cdet.left.sb set" -wrap none
465 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
466 pack .ctop.cdet.left.sb -side right -fill y
467 pack $ctext -side left -fill both -expand 1
468 .ctop.cdet add .ctop.cdet.left
470 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
471 $ctext tag conf hunksep -fore blue
472 $ctext tag conf d0 -fore red
473 $ctext tag conf d1 -fore "#00a000"
474 $ctext tag conf m0 -fore red
475 $ctext tag conf m1 -fore blue
476 $ctext tag conf m2 -fore green
477 $ctext tag conf m3 -fore purple
478 $ctext tag conf m4 -fore brown
479 $ctext tag conf m5 -fore "#009090"
480 $ctext tag conf m6 -fore magenta
481 $ctext tag conf m7 -fore "#808000"
482 $ctext tag conf m8 -fore "#009000"
483 $ctext tag conf m9 -fore "#ff0080"
484 $ctext tag conf m10 -fore cyan
485 $ctext tag conf m11 -fore "#b07070"
486 $ctext tag conf m12 -fore "#70b0f0"
487 $ctext tag conf m13 -fore "#70f0b0"
488 $ctext tag conf m14 -fore "#f0b070"
489 $ctext tag conf m15 -fore "#ff70b0"
490 $ctext tag conf mmax -fore darkgrey
492 $ctext tag conf mresult -font [concat $textfont bold]
493 $ctext tag conf msep -font [concat $textfont bold]
494 $ctext tag conf found -back yellow
496 frame .ctop.cdet.right
497 set cflist .ctop.cdet.right.cfiles
498 listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
499 -yscrollcommand ".ctop.cdet.right.sb set"
500 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
501 pack .ctop.cdet.right.sb -side right -fill y
502 pack $cflist -side left -fill both -expand 1
503 .ctop.cdet add .ctop.cdet.right
504 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
506 pack .ctop -side top -fill both -expand 1
508 bindall <1> {selcanvline %W %x %y}
509 #bindall <B1-Motion> {selcanvline %W %x %y}
510 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
511 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
512 bindall <2> "allcanvs scan mark 0 %y"
513 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
514 bind . <Key-Up> "selnextline -1"
515 bind . <Key-Down> "selnextline 1"
516 bind . <Key-Right> "goforw"
517 bind . <Key-Left> "goback"
518 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
519 bind . <Key-Next> "allcanvs yview scroll 1 pages"
520 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
521 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
522 bindkey <Key-space> "$ctext yview scroll 1 pages"
523 bindkey p "selnextline -1"
524 bindkey n "selnextline 1"
527 bindkey i "selnextline -1"
528 bindkey k "selnextline 1"
531 bindkey b "$ctext yview scroll -1 pages"
532 bindkey d "$ctext yview scroll 18 units"
533 bindkey u "$ctext yview scroll -18 units"
534 bindkey / {findnext 1}
535 bindkey <Key-Return> {findnext 0}
538 bind . <Control-q> doquit
539 bind . <Control-f> dofind
540 bind . <Control-g> {findnext 0}
541 bind . <Control-r> findprev
542 bind . <Control-equal> {incrfont 1}
543 bind . <Control-KP_Add> {incrfont 1}
544 bind . <Control-minus> {incrfont -1}
545 bind . <Control-KP_Subtract> {incrfont -1}
546 bind $cflist <<ListboxSelect>> listboxsel
547 bind . <Destroy> {savestuff %W}
548 bind . <Button-1> "click %W"
549 bind $fstring <Key-Return> dofind
550 bind $sha1entry <Key-Return> gotocommit
551 bind $sha1entry <<PasteSelection>> clearsha1
553 set maincursor [. cget -cursor]
554 set textcursor [$ctext cget -cursor]
555 set curtextcursor $textcursor
557 set rowctxmenu .rowctxmenu
558 menu $rowctxmenu -tearoff 0
559 $rowctxmenu add command -label "Diff this -> selected" \
560 -command {diffvssel 0}
561 $rowctxmenu add command -label "Diff selected -> this" \
562 -command {diffvssel 1}
563 $rowctxmenu add command -label "Make patch" -command mkpatch
564 $rowctxmenu add command -label "Create tag" -command mktag
565 $rowctxmenu add command -label "Write commit to file" -command writecommit
568 proc scrollcanv {cscroll f0 f1} {
573 # when we make a key binding for the toplevel, make sure
574 # it doesn't get triggered when that key is pressed in the
575 # find string entry widget.
576 proc bindkey {ev script} {
579 set escript [bind Entry $ev]
580 if {$escript == {}} {
581 set escript [bind Entry <Key>]
584 bind $e $ev "$escript; break"
588 # set the focus back to the toplevel for any click outside
599 global canv canv2 canv3 ctext cflist mainfont textfont
600 global stuffsaved findmergefiles maxgraphpct
603 if {$stuffsaved} return
604 if {![winfo viewable .]} return
606 set f [open "~/.gitk-new" w]
607 puts $f [list set mainfont $mainfont]
608 puts $f [list set textfont $textfont]
609 puts $f [list set findmergefiles $findmergefiles]
610 puts $f [list set maxgraphpct $maxgraphpct]
611 puts $f [list set maxwidth $maxwidth]
612 puts $f "set geometry(width) [winfo width .ctop]"
613 puts $f "set geometry(height) [winfo height .ctop]"
614 puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
615 puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]"
616 puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]"
617 puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]"
618 set wid [expr {([winfo width $ctext] - 8) \
619 / [font measure $textfont "0"]}]
620 puts $f "set geometry(ctextw) $wid"
621 set wid [expr {([winfo width $cflist] - 11) \
622 / [font measure [$cflist cget -font] "0"]}]
623 puts $f "set geometry(cflistw) $wid"
625 file rename -force "~/.gitk-new" "~/.gitk"
630 proc resizeclistpanes {win w} {
632 if {[info exists oldwidth($win)]} {
633 set s0 [$win sash coord 0]
634 set s1 [$win sash coord 1]
636 set sash0 [expr {int($w/2 - 2)}]
637 set sash1 [expr {int($w*5/6 - 2)}]
639 set factor [expr {1.0 * $w / $oldwidth($win)}]
640 set sash0 [expr {int($factor * [lindex $s0 0])}]
641 set sash1 [expr {int($factor * [lindex $s1 0])}]
645 if {$sash1 < $sash0 + 20} {
646 set sash1 [expr {$sash0 + 20}]
648 if {$sash1 > $w - 10} {
649 set sash1 [expr {$w - 10}]
650 if {$sash0 > $sash1 - 20} {
651 set sash0 [expr {$sash1 - 20}]
655 $win sash place 0 $sash0 [lindex $s0 1]
656 $win sash place 1 $sash1 [lindex $s1 1]
658 set oldwidth($win) $w
661 proc resizecdetpanes {win w} {
663 if {[info exists oldwidth($win)]} {
664 set s0 [$win sash coord 0]
666 set sash0 [expr {int($w*3/4 - 2)}]
668 set factor [expr {1.0 * $w / $oldwidth($win)}]
669 set sash0 [expr {int($factor * [lindex $s0 0])}]
673 if {$sash0 > $w - 15} {
674 set sash0 [expr {$w - 15}]
677 $win sash place 0 $sash0 [lindex $s0 1]
679 set oldwidth($win) $w
683 global canv canv2 canv3
689 proc bindall {event action} {
690 global canv canv2 canv3
691 bind $canv $event $action
692 bind $canv2 $event $action
693 bind $canv3 $event $action
698 if {[winfo exists $w]} {
703 wm title $w "About gitk"
705 Gitk - a commit viewer for git
707 Copyright © 2005-2006 Paul Mackerras
709 Use and redistribute under the terms of the GNU General Public License} \
710 -justify center -aspect 400
711 pack $w.m -side top -fill x -padx 20 -pady 20
712 button $w.ok -text Close -command "destroy $w"
713 pack $w.ok -side bottom
716 proc shortids {ids} {
719 if {[llength $id] > 1} {
720 lappend res [shortids $id]
721 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
722 lappend res [string range $id 0 7]
730 proc incrange {l x o} {
735 lset l $x [expr {$e + $o}]
744 for {} {$n > 0} {incr n -1} {
750 proc usedinrange {id l1 l2} {
751 global children commitrow
753 if {[info exists commitrow($id)]} {
754 set r $commitrow($id)
755 if {$l1 <= $r && $r <= $l2} {
756 return [expr {$r - $l1 + 1}]
759 foreach c $children($id) {
760 if {[info exists commitrow($c)]} {
762 if {$l1 <= $r && $r <= $l2} {
763 return [expr {$r - $l1 + 1}]
770 proc sanity {row {full 0}} {
771 global rowidlist rowoffsets
774 set ids [lindex $rowidlist $row]
777 if {$id eq {}} continue
778 if {$col < [llength $ids] - 1 &&
779 [lsearch -exact -start [expr {$col+1}] $ids $id] >= 0} {
780 puts "oops: [shortids $id] repeated in row $row col $col: {[shortids [lindex $rowidlist $row]]}"
782 set o [lindex $rowoffsets $row $col]
788 if {[lindex $rowidlist $y $x] != $id} {
789 puts "oops: rowoffsets wrong at row [expr {$y+1}] col [expr {$x-$o}]"
790 puts " id=[shortids $id] check started at row $row"
791 for {set i $row} {$i >= $y} {incr i -1} {
792 puts " row $i ids={[shortids [lindex $rowidlist $i]]} offs={[lindex $rowoffsets $i]}"
797 set o [lindex $rowoffsets $y $x]
802 proc makeuparrow {oid x y z} {
803 global rowidlist rowoffsets uparrowlen idrowranges
805 for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
808 set off0 [lindex $rowoffsets $y]
809 for {set x0 $x} {1} {incr x0} {
810 if {$x0 >= [llength $off0]} {
811 set x0 [llength [lindex $rowoffsets [expr {$y-1}]]]
814 set z [lindex $off0 $x0]
820 set z [expr {$x0 - $x}]
821 lset rowidlist $y [linsert [lindex $rowidlist $y] $x $oid]
822 lset rowoffsets $y [linsert [lindex $rowoffsets $y] $x $z]
824 set tmp [lreplace [lindex $rowoffsets $y] $x $x {}]
825 lset rowoffsets $y [incrange $tmp [expr {$x+1}] -1]
826 lappend idrowranges($oid) $y
830 global rowidlist rowoffsets displayorder
831 global rowlaidout rowoptim
832 global idinlist rowchk
833 global commitidx numcommits
842 catch {unset idinlist}
848 proc visiblerows {} {
849 global canv numcommits linespc
851 set ymax [lindex [$canv cget -scrollregion] 3]
852 if {$ymax eq {} || $ymax == 0} return
854 set y0 [expr {int([lindex $f 0] * $ymax)}]
855 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
859 set y1 [expr {int([lindex $f 1] * $ymax)}]
860 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
861 if {$r1 >= $numcommits} {
862 set r1 [expr {$numcommits - 1}]
864 return [list $r0 $r1]
868 global rowlaidout rowoptim commitidx numcommits optim_delay
872 set rowlaidout [layoutrows $row $commitidx 0]
873 set orow [expr {$rowlaidout - $uparrowlen - 1}]
874 if {$orow > $rowoptim} {
875 checkcrossings $rowoptim $orow
876 optimize_rows $rowoptim 0 $orow
879 set canshow [expr {$rowoptim - $optim_delay}]
880 if {$canshow > $numcommits} {
885 proc showstuff {canshow} {
887 global canvy0 linespc
888 global linesegends idrowranges idrangedrawn
890 if {$numcommits == 0} {
896 set numcommits $canshow
897 allcanvs conf -scrollregion \
898 [list 0 0 0 [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]]
899 set rows [visiblerows]
900 set r0 [lindex $rows 0]
901 set r1 [lindex $rows 1]
902 for {set r $row} {$r < $canshow} {incr r} {
903 if {[info exists linesegends($r)]} {
904 foreach id $linesegends($r) {
906 foreach {s e} $idrowranges($id) {
908 if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
909 && ![info exists idrangedrawn($id,$i)]} {
911 set idrangedrawn($id,$i) 1
917 if {$canshow > $r1} {
920 while {$row < $canshow} {
926 proc layoutrows {row endrow last} {
927 global rowidlist rowoffsets displayorder
928 global uparrowlen downarrowlen maxwidth mingaplen
929 global nchildren parents nparents
930 global idrowranges linesegends
932 global idinlist rowchk
934 set idlist [lindex $rowidlist $row]
935 set offs [lindex $rowoffsets $row]
936 while {$row < $endrow} {
937 set id [lindex $displayorder $row]
940 foreach p $parents($id) {
941 if {![info exists idinlist($p)]} {
943 } elseif {!$idinlist($p)} {
947 set nev [expr {[llength $idlist] + [llength $newolds]
948 + [llength $oldolds] - $maxwidth + 1}]
950 if {!$last && $row + $uparrowlen + $mingaplen >= $commitidx} break
951 for {set x [llength $idlist]} {[incr x -1] >= 0} {} {
952 set i [lindex $idlist $x]
953 if {![info exists rowchk($i)] || $row >= $rowchk($i)} {
954 set r [usedinrange $i [expr {$row - $downarrowlen}] \
955 [expr {$row + $uparrowlen + $mingaplen}]]
957 set idlist [lreplace $idlist $x $x]
958 set offs [lreplace $offs $x $x]
959 set offs [incrange $offs $x 1]
961 lappend linesegends($row) $i
962 lappend idrowranges($i) [expr {$row-1}]
963 if {[incr nev -1] <= 0} break
966 set rowchk($id) [expr {$row + $r}]
969 lset rowidlist $row $idlist
970 lset rowoffsets $row $offs
972 set col [lsearch -exact $idlist $id]
974 set col [llength $idlist]
976 lset rowidlist $row $idlist
978 if {$nchildren($id) > 0} {
979 set z [expr {[llength [lindex $rowidlist [expr {$row-1}]]] - $col}]
983 lset rowoffsets $row $offs
985 makeuparrow $id $col $row $z
990 if {[info exists idrowranges($id)]} {
991 lappend linesegends($row) $id
992 lappend idrowranges($id) $row
995 set offs [ntimes [llength $idlist] 0]
996 set l [llength $newolds]
997 set idlist [eval lreplace \$idlist $col $col $newolds]
1000 set offs [lrange $offs 0 [expr {$col - 1}]]
1001 foreach x $newolds {
1006 set tmp [expr {[llength $idlist] - [llength $offs]}]
1008 set offs [concat $offs [ntimes $tmp $o]]
1013 foreach i $newolds {
1015 set idrowranges($i) $row
1018 foreach oid $oldolds {
1019 set idinlist($oid) 1
1020 set idlist [linsert $idlist $col $oid]
1021 set offs [linsert $offs $col $o]
1022 makeuparrow $oid $col $row $o
1025 lappend rowidlist $idlist
1026 lappend rowoffsets $offs
1031 proc addextraid {id row} {
1032 global displayorder commitrow commitinfo nparents
1036 lappend displayorder $id
1037 set commitrow($id) $row
1039 if {![info exists commitinfo($id)]} {
1040 set commitinfo($id) {"No commit information available"}
1045 proc layouttail {} {
1046 global rowidlist rowoffsets idinlist commitidx
1047 global idrowranges linesegends
1050 set idlist [lindex $rowidlist $row]
1051 while {$idlist ne {}} {
1052 set col [expr {[llength $idlist] - 1}]
1053 set id [lindex $idlist $col]
1056 lappend linesegends($row) $id
1057 lappend idrowranges($id) $row
1059 set offs [ntimes $col 0]
1060 set idlist [lreplace $idlist $col $col]
1061 lappend rowidlist $idlist
1062 lappend rowoffsets $offs
1065 foreach id [array names idinlist] {
1067 lset rowidlist $row [list $id]
1068 lset rowoffsets $row 0
1069 makeuparrow $id 0 $row 0
1070 lappend linesegends($row) $id
1071 lappend idrowranges($id) $row
1073 lappend rowidlist {}
1074 lappend rowoffsets {}
1078 proc insert_pad {row col npad} {
1079 global rowidlist rowoffsets
1081 set pad [ntimes $npad {}]
1082 lset rowidlist $row [eval linsert [list [lindex $rowidlist $row]] $col $pad]
1083 set tmp [eval linsert [list [lindex $rowoffsets $row]] $col $pad]
1084 lset rowoffsets $row [incrange $tmp [expr {$col + $npad}] [expr {-$npad}]]
1087 proc optimize_rows {row col endrow} {
1088 global rowidlist rowoffsets idrowranges
1090 for {} {$row < $endrow} {incr row} {
1091 set idlist [lindex $rowidlist $row]
1092 set offs [lindex $rowoffsets $row]
1094 for {} {$col < [llength $offs]} {incr col} {
1095 if {[lindex $idlist $col] eq {}} {
1099 set z [lindex $offs $col]
1100 if {$z eq {}} continue
1102 set x0 [expr {$col + $z}]
1103 set y0 [expr {$row - 1}]
1104 set z0 [lindex $rowoffsets $y0 $x0]
1106 set id [lindex $idlist $col]
1107 if {[info exists idrowranges($id)] &&
1108 $y0 > [lindex $idrowranges($id) 0]} {
1112 if {$z < -1 || ($z < 0 && $isarrow)} {
1113 set npad [expr {-1 - $z + $isarrow}]
1114 set offs [incrange $offs $col $npad]
1115 insert_pad $y0 $x0 $npad
1117 optimize_rows $y0 $x0 $row
1119 set z [lindex $offs $col]
1120 set x0 [expr {$col + $z}]
1121 set z0 [lindex $rowoffsets $y0 $x0]
1122 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
1123 set npad [expr {$z - 1 + $isarrow}]
1124 set y1 [expr {$row + 1}]
1125 set offs2 [lindex $rowoffsets $y1]
1129 if {$z eq {} || $x1 + $z < $col} continue
1130 if {$x1 + $z > $col} {
1133 lset rowoffsets $y1 [incrange $offs2 $x1 $npad]
1136 set pad [ntimes $npad {}]
1137 set idlist [eval linsert \$idlist $col $pad]
1138 set tmp [eval linsert \$offs $col $pad]
1140 set offs [incrange $tmp $col [expr {-$npad}]]
1141 set z [lindex $offs $col]
1144 if {$z0 ne {} && $z < 0 && $z0 > 0} {
1145 insert_pad $y0 $x0 1
1146 set offs [incrange $offs $col 1]
1147 optimize_rows $y0 [expr {$x0 + 1}] $row
1151 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
1152 set o [lindex $offs $col]
1153 if {$o eq {} || $o <= 0} break
1155 if {[incr col] < [llength $idlist]} {
1156 set y1 [expr {$row + 1}]
1157 set offs2 [lindex $rowoffsets $y1]
1161 if {$z eq {} || $x1 + $z < $col} continue
1162 lset rowoffsets $y1 [incrange $offs2 $x1 1]
1165 set idlist [linsert $idlist $col {}]
1166 set tmp [linsert $offs $col {}]
1168 set offs [incrange $tmp $col -1]
1171 lset rowidlist $row $idlist
1172 lset rowoffsets $row $offs
1178 global canvx0 linespc
1179 return [expr {$canvx0 + $col * $linespc}]
1183 global canvy0 linespc
1184 return [expr {$canvy0 + $row * $linespc}]
1187 proc linewidth {id} {
1188 global thickerline lthickness
1191 if {[info exists thickerline] && $id eq $thickerline} {
1192 set wid [expr {2 * $lthickness}]
1197 proc drawlineseg {id i} {
1198 global rowoffsets rowidlist idrowranges
1199 global canv colormap
1201 set startrow [lindex $idrowranges($id) [expr {2 * $i}]]
1202 set row [lindex $idrowranges($id) [expr {2 * $i + 1}]]
1203 if {$startrow == $row} return
1206 set col [lsearch -exact [lindex $rowidlist $row] $id]
1208 puts "oops: drawline: id $id not on row $row"
1214 set o [lindex $rowoffsets $row $col]
1217 # changing direction
1218 set x [xc $row $col]
1220 lappend coords $x $y
1226 if {$coords eq {}} return
1227 set last [expr {[llength $idrowranges($id)] / 2 - 1}]
1228 set arrow [expr {2 * ($i > 0) + ($i < $last)}]
1229 set arrow [lindex {none first last both} $arrow]
1230 set x [xc $row $col]
1232 lappend coords $x $y
1233 set t [$canv create line $coords -width [linewidth $id] \
1234 -fill $colormap($id) -tags lines.$id -arrow $arrow]
1239 proc drawparentlinks {id row col olds} {
1240 global rowidlist canv colormap
1242 set row2 [expr {$row + 1}]
1243 set x [xc $row $col]
1246 set ids [lindex $rowidlist $row2]
1247 # rmx = right-most X coord used
1250 set i [lsearch -exact $ids $p]
1252 puts "oops, parent $p of $id not in list"
1256 # should handle duplicated parents here...
1257 set coords [list $x $y]
1258 if {$i < $col - 1} {
1259 lappend coords [xc $row [expr {$i + 1}]] $y
1260 } elseif {$i > $col + 1} {
1261 lappend coords [xc $row [expr {$i - 1}]] $y
1263 set x2 [xc $row2 $i]
1267 lappend coords $x2 $y2
1268 set t [$canv create line $coords -width [linewidth $p] \
1269 -fill $colormap($p) -tags lines.$p]
1276 proc drawlines {id} {
1277 global colormap canv
1278 global idrowranges idrangedrawn
1279 global children iddrawn commitrow rowidlist
1281 $canv delete lines.$id
1282 set nr [expr {[llength $idrowranges($id)] / 2}]
1283 for {set i 0} {$i < $nr} {incr i} {
1284 if {[info exists idrangedrawn($id,$i)]} {
1288 if {[info exists children($id)]} {
1289 foreach child $children($id) {
1290 if {[info exists iddrawn($child)]} {
1291 set row $commitrow($child)
1292 set col [lsearch -exact [lindex $rowidlist $row] $child]
1294 drawparentlinks $child $row $col [list $id]
1301 proc drawcmittext {id row col rmx} {
1302 global linespc canv canv2 canv3 canvy0
1303 global commitlisted commitinfo rowidlist
1304 global rowtextx idpos idtags idheads idotherrefs
1305 global linehtag linentag linedtag
1306 global mainfont namefont
1308 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
1309 set x [xc $row $col]
1311 set orad [expr {$linespc / 3}]
1312 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
1313 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
1314 -fill $ofill -outline black -width 1]
1316 $canv bind $t <1> {selcanvline {} %x %y}
1317 set xt [xc $row [llength [lindex $rowidlist $row]]]
1321 set rowtextx($row) $xt
1322 set idpos($id) [list $x $xt $y]
1323 if {[info exists idtags($id)] || [info exists idheads($id)]
1324 || [info exists idotherrefs($id)]} {
1325 set xt [drawtags $id $x $xt $y]
1327 set headline [lindex $commitinfo($id) 0]
1328 set name [lindex $commitinfo($id) 1]
1329 set date [lindex $commitinfo($id) 2]
1330 set date [formatdate $date]
1331 set linehtag($row) [$canv create text $xt $y -anchor w \
1332 -text $headline -font $mainfont ]
1333 $canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
1334 set linentag($row) [$canv2 create text 3 $y -anchor w \
1335 -text $name -font $namefont]
1336 set linedtag($row) [$canv3 create text 3 $y -anchor w \
1337 -text $date -font $mainfont]
1340 proc drawcmitrow {row} {
1341 global displayorder rowidlist
1342 global idrowranges idrangedrawn iddrawn
1343 global commitinfo commitlisted parents numcommits
1346 if {$row >= $numcommits} return
1347 foreach id [lindex $rowidlist $row] {
1348 if {![info exists idrowranges($id)]} continue
1350 foreach {s e} $idrowranges($id) {
1352 if {$row < $s} continue
1355 if {$e < $numcommits && ![info exists idrangedrawn($id,$i)]} {
1357 set idrangedrawn($id,$i) 1
1364 set id [lindex $displayorder $row]
1365 if {[info exists iddrawn($id)]} return
1366 set col [lsearch -exact [lindex $rowidlist $row] $id]
1368 puts "oops, row $row id $id not in list"
1371 if {![info exists commitinfo($id)]} {
1375 if {[info exists commitlisted($id)] && [info exists parents($id)]
1376 && $parents($id) ne {}} {
1377 set rmx [drawparentlinks $id $row $col $parents($id)]
1381 drawcmittext $id $row $col $rmx
1385 proc drawfrac {f0 f1} {
1386 global numcommits canv
1389 set ymax [lindex [$canv cget -scrollregion] 3]
1390 if {$ymax eq {} || $ymax == 0} return
1391 set y0 [expr {int($f0 * $ymax)}]
1392 set row [expr {int(($y0 - 3) / $linespc) - 1}]
1396 set y1 [expr {int($f1 * $ymax)}]
1397 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
1398 if {$endrow >= $numcommits} {
1399 set endrow [expr {$numcommits - 1}]
1401 for {} {$row <= $endrow} {incr row} {
1406 proc drawvisible {} {
1408 eval drawfrac [$canv yview]
1411 proc clear_display {} {
1412 global iddrawn idrangedrawn
1415 catch {unset iddrawn}
1416 catch {unset idrangedrawn}
1419 proc assigncolor {id} {
1420 global colormap colors nextcolor
1421 global parents nparents children nchildren
1422 global cornercrossings crossings
1424 if {[info exists colormap($id)]} return
1425 set ncolors [llength $colors]
1426 if {$nchildren($id) == 1} {
1427 set child [lindex $children($id) 0]
1428 if {[info exists colormap($child)]
1429 && $nparents($child) == 1} {
1430 set colormap($id) $colormap($child)
1435 if {[info exists cornercrossings($id)]} {
1436 foreach x $cornercrossings($id) {
1437 if {[info exists colormap($x)]
1438 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1439 lappend badcolors $colormap($x)
1442 if {[llength $badcolors] >= $ncolors} {
1446 set origbad $badcolors
1447 if {[llength $badcolors] < $ncolors - 1} {
1448 if {[info exists crossings($id)]} {
1449 foreach x $crossings($id) {
1450 if {[info exists colormap($x)]
1451 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1452 lappend badcolors $colormap($x)
1455 if {[llength $badcolors] >= $ncolors} {
1456 set badcolors $origbad
1459 set origbad $badcolors
1461 if {[llength $badcolors] < $ncolors - 1} {
1462 foreach child $children($id) {
1463 if {[info exists colormap($child)]
1464 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1465 lappend badcolors $colormap($child)
1467 if {[info exists parents($child)]} {
1468 foreach p $parents($child) {
1469 if {[info exists colormap($p)]
1470 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1471 lappend badcolors $colormap($p)
1476 if {[llength $badcolors] >= $ncolors} {
1477 set badcolors $origbad
1480 for {set i 0} {$i <= $ncolors} {incr i} {
1481 set c [lindex $colors $nextcolor]
1482 if {[incr nextcolor] >= $ncolors} {
1485 if {[lsearch -exact $badcolors $c]} break
1487 set colormap($id) $c
1490 proc bindline {t id} {
1493 $canv bind $t <Enter> "lineenter %x %y $id"
1494 $canv bind $t <Motion> "linemotion %x %y $id"
1495 $canv bind $t <Leave> "lineleave $id"
1496 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1499 proc drawtags {id x xt y1} {
1500 global idtags idheads idotherrefs
1501 global linespc lthickness
1502 global canv mainfont commitrow rowtextx
1507 if {[info exists idtags($id)]} {
1508 set marks $idtags($id)
1509 set ntags [llength $marks]
1511 if {[info exists idheads($id)]} {
1512 set marks [concat $marks $idheads($id)]
1513 set nheads [llength $idheads($id)]
1515 if {[info exists idotherrefs($id)]} {
1516 set marks [concat $marks $idotherrefs($id)]
1522 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1523 set yt [expr {$y1 - 0.5 * $linespc}]
1524 set yb [expr {$yt + $linespc - 1}]
1527 foreach tag $marks {
1528 set wid [font measure $mainfont $tag]
1531 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1533 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1534 -width $lthickness -fill black -tags tag.$id]
1536 foreach tag $marks x $xvals wid $wvals {
1537 set xl [expr {$x + $delta}]
1538 set xr [expr {$x + $delta + $wid + $lthickness}]
1539 if {[incr ntags -1] >= 0} {
1541 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
1542 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
1543 -width 1 -outline black -fill yellow -tags tag.$id]
1544 $canv bind $t <1> [list showtag $tag 1]
1545 set rowtextx($commitrow($id)) [expr {$xr + $linespc}]
1547 # draw a head or other ref
1548 if {[incr nheads -1] >= 0} {
1553 set xl [expr {$xl - $delta/2}]
1554 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1555 -width 1 -outline black -fill $col -tags tag.$id
1557 set t [$canv create text $xl $y1 -anchor w -text $tag \
1558 -font $mainfont -tags tag.$id]
1560 $canv bind $t <1> [list showtag $tag 1]
1566 proc checkcrossings {row endrow} {
1567 global displayorder parents rowidlist
1569 for {} {$row < $endrow} {incr row} {
1570 set id [lindex $displayorder $row]
1571 set i [lsearch -exact [lindex $rowidlist $row] $id]
1572 if {$i < 0} continue
1573 set idlist [lindex $rowidlist [expr {$row+1}]]
1574 foreach p $parents($id) {
1575 set j [lsearch -exact $idlist $p]
1578 notecrossings $row $p $j $i [expr {$j+1}]
1579 } elseif {$j > $i + 1} {
1580 notecrossings $row $p $i $j [expr {$j-1}]
1587 proc notecrossings {row id lo hi corner} {
1588 global rowidlist crossings cornercrossings
1590 for {set i $lo} {[incr i] < $hi} {} {
1591 set p [lindex [lindex $rowidlist $row] $i]
1592 if {$p == {}} continue
1593 if {$i == $corner} {
1594 if {![info exists cornercrossings($id)]
1595 || [lsearch -exact $cornercrossings($id) $p] < 0} {
1596 lappend cornercrossings($id) $p
1598 if {![info exists cornercrossings($p)]
1599 || [lsearch -exact $cornercrossings($p) $id] < 0} {
1600 lappend cornercrossings($p) $id
1603 if {![info exists crossings($id)]
1604 || [lsearch -exact $crossings($id) $p] < 0} {
1605 lappend crossings($id) $p
1607 if {![info exists crossings($p)]
1608 || [lsearch -exact $crossings($p) $id] < 0} {
1609 lappend crossings($p) $id
1615 proc xcoord {i level ln} {
1616 global canvx0 xspc1 xspc2
1618 set x [expr {$canvx0 + $i * $xspc1($ln)}]
1619 if {$i > 0 && $i == $level} {
1620 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
1621 } elseif {$i > $level} {
1622 set x [expr {$x + $xspc2 - $xspc1($ln)}]
1627 proc finishcommits {} {
1628 global commitidx phase
1629 global canv mainfont ctext maincursor textcursor
1631 if {$commitidx > 0} {
1635 $canv create text 3 3 -anchor nw -text "No commits selected" \
1636 -font $mainfont -tags textitems
1638 . config -cursor $maincursor
1639 settextcursor $textcursor
1643 # Don't change the text pane cursor if it is currently the hand cursor,
1644 # showing that we are over a sha1 ID link.
1645 proc settextcursor {c} {
1646 global ctext curtextcursor
1648 if {[$ctext cget -cursor] == $curtextcursor} {
1649 $ctext config -cursor $c
1651 set curtextcursor $c
1657 global canvy0 numcommits linespc
1658 global rowlaidout commitidx
1661 layoutrows $rowlaidout $commitidx 1
1663 optimize_rows $row 0 $commitidx
1664 showstuff $commitidx
1666 set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
1667 #puts "overall $drawmsecs ms for $numcommits commits"
1670 proc findmatches {f} {
1671 global findtype foundstring foundstrlen
1672 if {$findtype == "Regexp"} {
1673 set matches [regexp -indices -all -inline $foundstring $f]
1675 if {$findtype == "IgnCase"} {
1676 set str [string tolower $f]
1682 while {[set j [string first $foundstring $str $i]] >= 0} {
1683 lappend matches [list $j [expr {$j+$foundstrlen-1}]]
1684 set i [expr {$j + $foundstrlen}]
1691 global findtype findloc findstring markedmatches commitinfo
1692 global numcommits displayorder linehtag linentag linedtag
1693 global mainfont namefont canv canv2 canv3 selectedline
1694 global matchinglines foundstring foundstrlen matchstring
1700 set matchinglines {}
1701 if {$findloc == "Pickaxe"} {
1705 if {$findtype == "IgnCase"} {
1706 set foundstring [string tolower $findstring]
1708 set foundstring $findstring
1710 set foundstrlen [string length $findstring]
1711 if {$foundstrlen == 0} return
1712 regsub -all {[*?\[\\]} $foundstring {\\&} matchstring
1713 set matchstring "*$matchstring*"
1714 if {$findloc == "Files"} {
1718 if {![info exists selectedline]} {
1721 set oldsel $selectedline
1724 set fldtypes {Headline Author Date Committer CDate Comment}
1726 foreach d $commitdata {
1728 if {$findtype == "Regexp"} {
1729 set doesmatch [regexp $foundstring $d]
1730 } elseif {$findtype == "IgnCase"} {
1731 set doesmatch [string match -nocase $matchstring $d]
1733 set doesmatch [string match $matchstring $d]
1735 if {!$doesmatch} continue
1736 set id [lindex $displayorder $l]
1737 if {![info exists commitinfo($id)]} {
1740 set info $commitinfo($id)
1742 foreach f $info ty $fldtypes {
1743 if {$findloc != "All fields" && $findloc != $ty} {
1746 set matches [findmatches $f]
1747 if {$matches == {}} continue
1749 if {$ty == "Headline"} {
1751 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1752 } elseif {$ty == "Author"} {
1754 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1755 } elseif {$ty == "Date"} {
1757 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1761 lappend matchinglines $l
1762 if {!$didsel && $l > $oldsel} {
1768 if {$matchinglines == {}} {
1770 } elseif {!$didsel} {
1771 findselectline [lindex $matchinglines 0]
1775 proc findselectline {l} {
1776 global findloc commentend ctext
1778 if {$findloc == "All fields" || $findloc == "Comments"} {
1779 # highlight the matches in the comments
1780 set f [$ctext get 1.0 $commentend]
1781 set matches [findmatches $f]
1782 foreach match $matches {
1783 set start [lindex $match 0]
1784 set end [expr {[lindex $match 1] + 1}]
1785 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1790 proc findnext {restart} {
1791 global matchinglines selectedline
1792 if {![info exists matchinglines]} {
1798 if {![info exists selectedline]} return
1799 foreach l $matchinglines {
1800 if {$l > $selectedline} {
1809 global matchinglines selectedline
1810 if {![info exists matchinglines]} {
1814 if {![info exists selectedline]} return
1816 foreach l $matchinglines {
1817 if {$l >= $selectedline} break
1821 findselectline $prev
1827 proc findlocchange {name ix op} {
1828 global findloc findtype findtypemenu
1829 if {$findloc == "Pickaxe"} {
1835 $findtypemenu entryconf 1 -state $state
1836 $findtypemenu entryconf 2 -state $state
1839 proc stopfindproc {{done 0}} {
1840 global findprocpid findprocfile findids
1841 global ctext findoldcursor phase maincursor textcursor
1842 global findinprogress
1844 catch {unset findids}
1845 if {[info exists findprocpid]} {
1847 catch {exec kill $findprocpid}
1849 catch {close $findprocfile}
1852 if {[info exists findinprogress]} {
1853 unset findinprogress
1854 if {$phase != "incrdraw"} {
1855 . config -cursor $maincursor
1856 settextcursor $textcursor
1861 proc findpatches {} {
1862 global findstring selectedline numcommits
1863 global findprocpid findprocfile
1864 global finddidsel ctext displayorder findinprogress
1865 global findinsertpos
1867 if {$numcommits == 0} return
1869 # make a list of all the ids to search, starting at the one
1870 # after the selected line (if any)
1871 if {[info exists selectedline]} {
1877 for {set i 0} {$i < $numcommits} {incr i} {
1878 if {[incr l] >= $numcommits} {
1881 append inputids [lindex $displayorder $l] "\n"
1885 set f [open [list | git-diff-tree --stdin -s -r -S$findstring \
1888 error_popup "Error starting search process: $err"
1892 set findinsertpos end
1894 set findprocpid [pid $f]
1895 fconfigure $f -blocking 0
1896 fileevent $f readable readfindproc
1898 . config -cursor watch
1900 set findinprogress 1
1903 proc readfindproc {} {
1904 global findprocfile finddidsel
1905 global commitrow matchinglines findinsertpos
1907 set n [gets $findprocfile line]
1909 if {[eof $findprocfile]} {
1917 if {![regexp {^[0-9a-f]{40}} $line id]} {
1918 error_popup "Can't parse git-diff-tree output: $line"
1922 if {![info exists commitrow($id)]} {
1923 puts stderr "spurious id: $id"
1926 set l $commitrow($id)
1930 proc insertmatch {l id} {
1931 global matchinglines findinsertpos finddidsel
1933 if {$findinsertpos == "end"} {
1934 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
1935 set matchinglines [linsert $matchinglines 0 $l]
1938 lappend matchinglines $l
1941 set matchinglines [linsert $matchinglines $findinsertpos $l]
1952 global selectedline numcommits displayorder ctext
1953 global ffileline finddidsel parents nparents
1954 global findinprogress findstartline findinsertpos
1955 global treediffs fdiffid fdiffsneeded fdiffpos
1956 global findmergefiles
1958 if {$numcommits == 0} return
1960 if {[info exists selectedline]} {
1961 set l [expr {$selectedline + 1}]
1966 set findstartline $l
1970 set id [lindex $displayorder $l]
1971 if {$findmergefiles || $nparents($id) == 1} {
1972 if {![info exists treediffs($id)]} {
1973 append diffsneeded "$id\n"
1974 lappend fdiffsneeded $id
1977 if {[incr l] >= $numcommits} {
1980 if {$l == $findstartline} break
1983 # start off a git-diff-tree process if needed
1984 if {$diffsneeded ne {}} {
1986 set df [open [list | git-diff-tree -r --stdin << $diffsneeded] r]
1988 error_popup "Error starting search process: $err"
1991 catch {unset fdiffid}
1993 fconfigure $df -blocking 0
1994 fileevent $df readable [list readfilediffs $df]
1998 set findinsertpos end
1999 set id [lindex $displayorder $l]
2000 . config -cursor watch
2002 set findinprogress 1
2007 proc readfilediffs {df} {
2008 global findid fdiffid fdiffs
2010 set n [gets $df line]
2014 if {[catch {close $df} err]} {
2017 error_popup "Error in git-diff-tree: $err"
2018 } elseif {[info exists findid]} {
2022 error_popup "Couldn't find diffs for $id"
2027 if {[regexp {^([0-9a-f]{40})$} $line match id]} {
2028 # start of a new string of diffs
2032 } elseif {[string match ":*" $line]} {
2033 lappend fdiffs [lindex $line 5]
2037 proc donefilediff {} {
2038 global fdiffid fdiffs treediffs findid
2039 global fdiffsneeded fdiffpos
2041 if {[info exists fdiffid]} {
2042 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffid
2043 && $fdiffpos < [llength $fdiffsneeded]} {
2044 # git-diff-tree doesn't output anything for a commit
2045 # which doesn't change anything
2046 set nullid [lindex $fdiffsneeded $fdiffpos]
2047 set treediffs($nullid) {}
2048 if {[info exists findid] && $nullid eq $findid} {
2056 if {![info exists treediffs($fdiffid)]} {
2057 set treediffs($fdiffid) $fdiffs
2059 if {[info exists findid] && $fdiffid eq $findid} {
2066 proc findcont {id} {
2067 global findid treediffs parents nparents
2068 global ffileline findstartline finddidsel
2069 global displayorder numcommits matchinglines findinprogress
2070 global findmergefiles
2074 if {$findmergefiles || $nparents($id) == 1} {
2075 if {![info exists treediffs($id)]} {
2081 foreach f $treediffs($id) {
2082 set x [findmatches $f]
2092 if {[incr l] >= $numcommits} {
2095 if {$l == $findstartline} break
2096 set id [lindex $displayorder $l]
2104 # mark a commit as matching by putting a yellow background
2105 # behind the headline
2106 proc markheadline {l id} {
2107 global canv mainfont linehtag
2110 set bbox [$canv bbox $linehtag($l)]
2111 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2115 # mark the bits of a headline, author or date that match a find string
2116 proc markmatches {canv l str tag matches font} {
2117 set bbox [$canv bbox $tag]
2118 set x0 [lindex $bbox 0]
2119 set y0 [lindex $bbox 1]
2120 set y1 [lindex $bbox 3]
2121 foreach match $matches {
2122 set start [lindex $match 0]
2123 set end [lindex $match 1]
2124 if {$start > $end} continue
2125 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
2126 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
2127 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
2128 [expr {$x0+$xlen+2}] $y1 \
2129 -outline {} -tags matches -fill yellow]
2134 proc unmarkmatches {} {
2135 global matchinglines findids
2136 allcanvs delete matches
2137 catch {unset matchinglines}
2138 catch {unset findids}
2141 proc selcanvline {w x y} {
2142 global canv canvy0 ctext linespc
2144 set ymax [lindex [$canv cget -scrollregion] 3]
2145 if {$ymax == {}} return
2146 set yfrac [lindex [$canv yview] 0]
2147 set y [expr {$y + $yfrac * $ymax}]
2148 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2153 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2159 proc commit_descriptor {p} {
2162 if {[info exists commitinfo($p)]} {
2163 set l [lindex $commitinfo($p) 0]
2168 # append some text to the ctext widget, and make any SHA1 ID
2169 # that we know about be a clickable link.
2170 proc appendwithlinks {text} {
2171 global ctext commitrow linknum
2173 set start [$ctext index "end - 1c"]
2174 $ctext insert end $text
2175 $ctext insert end "\n"
2176 set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
2180 set linkid [string range $text $s $e]
2181 if {![info exists commitrow($linkid)]} continue
2183 $ctext tag add link "$start + $s c" "$start + $e c"
2184 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2185 $ctext tag bind link$linknum <1> [list selectline $commitrow($linkid) 1]
2188 $ctext tag conf link -foreground blue -underline 1
2189 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2190 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2193 proc selectline {l isnew} {
2194 global canv canv2 canv3 ctext commitinfo selectedline
2195 global displayorder linehtag linentag linedtag
2196 global canvy0 linespc parents nparents children
2197 global cflist currentid sha1entry
2198 global commentend idtags linknum
2199 global mergemax numcommits
2203 if {$l < 0 || $l >= $numcommits} return
2204 set y [expr {$canvy0 + $l * $linespc}]
2205 set ymax [lindex [$canv cget -scrollregion] 3]
2206 set ytop [expr {$y - $linespc - 1}]
2207 set ybot [expr {$y + $linespc + 1}]
2208 set wnow [$canv yview]
2209 set wtop [expr {[lindex $wnow 0] * $ymax}]
2210 set wbot [expr {[lindex $wnow 1] * $ymax}]
2211 set wh [expr {$wbot - $wtop}]
2213 if {$ytop < $wtop} {
2214 if {$ybot < $wtop} {
2215 set newtop [expr {$y - $wh / 2.0}]
2218 if {$newtop > $wtop - $linespc} {
2219 set newtop [expr {$wtop - $linespc}]
2222 } elseif {$ybot > $wbot} {
2223 if {$ytop > $wbot} {
2224 set newtop [expr {$y - $wh / 2.0}]
2226 set newtop [expr {$ybot - $wh}]
2227 if {$newtop < $wtop + $linespc} {
2228 set newtop [expr {$wtop + $linespc}]
2232 if {$newtop != $wtop} {
2236 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2240 if {![info exists linehtag($l)]} return
2242 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2243 -tags secsel -fill [$canv cget -selectbackground]]
2245 $canv2 delete secsel
2246 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2247 -tags secsel -fill [$canv2 cget -selectbackground]]
2249 $canv3 delete secsel
2250 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2251 -tags secsel -fill [$canv3 cget -selectbackground]]
2255 addtohistory [list selectline $l 0]
2260 set id [lindex $displayorder $l]
2262 $sha1entry delete 0 end
2263 $sha1entry insert 0 $id
2264 $sha1entry selection from 0
2265 $sha1entry selection to end
2267 $ctext conf -state normal
2268 $ctext delete 0.0 end
2270 $ctext mark set fmark.0 0.0
2271 $ctext mark gravity fmark.0 left
2272 set info $commitinfo($id)
2273 set date [formatdate [lindex $info 2]]
2274 $ctext insert end "Author: [lindex $info 1] $date\n"
2275 set date [formatdate [lindex $info 4]]
2276 $ctext insert end "Committer: [lindex $info 3] $date\n"
2277 if {[info exists idtags($id)]} {
2278 $ctext insert end "Tags:"
2279 foreach tag $idtags($id) {
2280 $ctext insert end " $tag"
2282 $ctext insert end "\n"
2286 if {$nparents($id) > 1} {
2288 foreach p $parents($id) {
2289 if {$np >= $mergemax} {
2294 $ctext insert end "Parent: " $tag
2295 appendwithlinks [commit_descriptor $p]
2299 if {[info exists parents($id)]} {
2300 foreach p $parents($id) {
2301 append comment "Parent: [commit_descriptor $p]\n"
2306 if {[info exists children($id)]} {
2307 foreach c $children($id) {
2308 append comment "Child: [commit_descriptor $c]\n"
2312 append comment [lindex $info 5]
2314 # make anything that looks like a SHA1 ID be a clickable link
2315 appendwithlinks $comment
2317 $ctext tag delete Comments
2318 $ctext tag remove found 1.0 end
2319 $ctext conf -state disabled
2320 set commentend [$ctext index "end - 1c"]
2322 $cflist delete 0 end
2323 $cflist insert end "Comments"
2324 if {$nparents($id) == 1} {
2326 } elseif {$nparents($id) > 1} {
2331 proc selnextline {dir} {
2333 if {![info exists selectedline]} return
2334 set l [expr {$selectedline + $dir}]
2339 proc unselectline {} {
2342 catch {unset selectedline}
2343 allcanvs delete secsel
2346 proc addtohistory {cmd} {
2347 global history historyindex
2349 if {$historyindex > 0
2350 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2354 if {$historyindex < [llength $history]} {
2355 set history [lreplace $history $historyindex end $cmd]
2357 lappend history $cmd
2360 if {$historyindex > 1} {
2361 .ctop.top.bar.leftbut conf -state normal
2363 .ctop.top.bar.leftbut conf -state disabled
2365 .ctop.top.bar.rightbut conf -state disabled
2369 global history historyindex
2371 if {$historyindex > 1} {
2372 incr historyindex -1
2373 set cmd [lindex $history [expr {$historyindex - 1}]]
2375 .ctop.top.bar.rightbut conf -state normal
2377 if {$historyindex <= 1} {
2378 .ctop.top.bar.leftbut conf -state disabled
2383 global history historyindex
2385 if {$historyindex < [llength $history]} {
2386 set cmd [lindex $history $historyindex]
2389 .ctop.top.bar.leftbut conf -state normal
2391 if {$historyindex >= [llength $history]} {
2392 .ctop.top.bar.rightbut conf -state disabled
2396 proc mergediff {id} {
2397 global parents diffmergeid diffopts mdifffd
2398 global difffilestart
2401 catch {unset difffilestart}
2402 # this doesn't seem to actually affect anything...
2403 set env(GIT_DIFF_OPTS) $diffopts
2404 set cmd [concat | git-diff-tree --no-commit-id --cc $id]
2405 if {[catch {set mdf [open $cmd r]} err]} {
2406 error_popup "Error getting merge diffs: $err"
2409 fconfigure $mdf -blocking 0
2410 set mdifffd($id) $mdf
2411 fileevent $mdf readable [list getmergediffline $mdf $id]
2412 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2415 proc getmergediffline {mdf id} {
2416 global diffmergeid ctext cflist nextupdate nparents mergemax
2417 global difffilestart
2419 set n [gets $mdf line]
2426 if {![info exists diffmergeid] || $id != $diffmergeid} {
2429 $ctext conf -state normal
2430 if {[regexp {^diff --cc (.*)} $line match fname]} {
2431 # start of a new file
2432 $ctext insert end "\n"
2433 set here [$ctext index "end - 1c"]
2434 set i [$cflist index end]
2435 $ctext mark set fmark.$i $here
2436 $ctext mark gravity fmark.$i left
2437 set difffilestart([expr {$i-1}]) $here
2438 $cflist insert end $fname
2439 set l [expr {(78 - [string length $fname]) / 2}]
2440 set pad [string range "----------------------------------------" 1 $l]
2441 $ctext insert end "$pad $fname $pad\n" filesep
2442 } elseif {[regexp {^@@} $line]} {
2443 $ctext insert end "$line\n" hunksep
2444 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
2447 # parse the prefix - one ' ', '-' or '+' for each parent
2448 set np $nparents($id)
2453 for {set j 0} {$j < $np} {incr j} {
2454 set c [string range $line $j $j]
2457 } elseif {$c == "-"} {
2459 } elseif {$c == "+"} {
2468 if {!$isbad && $minuses ne {} && $pluses eq {}} {
2469 # line doesn't appear in result, parents in $minuses have the line
2470 set num [lindex $minuses 0]
2471 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
2472 # line appears in result, parents in $pluses don't have the line
2473 lappend tags mresult
2474 set num [lindex $spaces 0]
2477 if {$num >= $mergemax} {
2482 $ctext insert end "$line\n" $tags
2484 $ctext conf -state disabled
2485 if {[clock clicks -milliseconds] >= $nextupdate} {
2487 fileevent $mdf readable {}
2489 fileevent $mdf readable [list getmergediffline $mdf $id]
2493 proc startdiff {ids} {
2494 global treediffs diffids treepending diffmergeid
2497 catch {unset diffmergeid}
2498 if {![info exists treediffs($ids)]} {
2499 if {![info exists treepending]} {
2507 proc addtocflist {ids} {
2508 global treediffs cflist
2509 foreach f $treediffs($ids) {
2510 $cflist insert end $f
2515 proc gettreediffs {ids} {
2516 global treediff parents treepending
2517 set treepending $ids
2520 {set gdtf [open [concat | git-diff-tree --no-commit-id -r $ids] r]} \
2522 fconfigure $gdtf -blocking 0
2523 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
2526 proc gettreediffline {gdtf ids} {
2527 global treediff treediffs treepending diffids diffmergeid
2529 set n [gets $gdtf line]
2531 if {![eof $gdtf]} return
2533 set treediffs($ids) $treediff
2535 if {$ids != $diffids} {
2536 gettreediffs $diffids
2538 if {[info exists diffmergeid]} {
2546 set file [lindex $line 5]
2547 lappend treediff $file
2550 proc getblobdiffs {ids} {
2551 global diffopts blobdifffd diffids env curdifftag curtagstart
2552 global difffilestart nextupdate diffinhdr treediffs
2554 set env(GIT_DIFF_OPTS) $diffopts
2555 set cmd [concat | git-diff-tree --no-commit-id -r -p -C $ids]
2556 if {[catch {set bdf [open $cmd r]} err]} {
2557 puts "error getting diffs: $err"
2561 fconfigure $bdf -blocking 0
2562 set blobdifffd($ids) $bdf
2563 set curdifftag Comments
2565 catch {unset difffilestart}
2566 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
2567 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2570 proc getblobdiffline {bdf ids} {
2571 global diffids blobdifffd ctext curdifftag curtagstart
2572 global diffnexthead diffnextnote difffilestart
2573 global nextupdate diffinhdr treediffs
2575 set n [gets $bdf line]
2579 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
2580 $ctext tag add $curdifftag $curtagstart end
2585 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
2588 $ctext conf -state normal
2589 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
2590 # start of a new file
2591 $ctext insert end "\n"
2592 $ctext tag add $curdifftag $curtagstart end
2593 set curtagstart [$ctext index "end - 1c"]
2595 set here [$ctext index "end - 1c"]
2596 set i [lsearch -exact $treediffs($diffids) $fname]
2598 set difffilestart($i) $here
2600 $ctext mark set fmark.$i $here
2601 $ctext mark gravity fmark.$i left
2603 if {$newname != $fname} {
2604 set i [lsearch -exact $treediffs($diffids) $newname]
2606 set difffilestart($i) $here
2608 $ctext mark set fmark.$i $here
2609 $ctext mark gravity fmark.$i left
2612 set curdifftag "f:$fname"
2613 $ctext tag delete $curdifftag
2614 set l [expr {(78 - [string length $header]) / 2}]
2615 set pad [string range "----------------------------------------" 1 $l]
2616 $ctext insert end "$pad $header $pad\n" filesep
2618 } elseif {[regexp {^(---|\+\+\+)} $line]} {
2620 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2621 $line match f1l f1c f2l f2c rest]} {
2622 $ctext insert end "$line\n" hunksep
2625 set x [string range $line 0 0]
2626 if {$x == "-" || $x == "+"} {
2627 set tag [expr {$x == "+"}]
2628 $ctext insert end "$line\n" d$tag
2629 } elseif {$x == " "} {
2630 $ctext insert end "$line\n"
2631 } elseif {$diffinhdr || $x == "\\"} {
2632 # e.g. "\ No newline at end of file"
2633 $ctext insert end "$line\n" filesep
2635 # Something else we don't recognize
2636 if {$curdifftag != "Comments"} {
2637 $ctext insert end "\n"
2638 $ctext tag add $curdifftag $curtagstart end
2639 set curtagstart [$ctext index "end - 1c"]
2640 set curdifftag Comments
2642 $ctext insert end "$line\n" filesep
2645 $ctext conf -state disabled
2646 if {[clock clicks -milliseconds] >= $nextupdate} {
2648 fileevent $bdf readable {}
2650 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
2655 global difffilestart ctext
2656 set here [$ctext index @0,0]
2657 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
2658 if {[$ctext compare $difffilestart($i) > $here]} {
2659 if {![info exists pos]
2660 || [$ctext compare $difffilestart($i) < $pos]} {
2661 set pos $difffilestart($i)
2665 if {[info exists pos]} {
2670 proc listboxsel {} {
2671 global ctext cflist currentid
2672 if {![info exists currentid]} return
2673 set sel [lsort [$cflist curselection]]
2674 if {$sel eq {}} return
2675 set first [lindex $sel 0]
2676 catch {$ctext yview fmark.$first}
2680 global linespc charspc canvx0 canvy0 mainfont
2681 global xspc1 xspc2 lthickness
2683 set linespc [font metrics $mainfont -linespace]
2684 set charspc [font measure $mainfont "m"]
2685 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
2686 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
2687 set lthickness [expr {int($linespc / 9) + 1}]
2688 set xspc1(0) $linespc
2693 global canv canvy0 linespc numcommits
2696 set ymax [lindex [$canv cget -scrollregion] 3]
2697 if {$ymax eq {} || $ymax == 0} return
2698 set span [$canv yview]
2700 allcanvs conf -scrollregion \
2701 [list 0 0 0 [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]]
2702 allcanvs yview moveto [lindex $span 0]
2704 if {[info exists selectedline]} {
2705 selectline $selectedline 0
2709 proc incrfont {inc} {
2710 global mainfont namefont textfont ctext canv phase
2711 global stopped entries
2713 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
2714 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
2715 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
2717 $ctext conf -font $textfont
2718 $ctext tag conf filesep -font [concat $textfont bold]
2719 foreach e $entries {
2720 $e conf -font $mainfont
2722 if {$phase == "getcommits"} {
2723 $canv itemconf textitems -font $mainfont
2729 global sha1entry sha1string
2730 if {[string length $sha1string] == 40} {
2731 $sha1entry delete 0 end
2735 proc sha1change {n1 n2 op} {
2736 global sha1string currentid sha1but
2737 if {$sha1string == {}
2738 || ([info exists currentid] && $sha1string == $currentid)} {
2743 if {[$sha1but cget -state] == $state} return
2744 if {$state == "normal"} {
2745 $sha1but conf -state normal -relief raised -text "Goto: "
2747 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
2751 proc gotocommit {} {
2752 global sha1string currentid commitrow tagids
2753 global displayorder numcommits
2755 if {$sha1string == {}
2756 || ([info exists currentid] && $sha1string == $currentid)} return
2757 if {[info exists tagids($sha1string)]} {
2758 set id $tagids($sha1string)
2760 set id [string tolower $sha1string]
2761 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
2763 foreach i $displayorder {
2764 if {[string match $id* $i]} {
2768 if {$matches ne {}} {
2769 if {[llength $matches] > 1} {
2770 error_popup "Short SHA1 id $id is ambiguous"
2773 set id [lindex $matches 0]
2777 if {[info exists commitrow($id)]} {
2778 selectline $commitrow($id) 1
2781 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
2786 error_popup "$type $sha1string is not known"
2789 proc lineenter {x y id} {
2790 global hoverx hovery hoverid hovertimer
2791 global commitinfo canv
2793 if {![info exists commitinfo($id)] && ![getcommit $id]} return
2797 if {[info exists hovertimer]} {
2798 after cancel $hovertimer
2800 set hovertimer [after 500 linehover]
2804 proc linemotion {x y id} {
2805 global hoverx hovery hoverid hovertimer
2807 if {[info exists hoverid] && $id == $hoverid} {
2810 if {[info exists hovertimer]} {
2811 after cancel $hovertimer
2813 set hovertimer [after 500 linehover]
2817 proc lineleave {id} {
2818 global hoverid hovertimer canv
2820 if {[info exists hoverid] && $id == $hoverid} {
2822 if {[info exists hovertimer]} {
2823 after cancel $hovertimer
2831 global hoverx hovery hoverid hovertimer
2832 global canv linespc lthickness
2833 global commitinfo mainfont
2835 set text [lindex $commitinfo($hoverid) 0]
2836 set ymax [lindex [$canv cget -scrollregion] 3]
2837 if {$ymax == {}} return
2838 set yfrac [lindex [$canv yview] 0]
2839 set x [expr {$hoverx + 2 * $linespc}]
2840 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
2841 set x0 [expr {$x - 2 * $lthickness}]
2842 set y0 [expr {$y - 2 * $lthickness}]
2843 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
2844 set y1 [expr {$y + $linespc + 2 * $lthickness}]
2845 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
2846 -fill \#ffff80 -outline black -width 1 -tags hover]
2848 set t [$canv create text $x $y -anchor nw -text $text -tags hover -font $mainfont]
2852 proc clickisonarrow {id y} {
2853 global lthickness idrowranges
2855 set thresh [expr {2 * $lthickness + 6}]
2856 set n [expr {[llength $idrowranges($id)] - 1}]
2857 for {set i 1} {$i < $n} {incr i} {
2858 set row [lindex $idrowranges($id) $i]
2859 if {abs([yc $row] - $y) < $thresh} {
2866 proc arrowjump {id n y} {
2867 global idrowranges canv
2869 # 1 <-> 2, 3 <-> 4, etc...
2870 set n [expr {(($n - 1) ^ 1) + 1}]
2871 set row [lindex $idrowranges($id) $n]
2873 set ymax [lindex [$canv cget -scrollregion] 3]
2874 if {$ymax eq {} || $ymax <= 0} return
2875 set view [$canv yview]
2876 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
2877 set yfrac [expr {$yt / $ymax - $yspan / 2}]
2881 allcanvs yview moveto $yfrac
2884 proc lineclick {x y id isnew} {
2885 global ctext commitinfo children cflist canv thickerline
2887 if {![info exists commitinfo($id)] && ![getcommit $id]} return
2892 # draw this line thicker than normal
2896 set ymax [lindex [$canv cget -scrollregion] 3]
2897 if {$ymax eq {}} return
2898 set yfrac [lindex [$canv yview] 0]
2899 set y [expr {$y + $yfrac * $ymax}]
2901 set dirn [clickisonarrow $id $y]
2903 arrowjump $id $dirn $y
2908 addtohistory [list lineclick $x $y $id 0]
2910 # fill the details pane with info about this line
2911 $ctext conf -state normal
2912 $ctext delete 0.0 end
2913 $ctext tag conf link -foreground blue -underline 1
2914 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2915 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2916 $ctext insert end "Parent:\t"
2917 $ctext insert end $id [list link link0]
2918 $ctext tag bind link0 <1> [list selbyid $id]
2919 set info $commitinfo($id)
2920 $ctext insert end "\n\t[lindex $info 0]\n"
2921 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
2922 set date [formatdate [lindex $info 2]]
2923 $ctext insert end "\tDate:\t$date\n"
2924 if {[info exists children($id)]} {
2925 $ctext insert end "\nChildren:"
2927 foreach child $children($id) {
2929 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
2930 set info $commitinfo($child)
2931 $ctext insert end "\n\t"
2932 $ctext insert end $child [list link link$i]
2933 $ctext tag bind link$i <1> [list selbyid $child]
2934 $ctext insert end "\n\t[lindex $info 0]"
2935 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
2936 set date [formatdate [lindex $info 2]]
2937 $ctext insert end "\n\tDate:\t$date\n"
2940 $ctext conf -state disabled
2942 $cflist delete 0 end
2945 proc normalline {} {
2947 if {[info exists thickerline]} {
2956 if {[info exists commitrow($id)]} {
2957 selectline $commitrow($id) 1
2963 if {![info exists startmstime]} {
2964 set startmstime [clock clicks -milliseconds]
2966 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
2969 proc rowmenu {x y id} {
2970 global rowctxmenu commitrow selectedline rowmenuid
2972 if {![info exists selectedline] || $commitrow($id) eq $selectedline} {
2977 $rowctxmenu entryconfigure 0 -state $state
2978 $rowctxmenu entryconfigure 1 -state $state
2979 $rowctxmenu entryconfigure 2 -state $state
2981 tk_popup $rowctxmenu $x $y
2984 proc diffvssel {dirn} {
2985 global rowmenuid selectedline displayorder
2987 if {![info exists selectedline]} return
2989 set oldid [lindex $displayorder $selectedline]
2990 set newid $rowmenuid
2992 set oldid $rowmenuid
2993 set newid [lindex $displayorder $selectedline]
2995 addtohistory [list doseldiff $oldid $newid]
2996 doseldiff $oldid $newid
2999 proc doseldiff {oldid newid} {
3003 $ctext conf -state normal
3004 $ctext delete 0.0 end
3005 $ctext mark set fmark.0 0.0
3006 $ctext mark gravity fmark.0 left
3007 $cflist delete 0 end
3008 $cflist insert end "Top"
3009 $ctext insert end "From "
3010 $ctext tag conf link -foreground blue -underline 1
3011 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3012 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3013 $ctext tag bind link0 <1> [list selbyid $oldid]
3014 $ctext insert end $oldid [list link link0]
3015 $ctext insert end "\n "
3016 $ctext insert end [lindex $commitinfo($oldid) 0]
3017 $ctext insert end "\n\nTo "
3018 $ctext tag bind link1 <1> [list selbyid $newid]
3019 $ctext insert end $newid [list link link1]
3020 $ctext insert end "\n "
3021 $ctext insert end [lindex $commitinfo($newid) 0]
3022 $ctext insert end "\n"
3023 $ctext conf -state disabled
3024 $ctext tag delete Comments
3025 $ctext tag remove found 1.0 end
3026 startdiff [list $oldid $newid]
3030 global rowmenuid currentid commitinfo patchtop patchnum
3032 if {![info exists currentid]} return
3033 set oldid $currentid
3034 set oldhead [lindex $commitinfo($oldid) 0]
3035 set newid $rowmenuid
3036 set newhead [lindex $commitinfo($newid) 0]
3039 catch {destroy $top}
3041 label $top.title -text "Generate patch"
3042 grid $top.title - -pady 10
3043 label $top.from -text "From:"
3044 entry $top.fromsha1 -width 40 -relief flat
3045 $top.fromsha1 insert 0 $oldid
3046 $top.fromsha1 conf -state readonly
3047 grid $top.from $top.fromsha1 -sticky w
3048 entry $top.fromhead -width 60 -relief flat
3049 $top.fromhead insert 0 $oldhead
3050 $top.fromhead conf -state readonly
3051 grid x $top.fromhead -sticky w
3052 label $top.to -text "To:"
3053 entry $top.tosha1 -width 40 -relief flat
3054 $top.tosha1 insert 0 $newid
3055 $top.tosha1 conf -state readonly
3056 grid $top.to $top.tosha1 -sticky w
3057 entry $top.tohead -width 60 -relief flat
3058 $top.tohead insert 0 $newhead
3059 $top.tohead conf -state readonly
3060 grid x $top.tohead -sticky w
3061 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
3062 grid $top.rev x -pady 10
3063 label $top.flab -text "Output file:"
3064 entry $top.fname -width 60
3065 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3067 grid $top.flab $top.fname -sticky w
3069 button $top.buts.gen -text "Generate" -command mkpatchgo
3070 button $top.buts.can -text "Cancel" -command mkpatchcan
3071 grid $top.buts.gen $top.buts.can
3072 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3073 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3074 grid $top.buts - -pady 10 -sticky ew
3078 proc mkpatchrev {} {
3081 set oldid [$patchtop.fromsha1 get]
3082 set oldhead [$patchtop.fromhead get]
3083 set newid [$patchtop.tosha1 get]
3084 set newhead [$patchtop.tohead get]
3085 foreach e [list fromsha1 fromhead tosha1 tohead] \
3086 v [list $newid $newhead $oldid $oldhead] {
3087 $patchtop.$e conf -state normal
3088 $patchtop.$e delete 0 end
3089 $patchtop.$e insert 0 $v
3090 $patchtop.$e conf -state readonly
3097 set oldid [$patchtop.fromsha1 get]
3098 set newid [$patchtop.tosha1 get]
3099 set fname [$patchtop.fname get]
3100 if {[catch {exec git-diff-tree -p $oldid $newid >$fname &} err]} {
3101 error_popup "Error creating patch: $err"
3103 catch {destroy $patchtop}
3107 proc mkpatchcan {} {
3110 catch {destroy $patchtop}
3115 global rowmenuid mktagtop commitinfo
3119 catch {destroy $top}
3121 label $top.title -text "Create tag"
3122 grid $top.title - -pady 10
3123 label $top.id -text "ID:"
3124 entry $top.sha1 -width 40 -relief flat
3125 $top.sha1 insert 0 $rowmenuid
3126 $top.sha1 conf -state readonly
3127 grid $top.id $top.sha1 -sticky w
3128 entry $top.head -width 60 -relief flat
3129 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3130 $top.head conf -state readonly
3131 grid x $top.head -sticky w
3132 label $top.tlab -text "Tag name:"
3133 entry $top.tag -width 60
3134 grid $top.tlab $top.tag -sticky w
3136 button $top.buts.gen -text "Create" -command mktaggo
3137 button $top.buts.can -text "Cancel" -command mktagcan
3138 grid $top.buts.gen $top.buts.can
3139 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3140 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3141 grid $top.buts - -pady 10 -sticky ew
3146 global mktagtop env tagids idtags
3148 set id [$mktagtop.sha1 get]
3149 set tag [$mktagtop.tag get]
3151 error_popup "No tag name specified"
3154 if {[info exists tagids($tag)]} {
3155 error_popup "Tag \"$tag\" already exists"
3160 set fname [file join $dir "refs/tags" $tag]
3161 set f [open $fname w]
3165 error_popup "Error creating tag: $err"
3169 set tagids($tag) $id
3170 lappend idtags($id) $tag
3174 proc redrawtags {id} {
3175 global canv linehtag commitrow idpos selectedline
3177 if {![info exists commitrow($id)]} return
3178 drawcmitrow $commitrow($id)
3179 $canv delete tag.$id
3180 set xt [eval drawtags $id $idpos($id)]
3181 $canv coords $linehtag($commitrow($id)) $xt [lindex $idpos($id) 2]
3182 if {[info exists selectedline] && $selectedline == $commitrow($id)} {
3183 selectline $selectedline 0
3190 catch {destroy $mktagtop}
3199 proc writecommit {} {
3200 global rowmenuid wrcomtop commitinfo wrcomcmd
3202 set top .writecommit
3204 catch {destroy $top}
3206 label $top.title -text "Write commit to file"
3207 grid $top.title - -pady 10
3208 label $top.id -text "ID:"
3209 entry $top.sha1 -width 40 -relief flat
3210 $top.sha1 insert 0 $rowmenuid
3211 $top.sha1 conf -state readonly
3212 grid $top.id $top.sha1 -sticky w
3213 entry $top.head -width 60 -relief flat
3214 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3215 $top.head conf -state readonly
3216 grid x $top.head -sticky w
3217 label $top.clab -text "Command:"
3218 entry $top.cmd -width 60 -textvariable wrcomcmd
3219 grid $top.clab $top.cmd -sticky w -pady 10
3220 label $top.flab -text "Output file:"
3221 entry $top.fname -width 60
3222 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3223 grid $top.flab $top.fname -sticky w
3225 button $top.buts.gen -text "Write" -command wrcomgo
3226 button $top.buts.can -text "Cancel" -command wrcomcan
3227 grid $top.buts.gen $top.buts.can
3228 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3229 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3230 grid $top.buts - -pady 10 -sticky ew
3237 set id [$wrcomtop.sha1 get]
3238 set cmd "echo $id | [$wrcomtop.cmd get]"
3239 set fname [$wrcomtop.fname get]
3240 if {[catch {exec sh -c $cmd >$fname &} err]} {
3241 error_popup "Error writing commit: $err"
3243 catch {destroy $wrcomtop}
3250 catch {destroy $wrcomtop}
3254 proc listrefs {id} {
3255 global idtags idheads idotherrefs
3258 if {[info exists idtags($id)]} {
3262 if {[info exists idheads($id)]} {
3266 if {[info exists idotherrefs($id)]} {
3267 set z $idotherrefs($id)
3269 return [list $x $y $z]
3272 proc rereadrefs {} {
3273 global idtags idheads idotherrefs
3274 global tagids headids otherrefids
3276 set refids [concat [array names idtags] \
3277 [array names idheads] [array names idotherrefs]]
3278 foreach id $refids {
3279 if {![info exists ref($id)]} {
3280 set ref($id) [listrefs $id]
3284 set refids [lsort -unique [concat $refids [array names idtags] \
3285 [array names idheads] [array names idotherrefs]]]
3286 foreach id $refids {
3287 set v [listrefs $id]
3288 if {![info exists ref($id)] || $ref($id) != $v} {
3294 proc showtag {tag isnew} {
3295 global ctext cflist tagcontents tagids linknum
3298 addtohistory [list showtag $tag 0]
3300 $ctext conf -state normal
3301 $ctext delete 0.0 end
3303 if {[info exists tagcontents($tag)]} {
3304 set text $tagcontents($tag)
3306 set text "Tag: $tag\nId: $tagids($tag)"
3308 appendwithlinks $text
3309 $ctext conf -state disabled
3310 $cflist delete 0 end
3320 global maxwidth maxgraphpct diffopts findmergefiles
3321 global oldprefs prefstop
3325 if {[winfo exists $top]} {
3329 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3330 set oldprefs($v) [set $v]
3333 wm title $top "Gitk preferences"
3334 label $top.ldisp -text "Commit list display options"
3335 grid $top.ldisp - -sticky w -pady 10
3336 label $top.spacer -text " "
3337 label $top.maxwidthl -text "Maximum graph width (lines)" \
3339 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
3340 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
3341 label $top.maxpctl -text "Maximum graph width (% of pane)" \
3343 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
3344 grid x $top.maxpctl $top.maxpct -sticky w
3345 checkbutton $top.findm -variable findmergefiles
3346 label $top.findml -text "Include merges for \"Find\" in \"Files\"" \
3348 grid $top.findm $top.findml - -sticky w
3349 label $top.ddisp -text "Diff display options"
3350 grid $top.ddisp - -sticky w -pady 10
3351 label $top.diffoptl -text "Options for diff program" \
3353 entry $top.diffopt -width 20 -textvariable diffopts
3354 grid x $top.diffoptl $top.diffopt -sticky w
3356 button $top.buts.ok -text "OK" -command prefsok
3357 button $top.buts.can -text "Cancel" -command prefscan
3358 grid $top.buts.ok $top.buts.can
3359 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3360 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3361 grid $top.buts - - -pady 10 -sticky ew
3365 global maxwidth maxgraphpct diffopts findmergefiles
3366 global oldprefs prefstop
3368 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3369 set $v $oldprefs($v)
3371 catch {destroy $prefstop}
3376 global maxwidth maxgraphpct
3377 global oldprefs prefstop
3379 catch {destroy $prefstop}
3381 if {$maxwidth != $oldprefs(maxwidth)
3382 || $maxgraphpct != $oldprefs(maxgraphpct)} {
3387 proc formatdate {d} {
3388 return [clock format $d -format "%Y-%m-%d %H:%M:%S"]
3391 # This list of encoding names and aliases is distilled from
3392 # http://www.iana.org/assignments/character-sets.
3393 # Not all of them are supported by Tcl.
3394 set encoding_aliases {
3395 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
3396 ISO646-US US-ASCII us IBM367 cp367 csASCII }
3397 { ISO-10646-UTF-1 csISO10646UTF1 }
3398 { ISO_646.basic:1983 ref csISO646basic1983 }
3399 { INVARIANT csINVARIANT }
3400 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
3401 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
3402 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
3403 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
3404 { NATS-DANO iso-ir-9-1 csNATSDANO }
3405 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
3406 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
3407 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
3408 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
3409 { ISO-2022-KR csISO2022KR }
3411 { ISO-2022-JP csISO2022JP }
3412 { ISO-2022-JP-2 csISO2022JP2 }
3413 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
3415 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
3416 { IT iso-ir-15 ISO646-IT csISO15Italian }
3417 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
3418 { ES iso-ir-17 ISO646-ES csISO17Spanish }
3419 { greek7-old iso-ir-18 csISO18Greek7Old }
3420 { latin-greek iso-ir-19 csISO19LatinGreek }
3421 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
3422 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
3423 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
3424 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
3425 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
3426 { BS_viewdata iso-ir-47 csISO47BSViewdata }
3427 { INIS iso-ir-49 csISO49INIS }
3428 { INIS-8 iso-ir-50 csISO50INIS8 }
3429 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
3430 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
3431 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
3432 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
3433 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
3434 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
3436 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
3437 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
3438 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
3439 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
3440 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
3441 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
3442 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
3443 { greek7 iso-ir-88 csISO88Greek7 }
3444 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
3445 { iso-ir-90 csISO90 }
3446 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
3447 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
3448 csISO92JISC62991984b }
3449 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
3450 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
3451 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
3452 csISO95JIS62291984handadd }
3453 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
3454 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
3455 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
3456 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
3458 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
3459 { T.61-7bit iso-ir-102 csISO102T617bit }
3460 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
3461 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
3462 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
3463 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
3464 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
3465 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
3466 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
3467 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
3468 arabic csISOLatinArabic }
3469 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
3470 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
3471 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
3472 greek greek8 csISOLatinGreek }
3473 { T.101-G2 iso-ir-128 csISO128T101G2 }
3474 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
3476 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
3477 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
3478 { CSN_369103 iso-ir-139 csISO139CSN369103 }
3479 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
3480 { ISO_6937-2-add iso-ir-142 csISOTextComm }
3481 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
3482 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
3483 csISOLatinCyrillic }
3484 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
3485 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
3486 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
3487 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
3488 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
3489 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
3490 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
3491 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
3492 { ISO_10367-box iso-ir-155 csISO10367Box }
3493 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
3494 { latin-lap lap iso-ir-158 csISO158Lap }
3495 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
3496 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
3499 { JIS_X0201 X0201 csHalfWidthKatakana }
3500 { KSC5636 ISO646-KR csKSC5636 }
3501 { ISO-10646-UCS-2 csUnicode }
3502 { ISO-10646-UCS-4 csUCS4 }
3503 { DEC-MCS dec csDECMCS }
3504 { hp-roman8 roman8 r8 csHPRoman8 }
3505 { macintosh mac csMacintosh }
3506 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
3508 { IBM038 EBCDIC-INT cp038 csIBM038 }
3509 { IBM273 CP273 csIBM273 }
3510 { IBM274 EBCDIC-BE CP274 csIBM274 }
3511 { IBM275 EBCDIC-BR cp275 csIBM275 }
3512 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
3513 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
3514 { IBM280 CP280 ebcdic-cp-it csIBM280 }
3515 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
3516 { IBM284 CP284 ebcdic-cp-es csIBM284 }
3517 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
3518 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
3519 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
3520 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
3521 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
3522 { IBM424 cp424 ebcdic-cp-he csIBM424 }
3523 { IBM437 cp437 437 csPC8CodePage437 }
3524 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
3525 { IBM775 cp775 csPC775Baltic }
3526 { IBM850 cp850 850 csPC850Multilingual }
3527 { IBM851 cp851 851 csIBM851 }
3528 { IBM852 cp852 852 csPCp852 }
3529 { IBM855 cp855 855 csIBM855 }
3530 { IBM857 cp857 857 csIBM857 }
3531 { IBM860 cp860 860 csIBM860 }
3532 { IBM861 cp861 861 cp-is csIBM861 }
3533 { IBM862 cp862 862 csPC862LatinHebrew }
3534 { IBM863 cp863 863 csIBM863 }
3535 { IBM864 cp864 csIBM864 }
3536 { IBM865 cp865 865 csIBM865 }
3537 { IBM866 cp866 866 csIBM866 }
3538 { IBM868 CP868 cp-ar csIBM868 }
3539 { IBM869 cp869 869 cp-gr csIBM869 }
3540 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
3541 { IBM871 CP871 ebcdic-cp-is csIBM871 }
3542 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
3543 { IBM891 cp891 csIBM891 }
3544 { IBM903 cp903 csIBM903 }
3545 { IBM904 cp904 904 csIBBM904 }
3546 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
3547 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
3548 { IBM1026 CP1026 csIBM1026 }
3549 { EBCDIC-AT-DE csIBMEBCDICATDE }
3550 { EBCDIC-AT-DE-A csEBCDICATDEA }
3551 { EBCDIC-CA-FR csEBCDICCAFR }
3552 { EBCDIC-DK-NO csEBCDICDKNO }
3553 { EBCDIC-DK-NO-A csEBCDICDKNOA }
3554 { EBCDIC-FI-SE csEBCDICFISE }
3555 { EBCDIC-FI-SE-A csEBCDICFISEA }
3556 { EBCDIC-FR csEBCDICFR }
3557 { EBCDIC-IT csEBCDICIT }
3558 { EBCDIC-PT csEBCDICPT }
3559 { EBCDIC-ES csEBCDICES }
3560 { EBCDIC-ES-A csEBCDICESA }
3561 { EBCDIC-ES-S csEBCDICESS }
3562 { EBCDIC-UK csEBCDICUK }
3563 { EBCDIC-US csEBCDICUS }
3564 { UNKNOWN-8BIT csUnknown8BiT }
3565 { MNEMONIC csMnemonic }
3570 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
3571 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
3572 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
3573 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
3574 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
3575 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
3576 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
3577 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
3578 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
3579 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
3580 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
3581 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
3582 { IBM1047 IBM-1047 }
3583 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
3584 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
3585 { UNICODE-1-1 csUnicode11 }
3588 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
3589 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
3591 { ISO-8859-15 ISO_8859-15 Latin-9 }
3592 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
3593 { GBK CP936 MS936 windows-936 }
3594 { JIS_Encoding csJISEncoding }
3595 { Shift_JIS MS_Kanji csShiftJIS }
3596 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
3598 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
3599 { ISO-10646-UCS-Basic csUnicodeASCII }
3600 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
3601 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
3602 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
3603 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
3604 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
3605 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
3606 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
3607 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
3608 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
3609 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
3610 { Adobe-Standard-Encoding csAdobeStandardEncoding }
3611 { Ventura-US csVenturaUS }
3612 { Ventura-International csVenturaInternational }
3613 { PC8-Danish-Norwegian csPC8DanishNorwegian }
3614 { PC8-Turkish csPC8Turkish }
3615 { IBM-Symbols csIBMSymbols }
3616 { IBM-Thai csIBMThai }
3617 { HP-Legal csHPLegal }
3618 { HP-Pi-font csHPPiFont }
3619 { HP-Math8 csHPMath8 }
3620 { Adobe-Symbol-Encoding csHPPSMath }
3621 { HP-DeskTop csHPDesktop }
3622 { Ventura-Math csVenturaMath }
3623 { Microsoft-Publishing csMicrosoftPublishing }
3624 { Windows-31J csWindows31J }
3629 proc tcl_encoding {enc} {
3630 global encoding_aliases
3631 set names [encoding names]
3632 set lcnames [string tolower $names]
3633 set enc [string tolower $enc]
3634 set i [lsearch -exact $lcnames $enc]
3636 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
3637 if {[regsub {^iso[-_]} $enc iso encx]} {
3638 set i [lsearch -exact $lcnames $encx]
3642 foreach l $encoding_aliases {
3643 set ll [string tolower $l]
3644 if {[lsearch -exact $ll $enc] < 0} continue
3645 # look through the aliases for one that tcl knows about
3647 set i [lsearch -exact $lcnames $e]
3649 if {[regsub {^iso[-_]} $e iso ex]} {
3650 set i [lsearch -exact $lcnames $ex]
3659 return [lindex $names $i]
3666 set diffopts "-U 5 -p"
3667 set wrcomcmd "git-diff-tree --stdin -p --pretty"
3671 set gitencoding [exec git-repo-config --get i18n.commitencoding]
3673 if {$gitencoding == ""} {
3674 set gitencoding "utf-8"
3676 set tclencoding [tcl_encoding $gitencoding]
3677 if {$tclencoding == {}} {
3678 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
3681 set mainfont {Helvetica 9}
3682 set textfont {Courier 9}
3683 set findmergefiles 0
3692 set colors {green red blue magenta darkgrey brown orange}
3694 catch {source ~/.gitk}
3696 set namefont $mainfont
3698 font create optionfont -family sans-serif -size -12
3702 switch -regexp -- $arg {
3704 "^-d" { set datemode 1 }
3706 lappend revtreeargs $arg
3711 # check that we can find a .git directory somewhere...
3713 if {![file isdirectory $gitdir]} {
3714 error_popup "Cannot find the git directory \"$gitdir\"."
3727 makewindow $revtreeargs
3729 getcommits $revtreeargs