2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
12 if {[info exists env(GIT_DIR)]} {
19 proc start_rev_list {} {
20 global startmsecs nextupdate ncmupdate
21 global commfd leftover tclencoding datemode
22 global revtreeargs curview viewfiles
24 set startmsecs [clock clicks -milliseconds]
25 set nextupdate [expr {$startmsecs + 100}]
29 if {$viewfiles($curview) ne {}} {
30 set args [concat $args "--" $viewfiles($curview)]
32 set order "--topo-order"
34 set order "--date-order"
37 set commfd [open [concat | git-rev-list --header $order \
38 --parents --boundary --default HEAD $args] r]
40 puts stderr "Error executing git-rev-list: $err"
44 fconfigure $commfd -blocking 0 -translation lf
45 if {$tclencoding != {}} {
46 fconfigure $commfd -encoding $tclencoding
48 fileevent $commfd readable [list getcommitlines $commfd]
49 . config -cursor watch
53 proc stop_rev_list {} {
56 if {![info exists commfd]} return
66 global phase canv mainfont
71 $canv create text 3 3 -anchor nw -text "Reading commits..." \
72 -font $mainfont -tags textitems
75 proc getcommitlines {commfd} {
76 global commitlisted nextupdate
78 global displayorder commitidx commitrow commitdata
79 global parentlist childlist children
81 set stuff [read $commfd]
83 if {![eof $commfd]} return
84 # set it blocking so we wait for the process to terminate
85 fconfigure $commfd -blocking 1
86 if {![catch {close $commfd} err]} {
87 after idle finishcommits
90 if {[string range $err 0 4] == "usage"} {
92 "Gitk: error reading commits: bad arguments to git-rev-list.\
93 (Note: arguments to gitk are passed to git-rev-list\
94 to allow selection of commits to be displayed.)"
96 set err "Error reading commits: $err"
104 set i [string first "\0" $stuff $start]
106 append leftover [string range $stuff $start end]
111 append cmit [string range $stuff 0 [expr {$i - 1}]]
114 set cmit [string range $stuff $start [expr {$i - 1}]]
116 set start [expr {$i + 1}]
117 set j [string first "\n" $cmit]
121 set ids [string range $cmit 0 [expr {$j - 1}]]
122 if {[string range $ids 0 0] == "-"} {
124 set ids [string range $ids 1 end]
128 if {[string length $id] != 40} {
136 if {[string length $shortcmit] > 80} {
137 set shortcmit "[string range $shortcmit 0 80]..."
139 error_popup "Can't parse git-rev-list output: {$shortcmit}"
142 set id [lindex $ids 0]
144 set olds [lrange $ids 1 end]
147 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
148 lappend children($p) $id
155 lappend parentlist $olds
156 if {[info exists children($id)]} {
157 lappend childlist $children($id)
162 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
163 set commitrow($id) $commitidx
165 lappend displayorder $id
166 lappend commitlisted $listed
172 if {[clock clicks -milliseconds] >= $nextupdate} {
177 proc doupdate {reading} {
178 global commfd nextupdate numcommits ncmupdate
181 fileevent $commfd readable {}
184 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
185 if {$numcommits < 100} {
186 set ncmupdate [expr {$numcommits + 1}]
187 } elseif {$numcommits < 10000} {
188 set ncmupdate [expr {$numcommits + 10}]
190 set ncmupdate [expr {$numcommits + 100}]
193 fileevent $commfd readable [list getcommitlines $commfd]
197 proc readcommit {id} {
198 if {[catch {set contents [exec git-cat-file commit $id]}]} return
199 parsecommit $id $contents 0
202 proc updatecommits {} {
203 global viewdata curview revtreeargs phase
211 catch {unset viewdata($n)}
216 proc parsecommit {id contents listed} {
217 global commitinfo cdate
226 set hdrend [string first "\n\n" $contents]
228 # should never happen...
229 set hdrend [string length $contents]
231 set header [string range $contents 0 [expr {$hdrend - 1}]]
232 set comment [string range $contents [expr {$hdrend + 2}] end]
233 foreach line [split $header "\n"] {
234 set tag [lindex $line 0]
235 if {$tag == "author"} {
236 set audate [lindex $line end-1]
237 set auname [lrange $line 1 end-2]
238 } elseif {$tag == "committer"} {
239 set comdate [lindex $line end-1]
240 set comname [lrange $line 1 end-2]
244 # take the first line of the comment as the headline
245 set i [string first "\n" $comment]
247 set headline [string trim [string range $comment 0 $i]]
249 set headline $comment
252 # git-rev-list indents the comment by 4 spaces;
253 # if we got this via git-cat-file, add the indentation
255 foreach line [split $comment "\n"] {
256 append newcomment " "
257 append newcomment $line
258 append newcomment "\n"
260 set comment $newcomment
262 if {$comdate != {}} {
263 set cdate($id) $comdate
265 set commitinfo($id) [list $headline $auname $audate \
266 $comname $comdate $comment]
269 proc getcommit {id} {
270 global commitdata commitinfo
272 if {[info exists commitdata($id)]} {
273 parsecommit $id $commitdata($id) 1
276 if {![info exists commitinfo($id)]} {
277 set commitinfo($id) {"No commit information available"}
284 global tagids idtags headids idheads tagcontents
285 global otherrefids idotherrefs
287 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
290 set refd [open [list | git ls-remote [gitdir]] r]
291 while {0 <= [set n [gets $refd line]]} {
292 if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
296 if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
300 if {$type == "tags"} {
301 set tagids($name) $id
302 lappend idtags($id) $name
307 set commit [exec git-rev-parse "$id^0"]
308 if {"$commit" != "$id"} {
309 set tagids($name) $commit
310 lappend idtags($commit) $name
314 set tagcontents($name) [exec git-cat-file tag "$id"]
316 } elseif { $type == "heads" } {
317 set headids($name) $id
318 lappend idheads($id) $name
320 set otherrefids($name) $id
321 lappend idotherrefs($id) $name
327 proc error_popup msg {
331 message $w.m -text $msg -justify center -aspect 400
332 pack $w.m -side top -fill x -padx 20 -pady 20
333 button $w.ok -text OK -command "destroy $w"
334 pack $w.ok -side bottom -fill x
335 bind $w <Visibility> "grab $w; focus $w"
336 bind $w <Key-Return> "destroy $w"
341 global canv canv2 canv3 linespc charspc ctext cflist
342 global textfont mainfont uifont
343 global findtype findtypemenu findloc findstring fstring geometry
344 global entries sha1entry sha1string sha1but
345 global maincursor textcursor curtextcursor
346 global rowctxmenu mergemax
349 .bar add cascade -label "File" -menu .bar.file
350 .bar configure -font $uifont
352 .bar.file add command -label "Update" -command updatecommits
353 .bar.file add command -label "Reread references" -command rereadrefs
354 .bar.file add command -label "Quit" -command doquit
355 .bar.file configure -font $uifont
357 .bar add cascade -label "Edit" -menu .bar.edit
358 .bar.edit add command -label "Preferences" -command doprefs
359 .bar.edit configure -font $uifont
360 menu .bar.view -font $uifont
361 .bar add cascade -label "View" -menu .bar.view
362 .bar.view add command -label "New view..." -command newview
363 .bar.view add command -label "Delete view" -command delview -state disabled
364 .bar.view add separator
365 .bar.view add command -label "All files" -command {showview 0}
367 .bar add cascade -label "Help" -menu .bar.help
368 .bar.help add command -label "About gitk" -command about
369 .bar.help add command -label "Key bindings" -command keys
370 .bar.help configure -font $uifont
371 . configure -menu .bar
373 if {![info exists geometry(canv1)]} {
374 set geometry(canv1) [expr {45 * $charspc}]
375 set geometry(canv2) [expr {30 * $charspc}]
376 set geometry(canv3) [expr {15 * $charspc}]
377 set geometry(canvh) [expr {25 * $linespc + 4}]
378 set geometry(ctextw) 80
379 set geometry(ctexth) 30
380 set geometry(cflistw) 30
382 panedwindow .ctop -orient vertical
383 if {[info exists geometry(width)]} {
384 .ctop conf -width $geometry(width) -height $geometry(height)
385 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
386 set geometry(ctexth) [expr {($texth - 8) /
387 [font metrics $textfont -linespace]}]
391 pack .ctop.top.bar -side bottom -fill x
392 set cscroll .ctop.top.csb
393 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
394 pack $cscroll -side right -fill y
395 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
396 pack .ctop.top.clist -side top -fill both -expand 1
398 set canv .ctop.top.clist.canv
399 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
401 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
402 .ctop.top.clist add $canv
403 set canv2 .ctop.top.clist.canv2
404 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
405 -bg white -bd 0 -yscrollincr $linespc
406 .ctop.top.clist add $canv2
407 set canv3 .ctop.top.clist.canv3
408 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
409 -bg white -bd 0 -yscrollincr $linespc
410 .ctop.top.clist add $canv3
411 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
413 set sha1entry .ctop.top.bar.sha1
414 set entries $sha1entry
415 set sha1but .ctop.top.bar.sha1label
416 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
417 -command gotocommit -width 8 -font $uifont
418 $sha1but conf -disabledforeground [$sha1but cget -foreground]
419 pack .ctop.top.bar.sha1label -side left
420 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
421 trace add variable sha1string write sha1change
422 pack $sha1entry -side left -pady 2
424 image create bitmap bm-left -data {
425 #define left_width 16
426 #define left_height 16
427 static unsigned char left_bits[] = {
428 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
429 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
430 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
432 image create bitmap bm-right -data {
433 #define right_width 16
434 #define right_height 16
435 static unsigned char right_bits[] = {
436 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
437 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
438 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
440 button .ctop.top.bar.leftbut -image bm-left -command goback \
441 -state disabled -width 26
442 pack .ctop.top.bar.leftbut -side left -fill y
443 button .ctop.top.bar.rightbut -image bm-right -command goforw \
444 -state disabled -width 26
445 pack .ctop.top.bar.rightbut -side left -fill y
447 button .ctop.top.bar.findbut -text "Find" -command dofind -font $uifont
448 pack .ctop.top.bar.findbut -side left
450 set fstring .ctop.top.bar.findstring
451 lappend entries $fstring
452 entry $fstring -width 30 -font $textfont -textvariable findstring -font $textfont
453 pack $fstring -side left -expand 1 -fill x
455 set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
456 findtype Exact IgnCase Regexp]
457 .ctop.top.bar.findtype configure -font $uifont
458 .ctop.top.bar.findtype.menu configure -font $uifont
459 set findloc "All fields"
460 tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
461 Comments Author Committer Files Pickaxe
462 .ctop.top.bar.findloc configure -font $uifont
463 .ctop.top.bar.findloc.menu configure -font $uifont
465 pack .ctop.top.bar.findloc -side right
466 pack .ctop.top.bar.findtype -side right
467 # for making sure type==Exact whenever loc==Pickaxe
468 trace add variable findloc write findlocchange
470 panedwindow .ctop.cdet -orient horizontal
472 frame .ctop.cdet.left
473 set ctext .ctop.cdet.left.ctext
474 text $ctext -bg white -state disabled -font $textfont \
475 -width $geometry(ctextw) -height $geometry(ctexth) \
476 -yscrollcommand ".ctop.cdet.left.sb set" -wrap none
477 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
478 pack .ctop.cdet.left.sb -side right -fill y
479 pack $ctext -side left -fill both -expand 1
480 .ctop.cdet add .ctop.cdet.left
482 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
483 $ctext tag conf hunksep -fore blue
484 $ctext tag conf d0 -fore red
485 $ctext tag conf d1 -fore "#00a000"
486 $ctext tag conf m0 -fore red
487 $ctext tag conf m1 -fore blue
488 $ctext tag conf m2 -fore green
489 $ctext tag conf m3 -fore purple
490 $ctext tag conf m4 -fore brown
491 $ctext tag conf m5 -fore "#009090"
492 $ctext tag conf m6 -fore magenta
493 $ctext tag conf m7 -fore "#808000"
494 $ctext tag conf m8 -fore "#009000"
495 $ctext tag conf m9 -fore "#ff0080"
496 $ctext tag conf m10 -fore cyan
497 $ctext tag conf m11 -fore "#b07070"
498 $ctext tag conf m12 -fore "#70b0f0"
499 $ctext tag conf m13 -fore "#70f0b0"
500 $ctext tag conf m14 -fore "#f0b070"
501 $ctext tag conf m15 -fore "#ff70b0"
502 $ctext tag conf mmax -fore darkgrey
504 $ctext tag conf mresult -font [concat $textfont bold]
505 $ctext tag conf msep -font [concat $textfont bold]
506 $ctext tag conf found -back yellow
508 frame .ctop.cdet.right
509 set cflist .ctop.cdet.right.cfiles
510 listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
511 -yscrollcommand ".ctop.cdet.right.sb set" -font $mainfont
512 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
513 pack .ctop.cdet.right.sb -side right -fill y
514 pack $cflist -side left -fill both -expand 1
515 .ctop.cdet add .ctop.cdet.right
516 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
518 pack .ctop -side top -fill both -expand 1
520 bindall <1> {selcanvline %W %x %y}
521 #bindall <B1-Motion> {selcanvline %W %x %y}
522 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
523 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
524 bindall <2> "canvscan mark %W %x %y"
525 bindall <B2-Motion> "canvscan dragto %W %x %y"
526 bindkey <Home> selfirstline
527 bindkey <End> sellastline
528 bind . <Key-Up> "selnextline -1"
529 bind . <Key-Down> "selnextline 1"
530 bindkey <Key-Right> "goforw"
531 bindkey <Key-Left> "goback"
532 bind . <Key-Prior> "selnextpage -1"
533 bind . <Key-Next> "selnextpage 1"
534 bind . <Control-Home> "allcanvs yview moveto 0.0"
535 bind . <Control-End> "allcanvs yview moveto 1.0"
536 bind . <Control-Key-Up> "allcanvs yview scroll -1 units"
537 bind . <Control-Key-Down> "allcanvs yview scroll 1 units"
538 bind . <Control-Key-Prior> "allcanvs yview scroll -1 pages"
539 bind . <Control-Key-Next> "allcanvs yview scroll 1 pages"
540 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
541 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
542 bindkey <Key-space> "$ctext yview scroll 1 pages"
543 bindkey p "selnextline -1"
544 bindkey n "selnextline 1"
547 bindkey i "selnextline -1"
548 bindkey k "selnextline 1"
551 bindkey b "$ctext yview scroll -1 pages"
552 bindkey d "$ctext yview scroll 18 units"
553 bindkey u "$ctext yview scroll -18 units"
554 bindkey / {findnext 1}
555 bindkey <Key-Return> {findnext 0}
558 bind . <Control-q> doquit
559 bind . <Control-f> dofind
560 bind . <Control-g> {findnext 0}
561 bind . <Control-r> findprev
562 bind . <Control-equal> {incrfont 1}
563 bind . <Control-KP_Add> {incrfont 1}
564 bind . <Control-minus> {incrfont -1}
565 bind . <Control-KP_Subtract> {incrfont -1}
566 bind $cflist <<ListboxSelect>> listboxsel
567 bind . <Destroy> {savestuff %W}
568 bind . <Button-1> "click %W"
569 bind $fstring <Key-Return> dofind
570 bind $sha1entry <Key-Return> gotocommit
571 bind $sha1entry <<PasteSelection>> clearsha1
573 set maincursor [. cget -cursor]
574 set textcursor [$ctext cget -cursor]
575 set curtextcursor $textcursor
577 set rowctxmenu .rowctxmenu
578 menu $rowctxmenu -tearoff 0
579 $rowctxmenu add command -label "Diff this -> selected" \
580 -command {diffvssel 0}
581 $rowctxmenu add command -label "Diff selected -> this" \
582 -command {diffvssel 1}
583 $rowctxmenu add command -label "Make patch" -command mkpatch
584 $rowctxmenu add command -label "Create tag" -command mktag
585 $rowctxmenu add command -label "Write commit to file" -command writecommit
588 # mouse-2 makes all windows scan vertically, but only the one
589 # the cursor is in scans horizontally
590 proc canvscan {op w x y} {
591 global canv canv2 canv3
592 foreach c [list $canv $canv2 $canv3] {
601 proc scrollcanv {cscroll f0 f1} {
606 # when we make a key binding for the toplevel, make sure
607 # it doesn't get triggered when that key is pressed in the
608 # find string entry widget.
609 proc bindkey {ev script} {
612 set escript [bind Entry $ev]
613 if {$escript == {}} {
614 set escript [bind Entry <Key>]
617 bind $e $ev "$escript; break"
621 # set the focus back to the toplevel for any click outside
632 global canv canv2 canv3 ctext cflist mainfont textfont uifont
633 global stuffsaved findmergefiles maxgraphpct
636 if {$stuffsaved} return
637 if {![winfo viewable .]} return
639 set f [open "~/.gitk-new" w]
640 puts $f [list set mainfont $mainfont]
641 puts $f [list set textfont $textfont]
642 puts $f [list set uifont $uifont]
643 puts $f [list set findmergefiles $findmergefiles]
644 puts $f [list set maxgraphpct $maxgraphpct]
645 puts $f [list set maxwidth $maxwidth]
646 puts $f "set geometry(width) [winfo width .ctop]"
647 puts $f "set geometry(height) [winfo height .ctop]"
648 puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
649 puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]"
650 puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]"
651 puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]"
652 set wid [expr {([winfo width $ctext] - 8) \
653 / [font measure $textfont "0"]}]
654 puts $f "set geometry(ctextw) $wid"
655 set wid [expr {([winfo width $cflist] - 11) \
656 / [font measure [$cflist cget -font] "0"]}]
657 puts $f "set geometry(cflistw) $wid"
659 file rename -force "~/.gitk-new" "~/.gitk"
664 proc resizeclistpanes {win w} {
666 if {[info exists oldwidth($win)]} {
667 set s0 [$win sash coord 0]
668 set s1 [$win sash coord 1]
670 set sash0 [expr {int($w/2 - 2)}]
671 set sash1 [expr {int($w*5/6 - 2)}]
673 set factor [expr {1.0 * $w / $oldwidth($win)}]
674 set sash0 [expr {int($factor * [lindex $s0 0])}]
675 set sash1 [expr {int($factor * [lindex $s1 0])}]
679 if {$sash1 < $sash0 + 20} {
680 set sash1 [expr {$sash0 + 20}]
682 if {$sash1 > $w - 10} {
683 set sash1 [expr {$w - 10}]
684 if {$sash0 > $sash1 - 20} {
685 set sash0 [expr {$sash1 - 20}]
689 $win sash place 0 $sash0 [lindex $s0 1]
690 $win sash place 1 $sash1 [lindex $s1 1]
692 set oldwidth($win) $w
695 proc resizecdetpanes {win w} {
697 if {[info exists oldwidth($win)]} {
698 set s0 [$win sash coord 0]
700 set sash0 [expr {int($w*3/4 - 2)}]
702 set factor [expr {1.0 * $w / $oldwidth($win)}]
703 set sash0 [expr {int($factor * [lindex $s0 0])}]
707 if {$sash0 > $w - 15} {
708 set sash0 [expr {$w - 15}]
711 $win sash place 0 $sash0 [lindex $s0 1]
713 set oldwidth($win) $w
717 global canv canv2 canv3
723 proc bindall {event action} {
724 global canv canv2 canv3
725 bind $canv $event $action
726 bind $canv2 $event $action
727 bind $canv3 $event $action
732 if {[winfo exists $w]} {
737 wm title $w "About gitk"
739 Gitk - a commit viewer for git
741 Copyright © 2005-2006 Paul Mackerras
743 Use and redistribute under the terms of the GNU General Public License} \
744 -justify center -aspect 400
745 pack $w.m -side top -fill x -padx 20 -pady 20
746 button $w.ok -text Close -command "destroy $w"
747 pack $w.ok -side bottom
752 if {[winfo exists $w]} {
757 wm title $w "Gitk key bindings"
762 <Home> Move to first commit
763 <End> Move to last commit
764 <Up>, p, i Move up one commit
765 <Down>, n, k Move down one commit
766 <Left>, z, j Go back in history list
767 <Right>, x, l Go forward in history list
768 <PageUp> Move up one page in commit list
769 <PageDown> Move down one page in commit list
770 <Ctrl-Home> Scroll to top of commit list
771 <Ctrl-End> Scroll to bottom of commit list
772 <Ctrl-Up> Scroll commit list up one line
773 <Ctrl-Down> Scroll commit list down one line
774 <Ctrl-PageUp> Scroll commit list up one page
775 <Ctrl-PageDown> Scroll commit list down one page
776 <Delete>, b Scroll diff view up one page
777 <Backspace> Scroll diff view up one page
778 <Space> Scroll diff view down one page
779 u Scroll diff view up 18 lines
780 d Scroll diff view down 18 lines
782 <Ctrl-G> Move to next find hit
783 <Ctrl-R> Move to previous find hit
784 <Return> Move to next find hit
785 / Move to next find hit, or redo find
786 ? Move to previous find hit
787 f Scroll diff view to next file
788 <Ctrl-KP+> Increase font size
789 <Ctrl-plus> Increase font size
790 <Ctrl-KP-> Decrease font size
791 <Ctrl-minus> Decrease font size
793 -justify left -bg white -border 2 -relief sunken
794 pack $w.m -side top -fill both
795 button $w.ok -text Close -command "destroy $w"
796 pack $w.ok -side bottom
800 global newviewname nextviewnum newviewtop
803 if {[winfo exists $top]} {
809 wm title $top "Gitk view definition"
810 label $top.nl -text "Name"
811 entry $top.name -width 20 -textvariable newviewname
812 set newviewname "View $nextviewnum"
813 grid $top.nl $top.name -sticky w
814 label $top.l -text "Files and directories to include:"
815 grid $top.l - -sticky w -pady 10
816 text $top.t -width 30 -height 10
817 grid $top.t - -sticky w
819 button $top.buts.ok -text "OK" -command newviewok
820 button $top.buts.can -text "Cancel" -command newviewcan
821 grid $top.buts.ok $top.buts.can
822 grid columnconfigure $top.buts 0 -weight 1 -uniform a
823 grid columnconfigure $top.buts 1 -weight 1 -uniform a
824 grid $top.buts - -pady 10 -sticky ew
829 global newviewtop nextviewnum
830 global viewname viewfiles
834 set viewname($n) [$newviewtop.name get]
836 foreach f [split [$newviewtop.t get 0.0 end] "\n"] {
837 set ft [string trim $f]
842 set viewfiles($n) $files
843 catch {destroy $newviewtop}
845 .bar.view add command -label $viewname($n) -command [list showview $n]
846 after idle showview $n
852 catch {destroy $newviewtop}
857 global curview viewdata
859 if {$curview == 0} return
860 set nmenu [.bar.view index end]
861 set targetcmd [list showview $curview]
862 for {set i 5} {$i <= $nmenu} {incr i} {
863 if {[.bar.view entrycget $i -command] eq $targetcmd} {
868 set viewdata($curview) {}
876 foreach i [array names $var] {
877 lappend ret $i [set $var\($i\)]
882 proc unflatten {var l} {
892 global curview viewdata viewfiles
893 global displayorder parentlist childlist rowidlist rowoffsets
894 global colormap rowtextx commitrow
895 global numcommits rowrangelist commitlisted idrowranges
896 global selectedline currentid canv canvy0
897 global matchinglines treediffs
898 global pending_select phase
899 global commitidx rowlaidout rowoptim linesegends leftover
900 global commfd nextupdate
902 if {$n == $curview} return
904 if {[info exists selectedline]} {
906 set y [yc $selectedline]
907 set ymax [lindex [$canv cget -scrollregion] 3]
908 set span [$canv yview]
909 set ytop [expr {[lindex $span 0] * $ymax}]
910 set ybot [expr {[lindex $span 1] * $ymax}]
911 if {$ytop < $y && $y < $ybot} {
912 set yscreen [expr {$y - $ytop}]
914 set yscreen [expr {($ybot - $ytop) / 2}]
922 set viewdata($curview) \
923 [list $phase $displayorder $parentlist $childlist $rowidlist \
924 $rowoffsets $rowrangelist $commitlisted \
925 [flatten children] [flatten idrowranges] \
927 $commitidx $rowlaidout $rowoptim $numcommits \
928 $linesegends $leftover $commfd]
929 fileevent $commfd readable {}
930 } elseif {![info exists viewdata($curview)]
931 || [lindex $viewdata($curview) 0] ne {}} {
932 set viewdata($curview) \
933 [list {} $displayorder $parentlist $childlist $rowidlist \
934 $rowoffsets $rowrangelist $commitlisted]
937 catch {unset matchinglines}
938 catch {unset treediffs}
942 .bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}]
944 if {![info exists viewdata($n)]} {
945 set pending_select $selid
951 set phase [lindex $v 0]
952 set displayorder [lindex $v 1]
953 set parentlist [lindex $v 2]
954 set childlist [lindex $v 3]
955 set rowidlist [lindex $v 4]
956 set rowoffsets [lindex $v 5]
957 set rowrangelist [lindex $v 6]
958 set commitlisted [lindex $v 7]
960 set numcommits [llength $displayorder]
961 catch {unset idrowranges}
962 catch {unset children}
964 unflatten children [lindex $v 8]
965 unflatten idrowranges [lindex $v 9]
966 unflatten idinlist [lindex $v 10]
967 set commitidx [lindex $v 11]
968 set rowlaidout [lindex $v 12]
969 set rowoptim [lindex $v 13]
970 set numcommits [lindex $v 14]
971 set linesegends [lindex $v 15]
972 set leftover [lindex $v 16]
973 set commfd [lindex $v 17]
974 fileevent $commfd readable [list getcommitlines $commfd]
975 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
978 catch {unset colormap}
979 catch {unset rowtextx}
980 catch {unset commitrow}
983 foreach id $displayorder {
984 set commitrow($id) $row
990 if {$selid ne {} && [info exists commitrow($selid)]} {
991 set row $commitrow($selid)
992 # try to get the selected row in the same position on the screen
993 set ymax [lindex [$canv cget -scrollregion] 3]
994 set ytop [expr {[yc $row] - $yscreen}]
998 set yf [expr {$ytop * 1.0 / $ymax}]
1000 allcanvs yview moveto $yf
1004 global maincursor textcursor
1005 . config -cursor $maincursor
1006 settextcursor $textcursor
1008 . config -cursor watch
1013 proc shortids {ids} {
1016 if {[llength $id] > 1} {
1017 lappend res [shortids $id]
1018 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
1019 lappend res [string range $id 0 7]
1027 proc incrange {l x o} {
1030 set e [lindex $l $x]
1032 lset l $x [expr {$e + $o}]
1041 for {} {$n > 0} {incr n -1} {
1047 proc usedinrange {id l1 l2} {
1048 global children commitrow childlist
1050 if {[info exists commitrow($id)]} {
1051 set r $commitrow($id)
1052 if {$l1 <= $r && $r <= $l2} {
1053 return [expr {$r - $l1 + 1}]
1055 set kids [lindex $childlist $r]
1057 set kids $children($id)
1060 set r $commitrow($c)
1061 if {$l1 <= $r && $r <= $l2} {
1062 return [expr {$r - $l1 + 1}]
1068 proc sanity {row {full 0}} {
1069 global rowidlist rowoffsets
1072 set ids [lindex $rowidlist $row]
1075 if {$id eq {}} continue
1076 if {$col < [llength $ids] - 1 &&
1077 [lsearch -exact -start [expr {$col+1}] $ids $id] >= 0} {
1078 puts "oops: [shortids $id] repeated in row $row col $col: {[shortids [lindex $rowidlist $row]]}"
1080 set o [lindex $rowoffsets $row $col]
1086 if {[lindex $rowidlist $y $x] != $id} {
1087 puts "oops: rowoffsets wrong at row [expr {$y+1}] col [expr {$x-$o}]"
1088 puts " id=[shortids $id] check started at row $row"
1089 for {set i $row} {$i >= $y} {incr i -1} {
1090 puts " row $i ids={[shortids [lindex $rowidlist $i]]} offs={[lindex $rowoffsets $i]}"
1095 set o [lindex $rowoffsets $y $x]
1100 proc makeuparrow {oid x y z} {
1101 global rowidlist rowoffsets uparrowlen idrowranges
1103 for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
1106 set off0 [lindex $rowoffsets $y]
1107 for {set x0 $x} {1} {incr x0} {
1108 if {$x0 >= [llength $off0]} {
1109 set x0 [llength [lindex $rowoffsets [expr {$y-1}]]]
1112 set z [lindex $off0 $x0]
1118 set z [expr {$x0 - $x}]
1119 lset rowidlist $y [linsert [lindex $rowidlist $y] $x $oid]
1120 lset rowoffsets $y [linsert [lindex $rowoffsets $y] $x $z]
1122 set tmp [lreplace [lindex $rowoffsets $y] $x $x {}]
1123 lset rowoffsets $y [incrange $tmp [expr {$x+1}] -1]
1124 lappend idrowranges($oid) $y
1127 proc initlayout {} {
1128 global rowidlist rowoffsets displayorder commitlisted
1129 global rowlaidout rowoptim
1130 global idinlist rowchk rowrangelist idrowranges
1131 global commitidx numcommits canvxmax canv
1133 global parentlist childlist children
1134 global colormap rowtextx commitrow
1144 catch {unset children}
1148 catch {unset idinlist}
1149 catch {unset rowchk}
1152 set canvxmax [$canv cget -width]
1153 catch {unset colormap}
1154 catch {unset rowtextx}
1155 catch {unset commitrow}
1156 catch {unset idrowranges}
1160 proc setcanvscroll {} {
1161 global canv canv2 canv3 numcommits linespc canvxmax canvy0
1163 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
1164 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
1165 $canv2 conf -scrollregion [list 0 0 0 $ymax]
1166 $canv3 conf -scrollregion [list 0 0 0 $ymax]
1169 proc visiblerows {} {
1170 global canv numcommits linespc
1172 set ymax [lindex [$canv cget -scrollregion] 3]
1173 if {$ymax eq {} || $ymax == 0} return
1175 set y0 [expr {int([lindex $f 0] * $ymax)}]
1176 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
1180 set y1 [expr {int([lindex $f 1] * $ymax)}]
1181 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
1182 if {$r1 >= $numcommits} {
1183 set r1 [expr {$numcommits - 1}]
1185 return [list $r0 $r1]
1188 proc layoutmore {} {
1189 global rowlaidout rowoptim commitidx numcommits optim_delay
1193 set rowlaidout [layoutrows $row $commitidx 0]
1194 set orow [expr {$rowlaidout - $uparrowlen - 1}]
1195 if {$orow > $rowoptim} {
1196 optimize_rows $rowoptim 0 $orow
1199 set canshow [expr {$rowoptim - $optim_delay}]
1200 if {$canshow > $numcommits} {
1205 proc showstuff {canshow} {
1206 global numcommits commitrow pending_select selectedline
1207 global linesegends idrowranges idrangedrawn
1209 if {$numcommits == 0} {
1211 set phase "incrdraw"
1215 set numcommits $canshow
1217 set rows [visiblerows]
1218 set r0 [lindex $rows 0]
1219 set r1 [lindex $rows 1]
1221 for {set r $row} {$r < $canshow} {incr r} {
1222 foreach id [lindex $linesegends [expr {$r+1}]] {
1224 foreach {s e} [rowranges $id] {
1226 if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
1227 && ![info exists idrangedrawn($id,$i)]} {
1229 set idrangedrawn($id,$i) 1
1234 if {$canshow > $r1} {
1237 while {$row < $canshow} {
1241 if {[info exists pending_select] &&
1242 [info exists commitrow($pending_select)] &&
1243 $commitrow($pending_select) < $numcommits} {
1244 selectline $commitrow($pending_select) 1
1246 if {![info exists selectedline] && ![info exists pending_select]} {
1251 proc layoutrows {row endrow last} {
1252 global rowidlist rowoffsets displayorder
1253 global uparrowlen downarrowlen maxwidth mingaplen
1254 global childlist parentlist
1255 global idrowranges linesegends
1257 global idinlist rowchk rowrangelist
1259 set idlist [lindex $rowidlist $row]
1260 set offs [lindex $rowoffsets $row]
1261 while {$row < $endrow} {
1262 set id [lindex $displayorder $row]
1265 foreach p [lindex $parentlist $row] {
1266 if {![info exists idinlist($p)]} {
1268 } elseif {!$idinlist($p)} {
1273 set nev [expr {[llength $idlist] + [llength $newolds]
1274 + [llength $oldolds] - $maxwidth + 1}]
1276 if {!$last && $row + $uparrowlen + $mingaplen >= $commitidx} break
1277 for {set x [llength $idlist]} {[incr x -1] >= 0} {} {
1278 set i [lindex $idlist $x]
1279 if {![info exists rowchk($i)] || $row >= $rowchk($i)} {
1280 set r [usedinrange $i [expr {$row - $downarrowlen}] \
1281 [expr {$row + $uparrowlen + $mingaplen}]]
1283 set idlist [lreplace $idlist $x $x]
1284 set offs [lreplace $offs $x $x]
1285 set offs [incrange $offs $x 1]
1287 set rm1 [expr {$row - 1}]
1289 lappend idrowranges($i) $rm1
1290 if {[incr nev -1] <= 0} break
1293 set rowchk($id) [expr {$row + $r}]
1296 lset rowidlist $row $idlist
1297 lset rowoffsets $row $offs
1299 lappend linesegends $lse
1300 set col [lsearch -exact $idlist $id]
1302 set col [llength $idlist]
1304 lset rowidlist $row $idlist
1306 if {[lindex $childlist $row] ne {}} {
1307 set z [expr {[llength [lindex $rowidlist [expr {$row-1}]]] - $col}]
1311 lset rowoffsets $row $offs
1313 makeuparrow $id $col $row $z
1319 if {[info exists idrowranges($id)]} {
1320 set ranges $idrowranges($id)
1322 unset idrowranges($id)
1324 lappend rowrangelist $ranges
1326 set offs [ntimes [llength $idlist] 0]
1327 set l [llength $newolds]
1328 set idlist [eval lreplace \$idlist $col $col $newolds]
1331 set offs [lrange $offs 0 [expr {$col - 1}]]
1332 foreach x $newolds {
1337 set tmp [expr {[llength $idlist] - [llength $offs]}]
1339 set offs [concat $offs [ntimes $tmp $o]]
1344 foreach i $newolds {
1346 set idrowranges($i) $row
1349 foreach oid $oldolds {
1350 set idinlist($oid) 1
1351 set idlist [linsert $idlist $col $oid]
1352 set offs [linsert $offs $col $o]
1353 makeuparrow $oid $col $row $o
1356 lappend rowidlist $idlist
1357 lappend rowoffsets $offs
1362 proc addextraid {id row} {
1363 global displayorder commitrow commitinfo
1365 global parentlist childlist children
1368 lappend displayorder $id
1369 lappend parentlist {}
1370 set commitrow($id) $row
1372 if {![info exists commitinfo($id)]} {
1373 set commitinfo($id) {"No commit information available"}
1375 if {[info exists children($id)]} {
1376 lappend childlist $children($id)
1379 lappend childlist {}
1383 proc layouttail {} {
1384 global rowidlist rowoffsets idinlist commitidx
1385 global idrowranges rowrangelist
1388 set idlist [lindex $rowidlist $row]
1389 while {$idlist ne {}} {
1390 set col [expr {[llength $idlist] - 1}]
1391 set id [lindex $idlist $col]
1394 lappend idrowranges($id) $row
1395 lappend rowrangelist $idrowranges($id)
1396 unset idrowranges($id)
1398 set offs [ntimes $col 0]
1399 set idlist [lreplace $idlist $col $col]
1400 lappend rowidlist $idlist
1401 lappend rowoffsets $offs
1404 foreach id [array names idinlist] {
1406 lset rowidlist $row [list $id]
1407 lset rowoffsets $row 0
1408 makeuparrow $id 0 $row 0
1409 lappend idrowranges($id) $row
1410 lappend rowrangelist $idrowranges($id)
1411 unset idrowranges($id)
1413 lappend rowidlist {}
1414 lappend rowoffsets {}
1418 proc insert_pad {row col npad} {
1419 global rowidlist rowoffsets
1421 set pad [ntimes $npad {}]
1422 lset rowidlist $row [eval linsert [list [lindex $rowidlist $row]] $col $pad]
1423 set tmp [eval linsert [list [lindex $rowoffsets $row]] $col $pad]
1424 lset rowoffsets $row [incrange $tmp [expr {$col + $npad}] [expr {-$npad}]]
1427 proc optimize_rows {row col endrow} {
1428 global rowidlist rowoffsets idrowranges displayorder
1430 for {} {$row < $endrow} {incr row} {
1431 set idlist [lindex $rowidlist $row]
1432 set offs [lindex $rowoffsets $row]
1434 for {} {$col < [llength $offs]} {incr col} {
1435 if {[lindex $idlist $col] eq {}} {
1439 set z [lindex $offs $col]
1440 if {$z eq {}} continue
1442 set x0 [expr {$col + $z}]
1443 set y0 [expr {$row - 1}]
1444 set z0 [lindex $rowoffsets $y0 $x0]
1446 set id [lindex $idlist $col]
1447 set ranges [rowranges $id]
1448 if {$ranges ne {} && $y0 > [lindex $ranges 0]} {
1452 if {$z < -1 || ($z < 0 && $isarrow)} {
1453 set npad [expr {-1 - $z + $isarrow}]
1454 set offs [incrange $offs $col $npad]
1455 insert_pad $y0 $x0 $npad
1457 optimize_rows $y0 $x0 $row
1459 set z [lindex $offs $col]
1460 set x0 [expr {$col + $z}]
1461 set z0 [lindex $rowoffsets $y0 $x0]
1462 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
1463 set npad [expr {$z - 1 + $isarrow}]
1464 set y1 [expr {$row + 1}]
1465 set offs2 [lindex $rowoffsets $y1]
1469 if {$z eq {} || $x1 + $z < $col} continue
1470 if {$x1 + $z > $col} {
1473 lset rowoffsets $y1 [incrange $offs2 $x1 $npad]
1476 set pad [ntimes $npad {}]
1477 set idlist [eval linsert \$idlist $col $pad]
1478 set tmp [eval linsert \$offs $col $pad]
1480 set offs [incrange $tmp $col [expr {-$npad}]]
1481 set z [lindex $offs $col]
1484 if {$z0 eq {} && !$isarrow} {
1485 # this line links to its first child on row $row-2
1486 set rm2 [expr {$row - 2}]
1487 set id [lindex $displayorder $rm2]
1488 set xc [lsearch -exact [lindex $rowidlist $rm2] $id]
1490 set z0 [expr {$xc - $x0}]
1493 if {$z0 ne {} && $z < 0 && $z0 > 0} {
1494 insert_pad $y0 $x0 1
1495 set offs [incrange $offs $col 1]
1496 optimize_rows $y0 [expr {$x0 + 1}] $row
1501 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
1502 set o [lindex $offs $col]
1504 # check if this is the link to the first child
1505 set id [lindex $idlist $col]
1506 set ranges [rowranges $id]
1507 if {$ranges ne {} && $row == [lindex $ranges 0]} {
1508 # it is, work out offset to child
1509 set y0 [expr {$row - 1}]
1510 set id [lindex $displayorder $y0]
1511 set x0 [lsearch -exact [lindex $rowidlist $y0] $id]
1513 set o [expr {$x0 - $col}]
1517 if {$o eq {} || $o <= 0} break
1519 if {$o ne {} && [incr col] < [llength $idlist]} {
1520 set y1 [expr {$row + 1}]
1521 set offs2 [lindex $rowoffsets $y1]
1525 if {$z eq {} || $x1 + $z < $col} continue
1526 lset rowoffsets $y1 [incrange $offs2 $x1 1]
1529 set idlist [linsert $idlist $col {}]
1530 set tmp [linsert $offs $col {}]
1532 set offs [incrange $tmp $col -1]
1535 lset rowidlist $row $idlist
1536 lset rowoffsets $row $offs
1542 global canvx0 linespc
1543 return [expr {$canvx0 + $col * $linespc}]
1547 global canvy0 linespc
1548 return [expr {$canvy0 + $row * $linespc}]
1551 proc linewidth {id} {
1552 global thickerline lthickness
1555 if {[info exists thickerline] && $id eq $thickerline} {
1556 set wid [expr {2 * $lthickness}]
1561 proc rowranges {id} {
1562 global phase idrowranges commitrow rowlaidout rowrangelist
1566 ([info exists commitrow($id)] && $commitrow($id) < $rowlaidout)} {
1567 set ranges [lindex $rowrangelist $commitrow($id)]
1568 } elseif {[info exists idrowranges($id)]} {
1569 set ranges $idrowranges($id)
1574 proc drawlineseg {id i} {
1575 global rowoffsets rowidlist
1577 global canv colormap linespc
1578 global numcommits commitrow
1580 set ranges [rowranges $id]
1582 if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} {
1583 set downarrow [expr {$i < [llength $ranges] / 2 - 1}]
1587 set startrow [lindex $ranges [expr {2 * $i}]]
1588 set row [lindex $ranges [expr {2 * $i + 1}]]
1589 if {$startrow == $row} return
1592 set col [lsearch -exact [lindex $rowidlist $row] $id]
1594 puts "oops: drawline: id $id not on row $row"
1600 set o [lindex $rowoffsets $row $col]
1603 # changing direction
1604 set x [xc $row $col]
1606 lappend coords $x $y
1612 set x [xc $row $col]
1614 lappend coords $x $y
1616 # draw the link to the first child as part of this line
1618 set child [lindex $displayorder $row]
1619 set ccol [lsearch -exact [lindex $rowidlist $row] $child]
1621 set x [xc $row $ccol]
1623 if {$ccol < $col - 1} {
1624 lappend coords [xc $row [expr {$col - 1}]] [yc $row]
1625 } elseif {$ccol > $col + 1} {
1626 lappend coords [xc $row [expr {$col + 1}]] [yc $row]
1628 lappend coords $x $y
1631 if {[llength $coords] < 4} return
1633 # This line has an arrow at the lower end: check if the arrow is
1634 # on a diagonal segment, and if so, work around the Tk 8.4
1635 # refusal to draw arrows on diagonal lines.
1636 set x0 [lindex $coords 0]
1637 set x1 [lindex $coords 2]
1639 set y0 [lindex $coords 1]
1640 set y1 [lindex $coords 3]
1641 if {$y0 - $y1 <= 2 * $linespc && $x1 == [lindex $coords 4]} {
1642 # we have a nearby vertical segment, just trim off the diag bit
1643 set coords [lrange $coords 2 end]
1645 set slope [expr {($x0 - $x1) / ($y0 - $y1)}]
1646 set xi [expr {$x0 - $slope * $linespc / 2}]
1647 set yi [expr {$y0 - $linespc / 2}]
1648 set coords [lreplace $coords 0 1 $xi $y0 $xi $yi]
1652 set arrow [expr {2 * ($i > 0) + $downarrow}]
1653 set arrow [lindex {none first last both} $arrow]
1654 set t [$canv create line $coords -width [linewidth $id] \
1655 -fill $colormap($id) -tags lines.$id -arrow $arrow]
1660 proc drawparentlinks {id row col olds} {
1661 global rowidlist canv colormap
1663 set row2 [expr {$row + 1}]
1664 set x [xc $row $col]
1667 set ids [lindex $rowidlist $row2]
1668 # rmx = right-most X coord used
1671 set i [lsearch -exact $ids $p]
1673 puts "oops, parent $p of $id not in list"
1676 set x2 [xc $row2 $i]
1680 set ranges [rowranges $p]
1681 if {$ranges ne {} && $row2 == [lindex $ranges 0]
1682 && $row2 < [lindex $ranges 1]} {
1683 # drawlineseg will do this one for us
1687 # should handle duplicated parents here...
1688 set coords [list $x $y]
1689 if {$i < $col - 1} {
1690 lappend coords [xc $row [expr {$i + 1}]] $y
1691 } elseif {$i > $col + 1} {
1692 lappend coords [xc $row [expr {$i - 1}]] $y
1694 lappend coords $x2 $y2
1695 set t [$canv create line $coords -width [linewidth $p] \
1696 -fill $colormap($p) -tags lines.$p]
1703 proc drawlines {id} {
1704 global colormap canv
1706 global childlist iddrawn commitrow rowidlist
1708 $canv delete lines.$id
1709 set nr [expr {[llength [rowranges $id]] / 2}]
1710 for {set i 0} {$i < $nr} {incr i} {
1711 if {[info exists idrangedrawn($id,$i)]} {
1715 foreach child [lindex $childlist $commitrow($id)] {
1716 if {[info exists iddrawn($child)]} {
1717 set row $commitrow($child)
1718 set col [lsearch -exact [lindex $rowidlist $row] $child]
1720 drawparentlinks $child $row $col [list $id]
1726 proc drawcmittext {id row col rmx} {
1727 global linespc canv canv2 canv3 canvy0
1728 global commitlisted commitinfo rowidlist
1729 global rowtextx idpos idtags idheads idotherrefs
1730 global linehtag linentag linedtag
1731 global mainfont namefont canvxmax
1733 set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
1734 set x [xc $row $col]
1736 set orad [expr {$linespc / 3}]
1737 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
1738 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
1739 -fill $ofill -outline black -width 1]
1741 $canv bind $t <1> {selcanvline {} %x %y}
1742 set xt [xc $row [llength [lindex $rowidlist $row]]]
1746 set rowtextx($row) $xt
1747 set idpos($id) [list $x $xt $y]
1748 if {[info exists idtags($id)] || [info exists idheads($id)]
1749 || [info exists idotherrefs($id)]} {
1750 set xt [drawtags $id $x $xt $y]
1752 set headline [lindex $commitinfo($id) 0]
1753 set name [lindex $commitinfo($id) 1]
1754 set date [lindex $commitinfo($id) 2]
1755 set date [formatdate $date]
1756 set linehtag($row) [$canv create text $xt $y -anchor w \
1757 -text $headline -font $mainfont ]
1758 $canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
1759 set linentag($row) [$canv2 create text 3 $y -anchor w \
1760 -text $name -font $namefont]
1761 set linedtag($row) [$canv3 create text 3 $y -anchor w \
1762 -text $date -font $mainfont]
1763 set xr [expr {$xt + [font measure $mainfont $headline]}]
1764 if {$xr > $canvxmax} {
1770 proc drawcmitrow {row} {
1771 global displayorder rowidlist
1772 global idrangedrawn iddrawn
1773 global commitinfo commitlisted parentlist numcommits
1775 if {$row >= $numcommits} return
1776 foreach id [lindex $rowidlist $row] {
1777 if {$id eq {}} continue
1779 foreach {s e} [rowranges $id] {
1781 if {$row < $s} continue
1784 if {$e < $numcommits && ![info exists idrangedrawn($id,$i)]} {
1786 set idrangedrawn($id,$i) 1
1793 set id [lindex $displayorder $row]
1794 if {[info exists iddrawn($id)]} return
1795 set col [lsearch -exact [lindex $rowidlist $row] $id]
1797 puts "oops, row $row id $id not in list"
1800 if {![info exists commitinfo($id)]} {
1804 set olds [lindex $parentlist $row]
1806 set rmx [drawparentlinks $id $row $col $olds]
1810 drawcmittext $id $row $col $rmx
1814 proc drawfrac {f0 f1} {
1815 global numcommits canv
1818 set ymax [lindex [$canv cget -scrollregion] 3]
1819 if {$ymax eq {} || $ymax == 0} return
1820 set y0 [expr {int($f0 * $ymax)}]
1821 set row [expr {int(($y0 - 3) / $linespc) - 1}]
1825 set y1 [expr {int($f1 * $ymax)}]
1826 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
1827 if {$endrow >= $numcommits} {
1828 set endrow [expr {$numcommits - 1}]
1830 for {} {$row <= $endrow} {incr row} {
1835 proc drawvisible {} {
1837 eval drawfrac [$canv yview]
1840 proc clear_display {} {
1841 global iddrawn idrangedrawn
1844 catch {unset iddrawn}
1845 catch {unset idrangedrawn}
1848 proc findcrossings {id} {
1849 global rowidlist parentlist numcommits rowoffsets displayorder
1853 foreach {s e} [rowranges $id] {
1854 if {$e >= $numcommits} {
1855 set e [expr {$numcommits - 1}]
1857 if {$e <= $s} continue
1858 set x [lsearch -exact [lindex $rowidlist $e] $id]
1860 puts "findcrossings: oops, no [shortids $id] in row $e"
1863 for {set row $e} {[incr row -1] >= $s} {} {
1864 set olds [lindex $parentlist $row]
1865 set kid [lindex $displayorder $row]
1866 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
1867 if {$kidx < 0} continue
1868 set nextrow [lindex $rowidlist [expr {$row + 1}]]
1870 set px [lsearch -exact $nextrow $p]
1871 if {$px < 0} continue
1872 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
1873 if {[lsearch -exact $ccross $p] >= 0} continue
1874 if {$x == $px + ($kidx < $px? -1: 1)} {
1876 } elseif {[lsearch -exact $cross $p] < 0} {
1881 set inc [lindex $rowoffsets $row $x]
1882 if {$inc eq {}} break
1886 return [concat $ccross {{}} $cross]
1889 proc assigncolor {id} {
1890 global colormap colors nextcolor
1891 global commitrow parentlist children childlist
1893 if {[info exists colormap($id)]} return
1894 set ncolors [llength $colors]
1895 if {[info exists commitrow($id)]} {
1896 set kids [lindex $childlist $commitrow($id)]
1897 } elseif {[info exists children($id)]} {
1898 set kids $children($id)
1902 if {[llength $kids] == 1} {
1903 set child [lindex $kids 0]
1904 if {[info exists colormap($child)]
1905 && [llength [lindex $parentlist $commitrow($child)]] == 1} {
1906 set colormap($id) $colormap($child)
1912 foreach x [findcrossings $id] {
1914 # delimiter between corner crossings and other crossings
1915 if {[llength $badcolors] >= $ncolors - 1} break
1916 set origbad $badcolors
1918 if {[info exists colormap($x)]
1919 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1920 lappend badcolors $colormap($x)
1923 if {[llength $badcolors] >= $ncolors} {
1924 set badcolors $origbad
1926 set origbad $badcolors
1927 if {[llength $badcolors] < $ncolors - 1} {
1928 foreach child $kids {
1929 if {[info exists colormap($child)]
1930 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1931 lappend badcolors $colormap($child)
1933 foreach p [lindex $parentlist $commitrow($child)] {
1934 if {[info exists colormap($p)]
1935 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1936 lappend badcolors $colormap($p)
1940 if {[llength $badcolors] >= $ncolors} {
1941 set badcolors $origbad
1944 for {set i 0} {$i <= $ncolors} {incr i} {
1945 set c [lindex $colors $nextcolor]
1946 if {[incr nextcolor] >= $ncolors} {
1949 if {[lsearch -exact $badcolors $c]} break
1951 set colormap($id) $c
1954 proc bindline {t id} {
1957 $canv bind $t <Enter> "lineenter %x %y $id"
1958 $canv bind $t <Motion> "linemotion %x %y $id"
1959 $canv bind $t <Leave> "lineleave $id"
1960 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1963 proc drawtags {id x xt y1} {
1964 global idtags idheads idotherrefs
1965 global linespc lthickness
1966 global canv mainfont commitrow rowtextx
1971 if {[info exists idtags($id)]} {
1972 set marks $idtags($id)
1973 set ntags [llength $marks]
1975 if {[info exists idheads($id)]} {
1976 set marks [concat $marks $idheads($id)]
1977 set nheads [llength $idheads($id)]
1979 if {[info exists idotherrefs($id)]} {
1980 set marks [concat $marks $idotherrefs($id)]
1986 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1987 set yt [expr {$y1 - 0.5 * $linespc}]
1988 set yb [expr {$yt + $linespc - 1}]
1991 foreach tag $marks {
1992 set wid [font measure $mainfont $tag]
1995 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1997 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1998 -width $lthickness -fill black -tags tag.$id]
2000 foreach tag $marks x $xvals wid $wvals {
2001 set xl [expr {$x + $delta}]
2002 set xr [expr {$x + $delta + $wid + $lthickness}]
2003 if {[incr ntags -1] >= 0} {
2005 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
2006 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
2007 -width 1 -outline black -fill yellow -tags tag.$id]
2008 $canv bind $t <1> [list showtag $tag 1]
2009 set rowtextx($commitrow($id)) [expr {$xr + $linespc}]
2011 # draw a head or other ref
2012 if {[incr nheads -1] >= 0} {
2017 set xl [expr {$xl - $delta/2}]
2018 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
2019 -width 1 -outline black -fill $col -tags tag.$id
2021 set t [$canv create text $xl $y1 -anchor w -text $tag \
2022 -font $mainfont -tags tag.$id]
2024 $canv bind $t <1> [list showtag $tag 1]
2030 proc xcoord {i level ln} {
2031 global canvx0 xspc1 xspc2
2033 set x [expr {$canvx0 + $i * $xspc1($ln)}]
2034 if {$i > 0 && $i == $level} {
2035 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
2036 } elseif {$i > $level} {
2037 set x [expr {$x + $xspc2 - $xspc1($ln)}]
2042 proc finishcommits {} {
2043 global commitidx phase
2044 global canv mainfont ctext maincursor textcursor
2045 global findinprogress pending_select
2047 if {$commitidx > 0} {
2051 $canv create text 3 3 -anchor nw -text "No commits selected" \
2052 -font $mainfont -tags textitems
2054 if {![info exists findinprogress]} {
2055 . config -cursor $maincursor
2056 settextcursor $textcursor
2059 catch {unset pending_select}
2062 # Don't change the text pane cursor if it is currently the hand cursor,
2063 # showing that we are over a sha1 ID link.
2064 proc settextcursor {c} {
2065 global ctext curtextcursor
2067 if {[$ctext cget -cursor] == $curtextcursor} {
2068 $ctext config -cursor $c
2070 set curtextcursor $c
2076 global canvy0 numcommits linespc
2077 global rowlaidout commitidx
2078 global pending_select
2081 layoutrows $rowlaidout $commitidx 1
2083 optimize_rows $row 0 $commitidx
2084 showstuff $commitidx
2085 if {[info exists pending_select]} {
2089 set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
2090 #puts "overall $drawmsecs ms for $numcommits commits"
2093 proc findmatches {f} {
2094 global findtype foundstring foundstrlen
2095 if {$findtype == "Regexp"} {
2096 set matches [regexp -indices -all -inline $foundstring $f]
2098 if {$findtype == "IgnCase"} {
2099 set str [string tolower $f]
2105 while {[set j [string first $foundstring $str $i]] >= 0} {
2106 lappend matches [list $j [expr {$j+$foundstrlen-1}]]
2107 set i [expr {$j + $foundstrlen}]
2114 global findtype findloc findstring markedmatches commitinfo
2115 global numcommits displayorder linehtag linentag linedtag
2116 global mainfont namefont canv canv2 canv3 selectedline
2117 global matchinglines foundstring foundstrlen matchstring
2123 set matchinglines {}
2124 if {$findloc == "Pickaxe"} {
2128 if {$findtype == "IgnCase"} {
2129 set foundstring [string tolower $findstring]
2131 set foundstring $findstring
2133 set foundstrlen [string length $findstring]
2134 if {$foundstrlen == 0} return
2135 regsub -all {[*?\[\\]} $foundstring {\\&} matchstring
2136 set matchstring "*$matchstring*"
2137 if {$findloc == "Files"} {
2141 if {![info exists selectedline]} {
2144 set oldsel $selectedline
2147 set fldtypes {Headline Author Date Committer CDate Comment}
2149 foreach id $displayorder {
2150 set d $commitdata($id)
2152 if {$findtype == "Regexp"} {
2153 set doesmatch [regexp $foundstring $d]
2154 } elseif {$findtype == "IgnCase"} {
2155 set doesmatch [string match -nocase $matchstring $d]
2157 set doesmatch [string match $matchstring $d]
2159 if {!$doesmatch} continue
2160 if {![info exists commitinfo($id)]} {
2163 set info $commitinfo($id)
2165 foreach f $info ty $fldtypes {
2166 if {$findloc != "All fields" && $findloc != $ty} {
2169 set matches [findmatches $f]
2170 if {$matches == {}} continue
2172 if {$ty == "Headline"} {
2174 markmatches $canv $l $f $linehtag($l) $matches $mainfont
2175 } elseif {$ty == "Author"} {
2177 markmatches $canv2 $l $f $linentag($l) $matches $namefont
2178 } elseif {$ty == "Date"} {
2180 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
2184 lappend matchinglines $l
2185 if {!$didsel && $l > $oldsel} {
2191 if {$matchinglines == {}} {
2193 } elseif {!$didsel} {
2194 findselectline [lindex $matchinglines 0]
2198 proc findselectline {l} {
2199 global findloc commentend ctext
2201 if {$findloc == "All fields" || $findloc == "Comments"} {
2202 # highlight the matches in the comments
2203 set f [$ctext get 1.0 $commentend]
2204 set matches [findmatches $f]
2205 foreach match $matches {
2206 set start [lindex $match 0]
2207 set end [expr {[lindex $match 1] + 1}]
2208 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
2213 proc findnext {restart} {
2214 global matchinglines selectedline
2215 if {![info exists matchinglines]} {
2221 if {![info exists selectedline]} return
2222 foreach l $matchinglines {
2223 if {$l > $selectedline} {
2232 global matchinglines selectedline
2233 if {![info exists matchinglines]} {
2237 if {![info exists selectedline]} return
2239 foreach l $matchinglines {
2240 if {$l >= $selectedline} break
2244 findselectline $prev
2250 proc findlocchange {name ix op} {
2251 global findloc findtype findtypemenu
2252 if {$findloc == "Pickaxe"} {
2258 $findtypemenu entryconf 1 -state $state
2259 $findtypemenu entryconf 2 -state $state
2262 proc stopfindproc {{done 0}} {
2263 global findprocpid findprocfile findids
2264 global ctext findoldcursor phase maincursor textcursor
2265 global findinprogress
2267 catch {unset findids}
2268 if {[info exists findprocpid]} {
2270 catch {exec kill $findprocpid}
2272 catch {close $findprocfile}
2275 if {[info exists findinprogress]} {
2276 unset findinprogress
2278 . config -cursor $maincursor
2279 settextcursor $textcursor
2284 proc findpatches {} {
2285 global findstring selectedline numcommits
2286 global findprocpid findprocfile
2287 global finddidsel ctext displayorder findinprogress
2288 global findinsertpos
2290 if {$numcommits == 0} return
2292 # make a list of all the ids to search, starting at the one
2293 # after the selected line (if any)
2294 if {[info exists selectedline]} {
2300 for {set i 0} {$i < $numcommits} {incr i} {
2301 if {[incr l] >= $numcommits} {
2304 append inputids [lindex $displayorder $l] "\n"
2308 set f [open [list | git-diff-tree --stdin -s -r -S$findstring \
2311 error_popup "Error starting search process: $err"
2315 set findinsertpos end
2317 set findprocpid [pid $f]
2318 fconfigure $f -blocking 0
2319 fileevent $f readable readfindproc
2321 . config -cursor watch
2323 set findinprogress 1
2326 proc readfindproc {} {
2327 global findprocfile finddidsel
2328 global commitrow matchinglines findinsertpos
2330 set n [gets $findprocfile line]
2332 if {[eof $findprocfile]} {
2340 if {![regexp {^[0-9a-f]{40}} $line id]} {
2341 error_popup "Can't parse git-diff-tree output: $line"
2345 if {![info exists commitrow($id)]} {
2346 puts stderr "spurious id: $id"
2349 set l $commitrow($id)
2353 proc insertmatch {l id} {
2354 global matchinglines findinsertpos finddidsel
2356 if {$findinsertpos == "end"} {
2357 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
2358 set matchinglines [linsert $matchinglines 0 $l]
2361 lappend matchinglines $l
2364 set matchinglines [linsert $matchinglines $findinsertpos $l]
2375 global selectedline numcommits displayorder ctext
2376 global ffileline finddidsel parentlist
2377 global findinprogress findstartline findinsertpos
2378 global treediffs fdiffid fdiffsneeded fdiffpos
2379 global findmergefiles
2381 if {$numcommits == 0} return
2383 if {[info exists selectedline]} {
2384 set l [expr {$selectedline + 1}]
2389 set findstartline $l
2393 set id [lindex $displayorder $l]
2394 if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2395 if {![info exists treediffs($id)]} {
2396 append diffsneeded "$id\n"
2397 lappend fdiffsneeded $id
2400 if {[incr l] >= $numcommits} {
2403 if {$l == $findstartline} break
2406 # start off a git-diff-tree process if needed
2407 if {$diffsneeded ne {}} {
2409 set df [open [list | git-diff-tree -r --stdin << $diffsneeded] r]
2411 error_popup "Error starting search process: $err"
2414 catch {unset fdiffid}
2416 fconfigure $df -blocking 0
2417 fileevent $df readable [list readfilediffs $df]
2421 set findinsertpos end
2422 set id [lindex $displayorder $l]
2423 . config -cursor watch
2425 set findinprogress 1
2430 proc readfilediffs {df} {
2431 global findid fdiffid fdiffs
2433 set n [gets $df line]
2437 if {[catch {close $df} err]} {
2440 error_popup "Error in git-diff-tree: $err"
2441 } elseif {[info exists findid]} {
2445 error_popup "Couldn't find diffs for $id"
2450 if {[regexp {^([0-9a-f]{40})$} $line match id]} {
2451 # start of a new string of diffs
2455 } elseif {[string match ":*" $line]} {
2456 lappend fdiffs [lindex $line 5]
2460 proc donefilediff {} {
2461 global fdiffid fdiffs treediffs findid
2462 global fdiffsneeded fdiffpos
2464 if {[info exists fdiffid]} {
2465 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffid
2466 && $fdiffpos < [llength $fdiffsneeded]} {
2467 # git-diff-tree doesn't output anything for a commit
2468 # which doesn't change anything
2469 set nullid [lindex $fdiffsneeded $fdiffpos]
2470 set treediffs($nullid) {}
2471 if {[info exists findid] && $nullid eq $findid} {
2479 if {![info exists treediffs($fdiffid)]} {
2480 set treediffs($fdiffid) $fdiffs
2482 if {[info exists findid] && $fdiffid eq $findid} {
2490 global findid treediffs parentlist
2491 global ffileline findstartline finddidsel
2492 global displayorder numcommits matchinglines findinprogress
2493 global findmergefiles
2497 set id [lindex $displayorder $l]
2498 if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2499 if {![info exists treediffs($id)]} {
2505 foreach f $treediffs($id) {
2506 set x [findmatches $f]
2516 if {[incr l] >= $numcommits} {
2519 if {$l == $findstartline} break
2527 # mark a commit as matching by putting a yellow background
2528 # behind the headline
2529 proc markheadline {l id} {
2530 global canv mainfont linehtag
2533 set bbox [$canv bbox $linehtag($l)]
2534 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2538 # mark the bits of a headline, author or date that match a find string
2539 proc markmatches {canv l str tag matches font} {
2540 set bbox [$canv bbox $tag]
2541 set x0 [lindex $bbox 0]
2542 set y0 [lindex $bbox 1]
2543 set y1 [lindex $bbox 3]
2544 foreach match $matches {
2545 set start [lindex $match 0]
2546 set end [lindex $match 1]
2547 if {$start > $end} continue
2548 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
2549 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
2550 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
2551 [expr {$x0+$xlen+2}] $y1 \
2552 -outline {} -tags matches -fill yellow]
2557 proc unmarkmatches {} {
2558 global matchinglines findids
2559 allcanvs delete matches
2560 catch {unset matchinglines}
2561 catch {unset findids}
2564 proc selcanvline {w x y} {
2565 global canv canvy0 ctext linespc
2567 set ymax [lindex [$canv cget -scrollregion] 3]
2568 if {$ymax == {}} return
2569 set yfrac [lindex [$canv yview] 0]
2570 set y [expr {$y + $yfrac * $ymax}]
2571 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2576 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2582 proc commit_descriptor {p} {
2585 if {[info exists commitinfo($p)]} {
2586 set l [lindex $commitinfo($p) 0]
2591 # append some text to the ctext widget, and make any SHA1 ID
2592 # that we know about be a clickable link.
2593 proc appendwithlinks {text} {
2594 global ctext commitrow linknum
2596 set start [$ctext index "end - 1c"]
2597 $ctext insert end $text
2598 $ctext insert end "\n"
2599 set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
2603 set linkid [string range $text $s $e]
2604 if {![info exists commitrow($linkid)]} continue
2606 $ctext tag add link "$start + $s c" "$start + $e c"
2607 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2608 $ctext tag bind link$linknum <1> [list selectline $commitrow($linkid) 1]
2611 $ctext tag conf link -foreground blue -underline 1
2612 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2613 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2616 proc viewnextline {dir} {
2620 set ymax [lindex [$canv cget -scrollregion] 3]
2621 set wnow [$canv yview]
2622 set wtop [expr {[lindex $wnow 0] * $ymax}]
2623 set newtop [expr {$wtop + $dir * $linespc}]
2626 } elseif {$newtop > $ymax} {
2629 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2632 proc selectline {l isnew} {
2633 global canv canv2 canv3 ctext commitinfo selectedline
2634 global displayorder linehtag linentag linedtag
2635 global canvy0 linespc parentlist childlist
2636 global cflist currentid sha1entry
2637 global commentend idtags linknum
2638 global mergemax numcommits pending_select
2640 catch {unset pending_select}
2643 if {$l < 0 || $l >= $numcommits} return
2644 set y [expr {$canvy0 + $l * $linespc}]
2645 set ymax [lindex [$canv cget -scrollregion] 3]
2646 set ytop [expr {$y - $linespc - 1}]
2647 set ybot [expr {$y + $linespc + 1}]
2648 set wnow [$canv yview]
2649 set wtop [expr {[lindex $wnow 0] * $ymax}]
2650 set wbot [expr {[lindex $wnow 1] * $ymax}]
2651 set wh [expr {$wbot - $wtop}]
2653 if {$ytop < $wtop} {
2654 if {$ybot < $wtop} {
2655 set newtop [expr {$y - $wh / 2.0}]
2658 if {$newtop > $wtop - $linespc} {
2659 set newtop [expr {$wtop - $linespc}]
2662 } elseif {$ybot > $wbot} {
2663 if {$ytop > $wbot} {
2664 set newtop [expr {$y - $wh / 2.0}]
2666 set newtop [expr {$ybot - $wh}]
2667 if {$newtop < $wtop + $linespc} {
2668 set newtop [expr {$wtop + $linespc}]
2672 if {$newtop != $wtop} {
2676 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2680 if {![info exists linehtag($l)]} return
2682 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2683 -tags secsel -fill [$canv cget -selectbackground]]
2685 $canv2 delete secsel
2686 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2687 -tags secsel -fill [$canv2 cget -selectbackground]]
2689 $canv3 delete secsel
2690 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2691 -tags secsel -fill [$canv3 cget -selectbackground]]
2695 addtohistory [list selectline $l 0]
2700 set id [lindex $displayorder $l]
2702 $sha1entry delete 0 end
2703 $sha1entry insert 0 $id
2704 $sha1entry selection from 0
2705 $sha1entry selection to end
2707 $ctext conf -state normal
2708 $ctext delete 0.0 end
2710 $ctext mark set fmark.0 0.0
2711 $ctext mark gravity fmark.0 left
2712 set info $commitinfo($id)
2713 set date [formatdate [lindex $info 2]]
2714 $ctext insert end "Author: [lindex $info 1] $date\n"
2715 set date [formatdate [lindex $info 4]]
2716 $ctext insert end "Committer: [lindex $info 3] $date\n"
2717 if {[info exists idtags($id)]} {
2718 $ctext insert end "Tags:"
2719 foreach tag $idtags($id) {
2720 $ctext insert end " $tag"
2722 $ctext insert end "\n"
2726 set olds [lindex $parentlist $l]
2727 if {[llength $olds] > 1} {
2730 if {$np >= $mergemax} {
2735 $ctext insert end "Parent: " $tag
2736 appendwithlinks [commit_descriptor $p]
2741 append comment "Parent: [commit_descriptor $p]\n"
2745 foreach c [lindex $childlist $l] {
2746 append comment "Child: [commit_descriptor $c]\n"
2749 append comment [lindex $info 5]
2751 # make anything that looks like a SHA1 ID be a clickable link
2752 appendwithlinks $comment
2754 $ctext tag delete Comments
2755 $ctext tag remove found 1.0 end
2756 $ctext conf -state disabled
2757 set commentend [$ctext index "end - 1c"]
2759 $cflist delete 0 end
2760 $cflist insert end "Comments"
2761 if {[llength $olds] <= 1} {
2768 proc selfirstline {} {
2773 proc sellastline {} {
2776 set l [expr {$numcommits - 1}]
2780 proc selnextline {dir} {
2782 if {![info exists selectedline]} return
2783 set l [expr {$selectedline + $dir}]
2788 proc selnextpage {dir} {
2789 global canv linespc selectedline numcommits
2791 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
2795 allcanvs yview scroll [expr {$dir * $lpp}] units
2796 if {![info exists selectedline]} return
2797 set l [expr {$selectedline + $dir * $lpp}]
2800 } elseif {$l >= $numcommits} {
2801 set l [expr $numcommits - 1]
2807 proc unselectline {} {
2808 global selectedline currentid
2810 catch {unset selectedline}
2811 catch {unset currentid}
2812 allcanvs delete secsel
2815 proc addtohistory {cmd} {
2816 global history historyindex curview
2818 set elt [list $curview $cmd]
2819 if {$historyindex > 0
2820 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
2824 if {$historyindex < [llength $history]} {
2825 set history [lreplace $history $historyindex end $elt]
2827 lappend history $elt
2830 if {$historyindex > 1} {
2831 .ctop.top.bar.leftbut conf -state normal
2833 .ctop.top.bar.leftbut conf -state disabled
2835 .ctop.top.bar.rightbut conf -state disabled
2841 set view [lindex $elt 0]
2842 set cmd [lindex $elt 1]
2843 if {$curview != $view} {
2850 global history historyindex
2852 if {$historyindex > 1} {
2853 incr historyindex -1
2854 godo [lindex $history [expr {$historyindex - 1}]]
2855 .ctop.top.bar.rightbut conf -state normal
2857 if {$historyindex <= 1} {
2858 .ctop.top.bar.leftbut conf -state disabled
2863 global history historyindex
2865 if {$historyindex < [llength $history]} {
2866 set cmd [lindex $history $historyindex]
2869 .ctop.top.bar.leftbut conf -state normal
2871 if {$historyindex >= [llength $history]} {
2872 .ctop.top.bar.rightbut conf -state disabled
2876 proc mergediff {id l} {
2877 global diffmergeid diffopts mdifffd
2878 global difffilestart diffids
2883 catch {unset difffilestart}
2884 # this doesn't seem to actually affect anything...
2885 set env(GIT_DIFF_OPTS) $diffopts
2886 set cmd [concat | git-diff-tree --no-commit-id --cc $id]
2887 if {[catch {set mdf [open $cmd r]} err]} {
2888 error_popup "Error getting merge diffs: $err"
2891 fconfigure $mdf -blocking 0
2892 set mdifffd($id) $mdf
2893 set np [llength [lindex $parentlist $l]]
2894 fileevent $mdf readable [list getmergediffline $mdf $id $np]
2895 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2898 proc getmergediffline {mdf id np} {
2899 global diffmergeid ctext cflist nextupdate mergemax
2900 global difffilestart mdifffd
2902 set n [gets $mdf line]
2909 if {![info exists diffmergeid] || $id != $diffmergeid
2910 || $mdf != $mdifffd($id)} {
2913 $ctext conf -state normal
2914 if {[regexp {^diff --cc (.*)} $line match fname]} {
2915 # start of a new file
2916 $ctext insert end "\n"
2917 set here [$ctext index "end - 1c"]
2918 set i [$cflist index end]
2919 $ctext mark set fmark.$i $here
2920 $ctext mark gravity fmark.$i left
2921 set difffilestart([expr {$i-1}]) $here
2922 $cflist insert end $fname
2923 set l [expr {(78 - [string length $fname]) / 2}]
2924 set pad [string range "----------------------------------------" 1 $l]
2925 $ctext insert end "$pad $fname $pad\n" filesep
2926 } elseif {[regexp {^@@} $line]} {
2927 $ctext insert end "$line\n" hunksep
2928 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
2931 # parse the prefix - one ' ', '-' or '+' for each parent
2936 for {set j 0} {$j < $np} {incr j} {
2937 set c [string range $line $j $j]
2940 } elseif {$c == "-"} {
2942 } elseif {$c == "+"} {
2951 if {!$isbad && $minuses ne {} && $pluses eq {}} {
2952 # line doesn't appear in result, parents in $minuses have the line
2953 set num [lindex $minuses 0]
2954 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
2955 # line appears in result, parents in $pluses don't have the line
2956 lappend tags mresult
2957 set num [lindex $spaces 0]
2960 if {$num >= $mergemax} {
2965 $ctext insert end "$line\n" $tags
2967 $ctext conf -state disabled
2968 if {[clock clicks -milliseconds] >= $nextupdate} {
2970 fileevent $mdf readable {}
2972 fileevent $mdf readable [list getmergediffline $mdf $id $np]
2976 proc startdiff {ids} {
2977 global treediffs diffids treepending diffmergeid
2980 catch {unset diffmergeid}
2981 if {![info exists treediffs($ids)]} {
2982 if {![info exists treepending]} {
2990 proc addtocflist {ids} {
2991 global treediffs cflist
2992 foreach f $treediffs($ids) {
2993 $cflist insert end $f
2998 proc gettreediffs {ids} {
2999 global treediff treepending
3000 set treepending $ids
3003 {set gdtf [open [concat | git-diff-tree --no-commit-id -r $ids] r]} \
3005 fconfigure $gdtf -blocking 0
3006 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
3009 proc gettreediffline {gdtf ids} {
3010 global treediff treediffs treepending diffids diffmergeid
3012 set n [gets $gdtf line]
3014 if {![eof $gdtf]} return
3016 set treediffs($ids) $treediff
3018 if {$ids != $diffids} {
3019 if {![info exists diffmergeid]} {
3020 gettreediffs $diffids
3027 set file [lindex $line 5]
3028 lappend treediff $file
3031 proc getblobdiffs {ids} {
3032 global diffopts blobdifffd diffids env curdifftag curtagstart
3033 global difffilestart nextupdate diffinhdr treediffs
3035 set env(GIT_DIFF_OPTS) $diffopts
3036 set cmd [concat | git-diff-tree --no-commit-id -r -p -C $ids]
3037 if {[catch {set bdf [open $cmd r]} err]} {
3038 puts "error getting diffs: $err"
3042 fconfigure $bdf -blocking 0
3043 set blobdifffd($ids) $bdf
3044 set curdifftag Comments
3046 catch {unset difffilestart}
3047 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
3048 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3051 proc getblobdiffline {bdf ids} {
3052 global diffids blobdifffd ctext curdifftag curtagstart
3053 global diffnexthead diffnextnote difffilestart
3054 global nextupdate diffinhdr treediffs
3056 set n [gets $bdf line]
3060 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
3061 $ctext tag add $curdifftag $curtagstart end
3066 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
3069 $ctext conf -state normal
3070 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
3071 # start of a new file
3072 $ctext insert end "\n"
3073 $ctext tag add $curdifftag $curtagstart end
3074 set curtagstart [$ctext index "end - 1c"]
3076 set here [$ctext index "end - 1c"]
3077 set i [lsearch -exact $treediffs($diffids) $fname]
3079 set difffilestart($i) $here
3081 $ctext mark set fmark.$i $here
3082 $ctext mark gravity fmark.$i left
3084 if {$newname != $fname} {
3085 set i [lsearch -exact $treediffs($diffids) $newname]
3087 set difffilestart($i) $here
3089 $ctext mark set fmark.$i $here
3090 $ctext mark gravity fmark.$i left
3093 set curdifftag "f:$fname"
3094 $ctext tag delete $curdifftag
3095 set l [expr {(78 - [string length $header]) / 2}]
3096 set pad [string range "----------------------------------------" 1 $l]
3097 $ctext insert end "$pad $header $pad\n" filesep
3099 } elseif {$diffinhdr && [string compare -length 3 $line "---"] == 0} {
3101 } elseif {$diffinhdr && [string compare -length 3 $line "+++"] == 0} {
3103 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
3104 $line match f1l f1c f2l f2c rest]} {
3105 $ctext insert end "$line\n" hunksep
3108 set x [string range $line 0 0]
3109 if {$x == "-" || $x == "+"} {
3110 set tag [expr {$x == "+"}]
3111 $ctext insert end "$line\n" d$tag
3112 } elseif {$x == " "} {
3113 $ctext insert end "$line\n"
3114 } elseif {$diffinhdr || $x == "\\"} {
3115 # e.g. "\ No newline at end of file"
3116 $ctext insert end "$line\n" filesep
3118 # Something else we don't recognize
3119 if {$curdifftag != "Comments"} {
3120 $ctext insert end "\n"
3121 $ctext tag add $curdifftag $curtagstart end
3122 set curtagstart [$ctext index "end - 1c"]
3123 set curdifftag Comments
3125 $ctext insert end "$line\n" filesep
3128 $ctext conf -state disabled
3129 if {[clock clicks -milliseconds] >= $nextupdate} {
3131 fileevent $bdf readable {}
3133 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
3138 global difffilestart ctext
3139 set here [$ctext index @0,0]
3140 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
3141 if {[$ctext compare $difffilestart($i) > $here]} {
3142 if {![info exists pos]
3143 || [$ctext compare $difffilestart($i) < $pos]} {
3144 set pos $difffilestart($i)
3148 if {[info exists pos]} {
3153 proc listboxsel {} {
3154 global ctext cflist currentid
3155 if {![info exists currentid]} return
3156 set sel [lsort [$cflist curselection]]
3157 if {$sel eq {}} return
3158 set first [lindex $sel 0]
3159 catch {$ctext yview fmark.$first}
3163 global linespc charspc canvx0 canvy0 mainfont
3164 global xspc1 xspc2 lthickness
3166 set linespc [font metrics $mainfont -linespace]
3167 set charspc [font measure $mainfont "m"]
3168 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
3169 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
3170 set lthickness [expr {int($linespc / 9) + 1}]
3171 set xspc1(0) $linespc
3179 set ymax [lindex [$canv cget -scrollregion] 3]
3180 if {$ymax eq {} || $ymax == 0} return
3181 set span [$canv yview]
3184 allcanvs yview moveto [lindex $span 0]
3186 if {[info exists selectedline]} {
3187 selectline $selectedline 0
3191 proc incrfont {inc} {
3192 global mainfont namefont textfont ctext canv phase
3193 global stopped entries
3195 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3196 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3197 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3199 $ctext conf -font $textfont
3200 $ctext tag conf filesep -font [concat $textfont bold]
3201 foreach e $entries {
3202 $e conf -font $mainfont
3204 if {$phase eq "getcommits"} {
3205 $canv itemconf textitems -font $mainfont
3211 global sha1entry sha1string
3212 if {[string length $sha1string] == 40} {
3213 $sha1entry delete 0 end
3217 proc sha1change {n1 n2 op} {
3218 global sha1string currentid sha1but
3219 if {$sha1string == {}
3220 || ([info exists currentid] && $sha1string == $currentid)} {
3225 if {[$sha1but cget -state] == $state} return
3226 if {$state == "normal"} {
3227 $sha1but conf -state normal -relief raised -text "Goto: "
3229 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3233 proc gotocommit {} {
3234 global sha1string currentid commitrow tagids headids
3235 global displayorder numcommits
3237 if {$sha1string == {}
3238 || ([info exists currentid] && $sha1string == $currentid)} return
3239 if {[info exists tagids($sha1string)]} {
3240 set id $tagids($sha1string)
3241 } elseif {[info exists headids($sha1string)]} {
3242 set id $headids($sha1string)
3244 set id [string tolower $sha1string]
3245 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3247 foreach i $displayorder {
3248 if {[string match $id* $i]} {
3252 if {$matches ne {}} {
3253 if {[llength $matches] > 1} {
3254 error_popup "Short SHA1 id $id is ambiguous"
3257 set id [lindex $matches 0]
3261 if {[info exists commitrow($id)]} {
3262 selectline $commitrow($id) 1
3265 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3270 error_popup "$type $sha1string is not known"
3273 proc lineenter {x y id} {
3274 global hoverx hovery hoverid hovertimer
3275 global commitinfo canv
3277 if {![info exists commitinfo($id)] && ![getcommit $id]} return
3281 if {[info exists hovertimer]} {
3282 after cancel $hovertimer
3284 set hovertimer [after 500 linehover]
3288 proc linemotion {x y id} {
3289 global hoverx hovery hoverid hovertimer
3291 if {[info exists hoverid] && $id == $hoverid} {
3294 if {[info exists hovertimer]} {
3295 after cancel $hovertimer
3297 set hovertimer [after 500 linehover]
3301 proc lineleave {id} {
3302 global hoverid hovertimer canv
3304 if {[info exists hoverid] && $id == $hoverid} {
3306 if {[info exists hovertimer]} {
3307 after cancel $hovertimer
3315 global hoverx hovery hoverid hovertimer
3316 global canv linespc lthickness
3317 global commitinfo mainfont
3319 set text [lindex $commitinfo($hoverid) 0]
3320 set ymax [lindex [$canv cget -scrollregion] 3]
3321 if {$ymax == {}} return
3322 set yfrac [lindex [$canv yview] 0]
3323 set x [expr {$hoverx + 2 * $linespc}]
3324 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3325 set x0 [expr {$x - 2 * $lthickness}]
3326 set y0 [expr {$y - 2 * $lthickness}]
3327 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3328 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3329 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3330 -fill \#ffff80 -outline black -width 1 -tags hover]
3332 set t [$canv create text $x $y -anchor nw -text $text -tags hover -font $mainfont]
3336 proc clickisonarrow {id y} {
3339 set ranges [rowranges $id]
3340 set thresh [expr {2 * $lthickness + 6}]
3341 set n [expr {[llength $ranges] - 1}]
3342 for {set i 1} {$i < $n} {incr i} {
3343 set row [lindex $ranges $i]
3344 if {abs([yc $row] - $y) < $thresh} {
3351 proc arrowjump {id n y} {
3354 # 1 <-> 2, 3 <-> 4, etc...
3355 set n [expr {(($n - 1) ^ 1) + 1}]
3356 set row [lindex [rowranges $id] $n]
3358 set ymax [lindex [$canv cget -scrollregion] 3]
3359 if {$ymax eq {} || $ymax <= 0} return
3360 set view [$canv yview]
3361 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3362 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3366 allcanvs yview moveto $yfrac
3369 proc lineclick {x y id isnew} {
3370 global ctext commitinfo childlist commitrow cflist canv thickerline
3372 if {![info exists commitinfo($id)] && ![getcommit $id]} return
3377 # draw this line thicker than normal
3381 set ymax [lindex [$canv cget -scrollregion] 3]
3382 if {$ymax eq {}} return
3383 set yfrac [lindex [$canv yview] 0]
3384 set y [expr {$y + $yfrac * $ymax}]
3386 set dirn [clickisonarrow $id $y]
3388 arrowjump $id $dirn $y
3393 addtohistory [list lineclick $x $y $id 0]
3395 # fill the details pane with info about this line
3396 $ctext conf -state normal
3397 $ctext delete 0.0 end
3398 $ctext tag conf link -foreground blue -underline 1
3399 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3400 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3401 $ctext insert end "Parent:\t"
3402 $ctext insert end $id [list link link0]
3403 $ctext tag bind link0 <1> [list selbyid $id]
3404 set info $commitinfo($id)
3405 $ctext insert end "\n\t[lindex $info 0]\n"
3406 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3407 set date [formatdate [lindex $info 2]]
3408 $ctext insert end "\tDate:\t$date\n"
3409 set kids [lindex $childlist $commitrow($id)]
3411 $ctext insert end "\nChildren:"
3413 foreach child $kids {
3415 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
3416 set info $commitinfo($child)
3417 $ctext insert end "\n\t"
3418 $ctext insert end $child [list link link$i]
3419 $ctext tag bind link$i <1> [list selbyid $child]
3420 $ctext insert end "\n\t[lindex $info 0]"
3421 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3422 set date [formatdate [lindex $info 2]]
3423 $ctext insert end "\n\tDate:\t$date\n"
3426 $ctext conf -state disabled
3428 $cflist delete 0 end
3431 proc normalline {} {
3433 if {[info exists thickerline]} {
3442 if {[info exists commitrow($id)]} {
3443 selectline $commitrow($id) 1
3449 if {![info exists startmstime]} {
3450 set startmstime [clock clicks -milliseconds]
3452 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3455 proc rowmenu {x y id} {
3456 global rowctxmenu commitrow selectedline rowmenuid
3458 if {![info exists selectedline] || $commitrow($id) eq $selectedline} {
3463 $rowctxmenu entryconfigure 0 -state $state
3464 $rowctxmenu entryconfigure 1 -state $state
3465 $rowctxmenu entryconfigure 2 -state $state
3467 tk_popup $rowctxmenu $x $y
3470 proc diffvssel {dirn} {
3471 global rowmenuid selectedline displayorder
3473 if {![info exists selectedline]} return
3475 set oldid [lindex $displayorder $selectedline]
3476 set newid $rowmenuid
3478 set oldid $rowmenuid
3479 set newid [lindex $displayorder $selectedline]
3481 addtohistory [list doseldiff $oldid $newid]
3482 doseldiff $oldid $newid
3485 proc doseldiff {oldid newid} {
3489 $ctext conf -state normal
3490 $ctext delete 0.0 end
3491 $ctext mark set fmark.0 0.0
3492 $ctext mark gravity fmark.0 left
3493 $cflist delete 0 end
3494 $cflist insert end "Top"
3495 $ctext insert end "From "
3496 $ctext tag conf link -foreground blue -underline 1
3497 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3498 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3499 $ctext tag bind link0 <1> [list selbyid $oldid]
3500 $ctext insert end $oldid [list link link0]
3501 $ctext insert end "\n "
3502 $ctext insert end [lindex $commitinfo($oldid) 0]
3503 $ctext insert end "\n\nTo "
3504 $ctext tag bind link1 <1> [list selbyid $newid]
3505 $ctext insert end $newid [list link link1]
3506 $ctext insert end "\n "
3507 $ctext insert end [lindex $commitinfo($newid) 0]
3508 $ctext insert end "\n"
3509 $ctext conf -state disabled
3510 $ctext tag delete Comments
3511 $ctext tag remove found 1.0 end
3512 startdiff [list $oldid $newid]
3516 global rowmenuid currentid commitinfo patchtop patchnum
3518 if {![info exists currentid]} return
3519 set oldid $currentid
3520 set oldhead [lindex $commitinfo($oldid) 0]
3521 set newid $rowmenuid
3522 set newhead [lindex $commitinfo($newid) 0]
3525 catch {destroy $top}
3527 label $top.title -text "Generate patch"
3528 grid $top.title - -pady 10
3529 label $top.from -text "From:"
3530 entry $top.fromsha1 -width 40 -relief flat
3531 $top.fromsha1 insert 0 $oldid
3532 $top.fromsha1 conf -state readonly
3533 grid $top.from $top.fromsha1 -sticky w
3534 entry $top.fromhead -width 60 -relief flat
3535 $top.fromhead insert 0 $oldhead
3536 $top.fromhead conf -state readonly
3537 grid x $top.fromhead -sticky w
3538 label $top.to -text "To:"
3539 entry $top.tosha1 -width 40 -relief flat
3540 $top.tosha1 insert 0 $newid
3541 $top.tosha1 conf -state readonly
3542 grid $top.to $top.tosha1 -sticky w
3543 entry $top.tohead -width 60 -relief flat
3544 $top.tohead insert 0 $newhead
3545 $top.tohead conf -state readonly
3546 grid x $top.tohead -sticky w
3547 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
3548 grid $top.rev x -pady 10
3549 label $top.flab -text "Output file:"
3550 entry $top.fname -width 60
3551 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3553 grid $top.flab $top.fname -sticky w
3555 button $top.buts.gen -text "Generate" -command mkpatchgo
3556 button $top.buts.can -text "Cancel" -command mkpatchcan
3557 grid $top.buts.gen $top.buts.can
3558 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3559 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3560 grid $top.buts - -pady 10 -sticky ew
3564 proc mkpatchrev {} {
3567 set oldid [$patchtop.fromsha1 get]
3568 set oldhead [$patchtop.fromhead get]
3569 set newid [$patchtop.tosha1 get]
3570 set newhead [$patchtop.tohead get]
3571 foreach e [list fromsha1 fromhead tosha1 tohead] \
3572 v [list $newid $newhead $oldid $oldhead] {
3573 $patchtop.$e conf -state normal
3574 $patchtop.$e delete 0 end
3575 $patchtop.$e insert 0 $v
3576 $patchtop.$e conf -state readonly
3583 set oldid [$patchtop.fromsha1 get]
3584 set newid [$patchtop.tosha1 get]
3585 set fname [$patchtop.fname get]
3586 if {[catch {exec git-diff-tree -p $oldid $newid >$fname &} err]} {
3587 error_popup "Error creating patch: $err"
3589 catch {destroy $patchtop}
3593 proc mkpatchcan {} {
3596 catch {destroy $patchtop}
3601 global rowmenuid mktagtop commitinfo
3605 catch {destroy $top}
3607 label $top.title -text "Create tag"
3608 grid $top.title - -pady 10
3609 label $top.id -text "ID:"
3610 entry $top.sha1 -width 40 -relief flat
3611 $top.sha1 insert 0 $rowmenuid
3612 $top.sha1 conf -state readonly
3613 grid $top.id $top.sha1 -sticky w
3614 entry $top.head -width 60 -relief flat
3615 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3616 $top.head conf -state readonly
3617 grid x $top.head -sticky w
3618 label $top.tlab -text "Tag name:"
3619 entry $top.tag -width 60
3620 grid $top.tlab $top.tag -sticky w
3622 button $top.buts.gen -text "Create" -command mktaggo
3623 button $top.buts.can -text "Cancel" -command mktagcan
3624 grid $top.buts.gen $top.buts.can
3625 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3626 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3627 grid $top.buts - -pady 10 -sticky ew
3632 global mktagtop env tagids idtags
3634 set id [$mktagtop.sha1 get]
3635 set tag [$mktagtop.tag get]
3637 error_popup "No tag name specified"
3640 if {[info exists tagids($tag)]} {
3641 error_popup "Tag \"$tag\" already exists"
3646 set fname [file join $dir "refs/tags" $tag]
3647 set f [open $fname w]
3651 error_popup "Error creating tag: $err"
3655 set tagids($tag) $id
3656 lappend idtags($id) $tag
3660 proc redrawtags {id} {
3661 global canv linehtag commitrow idpos selectedline
3663 if {![info exists commitrow($id)]} return
3664 drawcmitrow $commitrow($id)
3665 $canv delete tag.$id
3666 set xt [eval drawtags $id $idpos($id)]
3667 $canv coords $linehtag($commitrow($id)) $xt [lindex $idpos($id) 2]
3668 if {[info exists selectedline] && $selectedline == $commitrow($id)} {
3669 selectline $selectedline 0
3676 catch {destroy $mktagtop}
3685 proc writecommit {} {
3686 global rowmenuid wrcomtop commitinfo wrcomcmd
3688 set top .writecommit
3690 catch {destroy $top}
3692 label $top.title -text "Write commit to file"
3693 grid $top.title - -pady 10
3694 label $top.id -text "ID:"
3695 entry $top.sha1 -width 40 -relief flat
3696 $top.sha1 insert 0 $rowmenuid
3697 $top.sha1 conf -state readonly
3698 grid $top.id $top.sha1 -sticky w
3699 entry $top.head -width 60 -relief flat
3700 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3701 $top.head conf -state readonly
3702 grid x $top.head -sticky w
3703 label $top.clab -text "Command:"
3704 entry $top.cmd -width 60 -textvariable wrcomcmd
3705 grid $top.clab $top.cmd -sticky w -pady 10
3706 label $top.flab -text "Output file:"
3707 entry $top.fname -width 60
3708 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3709 grid $top.flab $top.fname -sticky w
3711 button $top.buts.gen -text "Write" -command wrcomgo
3712 button $top.buts.can -text "Cancel" -command wrcomcan
3713 grid $top.buts.gen $top.buts.can
3714 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3715 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3716 grid $top.buts - -pady 10 -sticky ew
3723 set id [$wrcomtop.sha1 get]
3724 set cmd "echo $id | [$wrcomtop.cmd get]"
3725 set fname [$wrcomtop.fname get]
3726 if {[catch {exec sh -c $cmd >$fname &} err]} {
3727 error_popup "Error writing commit: $err"
3729 catch {destroy $wrcomtop}
3736 catch {destroy $wrcomtop}
3740 proc listrefs {id} {
3741 global idtags idheads idotherrefs
3744 if {[info exists idtags($id)]} {
3748 if {[info exists idheads($id)]} {
3752 if {[info exists idotherrefs($id)]} {
3753 set z $idotherrefs($id)
3755 return [list $x $y $z]
3758 proc rereadrefs {} {
3759 global idtags idheads idotherrefs
3761 set refids [concat [array names idtags] \
3762 [array names idheads] [array names idotherrefs]]
3763 foreach id $refids {
3764 if {![info exists ref($id)]} {
3765 set ref($id) [listrefs $id]
3769 set refids [lsort -unique [concat $refids [array names idtags] \
3770 [array names idheads] [array names idotherrefs]]]
3771 foreach id $refids {
3772 set v [listrefs $id]
3773 if {![info exists ref($id)] || $ref($id) != $v} {
3779 proc showtag {tag isnew} {
3780 global ctext cflist tagcontents tagids linknum
3783 addtohistory [list showtag $tag 0]
3785 $ctext conf -state normal
3786 $ctext delete 0.0 end
3788 if {[info exists tagcontents($tag)]} {
3789 set text $tagcontents($tag)
3791 set text "Tag: $tag\nId: $tagids($tag)"
3793 appendwithlinks $text
3794 $ctext conf -state disabled
3795 $cflist delete 0 end
3805 global maxwidth maxgraphpct diffopts findmergefiles
3806 global oldprefs prefstop
3810 if {[winfo exists $top]} {
3814 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3815 set oldprefs($v) [set $v]
3818 wm title $top "Gitk preferences"
3819 label $top.ldisp -text "Commit list display options"
3820 grid $top.ldisp - -sticky w -pady 10
3821 label $top.spacer -text " "
3822 label $top.maxwidthl -text "Maximum graph width (lines)" \
3824 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
3825 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
3826 label $top.maxpctl -text "Maximum graph width (% of pane)" \
3828 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
3829 grid x $top.maxpctl $top.maxpct -sticky w
3830 checkbutton $top.findm -variable findmergefiles
3831 label $top.findml -text "Include merges for \"Find\" in \"Files\"" \
3833 grid $top.findm $top.findml - -sticky w
3834 label $top.ddisp -text "Diff display options"
3835 grid $top.ddisp - -sticky w -pady 10
3836 label $top.diffoptl -text "Options for diff program" \
3838 entry $top.diffopt -width 20 -textvariable diffopts
3839 grid x $top.diffoptl $top.diffopt -sticky w
3841 button $top.buts.ok -text "OK" -command prefsok
3842 button $top.buts.can -text "Cancel" -command prefscan
3843 grid $top.buts.ok $top.buts.can
3844 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3845 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3846 grid $top.buts - - -pady 10 -sticky ew
3850 global maxwidth maxgraphpct diffopts findmergefiles
3851 global oldprefs prefstop
3853 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3854 set $v $oldprefs($v)
3856 catch {destroy $prefstop}
3861 global maxwidth maxgraphpct
3862 global oldprefs prefstop
3864 catch {destroy $prefstop}
3866 if {$maxwidth != $oldprefs(maxwidth)
3867 || $maxgraphpct != $oldprefs(maxgraphpct)} {
3872 proc formatdate {d} {
3873 return [clock format $d -format "%Y-%m-%d %H:%M:%S"]
3876 # This list of encoding names and aliases is distilled from
3877 # http://www.iana.org/assignments/character-sets.
3878 # Not all of them are supported by Tcl.
3879 set encoding_aliases {
3880 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
3881 ISO646-US US-ASCII us IBM367 cp367 csASCII }
3882 { ISO-10646-UTF-1 csISO10646UTF1 }
3883 { ISO_646.basic:1983 ref csISO646basic1983 }
3884 { INVARIANT csINVARIANT }
3885 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
3886 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
3887 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
3888 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
3889 { NATS-DANO iso-ir-9-1 csNATSDANO }
3890 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
3891 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
3892 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
3893 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
3894 { ISO-2022-KR csISO2022KR }
3896 { ISO-2022-JP csISO2022JP }
3897 { ISO-2022-JP-2 csISO2022JP2 }
3898 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
3900 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
3901 { IT iso-ir-15 ISO646-IT csISO15Italian }
3902 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
3903 { ES iso-ir-17 ISO646-ES csISO17Spanish }
3904 { greek7-old iso-ir-18 csISO18Greek7Old }
3905 { latin-greek iso-ir-19 csISO19LatinGreek }
3906 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
3907 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
3908 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
3909 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
3910 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
3911 { BS_viewdata iso-ir-47 csISO47BSViewdata }
3912 { INIS iso-ir-49 csISO49INIS }
3913 { INIS-8 iso-ir-50 csISO50INIS8 }
3914 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
3915 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
3916 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
3917 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
3918 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
3919 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
3921 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
3922 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
3923 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
3924 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
3925 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
3926 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
3927 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
3928 { greek7 iso-ir-88 csISO88Greek7 }
3929 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
3930 { iso-ir-90 csISO90 }
3931 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
3932 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
3933 csISO92JISC62991984b }
3934 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
3935 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
3936 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
3937 csISO95JIS62291984handadd }
3938 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
3939 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
3940 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
3941 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
3943 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
3944 { T.61-7bit iso-ir-102 csISO102T617bit }
3945 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
3946 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
3947 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
3948 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
3949 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
3950 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
3951 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
3952 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
3953 arabic csISOLatinArabic }
3954 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
3955 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
3956 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
3957 greek greek8 csISOLatinGreek }
3958 { T.101-G2 iso-ir-128 csISO128T101G2 }
3959 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
3961 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
3962 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
3963 { CSN_369103 iso-ir-139 csISO139CSN369103 }
3964 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
3965 { ISO_6937-2-add iso-ir-142 csISOTextComm }
3966 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
3967 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
3968 csISOLatinCyrillic }
3969 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
3970 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
3971 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
3972 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
3973 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
3974 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
3975 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
3976 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
3977 { ISO_10367-box iso-ir-155 csISO10367Box }
3978 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
3979 { latin-lap lap iso-ir-158 csISO158Lap }
3980 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
3981 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
3984 { JIS_X0201 X0201 csHalfWidthKatakana }
3985 { KSC5636 ISO646-KR csKSC5636 }
3986 { ISO-10646-UCS-2 csUnicode }
3987 { ISO-10646-UCS-4 csUCS4 }
3988 { DEC-MCS dec csDECMCS }
3989 { hp-roman8 roman8 r8 csHPRoman8 }
3990 { macintosh mac csMacintosh }
3991 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
3993 { IBM038 EBCDIC-INT cp038 csIBM038 }
3994 { IBM273 CP273 csIBM273 }
3995 { IBM274 EBCDIC-BE CP274 csIBM274 }
3996 { IBM275 EBCDIC-BR cp275 csIBM275 }
3997 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
3998 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
3999 { IBM280 CP280 ebcdic-cp-it csIBM280 }
4000 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
4001 { IBM284 CP284 ebcdic-cp-es csIBM284 }
4002 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
4003 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
4004 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
4005 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
4006 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
4007 { IBM424 cp424 ebcdic-cp-he csIBM424 }
4008 { IBM437 cp437 437 csPC8CodePage437 }
4009 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
4010 { IBM775 cp775 csPC775Baltic }
4011 { IBM850 cp850 850 csPC850Multilingual }
4012 { IBM851 cp851 851 csIBM851 }
4013 { IBM852 cp852 852 csPCp852 }
4014 { IBM855 cp855 855 csIBM855 }
4015 { IBM857 cp857 857 csIBM857 }
4016 { IBM860 cp860 860 csIBM860 }
4017 { IBM861 cp861 861 cp-is csIBM861 }
4018 { IBM862 cp862 862 csPC862LatinHebrew }
4019 { IBM863 cp863 863 csIBM863 }
4020 { IBM864 cp864 csIBM864 }
4021 { IBM865 cp865 865 csIBM865 }
4022 { IBM866 cp866 866 csIBM866 }
4023 { IBM868 CP868 cp-ar csIBM868 }
4024 { IBM869 cp869 869 cp-gr csIBM869 }
4025 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
4026 { IBM871 CP871 ebcdic-cp-is csIBM871 }
4027 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
4028 { IBM891 cp891 csIBM891 }
4029 { IBM903 cp903 csIBM903 }
4030 { IBM904 cp904 904 csIBBM904 }
4031 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
4032 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
4033 { IBM1026 CP1026 csIBM1026 }
4034 { EBCDIC-AT-DE csIBMEBCDICATDE }
4035 { EBCDIC-AT-DE-A csEBCDICATDEA }
4036 { EBCDIC-CA-FR csEBCDICCAFR }
4037 { EBCDIC-DK-NO csEBCDICDKNO }
4038 { EBCDIC-DK-NO-A csEBCDICDKNOA }
4039 { EBCDIC-FI-SE csEBCDICFISE }
4040 { EBCDIC-FI-SE-A csEBCDICFISEA }
4041 { EBCDIC-FR csEBCDICFR }
4042 { EBCDIC-IT csEBCDICIT }
4043 { EBCDIC-PT csEBCDICPT }
4044 { EBCDIC-ES csEBCDICES }
4045 { EBCDIC-ES-A csEBCDICESA }
4046 { EBCDIC-ES-S csEBCDICESS }
4047 { EBCDIC-UK csEBCDICUK }
4048 { EBCDIC-US csEBCDICUS }
4049 { UNKNOWN-8BIT csUnknown8BiT }
4050 { MNEMONIC csMnemonic }
4055 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
4056 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
4057 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
4058 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
4059 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
4060 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
4061 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
4062 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
4063 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
4064 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
4065 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
4066 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
4067 { IBM1047 IBM-1047 }
4068 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
4069 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
4070 { UNICODE-1-1 csUnicode11 }
4073 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
4074 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
4076 { ISO-8859-15 ISO_8859-15 Latin-9 }
4077 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
4078 { GBK CP936 MS936 windows-936 }
4079 { JIS_Encoding csJISEncoding }
4080 { Shift_JIS MS_Kanji csShiftJIS }
4081 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
4083 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
4084 { ISO-10646-UCS-Basic csUnicodeASCII }
4085 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
4086 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
4087 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
4088 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
4089 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
4090 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
4091 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
4092 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
4093 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
4094 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
4095 { Adobe-Standard-Encoding csAdobeStandardEncoding }
4096 { Ventura-US csVenturaUS }
4097 { Ventura-International csVenturaInternational }
4098 { PC8-Danish-Norwegian csPC8DanishNorwegian }
4099 { PC8-Turkish csPC8Turkish }
4100 { IBM-Symbols csIBMSymbols }
4101 { IBM-Thai csIBMThai }
4102 { HP-Legal csHPLegal }
4103 { HP-Pi-font csHPPiFont }
4104 { HP-Math8 csHPMath8 }
4105 { Adobe-Symbol-Encoding csHPPSMath }
4106 { HP-DeskTop csHPDesktop }
4107 { Ventura-Math csVenturaMath }
4108 { Microsoft-Publishing csMicrosoftPublishing }
4109 { Windows-31J csWindows31J }
4114 proc tcl_encoding {enc} {
4115 global encoding_aliases
4116 set names [encoding names]
4117 set lcnames [string tolower $names]
4118 set enc [string tolower $enc]
4119 set i [lsearch -exact $lcnames $enc]
4121 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
4122 if {[regsub {^iso[-_]} $enc iso encx]} {
4123 set i [lsearch -exact $lcnames $encx]
4127 foreach l $encoding_aliases {
4128 set ll [string tolower $l]
4129 if {[lsearch -exact $ll $enc] < 0} continue
4130 # look through the aliases for one that tcl knows about
4132 set i [lsearch -exact $lcnames $e]
4134 if {[regsub {^iso[-_]} $e iso ex]} {
4135 set i [lsearch -exact $lcnames $ex]
4144 return [lindex $names $i]
4151 set diffopts "-U 5 -p"
4152 set wrcomcmd "git-diff-tree --stdin -p --pretty"
4156 set gitencoding [exec git-repo-config --get i18n.commitencoding]
4158 if {$gitencoding == ""} {
4159 set gitencoding "utf-8"
4161 set tclencoding [tcl_encoding $gitencoding]
4162 if {$tclencoding == {}} {
4163 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
4166 set mainfont {Helvetica 9}
4167 set textfont {Courier 9}
4168 set uifont {Helvetica 9 bold}
4169 set findmergefiles 0
4178 set colors {green red blue magenta darkgrey brown orange}
4180 catch {source ~/.gitk}
4182 set namefont $mainfont
4184 font create optionfont -family sans-serif -size -12
4188 switch -regexp -- $arg {
4190 "^-d" { set datemode 1 }
4192 lappend revtreeargs $arg
4197 # check that we can find a .git directory somewhere...
4199 if {![file isdirectory $gitdir]} {
4200 error_popup "Cannot find the git directory \"$gitdir\"."
4220 set cmdline_files {}
4222 set fileargs [eval exec git-rev-parse --no-revs --no-flags $revtreeargs]
4223 set cmdline_files [split $fileargs "\n"]
4224 set n [llength $cmdline_files]
4225 set revtreeargs [lrange $revtreeargs 0 end-$n]
4227 if {[lindex $revtreeargs end] eq "--"} {
4228 set revtreeargs [lrange $revtreeargs 0 end-1]
4231 if {$cmdline_files ne {}} {
4232 # create a view for the files/dirs specified on the command line
4235 set viewname(1) "Command line"
4236 set viewfiles(1) $cmdline_files
4237 .bar.view add command -label $viewname(1) -command {showview 1}
4238 .bar.view entryconf 2 -state normal