2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2005-2006 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
12 if {[info exists env
(GIT_DIR
)]} {
15 return [exec git rev-parse
--git-dir]
19 # A simple scheduler for compute-intensive stuff.
20 # The aim is to make sure that event handlers for GUI actions can
21 # run at least every 50-100 ms. Unfortunately fileevent handlers are
22 # run before X event handlers, so reading from a fast source can
23 # make the GUI completely unresponsive.
28 if {[info exists isonrunq
($script)]} return
32 lappend runq
[list
{} $script]
33 set isonrunq
($script) 1
36 proc filerun
{fd
script} {
37 fileevent
$fd readable
[list filereadable
$fd $script]
40 proc filereadable
{fd
script} {
43 fileevent
$fd readable
{}
47 lappend runq
[list
$fd $script]
53 set tstart
[clock clicks
-milliseconds]
56 set fd
[lindex
$runq 0 0]
57 set script [lindex
$runq 0 1]
58 set repeat
[eval $script]
59 set t1
[clock clicks
-milliseconds]
60 set t
[expr {$t1 - $t0}]
61 set runq
[lrange
$runq 1 end
]
62 if {$repeat ne
{} && $repeat} {
63 if {$fd eq
{} ||
$repeat == 2} {
64 # script returns 1 if it wants to be readded
65 # file readers return 2 if they could do more straight away
66 lappend runq
[list
$fd $script]
68 fileevent
$fd readable
[list filereadable
$fd $script]
70 } elseif
{$fd eq
{}} {
71 unset isonrunq
($script)
74 if {$t1 - $tstart >= 80} break
81 # Start off a git rev-list process and arrange to read its output
82 proc start_rev_list
{view
} {
84 global commfd leftover tclencoding datemode
85 global viewargs viewfiles commitidx viewcomplete vnextroot
86 global showlocalchanges commitinterest mainheadid
88 set startmsecs
[clock clicks
-milliseconds]
89 set commitidx
($view) 0
90 set viewcomplete
($view) 0
91 set vnextroot
($view) 0
92 set order
"--topo-order"
94 set order
"--date-order"
97 set fd
[open
[concat | git log
-z --pretty=raw
$order --parents \
98 --boundary $viewargs($view) "--" $viewfiles($view)] r
]
100 error_popup
"Error executing git rev-list: $err"
103 set commfd
($view) $fd
104 set leftover
($view) {}
105 if {$showlocalchanges} {
106 lappend commitinterest
($mainheadid) {dodiffindex
}
108 fconfigure
$fd -blocking 0 -translation lf
-eofchar {}
109 if {$tclencoding != {}} {
110 fconfigure
$fd -encoding $tclencoding
112 filerun
$fd [list getcommitlines
$fd $view]
116 proc stop_rev_list
{} {
117 global commfd curview
119 if {![info exists commfd
($curview)]} return
120 set fd
$commfd($curview)
126 unset commfd
($curview)
130 global phase canv mainfont curview
134 start_rev_list
$curview
135 show_status
"Reading commits..."
138 # This makes a string representation of a positive integer which
139 # sorts as a string in numerical order
142 return [format
"%x" $n]
143 } elseif
{$n < 256} {
144 return [format
"x%.2x" $n]
145 } elseif
{$n < 65536} {
146 return [format
"y%.4x" $n]
148 return [format
"z%.8x" $n]
151 proc getcommitlines
{fd view
} {
152 global commitlisted commitinterest
153 global leftover commfd
154 global displayorder commitidx viewcomplete commitrow commitdata
155 global parentlist children curview hlview
156 global vparentlist vdisporder vcmitlisted
157 global ordertok vnextroot idpending
159 set stuff
[read $fd 500000]
160 # git log doesn't terminate the last commit with a null...
161 if {$stuff == {} && $leftover($view) ne
{} && [eof
$fd]} {
168 # Check if we have seen any ids listed as parents that haven't
169 # appeared in the list
170 foreach vid
[array names idpending
"$view,*"] {
171 # should only get here if git log is buggy
172 set id
[lindex
[split $vid ","] 1]
173 set commitrow
($vid) $commitidx($view)
174 incr commitidx
($view)
175 if {$view == $curview} {
176 lappend parentlist
{}
177 lappend displayorder
$id
178 lappend commitlisted
0
180 lappend vparentlist
($view) {}
181 lappend vdisporder
($view) $id
182 lappend vcmitlisted
($view) 0
185 set viewcomplete
($view) 1
189 # set it blocking so we wait for the process to terminate
190 fconfigure
$fd -blocking 1
191 if {[catch
{close
$fd} err
]} {
193 if {$view != $curview} {
194 set fv
" for the \"$viewname($view)\" view"
196 if {[string range
$err 0 4] == "usage"} {
197 set err
"Gitk: error reading commits$fv:\
198 bad arguments to git rev-list."
199 if {$viewname($view) eq
"Command line"} {
201 " (Note: arguments to gitk are passed to git rev-list\
202 to allow selection of commits to be displayed.)"
205 set err
"Error reading commits$fv: $err"
209 if {$view == $curview} {
210 run chewcommits
$view
217 set i
[string first
"\0" $stuff $start]
219 append leftover
($view) [string range
$stuff $start end
]
223 set cmit
$leftover($view)
224 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
225 set leftover
($view) {}
227 set cmit
[string range
$stuff $start [expr {$i - 1}]]
229 set start
[expr {$i + 1}]
230 set j
[string first
"\n" $cmit]
233 if {$j >= 0 && [string match
"commit *" $cmit]} {
234 set ids
[string range
$cmit 7 [expr {$j - 1}]]
235 if {[string match
{[-<>]*} $ids]} {
236 switch
-- [string index
$ids 0] {
241 set ids
[string range
$ids 1 end
]
245 if {[string length
$id] != 40} {
253 if {[string length
$shortcmit] > 80} {
254 set shortcmit
"[string range $shortcmit 0 80]..."
256 error_popup
"Can't parse git log output: {$shortcmit}"
259 set id
[lindex
$ids 0]
260 if {![info exists ordertok
($view,$id)]} {
261 set otok
"o[strrep $vnextroot($view)]"
262 incr vnextroot
($view)
263 set ordertok
($view,$id) $otok
265 set otok
$ordertok($view,$id)
266 unset idpending
($view,$id)
269 set olds
[lrange
$ids 1 end
]
270 if {[llength
$olds] == 1} {
271 set p
[lindex
$olds 0]
272 lappend children
($view,$p) $id
273 if {![info exists ordertok
($view,$p)]} {
274 set ordertok
($view,$p) $ordertok($view,$id)
275 set idpending
($view,$p) 1
280 if {$i == 0 ||
[lsearch
-exact $olds $p] >= $i} {
281 lappend children
($view,$p) $id
283 if {![info exists ordertok
($view,$p)]} {
284 set ordertok
($view,$p) "$otok[strrep $i]]"
285 set idpending
($view,$p) 1
293 if {![info exists children
($view,$id)]} {
294 set children
($view,$id) {}
296 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
297 set commitrow
($view,$id) $commitidx($view)
298 incr commitidx
($view)
299 if {$view == $curview} {
300 lappend parentlist
$olds
301 lappend displayorder
$id
302 lappend commitlisted
$listed
304 lappend vparentlist
($view) $olds
305 lappend vdisporder
($view) $id
306 lappend vcmitlisted
($view) $listed
308 if {[info exists commitinterest
($id)]} {
309 foreach
script $commitinterest($id) {
310 eval [string map
[list
"%I" $id] $script]
312 unset commitinterest
($id)
317 run chewcommits
$view
322 proc chewcommits
{view
} {
323 global curview hlview viewcomplete
324 global selectedline pending_select
326 if {$view == $curview} {
328 if {$viewcomplete($view)} {
329 global displayorder commitidx phase
330 global numcommits startmsecs
332 if {[info exists pending_select
]} {
333 set row
[first_real_row
]
336 if {$commitidx($curview) > 0} {
337 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
338 #puts "overall $ms ms for $numcommits commits"
340 show_status
"No commits selected"
346 if {[info exists hlview
] && $view == $hlview} {
352 proc readcommit
{id
} {
353 if {[catch
{set contents
[exec git cat-file commit
$id]}]} return
354 parsecommit
$id $contents 0
357 proc updatecommits
{} {
358 global viewdata curview phase displayorder ordertok idpending
359 global children commitrow selectedline thickerline showneartags
366 foreach id
$displayorder {
367 catch
{unset children
($n,$id)}
368 catch
{unset commitrow
($n,$id)}
369 catch
{unset ordertok
($n,$id)}
371 foreach vid
[array names idpending
"$n,*"] {
372 unset idpending
($vid)
375 catch
{unset selectedline
}
376 catch
{unset thickerline
}
377 catch
{unset viewdata
($n)}
386 proc parsecommit
{id contents listed
} {
387 global commitinfo cdate
396 set hdrend
[string first
"\n\n" $contents]
398 # should never happen...
399 set hdrend
[string length
$contents]
401 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
402 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
403 foreach line
[split $header "\n"] {
404 set tag
[lindex
$line 0]
405 if {$tag == "author"} {
406 set audate
[lindex
$line end-1
]
407 set auname
[lrange
$line 1 end-2
]
408 } elseif
{$tag == "committer"} {
409 set comdate
[lindex
$line end-1
]
410 set comname
[lrange
$line 1 end-2
]
414 # take the first non-blank line of the comment as the headline
415 set headline
[string trimleft
$comment]
416 set i
[string first
"\n" $headline]
418 set headline
[string range
$headline 0 $i]
420 set headline
[string trimright
$headline]
421 set i
[string first
"\r" $headline]
423 set headline
[string trimright
[string range
$headline 0 $i]]
426 # git rev-list indents the comment by 4 spaces;
427 # if we got this via git cat-file, add the indentation
429 foreach line
[split $comment "\n"] {
430 append newcomment
" "
431 append newcomment
$line
432 append newcomment
"\n"
434 set comment
$newcomment
436 if {$comdate != {}} {
437 set cdate
($id) $comdate
439 set commitinfo
($id) [list
$headline $auname $audate \
440 $comname $comdate $comment]
443 proc getcommit
{id
} {
444 global commitdata commitinfo
446 if {[info exists commitdata
($id)]} {
447 parsecommit
$id $commitdata($id) 1
450 if {![info exists commitinfo
($id)]} {
451 set commitinfo
($id) {"No commit information available"}
458 global tagids idtags headids idheads tagobjid
459 global otherrefids idotherrefs mainhead mainheadid
461 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
464 set refd
[open
[list | git show-ref
-d] r
]
465 while {[gets
$refd line
] >= 0} {
466 if {[string index
$line 40] ne
" "} continue
467 set id
[string range
$line 0 39]
468 set ref
[string range
$line 41 end
]
469 if {![string match
"refs/*" $ref]} continue
470 set name
[string range
$ref 5 end
]
471 if {[string match
"remotes/*" $name]} {
472 if {![string match
"*/HEAD" $name]} {
473 set headids
($name) $id
474 lappend idheads
($id) $name
476 } elseif
{[string match
"heads/*" $name]} {
477 set name
[string range
$name 6 end
]
478 set headids
($name) $id
479 lappend idheads
($id) $name
480 } elseif
{[string match
"tags/*" $name]} {
481 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
482 # which is what we want since the former is the commit ID
483 set name
[string range
$name 5 end
]
484 if {[string match
"*^{}" $name]} {
485 set name
[string range
$name 0 end-3
]
487 set tagobjid
($name) $id
489 set tagids
($name) $id
490 lappend idtags
($id) $name
492 set otherrefids
($name) $id
493 lappend idotherrefs
($id) $name
500 set thehead
[exec git symbolic-ref HEAD
]
501 if {[string match
"refs/heads/*" $thehead]} {
502 set mainhead
[string range
$thehead 11 end
]
503 if {[info exists headids
($mainhead)]} {
504 set mainheadid
$headids($mainhead)
510 # skip over fake commits
511 proc first_real_row
{} {
512 global nullid nullid2 displayorder numcommits
514 for {set row
0} {$row < $numcommits} {incr row
} {
515 set id
[lindex
$displayorder $row]
516 if {$id ne
$nullid && $id ne
$nullid2} {
523 # update things for a head moved to a child of its previous location
524 proc movehead
{id name
} {
525 global headids idheads
527 removehead
$headids($name) $name
528 set headids
($name) $id
529 lappend idheads
($id) $name
532 # update things when a head has been removed
533 proc removehead
{id name
} {
534 global headids idheads
536 if {$idheads($id) eq
$name} {
539 set i
[lsearch
-exact $idheads($id) $name]
541 set idheads
($id) [lreplace
$idheads($id) $i $i]
547 proc show_error
{w top msg
} {
548 message
$w.m
-text $msg -justify center
-aspect 400
549 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
550 button
$w.ok
-text OK
-command "destroy $top"
551 pack
$w.ok
-side bottom
-fill x
552 bind $top <Visibility
> "grab $top; focus $top"
553 bind $top <Key-Return
> "destroy $top"
557 proc error_popup msg
{
561 show_error
$w $w $msg
564 proc confirm_popup msg
{
570 message
$w.m
-text $msg -justify center
-aspect 400
571 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
572 button
$w.ok
-text OK
-command "set confirm_ok 1; destroy $w"
573 pack
$w.ok
-side left
-fill x
574 button
$w.cancel
-text Cancel
-command "destroy $w"
575 pack
$w.cancel
-side right
-fill x
576 bind $w <Visibility
> "grab $w; focus $w"
582 global canv canv2 canv3 linespc charspc ctext cflist
583 global textfont mainfont uifont tabstop
584 global findtype findtypemenu findloc findstring fstring geometry
585 global entries sha1entry sha1string sha1but
586 global diffcontextstring diffcontext
587 global maincursor textcursor curtextcursor
588 global rowctxmenu fakerowmenu mergemax wrapcomment
589 global highlight_files gdttype
590 global searchstring sstring
591 global bgcolor fgcolor bglist fglist diffcolors selectbgcolor
595 .bar add cascade
-label "File" -menu .bar.
file
596 .bar configure
-font $uifont
598 .bar.
file add
command -label "Update" -command updatecommits
599 .bar.
file add
command -label "Reread references" -command rereadrefs
600 .bar.
file add
command -label "List references" -command showrefs
601 .bar.
file add
command -label "Quit" -command doquit
602 .bar.
file configure
-font $uifont
604 .bar add cascade
-label "Edit" -menu .bar.edit
605 .bar.edit add
command -label "Preferences" -command doprefs
606 .bar.edit configure
-font $uifont
608 menu .bar.view
-font $uifont
609 .bar add cascade
-label "View" -menu .bar.view
610 .bar.view add
command -label "New view..." -command {newview
0}
611 .bar.view add
command -label "Edit view..." -command editview \
613 .bar.view add
command -label "Delete view" -command delview
-state disabled
614 .bar.view add separator
615 .bar.view add radiobutton
-label "All files" -command {showview
0} \
616 -variable selectedview
-value 0
619 .bar add cascade
-label "Help" -menu .bar.
help
620 .bar.
help add
command -label "About gitk" -command about
621 .bar.
help add
command -label "Key bindings" -command keys
622 .bar.
help configure
-font $uifont
623 . configure
-menu .bar
625 # the gui has upper and lower half, parts of a paned window.
626 panedwindow .ctop
-orient vertical
628 # possibly use assumed geometry
629 if {![info exists geometry
(pwsash0
)]} {
630 set geometry
(topheight
) [expr {15 * $linespc}]
631 set geometry
(topwidth
) [expr {80 * $charspc}]
632 set geometry
(botheight
) [expr {15 * $linespc}]
633 set geometry
(botwidth
) [expr {50 * $charspc}]
634 set geometry
(pwsash0
) "[expr {40 * $charspc}] 2"
635 set geometry
(pwsash1
) "[expr {60 * $charspc}] 2"
638 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
639 frame .tf
-height $geometry(topheight
) -width $geometry(topwidth
)
641 panedwindow .tf.histframe.pwclist
-orient horizontal
-sashpad 0 -handlesize 4
643 # create three canvases
644 set cscroll .tf.histframe.csb
645 set canv .tf.histframe.pwclist.canv
647 -selectbackground $selectbgcolor \
648 -background $bgcolor -bd 0 \
649 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
650 .tf.histframe.pwclist add
$canv
651 set canv2 .tf.histframe.pwclist.canv2
653 -selectbackground $selectbgcolor \
654 -background $bgcolor -bd 0 -yscrollincr $linespc
655 .tf.histframe.pwclist add
$canv2
656 set canv3 .tf.histframe.pwclist.canv3
658 -selectbackground $selectbgcolor \
659 -background $bgcolor -bd 0 -yscrollincr $linespc
660 .tf.histframe.pwclist add
$canv3
661 eval .tf.histframe.pwclist sash place
0 $geometry(pwsash0
)
662 eval .tf.histframe.pwclist sash place
1 $geometry(pwsash1
)
664 # a scroll bar to rule them
665 scrollbar
$cscroll -command {allcanvs yview
} -highlightthickness 0
666 pack
$cscroll -side right
-fill y
667 bind .tf.histframe.pwclist
<Configure
> {resizeclistpanes
%W
%w
}
668 lappend bglist
$canv $canv2 $canv3
669 pack .tf.histframe.pwclist
-fill both
-expand 1 -side left
671 # we have two button bars at bottom of top frame. Bar 1
673 frame .tf.lbar
-height 15
675 set sha1entry .tf.bar.sha1
676 set entries
$sha1entry
677 set sha1but .tf.bar.sha1label
678 button
$sha1but -text "SHA1 ID: " -state disabled
-relief flat \
679 -command gotocommit
-width 8 -font $uifont
680 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
681 pack .tf.bar.sha1label
-side left
682 entry
$sha1entry -width 40 -font $textfont -textvariable sha1string
683 trace add variable sha1string
write sha1change
684 pack
$sha1entry -side left
-pady 2
686 image create bitmap bm-left
-data {
687 #define left_width 16
688 #define left_height 16
689 static unsigned char left_bits
[] = {
690 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
691 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
692 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
694 image create bitmap bm-right
-data {
695 #define right_width 16
696 #define right_height 16
697 static unsigned char right_bits
[] = {
698 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
699 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
700 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
702 button .tf.bar.leftbut
-image bm-left
-command goback \
703 -state disabled
-width 26
704 pack .tf.bar.leftbut
-side left
-fill y
705 button .tf.bar.rightbut
-image bm-right
-command goforw \
706 -state disabled
-width 26
707 pack .tf.bar.rightbut
-side left
-fill y
709 button .tf.bar.findbut
-text "Find" -command dofind
-font $uifont
710 pack .tf.bar.findbut
-side left
712 set fstring .tf.bar.findstring
713 lappend entries
$fstring
714 entry
$fstring -width 30 -font $textfont -textvariable findstring
715 trace add variable findstring
write find_change
716 pack
$fstring -side left
-expand 1 -fill x
-in .tf.bar
718 set findtypemenu
[tk_optionMenu .tf.bar.findtype \
719 findtype Exact IgnCase Regexp
]
720 trace add variable findtype
write find_change
721 .tf.bar.findtype configure
-font $uifont
722 .tf.bar.findtype.menu configure
-font $uifont
723 set findloc
"All fields"
724 tk_optionMenu .tf.bar.findloc findloc
"All fields" Headline \
725 Comments Author Committer
726 trace add variable findloc
write find_change
727 .tf.bar.findloc configure
-font $uifont
728 .tf.bar.findloc.menu configure
-font $uifont
729 pack .tf.bar.findloc
-side right
730 pack .tf.bar.findtype
-side right
732 # build up the bottom bar of upper window
733 label .tf.lbar.flabel
-text "Highlight: Commits " \
735 pack .tf.lbar.flabel
-side left
-fill y
736 set gdttype
"touching paths:"
737 set gm
[tk_optionMenu .tf.lbar.gdttype gdttype
"touching paths:" \
738 "adding/removing string:"]
739 trace add variable gdttype
write hfiles_change
740 $gm conf
-font $uifont
741 .tf.lbar.gdttype conf
-font $uifont
742 pack .tf.lbar.gdttype
-side left
-fill y
743 entry .tf.lbar.fent
-width 25 -font $textfont \
744 -textvariable highlight_files
745 trace add variable highlight_files
write hfiles_change
746 lappend entries .tf.lbar.fent
747 pack .tf.lbar.fent
-side left
-fill x
-expand 1
748 label .tf.lbar.vlabel
-text " OR in view" -font $uifont
749 pack .tf.lbar.vlabel
-side left
-fill y
750 global viewhlmenu selectedhlview
751 set viewhlmenu
[tk_optionMenu .tf.lbar.vhl selectedhlview None
]
752 $viewhlmenu entryconf None
-command delvhighlight
753 $viewhlmenu conf
-font $uifont
754 .tf.lbar.vhl conf
-font $uifont
755 pack .tf.lbar.vhl
-side left
-fill y
756 label .tf.lbar.rlabel
-text " OR " -font $uifont
757 pack .tf.lbar.rlabel
-side left
-fill y
758 global highlight_related
759 set m
[tk_optionMenu .tf.lbar.relm highlight_related None \
760 "Descendent" "Not descendent" "Ancestor" "Not ancestor"]
761 $m conf
-font $uifont
762 .tf.lbar.relm conf
-font $uifont
763 trace add variable highlight_related
write vrel_change
764 pack .tf.lbar.relm
-side left
-fill y
766 # Finish putting the upper half of the viewer together
767 pack .tf.lbar
-in .tf
-side bottom
-fill x
768 pack .tf.bar
-in .tf
-side bottom
-fill x
769 pack .tf.histframe
-fill both
-side top
-expand 1
771 .ctop paneconfigure .tf
-height $geometry(topheight
)
772 .ctop paneconfigure .tf
-width $geometry(topwidth
)
774 # now build up the bottom
775 panedwindow .pwbottom
-orient horizontal
777 # lower left, a text box over search bar, scroll bar to the right
778 # if we know window height, then that will set the lower text height, otherwise
779 # we set lower text height which will drive window height
780 if {[info exists geometry
(main
)]} {
781 frame .bleft
-width $geometry(botwidth
)
783 frame .bleft
-width $geometry(botwidth
) -height $geometry(botheight
)
788 button .bleft.top.search
-text "Search" -command dosearch \
790 pack .bleft.top.search
-side left
-padx 5
791 set sstring .bleft.top.sstring
792 entry
$sstring -width 20 -font $textfont -textvariable searchstring
793 lappend entries
$sstring
794 trace add variable searchstring
write incrsearch
795 pack
$sstring -side left
-expand 1 -fill x
796 radiobutton .bleft.mid.
diff -text "Diff" \
797 -command changediffdisp
-variable diffelide
-value {0 0}
798 radiobutton .bleft.mid.old
-text "Old version" \
799 -command changediffdisp
-variable diffelide
-value {0 1}
800 radiobutton .bleft.mid.new
-text "New version" \
801 -command changediffdisp
-variable diffelide
-value {1 0}
802 label .bleft.mid.labeldiffcontext
-text " Lines of context: " \
804 pack .bleft.mid.
diff .bleft.mid.old .bleft.mid.new
-side left
805 spinbox .bleft.mid.diffcontext
-width 5 -font $textfont \
806 -from 1 -increment 1 -to 10000000 \
807 -validate all
-validatecommand "diffcontextvalidate %P" \
808 -textvariable diffcontextstring
809 .bleft.mid.diffcontext
set $diffcontext
810 trace add variable diffcontextstring
write diffcontextchange
811 lappend entries .bleft.mid.diffcontext
812 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext
-side left
813 set ctext .bleft.ctext
814 text
$ctext -background $bgcolor -foreground $fgcolor \
815 -tabs "[expr {$tabstop * $charspc}]" \
816 -state disabled
-font $textfont \
817 -yscrollcommand scrolltext
-wrap none
818 scrollbar .bleft.sb
-command "$ctext yview"
819 pack .bleft.top
-side top
-fill x
820 pack .bleft.mid
-side top
-fill x
821 pack .bleft.sb
-side right
-fill y
822 pack
$ctext -side left
-fill both
-expand 1
823 lappend bglist
$ctext
824 lappend fglist
$ctext
826 $ctext tag conf comment
-wrap $wrapcomment
827 $ctext tag conf filesep
-font [concat
$textfont bold
] -back "#aaaaaa"
828 $ctext tag conf hunksep
-fore [lindex
$diffcolors 2]
829 $ctext tag conf d0
-fore [lindex
$diffcolors 0]
830 $ctext tag conf d1
-fore [lindex
$diffcolors 1]
831 $ctext tag conf m0
-fore red
832 $ctext tag conf m1
-fore blue
833 $ctext tag conf m2
-fore green
834 $ctext tag conf m3
-fore purple
835 $ctext tag conf
m4 -fore brown
836 $ctext tag conf m5
-fore "#009090"
837 $ctext tag conf m6
-fore magenta
838 $ctext tag conf m7
-fore "#808000"
839 $ctext tag conf m8
-fore "#009000"
840 $ctext tag conf m9
-fore "#ff0080"
841 $ctext tag conf m10
-fore cyan
842 $ctext tag conf m11
-fore "#b07070"
843 $ctext tag conf m12
-fore "#70b0f0"
844 $ctext tag conf m13
-fore "#70f0b0"
845 $ctext tag conf m14
-fore "#f0b070"
846 $ctext tag conf m15
-fore "#ff70b0"
847 $ctext tag conf mmax
-fore darkgrey
849 $ctext tag conf mresult
-font [concat
$textfont bold
]
850 $ctext tag conf msep
-font [concat
$textfont bold
]
851 $ctext tag conf found
-back yellow
854 .pwbottom paneconfigure .bleft
-width $geometry(botwidth
)
859 radiobutton .bright.mode.
patch -text "Patch" \
860 -command reselectline
-variable cmitmode
-value "patch"
861 .bright.mode.
patch configure
-font $uifont
862 radiobutton .bright.mode.tree
-text "Tree" \
863 -command reselectline
-variable cmitmode
-value "tree"
864 .bright.mode.tree configure
-font $uifont
865 grid .bright.mode.
patch .bright.mode.tree
-sticky ew
866 pack .bright.mode
-side top
-fill x
867 set cflist .bright.cfiles
868 set indent
[font measure
$mainfont "nn"]
870 -selectbackground $selectbgcolor \
871 -background $bgcolor -foreground $fgcolor \
873 -tabs [list
$indent [expr {2 * $indent}]] \
874 -yscrollcommand ".bright.sb set" \
875 -cursor [. cget
-cursor] \
876 -spacing1 1 -spacing3 1
877 lappend bglist
$cflist
878 lappend fglist
$cflist
879 scrollbar .bright.sb
-command "$cflist yview"
880 pack .bright.sb
-side right
-fill y
881 pack
$cflist -side left
-fill both
-expand 1
882 $cflist tag configure highlight \
883 -background [$cflist cget
-selectbackground]
884 $cflist tag configure bold
-font [concat
$mainfont bold
]
886 .pwbottom add .bright
889 # restore window position if known
890 if {[info exists geometry
(main
)]} {
891 wm geometry .
"$geometry(main)"
894 if {[tk windowingsystem
] eq
{aqua
}} {
900 bind .pwbottom
<Configure
> {resizecdetpanes
%W
%w
}
901 pack .ctop
-fill both
-expand 1
902 bindall
<1> {selcanvline
%W
%x
%y
}
903 #bindall <B1-Motion> {selcanvline %W %x %y}
904 if {[tk windowingsystem
] == "win32"} {
905 bind .
<MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
}
906 bind $ctext <MouseWheel
> { windows_mousewheel_redirector
%W
%X
%Y
%D
; break }
908 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
909 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
911 bindall
<2> "canvscan mark %W %x %y"
912 bindall
<B2-Motion
> "canvscan dragto %W %x %y"
913 bindkey
<Home
> selfirstline
914 bindkey
<End
> sellastline
915 bind .
<Key-Up
> "selnextline -1"
916 bind .
<Key-Down
> "selnextline 1"
917 bind .
<Shift-Key-Up
> "next_highlight -1"
918 bind .
<Shift-Key-Down
> "next_highlight 1"
919 bindkey
<Key-Right
> "goforw"
920 bindkey
<Key-Left
> "goback"
921 bind .
<Key-Prior
> "selnextpage -1"
922 bind .
<Key-Next
> "selnextpage 1"
923 bind .
<$M1B-Home> "allcanvs yview moveto 0.0"
924 bind .
<$M1B-End> "allcanvs yview moveto 1.0"
925 bind .
<$M1B-Key-Up> "allcanvs yview scroll -1 units"
926 bind .
<$M1B-Key-Down> "allcanvs yview scroll 1 units"
927 bind .
<$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
928 bind .
<$M1B-Key-Next> "allcanvs yview scroll 1 pages"
929 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
930 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
931 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
932 bindkey p
"selnextline -1"
933 bindkey n
"selnextline 1"
936 bindkey i
"selnextline -1"
937 bindkey k
"selnextline 1"
940 bindkey b
"$ctext yview scroll -1 pages"
941 bindkey d
"$ctext yview scroll 18 units"
942 bindkey u
"$ctext yview scroll -18 units"
943 bindkey
/ {findnext
1}
944 bindkey
<Key-Return
> {findnext
0}
947 bindkey
<F5
> updatecommits
948 bind .
<$M1B-q> doquit
949 bind .
<$M1B-f> dofind
950 bind .
<$M1B-g> {findnext
0}
951 bind .
<$M1B-r> dosearchback
952 bind .
<$M1B-s> dosearch
953 bind .
<$M1B-equal> {incrfont
1}
954 bind .
<$M1B-KP_Add> {incrfont
1}
955 bind .
<$M1B-minus> {incrfont
-1}
956 bind .
<$M1B-KP_Subtract> {incrfont
-1}
957 wm protocol . WM_DELETE_WINDOW doquit
958 bind .
<Button-1
> "click %W"
959 bind $fstring <Key-Return
> dofind
960 bind $sha1entry <Key-Return
> gotocommit
961 bind $sha1entry <<PasteSelection>> clearsha1
962 bind $cflist <1> {sel_flist %W %x %y; break}
963 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
964 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
965 bind $cflist <Button-3> {pop_flist_menu %W %X %Y %x %y}
967 set maincursor [. cget -cursor]
968 set textcursor [$ctext cget -cursor]
969 set curtextcursor $textcursor
971 set rowctxmenu .rowctxmenu
972 menu $rowctxmenu -tearoff 0
973 $rowctxmenu add command -label "Diff this -> selected" \
974 -command {diffvssel 0}
975 $rowctxmenu add command -label "Diff selected -> this" \
976 -command {diffvssel 1}
977 $rowctxmenu add command -label "Make patch" -command mkpatch
978 $rowctxmenu add command -label "Create tag" -command mktag
979 $rowctxmenu add command -label "Write commit to file" -command writecommit
980 $rowctxmenu add command -label "Create new branch" -command mkbranch
981 $rowctxmenu add command -label "Cherry-pick this commit" \
983 $rowctxmenu add command -label "Reset HEAD branch to here" \
986 set fakerowmenu .fakerowmenu
987 menu $fakerowmenu -tearoff 0
988 $fakerowmenu add command -label "Diff this -> selected" \
989 -command {diffvssel 0}
990 $fakerowmenu add command -label "Diff selected -> this" \
991 -command {diffvssel 1}
992 $fakerowmenu add command -label "Make patch" -command mkpatch
993 # $fakerowmenu add command -label "Commit" -command {mkcommit 0}
994 # $fakerowmenu add command -label "Commit all" -command {mkcommit 1}
995 # $fakerowmenu add command -label "Revert local changes" -command revertlocal
997 set headctxmenu .headctxmenu
998 menu $headctxmenu -tearoff 0
999 $headctxmenu add command -label "Check out this branch" \
1001 $headctxmenu add command -label "Remove this branch" \
1005 set flist_menu .flistctxmenu
1006 menu $flist_menu -tearoff 0
1007 $flist_menu add command -label "Highlight this too" \
1008 -command {flist_hl 0}
1009 $flist_menu add command -label "Highlight this only" \
1010 -command {flist_hl 1}
1013 # Windows sends all mouse wheel events to the current focused window, not
1014 # the one where the mouse hovers, so bind those events here and redirect
1015 # to the correct window
1016 proc windows_mousewheel_redirector {W X Y D} {
1017 global canv canv2 canv3
1018 set w [winfo containing -displayof $W $X $Y]
1020 set u [expr {$D < 0 ? 5 : -5}]
1021 if {$w == $canv || $w == $canv2 || $w == $canv3} {
1022 allcanvs yview scroll $u units
1025 $w yview scroll $u units
1031 # mouse-2 makes all windows scan vertically, but only the one
1032 # the cursor is in scans horizontally
1033 proc canvscan {op w x y} {
1034 global canv canv2 canv3
1035 foreach c [list $canv $canv2 $canv3] {
1044 proc scrollcanv {cscroll f0 f1} {
1045 $cscroll set $f0 $f1
1050 # when we make a key binding for the toplevel, make sure
1051 # it doesn't get triggered when that key is pressed in the
1052 # find string entry widget.
1053 proc bindkey {ev script} {
1056 set escript [bind Entry $ev]
1057 if {$escript == {}} {
1058 set escript [bind Entry <Key>]
1060 foreach e $entries {
1061 bind $e $ev "$escript; break"
1065 # set the focus back to the toplevel for any click outside
1068 global ctext entries
1069 foreach e [concat $entries $ctext] {
1070 if {$w == $e} return
1075 proc savestuff {w} {
1076 global canv canv2 canv3 ctext cflist mainfont textfont uifont tabstop
1077 global stuffsaved findmergefiles maxgraphpct
1078 global maxwidth showneartags showlocalchanges
1079 global viewname viewfiles viewargs viewperm nextviewnum
1080 global cmitmode wrapcomment datetimeformat
1081 global colors bgcolor fgcolor diffcolors diffcontext selectbgcolor
1083 if {$stuffsaved} return
1084 if {![winfo viewable .]} return
1086 set f [open "~/.gitk-new" w]
1087 puts $f [list set mainfont $mainfont]
1088 puts $f [list set textfont $textfont]
1089 puts $f [list set uifont $uifont]
1090 puts $f [list set tabstop $tabstop]
1091 puts $f [list set findmergefiles $findmergefiles]
1092 puts $f [list set maxgraphpct $maxgraphpct]
1093 puts $f [list set maxwidth $maxwidth]
1094 puts $f [list set cmitmode $cmitmode]
1095 puts $f [list set wrapcomment $wrapcomment]
1096 puts $f [list set showneartags $showneartags]
1097 puts $f [list set showlocalchanges $showlocalchanges]
1098 puts $f [list set datetimeformat $datetimeformat]
1099 puts $f [list set bgcolor $bgcolor]
1100 puts $f [list set fgcolor $fgcolor]
1101 puts $f [list set colors $colors]
1102 puts $f [list set diffcolors $diffcolors]
1103 puts $f [list set diffcontext $diffcontext]
1104 puts $f [list set selectbgcolor $selectbgcolor]
1106 puts $f "set geometry(main) [wm geometry .]"
1107 puts $f "set geometry(topwidth) [winfo width .tf]"
1108 puts $f "set geometry(topheight) [winfo height .tf]"
1109 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
1110 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
1111 puts $f "set geometry(botwidth) [winfo width .bleft]"
1112 puts $f "set geometry(botheight) [winfo height .bleft]"
1114 puts -nonewline $f "set permviews {"
1115 for {set v 0} {$v < $nextviewnum} {incr v} {
1116 if {$viewperm($v)} {
1117 puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v)]}"
1122 file rename -force "~/.gitk-new" "~/.gitk"
1127 proc resizeclistpanes {win w} {
1129 if {[info exists oldwidth($win)]} {
1130 set s0 [$win sash coord 0]
1131 set s1 [$win sash coord 1]
1133 set sash0 [expr {int($w/2 - 2)}]
1134 set sash1 [expr {int($w*5/6 - 2)}]
1136 set factor [expr {1.0 * $w / $oldwidth($win)}]
1137 set sash0 [expr {int($factor * [lindex $s0 0])}]
1138 set sash1 [expr {int($factor * [lindex $s1 0])}]
1142 if {$sash1 < $sash0 + 20} {
1143 set sash1 [expr {$sash0 + 20}]
1145 if {$sash1 > $w - 10} {
1146 set sash1 [expr {$w - 10}]
1147 if {$sash0 > $sash1 - 20} {
1148 set sash0 [expr {$sash1 - 20}]
1152 $win sash place 0 $sash0 [lindex $s0 1]
1153 $win sash place 1 $sash1 [lindex $s1 1]
1155 set oldwidth($win) $w
1158 proc resizecdetpanes {win w} {
1160 if {[info exists oldwidth($win)]} {
1161 set s0 [$win sash coord 0]
1163 set sash0 [expr {int($w*3/4 - 2)}]
1165 set factor [expr {1.0 * $w / $oldwidth($win)}]
1166 set sash0 [expr {int($factor * [lindex $s0 0])}]
1170 if {$sash0 > $w - 15} {
1171 set sash0 [expr {$w - 15}]
1174 $win sash place 0 $sash0 [lindex $s0 1]
1176 set oldwidth($win) $w
1179 proc allcanvs args {
1180 global canv canv2 canv3
1186 proc bindall {event action} {
1187 global canv canv2 canv3
1188 bind $canv $event $action
1189 bind $canv2 $event $action
1190 bind $canv3 $event $action
1196 if {[winfo exists $w]} {
1201 wm title $w "About gitk"
1202 message $w.m -text {
1203 Gitk - a commit viewer for git
1205 Copyright © 2005-2006 Paul Mackerras
1207 Use and redistribute under the terms of the GNU General Public License} \
1208 -justify center -aspect 400 -border 2 -bg white -relief groove
1209 pack $w.m -side top -fill x -padx 2 -pady 2
1210 $w.m configure -font $uifont
1211 button $w.ok -text Close -command "destroy $w" -default active
1212 pack $w.ok -side bottom
1213 $w.ok configure -font $uifont
1214 bind $w <Visibility> "focus $w.ok"
1215 bind $w <Key-Escape> "destroy $w"
1216 bind $w <Key-Return> "destroy $w"
1222 if {[winfo exists $w]} {
1226 if {[tk windowingsystem] eq {aqua}} {
1232 wm title $w "Gitk key bindings"
1233 message $w.m -text "
1237 <Home> Move to first commit
1238 <End> Move to last commit
1239 <Up>, p, i Move up one commit
1240 <Down>, n, k Move down one commit
1241 <Left>, z, j Go back in history list
1242 <Right>, x, l Go forward in history list
1243 <PageUp> Move up one page in commit list
1244 <PageDown> Move down one page in commit list
1245 <$M1T-Home> Scroll to top of commit list
1246 <$M1T-End> Scroll to bottom of commit list
1247 <$M1T-Up> Scroll commit list up one line
1248 <$M1T-Down> Scroll commit list down one line
1249 <$M1T-PageUp> Scroll commit list up one page
1250 <$M1T-PageDown> Scroll commit list down one page
1251 <Shift-Up> Move to previous highlighted line
1252 <Shift-Down> Move to next highlighted line
1253 <Delete>, b Scroll diff view up one page
1254 <Backspace> Scroll diff view up one page
1255 <Space> Scroll diff view down one page
1256 u Scroll diff view up 18 lines
1257 d Scroll diff view down 18 lines
1259 <$M1T-G> Move to next find hit
1260 <Return> Move to next find hit
1261 / Move to next find hit, or redo find
1262 ? Move to previous find hit
1263 f Scroll diff view to next file
1264 <$M1T-S> Search for next hit in diff view
1265 <$M1T-R> Search for previous hit in diff view
1266 <$M1T-KP+> Increase font size
1267 <$M1T-plus> Increase font size
1268 <$M1T-KP-> Decrease font size
1269 <$M1T-minus> Decrease font size
1272 -justify left -bg white -border 2 -relief groove
1273 pack $w.m -side top -fill both -padx 2 -pady 2
1274 $w.m configure -font $uifont
1275 button $w.ok -text Close -command "destroy $w" -default active
1276 pack $w.ok -side bottom
1277 $w.ok configure -font $uifont
1278 bind $w <Visibility> "focus $w.ok"
1279 bind $w <Key-Escape> "destroy $w"
1280 bind $w <Key-Return> "destroy $w"
1283 # Procedures for manipulating the file list window at the
1284 # bottom right of the overall window.
1286 proc treeview {w l openlevs} {
1287 global treecontents treediropen treeheight treeparent treeindex
1297 set treecontents() {}
1298 $w conf -state normal
1300 while {[string range $f 0 $prefixend] ne $prefix} {
1301 if {$lev <= $openlevs} {
1302 $w mark set e:$treeindex($prefix) "end -1c"
1303 $w mark gravity e:$treeindex($prefix) left
1305 set treeheight($prefix) $ht
1306 incr ht [lindex $htstack end]
1307 set htstack [lreplace $htstack end end]
1308 set prefixend [lindex $prefendstack end]
1309 set prefendstack [lreplace $prefendstack end end]
1310 set prefix [string range $prefix 0 $prefixend]
1313 set tail [string range $f [expr {$prefixend+1}] end]
1314 while {[set slash [string first "/" $tail]] >= 0} {
1317 lappend prefendstack $prefixend
1318 incr prefixend [expr {$slash + 1}]
1319 set d [string range $tail 0 $slash]
1320 lappend treecontents($prefix) $d
1321 set oldprefix $prefix
1323 set treecontents($prefix) {}
1324 set treeindex($prefix) [incr ix]
1325 set treeparent($prefix) $oldprefix
1326 set tail [string range $tail [expr {$slash+1}] end]
1327 if {$lev <= $openlevs} {
1329 set treediropen($prefix) [expr {$lev < $openlevs}]
1330 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
1331 $w mark set d:$ix "end -1c"
1332 $w mark gravity d:$ix left
1334 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
1336 $w image create end -align center -image $bm -padx 1 \
1338 $w insert end $d [highlight_tag $prefix]
1339 $w mark set s:$ix "end -1c"
1340 $w mark gravity s:$ix left
1345 if {$lev <= $openlevs} {
1348 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
1350 $w insert end $tail [highlight_tag $f]
1352 lappend treecontents($prefix) $tail
1355 while {$htstack ne {}} {
1356 set treeheight($prefix) $ht
1357 incr ht [lindex $htstack end]
1358 set htstack [lreplace $htstack end end]
1359 set prefixend [lindex $prefendstack end]
1360 set prefendstack [lreplace $prefendstack end end]
1361 set prefix [string range $prefix 0 $prefixend]
1363 $w conf -state disabled
1366 proc linetoelt {l} {
1367 global treeheight treecontents
1372 foreach e $treecontents($prefix) {
1377 if {[string index $e end] eq "/"} {
1378 set n $treeheight($prefix$e)
1390 proc highlight_tree {y prefix} {
1391 global treeheight treecontents cflist
1393 foreach e $treecontents($prefix) {
1395 if {[highlight_tag $path] ne {}} {
1396 $cflist tag add bold $y.0 "$y.0 lineend"
1399 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
1400 set y [highlight_tree $y $path]
1406 proc treeclosedir {w dir} {
1407 global treediropen treeheight treeparent treeindex
1409 set ix $treeindex($dir)
1410 $w conf -state normal
1411 $w delete s:$ix e:$ix
1412 set treediropen($dir) 0
1413 $w image configure a:$ix -image tri-rt
1414 $w conf -state disabled
1415 set n [expr {1 - $treeheight($dir)}]
1416 while {$dir ne {}} {
1417 incr treeheight($dir) $n
1418 set dir $treeparent($dir)
1422 proc treeopendir {w dir} {
1423 global treediropen treeheight treeparent treecontents treeindex
1425 set ix $treeindex($dir)
1426 $w conf -state normal
1427 $w image configure a:$ix -image tri-dn
1428 $w mark set e:$ix s:$ix
1429 $w mark gravity e:$ix right
1432 set n [llength $treecontents($dir)]
1433 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
1436 incr treeheight($x) $n
1438 foreach e $treecontents($dir) {
1440 if {[string index $e end] eq "/"} {
1441 set iy $treeindex($de)
1442 $w mark set d:$iy e:$ix
1443 $w mark gravity d:$iy left
1444 $w insert e:$ix $str
1445 set treediropen($de) 0
1446 $w image create e:$ix -align center -image tri-rt -padx 1 \
1448 $w insert e:$ix $e [highlight_tag $de]
1449 $w mark set s:$iy e:$ix
1450 $w mark gravity s:$iy left
1451 set treeheight($de) 1
1453 $w insert e:$ix $str
1454 $w insert e:$ix $e [highlight_tag $de]
1457 $w mark gravity e:$ix left
1458 $w conf -state disabled
1459 set treediropen($dir) 1
1460 set top [lindex [split [$w index @0,0] .] 0]
1461 set ht [$w cget -height]
1462 set l [lindex [split [$w index s:$ix] .] 0]
1465 } elseif {$l + $n + 1 > $top + $ht} {
1466 set top [expr {$l + $n + 2 - $ht}]
1474 proc treeclick {w x y} {
1475 global treediropen cmitmode ctext cflist cflist_top
1477 if {$cmitmode ne "tree"} return
1478 if {![info exists cflist_top]} return
1479 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1480 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
1481 $cflist tag add highlight $l.0 "$l.0 lineend"
1487 set e [linetoelt $l]
1488 if {[string index $e end] ne "/"} {
1490 } elseif {$treediropen($e)} {
1497 proc setfilelist {id} {
1498 global treefilelist cflist
1500 treeview $cflist $treefilelist($id) 0
1503 image create bitmap tri-rt -background black -foreground blue -data {
1504 #define tri-rt_width 13
1505 #define tri-rt_height 13
1506 static unsigned char tri-rt_bits[] = {
1507 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
1508 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
1511 #define tri-rt-mask_width 13
1512 #define tri-rt-mask_height 13
1513 static unsigned char tri-rt-mask_bits[] = {
1514 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
1515 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
1518 image create bitmap tri-dn -background black -foreground blue -data {
1519 #define tri-dn_width 13
1520 #define tri-dn_height 13
1521 static unsigned char tri-dn_bits[] = {
1522 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
1523 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1526 #define tri-dn-mask_width 13
1527 #define tri-dn-mask_height 13
1528 static unsigned char tri-dn-mask_bits[] = {
1529 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
1530 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1534 image create bitmap reficon-T -background black -foreground yellow -data {
1535 #define tagicon_width 13
1536 #define tagicon_height 9
1537 static unsigned char tagicon_bits[] = {
1538 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
1539 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
1541 #define tagicon-mask_width 13
1542 #define tagicon-mask_height 9
1543 static unsigned char tagicon-mask_bits[] = {
1544 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
1545 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
1548 #define headicon_width 13
1549 #define headicon_height 9
1550 static unsigned char headicon_bits[] = {
1551 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
1552 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
1555 #define headicon-mask_width 13
1556 #define headicon-mask_height 9
1557 static unsigned char headicon-mask_bits[] = {
1558 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
1559 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
1561 image create bitmap reficon-H -background black -foreground green \
1562 -data $rectdata -maskdata $rectmask
1563 image create bitmap reficon-o -background black -foreground "#ddddff" \
1564 -data $rectdata -maskdata $rectmask
1566 proc init_flist {first} {
1567 global cflist cflist_top selectedline difffilestart
1569 $cflist conf -state normal
1570 $cflist delete 0.0 end
1572 $cflist insert end $first
1574 $cflist tag add highlight 1.0 "1.0 lineend"
1576 catch {unset cflist_top}
1578 $cflist conf -state disabled
1579 set difffilestart {}
1582 proc highlight_tag {f} {
1583 global highlight_paths
1585 foreach p $highlight_paths {
1586 if {[string match $p $f]} {
1593 proc highlight_filelist {} {
1594 global cmitmode cflist
1596 $cflist conf -state normal
1597 if {$cmitmode ne "tree"} {
1598 set end [lindex [split [$cflist index end] .] 0]
1599 for {set l 2} {$l < $end} {incr l} {
1600 set line [$cflist get $l.0 "$l.0 lineend"]
1601 if {[highlight_tag $line] ne {}} {
1602 $cflist tag add bold $l.0 "$l.0 lineend"
1608 $cflist conf -state disabled
1611 proc unhighlight_filelist {} {
1614 $cflist conf -state normal
1615 $cflist tag remove bold 1.0 end
1616 $cflist conf -state disabled
1619 proc add_flist {fl} {
1622 $cflist conf -state normal
1624 $cflist insert end "\n"
1625 $cflist insert end $f [highlight_tag $f]
1627 $cflist conf -state disabled
1630 proc sel_flist {w x y} {
1631 global ctext difffilestart cflist cflist_top cmitmode
1633 if {$cmitmode eq "tree"} return
1634 if {![info exists cflist_top]} return
1635 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1636 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
1637 $cflist tag add highlight $l.0 "$l.0 lineend"
1642 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
1646 proc pop_flist_menu {w X Y x y} {
1647 global ctext cflist cmitmode flist_menu flist_menu_file
1648 global treediffs diffids
1650 set l [lindex [split [$w index "@$x,$y"] "."] 0]
1652 if {$cmitmode eq "tree"} {
1653 set e [linetoelt $l]
1654 if {[string index $e end] eq "/"} return
1656 set e [lindex $treediffs($diffids) [expr {$l-2}]]
1658 set flist_menu_file $e
1659 tk_popup $flist_menu $X $Y
1662 proc flist_hl {only} {
1663 global flist_menu_file highlight_files
1665 set x [shellquote $flist_menu_file]
1666 if {$only || $highlight_files eq {}} {
1667 set highlight_files $x
1669 append highlight_files " " $x
1673 # Functions for adding and removing shell-type quoting
1675 proc shellquote {str} {
1676 if {![string match "*\['\"\\ \t]*" $str]} {
1679 if {![string match "*\['\"\\]*" $str]} {
1682 if {![string match "*'*" $str]} {
1685 return "\"[string map {\" \\\" \\ \\\\} $str]\""
1688 proc shellarglist {l} {
1694 append str [shellquote $a]
1699 proc shelldequote {str} {
1704 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
1705 append ret [string range $str $used end]
1706 set used [string length $str]
1709 set first [lindex $first 0]
1710 set ch [string index $str $first]
1711 if {$first > $used} {
1712 append ret [string range $str $used [expr {$first - 1}]]
1715 if {$ch eq " " || $ch eq "\t"} break
1718 set first [string first "'" $str $used]
1720 error "unmatched single-quote"
1722 append ret [string range $str $used [expr {$first - 1}]]
1727 if {$used >= [string length $str]} {
1728 error "trailing backslash"
1730 append ret [string index $str $used]
1735 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
1736 error "unmatched double-quote"
1738 set first [lindex $first 0]
1739 set ch [string index $str $first]
1740 if {$first > $used} {
1741 append ret [string range $str $used [expr {$first - 1}]]
1744 if {$ch eq "\""} break
1746 append ret [string index $str $used]
1750 return [list $used $ret]
1753 proc shellsplit {str} {
1756 set str [string trimleft $str]
1757 if {$str eq {}} break
1758 set dq [shelldequote $str]
1759 set n [lindex $dq 0]
1760 set word [lindex $dq 1]
1761 set str [string range $str $n end]
1767 # Code to implement multiple views
1769 proc newview {ishighlight} {
1770 global nextviewnum newviewname newviewperm uifont newishighlight
1771 global newviewargs revtreeargs
1773 set newishighlight $ishighlight
1775 if {[winfo exists $top]} {
1779 set newviewname($nextviewnum) "View $nextviewnum"
1780 set newviewperm($nextviewnum) 0
1781 set newviewargs($nextviewnum) [shellarglist $revtreeargs]
1782 vieweditor $top $nextviewnum "Gitk view definition"
1787 global viewname viewperm newviewname newviewperm
1788 global viewargs newviewargs
1790 set top .gitkvedit-$curview
1791 if {[winfo exists $top]} {
1795 set newviewname($curview) $viewname($curview)
1796 set newviewperm($curview) $viewperm($curview)
1797 set newviewargs($curview) [shellarglist $viewargs($curview)]
1798 vieweditor $top $curview "Gitk: edit view $viewname($curview)"
1801 proc vieweditor {top n title} {
1802 global newviewname newviewperm viewfiles
1806 wm title $top $title
1807 label $top.nl -text "Name" -font $uifont
1808 entry $top.name -width 20 -textvariable newviewname($n) -font $uifont
1809 grid $top.nl $top.name -sticky w -pady 5
1810 checkbutton $top.perm -text "Remember this view" -variable newviewperm($n) \
1812 grid $top.perm - -pady 5 -sticky w
1813 message $top.al -aspect 1000 -font $uifont \
1814 -text "Commits to include (arguments to git rev-list):"
1815 grid $top.al - -sticky w -pady 5
1816 entry $top.args -width 50 -textvariable newviewargs($n) \
1817 -background white -font $uifont
1818 grid $top.args - -sticky ew -padx 5
1819 message $top.l -aspect 1000 -font $uifont \
1820 -text "Enter files and directories to include, one per line:"
1821 grid $top.l - -sticky w
1822 text $top.t -width 40 -height 10 -background white -font $uifont
1823 if {[info exists viewfiles($n)]} {
1824 foreach f $viewfiles($n) {
1825 $top.t insert end $f
1826 $top.t insert end "\n"
1828 $top.t delete {end - 1c} end
1829 $top.t mark set insert 0.0
1831 grid $top.t - -sticky ew -padx 5
1833 button $top.buts.ok -text "OK" -command [list newviewok $top $n] \
1835 button $top.buts.can -text "Cancel" -command [list destroy $top] \
1837 grid $top.buts.ok $top.buts.can
1838 grid columnconfigure $top.buts 0 -weight 1 -uniform a
1839 grid columnconfigure $top.buts 1 -weight 1 -uniform a
1840 grid $top.buts - -pady 10 -sticky ew
1844 proc doviewmenu {m first cmd op argv} {
1845 set nmenu [$m index end]
1846 for {set i $first} {$i <= $nmenu} {incr i} {
1847 if {[$m entrycget $i -command] eq $cmd} {
1848 eval $m $op $i $argv
1854 proc allviewmenus {n op args} {
1857 doviewmenu .bar.view 5 [list showview $n] $op $args
1858 doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
1861 proc newviewok {top n} {
1862 global nextviewnum newviewperm newviewname newishighlight
1863 global viewname viewfiles viewperm selectedview curview
1864 global viewargs newviewargs viewhlmenu
1867 set newargs [shellsplit $newviewargs($n)]
1869 error_popup "Error in commit selection arguments: $err"
1875 foreach f [split [$top.t get 0.0 end] "\n"] {
1876 set ft [string trim $f]
1881 if {![info exists viewfiles($n)]} {
1882 # creating a new view
1884 set viewname($n) $newviewname($n)
1885 set viewperm($n) $newviewperm($n)
1886 set viewfiles($n) $files
1887 set viewargs($n) $newargs
1889 if {!$newishighlight} {
1892 run addvhighlight $n
1895 # editing an existing view
1896 set viewperm($n) $newviewperm($n)
1897 if {$newviewname($n) ne $viewname($n)} {
1898 set viewname($n) $newviewname($n)
1899 doviewmenu .bar.view 5 [list showview $n] \
1900 entryconf [list -label $viewname($n)]
1901 doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
1902 entryconf [list -label $viewname($n) -value $viewname($n)]
1904 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n)} {
1905 set viewfiles($n) $files
1906 set viewargs($n) $newargs
1907 if {$curview == $n} {
1912 catch {destroy $top}
1916 global curview viewdata viewperm hlview selectedhlview
1918 if {$curview == 0} return
1919 if {[info exists hlview] && $hlview == $curview} {
1920 set selectedhlview None
1923 allviewmenus $curview delete
1924 set viewdata($curview) {}
1925 set viewperm($curview) 0
1929 proc addviewmenu {n} {
1930 global viewname viewhlmenu
1932 .bar.view add radiobutton -label $viewname($n) \
1933 -command [list showview $n] -variable selectedview -value $n
1934 $viewhlmenu add radiobutton -label $viewname($n) \
1935 -command [list addvhighlight $n] -variable selectedhlview
1938 proc flatten {var} {
1942 foreach i [array names $var] {
1943 lappend ret $i [set $var\($i\)]
1948 proc unflatten {var l} {
1958 global curview viewdata viewfiles
1959 global displayorder parentlist rowidlist rowisopt rowfinal
1960 global colormap rowtextx commitrow nextcolor canvxmax
1961 global numcommits commitlisted
1962 global selectedline currentid canv canvy0
1964 global pending_select phase
1967 global selectedview selectfirst
1968 global vparentlist vdisporder vcmitlisted
1969 global hlview selectedhlview commitinterest
1971 if {$n == $curview} return
1973 if {[info exists selectedline]} {
1974 set selid $currentid
1975 set y [yc $selectedline]
1976 set ymax [lindex [$canv cget -scrollregion] 3]
1977 set span [$canv yview]
1978 set ytop [expr {[lindex $span 0] * $ymax}]
1979 set ybot [expr {[lindex $span 1] * $ymax}]
1980 if {$ytop < $y && $y < $ybot} {
1981 set yscreen [expr {$y - $ytop}]
1983 set yscreen [expr {($ybot - $ytop) / 2}]
1985 } elseif {[info exists pending_select]} {
1986 set selid $pending_select
1987 unset pending_select
1991 if {$curview >= 0} {
1992 set vparentlist($curview) $parentlist
1993 set vdisporder($curview) $displayorder
1994 set vcmitlisted($curview) $commitlisted
1996 ![info exists viewdata($curview)] ||
1997 [lindex $viewdata($curview) 0] ne {}} {
1998 set viewdata($curview) \
1999 [list $phase $rowidlist $rowisopt $rowfinal]
2002 catch {unset treediffs}
2004 if {[info exists hlview] && $hlview == $n} {
2006 set selectedhlview None
2008 catch {unset commitinterest}
2012 .bar.view entryconf Edit* -state [expr {$n == 0? "disabled": "normal"}]
2013 .bar.view entryconf Delete* -state [expr {$n == 0? "disabled": "normal"}]
2016 if {![info exists viewdata($n)]} {
2018 set pending_select $selid
2025 set phase [lindex $v 0]
2026 set displayorder $vdisporder($n)
2027 set parentlist $vparentlist($n)
2028 set commitlisted $vcmitlisted($n)
2029 set rowidlist [lindex $v 1]
2030 set rowisopt [lindex $v 2]
2031 set rowfinal [lindex $v 3]
2032 set numcommits $commitidx($n)
2034 catch {unset colormap}
2035 catch {unset rowtextx}
2037 set canvxmax [$canv cget -width]
2044 if {$selid ne {} && [info exists commitrow($n,$selid)]} {
2045 set row $commitrow($n,$selid)
2046 # try to get the selected row in the same position on the screen
2047 set ymax [lindex [$canv cget -scrollregion] 3]
2048 set ytop [expr {[yc $row] - $yscreen}]
2052 set yf [expr {$ytop * 1.0 / $ymax}]
2054 allcanvs yview moveto $yf
2058 } elseif {$selid ne {}} {
2059 set pending_select $selid
2061 set row [first_real_row]
2062 if {$row < $numcommits} {
2069 if {$phase eq "getcommits"} {
2070 show_status "Reading commits..."
2073 } elseif {$numcommits == 0} {
2074 show_status "No commits selected"
2078 # Stuff relating to the highlighting facility
2080 proc ishighlighted {row} {
2081 global vhighlights fhighlights nhighlights rhighlights
2083 if {[info exists nhighlights($row)] && $nhighlights($row) > 0} {
2084 return $nhighlights($row)
2086 if {[info exists vhighlights($row)] && $vhighlights($row) > 0} {
2087 return $vhighlights($row)
2089 if {[info exists fhighlights($row)] && $fhighlights($row) > 0} {
2090 return $fhighlights($row)
2092 if {[info exists rhighlights($row)] && $rhighlights($row) > 0} {
2093 return $rhighlights($row)
2098 proc bolden {row font} {
2099 global canv linehtag selectedline boldrows
2101 lappend boldrows $row
2102 $canv itemconf $linehtag($row) -font $font
2103 if {[info exists selectedline] && $row == $selectedline} {
2105 set t [eval $canv create rect [$canv bbox $linehtag($row)] \
2106 -outline {{}} -tags secsel \
2107 -fill [$canv cget -selectbackground]]
2112 proc bolden_name {row font} {
2113 global canv2 linentag selectedline boldnamerows
2115 lappend boldnamerows $row
2116 $canv2 itemconf $linentag($row) -font $font
2117 if {[info exists selectedline] && $row == $selectedline} {
2118 $canv2 delete secsel
2119 set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \
2120 -outline {{}} -tags secsel \
2121 -fill [$canv2 cget -selectbackground]]
2127 global mainfont boldrows
2130 foreach row $boldrows {
2131 if {![ishighlighted $row]} {
2132 bolden $row $mainfont
2134 lappend stillbold $row
2137 set boldrows $stillbold
2140 proc addvhighlight {n} {
2141 global hlview curview viewdata vhl_done vhighlights commitidx
2143 if {[info exists hlview]} {
2147 if {$n != $curview && ![info exists viewdata($n)]} {
2148 set viewdata($n) [list getcommits {{}} 0 0 0]
2149 set vparentlist($n) {}
2150 set vdisporder($n) {}
2151 set vcmitlisted($n) {}
2154 set vhl_done $commitidx($hlview)
2155 if {$vhl_done > 0} {
2160 proc delvhighlight {} {
2161 global hlview vhighlights
2163 if {![info exists hlview]} return
2165 catch {unset vhighlights}
2169 proc vhighlightmore {} {
2170 global hlview vhl_done commitidx vhighlights
2171 global displayorder vdisporder curview mainfont
2173 set font [concat $mainfont bold]
2174 set max $commitidx($hlview)
2175 if {$hlview == $curview} {
2176 set disp $displayorder
2178 set disp $vdisporder($hlview)
2180 set vr [visiblerows]
2181 set r0 [lindex $vr 0]
2182 set r1 [lindex $vr 1]
2183 for {set i $vhl_done} {$i < $max} {incr i} {
2184 set id [lindex $disp $i]
2185 if {[info exists commitrow($curview,$id)]} {
2186 set row $commitrow($curview,$id)
2187 if {$r0 <= $row && $row <= $r1} {
2188 if {![highlighted $row]} {
2191 set vhighlights($row) 1
2198 proc askvhighlight {row id} {
2199 global hlview vhighlights commitrow iddrawn mainfont
2201 if {[info exists commitrow($hlview,$id)]} {
2202 if {[info exists iddrawn($id)] && ![ishighlighted $row]} {
2203 bolden $row [concat $mainfont bold]
2205 set vhighlights($row) 1
2207 set vhighlights($row) 0
2211 proc hfiles_change {name ix op} {
2212 global highlight_files filehighlight fhighlights fh_serial
2213 global mainfont highlight_paths
2215 if {[info exists filehighlight]} {
2216 # delete previous highlights
2217 catch {close $filehighlight}
2219 catch {unset fhighlights}
2221 unhighlight_filelist
2223 set highlight_paths {}
2224 after cancel do_file_hl $fh_serial
2226 if {$highlight_files ne {}} {
2227 after 300 do_file_hl $fh_serial
2231 proc makepatterns {l} {
2234 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
2235 if {[string index $ee end] eq "/"} {
2245 proc do_file_hl {serial} {
2246 global highlight_files filehighlight highlight_paths gdttype fhl_list
2248 if {$gdttype eq "touching paths:"} {
2249 if {[catch {set paths [shellsplit $highlight_files]}]} return
2250 set highlight_paths [makepatterns $paths]
2252 set gdtargs [concat -- $paths]
2254 set gdtargs [list "-S$highlight_files"]
2256 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
2257 set filehighlight [open $cmd r+]
2258 fconfigure $filehighlight -blocking 0
2259 filerun $filehighlight readfhighlight
2265 proc flushhighlights {} {
2266 global filehighlight fhl_list
2268 if {[info exists filehighlight]} {
2270 puts $filehighlight ""
2271 flush $filehighlight
2275 proc askfilehighlight {row id} {
2276 global filehighlight fhighlights fhl_list
2278 lappend fhl_list $id
2279 set fhighlights($row) -1
2280 puts $filehighlight $id
2283 proc readfhighlight {} {
2284 global filehighlight fhighlights commitrow curview mainfont iddrawn
2287 if {![info exists filehighlight]} {
2291 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
2292 set line [string trim $line]
2293 set i [lsearch -exact $fhl_list $line]
2294 if {$i < 0} continue
2295 for {set j 0} {$j < $i} {incr j} {
2296 set id [lindex $fhl_list $j]
2297 if {[info exists commitrow($curview,$id)]} {
2298 set fhighlights($commitrow($curview,$id)) 0
2301 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
2302 if {$line eq {}} continue
2303 if {![info exists commitrow($curview,$line)]} continue
2304 set row $commitrow($curview,$line)
2305 if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
2306 bolden $row [concat $mainfont bold]
2308 set fhighlights($row) 1
2310 if {[eof $filehighlight]} {
2312 puts "oops, git diff-tree died"
2313 catch {close $filehighlight}
2321 proc find_change {name ix op} {
2322 global nhighlights mainfont boldnamerows
2323 global findstring findpattern findtype
2325 # delete previous highlights, if any
2326 foreach row $boldnamerows {
2327 bolden_name $row $mainfont
2330 catch {unset nhighlights}
2333 if {$findtype ne "Regexp"} {
2334 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
2336 set findpattern "*$e*"
2341 proc doesmatch {f} {
2342 global findtype findstring findpattern
2344 if {$findtype eq "Regexp"} {
2345 return [regexp $findstring $f]
2346 } elseif {$findtype eq "IgnCase"} {
2347 return [string match -nocase $findpattern $f]
2349 return [string match $findpattern $f]
2353 proc askfindhighlight {row id} {
2354 global nhighlights commitinfo iddrawn mainfont
2356 global markingmatches
2358 if {![info exists commitinfo($id)]} {
2361 set info $commitinfo($id)
2363 set fldtypes {Headline Author Date Committer CDate Comments}
2364 foreach f $info ty $fldtypes {
2365 if {($findloc eq "All fields" || $findloc eq $ty) &&
2367 if {$ty eq "Author"} {
2374 if {$isbold && [info exists iddrawn($id)]} {
2375 set f [concat $mainfont bold]
2376 if {![ishighlighted $row]} {
2382 if {$markingmatches} {
2383 markrowmatches $row $id
2386 set nhighlights($row) $isbold
2389 proc markrowmatches {row id} {
2390 global canv canv2 linehtag linentag commitinfo findloc
2392 set headline [lindex $commitinfo($id) 0]
2393 set author [lindex $commitinfo($id) 1]
2394 $canv delete match$row
2395 $canv2 delete match$row
2396 if {$findloc eq "All fields" || $findloc eq "Headline"} {
2397 set m [findmatches $headline]
2399 markmatches $canv $row $headline $linehtag($row) $m \
2400 [$canv itemcget $linehtag($row) -font] $row
2403 if {$findloc eq "All fields" || $findloc eq "Author"} {
2404 set m [findmatches $author]
2406 markmatches $canv2 $row $author $linentag($row) $m \
2407 [$canv2 itemcget $linentag($row) -font] $row
2412 proc vrel_change {name ix op} {
2413 global highlight_related
2416 if {$highlight_related ne "None"} {
2421 # prepare for testing whether commits are descendents or ancestors of a
2422 proc rhighlight_sel {a} {
2423 global descendent desc_todo ancestor anc_todo
2424 global highlight_related rhighlights
2426 catch {unset descendent}
2427 set desc_todo [list $a]
2428 catch {unset ancestor}
2429 set anc_todo [list $a]
2430 if {$highlight_related ne "None"} {
2436 proc rhighlight_none {} {
2439 catch {unset rhighlights}
2443 proc is_descendent {a} {
2444 global curview children commitrow descendent desc_todo
2447 set la $commitrow($v,$a)
2451 for {set i 0} {$i < [llength $todo]} {incr i} {
2452 set do [lindex $todo $i]
2453 if {$commitrow($v,$do) < $la} {
2454 lappend leftover $do
2457 foreach nk $children($v,$do) {
2458 if {![info exists descendent($nk)]} {
2459 set descendent($nk) 1
2467 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
2471 set descendent($a) 0
2472 set desc_todo $leftover
2475 proc is_ancestor {a} {
2476 global curview parentlist commitrow ancestor anc_todo
2479 set la $commitrow($v,$a)
2483 for {set i 0} {$i < [llength $todo]} {incr i} {
2484 set do [lindex $todo $i]
2485 if {![info exists commitrow($v,$do)] || $commitrow($v,$do) > $la} {
2486 lappend leftover $do
2489 foreach np [lindex $parentlist $commitrow($v,$do)] {
2490 if {![info exists ancestor($np)]} {
2499 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
2504 set anc_todo $leftover
2507 proc askrelhighlight {row id} {
2508 global descendent highlight_related iddrawn mainfont rhighlights
2509 global selectedline ancestor
2511 if {![info exists selectedline]} return
2513 if {$highlight_related eq "Descendent" ||
2514 $highlight_related eq "Not descendent"} {
2515 if {![info exists descendent($id)]} {
2518 if {$descendent($id) == ($highlight_related eq "Descendent")} {
2521 } elseif {$highlight_related eq "Ancestor" ||
2522 $highlight_related eq "Not ancestor"} {
2523 if {![info exists ancestor($id)]} {
2526 if {$ancestor($id) == ($highlight_related eq "Ancestor")} {
2530 if {[info exists iddrawn($id)]} {
2531 if {$isbold && ![ishighlighted $row]} {
2532 bolden $row [concat $mainfont bold]
2535 set rhighlights($row) $isbold
2538 proc next_hlcont {} {
2539 global fhl_row fhl_dirn displayorder numcommits
2540 global vhighlights fhighlights nhighlights rhighlights
2541 global hlview filehighlight findstring highlight_related
2543 if {![info exists fhl_dirn] || $fhl_dirn == 0} return
2546 if {$row < 0 || $row >= $numcommits} {
2551 set id [lindex $displayorder $row]
2552 if {[info exists hlview]} {
2553 if {![info exists vhighlights($row)]} {
2554 askvhighlight $row $id
2556 if {$vhighlights($row) > 0} break
2558 if {$findstring ne {}} {
2559 if {![info exists nhighlights($row)]} {
2560 askfindhighlight $row $id
2562 if {$nhighlights($row) > 0} break
2564 if {$highlight_related ne "None"} {
2565 if {![info exists rhighlights($row)]} {
2566 askrelhighlight $row $id
2568 if {$rhighlights($row) > 0} break
2570 if {[info exists filehighlight]} {
2571 if {![info exists fhighlights($row)]} {
2572 # ask for a few more while we're at it...
2574 for {set n 0} {$n < 100} {incr n} {
2575 if {![info exists fhighlights($r)]} {
2576 askfilehighlight $r [lindex $displayorder $r]
2579 if {$r < 0 || $r >= $numcommits} break
2583 if {$fhighlights($row) < 0} {
2587 if {$fhighlights($row) > 0} break
2595 proc next_highlight {dirn} {
2596 global selectedline fhl_row fhl_dirn
2597 global hlview filehighlight findstring highlight_related
2599 if {![info exists selectedline]} return
2600 if {!([info exists hlview] || $findstring ne {} ||
2601 $highlight_related ne "None" || [info exists filehighlight])} return
2602 set fhl_row [expr {$selectedline + $dirn}]
2607 proc cancel_next_highlight {} {
2613 # Graph layout functions
2615 proc shortids {ids} {
2618 if {[llength $id] > 1} {
2619 lappend res [shortids $id]
2620 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
2621 lappend res [string range $id 0 7]
2632 for {set mask 1} {$mask <= $n} {incr mask $mask} {
2633 if {($n & $mask) != 0} {
2634 set ret [concat $ret $o]
2636 set o [concat $o $o]
2641 # Work out where id should go in idlist so that order-token
2642 # values increase from left to right
2643 proc idcol {idlist id {i 0}} {
2644 global ordertok curview
2646 set t $ordertok($curview,$id)
2647 if {$i >= [llength $idlist] ||
2648 $t < $ordertok($curview,[lindex $idlist $i])} {
2649 if {$i > [llength $idlist]} {
2650 set i [llength $idlist]
2652 while {[incr i -1] >= 0 &&
2653 $t < $ordertok($curview,[lindex $idlist $i])} {}
2656 if {$t > $ordertok($curview,[lindex $idlist $i])} {
2657 while {[incr i] < [llength $idlist] &&
2658 $t >= $ordertok($curview,[lindex $idlist $i])} {}
2664 proc initlayout {} {
2665 global rowidlist rowisopt rowfinal displayorder commitlisted
2666 global numcommits canvxmax canv
2669 global colormap rowtextx
2680 set canvxmax [$canv cget -width]
2681 catch {unset colormap}
2682 catch {unset rowtextx}
2686 proc setcanvscroll {} {
2687 global canv canv2 canv3 numcommits linespc canvxmax canvy0
2689 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
2690 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
2691 $canv2 conf -scrollregion [list 0 0 0 $ymax]
2692 $canv3 conf -scrollregion [list 0 0 0 $ymax]
2695 proc visiblerows {} {
2696 global canv numcommits linespc
2698 set ymax [lindex [$canv cget -scrollregion] 3]
2699 if {$ymax eq {} || $ymax == 0} return
2701 set y0 [expr {int([lindex $f 0] * $ymax)}]
2702 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
2706 set y1 [expr {int([lindex $f 1] * $ymax)}]
2707 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
2708 if {$r1 >= $numcommits} {
2709 set r1 [expr {$numcommits - 1}]
2711 return [list $r0 $r1]
2714 proc layoutmore {} {
2715 global commitidx viewcomplete numcommits
2716 global uparrowlen downarrowlen mingaplen curview
2718 set show $commitidx($curview)
2719 if {$show > $numcommits} {
2720 showstuff $show $viewcomplete($curview)
2724 proc showstuff {canshow last} {
2725 global numcommits commitrow pending_select selectedline curview
2726 global mainheadid displayorder selectfirst
2727 global lastscrollset commitinterest
2729 if {$numcommits == 0} {
2731 set phase "incrdraw"
2735 set prev $numcommits
2736 set numcommits $canshow
2737 set t [clock clicks -milliseconds]
2738 if {$prev < 100 || $last || $t - $lastscrollset > 500} {
2739 set lastscrollset $t
2742 set rows [visiblerows]
2743 set r1 [lindex $rows 1]
2744 if {$r1 >= $canshow} {
2745 set r1 [expr {$canshow - 1}]
2750 if {[info exists pending_select] &&
2751 [info exists commitrow($curview,$pending_select)] &&
2752 $commitrow($curview,$pending_select) < $numcommits} {
2753 selectline $commitrow($curview,$pending_select) 1
2756 if {[info exists selectedline] || [info exists pending_select]} {
2759 set l [first_real_row]
2766 proc doshowlocalchanges {} {
2767 global curview mainheadid phase commitrow
2769 if {[info exists commitrow($curview,$mainheadid)] &&
2770 ($phase eq {} || $commitrow($curview,$mainheadid) < $numcommits - 1)} {
2772 } elseif {$phase ne {}} {
2773 lappend commitinterest($mainheadid) {}
2777 proc dohidelocalchanges {} {
2778 global localfrow localirow lserial
2780 if {$localfrow >= 0} {
2781 removerow $localfrow
2783 if {$localirow > 0} {
2787 if {$localirow >= 0} {
2788 removerow $localirow
2794 # spawn off a process to do git diff-index --cached HEAD
2795 proc dodiffindex {} {
2796 global localirow localfrow lserial showlocalchanges
2798 if {!$showlocalchanges} return
2802 set fd [open "|git diff-index --cached HEAD" r]
2803 fconfigure $fd -blocking 0
2804 filerun $fd [list readdiffindex $fd $lserial]
2807 proc readdiffindex {fd serial} {
2808 global localirow commitrow mainheadid nullid2 curview
2809 global commitinfo commitdata lserial
2812 if {[gets $fd line] < 0} {
2818 # we only need to see one line and we don't really care what it says...
2821 # now see if there are any local changes not checked in to the index
2822 if {$serial == $lserial} {
2823 set fd [open "|git diff-files" r]
2824 fconfigure $fd -blocking 0
2825 filerun $fd [list readdifffiles $fd $serial]
2828 if {$isdiff && $serial == $lserial && $localirow == -1} {
2829 # add the line for the changes in the index to the graph
2830 set localirow $commitrow($curview,$mainheadid)
2831 set hl "Local changes checked in to index but not committed"
2832 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
2833 set commitdata($nullid2) "\n $hl\n"
2834 insertrow $localirow $nullid2
2839 proc readdifffiles {fd serial} {
2840 global localirow localfrow commitrow mainheadid nullid curview
2841 global commitinfo commitdata lserial
2844 if {[gets $fd line] < 0} {
2850 # we only need to see one line and we don't really care what it says...
2853 if {$isdiff && $serial == $lserial && $localfrow == -1} {
2854 # add the line for the local diff to the graph
2855 if {$localirow >= 0} {
2856 set localfrow $localirow
2859 set localfrow $commitrow($curview,$mainheadid)
2861 set hl "Local uncommitted changes, not checked in to index"
2862 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
2863 set commitdata($nullid) "\n $hl\n"
2864 insertrow $localfrow $nullid
2869 proc nextuse {id row} {
2870 global commitrow curview children
2872 if {[info exists children($curview,$id)]} {
2873 foreach kid $children($curview,$id) {
2874 if {![info exists commitrow($curview,$kid)]} {
2877 if {$commitrow($curview,$kid) > $row} {
2878 return $commitrow($curview,$kid)
2882 if {[info exists commitrow($curview,$id)]} {
2883 return $commitrow($curview,$id)
2888 proc prevuse {id row} {
2889 global commitrow curview children
2892 if {[info exists children($curview,$id)]} {
2893 foreach kid $children($curview,$id) {
2894 if {![info exists commitrow($curview,$kid)]} break
2895 if {$commitrow($curview,$kid) < $row} {
2896 set ret $commitrow($curview,$kid)
2903 proc make_idlist {row} {
2904 global displayorder parentlist uparrowlen downarrowlen mingaplen
2905 global commitidx curview ordertok children commitrow
2907 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
2911 set ra [expr {$row - $downarrowlen}]
2915 set rb [expr {$row + $uparrowlen}]
2916 if {$rb > $commitidx($curview)} {
2917 set rb $commitidx($curview)
2920 for {} {$r < $ra} {incr r} {
2921 set nextid [lindex $displayorder [expr {$r + 1}]]
2922 foreach p [lindex $parentlist $r] {
2923 if {$p eq $nextid} continue
2924 set rn [nextuse $p $r]
2926 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
2927 lappend ids [list $ordertok($curview,$p) $p]
2931 for {} {$r < $row} {incr r} {
2932 set nextid [lindex $displayorder [expr {$r + 1}]]
2933 foreach p [lindex $parentlist $r] {
2934 if {$p eq $nextid} continue
2935 set rn [nextuse $p $r]
2936 if {$rn < 0 || $rn >= $row} {
2937 lappend ids [list $ordertok($curview,$p) $p]
2941 set id [lindex $displayorder $row]
2942 lappend ids [list $ordertok($curview,$id) $id]
2944 foreach p [lindex $parentlist $r] {
2945 set firstkid [lindex $children($curview,$p) 0]
2946 if {$commitrow($curview,$firstkid) < $row} {
2947 lappend ids [list $ordertok($curview,$p) $p]
2951 set id [lindex $displayorder $r]
2953 set firstkid [lindex $children($curview,$id) 0]
2954 if {$firstkid ne {} && $commitrow($curview,$firstkid) < $row} {
2955 lappend ids [list $ordertok($curview,$id) $id]
2960 foreach idx [lsort -unique $ids] {
2961 lappend idlist [lindex $idx 1]
2966 proc rowsequal {a b} {
2967 while {[set i [lsearch -exact $a {}]] >= 0} {
2968 set a [lreplace $a $i $i]
2970 while {[set i [lsearch -exact $b {}]] >= 0} {
2971 set b [lreplace $b $i $i]
2973 return [expr {$a eq $b}]
2976 proc makeupline {id row rend col} {
2977 global rowidlist uparrowlen downarrowlen mingaplen
2979 for {set r $rend} {1} {set r $rstart} {
2980 set rstart [prevuse $id $r]
2981 if {$rstart < 0} return
2982 if {$rstart < $row} break
2984 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
2985 set rstart [expr {$rend - $uparrowlen - 1}]
2987 for {set r $rstart} {[incr r] <= $row} {} {
2988 set idlist [lindex $rowidlist $r]
2989 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
2990 set col [idcol $idlist $id $col]
2991 lset rowidlist $r [linsert $idlist $col $id]
2997 proc layoutrows {row endrow} {
2998 global rowidlist rowisopt rowfinal displayorder
2999 global uparrowlen downarrowlen maxwidth mingaplen
3000 global children parentlist
3001 global commitidx viewcomplete curview commitrow
3005 set rm1 [expr {$row - 1}]
3006 foreach id [lindex $rowidlist $rm1] {
3011 set final [lindex $rowfinal $rm1]
3013 for {} {$row < $endrow} {incr row} {
3014 set rm1 [expr {$row - 1}]
3015 if {$rm1 < 0 || $idlist eq {}} {
3016 set idlist [make_idlist $row]
3019 set id [lindex $displayorder $rm1]
3020 set col [lsearch -exact $idlist $id]
3021 set idlist [lreplace $idlist $col $col]
3022 foreach p [lindex $parentlist $rm1] {
3023 if {[lsearch -exact $idlist $p] < 0} {
3024 set col [idcol $idlist $p $col]
3025 set idlist [linsert $idlist $col $p]
3026 # if not the first child, we have to insert a line going up
3027 if {$id ne [lindex $children($curview,$p) 0]} {
3028 makeupline $p $rm1 $row $col
3032 set id [lindex $displayorder $row]
3033 if {$row > $downarrowlen} {
3034 set termrow [expr {$row - $downarrowlen - 1}]
3035 foreach p [lindex $parentlist $termrow] {
3036 set i [lsearch -exact $idlist $p]
3037 if {$i < 0} continue
3038 set nr [nextuse $p $termrow]
3039 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
3040 set idlist [lreplace $idlist $i $i]
3044 set col [lsearch -exact $idlist $id]
3046 set col [idcol $idlist $id]
3047 set idlist [linsert $idlist $col $id]
3048 if {$children($curview,$id) ne {}} {
3049 makeupline $id $rm1 $row $col
3052 set r [expr {$row + $uparrowlen - 1}]
3053 if {$r < $commitidx($curview)} {
3055 foreach p [lindex $parentlist $r] {
3056 if {[lsearch -exact $idlist $p] >= 0} continue
3057 set fk [lindex $children($curview,$p) 0]
3058 if {$commitrow($curview,$fk) < $row} {
3059 set x [idcol $idlist $p $x]
3060 set idlist [linsert $idlist $x $p]
3063 if {[incr r] < $commitidx($curview)} {
3064 set p [lindex $displayorder $r]
3065 if {[lsearch -exact $idlist $p] < 0} {
3066 set fk [lindex $children($curview,$p) 0]
3067 if {$fk ne {} && $commitrow($curview,$fk) < $row} {
3068 set x [idcol $idlist $p $x]
3069 set idlist [linsert $idlist $x $p]
3075 if {$final && !$viewcomplete($curview) &&
3076 $row + $uparrowlen + $mingaplen + $downarrowlen
3077 >= $commitidx($curview)} {
3080 set l [llength $rowidlist]
3082 lappend rowidlist $idlist
3084 lappend rowfinal $final
3085 } elseif {$row < $l} {
3086 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
3087 lset rowidlist $row $idlist
3090 lset rowfinal $row $final
3092 set pad [ntimes [expr {$row - $l}] {}]
3093 set rowidlist [concat $rowidlist $pad]
3094 lappend rowidlist $idlist
3095 set rowfinal [concat $rowfinal $pad]
3096 lappend rowfinal $final
3097 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
3103 proc changedrow {row} {
3104 global displayorder iddrawn rowisopt need_redisplay
3106 set l [llength $rowisopt]
3108 lset rowisopt $row 0
3109 if {$row + 1 < $l} {
3110 lset rowisopt [expr {$row + 1}] 0
3111 if {$row + 2 < $l} {
3112 lset rowisopt [expr {$row + 2}] 0
3116 set id [lindex $displayorder $row]
3117 if {[info exists iddrawn($id)]} {
3118 set need_redisplay 1
3122 proc insert_pad {row col npad} {
3125 set pad [ntimes $npad {}]
3126 set idlist [lindex $rowidlist $row]
3127 set bef [lrange $idlist 0 [expr {$col - 1}]]
3128 set aft [lrange $idlist $col end]
3129 set i [lsearch -exact $aft {}]
3131 set aft [lreplace $aft $i $i]
3133 lset rowidlist $row [concat $bef $pad $aft]
3137 proc optimize_rows {row col endrow} {
3138 global rowidlist rowisopt displayorder curview children
3143 for {} {$row < $endrow} {incr row; set col 0} {
3144 if {[lindex $rowisopt $row]} continue
3146 set y0 [expr {$row - 1}]
3147 set ym [expr {$row - 2}]
3148 set idlist [lindex $rowidlist $row]
3149 set previdlist [lindex $rowidlist $y0]
3150 if {$idlist eq {} || $previdlist eq {}} continue
3152 set pprevidlist [lindex $rowidlist $ym]
3153 if {$pprevidlist eq {}} continue
3159 for {} {$col < [llength $idlist]} {incr col} {
3160 set id [lindex $idlist $col]
3161 if {[lindex $previdlist $col] eq $id} continue
3166 set x0 [lsearch -exact $previdlist $id]
3167 if {$x0 < 0} continue
3168 set z [expr {$x0 - $col}]
3172 set xm [lsearch -exact $pprevidlist $id]
3174 set z0 [expr {$xm - $x0}]
3178 # if row y0 is the first child of $id then it's not an arrow
3179 if {[lindex $children($curview,$id) 0] ne
3180 [lindex $displayorder $y0]} {
3184 if {!$isarrow && $id ne [lindex $displayorder $row] &&
3185 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
3188 # Looking at lines from this row to the previous row,
3189 # make them go straight up if they end in an arrow on
3190 # the previous row; otherwise make them go straight up
3192 if {$z < -1 || ($z < 0 && $isarrow)} {
3193 # Line currently goes left too much;
3194 # insert pads in the previous row, then optimize it
3195 set npad [expr {-1 - $z + $isarrow}]
3196 insert_pad $y0 $x0 $npad
3198 optimize_rows $y0 $x0 $row
3200 set previdlist [lindex $rowidlist $y0]
3201 set x0 [lsearch -exact $previdlist $id]
3202 set z [expr {$x0 - $col}]
3204 set pprevidlist [lindex $rowidlist $ym]
3205 set xm [lsearch -exact $pprevidlist $id]
3206 set z0 [expr {$xm - $x0}]
3208 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
3209 # Line currently goes right too much;
3210 # insert pads in this line
3211 set npad [expr {$z - 1 + $isarrow}]
3212 insert_pad $row $col $npad
3213 set idlist [lindex $rowidlist $row]
3215 set z [expr {$x0 - $col}]
3218 if {$z0 eq {} && !$isarrow && $ym >= 0} {
3219 # this line links to its first child on row $row-2
3220 set id [lindex $displayorder $ym]
3221 set xc [lsearch -exact $pprevidlist $id]
3223 set z0 [expr {$xc - $x0}]
3226 # avoid lines jigging left then immediately right
3227 if {$z0 ne {} && $z < 0 && $z0 > 0} {
3228 insert_pad $y0 $x0 1
3230 optimize_rows $y0 $x0 $row
3231 set previdlist [lindex $rowidlist $y0]
3235 # Find the first column that doesn't have a line going right
3236 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
3237 set id [lindex $idlist $col]
3238 if {$id eq {}} break
3239 set x0 [lsearch -exact $previdlist $id]
3241 # check if this is the link to the first child
3242 set kid [lindex $displayorder $y0]
3243 if {[lindex $children($curview,$id) 0] eq $kid} {
3244 # it is, work out offset to child
3245 set x0 [lsearch -exact $previdlist $kid]
3248 if {$x0 <= $col} break
3250 # Insert a pad at that column as long as it has a line and
3251 # isn't the last column
3252 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
3253 set idlist [linsert $idlist $col {}]
3254 lset rowidlist $row $idlist
3262 global canvx0 linespc
3263 return [expr {$canvx0 + $col * $linespc}]
3267 global canvy0 linespc
3268 return [expr {$canvy0 + $row * $linespc}]
3271 proc linewidth {id} {
3272 global thickerline lthickness
3275 if {[info exists thickerline] && $id eq $thickerline} {
3276 set wid [expr {2 * $lthickness}]
3281 proc rowranges {id} {
3282 global commitrow curview children uparrowlen downarrowlen
3285 set kids $children($curview,$id)
3291 foreach child $kids {
3292 if {![info exists commitrow($curview,$child)]} break
3293 set row $commitrow($curview,$child)
3294 if {![info exists prev]} {
3295 lappend ret [expr {$row + 1}]
3297 if {$row <= $prevrow} {
3298 puts "oops children out of order [shortids $id] $row < [shortids $prev] $prevrow"
3300 # see if the line extends the whole way from prevrow to row
3301 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
3302 [lsearch -exact [lindex $rowidlist \
3303 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
3304 # it doesn't, see where it ends
3305 set r [expr {$prevrow + $downarrowlen}]
3306 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
3307 while {[incr r -1] > $prevrow &&
3308 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
3310 while {[incr r] <= $row &&
3311 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
3315 # see where it starts up again
3316 set r [expr {$row - $uparrowlen}]
3317 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
3318 while {[incr r] < $row &&
3319 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
3321 while {[incr r -1] >= $prevrow &&
3322 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
3328 if {$child eq $id} {
3337 proc drawlineseg {id row endrow arrowlow} {
3338 global rowidlist displayorder iddrawn linesegs
3339 global canv colormap linespc curview maxlinelen parentlist
3341 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
3342 set le [expr {$row + 1}]
3345 set c [lsearch -exact [lindex $rowidlist $le] $id]
3351 set x [lindex $displayorder $le]
3356 if {[info exists iddrawn($x)] || $le == $endrow} {
3357 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
3373 if {[info exists linesegs($id)]} {
3374 set lines $linesegs($id)
3376 set r0 [lindex $li 0]
3378 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
3388 set li [lindex $lines [expr {$i-1}]]
3389 set r1 [lindex $li 1]
3390 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
3395 set x [lindex $cols [expr {$le - $row}]]
3396 set xp [lindex $cols [expr {$le - 1 - $row}]]
3397 set dir [expr {$xp - $x}]
3399 set ith [lindex $lines $i 2]
3400 set coords [$canv coords $ith]
3401 set ah [$canv itemcget $ith -arrow]
3402 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
3403 set x2 [lindex $cols [expr {$le + 1 - $row}]]
3404 if {$x2 ne {} && $x - $x2 == $dir} {
3405 set coords [lrange $coords 0 end-2]
3408 set coords [list [xc $le $x] [yc $le]]
3411 set itl [lindex $lines [expr {$i-1}] 2]
3412 set al [$canv itemcget $itl -arrow]
3413 set arrowlow [expr {$al eq "last" || $al eq "both"}]
3414 } elseif {$arrowlow} {
3415 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
3416 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
3420 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
3421 for {set y $le} {[incr y -1] > $row} {} {
3423 set xp [lindex $cols [expr {$y - 1 - $row}]]
3424 set ndir [expr {$xp - $x}]
3425 if {$dir != $ndir || $xp < 0} {
3426 lappend coords [xc $y $x] [yc $y]
3432 # join parent line to first child
3433 set ch [lindex $displayorder $row]
3434 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
3436 puts "oops: drawlineseg: child $ch not on row $row"
3437 } elseif {$xc != $x} {
3438 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
3439 set d [expr {int(0.5 * $linespc)}]
3442 set x2 [expr {$x1 - $d}]
3444 set x2 [expr {$x1 + $d}]
3447 set y1 [expr {$y2 + $d}]
3448 lappend coords $x1 $y1 $x2 $y2
3449 } elseif {$xc < $x - 1} {
3450 lappend coords [xc $row [expr {$x-1}]] [yc $row]
3451 } elseif {$xc > $x + 1} {
3452 lappend coords [xc $row [expr {$x+1}]] [yc $row]
3456 lappend coords [xc $row $x] [yc $row]
3458 set xn [xc $row $xp]
3460 lappend coords $xn $yn
3464 set t [$canv create line $coords -width [linewidth $id] \
3465 -fill $colormap($id) -tags lines.$id -arrow $arrow]
3468 set lines [linsert $lines $i [list $row $le $t]]
3470 $canv coords $ith $coords
3471 if {$arrow ne $ah} {
3472 $canv itemconf $ith -arrow $arrow
3474 lset lines $i 0 $row
3477 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
3478 set ndir [expr {$xo - $xp}]
3479 set clow [$canv coords $itl]
3480 if {$dir == $ndir} {
3481 set clow [lrange $clow 2 end]
3483 set coords [concat $coords $clow]
3485 lset lines [expr {$i-1}] 1 $le
3487 # coalesce two pieces
3489 set b [lindex $lines [expr {$i-1}] 0]
3490 set e [lindex $lines $i 1]
3491 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
3493 $canv coords $itl $coords
3494 if {$arrow ne $al} {
3495 $canv itemconf $itl -arrow $arrow
3499 set linesegs($id) $lines
3503 proc drawparentlinks {id row} {
3504 global rowidlist canv colormap curview parentlist
3505 global idpos linespc
3507 set rowids [lindex $rowidlist $row]
3508 set col [lsearch -exact $rowids $id]
3509 if {$col < 0} return
3510 set olds [lindex $parentlist $row]
3511 set row2 [expr {$row + 1}]
3512 set x [xc $row $col]
3515 set d [expr {int(0.5 * $linespc)}]
3516 set ymid [expr {$y + $d}]
3517 set ids [lindex $rowidlist $row2]
3518 # rmx = right-most X coord used
3521 set i [lsearch -exact $ids $p]
3523 puts "oops, parent $p of $id not in list"
3526 set x2 [xc $row2 $i]
3530 set j [lsearch -exact $rowids $p]
3532 # drawlineseg will do this one for us
3536 # should handle duplicated parents here...
3537 set coords [list $x $y]
3539 # if attaching to a vertical segment, draw a smaller
3540 # slant for visual distinctness
3543 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
3545 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
3547 } elseif {$i < $col && $i < $j} {
3548 # segment slants towards us already
3549 lappend coords [xc $row $j] $y
3551 if {$i < $col - 1} {
3552 lappend coords [expr {$x2 + $linespc}] $y
3553 } elseif {$i > $col + 1} {
3554 lappend coords [expr {$x2 - $linespc}] $y
3556 lappend coords $x2 $y2
3559 lappend coords $x2 $y2
3561 set t [$canv create line $coords -width [linewidth $p] \
3562 -fill $colormap($p) -tags lines.$p]
3566 if {$rmx > [lindex $idpos($id) 1]} {
3567 lset idpos($id) 1 $rmx
3572 proc drawlines {id} {
3575 $canv itemconf lines.$id -width [linewidth $id]
3578 proc drawcmittext {id row col} {
3579 global linespc canv canv2 canv3 canvy0 fgcolor curview
3580 global commitlisted commitinfo rowidlist parentlist
3581 global rowtextx idpos idtags idheads idotherrefs
3582 global linehtag linentag linedtag selectedline
3583 global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2
3585 # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
3586 set listed [lindex $commitlisted $row]
3587 if {$id eq $nullid} {
3589 } elseif {$id eq $nullid2} {
3592 set ofill [expr {$listed != 0? "blue": "white"}]
3594 set x [xc $row $col]
3596 set orad [expr {$linespc / 3}]
3598 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
3599 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3600 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3601 } elseif {$listed == 2} {
3602 # triangle pointing left for left-side commits
3603 set t [$canv create polygon \
3604 [expr {$x - $orad}] $y \
3605 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
3606 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3607 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3609 # triangle pointing right for right-side commits
3610 set t [$canv create polygon \
3611 [expr {$x + $orad - 1}] $y \
3612 [expr {$x - $orad}] [expr {$y - $orad}] \
3613 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
3614 -fill $ofill -outline $fgcolor -width 1 -tags circle]
3617 $canv bind $t <1> {selcanvline {} %x %y}
3618 set rmx [llength [lindex $rowidlist $row]]
3619 set olds [lindex $parentlist $row]
3621 set nextids [lindex $rowidlist [expr {$row + 1}]]
3623 set i [lsearch -exact $nextids $p]
3629 set xt [xc $row $rmx]
3630 set rowtextx($row) $xt
3631 set idpos($id) [list $x $xt $y]
3632 if {[info exists idtags($id)] || [info exists idheads($id)]
3633 || [info exists idotherrefs($id)]} {
3634 set xt [drawtags $id $x $xt $y]
3636 set headline [lindex $commitinfo($id) 0]
3637 set name [lindex $commitinfo($id) 1]
3638 set date [lindex $commitinfo($id) 2]
3639 set date [formatdate $date]
3642 set isbold [ishighlighted $row]
3644 lappend boldrows $row
3647 lappend boldnamerows $row
3651 set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
3652 -text $headline -font $font -tags text]
3653 $canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
3654 set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
3655 -text $name -font $nfont -tags text]
3656 set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
3657 -text $date -font $mainfont -tags text]
3658 if {[info exists selectedline] && $selectedline == $row} {
3661 set xr [expr {$xt + [font measure $mainfont $headline]}]
3662 if {$xr > $canvxmax} {
3668 proc drawcmitrow {row} {
3669 global displayorder rowidlist nrows_drawn
3670 global iddrawn markingmatches
3671 global commitinfo parentlist numcommits
3672 global filehighlight fhighlights findstring nhighlights
3673 global hlview vhighlights
3674 global highlight_related rhighlights
3676 if {$row >= $numcommits} return
3678 set id [lindex $displayorder $row]
3679 if {[info exists hlview] && ![info exists vhighlights($row)]} {
3680 askvhighlight $row $id
3682 if {[info exists filehighlight] && ![info exists fhighlights($row)]} {
3683 askfilehighlight $row $id
3685 if {$findstring ne {} && ![info exists nhighlights($row)]} {
3686 askfindhighlight $row $id
3688 if {$highlight_related ne "None" && ![info exists rhighlights($row)]} {
3689 askrelhighlight $row $id
3691 if {![info exists iddrawn($id)]} {
3692 set col [lsearch -exact [lindex $rowidlist $row] $id]
3694 puts "oops, row $row id $id not in list"
3697 if {![info exists commitinfo($id)]} {
3701 drawcmittext $id $row $col
3705 if {$markingmatches} {
3706 markrowmatches $row $id
3710 proc drawcommits {row {endrow {}}} {
3711 global numcommits iddrawn displayorder curview need_redisplay
3712 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
3717 if {$endrow eq {}} {
3720 if {$endrow >= $numcommits} {
3721 set endrow [expr {$numcommits - 1}]
3724 set rl1 [expr {$row - $downarrowlen - 3}]
3728 set ro1 [expr {$row - 3}]
3732 set r2 [expr {$endrow + $uparrowlen + 3}]
3733 if {$r2 > $numcommits} {
3736 for {set r $rl1} {$r < $r2} {incr r} {
3737 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
3741 set rl1 [expr {$r + 1}]
3747 optimize_rows $ro1 0 $r2
3748 if {$need_redisplay || $nrows_drawn > 2000} {
3753 # make the lines join to already-drawn rows either side
3754 set r [expr {$row - 1}]
3755 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
3758 set er [expr {$endrow + 1}]
3759 if {$er >= $numcommits ||
3760 ![info exists iddrawn([lindex $displayorder $er])]} {
3763 for {} {$r <= $er} {incr r} {
3764 set id [lindex $displayorder $r]
3765 set wasdrawn [info exists iddrawn($id)]
3767 if {$r == $er} break
3768 set nextid [lindex $displayorder [expr {$r + 1}]]
3769 if {$wasdrawn && [info exists iddrawn($nextid)]} {
3770 catch {unset prevlines}
3773 drawparentlinks $id $r
3775 if {[info exists lineends($r)]} {
3776 foreach lid $lineends($r) {
3777 unset prevlines($lid)
3780 set rowids [lindex $rowidlist $r]
3781 foreach lid $rowids {
3782 if {$lid eq {}} continue
3784 # see if this is the first child of any of its parents
3785 foreach p [lindex $parentlist $r] {
3786 if {[lsearch -exact $rowids $p] < 0} {
3787 # make this line extend up to the child
3788 set le [drawlineseg $p $r $er 0]
3789 lappend lineends($le) $p
3793 } elseif {![info exists prevlines($lid)]} {
3794 set le [drawlineseg $lid $r $er 1]
3795 lappend lineends($le) $lid
3796 set prevlines($lid) 1
3802 proc drawfrac {f0 f1} {
3805 set ymax [lindex [$canv cget -scrollregion] 3]
3806 if {$ymax eq {} || $ymax == 0} return
3807 set y0 [expr {int($f0 * $ymax)}]
3808 set row [expr {int(($y0 - 3) / $linespc) - 1}]
3809 set y1 [expr {int($f1 * $ymax)}]
3810 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
3811 drawcommits $row $endrow
3814 proc drawvisible {} {
3816 eval drawfrac [$canv yview]
3819 proc clear_display {} {
3820 global iddrawn linesegs need_redisplay nrows_drawn
3821 global vhighlights fhighlights nhighlights rhighlights
3824 catch {unset iddrawn}
3825 catch {unset linesegs}
3826 catch {unset vhighlights}
3827 catch {unset fhighlights}
3828 catch {unset nhighlights}
3829 catch {unset rhighlights}
3830 set need_redisplay 0
3834 proc findcrossings {id} {
3835 global rowidlist parentlist numcommits displayorder
3839 foreach {s e} [rowranges $id] {
3840 if {$e >= $numcommits} {
3841 set e [expr {$numcommits - 1}]
3843 if {$e <= $s} continue
3844 for {set row $e} {[incr row -1] >= $s} {} {
3845 set x [lsearch -exact [lindex $rowidlist $row] $id]
3847 set olds [lindex $parentlist $row]
3848 set kid [lindex $displayorder $row]
3849 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
3850 if {$kidx < 0} continue
3851 set nextrow [lindex $rowidlist [expr {$row + 1}]]
3853 set px [lsearch -exact $nextrow $p]
3854 if {$px < 0} continue
3855 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
3856 if {[lsearch -exact $ccross $p] >= 0} continue
3857 if {$x == $px + ($kidx < $px? -1: 1)} {
3859 } elseif {[lsearch -exact $cross $p] < 0} {
3866 return [concat $ccross {{}} $cross]
3869 proc assigncolor {id} {
3870 global colormap colors nextcolor
3871 global commitrow parentlist children children curview
3873 if {[info exists colormap($id)]} return
3874 set ncolors [llength $colors]
3875 if {[info exists children($curview,$id)]} {
3876 set kids $children($curview,$id)
3880 if {[llength $kids] == 1} {
3881 set child [lindex $kids 0]
3882 if {[info exists colormap($child)]
3883 && [llength [lindex $parentlist $commitrow($curview,$child)]] == 1} {
3884 set colormap($id) $colormap($child)
3890 foreach x [findcrossings $id] {
3892 # delimiter between corner crossings and other crossings
3893 if {[llength $badcolors] >= $ncolors - 1} break
3894 set origbad $badcolors
3896 if {[info exists colormap($x)]
3897 && [lsearch -exact $badcolors $colormap($x)] < 0} {
3898 lappend badcolors $colormap($x)
3901 if {[llength $badcolors] >= $ncolors} {
3902 set badcolors $origbad
3904 set origbad $badcolors
3905 if {[llength $badcolors] < $ncolors - 1} {
3906 foreach child $kids {
3907 if {[info exists colormap($child)]
3908 && [lsearch -exact $badcolors $colormap($child)] < 0} {
3909 lappend badcolors $colormap($child)
3911 foreach p [lindex $parentlist $commitrow($curview,$child)] {
3912 if {[info exists colormap($p)]
3913 && [lsearch -exact $badcolors $colormap($p)] < 0} {
3914 lappend badcolors $colormap($p)
3918 if {[llength $badcolors] >= $ncolors} {
3919 set badcolors $origbad
3922 for {set i 0} {$i <= $ncolors} {incr i} {
3923 set c [lindex $colors $nextcolor]
3924 if {[incr nextcolor] >= $ncolors} {
3927 if {[lsearch -exact $badcolors $c]} break
3929 set colormap($id) $c
3932 proc bindline {t id} {
3935 $canv bind $t <Enter> "lineenter %x %y $id"
3936 $canv bind $t <Motion> "linemotion %x %y $id"
3937 $canv bind $t <Leave> "lineleave $id"
3938 $canv bind $t <Button-1> "lineclick %x %y $id 1"
3941 proc drawtags {id x xt y1} {
3942 global idtags idheads idotherrefs mainhead
3943 global linespc lthickness
3944 global canv mainfont commitrow rowtextx curview fgcolor bgcolor
3949 if {[info exists idtags($id)]} {
3950 set marks $idtags($id)
3951 set ntags [llength $marks]
3953 if {[info exists idheads($id)]} {
3954 set marks [concat $marks $idheads($id)]
3955 set nheads [llength $idheads($id)]
3957 if {[info exists idotherrefs($id)]} {
3958 set marks [concat $marks $idotherrefs($id)]
3964 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
3965 set yt [expr {$y1 - 0.5 * $linespc}]
3966 set yb [expr {$yt + $linespc - 1}]
3970 foreach tag $marks {
3972 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
3973 set wid [font measure [concat $mainfont bold] $tag]
3975 set wid [font measure $mainfont $tag]
3979 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
3981 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
3982 -width $lthickness -fill black -tags tag.$id]
3984 foreach tag $marks x $xvals wid $wvals {
3985 set xl [expr {$x + $delta}]
3986 set xr [expr {$x + $delta + $wid + $lthickness}]
3988 if {[incr ntags -1] >= 0} {
3990 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
3991 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
3992 -width 1 -outline black -fill yellow -tags tag.$id]
3993 $canv bind $t <1> [list showtag $tag 1]
3994 set rowtextx($commitrow($curview,$id)) [expr {$xr + $linespc}]
3996 # draw a head or other ref
3997 if {[incr nheads -1] >= 0} {
3999 if {$tag eq $mainhead} {
4005 set xl [expr {$xl - $delta/2}]
4006 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
4007 -width 1 -outline black -fill $col -tags tag.$id
4008 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
4009 set rwid [font measure $mainfont $remoteprefix]
4010 set xi [expr {$x + 1}]
4011 set yti [expr {$yt + 1}]
4012 set xri [expr {$x + $rwid}]
4013 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
4014 -width 0 -fill "#ffddaa" -tags tag.$id
4017 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
4018 -font $font -tags [list tag.$id text]]
4020 $canv bind $t <1> [list showtag $tag 1]
4021 } elseif {$nheads >= 0} {
4022 $canv bind $t <Button-3> [list headmenu %X %Y $id $tag]
4028 proc xcoord {i level ln} {
4029 global canvx0 xspc1 xspc2
4031 set x [expr {$canvx0 + $i * $xspc1($ln)}]
4032 if {$i > 0 && $i == $level} {
4033 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
4034 } elseif {$i > $level} {
4035 set x [expr {$x + $xspc2 - $xspc1($ln)}]
4040 proc show_status {msg} {
4041 global canv mainfont fgcolor
4044 $canv create text 3 3 -anchor nw -text $msg -font $mainfont \
4045 -tags text -fill $fgcolor
4048 # Insert a new commit as the child of the commit on row $row.
4049 # The new commit will be displayed on row $row and the commits
4050 # on that row and below will move down one row.
4051 proc insertrow {row newcmit} {
4052 global displayorder parentlist commitlisted children
4053 global commitrow curview rowidlist rowisopt rowfinal numcommits
4055 global selectedline commitidx ordertok
4057 if {$row >= $numcommits} {
4058 puts "oops, inserting new row $row but only have $numcommits rows"
4061 set p [lindex $displayorder $row]
4062 set displayorder [linsert $displayorder $row $newcmit]
4063 set parentlist [linsert $parentlist $row $p]
4064 set kids $children($curview,$p)
4065 lappend kids $newcmit
4066 set children($curview,$p) $kids
4067 set children($curview,$newcmit) {}
4068 set commitlisted [linsert $commitlisted $row 1]
4069 set l [llength $displayorder]
4070 for {set r $row} {$r < $l} {incr r} {
4071 set id [lindex $displayorder $r]
4072 set commitrow($curview,$id) $r
4074 incr commitidx($curview)
4075 set ordertok($curview,$newcmit) $ordertok($curview,$p)
4077 set idlist [lindex $rowidlist $row]
4078 if {[llength $kids] == 1} {
4079 set col [lsearch -exact $idlist $p]
4080 lset idlist $col $newcmit
4082 set col [llength $idlist]
4083 lappend idlist $newcmit
4085 set rowidlist [linsert $rowidlist $row $idlist]
4086 set rowisopt [linsert $rowisopt $row 0]
4087 set rowfinal [linsert $rowfinal $row [lindex $rowfinal $row]]
4091 if {[info exists selectedline] && $selectedline >= $row} {
4097 # Remove a commit that was inserted with insertrow on row $row.
4098 proc removerow {row} {
4099 global displayorder parentlist commitlisted children
4100 global commitrow curview rowidlist rowisopt rowfinal numcommits
4102 global linesegends selectedline commitidx
4104 if {$row >= $numcommits} {
4105 puts "oops, removing row $row but only have $numcommits rows"
4108 set rp1 [expr {$row + 1}]
4109 set id [lindex $displayorder $row]
4110 set p [lindex $parentlist $row]
4111 set displayorder [lreplace $displayorder $row $row]
4112 set parentlist [lreplace $parentlist $row $row]
4113 set commitlisted [lreplace $commitlisted $row $row]
4114 set kids $children($curview,$p)
4115 set i [lsearch -exact $kids $id]
4117 set kids [lreplace $kids $i $i]
4118 set children($curview,$p) $kids
4120 set l [llength $displayorder]
4121 for {set r $row} {$r < $l} {incr r} {
4122 set id [lindex $displayorder $r]
4123 set commitrow($curview,$id) $r
4125 incr commitidx($curview) -1
4127 set rowidlist [lreplace $rowidlist $row $row]
4128 set rowisopt [lreplace $rowisopt $row $row]
4129 set rowfinal [lreplace $rowfinal $row $row]
4133 if {[info exists selectedline] && $selectedline > $row} {
4134 incr selectedline -1
4139 # Don't change the text pane cursor if it is currently the hand cursor,
4140 # showing that we are over a sha1 ID link.
4141 proc settextcursor {c} {
4142 global ctext curtextcursor
4144 if {[$ctext cget -cursor] == $curtextcursor} {
4145 $ctext config -cursor $c
4147 set curtextcursor $c
4150 proc nowbusy {what} {
4153 if {[array names isbusy] eq {}} {
4154 . config -cursor watch
4160 proc notbusy {what} {
4161 global isbusy maincursor textcursor
4163 catch {unset isbusy($what)}
4164 if {[array names isbusy] eq {}} {
4165 . config -cursor $maincursor
4166 settextcursor $textcursor
4170 proc findmatches {f} {
4171 global findtype findstring
4172 if {$findtype == "Regexp"} {
4173 set matches [regexp -indices -all -inline $findstring $f]
4176 if {$findtype == "IgnCase"} {
4177 set f [string tolower $f]
4178 set fs [string tolower $fs]
4182 set l [string length $fs]
4183 while {[set j [string first $fs $f $i]] >= 0} {
4184 lappend matches [list $j [expr {$j+$l-1}]]
4185 set i [expr {$j + $l}]
4191 proc dofind {{rev 0}} {
4192 global findstring findstartline findcurline selectedline numcommits
4195 cancel_next_highlight
4197 if {$findstring eq {} || $numcommits == 0} return
4198 if {![info exists selectedline]} {
4199 set findstartline [lindex [visiblerows] $rev]
4201 set findstartline $selectedline
4203 set findcurline $findstartline
4208 if {$findcurline == 0} {
4209 set findcurline $numcommits
4216 proc findnext {restart} {
4218 if {![info exists findcurline]} {
4232 if {![info exists findcurline]} {
4241 global commitdata commitinfo numcommits findstring findpattern findloc
4242 global findstartline findcurline displayorder
4244 set fldtypes {Headline Author Date Committer CDate Comments}
4245 set l [expr {$findcurline + 1}]
4246 if {$l >= $numcommits} {
4249 if {$l <= $findstartline} {
4250 set lim [expr {$findstartline + 1}]
4254 if {$lim - $l > 500} {
4255 set lim [expr {$l + 500}]
4258 for {} {$l < $lim} {incr l} {
4259 set id [lindex $displayorder $l]
4260 # shouldn't happen unless git log doesn't give all the commits...
4261 if {![info exists commitdata($id)]} continue
4262 if {![doesmatch $commitdata($id)]} continue
4263 if {![info exists commitinfo($id)]} {
4266 set info $commitinfo($id)
4267 foreach f $info ty $fldtypes {
4268 if {($findloc eq "All fields" || $findloc eq $ty) &&
4276 if {$l == $findstartline + 1} {
4282 set findcurline [expr {$l - 1}]
4286 proc findmorerev {} {
4287 global commitdata commitinfo numcommits findstring findpattern findloc
4288 global findstartline findcurline displayorder
4290 set fldtypes {Headline Author Date Committer CDate Comments}
4296 if {$l >= $findstartline} {
4297 set lim [expr {$findstartline - 1}]
4301 if {$l - $lim > 500} {
4302 set lim [expr {$l - 500}]
4305 for {} {$l > $lim} {incr l -1} {
4306 set id [lindex $displayorder $l]
4307 if {![info exists commitdata($id)]} continue
4308 if {![doesmatch $commitdata($id)]} continue
4309 if {![info exists commitinfo($id)]} {
4312 set info $commitinfo($id)
4313 foreach f $info ty $fldtypes {
4314 if {($findloc eq "All fields" || $findloc eq $ty) &&
4328 set findcurline [expr {$l + 1}]
4332 proc findselectline {l} {
4333 global findloc commentend ctext findcurline markingmatches
4335 set markingmatches 1
4338 if {$findloc == "All fields" || $findloc == "Comments"} {
4339 # highlight the matches in the comments
4340 set f [$ctext get 1.0 $commentend]
4341 set matches [findmatches $f]
4342 foreach match $matches {
4343 set start [lindex $match 0]
4344 set end [expr {[lindex $match 1] + 1}]
4345 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
4351 # mark the bits of a headline or author that match a find string
4352 proc markmatches {canv l str tag matches font row} {
4355 set bbox [$canv bbox $tag]
4356 set x0 [lindex $bbox 0]
4357 set y0 [lindex $bbox 1]
4358 set y1 [lindex $bbox 3]
4359 foreach match $matches {
4360 set start [lindex $match 0]
4361 set end [lindex $match 1]
4362 if {$start > $end} continue
4363 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
4364 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
4365 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
4366 [expr {$x0+$xlen+2}] $y1 \
4367 -outline {} -tags [list match$l matches] -fill yellow]
4369 if {[info exists selectedline] && $row == $selectedline} {
4370 $canv raise $t secsel
4375 proc unmarkmatches {} {
4376 global findids markingmatches findcurline
4378 allcanvs delete matches
4379 catch {unset findids}
4380 set markingmatches 0
4381 catch {unset findcurline}
4384 proc selcanvline {w x y} {
4385 global canv canvy0 ctext linespc
4387 set ymax [lindex [$canv cget -scrollregion] 3]
4388 if {$ymax == {}} return
4389 set yfrac [lindex [$canv yview] 0]
4390 set y [expr {$y + $yfrac * $ymax}]
4391 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
4396 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
4402 proc commit_descriptor {p} {
4404 if {![info exists commitinfo($p)]} {
4408 if {[llength $commitinfo($p)] > 1} {
4409 set l [lindex $commitinfo($p) 0]
4414 # append some text to the ctext widget, and make any SHA1 ID
4415 # that we know about be a clickable link.
4416 proc appendwithlinks {text tags} {
4417 global ctext commitrow linknum curview pendinglinks
4419 set start [$ctext index "end - 1c"]
4420 $ctext insert end $text $tags
4421 set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
4425 set linkid [string range $text $s $e]
4427 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
4428 setlink $linkid link$linknum
4433 proc setlink {id lk} {
4434 global curview commitrow ctext pendinglinks commitinterest
4436 if {[info exists commitrow($curview,$id)]} {
4437 $ctext tag conf $lk -foreground blue -underline 1
4438 $ctext tag bind $lk <1> [list selectline $commitrow($curview,$id) 1]
4439 $ctext tag bind $lk <Enter> {linkcursor %W 1}
4440 $ctext tag bind $lk <Leave> {linkcursor %W -1}
4442 lappend pendinglinks($id) $lk
4443 lappend commitinterest($id) {makelink %I}
4447 proc makelink {id} {
4450 if {![info exists pendinglinks($id)]} return
4451 foreach lk $pendinglinks($id) {
4454 unset pendinglinks($id)
4457 proc linkcursor {w inc} {
4458 global linkentercount curtextcursor
4460 if {[incr linkentercount $inc] > 0} {
4461 $w configure -cursor hand2
4463 $w configure -cursor $curtextcursor
4464 if {$linkentercount < 0} {
4465 set linkentercount 0
4470 proc viewnextline {dir} {
4474 set ymax [lindex [$canv cget -scrollregion] 3]
4475 set wnow [$canv yview]
4476 set wtop [expr {[lindex $wnow 0] * $ymax}]
4477 set newtop [expr {$wtop + $dir * $linespc}]
4480 } elseif {$newtop > $ymax} {
4483 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
4486 # add a list of tag or branch names at position pos
4487 # returns the number of names inserted
4488 proc appendrefs {pos ids var} {
4489 global ctext commitrow linknum curview $var maxrefs
4491 if {[catch {$ctext index $pos}]} {
4494 $ctext conf -state normal
4495 $ctext delete $pos "$pos lineend"
4498 foreach tag [set $var\($id\)] {
4499 lappend tags [list $tag $id]
4502 if {[llength $tags] > $maxrefs} {
4503 $ctext insert $pos "many ([llength $tags])"
4505 set tags [lsort -index 0 -decreasing $tags]
4508 set id [lindex $ti 1]
4511 $ctext tag delete $lk
4512 $ctext insert $pos $sep
4513 $ctext insert $pos [lindex $ti 0] $lk
4518 $ctext conf -state disabled
4519 return [llength $tags]
4522 # called when we have finished computing the nearby tags
4523 proc dispneartags {delay} {
4524 global selectedline currentid showneartags tagphase
4526 if {![info exists selectedline] || !$showneartags} return
4527 after cancel dispnexttag
4529 after 200 dispnexttag
4532 after idle dispnexttag
4537 proc dispnexttag {} {
4538 global selectedline currentid showneartags tagphase ctext
4540 if {![info exists selectedline] || !$showneartags} return
4541 switch -- $tagphase {
4543 set dtags [desctags $currentid]
4545 appendrefs precedes $dtags idtags
4549 set atags [anctags $currentid]
4551 appendrefs follows $atags idtags
4555 set dheads [descheads $currentid]
4556 if {$dheads ne {}} {
4557 if {[appendrefs branch $dheads idheads] > 1
4558 && [$ctext get "branch -3c"] eq "h"} {
4559 # turn "Branch" into "Branches"
4560 $ctext conf -state normal
4561 $ctext insert "branch -2c" "es"
4562 $ctext conf -state disabled
4567 if {[incr tagphase] <= 2} {
4568 after idle dispnexttag
4572 proc make_secsel {l} {
4573 global linehtag linentag linedtag canv canv2 canv3
4575 if {![info exists linehtag($l)]} return
4577 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
4578 -tags secsel -fill [$canv cget -selectbackground]]
4580 $canv2 delete secsel
4581 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
4582 -tags secsel -fill [$canv2 cget -selectbackground]]
4584 $canv3 delete secsel
4585 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
4586 -tags secsel -fill [$canv3 cget -selectbackground]]
4590 proc selectline {l isnew} {
4591 global canv ctext commitinfo selectedline
4593 global canvy0 linespc parentlist children curview
4594 global currentid sha1entry
4595 global commentend idtags linknum
4596 global mergemax numcommits pending_select
4597 global cmitmode showneartags allcommits
4599 catch {unset pending_select}
4602 cancel_next_highlight
4604 if {$l < 0 || $l >= $numcommits} return
4605 set y [expr {$canvy0 + $l * $linespc}]
4606 set ymax [lindex [$canv cget -scrollregion] 3]
4607 set ytop [expr {$y - $linespc - 1}]
4608 set ybot [expr {$y + $linespc + 1}]
4609 set wnow [$canv yview]
4610 set wtop [expr {[lindex $wnow 0] * $ymax}]
4611 set wbot [expr {[lindex $wnow 1] * $ymax}]
4612 set wh [expr {$wbot - $wtop}]
4614 if {$ytop < $wtop} {
4615 if {$ybot < $wtop} {
4616 set newtop [expr {$y - $wh / 2.0}]
4619 if {$newtop > $wtop - $linespc} {
4620 set newtop [expr {$wtop - $linespc}]
4623 } elseif {$ybot > $wbot} {
4624 if {$ytop > $wbot} {
4625 set newtop [expr {$y - $wh / 2.0}]
4627 set newtop [expr {$ybot - $wh}]
4628 if {$newtop < $wtop + $linespc} {
4629 set newtop [expr {$wtop + $linespc}]
4633 if {$newtop != $wtop} {
4637 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
4644 addtohistory [list selectline $l 0]
4649 set id [lindex $displayorder $l]
4651 $sha1entry delete 0 end
4652 $sha1entry insert 0 $id
4653 $sha1entry selection from 0
4654 $sha1entry selection to end
4657 $ctext conf -state normal
4660 set info $commitinfo($id)
4661 set date [formatdate [lindex $info 2]]
4662 $ctext insert end "Author: [lindex $info 1] $date\n"
4663 set date [formatdate [lindex $info 4]]
4664 $ctext insert end "Committer: [lindex $info 3] $date\n"
4665 if {[info exists idtags($id)]} {
4666 $ctext insert end "Tags:"
4667 foreach tag $idtags($id) {
4668 $ctext insert end " $tag"
4670 $ctext insert end "\n"
4674 set olds [lindex $parentlist $l]
4675 if {[llength $olds] > 1} {
4678 if {$np >= $mergemax} {
4683 $ctext insert end "Parent: " $tag
4684 appendwithlinks [commit_descriptor $p] {}
4689 append headers "Parent: [commit_descriptor $p]"
4693 foreach c $children($curview,$id) {
4694 append headers "Child: [commit_descriptor $c]"
4697 # make anything that looks like a SHA1 ID be a clickable link
4698 appendwithlinks $headers {}
4699 if {$showneartags} {
4700 if {![info exists allcommits]} {
4703 $ctext insert end "Branch: "
4704 $ctext mark set branch "end -1c"
4705 $ctext mark gravity branch left
4706 $ctext insert end "\nFollows: "
4707 $ctext mark set follows "end -1c"
4708 $ctext mark gravity follows left
4709 $ctext insert end "\nPrecedes: "
4710 $ctext mark set precedes "end -1c"
4711 $ctext mark gravity precedes left
4712 $ctext insert end "\n"
4715 $ctext insert end "\n"
4716 set comment [lindex $info 5]
4717 if {[string first "\r" $comment] >= 0} {
4718 set comment [string map {"\r" "\n "} $comment]
4720 appendwithlinks $comment {comment}
4722 $ctext tag remove found 1.0 end
4723 $ctext conf -state disabled
4724 set commentend [$ctext index "end - 1c"]
4726 init_flist "Comments"
4727 if {$cmitmode eq "tree"} {
4729 } elseif {[llength $olds] <= 1} {
4736 proc selfirstline {} {
4741 proc sellastline {} {
4744 set l [expr {$numcommits - 1}]
4748 proc selnextline {dir} {
4751 if {![info exists selectedline]} return
4752 set l [expr {$selectedline + $dir}]
4757 proc selnextpage {dir} {
4758 global canv linespc selectedline numcommits
4760 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
4764 allcanvs yview scroll [expr {$dir * $lpp}] units
4766 if {![info exists selectedline]} return
4767 set l [expr {$selectedline + $dir * $lpp}]
4770 } elseif {$l >= $numcommits} {
4771 set l [expr $numcommits - 1]
4777 proc unselectline {} {
4778 global selectedline currentid
4780 catch {unset selectedline}
4781 catch {unset currentid}
4782 allcanvs delete secsel
4784 cancel_next_highlight
4787 proc reselectline {} {
4790 if {[info exists selectedline]} {
4791 selectline $selectedline 0
4795 proc addtohistory {cmd} {
4796 global history historyindex curview
4798 set elt [list $curview $cmd]
4799 if {$historyindex > 0
4800 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
4804 if {$historyindex < [llength $history]} {
4805 set history [lreplace $history $historyindex end $elt]
4807 lappend history $elt
4810 if {$historyindex > 1} {
4811 .tf.bar.leftbut conf -state normal
4813 .tf.bar.leftbut conf -state disabled
4815 .tf.bar.rightbut conf -state disabled
4821 set view [lindex $elt 0]
4822 set cmd [lindex $elt 1]
4823 if {$curview != $view} {
4830 global history historyindex
4833 if {$historyindex > 1} {
4834 incr historyindex -1
4835 godo [lindex $history [expr {$historyindex - 1}]]
4836 .tf.bar.rightbut conf -state normal
4838 if {$historyindex <= 1} {
4839 .tf.bar.leftbut conf -state disabled
4844 global history historyindex
4847 if {$historyindex < [llength $history]} {
4848 set cmd [lindex $history $historyindex]
4851 .tf.bar.leftbut conf -state normal
4853 if {$historyindex >= [llength $history]} {
4854 .tf.bar.rightbut conf -state disabled
4859 global treefilelist treeidlist diffids diffmergeid treepending
4860 global nullid nullid2
4863 catch {unset diffmergeid}
4864 if {![info exists treefilelist($id)]} {
4865 if {![info exists treepending]} {
4866 if {$id eq $nullid} {
4867 set cmd [list | git ls-files]
4868 } elseif {$id eq $nullid2} {
4869 set cmd [list | git ls-files --stage -t]
4871 set cmd [list | git ls-tree -r $id]
4873 if {[catch {set gtf [open $cmd r]}]} {
4877 set treefilelist($id) {}
4878 set treeidlist($id) {}
4879 fconfigure $gtf -blocking 0
4880 filerun $gtf [list gettreeline $gtf $id]
4887 proc gettreeline {gtf id} {
4888 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
4891 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
4892 if {$diffids eq $nullid} {
4895 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
4896 set i [string first "\t" $line]
4897 if {$i < 0} continue
4898 set sha1 [lindex $line 2]
4899 set fname [string range $line [expr {$i+1}] end]
4900 if {[string index $fname 0] eq "\""} {
4901 set fname [lindex $fname 0]
4903 lappend treeidlist($id) $sha1
4905 lappend treefilelist($id) $fname
4908 return [expr {$nl >= 1000? 2: 1}]
4912 if {$cmitmode ne "tree"} {
4913 if {![info exists diffmergeid]} {
4914 gettreediffs $diffids
4916 } elseif {$id ne $diffids} {
4925 global treefilelist treeidlist diffids nullid nullid2
4926 global ctext commentend
4928 set i [lsearch -exact $treefilelist($diffids) $f]
4930 puts "oops, $f not in list for id $diffids"
4933 if {$diffids eq $nullid} {
4934 if {[catch {set bf [open $f r]} err]} {
4935 puts "oops, can't read $f: $err"
4939 set blob [lindex $treeidlist($diffids) $i]
4940 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
4941 puts "oops, error reading blob $blob: $err"
4945 fconfigure $bf -blocking 0
4946 filerun $bf [list getblobline $bf $diffids]
4947 $ctext config -state normal
4948 clear_ctext $commentend
4949 $ctext insert end "\n"
4950 $ctext insert end "$f\n" filesep
4951 $ctext config -state disabled
4952 $ctext yview $commentend
4955 proc getblobline {bf id} {
4956 global diffids cmitmode ctext
4958 if {$id ne $diffids || $cmitmode ne "tree"} {
4962 $ctext config -state normal
4964 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
4965 $ctext insert end "$line\n"
4968 # delete last newline
4969 $ctext delete "end - 2c" "end - 1c"
4973 $ctext config -state disabled
4974 return [expr {$nl >= 1000? 2: 1}]
4977 proc mergediff {id l} {
4978 global diffmergeid diffopts mdifffd
4984 # this doesn't seem to actually affect anything...
4985 set env(GIT_DIFF_OPTS) $diffopts
4986 set cmd [concat | git diff-tree --no-commit-id --cc $id]
4987 if {[catch {set mdf [open $cmd r]} err]} {
4988 error_popup "Error getting merge diffs: $err"
4991 fconfigure $mdf -blocking 0
4992 set mdifffd($id) $mdf
4993 set np [llength [lindex $parentlist $l]]
4994 filerun $mdf [list getmergediffline $mdf $id $np]
4997 proc getmergediffline {mdf id np} {
4998 global diffmergeid ctext cflist mergemax
4999 global difffilestart mdifffd
5001 $ctext conf -state normal
5003 while {[incr nr] <= 1000 && [gets $mdf line] >= 0} {
5004 if {![info exists diffmergeid] || $id != $diffmergeid
5005 || $mdf != $mdifffd($id)} {
5009 if {[regexp {^diff --cc (.*)} $line match fname]} {
5010 # start of a new file
5011 $ctext insert end "\n"
5012 set here [$ctext index "end - 1c"]
5013 lappend difffilestart $here
5014 add_flist [list $fname]
5015 set l [expr {(78 - [string length $fname]) / 2}]
5016 set pad [string range "----------------------------------------" 1 $l]
5017 $ctext insert end "$pad $fname $pad\n" filesep
5018 } elseif {[regexp {^@@} $line]} {
5019 $ctext insert end "$line\n" hunksep
5020 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
5023 # parse the prefix - one ' ', '-' or '+' for each parent
5028 for {set j 0} {$j < $np} {incr j} {
5029 set c [string range $line $j $j]
5032 } elseif {$c == "-"} {
5034 } elseif {$c == "+"} {
5043 if {!$isbad && $minuses ne {} && $pluses eq {}} {
5044 # line doesn't appear in result, parents in $minuses have the line
5045 set num [lindex $minuses 0]
5046 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
5047 # line appears in result, parents in $pluses don't have the line
5048 lappend tags mresult
5049 set num [lindex $spaces 0]
5052 if {$num >= $mergemax} {
5057 $ctext insert end "$line\n" $tags
5060 $ctext conf -state disabled
5065 return [expr {$nr >= 1000? 2: 1}]
5068 proc startdiff {ids} {
5069 global treediffs diffids treepending diffmergeid nullid nullid2
5072 catch {unset diffmergeid}
5073 if {![info exists treediffs($ids)] ||
5074 [lsearch -exact $ids $nullid] >= 0 ||
5075 [lsearch -exact $ids $nullid2] >= 0} {
5076 if {![info exists treepending]} {
5084 proc addtocflist {ids} {
5085 global treediffs cflist
5086 add_flist $treediffs($ids)
5090 proc diffcmd {ids flags} {
5091 global nullid nullid2
5093 set i [lsearch -exact $ids $nullid]
5094 set j [lsearch -exact $ids $nullid2]
5096 if {[llength $ids] > 1 && $j < 0} {
5097 # comparing working directory with some specific revision
5098 set cmd [concat | git diff-index $flags]
5100 lappend cmd -R [lindex $ids 1]
5102 lappend cmd [lindex $ids 0]
5105 # comparing working directory with index
5106 set cmd [concat | git diff-files $flags]
5111 } elseif {$j >= 0} {
5112 set cmd [concat | git diff-index --cached $flags]
5113 if {[llength $ids] > 1} {
5114 # comparing index with specific revision
5116 lappend cmd -R [lindex $ids 1]
5118 lappend cmd [lindex $ids 0]
5121 # comparing index with HEAD
5125 set cmd [concat | git diff-tree -r $flags $ids]
5130 proc gettreediffs {ids} {
5131 global treediff treepending
5133 set treepending $ids
5135 if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
5136 fconfigure $gdtf -blocking 0
5137 filerun $gdtf [list gettreediffline $gdtf $ids]
5140 proc gettreediffline {gdtf ids} {
5141 global treediff treediffs treepending diffids diffmergeid
5145 while {[incr nr] <= 1000 && [gets $gdtf line] >= 0} {
5146 set i [string first "\t" $line]
5148 set file [string range $line [expr {$i+1}] end]
5149 if {[string index $file 0] eq "\""} {
5150 set file [lindex $file 0]
5152 lappend treediff $file
5156 return [expr {$nr >= 1000? 2: 1}]
5159 set treediffs($ids) $treediff
5161 if {$cmitmode eq "tree"} {
5163 } elseif {$ids != $diffids} {
5164 if {![info exists diffmergeid]} {
5165 gettreediffs $diffids
5173 # empty string or positive integer
5174 proc diffcontextvalidate {v} {
5175 return [regexp {^(|[1-9][0-9]*)$} $v]
5178 proc diffcontextchange {n1 n2 op} {
5179 global diffcontextstring diffcontext
5181 if {[string is integer -strict $diffcontextstring]} {
5182 if {$diffcontextstring > 0} {
5183 set diffcontext $diffcontextstring
5189 proc getblobdiffs {ids} {
5190 global diffopts blobdifffd diffids env
5191 global diffinhdr treediffs
5194 set env(GIT_DIFF_OPTS) $diffopts
5195 if {[catch {set bdf [open [diffcmd $ids "-p -C --no-commit-id -U$diffcontext"] r]} err]} {
5196 puts "error getting diffs: $err"
5200 fconfigure $bdf -blocking 0
5201 set blobdifffd($ids) $bdf
5202 filerun $bdf [list getblobdiffline $bdf $diffids]
5205 proc setinlist {var i val} {
5208 while {[llength [set $var]] < $i} {
5211 if {[llength [set $var]] == $i} {
5218 proc makediffhdr {fname ids} {
5219 global ctext curdiffstart treediffs
5221 set i [lsearch -exact $treediffs($ids) $fname]
5223 setinlist difffilestart $i $curdiffstart
5225 set l [expr {(78 - [string length $fname]) / 2}]
5226 set pad [string range "----------------------------------------" 1 $l]
5227 $ctext insert $curdiffstart "$pad $fname $pad" filesep
5230 proc getblobdiffline {bdf ids} {
5231 global diffids blobdifffd ctext curdiffstart
5232 global diffnexthead diffnextnote difffilestart
5233 global diffinhdr treediffs
5236 $ctext conf -state normal
5237 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
5238 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
5242 if {![string compare -length 11 "diff --git " $line]} {
5243 # trim off "diff --git "
5244 set line [string range $line 11 end]
5246 # start of a new file
5247 $ctext insert end "\n"
5248 set curdiffstart [$ctext index "end - 1c"]
5249 $ctext insert end "\n" filesep
5250 # If the name hasn't changed the length will be odd,
5251 # the middle char will be a space, and the two bits either
5252 # side will be a/name and b/name, or "a/name" and "b/name".
5253 # If the name has changed we'll get "rename from" and
5254 # "rename to" or "copy from" and "copy to" lines following this,
5255 # and we'll use them to get the filenames.
5256 # This complexity is necessary because spaces in the filename(s)
5257 # don't get escaped.
5258 set l [string length $line]
5259 set i [expr {$l / 2}]
5260 if {!(($l & 1) && [string index $line $i] eq " " &&
5261 [string range $line 2 [expr {$i - 1}]] eq \
5262 [string range $line [expr {$i + 3}] end])} {
5265 # unescape if quoted and chop off the a/ from the front
5266 if {[string index $line 0] eq "\""} {
5267 set fname [string range [lindex $line 0] 2 end]
5269 set fname [string range $line 2 [expr {$i - 1}]]
5271 makediffhdr $fname $ids
5273 } elseif {[regexp {^@@ -([0-9]+)(,[0-9]+)? \+([0-9]+)(,[0-9]+)? @@(.*)} \
5274 $line match f1l f1c f2l f2c rest]} {
5275 $ctext insert end "$line\n" hunksep
5278 } elseif {$diffinhdr} {
5279 if {![string compare -length 12 "rename from " $line] ||
5280 ![string compare -length 10 "copy from " $line]} {
5281 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
5282 if {[string index $fname 0] eq "\""} {
5283 set fname [lindex $fname 0]
5285 set i [lsearch -exact $treediffs($ids) $fname]
5287 setinlist difffilestart $i $curdiffstart
5289 } elseif {![string compare -length 10 $line "rename to "] ||
5290 ![string compare -length 8 $line "copy to "]} {
5291 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
5292 if {[string index $fname 0] eq "\""} {
5293 set fname [lindex $fname 0]
5295 makediffhdr $fname $ids
5296 } elseif {[string compare -length 3 $line "---"] == 0} {
5299 } elseif {[string compare -length 3 $line "+++"] == 0} {
5303 $ctext insert end "$line\n" filesep
5306 set x [string range $line 0 0]
5307 if {$x == "-" || $x == "+"} {
5308 set tag [expr {$x == "+"}]
5309 $ctext insert end "$line\n" d$tag
5310 } elseif {$x == " "} {
5311 $ctext insert end "$line\n"
5313 # "\ No newline at end of file",
5314 # or something else we don't recognize
5315 $ctext insert end "$line\n" hunksep
5319 $ctext conf -state disabled
5324 return [expr {$nr >= 1000? 2: 1}]
5327 proc changediffdisp {} {
5328 global ctext diffelide
5330 $ctext tag conf d0 -elide [lindex $diffelide 0]
5331 $ctext tag conf d1 -elide [lindex $diffelide 1]
5335 global difffilestart ctext
5336 set prev [lindex $difffilestart 0]
5337 set here [$ctext index @0,0]
5338 foreach loc $difffilestart {
5339 if {[$ctext compare $loc >= $here]} {
5349 global difffilestart ctext
5350 set here [$ctext index @0,0]
5351 foreach loc $difffilestart {
5352 if {[$ctext compare $loc > $here]} {
5359 proc clear_ctext {{first 1.0}} {
5360 global ctext smarktop smarkbot
5363 set l [lindex [split $first .] 0]
5364 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
5367 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
5370 $ctext delete $first end
5371 if {$first eq "1.0"} {
5372 catch {unset pendinglinks}
5376 proc incrsearch {name ix op} {
5377 global ctext searchstring searchdirn
5379 $ctext tag remove found 1.0 end
5380 if {[catch {$ctext index anchor}]} {
5381 # no anchor set, use start of selection, or of visible area
5382 set sel [$ctext tag ranges sel]
5384 $ctext mark set anchor [lindex $sel 0]
5385 } elseif {$searchdirn eq "-forwards"} {
5386 $ctext mark set anchor @0,0
5388 $ctext mark set anchor @0,[winfo height $ctext]
5391 if {$searchstring ne {}} {
5392 set here [$ctext search $searchdirn -- $searchstring anchor]
5401 global sstring ctext searchstring searchdirn
5404 $sstring icursor end
5405 set searchdirn -forwards
5406 if {$searchstring ne {}} {
5407 set sel [$ctext tag ranges sel]
5409 set start "[lindex $sel 0] + 1c"
5410 } elseif {[catch {set start [$ctext index anchor]}]} {
5413 set match [$ctext search -count mlen -- $searchstring $start]
5414 $ctext tag remove sel 1.0 end
5420 set mend "$match + $mlen c"
5421 $ctext tag add sel $match $mend
5422 $ctext mark unset anchor
5426 proc dosearchback {} {
5427 global sstring ctext searchstring searchdirn
5430 $sstring icursor end
5431 set searchdirn -backwards
5432 if {$searchstring ne {}} {
5433 set sel [$ctext tag ranges sel]
5435 set start [lindex $sel 0]
5436 } elseif {[catch {set start [$ctext index anchor]}]} {
5437 set start @0,[winfo height $ctext]
5439 set match [$ctext search -backwards -count ml -- $searchstring $start]
5440 $ctext tag remove sel 1.0 end
5446 set mend "$match + $ml c"
5447 $ctext tag add sel $match $mend
5448 $ctext mark unset anchor
5452 proc searchmark {first last} {
5453 global ctext searchstring
5457 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
5458 if {$match eq {}} break
5459 set mend "$match + $mlen c"
5460 $ctext tag add found $match $mend
5464 proc searchmarkvisible {doall} {
5465 global ctext smarktop smarkbot
5467 set topline [lindex [split [$ctext index @0,0] .] 0]
5468 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
5469 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
5470 # no overlap with previous
5471 searchmark $topline $botline
5472 set smarktop $topline
5473 set smarkbot $botline
5475 if {$topline < $smarktop} {
5476 searchmark $topline [expr {$smarktop-1}]
5477 set smarktop $topline
5479 if {$botline > $smarkbot} {
5480 searchmark [expr {$smarkbot+1}] $botline
5481 set smarkbot $botline
5486 proc scrolltext {f0 f1} {
5489 .bleft.sb set $f0 $f1
5490 if {$searchstring ne {}} {
5496 global linespc charspc canvx0 canvy0 mainfont
5497 global xspc1 xspc2 lthickness
5499 set linespc [font metrics $mainfont -linespace]
5500 set charspc [font measure $mainfont "m"]
5501 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
5502 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
5503 set lthickness [expr {int($linespc / 9) + 1}]
5504 set xspc1(0) $linespc
5512 set ymax [lindex [$canv cget -scrollregion] 3]
5513 if {$ymax eq {} || $ymax == 0} return
5514 set span [$canv yview]
5517 allcanvs yview moveto [lindex $span 0]
5519 if {[info exists selectedline]} {
5520 selectline $selectedline 0
5521 allcanvs yview moveto [lindex $span 0]
5525 proc incrfont {inc} {
5526 global mainfont textfont ctext canv phase cflist showrefstop
5527 global charspc tabstop
5528 global stopped entries
5530 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
5531 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
5533 $ctext conf -font $textfont -tabs "[expr {$tabstop * $charspc}]"
5534 $cflist conf -font $textfont
5535 $ctext tag conf filesep -font [concat $textfont bold]
5536 foreach e $entries {
5537 $e conf -font $mainfont
5539 if {$phase eq "getcommits"} {
5540 $canv itemconf textitems -font $mainfont
5542 if {[info exists showrefstop] && [winfo exists $showrefstop]} {
5543 $showrefstop.list conf -font $mainfont
5549 global sha1entry sha1string
5550 if {[string length $sha1string] == 40} {
5551 $sha1entry delete 0 end
5555 proc sha1change {n1 n2 op} {
5556 global sha1string currentid sha1but
5557 if {$sha1string == {}
5558 || ([info exists currentid] && $sha1string == $currentid)} {
5563 if {[$sha1but cget -state] == $state} return
5564 if {$state == "normal"} {
5565 $sha1but conf -state normal -relief raised -text "Goto: "
5567 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
5571 proc gotocommit {} {
5572 global sha1string currentid commitrow tagids headids
5573 global displayorder numcommits curview
5575 if {$sha1string == {}
5576 || ([info exists currentid] && $sha1string == $currentid)} return
5577 if {[info exists tagids($sha1string)]} {
5578 set id $tagids($sha1string)
5579 } elseif {[info exists headids($sha1string)]} {
5580 set id $headids($sha1string)
5582 set id [string tolower $sha1string]
5583 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
5585 foreach i $displayorder {
5586 if {[string match $id* $i]} {
5590 if {$matches ne {}} {
5591 if {[llength $matches] > 1} {
5592 error_popup "Short SHA1 id $id is ambiguous"
5595 set id [lindex $matches 0]
5599 if {[info exists commitrow($curview,$id)]} {
5600 selectline $commitrow($curview,$id) 1
5603 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
5608 error_popup "$type $sha1string is not known"
5611 proc lineenter {x y id} {
5612 global hoverx hovery hoverid hovertimer
5613 global commitinfo canv
5615 if {![info exists commitinfo($id)] && ![getcommit $id]} return
5619 if {[info exists hovertimer]} {
5620 after cancel $hovertimer
5622 set hovertimer [after 500 linehover]
5626 proc linemotion {x y id} {
5627 global hoverx hovery hoverid hovertimer
5629 if {[info exists hoverid] && $id == $hoverid} {
5632 if {[info exists hovertimer]} {
5633 after cancel $hovertimer
5635 set hovertimer [after 500 linehover]
5639 proc lineleave {id} {
5640 global hoverid hovertimer canv
5642 if {[info exists hoverid] && $id == $hoverid} {
5644 if {[info exists hovertimer]} {
5645 after cancel $hovertimer
5653 global hoverx hovery hoverid hovertimer
5654 global canv linespc lthickness
5655 global commitinfo mainfont
5657 set text [lindex $commitinfo($hoverid) 0]
5658 set ymax [lindex [$canv cget -scrollregion] 3]
5659 if {$ymax == {}} return
5660 set yfrac [lindex [$canv yview] 0]
5661 set x [expr {$hoverx + 2 * $linespc}]
5662 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
5663 set x0 [expr {$x - 2 * $lthickness}]
5664 set y0 [expr {$y - 2 * $lthickness}]
5665 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
5666 set y1 [expr {$y + $linespc + 2 * $lthickness}]
5667 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
5668 -fill \#ffff80 -outline black -width 1 -tags hover]
5670 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
5675 proc clickisonarrow {id y} {
5678 set ranges [rowranges $id]
5679 set thresh [expr {2 * $lthickness + 6}]
5680 set n [expr {[llength $ranges] - 1}]
5681 for {set i 1} {$i < $n} {incr i} {
5682 set row [lindex $ranges $i]
5683 if {abs([yc $row] - $y) < $thresh} {
5690 proc arrowjump {id n y} {
5693 # 1 <-> 2, 3 <-> 4, etc...
5694 set n [expr {(($n - 1) ^ 1) + 1}]
5695 set row [lindex [rowranges $id] $n]
5697 set ymax [lindex [$canv cget -scrollregion] 3]
5698 if {$ymax eq {} || $ymax <= 0} return
5699 set view [$canv yview]
5700 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
5701 set yfrac [expr {$yt / $ymax - $yspan / 2}]
5705 allcanvs yview moveto $yfrac
5708 proc lineclick {x y id isnew} {
5709 global ctext commitinfo children canv thickerline curview commitrow
5711 if {![info exists commitinfo($id)] && ![getcommit $id]} return
5716 # draw this line thicker than normal
5720 set ymax [lindex [$canv cget -scrollregion] 3]
5721 if {$ymax eq {}} return
5722 set yfrac [lindex [$canv yview] 0]
5723 set y [expr {$y + $yfrac * $ymax}]
5725 set dirn [clickisonarrow $id $y]
5727 arrowjump $id $dirn $y
5732 addtohistory [list lineclick $x $y $id 0]
5734 # fill the details pane with info about this line
5735 $ctext conf -state normal
5737 $ctext insert end "Parent:\t"
5738 $ctext insert end $id link0
5740 set info $commitinfo($id)
5741 $ctext insert end "\n\t[lindex $info 0]\n"
5742 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
5743 set date [formatdate [lindex $info 2]]
5744 $ctext insert end "\tDate:\t$date\n"
5745 set kids $children($curview,$id)
5747 $ctext insert end "\nChildren:"
5749 foreach child $kids {
5751 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
5752 set info $commitinfo($child)
5753 $ctext insert end "\n\t"
5754 $ctext insert end $child link$i
5755 setlink $child link$i
5756 $ctext insert end "\n\t[lindex $info 0]"
5757 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
5758 set date [formatdate [lindex $info 2]]
5759 $ctext insert end "\n\tDate:\t$date\n"
5762 $ctext conf -state disabled
5766 proc normalline {} {
5768 if {[info exists thickerline]} {
5776 global commitrow curview
5777 if {[info exists commitrow($curview,$id)]} {
5778 selectline $commitrow($curview,$id) 1
5784 if {![info exists startmstime]} {
5785 set startmstime [clock clicks -milliseconds]
5787 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
5790 proc rowmenu {x y id} {
5791 global rowctxmenu commitrow selectedline rowmenuid curview
5792 global nullid nullid2 fakerowmenu mainhead
5795 if {![info exists selectedline]
5796 || $commitrow($curview,$id) eq $selectedline} {
5801 if {$id ne $nullid && $id ne $nullid2} {
5802 set menu $rowctxmenu
5803 $menu entryconfigure 7 -label "Reset $mainhead branch to here"
5805 set menu $fakerowmenu
5807 $menu entryconfigure "Diff this*" -state $state
5808 $menu entryconfigure "Diff selected*" -state $state
5809 $menu entryconfigure "Make patch" -state $state
5810 tk_popup $menu $x $y
5813 proc diffvssel {dirn} {
5814 global rowmenuid selectedline displayorder
5816 if {![info exists selectedline]} return
5818 set oldid [lindex $displayorder $selectedline]
5819 set newid $rowmenuid
5821 set oldid $rowmenuid
5822 set newid [lindex $displayorder $selectedline]
5824 addtohistory [list doseldiff $oldid $newid]
5825 doseldiff $oldid $newid
5828 proc doseldiff {oldid newid} {
5832 $ctext conf -state normal
5835 $ctext insert end "From "
5836 $ctext insert end $oldid link0
5837 setlink $oldid link0
5838 $ctext insert end "\n "
5839 $ctext insert end [lindex $commitinfo($oldid) 0]
5840 $ctext insert end "\n\nTo "
5841 $ctext insert end $newid link1
5842 setlink $newid link1
5843 $ctext insert end "\n "
5844 $ctext insert end [lindex $commitinfo($newid) 0]
5845 $ctext insert end "\n"
5846 $ctext conf -state disabled
5847 $ctext tag remove found 1.0 end
5848 startdiff [list $oldid $newid]
5852 global rowmenuid currentid commitinfo patchtop patchnum
5854 if {![info exists currentid]} return
5855 set oldid $currentid
5856 set oldhead [lindex $commitinfo($oldid) 0]
5857 set newid $rowmenuid
5858 set newhead [lindex $commitinfo($newid) 0]
5861 catch {destroy $top}
5863 label $top.title -text "Generate patch"
5864 grid $top.title - -pady 10
5865 label $top.from -text "From:"
5866 entry $top.fromsha1 -width 40 -relief flat
5867 $top.fromsha1 insert 0 $oldid
5868 $top.fromsha1 conf -state readonly
5869 grid $top.from $top.fromsha1 -sticky w
5870 entry $top.fromhead -width 60 -relief flat
5871 $top.fromhead insert 0 $oldhead
5872 $top.fromhead conf -state readonly
5873 grid x $top.fromhead -sticky w
5874 label $top.to -text "To:"
5875 entry $top.tosha1 -width 40 -relief flat
5876 $top.tosha1 insert 0 $newid
5877 $top.tosha1 conf -state readonly
5878 grid $top.to $top.tosha1 -sticky w
5879 entry $top.tohead -width 60 -relief flat
5880 $top.tohead insert 0 $newhead
5881 $top.tohead conf -state readonly
5882 grid x $top.tohead -sticky w
5883 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
5884 grid $top.rev x -pady 10
5885 label $top.flab -text "Output file:"
5886 entry $top.fname -width 60
5887 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
5889 grid $top.flab $top.fname -sticky w
5891 button $top.buts.gen -text "Generate" -command mkpatchgo
5892 button $top.buts.can -text "Cancel" -command mkpatchcan
5893 grid $top.buts.gen $top.buts.can
5894 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5895 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5896 grid $top.buts - -pady 10 -sticky ew
5900 proc mkpatchrev {} {
5903 set oldid [$patchtop.fromsha1 get]
5904 set oldhead [$patchtop.fromhead get]
5905 set newid [$patchtop.tosha1 get]
5906 set newhead [$patchtop.tohead get]
5907 foreach e [list fromsha1 fromhead tosha1 tohead] \
5908 v [list $newid $newhead $oldid $oldhead] {
5909 $patchtop.$e conf -state normal
5910 $patchtop.$e delete 0 end
5911 $patchtop.$e insert 0 $v
5912 $patchtop.$e conf -state readonly
5917 global patchtop nullid nullid2
5919 set oldid [$patchtop.fromsha1 get]
5920 set newid [$patchtop.tosha1 get]
5921 set fname [$patchtop.fname get]
5922 set cmd [diffcmd [list $oldid $newid] -p]
5923 lappend cmd >$fname &
5924 if {[catch {eval exec $cmd} err]} {
5925 error_popup "Error creating patch: $err"
5927 catch {destroy $patchtop}
5931 proc mkpatchcan {} {
5934 catch {destroy $patchtop}
5939 global rowmenuid mktagtop commitinfo
5943 catch {destroy $top}
5945 label $top.title -text "Create tag"
5946 grid $top.title - -pady 10
5947 label $top.id -text "ID:"
5948 entry $top.sha1 -width 40 -relief flat
5949 $top.sha1 insert 0 $rowmenuid
5950 $top.sha1 conf -state readonly
5951 grid $top.id $top.sha1 -sticky w
5952 entry $top.head -width 60 -relief flat
5953 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
5954 $top.head conf -state readonly
5955 grid x $top.head -sticky w
5956 label $top.tlab -text "Tag name:"
5957 entry $top.tag -width 60
5958 grid $top.tlab $top.tag -sticky w
5960 button $top.buts.gen -text "Create" -command mktaggo
5961 button $top.buts.can -text "Cancel" -command mktagcan
5962 grid $top.buts.gen $top.buts.can
5963 grid columnconfigure $top.buts 0 -weight 1 -uniform a
5964 grid columnconfigure $top.buts 1 -weight 1 -uniform a
5965 grid $top.buts - -pady 10 -sticky ew
5970 global mktagtop env tagids idtags
5972 set id [$mktagtop.sha1 get]
5973 set tag [$mktagtop.tag get]
5975 error_popup "No tag name specified"
5978 if {[info exists tagids($tag)]} {
5979 error_popup "Tag \"$tag\" already exists"
5984 set fname [file join $dir "refs/tags" $tag]
5985 set f [open $fname w]
5989 error_popup "Error creating tag: $err"
5993 set tagids($tag) $id
5994 lappend idtags($id) $tag
6001 proc redrawtags {id} {
6002 global canv linehtag commitrow idpos selectedline curview
6003 global mainfont canvxmax iddrawn
6005 if {![info exists commitrow($curview,$id)]} return
6006 if {![info exists iddrawn($id)]} return
6007 drawcommits $commitrow($curview,$id)
6008 $canv delete tag.$id
6009 set xt [eval drawtags $id $idpos($id)]
6010 $canv coords $linehtag($commitrow($curview,$id)) $xt [lindex $idpos($id) 2]
6011 set text [$canv itemcget $linehtag($commitrow($curview,$id)) -text]
6012 set xr [expr {$xt + [font measure $mainfont $text]}]
6013 if {$xr > $canvxmax} {
6017 if {[info exists selectedline]
6018 && $selectedline == $commitrow($curview,$id)} {
6019 selectline $selectedline 0
6026 catch {destroy $mktagtop}
6035 proc writecommit {} {
6036 global rowmenuid wrcomtop commitinfo wrcomcmd
6038 set top .writecommit
6040 catch {destroy $top}
6042 label $top.title -text "Write commit to file"
6043 grid $top.title - -pady 10
6044 label $top.id -text "ID:"
6045 entry $top.sha1 -width 40 -relief flat
6046 $top.sha1 insert 0 $rowmenuid
6047 $top.sha1 conf -state readonly
6048 grid $top.id $top.sha1 -sticky w
6049 entry $top.head -width 60 -relief flat
6050 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
6051 $top.head conf -state readonly
6052 grid x $top.head -sticky w
6053 label $top.clab -text "Command:"
6054 entry $top.cmd -width 60 -textvariable wrcomcmd
6055 grid $top.clab $top.cmd -sticky w -pady 10
6056 label $top.flab -text "Output file:"
6057 entry $top.fname -width 60
6058 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
6059 grid $top.flab $top.fname -sticky w
6061 button $top.buts.gen -text "Write" -command wrcomgo
6062 button $top.buts.can -text "Cancel" -command wrcomcan
6063 grid $top.buts.gen $top.buts.can
6064 grid columnconfigure $top.buts 0 -weight 1 -uniform a
6065 grid columnconfigure $top.buts 1 -weight 1 -uniform a
6066 grid $top.buts - -pady 10 -sticky ew
6073 set id [$wrcomtop.sha1 get]
6074 set cmd "echo $id | [$wrcomtop.cmd get]"
6075 set fname [$wrcomtop.fname get]
6076 if {[catch {exec sh -c $cmd >$fname &} err]} {
6077 error_popup "Error writing commit: $err"
6079 catch {destroy $wrcomtop}
6086 catch {destroy $wrcomtop}
6091 global rowmenuid mkbrtop
6094 catch {destroy $top}
6096 label $top.title -text "Create new branch"
6097 grid $top.title - -pady 10
6098 label $top.id -text "ID:"
6099 entry $top.sha1 -width 40 -relief flat
6100 $top.sha1 insert 0 $rowmenuid
6101 $top.sha1 conf -state readonly
6102 grid $top.id $top.sha1 -sticky w
6103 label $top.nlab -text "Name:"
6104 entry $top.name -width 40
6105 grid $top.nlab $top.name -sticky w
6107 button $top.buts.go -text "Create" -command [list mkbrgo $top]
6108 button $top.buts.can -text "Cancel" -command "catch {destroy $top}"
6109 grid $top.buts.go $top.buts.can
6110 grid columnconfigure $top.buts 0 -weight 1 -uniform a
6111 grid columnconfigure $top.buts 1 -weight 1 -uniform a
6112 grid $top.buts - -pady 10 -sticky ew
6117 global headids idheads
6119 set name [$top.name get]
6120 set id [$top.sha1 get]
6122 error_popup "Please specify a name for the new branch"
6125 catch {destroy $top}
6129 exec git branch $name $id
6134 set headids($name) $id
6135 lappend idheads($id) $name
6144 proc cherrypick {} {
6145 global rowmenuid curview commitrow
6148 set oldhead [exec git rev-parse HEAD]
6149 set dheads [descheads $rowmenuid]
6150 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
6151 set ok [confirm_popup "Commit [string range $rowmenuid 0 7] is already\
6152 included in branch $mainhead -- really re-apply it?"]
6157 # Unfortunately git-cherry-pick writes stuff to stderr even when
6158 # no error occurs, and exec takes that as an indication of error...
6159 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
6164 set newhead [exec git rev-parse HEAD]
6165 if {$newhead eq $oldhead} {
6167 error_popup "No changes committed"
6170 addnewchild $newhead $oldhead
6171 if {[info exists commitrow($curview,$oldhead)]} {
6172 insertrow $commitrow($curview,$oldhead) $newhead
6173 if {$mainhead ne {}} {
6174 movehead $newhead $mainhead
6175 movedhead $newhead $mainhead
6184 global mainheadid mainhead rowmenuid confirm_ok resettype
6187 set w ".confirmreset"
6190 wm title $w "Confirm reset"
6191 message $w.m -text \
6192 "Reset branch $mainhead to [string range $rowmenuid 0 7]?" \
6193 -justify center -aspect 1000
6194 pack $w.m -side top -fill x -padx 20 -pady 20
6195 frame $w.f -relief sunken -border 2
6196 message $w.f.rt -text "Reset type:" -aspect 1000
6197 grid $w.f.rt -sticky w
6199 radiobutton $w.f.soft -value soft -variable resettype -justify left \
6200 -text "Soft: Leave working tree and index untouched"
6201 grid $w.f.soft -sticky w
6202 radiobutton $w.f.mixed -value mixed -variable resettype -justify left \
6203 -text "Mixed: Leave working tree untouched, reset index"
6204 grid $w.f.mixed -sticky w
6205 radiobutton $w.f.hard -value hard -variable resettype -justify left \
6206 -text "Hard: Reset working tree and index\n(discard ALL local changes)"
6207 grid $w.f.hard -sticky w
6208 pack $w.f -side top -fill x
6209 button $w.ok -text OK -command "set confirm_ok 1; destroy $w"
6210 pack $w.ok -side left -fill x -padx 20 -pady 20
6211 button $w.cancel -text Cancel -command "destroy $w"
6212 pack $w.cancel -side right -fill x -padx 20 -pady 20
6213 bind $w <Visibility> "grab $w; focus $w"
6215 if {!$confirm_ok} return
6216 if {[catch {set fd [open \
6217 [list | sh -c "git reset --$resettype $rowmenuid 2>&1"] r]} err]} {
6221 set w ".resetprogress"
6222 filerun $fd [list readresetstat $fd $w]
6225 wm title $w "Reset progress"
6226 message $w.m -text "Reset in progress, please wait..." \
6227 -justify center -aspect 1000
6228 pack $w.m -side top -fill x -padx 20 -pady 5
6229 canvas $w.c -width 150 -height 20 -bg white
6230 $w.c create rect 0 0 0 20 -fill green -tags rect
6231 pack $w.c -side top -fill x -padx 20 -pady 5 -expand 1
6236 proc readresetstat {fd w} {
6237 global mainhead mainheadid showlocalchanges
6239 if {[gets $fd line] >= 0} {
6240 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
6241 set x [expr {($m * 150) / $n}]
6242 $w.c coords rect 0 0 $x 20
6248 if {[catch {close $fd} err]} {
6251 set oldhead $mainheadid
6252 set newhead [exec git rev-parse HEAD]
6253 if {$newhead ne $oldhead} {
6254 movehead $newhead $mainhead
6255 movedhead $newhead $mainhead
6256 set mainheadid $newhead
6260 if {$showlocalchanges} {
6266 # context menu for a head
6267 proc headmenu {x y id head} {
6268 global headmenuid headmenuhead headctxmenu mainhead
6271 set headmenuhead $head
6273 if {$head eq $mainhead} {
6276 $headctxmenu entryconfigure 0 -state $state
6277 $headctxmenu entryconfigure 1 -state $state
6278 tk_popup $headctxmenu $x $y
6282 global headmenuid headmenuhead mainhead headids
6283 global showlocalchanges mainheadid
6285 # check the tree is clean first??
6286 set oldmainhead $mainhead
6291 exec git checkout -q $headmenuhead
6297 set mainhead $headmenuhead
6298 set mainheadid $headmenuid
6299 if {[info exists headids($oldmainhead)]} {
6300 redrawtags $headids($oldmainhead)
6302 redrawtags $headmenuid
6304 if {$showlocalchanges} {
6310 global headmenuid headmenuhead mainhead
6313 set head $headmenuhead
6315 # this check shouldn't be needed any more...
6316 if {$head eq $mainhead} {
6317 error_popup "Cannot delete the currently checked-out branch"
6320 set dheads [descheads $id]
6321 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
6322 # the stuff on this branch isn't on any other branch
6323 if {![confirm_popup "The commits on branch $head aren't on any other\
6324 branch.\nReally delete branch $head?"]} return
6328 if {[catch {exec git branch -D $head} err]} {
6333 removehead $id $head
6334 removedhead $id $head
6341 # Display a list of tags and heads
6343 global showrefstop bgcolor fgcolor selectbgcolor mainfont
6344 global bglist fglist uifont reflistfilter reflist maincursor
6347 set showrefstop $top
6348 if {[winfo exists $top]} {
6354 wm title $top "Tags and heads: [file tail [pwd]]"
6355 text $top.list -background $bgcolor -foreground $fgcolor \
6356 -selectbackground $selectbgcolor -font $mainfont \
6357 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
6358 -width 30 -height 20 -cursor $maincursor \
6359 -spacing1 1 -spacing3 1 -state disabled
6360 $top.list tag configure highlight -background $selectbgcolor
6361 lappend bglist $top.list
6362 lappend fglist $top.list
6363 scrollbar $top.ysb -command "$top.list yview" -orient vertical
6364 scrollbar $top.xsb -command "$top.list xview" -orient horizontal
6365 grid $top.list $top.ysb -sticky nsew
6366 grid $top.xsb x -sticky ew
6368 label $top.f.l -text "Filter: " -font $uifont
6369 entry $top.f.e -width 20 -textvariable reflistfilter -font $uifont
6370 set reflistfilter "*"
6371 trace add variable reflistfilter write reflistfilter_change
6372 pack $top.f.e -side right -fill x -expand 1
6373 pack $top.f.l -side left
6374 grid $top.f - -sticky ew -pady 2
6375 button $top.close -command [list destroy $top] -text "Close" \
6378 grid columnconfigure $top 0 -weight 1
6379 grid rowconfigure $top 0 -weight 1
6380 bind $top.list <1> {break}
6381 bind $top.list <B1-Motion> {break}
6382 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
6387 proc sel_reflist {w x y} {
6388 global showrefstop reflist headids tagids otherrefids
6390 if {![winfo exists $showrefstop]} return
6391 set l [lindex [split [$w index "@$x,$y"] "."] 0]
6392 set ref [lindex $reflist [expr {$l-1}]]
6393 set n [lindex $ref 0]
6394 switch -- [lindex $ref 1] {
6395 "H" {selbyid $headids($n)}
6396 "T" {selbyid $tagids($n)}
6397 "o" {selbyid $otherrefids($n)}
6399 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
6402 proc unsel_reflist {} {
6405 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
6406 $showrefstop.list tag remove highlight 0.0 end
6409 proc reflistfilter_change {n1 n2 op} {
6410 global reflistfilter
6412 after cancel refill_reflist
6413 after 200 refill_reflist
6416 proc refill_reflist {} {
6417 global reflist reflistfilter showrefstop headids tagids otherrefids
6418 global commitrow curview commitinterest
6420 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
6422 foreach n [array names headids] {
6423 if {[string match $reflistfilter $n]} {
6424 if {[info exists commitrow($curview,$headids($n))]} {
6425 lappend refs [list $n H]
6427 set commitinterest($headids($n)) {run refill_reflist}
6431 foreach n [array names tagids] {
6432 if {[string match $reflistfilter $n]} {
6433 if {[info exists commitrow($curview,$tagids($n))]} {
6434 lappend refs [list $n T]
6436 set commitinterest($tagids($n)) {run refill_reflist}
6440 foreach n [array names otherrefids] {
6441 if {[string match $reflistfilter $n]} {
6442 if {[info exists commitrow($curview,$otherrefids($n))]} {
6443 lappend refs [list $n o]
6445 set commitinterest($otherrefids($n)) {run refill_reflist}
6449 set refs [lsort -index 0 $refs]
6450 if {$refs eq $reflist} return
6452 # Update the contents of $showrefstop.list according to the
6453 # differences between $reflist (old) and $refs (new)
6454 $showrefstop.list conf -state normal
6455 $showrefstop.list insert end "\n"
6458 while {$i < [llength $reflist] || $j < [llength $refs]} {
6459 if {$i < [llength $reflist]} {
6460 if {$j < [llength $refs]} {
6461 set cmp [string compare [lindex $reflist $i 0] \
6462 [lindex $refs $j 0]]
6464 set cmp [string compare [lindex $reflist $i 1] \
6465 [lindex $refs $j 1]]
6475 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
6483 set l [expr {$j + 1}]
6484 $showrefstop.list image create $l.0 -align baseline \
6485 -image reficon-[lindex $refs $j 1] -padx 2
6486 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
6492 # delete last newline
6493 $showrefstop.list delete end-2c end-1c
6494 $showrefstop.list conf -state disabled
6497 # Stuff for finding nearby tags
6498 proc getallcommits {} {
6499 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
6500 global idheads idtags idotherrefs allparents tagobjid
6502 if {![info exists allcommits]} {
6508 set allccache [file join [gitdir] "gitk.cache"]
6510 set f [open $allccache r]
6519 set cmd [list | git rev-list --parents]
6520 set allcupdate [expr {$seeds ne {}}]
6524 set refs [concat [array names idheads] [array names idtags] \
6525 [array names idotherrefs]]
6528 foreach name [array names tagobjid] {
6529 lappend tagobjs $tagobjid($name)
6531 foreach id [lsort -unique $refs] {
6532 if {![info exists allparents($id)] &&
6533 [lsearch -exact $tagobjs $id] < 0} {
6544 set fd [open [concat $cmd $ids] r]
6545 fconfigure $fd -blocking 0
6548 filerun $fd [list getallclines $fd]
6554 # Since most commits have 1 parent and 1 child, we group strings of
6555 # such commits into "arcs" joining branch/merge points (BMPs), which
6556 # are commits that either don't have 1 parent or don't have 1 child.
6558 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
6559 # arcout(id) - outgoing arcs for BMP
6560 # arcids(a) - list of IDs on arc including end but not start
6561 # arcstart(a) - BMP ID at start of arc
6562 # arcend(a) - BMP ID at end of arc
6563 # growing(a) - arc a is still growing
6564 # arctags(a) - IDs out of arcids (excluding end) that have tags
6565 # archeads(a) - IDs out of arcids (excluding end) that have heads
6566 # The start of an arc is at the descendent end, so "incoming" means
6567 # coming from descendents, and "outgoing" means going towards ancestors.
6569 proc getallclines {fd} {
6570 global allparents allchildren idtags idheads nextarc
6571 global arcnos arcids arctags arcout arcend arcstart archeads growing
6572 global seeds allcommits cachedarcs allcupdate
6575 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
6576 set id [lindex $line 0]
6577 if {[info exists allparents($id)]} {
6582 set olds [lrange $line 1 end]
6583 set allparents($id) $olds
6584 if {![info exists allchildren($id)]} {
6585 set allchildren($id) {}
6590 if {[llength $olds] == 1 && [llength $a] == 1} {
6591 lappend arcids($a) $id
6592 if {[info exists idtags($id)]} {
6593 lappend arctags($a) $id
6595 if {[info exists idheads($id)]} {
6596 lappend archeads($a) $id
6598 if {[info exists allparents($olds)]} {
6599 # seen parent already
6600 if {![info exists arcout($olds)]} {
6603 lappend arcids($a) $olds
6604 set arcend($a) $olds
6607 lappend allchildren($olds) $id
6608 lappend arcnos($olds) $a
6612 foreach a $arcnos($id) {
6613 lappend arcids($a) $id
6620 lappend allchildren($p) $id
6621 set a [incr nextarc]
6622 set arcstart($a) $id
6629 if {[info exists allparents($p)]} {
6630 # seen it already, may need to make a new branch
6631 if {![info exists arcout($p)]} {
6634 lappend arcids($a) $p
6638 lappend arcnos($p) $a
6643 global cached_dheads cached_dtags cached_atags
6644 catch {unset cached_dheads}
6645 catch {unset cached_dtags}
6646 catch {unset cached_atags}
6649 return [expr {$nid >= 1000? 2: 1}]
6653 fconfigure $fd -blocking 1
6656 # got an error reading the list of commits
6657 # if we were updating, try rereading the whole thing again
6663 error_popup "Error reading commit topology information;\
6664 branch and preceding/following tag information\
6665 will be incomplete.\n($err)"
6668 if {[incr allcommits -1] == 0} {
6678 proc recalcarc {a} {
6679 global arctags archeads arcids idtags idheads
6683 foreach id [lrange $arcids($a) 0 end-1] {
6684 if {[info exists idtags($id)]} {
6687 if {[info exists idheads($id)]} {
6692 set archeads($a) $ah
6696 global arcnos arcids nextarc arctags archeads idtags idheads
6697 global arcstart arcend arcout allparents growing
6700 if {[llength $a] != 1} {
6701 puts "oops splitarc called but [llength $a] arcs already"
6705 set i [lsearch -exact $arcids($a) $p]
6707 puts "oops splitarc $p not in arc $a"
6710 set na [incr nextarc]
6711 if {[info exists arcend($a)]} {
6712 set arcend($na) $arcend($a)
6714 set l [lindex $allparents([lindex $arcids($a) end]) 0]
6715 set j [lsearch -exact $arcnos($l) $a]
6716 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
6718 set tail [lrange $arcids($a) [expr {$i+1}] end]
6719 set arcids($a) [lrange $arcids($a) 0 $i]
6721 set arcstart($na) $p
6723 set arcids($na) $tail
6724 if {[info exists growing($a)]} {
6730 if {[llength $arcnos($id)] == 1} {
6733 set j [lsearch -exact $arcnos($id) $a]
6734 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
6738 # reconstruct tags and heads lists
6739 if {$arctags($a) ne {} || $archeads($a) ne {}} {
6744 set archeads($na) {}
6748 # Update things for a new commit added that is a child of one
6749 # existing commit. Used when cherry-picking.
6750 proc addnewchild {id p} {
6751 global allparents allchildren idtags nextarc
6752 global arcnos arcids arctags arcout arcend arcstart archeads growing
6753 global seeds allcommits
6755 if {![info exists allcommits]} return
6756 set allparents($id) [list $p]
6757 set allchildren($id) {}
6760 lappend allchildren($p) $id
6761 set a [incr nextarc]
6762 set arcstart($a) $id
6765 set arcids($a) [list $p]
6767 if {![info exists arcout($p)]} {
6770 lappend arcnos($p) $a
6771 set arcout($id) [list $a]
6774 # This implements a cache for the topology information.
6775 # The cache saves, for each arc, the start and end of the arc,
6776 # the ids on the arc, and the outgoing arcs from the end.
6777 proc readcache {f} {
6778 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
6779 global idtags idheads allparents cachedarcs possible_seeds seeds growing
6784 if {$lim - $a > 500} {
6785 set lim [expr {$a + 500}]
6789 # finish reading the cache and setting up arctags, etc.
6791 if {$line ne "1"} {error "bad final version"}
6793 foreach id [array names idtags] {
6794 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
6795 [llength $allparents($id)] == 1} {
6796 set a [lindex $arcnos($id) 0]
6797 if {$arctags($a) eq {}} {
6802 foreach id [array names idheads] {
6803 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
6804 [llength $allparents($id)] == 1} {
6805 set a [lindex $arcnos($id) 0]
6806 if {$archeads($a) eq {}} {
6811 foreach id [lsort -unique $possible_seeds] {
6812 if {$arcnos($id) eq {}} {
6818 while {[incr a] <= $lim} {
6820 if {[llength $line] != 3} {error "bad line"}
6821 set s [lindex $line 0]
6823 lappend arcout($s) $a
6824 if {![info exists arcnos($s)]} {
6825 lappend possible_seeds $s
6828 set e [lindex $line 1]
6833 if {![info exists arcout($e)]} {
6837 set arcids($a) [lindex $line 2]
6838 foreach id $arcids($a) {
6839 lappend allparents($s) $id
6841 lappend arcnos($id) $a
6843 if {![info exists allparents($s)]} {
6844 set allparents($s) {}
6849 set nextarc [expr {$a - 1}]
6862 global nextarc cachedarcs possible_seeds
6866 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
6867 # make sure it's an integer
6868 set cachedarcs [expr {int([lindex $line 1])}]
6869 if {$cachedarcs < 0} {error "bad number of arcs"}
6871 set possible_seeds {}
6879 proc dropcache {err} {
6880 global allcwait nextarc cachedarcs seeds
6882 #puts "dropping cache ($err)"
6883 foreach v {arcnos arcout arcids arcstart arcend growing \
6884 arctags archeads allparents allchildren} {
6895 proc writecache {f} {
6896 global cachearc cachedarcs allccache
6897 global arcstart arcend arcnos arcids arcout
6901 if {$lim - $a > 1000} {
6902 set lim [expr {$a + 1000}]
6905 while {[incr a] <= $lim} {
6906 if {[info exists arcend($a)]} {
6907 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
6909 puts $f [list $arcstart($a) {} $arcids($a)]
6914 catch {file delete $allccache}
6915 #puts "writing cache failed ($err)"
6918 set cachearc [expr {$a - 1}]
6919 if {$a > $cachedarcs} {
6928 global nextarc cachedarcs cachearc allccache
6930 if {$nextarc == $cachedarcs} return
6932 set cachedarcs $nextarc
6934 set f [open $allccache w]
6935 puts $f [list 1 $cachedarcs]
6940 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
6941 # or 0 if neither is true.
6942 proc anc_or_desc {a b} {
6943 global arcout arcstart arcend arcnos cached_isanc
6945 if {$arcnos($a) eq $arcnos($b)} {
6946 # Both are on the same arc(s); either both are the same BMP,
6947 # or if one is not a BMP, the other is also not a BMP or is
6948 # the BMP at end of the arc (and it only has 1 incoming arc).
6949 # Or both can be BMPs with no incoming arcs.
6950 if {$a eq $b || $arcnos($a) eq {}} {
6953 # assert {[llength $arcnos($a)] == 1}
6954 set arc [lindex $arcnos($a) 0]
6955 set i [lsearch -exact $arcids($arc) $a]
6956 set j [lsearch -exact $arcids($arc) $b]
6957 if {$i < 0 || $i > $j} {
6964 if {![info exists arcout($a)]} {
6965 set arc [lindex $arcnos($a) 0]
6966 if {[info exists arcend($arc)]} {
6967 set aend $arcend($arc)
6971 set a $arcstart($arc)
6975 if {![info exists arcout($b)]} {
6976 set arc [lindex $arcnos($b) 0]
6977 if {[info exists arcend($arc)]} {
6978 set bend $arcend($arc)
6982 set b $arcstart($arc)
6992 if {[info exists cached_isanc($a,$bend)]} {
6993 if {$cached_isanc($a,$bend)} {
6997 if {[info exists cached_isanc($b,$aend)]} {
6998 if {$cached_isanc($b,$aend)} {
7001 if {[info exists cached_isanc($a,$bend)]} {
7006 set todo [list $a $b]
7009 for {set i 0} {$i < [llength $todo]} {incr i} {
7010 set x [lindex $todo $i]
7011 if {$anc($x) eq {}} {
7014 foreach arc $arcnos($x) {
7015 set xd $arcstart($arc)
7017 set cached_isanc($a,$bend) 1
7018 set cached_isanc($b,$aend) 0
7020 } elseif {$xd eq $aend} {
7021 set cached_isanc($b,$aend) 1
7022 set cached_isanc($a,$bend) 0
7025 if {![info exists anc($xd)]} {
7026 set anc($xd) $anc($x)
7028 } elseif {$anc($xd) ne $anc($x)} {
7033 set cached_isanc($a,$bend) 0
7034 set cached_isanc($b,$aend) 0
7038 # This identifies whether $desc has an ancestor that is
7039 # a growing tip of the graph and which is not an ancestor of $anc
7040 # and returns 0 if so and 1 if not.
7041 # If we subsequently discover a tag on such a growing tip, and that
7042 # turns out to be a descendent of $anc (which it could, since we
7043 # don't necessarily see children before parents), then $desc
7044 # isn't a good choice to display as a descendent tag of
7045 # $anc (since it is the descendent of another tag which is
7046 # a descendent of $anc). Similarly, $anc isn't a good choice to
7047 # display as a ancestor tag of $desc.
7049 proc is_certain {desc anc} {
7050 global arcnos arcout arcstart arcend growing problems
7053 if {[llength $arcnos($anc)] == 1} {
7054 # tags on the same arc are certain
7055 if {$arcnos($desc) eq $arcnos($anc)} {
7058 if {![info exists arcout($anc)]} {
7059 # if $anc is partway along an arc, use the start of the arc instead
7060 set a [lindex $arcnos($anc) 0]
7061 set anc $arcstart($a)
7064 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
7067 set a [lindex $arcnos($desc) 0]
7073 set anclist [list $x]
7077 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
7078 set x [lindex $anclist $i]
7083 foreach a $arcout($x) {
7084 if {[info exists growing($a)]} {
7085 if {![info exists growanc($x)] && $dl($x)} {
7091 if {[info exists dl($y)]} {
7095 if {![info exists done($y)]} {
7098 if {[info exists growanc($x)]} {
7102 for {set k 0} {$k < [llength $xl]} {incr k} {
7103 set z [lindex $xl $k]
7104 foreach c $arcout($z) {
7105 if {[info exists arcend($c)]} {
7107 if {[info exists dl($v)] && $dl($v)} {
7109 if {![info exists done($v)]} {
7112 if {[info exists growanc($v)]} {
7122 } elseif {$y eq $anc || !$dl($x)} {
7133 foreach x [array names growanc] {
7142 proc validate_arctags {a} {
7143 global arctags idtags
7147 foreach id $arctags($a) {
7149 if {![info exists idtags($id)]} {
7150 set na [lreplace $na $i $i]
7157 proc validate_archeads {a} {
7158 global archeads idheads
7161 set na $archeads($a)
7162 foreach id $archeads($a) {
7164 if {![info exists idheads($id)]} {
7165 set na [lreplace $na $i $i]
7169 set archeads($a) $na
7172 # Return the list of IDs that have tags that are descendents of id,
7173 # ignoring IDs that are descendents of IDs already reported.
7174 proc desctags {id} {
7175 global arcnos arcstart arcids arctags idtags allparents
7176 global growing cached_dtags
7178 if {![info exists allparents($id)]} {
7181 set t1 [clock clicks -milliseconds]
7183 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
7184 # part-way along an arc; check that arc first
7185 set a [lindex $arcnos($id) 0]
7186 if {$arctags($a) ne {}} {
7188 set i [lsearch -exact $arcids($a) $id]
7190 foreach t $arctags($a) {
7191 set j [lsearch -exact $arcids($a) $t]
7199 set id $arcstart($a)
7200 if {[info exists idtags($id)]} {
7204 if {[info exists cached_dtags($id)]} {
7205 return $cached_dtags($id)
7212 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
7213 set id [lindex $todo $i]
7215 set ta [info exists hastaggedancestor($id)]
7219 # ignore tags on starting node
7220 if {!$ta && $i > 0} {
7221 if {[info exists idtags($id)]} {
7224 } elseif {[info exists cached_dtags($id)]} {
7225 set tagloc($id) $cached_dtags($id)
7229 foreach a $arcnos($id) {
7231 if {!$ta && $arctags($a) ne {}} {
7233 if {$arctags($a) ne {}} {
7234 lappend tagloc($id) [lindex $arctags($a) end]
7237 if {$ta || $arctags($a) ne {}} {
7238 set tomark [list $d]
7239 for {set j 0} {$j < [llength $tomark]} {incr j} {
7240 set dd [lindex $tomark $j]
7241 if {![info exists hastaggedancestor($dd)]} {
7242 if {[info exists done($dd)]} {
7243 foreach b $arcnos($dd) {
7244 lappend tomark $arcstart($b)
7246 if {[info exists tagloc($dd)]} {
7249 } elseif {[info exists queued($dd)]} {
7252 set hastaggedancestor($dd) 1
7256 if {![info exists queued($d)]} {
7259 if {![info exists hastaggedancestor($d)]} {
7266 foreach id [array names tagloc] {
7267 if {![info exists hastaggedancestor($id)]} {
7268 foreach t $tagloc($id) {
7269 if {[lsearch -exact $tags $t] < 0} {
7275 set t2 [clock clicks -milliseconds]
7278 # remove tags that are descendents of other tags
7279 for {set i 0} {$i < [llength $tags]} {incr i} {
7280 set a [lindex $tags $i]
7281 for {set j 0} {$j < $i} {incr j} {
7282 set b [lindex $tags $j]
7283 set r [anc_or_desc $a $b]
7285 set tags [lreplace $tags $j $j]
7288 } elseif {$r == -1} {
7289 set tags [lreplace $tags $i $i]
7296 if {[array names growing] ne {}} {
7297 # graph isn't finished, need to check if any tag could get
7298 # eclipsed by another tag coming later. Simply ignore any
7299 # tags that could later get eclipsed.
7302 if {[is_certain $t $origid]} {
7306 if {$tags eq $ctags} {
7307 set cached_dtags($origid) $tags
7312 set cached_dtags($origid) $tags
7314 set t3 [clock clicks -milliseconds]
7315 if {0 && $t3 - $t1 >= 100} {
7316 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
7317 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
7323 global arcnos arcids arcout arcend arctags idtags allparents
7324 global growing cached_atags
7326 if {![info exists allparents($id)]} {
7329 set t1 [clock clicks -milliseconds]
7331 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
7332 # part-way along an arc; check that arc first
7333 set a [lindex $arcnos($id) 0]
7334 if {$arctags($a) ne {}} {
7336 set i [lsearch -exact $arcids($a) $id]
7337 foreach t $arctags($a) {
7338 set j [lsearch -exact $arcids($a) $t]
7344 if {![info exists arcend($a)]} {
7348 if {[info exists idtags($id)]} {
7352 if {[info exists cached_atags($id)]} {
7353 return $cached_atags($id)
7361 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
7362 set id [lindex $todo $i]
7364 set td [info exists hastaggeddescendent($id)]
7368 # ignore tags on starting node
7369 if {!$td && $i > 0} {
7370 if {[info exists idtags($id)]} {
7373 } elseif {[info exists cached_atags($id)]} {
7374 set tagloc($id) $cached_atags($id)
7378 foreach a $arcout($id) {
7379 if {!$td && $arctags($a) ne {}} {
7381 if {$arctags($a) ne {}} {
7382 lappend tagloc($id) [lindex $arctags($a) 0]
7385 if {![info exists arcend($a)]} continue
7387 if {$td || $arctags($a) ne {}} {
7388 set tomark [list $d]
7389 for {set j 0} {$j < [llength $tomark]} {incr j} {
7390 set dd [lindex $tomark $j]
7391 if {![info exists hastaggeddescendent($dd)]} {
7392 if {[info exists done($dd)]} {
7393 foreach b $arcout($dd) {
7394 if {[info exists arcend($b)]} {
7395 lappend tomark $arcend($b)
7398 if {[info exists tagloc($dd)]} {
7401 } elseif {[info exists queued($dd)]} {
7404 set hastaggeddescendent($dd) 1
7408 if {![info exists queued($d)]} {
7411 if {![info exists hastaggeddescendent($d)]} {
7417 set t2 [clock clicks -milliseconds]
7420 foreach id [array names tagloc] {
7421 if {![info exists hastaggeddescendent($id)]} {
7422 foreach t $tagloc($id) {
7423 if {[lsearch -exact $tags $t] < 0} {
7430 # remove tags that are ancestors of other tags
7431 for {set i 0} {$i < [llength $tags]} {incr i} {
7432 set a [lindex $tags $i]
7433 for {set j 0} {$j < $i} {incr j} {
7434 set b [lindex $tags $j]
7435 set r [anc_or_desc $a $b]
7437 set tags [lreplace $tags $j $j]
7440 } elseif {$r == 1} {
7441 set tags [lreplace $tags $i $i]
7448 if {[array names growing] ne {}} {
7449 # graph isn't finished, need to check if any tag could get
7450 # eclipsed by another tag coming later. Simply ignore any
7451 # tags that could later get eclipsed.
7454 if {[is_certain $origid $t]} {
7458 if {$tags eq $ctags} {
7459 set cached_atags($origid) $tags
7464 set cached_atags($origid) $tags
7466 set t3 [clock clicks -milliseconds]
7467 if {0 && $t3 - $t1 >= 100} {
7468 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
7469 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
7474 # Return the list of IDs that have heads that are descendents of id,
7475 # including id itself if it has a head.
7476 proc descheads {id} {
7477 global arcnos arcstart arcids archeads idheads cached_dheads
7480 if {![info exists allparents($id)]} {
7484 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
7485 # part-way along an arc; check it first
7486 set a [lindex $arcnos($id) 0]
7487 if {$archeads($a) ne {}} {
7488 validate_archeads $a
7489 set i [lsearch -exact $arcids($a) $id]
7490 foreach t $archeads($a) {
7491 set j [lsearch -exact $arcids($a) $t]
7496 set id $arcstart($a)
7502 for {set i 0} {$i < [llength $todo]} {incr i} {
7503 set id [lindex $todo $i]
7504 if {[info exists cached_dheads($id)]} {
7505 set ret [concat $ret $cached_dheads($id)]
7507 if {[info exists idheads($id)]} {
7510 foreach a $arcnos($id) {
7511 if {$archeads($a) ne {}} {
7512 validate_archeads $a
7513 if {$archeads($a) ne {}} {
7514 set ret [concat $ret $archeads($a)]
7518 if {![info exists seen($d)]} {
7525 set ret [lsort -unique $ret]
7526 set cached_dheads($origid) $ret
7527 return [concat $ret $aret]
7530 proc addedtag {id} {
7531 global arcnos arcout cached_dtags cached_atags
7533 if {![info exists arcnos($id)]} return
7534 if {![info exists arcout($id)]} {
7535 recalcarc [lindex $arcnos($id) 0]
7537 catch {unset cached_dtags}
7538 catch {unset cached_atags}
7541 proc addedhead {hid head} {
7542 global arcnos arcout cached_dheads
7544 if {![info exists arcnos($hid)]} return
7545 if {![info exists arcout($hid)]} {
7546 recalcarc [lindex $arcnos($hid) 0]
7548 catch {unset cached_dheads}
7551 proc removedhead {hid head} {
7552 global cached_dheads
7554 catch {unset cached_dheads}
7557 proc movedhead {hid head} {
7558 global arcnos arcout cached_dheads
7560 if {![info exists arcnos($hid)]} return
7561 if {![info exists arcout($hid)]} {
7562 recalcarc [lindex $arcnos($hid) 0]
7564 catch {unset cached_dheads}
7567 proc changedrefs {} {
7568 global cached_dheads cached_dtags cached_atags
7569 global arctags archeads arcnos arcout idheads idtags
7571 foreach id [concat [array names idheads] [array names idtags]] {
7572 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
7573 set a [lindex $arcnos($id) 0]
7574 if {![info exists donearc($a)]} {
7580 catch {unset cached_dtags}
7581 catch {unset cached_atags}
7582 catch {unset cached_dheads}
7585 proc rereadrefs {} {
7586 global idtags idheads idotherrefs mainhead
7588 set refids [concat [array names idtags] \
7589 [array names idheads] [array names idotherrefs]]
7590 foreach id $refids {
7591 if {![info exists ref($id)]} {
7592 set ref($id) [listrefs $id]
7595 set oldmainhead $mainhead
7598 set refids [lsort -unique [concat $refids [array names idtags] \
7599 [array names idheads] [array names idotherrefs]]]
7600 foreach id $refids {
7601 set v [listrefs $id]
7602 if {![info exists ref($id)] || $ref($id) != $v ||
7603 ($id eq $oldmainhead && $id ne $mainhead) ||
7604 ($id eq $mainhead && $id ne $oldmainhead)} {
7611 proc listrefs {id} {
7612 global idtags idheads idotherrefs
7615 if {[info exists idtags($id)]} {
7619 if {[info exists idheads($id)]} {
7623 if {[info exists idotherrefs($id)]} {
7624 set z $idotherrefs($id)
7626 return [list $x $y $z]
7629 proc showtag {tag isnew} {
7630 global ctext tagcontents tagids linknum tagobjid
7633 addtohistory [list showtag $tag 0]
7635 $ctext conf -state normal
7638 if {![info exists tagcontents($tag)]} {
7640 set tagcontents($tag) [exec git cat-file tag $tagobjid($tag)]
7643 if {[info exists tagcontents($tag)]} {
7644 set text $tagcontents($tag)
7646 set text "Tag: $tag\nId: $tagids($tag)"
7648 appendwithlinks $text {}
7649 $ctext conf -state disabled
7661 global maxwidth maxgraphpct diffopts
7662 global oldprefs prefstop showneartags showlocalchanges
7663 global bgcolor fgcolor ctext diffcolors selectbgcolor
7664 global uifont tabstop
7668 if {[winfo exists $top]} {
7672 foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
7673 set oldprefs($v) [set $v]
7676 wm title $top "Gitk preferences"
7677 label $top.ldisp -text "Commit list display options"
7678 $top.ldisp configure -font $uifont
7679 grid $top.ldisp - -sticky w -pady 10
7680 label $top.spacer -text " "
7681 label $top.maxwidthl -text "Maximum graph width (lines)" \
7683 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
7684 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
7685 label $top.maxpctl -text "Maximum graph width (% of pane)" \
7687 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
7688 grid x $top.maxpctl $top.maxpct -sticky w
7689 frame $top.showlocal
7690 label $top.showlocal.l -text "Show local changes" -font optionfont
7691 checkbutton $top.showlocal.b -variable showlocalchanges
7692 pack $top.showlocal.b $top.showlocal.l -side left
7693 grid x $top.showlocal -sticky w
7695 label $top.ddisp -text "Diff display options"
7696 $top.ddisp configure -font $uifont
7697 grid $top.ddisp - -sticky w -pady 10
7698 label $top.diffoptl -text "Options for diff program" \
7700 entry $top.diffopt -width 20 -textvariable diffopts
7701 grid x $top.diffoptl $top.diffopt -sticky w
7703 label $top.ntag.l -text "Display nearby tags" -font optionfont
7704 checkbutton $top.ntag.b -variable showneartags
7705 pack $top.ntag.b $top.ntag.l -side left
7706 grid x $top.ntag -sticky w
7707 label $top.tabstopl -text "tabstop" -font optionfont
7708 spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
7709 grid x $top.tabstopl $top.tabstop -sticky w
7711 label $top.cdisp -text "Colors: press to choose"
7712 $top.cdisp configure -font $uifont
7713 grid $top.cdisp - -sticky w -pady 10
7714 label $top.bg -padx 40 -relief sunk -background $bgcolor
7715 button $top.bgbut -text "Background" -font optionfont \
7716 -command [list choosecolor bgcolor 0 $top.bg background setbg]
7717 grid x $top.bgbut $top.bg -sticky w
7718 label $top.fg -padx 40 -relief sunk -background $fgcolor
7719 button $top.fgbut -text "Foreground" -font optionfont \
7720 -command [list choosecolor fgcolor 0 $top.fg foreground setfg]
7721 grid x $top.fgbut $top.fg -sticky w
7722 label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
7723 button $top.diffoldbut -text "Diff: old lines" -font optionfont \
7724 -command [list choosecolor diffcolors 0 $top.diffold "diff old lines" \
7725 [list $ctext tag conf d0 -foreground]]
7726 grid x $top.diffoldbut $top.diffold -sticky w
7727 label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
7728 button $top.diffnewbut -text "Diff: new lines" -font optionfont \
7729 -command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \
7730 [list $ctext tag conf d1 -foreground]]
7731 grid x $top.diffnewbut $top.diffnew -sticky w
7732 label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
7733 button $top.hunksepbut -text "Diff: hunk header" -font optionfont \
7734 -command [list choosecolor diffcolors 2 $top.hunksep \
7735 "diff hunk header" \
7736 [list $ctext tag conf hunksep -foreground]]
7737 grid x $top.hunksepbut $top.hunksep -sticky w
7738 label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor
7739 button $top.selbgbut -text "Select bg" -font optionfont \
7740 -command [list choosecolor selectbgcolor 0 $top.selbgsep background setselbg]
7741 grid x $top.selbgbut $top.selbgsep -sticky w
7744 button $top.buts.ok -text "OK" -command prefsok -default active
7745 $top.buts.ok configure -font $uifont
7746 button $top.buts.can -text "Cancel" -command prefscan -default normal
7747 $top.buts.can configure -font $uifont
7748 grid $top.buts.ok $top.buts.can
7749 grid columnconfigure $top.buts 0 -weight 1 -uniform a
7750 grid columnconfigure $top.buts 1 -weight 1 -uniform a
7751 grid $top.buts - - -pady 10 -sticky ew
7752 bind $top <Visibility> "focus $top.buts.ok"
7755 proc choosecolor {v vi w x cmd} {
7758 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
7759 -title "Gitk: choose color for $x"]
7760 if {$c eq {}} return
7761 $w conf -background $c
7767 global bglist cflist
7769 $w configure -selectbackground $c
7771 $cflist tag configure highlight \
7772 -background [$cflist cget -selectbackground]
7773 allcanvs itemconf secsel -fill $c
7780 $w conf -background $c
7788 $w conf -foreground $c
7790 allcanvs itemconf text -fill $c
7791 $canv itemconf circle -outline $c
7795 global maxwidth maxgraphpct diffopts
7796 global oldprefs prefstop showneartags showlocalchanges
7798 foreach v {maxwidth maxgraphpct diffopts showneartags showlocalchanges} {
7799 set $v $oldprefs($v)
7801 catch {destroy $prefstop}
7806 global maxwidth maxgraphpct
7807 global oldprefs prefstop showneartags showlocalchanges
7808 global charspc ctext tabstop
7810 catch {destroy $prefstop}
7812 $ctext configure -tabs "[expr {$tabstop * $charspc}]"
7813 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
7814 if {$showlocalchanges} {
7820 if {$maxwidth != $oldprefs(maxwidth)
7821 || $maxgraphpct != $oldprefs(maxgraphpct)} {
7823 } elseif {$showneartags != $oldprefs(showneartags)} {
7828 proc formatdate {d} {
7829 global datetimeformat
7831 set d [clock format $d -format $datetimeformat]
7836 # This list of encoding names and aliases is distilled from
7837 # http://www.iana.org/assignments/character-sets.
7838 # Not all of them are supported by Tcl.
7839 set encoding_aliases {
7840 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
7841 ISO646-US US-ASCII us IBM367 cp367 csASCII }
7842 { ISO-10646-UTF-1 csISO10646UTF1 }
7843 { ISO_646.basic:1983 ref csISO646basic1983 }
7844 { INVARIANT csINVARIANT }
7845 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
7846 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
7847 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
7848 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
7849 { NATS-DANO iso-ir-9-1 csNATSDANO }
7850 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
7851 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
7852 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
7853 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
7854 { ISO-2022-KR csISO2022KR }
7856 { ISO-2022-JP csISO2022JP }
7857 { ISO-2022-JP-2 csISO2022JP2 }
7858 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
7860 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
7861 { IT iso-ir-15 ISO646-IT csISO15Italian }
7862 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
7863 { ES iso-ir-17 ISO646-ES csISO17Spanish }
7864 { greek7-old iso-ir-18 csISO18Greek7Old }
7865 { latin-greek iso-ir-19 csISO19LatinGreek }
7866 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
7867 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
7868 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
7869 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
7870 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
7871 { BS_viewdata iso-ir-47 csISO47BSViewdata }
7872 { INIS iso-ir-49 csISO49INIS }
7873 { INIS-8 iso-ir-50 csISO50INIS8 }
7874 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
7875 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
7876 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
7877 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
7878 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
7879 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
7881 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
7882 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
7883 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
7884 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
7885 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
7886 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
7887 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
7888 { greek7 iso-ir-88 csISO88Greek7 }
7889 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
7890 { iso-ir-90 csISO90 }
7891 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
7892 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
7893 csISO92JISC62991984b }
7894 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
7895 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
7896 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
7897 csISO95JIS62291984handadd }
7898 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
7899 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
7900 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
7901 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
7903 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
7904 { T.61-7bit iso-ir-102 csISO102T617bit }
7905 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
7906 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
7907 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
7908 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
7909 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
7910 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
7911 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
7912 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
7913 arabic csISOLatinArabic }
7914 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
7915 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
7916 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
7917 greek greek8 csISOLatinGreek }
7918 { T.101-G2 iso-ir-128 csISO128T101G2 }
7919 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
7921 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
7922 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
7923 { CSN_369103 iso-ir-139 csISO139CSN369103 }
7924 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
7925 { ISO_6937-2-add iso-ir-142 csISOTextComm }
7926 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
7927 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
7928 csISOLatinCyrillic }
7929 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
7930 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
7931 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
7932 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
7933 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
7934 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
7935 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
7936 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
7937 { ISO_10367-box iso-ir-155 csISO10367Box }
7938 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
7939 { latin-lap lap iso-ir-158 csISO158Lap }
7940 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
7941 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
7944 { JIS_X0201 X0201 csHalfWidthKatakana }
7945 { KSC5636 ISO646-KR csKSC5636 }
7946 { ISO-10646-UCS-2 csUnicode }
7947 { ISO-10646-UCS-4 csUCS4 }
7948 { DEC-MCS dec csDECMCS }
7949 { hp-roman8 roman8 r8 csHPRoman8 }
7950 { macintosh mac csMacintosh }
7951 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
7953 { IBM038 EBCDIC-INT cp038 csIBM038 }
7954 { IBM273 CP273 csIBM273 }
7955 { IBM274 EBCDIC-BE CP274 csIBM274 }
7956 { IBM275 EBCDIC-BR cp275 csIBM275 }
7957 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
7958 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
7959 { IBM280 CP280 ebcdic-cp-it csIBM280 }
7960 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
7961 { IBM284 CP284 ebcdic-cp-es csIBM284 }
7962 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
7963 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
7964 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
7965 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
7966 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
7967 { IBM424 cp424 ebcdic-cp-he csIBM424 }
7968 { IBM437 cp437 437 csPC8CodePage437 }
7969 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
7970 { IBM775 cp775 csPC775Baltic }
7971 { IBM850 cp850 850 csPC850Multilingual }
7972 { IBM851 cp851 851 csIBM851 }
7973 { IBM852 cp852 852 csPCp852 }
7974 { IBM855 cp855 855 csIBM855 }
7975 { IBM857 cp857 857 csIBM857 }
7976 { IBM860 cp860 860 csIBM860 }
7977 { IBM861 cp861 861 cp-is csIBM861 }
7978 { IBM862 cp862 862 csPC862LatinHebrew }
7979 { IBM863 cp863 863 csIBM863 }
7980 { IBM864 cp864 csIBM864 }
7981 { IBM865 cp865 865 csIBM865 }
7982 { IBM866 cp866 866 csIBM866 }
7983 { IBM868 CP868 cp-ar csIBM868 }
7984 { IBM869 cp869 869 cp-gr csIBM869 }
7985 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
7986 { IBM871 CP871 ebcdic-cp-is csIBM871 }
7987 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
7988 { IBM891 cp891 csIBM891 }
7989 { IBM903 cp903 csIBM903 }
7990 { IBM904 cp904 904 csIBBM904 }
7991 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
7992 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
7993 { IBM1026 CP1026 csIBM1026 }
7994 { EBCDIC-AT-DE csIBMEBCDICATDE }
7995 { EBCDIC-AT-DE-A csEBCDICATDEA }
7996 { EBCDIC-CA-FR csEBCDICCAFR }
7997 { EBCDIC-DK-NO csEBCDICDKNO }
7998 { EBCDIC-DK-NO-A csEBCDICDKNOA }
7999 { EBCDIC-FI-SE csEBCDICFISE }
8000 { EBCDIC-FI-SE-A csEBCDICFISEA }
8001 { EBCDIC-FR csEBCDICFR }
8002 { EBCDIC-IT csEBCDICIT }
8003 { EBCDIC-PT csEBCDICPT }
8004 { EBCDIC-ES csEBCDICES }
8005 { EBCDIC-ES-A csEBCDICESA }
8006 { EBCDIC-ES-S csEBCDICESS }
8007 { EBCDIC-UK csEBCDICUK }
8008 { EBCDIC-US csEBCDICUS }
8009 { UNKNOWN-8BIT csUnknown8BiT }
8010 { MNEMONIC csMnemonic }
8015 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
8016 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
8017 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
8018 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
8019 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
8020 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
8021 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
8022 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
8023 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
8024 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
8025 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
8026 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
8027 { IBM1047 IBM-1047 }
8028 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
8029 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
8030 { UNICODE-1-1 csUnicode11 }
8033 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
8034 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
8036 { ISO-8859-15 ISO_8859-15 Latin-9 }
8037 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
8038 { GBK CP936 MS936 windows-936 }
8039 { JIS_Encoding csJISEncoding }
8040 { Shift_JIS MS_Kanji csShiftJIS }
8041 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
8043 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
8044 { ISO-10646-UCS-Basic csUnicodeASCII }
8045 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
8046 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
8047 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
8048 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
8049 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
8050 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
8051 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
8052 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
8053 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
8054 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
8055 { Adobe-Standard-Encoding csAdobeStandardEncoding }
8056 { Ventura-US csVenturaUS }
8057 { Ventura-International csVenturaInternational }
8058 { PC8-Danish-Norwegian csPC8DanishNorwegian }
8059 { PC8-Turkish csPC8Turkish }
8060 { IBM-Symbols csIBMSymbols }
8061 { IBM-Thai csIBMThai }
8062 { HP-Legal csHPLegal }
8063 { HP-Pi-font csHPPiFont }
8064 { HP-Math8 csHPMath8 }
8065 { Adobe-Symbol-Encoding csHPPSMath }
8066 { HP-DeskTop csHPDesktop }
8067 { Ventura-Math csVenturaMath }
8068 { Microsoft-Publishing csMicrosoftPublishing }
8069 { Windows-31J csWindows31J }
8074 proc tcl_encoding {enc} {
8075 global encoding_aliases
8076 set names [encoding names]
8077 set lcnames [string tolower $names]
8078 set enc [string tolower $enc]
8079 set i [lsearch -exact $lcnames $enc]
8081 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
8082 if {[regsub {^iso[-_]} $enc iso encx]} {
8083 set i [lsearch -exact $lcnames $encx]
8087 foreach l $encoding_aliases {
8088 set ll [string tolower $l]
8089 if {[lsearch -exact $ll $enc] < 0} continue
8090 # look through the aliases for one that tcl knows about
8092 set i [lsearch -exact $lcnames $e]
8094 if {[regsub {^iso[-_]} $e iso ex]} {
8095 set i [lsearch -exact $lcnames $ex]
8104 return [lindex $names $i]
8111 set diffopts "-U 5 -p"
8112 set wrcomcmd "git diff-tree --stdin -p --pretty"
8116 set gitencoding [exec git config --get i18n.commitencoding]
8118 if {$gitencoding == ""} {
8119 set gitencoding "utf-8"
8121 set tclencoding [tcl_encoding $gitencoding]
8122 if {$tclencoding == {}} {
8123 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
8126 set mainfont {Helvetica 9}
8127 set textfont {Courier 9}
8128 set uifont {Helvetica 9 bold}
8130 set findmergefiles 0
8138 set cmitmode "patch"
8139 set wrapcomment "none"
8143 set showlocalchanges 1
8144 set datetimeformat "%Y-%m-%d %H:%M:%S"
8146 set colors {green red blue magenta darkgrey brown orange}
8149 set diffcolors {red "#00a000" blue}
8151 set selectbgcolor gray85
8153 catch {source ~/.gitk}
8155 font create optionfont -family sans-serif -size -12
8157 # check that we can find a .git directory somewhere...
8158 if {[catch {set gitdir [gitdir]}]} {
8159 show_error {} . "Cannot find a git repository here."
8162 if {![file isdirectory $gitdir]} {
8163 show_error {} . "Cannot find the git directory \"$gitdir\"."
8168 set cmdline_files {}
8173 "-d" { set datemode 1 }
8175 set cmdline_files [lrange $argv [expr {$i + 1}] end]
8179 lappend revtreeargs $arg
8185 if {$i >= [llength $argv] && $revtreeargs ne {}} {
8186 # no -- on command line, but some arguments (other than -d)
8188 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
8189 set cmdline_files [split $f "\n"]
8190 set n [llength $cmdline_files]
8191 set revtreeargs [lrange $revtreeargs 0 end-$n]
8192 # Unfortunately git rev-parse doesn't produce an error when
8193 # something is both a revision and a filename. To be consistent
8194 # with git log and git rev-list, check revtreeargs for filenames.
8195 foreach arg $revtreeargs {
8196 if {[file exists $arg]} {
8197 show_error {} . "Ambiguous argument '$arg': both revision\
8203 # unfortunately we get both stdout and stderr in $err,
8204 # so look for "fatal:".
8205 set i [string first "fatal:" $err]
8207 set err [string range $err [expr {$i + 6}] end]
8209 show_error {} . "Bad arguments to gitk:\n$err"
8214 set nullid "0000000000000000000000000000000000000000"
8215 set nullid2 "0000000000000000000000000000000000000001"
8223 set highlight_paths {}
8224 set searchdirn -forwards
8228 set markingmatches 0
8229 set linkentercount 0
8230 set need_redisplay 0
8236 set selectedhlview None
8250 # wait for the window to become visible
8252 wm title . "[file tail $argv0]: [file tail [pwd]]"
8255 if {$cmdline_files ne {} || $revtreeargs ne {}} {
8256 # create a view for the files/dirs specified on the command line
8260 set viewname(1) "Command line"
8261 set viewfiles(1) $cmdline_files
8262 set viewargs(1) $revtreeargs
8265 .bar.view entryconf Edit* -state normal
8266 .bar.view entryconf Delete* -state normal
8269 if {[info exists permviews]} {
8270 foreach v $permviews {
8273 set viewname($n) [lindex $v 0]
8274 set viewfiles($n) [lindex $v 1]
8275 set viewargs($n) [lindex $v 2]