]>
Commit | Line | Data |
---|---|---|
1db95b00 PM |
1 | #!/bin/sh |
2 | # Tcl ignores the next line -*- tcl -*- \ | |
9e026d39 | 3 | exec wish "$0" -- "$@" |
1db95b00 PM |
4 | |
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. | |
9 | ||
73b6a6cb JH |
10 | proc gitdir {} { |
11 | global env | |
12 | if {[info exists env(GIT_DIR)]} { | |
13 | return $env(GIT_DIR) | |
14 | } else { | |
15 | return ".git" | |
16 | } | |
17 | } | |
18 | ||
1db95b00 | 19 | proc getcommits {rargs} { |
e2ede2b9 | 20 | global commits commfd phase canv mainfont env |
466e4fdd | 21 | global startmsecs nextupdate ncmupdate |
b490a991 | 22 | global ctext maincursor textcursor leftover |
9ccbdfbf | 23 | |
e2ede2b9 | 24 | # check that we can find a .git directory somewhere... |
73b6a6cb | 25 | set gitdir [gitdir] |
e2ede2b9 PM |
26 | if {![file isdirectory $gitdir]} { |
27 | error_popup "Cannot find the git directory \"$gitdir\"." | |
28 | exit 1 | |
29 | } | |
1db95b00 | 30 | set commits {} |
1d10f36d | 31 | set phase getcommits |
9ccbdfbf PM |
32 | set startmsecs [clock clicks -milliseconds] |
33 | set nextupdate [expr $startmsecs + 100] | |
b664550c | 34 | set ncmupdate 1 |
2efef4b9 | 35 | if [catch { |
b490a991 | 36 | set parse_args [concat --default HEAD $rargs] |
2efef4b9 PM |
37 | set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"] |
38 | }] { | |
b490a991 | 39 | # if git-rev-parse failed for some reason... |
2efef4b9 PM |
40 | if {$rargs == {}} { |
41 | set rargs HEAD | |
42 | } | |
b490a991 | 43 | set parsed_args $rargs |
2efef4b9 PM |
44 | } |
45 | if [catch { | |
e5ea701b | 46 | set commfd [open "|git-rev-list --header --topo-order --parents $parsed_args" r] |
2efef4b9 | 47 | } err] { |
cfb4563c | 48 | puts stderr "Error executing git-rev-list: $err" |
1d10f36d PM |
49 | exit 1 |
50 | } | |
b490a991 | 51 | set leftover {} |
d6e8149b | 52 | fconfigure $commfd -blocking 0 -translation lf |
466e4fdd | 53 | fileevent $commfd readable [list getcommitlines $commfd] |
1d10f36d PM |
54 | $canv delete all |
55 | $canv create text 3 3 -anchor nw -text "Reading commits..." \ | |
56 | -font $mainfont -tags textitems | |
ea13cba1 | 57 | . config -cursor watch |
94a2eede | 58 | settextcursor watch |
1d10f36d PM |
59 | } |
60 | ||
b490a991 | 61 | proc getcommitlines {commfd} { |
f6075eba | 62 | global commits parents cdate children |
9ccbdfbf | 63 | global commitlisted phase commitinfo nextupdate |
b490a991 | 64 | global stopped redisplaying leftover |
9ccbdfbf | 65 | |
b490a991 PM |
66 | set stuff [read $commfd] |
67 | if {$stuff == {}} { | |
1d10f36d | 68 | if {![eof $commfd]} return |
f0654861 | 69 | # set it blocking so we wait for the process to terminate |
df3d83b1 | 70 | fconfigure $commfd -blocking 1 |
1d10f36d | 71 | if {![catch {close $commfd} err]} { |
9ccbdfbf | 72 | after idle finishcommits |
1d10f36d PM |
73 | return |
74 | } | |
9a40c50c | 75 | if {[string range $err 0 4] == "usage"} { |
9ccbdfbf PM |
76 | set err \ |
77 | {Gitk: error reading commits: bad arguments to git-rev-list. | |
78 | (Note: arguments to gitk are passed to git-rev-list | |
79 | to allow selection of commits to be displayed.)} | |
9a40c50c | 80 | } else { |
df3d83b1 | 81 | set err "Error reading commits: $err" |
9a40c50c | 82 | } |
df3d83b1 | 83 | error_popup $err |
1d10f36d | 84 | exit 1 |
9a40c50c | 85 | } |
b490a991 PM |
86 | set start 0 |
87 | while 1 { | |
88 | set i [string first "\0" $stuff $start] | |
89 | if {$i < 0} { | |
7e952e79 | 90 | append leftover [string range $stuff $start end] |
b490a991 | 91 | return |
9ccbdfbf | 92 | } |
b490a991 PM |
93 | set cmit [string range $stuff $start [expr {$i - 1}]] |
94 | if {$start == 0} { | |
95 | set cmit "$leftover$cmit" | |
7e952e79 | 96 | set leftover {} |
b490a991 PM |
97 | } |
98 | set start [expr {$i + 1}] | |
e5ea701b PM |
99 | set j [string first "\n" $cmit] |
100 | set ok 0 | |
101 | if {$j >= 0} { | |
102 | set ids [string range $cmit 0 [expr {$j - 1}]] | |
103 | set ok 1 | |
104 | foreach id $ids { | |
105 | if {![regexp {^[0-9a-f]{40}$} $id]} { | |
106 | set ok 0 | |
107 | break | |
108 | } | |
109 | } | |
110 | } | |
111 | if {!$ok} { | |
7e952e79 PM |
112 | set shortcmit $cmit |
113 | if {[string length $shortcmit] > 80} { | |
114 | set shortcmit "[string range $shortcmit 0 80]..." | |
115 | } | |
116 | error_popup "Can't parse git-rev-list output: {$shortcmit}" | |
b490a991 PM |
117 | exit 1 |
118 | } | |
e5ea701b PM |
119 | set id [lindex $ids 0] |
120 | set olds [lrange $ids 1 end] | |
121 | set cmit [string range $cmit [expr {$j + 1}] end] | |
b490a991 PM |
122 | lappend commits $id |
123 | set commitlisted($id) 1 | |
e5ea701b | 124 | parsecommit $id $cmit 1 [lrange $ids 1 end] |
b490a991 | 125 | drawcommit $id |
b664550c PM |
126 | if {[clock clicks -milliseconds] >= $nextupdate} { |
127 | doupdate 1 | |
b490a991 PM |
128 | } |
129 | while {$redisplaying} { | |
130 | set redisplaying 0 | |
131 | if {$stopped == 1} { | |
132 | set stopped 0 | |
133 | set phase "getcommits" | |
134 | foreach id $commits { | |
135 | drawcommit $id | |
136 | if {$stopped} break | |
b664550c PM |
137 | if {[clock clicks -milliseconds] >= $nextupdate} { |
138 | doupdate 1 | |
b490a991 | 139 | } |
9ccbdfbf PM |
140 | } |
141 | } | |
142 | } | |
143 | } | |
144 | } | |
145 | ||
b664550c PM |
146 | proc doupdate {reading} { |
147 | global commfd nextupdate numcommits ncmupdate | |
9ccbdfbf | 148 | |
b664550c PM |
149 | if {$reading} { |
150 | fileevent $commfd readable {} | |
151 | } | |
9ccbdfbf | 152 | update |
b664550c PM |
153 | set nextupdate [expr {[clock clicks -milliseconds] + 100}] |
154 | if {$numcommits < 100} { | |
155 | set ncmupdate [expr {$numcommits + 1}] | |
156 | } elseif {$numcommits < 10000} { | |
157 | set ncmupdate [expr {$numcommits + 10}] | |
158 | } else { | |
159 | set ncmupdate [expr {$numcommits + 100}] | |
160 | } | |
161 | if {$reading} { | |
162 | fileevent $commfd readable [list getcommitlines $commfd] | |
163 | } | |
1db95b00 PM |
164 | } |
165 | ||
166 | proc readcommit {id} { | |
b490a991 | 167 | if [catch {set contents [exec git-cat-file commit $id]}] return |
e5ea701b | 168 | parsecommit $id $contents 0 {} |
b490a991 PM |
169 | } |
170 | ||
e5ea701b | 171 | proc parsecommit {id contents listed olds} { |
9ccbdfbf | 172 | global commitinfo children nchildren parents nparents cdate ncleft |
9ccbdfbf | 173 | |
1db95b00 PM |
174 | set inhdr 1 |
175 | set comment {} | |
176 | set headline {} | |
177 | set auname {} | |
178 | set audate {} | |
179 | set comname {} | |
180 | set comdate {} | |
cfb4563c PM |
181 | if {![info exists nchildren($id)]} { |
182 | set children($id) {} | |
183 | set nchildren($id) 0 | |
9ccbdfbf | 184 | set ncleft($id) 0 |
cfb4563c | 185 | } |
e5ea701b PM |
186 | set parents($id) $olds |
187 | set nparents($id) [llength $olds] | |
188 | foreach p $olds { | |
189 | if {![info exists nchildren($p)]} { | |
190 | set children($p) [list $id] | |
191 | set nchildren($p) 1 | |
192 | set ncleft($p) 1 | |
193 | } elseif {[lsearch -exact $children($p) $id] < 0} { | |
194 | lappend children($p) $id | |
195 | incr nchildren($p) | |
196 | incr ncleft($p) | |
244edd12 PM |
197 | } |
198 | } | |
df3d83b1 | 199 | foreach line [split $contents "\n"] { |
1db95b00 PM |
200 | if {$inhdr} { |
201 | if {$line == {}} { | |
202 | set inhdr 0 | |
203 | } else { | |
204 | set tag [lindex $line 0] | |
e5ea701b | 205 | if {$tag == "author"} { |
1db95b00 PM |
206 | set x [expr {[llength $line] - 2}] |
207 | set audate [lindex $line $x] | |
208 | set auname [lrange $line 1 [expr {$x - 1}]] | |
209 | } elseif {$tag == "committer"} { | |
210 | set x [expr {[llength $line] - 2}] | |
211 | set comdate [lindex $line $x] | |
212 | set comname [lrange $line 1 [expr {$x - 1}]] | |
213 | } | |
214 | } | |
215 | } else { | |
216 | if {$comment == {}} { | |
806ce097 | 217 | set headline [string trim $line] |
1db95b00 PM |
218 | } else { |
219 | append comment "\n" | |
220 | } | |
806ce097 PM |
221 | if {!$listed} { |
222 | # git-rev-list indents the comment by 4 spaces; | |
223 | # if we got this via git-cat-file, add the indentation | |
224 | append comment " " | |
225 | } | |
1db95b00 PM |
226 | append comment $line |
227 | } | |
228 | } | |
229 | if {$audate != {}} { | |
230 | set audate [clock format $audate -format "%Y-%m-%d %H:%M:%S"] | |
231 | } | |
232 | if {$comdate != {}} { | |
cfb4563c | 233 | set cdate($id) $comdate |
1db95b00 PM |
234 | set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"] |
235 | } | |
e5c2d856 PM |
236 | set commitinfo($id) [list $headline $auname $audate \ |
237 | $comname $comdate $comment] | |
1db95b00 PM |
238 | } |
239 | ||
887fe3c4 | 240 | proc readrefs {} { |
106288cb PM |
241 | global tagids idtags headids idheads tagcontents |
242 | ||
73b6a6cb | 243 | set tags [glob -nocomplain -types f [gitdir]/refs/tags/*] |
887fe3c4 PM |
244 | foreach f $tags { |
245 | catch { | |
246 | set fd [open $f r] | |
247 | set line [read $fd] | |
248 | if {[regexp {^[0-9a-f]{40}} $line id]} { | |
9ccbdfbf PM |
249 | set direct [file tail $f] |
250 | set tagids($direct) $id | |
251 | lappend idtags($id) $direct | |
106288cb PM |
252 | set tagblob [exec git-cat-file tag $id] |
253 | set contents [split $tagblob "\n"] | |
887fe3c4 PM |
254 | set obj {} |
255 | set type {} | |
256 | set tag {} | |
257 | foreach l $contents { | |
258 | if {$l == {}} break | |
259 | switch -- [lindex $l 0] { | |
260 | "object" {set obj [lindex $l 1]} | |
261 | "type" {set type [lindex $l 1]} | |
262 | "tag" {set tag [string range $l 4 end]} | |
263 | } | |
264 | } | |
265 | if {$obj != {} && $type == "commit" && $tag != {}} { | |
266 | set tagids($tag) $obj | |
267 | lappend idtags($obj) $tag | |
106288cb | 268 | set tagcontents($tag) $tagblob |
887fe3c4 PM |
269 | } |
270 | } | |
c2f6a022 PM |
271 | close $fd |
272 | } | |
273 | } | |
73b6a6cb | 274 | set heads [glob -nocomplain -types f [gitdir]/refs/heads/*] |
c2f6a022 PM |
275 | foreach f $heads { |
276 | catch { | |
277 | set fd [open $f r] | |
278 | set line [read $fd 40] | |
279 | if {[regexp {^[0-9a-f]{40}} $line id]} { | |
280 | set head [file tail $f] | |
281 | set headids($head) $line | |
282 | lappend idheads($line) $head | |
283 | } | |
284 | close $fd | |
887fe3c4 PM |
285 | } |
286 | } | |
f1d83ba3 PM |
287 | readotherrefs refs {} {tags heads} |
288 | } | |
289 | ||
290 | proc readotherrefs {base dname excl} { | |
291 | global otherrefids idotherrefs | |
292 | ||
293 | set git [gitdir] | |
294 | set files [glob -nocomplain -types f [file join $git $base *]] | |
295 | foreach f $files { | |
296 | catch { | |
297 | set fd [open $f r] | |
298 | set line [read $fd 40] | |
299 | if {[regexp {^[0-9a-f]{40}} $line id]} { | |
300 | set name "$dname[file tail $f]" | |
301 | set otherrefids($name) $id | |
302 | lappend idotherrefs($id) $name | |
303 | } | |
304 | close $fd | |
305 | } | |
306 | } | |
307 | set dirs [glob -nocomplain -types d [file join $git $base *]] | |
308 | foreach d $dirs { | |
309 | set dir [file tail $d] | |
310 | if {[lsearch -exact $excl $dir] >= 0} continue | |
311 | readotherrefs [file join $base $dir] "$dname$dir/" {} | |
312 | } | |
887fe3c4 PM |
313 | } |
314 | ||
df3d83b1 PM |
315 | proc error_popup msg { |
316 | set w .error | |
317 | toplevel $w | |
318 | wm transient $w . | |
319 | message $w.m -text $msg -justify center -aspect 400 | |
320 | pack $w.m -side top -fill x -padx 20 -pady 20 | |
321 | button $w.ok -text OK -command "destroy $w" | |
322 | pack $w.ok -side bottom -fill x | |
323 | bind $w <Visibility> "grab $w; focus $w" | |
324 | tkwait window $w | |
325 | } | |
326 | ||
1db95b00 | 327 | proc makewindow {} { |
e5c2d856 | 328 | global canv canv2 canv3 linespc charspc ctext cflist textfont |
b74fd579 | 329 | global findtype findtypemenu findloc findstring fstring geometry |
887fe3c4 | 330 | global entries sha1entry sha1string sha1but |
94a2eede | 331 | global maincursor textcursor curtextcursor |
9d2a52ec | 332 | global rowctxmenu gaudydiff mergemax |
9a40c50c PM |
333 | |
334 | menu .bar | |
335 | .bar add cascade -label "File" -menu .bar.file | |
336 | menu .bar.file | |
f1d83ba3 | 337 | .bar.file add command -label "Reread references" -command rereadrefs |
1d10f36d | 338 | .bar.file add command -label "Quit" -command doquit |
9a40c50c PM |
339 | menu .bar.help |
340 | .bar add cascade -label "Help" -menu .bar.help | |
341 | .bar.help add command -label "About gitk" -command about | |
342 | . configure -menu .bar | |
343 | ||
0fba86b3 PM |
344 | if {![info exists geometry(canv1)]} { |
345 | set geometry(canv1) [expr 45 * $charspc] | |
346 | set geometry(canv2) [expr 30 * $charspc] | |
347 | set geometry(canv3) [expr 15 * $charspc] | |
348 | set geometry(canvh) [expr 25 * $linespc + 4] | |
349 | set geometry(ctextw) 80 | |
350 | set geometry(ctexth) 30 | |
351 | set geometry(cflistw) 30 | |
352 | } | |
0327d27a | 353 | panedwindow .ctop -orient vertical |
0fba86b3 PM |
354 | if {[info exists geometry(width)]} { |
355 | .ctop conf -width $geometry(width) -height $geometry(height) | |
17386066 PM |
356 | set texth [expr {$geometry(height) - $geometry(canvh) - 56}] |
357 | set geometry(ctexth) [expr {($texth - 8) / | |
358 | [font metrics $textfont -linespace]}] | |
0fba86b3 | 359 | } |
98f350e5 PM |
360 | frame .ctop.top |
361 | frame .ctop.top.bar | |
362 | pack .ctop.top.bar -side bottom -fill x | |
363 | set cscroll .ctop.top.csb | |
364 | scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0 | |
365 | pack $cscroll -side right -fill y | |
366 | panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4 | |
367 | pack .ctop.top.clist -side top -fill both -expand 1 | |
368 | .ctop add .ctop.top | |
369 | set canv .ctop.top.clist.canv | |
0fba86b3 | 370 | canvas $canv -height $geometry(canvh) -width $geometry(canv1) \ |
b5721c72 PM |
371 | -bg white -bd 0 \ |
372 | -yscrollincr $linespc -yscrollcommand "$cscroll set" | |
98f350e5 PM |
373 | .ctop.top.clist add $canv |
374 | set canv2 .ctop.top.clist.canv2 | |
0fba86b3 | 375 | canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \ |
b5721c72 | 376 | -bg white -bd 0 -yscrollincr $linespc |
98f350e5 PM |
377 | .ctop.top.clist add $canv2 |
378 | set canv3 .ctop.top.clist.canv3 | |
0fba86b3 | 379 | canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \ |
b5721c72 | 380 | -bg white -bd 0 -yscrollincr $linespc |
98f350e5 | 381 | .ctop.top.clist add $canv3 |
43bddeb4 | 382 | bind .ctop.top.clist <Configure> {resizeclistpanes %W %w} |
98f350e5 PM |
383 | |
384 | set sha1entry .ctop.top.bar.sha1 | |
887fe3c4 PM |
385 | set entries $sha1entry |
386 | set sha1but .ctop.top.bar.sha1label | |
387 | button $sha1but -text "SHA1 ID: " -state disabled -relief flat \ | |
388 | -command gotocommit -width 8 | |
389 | $sha1but conf -disabledforeground [$sha1but cget -foreground] | |
98f350e5 | 390 | pack .ctop.top.bar.sha1label -side left |
887fe3c4 PM |
391 | entry $sha1entry -width 40 -font $textfont -textvariable sha1string |
392 | trace add variable sha1string write sha1change | |
98f350e5 | 393 | pack $sha1entry -side left -pady 2 |
d698206c PM |
394 | |
395 | image create bitmap bm-left -data { | |
396 | #define left_width 16 | |
397 | #define left_height 16 | |
398 | static unsigned char left_bits[] = { | |
399 | 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, | |
400 | 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00, | |
401 | 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01}; | |
402 | } | |
403 | image create bitmap bm-right -data { | |
404 | #define right_width 16 | |
405 | #define right_height 16 | |
406 | static unsigned char right_bits[] = { | |
407 | 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c, | |
408 | 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c, | |
409 | 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01}; | |
410 | } | |
411 | button .ctop.top.bar.leftbut -image bm-left -command goback \ | |
412 | -state disabled -width 26 | |
413 | pack .ctop.top.bar.leftbut -side left -fill y | |
414 | button .ctop.top.bar.rightbut -image bm-right -command goforw \ | |
415 | -state disabled -width 26 | |
416 | pack .ctop.top.bar.rightbut -side left -fill y | |
417 | ||
98f350e5 PM |
418 | button .ctop.top.bar.findbut -text "Find" -command dofind |
419 | pack .ctop.top.bar.findbut -side left | |
420 | set findstring {} | |
df3d83b1 | 421 | set fstring .ctop.top.bar.findstring |
887fe3c4 | 422 | lappend entries $fstring |
df3d83b1 | 423 | entry $fstring -width 30 -font $textfont -textvariable findstring |
df3d83b1 | 424 | pack $fstring -side left -expand 1 -fill x |
98f350e5 | 425 | set findtype Exact |
b74fd579 PM |
426 | set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \ |
427 | findtype Exact IgnCase Regexp] | |
98f350e5 PM |
428 | set findloc "All fields" |
429 | tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \ | |
b74fd579 | 430 | Comments Author Committer Files Pickaxe |
98f350e5 PM |
431 | pack .ctop.top.bar.findloc -side right |
432 | pack .ctop.top.bar.findtype -side right | |
b74fd579 PM |
433 | # for making sure type==Exact whenever loc==Pickaxe |
434 | trace add variable findloc write findlocchange | |
b5721c72 | 435 | |
5ad588de PM |
436 | panedwindow .ctop.cdet -orient horizontal |
437 | .ctop add .ctop.cdet | |
d2610d11 PM |
438 | frame .ctop.cdet.left |
439 | set ctext .ctop.cdet.left.ctext | |
0fba86b3 PM |
440 | text $ctext -bg white -state disabled -font $textfont \ |
441 | -width $geometry(ctextw) -height $geometry(ctexth) \ | |
b1ba39e7 | 442 | -yscrollcommand ".ctop.cdet.left.sb set" -wrap none |
d2610d11 PM |
443 | scrollbar .ctop.cdet.left.sb -command "$ctext yview" |
444 | pack .ctop.cdet.left.sb -side right -fill y | |
445 | pack $ctext -side left -fill both -expand 1 | |
446 | .ctop.cdet add .ctop.cdet.left | |
447 | ||
f0654861 PM |
448 | $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa" |
449 | if {$gaudydiff} { | |
450 | $ctext tag conf hunksep -back blue -fore white | |
451 | $ctext tag conf d0 -back "#ff8080" | |
452 | $ctext tag conf d1 -back green | |
453 | } else { | |
454 | $ctext tag conf hunksep -fore blue | |
455 | $ctext tag conf d0 -fore red | |
456 | $ctext tag conf d1 -fore "#00a000" | |
9d2a52ec PM |
457 | $ctext tag conf m0 -fore red |
458 | $ctext tag conf m1 -fore blue | |
459 | $ctext tag conf m2 -fore green | |
460 | $ctext tag conf m3 -fore purple | |
461 | $ctext tag conf m4 -fore brown | |
462 | $ctext tag conf mmax -fore darkgrey | |
463 | set mergemax 5 | |
464 | $ctext tag conf mresult -font [concat $textfont bold] | |
465 | $ctext tag conf msep -font [concat $textfont bold] | |
f0654861 PM |
466 | $ctext tag conf found -back yellow |
467 | } | |
e5c2d856 | 468 | |
d2610d11 PM |
469 | frame .ctop.cdet.right |
470 | set cflist .ctop.cdet.right.cfiles | |
17386066 | 471 | listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \ |
d2610d11 PM |
472 | -yscrollcommand ".ctop.cdet.right.sb set" |
473 | scrollbar .ctop.cdet.right.sb -command "$cflist yview" | |
474 | pack .ctop.cdet.right.sb -side right -fill y | |
475 | pack $cflist -side left -fill both -expand 1 | |
476 | .ctop.cdet add .ctop.cdet.right | |
0fba86b3 | 477 | bind .ctop.cdet <Configure> {resizecdetpanes %W %w} |
d2610d11 | 478 | |
0327d27a | 479 | pack .ctop -side top -fill both -expand 1 |
1db95b00 | 480 | |
c8dfbcf9 PM |
481 | bindall <1> {selcanvline %W %x %y} |
482 | #bindall <B1-Motion> {selcanvline %W %x %y} | |
cfb4563c PM |
483 | bindall <ButtonRelease-4> "allcanvs yview scroll -5 units" |
484 | bindall <ButtonRelease-5> "allcanvs yview scroll 5 units" | |
b5721c72 PM |
485 | bindall <2> "allcanvs scan mark 0 %y" |
486 | bindall <B2-Motion> "allcanvs scan dragto 0 %y" | |
17386066 PM |
487 | bind . <Key-Up> "selnextline -1" |
488 | bind . <Key-Down> "selnextline 1" | |
6e2dda35 RS |
489 | bind . <Key-Right> "goforw" |
490 | bind . <Key-Left> "goback" | |
cfb4563c PM |
491 | bind . <Key-Prior> "allcanvs yview scroll -1 pages" |
492 | bind . <Key-Next> "allcanvs yview scroll 1 pages" | |
493 | bindkey <Key-Delete> "$ctext yview scroll -1 pages" | |
494 | bindkey <Key-BackSpace> "$ctext yview scroll -1 pages" | |
495 | bindkey <Key-space> "$ctext yview scroll 1 pages" | |
df3d83b1 PM |
496 | bindkey p "selnextline -1" |
497 | bindkey n "selnextline 1" | |
6e2dda35 RS |
498 | bindkey z "goback" |
499 | bindkey x "goforw" | |
500 | bindkey i "selnextline -1" | |
501 | bindkey k "selnextline 1" | |
502 | bindkey j "goback" | |
503 | bindkey l "goforw" | |
cfb4563c PM |
504 | bindkey b "$ctext yview scroll -1 pages" |
505 | bindkey d "$ctext yview scroll 18 units" | |
506 | bindkey u "$ctext yview scroll -18 units" | |
b74fd579 PM |
507 | bindkey / {findnext 1} |
508 | bindkey <Key-Return> {findnext 0} | |
df3d83b1 | 509 | bindkey ? findprev |
39ad8570 | 510 | bindkey f nextfile |
1d10f36d | 511 | bind . <Control-q> doquit |
98f350e5 | 512 | bind . <Control-f> dofind |
b74fd579 | 513 | bind . <Control-g> {findnext 0} |
98f350e5 | 514 | bind . <Control-r> findprev |
1d10f36d PM |
515 | bind . <Control-equal> {incrfont 1} |
516 | bind . <Control-KP_Add> {incrfont 1} | |
517 | bind . <Control-minus> {incrfont -1} | |
518 | bind . <Control-KP_Subtract> {incrfont -1} | |
e5c2d856 | 519 | bind $cflist <<ListboxSelect>> listboxsel |
0fba86b3 | 520 | bind . <Destroy> {savestuff %W} |
df3d83b1 | 521 | bind . <Button-1> "click %W" |
17386066 | 522 | bind $fstring <Key-Return> dofind |
887fe3c4 | 523 | bind $sha1entry <Key-Return> gotocommit |
ee3dc72e | 524 | bind $sha1entry <<PasteSelection>> clearsha1 |
ea13cba1 PM |
525 | |
526 | set maincursor [. cget -cursor] | |
527 | set textcursor [$ctext cget -cursor] | |
94a2eede | 528 | set curtextcursor $textcursor |
84ba7345 | 529 | |
c8dfbcf9 PM |
530 | set rowctxmenu .rowctxmenu |
531 | menu $rowctxmenu -tearoff 0 | |
532 | $rowctxmenu add command -label "Diff this -> selected" \ | |
533 | -command {diffvssel 0} | |
534 | $rowctxmenu add command -label "Diff selected -> this" \ | |
535 | -command {diffvssel 1} | |
74daedb6 | 536 | $rowctxmenu add command -label "Make patch" -command mkpatch |
bdbfbe3d | 537 | $rowctxmenu add command -label "Create tag" -command mktag |
4a2139f5 | 538 | $rowctxmenu add command -label "Write commit to file" -command writecommit |
df3d83b1 PM |
539 | } |
540 | ||
541 | # when we make a key binding for the toplevel, make sure | |
542 | # it doesn't get triggered when that key is pressed in the | |
543 | # find string entry widget. | |
544 | proc bindkey {ev script} { | |
887fe3c4 | 545 | global entries |
df3d83b1 PM |
546 | bind . $ev $script |
547 | set escript [bind Entry $ev] | |
548 | if {$escript == {}} { | |
549 | set escript [bind Entry <Key>] | |
550 | } | |
887fe3c4 PM |
551 | foreach e $entries { |
552 | bind $e $ev "$escript; break" | |
553 | } | |
df3d83b1 PM |
554 | } |
555 | ||
556 | # set the focus back to the toplevel for any click outside | |
887fe3c4 | 557 | # the entry widgets |
df3d83b1 | 558 | proc click {w} { |
887fe3c4 PM |
559 | global entries |
560 | foreach e $entries { | |
561 | if {$w == $e} return | |
df3d83b1 | 562 | } |
887fe3c4 | 563 | focus . |
0fba86b3 PM |
564 | } |
565 | ||
566 | proc savestuff {w} { | |
567 | global canv canv2 canv3 ctext cflist mainfont textfont | |
8d858d1a | 568 | global stuffsaved findmergefiles gaudydiff maxgraphpct |
04c13d38 | 569 | global maxwidth |
4ef17537 | 570 | |
0fba86b3 | 571 | if {$stuffsaved} return |
df3d83b1 | 572 | if {![winfo viewable .]} return |
0fba86b3 PM |
573 | catch { |
574 | set f [open "~/.gitk-new" w] | |
f0654861 PM |
575 | puts $f [list set mainfont $mainfont] |
576 | puts $f [list set textfont $textfont] | |
577 | puts $f [list set findmergefiles $findmergefiles] | |
578 | puts $f [list set gaudydiff $gaudydiff] | |
8d858d1a | 579 | puts $f [list set maxgraphpct $maxgraphpct] |
04c13d38 | 580 | puts $f [list set maxwidth $maxwidth] |
0fba86b3 PM |
581 | puts $f "set geometry(width) [winfo width .ctop]" |
582 | puts $f "set geometry(height) [winfo height .ctop]" | |
df3d83b1 PM |
583 | puts $f "set geometry(canv1) [expr [winfo width $canv]-2]" |
584 | puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]" | |
585 | puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]" | |
586 | puts $f "set geometry(canvh) [expr [winfo height $canv]-2]" | |
0fba86b3 PM |
587 | set wid [expr {([winfo width $ctext] - 8) \ |
588 | / [font measure $textfont "0"]}] | |
0fba86b3 | 589 | puts $f "set geometry(ctextw) $wid" |
0fba86b3 PM |
590 | set wid [expr {([winfo width $cflist] - 11) \ |
591 | / [font measure [$cflist cget -font] "0"]}] | |
592 | puts $f "set geometry(cflistw) $wid" | |
593 | close $f | |
594 | file rename -force "~/.gitk-new" "~/.gitk" | |
595 | } | |
596 | set stuffsaved 1 | |
1db95b00 PM |
597 | } |
598 | ||
43bddeb4 PM |
599 | proc resizeclistpanes {win w} { |
600 | global oldwidth | |
601 | if [info exists oldwidth($win)] { | |
602 | set s0 [$win sash coord 0] | |
603 | set s1 [$win sash coord 1] | |
604 | if {$w < 60} { | |
605 | set sash0 [expr {int($w/2 - 2)}] | |
606 | set sash1 [expr {int($w*5/6 - 2)}] | |
607 | } else { | |
608 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
609 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
610 | set sash1 [expr {int($factor * [lindex $s1 0])}] | |
611 | if {$sash0 < 30} { | |
612 | set sash0 30 | |
613 | } | |
614 | if {$sash1 < $sash0 + 20} { | |
615 | set sash1 [expr $sash0 + 20] | |
616 | } | |
617 | if {$sash1 > $w - 10} { | |
618 | set sash1 [expr $w - 10] | |
619 | if {$sash0 > $sash1 - 20} { | |
620 | set sash0 [expr $sash1 - 20] | |
621 | } | |
622 | } | |
623 | } | |
624 | $win sash place 0 $sash0 [lindex $s0 1] | |
625 | $win sash place 1 $sash1 [lindex $s1 1] | |
626 | } | |
627 | set oldwidth($win) $w | |
628 | } | |
629 | ||
630 | proc resizecdetpanes {win w} { | |
631 | global oldwidth | |
632 | if [info exists oldwidth($win)] { | |
633 | set s0 [$win sash coord 0] | |
634 | if {$w < 60} { | |
635 | set sash0 [expr {int($w*3/4 - 2)}] | |
636 | } else { | |
637 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
638 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
639 | if {$sash0 < 45} { | |
640 | set sash0 45 | |
641 | } | |
642 | if {$sash0 > $w - 15} { | |
643 | set sash0 [expr $w - 15] | |
644 | } | |
645 | } | |
646 | $win sash place 0 $sash0 [lindex $s0 1] | |
647 | } | |
648 | set oldwidth($win) $w | |
649 | } | |
650 | ||
b5721c72 PM |
651 | proc allcanvs args { |
652 | global canv canv2 canv3 | |
653 | eval $canv $args | |
654 | eval $canv2 $args | |
655 | eval $canv3 $args | |
656 | } | |
657 | ||
658 | proc bindall {event action} { | |
659 | global canv canv2 canv3 | |
660 | bind $canv $event $action | |
661 | bind $canv2 $event $action | |
662 | bind $canv3 $event $action | |
663 | } | |
664 | ||
9a40c50c PM |
665 | proc about {} { |
666 | set w .about | |
667 | if {[winfo exists $w]} { | |
668 | raise $w | |
669 | return | |
670 | } | |
671 | toplevel $w | |
672 | wm title $w "About gitk" | |
673 | message $w.m -text { | |
c8dfbcf9 | 674 | Gitk version 1.2 |
9a40c50c PM |
675 | |
676 |