2 # Tcl ignores the next line -*- tcl -*- \
5 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
6 # This program is free software; it may be used, copied, modified
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
12 if {[info exists env
(GIT_DIR
)]} {
19 proc start_rev_list
{rlargs
} {
20 global startmsecs nextupdate ncmupdate
21 global commfd leftover tclencoding datemode
23 set startmsecs
[clock clicks
-milliseconds]
24 set nextupdate
[expr {$startmsecs + 100}]
27 set order
"--topo-order"
29 set order
"--date-order"
32 set commfd
[open
[concat | git-rev-list
--header $order \
33 --parents --boundary --default HEAD
$rlargs] r
]
35 puts stderr
"Error executing git-rev-list: $err"
39 fconfigure
$commfd -blocking 0 -translation lf
40 if {$tclencoding != {}} {
41 fconfigure
$commfd -encoding $tclencoding
43 fileevent
$commfd readable
[list getcommitlines
$commfd]
44 . config
-cursor watch
48 proc getcommits
{rargs
} {
49 global phase canv mainfont
54 $canv create text
3 3 -anchor nw
-text "Reading commits..." \
55 -font $mainfont -tags textitems
58 proc getcommitlines
{commfd
} {
59 global commitlisted nextupdate
61 global displayorder commitidx commitrow commitdata
62 global parentlist childlist children
64 set stuff
[read $commfd]
66 if {![eof
$commfd]} return
67 # set it blocking so we wait for the process to terminate
68 fconfigure
$commfd -blocking 1
69 if {![catch
{close
$commfd} err
]} {
70 after idle finishcommits
73 if {[string range
$err 0 4] == "usage"} {
75 "Gitk: error reading commits: bad arguments to git-rev-list.\
76 (Note: arguments to gitk are passed to git-rev-list\
77 to allow selection of commits to be displayed.)"
79 set err
"Error reading commits: $err"
87 set i
[string first
"\0" $stuff $start]
89 append leftover
[string range
$stuff $start end
]
94 append cmit
[string range
$stuff 0 [expr {$i - 1}]]
97 set cmit
[string range
$stuff $start [expr {$i - 1}]]
99 set start
[expr {$i + 1}]
100 set j
[string first
"\n" $cmit]
104 set ids
[string range
$cmit 0 [expr {$j - 1}]]
105 if {[string range
$ids 0 0] == "-"} {
107 set ids
[string range
$ids 1 end
]
111 if {[string length
$id] != 40} {
119 if {[string length
$shortcmit] > 80} {
120 set shortcmit
"[string range $shortcmit 0 80]..."
122 error_popup
"Can't parse git-rev-list output: {$shortcmit}"
125 set id
[lindex
$ids 0]
127 set olds
[lrange
$ids 1 end
]
128 if {[llength
$olds] > 1} {
129 set olds
[lsort
-unique $olds]
132 lappend children
($p) $id
137 lappend parentlist
$olds
138 if {[info exists children
($id)]} {
139 lappend childlist
$children($id)
143 set commitdata
($id) [string range
$cmit [expr {$j + 1}] end
]
144 set commitrow
($id) $commitidx
146 lappend displayorder
$id
147 lappend commitlisted
$listed
153 if {[clock clicks
-milliseconds] >= $nextupdate} {
158 proc doupdate
{reading
} {
159 global commfd nextupdate numcommits ncmupdate
162 fileevent
$commfd readable
{}
165 set nextupdate
[expr {[clock clicks
-milliseconds] + 100}]
166 if {$numcommits < 100} {
167 set ncmupdate
[expr {$numcommits + 1}]
168 } elseif
{$numcommits < 10000} {
169 set ncmupdate
[expr {$numcommits + 10}]
171 set ncmupdate
[expr {$numcommits + 100}]
174 fileevent
$commfd readable
[list getcommitlines
$commfd]
178 proc readcommit
{id
} {
179 if {[catch
{set contents
[exec git-cat-file commit
$id]}]} return
180 parsecommit
$id $contents 0
183 proc updatecommits
{rargs
} {
185 foreach v
{colormap selectedline matchinglines treediffs
186 mergefilelist currentid rowtextx commitrow
187 rowidlist rowoffsets idrowranges idrangedrawn iddrawn
188 linesegends crossings cornercrossings
} {
197 proc parsecommit
{id contents listed
} {
198 global commitinfo cdate
207 set hdrend
[string first
"\n\n" $contents]
209 # should never happen...
210 set hdrend
[string length
$contents]
212 set header
[string range
$contents 0 [expr {$hdrend - 1}]]
213 set comment
[string range
$contents [expr {$hdrend + 2}] end
]
214 foreach line
[split $header "\n"] {
215 set tag
[lindex
$line 0]
216 if {$tag == "author"} {
217 set audate
[lindex
$line end-1
]
218 set auname
[lrange
$line 1 end-2
]
219 } elseif
{$tag == "committer"} {
220 set comdate
[lindex
$line end-1
]
221 set comname
[lrange
$line 1 end-2
]
225 # take the first line of the comment as the headline
226 set i
[string first
"\n" $comment]
228 set headline
[string trim
[string range
$comment 0 $i]]
230 set headline
$comment
233 # git-rev-list indents the comment by 4 spaces;
234 # if we got this via git-cat-file, add the indentation
236 foreach line
[split $comment "\n"] {
237 append newcomment
" "
238 append newcomment
$line
239 append newcomment
"\n"
241 set comment
$newcomment
243 if {$comdate != {}} {
244 set cdate
($id) $comdate
246 set commitinfo
($id) [list
$headline $auname $audate \
247 $comname $comdate $comment]
250 proc getcommit
{id
} {
251 global commitdata commitinfo
253 if {[info exists commitdata
($id)]} {
254 parsecommit
$id $commitdata($id) 1
257 if {![info exists commitinfo
($id)]} {
258 set commitinfo
($id) {"No commit information available"}
265 global tagids idtags headids idheads tagcontents
266 global otherrefids idotherrefs
268 foreach v
{tagids idtags headids idheads otherrefids idotherrefs
} {
271 set refd
[open
[list | git ls-remote
[gitdir
]] r
]
272 while {0 <= [set n
[gets
$refd line
]]} {
273 if {![regexp
{^
([0-9a-f]{40}) refs
/([^^
]*)$
} $line \
277 if {[regexp
{^remotes
/.
*/HEAD$
} $path match
]} {
280 if {![regexp
{^
(tags|heads
)/(.
*)$
} $path match
type name
]} {
284 if {[regexp
{^remotes
/} $path match
]} {
287 if {$type == "tags"} {
288 set tagids
($name) $id
289 lappend idtags
($id) $name
294 set commit
[exec git-rev-parse
"$id^0"]
295 if {"$commit" != "$id"} {
296 set tagids
($name) $commit
297 lappend idtags
($commit) $name
301 set tagcontents
($name) [exec git-cat-file tag
"$id"]
303 } elseif
{ $type == "heads" } {
304 set headids
($name) $id
305 lappend idheads
($id) $name
307 set otherrefids
($name) $id
308 lappend idotherrefs
($id) $name
314 proc error_popup msg
{
318 message
$w.m
-text $msg -justify center
-aspect 400
319 pack
$w.m
-side top
-fill x
-padx 20 -pady 20
320 button
$w.ok
-text OK
-command "destroy $w"
321 pack
$w.ok
-side bottom
-fill x
322 bind $w <Visibility
> "grab $w; focus $w"
323 bind $w <Key-Return
> "destroy $w"
327 proc makewindow
{rargs
} {
328 global canv canv2 canv3 linespc charspc ctext cflist textfont mainfont uifont
329 global findtype findtypemenu findloc findstring fstring geometry
330 global entries sha1entry sha1string sha1but
331 global maincursor textcursor curtextcursor
332 global rowctxmenu mergemax
335 .bar add cascade
-label "File" -menu .bar.
file
336 .bar configure
-font $uifont
338 .bar.
file add
command -label "Update" -command [list updatecommits
$rargs]
339 .bar.
file add
command -label "Reread references" -command rereadrefs
340 .bar.
file add
command -label "Quit" -command doquit
341 .bar.
file configure
-font $uifont
343 .bar add cascade
-label "Edit" -menu .bar.edit
344 .bar.edit add
command -label "Preferences" -command doprefs
345 .bar.edit configure
-font $uifont
347 .bar add cascade
-label "Help" -menu .bar.
help
348 .bar.
help add
command -label "About gitk" -command about
349 .bar.
help add
command -label "Key bindings" -command keys
350 .bar.
help configure
-font $uifont
351 . configure
-menu .bar
353 if {![info exists geometry
(canv1
)]} {
354 set geometry
(canv1
) [expr {45 * $charspc}]
355 set geometry
(canv2
) [expr {30 * $charspc}]
356 set geometry
(canv3
) [expr {15 * $charspc}]
357 set geometry
(canvh
) [expr {25 * $linespc + 4}]
358 set geometry
(ctextw
) 80
359 set geometry
(ctexth
) 30
360 set geometry
(cflistw
) 30
362 panedwindow .ctop
-orient vertical
363 if {[info exists geometry
(width
)]} {
364 .ctop conf
-width $geometry(width
) -height $geometry(height
)
365 set texth
[expr {$geometry(height
) - $geometry(canvh
) - 56}]
366 set geometry
(ctexth
) [expr {($texth - 8) /
367 [font metrics
$textfont -linespace]}]
371 pack .ctop.top.bar
-side bottom
-fill x
372 set cscroll .ctop.top.csb
373 scrollbar
$cscroll -command {allcanvs yview
} -highlightthickness 0
374 pack
$cscroll -side right
-fill y
375 panedwindow .ctop.top.clist
-orient horizontal
-sashpad 0 -handlesize 4
376 pack .ctop.top.clist
-side top
-fill both
-expand 1
378 set canv .ctop.top.clist.canv
379 canvas
$canv -height $geometry(canvh
) -width $geometry(canv1
) \
381 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
382 .ctop.top.clist add
$canv
383 set canv2 .ctop.top.clist.canv2
384 canvas
$canv2 -height $geometry(canvh
) -width $geometry(canv2
) \
385 -bg white
-bd 0 -yscrollincr $linespc
386 .ctop.top.clist add
$canv2
387 set canv3 .ctop.top.clist.canv3
388 canvas
$canv3 -height $geometry(canvh
) -width $geometry(canv3
) \
389 -bg white
-bd 0 -yscrollincr $linespc
390 .ctop.top.clist add
$canv3
391 bind .ctop.top.clist
<Configure
> {resizeclistpanes
%W
%w
}
393 set sha1entry .ctop.top.bar.sha1
394 set entries
$sha1entry
395 set sha1but .ctop.top.bar.sha1label
396 button
$sha1but -text "SHA1 ID: " -state disabled
-relief flat \
397 -command gotocommit
-width 8 -font $uifont
398 $sha1but conf
-disabledforeground [$sha1but cget
-foreground]
399 pack .ctop.top.bar.sha1label
-side left
400 entry
$sha1entry -width 40 -font $textfont -textvariable sha1string
401 trace add variable sha1string
write sha1change
402 pack
$sha1entry -side left
-pady 2
404 image create bitmap bm-left
-data {
405 #define left_width 16
406 #define left_height 16
407 static unsigned char left_bits
[] = {
408 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
409 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
410 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
412 image create bitmap bm-right
-data {
413 #define right_width 16
414 #define right_height 16
415 static unsigned char right_bits
[] = {
416 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
417 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
418 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
420 button .ctop.top.bar.leftbut
-image bm-left
-command goback \
421 -state disabled
-width 26
422 pack .ctop.top.bar.leftbut
-side left
-fill y
423 button .ctop.top.bar.rightbut
-image bm-right
-command goforw \
424 -state disabled
-width 26
425 pack .ctop.top.bar.rightbut
-side left
-fill y
427 button .ctop.top.bar.findbut
-text "Find" -command dofind
-font $uifont
428 pack .ctop.top.bar.findbut
-side left
430 set fstring .ctop.top.bar.findstring
431 lappend entries
$fstring
432 entry
$fstring -width 30 -font $textfont -textvariable findstring
-font $textfont
433 pack
$fstring -side left
-expand 1 -fill x
435 set findtypemenu
[tk_optionMenu .ctop.top.bar.findtype \
436 findtype Exact IgnCase Regexp
]
437 .ctop.top.bar.findtype configure
-font $uifont
438 .ctop.top.bar.findtype.menu configure
-font $uifont
439 set findloc
"All fields"
440 tk_optionMenu .ctop.top.bar.findloc findloc
"All fields" Headline \
441 Comments Author Committer Files Pickaxe
442 .ctop.top.bar.findloc configure
-font $uifont
443 .ctop.top.bar.findloc.menu configure
-font $uifont
445 pack .ctop.top.bar.findloc
-side right
446 pack .ctop.top.bar.findtype
-side right
447 # for making sure type==Exact whenever loc==Pickaxe
448 trace add variable findloc
write findlocchange
450 panedwindow .ctop.cdet
-orient horizontal
452 frame .ctop.cdet.left
453 set ctext .ctop.cdet.left.ctext
454 text
$ctext -bg white
-state disabled
-font $textfont \
455 -width $geometry(ctextw
) -height $geometry(ctexth
) \
456 -yscrollcommand ".ctop.cdet.left.sb set" -wrap none
457 scrollbar .ctop.cdet.left.sb
-command "$ctext yview"
458 pack .ctop.cdet.left.sb
-side right
-fill y
459 pack
$ctext -side left
-fill both
-expand 1
460 .ctop.cdet add .ctop.cdet.left
462 $ctext tag conf filesep
-font [concat
$textfont bold
] -back "#aaaaaa"
463 $ctext tag conf hunksep
-fore blue
464 $ctext tag conf d0
-fore red
465 $ctext tag conf d1
-fore "#00a000"
466 $ctext tag conf m0
-fore red
467 $ctext tag conf m1
-fore blue
468 $ctext tag conf m2
-fore green
469 $ctext tag conf m3
-fore purple
470 $ctext tag conf
m4 -fore brown
471 $ctext tag conf m5
-fore "#009090"
472 $ctext tag conf m6
-fore magenta
473 $ctext tag conf m7
-fore "#808000"
474 $ctext tag conf m8
-fore "#009000"
475 $ctext tag conf m9
-fore "#ff0080"
476 $ctext tag conf m10
-fore cyan
477 $ctext tag conf m11
-fore "#b07070"
478 $ctext tag conf m12
-fore "#70b0f0"
479 $ctext tag conf m13
-fore "#70f0b0"
480 $ctext tag conf m14
-fore "#f0b070"
481 $ctext tag conf m15
-fore "#ff70b0"
482 $ctext tag conf mmax
-fore darkgrey
484 $ctext tag conf mresult
-font [concat
$textfont bold
]
485 $ctext tag conf msep
-font [concat
$textfont bold
]
486 $ctext tag conf found
-back yellow
488 frame .ctop.cdet.right
489 set cflist .ctop.cdet.right.cfiles
490 listbox
$cflist -bg white
-selectmode extended
-width $geometry(cflistw
) \
491 -yscrollcommand ".ctop.cdet.right.sb set" -font $mainfont
492 scrollbar .ctop.cdet.right.sb
-command "$cflist yview"
493 pack .ctop.cdet.right.sb
-side right
-fill y
494 pack
$cflist -side left
-fill both
-expand 1
495 .ctop.cdet add .ctop.cdet.right
496 bind .ctop.cdet
<Configure
> {resizecdetpanes
%W
%w
}
498 pack .ctop
-side top
-fill both
-expand 1
500 bindall
<1> {selcanvline
%W
%x
%y
}
501 #bindall <B1-Motion> {selcanvline %W %x %y}
502 bindall
<ButtonRelease-4
> "allcanvs yview scroll -5 units"
503 bindall
<ButtonRelease-5
> "allcanvs yview scroll 5 units"
504 bindall
<2> "canvscan mark %W %x %y"
505 bindall
<B2-Motion
> "canvscan dragto %W %x %y"
506 bindkey
<Home
> selfirstline
507 bindkey
<End
> sellastline
508 bind .
<Key-Up
> "selnextline -1"
509 bind .
<Key-Down
> "selnextline 1"
510 bindkey
<Key-Right
> "goforw"
511 bindkey
<Key-Left
> "goback"
512 bind .
<Key-Prior
> "selnextpage -1"
513 bind .
<Key-Next
> "selnextpage 1"
514 bind .
<Control-Home
> "allcanvs yview moveto 0.0"
515 bind .
<Control-End
> "allcanvs yview moveto 1.0"
516 bind .
<Control-Key-Up
> "allcanvs yview scroll -1 units"
517 bind .
<Control-Key-Down
> "allcanvs yview scroll 1 units"
518 bind .
<Control-Key-Prior
> "allcanvs yview scroll -1 pages"
519 bind .
<Control-Key-Next
> "allcanvs yview scroll 1 pages"
520 bindkey
<Key-Delete
> "$ctext yview scroll -1 pages"
521 bindkey
<Key-BackSpace
> "$ctext yview scroll -1 pages"
522 bindkey
<Key-space
> "$ctext yview scroll 1 pages"
523 bindkey p
"selnextline -1"
524 bindkey n
"selnextline 1"
527 bindkey i
"selnextline -1"
528 bindkey k
"selnextline 1"
531 bindkey b
"$ctext yview scroll -1 pages"
532 bindkey d
"$ctext yview scroll 18 units"
533 bindkey u
"$ctext yview scroll -18 units"
534 bindkey
/ {findnext
1}
535 bindkey
<Key-Return
> {findnext
0}
538 bind .
<Control-q
> doquit
539 bind .
<Control-f
> dofind
540 bind .
<Control-g
> {findnext
0}
541 bind .
<Control-r
> findprev
542 bind .
<Control-equal
> {incrfont
1}
543 bind .
<Control-KP_Add
> {incrfont
1}
544 bind .
<Control-minus
> {incrfont
-1}
545 bind .
<Control-KP_Subtract
> {incrfont
-1}
546 bind $cflist <<ListboxSelect>> listboxsel
547 bind . <Destroy> {savestuff %W}
548 bind . <Button-1> "click %W"
549 bind $fstring <Key-Return> dofind
550 bind $sha1entry <Key-Return> gotocommit
551 bind $sha1entry <<PasteSelection>> clearsha1
553 set maincursor [. cget -cursor]
554 set textcursor [$ctext cget -cursor]
555 set curtextcursor $textcursor
557 set rowctxmenu .rowctxmenu
558 menu $rowctxmenu -tearoff 0
559 $rowctxmenu add command -label "Diff this -> selected" \
560 -command {diffvssel 0}
561 $rowctxmenu add command -label "Diff selected -> this" \
562 -command {diffvssel 1}
563 $rowctxmenu add command -label "Make patch" -command mkpatch
564 $rowctxmenu add command -label "Create tag" -command mktag
565 $rowctxmenu add command -label "Write commit to file" -command writecommit
568 # mouse-2 makes all windows scan vertically, but only the one
569 # the cursor is in scans horizontally
570 proc canvscan {op w x y} {
571 global canv canv2 canv3
572 foreach c [list $canv $canv2 $canv3] {
581 proc scrollcanv {cscroll f0 f1} {
586 # when we make a key binding for the toplevel, make sure
587 # it doesn't get triggered when that key is pressed in the
588 # find string entry widget.
589 proc bindkey {ev script} {
592 set escript [bind Entry $ev]
593 if {$escript == {}} {
594 set escript [bind Entry <Key>]
597 bind $e $ev "$escript; break"
601 # set the focus back to the toplevel for any click outside
612 global canv canv2 canv3 ctext cflist mainfont textfont uifont
613 global stuffsaved findmergefiles maxgraphpct
616 if {$stuffsaved} return
617 if {![winfo viewable .]} return
619 set f [open "~/.gitk-new" w]
620 puts $f [list set mainfont $mainfont]
621 puts $f [list set textfont $textfont]
622 puts $f [list set uifont $uifont]
623 puts $f [list set findmergefiles $findmergefiles]
624 puts $f [list set maxgraphpct $maxgraphpct]
625 puts $f [list set maxwidth $maxwidth]
626 puts $f "set geometry(width) [winfo width .ctop]"
627 puts $f "set geometry(height) [winfo height .ctop]"
628 puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
629 puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]"
630 puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]"
631 puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]"
632 set wid [expr {([winfo width $ctext] - 8) \
633 / [font measure $textfont "0"]}]
634 puts $f "set geometry(ctextw) $wid"
635 set wid [expr {([winfo width $cflist] - 11) \
636 / [font measure [$cflist cget -font] "0"]}]
637 puts $f "set geometry(cflistw) $wid"
639 file rename -force "~/.gitk-new" "~/.gitk"
644 proc resizeclistpanes {win w} {
646 if {[info exists oldwidth($win)]} {
647 set s0 [$win sash coord 0]
648 set s1 [$win sash coord 1]
650 set sash0 [expr {int($w/2 - 2)}]
651 set sash1 [expr {int($w*5/6 - 2)}]
653 set factor [expr {1.0 * $w / $oldwidth($win)}]
654 set sash0 [expr {int($factor * [lindex $s0 0])}]
655 set sash1 [expr {int($factor * [lindex $s1 0])}]
659 if {$sash1 < $sash0 + 20} {
660 set sash1 [expr {$sash0 + 20}]
662 if {$sash1 > $w - 10} {
663 set sash1 [expr {$w - 10}]
664 if {$sash0 > $sash1 - 20} {
665 set sash0 [expr {$sash1 - 20}]
669 $win sash place 0 $sash0 [lindex $s0 1]
670 $win sash place 1 $sash1 [lindex $s1 1]
672 set oldwidth($win) $w
675 proc resizecdetpanes {win w} {
677 if {[info exists oldwidth($win)]} {
678 set s0 [$win sash coord 0]
680 set sash0 [expr {int($w*3/4 - 2)}]
682 set factor [expr {1.0 * $w / $oldwidth($win)}]
683 set sash0 [expr {int($factor * [lindex $s0 0])}]
687 if {$sash0 > $w - 15} {
688 set sash0 [expr {$w - 15}]
691 $win sash place 0 $sash0 [lindex $s0 1]
693 set oldwidth($win) $w
697 global canv canv2 canv3
703 proc bindall {event action} {
704 global canv canv2 canv3
705 bind $canv $event $action
706 bind $canv2 $event $action
707 bind $canv3 $event $action
712 if {[winfo exists $w]} {
717 wm title $w "About gitk"
719 Gitk - a commit viewer for git
721 Copyright © 2005-2006 Paul Mackerras
723 Use and redistribute under the terms of the GNU General Public License} \
724 -justify center -aspect 400
725 pack $w.m -side top -fill x -padx 20 -pady 20
726 button $w.ok -text Close -command "destroy $w"
727 pack $w.ok -side bottom
732 if {[winfo exists $w]} {
737 wm title $w "Gitk key bindings"
742 <Home> Move to first commit
743 <End> Move to last commit
744 <Up>, p, i Move up one commit
745 <Down>, n, k Move down one commit
746 <Left>, z, j Go back in history list
747 <Right>, x, l Go forward in history list
748 <PageUp> Move up one page in commit list
749 <PageDown> Move down one page in commit list
750 <Ctrl-Home> Scroll to top of commit list
751 <Ctrl-End> Scroll to bottom of commit list
752 <Ctrl-Up> Scroll commit list up one line
753 <Ctrl-Down> Scroll commit list down one line
754 <Ctrl-PageUp> Scroll commit list up one page
755 <Ctrl-PageDown> Scroll commit list down one page
756 <Delete>, b Scroll diff view up one page
757 <Backspace> Scroll diff view up one page
758 <Space> Scroll diff view down one page
759 u Scroll diff view up 18 lines
760 d Scroll diff view down 18 lines
762 <Ctrl-G> Move to next find hit
763 <Ctrl-R> Move to previous find hit
764 <Return> Move to next find hit
765 / Move to next find hit, or redo find
766 ? Move to previous find hit
767 f Scroll diff view to next file
768 <Ctrl-KP+> Increase font size
769 <Ctrl-plus> Increase font size
770 <Ctrl-KP-> Decrease font size
771 <Ctrl-minus> Decrease font size
773 -justify left -bg white -border 2 -relief sunken
774 pack $w.m -side top -fill both
775 button $w.ok -text Close -command "destroy $w"
776 pack $w.ok -side bottom
779 proc shortids {ids} {
782 if {[llength $id] > 1} {
783 lappend res [shortids $id]
784 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
785 lappend res [string range $id 0 7]
793 proc incrange {l x o} {
798 lset l $x [expr {$e + $o}]
807 for {} {$n > 0} {incr n -1} {
813 proc usedinrange {id l1 l2} {
814 global children commitrow
816 if {[info exists commitrow($id)]} {
817 set r $commitrow($id)
818 if {$l1 <= $r && $r <= $l2} {
819 return [expr {$r - $l1 + 1}]
822 foreach c $children($id) {
823 if {[info exists commitrow($c)]} {
825 if {$l1 <= $r && $r <= $l2} {
826 return [expr {$r - $l1 + 1}]
833 proc sanity {row {full 0}} {
834 global rowidlist rowoffsets
837 set ids [lindex $rowidlist $row]
840 if {$id eq {}} continue
841 if {$col < [llength $ids] - 1 &&
842 [lsearch -exact -start [expr {$col+1}] $ids $id] >= 0} {
843 puts "oops: [shortids $id] repeated in row $row col $col: {[shortids [lindex $rowidlist $row]]}"
845 set o [lindex $rowoffsets $row $col]
851 if {[lindex $rowidlist $y $x] != $id} {
852 puts "oops: rowoffsets wrong at row [expr {$y+1}] col [expr {$x-$o}]"
853 puts " id=[shortids $id] check started at row $row"
854 for {set i $row} {$i >= $y} {incr i -1} {
855 puts " row $i ids={[shortids [lindex $rowidlist $i]]} offs={[lindex $rowoffsets $i]}"
860 set o [lindex $rowoffsets $y $x]
865 proc makeuparrow {oid x y z} {
866 global rowidlist rowoffsets uparrowlen idrowranges
868 for {set i 1} {$i < $uparrowlen && $y > 1} {incr i} {
871 set off0 [lindex $rowoffsets $y]
872 for {set x0 $x} {1} {incr x0} {
873 if {$x0 >= [llength $off0]} {
874 set x0 [llength [lindex $rowoffsets [expr {$y-1}]]]
877 set z [lindex $off0 $x0]
883 set z [expr {$x0 - $x}]
884 lset rowidlist $y [linsert [lindex $rowidlist $y] $x $oid]
885 lset rowoffsets $y [linsert [lindex $rowoffsets $y] $x $z]
887 set tmp [lreplace [lindex $rowoffsets $y] $x $x {}]
888 lset rowoffsets $y [incrange $tmp [expr {$x+1}] -1]
889 lappend idrowranges($oid) $y
893 global rowidlist rowoffsets displayorder commitlisted
894 global rowlaidout rowoptim
895 global idinlist rowchk
896 global commitidx numcommits canvxmax canv
898 global parentlist childlist children
906 catch {unset children}
910 catch {unset idinlist}
914 set canvxmax [$canv cget -width]
917 proc setcanvscroll {} {
918 global canv canv2 canv3 numcommits linespc canvxmax canvy0
920 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
921 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
922 $canv2 conf -scrollregion [list 0 0 0 $ymax]
923 $canv3 conf -scrollregion [list 0 0 0 $ymax]
926 proc visiblerows {} {
927 global canv numcommits linespc
929 set ymax [lindex [$canv cget -scrollregion] 3]
930 if {$ymax eq {} || $ymax == 0} return
932 set y0 [expr {int([lindex $f 0] * $ymax)}]
933 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
937 set y1 [expr {int([lindex $f 1] * $ymax)}]
938 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
939 if {$r1 >= $numcommits} {
940 set r1 [expr {$numcommits - 1}]
942 return [list $r0 $r1]
946 global rowlaidout rowoptim commitidx numcommits optim_delay
950 set rowlaidout [layoutrows $row $commitidx 0]
951 set orow [expr {$rowlaidout - $uparrowlen - 1}]
952 if {$orow > $rowoptim} {
953 checkcrossings $rowoptim $orow
954 optimize_rows $rowoptim 0 $orow
957 set canshow [expr {$rowoptim - $optim_delay}]
958 if {$canshow > $numcommits} {
963 proc showstuff {canshow} {
965 global linesegends idrowranges idrangedrawn
967 if {$numcommits == 0} {
973 set numcommits $canshow
975 set rows [visiblerows]
976 set r0 [lindex $rows 0]
977 set r1 [lindex $rows 1]
978 for {set r $row} {$r < $canshow} {incr r} {
979 if {[info exists linesegends($r)]} {
980 foreach id $linesegends($r) {
982 foreach {s e} $idrowranges($id) {
984 if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
985 && ![info exists idrangedrawn($id,$i)]} {
987 set idrangedrawn($id,$i) 1
993 if {$canshow > $r1} {
996 while {$row < $canshow} {
1002 proc layoutrows {row endrow last} {
1003 global rowidlist rowoffsets displayorder
1004 global uparrowlen downarrowlen maxwidth mingaplen
1005 global childlist parentlist
1006 global idrowranges linesegends
1008 global idinlist rowchk
1010 set idlist [lindex $rowidlist $row]
1011 set offs [lindex $rowoffsets $row]
1012 while {$row < $endrow} {
1013 set id [lindex $displayorder $row]
1016 foreach p [lindex $parentlist $row] {
1017 if {![info exists idinlist($p)]} {
1019 } elseif {!$idinlist($p)} {
1023 set nev [expr {[llength $idlist] + [llength $newolds]
1024 + [llength $oldolds] - $maxwidth + 1}]
1026 if {!$last && $row + $uparrowlen + $mingaplen >= $commitidx} break
1027 for {set x [llength $idlist]} {[incr x -1] >= 0} {} {
1028 set i [lindex $idlist $x]
1029 if {![info exists rowchk($i)] || $row >= $rowchk($i)} {
1030 set r [usedinrange $i [expr {$row - $downarrowlen}] \
1031 [expr {$row + $uparrowlen + $mingaplen}]]
1033 set idlist [lreplace $idlist $x $x]
1034 set offs [lreplace $offs $x $x]
1035 set offs [incrange $offs $x 1]
1037 set rm1 [expr {$row - 1}]
1038 lappend linesegends($rm1) $i
1039 lappend idrowranges($i) $rm1
1040 if {[incr nev -1] <= 0} break
1043 set rowchk($id) [expr {$row + $r}]
1046 lset rowidlist $row $idlist
1047 lset rowoffsets $row $offs
1049 set col [lsearch -exact $idlist $id]
1051 set col [llength $idlist]
1053 lset rowidlist $row $idlist
1055 if {[lindex $childlist $row] ne {}} {
1056 set z [expr {[llength [lindex $rowidlist [expr {$row-1}]]] - $col}]
1060 lset rowoffsets $row $offs
1062 makeuparrow $id $col $row $z
1067 if {[info exists idrowranges($id)]} {
1068 lappend idrowranges($id) $row
1071 set offs [ntimes [llength $idlist] 0]
1072 set l [llength $newolds]
1073 set idlist [eval lreplace \$idlist $col $col $newolds]
1076 set offs [lrange $offs 0 [expr {$col - 1}]]
1077 foreach x $newolds {
1082 set tmp [expr {[llength $idlist] - [llength $offs]}]
1084 set offs [concat $offs [ntimes $tmp $o]]
1089 foreach i $newolds {
1091 set idrowranges($i) $row
1094 foreach oid $oldolds {
1095 set idinlist($oid) 1
1096 set idlist [linsert $idlist $col $oid]
1097 set offs [linsert $offs $col $o]
1098 makeuparrow $oid $col $row $o
1101 lappend rowidlist $idlist
1102 lappend rowoffsets $offs
1107 proc addextraid {id row} {
1108 global displayorder commitrow commitinfo
1109 global commitidx commitlisted
1110 global parentlist childlist children
1113 lappend displayorder $id
1114 lappend commitlisted 0
1115 lappend parentlist {}
1116 set commitrow($id) $row
1118 if {![info exists commitinfo($id)]} {
1119 set commitinfo($id) {"No commit information available"}
1121 if {[info exists children($id)]} {
1122 lappend childlist $children($id)
1124 lappend childlist {}
1128 proc layouttail {} {
1129 global rowidlist rowoffsets idinlist commitidx
1133 set idlist [lindex $rowidlist $row]
1134 while {$idlist ne {}} {
1135 set col [expr {[llength $idlist] - 1}]
1136 set id [lindex $idlist $col]
1139 lappend idrowranges($id) $row
1141 set offs [ntimes $col 0]
1142 set idlist [lreplace $idlist $col $col]
1143 lappend rowidlist $idlist
1144 lappend rowoffsets $offs
1147 foreach id [array names idinlist] {
1149 lset rowidlist $row [list $id]
1150 lset rowoffsets $row 0
1151 makeuparrow $id 0 $row 0
1152 lappend idrowranges($id) $row
1154 lappend rowidlist {}
1155 lappend rowoffsets {}
1159 proc insert_pad {row col npad} {
1160 global rowidlist rowoffsets
1162 set pad [ntimes $npad {}]
1163 lset rowidlist $row [eval linsert [list [lindex $rowidlist $row]] $col $pad]
1164 set tmp [eval linsert [list [lindex $rowoffsets $row]] $col $pad]
1165 lset rowoffsets $row [incrange $tmp [expr {$col + $npad}] [expr {-$npad}]]
1168 proc optimize_rows {row col endrow} {
1169 global rowidlist rowoffsets idrowranges linesegends displayorder
1171 for {} {$row < $endrow} {incr row} {
1172 set idlist [lindex $rowidlist $row]
1173 set offs [lindex $rowoffsets $row]
1175 for {} {$col < [llength $offs]} {incr col} {
1176 if {[lindex $idlist $col] eq {}} {
1180 set z [lindex $offs $col]
1181 if {$z eq {}} continue
1183 set x0 [expr {$col + $z}]
1184 set y0 [expr {$row - 1}]
1185 set z0 [lindex $rowoffsets $y0 $x0]
1187 set id [lindex $idlist $col]
1188 if {[info exists idrowranges($id)] &&
1189 $y0 > [lindex $idrowranges($id) 0]} {
1193 if {$z < -1 || ($z < 0 && $isarrow)} {
1194 set npad [expr {-1 - $z + $isarrow}]
1195 set offs [incrange $offs $col $npad]
1196 insert_pad $y0 $x0 $npad
1198 optimize_rows $y0 $x0 $row
1200 set z [lindex $offs $col]
1201 set x0 [expr {$col + $z}]
1202 set z0 [lindex $rowoffsets $y0 $x0]
1203 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
1204 set npad [expr {$z - 1 + $isarrow}]
1205 set y1 [expr {$row + 1}]
1206 set offs2 [lindex $rowoffsets $y1]
1210 if {$z eq {} || $x1 + $z < $col} continue
1211 if {$x1 + $z > $col} {
1214 lset rowoffsets $y1 [incrange $offs2 $x1 $npad]
1217 set pad [ntimes $npad {}]
1218 set idlist [eval linsert \$idlist $col $pad]
1219 set tmp [eval linsert \$offs $col $pad]
1221 set offs [incrange $tmp $col [expr {-$npad}]]
1222 set z [lindex $offs $col]
1225 if {$z0 eq {} && !$isarrow} {
1226 # this line links to its first child on row $row-2
1227 set rm2 [expr {$row - 2}]
1228 set id [lindex $displayorder $rm2]
1229 set xc [lsearch -exact [lindex $rowidlist $rm2] $id]
1231 set z0 [expr {$xc - $x0}]
1234 if {$z0 ne {} && $z < 0 && $z0 > 0} {
1235 insert_pad $y0 $x0 1
1236 set offs [incrange $offs $col 1]
1237 optimize_rows $y0 [expr {$x0 + 1}] $row
1242 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
1243 set o [lindex $offs $col]
1245 # check if this is the link to the first child
1246 set id [lindex $idlist $col]
1247 if {[info exists idrowranges($id)] &&
1248 $row == [lindex $idrowranges($id) 0]} {
1249 # it is, work out offset to child
1250 set y0 [expr {$row - 1}]
1251 set id [lindex $displayorder $y0]
1252 set x0 [lsearch -exact [lindex $rowidlist $y0] $id]
1254 set o [expr {$x0 - $col}]
1258 if {$o eq {} || $o <= 0} break
1260 if {$o ne {} && [incr col] < [llength $idlist]} {
1261 set y1 [expr {$row + 1}]
1262 set offs2 [lindex $rowoffsets $y1]
1266 if {$z eq {} || $x1 + $z < $col} continue
1267 lset rowoffsets $y1 [incrange $offs2 $x1 1]
1270 set idlist [linsert $idlist $col {}]
1271 set tmp [linsert $offs $col {}]
1273 set offs [incrange $tmp $col -1]
1276 lset rowidlist $row $idlist
1277 lset rowoffsets $row $offs
1283 global canvx0 linespc
1284 return [expr {$canvx0 + $col * $linespc}]
1288 global canvy0 linespc
1289 return [expr {$canvy0 + $row * $linespc}]
1292 proc linewidth {id} {
1293 global thickerline lthickness
1296 if {[info exists thickerline] && $id eq $thickerline} {
1297 set wid [expr {2 * $lthickness}]
1302 proc drawlineseg {id i} {
1303 global rowoffsets rowidlist idrowranges
1305 global canv colormap linespc
1307 set startrow [lindex $idrowranges($id) [expr {2 * $i}]]
1308 set row [lindex $idrowranges($id) [expr {2 * $i + 1}]]
1309 if {$startrow == $row} return
1312 set col [lsearch -exact [lindex $rowidlist $row] $id]
1314 puts "oops: drawline: id $id not on row $row"
1320 set o [lindex $rowoffsets $row $col]
1323 # changing direction
1324 set x [xc $row $col]
1326 lappend coords $x $y
1332 set x [xc $row $col]
1334 lappend coords $x $y
1336 # draw the link to the first child as part of this line
1338 set child [lindex $displayorder $row]
1339 set ccol [lsearch -exact [lindex $rowidlist $row] $child]
1341 set x [xc $row $ccol]
1343 if {$ccol < $col - 1} {
1344 lappend coords [xc $row [expr {$col - 1}]] [yc $row]
1345 } elseif {$ccol > $col + 1} {
1346 lappend coords [xc $row [expr {$col + 1}]] [yc $row]
1348 lappend coords $x $y
1351 if {[llength $coords] < 4} return
1352 set last [expr {[llength $idrowranges($id)] / 2 - 1}]
1354 # This line has an arrow at the lower end: check if the arrow is
1355 # on a diagonal segment, and if so, work around the Tk 8.4
1356 # refusal to draw arrows on diagonal lines.
1357 set x0 [lindex $coords 0]
1358 set x1 [lindex $coords 2]
1360 set y0 [lindex $coords 1]
1361 set y1 [lindex $coords 3]
1362 if {$y0 - $y1 <= 2 * $linespc && $x1 == [lindex $coords 4]} {
1363 # we have a nearby vertical segment, just trim off the diag bit
1364 set coords [lrange $coords 2 end]
1366 set slope [expr {($x0 - $x1) / ($y0 - $y1)}]
1367 set xi [expr {$x0 - $slope * $linespc / 2}]
1368 set yi [expr {$y0 - $linespc / 2}]
1369 set coords [lreplace $coords 0 1 $xi $y0 $xi $yi]
1373 set arrow [expr {2 * ($i > 0) + ($i < $last)}]
1374 set arrow [lindex {none first last both} $arrow]
1375 set t [$canv create line $coords -width [linewidth $id] \
1376 -fill $colormap($id) -tags lines.$id -arrow $arrow]
1381 proc drawparentlinks {id row col olds} {
1382 global rowidlist canv colormap idrowranges
1384 set row2 [expr {$row + 1}]
1385 set x [xc $row $col]
1388 set ids [lindex $rowidlist $row2]
1389 # rmx = right-most X coord used
1392 set i [lsearch -exact $ids $p]
1394 puts "oops, parent $p of $id not in list"
1397 set x2 [xc $row2 $i]
1401 if {[info exists idrowranges($p)] &&
1402 $row2 == [lindex $idrowranges($p) 0] &&
1403 $row2 < [lindex $idrowranges($p) 1]} {
1404 # drawlineseg will do this one for us
1408 # should handle duplicated parents here...
1409 set coords [list $x $y]
1410 if {$i < $col - 1} {
1411 lappend coords [xc $row [expr {$i + 1}]] $y
1412 } elseif {$i > $col + 1} {
1413 lappend coords [xc $row [expr {$i - 1}]] $y
1415 lappend coords $x2 $y2
1416 set t [$canv create line $coords -width [linewidth $p] \
1417 -fill $colormap($p) -tags lines.$p]
1424 proc drawlines {id} {
1425 global colormap canv
1426 global idrowranges idrangedrawn
1427 global childlist iddrawn commitrow rowidlist
1429 $canv delete lines.$id
1430 set nr [expr {[llength $idrowranges($id)] / 2}]
1431 for {set i 0} {$i < $nr} {incr i} {
1432 if {[info exists idrangedrawn($id,$i)]} {
1436 foreach child [lindex $childlist $commitrow($id)] {
1437 if {[info exists iddrawn($child)]} {
1438 set row $commitrow($child)
1439 set col [lsearch -exact [lindex $rowidlist $row] $child]
1441 drawparentlinks $child $row $col [list $id]
1447 proc drawcmittext {id row col rmx} {
1448 global linespc canv canv2 canv3 canvy0
1449 global commitlisted commitinfo rowidlist
1450 global rowtextx idpos idtags idheads idotherrefs
1451 global linehtag linentag linedtag
1452 global mainfont namefont canvxmax
1454 set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
1455 set x [xc $row $col]
1457 set orad [expr {$linespc / 3}]
1458 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
1459 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
1460 -fill $ofill -outline black -width 1]
1462 $canv bind $t <1> {selcanvline {} %x %y}
1463 set xt [xc $row [llength [lindex $rowidlist $row]]]
1467 set rowtextx($row) $xt
1468 set idpos($id) [list $x $xt $y]
1469 if {[info exists idtags($id)] || [info exists idheads($id)]
1470 || [info exists idotherrefs($id)]} {
1471 set xt [drawtags $id $x $xt $y]
1473 set headline [lindex $commitinfo($id) 0]
1474 set name [lindex $commitinfo($id) 1]
1475 set date [lindex $commitinfo($id) 2]
1476 set date [formatdate $date]
1477 set linehtag($row) [$canv create text $xt $y -anchor w \
1478 -text $headline -font $mainfont ]
1479 $canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
1480 set linentag($row) [$canv2 create text 3 $y -anchor w \
1481 -text $name -font $namefont]
1482 set linedtag($row) [$canv3 create text 3 $y -anchor w \
1483 -text $date -font $mainfont]
1484 set xr [expr {$xt + [font measure $mainfont $headline]}]
1485 if {$xr > $canvxmax} {
1491 proc drawcmitrow {row} {
1492 global displayorder rowidlist
1493 global idrowranges idrangedrawn iddrawn
1494 global commitinfo parentlist numcommits
1496 if {$row >= $numcommits} return
1497 foreach id [lindex $rowidlist $row] {
1498 if {![info exists idrowranges($id)]} continue
1500 foreach {s e} $idrowranges($id) {
1502 if {$row < $s} continue
1505 if {$e < $numcommits && ![info exists idrangedrawn($id,$i)]} {
1507 set idrangedrawn($id,$i) 1
1514 set id [lindex $displayorder $row]
1515 if {[info exists iddrawn($id)]} return
1516 set col [lsearch -exact [lindex $rowidlist $row] $id]
1518 puts "oops, row $row id $id not in list"
1521 if {![info exists commitinfo($id)]} {
1525 set olds [lindex $parentlist $row]
1527 set rmx [drawparentlinks $id $row $col $olds]
1531 drawcmittext $id $row $col $rmx
1535 proc drawfrac {f0 f1} {
1536 global numcommits canv
1539 set ymax [lindex [$canv cget -scrollregion] 3]
1540 if {$ymax eq {} || $ymax == 0} return
1541 set y0 [expr {int($f0 * $ymax)}]
1542 set row [expr {int(($y0 - 3) / $linespc) - 1}]
1546 set y1 [expr {int($f1 * $ymax)}]
1547 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
1548 if {$endrow >= $numcommits} {
1549 set endrow [expr {$numcommits - 1}]
1551 for {} {$row <= $endrow} {incr row} {
1556 proc drawvisible {} {
1558 eval drawfrac [$canv yview]
1561 proc clear_display {} {
1562 global iddrawn idrangedrawn
1565 catch {unset iddrawn}
1566 catch {unset idrangedrawn}
1569 proc assigncolor {id} {
1570 global colormap colors nextcolor
1571 global commitrow parentlist children childlist
1572 global cornercrossings crossings
1574 if {[info exists colormap($id)]} return
1575 set ncolors [llength $colors]
1576 if {[info exists commitrow($id)]} {
1577 set kids [lindex $childlist $commitrow($id)]
1578 } elseif {[info exists children($id)]} {
1579 set kids $children($id)
1583 if {[llength $kids] == 1} {
1584 set child [lindex $kids 0]
1585 if {[info exists colormap($child)]
1586 && [llength [lindex $parentlist $commitrow($child)]] == 1} {
1587 set colormap($id) $colormap($child)
1592 if {[info exists cornercrossings($id)]} {
1593 foreach x $cornercrossings($id) {
1594 if {[info exists colormap($x)]
1595 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1596 lappend badcolors $colormap($x)
1599 if {[llength $badcolors] >= $ncolors} {
1603 set origbad $badcolors
1604 if {[llength $badcolors] < $ncolors - 1} {
1605 if {[info exists crossings($id)]} {
1606 foreach x $crossings($id) {
1607 if {[info exists colormap($x)]
1608 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1609 lappend badcolors $colormap($x)
1612 if {[llength $badcolors] >= $ncolors} {
1613 set badcolors $origbad
1616 set origbad $badcolors
1618 if {[llength $badcolors] < $ncolors - 1} {
1619 foreach child $kids {
1620 if {[info exists colormap($child)]
1621 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1622 lappend badcolors $colormap($child)
1624 foreach p [lindex $parentlist $commitrow($child)] {
1625 if {[info exists colormap($p)]
1626 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1627 lappend badcolors $colormap($p)
1631 if {[llength $badcolors] >= $ncolors} {
1632 set badcolors $origbad
1635 for {set i 0} {$i <= $ncolors} {incr i} {
1636 set c [lindex $colors $nextcolor]
1637 if {[incr nextcolor] >= $ncolors} {
1640 if {[lsearch -exact $badcolors $c]} break
1642 set colormap($id) $c
1645 proc bindline {t id} {
1648 $canv bind $t <Enter> "lineenter %x %y $id"
1649 $canv bind $t <Motion> "linemotion %x %y $id"
1650 $canv bind $t <Leave> "lineleave $id"
1651 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1654 proc drawtags {id x xt y1} {
1655 global idtags idheads idotherrefs
1656 global linespc lthickness
1657 global canv mainfont commitrow rowtextx
1662 if {[info exists idtags($id)]} {
1663 set marks $idtags($id)
1664 set ntags [llength $marks]
1666 if {[info exists idheads($id)]} {
1667 set marks [concat $marks $idheads($id)]
1668 set nheads [llength $idheads($id)]
1670 if {[info exists idotherrefs($id)]} {
1671 set marks [concat $marks $idotherrefs($id)]
1677 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1678 set yt [expr {$y1 - 0.5 * $linespc}]
1679 set yb [expr {$yt + $linespc - 1}]
1682 foreach tag $marks {
1683 set wid [font measure $mainfont $tag]
1686 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1688 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1689 -width $lthickness -fill black -tags tag.$id]
1691 foreach tag $marks x $xvals wid $wvals {
1692 set xl [expr {$x + $delta}]
1693 set xr [expr {$x + $delta + $wid + $lthickness}]
1694 if {[incr ntags -1] >= 0} {
1696 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
1697 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
1698 -width 1 -outline black -fill yellow -tags tag.$id]
1699 $canv bind $t <1> [list showtag $tag 1]
1700 set rowtextx($commitrow($id)) [expr {$xr + $linespc}]
1702 # draw a head or other ref
1703 if {[incr nheads -1] >= 0} {
1708 set xl [expr {$xl - $delta/2}]
1709 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1710 -width 1 -outline black -fill $col -tags tag.$id
1711 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
1712 set rwid [font measure $mainfont $remoteprefix]
1713 set xi [expr {$x + 1}]
1714 set yti [expr {$yt + 1}]
1715 set xri [expr {$x + $rwid}]
1716 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
1717 -width 0 -fill "#ffddaa" -tags tag.$id
1720 set t [$canv create text $xl $y1 -anchor w -text $tag \
1721 -font $mainfont -tags tag.$id]
1723 $canv bind $t <1> [list showtag $tag 1]
1729 proc checkcrossings {row endrow} {
1730 global displayorder parentlist rowidlist
1732 for {} {$row < $endrow} {incr row} {
1733 set id [lindex $displayorder $row]
1734 set i [lsearch -exact [lindex $rowidlist $row] $id]
1735 if {$i < 0} continue
1736 set idlist [lindex $rowidlist [expr {$row+1}]]
1737 foreach p [lindex $parentlist $row] {
1738 set j [lsearch -exact $idlist $p]
1741 notecrossings $row $p $j $i [expr {$j+1}]
1742 } elseif {$j > $i + 1} {
1743 notecrossings $row $p $i $j [expr {$j-1}]
1750 proc notecrossings {row id lo hi corner} {
1751 global rowidlist crossings cornercrossings
1753 for {set i $lo} {[incr i] < $hi} {} {
1754 set p [lindex [lindex $rowidlist $row] $i]
1755 if {$p == {}} continue
1756 if {$i == $corner} {
1757 if {![info exists cornercrossings($id)]
1758 || [lsearch -exact $cornercrossings($id) $p] < 0} {
1759 lappend cornercrossings($id) $p
1761 if {![info exists cornercrossings($p)]
1762 || [lsearch -exact $cornercrossings($p) $id] < 0} {
1763 lappend cornercrossings($p) $id
1766 if {![info exists crossings($id)]
1767 || [lsearch -exact $crossings($id) $p] < 0} {
1768 lappend crossings($id) $p
1770 if {![info exists crossings($p)]
1771 || [lsearch -exact $crossings($p) $id] < 0} {
1772 lappend crossings($p) $id
1778 proc xcoord {i level ln} {
1779 global canvx0 xspc1 xspc2
1781 set x [expr {$canvx0 + $i * $xspc1($ln)}]
1782 if {$i > 0 && $i == $level} {
1783 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
1784 } elseif {$i > $level} {
1785 set x [expr {$x + $xspc2 - $xspc1($ln)}]
1790 proc finishcommits {} {
1791 global commitidx phase
1792 global canv mainfont ctext maincursor textcursor
1793 global findinprogress
1795 if {$commitidx > 0} {
1799 $canv create text 3 3 -anchor nw -text "No commits selected" \
1800 -font $mainfont -tags textitems
1802 if {![info exists findinprogress]} {
1803 . config -cursor $maincursor
1804 settextcursor $textcursor
1809 # Don't change the text pane cursor if it is currently the hand cursor,
1810 # showing that we are over a sha1 ID link.
1811 proc settextcursor {c} {
1812 global ctext curtextcursor
1814 if {[$ctext cget -cursor] == $curtextcursor} {
1815 $ctext config -cursor $c
1817 set curtextcursor $c
1823 global canvy0 numcommits linespc
1824 global rowlaidout commitidx
1827 layoutrows $rowlaidout $commitidx 1
1829 optimize_rows $row 0 $commitidx
1830 showstuff $commitidx
1832 set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
1833 #puts "overall $drawmsecs ms for $numcommits commits"
1836 proc findmatches {f} {
1837 global findtype foundstring foundstrlen
1838 if {$findtype == "Regexp"} {
1839 set matches [regexp -indices -all -inline $foundstring $f]
1841 if {$findtype == "IgnCase"} {
1842 set str [string tolower $f]
1848 while {[set j [string first $foundstring $str $i]] >= 0} {
1849 lappend matches [list $j [expr {$j+$foundstrlen-1}]]
1850 set i [expr {$j + $foundstrlen}]
1857 global findtype findloc findstring markedmatches commitinfo
1858 global numcommits displayorder linehtag linentag linedtag
1859 global mainfont namefont canv canv2 canv3 selectedline
1860 global matchinglines foundstring foundstrlen matchstring
1866 set matchinglines {}
1867 if {$findloc == "Pickaxe"} {
1871 if {$findtype == "IgnCase"} {
1872 set foundstring [string tolower $findstring]
1874 set foundstring $findstring
1876 set foundstrlen [string length $findstring]
1877 if {$foundstrlen == 0} return
1878 regsub -all {[*?\[\\]} $foundstring {\\&} matchstring
1879 set matchstring "*$matchstring*"
1880 if {$findloc == "Files"} {
1884 if {![info exists selectedline]} {
1887 set oldsel $selectedline
1890 set fldtypes {Headline Author Date Committer CDate Comment}
1892 foreach id $displayorder {
1893 set d $commitdata($id)
1895 if {$findtype == "Regexp"} {
1896 set doesmatch [regexp $foundstring $d]
1897 } elseif {$findtype == "IgnCase"} {
1898 set doesmatch [string match -nocase $matchstring $d]
1900 set doesmatch [string match $matchstring $d]
1902 if {!$doesmatch} continue
1903 if {![info exists commitinfo($id)]} {
1906 set info $commitinfo($id)
1908 foreach f $info ty $fldtypes {
1909 if {$findloc != "All fields" && $findloc != $ty} {
1912 set matches [findmatches $f]
1913 if {$matches == {}} continue
1915 if {$ty == "Headline"} {
1917 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1918 } elseif {$ty == "Author"} {
1920 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1921 } elseif {$ty == "Date"} {
1923 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1927 lappend matchinglines $l
1928 if {!$didsel && $l > $oldsel} {
1934 if {$matchinglines == {}} {
1936 } elseif {!$didsel} {
1937 findselectline [lindex $matchinglines 0]
1941 proc findselectline {l} {
1942 global findloc commentend ctext
1944 if {$findloc == "All fields" || $findloc == "Comments"} {
1945 # highlight the matches in the comments
1946 set f [$ctext get 1.0 $commentend]
1947 set matches [findmatches $f]
1948 foreach match $matches {
1949 set start [lindex $match 0]
1950 set end [expr {[lindex $match 1] + 1}]
1951 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1956 proc findnext {restart} {
1957 global matchinglines selectedline
1958 if {![info exists matchinglines]} {
1964 if {![info exists selectedline]} return
1965 foreach l $matchinglines {
1966 if {$l > $selectedline} {
1975 global matchinglines selectedline
1976 if {![info exists matchinglines]} {
1980 if {![info exists selectedline]} return
1982 foreach l $matchinglines {
1983 if {$l >= $selectedline} break
1987 findselectline $prev
1993 proc findlocchange {name ix op} {
1994 global findloc findtype findtypemenu
1995 if {$findloc == "Pickaxe"} {
2001 $findtypemenu entryconf 1 -state $state
2002 $findtypemenu entryconf 2 -state $state
2005 proc stopfindproc {{done 0}} {
2006 global findprocpid findprocfile findids
2007 global ctext findoldcursor phase maincursor textcursor
2008 global findinprogress
2010 catch {unset findids}
2011 if {[info exists findprocpid]} {
2013 catch {exec kill $findprocpid}
2015 catch {close $findprocfile}
2018 if {[info exists findinprogress]} {
2019 unset findinprogress
2020 if {$phase != "incrdraw"} {
2021 . config -cursor $maincursor
2022 settextcursor $textcursor
2027 proc findpatches {} {
2028 global findstring selectedline numcommits
2029 global findprocpid findprocfile
2030 global finddidsel ctext displayorder findinprogress
2031 global findinsertpos
2033 if {$numcommits == 0} return
2035 # make a list of all the ids to search, starting at the one
2036 # after the selected line (if any)
2037 if {[info exists selectedline]} {
2043 for {set i 0} {$i < $numcommits} {incr i} {
2044 if {[incr l] >= $numcommits} {
2047 append inputids [lindex $displayorder $l] "\n"
2051 set f [open [list | git-diff-tree --stdin -s -r -S$findstring \
2054 error_popup "Error starting search process: $err"
2058 set findinsertpos end
2060 set findprocpid [pid $f]
2061 fconfigure $f -blocking 0
2062 fileevent $f readable readfindproc
2064 . config -cursor watch
2066 set findinprogress 1
2069 proc readfindproc {} {
2070 global findprocfile finddidsel
2071 global commitrow matchinglines findinsertpos
2073 set n [gets $findprocfile line]
2075 if {[eof $findprocfile]} {
2083 if {![regexp {^[0-9a-f]{40}} $line id]} {
2084 error_popup "Can't parse git-diff-tree output: $line"
2088 if {![info exists commitrow($id)]} {
2089 puts stderr "spurious id: $id"
2092 set l $commitrow($id)
2096 proc insertmatch {l id} {
2097 global matchinglines findinsertpos finddidsel
2099 if {$findinsertpos == "end"} {
2100 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
2101 set matchinglines [linsert $matchinglines 0 $l]
2104 lappend matchinglines $l
2107 set matchinglines [linsert $matchinglines $findinsertpos $l]
2118 global selectedline numcommits displayorder ctext
2119 global ffileline finddidsel parentlist
2120 global findinprogress findstartline findinsertpos
2121 global treediffs fdiffid fdiffsneeded fdiffpos
2122 global findmergefiles
2124 if {$numcommits == 0} return
2126 if {[info exists selectedline]} {
2127 set l [expr {$selectedline + 1}]
2132 set findstartline $l
2136 set id [lindex $displayorder $l]
2137 if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2138 if {![info exists treediffs($id)]} {
2139 append diffsneeded "$id\n"
2140 lappend fdiffsneeded $id
2143 if {[incr l] >= $numcommits} {
2146 if {$l == $findstartline} break
2149 # start off a git-diff-tree process if needed
2150 if {$diffsneeded ne {}} {
2152 set df [open [list | git-diff-tree -r --stdin << $diffsneeded] r]
2154 error_popup "Error starting search process: $err"
2157 catch {unset fdiffid}
2159 fconfigure $df -blocking 0
2160 fileevent $df readable [list readfilediffs $df]
2164 set findinsertpos end
2165 set id [lindex $displayorder $l]
2166 . config -cursor watch
2168 set findinprogress 1
2173 proc readfilediffs {df} {
2174 global findid fdiffid fdiffs
2176 set n [gets $df line]
2180 if {[catch {close $df} err]} {
2183 error_popup "Error in git-diff-tree: $err"
2184 } elseif {[info exists findid]} {
2188 error_popup "Couldn't find diffs for $id"
2193 if {[regexp {^([0-9a-f]{40})$} $line match id]} {
2194 # start of a new string of diffs
2198 } elseif {[string match ":*" $line]} {
2199 lappend fdiffs [lindex $line 5]
2203 proc donefilediff {} {
2204 global fdiffid fdiffs treediffs findid
2205 global fdiffsneeded fdiffpos
2207 if {[info exists fdiffid]} {
2208 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffid
2209 && $fdiffpos < [llength $fdiffsneeded]} {
2210 # git-diff-tree doesn't output anything for a commit
2211 # which doesn't change anything
2212 set nullid [lindex $fdiffsneeded $fdiffpos]
2213 set treediffs($nullid) {}
2214 if {[info exists findid] && $nullid eq $findid} {
2222 if {![info exists treediffs($fdiffid)]} {
2223 set treediffs($fdiffid) $fdiffs
2225 if {[info exists findid] && $fdiffid eq $findid} {
2233 global findid treediffs parentlist
2234 global ffileline findstartline finddidsel
2235 global displayorder numcommits matchinglines findinprogress
2236 global findmergefiles
2240 set id [lindex $displayorder $l]
2241 if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2242 if {![info exists treediffs($id)]} {
2248 foreach f $treediffs($id) {
2249 set x [findmatches $f]
2259 if {[incr l] >= $numcommits} {
2262 if {$l == $findstartline} break
2270 # mark a commit as matching by putting a yellow background
2271 # behind the headline
2272 proc markheadline {l id} {
2273 global canv mainfont linehtag
2276 set bbox [$canv bbox $linehtag($l)]
2277 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2281 # mark the bits of a headline, author or date that match a find string
2282 proc markmatches {canv l str tag matches font} {
2283 set bbox [$canv bbox $tag]
2284 set x0 [lindex $bbox 0]
2285 set y0 [lindex $bbox 1]
2286 set y1 [lindex $bbox 3]
2287 foreach match $matches {
2288 set start [lindex $match 0]
2289 set end [lindex $match 1]
2290 if {$start > $end} continue
2291 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
2292 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
2293 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
2294 [expr {$x0+$xlen+2}] $y1 \
2295 -outline {} -tags matches -fill yellow]
2300 proc unmarkmatches {} {
2301 global matchinglines findids
2302 allcanvs delete matches
2303 catch {unset matchinglines}
2304 catch {unset findids}
2307 proc selcanvline {w x y} {
2308 global canv canvy0 ctext linespc
2310 set ymax [lindex [$canv cget -scrollregion] 3]
2311 if {$ymax == {}} return
2312 set yfrac [lindex [$canv yview] 0]
2313 set y [expr {$y + $yfrac * $ymax}]
2314 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2319 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2325 proc commit_descriptor {p} {
2328 if {[info exists commitinfo($p)]} {
2329 set l [lindex $commitinfo($p) 0]
2334 # append some text to the ctext widget, and make any SHA1 ID
2335 # that we know about be a clickable link.
2336 proc appendwithlinks {text} {
2337 global ctext commitrow linknum
2339 set start [$ctext index "end - 1c"]
2340 $ctext insert end $text
2341 $ctext insert end "\n"
2342 set links [regexp -indices -all -inline {[0-9a-f]{40}} $text]
2346 set linkid [string range $text $s $e]
2347 if {![info exists commitrow($linkid)]} continue
2349 $ctext tag add link "$start + $s c" "$start + $e c"
2350 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2351 $ctext tag bind link$linknum <1> [list selectline $commitrow($linkid) 1]
2354 $ctext tag conf link -foreground blue -underline 1
2355 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2356 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2359 proc viewnextline {dir} {
2363 set ymax [lindex [$canv cget -scrollregion] 3]
2364 set wnow [$canv yview]
2365 set wtop [expr {[lindex $wnow 0] * $ymax}]
2366 set newtop [expr {$wtop + $dir * $linespc}]
2369 } elseif {$newtop > $ymax} {
2372 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2375 proc selectline {l isnew} {
2376 global canv canv2 canv3 ctext commitinfo selectedline
2377 global displayorder linehtag linentag linedtag
2378 global canvy0 linespc parentlist childlist
2379 global cflist currentid sha1entry
2380 global commentend idtags linknum
2381 global mergemax numcommits
2385 if {$l < 0 || $l >= $numcommits} return
2386 set y [expr {$canvy0 + $l * $linespc}]
2387 set ymax [lindex [$canv cget -scrollregion] 3]
2388 set ytop [expr {$y - $linespc - 1}]
2389 set ybot [expr {$y + $linespc + 1}]
2390 set wnow [$canv yview]
2391 set wtop [expr {[lindex $wnow 0] * $ymax}]
2392 set wbot [expr {[lindex $wnow 1] * $ymax}]
2393 set wh [expr {$wbot - $wtop}]
2395 if {$ytop < $wtop} {
2396 if {$ybot < $wtop} {
2397 set newtop [expr {$y - $wh / 2.0}]
2400 if {$newtop > $wtop - $linespc} {
2401 set newtop [expr {$wtop - $linespc}]
2404 } elseif {$ybot > $wbot} {
2405 if {$ytop > $wbot} {
2406 set newtop [expr {$y - $wh / 2.0}]
2408 set newtop [expr {$ybot - $wh}]
2409 if {$newtop < $wtop + $linespc} {
2410 set newtop [expr {$wtop + $linespc}]
2414 if {$newtop != $wtop} {
2418 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2422 if {![info exists linehtag($l)]} return
2424 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2425 -tags secsel -fill [$canv cget -selectbackground]]
2427 $canv2 delete secsel
2428 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2429 -tags secsel -fill [$canv2 cget -selectbackground]]
2431 $canv3 delete secsel
2432 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2433 -tags secsel -fill [$canv3 cget -selectbackground]]
2437 addtohistory [list selectline $l 0]
2442 set id [lindex $displayorder $l]
2444 $sha1entry delete 0 end
2445 $sha1entry insert 0 $id
2446 $sha1entry selection from 0
2447 $sha1entry selection to end
2449 $ctext conf -state normal
2450 $ctext delete 0.0 end
2452 $ctext mark set fmark.0 0.0
2453 $ctext mark gravity fmark.0 left
2454 set info $commitinfo($id)
2455 set date [formatdate [lindex $info 2]]
2456 $ctext insert end "Author: [lindex $info 1] $date\n"
2457 set date [formatdate [lindex $info 4]]
2458 $ctext insert end "Committer: [lindex $info 3] $date\n"
2459 if {[info exists idtags($id)]} {
2460 $ctext insert end "Tags:"
2461 foreach tag $idtags($id) {
2462 $ctext insert end " $tag"
2464 $ctext insert end "\n"
2468 set olds [lindex $parentlist $l]
2469 if {[llength $olds] > 1} {
2472 if {$np >= $mergemax} {
2477 $ctext insert end "Parent: " $tag
2478 appendwithlinks [commit_descriptor $p]
2483 append comment "Parent: [commit_descriptor $p]\n"
2487 foreach c [lindex $childlist $l] {
2488 append comment "Child: [commit_descriptor $c]\n"
2491 append comment [lindex $info 5]
2493 # make anything that looks like a SHA1 ID be a clickable link
2494 appendwithlinks $comment
2496 $ctext tag delete Comments
2497 $ctext tag remove found 1.0 end
2498 $ctext conf -state disabled
2499 set commentend [$ctext index "end - 1c"]
2501 $cflist delete 0 end
2502 $cflist insert end "Comments"
2503 if {[llength $olds] <= 1} {
2510 proc selfirstline {} {
2515 proc sellastline {} {
2518 set l [expr {$numcommits - 1}]
2522 proc selnextline {dir} {
2524 if {![info exists selectedline]} return
2525 set l [expr {$selectedline + $dir}]
2530 proc selnextpage {dir} {
2531 global canv linespc selectedline numcommits
2533 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
2537 allcanvs yview scroll [expr {$dir * $lpp}] units
2538 if {![info exists selectedline]} return
2539 set l [expr {$selectedline + $dir * $lpp}]
2542 } elseif {$l >= $numcommits} {
2543 set l [expr $numcommits - 1]
2549 proc unselectline {} {
2552 catch {unset selectedline}
2553 allcanvs delete secsel
2556 proc addtohistory {cmd} {
2557 global history historyindex
2559 if {$historyindex > 0
2560 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2564 if {$historyindex < [llength $history]} {
2565 set history [lreplace $history $historyindex end $cmd]
2567 lappend history $cmd
2570 if {$historyindex > 1} {
2571 .ctop.top.bar.leftbut conf -state normal
2573 .ctop.top.bar.leftbut conf -state disabled
2575 .ctop.top.bar.rightbut conf -state disabled
2579 global history historyindex
2581 if {$historyindex > 1} {
2582 incr historyindex -1
2583 set cmd [lindex $history [expr {$historyindex - 1}]]
2585 .ctop.top.bar.rightbut conf -state normal
2587 if {$historyindex <= 1} {
2588 .ctop.top.bar.leftbut conf -state disabled
2593 global history historyindex
2595 if {$historyindex < [llength $history]} {
2596 set cmd [lindex $history $historyindex]
2599 .ctop.top.bar.leftbut conf -state normal
2601 if {$historyindex >= [llength $history]} {
2602 .ctop.top.bar.rightbut conf -state disabled
2606 proc mergediff {id l} {
2607 global diffmergeid diffopts mdifffd
2608 global difffilestart diffids
2613 catch {unset difffilestart}
2614 # this doesn't seem to actually affect anything...
2615 set env(GIT_DIFF_OPTS) $diffopts
2616 set cmd [concat | git-diff-tree --no-commit-id --cc $id]
2617 if {[catch {set mdf [open $cmd r]} err]} {
2618 error_popup "Error getting merge diffs: $err"
2621 fconfigure $mdf -blocking 0
2622 set mdifffd($id) $mdf
2623 set np [llength [lindex $parentlist $l]]
2624 fileevent $mdf readable [list getmergediffline $mdf $id $np]
2625 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2628 proc getmergediffline {mdf id np} {
2629 global diffmergeid ctext cflist nextupdate mergemax
2630 global difffilestart mdifffd
2632 set n [gets $mdf line]
2639 if {![info exists diffmergeid] || $id != $diffmergeid
2640 || $mdf != $mdifffd($id)} {
2643 $ctext conf -state normal
2644 if {[regexp {^diff --cc (.*)} $line match fname]} {
2645 # start of a new file
2646 $ctext insert end "\n"
2647 set here [$ctext index "end - 1c"]
2648 set i [$cflist index end]
2649 $ctext mark set fmark.$i $here
2650 $ctext mark gravity fmark.$i left
2651 set difffilestart([expr {$i-1}]) $here
2652 $cflist insert end $fname
2653 set l [expr {(78 - [string length $fname]) / 2}]
2654 set pad [string range "----------------------------------------" 1 $l]
2655 $ctext insert end "$pad $fname $pad\n" filesep
2656 } elseif {[regexp {^@@} $line]} {
2657 $ctext insert end "$line\n" hunksep
2658 } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
2661 # parse the prefix - one ' ', '-' or '+' for each parent
2666 for {set j 0} {$j < $np} {incr j} {
2667 set c [string range $line $j $j]
2670 } elseif {$c == "-"} {
2672 } elseif {$c == "+"} {
2681 if {!$isbad && $minuses ne {} && $pluses eq {}} {
2682 # line doesn't appear in result, parents in $minuses have the line
2683 set num [lindex $minuses 0]
2684 } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
2685 # line appears in result, parents in $pluses don't have the line
2686 lappend tags mresult
2687 set num [lindex $spaces 0]
2690 if {$num >= $mergemax} {
2695 $ctext insert end "$line\n" $tags
2697 $ctext conf -state disabled
2698 if {[clock clicks -milliseconds] >= $nextupdate} {
2700 fileevent $mdf readable {}
2702 fileevent $mdf readable [list getmergediffline $mdf $id $np]
2706 proc startdiff {ids} {
2707 global treediffs diffids treepending diffmergeid
2710 catch {unset diffmergeid}
2711 if {![info exists treediffs($ids)]} {
2712 if {![info exists treepending]} {
2720 proc addtocflist {ids} {
2721 global treediffs cflist
2722 foreach f $treediffs($ids) {
2723 $cflist insert end $f
2728 proc gettreediffs {ids} {
2729 global treediff treepending
2730 set treepending $ids
2733 {set gdtf [open [concat | git-diff-tree --no-commit-id -r $ids] r]} \
2735 fconfigure $gdtf -blocking 0
2736 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
2739 proc gettreediffline {gdtf ids} {
2740 global treediff treediffs treepending diffids diffmergeid
2742 set n [gets $gdtf line]
2744 if {![eof $gdtf]} return
2746 set treediffs($ids) $treediff
2748 if {$ids != $diffids} {
2749 if {![info exists diffmergeid]} {
2750 gettreediffs $diffids
2757 set file [lindex $line 5]
2758 lappend treediff $file
2761 proc getblobdiffs {ids} {
2762 global diffopts blobdifffd diffids env curdifftag curtagstart
2763 global difffilestart nextupdate diffinhdr treediffs
2765 set env(GIT_DIFF_OPTS) $diffopts
2766 set cmd [concat | git-diff-tree --no-commit-id -r -p -C $ids]
2767 if {[catch {set bdf [open $cmd r]} err]} {
2768 puts "error getting diffs: $err"
2772 fconfigure $bdf -blocking 0
2773 set blobdifffd($ids) $bdf
2774 set curdifftag Comments
2776 catch {unset difffilestart}
2777 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
2778 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2781 proc getblobdiffline {bdf ids} {
2782 global diffids blobdifffd ctext curdifftag curtagstart
2783 global diffnexthead diffnextnote difffilestart
2784 global nextupdate diffinhdr treediffs
2786 set n [gets $bdf line]
2790 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
2791 $ctext tag add $curdifftag $curtagstart end
2796 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
2799 $ctext conf -state normal
2800 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
2801 # start of a new file
2802 $ctext insert end "\n"
2803 $ctext tag add $curdifftag $curtagstart end
2804 set curtagstart [$ctext index "end - 1c"]
2806 set here [$ctext index "end - 1c"]
2807 set i [lsearch -exact $treediffs($diffids) $fname]
2809 set difffilestart($i) $here
2811 $ctext mark set fmark.$i $here
2812 $ctext mark gravity fmark.$i left
2814 if {$newname != $fname} {
2815 set i [lsearch -exact $treediffs($diffids) $newname]
2817 set difffilestart($i) $here
2819 $ctext mark set fmark.$i $here
2820 $ctext mark gravity fmark.$i left
2823 set curdifftag "f:$fname"
2824 $ctext tag delete $curdifftag
2825 set l [expr {(78 - [string length $header]) / 2}]
2826 set pad [string range "----------------------------------------" 1 $l]
2827 $ctext insert end "$pad $header $pad\n" filesep
2829 } elseif {$diffinhdr && [string compare -length 3 $line "---"] == 0} {
2831 } elseif {$diffinhdr && [string compare -length 3 $line "+++"] == 0} {
2833 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2834 $line match f1l f1c f2l f2c rest]} {
2835 $ctext insert end "$line\n" hunksep
2838 set x [string range $line 0 0]
2839 if {$x == "-" || $x == "+"} {
2840 set tag [expr {$x == "+"}]
2841 $ctext insert end "$line\n" d$tag
2842 } elseif {$x == " "} {
2843 $ctext insert end "$line\n"
2844 } elseif {$diffinhdr || $x == "\\"} {
2845 # e.g. "\ No newline at end of file"
2846 $ctext insert end "$line\n" filesep
2848 # Something else we don't recognize
2849 if {$curdifftag != "Comments"} {
2850 $ctext insert end "\n"
2851 $ctext tag add $curdifftag $curtagstart end
2852 set curtagstart [$ctext index "end - 1c"]
2853 set curdifftag Comments
2855 $ctext insert end "$line\n" filesep
2858 $ctext conf -state disabled
2859 if {[clock clicks -milliseconds] >= $nextupdate} {
2861 fileevent $bdf readable {}
2863 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
2868 global difffilestart ctext
2869 set here [$ctext index @0,0]
2870 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
2871 if {[$ctext compare $difffilestart($i) > $here]} {
2872 if {![info exists pos]
2873 || [$ctext compare $difffilestart($i) < $pos]} {
2874 set pos $difffilestart($i)
2878 if {[info exists pos]} {
2883 proc listboxsel {} {
2884 global ctext cflist currentid
2885 if {![info exists currentid]} return
2886 set sel [lsort [$cflist curselection]]
2887 if {$sel eq {}} return
2888 set first [lindex $sel 0]
2889 catch {$ctext yview fmark.$first}
2893 global linespc charspc canvx0 canvy0 mainfont
2894 global xspc1 xspc2 lthickness
2896 set linespc [font metrics $mainfont -linespace]
2897 set charspc [font measure $mainfont "m"]
2898 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
2899 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
2900 set lthickness [expr {int($linespc / 9) + 1}]
2901 set xspc1(0) $linespc
2909 set ymax [lindex [$canv cget -scrollregion] 3]
2910 if {$ymax eq {} || $ymax == 0} return
2911 set span [$canv yview]
2914 allcanvs yview moveto [lindex $span 0]
2916 if {[info exists selectedline]} {
2917 selectline $selectedline 0
2921 proc incrfont {inc} {
2922 global mainfont namefont textfont ctext canv phase
2923 global stopped entries
2925 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
2926 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
2927 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
2929 $ctext conf -font $textfont
2930 $ctext tag conf filesep -font [concat $textfont bold]
2931 foreach e $entries {
2932 $e conf -font $mainfont
2934 if {$phase == "getcommits"} {
2935 $canv itemconf textitems -font $mainfont
2941 global sha1entry sha1string
2942 if {[string length $sha1string] == 40} {
2943 $sha1entry delete 0 end
2947 proc sha1change {n1 n2 op} {
2948 global sha1string currentid sha1but
2949 if {$sha1string == {}
2950 || ([info exists currentid] && $sha1string == $currentid)} {
2955 if {[$sha1but cget -state] == $state} return
2956 if {$state == "normal"} {
2957 $sha1but conf -state normal -relief raised -text "Goto: "
2959 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
2963 proc gotocommit {} {
2964 global sha1string currentid commitrow tagids headids
2965 global displayorder numcommits
2967 if {$sha1string == {}
2968 || ([info exists currentid] && $sha1string == $currentid)} return
2969 if {[info exists tagids($sha1string)]} {
2970 set id $tagids($sha1string)
2971 } elseif {[info exists headids($sha1string)]} {
2972 set id $headids($sha1string)
2974 set id [string tolower $sha1string]
2975 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
2977 foreach i $displayorder {
2978 if {[string match $id* $i]} {
2982 if {$matches ne {}} {
2983 if {[llength $matches] > 1} {
2984 error_popup "Short SHA1 id $id is ambiguous"
2987 set id [lindex $matches 0]
2991 if {[info exists commitrow($id)]} {
2992 selectline $commitrow($id) 1
2995 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3000 error_popup "$type $sha1string is not known"
3003 proc lineenter {x y id} {
3004 global hoverx hovery hoverid hovertimer
3005 global commitinfo canv
3007 if {![info exists commitinfo($id)] && ![getcommit $id]} return
3011 if {[info exists hovertimer]} {
3012 after cancel $hovertimer
3014 set hovertimer [after 500 linehover]
3018 proc linemotion {x y id} {
3019 global hoverx hovery hoverid hovertimer
3021 if {[info exists hoverid] && $id == $hoverid} {
3024 if {[info exists hovertimer]} {
3025 after cancel $hovertimer
3027 set hovertimer [after 500 linehover]
3031 proc lineleave {id} {
3032 global hoverid hovertimer canv
3034 if {[info exists hoverid] && $id == $hoverid} {
3036 if {[info exists hovertimer]} {
3037 after cancel $hovertimer
3045 global hoverx hovery hoverid hovertimer
3046 global canv linespc lthickness
3047 global commitinfo mainfont
3049 set text [lindex $commitinfo($hoverid) 0]
3050 set ymax [lindex [$canv cget -scrollregion] 3]
3051 if {$ymax == {}} return
3052 set yfrac [lindex [$canv yview] 0]
3053 set x [expr {$hoverx + 2 * $linespc}]
3054 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3055 set x0 [expr {$x - 2 * $lthickness}]
3056 set y0 [expr {$y - 2 * $lthickness}]
3057 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3058 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3059 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3060 -fill \#ffff80 -outline black -width 1 -tags hover]
3062 set t [$canv create text $x $y -anchor nw -text $text -tags hover -font $mainfont]
3066 proc clickisonarrow {id y} {
3067 global lthickness idrowranges
3069 set thresh [expr {2 * $lthickness + 6}]
3070 set n [expr {[llength $idrowranges($id)] - 1}]
3071 for {set i 1} {$i < $n} {incr i} {
3072 set row [lindex $idrowranges($id) $i]
3073 if {abs([yc $row] - $y) < $thresh} {
3080 proc arrowjump {id n y} {
3081 global idrowranges canv
3083 # 1 <-> 2, 3 <-> 4, etc...
3084 set n [expr {(($n - 1) ^ 1) + 1}]
3085 set row [lindex $idrowranges($id) $n]
3087 set ymax [lindex [$canv cget -scrollregion] 3]
3088 if {$ymax eq {} || $ymax <= 0} return
3089 set view [$canv yview]
3090 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3091 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3095 allcanvs yview moveto $yfrac
3098 proc lineclick {x y id isnew} {
3099 global ctext commitinfo childlist commitrow cflist canv thickerline
3101 if {![info exists commitinfo($id)] && ![getcommit $id]} return
3106 # draw this line thicker than normal
3110 set ymax [lindex [$canv cget -scrollregion] 3]
3111 if {$ymax eq {}} return
3112 set yfrac [lindex [$canv yview] 0]
3113 set y [expr {$y + $yfrac * $ymax}]
3115 set dirn [clickisonarrow $id $y]
3117 arrowjump $id $dirn $y
3122 addtohistory [list lineclick $x $y $id 0]
3124 # fill the details pane with info about this line
3125 $ctext conf -state normal
3126 $ctext delete 0.0 end
3127 $ctext tag conf link -foreground blue -underline 1
3128 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3129 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3130 $ctext insert end "Parent:\t"
3131 $ctext insert end $id [list link link0]
3132 $ctext tag bind link0 <1> [list selbyid $id]
3133 set info $commitinfo($id)
3134 $ctext insert end "\n\t[lindex $info 0]\n"
3135 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3136 set date [formatdate [lindex $info 2]]
3137 $ctext insert end "\tDate:\t$date\n"
3138 set kids [lindex $childlist $commitrow($id)]
3140 $ctext insert end "\nChildren:"
3142 foreach child $kids {
3144 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
3145 set info $commitinfo($child)
3146 $ctext insert end "\n\t"
3147 $ctext insert end $child [list link link$i]
3148 $ctext tag bind link$i <1> [list selbyid $child]
3149 $ctext insert end "\n\t[lindex $info 0]"
3150 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3151 set date [formatdate [lindex $info 2]]
3152 $ctext insert end "\n\tDate:\t$date\n"
3155 $ctext conf -state disabled
3157 $cflist delete 0 end
3160 proc normalline {} {
3162 if {[info exists thickerline]} {
3171 if {[info exists commitrow($id)]} {
3172 selectline $commitrow($id) 1
3178 if {![info exists startmstime]} {
3179 set startmstime [clock clicks -milliseconds]
3181 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3184 proc rowmenu {x y id} {
3185 global rowctxmenu commitrow selectedline rowmenuid
3187 if {![info exists selectedline] || $commitrow($id) eq $selectedline} {
3192 $rowctxmenu entryconfigure 0 -state $state
3193 $rowctxmenu entryconfigure 1 -state $state
3194 $rowctxmenu entryconfigure 2 -state $state
3196 tk_popup $rowctxmenu $x $y
3199 proc diffvssel {dirn} {
3200 global rowmenuid selectedline displayorder
3202 if {![info exists selectedline]} return
3204 set oldid [lindex $displayorder $selectedline]
3205 set newid $rowmenuid
3207 set oldid $rowmenuid
3208 set newid [lindex $displayorder $selectedline]
3210 addtohistory [list doseldiff $oldid $newid]
3211 doseldiff $oldid $newid
3214 proc doseldiff {oldid newid} {
3218 $ctext conf -state normal
3219 $ctext delete 0.0 end
3220 $ctext mark set fmark.0 0.0
3221 $ctext mark gravity fmark.0 left
3222 $cflist delete 0 end
3223 $cflist insert end "Top"
3224 $ctext insert end "From "
3225 $ctext tag conf link -foreground blue -underline 1
3226 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3227 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3228 $ctext tag bind link0 <1> [list selbyid $oldid]
3229 $ctext insert end $oldid [list link link0]
3230 $ctext insert end "\n "
3231 $ctext insert end [lindex $commitinfo($oldid) 0]
3232 $ctext insert end "\n\nTo "
3233 $ctext tag bind link1 <1> [list selbyid $newid]
3234 $ctext insert end $newid [list link link1]
3235 $ctext insert end "\n "
3236 $ctext insert end [lindex $commitinfo($newid) 0]
3237 $ctext insert end "\n"
3238 $ctext conf -state disabled
3239 $ctext tag delete Comments
3240 $ctext tag remove found 1.0 end
3241 startdiff [list $oldid $newid]
3245 global rowmenuid currentid commitinfo patchtop patchnum
3247 if {![info exists currentid]} return
3248 set oldid $currentid
3249 set oldhead [lindex $commitinfo($oldid) 0]
3250 set newid $rowmenuid
3251 set newhead [lindex $commitinfo($newid) 0]
3254 catch {destroy $top}
3256 label $top.title -text "Generate patch"
3257 grid $top.title - -pady 10
3258 label $top.from -text "From:"
3259 entry $top.fromsha1 -width 40 -relief flat
3260 $top.fromsha1 insert 0 $oldid
3261 $top.fromsha1 conf -state readonly
3262 grid $top.from $top.fromsha1 -sticky w
3263 entry $top.fromhead -width 60 -relief flat
3264 $top.fromhead insert 0 $oldhead
3265 $top.fromhead conf -state readonly
3266 grid x $top.fromhead -sticky w
3267 label $top.to -text "To:"
3268 entry $top.tosha1 -width 40 -relief flat
3269 $top.tosha1 insert 0 $newid
3270 $top.tosha1 conf -state readonly
3271 grid $top.to $top.tosha1 -sticky w
3272 entry $top.tohead -width 60 -relief flat
3273 $top.tohead insert 0 $newhead
3274 $top.tohead conf -state readonly
3275 grid x $top.tohead -sticky w
3276 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
3277 grid $top.rev x -pady 10
3278 label $top.flab -text "Output file:"
3279 entry $top.fname -width 60
3280 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3282 grid $top.flab $top.fname -sticky w
3284 button $top.buts.gen -text "Generate" -command mkpatchgo
3285 button $top.buts.can -text "Cancel" -command mkpatchcan
3286 grid $top.buts.gen $top.buts.can
3287 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3288 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3289 grid $top.buts - -pady 10 -sticky ew
3293 proc mkpatchrev {} {
3296 set oldid [$patchtop.fromsha1 get]
3297 set oldhead [$patchtop.fromhead get]
3298 set newid [$patchtop.tosha1 get]
3299 set newhead [$patchtop.tohead get]
3300 foreach e [list fromsha1 fromhead tosha1 tohead] \
3301 v [list $newid $newhead $oldid $oldhead] {
3302 $patchtop.$e conf -state normal
3303 $patchtop.$e delete 0 end
3304 $patchtop.$e insert 0 $v
3305 $patchtop.$e conf -state readonly
3312 set oldid [$patchtop.fromsha1 get]
3313 set newid [$patchtop.tosha1 get]
3314 set fname [$patchtop.fname get]
3315 if {[catch {exec git-diff-tree -p $oldid $newid >$fname &} err]} {
3316 error_popup "Error creating patch: $err"
3318 catch {destroy $patchtop}
3322 proc mkpatchcan {} {
3325 catch {destroy $patchtop}
3330 global rowmenuid mktagtop commitinfo
3334 catch {destroy $top}
3336 label $top.title -text "Create tag"
3337 grid $top.title - -pady 10
3338 label $top.id -text "ID:"
3339 entry $top.sha1 -width 40 -relief flat
3340 $top.sha1 insert 0 $rowmenuid
3341 $top.sha1 conf -state readonly
3342 grid $top.id $top.sha1 -sticky w
3343 entry $top.head -width 60 -relief flat
3344 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3345 $top.head conf -state readonly
3346 grid x $top.head -sticky w
3347 label $top.tlab -text "Tag name:"
3348 entry $top.tag -width 60
3349 grid $top.tlab $top.tag -sticky w
3351 button $top.buts.gen -text "Create" -command mktaggo
3352 button $top.buts.can -text "Cancel" -command mktagcan
3353 grid $top.buts.gen $top.buts.can
3354 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3355 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3356 grid $top.buts - -pady 10 -sticky ew
3361 global mktagtop env tagids idtags
3363 set id [$mktagtop.sha1 get]
3364 set tag [$mktagtop.tag get]
3366 error_popup "No tag name specified"
3369 if {[info exists tagids($tag)]} {
3370 error_popup "Tag \"$tag\" already exists"
3375 set fname [file join $dir "refs/tags" $tag]
3376 set f [open $fname w]
3380 error_popup "Error creating tag: $err"
3384 set tagids($tag) $id
3385 lappend idtags($id) $tag
3389 proc redrawtags {id} {
3390 global canv linehtag commitrow idpos selectedline
3392 if {![info exists commitrow($id)]} return
3393 drawcmitrow $commitrow($id)
3394 $canv delete tag.$id
3395 set xt [eval drawtags $id $idpos($id)]
3396 $canv coords $linehtag($commitrow($id)) $xt [lindex $idpos($id) 2]
3397 if {[info exists selectedline] && $selectedline == $commitrow($id)} {
3398 selectline $selectedline 0
3405 catch {destroy $mktagtop}
3414 proc writecommit {} {
3415 global rowmenuid wrcomtop commitinfo wrcomcmd
3417 set top .writecommit
3419 catch {destroy $top}
3421 label $top.title -text "Write commit to file"
3422 grid $top.title - -pady 10
3423 label $top.id -text "ID:"
3424 entry $top.sha1 -width 40 -relief flat
3425 $top.sha1 insert 0 $rowmenuid
3426 $top.sha1 conf -state readonly
3427 grid $top.id $top.sha1 -sticky w
3428 entry $top.head -width 60 -relief flat
3429 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3430 $top.head conf -state readonly
3431 grid x $top.head -sticky w
3432 label $top.clab -text "Command:"
3433 entry $top.cmd -width 60 -textvariable wrcomcmd
3434 grid $top.clab $top.cmd -sticky w -pady 10
3435 label $top.flab -text "Output file:"
3436 entry $top.fname -width 60
3437 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3438 grid $top.flab $top.fname -sticky w
3440 button $top.buts.gen -text "Write" -command wrcomgo
3441 button $top.buts.can -text "Cancel" -command wrcomcan
3442 grid $top.buts.gen $top.buts.can
3443 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3444 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3445 grid $top.buts - -pady 10 -sticky ew
3452 set id [$wrcomtop.sha1 get]
3453 set cmd "echo $id | [$wrcomtop.cmd get]"
3454 set fname [$wrcomtop.fname get]
3455 if {[catch {exec sh -c $cmd >$fname &} err]} {
3456 error_popup "Error writing commit: $err"
3458 catch {destroy $wrcomtop}
3465 catch {destroy $wrcomtop}
3469 proc listrefs {id} {
3470 global idtags idheads idotherrefs
3473 if {[info exists idtags($id)]} {
3477 if {[info exists idheads($id)]} {
3481 if {[info exists idotherrefs($id)]} {
3482 set z $idotherrefs($id)
3484 return [list $x $y $z]
3487 proc rereadrefs {} {
3488 global idtags idheads idotherrefs
3490 set refids [concat [array names idtags] \
3491 [array names idheads] [array names idotherrefs]]
3492 foreach id $refids {
3493 if {![info exists ref($id)]} {
3494 set ref($id) [listrefs $id]
3498 set refids [lsort -unique [concat $refids [array names idtags] \
3499 [array names idheads] [array names idotherrefs]]]
3500 foreach id $refids {
3501 set v [listrefs $id]
3502 if {![info exists ref($id)] || $ref($id) != $v} {
3508 proc showtag {tag isnew} {
3509 global ctext cflist tagcontents tagids linknum
3512 addtohistory [list showtag $tag 0]
3514 $ctext conf -state normal
3515 $ctext delete 0.0 end
3517 if {[info exists tagcontents($tag)]} {
3518 set text $tagcontents($tag)
3520 set text "Tag: $tag\nId: $tagids($tag)"
3522 appendwithlinks $text
3523 $ctext conf -state disabled
3524 $cflist delete 0 end
3534 global maxwidth maxgraphpct diffopts findmergefiles
3535 global oldprefs prefstop
3539 if {[winfo exists $top]} {
3543 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3544 set oldprefs($v) [set $v]
3547 wm title $top "Gitk preferences"
3548 label $top.ldisp -text "Commit list display options"
3549 grid $top.ldisp - -sticky w -pady 10
3550 label $top.spacer -text " "
3551 label $top.maxwidthl -text "Maximum graph width (lines)" \
3553 spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
3554 grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
3555 label $top.maxpctl -text "Maximum graph width (% of pane)" \
3557 spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
3558 grid x $top.maxpctl $top.maxpct -sticky w
3559 checkbutton $top.findm -variable findmergefiles
3560 label $top.findml -text "Include merges for \"Find\" in \"Files\"" \
3562 grid $top.findm $top.findml - -sticky w
3563 label $top.ddisp -text "Diff display options"
3564 grid $top.ddisp - -sticky w -pady 10
3565 label $top.diffoptl -text "Options for diff program" \
3567 entry $top.diffopt -width 20 -textvariable diffopts
3568 grid x $top.diffoptl $top.diffopt -sticky w
3570 button $top.buts.ok -text "OK" -command prefsok
3571 button $top.buts.can -text "Cancel" -command prefscan
3572 grid $top.buts.ok $top.buts.can
3573 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3574 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3575 grid $top.buts - - -pady 10 -sticky ew
3579 global maxwidth maxgraphpct diffopts findmergefiles
3580 global oldprefs prefstop
3582 foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3583 set $v $oldprefs($v)
3585 catch {destroy $prefstop}
3590 global maxwidth maxgraphpct
3591 global oldprefs prefstop
3593 catch {destroy $prefstop}
3595 if {$maxwidth != $oldprefs(maxwidth)
3596 || $maxgraphpct != $oldprefs(maxgraphpct)} {
3601 proc formatdate {d} {
3602 return [clock format $d -format "%Y-%m-%d %H:%M:%S"]
3605 # This list of encoding names and aliases is distilled from
3606 # http://www.iana.org/assignments/character-sets.
3607 # Not all of them are supported by Tcl.
3608 set encoding_aliases {
3609 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
3610 ISO646-US US-ASCII us IBM367 cp367 csASCII }
3611 { ISO-10646-UTF-1 csISO10646UTF1 }
3612 { ISO_646.basic:1983 ref csISO646basic1983 }
3613 { INVARIANT csINVARIANT }
3614 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
3615 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
3616 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
3617 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
3618 { NATS-DANO iso-ir-9-1 csNATSDANO }
3619 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
3620 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
3621 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
3622 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
3623 { ISO-2022-KR csISO2022KR }
3625 { ISO-2022-JP csISO2022JP }
3626 { ISO-2022-JP-2 csISO2022JP2 }
3627 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
3629 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
3630 { IT iso-ir-15 ISO646-IT csISO15Italian }
3631 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
3632 { ES iso-ir-17 ISO646-ES csISO17Spanish }
3633 { greek7-old iso-ir-18 csISO18Greek7Old }
3634 { latin-greek iso-ir-19 csISO19LatinGreek }
3635 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
3636 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
3637 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
3638 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
3639 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
3640 { BS_viewdata iso-ir-47 csISO47BSViewdata }
3641 { INIS iso-ir-49 csISO49INIS }
3642 { INIS-8 iso-ir-50 csISO50INIS8 }
3643 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
3644 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
3645 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
3646 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
3647 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
3648 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
3650 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
3651 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
3652 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
3653 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
3654 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
3655 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
3656 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
3657 { greek7 iso-ir-88 csISO88Greek7 }
3658 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
3659 { iso-ir-90 csISO90 }
3660 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
3661 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
3662 csISO92JISC62991984b }
3663 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
3664 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
3665 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
3666 csISO95JIS62291984handadd }
3667 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
3668 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
3669 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
3670 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
3672 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
3673 { T.61-7bit iso-ir-102 csISO102T617bit }
3674 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
3675 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
3676 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
3677 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
3678 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
3679 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
3680 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
3681 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
3682 arabic csISOLatinArabic }
3683 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
3684 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
3685 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
3686 greek greek8 csISOLatinGreek }
3687 { T.101-G2 iso-ir-128 csISO128T101G2 }
3688 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
3690 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
3691 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
3692 { CSN_369103 iso-ir-139 csISO139CSN369103 }
3693 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
3694 { ISO_6937-2-add iso-ir-142 csISOTextComm }
3695 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
3696 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
3697 csISOLatinCyrillic }
3698 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
3699 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
3700 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
3701 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
3702 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
3703 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
3704 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
3705 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
3706 { ISO_10367-box iso-ir-155 csISO10367Box }
3707 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
3708 { latin-lap lap iso-ir-158 csISO158Lap }
3709 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
3710 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
3713 { JIS_X0201 X0201 csHalfWidthKatakana }
3714 { KSC5636 ISO646-KR csKSC5636 }
3715 { ISO-10646-UCS-2 csUnicode }
3716 { ISO-10646-UCS-4 csUCS4 }
3717 { DEC-MCS dec csDECMCS }
3718 { hp-roman8 roman8 r8 csHPRoman8 }
3719 { macintosh mac csMacintosh }
3720 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
3722 { IBM038 EBCDIC-INT cp038 csIBM038 }
3723 { IBM273 CP273 csIBM273 }
3724 { IBM274 EBCDIC-BE CP274 csIBM274 }
3725 { IBM275 EBCDIC-BR cp275 csIBM275 }
3726 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
3727 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
3728 { IBM280 CP280 ebcdic-cp-it csIBM280 }
3729 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
3730 { IBM284 CP284 ebcdic-cp-es csIBM284 }
3731 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
3732 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
3733 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
3734 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
3735 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
3736 { IBM424 cp424 ebcdic-cp-he csIBM424 }
3737 { IBM437 cp437 437 csPC8CodePage437 }
3738 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
3739 { IBM775 cp775 csPC775Baltic }
3740 { IBM850 cp850 850 csPC850Multilingual }
3741 { IBM851 cp851 851 csIBM851 }
3742 { IBM852 cp852 852 csPCp852 }
3743 { IBM855 cp855 855 csIBM855 }
3744 { IBM857 cp857 857 csIBM857 }
3745 { IBM860 cp860 860 csIBM860 }
3746 { IBM861 cp861 861 cp-is csIBM861 }
3747 { IBM862 cp862 862 csPC862LatinHebrew }
3748 { IBM863 cp863 863 csIBM863 }
3749 { IBM864 cp864 csIBM864 }
3750 { IBM865 cp865 865 csIBM865 }
3751 { IBM866 cp866 866 csIBM866 }
3752 { IBM868 CP868 cp-ar csIBM868 }
3753 { IBM869 cp869 869 cp-gr csIBM869 }
3754 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
3755 { IBM871 CP871 ebcdic-cp-is csIBM871 }
3756 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
3757 { IBM891 cp891 csIBM891 }
3758 { IBM903 cp903 csIBM903 }
3759 { IBM904 cp904 904 csIBBM904 }
3760 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
3761 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
3762 { IBM1026 CP1026 csIBM1026 }
3763 { EBCDIC-AT-DE csIBMEBCDICATDE }
3764 { EBCDIC-AT-DE-A csEBCDICATDEA }
3765 { EBCDIC-CA-FR csEBCDICCAFR }
3766 { EBCDIC-DK-NO csEBCDICDKNO }
3767 { EBCDIC-DK-NO-A csEBCDICDKNOA }
3768 { EBCDIC-FI-SE csEBCDICFISE }
3769 { EBCDIC-FI-SE-A csEBCDICFISEA }
3770 { EBCDIC-FR csEBCDICFR }
3771 { EBCDIC-IT csEBCDICIT }
3772 { EBCDIC-PT csEBCDICPT }
3773 { EBCDIC-ES csEBCDICES }
3774 { EBCDIC-ES-A csEBCDICESA }
3775 { EBCDIC-ES-S csEBCDICESS }
3776 { EBCDIC-UK csEBCDICUK }
3777 { EBCDIC-US csEBCDICUS }
3778 { UNKNOWN-8BIT csUnknown8BiT }
3779 { MNEMONIC csMnemonic }
3784 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
3785 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
3786 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
3787 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
3788 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
3789 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
3790 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
3791 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
3792 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
3793 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
3794 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
3795 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
3796 { IBM1047 IBM-1047 }
3797 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
3798 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
3799 { UNICODE-1-1 csUnicode11 }
3802 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
3803 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
3805 { ISO-8859-15 ISO_8859-15 Latin-9 }
3806 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
3807 { GBK CP936 MS936 windows-936 }
3808 { JIS_Encoding csJISEncoding }
3809 { Shift_JIS MS_Kanji csShiftJIS }
3810 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
3812 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
3813 { ISO-10646-UCS-Basic csUnicodeASCII }
3814 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
3815 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
3816 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
3817 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
3818 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
3819 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
3820 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
3821 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
3822 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
3823 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
3824 { Adobe-Standard-Encoding csAdobeStandardEncoding }
3825 { Ventura-US csVenturaUS }
3826 { Ventura-International csVenturaInternational }
3827 { PC8-Danish-Norwegian csPC8DanishNorwegian }
3828 { PC8-Turkish csPC8Turkish }
3829 { IBM-Symbols csIBMSymbols }
3830 { IBM-Thai csIBMThai }
3831 { HP-Legal csHPLegal }
3832 { HP-Pi-font csHPPiFont }
3833 { HP-Math8 csHPMath8 }
3834 { Adobe-Symbol-Encoding csHPPSMath }
3835 { HP-DeskTop csHPDesktop }
3836 { Ventura-Math csVenturaMath }
3837 { Microsoft-Publishing csMicrosoftPublishing }
3838 { Windows-31J csWindows31J }
3843 proc tcl_encoding {enc} {
3844 global encoding_aliases
3845 set names [encoding names]
3846 set lcnames [string tolower $names]
3847 set enc [string tolower $enc]
3848 set i [lsearch -exact $lcnames $enc]
3850 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
3851 if {[regsub {^iso[-_]} $enc iso encx]} {
3852 set i [lsearch -exact $lcnames $encx]
3856 foreach l $encoding_aliases {
3857 set ll [string tolower $l]
3858 if {[lsearch -exact $ll $enc] < 0} continue
3859 # look through the aliases for one that tcl knows about
3861 set i [lsearch -exact $lcnames $e]
3863 if {[regsub {^iso[-_]} $e iso ex]} {
3864 set i [lsearch -exact $lcnames $ex]
3873 return [lindex $names $i]
3880 set diffopts "-U 5 -p"
3881 set wrcomcmd "git-diff-tree --stdin -p --pretty"
3885 set gitencoding [exec git-repo-config --get i18n.commitencoding]
3887 if {$gitencoding == ""} {
3888 set gitencoding "utf-8"
3890 set tclencoding [tcl_encoding $gitencoding]
3891 if {$tclencoding == {}} {
3892 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
3895 set mainfont {Helvetica 9}
3896 set textfont {Courier 9}
3897 set uifont {Helvetica 9 bold}
3898 set findmergefiles 0
3907 set colors {green red blue magenta darkgrey brown orange}
3909 catch {source ~/.gitk}
3911 set namefont $mainfont
3913 font create optionfont -family sans-serif -size -12
3917 switch -regexp -- $arg {
3919 "^-d" { set datemode 1 }
3921 lappend revtreeargs $arg
3926 # check that we can find a .git directory somewhere...
3928 if {![file isdirectory $gitdir]} {
3929 error_popup "Cannot find the git directory \"$gitdir\"."
3942 makewindow $revtreeargs
3944 getcommits $revtreeargs