2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2005-2006 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)]} {
15 return [exec git rev-parse --git-dir]
19 # A simple scheduler for compute-intensive stuff.
20 # The aim is to make sure that event handlers for GUI actions can
21 # run at least every 50-100 ms. Unfortunately fileevent handlers are
22 # run before X event handlers, so reading from a fast source can
23 # make the GUI completely unresponsive.
28 if {[info exists isonrunq($script)]} return
32 lappend runq [list {} $script]
33 set isonrunq($script) 1
36 proc filerun {fd script} {
37 fileevent $fd readable [list filereadable $fd $script]
40 proc filereadable {fd script} {
43 fileevent $fd readable {}
47 lappend runq [list $fd $script]
53 set tstart [clock clicks -milliseconds]
56 set fd [lindex $runq 0 0]
57 set script [lindex $runq 0 1]
58 set repeat [eval $script]
59 set t1 [clock clicks -milliseconds]
60 set t [expr {$t1 - $t0}]
61 set runq [lrange $runq 1 end]
62 if {$repeat ne {} && $repeat} {
63 if {$fd eq {} || $repeat == 2} {
64 # script returns 1 if it wants to be readded
65 # file readers return 2 if they could do more straight away
66 lappend runq [list $fd $script]
68 fileevent $fd readable [list filereadable $fd $script]
70 } elseif {$fd eq {}} {
71 unset isonrunq($script)
74 if {$t1 - $tstart >= 80} break
81 # Start off a git rev-list process and arrange to read its output
82 proc start_rev_list {view} {
84 global commfd leftover tclencoding datemode
85 global viewargs viewfiles commitidx
86 global lookingforhead showlocalchanges
88 set startmsecs [clock clicks -milliseconds]
89 set commitidx($view) 0
90 set args $viewargs($view)
91 if {$viewfiles($view) ne {}} {
92 set args [concat $args "--" $viewfiles($view)]
94 set order "--topo-order"
96 set order "--date-order"
99 set fd [open [concat | git log -z --pretty=raw $order \
100 --parents --boundary $args] r]
102 puts stderr "Error executing git rev-list: $err"
105 set commfd($view) $fd
106 set leftover($view) {}
107 set lookingforhead $showlocalchanges
108 fconfigure $fd -blocking 0 -translation lf
109 if {$tclencoding != {}} {
110 fconfigure $fd -encoding $tclencoding
112 filerun $fd [list getcommitlines $fd $view]
116 proc stop_rev_list {} {
117 global commfd curview
119 if {![info exists commfd($curview)]} return
120 set fd $commfd($curview)
126 unset commfd($curview)
130 global phase canv mainfont curview
134 start_rev_list $curview
135 show_status "Reading commits..."
138 proc getcommitlines {fd view} {
140 global leftover commfd
141 global displayorder commitidx commitrow commitdata
142 global parentlist children curview hlview
143 global vparentlist vdisporder vcmitlisted
145 set stuff [read $fd 500000]
153 # set it blocking so we wait for the process to terminate
154 fconfigure $fd -blocking 1
155 if {[catch {close $fd} err]} {
157 if {$view != $curview} {
158 set fv " for the \"$viewname($view)\" view"
160 if {[string range $err 0 4] == "usage"} {
161 set err "Gitk: error reading commits$fv:\
162 bad arguments to git rev-list."
163 if {$viewname($view) eq "Command line"} {
165 " (Note: arguments to gitk are passed to git rev-list\
166 to allow selection of commits to be displayed.)"
169 set err "Error reading commits$fv: $err"
173 if {$view == $curview} {
174 run chewcommits $view
181 set i [string first "\0" $stuff $start]
183 append leftover($view) [string range $stuff $start end]
187 set cmit $leftover($view)
188 append cmit [string range $stuff 0 [expr {$i - 1}]]
189 set leftover($view) {}
191 set cmit [string range $stuff $start [expr {$i - 1}]]
193 set start [expr {$i + 1}]
194 set j [string first "\n" $cmit]
197 if {$j >= 0 && [string match "commit *" $cmit]} {
198 set ids [string range $cmit 7 [expr {$j - 1}]]
199 if {[string match {[-<>]*} $ids]} {
200 switch -- [string index $ids 0] {
205 set ids [string range $ids 1 end]
209 if {[string length $id] != 40} {
217 if {[string length $shortcmit] > 80} {
218 set shortcmit "[string range $shortcmit 0 80]..."
220 error_popup "Can't parse git log output: {$shortcmit}"
223 set id [lindex $ids 0]
225 set olds [lrange $ids 1 end]
228 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
229 lappend children($view,$p) $id
236 if {![info exists children($view,$id)]} {
237 set children($view,$id) {}
239 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
240 set commitrow($view,$id) $commitidx($view)
241 incr commitidx($view)
242 if {$view == $curview} {
243 lappend parentlist $olds
244 lappend displayorder $id
245 lappend commitlisted $listed
247 lappend vparentlist($view) $olds
248 lappend vdisporder($view) $id
249 lappend vcmitlisted($view) $listed
254 run chewcommits $view
259 proc chewcommits {view} {
260 global curview hlview commfd
261 global selectedline pending_select
264 if {$view == $curview} {
265 set allread [expr {![info exists commfd($view)]}]
266 set tlimit [expr {[clock clicks -milliseconds] + 50}]
267 set more [layoutmore $tlimit $allread]
268 if {$allread && !$more} {
269 global displayorder nullid commitidx phase
270 global numcommits startmsecs
272 if {[info exists pending_select]} {
273 set row [expr {[lindex $displayorder 0] eq $nullid}]
276 if {$commitidx($curview) > 0} {
277 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
278 #puts "overall $ms ms for $numcommits commits"
280 show_status "No commits selected"
286 if {[info exists hlview] && $view == $hlview} {
292 proc readcommit {id} {
293 if {[catch {set contents [exec git cat-file commit $id]}]} return
294 parsecommit $id $contents 0
297 proc updatecommits {} {
298 global viewdata curview phase displayorder
299 global children commitrow selectedline thickerline
306 foreach id $displayorder {
307 catch {unset children($n,$id)}
308 catch {unset commitrow($n,$id)}
311 catch {unset selectedline}
312 catch {unset thickerline}
313 catch {unset viewdata($n)}
320 proc parsecommit {id contents listed} {
321 global commitinfo cdate
330 set hdrend [string first "\n\n" $contents]
332 # should never happen...
333 set hdrend [string length $contents]
335 set header [string range $contents 0 [expr {$hdrend - 1}]]
336 set comment [string range $contents [expr {$hdrend + 2}] end]
337 foreach line [split $header "\n"] {
338 set tag [lindex $line 0]
339 if {$tag == "author"} {
340 set audate [lindex $line end-1]
341 set auname [lrange $line 1 end-2]
342 } elseif {$tag == "committer"} {
343 set comdate [lindex $line end-1]
344 set comname [lrange $line 1 end-2]
348 # take the first non-blank line of the comment as the headline
349 set headline [string trimleft $comment]
350 set i [string first "\n" $headline]
352 set headline [string range $headline 0 $i]
354 set headline [string trimright $headline]
355 set i [string first "\r" $headline]
357 set headline [string trimright [string range $headline 0 $i]]
360 # git rev-list indents the comment by 4 spaces;
361 # if we got this via git cat-file, add the indentation
363 foreach line [split $comment "\n"] {
364 append newcomment " "
365 append newcomment $line
366 append newcomment "\n"
368 set comment $newcomment
370 if {$comdate != {}} {
371 set cdate($id) $comdate
373 set commitinfo($id) [list $headline $auname $audate \
374 $comname $comdate $comment]
377 proc getcommit {id} {
378 global commitdata commitinfo
380 if {[info exists commitdata($id)]} {
381 parsecommit $id $commitdata($id) 1
384 if {![info exists commitinfo($id)]} {
385 set commitinfo($id) {"No commit information available"}
392 global tagids idtags headids idheads tagobjid
393 global otherrefids idotherrefs mainhead mainheadid
395 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
398 set refd [open [list | git show-ref -d] r]
399 while {[gets $refd line] >= 0} {
400 if {[string index $line 40] ne " "} continue
401 set id [string range $line 0 39]
402 set ref [string range $line 41 end]
403 if {![string match "refs/*" $ref]} continue
404 set name [string range $ref 5 end]
405 if {[string match "remotes/*" $name]} {
406 if {![string match "*/HEAD" $name]} {
407 set headids($name) $id
408 lappend idheads($id) $name
410 } elseif {[string match "heads/*" $name]} {
411 set name [string range $name 6 end]
412 set headids($name) $id
413 lappend idheads($id) $name
414 } elseif {[string match "tags/*" $name]} {
415 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
416 # which is what we want since the former is the commit ID
417 set name [string range $name 5 end]
418 if {[string match "*^{}" $name]} {
419 set name [string range $name 0 end-3]
421 set tagobjid($name) $id
423 set tagids($name) $id
424 lappend idtags($id) $name
426 set otherrefids($name) $id
427 lappend idotherrefs($id) $name
434 set thehead [exec git symbolic-ref HEAD]
435 if {[string match "refs/heads/*" $thehead]} {
436 set mainhead [string range $thehead 11 end]
437 if {[info exists headids($mainhead)]} {
438 set mainheadid $headids($mainhead)
444 # update things for a head moved to a child of its previous location
445 proc movehead {id name} {
446 global headids idheads
448 removehead $headids($name) $name
449 set headids($name) $id
450 lappend idheads($id) $name
453 # update things when a head has been removed
454 proc removehead {id name} {
455 global headids idheads
457 if {$idheads($id) eq $name} {
460 set i [lsearch -exact $idheads($id) $name]
462 set idheads($id) [lreplace $idheads($id) $i $i]
468 proc show_error {w top msg} {
469 message $w.m -text $msg -justify center -aspect 400
470 pack $w.m -side top -fill x -padx 20 -pady 20
471 button $w.ok -text OK -command "destroy $top"
472 pack $w.ok -side bottom -fill x
473 bind $top <Visibility> "grab $top; focus $top"
474 bind $top <Key-Return> "destroy $top"
478 proc error_popup msg {
482 show_error $w $w $msg
485 proc confirm_popup msg {
491 message $w.m -text $msg -justify center -aspect 400
492 pack $w.m -side top -fill x -padx 20 -pady 20
493 button $w.ok -text OK -command "set confirm_ok 1; destroy $w"
494 pack $w.ok -side left -fill x
495 button $w.cancel -text Cancel -command "destroy $w"
496 pack $w.cancel -side right -fill x
497 bind $w <Visibility> "grab $w; focus $w"
503 global canv canv2 canv3 linespc charspc ctext cflist
504 global textfont mainfont uifont tabstop
505 global findtype findtypemenu findloc findstring fstring geometry
506 global entries sha1entry sha1string sha1but
507 global maincursor textcursor curtextcursor
508 global rowctxmenu fakerowmenu mergemax wrapcomment
509 global highlight_files gdttype
510 global searchstring sstring
511 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
515 .bar add cascade -label "File" -menu .bar.file
516 .bar configure -font $uifont
518 .bar.file add command -label "Update" -command updatecommits
519 .bar.file add command -label "Reread references" -command rereadrefs
520 .bar.file add command -label "Quit" -command doquit
521 .bar.file configure -font $uifont
523 .bar add cascade -label "Edit" -menu .bar.edit
524 .bar.edit add command -label "Preferences" -command doprefs
525 .bar.edit configure -font $uifont
527 menu .bar.view -font $uifont
528 .bar add cascade -label "View" -menu .bar.view
529 .bar.view add command -label "New view..." -command {newview 0}
530 .bar.view add command -label "Edit view..." -command editview \
532 .bar.view add command -label "Delete view" -command delview -state disabled
533 .bar.view add separator
534 .bar.view add radiobutton -label "All files" -command {showview 0} \
535 -variable selectedview -value 0
538 .bar add cascade -label "Help" -menu .bar.help
539 .bar.help add command -label "About gitk" -command about
540 .bar.help add command -label "Key bindings" -command keys
541 .bar.help configure -font $uifont
542 . configure -menu .bar
544 # the gui has upper and lower half, parts of a paned window.
545 panedwindow .ctop -orient vertical
547 # possibly use assumed geometry
548 if {![info exists geometry(pwsash0)]} {
549 set geometry(topheight) [expr {15 * $linespc}]
550 set geometry(topwidth) [expr {80 * $charspc}]
551 set geometry(botheight) [expr {15 * $linespc}]
552 set geometry(botwidth) [expr {50 * $charspc}]
553 set geometry(pwsash0) "[expr {40 * $charspc}] 2"
554 set geometry(pwsash1) "[expr {60 * $charspc}] 2"
557 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
558 frame .tf -height $geometry(topheight) -width $geometry(topwidth)
560 panedwindow .tf.histframe.pwclist -orient horizontal -sashpad 0 -handlesize 4
562 # create three canvases
563 set cscroll .tf.histframe.csb
564 set canv .tf.histframe.pwclist.canv
566 -selectbackground $selectbgcolor \
567 -background $bgcolor -bd 0 \
568 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
569 .tf.histframe.pwclist add $canv
570 set canv2 .tf.histframe.pwclist.canv2
572 -selectbackground $selectbgcolor \
573 -background $bgcolor -bd 0 -yscrollincr $linespc
574 .tf.histframe.pwclist add $canv2
575 set canv3 .tf.histframe.pwclist.canv3
577 -selectbackground $selectbgcolor \
578 -background $bgcolor -bd 0 -yscrollincr $linespc
579 .tf.histframe.pwclist add $canv3
580 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
581 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
583 # a scroll bar to rule them
584 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
585 pack $cscroll -side right -fill y
586 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
587 lappend bglist $canv $canv2 $canv3
588 pack .tf.histframe.pwclist -fill both -expand 1 -side left
590 # we have two button bars at bottom of top frame. Bar 1
592 frame .tf.lbar -height 15
594 set sha1entry .tf.bar.sha1
595 set entries $sha1entry
596 set sha1but .tf.bar.sha1label
597 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
598 -command gotocommit -width 8 -font $uifont
599 $sha1but conf -disabledforeground [$sha1but cget -foreground]
600 pack .tf.bar.sha1label -side left
601 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
602 trace add variable sha1string write sha1change
603 pack $sha1entry -side left -pady 2
605 image create bitmap bm-left -data {
606 #define left_width 16
607 #define left_height 16
608 static unsigned char left_bits[] = {
609 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
610 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
611 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
613 image create bitmap bm-right -data {
614 #define right_width 16
615 #define right_height 16
616 static unsigned char right_bits[] = {
617 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
618 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
619 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
621 button .tf.bar.leftbut -image bm-left -command goback \
622 -state disabled -width 26
623 pack .tf.bar.leftbut -side left -fill y
624 button .tf.bar.rightbut -image bm-right -command goforw \
625 -state disabled -width 26
626 pack .tf.bar.rightbut -side left -fill y
628 button .tf.bar.findbut -text "Find" -command dofind -font $uifont
629 pack .tf.bar.findbut -side left
631 set fstring .tf.bar.findstring
632 lappend entries $fstring
633 entry $fstring -width 30 -font $textfont -textvariable findstring
634 trace add variable findstring write find_change
635 pack $fstring -side left -expand 1 -fill x -in .tf.bar
637 set findtypemenu [tk_optionMenu .tf.bar.findtype \
638 findtype Exact IgnCase Regexp]
639 trace add variable findtype write find_change
640 .tf.bar.findtype configure -font $uifont
641 .tf.bar.findtype.menu configure -font $uifont
642 set findloc "All fields"
643 tk_optionMenu .tf.bar.findloc findloc "All fields" Headline \
644 Comments Author Committer
645 trace add variable findloc write find_change
646 .tf.bar.findloc configure -font $uifont
647 .tf.bar.findloc.menu configure -font $uifont
648 pack .tf.bar.findloc -side right
649 pack .tf.bar.findtype -side right
651 # build up the bottom bar of upper window
652 label .tf.lbar.flabel -text "Highlight: Commits " \
654 pack .tf.lbar.flabel -side left -fill y
655 set gdttype "touching paths:"
656 set gm [tk_optionMenu .tf.lbar.gdttype gdttype "touching paths:" \
657 "adding/removing string:"]
658 trace add variable gdttype write hfiles_change
659 $gm conf -font $uifont
660 .tf.lbar.gdttype conf -font $uifont
661 pack .tf.lbar.gdttype -side left -fill y
662 entry .tf.lbar.fent -width 25 -font $textfont \
663 -textvariable highlight_files
664 trace add variable highlight_files write hfiles_change
665 lappend entries .tf.lbar.fent
666 pack .tf.lbar.fent -side left -fill x -expand 1
667 label .tf.lbar.vlabel -text " OR in view" -font $uifont
668 pack .tf.lbar.vlabel -side left -fill y
669 global viewhlmenu selectedhlview
670 set viewhlmenu [tk_optionMenu .tf.lbar.vhl selectedhlview None]
671 $viewhlmenu entryconf None -command delvhighlight
672 $viewhlmenu conf -font $uifont
673 .tf.lbar.vhl conf -font $uifont
674 pack .tf.lbar.vhl -side left -fill y
675 label .tf.lbar.rlabel -text " OR " -font $uifont
676 pack .tf.lbar.rlabel -side left -fill y
677 global highlight_related
678 set m [tk_optionMenu .tf.lbar.relm highlight_related None \
679 "Descendent" "Not descendent" "Ancestor" "Not ancestor"]
680 $m conf -font $uifont
681 .tf.lbar.relm conf -font $uifont
682 trace add variable highlight_related write vrel_change
683 pack .tf.lbar.relm -side left -fill y
685 # Finish putting the upper half of the viewer together
686 pack .tf.lbar -in .tf -side bottom -fill x
687 pack .tf.bar -in .tf -side bottom -fill x
688 pack .tf.histframe -fill both -side top -expand 1
690 .ctop paneconfigure .tf -height $geometry(topheight)
691 .ctop paneconfigure .tf -width $geometry(topwidth)
693 # now build up the bottom
694 panedwindow .pwbottom -orient horizontal
696 # lower left, a text box over search bar, scroll bar to the right
697 # if we know window height, then that will set the lower text height, otherwise
698 # we set lower text height which will drive window height
699 if {[info exists geometry(main)]} {
700 frame .bleft -width $geometry(botwidth)
702 frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
707 button .bleft.top.search -text "Search" -command dosearch \
709 pack .bleft.top.search -side left -padx 5
710 set sstring .bleft.top.sstring
711 entry $sstring -width 20 -font $textfont -textvariable searchstring
712 lappend entries $sstring
713 trace add variable searchstring write incrsearch
714 pack $sstring -side left -expand 1 -fill x
715 radiobutton .bleft.mid.diff -text "Diff" \
716 -command changediffdisp -variable diffelide -value {0 0}
717 radiobutton .bleft.mid.old -text "Old version" \
718 -command changediffdisp -variable diffelide -value {0 1}
719 radiobutton .bleft.mid.new -text "New version" \
720 -command changediffdisp -variable diffelide -value {1 0}
721 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left
722 set ctext .bleft.ctext
723 text $ctext -background $bgcolor -foreground $fgcolor \
724 -tabs "[expr {$tabstop * $charspc}]" \
725 -state disabled -font $textfont \
726 -yscrollcommand scrolltext -wrap none
727 scrollbar .bleft.sb -command "$ctext yview"
728 pack .bleft.top -side top -fill x
729 pack .bleft.mid -side top -fill x
730 pack .bleft.sb -side right -fill y
731 pack $ctext -side left -fill both -expand 1
732 lappend bglist $ctext
733 lappend fglist $ctext
735 $ctext tag conf comment -wrap $wrapcomment
736 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
737 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
738 $ctext tag conf d0 -fore [lindex $diffcolors 0]
739 $ctext tag conf d1 -fore [lindex $diffcolors 1]
740 $ctext tag conf m0 -fore red
741 $ctext tag conf m1 -fore blue
742 $ctext tag conf m2 -fore green
743 $ctext tag conf m3 -fore purple
744 $ctext tag conf m4 -fore brown
745 $ctext tag conf m5 -fore "#009090"
746 $ctext tag conf m6 -fore magenta
747 $ctext tag conf m7 -fore "#808000"
748 $ctext tag conf m8 -fore "#009000"
749 $ctext tag conf m9 -fore "#ff0080"
750 $ctext tag conf m10 -fore cyan
751 $ctext tag conf m11 -fore "#b07070"
752 $ctext tag conf m12 -fore "#70b0f0"
753 $ctext tag conf m13 -fore "#70f0b0"
754 $ctext tag conf m14 -fore "#f0b070"
755 $ctext tag conf m15 -fore "#ff70b0"
756 $ctext tag conf mmax -fore darkgrey
758 $ctext tag conf mresult -font [concat $textfont bold]
759 $ctext tag conf msep -font [concat $textfont bold]
760 $ctext tag conf found -back yellow
763 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
768 radiobutton .bright.mode.patch -text "Patch" \
769 -command reselectline -variable cmitmode -value "patch"
770 .bright.mode.patch configure -font $uifont
771 radiobutton .bright.mode.tree -text "Tree" \
772 -command reselectline -variable cmitmode -value "tree"
773 .bright.mode.tree configure -font $uifont
774 grid .bright.mode.patch .bright.mode.tree -sticky ew
775 pack .bright.mode -side top -fill x
776 set cflist .bright.cfiles
777 set indent [font measure $mainfont "nn"]
779 -selectbackground $selectbgcolor \
780 -background $bgcolor -foreground $fgcolor \
782 -tabs [list $indent [expr {2 * $indent}]] \
783 -yscrollcommand ".bright.sb set" \
784 -cursor [. cget -cursor] \
785 -spacing1 1 -spacing3 1
786 lappend bglist $cflist
787 lappend fglist $cflist
788 scrollbar .bright.sb -command "$cflist yview"
789 pack .bright.sb -side right -fill y
790 pack $cflist -side left -fill both -expand 1
791 $cflist tag configure highlight \
792 -background [$cflist cget -selectbackground]
793 $cflist tag configure bold -font [concat $mainfont bold]
795 .pwbottom add .bright
798 # restore window position if known
799 if {[info exists geometry(main)]} {
800 wm geometry . "$geometry(main)"
803 bind .pwbottom <Configure> {resizecdetpanes %W %w}
804 pack .ctop -fill both -expand 1
805 bindall <1> {selcanvline %W %x %y}
806 #bindall <B1-Motion> {selcanvline %W %x %y}
807 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
808 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
809 bindall <2> "canvscan mark %W %x %y"
810 bindall <B2-Motion> "canvscan dragto %W %x %y"
811 bindkey <Home> selfirstline
812 bindkey <End> sellastline
813 bind . <Key-Up> "selnextline -1"
814 bind . <Key-Down> "selnextline 1"
815 bind . <Shift-Key-Up> "next_highlight -1"
816 bind . <Shift-Key-Down> "next_highlight 1"
817 bindkey <Key-Right> "goforw"
818 bindkey <Key-Left> "goback"
819 bind . <Key-Prior> "selnextpage -1"
820 bind . <Key-Next> "selnextpage 1"
821 bind . <Control-Home> "allcanvs yview moveto 0.0"
822 bind . <Control-End> "allcanvs yview moveto 1.0"
823 bind . <Control-Key-Up> "allcanvs yview scroll -1 units"
824 bind . <Control-Key-Down> "allcanvs yview scroll 1 units"
825 bind . <Control-Key-Prior> "allcanvs yview scroll -1 pages"
826 bind . <Control-Key-Next> "allcanvs yview scroll 1 pages"
827 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
828 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
829 bindkey <Key-space> "$ctext yview scroll 1 pages"
830 bindkey p "selnextline -1"
831 bindkey n "selnextline 1"
834 bindkey i "selnextline -1"
835 bindkey k "selnextline 1"
838 bindkey b "$ctext yview scroll -1 pages"
839 bindkey d "$ctext yview scroll 18 units"
840 bindkey u "$ctext yview scroll -18 units"
841 bindkey / {findnext 1}
842 bindkey <Key-Return> {findnext 0}
845 bindkey <F5> updatecommits
846 bind . <Control-q> doquit
847 bind . <Control-f> dofind
848 bind . <Control-g> {findnext 0}
849 bind . <Control-r> dosearchback
850 bind . <Control-s> dosearch
851 bind . <Control-equal> {incrfont 1}
852 bind . <Control-KP_Add> {incrfont 1}
853 bind . <Control-minus> {incrfont -1}
854 bind . <Control-KP_Subtract> {incrfont -1}
855 wm protocol . WM_DELETE_WINDOW doquit
856 bind . <Button-1> "click %W"
857 bind $fstring <Key-Return> dofind
858 bind $sha1entry <Key-Return> gotocommit
859 bind $sha1entry <<PasteSelection>> clearsha1
860 bind $cflist <1> {sel_flist %W %x %y; break}
861 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
862 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
864 set maincursor [. cget -cursor]
865 set textcursor [$ctext cget -cursor]
866 set curtextcursor $textcursor
868 set rowctxmenu .rowctxmenu
869 menu $rowctxmenu -tearoff 0
870 $rowctxmenu add command -label "Diff this -> selected" \
871 -command {diffvssel 0}
872 $rowctxmenu add command -label "Diff selected -> this" \
873 -command {diffvssel 1}
874 $rowctxmenu add command -label "Make patch" -command mkpatch
875 $rowctxmenu add command -label "Create tag" -command mktag
876 $rowctxmenu add command -label "Write commit to file" -command writecommit
877 $rowctxmenu add command -label "Create new branch" -command mkbranch
878 $rowctxmenu add command -label "Cherry-pick this commit" \
880 $rowctxmenu add command -label "Reset HEAD branch to here" \
883 set fakerowmenu .fakerowmenu
884 menu $fakerowmenu -tearoff 0
885 $fakerowmenu add command -label "Diff this -> selected" \
886 -command {diffvssel 0}
887 $fakerowmenu add command -label "Diff selected -> this" \
888 -command {diffvssel 1}
889 $fakerowmenu add command -label "Make patch" -command mkpatch
890 # $fakerowmenu add command -label "Commit" -command {mkcommit 0}
891 # $fakerowmenu add command -label "Commit all" -command {mkcommit 1}
892 # $fakerowmenu add command -label "Revert local changes" -command revertlocal
894 set headctxmenu .headctxmenu
895 menu $headctxmenu -tearoff 0
896 $headctxmenu add command -label "Check out this branch" \
898 $headctxmenu add command -label "Remove this branch" \
902 # mouse-2 makes all windows scan vertically, but only the one
903 # the cursor is in scans horizontally
904 proc canvscan {op w x y} {
905 global canv canv2 canv3
906 foreach c [list $canv $canv2 $canv3] {
915 proc scrollcanv {cscroll f0 f1} {
921 # when we make a key binding for the toplevel, make sure
922 # it doesn't get triggered when that key is pressed in the
923 # find string entry widget.
924 proc bindkey {ev script} {
927 set escript [bind Entry $ev]
928 if {$escript == {}} {
929 set escript [bind Entry <Key>]
932 bind $e $ev "$escript; break"
936 # set the focus back to the toplevel for any click outside
947 global canv canv2 canv3 ctext cflist mainfont textfont uifont tabstop
948 global stuffsaved findmergefiles maxgraphpct
949 global maxwidth showneartags showlocalchanges
950 global viewname viewfiles viewargs viewperm nextviewnum
951 global cmitmode wrapcomment
952 global colors bgcolor fgcolor diffcolors selectbgcolor
954 if {$stuffsaved} return
955 if {![winfo viewable .]} return
957 set f [open "~/.gitk-new" w]
958 puts $f [list set mainfont $mainfont]
959 puts $f [list set textfont $textfont]
960 puts $f [list set uifont $uifont]
961 puts $f [list set tabstop $tabstop]
962 puts $f [list set findmergefiles $findmergefiles]
963 puts $f [list set maxgraphpct $maxgraphpct]
964 puts $f [list set maxwidth $maxwidth]
965 puts $f [list set cmitmode $cmitmode]
966 puts $f [list set wrapcomment $wrapcomment]
967 puts $f [list set showneartags $showneartags]
968 puts $f [list set showlocalchanges $showlocalchanges]
969 puts $f [list set bgcolor $bgcolor]
970 puts $f [list set fgcolor $fgcolor]
971 puts $f [list set colors $colors]
972 puts $f [list set diffcolors $diffcolors]
973 puts $f [list set selectbgcolor $selectbgcolor]
975 puts $f "set geometry(main) [wm geometry .]"
976 puts $f "set geometry(topwidth) [winfo width .tf]"
977 puts $f "set geometry(topheight) [winfo height .tf]"
978 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
979 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
980 puts $f "set geometry(botwidth) [winfo width .bleft]"
981 puts $f "set geometry(botheight) [winfo height .bleft]"
983 puts -nonewline $f "set permviews {"
984 for {set v 0} {$v < $nextviewnum} {incr v} {
986 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v)]}"
991 file rename -force "~/.gitk-new" "~/.gitk"
996 proc resizeclistpanes {win w} {
998 if {[info exists oldwidth($win)]} {
999 set s0 [$win sash coord 0]
1000 set s1 [$win sash coord 1]
1002 set sash0 [expr {int($w/2 - 2)}]
1003 set sash1 [expr {int($w*5/6 - 2)}]
1005 set factor [expr {1.0 * $w / $oldwidth($win)}]
1006 set sash0 [expr {int($factor * [lindex $s0 0])}]
1007 set sash1 [expr {int($factor * [lindex $s1 0])}]
1011 if {$sash1 < $sash0 + 20} {
1012 set sash1 [expr {$sash0 + 20}]
1014 if {$sash1 > $w - 10} {
1015 set sash1 [expr {$w - 10}]
1016 if {$sash0 > $sash1 - 20} {
1017 set sash0 [expr {$sash1 - 20}]
1021 $win sash place 0 $sash0 [lindex $s0 1]
1022 $win sash place 1 $sash1 [lindex $s1 1]
1024 set oldwidth($win) $w
1027 proc resizecdetpanes {win w} {
1029 if {[info exists oldwidth($win)]} {
1030 set s0 [$win sash coord 0]
1032 set sash0 [expr {int($w*3/4 - 2)}]
1034 set factor [expr {1.0 * $w / $oldwidth($win)}]
1035 set sash0 [expr {int($factor * [lindex $s0 0])}]
1039 if {$sash0 > $w - 15} {
1040 set sash0 [expr {$w - 15}]
1043 $win sash place 0 $sash0 [lindex $s0 1]
1045 set oldwidth($win) $w
1048 proc allcanvs args {
1049 global canv canv2 canv3
1055 proc bindall {event action} {
1056 global canv canv2 canv3
1057 bind $canv $event $action
1058 bind $canv2 $event $action
1059 bind $canv3 $event $action
1065 if {[winfo exists $w]} {
1070 wm title $w "About gitk"
1071 message $w.m -text {
1072 Gitk - a commit viewer for git
1074 Copyright © 2005-2006 Paul Mackerras
1076 Use and redistribute under the terms of the GNU General Public License} \
1077 -justify center -aspect 400 -border 2 -bg white -relief groove
1078 pack $w.m -side top -fill x -padx 2 -pady 2
1079 $w.m configure -font $uifont
1080 button $w.ok -text Close -command "destroy $w" -default active
1081 pack $w.ok -side bottom
1082 $w.ok configure -font $uifont
1083 bind $w <Visibility> "focus $w.ok"
1084 bind $w <Key-Escape> "destroy $w"
1085 bind $w <Key-Return> "destroy $w"
1091 if {[winfo exists $w]} {
1096 wm title $w "Gitk key bindings"
1097 message $w.m -text {
1101 <Home> Move to first commit
1102 <End> Move to last commit
1103 <Up>, p, i Move up one commit
1104 <Down>, n, k Move down one commit
1105 <Left>, z, j Go back in history list
1106 <Right>, x, l Go forward in history list
1107 <PageUp> Move up one page in commit list
1108 <PageDown> Move down one page in commit list
1109 <Ctrl-Home> Scroll to top of commit list
1110 <Ctrl-End> Scroll to bottom of commit list
1111 <Ctrl-Up> Scroll commit list up one line
1112 <Ctrl-Down> Scroll commit list down one line
1113 <Ctrl-PageUp> Scroll commit list up one page
1114 <Ctrl-PageDown> Scroll commit list down one page
1115 <Shift-Up> Move to previous highlighted line
1116 <Shift-Down> Move to next highlighted line
1117 <Delete>, b Scroll diff view up one page
1118 <Backspace> Scroll diff view up one page
1119 <Space> Scroll diff view down one page
1120 u Scroll diff view up 18 lines
1121 d Scroll diff view down 18 lines
1123 <Ctrl-G> Move to next find hit
1124 <Return> Move to next find hit
1125 / Move to next find hit, or redo find
1126 ? Move to previous find hit
1127 f Scroll diff view to next file
1128 <Ctrl-S> Search for next hit in diff view
1129 <Ctrl-R> Search for previous hit in diff view
1130 <Ctrl-KP+> Increase font size
1131 <Ctrl-plus> Increase font size
1132 <Ctrl-KP-> Decrease font size
1133 <Ctrl-minus> Decrease font size
1136 -justify left -bg white -border 2 -relief groove
1137 pack $w.m -side top -fill both -padx 2 -pady 2
1138 $w.m configure -font $uifont
1139 button $w.ok -text Close -command "destroy $w" -default active
1140 pack $w.ok -side bottom
1141 $w.ok configure -font $uifont
1142 bind $w <Visibility> "focus $w.ok"
1143 bind $w <Key-Escape> "destroy $w"
1144 bind $w <Key-Return> "destroy $w"
1147 # Procedures for manipulating the file list window at the
1148 # bottom right of the overall window.
1150 proc treeview {w l openlevs} {
1151 global treecontents treediropen treeheight treeparent treeindex
1161 set treecontents() {}
1162 $w conf -state normal
1164 while {[string range $f 0 $prefixend] ne $prefix} {
1165 if {$lev <= $openlevs} {
1166 $w mark set e:$treeindex($prefix) "end -1c"
1167 $w mark gravity e:$treeindex($prefix) left
1169 set treeheight($prefix) $ht
1170 incr ht [lindex $htstack end]
1171 set htstack [lreplace $htstack end end]
1172 set prefixend [lindex $prefendstack end]
1173 set prefendstack [lreplace $prefendstack end end]
1174 set prefix [string range $prefix 0 $prefixend]
1177 set tail [string range $f [expr {$prefixend+1}] end]
1178 while {[set slash [string first "/" $tail]] >= 0} {
1181 lappend prefendstack $prefixend
1182 incr prefixend [expr {$slash + 1}]
1183 set d [string range $tail 0 $slash]
1184 lappend treecontents($prefix) $d
1185 set oldprefix $prefix
1187 set treecontents($prefix) {}
1188 set treeindex($prefix) [incr ix]
1189 set treeparent($prefix) $oldprefix
1190 set tail [string range $tail [expr {$slash+1}] end]
1191 if {$lev <= $openlevs} {
1193 set treediropen($prefix) [expr {$lev < $openlevs}]
1194 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
1195 $w mark set d:$ix "end -1c"
1196 $w mark gravity d:$ix left
1198 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
1200 $w image create end -align center -image $bm -padx 1 \
1202 $w insert end $d [highlight_tag $prefix]
1203 $w mark set s:$ix "end -1c"
1204 $w mark gravity s:$ix left
1209 if {$lev <= $openlevs} {
1212 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
1214 $w insert end $tail [highlight_tag $f]
1216 lappend treecontents($prefix) $tail
1219 while {$htstack ne {}} {
1220 set treeheight($prefix) $ht
1221 incr ht [lindex $htstack end]
1222 set htstack [lreplace $htstack end end]
1223 set prefixend [lindex $prefendstack end]
1224 set prefendstack [lreplace $prefendstack end end]
1225 set prefix [string range $prefix 0 $prefixend]
1227 $w conf -state disabled
1230 proc linetoelt {l} {
1231 global treeheight treecontents
1236 foreach e $treecontents($prefix) {
1241 if {[string index $e end] eq "/"} {
1242 set n $treeheight($prefix$e)
1254 proc highlight_tree {y prefix} {
1255 global treeheight treecontents cflist
1257 foreach e $treecontents($prefix) {
1259 if {[highlight_tag $path] ne {}} {
1260 $cflist tag add bold $y.0 "$y.0 lineend"
1263 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
1264 set y [highlight_tree $y $path]
1270 proc treeclosedir {w dir} {
1271 global treediropen treeheight treeparent treeindex
1273 set ix $treeindex($dir)
1274 $w conf -state normal
1275 $w delete s:$ix e:$ix
1276 set treediropen($dir) 0
1277 $w image configure a:$ix -image tri-rt
1278 $w conf -state disabled
1279 set n [expr {1 - $treeheight($dir)}]
1280 while {$dir ne {}} {
1281 incr treeheight($dir) $n
1282 set dir $treeparent($dir)
1286 proc treeopendir {w dir} {
1287 global treediropen treeheight treeparent treecontents treeindex
1289 set ix $treeindex($dir)
1290 $w conf -state normal
1291 $w image configure a:$ix -image tri-dn
1292 $w mark set e:$ix s:$ix
1293 $w mark gravity e:$ix right
1296 set n [llength $treecontents($dir)]
1297 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
1300 incr treeheight($x) $n
1302 foreach e $treecontents($dir) {
1304 if {[string index $e end] eq "/"} {
1305 set iy $treeindex($de)
1306 $w mark set d:$iy e:$ix
1307 $w mark gravity d:$iy left
1308 $w insert e:$ix $str
1309 set treediropen($de) 0
1310 $w image create e:$ix -align center -image tri-rt -padx 1 \
1312 $w insert e:$ix $e [highlight_tag $de]
1313 $w mark set s:$iy e:$ix
1314 $w mark gravity s:$iy left
1315 set treeheight($de) 1
1317 $w insert e:$ix $str
1318 $w insert e:$ix $e [highlight_tag $de]
1321 $w mark gravity e:$ix left
1322 $w conf -state disabled
1323 set treediropen($dir) 1
1324 set top [lindex [split [$w index @0,0] .] 0]
1325 set ht [$w cget -height]
1326 set l [lindex [split [$w index s:$ix] .] 0]
1329 } elseif {$l + $n + 1 > $top + $ht} {
1330 set top [expr {$l + $n + 2 - $ht}]
1338 proc treeclick {w x y} {
1339 global treediropen cmitmode ctext cflist cflist_top
1341 if {$cmitmode ne "tree"} return
1342 if {![info exists cflist_top]} return
1343 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1344 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
1345 $cflist tag add highlight $l.0 "$l.0 lineend"
1351 set e [linetoelt $l]
1352 if {[string index $e end] ne "/"} {
1354 } elseif {$treediropen($e)} {
1361 proc setfilelist {id} {
1362 global treefilelist cflist
1364 treeview $cflist $treefilelist($id) 0
1367 image create bitmap tri-rt -background black -foreground blue -data {
1368 #define tri-rt_width 13
1369 #define tri-rt_height 13
1370 static unsigned char tri-rt_bits[] = {
1371 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
1372 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
1375 #define tri-rt-mask_width 13
1376 #define tri-rt-mask_height 13
1377 static unsigned char tri-rt-mask_bits[] = {
1378 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
1379 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
1382 image create bitmap tri-dn -background black -foreground blue -data {
1383 #define tri-dn_width 13
1384 #define tri-dn_height 13
1385 static unsigned char tri-dn_bits[] = {
1386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
1387 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1390 #define tri-dn-mask_width 13
1391 #define tri-dn-mask_height 13
1392 static unsigned char tri-dn-mask_bits[] = {
1393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
1394 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1398 proc init_flist {first} {
1399 global cflist cflist_top selectedline difffilestart
1401 $cflist conf -state normal
1402 $cflist delete 0.0 end
1404 $cflist insert end $first
1406 $cflist tag add highlight 1.0 "1.0 lineend"
1408 catch {unset cflist_top}
1410 $cflist conf -state disabled
1411 set difffilestart {}
1414 proc highlight_tag {f} {
1415 global highlight_paths
1417 foreach p $highlight_paths {
1418 if {[string match $p $f]} {
1425 proc highlight_filelist {} {
1426 global cmitmode cflist
1428 $cflist conf -state normal
1429 if {$cmitmode ne "tree"} {
1430 set end [lindex [split [$cflist index end] .] 0]
1431 for {set l 2} {$l < $end} {incr l} {
1432 set line [$cflist get $l.0 "$l.0 lineend"]
1433 if {[highlight_tag $line] ne {}} {
1434 $cflist tag add bold $l.0 "$l.0 lineend"
1440 $cflist conf -state disabled
1443 proc unhighlight_filelist {} {
1446 $cflist conf -state normal
1447 $cflist tag remove bold 1.0 end
1448 $cflist conf -state disabled
1451 proc add_flist {fl} {
1454 $cflist conf -state normal
1456 $cflist insert end "\n"
1457 $cflist insert end $f [highlight_tag $f]
1459 $cflist conf -state disabled
1462 proc sel_flist {w x y} {
1463 global ctext difffilestart cflist cflist_top cmitmode
1465 if {$cmitmode eq "tree"} return
1466 if {![info exists cflist_top]} return
1467 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1468 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
1469 $cflist tag add highlight $l.0 "$l.0 lineend"
1474 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
1478 # Functions for adding and removing shell-type quoting
1480 proc shellquote {str} {
1481 if {![string match "*\['\"\\ \t]*" $str]} {
1484 if {![string match "*\['\"\\]*" $str]} {
1487 if {![string match "*'*" $str]} {
1490 return "\"[string map {\" \\\" \\ \\\\} $str]\""
1493 proc shellarglist {l} {
1499 append str [shellquote $a]
1504 proc shelldequote {str} {
1509 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
1510 append ret [string range $str $used end]
1511 set used [string length $str]
1514 set first [lindex $first 0]
1515 set ch [string index $str $first]
1516 if {$first > $used} {
1517 append ret [string range $str $used [expr {$first - 1}]]
1520 if {$ch eq " " || $ch eq "\t"} break
1523 set first [string first "'" $str $used]
1525 error "unmatched single-quote"
1527 append ret [string range $str $used [expr {$first - 1}]]
1532 if {$used >= [string length $str]} {
1533 error "trailing backslash"
1535 append ret [string index $str $used]
1540 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
1541 error "unmatched double-quote"
1543 set first [lindex $first 0]
1544 set ch [string index $str $first]
1545 if {$first > $used} {
1546 append ret [string range $str $used [expr {$first - 1}]]
1549 if {$ch eq "\""} break
1551 append ret [string index $str $used]
1555 return [list $used $ret]
1558 proc shellsplit {str} {
1561 set str [string trimleft $str]
1562 if {$str eq {}} break
1563 set dq [shelldequote $str]
1564 set n [lindex $dq 0]
1565 set word [lindex $dq 1]
1566 set str [string range $str $n end]
1572 # Code to implement multiple views
1574 proc newview {ishighlight} {
1575 global nextviewnum newviewname newviewperm uifont newishighlight
1576 global newviewargs revtreeargs
1578 set newishighlight $ishighlight
1580 if {[winfo exists $top]} {
1584 set newviewname($nextviewnum) "View $nextviewnum"
1585 set newviewperm($nextviewnum) 0
1586 set newviewargs($nextviewnum) [shellarglist $revtreeargs]
1587 vieweditor $top $nextviewnum "Gitk view definition"
1592 global viewname viewperm newviewname newviewperm
1593 global viewargs newviewargs
1595 set top .gitkvedit-$curview
1596 if {[winfo exists $top]} {
1600 set newviewname($curview) $viewname($curview)
1601 set newviewperm($curview) $viewperm($curview)
1602 set newviewargs($curview) [shellarglist $viewargs($curview)]
1603 vieweditor $top $curview "Gitk: edit view $viewname($curview)"
1606 proc vieweditor {top n title} {
1607 global newviewname newviewperm viewfiles
1611 wm title $top $title
1612 label $top.nl -text "Name" -font $uifont
1613 entry $top.name -width 20 -textvariable newviewname($n) -font $uifont
1614 grid $top.nl $top.name -sticky w -pady 5
1615 checkbutton $top.perm -text "Remember this view" -variable newviewperm($n) \
1617 grid $top.perm - -pady 5 -sticky w
1618 message $top.al -aspect 1000 -font $uifont \
1619 -text "Commits to include (arguments to git rev-list):"
1620 grid $top.al - -sticky w -pady 5
1621 entry $top.args -width 50 -textvariable newviewargs($n) \
1622 -background white -font $uifont
1623 grid $top.args - -sticky ew -padx 5
1624 message $top.l -aspect 1000 -font $uifont \
1625 -text "Enter files and directories to include, one per line:"
1626 grid $top.l - -sticky w
1627 text $top.t -width 40 -height 10 -background white -font $uifont
1628 if {[info exists viewfiles($n)]} {
1629 foreach f $viewfiles($n) {
1630 $top.t insert end $f
1631 $top.t insert end "\n"
1633 $top.t delete {end - 1c} end
1634 $top.t mark set insert 0.0
1636 grid $top.t - -sticky ew -padx 5
1638 button $top.buts.ok -text "OK" -command [list newviewok $top $n] \
1640 button $top.buts.can -text "Cancel" -command [list destroy $top] \
1642 grid $top.buts.ok $top.buts.can
1643 grid columnconfigure $top.buts 0 -weight 1 -uniform a
1644 grid columnconfigure $top.buts 1 -weight 1 -uniform a
1645 grid $top.buts - -pady 10 -sticky ew
1649 proc doviewmenu {m first cmd op argv} {
1650 set nmenu [$m index end]
1651 for {set i $first} {$i <= $nmenu} {incr i} {
1652 if {[$m entrycget $i -command] eq $cmd} {
1653 eval $m $op $i $argv
1659 proc allviewmenus {n op args} {
1662 doviewmenu .bar.view 5 [list showview $n] $op $args
1663 doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
1666 proc newviewok {top n} {
1667 global nextviewnum newviewperm newviewname newishighlight
1668 global viewname viewfiles viewperm selectedview curview
1669 global viewargs newviewargs viewhlmenu
1672 set newargs [shellsplit $newviewargs($n)]
1674 error_popup "Error in commit selection arguments: $err"
1680 foreach f [split [$top.t get 0.0 end] "\n"] {
1681 set ft [string trim $f]
1686 if {![info exists viewfiles($n)]} {
1687 # creating a new view
1689 set viewname($n) $newviewname($n)
1690 set viewperm($n) $newviewperm($n)
1691 set viewfiles($n) $files
1692 set viewargs($n) $newargs
1694 if {!$newishighlight} {
1697 run addvhighlight $n
1700 # editing an existing view
1701 set viewperm($n) $newviewperm($n)
1702 if {$newviewname($n) ne $viewname($n)} {
1703 set viewname($n) $newviewname($n)
1704 doviewmenu .bar.view 5 [list showview $n] \
1705 entryconf [list -label $viewname($n)]
1706 doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
1707 entryconf [list -label $viewname($n) -value $viewname($n)]
1709 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n)} {
1710 set viewfiles($n) $files
1711 set viewargs($n) $newargs
1712 if {$curview == $n} {
1717 catch {destroy $top}
1721 global curview viewdata viewperm hlview selectedhlview
1723 if {$curview == 0} return
1724 if {[info exists hlview] && $hlview == $curview} {
1725 set selectedhlview None
1728 allviewmenus $curview delete
1729 set viewdata($curview) {}
1730 set viewperm($curview) 0
1734 proc addviewmenu {n} {
1735 global viewname viewhlmenu
1737 .bar.view add radiobutton -label $viewname($n) \
1738 -command [list showview $n] -variable selectedview -value $n
1739 $viewhlmenu add radiobutton -label $viewname($n) \
1740 -command [list addvhighlight $n] -variable selectedhlview
1743 proc flatten {var} {
1747 foreach i [array names $var] {
1748 lappend ret $i [set $var\($i\)]
1753 proc unflatten {var l} {
1763 global curview viewdata viewfiles
1764 global displayorder parentlist rowidlist rowoffsets
1765 global colormap rowtextx commitrow nextcolor canvxmax
1766 global numcommits rowrangelist commitlisted idrowranges rowchk
1767 global selectedline currentid canv canvy0
1769 global pending_select phase
1770 global commitidx rowlaidout rowoptim
1772 global selectedview selectfirst
1773 global vparentlist vdisporder vcmitlisted
1774 global hlview selectedhlview
1776 if {$n == $curview} return
1778 if {[info exists selectedline]} {
1779 set selid $currentid
1780 set y [yc $selectedline]
1781 set ymax [lindex [$canv cget -scrollregion] 3]
1782 set span [$canv yview]
1783 set ytop [expr {[lindex $span 0] * $ymax}]
1784 set ybot [expr {[lindex $span 1] * $ymax}]
1785 if {$ytop < $y && $y < $ybot} {
1786 set yscreen [expr {$y - $ytop}]
1788 set yscreen [expr {($ybot - $ytop) / 2}]
1790 } elseif {[info exists pending_select]} {
1791 set selid $pending_select
1792 unset pending_select
1796 if {$curview >= 0} {
1797 set vparentlist($curview) $parentlist
1798 set vdisporder($curview) $displayorder
1799 set vcmitlisted($curview) $commitlisted
1801 set viewdata($curview) \
1802 [list $phase $rowidlist $rowoffsets $rowrangelist \
1803 [flatten idrowranges] [flatten idinlist] \
1804 $rowlaidout $rowoptim $numcommits]
1805 } elseif {![info exists viewdata($curview)]
1806 || [lindex $viewdata($curview) 0] ne {}} {
1807 set viewdata($curview) \
1808 [list {} $rowidlist $rowoffsets $rowrangelist]
1811 catch {unset treediffs}
1813 if {[info exists hlview] && $hlview == $n} {
1815 set selectedhlview None
1820 .bar.view entryconf Edit* -state [expr {$n == 0? "disabled": "normal"}]
1821 .bar.view entryconf Delete* -state [expr {$n == 0? "disabled": "normal"}]
1823 if {![info exists viewdata($n)]} {
1825 set pending_select $selid
1832 set phase [lindex $v 0]
1833 set displayorder $vdisporder($n)
1834 set parentlist $vparentlist($n)
1835 set commitlisted $vcmitlisted($n)
1836 set rowidlist [lindex $v 1]
1837 set rowoffsets [lindex $v 2]
1838 set rowrangelist [lindex $v 3]
1840 set numcommits [llength $displayorder]
1841 catch {unset idrowranges}
1843 unflatten idrowranges [lindex $v 4]
1844 unflatten idinlist [lindex $v 5]
1845 set rowlaidout [lindex $v 6]
1846 set rowoptim [lindex $v 7]
1847 set numcommits [lindex $v 8]
1848 catch {unset rowchk}
1851 catch {unset colormap}
1852 catch {unset rowtextx}
1854 set canvxmax [$canv cget -width]
1861 if {$selid ne {} && [info exists commitrow($n,$selid)]} {
1862 set row $commitrow($n,$selid)
1863 # try to get the selected row in the same position on the screen
1864 set ymax [lindex [$canv cget -scrollregion] 3]
1865 set ytop [expr {[yc $row] - $yscreen}]
1869 set yf [expr {$ytop * 1.0 / $ymax}]
1871 allcanvs yview moveto $yf
1875 } elseif {$selid ne {}} {
1876 set pending_select $selid
1878 set row [expr {[lindex $displayorder 0] eq $nullid}]
1879 if {$row < $numcommits} {
1886 if {$phase eq "getcommits"} {
1887 show_status "Reading commits..."
1890 } elseif {$numcommits == 0} {
1891 show_status "No commits selected"
1895 # Stuff relating to the highlighting facility
1897 proc ishighlighted {row} {
1898 global vhighlights fhighlights nhighlights rhighlights
1900 if {[info exists nhighlights($row)] && $nhighlights($row) > 0} {
1901 return $nhighlights($row)
1903 if {[info exists vhighlights($row)] && $vhighlights($row) > 0} {
1904 return $vhighlights($row)
1906 if {[info exists fhighlights($row)] && $fhighlights($row) > 0} {
1907 return $fhighlights($row)
1909 if {[info exists rhighlights($row)] && $rhighlights($row) > 0} {
1910 return $rhighlights($row)
1915 proc bolden {row font} {
1916 global canv linehtag selectedline boldrows
1918 lappend boldrows $row
1919 $canv itemconf $linehtag($row) -font $font
1920 if {[info exists selectedline] && $row == $selectedline} {
1922 set t [eval $canv create rect [$canv bbox $linehtag($row)] \
1923 -outline {{}} -tags secsel \
1924 -fill [$canv cget -selectbackground]]
1929 proc bolden_name {row font} {
1930 global canv2 linentag selectedline boldnamerows
1932 lappend boldnamerows $row
1933 $canv2 itemconf $linentag($row) -font $font
1934 if {[info exists selectedline] && $row == $selectedline} {
1935 $canv2 delete secsel
1936 set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \
1937 -outline {{}} -tags secsel \
1938 -fill [$canv2 cget -selectbackground]]
1944 global mainfont boldrows
1947 foreach row $boldrows {
1948 if {![ishighlighted $row]} {
1949 bolden $row $mainfont
1951 lappend stillbold $row
1954 set boldrows $stillbold
1957 proc addvhighlight {n} {
1958 global hlview curview viewdata vhl_done vhighlights commitidx
1960 if {[info exists hlview]} {
1964 if {$n != $curview && ![info exists viewdata($n)]} {
1965 set viewdata($n) [list getcommits {{}} {{}} {} {} {} 0 0 0 {}]
1966 set vparentlist($n) {}
1967 set vdisporder($n) {}
1968 set vcmitlisted($n) {}
1971 set vhl_done $commitidx($hlview)
1972 if {$vhl_done > 0} {
1977 proc delvhighlight {} {
1978 global hlview vhighlights
1980 if {![info exists hlview]} return
1982 catch {unset vhighlights}
1986 proc vhighlightmore {} {
1987 global hlview vhl_done commitidx vhighlights
1988 global displayorder vdisporder curview mainfont
1990 set font [concat $mainfont bold]
1991 set max $commitidx($hlview)
1992 if {$hlview == $curview} {
1993 set disp $displayorder
1995 set disp $vdisporder($hlview)
1997 set vr [visiblerows]
1998 set r0 [lindex $vr 0]
1999 set r1 [lindex $vr 1]
2000 for {set i $vhl_done} {$i < $max} {incr i} {
2001 set id [lindex $disp $i]
2002 if {[info exists commitrow($curview,$id)]} {
2003 set row $commitrow($curview,$id)
2004 if {$r0 <= $row && $row <= $r1} {
2005 if {![highlighted $row]} {
2008 set vhighlights($row) 1
2015 proc askvhighlight {row id} {
2016 global hlview vhighlights commitrow iddrawn mainfont
2018 if {[info exists commitrow($hlview,$id)]} {
2019 if {[info exists iddrawn($id)] && ![ishighlighted $row]} {
2020 bolden $row [concat $mainfont bold]
2022 set vhighlights($row) 1
2024 set vhighlights($row) 0
2028 proc hfiles_change {name ix op} {
2029 global highlight_files filehighlight fhighlights fh_serial
2030 global mainfont highlight_paths
2032 if {[info exists filehighlight]} {
2033 # delete previous highlights
2034 catch {close $filehighlight}
2036 catch {unset fhighlights}
2038 unhighlight_filelist
2040 set highlight_paths {}
2041 after cancel do_file_hl $fh_serial
2043 if {$highlight_files ne {}} {
2044 after 300 do_file_hl $fh_serial
2048 proc makepatterns {l} {
2051 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
2052 if {[string index $ee end] eq "/"} {
2062 proc do_file_hl {serial} {
2063 global highlight_files filehighlight highlight_paths gdttype fhl_list
2065 if {$gdttype eq "touching paths:"} {
2066 if {[catch {set paths [shellsplit $highlight_files]}]} return
2067 set highlight_paths [makepatterns $paths]
2069 set gdtargs [concat -- $paths]
2071 set gdtargs [list "-S$highlight_files"]
2073 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
2074 set filehighlight [open $cmd r+]
2075 fconfigure $filehighlight -blocking 0
2076 filerun $filehighlight readfhighlight
2082 proc flushhighlights {} {
2083 global filehighlight fhl_list
2085 if {[info exists filehighlight]} {
2087 puts $filehighlight ""
2088 flush $filehighlight
2092 proc askfilehighlight {row id} {
2093 global filehighlight fhighlights fhl_list
2095 lappend fhl_list $id
2096 set fhighlights($row) -1
2097 puts $filehighlight $id
2100 proc readfhighlight {} {
2101 global filehighlight fhighlights commitrow curview mainfont iddrawn
2104 if {![info exists filehighlight]} {
2108 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
2109 set line [string trim $line]
2110 set i [lsearch -exact $fhl_list $line]
2111 if {$i < 0} continue
2112 for {set j 0} {$j < $i} {incr j} {
2113 set id [lindex $fhl_list $j]
2114 if {[info exists commitrow($curview,$id)]} {
2115 set fhighlights($commitrow($curview,$id)) 0
2118 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
2119 if {$line eq {}} continue
2120 if {![info exists commitrow($curview,$line)]} continue
2121 set row $commitrow($curview,$line)
2122 if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
2123 bolden $row [concat $mainfont bold]
2125 set fhighlights($row) 1
2127 if {[eof $filehighlight]} {
2129 puts "oops, git diff-tree died"
2130 catch {close $filehighlight}
2138 proc find_change {name ix op} {
2139 global nhighlights mainfont boldnamerows
2140 global findstring findpattern findtype markingmatches
2142 # delete previous highlights, if any
2143 foreach row $boldnamerows {
2144 bolden_name $row $mainfont
2147 catch {unset nhighlights}
2150 if {$findtype ne "Regexp"} {
2151 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
2153 set findpattern "*$e*"
2155 set markingmatches [expr {$findstring ne {}}]
2159 proc doesmatch {f} {
2160 global findtype findstring findpattern
2162 if {$findtype eq "Regexp"} {
2163 return [regexp $findstring $f]
2164 } elseif {$findtype eq "IgnCase"} {
2165 return [string match -nocase $findpattern $f]
2167 return [string match $findpattern $f]
2171 proc askfindhighlight {row id} {
2172 global nhighlights commitinfo iddrawn mainfont
2174 global markingmatches
2176 if {![info exists commitinfo($id)]} {
2179 set info $commitinfo($id)
2181 set fldtypes {Headline Author Date Committer CDate Comments}
2182 foreach f $info ty $fldtypes {
2183 if {($findloc eq "All fields" || $findloc eq $ty) &&
2185 if {$ty eq "Author"} {
2192 if {$isbold && [info exists iddrawn($id)]} {
2193 set f [concat $mainfont bold]
2194 if {![ishighlighted $row]} {
2200 if {$markingmatches} {
2201 markrowmatches $row [lindex $info 0] [lindex $info 1]
2204 set nhighlights($row) $isbold
2207 proc markrowmatches {row headline author} {
2208 global canv canv2 linehtag linentag
2210 $canv delete match$row
2211 $canv2 delete match$row
2212 set m [findmatches $headline]
2214 markmatches $canv $row $headline $linehtag($row) $m \
2215 [$canv itemcget $linehtag($row) -font]
2217 set m [findmatches $author]
2219 markmatches $canv2 $row $author $linentag($row) $m \
2220 [$canv2 itemcget $linentag($row) -font]
2224 proc vrel_change {name ix op} {
2225 global highlight_related
2228 if {$highlight_related ne "None"} {
2233 # prepare for testing whether commits are descendents or ancestors of a
2234 proc rhighlight_sel {a} {
2235 global descendent desc_todo ancestor anc_todo
2236 global highlight_related rhighlights
2238 catch {unset descendent}
2239 set desc_todo [list $a]
2240 catch {unset ancestor}
2241 set anc_todo [list $a]
2242 if {$highlight_related ne "None"} {
2248 proc rhighlight_none {} {
2251 catch {unset rhighlights}
2255 proc is_descendent {a} {
2256 global curview children commitrow descendent desc_todo
2259 set la $commitrow($v,$a)
2263 for {set i 0} {$i < [llength $todo]} {incr i} {
2264 set do [lindex $todo $i]
2265 if {$commitrow($v,$do) < $la} {
2266 lappend leftover $do
2269 foreach nk $children($v,$do) {
2270 if {![info exists descendent($nk)]} {
2271 set descendent($nk) 1
2279 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
2283 set descendent($a) 0
2284 set desc_todo $leftover
2287 proc is_ancestor {a} {
2288 global curview parentlist commitrow ancestor anc_todo
2291 set la $commitrow($v,$a)
2295 for {set i 0} {$i < [llength $todo]} {incr i} {
2296 set do [lindex $todo $i]
2297 if {![info exists commitrow($v,$do)] || $commitrow($v,$do) > $la} {
2298 lappend leftover $do
2301 foreach np [lindex $parentlist $commitrow($v,$do)] {
2302 if {![info exists ancestor($np)]} {
2311 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
2316 set anc_todo $leftover
2319 proc askrelhighlight {row id} {
2320 global descendent highlight_related iddrawn mainfont rhighlights
2321 global selectedline ancestor
2323 if {![info exists selectedline]} return
2325 if {$highlight_related eq "Descendent" ||
2326 $highlight_related eq "Not descendent"} {
2327 if {![info exists descendent($id)]} {
2330 if {$descendent($id) == ($highlight_related eq "Descendent")} {
2333 } elseif {$highlight_related eq "Ancestor" ||
2334 $highlight_related eq "Not ancestor"} {
2335 if {![info exists ancestor($id)]} {
2338 if {$ancestor($id) == ($highlight_related eq "Ancestor")} {
2342 if {[info exists iddrawn($id)]} {
2343 if {$isbold && ![ishighlighted $row]} {
2344 bolden $row [concat $mainfont bold]
2347 set rhighlights($row) $isbold
2350 proc next_hlcont {} {
2351 global fhl_row fhl_dirn displayorder numcommits
2352 global vhighlights fhighlights nhighlights rhighlights
2353 global hlview filehighlight findstring highlight_related
2355 if {![info exists fhl_dirn] || $fhl_dirn == 0} return
2358 if {$row < 0 || $row >= $numcommits} {
2363 set id [lindex $displayorder $row]
2364 if {[info exists hlview]} {
2365 if {![info exists vhighlights($row)]} {
2366 askvhighlight $row $id
2368 if {$vhighlights($row) > 0} break
2370 if {$findstring ne {}} {
2371 if {![info exists nhighlights($row)]} {
2372 askfindhighlight $row $id
2374 if {$nhighlights($row) > 0} break
2376 if {$highlight_related ne "None"} {
2377 if {![info exists rhighlights($row)]} {
2378 askrelhighlight $row $id
2380 if {$rhighlights($row) > 0} break
2382 if {[info exists filehighlight]} {
2383 if {![info exists fhighlights($row)]} {
2384 # ask for a few more while we're at it...
2386 for {set n 0} {$n < 100} {incr n} {
2387 if {![info exists fhighlights($r)]} {
2388 askfilehighlight $r [lindex $displayorder $r]
2391 if {$r < 0 || $r >= $numcommits} break
2395 if {$fhighlights($row) < 0} {
2399 if {$fhighlights($row) > 0} break
2407 proc next_highlight {dirn} {
2408 global selectedline fhl_row fhl_dirn
2409 global hlview filehighlight findstring highlight_related
2411 if {![info exists selectedline]} return
2412 if {!([info exists hlview] || $findstring ne {} ||
2413 $highlight_related ne "None" || [info exists filehighlight])} return
2414 set fhl_row [expr {$selectedline + $dirn}]
2419 proc cancel_next_highlight {} {
2425 # Graph layout functions
2427 proc shortids {ids} {
2430 if {[llength $id] > 1} {
2431 lappend res [shortids $id]
2432 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
2433 lappend res [string range $id 0 7]
2441 proc incrange {l x o} {
2444 set e [lindex $l $x]
2446 lset l $x [expr {$e + $o}]
2455 for {} {$n > 0} {incr n -1} {
2461 proc usedinrange {id l1 l2} {
2462 global children commitrow curview
2464 if {[info exists commitrow($curview,$id)]} {
2465 set r $commitrow($curview,$id)
2466 if {$l1 <= $r && $r <= $l2} {
2467 return [expr {$r - $l1 + 1}]
2470 set kids $children($curview,$id)
2472 set r $commitrow($curview,$c)
2473 if {$l1 <= $r && $r <= $l2} {
2474 return [expr {$r - $l1 + 1}]
2480 proc sanity {row {full 0}} {
2481 global rowidlist rowoffsets
2484 set ids [lindex $rowidlist $row]
2487 if {$id eq {}} continue
2488 if {$col < [llength $ids] - 1 &&
2489 [lsearch -exact -start [expr {$col+1}] $ids $id] >= 0} {
2490 puts "oops: [shortids $id] repeated in row $row col $col: {[shortids [lindex $rowidlist $row]]}"
2492 set o [lindex $rowoffsets $row $col]
2498 if {[lindex $rowidlist $y $x] != $id} {
2499 puts "oops: rowoffsets wrong at row [expr {$y+1}] col [expr {$x-$o}]"
2500 puts " id=[shortids $id] check started at row $row"
2501 for {set i $row} {$i >= $y} {incr i -1} {
2502 puts " row $i ids={[shortids [lindex $rowidlist $i]]} offs={[lindex $rowoffsets $i]}"
2507 set o [lindex $rowoffsets $y $x]
2512 proc makeuparrow {oid x y z} {
2513 global rowidlist rowoffsets uparrowlen idrowranges displayorder
2515 for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
2518 set off0 [lindex $rowoffsets $y]
2519 for {set x0 $x} {1} {incr x0} {
2520 if {$x0 >= [llength $off0]} {
2521 set x0 [llength [lindex $rowoffsets [expr {$y-1}]]]
2524 set z [lindex $off0 $x0]
2530 set z [expr {$x0 - $x}]
2531 lset rowidlist $y [linsert [lindex $rowidlist $y] $x $oid]
2532 lset rowoffsets $y [linsert [lindex $rowoffsets $y] $x $z]
2534 set tmp [lreplace [lindex $rowoffsets $y] $x $x {}]
2535 lset rowoffsets $y [incrange $tmp [expr {$x+1}] -1]
2536 lappend idrowranges($oid) [lindex $displayorder $y]
2539 proc initlayout {} {
2540 global rowidlist rowoffsets displayorder commitlisted
2541 global rowlaidout rowoptim
2542 global idinlist rowchk rowrangelist idrowranges
2543 global numcommits canvxmax canv
2546 global colormap rowtextx
2557 catch {unset idinlist}
2558 catch {unset rowchk}
2561 set canvxmax [$canv cget -width]
2562 catch {unset colormap}
2563 catch {unset rowtextx}
2564 catch {unset idrowranges}
2568 proc setcanvscroll {} {
2569 global canv canv2 canv3 numcommits linespc canvxmax canvy0
2571 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
2572 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
2573 $canv2 conf -scrollregion [list 0 0 0 $ymax]
2574 $canv3 conf -scrollregion [list 0 0 0 $ymax]
2577 proc visiblerows {} {
2578 global canv numcommits linespc
2580 set ymax [lindex [$canv cget -scrollregion] 3]
2581 if {$ymax eq {} || $ymax == 0} return
2583 set y0 [expr {int([lindex $f 0] * $ymax)}]
2584 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
2588 set y1 [expr {int([lindex $f 1] * $ymax)}]
2589 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
2590 if {$r1 >= $numcommits} {
2591 set r1 [expr {$numcommits - 1}]
2593 return [list $r0 $r1]
2596 proc layoutmore {tmax allread} {
2597 global rowlaidout rowoptim commitidx numcommits optim_delay
2598 global uparrowlen curview rowidlist idinlist
2601 set showdelay $optim_delay
2602 set optdelay [expr {$uparrowlen + 1}]
2604 if {$rowoptim - $showdelay > $numcommits} {
2605 showstuff [expr {$rowoptim - $showdelay}] $showlast
2606 } elseif {$rowlaidout - $optdelay > $rowoptim} {
2607 set nr [expr {$rowlaidout - $optdelay - $rowoptim}]
2611 optimize_rows $rowoptim 0 [expr {$rowoptim + $nr}]
2613 } elseif {$commitidx($curview) > $rowlaidout} {
2614 set nr [expr {$commitidx($curview) - $rowlaidout}]
2615 # may need to increase this threshold if uparrowlen or
2616 # mingaplen are increased...
2621 set rowlaidout [layoutrows $row [expr {$row + $nr}] $allread]
2622 if {$rowlaidout == $row} {
2625 } elseif {$allread} {
2627 set nrows $commitidx($curview)
2628 if {[lindex $rowidlist $nrows] ne {} ||
2629 [array names idinlist] ne {}} {
2631 set rowlaidout $commitidx($curview)
2632 } elseif {$rowoptim == $nrows} {
2635 if {$numcommits == $nrows} {
2642 if {$tmax ne {} && [clock clicks -milliseconds] >= $tmax} {
2648 proc showstuff {canshow last} {
2649 global numcommits commitrow pending_select selectedline curview
2650 global lookingforhead mainheadid displayorder nullid selectfirst
2651 global lastscrollset
2653 if {$numcommits == 0} {
2655 set phase "incrdraw"
2659 set prev $numcommits
2660 set numcommits $canshow
2661 set t [clock clicks -milliseconds]
2662 if {$prev < 100 || $last || $t - $lastscrollset > 500} {
2663 set lastscrollset $t
2666 set rows [visiblerows]
2667 set r1 [lindex $rows 1]
2668 if {$r1 >= $canshow} {
2669 set r1 [expr {$canshow - 1}]
2674 if {[info exists pending_select] &&
2675 [info exists commitrow($curview,$pending_select)] &&
2676 $commitrow($curview,$pending_select) < $numcommits} {
2677 selectline $commitrow($curview,$pending_select) 1
2680 if {[info exists selectedline] || [info exists pending_select]} {
2683 set l [expr {[lindex $displayorder 0] eq $nullid}]
2688 if {$lookingforhead && [info exists commitrow($curview,$mainheadid)]
2689 && ($last || $commitrow($curview,$mainheadid) < $numcommits - 1)} {
2690 set lookingforhead 0
2695 proc doshowlocalchanges {} {
2696 global lookingforhead curview mainheadid phase commitrow
2698 if {[info exists commitrow($curview,$mainheadid)] &&
2699 ($phase eq {} || $commitrow($curview,$mainheadid) < $numcommits - 1)} {
2701 } elseif {$phase ne {}} {
2702 set lookingforhead 1
2706 proc dohidelocalchanges {} {
2707 global lookingforhead localrow lserial
2709 set lookingforhead 0
2710 if {$localrow >= 0} {
2717 # spawn off a process to do git diff-index HEAD
2718 proc dodiffindex {} {
2719 global localrow lserial
2723 set fd [open "|git diff-index HEAD" r]
2724 fconfigure $fd -blocking 0
2725 filerun $fd [list readdiffindex $fd $lserial]
2728 proc readdiffindex {fd serial} {
2729 global localrow commitrow mainheadid nullid curview
2730 global commitinfo commitdata lserial
2732 if {[gets $fd line] < 0} {
2739 # we only need to see one line and we don't really care what it says...
2742 if {$serial == $lserial && $localrow == -1} {
2743 # add the line for the local diff to the graph
2744 set localrow $commitrow($curview,$mainheadid)
2745 set hl "Local uncommitted changes"
2746 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
2747 set commitdata($nullid) "\n $hl\n"
2748 insertrow $localrow $nullid
2753 proc layoutrows {row endrow last} {
2754 global rowidlist rowoffsets displayorder
2755 global uparrowlen downarrowlen maxwidth mingaplen
2756 global children parentlist
2758 global commitidx curview
2759 global idinlist rowchk rowrangelist
2761 set idlist [lindex $rowidlist $row]
2762 set offs [lindex $rowoffsets $row]
2763 while {$row < $endrow} {
2764 set id [lindex $displayorder $row]
2767 foreach p [lindex $parentlist $row] {
2768 if {![info exists idinlist($p)]} {
2770 } elseif {!$idinlist($p)} {
2774 set nev [expr {[llength $idlist] + [llength $newolds]
2775 + [llength $oldolds] - $maxwidth + 1}]
2778 $row + $uparrowlen + $mingaplen >= $commitidx($curview)} break
2779 for {set x [llength $idlist]} {[incr x -1] >= 0} {} {
2780 set i [lindex $idlist $x]
2781 if {![info exists rowchk($i)] || $row >= $rowchk($i)} {
2782 set r [usedinrange $i [expr {$row - $downarrowlen}] \
2783 [expr {$row + $uparrowlen + $mingaplen}]]
2785 set idlist [lreplace $idlist $x $x]
2786 set offs [lreplace $offs $x $x]
2787 set offs [incrange $offs $x 1]
2789 set rm1 [expr {$row - 1}]
2790 lappend idrowranges($i) [lindex $displayorder $rm1]
2791 if {[incr nev -1] <= 0} break
2794 set rowchk($id) [expr {$row + $r}]
2797 lset rowidlist $row $idlist
2798 lset rowoffsets $row $offs
2800 set col [lsearch -exact $idlist $id]
2802 set col [llength $idlist]
2804 lset rowidlist $row $idlist
2806 if {$children($curview,$id) ne {}} {
2807 set z [expr {[llength [lindex $rowidlist [expr {$row-1}]]] - $col}]
2811 lset rowoffsets $row $offs
2813 makeuparrow $id $col $row $z
2819 if {[info exists idrowranges($id)]} {
2820 set ranges $idrowranges($id)
2822 unset idrowranges($id)
2824 lappend rowrangelist $ranges
2826 set offs [ntimes [llength $idlist] 0]
2827 set l [llength $newolds]
2828 set idlist [eval lreplace \$idlist $col $col $newolds]
2831 set offs [lrange $offs 0 [expr {$col - 1}]]
2832 foreach x $newolds {
2837 set tmp [expr {[llength $idlist] - [llength $offs]}]
2839 set offs [concat $offs [ntimes $tmp $o]]
2844 foreach i $newolds {
2846 set idrowranges($i) $id
2849 foreach oid $oldolds {
2850 set idinlist($oid) 1
2851 set idlist [linsert $idlist $col $oid]
2852 set offs [linsert $offs $col $o]
2853 makeuparrow $oid $col $row $o
2856 lappend rowidlist $idlist
2857 lappend rowoffsets $offs
2862 proc addextraid {id row} {
2863 global displayorder commitrow commitinfo
2864 global commitidx commitlisted
2865 global parentlist children curview
2867 incr commitidx($curview)
2868 lappend displayorder $id
2869 lappend commitlisted 0
2870 lappend parentlist {}
2871 set commitrow($curview,$id) $row
2873 if {![info exists commitinfo($id)]} {
2874 set commitinfo($id) {"No commit information available"}
2876 if {![info exists children($curview,$id)]} {
2877 set children($curview,$id) {}
2881 proc layouttail {} {
2882 global rowidlist rowoffsets idinlist commitidx curview
2883 global idrowranges rowrangelist
2885 set row $commitidx($curview)
2886 set idlist [lindex $rowidlist $row]
2887 while {$idlist ne {}} {
2888 set col [expr {[llength $idlist] - 1}]
2889 set id [lindex $idlist $col]
2892 lappend idrowranges($id) $id
2893 lappend rowrangelist $idrowranges($id)
2894 unset idrowranges($id)
2896 set offs [ntimes $col 0]
2897 set idlist [lreplace $idlist $col $col]
2898 lappend rowidlist $idlist
2899 lappend rowoffsets $offs
2902 foreach id [array names idinlist] {
2905 lset rowidlist $row [list $id]
2906 lset rowoffsets $row 0
2907 makeuparrow $id 0 $row 0
2908 lappend idrowranges($id) $id
2909 lappend rowrangelist $idrowranges($id)
2910 unset idrowranges($id)
2912 lappend rowidlist {}
2913 lappend rowoffsets {}
2917 proc insert_pad {row col npad} {
2918 global rowidlist rowoffsets
2920 set pad [ntimes $npad {}]
2921 lset rowidlist $row [eval linsert [list [lindex $rowidlist $row]] $col $pad]
2922 set tmp [eval linsert [list [lindex $rowoffsets $row]] $col $pad]
2923 lset rowoffsets $row [incrange $tmp [expr {$col + $npad}] [expr {-$npad}]]
2926 proc optimize_rows {row col endrow} {
2927 global rowidlist rowoffsets displayorder
2929 for {} {$row < $endrow} {incr row} {
2930 set idlist [lindex $rowidlist $row]
2931 set offs [lindex $rowoffsets $row]
2933 for {} {$col < [llength $offs]} {incr col} {
2934 if {[lindex $idlist $col] eq {}} {
2938 set z [lindex $offs $col]
2939 if {$z eq {}} continue
2941 set x0 [expr {$col + $z}]
2942 set y0 [expr {$row - 1}]
2943 set z0 [lindex $rowoffsets $y0 $x0]
2945 set id [lindex $idlist $col]
2946 set ranges [rowranges $id]
2947 if {$ranges ne {} && $y0 > [lindex $ranges 0]} {
2951 # Looking at lines from this row to the previous row,
2952 # make them go straight up if they end in an arrow on
2953 # the previous row; otherwise make them go straight up
2955 if {$z < -1 || ($z < 0 && $isarrow)} {
2956 # Line currently goes left too much;
2957 # insert pads in the previous row, then optimize it
2958 set npad [expr {-1 - $z + $isarrow}]
2959 set offs [incrange $offs $col $npad]
2960 insert_pad $y0 $x0 $npad
2962 optimize_rows $y0 $x0 $row
2964 set z [lindex $offs $col]
2965 set x0 [expr {$col + $z}]
2966 set z0 [lindex $rowoffsets $y0 $x0]
2967 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
2968 # Line currently goes right too much;
2969 # insert pads in this line and adjust the next's rowoffsets
2970 set npad [expr {$z - 1 + $isarrow}]
2971 set y1 [expr {$row + 1}]
2972 set offs2 [lindex $rowoffsets $y1]
2976 if {$z eq {} || $x1 + $z < $col} continue
2977 if {$x1 + $z > $col} {
2980 lset rowoffsets $y1 [incrange $offs2 $x1 $npad]
2983 set pad [ntimes $npad {}]
2984 set idlist [eval linsert \$idlist $col $pad]
2985 set tmp [eval linsert \$offs $col $pad]
2987 set offs [incrange $tmp $col [expr {-$npad}]]
2988 set z [lindex $offs $col]
2991 if {$z0 eq {} && !$isarrow} {
2992 # this line links to its first child on row $row-2
2993 set rm2 [expr {$row - 2}]
2994 set id [lindex $displayorder $rm2]
2995 set xc [lsearch -exact [lindex $rowidlist $rm2] $id]
2997 set z0 [expr {$xc - $x0}]
3000 # avoid lines jigging left then immediately right
3001 if {$z0 ne {} && $z < 0 && $z0 > 0} {
3002 insert_pad $y0 $x0 1
3003 set offs [incrange $offs $col 1]
3004 optimize_rows $y0 [expr {$x0 + 1}] $row
3009 # Find the first column that doesn't have a line going right
3010 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
3011 set o [lindex $offs $col]
3013 # check if this is the link to the first child
3014 set id [lindex $idlist $col]
3015 set ranges [rowranges $id]
3016 if {$ranges ne {} && $row == [lindex $ranges 0]} {
3017 # it is, work out offset to child
3018 set y0 [expr {$row - 1}]
3019 set id [lindex $displayorder $y0]
3020 set x0 [lsearch -exact [lindex $rowidlist $y0] $id]
3022 set o [expr {$x0 - $col}]
3026 if {$o eq {} || $o <= 0} break
3028 # Insert a pad at that column as long as it has a line and
3029 # isn't the last column, and adjust the next row' offsets
3030 if {$o ne {} && [incr col] < [llength $idlist]} {
3031 set y1 [expr {$row + 1}]
3032 set offs2 [lindex $rowoffsets $y1]
3036 if {$z eq {} || $x1 + $z < $col} continue
3037 lset rowoffsets $y1 [incrange $offs2 $x1 1]
3040 set idlist [linsert $idlist $col {}]
3041 set tmp [linsert $offs $col {}]
3043 set offs [incrange $tmp $col -1]
3046 lset rowidlist $row $idlist
3047 lset rowoffsets $row $offs
3053 global canvx0 linespc
3054 return [expr {$canvx0 + $col * $linespc}]
3058 global canvy0 linespc
3059 return [expr {$canvy0 + $row * $linespc}]
3062 proc linewidth {id} {
3063 global thickerline lthickness
3066 if {[info exists thickerline] && $id eq $thickerline} {
3067 set wid [expr {2 * $lthickness}]
3072 proc rowranges {id} {
3073 global phase idrowranges commitrow rowlaidout rowrangelist curview
3077 ([info exists commitrow($curview,$id)]
3078 && $commitrow($curview,$id) < $rowlaidout)} {
3079 set ranges [lindex $rowrangelist $commitrow($curview,$id)]
3080 } elseif {[info exists idrowranges($id)]} {
3081 set ranges $idrowranges($id)
3084 foreach rid $ranges {
3085 lappend linenos $commitrow($curview,$rid)
3087 if {$linenos ne {}} {
3088 lset linenos 0 [expr {[lindex $linenos 0] + 1}]
3093 # work around tk8.4 refusal to draw arrows on diagonal segments
3094 proc adjarrowhigh {coords} {
3097 set x0 [lindex $coords 0]
3098 set x1 [lindex $coords 2]
3100 set y0 [lindex $coords 1]
3101 set y1 [lindex $coords 3]
3102 if {$y0 - $y1 <= 2 * $linespc && $x1 == [lindex $coords 4]} {
3103 # we have a nearby vertical segment, just trim off the diag bit
3104 set coords [lrange $coords 2 end]
3106 set slope [expr {($x0 - $x1) / ($y0 - $y1)}]
3107 set xi [expr {$x0 - $slope * $linespc / 2}]
3108 set yi [expr {$y0 - $linespc / 2}]
3109 set coords [lreplace $coords 0 1 $xi $y0 $xi $yi]
3115 proc drawlineseg {id row endrow arrowlow} {
3116 global rowidlist displayorder iddrawn linesegs
3117 global canv colormap linespc curview maxlinelen
3119 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
3120 set le [expr {$row + 1}]
3123 set c [lsearch -exact [lindex $rowidlist $le] $id]
3129 set x [lindex $displayorder $le]
3134 if {[info exists iddrawn($x)] || $le == $endrow} {
3135 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
3151 if {[info exists linesegs($id)]} {
3152 set lines $linesegs($id)
3154 set r0 [lindex $li 0]
3156 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
3166 set li [lindex $lines [expr {$i-1}]]
3167 set r1 [lindex $li 1]
3168 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
3173 set x [lindex $cols [expr {$le - $row}]]
3174 set xp [lindex $cols [expr {$le - 1 - $row}]]
3175 set dir [expr {$xp - $x}]
3177 set ith [lindex $lines $i 2]
3178 set coords [$canv coords $ith]
3179 set ah [$canv itemcget $ith -arrow]
3180 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
3181 set x2 [lindex $cols [expr {$le + 1 - $row}]]
3182 if {$x2 ne {} && $x - $x2 == $dir} {
3183 set coords [lrange $coords 0 end-2]
3186 set coords [list [xc $le $x] [yc $le]]
3189 set itl [lindex $lines [expr {$i-1}] 2]
3190 set al [$canv itemcget $itl -arrow]
3191 set arrowlow [expr {$al eq "last" || $al eq "both"}]
3192 } elseif {$arrowlow &&
3193 [lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0} {
3196 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
3197 for {set y $le} {[incr y -1] > $row} {} {
3199 set xp [lindex $cols [expr {$y - 1 - $row}]]
3200 set ndir [expr {$xp - $x}]
3201 if {$dir != $ndir || $xp < 0} {
3202 lappend coords [xc $y $x] [yc $y]
3208 # join parent line to first child
3209 set ch [lindex $displayorder $row]
3210 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
3212 puts "oops: drawlineseg: child $ch not on row $row"
3215 lappend coords [xc $row [expr {$x-1}]] [yc $row]
3216 } elseif {$xc > $x + 1} {
3217 lappend coords [xc $row [expr {$x+1}]] [yc $row]
3221 lappend coords [xc $row $x] [yc $row]
3223 set xn [xc $row $xp]
3225 # work around tk8.4 refusal to draw arrows on diagonal segments
3226 if {$arrowlow && $xn != [lindex $coords end-1]} {
3227 if {[llength $coords] < 4 ||
3228 [lindex $coords end-3] != [lindex $coords end-1] ||
3229 [lindex $coords end] - $yn > 2 * $linespc} {
3230 set xn [xc $row [expr {$xp - 0.5 * $dir}]]
3231 set yo [yc [expr {$row + 0.5}]]
3232 lappend coords $xn $yo $xn $yn
3235 lappend coords $xn $yn
3240 set coords [adjarrowhigh $coords]
3243 set t [$canv create line $coords -width [linewidth $id] \
3244 -fill $colormap($id) -tags lines.$id -arrow $arrow]
3247 set lines [linsert $lines $i [list $row $le $t]]
3249 $canv coords $ith $coords
3250 if {$arrow ne $ah} {
3251 $canv itemconf $ith -arrow $arrow
3253 lset lines $i 0 $row
3256 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
3257 set ndir [expr {$xo - $xp}]
3258 set clow [$canv coords $itl]
3259 if {$dir == $ndir} {
3260 set clow [lrange $clow 2 end]
3262 set coords [concat $coords $clow]
3264 lset lines [expr {$i-1}] 1 $le
3266 set coords [adjarrowhigh $coords]
3269 # coalesce two pieces
3271 set b [lindex $lines [expr {$i-1}] 0]
3272 set e [lindex $lines $i 1]
3273 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
3275 $canv coords $itl $coords
3276 if {$arrow ne $al} {
3277 $canv itemconf $itl -arrow $arrow
3281 set linesegs($id) $lines
3285 proc drawparentlinks {id row} {
3286 global rowidlist canv colormap curview parentlist
3289 set rowids [lindex $rowidlist $row]
3290 set col [lsearch -exact $rowids $id]
3291 if {$col < 0} return
3292 set olds [lindex $parentlist $row]
3293 set row2 [expr {$row + 1}]
3294 set x [xc $row $col]
3297 set ids [lindex $rowidlist $row2]
3298 # rmx = right-most X coord used
3301 set i [lsearch -exact $ids $p]
3303 puts "oops, parent $p of $id not in list"
3306 set x2 [xc $row2 $i]
3310 if {[lsearch -exact $rowids $p] < 0} {
3311 # drawlineseg will do this one for us
3315 # should handle duplicated parents here...
3316 set coords [list $x $y]
3317 if {$i < $col - 1} {
3318 lappend coords [xc $row [expr {$i + 1}]] $y
3319 } elseif {$i > $col + 1} {
3320 lappend coords [xc $row [expr {$i - 1}]] $y
3322 lappend coords $x2 $y2
3323 set t [$canv create line $coords -width [linewidth $p] \
3324 -fill $colormap($p) -tags lines.$p]
3328 if {$rmx > [lindex $idpos($id) 1]} {
3329 lset idpos($id) 1 $rmx
3334 proc drawlines {id} {
3337 $canv itemconf lines.$id -width [linewidth $id]
3340 proc drawcmittext {id row col} {
3341 global linespc canv canv2 canv3 canvy0 fgcolor curview
3342 global commitlisted commitinfo rowidlist parentlist
3343 global rowtextx idpos idtags idheads idotherrefs
3344 global linehtag linentag linedtag markingmatches
3345 global mainfont canvxmax boldrows boldnamerows fgcolor nullid
3347 # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
3348 set listed [lindex $commitlisted $row]
3349 if {$id eq $nullid} {
3352 set ofill [expr {$listed != 0? "blue": "white"}]
3354 set x [xc $row $col]
3356 set orad [expr {$linespc / 3}]
3358 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
3359 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3360 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3361 } elseif {$listed == 2} {
3362 # triangle pointing left for left-side commits
3363 set t [$canv create polygon \
3364 [expr {$x - $orad}] $y \
3365 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
3366 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3367 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3369 # triangle pointing right for right-side commits
3370 set t [$canv create polygon \
3371 [expr {$x + $orad - 1}] $y \
3372 [expr {$x - $orad}] [expr {$y - $orad}] \
3373 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
3374 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3377 $canv bind $t <1> {selcanvline {} %x %y}
3378 set rmx [llength [lindex $rowidlist $row]]
3379 set olds [lindex $parentlist $row]
3381 set nextids [lindex $rowidlist [expr {$row + 1}]]
3383 set i [lsearch -exact $nextids $p]
3389 set xt [xc $row $rmx]
3390 set rowtextx($row) $xt
3391 set idpos($id) [list $x $xt $y]
3392 if {[info exists idtags($id)] || [info exists idheads($id)]
3393 || [info exists idotherrefs($id)]} {
3394 set xt [drawtags $id $x $xt $y]
3396 set headline [lindex $commitinfo($id) 0]
3397 set name [lindex $commitinfo($id) 1]
3398 set date [lindex $commitinfo($id) 2]
3399 set date [formatdate $date]
3402 set isbold [ishighlighted $row]
3404 lappend boldrows $row
3407 lappend boldnamerows $row
3411 set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
3412 -text $headline -font $font -tags text]
3413 $canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
3414 set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
3415 -text $name -font $nfont -tags text]
3416 set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
3417 -text $date -font $mainfont -tags text]
3418 set xr [expr {$xt + [font measure $mainfont $headline]}]
3419 if {$markingmatches} {
3420 markrowmatches $row $headline $name
3422 if {$xr > $canvxmax} {
3428 proc drawcmitrow {row} {
3429 global displayorder rowidlist
3431 global commitinfo parentlist numcommits
3432 global filehighlight fhighlights findstring nhighlights
3433 global hlview vhighlights
3434 global highlight_related rhighlights
3436 if {$row >= $numcommits} return
3438 set id [lindex $displayorder $row]
3439 if {[info exists hlview] && ![info exists vhighlights($row)]} {
3440 askvhighlight $row $id
3442 if {[info exists filehighlight] && ![info exists fhighlights($row)]} {
3443 askfilehighlight $row $id
3445 if {$findstring ne {} && ![info exists nhighlights($row)]} {
3446 askfindhighlight $row $id
3448 if {$highlight_related ne "None" && ![info exists rhighlights($row)]} {
3449 askrelhighlight $row $id
3451 if {[info exists iddrawn($id)]} return
3452 set col [lsearch -exact [lindex $rowidlist $row] $id]
3454 puts "oops, row $row id $id not in list"
3457 if {![info exists commitinfo($id)]} {
3461 drawcmittext $id $row $col
3465 proc drawcommits {row {endrow {}}} {
3466 global numcommits iddrawn displayorder curview
3467 global parentlist rowidlist
3472 if {$endrow eq {}} {
3475 if {$endrow >= $numcommits} {
3476 set endrow [expr {$numcommits - 1}]
3479 # make the lines join to already-drawn rows either side
3480 set r [expr {$row - 1}]
3481 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
3484 set er [expr {$endrow + 1}]
3485 if {$er >= $numcommits ||
3486 ![info exists iddrawn([lindex $displayorder $er])]} {
3489 for {} {$r <= $er} {incr r} {
3490 set id [lindex $displayorder $r]
3491 set wasdrawn [info exists iddrawn($id)]
3493 if {$r == $er} break
3494 set nextid [lindex $displayorder [expr {$r + 1}]]
3495 if {$wasdrawn && [info exists iddrawn($nextid)]} {
3496 catch {unset prevlines}
3499 drawparentlinks $id $r
3501 if {[info exists lineends($r)]} {
3502 foreach lid $lineends($r) {
3503 unset prevlines($lid)
3506 set rowids [lindex $rowidlist $r]
3507 foreach lid $rowids {
3508 if {$lid eq {}} continue
3510 # see if this is the first child of any of its parents
3511 foreach p [lindex $parentlist $r] {
3512 if {[lsearch -exact $rowids $p] < 0} {
3513 # make this line extend up to the child
3514 set le [drawlineseg $p $r $er 0]
3515 lappend lineends($le) $p
3519 } elseif {![info exists prevlines($lid)]} {
3520 set le [drawlineseg $lid $r $er 1]
3521 lappend lineends($le) $lid
3522 set prevlines($lid) 1
3528 proc drawfrac {f0 f1} {
3531 set ymax [lindex [$canv cget -scrollregion] 3]
3532 if {$ymax eq {} || $ymax == 0} return
3533 set y0 [expr {int($f0 * $ymax)}]
3534 set row [expr {int(($y0 - 3) / $linespc) - 1}]
3535 set y1 [expr {int($f1 * $ymax)}]
3536 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
3537 drawcommits $row $endrow
3540 proc drawvisible {} {
3542 eval drawfrac [$canv yview]
3545 proc clear_display {} {
3546 global iddrawn linesegs
3547 global vhighlights fhighlights nhighlights rhighlights
3550 catch {unset iddrawn}
3551 catch {unset linesegs}
3552 catch {unset vhighlights}
3553 catch {unset fhighlights}
3554 catch {unset nhighlights}
3555 catch {unset rhighlights}
3558 proc findcrossings {id} {
3559 global rowidlist parentlist numcommits rowoffsets displayorder
3563 foreach {s e} [rowranges $id] {
3564 if {$e >= $numcommits} {
3565 set e [expr {$numcommits - 1}]
3567 if {$e <= $s} continue
3568 set x [lsearch -exact [lindex $rowidlist $e] $id]
3570 puts "findcrossings: oops, no [shortids $id] in row $e"
3573 for {set row $e} {[incr row -1] >= $s} {} {
3574 set olds [lindex $parentlist $row]
3575 set kid [lindex $displayorder $row]
3576 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
3577 if {$kidx < 0} continue
3578 set nextrow [lindex $rowidlist [expr {$row + 1}]]
3580 set px [lsearch -exact $nextrow $p]
3581 if {$px < 0} continue
3582 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
3583 if {[lsearch -exact $ccross $p] >= 0} continue
3584 if {$x == $px + ($kidx < $px? -1: 1)} {
3586 } elseif {[lsearch -exact $cross $p] < 0} {
3591 set inc [lindex $rowoffsets $row $x]
3592 if {$inc eq {}} break
3596 return [concat $ccross {{}} $cross]
3599 proc assigncolor {id} {
3600 global colormap colors nextcolor
3601 global commitrow parentlist children children curview
3603 if {[info exists colormap($id)]} return
3604 set ncolors [llength $colors]
3605 if {[info exists children($curview,$id)]} {
3606 set kids $children($curview,$id)
3610 if {[llength $kids] == 1} {
3611 set child [lindex $kids 0]
3612 if {[info exists colormap($child)]
3613 && [llength [lindex $parentlist $commitrow($curview,$child)]] == 1} {
3614 set colormap($id) $colormap($child)
3620 foreach x [findcrossings $id] {
3622 # delimiter between corner crossings and other crossings
3623 if {[llength $badcolors] >= $ncolors - 1} break
3624 set origbad $badcolors
3626 if {[info exists colormap($x)]
3627 && [lsearch -exact $badcolors $colormap($x)] < 0} {
3628 lappend badcolors $colormap($x)
3631 if {[llength $badcolors] >= $ncolors} {
3632 set badcolors $origbad
3634 set origbad $badcolors
3635 if {[llength $badcolors] < $ncolors - 1} {
3636 foreach child $kids {
3637 if {[info exists colormap($child)]
3638 && [lsearch -exact $badcolors $colormap($child)] < 0} {
3639 lappend badcolors $colormap($child)
3641 foreach p [lindex $parentlist $commitrow($curview,$child)] {
3642 if {[info exists colormap($p)]
3643 && [lsearch -exact $badcolors $colormap($p)] < 0} {
3644 lappend badcolors $colormap($p)
3648 if {[llength $badcolors] >= $ncolors} {
3649 set badcolors $origbad
3652 for {set i 0} {$i <= $ncolors} {incr i} {
3653 set c [lindex $colors $nextcolor]
3654 if {[incr nextcolor] >= $ncolors} {
3657 if {[lsearch -exact $badcolors $c]} break
3659 set colormap($id) $c
3662 proc bindline {t id} {
3665 $canv bind $t <Enter> "lineenter %x %y $id"
3666 $canv bind $t <Motion> "linemotion %x %y $id"
3667 $canv bind $t <Leave> "lineleave $id"
3668 $canv bind $t <Button-1> "lineclick %x %y $id 1"
3671 proc drawtags {id x xt y1} {
3672 global idtags idheads idotherrefs mainhead
3673 global linespc lthickness
3674 global canv mainfont commitrow rowtextx curview fgcolor bgcolor
3679 if {[info exists idtags($id)]} {
3680 set marks $idtags($id)
3681 set ntags [llength $marks]
3683 if {[info exists idheads($id)]} {
3684 set marks [concat $marks $idheads($id)]
3685 set nheads [llength $idheads($id)]
3687 if {[info exists idotherrefs($id)]} {
3688 set marks [concat $marks $idotherrefs($id)]
3694 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
3695 set yt [expr {$y1 - 0.5 * $linespc}]
3696 set yb [expr {$yt + $linespc - 1}]
3700 foreach tag $marks {
3702 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
3703 set wid [font measure [concat $mainfont bold] $tag]
3705 set wid [font measure $mainfont $tag]
3709 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
3711 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
3712 -width $lthickness -fill black -tags tag.$id]
3714 foreach tag $marks x $xvals wid $wvals {
3715 set xl [expr {$x + $delta}]
3716 set xr [expr {$x + $delta + $wid + $lthickness}]
3718 if {[incr ntags -1] >= 0} {
3720 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
3721 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
3722 -width 1 -outline black -fill yellow -tags tag.$id]
3723 $canv bind $t <1> [list showtag $tag 1]
3724 set rowtextx($commitrow($curview,$id)) [expr {$xr + $linespc}]
3726 # draw a head or other ref
3727 if {[incr nheads -1] >= 0} {
3729 if {$tag eq $mainhead} {
3735 set xl [expr {$xl - $delta/2}]
3736 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
3737 -width 1 -outline black -fill $col -tags tag.$id
3738 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
3739 set rwid [font measure $mainfont $remoteprefix]
3740 set xi [expr {$x + 1}]
3741 set yti [expr {$yt + 1}]
3742 set xri [expr {$x + $rwid}]
3743 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
3744 -width 0 -fill "#ffddaa" -tags tag.$id
3747 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
3748 -font $font -tags [list tag.$id text]]
3750 $canv bind $t <1> [list showtag $tag 1]
3751 } elseif {$nheads >= 0} {
3752 $canv bind $t <Button-3> [list headmenu %X %Y $id $tag]
3758 proc xcoord {i level ln} {
3759 global canvx0 xspc1 xspc2
3761 set x [expr {$canvx0 + $i * $xspc1($ln)}]
3762 if {$i > 0 && $i == $level} {
3763 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
3764 } elseif {$i > $level} {
3765 set x [expr {$x + $xspc2 - $xspc1($ln)}]
3770 proc show_status {msg} {
3771 global canv mainfont fgcolor
3774 $canv create text 3 3 -anchor nw -text $msg -font $mainfont \
3775 -tags text -fill $fgcolor
3778 # Insert a new commit as the child of the commit on row $row.
3779 # The new commit will be displayed on row $row and the commits
3780 # on that row and below will move down one row.
3781 proc insertrow {row newcmit} {
3782 global displayorder parentlist commitlisted children
3783 global commitrow curview rowidlist rowoffsets numcommits
3784 global rowrangelist rowlaidout rowoptim numcommits
3785 global selectedline rowchk commitidx
3787 if {$row >= $numcommits} {
3788 puts "oops, inserting new row $row but only have $numcommits rows"
3791 set p [lindex $displayorder $row]
3792 set displayorder [linsert $displayorder $row $newcmit]
3793 set parentlist [linsert $parentlist $row $p]
3794 set kids $children($curview,$p)
3795 lappend kids $newcmit
3796 set children($curview,$p) $kids
3797 set children($curview,$newcmit) {}
3798 set commitlisted [linsert $commitlisted $row 1]
3799 set l [llength $displayorder]
3800 for {set r $row} {$r < $l} {incr r} {
3801 set id [lindex $displayorder $r]
3802 set commitrow($curview,$id) $r
3804 incr commitidx($curview)
3806 set idlist [lindex $rowidlist $row]
3807 set offs [lindex $rowoffsets $row]
3810 if {$x eq {} || ($x eq $p && [llength $kids] == 1)} {
3816 if {[llength $kids] == 1} {
3817 set col [lsearch -exact $idlist $p]
3818 lset idlist $col $newcmit
3820 set col [llength $idlist]
3821 lappend idlist $newcmit
3823 lset rowoffsets $row $offs
3825 set rowidlist [linsert $rowidlist $row $idlist]
3826 set rowoffsets [linsert $rowoffsets [expr {$row+1}] $newoffs]
3828 set rowrangelist [linsert $rowrangelist $row {}]
3829 if {[llength $kids] > 1} {
3830 set rp1 [expr {$row + 1}]
3831 set ranges [lindex $rowrangelist $rp1]
3832 if {$ranges eq {}} {
3833 set ranges [list $newcmit $p]
3834 } elseif {[lindex $ranges end-1] eq $p} {
3835 lset ranges end-1 $newcmit
3837 lset rowrangelist $rp1 $ranges
3840 catch {unset rowchk}
3846 if {[info exists selectedline] && $selectedline >= $row} {
3852 # Remove a commit that was inserted with insertrow on row $row.
3853 proc removerow {row} {
3854 global displayorder parentlist commitlisted children
3855 global commitrow curview rowidlist rowoffsets numcommits
3856 global rowrangelist idrowranges rowlaidout rowoptim numcommits
3857 global linesegends selectedline rowchk commitidx
3859 if {$row >= $numcommits} {
3860 puts "oops, removing row $row but only have $numcommits rows"
3863 set rp1 [expr {$row + 1}]
3864 set id [lindex $displayorder $row]
3865 set p [lindex $parentlist $row]
3866 set displayorder [lreplace $displayorder $row $row]
3867 set parentlist [lreplace $parentlist $row $row]
3868 set commitlisted [lreplace $commitlisted $row $row]
3869 set kids $children($curview,$p)
3870 set i [lsearch -exact $kids $id]
3872 set kids [lreplace $kids $i $i]
3873 set children($curview,$p) $kids
3875 set l [llength $displayorder]
3876 for {set r $row} {$r < $l} {incr r} {
3877 set id [lindex $displayorder $r]
3878 set commitrow($curview,$id) $r
3880 incr commitidx($curview) -1
3882 set rowidlist [lreplace $rowidlist $row $row]
3883 set rowoffsets [lreplace $rowoffsets $rp1 $rp1]
3885 set offs [lindex $rowoffsets $row]
3886 set offs [lreplace $offs end end]
3887 lset rowoffsets $row $offs
3890 set rowrangelist [lreplace $rowrangelist $row $row]
3891 if {[llength $kids] > 0} {
3892 set ranges [lindex $rowrangelist $row]
3893 if {[lindex $ranges end-1] eq $id} {
3894 set ranges [lreplace $ranges end-1 end]
3895 lset rowrangelist $row $ranges
3899 catch {unset rowchk}
3905 if {[info exists selectedline] && $selectedline > $row} {
3906 incr selectedline -1
3911 # Don't change the text pane cursor if it is currently the hand cursor,
3912 # showing that we are over a sha1 ID link.
3913 proc settextcursor {c} {
3914 global ctext curtextcursor
3916 if {[$ctext cget -cursor] == $curtextcursor} {
3917 $ctext config -cursor $c
3919 set curtextcursor $c
3922 proc nowbusy {what} {
3925 if {[array names isbusy] eq {}} {
3926 . config -cursor watch
3932 proc notbusy {what} {
3933 global isbusy maincursor textcursor
3935 catch {unset isbusy($what)}
3936 if {[array names isbusy] eq {}} {
3937 . config -cursor $maincursor
3938 settextcursor $textcursor
3942 proc findmatches {f} {
3943 global findtype findstring
3944 if {$findtype == "Regexp"} {
3945 set matches [regexp -indices -all -inline $findstring $f]
3948 if {$findtype == "IgnCase"} {
3949 set f [string tolower $f]
3950 set fs [string tolower $fs]
3954 set l [string length $fs]
3955 while {[set j [string first $fs $f $i]] >= 0} {
3956 lappend matches [list $j [expr {$j+$l-1}]]
3957 set i [expr {$j + $l}]
3963 proc dofind {{rev 0}} {
3964 global findstring findstartline findcurline selectedline numcommits
3967 cancel_next_highlight
3969 if {$findstring eq {} || $numcommits == 0} return
3970 if {![info exists selectedline]} {
3971 set findstartline [lindex [visiblerows] $rev]
3973 set findstartline $selectedline
3975 set findcurline $findstartline
3980 set findcurline $findstartline
3981 if {$findcurline == 0} {
3982 set findcurline $numcommits
3989 proc findnext {restart} {
3991 if {![info exists findcurline]} {
4005 if {![info exists findcurline]} {
4014 global commitdata commitinfo numcommits findstring findpattern findloc
4015 global findstartline findcurline markingmatches displayorder
4017 set fldtypes {Headline Author Date Committer CDate Comments}
4018 set l [expr {$findcurline + 1}]
4019 if {$l >= $numcommits} {
4022 if {$l <= $findstartline} {
4023 set lim [expr {$findstartline + 1}]
4027 if {$lim - $l > 500} {
4028 set lim [expr {$l + 500}]
4031 for {} {$l < $lim} {incr l} {
4032 set id [lindex $displayorder $l]
4033 if {![doesmatch $commitdata($id)]} continue
4034 if {![info exists commitinfo($id)]} {
4037 set info $commitinfo($id)
4038 foreach f $info ty $fldtypes {
4039 if {($findloc eq "All fields" || $findloc eq $ty) &&
4041 set markingmatches 1
4048 if {$l == $findstartline + 1} {
4054 set findcurline [expr {$l - 1}]
4058 proc findmorerev {} {
4059 global commitdata commitinfo numcommits findstring findpattern findloc
4060 global findstartline findcurline markingmatches displayorder
4062 set fldtypes {Headline Author Date Committer CDate Comments}
4068 if {$l >= $findstartline} {
4069 set lim [expr {$findstartline - 1}]
4073 if {$l - $lim > 500} {
4074 set lim [expr {$l - 500}]
4077 for {} {$l > $lim} {incr l -1} {
4078 set id [lindex $displayorder $l]
4079 if {![doesmatch $commitdata($id)]} continue
4080 if {![info exists commitinfo($id)]} {
4083 set info $commitinfo($id)
4084 foreach f $info ty $fldtypes {
4085 if {($findloc eq "All fields" || $findloc eq $ty) &&
4087 set markingmatches 1
4100 set findcurline [expr {$l + 1}]
4104 proc findselectline {l} {
4105 global findloc commentend ctext
4107 if {$findloc == "All fields" || $findloc == "Comments"} {
4108 # highlight the matches in the comments
4109 set f [$ctext get 1.0 $commentend]
4110 set matches [findmatches $f]
4111 foreach match $matches {
4112 set start [lindex $match 0]
4113 set end [expr {[lindex $match 1] + 1}]
4114 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
4119 # mark the bits of a headline or author that match a find string
4120 proc markmatches {canv l str tag matches font} {
4121 set bbox [$canv bbox $tag]
4122 set x0 [lindex $bbox 0]
4123 set y0 [lindex $bbox 1]
4124 set y1 [lindex $bbox 3]
4125 foreach match $matches {
4126 set start [lindex $match 0]
4127 set end [lindex $match 1]
4128 if {$start > $end} continue
4129 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
4130 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
4131 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
4132 [expr {$x0+$xlen+2}] $y1 \
4133 -outline {} -tags [list match$l matches] -fill yellow]
4138 proc unmarkmatches {} {
4139 global findids markingmatches findcurline
4141 allcanvs delete matches
4142 catch {unset findids}
4143 set markingmatches 0
4144 catch {unset findcurline}
4147 proc selcanvline {w x y} {
4148 global canv canvy0 ctext linespc
4150 set ymax [lindex [$canv cget -scrollregion] 3]
4151 if {$ymax == {}} return
4152 set yfrac [lindex [$canv yview] 0]
4153 set y [expr {$y + $yfrac * $ymax}]
4154 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
4159 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
4165 proc commit_descriptor {p} {
4167 if {![info exists commitinfo($p)]} {
4171 if {[llength $commitinfo($p)] > 1} {
4172 set l [lindex $commitinfo($p) 0]
4177 # append some text to the ctext widget, and make any SHA1 ID
4178 # that we know about be a clickable link.
4179 proc appendwithlinks {text tags} {
4180 global ctext commitrow linknum curview
4182 set start [$ctext index "end - 1c"]
4183 $ctext insert end $text $tags
4184 set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
4188 set linkid [string range $text $s $e]
4189 if {![info exists commitrow($curview,$linkid)]} continue
4191 $ctext tag add link "$start + $s c" "$start + $e c"
4192 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
4193 $ctext tag bind link$linknum <1> \
4194 [list selectline $commitrow($curview,$linkid) 1]
4197 $ctext tag conf link -foreground blue -underline 1
4198 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
4199 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
4202 proc viewnextline {dir} {
4206 set ymax [lindex [$canv cget -scrollregion] 3]
4207 set wnow [$canv yview]
4208 set wtop [expr {[lindex $wnow 0] * $ymax}]
4209 set newtop [expr {$wtop + $dir * $linespc}]
4212 } elseif {$newtop > $ymax} {
4215 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
4218 # add a list of tag or branch names at position pos
4219 # returns the number of names inserted
4220 proc appendrefs {pos ids var} {
4221 global ctext commitrow linknum curview $var maxrefs
4223 if {[catch {$ctext index $pos}]} {
4226 $ctext conf -state normal
4227 $ctext delete $pos "$pos lineend"
4230 foreach tag [set $var\($id\)] {
4231 lappend tags [list $tag $id]
4234 if {[llength $tags] > $maxrefs} {
4235 $ctext insert $pos "many ([llength $tags])"
4237 set tags [lsort -index 0 -decreasing $tags]
4240 set id [lindex $ti 1]
4243 $ctext tag delete $lk
4244 $ctext insert $pos $sep
4245 $ctext insert $pos [lindex $ti 0] $lk
4246 if {[info exists commitrow($curview,$id)]} {
4247 $ctext tag conf $lk -foreground blue
4248 $ctext tag bind $lk <1> \
4249 [list selectline $commitrow($curview,$id) 1]
4250 $ctext tag conf $lk -underline 1
4251 $ctext tag bind $lk <Enter> { %W configure -cursor hand2 }
4252 $ctext tag bind $lk <Leave> \
4253 { %W configure -cursor $curtextcursor }
4258 $ctext conf -state disabled
4259 return [llength $tags]
4262 # called when we have finished computing the nearby tags
4263 proc dispneartags {delay} {
4264 global selectedline currentid showneartags tagphase
4266 if {![info exists selectedline] || !$showneartags} return
4267 after cancel dispnexttag
4269 after 200 dispnexttag
4272 after idle dispnexttag
4277 proc dispnexttag {} {
4278 global selectedline currentid showneartags tagphase ctext
4280 if {![info exists selectedline] || !$showneartags} return
4281 switch -- $tagphase {
4283 set dtags [desctags $currentid]
4285 appendrefs precedes $dtags idtags
4289 set atags [anctags $currentid]
4291 appendrefs follows $atags idtags
4295 set dheads [descheads $currentid]
4296 if {$dheads ne {}} {
4297 if {[appendrefs branch $dheads idheads] > 1
4298 && [$ctext get "branch -3c"] eq "h"} {
4299 # turn "Branch" into "Branches"
4300 $ctext conf -state normal
4301 $ctext insert "branch -2c" "es"
4302 $ctext conf -state disabled
4307 if {[incr tagphase] <= 2} {
4308 after idle dispnexttag
4312 proc selectline {l isnew} {
4313 global canv canv2 canv3 ctext commitinfo selectedline
4314 global displayorder linehtag linentag linedtag
4315 global canvy0 linespc parentlist children curview
4316 global currentid sha1entry
4317 global commentend idtags linknum
4318 global mergemax numcommits pending_select
4319 global cmitmode showneartags allcommits
4321 catch {unset pending_select}
4324 cancel_next_highlight
4325 if {$l < 0 || $l >= $numcommits} return
4326 set y [expr {$canvy0 + $l * $linespc}]
4327 set ymax [lindex [$canv cget -scrollregion] 3]
4328 set ytop [expr {$y - $linespc - 1}]
4329 set ybot [expr {$y + $linespc + 1}]
4330 set wnow [$canv yview]
4331 set wtop [expr {[lindex $wnow 0] * $ymax}]
4332 set wbot [expr {[lindex $wnow 1] * $ymax}]
4333 set wh [expr {$wbot - $wtop}]
4335 if {$ytop < $wtop} {
4336 if {$ybot < $wtop} {
4337 set newtop [expr {$y - $wh / 2.0}]
4340 if {$newtop > $wtop - $linespc} {
4341 set newtop [expr {$wtop - $linespc}]
4344 } elseif {$ybot > $wbot} {
4345 if {$ytop > $wbot} {
4346 set newtop [expr {$y - $wh / 2.0}]
4348 set newtop [expr {$ybot - $wh}]
4349 if {$newtop < $wtop + $linespc} {
4350 set newtop [expr {$wtop + $linespc}]
4354 if {$newtop != $wtop} {
4358 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
4362 if {![info exists linehtag($l)]} return
4364 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
4365 -tags secsel -fill [$canv cget -selectbackground]]
4367 $canv2 delete secsel
4368 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
4369 -tags secsel -fill [$canv2 cget -selectbackground]]
4371 $canv3 delete secsel
4372 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
4373 -tags secsel -fill [$canv3 cget -selectbackground]]
4377 addtohistory [list selectline $l 0]
4382 set id [lindex $displayorder $l]
4384 $sha1entry delete 0 end
4385 $sha1entry insert 0 $id
4386 $sha1entry selection from 0
4387 $sha1entry selection to end
4390 $ctext conf -state normal
4393 set info $commitinfo($id)
4394 set date [formatdate [lindex $info 2]]
4395 $ctext insert end "Author: [lindex $info 1] $date\n"
4396 set date [formatdate [lindex $info 4]]
4397 $ctext insert end "Committer: [lindex $info 3] $date\n"
4398 if {[info exists idtags($id)]} {
4399 $ctext insert end "Tags:"
4400 foreach tag $idtags($id) {
4401 $ctext insert end " $tag"
4403 $ctext insert end "\n"
4407 set olds [lindex $parentlist $l]
4408 if {[llength $olds] > 1} {
4411 if {$np >= $mergemax} {
4416 $ctext insert end "Parent: " $tag
4417 appendwithlinks [commit_descriptor $p] {}
4422 append headers "Parent: [commit_descriptor $p]"
4426 foreach c $children($curview,$id) {
4427 append headers "Child: [commit_descriptor $c]"
4430 # make anything that looks like a SHA1 ID be a clickable link
4431 appendwithlinks $headers {}
4432 if {$showneartags} {
4433 if {![info exists allcommits]} {
4436 $ctext insert end "Branch: "
4437 $ctext mark set branch "end -1c"
4438 $ctext mark gravity branch left
4439 $ctext insert end "\nFollows: "
4440 $ctext mark set follows "end -1c"
4441 $ctext mark gravity follows left
4442 $ctext insert end "\nPrecedes: "
4443 $ctext mark set precedes "end -1c"
4444 $ctext mark gravity precedes left
4445 $ctext insert end "\n"
4448 $ctext insert end "\n"
4449 set comment [lindex $info 5]
4450 if {[string first "\r" $comment] >= 0} {
4451 set comment [string map {"\r" "\n "} $comment]
4453 appendwithlinks $comment {comment}
4455 $ctext tag remove found 1.0 end
4456 $ctext conf -state disabled
4457 set commentend [$ctext index "end - 1c"]
4459 init_flist "Comments"
4460 if {$cmitmode eq "tree"} {
4462 } elseif {[llength $olds] <= 1} {
4469 proc selfirstline {} {
4474 proc sellastline {} {
4477 set l [expr {$numcommits - 1}]
4481 proc selnextline {dir} {
4483 if {![info exists selectedline]} return
4484 set l [expr {$selectedline + $dir}]
4489 proc selnextpage {dir} {
4490 global canv linespc selectedline numcommits
4492 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
4496 allcanvs yview scroll [expr {$dir * $lpp}] units
4498 if {![info exists selectedline]} return
4499 set l [expr {$selectedline + $dir * $lpp}]
4502 } elseif {$l >= $numcommits} {
4503 set l [expr $numcommits - 1]
4509 proc unselectline {} {
4510 global selectedline currentid
4512 catch {unset selectedline}
4513 catch {unset currentid}
4514 allcanvs delete secsel
4516 cancel_next_highlight
4519 proc reselectline {} {
4522 if {[info exists selectedline]} {
4523 selectline $selectedline 0
4527 proc addtohistory {cmd} {
4528 global history historyindex curview
4530 set elt [list $curview $cmd]
4531 if {$historyindex > 0
4532 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
4536 if {$historyindex < [llength $history]} {
4537 set history [lreplace $history $historyindex end $elt]
4539 lappend history $elt
4542 if {$historyindex > 1} {
4543 .tf.bar.leftbut conf -state normal
4545 .tf.bar.leftbut conf -state disabled
4547 .tf.bar.rightbut conf -state disabled
4553 set view [lindex $elt 0]
4554 set cmd [lindex $elt 1]
4555 if {$curview != $view} {
4562 global history historyindex
4564 if {$historyindex > 1} {
4565 incr historyindex -1
4566 godo [lindex $history [expr {$historyindex - 1}]]
4567 .tf.bar.rightbut conf -state normal
4569 if {$historyindex <= 1} {
4570 .tf.bar.leftbut conf -state disabled
4575 global history historyindex
4577 if {$historyindex < [llength $history]} {
4578 set cmd [lindex $history $historyindex]
4581 .tf.bar.leftbut conf -state normal
4583 if {$historyindex >= [llength $history]} {
4584 .tf.bar.rightbut conf -state disabled
4589 global treefilelist treeidlist diffids diffmergeid treepending nullid
4592 catch {unset diffmergeid}
4593 if {![info exists treefilelist($id)]} {
4594 if {![info exists treepending]} {
4595 if {$id ne $nullid} {
4596 set cmd [concat | git ls-tree -r $id]
4598 set cmd [concat | git ls-files]
4600 if {[catch {set gtf [open $cmd r]}]} {
4604 set treefilelist($id) {}
4605 set treeidlist($id) {}
4606 fconfigure $gtf -blocking 0
4607 filerun $gtf [list gettreeline $gtf $id]
4614 proc gettreeline {gtf id} {
4615 global treefilelist treeidlist treepending cmitmode diffids nullid
4618 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
4619 if {$diffids ne $nullid} {
4620 if {[lindex $line 1] ne "blob"} continue
4621 set i [string first "\t" $line]
4622 if {$i < 0} continue
4623 set sha1 [lindex $line 2]
4624 set fname [string range $line [expr {$i+1}] end]
4625 if {[string index $fname 0] eq "\""} {
4626 set fname [lindex $fname 0]
4628 lappend treeidlist($id) $sha1
4632 lappend treefilelist($id) $fname
4635 return [expr {$nl >= 1000? 2: 1}]
4639 if {$cmitmode ne "tree"} {
4640 if {![info exists diffmergeid]} {
4641 gettreediffs $diffids
4643 } elseif {$id ne $diffids} {
4652 global treefilelist treeidlist diffids nullid
4653 global ctext commentend
4655 set i [lsearch -exact $treefilelist($diffids) $f]
4657 puts "oops, $f not in list for id $diffids"
4660 if {$diffids ne $nullid} {
4661 set blob [lindex $treeidlist($diffids) $i]
4662 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
4663 puts "oops, error reading blob $blob: $err"
4667 if {[catch {set bf [open $f r]} err]} {
4668 puts "oops, can't read $f: $err"
4672 fconfigure $bf -blocking 0
4673 filerun $bf [list getblobline $bf $diffids]
4674 $ctext config -state normal
4675 clear_ctext $commentend
4676 $ctext insert end "\n"
4677 $ctext insert end "$f\n" filesep
4678 $ctext config -state disabled
4679 $ctext yview $commentend
4682 proc getblobline {bf id} {
4683 global diffids cmitmode ctext
4685 if {$id ne $diffids || $cmitmode ne "tree"} {
4689 $ctext config -state normal
4691 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
4692 $ctext insert end "$line\n"
4695 # delete last newline
4696 $ctext delete "end - 2c" "end - 1c"
4700 $ctext config -state disabled
4701 return [expr {$nl >= 1000? 2: 1}]
4704 proc mergediff {id l} {
4705 global diffmergeid diffopts mdifffd
4711 # this doesn't seem to actually affect anything...
4712 set env(GIT_DIFF_OPTS) $diffopts
4713 set cmd [concat | git diff-tree --no-commit-id --cc $id]
4714 if {[catch {set mdf [open $cmd r]} err]} {
4715 error_popup "Error getting merge diffs: $err"
4718 fconfigure $mdf -blocking 0
4719 set mdifffd($id) $mdf
4720 set np [llength [lindex $parentlist $l]]
4721 filerun $mdf [list getmergediffline $mdf $id $np]
4724 proc getmergediffline {mdf id np} {
4725 global diffmergeid ctext cflist mergemax
4726 global difffilestart mdifffd
4728 $ctext conf -state normal
4730 while {[incr nr] <= 1000 && [gets $mdf line] >= 0} {
4731 if {![info exists diffmergeid] || $id != $diffmergeid
4732 || $mdf != $mdifffd($id)} {
4736 if {[regexp {^diff --cc (.*)} $line match fname]} {
4737 # start of a new file
4738 $ctext insert end "\n"
4739 set here [$ctext index "end - 1c"]
4740 lappend difffilestart $here
4741 add_flist [list $fname]
4742 set l [expr {(78 - [string length $fname]) / 2}]
4743 set pad [string range "----------------------------------------" 1 $l]
4744 $ctext insert end "$pad $fname $pad\n" filesep
4745 } elseif {[regexp {^@@} $line]} {
4746 $ctext insert end "$line\n" hunksep
4747 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
4750 # parse the prefix - one ' ', '-' or '+' for each parent
4755 for {set j 0} {$j < $np} {incr j} {
4756 set c [string range $line $j $j]
4759 } elseif {$c == "-"} {
4761 } elseif {$c == "+"} {
4770 if {!$isbad && $minuses ne {} && $pluses eq {}} {
4771 # line doesn't appear in result, parents in $minuses have the line
4772 set num [lindex $minuses 0]
4773 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
4774 # line appears in result, parents in $pluses don't have the line
4775 lappend tags mresult
4776 set num [lindex $spaces 0]
4779 if {$num >= $mergemax} {
4784 $ctext insert end "$line\n" $tags
4787 $ctext conf -state disabled
4792 return [expr {$nr >= 1000? 2: 1}]
4795 proc startdiff {ids} {
4796 global treediffs diffids treepending diffmergeid nullid
4799 catch {unset diffmergeid}
4800 if {![info exists treediffs($ids)] || [lsearch -exact $ids $nullid] >= 0} {
4801 if {![info exists treepending]} {
4809 proc addtocflist {ids} {
4810 global treediffs cflist
4811 add_flist $treediffs($ids)
4815 proc diffcmd {ids flags} {
4818 set i [lsearch -exact $ids $nullid]
4820 set cmd [concat | git diff-index $flags]
4821 if {[llength $ids] > 1} {
4823 lappend cmd -R [lindex $ids 1]
4825 lappend cmd [lindex $ids 0]
4831 set cmd [concat | git diff-tree --no-commit-id -r $flags $ids]
4836 proc gettreediffs {ids} {
4837 global treediff treepending
4839 set treepending $ids
4841 if {[catch {set gdtf [open [diffcmd $ids {}] r]}]} return
4842 fconfigure $gdtf -blocking 0
4843 filerun $gdtf [list gettreediffline $gdtf $ids]
4846 proc gettreediffline {gdtf ids} {
4847 global treediff treediffs treepending diffids diffmergeid
4851 while {[incr nr] <= 1000 && [gets $gdtf line] >= 0} {
4852 set i [string first "\t" $line]
4854 set file [string range $line [expr {$i+1}] end]
4855 if {[string index $file 0] eq "\""} {
4856 set file [lindex $file 0]
4858 lappend treediff $file
4862 return [expr {$nr >= 1000? 2: 1}]
4865 set treediffs($ids) $treediff
4867 if {$cmitmode eq "tree"} {
4869 } elseif {$ids != $diffids} {
4870 if {![info exists diffmergeid]} {
4871 gettreediffs $diffids
4879 proc getblobdiffs {ids} {
4880 global diffopts blobdifffd diffids env
4881 global diffinhdr treediffs
4883 set env(GIT_DIFF_OPTS) $diffopts
4884 if {[catch {set bdf [open [diffcmd $ids {-p -C}] r]} err]} {
4885 puts "error getting diffs: $err"
4889 fconfigure $bdf -blocking 0
4890 set blobdifffd($ids) $bdf
4891 filerun $bdf [list getblobdiffline $bdf $diffids]
4894 proc setinlist {var i val} {
4897 while {[llength [set $var]] < $i} {
4900 if {[llength [set $var]] == $i} {
4907 proc makediffhdr {fname ids} {
4908 global ctext curdiffstart treediffs
4910 set i [lsearch -exact $treediffs($ids) $fname]
4912 setinlist difffilestart $i $curdiffstart
4914 set l [expr {(78 - [string length $fname]) / 2}]
4915 set pad [string range "----------------------------------------" 1 $l]
4916 $ctext insert $curdiffstart "$pad $fname $pad" filesep
4919 proc getblobdiffline {bdf ids} {
4920 global diffids blobdifffd ctext curdiffstart
4921 global diffnexthead diffnextnote difffilestart
4922 global diffinhdr treediffs
4925 $ctext conf -state normal
4926 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
4927 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
4931 if {![string compare -length 11 "diff --git " $line]} {
4932 # trim off "diff --git "
4933 set line [string range $line 11 end]
4935 # start of a new file
4936 $ctext insert end "\n"
4937 set curdiffstart [$ctext index "end - 1c"]
4938 $ctext insert end "\n" filesep
4939 # If the name hasn't changed the length will be odd,
4940 # the middle char will be a space, and the two bits either
4941 # side will be a/name and b/name, or "a/name" and "b/name".
4942 # If the name has changed we'll get "rename from" and
4943 # "rename to" lines following this, and we'll use them
4944 # to get the filenames.
4945 # This complexity is necessary because spaces in the filename(s)
4946 # don't get escaped.
4947 set l [string length $line]
4948 set i [expr {$l / 2}]
4949 if {!(($l & 1) && [string index $line $i] eq " " &&
4950 [string range $line 2 [expr {$i - 1}]] eq \
4951 [string range $line [expr {$i + 3}] end])} {
4954 # unescape if quoted and chop off the a/ from the front
4955 if {[string index $line 0] eq "\""} {
4956 set fname [string range [lindex $line 0] 2 end]
4958 set fname [string range $line 2 [expr {$i - 1}]]
4960 makediffhdr $fname $ids
4962 } elseif {[regexp {^@@ -([0-9]+)(,[0-9]+)? \+([0-9]+)(,[0-9]+)? @@(.*)} \
4963 $line match f1l f1c f2l f2c rest]} {
4964 $ctext insert end "$line\n" hunksep
4967 } elseif {$diffinhdr} {
4968 if {![string compare -length 12 "rename from " $line]} {
4969 set fname [string range $line 12 end]
4970 if {[string index $fname 0] eq "\""} {
4971 set fname [lindex $fname 0]
4973 set i [lsearch -exact $treediffs($ids) $fname]
4975 setinlist difffilestart $i $curdiffstart
4977 } elseif {![string compare -length 10 $line "rename to "]} {
4978 set fname [string range $line 10 end]
4979 if {[string index $fname 0] eq "\""} {
4980 set fname [lindex $fname 0]
4982 makediffhdr $fname $ids
4983 } elseif {[string compare -length 3 $line "---"] == 0} {
4986 } elseif {[string compare -length 3 $line "+++"] == 0} {
4990 $ctext insert end "$line\n" filesep
4993 set x [string range $line 0 0]
4994 if {$x == "-" || $x == "+"} {
4995 set tag [expr {$x == "+"}]
4996 $ctext insert end "$line\n" d$tag
4997 } elseif {$x == " "} {
4998 $ctext insert end "$line\n"
5000 # "\ No newline at end of file",
5001 # or something else we don't recognize
5002 $ctext insert end "$line\n" hunksep
5006 $ctext conf -state disabled
5011 return [expr {$nr >= 1000? 2: 1}]
5014 proc changediffdisp {} {
5015 global ctext diffelide
5017 $ctext tag conf d0 -elide [lindex $diffelide 0]
5018 $ctext tag conf d1 -elide [lindex $diffelide 1]
5022 global difffilestart ctext
5023 set prev [lindex $difffilestart 0]
5024 set here [$ctext index @0,0]
5025 foreach loc $difffilestart {
5026 if {[$ctext compare $loc >= $here]} {
5036 global difffilestart ctext
5037 set here [$ctext index @0,0]
5038 foreach loc $difffilestart {
5039 if {[$ctext compare $loc > $here]} {
5046 proc clear_ctext {{first 1.0}} {
5047 global ctext smarktop smarkbot
5049 set l [lindex [split $first .] 0]
5050 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
5053 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
5056 $ctext delete $first end
5059 proc incrsearch {name ix op} {
5060 global ctext searchstring searchdirn
5062 $ctext tag remove found 1.0 end
5063 if {[catch {$ctext index anchor}]} {
5064 # no anchor set, use start of selection, or of visible area
5065 set sel [$ctext tag ranges sel]
5067 $ctext mark set anchor [lindex $sel 0]
5068 } elseif {$searchdirn eq "-forwards"} {
5069 $ctext mark set anchor @0,0
5071 $ctext mark set anchor @0,[winfo height $ctext]
5074 if {$searchstring ne {}} {
5075 set here [$ctext search $searchdirn -- $searchstring anchor]
5084 global sstring ctext searchstring searchdirn
5087 $sstring icursor end
5088 set searchdirn -forwards
5089 if {$searchstring ne {}} {
5090 set sel [$ctext tag ranges sel]
5092 set start "[lindex $sel 0] + 1c"
5093 } elseif {[catch {set start [$ctext index anchor]}]} {
5096 set match [$ctext search -count mlen -- $searchstring $start]
5097 $ctext tag remove sel 1.0 end
5103 set mend "$match + $mlen c"
5104 $ctext tag add sel $match $mend
5105 $ctext mark unset anchor
5109 proc dosearchback {} {
5110 global sstring ctext searchstring searchdirn
5113 $sstring icursor end
5114 set searchdirn -backwards
5115 if {$searchstring ne {}} {
5116 set sel [$ctext tag ranges sel]
5118 set start [lindex $sel 0]
5119 } elseif {[catch {set start [$ctext index anchor]}]} {
5120 set start @0,[winfo height $ctext]
5122 set match [$ctext search -backwards -count ml -- $searchstring $start]
5123 $ctext tag remove sel 1.0 end
5129 set mend "$match + $ml c"
5130 $ctext tag add sel $match $mend
5131 $ctext mark unset anchor
5135 proc searchmark {first last} {
5136 global ctext searchstring
5140 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
5141 if {$match eq {}} break
5142 set mend "$match + $mlen c"
5143 $ctext tag add found $match $mend
5147 proc searchmarkvisible {doall} {
5148 global ctext smarktop smarkbot
5150 set topline [lindex [split [$ctext index @0,0] .] 0]
5151 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
5152 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
5153 # no overlap with previous
5154 searchmark $topline $botline
5155 set smarktop $topline
5156 set smarkbot $botline
5158 if {$topline < $smarktop} {
5159 searchmark $topline [expr {$smarktop-1}]
5160 set smarktop $topline
5162 if {$botline > $smarkbot} {
5163 searchmark [expr {$smarkbot+1}] $botline
5164 set smarkbot $botline
5169 proc scrolltext {f0 f1} {
5172 .bleft.sb set $f0 $f1
5173 if {$searchstring ne {}} {
5179 global linespc charspc canvx0 canvy0 mainfont
5180 global xspc1 xspc2 lthickness
5182 set linespc [font metrics $mainfont -linespace]
5183 set charspc [font measure $mainfont "m"]
5184 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
5185 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
5186 set lthickness [expr {int($linespc / 9) + 1}]
5187 set xspc1(0) $linespc
5195 set ymax [lindex [$canv cget -scrollregion] 3]
5196 if {$ymax eq {} || $ymax == 0} return
5197 set span [$canv yview]
5200 allcanvs yview moveto [lindex $span 0]
5202 if {[info exists selectedline]} {
5203 selectline $selectedline 0
5204 allcanvs yview moveto [lindex $span 0]
5208 proc incrfont {inc} {
5209 global mainfont textfont ctext canv phase cflist
5210 global charspc tabstop
5211 global stopped entries
5213 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
5214 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
5216 $ctext conf -font $textfont -tabs "[expr {$tabstop * $charspc}]"
5217 $cflist conf -font $textfont
5218 $ctext tag conf filesep -font [concat $textfont bold]
5219 foreach e $entries {
5220 $e conf -font $mainfont
5222 if {$phase eq "getcommits"} {
5223 $canv itemconf textitems -font $mainfont
5229 global sha1entry sha1string
5230 if {[string length $sha1string] == 40} {
5231 $sha1entry delete 0 end
5235 proc sha1change {n1 n2 op} {
5236 global sha1string currentid sha1but
5237 if {$sha1string == {}
5238 || ([info exists currentid] && $sha1string == $currentid)} {
5243 if {[$sha1but cget -state] == $state} return
5244 if {$state == "normal"} {
5245 $sha1but conf -state normal -relief raised -text "Goto: "
5247 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
5251 proc gotocommit {} {
5252 global sha1string currentid commitrow tagids headids
5253 global displayorder numcommits curview
5255 if {$sha1string == {}
5256 || ([info exists currentid] && $sha1string == $currentid)} return
5257 if {[info exists tagids($sha1string)]} {
5258 set id $tagids($sha1string)
5259 } elseif {[info exists headids($sha1string)]} {
5260 set id $headids($sha1string)
5262 set id [string tolower $sha1string]
5263 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
5265 foreach i $displayorder {
5266 if {[string match $id* $i]} {
5270 if {$matches ne {}} {
5271 if {[llength $matches] > 1} {
5272 error_popup "Short SHA1 id $id is ambiguous"
5275 set id [lindex $matches 0]
5279 if {[info exists commitrow($curview,$id)]} {
5280 selectline $commitrow($curview,$id) 1
5283 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
5288 error_popup "$type $sha1string is not known"
5291 proc lineenter {x y id} {
5292 global hoverx hovery hoverid hovertimer
5293 global commitinfo canv
5295 if {![info exists commitinfo($id)] && ![getcommit $id]} return
5299 if {[info exists hovertimer]} {
5300 after cancel $hovertimer
5302 set hovertimer [after 500 linehover]
5306 proc linemotion {x y id} {
5307 global hoverx hovery hoverid hovertimer
5309 if {[info exists hoverid] && $id == $hoverid} {
5312 if {[info exists hovertimer]} {
5313 after cancel $hovertimer
5315 set hovertimer [after 500 linehover]
5319 proc lineleave {id} {
5320 global hoverid hovertimer canv
5322 if {[info exists hoverid] && $id == $hoverid} {
5324 if {[info exists hovertimer]} {
5325 after cancel $hovertimer
5333 global hoverx hovery hoverid hovertimer
5334 global canv linespc lthickness
5335 global commitinfo mainfont
5337 set text [lindex $commitinfo($hoverid) 0]
5338 set ymax [lindex [$canv cget -scrollregion] 3]
5339 if {$ymax == {}} return
5340 set yfrac [lindex [$canv yview] 0]
5341 set x [expr {$hoverx + 2 * $linespc}]
5342 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
5343 set x0 [expr {$x - 2 * $lthickness}]
5344 set y0 [expr {$y - 2 * $lthickness}]
5345 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
5346 set y1 [expr {$y + $linespc + 2 * $lthickness}]
5347 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
5348 -fill \#ffff80 -outline black -width 1 -tags hover]
5350 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
5355 proc clickisonarrow {id y} {
5358 set ranges [rowranges $id]
5359 set thresh [expr {2 * $lthickness + 6}]
5360 set n [expr {[llength $ranges] - 1}]
5361 for {set i 1} {$i < $n} {incr i} {
5362 set row [lindex $ranges $i]
5363 if {abs([yc $row] - $y) < $thresh} {
5370 proc arrowjump {id n y} {
5373 # 1 <-> 2, 3 <-> 4, etc...
5374 set n [expr {(($n - 1) ^ 1) + 1}]
5375 set row [lindex [rowranges $id] $n]
5377 set ymax [lindex [$canv cget -scrollregion] 3]
5378 if {$ymax eq {} || $ymax <= 0} return
5379 set view [$canv yview]
5380 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
5381 set yfrac [expr {$yt / $ymax - $yspan / 2}]
5385 allcanvs yview moveto $yfrac
5388 proc lineclick {x y id isnew} {
5389 global ctext commitinfo children canv thickerline curview
5391 if {![info exists commitinfo($id)] && ![getcommit $id]} return
5396 # draw this line thicker than normal
5400 set ymax [lindex [$canv cget -scrollregion] 3]
5401 if {$ymax eq {}} return
5402 set yfrac [lindex [$canv yview] 0]
5403 set y [expr {$y + $yfrac * $ymax}]
5405 set dirn [clickisonarrow $id $y]
5407 arrowjump $id $dirn $y
5412 addtohistory [list lineclick $x $y $id 0]
5414 # fill the details pane with info about this line
5415 $ctext conf -state normal
5417 $ctext tag conf link -foreground blue -underline 1
5418 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
5419 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
5420 $ctext insert end "Parent:\t"
5421 $ctext insert end $id [list link link0]
5422 $ctext tag bind link0 <1> [list selbyid $id]
5423 set info $commitinfo($id)
5424 $ctext insert end "\n\t[lindex $info 0]\n"
5425 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
5426 set date [formatdate [lindex $info 2]]
5427 $ctext insert end "\tDate:\t$date\n"
5428 set kids $children($curview,$id)
5430 $ctext insert end "\nChildren:"
5432 foreach child $kids {
5434 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
5435 set info $commitinfo($child)
5436 $ctext insert end "\n\t"
5437 $ctext insert end $child [list link link$i]
5438 $ctext tag bind link$i <1> [list selbyid $child]
5439 $ctext insert end "\n\t[lindex $info 0]"
5440 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
5441 set date [formatdate [lindex $info 2]]
5442 $ctext insert end "\n\tDate:\t$date\n"
5445 $ctext conf -state disabled
5449 proc normalline {} {
5451 if {[info exists thickerline]} {
5459 global commitrow curview
5460 if {[info exists commitrow($curview,$id)]} {
5461 selectline $commitrow($curview,$id) 1
5467 if {![info exists startmstime]} {
5468 set startmstime [clock clicks -milliseconds]
5470 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
5473 proc rowmenu {x y id} {
5474 global rowctxmenu commitrow selectedline rowmenuid curview
5475 global nullid fakerowmenu mainhead
5478 if {![info exists selectedline]
5479 || $commitrow($curview,$id) eq $selectedline} {
5484 if {$id ne $nullid} {
5485 set menu $rowctxmenu
5486 $menu entryconfigure 7 -label "Reset $mainhead branch to here"
5488 set menu $fakerowmenu
5490 $menu entryconfigure "Diff this*" -state $state
5491 $menu entryconfigure "Diff selected*" -state $state
5492 $menu entryconfigure "Make patch" -state $state
5493 tk_popup $menu $x $y
5496 proc diffvssel {dirn} {
5497 global rowmenuid selectedline displayorder
5499 if {![info exists selectedline]} return
5501 set oldid [lindex $displayorder $selectedline]
5502 set newid $rowmenuid
5504 set oldid $rowmenuid
5505 set newid [lindex $displayorder $selectedline]
5507 addtohistory [list doseldiff $oldid $newid]
5508 doseldiff $oldid $newid
5511 proc doseldiff {oldid newid} {
5515 $ctext conf -state normal
5518 $ctext insert end "From "
5519 $ctext tag conf link -foreground blue -underline 1
5520 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
5521 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
5522 $ctext tag bind link0 <1> [list selbyid $oldid]
5523 $ctext insert end $oldid [list link link0]
5524 $ctext insert end "\n "
5525 $ctext insert end [lindex $commitinfo($oldid) 0]
5526 $ctext insert end "\n\nTo "
5527 $ctext tag bind link1 <1> [list selbyid $newid]
5528 $ctext insert end $newid [list link link1]
5529 $ctext insert end "\n "
5530 $ctext insert end [lindex $commitinfo($newid) 0]
5531 $ctext insert end "\n"
5532 $ctext conf -state disabled
5533 $ctext tag remove found 1.0 end
5534 startdiff [list $oldid $newid]
5538 global rowmenuid currentid commitinfo patchtop patchnum
5540 if {![info exists currentid]} return
5541 set oldid $currentid
5542 set oldhead [lindex $commitinfo($oldid) 0]
5543 set newid $rowmenuid
5544 set newhead [lindex $commitinfo($newid) 0]
5547 catch {destroy $top}
5549 label $top.title -text "Generate patch"
5550 grid $top.title - -pady 10
5551 label $top.from -text "From:"
5552 entry $top.fromsha1 -width 40 -relief flat
5553 $top.fromsha1 insert 0 $oldid
5554 $top.fromsha1 conf -state readonly
5555 grid $top.from $top.fromsha1 -sticky w
5556 entry $top.fromhead -width 60 -relief flat
5557 $top.fromhead insert 0 $oldhead
5558 $top.fromhead conf -state readonly
5559 grid x $top.fromhead -sticky w
5560 label $top.to -text "To:"
5561 entry $top.tosha1 -width 40 -relief flat
5562 $top.tosha1 insert 0 $newid
5563 $top.tosha1 conf -state readonly
5564 grid $top.to $top.tosha1 -sticky w
5565 entry $top.tohead -width 60 -relief flat
5566 $top.tohead insert 0 $newhead
5567 $top.tohead conf -state readonly
5568 grid x $top.tohead -sticky w
5569 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
5570 grid $top.rev x -pady 10
5571 label $top.flab -text "Output file:"
5572 entry $top.fname -width 60
5573 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
5575 grid $top.flab $top.fname -sticky w
5577 button $top.buts.gen -text "Generate" -command mkpatchgo
5578 button $top.buts.can -text "Cancel" -command mkpatchcan
5579 grid $top.buts.gen $top.buts.can
5580 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5581 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5582 grid $top.buts - -pady 10 -sticky ew
5586 proc mkpatchrev {} {
5589 set oldid [$patchtop.fromsha1 get]
5590 set oldhead [$patchtop.fromhead get]
5591 set newid [$patchtop.tosha1 get]
5592 set newhead [$patchtop.tohead get]
5593 foreach e [list fromsha1 fromhead tosha1 tohead] \
5594 v [list $newid $newhead $oldid $oldhead] {
5595 $patchtop.$e conf -state normal
5596 $patchtop.$e delete 0 end
5597 $patchtop.$e insert 0 $v
5598 $patchtop.$e conf -state readonly
5603 global patchtop nullid
5605 set oldid [$patchtop.fromsha1 get]
5606 set newid [$patchtop.tosha1 get]
5607 set fname [$patchtop.fname get]
5608 if {$newid eq $nullid} {
5609 set cmd [list git diff-index -p $oldid]
5610 } elseif {$oldid eq $nullid} {
5611 set cmd [list git diff-index -p -R $newid]
5613 set cmd [list git diff-tree -p $oldid $newid]
5615 lappend cmd >$fname &
5616 if {[catch {eval exec $cmd} err]} {
5617 error_popup "Error creating patch: $err"
5619 catch {destroy $patchtop}
5623 proc mkpatchcan {} {
5626 catch {destroy $patchtop}
5631 global rowmenuid mktagtop commitinfo
5635 catch {destroy $top}
5637 label $top.title -text "Create tag"
5638 grid $top.title - -pady 10
5639 label $top.id -text "ID:"
5640 entry $top.sha1 -width 40 -relief flat
5641 $top.sha1 insert 0 $rowmenuid
5642 $top.sha1 conf -state readonly
5643 grid $top.id $top.sha1 -sticky w
5644 entry $top.head -width 60 -relief flat
5645 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
5646 $top.head conf -state readonly
5647 grid x $top.head -sticky w
5648 label $top.tlab -text "Tag name:"
5649 entry $top.tag -width 60
5650 grid $top.tlab $top.tag -sticky w
5652 button $top.buts.gen -text "Create" -command mktaggo
5653 button $top.buts.can -text "Cancel" -command mktagcan
5654 grid $top.buts.gen $top.buts.can
5655 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5656 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5657 grid $top.buts - -pady 10 -sticky ew
5662 global mktagtop env tagids idtags
5664 set id [$mktagtop.sha1 get]
5665 set tag [$mktagtop.tag get]
5667 error_popup "No tag name specified"
5670 if {[info exists tagids($tag)]} {
5671 error_popup "Tag \"$tag\" already exists"
5676 set fname [file join $dir "refs/tags" $tag]
5677 set f [open $fname w]
5681 error_popup "Error creating tag: $err"
5685 set tagids($tag) $id
5686 lappend idtags($id) $tag
5691 proc redrawtags {id} {
5692 global canv linehtag commitrow idpos selectedline curview
5693 global mainfont canvxmax iddrawn
5695 if {![info exists commitrow($curview,$id)]} return
5696 if {![info exists iddrawn($id)]} return
5697 drawcommits $commitrow($curview,$id)
5698 $canv delete tag.$id
5699 set xt [eval drawtags $id $idpos($id)]
5700 $canv coords $linehtag($commitrow($curview,$id)) $xt [lindex $idpos($id) 2]
5701 set text [$canv itemcget $linehtag($commitrow($curview,$id)) -text]
5702 set xr [expr {$xt + [font measure $mainfont $text]}]
5703 if {$xr > $canvxmax} {
5707 if {[info exists selectedline]
5708 && $selectedline == $commitrow($curview,$id)} {
5709 selectline $selectedline 0
5716 catch {destroy $mktagtop}
5725 proc writecommit {} {
5726 global rowmenuid wrcomtop commitinfo wrcomcmd
5728 set top .writecommit
5730 catch {destroy $top}
5732 label $top.title -text "Write commit to file"
5733 grid $top.title - -pady 10
5734 label $top.id -text "ID:"
5735 entry $top.sha1 -width 40 -relief flat
5736 $top.sha1 insert 0 $rowmenuid
5737 $top.sha1 conf -state readonly
5738 grid $top.id $top.sha1 -sticky w
5739 entry $top.head -width 60 -relief flat
5740 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
5741 $top.head conf -state readonly
5742 grid x $top.head -sticky w
5743 label $top.clab -text "Command:"
5744 entry $top.cmd -width 60 -textvariable wrcomcmd
5745 grid $top.clab $top.cmd -sticky w -pady 10
5746 label $top.flab -text "Output file:"
5747 entry $top.fname -width 60
5748 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
5749 grid $top.flab $top.fname -sticky w
5751 button $top.buts.gen -text "Write" -command wrcomgo
5752 button $top.buts.can -text "Cancel" -command wrcomcan
5753 grid $top.buts.gen $top.buts.can
5754 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5755 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5756 grid $top.buts - -pady 10 -sticky ew
5763 set id [$wrcomtop.sha1 get]
5764 set cmd "echo $id | [$wrcomtop.cmd get]"
5765 set fname [$wrcomtop.fname get]
5766 if {[catch {exec sh -c $cmd >$fname &} err]} {
5767 error_popup "Error writing commit: $err"
5769 catch {destroy $wrcomtop}
5776 catch {destroy $wrcomtop}
5781 global rowmenuid mkbrtop
5784 catch {destroy $top}
5786 label $top.title -text "Create new branch"
5787 grid $top.title - -pady 10
5788 label $top.id -text "ID:"
5789 entry $top.sha1 -width 40 -relief flat
5790 $top.sha1 insert 0 $rowmenuid
5791 $top.sha1 conf -state readonly
5792 grid $top.id $top.sha1 -sticky w
5793 label $top.nlab -text "Name:"
5794 entry $top.name -width 40
5795 grid $top.nlab $top.name -sticky w
5797 button $top.buts.go -text "Create" -command [list mkbrgo $top]
5798 button $top.buts.can -text "Cancel" -command "catch {destroy $top}"
5799 grid $top.buts.go $top.buts.can
5800 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5801 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5802 grid $top.buts - -pady 10 -sticky ew
5807 global headids idheads
5809 set name [$top.name get]
5810 set id [$top.sha1 get]
5812 error_popup "Please specify a name for the new branch"
5815 catch {destroy $top}
5819 exec git branch $name $id
5824 set headids($name) $id
5825 lappend idheads($id) $name
5833 proc cherrypick {} {
5834 global rowmenuid curview commitrow
5837 set oldhead [exec git rev-parse HEAD]
5838 set dheads [descheads $rowmenuid]
5839 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
5840 set ok [confirm_popup "Commit [string range $rowmenuid 0 7] is already\
5841 included in branch $mainhead -- really re-apply it?"]
5846 # Unfortunately git-cherry-pick writes stuff to stderr even when
5847 # no error occurs, and exec takes that as an indication of error...
5848 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
5853 set newhead [exec git rev-parse HEAD]
5854 if {$newhead eq $oldhead} {
5856 error_popup "No changes committed"
5859 addnewchild $newhead $oldhead
5860 if {[info exists commitrow($curview,$oldhead)]} {
5861 insertrow $commitrow($curview,$oldhead) $newhead
5862 if {$mainhead ne {}} {
5863 movehead $newhead $mainhead
5864 movedhead $newhead $mainhead
5873 global mainheadid mainhead rowmenuid confirm_ok resettype
5874 global showlocalchanges
5877 set w ".confirmreset"
5880 wm title $w "Confirm reset"
5881 message $w.m -text \
5882 "Reset branch $mainhead to [string range $rowmenuid 0 7]?" \
5883 -justify center -aspect 1000
5884 pack $w.m -side top -fill x -padx 20 -pady 20
5885 frame $w.f -relief sunken -border 2
5886 message $w.f.rt -text "Reset type:" -aspect 1000
5887 grid $w.f.rt -sticky w
5889 radiobutton $w.f.soft -value soft -variable resettype -justify left \
5890 -text "Soft: Leave working tree and index untouched"
5891 grid $w.f.soft -sticky w
5892 radiobutton $w.f.mixed -value mixed -variable resettype -justify left \
5893 -text "Mixed: Leave working tree untouched, reset index"
5894 grid $w.f.mixed -sticky w
5895 radiobutton $w.f.hard -value hard -variable resettype -justify left \
5896 -text "Hard: Reset working tree and index\n(discard ALL local changes)"
5897 grid $w.f.hard -sticky w
5898 pack $w.f -side top -fill x
5899 button $w.ok -text OK -command "set confirm_ok 1; destroy $w"
5900 pack $w.ok -side left -fill x -padx 20 -pady 20
5901 button $w.cancel -text Cancel -command "destroy $w"
5902 pack $w.cancel -side right -fill x -padx 20 -pady 20
5903 bind $w <Visibility> "grab $w; focus $w"
5905 if {!$confirm_ok} return
5906 if {[catch {set fd [open \
5907 [list | sh -c "git reset --$resettype $rowmenuid 2>&1"] r]} err]} {
5911 set w ".resetprogress"
5912 filerun $fd [list readresetstat $fd $w]
5915 wm title $w "Reset progress"
5916 message $w.m -text "Reset in progress, please wait..." \
5917 -justify center -aspect 1000
5918 pack $w.m -side top -fill x -padx 20 -pady 5
5919 canvas $w.c -width 150 -height 20 -bg white
5920 $w.c create rect 0 0 0 20 -fill green -tags rect
5921 pack $w.c -side top -fill x -padx 20 -pady 5 -expand 1
5926 proc readresetstat {fd w} {
5927 global mainhead mainheadid showlocalchanges
5929 if {[gets $fd line] >= 0} {
5930 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
5931 set x [expr {($m * 150) / $n}]
5932 $w.c coords rect 0 0 $x 20
5938 if {[catch {close $fd} err]} {
5941 set oldhead $mainheadid
5942 set newhead [exec git rev-parse HEAD]
5943 if {$newhead ne $oldhead} {
5944 movehead $newhead $mainhead
5945 movedhead $newhead $mainhead
5946 set mainheadid $newhead
5950 if {$showlocalchanges} {
5956 # context menu for a head
5957 proc headmenu {x y id head} {
5958 global headmenuid headmenuhead headctxmenu mainhead
5961 set headmenuhead $head
5963 if {$head eq $mainhead} {
5966 $headctxmenu entryconfigure 0 -state $state
5967 $headctxmenu entryconfigure 1 -state $state
5968 tk_popup $headctxmenu $x $y
5972 global headmenuid headmenuhead mainhead headids
5973 global showlocalchanges mainheadid
5975 # check the tree is clean first??
5976 set oldmainhead $mainhead
5981 exec git checkout -q $headmenuhead
5987 set mainhead $headmenuhead
5988 set mainheadid $headmenuid
5989 if {[info exists headids($oldmainhead)]} {
5990 redrawtags $headids($oldmainhead)
5992 redrawtags $headmenuid
5994 if {$showlocalchanges} {
6000 global headmenuid headmenuhead mainhead
6001 global headids idheads
6003 set head $headmenuhead
6005 # this check shouldn't be needed any more...
6006 if {$head eq $mainhead} {
6007 error_popup "Cannot delete the currently checked-out branch"
6010 set dheads [descheads $id]
6011 if {$dheads eq $headids($head)} {
6012 # the stuff on this branch isn't on any other branch
6013 if {![confirm_popup "The commits on branch $head aren't on any other\
6014 branch.\nReally delete branch $head?"]} return
6018 if {[catch {exec git branch -D $head} err]} {
6023 removehead $id $head
6024 removedhead $id $head
6030 # Stuff for finding nearby tags
6031 proc getallcommits {} {
6032 global allcommits allids nbmp nextarc seeds
6042 # Called when the graph might have changed
6043 proc regetallcommits {} {
6044 global allcommits seeds
6046 set cmd [concat | git rev-list --all --parents]
6050 set fd [open $cmd r]
6051 fconfigure $fd -blocking 0
6054 filerun $fd [list getallclines $fd]
6057 # Since most commits have 1 parent and 1 child, we group strings of
6058 # such commits into "arcs" joining branch/merge points (BMPs), which
6059 # are commits that either don't have 1 parent or don't have 1 child.
6061 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
6062 # arcout(id) - outgoing arcs for BMP
6063 # arcids(a) - list of IDs on arc including end but not start
6064 # arcstart(a) - BMP ID at start of arc
6065 # arcend(a) - BMP ID at end of arc
6066 # growing(a) - arc a is still growing
6067 # arctags(a) - IDs out of arcids (excluding end) that have tags
6068 # archeads(a) - IDs out of arcids (excluding end) that have heads
6069 # The start of an arc is at the descendent end, so "incoming" means
6070 # coming from descendents, and "outgoing" means going towards ancestors.
6072 proc getallclines {fd} {
6073 global allids allparents allchildren idtags idheads nextarc nbmp
6074 global arcnos arcids arctags arcout arcend arcstart archeads growing
6075 global seeds allcommits
6078 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
6079 set id [lindex $line 0]
6080 if {[info exists allparents($id)]} {
6085 set olds [lrange $line 1 end]
6086 set allparents($id) $olds
6087 if {![info exists allchildren($id)]} {
6088 set allchildren($id) {}
6093 if {[llength $olds] == 1 && [llength $a] == 1} {
6094 lappend arcids($a) $id
6095 if {[info exists idtags($id)]} {
6096 lappend arctags($a) $id
6098 if {[info exists idheads($id)]} {
6099 lappend archeads($a) $id
6101 if {[info exists allparents($olds)]} {
6102 # seen parent already
6103 if {![info exists arcout($olds)]} {
6106 lappend arcids($a) $olds
6107 set arcend($a) $olds
6110 lappend allchildren($olds) $id
6111 lappend arcnos($olds) $a
6116 foreach a $arcnos($id) {
6117 lappend arcids($a) $id
6124 lappend allchildren($p) $id
6125 set a [incr nextarc]
6126 set arcstart($a) $id
6133 if {[info exists allparents($p)]} {
6134 # seen it already, may need to make a new branch
6135 if {![info exists arcout($p)]} {
6138 lappend arcids($a) $p
6142 lappend arcnos($p) $a
6147 global cached_dheads cached_dtags cached_atags
6148 catch {unset cached_dheads}
6149 catch {unset cached_dtags}
6150 catch {unset cached_atags}
6153 return [expr {$nid >= 1000? 2: 1}]
6156 if {[incr allcommits -1] == 0} {
6163 proc recalcarc {a} {
6164 global arctags archeads arcids idtags idheads
6168 foreach id [lrange $arcids($a) 0 end-1] {
6169 if {[info exists idtags($id)]} {
6172 if {[info exists idheads($id)]} {
6177 set archeads($a) $ah
6181 global arcnos arcids nextarc nbmp arctags archeads idtags idheads
6182 global arcstart arcend arcout allparents growing
6185 if {[llength $a] != 1} {
6186 puts "oops splitarc called but [llength $a] arcs already"
6190 set i [lsearch -exact $arcids($a) $p]
6192 puts "oops splitarc $p not in arc $a"
6195 set na [incr nextarc]
6196 if {[info exists arcend($a)]} {
6197 set arcend($na) $arcend($a)
6199 set l [lindex $allparents([lindex $arcids($a) end]) 0]
6200 set j [lsearch -exact $arcnos($l) $a]
6201 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
6203 set tail [lrange $arcids($a) [expr {$i+1}] end]
6204 set arcids($a) [lrange $arcids($a) 0 $i]
6206 set arcstart($na) $p
6208 set arcids($na) $tail
6209 if {[info exists growing($a)]} {
6216 if {[llength $arcnos($id)] == 1} {
6219 set j [lsearch -exact $arcnos($id) $a]
6220 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
6224 # reconstruct tags and heads lists
6225 if {$arctags($a) ne {} || $archeads($a) ne {}} {
6230 set archeads($na) {}
6234 # Update things for a new commit added that is a child of one
6235 # existing commit. Used when cherry-picking.
6236 proc addnewchild {id p} {
6237 global allids allparents allchildren idtags nextarc nbmp
6238 global arcnos arcids arctags arcout arcend arcstart archeads growing
6242 set allparents($id) [list $p]
6243 set allchildren($id) {}
6247 lappend allchildren($p) $id
6248 set a [incr nextarc]
6249 set arcstart($a) $id
6252 set arcids($a) [list $p]
6254 if {![info exists arcout($p)]} {
6257 lappend arcnos($p) $a
6258 set arcout($id) [list $a]
6261 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
6262 # or 0 if neither is true.
6263 proc anc_or_desc {a b} {
6264 global arcout arcstart arcend arcnos cached_isanc
6266 if {$arcnos($a) eq $arcnos($b)} {
6267 # Both are on the same arc(s); either both are the same BMP,
6268 # or if one is not a BMP, the other is also not a BMP or is
6269 # the BMP at end of the arc (and it only has 1 incoming arc).
6270 # Or both can be BMPs with no incoming arcs.
6271 if {$a eq $b || $arcnos($a) eq {}} {
6274 # assert {[llength $arcnos($a)] == 1}
6275 set arc [lindex $arcnos($a) 0]
6276 set i [lsearch -exact $arcids($arc) $a]
6277 set j [lsearch -exact $arcids($arc) $b]
6278 if {$i < 0 || $i > $j} {
6285 if {![info exists arcout($a)]} {
6286 set arc [lindex $arcnos($a) 0]
6287 if {[info exists arcend($arc)]} {
6288 set aend $arcend($arc)
6292 set a $arcstart($arc)
6296 if {![info exists arcout($b)]} {
6297 set arc [lindex $arcnos($b) 0]
6298 if {[info exists arcend($arc)]} {
6299 set bend $arcend($arc)
6303 set b $arcstart($arc)
6313 if {[info exists cached_isanc($a,$bend)]} {
6314 if {$cached_isanc($a,$bend)} {
6318 if {[info exists cached_isanc($b,$aend)]} {
6319 if {$cached_isanc($b,$aend)} {
6322 if {[info exists cached_isanc($a,$bend)]} {
6327 set todo [list $a $b]
6330 for {set i 0} {$i < [llength $todo]} {incr i} {
6331 set x [lindex $todo $i]
6332 if {$anc($x) eq {}} {
6335 foreach arc $arcnos($x) {
6336 set xd $arcstart($arc)
6338 set cached_isanc($a,$bend) 1
6339 set cached_isanc($b,$aend) 0
6341 } elseif {$xd eq $aend} {
6342 set cached_isanc($b,$aend) 1
6343 set cached_isanc($a,$bend) 0
6346 if {![info exists anc($xd)]} {
6347 set anc($xd) $anc($x)
6349 } elseif {$anc($xd) ne $anc($x)} {
6354 set cached_isanc($a,$bend) 0
6355 set cached_isanc($b,$aend) 0
6359 # This identifies whether $desc has an ancestor that is
6360 # a growing tip of the graph and which is not an ancestor of $anc
6361 # and returns 0 if so and 1 if not.
6362 # If we subsequently discover a tag on such a growing tip, and that
6363 # turns out to be a descendent of $anc (which it could, since we
6364 # don't necessarily see children before parents), then $desc
6365 # isn't a good choice to display as a descendent tag of
6366 # $anc (since it is the descendent of another tag which is
6367 # a descendent of $anc). Similarly, $anc isn't a good choice to
6368 # display as a ancestor tag of $desc.
6370 proc is_certain {desc anc} {
6371 global arcnos arcout arcstart arcend growing problems
6374 if {[llength $arcnos($anc)] == 1} {
6375 # tags on the same arc are certain
6376 if {$arcnos($desc) eq $arcnos($anc)} {
6379 if {![info exists arcout($anc)]} {
6380 # if $anc is partway along an arc, use the start of the arc instead
6381 set a [lindex $arcnos($anc) 0]
6382 set anc $arcstart($a)
6385 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
6388 set a [lindex $arcnos($desc) 0]
6394 set anclist [list $x]
6398 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
6399 set x [lindex $anclist $i]
6404 foreach a $arcout($x) {
6405 if {[info exists growing($a)]} {
6406 if {![info exists growanc($x)] && $dl($x)} {
6412 if {[info exists dl($y)]} {
6416 if {![info exists done($y)]} {
6419 if {[info exists growanc($x)]} {
6423 for {set k 0} {$k < [llength $xl]} {incr k} {
6424 set z [lindex $xl $k]
6425 foreach c $arcout($z) {
6426 if {[info exists arcend($c)]} {
6428 if {[info exists dl($v)] && $dl($v)} {
6430 if {![info exists done($v)]} {
6433 if {[info exists growanc($v)]} {
6443 } elseif {$y eq $anc || !$dl($x)} {
6454 foreach x [array names growanc] {
6463 proc validate_arctags {a} {
6464 global arctags idtags
6468 foreach id $arctags($a) {
6470 if {![info exists idtags($id)]} {
6471 set na [lreplace $na $i $i]
6478 proc validate_archeads {a} {
6479 global archeads idheads
6482 set na $archeads($a)
6483 foreach id $archeads($a) {
6485 if {![info exists idheads($id)]} {
6486 set na [lreplace $na $i $i]
6490 set archeads($a) $na
6493 # Return the list of IDs that have tags that are descendents of id,
6494 # ignoring IDs that are descendents of IDs already reported.
6495 proc desctags {id} {
6496 global arcnos arcstart arcids arctags idtags allparents
6497 global growing cached_dtags
6499 if {![info exists allparents($id)]} {
6502 set t1 [clock clicks -milliseconds]
6504 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
6505 # part-way along an arc; check that arc first
6506 set a [lindex $arcnos($id) 0]
6507 if {$arctags($a) ne {}} {
6509 set i [lsearch -exact $arcids($a) $id]
6511 foreach t $arctags($a) {
6512 set j [lsearch -exact $arcids($a) $t]
6520 set id $arcstart($a)
6521 if {[info exists idtags($id)]} {
6525 if {[info exists cached_dtags($id)]} {
6526 return $cached_dtags($id)
6533 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
6534 set id [lindex $todo $i]
6536 set ta [info exists hastaggedancestor($id)]
6540 # ignore tags on starting node
6541 if {!$ta && $i > 0} {
6542 if {[info exists idtags($id)]} {
6545 } elseif {[info exists cached_dtags($id)]} {
6546 set tagloc($id) $cached_dtags($id)
6550 foreach a $arcnos($id) {
6552 if {!$ta && $arctags($a) ne {}} {
6554 if {$arctags($a) ne {}} {
6555 lappend tagloc($id) [lindex $arctags($a) end]
6558 if {$ta || $arctags($a) ne {}} {
6559 set tomark [list $d]
6560 for {set j 0} {$j < [llength $tomark]} {incr j} {
6561 set dd [lindex $tomark $j]
6562 if {![info exists hastaggedancestor($dd)]} {
6563 if {[info exists done($dd)]} {
6564 foreach b $arcnos($dd) {
6565 lappend tomark $arcstart($b)
6567 if {[info exists tagloc($dd)]} {
6570 } elseif {[info exists queued($dd)]} {
6573 set hastaggedancestor($dd) 1
6577 if {![info exists queued($d)]} {
6580 if {![info exists hastaggedancestor($d)]} {
6587 foreach id [array names tagloc] {
6588 if {![info exists hastaggedancestor($id)]} {
6589 foreach t $tagloc($id) {
6590 if {[lsearch -exact $tags $t] < 0} {
6596 set t2 [clock clicks -milliseconds]
6599 # remove tags that are descendents of other tags
6600 for {set i 0} {$i < [llength $tags]} {incr i} {
6601 set a [lindex $tags $i]
6602 for {set j 0} {$j < $i} {incr j} {
6603 set b [lindex $tags $j]
6604 set r [anc_or_desc $a $b]
6606 set tags [lreplace $tags $j $j]
6609 } elseif {$r == -1} {
6610 set tags [lreplace $tags $i $i]
6617 if {[array names growing] ne {}} {
6618 # graph isn't finished, need to check if any tag could get
6619 # eclipsed by another tag coming later. Simply ignore any
6620 # tags that could later get eclipsed.
6623 if {[is_certain $t $origid]} {
6627 if {$tags eq $ctags} {
6628 set cached_dtags($origid) $tags
6633 set cached_dtags($origid) $tags
6635 set t3 [clock clicks -milliseconds]
6636 if {0 && $t3 - $t1 >= 100} {
6637 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
6638 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
6644 global arcnos arcids arcout arcend arctags idtags allparents
6645 global growing cached_atags
6647 if {![info exists allparents($id)]} {
6650 set t1 [clock clicks -milliseconds]
6652 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
6653 # part-way along an arc; check that arc first
6654 set a [lindex $arcnos($id) 0]
6655 if {$arctags($a) ne {}} {
6657 set i [lsearch -exact $arcids($a) $id]
6658 foreach t $arctags($a) {
6659 set j [lsearch -exact $arcids($a) $t]
6665 if {![info exists arcend($a)]} {
6669 if {[info exists idtags($id)]} {
6673 if {[info exists cached_atags($id)]} {
6674 return $cached_atags($id)
6682 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
6683 set id [lindex $todo $i]
6685 set td [info exists hastaggeddescendent($id)]
6689 # ignore tags on starting node
6690 if {!$td && $i > 0} {
6691 if {[info exists idtags($id)]} {
6694 } elseif {[info exists cached_atags($id)]} {
6695 set tagloc($id) $cached_atags($id)
6699 foreach a $arcout($id) {
6700 if {!$td && $arctags($a) ne {}} {
6702 if {$arctags($a) ne {}} {
6703 lappend tagloc($id) [lindex $arctags($a) 0]
6706 if {![info exists arcend($a)]} continue
6708 if {$td || $arctags($a) ne {}} {
6709 set tomark [list $d]
6710 for {set j 0} {$j < [llength $tomark]} {incr j} {
6711 set dd [lindex $tomark $j]
6712 if {![info exists hastaggeddescendent($dd)]} {
6713 if {[info exists done($dd)]} {
6714 foreach b $arcout($dd) {
6715 if {[info exists arcend($b)]} {
6716 lappend tomark $arcend($b)
6719 if {[info exists tagloc($dd)]} {
6722 } elseif {[info exists queued($dd)]} {
6725 set hastaggeddescendent($dd) 1
6729 if {![info exists queued($d)]} {
6732 if {![info exists hastaggeddescendent($d)]} {
6738 set t2 [clock clicks -milliseconds]
6741 foreach id [array names tagloc] {
6742 if {![info exists hastaggeddescendent($id)]} {
6743 foreach t $tagloc($id) {
6744 if {[lsearch -exact $tags $t] < 0} {
6751 # remove tags that are ancestors of other tags
6752 for {set i 0} {$i < [llength $tags]} {incr i} {
6753 set a [lindex $tags $i]
6754 for {set j 0} {$j < $i} {incr j} {
6755 set b [lindex $tags $j]
6756 set r [anc_or_desc $a $b]
6758 set tags [lreplace $tags $j $j]
6761 } elseif {$r == 1} {
6762 set tags [lreplace $tags $i $i]
6769 if {[array names growing] ne {}} {
6770 # graph isn't finished, need to check if any tag could get
6771 # eclipsed by another tag coming later. Simply ignore any
6772 # tags that could later get eclipsed.
6775 if {[is_certain $origid $t]} {
6779 if {$tags eq $ctags} {
6780 set cached_atags($origid) $tags
6785 set cached_atags($origid) $tags
6787 set t3 [clock clicks -milliseconds]
6788 if {0 && $t3 - $t1 >= 100} {
6789 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
6790 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
6795 # Return the list of IDs that have heads that are descendents of id,
6796 # including id itself if it has a head.
6797 proc descheads {id} {
6798 global arcnos arcstart arcids archeads idheads cached_dheads
6801 if {![info exists allparents($id)]} {
6805 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
6806 # part-way along an arc; check it first
6807 set a [lindex $arcnos($id) 0]
6808 if {$archeads($a) ne {}} {
6809 validate_archeads $a
6810 set i [lsearch -exact $arcids($a) $id]
6811 foreach t $archeads($a) {
6812 set j [lsearch -exact $arcids($a) $t]
6817 set id $arcstart($a)
6823 for {set i 0} {$i < [llength $todo]} {incr i} {
6824 set id [lindex $todo $i]
6825 if {[info exists cached_dheads($id)]} {
6826 set ret [concat $ret $cached_dheads($id)]
6828 if {[info exists idheads($id)]} {
6831 foreach a $arcnos($id) {
6832 if {$archeads($a) ne {}} {
6833 validate_archeads $a
6834 if {$archeads($a) ne {}} {
6835 set ret [concat $ret $archeads($a)]
6839 if {![info exists seen($d)]} {
6846 set ret [lsort -unique $ret]
6847 set cached_dheads($origid) $ret
6848 return [concat $ret $aret]
6851 proc addedtag {id} {
6852 global arcnos arcout cached_dtags cached_atags
6854 if {![info exists arcnos($id)]} return
6855 if {![info exists arcout($id)]} {
6856 recalcarc [lindex $arcnos($id) 0]
6858 catch {unset cached_dtags}
6859 catch {unset cached_atags}
6862 proc addedhead {hid head} {
6863 global arcnos arcout cached_dheads
6865 if {![info exists arcnos($hid)]} return
6866 if {![info exists arcout($hid)]} {
6867 recalcarc [lindex $arcnos($hid) 0]
6869 catch {unset cached_dheads}
6872 proc removedhead {hid head} {
6873 global cached_dheads
6875 catch {unset cached_dheads}
6878 proc movedhead {hid head} {
6879 global arcnos arcout cached_dheads
6881 if {![info exists arcnos($hid)]} return
6882 if {![info exists arcout($hid)]} {
6883 recalcarc [lindex $arcnos($hid) 0]
6885 catch {unset cached_dheads}
6888 proc changedrefs {} {
6889 global cached_dheads cached_dtags cached_atags
6890 global arctags archeads arcnos arcout idheads idtags
6892 foreach id [concat [array names idheads] [array names idtags]] {
6893 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
6894 set a [lindex $arcnos($id) 0]
6895 if {![info exists donearc($a)]} {
6901 catch {unset cached_dtags}
6902 catch {unset cached_atags}
6903 catch {unset cached_dheads}
6906 proc rereadrefs {} {
6907 global idtags idheads idotherrefs mainhead
6909 set refids [concat [array names idtags] \
6910 [array names idheads] [array names idotherrefs]]
6911 foreach id $refids {
6912 if {![info exists ref($id)]} {
6913 set ref($id) [listrefs $id]
6916 set oldmainhead $mainhead
6919 set refids [lsort -unique [concat $refids [array names idtags] \
6920 [array names idheads] [array names idotherrefs]]]
6921 foreach id $refids {
6922 set v [listrefs $id]
6923 if {![info exists ref($id)] || $ref($id) != $v ||
6924 ($id eq $oldmainhead && $id ne $mainhead) ||
6925 ($id eq $mainhead && $id ne $oldmainhead)} {
6931 proc listrefs {id} {
6932 global idtags idheads idotherrefs
6935 if {[info exists idtags($id)]} {
6939 if {[info exists idheads($id)]} {
6943 if {[info exists idotherrefs($id)]} {
6944 set z $idotherrefs($id)
6946 return [list $x $y $z]
6949 proc showtag {tag isnew} {
6950 global ctext tagcontents tagids linknum tagobjid
6953 addtohistory [list showtag $tag 0]
6955 $ctext conf -state normal
6958 if {![info exists tagcontents($tag)]} {
6960 set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
6963 if {[info exists tagcontents($tag)]} {
6964 set text $tagcontents($tag)
6966 set text "Tag: $tag\nId: $tagids($tag)"
6968 appendwithlinks $text {}
6969 $ctext conf -state disabled
6981 global maxwidth maxgraphpct diffopts
6982 global oldprefs prefstop showneartags showlocalchanges
6983 global bgcolor fgcolor ctext diffcolors selectbgcolor
6984 global uifont tabstop
6988 if {[winfo exists $top]} {
6992 foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
6993 set oldprefs($v) [set $v]
6996 wm title $top "Gitk preferences"
6997 label $top.ldisp -text "Commit list display options"
6998 $top.ldisp configure -font $uifont
6999 grid $top.ldisp - -sticky w -pady 10
7000 label $top.spacer -text " "
7001 label $top.maxwidthl -text "Maximum graph width (lines)" \
7003 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
7004 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
7005 label $top.maxpctl -text "Maximum graph width (% of pane)" \
7007 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
7008 grid x $top.maxpctl $top.maxpct -sticky w
7009 frame $top.showlocal
7010 label $top.showlocal.l -text "Show local changes" -font optionfont
7011 checkbutton $top.showlocal.b -variable showlocalchanges
7012 pack $top.showlocal.b $top.showlocal.l -side left
7013 grid x $top.showlocal -sticky w
7015 label $top.ddisp -text "Diff display options"
7016 $top.ddisp configure -font $uifont
7017 grid $top.ddisp - -sticky w -pady 10
7018 label $top.diffoptl -text "Options for diff program" \
7020 entry $top.diffopt -width 20 -textvariable diffopts
7021 grid x $top.diffoptl $top.diffopt -sticky w
7023 label $top.ntag.l -text "Display nearby tags" -font optionfont
7024 checkbutton $top.ntag.b -variable showneartags
7025 pack $top.ntag.b $top.ntag.l -side left
7026 grid x $top.ntag -sticky w
7027 label $top.tabstopl -text "tabstop" -font optionfont
7028 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
7029 grid x $top.tabstopl $top.tabstop -sticky w
7031 label $top.cdisp -text "Colors: press to choose"
7032 $top.cdisp configure -font $uifont
7033 grid $top.cdisp - -sticky w -pady 10
7034 label $top.bg -padx 40 -relief sunk -background $bgcolor
7035 button $top.bgbut -text "Background" -font optionfont \
7036 -command [list choosecolor bgcolor 0 $top.bg background setbg]
7037 grid x $top.bgbut $top.bg -sticky w
7038 label $top.fg -padx 40 -relief sunk -background $fgcolor
7039 button $top.fgbut -text "Foreground" -font optionfont \
7040 -command [list choosecolor fgcolor 0 $top.fg foreground setfg]
7041 grid x $top.fgbut $top.fg -sticky w
7042 label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
7043 button $top.diffoldbut -text "Diff: old lines" -font optionfont \
7044 -command [list choosecolor diffcolors 0 $top.diffold "diff old lines" \
7045 [list $ctext tag conf d0 -foreground]]
7046 grid x $top.diffoldbut $top.diffold -sticky w
7047 label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
7048 button $top.diffnewbut -text "Diff: new lines" -font optionfont \
7049 -command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \
7050 [list $ctext tag conf d1 -foreground]]
7051 grid x $top.diffnewbut $top.diffnew -sticky w
7052 label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
7053 button $top.hunksepbut -text "Diff: hunk header" -font optionfont \
7054 -command [list choosecolor diffcolors 2 $top.hunksep \
7055 "diff hunk header" \
7056 [list $ctext tag conf hunksep -foreground]]
7057 grid x $top.hunksepbut $top.hunksep -sticky w
7058 label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor
7059 button $top.selbgbut -text "Select bg" -font optionfont \
7060 -command [list choosecolor selectbgcolor 0 $top.selbgsep background setselbg]
7061 grid x $top.selbgbut $top.selbgsep -sticky w
7064 button $top.buts.ok -text "OK" -command prefsok -default active
7065 $top.buts.ok configure -font $uifont
7066 button $top.buts.can -text "Cancel" -command prefscan -default normal
7067 $top.buts.can configure -font $uifont
7068 grid $top.buts.ok $top.buts.can
7069 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7070 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7071 grid $top.buts - - -pady 10 -sticky ew
7072 bind $top <Visibility> "focus $top.buts.ok"
7075 proc choosecolor {v vi w x cmd} {
7078 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
7079 -title "Gitk: choose color for $x"]
7080 if {$c eq {}} return
7081 $w conf -background $c
7087 global bglist cflist
7089 $w configure -selectbackground $c
7091 $cflist tag configure highlight \
7092 -background [$cflist cget -selectbackground]
7093 allcanvs itemconf secsel -fill $c
7100 $w conf -background $c
7108 $w conf -foreground $c
7110 allcanvs itemconf text -fill $c
7111 $canv itemconf circle -outline $c
7115 global maxwidth maxgraphpct diffopts
7116 global oldprefs prefstop showneartags showlocalchanges
7118 foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
7119 set $v $oldprefs($v)
7121 catch {destroy $prefstop}
7126 global maxwidth maxgraphpct
7127 global oldprefs prefstop showneartags showlocalchanges
7128 global charspc ctext tabstop
7130 catch {destroy $prefstop}
7132 $ctext configure -tabs "[expr {$tabstop * $charspc}]"
7133 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
7134 if {$showlocalchanges} {
7140 if {$maxwidth != $oldprefs(maxwidth)
7141 || $maxgraphpct != $oldprefs(maxgraphpct)} {
7143 } elseif {$showneartags != $oldprefs(showneartags)} {
7148 proc formatdate {d} {
7150 set d [clock format $d -format "%Y-%m-%d %H:%M:%S"]
7155 # This list of encoding names and aliases is distilled from
7156 # http://www.iana.org/assignments/character-sets.
7157 # Not all of them are supported by Tcl.
7158 set encoding_aliases {
7159 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
7160 ISO646-US US-ASCII us IBM367 cp367 csASCII }
7161 { ISO-10646-UTF-1 csISO10646UTF1 }
7162 { ISO_646.basic:1983 ref csISO646basic1983 }
7163 { INVARIANT csINVARIANT }
7164 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
7165 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
7166 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
7167 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
7168 { NATS-DANO iso-ir-9-1 csNATSDANO }
7169 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
7170 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
7171 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
7172 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
7173 { ISO-2022-KR csISO2022KR }
7175 { ISO-2022-JP csISO2022JP }
7176 { ISO-2022-JP-2 csISO2022JP2 }
7177 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
7179 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
7180 { IT iso-ir-15 ISO646-IT csISO15Italian }
7181 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
7182 { ES iso-ir-17 ISO646-ES csISO17Spanish }
7183 { greek7-old iso-ir-18 csISO18Greek7Old }
7184 { latin-greek iso-ir-19 csISO19LatinGreek }
7185 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
7186 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
7187 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
7188 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
7189 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
7190 { BS_viewdata iso-ir-47 csISO47BSViewdata }
7191 { INIS iso-ir-49 csISO49INIS }
7192 { INIS-8 iso-ir-50 csISO50INIS8 }
7193 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
7194 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
7195 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
7196 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
7197 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
7198 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
7200 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
7201 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
7202 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
7203 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
7204 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
7205 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
7206 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
7207 { greek7 iso-ir-88 csISO88Greek7 }
7208 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
7209 { iso-ir-90 csISO90 }
7210 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
7211 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
7212 csISO92JISC62991984b }
7213 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
7214 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
7215 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
7216 csISO95JIS62291984handadd }
7217 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
7218 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
7219 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
7220 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
7222 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
7223 { T.61-7bit iso-ir-102 csISO102T617bit }
7224 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
7225 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
7226 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
7227 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
7228 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
7229 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
7230 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
7231 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
7232 arabic csISOLatinArabic }
7233 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
7234 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
7235 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
7236 greek greek8 csISOLatinGreek }
7237 { T.101-G2 iso-ir-128 csISO128T101G2 }
7238 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
7240 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
7241 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
7242 { CSN_369103 iso-ir-139 csISO139CSN369103 }
7243 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
7244 { ISO_6937-2-add iso-ir-142 csISOTextComm }
7245 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
7246 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
7247 csISOLatinCyrillic }
7248 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
7249 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
7250 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
7251 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
7252 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
7253 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
7254 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
7255 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
7256 { ISO_10367-box iso-ir-155 csISO10367Box }
7257 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
7258 { latin-lap lap iso-ir-158 csISO158Lap }
7259 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
7260 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
7263 { JIS_X0201 X0201 csHalfWidthKatakana }
7264 { KSC5636 ISO646-KR csKSC5636 }
7265 { ISO-10646-UCS-2 csUnicode }
7266 { ISO-10646-UCS-4 csUCS4 }
7267 { DEC-MCS dec csDECMCS }
7268 { hp-roman8 roman8 r8 csHPRoman8 }
7269 { macintosh mac csMacintosh }
7270 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
7272 { IBM038 EBCDIC-INT cp038 csIBM038 }
7273 { IBM273 CP273 csIBM273 }
7274 { IBM274 EBCDIC-BE CP274 csIBM274 }
7275 { IBM275 EBCDIC-BR cp275 csIBM275 }
7276 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
7277 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
7278 { IBM280 CP280 ebcdic-cp-it csIBM280 }
7279 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
7280 { IBM284 CP284 ebcdic-cp-es csIBM284 }
7281 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
7282 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
7283 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
7284 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
7285 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
7286 { IBM424 cp424 ebcdic-cp-he csIBM424 }
7287 { IBM437 cp437 437 csPC8CodePage437 }
7288 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
7289 { IBM775 cp775 csPC775Baltic }
7290 { IBM850 cp850 850 csPC850Multilingual }
7291 { IBM851 cp851 851 csIBM851 }
7292 { IBM852 cp852 852 csPCp852 }
7293 { IBM855 cp855 855 csIBM855 }
7294 { IBM857 cp857 857 csIBM857 }
7295 { IBM860 cp860 860 csIBM860 }
7296 { IBM861 cp861 861 cp-is csIBM861 }
7297 { IBM862 cp862 862 csPC862LatinHebrew }
7298 { IBM863 cp863 863 csIBM863 }
7299 { IBM864 cp864 csIBM864 }
7300 { IBM865 cp865 865 csIBM865 }
7301 { IBM866 cp866 866 csIBM866 }
7302 { IBM868 CP868 cp-ar csIBM868 }
7303 { IBM869 cp869 869 cp-gr csIBM869 }
7304 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
7305 { IBM871 CP871 ebcdic-cp-is csIBM871 }
7306 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
7307 { IBM891 cp891 csIBM891 }
7308 { IBM903 cp903 csIBM903 }
7309 { IBM904 cp904 904 csIBBM904 }
7310 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
7311 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
7312 { IBM1026 CP1026 csIBM1026 }
7313 { EBCDIC-AT-DE csIBMEBCDICATDE }
7314 { EBCDIC-AT-DE-A csEBCDICATDEA }
7315 { EBCDIC-CA-FR csEBCDICCAFR }
7316 { EBCDIC-DK-NO csEBCDICDKNO }
7317 { EBCDIC-DK-NO-A csEBCDICDKNOA }
7318 { EBCDIC-FI-SE csEBCDICFISE }
7319 { EBCDIC-FI-SE-A csEBCDICFISEA }
7320 { EBCDIC-FR csEBCDICFR }
7321 { EBCDIC-IT csEBCDICIT }
7322 { EBCDIC-PT csEBCDICPT }
7323 { EBCDIC-ES csEBCDICES }
7324 { EBCDIC-ES-A csEBCDICESA }
7325 { EBCDIC-ES-S csEBCDICESS }
7326 { EBCDIC-UK csEBCDICUK }
7327 { EBCDIC-US csEBCDICUS }
7328 { UNKNOWN-8BIT csUnknown8BiT }
7329 { MNEMONIC csMnemonic }
7334 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
7335 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
7336 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
7337 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
7338 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
7339 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
7340 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
7341 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
7342 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
7343 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
7344 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
7345 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
7346 { IBM1047 IBM-1047 }
7347 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
7348 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
7349 { UNICODE-1-1 csUnicode11 }
7352 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
7353 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
7355 { ISO-8859-15 ISO_8859-15 Latin-9 }
7356 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
7357 { GBK CP936 MS936 windows-936 }
7358 { JIS_Encoding csJISEncoding }
7359 { Shift_JIS MS_Kanji csShiftJIS }
7360 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
7362 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
7363 { ISO-10646-UCS-Basic csUnicodeASCII }
7364 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
7365 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
7366 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
7367 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
7368 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
7369 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
7370 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
7371 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
7372 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
7373 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
7374 { Adobe-Standard-Encoding csAdobeStandardEncoding }
7375 { Ventura-US csVenturaUS }
7376 { Ventura-International csVenturaInternational }
7377 { PC8-Danish-Norwegian csPC8DanishNorwegian }
7378 { PC8-Turkish csPC8Turkish }
7379 { IBM-Symbols csIBMSymbols }
7380 { IBM-Thai csIBMThai }
7381 { HP-Legal csHPLegal }
7382 { HP-Pi-font csHPPiFont }
7383 { HP-Math8 csHPMath8 }
7384 { Adobe-Symbol-Encoding csHPPSMath }
7385 { HP-DeskTop csHPDesktop }
7386 { Ventura-Math csVenturaMath }
7387 { Microsoft-Publishing csMicrosoftPublishing }
7388 { Windows-31J csWindows31J }
7393 proc tcl_encoding {enc} {
7394 global encoding_aliases
7395 set names [encoding names]
7396 set lcnames [string tolower $names]
7397 set enc [string tolower $enc]
7398 set i [lsearch -exact $lcnames $enc]
7400 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
7401 if {[regsub {^iso[-_]} $enc iso encx]} {
7402 set i [lsearch -exact $lcnames $encx]
7406 foreach l $encoding_aliases {
7407 set ll [string tolower $l]
7408 if {[lsearch -exact $ll $enc] < 0} continue
7409 # look through the aliases for one that tcl knows about
7411 set i [lsearch -exact $lcnames $e]
7413 if {[regsub {^iso[-_]} $e iso ex]} {
7414 set i [lsearch -exact $lcnames $ex]
7423 return [lindex $names $i]
7430 set diffopts "-U 5 -p"
7431 set wrcomcmd "git diff-tree --stdin -p --pretty"
7435 set gitencoding [exec git config --get i18n.commitencoding]
7437 if {$gitencoding == ""} {
7438 set gitencoding "utf-8"
7440 set tclencoding [tcl_encoding $gitencoding]
7441 if {$tclencoding == {}} {
7442 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
7445 set mainfont {Helvetica 9}
7446 set textfont {Courier 9}
7447 set uifont {Helvetica 9 bold}
7449 set findmergefiles 0
7457 set cmitmode "patch"
7458 set wrapcomment "none"
7462 set showlocalchanges 1
7464 set colors {green red blue magenta darkgrey brown orange}
7467 set diffcolors {red "#00a000" blue}
7468 set selectbgcolor gray85
7470 catch {source ~/.gitk}
7472 font create optionfont -family sans-serif -size -12
7476 switch -regexp -- $arg {
7478 "^-d" { set datemode 1 }
7480 lappend revtreeargs $arg
7485 # check that we can find a .git directory somewhere...
7487 if {![file isdirectory $gitdir]} {
7488 show_error {} . "Cannot find the git directory \"$gitdir\"."
7492 set cmdline_files {}
7493 set i [lsearch -exact $revtreeargs "--"]
7495 set cmdline_files [lrange $revtreeargs [expr {$i + 1}] end]
7496 set revtreeargs [lrange $revtreeargs 0 [expr {$i - 1}]]
7497 } elseif {$revtreeargs ne {}} {
7499 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
7500 set cmdline_files [split $f "\n"]
7501 set n [llength $cmdline_files]
7502 set revtreeargs [lrange $revtreeargs 0 end-$n]
7504 # unfortunately we get both stdout and stderr in $err,
7505 # so look for "fatal:".
7506 set i [string first "fatal:" $err]
7508 set err [string range $err [expr {$i + 6}] end]
7510 show_error {} . "Bad arguments to gitk:\n$err"
7515 set nullid "0000000000000000000000000000000000000000"
7522 set highlight_paths {}
7523 set searchdirn -forwards
7527 set markingmatches 0
7534 set selectedhlview None
7543 set lookingforhead 0
7548 wm title . "[file tail $argv0]: [file tail [pwd]]"
7551 if {$cmdline_files ne {} || $revtreeargs ne {}} {
7552 # create a view for the files/dirs specified on the command line
7556 set viewname(1) "Command line"
7557 set viewfiles(1) $cmdline_files
7558 set viewargs(1) $revtreeargs
7561 .bar.view entryconf Edit* -state normal
7562 .bar.view entryconf Delete* -state normal
7565 if {[info exists permviews]} {
7566 foreach v $permviews {
7569 set viewname($n) [lindex $v 0]
7570 set viewfiles($n) [lindex $v 1]
7571 set viewargs($n) [lindex $v 2]