]>
Commit | Line | Data |
---|---|---|
1db95b00 PM |
1 | #!/bin/sh |
2 | # Tcl ignores the next line -*- tcl -*- \ | |
9e026d39 | 3 | exec wish "$0" -- "$@" |
1db95b00 | 4 | |
aa43561a | 5 | # Copyright © 2005-2009 Paul Mackerras. All rights reserved. |
1db95b00 PM |
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 | ||
d93f1713 PT |
10 | package require Tk |
11 | ||
73b6a6cb JH |
12 | proc gitdir {} { |
13 | global env | |
14 | if {[info exists env(GIT_DIR)]} { | |
15 | return $env(GIT_DIR) | |
16 | } else { | |
5024baa4 | 17 | return [exec git rev-parse --git-dir] |
73b6a6cb JH |
18 | } |
19 | } | |
20 | ||
7eb3cb9c PM |
21 | # A simple scheduler for compute-intensive stuff. |
22 | # The aim is to make sure that event handlers for GUI actions can | |
23 | # run at least every 50-100 ms. Unfortunately fileevent handlers are | |
24 | # run before X event handlers, so reading from a fast source can | |
25 | # make the GUI completely unresponsive. | |
26 | proc run args { | |
df75e86d | 27 | global isonrunq runq currunq |
7eb3cb9c PM |
28 | |
29 | set script $args | |
30 | if {[info exists isonrunq($script)]} return | |
df75e86d | 31 | if {$runq eq {} && ![info exists currunq]} { |
7eb3cb9c PM |
32 | after idle dorunq |
33 | } | |
34 | lappend runq [list {} $script] | |
35 | set isonrunq($script) 1 | |
36 | } | |
37 | ||
38 | proc filerun {fd script} { | |
39 | fileevent $fd readable [list filereadable $fd $script] | |
40 | } | |
41 | ||
42 | proc filereadable {fd script} { | |
df75e86d | 43 | global runq currunq |
7eb3cb9c PM |
44 | |
45 | fileevent $fd readable {} | |
df75e86d | 46 | if {$runq eq {} && ![info exists currunq]} { |
7eb3cb9c PM |
47 | after idle dorunq |
48 | } | |
49 | lappend runq [list $fd $script] | |
50 | } | |
51 | ||
7fcc92bf PM |
52 | proc nukefile {fd} { |
53 | global runq | |
54 | ||
55 | for {set i 0} {$i < [llength $runq]} {} { | |
56 | if {[lindex $runq $i 0] eq $fd} { | |
57 | set runq [lreplace $runq $i $i] | |
58 | } else { | |
59 | incr i | |
60 | } | |
61 | } | |
62 | } | |
63 | ||
7eb3cb9c | 64 | proc dorunq {} { |
df75e86d | 65 | global isonrunq runq currunq |
7eb3cb9c PM |
66 | |
67 | set tstart [clock clicks -milliseconds] | |
68 | set t0 $tstart | |
7fcc92bf | 69 | while {[llength $runq] > 0} { |
7eb3cb9c PM |
70 | set fd [lindex $runq 0 0] |
71 | set script [lindex $runq 0 1] | |
df75e86d AG |
72 | set currunq [lindex $runq 0] |
73 | set runq [lrange $runq 1 end] | |
7eb3cb9c | 74 | set repeat [eval $script] |
df75e86d | 75 | unset currunq |
7eb3cb9c PM |
76 | set t1 [clock clicks -milliseconds] |
77 | set t [expr {$t1 - $t0}] | |
7eb3cb9c PM |
78 | if {$repeat ne {} && $repeat} { |
79 | if {$fd eq {} || $repeat == 2} { | |
80 | # script returns 1 if it wants to be readded | |
81 | # file readers return 2 if they could do more straight away | |
82 | lappend runq [list $fd $script] | |
83 | } else { | |
84 | fileevent $fd readable [list filereadable $fd $script] | |
85 | } | |
86 | } elseif {$fd eq {}} { | |
87 | unset isonrunq($script) | |
88 | } | |
89 | set t0 $t1 | |
90 | if {$t1 - $tstart >= 80} break | |
91 | } | |
92 | if {$runq ne {}} { | |
93 | after idle dorunq | |
94 | } | |
95 | } | |
96 | ||
e439e092 AG |
97 | proc reg_instance {fd} { |
98 | global commfd leftover loginstance | |
99 | ||
100 | set i [incr loginstance] | |
101 | set commfd($i) $fd | |
102 | set leftover($i) {} | |
103 | return $i | |
104 | } | |
105 | ||
3ed31a81 PM |
106 | proc unmerged_files {files} { |
107 | global nr_unmerged | |
108 | ||
109 | # find the list of unmerged files | |
110 | set mlist {} | |
111 | set nr_unmerged 0 | |
112 | if {[catch { | |
113 | set fd [open "| git ls-files -u" r] | |
114 | } err]} { | |
115 | show_error {} . "[mc "Couldn't get list of unmerged files:"] $err" | |
116 | exit 1 | |
117 | } | |
118 | while {[gets $fd line] >= 0} { | |
119 | set i [string first "\t" $line] | |
120 | if {$i < 0} continue | |
121 | set fname [string range $line [expr {$i+1}] end] | |
122 | if {[lsearch -exact $mlist $fname] >= 0} continue | |
123 | incr nr_unmerged | |
124 | if {$files eq {} || [path_filter $files $fname]} { | |
125 | lappend mlist $fname | |
126 | } | |
127 | } | |
128 | catch {close $fd} | |
129 | return $mlist | |
130 | } | |
131 | ||
132 | proc parseviewargs {n arglist} { | |
c2f2dab9 | 133 | global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env |
3ed31a81 PM |
134 | |
135 | set vdatemode($n) 0 | |
136 | set vmergeonly($n) 0 | |
ee66e089 PM |
137 | set glflags {} |
138 | set diffargs {} | |
139 | set nextisval 0 | |
140 | set revargs {} | |
141 | set origargs $arglist | |
142 | set allknown 1 | |
143 | set filtered 0 | |
144 | set i -1 | |
145 | foreach arg $arglist { | |
146 | incr i | |
147 | if {$nextisval} { | |
148 | lappend glflags $arg | |
149 | set nextisval 0 | |
150 | continue | |
151 | } | |
3ed31a81 PM |
152 | switch -glob -- $arg { |
153 | "-d" - | |
154 | "--date-order" { | |
155 | set vdatemode($n) 1 | |
ee66e089 PM |
156 | # remove from origargs in case we hit an unknown option |
157 | set origargs [lreplace $origargs $i $i] | |
158 | incr i -1 | |
159 | } | |
ee66e089 PM |
160 | "-[puabwcrRBMC]" - |
161 | "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" - | |
162 | "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" - | |
163 | "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" - | |
164 | "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" - | |
165 | "--ignore-space-change" - "-U*" - "--unified=*" { | |
29582284 PM |
166 | # These request or affect diff output, which we don't want. |
167 | # Some could be used to set our defaults for diff display. | |
ee66e089 PM |
168 | lappend diffargs $arg |
169 | } | |
ee66e089 PM |
170 | "--raw" - "--patch-with-raw" - "--patch-with-stat" - |
171 | "--name-only" - "--name-status" - "--color" - "--color-words" - | |
172 | "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" - | |
173 | "--cc" - "-z" - "--header" - "--parents" - "--boundary" - | |
174 | "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" - | |
175 | "--timestamp" - "relative-date" - "--date=*" - "--stdin" - | |
176 | "--objects" - "--objects-edge" - "--reverse" { | |
29582284 PM |
177 | # These cause our parsing of git log's output to fail, or else |
178 | # they're options we want to set ourselves, so ignore them. | |
ee66e089 | 179 | } |
ee66e089 PM |
180 | "--stat=*" - "--numstat" - "--shortstat" - "--summary" - |
181 | "--check" - "--exit-code" - "--quiet" - "--topo-order" - | |
182 | "--full-history" - "--dense" - "--sparse" - | |
183 | "--follow" - "--left-right" - "--encoding=*" { | |
29582284 | 184 | # These are harmless, and some are even useful |
ee66e089 PM |
185 | lappend glflags $arg |
186 | } | |
ee66e089 PM |
187 | "--diff-filter=*" - "--no-merges" - "--unpacked" - |
188 | "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" - | |
189 | "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - | |
190 | "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - | |
191 | "--remove-empty" - "--first-parent" - "--cherry-pick" - | |
f687aaa8 DS |
192 | "-S*" - "--pickaxe-all" - "--pickaxe-regex" - |
193 | "--simplify-by-decoration" { | |
29582284 | 194 | # These mean that we get a subset of the commits |
ee66e089 PM |
195 | set filtered 1 |
196 | lappend glflags $arg | |
197 | } | |
ee66e089 | 198 | "-n" { |
29582284 PM |
199 | # This appears to be the only one that has a value as a |
200 | # separate word following it | |
ee66e089 PM |
201 | set filtered 1 |
202 | set nextisval 1 | |
203 | lappend glflags $arg | |
204 | } | |
6e7e87c7 | 205 | "--not" - "--all" { |
ee66e089 | 206 | lappend revargs $arg |
3ed31a81 PM |
207 | } |
208 | "--merge" { | |
209 | set vmergeonly($n) 1 | |
ee66e089 PM |
210 | # git rev-parse doesn't understand --merge |
211 | lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD | |
212 | } | |
c2f2dab9 CC |
213 | "--no-replace-objects" { |
214 | set env(GIT_NO_REPLACE_OBJECTS) "1" | |
215 | } | |
ee66e089 | 216 | "-*" { |
29582284 | 217 | # Other flag arguments including -<n> |
ee66e089 PM |
218 | if {[string is digit -strict [string range $arg 1 end]]} { |
219 | set filtered 1 | |
220 | } else { | |
221 | # a flag argument that we don't recognize; | |
222 | # that means we can't optimize | |
223 | set allknown 0 | |
224 | } | |
225 | lappend glflags $arg | |
3ed31a81 PM |
226 | } |
227 | default { | |
29582284 | 228 | # Non-flag arguments specify commits or ranges of commits |
ee66e089 PM |
229 | if {[string match "*...*" $arg]} { |
230 | lappend revargs --gitk-symmetric-diff-marker | |
231 | } | |
232 | lappend revargs $arg | |
233 | } | |
234 | } | |
235 | } | |
236 | set vdflags($n) $diffargs | |
237 | set vflags($n) $glflags | |
238 | set vrevs($n) $revargs | |
239 | set vfiltered($n) $filtered | |
240 | set vorigargs($n) $origargs | |
241 | return $allknown | |
242 | } | |
243 | ||
244 | proc parseviewrevs {view revs} { | |
245 | global vposids vnegids | |
246 | ||
247 | if {$revs eq {}} { | |
248 | set revs HEAD | |
249 | } | |
250 | if {[catch {set ids [eval exec git rev-parse $revs]} err]} { | |
251 | # we get stdout followed by stderr in $err | |
252 | # for an unknown rev, git rev-parse echoes it and then errors out | |
253 | set errlines [split $err "\n"] | |
254 | set badrev {} | |
255 | for {set l 0} {$l < [llength $errlines]} {incr l} { | |
256 | set line [lindex $errlines $l] | |
257 | if {!([string length $line] == 40 && [string is xdigit $line])} { | |
258 | if {[string match "fatal:*" $line]} { | |
259 | if {[string match "fatal: ambiguous argument*" $line] | |
260 | && $badrev ne {}} { | |
261 | if {[llength $badrev] == 1} { | |
262 | set err "unknown revision $badrev" | |
263 | } else { | |
264 | set err "unknown revisions: [join $badrev ", "]" | |
265 | } | |
266 | } else { | |
267 | set err [join [lrange $errlines $l end] "\n"] | |
268 | } | |
269 | break | |
270 | } | |
271 | lappend badrev $line | |
272 | } | |
d93f1713 | 273 | } |
3945d2c0 | 274 | error_popup "[mc "Error parsing revisions:"] $err" |
ee66e089 PM |
275 | return {} |
276 | } | |
277 | set ret {} | |
278 | set pos {} | |
279 | set neg {} | |
280 | set sdm 0 | |
281 | foreach id [split $ids "\n"] { | |
282 | if {$id eq "--gitk-symmetric-diff-marker"} { | |
283 | set sdm 4 | |
284 | } elseif {[string match "^*" $id]} { | |
285 | if {$sdm != 1} { | |
286 | lappend ret $id | |
287 | if {$sdm == 3} { | |
288 | set sdm 0 | |
289 | } | |
290 | } | |
291 | lappend neg [string range $id 1 end] | |
292 | } else { | |
293 | if {$sdm != 2} { | |
294 | lappend ret $id | |
295 | } else { | |
2b1fbf90 | 296 | lset ret end $id...[lindex $ret end] |
3ed31a81 | 297 | } |
ee66e089 | 298 | lappend pos $id |
3ed31a81 | 299 | } |
ee66e089 | 300 | incr sdm -1 |
3ed31a81 | 301 | } |
ee66e089 PM |
302 | set vposids($view) $pos |
303 | set vnegids($view) $neg | |
304 | return $ret | |
3ed31a81 PM |
305 | } |
306 | ||
f9e0b6fb | 307 | # Start off a git log process and arrange to read its output |
da7c24dd | 308 | proc start_rev_list {view} { |
6df7403a | 309 | global startmsecs commitidx viewcomplete curview |
e439e092 | 310 | global tclencoding |
ee66e089 | 311 | global viewargs viewargscmd viewfiles vfilelimit |
d375ef9b | 312 | global showlocalchanges |
e439e092 | 313 | global viewactive viewinstances vmergeonly |
cdc8429c | 314 | global mainheadid viewmainheadid viewmainheadid_orig |
ee66e089 | 315 | global vcanopt vflags vrevs vorigargs |
9ccbdfbf | 316 | |
9ccbdfbf | 317 | set startmsecs [clock clicks -milliseconds] |
da7c24dd | 318 | set commitidx($view) 0 |
3ed31a81 PM |
319 | # these are set this way for the error exits |
320 | set viewcomplete($view) 1 | |
321 | set viewactive($view) 0 | |
7fcc92bf PM |
322 | varcinit $view |
323 | ||
2d480856 YD |
324 | set args $viewargs($view) |
325 | if {$viewargscmd($view) ne {}} { | |
326 | if {[catch { | |
327 | set str [exec sh -c $viewargscmd($view)] | |
328 | } err]} { | |
3945d2c0 | 329 | error_popup "[mc "Error executing --argscmd command:"] $err" |
3ed31a81 | 330 | return 0 |
2d480856 YD |
331 | } |
332 | set args [concat $args [split $str "\n"]] | |
333 | } | |
ee66e089 | 334 | set vcanopt($view) [parseviewargs $view $args] |
3ed31a81 PM |
335 | |
336 | set files $viewfiles($view) | |
337 | if {$vmergeonly($view)} { | |
338 | set files [unmerged_files $files] | |
339 | if {$files eq {}} { | |
340 | global nr_unmerged | |
341 | if {$nr_unmerged == 0} { | |
342 | error_popup [mc "No files selected: --merge specified but\ | |
343 | no files are unmerged."] | |
344 | } else { | |
345 | error_popup [mc "No files selected: --merge specified but\ | |
346 | no unmerged files are within file limit."] | |
347 | } | |
348 | return 0 | |
349 | } | |
350 | } | |
351 | set vfilelimit($view) $files | |
352 | ||
ee66e089 PM |
353 | if {$vcanopt($view)} { |
354 | set revs [parseviewrevs $view $vrevs($view)] | |
355 | if {$revs eq {}} { | |
356 | return 0 | |
357 | } | |
358 | set args [concat $vflags($view) $revs] | |
359 | } else { | |
360 | set args $vorigargs($view) | |
361 | } | |
362 | ||
418c4c7b | 363 | if {[catch { |
7fcc92bf | 364 | set fd [open [concat | git log --no-color -z --pretty=raw --parents \ |
3ed31a81 | 365 | --boundary $args "--" $files] r] |
418c4c7b | 366 | } err]} { |
00abadb9 | 367 | error_popup "[mc "Error executing git log:"] $err" |
3ed31a81 | 368 | return 0 |
1d10f36d | 369 | } |
e439e092 | 370 | set i [reg_instance $fd] |
7fcc92bf | 371 | set viewinstances($view) [list $i] |
cdc8429c PM |
372 | set viewmainheadid($view) $mainheadid |
373 | set viewmainheadid_orig($view) $mainheadid | |
374 | if {$files ne {} && $mainheadid ne {}} { | |
375 | get_viewmainhead $view | |
376 | } | |
377 | if {$showlocalchanges && $viewmainheadid($view) ne {}} { | |
378 | interestedin $viewmainheadid($view) dodiffindex | |
3e6b893f | 379 | } |
86da5b6c | 380 | fconfigure $fd -blocking 0 -translation lf -eofchar {} |
fd8ccbec | 381 | if {$tclencoding != {}} { |
da7c24dd | 382 | fconfigure $fd -encoding $tclencoding |
fd8ccbec | 383 | } |
f806f0fb | 384 | filerun $fd [list getcommitlines $fd $i $view 0] |
d990cedf | 385 | nowbusy $view [mc "Reading"] |
3ed31a81 PM |
386 | set viewcomplete($view) 0 |
387 | set viewactive($view) 1 | |
388 | return 1 | |
38ad0910 PM |
389 | } |
390 | ||
e2f90ee4 AG |
391 | proc stop_instance {inst} { |
392 | global commfd leftover | |
393 | ||
394 | set fd $commfd($inst) | |
395 | catch { | |
396 | set pid [pid $fd] | |
b6326e92 AG |
397 | |
398 | if {$::tcl_platform(platform) eq {windows}} { | |
399 | exec kill -f $pid | |
400 | } else { | |
401 | exec kill $pid | |
402 | } | |
e2f90ee4 AG |
403 | } |
404 | catch {close $fd} | |
405 | nukefile $fd | |
406 | unset commfd($inst) | |
407 | unset leftover($inst) | |
408 | } | |
409 | ||
410 | proc stop_backends {} { | |
411 | global commfd | |
412 | ||
413 | foreach inst [array names commfd] { | |
414 | stop_instance $inst | |
415 | } | |
416 | } | |
417 | ||
7fcc92bf | 418 | proc stop_rev_list {view} { |
e2f90ee4 | 419 | global viewinstances |
22626ef4 | 420 | |
7fcc92bf | 421 | foreach inst $viewinstances($view) { |
e2f90ee4 | 422 | stop_instance $inst |
22626ef4 | 423 | } |
7fcc92bf | 424 | set viewinstances($view) {} |
22626ef4 PM |
425 | } |
426 | ||
567c34e0 | 427 | proc reset_pending_select {selid} { |
39816d60 | 428 | global pending_select mainheadid selectheadid |
567c34e0 AG |
429 | |
430 | if {$selid ne {}} { | |
431 | set pending_select $selid | |
39816d60 AG |
432 | } elseif {$selectheadid ne {}} { |
433 | set pending_select $selectheadid | |
567c34e0 AG |
434 | } else { |
435 | set pending_select $mainheadid | |
436 | } | |
437 | } | |
438 | ||
439 | proc getcommits {selid} { | |
3ed31a81 | 440 | global canv curview need_redisplay viewactive |
38ad0910 | 441 | |
da7c24dd | 442 | initlayout |
3ed31a81 | 443 | if {[start_rev_list $curview]} { |
567c34e0 | 444 | reset_pending_select $selid |
3ed31a81 PM |
445 | show_status [mc "Reading commits..."] |
446 | set need_redisplay 1 | |
447 | } else { | |
448 | show_status [mc "No commits selected"] | |
449 | } | |
1d10f36d PM |
450 | } |
451 | ||
7fcc92bf | 452 | proc updatecommits {} { |
ee66e089 | 453 | global curview vcanopt vorigargs vfilelimit viewinstances |
e439e092 AG |
454 | global viewactive viewcomplete tclencoding |
455 | global startmsecs showneartags showlocalchanges | |
cdc8429c | 456 | global mainheadid viewmainheadid viewmainheadid_orig pending_select |
92e22ca0 | 457 | global isworktree |
ee66e089 | 458 | global varcid vposids vnegids vflags vrevs |
7fcc92bf | 459 | |
92e22ca0 | 460 | set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}] |
fc2a256f | 461 | rereadrefs |
cdc8429c PM |
462 | set view $curview |
463 | if {$mainheadid ne $viewmainheadid_orig($view)} { | |
464 | if {$showlocalchanges} { | |
eb5f8c9c PM |
465 | dohidelocalchanges |
466 | } | |
cdc8429c PM |
467 | set viewmainheadid($view) $mainheadid |
468 | set viewmainheadid_orig($view) $mainheadid | |
469 | if {$vfilelimit($view) ne {}} { | |
470 | get_viewmainhead $view | |
eb5f8c9c PM |
471 | } |
472 | } | |
cdc8429c PM |
473 | if {$showlocalchanges} { |
474 | doshowlocalchanges | |
475 | } | |
ee66e089 PM |
476 | if {$vcanopt($view)} { |
477 | set oldpos $vposids($view) | |
478 | set oldneg $vnegids($view) | |
479 | set revs [parseviewrevs $view $vrevs($view)] | |
480 | if {$revs eq {}} { | |
481 | return | |
482 | } | |
483 | # note: getting the delta when negative refs change is hard, | |
484 | # and could require multiple git log invocations, so in that | |
485 | # case we ask git log for all the commits (not just the delta) | |
486 | if {$oldneg eq $vnegids($view)} { | |
487 | set newrevs {} | |
488 | set npos 0 | |
489 | # take out positive refs that we asked for before or | |
490 | # that we have already seen | |
491 | foreach rev $revs { | |
492 | if {[string length $rev] == 40} { | |
493 | if {[lsearch -exact $oldpos $rev] < 0 | |
494 | && ![info exists varcid($view,$rev)]} { | |
495 | lappend newrevs $rev | |
496 | incr npos | |
497 | } | |
498 | } else { | |
499 | lappend $newrevs $rev | |
500 | } | |
501 | } | |
502 | if {$npos == 0} return | |
503 | set revs $newrevs | |
504 | set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]] | |
505 | } | |
506 | set args [concat $vflags($view) $revs --not $oldpos] | |
507 | } else { | |
508 | set args $vorigargs($view) | |
509 | } | |
7fcc92bf PM |
510 | if {[catch { |
511 | set fd [open [concat | git log --no-color -z --pretty=raw --parents \ | |
ee66e089 | 512 | --boundary $args "--" $vfilelimit($view)] r] |
7fcc92bf | 513 | } err]} { |
3945d2c0 | 514 | error_popup "[mc "Error executing git log:"] $err" |
ee66e089 | 515 | return |
7fcc92bf PM |
516 | } |
517 | if {$viewactive($view) == 0} { | |
518 | set startmsecs [clock clicks -milliseconds] | |
519 | } | |
e439e092 | 520 | set i [reg_instance $fd] |
7fcc92bf | 521 | lappend viewinstances($view) $i |
7fcc92bf PM |
522 | fconfigure $fd -blocking 0 -translation lf -eofchar {} |
523 | if {$tclencoding != {}} { | |
524 | fconfigure $fd -encoding $tclencoding | |
525 | } | |
f806f0fb | 526 | filerun $fd [list getcommitlines $fd $i $view 1] |
7fcc92bf PM |
527 | incr viewactive($view) |
528 | set viewcomplete($view) 0 | |
567c34e0 | 529 | reset_pending_select {} |
b56e0a9a | 530 | nowbusy $view [mc "Reading"] |
7fcc92bf PM |
531 | if {$showneartags} { |
532 | getallcommits | |
533 | } | |
534 | } | |
535 | ||
536 | proc reloadcommits {} { | |
537 | global curview viewcomplete selectedline currentid thickerline | |
538 | global showneartags treediffs commitinterest cached_commitrow | |
6df7403a | 539 | global targetid |
7fcc92bf | 540 | |
567c34e0 AG |
541 | set selid {} |
542 | if {$selectedline ne {}} { | |
543 | set selid $currentid | |
544 | } | |
545 | ||
7fcc92bf PM |
546 | if {!$viewcomplete($curview)} { |
547 | stop_rev_list $curview | |
7fcc92bf PM |
548 | } |
549 | resetvarcs $curview | |
94b4a69f | 550 | set selectedline {} |
7fcc92bf PM |
551 | catch {unset currentid} |
552 | catch {unset thickerline} | |
553 | catch {unset treediffs} | |
554 | readrefs | |
555 | changedrefs | |
556 | if {$showneartags} { | |
557 | getallcommits | |
558 | } | |
559 | clear_display | |
560 | catch {unset commitinterest} | |
561 | catch {unset cached_commitrow} | |
42a671fc | 562 | catch {unset targetid} |
7fcc92bf | 563 | setcanvscroll |
567c34e0 | 564 | getcommits $selid |
e7297a1c | 565 | return 0 |
7fcc92bf PM |
566 | } |
567 | ||
6e8c8707 PM |
568 | # This makes a string representation of a positive integer which |
569 | # sorts as a string in numerical order | |
570 | proc strrep {n} { | |
571 | if {$n < 16} { | |
572 | return [format "%x" $n] | |
573 | } elseif {$n < 256} { | |
574 | return [format "x%.2x" $n] | |
575 | } elseif {$n < 65536} { | |
576 | return [format "y%.4x" $n] | |
577 | } | |
578 | return [format "z%.8x" $n] | |
579 | } | |
580 | ||
7fcc92bf PM |
581 | # Procedures used in reordering commits from git log (without |
582 | # --topo-order) into the order for display. | |
583 | ||
584 | proc varcinit {view} { | |
f3ea5ede PM |
585 | global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow |
586 | global vtokmod varcmod vrowmod varcix vlastins | |
7fcc92bf | 587 | |
7fcc92bf PM |
588 | set varcstart($view) {{}} |
589 | set vupptr($view) {0} | |
590 | set vdownptr($view) {0} | |
591 | set vleftptr($view) {0} | |
f3ea5ede | 592 | set vbackptr($view) {0} |
7fcc92bf PM |
593 | set varctok($view) {{}} |
594 | set varcrow($view) {{}} | |
595 | set vtokmod($view) {} | |
596 | set varcmod($view) 0 | |
e5b37ac1 | 597 | set vrowmod($view) 0 |
7fcc92bf | 598 | set varcix($view) {{}} |
f3ea5ede | 599 | set vlastins($view) {0} |
7fcc92bf PM |
600 | } |
601 | ||
602 | proc resetvarcs {view} { | |
603 | global varcid varccommits parents children vseedcount ordertok | |
604 | ||
605 | foreach vid [array names varcid $view,*] { | |
606 | unset varcid($vid) | |
607 | unset children($vid) | |
608 | unset parents($vid) | |
609 | } | |
610 | # some commits might have children but haven't been seen yet | |
611 | foreach vid [array names children $view,*] { | |
612 | unset children($vid) | |
613 | } | |
614 | foreach va [array names varccommits $view,*] { | |
615 | unset varccommits($va) | |
616 | } | |
617 | foreach vd [array names vseedcount $view,*] { | |
618 | unset vseedcount($vd) | |
619 | } | |
9257d8f7 | 620 | catch {unset ordertok} |
7fcc92bf PM |
621 | } |
622 | ||
468bcaed PM |
623 | # returns a list of the commits with no children |
624 | proc seeds {v} { | |
625 | global vdownptr vleftptr varcstart | |
626 | ||
627 | set ret {} | |
628 | set a [lindex $vdownptr($v) 0] | |
629 | while {$a != 0} { | |
630 | lappend ret [lindex $varcstart($v) $a] | |
631 | set a [lindex $vleftptr($v) $a] | |
632 | } | |
633 | return $ret | |
634 | } | |
635 | ||
7fcc92bf | 636 | proc newvarc {view id} { |
3ed31a81 | 637 | global varcid varctok parents children vdatemode |
f3ea5ede PM |
638 | global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart |
639 | global commitdata commitinfo vseedcount varccommits vlastins | |
7fcc92bf PM |
640 | |
641 | set a [llength $varctok($view)] | |
642 | set vid $view,$id | |
3ed31a81 | 643 | if {[llength $children($vid)] == 0 || $vdatemode($view)} { |
7fcc92bf PM |
644 | if {![info exists commitinfo($id)]} { |
645 | parsecommit $id $commitdata($id) 1 | |
646 | } | |
647 | set cdate [lindex $commitinfo($id) 4] | |
648 | if {![string is integer -strict $cdate]} { | |
649 | set cdate 0 | |
650 | } | |
651 | if {![info exists vseedcount($view,$cdate)]} { | |
652 | set vseedcount($view,$cdate) -1 | |
653 | } | |
654 | set c [incr vseedcount($view,$cdate)] | |
655 | set cdate [expr {$cdate ^ 0xffffffff}] | |
656 | set tok "s[strrep $cdate][strrep $c]" | |
7fcc92bf PM |
657 | } else { |
658 | set tok {} | |
f3ea5ede PM |
659 | } |
660 | set ka 0 | |
661 | if {[llength $children($vid)] > 0} { | |
662 | set kid [lindex $children($vid) end] | |
663 | set k $varcid($view,$kid) | |
664 | if {[string compare [lindex $varctok($view) $k] $tok] > 0} { | |
665 | set ki $kid | |
666 | set ka $k | |
667 | set tok [lindex $varctok($view) $k] | |
7fcc92bf | 668 | } |
f3ea5ede PM |
669 | } |
670 | if {$ka != 0} { | |
7fcc92bf PM |
671 | set i [lsearch -exact $parents($view,$ki) $id] |
672 | set j [expr {[llength $parents($view,$ki)] - 1 - $i}] | |
7fcc92bf PM |
673 | append tok [strrep $j] |
674 | } | |
f3ea5ede PM |
675 | set c [lindex $vlastins($view) $ka] |
676 | if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} { | |
677 | set c $ka | |
678 | set b [lindex $vdownptr($view) $ka] | |
679 | } else { | |
680 | set b [lindex $vleftptr($view) $c] | |
681 | } | |
682 | while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} { | |
683 | set c $b | |
684 | set b [lindex $vleftptr($view) $c] | |
685 | } | |
686 | if {$c == $ka} { | |
687 | lset vdownptr($view) $ka $a | |
688 | lappend vbackptr($view) 0 | |
689 | } else { | |
690 | lset vleftptr($view) $c $a | |
691 | lappend vbackptr($view) $c | |
692 | } | |
693 | lset vlastins($view) $ka $a | |
694 | lappend vupptr($view) $ka | |
695 | lappend vleftptr($view) $b | |
696 | if {$b != 0} { | |
697 | lset vbackptr($view) $b $a | |
698 | } | |
7fcc92bf PM |
699 | lappend varctok($view) $tok |
700 | lappend varcstart($view) $id | |
701 | lappend vdownptr($view) 0 | |
702 | lappend varcrow($view) {} | |
703 | lappend varcix($view) {} | |
e5b37ac1 | 704 | set varccommits($view,$a) {} |
f3ea5ede | 705 | lappend vlastins($view) 0 |
7fcc92bf PM |
706 | return $a |
707 | } | |
708 | ||
709 | proc splitvarc {p v} { | |
52b8ea93 | 710 | global varcid varcstart varccommits varctok vtokmod |
f3ea5ede | 711 | global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins |
7fcc92bf PM |
712 | |
713 | set oa $varcid($v,$p) | |
52b8ea93 | 714 | set otok [lindex $varctok($v) $oa] |
7fcc92bf PM |
715 | set ac $varccommits($v,$oa) |
716 | set i [lsearch -exact $varccommits($v,$oa) $p] | |
717 | if {$i <= 0} return | |
718 | set na [llength $varctok($v)] | |
719 | # "%" sorts before "0"... | |
52b8ea93 | 720 | set tok "$otok%[strrep $i]" |
7fcc92bf PM |
721 | lappend varctok($v) $tok |
722 | lappend varcrow($v) {} | |
723 | lappend varcix($v) {} | |
724 | set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]] | |
725 | set varccommits($v,$na) [lrange $ac $i end] | |
726 | lappend varcstart($v) $p | |
727 | foreach id $varccommits($v,$na) { | |
728 | set varcid($v,$id) $na | |
729 | } | |
730 | lappend vdownptr($v) [lindex $vdownptr($v) $oa] | |
841ea824 | 731 | lappend vlastins($v) [lindex $vlastins($v) $oa] |
7fcc92bf | 732 | lset vdownptr($v) $oa $na |
841ea824 | 733 | lset vlastins($v) $oa 0 |
7fcc92bf PM |
734 | lappend vupptr($v) $oa |
735 | lappend vleftptr($v) 0 | |
f3ea5ede | 736 | lappend vbackptr($v) 0 |
7fcc92bf PM |
737 | for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} { |
738 | lset vupptr($v) $b $na | |
739 | } | |
52b8ea93 PM |
740 | if {[string compare $otok $vtokmod($v)] <= 0} { |
741 | modify_arc $v $oa | |
742 | } | |
7fcc92bf PM |
743 | } |
744 | ||
745 | proc renumbervarc {a v} { | |
746 | global parents children varctok varcstart varccommits | |
3ed31a81 | 747 | global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode |
7fcc92bf PM |
748 | |
749 | set t1 [clock clicks -milliseconds] | |
750 | set todo {} | |
751 | set isrelated($a) 1 | |
f3ea5ede | 752 | set kidchanged($a) 1 |
7fcc92bf PM |
753 | set ntot 0 |
754 | while {$a != 0} { | |
755 | if {[info exists isrelated($a)]} { | |
756 | lappend todo $a | |
757 | set id [lindex $varccommits($v,$a) end] | |
758 | foreach p $parents($v,$id) { | |
759 | if {[info exists varcid($v,$p)]} { | |
760 | set isrelated($varcid($v,$p)) 1 | |
761 | } | |
762 | } | |
763 | } | |
764 | incr ntot | |
765 | set b [lindex $vdownptr($v) $a] | |
766 | if {$b == 0} { | |
767 | while {$a != 0} { | |
768 | set b [lindex $vleftptr($v) $a] | |
769 | if {$b != 0} break | |
770 | set a [lindex $vupptr($v) $a] | |
771 | } | |
772 | } | |
773 | set a $b | |
774 | } | |
775 | foreach a $todo { | |
f3ea5ede | 776 | if {![info exists kidchanged($a)]} continue |
7fcc92bf | 777 | set id [lindex $varcstart($v) $a] |
f3ea5ede PM |
778 | if {[llength $children($v,$id)] > 1} { |
779 | set children($v,$id) [lsort -command [list vtokcmp $v] \ | |
780 | $children($v,$id)] | |
781 | } | |
782 | set oldtok [lindex $varctok($v) $a] | |
3ed31a81 | 783 | if {!$vdatemode($v)} { |
f3ea5ede PM |
784 | set tok {} |
785 | } else { | |
786 | set tok $oldtok | |
787 | } | |
788 | set ka 0 | |
c8c9f3d9 PM |
789 | set kid [last_real_child $v,$id] |
790 | if {$kid ne {}} { | |
f3ea5ede PM |
791 | set k $varcid($v,$kid) |
792 | if {[string compare [lindex $varctok($v) $k] $tok] > 0} { | |
793 | set ki $kid | |
794 | set ka $k | |
795 | set tok [lindex $varctok($v) $k] | |
7fcc92bf PM |
796 | } |
797 | } | |
f3ea5ede | 798 | if {$ka != 0} { |
7fcc92bf PM |
799 | set i [lsearch -exact $parents($v,$ki) $id] |
800 | set j [expr {[llength $parents($v,$ki)] - 1 - $i}] | |
801 | append tok [strrep $j] | |
7fcc92bf | 802 | } |
f3ea5ede PM |
803 | if {$tok eq $oldtok} { |
804 | continue | |
805 | } | |
806 | set id [lindex $varccommits($v,$a) end] | |
807 | foreach p $parents($v,$id) { | |
808 | if {[info exists varcid($v,$p)]} { | |
809 | set kidchanged($varcid($v,$p)) 1 | |
810 | } else { | |
811 | set sortkids($p) 1 | |
812 | } | |
813 | } | |
814 | lset varctok($v) $a $tok | |
7fcc92bf PM |
815 | set b [lindex $vupptr($v) $a] |
816 | if {$b != $ka} { | |
9257d8f7 PM |
817 | if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} { |
818 | modify_arc $v $ka | |
38dfe939 | 819 | } |
9257d8f7 PM |
820 | if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} { |
821 | modify_arc $v $b | |
38dfe939 | 822 | } |
f3ea5ede PM |
823 | set c [lindex $vbackptr($v) $a] |
824 | set d [lindex $vleftptr($v) $a] | |
825 | if {$c == 0} { | |
826 | lset vdownptr($v) $b $d | |
7fcc92bf | 827 | } else { |
f3ea5ede PM |
828 | lset vleftptr($v) $c $d |
829 | } | |
830 | if {$d != 0} { | |
831 | lset vbackptr($v) $d $c | |
7fcc92bf | 832 | } |
841ea824 PM |
833 | if {[lindex $vlastins($v) $b] == $a} { |
834 | lset vlastins($v) $b $c | |
835 | } | |
7fcc92bf | 836 | lset vupptr($v) $a $ka |
f3ea5ede PM |
837 | set c [lindex $vlastins($v) $ka] |
838 | if {$c == 0 || \ | |
839 | [string compare $tok [lindex $varctok($v) $c]] < 0} { | |
840 | set c $ka | |
841 | set b [lindex $vdownptr($v) $ka] | |
842 | } else { | |
843 | set b [lindex $vleftptr($v) $c] | |
844 | } | |
845 | while {$b != 0 && \ | |
846 | [string compare $tok [lindex $varctok($v) $b]] >= 0} { | |
847 | set c $b | |
848 | set b [lindex $vleftptr($v) $c] | |
7fcc92bf | 849 | } |
f3ea5ede PM |
850 | if {$c == $ka} { |
851 | lset vdownptr($v) $ka $a | |
852 | lset vbackptr($v) $a 0 | |
853 | } else { | |
854 | lset vleftptr($v) $c $a | |
855 | lset vbackptr($v) $a $c | |
7fcc92bf | 856 | } |
f3ea5ede PM |
857 | lset vleftptr($v) $a $b |
858 | if {$b != 0} { | |
859 | lset vbackptr($v) $b $a | |
860 | } | |
861 | lset vlastins($v) $ka $a | |
862 | } | |
863 | } | |
864 | foreach id [array names sortkids] { | |
865 | if {[llength $children($v,$id)] > 1} { | |
866 | set children($v,$id) [lsort -command [list vtokcmp $v] \ | |
867 | $children($v,$id)] | |
7fcc92bf PM |
868 | } |
869 | } | |
870 | set t2 [clock clicks -milliseconds] | |
871 | #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms" | |
872 | } | |
873 | ||
f806f0fb PM |
874 | # Fix up the graph after we have found out that in view $v, |
875 | # $p (a commit that we have already seen) is actually the parent | |
876 | # of the last commit in arc $a. | |
7fcc92bf | 877 | proc fix_reversal {p a v} { |
24f7a667 | 878 | global varcid varcstart varctok vupptr |
7fcc92bf PM |
879 | |
880 | set pa $varcid($v,$p) | |
881 | if {$p ne [lindex $varcstart($v) $pa]} { | |
882 | splitvarc $p $v | |
883 | set pa $varcid($v,$p) | |
884 | } | |
24f7a667 PM |
885 | # seeds always need to be renumbered |
886 | if {[lindex $vupptr($v) $pa] == 0 || | |
887 | [string compare [lindex $varctok($v) $a] \ | |
888 | [lindex $varctok($v) $pa]] > 0} { | |
7fcc92bf PM |
889 | renumbervarc $pa $v |
890 | } | |
891 | } | |
892 | ||
893 | proc insertrow {id p v} { | |
b8a938cf PM |
894 | global cmitlisted children parents varcid varctok vtokmod |
895 | global varccommits ordertok commitidx numcommits curview | |
896 | global targetid targetrow | |
897 | ||
898 | readcommit $id | |
899 | set vid $v,$id | |
900 | set cmitlisted($vid) 1 | |
901 | set children($vid) {} | |
902 | set parents($vid) [list $p] | |
903 | set a [newvarc $v $id] | |
904 | set varcid($vid) $a | |
905 | if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} { | |
906 | modify_arc $v $a | |
907 | } | |
908 | lappend varccommits($v,$a) $id | |
909 | set vp $v,$p | |
910 | if {[llength [lappend children($vp) $id]] > 1} { | |
911 | set children($vp) [lsort -command [list vtokcmp $v] $children($vp)] | |
912 | catch {unset ordertok} | |
913 | } | |
914 | fix_reversal $p $a $v | |
915 | incr commitidx($v) | |
916 | if {$v == $curview} { | |
917 | set numcommits $commitidx($v) | |
918 | setcanvscroll | |
919 | if {[info exists targetid]} { | |
920 | if {![comes_before $targetid $p]} { | |
921 | incr targetrow | |
922 | } | |
923 | } | |
924 | } | |
925 | } | |
926 | ||
927 | proc insertfakerow {id p} { | |
9257d8f7 | 928 | global varcid varccommits parents children cmitlisted |
b8a938cf | 929 | global commitidx varctok vtokmod targetid targetrow curview numcommits |
7fcc92bf | 930 | |
b8a938cf | 931 | set v $curview |
7fcc92bf PM |
932 | set a $varcid($v,$p) |
933 | set i [lsearch -exact $varccommits($v,$a) $p] | |
934 | if {$i < 0} { | |
b8a938cf | 935 | puts "oops: insertfakerow can't find [shortids $p] on arc $a" |
7fcc92bf PM |
936 | return |
937 | } | |
938 | set children($v,$id) {} | |
939 | set parents($v,$id) [list $p] | |
940 | set varcid($v,$id) $a | |
9257d8f7 | 941 | lappend children($v,$p) $id |
7fcc92bf | 942 | set cmitlisted($v,$id) 1 |
b8a938cf | 943 | set numcommits [incr commitidx($v)] |
7fcc92bf PM |
944 | # note we deliberately don't update varcstart($v) even if $i == 0 |
945 | set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id] | |
c9cfdc96 | 946 | modify_arc $v $a $i |
42a671fc PM |
947 | if {[info exists targetid]} { |
948 | if {![comes_before $targetid $p]} { | |
949 | incr targetrow | |
950 | } | |
951 | } | |
b8a938cf | 952 | setcanvscroll |
9257d8f7 | 953 | drawvisible |
7fcc92bf PM |
954 | } |
955 | ||
b8a938cf | 956 | proc removefakerow {id} { |
9257d8f7 | 957 | global varcid varccommits parents children commitidx |
fc2a256f | 958 | global varctok vtokmod cmitlisted currentid selectedline |
b8a938cf | 959 | global targetid curview numcommits |
7fcc92bf | 960 | |
b8a938cf | 961 | set v $curview |
7fcc92bf | 962 | if {[llength $parents($v,$id)] != 1} { |
b8a938cf | 963 | puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents" |
7fcc92bf PM |
964 | return |
965 | } | |
966 | set p [lindex $parents($v,$id) 0] | |
967 | set a $varcid($v,$id) | |
968 | set i [lsearch -exact $varccommits($v,$a) $id] | |
969 | if {$i < 0} { | |
b8a938cf | 970 | puts "oops: removefakerow can't find [shortids $id] on arc $a" |
7fcc92bf PM |
971 | return |
972 | } | |
973 | unset varcid($v,$id) | |
974 | set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i] | |
975 | unset parents($v,$id) | |
976 | unset children($v,$id) | |
977 | unset cmitlisted($v,$id) | |
b8a938cf | 978 | set numcommits [incr commitidx($v) -1] |
7fcc92bf PM |
979 | set j [lsearch -exact $children($v,$p) $id] |
980 | if {$j >= 0} { | |
981 | set children($v,$p) [lreplace $children($v,$p) $j $j] | |
982 | } | |
c9cfdc96 | 983 | modify_arc $v $a $i |
fc2a256f PM |
984 | if {[info exist currentid] && $id eq $currentid} { |
985 | unset currentid | |
94b4a69f | 986 | set selectedline {} |
fc2a256f | 987 | } |
42a671fc PM |
988 | if {[info exists targetid] && $targetid eq $id} { |
989 | set targetid $p | |
990 | } | |
b8a938cf | 991 | setcanvscroll |
9257d8f7 | 992 | drawvisible |
7fcc92bf PM |
993 | } |
994 | ||
aa43561a PM |
995 | proc real_children {vp} { |
996 | global children nullid nullid2 | |
997 | ||
998 | set kids {} | |
999 | foreach id $children($vp) { | |
1000 | if {$id ne $nullid && $id ne $nullid2} { | |
1001 | lappend kids $id | |
1002 | } | |
1003 | } | |
1004 | return $kids | |
1005 | } | |
1006 | ||
c8c9f3d9 PM |
1007 | proc first_real_child {vp} { |
1008 | global children nullid nullid2 | |
1009 | ||
1010 | foreach id $children($vp) { | |
1011 | if {$id ne $nullid && $id ne $nullid2} { | |
1012 | return $id | |
1013 | } | |
1014 | } | |
1015 | return {} | |
1016 | } | |
1017 | ||
1018 | proc last_real_child {vp} { | |
1019 | global children nullid nullid2 | |
1020 | ||
1021 | set kids $children($vp) | |
1022 | for {set i [llength $kids]} {[incr i -1] >= 0} {} { | |
1023 | set id [lindex $kids $i] | |
1024 | if {$id ne $nullid && $id ne $nullid2} { | |
1025 | return $id | |
1026 | } | |
1027 | } | |
1028 | return {} | |
1029 | } | |
1030 | ||
7fcc92bf PM |
1031 | proc vtokcmp {v a b} { |
1032 | global varctok varcid | |
1033 | ||
1034 | return [string compare [lindex $varctok($v) $varcid($v,$a)] \ | |
1035 | [lindex $varctok($v) $varcid($v,$b)]] | |
1036 | } | |
1037 | ||
c9cfdc96 PM |
1038 | # This assumes that if lim is not given, the caller has checked that |
1039 | # arc a's token is less than $vtokmod($v) | |
e5b37ac1 PM |
1040 | proc modify_arc {v a {lim {}}} { |
1041 | global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits | |
9257d8f7 | 1042 | |
c9cfdc96 PM |
1043 | if {$lim ne {}} { |
1044 | set c [string compare [lindex $varctok($v) $a] $vtokmod($v)] | |
1045 | if {$c > 0} return | |
1046 | if {$c == 0} { | |
1047 | set r [lindex $varcrow($v) $a] | |
1048 | if {$r ne {} && $vrowmod($v) <= $r + $lim} return | |
1049 | } | |
1050 | } | |
9257d8f7 PM |
1051 | set vtokmod($v) [lindex $varctok($v) $a] |
1052 | set varcmod($v) $a | |
1053 | if {$v == $curview} { | |
1054 | while {$a != 0 && [lindex $varcrow($v) $a] eq {}} { | |
1055 | set a [lindex $vupptr($v) $a] | |
e5b37ac1 | 1056 | set lim {} |
9257d8f7 | 1057 | } |
e5b37ac1 PM |
1058 | set r 0 |
1059 | if {$a != 0} { | |
1060 | if {$lim eq {}} { | |
1061 | set lim [llength $varccommits($v,$a)] | |
1062 | } | |
1063 | set r [expr {[lindex $varcrow($v) $a] + $lim}] | |
1064 | } | |
1065 | set vrowmod($v) $r | |
0c27886e | 1066 | undolayout $r |
9257d8f7 PM |
1067 | } |
1068 | } | |
1069 | ||
7fcc92bf | 1070 | proc update_arcrows {v} { |
e5b37ac1 | 1071 | global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline |
24f7a667 | 1072 | global varcid vrownum varcorder varcix varccommits |
7fcc92bf | 1073 | global vupptr vdownptr vleftptr varctok |
24f7a667 | 1074 | global displayorder parentlist curview cached_commitrow |
7fcc92bf | 1075 | |
c9cfdc96 PM |
1076 | if {$vrowmod($v) == $commitidx($v)} return |
1077 | if {$v == $curview} { | |
1078 | if {[llength $displayorder] > $vrowmod($v)} { | |
1079 | set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]] | |
1080 | set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]] | |
1081 | } | |
1082 | catch {unset cached_commitrow} | |
1083 | } | |
7fcc92bf PM |
1084 | set narctot [expr {[llength $varctok($v)] - 1}] |
1085 | set a $varcmod($v) | |
1086 | while {$a != 0 && [lindex $varcix($v) $a] eq {}} { | |
1087 | # go up the tree until we find something that has a row number, | |
1088 | # or we get to a seed | |
1089 | set a [lindex $vupptr($v) $a] | |
1090 | } | |
1091 | if {$a == 0} { | |
1092 | set a [lindex $vdownptr($v) 0] | |
1093 | if {$a == 0} return | |
1094 | set vrownum($v) {0} | |
1095 | set varcorder($v) [list $a] | |
1096 | lset varcix($v) $a 0 | |
1097 | lset varcrow($v) $a 0 | |
1098 | set arcn 0 | |
1099 | set row 0 | |
1100 | } else { | |
1101 | set arcn [lindex $varcix($v) $a] | |
7fcc92bf PM |
1102 | if {[llength $vrownum($v)] > $arcn + 1} { |
1103 | set vrownum($v) [lrange $vrownum($v) 0 $arcn] | |
1104 | set varcorder($v) [lrange $varcorder($v) 0 $arcn] | |
1105 | } | |
1106 | set row [lindex $varcrow($v) $a] | |
1107 | } | |
7fcc92bf PM |
1108 | while {1} { |
1109 | set p $a | |
1110 | incr row [llength $varccommits($v,$a)] | |
1111 | # go down if possible | |
1112 | set b [lindex $vdownptr($v) $a] | |
1113 | if {$b == 0} { | |
1114 | # if not, go left, or go up until we can go left | |
1115 | while {$a != 0} { | |
1116 | set b [lindex $vleftptr($v) $a] | |
1117 | if {$b != 0} break | |
1118 | set a [lindex $vupptr($v) $a] | |
1119 | } | |
1120 | if {$a == 0} break | |
1121 | } | |
1122 | set a $b | |
1123 | incr arcn | |
1124 | lappend vrownum($v) $row | |
1125 | lappend varcorder($v) $a | |
1126 | lset varcix($v) $a $arcn | |
1127 | lset varcrow($v) $a $row | |
1128 | } | |
e5b37ac1 PM |
1129 | set vtokmod($v) [lindex $varctok($v) $p] |
1130 | set varcmod($v) $p | |
1131 | set vrowmod($v) $row | |
7fcc92bf PM |
1132 | if {[info exists currentid]} { |
1133 | set selectedline [rowofcommit $currentid] | |
1134 | } | |
7fcc92bf PM |
1135 | } |
1136 | ||
1137 | # Test whether view $v contains commit $id | |
1138 | proc commitinview {id v} { | |
1139 | global varcid | |
1140 | ||
1141 | return [info exists varcid($v,$id)] | |
1142 | } | |
1143 | ||
1144 | # Return the row number for commit $id in the current view | |
1145 | proc rowofcommit {id} { | |
1146 | global varcid varccommits varcrow curview cached_commitrow | |
9257d8f7 | 1147 | global varctok vtokmod |
7fcc92bf | 1148 | |
7fcc92bf PM |
1149 | set v $curview |
1150 | if {![info exists varcid($v,$id)]} { | |
1151 | puts "oops rowofcommit no arc for [shortids $id]" | |
1152 | return {} | |
1153 | } | |
1154 | set a $varcid($v,$id) | |
fc2a256f | 1155 | if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} { |
9257d8f7 PM |
1156 | update_arcrows $v |
1157 | } | |
31c0eaa8 PM |
1158 | if {[info exists cached_commitrow($id)]} { |
1159 | return $cached_commitrow($id) | |
1160 | } | |
7fcc92bf PM |
1161 | set i [lsearch -exact $varccommits($v,$a) $id] |
1162 | if {$i < 0} { | |
1163 | puts "oops didn't find commit [shortids $id] in arc $a" | |
1164 | return {} | |
1165 | } | |
1166 | incr i [lindex $varcrow($v) $a] | |
1167 | set cached_commitrow($id) $i | |
1168 | return $i | |
1169 | } | |
1170 | ||
42a671fc PM |
1171 | # Returns 1 if a is on an earlier row than b, otherwise 0 |
1172 | proc comes_before {a b} { | |
1173 | global varcid varctok curview | |
1174 | ||
1175 | set v $curview | |
1176 | if {$a eq $b || ![info exists varcid($v,$a)] || \ | |
1177 | ![info exists varcid($v,$b)]} { | |
1178 | return 0 | |
1179 | } | |
1180 | if {$varcid($v,$a) != $varcid($v,$b)} { | |
1181 | return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \ | |
1182 | [lindex $varctok($v) $varcid($v,$b)]] < 0}] | |
1183 | } | |
1184 | return [expr {[rowofcommit $a] < [rowofcommit $b]}] | |
1185 | } | |
1186 | ||
7fcc92bf PM |
1187 | proc bsearch {l elt} { |
1188 | if {[llength $l] == 0 || $elt <= [lindex $l 0]} { | |
1189 | return 0 | |
1190 | } | |
1191 | set lo 0 | |
1192 | set hi [llength $l] | |
1193 | while {$hi - $lo > 1} { | |
1194 | set mid [expr {int(($lo + $hi) / 2)}] | |
1195 | set t [lindex $l $mid] | |
1196 | if {$elt < $t} { | |
1197 | set hi $mid | |
1198 | } elseif {$elt > $t} { | |
1199 | set lo $mid | |
1200 | } else { | |
1201 | return $mid | |
1202 | } | |
1203 | } | |
1204 | return $lo | |
1205 | } | |
1206 | ||
1207 | # Make sure rows $start..$end-1 are valid in displayorder and parentlist | |
1208 | proc make_disporder {start end} { | |
1209 | global vrownum curview commitidx displayorder parentlist | |
e5b37ac1 | 1210 | global varccommits varcorder parents vrowmod varcrow |
7fcc92bf PM |
1211 | global d_valid_start d_valid_end |
1212 | ||
e5b37ac1 | 1213 | if {$end > $vrowmod($curview)} { |
9257d8f7 PM |
1214 | update_arcrows $curview |
1215 | } | |
7fcc92bf PM |
1216 | set ai [bsearch $vrownum($curview) $start] |
1217 | set start [lindex $vrownum($curview) $ai] | |
1218 | set narc [llength $vrownum($curview)] | |
1219 | for {set r $start} {$ai < $narc && $r < $end} {incr ai} { | |
1220 | set a [lindex $varcorder($curview) $ai] | |
1221 | set l [llength $displayorder] | |
1222 | set al [llength $varccommits($curview,$a)] | |
1223 | if {$l < $r + $al} { | |
1224 | if {$l < $r} { | |
1225 | set pad [ntimes [expr {$r - $l}] {}] | |
1226 | set displayorder [concat $displayorder $pad] | |
1227 | set parentlist [concat $parentlist $pad] | |
1228 | } elseif {$l > $r} { | |
1229 | set displayorder [lrange $displayorder 0 [expr {$r - 1}]] | |
1230 | set parentlist [lrange $parentlist 0 [expr {$r - 1}]] | |
1231 | } | |
1232 | foreach id $varccommits($curview,$a) { | |
1233 | lappend displayorder $id | |
1234 | lappend parentlist $parents($curview,$id) | |
1235 | } | |
17529cf9 | 1236 | } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} { |
7fcc92bf PM |
1237 | set i $r |
1238 | foreach id $varccommits($curview,$a) { | |
1239 | lset displayorder $i $id | |
1240 | lset parentlist $i $parents($curview,$id) | |
1241 | incr i | |
1242 | } | |
1243 | } | |
1244 | incr r $al | |
1245 | } | |
1246 | } | |
1247 | ||
1248 | proc commitonrow {row} { | |
1249 | global displayorder | |
1250 | ||
1251 | set id [lindex $displayorder $row] | |
1252 | if {$id eq {}} { | |
1253 | make_disporder $row [expr {$row + 1}] | |
1254 | set id [lindex $displayorder $row] | |
1255 | } | |
1256 | return $id | |
1257 | } | |
1258 | ||
1259 | proc closevarcs {v} { | |
1260 | global varctok varccommits varcid parents children | |
d375ef9b | 1261 | global cmitlisted commitidx vtokmod |
7fcc92bf PM |
1262 | |
1263 | set missing_parents 0 | |
1264 | set scripts {} | |
1265 | set narcs [llength $varctok($v)] | |
1266 | for {set a 1} {$a < $narcs} {incr a} { | |
1267 | set id [lindex $varccommits($v,$a) end] | |
1268 | foreach p $parents($v,$id) { | |
1269 | if {[info exists varcid($v,$p)]} continue | |
1270 | # add p as a new commit | |
1271 | incr missing_parents | |
1272 | set cmitlisted($v,$p) 0 | |
1273 | set parents($v,$p) {} | |
1274 | if {[llength $children($v,$p)] == 1 && | |
1275 | [llength $parents($v,$id)] == 1} { | |
1276 | set b $a | |
1277 | } else { | |
1278 | set b [newvarc $v $p] | |
1279 | } | |
1280 | set varcid($v,$p) $b | |
9257d8f7 PM |
1281 | if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} { |
1282 | modify_arc $v $b | |
7fcc92bf | 1283 | } |
e5b37ac1 | 1284 | lappend varccommits($v,$b) $p |
7fcc92bf | 1285 | incr commitidx($v) |
d375ef9b | 1286 | set scripts [check_interest $p $scripts] |
7fcc92bf PM |
1287 | } |
1288 | } | |
1289 | if {$missing_parents > 0} { | |
7fcc92bf PM |
1290 | foreach s $scripts { |
1291 | eval $s | |
1292 | } | |
1293 | } | |
1294 | } | |
1295 | ||
f806f0fb PM |
1296 | # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid |
1297 | # Assumes we already have an arc for $rwid. | |
1298 | proc rewrite_commit {v id rwid} { | |
1299 | global children parents varcid varctok vtokmod varccommits | |
1300 | ||
1301 | foreach ch $children($v,$id) { | |
1302 | # make $rwid be $ch's parent in place of $id | |
1303 | set i [lsearch -exact $parents($v,$ch) $id] | |
1304 | if {$i < 0} { | |
1305 | puts "oops rewrite_commit didn't find $id in parent list for $ch" | |
1306 | } | |
1307 | set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid] | |
1308 | # add $ch to $rwid's children and sort the list if necessary | |
1309 | if {[llength [lappend children($v,$rwid) $ch]] > 1} { | |
1310 | set children($v,$rwid) [lsort -command [list vtokcmp $v] \ | |
1311 | $children($v,$rwid)] | |
1312 | } | |
1313 | # fix the graph after joining $id to $rwid | |
1314 | set a $varcid($v,$ch) | |
1315 | fix_reversal $rwid $a $v | |
c9cfdc96 PM |
1316 | # parentlist is wrong for the last element of arc $a |
1317 | # even if displayorder is right, hence the 3rd arg here | |
1318 | modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}] | |
f806f0fb PM |
1319 | } |
1320 | } | |
1321 | ||
d375ef9b PM |
1322 | # Mechanism for registering a command to be executed when we come |
1323 | # across a particular commit. To handle the case when only the | |
1324 | # prefix of the commit is known, the commitinterest array is now | |
1325 | # indexed by the first 4 characters of the ID. Each element is a | |
1326 | # list of id, cmd pairs. | |
1327 | proc interestedin {id cmd} { | |
1328 | global commitinterest | |
1329 | ||
1330 | lappend commitinterest([string range $id 0 3]) $id $cmd | |
1331 | } | |
1332 | ||
1333 | proc check_interest {id scripts} { | |
1334 | global commitinterest | |
1335 | ||
1336 | set prefix [string range $id 0 3] | |
1337 | if {[info exists commitinterest($prefix)]} { | |
1338 | set newlist {} | |
1339 | foreach {i script} $commitinterest($prefix) { | |
1340 | if {[string match "$i*" $id]} { | |
1341 | lappend scripts [string map [list "%I" $id "%P" $i] $script] | |
1342 | } else { | |
1343 | lappend newlist $i $script | |
1344 | } | |
1345 | } | |
1346 | if {$newlist ne {}} { | |
1347 | set commitinterest($prefix) $newlist | |
1348 | } else { | |
1349 | unset commitinterest($prefix) | |
1350 | } | |
1351 | } | |
1352 | return $scripts | |
1353 | } | |
1354 | ||
f806f0fb | 1355 | proc getcommitlines {fd inst view updating} { |
d375ef9b | 1356 | global cmitlisted leftover |
3ed31a81 | 1357 | global commitidx commitdata vdatemode |
7fcc92bf | 1358 | global parents children curview hlview |
468bcaed | 1359 | global idpending ordertok |
3ed31a81 | 1360 | global varccommits varcid varctok vtokmod vfilelimit |
9ccbdfbf | 1361 | |
d1e46756 | 1362 | set stuff [read $fd 500000] |
005a2f4e | 1363 | # git log doesn't terminate the last commit with a null... |
7fcc92bf | 1364 | if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} { |
005a2f4e PM |
1365 | set stuff "\0" |
1366 | } | |
b490a991 | 1367 | if {$stuff == {}} { |
7eb3cb9c PM |
1368 | if {![eof $fd]} { |
1369 | return 1 | |
1370 | } | |
6df7403a | 1371 | global commfd viewcomplete viewactive viewname |
7fcc92bf PM |
1372 | global viewinstances |
1373 | unset commfd($inst) | |
1374 | set i [lsearch -exact $viewinstances($view) $inst] | |
1375 | if {$i >= 0} { | |
1376 | set viewinstances($view) [lreplace $viewinstances($view) $i $i] | |
b0cdca99 | 1377 | } |
f0654861 | 1378 | # set it blocking so we wait for the process to terminate |
da7c24dd | 1379 | fconfigure $fd -blocking 1 |
098dd8a3 PM |
1380 | if {[catch {close $fd} err]} { |
1381 | set fv {} | |
1382 | if {$view != $curview} { | |
1383 | set fv " for the \"$viewname($view)\" view" | |
da7c24dd | 1384 | } |
098dd8a3 PM |
1385 | if {[string range $err 0 4] == "usage"} { |
1386 | set err "Gitk: error reading commits$fv:\ | |
f9e0b6fb | 1387 | bad arguments to git log." |
098dd8a3 PM |
1388 | if {$viewname($view) eq "Command line"} { |
1389 | append err \ | |
f9e0b6fb | 1390 | " (Note: arguments to gitk are passed to git log\ |
098dd8a3 PM |
1391 | to allow selection of commits to be displayed.)" |
1392 | } | |
1393 | } else { | |
1394 | set err "Error reading commits$fv: $err" | |
1395 | } | |
1396 | error_popup $err | |
1d10f36d | 1397 | } |
7fcc92bf PM |
1398 | if {[incr viewactive($view) -1] <= 0} { |
1399 | set viewcomplete($view) 1 | |
1400 | # Check if we have seen any ids listed as parents that haven't | |
1401 | # appeared in the list | |
1402 | closevarcs $view | |
1403 | notbusy $view | |
7fcc92bf | 1404 | } |
098dd8a3 | 1405 | if {$view == $curview} { |
ac1276ab | 1406 | run chewcommits |
9a40c50c | 1407 | } |
7eb3cb9c | 1408 | return 0 |
9a40c50c | 1409 | } |
b490a991 | 1410 | set start 0 |
8f7d0cec | 1411 | set gotsome 0 |
7fcc92bf | 1412 | set scripts {} |
b490a991 PM |
1413 | while 1 { |
1414 | set i [string first "\0" $stuff $start] | |
1415 | if {$i < 0} { | |
7fcc92bf | 1416 | append leftover($inst) [string range $stuff $start end] |
9f1afe05 | 1417 | break |
9ccbdfbf | 1418 | } |
b490a991 | 1419 | if {$start == 0} { |
7fcc92bf | 1420 | set cmit $leftover($inst) |
8f7d0cec | 1421 | append cmit [string range $stuff 0 [expr {$i - 1}]] |
7fcc92bf | 1422 | set leftover($inst) {} |
8f7d0cec PM |
1423 | } else { |
1424 | set cmit [string range $stuff $start [expr {$i - 1}]] | |
b490a991 PM |
1425 | } |
1426 | set start [expr {$i + 1}] | |
e5ea701b PM |
1427 | set j [string first "\n" $cmit] |
1428 | set ok 0 | |
16c1ff96 | 1429 | set listed 1 |
c961b228 PM |
1430 | if {$j >= 0 && [string match "commit *" $cmit]} { |
1431 | set ids [string range $cmit 7 [expr {$j - 1}]] | |
1407ade9 | 1432 | if {[string match {[-^<>]*} $ids]} { |
c961b228 PM |
1433 | switch -- [string index $ids 0] { |
1434 | "-" {set listed 0} | |
1407ade9 LT |
1435 | "^" {set listed 2} |
1436 | "<" {set listed 3} | |
1437 | ">" {set listed 4} | |
c961b228 | 1438 | } |
16c1ff96 PM |
1439 | set ids [string range $ids 1 end] |
1440 | } | |
e5ea701b PM |
1441 | set ok 1 |
1442 | foreach id $ids { | |
8f7d0cec | 1443 | if {[string length $id] != 40} { |
e5ea701b PM |
1444 | set ok 0 |
1445 | break | |
1446 | } | |
1447 | } | |
1448 | } | |
1449 | if {!$ok} { | |
7e952e79 PM |
1450 | set shortcmit $cmit |
1451 | if {[string length $shortcmit] > 80} { | |
1452 | set shortcmit "[string range $shortcmit 0 80]..." | |
1453 | } | |
d990cedf | 1454 | error_popup "[mc "Can't parse git log output:"] {$shortcmit}" |
b490a991 PM |
1455 | exit 1 |
1456 | } | |
e5ea701b | 1457 | set id [lindex $ids 0] |
7fcc92bf | 1458 | set vid $view,$id |
f806f0fb PM |
1459 | |
1460 | if {!$listed && $updating && ![info exists varcid($vid)] && | |
3ed31a81 | 1461 | $vfilelimit($view) ne {}} { |
f806f0fb PM |
1462 | # git log doesn't rewrite parents for unlisted commits |
1463 | # when doing path limiting, so work around that here | |
1464 | # by working out the rewritten parent with git rev-list | |
1465 | # and if we already know about it, using the rewritten | |
1466 | # parent as a substitute parent for $id's children. | |
1467 | if {![catch { | |
1468 | set rwid [exec git rev-list --first-parent --max-count=1 \ | |
3ed31a81 | 1469 | $id -- $vfilelimit($view)] |
f806f0fb PM |
1470 | }]} { |
1471 | if {$rwid ne {} && [info exists varcid($view,$rwid)]} { | |
1472 | # use $rwid in place of $id | |
1473 | rewrite_commit $view $id $rwid | |
1474 | continue | |
1475 | } | |
1476 | } | |
1477 | } | |
1478 | ||
f1bf4ee6 PM |
1479 | set a 0 |
1480 | if {[info exists varcid($vid)]} { | |
1481 | if {$cmitlisted($vid) || !$listed} continue | |
1482 | set a $varcid($vid) | |
1483 | } | |
16c1ff96 PM |
1484 | if {$listed} { |
1485 | set olds [lrange $ids 1 end] | |
16c1ff96 PM |
1486 | } else { |
1487 | set olds {} | |
1488 | } | |
f7a3e8d2 | 1489 | set commitdata($id) [string range $cmit [expr {$j + 1}] end] |
7fcc92bf PM |
1490 | set cmitlisted($vid) $listed |
1491 | set parents($vid) $olds | |
7fcc92bf PM |
1492 | if {![info exists children($vid)]} { |
1493 | set children($vid) {} | |
f1bf4ee6 | 1494 | } elseif {$a == 0 && [llength $children($vid)] == 1} { |
f3ea5ede PM |
1495 | set k [lindex $children($vid) 0] |
1496 | if {[llength $parents($view,$k)] == 1 && | |
3ed31a81 | 1497 | (!$vdatemode($view) || |
f3ea5ede PM |
1498 | $varcid($view,$k) == [llength $varctok($view)] - 1)} { |
1499 | set a $varcid($view,$k) | |
7fcc92bf | 1500 | } |
da7c24dd | 1501 | } |
7fcc92bf PM |
1502 | if {$a == 0} { |
1503 | # new arc | |
1504 | set a [newvarc $view $id] | |
1505 | } | |
e5b37ac1 PM |
1506 | if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} { |
1507 | modify_arc $view $a | |
1508 | } | |
f1bf4ee6 PM |
1509 | if {![info exists varcid($vid)]} { |
1510 | set varcid($vid) $a | |
1511 | lappend varccommits($view,$a) $id | |
1512 | incr commitidx($view) | |
1513 | } | |
e5b37ac1 | 1514 | |
7fcc92bf PM |
1515 | set i 0 |
1516 | foreach p $olds { | |
1517 | if {$i == 0 || [lsearch -exact $olds $p] >= $i} { | |
1518 | set vp $view,$p | |
1519 | if {[llength [lappend children($vp) $id]] > 1 && | |
1520 | [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} { | |
1521 | set children($vp) [lsort -command [list vtokcmp $view] \ | |
1522 | $children($vp)] | |
9257d8f7 | 1523 | catch {unset ordertok} |
7fcc92bf | 1524 | } |
f3ea5ede PM |
1525 | if {[info exists varcid($view,$p)]} { |
1526 | fix_reversal $p $a $view | |
1527 | } | |
7fcc92bf PM |
1528 | } |
1529 | incr i | |
1530 | } | |
7fcc92bf | 1531 | |
d375ef9b | 1532 | set scripts [check_interest $id $scripts] |
8f7d0cec PM |
1533 | set gotsome 1 |
1534 | } | |
1535 | if {$gotsome} { | |
ac1276ab PM |
1536 | global numcommits hlview |
1537 | ||
1538 | if {$view == $curview} { | |
1539 | set numcommits $commitidx($view) | |
1540 | run chewcommits | |
1541 | } | |
1542 | if {[info exists hlview] && $view == $hlview} { | |
1543 | # we never actually get here... | |
1544 | run vhighlightmore | |
1545 | } | |
7fcc92bf PM |
1546 | foreach s $scripts { |
1547 | eval $s | |
1548 | } | |
9ccbdfbf | 1549 | } |
7eb3cb9c | 1550 | return 2 |
9ccbdfbf PM |
1551 | } |
1552 | ||
ac1276ab | 1553 | proc chewcommits {} { |
f5f3c2e2 | 1554 | global curview hlview viewcomplete |
7fcc92bf | 1555 | global pending_select |
7eb3cb9c | 1556 | |
ac1276ab PM |
1557 | layoutmore |
1558 | if {$viewcomplete($curview)} { | |
1559 | global commitidx varctok | |
1560 | global numcommits startmsecs | |
ac1276ab PM |
1561 | |
1562 | if {[info exists pending_select]} { | |
835e62ae AG |
1563 | update |
1564 | reset_pending_select {} | |
1565 | ||
1566 | if {[commitinview $pending_select $curview]} { | |
1567 | selectline [rowofcommit $pending_select] 1 | |
1568 | } else { | |
1569 | set row [first_real_row] | |
1570 | selectline $row 1 | |
1571 | } | |
7eb3cb9c | 1572 | } |
ac1276ab PM |
1573 | if {$commitidx($curview) > 0} { |
1574 | #set ms [expr {[clock clicks -milliseconds] - $startmsecs}] | |
1575 | #puts "overall $ms ms for $numcommits commits" | |
1576 | #puts "[llength $varctok($view)] arcs, $commitidx($view) commits" | |
1577 | } else { | |
1578 | show_status [mc "No commits selected"] | |
1579 | } | |
1580 | notbusy layout | |
b664550c | 1581 | } |
f5f3c2e2 | 1582 | return 0 |
1db95b00 PM |
1583 | } |
1584 | ||
590915da AG |
1585 | proc do_readcommit {id} { |
1586 | global tclencoding | |
1587 | ||
1588 | # Invoke git-log to handle automatic encoding conversion | |
1589 | set fd [open [concat | git log --no-color --pretty=raw -1 $id] r] | |
1590 | # Read the results using i18n.logoutputencoding | |
1591 | fconfigure $fd -translation lf -eofchar {} | |
1592 | if {$tclencoding != {}} { | |
1593 | fconfigure $fd -encoding $tclencoding | |
1594 | } | |
1595 | set contents [read $fd] | |
1596 | close $fd | |
1597 | # Remove the heading line | |
1598 | regsub {^commit [0-9a-f]+\n} $contents {} contents | |
1599 | ||
1600 | return $contents | |
1601 | } | |
1602 | ||
1db95b00 | 1603 | proc readcommit {id} { |
590915da AG |
1604 | if {[catch {set contents [do_readcommit $id]}]} return |
1605 | parsecommit $id $contents 1 | |
b490a991 PM |
1606 | } |
1607 | ||
8f7d0cec | 1608 | proc parsecommit {id contents listed} { |
b5c2f306 SV |
1609 | global commitinfo cdate |
1610 | ||
1611 | set inhdr 1 | |
1612 | set comment {} | |
1613 | set headline {} | |
1614 | set auname {} | |
1615 | set audate {} | |
1616 | set comname {} | |
1617 | set comdate {} | |
232475d3 PM |
1618 | set hdrend [string first "\n\n" $contents] |
1619 | if {$hdrend < 0} { | |
1620 | # should never happen... | |
1621 | set hdrend [string length $contents] | |
1622 | } | |
1623 | set header [string range $contents 0 [expr {$hdrend - 1}]] | |
1624 | set comment [string range $contents [expr {$hdrend + 2}] end] | |
1625 | foreach line [split $header "\n"] { | |
61f57cb0 | 1626 | set line [split $line " "] |
232475d3 PM |
1627 | set tag [lindex $line 0] |
1628 | if {$tag == "author"} { | |
1629 | set audate [lindex $line end-1] | |
61f57cb0 | 1630 | set auname [join [lrange $line 1 end-2] " "] |
232475d3 PM |
1631 | } elseif {$tag == "committer"} { |
1632 | set comdate [lindex $line end-1] | |
61f57cb0 | 1633 | set comname [join [lrange $line 1 end-2] " "] |
1db95b00 PM |
1634 | } |
1635 | } | |
232475d3 | 1636 | set headline {} |
43c25074 PM |
1637 | # take the first non-blank line of the comment as the headline |
1638 | set headline [string trimleft $comment] | |
1639 | set i [string first "\n" $headline] | |
232475d3 | 1640 | if {$i >= 0} { |
43c25074 PM |
1641 | set headline [string range $headline 0 $i] |
1642 | } | |
1643 | set headline [string trimright $headline] | |
1644 | set i [string first "\r" $headline] | |
1645 | if {$i >= 0} { | |
1646 | set headline [string trimright [string range $headline 0 $i]] | |
232475d3 PM |
1647 | } |
1648 | if {!$listed} { | |
f9e0b6fb | 1649 | # git log indents the comment by 4 spaces; |
8974c6f9 | 1650 | # if we got this via git cat-file, add the indentation |
232475d3 PM |
1651 | set newcomment {} |
1652 | foreach line [split $comment "\n"] { | |
1653 | append newcomment " " | |
1654 | append newcomment $line | |
f6e2869f | 1655 | append newcomment "\n" |
232475d3 PM |
1656 | } |
1657 | set comment $newcomment | |
1db95b00 PM |
1658 | } |
1659 | if {$comdate != {}} { | |
cfb4563c | 1660 | set cdate($id) $comdate |
1db95b00 | 1661 | } |
e5c2d856 PM |
1662 | set commitinfo($id) [list $headline $auname $audate \ |
1663 | $comname $comdate $comment] | |
1db95b00 PM |
1664 | } |
1665 | ||
f7a3e8d2 | 1666 | proc getcommit {id} { |
79b2c75e | 1667 | global commitdata commitinfo |
8ed16484 | 1668 | |
f7a3e8d2 PM |
1669 | if {[info exists commitdata($id)]} { |
1670 | parsecommit $id $commitdata($id) 1 | |
8ed16484 PM |
1671 | } else { |
1672 | readcommit $id | |
1673 | if {![info exists commitinfo($id)]} { | |
d990cedf | 1674 | set commitinfo($id) [list [mc "No commit information available"]] |
8ed16484 PM |
1675 | } |
1676 | } | |
1677 | return 1 | |
1678 | } | |
1679 | ||
d375ef9b PM |
1680 | # Expand an abbreviated commit ID to a list of full 40-char IDs that match |
1681 | # and are present in the current view. | |
1682 | # This is fairly slow... | |
1683 | proc longid {prefix} { | |
1684 | global varcid curview | |
1685 | ||
1686 | set ids {} | |
1687 | foreach match [array names varcid "$curview,$prefix*"] { | |
1688 | lappend ids [lindex [split $match ","] 1] | |
1689 | } | |
1690 | return $ids | |
1691 | } | |
1692 | ||
887fe3c4 | 1693 | proc readrefs {} { |
62d3ea65 | 1694 | global tagids idtags headids idheads tagobjid |
219ea3a9 | 1695 | global otherrefids idotherrefs mainhead mainheadid |
39816d60 | 1696 | global selecthead selectheadid |
ffe15297 | 1697 | global hideremotes |
106288cb | 1698 | |
b5c2f306 SV |
1699 | foreach v {tagids idtags headids idheads otherrefids idotherrefs} { |
1700 | catch {unset $v} | |
1701 | } | |
62d3ea65 PM |
1702 | set refd [open [list | git show-ref -d] r] |
1703 | while {[gets $refd line] >= 0} { | |
1704 | if {[string index $line 40] ne " "} continue | |
1705 | set id [string range $line 0 39] | |
1706 | set ref [string range $line 41 end] | |
1707 | if {![string match "refs/*" $ref]} continue | |
1708 | set name [string range $ref 5 end] | |
1709 | if {[string match "remotes/*" $name]} { | |
ffe15297 | 1710 | if {![string match "*/HEAD" $name] && !$hideremotes} { |
62d3ea65 PM |
1711 | set headids($name) $id |
1712 | lappend idheads($id) $name | |
f1d83ba3 | 1713 | } |
62d3ea65 PM |
1714 | } elseif {[string match "heads/*" $name]} { |
1715 | set name [string range $name 6 end] | |
36a7cad6 JH |
1716 | set headids($name) $id |
1717 | lappend idheads($id) $name | |
62d3ea65 PM |
1718 | } elseif {[string match "tags/*" $name]} { |
1719 | # this lets refs/tags/foo^{} overwrite refs/tags/foo, | |
1720 | # which is what we want since the former is the commit ID | |
1721 | set name [string range $name 5 end] | |
1722 | if {[string match "*^{}" $name]} { | |
1723 | set name [string range $name 0 end-3] | |
1724 | } else { | |
1725 | set tagobjid($name) $id | |
1726 | } | |
1727 | set tagids($name) $id | |
1728 | lappend idtags($id) $name | |
36a7cad6 JH |
1729 | } else { |
1730 | set otherrefids($name) $id | |
1731 | lappend idotherrefs($id) $name | |
f1d83ba3 PM |
1732 | } |
1733 | } | |
062d671f | 1734 | catch {close $refd} |
8a48571c | 1735 | set mainhead {} |
219ea3a9 | 1736 | set mainheadid {} |
8a48571c | 1737 | catch { |
c11ff120 | 1738 | set mainheadid [exec git rev-parse HEAD] |
8a48571c PM |
1739 | set thehead [exec git symbolic-ref HEAD] |
1740 | if {[string match "refs/heads/*" $thehead]} { | |
1741 | set mainhead [string range $thehead 11 end] | |
1742 | } | |
1743 | } | |
39816d60 AG |
1744 | set selectheadid {} |
1745 | if {$selecthead ne {}} { | |
1746 | catch { | |
1747 | set selectheadid [exec git rev-parse --verify $selecthead] | |
1748 | } | |
1749 | } | |
887fe3c4 PM |
1750 | } |
1751 | ||
8f489363 PM |
1752 | # skip over fake commits |
1753 | proc first_real_row {} { | |
7fcc92bf | 1754 | global nullid nullid2 numcommits |
8f489363 PM |
1755 | |
1756 | for {set row 0} {$row < $numcommits} {incr row} { | |
7fcc92bf | 1757 | set id [commitonrow $row] |
8f489363 PM |
1758 | if {$id ne $nullid && $id ne $nullid2} { |
1759 | break | |
1760 | } | |
1761 | } | |
1762 | return $row | |
1763 | } | |
1764 | ||
e11f1233 PM |
1765 | # update things for a head moved to a child of its previous location |
1766 | proc movehead {id name} { | |
1767 | global headids idheads | |
1768 | ||
1769 | removehead $headids($name) $name | |
1770 | set headids($name) $id | |
1771 | lappend idheads($id) $name | |
1772 | } | |
1773 | ||
1774 | # update things when a head has been removed | |
1775 | proc removehead {id name} { | |
1776 | global headids idheads | |
1777 | ||
1778 | if {$idheads($id) eq $name} { | |
1779 | unset idheads($id) | |
1780 | } else { | |
1781 | set i [lsearch -exact $idheads($id) $name] | |
1782 | if {$i >= 0} { | |
1783 | set idheads($id) [lreplace $idheads($id) $i $i] | |
1784 | } | |
1785 | } | |
1786 | unset headids($name) | |
1787 | } | |
1788 | ||
d93f1713 PT |
1789 | proc ttk_toplevel {w args} { |
1790 | global use_ttk | |
1791 | eval [linsert $args 0 ::toplevel $w] | |
1792 | if {$use_ttk} { | |
1793 | place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1 | |
1794 | } | |
1795 | return $w | |
1796 | } | |
1797 | ||
e7d64008 AG |
1798 | proc make_transient {window origin} { |
1799 | global have_tk85 | |
1800 | ||
1801 | # In MacOS Tk 8.4 transient appears to work by setting | |
1802 | # overrideredirect, which is utterly useless, since the | |
1803 | # windows get no border, and are not even kept above | |
1804 | # the parent. | |
1805 | if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return | |
1806 | ||
1807 | wm transient $window $origin | |
1808 | ||
1809 | # Windows fails to place transient windows normally, so | |
1810 | # schedule a callback to center them on the parent. | |
1811 | if {[tk windowingsystem] eq {win32}} { | |
1812 | after idle [list tk::PlaceWindow $window widget $origin] | |
1813 | } | |
1814 | } | |
1815 | ||
8d849957 | 1816 | proc show_error {w top msg {mc mc}} { |
d93f1713 | 1817 | global NS |
3cb1f9c9 | 1818 | if {![info exists NS]} {set NS ""} |
d93f1713 | 1819 | if {[wm state $top] eq "withdrawn"} { wm deiconify $top } |
df3d83b1 PM |
1820 | message $w.m -text $msg -justify center -aspect 400 |
1821 | pack $w.m -side top -fill x -padx 20 -pady 20 | |
7a0ebbf8 | 1822 | ${NS}::button $w.ok -default active -text [$mc OK] -command "destroy $top" |
df3d83b1 | 1823 | pack $w.ok -side bottom -fill x |
e54be9e3 PM |
1824 | bind $top <Visibility> "grab $top; focus $top" |
1825 | bind $top <Key-Return> "destroy $top" | |
76f15947 AG |
1826 | bind $top <Key-space> "destroy $top" |
1827 | bind $top <Key-Escape> "destroy $top" | |
e54be9e3 | 1828 | tkwait window $top |
df3d83b1 PM |
1829 | } |
1830 | ||
84a76f18 | 1831 | proc error_popup {msg {owner .}} { |
d93f1713 PT |
1832 | if {[tk windowingsystem] eq "win32"} { |
1833 | tk_messageBox -icon error -type ok -title [wm title .] \ | |
1834 | -parent $owner -message $msg | |
1835 | } else { | |
1836 | set w .error | |
1837 | ttk_toplevel $w | |
1838 | make_transient $w $owner | |
1839 | show_error $w $w $msg | |
1840 | } | |
098dd8a3 PM |
1841 | } |
1842 | ||
84a76f18 | 1843 | proc confirm_popup {msg {owner .}} { |
d93f1713 | 1844 | global confirm_ok NS |
10299152 PM |
1845 | set confirm_ok 0 |
1846 | set w .confirm | |
d93f1713 | 1847 | ttk_toplevel $w |
e7d64008 | 1848 | make_transient $w $owner |
10299152 PM |
1849 | message $w.m -text $msg -justify center -aspect 400 |
1850 | pack $w.m -side top -fill x -padx 20 -pady 20 | |
d93f1713 | 1851 | ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" |
10299152 | 1852 | pack $w.ok -side left -fill x |
d93f1713 | 1853 | ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w" |
10299152 PM |
1854 | pack $w.cancel -side right -fill x |
1855 | bind $w <Visibility> "grab $w; focus $w" | |
76f15947 AG |
1856 | bind $w <Key-Return> "set confirm_ok 1; destroy $w" |
1857 | bind $w <Key-space> "set confirm_ok 1; destroy $w" | |
1858 | bind $w <Key-Escape> "destroy $w" | |
d93f1713 | 1859 | tk::PlaceWindow $w widget $owner |
10299152 PM |
1860 | tkwait window $w |
1861 | return $confirm_ok | |
1862 | } | |
1863 | ||
b039f0a6 | 1864 | proc setoptions {} { |
d93f1713 PT |
1865 | if {[tk windowingsystem] ne "win32"} { |
1866 | option add *Panedwindow.showHandle 1 startupFile | |
1867 | option add *Panedwindow.sashRelief raised startupFile | |
1868 | if {[tk windowingsystem] ne "aqua"} { | |
1869 | option add *Menu.font uifont startupFile | |
1870 | } | |
1871 | } else { | |
1872 | option add *Menu.TearOff 0 startupFile | |
1873 | } | |
b039f0a6 PM |
1874 | option add *Button.font uifont startupFile |
1875 | option add *Checkbutton.font uifont startupFile | |
1876 | option add *Radiobutton.font uifont startupFile | |
b039f0a6 PM |
1877 | option add *Menubutton.font uifont startupFile |
1878 | option add *Label.font uifont startupFile | |
1879 | option add *Message.font uifont startupFile | |
b9b142ff MH |
1880 | option add *Entry.font textfont startupFile |
1881 | option add *Text.font textfont startupFile | |
d93f1713 | 1882 | option add *Labelframe.font uifont startupFile |
0933b04e | 1883 | option add *Spinbox.font textfont startupFile |
207ad7b8 | 1884 | option add *Listbox.font mainfont startupFile |
b039f0a6 PM |
1885 | } |
1886 | ||
79056034 PM |
1887 | # Make a menu and submenus. |
1888 | # m is the window name for the menu, items is the list of menu items to add. | |
1889 | # Each item is a list {mc label type description options...} | |
1890 | # mc is ignored; it's so we can put mc there to alert xgettext | |
1891 | # label is the string that appears in the menu | |
1892 | # type is cascade, command or radiobutton (should add checkbutton) | |
1893 | # description depends on type; it's the sublist for cascade, the | |
1894 | # command to invoke for command, or {variable value} for radiobutton | |
f2d0bbbd PM |
1895 | proc makemenu {m items} { |
1896 | menu $m | |
cea07cf8 AG |
1897 | if {[tk windowingsystem] eq {aqua}} { |
1898 | set Meta1 Cmd | |
1899 | } else { | |
1900 | set Meta1 Ctrl | |
1901 | } | |
f2d0bbbd | 1902 | foreach i $items { |
79056034 PM |
1903 | set name [mc [lindex $i 1]] |
1904 | set type [lindex $i 2] | |
1905 | set thing [lindex $i 3] | |
f2d0bbbd PM |
1906 | set params [list $type] |
1907 | if {$name ne {}} { | |
1908 | set u [string first "&" [string map {&& x} $name]] | |
1909 | lappend params -label [string map {&& & & {}} $name] | |
1910 | if {$u >= 0} { | |
1911 | lappend params -underline $u | |
1912 | } | |
1913 | } | |
1914 | switch -- $type { | |
1915 | "cascade" { | |
79056034 | 1916 | set submenu [string tolower [string map {& ""} [lindex $i 1]]] |
f2d0bbbd PM |
1917 | lappend params -menu $m.$submenu |
1918 | } | |
1919 | "command" { | |
1920 | lappend params -command $thing | |
1921 | } | |
1922 | "radiobutton" { | |
1923 | lappend params -variable [lindex $thing 0] \ | |
1924 | -value [lindex $thing 1] | |
1925 | } | |
1926 | } | |
cea07cf8 AG |
1927 | set tail [lrange $i 4 end] |
1928 | regsub -all {\yMeta1\y} $tail $Meta1 tail | |
1929 | eval $m add $params $tail | |
f2d0bbbd PM |
1930 | if {$type eq "cascade"} { |
1931 | makemenu $m.$submenu $thing | |
1932 | } | |
1933 | } | |
1934 | } | |
1935 | ||
1936 | # translate string and remove ampersands | |
1937 | proc mca {str} { | |
1938 | return [string map {&& & & {}} [mc $str]] | |
1939 | } | |
1940 | ||
d93f1713 PT |
1941 | proc makedroplist {w varname args} { |
1942 | global use_ttk | |
1943 | if {$use_ttk} { | |
3cb1f9c9 PT |
1944 | set width 0 |
1945 | foreach label $args { | |
1946 | set cx [string length $label] | |
1947 | if {$cx > $width} {set width $cx} | |
1948 | } | |
1949 | set gm [ttk::combobox $w -width $width -state readonly\ | |
d93f1713 PT |
1950 | -textvariable $varname -values $args] |
1951 | } else { | |
1952 | set gm [eval [linsert $args 0 tk_optionMenu $w $varname]] | |
1953 | } | |
1954 | return $gm | |
1955 | } | |
1956 | ||
d94f8cd6 | 1957 | proc makewindow {} { |
31c0eaa8 | 1958 | global canv canv2 canv3 linespc charspc ctext cflist cscroll |
9c311b32 | 1959 | global tabstop |
b74fd579 | 1960 | global findtype findtypemenu findloc findstring fstring geometry |
887fe3c4 | 1961 | global entries sha1entry sha1string sha1but |
890fae70 | 1962 | global diffcontextstring diffcontext |
b9b86007 | 1963 | global ignorespace |
94a2eede | 1964 | global maincursor textcursor curtextcursor |
219ea3a9 | 1965 | global rowctxmenu fakerowmenu mergemax wrapcomment |
60f7a7dc | 1966 | global highlight_files gdttype |
3ea06f9f | 1967 | global searchstring sstring |
60378c0c | 1968 | global bgcolor fgcolor bglist fglist diffcolors selectbgcolor |
bb3edc8b PM |
1969 | global headctxmenu progresscanv progressitem progresscoords statusw |
1970 | global fprogitem fprogcoord lastprogupdate progupdatepending | |
6df7403a | 1971 | global rprogitem rprogcoord rownumsel numcommits |
d93f1713 | 1972 | global have_tk85 use_ttk NS |
9a40c50c | 1973 | |
79056034 PM |
1974 | # The "mc" arguments here are purely so that xgettext |
1975 | # sees the following string as needing to be translated | |
5fdcbb13 DS |
1976 | set file { |
1977 | mc "File" cascade { | |
79056034 | 1978 | {mc "Update" command updatecommits -accelerator F5} |
cea07cf8 | 1979 | {mc "Reload" command reloadcommits -accelerator Meta1-F5} |
79056034 | 1980 | {mc "Reread references" command rereadrefs} |
cea07cf8 | 1981 | {mc "List references" command showrefs -accelerator F2} |
7fb0abb1 AG |
1982 | {xx "" separator} |
1983 | {mc "Start git gui" command {exec git gui &}} | |
1984 | {xx "" separator} | |
cea07cf8 | 1985 | {mc "Quit" command doquit -accelerator Meta1-Q} |
f2d0bbbd | 1986 | }} |
5fdcbb13 DS |
1987 | set edit { |
1988 | mc "Edit" cascade { | |
79056034 | 1989 | {mc "Preferences" command doprefs} |
f2d0bbbd | 1990 | }} |
5fdcbb13 DS |
1991 | set view { |
1992 | mc "View" cascade { | |
cea07cf8 AG |
1993 | {mc "New view..." command {newview 0} -accelerator Shift-F4} |
1994 | {mc "Edit view..." command editview -state disabled -accelerator F4} | |
79056034 PM |
1995 | {mc "Delete view" command delview -state disabled} |
1996 | {xx "" separator} | |
1997 | {mc "All files" radiobutton {selectedview 0} -command {showview 0}} | |
f2d0bbbd | 1998 | }} |
5fdcbb13 DS |
1999 | if {[tk windowingsystem] ne "aqua"} { |
2000 | set help { | |
2001 | mc "Help" cascade { | |
2002 | {mc "About gitk" command about} | |
2003 | {mc "Key bindings" command keys} | |
2004 | }} | |
2005 | set bar [list $file $edit $view $help] | |
2006 | } else { | |
2007 | proc ::tk::mac::ShowPreferences {} {doprefs} | |
2008 | proc ::tk::mac::Quit {} {doquit} | |
2009 | lset file end [lreplace [lindex $file end] end-1 end] | |
2010 | set apple { | |
2011 | xx "Apple" cascade { | |
79056034 | 2012 | {mc "About gitk" command about} |
5fdcbb13 DS |
2013 | {xx "" separator} |
2014 | }} | |
2015 | set help { | |
2016 | mc "Help" cascade { | |
79056034 | 2017 | {mc "Key bindings" command keys} |
f2d0bbbd | 2018 | }} |
5fdcbb13 | 2019 | set bar [list $apple $file $view $help] |
f2d0bbbd | 2020 | } |
5fdcbb13 | 2021 | makemenu .bar $bar |
9a40c50c PM |
2022 | . configure -menu .bar |
2023 | ||
d93f1713 PT |
2024 | if {$use_ttk} { |
2025 | # cover the non-themed toplevel with a themed frame. | |
2026 | place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1 | |
2027 | } | |
2028 | ||
e9937d2a | 2029 | # the gui has upper and lower half, parts of a paned window. |
d93f1713 | 2030 | ${NS}::panedwindow .ctop -orient vertical |
e9937d2a JH |
2031 | |
2032 | # possibly use assumed geometry | |
9ca72f4f | 2033 | if {![info exists geometry(pwsash0)]} { |
e9937d2a JH |
2034 | set geometry(topheight) [expr {15 * $linespc}] |
2035 | set geometry(topwidth) [expr {80 * $charspc}] | |
2036 | set geometry(botheight) [expr {15 * $linespc}] | |
2037 | set geometry(botwidth) [expr {50 * $charspc}] | |
d93f1713 PT |
2038 | set geometry(pwsash0) [list [expr {40 * $charspc}] 2] |
2039 | set geometry(pwsash1) [list [expr {60 * $charspc}] 2] | |
e9937d2a JH |
2040 | } |
2041 | ||
2042 | # the upper half will have a paned window, a scroll bar to the right, and some stuff below | |
d93f1713 PT |
2043 | ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth) |
2044 | ${NS}::frame .tf.histframe | |
2045 | ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal | |
2046 | if {!$use_ttk} { | |
2047 | .tf.histframe.pwclist configure -sashpad 0 -handlesize 4 | |
2048 | } | |
e9937d2a JH |
2049 | |
2050 | # create three canvases | |
2051 | set cscroll .tf.histframe.csb | |
2052 | set canv .tf.histframe.pwclist.canv | |
9ca72f4f | 2053 | canvas $canv \ |
60378c0c | 2054 | -selectbackground $selectbgcolor \ |
f8a2c0d1 | 2055 | -background $bgcolor -bd 0 \ |
9f1afe05 | 2056 | -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll" |
e9937d2a JH |
2057 | .tf.histframe.pwclist add $canv |
2058 | set canv2 .tf.histframe.pwclist.canv2 | |
9ca72f4f | 2059 | canvas $canv2 \ |
60378c0c | 2060 | -selectbackground $selectbgcolor \ |
f8a2c0d1 | 2061 | -background $bgcolor -bd 0 -yscrollincr $linespc |
e9937d2a JH |
2062 | .tf.histframe.pwclist add $canv2 |
2063 | set canv3 .tf.histframe.pwclist.canv3 | |
9ca72f4f | 2064 | canvas $canv3 \ |
60378c0c | 2065 | -selectbackground $selectbgcolor \ |
f8a2c0d1 | 2066 | -background $bgcolor -bd 0 -yscrollincr $linespc |
e9937d2a | 2067 | .tf.histframe.pwclist add $canv3 |
d93f1713 PT |
2068 | if {$use_ttk} { |
2069 | bind .tf.histframe.pwclist <Map> { | |
2070 | bind %W <Map> {} | |
2071 | .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0] | |
2072 | .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0] | |
2073 | } | |
2074 | } else { | |
2075 | eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0) | |
2076 | eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1) | |
2077 | } | |
e9937d2a JH |
2078 | |
2079 | # a scroll bar to rule them | |
d93f1713 PT |
2080 | ${NS}::scrollbar $cscroll -command {allcanvs yview} |
2081 | if {!$use_ttk} {$cscroll configure -highlightthickness 0} | |
e9937d2a JH |
2082 | pack $cscroll -side right -fill y |
2083 | bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w} | |
f8a2c0d1 | 2084 | lappend bglist $canv $canv2 $canv3 |
e9937d2a | 2085 | pack .tf.histframe.pwclist -fill both -expand 1 -side left |
98f350e5 | 2086 | |
e9937d2a | 2087 | # we have two button bars at bottom of top frame. Bar 1 |
d93f1713 PT |
2088 | ${NS}::frame .tf.bar |
2089 | ${NS}::frame .tf.lbar -height 15 | |
e9937d2a JH |
2090 | |
2091 | set sha1entry .tf.bar.sha1 | |
887fe3c4 | 2092 | set entries $sha1entry |
e9937d2a | 2093 | set sha1but .tf.bar.sha1label |
0359ba72 | 2094 | button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \ |
b039f0a6 | 2095 | -command gotocommit -width 8 |
887fe3c4 | 2096 | $sha1but conf -disabledforeground [$sha1but cget -foreground] |
e9937d2a | 2097 | pack .tf.bar.sha1label -side left |
d93f1713 | 2098 | ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string |
887fe3c4 | 2099 | trace add variable sha1string write sha1change |
98f350e5 | 2100 | pack $sha1entry -side left -pady 2 |
d698206c PM |
2101 | |
2102 | image create bitmap bm-left -data { | |
2103 | #define left_width 16 | |
2104 | #define left_height 16 | |
2105 | static unsigned char left_bits[] = { | |
2106 | 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, | |
2107 | 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00, | |
2108 | 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01}; | |
2109 | } | |
2110 | image create bitmap bm-right -data { | |
2111 | #define right_width 16 | |
2112 | #define right_height 16 | |
2113 | static unsigned char right_bits[] = { | |
2114 | 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c, | |
2115 | 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c, | |
2116 | 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01}; | |
2117 | } | |
d93f1713 | 2118 | ${NS}::button .tf.bar.leftbut -image bm-left -command goback \ |
d698206c | 2119 | -state disabled -width 26 |
e9937d2a | 2120 | pack .tf.bar.leftbut -side left -fill y |
d93f1713 | 2121 | ${NS}::button .tf.bar.rightbut -image bm-right -command goforw \ |
d698206c | 2122 | -state disabled -width 26 |
e9937d2a | 2123 | pack .tf.bar.rightbut -side left -fill y |
d698206c | 2124 | |
d93f1713 | 2125 | ${NS}::label .tf.bar.rowlabel -text [mc "Row"] |
6df7403a | 2126 | set rownumsel {} |
d93f1713 | 2127 | ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \ |
6df7403a | 2128 | -relief sunken -anchor e |
d93f1713 PT |
2129 | ${NS}::label .tf.bar.rowlabel2 -text "/" |
2130 | ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \ | |
6df7403a PM |
2131 | -relief sunken -anchor e |
2132 | pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \ | |
2133 | -side left | |
d93f1713 PT |
2134 | if {!$use_ttk} { |
2135 | foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont} | |
2136 | } | |
6df7403a | 2137 | global selectedline |
94b4a69f | 2138 | trace add variable selectedline write selectedline_change |
6df7403a | 2139 | |
bb3edc8b PM |
2140 | # Status label and progress bar |
2141 | set statusw .tf.bar.status | |
d93f1713 | 2142 | ${NS}::label $statusw -width 15 -relief sunken |
bb3edc8b | 2143 | pack $statusw -side left -padx 5 |
d93f1713 PT |
2144 | if {$use_ttk} { |
2145 | set progresscanv [ttk::progressbar .tf.bar.progress] | |
2146 | } else { | |
2147 | set h [expr {[font metrics uifont -linespace] + 2}] | |
2148 | set progresscanv .tf.bar.progress | |
2149 | canvas $progresscanv -relief sunken -height $h -borderwidth 2 | |
2150 | set progressitem [$progresscanv create rect -1 0 0 $h -fill green] | |
2151 | set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow] | |
2152 | set rprogitem [$progresscanv create rect -1 0 0 $h -fill red] | |
2153 | } | |
2154 | pack $progresscanv -side right -expand 1 -fill x -padx {0 2} | |
bb3edc8b PM |
2155 | set progresscoords {0 0} |
2156 | set fprogcoord 0 | |
a137a90f | 2157 | set rprogcoord 0 |
bb3edc8b PM |
2158 | bind $progresscanv <Configure> adjustprogress |
2159 | set lastprogupdate [clock clicks -milliseconds] | |
2160 | set progupdatepending 0 | |
2161 | ||
687c8765 | 2162 | # build up the bottom bar of upper window |
d93f1713 PT |
2163 | ${NS}::label .tf.lbar.flabel -text "[mc "Find"] " |
2164 | ${NS}::button .tf.lbar.fnext -text [mc "next"] -command {dofind 1 1} | |
2165 | ${NS}::button .tf.lbar.fprev -text [mc "prev"] -command {dofind -1 1} | |
2166 | ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] " | |
687c8765 PM |
2167 | pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \ |
2168 | -side left -fill y | |
b007ee20 | 2169 | set gdttype [mc "containing:"] |
3cb1f9c9 | 2170 | set gm [makedroplist .tf.lbar.gdttype gdttype \ |
b007ee20 CS |
2171 | [mc "containing:"] \ |
2172 | [mc "touching paths:"] \ | |
2173 | [mc "adding/removing string:"]] | |
687c8765 | 2174 | trace add variable gdttype write gdttype_change |
687c8765 PM |
2175 | pack .tf.lbar.gdttype -side left -fill y |
2176 | ||
98f350e5 | 2177 | set findstring {} |
687c8765 | 2178 | set fstring .tf.lbar.findstring |
887fe3c4 | 2179 | lappend entries $fstring |
b9b142ff | 2180 | ${NS}::entry $fstring -width 30 -textvariable findstring |
60f7a7dc | 2181 | trace add variable findstring write find_change |
b007ee20 | 2182 | set findtype [mc "Exact"] |
d93f1713 PT |
2183 | set findtypemenu [makedroplist .tf.lbar.findtype \ |
2184 | findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]] | |
687c8765 | 2185 | trace add variable findtype write findcom_change |
b007ee20 | 2186 | set findloc [mc "All fields"] |
d93f1713 | 2187 | makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \ |
b007ee20 | 2188 | [mc "Comments"] [mc "Author"] [mc "Committer"] |
60f7a7dc | 2189 | trace add variable findloc write find_change |
687c8765 PM |
2190 | pack .tf.lbar.findloc -side right |
2191 | pack .tf.lbar.findtype -side right | |
2192 | pack $fstring -side left -expand 1 -fill x | |
e9937d2a JH |
2193 | |
2194 | # Finish putting the upper half of the viewer together | |
2195 | pack .tf.lbar -in .tf -side bottom -fill x | |
2196 | pack .tf.bar -in .tf -side bottom -fill x | |
2197 | pack .tf.histframe -fill both -side top -expand 1 | |
2198 | .ctop add .tf | |
d93f1713 PT |
2199 | if {!$use_ttk} { |
2200 | .ctop paneconfigure .tf -height $geometry(topheight) | |
2201 | .ctop paneconfigure .tf -width $geometry(topwidth) | |
2202 | } | |
e9937d2a JH |
2203 | |
2204 | # now build up the bottom | |
d93f1713 | 2205 | ${NS}::panedwindow .pwbottom -orient horizontal |
e9937d2a JH |
2206 | |
2207 | # lower left, a text box over search bar, scroll bar to the right | |
2208 | # if we know window height, then that will set the lower text height, otherwise | |
2209 | # we set lower text height which will drive window height | |
2210 | if {[info exists geometry(main)]} { | |
d93f1713 | 2211 | ${NS}::frame .bleft -width $geometry(botwidth) |
e9937d2a | 2212 | } else { |
d93f1713 | 2213 | ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight) |
e9937d2a | 2214 | } |
d93f1713 PT |
2215 | ${NS}::frame .bleft.top |
2216 | ${NS}::frame .bleft.mid | |
2217 | ${NS}::frame .bleft.bottom | |
e9937d2a | 2218 | |
d93f1713 | 2219 | ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch |
e9937d2a JH |
2220 | pack .bleft.top.search -side left -padx 5 |
2221 | set sstring .bleft.top.sstring | |
d93f1713 | 2222 | set searchstring "" |
b9b142ff | 2223 | ${NS}::entry $sstring -width 20 -textvariable searchstring |
3ea06f9f PM |
2224 | lappend entries $sstring |
2225 | trace add variable searchstring write incrsearch | |
2226 | pack $sstring -side left -expand 1 -fill x | |
d93f1713 | 2227 | ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \ |
a8d610a2 | 2228 | -command changediffdisp -variable diffelide -value {0 0} |
d93f1713 | 2229 | ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \ |
a8d610a2 | 2230 | -command changediffdisp -variable diffelide -value {0 1} |
d93f1713 | 2231 | ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \ |
a8d610a2 | 2232 | -command changediffdisp -variable diffelide -value {1 0} |
d93f1713 | 2233 | ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: " |
a8d610a2 | 2234 | pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left |
0933b04e | 2235 | spinbox .bleft.mid.diffcontext -width 5 \ |
a41ddbb6 | 2236 | -from 0 -increment 1 -to 10000000 \ |
890fae70 SP |
2237 | -validate all -validatecommand "diffcontextvalidate %P" \ |
2238 | -textvariable diffcontextstring | |
2239 | .bleft.mid.diffcontext set $diffcontext | |
2240 | trace add variable diffcontextstring write diffcontextchange | |
2241 | lappend entries .bleft.mid.diffcontext | |
2242 | pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left | |
d93f1713 | 2243 | ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \ |
b9b86007 SP |
2244 | -command changeignorespace -variable ignorespace |
2245 | pack .bleft.mid.ignspace -side left -padx 5 | |
8809d691 | 2246 | set ctext .bleft.bottom.ctext |
f8a2c0d1 | 2247 | text $ctext -background $bgcolor -foreground $fgcolor \ |
9c311b32 | 2248 | -state disabled -font textfont \ |
8809d691 PK |
2249 | -yscrollcommand scrolltext -wrap none \ |
2250 | -xscrollcommand ".bleft.bottom.sbhorizontal set" | |
32f1b3e4 PM |
2251 | if {$have_tk85} { |
2252 | $ctext conf -tabstyle wordprocessor | |
2253 | } | |
d93f1713 PT |
2254 | ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview" |
2255 | ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h | |
e9937d2a | 2256 | pack .bleft.top -side top -fill x |
a8d610a2 | 2257 | pack .bleft.mid -side top -fill x |
8809d691 PK |
2258 | grid $ctext .bleft.bottom.sb -sticky nsew |
2259 | grid .bleft.bottom.sbhorizontal -sticky ew | |
2260 | grid columnconfigure .bleft.bottom 0 -weight 1 | |
2261 | grid rowconfigure .bleft.bottom 0 -weight 1 | |
2262 | grid rowconfigure .bleft.bottom 1 -weight 0 | |
2263 | pack .bleft.bottom -side top -fill both -expand 1 | |
f8a2c0d1 PM |
2264 | lappend bglist $ctext |
2265 | lappend fglist $ctext | |
d2610d11 | 2266 | |
f1b86294 | 2267 | $ctext tag conf comment -wrap $wrapcomment |
9c311b32 | 2268 | $ctext tag conf filesep -font textfontbold -back "#aaaaaa" |
f8a2c0d1 PM |
2269 | $ctext tag conf hunksep -fore [lindex $diffcolors 2] |
2270 | $ctext tag conf d0 -fore [lindex $diffcolors 0] | |
8b07dca1 | 2271 | $ctext tag conf dresult -fore [lindex $diffcolors 1] |
712fcc08 PM |
2272 | $ctext tag conf m0 -fore red |
2273 | $ctext tag conf m1 -fore blue | |
2274 | $ctext tag conf m2 -fore green | |
2275 | $ctext tag conf m3 -fore purple | |
2276 | $ctext tag conf m4 -fore brown | |
b77b0278 PM |
2277 | $ctext tag conf m5 -fore "#009090" |
2278 | $ctext tag conf m6 -fore magenta | |
2279 | $ctext tag conf m7 -fore "#808000" | |
2280 | $ctext tag conf m8 -fore "#009000" | |
2281 | $ctext tag conf m9 -fore "#ff0080" | |
2282 | $ctext tag conf m10 -fore cyan | |
2283 | $ctext tag conf m11 -fore "#b07070" | |
2284 | $ctext tag conf m12 -fore "#70b0f0" | |
2285 | $ctext tag conf m13 -fore "#70f0b0" | |
2286 | $ctext tag conf m14 -fore "#f0b070" | |
2287 | $ctext tag conf m15 -fore "#ff70b0" | |
712fcc08 | 2288 | $ctext tag conf mmax -fore darkgrey |
b77b0278 | 2289 | set mergemax 16 |
9c311b32 PM |
2290 | $ctext tag conf mresult -font textfontbold |
2291 | $ctext tag conf msep -font textfontbold | |
712fcc08 | 2292 | $ctext tag conf found -back yellow |
e5c2d856 | 2293 | |
e9937d2a | 2294 | .pwbottom add .bleft |
d93f1713 PT |
2295 | if {!$use_ttk} { |
2296 | .pwbottom paneconfigure .bleft -width $geometry(botwidth) | |
2297 | } | |
e9937d2a JH |
2298 | |
2299 | # lower right | |
d93f1713 PT |
2300 | ${NS}::frame .bright |
2301 | ${NS}::frame .bright.mode | |
2302 | ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \ | |
f8b28a40 | 2303 | -command reselectline -variable cmitmode -value "patch" |
d93f1713 | 2304 | ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \ |
f8b28a40 | 2305 | -command reselectline -variable cmitmode -value "tree" |
e9937d2a JH |
2306 | grid .bright.mode.patch .bright.mode.tree -sticky ew |
2307 | pack .bright.mode -side top -fill x | |
2308 | set cflist .bright.cfiles | |
9c311b32 | 2309 | set indent [font measure mainfont "nn"] |
e9937d2a | 2310 | text $cflist \ |
60378c0c | 2311 | -selectbackground $selectbgcolor \ |
f8a2c0d1 | 2312 | -background $bgcolor -foreground $fgcolor \ |
9c311b32 | 2313 | -font mainfont \ |
7fcceed7 | 2314 | -tabs [list $indent [expr {2 * $indent}]] \ |
e9937d2a | 2315 | -yscrollcommand ".bright.sb set" \ |
7fcceed7 PM |
2316 | -cursor [. cget -cursor] \ |
2317 | -spacing1 1 -spacing3 1 | |
f8a2c0d1 PM |
2318 | lappend bglist $cflist |
2319 | lappend fglist $cflist | |
d93f1713 | 2320 | ${NS}::scrollbar .bright.sb -command "$cflist yview" |
e9937d2a | 2321 | pack .bright.sb -side right -fill y |
d2610d11 | 2322 | pack $cflist -side left -fill both -expand 1 |
89b11d3b PM |
2323 | $cflist tag configure highlight \ |
2324 | -background [$cflist cget -selectbackground] | |
9c311b32 | 2325 | $cflist tag configure bold -font mainfontbold |
d2610d11 | 2326 | |
e9937d2a JH |
2327 | .pwbottom add .bright |
2328 | .ctop add .pwbottom | |
1db95b00 | 2329 | |
b9bee115 | 2330 | # restore window width & height if known |
e9937d2a | 2331 | if {[info exists geometry(main)]} { |
b9bee115 PM |
2332 | if {[scan $geometry(main) "%dx%d" w h] >= 2} { |
2333 | if {$w > [winfo screenwidth .]} { | |
2334 | set w [winfo screenwidth .] | |
2335 | } | |
2336 | if {$h > [winfo screenheight .]} { | |
2337 | set h [winfo screenheight .] | |
2338 | } | |
2339 | wm geometry . "${w}x$h" | |
2340 | } | |
e9937d2a JH |
2341 | } |
2342 | ||
c876dbad PT |
2343 | if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} { |
2344 | wm state . $geometry(state) | |
2345 | } | |
2346 | ||
d23d98d3 SP |
2347 | if {[tk windowingsystem] eq {aqua}} { |
2348 | set M1B M1 | |
5fdcbb13 | 2349 | set ::BM "3" |
d23d98d3 SP |
2350 | } else { |
2351 | set M1B Control | |
5fdcbb13 | 2352 | set ::BM "2" |
d23d98d3 SP |
2353 | } |
2354 | ||
d93f1713 PT |
2355 | if {$use_ttk} { |
2356 | bind .ctop <Map> { | |
2357 | bind %W <Map> {} | |
2358 | %W sashpos 0 $::geometry(topheight) | |
2359 | } | |
2360 | bind .pwbottom <Map> { | |
2361 | bind %W <Map> {} | |
2362 | %W sashpos 0 $::geometry(botwidth) | |
2363 | } | |
2364 | } | |
2365 | ||
e9937d2a JH |
2366 | bind .pwbottom <Configure> {resizecdetpanes %W %w} |
2367 | pack .ctop -fill both -expand 1 | |
c8dfbcf9 PM |
2368 | bindall <1> {selcanvline %W %x %y} |
2369 | #bindall <B1-Motion> {selcanvline %W %x %y} | |
314c3093 ML |
2370 | if {[tk windowingsystem] == "win32"} { |
2371 | bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D } | |
2372 | bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break } | |
2373 | } else { | |
2374 | bindall <ButtonRelease-4> "allcanvs yview scroll -5 units" | |
2375 | bindall <ButtonRelease-5> "allcanvs yview scroll 5 units" | |
5dd57d51 JS |
2376 | if {[tk windowingsystem] eq "aqua"} { |
2377 | bindall <MouseWheel> { | |
2378 | set delta [expr {- (%D)}] | |
2379 | allcanvs yview scroll $delta units | |
2380 | } | |
5fdcbb13 DS |
2381 | bindall <Shift-MouseWheel> { |
2382 | set delta [expr {- (%D)}] | |
2383 | $canv xview scroll $delta units | |
2384 | } | |
5dd57d51 | 2385 | } |
314c3093 | 2386 | } |
5fdcbb13 DS |
2387 | bindall <$::BM> "canvscan mark %W %x %y" |
2388 | bindall <B$::BM-Motion> "canvscan dragto %W %x %y" | |
decd0a1e JL |
2389 | bind all <$M1B-Key-w> {destroy [winfo toplevel %W]} |
2390 | bind . <$M1B-Key-w> doquit | |
6e5f7203 RN |
2391 | bindkey <Home> selfirstline |
2392 | bindkey <End> sellastline | |
17386066 PM |
2393 | bind . <Key-Up> "selnextline -1" |
2394 | bind . <Key-Down> "selnextline 1" | |
cca5d946 PM |
2395 | bind . <Shift-Key-Up> "dofind -1 0" |
2396 | bind . <Shift-Key-Down> "dofind 1 0" | |
6e5f7203 RN |
2397 | bindkey <Key-Right> "goforw" |
2398 | bindkey <Key-Left> "goback" | |
2399 | bind . <Key-Prior> "selnextpage -1" | |
2400 | bind . <Key-Next> "selnextpage 1" | |
d23d98d3 SP |
2401 | bind . <$M1B-Home> "allcanvs yview moveto 0.0" |
2402 | bind . <$M1B-End> "allcanvs yview moveto 1.0" | |
2403 | bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units" | |
2404 | bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units" | |
2405 | bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages" | |
2406 | bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages" | |
cfb4563c PM |
2407 | bindkey <Key-Delete> "$ctext yview scroll -1 pages" |
2408 | bindkey <Key-BackSpace> "$ctext yview scroll -1 pages" | |
2409 | bindkey <Key-space> "$ctext yview scroll 1 pages" | |
df3d83b1 PM |
2410 | bindkey p "selnextline -1" |
2411 | bindkey n "selnextline 1" | |
6e2dda35 RS |
2412 | bindkey z "goback" |
2413 | bindkey x "goforw" | |
2414 | bindkey i "selnextline -1" | |
2415 | bindkey k "selnextline 1" | |
2416 | bindkey j "goback" | |
2417 | bindkey l "goforw" | |
f4c54b3c | 2418 | bindkey b prevfile |
cfb4563c PM |
2419 | bindkey d "$ctext yview scroll 18 units" |
2420 | bindkey u "$ctext yview scroll -18 units" | |
97bed034 | 2421 | bindkey / {focus $fstring} |
b6e192db | 2422 | bindkey <Key-KP_Divide> {focus $fstring} |
cca5d946 PM |
2423 | bindkey <Key-Return> {dofind 1 1} |
2424 | bindkey ? {dofind -1 1} | |
39ad8570 | 2425 | bindkey f nextfile |
cea07cf8 AG |
2426 | bind . <F5> updatecommits |
2427 | bind . <$M1B-F5> reloadcommits | |
2428 | bind . <F2> showrefs | |
2429 | bind . <Shift-F4> {newview 0} | |
2430 | catch { bind . <Shift-Key-XF86_Switch_VT_4> {newview 0} } | |
2431 | bind . <F4> edit_or_newview | |
d23d98d3 | 2432 | bind . <$M1B-q> doquit |
cca5d946 PM |
2433 | bind . <$M1B-f> {dofind 1 1} |
2434 | bind . <$M1B-g> {dofind 1 0} | |
d23d98d3 SP |
2435 | bind . <$M1B-r> dosearchback |
2436 | bind . <$M1B-s> dosearch | |
2437 | bind . <$M1B-equal> {incrfont 1} | |
646f3a14 | 2438 | bind . <$M1B-plus> {incrfont 1} |
d23d98d3 SP |
2439 | bind . <$M1B-KP_Add> {incrfont 1} |
2440 | bind . <$M1B-minus> {incrfont -1} | |
2441 | bind . <$M1B-KP_Subtract> {incrfont -1} | |
b6047c5a | 2442 | wm protocol . WM_DELETE_WINDOW doquit |
e2f90ee4 | 2443 | bind . <Destroy> {stop_backends} |
df3d83b1 | 2444 | bind . <Button-1> "click %W" |
cca5d946 | 2445 | bind $fstring <Key-Return> {dofind 1 1} |
968ce45c | 2446 | bind $sha1entry <Key-Return> {gotocommit; break} |
ee3dc72e | 2447 | bind $sha1entry <<PasteSelection>> clearsha1 |
7fcceed7 PM |
2448 | bind $cflist <1> {sel_flist %W %x %y; break} |
2449 | bind $cflist <B1-Motion> {sel_flist %W %x %y; break} | |
f8b28a40 | 2450 | bind $cflist <ButtonRelease-1> {treeclick %W %x %y} |
d277e89f PM |
2451 | global ctxbut |
2452 | bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y} | |
7cdc3556 | 2453 | bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y} |
ea13cba1 PM |
2454 | |
2455 | set maincursor [. cget -cursor] | |
2456 | set textcursor [$ctext cget -cursor] | |
94a2eede | 2457 | set curtextcursor $textcursor |
84ba7345 | 2458 | |
c8dfbcf9 | 2459 | set rowctxmenu .rowctxmenu |
f2d0bbbd | 2460 | makemenu $rowctxmenu { |
79056034 PM |
2461 | {mc "Diff this -> selected" command {diffvssel 0}} |
2462 | {mc "Diff selected -> this" command {diffvssel 1}} | |
2463 | {mc "Make patch" command mkpatch} | |
2464 | {mc "Create tag" command mktag} | |
2465 | {mc "Write commit to file" command writecommit} | |
2466 | {mc "Create new branch" command mkbranch} | |
2467 | {mc "Cherry-pick this commit" command cherrypick} | |
2468 | {mc "Reset HEAD branch to here" command resethead} | |
b9fdba7f PM |
2469 | {mc "Mark this commit" command markhere} |
2470 | {mc "Return to mark" command gotomark} | |
2471 | {mc "Find descendant of this and mark" command find_common_desc} | |
010509f2 | 2472 | {mc "Compare with marked commit" command compare_commits} |
f2d0bbbd PM |
2473 | } |
2474 | $rowctxmenu configure -tearoff 0 | |
10299152 | 2475 | |
219ea3a9 | 2476 | set fakerowmenu .fakerowmenu |
f2d0bbbd | 2477 | makemenu $fakerowmenu { |
79056034 PM |
2478 | {mc "Diff this -> selected" command {diffvssel 0}} |
2479 | {mc "Diff selected -> this" command {diffvssel 1}} | |
2480 | {mc "Make patch" command mkpatch} | |
f2d0bbbd PM |
2481 | } |
2482 | $fakerowmenu configure -tearoff 0 | |
219ea3a9 | 2483 | |
10299152 | 2484 | set headctxmenu .headctxmenu |
f2d0bbbd | 2485 | makemenu $headctxmenu { |
79056034 PM |
2486 | {mc "Check out this branch" command cobranch} |
2487 | {mc "Remove this branch" command rmbranch} | |
f2d0bbbd PM |
2488 | } |
2489 | $headctxmenu configure -tearoff 0 | |
3244729a PM |
2490 | |
2491 | global flist_menu | |
2492 | set flist_menu .flistctxmenu | |
f2d0bbbd | 2493 | makemenu $flist_menu { |
79056034 PM |
2494 | {mc "Highlight this too" command {flist_hl 0}} |
2495 | {mc "Highlight this only" command {flist_hl 1}} | |
2496 | {mc "External diff" command {external_diff}} | |
2497 | {mc "Blame parent commit" command {external_blame 1}} | |
f2d0bbbd PM |
2498 | } |
2499 | $flist_menu configure -tearoff 0 | |
7cdc3556 AG |
2500 | |
2501 | global diff_menu | |
2502 | set diff_menu .diffctxmenu | |
2503 | makemenu $diff_menu { | |
8a897742 | 2504 | {mc "Show origin of this line" command show_line_source} |
7cdc3556 AG |
2505 | {mc "Run git gui blame on this line" command {external_blame_diff}} |
2506 | } | |
2507 | $diff_menu configure -tearoff 0 | |
df3d83b1 PM |
2508 | } |
2509 | ||
314c3093 ML |
2510 | # Windows sends all mouse wheel events to the current focused window, not |
2511 | # the one where the mouse hovers, so bind those events here and redirect | |
2512 | # to the correct window | |
2513 | proc windows_mousewheel_redirector {W X Y D} { | |
2514 | global canv canv2 canv3 | |
2515 | set w [winfo containing -displayof $W $X $Y] | |
2516 | if {$w ne ""} { | |
2517 | set u [expr {$D < 0 ? 5 : -5}] | |
2518 | if {$w == $canv || $w == $canv2 || $w == $canv3} { | |
2519 | allcanvs yview scroll $u units | |
2520 | } else { | |
2521 | catch { | |
2522 | $w yview scroll $u units | |
2523 | } | |
2524 | } | |
2525 | } | |
2526 | } | |
2527 | ||
6df7403a PM |
2528 | # Update row number label when selectedline changes |
2529 | proc selectedline_change {n1 n2 op} { | |
2530 | global selectedline rownumsel | |
2531 | ||
94b4a69f | 2532 | if {$selectedline eq {}} { |
6df7403a PM |
2533 | set rownumsel {} |
2534 | } else { | |
2535 | set rownumsel [expr {$selectedline + 1}] | |
2536 | } | |
2537 | } | |
2538 | ||
be0cd098 PM |
2539 | # mouse-2 makes all windows scan vertically, but only the one |
2540 | # the cursor is in scans horizontally | |
2541 | proc canvscan {op w x y} { | |
2542 | global canv canv2 canv3 | |
2543 | foreach c [list $canv $canv2 $canv3] { | |
2544 | if {$c == $w} { | |
2545 | $c scan $op $x $y | |
2546 | } else { | |
2547 | $c scan $op 0 $y | |
2548 | } | |
2549 | } | |
2550 | } | |
2551 | ||
9f1afe05 PM |
2552 | proc scrollcanv {cscroll f0 f1} { |
2553 | $cscroll set $f0 $f1 | |
31c0eaa8 | 2554 | drawvisible |
908c3585 | 2555 | flushhighlights |
9f1afe05 PM |
2556 | } |
2557 | ||
df3d83b1 PM |
2558 | # when we make a key binding for the toplevel, make sure |
2559 | # it doesn't get triggered when that key is pressed in the | |
2560 | # find string entry widget. | |
2561 | proc bindkey {ev script} { | |
887fe3c4 | 2562 | global entries |
df3d83b1 PM |
2563 | bind . $ev $script |
2564 | set escript [bind Entry $ev] | |
2565 | if {$escript == {}} { | |
2566 | set escript [bind Entry <Key>] | |
2567 | } | |
887fe3c4 PM |
2568 | foreach e $entries { |
2569 | bind $e $ev "$escript; break" | |
2570 | } | |
df3d83b1 PM |
2571 | } |
2572 | ||
2573 | # set the focus back to the toplevel for any click outside | |
887fe3c4 | 2574 | # the entry widgets |
df3d83b1 | 2575 | proc click {w} { |
bd441de4 ML |
2576 | global ctext entries |
2577 | foreach e [concat $entries $ctext] { | |
887fe3c4 | 2578 | if {$w == $e} return |
df3d83b1 | 2579 | } |
887fe3c4 | 2580 | focus . |
0fba86b3 PM |
2581 | } |
2582 | ||
bb3edc8b PM |
2583 | # Adjust the progress bar for a change in requested extent or canvas size |
2584 | proc adjustprogress {} { | |
2585 | global progresscanv progressitem progresscoords | |
2586 | global fprogitem fprogcoord lastprogupdate progupdatepending | |
d93f1713 PT |
2587 | global rprogitem rprogcoord use_ttk |
2588 | ||
2589 | if {$use_ttk} { | |
2590 | $progresscanv configure -value [expr {int($fprogcoord * 100)}] | |
2591 | return | |
2592 | } | |
bb3edc8b PM |
2593 | |
2594 | set w [expr {[winfo width $progresscanv] - 4}] | |
2595 | set x0 [expr {$w * [lindex $progresscoords 0]}] | |
2596 | set x1 [expr {$w * [lindex $progresscoords 1]}] | |
2597 | set h [winfo height $progresscanv] | |
2598 | $progresscanv coords $progressitem $x0 0 $x1 $h | |
2599 | $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h | |
a137a90f | 2600 | $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h |
bb3edc8b PM |
2601 | set now [clock clicks -milliseconds] |
2602 | if {$now >= $lastprogupdate + 100} { | |
2603 | set progupdatepending 0 | |
2604 | update | |
2605 | } elseif {!$progupdatepending} { | |
2606 | set progupdatepending 1 | |
2607 | after [expr {$lastprogupdate + 100 - $now}] doprogupdate | |
2608 | } | |
2609 | } | |
2610 | ||
2611 | proc doprogupdate {} { | |
2612 | global lastprogupdate progupdatepending | |
2613 | ||
2614 | if {$progupdatepending} { | |
2615 | set progupdatepending 0 | |
2616 | set lastprogupdate [clock clicks -milliseconds] | |
2617 | update | |
2618 | } | |
2619 | } | |
2620 | ||
0fba86b3 | 2621 | proc savestuff {w} { |
32f1b3e4 | 2622 | global canv canv2 canv3 mainfont textfont uifont tabstop |
712fcc08 | 2623 | global stuffsaved findmergefiles maxgraphpct |
219ea3a9 | 2624 | global maxwidth showneartags showlocalchanges |
2d480856 | 2625 | global viewname viewfiles viewargs viewargscmd viewperm nextviewnum |
7a39a17a | 2626 | global cmitmode wrapcomment datetimeformat limitdiffs |
5497f7a2 | 2627 | global colors uicolor bgcolor fgcolor diffcolors diffcontext selectbgcolor |
d93f1713 | 2628 | global autoselect extdifftool perfile_attrs markbgcolor use_ttk |
0cc08ff7 | 2629 | global hideremotes want_ttk |
4ef17537 | 2630 | |
0fba86b3 | 2631 | if {$stuffsaved} return |
df3d83b1 | 2632 | if {![winfo viewable .]} return |
0fba86b3 | 2633 | catch { |
9bedb0e1 | 2634 | if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new} |
0fba86b3 | 2635 | set f [open "~/.gitk-new" w] |
9832e4f2 PM |
2636 | if {$::tcl_platform(platform) eq {windows}} { |
2637 | file attributes "~/.gitk-new" -hidden true | |
2638 | } | |
f0654861 PM |
2639 | puts $f [list set mainfont $mainfont] |
2640 | puts $f [list set textfont $textfont] | |
4840be66 | 2641 | puts $f [list set uifont $uifont] |
7e12f1a6 | 2642 | puts $f [list set tabstop $tabstop] |
f0654861 | 2643 | puts $f [list set findmergefiles $findmergefiles] |
8d858d1a | 2644 | puts $f [list set maxgraphpct $maxgraphpct] |
04c13d38 | 2645 | puts $f [list set maxwidth $maxwidth] |
f8b28a40 | 2646 | puts $f [list set cmitmode $cmitmode] |
f1b86294 | 2647 | puts $f [list set wrapcomment $wrapcomment] |
95293b58 | 2648 | puts $f [list set autoselect $autoselect] |
b8ab2e17 | 2649 | puts $f [list set showneartags $showneartags] |
ffe15297 | 2650 | puts $f [list set hideremotes $hideremotes] |
219ea3a9 | 2651 | puts $f [list set showlocalchanges $showlocalchanges] |
e8b5f4be | 2652 | puts $f [list set datetimeformat $datetimeformat] |
7a39a17a | 2653 | puts $f [list set limitdiffs $limitdiffs] |
5497f7a2 | 2654 | puts $f [list set uicolor $uicolor] |
0cc08ff7 | 2655 | puts $f [list set want_ttk $want_ttk] |
f8a2c0d1 PM |
2656 | puts $f [list set bgcolor $bgcolor] |
2657 | puts $f [list set fgcolor $fgcolor] | |
2658 | puts $f [list set colors $colors] | |
2659 | puts $f [list set diffcolors $diffcolors] | |
e3e901be | 2660 | puts $f [list set markbgcolor $markbgcolor] |
890fae70 | 2661 | puts $f [list set diffcontext $diffcontext] |
60378c0c | 2662 | puts $f [list set selectbgcolor $selectbgcolor] |
314f5de1 | 2663 | puts $f [list set extdifftool $extdifftool] |
39ee47ef | 2664 | puts $f [list set perfile_attrs $perfile_attrs] |
e9937d2a | 2665 | |
b6047c5a | 2666 | puts $f "set geometry(main) [wm geometry .]" |
c876dbad | 2667 | puts $f "set geometry(state) [wm state .]" |
e9937d2a JH |
2668 | puts $f "set geometry(topwidth) [winfo width .tf]" |
2669 | puts $f "set geometry(topheight) [winfo height .tf]" | |
d93f1713 PT |
2670 | if {$use_ttk} { |
2671 | puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\"" | |
2672 | puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\"" | |
2673 | } else { | |
2674 | puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\"" | |
2675 | puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\"" | |
2676 | } | |
e9937d2a JH |
2677 | puts $f "set geometry(botwidth) [winfo width .bleft]" |
2678 | puts $f "set geometry(botheight) [winfo height .bleft]" | |
2679 | ||
a90a6d24 PM |
2680 | puts -nonewline $f "set permviews {" |
2681 | for {set v 0} {$v < $nextviewnum} {incr v} { | |
2682 | if {$viewperm($v)} { | |
2d480856 | 2683 | puts $f "{[list $viewname($v) $viewfiles($v) $viewargs($v) $viewargscmd($v)]}" |
a90a6d24 PM |
2684 | } |
2685 | } | |
2686 | puts $f "}" | |
0fba86b3 PM |
2687 | close $f |
2688 | file rename -force "~/.gitk-new" "~/.gitk" | |
2689 | } | |
2690 | set stuffsaved 1 | |
1db95b00 PM |
2691 | } |
2692 | ||
43bddeb4 | 2693 | proc resizeclistpanes {win w} { |
d93f1713 | 2694 | global oldwidth use_ttk |
418c4c7b | 2695 | if {[info exists oldwidth($win)]} { |
d93f1713 PT |
2696 | if {$use_ttk} { |
2697 | set s0 [$win sashpos 0] | |
2698 | set s1 [$win sashpos 1] | |
2699 | } else { | |
2700 | set s0 [$win sash coord 0] | |
2701 | set s1 [$win sash coord 1] | |
2702 | } | |
43bddeb4 PM |
2703 | if {$w < 60} { |
2704 | set sash0 [expr {int($w/2 - 2)}] | |
2705 | set sash1 [expr {int($w*5/6 - 2)}] | |
2706 | } else { | |
2707 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
2708 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
2709 | set sash1 [expr {int($factor * [lindex $s1 0])}] | |
2710 | if {$sash0 < 30} { | |
2711 | set sash0 30 | |
2712 | } | |
2713 | if {$sash1 < $sash0 + 20} { | |
2ed49d54 | 2714 | set sash1 [expr {$sash0 + 20}] |
43bddeb4 PM |
2715 | } |
2716 | if {$sash1 > $w - 10} { | |
2ed49d54 | 2717 | set sash1 [expr {$w - 10}] |
43bddeb4 | 2718 | if {$sash0 > $sash1 - 20} { |
2ed49d54 | 2719 | set sash0 [expr {$sash1 - 20}] |
43bddeb4 PM |
2720 | } |
2721 | } | |
2722 | } | |
d93f1713 PT |
2723 | if {$use_ttk} { |
2724 | $win sashpos 0 $sash0 | |
2725 | $win sashpos 1 $sash1 | |
2726 | } else { | |
2727 | $win sash place 0 $sash0 [lindex $s0 1] | |
2728 | $win sash place 1 $sash1 [lindex $s1 1] | |
2729 | } | |
43bddeb4 PM |
2730 | } |
2731 | set oldwidth($win) $w | |
2732 | } | |
2733 | ||
2734 | proc resizecdetpanes {win w} { | |
d93f1713 | 2735 | global oldwidth use_ttk |
418c4c7b | 2736 | if {[info exists oldwidth($win)]} { |
d93f1713 PT |
2737 | if {$use_ttk} { |
2738 | set s0 [$win sashpos 0] | |
2739 | } else { | |
2740 | set s0 [$win sash coord 0] | |
2741 | } | |
43bddeb4 PM |
2742 | if {$w < 60} { |
2743 | set sash0 [expr {int($w*3/4 - 2)}] | |
2744 | } else { | |
2745 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
2746 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
2747 | if {$sash0 < 45} { | |
2748 | set sash0 45 | |
2749 | } | |
2750 | if {$sash0 > $w - 15} { | |
2ed49d54 | 2751 | set sash0 [expr {$w - 15}] |
43bddeb4 PM |
2752 | } |
2753 | } | |
d93f1713 PT |
2754 | if {$use_ttk} { |
2755 | $win sashpos 0 $sash0 | |
2756 | } else { | |
2757 | $win sash place 0 $sash0 [lindex $s0 1] | |
2758 | } | |
43bddeb4 PM |
2759 | } |
2760 | set oldwidth($win) $w | |
2761 | } | |
2762 | ||
b5721c72 PM |
2763 | proc allcanvs args { |
2764 | global canv canv2 canv3 | |
2765 | eval $canv $args | |
2766 | eval $canv2 $args | |
2767 | eval $canv3 $args | |
2768 | } | |
2769 | ||
2770 | proc bindall {event action} { | |
2771 | global canv canv2 canv3 | |
2772 | bind $canv $event $action | |
2773 | bind $canv2 $event $action | |
2774 | bind $canv3 $event $action | |
2775 | } | |
2776 | ||
9a40c50c | 2777 | proc about {} { |
d93f1713 | 2778 | global uifont NS |
9a40c50c PM |
2779 | set w .about |
2780 | if {[winfo exists $w]} { | |
2781 | raise $w | |
2782 | return | |
2783 | } | |
d93f1713 | 2784 | ttk_toplevel $w |
d990cedf | 2785 | wm title $w [mc "About gitk"] |
e7d64008 | 2786 | make_transient $w . |
d990cedf | 2787 | message $w.m -text [mc " |
9f1afe05 | 2788 | Gitk - a commit viewer for git |
9a40c50c | 2789 | |
e7d516b6 | 2790 | Copyright \u00a9 2005-2010 Paul Mackerras |
9a40c50c | 2791 | |
d990cedf | 2792 | Use and redistribute under the terms of the GNU General Public License"] \ |
3a950e9a ER |
2793 | -justify center -aspect 400 -border 2 -bg white -relief groove |
2794 | pack $w.m -side top -fill x -padx 2 -pady 2 | |
d93f1713 | 2795 | ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active |
9a40c50c | 2796 | pack $w.ok -side bottom |
3a950e9a ER |
2797 | bind $w <Visibility> "focus $w.ok" |
2798 | bind $w <Key-Escape> "destroy $w" | |
2799 | bind $w <Key-Return> "destroy $w" | |
d93f1713 | 2800 | tk::PlaceWindow $w widget . |
9a40c50c PM |
2801 | } |
2802 | ||
4e95e1f7 | 2803 | proc keys {} { |
d93f1713 | 2804 | global NS |
4e95e1f7 PM |
2805 | set w .keys |
2806 | if {[winfo exists $w]} { | |
2807 | raise $w | |
2808 | return | |
2809 | } | |
d23d98d3 SP |
2810 | if {[tk windowingsystem] eq {aqua}} { |
2811 | set M1T Cmd | |
2812 | } else { | |
2813 | set M1T Ctrl | |
2814 | } | |
d93f1713 | 2815 | ttk_toplevel $w |
d990cedf | 2816 | wm title $w [mc "Gitk key bindings"] |
e7d64008 | 2817 | make_transient $w . |
3d2c998e MB |
2818 | message $w.m -text " |
2819 | [mc "Gitk key bindings:"] | |
2820 | ||
2821 | [mc "<%s-Q> Quit" $M1T] | |
decd0a1e | 2822 | [mc "<%s-W> Close window" $M1T] |
3d2c998e MB |
2823 | [mc "<Home> Move to first commit"] |
2824 | [mc "<End> Move to last commit"] | |
2825 | [mc "<Up>, p, i Move up one commit"] | |
2826 | [mc "<Down>, n, k Move down one commit"] | |
2827 | [mc "<Left>, z, j Go back in history list"] | |
2828 | [mc "<Right>, x, l Go forward in history list"] | |
2829 | [mc "<PageUp> Move up one page in commit list"] | |
2830 | [mc "<PageDown> Move down one page in commit list"] | |
2831 | [mc "<%s-Home> Scroll to top of commit list" $M1T] | |
2832 | [mc "<%s-End> Scroll to bottom of commit list" $M1T] | |
2833 | [mc "<%s-Up> Scroll commit list up one line" $M1T] | |
2834 | [mc "<%s-Down> Scroll commit list down one line" $M1T] | |
2835 | [mc "<%s-PageUp> Scroll commit list up one page" $M1T] | |
2836 | [mc "<%s-PageDown> Scroll commit list down one page" $M1T] | |
2837 | [mc "<Shift-Up> Find backwards (upwards, later commits)"] | |
2838 | [mc "<Shift-Down> Find forwards (downwards, earlier commits)"] | |
2839 | [mc "<Delete>, b Scroll diff view up one page"] | |
2840 | [mc "<Backspace> Scroll diff view up one page"] | |
2841 | [mc "<Space> Scroll diff view down one page"] | |
2842 | [mc "u Scroll diff view up 18 lines"] | |
2843 | [mc "d Scroll diff view down 18 lines"] | |
2844 | [mc "<%s-F> Find" $M1T] | |
2845 | [mc "<%s-G> Move to next find hit" $M1T] | |
2846 | [mc "<Return> Move to next find hit"] | |
97bed034 | 2847 | [mc "/ Focus the search box"] |
3d2c998e MB |
2848 | [mc "? Move to previous find hit"] |
2849 | [mc "f Scroll diff view to next file"] | |
2850 | [mc "<%s-S> Search for next hit in diff view" $M1T] | |
2851 | [mc "<%s-R> Search for previous hit in diff view" $M1T] | |
2852 | [mc "<%s-KP+> Increase font size" $M1T] | |
2853 | [mc "<%s-plus> Increase font size" $M1T] | |
2854 | [mc "<%s-KP-> Decrease font size" $M1T] | |
2855 | [mc "<%s-minus> Decrease font size" $M1T] | |
2856 | [mc "<F5> Update"] | |
2857 | " \ | |
3a950e9a ER |
2858 | -justify left -bg white -border 2 -relief groove |
2859 | pack $w.m -side top -fill both -padx 2 -pady 2 | |
d93f1713 | 2860 | ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active |
76f15947 | 2861 | bind $w <Key-Escape> [list destroy $w] |
4e95e1f7 | 2862 | pack $w.ok -side bottom |
3a950e9a ER |
2863 | bind $w <Visibility> "focus $w.ok" |
2864 | bind $w <Key-Escape> "destroy $w" | |
2865 | bind $w <Key-Return> "destroy $w" | |
4e95e1f7 PM |
2866 | } |
2867 | ||
7fcceed7 PM |
2868 | # Procedures for manipulating the file list window at the |
2869 | # bottom right of the overall window. | |
f8b28a40 PM |
2870 | |
2871 | proc treeview {w l openlevs} { | |
2872 | global treecontents treediropen treeheight treeparent treeindex | |
2873 | ||
2874 | set ix 0 | |
2875 | set treeindex() 0 | |
2876 | set lev 0 | |
2877 | set prefix {} | |
2878 | set prefixend -1 | |
2879 | set prefendstack {} | |
2880 | set htstack {} | |
2881 | set ht 0 | |
2882 | set treecontents() {} | |
2883 | $w conf -state normal | |
2884 | foreach f $l { | |
2885 | while {[string range $f 0 $prefixend] ne $prefix} { | |
2886 | if {$lev <= $openlevs} { | |
2887 | $w mark set e:$treeindex($prefix) "end -1c" | |
2888 | $w mark gravity e:$treeindex($prefix) left | |
2889 | } | |
2890 | set treeheight($prefix) $ht | |
2891 | incr ht [lindex $htstack end] | |
2892 | set htstack [lreplace $htstack end end] | |
2893 | set prefixend [lindex $prefendstack end] | |
2894 | set prefendstack [lreplace $prefendstack end end] | |
2895 | set prefix [string range $prefix 0 $prefixend] | |
2896 | incr lev -1 | |
2897 | } | |
2898 | set tail [string range $f [expr {$prefixend+1}] end] | |
2899 | while {[set slash [string first "/" $tail]] >= 0} { | |
2900 | lappend htstack $ht | |
2901 | set ht 0 | |
2902 | lappend prefendstack $prefixend | |
2903 | incr prefixend [expr {$slash + 1}] | |
2904 | set d [string range $tail 0 $slash] | |
2905 | lappend treecontents($prefix) $d | |
2906 | set oldprefix $prefix | |
2907 | append prefix $d | |
2908 | set treecontents($prefix) {} | |
2909 | set treeindex($prefix) [incr ix] | |
2910 | set treeparent($prefix) $oldprefix | |
2911 | set tail [string range $tail [expr {$slash+1}] end] | |
2912 | if {$lev <= $openlevs} { | |
2913 | set ht 1 | |
2914 | set treediropen($prefix) [expr {$lev < $openlevs}] | |
2915 | set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}] | |
2916 | $w mark set d:$ix "end -1c" | |
2917 | $w mark gravity d:$ix left | |
2918 | set str "\n" | |
2919 | for {set i 0} {$i < $lev} {incr i} {append str "\t"} | |
2920 | $w insert end $str | |
2921 | $w image create end -align center -image $bm -padx 1 \ | |
2922 | -name a:$ix | |
45a9d505 | 2923 | $w insert end $d [highlight_tag $prefix] |
f8b28a40 PM |
2924 | $w mark set s:$ix "end -1c" |
2925 | $w mark gravity s:$ix left | |
2926 | } | |
2927 | incr lev | |
2928 | } | |
2929 | if {$tail ne {}} { | |
2930 | if {$lev <= $openlevs} { | |
2931 | incr ht | |
2932 | set str "\n" | |
2933 | for {set i 0} {$i < $lev} {incr i} {append str "\t"} | |
2934 | $w insert end $str | |
45a9d505 | 2935 | $w insert end $tail [highlight_tag $f] |
f8b28a40 PM |
2936 | } |
2937 | lappend treecontents($prefix) $tail | |
2938 | } | |
2939 | } | |
2940 | while {$htstack ne {}} { | |
2941 | set treeheight($prefix) $ht | |
2942 | incr ht [lindex $htstack end] | |
2943 | set htstack [lreplace $htstack end end] | |
096e96b4 BD |
2944 | set prefixend [lindex $prefendstack end] |
2945 | set prefendstack [lreplace $prefendstack end end] | |
2946 | set prefix [string range $prefix 0 $prefixend] | |
f8b28a40 PM |
2947 | } |
2948 | $w conf -state disabled | |
2949 | } | |
2950 | ||
2951 | proc linetoelt {l} { | |
2952 | global treeheight treecontents | |
2953 | ||
2954 | set y 2 | |
2955 | set prefix {} | |
2956 | while {1} { | |
2957 | foreach e $treecontents($prefix) { | |
2958 | if {$y == $l} { | |
2959 | return "$prefix$e" | |
2960 | } | |
2961 | set n 1 | |
2962 | if {[string index $e end] eq "/"} { | |
2963 | set n $treeheight($prefix$e) | |
2964 | if {$y + $n > $l} { | |
2965 | append prefix $e | |
2966 | incr y | |
2967 | break | |
2968 | } | |
2969 | } | |
2970 | incr y $n | |
2971 | } | |
2972 | } | |
2973 | } | |
2974 | ||
45a9d505 PM |
2975 | proc highlight_tree {y prefix} { |
2976 | global treeheight treecontents cflist | |
2977 | ||
2978 | foreach e $treecontents($prefix) { | |
2979 | set path $prefix$e | |
2980 | if {[highlight_tag $path] ne {}} { | |
2981 | $cflist tag add bold $y.0 "$y.0 lineend" | |
2982 | } | |
2983 | incr y | |
2984 | if {[string index $e end] eq "/" && $treeheight($path) > 1} { | |
2985 | set y [highlight_tree $y $path] | |
2986 | } | |
2987 | } | |
2988 | return $y | |
2989 | } | |
2990 | ||
f8b28a40 PM |
2991 | proc treeclosedir {w dir} { |
2992 | global treediropen treeheight treeparent treeindex | |
2993 | ||
2994 | set ix $treeindex($dir) | |
2995 | $w conf -state normal | |
2996 | $w delete s:$ix e:$ix | |
2997 | set treediropen($dir) 0 | |
2998 | $w image configure a:$ix -image tri-rt | |
2999 | $w conf -state disabled | |
3000 | set n [expr {1 - $treeheight($dir)}] | |
3001 | while {$dir ne {}} { | |
3002 | incr treeheight($dir) $n | |
3003 | set dir $treeparent($dir) | |
3004 | } | |
3005 | } | |
3006 | ||
3007 | proc treeopendir {w dir} { | |
3008 | global treediropen treeheight treeparent treecontents treeindex | |
3009 | ||
3010 | set ix $treeindex($dir) | |
3011 | $w conf -state normal | |
3012 | $w image configure a:$ix -image tri-dn | |
3013 | $w mark set e:$ix s:$ix | |
3014 | $w mark gravity e:$ix right | |
3015 | set lev 0 | |
3016 | set str "\n" | |
3017 | set n [llength $treecontents($dir)] | |
3018 | for {set x $dir} {$x ne {}} {set x $treeparent($x)} { | |
3019 | incr lev | |
3020 | append str "\t" | |
3021 | incr treeheight($x) $n | |
3022 | } | |
3023 | foreach e $treecontents($dir) { | |
45a9d505 | 3024 | set de $dir$e |
f8b28a40 | 3025 | if {[string index $e end] eq "/"} { |
f8b28a40 PM |
3026 | set iy $treeindex($de) |
3027 | $w mark set d:$iy e:$ix | |
3028 | $w mark gravity d:$iy left | |
3029 | $w insert e:$ix $str | |
3030 | set treediropen($de) 0 | |
3031 | $w image create e:$ix -align center -image tri-rt -padx 1 \ | |
3032 | -name a:$iy | |
45a9d505 | 3033 | $w insert e:$ix $e [highlight_tag $de] |
f8b28a40 PM |
3034 | $w mark set s:$iy e:$ix |
3035 | $w mark gravity s:$iy left | |
3036 | set treeheight($de) 1 | |
3037 | } else { | |
3038 | $w insert e:$ix $str | |
45a9d505 | 3039 | $w insert e:$ix $e [highlight_tag $de] |
f8b28a40 PM |
3040 | } |
3041 | } | |
b8a640ee | 3042 | $w mark gravity e:$ix right |
f8b28a40 PM |
3043 | $w conf -state disabled |
3044 | set treediropen($dir) 1 | |
3045 | set top [lindex [split [$w index @0,0] .] 0] | |
3046 | set ht [$w cget -height] | |
3047 | set l [lindex [split [$w index s:$ix] .] 0] | |
3048 | if {$l < $top} { | |
3049 | $w yview $l.0 | |
3050 | } elseif {$l + $n + 1 > $top + $ht} { | |
3051 | set top [expr {$l + $n + 2 - $ht}] | |
3052 | if {$l < $top} { | |
3053 | set top $l | |
3054 | } | |
3055 | $w yview $top.0 | |
3056 | } | |
3057 | } | |
3058 | ||
3059 | proc treeclick {w x y} { | |
3060 | global treediropen cmitmode ctext cflist cflist_top | |
3061 | ||
3062 | if {$cmitmode ne "tree"} return | |
3063 | if {![info exists cflist_top]} return | |
3064 | set l [lindex [split [$w index "@$x,$y"] "."] 0] | |
3065 | $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" | |
3066 | $cflist tag add highlight $l.0 "$l.0 lineend" | |
3067 | set cflist_top $l | |
3068 | if {$l == 1} { | |
3069 | $ctext yview 1.0 | |
3070 | return | |
3071 | } | |
3072 | set e [linetoelt $l] | |
3073 | if {[string index $e end] ne "/"} { | |
3074 | showfile $e | |
3075 | } elseif {$treediropen($e)} { | |
3076 | treeclosedir $w $e | |
3077 | } else { | |
3078 | treeopendir $w $e | |
3079 | } | |
3080 | } | |
3081 | ||
3082 | proc setfilelist {id} { | |
8a897742 | 3083 | global treefilelist cflist jump_to_here |
f8b28a40 PM |
3084 | |
3085 | treeview $cflist $treefilelist($id) 0 | |
8a897742 PM |
3086 | if {$jump_to_here ne {}} { |
3087 | set f [lindex $jump_to_here 0] | |
3088 | if {[lsearch -exact $treefilelist($id) $f] >= 0} { | |
3089 | showfile $f | |
3090 | } | |
3091 | } | |
f8b28a40 PM |
3092 | } |
3093 | ||
3094 | image create bitmap tri-rt -background black -foreground blue -data { | |
3095 | #define tri-rt_width 13 | |
3096 | #define tri-rt_height 13 | |
3097 | static unsigned char tri-rt_bits[] = { | |
3098 | 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00, | |
3099 | 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00, | |
3100 | 0x00, 0x00}; | |
3101 | } -maskdata { | |
3102 | #define tri-rt-mask_width 13 | |
3103 | #define tri-rt-mask_height 13 | |
3104 | static unsigned char tri-rt-mask_bits[] = { | |
3105 | 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, | |
3106 | 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00, | |
3107 | 0x08, 0x00}; | |
3108 | } | |
3109 | image create bitmap tri-dn -background black -foreground blue -data { | |
3110 | #define tri-dn_width 13 | |
3111 | #define tri-dn_height 13 | |
3112 | static unsigned char tri-dn_bits[] = { | |
3113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03, | |
3114 | 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
3115 | 0x00, 0x00}; | |
3116 | } -maskdata { | |
3117 | #define tri-dn-mask_width 13 | |
3118 | #define tri-dn-mask_height 13 | |
3119 | static unsigned char tri-dn-mask_bits[] = { | |
3120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07, | |
3121 | 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, | |
3122 | 0x00, 0x00}; | |
3123 | } | |
3124 | ||
887c996e PM |
3125 | image create bitmap reficon-T -background black -foreground yellow -data { |
3126 | #define tagicon_width 13 | |
3127 | #define tagicon_height 9 | |
3128 | static unsigned char tagicon_bits[] = { | |
3129 | 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07, | |
3130 | 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00}; | |
3131 | } -maskdata { | |
3132 | #define tagicon-mask_width 13 | |
3133 | #define tagicon-mask_height 9 | |
3134 | static unsigned char tagicon-mask_bits[] = { | |
3135 | 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, | |
3136 | 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00}; | |
3137 | } | |
3138 | set rectdata { | |
3139 | #define headicon_width 13 | |
3140 | #define headicon_height 9 | |
3141 | static unsigned char headicon_bits[] = { | |
3142 | 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07, | |
3143 | 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00}; | |
3144 | } | |
3145 | set rectmask { | |
3146 | #define headicon-mask_width 13 | |
3147 | #define headicon-mask_height 9 | |
3148 | static unsigned char headicon-mask_bits[] = { | |
3149 | 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, | |
3150 | 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00}; | |
3151 | } | |
3152 | image create bitmap reficon-H -background black -foreground green \ | |
3153 | -data $rectdata -maskdata $rectmask | |
3154 | image create bitmap reficon-o -background black -foreground "#ddddff" \ | |
3155 | -data $rectdata -maskdata $rectmask | |
3156 | ||
7fcceed7 | 3157 | proc init_flist {first} { |
7fcc92bf | 3158 | global cflist cflist_top difffilestart |
7fcceed7 PM |
3159 | |
3160 | $cflist conf -state normal | |
3161 | $cflist delete 0.0 end | |
3162 | if {$first ne {}} { | |
3163 | $cflist insert end $first | |
3164 | set cflist_top 1 | |
7fcceed7 PM |
3165 | $cflist tag add highlight 1.0 "1.0 lineend" |
3166 | } else { | |
3167 | catch {unset cflist_top} | |
3168 | } | |
3169 | $cflist conf -state disabled | |
3170 | set difffilestart {} | |
3171 | } | |
3172 | ||
63b79191 PM |
3173 | proc highlight_tag {f} { |
3174 | global highlight_paths | |
3175 | ||
3176 | foreach p $highlight_paths { | |
3177 | if {[string match $p $f]} { | |
3178 | return "bold" | |
3179 | } | |
3180 | } | |
3181 | return {} | |
3182 | } | |
3183 | ||
3184 | proc highlight_filelist {} { | |
45a9d505 | 3185 | global cmitmode cflist |
63b79191 | 3186 | |
45a9d505 PM |
3187 | $cflist conf -state normal |
3188 | if {$cmitmode ne "tree"} { | |
63b79191 PM |
3189 | set end [lindex [split [$cflist index end] .] 0] |
3190 | for {set l 2} {$l < $end} {incr l} { | |
3191 | set line [$cflist get $l.0 "$l.0 lineend"] | |
3192 | if {[highlight_tag $line] ne {}} { | |
3193 | $cflist tag add bold $l.0 "$l.0 lineend" | |
3194 | } | |
3195 | } | |
45a9d505 PM |
3196 | } else { |
3197 | highlight_tree 2 {} | |
63b79191 | 3198 | } |
45a9d505 | 3199 | $cflist conf -state disabled |
63b79191 PM |
3200 | } |
3201 | ||
3202 | proc unhighlight_filelist {} { | |
45a9d505 | 3203 | global cflist |
63b79191 | 3204 | |
45a9d505 PM |
3205 | $cflist conf -state normal |
3206 | $cflist tag remove bold 1.0 end | |
3207 | $cflist conf -state disabled | |
63b79191 PM |
3208 | } |
3209 | ||
f8b28a40 | 3210 | proc add_flist {fl} { |
45a9d505 | 3211 | global cflist |
7fcceed7 | 3212 | |
45a9d505 PM |
3213 | $cflist conf -state normal |
3214 | foreach f $fl { | |
3215 | $cflist insert end "\n" | |
3216 | $cflist insert end $f [highlight_tag $f] | |
7fcceed7 | 3217 | } |
45a9d505 | 3218 | $cflist conf -state disabled |
7fcceed7 PM |
3219 | } |
3220 | ||
3221 | proc sel_flist {w x y} { | |
45a9d505 | 3222 | global ctext difffilestart cflist cflist_top cmitmode |
7fcceed7 | 3223 | |
f8b28a40 | 3224 | if {$cmitmode eq "tree"} return |
7fcceed7 PM |
3225 | if {![info exists cflist_top]} return |
3226 | set l [lindex [split [$w index "@$x,$y"] "."] 0] | |
89b11d3b PM |
3227 | $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" |
3228 | $cflist tag add highlight $l.0 "$l.0 lineend" | |
3229 | set cflist_top $l | |
f8b28a40 PM |
3230 | if {$l == 1} { |
3231 | $ctext yview 1.0 | |
3232 | } else { | |
3233 | catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} | |
7fcceed7 | 3234 | } |
7fcceed7 PM |
3235 | } |
3236 | ||
3244729a PM |
3237 | proc pop_flist_menu {w X Y x y} { |
3238 | global ctext cflist cmitmode flist_menu flist_menu_file | |
3239 | global treediffs diffids | |
3240 | ||
bb3edc8b | 3241 | stopfinding |
3244729a PM |
3242 | set l [lindex [split [$w index "@$x,$y"] "."] 0] |
3243 | if {$l <= 1} return | |
3244 | if {$cmitmode eq "tree"} { | |
3245 | set e [linetoelt $l] | |
3246 | if {[string index $e end] eq "/"} return | |
3247 | } else { | |
3248 | set e [lindex $treediffs($diffids) [expr {$l-2}]] | |
3249 | } | |
3250 | set flist_menu_file $e | |
314f5de1 TA |
3251 | set xdiffstate "normal" |
3252 | if {$cmitmode eq "tree"} { | |
3253 | set xdiffstate "disabled" | |
3254 | } | |
3255 | # Disable "External diff" item in tree mode | |
3256 | $flist_menu entryconf 2 -state $xdiffstate | |
3244729a PM |
3257 | tk_popup $flist_menu $X $Y |
3258 | } | |
3259 | ||
7cdc3556 AG |
3260 | proc find_ctext_fileinfo {line} { |
3261 | global ctext_file_names ctext_file_lines | |
3262 | ||
3263 | set ok [bsearch $ctext_file_lines $line] | |
3264 | set tline [lindex $ctext_file_lines $ok] | |
3265 | ||
3266 | if {$ok >= [llength $ctext_file_lines] || $line < $tline} { | |
3267 | return {} | |
3268 | } else { | |
3269 | return [list [lindex $ctext_file_names $ok] $tline] | |
3270 | } | |
3271 | } | |
3272 | ||
3273 | proc pop_diff_menu {w X Y x y} { | |
3274 | global ctext diff_menu flist_menu_file | |
3275 | global diff_menu_txtpos diff_menu_line | |
3276 | global diff_menu_filebase | |
3277 | ||
7cdc3556 AG |
3278 | set diff_menu_txtpos [split [$w index "@$x,$y"] "."] |
3279 | set diff_menu_line [lindex $diff_menu_txtpos 0] | |
190ec52c PM |
3280 | # don't pop up the menu on hunk-separator or file-separator lines |
3281 | if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} { | |
3282 | return | |
3283 | } | |
3284 | stopfinding | |
7cdc3556 AG |
3285 | set f [find_ctext_fileinfo $diff_menu_line] |
3286 | if {$f eq {}} return | |
3287 | set flist_menu_file [lindex $f 0] | |
3288 | set diff_menu_filebase [lindex $f 1] | |
3289 | tk_popup $diff_menu $X $Y | |
3290 | } | |
3291 | ||
3244729a | 3292 | proc flist_hl {only} { |
bb3edc8b | 3293 | global flist_menu_file findstring gdttype |
3244729a PM |
3294 | |
3295 | set x [shellquote $flist_menu_file] | |
b007ee20 | 3296 | if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} { |
bb3edc8b | 3297 | set findstring $x |
3244729a | 3298 | } else { |
bb3edc8b | 3299 | append findstring " " $x |
3244729a | 3300 | } |
b007ee20 | 3301 | set gdttype [mc "touching paths:"] |
3244729a PM |
3302 | } |
3303 | ||
c21398be PM |
3304 | proc gitknewtmpdir {} { |
3305 | global diffnum gitktmpdir gitdir | |
3306 | ||
3307 | if {![info exists gitktmpdir]} { | |
3308 | set gitktmpdir [file join [file dirname $gitdir] \ | |
3309 | [format ".gitk-tmp.%s" [pid]]] | |
3310 | if {[catch {file mkdir $gitktmpdir} err]} { | |
3311 | error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" | |
3312 | unset gitktmpdir | |
3313 | return {} | |
3314 | } | |
3315 | set diffnum 0 | |
3316 | } | |
3317 | incr diffnum | |
3318 | set diffdir [file join $gitktmpdir $diffnum] | |
3319 | if {[catch {file mkdir $diffdir} err]} { | |
3320 | error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err" | |
3321 | return {} | |
3322 | } | |
3323 | return $diffdir | |
3324 | } | |
3325 | ||
314f5de1 TA |
3326 | proc save_file_from_commit {filename output what} { |
3327 | global nullfile | |
3328 | ||
3329 | if {[catch {exec git show $filename -- > $output} err]} { | |
3330 | if {[string match "fatal: bad revision *" $err]} { | |
3331 | return $nullfile | |
3332 | } | |
3945d2c0 | 3333 | error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err" |
314f5de1 TA |
3334 | return {} |
3335 | } | |
3336 | return $output | |
3337 | } | |
3338 | ||
3339 | proc external_diff_get_one_file {diffid filename diffdir} { | |
3340 | global nullid nullid2 nullfile | |
3341 | global gitdir | |
3342 | ||
3343 | if {$diffid == $nullid} { | |
3344 | set difffile [file join [file dirname $gitdir] $filename] | |
3345 | if {[file exists $difffile]} { | |
3346 | return $difffile | |
3347 | } | |
3348 | return $nullfile | |
3349 | } | |
3350 | if {$diffid == $nullid2} { | |
3351 | set difffile [file join $diffdir "\[index\] [file tail $filename]"] | |
3352 | return [save_file_from_commit :$filename $difffile index] | |
3353 | } | |
3354 | set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"] | |
3355 | return [save_file_from_commit $diffid:$filename $difffile \ | |
3356 | "revision $diffid"] | |
3357 | } | |
3358 | ||
3359 | proc external_diff {} { | |
c21398be | 3360 | global nullid nullid2 |
314f5de1 TA |
3361 | global flist_menu_file |
3362 | global diffids | |
c21398be | 3363 | global extdifftool |
314f5de1 TA |
3364 | |
3365 | if {[llength $diffids] == 1} { | |
3366 | # no reference commit given | |
3367 | set diffidto [lindex $diffids 0] | |
3368 | if {$diffidto eq $nullid} { | |
3369 | # diffing working copy with index | |
3370 | set diffidfrom $nullid2 | |
3371 | } elseif {$diffidto eq $nullid2} { | |
3372 | # diffing index with HEAD | |
3373 | set diffidfrom "HEAD" | |
3374 | } else { | |
3375 | # use first parent commit | |
3376 | global parentlist selectedline | |
3377 | set diffidfrom [lindex $parentlist $selectedline 0] | |
3378 | } | |
3379 | } else { | |
3380 | set diffidfrom [lindex $diffids 0] | |
3381 | set diffidto [lindex $diffids 1] | |
3382 | } | |
3383 | ||
3384 | # make sure that several diffs wont collide | |
c21398be PM |
3385 | set diffdir [gitknewtmpdir] |
3386 | if {$diffdir eq {}} return | |
314f5de1 TA |
3387 | |
3388 | # gather files to diff | |
3389 | set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir] | |
3390 | set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir] | |
3391 | ||
3392 | if {$difffromfile ne {} && $difftofile ne {}} { | |
b575b2f1 PT |
3393 | set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile] |
3394 | if {[catch {set fl [open |$cmd r]} err]} { | |
314f5de1 | 3395 | file delete -force $diffdir |
3945d2c0 | 3396 | error_popup "$extdifftool: [mc "command failed:"] $err" |
314f5de1 TA |
3397 | } else { |
3398 | fconfigure $fl -blocking 0 | |
3399 | filerun $fl [list delete_at_eof $fl $diffdir] | |
3400 | } | |
3401 | } | |
3402 | } | |
3403 | ||
7cdc3556 AG |
3404 | proc find_hunk_blamespec {base line} { |
3405 | global ctext | |
3406 | ||
3407 | # Find and parse the hunk header | |
3408 | set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0] | |
3409 | if {$s_lix eq {}} return | |
3410 | ||
3411 | set s_line [$ctext get $s_lix "$s_lix + 1 lines"] | |
3412 | if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \ | |
3413 | s_line old_specs osz osz1 new_line nsz]} { | |
3414 | return | |
3415 | } | |
3416 | ||
3417 | # base lines for the parents | |
3418 | set base_lines [list $new_line] | |
3419 | foreach old_spec [lrange [split $old_specs " "] 1 end] { | |
3420 | if {![regexp -- {-(\d+)(,\d+)?} $old_spec \ | |
3421 | old_spec old_line osz]} { | |
3422 | return | |
3423 | } | |
3424 | lappend base_lines $old_line | |
3425 | } | |
3426 | ||
3427 | # Now scan the lines to determine offset within the hunk | |
7cdc3556 AG |
3428 | set max_parent [expr {[llength $base_lines]-2}] |
3429 | set dline 0 | |
3430 | set s_lno [lindex [split $s_lix "."] 0] | |
3431 | ||
190ec52c PM |
3432 | # Determine if the line is removed |
3433 | set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"] | |
3434 | if {[string match {[-+ ]*} $chunk]} { | |
7cdc3556 AG |
3435 | set removed_idx [string first "-" $chunk] |
3436 | # Choose a parent index | |
190ec52c PM |
3437 | if {$removed_idx >= 0} { |
3438 | set parent $removed_idx | |
3439 | } else { | |
3440 | set unchanged_idx [string first " " $chunk] | |
3441 | if {$unchanged_idx >= 0} { | |
3442 | set parent $unchanged_idx | |
7cdc3556 | 3443 | } else { |
190ec52c PM |
3444 | # blame the current commit |
3445 | set parent -1 | |
7cdc3556 AG |
3446 | } |
3447 | } | |
3448 | # then count other lines that belong to it | |
190ec52c PM |
3449 | for {set i $line} {[incr i -1] > $s_lno} {} { |
3450 | set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"] | |
3451 | # Determine if the line is removed | |
3452 | set removed_idx [string first "-" $chunk] | |
3453 | if {$parent >= 0} { | |
3454 | set code [string index $chunk $parent] | |
3455 | if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} { | |
3456 | incr dline | |
3457 | } | |
3458 | } else { | |
3459 | if {$removed_idx < 0} { | |
3460 | incr dline | |
3461 | } | |
7cdc3556 AG |
3462 | } |
3463 | } | |
190ec52c PM |
3464 | incr parent |
3465 | } else { | |
3466 | set parent 0 | |
7cdc3556 AG |
3467 | } |
3468 | ||
7cdc3556 AG |
3469 | incr dline [lindex $base_lines $parent] |
3470 | return [list $parent $dline] | |
3471 | } | |
3472 | ||
3473 | proc external_blame_diff {} { | |
8b07dca1 | 3474 | global currentid cmitmode |
7cdc3556 AG |
3475 | global diff_menu_txtpos diff_menu_line |
3476 | global diff_menu_filebase flist_menu_file | |
3477 | ||
3478 | if {$cmitmode eq "tree"} { | |
3479 | set parent_idx 0 | |
190ec52c | 3480 | set line [expr {$diff_menu_line - $diff_menu_filebase}] |
7cdc3556 AG |
3481 | } else { |
3482 | set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] | |
3483 | if {$hinfo ne {}} { | |
3484 | set parent_idx [lindex $hinfo 0] | |
3485 | set line [lindex $hinfo 1] | |
3486 | } else { | |
3487 | set parent_idx 0 | |
3488 | set line 0 | |
3489 | } | |
3490 | } | |
3491 | ||
3492 | external_blame $parent_idx $line | |
3493 | } | |
3494 | ||
fc4977e1 PM |
3495 | # Find the SHA1 ID of the blob for file $fname in the index |
3496 | # at stage 0 or 2 | |
3497 | proc index_sha1 {fname} { | |
3498 | set f [open [list | git ls-files -s $fname] r] | |
3499 | while {[gets $f line] >= 0} { | |
3500 | set info [lindex [split $line "\t"] 0] | |
3501 | set stage [lindex $info 2] | |
3502 | if {$stage eq "0" || $stage eq "2"} { | |
3503 | close $f | |
3504 | return [lindex $info 1] | |
3505 | } | |
3506 | } | |
3507 | close $f | |
3508 | return {} | |
3509 | } | |
3510 | ||
9712b81a PM |
3511 | # Turn an absolute path into one relative to the current directory |
3512 | proc make_relative {f} { | |
a4390ace MH |
3513 | if {[file pathtype $f] eq "relative"} { |
3514 | return $f | |
3515 | } | |
9712b81a PM |
3516 | set elts [file split $f] |
3517 | set here [file split [pwd]] | |
3518 | set ei 0 | |
3519 | set hi 0 | |
3520 | set res {} | |
3521 | foreach d $here { | |
3522 | if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} { | |
3523 | lappend res ".." | |
3524 | } else { | |
3525 | incr ei | |
3526 | } | |
3527 | incr hi | |
3528 | } | |
3529 | set elts [concat $res [lrange $elts $ei end]] | |
3530 | return [eval file join $elts] | |
3531 | } | |
3532 | ||
7cdc3556 | 3533 | proc external_blame {parent_idx {line {}}} { |
9712b81a | 3534 | global flist_menu_file gitdir |
77aa0ae8 AG |
3535 | global nullid nullid2 |
3536 | global parentlist selectedline currentid | |
3537 | ||
3538 | if {$parent_idx > 0} { | |
3539 | set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]] | |
3540 | } else { | |
3541 | set base_commit $currentid | |
3542 | } | |
3543 | ||
3544 | if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} { | |
3545 | error_popup [mc "No such commit"] | |
3546 | return | |
3547 | } | |
3548 | ||
7cdc3556 AG |
3549 | set cmdline [list git gui blame] |
3550 | if {$line ne {} && $line > 1} { | |
3551 | lappend cmdline "--line=$line" | |
3552 | } | |
9712b81a PM |
3553 | set f [file join [file dirname $gitdir] $flist_menu_file] |
3554 | # Unfortunately it seems git gui blame doesn't like | |
3555 | # being given an absolute path... | |
3556 | set f [make_relative $f] | |
3557 | lappend cmdline $base_commit $f | |
7cdc3556 | 3558 | if {[catch {eval exec $cmdline &} err]} { |
3945d2c0 | 3559 | error_popup "[mc "git gui blame: command failed:"] $err" |
77aa0ae8 AG |
3560 | } |
3561 | } | |
3562 | ||
8a897742 PM |
3563 | proc show_line_source {} { |
3564 | global cmitmode currentid parents curview blamestuff blameinst | |
3565 | global diff_menu_line diff_menu_filebase flist_menu_file | |
fc4977e1 | 3566 | global nullid nullid2 gitdir |
8a897742 | 3567 | |
fc4977e1 | 3568 | set from_index {} |
8a897742 PM |
3569 | if {$cmitmode eq "tree"} { |
3570 | set id $currentid | |
3571 | set line [expr {$diff_menu_line - $diff_menu_filebase}] | |
3572 | } else { | |
3573 | set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] | |
3574 | if {$h eq {}} return | |
3575 | set pi [lindex $h 0] | |
3576 | if {$pi == 0} { | |
3577 | mark_ctext_line $diff_menu_line | |
3578 | return | |
3579 | } | |
fc4977e1 PM |
3580 | incr pi -1 |
3581 | if {$currentid eq $nullid} { | |
3582 | if {$pi > 0} { | |
3583 | # must be a merge in progress... | |
3584 | if {[catch { | |
3585 | # get the last line from .git/MERGE_HEAD | |
3586 | set f [open [file join $gitdir MERGE_HEAD] r] | |
3587 | set id [lindex [split [read $f] "\n"] end-1] | |
3588 | close $f | |
3589 | } err]} { | |
3590 | error_popup [mc "Couldn't read merge head: %s" $err] | |
3591 | return | |
3592 | } | |
3593 | } elseif {$parents($curview,$currentid) eq $nullid2} { | |
3594 | # need to do the blame from the index | |
3595 | if {[catch { | |
3596 | set from_index [index_sha1 $flist_menu_file] | |
3597 | } err]} { | |
3598 | error_popup [mc "Error reading index: %s" $err] | |
3599 | return | |
3600 | } | |
9712b81a PM |
3601 | } else { |
3602 | set id $parents($curview,$currentid) | |
fc4977e1 PM |
3603 | } |
3604 | } else { | |
3605 | set id [lindex $parents($curview,$currentid) $pi] | |
3606 | } | |
8a897742 PM |
3607 | set line [lindex $h 1] |
3608 | } | |
fc4977e1 PM |
3609 | set blameargs {} |
3610 | if {$from_index ne {}} { | |
3611 | lappend blameargs | git cat-file blob $from_index | |
3612 | } | |
3613 | lappend blameargs | git blame -p -L$line,+1 | |
3614 | if {$from_index ne {}} { | |
3615 | lappend blameargs --contents - | |
3616 | } else { | |
3617 | lappend blameargs $id | |
3618 | } | |
9712b81a | 3619 | lappend blameargs -- [file join [file dirname $gitdir] $flist_menu_file] |
8a897742 | 3620 | if {[catch { |
fc4977e1 | 3621 | set f [open $blameargs r] |
8a897742 PM |
3622 | } err]} { |
3623 | error_popup [mc "Couldn't start git blame: %s" $err] | |
3624 | return | |
3625 | } | |
f3413079 | 3626 | nowbusy blaming [mc "Searching"] |
8a897742 PM |
3627 | fconfigure $f -blocking 0 |
3628 | set i [reg_instance $f] | |
3629 | set blamestuff($i) {} | |
3630 | set blameinst $i | |
3631 | filerun $f [list read_line_source $f $i] | |
3632 | } | |
3633 | ||
3634 | proc stopblaming {} { | |
3635 | global blameinst | |
3636 | ||
3637 | if {[info exists blameinst]} { | |
3638 | stop_instance $blameinst | |
3639 | unset blameinst | |
f3413079 | 3640 | notbusy blaming |
8a897742 PM |
3641 | } |
3642 | } | |
3643 | ||
3644 | proc read_line_source {fd inst} { | |
fc4977e1 | 3645 | global blamestuff curview commfd blameinst nullid nullid2 |
8a897742 PM |
3646 | |
3647 | while {[gets $fd line] >= 0} { | |
3648 | lappend blamestuff($inst) $line | |
3649 | } | |
3650 | if {![eof $fd]} { | |
3651 | return 1 | |
3652 | } | |
3653 | unset commfd($inst) | |
3654 | unset blameinst | |
f3413079 | 3655 | notbusy blaming |
8a897742 PM |
3656 | fconfigure $fd -blocking 1 |
3657 | if {[catch {close $fd} err]} { | |
3658 | error_popup [mc "Error running git blame: %s" $err] | |
3659 | return 0 | |
3660 | } | |
3661 | ||
3662 | set fname {} | |
3663 | set line [split [lindex $blamestuff($inst) 0] " "] | |
3664 | set id [lindex $line 0] | |
3665 | set lnum [lindex $line 1] | |
3666 | if {[string length $id] == 40 && [string is xdigit $id] && | |
3667 | [string is digit -strict $lnum]} { | |
3668 | # look for "filename" line | |
3669 | foreach l $blamestuff($inst) { | |
3670 | if {[string match "filename *" $l]} { | |
3671 | set fname [string range $l 9 end] | |
3672 | break | |
3673 | } | |
3674 | } | |
3675 | } | |
3676 | if {$fname ne {}} { | |
3677 | # all looks good, select it | |
fc4977e1 PM |
3678 | if {$id eq $nullid} { |
3679 | # blame uses all-zeroes to mean not committed, | |
3680 | # which would mean a change in the index | |
3681 | set id $nullid2 | |
3682 | } | |
8a897742 PM |
3683 | if {[commitinview $id $curview]} { |
3684 | selectline [rowofcommit $id] 1 [list $fname $lnum] | |
3685 | } else { | |
3686 | error_popup [mc "That line comes from commit %s, \ | |
3687 | which is not in this view" [shortids $id]] | |
3688 | } | |
3689 | } else { | |
3690 | puts "oops couldn't parse git blame output" | |
3691 | } | |
3692 | return 0 | |
3693 | } | |
3694 | ||
314f5de1 TA |
3695 | # delete $dir when we see eof on $f (presumably because the child has exited) |
3696 | proc delete_at_eof {f dir} { | |
3697 | while {[gets $f line] >= 0} {} | |
3698 | if {[eof $f]} { | |
3699 | if {[catch {close $f} err]} { | |
3945d2c0 | 3700 | error_popup "[mc "External diff viewer failed:"] $err" |
314f5de1 TA |
3701 | } |
3702 | file delete -force $dir | |
3703 | return 0 | |
3704 | } | |
3705 | return 1 | |
3706 | } | |
3707 | ||
098dd8a3 PM |
3708 | # Functions for adding and removing shell-type quoting |
3709 | ||
3710 | proc shellquote {str} { | |
3711 | if {![string match "*\['\"\\ \t]*" $str]} { | |
3712 | return $str | |
3713 | } | |
3714 | if {![string match "*\['\"\\]*" $str]} { | |
3715 | return "\"$str\"" | |
3716 | } | |
3717 | if {![string match "*'*" $str]} { | |
3718 | return "'$str'" | |
3719 | } | |
3720 | return "\"[string map {\" \\\" \\ \\\\} $str]\"" | |
3721 | } | |
3722 | ||
3723 | proc shellarglist {l} { | |
3724 | set str {} | |
3725 | foreach a $l { | |
3726 | if {$str ne {}} { | |
3727 | append str " " | |
3728 | } | |
3729 | append str [shellquote $a] | |
3730 | } | |
3731 | return $str | |
3732 | } | |
3733 | ||
3734 | proc shelldequote {str} { | |
3735 | set ret {} | |
3736 | set used -1 | |
3737 | while {1} { | |
3738 | incr used | |
3739 | if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} { | |
3740 | append ret [string range $str $used end] | |
3741 | set used [string length $str] | |
3742 | break | |
3743 | } | |
3744 | set first [lindex $first 0] | |
3745 | set ch [string index $str $first] | |
3746 | if {$first > $used} { | |
3747 | append ret [string range $str $used [expr {$first - 1}]] | |
3748 | set used $first | |
3749 | } | |
3750 | if {$ch eq " " || $ch eq "\t"} break | |
3751 | incr used | |
3752 | if {$ch eq "'"} { | |
3753 | set first [string first "'" $str $used] | |
3754 | if {$first < 0} { | |
3755 | error "unmatched single-quote" | |
3756 | } | |
3757 | append ret [string range $str $used [expr {$first - 1}]] | |
3758 | set used $first | |
3759 | continue | |
3760 | } | |
3761 | if {$ch eq "\\"} { | |
3762 | if {$used >= [string length $str]} { | |
3763 | error "trailing backslash" | |
3764 | } | |
3765 | append ret [string index $str $used] | |
3766 | continue | |
3767 | } | |
3768 | # here ch == "\"" | |
3769 | while {1} { | |
3770 | if {![regexp -start $used -indices "\[\"\\\\]" $str first]} { | |
3771 | error "unmatched double-quote" | |
3772 | } | |
3773 | set first [lindex $first 0] | |
3774 | set ch [string index $str $first] | |
3775 | if {$first > $used} { | |
3776 | append ret [string range $str $used [expr {$first - 1}]] | |
3777 | set used $first | |
3778 | } | |
3779 | if {$ch eq "\""} break | |
3780 | incr used | |
3781 | append ret [string index $str $used] | |
3782 | incr used | |
3783 | } | |
3784 | } | |
3785 | return [list $used $ret] | |
3786 | } | |
3787 | ||
3788 | proc shellsplit {str} { | |
3789 | set l {} | |
3790 | while {1} { | |
3791 | set str [string trimleft $str] | |
3792 | if {$str eq {}} break | |
3793 | set dq [shelldequote $str] | |
3794 | set n [lindex $dq 0] | |
3795 | set word [lindex $dq 1] | |
3796 | set str [string range $str $n end] | |
3797 | lappend l $word | |
3798 | } | |
3799 | return $l | |
3800 | } | |
3801 | ||
7fcceed7 PM |
3802 | # Code to implement multiple views |
3803 | ||
da7c24dd | 3804 | proc newview {ishighlight} { |
218a900b AG |
3805 | global nextviewnum newviewname newishighlight |
3806 | global revtreeargs viewargscmd newviewopts curview | |
50b44ece | 3807 | |
da7c24dd | 3808 | set newishighlight $ishighlight |
50b44ece PM |
3809 | set top .gitkview |
3810 | if {[winfo exists $top]} { | |
3811 | raise $top | |
3812 | return | |
3813 | } | |
5d11f794 | 3814 | decode_view_opts $nextviewnum $revtreeargs |
a3a1f579 | 3815 | set newviewname($nextviewnum) "[mc "View"] $nextviewnum" |
218a900b AG |
3816 | set newviewopts($nextviewnum,perm) 0 |
3817 | set newviewopts($nextviewnum,cmd) $viewargscmd($curview) | |
d990cedf | 3818 | vieweditor $top $nextviewnum [mc "Gitk view definition"] |
d16c0812 PM |
3819 | } |
3820 | ||
218a900b | 3821 | set known_view_options { |
13d40b61 EN |
3822 | {perm b . {} {mc "Remember this view"}} |
3823 | {reflabel l + {} {mc "References (space separated list):"}} | |
3824 | {refs t15 .. {} {mc "Branches & tags:"}} | |
3825 | {allrefs b *. "--all" {mc "All refs"}} | |
3826 | {branches b . "--branches" {mc "All (local) branches"}} | |
3827 | {tags b . "--tags" {mc "All tags"}} | |
3828 | {remotes b . "--remotes" {mc "All remote-tracking branches"}} | |
3829 | {commitlbl l + {} {mc "Commit Info (regular expressions):"}} | |
3830 | {author t15 .. "--author=*" {mc "Author:"}} | |
3831 | {committer t15 . "--committer=*" {mc "Committer:"}} | |
3832 | {loginfo t15 .. "--grep=*" {mc "Commit Message:"}} | |
3833 | {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}} | |
3834 | {changes_l l + {} {mc "Changes to Files:"}} | |
3835 | {pickaxe_s r0 . {} {mc "Fixed String"}} | |
3836 | {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}} | |
3837 | {pickaxe t15 .. "-S*" {mc "Search string:"}} | |
3838 | {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}} | |
3839 | {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}} | |
3840 | {until t15 . {"--until=*" "--before=*"} {mc "Until:"}} | |
3841 | {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}} | |
3842 | {limit t10 *. "--max-count=*" {mc "Number to show:"}} | |
3843 | {skip t10 . "--skip=*" {mc "Number to skip:"}} | |
3844 | {misc_lbl l + {} {mc "Miscellaneous options:"}} | |
3845 | {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}} | |
3846 | {lright b . "--left-right" {mc "Mark branch sides"}} | |
3847 | {first b . "--first-parent" {mc "Limit to first parent"}} | |
f687aaa8 | 3848 | {smplhst b . "--simplify-by-decoration" {mc "Simple history"}} |
13d40b61 EN |
3849 | {args t50 *. {} {mc "Additional arguments to git log:"}} |
3850 | {allpaths path + {} {mc "Enter files and directories to include, one per line:"}} | |
3851 | {cmd t50= + {} {mc "Command to generate more commits to include:"}} | |
218a900b AG |
3852 | } |
3853 | ||
e7feb695 | 3854 | # Convert $newviewopts($n, ...) into args for git log. |
218a900b AG |
3855 | proc encode_view_opts {n} { |
3856 | global known_view_options newviewopts | |
3857 | ||
3858 | set rargs [list] | |
3859 | foreach opt $known_view_options { | |
3860 | set patterns [lindex $opt 3] | |
3861 | if {$patterns eq {}} continue | |
3862 | set pattern [lindex $patterns 0] | |
3863 | ||
218a900b | 3864 | if {[lindex $opt 1] eq "b"} { |
13d40b61 | 3865 | set val $newviewopts($n,[lindex $opt 0]) |
218a900b AG |
3866 | if {$val} { |
3867 | lappend rargs $pattern | |
3868 | } | |
13d40b61 EN |
3869 | } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} { |
3870 | regexp {^(.*_)} [lindex $opt 0] uselessvar button_id | |
3871 | set val $newviewopts($n,$button_id) | |
3872 | if {$val eq $value} { | |
3873 | lappend rargs $pattern | |
3874 | } | |
218a900b | 3875 | } else { |
13d40b61 | 3876 | set val $newviewopts($n,[lindex $opt 0]) |
218a900b AG |
3877 | set val [string trim $val] |
3878 | if {$val ne {}} { | |
3879 | set pfix [string range $pattern 0 end-1] | |
3880 | lappend rargs $pfix$val | |
3881 | } | |
3882 | } | |
3883 | } | |
13d40b61 | 3884 | set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]] |
218a900b AG |
3885 | return [concat $rargs [shellsplit $newviewopts($n,args)]] |
3886 | } | |
3887 | ||
e7feb695 | 3888 | # Fill $newviewopts($n, ...) based on args for git log. |
218a900b AG |
3889 | proc decode_view_opts {n view_args} { |
3890 | global known_view_options newviewopts | |
3891 | ||
3892 | foreach opt $known_view_options { | |
13d40b61 | 3893 | set id [lindex $opt 0] |
218a900b | 3894 | if {[lindex $opt 1] eq "b"} { |
13d40b61 EN |
3895 | # Checkboxes |
3896 | set val 0 | |
3897 | } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} { | |
3898 | # Radiobuttons | |
3899 | regexp {^(.*_)} $id uselessvar id | |
218a900b AG |
3900 | set val 0 |
3901 | } else { | |
13d40b61 | 3902 | # Text fields |
218a900b AG |
3903 | set val {} |
3904 | } | |
13d40b61 | 3905 | set newviewopts($n,$id) $val |
218a900b AG |
3906 | } |
3907 | set oargs [list] | |
13d40b61 | 3908 | set refargs [list] |
218a900b AG |
3909 | foreach arg $view_args { |
3910 | if {[regexp -- {^-([0-9]+)$} $arg arg cnt] | |
3911 | && ![info exists found(limit)]} { | |
3912 | set newviewopts($n,limit) $cnt | |
3913 | set found(limit) 1 | |
3914 | continue | |
3915 | } | |
3916 | catch { unset val } | |
3917 | foreach opt $known_view_options { | |
3918 | set id [lindex $opt 0] | |
3919 | if {[info exists found($id)]} continue | |
3920 | foreach pattern [lindex $opt 3] { | |
3921 | if {![string match $pattern $arg]} continue | |
13d40b61 EN |
3922 | if {[lindex $opt 1] eq "b"} { |
3923 | # Check buttons | |
3924 | set val 1 | |
3925 | } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} { | |
3926 | # Radio buttons | |
3927 | regexp {^(.*_)} $id uselessvar id | |
3928 | set val $num | |
3929 | } else { | |
3930 | # Text input fields | |
218a900b AG |
3931 | set size [string length $pattern] |
3932 | set val [string range $arg [expr {$size-1}] end] | |
218a900b AG |
3933 | } |
3934 | set newviewopts($n,$id) $val | |
3935 | set found($id) 1 | |
3936 | break | |
3937 | } | |
3938 | if {[info exists val]} break | |
3939 | } | |
3940 | if {[info exists val]} continue | |
13d40b61 EN |
3941 | if {[regexp {^-} $arg]} { |
3942 | lappend oargs $arg | |
3943 | } else { | |
3944 | lappend refargs $arg | |
3945 | } | |
218a900b | 3946 | } |
13d40b61 | 3947 | set newviewopts($n,refs) [shellarglist $refargs] |
218a900b AG |
3948 | set newviewopts($n,args) [shellarglist $oargs] |
3949 | } | |
3950 | ||
cea07cf8 AG |
3951 | proc edit_or_newview {} { |
3952 | global curview | |
3953 | ||
3954 | if {$curview > 0} { | |
3955 | editview | |
3956 | } else { | |
3957 | newview 0 | |
3958 | } | |
3959 | } | |
3960 | ||
d16c0812 PM |
3961 | proc editview {} { |
3962 | global curview | |
218a900b AG |
3963 | global viewname viewperm newviewname newviewopts |
3964 | global viewargs viewargscmd | |
d16c0812 PM |
3965 | |
3966 | set top .gitkvedit-$curview | |
3967 | if {[winfo exists $top]} { | |
3968 | raise $top | |
3969 | return | |
3970 | } | |
5d11f794 | 3971 | decode_view_opts $curview $viewargs($curview) |
218a900b AG |
3972 | set newviewname($curview) $viewname($curview) |
3973 | set newviewopts($curview,perm) $viewperm($curview) | |
3974 | set newviewopts($curview,cmd) $viewargscmd($curview) | |
b56e0a9a | 3975 | vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)" |
d16c0812 PM |
3976 | } |
3977 | ||
3978 | proc vieweditor {top n title} { | |
218a900b | 3979 | global newviewname newviewopts viewfiles bgcolor |
d93f1713 | 3980 | global known_view_options NS |
d16c0812 | 3981 | |
d93f1713 | 3982 | ttk_toplevel $top |
e0a01995 | 3983 | wm title $top [concat $title [mc "-- criteria for selecting revisions"]] |
e7d64008 | 3984 | make_transient $top . |
218a900b AG |
3985 | |
3986 | # View name | |
d93f1713 | 3987 | ${NS}::frame $top.nfr |
eae7d64a | 3988 | ${NS}::label $top.nl -text [mc "View Name"] |
d93f1713 | 3989 | ${NS}::entry $top.name -width 20 -textvariable newviewname($n) |
218a900b | 3990 | pack $top.nfr -in $top -fill x -pady 5 -padx 3 |
13d40b61 EN |
3991 | pack $top.nl -in $top.nfr -side left -padx {0 5} |
3992 | pack $top.name -in $top.nfr -side left -padx {0 25} | |
218a900b AG |
3993 | |
3994 | # View options | |
3995 | set cframe $top.nfr | |
3996 | set cexpand 0 | |
3997 | set cnt 0 | |
3998 | foreach opt $known_view_options { | |
3999 | set id [lindex $opt 0] | |
4000 | set type [lindex $opt 1] | |
4001 | set flags [lindex $opt 2] | |
4002 | set title [eval [lindex $opt 4]] | |
4003 | set lxpad 0 | |
4004 | ||
4005 | if {$flags eq "+" || $flags eq "*"} { | |
4006 | set cframe $top.fr$cnt | |
4007 | incr cnt | |
d93f1713 | 4008 | ${NS}::frame $cframe |
218a900b AG |
4009 | pack $cframe -in $top -fill x -pady 3 -padx 3 |
4010 | set cexpand [expr {$flags eq "*"}] | |
13d40b61 EN |
4011 | } elseif {$flags eq ".." || $flags eq "*."} { |
4012 | set cframe $top.fr$cnt | |
4013 | incr cnt | |
eae7d64a | 4014 | ${NS}::frame $cframe |
13d40b61 EN |
4015 | pack $cframe -in $top -fill x -pady 3 -padx [list 15 3] |
4016 | set cexpand [expr {$flags eq "*."}] | |
218a900b AG |
4017 | } else { |
4018 | set lxpad 5 | |
4019 | } | |
4020 | ||
13d40b61 | 4021 | if {$type eq "l"} { |
eae7d64a | 4022 | ${NS}::label $cframe.l_$id -text $title |
13d40b61 EN |
4023 | pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w |
4024 | } elseif {$type eq "b"} { | |
d93f1713 | 4025 | ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id) |
218a900b AG |
4026 | pack $cframe.c_$id -in $cframe -side left \ |
4027 | -padx [list $lxpad 0] -expand $cexpand -anchor w | |
13d40b61 EN |
4028 | } elseif {[regexp {^r(\d+)$} $type type sz]} { |
4029 | regexp {^(.*_)} $id uselessvar button_id | |
eae7d64a | 4030 | ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz |
13d40b61 EN |
4031 | pack $cframe.c_$id -in $cframe -side left \ |
4032 | -padx [list $lxpad 0] -expand $cexpand -anchor w | |
218a900b | 4033 | } elseif {[regexp {^t(\d+)$} $type type sz]} { |
d93f1713 PT |
4034 | ${NS}::label $cframe.l_$id -text $title |
4035 | ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \ | |
218a900b AG |
4036 | -textvariable newviewopts($n,$id) |
4037 | pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0] | |
4038 | pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x | |
4039 | } elseif {[regexp {^t(\d+)=$} $type type sz]} { | |
d93f1713 PT |
4040 | ${NS}::label $cframe.l_$id -text $title |
4041 | ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \ | |
218a900b AG |
4042 | -textvariable newviewopts($n,$id) |
4043 | pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w | |
4044 | pack $cframe.e_$id -in $cframe -side top -fill x | |
13d40b61 | 4045 | } elseif {$type eq "path"} { |
eae7d64a | 4046 | ${NS}::label $top.l -text $title |
13d40b61 | 4047 | pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3 |
b9b142ff | 4048 | text $top.t -width 40 -height 5 -background $bgcolor |
13d40b61 EN |
4049 | if {[info exists viewfiles($n)]} { |
4050 | foreach f $viewfiles($n) { | |
4051 | $top.t insert end $f | |
4052 | $top.t insert end "\n" | |
4053 | } | |
4054 | $top.t delete {end - 1c} end | |
4055 | $top.t mark set insert 0.0 | |
4056 | } | |
4057 | pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3 | |
218a900b AG |
4058 | } |
4059 | } | |
4060 | ||
d93f1713 PT |
4061 | ${NS}::frame $top.buts |
4062 | ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] | |
4063 | ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1] | |
4064 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top] | |
218a900b AG |
4065 | bind $top <Control-Return> [list newviewok $top $n] |
4066 | bind $top <F5> [list newviewok $top $n 1] | |
76f15947 | 4067 | bind $top <Escape> [list destroy $top] |
218a900b | 4068 | grid $top.buts.ok $top.buts.apply $top.buts.can |
50b44ece PM |
4069 | grid columnconfigure $top.buts 0 -weight 1 -uniform a |
4070 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
218a900b AG |
4071 | grid columnconfigure $top.buts 2 -weight 1 -uniform a |
4072 | pack $top.buts -in $top -side top -fill x | |
50b44ece PM |
4073 | focus $top.t |
4074 | } | |
4075 | ||
908c3585 | 4076 | proc doviewmenu {m first cmd op argv} { |
da7c24dd PM |
4077 | set nmenu [$m index end] |
4078 | for {set i $first} {$i <= $nmenu} {incr i} { | |
4079 | if {[$m entrycget $i -command] eq $cmd} { | |
908c3585 | 4080 | eval $m $op $i $argv |
da7c24dd | 4081 | break |
d16c0812 PM |
4082 | } |
4083 | } | |
da7c24dd PM |
4084 | } |
4085 | ||
4086 | proc allviewmenus {n op args} { | |
687c8765 | 4087 | # global viewhlmenu |
908c3585 | 4088 | |
3cd204e5 | 4089 | doviewmenu .bar.view 5 [list showview $n] $op $args |
687c8765 | 4090 | # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args |
d16c0812 PM |
4091 | } |
4092 | ||
218a900b | 4093 | proc newviewok {top n {apply 0}} { |
da7c24dd | 4094 | global nextviewnum newviewperm newviewname newishighlight |
d16c0812 | 4095 | global viewname viewfiles viewperm selectedview curview |
218a900b | 4096 | global viewargs viewargscmd newviewopts viewhlmenu |
50b44ece | 4097 | |
098dd8a3 | 4098 | if {[catch { |
218a900b | 4099 | set newargs [encode_view_opts $n] |
098dd8a3 | 4100 | } err]} { |
84a76f18 | 4101 | error_popup "[mc "Error in commit selection arguments:"] $err" $top |
098dd8a3 PM |
4102 | return |
4103 | } | |
50b44ece | 4104 | set files {} |
d16c0812 | 4105 | foreach f [split [$top.t get 0.0 end] "\n"] { |
50b44ece PM |
4106 | set ft [string trim $f] |
4107 | if {$ft ne {}} { | |
4108 | lappend files $ft | |
4109 | } | |
4110 | } | |
d16c0812 PM |
4111 | if {![info exists viewfiles($n)]} { |
4112 | # creating a new view | |
4113 | incr nextviewnum | |
4114 | set viewname($n) $newviewname($n) | |
218a900b | 4115 | set viewperm($n) $newviewopts($n,perm) |
d16c0812 | 4116 | set viewfiles($n) $files |
098dd8a3 | 4117 | set viewargs($n) $newargs |
218a900b | 4118 | set viewargscmd($n) $newviewopts($n,cmd) |
da7c24dd PM |
4119 | addviewmenu $n |
4120 | if {!$newishighlight} { | |
7eb3cb9c | 4121 | run showview $n |
da7c24dd | 4122 | } else { |
7eb3cb9c | 4123 | run addvhighlight $n |
da7c24dd | 4124 | } |
d16c0812 PM |
4125 | } else { |
4126 | # editing an existing view | |
218a900b | 4127 | set viewperm($n) $newviewopts($n,perm) |
d16c0812 PM |
4128 | if {$newviewname($n) ne $viewname($n)} { |
4129 | set viewname($n) $newviewname($n) | |
3cd204e5 | 4130 | doviewmenu .bar.view 5 [list showview $n] \ |
908c3585 | 4131 | entryconf [list -label $viewname($n)] |
687c8765 PM |
4132 | # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \ |
4133 | # entryconf [list -label $viewname($n) -value $viewname($n)] | |
d16c0812 | 4134 | } |
2d480856 | 4135 | if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \ |
218a900b | 4136 | $newviewopts($n,cmd) ne $viewargscmd($n)} { |
d16c0812 | 4137 | set viewfiles($n) $files |
098dd8a3 | 4138 | set viewargs($n) $newargs |
218a900b | 4139 | set viewargscmd($n) $newviewopts($n,cmd) |
d16c0812 | 4140 | if {$curview == $n} { |
7fcc92bf | 4141 | run reloadcommits |
d16c0812 PM |
4142 | } |
4143 | } | |
4144 | } | |
218a900b | 4145 | if {$apply} return |
d16c0812 | 4146 | catch {destroy $top} |
50b44ece PM |
4147 | } |
4148 | ||
4149 | proc delview {} { | |
7fcc92bf | 4150 | global curview viewperm hlview selectedhlview |
50b44ece PM |
4151 | |
4152 | if {$curview == 0} return | |
908c3585 | 4153 | if {[info exists hlview] && $hlview == $curview} { |
b007ee20 | 4154 | set selectedhlview [mc "None"] |
908c3585 PM |
4155 | unset hlview |
4156 | } | |
da7c24dd | 4157 | allviewmenus $curview delete |
a90a6d24 | 4158 | set viewperm($curview) 0 |
50b44ece PM |
4159 | showview 0 |
4160 | } | |
4161 | ||
da7c24dd | 4162 | proc addviewmenu {n} { |
908c3585 | 4163 | global viewname viewhlmenu |
da7c24dd PM |
4164 | |
4165 | .bar.view add radiobutton -label $viewname($n) \ | |
4166 | -command [list showview $n] -variable selectedview -value $n | |
687c8765 PM |
4167 | #$viewhlmenu add radiobutton -label $viewname($n) \ |
4168 | # -command [list addvhighlight $n] -variable selectedhlview | |
da7c24dd PM |
4169 | } |
4170 | ||
50b44ece | 4171 | proc showview {n} { |
3ed31a81 | 4172 | global curview cached_commitrow ordertok |
f5f3c2e2 | 4173 | global displayorder parentlist rowidlist rowisopt rowfinal |
7fcc92bf PM |
4174 | global colormap rowtextx nextcolor canvxmax |
4175 | global numcommits viewcomplete | |
50b44ece | 4176 | global selectedline currentid canv canvy0 |
4fb0fa19 | 4177 | global treediffs |
3e76608d | 4178 | global pending_select mainheadid |
0380081c | 4179 | global commitidx |
3e76608d | 4180 | global selectedview |
97645683 | 4181 | global hlview selectedhlview commitinterest |
50b44ece PM |
4182 | |
4183 | if {$n == $curview} return | |
4184 | set selid {} | |
7fcc92bf PM |
4185 | set ymax [lindex [$canv cget -scrollregion] 3] |
4186 | set span [$canv yview] | |
4187 | set ytop [expr {[lindex $span 0] * $ymax}] | |
4188 | set ybot [expr {[lindex $span 1] * $ymax}] | |
4189 | set yscreen [expr {($ybot - $ytop) / 2}] | |
94b4a69f | 4190 | if {$selectedline ne {}} { |
50b44ece PM |
4191 | set selid $currentid |
4192 | set y [yc $selectedline] | |
50b44ece PM |
4193 | if {$ytop < $y && $y < $ybot} { |
4194 | set yscreen [expr {$y - $ytop}] | |
50b44ece | 4195 | } |
e507fd48 PM |
4196 | } elseif {[info exists pending_select]} { |
4197 | set selid $pending_select | |
4198 | unset pending_select | |
50b44ece PM |
4199 | } |
4200 | unselectline | |
fdedbcfb | 4201 | normalline |
50b44ece PM |
4202 | catch {unset treediffs} |
4203 | clear_display | |
908c3585 PM |
4204 | if {[info exists hlview] && $hlview == $n} { |
4205 | unset hlview | |
b007ee20 | 4206 | set selectedhlview [mc "None"] |
908c3585 | 4207 | } |
97645683 | 4208 | catch {unset commitinterest} |
7fcc92bf | 4209 | catch {unset cached_commitrow} |
9257d8f7 | 4210 | catch {unset ordertok} |
50b44ece PM |
4211 | |
4212 | set curview $n | |
a90a6d24 | 4213 | set selectedview $n |
f2d0bbbd PM |
4214 | .bar.view entryconf [mca "Edit view..."] -state [expr {$n == 0? "disabled": "normal"}] |
4215 | .bar.view entryconf [mca "Delete view"] -state [expr {$n == 0? "disabled": "normal"}] | |
50b44ece | 4216 | |
df904497 | 4217 | run refill_reflist |
7fcc92bf | 4218 | if {![info exists viewcomplete($n)]} { |
567c34e0 | 4219 | getcommits $selid |
50b44ece PM |
4220 | return |
4221 | } | |
4222 | ||
7fcc92bf PM |
4223 | set displayorder {} |
4224 | set parentlist {} | |
4225 | set rowidlist {} | |
4226 | set rowisopt {} | |
4227 | set rowfinal {} | |
f5f3c2e2 | 4228 | set numcommits $commitidx($n) |
22626ef4 | 4229 | |
50b44ece PM |
4230 | catch {unset colormap} |
4231 | catch {unset rowtextx} | |
da7c24dd PM |
4232 | set nextcolor 0 |
4233 | set canvxmax [$canv cget -width] | |
50b44ece PM |
4234 | set curview $n |
4235 | set row 0 | |
50b44ece PM |
4236 | setcanvscroll |
4237 | set yf 0 | |
e507fd48 | 4238 | set row {} |
7fcc92bf PM |
4239 | if {$selid ne {} && [commitinview $selid $n]} { |
4240 | set row [rowofcommit $selid] | |
50b44ece PM |
4241 | # try to get the selected row in the same position on the screen |
4242 | set ymax [lindex [$canv cget -scrollregion] 3] | |
4243 | set ytop [expr {[yc $row] - $yscreen}] | |
4244 | if {$ytop < 0} { | |
4245 | set ytop 0 | |
4246 | } | |
4247 | set yf [expr {$ytop * 1.0 / $ymax}] | |
4248 | } | |
4249 | allcanvs yview moveto $yf | |
4250 | drawvisible | |
e507fd48 PM |
4251 | if {$row ne {}} { |
4252 | selectline $row 0 | |
3e76608d | 4253 | } elseif {!$viewcomplete($n)} { |
567c34e0 | 4254 | reset_pending_select $selid |
e507fd48 | 4255 | } else { |
835e62ae AG |
4256 | reset_pending_select {} |
4257 | ||
4258 | if {[commitinview $pending_select $curview]} { | |
4259 | selectline [rowofcommit $pending_select] 1 | |
4260 | } else { | |
4261 | set row [first_real_row] | |
4262 | if {$row < $numcommits} { | |
4263 | selectline $row 0 | |
4264 | } | |
e507fd48 PM |
4265 | } |
4266 | } | |
7fcc92bf PM |
4267 | if {!$viewcomplete($n)} { |
4268 | if {$numcommits == 0} { | |
d990cedf | 4269 | show_status [mc "Reading commits..."] |
d16c0812 | 4270 | } |
098dd8a3 | 4271 | } elseif {$numcommits == 0} { |
d990cedf | 4272 | show_status [mc "No commits selected"] |
2516dae2 | 4273 | } |
50b44ece PM |
4274 | } |
4275 | ||
908c3585 PM |
4276 | # Stuff relating to the highlighting facility |
4277 | ||
476ca63d | 4278 | proc ishighlighted {id} { |
164ff275 | 4279 | global vhighlights fhighlights nhighlights rhighlights |
908c3585 | 4280 | |
476ca63d PM |
4281 | if {[info exists nhighlights($id)] && $nhighlights($id) > 0} { |
4282 | return $nhighlights($id) | |
908c3585 | 4283 | } |
476ca63d PM |
4284 | if {[info exists vhighlights($id)] && $vhighlights($id) > 0} { |
4285 | return $vhighlights($id) | |
908c3585 | 4286 | } |
476ca63d PM |
4287 | if {[info exists fhighlights($id)] && $fhighlights($id) > 0} { |
4288 | return $fhighlights($id) | |
908c3585 | 4289 | } |
476ca63d PM |
4290 | if {[info exists rhighlights($id)] && $rhighlights($id) > 0} { |
4291 | return $rhighlights($id) | |
164ff275 | 4292 | } |
908c3585 PM |
4293 | return 0 |
4294 | } | |
4295 | ||
28593d3f | 4296 | proc bolden {id font} { |
b9fdba7f | 4297 | global canv linehtag currentid boldids need_redisplay markedid |
908c3585 | 4298 | |
d98d50e2 PM |
4299 | # need_redisplay = 1 means the display is stale and about to be redrawn |
4300 | if {$need_redisplay} return | |
28593d3f PM |
4301 | lappend boldids $id |
4302 | $canv itemconf $linehtag($id) -font $font | |
4303 | if {[info exists currentid] && $id eq $currentid} { | |
908c3585 | 4304 | $canv delete secsel |
28593d3f | 4305 | set t [eval $canv create rect [$canv bbox $linehtag($id)] \ |
908c3585 PM |
4306 | -outline {{}} -tags secsel \ |
4307 | -fill [$canv cget -selectbackground]] | |
4308 | $canv lower $t | |
4309 | } | |
b9fdba7f PM |
4310 | if {[info exists markedid] && $id eq $markedid} { |
4311 | make_idmark $id | |
4312 | } | |
908c3585 PM |
4313 | } |
4314 | ||
28593d3f PM |
4315 | proc bolden_name {id font} { |
4316 | global canv2 linentag currentid boldnameids need_redisplay | |
908c3585 | 4317 | |
d98d50e2 | 4318 | if {$need_redisplay} return |
28593d3f PM |
4319 | lappend boldnameids $id |
4320 | $canv2 itemconf $linentag($id) -font $font | |
4321 | if {[info exists currentid] && $id eq $currentid} { | |
908c3585 | 4322 | $canv2 delete secsel |
28593d3f | 4323 | set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \ |
908c3585 PM |
4324 | -outline {{}} -tags secsel \ |
4325 | -fill [$canv2 cget -selectbackground]] | |
4326 | $canv2 lower $t | |
4327 | } | |
4328 | } | |
4329 | ||
4e7d6779 | 4330 | proc unbolden {} { |
28593d3f | 4331 | global boldids |
908c3585 | 4332 | |
4e7d6779 | 4333 | set stillbold {} |
28593d3f PM |
4334 | foreach id $boldids { |
4335 | if {![ishighlighted $id]} { | |
4336 | bolden $id mainfont | |
4e7d6779 | 4337 | } else { |
28593d3f | 4338 | lappend stillbold $id |
908c3585 PM |
4339 | } |
4340 | } | |
28593d3f | 4341 | set boldids $stillbold |
908c3585 PM |
4342 | } |
4343 | ||
4344 | proc addvhighlight {n} { | |
476ca63d | 4345 | global hlview viewcomplete curview vhl_done commitidx |
da7c24dd PM |
4346 | |
4347 | if {[info exists hlview]} { | |
908c3585 | 4348 | delvhighlight |
da7c24dd PM |
4349 | } |
4350 | set hlview $n | |
7fcc92bf | 4351 | if {$n != $curview && ![info exists viewcomplete($n)]} { |
da7c24dd | 4352 | start_rev_list $n |
908c3585 PM |
4353 | } |
4354 | set vhl_done $commitidx($hlview) | |
4355 | if {$vhl_done > 0} { | |
4356 | drawvisible | |
da7c24dd PM |
4357 | } |
4358 | } | |
4359 | ||
908c3585 PM |
4360 | proc delvhighlight {} { |
4361 | global hlview vhighlights | |
da7c24dd PM |
4362 | |
4363 | if {![info exists hlview]} return | |
4364 | unset hlview | |
4e7d6779 PM |
4365 | catch {unset vhighlights} |
4366 | unbolden | |
da7c24dd PM |
4367 | } |
4368 | ||
908c3585 | 4369 | proc vhighlightmore {} { |
7fcc92bf | 4370 | global hlview vhl_done commitidx vhighlights curview |
da7c24dd | 4371 | |
da7c24dd | 4372 | set max $commitidx($hlview) |
908c3585 PM |
4373 | set vr [visiblerows] |
4374 | set r0 [lindex $vr 0] | |
4375 | set r1 [lindex $vr 1] | |
4376 | for {set i $vhl_done} {$i < $max} {incr i} { | |
7fcc92bf PM |
4377 | set id [commitonrow $i $hlview] |
4378 | if {[commitinview $id $curview]} { | |
4379 | set row [rowofcommit $id] | |
908c3585 PM |
4380 | if {$r0 <= $row && $row <= $r1} { |
4381 | if {![highlighted $row]} { | |
28593d3f | 4382 | bolden $id mainfontbold |
da7c24dd | 4383 | } |
476ca63d | 4384 | set vhighlights($id) 1 |
da7c24dd PM |
4385 | } |
4386 | } | |
4387 | } | |
908c3585 | 4388 | set vhl_done $max |
ac1276ab | 4389 | return 0 |
908c3585 PM |
4390 | } |
4391 | ||
4392 | proc askvhighlight {row id} { | |
7fcc92bf | 4393 | global hlview vhighlights iddrawn |
908c3585 | 4394 | |
7fcc92bf | 4395 | if {[commitinview $id $hlview]} { |
476ca63d | 4396 | if {[info exists iddrawn($id)] && ![ishighlighted $id]} { |
28593d3f | 4397 | bolden $id mainfontbold |
908c3585 | 4398 | } |
476ca63d | 4399 | set vhighlights($id) 1 |
908c3585 | 4400 | } else { |
476ca63d | 4401 | set vhighlights($id) 0 |
908c3585 PM |
4402 | } |
4403 | } | |
4404 | ||
687c8765 | 4405 | proc hfiles_change {} { |
908c3585 | 4406 | global highlight_files filehighlight fhighlights fh_serial |
8b39e04f | 4407 | global highlight_paths |
908c3585 PM |
4408 | |
4409 | if {[info exists filehighlight]} { | |
4410 | # delete previous highlights | |
4411 | catch {close $filehighlight} | |
4412 | unset filehighlight | |
4e7d6779 PM |
4413 | catch {unset fhighlights} |
4414 | unbolden | |
63b79191 | 4415 | unhighlight_filelist |
908c3585 | 4416 | } |
63b79191 | 4417 | set highlight_paths {} |
908c3585 PM |
4418 | after cancel do_file_hl $fh_serial |
4419 | incr fh_serial | |
4420 | if {$highlight_files ne {}} { | |
4421 | after 300 do_file_hl $fh_serial | |
4422 | } | |
4423 | } | |
4424 | ||
687c8765 PM |
4425 | proc gdttype_change {name ix op} { |
4426 | global gdttype highlight_files findstring findpattern | |
4427 | ||
bb3edc8b | 4428 | stopfinding |
687c8765 | 4429 | if {$findstring ne {}} { |
b007ee20 | 4430 | if {$gdttype eq [mc "containing:"]} { |
687c8765 PM |
4431 | if {$highlight_files ne {}} { |
4432 | set highlight_files {} | |
4433 | hfiles_change | |
4434 | } | |
4435 | findcom_change | |
4436 | } else { | |
4437 | if {$findpattern ne {}} { | |
4438 | set findpattern {} | |
4439 | findcom_change | |
4440 | } | |
4441 | set highlight_files $findstring | |
4442 | hfiles_change | |
4443 | } | |
4444 | drawvisible | |
4445 | } | |
4446 | # enable/disable findtype/findloc menus too | |
4447 | } | |
4448 | ||
4449 | proc find_change {name ix op} { | |
4450 | global gdttype findstring highlight_files | |
4451 | ||
bb3edc8b | 4452 | stopfinding |
b007ee20 | 4453 | if {$gdttype eq [mc "containing:"]} { |
687c8765 PM |
4454 | findcom_change |
4455 | } else { | |
4456 | if {$highlight_files ne $findstring} { | |
4457 | set highlight_files $findstring | |
4458 | hfiles_change | |
4459 | } | |
4460 | } | |
4461 | drawvisible | |
4462 | } | |
4463 | ||
64b5f146 | 4464 | proc findcom_change args { |
28593d3f | 4465 | global nhighlights boldnameids |
687c8765 PM |
4466 | global findpattern findtype findstring gdttype |
4467 | ||
bb3edc8b | 4468 | stopfinding |
687c8765 | 4469 | # delete previous highlights, if any |
28593d3f PM |
4470 | foreach id $boldnameids { |
4471 | bolden_name $id mainfont | |
687c8765 | 4472 | } |
28593d3f | 4473 | set boldnameids {} |
687c8765 PM |
4474 | catch {unset nhighlights} |
4475 | unbolden | |
4476 | unmarkmatches | |
b007ee20 | 4477 | if {$gdttype ne [mc "containing:"] || $findstring eq {}} { |
687c8765 | 4478 | set findpattern {} |
b007ee20 | 4479 | } elseif {$findtype eq [mc "Regexp"]} { |
687c8765 PM |
4480 | set findpattern $findstring |
4481 | } else { | |
4482 | set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \ | |
4483 | $findstring] | |
4484 | set findpattern "*$e*" | |
4485 | } | |
4486 | } | |
4487 | ||
63b79191 PM |
4488 | proc makepatterns {l} { |
4489 | set ret {} | |
4490 | foreach e $l { | |
4491 | set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e] | |
4492 | if {[string index $ee end] eq "/"} { | |
4493 | lappend ret "$ee*" | |
4494 | } else { | |
4495 | lappend ret $ee | |
4496 | lappend ret "$ee/*" | |
4497 | } | |
4498 | } | |
4499 | return $ret | |
4500 | } | |
4501 | ||
908c3585 | 4502 | proc do_file_hl {serial} { |
4e7d6779 | 4503 | global highlight_files filehighlight highlight_paths gdttype fhl_list |
908c3585 | 4504 | |
b007ee20 | 4505 | if {$gdttype eq [mc "touching paths:"]} { |
60f7a7dc PM |
4506 | if {[catch {set paths [shellsplit $highlight_files]}]} return |
4507 | set highlight_paths [makepatterns $paths] | |
4508 | highlight_filelist | |
4509 | set gdtargs [concat -- $paths] | |
b007ee20 | 4510 | } elseif {$gdttype eq [mc "adding/removing string:"]} { |
60f7a7dc | 4511 | set gdtargs [list "-S$highlight_files"] |
687c8765 PM |
4512 | } else { |
4513 | # must be "containing:", i.e. we're searching commit info | |
4514 | return | |
60f7a7dc | 4515 | } |
1ce09dd6 | 4516 | set cmd [concat | git diff-tree -r -s --stdin $gdtargs] |
908c3585 PM |
4517 | set filehighlight [open $cmd r+] |
4518 | fconfigure $filehighlight -blocking 0 | |
7eb3cb9c | 4519 | filerun $filehighlight readfhighlight |
4e7d6779 | 4520 | set fhl_list {} |
908c3585 PM |
4521 | drawvisible |
4522 | flushhighlights | |
4523 | } | |
4524 | ||
4525 | proc flushhighlights {} { | |
4e7d6779 | 4526 | global filehighlight fhl_list |
908c3585 PM |
4527 | |
4528 | if {[info exists filehighlight]} { | |
4e7d6779 | 4529 | lappend fhl_list {} |
908c3585 PM |
4530 | puts $filehighlight "" |
4531 | flush $filehighlight | |
4532 | } | |
4533 | } | |
4534 | ||
4535 | proc askfilehighlight {row id} { | |
4e7d6779 | 4536 | global filehighlight fhighlights fhl_list |
908c3585 | 4537 | |
4e7d6779 | 4538 | lappend fhl_list $id |
476ca63d | 4539 | set fhighlights($id) -1 |
908c3585 PM |
4540 | puts $filehighlight $id |
4541 | } | |
4542 | ||
4543 | proc readfhighlight {} { | |
7fcc92bf | 4544 | global filehighlight fhighlights curview iddrawn |
687c8765 | 4545 | global fhl_list find_dirn |
4e7d6779 | 4546 | |
7eb3cb9c PM |
4547 | if {![info exists filehighlight]} { |
4548 | return 0 | |
4549 | } | |
4550 | set nr 0 | |
4551 | while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} { | |
4e7d6779 PM |
4552 | set line [string trim $line] |
4553 | set i [lsearch -exact $fhl_list $line] | |
4554 | if {$i < 0} continue | |
4555 | for {set j 0} {$j < $i} {incr j} { | |
4556 | set id [lindex $fhl_list $j] | |
476ca63d | 4557 | set fhighlights($id) 0 |
908c3585 | 4558 | } |
4e7d6779 PM |
4559 | set fhl_list [lrange $fhl_list [expr {$i+1}] end] |
4560 | if {$line eq {}} continue | |
7fcc92bf | 4561 | if {![commitinview $line $curview]} continue |
476ca63d | 4562 | if {[info exists iddrawn($line)] && ![ishighlighted $line]} { |
28593d3f | 4563 | bolden $line mainfontbold |
4e7d6779 | 4564 | } |
476ca63d | 4565 | set fhighlights($line) 1 |
908c3585 | 4566 | } |
4e7d6779 PM |
4567 | if {[eof $filehighlight]} { |
4568 | # strange... | |
1ce09dd6 | 4569 | puts "oops, git diff-tree died" |
4e7d6779 PM |
4570 | catch {close $filehighlight} |
4571 | unset filehighlight | |
7eb3cb9c | 4572 | return 0 |
908c3585 | 4573 | } |
687c8765 | 4574 | if {[info exists find_dirn]} { |
cca5d946 | 4575 | run findmore |
908c3585 | 4576 | } |
687c8765 | 4577 | return 1 |
908c3585 PM |
4578 | } |
4579 | ||
4fb0fa19 | 4580 | proc doesmatch {f} { |
687c8765 | 4581 | global findtype findpattern |
4fb0fa19 | 4582 | |
b007ee20 | 4583 | if {$findtype eq [mc "Regexp"]} { |
687c8765 | 4584 | return [regexp $findpattern $f] |
b007ee20 | 4585 | } elseif {$findtype eq [mc "IgnCase"]} { |
4fb0fa19 PM |
4586 | return [string match -nocase $findpattern $f] |
4587 | } else { | |
4588 | return [string match $findpattern $f] | |
4589 | } | |
4590 | } | |
4591 | ||
60f7a7dc | 4592 | proc askfindhighlight {row id} { |
9c311b32 | 4593 | global nhighlights commitinfo iddrawn |
4fb0fa19 PM |
4594 | global findloc |
4595 | global markingmatches | |
908c3585 PM |
4596 | |
4597 | if {![info exists commitinfo($id)]} { | |
4598 | getcommit $id | |
4599 | } | |
60f7a7dc | 4600 | set info $commitinfo($id) |
908c3585 | 4601 | set isbold 0 |
b007ee20 | 4602 | set fldtypes [list [mc Headline] [mc Author] [mc Date] [mc Committer] [mc CDate] [mc Comments]] |
60f7a7dc | 4603 | foreach f $info ty $fldtypes { |
b007ee20 | 4604 | if {($findloc eq [mc "All fields"] || $findloc eq $ty) && |
4fb0fa19 | 4605 | [doesmatch $f]} { |
b007ee20 | 4606 | if {$ty eq [mc "Author"]} { |
60f7a7dc | 4607 | set isbold 2 |
4fb0fa19 | 4608 | break |
60f7a7dc | 4609 | } |
4fb0fa19 | 4610 | set isbold 1 |
908c3585 PM |
4611 | } |
4612 | } | |
4fb0fa19 | 4613 | if {$isbold && [info exists iddrawn($id)]} { |
476ca63d | 4614 | if {![ishighlighted $id]} { |
28593d3f | 4615 | bolden $id mainfontbold |
4fb0fa19 | 4616 | if {$isbold > 1} { |
28593d3f | 4617 | bolden_name $id mainfontbold |
4fb0fa19 | 4618 | } |
908c3585 | 4619 | } |
4fb0fa19 | 4620 | if {$markingmatches} { |
005a2f4e | 4621 | markrowmatches $row $id |
908c3585 PM |
4622 | } |
4623 | } | |
476ca63d | 4624 | set nhighlights($id) $isbold |
da7c24dd PM |
4625 | } |
4626 | ||
005a2f4e PM |
4627 | proc markrowmatches {row id} { |
4628 | global canv canv2 linehtag linentag commitinfo findloc | |
4fb0fa19 | 4629 | |
005a2f4e PM |
4630 | set headline [lindex $commitinfo($id) 0] |
4631 | set author [lindex $commitinfo($id) 1] | |
4fb0fa19 PM |
4632 | $canv delete match$row |
4633 | $canv2 delete match$row | |
b007ee20 | 4634 | if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} { |
005a2f4e PM |
4635 | set m [findmatches $headline] |
4636 | if {$m ne {}} { | |
28593d3f PM |
4637 | markmatches $canv $row $headline $linehtag($id) $m \ |
4638 | [$canv itemcget $linehtag($id) -font] $row | |
005a2f4e | 4639 | } |
4fb0fa19 | 4640 | } |
b007ee20 | 4641 | if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} { |
005a2f4e PM |
4642 | set m [findmatches $author] |
4643 | if {$m ne {}} { | |
28593d3f PM |
4644 | markmatches $canv2 $row $author $linentag($id) $m \ |
4645 | [$canv2 itemcget $linentag($id) -font] $row | |
005a2f4e | 4646 | } |
4fb0fa19 PM |
4647 | } |
4648 | } | |
4649 | ||
164ff275 PM |
4650 | proc vrel_change {name ix op} { |
4651 | global highlight_related | |
4652 | ||
4653 | rhighlight_none | |
b007ee20 | 4654 | if {$highlight_related ne [mc "None"]} { |
7eb3cb9c | 4655 | run drawvisible |
164ff275 PM |
4656 | } |
4657 | } | |
4658 | ||
4659 | # prepare for testing whether commits are descendents or ancestors of a | |
4660 | proc rhighlight_sel {a} { | |
4661 | global descendent desc_todo ancestor anc_todo | |
476ca63d | 4662 | global highlight_related |
164ff275 PM |
4663 | |
4664 | catch {unset descendent} | |
4665 | set desc_todo [list $a] | |
4666 | catch {unset ancestor} | |
4667 | set anc_todo [list $a] | |
b007ee20 | 4668 | if {$highlight_related ne [mc "None"]} { |
164ff275 | 4669 | rhighlight_none |
7eb3cb9c | 4670 | run drawvisible |
164ff275 PM |
4671 | } |
4672 | } | |
4673 | ||
4674 | proc rhighlight_none {} { | |
4675 | global rhighlights | |
4676 | ||
4e7d6779 PM |
4677 | catch {unset rhighlights} |
4678 | unbolden | |
164ff275 PM |
4679 | } |
4680 | ||
4681 | proc is_descendent {a} { | |
7fcc92bf | 4682 | global curview children descendent desc_todo |
164ff275 PM |
4683 | |
4684 | set v $curview | |
7fcc92bf | 4685 | set la [rowofcommit $a] |
164ff275 PM |
4686 | set todo $desc_todo |
4687 | set leftover {} | |
4688 | set done 0 | |
4689 | for {set i 0} {$i < [llength $todo]} {incr i} { | |
4690 | set do [lindex $todo $i] | |
7fcc92bf | 4691 | if {[rowofcommit $do] < $la} { |
164ff275 PM |
4692 | lappend leftover $do |
4693 | continue | |
4694 | } | |
4695 | foreach nk $children($v,$do) { | |
4696 | if {![info exists descendent($nk)]} { | |
4697 | set descendent($nk) 1 | |
4698 | lappend todo $nk | |
4699 | if {$nk eq $a} { | |
4700 | set done 1 | |
4701 | } | |
4702 | } | |
4703 | } | |
4704 | if {$done} { | |
4705 | set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]] | |
4706 | return | |
4707 | } | |
4708 | } | |
4709 | set descendent($a) 0 | |
4710 | set desc_todo $leftover | |
4711 | } | |
4712 | ||
4713 | proc is_ancestor {a} { | |
7fcc92bf | 4714 | global curview parents ancestor anc_todo |
164ff275 PM |
4715 | |
4716 | set v $curview | |
7fcc92bf | 4717 | set la [rowofcommit $a] |
164ff275 PM |
4718 | set todo $anc_todo |
4719 | set leftover {} | |
4720 | set done 0 | |
4721 | for {set i 0} {$i < [llength $todo]} {incr i} { | |
4722 | set do [lindex $todo $i] | |
7fcc92bf | 4723 | if {![commitinview $do $v] || [rowofcommit $do] > $la} { |
164ff275 PM |
4724 | lappend leftover $do |
4725 | continue | |
4726 | } | |
7fcc92bf | 4727 | foreach np $parents($v,$do) { |
164ff275 PM |
4728 | if {![info exists ancestor($np)]} { |
4729 | set ancestor($np) 1 | |
4730 | lappend todo $np | |
4731 | if {$np eq $a} { | |
4732 | set done 1 | |
4733 | } | |
4734 | } | |
4735 | } | |
4736 | if {$done} { | |
4737 | set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]] | |
4738 | return | |
4739 | } | |
4740 | } | |
4741 | set ancestor($a) 0 | |
4742 | set anc_todo $leftover | |
4743 | } | |
4744 | ||
4745 | proc askrelhighlight {row id} { | |
9c311b32 | 4746 | global descendent highlight_related iddrawn rhighlights |
164ff275 PM |
4747 | global selectedline ancestor |
4748 | ||
94b4a69f | 4749 | if {$selectedline eq {}} return |
164ff275 | 4750 | set isbold 0 |
55e34436 CS |
4751 | if {$highlight_related eq [mc "Descendant"] || |
4752 | $highlight_related eq [mc "Not descendant"]} { | |
164ff275 PM |
4753 | if {![info exists descendent($id)]} { |
4754 | is_descendent $id | |
4755 | } | |
55e34436 | 4756 | if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} { |
164ff275 PM |
4757 | set isbold 1 |
4758 | } | |
b007ee20 CS |
4759 | } elseif {$highlight_related eq [mc "Ancestor"] || |
4760 | $highlight_related eq [mc "Not ancestor"]} { | |
164ff275 PM |
4761 | if {![info exists ancestor($id)]} { |
4762 | is_ancestor $id | |
4763 | } | |
b007ee20 | 4764 | if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} { |
164ff275 PM |
4765 | set isbold 1 |
4766 | } | |
4767 | } | |
4768 | if {[info exists iddrawn($id)]} { | |
476ca63d | 4769 | if {$isbold && ![ishighlighted $id]} { |
28593d3f | 4770 | bolden $id mainfontbold |
164ff275 PM |
4771 | } |
4772 | } | |
476ca63d | 4773 | set rhighlights($id) $isbold |
164ff275 PM |
4774 | } |
4775 | ||
da7c24dd PM |
4776 | # Graph layout functions |
4777 | ||
9f1afe05 PM |
4778 | proc shortids {ids} { |
4779 | set res {} | |
4780 | foreach id $ids { | |
4781 | if {[llength $id] > 1} { | |
4782 | lappend res [shortids $id] | |
4783 | } elseif {[regexp {^[0-9a-f]{40}$} $id]} { | |
4784 | lappend res [string range $id 0 7] | |
4785 | } else { | |
4786 | lappend res $id | |
4787 | } | |
4788 | } | |
4789 | return $res | |
4790 | } | |
4791 | ||
9f1afe05 PM |
4792 | proc ntimes {n o} { |
4793 | set ret {} | |
0380081c PM |
4794 | set o [list $o] |
4795 | for {set mask 1} {$mask <= $n} {incr mask $mask} { | |
4796 | if {($n & $mask) != 0} { | |
4797 | set ret [concat $ret $o] | |
9f1afe05 | 4798 | } |
0380081c | 4799 | set o [concat $o $o] |
9f1afe05 | 4800 | } |
0380081c | 4801 | return $ret |
9f1afe05 PM |
4802 | } |
4803 | ||
9257d8f7 PM |
4804 | proc ordertoken {id} { |
4805 | global ordertok curview varcid varcstart varctok curview parents children | |
4806 | global nullid nullid2 | |
4807 | ||
4808 | if {[info exists ordertok($id)]} { | |
4809 | return $ordertok($id) | |
4810 | } | |
4811 | set origid $id | |
4812 | set todo {} | |
4813 | while {1} { | |
4814 | if {[info exists varcid($curview,$id)]} { | |
4815 | set a $varcid($curview,$id) | |
4816 | set p [lindex $varcstart($curview) $a] | |
4817 | } else { | |
4818 | set p [lindex $children($curview,$id) 0] | |
4819 | } | |
4820 | if {[info exists ordertok($p)]} { | |
4821 | set tok $ordertok($p) | |
4822 | break | |
4823 | } | |
c8c9f3d9 PM |
4824 | set id [first_real_child $curview,$p] |
4825 | if {$id eq {}} { | |
9257d8f7 | 4826 | # it's a root |
46308ea1 | 4827 | set tok [lindex $varctok($curview) $varcid($curview,$p)] |
9257d8f7 PM |
4828 | break |
4829 | } | |
9257d8f7 PM |
4830 | if {[llength $parents($curview,$id)] == 1} { |
4831 | lappend todo [list $p {}] | |
4832 | } else { | |
4833 | set j [lsearch -exact $parents($curview,$id) $p] | |
4834 | if {$j < 0} { | |
4835 | puts "oops didn't find [shortids $p] in parents of [shortids $id]" | |
4836 | } | |
4837 | lappend todo [list $p [strrep $j]] | |
4838 | } | |
4839 | } | |
4840 | for {set i [llength $todo]} {[incr i -1] >= 0} {} { | |
4841 | set p [lindex $todo $i 0] | |
4842 | append tok [lindex $todo $i 1] | |
4843 | set ordertok($p) $tok | |
4844 | } | |
4845 | set ordertok($origid) $tok | |
4846 | return $tok | |
4847 | } | |
4848 | ||
6e8c8707 PM |
4849 | # Work out where id should go in idlist so that order-token |
4850 | # values increase from left to right | |
4851 | proc idcol {idlist id {i 0}} { | |
9257d8f7 | 4852 | set t [ordertoken $id] |
e5b37ac1 PM |
4853 | if {$i < 0} { |
4854 | set i 0 | |
4855 | } | |
9257d8f7 | 4856 | if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} { |
6e8c8707 PM |
4857 | if {$i > [llength $idlist]} { |
4858 | set i [llength $idlist] | |
9f1afe05 | 4859 | } |
9257d8f7 | 4860 | while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {} |
6e8c8707 PM |
4861 | incr i |
4862 | } else { | |
9257d8f7 | 4863 | if {$t > [ordertoken [lindex $idlist $i]]} { |
6e8c8707 | 4864 | while {[incr i] < [llength $idlist] && |
9257d8f7 | 4865 | $t >= [ordertoken [lindex $idlist $i]]} {} |
9f1afe05 | 4866 | } |
9f1afe05 | 4867 | } |
6e8c8707 | 4868 | return $i |
9f1afe05 PM |
4869 | } |
4870 | ||
4871 | proc initlayout {} { | |
7fcc92bf | 4872 | global rowidlist rowisopt rowfinal displayorder parentlist |
da7c24dd | 4873 | global numcommits canvxmax canv |
8f7d0cec | 4874 | global nextcolor |
da7c24dd | 4875 | global colormap rowtextx |
9f1afe05 | 4876 | |
8f7d0cec PM |
4877 | set numcommits 0 |
4878 | set displayorder {} | |
79b2c75e | 4879 | set parentlist {} |
8f7d0cec | 4880 | set nextcolor 0 |
0380081c PM |
4881 | set rowidlist {} |
4882 | set rowisopt {} | |
f5f3c2e2 | 4883 | set rowfinal {} |
be0cd098 | 4884 | set canvxmax [$canv cget -width] |
50b44ece PM |
4885 | catch {unset colormap} |
4886 | catch {unset rowtextx} | |
ac1276ab | 4887 | setcanvscroll |
be0cd098 PM |
4888 | } |
4889 | ||
4890 | proc setcanvscroll {} { | |
4891 | global canv canv2 canv3 numcommits linespc canvxmax canvy0 | |
ac1276ab | 4892 | global lastscrollset lastscrollrows |
be0cd098 PM |
4893 | |
4894 | set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}] | |
4895 | $canv conf -scrollregion [list 0 0 $canvxmax $ymax] | |
4896 | $canv2 conf -scrollregion [list 0 0 0 $ymax] | |
4897 | $canv3 conf -scrollregion [list 0 0 0 $ymax] | |
ac1276ab PM |
4898 | set lastscrollset [clock clicks -milliseconds] |
4899 | set lastscrollrows $numcommits | |
9f1afe05 PM |
4900 | } |
4901 | ||
4902 | proc visiblerows {} { | |
4903 | global canv numcommits linespc | |
4904 | ||
4905 | set ymax [lindex [$canv cget -scrollregion] 3] | |
4906 | if {$ymax eq {} || $ymax == 0} return | |
4907 | set f [$canv yview] | |
4908 | set y0 [expr {int([lindex $f 0] * $ymax)}] | |
4909 | set r0 [expr {int(($y0 - 3) / $linespc) - 1}] | |
4910 | if {$r0 < 0} { | |
4911 | set r0 0 | |
4912 | } | |
4913 | set y1 [expr {int([lindex $f 1] * $ymax)}] | |
4914 | set r1 [expr {int(($y1 - 3) / $linespc) + 1}] | |
4915 | if {$r1 >= $numcommits} { | |
4916 | set r1 [expr {$numcommits - 1}] | |
4917 | } | |
4918 | return [list $r0 $r1] | |
4919 | } | |
4920 | ||
f5f3c2e2 | 4921 | proc layoutmore {} { |
38dfe939 | 4922 | global commitidx viewcomplete curview |
94b4a69f | 4923 | global numcommits pending_select curview |
d375ef9b | 4924 | global lastscrollset lastscrollrows |
ac1276ab PM |
4925 | |
4926 | if {$lastscrollrows < 100 || $viewcomplete($curview) || | |
4927 | [clock clicks -milliseconds] - $lastscrollset > 500} { | |
a2c22362 PM |
4928 | setcanvscroll |
4929 | } | |
d94f8cd6 | 4930 | if {[info exists pending_select] && |
7fcc92bf | 4931 | [commitinview $pending_select $curview]} { |
567c34e0 | 4932 | update |
7fcc92bf | 4933 | selectline [rowofcommit $pending_select] 1 |
d94f8cd6 | 4934 | } |
ac1276ab | 4935 | drawvisible |
219ea3a9 PM |
4936 | } |
4937 | ||
cdc8429c PM |
4938 | # With path limiting, we mightn't get the actual HEAD commit, |
4939 | # so ask git rev-list what is the first ancestor of HEAD that | |
4940 | # touches a file in the path limit. | |
4941 | proc get_viewmainhead {view} { | |
4942 | global viewmainheadid vfilelimit viewinstances mainheadid | |
4943 | ||
4944 | catch { | |
4945 | set rfd [open [concat | git rev-list -1 $mainheadid \ | |
4946 | -- $vfilelimit($view)] r] | |
4947 | set j [reg_instance $rfd] | |
4948 | lappend viewinstances($view) $j | |
4949 | fconfigure $rfd -blocking 0 | |
4950 | filerun $rfd [list getviewhead $rfd $j $view] | |
4951 | set viewmainheadid($curview) {} | |
4952 | } | |
4953 | } | |
4954 | ||
4955 | # git rev-list should give us just 1 line to use as viewmainheadid($view) | |
4956 | proc getviewhead {fd inst view} { | |
4957 | global viewmainheadid commfd curview viewinstances showlocalchanges | |
4958 | ||
4959 | set id {} | |
4960 | if {[gets $fd line] < 0} { | |
4961 | if {![eof $fd]} { | |
4962 | return 1 | |
4963 | } | |
4964 | } elseif {[string length $line] == 40 && [string is xdigit $line]} { | |
4965 | set id $line | |
4966 | } | |
4967 | set viewmainheadid($view) $id | |
4968 | close $fd | |
4969 | unset commfd($inst) | |
4970 | set i [lsearch -exact $viewinstances($view) $inst] | |
4971 | if {$i >= 0} { | |
4972 | set viewinstances($view) [lreplace $viewinstances($view) $i $i] | |
4973 | } | |
4974 | if {$showlocalchanges && $id ne {} && $view == $curview} { | |
4975 | doshowlocalchanges | |
4976 | } | |
4977 | return 0 | |
4978 | } | |
4979 | ||
219ea3a9 | 4980 | proc doshowlocalchanges {} { |
cdc8429c | 4981 | global curview viewmainheadid |
219ea3a9 | 4982 | |
cdc8429c PM |
4983 | if {$viewmainheadid($curview) eq {}} return |
4984 | if {[commitinview $viewmainheadid($curview) $curview]} { | |
219ea3a9 | 4985 | dodiffindex |
38dfe939 | 4986 | } else { |
cdc8429c | 4987 | interestedin $viewmainheadid($curview) dodiffindex |
219ea3a9 PM |
4988 | } |
4989 | } | |
4990 | ||
4991 | proc dohidelocalchanges {} { | |
7fcc92bf | 4992 | global nullid nullid2 lserial curview |
219ea3a9 | 4993 | |
7fcc92bf | 4994 | if {[commitinview $nullid $curview]} { |
b8a938cf | 4995 | removefakerow $nullid |
8f489363 | 4996 | } |
7fcc92bf | 4997 | if {[commitinview $nullid2 $curview]} { |
b8a938cf | 4998 | removefakerow $nullid2 |
219ea3a9 PM |
4999 | } |
5000 | incr lserial | |
5001 | } | |
5002 | ||
8f489363 | 5003 | # spawn off a process to do git diff-index --cached HEAD |
219ea3a9 | 5004 | proc dodiffindex {} { |
cdc8429c | 5005 | global lserial showlocalchanges vfilelimit curview |
cb8329aa | 5006 | global isworktree |
219ea3a9 | 5007 | |
cb8329aa | 5008 | if {!$showlocalchanges || !$isworktree} return |
219ea3a9 | 5009 | incr lserial |
cdc8429c PM |
5010 | set cmd "|git diff-index --cached HEAD" |
5011 | if {$vfilelimit($curview) ne {}} { | |
5012 | set cmd [concat $cmd -- $vfilelimit($curview)] | |
5013 | } | |
5014 | set fd [open $cmd r] | |
219ea3a9 | 5015 | fconfigure $fd -blocking 0 |
e439e092 AG |
5016 | set i [reg_instance $fd] |
5017 | filerun $fd [list readdiffindex $fd $lserial $i] | |
219ea3a9 PM |
5018 | } |
5019 | ||
e439e092 | 5020 | proc readdiffindex {fd serial inst} { |
cdc8429c PM |
5021 | global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial |
5022 | global vfilelimit | |
219ea3a9 | 5023 | |
8f489363 | 5024 | set isdiff 1 |
219ea3a9 | 5025 | if {[gets $fd line] < 0} { |
8f489363 PM |
5026 | if {![eof $fd]} { |
5027 | return 1 | |
219ea3a9 | 5028 | } |
8f489363 | 5029 | set isdiff 0 |
219ea3a9 PM |
5030 | } |
5031 | # we only need to see one line and we don't really care what it says... | |
e439e092 | 5032 | stop_instance $inst |
219ea3a9 | 5033 | |
24f7a667 PM |
5034 | if {$serial != $lserial} { |
5035 | return 0 | |
8f489363 PM |
5036 | } |
5037 | ||
24f7a667 | 5038 | # now see if there are any local changes not checked in to the index |
cdc8429c PM |
5039 | set cmd "|git diff-files" |
5040 | if {$vfilelimit($curview) ne {}} { | |
5041 | set cmd [concat $cmd -- $vfilelimit($curview)] | |
5042 | } | |
5043 | set fd [open $cmd r] | |
24f7a667 | 5044 | fconfigure $fd -blocking 0 |
e439e092 AG |
5045 | set i [reg_instance $fd] |
5046 | filerun $fd [list readdifffiles $fd $serial $i] | |
24f7a667 PM |
5047 | |
5048 | if {$isdiff && ![commitinview $nullid2 $curview]} { | |
8f489363 | 5049 | # add the line for the changes in the index to the graph |
d990cedf | 5050 | set hl [mc "Local changes checked in to index but not committed"] |
8f489363 PM |
5051 | set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"] |
5052 | set commitdata($nullid2) "\n $hl\n" | |
fc2a256f | 5053 | if {[commitinview $nullid $curview]} { |
b8a938cf | 5054 | removefakerow $nullid |
fc2a256f | 5055 | } |
cdc8429c | 5056 | insertfakerow $nullid2 $viewmainheadid($curview) |
24f7a667 | 5057 | } elseif {!$isdiff && [commitinview $nullid2 $curview]} { |
cdc8429c PM |
5058 | if {[commitinview $nullid $curview]} { |
5059 | removefakerow $nullid | |
5060 | } | |
b8a938cf | 5061 | removefakerow $nullid2 |
8f489363 PM |
5062 | } |
5063 | return 0 | |
5064 | } | |
5065 | ||
e439e092 | 5066 | proc readdifffiles {fd serial inst} { |
cdc8429c | 5067 | global viewmainheadid nullid nullid2 curview |
8f489363 PM |
5068 | global commitinfo commitdata lserial |
5069 | ||
5070 | set isdiff 1 | |
5071 | if {[gets $fd line] < 0} { | |
5072 | if {![eof $fd]} { | |
5073 | return 1 | |
5074 | } | |
5075 | set isdiff 0 | |
5076 | } | |
5077 | # we only need to see one line and we don't really care what it says... | |
e439e092 | 5078 | stop_instance $inst |
8f489363 | 5079 | |
24f7a667 PM |
5080 | if {$serial != $lserial} { |
5081 | return 0 | |
5082 | } | |
5083 | ||
5084 | if {$isdiff && ![commitinview $nullid $curview]} { | |
219ea3a9 | 5085 | # add the line for the local diff to the graph |
d990cedf | 5086 | set hl [mc "Local uncommitted changes, not checked in to index"] |
219ea3a9 PM |
5087 | set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"] |
5088 | set commitdata($nullid) "\n $hl\n" | |
7fcc92bf PM |
5089 | if {[commitinview $nullid2 $curview]} { |
5090 | set p $nullid2 | |
5091 | } else { | |
cdc8429c | 5092 | set p $viewmainheadid($curview) |
7fcc92bf | 5093 | } |
b8a938cf | 5094 | insertfakerow $nullid $p |
24f7a667 | 5095 | } elseif {!$isdiff && [commitinview $nullid $curview]} { |
b8a938cf | 5096 | removefakerow $nullid |
219ea3a9 PM |
5097 | } |
5098 | return 0 | |
9f1afe05 PM |
5099 | } |
5100 | ||
8f0bc7e9 | 5101 | proc nextuse {id row} { |
7fcc92bf | 5102 | global curview children |
9f1afe05 | 5103 | |
8f0bc7e9 PM |
5104 | if {[info exists children($curview,$id)]} { |
5105 | foreach kid $children($curview,$id) { | |
7fcc92bf | 5106 | if {![commitinview $kid $curview]} { |
0380081c PM |
5107 | return -1 |
5108 | } | |
7fcc92bf PM |
5109 | if {[rowofcommit $kid] > $row} { |
5110 | return [rowofcommit $kid] | |
9f1afe05 | 5111 | } |
9f1afe05 | 5112 | } |
8f0bc7e9 | 5113 | } |
7fcc92bf PM |
5114 | if {[commitinview $id $curview]} { |
5115 | return [rowofcommit $id] | |
8f0bc7e9 PM |
5116 | } |
5117 | return -1 | |
5118 | } | |
5119 | ||
f5f3c2e2 | 5120 | proc prevuse {id row} { |
7fcc92bf | 5121 | global curview children |
f5f3c2e2 PM |
5122 | |
5123 | set ret -1 | |
5124 | if {[info exists children($curview,$id)]} { | |
5125 | foreach kid $children($curview,$id) { | |
7fcc92bf PM |
5126 | if {![commitinview $kid $curview]} break |
5127 | if {[rowofcommit $kid] < $row} { | |
5128 | set ret [rowofcommit $kid] | |
7b459a1c | 5129 | } |
7b459a1c | 5130 | } |
f5f3c2e2 PM |
5131 | } |
5132 | return $ret | |
5133 | } | |
5134 | ||
0380081c PM |
5135 | proc make_idlist {row} { |
5136 | global displayorder parentlist uparrowlen downarrowlen mingaplen | |
9257d8f7 | 5137 | global commitidx curview children |
9f1afe05 | 5138 | |
0380081c PM |
5139 | set r [expr {$row - $mingaplen - $downarrowlen - 1}] |
5140 | if {$r < 0} { | |
5141 | set r 0 | |
8f0bc7e9 | 5142 | } |
0380081c PM |
5143 | set ra [expr {$row - $downarrowlen}] |
5144 | if {$ra < 0} { | |
5145 | set ra 0 | |
5146 | } | |
5147 | set rb [expr {$row + $uparrowlen}] | |
5148 | if {$rb > $commitidx($curview)} { | |
5149 | set rb $commitidx($curview) | |
5150 | } | |
7fcc92bf | 5151 | make_disporder $r [expr {$rb + 1}] |
0380081c PM |
5152 | set ids {} |
5153 | for {} {$r < $ra} {incr r} { | |
5154 | set nextid [lindex $displayorder [expr {$r + 1}]] | |
5155 | foreach p [lindex $parentlist $r] { | |
5156 | if {$p eq $nextid} continue | |
5157 | set rn [nextuse $p $r] | |
5158 | if {$rn >= $row && | |
5159 | $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} { | |
9257d8f7 | 5160 | lappend ids [list [ordertoken $p] $p] |
9f1afe05 | 5161 | } |
9f1afe05 | 5162 | } |
0380081c PM |
5163 | } |
5164 | for {} {$r < $row} {incr r} { | |
5165 | set nextid [lindex $displayorder [expr {$r + 1}]] | |
5166 | foreach p [lindex $parentlist $r] { | |
5167 | if {$p eq $nextid} continue | |
5168 | set rn [nextuse $p $r] | |
5169 | if {$rn < 0 || $rn >= $row} { | |
9257d8f7 | 5170 | lappend ids [list [ordertoken $p] $p] |
9f1afe05 | 5171 | } |
9f1afe05 | 5172 | } |
0380081c PM |
5173 | } |
5174 | set id [lindex $displayorder $row] | |
9257d8f7 | 5175 | lappend ids [list [ordertoken $id] $id] |
0380081c PM |
5176 | while {$r < $rb} { |
5177 | foreach p [lindex $parentlist $r] { | |
5178 | set firstkid [lindex $children($curview,$p) 0] | |
7fcc92bf | 5179 | if {[rowofcommit $firstkid] < $row} { |
9257d8f7 | 5180 | lappend ids [list [ordertoken $p] $p] |
9f1afe05 | 5181 | } |
9f1afe05 | 5182 | } |
0380081c PM |
5183 | incr r |
5184 | set id [lindex $displayorder $r] | |
5185 | if {$id ne {}} { | |
5186 | set firstkid [lindex $children($curview,$id) 0] | |
7fcc92bf | 5187 | if {$firstkid ne {} && [rowofcommit $firstkid] < $row} { |
9257d8f7 | 5188 | lappend ids [list [ordertoken $id] $id] |
0380081c | 5189 | } |
9f1afe05 | 5190 | } |
9f1afe05 | 5191 | } |
0380081c PM |
5192 | set idlist {} |
5193 | foreach idx [lsort -unique $ids] { | |
5194 | lappend idlist [lindex $idx 1] | |
5195 | } | |
5196 | return $idlist | |
9f1afe05 PM |
5197 | } |
5198 | ||
f5f3c2e2 PM |
5199 | proc rowsequal {a b} { |
5200 | while {[set i [lsearch -exact $a {}]] >= 0} { | |
5201 | set a [lreplace $a $i $i] | |
5202 | } | |
5203 | while {[set i [lsearch -exact $b {}]] >= 0} { | |
5204 | set b [lreplace $b $i $i] | |
5205 | } | |
5206 | return [expr {$a eq $b}] | |
9f1afe05 PM |
5207 | } |
5208 | ||
f5f3c2e2 PM |
5209 | proc makeupline {id row rend col} { |
5210 | global rowidlist uparrowlen downarrowlen mingaplen | |
9f1afe05 | 5211 | |
f5f3c2e2 PM |
5212 | for {set r $rend} {1} {set r $rstart} { |
5213 | set rstart [prevuse $id $r] | |
5214 | if {$rstart < 0} return | |
5215 | if {$rstart < $row} break | |
5216 | } | |
5217 | if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} { | |
5218 | set rstart [expr {$rend - $uparrowlen - 1}] | |
79b2c75e | 5219 | } |
f5f3c2e2 PM |
5220 | for {set r $rstart} {[incr r] <= $row} {} { |
5221 | set idlist [lindex $rowidlist $r] | |
5222 | if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} { | |
5223 | set col [idcol $idlist $id $col] | |
5224 | lset rowidlist $r [linsert $idlist $col $id] | |
5225 | changedrow $r | |
5226 | } | |
9f1afe05 PM |
5227 | } |
5228 | } | |
5229 | ||
0380081c | 5230 | proc layoutrows {row endrow} { |
f5f3c2e2 | 5231 | global rowidlist rowisopt rowfinal displayorder |
0380081c PM |
5232 | global uparrowlen downarrowlen maxwidth mingaplen |
5233 | global children parentlist | |
7fcc92bf | 5234 | global commitidx viewcomplete curview |
9f1afe05 | 5235 | |
7fcc92bf | 5236 | make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}] |
0380081c PM |
5237 | set idlist {} |
5238 | if {$row > 0} { | |
f56782ae PM |
5239 | set rm1 [expr {$row - 1}] |
5240 | foreach id [lindex $rowidlist $rm1] { | |
0380081c PM |
5241 | if {$id ne {}} { |
5242 | lappend idlist $id | |
5243 | } | |
5244 | } | |
f56782ae | 5245 | set final [lindex $rowfinal $rm1] |
79b2c75e | 5246 | } |
0380081c PM |
5247 | for {} {$row < $endrow} {incr row} { |
5248 | set rm1 [expr {$row - 1}] | |
f56782ae | 5249 | if {$rm1 < 0 || $idlist eq {}} { |
0380081c | 5250 | set idlist [make_idlist $row] |
f5f3c2e2 | 5251 | set final 1 |
0380081c PM |
5252 | } else { |
5253 | set id [lindex $displayorder $rm1] | |
5254 | set col [lsearch -exact $idlist $id] | |
5255 | set idlist [lreplace $idlist $col $col] | |
5256 | foreach p [lindex $parentlist $rm1] { | |
5257 | if {[lsearch -exact $idlist $p] < 0} { | |
5258 | set col [idcol $idlist $p $col] | |
5259 | set idlist [linsert $idlist $col $p] | |
f5f3c2e2 PM |
5260 | # if not the first child, we have to insert a line going up |
5261 | if {$id ne [lindex $children($curview,$p) 0]} { | |
5262 | makeupline $p $rm1 $row $col | |
5263 | } | |
0380081c PM |
5264 | } |
5265 | } | |
5266 | set id [lindex $displayorder $row] | |
5267 | if {$row > $downarrowlen} { | |
5268 | set termrow [expr {$row - $downarrowlen - 1}] | |
5269 | foreach p [lindex $parentlist $termrow] { | |
5270 | set i [lsearch -exact $idlist $p] | |
5271 | if {$i < 0} continue | |
5272 | set nr [nextuse $p $termrow] | |
5273 | if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} { | |
5274 | set idlist [lreplace $idlist $i $i] | |
5275 | } | |
5276 | } | |
5277 | } | |
5278 | set col [lsearch -exact $idlist $id] | |
5279 | if {$col < 0} { | |
5280 | set col [idcol $idlist $id] | |
5281 | set idlist [linsert $idlist $col $id] | |
f5f3c2e2 PM |
5282 | if {$children($curview,$id) ne {}} { |
5283 | makeupline $id $rm1 $row $col | |
5284 | } | |
0380081c PM |
5285 | } |
5286 | set r [expr {$row + $uparrowlen - 1}] | |
5287 | if {$r < $commitidx($curview)} { | |
5288 | set x $col | |
5289 | foreach p [lindex $parentlist $r] { | |
5290 | if {[lsearch -exact $idlist $p] >= 0} continue | |
5291 | set fk [lindex $children($curview,$p) 0] | |
7fcc92bf | 5292 | if {[rowofcommit $fk] < $row} { |
0380081c PM |
5293 | set x [idcol $idlist $p $x] |
5294 | set idlist [linsert $idlist $x $p] | |
5295 | } | |
5296 | } | |
5297 | if {[incr r] < $commitidx($curview)} { | |
5298 | set p [lindex $displayorder $r] | |
5299 | if {[lsearch -exact $idlist $p] < 0} { | |
5300 | set fk [lindex $children($curview,$p) 0] | |
7fcc92bf | 5301 | if {$fk ne {} && [rowofcommit $fk] < $row} { |
0380081c PM |
5302 | set x [idcol $idlist $p $x] |
5303 | set idlist [linsert $idlist $x $p] | |
5304 | } | |
5305 | } | |
5306 | } | |
5307 | } | |
5308 | } | |
f5f3c2e2 PM |
5309 | if {$final && !$viewcomplete($curview) && |
5310 | $row + $uparrowlen + $mingaplen + $downarrowlen | |
5311 | >= $commitidx($curview)} { | |
5312 | set final 0 | |
5313 | } | |
0380081c PM |
5314 | set l [llength $rowidlist] |
5315 | if {$row == $l} { | |
5316 | lappend rowidlist $idlist | |
5317 | lappend rowisopt 0 | |
f5f3c2e2 | 5318 | lappend rowfinal $final |
0380081c | 5319 | } elseif {$row < $l} { |
f5f3c2e2 | 5320 | if {![rowsequal $idlist [lindex $rowidlist $row]]} { |
0380081c PM |
5321 | lset rowidlist $row $idlist |
5322 | changedrow $row | |
5323 | } | |
f56782ae | 5324 | lset rowfinal $row $final |
0380081c | 5325 | } else { |
f5f3c2e2 PM |
5326 | set pad [ntimes [expr {$row - $l}] {}] |
5327 | set rowidlist [concat $rowidlist $pad] | |
0380081c | 5328 | lappend rowidlist $idlist |
f5f3c2e2 PM |
5329 | set rowfinal [concat $rowfinal $pad] |
5330 | lappend rowfinal $final | |
0380081c PM |
5331 | set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]] |
5332 | } | |
9f1afe05 | 5333 | } |
0380081c | 5334 | return $row |
9f1afe05 PM |
5335 | } |
5336 | ||
0380081c PM |
5337 | proc changedrow {row} { |
5338 | global displayorder iddrawn rowisopt need_redisplay | |
9f1afe05 | 5339 | |
0380081c PM |
5340 | set l [llength $rowisopt] |
5341 | if {$row < $l} { | |
5342 | lset rowisopt $row 0 | |
5343 | if {$row + 1 < $l} { | |
5344 | lset rowisopt [expr {$row + 1}] 0 | |
5345 | if {$row + 2 < $l} { | |
5346 | lset rowisopt [expr {$row + 2}] 0 | |
5347 | } | |
5348 | } | |
5349 | } | |
5350 | set id [lindex $displayorder $row] | |
5351 | if {[info exists iddrawn($id)]} { | |
5352 | set need_redisplay 1 | |
9f1afe05 PM |
5353 | } |
5354 | } | |
5355 | ||
5356 | proc insert_pad {row col npad} { | |
6e8c8707 | 5357 | global rowidlist |
9f1afe05 PM |
5358 | |
5359 | set pad [ntimes $npad {}] | |
e341c06d PM |
5360 | set idlist [lindex $rowidlist $row] |
5361 | set bef [lrange $idlist 0 [expr {$col - 1}]] | |
5362 | set aft [lrange $idlist $col end] | |
5363 | set i [lsearch -exact $aft {}] | |
5364 | if {$i > 0} { | |
5365 | set aft [lreplace $aft $i $i] | |
5366 | } | |
5367 | lset rowidlist $row [concat $bef $pad $aft] | |
0380081c | 5368 | changedrow $row |
9f1afe05 PM |
5369 | } |
5370 | ||
5371 | proc optimize_rows {row col endrow} { | |
0380081c | 5372 | global rowidlist rowisopt displayorder curview children |
9f1afe05 | 5373 | |
6e8c8707 PM |
5374 | if {$row < 1} { |
5375 | set row 1 | |
5376 | } | |
0380081c PM |
5377 | for {} {$row < $endrow} {incr row; set col 0} { |
5378 | if {[lindex $rowisopt $row]} continue | |
9f1afe05 | 5379 | set haspad 0 |
6e8c8707 PM |
5380 | set y0 [expr {$row - 1}] |
5381 | set ym [expr {$row - 2}] | |
0380081c PM |
5382 | set idlist [lindex $rowidlist $row] |
5383 | set previdlist [lindex $rowidlist $y0] | |
5384 | if {$idlist eq {} || $previdlist eq {}} continue | |
5385 | if {$ym >= 0} { | |
5386 | set pprevidlist [lindex $rowidlist $ym] | |
5387 | if {$pprevidlist eq {}} continue | |
5388 | } else { | |
5389 | set pprevidlist {} | |
5390 | } | |
6e8c8707 PM |
5391 | set x0 -1 |
5392 | set xm -1 | |
5393 | for {} {$col < [llength $idlist]} {incr col} { | |
5394 | set id [lindex $idlist $col] | |
5395 | if {[lindex $previdlist $col] eq $id} continue | |
5396 | if {$id eq {}} { | |
9f1afe05 PM |
5397 | set haspad 1 |
5398 | continue | |
5399 | } | |
6e8c8707 PM |
5400 | set x0 [lsearch -exact $previdlist $id] |
5401 | if {$x0 < 0} continue | |
5402 | set z [expr {$x0 - $col}] | |
9f1afe05 | 5403 | set isarrow 0 |
6e8c8707 PM |
5404 | set z0 {} |
5405 | if {$ym >= 0} { | |
5406 | set xm [lsearch -exact $pprevidlist $id] | |
5407 | if {$xm >= 0} { | |
5408 | set z0 [expr {$xm - $x0}] | |
5409 | } | |
5410 | } | |
9f1afe05 | 5411 | if {$z0 eq {}} { |
92ed666f PM |
5412 | # if row y0 is the first child of $id then it's not an arrow |
5413 | if {[lindex $children($curview,$id) 0] ne | |
5414 | [lindex $displayorder $y0]} { | |
9f1afe05 PM |
5415 | set isarrow 1 |
5416 | } | |
5417 | } | |
e341c06d PM |
5418 | if {!$isarrow && $id ne [lindex $displayorder $row] && |
5419 | [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} { | |
5420 | set isarrow 1 | |
5421 | } | |
3fc4279a PM |
5422 | # Looking at lines from this row to the previous row, |
5423 | # make them go straight up if they end in an arrow on | |
5424 | # the previous row; otherwise make them go straight up | |
5425 | # or at 45 degrees. | |
9f1afe05 | 5426 | if {$z < -1 || ($z < 0 && $isarrow)} { |
3fc4279a PM |
5427 | # Line currently goes left too much; |
5428 | # insert pads in the previous row, then optimize it | |
9f1afe05 | 5429 | set npad [expr {-1 - $z + $isarrow}] |
9f1afe05 PM |
5430 | insert_pad $y0 $x0 $npad |
5431 | if {$y0 > 0} { | |
5432 | optimize_rows $y0 $x0 $row | |
5433 | } | |
6e8c8707 PM |
5434 | set previdlist [lindex $rowidlist $y0] |
5435 | set x0 [lsearch -exact $previdlist $id] | |
5436 | set z [expr {$x0 - $col}] | |
5437 | if {$z0 ne {}} { | |
5438 | set pprevidlist [lindex $rowidlist $ym] | |
5439 | set xm [lsearch -exact $pprevidlist $id] | |
5440 | set z0 [expr {$xm - $x0}] | |
5441 | } | |
9f1afe05 | 5442 | } elseif {$z > 1 || ($z > 0 && $isarrow)} { |
3fc4279a | 5443 | # Line currently goes right too much; |
6e8c8707 | 5444 | # insert pads in this line |
9f1afe05 | 5445 | set npad [expr {$z - 1 + $isarrow}] |
e341c06d PM |
5446 | insert_pad $row $col $npad |
5447 | set idlist [lindex $rowidlist $row] | |
9f1afe05 | 5448 | incr col $npad |
6e8c8707 | 5449 | set z [expr {$x0 - $col}] |
9f1afe05 PM |
5450 | set haspad 1 |
5451 | } | |
6e8c8707 | 5452 | if {$z0 eq {} && !$isarrow && $ym >= 0} { |
eb447a12 | 5453 | # this line links to its first child on row $row-2 |
6e8c8707 PM |
5454 | set id [lindex $displayorder $ym] |
5455 | set xc [lsearch -exact $pprevidlist $id] | |
eb447a12 PM |
5456 | if {$xc >= 0} { |
5457 | set z0 [expr {$xc - $x0}] | |
5458 | } | |
5459 | } | |
3fc4279a | 5460 | # avoid lines jigging left then immediately right |
9f1afe05 PM |
5461 | if {$z0 ne {} && $z < 0 && $z0 > 0} { |
5462 | insert_pad $y0 $x0 1 | |
6e8c8707 PM |
5463 | incr x0 |
5464 | optimize_rows $y0 $x0 $row | |
5465 | set previdlist [lindex $rowidlist $y0] | |
9f1afe05 PM |
5466 | } |
5467 | } | |
5468 | if {!$haspad} { | |
3fc4279a | 5469 | # Find the first column that doesn't have a line going right |
9f1afe05 | 5470 | for {set col [llength $idlist]} {[incr col -1] >= 0} {} { |
6e8c8707 PM |
5471 | set id [lindex $idlist $col] |
5472 | if {$id eq {}} break | |
5473 | set x0 [lsearch -exact $previdlist $id] | |
5474 | if {$x0 < 0} { | |
eb447a12 | 5475 | # check if this is the link to the first child |
92ed666f PM |
5476 | set kid [lindex $displayorder $y0] |
5477 | if {[lindex $children($curview,$id) 0] eq $kid} { | |
eb447a12 | 5478 | # it is, work out offset to child |
92ed666f | 5479 | set x0 [lsearch -exact $previdlist $kid] |
eb447a12 PM |
5480 | } |
5481 | } | |
6e8c8707 | 5482 | if {$x0 <= $col} break |
9f1afe05 | 5483 | } |
3fc4279a | 5484 | # Insert a pad at that column as long as it has a line and |
6e8c8707 PM |
5485 | # isn't the last column |
5486 | if {$x0 >= 0 && [incr col] < [llength $idlist]} { | |
9f1afe05 | 5487 | set idlist [linsert $idlist $col {}] |
0380081c PM |
5488 | lset rowidlist $row $idlist |
5489 | changedrow $row | |
9f1afe05 PM |
5490 | } |
5491 | } | |
9f1afe05 PM |
5492 | } |
5493 | } | |
5494 | ||
5495 | proc xc {row col} { | |
5496 | global canvx0 linespc | |
5497 | return [expr {$canvx0 + $col * $linespc}] | |
5498 | } | |
5499 | ||
5500 | proc yc {row} { | |
5501 | global canvy0 linespc | |
5502 | return [expr {$canvy0 + $row * $linespc}] | |
5503 | } | |
5504 | ||
c934a8a3 PM |
5505 | proc linewidth {id} { |
5506 | global thickerline lthickness | |
5507 | ||
5508 | set wid $lthickness | |
5509 | if {[info exists thickerline] && $id eq $thickerline} { | |
5510 | set wid [expr {2 * $lthickness}] | |
5511 | } | |
5512 | return $wid | |
5513 | } | |
5514 | ||
50b44ece | 5515 | proc rowranges {id} { |
7fcc92bf | 5516 | global curview children uparrowlen downarrowlen |
92ed666f | 5517 | global rowidlist |
50b44ece | 5518 | |
92ed666f PM |
5519 | set kids $children($curview,$id) |
5520 | if {$kids eq {}} { | |
5521 | return {} | |
66e46f37 | 5522 | } |
92ed666f PM |
5523 | set ret {} |
5524 | lappend kids $id | |
5525 | foreach child $kids { | |
7fcc92bf PM |
5526 | if {![commitinview $child $curview]} break |
5527 | set row [rowofcommit $child] | |
92ed666f PM |
5528 | if {![info exists prev]} { |
5529 | lappend ret [expr {$row + 1}] | |
322a8cc9 | 5530 | } else { |
92ed666f | 5531 | if {$row <= $prevrow} { |
7fcc92bf | 5532 | puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow" |
92ed666f PM |
5533 | } |
5534 | # see if the line extends the whole way from prevrow to row | |
5535 | if {$row > $prevrow + $uparrowlen + $downarrowlen && | |
5536 | [lsearch -exact [lindex $rowidlist \ | |
5537 | [expr {int(($row + $prevrow) / 2)}]] $id] < 0} { | |
5538 | # it doesn't, see where it ends | |
5539 | set r [expr {$prevrow + $downarrowlen}] | |
5540 | if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} { | |
5541 | while {[incr r -1] > $prevrow && | |
5542 | [lsearch -exact [lindex $rowidlist $r] $id] < 0} {} | |
5543 | } else { | |
5544 | while {[incr r] <= $row && | |
5545 | [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {} | |
5546 | incr r -1 | |
5547 | } | |
5548 | lappend ret $r | |
5549 | # see where it starts up again | |
5550 | set r [expr {$row - $uparrowlen}] | |
5551 | if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} { | |
5552 | while {[incr r] < $row && | |
5553 | [lsearch -exact [lindex $rowidlist $r] $id] < 0} {} | |
5554 | } else { | |
5555 | while {[incr r -1] >= $prevrow && | |
5556 | [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {} | |
5557 | incr r | |
5558 | } | |
5559 | lappend ret $r | |
5560 | } | |
5561 | } | |
5562 | if {$child eq $id} { | |
5563 | lappend ret $row | |
322a8cc9 | 5564 | } |
7fcc92bf | 5565 | set prev $child |
92ed666f | 5566 | set prevrow $row |
9f1afe05 | 5567 | } |
92ed666f | 5568 | return $ret |
322a8cc9 PM |
5569 | } |
5570 | ||
5571 | proc drawlineseg {id row endrow arrowlow} { | |
5572 | global rowidlist displayorder iddrawn linesegs | |
e341c06d | 5573 | global canv colormap linespc curview maxlinelen parentlist |
322a8cc9 PM |
5574 | |
5575 | set cols [list [lsearch -exact [lindex $rowidlist $row] $id]] | |
5576 | set le [expr {$row + 1}] | |
5577 | set arrowhigh 1 | |
9f1afe05 | 5578 | while {1} { |
322a8cc9 PM |
5579 | set c [lsearch -exact [lindex $rowidlist $le] $id] |
5580 | if {$c < 0} { | |
5581 | incr le -1 | |
5582 | break | |
5583 | } | |
5584 | lappend cols $c | |
5585 | set x [lindex $displayorder $le] | |
5586 | if {$x eq $id} { | |
5587 | set arrowhigh 0 | |
5588 | break | |
9f1afe05 | 5589 | } |
322a8cc9 PM |
5590 | if {[info exists iddrawn($x)] || $le == $endrow} { |
5591 | set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id] | |
5592 | if {$c >= 0} { | |
5593 | lappend cols $c | |
5594 | set arrowhigh 0 | |
5595 | } | |
5596 | break | |
5597 | } | |
5598 | incr le | |
9f1afe05 | 5599 | } |
322a8cc9 PM |
5600 | if {$le <= $row} { |
5601 | return $row | |
5602 | } | |
5603 | ||
5604 | set lines {} | |
5605 | set i 0 | |
5606 | set joinhigh 0 | |
5607 | if {[info exists linesegs($id)]} { | |
5608 | set lines $linesegs($id) | |
5609 | foreach li $lines { | |
5610 | set r0 [lindex $li 0] | |
5611 | if {$r0 > $row} { | |
5612 | if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} { | |
5613 | set joinhigh 1 | |
5614 | } | |
5615 | break | |
5616 | } | |
5617 | incr i | |
5618 | } | |
5619 | } | |
5620 | set joinlow 0 | |
5621 | if {$i > 0} { | |
5622 | set li [lindex $lines [expr {$i-1}]] | |
5623 | set r1 [lindex $li 1] | |
5624 | if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} { | |
5625 | set joinlow 1 | |
5626 | } | |
5627 | } | |
5628 | ||
5629 | set x [lindex $cols [expr {$le - $row}]] | |
5630 | set xp [lindex $cols [expr {$le - 1 - $row}]] | |
5631 | set dir [expr {$xp - $x}] | |
5632 | if {$joinhigh} { | |
5633 | set ith [lindex $lines $i 2] | |
5634 | set coords [$canv coords $ith] | |
5635 | set ah [$canv itemcget $ith -arrow] | |
5636 | set arrowhigh [expr {$ah eq "first" || $ah eq "both"}] | |
5637 | set x2 [lindex $cols [expr {$le + 1 - $row}]] | |
5638 | if {$x2 ne {} && $x - $x2 == $dir} { | |
5639 | set coords [lrange $coords 0 end-2] | |
5640 | } | |
5641 | } else { | |
5642 | set coords [list [xc $le $x] [yc $le]] | |
5643 | } | |
5644 | if {$joinlow} { | |
5645 | set itl [lindex $lines [expr {$i-1}] 2] | |
5646 | set al [$canv itemcget $itl -arrow] | |
5647 | set arrowlow [expr {$al eq "last" || $al eq "both"}] | |
e341c06d PM |
5648 | } elseif {$arrowlow} { |
5649 | if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 || | |
5650 | [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} { | |
5651 | set arrowlow 0 | |
5652 | } | |
322a8cc9 PM |
5653 | } |
5654 | set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]] | |
5655 | for {set y $le} {[incr y -1] > $row} {} { | |
5656 | set x $xp | |
5657 | set xp [lindex $cols [expr {$y - 1 - $row}]] | |
5658 | set ndir [expr {$xp - $x}] | |
5659 | if {$dir != $ndir || $xp < 0} { | |
5660 | lappend coords [xc $y $x] [yc $y] | |
5661 | } | |
5662 | set dir $ndir | |
5663 | } | |
5664 | if {!$joinlow} { | |
5665 | if {$xp < 0} { | |
5666 | # join parent line to first child | |
5667 | set ch [lindex $displayorder $row] | |
5668 | set xc [lsearch -exact [lindex $rowidlist $row] $ch] | |
5669 | if {$xc < 0} { | |
5670 | puts "oops: drawlineseg: child $ch not on row $row" | |
e341c06d PM |
5671 | } elseif {$xc != $x} { |
5672 | if {($arrowhigh && $le == $row + 1) || $dir == 0} { | |
5673 | set d [expr {int(0.5 * $linespc)}] | |
5674 | set x1 [xc $row $x] | |
5675 | if {$xc < $x} { | |
5676 | set x2 [expr {$x1 - $d}] | |
5677 | } else { | |
5678 | set x2 [expr {$x1 + $d}] | |
5679 | } | |
5680 | set y2 [yc $row] | |
5681 | set y1 [expr {$y2 + $d}] | |
5682 | lappend coords $x1 $y1 $x2 $y2 | |
5683 | } elseif {$xc < $x - 1} { | |
322a8cc9 PM |
5684 | lappend coords [xc $row [expr {$x-1}]] [yc $row] |
5685 | } elseif {$xc > $x + 1} { | |
5686 | lappend coords [xc $row [expr {$x+1}]] [yc $row] | |
5687 | } | |
5688 | set x $xc | |
eb447a12 | 5689 | } |
322a8cc9 PM |
5690 | lappend coords [xc $row $x] [yc $row] |
5691 | } else { | |
5692 | set xn [xc $row $xp] | |
5693 | set yn [yc $row] | |
e341c06d | 5694 | lappend coords $xn $yn |
322a8cc9 PM |
5695 | } |
5696 | if {!$joinhigh} { | |
322a8cc9 PM |
5697 | assigncolor $id |
5698 | set t [$canv create line $coords -width [linewidth $id] \ | |
5699 | -fill $colormap($id) -tags lines.$id -arrow $arrow] | |
5700 | $canv lower $t | |
5701 | bindline $t $id | |
5702 | set lines [linsert $lines $i [list $row $le $t]] | |
5703 | } else { | |
5704 | $canv coords $ith $coords | |
5705 | if {$arrow ne $ah} { | |
5706 | $canv itemconf $ith -arrow $arrow | |
5707 | } | |
5708 | lset lines $i 0 $row | |
5709 | } | |
5710 | } else { | |
5711 | set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id] | |
5712 | set ndir [expr {$xo - $xp}] | |
5713 | set clow [$canv coords $itl] | |
5714 | if {$dir == $ndir} { | |
5715 | set clow [lrange $clow 2 end] | |
5716 | } | |
5717 | set coords [concat $coords $clow] | |
5718 | if {!$joinhigh} { | |
5719 | lset lines [expr {$i-1}] 1 $le | |
322a8cc9 PM |
5720 | } else { |
5721 | # coalesce two pieces | |
5722 | $canv delete $ith | |
5723 | set b [lindex $lines [expr {$i-1}] 0] | |
5724 | set e [lindex $lines $i 1] | |
5725 | set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]] | |
5726 | } | |
5727 | $canv coords $itl $coords | |
5728 | if {$arrow ne $al} { | |
5729 | $canv itemconf $itl -arrow $arrow | |
879e8b1a PM |
5730 | } |
5731 | } | |
322a8cc9 PM |
5732 | |
5733 | set linesegs($id) $lines | |
5734 | return $le | |
9f1afe05 PM |
5735 | } |
5736 | ||
322a8cc9 PM |
5737 | proc drawparentlinks {id row} { |
5738 | global rowidlist canv colormap curview parentlist | |
513a54dc | 5739 | global idpos linespc |
9f1afe05 | 5740 | |
322a8cc9 PM |
5741 | set rowids [lindex $rowidlist $row] |
5742 | set col [lsearch -exact $rowids $id] | |
5743 | if {$col < 0} return | |
5744 | set olds [lindex $parentlist $row] | |
9f1afe05 PM |
5745 | set row2 [expr {$row + 1}] |
5746 | set x [xc $row $col] | |
5747 | set y [yc $row] | |
5748 | set y2 [yc $row2] | |
e341c06d | 5749 | set d [expr {int(0.5 * $linespc)}] |
513a54dc | 5750 | set ymid [expr {$y + $d}] |
8f7d0cec | 5751 | set ids [lindex $rowidlist $row2] |
9f1afe05 PM |
5752 | # rmx = right-most X coord used |
5753 | set rmx 0 | |
9f1afe05 | 5754 | foreach p $olds { |
f3408449 PM |
5755 | set i [lsearch -exact $ids $p] |
5756 | if {$i < 0} { | |
5757 | puts "oops, parent $p of $id not in list" | |
5758 | continue | |
5759 | } | |
5760 | set x2 [xc $row2 $i] | |
5761 | if {$x2 > $rmx} { | |
5762 | set rmx $x2 | |
5763 | } | |
513a54dc PM |
5764 | set j [lsearch -exact $rowids $p] |
5765 | if {$j < 0} { | |
eb447a12 PM |
5766 | # drawlineseg will do this one for us |
5767 | continue | |
5768 | } | |
9f1afe05 PM |
5769 | assigncolor $p |
5770 | # should handle duplicated parents here... | |
5771 | set coords [list $x $y] | |
513a54dc PM |
5772 | if {$i != $col} { |
5773 | # if attaching to a vertical segment, draw a smaller | |
5774 | # slant for visual distinctness | |
5775 | if {$i == $j} { | |
5776 | if {$i < $col} { | |
5777 | lappend coords [expr {$x2 + $d}] $y $x2 $ymid | |
5778 | } else { | |
5779 | lappend coords [expr {$x2 - $d}] $y $x2 $ymid | |
5780 | } | |
5781 | } elseif {$i < $col && $i < $j} { | |
5782 | # segment slants towards us already | |
5783 | lappend coords [xc $row $j] $y | |
5784 | } else { | |
5785 | if {$i < $col - 1} { | |
5786 | lappend coords [expr {$x2 + $linespc}] $y | |
5787 | } elseif {$i > $col + 1} { | |
5788 | lappend coords [expr {$x2 - $linespc}] $y | |
5789 | } | |
5790 | lappend coords $x2 $y2 | |
5791 | } | |
5792 | } else { | |
5793 | lappend coords $x2 $y2 | |
9f1afe05 | 5794 | } |
c934a8a3 | 5795 | set t [$canv create line $coords -width [linewidth $p] \ |
9f1afe05 PM |
5796 | -fill $colormap($p) -tags lines.$p] |
5797 | $canv lower $t | |
5798 | bindline $t $p | |
5799 | } | |
322a8cc9 PM |
5800 | if {$rmx > [lindex $idpos($id) 1]} { |
5801 | lset idpos($id) 1 $rmx | |
5802 | redrawtags $id | |
5803 | } | |
9f1afe05 PM |
5804 | } |
5805 | ||
c934a8a3 | 5806 | proc drawlines {id} { |
322a8cc9 | 5807 | global canv |
9f1afe05 | 5808 | |
322a8cc9 | 5809 | $canv itemconf lines.$id -width [linewidth $id] |
9f1afe05 PM |
5810 | } |
5811 | ||
322a8cc9 | 5812 | proc drawcmittext {id row col} { |
7fcc92bf PM |
5813 | global linespc canv canv2 canv3 fgcolor curview |
5814 | global cmitlisted commitinfo rowidlist parentlist | |
9f1afe05 | 5815 | global rowtextx idpos idtags idheads idotherrefs |
0380081c | 5816 | global linehtag linentag linedtag selectedline |
b9fdba7f | 5817 | global canvxmax boldids boldnameids fgcolor markedid |
d277e89f | 5818 | global mainheadid nullid nullid2 circleitem circlecolors ctxbut |
9f1afe05 | 5819 | |
1407ade9 | 5820 | # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right |
7fcc92bf | 5821 | set listed $cmitlisted($curview,$id) |
219ea3a9 PM |
5822 | if {$id eq $nullid} { |
5823 | set ofill red | |
8f489363 | 5824 | } elseif {$id eq $nullid2} { |
ef3192b8 | 5825 | set ofill green |
c11ff120 PM |
5826 | } elseif {$id eq $mainheadid} { |
5827 | set ofill yellow | |
219ea3a9 | 5828 | } else { |
c11ff120 | 5829 | set ofill [lindex $circlecolors $listed] |
219ea3a9 | 5830 | } |
9f1afe05 PM |
5831 | set x [xc $row $col] |
5832 | set y [yc $row] | |
5833 | set orad [expr {$linespc / 3}] | |
1407ade9 | 5834 | if {$listed <= 2} { |
c961b228 PM |
5835 | set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \ |
5836 | [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \ | |
5837 | -fill $ofill -outline $fgcolor -width 1 -tags circle] | |
1407ade9 | 5838 | } elseif {$listed == 3} { |
c961b228 PM |
5839 | # triangle pointing left for left-side commits |
5840 | set t [$canv create polygon \ | |
5841 | [expr {$x - $orad}] $y \ | |
5842 | [expr {$x + $orad - 1}] [expr {$y - $orad}] \ | |
5843 | [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \ | |
5844 | -fill $ofill -outline $fgcolor -width 1 -tags circle] | |
5845 | } else { | |
5846 | # triangle pointing right for right-side commits | |
5847 | set t [$canv create polygon \ | |
5848 | [expr {$x + $orad - 1}] $y \ | |
5849 | [expr {$x - $orad}] [expr {$y - $orad}] \ | |
5850 | [expr {$x - $orad}] [expr {$y + $orad - 1}] \ | |
5851 | -fill $ofill -outline $fgcolor -width 1 -tags circle] | |
5852 | } | |
c11ff120 | 5853 | set circleitem($row) $t |
9f1afe05 PM |
5854 | $canv raise $t |
5855 | $canv bind $t <1> {selcanvline {} %x %y} | |
322a8cc9 PM |
5856 | set rmx [llength [lindex $rowidlist $row]] |
5857 | set olds [lindex $parentlist $row] | |
5858 | if {$olds ne {}} { | |
5859 | set nextids [lindex $rowidlist [expr {$row + 1}]] | |
5860 | foreach p $olds { | |
5861 | set i [lsearch -exact $nextids $p] | |
5862 | if {$i > $rmx} { | |
5863 | set rmx $i | |
5864 | } | |
5865 | } | |
9f1afe05 | 5866 | } |
322a8cc9 | 5867 | set xt [xc $row $rmx] |
9f1afe05 PM |
5868 | set rowtextx($row) $xt |
5869 | set idpos($id) [list $x $xt $y] | |
5870 | if {[info exists idtags($id)] || [info exists idheads($id)] | |
5871 | || [info exists idotherrefs($id)]} { | |
5872 | set xt [drawtags $id $x $xt $y] | |
5873 | } | |
5874 | set headline [lindex $commitinfo($id) 0] | |
5875 | set name [lindex $commitinfo($id) 1] | |
5876 | set date [lindex $commitinfo($id) 2] | |
5877 | set date [formatdate $date] | |
9c311b32 PM |
5878 | set font mainfont |
5879 | set nfont mainfont | |
476ca63d | 5880 | set isbold [ishighlighted $id] |
908c3585 | 5881 | if {$isbold > 0} { |
28593d3f | 5882 | lappend boldids $id |
9c311b32 | 5883 | set font mainfontbold |
908c3585 | 5884 | if {$isbold > 1} { |
28593d3f | 5885 | lappend boldnameids $id |
9c311b32 | 5886 | set nfont mainfontbold |
908c3585 | 5887 | } |
da7c24dd | 5888 | } |
28593d3f PM |
5889 | set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \ |
5890 | -text $headline -font $font -tags text] | |
5891 | $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id" | |
5892 | set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \ | |
5893 | -text $name -font $nfont -tags text] | |
5894 | set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ | |
5895 | -text $date -font mainfont -tags text] | |
94b4a69f | 5896 | if {$selectedline == $row} { |
28593d3f | 5897 | make_secsel $id |
0380081c | 5898 | } |
b9fdba7f PM |
5899 | if {[info exists markedid] && $markedid eq $id} { |
5900 | make_idmark $id | |
5901 | } | |
9c311b32 | 5902 | set xr [expr {$xt + [font measure $font $headline]}] |
be0cd098 PM |
5903 | if {$xr > $canvxmax} { |
5904 | set canvxmax $xr | |
5905 | setcanvscroll | |
5906 | } | |
9f1afe05 PM |
5907 | } |
5908 | ||
5909 | proc drawcmitrow {row} { | |
0380081c | 5910 | global displayorder rowidlist nrows_drawn |
005a2f4e | 5911 | global iddrawn markingmatches |
7fcc92bf | 5912 | global commitinfo numcommits |
687c8765 | 5913 | global filehighlight fhighlights findpattern nhighlights |
908c3585 | 5914 | global hlview vhighlights |
164ff275 | 5915 | global highlight_related rhighlights |
9f1afe05 | 5916 | |
8f7d0cec | 5917 | if {$row >= $numcommits} return |
9f1afe05 PM |
5918 | |
5919 | set id [lindex $displayorder $row] | |
476ca63d | 5920 | if {[info exists hlview] && ![info exists vhighlights($id)]} { |
908c3585 PM |
5921 | askvhighlight $row $id |
5922 | } | |
476ca63d | 5923 | if {[info exists filehighlight] && ![info exists fhighlights($id)]} { |
908c3585 PM |
5924 | askfilehighlight $row $id |
5925 | } | |
476ca63d | 5926 | if {$findpattern ne {} && ![info exists nhighlights($id)]} { |
60f7a7dc | 5927 | askfindhighlight $row $id |
908c3585 | 5928 | } |
476ca63d | 5929 | if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} { |
164ff275 PM |
5930 | askrelhighlight $row $id |
5931 | } | |
005a2f4e PM |
5932 | if {![info exists iddrawn($id)]} { |
5933 | set col [lsearch -exact [lindex $rowidlist $row] $id] | |
5934 | if {$col < 0} { | |
5935 | puts "oops, row $row id $id not in list" | |
5936 | return | |
5937 | } | |
5938 | if {![info exists commitinfo($id)]} { | |
5939 | getcommit $id | |
5940 | } | |
5941 | assigncolor $id | |
5942 | drawcmittext $id $row $col | |
5943 | set iddrawn($id) 1 | |
0380081c | 5944 | incr nrows_drawn |
9f1afe05 | 5945 | } |
005a2f4e PM |
5946 | if {$markingmatches} { |
5947 | markrowmatches $row $id | |
9f1afe05 | 5948 | } |
9f1afe05 PM |
5949 | } |
5950 | ||
322a8cc9 | 5951 | proc drawcommits {row {endrow {}}} { |
0380081c | 5952 | global numcommits iddrawn displayorder curview need_redisplay |
f5f3c2e2 | 5953 | global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn |
9f1afe05 | 5954 | |
9f1afe05 PM |
5955 | if {$row < 0} { |
5956 | set row 0 | |
5957 | } | |
322a8cc9 PM |
5958 | if {$endrow eq {}} { |
5959 | set endrow $row | |
5960 | } | |
9f1afe05 PM |
5961 | if {$endrow >= $numcommits} { |
5962 | set endrow [expr {$numcommits - 1}] | |
5963 | } | |
322a8cc9 | 5964 | |
0380081c PM |
5965 | set rl1 [expr {$row - $downarrowlen - 3}] |
5966 | if {$rl1 < 0} { | |
5967 | set rl1 0 | |
5968 | } | |
5969 | set ro1 [expr {$row - 3}] | |
5970 | if {$ro1 < 0} { | |
5971 | set ro1 0 | |
5972 | } | |
5973 | set r2 [expr {$endrow + $uparrowlen + 3}] | |
5974 | if {$r2 > $numcommits} { | |
5975 | set r2 $numcommits | |
5976 | } | |
5977 | for {set r $rl1} {$r < $r2} {incr r} { | |
f5f3c2e2 | 5978 | if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} { |
0380081c PM |
5979 | if {$rl1 < $r} { |
5980 | layoutrows $rl1 $r | |
5981 | } | |
5982 | set rl1 [expr {$r + 1}] | |
5983 | } | |
5984 | } | |
5985 | if {$rl1 < $r} { | |
5986 | layoutrows $rl1 $r | |
5987 | } | |
5988 | optimize_rows $ro1 0 $r2 | |
5989 | if {$need_redisplay || $nrows_drawn > 2000} { | |
5990 | clear_display | |
0380081c PM |
5991 | } |
5992 | ||
322a8cc9 PM |
5993 | # make the lines join to already-drawn rows either side |
5994 | set r [expr {$row - 1}] | |
5995 | if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} { | |
5996 | set r $row | |
5997 | } | |
5998 | set er [expr {$endrow + 1}] | |
5999 | if {$er >= $numcommits || | |
6000 | ![info exists iddrawn([lindex $displayorder $er])]} { | |
6001 | set er $endrow | |
6002 | } | |
6003 | for {} {$r <= $er} {incr r} { | |
6004 | set id [lindex $displayorder $r] | |
6005 | set wasdrawn [info exists iddrawn($id)] | |
4fb0fa19 | 6006 | drawcmitrow $r |
322a8cc9 PM |
6007 | if {$r == $er} break |
6008 | set nextid [lindex $displayorder [expr {$r + 1}]] | |
e5ef6f95 | 6009 | if {$wasdrawn && [info exists iddrawn($nextid)]} continue |
322a8cc9 PM |
6010 | drawparentlinks $id $r |
6011 | ||
322a8cc9 PM |
6012 | set rowids [lindex $rowidlist $r] |
6013 | foreach lid $rowids { | |
6014 | if {$lid eq {}} continue | |
e5ef6f95 | 6015 | if {[info exists lineend($lid)] && $lineend($lid) > $r} continue |
322a8cc9 PM |
6016 | if {$lid eq $id} { |
6017 | # see if this is the first child of any of its parents | |
6018 | foreach p [lindex $parentlist $r] { | |
6019 | if {[lsearch -exact $rowids $p] < 0} { | |
6020 | # make this line extend up to the child | |
e5ef6f95 | 6021 | set lineend($p) [drawlineseg $p $r $er 0] |
322a8cc9 PM |
6022 | } |
6023 | } | |
e5ef6f95 PM |
6024 | } else { |
6025 | set lineend($lid) [drawlineseg $lid $r $er 1] | |
322a8cc9 PM |
6026 | } |
6027 | } | |
9f1afe05 PM |
6028 | } |
6029 | } | |
6030 | ||
7fcc92bf PM |
6031 | proc undolayout {row} { |
6032 | global uparrowlen mingaplen downarrowlen | |
6033 | global rowidlist rowisopt rowfinal need_redisplay | |
6034 | ||
6035 | set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}] | |
6036 | if {$r < 0} { | |
6037 | set r 0 | |
6038 | } | |
6039 | if {[llength $rowidlist] > $r} { | |
6040 | incr r -1 | |
6041 | set rowidlist [lrange $rowidlist 0 $r] | |
6042 | set rowfinal [lrange $rowfinal 0 $r] | |
6043 | set rowisopt [lrange $rowisopt 0 $r] | |
6044 | set need_redisplay 1 | |
6045 | run drawvisible | |
6046 | } | |
6047 | } | |
6048 | ||
31c0eaa8 PM |
6049 | proc drawvisible {} { |
6050 | global canv linespc curview vrowmod selectedline targetrow targetid | |
42a671fc | 6051 | global need_redisplay cscroll numcommits |
322a8cc9 | 6052 | |
31c0eaa8 | 6053 | set fs [$canv yview] |
322a8cc9 | 6054 | set ymax [lindex [$canv cget -scrollregion] 3] |
5a7f577d | 6055 | if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return |
31c0eaa8 PM |
6056 | set f0 [lindex $fs 0] |
6057 | set f1 [lindex $fs 1] | |
322a8cc9 | 6058 | set y0 [expr {int($f0 * $ymax)}] |
322a8cc9 | 6059 | set y1 [expr {int($f1 * $ymax)}] |
31c0eaa8 PM |
6060 | |
6061 | if {[info exists targetid]} { | |
42a671fc PM |
6062 | if {[commitinview $targetid $curview]} { |
6063 | set r [rowofcommit $targetid] | |
6064 | if {$r != $targetrow} { | |
6065 | # Fix up the scrollregion and change the scrolling position | |
6066 | # now that our target row has moved. | |
6067 | set diff [expr {($r - $targetrow) * $linespc}] | |
6068 | set targetrow $r | |
6069 | setcanvscroll | |
6070 | set ymax [lindex [$canv cget -scrollregion] 3] | |
6071 | incr y0 $diff | |
6072 | incr y1 $diff | |
6073 | set f0 [expr {$y0 / $ymax}] | |
6074 | set f1 [expr {$y1 / $ymax}] | |
6075 | allcanvs yview moveto $f0 | |
6076 | $cscroll set $f0 $f1 | |
6077 | set need_redisplay 1 | |
6078 | } | |
6079 | } else { | |
6080 | unset targetid | |
31c0eaa8 PM |
6081 | } |
6082 | } | |
6083 | ||
6084 | set row [expr {int(($y0 - 3) / $linespc) - 1}] | |
322a8cc9 | 6085 | set endrow [expr {int(($y1 - 3) / $linespc) + 1}] |
31c0eaa8 PM |
6086 | if {$endrow >= $vrowmod($curview)} { |
6087 | update_arcrows $curview | |
6088 | } | |
94b4a69f | 6089 | if {$selectedline ne {} && |
31c0eaa8 PM |
6090 | $row <= $selectedline && $selectedline <= $endrow} { |
6091 | set targetrow $selectedline | |
ac1276ab | 6092 | } elseif {[info exists targetid]} { |
31c0eaa8 PM |
6093 | set targetrow [expr {int(($row + $endrow) / 2)}] |
6094 | } | |
ac1276ab PM |
6095 | if {[info exists targetrow]} { |
6096 | if {$targetrow >= $numcommits} { | |
6097 | set targetrow [expr {$numcommits - 1}] | |
6098 | } | |
6099 | set targetid [commitonrow $targetrow] | |
42a671fc | 6100 | } |
322a8cc9 PM |
6101 | drawcommits $row $endrow |
6102 | } | |
6103 | ||
9f1afe05 | 6104 | proc clear_display {} { |
0380081c | 6105 | global iddrawn linesegs need_redisplay nrows_drawn |
164ff275 | 6106 | global vhighlights fhighlights nhighlights rhighlights |
28593d3f | 6107 | global linehtag linentag linedtag boldids boldnameids |
9f1afe05 PM |
6108 | |
6109 | allcanvs delete all | |
6110 | catch {unset iddrawn} | |
322a8cc9 | 6111 | catch {unset linesegs} |
94503a66 PM |
6112 | catch {unset linehtag} |
6113 | catch {unset linentag} | |
6114 | catch {unset linedtag} | |
28593d3f PM |
6115 | set boldids {} |
6116 | set boldnameids {} | |
908c3585 PM |
6117 | catch {unset vhighlights} |
6118 | catch {unset fhighlights} | |
6119 | catch {unset nhighlights} | |
164ff275 | 6120 | catch {unset rhighlights} |
0380081c PM |
6121 | set need_redisplay 0 |
6122 | set nrows_drawn 0 | |
9f1afe05 PM |
6123 | } |
6124 | ||
50b44ece | 6125 | proc findcrossings {id} { |
6e8c8707 | 6126 | global rowidlist parentlist numcommits displayorder |
50b44ece PM |
6127 | |
6128 | set cross {} | |
6129 | set ccross {} | |
6130 | foreach {s e} [rowranges $id] { | |
6131 | if {$e >= $numcommits} { | |
6132 | set e [expr {$numcommits - 1}] | |
50b44ece | 6133 | } |
d94f8cd6 | 6134 | if {$e <= $s} continue |
50b44ece | 6135 | for {set row $e} {[incr row -1] >= $s} {} { |
6e8c8707 PM |
6136 | set x [lsearch -exact [lindex $rowidlist $row] $id] |
6137 | if {$x < 0} break | |
50b44ece PM |
6138 | set olds [lindex $parentlist $row] |
6139 | set kid [lindex $displayorder $row] | |
6140 | set kidx [lsearch -exact [lindex $rowidlist $row] $kid] | |
6141 | if {$kidx < 0} continue | |
6142 | set nextrow [lindex $rowidlist [expr {$row + 1}]] | |
6143 | foreach p $olds { | |
6144 | set px [lsearch -exact $nextrow $p] | |
6145 | if {$px < 0} continue | |
6146 | if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} { | |
6147 | if {[lsearch -exact $ccross $p] >= 0} continue | |
6148 | if {$x == $px + ($kidx < $px? -1: 1)} { | |
6149 | lappend ccross $p | |
6150 | } elseif {[lsearch -exact $cross $p] < 0} { | |
6151 | lappend cross $p | |
6152 | } | |
6153 | } | |
6154 | } | |
50b44ece PM |
6155 | } |
6156 | } | |
6157 | return [concat $ccross {{}} $cross] | |
6158 | } | |
6159 | ||
e5c2d856 | 6160 | proc assigncolor {id} { |
aa81d974 | 6161 | global colormap colors nextcolor |
7fcc92bf | 6162 | global parents children children curview |
6c20ff34 | 6163 | |
418c4c7b | 6164 | if {[info exists colormap($id)]} return |
e5c2d856 | 6165 | set ncolors [llength $colors] |
da7c24dd PM |
6166 | if {[info exists children($curview,$id)]} { |
6167 | set kids $children($curview,$id) | |
79b2c75e PM |
6168 | } else { |
6169 | set kids {} | |
6170 | } | |
6171 | if {[llength $kids] == 1} { | |
6172 | set child [lindex $kids 0] | |
9ccbdfbf | 6173 | if {[info exists colormap($child)] |
7fcc92bf | 6174 | && [llength $parents($curview,$child)] == 1} { |
9ccbdfbf PM |
6175 | set colormap($id) $colormap($child) |
6176 | return | |
e5c2d856 | 6177 | } |
9ccbdfbf PM |
6178 | } |
6179 | set badcolors {} | |
50b44ece PM |
6180 | set origbad {} |
6181 | foreach x [findcrossings $id] { | |
6182 | if {$x eq {}} { | |
6183 | # delimiter between corner crossings and other crossings | |
6184 | if {[llength $badcolors] >= $ncolors - 1} break | |
6185 | set origbad $badcolors | |
e5c2d856 | 6186 | } |
50b44ece PM |
6187 | if {[info exists colormap($x)] |
6188 | && [lsearch -exact $badcolors $colormap($x)] < 0} { | |
6189 | lappend badcolors $colormap($x) | |
6c20ff34 PM |
6190 | } |
6191 | } | |
50b44ece PM |
6192 | if {[llength $badcolors] >= $ncolors} { |
6193 | set badcolors $origbad | |
9ccbdfbf | 6194 | } |
50b44ece | 6195 | set origbad $badcolors |
6c20ff34 | 6196 | if {[llength $badcolors] < $ncolors - 1} { |
79b2c75e | 6197 | foreach child $kids { |
6c20ff34 PM |
6198 | if {[info exists colormap($child)] |
6199 | && [lsearch -exact $badcolors $colormap($child)] < 0} { | |
6200 | lappend badcolors $colormap($child) | |
6201 | } | |
7fcc92bf | 6202 | foreach p $parents($curview,$child) { |
79b2c75e PM |
6203 | if {[info exists colormap($p)] |
6204 | && [lsearch -exact $badcolors $colormap($p)] < 0} { | |
6205 | lappend badcolors $colormap($p) | |
6c20ff34 PM |
6206 | } |
6207 | } | |
6208 | } | |
6209 | if {[llength $badcolors] >= $ncolors} { | |
6210 | set badcolors $origbad | |
6211 | } | |
9ccbdfbf PM |
6212 | } |
6213 | for {set i 0} {$i <= $ncolors} {incr i} { | |
6214 | set c [lindex $colors $nextcolor] | |
6215 | if {[incr nextcolor] >= $ncolors} { | |
6216 | set nextcolor 0 | |
e5c2d856 | 6217 | } |
9ccbdfbf | 6218 | if {[lsearch -exact $badcolors $c]} break |
e5c2d856 | 6219 | } |
9ccbdfbf | 6220 | set colormap($id) $c |
e5c2d856 PM |
6221 | } |
6222 | ||
a823a911 PM |
6223 | proc bindline {t id} { |
6224 | global canv | |
6225 | ||
a823a911 PM |
6226 | $canv bind $t <Enter> "lineenter %x %y $id" |
6227 | $canv bind $t <Motion> "linemotion %x %y $id" | |
6228 | $canv bind $t <Leave> "lineleave $id" | |
fa4da7b3 | 6229 | $canv bind $t <Button-1> "lineclick %x %y $id 1" |
a823a911 PM |
6230 | } |
6231 | ||
bdbfbe3d | 6232 | proc drawtags {id x xt y1} { |
8a48571c | 6233 | global idtags idheads idotherrefs mainhead |
bdbfbe3d | 6234 | global linespc lthickness |
d277e89f | 6235 | global canv rowtextx curview fgcolor bgcolor ctxbut |
bdbfbe3d PM |
6236 | |
6237 | set marks {} | |
6238 | set ntags 0 | |
f1d83ba3 | 6239 | set nheads 0 |
bdbfbe3d PM |
6240 | if {[info exists idtags($id)]} { |
6241 | set marks $idtags($id) | |
6242 | set ntags [llength $marks] | |
6243 | } | |
6244 | if {[info exists idheads($id)]} { | |
6245 | set marks [concat $marks $idheads($id)] | |
f1d83ba3 PM |
6246 | set nheads [llength $idheads($id)] |
6247 | } | |
6248 | if {[info exists idotherrefs($id)]} { | |
6249 | set marks [concat $marks $idotherrefs($id)] | |
bdbfbe3d PM |
6250 | } |
6251 | if {$marks eq {}} { | |
6252 | return $xt | |
6253 | } | |
6254 | ||
6255 | set delta [expr {int(0.5 * ($linespc - $lthickness))}] | |
2ed49d54 JH |
6256 | set yt [expr {$y1 - 0.5 * $linespc}] |
6257 | set yb [expr {$yt + $linespc - 1}] | |
bdbfbe3d PM |
6258 | set xvals {} |
6259 | set wvals {} | |
8a48571c | 6260 | set i -1 |
bdbfbe3d | 6261 | foreach tag $marks { |
8a48571c PM |
6262 | incr i |
6263 | if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} { | |
9c311b32 | 6264 | set wid [font measure mainfontbold $tag] |
8a48571c | 6265 | } else { |
9c311b32 | 6266 | set wid [font measure mainfont $tag] |
8a48571c | 6267 | } |
bdbfbe3d PM |
6268 | lappend xvals $xt |
6269 | lappend wvals $wid | |
6270 | set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}] | |
6271 | } | |
6272 | set t [$canv create line $x $y1 [lindex $xvals end] $y1 \ | |
6273 | -width $lthickness -fill black -tags tag.$id] | |
6274 | $canv lower $t | |
6275 | foreach tag $marks x $xvals wid $wvals { | |
2ed49d54 JH |
6276 | set xl [expr {$x + $delta}] |
6277 | set xr [expr {$x + $delta + $wid + $lthickness}] | |
9c311b32 | 6278 | set font mainfont |
bdbfbe3d PM |
6279 | if {[incr ntags -1] >= 0} { |
6280 | # draw a tag | |
2ed49d54 JH |
6281 | set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \ |
6282 | $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \ | |
106288cb PM |
6283 | -width 1 -outline black -fill yellow -tags tag.$id] |
6284 | $canv bind $t <1> [list showtag $tag 1] | |
7fcc92bf | 6285 | set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}] |
bdbfbe3d | 6286 | } else { |
f1d83ba3 PM |
6287 | # draw a head or other ref |
6288 | if {[incr nheads -1] >= 0} { | |
6289 | set col green | |
8a48571c | 6290 | if {$tag eq $mainhead} { |
9c311b32 | 6291 | set font mainfontbold |
8a48571c | 6292 | } |
f1d83ba3 PM |
6293 | } else { |
6294 | set col "#ddddff" | |
6295 | } | |
2ed49d54 | 6296 | set xl [expr {$xl - $delta/2}] |
bdbfbe3d | 6297 | $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \ |
f1d83ba3 | 6298 | -width 1 -outline black -fill $col -tags tag.$id |
a970fcf2 | 6299 | if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} { |
9c311b32 | 6300 | set rwid [font measure mainfont $remoteprefix] |
a970fcf2 JW |
6301 | set xi [expr {$x + 1}] |
6302 | set yti [expr {$yt + 1}] | |
6303 | set xri [expr {$x + $rwid}] | |
6304 | $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \ | |
6305 | -width 0 -fill "#ffddaa" -tags tag.$id | |
6306 | } | |
bdbfbe3d | 6307 | } |
f8a2c0d1 | 6308 | set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \ |
8a48571c | 6309 | -font $font -tags [list tag.$id text]] |
106288cb PM |
6310 | if {$ntags >= 0} { |
6311 | $canv bind $t <1> [list showtag $tag 1] | |
10299152 | 6312 | } elseif {$nheads >= 0} { |
d277e89f | 6313 | $canv bind $t $ctxbut [list headmenu %X %Y $id $tag] |
106288cb | 6314 | } |
bdbfbe3d PM |
6315 | } |
6316 | return $xt | |
6317 | } | |
6318 | ||
8d858d1a PM |
6319 | proc xcoord {i level ln} { |
6320 | global canvx0 xspc1 xspc2 | |
6321 | ||
6322 | set x [expr {$canvx0 + $i * $xspc1($ln)}] | |
6323 | if {$i > 0 && $i == $level} { | |
6324 | set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}] | |
6325 | } elseif {$i > $level} { | |
6326 | set x [expr {$x + $xspc2 - $xspc1($ln)}] | |
6327 | } | |
6328 | return $x | |
6329 | } | |
9ccbdfbf | 6330 | |
098dd8a3 | 6331 | proc show_status {msg} { |
9c311b32 | 6332 | global canv fgcolor |
098dd8a3 PM |
6333 | |
6334 | clear_display | |
9c311b32 | 6335 | $canv create text 3 3 -anchor nw -text $msg -font mainfont \ |
f8a2c0d1 | 6336 | -tags text -fill $fgcolor |
098dd8a3 PM |
6337 | } |
6338 | ||
94a2eede PM |
6339 | # Don't change the text pane cursor if it is currently the hand cursor, |
6340 | # showing that we are over a sha1 ID link. | |
6341 | proc settextcursor {c} { | |
6342 | global ctext curtextcursor | |
6343 | ||
6344 | if {[$ctext cget -cursor] == $curtextcursor} { | |
6345 | $ctext config -cursor $c | |
6346 | } | |
6347 | set curtextcursor $c | |
9ccbdfbf PM |
6348 | } |
6349 | ||
a137a90f PM |
6350 | proc nowbusy {what {name {}}} { |
6351 | global isbusy busyname statusw | |
da7c24dd PM |
6352 | |
6353 | if {[array names isbusy] eq {}} { | |
6354 | . config -cursor watch | |
6355 | settextcursor watch | |
6356 | } | |
6357 | set isbusy($what) 1 | |
a137a90f PM |
6358 | set busyname($what) $name |
6359 | if {$name ne {}} { | |
6360 | $statusw conf -text $name | |
6361 | } | |
da7c24dd PM |
6362 | } |
6363 | ||
6364 | proc notbusy {what} { | |
a137a90f | 6365 | global isbusy maincursor textcursor busyname statusw |
da7c24dd | 6366 | |
a137a90f PM |
6367 | catch { |
6368 | unset isbusy($what) | |
6369 | if {$busyname($what) ne {} && | |
6370 | [$statusw cget -text] eq $busyname($what)} { | |
6371 | $statusw conf -text {} | |
6372 | } | |
6373 | } | |
da7c24dd PM |
6374 | if {[array names isbusy] eq {}} { |
6375 | . config -cursor $maincursor | |
6376 | settextcursor $textcursor | |
6377 | } | |
6378 | } | |
6379 | ||
df3d83b1 | 6380 | proc findmatches {f} { |
4fb0fa19 | 6381 | global findtype findstring |
b007ee20 | 6382 | if {$findtype == [mc "Regexp"]} { |
4fb0fa19 | 6383 | set matches [regexp -indices -all -inline $findstring $f] |
df3d83b1 | 6384 | } else { |
4fb0fa19 | 6385 | set fs $findstring |
b007ee20 | 6386 | if {$findtype == [mc "IgnCase"]} { |
4fb0fa19 PM |
6387 | set f [string tolower $f] |
6388 | set fs [string tolower $fs] | |
df3d83b1 PM |
6389 | } |
6390 | set matches {} | |
6391 | set i 0 | |
4fb0fa19 PM |
6392 | set l [string length $fs] |
6393 | while {[set j [string first $fs $f $i]] >= 0} { | |
6394 | lappend matches [list $j [expr {$j+$l-1}]] | |
6395 | set i [expr {$j + $l}] | |
df3d83b1 PM |
6396 | } |
6397 | } | |
6398 | return $matches | |
6399 | } | |
6400 | ||
cca5d946 | 6401 | proc dofind {{dirn 1} {wrap 1}} { |
4fb0fa19 | 6402 | global findstring findstartline findcurline selectedline numcommits |
cca5d946 | 6403 | global gdttype filehighlight fh_serial find_dirn findallowwrap |
b74fd579 | 6404 | |
cca5d946 PM |
6405 | if {[info exists find_dirn]} { |
6406 | if {$find_dirn == $dirn} return | |
6407 | stopfinding | |
6408 | } | |
df3d83b1 | 6409 | focus . |
4fb0fa19 | 6410 | if {$findstring eq {} || $numcommits == 0} return |
94b4a69f | 6411 | if {$selectedline eq {}} { |
cca5d946 | 6412 | set findstartline [lindex [visiblerows] [expr {$dirn < 0}]] |
98f350e5 | 6413 | } else { |
4fb0fa19 | 6414 | set findstartline $selectedline |
98f350e5 | 6415 | } |
4fb0fa19 | 6416 | set findcurline $findstartline |
b007ee20 CS |
6417 | nowbusy finding [mc "Searching"] |
6418 | if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} { | |
687c8765 PM |
6419 | after cancel do_file_hl $fh_serial |
6420 | do_file_hl $fh_serial | |
98f350e5 | 6421 | } |
cca5d946 PM |
6422 | set find_dirn $dirn |
6423 | set findallowwrap $wrap | |
6424 | run findmore | |
4fb0fa19 PM |
6425 | } |
6426 | ||
bb3edc8b PM |
6427 | proc stopfinding {} { |
6428 | global find_dirn findcurline fprogcoord | |
4fb0fa19 | 6429 | |
bb3edc8b PM |
6430 | if {[info exists find_dirn]} { |
6431 | unset find_dirn | |
6432 | unset findcurline | |
6433 | notbusy finding | |
6434 | set fprogcoord 0 | |
6435 | adjustprogress | |
4fb0fa19 | 6436 | } |
8a897742 | 6437 | stopblaming |
4fb0fa19 PM |
6438 | } |
6439 | ||
6440 | proc findmore {} { | |
687c8765 | 6441 | global commitdata commitinfo numcommits findpattern findloc |
7fcc92bf | 6442 | global findstartline findcurline findallowwrap |
bb3edc8b | 6443 | global find_dirn gdttype fhighlights fprogcoord |
cd2bcae7 | 6444 | global curview varcorder vrownum varccommits vrowmod |
4fb0fa19 | 6445 | |
bb3edc8b | 6446 | if {![info exists find_dirn]} { |
4fb0fa19 PM |
6447 | return 0 |
6448 | } | |
b007ee20 | 6449 | set fldtypes [list [mc "Headline"] [mc "Author"] [mc "Date"] [mc "Committer"] [mc "CDate"] [mc "Comments"]] |
4fb0fa19 | 6450 | set l $findcurline |
cca5d946 PM |
6451 | set moretodo 0 |
6452 | if {$find_dirn > 0} { | |
6453 | incr l | |
6454 | if {$l >= $numcommits} { | |
6455 | set l 0 | |
6456 | } | |
6457 | if {$l <= $findstartline} { | |
6458 | set lim [expr {$findstartline + 1}] | |
6459 | } else { | |
6460 | set lim $numcommits | |
6461 | set moretodo $findallowwrap | |
8ed16484 | 6462 | } |
4fb0fa19 | 6463 | } else { |
cca5d946 PM |
6464 | if {$l == 0} { |
6465 | set l $numcommits | |
98f350e5 | 6466 | } |
cca5d946 PM |
6467 | incr l -1 |
6468 | if {$l >= $findstartline} { | |
6469 | set lim [expr {$findstartline - 1}] | |
bb3edc8b | 6470 | } else { |
cca5d946 PM |
6471 | set lim -1 |
6472 | set moretodo $findallowwrap | |
bb3edc8b | 6473 | } |
687c8765 | 6474 | } |
cca5d946 PM |
6475 | set n [expr {($lim - $l) * $find_dirn}] |
6476 | if {$n > 500} { | |
6477 | set n 500 | |
6478 | set moretodo 1 | |
4fb0fa19 | 6479 | } |
cd2bcae7 PM |
6480 | if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} { |
6481 | update_arcrows $curview | |
6482 | } | |
687c8765 PM |
6483 | set found 0 |
6484 | set domore 1 | |
7fcc92bf PM |
6485 | set ai [bsearch $vrownum($curview) $l] |
6486 | set a [lindex $varcorder($curview) $ai] | |
6487 | set arow [lindex $vrownum($curview) $ai] | |
6488 | set ids [lindex $varccommits($curview,$a)] | |
6489 | set arowend [expr {$arow + [llength $ids]}] | |
b007ee20 | 6490 | if {$gdttype eq [mc "containing:"]} { |
cca5d946 | 6491 | for {} {$n > 0} {incr n -1; incr l $find_dirn} { |
7fcc92bf PM |
6492 | if {$l < $arow || $l >= $arowend} { |
6493 | incr ai $find_dirn | |
6494 | set a [lindex $varcorder($curview) $ai] | |
6495 | set arow [lindex $vrownum($curview) $ai] | |
6496 | set ids [lindex $varccommits($curview,$a)] | |
6497 | set arowend [expr {$arow + [llength $ids]}] | |
6498 | } | |
6499 | set id [lindex $ids [expr {$l - $arow}]] | |
cca5d946 | 6500 | # shouldn't happen unless git log doesn't give all the commits... |
7fcc92bf PM |
6501 | if {![info exists commitdata($id)] || |
6502 | ![doesmatch $commitdata($id)]} { | |
6503 | continue | |
6504 | } | |
687c8765 PM |
6505 | if {![info exists commitinfo($id)]} { |
6506 | getcommit $id | |
6507 | } | |
6508 | set info $commitinfo($id) | |
6509 | foreach f $info ty $fldtypes { | |
b007ee20 | 6510 | if {($findloc eq [mc "All fields"] || $findloc eq $ty) && |
687c8765 PM |
6511 | [doesmatch $f]} { |
6512 | set found 1 | |
6513 | break | |
6514 | } | |
6515 | } | |
6516 | if {$found} break | |
4fb0fa19 | 6517 | } |
687c8765 | 6518 | } else { |
cca5d946 | 6519 | for {} {$n > 0} {incr n -1; incr l $find_dirn} { |
7fcc92bf PM |
6520 | if {$l < $arow || $l >= $arowend} { |
6521 | incr ai $find_dirn | |
6522 | set a [lindex $varcorder($curview) $ai] | |
6523 | set arow [lindex $vrownum($curview) $ai] | |
6524 | set ids [lindex $varccommits($curview,$a)] | |
6525 | set arowend [expr {$arow + [llength $ids]}] | |
6526 | } | |
6527 | set id [lindex $ids [expr {$l - $arow}]] | |
476ca63d PM |
6528 | if {![info exists fhighlights($id)]} { |
6529 | # this sets fhighlights($id) to -1 | |
687c8765 | 6530 | askfilehighlight $l $id |
cd2bcae7 | 6531 | } |
476ca63d | 6532 | if {$fhighlights($id) > 0} { |
cd2bcae7 PM |
6533 | set found $domore |
6534 | break | |
6535 | } | |
476ca63d | 6536 | if {$fhighlights($id) < 0} { |
687c8765 PM |
6537 | if {$domore} { |
6538 | set domore 0 | |
cca5d946 | 6539 | set findcurline [expr {$l - $find_dirn}] |
687c8765 | 6540 | } |
98f350e5 PM |
6541 | } |
6542 | } | |
6543 | } | |
cca5d946 | 6544 | if {$found || ($domore && !$moretodo)} { |
4fb0fa19 | 6545 | unset findcurline |
687c8765 | 6546 | unset find_dirn |
4fb0fa19 | 6547 | notbusy finding |
bb3edc8b PM |
6548 | set fprogcoord 0 |
6549 | adjustprogress | |
6550 | if {$found} { | |
6551 | findselectline $l | |
6552 | } else { | |
6553 | bell | |
6554 | } | |
4fb0fa19 | 6555 | return 0 |
df3d83b1 | 6556 | } |
687c8765 PM |
6557 | if {!$domore} { |
6558 | flushhighlights | |
bb3edc8b | 6559 | } else { |
cca5d946 | 6560 | set findcurline [expr {$l - $find_dirn}] |
687c8765 | 6561 | } |
cca5d946 | 6562 | set n [expr {($findcurline - $findstartline) * $find_dirn - 1}] |
bb3edc8b PM |
6563 | if {$n < 0} { |
6564 | incr n $numcommits | |
df3d83b1 | 6565 | } |
bb3edc8b PM |
6566 | set fprogcoord [expr {$n * 1.0 / $numcommits}] |
6567 | adjustprogress | |
6568 | return $domore | |
df3d83b1 PM |
6569 | } |
6570 | ||
6571 | proc findselectline {l} { | |
687c8765 | 6572 | global findloc commentend ctext findcurline markingmatches gdttype |
005a2f4e | 6573 | |
8b39e04f | 6574 | set markingmatches [expr {$gdttype eq [mc "containing:"]}] |
005a2f4e | 6575 | set findcurline $l |
d698206c | 6576 | selectline $l 1 |
8b39e04f PM |
6577 | if {$markingmatches && |
6578 | ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} { | |
df3d83b1 PM |
6579 | # highlight the matches in the comments |
6580 | set f [$ctext get 1.0 $commentend] | |
6581 | set matches [findmatches $f] | |
6582 | foreach match $matches { | |
6583 | set start [lindex $match 0] | |
2ed49d54 | 6584 | set end [expr {[lindex $match 1] + 1}] |
df3d83b1 PM |
6585 | $ctext tag add found "1.0 + $start c" "1.0 + $end c" |
6586 | } | |
98f350e5 | 6587 | } |
005a2f4e | 6588 | drawvisible |
98f350e5 PM |
6589 | } |
6590 | ||
4fb0fa19 | 6591 | # mark the bits of a headline or author that match a find string |
005a2f4e PM |
6592 | proc markmatches {canv l str tag matches font row} { |
6593 | global selectedline | |
6594 | ||
98f350e5 PM |
6595 | set bbox [$canv bbox $tag] |
6596 | set x0 [lindex $bbox 0] | |
6597 | set y0 [lindex $bbox 1] | |
6598 | set y1 [lindex $bbox 3] | |
6599 | foreach match $matches { | |
6600 | set start [lindex $match 0] | |
6601 | set end [lindex $match 1] | |
6602 | if {$start > $end} continue | |
2ed49d54 JH |
6603 | set xoff [font measure $font [string range $str 0 [expr {$start-1}]]] |
6604 | set xlen [font measure $font [string range $str 0 [expr {$end}]]] | |
6605 | set t [$canv create rect [expr {$x0+$xoff}] $y0 \ | |
6606 | [expr {$x0+$xlen+2}] $y1 \ | |
4fb0fa19 | 6607 | -outline {} -tags [list match$l matches] -fill yellow] |
98f350e5 | 6608 | $canv lower $t |
94b4a69f | 6609 | if {$row == $selectedline} { |
005a2f4e PM |
6610 | $canv raise $t secsel |
6611 | } | |
98f350e5 PM |
6612 | } |
6613 | } | |
6614 | ||
6615 | proc unmarkmatches {} { | |
bb3edc8b | 6616 | global markingmatches |
4fb0fa19 | 6617 | |
98f350e5 | 6618 | allcanvs delete matches |
4fb0fa19 | 6619 | set markingmatches 0 |
bb3edc8b | 6620 | stopfinding |
98f350e5 PM |
6621 | } |
6622 | ||
c8dfbcf9 | 6623 | proc selcanvline {w x y} { |
fa4da7b3 | 6624 | global canv canvy0 ctext linespc |
9f1afe05 | 6625 | global rowtextx |
1db95b00 | 6626 | set ymax [lindex [$canv cget -scrollregion] 3] |
cfb4563c | 6627 | if {$ymax == {}} return |
1db95b00 PM |
6628 | set yfrac [lindex [$canv yview] 0] |
6629 | set y [expr {$y + $yfrac * $ymax}] | |
6630 | set l [expr {int(($y - $canvy0) / $linespc + 0.5)}] | |
6631 | if {$l < 0} { | |
6632 | set l 0 | |
6633 | } | |
c8dfbcf9 | 6634 | if {$w eq $canv} { |
fc2a256f PM |
6635 | set xmax [lindex [$canv cget -scrollregion] 2] |
6636 | set xleft [expr {[lindex [$canv xview] 0] * $xmax}] | |
6637 | if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return | |
c8dfbcf9 | 6638 | } |
98f350e5 | 6639 | unmarkmatches |
d698206c | 6640 | selectline $l 1 |
5ad588de PM |
6641 | } |
6642 | ||
b1ba39e7 LT |
6643 | proc commit_descriptor {p} { |
6644 | global commitinfo | |
b0934489 PM |
6645 | if {![info exists commitinfo($p)]} { |
6646 | getcommit $p | |
6647 | } | |
b1ba39e7 | 6648 | set l "..." |
b0934489 | 6649 | if {[llength $commitinfo($p)] > 1} { |
b1ba39e7 LT |
6650 | set l [lindex $commitinfo($p) 0] |
6651 | } | |
b8ab2e17 | 6652 | return "$p ($l)\n" |
b1ba39e7 LT |
6653 | } |
6654 | ||
106288cb PM |
6655 | # append some text to the ctext widget, and make any SHA1 ID |
6656 | # that we know about be a clickable link. | |
f1b86294 | 6657 | proc appendwithlinks {text tags} { |
d375ef9b | 6658 | global ctext linknum curview |
106288cb PM |
6659 | |
6660 | set start [$ctext index "end - 1c"] | |
f1b86294 | 6661 | $ctext insert end $text $tags |
d375ef9b | 6662 | set links [regexp -indices -all -inline {\m[0-9a-f]{6,40}\M} $text] |
106288cb PM |
6663 | foreach l $links { |
6664 | set s [lindex $l 0] | |
6665 | set e [lindex $l 1] | |
6666 | set linkid [string range $text $s $e] | |
106288cb | 6667 | incr e |
c73adce2 | 6668 | $ctext tag delete link$linknum |
106288cb | 6669 | $ctext tag add link$linknum "$start + $s c" "$start + $e c" |
97645683 | 6670 | setlink $linkid link$linknum |
106288cb PM |
6671 | incr linknum |
6672 | } | |
97645683 PM |
6673 | } |
6674 | ||
6675 | proc setlink {id lk} { | |
d375ef9b | 6676 | global curview ctext pendinglinks |
97645683 | 6677 | |
d375ef9b PM |
6678 | set known 0 |
6679 | if {[string length $id] < 40} { | |
6680 | set matches [longid $id] | |
6681 | if {[llength $matches] > 0} { | |
6682 | if {[llength $matches] > 1} return | |
6683 | set known 1 | |
6684 | set id [lindex $matches 0] | |
6685 | } | |
6686 | } else { | |
6687 | set known [commitinview $id $curview] | |
6688 | } | |
6689 | if {$known} { | |
97645683 | 6690 | $ctext tag conf $lk -foreground blue -underline 1 |
d375ef9b | 6691 | $ctext tag bind $lk <1> [list selbyid $id] |
97645683 PM |
6692 | $ctext tag bind $lk <Enter> {linkcursor %W 1} |
6693 | $ctext tag bind $lk <Leave> {linkcursor %W -1} | |
6694 | } else { | |
6695 | lappend pendinglinks($id) $lk | |
d375ef9b | 6696 | interestedin $id {makelink %P} |
97645683 PM |
6697 | } |
6698 | } | |
6699 | ||
6f63fc18 PM |
6700 | proc appendshortlink {id {pre {}} {post {}}} { |
6701 | global ctext linknum | |
6702 | ||
6703 | $ctext insert end $pre | |
6704 | $ctext tag delete link$linknum | |
6705 | $ctext insert end [string range $id 0 7] link$linknum | |
6706 | $ctext insert end $post | |
6707 | setlink $id link$linknum | |
6708 | incr linknum | |
6709 | } | |
6710 | ||
97645683 PM |
6711 | proc makelink {id} { |
6712 | global pendinglinks | |
6713 | ||
6714 | if {![info exists pendinglinks($id)]} return | |
6715 | foreach lk $pendinglinks($id) { | |
6716 | setlink $id $lk | |
6717 | } | |
6718 | unset pendinglinks($id) | |
6719 | } | |
6720 | ||
6721 | proc linkcursor {w inc} { | |
6722 | global linkentercount curtextcursor | |
6723 | ||
6724 | if {[incr linkentercount $inc] > 0} { | |
6725 | $w configure -cursor hand2 | |
6726 | } else { | |
6727 | $w configure -cursor $curtextcursor | |
6728 | if {$linkentercount < 0} { | |
6729 | set linkentercount 0 | |
6730 | } | |
6731 | } | |
106288cb PM |
6732 | } |
6733 | ||
6e5f7203 RN |
6734 | proc viewnextline {dir} { |
6735 | global canv linespc | |
6736 | ||
6737 | $canv delete hover | |
6738 | set ymax [lindex [$canv cget -scrollregion] 3] | |
6739 | set wnow [$canv yview] | |
6740 | set wtop [expr {[lindex $wnow 0] * $ymax}] | |
6741 | set newtop [expr {$wtop + $dir * $linespc}] | |
6742 | if {$newtop < 0} { | |
6743 | set newtop 0 | |
6744 | } elseif {$newtop > $ymax} { | |
6745 | set newtop $ymax | |
6746 | } | |
6747 | allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}] | |
6748 | } | |
6749 | ||
ef030b85 PM |
6750 | # add a list of tag or branch names at position pos |
6751 | # returns the number of names inserted | |
e11f1233 | 6752 | proc appendrefs {pos ids var} { |
7fcc92bf | 6753 | global ctext linknum curview $var maxrefs |
b8ab2e17 | 6754 | |
ef030b85 PM |
6755 | if {[catch {$ctext index $pos}]} { |
6756 | return 0 | |
6757 | } | |
e11f1233 PM |
6758 | $ctext conf -state normal |
6759 | $ctext delete $pos "$pos lineend" | |
6760 | set tags {} | |
6761 | foreach id $ids { | |
6762 | foreach tag [set $var\($id\)] { | |
6763 | lappend tags [list $tag $id] | |
6764 | } | |
6765 | } | |
0a4dd8b8 | 6766 | if {[llength $tags] > $maxrefs} { |
84b4b832 | 6767 | $ctext insert $pos "[mc "many"] ([llength $tags])" |
0a4dd8b8 PM |
6768 | } else { |
6769 | set tags [lsort -index 0 -decreasing $tags] | |
6770 | set sep {} | |
6771 | foreach ti $tags { | |
6772 | set id [lindex $ti 1] | |
6773 | set lk link$linknum | |
6774 | incr linknum | |
6775 | $ctext tag delete $lk | |
6776 | $ctext insert $pos $sep | |
6777 | $ctext insert $pos [lindex $ti 0] $lk | |
97645683 | 6778 | setlink $id $lk |
0a4dd8b8 | 6779 | set sep ", " |
b8ab2e17 | 6780 | } |
b8ab2e17 | 6781 | } |
e11f1233 | 6782 | $ctext conf -state disabled |
ef030b85 | 6783 | return [llength $tags] |
b8ab2e17 PM |
6784 | } |
6785 | ||
e11f1233 PM |
6786 | # called when we have finished computing the nearby tags |
6787 | proc dispneartags {delay} { | |
6788 | global selectedline currentid showneartags tagphase | |
ca6d8f58 | 6789 | |
94b4a69f | 6790 | if {$selectedline eq {} || !$showneartags} return |
e11f1233 PM |
6791 | after cancel dispnexttag |
6792 | if {$delay} { | |
6793 | after 200 dispnexttag | |
6794 | set tagphase -1 | |
6795 | } else { | |
6796 | after idle dispnexttag | |
6797 | set tagphase 0 | |
ca6d8f58 | 6798 | } |
ca6d8f58 PM |
6799 | } |
6800 | ||
e11f1233 PM |
6801 | proc dispnexttag {} { |
6802 | global selectedline currentid showneartags tagphase ctext | |
b8ab2e17 | 6803 | |
94b4a69f | 6804 | if {$selectedline eq {} || !$showneartags} return |
e11f1233 PM |
6805 | switch -- $tagphase { |
6806 | 0 { | |
6807 | set dtags [desctags $currentid] | |
6808 | if {$dtags ne {}} { | |
6809 | appendrefs precedes $dtags idtags | |
6810 | } | |
6811 | } | |
6812 | 1 { | |
6813 | set atags [anctags $currentid] | |
6814 | if {$atags ne {}} { | |
6815 | appendrefs follows $atags idtags | |
6816 | } | |
6817 | } | |
6818 | 2 { | |
6819 | set dheads [descheads $currentid] | |
6820 | if {$dheads ne {}} { | |
6821 | if {[appendrefs branch $dheads idheads] > 1 | |
6822 | && [$ctext get "branch -3c"] eq "h"} { | |
6823 | # turn "Branch" into "Branches" | |
6824 | $ctext conf -state normal | |
6825 | $ctext insert "branch -2c" "es" | |
6826 | $ctext conf -state disabled | |
6827 | } | |
6828 | } | |
ef030b85 PM |
6829 | } |
6830 | } | |
e11f1233 PM |
6831 | if {[incr tagphase] <= 2} { |
6832 | after idle dispnexttag | |
b8ab2e17 | 6833 | } |
b8ab2e17 PM |
6834 | } |
6835 | ||
28593d3f | 6836 | proc make_secsel {id} { |
0380081c PM |
6837 | global linehtag linentag linedtag canv canv2 canv3 |
6838 | ||
28593d3f | 6839 | if {![info exists linehtag($id)]} return |
0380081c | 6840 | $canv delete secsel |
28593d3f | 6841 | set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \ |
0380081c PM |
6842 | -tags secsel -fill [$canv cget -selectbackground]] |
6843 | $canv lower $t | |
6844 | $canv2 delete secsel | |
28593d3f | 6845 | set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \ |
0380081c PM |
6846 | -tags secsel -fill [$canv2 cget -selectbackground]] |
6847 | $canv2 lower $t | |
6848 | $canv3 delete secsel | |
28593d3f | 6849 | set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \ |
0380081c PM |
6850 | -tags secsel -fill [$canv3 cget -selectbackground]] |
6851 | $canv3 lower $t | |
6852 | } | |
6853 | ||
b9fdba7f PM |
6854 | proc make_idmark {id} { |
6855 | global linehtag canv fgcolor | |
6856 | ||
6857 | if {![info exists linehtag($id)]} return | |
6858 | $canv delete markid | |
6859 | set t [eval $canv create rect [$canv bbox $linehtag($id)] \ | |
6860 | -tags markid -outline $fgcolor] | |
6861 | $canv raise $t | |
6862 | } | |
6863 | ||
8a897742 | 6864 | proc selectline {l isnew {desired_loc {}}} { |
0380081c | 6865 | global canv ctext commitinfo selectedline |
7fcc92bf | 6866 | global canvy0 linespc parents children curview |
7fcceed7 | 6867 | global currentid sha1entry |
9f1afe05 | 6868 | global commentend idtags linknum |
d94f8cd6 | 6869 | global mergemax numcommits pending_select |
e11f1233 | 6870 | global cmitmode showneartags allcommits |
c30acc77 | 6871 | global targetrow targetid lastscrollrows |
8a897742 | 6872 | global autoselect jump_to_here |
d698206c | 6873 | |
d94f8cd6 | 6874 | catch {unset pending_select} |
84ba7345 | 6875 | $canv delete hover |
9843c307 | 6876 | normalline |
887c996e | 6877 | unsel_reflist |
bb3edc8b | 6878 | stopfinding |
8f7d0cec | 6879 | if {$l < 0 || $l >= $numcommits} return |
ac1276ab PM |
6880 | set id [commitonrow $l] |
6881 | set targetid $id | |
6882 | set targetrow $l | |
c30acc77 PM |
6883 | set selectedline $l |
6884 | set currentid $id | |
6885 | if {$lastscrollrows < $numcommits} { | |
6886 | setcanvscroll | |
6887 | } | |
ac1276ab | 6888 | |
5ad588de | 6889 | set y [expr {$canvy0 + $l * $linespc}] |
17386066 | 6890 | set ymax [lindex [$canv cget -scrollregion] 3] |
5842215e PM |
6891 | set ytop [expr {$y - $linespc - 1}] |
6892 | set ybot [expr {$y + $linespc + 1}] | |
5ad588de | 6893 | set wnow [$canv yview] |
2ed49d54 JH |
6894 | set wtop [expr {[lindex $wnow 0] * $ymax}] |
6895 | set wbot [expr {[lindex $wnow 1] * $ymax}] | |
5842215e PM |
6896 | set wh [expr {$wbot - $wtop}] |
6897 | set newtop $wtop | |
17386066 | 6898 | if {$ytop < $wtop} { |
5842215e PM |
6899 | if {$ybot < $wtop} { |
6900 | set newtop [expr {$y - $wh / 2.0}] | |
6901 | } else { | |
6902 | set newtop $ytop | |
6903 | if {$newtop > $wtop - $linespc} { | |
6904 | set newtop [expr {$wtop - $linespc}] | |
6905 | } | |
17386066 | 6906 | } |
5842215e PM |
6907 | } elseif {$ybot > $wbot} { |
6908 | if {$ytop > $wbot} { | |
6909 | set newtop [expr {$y - $wh / 2.0}] | |
6910 | } else { | |
6911 | set newtop [expr {$ybot - $wh}] | |
6912 | if {$newtop < $wtop + $linespc} { | |
6913 | set newtop [expr {$wtop + $linespc}] | |
6914 | } | |
17386066 | 6915 | } |
5842215e PM |
6916 | } |
6917 | if {$newtop != $wtop} { | |
6918 | if {$newtop < 0} { | |
6919 | set newtop 0 | |
6920 | } | |
2ed49d54 | 6921 | allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}] |
9f1afe05 | 6922 | drawvisible |
5ad588de | 6923 | } |
d698206c | 6924 | |
28593d3f | 6925 | make_secsel $id |
9f1afe05 | 6926 | |
fa4da7b3 | 6927 | if {$isnew} { |
354af6bd | 6928 | addtohistory [list selbyid $id 0] savecmitpos |
d698206c PM |
6929 | } |
6930 | ||
98f350e5 PM |
6931 | $sha1entry delete 0 end |
6932 | $sha1entry insert 0 $id | |
95293b58 | 6933 | if {$autoselect} { |
d93f1713 | 6934 | $sha1entry selection range 0 end |
95293b58 | 6935 | } |
164ff275 | 6936 | rhighlight_sel $id |
98f350e5 | 6937 | |
5ad588de | 6938 | $ctext conf -state normal |
3ea06f9f | 6939 | clear_ctext |
106288cb | 6940 | set linknum 0 |
d76afb15 PM |
6941 | if {![info exists commitinfo($id)]} { |
6942 | getcommit $id | |
6943 | } | |
1db95b00 | 6944 | set info $commitinfo($id) |
232475d3 | 6945 | set date [formatdate [lindex $info 2]] |
d990cedf | 6946 | $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n" |
232475d3 | 6947 | set date [formatdate [lindex $info 4]] |
d990cedf | 6948 | $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n" |
887fe3c4 | 6949 | if {[info exists idtags($id)]} { |
d990cedf | 6950 | $ctext insert end [mc "Tags:"] |
887fe3c4 PM |
6951 | foreach tag $idtags($id) { |
6952 | $ctext insert end " $tag" | |
6953 | } | |
6954 | $ctext insert end "\n" | |
6955 | } | |
40b87ff8 | 6956 | |
f1b86294 | 6957 | set headers {} |
7fcc92bf | 6958 | set olds $parents($curview,$id) |
79b2c75e | 6959 | if {[llength $olds] > 1} { |
b77b0278 | 6960 | set np 0 |
79b2c75e | 6961 | foreach p $olds { |
b77b0278 PM |
6962 | if {$np >= $mergemax} { |
6963 | set tag mmax | |
6964 | } else { | |
6965 | set tag m$np | |
6966 | } | |
d990cedf | 6967 | $ctext insert end "[mc "Parent"]: " $tag |
f1b86294 | 6968 | appendwithlinks [commit_descriptor $p] {} |
b77b0278 PM |
6969 | incr np |
6970 | } | |
6971 | } else { | |
79b2c75e | 6972 | foreach p $olds { |
d990cedf | 6973 | append headers "[mc "Parent"]: [commit_descriptor $p]" |
b1ba39e7 LT |
6974 | } |
6975 | } | |
b77b0278 | 6976 | |
6a90bff1 | 6977 | foreach c $children($curview,$id) { |
d990cedf | 6978 | append headers "[mc "Child"]: [commit_descriptor $c]" |
8b192809 | 6979 | } |
d698206c PM |
6980 | |
6981 | # make anything that looks like a SHA1 ID be a clickable link | |
f1b86294 | 6982 | appendwithlinks $headers {} |
b8ab2e17 PM |
6983 | if {$showneartags} { |
6984 | if {![info exists allcommits]} { | |
6985 | getallcommits | |
6986 | } | |
d990cedf | 6987 | $ctext insert end "[mc "Branch"]: " |
ef030b85 PM |
6988 | $ctext mark set branch "end -1c" |
6989 | $ctext mark gravity branch left | |
d990cedf | 6990 | $ctext insert end "\n[mc "Follows"]: " |
b8ab2e17 PM |
6991 | $ctext mark set follows "end -1c" |
6992 | $ctext mark gravity follows left | |
d990cedf | 6993 | $ctext insert end "\n[mc "Precedes"]: " |
b8ab2e17 PM |
6994 | $ctext mark set precedes "end -1c" |
6995 | $ctext mark gravity precedes left | |
b8ab2e17 | 6996 | $ctext insert end "\n" |
e11f1233 | 6997 | dispneartags 1 |
b8ab2e17 PM |
6998 | } |
6999 | $ctext insert end "\n" | |
43c25074 PM |
7000 | set comment [lindex $info 5] |
7001 | if {[string first "\r" $comment] >= 0} { | |
7002 | set comment [string map {"\r" "\n "} $comment] | |
7003 | } | |
7004 | appendwithlinks $comment {comment} | |
d698206c | 7005 | |
df3d83b1 | 7006 | $ctext tag remove found 1.0 end |
5ad588de | 7007 | $ctext conf -state disabled |
df3d83b1 | 7008 | set commentend [$ctext index "end - 1c"] |
5ad588de | 7009 | |
8a897742 | 7010 | set jump_to_here $desired_loc |
b007ee20 | 7011 | init_flist [mc "Comments"] |
f8b28a40 PM |
7012 | if {$cmitmode eq "tree"} { |
7013 | gettree $id | |
7014 | } elseif {[llength $olds] <= 1} { | |
d327244a | 7015 | startdiff $id |
7b5ff7e7 | 7016 | } else { |
7fcc92bf | 7017 | mergediff $id |
3c461ffe PM |
7018 | } |
7019 | } | |
7020 | ||
6e5f7203 RN |
7021 | proc selfirstline {} { |
7022 | unmarkmatches | |
7023 | selectline 0 1 | |
7024 | } | |
7025 | ||
7026 | proc sellastline {} { | |
7027 | global numcommits | |
7028 | unmarkmatches | |
7029 | set l [expr {$numcommits - 1}] | |
7030 | selectline $l 1 | |
7031 | } | |
7032 | ||
3c461ffe PM |
7033 | proc selnextline {dir} { |
7034 | global selectedline | |
bd441de4 | 7035 | focus . |
94b4a69f | 7036 | if {$selectedline eq {}} return |
2ed49d54 | 7037 | set l [expr {$selectedline + $dir}] |
3c461ffe | 7038 | unmarkmatches |
d698206c PM |
7039 | selectline $l 1 |
7040 | } | |
7041 | ||
6e5f7203 RN |
7042 | proc selnextpage {dir} { |
7043 | global canv linespc selectedline numcommits | |
7044 | ||
7045 | set lpp [expr {([winfo height $canv] - 2) / $linespc}] | |
7046 | if {$lpp < 1} { | |
7047 | set lpp 1 | |
7048 | } | |
7049 | allcanvs yview scroll [expr {$dir * $lpp}] units | |
e72ee5eb | 7050 | drawvisible |
94b4a69f | 7051 | if {$selectedline eq {}} return |
6e5f7203 RN |
7052 | set l [expr {$selectedline + $dir * $lpp}] |
7053 | if {$l < 0} { | |
7054 | set l 0 | |
7055 | } elseif {$l >= $numcommits} { | |
7056 | set l [expr $numcommits - 1] | |
7057 | } | |
7058 | unmarkmatches | |
40b87ff8 | 7059 | selectline $l 1 |
6e5f7203 RN |
7060 | } |
7061 | ||
fa4da7b3 | 7062 | proc unselectline {} { |
50b44ece | 7063 | global selectedline currentid |
fa4da7b3 | 7064 | |
94b4a69f | 7065 | set selectedline {} |
50b44ece | 7066 | catch {unset currentid} |
fa4da7b3 | 7067 | allcanvs delete secsel |
164ff275 | 7068 | rhighlight_none |
fa4da7b3 PM |
7069 | } |
7070 | ||
f8b28a40 PM |
7071 | proc reselectline {} { |
7072 | global selectedline | |
7073 | ||
94b4a69f | 7074 | if {$selectedline ne {}} { |
f8b28a40 PM |
7075 | selectline $selectedline 0 |
7076 | } | |
7077 | } | |
7078 | ||
354af6bd | 7079 | proc addtohistory {cmd {saveproc {}}} { |
2516dae2 | 7080 | global history historyindex curview |
fa4da7b3 | 7081 | |
354af6bd PM |
7082 | unset_posvars |
7083 | save_position | |
7084 | set elt [list $curview $cmd $saveproc {}] | |
fa4da7b3 | 7085 | if {$historyindex > 0 |
2516dae2 | 7086 | && [lindex $history [expr {$historyindex - 1}]] == $elt} { |
fa4da7b3 PM |
7087 | return |
7088 | } | |
7089 | ||
7090 | if {$historyindex < [llength $history]} { | |
2516dae2 | 7091 | set history [lreplace $history $historyindex end $elt] |
fa4da7b3 | 7092 | } else { |
2516dae2 | 7093 | lappend history $elt |
fa4da7b3 PM |
7094 | } |
7095 | incr historyindex | |
7096 | if {$historyindex > 1} { | |
e9937d2a | 7097 | .tf.bar.leftbut conf -state normal |
fa4da7b3 | 7098 | } else { |
e9937d2a | 7099 | .tf.bar.leftbut conf -state disabled |
fa4da7b3 | 7100 | } |
e9937d2a | 7101 | .tf.bar.rightbut conf -state disabled |
fa4da7b3 PM |
7102 | } |
7103 | ||
354af6bd PM |
7104 | # save the scrolling position of the diff display pane |
7105 | proc save_position {} { | |
7106 | global historyindex history | |
7107 | ||
7108 | if {$historyindex < 1} return | |
7109 | set hi [expr {$historyindex - 1}] | |
7110 | set fn [lindex $history $hi 2] | |
7111 | if {$fn ne {}} { | |
7112 | lset history $hi 3 [eval $fn] | |
7113 | } | |
7114 | } | |
7115 | ||
7116 | proc unset_posvars {} { | |
7117 | global last_posvars | |
7118 | ||
7119 | if {[info exists last_posvars]} { | |
7120 | foreach {var val} $last_posvars { | |
7121 | global $var | |
7122 | catch {unset $var} | |
7123 | } | |
7124 | unset last_posvars | |
7125 | } | |
7126 | } | |
7127 | ||
2516dae2 | 7128 | proc godo {elt} { |
354af6bd | 7129 | global curview last_posvars |
2516dae2 PM |
7130 | |
7131 | set view [lindex $elt 0] | |
7132 | set cmd [lindex $elt 1] | |
354af6bd | 7133 | set pv [lindex $elt 3] |
2516dae2 PM |
7134 | if {$curview != $view} { |
7135 | showview $view | |
7136 | } | |
354af6bd PM |
7137 | unset_posvars |
7138 | foreach {var val} $pv { | |
7139 | global $var | |
7140 | set $var $val | |
7141 | } | |
7142 | set last_posvars $pv | |
2516dae2 PM |
7143 | eval $cmd |
7144 | } | |
7145 | ||
d698206c PM |
7146 | proc goback {} { |
7147 | global history historyindex | |
bd441de4 | 7148 | focus . |
d698206c PM |
7149 | |
7150 | if {$historyindex > 1} { | |
354af6bd | 7151 | save_position |
d698206c | 7152 | incr historyindex -1 |
2516dae2 | 7153 | godo [lindex $history [expr {$historyindex - 1}]] |
e9937d2a | 7154 | .tf.bar.rightbut conf -state normal |
d698206c PM |
7155 | } |
7156 | if {$historyindex <= 1} { | |
e9937d2a | 7157 | .tf.bar.leftbut conf -state disabled |
d698206c PM |
7158 | } |
7159 | } | |
7160 | ||
7161 | proc goforw {} { | |
7162 | global history historyindex | |
bd441de4 | 7163 | focus . |
d698206c PM |
7164 | |
7165 | if {$historyindex < [llength $history]} { | |
354af6bd | 7166 | save_position |
fa4da7b3 | 7167 | set cmd [lindex $history $historyindex] |
d698206c | 7168 | incr historyindex |
2516dae2 | 7169 | godo $cmd |
e9937d2a | 7170 | .tf.bar.leftbut conf -state normal |
d698206c PM |
7171 | } |
7172 | if {$historyindex >= [llength $history]} { | |
e9937d2a | 7173 | .tf.bar.rightbut conf -state disabled |
d698206c | 7174 | } |
e2ed4324 PM |
7175 | } |
7176 | ||
f8b28a40 | 7177 | proc gettree {id} { |
8f489363 PM |
7178 | global treefilelist treeidlist diffids diffmergeid treepending |
7179 | global nullid nullid2 | |
f8b28a40 PM |
7180 | |
7181 | set diffids $id | |
7182 | catch {unset diffmergeid} | |
7183 | if {![info exists treefilelist($id)]} { | |
7184 | if {![info exists treepending]} { | |
8f489363 PM |
7185 | if {$id eq $nullid} { |
7186 | set cmd [list | git ls-files] | |
7187 | } elseif {$id eq $nullid2} { | |
7188 | set cmd [list | git ls-files --stage -t] | |
219ea3a9 | 7189 | } else { |
8f489363 | 7190 | set cmd [list | git ls-tree -r $id] |
219ea3a9 PM |
7191 | } |
7192 | if {[catch {set gtf [open $cmd r]}]} { | |
f8b28a40 PM |
7193 | return |
7194 | } | |
7195 | set treepending $id | |
7196 | set treefilelist($id) {} | |
7197 | set treeidlist($id) {} | |
09c7029d | 7198 | fconfigure $gtf -blocking 0 -encoding binary |
7eb3cb9c | 7199 | filerun $gtf [list gettreeline $gtf $id] |
f8b28a40 PM |
7200 | } |
7201 | } else { | |
7202 | setfilelist $id | |
7203 | } | |
7204 | } | |
7205 | ||
7206 | proc gettreeline {gtf id} { | |
8f489363 | 7207 | global treefilelist treeidlist treepending cmitmode diffids nullid nullid2 |
f8b28a40 | 7208 | |
7eb3cb9c PM |
7209 | set nl 0 |
7210 | while {[incr nl] <= 1000 && [gets $gtf line] >= 0} { | |
8f489363 PM |
7211 | if {$diffids eq $nullid} { |
7212 | set fname $line | |
7213 | } else { | |
9396cd38 PM |
7214 | set i [string first "\t" $line] |
7215 | if {$i < 0} continue | |
9396cd38 | 7216 | set fname [string range $line [expr {$i+1}] end] |
f31fa2c0 PM |
7217 | set line [string range $line 0 [expr {$i-1}]] |
7218 | if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue | |
7219 | set sha1 [lindex $line 2] | |
219ea3a9 | 7220 | lappend treeidlist($id) $sha1 |
219ea3a9 | 7221 | } |
09c7029d AG |
7222 | if {[string index $fname 0] eq "\""} { |
7223 | set fname [lindex $fname 0] | |
7224 | } | |
7225 | set fname [encoding convertfrom $fname] | |
7eb3cb9c PM |
7226 | lappend treefilelist($id) $fname |
7227 | } | |
7228 | if {![eof $gtf]} { | |
7229 | return [expr {$nl >= 1000? 2: 1}] | |
f8b28a40 | 7230 | } |
f8b28a40 PM |
7231 | close $gtf |
7232 | unset treepending | |
7233 | if {$cmitmode ne "tree"} { | |
7234 | if {![info exists diffmergeid]} { | |
7235 | gettreediffs $diffids | |
7236 | } | |
7237 | } elseif {$id ne $diffids} { | |
7238 | gettree $diffids | |
7239 | } else { | |
7240 | setfilelist $id | |
7241 | } | |
7eb3cb9c | 7242 | return 0 |
f8b28a40 PM |
7243 | } |
7244 | ||
7245 | proc showfile {f} { | |
8f489363 | 7246 | global treefilelist treeidlist diffids nullid nullid2 |
7cdc3556 | 7247 | global ctext_file_names ctext_file_lines |
f8b28a40 PM |
7248 | global ctext commentend |
7249 | ||
7250 | set i [lsearch -exact $treefilelist($diffids) $f] | |
7251 | if {$i < 0} { | |
7252 | puts "oops, $f not in list for id $diffids" | |
7253 | return | |
7254 | } | |
8f489363 PM |
7255 | if {$diffids eq $nullid} { |
7256 | if {[catch {set bf [open $f r]} err]} { | |
7257 | puts "oops, can't read $f: $err" | |
219ea3a9 PM |
7258 | return |
7259 | } | |
7260 | } else { | |
8f489363 PM |
7261 | set blob [lindex $treeidlist($diffids) $i] |
7262 | if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} { | |
7263 | puts "oops, error reading blob $blob: $err" | |
219ea3a9 PM |
7264 | return |
7265 | } | |
f8b28a40 | 7266 | } |
09c7029d | 7267 | fconfigure $bf -blocking 0 -encoding [get_path_encoding $f] |
7eb3cb9c | 7268 | filerun $bf [list getblobline $bf $diffids] |
f8b28a40 | 7269 | $ctext config -state normal |
3ea06f9f | 7270 | clear_ctext $commentend |
7cdc3556 AG |
7271 | lappend ctext_file_names $f |
7272 | lappend ctext_file_lines [lindex [split $commentend "."] 0] | |
f8b28a40 PM |
7273 | $ctext insert end "\n" |
7274 | $ctext insert end "$f\n" filesep | |
7275 | $ctext config -state disabled | |
7276 | $ctext yview $commentend | |
32f1b3e4 | 7277 | settabs 0 |
f8b28a40 PM |
7278 | } |
7279 | ||
7280 | proc getblobline {bf id} { | |
7281 | global diffids cmitmode ctext | |
7282 | ||
7283 | if {$id ne $diffids || $cmitmode ne "tree"} { | |
7284 | catch {close $bf} | |
7eb3cb9c | 7285 | return 0 |
f8b28a40 PM |
7286 | } |
7287 | $ctext config -state normal | |
7eb3cb9c PM |
7288 | set nl 0 |
7289 | while {[incr nl] <= 1000 && [gets $bf line] >= 0} { | |
f8b28a40 PM |
7290 | $ctext insert end "$line\n" |
7291 | } | |
7292 | if {[eof $bf]} { | |
8a897742 PM |
7293 | global jump_to_here ctext_file_names commentend |
7294 | ||
f8b28a40 PM |
7295 | # delete last newline |
7296 | $ctext delete "end - 2c" "end - 1c" | |
7297 | close $bf | |
8a897742 PM |
7298 | if {$jump_to_here ne {} && |
7299 | [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} { | |
7300 | set lnum [expr {[lindex $jump_to_here 1] + | |
7301 | [lindex [split $commentend .] 0]}] | |
7302 | mark_ctext_line $lnum | |
7303 | } | |
7eb3cb9c | 7304 | return 0 |
f8b28a40 PM |
7305 | } |
7306 | $ctext config -state disabled | |
7eb3cb9c | 7307 | return [expr {$nl >= 1000? 2: 1}] |
f8b28a40 PM |
7308 | } |
7309 | ||
8a897742 | 7310 | proc mark_ctext_line {lnum} { |
e3e901be | 7311 | global ctext markbgcolor |
8a897742 PM |
7312 | |
7313 | $ctext tag delete omark | |
7314 | $ctext tag add omark $lnum.0 "$lnum.0 + 1 line" | |
e3e901be | 7315 | $ctext tag conf omark -background $markbgcolor |
8a897742 PM |
7316 | $ctext see $lnum.0 |
7317 | } | |
7318 | ||
7fcc92bf | 7319 | proc mergediff {id} { |
8b07dca1 | 7320 | global diffmergeid |
2df6442f | 7321 | global diffids treediffs |
8b07dca1 | 7322 | global parents curview |
e2ed4324 | 7323 | |
3c461ffe | 7324 | set diffmergeid $id |
7a1d9d14 | 7325 | set diffids $id |
2df6442f | 7326 | set treediffs($id) {} |
7fcc92bf | 7327 | set np [llength $parents($curview,$id)] |
32f1b3e4 | 7328 | settabs $np |
8b07dca1 | 7329 | getblobdiffs $id |
c8a4acbf PM |
7330 | } |
7331 | ||
3c461ffe | 7332 | proc startdiff {ids} { |
8f489363 | 7333 | global treediffs diffids treepending diffmergeid nullid nullid2 |
c8dfbcf9 | 7334 | |
32f1b3e4 | 7335 | settabs 1 |
4f2c2642 | 7336 | set diffids $ids |
3c461ffe | 7337 | catch {unset diffmergeid} |
8f489363 PM |
7338 | if {![info exists treediffs($ids)] || |
7339 | [lsearch -exact $ids $nullid] >= 0 || | |
7340 | [lsearch -exact $ids $nullid2] >= 0} { | |
c8dfbcf9 | 7341 | if {![info exists treepending]} { |
14c9dbd6 | 7342 | gettreediffs $ids |
c8dfbcf9 PM |
7343 | } |
7344 | } else { | |
14c9dbd6 | 7345 | addtocflist $ids |
c8dfbcf9 PM |
7346 | } |
7347 | } | |
7348 | ||
7a39a17a PM |
7349 | proc path_filter {filter name} { |
7350 | foreach p $filter { | |
7351 | set l [string length $p] | |
74a40c71 PM |
7352 | if {[string index $p end] eq "/"} { |
7353 | if {[string compare -length $l $p $name] == 0} { | |
7354 | return 1 | |
7355 | } | |
7356 | } else { | |
7357 | if {[string compare -length $l $p $name] == 0 && | |
7358 | ([string length $name] == $l || | |
7359 | [string index $name $l] eq "/")} { | |
7360 | return 1 | |
7361 | } | |
7a39a17a PM |
7362 | } |
7363 | } | |
7364 | return 0 | |
7365 | } | |
7366 | ||
c8dfbcf9 | 7367 | proc addtocflist {ids} { |
74a40c71 | 7368 | global treediffs |
7a39a17a | 7369 | |
74a40c71 | 7370 | add_flist $treediffs($ids) |
c8dfbcf9 | 7371 | getblobdiffs $ids |
d2610d11 PM |
7372 | } |
7373 | ||
219ea3a9 | 7374 | proc diffcmd {ids flags} { |
8f489363 | 7375 | global nullid nullid2 |
219ea3a9 PM |
7376 | |
7377 | set i [lsearch -exact $ids $nullid] | |
8f489363 | 7378 | set j [lsearch -exact $ids $nullid2] |
219ea3a9 | 7379 | if {$i >= 0} { |
8f489363 PM |
7380 | if {[llength $ids] > 1 && $j < 0} { |
7381 | # comparing working directory with some specific revision | |
7382 | set cmd [concat | git diff-index $flags] | |
7383 | if {$i == 0} { | |
7384 | lappend cmd -R [lindex $ids 1] | |
7385 | } else { | |
7386 | lappend cmd [lindex $ids 0] | |
7387 | } | |
7388 | } else { | |
7389 | # comparing working directory with index | |
7390 | set cmd [concat | git diff-files $flags] | |
7391 | if {$j == 1} { | |
7392 | lappend cmd -R | |
7393 | } | |
7394 | } | |
7395 | } elseif {$j >= 0} { | |
7396 | set cmd [concat | git diff-index --cached $flags] | |
219ea3a9 | 7397 | if {[llength $ids] > 1} { |
8f489363 | 7398 | # comparing index with specific revision |
90a77925 | 7399 | if {$j == 0} { |
219ea3a9 PM |
7400 | lappend cmd -R [lindex $ids 1] |
7401 | } else { | |
7402 | lappend cmd [lindex $ids 0] | |
7403 | } | |
7404 | } else { | |
8f489363 | 7405 | # comparing index with HEAD |
219ea3a9 PM |
7406 | lappend cmd HEAD |
7407 | } | |
7408 | } else { | |
8f489363 | 7409 | set cmd [concat | git diff-tree -r $flags $ids] |
219ea3a9 PM |
7410 | } |
7411 | return $cmd | |
7412 | } | |
7413 | ||
c8dfbcf9 | 7414 | proc gettreediffs {ids} { |
79b2c75e | 7415 | global treediff treepending |
219ea3a9 | 7416 | |
7272131b AG |
7417 | if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return |
7418 | ||
c8dfbcf9 | 7419 | set treepending $ids |
3c461ffe | 7420 | set treediff {} |
09c7029d | 7421 | fconfigure $gdtf -blocking 0 -encoding binary |
7eb3cb9c | 7422 | filerun $gdtf [list gettreediffline $gdtf $ids] |
d2610d11 PM |
7423 | } |
7424 | ||
c8dfbcf9 | 7425 | proc gettreediffline {gdtf ids} { |
3c461ffe | 7426 | global treediff treediffs treepending diffids diffmergeid |
39ee47ef | 7427 | global cmitmode vfilelimit curview limitdiffs perfile_attrs |
3c461ffe | 7428 | |
7eb3cb9c | 7429 | set nr 0 |
4db09304 | 7430 | set sublist {} |
39ee47ef PM |
7431 | set max 1000 |
7432 | if {$perfile_attrs} { | |
7433 | # cache_gitattr is slow, and even slower on win32 where we | |
7434 | # have to invoke it for only about 30 paths at a time | |
7435 | set max 500 | |
7436 | if {[tk windowingsystem] == "win32"} { | |
7437 | set max 120 | |
7438 | } | |
7439 | } | |
7440 | while {[incr nr] <= $max && [gets $gdtf line] >= 0} { | |
9396cd38 PM |
7441 | set i [string first "\t" $line] |
7442 | if {$i >= 0} { | |
7443 | set file [string range $line [expr {$i+1}] end] | |
7444 | if {[string index $file 0] eq "\""} { | |
7445 | set file [lindex $file 0] | |
7446 | } | |
09c7029d | 7447 | set file [encoding convertfrom $file] |
48a81b7c PM |
7448 | if {$file ne [lindex $treediff end]} { |
7449 | lappend treediff $file | |
7450 | lappend sublist $file | |
7451 | } | |
9396cd38 | 7452 | } |
7eb3cb9c | 7453 | } |
39ee47ef PM |
7454 | if {$perfile_attrs} { |
7455 | cache_gitattr encoding $sublist | |
7456 | } | |
7eb3cb9c | 7457 | if {![eof $gdtf]} { |
39ee47ef | 7458 | return [expr {$nr >= $max? 2: 1}] |
7eb3cb9c PM |
7459 | } |
7460 | close $gdtf | |
3ed31a81 | 7461 | if {$limitdiffs && $vfilelimit($curview) ne {}} { |
74a40c71 PM |
7462 | set flist {} |
7463 | foreach f $treediff { | |
3ed31a81 | 7464 | if {[path_filter $vfilelimit($curview) $f]} { |
74a40c71 PM |
7465 | lappend flist $f |
7466 | } | |
7467 | } | |
7468 | set treediffs($ids) $flist | |
7469 | } else { | |
7470 | set treediffs($ids) $treediff | |
7471 | } | |
7eb3cb9c | 7472 | unset treepending |
e1160138 | 7473 | if {$cmitmode eq "tree" && [llength $diffids] == 1} { |
7eb3cb9c PM |
7474 | gettree $diffids |
7475 | } elseif {$ids != $diffids} { | |
7476 | if {![info exists diffmergeid]} { | |
7477 | gettreediffs $diffids | |
b74fd579 | 7478 | } |
7eb3cb9c PM |
7479 | } else { |
7480 | addtocflist $ids | |
d2610d11 | 7481 | } |
7eb3cb9c | 7482 | return 0 |
d2610d11 PM |
7483 | } |
7484 | ||
890fae70 SP |
7485 | # empty string or positive integer |
7486 | proc diffcontextvalidate {v} { | |
7487 | return [regexp {^(|[1-9][0-9]*)$} $v] | |
7488 | } | |
7489 | ||
7490 | proc diffcontextchange {n1 n2 op} { | |
7491 | global diffcontextstring diffcontext | |
7492 | ||
7493 | if {[string is integer -strict $diffcontextstring]} { | |
a41ddbb6 | 7494 | if {$diffcontextstring >= 0} { |
890fae70 SP |
7495 | set diffcontext $diffcontextstring |
7496 | reselectline | |
7497 | } | |
7498 | } | |
7499 | } | |
7500 | ||
b9b86007 SP |
7501 | proc changeignorespace {} { |
7502 | reselectline | |
7503 | } | |
7504 | ||
c8dfbcf9 | 7505 | proc getblobdiffs {ids} { |
8d73b242 | 7506 | global blobdifffd diffids env |
7eb3cb9c | 7507 | global diffinhdr treediffs |
890fae70 | 7508 | global diffcontext |
b9b86007 | 7509 | global ignorespace |
3ed31a81 | 7510 | global limitdiffs vfilelimit curview |
8b07dca1 | 7511 | global diffencoding targetline diffnparents |
a1d383c5 | 7512 | global git_version currdiffsubmod |
c8dfbcf9 | 7513 | |
a8138733 PM |
7514 | set textconv {} |
7515 | if {[package vcompare $git_version "1.6.1"] >= 0} { | |
7516 | set textconv "--textconv" | |
7517 | } | |
5c838d23 JL |
7518 | set submodule {} |
7519 | if {[package vcompare $git_version "1.6.6"] >= 0} { | |
7520 | set submodule "--submodule" | |
7521 | } | |
7522 | set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"] | |
b9b86007 SP |
7523 | if {$ignorespace} { |
7524 | append cmd " -w" | |
7525 | } | |
3ed31a81 PM |
7526 | if {$limitdiffs && $vfilelimit($curview) ne {}} { |
7527 | set cmd [concat $cmd -- $vfilelimit($curview)] | |
7a39a17a PM |
7528 | } |
7529 | if {[catch {set bdf [open $cmd r]} err]} { | |
8b07dca1 | 7530 | error_popup [mc "Error getting diffs: %s" $err] |
e5c2d856 PM |
7531 | return |
7532 | } | |
8a897742 | 7533 | set targetline {} |
8b07dca1 | 7534 | set diffnparents 0 |
4f2c2642 | 7535 | set diffinhdr 0 |
09c7029d | 7536 | set diffencoding [get_path_encoding {}] |
681c3290 | 7537 | fconfigure $bdf -blocking 0 -encoding binary -eofchar {} |
c8dfbcf9 | 7538 | set blobdifffd($ids) $bdf |
a1d383c5 | 7539 | set currdiffsubmod "" |
7eb3cb9c | 7540 | filerun $bdf [list getblobdiffline $bdf $diffids] |
e5c2d856 PM |
7541 | } |
7542 | ||
354af6bd PM |
7543 | proc savecmitpos {} { |
7544 | global ctext cmitmode | |
7545 | ||
7546 | if {$cmitmode eq "tree"} { | |
7547 | return {} | |
7548 | } | |
7549 | return [list target_scrollpos [$ctext index @0,0]] | |
7550 | } | |
7551 | ||
7552 | proc savectextpos {} { | |
7553 | global ctext | |
7554 | ||
7555 | return [list target_scrollpos [$ctext index @0,0]] | |
7556 | } | |
7557 | ||
7558 | proc maybe_scroll_ctext {ateof} { | |
7559 | global ctext target_scrollpos | |
7560 | ||
7561 | if {![info exists target_scrollpos]} return | |
7562 | if {!$ateof} { | |
7563 | set nlines [expr {[winfo height $ctext] | |
7564 | / [font metrics textfont -linespace]}] | |
7565 | if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return | |
7566 | } | |
7567 | $ctext yview $target_scrollpos | |
7568 | unset target_scrollpos | |
7569 | } | |
7570 | ||
89b11d3b PM |
7571 | proc setinlist {var i val} { |
7572 | global $var | |
7573 | ||
7574 | while {[llength [set $var]] < $i} { | |
7575 | lappend $var {} | |
7576 | } | |
7577 | if {[llength [set $var]] == $i} { | |
7578 | lappend $var $val | |
7579 | } else { | |
7580 | lset $var $i $val | |
7581 | } | |
7582 | } | |
7583 | ||
9396cd38 | 7584 | proc makediffhdr {fname ids} { |
8b07dca1 | 7585 | global ctext curdiffstart treediffs diffencoding |
8a897742 | 7586 | global ctext_file_names jump_to_here targetline diffline |
9396cd38 | 7587 | |
8b07dca1 PM |
7588 | set fname [encoding convertfrom $fname] |
7589 | set diffencoding [get_path_encoding $fname] | |
9396cd38 PM |
7590 | set i [lsearch -exact $treediffs($ids) $fname] |
7591 | if {$i >= 0} { | |
7592 | setinlist difffilestart $i $curdiffstart | |
7593 | } | |
48a81b7c | 7594 | lset ctext_file_names end $fname |
9396cd38 PM |
7595 | set l [expr {(78 - [string length $fname]) / 2}] |
7596 | set pad [string range "----------------------------------------" 1 $l] | |
7597 | $ctext insert $curdiffstart "$pad $fname $pad" filesep | |
8a897742 PM |
7598 | set targetline {} |
7599 | if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} { | |
7600 | set targetline [lindex $jump_to_here 1] | |
7601 | } | |
7602 | set diffline 0 | |
9396cd38 PM |
7603 | } |
7604 | ||
c8dfbcf9 | 7605 | proc getblobdiffline {bdf ids} { |
9396cd38 | 7606 | global diffids blobdifffd ctext curdiffstart |
7eab2933 | 7607 | global diffnexthead diffnextnote difffilestart |
7cdc3556 | 7608 | global ctext_file_names ctext_file_lines |
8b07dca1 | 7609 | global diffinhdr treediffs mergemax diffnparents |
a1d383c5 | 7610 | global diffencoding jump_to_here targetline diffline currdiffsubmod |
c8dfbcf9 | 7611 | |
7eb3cb9c | 7612 | set nr 0 |
e5c2d856 | 7613 | $ctext conf -state normal |
7eb3cb9c PM |
7614 | while {[incr nr] <= 1000 && [gets $bdf line] >= 0} { |
7615 | if {$ids != $diffids || $bdf != $blobdifffd($ids)} { | |
c21398be | 7616 | catch {close $bdf} |
7eb3cb9c | 7617 | return 0 |
89b11d3b | 7618 | } |
8b07dca1 PM |
7619 | if {![string compare -length 5 "diff " $line]} { |
7620 | if {![regexp {^diff (--cc|--git) } $line m type]} { | |
7621 | set line [encoding convertfrom $line] | |
7622 | $ctext insert end "$line\n" hunksep | |
7623 | continue | |
7624 | } | |
7eb3cb9c | 7625 | # start of a new file |
8b07dca1 | 7626 | set diffinhdr 1 |
7eb3cb9c | 7627 | $ctext insert end "\n" |
9396cd38 | 7628 | set curdiffstart [$ctext index "end - 1c"] |
7cdc3556 AG |
7629 | lappend ctext_file_names "" |
7630 | lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] | |
9396cd38 | 7631 | $ctext insert end "\n" filesep |
8b07dca1 PM |
7632 | |
7633 | if {$type eq "--cc"} { | |
7634 | # start of a new file in a merge diff | |
7635 | set fname [string range $line 10 end] | |
7636 | if {[lsearch -exact $treediffs($ids) $fname] < 0} { | |
7637 | lappend treediffs($ids) $fname | |
7638 | add_flist [list $fname] | |
7639 | } | |
7640 | ||
9396cd38 | 7641 | } else { |
8b07dca1 PM |
7642 | set line [string range $line 11 end] |
7643 | # If the name hasn't changed the length will be odd, | |
7644 | # the middle char will be a space, and the two bits either | |
7645 | # side will be a/name and b/name, or "a/name" and "b/name". | |
7646 | # If the name has changed we'll get "rename from" and | |
7647 | # "rename to" or "copy from" and "copy to" lines following | |
7648 | # this, and we'll use them to get the filenames. | |
7649 | # This complexity is necessary because spaces in the | |
7650 | # filename(s) don't get escaped. | |
7651 | set l [string length $line] | |
7652 | set i [expr {$l / 2}] | |
7653 | if {!(($l & 1) && [string index $line $i] eq " " && | |
7654 | [string range $line 2 [expr {$i - 1}]] eq \ | |
7655 | [string range $line [expr {$i + 3}] end])} { | |
7656 | continue | |
7657 | } | |
7658 | # unescape if quoted and chop off the a/ from the front | |
7659 | if {[string index $line 0] eq "\""} { | |
7660 | set fname [string range [lindex $line 0] 2 end] | |
7661 | } else { | |
7662 | set fname [string range $line 2 [expr {$i - 1}]] | |
7663 | } | |
7eb3cb9c | 7664 | } |
9396cd38 PM |
7665 | makediffhdr $fname $ids |
7666 | ||
48a81b7c PM |
7667 | } elseif {![string compare -length 16 "* Unmerged path " $line]} { |
7668 | set fname [encoding convertfrom [string range $line 16 end]] | |
7669 | $ctext insert end "\n" | |
7670 | set curdiffstart [$ctext index "end - 1c"] | |
7671 | lappend ctext_file_names $fname | |
7672 | lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] | |
7673 | $ctext insert end "$line\n" filesep | |
7674 | set i [lsearch -exact $treediffs($ids) $fname] | |
7675 | if {$i >= 0} { | |
7676 | setinlist difffilestart $i $curdiffstart | |
7677 | } | |
7678 | ||
8b07dca1 PM |
7679 | } elseif {![string compare -length 2 "@@" $line]} { |
7680 | regexp {^@@+} $line ats | |
09c7029d | 7681 | set line [encoding convertfrom $diffencoding $line] |
7eb3cb9c | 7682 | $ctext insert end "$line\n" hunksep |
8b07dca1 PM |
7683 | if {[regexp { \+(\d+),\d+ @@} $line m nl]} { |
7684 | set diffline $nl | |
7685 | } | |
7686 | set diffnparents [expr {[string length $ats] - 1}] | |
7eb3cb9c | 7687 | set diffinhdr 0 |
9396cd38 | 7688 | |
5c838d23 JL |
7689 | } elseif {![string compare -length 10 "Submodule " $line]} { |
7690 | # start of a new submodule | |
a1d383c5 JL |
7691 | if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} { |
7692 | set fname [string range $line 10 [expr [lindex $nameend 0] - 2]] | |
7693 | } else { | |
7694 | set fname [string range $line 10 [expr [string first "contains " $line] - 2]] | |
7695 | } | |
7696 | if {$currdiffsubmod != $fname} { | |
5c838d23 JL |
7697 | $ctext insert end "\n"; # Add newline after commit message |
7698 | } | |
7699 | set curdiffstart [$ctext index "end - 1c"] | |
7700 | lappend ctext_file_names "" | |
a1d383c5 JL |
7701 | if {$currdiffsubmod != $fname} { |
7702 | lappend ctext_file_lines $fname | |
7703 | makediffhdr $fname $ids | |
7704 | set currdiffsubmod $fname | |
7705 | $ctext insert end "\n$line\n" filesep | |
7706 | } else { | |
7707 | $ctext insert end "$line\n" filesep | |
7708 | } | |
5c838d23 | 7709 | } elseif {![string compare -length 3 " >" $line]} { |
a1d383c5 | 7710 | set $currdiffsubmod "" |
1f2cecfd | 7711 | set line [encoding convertfrom $diffencoding $line] |
5c838d23 JL |
7712 | $ctext insert end "$line\n" dresult |
7713 | } elseif {![string compare -length 3 " <" $line]} { | |
a1d383c5 | 7714 | set $currdiffsubmod "" |
1f2cecfd | 7715 | set line [encoding convertfrom $diffencoding $line] |
5c838d23 | 7716 | $ctext insert end "$line\n" d0 |
9396cd38 | 7717 | } elseif {$diffinhdr} { |
5e85ec4c | 7718 | if {![string compare -length 12 "rename from " $line]} { |
d1cb298b | 7719 | set fname [string range $line [expr 6 + [string first " from " $line] ] end] |
9396cd38 PM |
7720 | if {[string index $fname 0] eq "\""} { |
7721 | set fname [lindex $fname 0] | |
7722 | } | |
09c7029d | 7723 | set fname [encoding convertfrom $fname] |
9396cd38 PM |
7724 | set i [lsearch -exact $treediffs($ids) $fname] |
7725 | if {$i >= 0} { | |
7726 | setinlist difffilestart $i $curdiffstart | |
7727 | } | |
d1cb298b JS |
7728 | } elseif {![string compare -length 10 $line "rename to "] || |
7729 | ![string compare -length 8 $line "copy to "]} { | |
7730 | set fname [string range $line [expr 4 + [string first " to " $line] ] end] | |
9396cd38 PM |
7731 | if {[string index $fname 0] eq "\""} { |
7732 | set fname [lindex $fname 0] | |
7733 | } | |
7734 | makediffhdr $fname $ids | |
7735 | } elseif {[string compare -length 3 $line "---"] == 0} { | |
7736 | # do nothing | |
7737 | continue | |
7738 | } elseif {[string compare -length 3 $line "+++"] == 0} { | |
7739 | set diffinhdr 0 | |
7740 | continue | |
7741 | } | |
7742 | $ctext insert end "$line\n" filesep | |
7743 | ||
e5c2d856 | 7744 | } else { |
681c3290 PT |
7745 | set line [string map {\x1A ^Z} \ |
7746 | [encoding convertfrom $diffencoding $line]] | |
8b07dca1 PM |
7747 | # parse the prefix - one ' ', '-' or '+' for each parent |
7748 | set prefix [string range $line 0 [expr {$diffnparents - 1}]] | |
7749 | set tag [expr {$diffnparents > 1? "m": "d"}] | |
7750 | if {[string trim $prefix " -+"] eq {}} { | |
7751 | # prefix only has " ", "-" and "+" in it: normal diff line | |
7752 | set num [string first "-" $prefix] | |
7753 | if {$num >= 0} { | |
7754 | # removed line, first parent with line is $num | |
7755 | if {$num >= $mergemax} { | |
7756 | set num "max" | |
7757 | } | |
7758 | $ctext insert end "$line\n" $tag$num | |
7759 | } else { | |
7760 | set tags {} | |
7761 | if {[string first "+" $prefix] >= 0} { | |
7762 | # added line | |
7763 | lappend tags ${tag}result | |
7764 | if {$diffnparents > 1} { | |
7765 | set num [string first " " $prefix] | |
7766 | if {$num >= 0} { | |
7767 | if {$num >= $mergemax} { | |
7768 | set num "max" | |
7769 | } | |
7770 | lappend tags m$num | |
7771 | } | |
7772 | } | |
7773 | } | |
7774 | if {$targetline ne {}} { | |
7775 | if {$diffline == $targetline} { | |
7776 | set seehere [$ctext index "end - 1 chars"] | |
7777 | set targetline {} | |
7778 | } else { | |
7779 | incr diffline | |
7780 | } | |
7781 | } | |
7782 | $ctext insert end "$line\n" $tags | |
7783 | } | |
7eb3cb9c | 7784 | } else { |
9396cd38 PM |
7785 | # "\ No newline at end of file", |
7786 | # or something else we don't recognize | |
7787 | $ctext insert end "$line\n" hunksep | |
e5c2d856 | 7788 | } |
e5c2d856 PM |
7789 | } |
7790 | } | |
8b07dca1 PM |
7791 | if {[info exists seehere]} { |
7792 | mark_ctext_line [lindex [split $seehere .] 0] | |
7793 | } | |
354af6bd | 7794 | maybe_scroll_ctext [eof $bdf] |
e5c2d856 | 7795 | $ctext conf -state disabled |
7eb3cb9c | 7796 | if {[eof $bdf]} { |
c21398be | 7797 | catch {close $bdf} |
7eb3cb9c | 7798 | return 0 |
c8dfbcf9 | 7799 | } |
7eb3cb9c | 7800 | return [expr {$nr >= 1000? 2: 1}] |
e5c2d856 PM |
7801 | } |
7802 | ||
a8d610a2 PM |
7803 | proc changediffdisp {} { |
7804 | global ctext diffelide | |
7805 | ||
7806 | $ctext tag conf d0 -elide [lindex $diffelide 0] | |
8b07dca1 | 7807 | $ctext tag conf dresult -elide [lindex $diffelide 1] |
a8d610a2 PM |
7808 | } |
7809 | ||
f4c54b3c PM |
7810 | proc highlightfile {loc cline} { |
7811 | global ctext cflist cflist_top | |
7812 | ||
7813 | $ctext yview $loc | |
7814 | $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" | |
7815 | $cflist tag add highlight $cline.0 "$cline.0 lineend" | |
7816 | $cflist see $cline.0 | |
7817 | set cflist_top $cline | |
7818 | } | |
7819 | ||
67c22874 | 7820 | proc prevfile {} { |
f4c54b3c PM |
7821 | global difffilestart ctext cmitmode |
7822 | ||
7823 | if {$cmitmode eq "tree"} return | |
7824 | set prev 0.0 | |
7825 | set prevline 1 | |
67c22874 OH |
7826 | set here [$ctext index @0,0] |
7827 | foreach loc $difffilestart { | |
7828 | if {[$ctext compare $loc >= $here]} { | |
f4c54b3c | 7829 | highlightfile $prev $prevline |
67c22874 OH |
7830 | return |
7831 | } | |
7832 | set prev $loc | |
f4c54b3c | 7833 | incr prevline |
67c22874 | 7834 | } |
f4c54b3c | 7835 | highlightfile $prev $prevline |
67c22874 OH |
7836 | } |
7837 | ||
39ad8570 | 7838 | proc nextfile {} { |
f4c54b3c PM |
7839 | global difffilestart ctext cmitmode |
7840 | ||
7841 | if {$cmitmode eq "tree"} return | |
39ad8570 | 7842 | set here [$ctext index @0,0] |
f4c54b3c | 7843 | set line 1 |
7fcceed7 | 7844 | foreach loc $difffilestart { |
f4c54b3c | 7845 | incr line |
7fcceed7 | 7846 | if {[$ctext compare $loc > $here]} { |
f4c54b3c | 7847 | highlightfile $loc $line |
67c22874 | 7848 | return |
39ad8570 PM |
7849 | } |
7850 | } | |
1db95b00 PM |
7851 | } |
7852 | ||
3ea06f9f PM |
7853 | proc clear_ctext {{first 1.0}} { |
7854 | global ctext smarktop smarkbot | |
7cdc3556 | 7855 | global ctext_file_names ctext_file_lines |
97645683 | 7856 | global pendinglinks |
3ea06f9f | 7857 | |
1902c270 PM |
7858 | set l [lindex [split $first .] 0] |
7859 | if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} { | |
7860 | set smarktop $l | |
3ea06f9f | 7861 | } |
1902c270 PM |
7862 | if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} { |
7863 | set smarkbot $l | |
3ea06f9f PM |
7864 | } |
7865 | $ctext delete $first end | |
97645683 PM |
7866 | if {$first eq "1.0"} { |
7867 | catch {unset pendinglinks} | |
7868 | } | |
7cdc3556 AG |
7869 | set ctext_file_names {} |
7870 | set ctext_file_lines {} | |
3ea06f9f PM |
7871 | } |
7872 | ||
32f1b3e4 | 7873 | proc settabs {{firstab {}}} { |
9c311b32 | 7874 | global firsttabstop tabstop ctext have_tk85 |
32f1b3e4 PM |
7875 | |
7876 | if {$firstab ne {} && $have_tk85} { | |
7877 | set firsttabstop $firstab | |
7878 | } | |
9c311b32 | 7879 | set w [font measure textfont "0"] |
32f1b3e4 | 7880 | if {$firsttabstop != 0} { |
64b5f146 PM |
7881 | $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \ |
7882 | [expr {($firsttabstop + 2 * $tabstop) * $w}]] | |
32f1b3e4 PM |
7883 | } elseif {$have_tk85 || $tabstop != 8} { |
7884 | $ctext conf -tabs [expr {$tabstop * $w}] | |
7885 | } else { | |
7886 | $ctext conf -tabs {} | |
7887 | } | |
3ea06f9f PM |
7888 | } |
7889 | ||
7890 | proc incrsearch {name ix op} { | |
1902c270 | 7891 | global ctext searchstring searchdirn |
3ea06f9f PM |
7892 | |
7893 | $ctext tag remove found 1.0 end | |
1902c270 PM |
7894 | if {[catch {$ctext index anchor}]} { |
7895 | # no anchor set, use start of selection, or of visible area | |
7896 | set sel [$ctext tag ranges sel] | |
7897 | if {$sel ne {}} { | |
7898 | $ctext mark set anchor [lindex $sel 0] | |
7899 | } elseif {$searchdirn eq "-forwards"} { | |
7900 | $ctext mark set anchor @0,0 | |
7901 | } else { | |
7902 | $ctext mark set anchor @0,[winfo height $ctext] | |
7903 | } | |
7904 | } | |
3ea06f9f | 7905 | if {$searchstring ne {}} { |
1902c270 PM |
7906 | set here [$ctext search $searchdirn -- $searchstring anchor] |
7907 | if {$here ne {}} { | |
7908 | $ctext see $here | |
7909 | } | |
3ea06f9f PM |
7910 | searchmarkvisible 1 |
7911 | } | |
7912 | } | |
7913 | ||
7914 | proc dosearch {} { | |
1902c270 | 7915 | global sstring ctext searchstring searchdirn |
3ea06f9f PM |
7916 | |
7917 | focus $sstring | |
7918 | $sstring icursor end | |
1902c270 PM |
7919 | set searchdirn -forwards |
7920 | if {$searchstring ne {}} { | |
7921 | set sel [$ctext tag ranges sel] | |
7922 | if {$sel ne {}} { | |
7923 | set start "[lindex $sel 0] + 1c" | |
7924 | } elseif {[catch {set start [$ctext index anchor]}]} { | |
7925 | set start "@0,0" | |
7926 | } | |
7927 | set match [$ctext search -count mlen -- $searchstring $start] | |
7928 | $ctext tag remove sel 1.0 end | |
7929 | if {$match eq {}} { | |
7930 | bell | |
7931 | return | |
7932 | } | |
7933 | $ctext see $match | |
7934 | set mend "$match + $mlen c" | |
7935 | $ctext tag add sel $match $mend | |
7936 | $ctext mark unset anchor | |
7937 | } | |
7938 | } | |
7939 | ||
7940 | proc dosearchback {} { | |
7941 | global sstring ctext searchstring searchdirn | |
7942 | ||
7943 | focus $sstring | |
7944 | $sstring icursor end | |
7945 | set searchdirn -backwards | |
7946 | if {$searchstring ne {}} { | |
7947 | set sel [$ctext tag ranges sel] | |
7948 | if {$sel ne {}} { | |
7949 | set start [lindex $sel 0] | |
7950 | } elseif {[catch {set start [$ctext index anchor]}]} { | |
7951 | set start @0,[winfo height $ctext] | |
7952 | } | |
7953 | set match [$ctext search -backwards -count ml -- $searchstring $start] | |
7954 | $ctext tag remove sel 1.0 end | |
7955 | if {$match eq {}} { | |
7956 | bell | |
7957 | return | |
7958 | } | |
7959 | $ctext see $match | |
7960 | set mend "$match + $ml c" | |
7961 | $ctext tag add sel $match $mend | |
7962 | $ctext mark unset anchor | |
3ea06f9f | 7963 | } |
3ea06f9f PM |
7964 | } |
7965 | ||
7966 | proc searchmark {first last} { | |
7967 | global ctext searchstring | |
7968 | ||
7969 | set mend $first.0 | |
7970 | while {1} { | |
7971 | set match [$ctext search -count mlen -- $searchstring $mend $last.end] | |
7972 | if {$match eq {}} break | |
7973 | set mend "$match + $mlen c" | |
7974 | $ctext tag add found $match $mend | |
7975 | } | |
7976 | } | |
7977 | ||
7978 | proc searchmarkvisible {doall} { | |
7979 | global ctext smarktop smarkbot | |
7980 | ||
7981 | set topline [lindex [split [$ctext index @0,0] .] 0] | |
7982 | set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0] | |
7983 | if {$doall || $botline < $smarktop || $topline > $smarkbot} { | |
7984 | # no overlap with previous | |
7985 | searchmark $topline $botline | |
7986 | set smarktop $topline | |
7987 | set smarkbot $botline | |
7988 | } else { | |
7989 | if {$topline < $smarktop} { | |
7990 | searchmark $topline [expr {$smarktop-1}] | |
7991 | set smarktop $topline | |
7992 | } | |
7993 | if {$botline > $smarkbot} { | |
7994 | searchmark [expr {$smarkbot+1}] $botline | |
7995 | set smarkbot $botline | |
7996 | } | |
7997 | } | |
7998 | } | |
7999 | ||
8000 | proc scrolltext {f0 f1} { | |
1902c270 | 8001 | global searchstring |
3ea06f9f | 8002 | |
8809d691 | 8003 | .bleft.bottom.sb set $f0 $f1 |
3ea06f9f PM |
8004 | if {$searchstring ne {}} { |
8005 | searchmarkvisible 0 | |
8006 | } | |
8007 | } | |
8008 | ||
1d10f36d | 8009 | proc setcoords {} { |
9c311b32 | 8010 | global linespc charspc canvx0 canvy0 |
f6075eba | 8011 | global xspc1 xspc2 lthickness |
8d858d1a | 8012 | |
9c311b32 PM |
8013 | set linespc [font metrics mainfont -linespace] |
8014 | set charspc [font measure mainfont "m"] | |
9f1afe05 PM |
8015 | set canvy0 [expr {int(3 + 0.5 * $linespc)}] |
8016 | set canvx0 [expr {int(3 + 0.5 * $linespc)}] | |
f6075eba | 8017 | set lthickness [expr {int($linespc / 9) + 1}] |
8d858d1a PM |
8018 | set xspc1(0) $linespc |
8019 | set xspc2 $linespc | |
9a40c50c | 8020 | } |
1db95b00 | 8021 | |
1d10f36d | 8022 | proc redisplay {} { |
be0cd098 | 8023 | global canv |
9f1afe05 PM |
8024 | global selectedline |
8025 | ||
8026 | set ymax [lindex [$canv cget -scrollregion] 3] | |
8027 | if {$ymax eq {} || $ymax == 0} return | |
8028 | set span [$canv yview] | |
8029 | clear_display | |
be0cd098 | 8030 | setcanvscroll |
9f1afe05 PM |
8031 | allcanvs yview moveto [lindex $span 0] |
8032 | drawvisible | |
94b4a69f | 8033 | if {$selectedline ne {}} { |
9f1afe05 | 8034 | selectline $selectedline 0 |
ca6d8f58 | 8035 | allcanvs yview moveto [lindex $span 0] |
1d10f36d PM |
8036 | } |
8037 | } | |
8038 | ||
0ed1dd3c PM |
8039 | proc parsefont {f n} { |
8040 | global fontattr | |
8041 | ||
8042 | set fontattr($f,family) [lindex $n 0] | |
8043 | set s [lindex $n 1] | |
8044 | if {$s eq {} || $s == 0} { | |
8045 | set s 10 | |
8046 | } elseif {$s < 0} { | |
8047 | set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}] | |
9c311b32 | 8048 | } |
0ed1dd3c PM |
8049 | set fontattr($f,size) $s |
8050 | set fontattr($f,weight) normal | |
8051 | set fontattr($f,slant) roman | |
8052 | foreach style [lrange $n 2 end] { | |
8053 | switch -- $style { | |
8054 | "normal" - | |
8055 | "bold" {set fontattr($f,weight) $style} | |
8056 | "roman" - | |
8057 | "italic" {set fontattr($f,slant) $style} | |
8058 | } | |
9c311b32 | 8059 | } |
0ed1dd3c PM |
8060 | } |
8061 | ||
8062 | proc fontflags {f {isbold 0}} { | |
8063 | global fontattr | |
8064 | ||
8065 | return [list -family $fontattr($f,family) -size $fontattr($f,size) \ | |
8066 | -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \ | |
8067 | -slant $fontattr($f,slant)] | |
8068 | } | |
8069 | ||
8070 | proc fontname {f} { | |
8071 | global fontattr | |
8072 | ||
8073 | set n [list $fontattr($f,family) $fontattr($f,size)] | |
8074 | if {$fontattr($f,weight) eq "bold"} { | |
8075 | lappend n "bold" | |
9c311b32 | 8076 | } |
0ed1dd3c PM |
8077 | if {$fontattr($f,slant) eq "italic"} { |
8078 | lappend n "italic" | |
9c311b32 | 8079 | } |
0ed1dd3c | 8080 | return $n |
9c311b32 PM |
8081 | } |
8082 | ||
1d10f36d | 8083 | proc incrfont {inc} { |
7fcc92bf | 8084 | global mainfont textfont ctext canv cflist showrefstop |
0ed1dd3c PM |
8085 | global stopped entries fontattr |
8086 | ||
1d10f36d | 8087 | unmarkmatches |
0ed1dd3c | 8088 | set s $fontattr(mainfont,size) |
9c311b32 PM |
8089 | incr s $inc |
8090 | if {$s < 1} { | |
8091 | set s 1 | |
8092 | } | |
0ed1dd3c | 8093 | set fontattr(mainfont,size) $s |
9c311b32 PM |
8094 | font config mainfont -size $s |
8095 | font config mainfontbold -size $s | |
0ed1dd3c PM |
8096 | set mainfont [fontname mainfont] |
8097 | set s $fontattr(textfont,size) | |
9c311b32 PM |
8098 | incr s $inc |
8099 | if {$s < 1} { | |
8100 | set s 1 | |
8101 | } | |
0ed1dd3c | 8102 | set fontattr(textfont,size) $s |
9c311b32 PM |
8103 | font config textfont -size $s |
8104 | font config textfontbold -size $s | |
0ed1dd3c | 8105 | set textfont [fontname textfont] |
1d10f36d | 8106 | setcoords |
32f1b3e4 | 8107 | settabs |
1d10f36d PM |
8108 | redisplay |
8109 | } | |
1db95b00 | 8110 | |
ee3dc72e PM |
8111 | proc clearsha1 {} { |
8112 | global sha1entry sha1string | |
8113 | if {[string length $sha1string] == 40} { | |
8114 | $sha1entry delete 0 end | |
8115 | } | |
8116 | } | |
8117 | ||
887fe3c4 PM |
8118 | proc sha1change {n1 n2 op} { |
8119 | global sha1string currentid sha1but | |
8120 | if {$sha1string == {} | |
8121 | || ([info exists currentid] && $sha1string == $currentid)} { | |
8122 | set state disabled | |
8123 | } else { | |
8124 | set state normal | |
8125 | } | |
8126 | if {[$sha1but cget -state] == $state} return | |
8127 | if {$state == "normal"} { | |
d990cedf | 8128 | $sha1but conf -state normal -relief raised -text "[mc "Goto:"] " |
887fe3c4 | 8129 | } else { |
d990cedf | 8130 | $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] " |
887fe3c4 PM |
8131 | } |
8132 | } | |
8133 | ||
8134 | proc gotocommit {} { | |
7fcc92bf | 8135 | global sha1string tagids headids curview varcid |
f3b8b3ce | 8136 | |
887fe3c4 PM |
8137 | if {$sha1string == {} |
8138 | || ([info exists currentid] && $sha1string == $currentid)} return | |
8139 | if {[info exists tagids($sha1string)]} { | |
8140 | set id $tagids($sha1string) | |
e1007129 SR |
8141 | } elseif {[info exists headids($sha1string)]} { |
8142 | set id $headids($sha1string) | |
887fe3c4 PM |
8143 | } else { |
8144 | set id [string tolower $sha1string] | |
f3b8b3ce | 8145 | if {[regexp {^[0-9a-f]{4,39}$} $id]} { |
d375ef9b | 8146 | set matches [longid $id] |
f3b8b3ce PM |
8147 | if {$matches ne {}} { |
8148 | if {[llength $matches] > 1} { | |
d990cedf | 8149 | error_popup [mc "Short SHA1 id %s is ambiguous" $id] |
f3b8b3ce PM |
8150 | return |
8151 | } | |
d375ef9b | 8152 | set id [lindex $matches 0] |
f3b8b3ce | 8153 | } |
9bf3acfa TR |
8154 | } else { |
8155 | if {[catch {set id [exec git rev-parse --verify $sha1string]}]} { | |
8156 | error_popup [mc "Revision %s is not known" $sha1string] | |
8157 | return | |
8158 | } | |
f3b8b3ce | 8159 | } |
887fe3c4 | 8160 | } |
7fcc92bf PM |
8161 | if {[commitinview $id $curview]} { |
8162 | selectline [rowofcommit $id] 1 | |
887fe3c4 PM |
8163 | return |
8164 | } | |
f3b8b3ce | 8165 | if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} { |
d990cedf | 8166 | set msg [mc "SHA1 id %s is not known" $sha1string] |
887fe3c4 | 8167 | } else { |
9bf3acfa | 8168 | set msg [mc "Revision %s is not in the current view" $sha1string] |
887fe3c4 | 8169 | } |
d990cedf | 8170 | error_popup $msg |
887fe3c4 PM |
8171 | } |
8172 | ||
84ba7345 PM |
8173 | proc lineenter {x y id} { |
8174 | global hoverx hovery hoverid hovertimer | |
8175 | global commitinfo canv | |
8176 | ||
8ed16484 | 8177 | if {![info exists commitinfo($id)] && ![getcommit $id]} return |
84ba7345 PM |
8178 | set hoverx $x |
8179 | set hovery $y | |
8180 | set hoverid $id | |
8181 | if {[info exists hovertimer]} { | |
8182 | after cancel $hovertimer | |
8183 | } | |
8184 | set hovertimer [after 500 linehover] | |
8185 | $canv delete hover | |
8186 | } | |
8187 | ||
8188 | proc linemotion {x y id} { | |
8189 | global hoverx hovery hoverid hovertimer | |
8190 | ||
8191 | if {[info exists hoverid] && $id == $hoverid} { | |
8192 | set hoverx $x | |
8193 | set hovery $y | |
8194 | if {[info exists hovertimer]} { | |
8195 | after cancel $hovertimer | |
8196 | } | |
8197 | set hovertimer [after 500 linehover] | |
8198 | } | |
8199 | } | |
8200 | ||
8201 | proc lineleave {id} { | |
8202 | global hoverid hovertimer canv | |
8203 | ||
8204 | if {[info exists hoverid] && $id == $hoverid} { | |
8205 | $canv delete hover | |
8206 | if {[info exists hovertimer]} { | |
8207 | after cancel $hovertimer | |
8208 | unset hovertimer | |
8209 | } | |
8210 | unset hoverid | |
8211 | } | |
8212 | } | |
8213 | ||
8214 | proc linehover {} { | |
8215 | global hoverx hovery hoverid hovertimer | |
8216 | global canv linespc lthickness | |
9c311b32 | 8217 | global commitinfo |
84ba7345 PM |
8218 | |
8219 | set text [lindex $commitinfo($hoverid) 0] | |
8220 | set ymax [lindex [$canv cget -scrollregion] 3] | |
8221 | if {$ymax == {}} return | |
8222 | set yfrac [lindex [$canv yview] 0] | |
8223 | set x [expr {$hoverx + 2 * $linespc}] | |
8224 | set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}] | |
8225 | set x0 [expr {$x - 2 * $lthickness}] | |
8226 | set y0 [expr {$y - 2 * $lthickness}] | |
9c311b32 | 8227 | set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}] |
84ba7345 PM |
8228 | set y1 [expr {$y + $linespc + 2 * $lthickness}] |
8229 | set t [$canv create rectangle $x0 $y0 $x1 $y1 \ | |
8230 | -fill \#ffff80 -outline black -width 1 -tags hover] | |
8231 | $canv raise $t | |
f8a2c0d1 | 8232 | set t [$canv create text $x $y -anchor nw -text $text -tags hover \ |
9c311b32 | 8233 | -font mainfont] |
84ba7345 PM |
8234 | $canv raise $t |
8235 | } | |
8236 | ||
9843c307 | 8237 | proc clickisonarrow {id y} { |
50b44ece | 8238 | global lthickness |
9843c307 | 8239 | |
50b44ece | 8240 | set ranges [rowranges $id] |
9843c307 | 8241 | set thresh [expr {2 * $lthickness + 6}] |
50b44ece | 8242 | set n [expr {[llength $ranges] - 1}] |
f6342480 | 8243 | for {set i 1} {$i < $n} {incr i} { |
50b44ece | 8244 | set row [lindex $ranges $i] |
f6342480 PM |
8245 | if {abs([yc $row] - $y) < $thresh} { |
8246 | return $i | |
9843c307 PM |
8247 | } |
8248 | } | |
8249 | return {} | |
8250 | } | |
8251 | ||
f6342480 | 8252 | proc arrowjump {id n y} { |
50b44ece | 8253 | global canv |
9843c307 | 8254 | |
f6342480 PM |
8255 | # 1 <-> 2, 3 <-> 4, etc... |
8256 | set n [expr {(($n - 1) ^ 1) + 1}] | |
50b44ece | 8257 | set row [lindex [rowranges $id] $n] |
f6342480 | 8258 | set yt [yc $row] |
9843c307 PM |
8259 | set ymax [lindex [$canv cget -scrollregion] 3] |
8260 | if {$ymax eq {} || $ymax <= 0} return | |
8261 | set view [$canv yview] | |
8262 | set yspan [expr {[lindex $view 1] - [lindex $view 0]}] | |
8263 | set yfrac [expr {$yt / $ymax - $yspan / 2}] | |
8264 | if {$yfrac < 0} { | |
8265 | set yfrac 0 | |
8266 | } | |
f6342480 | 8267 | allcanvs yview moveto $yfrac |
9843c307 PM |
8268 | } |
8269 | ||
fa4da7b3 | 8270 | proc lineclick {x y id isnew} { |
7fcc92bf | 8271 | global ctext commitinfo children canv thickerline curview |
c8dfbcf9 | 8272 | |
8ed16484 | 8273 | if {![info exists commitinfo($id)] && ![getcommit $id]} return |
c8dfbcf9 | 8274 | unmarkmatches |
fa4da7b3 | 8275 | unselectline |
9843c307 PM |
8276 | normalline |
8277 | $canv delete hover | |
8278 | # draw this line thicker than normal | |
9843c307 | 8279 | set thickerline $id |
c934a8a3 | 8280 | drawlines $id |
fa4da7b3 | 8281 | if {$isnew} { |
9843c307 PM |
8282 | set ymax [lindex [$canv cget -scrollregion] 3] |
8283 | if {$ymax eq {}} return | |
8284 | set yfrac [lindex [$canv yview] 0] | |
8285 | set y [expr {$y + $yfrac * $ymax}] | |
8286 | } | |
8287 | set dirn [clickisonarrow $id $y] | |
8288 | if {$dirn ne {}} { | |
8289 | arrowjump $id $dirn $y | |
8290 | return | |
8291 | } | |
8292 | ||
8293 | if {$isnew} { | |
354af6bd | 8294 | addtohistory [list lineclick $x $y $id 0] savectextpos |
fa4da7b3 | 8295 | } |
c8dfbcf9 PM |
8296 | # fill the details pane with info about this line |
8297 | $ctext conf -state normal | |
3ea06f9f | 8298 | clear_ctext |
32f1b3e4 | 8299 | settabs 0 |
d990cedf | 8300 | $ctext insert end "[mc "Parent"]:\t" |
97645683 PM |
8301 | $ctext insert end $id link0 |
8302 | setlink $id link0 | |
c8dfbcf9 | 8303 | set info $commitinfo($id) |
fa4da7b3 | 8304 | $ctext insert end "\n\t[lindex $info 0]\n" |
d990cedf | 8305 | $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n" |
232475d3 | 8306 | set date [formatdate [lindex $info 2]] |
d990cedf | 8307 | $ctext insert end "\t[mc "Date"]:\t$date\n" |
da7c24dd | 8308 | set kids $children($curview,$id) |
79b2c75e | 8309 | if {$kids ne {}} { |
d990cedf | 8310 | $ctext insert end "\n[mc "Children"]:" |
fa4da7b3 | 8311 | set i 0 |
79b2c75e | 8312 | foreach child $kids { |
fa4da7b3 | 8313 | incr i |
8ed16484 | 8314 | if {![info exists commitinfo($child)] && ![getcommit $child]} continue |
c8dfbcf9 | 8315 | set info $commitinfo($child) |
fa4da7b3 | 8316 | $ctext insert end "\n\t" |
97645683 PM |
8317 | $ctext insert end $child link$i |
8318 | setlink $child link$i | |
fa4da7b3 | 8319 | $ctext insert end "\n\t[lindex $info 0]" |
d990cedf | 8320 | $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]" |
232475d3 | 8321 | set date [formatdate [lindex $info 2]] |
d990cedf | 8322 | $ctext insert end "\n\t[mc "Date"]:\t$date\n" |
c8dfbcf9 PM |
8323 | } |
8324 | } | |
354af6bd | 8325 | maybe_scroll_ctext 1 |
c8dfbcf9 | 8326 | $ctext conf -state disabled |
7fcceed7 | 8327 | init_flist {} |
c8dfbcf9 PM |
8328 | } |
8329 | ||
9843c307 PM |
8330 | proc normalline {} { |
8331 | global thickerline | |
8332 | if {[info exists thickerline]} { | |
c934a8a3 | 8333 | set id $thickerline |
9843c307 | 8334 | unset thickerline |
c934a8a3 | 8335 | drawlines $id |
9843c307 PM |
8336 | } |
8337 | } | |
8338 | ||
354af6bd | 8339 | proc selbyid {id {isnew 1}} { |
7fcc92bf PM |
8340 | global curview |
8341 | if {[commitinview $id $curview]} { | |
354af6bd | 8342 | selectline [rowofcommit $id] $isnew |
c8dfbcf9 PM |
8343 | } |
8344 | } | |
8345 | ||
8346 | proc mstime {} { | |
8347 | global startmstime | |
8348 | if {![info exists startmstime]} { | |
8349 | set startmstime [clock clicks -milliseconds] | |
8350 | } | |
8351 | return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]] | |
8352 | } | |
8353 | ||
8354 | proc rowmenu {x y id} { | |
7fcc92bf | 8355 | global rowctxmenu selectedline rowmenuid curview |
b9fdba7f | 8356 | global nullid nullid2 fakerowmenu mainhead markedid |
c8dfbcf9 | 8357 | |
bb3edc8b | 8358 | stopfinding |
219ea3a9 | 8359 | set rowmenuid $id |
94b4a69f | 8360 | if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} { |
c8dfbcf9 PM |
8361 | set state disabled |
8362 | } else { | |
8363 | set state normal | |
8364 | } | |
8f489363 | 8365 | if {$id ne $nullid && $id ne $nullid2} { |
219ea3a9 | 8366 | set menu $rowctxmenu |
5e3502da | 8367 | if {$mainhead ne {}} { |
da12e59d | 8368 | $menu entryconfigure 7 -label [mc "Reset %s branch to here" $mainhead] -state normal |
5e3502da MB |
8369 | } else { |
8370 | $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled | |
8371 | } | |
b9fdba7f PM |
8372 | if {[info exists markedid] && $markedid ne $id} { |
8373 | $menu entryconfigure 9 -state normal | |
8374 | $menu entryconfigure 10 -state normal | |
010509f2 | 8375 | $menu entryconfigure 11 -state normal |
b9fdba7f PM |
8376 | } else { |
8377 | $menu entryconfigure 9 -state disabled | |
8378 | $menu entryconfigure 10 -state disabled | |
010509f2 | 8379 | $menu entryconfigure 11 -state disabled |
b9fdba7f | 8380 | } |
219ea3a9 PM |
8381 | } else { |
8382 | set menu $fakerowmenu | |
8383 | } | |
f2d0bbbd PM |
8384 | $menu entryconfigure [mca "Diff this -> selected"] -state $state |
8385 | $menu entryconfigure [mca "Diff selected -> this"] -state $state | |
8386 | $menu entryconfigure [mca "Make patch"] -state $state | |
219ea3a9 | 8387 | tk_popup $menu $x $y |
c8dfbcf9 PM |
8388 | } |
8389 | ||
b9fdba7f PM |
8390 | proc markhere {} { |
8391 | global rowmenuid markedid canv | |
8392 | ||
8393 | set markedid $rowmenuid | |
8394 | make_idmark $markedid | |
8395 | } | |
8396 | ||
8397 | proc gotomark {} { | |
8398 | global markedid | |
8399 | ||
8400 | if {[info exists markedid]} { | |
8401 | selbyid $markedid | |
8402 | } | |
8403 | } | |
8404 | ||
8405 | proc replace_by_kids {l r} { | |
8406 | global curview children | |
8407 | ||
8408 | set id [commitonrow $r] | |
8409 | set l [lreplace $l 0 0] | |
8410 | foreach kid $children($curview,$id) { | |
8411 | lappend l [rowofcommit $kid] | |
8412 | } | |
8413 | return [lsort -integer -decreasing -unique $l] | |
8414 | } | |
8415 | ||
8416 | proc find_common_desc {} { | |
8417 | global markedid rowmenuid curview children | |
8418 | ||
8419 | if {![info exists markedid]} return | |
8420 | if {![commitinview $markedid $curview] || | |
8421 | ![commitinview $rowmenuid $curview]} return | |
8422 | #set t1 [clock clicks -milliseconds] | |
8423 | set l1 [list [rowofcommit $markedid]] | |
8424 | set l2 [list [rowofcommit $rowmenuid]] | |
8425 | while 1 { | |
8426 | set r1 [lindex $l1 0] | |
8427 | set r2 [lindex $l2 0] | |
8428 | if {$r1 eq {} || $r2 eq {}} break | |
8429 | if {$r1 == $r2} { | |
8430 | selectline $r1 1 | |
8431 | break | |
8432 | } | |
8433 | if {$r1 > $r2} { | |
8434 | set l1 [replace_by_kids $l1 $r1] | |
8435 | } else { | |
8436 | set l2 [replace_by_kids $l2 $r2] | |
8437 | } | |
8438 | } | |
8439 | #set t2 [clock clicks -milliseconds] | |
8440 | #puts "took [expr {$t2-$t1}]ms" | |
8441 | } | |
8442 | ||
010509f2 PM |
8443 | proc compare_commits {} { |
8444 | global markedid rowmenuid curview children | |
8445 | ||
8446 | if {![info exists markedid]} return | |
8447 | if {![commitinview $markedid $curview]} return | |
8448 | addtohistory [list do_cmp_commits $markedid $rowmenuid] | |
8449 | do_cmp_commits $markedid $rowmenuid | |
8450 | } | |
8451 | ||
8452 | proc getpatchid {id} { | |
8453 | global patchids | |
8454 | ||
8455 | if {![info exists patchids($id)]} { | |
6f63fc18 PM |
8456 | set cmd [diffcmd [list $id] {-p --root}] |
8457 | # trim off the initial "|" | |
8458 | set cmd [lrange $cmd 1 end] | |
8459 | if {[catch { | |
8460 | set x [eval exec $cmd | git patch-id] | |
8461 | set patchids($id) [lindex $x 0] | |
8462 | }]} { | |
8463 | set patchids($id) "error" | |
8464 | } | |
010509f2 PM |
8465 | } |
8466 | return $patchids($id) | |
8467 | } | |
8468 | ||
8469 | proc do_cmp_commits {a b} { | |
8470 | global ctext curview parents children patchids commitinfo | |
8471 | ||
8472 | $ctext conf -state normal | |
8473 | clear_ctext | |
8474 | init_flist {} | |
8475 | for {set i 0} {$i < 100} {incr i} { | |
010509f2 PM |
8476 | set skipa 0 |
8477 | set skipb 0 | |
8478 | if {[llength $parents($curview,$a)] > 1} { | |
6f63fc18 | 8479 | appendshortlink $a [mc "Skipping merge commit "] "\n" |
010509f2 PM |
8480 | set skipa 1 |
8481 | } else { | |
8482 | set patcha [getpatchid $a] | |
8483 | } | |
8484 | if {[llength $parents($curview,$b)] > 1} { | |
6f63fc18 | 8485 | appendshortlink $b [mc "Skipping merge commit "] "\n" |
010509f2 PM |
8486 | set skipb 1 |
8487 | } else { | |
8488 | set patchb [getpatchid $b] | |
8489 | } | |
8490 | if {!$skipa && !$skipb} { | |
8491 | set heada [lindex $commitinfo($a) 0] | |
8492 | set headb [lindex $commitinfo($b) 0] | |
6f63fc18 PM |
8493 | if {$patcha eq "error"} { |
8494 | appendshortlink $a [mc "Error getting patch ID for "] \ | |
8495 | [mc " - stopping\n"] | |
8496 | break | |
8497 | } | |
8498 | if {$patchb eq "error"} { | |
8499 | appendshortlink $b [mc "Error getting patch ID for "] \ | |
8500 | [mc " - stopping\n"] | |
8501 | break | |
8502 | } | |
010509f2 PM |
8503 | if {$patcha eq $patchb} { |
8504 | if {$heada eq $headb} { | |
6f63fc18 PM |
8505 | appendshortlink $a [mc "Commit "] |
8506 | appendshortlink $b " == " " $heada\n" | |
010509f2 | 8507 | } else { |
6f63fc18 PM |
8508 | appendshortlink $a [mc "Commit "] " $heada\n" |
8509 | appendshortlink $b [mc " is the same patch as\n "] \ | |
8510 | " $headb\n" | |
010509f2 PM |
8511 | } |
8512 | set skipa 1 | |
8513 | set skipb 1 | |
8514 | } else { | |
8515 | $ctext insert end "\n" | |
6f63fc18 PM |
8516 | appendshortlink $a [mc "Commit "] " $heada\n" |
8517 | appendshortlink $b [mc " differs from\n "] \ | |
8518 | " $headb\n" | |
c21398be PM |
8519 | $ctext insert end [mc "Diff of commits:\n\n"] |
8520 | $ctext conf -state disabled | |
8521 | update | |
8522 | diffcommits $a $b | |
8523 | return | |
010509f2 PM |
8524 | } |
8525 | } | |
8526 | if {$skipa} { | |
aa43561a PM |
8527 | set kids [real_children $curview,$a] |
8528 | if {[llength $kids] != 1} { | |
010509f2 | 8529 | $ctext insert end "\n" |
6f63fc18 | 8530 | appendshortlink $a [mc "Commit "] \ |
aa43561a | 8531 | [mc " has %s children - stopping\n" [llength $kids]] |
010509f2 PM |
8532 | break |
8533 | } | |
aa43561a | 8534 | set a [lindex $kids 0] |
010509f2 PM |
8535 | } |
8536 | if {$skipb} { | |
aa43561a PM |
8537 | set kids [real_children $curview,$b] |
8538 | if {[llength $kids] != 1} { | |
6f63fc18 | 8539 | appendshortlink $b [mc "Commit "] \ |
aa43561a | 8540 | [mc " has %s children - stopping\n" [llength $kids]] |
010509f2 PM |
8541 | break |
8542 | } | |
aa43561a | 8543 | set b [lindex $kids 0] |
010509f2 PM |
8544 | } |
8545 | } | |
8546 | $ctext conf -state disabled | |
8547 | } | |
8548 | ||
c21398be | 8549 | proc diffcommits {a b} { |
a1d383c5 | 8550 | global diffcontext diffids blobdifffd diffinhdr currdiffsubmod |
c21398be PM |
8551 | |
8552 | set tmpdir [gitknewtmpdir] | |
8553 | set fna [file join $tmpdir "commit-[string range $a 0 7]"] | |
8554 | set fnb [file join $tmpdir "commit-[string range $b 0 7]"] | |
8555 | if {[catch { | |
8556 | exec git diff-tree -p --pretty $a >$fna | |
8557 | exec git diff-tree -p --pretty $b >$fnb | |
8558 | } err]} { | |
8559 | error_popup [mc "Error writing commit to file: %s" $err] | |
8560 | return | |
8561 | } | |
8562 | if {[catch { | |
8563 | set fd [open "| diff -U$diffcontext $fna $fnb" r] | |
8564 | } err]} { | |
8565 | error_popup [mc "Error diffing commits: %s" $err] | |
8566 | return | |
8567 | } | |
8568 | set diffids [list commits $a $b] | |
8569 | set blobdifffd($diffids) $fd | |
8570 | set diffinhdr 0 | |
a1d383c5 | 8571 | set currdiffsubmod "" |
c21398be PM |
8572 | filerun $fd [list getblobdiffline $fd $diffids] |
8573 | } | |
8574 | ||
c8dfbcf9 | 8575 | proc diffvssel {dirn} { |
7fcc92bf | 8576 | global rowmenuid selectedline |
c8dfbcf9 | 8577 | |
94b4a69f | 8578 | if {$selectedline eq {}} return |
c8dfbcf9 | 8579 | if {$dirn} { |
7fcc92bf | 8580 | set oldid [commitonrow $selectedline] |
c8dfbcf9 PM |
8581 | set newid $rowmenuid |
8582 | } else { | |
8583 | set oldid $rowmenuid | |
7fcc92bf | 8584 | set newid [commitonrow $selectedline] |
c8dfbcf9 | 8585 | } |
354af6bd | 8586 | addtohistory [list doseldiff $oldid $newid] savectextpos |
fa4da7b3 PM |
8587 | doseldiff $oldid $newid |
8588 | } | |
8589 | ||
8590 | proc doseldiff {oldid newid} { | |
7fcceed7 | 8591 | global ctext |
fa4da7b3 PM |
8592 | global commitinfo |
8593 | ||
c8dfbcf9 | 8594 | $ctext conf -state normal |
3ea06f9f | 8595 | clear_ctext |
d990cedf CS |
8596 | init_flist [mc "Top"] |
8597 | $ctext insert end "[mc "From"] " | |
97645683 PM |
8598 | $ctext insert end $oldid link0 |
8599 | setlink $oldid link0 | |
fa4da7b3 | 8600 | $ctext insert end "\n " |
c8dfbcf9 | 8601 | $ctext insert end [lindex $commitinfo($oldid) 0] |
d990cedf | 8602 | $ctext insert end "\n\n[mc "To"] " |
97645683 PM |
8603 | $ctext insert end $newid link1 |
8604 | setlink $newid link1 | |
fa4da7b3 | 8605 | $ctext insert end "\n " |
c8dfbcf9 PM |
8606 | $ctext insert end [lindex $commitinfo($newid) 0] |
8607 | $ctext insert end "\n" | |
8608 | $ctext conf -state disabled | |
c8dfbcf9 | 8609 | $ctext tag remove found 1.0 end |
d327244a | 8610 | startdiff [list $oldid $newid] |
c8dfbcf9 PM |
8611 | } |
8612 | ||
74daedb6 | 8613 | proc mkpatch {} { |
d93f1713 | 8614 | global rowmenuid currentid commitinfo patchtop patchnum NS |
74daedb6 PM |
8615 | |
8616 | if {![info exists currentid]} return | |
8617 | set oldid $currentid | |
8618 | set oldhead [lindex $commitinfo($oldid) 0] | |
8619 | set newid $rowmenuid | |
8620 | set newhead [lindex $commitinfo($newid) 0] | |
8621 | set top .patch | |
8622 | set patchtop $top | |
8623 | catch {destroy $top} | |
d93f1713 | 8624 | ttk_toplevel $top |
e7d64008 | 8625 | make_transient $top . |
d93f1713 | 8626 | ${NS}::label $top.title -text [mc "Generate patch"] |
4a2139f5 | 8627 | grid $top.title - -pady 10 |
d93f1713 PT |
8628 | ${NS}::label $top.from -text [mc "From:"] |
8629 | ${NS}::entry $top.fromsha1 -width 40 | |
74daedb6 PM |
8630 | $top.fromsha1 insert 0 $oldid |
8631 | $top.fromsha1 conf -state readonly | |
8632 | grid $top.from $top.fromsha1 -sticky w | |
d93f1713 | 8633 | ${NS}::entry $top.fromhead -width 60 |
74daedb6 PM |
8634 | $top.fromhead insert 0 $oldhead |
8635 | $top.fromhead conf -state readonly | |
8636 | grid x $top.fromhead -sticky w | |
d93f1713 PT |
8637 | ${NS}::label $top.to -text [mc "To:"] |
8638 | ${NS}::entry $top.tosha1 -width 40 | |
74daedb6 PM |
8639 | $top.tosha1 insert 0 $newid |
8640 | $top.tosha1 conf -state readonly | |
8641 | grid $top.to $top.tosha1 -sticky w | |
d93f1713 | 8642 | ${NS}::entry $top.tohead -width 60 |
74daedb6 PM |
8643 | $top.tohead insert 0 $newhead |
8644 | $top.tohead conf -state readonly | |
8645 | grid x $top.tohead -sticky w | |
d93f1713 PT |
8646 | ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev |
8647 | grid $top.rev x -pady 10 -padx 5 | |
8648 | ${NS}::label $top.flab -text [mc "Output file:"] | |
8649 | ${NS}::entry $top.fname -width 60 | |
74daedb6 PM |
8650 | $top.fname insert 0 [file normalize "patch$patchnum.patch"] |
8651 | incr patchnum | |
bdbfbe3d | 8652 | grid $top.flab $top.fname -sticky w |
d93f1713 PT |
8653 | ${NS}::frame $top.buts |
8654 | ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo | |
8655 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan | |
76f15947 AG |
8656 | bind $top <Key-Return> mkpatchgo |
8657 | bind $top <Key-Escape> mkpatchcan | |
74daedb6 PM |
8658 | grid $top.buts.gen $top.buts.can |
8659 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
8660 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
8661 | grid $top.buts - -pady 10 -sticky ew | |
bdbfbe3d | 8662 | focus $top.fname |
74daedb6 PM |
8663 | } |
8664 | ||
8665 | proc mkpatchrev {} { | |
8666 | global patchtop | |
8667 | ||
8668 | set oldid [$patchtop.fromsha1 get] | |
8669 | set oldhead [$patchtop.fromhead get] | |
8670 | set newid [$patchtop.tosha1 get] | |
8671 | set newhead [$patchtop.tohead get] | |
8672 | foreach e [list fromsha1 fromhead tosha1 tohead] \ | |
8673 | v [list $newid $newhead $oldid $oldhead] { | |
8674 | $patchtop.$e conf -state normal | |
8675 | $patchtop.$e delete 0 end | |
8676 | $patchtop.$e insert 0 $v | |
8677 | $patchtop.$e conf -state readonly | |
8678 | } | |
8679 | } | |
8680 | ||
8681 | proc mkpatchgo {} { | |
8f489363 | 8682 | global patchtop nullid nullid2 |
74daedb6 PM |
8683 | |
8684 | set oldid [$patchtop.fromsha1 get] | |
8685 | set newid [$patchtop.tosha1 get] | |
8686 | set fname [$patchtop.fname get] | |
8f489363 | 8687 | set cmd [diffcmd [list $oldid $newid] -p] |
d372e216 PM |
8688 | # trim off the initial "|" |
8689 | set cmd [lrange $cmd 1 end] | |
219ea3a9 PM |
8690 | lappend cmd >$fname & |
8691 | if {[catch {eval exec $cmd} err]} { | |
84a76f18 | 8692 | error_popup "[mc "Error creating patch:"] $err" $patchtop |
74daedb6 PM |
8693 | } |
8694 | catch {destroy $patchtop} | |
8695 | unset patchtop | |
8696 | } | |
8697 | ||
8698 | proc mkpatchcan {} { | |
8699 | global patchtop | |
8700 | ||
8701 | catch {destroy $patchtop} | |
8702 | unset patchtop | |
8703 | } | |
8704 | ||
bdbfbe3d | 8705 | proc mktag {} { |
d93f1713 | 8706 | global rowmenuid mktagtop commitinfo NS |
bdbfbe3d PM |
8707 | |
8708 | set top .maketag | |
8709 | set mktagtop $top | |
8710 | catch {destroy $top} | |
d93f1713 | 8711 | ttk_toplevel $top |
e7d64008 | 8712 | make_transient $top . |
d93f1713 | 8713 | ${NS}::label $top.title -text [mc "Create tag"] |
4a2139f5 | 8714 | grid $top.title - -pady 10 |
d93f1713 PT |
8715 | ${NS}::label $top.id -text [mc "ID:"] |
8716 | ${NS}::entry $top.sha1 -width 40 | |
bdbfbe3d PM |
8717 | $top.sha1 insert 0 $rowmenuid |
8718 | $top.sha1 conf -state readonly | |
8719 | grid $top.id $top.sha1 -sticky w | |
d93f1713 | 8720 | ${NS}::entry $top.head -width 60 |
bdbfbe3d PM |
8721 | $top.head insert 0 [lindex $commitinfo($rowmenuid) 0] |
8722 | $top.head conf -state readonly | |
8723 | grid x $top.head -sticky w | |
d93f1713 PT |
8724 | ${NS}::label $top.tlab -text [mc "Tag name:"] |
8725 | ${NS}::entry $top.tag -width 60 | |
bdbfbe3d | 8726 | grid $top.tlab $top.tag -sticky w |
dfb891e3 DD |
8727 | ${NS}::label $top.op -text [mc "Tag message is optional"] |
8728 | grid $top.op -columnspan 2 -sticky we | |
8729 | ${NS}::label $top.mlab -text [mc "Tag message:"] | |
8730 | ${NS}::entry $top.msg -width 60 | |
8731 | grid $top.mlab $top.msg -sticky w | |
d93f1713 PT |
8732 | ${NS}::frame $top.buts |
8733 | ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo | |
8734 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan | |
76f15947 AG |
8735 | bind $top <Key-Return> mktaggo |
8736 | bind $top <Key-Escape> mktagcan | |
bdbfbe3d PM |
8737 | grid $top.buts.gen $top.buts.can |
8738 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
8739 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
8740 | grid $top.buts - -pady 10 -sticky ew | |
8741 | focus $top.tag | |
8742 | } | |
8743 | ||
8744 | proc domktag {} { | |
8745 | global mktagtop env tagids idtags | |
bdbfbe3d PM |
8746 | |
8747 | set id [$mktagtop.sha1 get] | |
8748 | set tag [$mktagtop.tag get] | |
dfb891e3 | 8749 | set msg [$mktagtop.msg get] |
bdbfbe3d | 8750 | if {$tag == {}} { |
84a76f18 AG |
8751 | error_popup [mc "No tag name specified"] $mktagtop |
8752 | return 0 | |
bdbfbe3d PM |
8753 | } |
8754 | if {[info exists tagids($tag)]} { | |
84a76f18 AG |
8755 | error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop |
8756 | return 0 | |
bdbfbe3d PM |
8757 | } |
8758 | if {[catch { | |
dfb891e3 DD |
8759 | if {$msg != {}} { |
8760 | exec git tag -a -m $msg $tag $id | |
8761 | } else { | |
8762 | exec git tag $tag $id | |
8763 | } | |
bdbfbe3d | 8764 | } err]} { |
84a76f18 AG |
8765 | error_popup "[mc "Error creating tag:"] $err" $mktagtop |
8766 | return 0 | |
bdbfbe3d PM |
8767 | } |
8768 | ||
8769 | set tagids($tag) $id | |
8770 | lappend idtags($id) $tag | |
f1d83ba3 | 8771 | redrawtags $id |
ceadfe90 | 8772 | addedtag $id |
887c996e PM |
8773 | dispneartags 0 |
8774 | run refill_reflist | |
84a76f18 | 8775 | return 1 |
f1d83ba3 PM |
8776 | } |
8777 | ||
8778 | proc redrawtags {id} { | |
b9fdba7f | 8779 | global canv linehtag idpos currentid curview cmitlisted markedid |
c11ff120 | 8780 | global canvxmax iddrawn circleitem mainheadid circlecolors |
f1d83ba3 | 8781 | |
7fcc92bf | 8782 | if {![commitinview $id $curview]} return |
322a8cc9 | 8783 | if {![info exists iddrawn($id)]} return |
fc2a256f | 8784 | set row [rowofcommit $id] |
c11ff120 PM |
8785 | if {$id eq $mainheadid} { |
8786 | set ofill yellow | |
8787 | } else { | |
8788 | set ofill [lindex $circlecolors $cmitlisted($curview,$id)] | |
8789 | } | |
8790 | $canv itemconf $circleitem($row) -fill $ofill | |
bdbfbe3d PM |
8791 | $canv delete tag.$id |
8792 | set xt [eval drawtags $id $idpos($id)] | |
28593d3f PM |
8793 | $canv coords $linehtag($id) $xt [lindex $idpos($id) 2] |
8794 | set text [$canv itemcget $linehtag($id) -text] | |
8795 | set font [$canv itemcget $linehtag($id) -font] | |
fc2a256f | 8796 | set xr [expr {$xt + [font measure $font $text]}] |
b8ab2e17 PM |
8797 | if {$xr > $canvxmax} { |
8798 | set canvxmax $xr | |
8799 | setcanvscroll | |
8800 | } | |
fc2a256f | 8801 | if {[info exists currentid] && $currentid == $id} { |
28593d3f | 8802 | make_secsel $id |
bdbfbe3d | 8803 | } |
b9fdba7f PM |
8804 | if {[info exists markedid] && $markedid eq $id} { |
8805 | make_idmark $id | |
8806 | } | |
bdbfbe3d PM |
8807 | } |
8808 | ||
8809 | proc mktagcan {} { | |
8810 | global mktagtop | |
8811 | ||
8812 | catch {destroy $mktagtop} | |
8813 | unset mktagtop | |
8814 | } | |
8815 | ||
8816 | proc mktaggo {} { | |
84a76f18 | 8817 | if {![domktag]} return |
bdbfbe3d PM |
8818 | mktagcan |
8819 | } | |
8820 | ||
4a2139f5 | 8821 | proc writecommit {} { |
d93f1713 | 8822 | global rowmenuid wrcomtop commitinfo wrcomcmd NS |
4a2139f5 PM |
8823 | |
8824 | set top .writecommit | |
8825 | set wrcomtop $top | |
8826 | catch {destroy $top} | |
d93f1713 | 8827 | ttk_toplevel $top |
e7d64008 | 8828 | make_transient $top . |
d93f1713 | 8829 | ${NS}::label $top.title -text [mc "Write commit to file"] |
4a2139f5 | 8830 | grid $top.title - -pady 10 |
d93f1713 PT |
8831 | ${NS}::label $top.id -text [mc "ID:"] |
8832 | ${NS}::entry $top.sha1 -width 40 | |
4a2139f5 PM |
8833 | $top.sha1 insert 0 $rowmenuid |
8834 | $top.sha1 conf -state readonly | |
8835 | grid $top.id $top.sha1 -sticky w | |
d93f1713 | 8836 | ${NS}::entry $top.head -width 60 |
4a2139f5 PM |
8837 | $top.head insert 0 [lindex $commitinfo($rowmenuid) 0] |
8838 | $top.head conf -state readonly | |
8839 | grid x $top.head -sticky w | |
d93f1713 PT |
8840 | ${NS}::label $top.clab -text [mc "Command:"] |
8841 | ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd | |
4a2139f5 | 8842 | grid $top.clab $top.cmd -sticky w -pady 10 |
d93f1713 PT |
8843 | ${NS}::label $top.flab -text [mc "Output file:"] |
8844 | ${NS}::entry $top.fname -width 60 | |
4a2139f5 PM |
8845 | $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"] |
8846 | grid $top.flab $top.fname -sticky w | |
d93f1713 PT |
8847 | ${NS}::frame $top.buts |
8848 | ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo | |
8849 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan | |
76f15947 AG |
8850 | bind $top <Key-Return> wrcomgo |
8851 | bind $top <Key-Escape> wrcomcan | |
4a2139f5 PM |
8852 | grid $top.buts.gen $top.buts.can |
8853 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
8854 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
8855 | grid $top.buts - -pady 10 -sticky ew | |
8856 | focus $top.fname | |
8857 | } | |
8858 | ||
8859 | proc wrcomgo {} { | |
8860 | global wrcomtop | |
8861 | ||
8862 | set id [$wrcomtop.sha1 get] | |
8863 | set cmd "echo $id | [$wrcomtop.cmd get]" | |
8864 | set fname [$wrcomtop.fname get] | |
8865 | if {[catch {exec sh -c $cmd >$fname &} err]} { | |
84a76f18 | 8866 | error_popup "[mc "Error writing commit:"] $err" $wrcomtop |
4a2139f5 PM |
8867 | } |
8868 | catch {destroy $wrcomtop} | |
8869 | unset wrcomtop | |
8870 | } | |
8871 | ||
8872 | proc wrcomcan {} { | |
8873 | global wrcomtop | |
8874 | ||
8875 | catch {destroy $wrcomtop} | |
8876 | unset wrcomtop | |
8877 | } | |
8878 | ||
d6ac1a86 | 8879 | proc mkbranch {} { |
d93f1713 | 8880 | global rowmenuid mkbrtop NS |
d6ac1a86 PM |
8881 | |
8882 | set top .makebranch | |
8883 | catch {destroy $top} | |
d93f1713 | 8884 | ttk_toplevel $top |
e7d64008 | 8885 | make_transient $top . |
d93f1713 | 8886 | ${NS}::label $top.title -text [mc "Create new branch"] |
d6ac1a86 | 8887 | grid $top.title - -pady 10 |
d93f1713 PT |
8888 | ${NS}::label $top.id -text [mc "ID:"] |
8889 | ${NS}::entry $top.sha1 -width 40 | |
d6ac1a86 PM |
8890 | $top.sha1 insert 0 $rowmenuid |
8891 | $top.sha1 conf -state readonly | |
8892 | grid $top.id $top.sha1 -sticky w | |
d93f1713 PT |
8893 | ${NS}::label $top.nlab -text [mc "Name:"] |
8894 | ${NS}::entry $top.name -width 40 | |
d6ac1a86 | 8895 | grid $top.nlab $top.name -sticky w |
d93f1713 PT |
8896 | ${NS}::frame $top.buts |
8897 | ${NS}::button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top] | |
8898 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}" | |
76f15947 AG |
8899 | bind $top <Key-Return> [list mkbrgo $top] |
8900 | bind $top <Key-Escape> "catch {destroy $top}" | |
d6ac1a86 PM |
8901 | grid $top.buts.go $top.buts.can |
8902 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
8903 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
8904 | grid $top.buts - -pady 10 -sticky ew | |
8905 | focus $top.name | |
8906 | } | |
8907 | ||
8908 | proc mkbrgo {top} { | |
8909 | global headids idheads | |
8910 | ||
8911 | set name [$top.name get] | |
8912 | set id [$top.sha1 get] | |
bee866fa AG |
8913 | set cmdargs {} |
8914 | set old_id {} | |
d6ac1a86 | 8915 | if {$name eq {}} { |
84a76f18 | 8916 | error_popup [mc "Please specify a name for the new branch"] $top |
d6ac1a86 PM |
8917 | return |
8918 | } | |
bee866fa AG |
8919 | if {[info exists headids($name)]} { |
8920 | if {![confirm_popup [mc \ | |
84a76f18 | 8921 | "Branch '%s' already exists. Overwrite?" $name] $top]} { |
bee866fa AG |
8922 | return |
8923 | } | |
8924 | set old_id $headids($name) | |
8925 | lappend cmdargs -f | |
8926 | } | |
d6ac1a86 | 8927 | catch {destroy $top} |
bee866fa | 8928 | lappend cmdargs $name $id |
d6ac1a86 PM |
8929 | nowbusy newbranch |
8930 | update | |
8931 | if {[catch { | |
bee866fa | 8932 | eval exec git branch $cmdargs |
d6ac1a86 PM |
8933 | } err]} { |
8934 | notbusy newbranch | |
8935 | error_popup $err | |
8936 | } else { | |
d6ac1a86 | 8937 | notbusy newbranch |
bee866fa AG |
8938 | if {$old_id ne {}} { |
8939 | movehead $id $name | |
8940 | movedhead $id $name | |
8941 | redrawtags $old_id | |
8942 | redrawtags $id | |
8943 | } else { | |
8944 | set headids($name) $id | |
8945 | lappend idheads($id) $name | |
8946 | addedhead $id $name | |
8947 | redrawtags $id | |
8948 | } | |
e11f1233 | 8949 | dispneartags 0 |
887c996e | 8950 | run refill_reflist |
d6ac1a86 PM |
8951 | } |
8952 | } | |
8953 | ||
15e35055 AG |
8954 | proc exec_citool {tool_args {baseid {}}} { |
8955 | global commitinfo env | |
8956 | ||
8957 | set save_env [array get env GIT_AUTHOR_*] | |
8958 | ||
8959 | if {$baseid ne {}} { | |
8960 | if {![info exists commitinfo($baseid)]} { | |
8961 | getcommit $baseid | |
8962 | } | |
8963 | set author [lindex $commitinfo($baseid) 1] | |
8964 | set date [lindex $commitinfo($baseid) 2] | |
8965 | if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \ | |
8966 | $author author name email] | |
8967 | && $date ne {}} { | |
8968 | set env(GIT_AUTHOR_NAME) $name | |
8969 | set env(GIT_AUTHOR_EMAIL) $email | |
8970 | set env(GIT_AUTHOR_DATE) $date | |
8971 | } | |
8972 | } | |
8973 | ||
8974 | eval exec git citool $tool_args & | |
8975 | ||
8976 | array unset env GIT_AUTHOR_* | |
8977 | array set env $save_env | |
8978 | } | |
8979 | ||
ca6d8f58 | 8980 | proc cherrypick {} { |
468bcaed | 8981 | global rowmenuid curview |
b8a938cf | 8982 | global mainhead mainheadid |
ca6d8f58 | 8983 | |
e11f1233 PM |
8984 | set oldhead [exec git rev-parse HEAD] |
8985 | set dheads [descheads $rowmenuid] | |
8986 | if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} { | |
d990cedf CS |
8987 | set ok [confirm_popup [mc "Commit %s is already\ |
8988 | included in branch %s -- really re-apply it?" \ | |
8989 | [string range $rowmenuid 0 7] $mainhead]] | |
ca6d8f58 PM |
8990 | if {!$ok} return |
8991 | } | |
d990cedf | 8992 | nowbusy cherrypick [mc "Cherry-picking"] |
ca6d8f58 | 8993 | update |
ca6d8f58 PM |
8994 | # Unfortunately git-cherry-pick writes stuff to stderr even when |
8995 | # no error occurs, and exec takes that as an indication of error... | |
8996 | if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} { | |
8997 | notbusy cherrypick | |
15e35055 | 8998 | if {[regexp -line \ |
887a791f PM |
8999 | {Entry '(.*)' (would be overwritten by merge|not uptodate)} \ |
9000 | $err msg fname]} { | |
9001 | error_popup [mc "Cherry-pick failed because of local changes\ | |
9002 | to file '%s'.\nPlease commit, reset or stash\ | |
9003 | your changes and try again." $fname] | |
9004 | } elseif {[regexp -line \ | |
9005 | {^(CONFLICT \(.*\):|Automatic cherry-pick failed)} \ | |
9006 | $err]} { | |
9007 | if {[confirm_popup [mc "Cherry-pick failed because of merge\ | |
9008 | conflict.\nDo you wish to run git citool to\ | |
9009 | resolve it?"]]} { | |
9010 | # Force citool to read MERGE_MSG | |
9011 | file delete [file join [gitdir] "GITGUI_MSG"] | |
9012 | exec_citool {} $rowmenuid | |
9013 | } | |
15e35055 AG |
9014 | } else { |
9015 | error_popup $err | |
9016 | } | |
887a791f | 9017 | run updatecommits |
ca6d8f58 PM |
9018 | return |
9019 | } | |
9020 | set newhead [exec git rev-parse HEAD] | |
9021 | if {$newhead eq $oldhead} { | |
9022 | notbusy cherrypick | |
d990cedf | 9023 | error_popup [mc "No changes committed"] |
ca6d8f58 PM |
9024 | return |
9025 | } | |
e11f1233 | 9026 | addnewchild $newhead $oldhead |
7fcc92bf | 9027 | if {[commitinview $oldhead $curview]} { |
cdc8429c | 9028 | # XXX this isn't right if we have a path limit... |
7fcc92bf | 9029 | insertrow $newhead $oldhead $curview |
ca6d8f58 | 9030 | if {$mainhead ne {}} { |
e11f1233 | 9031 | movehead $newhead $mainhead |
ca6d8f58 PM |
9032 | movedhead $newhead $mainhead |
9033 | } | |
c11ff120 | 9034 | set mainheadid $newhead |
ca6d8f58 PM |
9035 | redrawtags $oldhead |
9036 | redrawtags $newhead | |
46308ea1 | 9037 | selbyid $newhead |
ca6d8f58 PM |
9038 | } |
9039 | notbusy cherrypick | |
9040 | } | |
9041 | ||
6fb735ae | 9042 | proc resethead {} { |
d93f1713 | 9043 | global mainhead rowmenuid confirm_ok resettype NS |
6fb735ae PM |
9044 | |
9045 | set confirm_ok 0 | |
9046 | set w ".confirmreset" | |
d93f1713 | 9047 | ttk_toplevel $w |
e7d64008 | 9048 | make_transient $w . |
d990cedf | 9049 | wm title $w [mc "Confirm reset"] |
d93f1713 PT |
9050 | ${NS}::label $w.m -text \ |
9051 | [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]] | |
6fb735ae | 9052 | pack $w.m -side top -fill x -padx 20 -pady 20 |
d93f1713 | 9053 | ${NS}::labelframe $w.f -text [mc "Reset type:"] |
6fb735ae | 9054 | set resettype mixed |
d93f1713 | 9055 | ${NS}::radiobutton $w.f.soft -value soft -variable resettype \ |
d990cedf | 9056 | -text [mc "Soft: Leave working tree and index untouched"] |
6fb735ae | 9057 | grid $w.f.soft -sticky w |
d93f1713 | 9058 | ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \ |
d990cedf | 9059 | -text [mc "Mixed: Leave working tree untouched, reset index"] |
6fb735ae | 9060 | grid $w.f.mixed -sticky w |
d93f1713 | 9061 | ${NS}::radiobutton $w.f.hard -value hard -variable resettype \ |
d990cedf | 9062 | -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"] |
6fb735ae | 9063 | grid $w.f.hard -sticky w |
d93f1713 PT |
9064 | pack $w.f -side top -fill x -padx 4 |
9065 | ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" | |
6fb735ae | 9066 | pack $w.ok -side left -fill x -padx 20 -pady 20 |
d93f1713 | 9067 | ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w" |
76f15947 | 9068 | bind $w <Key-Escape> [list destroy $w] |
6fb735ae PM |
9069 | pack $w.cancel -side right -fill x -padx 20 -pady 20 |
9070 | bind $w <Visibility> "grab $w; focus $w" | |
9071 | tkwait window $w | |
9072 | if {!$confirm_ok} return | |
706d6c3e | 9073 | if {[catch {set fd [open \ |
08ba820f | 9074 | [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} { |
6fb735ae PM |
9075 | error_popup $err |
9076 | } else { | |
706d6c3e | 9077 | dohidelocalchanges |
a137a90f | 9078 | filerun $fd [list readresetstat $fd] |
d990cedf | 9079 | nowbusy reset [mc "Resetting"] |
46308ea1 | 9080 | selbyid $rowmenuid |
706d6c3e PM |
9081 | } |
9082 | } | |
9083 | ||
a137a90f PM |
9084 | proc readresetstat {fd} { |
9085 | global mainhead mainheadid showlocalchanges rprogcoord | |
706d6c3e PM |
9086 | |
9087 | if {[gets $fd line] >= 0} { | |
9088 | if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} { | |
a137a90f PM |
9089 | set rprogcoord [expr {1.0 * $m / $n}] |
9090 | adjustprogress | |
706d6c3e PM |
9091 | } |
9092 | return 1 | |
9093 | } | |
a137a90f PM |
9094 | set rprogcoord 0 |
9095 | adjustprogress | |
706d6c3e PM |
9096 | notbusy reset |
9097 | if {[catch {close $fd} err]} { | |
9098 | error_popup $err | |
9099 | } | |
9100 | set oldhead $mainheadid | |
9101 | set newhead [exec git rev-parse HEAD] | |
9102 | if {$newhead ne $oldhead} { | |
9103 | movehead $newhead $mainhead | |
9104 | movedhead $newhead $mainhead | |
9105 | set mainheadid $newhead | |
6fb735ae | 9106 | redrawtags $oldhead |
706d6c3e | 9107 | redrawtags $newhead |
6fb735ae PM |
9108 | } |
9109 | if {$showlocalchanges} { | |
9110 | doshowlocalchanges | |
9111 | } | |
706d6c3e | 9112 | return 0 |
6fb735ae PM |
9113 | } |
9114 | ||
10299152 PM |
9115 | # context menu for a head |
9116 | proc headmenu {x y id head} { | |
00609463 | 9117 | global headmenuid headmenuhead headctxmenu mainhead |
10299152 | 9118 | |
bb3edc8b | 9119 | stopfinding |
10299152 PM |
9120 | set headmenuid $id |
9121 | set headmenuhead $head | |
00609463 | 9122 | set state normal |
70a5fc44 SC |
9123 | if {[string match "remotes/*" $head]} { |
9124 | set state disabled | |
9125 | } | |
00609463 PM |
9126 | if {$head eq $mainhead} { |
9127 | set state disabled | |
9128 | } | |
9129 | $headctxmenu entryconfigure 0 -state $state | |
9130 | $headctxmenu entryconfigure 1 -state $state | |
10299152 PM |
9131 | tk_popup $headctxmenu $x $y |
9132 | } | |
9133 | ||
9134 | proc cobranch {} { | |
c11ff120 | 9135 | global headmenuid headmenuhead headids |
cdc8429c | 9136 | global showlocalchanges |
10299152 PM |
9137 | |
9138 | # check the tree is clean first?? | |
d990cedf | 9139 | nowbusy checkout [mc "Checking out"] |
10299152 | 9140 | update |
219ea3a9 | 9141 | dohidelocalchanges |
10299152 | 9142 | if {[catch { |
08ba820f | 9143 | set fd [open [list | git checkout $headmenuhead 2>@1] r] |
10299152 PM |
9144 | } err]} { |
9145 | notbusy checkout | |
9146 | error_popup $err | |
08ba820f PM |
9147 | if {$showlocalchanges} { |
9148 | dodiffindex | |
9149 | } | |
10299152 | 9150 | } else { |
08ba820f PM |
9151 | filerun $fd [list readcheckoutstat $fd $headmenuhead $headmenuid] |
9152 | } | |
9153 | } | |
9154 | ||
9155 | proc readcheckoutstat {fd newhead newheadid} { | |
9156 | global mainhead mainheadid headids showlocalchanges progresscoords | |
cdc8429c | 9157 | global viewmainheadid curview |
08ba820f PM |
9158 | |
9159 | if {[gets $fd line] >= 0} { | |
9160 | if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} { | |
9161 | set progresscoords [list 0 [expr {1.0 * $m / $n}]] | |
9162 | adjustprogress | |
10299152 | 9163 | } |
08ba820f PM |
9164 | return 1 |
9165 | } | |
9166 | set progresscoords {0 0} | |
9167 | adjustprogress | |
9168 | notbusy checkout | |
9169 | if {[catch {close $fd} err]} { | |
9170 | error_popup $err | |
9171 | } | |
c11ff120 | 9172 | set oldmainid $mainheadid |
08ba820f PM |
9173 | set mainhead $newhead |
9174 | set mainheadid $newheadid | |
cdc8429c | 9175 | set viewmainheadid($curview) $newheadid |
c11ff120 | 9176 | redrawtags $oldmainid |
08ba820f PM |
9177 | redrawtags $newheadid |
9178 | selbyid $newheadid | |
6fb735ae PM |
9179 | if {$showlocalchanges} { |
9180 | dodiffindex | |
10299152 PM |
9181 | } |
9182 | } | |
9183 | ||
9184 | proc rmbranch {} { | |
e11f1233 | 9185 | global headmenuid headmenuhead mainhead |
b1054ac9 | 9186 | global idheads |
10299152 PM |
9187 | |
9188 | set head $headmenuhead | |
9189 | set id $headmenuid | |
00609463 | 9190 | # this check shouldn't be needed any more... |
10299152 | 9191 | if {$head eq $mainhead} { |
d990cedf | 9192 | error_popup [mc "Cannot delete the currently checked-out branch"] |
10299152 PM |
9193 | return |
9194 | } | |
e11f1233 | 9195 | set dheads [descheads $id] |
d7b16113 | 9196 | if {[llength $dheads] == 1 && $idheads($dheads) eq $head} { |
10299152 | 9197 | # the stuff on this branch isn't on any other branch |
d990cedf CS |
9198 | if {![confirm_popup [mc "The commits on branch %s aren't on any other\ |
9199 | branch.\nReally delete branch %s?" $head $head]]} return | |
10299152 PM |
9200 | } |
9201 | nowbusy rmbranch | |
9202 | update | |
9203 | if {[catch {exec git branch -D $head} err]} { | |
9204 | notbusy rmbranch | |
9205 | error_popup $err | |
9206 | return | |
9207 | } | |
e11f1233 | 9208 | removehead $id $head |
ca6d8f58 | 9209 | removedhead $id $head |
10299152 PM |
9210 | redrawtags $id |
9211 | notbusy rmbranch | |
e11f1233 | 9212 | dispneartags 0 |
887c996e PM |
9213 | run refill_reflist |
9214 | } | |
9215 | ||
9216 | # Display a list of tags and heads | |
9217 | proc showrefs {} { | |
d93f1713 | 9218 | global showrefstop bgcolor fgcolor selectbgcolor NS |
9c311b32 | 9219 | global bglist fglist reflistfilter reflist maincursor |
887c996e PM |
9220 | |
9221 | set top .showrefs | |
9222 | set showrefstop $top | |
9223 | if {[winfo exists $top]} { | |
9224 | raise $top | |
9225 | refill_reflist | |
9226 | return | |
9227 | } | |
d93f1713 | 9228 | ttk_toplevel $top |
d990cedf | 9229 | wm title $top [mc "Tags and heads: %s" [file tail [pwd]]] |
e7d64008 | 9230 | make_transient $top . |
887c996e | 9231 | text $top.list -background $bgcolor -foreground $fgcolor \ |
9c311b32 | 9232 | -selectbackground $selectbgcolor -font mainfont \ |
887c996e PM |
9233 | -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \ |
9234 | -width 30 -height 20 -cursor $maincursor \ | |
9235 | -spacing1 1 -spacing3 1 -state disabled | |
9236 | $top.list tag configure highlight -background $selectbgcolor | |
9237 | lappend bglist $top.list | |
9238 | lappend fglist $top.list | |
d93f1713 PT |
9239 | ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical |
9240 | ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal | |
887c996e PM |
9241 | grid $top.list $top.ysb -sticky nsew |
9242 | grid $top.xsb x -sticky ew | |
d93f1713 PT |
9243 | ${NS}::frame $top.f |
9244 | ${NS}::label $top.f.l -text "[mc "Filter"]: " | |
9245 | ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter | |
887c996e PM |
9246 | set reflistfilter "*" |
9247 | trace add variable reflistfilter write reflistfilter_change | |
9248 | pack $top.f.e -side right -fill x -expand 1 | |
9249 | pack $top.f.l -side left | |
9250 | grid $top.f - -sticky ew -pady 2 | |
d93f1713 | 9251 | ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"] |
76f15947 | 9252 | bind $top <Key-Escape> [list destroy $top] |
887c996e PM |
9253 | grid $top.close - |
9254 | grid columnconfigure $top 0 -weight 1 | |
9255 | grid rowconfigure $top 0 -weight 1 | |
9256 | bind $top.list <1> {break} | |
9257 | bind $top.list <B1-Motion> {break} | |
9258 | bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break} | |
9259 | set reflist {} | |
9260 | refill_reflist | |
9261 | } | |
9262 | ||
9263 | proc sel_reflist {w x y} { | |
9264 | global showrefstop reflist headids tagids otherrefids | |
9265 | ||
9266 | if {![winfo exists $showrefstop]} return | |
9267 | set l [lindex [split [$w index "@$x,$y"] "."] 0] | |
9268 | set ref [lindex $reflist [expr {$l-1}]] | |
9269 | set n [lindex $ref 0] | |
9270 | switch -- [lindex $ref 1] { | |
9271 | "H" {selbyid $headids($n)} | |
9272 | "T" {selbyid $tagids($n)} | |
9273 | "o" {selbyid $otherrefids($n)} | |
9274 | } | |
9275 | $showrefstop.list tag add highlight $l.0 "$l.0 lineend" | |
9276 | } | |
9277 | ||
9278 | proc unsel_reflist {} { | |
9279 | global showrefstop | |
9280 | ||
9281 | if {![info exists showrefstop] || ![winfo exists $showrefstop]} return | |
9282 | $showrefstop.list tag remove highlight 0.0 end | |
9283 | } | |
9284 | ||
9285 | proc reflistfilter_change {n1 n2 op} { | |
9286 | global reflistfilter | |
9287 | ||
9288 | after cancel refill_reflist | |
9289 | after 200 refill_reflist | |
9290 | } | |
9291 | ||
9292 | proc refill_reflist {} { | |
9293 | global reflist reflistfilter showrefstop headids tagids otherrefids | |
d375ef9b | 9294 | global curview |
887c996e PM |
9295 | |
9296 | if {![info exists showrefstop] || ![winfo exists $showrefstop]} return | |
9297 | set refs {} | |
9298 | foreach n [array names headids] { | |
9299 | if {[string match $reflistfilter $n]} { | |
7fcc92bf | 9300 | if {[commitinview $headids($n) $curview]} { |
887c996e PM |
9301 | lappend refs [list $n H] |
9302 | } else { | |
d375ef9b | 9303 | interestedin $headids($n) {run refill_reflist} |
887c996e PM |
9304 | } |
9305 | } | |
9306 | } | |
9307 | foreach n [array names tagids] { | |
9308 | if {[string match $reflistfilter $n]} { | |
7fcc92bf | 9309 | if {[commitinview $tagids($n) $curview]} { |
887c996e PM |
9310 | lappend refs [list $n T] |
9311 | } else { | |
d375ef9b | 9312 | interestedin $tagids($n) {run refill_reflist} |
887c996e PM |
9313 | } |
9314 | } | |
9315 | } | |
9316 | foreach n [array names otherrefids] { | |
9317 | if {[string match $reflistfilter $n]} { | |
7fcc92bf | 9318 | if {[commitinview $otherrefids($n) $curview]} { |
887c996e PM |
9319 | lappend refs [list $n o] |
9320 | } else { | |
d375ef9b | 9321 | interestedin $otherrefids($n) {run refill_reflist} |
887c996e PM |
9322 | } |
9323 | } | |
9324 | } | |
9325 | set refs [lsort -index 0 $refs] | |
9326 | if {$refs eq $reflist} return | |
9327 | ||
9328 | # Update the contents of $showrefstop.list according to the | |
9329 | # differences between $reflist (old) and $refs (new) | |
9330 | $showrefstop.list conf -state normal | |
9331 | $showrefstop.list insert end "\n" | |
9332 | set i 0 | |
9333 | set j 0 | |
9334 | while {$i < [llength $reflist] || $j < [llength $refs]} { | |
9335 | if {$i < [llength $reflist]} { | |
9336 | if {$j < [llength $refs]} { | |
9337 | set cmp [string compare [lindex $reflist $i 0] \ | |
9338 | [lindex $refs $j 0]] | |
9339 | if {$cmp == 0} { | |
9340 | set cmp [string compare [lindex $reflist $i 1] \ | |
9341 | [lindex $refs $j 1]] | |
9342 | } | |
9343 | } else { | |
9344 | set cmp -1 | |
9345 | } | |
9346 | } else { | |
9347 | set cmp 1 | |
9348 | } | |
9349 | switch -- $cmp { | |
9350 | -1 { | |
9351 | $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0" | |
9352 | incr i | |
9353 | } | |
9354 | 0 { | |
9355 | incr i | |
9356 | incr j | |
9357 | } | |
9358 | 1 { | |
9359 | set l [expr {$j + 1}] | |
9360 | $showrefstop.list image create $l.0 -align baseline \ | |
9361 | -image reficon-[lindex $refs $j 1] -padx 2 | |
9362 | $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n" | |
9363 | incr j | |
9364 | } | |
9365 | } | |
9366 | } | |
9367 | set reflist $refs | |
9368 | # delete last newline | |
9369 | $showrefstop.list delete end-2c end-1c | |
9370 | $showrefstop.list conf -state disabled | |
10299152 PM |
9371 | } |
9372 | ||
b8ab2e17 PM |
9373 | # Stuff for finding nearby tags |
9374 | proc getallcommits {} { | |
5cd15b6b PM |
9375 | global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate |
9376 | global idheads idtags idotherrefs allparents tagobjid | |
f1d83ba3 | 9377 | |
a69b2d1a | 9378 | if {![info exists allcommits]} { |
a69b2d1a PM |
9379 | set nextarc 0 |
9380 | set allcommits 0 | |
9381 | set seeds {} | |
5cd15b6b PM |
9382 | set allcwait 0 |
9383 | set cachedarcs 0 | |
9384 | set allccache [file join [gitdir] "gitk.cache"] | |
9385 | if {![catch { | |
9386 | set f [open $allccache r] | |
9387 | set allcwait 1 | |
9388 | getcache $f | |
9389 | }]} return | |
a69b2d1a | 9390 | } |
2d71bccc | 9391 | |
5cd15b6b PM |
9392 | if {$allcwait} { |
9393 | return | |
9394 | } | |
9395 | set cmd [list | git rev-list --parents] | |
9396 | set allcupdate [expr {$seeds ne {}}] | |
9397 | if {!$allcupdate} { | |
9398 | set ids "--all" | |
9399 | } else { | |
9400 | set refs [concat [array names idheads] [array names idtags] \ | |
9401 | [array names idotherrefs]] | |
9402 | set ids {} | |
9403 | set tagobjs {} | |
9404 | foreach name [array names tagobjid] { | |
9405 | lappend tagobjs $tagobjid($name) | |
9406 | } | |
9407 | foreach id [lsort -unique $refs] { | |
9408 | if {![info exists allparents($id)] && | |
9409 | [lsearch -exact $tagobjs $id] < 0} { | |
9410 | lappend ids $id | |
9411 | } | |
9412 | } | |
9413 | if {$ids ne {}} { | |
9414 | foreach id $seeds { | |
9415 | lappend ids "^$id" | |
9416 | } | |
9417 | } | |
9418 | } | |
9419 | if {$ids ne {}} { | |
9420 | set fd [open [concat $cmd $ids] r] | |
9421 | fconfigure $fd -blocking 0 | |
9422 | incr allcommits | |
9423 | nowbusy allcommits | |
9424 | filerun $fd [list getallclines $fd] | |
9425 | } else { | |
9426 | dispneartags 0 | |
2d71bccc | 9427 | } |
e11f1233 PM |
9428 | } |
9429 | ||
9430 | # Since most commits have 1 parent and 1 child, we group strings of | |
9431 | # such commits into "arcs" joining branch/merge points (BMPs), which | |
9432 | # are commits that either don't have 1 parent or don't have 1 child. | |
9433 | # | |
9434 | # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes | |
9435 | # arcout(id) - outgoing arcs for BMP | |
9436 | # arcids(a) - list of IDs on arc including end but not start | |
9437 | # arcstart(a) - BMP ID at start of arc | |
9438 | # arcend(a) - BMP ID at end of arc | |
9439 | # growing(a) - arc a is still growing | |
9440 | # arctags(a) - IDs out of arcids (excluding end) that have tags | |
9441 | # archeads(a) - IDs out of arcids (excluding end) that have heads | |
9442 | # The start of an arc is at the descendent end, so "incoming" means | |
9443 | # coming from descendents, and "outgoing" means going towards ancestors. | |
9444 | ||
9445 | proc getallclines {fd} { | |
5cd15b6b | 9446 | global allparents allchildren idtags idheads nextarc |
e11f1233 | 9447 | global arcnos arcids arctags arcout arcend arcstart archeads growing |
5cd15b6b | 9448 | global seeds allcommits cachedarcs allcupdate |
d93f1713 | 9449 | |
e11f1233 | 9450 | set nid 0 |
7eb3cb9c | 9451 | while {[incr nid] <= 1000 && [gets $fd line] >= 0} { |
e11f1233 PM |
9452 | set id [lindex $line 0] |
9453 | if {[info exists allparents($id)]} { | |
9454 | # seen it already | |
9455 | continue | |
9456 | } | |
5cd15b6b | 9457 | set cachedarcs 0 |
e11f1233 PM |
9458 | set olds [lrange $line 1 end] |
9459 | set allparents($id) $olds | |
9460 | if {![info exists allchildren($id)]} { | |
9461 | set allchildren($id) {} | |
9462 | set arcnos($id) {} | |
9463 | lappend seeds $id | |
9464 | } else { | |
9465 | set a $arcnos($id) | |
9466 | if {[llength $olds] == 1 && [llength $a] == 1} { | |
9467 | lappend arcids($a) $id | |
9468 | if {[info exists idtags($id)]} { | |
9469 | lappend arctags($a) $id | |
b8ab2e17 | 9470 | } |
e11f1233 PM |
9471 | if {[info exists idheads($id)]} { |
9472 | lappend archeads($a) $id | |
9473 | } | |
9474 | if {[info exists allparents($olds)]} { | |
9475 | # seen parent already | |
9476 | if {![info exists arcout($olds)]} { | |
9477 | splitarc $olds | |
9478 | } | |
9479 | lappend arcids($a) $olds | |
9480 | set arcend($a) $olds | |
9481 | unset growing($a) | |
9482 | } | |
9483 | lappend allchildren($olds) $id | |
9484 | lappend arcnos($olds) $a | |
9485 | continue | |
9486 | } | |
9487 | } | |
e11f1233 PM |
9488 | foreach a $arcnos($id) { |
9489 | lappend arcids($a) $id | |
9490 | set arcend($a) $id | |
9491 | unset growing($a) | |
9492 | } | |
9493 | ||
9494 | set ao {} | |
9495 | foreach p $olds { | |
9496 | lappend allchildren($p) $id | |
9497 | set a [incr nextarc] | |
9498 | set arcstart($a) $id | |
9499 | set archeads($a) {} | |
9500 | set arctags($a) {} | |
9501 | set archeads($a) {} | |
9502 | set arcids($a) {} | |
9503 | lappend ao $a | |
9504 | set growing($a) 1 | |
9505 | if {[info exists allparents($p)]} { | |
9506 | # seen it already, may need to make a new branch | |
9507 | if {![info exists arcout($p)]} { | |
9508 | splitarc $p | |
9509 | } | |
9510 | lappend arcids($a) $p | |
9511 | set arcend($a) $p | |
9512 | unset growing($a) | |
9513 | } | |
9514 | lappend arcnos($p) $a | |
9515 | } | |
9516 | set arcout($id) $ao | |
f1d83ba3 | 9517 | } |
f3326b66 PM |
9518 | if {$nid > 0} { |
9519 | global cached_dheads cached_dtags cached_atags | |
9520 | catch {unset cached_dheads} | |
9521 | catch {unset cached_dtags} | |
9522 | catch {unset cached_atags} | |
9523 | } | |
7eb3cb9c PM |
9524 | if {![eof $fd]} { |
9525 | return [expr {$nid >= 1000? 2: 1}] | |
9526 | } | |
5cd15b6b PM |
9527 | set cacheok 1 |
9528 | if {[catch { | |
9529 | fconfigure $fd -blocking 1 | |
9530 | close $fd | |
9531 | } err]} { | |
9532 | # got an error reading the list of commits | |
9533 | # if we were updating, try rereading the whole thing again | |
9534 | if {$allcupdate} { | |
9535 | incr allcommits -1 | |
9536 | dropcache $err | |
9537 | return | |
9538 | } | |
d990cedf | 9539 | error_popup "[mc "Error reading commit topology information;\ |
5cd15b6b | 9540 | branch and preceding/following tag information\ |
d990cedf | 9541 | will be incomplete."]\n($err)" |
5cd15b6b PM |
9542 | set cacheok 0 |
9543 | } | |
e11f1233 PM |
9544 | if {[incr allcommits -1] == 0} { |
9545 | notbusy allcommits | |
5cd15b6b PM |
9546 | if {$cacheok} { |
9547 | run savecache | |
9548 | } | |
e11f1233 PM |
9549 | } |
9550 | dispneartags 0 | |
7eb3cb9c | 9551 | return 0 |
b8ab2e17 PM |
9552 | } |
9553 | ||
e11f1233 PM |
9554 | proc recalcarc {a} { |
9555 | global arctags archeads arcids idtags idheads | |
b8ab2e17 | 9556 | |
e11f1233 PM |
9557 | set at {} |
9558 | set ah {} | |
9559 | foreach id [lrange $arcids($a) 0 end-1] { | |
9560 | if {[info exists idtags($id)]} { | |
9561 | lappend at $id | |
9562 | } | |
9563 | if {[info exists idheads($id)]} { | |
9564 | lappend ah $id | |
b8ab2e17 | 9565 | } |
f1d83ba3 | 9566 | } |
e11f1233 PM |
9567 | set arctags($a) $at |
9568 | set archeads($a) $ah | |
b8ab2e17 PM |
9569 | } |
9570 | ||
e11f1233 | 9571 | proc splitarc {p} { |
5cd15b6b | 9572 | global arcnos arcids nextarc arctags archeads idtags idheads |
e11f1233 | 9573 | global arcstart arcend arcout allparents growing |
cec7bece | 9574 | |
e11f1233 PM |
9575 | set a $arcnos($p) |
9576 | if {[llength $a] != 1} { | |
9577 | puts "oops splitarc called but [llength $a] arcs already" | |
9578 | return | |
9579 | } | |
9580 | set a [lindex $a 0] | |
9581 | set i [lsearch -exact $arcids($a) $p] | |
9582 | if {$i < 0} { | |
9583 | puts "oops splitarc $p not in arc $a" | |
9584 | return | |
9585 | } | |
9586 | set na [incr nextarc] | |
9587 | if {[info exists arcend($a)]} { | |
9588 | set arcend($na) $arcend($a) | |
9589 | } else { | |
9590 | set l [lindex $allparents([lindex $arcids($a) end]) 0] | |
9591 | set j [lsearch -exact $arcnos($l) $a] | |
9592 | set arcnos($l) [lreplace $arcnos($l) $j $j $na] | |
9593 | } | |
9594 | set tail [lrange $arcids($a) [expr {$i+1}] end] | |
9595 | set arcids($a) [lrange $arcids($a) 0 $i] | |
9596 | set arcend($a) $p | |
9597 | set arcstart($na) $p | |
9598 | set arcout($p) $na | |
9599 | set arcids($na) $tail | |
9600 | if {[info exists growing($a)]} { | |
9601 | set growing($na) 1 | |
9602 | unset growing($a) | |
9603 | } | |
e11f1233 PM |
9604 | |
9605 | foreach id $tail { | |
9606 | if {[llength $arcnos($id)] == 1} { | |
9607 | set arcnos($id) $na | |
cec7bece | 9608 | } else { |
e11f1233 PM |
9609 | set j [lsearch -exact $arcnos($id) $a] |
9610 | set arcnos($id) [lreplace $arcnos($id) $j $j $na] | |
cec7bece | 9611 | } |
e11f1233 PM |
9612 | } |
9613 | ||
9614 | # reconstruct tags and heads lists | |
9615 | if {$arctags($a) ne {} || $archeads($a) ne {}} { | |
9616 | recalcarc $a | |
9617 | recalcarc $na | |
9618 | } else { | |
9619 | set arctags($na) {} | |
9620 | set archeads($na) {} | |
9621 | } | |
9622 | } | |
9623 | ||
9624 | # Update things for a new commit added that is a child of one | |
9625 | # existing commit. Used when cherry-picking. | |
9626 | proc addnewchild {id p} { | |
5cd15b6b | 9627 | global allparents allchildren idtags nextarc |
e11f1233 | 9628 | global arcnos arcids arctags arcout arcend arcstart archeads growing |
719c2b9d | 9629 | global seeds allcommits |
e11f1233 | 9630 | |
3ebba3c7 | 9631 | if {![info exists allcommits] || ![info exists arcnos($p)]} return |
e11f1233 PM |
9632 | set allparents($id) [list $p] |
9633 | set allchildren($id) {} | |
9634 | set arcnos($id) {} | |
9635 | lappend seeds $id | |
e11f1233 PM |
9636 | lappend allchildren($p) $id |
9637 | set a [incr nextarc] | |
9638 | set arcstart($a) $id | |
9639 | set archeads($a) {} | |
9640 | set arctags($a) {} | |
9641 | set arcids($a) [list $p] | |
9642 | set arcend($a) $p | |
9643 | if {![info exists arcout($p)]} { | |
9644 | splitarc $p | |
9645 | } | |
9646 | lappend arcnos($p) $a | |
9647 | set arcout($id) [list $a] | |
9648 | } | |
9649 | ||
5cd15b6b PM |
9650 | # This implements a cache for the topology information. |
9651 | # The cache saves, for each arc, the start and end of the arc, | |
9652 | # the ids on the arc, and the outgoing arcs from the end. | |
9653 | proc readcache {f} { | |
9654 | global arcnos arcids arcout arcstart arcend arctags archeads nextarc | |
9655 | global idtags idheads allparents cachedarcs possible_seeds seeds growing | |
9656 | global allcwait | |
9657 | ||
9658 | set a $nextarc | |
9659 | set lim $cachedarcs | |
9660 | if {$lim - $a > 500} { | |
9661 | set lim [expr {$a + 500}] | |
9662 | } | |
9663 | if {[catch { | |
9664 | if {$a == $lim} { | |
9665 | # finish reading the cache and setting up arctags, etc. | |
9666 | set line [gets $f] | |
9667 | if {$line ne "1"} {error "bad final version"} | |
9668 | close $f | |
9669 | foreach id [array names idtags] { | |
9670 | if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 && | |
9671 | [llength $allparents($id)] == 1} { | |
9672 | set a [lindex $arcnos($id) 0] | |
9673 | if {$arctags($a) eq {}} { | |
9674 | recalcarc $a | |
9675 | } | |
9676 | } | |
9677 | } | |
9678 | foreach id [array names idheads] { | |
9679 | if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 && | |
9680 | [llength $allparents($id)] == 1} { | |
9681 | set a [lindex $arcnos($id) 0] | |
9682 | if {$archeads($a) eq {}} { | |
9683 | recalcarc $a | |
9684 | } | |
9685 | } | |
9686 | } | |
9687 | foreach id [lsort -unique $possible_seeds] { | |
9688 | if {$arcnos($id) eq {}} { | |
9689 | lappend seeds $id | |
9690 | } | |
9691 | } | |
9692 | set allcwait 0 | |
9693 | } else { | |
9694 | while {[incr a] <= $lim} { | |
9695 | set line [gets $f] | |
9696 | if {[llength $line] != 3} {error "bad line"} | |
9697 | set s [lindex $line 0] | |
9698 | set arcstart($a) $s | |
9699 | lappend arcout($s) $a | |
9700 | if {![info exists arcnos($s)]} { | |
9701 | lappend possible_seeds $s | |
9702 | set arcnos($s) {} | |
9703 | } | |
9704 | set e [lindex $line 1] | |
9705 | if {$e eq {}} { | |
9706 | set growing($a) 1 | |
9707 | } else { | |
9708 | set arcend($a) $e | |
9709 | if {![info exists arcout($e)]} { | |
9710 | set arcout($e) {} | |
9711 | } | |
9712 | } | |
9713 | set arcids($a) [lindex $line 2] | |
9714 | foreach id $arcids($a) { | |
9715 | lappend allparents($s) $id | |
9716 | set s $id | |
9717 | lappend arcnos($id) $a | |
9718 | } | |
9719 | if {![info exists allparents($s)]} { | |
9720 | set allparents($s) {} | |
9721 | } | |
9722 | set arctags($a) {} | |
9723 | set archeads($a) {} | |
9724 | } | |
9725 | set nextarc [expr {$a - 1}] | |
9726 | } | |
9727 | } err]} { | |
9728 | dropcache $err | |
9729 | return 0 | |
9730 | } | |
9731 | if {!$allcwait} { | |
9732 | getallcommits | |
9733 | } | |
9734 | return $allcwait | |
9735 | } | |
9736 | ||
9737 | proc getcache {f} { | |
9738 | global nextarc cachedarcs possible_seeds | |
9739 | ||
9740 | if {[catch { | |
9741 | set line [gets $f] | |
9742 | if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"} | |
9743 | # make sure it's an integer | |
9744 | set cachedarcs [expr {int([lindex $line 1])}] | |
9745 | if {$cachedarcs < 0} {error "bad number of arcs"} | |
9746 | set nextarc 0 | |
9747 | set possible_seeds {} | |
9748 | run readcache $f | |
9749 | } err]} { | |
9750 | dropcache $err | |
9751 | } | |
9752 | return 0 | |
9753 | } | |
9754 | ||
9755 | proc dropcache {err} { | |
9756 | global allcwait nextarc cachedarcs seeds | |
9757 | ||
9758 | #puts "dropping cache ($err)" | |
9759 | foreach v {arcnos arcout arcids arcstart arcend growing \ | |
9760 | arctags archeads allparents allchildren} { | |
9761 | global $v | |
9762 | catch {unset $v} | |
9763 | } | |
9764 | set allcwait 0 | |
9765 | set nextarc 0 | |
9766 | set cachedarcs 0 | |
9767 | set seeds {} | |
9768 | getallcommits | |
9769 | } | |
9770 | ||
9771 | proc writecache {f} { | |
9772 | global cachearc cachedarcs allccache | |
9773 | global arcstart arcend arcnos arcids arcout | |
9774 | ||
9775 | set a $cachearc | |
9776 | set lim $cachedarcs | |
9777 | if {$lim - $a > 1000} { | |
9778 | set lim [expr {$a + 1000}] | |
9779 | } | |
9780 | if {[catch { | |
9781 | while {[incr a] <= $lim} { | |
9782 | if {[info exists arcend($a)]} { | |
9783 | puts $f [list $arcstart($a) $arcend($a) $arcids($a)] | |
9784 | } else { | |
9785 | puts $f [list $arcstart($a) {} $arcids($a)] | |
9786 | } | |
9787 | } | |
9788 | } err]} { | |
9789 | catch {close $f} | |
9790 | catch {file delete $allccache} | |
9791 | #puts "writing cache failed ($err)" | |
9792 | return 0 | |
9793 | } | |
9794 | set cachearc [expr {$a - 1}] | |
9795 | if {$a > $cachedarcs} { | |
9796 | puts $f "1" | |
9797 | close $f | |
9798 | return 0 | |
9799 | } | |
9800 | return 1 | |
9801 | } | |
9802 | ||
9803 | proc savecache {} { | |
9804 | global nextarc cachedarcs cachearc allccache | |
9805 | ||
9806 | if {$nextarc == $cachedarcs} return | |
9807 | set cachearc 0 | |
9808 | set cachedarcs $nextarc | |
9809 | catch { | |
9810 | set f [open $allccache w] | |
9811 | puts $f [list 1 $cachedarcs] | |
9812 | run writecache $f | |
9813 | } | |
9814 | } | |
9815 | ||
e11f1233 PM |
9816 | # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a, |
9817 | # or 0 if neither is true. | |
9818 | proc anc_or_desc {a b} { | |
9819 | global arcout arcstart arcend arcnos cached_isanc | |
9820 | ||
9821 | if {$arcnos($a) eq $arcnos($b)} { | |
9822 | # Both are on the same arc(s); either both are the same BMP, | |
9823 | # or if one is not a BMP, the other is also not a BMP or is | |
9824 | # the BMP at end of the arc (and it only has 1 incoming arc). | |
69c0b5d2 PM |
9825 | # Or both can be BMPs with no incoming arcs. |
9826 | if {$a eq $b || $arcnos($a) eq {}} { | |
e11f1233 | 9827 | return 0 |
cec7bece | 9828 | } |
e11f1233 PM |
9829 | # assert {[llength $arcnos($a)] == 1} |
9830 | set arc [lindex $arcnos($a) 0] | |
9831 | set i [lsearch -exact $arcids($arc) $a] | |
9832 | set j [lsearch -exact $arcids($arc) $b] | |
9833 | if {$i < 0 || $i > $j} { | |
9834 | return 1 | |
9835 | } else { | |
9836 | return -1 | |
cec7bece PM |
9837 | } |
9838 | } | |
e11f1233 PM |
9839 | |
9840 | if {![info exists arcout($a)]} { | |
9841 | set arc [lindex $arcnos($a) 0] | |
9842 | if {[info exists arcend($arc)]} { | |
9843 | set aend $arcend($arc) | |
9844 | } else { | |
9845 | set aend {} | |
cec7bece | 9846 | } |
e11f1233 PM |
9847 | set a $arcstart($arc) |
9848 | } else { | |
9849 | set aend $a | |
9850 | } | |
9851 | if {![info exists arcout($b)]} { | |
9852 | set arc [lindex $arcnos($b) 0] | |
9853 | if {[info exists arcend($arc)]} { | |
9854 | set bend $arcend($arc) | |
9855 | } else { | |
9856 | set bend {} | |
cec7bece | 9857 | } |
e11f1233 PM |
9858 | set b $arcstart($arc) |
9859 | } else { | |
9860 | set bend $b | |
cec7bece | 9861 | } |
e11f1233 PM |
9862 | if {$a eq $bend} { |
9863 | return 1 | |
9864 | } | |
9865 | if {$b eq $aend} { | |
9866 | return -1 | |
9867 | } | |
9868 | if {[info exists cached_isanc($a,$bend)]} { | |
9869 | if {$cached_isanc($a,$bend)} { | |
9870 | return 1 | |
9871 | } | |
9872 | } | |
9873 | if {[info exists cached_isanc($b,$aend)]} { | |
9874 | if {$cached_isanc($b,$aend)} { | |
9875 | return -1 | |
9876 | } | |
9877 | if {[info exists cached_isanc($a,$bend)]} { | |
9878 | return 0 | |
9879 | } | |
cec7bece | 9880 | } |
cec7bece | 9881 | |
e11f1233 PM |
9882 | set todo [list $a $b] |
9883 | set anc($a) a | |
9884 | set anc($b) b | |
9885 | for {set i 0} {$i < [llength $todo]} {incr i} { | |
9886 | set x [lindex $todo $i] | |
9887 | if {$anc($x) eq {}} { | |
9888 | continue | |
9889 | } | |
9890 | foreach arc $arcnos($x) { | |
9891 | set xd $arcstart($arc) | |
9892 | if {$xd eq $bend} { | |
9893 | set cached_isanc($a,$bend) 1 | |
9894 | set cached_isanc($b,$aend) 0 | |
9895 | return 1 | |
9896 | } elseif {$xd eq $aend} { | |
9897 | set cached_isanc($b,$aend) 1 | |
9898 | set cached_isanc($a,$bend) 0 | |
9899 | return -1 | |
9900 | } | |
9901 | if {![info exists anc($xd)]} { | |
9902 | set anc($xd) $anc($x) | |
9903 | lappend todo $xd | |
9904 | } elseif {$anc($xd) ne $anc($x)} { | |
9905 | set anc($xd) {} | |
9906 | } | |
9907 | } | |
9908 | } | |
9909 | set cached_isanc($a,$bend) 0 | |
9910 | set cached_isanc($b,$aend) 0 | |
9911 | return 0 | |
9912 | } | |
b8ab2e17 | 9913 | |
e11f1233 PM |
9914 | # This identifies whether $desc has an ancestor that is |
9915 | # a growing tip of the graph and which is not an ancestor of $anc | |
9916 | # and returns 0 if so and 1 if not. | |
9917 | # If we subsequently discover a tag on such a growing tip, and that | |
9918 | # turns out to be a descendent of $anc (which it could, since we | |
9919 | # don't necessarily see children before parents), then $desc | |
9920 | # isn't a good choice to display as a descendent tag of | |
9921 | # $anc (since it is the descendent of another tag which is | |
9922 | # a descendent of $anc). Similarly, $anc isn't a good choice to | |
9923 | # display as a ancestor tag of $desc. | |
9924 | # | |
9925 | proc is_certain {desc anc} { | |
9926 | global arcnos arcout arcstart arcend growing problems | |
9927 | ||
9928 | set certain {} | |
9929 | if {[llength $arcnos($anc)] == 1} { | |
9930 | # tags on the same arc are certain | |
9931 | if {$arcnos($desc) eq $arcnos($anc)} { | |
9932 | return 1 | |
b8ab2e17 | 9933 | } |
e11f1233 PM |
9934 | if {![info exists arcout($anc)]} { |
9935 | # if $anc is partway along an arc, use the start of the arc instead | |
9936 | set a [lindex $arcnos($anc) 0] | |
9937 | set anc $arcstart($a) | |
b8ab2e17 | 9938 | } |
e11f1233 PM |
9939 | } |
9940 | if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} { | |
9941 | set x $desc | |
9942 | } else { | |
9943 | set a [lindex $arcnos($desc) 0] | |
9944 | set x $arcend($a) | |
9945 | } | |
9946 | if {$x == $anc} { | |
9947 | return 1 | |
9948 | } | |
9949 | set anclist [list $x] | |
9950 | set dl($x) 1 | |
9951 | set nnh 1 | |
9952 | set ngrowanc 0 | |
9953 | for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} { | |
9954 | set x [lindex $anclist $i] | |
9955 | if {$dl($x)} { | |
9956 | incr nnh -1 | |
9957 | } | |
9958 | set done($x) 1 | |
9959 | foreach a $arcout($x) { | |
9960 | if {[info exists growing($a)]} { | |
9961 | if {![info exists growanc($x)] && $dl($x)} { | |
9962 | set growanc($x) 1 | |
9963 | incr ngrowanc | |
9964 | } | |
9965 | } else { | |
9966 | set y $arcend($a) | |
9967 | if {[info exists dl($y)]} { | |
9968 | if {$dl($y)} { | |
9969 | if {!$dl($x)} { | |
9970 | set dl($y) 0 | |
9971 | if {![info exists done($y)]} { | |
9972 | incr nnh -1 | |
9973 | } | |
9974 | if {[info exists growanc($x)]} { | |
9975 | incr ngrowanc -1 | |
9976 | } | |
9977 | set xl [list $y] | |
9978 | for {set k 0} {$k < [llength $xl]} {incr k} { | |
9979 | set z [lindex $xl $k] | |
9980 | foreach c $arcout($z) { | |
9981 | if {[info exists arcend($c)]} { | |
9982 | set v $arcend($c) | |
9983 | if {[info exists dl($v)] && $dl($v)} { | |
9984 | set dl($v) 0 | |
9985 | if {![info exists done($v)]} { | |
9986 | incr nnh -1 | |
9987 | } | |
9988 | if {[info exists growanc($v)]} { | |
9989 | incr ngrowanc -1 | |
9990 | } | |
9991 | lappend xl $v | |
9992 | } | |
9993 | } | |
9994 | } | |
9995 | } | |
9996 | } | |
9997 | } | |
9998 | } elseif {$y eq $anc || !$dl($x)} { | |
9999 | set dl($y) 0 | |
10000 | lappend anclist $y | |
10001 | } else { | |
10002 | set dl($y) 1 | |
10003 | lappend anclist $y | |
10004 | incr nnh | |
10005 | } | |
10006 | } | |
b8ab2e17 PM |
10007 | } |
10008 | } | |
e11f1233 PM |
10009 | foreach x [array names growanc] { |
10010 | if {$dl($x)} { | |
10011 | return 0 | |
b8ab2e17 | 10012 | } |
7eb3cb9c | 10013 | return 0 |
b8ab2e17 | 10014 | } |
e11f1233 | 10015 | return 1 |
b8ab2e17 PM |
10016 | } |
10017 | ||
e11f1233 PM |
10018 | proc validate_arctags {a} { |
10019 | global arctags idtags | |
b8ab2e17 | 10020 | |
e11f1233 PM |
10021 | set i -1 |
10022 | set na $arctags($a) | |
10023 | foreach id $arctags($a) { | |
10024 | incr i | |
10025 | if {![info exists idtags($id)]} { | |
10026 | set na [lreplace $na $i $i] | |
10027 | incr i -1 | |
10028 | } | |
10029 | } | |
10030 | set arctags($a) $na | |
10031 | } | |
10032 | ||
10033 | proc validate_archeads {a} { | |
10034 | global archeads idheads | |
10035 | ||
10036 | set i -1 | |
10037 | set na $archeads($a) | |
10038 | foreach id $archeads($a) { | |
10039 | incr i | |
10040 | if {![info exists idheads($id)]} { | |
10041 | set na [lreplace $na $i $i] | |
10042 | incr i -1 | |
10043 | } | |
10044 | } | |
10045 | set archeads($a) $na | |
10046 | } | |
10047 | ||
10048 | # Return the list of IDs that have tags that are descendents of id, | |
10049 | # ignoring IDs that are descendents of IDs already reported. | |
10050 | proc desctags {id} { | |
10051 | global arcnos arcstart arcids arctags idtags allparents | |
10052 | global growing cached_dtags | |
10053 | ||
10054 | if {![info exists allparents($id)]} { | |
10055 | return {} | |
10056 | } | |
10057 | set t1 [clock clicks -milliseconds] | |
10058 | set argid $id | |
10059 | if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} { | |
10060 | # part-way along an arc; check that arc first | |
10061 | set a [lindex $arcnos($id) 0] | |
10062 | if {$arctags($a) ne {}} { | |
10063 | validate_arctags $a | |
10064 | set i [lsearch -exact $arcids($a) $id] | |
10065 | set tid {} | |
10066 | foreach t $arctags($a) { | |
10067 | set j [lsearch -exact $arcids($a) $t] | |
10068 | if {$j >= $i} break | |
10069 | set tid $t | |
b8ab2e17 | 10070 | } |
e11f1233 PM |
10071 | if {$tid ne {}} { |
10072 | return $tid | |
b8ab2e17 PM |
10073 | } |
10074 | } | |
e11f1233 PM |
10075 | set id $arcstart($a) |
10076 | if {[info exists idtags($id)]} { | |
10077 | return $id | |
10078 | } | |
10079 | } | |
10080 | if {[info exists cached_dtags($id)]} { | |
10081 | return $cached_dtags($id) | |
10082 | } | |
10083 | ||
10084 | set origid $id | |
10085 | set todo [list $id] | |
10086 | set queued($id) 1 | |
10087 | set nc 1 | |
10088 | for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} { | |
10089 | set id [lindex $todo $i] | |
10090 | set done($id) 1 | |
10091 | set ta [info exists hastaggedancestor($id)] | |
10092 | if {!$ta} { | |
10093 | incr nc -1 | |
10094 | } | |
10095 | # ignore tags on starting node | |
10096 | if {!$ta && $i > 0} { | |
10097 | if {[info exists idtags($id)]} { | |
10098 | set tagloc($id) $id | |
10099 | set ta 1 | |
10100 | } elseif {[info exists cached_dtags($id)]} { | |
10101 | set tagloc($id) $cached_dtags($id) | |
10102 | set ta 1 | |
10103 | } | |
10104 | } | |
10105 | foreach a $arcnos($id) { | |
10106 | set d $arcstart($a) | |
10107 | if {!$ta && $arctags($a) ne {}} { | |
10108 | validate_arctags $a | |
10109 | if {$arctags($a) ne {}} { | |
10110 | lappend tagloc($id) [lindex $arctags($a) end] | |
10111 | } | |
10112 | } | |
10113 | if {$ta || $arctags($a) ne {}} { | |
10114 | set tomark [list $d] | |
10115 | for {set j 0} {$j < [llength $tomark]} {incr j} { | |
10116 | set dd [lindex $tomark $j] | |
10117 | if {![info exists hastaggedancestor($dd)]} { | |
10118 | if {[info exists done($dd)]} { | |
10119 | foreach b $arcnos($dd) { | |
10120 | lappend tomark $arcstart($b) | |
10121 | } | |
10122 | if {[info exists tagloc($dd)]} { | |
10123 | unset tagloc($dd) | |
10124 | } | |
10125 | } elseif {[info exists queued($dd)]} { | |
10126 | incr nc -1 | |
10127 | } | |
10128 | set hastaggedancestor($dd) 1 | |
10129 | } | |
10130 | } | |
10131 | } | |
10132 | if {![info exists queued($d)]} { | |
10133 | lappend todo $d | |
10134 | set queued($d) 1 | |
10135 | if {![info exists hastaggedancestor($d)]} { | |
10136 | incr nc | |
10137 | } | |
10138 | } | |
b8ab2e17 | 10139 | } |
f1d83ba3 | 10140 | } |
e11f1233 PM |
10141 | set tags {} |
10142 | foreach id [array names tagloc] { | |
10143 | if {![info exists hastaggedancestor($id)]} { | |
10144 | foreach t $tagloc($id) { | |
10145 | if {[lsearch -exact $tags $t] < 0} { | |
10146 | lappend tags $t | |
10147 | } | |
10148 | } | |
10149 | } | |
10150 | } | |
10151 | set t2 [clock clicks -milliseconds] | |
10152 | set loopix $i | |
f1d83ba3 | 10153 | |
e11f1233 PM |
10154 | # remove tags that are descendents of other tags |
10155 | for {set i 0} {$i < [llength $tags]} {incr i} { | |
10156 | set a [lindex $tags $i] | |
10157 | for {set j 0} {$j < $i} {incr j} { | |
10158 | set b [lindex $tags $j] | |
10159 | set r [anc_or_desc $a $b] | |
10160 | if {$r == 1} { | |
10161 | set tags [lreplace $tags $j $j] | |
10162 | incr j -1 | |
10163 | incr i -1 | |
10164 | } elseif {$r == -1} { | |
10165 | set tags [lreplace $tags $i $i] | |
10166 | incr i -1 | |
10167 | break | |
ceadfe90 PM |
10168 | } |
10169 | } | |
10170 | } | |
10171 | ||
e11f1233 PM |
10172 | if {[array names growing] ne {}} { |
10173 | # graph isn't finished, need to check if any tag could get | |
10174 | # eclipsed by another tag coming later. Simply ignore any | |
10175 | # tags that could later get eclipsed. | |
10176 | set ctags {} | |
10177 | foreach t $tags { | |
10178 | if {[is_certain $t $origid]} { | |
10179 | lappend ctags $t | |
10180 | } | |
ceadfe90 | 10181 | } |
e11f1233 PM |
10182 | if {$tags eq $ctags} { |
10183 | set cached_dtags($origid) $tags | |
10184 | } else { | |
10185 | set tags $ctags | |
ceadfe90 | 10186 | } |
e11f1233 PM |
10187 | } else { |
10188 | set cached_dtags($origid) $tags | |
10189 | } | |
10190 | set t3 [clock clicks -milliseconds] | |
10191 | if {0 && $t3 - $t1 >= 100} { | |
10192 | puts "iterating descendents ($loopix/[llength $todo] nodes) took\ | |
10193 | [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left" | |
ceadfe90 | 10194 | } |
e11f1233 PM |
10195 | return $tags |
10196 | } | |
ceadfe90 | 10197 | |
e11f1233 PM |
10198 | proc anctags {id} { |
10199 | global arcnos arcids arcout arcend arctags idtags allparents | |
10200 | global growing cached_atags | |
10201 | ||
10202 | if {![info exists allparents($id)]} { | |
10203 | return {} | |
10204 | } | |
10205 | set t1 [clock clicks -milliseconds] | |
10206 | set argid $id | |
10207 | if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} { | |
10208 | # part-way along an arc; check that arc first | |
10209 | set a [lindex $arcnos($id) 0] | |
10210 | if {$arctags($a) ne {}} { | |
10211 | validate_arctags $a | |
10212 | set i [lsearch -exact $arcids($a) $id] | |
10213 | foreach t $arctags($a) { | |
10214 | set j [lsearch -exact $arcids($a) $t] | |
10215 | if {$j > $i} { | |
10216 | return $t | |
10217 | } | |
10218 | } | |
ceadfe90 | 10219 | } |
e11f1233 PM |
10220 | if {![info exists arcend($a)]} { |
10221 | return {} | |
10222 | } | |
10223 | set id $arcend($a) | |
10224 | if {[info exists idtags($id)]} { | |
10225 | return $id | |
10226 | } | |
10227 | } | |
10228 | if {[info exists cached_atags($id)]} { | |
10229 | return $cached_atags($id) | |
10230 | } | |
10231 | ||
10232 | set origid $id | |
10233 | set todo [list $id] | |
10234 | set queued($id) 1 | |
10235 | set taglist {} | |
10236 | set nc 1 | |
10237 | for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} { | |
10238 | set id [lindex $todo $i] | |
10239 | set done($id) 1 | |
10240 | set td [info exists hastaggeddescendent($id)] | |
10241 | if {!$td} { | |
10242 | incr nc -1 | |
10243 | } | |
10244 | # ignore tags on starting node | |
10245 | if {!$td && $i > 0} { | |
10246 | if {[info exists idtags($id)]} { | |
10247 | set tagloc($id) $id | |
10248 | set td 1 | |
10249 | } elseif {[info exists cached_atags($id)]} { | |
10250 | set tagloc($id) $cached_atags($id) | |
10251 | set td 1 | |
10252 | } | |
10253 | } | |
10254 | foreach a $arcout($id) { | |
10255 | if {!$td && $arctags($a) ne {}} { | |
10256 | validate_arctags $a | |
10257 | if {$arctags($a) ne {}} { | |
10258 | lappend tagloc($id) [lindex $arctags($a) 0] | |
10259 | } | |
10260 | } | |
10261 | if {![info exists arcend($a)]} continue | |
10262 | set d $arcend($a) | |
10263 | if {$td || $arctags($a) ne {}} { | |
10264 | set tomark [list $d] | |
10265 | for {set j 0} {$j < [llength $tomark]} {incr j} { | |
10266 | set dd [lindex $tomark $j] | |
10267 | if {![info exists hastaggeddescendent($dd)]} { | |
10268 | if {[info exists done($dd)]} { | |
10269 | foreach b $arcout($dd) { | |
10270 | if {[info exists arcend($b)]} { | |
10271 | lappend tomark $arcend($b) | |
10272 | } | |
10273 | } | |
10274 | if {[info exists tagloc($dd)]} { | |
10275 | unset tagloc($dd) | |
10276 | } | |
10277 | } elseif {[info exists queued($dd)]} { | |
10278 | incr nc -1 | |
10279 | } | |
10280 | set hastaggeddescendent($dd) 1 | |
10281 | } | |
10282 | } | |
10283 | } | |
10284 | if {![info exists queued($d)]} { | |
10285 | lappend todo $d | |
10286 | set queued($d) 1 | |
10287 | if {![info exists hastaggeddescendent($d)]} { | |
10288 | incr nc | |
10289 | } | |
10290 | } | |
10291 | } | |
10292 | } | |
10293 | set t2 [clock clicks -milliseconds] | |
10294 | set loopix $i | |
10295 | set tags {} | |
10296 | foreach id [array names tagloc] { | |
10297 | if {![info exists hastaggeddescendent($id)]} { | |
10298 | foreach t $tagloc($id) { | |
10299 | if {[lsearch -exact $tags $t] < 0} { | |
10300 | lappend tags $t | |
10301 | } | |
10302 | } | |
ceadfe90 PM |
10303 | } |
10304 | } | |
ceadfe90 | 10305 | |
e11f1233 PM |
10306 | # remove tags that are ancestors of other tags |
10307 | for {set i 0} {$i < [llength $tags]} {incr i} { | |
10308 | set a [lindex $tags $i] | |
10309 | for {set j 0} {$j < $i} {incr j} { | |
10310 | set b [lindex $tags $j] | |
10311 | set r [anc_or_desc $a $b] | |
10312 | if {$r == -1} { | |
10313 | set tags [lreplace $tags $j $j] | |
10314 | incr j -1 | |
10315 | incr i -1 | |
10316 | } elseif {$r == 1} { | |
10317 | set tags [lreplace $tags $i $i] | |
10318 | incr i -1 | |
10319 | break | |
10320 | } | |
10321 | } | |
10322 | } | |
10323 | ||
10324 | if {[array names growing] ne {}} { | |
10325 | # graph isn't finished, need to check if any tag could get | |
10326 | # eclipsed by another tag coming later. Simply ignore any | |
10327 | # tags that could later get eclipsed. | |
10328 | set ctags {} | |
10329 | foreach t $tags { | |
10330 | if {[is_certain $origid $t]} { | |
10331 | lappend ctags $t | |
10332 | } | |
10333 | } | |
10334 | if {$tags eq $ctags} { | |
10335 | set cached_atags($origid) $tags | |
10336 | } else { | |
10337 | set tags $ctags | |
d6ac1a86 | 10338 | } |
e11f1233 PM |
10339 | } else { |
10340 | set cached_atags($origid) $tags | |
10341 | } | |
10342 | set t3 [clock clicks -milliseconds] | |
10343 | if {0 && $t3 - $t1 >= 100} { | |
10344 | puts "iterating ancestors ($loopix/[llength $todo] nodes) took\ | |
10345 | [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left" | |
d6ac1a86 | 10346 | } |
e11f1233 | 10347 | return $tags |
d6ac1a86 PM |
10348 | } |
10349 | ||
e11f1233 PM |
10350 | # Return the list of IDs that have heads that are descendents of id, |
10351 | # including id itself if it has a head. | |
10352 | proc descheads {id} { | |
10353 | global arcnos arcstart arcids archeads idheads cached_dheads | |
10354 | global allparents | |
ca6d8f58 | 10355 | |
e11f1233 PM |
10356 | if {![info exists allparents($id)]} { |
10357 | return {} | |
10358 | } | |
f3326b66 | 10359 | set aret {} |
e11f1233 PM |
10360 | if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} { |
10361 | # part-way along an arc; check it first | |
10362 | set a [lindex $arcnos($id) 0] | |
10363 | if {$archeads($a) ne {}} { | |
10364 | validate_archeads $a | |
10365 | set i [lsearch -exact $arcids($a) $id] | |
10366 | foreach t $archeads($a) { | |
10367 | set j [lsearch -exact $arcids($a) $t] | |
10368 | if {$j > $i} break | |
f3326b66 | 10369 | lappend aret $t |
e11f1233 | 10370 | } |
ca6d8f58 | 10371 | } |
e11f1233 | 10372 | set id $arcstart($a) |
ca6d8f58 | 10373 | } |
e11f1233 PM |
10374 | set origid $id |
10375 | set todo [list $id] | |
10376 | set seen($id) 1 | |
f3326b66 | 10377 | set ret {} |
e11f1233 PM |
10378 | for {set i 0} {$i < [llength $todo]} {incr i} { |
10379 | set id [lindex $todo $i] | |
10380 | if {[info exists cached_dheads($id)]} { | |
10381 | set ret [concat $ret $cached_dheads($id)] | |
10382 | } else { | |
10383 | if {[info exists idheads($id)]} { | |
10384 | lappend ret $id | |
10385 | } | |
10386 | foreach a $arcnos($id) { | |
10387 | if {$archeads($a) ne {}} { | |
706d6c3e PM |
10388 | validate_archeads $a |
10389 | if {$archeads($a) ne {}} { | |
10390 | set ret [concat $ret $archeads($a)] | |
10391 | } | |
e11f1233 PM |
10392 | } |
10393 | set d $arcstart($a) | |
10394 | if {![info exists seen($d)]} { | |
10395 | lappend todo $d | |
10396 | set seen($d) 1 | |
10397 | } | |
10398 | } | |
10299152 | 10399 | } |
10299152 | 10400 | } |
e11f1233 PM |
10401 | set ret [lsort -unique $ret] |
10402 | set cached_dheads($origid) $ret | |
f3326b66 | 10403 | return [concat $ret $aret] |
10299152 PM |
10404 | } |
10405 | ||
e11f1233 PM |
10406 | proc addedtag {id} { |
10407 | global arcnos arcout cached_dtags cached_atags | |
ca6d8f58 | 10408 | |
e11f1233 PM |
10409 | if {![info exists arcnos($id)]} return |
10410 | if {![info exists arcout($id)]} { | |
10411 | recalcarc [lindex $arcnos($id) 0] | |
ca6d8f58 | 10412 | } |
e11f1233 PM |
10413 | catch {unset cached_dtags} |
10414 | catch {unset cached_atags} | |
ca6d8f58 PM |
10415 | } |
10416 | ||
e11f1233 PM |
10417 | proc addedhead {hid head} { |
10418 | global arcnos arcout cached_dheads | |
10419 | ||
10420 | if {![info exists arcnos($hid)]} return | |
10421 | if {![info exists arcout($hid)]} { | |
10422 | recalcarc [lindex $arcnos($hid) 0] | |
10423 | } | |
10424 | catch {unset cached_dheads} | |
10425 | } | |
10426 | ||
10427 | proc removedhead {hid head} { | |
10428 | global cached_dheads | |
10429 | ||
10430 | catch {unset cached_dheads} | |
10431 | } | |
10432 | ||
10433 | proc movedhead {hid head} { | |
10434 | global arcnos arcout cached_dheads | |
cec7bece | 10435 | |
e11f1233 PM |
10436 | if {![info exists arcnos($hid)]} return |
10437 | if {![info exists arcout($hid)]} { | |
10438 | recalcarc [lindex $arcnos($hid) 0] | |
cec7bece | 10439 | } |
e11f1233 PM |
10440 | catch {unset cached_dheads} |
10441 | } | |
10442 | ||
10443 | proc changedrefs {} { | |
10444 | global cached_dheads cached_dtags cached_atags | |
10445 | global arctags archeads arcnos arcout idheads idtags | |
10446 | ||
10447 | foreach id [concat [array names idheads] [array names idtags]] { | |
10448 | if {[info exists arcnos($id)] && ![info exists arcout($id)]} { | |
10449 | set a [lindex $arcnos($id) 0] | |
10450 | if {![info exists donearc($a)]} { | |
10451 | recalcarc $a | |
10452 | set donearc($a) 1 | |
10453 | } | |
cec7bece PM |
10454 | } |
10455 | } | |
e11f1233 PM |
10456 | catch {unset cached_dtags} |
10457 | catch {unset cached_atags} | |
10458 | catch {unset cached_dheads} | |
cec7bece PM |
10459 | } |
10460 | ||
f1d83ba3 | 10461 | proc rereadrefs {} { |
fc2a256f | 10462 | global idtags idheads idotherrefs mainheadid |
f1d83ba3 PM |
10463 | |
10464 | set refids [concat [array names idtags] \ | |
10465 | [array names idheads] [array names idotherrefs]] | |
10466 | foreach id $refids { | |
10467 | if {![info exists ref($id)]} { | |
10468 | set ref($id) [listrefs $id] | |
10469 | } | |
10470 | } | |
fc2a256f | 10471 | set oldmainhead $mainheadid |
f1d83ba3 | 10472 | readrefs |
cec7bece | 10473 | changedrefs |
f1d83ba3 PM |
10474 | set refids [lsort -unique [concat $refids [array names idtags] \ |
10475 | [array names idheads] [array names idotherrefs]]] | |
10476 | foreach id $refids { | |
10477 | set v [listrefs $id] | |
c11ff120 | 10478 | if {![info exists ref($id)] || $ref($id) != $v} { |
f1d83ba3 PM |
10479 | redrawtags $id |
10480 | } | |
10481 | } | |
c11ff120 PM |
10482 | if {$oldmainhead ne $mainheadid} { |
10483 | redrawtags $oldmainhead | |
10484 | redrawtags $mainheadid | |
10485 | } | |
887c996e | 10486 | run refill_reflist |
f1d83ba3 PM |
10487 | } |
10488 | ||
2e1ded44 JH |
10489 | proc listrefs {id} { |
10490 | global idtags idheads idotherrefs | |
10491 | ||
10492 | set x {} | |
10493 | if {[info exists idtags($id)]} { | |
10494 | set x $idtags($id) | |
10495 | } | |
10496 | set y {} | |
10497 | if {[info exists idheads($id)]} { | |
10498 | set y $idheads($id) | |
10499 | } | |
10500 | set z {} | |
10501 | if {[info exists idotherrefs($id)]} { | |
10502 | set z $idotherrefs($id) | |
10503 | } | |
10504 | return [list $x $y $z] | |
10505 | } | |
10506 | ||
106288cb | 10507 | proc showtag {tag isnew} { |
62d3ea65 | 10508 | global ctext tagcontents tagids linknum tagobjid |
106288cb PM |
10509 | |
10510 | if {$isnew} { | |
354af6bd | 10511 | addtohistory [list showtag $tag 0] savectextpos |
106288cb PM |
10512 | } |
10513 | $ctext conf -state normal | |
3ea06f9f | 10514 | clear_ctext |
32f1b3e4 | 10515 | settabs 0 |
106288cb | 10516 | set linknum 0 |
62d3ea65 PM |
10517 | if {![info exists tagcontents($tag)]} { |
10518 | catch { | |
fcacf489 | 10519 | set tagcontents($tag) [exec git cat-file tag $tag] |
62d3ea65 PM |
10520 | } |
10521 | } | |
106288cb PM |
10522 | if {[info exists tagcontents($tag)]} { |
10523 | set text $tagcontents($tag) | |
10524 | } else { | |
d990cedf | 10525 | set text "[mc "Tag"]: $tag\n[mc "Id"]: $tagids($tag)" |
106288cb | 10526 | } |
f1b86294 | 10527 | appendwithlinks $text {} |
a80e82f6 | 10528 | maybe_scroll_ctext 1 |
106288cb | 10529 | $ctext conf -state disabled |
7fcceed7 | 10530 | init_flist {} |
106288cb PM |
10531 | } |
10532 | ||
1d10f36d PM |
10533 | proc doquit {} { |
10534 | global stopped | |
314f5de1 TA |
10535 | global gitktmpdir |
10536 | ||
1d10f36d | 10537 | set stopped 100 |
b6047c5a | 10538 | savestuff . |
1d10f36d | 10539 | destroy . |
314f5de1 TA |
10540 | |
10541 | if {[info exists gitktmpdir]} { | |
10542 | catch {file delete -force $gitktmpdir} | |
10543 | } | |
1d10f36d | 10544 | } |
1db95b00 | 10545 | |
9a7558f3 | 10546 | proc mkfontdisp {font top which} { |
d93f1713 | 10547 | global fontattr fontpref $font NS use_ttk |
9a7558f3 PM |
10548 | |
10549 | set fontpref($font) [set $font] | |
d93f1713 | 10550 | ${NS}::button $top.${font}but -text $which \ |
9a7558f3 | 10551 | -command [list choosefont $font $which] |
d93f1713 | 10552 | ${NS}::label $top.$font -relief flat -font $font \ |
9a7558f3 PM |
10553 | -text $fontattr($font,family) -justify left |
10554 | grid x $top.${font}but $top.$font -sticky w | |
10555 | } | |
10556 | ||
10557 | proc choosefont {font which} { | |
10558 | global fontparam fontlist fonttop fontattr | |
d93f1713 | 10559 | global prefstop NS |
9a7558f3 PM |
10560 | |
10561 | set fontparam(which) $which | |
10562 | set fontparam(font) $font | |
10563 | set fontparam(family) [font actual $font -family] | |
10564 | set fontparam(size) $fontattr($font,size) | |
10565 | set fontparam(weight) $fontattr($font,weight) | |
10566 | set fontparam(slant) $fontattr($font,slant) | |
10567 | set top .gitkfont | |
10568 | set fonttop $top | |
10569 | if {![winfo exists $top]} { | |
10570 | font create sample | |
10571 | eval font config sample [font actual $font] | |
d93f1713 | 10572 | ttk_toplevel $top |
e7d64008 | 10573 | make_transient $top $prefstop |
d990cedf | 10574 | wm title $top [mc "Gitk font chooser"] |
d93f1713 | 10575 | ${NS}::label $top.l -textvariable fontparam(which) |
9a7558f3 PM |
10576 | pack $top.l -side top |
10577 | set fontlist [lsort [font families]] | |
d93f1713 | 10578 | ${NS}::frame $top.f |
9a7558f3 PM |
10579 | listbox $top.f.fam -listvariable fontlist \ |
10580 | -yscrollcommand [list $top.f.sb set] | |
10581 | bind $top.f.fam <<ListboxSelect>> selfontfam | |
d93f1713 | 10582 | ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview] |
9a7558f3 PM |
10583 | pack $top.f.sb -side right -fill y |
10584 | pack $top.f.fam -side left -fill both -expand 1 | |
10585 | pack $top.f -side top -fill both -expand 1 | |
d93f1713 | 10586 | ${NS}::frame $top.g |
9a7558f3 PM |
10587 | spinbox $top.g.size -from 4 -to 40 -width 4 \ |
10588 | -textvariable fontparam(size) \ | |
10589 | -validatecommand {string is integer -strict %s} | |
10590 | checkbutton $top.g.bold -padx 5 \ | |
d990cedf | 10591 | -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \ |
9a7558f3 PM |
10592 | -variable fontparam(weight) -onvalue bold -offvalue normal |
10593 | checkbutton $top.g.ital -padx 5 \ | |
d990cedf | 10594 | -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \ |
9a7558f3 PM |
10595 | -variable fontparam(slant) -onvalue italic -offvalue roman |
10596 | pack $top.g.size $top.g.bold $top.g.ital -side left | |
10597 | pack $top.g -side top | |
10598 | canvas $top.c -width 150 -height 50 -border 2 -relief sunk \ | |
10599 | -background white | |
10600 | $top.c create text 100 25 -anchor center -text $which -font sample \ | |
10601 | -fill black -tags text | |
10602 | bind $top.c <Configure> [list centertext $top.c] | |
10603 | pack $top.c -side top -fill x | |
d93f1713 PT |
10604 | ${NS}::frame $top.buts |
10605 | ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active | |
10606 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal | |
76f15947 AG |
10607 | bind $top <Key-Return> fontok |
10608 | bind $top <Key-Escape> fontcan | |
9a7558f3 PM |
10609 | grid $top.buts.ok $top.buts.can |
10610 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
10611 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
10612 | pack $top.buts -side bottom -fill x | |
10613 | trace add variable fontparam write chg_fontparam | |
10614 | } else { | |
10615 | raise $top | |
10616 | $top.c itemconf text -text $which | |
10617 | } | |
10618 | set i [lsearch -exact $fontlist $fontparam(family)] | |
10619 | if {$i >= 0} { | |
10620 | $top.f.fam selection set $i | |
10621 | $top.f.fam see $i | |
10622 | } | |
10623 | } | |
10624 | ||
10625 | proc centertext {w} { | |
10626 | $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}] | |
10627 | } | |
10628 | ||
10629 | proc fontok {} { | |
10630 | global fontparam fontpref prefstop | |
10631 | ||
10632 | set f $fontparam(font) | |
10633 | set fontpref($f) [list $fontparam(family) $fontparam(size)] | |
10634 | if {$fontparam(weight) eq "bold"} { | |
10635 | lappend fontpref($f) "bold" | |
10636 | } | |
10637 | if {$fontparam(slant) eq "italic"} { | |
10638 | lappend fontpref($f) "italic" | |
10639 | } | |
10640 | set w $prefstop.$f | |
10641 | $w conf -text $fontparam(family) -font $fontpref($f) | |
d93f1713 | 10642 | |
9a7558f3 PM |
10643 | fontcan |
10644 | } | |
10645 | ||
10646 | proc fontcan {} { | |
10647 | global fonttop fontparam | |
10648 | ||
10649 | if {[info exists fonttop]} { | |
10650 | catch {destroy $fonttop} | |
10651 | catch {font delete sample} | |
10652 | unset fonttop | |
10653 | unset fontparam | |
10654 | } | |
10655 | } | |
10656 | ||
d93f1713 PT |
10657 | if {[package vsatisfies [package provide Tk] 8.6]} { |
10658 | # In Tk 8.6 we have a native font chooser dialog. Overwrite the above | |
10659 | # function to make use of it. | |
10660 | proc choosefont {font which} { | |
10661 | tk fontchooser configure -title $which -font $font \ | |
10662 | -command [list on_choosefont $font $which] | |
10663 | tk fontchooser show | |
10664 | } | |
10665 | proc on_choosefont {font which newfont} { | |
10666 | global fontparam | |
10667 | puts stderr "$font $newfont" | |
10668 | array set f [font actual $newfont] | |
10669 | set fontparam(which) $which | |
10670 | set fontparam(font) $font | |
10671 | set fontparam(family) $f(-family) | |
10672 | set fontparam(size) $f(-size) | |
10673 | set fontparam(weight) $f(-weight) | |
10674 | set fontparam(slant) $f(-slant) | |
10675 | fontok | |
10676 | } | |
10677 | } | |
10678 | ||
9a7558f3 PM |
10679 | proc selfontfam {} { |
10680 | global fonttop fontparam | |
10681 | ||
10682 | set i [$fonttop.f.fam curselection] | |
10683 | if {$i ne {}} { | |
10684 | set fontparam(family) [$fonttop.f.fam get $i] | |
10685 | } | |
10686 | } | |
10687 | ||
10688 | proc chg_fontparam {v sub op} { | |
10689 | global fontparam | |
10690 | ||
10691 | font config sample -$sub $fontparam($sub) | |
10692 | } | |
10693 | ||
712fcc08 | 10694 | proc doprefs {} { |
d93f1713 | 10695 | global maxwidth maxgraphpct use_ttk NS |
219ea3a9 | 10696 | global oldprefs prefstop showneartags showlocalchanges |
5497f7a2 | 10697 | global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor |
39ee47ef | 10698 | global tabstop limitdiffs autoselect extdifftool perfile_attrs |
0cc08ff7 | 10699 | global hideremotes want_ttk have_ttk |
232475d3 | 10700 | |
712fcc08 PM |
10701 | set top .gitkprefs |
10702 | set prefstop $top | |
10703 | if {[winfo exists $top]} { | |
10704 | raise $top | |
10705 | return | |
757f17bc | 10706 | } |
3de07118 | 10707 | foreach v {maxwidth maxgraphpct showneartags showlocalchanges \ |
0cc08ff7 | 10708 | limitdiffs tabstop perfile_attrs hideremotes want_ttk} { |
712fcc08 | 10709 | set oldprefs($v) [set $v] |
232475d3 | 10710 | } |
d93f1713 | 10711 | ttk_toplevel $top |
d990cedf | 10712 | wm title $top [mc "Gitk preferences"] |
e7d64008 | 10713 | make_transient $top . |
d93f1713 | 10714 | ${NS}::label $top.ldisp -text [mc "Commit list display options"] |
712fcc08 | 10715 | grid $top.ldisp - -sticky w -pady 10 |
d93f1713 PT |
10716 | ${NS}::label $top.spacer -text " " |
10717 | ${NS}::label $top.maxwidthl -text [mc "Maximum graph width (lines)"] | |
712fcc08 PM |
10718 | spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth |
10719 | grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w | |
d93f1713 | 10720 | ${NS}::label $top.maxpctl -text [mc "Maximum graph width (% of pane)"] |
712fcc08 PM |
10721 | spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct |
10722 | grid x $top.maxpctl $top.maxpct -sticky w | |
d93f1713 PT |
10723 | ${NS}::checkbutton $top.showlocal -text [mc "Show local changes"] \ |
10724 | -variable showlocalchanges | |
219ea3a9 | 10725 | grid x $top.showlocal -sticky w |
d93f1713 PT |
10726 | ${NS}::checkbutton $top.autoselect -text [mc "Auto-select SHA1"] \ |
10727 | -variable autoselect | |
95293b58 | 10728 | grid x $top.autoselect -sticky w |
0cc08ff7 PM |
10729 | ${NS}::checkbutton $top.hideremotes -text [mc "Hide remote refs"] \ |
10730 | -variable hideremotes | |
10731 | grid x $top.hideremotes -sticky w | |
f8a2c0d1 | 10732 | |
d93f1713 | 10733 | ${NS}::label $top.ddisp -text [mc "Diff display options"] |
712fcc08 | 10734 | grid $top.ddisp - -sticky w -pady 10 |
d93f1713 | 10735 | ${NS}::label $top.tabstopl -text [mc "Tab spacing"] |
94503918 PM |
10736 | spinbox $top.tabstop -from 1 -to 20 -width 4 -textvariable tabstop |
10737 | grid x $top.tabstopl $top.tabstop -sticky w | |
d93f1713 PT |
10738 | ${NS}::checkbutton $top.ntag -text [mc "Display nearby tags"] \ |
10739 | -variable showneartags | |
b8ab2e17 | 10740 | grid x $top.ntag -sticky w |
d93f1713 PT |
10741 | ${NS}::checkbutton $top.ldiff -text [mc "Limit diffs to listed paths"] \ |
10742 | -variable limitdiffs | |
7a39a17a | 10743 | grid x $top.ldiff -sticky w |
d93f1713 PT |
10744 | ${NS}::checkbutton $top.lattr -text [mc "Support per-file encodings"] \ |
10745 | -variable perfile_attrs | |
39ee47ef | 10746 | grid x $top.lattr -sticky w |
f8a2c0d1 | 10747 | |
d93f1713 PT |
10748 | ${NS}::entry $top.extdifft -textvariable extdifftool |
10749 | ${NS}::frame $top.extdifff | |
10750 | ${NS}::label $top.extdifff.l -text [mc "External diff tool" ] | |
10751 | ${NS}::button $top.extdifff.b -text [mc "Choose..."] -command choose_extdiff | |
314f5de1 | 10752 | pack $top.extdifff.l $top.extdifff.b -side left |
d93f1713 PT |
10753 | pack configure $top.extdifff.l -padx 10 |
10754 | grid x $top.extdifff $top.extdifft -sticky ew | |
314f5de1 | 10755 | |
0cc08ff7 PM |
10756 | ${NS}::label $top.lgen -text [mc "General options"] |
10757 | grid $top.lgen - -sticky w -pady 10 | |
10758 | ${NS}::checkbutton $top.want_ttk -variable want_ttk \ | |
10759 | -text [mc "Use themed widgets"] | |
10760 | if {$have_ttk} { | |
10761 | ${NS}::label $top.ttk_note -text [mc "(change requires restart)"] | |
10762 | } else { | |
10763 | ${NS}::label $top.ttk_note -text [mc "(currently unavailable)"] | |
10764 | } | |
10765 | grid x $top.want_ttk $top.ttk_note -sticky w | |
314f5de1 | 10766 | |
d93f1713 | 10767 | ${NS}::label $top.cdisp -text [mc "Colors: press to choose"] |
f8a2c0d1 | 10768 | grid $top.cdisp - -sticky w -pady 10 |
5497f7a2 | 10769 | label $top.ui -padx 40 -relief sunk -background $uicolor |
1924d1bc | 10770 | ${NS}::button $top.uibut -text [mc "Interface"] \ |
5497f7a2 GR |
10771 | -command [list choosecolor uicolor {} $top.ui [mc "interface"] setui] |
10772 | grid x $top.uibut $top.ui -sticky w | |
f8a2c0d1 | 10773 | label $top.bg -padx 40 -relief sunk -background $bgcolor |
d93f1713 | 10774 | ${NS}::button $top.bgbut -text [mc "Background"] \ |
968b016a | 10775 | -command [list choosecolor bgcolor {} $top.bg [mc "background"] setbg] |
f8a2c0d1 PM |
10776 | grid x $top.bgbut $top.bg -sticky w |
10777 | label $top.fg -padx 40 -relief sunk -background $fgcolor | |
d93f1713 | 10778 | ${NS}::button $top.fgbut -text [mc "Foreground"] \ |
968b016a | 10779 | -command [list choosecolor fgcolor {} $top.fg [mc "foreground"] setfg] |
f8a2c0d1 PM |
10780 | grid x $top.fgbut $top.fg -sticky w |
10781 | label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0] | |
d93f1713 | 10782 | ${NS}::button $top.diffoldbut -text [mc "Diff: old lines"] \ |
968b016a | 10783 | -command [list choosecolor diffcolors 0 $top.diffold [mc "diff old lines"] \ |
f8a2c0d1 PM |
10784 | [list $ctext tag conf d0 -foreground]] |
10785 | grid x $top.diffoldbut $top.diffold -sticky w | |
10786 | label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1] | |
d93f1713 | 10787 | ${NS}::button $top.diffnewbut -text [mc "Diff: new lines"] \ |
968b016a | 10788 | -command [list choosecolor diffcolors 1 $top.diffnew [mc "diff new lines"] \ |
8b07dca1 | 10789 | [list $ctext tag conf dresult -foreground]] |
f8a2c0d1 PM |
10790 | grid x $top.diffnewbut $top.diffnew -sticky w |
10791 | label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2] | |
d93f1713 | 10792 | ${NS}::button $top.hunksepbut -text [mc "Diff: hunk header"] \ |
f8a2c0d1 | 10793 | -command [list choosecolor diffcolors 2 $top.hunksep \ |
968b016a | 10794 | [mc "diff hunk header"] \ |
f8a2c0d1 PM |
10795 | [list $ctext tag conf hunksep -foreground]] |
10796 | grid x $top.hunksepbut $top.hunksep -sticky w | |
e3e901be | 10797 | label $top.markbgsep -padx 40 -relief sunk -background $markbgcolor |
d93f1713 | 10798 | ${NS}::button $top.markbgbut -text [mc "Marked line bg"] \ |
e3e901be PM |
10799 | -command [list choosecolor markbgcolor {} $top.markbgsep \ |
10800 | [mc "marked line background"] \ | |
10801 | [list $ctext tag conf omark -background]] | |
10802 | grid x $top.markbgbut $top.markbgsep -sticky w | |
60378c0c | 10803 | label $top.selbgsep -padx 40 -relief sunk -background $selectbgcolor |
d93f1713 | 10804 | ${NS}::button $top.selbgbut -text [mc "Select bg"] \ |
968b016a | 10805 | -command [list choosecolor selectbgcolor {} $top.selbgsep [mc "background"] setselbg] |
60378c0c | 10806 | grid x $top.selbgbut $top.selbgsep -sticky w |
f8a2c0d1 | 10807 | |
d93f1713 | 10808 | ${NS}::label $top.cfont -text [mc "Fonts: press to choose"] |
9a7558f3 | 10809 | grid $top.cfont - -sticky w -pady 10 |
d990cedf CS |
10810 | mkfontdisp mainfont $top [mc "Main font"] |
10811 | mkfontdisp textfont $top [mc "Diff display font"] | |
10812 | mkfontdisp uifont $top [mc "User interface font"] | |
9a7558f3 | 10813 | |
d93f1713 PT |
10814 | ${NS}::frame $top.buts |
10815 | ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active | |
10816 | ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal | |
76f15947 AG |
10817 | bind $top <Key-Return> prefsok |
10818 | bind $top <Key-Escape> prefscan | |
712fcc08 PM |
10819 | grid $top.buts.ok $top.buts.can |
10820 | grid columnconfigure $top.buts 0 -weight 1 -uniform a | |
10821 | grid columnconfigure $top.buts 1 -weight 1 -uniform a | |
10822 | grid $top.buts - - -pady 10 -sticky ew | |
d93f1713 | 10823 | grid columnconfigure $top 2 -weight 1 |
3a950e9a | 10824 | bind $top <Visibility> "focus $top.buts.ok" |
712fcc08 PM |
10825 | } |
10826 | ||
314f5de1 TA |
10827 | proc choose_extdiff {} { |
10828 | global extdifftool | |
10829 | ||
b56e0a9a | 10830 | set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false] |
314f5de1 TA |
10831 | if {$prog ne {}} { |
10832 | set extdifftool $prog | |
10833 | } | |
10834 | } | |
10835 | ||
f8a2c0d1 PM |
10836 | proc choosecolor {v vi w x cmd} { |
10837 | global $v | |
10838 | ||
10839 | set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \ | |
d990cedf | 10840 | -title [mc "Gitk: choose color for %s" $x]] |
f8a2c0d1 PM |
10841 | if {$c eq {}} return |
10842 | $w conf -background $c | |
10843 | lset $v $vi $c | |
10844 | eval $cmd $c | |
10845 | } | |
10846 | ||
60378c0c ML |
10847 | proc setselbg {c} { |
10848 | global bglist cflist | |
10849 | foreach w $bglist { | |
10850 | $w configure -selectbackground $c | |
10851 | } | |
10852 | $cflist tag configure highlight \ | |
10853 | -background [$cflist cget -selectbackground] | |
10854 | allcanvs itemconf secsel -fill $c | |
10855 | } | |
10856 | ||
51a7e8b6 PM |
10857 | # This sets the background color and the color scheme for the whole UI. |
10858 | # For some reason, tk_setPalette chooses a nasty dark red for selectColor | |
10859 | # if we don't specify one ourselves, which makes the checkbuttons and | |
10860 | # radiobuttons look bad. This chooses white for selectColor if the | |
10861 | # background color is light, or black if it is dark. | |
5497f7a2 | 10862 | proc setui {c} { |
2e58c944 | 10863 | if {[tk windowingsystem] eq "win32"} { return } |
51a7e8b6 PM |
10864 | set bg [winfo rgb . $c] |
10865 | set selc black | |
10866 | if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} { | |
10867 | set selc white | |
10868 | } | |
10869 | tk_setPalette background $c selectColor $selc | |
5497f7a2 GR |
10870 | } |
10871 | ||
f8a2c0d1 PM |
10872 | proc setbg {c} { |
10873 | global bglist | |
10874 | ||
10875 | foreach w $bglist { | |
10876 | $w conf -background $c | |
10877 | } | |
10878 | } | |
10879 | ||
10880 | proc setfg {c} { | |
10881 | global fglist canv | |
10882 | ||
10883 | foreach w $fglist { | |
10884 | $w conf -foreground $c | |
10885 | } | |
10886 | allcanvs itemconf text -fill $c | |
10887 | $canv itemconf circle -outline $c | |
b9fdba7f | 10888 | $canv itemconf markid -outline $c |
f8a2c0d1 PM |
10889 | } |
10890 | ||
712fcc08 | 10891 | proc prefscan {} { |
94503918 | 10892 | global oldprefs prefstop |
712fcc08 | 10893 | |
3de07118 | 10894 | foreach v {maxwidth maxgraphpct showneartags showlocalchanges \ |
0cc08ff7 | 10895 | limitdiffs tabstop perfile_attrs hideremotes want_ttk} { |
94503918 | 10896 | global $v |
712fcc08 PM |
10897 | set $v $oldprefs($v) |
10898 | } | |
10899 | catch {destroy $prefstop} | |
10900 | unset prefstop | |
9a7558f3 | 10901 | fontcan |
712fcc08 PM |
10902 | } |
10903 | ||
10904 | proc prefsok {} { | |
10905 | global maxwidth maxgraphpct | |
219ea3a9 | 10906 | global oldprefs prefstop showneartags showlocalchanges |
9a7558f3 | 10907 | global fontpref mainfont textfont uifont |
39ee47ef | 10908 | global limitdiffs treediffs perfile_attrs |
ffe15297 | 10909 | global hideremotes |
712fcc08 PM |
10910 | |
10911 | catch {destroy $prefstop} | |
10912 | unset prefstop | |
9a7558f3 PM |
10913 | fontcan |
10914 | set fontchanged 0 | |
10915 | if {$mainfont ne $fontpref(mainfont)} { | |
10916 | set mainfont $fontpref(mainfont) | |
10917 | parsefont mainfont $mainfont | |
10918 | eval font configure mainfont [fontflags mainfont] | |
10919 | eval font configure mainfontbold [fontflags mainfont 1] | |
10920 | setcoords | |
10921 | set fontchanged 1 | |
10922 | } | |
10923 | if {$textfont ne $fontpref(textfont)} { | |
10924 | set textfont $fontpref(textfont) | |
10925 | parsefont textfont $textfont | |
10926 | eval font configure textfont [fontflags textfont] | |
10927 | eval font configure textfontbold [fontflags textfont 1] | |
10928 | } | |
10929 | if {$uifont ne $fontpref(uifont)} { | |
10930 | set uifont $fontpref(uifont) | |
10931 | parsefont uifont $uifont | |
10932 | eval font configure uifont [fontflags uifont] | |
10933 | } | |
32f1b3e4 | 10934 | settabs |
219ea3a9 PM |
10935 | if {$showlocalchanges != $oldprefs(showlocalchanges)} { |
10936 | if {$showlocalchanges} { | |
10937 | doshowlocalchanges | |
10938 | } else { | |
10939 | dohidelocalchanges | |
10940 | } | |
10941 | } | |
39ee47ef PM |
10942 | if {$limitdiffs != $oldprefs(limitdiffs) || |
10943 | ($perfile_attrs && !$oldprefs(perfile_attrs))} { | |
10944 | # treediffs elements are limited by path; | |
10945 | # won't have encodings cached if perfile_attrs was just turned on | |
74a40c71 PM |
10946 | catch {unset treediffs} |
10947 | } | |
9a7558f3 | 10948 | if {$fontchanged || $maxwidth != $oldprefs(maxwidth) |
712fcc08 PM |
10949 | || $maxgraphpct != $oldprefs(maxgraphpct)} { |
10950 | redisplay | |
7a39a17a PM |
10951 | } elseif {$showneartags != $oldprefs(showneartags) || |
10952 | $limitdiffs != $oldprefs(limitdiffs)} { | |
b8ab2e17 | 10953 | reselectline |
712fcc08 | 10954 | } |
ffe15297 TR |
10955 | if {$hideremotes != $oldprefs(hideremotes)} { |
10956 | rereadrefs | |
10957 | } | |
712fcc08 PM |
10958 | } |
10959 | ||
10960 | proc formatdate {d} { | |
e8b5f4be | 10961 | global datetimeformat |
219ea3a9 | 10962 | if {$d ne {}} { |
e8b5f4be | 10963 | set d [clock format $d -format $datetimeformat] |
219ea3a9 PM |
10964 | } |
10965 | return $d | |
232475d3 PM |
10966 | } |
10967 | ||
fd8ccbec PM |
10968 | # This list of encoding names and aliases is distilled from |
10969 | # http://www.iana.org/assignments/character-sets. | |
10970 | # Not all of them are supported by Tcl. | |
10971 | set encoding_aliases { | |
10972 | { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII | |
10973 | ISO646-US US-ASCII us IBM367 cp367 csASCII } | |
10974 | { ISO-10646-UTF-1 csISO10646UTF1 } | |
10975 | { ISO_646.basic:1983 ref csISO646basic1983 } | |
10976 | { INVARIANT csINVARIANT } | |
10977 | { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion } | |
10978 | { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom } | |
10979 | { NATS-SEFI iso-ir-8-1 csNATSSEFI } | |
10980 | { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD } | |
10981 | { NATS-DANO iso-ir-9-1 csNATSDANO } | |
10982 | { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD } | |
10983 | { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish } | |
10984 | { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames } | |
10985 | { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 } | |
10986 | { ISO-2022-KR csISO2022KR } | |
10987 | { EUC-KR csEUCKR } | |
10988 | { ISO-2022-JP csISO2022JP } | |
10989 | { ISO-2022-JP-2 csISO2022JP2 } | |
10990 | { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7 | |
10991 | csISO13JISC6220jp } | |
10992 | { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro } | |
10993 | { IT iso-ir-15 ISO646-IT csISO15Italian } | |
10994 | { PT iso-ir-16 ISO646-PT csISO16Portuguese } | |
10995 | { ES iso-ir-17 ISO646-ES csISO17Spanish } | |
10996 | { greek7-old iso-ir-18 csISO18Greek7Old } | |
10997 | { latin-greek iso-ir-19 csISO19LatinGreek } | |
10998 | { DIN_66003 iso-ir-21 de ISO646-DE csISO21German } | |
10999 | { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French } | |
11000 | { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 } | |
11001 | { ISO_5427 iso-ir-37 csISO5427Cyrillic } | |
11002 | { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 } | |
11003 | { BS_viewdata iso-ir-47 csISO47BSViewdata } | |
11004 | { INIS iso-ir-49 csISO49INIS } | |
11005 | { INIS-8 iso-ir-50 csISO50INIS8 } | |
11006 | { INIS-cyrillic iso-ir-51 csISO51INISCyrillic } | |
11007 | { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 } | |
11008 | { ISO_5428:1980 iso-ir-55 csISO5428Greek } | |
11009 | { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 } | |
11010 | { GB_2312-80 iso-ir-58 chinese csISO58GB231280 } | |
11011 | { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian | |
11012 | csISO60Norwegian1 } | |
11013 | { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 } | |
11014 | { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French } | |
11015 | { videotex-suppl iso-ir-70 csISO70VideotexSupp1 } | |
11016 | { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 } | |
11017 | { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 } | |
11018 | { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian } | |
11019 | { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 } | |
11020 | { greek7 iso-ir-88 csISO88Greek7 } | |
11021 | { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 } | |
11022 | { iso-ir-90 csISO90 } | |
11023 | { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a } | |
11024 | { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b | |
11025 | csISO92JISC62991984b } | |
11026 | { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd } | |
11027 | { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand } | |
11028 | { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add | |
11029 | csISO95JIS62291984handadd } | |
11030 | { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana } | |
11031 | { ISO_2033-1983 iso-ir-98 e13b csISO2033 } | |
11032 | { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS } | |
11033 | { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819 | |
11034 | CP819 csISOLatin1 } | |
11035 | { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 } | |
11036 | { T.61-7bit iso-ir-102 csISO102T617bit } | |
11037 | { T.61-8bit T.61 iso-ir-103 csISO103T618bit } | |
11038 | { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 } | |
11039 | { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 } | |
11040 | { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic } | |
11041 | { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 } | |
11042 | { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 } | |
11043 | { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr } | |
11044 | { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708 | |
11045 | arabic csISOLatinArabic } | |
11046 | { ISO_8859-6-E csISO88596E ISO-8859-6-E } | |
11047 | { ISO_8859-6-I csISO88596I ISO-8859-6-I } | |
11048 | { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118 | |
11049 | greek greek8 csISOLatinGreek } | |
11050 | { T.101-G2 iso-ir-128 csISO128T101G2 } | |
11051 | { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew | |
11052 | csISOLatinHebrew } | |
11053 | { ISO_8859-8-E csISO88598E ISO-8859-8-E } | |
11054 | { ISO_8859-8-I csISO88598I ISO-8859-8-I } | |
11055 | { CSN_369103 iso-ir-139 csISO139CSN369103 } | |
11056 | { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 } | |
11057 | { ISO_6937-2-add iso-ir-142 csISOTextComm } | |
11058 | { IEC_P27-1 iso-ir-143 csISO143IECP271 } | |
11059 | { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic | |
11060 | csISOLatinCyrillic } | |
11061 | { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian } | |
11062 | { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian } | |
11063 | { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 } | |
11064 | { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT } | |
11065 | { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba } | |
11066 | { ISO_6937-2-25 iso-ir-152 csISO6937Add } | |
11067 | { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 } | |
11068 | { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp } | |
11069 | { ISO_10367-box iso-ir-155 csISO10367Box } | |
11070 | { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 } | |
11071 | { latin-lap lap iso-ir-158 csISO158Lap } | |
11072 | { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 } | |
11073 | { DS_2089 DS2089 ISO646-DK dk csISO646Danish } | |
11074 | { us-dk csUSDK } | |
11075 | { dk-us csDKUS } | |
11076 | { JIS_X0201 X0201 csHalfWidthKatakana } | |
11077 | { KSC5636 ISO646-KR csKSC5636 } | |
11078 | { ISO-10646-UCS-2 csUnicode } | |
11079 | { ISO-10646-UCS-4 csUCS4 } | |
11080 | { DEC-MCS dec csDECMCS } | |
11081 | { hp-roman8 roman8 r8 csHPRoman8 } | |
11082 | { macintosh mac csMacintosh } | |
11083 | { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl | |
11084 | csIBM037 } | |
11085 | { IBM038 EBCDIC-INT cp038 csIBM038 } | |
11086 | { IBM273 CP273 csIBM273 } | |
11087 | { IBM274 EBCDIC-BE CP274 csIBM274 } | |
11088 | { IBM275 EBCDIC-BR cp275 csIBM275 } | |
11089 | { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 } | |
11090 | { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 } | |
11091 | { IBM280 CP280 ebcdic-cp-it csIBM280 } | |
11092 | { IBM281 EBCDIC-JP-E cp281 csIBM281 } | |
11093 | { IBM284 CP284 ebcdic-cp-es csIBM284 } | |
11094 | { IBM285 CP285 ebcdic-cp-gb csIBM285 } | |
11095 | { IBM290 cp290 EBCDIC-JP-kana csIBM290 } | |
11096 | { IBM297 cp297 ebcdic-cp-fr csIBM297 } | |
11097 | { IBM420 cp420 ebcdic-cp-ar1 csIBM420 } | |
11098 | { IBM423 cp423 ebcdic-cp-gr csIBM423 } | |
11099 | { IBM424 cp424 ebcdic-cp-he csIBM424 } | |
11100 | { IBM437 cp437 437 csPC8CodePage437 } | |
11101 | { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 } | |
11102 | { IBM775 cp775 csPC775Baltic } | |
11103 | { IBM850 cp850 850 csPC850Multilingual } | |
11104 | { IBM851 cp851 851 csIBM851 } | |
11105 | { IBM852 cp852 852 csPCp852 } | |
11106 | { IBM855 cp855 855 csIBM855 } | |
11107 | { IBM857 cp857 857 csIBM857 } | |
11108 | { IBM860 cp860 860 csIBM860 } | |
11109 | { IBM861 cp861 861 cp-is csIBM861 } | |
11110 | { IBM862 cp862 862 csPC862LatinHebrew } | |
11111 | { IBM863 cp863 863 csIBM863 } | |
11112 | { IBM864 cp864 csIBM864 } | |
11113 | { IBM865 cp865 865 csIBM865 } | |
11114 | { IBM866 cp866 866 csIBM866 } | |
11115 | { IBM868 CP868 cp-ar csIBM868 } | |
11116 | { IBM869 cp869 869 cp-gr csIBM869 } | |
11117 | { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 } | |
11118 | { IBM871 CP871 ebcdic-cp-is csIBM871 } | |
11119 | { IBM880 cp880 EBCDIC-Cyrillic csIBM880 } | |
11120 | { IBM891 cp891 csIBM891 } | |
11121 | { IBM903 cp903 csIBM903 } | |
11122 | { IBM904 cp904 904 csIBBM904 } | |
11123 | { IBM905 CP905 ebcdic-cp-tr csIBM905 } | |
11124 | { IBM918 CP918 ebcdic-cp-ar2 csIBM918 } | |
11125 | { IBM1026 CP1026 csIBM1026 } | |
11126 | { EBCDIC-AT-DE csIBMEBCDICATDE } | |
11127 | { EBCDIC-AT-DE-A csEBCDICATDEA } | |
11128 | { EBCDIC-CA-FR csEBCDICCAFR } | |
11129 | { EBCDIC-DK-NO csEBCDICDKNO } | |
11130 | { EBCDIC-DK-NO-A csEBCDICDKNOA } | |
11131 | { EBCDIC-FI-SE csEBCDICFISE } | |
11132 | { EBCDIC-FI-SE-A csEBCDICFISEA } | |
11133 | { EBCDIC-FR csEBCDICFR } | |
11134 | { EBCDIC-IT csEBCDICIT } | |
11135 | { EBCDIC-PT csEBCDICPT } | |
11136 | { EBCDIC-ES csEBCDICES } | |
11137 | { EBCDIC-ES-A csEBCDICESA } | |
11138 | { EBCDIC-ES-S csEBCDICESS } | |
11139 | { EBCDIC-UK csEBCDICUK } | |
11140 | { EBCDIC-US csEBCDICUS } | |
11141 | { UNKNOWN-8BIT csUnknown8BiT } | |
11142 | { MNEMONIC csMnemonic } | |
11143 | { MNEM csMnem } | |
11144 | { VISCII csVISCII } | |
11145 | { VIQR csVIQR } | |
11146 | { KOI8-R csKOI8R } | |
11147 | { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro } | |
11148 | { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro } | |
11149 | { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro } | |
11150 | { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro } | |
11151 | { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro } | |
11152 | { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro } | |
11153 | { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro } | |
11154 | { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro } | |
11155 | { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro } | |
11156 | { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro } | |
11157 | { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro } | |
11158 | { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro } | |
11159 | { IBM1047 IBM-1047 } | |
11160 | { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian } | |
11161 | { Amiga-1251 Ami1251 Amiga1251 Ami-1251 } | |
11162 | { UNICODE-1-1 csUnicode11 } | |
11163 | { CESU-8 csCESU-8 } | |
11164 | { BOCU-1 csBOCU-1 } | |
11165 | { UNICODE-1-1-UTF-7 csUnicode11UTF7 } | |
11166 | { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic | |
11167 | l8 } | |
11168 | { ISO-8859-15 ISO_8859-15 Latin-9 } | |
11169 | { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 } | |
11170 | { GBK CP936 MS936 windows-936 } | |
11171 | { JIS_Encoding csJISEncoding } | |
09c7029d | 11172 | { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS } |
fd8ccbec PM |
11173 | { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese |
11174 | EUC-JP } | |
11175 | { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese } | |
11176 | { ISO-10646-UCS-Basic csUnicodeASCII } | |
11177 | { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 } | |
11178 | { ISO-Unicode-IBM-1261 csUnicodeIBM1261 } | |
11179 | { ISO-Unicode-IBM-1268 csUnicodeIBM1268 } | |
11180 | { ISO-Unicode-IBM-1276 csUnicodeIBM1276 } | |
11181 | { ISO-Unicode-IBM-1264 csUnicodeIBM1264 } | |
11182 | { ISO-Unicode-IBM-1265 csUnicodeIBM1265 } | |
11183 | { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 } | |
11184 | { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 } | |
11185 | { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 } | |
11186 | { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 } | |
11187 | { Adobe-Standard-Encoding csAdobeStandardEncoding } | |
11188 | { Ventura-US csVenturaUS } | |
11189 | { Ventura-International csVenturaInternational } | |
11190 | { PC8-Danish-Norwegian csPC8DanishNorwegian } | |
11191 | { PC8-Turkish csPC8Turkish } | |
11192 | { IBM-Symbols csIBMSymbols } | |
11193 | { IBM-Thai csIBMThai } | |
11194 | { HP-Legal csHPLegal } | |
11195 | { HP-Pi-font csHPPiFont } | |
11196 | { HP-Math8 csHPMath8 } | |
11197 | { Adobe-Symbol-Encoding csHPPSMath } | |
11198 | { HP-DeskTop csHPDesktop } | |
11199 | { Ventura-Math csVenturaMath } | |
11200 | { Microsoft-Publishing csMicrosoftPublishing } | |
11201 | { Windows-31J csWindows31J } | |
11202 | { GB2312 csGB2312 } | |
11203 | { Big5 csBig5 } | |
11204 | } | |
11205 | ||
11206 | proc tcl_encoding {enc} { | |
39ee47ef PM |
11207 | global encoding_aliases tcl_encoding_cache |
11208 | if {[info exists tcl_encoding_cache($enc)]} { | |
11209 | return $tcl_encoding_cache($enc) | |
11210 | } | |
fd8ccbec PM |
11211 | set names [encoding names] |
11212 | set lcnames [string tolower $names] | |
11213 | set enc [string tolower $enc] | |
11214 | set i [lsearch -exact $lcnames $enc] | |
11215 | if {$i < 0} { | |
11216 | # look for "isonnn" instead of "iso-nnn" or "iso_nnn" | |
09c7029d | 11217 | if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} { |
fd8ccbec PM |
11218 | set i [lsearch -exact $lcnames $encx] |
11219 | } | |
11220 | } | |
11221 | if {$i < 0} { | |
11222 | foreach l $encoding_aliases { | |
11223 | set ll [string tolower $l] | |
11224 | if {[lsearch -exact $ll $enc] < 0} continue | |
11225 | # look through the aliases for one that tcl knows about | |
11226 | foreach e $ll { | |
11227 | set i [lsearch -exact $lcnames $e] | |
11228 | if {$i < 0} { | |
09c7029d | 11229 | if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} { |
fd8ccbec PM |
11230 | set i [lsearch -exact $lcnames $ex] |
11231 | } | |
11232 | } | |
11233 | if {$i >= 0} break | |
11234 | } | |
11235 | break | |
11236 | } | |
11237 | } | |
39ee47ef | 11238 | set tclenc {} |
fd8ccbec | 11239 | if {$i >= 0} { |
39ee47ef | 11240 | set tclenc [lindex $names $i] |
fd8ccbec | 11241 | } |
39ee47ef PM |
11242 | set tcl_encoding_cache($enc) $tclenc |
11243 | return $tclenc | |
fd8ccbec PM |
11244 | } |
11245 | ||
09c7029d | 11246 | proc gitattr {path attr default} { |
39ee47ef PM |
11247 | global path_attr_cache |
11248 | if {[info exists path_attr_cache($attr,$path)]} { | |
11249 | set r $path_attr_cache($attr,$path) | |
11250 | } else { | |
11251 | set r "unspecified" | |
11252 | if {![catch {set line [exec git check-attr $attr -- $path]}]} { | |
097e1118 | 11253 | regexp "(.*): $attr: (.*)" $line m f r |
09c7029d | 11254 | } |
4db09304 | 11255 | set path_attr_cache($attr,$path) $r |
39ee47ef PM |
11256 | } |
11257 | if {$r eq "unspecified"} { | |
11258 | return $default | |
11259 | } | |
11260 | return $r | |
09c7029d AG |
11261 | } |
11262 | ||
4db09304 | 11263 | proc cache_gitattr {attr pathlist} { |
39ee47ef PM |
11264 | global path_attr_cache |
11265 | set newlist {} | |
11266 | foreach path $pathlist { | |
11267 | if {![info exists path_attr_cache($attr,$path)]} { | |
11268 | lappend newlist $path | |
11269 | } | |
11270 | } | |
11271 | set lim 1000 | |
11272 | if {[tk windowingsystem] == "win32"} { | |
11273 | # windows has a 32k limit on the arguments to a command... | |
11274 | set lim 30 | |
11275 | } | |
11276 | while {$newlist ne {}} { | |
11277 | set head [lrange $newlist 0 [expr {$lim - 1}]] | |
11278 | set newlist [lrange $newlist $lim end] | |
11279 | if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} { | |
11280 | foreach row [split $rlist "\n"] { | |
097e1118 | 11281 | if {[regexp "(.*): $attr: (.*)" $row m path value]} { |
39ee47ef PM |
11282 | if {[string index $path 0] eq "\""} { |
11283 | set path [encoding convertfrom [lindex $path 0]] | |
11284 | } | |
11285 | set path_attr_cache($attr,$path) $value | |
4db09304 | 11286 | } |
39ee47ef | 11287 | } |
4db09304 | 11288 | } |
39ee47ef | 11289 | } |
4db09304 AG |
11290 | } |
11291 | ||
09c7029d | 11292 | proc get_path_encoding {path} { |
39ee47ef PM |
11293 | global gui_encoding perfile_attrs |
11294 | set tcl_enc $gui_encoding | |
11295 | if {$path ne {} && $perfile_attrs} { | |
11296 | set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]] | |
11297 | if {$enc2 ne {}} { | |
11298 | set tcl_enc $enc2 | |
09c7029d | 11299 | } |
39ee47ef PM |
11300 | } |
11301 | return $tcl_enc | |
09c7029d AG |
11302 | } |
11303 | ||
5d7589d4 PM |
11304 | # First check that Tcl/Tk is recent enough |
11305 | if {[catch {package require Tk 8.4} err]} { | |
8d849957 BH |
11306 | show_error {} . "Sorry, gitk cannot run with this version of Tcl/Tk.\n\ |
11307 | Gitk requires at least Tcl/Tk 8.4." list | |
5d7589d4 PM |
11308 | exit 1 |
11309 | } | |
11310 | ||
1d10f36d | 11311 | # defaults... |
8974c6f9 | 11312 | set wrcomcmd "git diff-tree --stdin -p --pretty" |
671bc153 | 11313 | |
fd8ccbec | 11314 | set gitencoding {} |
671bc153 | 11315 | catch { |
27cb61ca | 11316 | set gitencoding [exec git config --get i18n.commitencoding] |
671bc153 | 11317 | } |
590915da AG |
11318 | catch { |
11319 | set gitencoding [exec git config --get i18n.logoutputencoding] | |
11320 | } | |
671bc153 | 11321 | if {$gitencoding == ""} { |
fd8ccbec PM |
11322 | set gitencoding "utf-8" |
11323 | } | |
11324 | set tclencoding [tcl_encoding $gitencoding] | |
11325 | if {$tclencoding == {}} { | |
11326 | puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk" | |
671bc153 | 11327 | } |
1db95b00 | 11328 | |
09c7029d AG |
11329 | set gui_encoding [encoding system] |
11330 | catch { | |
39ee47ef PM |
11331 | set enc [exec git config --get gui.encoding] |
11332 | if {$enc ne {}} { | |
11333 | set tclenc [tcl_encoding $enc] | |
11334 | if {$tclenc ne {}} { | |
11335 | set gui_encoding $tclenc | |
11336 | } else { | |
11337 | puts stderr "Warning: encoding $enc is not supported by Tcl/Tk" | |
11338 | } | |
11339 | } | |
09c7029d AG |
11340 | } |
11341 | ||
5fdcbb13 DS |
11342 | if {[tk windowingsystem] eq "aqua"} { |
11343 | set mainfont {{Lucida Grande} 9} | |
11344 | set textfont {Monaco 9} | |
11345 | set uifont {{Lucida Grande} 9 bold} | |
11346 | } else { | |
11347 | set mainfont {Helvetica 9} | |
11348 | set textfont {Courier 9} | |
11349 | set uifont {Helvetica 9 bold} | |
11350 | } | |
7e12f1a6 | 11351 | set tabstop 8 |
b74fd579 | 11352 | set findmergefiles 0 |
8d858d1a | 11353 | set maxgraphpct 50 |
f6075eba | 11354 | set maxwidth 16 |
232475d3 | 11355 | set revlistorder 0 |
757f17bc | 11356 | set fastdate 0 |
6e8c8707 PM |
11357 | set uparrowlen 5 |
11358 | set downarrowlen 5 | |
11359 | set mingaplen 100 | |
f8b28a40 | 11360 | set cmitmode "patch" |
f1b86294 | 11361 | set wrapcomment "none" |
b8ab2e17 | 11362 | set showneartags 1 |
ffe15297 | 11363 | set hideremotes 0 |
0a4dd8b8 | 11364 | set maxrefs 20 |
322a8cc9 | 11365 | set maxlinelen 200 |
219ea3a9 | 11366 | set showlocalchanges 1 |
7a39a17a | 11367 | set limitdiffs 1 |
e8b5f4be | 11368 | set datetimeformat "%Y-%m-%d %H:%M:%S" |
95293b58 | 11369 | set autoselect 1 |
39ee47ef | 11370 | set perfile_attrs 0 |
0cc08ff7 | 11371 | set want_ttk 1 |
1d10f36d | 11372 | |
5fdcbb13 DS |
11373 | if {[tk windowingsystem] eq "aqua"} { |
11374 | set extdifftool "opendiff" | |
11375 | } else { | |
11376 | set extdifftool "meld" | |
11377 | } | |
314f5de1 | 11378 | |
1d10f36d | 11379 | set colors {green red blue magenta darkgrey brown orange} |
1924d1bc PT |
11380 | if {[tk windowingsystem] eq "win32"} { |
11381 | set uicolor SystemButtonFace | |
11382 | set bgcolor SystemWindow | |
11383 | set fgcolor SystemButtonText | |
11384 | set selectbgcolor SystemHighlight | |
11385 | } else { | |
11386 | set uicolor grey85 | |
11387 | set bgcolor white | |
11388 | set fgcolor black | |
11389 | set selectbgcolor gray85 | |
11390 | } | |
f8a2c0d1 | 11391 | set diffcolors {red "#00a000" blue} |
890fae70 | 11392 | set diffcontext 3 |
b9b86007 | 11393 | set ignorespace 0 |
e3e901be | 11394 | set markbgcolor "#e0e0ff" |
1d10f36d | 11395 | |
c11ff120 PM |
11396 | set circlecolors {white blue gray blue blue} |
11397 | ||
d277e89f PM |
11398 | # button for popping up context menus |
11399 | if {[tk windowingsystem] eq "aqua"} { | |
11400 | set ctxbut <Button-2> | |
11401 | } else { | |
11402 | set ctxbut <Button-3> | |
11403 | } | |
11404 | ||
663c3aa9 CS |
11405 | ## For msgcat loading, first locate the installation location. |
11406 | if { [info exists ::env(GITK_MSGSDIR)] } { | |
11407 | ## Msgsdir was manually set in the environment. | |
11408 | set gitk_msgsdir $::env(GITK_MSGSDIR) | |
11409 | } else { | |
11410 | ## Let's guess the prefix from argv0. | |
11411 | set gitk_prefix [file dirname [file dirname [file normalize $argv0]]] | |
11412 | set gitk_libdir [file join $gitk_prefix share gitk lib] | |
11413 | set gitk_msgsdir [file join $gitk_libdir msgs] | |
11414 | unset gitk_prefix | |
11415 | } | |
11416 | ||
11417 | ## Internationalization (i18n) through msgcat and gettext. See | |
11418 | ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html | |
11419 | package require msgcat | |
11420 | namespace import ::msgcat::mc | |
11421 | ## And eventually load the actual message catalog | |
11422 | ::msgcat::mcload $gitk_msgsdir | |
11423 | ||
1d10f36d PM |
11424 | catch {source ~/.gitk} |
11425 | ||
0ed1dd3c PM |
11426 | parsefont mainfont $mainfont |
11427 | eval font create mainfont [fontflags mainfont] | |
11428 | eval font create mainfontbold [fontflags mainfont 1] | |
11429 | ||
11430 | parsefont textfont $textfont | |
11431 | eval font create textfont [fontflags textfont] | |
11432 | eval font create textfontbold [fontflags textfont 1] | |
11433 | ||
11434 | parsefont uifont $uifont | |
11435 | eval font create uifont [fontflags uifont] | |
17386066 | 11436 | |
51a7e8b6 | 11437 | setui $uicolor |
5497f7a2 | 11438 | |
b039f0a6 PM |
11439 | setoptions |
11440 | ||
cdaee5db | 11441 | # check that we can find a .git directory somewhere... |
6c87d60c | 11442 | if {[catch {set gitdir [gitdir]}]} { |
d990cedf | 11443 | show_error {} . [mc "Cannot find a git repository here."] |
6c87d60c AR |
11444 | exit 1 |
11445 | } | |
cdaee5db | 11446 | if {![file isdirectory $gitdir]} { |
d990cedf | 11447 | show_error {} . [mc "Cannot find the git directory \"%s\"." $gitdir] |
cdaee5db PM |
11448 | exit 1 |
11449 | } | |
11450 | ||
39816d60 AG |
11451 | set selecthead {} |
11452 | set selectheadid {} | |
11453 | ||
1d10f36d | 11454 | set revtreeargs {} |
cdaee5db PM |
11455 | set cmdline_files {} |
11456 | set i 0 | |
2d480856 | 11457 | set revtreeargscmd {} |
1d10f36d | 11458 | foreach arg $argv { |
2d480856 | 11459 | switch -glob -- $arg { |
6ebedabf | 11460 | "" { } |
cdaee5db PM |
11461 | "--" { |
11462 | set cmdline_files [lrange $argv [expr {$i + 1}] end] | |
11463 | break | |
11464 | } | |
39816d60 AG |
11465 | "--select-commit=*" { |
11466 | set selecthead [string range $arg 16 end] | |
11467 | } | |
2d480856 YD |
11468 | "--argscmd=*" { |
11469 | set revtreeargscmd [string range $arg 10 end] | |
11470 | } | |
1d10f36d PM |
11471 | default { |
11472 | lappend revtreeargs $arg | |
11473 | } | |
11474 | } | |
cdaee5db | 11475 | incr i |
1db95b00 | 11476 | } |
1d10f36d | 11477 | |
39816d60 AG |
11478 | if {$selecthead eq "HEAD"} { |
11479 | set selecthead {} | |
11480 | } | |
11481 | ||
cdaee5db | 11482 | if {$i >= [llength $argv] && $revtreeargs ne {}} { |
3ed31a81 | 11483 | # no -- on command line, but some arguments (other than --argscmd) |
098dd8a3 | 11484 | if {[catch { |
8974c6f9 | 11485 | set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs] |
098dd8a3 PM |
11486 | set cmdline_files [split $f "\n"] |
11487 | set n [llength $cmdline_files] | |
11488 | set revtreeargs [lrange $revtreeargs 0 end-$n] | |
cdaee5db PM |
11489 | # Unfortunately git rev-parse doesn't produce an error when |
11490 | # something is both a revision and a filename. To be consistent | |
11491 | # with git log and git rev-list, check revtreeargs for filenames. | |
11492 | foreach arg $revtreeargs { | |
11493 | if {[file exists $arg]} { | |
d990cedf CS |
11494 | show_error {} . [mc "Ambiguous argument '%s': both revision\ |
11495 | and filename" $arg] | |
cdaee5db PM |
11496 | exit 1 |
11497 | } | |
11498 | } | |
098dd8a3 PM |
11499 | } err]} { |
11500 | # unfortunately we get both stdout and stderr in $err, | |
11501 | # so look for "fatal:". | |
11502 | set i [string first "fatal:" $err] | |
11503 | if {$i > 0} { | |
b5e09633 | 11504 | set err [string range $err [expr {$i + 6}] end] |
098dd8a3 | 11505 | } |
d990cedf | 11506 | show_error {} . "[mc "Bad arguments to gitk:"]\n$err" |
098dd8a3 PM |
11507 | exit 1 |
11508 | } | |
11509 | } | |
11510 | ||
219ea3a9 | 11511 | set nullid "0000000000000000000000000000000000000000" |
8f489363 | 11512 | set nullid2 "0000000000000000000000000000000000000001" |
314f5de1 | 11513 | set nullfile "/dev/null" |
8f489363 | 11514 | |
32f1b3e4 | 11515 | set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}] |
0cc08ff7 PM |
11516 | if {![info exists have_ttk]} { |
11517 | set have_ttk [llength [info commands ::ttk::style]] | |
d93f1713 | 11518 | } |
0cc08ff7 | 11519 | set use_ttk [expr {$have_ttk && $want_ttk}] |
d93f1713 | 11520 | set NS [expr {$use_ttk ? "ttk" : ""}] |
0cc08ff7 | 11521 | |
194bbf6c | 11522 | set git_version [join [lrange [split [lindex [exec git version] end] .] 0 2] .] |
219ea3a9 | 11523 | |
7eb3cb9c | 11524 | set runq {} |
d698206c PM |
11525 | set history {} |
11526 | set historyindex 0 | |
908c3585 | 11527 | set fh_serial 0 |
908c3585 | 11528 | set nhl_names {} |
63b79191 | 11529 | set highlight_paths {} |
687c8765 | 11530 | set findpattern {} |
1902c270 | 11531 | set searchdirn -forwards |
28593d3f PM |
11532 | set boldids {} |
11533 | set boldnameids {} | |
a8d610a2 | 11534 | set diffelide {0 0} |
4fb0fa19 | 11535 | set markingmatches 0 |
97645683 | 11536 | set linkentercount 0 |
0380081c PM |
11537 | set need_redisplay 0 |
11538 | set nrows_drawn 0 | |
32f1b3e4 | 11539 | set firsttabstop 0 |
9f1afe05 | 11540 | |
50b44ece PM |
11541 | set nextviewnum 1 |
11542 | set curview 0 | |
a90a6d24 | 11543 | set selectedview 0 |
b007ee20 CS |
11544 | set selectedhlview [mc "None"] |
11545 | set highlight_related [mc "None"] | |
687c8765 | 11546 | set highlight_files {} |
50b44ece | 11547 | set viewfiles(0) {} |
a90a6d24 | 11548 | set viewperm(0) 0 |
098dd8a3 | 11549 | set viewargs(0) {} |
2d480856 | 11550 | set viewargscmd(0) {} |
50b44ece | 11551 | |
94b4a69f | 11552 | set selectedline {} |
6df7403a | 11553 | set numcommits 0 |
7fcc92bf | 11554 | set loginstance 0 |
098dd8a3 | 11555 | set cmdlineok 0 |
1d10f36d | 11556 | set stopped 0 |
0fba86b3 | 11557 | set stuffsaved 0 |
74daedb6 | 11558 | set patchnum 0 |
219ea3a9 | 11559 | set lserial 0 |
cb8329aa | 11560 | set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}] |
1d10f36d | 11561 | setcoords |
d94f8cd6 | 11562 | makewindow |
37871b73 GB |
11563 | catch { |
11564 | image create photo gitlogo -width 16 -height 16 | |
11565 | ||
11566 | image create photo gitlogominus -width 4 -height 2 | |
11567 | gitlogominus put #C00000 -to 0 0 4 2 | |
11568 | gitlogo copy gitlogominus -to 1 5 | |
11569 | gitlogo copy gitlogominus -to 6 5 | |
11570 | gitlogo copy gitlogominus -to 11 5 | |
11571 | image delete gitlogominus | |
11572 | ||
11573 | image create photo gitlogoplus -width 4 -height 4 | |
11574 | gitlogoplus put #008000 -to 1 0 3 4 | |
11575 | gitlogoplus put #008000 -to 0 1 4 3 | |
11576 | gitlogo copy gitlogoplus -to 1 9 | |
11577 | gitlogo copy gitlogoplus -to 6 9 | |
11578 | gitlogo copy gitlogoplus -to 11 9 | |
11579 | image delete gitlogoplus | |
11580 | ||
d38d7d49 SB |
11581 | image create photo gitlogo32 -width 32 -height 32 |
11582 | gitlogo32 copy gitlogo -zoom 2 2 | |
11583 | ||
11584 | wm iconphoto . -default gitlogo gitlogo32 | |
37871b73 | 11585 | } |
0eafba14 PM |
11586 | # wait for the window to become visible |
11587 | tkwait visibility . | |
6c283328 | 11588 | wm title . "[file tail $argv0]: [file tail [pwd]]" |
478afad6 | 11589 | update |
887fe3c4 | 11590 | readrefs |
a8aaf19c | 11591 | |
2d480856 | 11592 | if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} { |
50b44ece PM |
11593 | # create a view for the files/dirs specified on the command line |
11594 | set curview 1 | |
a90a6d24 | 11595 | set selectedview 1 |
50b44ece | 11596 | set nextviewnum 2 |
d990cedf | 11597 | set viewname(1) [mc "Command line"] |
50b44ece | 11598 | set viewfiles(1) $cmdline_files |
098dd8a3 | 11599 | set viewargs(1) $revtreeargs |
2d480856 | 11600 | set viewargscmd(1) $revtreeargscmd |
a90a6d24 | 11601 | set viewperm(1) 0 |
3ed31a81 | 11602 | set vdatemode(1) 0 |
da7c24dd | 11603 | addviewmenu 1 |
f2d0bbbd PM |
11604 | .bar.view entryconf [mca "Edit view..."] -state normal |
11605 | .bar.view entryconf [mca "Delete view"] -state normal | |
50b44ece | 11606 | } |
a90a6d24 PM |
11607 | |
11608 | if {[info exists permviews]} { | |
11609 | foreach v $permviews { | |
11610 | set n $nextviewnum | |
11611 | incr nextviewnum | |
11612 | set viewname($n) [lindex $v 0] | |
11613 | set viewfiles($n) [lindex $v 1] | |
098dd8a3 | 11614 | set viewargs($n) [lindex $v 2] |
2d480856 | 11615 | set viewargscmd($n) [lindex $v 3] |
a90a6d24 | 11616 | set viewperm($n) 1 |
da7c24dd | 11617 | addviewmenu $n |
a90a6d24 PM |
11618 | } |
11619 | } | |
e4df519f JS |
11620 | |
11621 | if {[tk windowingsystem] eq "win32"} { | |
11622 | focus -force . | |
11623 | } | |
11624 | ||
567c34e0 | 11625 | getcommits {} |
adab0dab PT |
11626 | |
11627 | # Local variables: | |
11628 | # mode: tcl | |
11629 | # indent-tabs-mode: t | |
11630 | # tab-width: 8 | |
11631 | # End: |