blob: 23d9dd1fe0d024c4af344c35faf01365ec8a6c58 [file] [log] [blame]
Paul Mackerras1db95b02005-05-09 04:08:39 +00001#!/bin/sh
2# Tcl ignores the next line -*- tcl -*- \
Paul Mackerras9e026d32005-09-27 10:29:41 +10003exec wish "$0" -- "$@"
Paul Mackerras1db95b02005-05-09 04:08:39 +00004
Paul Mackerrasfbf42642016-12-12 20:46:42 +11005# Copyright © 2005-2016 Paul Mackerras. All rights reserved.
Paul Mackerras1db95b02005-05-09 04:08:39 +00006# 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
Pat Thoytsd93f1712009-04-17 01:24:35 +010010package require Tk
11
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -040012proc hasworktree {} {
13 return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
Denton Liue2445882020-09-10 21:36:33 -070014 [exec git rev-parse --is-inside-git-dir] == "false"}]
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -040015}
16
Zbigniew Jędrzejewski-Szmek3878e632011-11-09 17:28:28 +010017proc reponame {} {
18 global gitdir
19 set n [file normalize $gitdir]
20 if {[string match "*/.git" $n]} {
Denton Liue2445882020-09-10 21:36:33 -070021 set n [string range $n 0 end-5]
Zbigniew Jędrzejewski-Szmek3878e632011-11-09 17:28:28 +010022 }
23 return [file tail $n]
24}
25
Pat Thoyts65bb0bd2011-12-13 16:50:50 +000026proc gitworktree {} {
27 variable _gitworktree
28 if {[info exists _gitworktree]} {
Denton Liue2445882020-09-10 21:36:33 -070029 return $_gitworktree
Pat Thoyts65bb0bd2011-12-13 16:50:50 +000030 }
31 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
32 if {[catch {set _gitworktree [exec git rev-parse --show-toplevel]}]} {
33 # try to set work tree from environment, core.worktree or use
34 # cdup to obtain a relative path to the top of the worktree. If
35 # run from the top, the ./ prefix ensures normalize expands pwd.
36 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
Denton Liue2445882020-09-10 21:36:33 -070037 if {[catch {set _gitworktree [exec git config --get core.worktree]}]} {
38 set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]]
39 }
Pat Thoyts65bb0bd2011-12-13 16:50:50 +000040 }
41 }
42 return $_gitworktree
43}
44
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100045# A simple scheduler for compute-intensive stuff.
46# The aim is to make sure that event handlers for GUI actions can
47# run at least every 50-100 ms. Unfortunately fileevent handlers are
48# run before X event handlers, so reading from a fast source can
49# make the GUI completely unresponsive.
50proc run args {
Alexander Gavrilovdf75e862008-08-09 14:41:50 +040051 global isonrunq runq currunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100052
53 set script $args
54 if {[info exists isonrunq($script)]} return
Alexander Gavrilovdf75e862008-08-09 14:41:50 +040055 if {$runq eq {} && ![info exists currunq]} {
Denton Liue2445882020-09-10 21:36:33 -070056 after idle dorunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100057 }
58 lappend runq [list {} $script]
59 set isonrunq($script) 1
60}
61
62proc filerun {fd script} {
63 fileevent $fd readable [list filereadable $fd $script]
64}
65
66proc filereadable {fd script} {
Alexander Gavrilovdf75e862008-08-09 14:41:50 +040067 global runq currunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100068
69 fileevent $fd readable {}
Alexander Gavrilovdf75e862008-08-09 14:41:50 +040070 if {$runq eq {} && ![info exists currunq]} {
Denton Liue2445882020-09-10 21:36:33 -070071 after idle dorunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100072 }
73 lappend runq [list $fd $script]
74}
75
Paul Mackerras7fcc92b2007-12-03 10:33:01 +110076proc nukefile {fd} {
77 global runq
78
79 for {set i 0} {$i < [llength $runq]} {} {
Denton Liue2445882020-09-10 21:36:33 -070080 if {[lindex $runq $i 0] eq $fd} {
81 set runq [lreplace $runq $i $i]
82 } else {
83 incr i
84 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +110085 }
86}
87
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100088proc dorunq {} {
Alexander Gavrilovdf75e862008-08-09 14:41:50 +040089 global isonrunq runq currunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100090
91 set tstart [clock clicks -milliseconds]
92 set t0 $tstart
Paul Mackerras7fcc92b2007-12-03 10:33:01 +110093 while {[llength $runq] > 0} {
Denton Liue2445882020-09-10 21:36:33 -070094 set fd [lindex $runq 0 0]
95 set script [lindex $runq 0 1]
96 set currunq [lindex $runq 0]
97 set runq [lrange $runq 1 end]
98 set repeat [eval $script]
99 unset currunq
100 set t1 [clock clicks -milliseconds]
101 set t [expr {$t1 - $t0}]
102 if {$repeat ne {} && $repeat} {
103 if {$fd eq {} || $repeat == 2} {
104 # script returns 1 if it wants to be readded
105 # file readers return 2 if they could do more straight away
106 lappend runq [list $fd $script]
107 } else {
108 fileevent $fd readable [list filereadable $fd $script]
109 }
110 } elseif {$fd eq {}} {
111 unset isonrunq($script)
112 }
113 set t0 $t1
114 if {$t1 - $tstart >= 80} break
Paul Mackerras7eb3cb92007-06-17 14:45:00 +1000115 }
116 if {$runq ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700117 after idle dorunq
Paul Mackerras7eb3cb92007-06-17 14:45:00 +1000118 }
119}
120
Alexander Gavrilove439e092008-07-13 16:40:47 +0400121proc reg_instance {fd} {
122 global commfd leftover loginstance
123
124 set i [incr loginstance]
125 set commfd($i) $fd
126 set leftover($i) {}
127 return $i
128}
129
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000130proc unmerged_files {files} {
131 global nr_unmerged
132
133 # find the list of unmerged files
134 set mlist {}
135 set nr_unmerged 0
136 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -0700137 set fd [open "| git ls-files -u" r]
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000138 } err]} {
Denton Liue2445882020-09-10 21:36:33 -0700139 show_error {} . "[mc "Couldn't get list of unmerged files:"] $err"
140 exit 1
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000141 }
142 while {[gets $fd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -0700143 set i [string first "\t" $line]
144 if {$i < 0} continue
145 set fname [string range $line [expr {$i+1}] end]
146 if {[lsearch -exact $mlist $fname] >= 0} continue
147 incr nr_unmerged
148 if {$files eq {} || [path_filter $files $fname]} {
149 lappend mlist $fname
150 }
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000151 }
152 catch {close $fd}
153 return $mlist
154}
155
156proc parseviewargs {n arglist} {
Christian Couderc2f2dab2009-12-12 05:52:39 +0100157 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env
Thomas Rast9403bd02013-11-16 18:37:43 +0100158 global vinlinediff
Thomas Rastae4e3ff2010-10-16 12:15:10 +0200159 global worddiff git_version
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000160
161 set vdatemode($n) 0
162 set vmergeonly($n) 0
Thomas Rast9403bd02013-11-16 18:37:43 +0100163 set vinlinediff($n) 0
Paul Mackerrasee66e082008-05-09 10:14:07 +1000164 set glflags {}
165 set diffargs {}
166 set nextisval 0
167 set revargs {}
168 set origargs $arglist
169 set allknown 1
170 set filtered 0
171 set i -1
172 foreach arg $arglist {
Denton Liue2445882020-09-10 21:36:33 -0700173 incr i
174 if {$nextisval} {
175 lappend glflags $arg
176 set nextisval 0
177 continue
178 }
179 switch -glob -- $arg {
180 "-d" -
181 "--date-order" {
182 set vdatemode($n) 1
183 # remove from origargs in case we hit an unknown option
184 set origargs [lreplace $origargs $i $i]
185 incr i -1
186 }
187 "-[puabwcrRBMC]" -
188 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" -
189 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" -
190 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" -
191 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" -
192 "--ignore-space-change" - "-U*" - "--unified=*" {
193 # These request or affect diff output, which we don't want.
194 # Some could be used to set our defaults for diff display.
195 lappend diffargs $arg
196 }
197 "--raw" - "--patch-with-raw" - "--patch-with-stat" -
198 "--name-only" - "--name-status" - "--color" -
199 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" -
200 "--cc" - "-z" - "--header" - "--parents" - "--boundary" -
201 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" -
202 "--timestamp" - "relative-date" - "--date=*" - "--stdin" -
203 "--objects" - "--objects-edge" - "--reverse" {
204 # These cause our parsing of git log's output to fail, or else
205 # they're options we want to set ourselves, so ignore them.
206 }
207 "--color-words*" - "--word-diff=color" {
208 # These trigger a word diff in the console interface,
209 # so help the user by enabling our own support
210 if {[package vcompare $git_version "1.7.2"] >= 0} {
211 set worddiff [mc "Color words"]
212 }
213 }
214 "--word-diff*" {
215 if {[package vcompare $git_version "1.7.2"] >= 0} {
216 set worddiff [mc "Markup words"]
217 }
218 }
219 "--stat=*" - "--numstat" - "--shortstat" - "--summary" -
220 "--check" - "--exit-code" - "--quiet" - "--topo-order" -
221 "--full-history" - "--dense" - "--sparse" -
222 "--follow" - "--left-right" - "--encoding=*" {
223 # These are harmless, and some are even useful
224 lappend glflags $arg
225 }
226 "--diff-filter=*" - "--no-merges" - "--unpacked" -
227 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" -
228 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" -
229 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" -
230 "--remove-empty" - "--first-parent" - "--cherry-pick" -
231 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" -
232 "--simplify-by-decoration" {
233 # These mean that we get a subset of the commits
234 set filtered 1
235 lappend glflags $arg
236 }
237 "-L*" {
238 # Line-log with 'stuck' argument (unstuck form is
239 # not supported)
240 set filtered 1
241 set vinlinediff($n) 1
242 set allknown 0
243 lappend glflags $arg
244 }
245 "-n" {
246 # This appears to be the only one that has a value as a
247 # separate word following it
248 set filtered 1
249 set nextisval 1
250 lappend glflags $arg
251 }
252 "--not" - "--all" {
253 lappend revargs $arg
254 }
255 "--merge" {
256 set vmergeonly($n) 1
257 # git rev-parse doesn't understand --merge
258 lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD
259 }
260 "--no-replace-objects" {
261 set env(GIT_NO_REPLACE_OBJECTS) "1"
262 }
263 "-*" {
264 # Other flag arguments including -<n>
265 if {[string is digit -strict [string range $arg 1 end]]} {
266 set filtered 1
267 } else {
268 # a flag argument that we don't recognize;
269 # that means we can't optimize
270 set allknown 0
271 }
272 lappend glflags $arg
273 }
274 default {
275 # Non-flag arguments specify commits or ranges of commits
276 if {[string match "*...*" $arg]} {
277 lappend revargs --gitk-symmetric-diff-marker
278 }
279 lappend revargs $arg
280 }
281 }
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000282 }
Paul Mackerrasee66e082008-05-09 10:14:07 +1000283 set vdflags($n) $diffargs
284 set vflags($n) $glflags
285 set vrevs($n) $revargs
286 set vfiltered($n) $filtered
287 set vorigargs($n) $origargs
288 return $allknown
289}
290
291proc parseviewrevs {view revs} {
292 global vposids vnegids
293
294 if {$revs eq {}} {
Denton Liue2445882020-09-10 21:36:33 -0700295 set revs HEAD
Max Kirillov4d5e1b12014-09-09 10:29:16 +0300296 } elseif {[lsearch -exact $revs --all] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -0700297 lappend revs HEAD
Paul Mackerrasee66e082008-05-09 10:14:07 +1000298 }
299 if {[catch {set ids [eval exec git rev-parse $revs]} err]} {
Denton Liue2445882020-09-10 21:36:33 -0700300 # we get stdout followed by stderr in $err
301 # for an unknown rev, git rev-parse echoes it and then errors out
302 set errlines [split $err "\n"]
303 set badrev {}
304 for {set l 0} {$l < [llength $errlines]} {incr l} {
305 set line [lindex $errlines $l]
306 if {!([string length $line] == 40 && [string is xdigit $line])} {
307 if {[string match "fatal:*" $line]} {
308 if {[string match "fatal: ambiguous argument*" $line]
309 && $badrev ne {}} {
310 if {[llength $badrev] == 1} {
311 set err "unknown revision $badrev"
312 } else {
313 set err "unknown revisions: [join $badrev ", "]"
314 }
315 } else {
316 set err [join [lrange $errlines $l end] "\n"]
317 }
318 break
319 }
320 lappend badrev $line
321 }
322 }
323 error_popup "[mc "Error parsing revisions:"] $err"
324 return {}
Paul Mackerrasee66e082008-05-09 10:14:07 +1000325 }
326 set ret {}
327 set pos {}
328 set neg {}
329 set sdm 0
330 foreach id [split $ids "\n"] {
Denton Liue2445882020-09-10 21:36:33 -0700331 if {$id eq "--gitk-symmetric-diff-marker"} {
332 set sdm 4
333 } elseif {[string match "^*" $id]} {
334 if {$sdm != 1} {
335 lappend ret $id
336 if {$sdm == 3} {
337 set sdm 0
338 }
339 }
340 lappend neg [string range $id 1 end]
341 } else {
342 if {$sdm != 2} {
343 lappend ret $id
344 } else {
345 lset ret end $id...[lindex $ret end]
346 }
347 lappend pos $id
348 }
349 incr sdm -1
Paul Mackerrasee66e082008-05-09 10:14:07 +1000350 }
351 set vposids($view) $pos
352 set vnegids($view) $neg
353 return $ret
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000354}
355
Paul Mackerrasf9e0b6f2008-03-04 21:14:17 +1100356# Start off a git log process and arrange to read its output
Paul Mackerrasda7c24d2006-05-02 11:15:29 +1000357proc start_rev_list {view} {
Paul Mackerras6df74032008-05-11 22:13:02 +1000358 global startmsecs commitidx viewcomplete curview
Alexander Gavrilove439e092008-07-13 16:40:47 +0400359 global tclencoding
Paul Mackerrasee66e082008-05-09 10:14:07 +1000360 global viewargs viewargscmd viewfiles vfilelimit
Paul Mackerrasd375ef92008-10-21 10:18:12 +1100361 global showlocalchanges
Alexander Gavrilove439e092008-07-13 16:40:47 +0400362 global viewactive viewinstances vmergeonly
Paul Mackerrascdc84292008-11-18 19:54:14 +1100363 global mainheadid viewmainheadid viewmainheadid_orig
Paul Mackerrasee66e082008-05-09 10:14:07 +1000364 global vcanopt vflags vrevs vorigargs
Kirill Smelkov7defefb2010-05-20 13:50:41 +0400365 global show_notes
Paul Mackerras38ad0912005-12-01 22:42:46 +1100366
367 set startmsecs [clock clicks -milliseconds]
Paul Mackerrasda7c24d2006-05-02 11:15:29 +1000368 set commitidx($view) 0
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000369 # these are set this way for the error exits
370 set viewcomplete($view) 1
371 set viewactive($view) 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100372 varcinit $view
373
Yann Dirson2d480852008-02-21 21:23:31 +0100374 set args $viewargs($view)
375 if {$viewargscmd($view) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700376 if {[catch {
377 set str [exec sh -c $viewargscmd($view)]
378 } err]} {
379 error_popup "[mc "Error executing --argscmd command:"] $err"
380 return 0
381 }
382 set args [concat $args [split $str "\n"]]
Yann Dirson2d480852008-02-21 21:23:31 +0100383 }
Paul Mackerrasee66e082008-05-09 10:14:07 +1000384 set vcanopt($view) [parseviewargs $view $args]
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000385
386 set files $viewfiles($view)
387 if {$vmergeonly($view)} {
Denton Liue2445882020-09-10 21:36:33 -0700388 set files [unmerged_files $files]
389 if {$files eq {}} {
390 global nr_unmerged
391 if {$nr_unmerged == 0} {
392 error_popup [mc "No files selected: --merge specified but\
393 no files are unmerged."]
394 } else {
395 error_popup [mc "No files selected: --merge specified but\
396 no unmerged files are within file limit."]
397 }
398 return 0
399 }
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000400 }
401 set vfilelimit($view) $files
402
Paul Mackerrasee66e082008-05-09 10:14:07 +1000403 if {$vcanopt($view)} {
Denton Liue2445882020-09-10 21:36:33 -0700404 set revs [parseviewrevs $view $vrevs($view)]
405 if {$revs eq {}} {
406 return 0
407 }
408 set args [concat $vflags($view) $revs]
Paul Mackerrasee66e082008-05-09 10:14:07 +1000409 } else {
Denton Liue2445882020-09-10 21:36:33 -0700410 set args $vorigargs($view)
Paul Mackerrasee66e082008-05-09 10:14:07 +1000411 }
412
Paul Mackerras418c4c72006-02-07 09:10:18 +1100413 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -0700414 set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
415 --parents --boundary $args "--" $files] r]
Paul Mackerras418c4c72006-02-07 09:10:18 +1100416 } err]} {
Denton Liue2445882020-09-10 21:36:33 -0700417 error_popup "[mc "Error executing git log:"] $err"
418 return 0
Paul Mackerras38ad0912005-12-01 22:42:46 +1100419 }
Alexander Gavrilove439e092008-07-13 16:40:47 +0400420 set i [reg_instance $fd]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100421 set viewinstances($view) [list $i]
Paul Mackerrascdc84292008-11-18 19:54:14 +1100422 set viewmainheadid($view) $mainheadid
423 set viewmainheadid_orig($view) $mainheadid
424 if {$files ne {} && $mainheadid ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700425 get_viewmainhead $view
Paul Mackerrascdc84292008-11-18 19:54:14 +1100426 }
427 if {$showlocalchanges && $viewmainheadid($view) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700428 interestedin $viewmainheadid($view) dodiffindex
Paul Mackerras3e6b8932007-09-15 09:33:39 +1000429 }
Mark Levedahl86da5b62007-07-17 18:42:04 -0400430 fconfigure $fd -blocking 0 -translation lf -eofchar {}
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +1100431 if {$tclencoding != {}} {
Denton Liue2445882020-09-10 21:36:33 -0700432 fconfigure $fd -encoding $tclencoding
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +1100433 }
Paul Mackerrasf806f0f2008-02-24 12:16:56 +1100434 filerun $fd [list getcommitlines $fd $i $view 0]
Christian Stimmingd990ced2007-11-07 18:42:55 +0100435 nowbusy $view [mc "Reading"]
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000436 set viewcomplete($view) 0
437 set viewactive($view) 1
438 return 1
Paul Mackerras38ad0912005-12-01 22:42:46 +1100439}
440
Alexander Gavrilove2f90ee2008-07-12 16:09:28 +0400441proc stop_instance {inst} {
442 global commfd leftover
443
444 set fd $commfd($inst)
445 catch {
Denton Liue2445882020-09-10 21:36:33 -0700446 set pid [pid $fd]
Alexander Gavrilovb6326e92008-07-15 00:35:42 +0400447
Denton Liue2445882020-09-10 21:36:33 -0700448 if {$::tcl_platform(platform) eq {windows}} {
449 exec taskkill /pid $pid
450 } else {
451 exec kill $pid
452 }
Alexander Gavrilove2f90ee2008-07-12 16:09:28 +0400453 }
454 catch {close $fd}
455 nukefile $fd
456 unset commfd($inst)
457 unset leftover($inst)
458}
459
460proc stop_backends {} {
461 global commfd
462
463 foreach inst [array names commfd] {
Denton Liue2445882020-09-10 21:36:33 -0700464 stop_instance $inst
Alexander Gavrilove2f90ee2008-07-12 16:09:28 +0400465 }
466}
467
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100468proc stop_rev_list {view} {
Alexander Gavrilove2f90ee2008-07-12 16:09:28 +0400469 global viewinstances
Paul Mackerras22626ef2006-04-17 09:56:02 +1000470
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100471 foreach inst $viewinstances($view) {
Denton Liue2445882020-09-10 21:36:33 -0700472 stop_instance $inst
Paul Mackerras22626ef2006-04-17 09:56:02 +1000473 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100474 set viewinstances($view) {}
Paul Mackerras22626ef2006-04-17 09:56:02 +1000475}
476
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400477proc reset_pending_select {selid} {
Alexander Gavrilov39816d62008-08-23 12:27:44 +0400478 global pending_select mainheadid selectheadid
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400479
480 if {$selid ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700481 set pending_select $selid
Alexander Gavrilov39816d62008-08-23 12:27:44 +0400482 } elseif {$selectheadid ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700483 set pending_select $selectheadid
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400484 } else {
Denton Liue2445882020-09-10 21:36:33 -0700485 set pending_select $mainheadid
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400486 }
487}
488
489proc getcommits {selid} {
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000490 global canv curview need_redisplay viewactive
Sven Verdoolaegeb5c2f302005-11-29 22:15:51 +0100491
Paul Mackerrasda7c24d2006-05-02 11:15:29 +1000492 initlayout
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000493 if {[start_rev_list $curview]} {
Denton Liue2445882020-09-10 21:36:33 -0700494 reset_pending_select $selid
495 show_status [mc "Reading commits..."]
496 set need_redisplay 1
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000497 } else {
Denton Liue2445882020-09-10 21:36:33 -0700498 show_status [mc "No commits selected"]
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000499 }
Paul Mackerras1d10f362005-05-15 12:55:47 +0000500}
501
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100502proc updatecommits {} {
Paul Mackerrasee66e082008-05-09 10:14:07 +1000503 global curview vcanopt vorigargs vfilelimit viewinstances
Alexander Gavrilove439e092008-07-13 16:40:47 +0400504 global viewactive viewcomplete tclencoding
505 global startmsecs showneartags showlocalchanges
Paul Mackerrascdc84292008-11-18 19:54:14 +1100506 global mainheadid viewmainheadid viewmainheadid_orig pending_select
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -0400507 global hasworktree
Paul Mackerrasee66e082008-05-09 10:14:07 +1000508 global varcid vposids vnegids vflags vrevs
Kirill Smelkov7defefb2010-05-20 13:50:41 +0400509 global show_notes
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100510
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -0400511 set hasworktree [hasworktree]
Paul Mackerrasfc2a2562007-12-26 23:03:43 +1100512 rereadrefs
Paul Mackerrascdc84292008-11-18 19:54:14 +1100513 set view $curview
514 if {$mainheadid ne $viewmainheadid_orig($view)} {
Denton Liue2445882020-09-10 21:36:33 -0700515 if {$showlocalchanges} {
516 dohidelocalchanges
517 }
518 set viewmainheadid($view) $mainheadid
519 set viewmainheadid_orig($view) $mainheadid
520 if {$vfilelimit($view) ne {}} {
521 get_viewmainhead $view
522 }
Paul Mackerraseb5f8c92007-12-29 21:13:34 +1100523 }
Paul Mackerrascdc84292008-11-18 19:54:14 +1100524 if {$showlocalchanges} {
Denton Liue2445882020-09-10 21:36:33 -0700525 doshowlocalchanges
Paul Mackerrascdc84292008-11-18 19:54:14 +1100526 }
Paul Mackerrasee66e082008-05-09 10:14:07 +1000527 if {$vcanopt($view)} {
Denton Liue2445882020-09-10 21:36:33 -0700528 set oldpos $vposids($view)
529 set oldneg $vnegids($view)
530 set revs [parseviewrevs $view $vrevs($view)]
531 if {$revs eq {}} {
532 return
533 }
534 # note: getting the delta when negative refs change is hard,
535 # and could require multiple git log invocations, so in that
536 # case we ask git log for all the commits (not just the delta)
537 if {$oldneg eq $vnegids($view)} {
538 set newrevs {}
539 set npos 0
540 # take out positive refs that we asked for before or
541 # that we have already seen
542 foreach rev $revs {
543 if {[string length $rev] == 40} {
544 if {[lsearch -exact $oldpos $rev] < 0
545 && ![info exists varcid($view,$rev)]} {
546 lappend newrevs $rev
547 incr npos
548 }
549 } else {
550 lappend $newrevs $rev
551 }
552 }
553 if {$npos == 0} return
554 set revs $newrevs
555 set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
556 }
557 set args [concat $vflags($view) $revs --not $oldpos]
Paul Mackerrasee66e082008-05-09 10:14:07 +1000558 } else {
Denton Liue2445882020-09-10 21:36:33 -0700559 set args $vorigargs($view)
Paul Mackerrasee66e082008-05-09 10:14:07 +1000560 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100561 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -0700562 set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
563 --parents --boundary $args "--" $vfilelimit($view)] r]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100564 } err]} {
Denton Liue2445882020-09-10 21:36:33 -0700565 error_popup "[mc "Error executing git log:"] $err"
566 return
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100567 }
568 if {$viewactive($view) == 0} {
Denton Liue2445882020-09-10 21:36:33 -0700569 set startmsecs [clock clicks -milliseconds]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100570 }
Alexander Gavrilove439e092008-07-13 16:40:47 +0400571 set i [reg_instance $fd]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100572 lappend viewinstances($view) $i
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100573 fconfigure $fd -blocking 0 -translation lf -eofchar {}
574 if {$tclencoding != {}} {
Denton Liue2445882020-09-10 21:36:33 -0700575 fconfigure $fd -encoding $tclencoding
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100576 }
Paul Mackerrasf806f0f2008-02-24 12:16:56 +1100577 filerun $fd [list getcommitlines $fd $i $view 1]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100578 incr viewactive($view)
579 set viewcomplete($view) 0
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400580 reset_pending_select {}
Michele Ballabiob56e0a92009-03-30 21:17:25 +0200581 nowbusy $view [mc "Reading"]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100582 if {$showneartags} {
Denton Liue2445882020-09-10 21:36:33 -0700583 getallcommits
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100584 }
585}
586
587proc reloadcommits {} {
588 global curview viewcomplete selectedline currentid thickerline
589 global showneartags treediffs commitinterest cached_commitrow
Markus Hitter18ae9122016-11-07 19:02:51 +0100590 global targetid commitinfo
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100591
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400592 set selid {}
593 if {$selectedline ne {}} {
Denton Liue2445882020-09-10 21:36:33 -0700594 set selid $currentid
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400595 }
596
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100597 if {!$viewcomplete($curview)} {
Denton Liue2445882020-09-10 21:36:33 -0700598 stop_rev_list $curview
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100599 }
600 resetvarcs $curview
Paul Mackerras94b4a692008-05-20 20:51:06 +1000601 set selectedline {}
Paul Mackerras009409f2015-05-02 20:53:36 +1000602 unset -nocomplain currentid
603 unset -nocomplain thickerline
604 unset -nocomplain treediffs
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100605 readrefs
606 changedrefs
607 if {$showneartags} {
Denton Liue2445882020-09-10 21:36:33 -0700608 getallcommits
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100609 }
610 clear_display
Markus Hitter18ae9122016-11-07 19:02:51 +0100611 unset -nocomplain commitinfo
Paul Mackerras009409f2015-05-02 20:53:36 +1000612 unset -nocomplain commitinterest
613 unset -nocomplain cached_commitrow
614 unset -nocomplain targetid
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100615 setcanvscroll
Alexander Gavrilov567c34e2008-07-26 20:13:45 +0400616 getcommits $selid
Paul Mackerrase7297a12008-01-15 22:30:40 +1100617 return 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100618}
619
Paul Mackerras6e8c8702007-07-31 21:03:06 +1000620# This makes a string representation of a positive integer which
621# sorts as a string in numerical order
622proc strrep {n} {
623 if {$n < 16} {
Denton Liue2445882020-09-10 21:36:33 -0700624 return [format "%x" $n]
Paul Mackerras6e8c8702007-07-31 21:03:06 +1000625 } elseif {$n < 256} {
Denton Liue2445882020-09-10 21:36:33 -0700626 return [format "x%.2x" $n]
Paul Mackerras6e8c8702007-07-31 21:03:06 +1000627 } elseif {$n < 65536} {
Denton Liue2445882020-09-10 21:36:33 -0700628 return [format "y%.4x" $n]
Paul Mackerras6e8c8702007-07-31 21:03:06 +1000629 }
630 return [format "z%.8x" $n]
631}
632
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100633# Procedures used in reordering commits from git log (without
634# --topo-order) into the order for display.
635
636proc varcinit {view} {
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100637 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
638 global vtokmod varcmod vrowmod varcix vlastins
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100639
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100640 set varcstart($view) {{}}
641 set vupptr($view) {0}
642 set vdownptr($view) {0}
643 set vleftptr($view) {0}
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100644 set vbackptr($view) {0}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100645 set varctok($view) {{}}
646 set varcrow($view) {{}}
647 set vtokmod($view) {}
648 set varcmod($view) 0
Paul Mackerrase5b37ac2007-12-12 18:13:51 +1100649 set vrowmod($view) 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100650 set varcix($view) {{}}
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100651 set vlastins($view) {0}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100652}
653
654proc resetvarcs {view} {
655 global varcid varccommits parents children vseedcount ordertok
Paul Mackerras22387f22012-03-19 11:21:08 +1100656 global vshortids
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100657
658 foreach vid [array names varcid $view,*] {
Denton Liue2445882020-09-10 21:36:33 -0700659 unset varcid($vid)
660 unset children($vid)
661 unset parents($vid)
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100662 }
Paul Mackerras22387f22012-03-19 11:21:08 +1100663 foreach vid [array names vshortids $view,*] {
Denton Liue2445882020-09-10 21:36:33 -0700664 unset vshortids($vid)
Paul Mackerras22387f22012-03-19 11:21:08 +1100665 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100666 # some commits might have children but haven't been seen yet
667 foreach vid [array names children $view,*] {
Denton Liue2445882020-09-10 21:36:33 -0700668 unset children($vid)
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100669 }
670 foreach va [array names varccommits $view,*] {
Denton Liue2445882020-09-10 21:36:33 -0700671 unset varccommits($va)
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100672 }
673 foreach vd [array names vseedcount $view,*] {
Denton Liue2445882020-09-10 21:36:33 -0700674 unset vseedcount($vd)
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100675 }
Paul Mackerras009409f2015-05-02 20:53:36 +1000676 unset -nocomplain ordertok
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100677}
678
Paul Mackerras468bcae2008-03-03 10:19:35 +1100679# returns a list of the commits with no children
680proc seeds {v} {
681 global vdownptr vleftptr varcstart
682
683 set ret {}
684 set a [lindex $vdownptr($v) 0]
685 while {$a != 0} {
Denton Liue2445882020-09-10 21:36:33 -0700686 lappend ret [lindex $varcstart($v) $a]
687 set a [lindex $vleftptr($v) $a]
Paul Mackerras468bcae2008-03-03 10:19:35 +1100688 }
689 return $ret
690}
691
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100692proc newvarc {view id} {
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000693 global varcid varctok parents children vdatemode
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100694 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
695 global commitdata commitinfo vseedcount varccommits vlastins
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100696
697 set a [llength $varctok($view)]
698 set vid $view,$id
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000699 if {[llength $children($vid)] == 0 || $vdatemode($view)} {
Denton Liue2445882020-09-10 21:36:33 -0700700 if {![info exists commitinfo($id)]} {
701 parsecommit $id $commitdata($id) 1
702 }
703 set cdate [lindex [lindex $commitinfo($id) 4] 0]
704 if {![string is integer -strict $cdate]} {
705 set cdate 0
706 }
707 if {![info exists vseedcount($view,$cdate)]} {
708 set vseedcount($view,$cdate) -1
709 }
710 set c [incr vseedcount($view,$cdate)]
711 set cdate [expr {$cdate ^ 0xffffffff}]
712 set tok "s[strrep $cdate][strrep $c]"
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100713 } else {
Denton Liue2445882020-09-10 21:36:33 -0700714 set tok {}
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100715 }
716 set ka 0
717 if {[llength $children($vid)] > 0} {
Denton Liue2445882020-09-10 21:36:33 -0700718 set kid [lindex $children($vid) end]
719 set k $varcid($view,$kid)
720 if {[string compare [lindex $varctok($view) $k] $tok] > 0} {
721 set ki $kid
722 set ka $k
723 set tok [lindex $varctok($view) $k]
724 }
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100725 }
726 if {$ka != 0} {
Denton Liue2445882020-09-10 21:36:33 -0700727 set i [lsearch -exact $parents($view,$ki) $id]
728 set j [expr {[llength $parents($view,$ki)] - 1 - $i}]
729 append tok [strrep $j]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100730 }
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100731 set c [lindex $vlastins($view) $ka]
732 if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} {
Denton Liue2445882020-09-10 21:36:33 -0700733 set c $ka
734 set b [lindex $vdownptr($view) $ka]
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100735 } else {
Denton Liue2445882020-09-10 21:36:33 -0700736 set b [lindex $vleftptr($view) $c]
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100737 }
738 while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -0700739 set c $b
740 set b [lindex $vleftptr($view) $c]
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100741 }
742 if {$c == $ka} {
Denton Liue2445882020-09-10 21:36:33 -0700743 lset vdownptr($view) $ka $a
744 lappend vbackptr($view) 0
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100745 } else {
Denton Liue2445882020-09-10 21:36:33 -0700746 lset vleftptr($view) $c $a
747 lappend vbackptr($view) $c
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100748 }
749 lset vlastins($view) $ka $a
750 lappend vupptr($view) $ka
751 lappend vleftptr($view) $b
752 if {$b != 0} {
Denton Liue2445882020-09-10 21:36:33 -0700753 lset vbackptr($view) $b $a
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100754 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100755 lappend varctok($view) $tok
756 lappend varcstart($view) $id
757 lappend vdownptr($view) 0
758 lappend varcrow($view) {}
759 lappend varcix($view) {}
Paul Mackerrase5b37ac2007-12-12 18:13:51 +1100760 set varccommits($view,$a) {}
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100761 lappend vlastins($view) 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100762 return $a
763}
764
765proc splitvarc {p v} {
Paul Mackerras52b8ea92009-03-02 09:38:17 +1100766 global varcid varcstart varccommits varctok vtokmod
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100767 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100768
769 set oa $varcid($v,$p)
Paul Mackerras52b8ea92009-03-02 09:38:17 +1100770 set otok [lindex $varctok($v) $oa]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100771 set ac $varccommits($v,$oa)
772 set i [lsearch -exact $varccommits($v,$oa) $p]
773 if {$i <= 0} return
774 set na [llength $varctok($v)]
775 # "%" sorts before "0"...
Paul Mackerras52b8ea92009-03-02 09:38:17 +1100776 set tok "$otok%[strrep $i]"
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100777 lappend varctok($v) $tok
778 lappend varcrow($v) {}
779 lappend varcix($v) {}
780 set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]]
781 set varccommits($v,$na) [lrange $ac $i end]
782 lappend varcstart($v) $p
783 foreach id $varccommits($v,$na) {
Denton Liue2445882020-09-10 21:36:33 -0700784 set varcid($v,$id) $na
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100785 }
786 lappend vdownptr($v) [lindex $vdownptr($v) $oa]
Paul Mackerras841ea822008-02-18 10:44:33 +1100787 lappend vlastins($v) [lindex $vlastins($v) $oa]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100788 lset vdownptr($v) $oa $na
Paul Mackerras841ea822008-02-18 10:44:33 +1100789 lset vlastins($v) $oa 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100790 lappend vupptr($v) $oa
791 lappend vleftptr($v) 0
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100792 lappend vbackptr($v) 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100793 for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} {
Denton Liue2445882020-09-10 21:36:33 -0700794 lset vupptr($v) $b $na
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100795 }
Paul Mackerras52b8ea92009-03-02 09:38:17 +1100796 if {[string compare $otok $vtokmod($v)] <= 0} {
Denton Liue2445882020-09-10 21:36:33 -0700797 modify_arc $v $oa
Paul Mackerras52b8ea92009-03-02 09:38:17 +1100798 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100799}
800
801proc renumbervarc {a v} {
802 global parents children varctok varcstart varccommits
Paul Mackerras3ed31a82008-04-26 16:00:00 +1000803 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100804
805 set t1 [clock clicks -milliseconds]
806 set todo {}
807 set isrelated($a) 1
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100808 set kidchanged($a) 1
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100809 set ntot 0
810 while {$a != 0} {
Denton Liue2445882020-09-10 21:36:33 -0700811 if {[info exists isrelated($a)]} {
812 lappend todo $a
813 set id [lindex $varccommits($v,$a) end]
814 foreach p $parents($v,$id) {
815 if {[info exists varcid($v,$p)]} {
816 set isrelated($varcid($v,$p)) 1
817 }
818 }
819 }
820 incr ntot
821 set b [lindex $vdownptr($v) $a]
822 if {$b == 0} {
823 while {$a != 0} {
824 set b [lindex $vleftptr($v) $a]
825 if {$b != 0} break
826 set a [lindex $vupptr($v) $a]
827 }
828 }
829 set a $b
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100830 }
831 foreach a $todo {
Denton Liue2445882020-09-10 21:36:33 -0700832 if {![info exists kidchanged($a)]} continue
833 set id [lindex $varcstart($v) $a]
834 if {[llength $children($v,$id)] > 1} {
835 set children($v,$id) [lsort -command [list vtokcmp $v] \
836 $children($v,$id)]
837 }
838 set oldtok [lindex $varctok($v) $a]
839 if {!$vdatemode($v)} {
840 set tok {}
841 } else {
842 set tok $oldtok
843 }
844 set ka 0
845 set kid [last_real_child $v,$id]
846 if {$kid ne {}} {
847 set k $varcid($v,$kid)
848 if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
849 set ki $kid
850 set ka $k
851 set tok [lindex $varctok($v) $k]
852 }
853 }
854 if {$ka != 0} {
855 set i [lsearch -exact $parents($v,$ki) $id]
856 set j [expr {[llength $parents($v,$ki)] - 1 - $i}]
857 append tok [strrep $j]
858 }
859 if {$tok eq $oldtok} {
860 continue
861 }
862 set id [lindex $varccommits($v,$a) end]
863 foreach p $parents($v,$id) {
864 if {[info exists varcid($v,$p)]} {
865 set kidchanged($varcid($v,$p)) 1
866 } else {
867 set sortkids($p) 1
868 }
869 }
870 lset varctok($v) $a $tok
871 set b [lindex $vupptr($v) $a]
872 if {$b != $ka} {
873 if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} {
874 modify_arc $v $ka
875 }
876 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
877 modify_arc $v $b
878 }
879 set c [lindex $vbackptr($v) $a]
880 set d [lindex $vleftptr($v) $a]
881 if {$c == 0} {
882 lset vdownptr($v) $b $d
883 } else {
884 lset vleftptr($v) $c $d
885 }
886 if {$d != 0} {
887 lset vbackptr($v) $d $c
888 }
889 if {[lindex $vlastins($v) $b] == $a} {
890 lset vlastins($v) $b $c
891 }
892 lset vupptr($v) $a $ka
893 set c [lindex $vlastins($v) $ka]
894 if {$c == 0 || \
895 [string compare $tok [lindex $varctok($v) $c]] < 0} {
896 set c $ka
897 set b [lindex $vdownptr($v) $ka]
898 } else {
899 set b [lindex $vleftptr($v) $c]
900 }
901 while {$b != 0 && \
902 [string compare $tok [lindex $varctok($v) $b]] >= 0} {
903 set c $b
904 set b [lindex $vleftptr($v) $c]
905 }
906 if {$c == $ka} {
907 lset vdownptr($v) $ka $a
908 lset vbackptr($v) $a 0
909 } else {
910 lset vleftptr($v) $c $a
911 lset vbackptr($v) $a $c
912 }
913 lset vleftptr($v) $a $b
914 if {$b != 0} {
915 lset vbackptr($v) $b $a
916 }
917 lset vlastins($v) $ka $a
918 }
Paul Mackerrasf3ea5ed2007-12-20 10:03:35 +1100919 }
920 foreach id [array names sortkids] {
Denton Liue2445882020-09-10 21:36:33 -0700921 if {[llength $children($v,$id)] > 1} {
922 set children($v,$id) [lsort -command [list vtokcmp $v] \
923 $children($v,$id)]
924 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100925 }
926 set t2 [clock clicks -milliseconds]
927 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms"
928}
929
Paul Mackerrasf806f0f2008-02-24 12:16:56 +1100930# Fix up the graph after we have found out that in view $v,
931# $p (a commit that we have already seen) is actually the parent
932# of the last commit in arc $a.
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100933proc fix_reversal {p a v} {
Paul Mackerras24f7a662007-12-19 09:35:33 +1100934 global varcid varcstart varctok vupptr
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100935
936 set pa $varcid($v,$p)
937 if {$p ne [lindex $varcstart($v) $pa]} {
Denton Liue2445882020-09-10 21:36:33 -0700938 splitvarc $p $v
939 set pa $varcid($v,$p)
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100940 }
Paul Mackerras24f7a662007-12-19 09:35:33 +1100941 # seeds always need to be renumbered
942 if {[lindex $vupptr($v) $pa] == 0 ||
Denton Liue2445882020-09-10 21:36:33 -0700943 [string compare [lindex $varctok($v) $a] \
944 [lindex $varctok($v) $pa]] > 0} {
945 renumbervarc $pa $v
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100946 }
947}
948
949proc insertrow {id p v} {
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100950 global cmitlisted children parents varcid varctok vtokmod
951 global varccommits ordertok commitidx numcommits curview
Paul Mackerras22387f22012-03-19 11:21:08 +1100952 global targetid targetrow vshortids
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100953
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100954 readcommit $id
955 set vid $v,$id
956 set cmitlisted($vid) 1
957 set children($vid) {}
958 set parents($vid) [list $p]
959 set a [newvarc $v $id]
960 set varcid($vid) $a
Paul Mackerras22387f22012-03-19 11:21:08 +1100961 lappend vshortids($v,[string range $id 0 3]) $id
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100962 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} {
Denton Liue2445882020-09-10 21:36:33 -0700963 modify_arc $v $a
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100964 }
965 lappend varccommits($v,$a) $id
966 set vp $v,$p
967 if {[llength [lappend children($vp) $id]] > 1} {
Denton Liue2445882020-09-10 21:36:33 -0700968 set children($vp) [lsort -command [list vtokcmp $v] $children($vp)]
969 unset -nocomplain ordertok
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100970 }
971 fix_reversal $p $a $v
972 incr commitidx($v)
973 if {$v == $curview} {
Denton Liue2445882020-09-10 21:36:33 -0700974 set numcommits $commitidx($v)
975 setcanvscroll
976 if {[info exists targetid]} {
977 if {![comes_before $targetid $p]} {
978 incr targetrow
979 }
980 }
Paul Mackerrasb8a938c2008-02-13 22:12:31 +1100981 }
982}
983
984proc insertfakerow {id p} {
985 global varcid varccommits parents children cmitlisted
986 global commitidx varctok vtokmod targetid targetrow curview numcommits
987
988 set v $curview
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100989 set a $varcid($v,$p)
990 set i [lsearch -exact $varccommits($v,$a) $p]
991 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -0700992 puts "oops: insertfakerow can't find [shortids $p] on arc $a"
993 return
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100994 }
995 set children($v,$id) {}
996 set parents($v,$id) [list $p]
997 set varcid($v,$id) $a
Paul Mackerras9257d8f2007-12-11 10:45:38 +1100998 lappend children($v,$p) $id
Paul Mackerras7fcc92b2007-12-03 10:33:01 +1100999 set cmitlisted($v,$id) 1
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001000 set numcommits [incr commitidx($v)]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001001 # note we deliberately don't update varcstart($v) even if $i == 0
1002 set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id]
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001003 modify_arc $v $a $i
Paul Mackerras42a671f2008-01-02 09:59:39 +11001004 if {[info exists targetid]} {
Denton Liue2445882020-09-10 21:36:33 -07001005 if {![comes_before $targetid $p]} {
1006 incr targetrow
1007 }
Paul Mackerras42a671f2008-01-02 09:59:39 +11001008 }
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001009 setcanvscroll
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001010 drawvisible
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001011}
1012
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001013proc removefakerow {id} {
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001014 global varcid varccommits parents children commitidx
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11001015 global varctok vtokmod cmitlisted currentid selectedline
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001016 global targetid curview numcommits
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001017
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001018 set v $curview
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001019 if {[llength $parents($v,$id)] != 1} {
Denton Liue2445882020-09-10 21:36:33 -07001020 puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents"
1021 return
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001022 }
1023 set p [lindex $parents($v,$id) 0]
1024 set a $varcid($v,$id)
1025 set i [lsearch -exact $varccommits($v,$a) $id]
1026 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -07001027 puts "oops: removefakerow can't find [shortids $id] on arc $a"
1028 return
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001029 }
1030 unset varcid($v,$id)
1031 set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i]
1032 unset parents($v,$id)
1033 unset children($v,$id)
1034 unset cmitlisted($v,$id)
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001035 set numcommits [incr commitidx($v) -1]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001036 set j [lsearch -exact $children($v,$p) $id]
1037 if {$j >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001038 set children($v,$p) [lreplace $children($v,$p) $j $j]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001039 }
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001040 modify_arc $v $a $i
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11001041 if {[info exist currentid] && $id eq $currentid} {
Denton Liue2445882020-09-10 21:36:33 -07001042 unset currentid
1043 set selectedline {}
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11001044 }
Paul Mackerras42a671f2008-01-02 09:59:39 +11001045 if {[info exists targetid] && $targetid eq $id} {
Denton Liue2445882020-09-10 21:36:33 -07001046 set targetid $p
Paul Mackerras42a671f2008-01-02 09:59:39 +11001047 }
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11001048 setcanvscroll
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001049 drawvisible
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001050}
1051
Paul Mackerrasaa435612009-09-10 21:58:40 +10001052proc real_children {vp} {
1053 global children nullid nullid2
1054
1055 set kids {}
1056 foreach id $children($vp) {
Denton Liue2445882020-09-10 21:36:33 -07001057 if {$id ne $nullid && $id ne $nullid2} {
1058 lappend kids $id
1059 }
Paul Mackerrasaa435612009-09-10 21:58:40 +10001060 }
1061 return $kids
1062}
1063
Paul Mackerrasc8c9f3d2008-01-06 13:54:58 +11001064proc first_real_child {vp} {
1065 global children nullid nullid2
1066
1067 foreach id $children($vp) {
Denton Liue2445882020-09-10 21:36:33 -07001068 if {$id ne $nullid && $id ne $nullid2} {
1069 return $id
1070 }
Paul Mackerrasc8c9f3d2008-01-06 13:54:58 +11001071 }
1072 return {}
1073}
1074
1075proc last_real_child {vp} {
1076 global children nullid nullid2
1077
1078 set kids $children($vp)
1079 for {set i [llength $kids]} {[incr i -1] >= 0} {} {
Denton Liue2445882020-09-10 21:36:33 -07001080 set id [lindex $kids $i]
1081 if {$id ne $nullid && $id ne $nullid2} {
1082 return $id
1083 }
Paul Mackerrasc8c9f3d2008-01-06 13:54:58 +11001084 }
1085 return {}
1086}
1087
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001088proc vtokcmp {v a b} {
1089 global varctok varcid
1090
1091 return [string compare [lindex $varctok($v) $varcid($v,$a)] \
Denton Liue2445882020-09-10 21:36:33 -07001092 [lindex $varctok($v) $varcid($v,$b)]]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001093}
1094
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001095# This assumes that if lim is not given, the caller has checked that
1096# arc a's token is less than $vtokmod($v)
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001097proc modify_arc {v a {lim {}}} {
1098 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001099
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001100 if {$lim ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07001101 set c [string compare [lindex $varctok($v) $a] $vtokmod($v)]
1102 if {$c > 0} return
1103 if {$c == 0} {
1104 set r [lindex $varcrow($v) $a]
1105 if {$r ne {} && $vrowmod($v) <= $r + $lim} return
1106 }
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001107 }
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001108 set vtokmod($v) [lindex $varctok($v) $a]
1109 set varcmod($v) $a
1110 if {$v == $curview} {
Denton Liue2445882020-09-10 21:36:33 -07001111 while {$a != 0 && [lindex $varcrow($v) $a] eq {}} {
1112 set a [lindex $vupptr($v) $a]
1113 set lim {}
1114 }
1115 set r 0
1116 if {$a != 0} {
1117 if {$lim eq {}} {
1118 set lim [llength $varccommits($v,$a)]
1119 }
1120 set r [expr {[lindex $varcrow($v) $a] + $lim}]
1121 }
1122 set vrowmod($v) $r
1123 undolayout $r
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001124 }
1125}
1126
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001127proc update_arcrows {v} {
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001128 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline
Paul Mackerras24f7a662007-12-19 09:35:33 +11001129 global varcid vrownum varcorder varcix varccommits
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001130 global vupptr vdownptr vleftptr varctok
Paul Mackerras24f7a662007-12-19 09:35:33 +11001131 global displayorder parentlist curview cached_commitrow
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001132
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001133 if {$vrowmod($v) == $commitidx($v)} return
1134 if {$v == $curview} {
Denton Liue2445882020-09-10 21:36:33 -07001135 if {[llength $displayorder] > $vrowmod($v)} {
1136 set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]]
1137 set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]]
1138 }
1139 unset -nocomplain cached_commitrow
Paul Mackerrasc9cfdc92008-03-04 21:32:38 +11001140 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001141 set narctot [expr {[llength $varctok($v)] - 1}]
1142 set a $varcmod($v)
1143 while {$a != 0 && [lindex $varcix($v) $a] eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07001144 # go up the tree until we find something that has a row number,
1145 # or we get to a seed
1146 set a [lindex $vupptr($v) $a]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001147 }
1148 if {$a == 0} {
Denton Liue2445882020-09-10 21:36:33 -07001149 set a [lindex $vdownptr($v) 0]
1150 if {$a == 0} return
1151 set vrownum($v) {0}
1152 set varcorder($v) [list $a]
1153 lset varcix($v) $a 0
1154 lset varcrow($v) $a 0
1155 set arcn 0
1156 set row 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001157 } else {
Denton Liue2445882020-09-10 21:36:33 -07001158 set arcn [lindex $varcix($v) $a]
1159 if {[llength $vrownum($v)] > $arcn + 1} {
1160 set vrownum($v) [lrange $vrownum($v) 0 $arcn]
1161 set varcorder($v) [lrange $varcorder($v) 0 $arcn]
1162 }
1163 set row [lindex $varcrow($v) $a]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001164 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001165 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07001166 set p $a
1167 incr row [llength $varccommits($v,$a)]
1168 # go down if possible
1169 set b [lindex $vdownptr($v) $a]
1170 if {$b == 0} {
1171 # if not, go left, or go up until we can go left
1172 while {$a != 0} {
1173 set b [lindex $vleftptr($v) $a]
1174 if {$b != 0} break
1175 set a [lindex $vupptr($v) $a]
1176 }
1177 if {$a == 0} break
1178 }
1179 set a $b
1180 incr arcn
1181 lappend vrownum($v) $row
1182 lappend varcorder($v) $a
1183 lset varcix($v) $a $arcn
1184 lset varcrow($v) $a $row
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001185 }
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001186 set vtokmod($v) [lindex $varctok($v) $p]
1187 set varcmod($v) $p
1188 set vrowmod($v) $row
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001189 if {[info exists currentid]} {
Denton Liue2445882020-09-10 21:36:33 -07001190 set selectedline [rowofcommit $currentid]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001191 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001192}
1193
1194# Test whether view $v contains commit $id
1195proc commitinview {id v} {
1196 global varcid
1197
1198 return [info exists varcid($v,$id)]
1199}
1200
1201# Return the row number for commit $id in the current view
1202proc rowofcommit {id} {
1203 global varcid varccommits varcrow curview cached_commitrow
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001204 global varctok vtokmod
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001205
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001206 set v $curview
1207 if {![info exists varcid($v,$id)]} {
Denton Liue2445882020-09-10 21:36:33 -07001208 puts "oops rowofcommit no arc for [shortids $id]"
1209 return {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001210 }
1211 set a $varcid($v,$id)
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11001212 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001213 update_arcrows $v
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001214 }
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11001215 if {[info exists cached_commitrow($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07001216 return $cached_commitrow($id)
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11001217 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001218 set i [lsearch -exact $varccommits($v,$a) $id]
1219 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -07001220 puts "oops didn't find commit [shortids $id] in arc $a"
1221 return {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001222 }
1223 incr i [lindex $varcrow($v) $a]
1224 set cached_commitrow($id) $i
1225 return $i
1226}
1227
Paul Mackerras42a671f2008-01-02 09:59:39 +11001228# Returns 1 if a is on an earlier row than b, otherwise 0
1229proc comes_before {a b} {
1230 global varcid varctok curview
1231
1232 set v $curview
1233 if {$a eq $b || ![info exists varcid($v,$a)] || \
Denton Liue2445882020-09-10 21:36:33 -07001234 ![info exists varcid($v,$b)]} {
1235 return 0
Paul Mackerras42a671f2008-01-02 09:59:39 +11001236 }
1237 if {$varcid($v,$a) != $varcid($v,$b)} {
Denton Liue2445882020-09-10 21:36:33 -07001238 return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \
1239 [lindex $varctok($v) $varcid($v,$b)]] < 0}]
Paul Mackerras42a671f2008-01-02 09:59:39 +11001240 }
1241 return [expr {[rowofcommit $a] < [rowofcommit $b]}]
1242}
1243
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001244proc bsearch {l elt} {
1245 if {[llength $l] == 0 || $elt <= [lindex $l 0]} {
Denton Liue2445882020-09-10 21:36:33 -07001246 return 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001247 }
1248 set lo 0
1249 set hi [llength $l]
1250 while {$hi - $lo > 1} {
Denton Liue2445882020-09-10 21:36:33 -07001251 set mid [expr {int(($lo + $hi) / 2)}]
1252 set t [lindex $l $mid]
1253 if {$elt < $t} {
1254 set hi $mid
1255 } elseif {$elt > $t} {
1256 set lo $mid
1257 } else {
1258 return $mid
1259 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001260 }
1261 return $lo
1262}
1263
1264# Make sure rows $start..$end-1 are valid in displayorder and parentlist
1265proc make_disporder {start end} {
1266 global vrownum curview commitidx displayorder parentlist
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001267 global varccommits varcorder parents vrowmod varcrow
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001268 global d_valid_start d_valid_end
1269
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001270 if {$end > $vrowmod($curview)} {
Denton Liue2445882020-09-10 21:36:33 -07001271 update_arcrows $curview
Paul Mackerras9257d8f2007-12-11 10:45:38 +11001272 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001273 set ai [bsearch $vrownum($curview) $start]
1274 set start [lindex $vrownum($curview) $ai]
1275 set narc [llength $vrownum($curview)]
1276 for {set r $start} {$ai < $narc && $r < $end} {incr ai} {
Denton Liue2445882020-09-10 21:36:33 -07001277 set a [lindex $varcorder($curview) $ai]
1278 set l [llength $displayorder]
1279 set al [llength $varccommits($curview,$a)]
1280 if {$l < $r + $al} {
1281 if {$l < $r} {
1282 set pad [ntimes [expr {$r - $l}] {}]
1283 set displayorder [concat $displayorder $pad]
1284 set parentlist [concat $parentlist $pad]
1285 } elseif {$l > $r} {
1286 set displayorder [lrange $displayorder 0 [expr {$r - 1}]]
1287 set parentlist [lrange $parentlist 0 [expr {$r - 1}]]
1288 }
1289 foreach id $varccommits($curview,$a) {
1290 lappend displayorder $id
1291 lappend parentlist $parents($curview,$id)
1292 }
1293 } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} {
1294 set i $r
1295 foreach id $varccommits($curview,$a) {
1296 lset displayorder $i $id
1297 lset parentlist $i $parents($curview,$id)
1298 incr i
1299 }
1300 }
1301 incr r $al
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001302 }
1303}
1304
1305proc commitonrow {row} {
1306 global displayorder
1307
1308 set id [lindex $displayorder $row]
1309 if {$id eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07001310 make_disporder $row [expr {$row + 1}]
1311 set id [lindex $displayorder $row]
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001312 }
1313 return $id
1314}
1315
1316proc closevarcs {v} {
1317 global varctok varccommits varcid parents children
Stefan Dotterweichd92aa572016-06-04 10:47:16 +02001318 global cmitlisted commitidx vtokmod curview numcommits
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001319
1320 set missing_parents 0
1321 set scripts {}
1322 set narcs [llength $varctok($v)]
1323 for {set a 1} {$a < $narcs} {incr a} {
Denton Liue2445882020-09-10 21:36:33 -07001324 set id [lindex $varccommits($v,$a) end]
1325 foreach p $parents($v,$id) {
1326 if {[info exists varcid($v,$p)]} continue
1327 # add p as a new commit
1328 incr missing_parents
1329 set cmitlisted($v,$p) 0
1330 set parents($v,$p) {}
1331 if {[llength $children($v,$p)] == 1 &&
1332 [llength $parents($v,$id)] == 1} {
1333 set b $a
1334 } else {
1335 set b [newvarc $v $p]
1336 }
1337 set varcid($v,$p) $b
1338 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
1339 modify_arc $v $b
1340 }
1341 lappend varccommits($v,$b) $p
1342 incr commitidx($v)
1343 if {$v == $curview} {
1344 set numcommits $commitidx($v)
1345 }
1346 set scripts [check_interest $p $scripts]
1347 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001348 }
1349 if {$missing_parents > 0} {
Denton Liue2445882020-09-10 21:36:33 -07001350 foreach s $scripts {
1351 eval $s
1352 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001353 }
1354}
1355
Paul Mackerrasf806f0f2008-02-24 12:16:56 +11001356# Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid
1357# Assumes we already have an arc for $rwid.
1358proc rewrite_commit {v id rwid} {
1359 global children parents varcid varctok vtokmod varccommits
1360
1361 foreach ch $children($v,$id) {
Denton Liue2445882020-09-10 21:36:33 -07001362 # make $rwid be $ch's parent in place of $id
1363 set i [lsearch -exact $parents($v,$ch) $id]
1364 if {$i < 0} {
1365 puts "oops rewrite_commit didn't find $id in parent list for $ch"
1366 }
1367 set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid]
1368 # add $ch to $rwid's children and sort the list if necessary
1369 if {[llength [lappend children($v,$rwid) $ch]] > 1} {
1370 set children($v,$rwid) [lsort -command [list vtokcmp $v] \
1371 $children($v,$rwid)]
1372 }
1373 # fix the graph after joining $id to $rwid
1374 set a $varcid($v,$ch)
1375 fix_reversal $rwid $a $v
1376 # parentlist is wrong for the last element of arc $a
1377 # even if displayorder is right, hence the 3rd arg here
1378 modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}]
Paul Mackerrasf806f0f2008-02-24 12:16:56 +11001379 }
1380}
1381
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001382# Mechanism for registering a command to be executed when we come
1383# across a particular commit. To handle the case when only the
1384# prefix of the commit is known, the commitinterest array is now
1385# indexed by the first 4 characters of the ID. Each element is a
1386# list of id, cmd pairs.
1387proc interestedin {id cmd} {
1388 global commitinterest
1389
1390 lappend commitinterest([string range $id 0 3]) $id $cmd
1391}
1392
1393proc check_interest {id scripts} {
1394 global commitinterest
1395
1396 set prefix [string range $id 0 3]
1397 if {[info exists commitinterest($prefix)]} {
Denton Liue2445882020-09-10 21:36:33 -07001398 set newlist {}
1399 foreach {i script} $commitinterest($prefix) {
1400 if {[string match "$i*" $id]} {
1401 lappend scripts [string map [list "%I" $id "%P" $i] $script]
1402 } else {
1403 lappend newlist $i $script
1404 }
1405 }
1406 if {$newlist ne {}} {
1407 set commitinterest($prefix) $newlist
1408 } else {
1409 unset commitinterest($prefix)
1410 }
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001411 }
1412 return $scripts
1413}
1414
Paul Mackerrasf806f0f2008-02-24 12:16:56 +11001415proc getcommitlines {fd inst view updating} {
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001416 global cmitlisted leftover
Paul Mackerras3ed31a82008-04-26 16:00:00 +10001417 global commitidx commitdata vdatemode
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001418 global parents children curview hlview
Paul Mackerras468bcae2008-03-03 10:19:35 +11001419 global idpending ordertok
Paul Mackerras22387f22012-03-19 11:21:08 +11001420 global varccommits varcid varctok vtokmod vfilelimit vshortids
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00001421
Paul Mackerrasd1e46752006-08-16 20:02:32 +10001422 set stuff [read $fd 500000]
Paul Mackerras005a2f42007-07-26 22:36:39 +10001423 # git log doesn't terminate the last commit with a null...
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001424 if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} {
Denton Liue2445882020-09-10 21:36:33 -07001425 set stuff "\0"
Paul Mackerras005a2f42007-07-26 22:36:39 +10001426 }
Paul Mackerrasb490a992005-06-22 10:25:38 +10001427 if {$stuff == {}} {
Denton Liue2445882020-09-10 21:36:33 -07001428 if {![eof $fd]} {
1429 return 1
1430 }
1431 global commfd viewcomplete viewactive viewname
1432 global viewinstances
1433 unset commfd($inst)
1434 set i [lsearch -exact $viewinstances($view) $inst]
1435 if {$i >= 0} {
1436 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
1437 }
1438 # set it blocking so we wait for the process to terminate
1439 fconfigure $fd -blocking 1
1440 if {[catch {close $fd} err]} {
1441 set fv {}
1442 if {$view != $curview} {
1443 set fv " for the \"$viewname($view)\" view"
1444 }
1445 if {[string range $err 0 4] == "usage"} {
1446 set err "Gitk: error reading commits$fv:\
1447 bad arguments to git log."
1448 if {$viewname($view) eq [mc "Command line"]} {
1449 append err \
1450 " (Note: arguments to gitk are passed to git log\
1451 to allow selection of commits to be displayed.)"
1452 }
1453 } else {
1454 set err "Error reading commits$fv: $err"
1455 }
1456 error_popup $err
1457 }
1458 if {[incr viewactive($view) -1] <= 0} {
1459 set viewcomplete($view) 1
1460 # Check if we have seen any ids listed as parents that haven't
1461 # appeared in the list
1462 closevarcs $view
1463 notbusy $view
1464 }
1465 if {$view == $curview} {
1466 run chewcommits
1467 }
1468 return 0
Paul Mackerras9a40c502005-05-12 23:46:16 +00001469 }
Paul Mackerrasb490a992005-06-22 10:25:38 +10001470 set start 0
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11001471 set gotsome 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001472 set scripts {}
Paul Mackerrasb490a992005-06-22 10:25:38 +10001473 while 1 {
Denton Liue2445882020-09-10 21:36:33 -07001474 set i [string first "\0" $stuff $start]
1475 if {$i < 0} {
1476 append leftover($inst) [string range $stuff $start end]
1477 break
1478 }
1479 if {$start == 0} {
1480 set cmit $leftover($inst)
1481 append cmit [string range $stuff 0 [expr {$i - 1}]]
1482 set leftover($inst) {}
1483 } else {
1484 set cmit [string range $stuff $start [expr {$i - 1}]]
1485 }
1486 set start [expr {$i + 1}]
1487 set j [string first "\n" $cmit]
1488 set ok 0
1489 set listed 1
1490 if {$j >= 0 && [string match "commit *" $cmit]} {
1491 set ids [string range $cmit 7 [expr {$j - 1}]]
1492 if {[string match {[-^<>]*} $ids]} {
1493 switch -- [string index $ids 0] {
1494 "-" {set listed 0}
1495 "^" {set listed 2}
1496 "<" {set listed 3}
1497 ">" {set listed 4}
1498 }
1499 set ids [string range $ids 1 end]
1500 }
1501 set ok 1
1502 foreach id $ids {
1503 if {[string length $id] != 40} {
1504 set ok 0
1505 break
1506 }
1507 }
1508 }
1509 if {!$ok} {
1510 set shortcmit $cmit
1511 if {[string length $shortcmit] > 80} {
1512 set shortcmit "[string range $shortcmit 0 80]..."
1513 }
1514 error_popup "[mc "Can't parse git log output:"] {$shortcmit}"
1515 exit 1
1516 }
1517 set id [lindex $ids 0]
1518 set vid $view,$id
Paul Mackerrasf806f0f2008-02-24 12:16:56 +11001519
Denton Liue2445882020-09-10 21:36:33 -07001520 lappend vshortids($view,[string range $id 0 3]) $id
Paul Mackerras22387f22012-03-19 11:21:08 +11001521
Denton Liue2445882020-09-10 21:36:33 -07001522 if {!$listed && $updating && ![info exists varcid($vid)] &&
1523 $vfilelimit($view) ne {}} {
1524 # git log doesn't rewrite parents for unlisted commits
1525 # when doing path limiting, so work around that here
1526 # by working out the rewritten parent with git rev-list
1527 # and if we already know about it, using the rewritten
1528 # parent as a substitute parent for $id's children.
1529 if {![catch {
1530 set rwid [exec git rev-list --first-parent --max-count=1 \
1531 $id -- $vfilelimit($view)]
1532 }]} {
1533 if {$rwid ne {} && [info exists varcid($view,$rwid)]} {
1534 # use $rwid in place of $id
1535 rewrite_commit $view $id $rwid
1536 continue
1537 }
1538 }
1539 }
Paul Mackerrasf806f0f2008-02-24 12:16:56 +11001540
Denton Liue2445882020-09-10 21:36:33 -07001541 set a 0
1542 if {[info exists varcid($vid)]} {
1543 if {$cmitlisted($vid) || !$listed} continue
1544 set a $varcid($vid)
1545 }
1546 if {$listed} {
1547 set olds [lrange $ids 1 end]
1548 } else {
1549 set olds {}
1550 }
1551 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
1552 set cmitlisted($vid) $listed
1553 set parents($vid) $olds
1554 if {![info exists children($vid)]} {
1555 set children($vid) {}
1556 } elseif {$a == 0 && [llength $children($vid)] == 1} {
1557 set k [lindex $children($vid) 0]
1558 if {[llength $parents($view,$k)] == 1 &&
1559 (!$vdatemode($view) ||
1560 $varcid($view,$k) == [llength $varctok($view)] - 1)} {
1561 set a $varcid($view,$k)
1562 }
1563 }
1564 if {$a == 0} {
1565 # new arc
1566 set a [newvarc $view $id]
1567 }
1568 if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} {
1569 modify_arc $view $a
1570 }
1571 if {![info exists varcid($vid)]} {
1572 set varcid($vid) $a
1573 lappend varccommits($view,$a) $id
1574 incr commitidx($view)
1575 }
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11001576
Denton Liue2445882020-09-10 21:36:33 -07001577 set i 0
1578 foreach p $olds {
1579 if {$i == 0 || [lsearch -exact $olds $p] >= $i} {
1580 set vp $view,$p
1581 if {[llength [lappend children($vp) $id]] > 1 &&
1582 [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} {
1583 set children($vp) [lsort -command [list vtokcmp $view] \
1584 $children($vp)]
1585 unset -nocomplain ordertok
1586 }
1587 if {[info exists varcid($view,$p)]} {
1588 fix_reversal $p $a $view
1589 }
1590 }
1591 incr i
1592 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001593
Denton Liue2445882020-09-10 21:36:33 -07001594 set scripts [check_interest $id $scripts]
1595 set gotsome 1
Paul Mackerras9f1afe02006-02-19 22:44:47 +11001596 }
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11001597 if {$gotsome} {
Denton Liue2445882020-09-10 21:36:33 -07001598 global numcommits hlview
Paul Mackerrasac1276a2008-03-03 10:11:08 +11001599
Denton Liue2445882020-09-10 21:36:33 -07001600 if {$view == $curview} {
1601 set numcommits $commitidx($view)
1602 run chewcommits
1603 }
1604 if {[info exists hlview] && $view == $hlview} {
1605 # we never actually get here...
1606 run vhighlightmore
1607 }
1608 foreach s $scripts {
1609 eval $s
1610 }
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11001611 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10001612 return 2
Paul Mackerrascfb45632005-05-31 12:14:42 +00001613}
1614
Paul Mackerrasac1276a2008-03-03 10:11:08 +11001615proc chewcommits {} {
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10001616 global curview hlview viewcomplete
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001617 global pending_select
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00001618
Paul Mackerrasac1276a2008-03-03 10:11:08 +11001619 layoutmore
1620 if {$viewcomplete($curview)} {
Denton Liue2445882020-09-10 21:36:33 -07001621 global commitidx varctok
1622 global numcommits startmsecs
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10001623
Denton Liue2445882020-09-10 21:36:33 -07001624 if {[info exists pending_select]} {
1625 update
1626 reset_pending_select {}
Alexander Gavrilov835e62a2008-07-26 20:15:54 +04001627
Denton Liue2445882020-09-10 21:36:33 -07001628 if {[commitinview $pending_select $curview]} {
1629 selectline [rowofcommit $pending_select] 1
1630 } else {
1631 set row [first_real_row]
1632 selectline $row 1
1633 }
1634 }
1635 if {$commitidx($curview) > 0} {
1636 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1637 #puts "overall $ms ms for $numcommits commits"
1638 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1639 } else {
1640 show_status [mc "No commits selected"]
1641 }
1642 notbusy layout
Paul Mackerrasb6645502005-08-11 09:56:23 +10001643 }
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10001644 return 0
Paul Mackerras1db95b02005-05-09 04:08:39 +00001645}
1646
Alexander Gavrilov590915d2008-11-09 18:06:07 +03001647proc do_readcommit {id} {
1648 global tclencoding
1649
1650 # Invoke git-log to handle automatic encoding conversion
1651 set fd [open [concat | git log --no-color --pretty=raw -1 $id] r]
1652 # Read the results using i18n.logoutputencoding
1653 fconfigure $fd -translation lf -eofchar {}
1654 if {$tclencoding != {}} {
Denton Liue2445882020-09-10 21:36:33 -07001655 fconfigure $fd -encoding $tclencoding
Alexander Gavrilov590915d2008-11-09 18:06:07 +03001656 }
1657 set contents [read $fd]
1658 close $fd
1659 # Remove the heading line
1660 regsub {^commit [0-9a-f]+\n} $contents {} contents
1661
1662 return $contents
1663}
1664
Paul Mackerras1db95b02005-05-09 04:08:39 +00001665proc readcommit {id} {
Alexander Gavrilov590915d2008-11-09 18:06:07 +03001666 if {[catch {set contents [do_readcommit $id]}]} return
1667 parsecommit $id $contents 1
Paul Mackerrasb490a992005-06-22 10:25:38 +10001668}
1669
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11001670proc parsecommit {id contents listed} {
Anders Kaseorgef738962011-01-19 14:46:59 -05001671 global commitinfo
Sven Verdoolaegeb5c2f302005-11-29 22:15:51 +01001672
1673 set inhdr 1
1674 set comment {}
1675 set headline {}
1676 set auname {}
1677 set audate {}
1678 set comname {}
1679 set comdate {}
Paul Mackerras232475d2005-11-15 10:34:03 +11001680 set hdrend [string first "\n\n" $contents]
1681 if {$hdrend < 0} {
Denton Liue2445882020-09-10 21:36:33 -07001682 # should never happen...
1683 set hdrend [string length $contents]
Paul Mackerras232475d2005-11-15 10:34:03 +11001684 }
1685 set header [string range $contents 0 [expr {$hdrend - 1}]]
1686 set comment [string range $contents [expr {$hdrend + 2}] end]
1687 foreach line [split $header "\n"] {
Denton Liue2445882020-09-10 21:36:33 -07001688 set line [split $line " "]
1689 set tag [lindex $line 0]
1690 if {$tag == "author"} {
1691 set audate [lrange $line end-1 end]
1692 set auname [join [lrange $line 1 end-2] " "]
1693 } elseif {$tag == "committer"} {
1694 set comdate [lrange $line end-1 end]
1695 set comname [join [lrange $line 1 end-2] " "]
1696 }
Paul Mackerras1db95b02005-05-09 04:08:39 +00001697 }
Paul Mackerras232475d2005-11-15 10:34:03 +11001698 set headline {}
Paul Mackerras43c25072006-09-27 10:56:02 +10001699 # take the first non-blank line of the comment as the headline
1700 set headline [string trimleft $comment]
1701 set i [string first "\n" $headline]
Paul Mackerras232475d2005-11-15 10:34:03 +11001702 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001703 set headline [string range $headline 0 $i]
Paul Mackerras43c25072006-09-27 10:56:02 +10001704 }
1705 set headline [string trimright $headline]
1706 set i [string first "\r" $headline]
1707 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001708 set headline [string trimright [string range $headline 0 $i]]
Paul Mackerras232475d2005-11-15 10:34:03 +11001709 }
1710 if {!$listed} {
Denton Liue2445882020-09-10 21:36:33 -07001711 # git log indents the comment by 4 spaces;
1712 # if we got this via git cat-file, add the indentation
1713 set newcomment {}
1714 foreach line [split $comment "\n"] {
1715 append newcomment " "
1716 append newcomment $line
1717 append newcomment "\n"
1718 }
1719 set comment $newcomment
Paul Mackerras1db95b02005-05-09 04:08:39 +00001720 }
Raphael Zimmerer36242492011-04-19 22:37:09 +02001721 set hasnote [string first "\nNotes:\n" $contents]
Thomas Rastb449eb22013-11-16 18:37:42 +01001722 set diff ""
1723 # If there is diff output shown in the git-log stream, split it
1724 # out. But get rid of the empty line that always precedes the
1725 # diff.
1726 set i [string first "\n\ndiff" $comment]
1727 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001728 set diff [string range $comment $i+1 end]
1729 set comment [string range $comment 0 $i-1]
Thomas Rastb449eb22013-11-16 18:37:42 +01001730 }
Paul Mackerrase5c2d852005-05-11 23:44:54 +00001731 set commitinfo($id) [list $headline $auname $audate \
Denton Liue2445882020-09-10 21:36:33 -07001732 $comname $comdate $comment $hasnote $diff]
Paul Mackerras1db95b02005-05-09 04:08:39 +00001733}
1734
Paul Mackerrasf7a3e8d2006-03-18 10:04:48 +11001735proc getcommit {id} {
Paul Mackerras79b2c752006-04-02 20:47:40 +10001736 global commitdata commitinfo
Paul Mackerras8ed16482006-03-02 22:56:44 +11001737
Paul Mackerrasf7a3e8d2006-03-18 10:04:48 +11001738 if {[info exists commitdata($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07001739 parsecommit $id $commitdata($id) 1
Paul Mackerras8ed16482006-03-02 22:56:44 +11001740 } else {
Denton Liue2445882020-09-10 21:36:33 -07001741 readcommit $id
1742 if {![info exists commitinfo($id)]} {
1743 set commitinfo($id) [list [mc "No commit information available"]]
1744 }
Paul Mackerras8ed16482006-03-02 22:56:44 +11001745 }
1746 return 1
1747}
1748
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001749# Expand an abbreviated commit ID to a list of full 40-char IDs that match
1750# and are present in the current view.
1751# This is fairly slow...
1752proc longid {prefix} {
Paul Mackerras22387f22012-03-19 11:21:08 +11001753 global varcid curview vshortids
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001754
1755 set ids {}
Paul Mackerras22387f22012-03-19 11:21:08 +11001756 if {[string length $prefix] >= 4} {
Denton Liue2445882020-09-10 21:36:33 -07001757 set vshortid $curview,[string range $prefix 0 3]
1758 if {[info exists vshortids($vshortid)]} {
1759 foreach id $vshortids($vshortid) {
1760 if {[string match "$prefix*" $id]} {
1761 if {[lsearch -exact $ids $id] < 0} {
1762 lappend ids $id
1763 if {[llength $ids] >= 2} break
1764 }
1765 }
1766 }
1767 }
Paul Mackerras22387f22012-03-19 11:21:08 +11001768 } else {
Denton Liue2445882020-09-10 21:36:33 -07001769 foreach match [array names varcid "$curview,$prefix*"] {
1770 lappend ids [lindex [split $match ","] 1]
1771 if {[llength $ids] >= 2} break
1772 }
Paul Mackerrasd375ef92008-10-21 10:18:12 +11001773 }
1774 return $ids
1775}
1776
Paul Mackerras887fe3c2005-05-21 07:35:37 +00001777proc readrefs {} {
Paul Mackerras62d3ea62006-09-11 10:36:53 +10001778 global tagids idtags headids idheads tagobjid
Paul Mackerras219ea3a2006-09-07 10:21:39 +10001779 global otherrefids idotherrefs mainhead mainheadid
Alexander Gavrilov39816d62008-08-23 12:27:44 +04001780 global selecthead selectheadid
Thomas Rastffe15292009-08-03 23:53:36 +02001781 global hideremotes
Kazuhiro Katod4247e02019-12-07 00:32:25 +00001782 global tclencoding
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10001783
Sven Verdoolaegeb5c2f302005-11-29 22:15:51 +01001784 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
Denton Liue2445882020-09-10 21:36:33 -07001785 unset -nocomplain $v
Sven Verdoolaegeb5c2f302005-11-29 22:15:51 +01001786 }
Paul Mackerras62d3ea62006-09-11 10:36:53 +10001787 set refd [open [list | git show-ref -d] r]
Kazuhiro Katod4247e02019-12-07 00:32:25 +00001788 if {$tclencoding != {}} {
Denton Liue2445882020-09-10 21:36:33 -07001789 fconfigure $refd -encoding $tclencoding
Kazuhiro Katod4247e02019-12-07 00:32:25 +00001790 }
Paul Mackerras62d3ea62006-09-11 10:36:53 +10001791 while {[gets $refd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07001792 if {[string index $line 40] ne " "} continue
1793 set id [string range $line 0 39]
1794 set ref [string range $line 41 end]
1795 if {![string match "refs/*" $ref]} continue
1796 set name [string range $ref 5 end]
1797 if {[string match "remotes/*" $name]} {
1798 if {![string match "*/HEAD" $name] && !$hideremotes} {
1799 set headids($name) $id
1800 lappend idheads($id) $name
1801 }
1802 } elseif {[string match "heads/*" $name]} {
1803 set name [string range $name 6 end]
1804 set headids($name) $id
1805 lappend idheads($id) $name
1806 } elseif {[string match "tags/*" $name]} {
1807 # this lets refs/tags/foo^{} overwrite refs/tags/foo,
1808 # which is what we want since the former is the commit ID
1809 set name [string range $name 5 end]
1810 if {[string match "*^{}" $name]} {
1811 set name [string range $name 0 end-3]
1812 } else {
1813 set tagobjid($name) $id
1814 }
1815 set tagids($name) $id
1816 lappend idtags($id) $name
1817 } else {
1818 set otherrefids($name) $id
1819 lappend idotherrefs($id) $name
1820 }
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10001821 }
Alex Riesen062d6712007-07-29 22:28:40 +02001822 catch {close $refd}
Paul Mackerras8a485712006-07-06 10:21:23 +10001823 set mainhead {}
Paul Mackerras219ea3a2006-09-07 10:21:39 +10001824 set mainheadid {}
Paul Mackerras8a485712006-07-06 10:21:23 +10001825 catch {
Denton Liue2445882020-09-10 21:36:33 -07001826 set mainheadid [exec git rev-parse HEAD]
1827 set thehead [exec git symbolic-ref HEAD]
1828 if {[string match "refs/heads/*" $thehead]} {
1829 set mainhead [string range $thehead 11 end]
1830 }
Paul Mackerras8a485712006-07-06 10:21:23 +10001831 }
Alexander Gavrilov39816d62008-08-23 12:27:44 +04001832 set selectheadid {}
1833 if {$selecthead ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07001834 catch {
1835 set selectheadid [exec git rev-parse --verify $selecthead]
1836 }
Alexander Gavrilov39816d62008-08-23 12:27:44 +04001837 }
Paul Mackerras887fe3c2005-05-21 07:35:37 +00001838}
1839
Paul Mackerras8f489362007-07-13 19:49:37 +10001840# skip over fake commits
1841proc first_real_row {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11001842 global nullid nullid2 numcommits
Paul Mackerras8f489362007-07-13 19:49:37 +10001843
1844 for {set row 0} {$row < $numcommits} {incr row} {
Denton Liue2445882020-09-10 21:36:33 -07001845 set id [commitonrow $row]
1846 if {$id ne $nullid && $id ne $nullid2} {
1847 break
1848 }
Paul Mackerras8f489362007-07-13 19:49:37 +10001849 }
1850 return $row
1851}
1852
Paul Mackerrase11f1232007-06-16 20:29:25 +10001853# update things for a head moved to a child of its previous location
1854proc movehead {id name} {
1855 global headids idheads
1856
1857 removehead $headids($name) $name
1858 set headids($name) $id
1859 lappend idheads($id) $name
1860}
1861
1862# update things when a head has been removed
1863proc removehead {id name} {
1864 global headids idheads
1865
1866 if {$idheads($id) eq $name} {
Denton Liue2445882020-09-10 21:36:33 -07001867 unset idheads($id)
Paul Mackerrase11f1232007-06-16 20:29:25 +10001868 } else {
Denton Liue2445882020-09-10 21:36:33 -07001869 set i [lsearch -exact $idheads($id) $name]
1870 if {$i >= 0} {
1871 set idheads($id) [lreplace $idheads($id) $i $i]
1872 }
Paul Mackerrase11f1232007-06-16 20:29:25 +10001873 }
1874 unset headids($name)
1875}
1876
Pat Thoytsd93f1712009-04-17 01:24:35 +01001877proc ttk_toplevel {w args} {
1878 global use_ttk
1879 eval [linsert $args 0 ::toplevel $w]
1880 if {$use_ttk} {
1881 place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1
1882 }
1883 return $w
1884}
1885
Alexander Gavrilove7d64002008-11-11 23:55:42 +03001886proc make_transient {window origin} {
1887 global have_tk85
1888
1889 # In MacOS Tk 8.4 transient appears to work by setting
1890 # overrideredirect, which is utterly useless, since the
1891 # windows get no border, and are not even kept above
1892 # the parent.
1893 if {!$have_tk85 && [tk windowingsystem] eq {aqua}} return
1894
1895 wm transient $window $origin
1896
1897 # Windows fails to place transient windows normally, so
1898 # schedule a callback to center them on the parent.
1899 if {[tk windowingsystem] eq {win32}} {
Denton Liue2445882020-09-10 21:36:33 -07001900 after idle [list tk::PlaceWindow $window widget $origin]
Alexander Gavrilove7d64002008-11-11 23:55:42 +03001901 }
1902}
1903
Alex Henrieef87a482015-05-11 13:26:41 -06001904proc show_error {w top msg} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01001905 global NS
Pat Thoyts3cb1f9c2009-05-12 15:45:06 +01001906 if {![info exists NS]} {set NS ""}
Pat Thoytsd93f1712009-04-17 01:24:35 +01001907 if {[wm state $top] eq "withdrawn"} { wm deiconify $top }
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00001908 message $w.m -text $msg -justify center -aspect 400
1909 pack $w.m -side top -fill x -padx 20 -pady 20
Alex Henrieef87a482015-05-11 13:26:41 -06001910 ${NS}::button $w.ok -default active -text [mc OK] -command "destroy $top"
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00001911 pack $w.ok -side bottom -fill x
Paul Mackerrase54be9e2006-05-26 22:34:30 +10001912 bind $top <Visibility> "grab $top; focus $top"
1913 bind $top <Key-Return> "destroy $top"
Alexander Gavrilov76f15942008-11-02 21:59:44 +03001914 bind $top <Key-space> "destroy $top"
1915 bind $top <Key-Escape> "destroy $top"
Paul Mackerrase54be9e2006-05-26 22:34:30 +10001916 tkwait window $top
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00001917}
1918
Alexander Gavrilov84a76f12008-11-02 21:59:45 +03001919proc error_popup {msg {owner .}} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01001920 if {[tk windowingsystem] eq "win32"} {
1921 tk_messageBox -icon error -type ok -title [wm title .] \
1922 -parent $owner -message $msg
1923 } else {
1924 set w .error
1925 ttk_toplevel $w
1926 make_transient $w $owner
1927 show_error $w $w $msg
1928 }
Paul Mackerras098dd8a2006-05-03 09:32:53 +10001929}
1930
Alexander Gavrilov84a76f12008-11-02 21:59:45 +03001931proc confirm_popup {msg {owner .}} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01001932 global confirm_ok NS
Paul Mackerras10299152006-08-02 09:52:01 +10001933 set confirm_ok 0
1934 set w .confirm
Pat Thoytsd93f1712009-04-17 01:24:35 +01001935 ttk_toplevel $w
Alexander Gavrilove7d64002008-11-11 23:55:42 +03001936 make_transient $w $owner
Paul Mackerras10299152006-08-02 09:52:01 +10001937 message $w.m -text $msg -justify center -aspect 400
1938 pack $w.m -side top -fill x -padx 20 -pady 20
Pat Thoytsd93f1712009-04-17 01:24:35 +01001939 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
Paul Mackerras10299152006-08-02 09:52:01 +10001940 pack $w.ok -side left -fill x
Pat Thoytsd93f1712009-04-17 01:24:35 +01001941 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
Paul Mackerras10299152006-08-02 09:52:01 +10001942 pack $w.cancel -side right -fill x
1943 bind $w <Visibility> "grab $w; focus $w"
Alexander Gavrilov76f15942008-11-02 21:59:44 +03001944 bind $w <Key-Return> "set confirm_ok 1; destroy $w"
1945 bind $w <Key-space> "set confirm_ok 1; destroy $w"
1946 bind $w <Key-Escape> "destroy $w"
Pat Thoytsd93f1712009-04-17 01:24:35 +01001947 tk::PlaceWindow $w widget $owner
Paul Mackerras10299152006-08-02 09:52:01 +10001948 tkwait window $w
1949 return $confirm_ok
1950}
1951
Paul Mackerrasb039f0a2008-01-06 15:54:46 +11001952proc setoptions {} {
Giuseppe Bilotta6cb73c82015-12-08 08:05:50 +01001953 global use_ttk
1954
Pat Thoytsd93f1712009-04-17 01:24:35 +01001955 if {[tk windowingsystem] ne "win32"} {
1956 option add *Panedwindow.showHandle 1 startupFile
1957 option add *Panedwindow.sashRelief raised startupFile
1958 if {[tk windowingsystem] ne "aqua"} {
1959 option add *Menu.font uifont startupFile
1960 }
1961 } else {
1962 option add *Menu.TearOff 0 startupFile
1963 }
Paul Mackerrasb039f0a2008-01-06 15:54:46 +11001964 option add *Button.font uifont startupFile
1965 option add *Checkbutton.font uifont startupFile
1966 option add *Radiobutton.font uifont startupFile
Paul Mackerrasb039f0a2008-01-06 15:54:46 +11001967 option add *Menubutton.font uifont startupFile
1968 option add *Label.font uifont startupFile
1969 option add *Message.font uifont startupFile
Mark Hillsb9b142f2010-01-13 20:40:22 +00001970 option add *Entry.font textfont startupFile
1971 option add *Text.font textfont startupFile
Pat Thoytsd93f1712009-04-17 01:24:35 +01001972 option add *Labelframe.font uifont startupFile
Mark Hills0933b042010-01-13 20:40:19 +00001973 option add *Spinbox.font textfont startupFile
Mark Hills207ad7b2010-01-13 20:40:20 +00001974 option add *Listbox.font mainfont startupFile
Paul Mackerrasb039f0a2008-01-06 15:54:46 +11001975}
1976
Giuseppe Bilotta6cb73c82015-12-08 08:05:50 +01001977proc setttkstyle {} {
1978 eval font configure TkDefaultFont [fontflags mainfont]
1979 eval font configure TkTextFont [fontflags textfont]
1980 eval font configure TkHeadingFont [fontflags mainfont]
1981 eval font configure TkCaptionFont [fontflags mainfont] -weight bold
1982 eval font configure TkTooltipFont [fontflags uifont]
1983 eval font configure TkFixedFont [fontflags textfont]
1984 eval font configure TkIconFont [fontflags uifont]
1985 eval font configure TkMenuFont [fontflags uifont]
1986 eval font configure TkSmallCaptionFont [fontflags uifont]
1987}
1988
Paul Mackerras79056032008-10-18 16:24:46 +11001989# Make a menu and submenus.
1990# m is the window name for the menu, items is the list of menu items to add.
1991# Each item is a list {mc label type description options...}
1992# mc is ignored; it's so we can put mc there to alert xgettext
1993# label is the string that appears in the menu
1994# type is cascade, command or radiobutton (should add checkbutton)
1995# description depends on type; it's the sublist for cascade, the
1996# command to invoke for command, or {variable value} for radiobutton
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11001997proc makemenu {m items} {
1998 menu $m
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03001999 if {[tk windowingsystem] eq {aqua}} {
Denton Liue2445882020-09-10 21:36:33 -07002000 set Meta1 Cmd
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03002001 } else {
Denton Liue2445882020-09-10 21:36:33 -07002002 set Meta1 Ctrl
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03002003 }
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002004 foreach i $items {
Denton Liue2445882020-09-10 21:36:33 -07002005 set name [mc [lindex $i 1]]
2006 set type [lindex $i 2]
2007 set thing [lindex $i 3]
2008 set params [list $type]
2009 if {$name ne {}} {
2010 set u [string first "&" [string map {&& x} $name]]
2011 lappend params -label [string map {&& & & {}} $name]
2012 if {$u >= 0} {
2013 lappend params -underline $u
2014 }
2015 }
2016 switch -- $type {
2017 "cascade" {
2018 set submenu [string tolower [string map {& ""} [lindex $i 1]]]
2019 lappend params -menu $m.$submenu
2020 }
2021 "command" {
2022 lappend params -command $thing
2023 }
2024 "radiobutton" {
2025 lappend params -variable [lindex $thing 0] \
2026 -value [lindex $thing 1]
2027 }
2028 }
2029 set tail [lrange $i 4 end]
2030 regsub -all {\yMeta1\y} $tail $Meta1 tail
2031 eval $m add $params $tail
2032 if {$type eq "cascade"} {
2033 makemenu $m.$submenu $thing
2034 }
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002035 }
2036}
2037
2038# translate string and remove ampersands
2039proc mca {str} {
2040 return [string map {&& & & {}} [mc $str]]
2041}
2042
Paul Mackerras39c12692013-05-11 17:08:41 +10002043proc cleardropsel {w} {
2044 $w selection clear
2045}
Pat Thoytsd93f1712009-04-17 01:24:35 +01002046proc makedroplist {w varname args} {
2047 global use_ttk
2048 if {$use_ttk} {
Pat Thoyts3cb1f9c2009-05-12 15:45:06 +01002049 set width 0
2050 foreach label $args {
2051 set cx [string length $label]
2052 if {$cx > $width} {set width $cx}
2053 }
Denton Liue2445882020-09-10 21:36:33 -07002054 set gm [ttk::combobox $w -width $width -state readonly\
2055 -textvariable $varname -values $args \
2056 -exportselection false]
2057 bind $gm <<ComboboxSelected>> [list $gm selection clear]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002058 } else {
Denton Liue2445882020-09-10 21:36:33 -07002059 set gm [eval [linsert $args 0 tk_optionMenu $w $varname]]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002060 }
2061 return $gm
2062}
2063
Paul Mackerrasd94f8cd2006-04-06 10:18:23 +10002064proc makewindow {} {
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11002065 global canv canv2 canv3 linespc charspc ctext cflist cscroll
Paul Mackerras9c311b32007-10-04 22:27:13 +10002066 global tabstop
Paul Mackerrasb74fd572005-07-16 07:46:13 -04002067 global findtype findtypemenu findloc findstring fstring geometry
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002068 global entries sha1entry sha1string sha1but
Steffen Prohaska890fae72007-08-12 12:05:46 +02002069 global diffcontextstring diffcontext
Steffen Prohaskab9b86002008-01-17 23:42:55 +01002070 global ignorespace
Paul Mackerras94a2eed2005-08-07 15:27:57 +10002071 global maincursor textcursor curtextcursor
Paul Mackerras219ea3a2006-09-07 10:21:39 +10002072 global rowctxmenu fakerowmenu mergemax wrapcomment
Paul Mackerras60f7a7d2006-05-26 10:43:47 +10002073 global highlight_files gdttype
Paul Mackerras3ea06f92006-05-24 10:16:03 +10002074 global searchstring sstring
Stefan Dotterweich113ce122020-02-11 22:24:48 +01002075 global bgcolor fgcolor bglist fglist diffcolors diffbgcolors selectbgcolor
Gauthier Östervall252c52d2013-03-27 14:40:51 +01002076 global uifgcolor uifgdisabledcolor
2077 global filesepbgcolor filesepfgcolor
2078 global mergecolors foundbgcolor currentsearchhitbgcolor
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002079 global headctxmenu progresscanv progressitem progresscoords statusw
2080 global fprogitem fprogcoord lastprogupdate progupdatepending
Paul Mackerras6df74032008-05-11 22:13:02 +10002081 global rprogitem rprogcoord rownumsel numcommits
Pat Thoytsd93f1712009-04-17 01:24:35 +01002082 global have_tk85 use_ttk NS
Thomas Rastae4e3ff2010-10-16 12:15:10 +02002083 global git_version
2084 global worddiff
Paul Mackerras9a40c502005-05-12 23:46:16 +00002085
Paul Mackerras79056032008-10-18 16:24:46 +11002086 # The "mc" arguments here are purely so that xgettext
2087 # sees the following string as needing to be translated
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002088 set file {
Denton Liue2445882020-09-10 21:36:33 -07002089 mc "&File" cascade {
2090 {mc "&Update" command updatecommits -accelerator F5}
2091 {mc "&Reload" command reloadcommits -accelerator Shift-F5}
2092 {mc "Reread re&ferences" command rereadrefs}
2093 {mc "&List references" command showrefs -accelerator F2}
2094 {xx "" separator}
2095 {mc "Start git &gui" command {exec git gui &}}
2096 {xx "" separator}
2097 {mc "&Quit" command doquit -accelerator Meta1-Q}
2098 }}
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002099 set edit {
Denton Liue2445882020-09-10 21:36:33 -07002100 mc "&Edit" cascade {
2101 {mc "&Preferences" command doprefs}
2102 }}
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002103 set view {
Denton Liue2445882020-09-10 21:36:33 -07002104 mc "&View" cascade {
2105 {mc "&New view..." command {newview 0} -accelerator Shift-F4}
2106 {mc "&Edit view..." command editview -state disabled -accelerator F4}
2107 {mc "&Delete view" command delview -state disabled}
2108 {xx "" separator}
2109 {mc "&All files" radiobutton {selectedview 0} -command {showview 0}}
2110 }}
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002111 if {[tk windowingsystem] ne "aqua"} {
Denton Liue2445882020-09-10 21:36:33 -07002112 set help {
2113 mc "&Help" cascade {
2114 {mc "&About gitk" command about}
2115 {mc "&Key bindings" command keys}
2116 }}
2117 set bar [list $file $edit $view $help]
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002118 } else {
Denton Liue2445882020-09-10 21:36:33 -07002119 proc ::tk::mac::ShowPreferences {} {doprefs}
2120 proc ::tk::mac::Quit {} {doquit}
2121 lset file end [lreplace [lindex $file end] end-1 end]
2122 set apple {
2123 xx "&Apple" cascade {
2124 {mc "&About gitk" command about}
2125 {xx "" separator}
2126 }}
2127 set help {
2128 mc "&Help" cascade {
2129 {mc "&Key bindings" command keys}
2130 }}
2131 set bar [list $apple $file $view $help]
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002132 }
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002133 makemenu .bar $bar
Paul Mackerras9a40c502005-05-12 23:46:16 +00002134 . configure -menu .bar
2135
Pat Thoytsd93f1712009-04-17 01:24:35 +01002136 if {$use_ttk} {
2137 # cover the non-themed toplevel with a themed frame.
2138 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1
2139 }
2140
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002141 # the gui has upper and lower half, parts of a paned window.
Pat Thoytsd93f1712009-04-17 01:24:35 +01002142 ${NS}::panedwindow .ctop -orient vertical
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002143
2144 # possibly use assumed geometry
Mark Levedahl9ca72f42007-02-12 19:19:34 -05002145 if {![info exists geometry(pwsash0)]} {
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002146 set geometry(topheight) [expr {15 * $linespc}]
2147 set geometry(topwidth) [expr {80 * $charspc}]
2148 set geometry(botheight) [expr {15 * $linespc}]
2149 set geometry(botwidth) [expr {50 * $charspc}]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002150 set geometry(pwsash0) [list [expr {40 * $charspc}] 2]
2151 set geometry(pwsash1) [list [expr {60 * $charspc}] 2]
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002152 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002153
2154 # the upper half will have a paned window, a scroll bar to the right, and some stuff below
Pat Thoytsd93f1712009-04-17 01:24:35 +01002155 ${NS}::frame .tf -height $geometry(topheight) -width $geometry(topwidth)
2156 ${NS}::frame .tf.histframe
2157 ${NS}::panedwindow .tf.histframe.pwclist -orient horizontal
2158 if {!$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002159 .tf.histframe.pwclist configure -sashpad 0 -handlesize 4
Pat Thoytsd93f1712009-04-17 01:24:35 +01002160 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002161
2162 # create three canvases
2163 set cscroll .tf.histframe.csb
2164 set canv .tf.histframe.pwclist.canv
Mark Levedahl9ca72f42007-02-12 19:19:34 -05002165 canvas $canv \
Denton Liue2445882020-09-10 21:36:33 -07002166 -selectbackground $selectbgcolor \
2167 -background $bgcolor -bd 0 \
2168 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002169 .tf.histframe.pwclist add $canv
2170 set canv2 .tf.histframe.pwclist.canv2
Mark Levedahl9ca72f42007-02-12 19:19:34 -05002171 canvas $canv2 \
Denton Liue2445882020-09-10 21:36:33 -07002172 -selectbackground $selectbgcolor \
2173 -background $bgcolor -bd 0 -yscrollincr $linespc
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002174 .tf.histframe.pwclist add $canv2
2175 set canv3 .tf.histframe.pwclist.canv3
Mark Levedahl9ca72f42007-02-12 19:19:34 -05002176 canvas $canv3 \
Denton Liue2445882020-09-10 21:36:33 -07002177 -selectbackground $selectbgcolor \
2178 -background $bgcolor -bd 0 -yscrollincr $linespc
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002179 .tf.histframe.pwclist add $canv3
Pat Thoytsd93f1712009-04-17 01:24:35 +01002180 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002181 bind .tf.histframe.pwclist <Map> {
2182 bind %W <Map> {}
2183 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0]
2184 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0]
2185 }
Pat Thoytsd93f1712009-04-17 01:24:35 +01002186 } else {
Denton Liue2445882020-09-10 21:36:33 -07002187 eval .tf.histframe.pwclist sash place 0 $geometry(pwsash0)
2188 eval .tf.histframe.pwclist sash place 1 $geometry(pwsash1)
Pat Thoytsd93f1712009-04-17 01:24:35 +01002189 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00002190
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002191 # a scroll bar to rule them
Pat Thoytsd93f1712009-04-17 01:24:35 +01002192 ${NS}::scrollbar $cscroll -command {allcanvs yview}
2193 if {!$use_ttk} {$cscroll configure -highlightthickness 0}
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002194 pack $cscroll -side right -fill y
2195 bind .tf.histframe.pwclist <Configure> {resizeclistpanes %W %w}
2196 lappend bglist $canv $canv2 $canv3
2197 pack .tf.histframe.pwclist -fill both -expand 1 -side left
2198
2199 # we have two button bars at bottom of top frame. Bar 1
Pat Thoytsd93f1712009-04-17 01:24:35 +01002200 ${NS}::frame .tf.bar
2201 ${NS}::frame .tf.lbar -height 15
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002202
2203 set sha1entry .tf.bar.sha1
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002204 set entries $sha1entry
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002205 set sha1but .tf.bar.sha1label
Markus Heidelberg0359ba72010-01-09 23:11:12 +01002206 button $sha1but -text "[mc "SHA1 ID:"] " -state disabled -relief flat \
Denton Liue2445882020-09-10 21:36:33 -07002207 -command gotocommit -width 8
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002208 $sha1but conf -disabledforeground [$sha1but cget -foreground]
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002209 pack .tf.bar.sha1label -side left
Pat Thoytsd93f1712009-04-17 01:24:35 +01002210 ${NS}::entry $sha1entry -width 40 -font textfont -textvariable sha1string
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002211 trace add variable sha1string write sha1change
Paul Mackerras98f350e2005-05-15 05:56:51 +00002212 pack $sha1entry -side left -pady 2
Paul Mackerrasd6982062005-08-06 22:06:06 +10002213
Stefan Hallerf062e502012-09-22 09:46:48 +02002214 set bm_left_data {
Denton Liue2445882020-09-10 21:36:33 -07002215 #define left_width 16
2216 #define left_height 16
2217 static unsigned char left_bits[] = {
2218 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
2219 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
2220 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
Paul Mackerrasd6982062005-08-06 22:06:06 +10002221 }
Stefan Hallerf062e502012-09-22 09:46:48 +02002222 set bm_right_data {
Denton Liue2445882020-09-10 21:36:33 -07002223 #define right_width 16
2224 #define right_height 16
2225 static unsigned char right_bits[] = {
2226 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
2227 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
2228 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
Paul Mackerrasd6982062005-08-06 22:06:06 +10002229 }
Gauthier Östervall252c52d2013-03-27 14:40:51 +01002230 image create bitmap bm-left -data $bm_left_data -foreground $uifgcolor
2231 image create bitmap bm-left-gray -data $bm_left_data -foreground $uifgdisabledcolor
2232 image create bitmap bm-right -data $bm_right_data -foreground $uifgcolor
2233 image create bitmap bm-right-gray -data $bm_right_data -foreground $uifgdisabledcolor
Stefan Hallerf062e502012-09-22 09:46:48 +02002234
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002235 ${NS}::button .tf.bar.leftbut -command goback -state disabled -width 26
2236 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002237 .tf.bar.leftbut configure -image [list bm-left disabled bm-left-gray]
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002238 } else {
Denton Liue2445882020-09-10 21:36:33 -07002239 .tf.bar.leftbut configure -image bm-left
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002240 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002241 pack .tf.bar.leftbut -side left -fill y
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002242 ${NS}::button .tf.bar.rightbut -command goforw -state disabled -width 26
2243 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002244 .tf.bar.rightbut configure -image [list bm-right disabled bm-right-gray]
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002245 } else {
Denton Liue2445882020-09-10 21:36:33 -07002246 .tf.bar.rightbut configure -image bm-right
Marcus Karlsson62e9ac52012-10-07 23:21:14 +02002247 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002248 pack .tf.bar.rightbut -side left -fill y
Paul Mackerrasd6982062005-08-06 22:06:06 +10002249
Pat Thoytsd93f1712009-04-17 01:24:35 +01002250 ${NS}::label .tf.bar.rowlabel -text [mc "Row"]
Paul Mackerras6df74032008-05-11 22:13:02 +10002251 set rownumsel {}
Pat Thoytsd93f1712009-04-17 01:24:35 +01002252 ${NS}::label .tf.bar.rownum -width 7 -textvariable rownumsel \
Denton Liue2445882020-09-10 21:36:33 -07002253 -relief sunken -anchor e
Pat Thoytsd93f1712009-04-17 01:24:35 +01002254 ${NS}::label .tf.bar.rowlabel2 -text "/"
2255 ${NS}::label .tf.bar.numcommits -width 7 -textvariable numcommits \
Denton Liue2445882020-09-10 21:36:33 -07002256 -relief sunken -anchor e
Paul Mackerras6df74032008-05-11 22:13:02 +10002257 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \
Denton Liue2445882020-09-10 21:36:33 -07002258 -side left
Pat Thoytsd93f1712009-04-17 01:24:35 +01002259 if {!$use_ttk} {
2260 foreach w {rownum numcommits} {.tf.bar.$w configure -font textfont}
2261 }
Paul Mackerras6df74032008-05-11 22:13:02 +10002262 global selectedline
Paul Mackerras94b4a692008-05-20 20:51:06 +10002263 trace add variable selectedline write selectedline_change
Paul Mackerras6df74032008-05-11 22:13:02 +10002264
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002265 # Status label and progress bar
2266 set statusw .tf.bar.status
Pat Thoytsd93f1712009-04-17 01:24:35 +01002267 ${NS}::label $statusw -width 15 -relief sunken
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002268 pack $statusw -side left -padx 5
Pat Thoytsd93f1712009-04-17 01:24:35 +01002269 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002270 set progresscanv [ttk::progressbar .tf.bar.progress]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002271 } else {
Denton Liue2445882020-09-10 21:36:33 -07002272 set h [expr {[font metrics uifont -linespace] + 2}]
2273 set progresscanv .tf.bar.progress
2274 canvas $progresscanv -relief sunken -height $h -borderwidth 2
2275 set progressitem [$progresscanv create rect -1 0 0 $h -fill "#00ff00"]
2276 set fprogitem [$progresscanv create rect -1 0 0 $h -fill yellow]
2277 set rprogitem [$progresscanv create rect -1 0 0 $h -fill red]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002278 }
2279 pack $progresscanv -side right -expand 1 -fill x -padx {0 2}
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002280 set progresscoords {0 0}
2281 set fprogcoord 0
Paul Mackerrasa137a902007-10-23 21:12:49 +10002282 set rprogcoord 0
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002283 bind $progresscanv <Configure> adjustprogress
2284 set lastprogupdate [clock clicks -milliseconds]
2285 set progupdatepending 0
Paul Mackerrasb5721c72005-05-10 12:08:22 +00002286
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002287 # build up the bottom bar of upper window
Pat Thoytsd93f1712009-04-17 01:24:35 +01002288 ${NS}::label .tf.lbar.flabel -text "[mc "Find"] "
Marc Branchaud786f15c2013-12-18 11:04:13 -05002289
2290 set bm_down_data {
Denton Liue2445882020-09-10 21:36:33 -07002291 #define down_width 16
2292 #define down_height 16
2293 static unsigned char down_bits[] = {
2294 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2295 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2296 0x87, 0xe1, 0x8e, 0x71, 0x9c, 0x39, 0xb8, 0x1d,
2297 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01};
Marc Branchaud786f15c2013-12-18 11:04:13 -05002298 }
2299 image create bitmap bm-down -data $bm_down_data -foreground $uifgcolor
2300 ${NS}::button .tf.lbar.fnext -width 26 -command {dofind 1 1}
2301 .tf.lbar.fnext configure -image bm-down
2302
2303 set bm_up_data {
Denton Liue2445882020-09-10 21:36:33 -07002304 #define up_width 16
2305 #define up_height 16
2306 static unsigned char up_bits[] = {
2307 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
2308 0xb8, 0x1d, 0x9c, 0x39, 0x8e, 0x71, 0x87, 0xe1,
2309 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
2310 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01};
Marc Branchaud786f15c2013-12-18 11:04:13 -05002311 }
2312 image create bitmap bm-up -data $bm_up_data -foreground $uifgcolor
2313 ${NS}::button .tf.lbar.fprev -width 26 -command {dofind -1 1}
2314 .tf.lbar.fprev configure -image bm-up
2315
Pat Thoytsd93f1712009-04-17 01:24:35 +01002316 ${NS}::label .tf.lbar.flab2 -text " [mc "commit"] "
Marc Branchaud786f15c2013-12-18 11:04:13 -05002317
Paul Mackerras687c8762007-09-22 12:49:33 +10002318 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
Denton Liue2445882020-09-10 21:36:33 -07002319 -side left -fill y
Christian Stimmingb007ee22007-11-07 18:44:35 +01002320 set gdttype [mc "containing:"]
Pat Thoyts3cb1f9c2009-05-12 15:45:06 +01002321 set gm [makedroplist .tf.lbar.gdttype gdttype \
Denton Liue2445882020-09-10 21:36:33 -07002322 [mc "containing:"] \
2323 [mc "touching paths:"] \
2324 [mc "adding/removing string:"] \
2325 [mc "changing lines matching:"]]
Paul Mackerras687c8762007-09-22 12:49:33 +10002326 trace add variable gdttype write gdttype_change
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002327 pack .tf.lbar.gdttype -side left -fill y
Paul Mackerras687c8762007-09-22 12:49:33 +10002328
2329 set findstring {}
2330 set fstring .tf.lbar.findstring
2331 lappend entries $fstring
Mark Hillsb9b142f2010-01-13 20:40:22 +00002332 ${NS}::entry $fstring -width 30 -textvariable findstring
Paul Mackerras687c8762007-09-22 12:49:33 +10002333 trace add variable findstring write find_change
Christian Stimmingb007ee22007-11-07 18:44:35 +01002334 set findtype [mc "Exact"]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002335 set findtypemenu [makedroplist .tf.lbar.findtype \
Denton Liue2445882020-09-10 21:36:33 -07002336 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]]
Paul Mackerras687c8762007-09-22 12:49:33 +10002337 trace add variable findtype write findcom_change
Christian Stimmingb007ee22007-11-07 18:44:35 +01002338 set findloc [mc "All fields"]
Pat Thoytsd93f1712009-04-17 01:24:35 +01002339 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \
Denton Liue2445882020-09-10 21:36:33 -07002340 [mc "Comments"] [mc "Author"] [mc "Committer"]
Paul Mackerras687c8762007-09-22 12:49:33 +10002341 trace add variable findloc write find_change
Paul Mackerras687c8762007-09-22 12:49:33 +10002342 pack .tf.lbar.findloc -side right
2343 pack .tf.lbar.findtype -side right
2344 pack $fstring -side left -expand 1 -fill x
Paul Mackerras908c3582006-05-20 09:38:11 +10002345
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002346 # Finish putting the upper half of the viewer together
2347 pack .tf.lbar -in .tf -side bottom -fill x
2348 pack .tf.bar -in .tf -side bottom -fill x
2349 pack .tf.histframe -fill both -side top -expand 1
2350 .ctop add .tf
Pat Thoytsd93f1712009-04-17 01:24:35 +01002351 if {!$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002352 .ctop paneconfigure .tf -height $geometry(topheight)
2353 .ctop paneconfigure .tf -width $geometry(topwidth)
Pat Thoytsd93f1712009-04-17 01:24:35 +01002354 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002355
2356 # now build up the bottom
Pat Thoytsd93f1712009-04-17 01:24:35 +01002357 ${NS}::panedwindow .pwbottom -orient horizontal
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002358
2359 # lower left, a text box over search bar, scroll bar to the right
2360 # if we know window height, then that will set the lower text height, otherwise
2361 # we set lower text height which will drive window height
2362 if {[info exists geometry(main)]} {
Denton Liue2445882020-09-10 21:36:33 -07002363 ${NS}::frame .bleft -width $geometry(botwidth)
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002364 } else {
Denton Liue2445882020-09-10 21:36:33 -07002365 ${NS}::frame .bleft -width $geometry(botwidth) -height $geometry(botheight)
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002366 }
Pat Thoytsd93f1712009-04-17 01:24:35 +01002367 ${NS}::frame .bleft.top
2368 ${NS}::frame .bleft.mid
2369 ${NS}::frame .bleft.bottom
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002370
Giuseppe Bilottacae4b602015-12-08 08:05:51 +01002371 # gap between sub-widgets
2372 set wgap [font measure uifont "i"]
2373
Pat Thoytsd93f1712009-04-17 01:24:35 +01002374 ${NS}::button .bleft.top.search -text [mc "Search"] -command dosearch
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002375 pack .bleft.top.search -side left -padx 5
2376 set sstring .bleft.top.sstring
Pat Thoytsd93f1712009-04-17 01:24:35 +01002377 set searchstring ""
Mark Hillsb9b142f2010-01-13 20:40:22 +00002378 ${NS}::entry $sstring -width 20 -textvariable searchstring
Paul Mackerras3ea06f92006-05-24 10:16:03 +10002379 lappend entries $sstring
2380 trace add variable searchstring write incrsearch
2381 pack $sstring -side left -expand 1 -fill x
Pat Thoytsd93f1712009-04-17 01:24:35 +01002382 ${NS}::radiobutton .bleft.mid.diff -text [mc "Diff"] \
Denton Liue2445882020-09-10 21:36:33 -07002383 -command changediffdisp -variable diffelide -value {0 0}
Pat Thoytsd93f1712009-04-17 01:24:35 +01002384 ${NS}::radiobutton .bleft.mid.old -text [mc "Old version"] \
Denton Liue2445882020-09-10 21:36:33 -07002385 -command changediffdisp -variable diffelide -value {0 1}
Pat Thoytsd93f1712009-04-17 01:24:35 +01002386 ${NS}::radiobutton .bleft.mid.new -text [mc "New version"] \
Denton Liue2445882020-09-10 21:36:33 -07002387 -command changediffdisp -variable diffelide -value {1 0}
Giuseppe Bilottacae4b602015-12-08 08:05:51 +01002388
Pat Thoytsd93f1712009-04-17 01:24:35 +01002389 ${NS}::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: "
Giuseppe Bilottacae4b602015-12-08 08:05:51 +01002390 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap
Mark Hills0933b042010-01-13 20:40:19 +00002391 spinbox .bleft.mid.diffcontext -width 5 \
Denton Liue2445882020-09-10 21:36:33 -07002392 -from 0 -increment 1 -to 10000000 \
2393 -validate all -validatecommand "diffcontextvalidate %P" \
2394 -textvariable diffcontextstring
Steffen Prohaska890fae72007-08-12 12:05:46 +02002395 .bleft.mid.diffcontext set $diffcontext
2396 trace add variable diffcontextstring write diffcontextchange
2397 lappend entries .bleft.mid.diffcontext
Giuseppe Bilottacae4b602015-12-08 08:05:51 +01002398 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap
Pat Thoytsd93f1712009-04-17 01:24:35 +01002399 ${NS}::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \
Denton Liue2445882020-09-10 21:36:33 -07002400 -command changeignorespace -variable ignorespace
Steffen Prohaskab9b86002008-01-17 23:42:55 +01002401 pack .bleft.mid.ignspace -side left -padx 5
Thomas Rastae4e3ff2010-10-16 12:15:10 +02002402
2403 set worddiff [mc "Line diff"]
2404 if {[package vcompare $git_version "1.7.2"] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07002405 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \
2406 [mc "Markup words"] [mc "Color words"]
2407 trace add variable worddiff write changeworddiff
2408 pack .bleft.mid.worddiff -side left -padx 5
Thomas Rastae4e3ff2010-10-16 12:15:10 +02002409 }
2410
Pekka Kaitaniemi8809d692008-03-08 14:27:23 +02002411 set ctext .bleft.bottom.ctext
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +10002412 text $ctext -background $bgcolor -foreground $fgcolor \
Denton Liue2445882020-09-10 21:36:33 -07002413 -state disabled -undo 0 -font textfont \
2414 -yscrollcommand scrolltext -wrap none \
2415 -xscrollcommand ".bleft.bottom.sbhorizontal set"
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10002416 if {$have_tk85} {
Denton Liue2445882020-09-10 21:36:33 -07002417 $ctext conf -tabstyle wordprocessor
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10002418 }
Pat Thoytsd93f1712009-04-17 01:24:35 +01002419 ${NS}::scrollbar .bleft.bottom.sb -command "$ctext yview"
2420 ${NS}::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002421 pack .bleft.top -side top -fill x
Paul Mackerrasa8d610a2007-04-19 11:39:12 +10002422 pack .bleft.mid -side top -fill x
Pekka Kaitaniemi8809d692008-03-08 14:27:23 +02002423 grid $ctext .bleft.bottom.sb -sticky nsew
2424 grid .bleft.bottom.sbhorizontal -sticky ew
2425 grid columnconfigure .bleft.bottom 0 -weight 1
2426 grid rowconfigure .bleft.bottom 0 -weight 1
2427 grid rowconfigure .bleft.bottom 1 -weight 0
2428 pack .bleft.bottom -side top -fill both -expand 1
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +10002429 lappend bglist $ctext
2430 lappend fglist $ctext
Paul Mackerrasd2610d12005-05-11 00:45:38 +00002431
Sergey Vlasovf1b86292006-05-15 19:13:14 +04002432 $ctext tag conf comment -wrap $wrapcomment
Gauthier Östervall252c52d2013-03-27 14:40:51 +01002433 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +10002434 $ctext tag conf hunksep -fore [lindex $diffcolors 2]
2435 $ctext tag conf d0 -fore [lindex $diffcolors 0]
Stefan Dotterweich113ce122020-02-11 22:24:48 +01002436 $ctext tag conf d0 -back [lindex $diffbgcolors 0]
Paul Mackerras8b07dca2008-11-02 22:34:47 +11002437 $ctext tag conf dresult -fore [lindex $diffcolors 1]
Stefan Dotterweich113ce122020-02-11 22:24:48 +01002438 $ctext tag conf dresult -back [lindex $diffbgcolors 1]
Gauthier Östervall252c52d2013-03-27 14:40:51 +01002439 $ctext tag conf m0 -fore [lindex $mergecolors 0]
2440 $ctext tag conf m1 -fore [lindex $mergecolors 1]
2441 $ctext tag conf m2 -fore [lindex $mergecolors 2]
2442 $ctext tag conf m3 -fore [lindex $mergecolors 3]
2443 $ctext tag conf m4 -fore [lindex $mergecolors 4]
2444 $ctext tag conf m5 -fore [lindex $mergecolors 5]
2445 $ctext tag conf m6 -fore [lindex $mergecolors 6]
2446 $ctext tag conf m7 -fore [lindex $mergecolors 7]
2447 $ctext tag conf m8 -fore [lindex $mergecolors 8]
2448 $ctext tag conf m9 -fore [lindex $mergecolors 9]
2449 $ctext tag conf m10 -fore [lindex $mergecolors 10]
2450 $ctext tag conf m11 -fore [lindex $mergecolors 11]
2451 $ctext tag conf m12 -fore [lindex $mergecolors 12]
2452 $ctext tag conf m13 -fore [lindex $mergecolors 13]
2453 $ctext tag conf m14 -fore [lindex $mergecolors 14]
2454 $ctext tag conf m15 -fore [lindex $mergecolors 15]
Paul Mackerras712fcc02005-11-30 09:28:16 +11002455 $ctext tag conf mmax -fore darkgrey
Paul Mackerrasb77b0272006-02-07 09:13:52 +11002456 set mergemax 16
Paul Mackerras9c311b32007-10-04 22:27:13 +10002457 $ctext tag conf mresult -font textfontbold
2458 $ctext tag conf msep -font textfontbold
Gauthier Östervall252c52d2013-03-27 14:40:51 +01002459 $ctext tag conf found -back $foundbgcolor
2460 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor
Paul Mackerras76d64ca2014-01-23 22:06:22 +11002461 $ctext tag conf wwrap -wrap word -lmargin2 1c
Paul Mackerras4399fe32013-01-03 10:10:31 +11002462 $ctext tag conf bold -font textfontbold
Johannes Sixt2faa6cd2020-04-09 19:48:12 +02002463 # set these to the lowest priority:
2464 $ctext tag lower currentsearchhit
2465 $ctext tag lower found
2466 $ctext tag lower filesep
2467 $ctext tag lower dresult
2468 $ctext tag lower d0
Paul Mackerrase5c2d852005-05-11 23:44:54 +00002469
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002470 .pwbottom add .bleft
Pat Thoytsd93f1712009-04-17 01:24:35 +01002471 if {!$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002472 .pwbottom paneconfigure .bleft -width $geometry(botwidth)
Pat Thoytsd93f1712009-04-17 01:24:35 +01002473 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002474
2475 # lower right
Pat Thoytsd93f1712009-04-17 01:24:35 +01002476 ${NS}::frame .bright
2477 ${NS}::frame .bright.mode
2478 ${NS}::radiobutton .bright.mode.patch -text [mc "Patch"] \
Denton Liue2445882020-09-10 21:36:33 -07002479 -command reselectline -variable cmitmode -value "patch"
Pat Thoytsd93f1712009-04-17 01:24:35 +01002480 ${NS}::radiobutton .bright.mode.tree -text [mc "Tree"] \
Denton Liue2445882020-09-10 21:36:33 -07002481 -command reselectline -variable cmitmode -value "tree"
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002482 grid .bright.mode.patch .bright.mode.tree -sticky ew
2483 pack .bright.mode -side top -fill x
2484 set cflist .bright.cfiles
Paul Mackerras9c311b32007-10-04 22:27:13 +10002485 set indent [font measure mainfont "nn"]
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002486 text $cflist \
Denton Liue2445882020-09-10 21:36:33 -07002487 -selectbackground $selectbgcolor \
2488 -background $bgcolor -foreground $fgcolor \
2489 -font mainfont \
2490 -tabs [list $indent [expr {2 * $indent}]] \
2491 -yscrollcommand ".bright.sb set" \
2492 -cursor [. cget -cursor] \
2493 -spacing1 1 -spacing3 1
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +10002494 lappend bglist $cflist
2495 lappend fglist $cflist
Pat Thoytsd93f1712009-04-17 01:24:35 +01002496 ${NS}::scrollbar .bright.sb -command "$cflist yview"
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002497 pack .bright.sb -side right -fill y
Paul Mackerrasd2610d12005-05-11 00:45:38 +00002498 pack $cflist -side left -fill both -expand 1
Paul Mackerras89b11d32006-05-02 19:55:31 +10002499 $cflist tag configure highlight \
Denton Liue2445882020-09-10 21:36:33 -07002500 -background [$cflist cget -selectbackground]
Paul Mackerras9c311b32007-10-04 22:27:13 +10002501 $cflist tag configure bold -font mainfontbold
Paul Mackerrasd2610d12005-05-11 00:45:38 +00002502
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002503 .pwbottom add .bright
2504 .ctop add .pwbottom
Paul Mackerras1db95b02005-05-09 04:08:39 +00002505
Paul Mackerrasb9bee112008-03-10 16:50:34 +11002506 # restore window width & height if known
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002507 if {[info exists geometry(main)]} {
Denton Liue2445882020-09-10 21:36:33 -07002508 if {[scan $geometry(main) "%dx%d" w h] >= 2} {
2509 if {$w > [winfo screenwidth .]} {
2510 set w [winfo screenwidth .]
2511 }
2512 if {$h > [winfo screenheight .]} {
2513 set h [winfo screenheight .]
2514 }
2515 wm geometry . "${w}x$h"
2516 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002517 }
2518
Pat Thoytsc876dba2009-04-14 22:09:53 +01002519 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
2520 wm state . $geometry(state)
2521 }
2522
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002523 if {[tk windowingsystem] eq {aqua}} {
2524 set M1B M1
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002525 set ::BM "3"
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002526 } else {
2527 set M1B Control
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002528 set ::BM "2"
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002529 }
2530
Pat Thoytsd93f1712009-04-17 01:24:35 +01002531 if {$use_ttk} {
2532 bind .ctop <Map> {
2533 bind %W <Map> {}
2534 %W sashpos 0 $::geometry(topheight)
2535 }
2536 bind .pwbottom <Map> {
2537 bind %W <Map> {}
2538 %W sashpos 0 $::geometry(botwidth)
2539 }
Denton Liue2445882020-09-10 21:36:33 -07002540 bind .pwbottom <Configure> {resizecdetpanes %W %w}
Pat Thoytsd93f1712009-04-17 01:24:35 +01002541 }
2542
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002543 pack .ctop -fill both -expand 1
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10002544 bindall <1> {selcanvline %W %x %y}
2545 #bindall <B1-Motion> {selcanvline %W %x %y}
Mark Levedahl314c3092007-08-07 21:40:35 -04002546 if {[tk windowingsystem] == "win32"} {
Denton Liue2445882020-09-10 21:36:33 -07002547 bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2548 bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
Mark Levedahl314c3092007-08-07 21:40:35 -04002549 } else {
Denton Liue2445882020-09-10 21:36:33 -07002550 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2551 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
2552 bind $ctext <Button> {
2553 if {"%b" eq 6} {
2554 $ctext xview scroll -5 units
2555 } elseif {"%b" eq 7} {
2556 $ctext xview scroll 5 units
2557 }
2558 }
Jonathan del Strother5dd57d52007-10-15 10:33:07 +01002559 if {[tk windowingsystem] eq "aqua"} {
2560 bindall <MouseWheel> {
2561 set delta [expr {- (%D)}]
2562 allcanvs yview scroll $delta units
2563 }
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002564 bindall <Shift-MouseWheel> {
2565 set delta [expr {- (%D)}]
2566 $canv xview scroll $delta units
2567 }
Jonathan del Strother5dd57d52007-10-15 10:33:07 +01002568 }
Mark Levedahl314c3092007-08-07 21:40:35 -04002569 }
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +01002570 bindall <$::BM> "canvscan mark %W %x %y"
2571 bindall <B$::BM-Motion> "canvscan dragto %W %x %y"
Jens Lehmanndecd0a12010-02-02 23:11:28 +01002572 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2573 bind . <$M1B-Key-w> doquit
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10002574 bindkey <Home> selfirstline
2575 bindkey <End> sellastline
Paul Mackerras17386062005-05-18 22:51:00 +00002576 bind . <Key-Up> "selnextline -1"
2577 bind . <Key-Down> "selnextline 1"
Paul Mackerrascca5d942007-10-27 21:16:56 +10002578 bind . <Shift-Key-Up> "dofind -1 0"
2579 bind . <Shift-Key-Down> "dofind 1 0"
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10002580 bindkey <Key-Right> "goforw"
2581 bindkey <Key-Left> "goback"
2582 bind . <Key-Prior> "selnextpage -1"
2583 bind . <Key-Next> "selnextpage 1"
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002584 bind . <$M1B-Home> "allcanvs yview moveto 0.0"
2585 bind . <$M1B-End> "allcanvs yview moveto 1.0"
2586 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units"
2587 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units"
2588 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages"
2589 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages"
Paul Mackerrascfb45632005-05-31 12:14:42 +00002590 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
2591 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
2592 bindkey <Key-space> "$ctext yview scroll 1 pages"
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002593 bindkey p "selnextline -1"
2594 bindkey n "selnextline 1"
Robert Suetterlin6e2dda32005-09-22 10:07:36 +10002595 bindkey z "goback"
2596 bindkey x "goforw"
Jonathan Nieder811c70f2011-09-19 11:49:50 -05002597 bindkey k "selnextline -1"
2598 bindkey j "selnextline 1"
2599 bindkey h "goback"
Robert Suetterlin6e2dda32005-09-22 10:07:36 +10002600 bindkey l "goforw"
Paul Mackerrasf4c54b32008-05-10 13:15:36 +10002601 bindkey b prevfile
Paul Mackerrascfb45632005-05-31 12:14:42 +00002602 bindkey d "$ctext yview scroll 18 units"
2603 bindkey u "$ctext yview scroll -18 units"
Ismael Luceno0deb5c92015-04-15 13:18:17 -03002604 bindkey g {$sha1entry delete 0 end; focus $sha1entry}
Giuseppe Bilotta97bed032008-12-02 02:19:22 +01002605 bindkey / {focus $fstring}
Michele Ballabiob6e192d2009-03-30 14:55:21 +02002606 bindkey <Key-KP_Divide> {focus $fstring}
Paul Mackerrascca5d942007-10-27 21:16:56 +10002607 bindkey <Key-Return> {dofind 1 1}
2608 bindkey ? {dofind -1 1}
Paul Mackerras39ad8572005-05-19 12:35:53 +00002609 bindkey f nextfile
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03002610 bind . <F5> updatecommits
Andrew Wongebb91db2012-10-02 11:04:45 -04002611 bindmodfunctionkey Shift 5 reloadcommits
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03002612 bind . <F2> showrefs
Andrew Wong69ecfcd2012-10-02 11:04:44 -04002613 bindmodfunctionkey Shift 4 {newview 0}
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03002614 bind . <F4> edit_or_newview
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002615 bind . <$M1B-q> doquit
Paul Mackerrascca5d942007-10-27 21:16:56 +10002616 bind . <$M1B-f> {dofind 1 1}
2617 bind . <$M1B-g> {dofind 1 0}
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002618 bind . <$M1B-r> dosearchback
2619 bind . <$M1B-s> dosearch
2620 bind . <$M1B-equal> {incrfont 1}
Johannes Schindelin646f3a12008-01-11 12:39:33 +00002621 bind . <$M1B-plus> {incrfont 1}
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04002622 bind . <$M1B-KP_Add> {incrfont 1}
2623 bind . <$M1B-minus> {incrfont -1}
2624 bind . <$M1B-KP_Subtract> {incrfont -1}
Mark Levedahlb6047c52007-02-08 22:22:24 -05002625 wm protocol . WM_DELETE_WINDOW doquit
Alexander Gavrilove2f90ee2008-07-12 16:09:28 +04002626 bind . <Destroy> {stop_backends}
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002627 bind . <Button-1> "click %W"
Paul Mackerrascca5d942007-10-27 21:16:56 +10002628 bind $fstring <Key-Return> {dofind 1 1}
Paul Mackerras968ce452008-10-16 09:57:02 +11002629 bind $sha1entry <Key-Return> {gotocommit; break}
Paul Mackerrasee3dc722005-06-25 16:37:13 +10002630 bind $sha1entry <<PasteSelection>> clearsha1
Ilya Bobyrada2ea12014-03-20 01:58:51 -07002631 bind $sha1entry <<Paste>> clearsha1
Paul Mackerras7fcceed2006-04-27 19:21:49 +10002632 bind $cflist <1> {sel_flist %W %x %y; break}
2633 bind $cflist <B1-Motion> {sel_flist %W %x %y; break}
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10002634 bind $cflist <ButtonRelease-1> {treeclick %W %x %y}
Paul Mackerrasd277e892008-09-21 18:11:37 -05002635 global ctxbut
2636 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04002637 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
Stefan Haller4adcbea2010-11-14 13:22:56 +01002638 bind $ctext <Button-1> {focus %W}
Stefan Hallerc4614992012-09-22 09:40:24 +02002639 bind $ctext <<Selection>> rehighlight_search_results
Max Kirillovd4ec30b2014-07-08 23:45:35 +03002640 for {set i 1} {$i < 10} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07002641 bind . <$M1B-Key-$i> [list go_to_parent $i]
Max Kirillovd4ec30b2014-07-08 23:45:35 +03002642 }
Paul Mackerrasea13cba2005-06-16 10:54:04 +00002643
2644 set maincursor [. cget -cursor]
2645 set textcursor [$ctext cget -cursor]
Paul Mackerras94a2eed2005-08-07 15:27:57 +10002646 set curtextcursor $textcursor
Paul Mackerras84ba7342005-06-17 00:12:26 +00002647
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10002648 set rowctxmenu .rowctxmenu
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002649 makemenu $rowctxmenu {
Denton Liue2445882020-09-10 21:36:33 -07002650 {mc "Diff this -> selected" command {diffvssel 0}}
2651 {mc "Diff selected -> this" command {diffvssel 1}}
2652 {mc "Make patch" command mkpatch}
2653 {mc "Create tag" command mktag}
2654 {mc "Copy commit reference" command copyreference}
2655 {mc "Write commit to file" command writecommit}
2656 {mc "Create new branch" command mkbranch}
2657 {mc "Cherry-pick this commit" command cherrypick}
2658 {mc "Reset HEAD branch to here" command resethead}
2659 {mc "Mark this commit" command markhere}
2660 {mc "Return to mark" command gotomark}
2661 {mc "Find descendant of this and mark" command find_common_desc}
2662 {mc "Compare with marked commit" command compare_commits}
2663 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2664 {mc "Diff marked commit -> this" command {diffvsmark 1}}
2665 {mc "Revert this commit" command revert}
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002666 }
2667 $rowctxmenu configure -tearoff 0
Paul Mackerras10299152006-08-02 09:52:01 +10002668
Paul Mackerras219ea3a2006-09-07 10:21:39 +10002669 set fakerowmenu .fakerowmenu
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002670 makemenu $fakerowmenu {
Denton Liue2445882020-09-10 21:36:33 -07002671 {mc "Diff this -> selected" command {diffvssel 0}}
2672 {mc "Diff selected -> this" command {diffvssel 1}}
2673 {mc "Make patch" command mkpatch}
2674 {mc "Diff this -> marked commit" command {diffvsmark 0}}
2675 {mc "Diff marked commit -> this" command {diffvsmark 1}}
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002676 }
2677 $fakerowmenu configure -tearoff 0
Paul Mackerras219ea3a2006-09-07 10:21:39 +10002678
Paul Mackerras10299152006-08-02 09:52:01 +10002679 set headctxmenu .headctxmenu
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002680 makemenu $headctxmenu {
Denton Liue2445882020-09-10 21:36:33 -07002681 {mc "Check out this branch" command cobranch}
2682 {mc "Rename this branch" command mvbranch}
2683 {mc "Remove this branch" command rmbranch}
2684 {mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002685 }
2686 $headctxmenu configure -tearoff 0
Paul Mackerras32447292007-07-27 22:30:15 +10002687
2688 global flist_menu
2689 set flist_menu .flistctxmenu
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002690 makemenu $flist_menu {
Denton Liue2445882020-09-10 21:36:33 -07002691 {mc "Highlight this too" command {flist_hl 0}}
2692 {mc "Highlight this only" command {flist_hl 1}}
2693 {mc "External diff" command {external_diff}}
2694 {mc "Blame parent commit" command {external_blame 1}}
2695 {mc "Copy path" command {clipboard clear; clipboard append $flist_menu_file}}
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11002696 }
2697 $flist_menu configure -tearoff 0
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04002698
2699 global diff_menu
2700 set diff_menu .diffctxmenu
2701 makemenu $diff_menu {
Denton Liue2445882020-09-10 21:36:33 -07002702 {mc "Show origin of this line" command show_line_source}
2703 {mc "Run git gui blame on this line" command {external_blame_diff}}
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04002704 }
2705 $diff_menu configure -tearoff 0
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002706}
2707
Mark Levedahl314c3092007-08-07 21:40:35 -04002708# Windows sends all mouse wheel events to the current focused window, not
2709# the one where the mouse hovers, so bind those events here and redirect
2710# to the correct window
2711proc windows_mousewheel_redirector {W X Y D} {
2712 global canv canv2 canv3
2713 set w [winfo containing -displayof $W $X $Y]
2714 if {$w ne ""} {
Denton Liue2445882020-09-10 21:36:33 -07002715 set u [expr {$D < 0 ? 5 : -5}]
2716 if {$w == $canv || $w == $canv2 || $w == $canv3} {
2717 allcanvs yview scroll $u units
2718 } else {
2719 catch {
2720 $w yview scroll $u units
2721 }
2722 }
Mark Levedahl314c3092007-08-07 21:40:35 -04002723 }
2724}
2725
Paul Mackerras6df74032008-05-11 22:13:02 +10002726# Update row number label when selectedline changes
2727proc selectedline_change {n1 n2 op} {
2728 global selectedline rownumsel
2729
Paul Mackerras94b4a692008-05-20 20:51:06 +10002730 if {$selectedline eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07002731 set rownumsel {}
Paul Mackerras6df74032008-05-11 22:13:02 +10002732 } else {
Denton Liue2445882020-09-10 21:36:33 -07002733 set rownumsel [expr {$selectedline + 1}]
Paul Mackerras6df74032008-05-11 22:13:02 +10002734 }
2735}
2736
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11002737# mouse-2 makes all windows scan vertically, but only the one
2738# the cursor is in scans horizontally
2739proc canvscan {op w x y} {
2740 global canv canv2 canv3
2741 foreach c [list $canv $canv2 $canv3] {
Denton Liue2445882020-09-10 21:36:33 -07002742 if {$c == $w} {
2743 $c scan $op $x $y
2744 } else {
2745 $c scan $op 0 $y
2746 }
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11002747 }
2748}
2749
Paul Mackerras9f1afe02006-02-19 22:44:47 +11002750proc scrollcanv {cscroll f0 f1} {
2751 $cscroll set $f0 $f1
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11002752 drawvisible
Paul Mackerras908c3582006-05-20 09:38:11 +10002753 flushhighlights
Paul Mackerras9f1afe02006-02-19 22:44:47 +11002754}
2755
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002756# when we make a key binding for the toplevel, make sure
2757# it doesn't get triggered when that key is pressed in the
2758# find string entry widget.
2759proc bindkey {ev script} {
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002760 global entries
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002761 bind . $ev $script
2762 set escript [bind Entry $ev]
2763 if {$escript == {}} {
Denton Liue2445882020-09-10 21:36:33 -07002764 set escript [bind Entry <Key>]
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002765 }
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002766 foreach e $entries {
Denton Liue2445882020-09-10 21:36:33 -07002767 bind $e $ev "$escript; break"
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002768 }
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002769}
2770
Andrew Wong69ecfcd2012-10-02 11:04:44 -04002771proc bindmodfunctionkey {mod n script} {
2772 bind . <$mod-F$n> $script
2773 catch { bind . <$mod-XF86_Switch_VT_$n> $script }
2774}
2775
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002776# set the focus back to the toplevel for any click outside
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002777# the entry widgets
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002778proc click {w} {
Mark Levedahlbd441de2007-08-07 21:40:34 -04002779 global ctext entries
2780 foreach e [concat $entries $ctext] {
Denton Liue2445882020-09-10 21:36:33 -07002781 if {$w == $e} return
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002782 }
Paul Mackerras887fe3c2005-05-21 07:35:37 +00002783 focus .
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002784}
2785
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002786# Adjust the progress bar for a change in requested extent or canvas size
2787proc adjustprogress {} {
2788 global progresscanv progressitem progresscoords
2789 global fprogitem fprogcoord lastprogupdate progupdatepending
Pat Thoytsd93f1712009-04-17 01:24:35 +01002790 global rprogitem rprogcoord use_ttk
2791
2792 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002793 $progresscanv configure -value [expr {int($fprogcoord * 100)}]
2794 return
Pat Thoytsd93f1712009-04-17 01:24:35 +01002795 }
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002796
2797 set w [expr {[winfo width $progresscanv] - 4}]
2798 set x0 [expr {$w * [lindex $progresscoords 0]}]
2799 set x1 [expr {$w * [lindex $progresscoords 1]}]
2800 set h [winfo height $progresscanv]
2801 $progresscanv coords $progressitem $x0 0 $x1 $h
2802 $progresscanv coords $fprogitem 0 0 [expr {$w * $fprogcoord}] $h
Paul Mackerrasa137a902007-10-23 21:12:49 +10002803 $progresscanv coords $rprogitem 0 0 [expr {$w * $rprogcoord}] $h
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002804 set now [clock clicks -milliseconds]
2805 if {$now >= $lastprogupdate + 100} {
Denton Liue2445882020-09-10 21:36:33 -07002806 set progupdatepending 0
2807 update
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002808 } elseif {!$progupdatepending} {
Denton Liue2445882020-09-10 21:36:33 -07002809 set progupdatepending 1
2810 after [expr {$lastprogupdate + 100 - $now}] doprogupdate
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002811 }
2812}
2813
2814proc doprogupdate {} {
2815 global lastprogupdate progupdatepending
2816
2817 if {$progupdatepending} {
Denton Liue2445882020-09-10 21:36:33 -07002818 set progupdatepending 0
2819 set lastprogupdate [clock clicks -milliseconds]
2820 update
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10002821 }
2822}
2823
Max Kirilloveaf7e832015-03-04 05:58:18 +02002824proc config_check_tmp_exists {tries_left} {
2825 global config_file_tmp
2826
2827 if {[file exists $config_file_tmp]} {
Denton Liue2445882020-09-10 21:36:33 -07002828 incr tries_left -1
2829 if {$tries_left > 0} {
2830 after 100 [list config_check_tmp_exists $tries_left]
2831 } else {
2832 error_popup "There appears to be a stale $config_file_tmp\
Max Kirilloveaf7e832015-03-04 05:58:18 +02002833 file, which will prevent gitk from saving its configuration on exit.\
2834 Please remove it if it is not being used by any existing gitk process."
Denton Liue2445882020-09-10 21:36:33 -07002835 }
Max Kirilloveaf7e832015-03-04 05:58:18 +02002836 }
2837}
2838
Max Kirillov995f7922015-03-04 05:58:16 +02002839proc config_init_trace {name} {
2840 global config_variable_changed config_variable_original
2841
2842 upvar #0 $name var
2843 set config_variable_changed($name) 0
2844 set config_variable_original($name) $var
2845}
2846
2847proc config_variable_change_cb {name name2 op} {
2848 global config_variable_changed config_variable_original
2849
2850 upvar #0 $name var
2851 if {$op eq "write" &&
Denton Liue2445882020-09-10 21:36:33 -07002852 (![info exists config_variable_original($name)] ||
2853 $config_variable_original($name) ne $var)} {
2854 set config_variable_changed($name) 1
Max Kirillov995f7922015-03-04 05:58:16 +02002855 }
2856}
2857
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002858proc savestuff {w} {
Max Kirillov9fabefb2014-09-14 23:35:57 +03002859 global stuffsaved
Astril Hayato8f863392014-01-21 19:10:16 +00002860 global config_file config_file_tmp
Max Kirillov995f7922015-03-04 05:58:16 +02002861 global config_variables config_variable_changed
2862 global viewchanged
2863
2864 upvar #0 viewname current_viewname
2865 upvar #0 viewfiles current_viewfiles
2866 upvar #0 viewargs current_viewargs
2867 upvar #0 viewargscmd current_viewargscmd
2868 upvar #0 viewperm current_viewperm
2869 upvar #0 nextviewnum current_nextviewnum
2870 upvar #0 use_ttk current_use_ttk
Paul Mackerras4ef17532005-07-27 22:16:51 -05002871
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002872 if {$stuffsaved} return
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00002873 if {![winfo viewable .]} return
Max Kirilloveaf7e832015-03-04 05:58:18 +02002874 set remove_tmp 0
Max Kirillov1dd29602015-03-04 05:58:17 +02002875 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07002876 set try_count 0
2877 while {[catch {set f [open $config_file_tmp {WRONLY CREAT EXCL}]}]} {
2878 if {[incr try_count] > 50} {
2879 error "Unable to write config file: $config_file_tmp exists"
2880 }
2881 after 100
2882 }
2883 set remove_tmp 1
2884 if {$::tcl_platform(platform) eq {windows}} {
2885 file attributes $config_file_tmp -hidden true
2886 }
2887 if {[file exists $config_file]} {
2888 source $config_file
2889 }
2890 foreach var_name $config_variables {
2891 upvar #0 $var_name var
2892 upvar 0 $var_name old_var
2893 if {!$config_variable_changed($var_name) && [info exists old_var]} {
2894 puts $f [list set $var_name $old_var]
2895 } else {
2896 puts $f [list set $var_name $var]
2897 }
2898 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002899
Denton Liue2445882020-09-10 21:36:33 -07002900 puts $f "set geometry(main) [wm geometry .]"
2901 puts $f "set geometry(state) [wm state .]"
2902 puts $f "set geometry(topwidth) [winfo width .tf]"
2903 puts $f "set geometry(topheight) [winfo height .tf]"
2904 if {$current_use_ttk} {
2905 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\""
2906 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\""
2907 } else {
2908 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sash coord 0]\""
2909 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sash coord 1]\""
2910 }
2911 puts $f "set geometry(botwidth) [winfo width .bleft]"
2912 puts $f "set geometry(botheight) [winfo height .bleft]"
Junio C Hamanoe9937d22007-02-01 08:46:38 -05002913
Denton Liue2445882020-09-10 21:36:33 -07002914 array set view_save {}
2915 array set views {}
2916 if {![info exists permviews]} { set permviews {} }
2917 foreach view $permviews {
2918 set view_save([lindex $view 0]) 1
2919 set views([lindex $view 0]) $view
2920 }
2921 puts -nonewline $f "set permviews {"
2922 for {set v 1} {$v < $current_nextviewnum} {incr v} {
2923 if {$viewchanged($v)} {
2924 if {$current_viewperm($v)} {
2925 set views($current_viewname($v)) [list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)]
2926 } else {
2927 set view_save($current_viewname($v)) 0
2928 }
2929 }
2930 }
2931 # write old and updated view to their places and append remaining to the end
2932 foreach view $permviews {
2933 set view_name [lindex $view 0]
2934 if {$view_save($view_name)} {
2935 puts $f "{$views($view_name)}"
2936 }
2937 unset views($view_name)
2938 }
2939 foreach view_name [array names views] {
2940 puts $f "{$views($view_name)}"
2941 }
2942 puts $f "}"
2943 close $f
2944 file rename -force $config_file_tmp $config_file
2945 set remove_tmp 0
Max Kirillov1dd29602015-03-04 05:58:17 +02002946 } err]} {
2947 puts "Error saving config: $err"
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002948 }
Max Kirilloveaf7e832015-03-04 05:58:18 +02002949 if {$remove_tmp} {
Denton Liue2445882020-09-10 21:36:33 -07002950 file delete -force $config_file_tmp
Max Kirilloveaf7e832015-03-04 05:58:18 +02002951 }
Paul Mackerras0fba86b2005-05-16 23:54:58 +00002952 set stuffsaved 1
Paul Mackerras1db95b02005-05-09 04:08:39 +00002953}
2954
Paul Mackerras43bddeb2005-05-15 23:19:18 +00002955proc resizeclistpanes {win w} {
Paul Mackerras6cd80492020-10-03 15:20:33 +10002956 global oldwidth oldsash use_ttk
Paul Mackerras418c4c72006-02-07 09:10:18 +11002957 if {[info exists oldwidth($win)]} {
Paul Mackerras6cd80492020-10-03 15:20:33 +10002958 if {[info exists oldsash($win)]} {
2959 set s0 [lindex $oldsash($win) 0]
2960 set s1 [lindex $oldsash($win) 1]
2961 } elseif {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07002962 set s0 [$win sashpos 0]
2963 set s1 [$win sashpos 1]
2964 } else {
2965 set s0 [$win sash coord 0]
2966 set s1 [$win sash coord 1]
2967 }
2968 if {$w < 60} {
2969 set sash0 [expr {int($w/2 - 2)}]
2970 set sash1 [expr {int($w*5/6 - 2)}]
2971 } else {
2972 set factor [expr {1.0 * $w / $oldwidth($win)}]
2973 set sash0 [expr {int($factor * [lindex $s0 0])}]
2974 set sash1 [expr {int($factor * [lindex $s1 0])}]
2975 if {$sash0 < 30} {
2976 set sash0 30
2977 }
2978 if {$sash1 < $sash0 + 20} {
2979 set sash1 [expr {$sash0 + 20}]
2980 }
2981 if {$sash1 > $w - 10} {
2982 set sash1 [expr {$w - 10}]
2983 if {$sash0 > $sash1 - 20} {
2984 set sash0 [expr {$sash1 - 20}]
2985 }
2986 }
2987 }
2988 if {$use_ttk} {
2989 $win sashpos 0 $sash0
2990 $win sashpos 1 $sash1
2991 } else {
2992 $win sash place 0 $sash0 [lindex $s0 1]
2993 $win sash place 1 $sash1 [lindex $s1 1]
2994 }
Paul Mackerras6cd80492020-10-03 15:20:33 +10002995 set oldsash($win) [list $sash0 $sash1]
Paul Mackerras43bddeb2005-05-15 23:19:18 +00002996 }
2997 set oldwidth($win) $w
2998}
2999
3000proc resizecdetpanes {win w} {
Paul Mackerras6cd80492020-10-03 15:20:33 +10003001 global oldwidth oldsash use_ttk
Paul Mackerras418c4c72006-02-07 09:10:18 +11003002 if {[info exists oldwidth($win)]} {
Paul Mackerras6cd80492020-10-03 15:20:33 +10003003 if {[info exists oldsash($win)]} {
3004 set s0 $oldsash($win)
3005 } elseif {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07003006 set s0 [$win sashpos 0]
3007 } else {
3008 set s0 [$win sash coord 0]
3009 }
3010 if {$w < 60} {
3011 set sash0 [expr {int($w*3/4 - 2)}]
3012 } else {
3013 set factor [expr {1.0 * $w / $oldwidth($win)}]
3014 set sash0 [expr {int($factor * [lindex $s0 0])}]
3015 if {$sash0 < 45} {
3016 set sash0 45
3017 }
3018 if {$sash0 > $w - 15} {
3019 set sash0 [expr {$w - 15}]
3020 }
3021 }
3022 if {$use_ttk} {
3023 $win sashpos 0 $sash0
3024 } else {
3025 $win sash place 0 $sash0 [lindex $s0 1]
3026 }
Paul Mackerras6cd80492020-10-03 15:20:33 +10003027 set oldsash($win) $sash0
Paul Mackerras43bddeb2005-05-15 23:19:18 +00003028 }
3029 set oldwidth($win) $w
3030}
3031
Paul Mackerrasb5721c72005-05-10 12:08:22 +00003032proc allcanvs args {
3033 global canv canv2 canv3
3034 eval $canv $args
3035 eval $canv2 $args
3036 eval $canv3 $args
3037}
3038
3039proc bindall {event action} {
3040 global canv canv2 canv3
3041 bind $canv $event $action
3042 bind $canv2 $event $action
3043 bind $canv3 $event $action
3044}
3045
Paul Mackerras9a40c502005-05-12 23:46:16 +00003046proc about {} {
Guillermo S. Romero22a713c2016-02-04 03:32:19 +01003047 global bgcolor NS
Paul Mackerras9a40c502005-05-12 23:46:16 +00003048 set w .about
3049 if {[winfo exists $w]} {
Denton Liue2445882020-09-10 21:36:33 -07003050 raise $w
3051 return
Paul Mackerras9a40c502005-05-12 23:46:16 +00003052 }
Pat Thoytsd93f1712009-04-17 01:24:35 +01003053 ttk_toplevel $w
Christian Stimmingd990ced2007-11-07 18:42:55 +01003054 wm title $w [mc "About gitk"]
Alexander Gavrilove7d64002008-11-11 23:55:42 +03003055 make_transient $w .
Christian Stimmingd990ced2007-11-07 18:42:55 +01003056 message $w.m -text [mc "
Paul Mackerras9f1afe02006-02-19 22:44:47 +11003057Gitk - a commit viewer for git
Paul Mackerras9a40c502005-05-12 23:46:16 +00003058
Paul Mackerrasfbf42642016-12-12 20:46:42 +11003059Copyright \u00a9 2005-2016 Paul Mackerras
Paul Mackerras9a40c502005-05-12 23:46:16 +00003060
Christian Stimmingd990ced2007-11-07 18:42:55 +01003061Use and redistribute under the terms of the GNU General Public License"] \
Denton Liue2445882020-09-10 21:36:33 -07003062 -justify center -aspect 400 -border 2 -bg $bgcolor -relief groove
Eygene Ryabinkin3a950e92007-03-27 14:36:59 +04003063 pack $w.m -side top -fill x -padx 2 -pady 2
Pat Thoytsd93f1712009-04-17 01:24:35 +01003064 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
Paul Mackerras9a40c502005-05-12 23:46:16 +00003065 pack $w.ok -side bottom
Eygene Ryabinkin3a950e92007-03-27 14:36:59 +04003066 bind $w <Visibility> "focus $w.ok"
3067 bind $w <Key-Escape> "destroy $w"
3068 bind $w <Key-Return> "destroy $w"
Pat Thoytsd93f1712009-04-17 01:24:35 +01003069 tk::PlaceWindow $w widget .
Paul Mackerras9a40c502005-05-12 23:46:16 +00003070}
3071
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003072proc keys {} {
Guillermo S. Romero22a713c2016-02-04 03:32:19 +01003073 global bgcolor NS
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003074 set w .keys
3075 if {[winfo exists $w]} {
Denton Liue2445882020-09-10 21:36:33 -07003076 raise $w
3077 return
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003078 }
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04003079 if {[tk windowingsystem] eq {aqua}} {
Denton Liue2445882020-09-10 21:36:33 -07003080 set M1T Cmd
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04003081 } else {
Denton Liue2445882020-09-10 21:36:33 -07003082 set M1T Ctrl
Shawn O. Pearced23d98d2007-07-19 00:37:58 -04003083 }
Pat Thoytsd93f1712009-04-17 01:24:35 +01003084 ttk_toplevel $w
Christian Stimmingd990ced2007-11-07 18:42:55 +01003085 wm title $w [mc "Gitk key bindings"]
Alexander Gavrilove7d64002008-11-11 23:55:42 +03003086 make_transient $w .
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003087 message $w.m -text "
3088[mc "Gitk key bindings:"]
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003089
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003090[mc "<%s-Q> Quit" $M1T]
Jens Lehmanndecd0a12010-02-02 23:11:28 +01003091[mc "<%s-W> Close window" $M1T]
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003092[mc "<Home> Move to first commit"]
3093[mc "<End> Move to last commit"]
Jonathan Nieder811c70f2011-09-19 11:49:50 -05003094[mc "<Up>, p, k Move up one commit"]
3095[mc "<Down>, n, j Move down one commit"]
3096[mc "<Left>, z, h Go back in history list"]
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003097[mc "<Right>, x, l Go forward in history list"]
Max Kirillovd4ec30b2014-07-08 23:45:35 +03003098[mc "<%s-n> Go to n-th parent of current commit in history list" $M1T]
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003099[mc "<PageUp> Move up one page in commit list"]
3100[mc "<PageDown> Move down one page in commit list"]
3101[mc "<%s-Home> Scroll to top of commit list" $M1T]
3102[mc "<%s-End> Scroll to bottom of commit list" $M1T]
3103[mc "<%s-Up> Scroll commit list up one line" $M1T]
3104[mc "<%s-Down> Scroll commit list down one line" $M1T]
3105[mc "<%s-PageUp> Scroll commit list up one page" $M1T]
3106[mc "<%s-PageDown> Scroll commit list down one page" $M1T]
3107[mc "<Shift-Up> Find backwards (upwards, later commits)"]
3108[mc "<Shift-Down> Find forwards (downwards, earlier commits)"]
3109[mc "<Delete>, b Scroll diff view up one page"]
3110[mc "<Backspace> Scroll diff view up one page"]
3111[mc "<Space> Scroll diff view down one page"]
3112[mc "u Scroll diff view up 18 lines"]
3113[mc "d Scroll diff view down 18 lines"]
3114[mc "<%s-F> Find" $M1T]
3115[mc "<%s-G> Move to next find hit" $M1T]
3116[mc "<Return> Move to next find hit"]
Ismael Luceno0deb5c92015-04-15 13:18:17 -03003117[mc "g Go to commit"]
Giuseppe Bilotta97bed032008-12-02 02:19:22 +01003118[mc "/ Focus the search box"]
Michele Ballabio3d2c9982008-01-15 23:31:49 +01003119[mc "? Move to previous find hit"]
3120[mc "f Scroll diff view to next file"]
3121[mc "<%s-S> Search for next hit in diff view" $M1T]
3122[mc "<%s-R> Search for previous hit in diff view" $M1T]
3123[mc "<%s-KP+> Increase font size" $M1T]
3124[mc "<%s-plus> Increase font size" $M1T]
3125[mc "<%s-KP-> Decrease font size" $M1T]
3126[mc "<%s-minus> Decrease font size" $M1T]
3127[mc "<F5> Update"]
3128" \
Denton Liue2445882020-09-10 21:36:33 -07003129 -justify left -bg $bgcolor -border 2 -relief groove
Eygene Ryabinkin3a950e92007-03-27 14:36:59 +04003130 pack $w.m -side top -fill both -padx 2 -pady 2
Pat Thoytsd93f1712009-04-17 01:24:35 +01003131 ${NS}::button $w.ok -text [mc "Close"] -command "destroy $w" -default active
Alexander Gavrilov76f15942008-11-02 21:59:44 +03003132 bind $w <Key-Escape> [list destroy $w]
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003133 pack $w.ok -side bottom
Eygene Ryabinkin3a950e92007-03-27 14:36:59 +04003134 bind $w <Visibility> "focus $w.ok"
3135 bind $w <Key-Escape> "destroy $w"
3136 bind $w <Key-Return> "destroy $w"
Paul Mackerras4e95e1f2006-04-05 09:39:51 +10003137}
3138
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003139# Procedures for manipulating the file list window at the
3140# bottom right of the overall window.
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003141
3142proc treeview {w l openlevs} {
3143 global treecontents treediropen treeheight treeparent treeindex
3144
3145 set ix 0
3146 set treeindex() 0
3147 set lev 0
3148 set prefix {}
3149 set prefixend -1
3150 set prefendstack {}
3151 set htstack {}
3152 set ht 0
3153 set treecontents() {}
3154 $w conf -state normal
3155 foreach f $l {
Denton Liue2445882020-09-10 21:36:33 -07003156 while {[string range $f 0 $prefixend] ne $prefix} {
3157 if {$lev <= $openlevs} {
3158 $w mark set e:$treeindex($prefix) "end -1c"
3159 $w mark gravity e:$treeindex($prefix) left
3160 }
3161 set treeheight($prefix) $ht
3162 incr ht [lindex $htstack end]
3163 set htstack [lreplace $htstack end end]
3164 set prefixend [lindex $prefendstack end]
3165 set prefendstack [lreplace $prefendstack end end]
3166 set prefix [string range $prefix 0 $prefixend]
3167 incr lev -1
3168 }
3169 set tail [string range $f [expr {$prefixend+1}] end]
3170 while {[set slash [string first "/" $tail]] >= 0} {
3171 lappend htstack $ht
3172 set ht 0
3173 lappend prefendstack $prefixend
3174 incr prefixend [expr {$slash + 1}]
3175 set d [string range $tail 0 $slash]
3176 lappend treecontents($prefix) $d
3177 set oldprefix $prefix
3178 append prefix $d
3179 set treecontents($prefix) {}
3180 set treeindex($prefix) [incr ix]
3181 set treeparent($prefix) $oldprefix
3182 set tail [string range $tail [expr {$slash+1}] end]
3183 if {$lev <= $openlevs} {
3184 set ht 1
3185 set treediropen($prefix) [expr {$lev < $openlevs}]
3186 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}]
3187 $w mark set d:$ix "end -1c"
3188 $w mark gravity d:$ix left
3189 set str "\n"
3190 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3191 $w insert end $str
3192 $w image create end -align center -image $bm -padx 1 \
3193 -name a:$ix
3194 $w insert end $d [highlight_tag $prefix]
3195 $w mark set s:$ix "end -1c"
3196 $w mark gravity s:$ix left
3197 }
3198 incr lev
3199 }
3200 if {$tail ne {}} {
3201 if {$lev <= $openlevs} {
3202 incr ht
3203 set str "\n"
3204 for {set i 0} {$i < $lev} {incr i} {append str "\t"}
3205 $w insert end $str
3206 $w insert end $tail [highlight_tag $f]
3207 }
3208 lappend treecontents($prefix) $tail
3209 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003210 }
3211 while {$htstack ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003212 set treeheight($prefix) $ht
3213 incr ht [lindex $htstack end]
3214 set htstack [lreplace $htstack end end]
3215 set prefixend [lindex $prefendstack end]
3216 set prefendstack [lreplace $prefendstack end end]
3217 set prefix [string range $prefix 0 $prefixend]
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003218 }
3219 $w conf -state disabled
3220}
3221
3222proc linetoelt {l} {
3223 global treeheight treecontents
3224
3225 set y 2
3226 set prefix {}
3227 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07003228 foreach e $treecontents($prefix) {
3229 if {$y == $l} {
3230 return "$prefix$e"
3231 }
3232 set n 1
3233 if {[string index $e end] eq "/"} {
3234 set n $treeheight($prefix$e)
3235 if {$y + $n > $l} {
3236 append prefix $e
3237 incr y
3238 break
3239 }
3240 }
3241 incr y $n
3242 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003243 }
3244}
3245
Paul Mackerras45a9d502006-05-20 22:56:27 +10003246proc highlight_tree {y prefix} {
3247 global treeheight treecontents cflist
3248
3249 foreach e $treecontents($prefix) {
Denton Liue2445882020-09-10 21:36:33 -07003250 set path $prefix$e
3251 if {[highlight_tag $path] ne {}} {
3252 $cflist tag add bold $y.0 "$y.0 lineend"
3253 }
3254 incr y
3255 if {[string index $e end] eq "/" && $treeheight($path) > 1} {
3256 set y [highlight_tree $y $path]
3257 }
Paul Mackerras45a9d502006-05-20 22:56:27 +10003258 }
3259 return $y
3260}
3261
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003262proc treeclosedir {w dir} {
3263 global treediropen treeheight treeparent treeindex
3264
3265 set ix $treeindex($dir)
3266 $w conf -state normal
3267 $w delete s:$ix e:$ix
3268 set treediropen($dir) 0
3269 $w image configure a:$ix -image tri-rt
3270 $w conf -state disabled
3271 set n [expr {1 - $treeheight($dir)}]
3272 while {$dir ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003273 incr treeheight($dir) $n
3274 set dir $treeparent($dir)
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003275 }
3276}
3277
3278proc treeopendir {w dir} {
3279 global treediropen treeheight treeparent treecontents treeindex
3280
3281 set ix $treeindex($dir)
3282 $w conf -state normal
3283 $w image configure a:$ix -image tri-dn
3284 $w mark set e:$ix s:$ix
3285 $w mark gravity e:$ix right
3286 set lev 0
3287 set str "\n"
3288 set n [llength $treecontents($dir)]
3289 for {set x $dir} {$x ne {}} {set x $treeparent($x)} {
Denton Liue2445882020-09-10 21:36:33 -07003290 incr lev
3291 append str "\t"
3292 incr treeheight($x) $n
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003293 }
3294 foreach e $treecontents($dir) {
Denton Liue2445882020-09-10 21:36:33 -07003295 set de $dir$e
3296 if {[string index $e end] eq "/"} {
3297 set iy $treeindex($de)
3298 $w mark set d:$iy e:$ix
3299 $w mark gravity d:$iy left
3300 $w insert e:$ix $str
3301 set treediropen($de) 0
3302 $w image create e:$ix -align center -image tri-rt -padx 1 \
3303 -name a:$iy
3304 $w insert e:$ix $e [highlight_tag $de]
3305 $w mark set s:$iy e:$ix
3306 $w mark gravity s:$iy left
3307 set treeheight($de) 1
3308 } else {
3309 $w insert e:$ix $str
3310 $w insert e:$ix $e [highlight_tag $de]
3311 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003312 }
Alexander Gavrilovb8a640e2008-09-08 11:28:16 +04003313 $w mark gravity e:$ix right
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003314 $w conf -state disabled
3315 set treediropen($dir) 1
3316 set top [lindex [split [$w index @0,0] .] 0]
3317 set ht [$w cget -height]
3318 set l [lindex [split [$w index s:$ix] .] 0]
3319 if {$l < $top} {
Denton Liue2445882020-09-10 21:36:33 -07003320 $w yview $l.0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003321 } elseif {$l + $n + 1 > $top + $ht} {
Denton Liue2445882020-09-10 21:36:33 -07003322 set top [expr {$l + $n + 2 - $ht}]
3323 if {$l < $top} {
3324 set top $l
3325 }
3326 $w yview $top.0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003327 }
3328}
3329
3330proc treeclick {w x y} {
3331 global treediropen cmitmode ctext cflist cflist_top
3332
3333 if {$cmitmode ne "tree"} return
3334 if {![info exists cflist_top]} return
3335 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3336 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3337 $cflist tag add highlight $l.0 "$l.0 lineend"
3338 set cflist_top $l
3339 if {$l == 1} {
Denton Liue2445882020-09-10 21:36:33 -07003340 $ctext yview 1.0
3341 return
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003342 }
3343 set e [linetoelt $l]
3344 if {[string index $e end] ne "/"} {
Denton Liue2445882020-09-10 21:36:33 -07003345 showfile $e
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003346 } elseif {$treediropen($e)} {
Denton Liue2445882020-09-10 21:36:33 -07003347 treeclosedir $w $e
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003348 } else {
Denton Liue2445882020-09-10 21:36:33 -07003349 treeopendir $w $e
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003350 }
3351}
3352
3353proc setfilelist {id} {
Paul Mackerras8a897742008-10-27 21:36:25 +11003354 global treefilelist cflist jump_to_here
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003355
3356 treeview $cflist $treefilelist($id) 0
Paul Mackerras8a897742008-10-27 21:36:25 +11003357 if {$jump_to_here ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003358 set f [lindex $jump_to_here 0]
3359 if {[lsearch -exact $treefilelist($id) $f] >= 0} {
3360 showfile $f
3361 }
Paul Mackerras8a897742008-10-27 21:36:25 +11003362 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003363}
3364
3365image create bitmap tri-rt -background black -foreground blue -data {
3366 #define tri-rt_width 13
3367 #define tri-rt_height 13
3368 static unsigned char tri-rt_bits[] = {
3369 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00,
3370 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00,
3371 0x00, 0x00};
3372} -maskdata {
3373 #define tri-rt-mask_width 13
3374 #define tri-rt-mask_height 13
3375 static unsigned char tri-rt-mask_bits[] = {
3376 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01,
3377 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00,
3378 0x08, 0x00};
3379}
3380image create bitmap tri-dn -background black -foreground blue -data {
3381 #define tri-dn_width 13
3382 #define tri-dn_height 13
3383 static unsigned char tri-dn_bits[] = {
3384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03,
3385 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3386 0x00, 0x00};
3387} -maskdata {
3388 #define tri-dn-mask_width 13
3389 #define tri-dn-mask_height 13
3390 static unsigned char tri-dn-mask_bits[] = {
3391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07,
3392 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
3393 0x00, 0x00};
3394}
3395
Paul Mackerras887c9962007-08-20 19:36:20 +10003396image create bitmap reficon-T -background black -foreground yellow -data {
3397 #define tagicon_width 13
3398 #define tagicon_height 9
3399 static unsigned char tagicon_bits[] = {
3400 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
3401 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
3402} -maskdata {
3403 #define tagicon-mask_width 13
3404 #define tagicon-mask_height 9
3405 static unsigned char tagicon-mask_bits[] = {
3406 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
3407 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
3408}
3409set rectdata {
3410 #define headicon_width 13
3411 #define headicon_height 9
3412 static unsigned char headicon_bits[] = {
3413 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
3414 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
3415}
3416set rectmask {
3417 #define headicon-mask_width 13
3418 #define headicon-mask_height 9
3419 static unsigned char headicon-mask_bits[] = {
3420 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
3421 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
3422}
Paul Mackerras6e8fda52016-12-12 11:29:21 +11003423image create bitmap reficon-H -background black -foreground "#00ff00" \
Paul Mackerras887c9962007-08-20 19:36:20 +10003424 -data $rectdata -maskdata $rectmask
Paul Wised7cc4fb2019-03-21 15:05:32 +08003425image create bitmap reficon-R -background black -foreground "#ffddaa" \
3426 -data $rectdata -maskdata $rectmask
Paul Mackerras887c9962007-08-20 19:36:20 +10003427image create bitmap reficon-o -background black -foreground "#ddddff" \
3428 -data $rectdata -maskdata $rectmask
3429
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003430proc init_flist {first} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11003431 global cflist cflist_top difffilestart
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003432
3433 $cflist conf -state normal
3434 $cflist delete 0.0 end
3435 if {$first ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003436 $cflist insert end $first
3437 set cflist_top 1
3438 $cflist tag add highlight 1.0 "1.0 lineend"
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003439 } else {
Denton Liue2445882020-09-10 21:36:33 -07003440 unset -nocomplain cflist_top
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003441 }
3442 $cflist conf -state disabled
3443 set difffilestart {}
3444}
3445
Paul Mackerras63b79192006-05-20 21:31:52 +10003446proc highlight_tag {f} {
3447 global highlight_paths
3448
3449 foreach p $highlight_paths {
Denton Liue2445882020-09-10 21:36:33 -07003450 if {[string match $p $f]} {
3451 return "bold"
3452 }
Paul Mackerras63b79192006-05-20 21:31:52 +10003453 }
3454 return {}
3455}
3456
3457proc highlight_filelist {} {
Paul Mackerras45a9d502006-05-20 22:56:27 +10003458 global cmitmode cflist
Paul Mackerras63b79192006-05-20 21:31:52 +10003459
Paul Mackerras45a9d502006-05-20 22:56:27 +10003460 $cflist conf -state normal
3461 if {$cmitmode ne "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07003462 set end [lindex [split [$cflist index end] .] 0]
3463 for {set l 2} {$l < $end} {incr l} {
3464 set line [$cflist get $l.0 "$l.0 lineend"]
3465 if {[highlight_tag $line] ne {}} {
3466 $cflist tag add bold $l.0 "$l.0 lineend"
3467 }
3468 }
Paul Mackerras45a9d502006-05-20 22:56:27 +10003469 } else {
Denton Liue2445882020-09-10 21:36:33 -07003470 highlight_tree 2 {}
Paul Mackerras63b79192006-05-20 21:31:52 +10003471 }
Paul Mackerras45a9d502006-05-20 22:56:27 +10003472 $cflist conf -state disabled
Paul Mackerras63b79192006-05-20 21:31:52 +10003473}
3474
3475proc unhighlight_filelist {} {
Paul Mackerras45a9d502006-05-20 22:56:27 +10003476 global cflist
Paul Mackerras63b79192006-05-20 21:31:52 +10003477
Paul Mackerras45a9d502006-05-20 22:56:27 +10003478 $cflist conf -state normal
3479 $cflist tag remove bold 1.0 end
3480 $cflist conf -state disabled
Paul Mackerras63b79192006-05-20 21:31:52 +10003481}
3482
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003483proc add_flist {fl} {
Paul Mackerras45a9d502006-05-20 22:56:27 +10003484 global cflist
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003485
Paul Mackerras45a9d502006-05-20 22:56:27 +10003486 $cflist conf -state normal
3487 foreach f $fl {
Denton Liue2445882020-09-10 21:36:33 -07003488 $cflist insert end "\n"
3489 $cflist insert end $f [highlight_tag $f]
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003490 }
Paul Mackerras45a9d502006-05-20 22:56:27 +10003491 $cflist conf -state disabled
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003492}
3493
3494proc sel_flist {w x y} {
Paul Mackerras45a9d502006-05-20 22:56:27 +10003495 global ctext difffilestart cflist cflist_top cmitmode
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003496
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003497 if {$cmitmode eq "tree"} return
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003498 if {![info exists cflist_top]} return
3499 set l [lindex [split [$w index "@$x,$y"] "."] 0]
Paul Mackerras89b11d32006-05-02 19:55:31 +10003500 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
3501 $cflist tag add highlight $l.0 "$l.0 lineend"
3502 set cflist_top $l
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003503 if {$l == 1} {
Denton Liue2445882020-09-10 21:36:33 -07003504 $ctext yview 1.0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10003505 } else {
Denton Liue2445882020-09-10 21:36:33 -07003506 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]}
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003507 }
Stefan Hallerb9671352012-09-19 20:17:27 +02003508 suppress_highlighting_file_for_current_scrollpos
Paul Mackerras7fcceed2006-04-27 19:21:49 +10003509}
3510
Paul Mackerras32447292007-07-27 22:30:15 +10003511proc pop_flist_menu {w X Y x y} {
3512 global ctext cflist cmitmode flist_menu flist_menu_file
3513 global treediffs diffids
3514
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10003515 stopfinding
Paul Mackerras32447292007-07-27 22:30:15 +10003516 set l [lindex [split [$w index "@$x,$y"] "."] 0]
3517 if {$l <= 1} return
3518 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07003519 set e [linetoelt $l]
3520 if {[string index $e end] eq "/"} return
Paul Mackerras32447292007-07-27 22:30:15 +10003521 } else {
Denton Liue2445882020-09-10 21:36:33 -07003522 set e [lindex $treediffs($diffids) [expr {$l-2}]]
Paul Mackerras32447292007-07-27 22:30:15 +10003523 }
3524 set flist_menu_file $e
Thomas Arcila314f5de2008-03-24 12:55:36 +01003525 set xdiffstate "normal"
3526 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07003527 set xdiffstate "disabled"
Thomas Arcila314f5de2008-03-24 12:55:36 +01003528 }
3529 # Disable "External diff" item in tree mode
3530 $flist_menu entryconf 2 -state $xdiffstate
Paul Mackerras32447292007-07-27 22:30:15 +10003531 tk_popup $flist_menu $X $Y
3532}
3533
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003534proc find_ctext_fileinfo {line} {
3535 global ctext_file_names ctext_file_lines
3536
3537 set ok [bsearch $ctext_file_lines $line]
3538 set tline [lindex $ctext_file_lines $ok]
3539
3540 if {$ok >= [llength $ctext_file_lines] || $line < $tline} {
3541 return {}
3542 } else {
3543 return [list [lindex $ctext_file_names $ok] $tline]
3544 }
3545}
3546
3547proc pop_diff_menu {w X Y x y} {
3548 global ctext diff_menu flist_menu_file
3549 global diff_menu_txtpos diff_menu_line
3550 global diff_menu_filebase
3551
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003552 set diff_menu_txtpos [split [$w index "@$x,$y"] "."]
3553 set diff_menu_line [lindex $diff_menu_txtpos 0]
Paul Mackerras190ec522008-10-27 21:13:37 +11003554 # don't pop up the menu on hunk-separator or file-separator lines
3555 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07003556 return
Paul Mackerras190ec522008-10-27 21:13:37 +11003557 }
3558 stopfinding
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003559 set f [find_ctext_fileinfo $diff_menu_line]
3560 if {$f eq {}} return
3561 set flist_menu_file [lindex $f 0]
3562 set diff_menu_filebase [lindex $f 1]
3563 tk_popup $diff_menu $X $Y
3564}
3565
Paul Mackerras32447292007-07-27 22:30:15 +10003566proc flist_hl {only} {
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10003567 global flist_menu_file findstring gdttype
Paul Mackerras32447292007-07-27 22:30:15 +10003568
3569 set x [shellquote $flist_menu_file]
Christian Stimmingb007ee22007-11-07 18:44:35 +01003570 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} {
Denton Liue2445882020-09-10 21:36:33 -07003571 set findstring $x
Paul Mackerras32447292007-07-27 22:30:15 +10003572 } else {
Denton Liue2445882020-09-10 21:36:33 -07003573 append findstring " " $x
Paul Mackerras32447292007-07-27 22:30:15 +10003574 }
Christian Stimmingb007ee22007-11-07 18:44:35 +01003575 set gdttype [mc "touching paths:"]
Paul Mackerras32447292007-07-27 22:30:15 +10003576}
3577
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003578proc gitknewtmpdir {} {
David Aguilarc7664f12014-06-13 14:13:37 -07003579 global diffnum gitktmpdir gitdir env
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003580
3581 if {![info exists gitktmpdir]} {
Denton Liue2445882020-09-10 21:36:33 -07003582 if {[info exists env(GITK_TMPDIR)]} {
3583 set tmpdir $env(GITK_TMPDIR)
3584 } elseif {[info exists env(TMPDIR)]} {
3585 set tmpdir $env(TMPDIR)
3586 } else {
3587 set tmpdir $gitdir
3588 }
3589 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"]
3590 if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} {
3591 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]]
3592 }
3593 if {[catch {file mkdir $gitktmpdir} err]} {
3594 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3595 unset gitktmpdir
3596 return {}
3597 }
3598 set diffnum 0
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003599 }
3600 incr diffnum
3601 set diffdir [file join $gitktmpdir $diffnum]
3602 if {[catch {file mkdir $diffdir} err]} {
Denton Liue2445882020-09-10 21:36:33 -07003603 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3604 return {}
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003605 }
3606 return $diffdir
3607}
3608
Thomas Arcila314f5de2008-03-24 12:55:36 +01003609proc save_file_from_commit {filename output what} {
3610 global nullfile
3611
3612 if {[catch {exec git show $filename -- > $output} err]} {
Denton Liue2445882020-09-10 21:36:33 -07003613 if {[string match "fatal: bad revision *" $err]} {
3614 return $nullfile
3615 }
3616 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err"
3617 return {}
Thomas Arcila314f5de2008-03-24 12:55:36 +01003618 }
3619 return $output
3620}
3621
3622proc external_diff_get_one_file {diffid filename diffdir} {
3623 global nullid nullid2 nullfile
Martin von Zweigbergk784b7e22011-04-04 22:14:15 -04003624 global worktree
Thomas Arcila314f5de2008-03-24 12:55:36 +01003625
3626 if {$diffid == $nullid} {
Martin von Zweigbergk784b7e22011-04-04 22:14:15 -04003627 set difffile [file join $worktree $filename]
Denton Liue2445882020-09-10 21:36:33 -07003628 if {[file exists $difffile]} {
3629 return $difffile
3630 }
3631 return $nullfile
Thomas Arcila314f5de2008-03-24 12:55:36 +01003632 }
3633 if {$diffid == $nullid2} {
3634 set difffile [file join $diffdir "\[index\] [file tail $filename]"]
3635 return [save_file_from_commit :$filename $difffile index]
3636 }
3637 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"]
3638 return [save_file_from_commit $diffid:$filename $difffile \
Denton Liue2445882020-09-10 21:36:33 -07003639 "revision $diffid"]
Thomas Arcila314f5de2008-03-24 12:55:36 +01003640}
3641
3642proc external_diff {} {
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003643 global nullid nullid2
Thomas Arcila314f5de2008-03-24 12:55:36 +01003644 global flist_menu_file
3645 global diffids
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003646 global extdifftool
Thomas Arcila314f5de2008-03-24 12:55:36 +01003647
3648 if {[llength $diffids] == 1} {
3649 # no reference commit given
3650 set diffidto [lindex $diffids 0]
3651 if {$diffidto eq $nullid} {
3652 # diffing working copy with index
3653 set diffidfrom $nullid2
3654 } elseif {$diffidto eq $nullid2} {
3655 # diffing index with HEAD
3656 set diffidfrom "HEAD"
3657 } else {
3658 # use first parent commit
3659 global parentlist selectedline
3660 set diffidfrom [lindex $parentlist $selectedline 0]
3661 }
3662 } else {
3663 set diffidfrom [lindex $diffids 0]
3664 set diffidto [lindex $diffids 1]
3665 }
3666
3667 # make sure that several diffs wont collide
Paul Mackerrasc21398b2009-09-07 10:08:21 +10003668 set diffdir [gitknewtmpdir]
3669 if {$diffdir eq {}} return
Thomas Arcila314f5de2008-03-24 12:55:36 +01003670
3671 # gather files to diff
3672 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3673 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3674
3675 if {$difffromfile ne {} && $difftofile ne {}} {
Pat Thoytsb575b2f2009-04-15 16:54:19 +01003676 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
3677 if {[catch {set fl [open |$cmd r]} err]} {
Thomas Arcila314f5de2008-03-24 12:55:36 +01003678 file delete -force $diffdir
Christian Stimming3945d2c2008-09-12 11:39:43 +02003679 error_popup "$extdifftool: [mc "command failed:"] $err"
Thomas Arcila314f5de2008-03-24 12:55:36 +01003680 } else {
3681 fconfigure $fl -blocking 0
3682 filerun $fl [list delete_at_eof $fl $diffdir]
3683 }
3684 }
3685}
3686
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003687proc find_hunk_blamespec {base line} {
3688 global ctext
3689
3690 # Find and parse the hunk header
3691 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0]
3692 if {$s_lix eq {}} return
3693
3694 set s_line [$ctext get $s_lix "$s_lix + 1 lines"]
3695 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \
Denton Liue2445882020-09-10 21:36:33 -07003696 s_line old_specs osz osz1 new_line nsz]} {
3697 return
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003698 }
3699
3700 # base lines for the parents
3701 set base_lines [list $new_line]
3702 foreach old_spec [lrange [split $old_specs " "] 1 end] {
Denton Liue2445882020-09-10 21:36:33 -07003703 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \
3704 old_spec old_line osz]} {
3705 return
3706 }
3707 lappend base_lines $old_line
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003708 }
3709
3710 # Now scan the lines to determine offset within the hunk
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003711 set max_parent [expr {[llength $base_lines]-2}]
3712 set dline 0
3713 set s_lno [lindex [split $s_lix "."] 0]
3714
Paul Mackerras190ec522008-10-27 21:13:37 +11003715 # Determine if the line is removed
3716 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"]
3717 if {[string match {[-+ ]*} $chunk]} {
Denton Liue2445882020-09-10 21:36:33 -07003718 set removed_idx [string first "-" $chunk]
3719 # Choose a parent index
3720 if {$removed_idx >= 0} {
3721 set parent $removed_idx
3722 } else {
3723 set unchanged_idx [string first " " $chunk]
3724 if {$unchanged_idx >= 0} {
3725 set parent $unchanged_idx
3726 } else {
3727 # blame the current commit
3728 set parent -1
3729 }
3730 }
3731 # then count other lines that belong to it
3732 for {set i $line} {[incr i -1] > $s_lno} {} {
3733 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"]
3734 # Determine if the line is removed
3735 set removed_idx [string first "-" $chunk]
3736 if {$parent >= 0} {
3737 set code [string index $chunk $parent]
3738 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} {
3739 incr dline
3740 }
3741 } else {
3742 if {$removed_idx < 0} {
3743 incr dline
3744 }
3745 }
3746 }
3747 incr parent
Paul Mackerras190ec522008-10-27 21:13:37 +11003748 } else {
Denton Liue2445882020-09-10 21:36:33 -07003749 set parent 0
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003750 }
3751
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003752 incr dline [lindex $base_lines $parent]
3753 return [list $parent $dline]
3754}
3755
3756proc external_blame_diff {} {
Paul Mackerras8b07dca2008-11-02 22:34:47 +11003757 global currentid cmitmode
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003758 global diff_menu_txtpos diff_menu_line
3759 global diff_menu_filebase flist_menu_file
3760
3761 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07003762 set parent_idx 0
3763 set line [expr {$diff_menu_line - $diff_menu_filebase}]
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003764 } else {
Denton Liue2445882020-09-10 21:36:33 -07003765 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3766 if {$hinfo ne {}} {
3767 set parent_idx [lindex $hinfo 0]
3768 set line [lindex $hinfo 1]
3769 } else {
3770 set parent_idx 0
3771 set line 0
3772 }
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003773 }
3774
3775 external_blame $parent_idx $line
3776}
3777
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003778# Find the SHA1 ID of the blob for file $fname in the index
3779# at stage 0 or 2
3780proc index_sha1 {fname} {
3781 set f [open [list | git ls-files -s $fname] r]
3782 while {[gets $f line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07003783 set info [lindex [split $line "\t"] 0]
3784 set stage [lindex $info 2]
3785 if {$stage eq "0" || $stage eq "2"} {
3786 close $f
3787 return [lindex $info 1]
3788 }
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003789 }
3790 close $f
3791 return {}
3792}
3793
Paul Mackerras9712b812008-12-06 21:44:05 +11003794# Turn an absolute path into one relative to the current directory
3795proc make_relative {f} {
Markus Heidelberga4390ac2009-11-04 00:21:41 +01003796 if {[file pathtype $f] eq "relative"} {
Denton Liue2445882020-09-10 21:36:33 -07003797 return $f
Markus Heidelberga4390ac2009-11-04 00:21:41 +01003798 }
Paul Mackerras9712b812008-12-06 21:44:05 +11003799 set elts [file split $f]
3800 set here [file split [pwd]]
3801 set ei 0
3802 set hi 0
3803 set res {}
3804 foreach d $here {
Denton Liue2445882020-09-10 21:36:33 -07003805 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} {
3806 lappend res ".."
3807 } else {
3808 incr ei
3809 }
3810 incr hi
Paul Mackerras9712b812008-12-06 21:44:05 +11003811 }
3812 set elts [concat $res [lrange $elts $ei end]]
3813 return [eval file join $elts]
3814}
3815
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003816proc external_blame {parent_idx {line {}}} {
Martin von Zweigbergk0a2a9792011-04-04 22:14:14 -04003817 global flist_menu_file cdup
Alexander Gavrilov77aa0ae2008-08-23 12:29:08 +04003818 global nullid nullid2
3819 global parentlist selectedline currentid
3820
3821 if {$parent_idx > 0} {
Denton Liue2445882020-09-10 21:36:33 -07003822 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]]
Alexander Gavrilov77aa0ae2008-08-23 12:29:08 +04003823 } else {
Denton Liue2445882020-09-10 21:36:33 -07003824 set base_commit $currentid
Alexander Gavrilov77aa0ae2008-08-23 12:29:08 +04003825 }
3826
3827 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} {
Denton Liue2445882020-09-10 21:36:33 -07003828 error_popup [mc "No such commit"]
3829 return
Alexander Gavrilov77aa0ae2008-08-23 12:29:08 +04003830 }
3831
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003832 set cmdline [list git gui blame]
3833 if {$line ne {} && $line > 1} {
Denton Liue2445882020-09-10 21:36:33 -07003834 lappend cmdline "--line=$line"
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003835 }
Martin von Zweigbergk0a2a9792011-04-04 22:14:14 -04003836 set f [file join $cdup $flist_menu_file]
Paul Mackerras9712b812008-12-06 21:44:05 +11003837 # Unfortunately it seems git gui blame doesn't like
3838 # being given an absolute path...
3839 set f [make_relative $f]
3840 lappend cmdline $base_commit $f
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04003841 if {[catch {eval exec $cmdline &} err]} {
Denton Liue2445882020-09-10 21:36:33 -07003842 error_popup "[mc "git gui blame: command failed:"] $err"
Alexander Gavrilov77aa0ae2008-08-23 12:29:08 +04003843 }
3844}
3845
Paul Mackerras8a897742008-10-27 21:36:25 +11003846proc show_line_source {} {
3847 global cmitmode currentid parents curview blamestuff blameinst
3848 global diff_menu_line diff_menu_filebase flist_menu_file
Martin von Zweigbergk9b6adf32011-04-04 22:14:13 -04003849 global nullid nullid2 gitdir cdup
Paul Mackerras8a897742008-10-27 21:36:25 +11003850
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003851 set from_index {}
Paul Mackerras8a897742008-10-27 21:36:25 +11003852 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07003853 set id $currentid
3854 set line [expr {$diff_menu_line - $diff_menu_filebase}]
Paul Mackerras8a897742008-10-27 21:36:25 +11003855 } else {
Denton Liue2445882020-09-10 21:36:33 -07003856 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line]
3857 if {$h eq {}} return
3858 set pi [lindex $h 0]
3859 if {$pi == 0} {
3860 mark_ctext_line $diff_menu_line
3861 return
3862 }
3863 incr pi -1
3864 if {$currentid eq $nullid} {
3865 if {$pi > 0} {
3866 # must be a merge in progress...
3867 if {[catch {
3868 # get the last line from .git/MERGE_HEAD
3869 set f [open [file join $gitdir MERGE_HEAD] r]
3870 set id [lindex [split [read $f] "\n"] end-1]
3871 close $f
3872 } err]} {
3873 error_popup [mc "Couldn't read merge head: %s" $err]
3874 return
3875 }
3876 } elseif {$parents($curview,$currentid) eq $nullid2} {
3877 # need to do the blame from the index
3878 if {[catch {
3879 set from_index [index_sha1 $flist_menu_file]
3880 } err]} {
3881 error_popup [mc "Error reading index: %s" $err]
3882 return
3883 }
3884 } else {
3885 set id $parents($curview,$currentid)
3886 }
3887 } else {
3888 set id [lindex $parents($curview,$currentid) $pi]
3889 }
3890 set line [lindex $h 1]
Paul Mackerras8a897742008-10-27 21:36:25 +11003891 }
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003892 set blameargs {}
3893 if {$from_index ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003894 lappend blameargs | git cat-file blob $from_index
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003895 }
3896 lappend blameargs | git blame -p -L$line,+1
3897 if {$from_index ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003898 lappend blameargs --contents -
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003899 } else {
Denton Liue2445882020-09-10 21:36:33 -07003900 lappend blameargs $id
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003901 }
Martin von Zweigbergk9b6adf32011-04-04 22:14:13 -04003902 lappend blameargs -- [file join $cdup $flist_menu_file]
Paul Mackerras8a897742008-10-27 21:36:25 +11003903 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07003904 set f [open $blameargs r]
Paul Mackerras8a897742008-10-27 21:36:25 +11003905 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07003906 error_popup [mc "Couldn't start git blame: %s" $err]
3907 return
Paul Mackerras8a897742008-10-27 21:36:25 +11003908 }
Alexander Gavrilovf3413072008-12-01 20:30:09 +03003909 nowbusy blaming [mc "Searching"]
Paul Mackerras8a897742008-10-27 21:36:25 +11003910 fconfigure $f -blocking 0
3911 set i [reg_instance $f]
3912 set blamestuff($i) {}
3913 set blameinst $i
3914 filerun $f [list read_line_source $f $i]
3915}
3916
3917proc stopblaming {} {
3918 global blameinst
3919
3920 if {[info exists blameinst]} {
Denton Liue2445882020-09-10 21:36:33 -07003921 stop_instance $blameinst
3922 unset blameinst
3923 notbusy blaming
Paul Mackerras8a897742008-10-27 21:36:25 +11003924 }
3925}
3926
3927proc read_line_source {fd inst} {
Paul Mackerrasfc4977e2008-11-04 12:57:44 +11003928 global blamestuff curview commfd blameinst nullid nullid2
Paul Mackerras8a897742008-10-27 21:36:25 +11003929
3930 while {[gets $fd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07003931 lappend blamestuff($inst) $line
Paul Mackerras8a897742008-10-27 21:36:25 +11003932 }
3933 if {![eof $fd]} {
Denton Liue2445882020-09-10 21:36:33 -07003934 return 1
Paul Mackerras8a897742008-10-27 21:36:25 +11003935 }
3936 unset commfd($inst)
3937 unset blameinst
Alexander Gavrilovf3413072008-12-01 20:30:09 +03003938 notbusy blaming
Paul Mackerras8a897742008-10-27 21:36:25 +11003939 fconfigure $fd -blocking 1
3940 if {[catch {close $fd} err]} {
Denton Liue2445882020-09-10 21:36:33 -07003941 error_popup [mc "Error running git blame: %s" $err]
3942 return 0
Paul Mackerras8a897742008-10-27 21:36:25 +11003943 }
3944
3945 set fname {}
3946 set line [split [lindex $blamestuff($inst) 0] " "]
3947 set id [lindex $line 0]
3948 set lnum [lindex $line 1]
3949 if {[string length $id] == 40 && [string is xdigit $id] &&
Denton Liue2445882020-09-10 21:36:33 -07003950 [string is digit -strict $lnum]} {
3951 # look for "filename" line
3952 foreach l $blamestuff($inst) {
3953 if {[string match "filename *" $l]} {
3954 set fname [string range $l 9 end]
3955 break
3956 }
3957 }
Paul Mackerras8a897742008-10-27 21:36:25 +11003958 }
3959 if {$fname ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07003960 # all looks good, select it
3961 if {$id eq $nullid} {
3962 # blame uses all-zeroes to mean not committed,
3963 # which would mean a change in the index
3964 set id $nullid2
3965 }
3966 if {[commitinview $id $curview]} {
3967 selectline [rowofcommit $id] 1 [list $fname $lnum] 1
3968 } else {
3969 error_popup [mc "That line comes from commit %s, \
3970 which is not in this view" [shortids $id]]
3971 }
Paul Mackerras8a897742008-10-27 21:36:25 +11003972 } else {
Denton Liue2445882020-09-10 21:36:33 -07003973 puts "oops couldn't parse git blame output"
Paul Mackerras8a897742008-10-27 21:36:25 +11003974 }
3975 return 0
3976}
3977
Thomas Arcila314f5de2008-03-24 12:55:36 +01003978# delete $dir when we see eof on $f (presumably because the child has exited)
3979proc delete_at_eof {f dir} {
3980 while {[gets $f line] >= 0} {}
3981 if {[eof $f]} {
Denton Liue2445882020-09-10 21:36:33 -07003982 if {[catch {close $f} err]} {
3983 error_popup "[mc "External diff viewer failed:"] $err"
3984 }
3985 file delete -force $dir
3986 return 0
Thomas Arcila314f5de2008-03-24 12:55:36 +01003987 }
3988 return 1
3989}
3990
Paul Mackerras098dd8a2006-05-03 09:32:53 +10003991# Functions for adding and removing shell-type quoting
3992
3993proc shellquote {str} {
3994 if {![string match "*\['\"\\ \t]*" $str]} {
Denton Liue2445882020-09-10 21:36:33 -07003995 return $str
Paul Mackerras098dd8a2006-05-03 09:32:53 +10003996 }
3997 if {![string match "*\['\"\\]*" $str]} {
Denton Liue2445882020-09-10 21:36:33 -07003998 return "\"$str\""
Paul Mackerras098dd8a2006-05-03 09:32:53 +10003999 }
4000 if {![string match "*'*" $str]} {
Denton Liue2445882020-09-10 21:36:33 -07004001 return "'$str'"
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004002 }
4003 return "\"[string map {\" \\\" \\ \\\\} $str]\""
4004}
4005
4006proc shellarglist {l} {
4007 set str {}
4008 foreach a $l {
Denton Liue2445882020-09-10 21:36:33 -07004009 if {$str ne {}} {
4010 append str " "
4011 }
4012 append str [shellquote $a]
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004013 }
4014 return $str
4015}
4016
4017proc shelldequote {str} {
4018 set ret {}
4019 set used -1
4020 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07004021 incr used
4022 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} {
4023 append ret [string range $str $used end]
4024 set used [string length $str]
4025 break
4026 }
4027 set first [lindex $first 0]
4028 set ch [string index $str $first]
4029 if {$first > $used} {
4030 append ret [string range $str $used [expr {$first - 1}]]
4031 set used $first
4032 }
4033 if {$ch eq " " || $ch eq "\t"} break
4034 incr used
4035 if {$ch eq "'"} {
4036 set first [string first "'" $str $used]
4037 if {$first < 0} {
4038 error "unmatched single-quote"
4039 }
4040 append ret [string range $str $used [expr {$first - 1}]]
4041 set used $first
4042 continue
4043 }
4044 if {$ch eq "\\"} {
4045 if {$used >= [string length $str]} {
4046 error "trailing backslash"
4047 }
4048 append ret [string index $str $used]
4049 continue
4050 }
4051 # here ch == "\""
4052 while {1} {
4053 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} {
4054 error "unmatched double-quote"
4055 }
4056 set first [lindex $first 0]
4057 set ch [string index $str $first]
4058 if {$first > $used} {
4059 append ret [string range $str $used [expr {$first - 1}]]
4060 set used $first
4061 }
4062 if {$ch eq "\""} break
4063 incr used
4064 append ret [string index $str $used]
4065 incr used
4066 }
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004067 }
4068 return [list $used $ret]
4069}
4070
4071proc shellsplit {str} {
4072 set l {}
4073 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07004074 set str [string trimleft $str]
4075 if {$str eq {}} break
4076 set dq [shelldequote $str]
4077 set n [lindex $dq 0]
4078 set word [lindex $dq 1]
4079 set str [string range $str $n end]
4080 lappend l $word
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004081 }
4082 return $l
4083}
4084
Marc Branchaud9922c5a2015-04-07 11:51:51 -04004085proc set_window_title {} {
4086 global appname curview viewname vrevs
4087 set rev [mc "All files"]
4088 if {$curview ne 0} {
Denton Liue2445882020-09-10 21:36:33 -07004089 if {$viewname($curview) eq [mc "Command line"]} {
4090 set rev [string map {"--gitk-symmetric-diff-marker" "--merge"} $vrevs($curview)]
4091 } else {
4092 set rev $viewname($curview)
4093 }
Marc Branchaud9922c5a2015-04-07 11:51:51 -04004094 }
4095 wm title . "[reponame]: $rev - $appname"
4096}
4097
Paul Mackerras7fcceed2006-04-27 19:21:49 +10004098# Code to implement multiple views
4099
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004100proc newview {ishighlight} {
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004101 global nextviewnum newviewname newishighlight
4102 global revtreeargs viewargscmd newviewopts curview
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004103
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004104 set newishighlight $ishighlight
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004105 set top .gitkview
4106 if {[winfo exists $top]} {
Denton Liue2445882020-09-10 21:36:33 -07004107 raise $top
4108 return
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004109 }
Jonathan Nieder5d11f792010-03-06 16:58:42 -06004110 decode_view_opts $nextviewnum $revtreeargs
Michele Ballabioa3a1f572008-03-03 21:12:47 +01004111 set newviewname($nextviewnum) "[mc "View"] $nextviewnum"
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004112 set newviewopts($nextviewnum,perm) 0
4113 set newviewopts($nextviewnum,cmd) $viewargscmd($curview)
Christian Stimmingd990ced2007-11-07 18:42:55 +01004114 vieweditor $top $nextviewnum [mc "Gitk view definition"]
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004115}
4116
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004117set known_view_options {
Elijah Newren13d40b62009-03-23 11:57:46 -06004118 {perm b . {} {mc "Remember this view"}}
4119 {reflabel l + {} {mc "References (space separated list):"}}
4120 {refs t15 .. {} {mc "Branches & tags:"}}
4121 {allrefs b *. "--all" {mc "All refs"}}
4122 {branches b . "--branches" {mc "All (local) branches"}}
4123 {tags b . "--tags" {mc "All tags"}}
4124 {remotes b . "--remotes" {mc "All remote-tracking branches"}}
4125 {commitlbl l + {} {mc "Commit Info (regular expressions):"}}
4126 {author t15 .. "--author=*" {mc "Author:"}}
4127 {committer t15 . "--committer=*" {mc "Committer:"}}
4128 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}}
4129 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}}
Alex Henrie00132512015-04-02 15:05:06 -06004130 {igrep b .. "--invert-grep" {mc "Matches no Commit Info criteria"}}
Elijah Newren13d40b62009-03-23 11:57:46 -06004131 {changes_l l + {} {mc "Changes to Files:"}}
4132 {pickaxe_s r0 . {} {mc "Fixed String"}}
4133 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}}
4134 {pickaxe t15 .. "-S*" {mc "Search string:"}}
4135 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}}
4136 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}}
4137 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}}
4138 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}}
4139 {limit t10 *. "--max-count=*" {mc "Number to show:"}}
4140 {skip t10 . "--skip=*" {mc "Number to skip:"}}
4141 {misc_lbl l + {} {mc "Miscellaneous options:"}}
4142 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}}
4143 {lright b . "--left-right" {mc "Mark branch sides"}}
4144 {first b . "--first-parent" {mc "Limit to first parent"}}
Dirk Suesserottf687aaa2009-05-21 15:35:40 +02004145 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}}
Elijah Newren13d40b62009-03-23 11:57:46 -06004146 {args t50 *. {} {mc "Additional arguments to git log:"}}
4147 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}}
4148 {cmd t50= + {} {mc "Command to generate more commits to include:"}}
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004149 }
4150
Jonathan Niedere7feb692010-03-06 16:48:38 -06004151# Convert $newviewopts($n, ...) into args for git log.
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004152proc encode_view_opts {n} {
4153 global known_view_options newviewopts
4154
4155 set rargs [list]
4156 foreach opt $known_view_options {
Denton Liue2445882020-09-10 21:36:33 -07004157 set patterns [lindex $opt 3]
4158 if {$patterns eq {}} continue
4159 set pattern [lindex $patterns 0]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004160
Denton Liue2445882020-09-10 21:36:33 -07004161 if {[lindex $opt 1] eq "b"} {
4162 set val $newviewopts($n,[lindex $opt 0])
4163 if {$val} {
4164 lappend rargs $pattern
4165 }
4166 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} {
4167 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id
4168 set val $newviewopts($n,$button_id)
4169 if {$val eq $value} {
4170 lappend rargs $pattern
4171 }
4172 } else {
4173 set val $newviewopts($n,[lindex $opt 0])
4174 set val [string trim $val]
4175 if {$val ne {}} {
4176 set pfix [string range $pattern 0 end-1]
4177 lappend rargs $pfix$val
4178 }
4179 }
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004180 }
Elijah Newren13d40b62009-03-23 11:57:46 -06004181 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004182 return [concat $rargs [shellsplit $newviewopts($n,args)]]
4183}
4184
Jonathan Niedere7feb692010-03-06 16:48:38 -06004185# Fill $newviewopts($n, ...) based on args for git log.
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004186proc decode_view_opts {n view_args} {
4187 global known_view_options newviewopts
4188
4189 foreach opt $known_view_options {
Denton Liue2445882020-09-10 21:36:33 -07004190 set id [lindex $opt 0]
4191 if {[lindex $opt 1] eq "b"} {
4192 # Checkboxes
4193 set val 0
Elijah Newren13d40b62009-03-23 11:57:46 -06004194 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} {
Denton Liue2445882020-09-10 21:36:33 -07004195 # Radiobuttons
4196 regexp {^(.*_)} $id uselessvar id
4197 set val 0
4198 } else {
4199 # Text fields
4200 set val {}
4201 }
4202 set newviewopts($n,$id) $val
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004203 }
4204 set oargs [list]
Elijah Newren13d40b62009-03-23 11:57:46 -06004205 set refargs [list]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004206 foreach arg $view_args {
Denton Liue2445882020-09-10 21:36:33 -07004207 if {[regexp -- {^-([0-9]+)$} $arg arg cnt]
4208 && ![info exists found(limit)]} {
4209 set newviewopts($n,limit) $cnt
4210 set found(limit) 1
4211 continue
4212 }
4213 catch { unset val }
4214 foreach opt $known_view_options {
4215 set id [lindex $opt 0]
4216 if {[info exists found($id)]} continue
4217 foreach pattern [lindex $opt 3] {
4218 if {![string match $pattern $arg]} continue
4219 if {[lindex $opt 1] eq "b"} {
4220 # Check buttons
4221 set val 1
4222 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} {
4223 # Radio buttons
4224 regexp {^(.*_)} $id uselessvar id
4225 set val $num
4226 } else {
4227 # Text input fields
4228 set size [string length $pattern]
4229 set val [string range $arg [expr {$size-1}] end]
4230 }
4231 set newviewopts($n,$id) $val
4232 set found($id) 1
4233 break
4234 }
4235 if {[info exists val]} break
4236 }
4237 if {[info exists val]} continue
4238 if {[regexp {^-} $arg]} {
4239 lappend oargs $arg
4240 } else {
4241 lappend refargs $arg
4242 }
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004243 }
Elijah Newren13d40b62009-03-23 11:57:46 -06004244 set newviewopts($n,refs) [shellarglist $refargs]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004245 set newviewopts($n,args) [shellarglist $oargs]
4246}
4247
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03004248proc edit_or_newview {} {
4249 global curview
4250
4251 if {$curview > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004252 editview
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03004253 } else {
Denton Liue2445882020-09-10 21:36:33 -07004254 newview 0
Alexander Gavrilovcea07cf2008-11-09 13:00:45 +03004255 }
4256}
4257
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004258proc editview {} {
4259 global curview
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004260 global viewname viewperm newviewname newviewopts
4261 global viewargs viewargscmd
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004262
4263 set top .gitkvedit-$curview
4264 if {[winfo exists $top]} {
Denton Liue2445882020-09-10 21:36:33 -07004265 raise $top
4266 return
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004267 }
Jonathan Nieder5d11f792010-03-06 16:58:42 -06004268 decode_view_opts $curview $viewargs($curview)
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004269 set newviewname($curview) $viewname($curview)
4270 set newviewopts($curview,perm) $viewperm($curview)
4271 set newviewopts($curview,cmd) $viewargscmd($curview)
Michele Ballabiob56e0a92009-03-30 21:17:25 +02004272 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)"
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004273}
4274
4275proc vieweditor {top n title} {
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004276 global newviewname newviewopts viewfiles bgcolor
Pat Thoytsd93f1712009-04-17 01:24:35 +01004277 global known_view_options NS
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004278
Pat Thoytsd93f1712009-04-17 01:24:35 +01004279 ttk_toplevel $top
Michele Ballabioe0a01992009-05-23 11:48:25 +02004280 wm title $top [concat $title [mc "-- criteria for selecting revisions"]]
Alexander Gavrilove7d64002008-11-11 23:55:42 +03004281 make_transient $top .
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004282
4283 # View name
Pat Thoytsd93f1712009-04-17 01:24:35 +01004284 ${NS}::frame $top.nfr
Paul Mackerraseae7d642009-09-05 17:34:03 +10004285 ${NS}::label $top.nl -text [mc "View Name"]
Pat Thoytsd93f1712009-04-17 01:24:35 +01004286 ${NS}::entry $top.name -width 20 -textvariable newviewname($n)
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004287 pack $top.nfr -in $top -fill x -pady 5 -padx 3
Elijah Newren13d40b62009-03-23 11:57:46 -06004288 pack $top.nl -in $top.nfr -side left -padx {0 5}
4289 pack $top.name -in $top.nfr -side left -padx {0 25}
Yann Dirson2d480852008-02-21 21:23:31 +01004290
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004291 # View options
4292 set cframe $top.nfr
4293 set cexpand 0
4294 set cnt 0
4295 foreach opt $known_view_options {
Denton Liue2445882020-09-10 21:36:33 -07004296 set id [lindex $opt 0]
4297 set type [lindex $opt 1]
4298 set flags [lindex $opt 2]
4299 set title [eval [lindex $opt 4]]
4300 set lxpad 0
Yann Dirson2d480852008-02-21 21:23:31 +01004301
Denton Liue2445882020-09-10 21:36:33 -07004302 if {$flags eq "+" || $flags eq "*"} {
4303 set cframe $top.fr$cnt
4304 incr cnt
4305 ${NS}::frame $cframe
4306 pack $cframe -in $top -fill x -pady 3 -padx 3
4307 set cexpand [expr {$flags eq "*"}]
Elijah Newren13d40b62009-03-23 11:57:46 -06004308 } elseif {$flags eq ".." || $flags eq "*."} {
Denton Liue2445882020-09-10 21:36:33 -07004309 set cframe $top.fr$cnt
4310 incr cnt
4311 ${NS}::frame $cframe
4312 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3]
4313 set cexpand [expr {$flags eq "*."}]
4314 } else {
4315 set lxpad 5
4316 }
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004317
Denton Liue2445882020-09-10 21:36:33 -07004318 if {$type eq "l"} {
Paul Mackerraseae7d642009-09-05 17:34:03 +10004319 ${NS}::label $cframe.l_$id -text $title
Elijah Newren13d40b62009-03-23 11:57:46 -06004320 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w
Denton Liue2445882020-09-10 21:36:33 -07004321 } elseif {$type eq "b"} {
4322 ${NS}::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id)
4323 pack $cframe.c_$id -in $cframe -side left \
4324 -padx [list $lxpad 0] -expand $cexpand -anchor w
4325 } elseif {[regexp {^r(\d+)$} $type type sz]} {
4326 regexp {^(.*_)} $id uselessvar button_id
4327 ${NS}::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz
4328 pack $cframe.c_$id -in $cframe -side left \
4329 -padx [list $lxpad 0] -expand $cexpand -anchor w
4330 } elseif {[regexp {^t(\d+)$} $type type sz]} {
4331 ${NS}::label $cframe.l_$id -text $title
4332 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4333 -textvariable newviewopts($n,$id)
4334 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0]
4335 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x
4336 } elseif {[regexp {^t(\d+)=$} $type type sz]} {
4337 ${NS}::label $cframe.l_$id -text $title
4338 ${NS}::entry $cframe.e_$id -width $sz -background $bgcolor \
4339 -textvariable newviewopts($n,$id)
4340 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w
4341 pack $cframe.e_$id -in $cframe -side top -fill x
4342 } elseif {$type eq "path"} {
4343 ${NS}::label $top.l -text $title
4344 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3
4345 text $top.t -width 40 -height 5 -background $bgcolor
4346 if {[info exists viewfiles($n)]} {
4347 foreach f $viewfiles($n) {
4348 $top.t insert end $f
4349 $top.t insert end "\n"
4350 }
4351 $top.t delete {end - 1c} end
4352 $top.t mark set insert 0.0
4353 }
4354 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3
4355 }
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004356 }
4357
Pat Thoytsd93f1712009-04-17 01:24:35 +01004358 ${NS}::frame $top.buts
4359 ${NS}::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n]
4360 ${NS}::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1]
4361 ${NS}::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004362 bind $top <Control-Return> [list newviewok $top $n]
4363 bind $top <F5> [list newviewok $top $n 1]
Alexander Gavrilov76f15942008-11-02 21:59:44 +03004364 bind $top <Escape> [list destroy $top]
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004365 grid $top.buts.ok $top.buts.apply $top.buts.can
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004366 grid columnconfigure $top.buts 0 -weight 1 -uniform a
4367 grid columnconfigure $top.buts 1 -weight 1 -uniform a
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004368 grid columnconfigure $top.buts 2 -weight 1 -uniform a
4369 pack $top.buts -in $top -side top -fill x
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004370 focus $top.t
4371}
4372
Paul Mackerras908c3582006-05-20 09:38:11 +10004373proc doviewmenu {m first cmd op argv} {
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004374 set nmenu [$m index end]
4375 for {set i $first} {$i <= $nmenu} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07004376 if {[$m entrycget $i -command] eq $cmd} {
4377 eval $m $op $i $argv
4378 break
4379 }
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004380 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004381}
4382
4383proc allviewmenus {n op args} {
Paul Mackerras687c8762007-09-22 12:49:33 +10004384 # global viewhlmenu
Paul Mackerras908c3582006-05-20 09:38:11 +10004385
Paul Mackerras3cd204e2006-11-23 21:06:16 +11004386 doviewmenu .bar.view 5 [list showview $n] $op $args
Paul Mackerras687c8762007-09-22 12:49:33 +10004387 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004388}
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004389
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004390proc newviewok {top n {apply 0}} {
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004391 global nextviewnum newviewperm newviewname newishighlight
Max Kirillov995f7922015-03-04 05:58:16 +02004392 global viewname viewfiles viewperm viewchanged selectedview curview
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004393 global viewargs viewargscmd newviewopts viewhlmenu
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004394
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004395 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07004396 set newargs [encode_view_opts $n]
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004397 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07004398 error_popup "[mc "Error in commit selection arguments:"] $err" $top
4399 return
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004400 }
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004401 set files {}
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004402 foreach f [split [$top.t get 0.0 end] "\n"] {
Denton Liue2445882020-09-10 21:36:33 -07004403 set ft [string trim $f]
4404 if {$ft ne {}} {
4405 lappend files $ft
4406 }
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004407 }
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004408 if {![info exists viewfiles($n)]} {
Denton Liue2445882020-09-10 21:36:33 -07004409 # creating a new view
4410 incr nextviewnum
4411 set viewname($n) $newviewname($n)
4412 set viewperm($n) $newviewopts($n,perm)
4413 set viewchanged($n) 1
4414 set viewfiles($n) $files
4415 set viewargs($n) $newargs
4416 set viewargscmd($n) $newviewopts($n,cmd)
4417 addviewmenu $n
4418 if {!$newishighlight} {
4419 run showview $n
4420 } else {
4421 run addvhighlight $n
4422 }
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004423 } else {
Denton Liue2445882020-09-10 21:36:33 -07004424 # editing an existing view
4425 set viewperm($n) $newviewopts($n,perm)
4426 set viewchanged($n) 1
4427 if {$newviewname($n) ne $viewname($n)} {
4428 set viewname($n) $newviewname($n)
4429 doviewmenu .bar.view 5 [list showview $n] \
4430 entryconf [list -label $viewname($n)]
4431 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
4432 # entryconf [list -label $viewname($n) -value $viewname($n)]
4433 }
4434 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \
4435 $newviewopts($n,cmd) ne $viewargscmd($n)} {
4436 set viewfiles($n) $files
4437 set viewargs($n) $newargs
4438 set viewargscmd($n) $newviewopts($n,cmd)
4439 if {$curview == $n} {
4440 run reloadcommits
4441 }
4442 }
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004443 }
Alexander Gavrilov218a9002008-11-02 21:59:48 +03004444 if {$apply} return
Paul Mackerrasd16c0812006-04-25 21:21:10 +10004445 catch {destroy $top}
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004446}
4447
4448proc delview {} {
Max Kirillov995f7922015-03-04 05:58:16 +02004449 global curview viewperm hlview selectedhlview viewchanged
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004450
4451 if {$curview == 0} return
Paul Mackerras908c3582006-05-20 09:38:11 +10004452 if {[info exists hlview] && $hlview == $curview} {
Denton Liue2445882020-09-10 21:36:33 -07004453 set selectedhlview [mc "None"]
4454 unset hlview
Paul Mackerras908c3582006-05-20 09:38:11 +10004455 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004456 allviewmenus $curview delete
Paul Mackerrasa90a6d22006-04-25 17:12:46 +10004457 set viewperm($curview) 0
Max Kirillov995f7922015-03-04 05:58:16 +02004458 set viewchanged($curview) 1
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004459 showview 0
4460}
4461
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004462proc addviewmenu {n} {
Paul Mackerras908c3582006-05-20 09:38:11 +10004463 global viewname viewhlmenu
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004464
4465 .bar.view add radiobutton -label $viewname($n) \
Denton Liue2445882020-09-10 21:36:33 -07004466 -command [list showview $n] -variable selectedview -value $n
Paul Mackerras687c8762007-09-22 12:49:33 +10004467 #$viewhlmenu add radiobutton -label $viewname($n) \
4468 # -command [list addvhighlight $n] -variable selectedhlview
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004469}
4470
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004471proc showview {n} {
Paul Mackerras3ed31a82008-04-26 16:00:00 +10004472 global curview cached_commitrow ordertok
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10004473 global displayorder parentlist rowidlist rowisopt rowfinal
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004474 global colormap rowtextx nextcolor canvxmax
4475 global numcommits viewcomplete
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004476 global selectedline currentid canv canvy0
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004477 global treediffs
Paul Mackerras3e766082008-01-13 17:26:30 +11004478 global pending_select mainheadid
Paul Mackerras03800812007-08-29 21:45:21 +10004479 global commitidx
Paul Mackerras3e766082008-01-13 17:26:30 +11004480 global selectedview
Paul Mackerras97645682007-08-23 22:24:38 +10004481 global hlview selectedhlview commitinterest
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004482
4483 if {$n == $curview} return
4484 set selid {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004485 set ymax [lindex [$canv cget -scrollregion] 3]
4486 set span [$canv yview]
4487 set ytop [expr {[lindex $span 0] * $ymax}]
4488 set ybot [expr {[lindex $span 1] * $ymax}]
4489 set yscreen [expr {($ybot - $ytop) / 2}]
Paul Mackerras94b4a692008-05-20 20:51:06 +10004490 if {$selectedline ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07004491 set selid $currentid
4492 set y [yc $selectedline]
4493 if {$ytop < $y && $y < $ybot} {
4494 set yscreen [expr {$y - $ytop}]
4495 }
Paul Mackerrase507fd42007-06-16 21:51:08 +10004496 } elseif {[info exists pending_select]} {
Denton Liue2445882020-09-10 21:36:33 -07004497 set selid $pending_select
4498 unset pending_select
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004499 }
4500 unselectline
Paul Mackerrasfdedbcf2006-04-06 21:22:52 +10004501 normalline
Paul Mackerras009409f2015-05-02 20:53:36 +10004502 unset -nocomplain treediffs
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004503 clear_display
Paul Mackerras908c3582006-05-20 09:38:11 +10004504 if {[info exists hlview] && $hlview == $n} {
Denton Liue2445882020-09-10 21:36:33 -07004505 unset hlview
4506 set selectedhlview [mc "None"]
Paul Mackerras908c3582006-05-20 09:38:11 +10004507 }
Paul Mackerras009409f2015-05-02 20:53:36 +10004508 unset -nocomplain commitinterest
4509 unset -nocomplain cached_commitrow
4510 unset -nocomplain ordertok
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004511
4512 set curview $n
Paul Mackerrasa90a6d22006-04-25 17:12:46 +10004513 set selectedview $n
Giuseppe Bilottad99b4b02015-09-09 15:20:53 +02004514 .bar.view entryconf [mca "&Edit view..."] -state [expr {$n == 0? "disabled": "normal"}]
4515 .bar.view entryconf [mca "&Delete view"] -state [expr {$n == 0? "disabled": "normal"}]
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004516
Paul Mackerrasdf904492007-08-29 22:03:07 +10004517 run refill_reflist
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004518 if {![info exists viewcomplete($n)]} {
Denton Liue2445882020-09-10 21:36:33 -07004519 getcommits $selid
4520 return
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004521 }
4522
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004523 set displayorder {}
4524 set parentlist {}
4525 set rowidlist {}
4526 set rowisopt {}
4527 set rowfinal {}
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10004528 set numcommits $commitidx($n)
Paul Mackerras22626ef2006-04-17 09:56:02 +10004529
Paul Mackerras009409f2015-05-02 20:53:36 +10004530 unset -nocomplain colormap
4531 unset -nocomplain rowtextx
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004532 set nextcolor 0
4533 set canvxmax [$canv cget -width]
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004534 set curview $n
4535 set row 0
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004536 setcanvscroll
4537 set yf 0
Paul Mackerrase507fd42007-06-16 21:51:08 +10004538 set row {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004539 if {$selid ne {} && [commitinview $selid $n]} {
Denton Liue2445882020-09-10 21:36:33 -07004540 set row [rowofcommit $selid]
4541 # try to get the selected row in the same position on the screen
4542 set ymax [lindex [$canv cget -scrollregion] 3]
4543 set ytop [expr {[yc $row] - $yscreen}]
4544 if {$ytop < 0} {
4545 set ytop 0
4546 }
4547 set yf [expr {$ytop * 1.0 / $ymax}]
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004548 }
4549 allcanvs yview moveto $yf
4550 drawvisible
Paul Mackerrase507fd42007-06-16 21:51:08 +10004551 if {$row ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07004552 selectline $row 0
Paul Mackerras3e766082008-01-13 17:26:30 +11004553 } elseif {!$viewcomplete($n)} {
Denton Liue2445882020-09-10 21:36:33 -07004554 reset_pending_select $selid
Paul Mackerrase507fd42007-06-16 21:51:08 +10004555 } else {
Denton Liue2445882020-09-10 21:36:33 -07004556 reset_pending_select {}
Alexander Gavrilov835e62a2008-07-26 20:15:54 +04004557
Denton Liue2445882020-09-10 21:36:33 -07004558 if {[commitinview $pending_select $curview]} {
4559 selectline [rowofcommit $pending_select] 1
4560 } else {
4561 set row [first_real_row]
4562 if {$row < $numcommits} {
4563 selectline $row 0
4564 }
4565 }
Paul Mackerrase507fd42007-06-16 21:51:08 +10004566 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004567 if {!$viewcomplete($n)} {
Denton Liue2445882020-09-10 21:36:33 -07004568 if {$numcommits == 0} {
4569 show_status [mc "Reading commits..."]
4570 }
Paul Mackerras098dd8a2006-05-03 09:32:53 +10004571 } elseif {$numcommits == 0} {
Denton Liue2445882020-09-10 21:36:33 -07004572 show_status [mc "No commits selected"]
Paul Mackerras2516dae2006-04-21 10:35:31 +10004573 }
Marc Branchaud9922c5a2015-04-07 11:51:51 -04004574 set_window_title
Paul Mackerras50b44ec2006-04-04 10:16:22 +10004575}
4576
Paul Mackerras908c3582006-05-20 09:38:11 +10004577# Stuff relating to the highlighting facility
4578
Paul Mackerras476ca632008-01-07 22:16:31 +11004579proc ishighlighted {id} {
Paul Mackerras164ff272006-05-29 19:50:02 +10004580 global vhighlights fhighlights nhighlights rhighlights
Paul Mackerras908c3582006-05-20 09:38:11 +10004581
Paul Mackerras476ca632008-01-07 22:16:31 +11004582 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004583 return $nhighlights($id)
Paul Mackerras908c3582006-05-20 09:38:11 +10004584 }
Paul Mackerras476ca632008-01-07 22:16:31 +11004585 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004586 return $vhighlights($id)
Paul Mackerras908c3582006-05-20 09:38:11 +10004587 }
Paul Mackerras476ca632008-01-07 22:16:31 +11004588 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004589 return $fhighlights($id)
Paul Mackerras908c3582006-05-20 09:38:11 +10004590 }
Paul Mackerras476ca632008-01-07 22:16:31 +11004591 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004592 return $rhighlights($id)
Paul Mackerras164ff272006-05-29 19:50:02 +10004593 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004594 return 0
4595}
4596
Paul Mackerras28593d32008-11-13 23:01:46 +11004597proc bolden {id font} {
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10004598 global canv linehtag currentid boldids need_redisplay markedid
Paul Mackerras908c3582006-05-20 09:38:11 +10004599
Paul Mackerrasd98d50e2008-11-13 22:39:00 +11004600 # need_redisplay = 1 means the display is stale and about to be redrawn
4601 if {$need_redisplay} return
Paul Mackerras28593d32008-11-13 23:01:46 +11004602 lappend boldids $id
4603 $canv itemconf $linehtag($id) -font $font
4604 if {[info exists currentid] && $id eq $currentid} {
Denton Liue2445882020-09-10 21:36:33 -07004605 $canv delete secsel
4606 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
4607 -outline {{}} -tags secsel \
4608 -fill [$canv cget -selectbackground]]
4609 $canv lower $t
Paul Mackerras908c3582006-05-20 09:38:11 +10004610 }
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10004611 if {[info exists markedid] && $id eq $markedid} {
Denton Liue2445882020-09-10 21:36:33 -07004612 make_idmark $id
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10004613 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004614}
4615
Paul Mackerras28593d32008-11-13 23:01:46 +11004616proc bolden_name {id font} {
4617 global canv2 linentag currentid boldnameids need_redisplay
Paul Mackerras908c3582006-05-20 09:38:11 +10004618
Paul Mackerrasd98d50e2008-11-13 22:39:00 +11004619 if {$need_redisplay} return
Paul Mackerras28593d32008-11-13 23:01:46 +11004620 lappend boldnameids $id
4621 $canv2 itemconf $linentag($id) -font $font
4622 if {[info exists currentid] && $id eq $currentid} {
Denton Liue2445882020-09-10 21:36:33 -07004623 $canv2 delete secsel
4624 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \
4625 -outline {{}} -tags secsel \
4626 -fill [$canv2 cget -selectbackground]]
4627 $canv2 lower $t
Paul Mackerras908c3582006-05-20 09:38:11 +10004628 }
4629}
4630
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004631proc unbolden {} {
Paul Mackerras28593d32008-11-13 23:01:46 +11004632 global boldids
Paul Mackerras908c3582006-05-20 09:38:11 +10004633
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004634 set stillbold {}
Paul Mackerras28593d32008-11-13 23:01:46 +11004635 foreach id $boldids {
Denton Liue2445882020-09-10 21:36:33 -07004636 if {![ishighlighted $id]} {
4637 bolden $id mainfont
4638 } else {
4639 lappend stillbold $id
4640 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004641 }
Paul Mackerras28593d32008-11-13 23:01:46 +11004642 set boldids $stillbold
Paul Mackerras908c3582006-05-20 09:38:11 +10004643}
4644
4645proc addvhighlight {n} {
Paul Mackerras476ca632008-01-07 22:16:31 +11004646 global hlview viewcomplete curview vhl_done commitidx
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004647
4648 if {[info exists hlview]} {
Denton Liue2445882020-09-10 21:36:33 -07004649 delvhighlight
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004650 }
4651 set hlview $n
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004652 if {$n != $curview && ![info exists viewcomplete($n)]} {
Denton Liue2445882020-09-10 21:36:33 -07004653 start_rev_list $n
Paul Mackerras908c3582006-05-20 09:38:11 +10004654 }
4655 set vhl_done $commitidx($hlview)
4656 if {$vhl_done > 0} {
Denton Liue2445882020-09-10 21:36:33 -07004657 drawvisible
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004658 }
4659}
4660
Paul Mackerras908c3582006-05-20 09:38:11 +10004661proc delvhighlight {} {
4662 global hlview vhighlights
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004663
4664 if {![info exists hlview]} return
4665 unset hlview
Paul Mackerras009409f2015-05-02 20:53:36 +10004666 unset -nocomplain vhighlights
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004667 unbolden
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004668}
4669
Paul Mackerras908c3582006-05-20 09:38:11 +10004670proc vhighlightmore {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004671 global hlview vhl_done commitidx vhighlights curview
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004672
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004673 set max $commitidx($hlview)
Paul Mackerras908c3582006-05-20 09:38:11 +10004674 set vr [visiblerows]
4675 set r0 [lindex $vr 0]
4676 set r1 [lindex $vr 1]
4677 for {set i $vhl_done} {$i < $max} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07004678 set id [commitonrow $i $hlview]
4679 if {[commitinview $id $curview]} {
4680 set row [rowofcommit $id]
4681 if {$r0 <= $row && $row <= $r1} {
4682 if {![highlighted $row]} {
4683 bolden $id mainfontbold
4684 }
4685 set vhighlights($id) 1
4686 }
4687 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004688 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004689 set vhl_done $max
Paul Mackerrasac1276a2008-03-03 10:11:08 +11004690 return 0
Paul Mackerras908c3582006-05-20 09:38:11 +10004691}
4692
4693proc askvhighlight {row id} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004694 global hlview vhighlights iddrawn
Paul Mackerras908c3582006-05-20 09:38:11 +10004695
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004696 if {[commitinview $id $hlview]} {
Denton Liue2445882020-09-10 21:36:33 -07004697 if {[info exists iddrawn($id)] && ![ishighlighted $id]} {
4698 bolden $id mainfontbold
4699 }
4700 set vhighlights($id) 1
Paul Mackerras908c3582006-05-20 09:38:11 +10004701 } else {
Denton Liue2445882020-09-10 21:36:33 -07004702 set vhighlights($id) 0
Paul Mackerras908c3582006-05-20 09:38:11 +10004703 }
4704}
4705
Paul Mackerras687c8762007-09-22 12:49:33 +10004706proc hfiles_change {} {
Paul Mackerras908c3582006-05-20 09:38:11 +10004707 global highlight_files filehighlight fhighlights fh_serial
Paul Mackerras8b39e042008-12-02 09:02:46 +11004708 global highlight_paths
Paul Mackerras908c3582006-05-20 09:38:11 +10004709
4710 if {[info exists filehighlight]} {
Denton Liue2445882020-09-10 21:36:33 -07004711 # delete previous highlights
4712 catch {close $filehighlight}
4713 unset filehighlight
4714 unset -nocomplain fhighlights
4715 unbolden
4716 unhighlight_filelist
Paul Mackerras908c3582006-05-20 09:38:11 +10004717 }
Paul Mackerras63b79192006-05-20 21:31:52 +10004718 set highlight_paths {}
Paul Mackerras908c3582006-05-20 09:38:11 +10004719 after cancel do_file_hl $fh_serial
4720 incr fh_serial
4721 if {$highlight_files ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07004722 after 300 do_file_hl $fh_serial
Paul Mackerras908c3582006-05-20 09:38:11 +10004723 }
4724}
4725
Paul Mackerras687c8762007-09-22 12:49:33 +10004726proc gdttype_change {name ix op} {
4727 global gdttype highlight_files findstring findpattern
4728
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10004729 stopfinding
Paul Mackerras687c8762007-09-22 12:49:33 +10004730 if {$findstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07004731 if {$gdttype eq [mc "containing:"]} {
4732 if {$highlight_files ne {}} {
4733 set highlight_files {}
4734 hfiles_change
4735 }
4736 findcom_change
4737 } else {
4738 if {$findpattern ne {}} {
4739 set findpattern {}
4740 findcom_change
4741 }
4742 set highlight_files $findstring
4743 hfiles_change
4744 }
4745 drawvisible
Paul Mackerras687c8762007-09-22 12:49:33 +10004746 }
4747 # enable/disable findtype/findloc menus too
4748}
4749
4750proc find_change {name ix op} {
4751 global gdttype findstring highlight_files
4752
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10004753 stopfinding
Christian Stimmingb007ee22007-11-07 18:44:35 +01004754 if {$gdttype eq [mc "containing:"]} {
Denton Liue2445882020-09-10 21:36:33 -07004755 findcom_change
Paul Mackerras687c8762007-09-22 12:49:33 +10004756 } else {
Denton Liue2445882020-09-10 21:36:33 -07004757 if {$highlight_files ne $findstring} {
4758 set highlight_files $findstring
4759 hfiles_change
4760 }
Paul Mackerras687c8762007-09-22 12:49:33 +10004761 }
4762 drawvisible
4763}
4764
Paul Mackerras64b5f142007-10-04 22:19:24 +10004765proc findcom_change args {
Paul Mackerras28593d32008-11-13 23:01:46 +11004766 global nhighlights boldnameids
Paul Mackerras687c8762007-09-22 12:49:33 +10004767 global findpattern findtype findstring gdttype
4768
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10004769 stopfinding
Paul Mackerras687c8762007-09-22 12:49:33 +10004770 # delete previous highlights, if any
Paul Mackerras28593d32008-11-13 23:01:46 +11004771 foreach id $boldnameids {
Denton Liue2445882020-09-10 21:36:33 -07004772 bolden_name $id mainfont
Paul Mackerras687c8762007-09-22 12:49:33 +10004773 }
Paul Mackerras28593d32008-11-13 23:01:46 +11004774 set boldnameids {}
Paul Mackerras009409f2015-05-02 20:53:36 +10004775 unset -nocomplain nhighlights
Paul Mackerras687c8762007-09-22 12:49:33 +10004776 unbolden
4777 unmarkmatches
Christian Stimmingb007ee22007-11-07 18:44:35 +01004778 if {$gdttype ne [mc "containing:"] || $findstring eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07004779 set findpattern {}
Christian Stimmingb007ee22007-11-07 18:44:35 +01004780 } elseif {$findtype eq [mc "Regexp"]} {
Denton Liue2445882020-09-10 21:36:33 -07004781 set findpattern $findstring
Paul Mackerras687c8762007-09-22 12:49:33 +10004782 } else {
Denton Liue2445882020-09-10 21:36:33 -07004783 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
4784 $findstring]
4785 set findpattern "*$e*"
Paul Mackerras687c8762007-09-22 12:49:33 +10004786 }
4787}
4788
Paul Mackerras63b79192006-05-20 21:31:52 +10004789proc makepatterns {l} {
4790 set ret {}
4791 foreach e $l {
Denton Liue2445882020-09-10 21:36:33 -07004792 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e]
4793 if {[string index $ee end] eq "/"} {
4794 lappend ret "$ee*"
4795 } else {
4796 lappend ret $ee
4797 lappend ret "$ee/*"
4798 }
Paul Mackerras63b79192006-05-20 21:31:52 +10004799 }
4800 return $ret
4801}
4802
Paul Mackerras908c3582006-05-20 09:38:11 +10004803proc do_file_hl {serial} {
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004804 global highlight_files filehighlight highlight_paths gdttype fhl_list
Yggy Kingde665fd2011-07-13 01:30:26 -07004805 global cdup findtype
Paul Mackerras908c3582006-05-20 09:38:11 +10004806
Christian Stimmingb007ee22007-11-07 18:44:35 +01004807 if {$gdttype eq [mc "touching paths:"]} {
Denton Liue2445882020-09-10 21:36:33 -07004808 # If "exact" match then convert backslashes to forward slashes.
4809 # Most useful to support Windows-flavoured file paths.
4810 if {$findtype eq [mc "Exact"]} {
4811 set highlight_files [string map {"\\" "/"} $highlight_files]
4812 }
4813 if {[catch {set paths [shellsplit $highlight_files]}]} return
4814 set highlight_paths [makepatterns $paths]
4815 highlight_filelist
4816 set relative_paths {}
4817 foreach path $paths {
4818 lappend relative_paths [file join $cdup $path]
4819 }
4820 set gdtargs [concat -- $relative_paths]
Christian Stimmingb007ee22007-11-07 18:44:35 +01004821 } elseif {$gdttype eq [mc "adding/removing string:"]} {
Denton Liue2445882020-09-10 21:36:33 -07004822 set gdtargs [list "-S$highlight_files"]
Martin Langhoffc33cb902012-06-14 20:34:11 +02004823 } elseif {$gdttype eq [mc "changing lines matching:"]} {
Denton Liue2445882020-09-10 21:36:33 -07004824 set gdtargs [list "-G$highlight_files"]
Paul Mackerras687c8762007-09-22 12:49:33 +10004825 } else {
Denton Liue2445882020-09-10 21:36:33 -07004826 # must be "containing:", i.e. we're searching commit info
4827 return
Paul Mackerras60f7a7d2006-05-26 10:43:47 +10004828 }
Brandon Casey1ce09dd2007-03-19 18:00:37 -05004829 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
Paul Mackerras908c3582006-05-20 09:38:11 +10004830 set filehighlight [open $cmd r+]
4831 fconfigure $filehighlight -blocking 0
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10004832 filerun $filehighlight readfhighlight
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004833 set fhl_list {}
Paul Mackerras908c3582006-05-20 09:38:11 +10004834 drawvisible
4835 flushhighlights
4836}
4837
4838proc flushhighlights {} {
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004839 global filehighlight fhl_list
Paul Mackerras908c3582006-05-20 09:38:11 +10004840
4841 if {[info exists filehighlight]} {
Denton Liue2445882020-09-10 21:36:33 -07004842 lappend fhl_list {}
4843 puts $filehighlight ""
4844 flush $filehighlight
Paul Mackerras908c3582006-05-20 09:38:11 +10004845 }
4846}
4847
4848proc askfilehighlight {row id} {
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004849 global filehighlight fhighlights fhl_list
Paul Mackerras908c3582006-05-20 09:38:11 +10004850
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004851 lappend fhl_list $id
Paul Mackerras476ca632008-01-07 22:16:31 +11004852 set fhighlights($id) -1
Paul Mackerras908c3582006-05-20 09:38:11 +10004853 puts $filehighlight $id
4854}
4855
4856proc readfhighlight {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004857 global filehighlight fhighlights curview iddrawn
Paul Mackerras687c8762007-09-22 12:49:33 +10004858 global fhl_list find_dirn
Paul Mackerras908c3582006-05-20 09:38:11 +10004859
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10004860 if {![info exists filehighlight]} {
Denton Liue2445882020-09-10 21:36:33 -07004861 return 0
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10004862 }
4863 set nr 0
4864 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07004865 set line [string trim $line]
4866 set i [lsearch -exact $fhl_list $line]
4867 if {$i < 0} continue
4868 for {set j 0} {$j < $i} {incr j} {
4869 set id [lindex $fhl_list $j]
4870 set fhighlights($id) 0
4871 }
4872 set fhl_list [lrange $fhl_list [expr {$i+1}] end]
4873 if {$line eq {}} continue
4874 if {![commitinview $line $curview]} continue
4875 if {[info exists iddrawn($line)] && ![ishighlighted $line]} {
4876 bolden $line mainfontbold
4877 }
4878 set fhighlights($line) 1
Paul Mackerras908c3582006-05-20 09:38:11 +10004879 }
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004880 if {[eof $filehighlight]} {
Denton Liue2445882020-09-10 21:36:33 -07004881 # strange...
4882 puts "oops, git diff-tree died"
4883 catch {close $filehighlight}
4884 unset filehighlight
4885 return 0
Paul Mackerras908c3582006-05-20 09:38:11 +10004886 }
Paul Mackerras687c8762007-09-22 12:49:33 +10004887 if {[info exists find_dirn]} {
Denton Liue2445882020-09-10 21:36:33 -07004888 run findmore
Paul Mackerras687c8762007-09-22 12:49:33 +10004889 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10004890 return 1
Paul Mackerras908c3582006-05-20 09:38:11 +10004891}
4892
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004893proc doesmatch {f} {
Paul Mackerras687c8762007-09-22 12:49:33 +10004894 global findtype findpattern
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004895
Christian Stimmingb007ee22007-11-07 18:44:35 +01004896 if {$findtype eq [mc "Regexp"]} {
Denton Liue2445882020-09-10 21:36:33 -07004897 return [regexp $findpattern $f]
Christian Stimmingb007ee22007-11-07 18:44:35 +01004898 } elseif {$findtype eq [mc "IgnCase"]} {
Denton Liue2445882020-09-10 21:36:33 -07004899 return [string match -nocase $findpattern $f]
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004900 } else {
Denton Liue2445882020-09-10 21:36:33 -07004901 return [string match $findpattern $f]
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004902 }
4903}
4904
Paul Mackerras60f7a7d2006-05-26 10:43:47 +10004905proc askfindhighlight {row id} {
Paul Mackerras9c311b32007-10-04 22:27:13 +10004906 global nhighlights commitinfo iddrawn
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004907 global findloc
4908 global markingmatches
Paul Mackerras908c3582006-05-20 09:38:11 +10004909
4910 if {![info exists commitinfo($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07004911 getcommit $id
Paul Mackerras908c3582006-05-20 09:38:11 +10004912 }
Paul Mackerras60f7a7d2006-05-26 10:43:47 +10004913 set info $commitinfo($id)
Paul Mackerras908c3582006-05-20 09:38:11 +10004914 set isbold 0
Frédéric Brière585c27c2010-03-14 18:59:09 -04004915 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]]
Paul Mackerras60f7a7d2006-05-26 10:43:47 +10004916 foreach f $info ty $fldtypes {
Denton Liue2445882020-09-10 21:36:33 -07004917 if {$ty eq ""} continue
4918 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
4919 [doesmatch $f]} {
4920 if {$ty eq [mc "Author"]} {
4921 set isbold 2
4922 break
4923 }
4924 set isbold 1
4925 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004926 }
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004927 if {$isbold && [info exists iddrawn($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07004928 if {![ishighlighted $id]} {
4929 bolden $id mainfontbold
4930 if {$isbold > 1} {
4931 bolden_name $id mainfontbold
4932 }
4933 }
4934 if {$markingmatches} {
4935 markrowmatches $row $id
4936 }
Paul Mackerras908c3582006-05-20 09:38:11 +10004937 }
Paul Mackerras476ca632008-01-07 22:16:31 +11004938 set nhighlights($id) $isbold
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10004939}
4940
Paul Mackerras005a2f42007-07-26 22:36:39 +10004941proc markrowmatches {row id} {
4942 global canv canv2 linehtag linentag commitinfo findloc
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004943
Paul Mackerras005a2f42007-07-26 22:36:39 +10004944 set headline [lindex $commitinfo($id) 0]
4945 set author [lindex $commitinfo($id) 1]
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004946 $canv delete match$row
4947 $canv2 delete match$row
Christian Stimmingb007ee22007-11-07 18:44:35 +01004948 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} {
Denton Liue2445882020-09-10 21:36:33 -07004949 set m [findmatches $headline]
4950 if {$m ne {}} {
4951 markmatches $canv $row $headline $linehtag($id) $m \
4952 [$canv itemcget $linehtag($id) -font] $row
4953 }
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004954 }
Christian Stimmingb007ee22007-11-07 18:44:35 +01004955 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} {
Denton Liue2445882020-09-10 21:36:33 -07004956 set m [findmatches $author]
4957 if {$m ne {}} {
4958 markmatches $canv2 $row $author $linentag($id) $m \
4959 [$canv2 itemcget $linentag($id) -font] $row
4960 }
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10004961 }
4962}
4963
Paul Mackerras164ff272006-05-29 19:50:02 +10004964proc vrel_change {name ix op} {
4965 global highlight_related
4966
4967 rhighlight_none
Christian Stimmingb007ee22007-11-07 18:44:35 +01004968 if {$highlight_related ne [mc "None"]} {
Denton Liue2445882020-09-10 21:36:33 -07004969 run drawvisible
Paul Mackerras164ff272006-05-29 19:50:02 +10004970 }
4971}
4972
4973# prepare for testing whether commits are descendents or ancestors of a
4974proc rhighlight_sel {a} {
4975 global descendent desc_todo ancestor anc_todo
Paul Mackerras476ca632008-01-07 22:16:31 +11004976 global highlight_related
Paul Mackerras164ff272006-05-29 19:50:02 +10004977
Paul Mackerras009409f2015-05-02 20:53:36 +10004978 unset -nocomplain descendent
Paul Mackerras164ff272006-05-29 19:50:02 +10004979 set desc_todo [list $a]
Paul Mackerras009409f2015-05-02 20:53:36 +10004980 unset -nocomplain ancestor
Paul Mackerras164ff272006-05-29 19:50:02 +10004981 set anc_todo [list $a]
Christian Stimmingb007ee22007-11-07 18:44:35 +01004982 if {$highlight_related ne [mc "None"]} {
Denton Liue2445882020-09-10 21:36:33 -07004983 rhighlight_none
4984 run drawvisible
Paul Mackerras164ff272006-05-29 19:50:02 +10004985 }
4986}
4987
4988proc rhighlight_none {} {
4989 global rhighlights
4990
Paul Mackerras009409f2015-05-02 20:53:36 +10004991 unset -nocomplain rhighlights
Paul Mackerras4e7d6772006-05-30 21:33:07 +10004992 unbolden
Paul Mackerras164ff272006-05-29 19:50:02 +10004993}
4994
4995proc is_descendent {a} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004996 global curview children descendent desc_todo
Paul Mackerras164ff272006-05-29 19:50:02 +10004997
4998 set v $curview
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11004999 set la [rowofcommit $a]
Paul Mackerras164ff272006-05-29 19:50:02 +10005000 set todo $desc_todo
5001 set leftover {}
5002 set done 0
5003 for {set i 0} {$i < [llength $todo]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07005004 set do [lindex $todo $i]
5005 if {[rowofcommit $do] < $la} {
5006 lappend leftover $do
5007 continue
5008 }
5009 foreach nk $children($v,$do) {
5010 if {![info exists descendent($nk)]} {
5011 set descendent($nk) 1
5012 lappend todo $nk
5013 if {$nk eq $a} {
5014 set done 1
5015 }
5016 }
5017 }
5018 if {$done} {
5019 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
5020 return
5021 }
Paul Mackerras164ff272006-05-29 19:50:02 +10005022 }
5023 set descendent($a) 0
5024 set desc_todo $leftover
5025}
5026
5027proc is_ancestor {a} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005028 global curview parents ancestor anc_todo
Paul Mackerras164ff272006-05-29 19:50:02 +10005029
5030 set v $curview
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005031 set la [rowofcommit $a]
Paul Mackerras164ff272006-05-29 19:50:02 +10005032 set todo $anc_todo
5033 set leftover {}
5034 set done 0
5035 for {set i 0} {$i < [llength $todo]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07005036 set do [lindex $todo $i]
5037 if {![commitinview $do $v] || [rowofcommit $do] > $la} {
5038 lappend leftover $do
5039 continue
5040 }
5041 foreach np $parents($v,$do) {
5042 if {![info exists ancestor($np)]} {
5043 set ancestor($np) 1
5044 lappend todo $np
5045 if {$np eq $a} {
5046 set done 1
5047 }
5048 }
5049 }
5050 if {$done} {
5051 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
5052 return
5053 }
Paul Mackerras164ff272006-05-29 19:50:02 +10005054 }
5055 set ancestor($a) 0
5056 set anc_todo $leftover
5057}
5058
5059proc askrelhighlight {row id} {
Paul Mackerras9c311b32007-10-04 22:27:13 +10005060 global descendent highlight_related iddrawn rhighlights
Paul Mackerras164ff272006-05-29 19:50:02 +10005061 global selectedline ancestor
5062
Paul Mackerras94b4a692008-05-20 20:51:06 +10005063 if {$selectedline eq {}} return
Paul Mackerras164ff272006-05-29 19:50:02 +10005064 set isbold 0
Christian Stimming55e34432008-01-09 22:23:18 +01005065 if {$highlight_related eq [mc "Descendant"] ||
Denton Liue2445882020-09-10 21:36:33 -07005066 $highlight_related eq [mc "Not descendant"]} {
5067 if {![info exists descendent($id)]} {
5068 is_descendent $id
5069 }
5070 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} {
5071 set isbold 1
5072 }
Christian Stimmingb007ee22007-11-07 18:44:35 +01005073 } elseif {$highlight_related eq [mc "Ancestor"] ||
Denton Liue2445882020-09-10 21:36:33 -07005074 $highlight_related eq [mc "Not ancestor"]} {
5075 if {![info exists ancestor($id)]} {
5076 is_ancestor $id
5077 }
5078 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} {
5079 set isbold 1
5080 }
Paul Mackerras164ff272006-05-29 19:50:02 +10005081 }
5082 if {[info exists iddrawn($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005083 if {$isbold && ![ishighlighted $id]} {
5084 bolden $id mainfontbold
5085 }
Paul Mackerras164ff272006-05-29 19:50:02 +10005086 }
Paul Mackerras476ca632008-01-07 22:16:31 +11005087 set rhighlights($id) $isbold
Paul Mackerras164ff272006-05-29 19:50:02 +10005088}
5089
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10005090# Graph layout functions
5091
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005092proc shortids {ids} {
5093 set res {}
5094 foreach id $ids {
Denton Liue2445882020-09-10 21:36:33 -07005095 if {[llength $id] > 1} {
5096 lappend res [shortids $id]
5097 } elseif {[regexp {^[0-9a-f]{40}$} $id]} {
5098 lappend res [string range $id 0 7]
5099 } else {
5100 lappend res $id
5101 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005102 }
5103 return $res
5104}
5105
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005106proc ntimes {n o} {
5107 set ret {}
Paul Mackerras03800812007-08-29 21:45:21 +10005108 set o [list $o]
5109 for {set mask 1} {$mask <= $n} {incr mask $mask} {
Denton Liue2445882020-09-10 21:36:33 -07005110 if {($n & $mask) != 0} {
5111 set ret [concat $ret $o]
5112 }
5113 set o [concat $o $o]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005114 }
5115 return $ret
5116}
5117
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005118proc ordertoken {id} {
5119 global ordertok curview varcid varcstart varctok curview parents children
5120 global nullid nullid2
5121
5122 if {[info exists ordertok($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005123 return $ordertok($id)
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005124 }
5125 set origid $id
5126 set todo {}
5127 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07005128 if {[info exists varcid($curview,$id)]} {
5129 set a $varcid($curview,$id)
5130 set p [lindex $varcstart($curview) $a]
5131 } else {
5132 set p [lindex $children($curview,$id) 0]
5133 }
5134 if {[info exists ordertok($p)]} {
5135 set tok $ordertok($p)
5136 break
5137 }
5138 set id [first_real_child $curview,$p]
5139 if {$id eq {}} {
5140 # it's a root
5141 set tok [lindex $varctok($curview) $varcid($curview,$p)]
5142 break
5143 }
5144 if {[llength $parents($curview,$id)] == 1} {
5145 lappend todo [list $p {}]
5146 } else {
5147 set j [lsearch -exact $parents($curview,$id) $p]
5148 if {$j < 0} {
5149 puts "oops didn't find [shortids $p] in parents of [shortids $id]"
5150 }
5151 lappend todo [list $p [strrep $j]]
5152 }
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005153 }
5154 for {set i [llength $todo]} {[incr i -1] >= 0} {} {
Denton Liue2445882020-09-10 21:36:33 -07005155 set p [lindex $todo $i 0]
5156 append tok [lindex $todo $i 1]
5157 set ordertok($p) $tok
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005158 }
5159 set ordertok($origid) $tok
5160 return $tok
5161}
5162
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005163# Work out where id should go in idlist so that order-token
5164# values increase from left to right
5165proc idcol {idlist id {i 0}} {
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005166 set t [ordertoken $id]
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11005167 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005168 set i 0
Paul Mackerrase5b37ac2007-12-12 18:13:51 +11005169 }
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005170 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} {
Denton Liue2445882020-09-10 21:36:33 -07005171 if {$i > [llength $idlist]} {
5172 set i [llength $idlist]
5173 }
5174 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {}
5175 incr i
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005176 } else {
Denton Liue2445882020-09-10 21:36:33 -07005177 if {$t > [ordertoken [lindex $idlist $i]]} {
5178 while {[incr i] < [llength $idlist] &&
5179 $t >= [ordertoken [lindex $idlist $i]]} {}
5180 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005181 }
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005182 return $i
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005183}
5184
5185proc initlayout {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005186 global rowidlist rowisopt rowfinal displayorder parentlist
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10005187 global numcommits canvxmax canv
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11005188 global nextcolor
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10005189 global colormap rowtextx
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005190
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11005191 set numcommits 0
5192 set displayorder {}
Paul Mackerras79b2c752006-04-02 20:47:40 +10005193 set parentlist {}
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11005194 set nextcolor 0
Paul Mackerras03800812007-08-29 21:45:21 +10005195 set rowidlist {}
5196 set rowisopt {}
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005197 set rowfinal {}
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11005198 set canvxmax [$canv cget -width]
Paul Mackerras009409f2015-05-02 20:53:36 +10005199 unset -nocomplain colormap
5200 unset -nocomplain rowtextx
Paul Mackerrasac1276a2008-03-03 10:11:08 +11005201 setcanvscroll
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11005202}
5203
5204proc setcanvscroll {} {
5205 global canv canv2 canv3 numcommits linespc canvxmax canvy0
Paul Mackerrasac1276a2008-03-03 10:11:08 +11005206 global lastscrollset lastscrollrows
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11005207
5208 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
5209 $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
5210 $canv2 conf -scrollregion [list 0 0 0 $ymax]
5211 $canv3 conf -scrollregion [list 0 0 0 $ymax]
Paul Mackerrasac1276a2008-03-03 10:11:08 +11005212 set lastscrollset [clock clicks -milliseconds]
5213 set lastscrollrows $numcommits
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005214}
5215
5216proc visiblerows {} {
5217 global canv numcommits linespc
5218
5219 set ymax [lindex [$canv cget -scrollregion] 3]
5220 if {$ymax eq {} || $ymax == 0} return
5221 set f [$canv yview]
5222 set y0 [expr {int([lindex $f 0] * $ymax)}]
5223 set r0 [expr {int(($y0 - 3) / $linespc) - 1}]
5224 if {$r0 < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005225 set r0 0
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005226 }
5227 set y1 [expr {int([lindex $f 1] * $ymax)}]
5228 set r1 [expr {int(($y1 - 3) / $linespc) + 1}]
5229 if {$r1 >= $numcommits} {
Denton Liue2445882020-09-10 21:36:33 -07005230 set r1 [expr {$numcommits - 1}]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005231 }
5232 return [list $r0 $r1]
5233}
5234
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005235proc layoutmore {} {
Paul Mackerras38dfe932007-12-06 20:50:31 +11005236 global commitidx viewcomplete curview
Paul Mackerras94b4a692008-05-20 20:51:06 +10005237 global numcommits pending_select curview
Paul Mackerrasd375ef92008-10-21 10:18:12 +11005238 global lastscrollset lastscrollrows
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005239
Paul Mackerrasac1276a2008-03-03 10:11:08 +11005240 if {$lastscrollrows < 100 || $viewcomplete($curview) ||
Denton Liue2445882020-09-10 21:36:33 -07005241 [clock clicks -milliseconds] - $lastscrollset > 500} {
5242 setcanvscroll
Paul Mackerrasa2c22362006-10-31 15:00:53 +11005243 }
Paul Mackerrasd94f8cd2006-04-06 10:18:23 +10005244 if {[info exists pending_select] &&
Denton Liue2445882020-09-10 21:36:33 -07005245 [commitinview $pending_select $curview]} {
5246 update
5247 selectline [rowofcommit $pending_select] 1
Paul Mackerrasd94f8cd2006-04-06 10:18:23 +10005248 }
Paul Mackerrasac1276a2008-03-03 10:11:08 +11005249 drawvisible
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005250}
5251
Paul Mackerrascdc84292008-11-18 19:54:14 +11005252# With path limiting, we mightn't get the actual HEAD commit,
5253# so ask git rev-list what is the first ancestor of HEAD that
5254# touches a file in the path limit.
5255proc get_viewmainhead {view} {
5256 global viewmainheadid vfilelimit viewinstances mainheadid
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005257
Paul Mackerrascdc84292008-11-18 19:54:14 +11005258 catch {
Denton Liue2445882020-09-10 21:36:33 -07005259 set rfd [open [concat | git rev-list -1 $mainheadid \
5260 -- $vfilelimit($view)] r]
5261 set j [reg_instance $rfd]
5262 lappend viewinstances($view) $j
5263 fconfigure $rfd -blocking 0
5264 filerun $rfd [list getviewhead $rfd $j $view]
5265 set viewmainheadid($curview) {}
Paul Mackerrascdc84292008-11-18 19:54:14 +11005266 }
5267}
5268
5269# git rev-list should give us just 1 line to use as viewmainheadid($view)
5270proc getviewhead {fd inst view} {
5271 global viewmainheadid commfd curview viewinstances showlocalchanges
5272
5273 set id {}
5274 if {[gets $fd line] < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005275 if {![eof $fd]} {
5276 return 1
5277 }
Paul Mackerrascdc84292008-11-18 19:54:14 +11005278 } elseif {[string length $line] == 40 && [string is xdigit $line]} {
Denton Liue2445882020-09-10 21:36:33 -07005279 set id $line
Paul Mackerrascdc84292008-11-18 19:54:14 +11005280 }
5281 set viewmainheadid($view) $id
5282 close $fd
5283 unset commfd($inst)
5284 set i [lsearch -exact $viewinstances($view) $inst]
5285 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07005286 set viewinstances($view) [lreplace $viewinstances($view) $i $i]
Paul Mackerrascdc84292008-11-18 19:54:14 +11005287 }
5288 if {$showlocalchanges && $id ne {} && $view == $curview} {
Denton Liue2445882020-09-10 21:36:33 -07005289 doshowlocalchanges
Paul Mackerrascdc84292008-11-18 19:54:14 +11005290 }
5291 return 0
5292}
5293
5294proc doshowlocalchanges {} {
5295 global curview viewmainheadid
5296
5297 if {$viewmainheadid($curview) eq {}} return
5298 if {[commitinview $viewmainheadid($curview) $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005299 dodiffindex
Paul Mackerras38dfe932007-12-06 20:50:31 +11005300 } else {
Denton Liue2445882020-09-10 21:36:33 -07005301 interestedin $viewmainheadid($curview) dodiffindex
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005302 }
5303}
5304
5305proc dohidelocalchanges {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005306 global nullid nullid2 lserial curview
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005307
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005308 if {[commitinview $nullid $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005309 removefakerow $nullid
Paul Mackerras8f489362007-07-13 19:49:37 +10005310 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005311 if {[commitinview $nullid2 $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005312 removefakerow $nullid2
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005313 }
5314 incr lserial
5315}
5316
Paul Mackerras8f489362007-07-13 19:49:37 +10005317# spawn off a process to do git diff-index --cached HEAD
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005318proc dodiffindex {} {
Paul Mackerrascdc84292008-11-18 19:54:14 +11005319 global lserial showlocalchanges vfilelimit curview
Jens Lehmann17f98362014-04-08 21:36:08 +02005320 global hasworktree git_version
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005321
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -04005322 if {!$showlocalchanges || !$hasworktree} return
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005323 incr lserial
Jens Lehmann17f98362014-04-08 21:36:08 +02005324 if {[package vcompare $git_version "1.7.2"] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07005325 set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD"
Jens Lehmann17f98362014-04-08 21:36:08 +02005326 } else {
Denton Liue2445882020-09-10 21:36:33 -07005327 set cmd "|git diff-index --cached HEAD"
Jens Lehmann17f98362014-04-08 21:36:08 +02005328 }
Paul Mackerrascdc84292008-11-18 19:54:14 +11005329 if {$vfilelimit($curview) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07005330 set cmd [concat $cmd -- $vfilelimit($curview)]
Paul Mackerrascdc84292008-11-18 19:54:14 +11005331 }
5332 set fd [open $cmd r]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005333 fconfigure $fd -blocking 0
Alexander Gavrilove439e092008-07-13 16:40:47 +04005334 set i [reg_instance $fd]
5335 filerun $fd [list readdiffindex $fd $lserial $i]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005336}
5337
Alexander Gavrilove439e092008-07-13 16:40:47 +04005338proc readdiffindex {fd serial inst} {
Paul Mackerrascdc84292008-11-18 19:54:14 +11005339 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
5340 global vfilelimit
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005341
Paul Mackerras8f489362007-07-13 19:49:37 +10005342 set isdiff 1
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005343 if {[gets $fd line] < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005344 if {![eof $fd]} {
5345 return 1
5346 }
5347 set isdiff 0
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005348 }
5349 # we only need to see one line and we don't really care what it says...
Alexander Gavrilove439e092008-07-13 16:40:47 +04005350 stop_instance $inst
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005351
Paul Mackerras24f7a662007-12-19 09:35:33 +11005352 if {$serial != $lserial} {
Denton Liue2445882020-09-10 21:36:33 -07005353 return 0
Paul Mackerras8f489362007-07-13 19:49:37 +10005354 }
5355
Paul Mackerras24f7a662007-12-19 09:35:33 +11005356 # now see if there are any local changes not checked in to the index
Paul Mackerrascdc84292008-11-18 19:54:14 +11005357 set cmd "|git diff-files"
5358 if {$vfilelimit($curview) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07005359 set cmd [concat $cmd -- $vfilelimit($curview)]
Paul Mackerrascdc84292008-11-18 19:54:14 +11005360 }
5361 set fd [open $cmd r]
Paul Mackerras24f7a662007-12-19 09:35:33 +11005362 fconfigure $fd -blocking 0
Alexander Gavrilove439e092008-07-13 16:40:47 +04005363 set i [reg_instance $fd]
5364 filerun $fd [list readdifffiles $fd $serial $i]
Paul Mackerras24f7a662007-12-19 09:35:33 +11005365
5366 if {$isdiff && ![commitinview $nullid2 $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005367 # add the line for the changes in the index to the graph
5368 set hl [mc "Local changes checked in to index but not committed"]
5369 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"]
5370 set commitdata($nullid2) "\n $hl\n"
5371 if {[commitinview $nullid $curview]} {
5372 removefakerow $nullid
5373 }
5374 insertfakerow $nullid2 $viewmainheadid($curview)
Paul Mackerras24f7a662007-12-19 09:35:33 +11005375 } elseif {!$isdiff && [commitinview $nullid2 $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005376 if {[commitinview $nullid $curview]} {
5377 removefakerow $nullid
5378 }
5379 removefakerow $nullid2
Paul Mackerras8f489362007-07-13 19:49:37 +10005380 }
5381 return 0
5382}
5383
Alexander Gavrilove439e092008-07-13 16:40:47 +04005384proc readdifffiles {fd serial inst} {
Paul Mackerrascdc84292008-11-18 19:54:14 +11005385 global viewmainheadid nullid nullid2 curview
Paul Mackerras8f489362007-07-13 19:49:37 +10005386 global commitinfo commitdata lserial
5387
5388 set isdiff 1
5389 if {[gets $fd line] < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005390 if {![eof $fd]} {
5391 return 1
5392 }
5393 set isdiff 0
Paul Mackerras8f489362007-07-13 19:49:37 +10005394 }
5395 # we only need to see one line and we don't really care what it says...
Alexander Gavrilove439e092008-07-13 16:40:47 +04005396 stop_instance $inst
Paul Mackerras8f489362007-07-13 19:49:37 +10005397
Paul Mackerras24f7a662007-12-19 09:35:33 +11005398 if {$serial != $lserial} {
Denton Liue2445882020-09-10 21:36:33 -07005399 return 0
Paul Mackerras24f7a662007-12-19 09:35:33 +11005400 }
5401
5402 if {$isdiff && ![commitinview $nullid $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005403 # add the line for the local diff to the graph
5404 set hl [mc "Local uncommitted changes, not checked in to index"]
5405 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"]
5406 set commitdata($nullid) "\n $hl\n"
5407 if {[commitinview $nullid2 $curview]} {
5408 set p $nullid2
5409 } else {
5410 set p $viewmainheadid($curview)
5411 }
5412 insertfakerow $nullid $p
Paul Mackerras24f7a662007-12-19 09:35:33 +11005413 } elseif {!$isdiff && [commitinview $nullid $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005414 removefakerow $nullid
Paul Mackerras219ea3a2006-09-07 10:21:39 +10005415 }
5416 return 0
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005417}
5418
Paul Mackerras8f0bc7e2007-08-24 22:16:42 +10005419proc nextuse {id row} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005420 global curview children
Paul Mackerras8f0bc7e2007-08-24 22:16:42 +10005421
5422 if {[info exists children($curview,$id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005423 foreach kid $children($curview,$id) {
5424 if {![commitinview $kid $curview]} {
5425 return -1
5426 }
5427 if {[rowofcommit $kid] > $row} {
5428 return [rowofcommit $kid]
5429 }
5430 }
Paul Mackerras8f0bc7e2007-08-24 22:16:42 +10005431 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005432 if {[commitinview $id $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07005433 return [rowofcommit $id]
Paul Mackerras8f0bc7e2007-08-24 22:16:42 +10005434 }
5435 return -1
5436}
5437
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005438proc prevuse {id row} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005439 global curview children
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005440
5441 set ret -1
5442 if {[info exists children($curview,$id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005443 foreach kid $children($curview,$id) {
5444 if {![commitinview $kid $curview]} break
5445 if {[rowofcommit $kid] < $row} {
5446 set ret [rowofcommit $kid]
5447 }
5448 }
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005449 }
5450 return $ret
5451}
5452
Paul Mackerras03800812007-08-29 21:45:21 +10005453proc make_idlist {row} {
5454 global displayorder parentlist uparrowlen downarrowlen mingaplen
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005455 global commitidx curview children
Paul Mackerras03800812007-08-29 21:45:21 +10005456
5457 set r [expr {$row - $mingaplen - $downarrowlen - 1}]
5458 if {$r < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005459 set r 0
Paul Mackerras03800812007-08-29 21:45:21 +10005460 }
5461 set ra [expr {$row - $downarrowlen}]
5462 if {$ra < 0} {
Denton Liue2445882020-09-10 21:36:33 -07005463 set ra 0
Paul Mackerras03800812007-08-29 21:45:21 +10005464 }
5465 set rb [expr {$row + $uparrowlen}]
5466 if {$rb > $commitidx($curview)} {
Denton Liue2445882020-09-10 21:36:33 -07005467 set rb $commitidx($curview)
Paul Mackerras03800812007-08-29 21:45:21 +10005468 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005469 make_disporder $r [expr {$rb + 1}]
Paul Mackerras03800812007-08-29 21:45:21 +10005470 set ids {}
5471 for {} {$r < $ra} {incr r} {
Denton Liue2445882020-09-10 21:36:33 -07005472 set nextid [lindex $displayorder [expr {$r + 1}]]
5473 foreach p [lindex $parentlist $r] {
5474 if {$p eq $nextid} continue
5475 set rn [nextuse $p $r]
5476 if {$rn >= $row &&
5477 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} {
5478 lappend ids [list [ordertoken $p] $p]
5479 }
5480 }
Paul Mackerras03800812007-08-29 21:45:21 +10005481 }
5482 for {} {$r < $row} {incr r} {
Denton Liue2445882020-09-10 21:36:33 -07005483 set nextid [lindex $displayorder [expr {$r + 1}]]
5484 foreach p [lindex $parentlist $r] {
5485 if {$p eq $nextid} continue
5486 set rn [nextuse $p $r]
5487 if {$rn < 0 || $rn >= $row} {
5488 lappend ids [list [ordertoken $p] $p]
5489 }
5490 }
Paul Mackerras03800812007-08-29 21:45:21 +10005491 }
5492 set id [lindex $displayorder $row]
Paul Mackerras9257d8f2007-12-11 10:45:38 +11005493 lappend ids [list [ordertoken $id] $id]
Paul Mackerras03800812007-08-29 21:45:21 +10005494 while {$r < $rb} {
Denton Liue2445882020-09-10 21:36:33 -07005495 foreach p [lindex $parentlist $r] {
5496 set firstkid [lindex $children($curview,$p) 0]
5497 if {[rowofcommit $firstkid] < $row} {
5498 lappend ids [list [ordertoken $p] $p]
5499 }
5500 }
5501 incr r
5502 set id [lindex $displayorder $r]
5503 if {$id ne {}} {
5504 set firstkid [lindex $children($curview,$id) 0]
5505 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} {
5506 lappend ids [list [ordertoken $id] $id]
5507 }
5508 }
Paul Mackerras03800812007-08-29 21:45:21 +10005509 }
5510 set idlist {}
5511 foreach idx [lsort -unique $ids] {
Denton Liue2445882020-09-10 21:36:33 -07005512 lappend idlist [lindex $idx 1]
Paul Mackerras03800812007-08-29 21:45:21 +10005513 }
5514 return $idlist
5515}
5516
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005517proc rowsequal {a b} {
5518 while {[set i [lsearch -exact $a {}]] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07005519 set a [lreplace $a $i $i]
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005520 }
5521 while {[set i [lsearch -exact $b {}]] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07005522 set b [lreplace $b $i $i]
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005523 }
5524 return [expr {$a eq $b}]
5525}
5526
5527proc makeupline {id row rend col} {
5528 global rowidlist uparrowlen downarrowlen mingaplen
5529
5530 for {set r $rend} {1} {set r $rstart} {
Denton Liue2445882020-09-10 21:36:33 -07005531 set rstart [prevuse $id $r]
5532 if {$rstart < 0} return
5533 if {$rstart < $row} break
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005534 }
5535 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} {
Denton Liue2445882020-09-10 21:36:33 -07005536 set rstart [expr {$rend - $uparrowlen - 1}]
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005537 }
5538 for {set r $rstart} {[incr r] <= $row} {} {
Denton Liue2445882020-09-10 21:36:33 -07005539 set idlist [lindex $rowidlist $r]
5540 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} {
5541 set col [idcol $idlist $id $col]
5542 lset rowidlist $r [linsert $idlist $col $id]
5543 changedrow $r
5544 }
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005545 }
5546}
5547
Paul Mackerras03800812007-08-29 21:45:21 +10005548proc layoutrows {row endrow} {
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10005549 global rowidlist rowisopt rowfinal displayorder
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005550 global uparrowlen downarrowlen maxwidth mingaplen
Paul Mackerras6a90bff2007-06-18 09:48:23 +10005551 global children parentlist
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005552 global commitidx viewcomplete curview
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005553
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005554 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}]
Paul Mackerras03800812007-08-29 21:45:21 +10005555 set idlist {}
5556 if {$row > 0} {
Denton Liue2445882020-09-10 21:36:33 -07005557 set rm1 [expr {$row - 1}]
5558 foreach id [lindex $rowidlist $rm1] {
5559 if {$id ne {}} {
5560 lappend idlist $id
5561 }
5562 }
5563 set final [lindex $rowfinal $rm1]
Paul Mackerras8f0bc7e2007-08-24 22:16:42 +10005564 }
Paul Mackerras03800812007-08-29 21:45:21 +10005565 for {} {$row < $endrow} {incr row} {
Denton Liue2445882020-09-10 21:36:33 -07005566 set rm1 [expr {$row - 1}]
5567 if {$rm1 < 0 || $idlist eq {}} {
5568 set idlist [make_idlist $row]
5569 set final 1
5570 } else {
5571 set id [lindex $displayorder $rm1]
5572 set col [lsearch -exact $idlist $id]
5573 set idlist [lreplace $idlist $col $col]
5574 foreach p [lindex $parentlist $rm1] {
5575 if {[lsearch -exact $idlist $p] < 0} {
5576 set col [idcol $idlist $p $col]
5577 set idlist [linsert $idlist $col $p]
5578 # if not the first child, we have to insert a line going up
5579 if {$id ne [lindex $children($curview,$p) 0]} {
5580 makeupline $p $rm1 $row $col
5581 }
5582 }
5583 }
5584 set id [lindex $displayorder $row]
5585 if {$row > $downarrowlen} {
5586 set termrow [expr {$row - $downarrowlen - 1}]
5587 foreach p [lindex $parentlist $termrow] {
5588 set i [lsearch -exact $idlist $p]
5589 if {$i < 0} continue
5590 set nr [nextuse $p $termrow]
5591 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} {
5592 set idlist [lreplace $idlist $i $i]
5593 }
5594 }
5595 }
5596 set col [lsearch -exact $idlist $id]
5597 if {$col < 0} {
5598 set col [idcol $idlist $id]
5599 set idlist [linsert $idlist $col $id]
5600 if {$children($curview,$id) ne {}} {
5601 makeupline $id $rm1 $row $col
5602 }
5603 }
5604 set r [expr {$row + $uparrowlen - 1}]
5605 if {$r < $commitidx($curview)} {
5606 set x $col
5607 foreach p [lindex $parentlist $r] {
5608 if {[lsearch -exact $idlist $p] >= 0} continue
5609 set fk [lindex $children($curview,$p) 0]
5610 if {[rowofcommit $fk] < $row} {
5611 set x [idcol $idlist $p $x]
5612 set idlist [linsert $idlist $x $p]
5613 }
5614 }
5615 if {[incr r] < $commitidx($curview)} {
5616 set p [lindex $displayorder $r]
5617 if {[lsearch -exact $idlist $p] < 0} {
5618 set fk [lindex $children($curview,$p) 0]
5619 if {$fk ne {} && [rowofcommit $fk] < $row} {
5620 set x [idcol $idlist $p $x]
5621 set idlist [linsert $idlist $x $p]
5622 }
5623 }
5624 }
5625 }
5626 }
5627 if {$final && !$viewcomplete($curview) &&
5628 $row + $uparrowlen + $mingaplen + $downarrowlen
5629 >= $commitidx($curview)} {
5630 set final 0
5631 }
5632 set l [llength $rowidlist]
5633 if {$row == $l} {
5634 lappend rowidlist $idlist
5635 lappend rowisopt 0
5636 lappend rowfinal $final
5637 } elseif {$row < $l} {
5638 if {![rowsequal $idlist [lindex $rowidlist $row]]} {
5639 lset rowidlist $row $idlist
5640 changedrow $row
5641 }
5642 lset rowfinal $row $final
5643 } else {
5644 set pad [ntimes [expr {$row - $l}] {}]
5645 set rowidlist [concat $rowidlist $pad]
5646 lappend rowidlist $idlist
5647 set rowfinal [concat $rowfinal $pad]
5648 lappend rowfinal $final
5649 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]]
5650 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005651 }
5652 return $row
5653}
5654
Paul Mackerras03800812007-08-29 21:45:21 +10005655proc changedrow {row} {
5656 global displayorder iddrawn rowisopt need_redisplay
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005657
Paul Mackerras03800812007-08-29 21:45:21 +10005658 set l [llength $rowisopt]
5659 if {$row < $l} {
Denton Liue2445882020-09-10 21:36:33 -07005660 lset rowisopt $row 0
5661 if {$row + 1 < $l} {
5662 lset rowisopt [expr {$row + 1}] 0
5663 if {$row + 2 < $l} {
5664 lset rowisopt [expr {$row + 2}] 0
5665 }
5666 }
Paul Mackerras79b2c752006-04-02 20:47:40 +10005667 }
Paul Mackerras03800812007-08-29 21:45:21 +10005668 set id [lindex $displayorder $row]
5669 if {[info exists iddrawn($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005670 set need_redisplay 1
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005671 }
5672}
5673
5674proc insert_pad {row col npad} {
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005675 global rowidlist
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005676
5677 set pad [ntimes $npad {}]
Paul Mackerrase341c062007-08-12 12:42:57 +10005678 set idlist [lindex $rowidlist $row]
5679 set bef [lrange $idlist 0 [expr {$col - 1}]]
5680 set aft [lrange $idlist $col end]
5681 set i [lsearch -exact $aft {}]
5682 if {$i > 0} {
Denton Liue2445882020-09-10 21:36:33 -07005683 set aft [lreplace $aft $i $i]
Paul Mackerrase341c062007-08-12 12:42:57 +10005684 }
5685 lset rowidlist $row [concat $bef $pad $aft]
Paul Mackerras03800812007-08-29 21:45:21 +10005686 changedrow $row
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005687}
5688
5689proc optimize_rows {row col endrow} {
Paul Mackerras03800812007-08-29 21:45:21 +10005690 global rowidlist rowisopt displayorder curview children
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005691
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005692 if {$row < 1} {
Denton Liue2445882020-09-10 21:36:33 -07005693 set row 1
Paul Mackerras6e8c8702007-07-31 21:03:06 +10005694 }
Paul Mackerras03800812007-08-29 21:45:21 +10005695 for {} {$row < $endrow} {incr row; set col 0} {
Denton Liue2445882020-09-10 21:36:33 -07005696 if {[lindex $rowisopt $row]} continue
5697 set haspad 0
5698 set y0 [expr {$row - 1}]
5699 set ym [expr {$row - 2}]
5700 set idlist [lindex $rowidlist $row]
5701 set previdlist [lindex $rowidlist $y0]
5702 if {$idlist eq {} || $previdlist eq {}} continue
5703 if {$ym >= 0} {
5704 set pprevidlist [lindex $rowidlist $ym]
5705 if {$pprevidlist eq {}} continue
5706 } else {
5707 set pprevidlist {}
5708 }
5709 set x0 -1
5710 set xm -1
5711 for {} {$col < [llength $idlist]} {incr col} {
5712 set id [lindex $idlist $col]
5713 if {[lindex $previdlist $col] eq $id} continue
5714 if {$id eq {}} {
5715 set haspad 1
5716 continue
5717 }
5718 set x0 [lsearch -exact $previdlist $id]
5719 if {$x0 < 0} continue
5720 set z [expr {$x0 - $col}]
5721 set isarrow 0
5722 set z0 {}
5723 if {$ym >= 0} {
5724 set xm [lsearch -exact $pprevidlist $id]
5725 if {$xm >= 0} {
5726 set z0 [expr {$xm - $x0}]
5727 }
5728 }
5729 if {$z0 eq {}} {
5730 # if row y0 is the first child of $id then it's not an arrow
5731 if {[lindex $children($curview,$id) 0] ne
5732 [lindex $displayorder $y0]} {
5733 set isarrow 1
5734 }
5735 }
5736 if {!$isarrow && $id ne [lindex $displayorder $row] &&
5737 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} {
5738 set isarrow 1
5739 }
5740 # Looking at lines from this row to the previous row,
5741 # make them go straight up if they end in an arrow on
5742 # the previous row; otherwise make them go straight up
5743 # or at 45 degrees.
5744 if {$z < -1 || ($z < 0 && $isarrow)} {
5745 # Line currently goes left too much;
5746 # insert pads in the previous row, then optimize it
5747 set npad [expr {-1 - $z + $isarrow}]
5748 insert_pad $y0 $x0 $npad
5749 if {$y0 > 0} {
5750 optimize_rows $y0 $x0 $row
5751 }
5752 set previdlist [lindex $rowidlist $y0]
5753 set x0 [lsearch -exact $previdlist $id]
5754 set z [expr {$x0 - $col}]
5755 if {$z0 ne {}} {
5756 set pprevidlist [lindex $rowidlist $ym]
5757 set xm [lsearch -exact $pprevidlist $id]
5758 set z0 [expr {$xm - $x0}]
5759 }
5760 } elseif {$z > 1 || ($z > 0 && $isarrow)} {
5761 # Line currently goes right too much;
5762 # insert pads in this line
5763 set npad [expr {$z - 1 + $isarrow}]
5764 insert_pad $row $col $npad
5765 set idlist [lindex $rowidlist $row]
5766 incr col $npad
5767 set z [expr {$x0 - $col}]
5768 set haspad 1
5769 }
5770 if {$z0 eq {} && !$isarrow && $ym >= 0} {
5771 # this line links to its first child on row $row-2
5772 set id [lindex $displayorder $ym]
5773 set xc [lsearch -exact $pprevidlist $id]
5774 if {$xc >= 0} {
5775 set z0 [expr {$xc - $x0}]
5776 }
5777 }
5778 # avoid lines jigging left then immediately right
5779 if {$z0 ne {} && $z < 0 && $z0 > 0} {
5780 insert_pad $y0 $x0 1
5781 incr x0
5782 optimize_rows $y0 $x0 $row
5783 set previdlist [lindex $rowidlist $y0]
5784 }
5785 }
5786 if {!$haspad} {
5787 # Find the first column that doesn't have a line going right
5788 for {set col [llength $idlist]} {[incr col -1] >= 0} {} {
5789 set id [lindex $idlist $col]
5790 if {$id eq {}} break
5791 set x0 [lsearch -exact $previdlist $id]
5792 if {$x0 < 0} {
5793 # check if this is the link to the first child
5794 set kid [lindex $displayorder $y0]
5795 if {[lindex $children($curview,$id) 0] eq $kid} {
5796 # it is, work out offset to child
5797 set x0 [lsearch -exact $previdlist $kid]
5798 }
5799 }
5800 if {$x0 <= $col} break
5801 }
5802 # Insert a pad at that column as long as it has a line and
5803 # isn't the last column
5804 if {$x0 >= 0 && [incr col] < [llength $idlist]} {
5805 set idlist [linsert $idlist $col {}]
5806 lset rowidlist $row $idlist
5807 changedrow $row
5808 }
5809 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005810 }
5811}
5812
5813proc xc {row col} {
5814 global canvx0 linespc
5815 return [expr {$canvx0 + $col * $linespc}]
5816}
5817
5818proc yc {row} {
5819 global canvy0 linespc
5820 return [expr {$canvy0 + $row * $linespc}]
5821}
5822
Paul Mackerrasc934a8a2006-03-02 23:00:44 +11005823proc linewidth {id} {
5824 global thickerline lthickness
5825
5826 set wid $lthickness
5827 if {[info exists thickerline] && $id eq $thickerline} {
Denton Liue2445882020-09-10 21:36:33 -07005828 set wid [expr {2 * $lthickness}]
Paul Mackerrasc934a8a2006-03-02 23:00:44 +11005829 }
5830 return $wid
5831}
5832
Paul Mackerras50b44ec2006-04-04 10:16:22 +10005833proc rowranges {id} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11005834 global curview children uparrowlen downarrowlen
Paul Mackerras92ed6662007-08-22 22:35:28 +10005835 global rowidlist
Paul Mackerras50b44ec2006-04-04 10:16:22 +10005836
Paul Mackerras92ed6662007-08-22 22:35:28 +10005837 set kids $children($curview,$id)
5838 if {$kids eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07005839 return {}
Paul Mackerras50b44ec2006-04-04 10:16:22 +10005840 }
Paul Mackerras92ed6662007-08-22 22:35:28 +10005841 set ret {}
5842 lappend kids $id
5843 foreach child $kids {
Denton Liue2445882020-09-10 21:36:33 -07005844 if {![commitinview $child $curview]} break
5845 set row [rowofcommit $child]
5846 if {![info exists prev]} {
5847 lappend ret [expr {$row + 1}]
5848 } else {
5849 if {$row <= $prevrow} {
5850 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow"
5851 }
5852 # see if the line extends the whole way from prevrow to row
5853 if {$row > $prevrow + $uparrowlen + $downarrowlen &&
5854 [lsearch -exact [lindex $rowidlist \
5855 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} {
5856 # it doesn't, see where it ends
5857 set r [expr {$prevrow + $downarrowlen}]
5858 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5859 while {[incr r -1] > $prevrow &&
5860 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5861 } else {
5862 while {[incr r] <= $row &&
5863 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5864 incr r -1
5865 }
5866 lappend ret $r
5867 # see where it starts up again
5868 set r [expr {$row - $uparrowlen}]
5869 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} {
5870 while {[incr r] < $row &&
5871 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {}
5872 } else {
5873 while {[incr r -1] >= $prevrow &&
5874 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {}
5875 incr r
5876 }
5877 lappend ret $r
5878 }
5879 }
5880 if {$child eq $id} {
5881 lappend ret $row
5882 }
5883 set prev $child
5884 set prevrow $row
Paul Mackerraseb447a12006-03-18 23:11:37 +11005885 }
Paul Mackerras92ed6662007-08-22 22:35:28 +10005886 return $ret
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005887}
5888
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005889proc drawlineseg {id row endrow arrowlow} {
5890 global rowidlist displayorder iddrawn linesegs
Paul Mackerrase341c062007-08-12 12:42:57 +10005891 global canv colormap linespc curview maxlinelen parentlist
Paul Mackerras9f1afe02006-02-19 22:44:47 +11005892
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005893 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]]
5894 set le [expr {$row + 1}]
5895 set arrowhigh 1
5896 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07005897 set c [lsearch -exact [lindex $rowidlist $le] $id]
5898 if {$c < 0} {
5899 incr le -1
5900 break
5901 }
5902 lappend cols $c
5903 set x [lindex $displayorder $le]
5904 if {$x eq $id} {
5905 set arrowhigh 0
5906 break
5907 }
5908 if {[info exists iddrawn($x)] || $le == $endrow} {
5909 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id]
5910 if {$c >= 0} {
5911 lappend cols $c
5912 set arrowhigh 0
5913 }
5914 break
5915 }
5916 incr le
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005917 }
5918 if {$le <= $row} {
Denton Liue2445882020-09-10 21:36:33 -07005919 return $row
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005920 }
5921
5922 set lines {}
5923 set i 0
5924 set joinhigh 0
5925 if {[info exists linesegs($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07005926 set lines $linesegs($id)
5927 foreach li $lines {
5928 set r0 [lindex $li 0]
5929 if {$r0 > $row} {
5930 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} {
5931 set joinhigh 1
5932 }
5933 break
5934 }
5935 incr i
5936 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005937 }
5938 set joinlow 0
5939 if {$i > 0} {
Denton Liue2445882020-09-10 21:36:33 -07005940 set li [lindex $lines [expr {$i-1}]]
5941 set r1 [lindex $li 1]
5942 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} {
5943 set joinlow 1
5944 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005945 }
5946
5947 set x [lindex $cols [expr {$le - $row}]]
5948 set xp [lindex $cols [expr {$le - 1 - $row}]]
5949 set dir [expr {$xp - $x}]
5950 if {$joinhigh} {
Denton Liue2445882020-09-10 21:36:33 -07005951 set ith [lindex $lines $i 2]
5952 set coords [$canv coords $ith]
5953 set ah [$canv itemcget $ith -arrow]
5954 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}]
5955 set x2 [lindex $cols [expr {$le + 1 - $row}]]
5956 if {$x2 ne {} && $x - $x2 == $dir} {
5957 set coords [lrange $coords 0 end-2]
5958 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005959 } else {
Denton Liue2445882020-09-10 21:36:33 -07005960 set coords [list [xc $le $x] [yc $le]]
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005961 }
5962 if {$joinlow} {
Denton Liue2445882020-09-10 21:36:33 -07005963 set itl [lindex $lines [expr {$i-1}] 2]
5964 set al [$canv itemcget $itl -arrow]
5965 set arrowlow [expr {$al eq "last" || $al eq "both"}]
Paul Mackerrase341c062007-08-12 12:42:57 +10005966 } elseif {$arrowlow} {
Denton Liue2445882020-09-10 21:36:33 -07005967 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 ||
5968 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} {
5969 set arrowlow 0
5970 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005971 }
5972 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]]
5973 for {set y $le} {[incr y -1] > $row} {} {
Denton Liue2445882020-09-10 21:36:33 -07005974 set x $xp
5975 set xp [lindex $cols [expr {$y - 1 - $row}]]
5976 set ndir [expr {$xp - $x}]
5977 if {$dir != $ndir || $xp < 0} {
5978 lappend coords [xc $y $x] [yc $y]
5979 }
5980 set dir $ndir
Paul Mackerras322a8cc2006-10-15 18:03:46 +10005981 }
5982 if {!$joinlow} {
Denton Liue2445882020-09-10 21:36:33 -07005983 if {$xp < 0} {
5984 # join parent line to first child
5985 set ch [lindex $displayorder $row]
5986 set xc [lsearch -exact [lindex $rowidlist $row] $ch]
5987 if {$xc < 0} {
5988 puts "oops: drawlineseg: child $ch not on row $row"
5989 } elseif {$xc != $x} {
5990 if {($arrowhigh && $le == $row + 1) || $dir == 0} {
5991 set d [expr {int(0.5 * $linespc)}]
5992 set x1 [xc $row $x]
5993 if {$xc < $x} {
5994 set x2 [expr {$x1 - $d}]
5995 } else {
5996 set x2 [expr {$x1 + $d}]
5997 }
5998 set y2 [yc $row]
5999 set y1 [expr {$y2 + $d}]
6000 lappend coords $x1 $y1 $x2 $y2
6001 } elseif {$xc < $x - 1} {
6002 lappend coords [xc $row [expr {$x-1}]] [yc $row]
6003 } elseif {$xc > $x + 1} {
6004 lappend coords [xc $row [expr {$x+1}]] [yc $row]
6005 }
6006 set x $xc
6007 }
6008 lappend coords [xc $row $x] [yc $row]
6009 } else {
6010 set xn [xc $row $xp]
6011 set yn [yc $row]
6012 lappend coords $xn $yn
6013 }
6014 if {!$joinhigh} {
6015 assigncolor $id
6016 set t [$canv create line $coords -width [linewidth $id] \
6017 -fill $colormap($id) -tags lines.$id -arrow $arrow]
6018 $canv lower $t
6019 bindline $t $id
6020 set lines [linsert $lines $i [list $row $le $t]]
6021 } else {
6022 $canv coords $ith $coords
6023 if {$arrow ne $ah} {
6024 $canv itemconf $ith -arrow $arrow
6025 }
6026 lset lines $i 0 $row
6027 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006028 } else {
Denton Liue2445882020-09-10 21:36:33 -07006029 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id]
6030 set ndir [expr {$xo - $xp}]
6031 set clow [$canv coords $itl]
6032 if {$dir == $ndir} {
6033 set clow [lrange $clow 2 end]
6034 }
6035 set coords [concat $coords $clow]
6036 if {!$joinhigh} {
6037 lset lines [expr {$i-1}] 1 $le
6038 } else {
6039 # coalesce two pieces
6040 $canv delete $ith
6041 set b [lindex $lines [expr {$i-1}] 0]
6042 set e [lindex $lines $i 1]
6043 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]]
6044 }
6045 $canv coords $itl $coords
6046 if {$arrow ne $al} {
6047 $canv itemconf $itl -arrow $arrow
6048 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006049 }
6050
6051 set linesegs($id) $lines
6052 return $le
6053}
6054
6055proc drawparentlinks {id row} {
6056 global rowidlist canv colormap curview parentlist
Paul Mackerras513a54d2007-08-01 22:27:57 +10006057 global idpos linespc
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006058
6059 set rowids [lindex $rowidlist $row]
6060 set col [lsearch -exact $rowids $id]
6061 if {$col < 0} return
6062 set olds [lindex $parentlist $row]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006063 set row2 [expr {$row + 1}]
6064 set x [xc $row $col]
6065 set y [yc $row]
6066 set y2 [yc $row2]
Paul Mackerrase341c062007-08-12 12:42:57 +10006067 set d [expr {int(0.5 * $linespc)}]
Paul Mackerras513a54d2007-08-01 22:27:57 +10006068 set ymid [expr {$y + $d}]
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11006069 set ids [lindex $rowidlist $row2]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006070 # rmx = right-most X coord used
6071 set rmx 0
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006072 foreach p $olds {
Denton Liue2445882020-09-10 21:36:33 -07006073 set i [lsearch -exact $ids $p]
6074 if {$i < 0} {
6075 puts "oops, parent $p of $id not in list"
6076 continue
6077 }
6078 set x2 [xc $row2 $i]
6079 if {$x2 > $rmx} {
6080 set rmx $x2
6081 }
6082 set j [lsearch -exact $rowids $p]
6083 if {$j < 0} {
6084 # drawlineseg will do this one for us
6085 continue
6086 }
6087 assigncolor $p
6088 # should handle duplicated parents here...
6089 set coords [list $x $y]
6090 if {$i != $col} {
6091 # if attaching to a vertical segment, draw a smaller
6092 # slant for visual distinctness
6093 if {$i == $j} {
6094 if {$i < $col} {
6095 lappend coords [expr {$x2 + $d}] $y $x2 $ymid
6096 } else {
6097 lappend coords [expr {$x2 - $d}] $y $x2 $ymid
6098 }
6099 } elseif {$i < $col && $i < $j} {
6100 # segment slants towards us already
6101 lappend coords [xc $row $j] $y
6102 } else {
6103 if {$i < $col - 1} {
6104 lappend coords [expr {$x2 + $linespc}] $y
6105 } elseif {$i > $col + 1} {
6106 lappend coords [expr {$x2 - $linespc}] $y
6107 }
6108 lappend coords $x2 $y2
6109 }
6110 } else {
6111 lappend coords $x2 $y2
6112 }
6113 set t [$canv create line $coords -width [linewidth $p] \
6114 -fill $colormap($p) -tags lines.$p]
6115 $canv lower $t
6116 bindline $t $p
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006117 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006118 if {$rmx > [lindex $idpos($id) 1]} {
Denton Liue2445882020-09-10 21:36:33 -07006119 lset idpos($id) 1 $rmx
6120 redrawtags $id
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006121 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006122}
6123
Paul Mackerrasc934a8a2006-03-02 23:00:44 +11006124proc drawlines {id} {
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006125 global canv
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006126
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006127 $canv itemconf lines.$id -width [linewidth $id]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006128}
6129
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006130proc drawcmittext {id row col} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006131 global linespc canv canv2 canv3 fgcolor curview
6132 global cmitlisted commitinfo rowidlist parentlist
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006133 global rowtextx idpos idtags idheads idotherrefs
Paul Mackerras03800812007-08-29 21:45:21 +10006134 global linehtag linentag linedtag selectedline
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10006135 global canvxmax boldids boldnameids fgcolor markedid
Paul Mackerrasd277e892008-09-21 18:11:37 -05006136 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
Gauthier Östervall252c52d2013-03-27 14:40:51 +01006137 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor
6138 global circleoutlinecolor
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006139
Linus Torvalds1407ade2008-02-09 14:02:07 -08006140 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006141 set listed $cmitlisted($curview,$id)
Paul Mackerras219ea3a2006-09-07 10:21:39 +10006142 if {$id eq $nullid} {
Denton Liue2445882020-09-10 21:36:33 -07006143 set ofill $workingfilescirclecolor
Paul Mackerras8f489362007-07-13 19:49:37 +10006144 } elseif {$id eq $nullid2} {
Denton Liue2445882020-09-10 21:36:33 -07006145 set ofill $indexcirclecolor
Paul Mackerrasc11ff122008-05-26 10:11:33 +10006146 } elseif {$id eq $mainheadid} {
Denton Liue2445882020-09-10 21:36:33 -07006147 set ofill $mainheadcirclecolor
Paul Mackerras219ea3a2006-09-07 10:21:39 +10006148 } else {
Denton Liue2445882020-09-10 21:36:33 -07006149 set ofill [lindex $circlecolors $listed]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10006150 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006151 set x [xc $row $col]
6152 set y [yc $row]
6153 set orad [expr {$linespc / 3}]
Linus Torvalds1407ade2008-02-09 14:02:07 -08006154 if {$listed <= 2} {
Denton Liue2445882020-09-10 21:36:33 -07006155 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
6156 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6157 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
Linus Torvalds1407ade2008-02-09 14:02:07 -08006158 } elseif {$listed == 3} {
Denton Liue2445882020-09-10 21:36:33 -07006159 # triangle pointing left for left-side commits
6160 set t [$canv create polygon \
6161 [expr {$x - $orad}] $y \
6162 [expr {$x + $orad - 1}] [expr {$y - $orad}] \
6163 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
6164 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
Paul Mackerrasc961b222007-07-09 22:45:47 +10006165 } else {
Denton Liue2445882020-09-10 21:36:33 -07006166 # triangle pointing right for right-side commits
6167 set t [$canv create polygon \
6168 [expr {$x + $orad - 1}] $y \
6169 [expr {$x - $orad}] [expr {$y - $orad}] \
6170 [expr {$x - $orad}] [expr {$y + $orad - 1}] \
6171 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle]
Paul Mackerrasc961b222007-07-09 22:45:47 +10006172 }
Paul Mackerrasc11ff122008-05-26 10:11:33 +10006173 set circleitem($row) $t
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006174 $canv raise $t
6175 $canv bind $t <1> {selcanvline {} %x %y}
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006176 set rmx [llength [lindex $rowidlist $row]]
6177 set olds [lindex $parentlist $row]
6178 if {$olds ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07006179 set nextids [lindex $rowidlist [expr {$row + 1}]]
6180 foreach p $olds {
6181 set i [lsearch -exact $nextids $p]
6182 if {$i > $rmx} {
6183 set rmx $i
6184 }
6185 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006186 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006187 set xt [xc $row $rmx]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006188 set rowtextx($row) $xt
6189 set idpos($id) [list $x $xt $y]
6190 if {[info exists idtags($id)] || [info exists idheads($id)]
Denton Liue2445882020-09-10 21:36:33 -07006191 || [info exists idotherrefs($id)]} {
6192 set xt [drawtags $id $x $xt $y]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006193 }
Raphael Zimmerer36242492011-04-19 22:37:09 +02006194 if {[lindex $commitinfo($id) 6] > 0} {
Denton Liue2445882020-09-10 21:36:33 -07006195 set xt [drawnotesign $xt $y]
Raphael Zimmerer36242492011-04-19 22:37:09 +02006196 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006197 set headline [lindex $commitinfo($id) 0]
6198 set name [lindex $commitinfo($id) 1]
6199 set date [lindex $commitinfo($id) 2]
6200 set date [formatdate $date]
Paul Mackerras9c311b32007-10-04 22:27:13 +10006201 set font mainfont
6202 set nfont mainfont
Paul Mackerras476ca632008-01-07 22:16:31 +11006203 set isbold [ishighlighted $id]
Paul Mackerras908c3582006-05-20 09:38:11 +10006204 if {$isbold > 0} {
Denton Liue2445882020-09-10 21:36:33 -07006205 lappend boldids $id
6206 set font mainfontbold
6207 if {$isbold > 1} {
6208 lappend boldnameids $id
6209 set nfont mainfontbold
6210 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006211 }
Paul Mackerras28593d32008-11-13 23:01:46 +11006212 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \
Denton Liue2445882020-09-10 21:36:33 -07006213 -text $headline -font $font -tags text]
Paul Mackerras28593d32008-11-13 23:01:46 +11006214 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id"
6215 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
Denton Liue2445882020-09-10 21:36:33 -07006216 -text $name -font $nfont -tags text]
Paul Mackerras28593d32008-11-13 23:01:46 +11006217 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
Denton Liue2445882020-09-10 21:36:33 -07006218 -text $date -font mainfont -tags text]
Paul Mackerras94b4a692008-05-20 20:51:06 +10006219 if {$selectedline == $row} {
Denton Liue2445882020-09-10 21:36:33 -07006220 make_secsel $id
Paul Mackerras03800812007-08-29 21:45:21 +10006221 }
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10006222 if {[info exists markedid] && $markedid eq $id} {
Denton Liue2445882020-09-10 21:36:33 -07006223 make_idmark $id
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10006224 }
Paul Mackerras9c311b32007-10-04 22:27:13 +10006225 set xr [expr {$xt + [font measure $font $headline]}]
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11006226 if {$xr > $canvxmax} {
Denton Liue2445882020-09-10 21:36:33 -07006227 set canvxmax $xr
6228 setcanvscroll
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11006229 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006230}
6231
6232proc drawcmitrow {row} {
Paul Mackerras03800812007-08-29 21:45:21 +10006233 global displayorder rowidlist nrows_drawn
Paul Mackerras005a2f42007-07-26 22:36:39 +10006234 global iddrawn markingmatches
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006235 global commitinfo numcommits
Paul Mackerras687c8762007-09-22 12:49:33 +10006236 global filehighlight fhighlights findpattern nhighlights
Paul Mackerras908c3582006-05-20 09:38:11 +10006237 global hlview vhighlights
Paul Mackerras164ff272006-05-29 19:50:02 +10006238 global highlight_related rhighlights
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006239
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11006240 if {$row >= $numcommits} return
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006241
6242 set id [lindex $displayorder $row]
Paul Mackerras476ca632008-01-07 22:16:31 +11006243 if {[info exists hlview] && ![info exists vhighlights($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006244 askvhighlight $row $id
Paul Mackerras908c3582006-05-20 09:38:11 +10006245 }
Paul Mackerras476ca632008-01-07 22:16:31 +11006246 if {[info exists filehighlight] && ![info exists fhighlights($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006247 askfilehighlight $row $id
Paul Mackerras908c3582006-05-20 09:38:11 +10006248 }
Paul Mackerras476ca632008-01-07 22:16:31 +11006249 if {$findpattern ne {} && ![info exists nhighlights($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006250 askfindhighlight $row $id
Paul Mackerras908c3582006-05-20 09:38:11 +10006251 }
Paul Mackerras476ca632008-01-07 22:16:31 +11006252 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006253 askrelhighlight $row $id
Paul Mackerras164ff272006-05-29 19:50:02 +10006254 }
Paul Mackerras005a2f42007-07-26 22:36:39 +10006255 if {![info exists iddrawn($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006256 set col [lsearch -exact [lindex $rowidlist $row] $id]
6257 if {$col < 0} {
6258 puts "oops, row $row id $id not in list"
6259 return
6260 }
6261 if {![info exists commitinfo($id)]} {
6262 getcommit $id
6263 }
6264 assigncolor $id
6265 drawcmittext $id $row $col
6266 set iddrawn($id) 1
6267 incr nrows_drawn
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006268 }
Paul Mackerras005a2f42007-07-26 22:36:39 +10006269 if {$markingmatches} {
Denton Liue2445882020-09-10 21:36:33 -07006270 markrowmatches $row $id
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006271 }
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006272}
6273
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006274proc drawcommits {row {endrow {}}} {
Paul Mackerras03800812007-08-29 21:45:21 +10006275 global numcommits iddrawn displayorder curview need_redisplay
Paul Mackerrasf5f3c2e2007-09-05 02:19:56 +10006276 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006277
6278 if {$row < 0} {
Denton Liue2445882020-09-10 21:36:33 -07006279 set row 0
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006280 }
6281 if {$endrow eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07006282 set endrow $row
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006283 }
6284 if {$endrow >= $numcommits} {
Denton Liue2445882020-09-10 21:36:33 -07006285 set endrow [expr {$numcommits - 1}]
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006286 }
6287
Paul Mackerras03800812007-08-29 21:45:21 +10006288 set rl1 [expr {$row - $downarrowlen - 3}]
6289 if {$rl1 < 0} {
Denton Liue2445882020-09-10 21:36:33 -07006290 set rl1 0
Paul Mackerras03800812007-08-29 21:45:21 +10006291 }
6292 set ro1 [expr {$row - 3}]
6293 if {$ro1 < 0} {
Denton Liue2445882020-09-10 21:36:33 -07006294 set ro1 0
Paul Mackerras03800812007-08-29 21:45:21 +10006295 }
6296 set r2 [expr {$endrow + $uparrowlen + 3}]
6297 if {$r2 > $numcommits} {
Denton Liue2445882020-09-10 21:36:33 -07006298 set r2 $numcommits
Paul Mackerras03800812007-08-29 21:45:21 +10006299 }
6300 for {set r $rl1} {$r < $r2} {incr r} {
Denton Liue2445882020-09-10 21:36:33 -07006301 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} {
6302 if {$rl1 < $r} {
6303 layoutrows $rl1 $r
6304 }
6305 set rl1 [expr {$r + 1}]
6306 }
Paul Mackerras03800812007-08-29 21:45:21 +10006307 }
6308 if {$rl1 < $r} {
Denton Liue2445882020-09-10 21:36:33 -07006309 layoutrows $rl1 $r
Paul Mackerras03800812007-08-29 21:45:21 +10006310 }
6311 optimize_rows $ro1 0 $r2
6312 if {$need_redisplay || $nrows_drawn > 2000} {
Denton Liue2445882020-09-10 21:36:33 -07006313 clear_display
Paul Mackerras03800812007-08-29 21:45:21 +10006314 }
6315
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006316 # make the lines join to already-drawn rows either side
6317 set r [expr {$row - 1}]
6318 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} {
Denton Liue2445882020-09-10 21:36:33 -07006319 set r $row
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006320 }
6321 set er [expr {$endrow + 1}]
6322 if {$er >= $numcommits ||
Denton Liue2445882020-09-10 21:36:33 -07006323 ![info exists iddrawn([lindex $displayorder $er])]} {
6324 set er $endrow
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006325 }
6326 for {} {$r <= $er} {incr r} {
Denton Liue2445882020-09-10 21:36:33 -07006327 set id [lindex $displayorder $r]
6328 set wasdrawn [info exists iddrawn($id)]
6329 drawcmitrow $r
6330 if {$r == $er} break
6331 set nextid [lindex $displayorder [expr {$r + 1}]]
6332 if {$wasdrawn && [info exists iddrawn($nextid)]} continue
6333 drawparentlinks $id $r
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006334
Denton Liue2445882020-09-10 21:36:33 -07006335 set rowids [lindex $rowidlist $r]
6336 foreach lid $rowids {
6337 if {$lid eq {}} continue
6338 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue
6339 if {$lid eq $id} {
6340 # see if this is the first child of any of its parents
6341 foreach p [lindex $parentlist $r] {
6342 if {[lsearch -exact $rowids $p] < 0} {
6343 # make this line extend up to the child
6344 set lineend($p) [drawlineseg $p $r $er 0]
6345 }
6346 }
6347 } else {
6348 set lineend($lid) [drawlineseg $lid $r $er 1]
6349 }
6350 }
Paul Mackerras322a8cc2006-10-15 18:03:46 +10006351 }
6352}
6353
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006354proc undolayout {row} {
6355 global uparrowlen mingaplen downarrowlen
6356 global rowidlist rowisopt rowfinal need_redisplay
6357
6358 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}]
6359 if {$r < 0} {
Denton Liue2445882020-09-10 21:36:33 -07006360 set r 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006361 }
6362 if {[llength $rowidlist] > $r} {
Denton Liue2445882020-09-10 21:36:33 -07006363 incr r -1
6364 set rowidlist [lrange $rowidlist 0 $r]
6365 set rowfinal [lrange $rowfinal 0 $r]
6366 set rowisopt [lrange $rowisopt 0 $r]
6367 set need_redisplay 1
6368 run drawvisible
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006369 }
6370}
6371
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006372proc drawvisible {} {
6373 global canv linespc curview vrowmod selectedline targetrow targetid
Paul Mackerras42a671f2008-01-02 09:59:39 +11006374 global need_redisplay cscroll numcommits
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006375
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006376 set fs [$canv yview]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006377 set ymax [lindex [$canv cget -scrollregion] 3]
Paul Mackerras5a7f5772008-01-15 22:45:36 +11006378 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006379 set f0 [lindex $fs 0]
6380 set f1 [lindex $fs 1]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006381 set y0 [expr {int($f0 * $ymax)}]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006382 set y1 [expr {int($f1 * $ymax)}]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006383
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006384 if {[info exists targetid]} {
Denton Liue2445882020-09-10 21:36:33 -07006385 if {[commitinview $targetid $curview]} {
6386 set r [rowofcommit $targetid]
6387 if {$r != $targetrow} {
6388 # Fix up the scrollregion and change the scrolling position
6389 # now that our target row has moved.
6390 set diff [expr {($r - $targetrow) * $linespc}]
6391 set targetrow $r
6392 setcanvscroll
6393 set ymax [lindex [$canv cget -scrollregion] 3]
6394 incr y0 $diff
6395 incr y1 $diff
6396 set f0 [expr {$y0 / $ymax}]
6397 set f1 [expr {$y1 / $ymax}]
6398 allcanvs yview moveto $f0
6399 $cscroll set $f0 $f1
6400 set need_redisplay 1
6401 }
6402 } else {
6403 unset targetid
6404 }
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006405 }
6406
6407 set row [expr {int(($y0 - 3) / $linespc) - 1}]
6408 set endrow [expr {int(($y1 - 3) / $linespc) + 1}]
6409 if {$endrow >= $vrowmod($curview)} {
Denton Liue2445882020-09-10 21:36:33 -07006410 update_arcrows $curview
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006411 }
Paul Mackerras94b4a692008-05-20 20:51:06 +10006412 if {$selectedline ne {} &&
Denton Liue2445882020-09-10 21:36:33 -07006413 $row <= $selectedline && $selectedline <= $endrow} {
6414 set targetrow $selectedline
Paul Mackerrasac1276a2008-03-03 10:11:08 +11006415 } elseif {[info exists targetid]} {
Denton Liue2445882020-09-10 21:36:33 -07006416 set targetrow [expr {int(($row + $endrow) / 2)}]
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006417 }
Paul Mackerrasac1276a2008-03-03 10:11:08 +11006418 if {[info exists targetrow]} {
Denton Liue2445882020-09-10 21:36:33 -07006419 if {$targetrow >= $numcommits} {
6420 set targetrow [expr {$numcommits - 1}]
6421 }
6422 set targetid [commitonrow $targetrow]
Paul Mackerras42a671f2008-01-02 09:59:39 +11006423 }
Paul Mackerras31c0eaa2007-12-30 22:41:14 +11006424 drawcommits $row $endrow
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006425}
6426
6427proc clear_display {} {
Paul Mackerras03800812007-08-29 21:45:21 +10006428 global iddrawn linesegs need_redisplay nrows_drawn
Paul Mackerras164ff272006-05-29 19:50:02 +10006429 global vhighlights fhighlights nhighlights rhighlights
Paul Mackerras28593d32008-11-13 23:01:46 +11006430 global linehtag linentag linedtag boldids boldnameids
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006431
6432 allcanvs delete all
Paul Mackerras009409f2015-05-02 20:53:36 +10006433 unset -nocomplain iddrawn
6434 unset -nocomplain linesegs
6435 unset -nocomplain linehtag
6436 unset -nocomplain linentag
6437 unset -nocomplain linedtag
Paul Mackerras28593d32008-11-13 23:01:46 +11006438 set boldids {}
6439 set boldnameids {}
Paul Mackerras009409f2015-05-02 20:53:36 +10006440 unset -nocomplain vhighlights
6441 unset -nocomplain fhighlights
6442 unset -nocomplain nhighlights
6443 unset -nocomplain rhighlights
Paul Mackerras03800812007-08-29 21:45:21 +10006444 set need_redisplay 0
6445 set nrows_drawn 0
Paul Mackerras9f1afe02006-02-19 22:44:47 +11006446}
6447
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006448proc findcrossings {id} {
Paul Mackerras6e8c8702007-07-31 21:03:06 +10006449 global rowidlist parentlist numcommits displayorder
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006450
6451 set cross {}
6452 set ccross {}
6453 foreach {s e} [rowranges $id] {
Denton Liue2445882020-09-10 21:36:33 -07006454 if {$e >= $numcommits} {
6455 set e [expr {$numcommits - 1}]
6456 }
6457 if {$e <= $s} continue
6458 for {set row $e} {[incr row -1] >= $s} {} {
6459 set x [lsearch -exact [lindex $rowidlist $row] $id]
6460 if {$x < 0} break
6461 set olds [lindex $parentlist $row]
6462 set kid [lindex $displayorder $row]
6463 set kidx [lsearch -exact [lindex $rowidlist $row] $kid]
6464 if {$kidx < 0} continue
6465 set nextrow [lindex $rowidlist [expr {$row + 1}]]
6466 foreach p $olds {
6467 set px [lsearch -exact $nextrow $p]
6468 if {$px < 0} continue
6469 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} {
6470 if {[lsearch -exact $ccross $p] >= 0} continue
6471 if {$x == $px + ($kidx < $px? -1: 1)} {
6472 lappend ccross $p
6473 } elseif {[lsearch -exact $cross $p] < 0} {
6474 lappend cross $p
6475 }
6476 }
6477 }
6478 }
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006479 }
6480 return [concat $ccross {{}} $cross]
6481}
6482
Paul Mackerrase5c2d852005-05-11 23:44:54 +00006483proc assigncolor {id} {
Paul Mackerrasaa81d972006-02-28 11:27:12 +11006484 global colormap colors nextcolor
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006485 global parents children children curview
Paul Mackerras6c20ff32005-06-22 19:53:32 +10006486
Paul Mackerras418c4c72006-02-07 09:10:18 +11006487 if {[info exists colormap($id)]} return
Paul Mackerrase5c2d852005-05-11 23:44:54 +00006488 set ncolors [llength $colors]
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006489 if {[info exists children($curview,$id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006490 set kids $children($curview,$id)
Paul Mackerras79b2c752006-04-02 20:47:40 +10006491 } else {
Denton Liue2445882020-09-10 21:36:33 -07006492 set kids {}
Paul Mackerras79b2c752006-04-02 20:47:40 +10006493 }
6494 if {[llength $kids] == 1} {
Denton Liue2445882020-09-10 21:36:33 -07006495 set child [lindex $kids 0]
6496 if {[info exists colormap($child)]
6497 && [llength $parents($curview,$child)] == 1} {
6498 set colormap($id) $colormap($child)
6499 return
6500 }
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00006501 }
6502 set badcolors {}
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006503 set origbad {}
6504 foreach x [findcrossings $id] {
Denton Liue2445882020-09-10 21:36:33 -07006505 if {$x eq {}} {
6506 # delimiter between corner crossings and other crossings
6507 if {[llength $badcolors] >= $ncolors - 1} break
6508 set origbad $badcolors
6509 }
6510 if {[info exists colormap($x)]
6511 && [lsearch -exact $badcolors $colormap($x)] < 0} {
6512 lappend badcolors $colormap($x)
6513 }
Paul Mackerras6c20ff32005-06-22 19:53:32 +10006514 }
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006515 if {[llength $badcolors] >= $ncolors} {
Denton Liue2445882020-09-10 21:36:33 -07006516 set badcolors $origbad
Paul Mackerras50b44ec2006-04-04 10:16:22 +10006517 }
Paul Mackerras6c20ff32005-06-22 19:53:32 +10006518 set origbad $badcolors
6519 if {[llength $badcolors] < $ncolors - 1} {
Denton Liue2445882020-09-10 21:36:33 -07006520 foreach child $kids {
6521 if {[info exists colormap($child)]
6522 && [lsearch -exact $badcolors $colormap($child)] < 0} {
6523 lappend badcolors $colormap($child)
6524 }
6525 foreach p $parents($curview,$child) {
6526 if {[info exists colormap($p)]
6527 && [lsearch -exact $badcolors $colormap($p)] < 0} {
6528 lappend badcolors $colormap($p)
6529 }
6530 }
6531 }
6532 if {[llength $badcolors] >= $ncolors} {
6533 set badcolors $origbad
6534 }
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00006535 }
6536 for {set i 0} {$i <= $ncolors} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07006537 set c [lindex $colors $nextcolor]
6538 if {[incr nextcolor] >= $ncolors} {
6539 set nextcolor 0
6540 }
6541 if {[lsearch -exact $badcolors $c]} break
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00006542 }
6543 set colormap($id) $c
6544}
6545
Paul Mackerrasa823a912005-06-21 10:01:38 +10006546proc bindline {t id} {
6547 global canv
6548
Paul Mackerrasa823a912005-06-21 10:01:38 +10006549 $canv bind $t <Enter> "lineenter %x %y $id"
6550 $canv bind $t <Motion> "linemotion %x %y $id"
6551 $canv bind $t <Leave> "lineleave $id"
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10006552 $canv bind $t <Button-1> "lineclick %x %y $id 1"
Paul Mackerrasa823a912005-06-21 10:01:38 +10006553}
6554
Paul Mackerras4399fe32013-01-03 10:10:31 +11006555proc graph_pane_width {} {
6556 global use_ttk
6557
6558 if {$use_ttk} {
Denton Liue2445882020-09-10 21:36:33 -07006559 set g [.tf.histframe.pwclist sashpos 0]
Paul Mackerras4399fe32013-01-03 10:10:31 +11006560 } else {
Denton Liue2445882020-09-10 21:36:33 -07006561 set g [.tf.histframe.pwclist sash coord 0]
Paul Mackerras4399fe32013-01-03 10:10:31 +11006562 }
6563 return [lindex $g 0]
6564}
6565
6566proc totalwidth {l font extra} {
6567 set tot 0
6568 foreach str $l {
Denton Liue2445882020-09-10 21:36:33 -07006569 set tot [expr {$tot + [font measure $font $str] + $extra}]
Paul Mackerras4399fe32013-01-03 10:10:31 +11006570 }
6571 return $tot
6572}
6573
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006574proc drawtags {id x xt y1} {
Paul Mackerras8a485712006-07-06 10:21:23 +10006575 global idtags idheads idotherrefs mainhead
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006576 global linespc lthickness
Paul Mackerrasd277e892008-09-21 18:11:37 -05006577 global canv rowtextx curview fgcolor bgcolor ctxbut
Gauthier Östervall252c52d2013-03-27 14:40:51 +01006578 global headbgcolor headfgcolor headoutlinecolor remotebgcolor
6579 global tagbgcolor tagfgcolor tagoutlinecolor
6580 global reflinecolor
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006581
6582 set marks {}
6583 set ntags 0
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10006584 set nheads 0
Paul Mackerras4399fe32013-01-03 10:10:31 +11006585 set singletag 0
6586 set maxtags 3
6587 set maxtagpct 25
6588 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}]
6589 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
6590 set extra [expr {$delta + $lthickness + $linespc}]
6591
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006592 if {[info exists idtags($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006593 set marks $idtags($id)
6594 set ntags [llength $marks]
6595 if {$ntags > $maxtags ||
6596 [totalwidth $marks mainfont $extra] > $maxwidth} {
6597 # show just a single "n tags..." tag
6598 set singletag 1
6599 if {$ntags == 1} {
6600 set marks [list "tag..."]
6601 } else {
6602 set marks [list [format "%d tags..." $ntags]]
6603 }
6604 set ntags 1
6605 }
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006606 }
6607 if {[info exists idheads($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006608 set marks [concat $marks $idheads($id)]
6609 set nheads [llength $idheads($id)]
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10006610 }
6611 if {[info exists idotherrefs($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07006612 set marks [concat $marks $idotherrefs($id)]
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006613 }
6614 if {$marks eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07006615 return $xt
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006616 }
6617
Jeff Hobbs2ed49d52005-11-22 17:39:53 -08006618 set yt [expr {$y1 - 0.5 * $linespc}]
6619 set yb [expr {$yt + $linespc - 1}]
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006620 set xvals {}
6621 set wvals {}
Paul Mackerras8a485712006-07-06 10:21:23 +10006622 set i -1
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006623 foreach tag $marks {
Denton Liue2445882020-09-10 21:36:33 -07006624 incr i
6625 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
6626 set wid [font measure mainfontbold $tag]
6627 } else {
6628 set wid [font measure mainfont $tag]
6629 }
6630 lappend xvals $xt
6631 lappend wvals $wid
6632 set xt [expr {$xt + $wid + $extra}]
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006633 }
6634 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
Denton Liue2445882020-09-10 21:36:33 -07006635 -width $lthickness -fill $reflinecolor -tags tag.$id]
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006636 $canv lower $t
6637 foreach tag $marks x $xvals wid $wvals {
Denton Liue2445882020-09-10 21:36:33 -07006638 set tag_quoted [string map {% %%} $tag]
6639 set xl [expr {$x + $delta}]
6640 set xr [expr {$x + $delta + $wid + $lthickness}]
6641 set font mainfont
6642 if {[incr ntags -1] >= 0} {
6643 # draw a tag
6644 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
6645 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
6646 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \
6647 -tags tag.$id]
6648 if {$singletag} {
6649 set tagclick [list showtags $id 1]
6650 } else {
6651 set tagclick [list showtag $tag_quoted 1]
6652 }
6653 $canv bind $t <1> $tagclick
6654 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
6655 } else {
6656 # draw a head or other ref
6657 if {[incr nheads -1] >= 0} {
6658 set col $headbgcolor
6659 if {$tag eq $mainhead} {
6660 set font mainfontbold
6661 }
6662 } else {
6663 set col "#ddddff"
6664 }
6665 set xl [expr {$xl - $delta/2}]
6666 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
6667 -width 1 -outline black -fill $col -tags tag.$id
6668 if {[regexp {^(remotes/.*/|remotes/)} $tag match remoteprefix]} {
6669 set rwid [font measure mainfont $remoteprefix]
6670 set xi [expr {$x + 1}]
6671 set yti [expr {$yt + 1}]
6672 set xri [expr {$x + $rwid}]
6673 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \
6674 -width 0 -fill $remotebgcolor -tags tag.$id
6675 }
6676 }
6677 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
6678 -font $font -tags [list tag.$id text]]
6679 if {$ntags >= 0} {
6680 $canv bind $t <1> $tagclick
6681 } elseif {$nheads >= 0} {
6682 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
6683 }
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10006684 }
6685 return $xt
6686}
6687
Raphael Zimmerer36242492011-04-19 22:37:09 +02006688proc drawnotesign {xt y} {
6689 global linespc canv fgcolor
6690
6691 set orad [expr {$linespc / 3}]
6692 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \
Denton Liue2445882020-09-10 21:36:33 -07006693 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \
6694 -fill yellow -outline $fgcolor -width 1 -tags circle]
Raphael Zimmerer36242492011-04-19 22:37:09 +02006695 set xt [expr {$xt + $orad * 3}]
6696 return $xt
6697}
6698
Paul Mackerras8d858d12005-08-05 09:52:16 +10006699proc xcoord {i level ln} {
6700 global canvx0 xspc1 xspc2
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00006701
Paul Mackerras8d858d12005-08-05 09:52:16 +10006702 set x [expr {$canvx0 + $i * $xspc1($ln)}]
6703 if {$i > 0 && $i == $level} {
Denton Liue2445882020-09-10 21:36:33 -07006704 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
Paul Mackerras8d858d12005-08-05 09:52:16 +10006705 } elseif {$i > $level} {
Denton Liue2445882020-09-10 21:36:33 -07006706 set x [expr {$x + $xspc2 - $xspc1($ln)}]
Paul Mackerras8d858d12005-08-05 09:52:16 +10006707 }
6708 return $x
6709}
6710
Paul Mackerras098dd8a2006-05-03 09:32:53 +10006711proc show_status {msg} {
Paul Mackerras9c311b32007-10-04 22:27:13 +10006712 global canv fgcolor
Paul Mackerras098dd8a2006-05-03 09:32:53 +10006713
6714 clear_display
Marc Branchaud9922c5a2015-04-07 11:51:51 -04006715 set_window_title
Paul Mackerras9c311b32007-10-04 22:27:13 +10006716 $canv create text 3 3 -anchor nw -text $msg -font mainfont \
Denton Liue2445882020-09-10 21:36:33 -07006717 -tags text -fill $fgcolor
Paul Mackerras098dd8a2006-05-03 09:32:53 +10006718}
6719
Paul Mackerras94a2eed2005-08-07 15:27:57 +10006720# Don't change the text pane cursor if it is currently the hand cursor,
6721# showing that we are over a sha1 ID link.
6722proc settextcursor {c} {
6723 global ctext curtextcursor
6724
6725 if {[$ctext cget -cursor] == $curtextcursor} {
Denton Liue2445882020-09-10 21:36:33 -07006726 $ctext config -cursor $c
Paul Mackerras94a2eed2005-08-07 15:27:57 +10006727 }
6728 set curtextcursor $c
Paul Mackerras9ccbdfb2005-06-16 00:27:23 +00006729}
6730
Paul Mackerrasa137a902007-10-23 21:12:49 +10006731proc nowbusy {what {name {}}} {
6732 global isbusy busyname statusw
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006733
6734 if {[array names isbusy] eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07006735 . config -cursor watch
6736 settextcursor watch
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006737 }
6738 set isbusy($what) 1
Paul Mackerrasa137a902007-10-23 21:12:49 +10006739 set busyname($what) $name
6740 if {$name ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07006741 $statusw conf -text $name
Paul Mackerrasa137a902007-10-23 21:12:49 +10006742 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006743}
6744
6745proc notbusy {what} {
Paul Mackerrasa137a902007-10-23 21:12:49 +10006746 global isbusy maincursor textcursor busyname statusw
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006747
Paul Mackerrasa137a902007-10-23 21:12:49 +10006748 catch {
Denton Liue2445882020-09-10 21:36:33 -07006749 unset isbusy($what)
6750 if {$busyname($what) ne {} &&
6751 [$statusw cget -text] eq $busyname($what)} {
6752 $statusw conf -text {}
6753 }
Paul Mackerrasa137a902007-10-23 21:12:49 +10006754 }
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006755 if {[array names isbusy] eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07006756 . config -cursor $maincursor
6757 settextcursor $textcursor
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10006758 }
6759}
6760
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006761proc findmatches {f} {
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006762 global findtype findstring
Christian Stimmingb007ee22007-11-07 18:44:35 +01006763 if {$findtype == [mc "Regexp"]} {
Denton Liue2445882020-09-10 21:36:33 -07006764 set matches [regexp -indices -all -inline $findstring $f]
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006765 } else {
Denton Liue2445882020-09-10 21:36:33 -07006766 set fs $findstring
6767 if {$findtype == [mc "IgnCase"]} {
6768 set f [string tolower $f]
6769 set fs [string tolower $fs]
6770 }
6771 set matches {}
6772 set i 0
6773 set l [string length $fs]
6774 while {[set j [string first $fs $f $i]] >= 0} {
6775 lappend matches [list $j [expr {$j+$l-1}]]
6776 set i [expr {$j + $l}]
6777 }
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006778 }
6779 return $matches
6780}
6781
Paul Mackerrascca5d942007-10-27 21:16:56 +10006782proc dofind {{dirn 1} {wrap 1}} {
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006783 global findstring findstartline findcurline selectedline numcommits
Paul Mackerrascca5d942007-10-27 21:16:56 +10006784 global gdttype filehighlight fh_serial find_dirn findallowwrap
Paul Mackerrasb74fd572005-07-16 07:46:13 -04006785
Paul Mackerrascca5d942007-10-27 21:16:56 +10006786 if {[info exists find_dirn]} {
Denton Liue2445882020-09-10 21:36:33 -07006787 if {$find_dirn == $dirn} return
6788 stopfinding
Paul Mackerrascca5d942007-10-27 21:16:56 +10006789 }
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006790 focus .
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006791 if {$findstring eq {} || $numcommits == 0} return
Paul Mackerras94b4a692008-05-20 20:51:06 +10006792 if {$selectedline eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07006793 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
Paul Mackerras98f350e2005-05-15 05:56:51 +00006794 } else {
Denton Liue2445882020-09-10 21:36:33 -07006795 set findstartline $selectedline
Paul Mackerras98f350e2005-05-15 05:56:51 +00006796 }
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006797 set findcurline $findstartline
Christian Stimmingb007ee22007-11-07 18:44:35 +01006798 nowbusy finding [mc "Searching"]
6799 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} {
Denton Liue2445882020-09-10 21:36:33 -07006800 after cancel do_file_hl $fh_serial
6801 do_file_hl $fh_serial
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006802 }
Paul Mackerrascca5d942007-10-27 21:16:56 +10006803 set find_dirn $dirn
6804 set findallowwrap $wrap
6805 run findmore
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006806}
6807
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006808proc stopfinding {} {
6809 global find_dirn findcurline fprogcoord
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006810
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006811 if {[info exists find_dirn]} {
Denton Liue2445882020-09-10 21:36:33 -07006812 unset find_dirn
6813 unset findcurline
6814 notbusy finding
6815 set fprogcoord 0
6816 adjustprogress
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006817 }
Paul Mackerras8a897742008-10-27 21:36:25 +11006818 stopblaming
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006819}
6820
6821proc findmore {} {
Paul Mackerras687c8762007-09-22 12:49:33 +10006822 global commitdata commitinfo numcommits findpattern findloc
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006823 global findstartline findcurline findallowwrap
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006824 global find_dirn gdttype fhighlights fprogcoord
Paul Mackerrascd2bcae2008-01-02 21:44:06 +11006825 global curview varcorder vrownum varccommits vrowmod
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006826
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006827 if {![info exists find_dirn]} {
Denton Liue2445882020-09-10 21:36:33 -07006828 return 0
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006829 }
Frédéric Brière585c27c2010-03-14 18:59:09 -04006830 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]]
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006831 set l $findcurline
Paul Mackerrascca5d942007-10-27 21:16:56 +10006832 set moretodo 0
6833 if {$find_dirn > 0} {
Denton Liue2445882020-09-10 21:36:33 -07006834 incr l
6835 if {$l >= $numcommits} {
6836 set l 0
6837 }
6838 if {$l <= $findstartline} {
6839 set lim [expr {$findstartline + 1}]
6840 } else {
6841 set lim $numcommits
6842 set moretodo $findallowwrap
6843 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00006844 } else {
Denton Liue2445882020-09-10 21:36:33 -07006845 if {$l == 0} {
6846 set l $numcommits
6847 }
6848 incr l -1
6849 if {$l >= $findstartline} {
6850 set lim [expr {$findstartline - 1}]
6851 } else {
6852 set lim -1
6853 set moretodo $findallowwrap
6854 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00006855 }
Paul Mackerrascca5d942007-10-27 21:16:56 +10006856 set n [expr {($lim - $l) * $find_dirn}]
6857 if {$n > 500} {
Denton Liue2445882020-09-10 21:36:33 -07006858 set n 500
6859 set moretodo 1
Paul Mackerras98f350e2005-05-15 05:56:51 +00006860 }
Paul Mackerrascd2bcae2008-01-02 21:44:06 +11006861 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} {
Denton Liue2445882020-09-10 21:36:33 -07006862 update_arcrows $curview
Paul Mackerrascd2bcae2008-01-02 21:44:06 +11006863 }
Paul Mackerras687c8762007-09-22 12:49:33 +10006864 set found 0
6865 set domore 1
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11006866 set ai [bsearch $vrownum($curview) $l]
6867 set a [lindex $varcorder($curview) $ai]
6868 set arow [lindex $vrownum($curview) $ai]
6869 set ids [lindex $varccommits($curview,$a)]
6870 set arowend [expr {$arow + [llength $ids]}]
Christian Stimmingb007ee22007-11-07 18:44:35 +01006871 if {$gdttype eq [mc "containing:"]} {
Denton Liue2445882020-09-10 21:36:33 -07006872 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6873 if {$l < $arow || $l >= $arowend} {
6874 incr ai $find_dirn
6875 set a [lindex $varcorder($curview) $ai]
6876 set arow [lindex $vrownum($curview) $ai]
6877 set ids [lindex $varccommits($curview,$a)]
6878 set arowend [expr {$arow + [llength $ids]}]
6879 }
6880 set id [lindex $ids [expr {$l - $arow}]]
6881 # shouldn't happen unless git log doesn't give all the commits...
6882 if {![info exists commitdata($id)] ||
6883 ![doesmatch $commitdata($id)]} {
6884 continue
6885 }
6886 if {![info exists commitinfo($id)]} {
6887 getcommit $id
6888 }
6889 set info $commitinfo($id)
6890 foreach f $info ty $fldtypes {
6891 if {$ty eq ""} continue
6892 if {($findloc eq [mc "All fields"] || $findloc eq $ty) &&
6893 [doesmatch $f]} {
6894 set found 1
6895 break
6896 }
6897 }
6898 if {$found} break
6899 }
Paul Mackerras687c8762007-09-22 12:49:33 +10006900 } else {
Denton Liue2445882020-09-10 21:36:33 -07006901 for {} {$n > 0} {incr n -1; incr l $find_dirn} {
6902 if {$l < $arow || $l >= $arowend} {
6903 incr ai $find_dirn
6904 set a [lindex $varcorder($curview) $ai]
6905 set arow [lindex $vrownum($curview) $ai]
6906 set ids [lindex $varccommits($curview,$a)]
6907 set arowend [expr {$arow + [llength $ids]}]
6908 }
6909 set id [lindex $ids [expr {$l - $arow}]]
6910 if {![info exists fhighlights($id)]} {
6911 # this sets fhighlights($id) to -1
6912 askfilehighlight $l $id
6913 }
6914 if {$fhighlights($id) > 0} {
6915 set found $domore
6916 break
6917 }
6918 if {$fhighlights($id) < 0} {
6919 if {$domore} {
6920 set domore 0
6921 set findcurline [expr {$l - $find_dirn}]
6922 }
6923 }
6924 }
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006925 }
Paul Mackerrascca5d942007-10-27 21:16:56 +10006926 if {$found || ($domore && !$moretodo)} {
Denton Liue2445882020-09-10 21:36:33 -07006927 unset findcurline
6928 unset find_dirn
6929 notbusy finding
6930 set fprogcoord 0
6931 adjustprogress
6932 if {$found} {
6933 findselectline $l
6934 } else {
6935 bell
6936 }
6937 return 0
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006938 }
Paul Mackerras687c8762007-09-22 12:49:33 +10006939 if {!$domore} {
Denton Liue2445882020-09-10 21:36:33 -07006940 flushhighlights
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006941 } else {
Denton Liue2445882020-09-10 21:36:33 -07006942 set findcurline [expr {$l - $find_dirn}]
Paul Mackerras687c8762007-09-22 12:49:33 +10006943 }
Paul Mackerrascca5d942007-10-27 21:16:56 +10006944 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006945 if {$n < 0} {
Denton Liue2445882020-09-10 21:36:33 -07006946 incr n $numcommits
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006947 }
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006948 set fprogcoord [expr {$n * 1.0 / $numcommits}]
6949 adjustprogress
6950 return $domore
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00006951}
6952
6953proc findselectline {l} {
Paul Mackerras687c8762007-09-22 12:49:33 +10006954 global findloc commentend ctext findcurline markingmatches gdttype
Paul Mackerras005a2f42007-07-26 22:36:39 +10006955
Paul Mackerras8b39e042008-12-02 09:02:46 +11006956 set markingmatches [expr {$gdttype eq [mc "containing:"]}]
Paul Mackerras005a2f42007-07-26 22:36:39 +10006957 set findcurline $l
Paul Mackerrasd6982062005-08-06 22:06:06 +10006958 selectline $l 1
Paul Mackerras8b39e042008-12-02 09:02:46 +11006959 if {$markingmatches &&
Denton Liue2445882020-09-10 21:36:33 -07006960 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} {
6961 # highlight the matches in the comments
6962 set f [$ctext get 1.0 $commentend]
6963 set matches [findmatches $f]
6964 foreach match $matches {
6965 set start [lindex $match 0]
6966 set end [expr {[lindex $match 1] + 1}]
6967 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
6968 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00006969 }
Paul Mackerras005a2f42007-07-26 22:36:39 +10006970 drawvisible
Paul Mackerras98f350e2005-05-15 05:56:51 +00006971}
6972
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006973# mark the bits of a headline or author that match a find string
Paul Mackerras005a2f42007-07-26 22:36:39 +10006974proc markmatches {canv l str tag matches font row} {
6975 global selectedline
6976
Paul Mackerras98f350e2005-05-15 05:56:51 +00006977 set bbox [$canv bbox $tag]
6978 set x0 [lindex $bbox 0]
6979 set y0 [lindex $bbox 1]
6980 set y1 [lindex $bbox 3]
6981 foreach match $matches {
Denton Liue2445882020-09-10 21:36:33 -07006982 set start [lindex $match 0]
6983 set end [lindex $match 1]
6984 if {$start > $end} continue
6985 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]]
6986 set xlen [font measure $font [string range $str 0 [expr {$end}]]]
6987 set t [$canv create rect [expr {$x0+$xoff}] $y0 \
6988 [expr {$x0+$xlen+2}] $y1 \
6989 -outline {} -tags [list match$l matches] -fill yellow]
6990 $canv lower $t
6991 if {$row == $selectedline} {
6992 $canv raise $t secsel
6993 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00006994 }
6995}
6996
6997proc unmarkmatches {} {
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10006998 global markingmatches
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10006999
Paul Mackerras98f350e2005-05-15 05:56:51 +00007000 allcanvs delete matches
Paul Mackerras4fb0fa12007-07-04 19:43:51 +10007001 set markingmatches 0
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10007002 stopfinding
Paul Mackerras98f350e2005-05-15 05:56:51 +00007003}
7004
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007005proc selcanvline {w x y} {
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007006 global canv canvy0 ctext linespc
Paul Mackerras9f1afe02006-02-19 22:44:47 +11007007 global rowtextx
Paul Mackerras1db95b02005-05-09 04:08:39 +00007008 set ymax [lindex [$canv cget -scrollregion] 3]
Paul Mackerrascfb45632005-05-31 12:14:42 +00007009 if {$ymax == {}} return
Paul Mackerras1db95b02005-05-09 04:08:39 +00007010 set yfrac [lindex [$canv yview] 0]
7011 set y [expr {$y + $yfrac * $ymax}]
7012 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
7013 if {$l < 0} {
Denton Liue2445882020-09-10 21:36:33 -07007014 set l 0
Paul Mackerras1db95b02005-05-09 04:08:39 +00007015 }
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007016 if {$w eq $canv} {
Denton Liue2445882020-09-10 21:36:33 -07007017 set xmax [lindex [$canv cget -scrollregion] 2]
7018 set xleft [expr {[lindex [$canv xview] 0] * $xmax}]
7019 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007020 }
Paul Mackerras98f350e2005-05-15 05:56:51 +00007021 unmarkmatches
Paul Mackerrasd6982062005-08-06 22:06:06 +10007022 selectline $l 1
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007023}
7024
Linus Torvaldsb1ba39e2005-08-08 20:04:20 -07007025proc commit_descriptor {p} {
7026 global commitinfo
Paul Mackerrasb0934482006-05-15 09:56:08 +10007027 if {![info exists commitinfo($p)]} {
Denton Liue2445882020-09-10 21:36:33 -07007028 getcommit $p
Paul Mackerrasb0934482006-05-15 09:56:08 +10007029 }
Linus Torvaldsb1ba39e2005-08-08 20:04:20 -07007030 set l "..."
Paul Mackerrasb0934482006-05-15 09:56:08 +10007031 if {[llength $commitinfo($p)] > 1} {
Denton Liue2445882020-09-10 21:36:33 -07007032 set l [lindex $commitinfo($p) 0]
Linus Torvaldsb1ba39e2005-08-08 20:04:20 -07007033 }
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007034 return "$p ($l)\n"
Linus Torvaldsb1ba39e2005-08-08 20:04:20 -07007035}
7036
Paul Mackerras106288c2005-08-19 23:11:39 +10007037# append some text to the ctext widget, and make any SHA1 ID
7038# that we know about be a clickable link.
Paul Mackerras3441de52019-08-27 08:12:34 +10007039# Also look for URLs of the form "http[s]://..." and make them web links.
Sergey Vlasovf1b86292006-05-15 19:13:14 +04007040proc appendwithlinks {text tags} {
Paul Mackerrasd375ef92008-10-21 10:18:12 +11007041 global ctext linknum curview
Paul Mackerras106288c2005-08-19 23:11:39 +10007042
7043 set start [$ctext index "end - 1c"]
Sergey Vlasovf1b86292006-05-15 19:13:14 +04007044 $ctext insert end $text $tags
Jim Meyering6c9e2d12011-12-10 16:08:57 +01007045 set links [regexp -indices -all -inline {(?:\m|-g)[0-9a-f]{6,40}\M} $text]
Paul Mackerras106288c2005-08-19 23:11:39 +10007046 foreach l $links {
Denton Liue2445882020-09-10 21:36:33 -07007047 set s [lindex $l 0]
7048 set e [lindex $l 1]
7049 set linkid [string range $text $s $e]
7050 incr e
7051 $ctext tag delete link$linknum
7052 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
7053 setlink $linkid link$linknum
7054 incr linknum
Paul Mackerras106288c2005-08-19 23:11:39 +10007055 }
Paul Mackerras3441de52019-08-27 08:12:34 +10007056 set wlinks [regexp -indices -all -inline -line \
Denton Liue2445882020-09-10 21:36:33 -07007057 {https?://[^[:space:]]+} $text]
Paul Mackerras3441de52019-08-27 08:12:34 +10007058 foreach l $wlinks {
Denton Liue2445882020-09-10 21:36:33 -07007059 set s2 [lindex $l 0]
7060 set e2 [lindex $l 1]
7061 set url [string range $text $s2 $e2]
7062 incr e2
7063 $ctext tag delete link$linknum
7064 $ctext tag add link$linknum "$start + $s2 c" "$start + $e2 c"
7065 setwlink $url link$linknum
7066 incr linknum
Paul Mackerras3441de52019-08-27 08:12:34 +10007067 }
Paul Mackerras97645682007-08-23 22:24:38 +10007068}
7069
7070proc setlink {id lk} {
Paul Mackerrasd375ef92008-10-21 10:18:12 +11007071 global curview ctext pendinglinks
Gauthier Östervall252c52d2013-03-27 14:40:51 +01007072 global linkfgcolor
Paul Mackerras97645682007-08-23 22:24:38 +10007073
Jim Meyering6c9e2d12011-12-10 16:08:57 +01007074 if {[string range $id 0 1] eq "-g"} {
7075 set id [string range $id 2 end]
7076 }
7077
Paul Mackerrasd375ef92008-10-21 10:18:12 +11007078 set known 0
7079 if {[string length $id] < 40} {
Denton Liue2445882020-09-10 21:36:33 -07007080 set matches [longid $id]
7081 if {[llength $matches] > 0} {
7082 if {[llength $matches] > 1} return
7083 set known 1
7084 set id [lindex $matches 0]
7085 }
Paul Mackerrasd375ef92008-10-21 10:18:12 +11007086 } else {
Denton Liue2445882020-09-10 21:36:33 -07007087 set known [commitinview $id $curview]
Paul Mackerrasd375ef92008-10-21 10:18:12 +11007088 }
7089 if {$known} {
Denton Liue2445882020-09-10 21:36:33 -07007090 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
7091 $ctext tag bind $lk <1> [list selbyid $id]
7092 $ctext tag bind $lk <Enter> {linkcursor %W 1}
7093 $ctext tag bind $lk <Leave> {linkcursor %W -1}
Paul Mackerras97645682007-08-23 22:24:38 +10007094 } else {
Denton Liue2445882020-09-10 21:36:33 -07007095 lappend pendinglinks($id) $lk
7096 interestedin $id {makelink %P}
Paul Mackerras97645682007-08-23 22:24:38 +10007097 }
7098}
7099
Paul Mackerras3441de52019-08-27 08:12:34 +10007100proc setwlink {url lk} {
7101 global ctext
7102 global linkfgcolor
7103 global web_browser
7104
7105 if {$web_browser eq {}} return
7106 $ctext tag conf $lk -foreground $linkfgcolor -underline 1
7107 $ctext tag bind $lk <1> [list browseweb $url]
7108 $ctext tag bind $lk <Enter> {linkcursor %W 1}
7109 $ctext tag bind $lk <Leave> {linkcursor %W -1}
7110}
7111
Paul Mackerras6f63fc12009-04-21 22:22:31 +10007112proc appendshortlink {id {pre {}} {post {}}} {
7113 global ctext linknum
7114
7115 $ctext insert end $pre
7116 $ctext tag delete link$linknum
7117 $ctext insert end [string range $id 0 7] link$linknum
7118 $ctext insert end $post
7119 setlink $id link$linknum
7120 incr linknum
7121}
7122
Paul Mackerras97645682007-08-23 22:24:38 +10007123proc makelink {id} {
7124 global pendinglinks
7125
7126 if {![info exists pendinglinks($id)]} return
7127 foreach lk $pendinglinks($id) {
Denton Liue2445882020-09-10 21:36:33 -07007128 setlink $id $lk
Paul Mackerras97645682007-08-23 22:24:38 +10007129 }
7130 unset pendinglinks($id)
7131}
7132
7133proc linkcursor {w inc} {
7134 global linkentercount curtextcursor
7135
7136 if {[incr linkentercount $inc] > 0} {
Denton Liue2445882020-09-10 21:36:33 -07007137 $w configure -cursor hand2
Paul Mackerras97645682007-08-23 22:24:38 +10007138 } else {
Denton Liue2445882020-09-10 21:36:33 -07007139 $w configure -cursor $curtextcursor
7140 if {$linkentercount < 0} {
7141 set linkentercount 0
7142 }
Paul Mackerras97645682007-08-23 22:24:38 +10007143 }
Paul Mackerras106288c2005-08-19 23:11:39 +10007144}
7145
Paul Mackerras3441de52019-08-27 08:12:34 +10007146proc browseweb {url} {
7147 global web_browser
7148
7149 if {$web_browser eq {}} return
7150 # Use eval here in case $web_browser is a command plus some arguments
7151 if {[catch {eval exec $web_browser [list $url] &} err]} {
Denton Liue2445882020-09-10 21:36:33 -07007152 error_popup "[mc "Error starting web browser:"] $err"
Paul Mackerras3441de52019-08-27 08:12:34 +10007153 }
7154}
7155
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007156proc viewnextline {dir} {
7157 global canv linespc
7158
7159 $canv delete hover
7160 set ymax [lindex [$canv cget -scrollregion] 3]
7161 set wnow [$canv yview]
7162 set wtop [expr {[lindex $wnow 0] * $ymax}]
7163 set newtop [expr {$wtop + $dir * $linespc}]
7164 if {$newtop < 0} {
Denton Liue2445882020-09-10 21:36:33 -07007165 set newtop 0
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007166 } elseif {$newtop > $ymax} {
Denton Liue2445882020-09-10 21:36:33 -07007167 set newtop $ymax
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007168 }
7169 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7170}
7171
Paul Mackerrasef030b82006-06-04 11:50:38 +10007172# add a list of tag or branch names at position pos
7173# returns the number of names inserted
Paul Mackerrase11f1232007-06-16 20:29:25 +10007174proc appendrefs {pos ids var} {
Max Kirillovbde4a0f2014-06-24 08:19:44 +03007175 global ctext linknum curview $var maxrefs visiblerefs mainheadid
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007176
Paul Mackerrasef030b82006-06-04 11:50:38 +10007177 if {[catch {$ctext index $pos}]} {
Denton Liue2445882020-09-10 21:36:33 -07007178 return 0
Paul Mackerrasef030b82006-06-04 11:50:38 +10007179 }
Paul Mackerrase11f1232007-06-16 20:29:25 +10007180 $ctext conf -state normal
7181 $ctext delete $pos "$pos lineend"
7182 set tags {}
7183 foreach id $ids {
Denton Liue2445882020-09-10 21:36:33 -07007184 foreach tag [set $var\($id\)] {
7185 lappend tags [list $tag $id]
7186 }
Paul Mackerrase11f1232007-06-16 20:29:25 +10007187 }
Paul Mackerras386befb2013-01-02 15:25:29 +11007188
7189 set sep {}
7190 set tags [lsort -index 0 -decreasing $tags]
7191 set nutags 0
7192
Paul Mackerras0a4dd8b2007-06-16 21:21:57 +10007193 if {[llength $tags] > $maxrefs} {
Denton Liue2445882020-09-10 21:36:33 -07007194 # If we are displaying heads, and there are too many,
7195 # see if there are some important heads to display.
7196 # Currently that are the current head and heads listed in $visiblerefs option
7197 set itags {}
7198 if {$var eq "idheads"} {
7199 set utags {}
7200 foreach ti $tags {
7201 set hname [lindex $ti 0]
7202 set id [lindex $ti 1]
7203 if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) &&
7204 [llength $itags] < $maxrefs} {
7205 lappend itags $ti
7206 } else {
7207 lappend utags $ti
7208 }
7209 }
7210 set tags $utags
7211 }
7212 if {$itags ne {}} {
7213 set str [mc "and many more"]
7214 set sep " "
7215 } else {
7216 set str [mc "many"]
7217 }
7218 $ctext insert $pos "$str ([llength $tags])"
7219 set nutags [llength $tags]
7220 set tags $itags
Paul Mackerras386befb2013-01-02 15:25:29 +11007221 }
7222
7223 foreach ti $tags {
Denton Liue2445882020-09-10 21:36:33 -07007224 set id [lindex $ti 1]
7225 set lk link$linknum
7226 incr linknum
7227 $ctext tag delete $lk
7228 $ctext insert $pos $sep
7229 $ctext insert $pos [lindex $ti 0] $lk
7230 setlink $id $lk
7231 set sep ", "
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007232 }
Paul Mackerrasd34835c2013-01-01 23:08:12 +11007233 $ctext tag add wwrap "$pos linestart" "$pos lineend"
Paul Mackerrase11f1232007-06-16 20:29:25 +10007234 $ctext conf -state disabled
Paul Mackerras386befb2013-01-02 15:25:29 +11007235 return [expr {[llength $tags] + $nutags}]
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007236}
7237
7238# called when we have finished computing the nearby tags
Paul Mackerrase11f1232007-06-16 20:29:25 +10007239proc dispneartags {delay} {
7240 global selectedline currentid showneartags tagphase
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007241
Paul Mackerras94b4a692008-05-20 20:51:06 +10007242 if {$selectedline eq {} || !$showneartags} return
Paul Mackerrase11f1232007-06-16 20:29:25 +10007243 after cancel dispnexttag
7244 if {$delay} {
Denton Liue2445882020-09-10 21:36:33 -07007245 after 200 dispnexttag
7246 set tagphase -1
Paul Mackerrase11f1232007-06-16 20:29:25 +10007247 } else {
Denton Liue2445882020-09-10 21:36:33 -07007248 after idle dispnexttag
7249 set tagphase 0
Paul Mackerrase11f1232007-06-16 20:29:25 +10007250 }
7251}
7252
7253proc dispnexttag {} {
7254 global selectedline currentid showneartags tagphase ctext
7255
Paul Mackerras94b4a692008-05-20 20:51:06 +10007256 if {$selectedline eq {} || !$showneartags} return
Paul Mackerrase11f1232007-06-16 20:29:25 +10007257 switch -- $tagphase {
Denton Liue2445882020-09-10 21:36:33 -07007258 0 {
7259 set dtags [desctags $currentid]
7260 if {$dtags ne {}} {
7261 appendrefs precedes $dtags idtags
7262 }
7263 }
7264 1 {
7265 set atags [anctags $currentid]
7266 if {$atags ne {}} {
7267 appendrefs follows $atags idtags
7268 }
7269 }
7270 2 {
7271 set dheads [descheads $currentid]
7272 if {$dheads ne {}} {
7273 if {[appendrefs branch $dheads idheads] > 1
7274 && [$ctext get "branch -3c"] eq "h"} {
7275 # turn "Branch" into "Branches"
7276 $ctext conf -state normal
7277 $ctext insert "branch -2c" "es"
7278 $ctext conf -state disabled
7279 }
7280 }
7281 }
Paul Mackerrasef030b82006-06-04 11:50:38 +10007282 }
Paul Mackerrase11f1232007-06-16 20:29:25 +10007283 if {[incr tagphase] <= 2} {
Denton Liue2445882020-09-10 21:36:33 -07007284 after idle dispnexttag
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007285 }
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007286}
7287
Paul Mackerras28593d32008-11-13 23:01:46 +11007288proc make_secsel {id} {
Paul Mackerras03800812007-08-29 21:45:21 +10007289 global linehtag linentag linedtag canv canv2 canv3
7290
Paul Mackerras28593d32008-11-13 23:01:46 +11007291 if {![info exists linehtag($id)]} return
Paul Mackerras03800812007-08-29 21:45:21 +10007292 $canv delete secsel
Paul Mackerras28593d32008-11-13 23:01:46 +11007293 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
Denton Liue2445882020-09-10 21:36:33 -07007294 -tags secsel -fill [$canv cget -selectbackground]]
Paul Mackerras03800812007-08-29 21:45:21 +10007295 $canv lower $t
7296 $canv2 delete secsel
Paul Mackerras28593d32008-11-13 23:01:46 +11007297 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
Denton Liue2445882020-09-10 21:36:33 -07007298 -tags secsel -fill [$canv2 cget -selectbackground]]
Paul Mackerras03800812007-08-29 21:45:21 +10007299 $canv2 lower $t
7300 $canv3 delete secsel
Paul Mackerras28593d32008-11-13 23:01:46 +11007301 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
Denton Liue2445882020-09-10 21:36:33 -07007302 -tags secsel -fill [$canv3 cget -selectbackground]]
Paul Mackerras03800812007-08-29 21:45:21 +10007303 $canv3 lower $t
7304}
7305
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10007306proc make_idmark {id} {
7307 global linehtag canv fgcolor
7308
7309 if {![info exists linehtag($id)]} return
7310 $canv delete markid
7311 set t [eval $canv create rect [$canv bbox $linehtag($id)] \
Denton Liue2445882020-09-10 21:36:33 -07007312 -tags markid -outline $fgcolor]
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10007313 $canv raise $t
7314}
7315
Max Kirillov4135d362014-04-05 23:38:50 +03007316proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
Paul Mackerras03800812007-08-29 21:45:21 +10007317 global canv ctext commitinfo selectedline
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11007318 global canvy0 linespc parents children curview
Paul Mackerras7fcceed2006-04-27 19:21:49 +10007319 global currentid sha1entry
Paul Mackerras9f1afe02006-02-19 22:44:47 +11007320 global commentend idtags linknum
Paul Mackerrasd94f8cd2006-04-06 10:18:23 +10007321 global mergemax numcommits pending_select
Paul Mackerrase11f1232007-06-16 20:29:25 +10007322 global cmitmode showneartags allcommits
Paul Mackerrasc30acc72008-03-07 22:51:55 +11007323 global targetrow targetid lastscrollrows
Paul Mackerras21ac8a82011-03-09 20:52:38 +11007324 global autoselect autosellen jump_to_here
Thomas Rast9403bd02013-11-16 18:37:43 +01007325 global vinlinediff
Paul Mackerrasd6982062005-08-06 22:06:06 +10007326
Paul Mackerras009409f2015-05-02 20:53:36 +10007327 unset -nocomplain pending_select
Paul Mackerras84ba7342005-06-17 00:12:26 +00007328 $canv delete hover
Paul Mackerras9843c302005-08-30 10:57:11 +10007329 normalline
Paul Mackerras887c9962007-08-20 19:36:20 +10007330 unsel_reflist
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10007331 stopfinding
Paul Mackerras8f7d0ce2006-02-28 22:10:19 +11007332 if {$l < 0 || $l >= $numcommits} return
Paul Mackerrasac1276a2008-03-03 10:11:08 +11007333 set id [commitonrow $l]
7334 set targetid $id
7335 set targetrow $l
Paul Mackerrasc30acc72008-03-07 22:51:55 +11007336 set selectedline $l
7337 set currentid $id
7338 if {$lastscrollrows < $numcommits} {
Denton Liue2445882020-09-10 21:36:33 -07007339 setcanvscroll
Paul Mackerrasc30acc72008-03-07 22:51:55 +11007340 }
Paul Mackerrasac1276a2008-03-03 10:11:08 +11007341
Max Kirillov4135d362014-04-05 23:38:50 +03007342 if {$cmitmode ne "patch" && $switch_to_patch} {
7343 set cmitmode "patch"
7344 }
7345
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007346 set y [expr {$canvy0 + $l * $linespc}]
Paul Mackerras17386062005-05-18 22:51:00 +00007347 set ymax [lindex [$canv cget -scrollregion] 3]
Paul Mackerras58422152005-05-19 10:56:42 +00007348 set ytop [expr {$y - $linespc - 1}]
7349 set ybot [expr {$y + $linespc + 1}]
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007350 set wnow [$canv yview]
Jeff Hobbs2ed49d52005-11-22 17:39:53 -08007351 set wtop [expr {[lindex $wnow 0] * $ymax}]
7352 set wbot [expr {[lindex $wnow 1] * $ymax}]
Paul Mackerras58422152005-05-19 10:56:42 +00007353 set wh [expr {$wbot - $wtop}]
7354 set newtop $wtop
Paul Mackerras17386062005-05-18 22:51:00 +00007355 if {$ytop < $wtop} {
Denton Liue2445882020-09-10 21:36:33 -07007356 if {$ybot < $wtop} {
7357 set newtop [expr {$y - $wh / 2.0}]
7358 } else {
7359 set newtop $ytop
7360 if {$newtop > $wtop - $linespc} {
7361 set newtop [expr {$wtop - $linespc}]
7362 }
7363 }
Paul Mackerras58422152005-05-19 10:56:42 +00007364 } elseif {$ybot > $wbot} {
Denton Liue2445882020-09-10 21:36:33 -07007365 if {$ytop > $wbot} {
7366 set newtop [expr {$y - $wh / 2.0}]
7367 } else {
7368 set newtop [expr {$ybot - $wh}]
7369 if {$newtop < $wtop + $linespc} {
7370 set newtop [expr {$wtop + $linespc}]
7371 }
7372 }
Paul Mackerras58422152005-05-19 10:56:42 +00007373 }
7374 if {$newtop != $wtop} {
Denton Liue2445882020-09-10 21:36:33 -07007375 if {$newtop < 0} {
7376 set newtop 0
7377 }
7378 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
7379 drawvisible
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007380 }
Paul Mackerrasd6982062005-08-06 22:06:06 +10007381
Paul Mackerras28593d32008-11-13 23:01:46 +11007382 make_secsel $id
Paul Mackerras9f1afe02006-02-19 22:44:47 +11007383
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007384 if {$isnew} {
Denton Liue2445882020-09-10 21:36:33 -07007385 addtohistory [list selbyid $id 0] savecmitpos
Paul Mackerrasd6982062005-08-06 22:06:06 +10007386 }
7387
Paul Mackerras98f350e2005-05-15 05:56:51 +00007388 $sha1entry delete 0 end
7389 $sha1entry insert 0 $id
Jeff King95293b52008-03-06 06:49:25 -05007390 if {$autoselect} {
Denton Liue2445882020-09-10 21:36:33 -07007391 $sha1entry selection range 0 $autosellen
Jeff King95293b52008-03-06 06:49:25 -05007392 }
Paul Mackerras164ff272006-05-29 19:50:02 +10007393 rhighlight_sel $id
Paul Mackerras98f350e2005-05-15 05:56:51 +00007394
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007395 $ctext conf -state normal
Paul Mackerras3ea06f92006-05-24 10:16:03 +10007396 clear_ctext
Paul Mackerras106288c2005-08-19 23:11:39 +10007397 set linknum 0
Paul Mackerrasd76afb12008-03-07 21:19:18 +11007398 if {![info exists commitinfo($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07007399 getcommit $id
Paul Mackerrasd76afb12008-03-07 21:19:18 +11007400 }
Paul Mackerras1db95b02005-05-09 04:08:39 +00007401 set info $commitinfo($id)
Paul Mackerras232475d2005-11-15 10:34:03 +11007402 set date [formatdate [lindex $info 2]]
Christian Stimmingd990ced2007-11-07 18:42:55 +01007403 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n"
Paul Mackerras232475d2005-11-15 10:34:03 +11007404 set date [formatdate [lindex $info 4]]
Christian Stimmingd990ced2007-11-07 18:42:55 +01007405 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n"
Paul Mackerras887fe3c2005-05-21 07:35:37 +00007406 if {[info exists idtags($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07007407 $ctext insert end [mc "Tags:"]
7408 foreach tag $idtags($id) {
7409 $ctext insert end " $tag"
7410 }
7411 $ctext insert end "\n"
Paul Mackerras887fe3c2005-05-21 07:35:37 +00007412 }
Mark Levedahl40b87ff2007-02-01 08:44:46 -05007413
Sergey Vlasovf1b86292006-05-15 19:13:14 +04007414 set headers {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11007415 set olds $parents($curview,$id)
Paul Mackerras79b2c752006-04-02 20:47:40 +10007416 if {[llength $olds] > 1} {
Denton Liue2445882020-09-10 21:36:33 -07007417 set np 0
7418 foreach p $olds {
7419 if {$np >= $mergemax} {
7420 set tag mmax
7421 } else {
7422 set tag m$np
7423 }
7424 $ctext insert end "[mc "Parent"]: " $tag
7425 appendwithlinks [commit_descriptor $p] {}
7426 incr np
7427 }
Paul Mackerrasb77b0272006-02-07 09:13:52 +11007428 } else {
Denton Liue2445882020-09-10 21:36:33 -07007429 foreach p $olds {
7430 append headers "[mc "Parent"]: [commit_descriptor $p]"
7431 }
Linus Torvaldsb1ba39e2005-08-08 20:04:20 -07007432 }
Paul Mackerrasb77b0272006-02-07 09:13:52 +11007433
Paul Mackerras6a90bff2007-06-18 09:48:23 +10007434 foreach c $children($curview,$id) {
Denton Liue2445882020-09-10 21:36:33 -07007435 append headers "[mc "Child"]: [commit_descriptor $c]"
Linus Torvalds8b192802005-08-07 13:58:56 -07007436 }
Paul Mackerrasd6982062005-08-06 22:06:06 +10007437
7438 # make anything that looks like a SHA1 ID be a clickable link
Sergey Vlasovf1b86292006-05-15 19:13:14 +04007439 appendwithlinks $headers {}
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007440 if {$showneartags} {
Denton Liue2445882020-09-10 21:36:33 -07007441 if {![info exists allcommits]} {
7442 getallcommits
7443 }
7444 $ctext insert end "[mc "Branch"]: "
7445 $ctext mark set branch "end -1c"
7446 $ctext mark gravity branch left
7447 $ctext insert end "\n[mc "Follows"]: "
7448 $ctext mark set follows "end -1c"
7449 $ctext mark gravity follows left
7450 $ctext insert end "\n[mc "Precedes"]: "
7451 $ctext mark set precedes "end -1c"
7452 $ctext mark gravity precedes left
7453 $ctext insert end "\n"
7454 dispneartags 1
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10007455 }
7456 $ctext insert end "\n"
Paul Mackerras43c25072006-09-27 10:56:02 +10007457 set comment [lindex $info 5]
7458 if {[string first "\r" $comment] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007459 set comment [string map {"\r" "\n "} $comment]
Paul Mackerras43c25072006-09-27 10:56:02 +10007460 }
7461 appendwithlinks $comment {comment}
Paul Mackerrasd6982062005-08-06 22:06:06 +10007462
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00007463 $ctext tag remove found 1.0 end
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007464 $ctext conf -state disabled
Paul Mackerrasdf3d83b2005-05-17 23:23:07 +00007465 set commentend [$ctext index "end - 1c"]
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007466
Paul Mackerras8a897742008-10-27 21:36:25 +11007467 set jump_to_here $desired_loc
Christian Stimmingb007ee22007-11-07 18:44:35 +01007468 init_flist [mc "Comments"]
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007469 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07007470 gettree $id
Thomas Rast9403bd02013-11-16 18:37:43 +01007471 } elseif {$vinlinediff($curview) == 1} {
Denton Liue2445882020-09-10 21:36:33 -07007472 showinlinediff $id
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007473 } elseif {[llength $olds] <= 1} {
Denton Liue2445882020-09-10 21:36:33 -07007474 startdiff $id
Paul Mackerras7b5ff7e2006-03-30 20:50:40 +11007475 } else {
Denton Liue2445882020-09-10 21:36:33 -07007476 mergediff $id
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007477 }
7478}
7479
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007480proc selfirstline {} {
7481 unmarkmatches
7482 selectline 0 1
7483}
7484
7485proc sellastline {} {
7486 global numcommits
7487 unmarkmatches
7488 set l [expr {$numcommits - 1}]
7489 selectline $l 1
7490}
7491
Paul Mackerrase5c2d852005-05-11 23:44:54 +00007492proc selnextline {dir} {
7493 global selectedline
Mark Levedahlbd441de2007-08-07 21:40:34 -04007494 focus .
Paul Mackerras94b4a692008-05-20 20:51:06 +10007495 if {$selectedline eq {}} return
Jeff Hobbs2ed49d52005-11-22 17:39:53 -08007496 set l [expr {$selectedline + $dir}]
Paul Mackerras98f350e2005-05-15 05:56:51 +00007497 unmarkmatches
Paul Mackerrasd6982062005-08-06 22:06:06 +10007498 selectline $l 1
7499}
7500
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007501proc selnextpage {dir} {
7502 global canv linespc selectedline numcommits
7503
7504 set lpp [expr {([winfo height $canv] - 2) / $linespc}]
7505 if {$lpp < 1} {
Denton Liue2445882020-09-10 21:36:33 -07007506 set lpp 1
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007507 }
7508 allcanvs yview scroll [expr {$dir * $lpp}] units
Paul Mackerrase72ee5e2006-05-20 09:58:49 +10007509 drawvisible
Paul Mackerras94b4a692008-05-20 20:51:06 +10007510 if {$selectedline eq {}} return
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007511 set l [expr {$selectedline + $dir * $lpp}]
7512 if {$l < 0} {
Denton Liue2445882020-09-10 21:36:33 -07007513 set l 0
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007514 } elseif {$l >= $numcommits} {
7515 set l [expr $numcommits - 1]
7516 }
7517 unmarkmatches
Mark Levedahl40b87ff2007-02-01 08:44:46 -05007518 selectline $l 1
Rutger Nijlunsing6e5f7202006-04-05 10:24:03 +10007519}
7520
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007521proc unselectline {} {
Paul Mackerras50b44ec2006-04-04 10:16:22 +10007522 global selectedline currentid
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007523
Paul Mackerras94b4a692008-05-20 20:51:06 +10007524 set selectedline {}
Paul Mackerras009409f2015-05-02 20:53:36 +10007525 unset -nocomplain currentid
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007526 allcanvs delete secsel
Paul Mackerras164ff272006-05-29 19:50:02 +10007527 rhighlight_none
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007528}
7529
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007530proc reselectline {} {
7531 global selectedline
7532
Paul Mackerras94b4a692008-05-20 20:51:06 +10007533 if {$selectedline ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07007534 selectline $selectedline 0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007535 }
7536}
7537
Paul Mackerras354af6b2008-11-23 13:14:23 +11007538proc addtohistory {cmd {saveproc {}}} {
Paul Mackerras2516dae2006-04-21 10:35:31 +10007539 global history historyindex curview
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007540
Paul Mackerras354af6b2008-11-23 13:14:23 +11007541 unset_posvars
7542 save_position
7543 set elt [list $curview $cmd $saveproc {}]
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007544 if {$historyindex > 0
Denton Liue2445882020-09-10 21:36:33 -07007545 && [lindex $history [expr {$historyindex - 1}]] == $elt} {
7546 return
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007547 }
7548
7549 if {$historyindex < [llength $history]} {
Denton Liue2445882020-09-10 21:36:33 -07007550 set history [lreplace $history $historyindex end $elt]
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007551 } else {
Denton Liue2445882020-09-10 21:36:33 -07007552 lappend history $elt
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007553 }
7554 incr historyindex
7555 if {$historyindex > 1} {
Denton Liue2445882020-09-10 21:36:33 -07007556 .tf.bar.leftbut conf -state normal
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007557 } else {
Denton Liue2445882020-09-10 21:36:33 -07007558 .tf.bar.leftbut conf -state disabled
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007559 }
Junio C Hamanoe9937d22007-02-01 08:46:38 -05007560 .tf.bar.rightbut conf -state disabled
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10007561}
7562
Paul Mackerras354af6b2008-11-23 13:14:23 +11007563# save the scrolling position of the diff display pane
7564proc save_position {} {
7565 global historyindex history
7566
7567 if {$historyindex < 1} return
7568 set hi [expr {$historyindex - 1}]
7569 set fn [lindex $history $hi 2]
7570 if {$fn ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07007571 lset history $hi 3 [eval $fn]
Paul Mackerras354af6b2008-11-23 13:14:23 +11007572 }
7573}
7574
7575proc unset_posvars {} {
7576 global last_posvars
7577
7578 if {[info exists last_posvars]} {
Denton Liue2445882020-09-10 21:36:33 -07007579 foreach {var val} $last_posvars {
7580 global $var
7581 unset -nocomplain $var
7582 }
7583 unset last_posvars
Paul Mackerras354af6b2008-11-23 13:14:23 +11007584 }
7585}
7586
Paul Mackerras2516dae2006-04-21 10:35:31 +10007587proc godo {elt} {
Paul Mackerras354af6b2008-11-23 13:14:23 +11007588 global curview last_posvars
Paul Mackerras2516dae2006-04-21 10:35:31 +10007589
7590 set view [lindex $elt 0]
7591 set cmd [lindex $elt 1]
Paul Mackerras354af6b2008-11-23 13:14:23 +11007592 set pv [lindex $elt 3]
Paul Mackerras2516dae2006-04-21 10:35:31 +10007593 if {$curview != $view} {
Denton Liue2445882020-09-10 21:36:33 -07007594 showview $view
Paul Mackerras2516dae2006-04-21 10:35:31 +10007595 }
Paul Mackerras354af6b2008-11-23 13:14:23 +11007596 unset_posvars
7597 foreach {var val} $pv {
Denton Liue2445882020-09-10 21:36:33 -07007598 global $var
7599 set $var $val
Paul Mackerras354af6b2008-11-23 13:14:23 +11007600 }
7601 set last_posvars $pv
Paul Mackerras2516dae2006-04-21 10:35:31 +10007602 eval $cmd
7603}
7604
Paul Mackerrasd6982062005-08-06 22:06:06 +10007605proc goback {} {
7606 global history historyindex
Mark Levedahlbd441de2007-08-07 21:40:34 -04007607 focus .
Paul Mackerrasd6982062005-08-06 22:06:06 +10007608
7609 if {$historyindex > 1} {
Denton Liue2445882020-09-10 21:36:33 -07007610 save_position
7611 incr historyindex -1
7612 godo [lindex $history [expr {$historyindex - 1}]]
7613 .tf.bar.rightbut conf -state normal
Paul Mackerrasd6982062005-08-06 22:06:06 +10007614 }
7615 if {$historyindex <= 1} {
Denton Liue2445882020-09-10 21:36:33 -07007616 .tf.bar.leftbut conf -state disabled
Paul Mackerrasd6982062005-08-06 22:06:06 +10007617 }
7618}
7619
7620proc goforw {} {
7621 global history historyindex
Mark Levedahlbd441de2007-08-07 21:40:34 -04007622 focus .
Paul Mackerrasd6982062005-08-06 22:06:06 +10007623
7624 if {$historyindex < [llength $history]} {
Denton Liue2445882020-09-10 21:36:33 -07007625 save_position
7626 set cmd [lindex $history $historyindex]
7627 incr historyindex
7628 godo $cmd
7629 .tf.bar.leftbut conf -state normal
Paul Mackerrasd6982062005-08-06 22:06:06 +10007630 }
7631 if {$historyindex >= [llength $history]} {
Denton Liue2445882020-09-10 21:36:33 -07007632 .tf.bar.rightbut conf -state disabled
Paul Mackerrasd6982062005-08-06 22:06:06 +10007633 }
Paul Mackerras5ad588d2005-05-10 01:02:55 +00007634}
7635
Max Kirillovd4ec30b2014-07-08 23:45:35 +03007636proc go_to_parent {i} {
7637 global parents curview targetid
7638 set ps $parents($curview,$targetid)
7639 if {[llength $ps] >= $i} {
Denton Liue2445882020-09-10 21:36:33 -07007640 selbyid [lindex $ps [expr $i - 1]]
Max Kirillovd4ec30b2014-07-08 23:45:35 +03007641 }
7642}
7643
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007644proc gettree {id} {
Paul Mackerras8f489362007-07-13 19:49:37 +10007645 global treefilelist treeidlist diffids diffmergeid treepending
7646 global nullid nullid2
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007647
7648 set diffids $id
Paul Mackerras009409f2015-05-02 20:53:36 +10007649 unset -nocomplain diffmergeid
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007650 if {![info exists treefilelist($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07007651 if {![info exists treepending]} {
7652 if {$id eq $nullid} {
7653 set cmd [list | git ls-files]
7654 } elseif {$id eq $nullid2} {
7655 set cmd [list | git ls-files --stage -t]
7656 } else {
7657 set cmd [list | git ls-tree -r $id]
7658 }
7659 if {[catch {set gtf [open $cmd r]}]} {
7660 return
7661 }
7662 set treepending $id
7663 set treefilelist($id) {}
7664 set treeidlist($id) {}
7665 fconfigure $gtf -blocking 0 -encoding binary
7666 filerun $gtf [list gettreeline $gtf $id]
7667 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007668 } else {
Denton Liue2445882020-09-10 21:36:33 -07007669 setfilelist $id
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007670 }
7671}
7672
7673proc gettreeline {gtf id} {
Paul Mackerras8f489362007-07-13 19:49:37 +10007674 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007675
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007676 set nl 0
7677 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007678 if {$diffids eq $nullid} {
7679 set fname $line
7680 } else {
7681 set i [string first "\t" $line]
7682 if {$i < 0} continue
7683 set fname [string range $line [expr {$i+1}] end]
7684 set line [string range $line 0 [expr {$i-1}]]
7685 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue
7686 set sha1 [lindex $line 2]
7687 lappend treeidlist($id) $sha1
7688 }
7689 if {[string index $fname 0] eq "\""} {
7690 set fname [lindex $fname 0]
7691 }
7692 set fname [encoding convertfrom $fname]
7693 lappend treefilelist($id) $fname
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007694 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007695 if {![eof $gtf]} {
Denton Liue2445882020-09-10 21:36:33 -07007696 return [expr {$nl >= 1000? 2: 1}]
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007697 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007698 close $gtf
7699 unset treepending
7700 if {$cmitmode ne "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07007701 if {![info exists diffmergeid]} {
7702 gettreediffs $diffids
7703 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007704 } elseif {$id ne $diffids} {
Denton Liue2445882020-09-10 21:36:33 -07007705 gettree $diffids
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007706 } else {
Denton Liue2445882020-09-10 21:36:33 -07007707 setfilelist $id
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007708 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007709 return 0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007710}
7711
7712proc showfile {f} {
Paul Mackerras8f489362007-07-13 19:49:37 +10007713 global treefilelist treeidlist diffids nullid nullid2
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04007714 global ctext_file_names ctext_file_lines
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007715 global ctext commentend
7716
7717 set i [lsearch -exact $treefilelist($diffids) $f]
7718 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -07007719 puts "oops, $f not in list for id $diffids"
7720 return
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007721 }
Paul Mackerras8f489362007-07-13 19:49:37 +10007722 if {$diffids eq $nullid} {
Denton Liue2445882020-09-10 21:36:33 -07007723 if {[catch {set bf [open $f r]} err]} {
7724 puts "oops, can't read $f: $err"
7725 return
7726 }
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007727 } else {
Denton Liue2445882020-09-10 21:36:33 -07007728 set blob [lindex $treeidlist($diffids) $i]
7729 if {[catch {set bf [open [concat | git cat-file blob $blob] r]} err]} {
7730 puts "oops, error reading blob $blob: $err"
7731 return
7732 }
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007733 }
Alexander Gavrilov09c70292008-10-13 12:12:31 +04007734 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f]
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007735 filerun $bf [list getblobline $bf $diffids]
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007736 $ctext config -state normal
Paul Mackerras3ea06f92006-05-24 10:16:03 +10007737 clear_ctext $commentend
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04007738 lappend ctext_file_names $f
7739 lappend ctext_file_lines [lindex [split $commentend "."] 0]
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007740 $ctext insert end "\n"
7741 $ctext insert end "$f\n" filesep
7742 $ctext config -state disabled
7743 $ctext yview $commentend
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10007744 settabs 0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007745}
7746
7747proc getblobline {bf id} {
7748 global diffids cmitmode ctext
7749
7750 if {$id ne $diffids || $cmitmode ne "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07007751 catch {close $bf}
7752 return 0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007753 }
7754 $ctext config -state normal
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007755 set nl 0
7756 while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007757 $ctext insert end "$line\n"
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007758 }
7759 if {[eof $bf]} {
Denton Liue2445882020-09-10 21:36:33 -07007760 global jump_to_here ctext_file_names commentend
Paul Mackerras8a897742008-10-27 21:36:25 +11007761
Denton Liue2445882020-09-10 21:36:33 -07007762 # delete last newline
7763 $ctext delete "end - 2c" "end - 1c"
7764 close $bf
7765 if {$jump_to_here ne {} &&
7766 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} {
7767 set lnum [expr {[lindex $jump_to_here 1] +
7768 [lindex [split $commentend .] 0]}]
7769 mark_ctext_line $lnum
7770 }
7771 $ctext config -state disabled
7772 return 0
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007773 }
7774 $ctext config -state disabled
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007775 return [expr {$nl >= 1000? 2: 1}]
Paul Mackerrasf8b28a42006-05-01 09:50:57 +10007776}
7777
Paul Mackerras8a897742008-10-27 21:36:25 +11007778proc mark_ctext_line {lnum} {
Paul Mackerrase3e901b2008-10-27 22:37:21 +11007779 global ctext markbgcolor
Paul Mackerras8a897742008-10-27 21:36:25 +11007780
7781 $ctext tag delete omark
7782 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line"
Paul Mackerrase3e901b2008-10-27 22:37:21 +11007783 $ctext tag conf omark -background $markbgcolor
Paul Mackerras8a897742008-10-27 21:36:25 +11007784 $ctext see $lnum.0
7785}
7786
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11007787proc mergediff {id} {
Paul Mackerras8b07dca2008-11-02 22:34:47 +11007788 global diffmergeid
Alexander Gavrilov2df64422008-10-08 11:05:37 +04007789 global diffids treediffs
Paul Mackerras8b07dca2008-11-02 22:34:47 +11007790 global parents curview
Paul Mackerrase2ed4322005-07-17 03:39:44 -04007791
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007792 set diffmergeid $id
Paul Mackerras7a1d9d12006-03-22 10:21:45 +11007793 set diffids $id
Alexander Gavrilov2df64422008-10-08 11:05:37 +04007794 set treediffs($id) {}
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11007795 set np [llength $parents($curview,$id)]
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10007796 settabs $np
Paul Mackerras8b07dca2008-11-02 22:34:47 +11007797 getblobdiffs $id
Paul Mackerrasc8a4acb2005-07-29 09:23:03 -05007798}
7799
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007800proc startdiff {ids} {
Paul Mackerras8f489362007-07-13 19:49:37 +10007801 global treediffs diffids treepending diffmergeid nullid nullid2
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007802
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10007803 settabs 1
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007804 set diffids $ids
Paul Mackerras009409f2015-05-02 20:53:36 +10007805 unset -nocomplain diffmergeid
Paul Mackerras8f489362007-07-13 19:49:37 +10007806 if {![info exists treediffs($ids)] ||
Denton Liue2445882020-09-10 21:36:33 -07007807 [lsearch -exact $ids $nullid] >= 0 ||
7808 [lsearch -exact $ids $nullid2] >= 0} {
7809 if {![info exists treepending]} {
7810 gettreediffs $ids
7811 }
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007812 } else {
Denton Liue2445882020-09-10 21:36:33 -07007813 addtocflist $ids
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007814 }
7815}
7816
Thomas Rast9403bd02013-11-16 18:37:43 +01007817proc showinlinediff {ids} {
7818 global commitinfo commitdata ctext
7819 global treediffs
7820
7821 set info $commitinfo($ids)
7822 set diff [lindex $info 7]
7823 set difflines [split $diff "\n"]
7824
7825 initblobdiffvars
7826 set treediff {}
7827
7828 set inhdr 0
7829 foreach line $difflines {
Denton Liue2445882020-09-10 21:36:33 -07007830 if {![string compare -length 5 "diff " $line]} {
7831 set inhdr 1
7832 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} {
7833 # offset also accounts for the b/ prefix
7834 lappend treediff [string range $line 6 end]
7835 set inhdr 0
7836 }
Thomas Rast9403bd02013-11-16 18:37:43 +01007837 }
7838
7839 set treediffs($ids) $treediff
7840 add_flist $treediff
7841
7842 $ctext conf -state normal
7843 foreach line $difflines {
Denton Liue2445882020-09-10 21:36:33 -07007844 parseblobdiffline $ids $line
Thomas Rast9403bd02013-11-16 18:37:43 +01007845 }
7846 maybe_scroll_ctext 1
7847 $ctext conf -state disabled
7848}
7849
Pat Thoyts65bb0bd2011-12-13 16:50:50 +00007850# If the filename (name) is under any of the passed filter paths
7851# then return true to include the file in the listing.
Paul Mackerras7a39a172007-10-23 10:15:11 +10007852proc path_filter {filter name} {
Pat Thoyts65bb0bd2011-12-13 16:50:50 +00007853 set worktree [gitworktree]
Paul Mackerras7a39a172007-10-23 10:15:11 +10007854 foreach p $filter {
Denton Liue2445882020-09-10 21:36:33 -07007855 set fq_p [file normalize $p]
7856 set fq_n [file normalize [file join $worktree $name]]
7857 if {[string match [file normalize $fq_p]* $fq_n]} {
7858 return 1
7859 }
Paul Mackerras7a39a172007-10-23 10:15:11 +10007860 }
7861 return 0
7862}
7863
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007864proc addtocflist {ids} {
Paul Mackerras74a40c72007-10-24 10:16:56 +10007865 global treediffs
Paul Mackerras7a39a172007-10-23 10:15:11 +10007866
Paul Mackerras74a40c72007-10-24 10:16:56 +10007867 add_flist $treediffs($ids)
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007868 getblobdiffs $ids
Paul Mackerrasd2610d12005-05-11 00:45:38 +00007869}
7870
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007871proc diffcmd {ids flags} {
Jens Lehmann17f98362014-04-08 21:36:08 +02007872 global log_showroot nullid nullid2 git_version
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007873
7874 set i [lsearch -exact $ids $nullid]
Paul Mackerras8f489362007-07-13 19:49:37 +10007875 set j [lsearch -exact $ids $nullid2]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007876 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007877 if {[llength $ids] > 1 && $j < 0} {
7878 # comparing working directory with some specific revision
7879 set cmd [concat | git diff-index $flags]
7880 if {$i == 0} {
7881 lappend cmd -R [lindex $ids 1]
7882 } else {
7883 lappend cmd [lindex $ids 0]
7884 }
7885 } else {
7886 # comparing working directory with index
7887 set cmd [concat | git diff-files $flags]
7888 if {$j == 1} {
7889 lappend cmd -R
7890 }
7891 }
Paul Mackerras8f489362007-07-13 19:49:37 +10007892 } elseif {$j >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007893 if {[package vcompare $git_version "1.7.2"] >= 0} {
7894 set flags "$flags --ignore-submodules=dirty"
7895 }
7896 set cmd [concat | git diff-index --cached $flags]
7897 if {[llength $ids] > 1} {
7898 # comparing index with specific revision
7899 if {$j == 0} {
7900 lappend cmd -R [lindex $ids 1]
7901 } else {
7902 lappend cmd [lindex $ids 0]
7903 }
7904 } else {
7905 # comparing index with HEAD
7906 lappend cmd HEAD
7907 }
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007908 } else {
Denton Liue2445882020-09-10 21:36:33 -07007909 if {$log_showroot} {
7910 lappend flags --root
7911 }
7912 set cmd [concat | git diff-tree -r $flags $ids]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007913 }
7914 return $cmd
7915}
7916
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007917proc gettreediffs {ids} {
Felipe Contreras2c8cd902013-04-27 17:01:39 -05007918 global treediff treepending limitdiffs vfilelimit curview
Paul Mackerras219ea3a2006-09-07 10:21:39 +10007919
Felipe Contreras2c8cd902013-04-27 17:01:39 -05007920 set cmd [diffcmd $ids {--no-commit-id}]
7921 if {$limitdiffs && $vfilelimit($curview) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07007922 set cmd [concat $cmd -- $vfilelimit($curview)]
Felipe Contreras2c8cd902013-04-27 17:01:39 -05007923 }
7924 if {[catch {set gdtf [open $cmd r]}]} return
Alexander Gavrilov72721312008-07-26 18:48:41 +04007925
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007926 set treepending $ids
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007927 set treediff {}
Alexander Gavrilov09c70292008-10-13 12:12:31 +04007928 fconfigure $gdtf -blocking 0 -encoding binary
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007929 filerun $gdtf [list gettreediffline $gdtf $ids]
Paul Mackerrasd2610d12005-05-11 00:45:38 +00007930}
7931
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10007932proc gettreediffline {gdtf ids} {
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007933 global treediff treediffs treepending diffids diffmergeid
Paul Mackerras39ee47e2008-10-15 22:23:03 +11007934 global cmitmode vfilelimit curview limitdiffs perfile_attrs
Paul Mackerras3c461ff2005-07-20 09:13:46 -04007935
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007936 set nr 0
Alexander Gavrilov4db09302008-10-13 12:12:33 +04007937 set sublist {}
Paul Mackerras39ee47e2008-10-15 22:23:03 +11007938 set max 1000
7939 if {$perfile_attrs} {
Denton Liue2445882020-09-10 21:36:33 -07007940 # cache_gitattr is slow, and even slower on win32 where we
7941 # have to invoke it for only about 30 paths at a time
7942 set max 500
7943 if {[tk windowingsystem] == "win32"} {
7944 set max 120
7945 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +11007946 }
7947 while {[incr nr] <= $max && [gets $gdtf line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07007948 set i [string first "\t" $line]
7949 if {$i >= 0} {
7950 set file [string range $line [expr {$i+1}] end]
7951 if {[string index $file 0] eq "\""} {
7952 set file [lindex $file 0]
7953 }
7954 set file [encoding convertfrom $file]
7955 if {$file ne [lindex $treediff end]} {
7956 lappend treediff $file
7957 lappend sublist $file
7958 }
7959 }
Paul Mackerrasd2610d12005-05-11 00:45:38 +00007960 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +11007961 if {$perfile_attrs} {
Denton Liue2445882020-09-10 21:36:33 -07007962 cache_gitattr encoding $sublist
Paul Mackerras39ee47e2008-10-15 22:23:03 +11007963 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007964 if {![eof $gdtf]} {
Denton Liue2445882020-09-10 21:36:33 -07007965 return [expr {$nr >= $max? 2: 1}]
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007966 }
7967 close $gdtf
Felipe Contreras2c8cd902013-04-27 17:01:39 -05007968 set treediffs($ids) $treediff
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007969 unset treepending
Paul Mackerrase1160132008-11-18 21:40:32 +11007970 if {$cmitmode eq "tree" && [llength $diffids] == 1} {
Denton Liue2445882020-09-10 21:36:33 -07007971 gettree $diffids
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007972 } elseif {$ids != $diffids} {
Denton Liue2445882020-09-10 21:36:33 -07007973 if {![info exists diffmergeid]} {
7974 gettreediffs $diffids
7975 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007976 } else {
Denton Liue2445882020-09-10 21:36:33 -07007977 addtocflist $ids
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10007978 }
7979 return 0
Paul Mackerrasd2610d12005-05-11 00:45:38 +00007980}
7981
Steffen Prohaska890fae72007-08-12 12:05:46 +02007982# empty string or positive integer
7983proc diffcontextvalidate {v} {
7984 return [regexp {^(|[1-9][0-9]*)$} $v]
7985}
7986
7987proc diffcontextchange {n1 n2 op} {
7988 global diffcontextstring diffcontext
7989
7990 if {[string is integer -strict $diffcontextstring]} {
Denton Liue2445882020-09-10 21:36:33 -07007991 if {$diffcontextstring >= 0} {
7992 set diffcontext $diffcontextstring
7993 reselectline
7994 }
Steffen Prohaska890fae72007-08-12 12:05:46 +02007995 }
7996}
7997
Steffen Prohaskab9b86002008-01-17 23:42:55 +01007998proc changeignorespace {} {
7999 reselectline
8000}
8001
Thomas Rastae4e3ff2010-10-16 12:15:10 +02008002proc changeworddiff {name ix op} {
8003 reselectline
8004}
8005
Thomas Rast5de460a2013-11-16 18:37:41 +01008006proc initblobdiffvars {} {
8007 global diffencoding targetline diffnparents
8008 global diffinhdr currdiffsubmod diffseehere
8009 set targetline {}
8010 set diffnparents 0
8011 set diffinhdr 0
8012 set diffencoding [get_path_encoding {}]
8013 set currdiffsubmod ""
8014 set diffseehere -1
8015}
8016
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008017proc getblobdiffs {ids} {
Paul Mackerras8d73b242007-10-06 20:22:00 +10008018 global blobdifffd diffids env
Thomas Rast5de460a2013-11-16 18:37:41 +01008019 global treediffs
Steffen Prohaska890fae72007-08-12 12:05:46 +02008020 global diffcontext
Steffen Prohaskab9b86002008-01-17 23:42:55 +01008021 global ignorespace
Thomas Rastae4e3ff2010-10-16 12:15:10 +02008022 global worddiff
Paul Mackerras3ed31a82008-04-26 16:00:00 +10008023 global limitdiffs vfilelimit curview
Thomas Rast5de460a2013-11-16 18:37:41 +01008024 global git_version
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008025
Paul Mackerrasa8138732009-05-16 21:06:01 +10008026 set textconv {}
8027 if {[package vcompare $git_version "1.6.1"] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07008028 set textconv "--textconv"
Paul Mackerrasa8138732009-05-16 21:06:01 +10008029 }
Jens Lehmann5c838d22009-10-28 12:40:45 +01008030 set submodule {}
8031 if {[package vcompare $git_version "1.6.6"] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07008032 set submodule "--submodule"
Jens Lehmann5c838d22009-10-28 12:40:45 +01008033 }
8034 set cmd [diffcmd $ids "-p $textconv $submodule -C --cc --no-commit-id -U$diffcontext"]
Steffen Prohaskab9b86002008-01-17 23:42:55 +01008035 if {$ignorespace} {
Denton Liue2445882020-09-10 21:36:33 -07008036 append cmd " -w"
Steffen Prohaskab9b86002008-01-17 23:42:55 +01008037 }
Thomas Rastae4e3ff2010-10-16 12:15:10 +02008038 if {$worddiff ne [mc "Line diff"]} {
Denton Liue2445882020-09-10 21:36:33 -07008039 append cmd " --word-diff=porcelain"
Thomas Rastae4e3ff2010-10-16 12:15:10 +02008040 }
Paul Mackerras3ed31a82008-04-26 16:00:00 +10008041 if {$limitdiffs && $vfilelimit($curview) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008042 set cmd [concat $cmd -- $vfilelimit($curview)]
Paul Mackerras7a39a172007-10-23 10:15:11 +10008043 }
8044 if {[catch {set bdf [open $cmd r]} err]} {
Denton Liue2445882020-09-10 21:36:33 -07008045 error_popup [mc "Error getting diffs: %s" $err]
8046 return
Paul Mackerrase5c2d852005-05-11 23:44:54 +00008047 }
Pat Thoyts681c3292009-03-16 10:24:40 +00008048 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008049 set blobdifffd($ids) $bdf
Thomas Rast5de460a2013-11-16 18:37:41 +01008050 initblobdiffvars
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10008051 filerun $bdf [list getblobdiffline $bdf $diffids]
Paul Mackerrase5c2d852005-05-11 23:44:54 +00008052}
8053
Paul Mackerras354af6b2008-11-23 13:14:23 +11008054proc savecmitpos {} {
8055 global ctext cmitmode
8056
8057 if {$cmitmode eq "tree"} {
Denton Liue2445882020-09-10 21:36:33 -07008058 return {}
Paul Mackerras354af6b2008-11-23 13:14:23 +11008059 }
8060 return [list target_scrollpos [$ctext index @0,0]]
8061}
8062
8063proc savectextpos {} {
8064 global ctext
8065
8066 return [list target_scrollpos [$ctext index @0,0]]
8067}
8068
8069proc maybe_scroll_ctext {ateof} {
8070 global ctext target_scrollpos
8071
8072 if {![info exists target_scrollpos]} return
8073 if {!$ateof} {
Denton Liue2445882020-09-10 21:36:33 -07008074 set nlines [expr {[winfo height $ctext]
8075 / [font metrics textfont -linespace]}]
8076 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return
Paul Mackerras354af6b2008-11-23 13:14:23 +11008077 }
8078 $ctext yview $target_scrollpos
8079 unset target_scrollpos
8080}
8081
Paul Mackerras89b11d32006-05-02 19:55:31 +10008082proc setinlist {var i val} {
8083 global $var
8084
8085 while {[llength [set $var]] < $i} {
Denton Liue2445882020-09-10 21:36:33 -07008086 lappend $var {}
Paul Mackerras89b11d32006-05-02 19:55:31 +10008087 }
8088 if {[llength [set $var]] == $i} {
Denton Liue2445882020-09-10 21:36:33 -07008089 lappend $var $val
Paul Mackerras89b11d32006-05-02 19:55:31 +10008090 } else {
Denton Liue2445882020-09-10 21:36:33 -07008091 lset $var $i $val
Paul Mackerras89b11d32006-05-02 19:55:31 +10008092 }
8093}
8094
Paul Mackerras9396cd32007-06-23 20:28:15 +10008095proc makediffhdr {fname ids} {
Paul Mackerras8b07dca2008-11-02 22:34:47 +11008096 global ctext curdiffstart treediffs diffencoding
Paul Mackerras8a897742008-10-27 21:36:25 +11008097 global ctext_file_names jump_to_here targetline diffline
Paul Mackerras9396cd32007-06-23 20:28:15 +10008098
Paul Mackerras8b07dca2008-11-02 22:34:47 +11008099 set fname [encoding convertfrom $fname]
8100 set diffencoding [get_path_encoding $fname]
Paul Mackerras9396cd32007-06-23 20:28:15 +10008101 set i [lsearch -exact $treediffs($ids) $fname]
8102 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07008103 setinlist difffilestart $i $curdiffstart
Paul Mackerras9396cd32007-06-23 20:28:15 +10008104 }
Paul Mackerras48a81b72008-11-04 21:09:00 +11008105 lset ctext_file_names end $fname
Paul Mackerras9396cd32007-06-23 20:28:15 +10008106 set l [expr {(78 - [string length $fname]) / 2}]
8107 set pad [string range "----------------------------------------" 1 $l]
8108 $ctext insert $curdiffstart "$pad $fname $pad" filesep
Paul Mackerras8a897742008-10-27 21:36:25 +11008109 set targetline {}
8110 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} {
Denton Liue2445882020-09-10 21:36:33 -07008111 set targetline [lindex $jump_to_here 1]
Paul Mackerras8a897742008-10-27 21:36:25 +11008112 }
8113 set diffline 0
Paul Mackerras9396cd32007-06-23 20:28:15 +10008114}
8115
Thomas Rast5de460a2013-11-16 18:37:41 +01008116proc blobdiffmaybeseehere {ateof} {
8117 global diffseehere
8118 if {$diffseehere >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07008119 mark_ctext_line [lindex [split $diffseehere .] 0]
Thomas Rast5de460a2013-11-16 18:37:41 +01008120 }
Max Kirillov1f3c8722014-01-18 14:58:51 +02008121 maybe_scroll_ctext $ateof
Thomas Rast5de460a2013-11-16 18:37:41 +01008122}
8123
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008124proc getblobdiffline {bdf ids} {
Thomas Rast5de460a2013-11-16 18:37:41 +01008125 global diffids blobdifffd
8126 global ctext
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008127
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10008128 set nr 0
Paul Mackerrase5c2d852005-05-11 23:44:54 +00008129 $ctext conf -state normal
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10008130 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07008131 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
8132 # Older diff read. Abort it.
8133 catch {close $bdf}
8134 if {$ids != $diffids} {
8135 array unset blobdifffd $ids
8136 }
8137 return 0
8138 }
8139 parseblobdiffline $ids $line
Paul Mackerrase5c2d852005-05-11 23:44:54 +00008140 }
8141 $ctext conf -state disabled
Thomas Rast5de460a2013-11-16 18:37:41 +01008142 blobdiffmaybeseehere [eof $bdf]
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10008143 if {[eof $bdf]} {
Denton Liue2445882020-09-10 21:36:33 -07008144 catch {close $bdf}
8145 array unset blobdifffd $ids
8146 return 0
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008147 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +10008148 return [expr {$nr >= 1000? 2: 1}]
Paul Mackerrase5c2d852005-05-11 23:44:54 +00008149}
8150
Thomas Rast5de460a2013-11-16 18:37:41 +01008151proc parseblobdiffline {ids line} {
8152 global ctext curdiffstart
8153 global diffnexthead diffnextnote difffilestart
8154 global ctext_file_names ctext_file_lines
8155 global diffinhdr treediffs mergemax diffnparents
8156 global diffencoding jump_to_here targetline diffline currdiffsubmod
8157 global worddiff diffseehere
8158
8159 if {![string compare -length 5 "diff " $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008160 if {![regexp {^diff (--cc|--git) } $line m type]} {
8161 set line [encoding convertfrom $line]
8162 $ctext insert end "$line\n" hunksep
8163 continue
8164 }
8165 # start of a new file
8166 set diffinhdr 1
8167 set currdiffsubmod ""
Роман Донченкоf177c492019-11-02 02:34:27 +03008168
Denton Liue2445882020-09-10 21:36:33 -07008169 $ctext insert end "\n"
8170 set curdiffstart [$ctext index "end - 1c"]
8171 lappend ctext_file_names ""
8172 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8173 $ctext insert end "\n" filesep
Thomas Rast5de460a2013-11-16 18:37:41 +01008174
Denton Liue2445882020-09-10 21:36:33 -07008175 if {$type eq "--cc"} {
8176 # start of a new file in a merge diff
8177 set fname [string range $line 10 end]
8178 if {[lsearch -exact $treediffs($ids) $fname] < 0} {
8179 lappend treediffs($ids) $fname
8180 add_flist [list $fname]
8181 }
Thomas Rast5de460a2013-11-16 18:37:41 +01008182
Denton Liue2445882020-09-10 21:36:33 -07008183 } else {
8184 set line [string range $line 11 end]
8185 # If the name hasn't changed the length will be odd,
8186 # the middle char will be a space, and the two bits either
8187 # side will be a/name and b/name, or "a/name" and "b/name".
8188 # If the name has changed we'll get "rename from" and
8189 # "rename to" or "copy from" and "copy to" lines following
8190 # this, and we'll use them to get the filenames.
8191 # This complexity is necessary because spaces in the
8192 # filename(s) don't get escaped.
8193 set l [string length $line]
8194 set i [expr {$l / 2}]
8195 if {!(($l & 1) && [string index $line $i] eq " " &&
8196 [string range $line 2 [expr {$i - 1}]] eq \
8197 [string range $line [expr {$i + 3}] end])} {
8198 return
8199 }
8200 # unescape if quoted and chop off the a/ from the front
8201 if {[string index $line 0] eq "\""} {
8202 set fname [string range [lindex $line 0] 2 end]
8203 } else {
8204 set fname [string range $line 2 [expr {$i - 1}]]
8205 }
8206 }
8207 makediffhdr $fname $ids
Thomas Rast5de460a2013-11-16 18:37:41 +01008208
8209 } elseif {![string compare -length 16 "* Unmerged path " $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008210 set fname [encoding convertfrom [string range $line 16 end]]
8211 $ctext insert end "\n"
8212 set curdiffstart [$ctext index "end - 1c"]
8213 lappend ctext_file_names $fname
8214 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8215 $ctext insert end "$line\n" filesep
8216 set i [lsearch -exact $treediffs($ids) $fname]
8217 if {$i >= 0} {
8218 setinlist difffilestart $i $curdiffstart
8219 }
Thomas Rast5de460a2013-11-16 18:37:41 +01008220
8221 } elseif {![string compare -length 2 "@@" $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008222 regexp {^@@+} $line ats
8223 set line [encoding convertfrom $diffencoding $line]
8224 $ctext insert end "$line\n" hunksep
8225 if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
8226 set diffline $nl
8227 }
8228 set diffnparents [expr {[string length $ats] - 1}]
8229 set diffinhdr 0
Thomas Rast5de460a2013-11-16 18:37:41 +01008230
8231 } elseif {![string compare -length 10 "Submodule " $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008232 # start of a new submodule
8233 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
8234 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
8235 } else {
8236 set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
8237 }
8238 if {$currdiffsubmod != $fname} {
8239 $ctext insert end "\n"; # Add newline after commit message
8240 }
8241 if {$currdiffsubmod != $fname} {
8242 set curdiffstart [$ctext index "end - 1c"]
8243 lappend ctext_file_names ""
8244 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0]
8245 makediffhdr $fname $ids
8246 set currdiffsubmod $fname
8247 $ctext insert end "\n$line\n" filesep
8248 } else {
8249 $ctext insert end "$line\n" filesep
8250 }
Gabriele Mazzotta9ea831a2019-03-23 18:00:36 +01008251 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008252 set line [encoding convertfrom $diffencoding $line]
8253 $ctext insert end "$line\n" dresult
Gabriele Mazzotta9ea831a2019-03-23 18:00:36 +01008254 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
Denton Liue2445882020-09-10 21:36:33 -07008255 set line [encoding convertfrom $diffencoding $line]
8256 $ctext insert end "$line\n" d0
Thomas Rast5de460a2013-11-16 18:37:41 +01008257 } elseif {$diffinhdr} {
Denton Liue2445882020-09-10 21:36:33 -07008258 if {![string compare -length 12 "rename from " $line]} {
8259 set fname [string range $line [expr 6 + [string first " from " $line] ] end]
8260 if {[string index $fname 0] eq "\""} {
8261 set fname [lindex $fname 0]
8262 }
8263 set fname [encoding convertfrom $fname]
8264 set i [lsearch -exact $treediffs($ids) $fname]
8265 if {$i >= 0} {
8266 setinlist difffilestart $i $curdiffstart
8267 }
8268 } elseif {![string compare -length 10 $line "rename to "] ||
8269 ![string compare -length 8 $line "copy to "]} {
8270 set fname [string range $line [expr 4 + [string first " to " $line] ] end]
8271 if {[string index $fname 0] eq "\""} {
8272 set fname [lindex $fname 0]
8273 }
8274 makediffhdr $fname $ids
8275 } elseif {[string compare -length 3 $line "---"] == 0} {
8276 # do nothing
8277 return
8278 } elseif {[string compare -length 3 $line "+++"] == 0} {
8279 set diffinhdr 0
8280 return
8281 }
8282 $ctext insert end "$line\n" filesep
Thomas Rast5de460a2013-11-16 18:37:41 +01008283
8284 } else {
Denton Liue2445882020-09-10 21:36:33 -07008285 set line [string map {\x1A ^Z} \
8286 [encoding convertfrom $diffencoding $line]]
8287 # parse the prefix - one ' ', '-' or '+' for each parent
8288 set prefix [string range $line 0 [expr {$diffnparents - 1}]]
8289 set tag [expr {$diffnparents > 1? "m": "d"}]
8290 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}]
8291 set words_pre_markup ""
8292 set words_post_markup ""
8293 if {[string trim $prefix " -+"] eq {}} {
8294 # prefix only has " ", "-" and "+" in it: normal diff line
8295 set num [string first "-" $prefix]
8296 if {$dowords} {
8297 set line [string range $line 1 end]
8298 }
8299 if {$num >= 0} {
8300 # removed line, first parent with line is $num
8301 if {$num >= $mergemax} {
8302 set num "max"
8303 }
8304 if {$dowords && $worddiff eq [mc "Markup words"]} {
8305 $ctext insert end "\[-$line-\]" $tag$num
8306 } else {
8307 $ctext insert end "$line" $tag$num
8308 }
8309 if {!$dowords} {
8310 $ctext insert end "\n" $tag$num
8311 }
8312 } else {
8313 set tags {}
8314 if {[string first "+" $prefix] >= 0} {
8315 # added line
8316 lappend tags ${tag}result
8317 if {$diffnparents > 1} {
8318 set num [string first " " $prefix]
8319 if {$num >= 0} {
8320 if {$num >= $mergemax} {
8321 set num "max"
8322 }
8323 lappend tags m$num
8324 }
8325 }
8326 set words_pre_markup "{+"
8327 set words_post_markup "+}"
8328 }
8329 if {$targetline ne {}} {
8330 if {$diffline == $targetline} {
8331 set diffseehere [$ctext index "end - 1 chars"]
8332 set targetline {}
8333 } else {
8334 incr diffline
8335 }
8336 }
8337 if {$dowords && $worddiff eq [mc "Markup words"]} {
8338 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags
8339 } else {
8340 $ctext insert end "$line" $tags
8341 }
8342 if {!$dowords} {
8343 $ctext insert end "\n" $tags
8344 }
8345 }
8346 } elseif {$dowords && $prefix eq "~"} {
8347 $ctext insert end "\n" {}
8348 } else {
8349 # "\ No newline at end of file",
8350 # or something else we don't recognize
8351 $ctext insert end "$line\n" hunksep
8352 }
Thomas Rast5de460a2013-11-16 18:37:41 +01008353 }
8354}
8355
Paul Mackerrasa8d610a2007-04-19 11:39:12 +10008356proc changediffdisp {} {
8357 global ctext diffelide
8358
8359 $ctext tag conf d0 -elide [lindex $diffelide 0]
Paul Mackerras8b07dca2008-11-02 22:34:47 +11008360 $ctext tag conf dresult -elide [lindex $diffelide 1]
Paul Mackerrasa8d610a2007-04-19 11:39:12 +10008361}
8362
Stefan Hallerb9671352012-09-19 20:17:27 +02008363proc highlightfile {cline} {
8364 global cflist cflist_top
Paul Mackerrasf4c54b32008-05-10 13:15:36 +10008365
Stefan Hallerce837c92012-10-04 22:50:16 +02008366 if {![info exists cflist_top]} return
8367
Paul Mackerrasf4c54b32008-05-10 13:15:36 +10008368 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend"
8369 $cflist tag add highlight $cline.0 "$cline.0 lineend"
8370 $cflist see $cline.0
8371 set cflist_top $cline
8372}
8373
Stefan Hallerb9671352012-09-19 20:17:27 +02008374proc highlightfile_for_scrollpos {topidx} {
Stefan Haller978904b2012-10-04 22:50:17 +02008375 global cmitmode difffilestart
Stefan Hallerb9671352012-09-19 20:17:27 +02008376
Stefan Haller978904b2012-10-04 22:50:17 +02008377 if {$cmitmode eq "tree"} return
Stefan Hallerb9671352012-09-19 20:17:27 +02008378 if {![info exists difffilestart]} return
8379
8380 set top [lindex [split $topidx .] 0]
8381 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} {
Denton Liue2445882020-09-10 21:36:33 -07008382 highlightfile 0
Stefan Hallerb9671352012-09-19 20:17:27 +02008383 } else {
Denton Liue2445882020-09-10 21:36:33 -07008384 highlightfile [expr {[bsearch $difffilestart $top] + 2}]
Stefan Hallerb9671352012-09-19 20:17:27 +02008385 }
8386}
8387
OGAWA Hirofumi67c22872006-09-27 12:32:19 +09008388proc prevfile {} {
Paul Mackerrasf4c54b32008-05-10 13:15:36 +10008389 global difffilestart ctext cmitmode
8390
8391 if {$cmitmode eq "tree"} return
8392 set prev 0.0
OGAWA Hirofumi67c22872006-09-27 12:32:19 +09008393 set here [$ctext index @0,0]
8394 foreach loc $difffilestart {
Denton Liue2445882020-09-10 21:36:33 -07008395 if {[$ctext compare $loc >= $here]} {
8396 $ctext yview $prev
8397 return
8398 }
8399 set prev $loc
OGAWA Hirofumi67c22872006-09-27 12:32:19 +09008400 }
Stefan Hallerb9671352012-09-19 20:17:27 +02008401 $ctext yview $prev
OGAWA Hirofumi67c22872006-09-27 12:32:19 +09008402}
8403
Paul Mackerras39ad8572005-05-19 12:35:53 +00008404proc nextfile {} {
Paul Mackerrasf4c54b32008-05-10 13:15:36 +10008405 global difffilestart ctext cmitmode
8406
8407 if {$cmitmode eq "tree"} return
Paul Mackerras39ad8572005-05-19 12:35:53 +00008408 set here [$ctext index @0,0]
Paul Mackerras7fcceed2006-04-27 19:21:49 +10008409 foreach loc $difffilestart {
Denton Liue2445882020-09-10 21:36:33 -07008410 if {[$ctext compare $loc > $here]} {
8411 $ctext yview $loc
8412 return
8413 }
Paul Mackerras39ad8572005-05-19 12:35:53 +00008414 }
Paul Mackerras1db95b02005-05-09 04:08:39 +00008415}
8416
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008417proc clear_ctext {{first 1.0}} {
8418 global ctext smarktop smarkbot
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04008419 global ctext_file_names ctext_file_lines
Paul Mackerras97645682007-08-23 22:24:38 +10008420 global pendinglinks
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008421
Paul Mackerras1902c272006-05-25 21:25:13 +10008422 set l [lindex [split $first .] 0]
8423 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
Denton Liue2445882020-09-10 21:36:33 -07008424 set smarktop $l
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008425 }
Paul Mackerras1902c272006-05-25 21:25:13 +10008426 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
Denton Liue2445882020-09-10 21:36:33 -07008427 set smarkbot $l
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008428 }
8429 $ctext delete $first end
Paul Mackerras97645682007-08-23 22:24:38 +10008430 if {$first eq "1.0"} {
Denton Liue2445882020-09-10 21:36:33 -07008431 unset -nocomplain pendinglinks
Paul Mackerras97645682007-08-23 22:24:38 +10008432 }
Alexander Gavrilov7cdc3552008-10-24 12:13:01 +04008433 set ctext_file_names {}
8434 set ctext_file_lines {}
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008435}
8436
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008437proc settabs {{firstab {}}} {
Paul Mackerras9c311b32007-10-04 22:27:13 +10008438 global firsttabstop tabstop ctext have_tk85
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008439
8440 if {$firstab ne {} && $have_tk85} {
Denton Liue2445882020-09-10 21:36:33 -07008441 set firsttabstop $firstab
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008442 }
Paul Mackerras9c311b32007-10-04 22:27:13 +10008443 set w [font measure textfont "0"]
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008444 if {$firsttabstop != 0} {
Denton Liue2445882020-09-10 21:36:33 -07008445 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \
8446 [expr {($firsttabstop + 2 * $tabstop) * $w}]]
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008447 } elseif {$have_tk85 || $tabstop != 8} {
Denton Liue2445882020-09-10 21:36:33 -07008448 $ctext conf -tabs [expr {$tabstop * $w}]
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008449 } else {
Denton Liue2445882020-09-10 21:36:33 -07008450 $ctext conf -tabs {}
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008451 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008452}
8453
8454proc incrsearch {name ix op} {
Paul Mackerras1902c272006-05-25 21:25:13 +10008455 global ctext searchstring searchdirn
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008456
Paul Mackerras1902c272006-05-25 21:25:13 +10008457 if {[catch {$ctext index anchor}]} {
Denton Liue2445882020-09-10 21:36:33 -07008458 # no anchor set, use start of selection, or of visible area
8459 set sel [$ctext tag ranges sel]
8460 if {$sel ne {}} {
8461 $ctext mark set anchor [lindex $sel 0]
8462 } elseif {$searchdirn eq "-forwards"} {
8463 $ctext mark set anchor @0,0
8464 } else {
8465 $ctext mark set anchor @0,[winfo height $ctext]
8466 }
Paul Mackerras1902c272006-05-25 21:25:13 +10008467 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008468 if {$searchstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008469 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor]
8470 if {$here ne {}} {
8471 $ctext see $here
8472 set mend "$here + $mlen c"
8473 $ctext tag remove sel 1.0 end
8474 $ctext tag add sel $here $mend
8475 suppress_highlighting_file_for_current_scrollpos
8476 highlightfile_for_scrollpos $here
8477 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008478 }
Stefan Hallerc4614992012-09-22 09:40:24 +02008479 rehighlight_search_results
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008480}
8481
8482proc dosearch {} {
Paul Mackerras1902c272006-05-25 21:25:13 +10008483 global sstring ctext searchstring searchdirn
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008484
8485 focus $sstring
8486 $sstring icursor end
Paul Mackerras1902c272006-05-25 21:25:13 +10008487 set searchdirn -forwards
8488 if {$searchstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008489 set sel [$ctext tag ranges sel]
8490 if {$sel ne {}} {
8491 set start "[lindex $sel 0] + 1c"
8492 } elseif {[catch {set start [$ctext index anchor]}]} {
8493 set start "@0,0"
8494 }
8495 set match [$ctext search -count mlen -- $searchstring $start]
8496 $ctext tag remove sel 1.0 end
8497 if {$match eq {}} {
8498 bell
8499 return
8500 }
8501 $ctext see $match
8502 suppress_highlighting_file_for_current_scrollpos
8503 highlightfile_for_scrollpos $match
8504 set mend "$match + $mlen c"
8505 $ctext tag add sel $match $mend
8506 $ctext mark unset anchor
8507 rehighlight_search_results
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008508 }
Paul Mackerras1902c272006-05-25 21:25:13 +10008509}
8510
8511proc dosearchback {} {
8512 global sstring ctext searchstring searchdirn
8513
8514 focus $sstring
8515 $sstring icursor end
8516 set searchdirn -backwards
8517 if {$searchstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008518 set sel [$ctext tag ranges sel]
8519 if {$sel ne {}} {
8520 set start [lindex $sel 0]
8521 } elseif {[catch {set start [$ctext index anchor]}]} {
8522 set start @0,[winfo height $ctext]
8523 }
8524 set match [$ctext search -backwards -count ml -- $searchstring $start]
8525 $ctext tag remove sel 1.0 end
8526 if {$match eq {}} {
8527 bell
8528 return
8529 }
8530 $ctext see $match
8531 suppress_highlighting_file_for_current_scrollpos
8532 highlightfile_for_scrollpos $match
8533 set mend "$match + $ml c"
8534 $ctext tag add sel $match $mend
8535 $ctext mark unset anchor
8536 rehighlight_search_results
Stefan Hallerc4614992012-09-22 09:40:24 +02008537 }
8538}
8539
8540proc rehighlight_search_results {} {
8541 global ctext searchstring
8542
8543 $ctext tag remove found 1.0 end
8544 $ctext tag remove currentsearchhit 1.0 end
8545
8546 if {$searchstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008547 searchmarkvisible 1
Paul Mackerras1902c272006-05-25 21:25:13 +10008548 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008549}
8550
8551proc searchmark {first last} {
8552 global ctext searchstring
8553
Stefan Hallerc4614992012-09-22 09:40:24 +02008554 set sel [$ctext tag ranges sel]
8555
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008556 set mend $first.0
8557 while {1} {
Denton Liue2445882020-09-10 21:36:33 -07008558 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8559 if {$match eq {}} break
8560 set mend "$match + $mlen c"
8561 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8562 $ctext tag add currentsearchhit $match $mend
8563 } else {
8564 $ctext tag add found $match $mend
8565 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008566 }
8567}
8568
8569proc searchmarkvisible {doall} {
8570 global ctext smarktop smarkbot
8571
8572 set topline [lindex [split [$ctext index @0,0] .] 0]
8573 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
8574 if {$doall || $botline < $smarktop || $topline > $smarkbot} {
Denton Liue2445882020-09-10 21:36:33 -07008575 # no overlap with previous
8576 searchmark $topline $botline
8577 set smarktop $topline
8578 set smarkbot $botline
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008579 } else {
Denton Liue2445882020-09-10 21:36:33 -07008580 if {$topline < $smarktop} {
8581 searchmark $topline [expr {$smarktop-1}]
8582 set smarktop $topline
8583 }
8584 if {$botline > $smarkbot} {
8585 searchmark [expr {$smarkbot+1}] $botline
8586 set smarkbot $botline
8587 }
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008588 }
8589}
8590
Stefan Hallerb9671352012-09-19 20:17:27 +02008591proc suppress_highlighting_file_for_current_scrollpos {} {
8592 global ctext suppress_highlighting_file_for_this_scrollpos
8593
8594 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0]
8595}
8596
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008597proc scrolltext {f0 f1} {
Stefan Hallerb9671352012-09-19 20:17:27 +02008598 global searchstring cmitmode ctext
8599 global suppress_highlighting_file_for_this_scrollpos
8600
Stefan Haller978904b2012-10-04 22:50:17 +02008601 set topidx [$ctext index @0,0]
8602 if {![info exists suppress_highlighting_file_for_this_scrollpos]
Denton Liue2445882020-09-10 21:36:33 -07008603 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} {
8604 highlightfile_for_scrollpos $topidx
Stefan Hallerb9671352012-09-19 20:17:27 +02008605 }
8606
Paul Mackerras009409f2015-05-02 20:53:36 +10008607 unset -nocomplain suppress_highlighting_file_for_this_scrollpos
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008608
Pekka Kaitaniemi8809d692008-03-08 14:27:23 +02008609 .bleft.bottom.sb set $f0 $f1
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008610 if {$searchstring ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008611 searchmarkvisible 0
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008612 }
8613}
8614
Paul Mackerras1d10f362005-05-15 12:55:47 +00008615proc setcoords {} {
Paul Mackerras9c311b32007-10-04 22:27:13 +10008616 global linespc charspc canvx0 canvy0
Paul Mackerrasf6075eb2005-08-18 09:30:10 +10008617 global xspc1 xspc2 lthickness
Paul Mackerras8d858d12005-08-05 09:52:16 +10008618
Paul Mackerras9c311b32007-10-04 22:27:13 +10008619 set linespc [font metrics mainfont -linespace]
8620 set charspc [font measure mainfont "m"]
Paul Mackerras9f1afe02006-02-19 22:44:47 +11008621 set canvy0 [expr {int(3 + 0.5 * $linespc)}]
8622 set canvx0 [expr {int(3 + 0.5 * $linespc)}]
Paul Mackerrasf6075eb2005-08-18 09:30:10 +10008623 set lthickness [expr {int($linespc / 9) + 1}]
Paul Mackerras8d858d12005-08-05 09:52:16 +10008624 set xspc1(0) $linespc
8625 set xspc2 $linespc
Paul Mackerras9a40c502005-05-12 23:46:16 +00008626}
Paul Mackerras1db95b02005-05-09 04:08:39 +00008627
Paul Mackerras1d10f362005-05-15 12:55:47 +00008628proc redisplay {} {
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11008629 global canv
Paul Mackerras9f1afe02006-02-19 22:44:47 +11008630 global selectedline
8631
8632 set ymax [lindex [$canv cget -scrollregion] 3]
8633 if {$ymax eq {} || $ymax == 0} return
8634 set span [$canv yview]
8635 clear_display
Paul Mackerrasbe0cd092006-03-31 09:55:11 +11008636 setcanvscroll
Paul Mackerras9f1afe02006-02-19 22:44:47 +11008637 allcanvs yview moveto [lindex $span 0]
8638 drawvisible
Paul Mackerras94b4a692008-05-20 20:51:06 +10008639 if {$selectedline ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008640 selectline $selectedline 0
8641 allcanvs yview moveto [lindex $span 0]
Paul Mackerras1db95b02005-05-09 04:08:39 +00008642 }
8643}
Paul Mackerras1d10f362005-05-15 12:55:47 +00008644
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008645proc parsefont {f n} {
8646 global fontattr
8647
8648 set fontattr($f,family) [lindex $n 0]
8649 set s [lindex $n 1]
8650 if {$s eq {} || $s == 0} {
Denton Liue2445882020-09-10 21:36:33 -07008651 set s 10
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008652 } elseif {$s < 0} {
Denton Liue2445882020-09-10 21:36:33 -07008653 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
Paul Mackerras9c311b32007-10-04 22:27:13 +10008654 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008655 set fontattr($f,size) $s
8656 set fontattr($f,weight) normal
8657 set fontattr($f,slant) roman
8658 foreach style [lrange $n 2 end] {
Denton Liue2445882020-09-10 21:36:33 -07008659 switch -- $style {
8660 "normal" -
8661 "bold" {set fontattr($f,weight) $style}
8662 "roman" -
8663 "italic" {set fontattr($f,slant) $style}
8664 }
Paul Mackerras9c311b32007-10-04 22:27:13 +10008665 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008666}
8667
8668proc fontflags {f {isbold 0}} {
8669 global fontattr
8670
8671 return [list -family $fontattr($f,family) -size $fontattr($f,size) \
Denton Liue2445882020-09-10 21:36:33 -07008672 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
8673 -slant $fontattr($f,slant)]
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008674}
8675
8676proc fontname {f} {
8677 global fontattr
8678
8679 set n [list $fontattr($f,family) $fontattr($f,size)]
8680 if {$fontattr($f,weight) eq "bold"} {
Denton Liue2445882020-09-10 21:36:33 -07008681 lappend n "bold"
Paul Mackerras9c311b32007-10-04 22:27:13 +10008682 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008683 if {$fontattr($f,slant) eq "italic"} {
Denton Liue2445882020-09-10 21:36:33 -07008684 lappend n "italic"
Paul Mackerras9c311b32007-10-04 22:27:13 +10008685 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008686 return $n
Paul Mackerras9c311b32007-10-04 22:27:13 +10008687}
8688
Paul Mackerras1d10f362005-05-15 12:55:47 +00008689proc incrfont {inc} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008690 global mainfont textfont ctext canv cflist showrefstop
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008691 global stopped entries fontattr
8692
Paul Mackerras1d10f362005-05-15 12:55:47 +00008693 unmarkmatches
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008694 set s $fontattr(mainfont,size)
Paul Mackerras9c311b32007-10-04 22:27:13 +10008695 incr s $inc
8696 if {$s < 1} {
Denton Liue2445882020-09-10 21:36:33 -07008697 set s 1
Paul Mackerras9c311b32007-10-04 22:27:13 +10008698 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008699 set fontattr(mainfont,size) $s
Paul Mackerras9c311b32007-10-04 22:27:13 +10008700 font config mainfont -size $s
8701 font config mainfontbold -size $s
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008702 set mainfont [fontname mainfont]
8703 set s $fontattr(textfont,size)
Paul Mackerras9c311b32007-10-04 22:27:13 +10008704 incr s $inc
8705 if {$s < 1} {
Denton Liue2445882020-09-10 21:36:33 -07008706 set s 1
Paul Mackerras9c311b32007-10-04 22:27:13 +10008707 }
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008708 set fontattr(textfont,size) $s
Paul Mackerras9c311b32007-10-04 22:27:13 +10008709 font config textfont -size $s
8710 font config textfontbold -size $s
Paul Mackerras0ed1dd32007-10-06 18:27:37 +10008711 set textfont [fontname textfont]
Paul Mackerras1d10f362005-05-15 12:55:47 +00008712 setcoords
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008713 settabs
Paul Mackerras1d10f362005-05-15 12:55:47 +00008714 redisplay
Paul Mackerras1db95b02005-05-09 04:08:39 +00008715}
Paul Mackerras1d10f362005-05-15 12:55:47 +00008716
Paul Mackerrasee3dc722005-06-25 16:37:13 +10008717proc clearsha1 {} {
8718 global sha1entry sha1string
8719 if {[string length $sha1string] == 40} {
Denton Liue2445882020-09-10 21:36:33 -07008720 $sha1entry delete 0 end
Paul Mackerrasee3dc722005-06-25 16:37:13 +10008721 }
8722}
8723
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008724proc sha1change {n1 n2 op} {
8725 global sha1string currentid sha1but
8726 if {$sha1string == {}
Denton Liue2445882020-09-10 21:36:33 -07008727 || ([info exists currentid] && $sha1string == $currentid)} {
8728 set state disabled
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008729 } else {
Denton Liue2445882020-09-10 21:36:33 -07008730 set state normal
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008731 }
8732 if {[$sha1but cget -state] == $state} return
8733 if {$state == "normal"} {
Denton Liue2445882020-09-10 21:36:33 -07008734 $sha1but conf -state normal -relief raised -text "[mc "Goto:"] "
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008735 } else {
Denton Liue2445882020-09-10 21:36:33 -07008736 $sha1but conf -state disabled -relief flat -text "[mc "SHA1 ID:"] "
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008737 }
8738}
8739
8740proc gotocommit {} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008741 global sha1string tagids headids curview varcid
Paul Mackerrasf3b8b3c2005-07-18 12:16:35 -04008742
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008743 if {$sha1string == {}
Denton Liue2445882020-09-10 21:36:33 -07008744 || ([info exists currentid] && $sha1string == $currentid)} return
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008745 if {[info exists tagids($sha1string)]} {
Denton Liue2445882020-09-10 21:36:33 -07008746 set id $tagids($sha1string)
Stephen Rothwelle1007122006-03-30 16:13:12 +11008747 } elseif {[info exists headids($sha1string)]} {
Denton Liue2445882020-09-10 21:36:33 -07008748 set id $headids($sha1string)
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008749 } else {
Denton Liue2445882020-09-10 21:36:33 -07008750 set id [string tolower $sha1string]
8751 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
8752 set matches [longid $id]
8753 if {$matches ne {}} {
8754 if {[llength $matches] > 1} {
8755 error_popup [mc "Short SHA1 id %s is ambiguous" $id]
8756 return
8757 }
8758 set id [lindex $matches 0]
8759 }
8760 } else {
8761 if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
8762 error_popup [mc "Revision %s is not known" $sha1string]
8763 return
8764 }
8765 }
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008766 }
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008767 if {[commitinview $id $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07008768 selectline [rowofcommit $id] 1
8769 return
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008770 }
Paul Mackerrasf3b8b3c2005-07-18 12:16:35 -04008771 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
Denton Liue2445882020-09-10 21:36:33 -07008772 set msg [mc "SHA1 id %s is not known" $sha1string]
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008773 } else {
Denton Liue2445882020-09-10 21:36:33 -07008774 set msg [mc "Revision %s is not in the current view" $sha1string]
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008775 }
Christian Stimmingd990ced2007-11-07 18:42:55 +01008776 error_popup $msg
Paul Mackerras887fe3c2005-05-21 07:35:37 +00008777}
8778
Paul Mackerras84ba7342005-06-17 00:12:26 +00008779proc lineenter {x y id} {
8780 global hoverx hovery hoverid hovertimer
8781 global commitinfo canv
8782
Paul Mackerras8ed16482006-03-02 22:56:44 +11008783 if {![info exists commitinfo($id)] && ![getcommit $id]} return
Paul Mackerras84ba7342005-06-17 00:12:26 +00008784 set hoverx $x
8785 set hovery $y
8786 set hoverid $id
8787 if {[info exists hovertimer]} {
Denton Liue2445882020-09-10 21:36:33 -07008788 after cancel $hovertimer
Paul Mackerras84ba7342005-06-17 00:12:26 +00008789 }
8790 set hovertimer [after 500 linehover]
8791 $canv delete hover
8792}
8793
8794proc linemotion {x y id} {
8795 global hoverx hovery hoverid hovertimer
8796
8797 if {[info exists hoverid] && $id == $hoverid} {
Denton Liue2445882020-09-10 21:36:33 -07008798 set hoverx $x
8799 set hovery $y
8800 if {[info exists hovertimer]} {
8801 after cancel $hovertimer
8802 }
8803 set hovertimer [after 500 linehover]
Paul Mackerras84ba7342005-06-17 00:12:26 +00008804 }
8805}
8806
8807proc lineleave {id} {
8808 global hoverid hovertimer canv
8809
8810 if {[info exists hoverid] && $id == $hoverid} {
Denton Liue2445882020-09-10 21:36:33 -07008811 $canv delete hover
8812 if {[info exists hovertimer]} {
8813 after cancel $hovertimer
8814 unset hovertimer
8815 }
8816 unset hoverid
Paul Mackerras84ba7342005-06-17 00:12:26 +00008817 }
8818}
8819
8820proc linehover {} {
8821 global hoverx hovery hoverid hovertimer
8822 global canv linespc lthickness
Gauthier Östervall252c52d2013-03-27 14:40:51 +01008823 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor
8824
Paul Mackerras9c311b32007-10-04 22:27:13 +10008825 global commitinfo
Paul Mackerras84ba7342005-06-17 00:12:26 +00008826
8827 set text [lindex $commitinfo($hoverid) 0]
8828 set ymax [lindex [$canv cget -scrollregion] 3]
8829 if {$ymax == {}} return
8830 set yfrac [lindex [$canv yview] 0]
8831 set x [expr {$hoverx + 2 * $linespc}]
8832 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
8833 set x0 [expr {$x - 2 * $lthickness}]
8834 set y0 [expr {$y - 2 * $lthickness}]
Paul Mackerras9c311b32007-10-04 22:27:13 +10008835 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}]
Paul Mackerras84ba7342005-06-17 00:12:26 +00008836 set y1 [expr {$y + $linespc + 2 * $lthickness}]
8837 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
Denton Liue2445882020-09-10 21:36:33 -07008838 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \
8839 -width 1 -tags hover]
Paul Mackerras84ba7342005-06-17 00:12:26 +00008840 $canv raise $t
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +10008841 set t [$canv create text $x $y -anchor nw -text $text -tags hover \
Denton Liue2445882020-09-10 21:36:33 -07008842 -font mainfont -fill $linehoverfgcolor]
Paul Mackerras84ba7342005-06-17 00:12:26 +00008843 $canv raise $t
8844}
8845
Paul Mackerras9843c302005-08-30 10:57:11 +10008846proc clickisonarrow {id y} {
Paul Mackerras50b44ec2006-04-04 10:16:22 +10008847 global lthickness
Paul Mackerras9843c302005-08-30 10:57:11 +10008848
Paul Mackerras50b44ec2006-04-04 10:16:22 +10008849 set ranges [rowranges $id]
Paul Mackerras9843c302005-08-30 10:57:11 +10008850 set thresh [expr {2 * $lthickness + 6}]
Paul Mackerras50b44ec2006-04-04 10:16:22 +10008851 set n [expr {[llength $ranges] - 1}]
Paul Mackerrasf6342482006-02-28 10:02:03 +11008852 for {set i 1} {$i < $n} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07008853 set row [lindex $ranges $i]
8854 if {abs([yc $row] - $y) < $thresh} {
8855 return $i
8856 }
Paul Mackerras9843c302005-08-30 10:57:11 +10008857 }
8858 return {}
8859}
8860
Paul Mackerrasf6342482006-02-28 10:02:03 +11008861proc arrowjump {id n y} {
Paul Mackerras50b44ec2006-04-04 10:16:22 +10008862 global canv
Paul Mackerras9843c302005-08-30 10:57:11 +10008863
Paul Mackerrasf6342482006-02-28 10:02:03 +11008864 # 1 <-> 2, 3 <-> 4, etc...
8865 set n [expr {(($n - 1) ^ 1) + 1}]
Paul Mackerras50b44ec2006-04-04 10:16:22 +10008866 set row [lindex [rowranges $id] $n]
Paul Mackerrasf6342482006-02-28 10:02:03 +11008867 set yt [yc $row]
Paul Mackerras9843c302005-08-30 10:57:11 +10008868 set ymax [lindex [$canv cget -scrollregion] 3]
8869 if {$ymax eq {} || $ymax <= 0} return
8870 set view [$canv yview]
8871 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
8872 set yfrac [expr {$yt / $ymax - $yspan / 2}]
8873 if {$yfrac < 0} {
Denton Liue2445882020-09-10 21:36:33 -07008874 set yfrac 0
Paul Mackerras9843c302005-08-30 10:57:11 +10008875 }
Paul Mackerrasf6342482006-02-28 10:02:03 +11008876 allcanvs yview moveto $yfrac
Paul Mackerras9843c302005-08-30 10:57:11 +10008877}
8878
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10008879proc lineclick {x y id isnew} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008880 global ctext commitinfo children canv thickerline curview
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008881
Paul Mackerras8ed16482006-03-02 22:56:44 +11008882 if {![info exists commitinfo($id)] && ![getcommit $id]} return
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008883 unmarkmatches
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10008884 unselectline
Paul Mackerras9843c302005-08-30 10:57:11 +10008885 normalline
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008886 $canv delete hover
Paul Mackerras9843c302005-08-30 10:57:11 +10008887 # draw this line thicker than normal
Paul Mackerras9843c302005-08-30 10:57:11 +10008888 set thickerline $id
Paul Mackerrasc934a8a2006-03-02 23:00:44 +11008889 drawlines $id
Paul Mackerras9843c302005-08-30 10:57:11 +10008890 if {$isnew} {
Denton Liue2445882020-09-10 21:36:33 -07008891 set ymax [lindex [$canv cget -scrollregion] 3]
8892 if {$ymax eq {}} return
8893 set yfrac [lindex [$canv yview] 0]
8894 set y [expr {$y + $yfrac * $ymax}]
Paul Mackerras9843c302005-08-30 10:57:11 +10008895 }
8896 set dirn [clickisonarrow $id $y]
8897 if {$dirn ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008898 arrowjump $id $dirn $y
8899 return
Paul Mackerras9843c302005-08-30 10:57:11 +10008900 }
8901
8902 if {$isnew} {
Denton Liue2445882020-09-10 21:36:33 -07008903 addtohistory [list lineclick $x $y $id 0] savectextpos
Paul Mackerras9843c302005-08-30 10:57:11 +10008904 }
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008905 # fill the details pane with info about this line
8906 $ctext conf -state normal
Paul Mackerras3ea06f92006-05-24 10:16:03 +10008907 clear_ctext
Paul Mackerras32f1b3e2007-09-28 21:27:39 +10008908 settabs 0
Christian Stimmingd990ced2007-11-07 18:42:55 +01008909 $ctext insert end "[mc "Parent"]:\t"
Paul Mackerras97645682007-08-23 22:24:38 +10008910 $ctext insert end $id link0
8911 setlink $id link0
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008912 set info $commitinfo($id)
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10008913 $ctext insert end "\n\t[lindex $info 0]\n"
Christian Stimmingd990ced2007-11-07 18:42:55 +01008914 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n"
Paul Mackerras232475d2005-11-15 10:34:03 +11008915 set date [formatdate [lindex $info 2]]
Christian Stimmingd990ced2007-11-07 18:42:55 +01008916 $ctext insert end "\t[mc "Date"]:\t$date\n"
Paul Mackerrasda7c24d2006-05-02 11:15:29 +10008917 set kids $children($curview,$id)
Paul Mackerras79b2c752006-04-02 20:47:40 +10008918 if {$kids ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07008919 $ctext insert end "\n[mc "Children"]:"
8920 set i 0
8921 foreach child $kids {
8922 incr i
8923 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
8924 set info $commitinfo($child)
8925 $ctext insert end "\n\t"
8926 $ctext insert end $child link$i
8927 setlink $child link$i
8928 $ctext insert end "\n\t[lindex $info 0]"
8929 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]"
8930 set date [formatdate [lindex $info 2]]
8931 $ctext insert end "\n\t[mc "Date"]:\t$date\n"
8932 }
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008933 }
Paul Mackerras354af6b2008-11-23 13:14:23 +11008934 maybe_scroll_ctext 1
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008935 $ctext conf -state disabled
Paul Mackerras7fcceed2006-04-27 19:21:49 +10008936 init_flist {}
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008937}
8938
Paul Mackerras9843c302005-08-30 10:57:11 +10008939proc normalline {} {
8940 global thickerline
8941 if {[info exists thickerline]} {
Denton Liue2445882020-09-10 21:36:33 -07008942 set id $thickerline
8943 unset thickerline
8944 drawlines $id
Paul Mackerras9843c302005-08-30 10:57:11 +10008945 }
8946}
8947
Paul Mackerras354af6b2008-11-23 13:14:23 +11008948proc selbyid {id {isnew 1}} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008949 global curview
8950 if {[commitinview $id $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07008951 selectline [rowofcommit $id] $isnew
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008952 }
8953}
8954
8955proc mstime {} {
8956 global startmstime
8957 if {![info exists startmstime]} {
Denton Liue2445882020-09-10 21:36:33 -07008958 set startmstime [clock clicks -milliseconds]
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008959 }
8960 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
8961}
8962
8963proc rowmenu {x y id} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11008964 global rowctxmenu selectedline rowmenuid curview
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10008965 global nullid nullid2 fakerowmenu mainhead markedid
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008966
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10008967 stopfinding
Paul Mackerras219ea3a2006-09-07 10:21:39 +10008968 set rowmenuid $id
Paul Mackerras94b4a692008-05-20 20:51:06 +10008969 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} {
Denton Liue2445882020-09-10 21:36:33 -07008970 set state disabled
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008971 } else {
Denton Liue2445882020-09-10 21:36:33 -07008972 set state normal
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008973 }
Paul Mackerras6febded2012-03-23 22:07:27 +11008974 if {[info exists markedid] && $markedid ne $id} {
Denton Liue2445882020-09-10 21:36:33 -07008975 set mstate normal
Paul Mackerras6febded2012-03-23 22:07:27 +11008976 } else {
Denton Liue2445882020-09-10 21:36:33 -07008977 set mstate disabled
Paul Mackerras6febded2012-03-23 22:07:27 +11008978 }
Paul Mackerras8f489362007-07-13 19:49:37 +10008979 if {$id ne $nullid && $id ne $nullid2} {
Denton Liue2445882020-09-10 21:36:33 -07008980 set menu $rowctxmenu
8981 if {$mainhead ne {}} {
8982 $menu entryconfigure 8 -label [mc "Reset %s branch to here" $mainhead] -state normal
8983 } else {
8984 $menu entryconfigure 8 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8985 }
8986 $menu entryconfigure 10 -state $mstate
8987 $menu entryconfigure 11 -state $mstate
8988 $menu entryconfigure 12 -state $mstate
Paul Mackerras219ea3a2006-09-07 10:21:39 +10008989 } else {
Denton Liue2445882020-09-10 21:36:33 -07008990 set menu $fakerowmenu
Paul Mackerras219ea3a2006-09-07 10:21:39 +10008991 }
Paul Mackerrasf2d0bbb2008-10-17 22:44:42 +11008992 $menu entryconfigure [mca "Diff this -> selected"] -state $state
8993 $menu entryconfigure [mca "Diff selected -> this"] -state $state
8994 $menu entryconfigure [mca "Make patch"] -state $state
Paul Mackerras6febded2012-03-23 22:07:27 +11008995 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate
8996 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate
Paul Mackerras219ea3a2006-09-07 10:21:39 +10008997 tk_popup $menu $x $y
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10008998}
8999
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009000proc markhere {} {
9001 global rowmenuid markedid canv
9002
9003 set markedid $rowmenuid
9004 make_idmark $markedid
9005}
9006
9007proc gotomark {} {
9008 global markedid
9009
9010 if {[info exists markedid]} {
Denton Liue2445882020-09-10 21:36:33 -07009011 selbyid $markedid
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009012 }
9013}
9014
9015proc replace_by_kids {l r} {
9016 global curview children
9017
9018 set id [commitonrow $r]
9019 set l [lreplace $l 0 0]
9020 foreach kid $children($curview,$id) {
Denton Liue2445882020-09-10 21:36:33 -07009021 lappend l [rowofcommit $kid]
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009022 }
9023 return [lsort -integer -decreasing -unique $l]
9024}
9025
9026proc find_common_desc {} {
9027 global markedid rowmenuid curview children
9028
9029 if {![info exists markedid]} return
9030 if {![commitinview $markedid $curview] ||
Denton Liue2445882020-09-10 21:36:33 -07009031 ![commitinview $rowmenuid $curview]} return
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009032 #set t1 [clock clicks -milliseconds]
9033 set l1 [list [rowofcommit $markedid]]
9034 set l2 [list [rowofcommit $rowmenuid]]
9035 while 1 {
Denton Liue2445882020-09-10 21:36:33 -07009036 set r1 [lindex $l1 0]
9037 set r2 [lindex $l2 0]
9038 if {$r1 eq {} || $r2 eq {}} break
9039 if {$r1 == $r2} {
9040 selectline $r1 1
9041 break
9042 }
9043 if {$r1 > $r2} {
9044 set l1 [replace_by_kids $l1 $r1]
9045 } else {
9046 set l2 [replace_by_kids $l2 $r2]
9047 }
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009048 }
9049 #set t2 [clock clicks -milliseconds]
9050 #puts "took [expr {$t2-$t1}]ms"
9051}
9052
Paul Mackerras010509f2009-04-09 22:10:20 +10009053proc compare_commits {} {
9054 global markedid rowmenuid curview children
9055
9056 if {![info exists markedid]} return
9057 if {![commitinview $markedid $curview]} return
9058 addtohistory [list do_cmp_commits $markedid $rowmenuid]
9059 do_cmp_commits $markedid $rowmenuid
9060}
9061
9062proc getpatchid {id} {
9063 global patchids
9064
9065 if {![info exists patchids($id)]} {
Denton Liue2445882020-09-10 21:36:33 -07009066 set cmd [diffcmd [list $id] {-p --root}]
9067 # trim off the initial "|"
9068 set cmd [lrange $cmd 1 end]
9069 if {[catch {
9070 set x [eval exec $cmd | git patch-id]
9071 set patchids($id) [lindex $x 0]
9072 }]} {
9073 set patchids($id) "error"
9074 }
Paul Mackerras010509f2009-04-09 22:10:20 +10009075 }
9076 return $patchids($id)
9077}
9078
9079proc do_cmp_commits {a b} {
9080 global ctext curview parents children patchids commitinfo
9081
9082 $ctext conf -state normal
9083 clear_ctext
9084 init_flist {}
9085 for {set i 0} {$i < 100} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -07009086 set skipa 0
9087 set skipb 0
9088 if {[llength $parents($curview,$a)] > 1} {
9089 appendshortlink $a [mc "Skipping merge commit "] "\n"
9090 set skipa 1
9091 } else {
9092 set patcha [getpatchid $a]
9093 }
9094 if {[llength $parents($curview,$b)] > 1} {
9095 appendshortlink $b [mc "Skipping merge commit "] "\n"
9096 set skipb 1
9097 } else {
9098 set patchb [getpatchid $b]
9099 }
9100 if {!$skipa && !$skipb} {
9101 set heada [lindex $commitinfo($a) 0]
9102 set headb [lindex $commitinfo($b) 0]
9103 if {$patcha eq "error"} {
9104 appendshortlink $a [mc "Error getting patch ID for "] \
9105 [mc " - stopping\n"]
9106 break
9107 }
9108 if {$patchb eq "error"} {
9109 appendshortlink $b [mc "Error getting patch ID for "] \
9110 [mc " - stopping\n"]
9111 break
9112 }
9113 if {$patcha eq $patchb} {
9114 if {$heada eq $headb} {
9115 appendshortlink $a [mc "Commit "]
9116 appendshortlink $b " == " " $heada\n"
9117 } else {
9118 appendshortlink $a [mc "Commit "] " $heada\n"
9119 appendshortlink $b [mc " is the same patch as\n "] \
9120 " $headb\n"
9121 }
9122 set skipa 1
9123 set skipb 1
9124 } else {
9125 $ctext insert end "\n"
9126 appendshortlink $a [mc "Commit "] " $heada\n"
9127 appendshortlink $b [mc " differs from\n "] \
9128 " $headb\n"
9129 $ctext insert end [mc "Diff of commits:\n\n"]
9130 $ctext conf -state disabled
9131 update
9132 diffcommits $a $b
9133 return
9134 }
9135 }
9136 if {$skipa} {
9137 set kids [real_children $curview,$a]
9138 if {[llength $kids] != 1} {
9139 $ctext insert end "\n"
9140 appendshortlink $a [mc "Commit "] \
9141 [mc " has %s children - stopping\n" [llength $kids]]
9142 break
9143 }
9144 set a [lindex $kids 0]
9145 }
9146 if {$skipb} {
9147 set kids [real_children $curview,$b]
9148 if {[llength $kids] != 1} {
9149 appendshortlink $b [mc "Commit "] \
9150 [mc " has %s children - stopping\n" [llength $kids]]
9151 break
9152 }
9153 set b [lindex $kids 0]
9154 }
Paul Mackerras010509f2009-04-09 22:10:20 +10009155 }
9156 $ctext conf -state disabled
9157}
9158
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009159proc diffcommits {a b} {
Jens Lehmanna1d383c2010-04-09 22:16:42 +02009160 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009161
9162 set tmpdir [gitknewtmpdir]
9163 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
9164 set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
9165 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009166 exec git diff-tree -p --pretty $a >$fna
9167 exec git diff-tree -p --pretty $b >$fnb
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009168 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009169 error_popup [mc "Error writing commit to file: %s" $err]
9170 return
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009171 }
9172 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009173 set fd [open "| diff -U$diffcontext $fna $fnb" r]
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009174 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009175 error_popup [mc "Error diffing commits: %s" $err]
9176 return
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009177 }
9178 set diffids [list commits $a $b]
9179 set blobdifffd($diffids) $fd
9180 set diffinhdr 0
Jens Lehmanna1d383c2010-04-09 22:16:42 +02009181 set currdiffsubmod ""
Paul Mackerrasc21398b2009-09-07 10:08:21 +10009182 filerun $fd [list getblobdiffline $fd $diffids]
9183}
9184
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009185proc diffvssel {dirn} {
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11009186 global rowmenuid selectedline
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009187
Paul Mackerras94b4a692008-05-20 20:51:06 +10009188 if {$selectedline eq {}} return
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009189 if {$dirn} {
Denton Liue2445882020-09-10 21:36:33 -07009190 set oldid [commitonrow $selectedline]
9191 set newid $rowmenuid
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009192 } else {
Denton Liue2445882020-09-10 21:36:33 -07009193 set oldid $rowmenuid
9194 set newid [commitonrow $selectedline]
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009195 }
Paul Mackerras354af6b2008-11-23 13:14:23 +11009196 addtohistory [list doseldiff $oldid $newid] savectextpos
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10009197 doseldiff $oldid $newid
9198}
9199
Paul Mackerras6febded2012-03-23 22:07:27 +11009200proc diffvsmark {dirn} {
9201 global rowmenuid markedid
9202
9203 if {![info exists markedid]} return
9204 if {$dirn} {
Denton Liue2445882020-09-10 21:36:33 -07009205 set oldid $markedid
9206 set newid $rowmenuid
Paul Mackerras6febded2012-03-23 22:07:27 +11009207 } else {
Denton Liue2445882020-09-10 21:36:33 -07009208 set oldid $rowmenuid
9209 set newid $markedid
Paul Mackerras6febded2012-03-23 22:07:27 +11009210 }
9211 addtohistory [list doseldiff $oldid $newid] savectextpos
9212 doseldiff $oldid $newid
9213}
9214
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10009215proc doseldiff {oldid newid} {
Paul Mackerras7fcceed2006-04-27 19:21:49 +10009216 global ctext
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10009217 global commitinfo
9218
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009219 $ctext conf -state normal
Paul Mackerras3ea06f92006-05-24 10:16:03 +10009220 clear_ctext
Christian Stimmingd990ced2007-11-07 18:42:55 +01009221 init_flist [mc "Top"]
9222 $ctext insert end "[mc "From"] "
Paul Mackerras97645682007-08-23 22:24:38 +10009223 $ctext insert end $oldid link0
9224 setlink $oldid link0
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10009225 $ctext insert end "\n "
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009226 $ctext insert end [lindex $commitinfo($oldid) 0]
Christian Stimmingd990ced2007-11-07 18:42:55 +01009227 $ctext insert end "\n\n[mc "To"] "
Paul Mackerras97645682007-08-23 22:24:38 +10009228 $ctext insert end $newid link1
9229 setlink $newid link1
Paul Mackerrasfa4da7b2005-08-08 09:47:22 +10009230 $ctext insert end "\n "
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009231 $ctext insert end [lindex $commitinfo($newid) 0]
9232 $ctext insert end "\n"
9233 $ctext conf -state disabled
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009234 $ctext tag remove found 1.0 end
Paul Mackerrasd3272442005-11-28 20:41:56 +11009235 startdiff [list $oldid $newid]
Paul Mackerrasc8dfbcf2005-06-25 15:39:21 +10009236}
9237
Paul Mackerras74daedb2005-06-27 19:27:32 +10009238proc mkpatch {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01009239 global rowmenuid currentid commitinfo patchtop patchnum NS
Paul Mackerras74daedb2005-06-27 19:27:32 +10009240
9241 if {![info exists currentid]} return
9242 set oldid $currentid
9243 set oldhead [lindex $commitinfo($oldid) 0]
9244 set newid $rowmenuid
9245 set newhead [lindex $commitinfo($newid) 0]
9246 set top .patch
9247 set patchtop $top
9248 catch {destroy $top}
Pat Thoytsd93f1712009-04-17 01:24:35 +01009249 ttk_toplevel $top
Alexander Gavrilove7d64002008-11-11 23:55:42 +03009250 make_transient $top .
Pat Thoytsd93f1712009-04-17 01:24:35 +01009251 ${NS}::label $top.title -text [mc "Generate patch"]
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009252 grid $top.title - -pady 10
Pat Thoytsd93f1712009-04-17 01:24:35 +01009253 ${NS}::label $top.from -text [mc "From:"]
9254 ${NS}::entry $top.fromsha1 -width 40
Paul Mackerras74daedb2005-06-27 19:27:32 +10009255 $top.fromsha1 insert 0 $oldid
9256 $top.fromsha1 conf -state readonly
9257 grid $top.from $top.fromsha1 -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009258 ${NS}::entry $top.fromhead -width 60
Paul Mackerras74daedb2005-06-27 19:27:32 +10009259 $top.fromhead insert 0 $oldhead
9260 $top.fromhead conf -state readonly
9261 grid x $top.fromhead -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009262 ${NS}::label $top.to -text [mc "To:"]
9263 ${NS}::entry $top.tosha1 -width 40
Paul Mackerras74daedb2005-06-27 19:27:32 +10009264 $top.tosha1 insert 0 $newid
9265 $top.tosha1 conf -state readonly
9266 grid $top.to $top.tosha1 -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009267 ${NS}::entry $top.tohead -width 60
Paul Mackerras74daedb2005-06-27 19:27:32 +10009268 $top.tohead insert 0 $newhead
9269 $top.tohead conf -state readonly
9270 grid x $top.tohead -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009271 ${NS}::button $top.rev -text [mc "Reverse"] -command mkpatchrev
9272 grid $top.rev x -pady 10 -padx 5
9273 ${NS}::label $top.flab -text [mc "Output file:"]
9274 ${NS}::entry $top.fname -width 60
Paul Mackerras74daedb2005-06-27 19:27:32 +10009275 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
9276 incr patchnum
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009277 grid $top.flab $top.fname -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009278 ${NS}::frame $top.buts
9279 ${NS}::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo
9280 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan
Alexander Gavrilov76f15942008-11-02 21:59:44 +03009281 bind $top <Key-Return> mkpatchgo
9282 bind $top <Key-Escape> mkpatchcan
Paul Mackerras74daedb2005-06-27 19:27:32 +10009283 grid $top.buts.gen $top.buts.can
9284 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9285 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9286 grid $top.buts - -pady 10 -sticky ew
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009287 focus $top.fname
Paul Mackerras74daedb2005-06-27 19:27:32 +10009288}
9289
9290proc mkpatchrev {} {
9291 global patchtop
9292
9293 set oldid [$patchtop.fromsha1 get]
9294 set oldhead [$patchtop.fromhead get]
9295 set newid [$patchtop.tosha1 get]
9296 set newhead [$patchtop.tohead get]
9297 foreach e [list fromsha1 fromhead tosha1 tohead] \
Denton Liue2445882020-09-10 21:36:33 -07009298 v [list $newid $newhead $oldid $oldhead] {
9299 $patchtop.$e conf -state normal
9300 $patchtop.$e delete 0 end
9301 $patchtop.$e insert 0 $v
9302 $patchtop.$e conf -state readonly
Paul Mackerras74daedb2005-06-27 19:27:32 +10009303 }
9304}
9305
9306proc mkpatchgo {} {
Paul Mackerras8f489362007-07-13 19:49:37 +10009307 global patchtop nullid nullid2
Paul Mackerras74daedb2005-06-27 19:27:32 +10009308
9309 set oldid [$patchtop.fromsha1 get]
9310 set newid [$patchtop.tosha1 get]
9311 set fname [$patchtop.fname get]
Paul Mackerras8f489362007-07-13 19:49:37 +10009312 set cmd [diffcmd [list $oldid $newid] -p]
Paul Mackerrasd372e212007-09-15 12:08:38 +10009313 # trim off the initial "|"
9314 set cmd [lrange $cmd 1 end]
Paul Mackerras219ea3a2006-09-07 10:21:39 +10009315 lappend cmd >$fname &
9316 if {[catch {eval exec $cmd} err]} {
Denton Liue2445882020-09-10 21:36:33 -07009317 error_popup "[mc "Error creating patch:"] $err" $patchtop
Paul Mackerras74daedb2005-06-27 19:27:32 +10009318 }
9319 catch {destroy $patchtop}
9320 unset patchtop
9321}
9322
9323proc mkpatchcan {} {
9324 global patchtop
9325
9326 catch {destroy $patchtop}
9327 unset patchtop
9328}
9329
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009330proc mktag {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01009331 global rowmenuid mktagtop commitinfo NS
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009332
9333 set top .maketag
9334 set mktagtop $top
9335 catch {destroy $top}
Pat Thoytsd93f1712009-04-17 01:24:35 +01009336 ttk_toplevel $top
Alexander Gavrilove7d64002008-11-11 23:55:42 +03009337 make_transient $top .
Pat Thoytsd93f1712009-04-17 01:24:35 +01009338 ${NS}::label $top.title -text [mc "Create tag"]
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009339 grid $top.title - -pady 10
Pat Thoytsd93f1712009-04-17 01:24:35 +01009340 ${NS}::label $top.id -text [mc "ID:"]
9341 ${NS}::entry $top.sha1 -width 40
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009342 $top.sha1 insert 0 $rowmenuid
9343 $top.sha1 conf -state readonly
9344 grid $top.id $top.sha1 -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009345 ${NS}::entry $top.head -width 60
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009346 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9347 $top.head conf -state readonly
9348 grid x $top.head -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009349 ${NS}::label $top.tlab -text [mc "Tag name:"]
9350 ${NS}::entry $top.tag -width 60
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009351 grid $top.tlab $top.tag -sticky w
Dave Dulsondfb891e2010-01-03 14:55:52 +00009352 ${NS}::label $top.op -text [mc "Tag message is optional"]
9353 grid $top.op -columnspan 2 -sticky we
9354 ${NS}::label $top.mlab -text [mc "Tag message:"]
9355 ${NS}::entry $top.msg -width 60
9356 grid $top.mlab $top.msg -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009357 ${NS}::frame $top.buts
9358 ${NS}::button $top.buts.gen -text [mc "Create"] -command mktaggo
9359 ${NS}::button $top.buts.can -text [mc "Cancel"] -command mktagcan
Alexander Gavrilov76f15942008-11-02 21:59:44 +03009360 bind $top <Key-Return> mktaggo
9361 bind $top <Key-Escape> mktagcan
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009362 grid $top.buts.gen $top.buts.can
9363 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9364 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9365 grid $top.buts - -pady 10 -sticky ew
9366 focus $top.tag
9367}
9368
9369proc domktag {} {
9370 global mktagtop env tagids idtags
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009371
9372 set id [$mktagtop.sha1 get]
9373 set tag [$mktagtop.tag get]
Dave Dulsondfb891e2010-01-03 14:55:52 +00009374 set msg [$mktagtop.msg get]
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009375 if {$tag == {}} {
Denton Liue2445882020-09-10 21:36:33 -07009376 error_popup [mc "No tag name specified"] $mktagtop
9377 return 0
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009378 }
9379 if {[info exists tagids($tag)]} {
Denton Liue2445882020-09-10 21:36:33 -07009380 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop
9381 return 0
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009382 }
9383 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009384 if {$msg != {}} {
9385 exec git tag -a -m $msg $tag $id
9386 } else {
9387 exec git tag $tag $id
9388 }
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009389 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009390 error_popup "[mc "Error creating tag:"] $err" $mktagtop
9391 return 0
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009392 }
9393
9394 set tagids($tag) $id
9395 lappend idtags($id) $tag
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10009396 redrawtags $id
Paul Mackerrasceadfe92006-08-08 20:55:36 +10009397 addedtag $id
Paul Mackerras887c9962007-08-20 19:36:20 +10009398 dispneartags 0
9399 run refill_reflist
Alexander Gavrilov84a76f12008-11-02 21:59:45 +03009400 return 1
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10009401}
9402
9403proc redrawtags {id} {
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009404 global canv linehtag idpos currentid curview cmitlisted markedid
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009405 global canvxmax iddrawn circleitem mainheadid circlecolors
Gauthier Östervall252c52d2013-03-27 14:40:51 +01009406 global mainheadcirclecolor
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +10009407
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11009408 if {![commitinview $id $curview]} return
Paul Mackerras322a8cc2006-10-15 18:03:46 +10009409 if {![info exists iddrawn($id)]} return
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11009410 set row [rowofcommit $id]
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009411 if {$id eq $mainheadid} {
Denton Liue2445882020-09-10 21:36:33 -07009412 set ofill $mainheadcirclecolor
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009413 } else {
Denton Liue2445882020-09-10 21:36:33 -07009414 set ofill [lindex $circlecolors $cmitlisted($curview,$id)]
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009415 }
9416 $canv itemconf $circleitem($row) -fill $ofill
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009417 $canv delete tag.$id
9418 set xt [eval drawtags $id $idpos($id)]
Paul Mackerras28593d32008-11-13 23:01:46 +11009419 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2]
9420 set text [$canv itemcget $linehtag($id) -text]
9421 set font [$canv itemcget $linehtag($id) -font]
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11009422 set xr [expr {$xt + [font measure $font $text]}]
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10009423 if {$xr > $canvxmax} {
Denton Liue2445882020-09-10 21:36:33 -07009424 set canvxmax $xr
9425 setcanvscroll
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +10009426 }
Paul Mackerrasfc2a2562007-12-26 23:03:43 +11009427 if {[info exists currentid] && $currentid == $id} {
Denton Liue2445882020-09-10 21:36:33 -07009428 make_secsel $id
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009429 }
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009430 if {[info exists markedid] && $markedid eq $id} {
Denton Liue2445882020-09-10 21:36:33 -07009431 make_idmark $id
Paul Mackerrasb9fdba72009-04-09 09:34:46 +10009432 }
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009433}
9434
9435proc mktagcan {} {
9436 global mktagtop
9437
9438 catch {destroy $mktagtop}
9439 unset mktagtop
9440}
9441
9442proc mktaggo {} {
Alexander Gavrilov84a76f12008-11-02 21:59:45 +03009443 if {![domktag]} return
Paul Mackerrasbdbfbe32005-06-27 22:56:40 +10009444 mktagcan
9445}
9446
Beat Bollib8b60952019-12-12 16:44:50 -08009447proc copyreference {} {
Beat Bollid835dbb2015-07-18 13:15:39 +02009448 global rowmenuid autosellen
9449
9450 set format "%h (\"%s\", %ad)"
9451 set cmd [list git show -s --pretty=format:$format --date=short]
9452 if {$autosellen < 40} {
9453 lappend cmd --abbrev=$autosellen
9454 }
Beat Bollib8b60952019-12-12 16:44:50 -08009455 set reference [eval exec $cmd $rowmenuid]
Beat Bollid835dbb2015-07-18 13:15:39 +02009456
9457 clipboard clear
Beat Bollib8b60952019-12-12 16:44:50 -08009458 clipboard append $reference
Beat Bollid835dbb2015-07-18 13:15:39 +02009459}
9460
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009461proc writecommit {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01009462 global rowmenuid wrcomtop commitinfo wrcomcmd NS
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009463
9464 set top .writecommit
9465 set wrcomtop $top
9466 catch {destroy $top}
Pat Thoytsd93f1712009-04-17 01:24:35 +01009467 ttk_toplevel $top
Alexander Gavrilove7d64002008-11-11 23:55:42 +03009468 make_transient $top .
Pat Thoytsd93f1712009-04-17 01:24:35 +01009469 ${NS}::label $top.title -text [mc "Write commit to file"]
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009470 grid $top.title - -pady 10
Pat Thoytsd93f1712009-04-17 01:24:35 +01009471 ${NS}::label $top.id -text [mc "ID:"]
9472 ${NS}::entry $top.sha1 -width 40
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009473 $top.sha1 insert 0 $rowmenuid
9474 $top.sha1 conf -state readonly
9475 grid $top.id $top.sha1 -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009476 ${NS}::entry $top.head -width 60
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009477 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
9478 $top.head conf -state readonly
9479 grid x $top.head -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009480 ${NS}::label $top.clab -text [mc "Command:"]
9481 ${NS}::entry $top.cmd -width 60 -textvariable wrcomcmd
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009482 grid $top.clab $top.cmd -sticky w -pady 10
Pat Thoytsd93f1712009-04-17 01:24:35 +01009483 ${NS}::label $top.flab -text [mc "Output file:"]
9484 ${NS}::entry $top.fname -width 60
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009485 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
9486 grid $top.flab $top.fname -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009487 ${NS}::frame $top.buts
9488 ${NS}::button $top.buts.gen -text [mc "Write"] -command wrcomgo
9489 ${NS}::button $top.buts.can -text [mc "Cancel"] -command wrcomcan
Alexander Gavrilov76f15942008-11-02 21:59:44 +03009490 bind $top <Key-Return> wrcomgo
9491 bind $top <Key-Escape> wrcomcan
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009492 grid $top.buts.gen $top.buts.can
9493 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9494 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9495 grid $top.buts - -pady 10 -sticky ew
9496 focus $top.fname
9497}
9498
9499proc wrcomgo {} {
9500 global wrcomtop
9501
9502 set id [$wrcomtop.sha1 get]
9503 set cmd "echo $id | [$wrcomtop.cmd get]"
9504 set fname [$wrcomtop.fname get]
9505 if {[catch {exec sh -c $cmd >$fname &} err]} {
Denton Liue2445882020-09-10 21:36:33 -07009506 error_popup "[mc "Error writing commit:"] $err" $wrcomtop
Paul Mackerras4a2139f2005-06-29 09:47:48 +10009507 }
9508 catch {destroy $wrcomtop}
9509 unset wrcomtop
9510}
9511
9512proc wrcomcan {} {
9513 global wrcomtop
9514
9515 catch {destroy $wrcomtop}
9516 unset wrcomtop
9517}
9518
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009519proc mkbranch {} {
Rogier Goossens5a046c52016-03-19 19:32:16 +01009520 global NS rowmenuid
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009521
Rogier Goossens5a046c52016-03-19 19:32:16 +01009522 set top .branchdialog
9523
9524 set val(name) ""
9525 set val(id) $rowmenuid
9526 set val(command) [list mkbrgo $top]
9527
9528 set ui(title) [mc "Create branch"]
9529 set ui(accept) [mc "Create"]
9530
9531 branchdia $top val ui
9532}
9533
9534proc mvbranch {} {
9535 global NS
9536 global headmenuid headmenuhead
9537
9538 set top .branchdialog
9539
9540 set val(name) $headmenuhead
9541 set val(id) $headmenuid
9542 set val(command) [list mvbrgo $top $headmenuhead]
9543
9544 set ui(title) [mc "Rename branch %s" $headmenuhead]
9545 set ui(accept) [mc "Rename"]
9546
9547 branchdia $top val ui
9548}
9549
9550proc branchdia {top valvar uivar} {
Rogier Goossens7f00f4c2016-03-27 09:21:01 +02009551 global NS commitinfo
Rogier Goossens5a046c52016-03-19 19:32:16 +01009552 upvar $valvar val $uivar ui
9553
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009554 catch {destroy $top}
Pat Thoytsd93f1712009-04-17 01:24:35 +01009555 ttk_toplevel $top
Alexander Gavrilove7d64002008-11-11 23:55:42 +03009556 make_transient $top .
Rogier Goossens5a046c52016-03-19 19:32:16 +01009557 ${NS}::label $top.title -text $ui(title)
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009558 grid $top.title - -pady 10
Pat Thoytsd93f1712009-04-17 01:24:35 +01009559 ${NS}::label $top.id -text [mc "ID:"]
9560 ${NS}::entry $top.sha1 -width 40
Rogier Goossens5a046c52016-03-19 19:32:16 +01009561 $top.sha1 insert 0 $val(id)
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009562 $top.sha1 conf -state readonly
9563 grid $top.id $top.sha1 -sticky w
Rogier Goossens7f00f4c2016-03-27 09:21:01 +02009564 ${NS}::entry $top.head -width 60
9565 $top.head insert 0 [lindex $commitinfo($val(id)) 0]
9566 $top.head conf -state readonly
9567 grid x $top.head -sticky ew
9568 grid columnconfigure $top 1 -weight 1
Pat Thoytsd93f1712009-04-17 01:24:35 +01009569 ${NS}::label $top.nlab -text [mc "Name:"]
9570 ${NS}::entry $top.name -width 40
Rogier Goossens5a046c52016-03-19 19:32:16 +01009571 $top.name insert 0 $val(name)
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009572 grid $top.nlab $top.name -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009573 ${NS}::frame $top.buts
Rogier Goossens5a046c52016-03-19 19:32:16 +01009574 ${NS}::button $top.buts.go -text $ui(accept) -command $val(command)
Pat Thoytsd93f1712009-04-17 01:24:35 +01009575 ${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
Rogier Goossens5a046c52016-03-19 19:32:16 +01009576 bind $top <Key-Return> $val(command)
Alexander Gavrilov76f15942008-11-02 21:59:44 +03009577 bind $top <Key-Escape> "catch {destroy $top}"
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009578 grid $top.buts.go $top.buts.can
9579 grid columnconfigure $top.buts 0 -weight 1 -uniform a
9580 grid columnconfigure $top.buts 1 -weight 1 -uniform a
9581 grid $top.buts - -pady 10 -sticky ew
9582 focus $top.name
9583}
9584
9585proc mkbrgo {top} {
9586 global headids idheads
9587
9588 set name [$top.name get]
9589 set id [$top.sha1 get]
Alexander Gavrilovbee866f2008-10-08 11:05:35 +04009590 set cmdargs {}
9591 set old_id {}
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009592 if {$name eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07009593 error_popup [mc "Please specify a name for the new branch"] $top
9594 return
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009595 }
Alexander Gavrilovbee866f2008-10-08 11:05:35 +04009596 if {[info exists headids($name)]} {
Denton Liue2445882020-09-10 21:36:33 -07009597 if {![confirm_popup [mc \
9598 "Branch '%s' already exists. Overwrite?" $name] $top]} {
9599 return
9600 }
9601 set old_id $headids($name)
9602 lappend cmdargs -f
Alexander Gavrilovbee866f2008-10-08 11:05:35 +04009603 }
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009604 catch {destroy $top}
Alexander Gavrilovbee866f2008-10-08 11:05:35 +04009605 lappend cmdargs $name $id
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009606 nowbusy newbranch
9607 update
9608 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009609 eval exec git branch $cmdargs
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009610 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009611 notbusy newbranch
9612 error_popup $err
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009613 } else {
Denton Liue2445882020-09-10 21:36:33 -07009614 notbusy newbranch
9615 if {$old_id ne {}} {
9616 movehead $id $name
9617 movedhead $id $name
9618 redrawtags $old_id
9619 redrawtags $id
9620 } else {
9621 set headids($name) $id
9622 lappend idheads($id) $name
9623 addedhead $id $name
9624 redrawtags $id
9625 }
9626 dispneartags 0
9627 run refill_reflist
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +10009628 }
9629}
9630
Rogier Goossens5a046c52016-03-19 19:32:16 +01009631proc mvbrgo {top prevname} {
9632 global headids idheads mainhead mainheadid
9633
9634 set name [$top.name get]
9635 set id [$top.sha1 get]
9636 set cmdargs {}
9637 if {$name eq $prevname} {
Denton Liue2445882020-09-10 21:36:33 -07009638 catch {destroy $top}
9639 return
Rogier Goossens5a046c52016-03-19 19:32:16 +01009640 }
9641 if {$name eq {}} {
Denton Liue2445882020-09-10 21:36:33 -07009642 error_popup [mc "Please specify a new name for the branch"] $top
9643 return
Rogier Goossens5a046c52016-03-19 19:32:16 +01009644 }
9645 catch {destroy $top}
9646 lappend cmdargs -m $prevname $name
9647 nowbusy renamebranch
9648 update
9649 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009650 eval exec git branch $cmdargs
Rogier Goossens5a046c52016-03-19 19:32:16 +01009651 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009652 notbusy renamebranch
9653 error_popup $err
Rogier Goossens5a046c52016-03-19 19:32:16 +01009654 } else {
Denton Liue2445882020-09-10 21:36:33 -07009655 notbusy renamebranch
9656 removehead $id $prevname
9657 removedhead $id $prevname
9658 set headids($name) $id
9659 lappend idheads($id) $name
9660 addedhead $id $name
9661 if {$prevname eq $mainhead} {
9662 set mainhead $name
9663 set mainheadid $id
9664 }
9665 redrawtags $id
9666 dispneartags 0
9667 run refill_reflist
Rogier Goossens5a046c52016-03-19 19:32:16 +01009668 }
9669}
9670
Alexander Gavrilov15e35052008-11-02 21:59:47 +03009671proc exec_citool {tool_args {baseid {}}} {
9672 global commitinfo env
9673
9674 set save_env [array get env GIT_AUTHOR_*]
9675
9676 if {$baseid ne {}} {
Denton Liue2445882020-09-10 21:36:33 -07009677 if {![info exists commitinfo($baseid)]} {
9678 getcommit $baseid
9679 }
9680 set author [lindex $commitinfo($baseid) 1]
9681 set date [lindex $commitinfo($baseid) 2]
9682 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \
9683 $author author name email]
9684 && $date ne {}} {
9685 set env(GIT_AUTHOR_NAME) $name
9686 set env(GIT_AUTHOR_EMAIL) $email
9687 set env(GIT_AUTHOR_DATE) $date
9688 }
Alexander Gavrilov15e35052008-11-02 21:59:47 +03009689 }
9690
9691 eval exec git citool $tool_args &
9692
9693 array unset env GIT_AUTHOR_*
9694 array set env $save_env
9695}
9696
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009697proc cherrypick {} {
Paul Mackerras468bcae2008-03-03 10:19:35 +11009698 global rowmenuid curview
Paul Mackerrasb8a938c2008-02-13 22:12:31 +11009699 global mainhead mainheadid
Martin von Zweigbergkda616db2011-04-04 22:14:17 -04009700 global gitdir
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009701
Paul Mackerrase11f1232007-06-16 20:29:25 +10009702 set oldhead [exec git rev-parse HEAD]
9703 set dheads [descheads $rowmenuid]
9704 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07009705 set ok [confirm_popup [mc "Commit %s is already\
9706 included in branch %s -- really re-apply it?" \
9707 [string range $rowmenuid 0 7] $mainhead]]
9708 if {!$ok} return
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009709 }
Christian Stimmingd990ced2007-11-07 18:42:55 +01009710 nowbusy cherrypick [mc "Cherry-picking"]
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009711 update
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009712 # Unfortunately git-cherry-pick writes stuff to stderr even when
9713 # no error occurs, and exec takes that as an indication of error...
9714 if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
Denton Liue2445882020-09-10 21:36:33 -07009715 notbusy cherrypick
9716 if {[regexp -line \
9717 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
9718 $err msg fname]} {
9719 error_popup [mc "Cherry-pick failed because of local changes\
9720 to file '%s'.\nPlease commit, reset or stash\
9721 your changes and try again." $fname]
9722 } elseif {[regexp -line \
9723 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \
9724 $err]} {
9725 if {[confirm_popup [mc "Cherry-pick failed because of merge\
9726 conflict.\nDo you wish to run git citool to\
9727 resolve it?"]]} {
9728 # Force citool to read MERGE_MSG
9729 file delete [file join $gitdir "GITGUI_MSG"]
9730 exec_citool {} $rowmenuid
9731 }
9732 } else {
9733 error_popup $err
9734 }
9735 run updatecommits
9736 return
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009737 }
9738 set newhead [exec git rev-parse HEAD]
9739 if {$newhead eq $oldhead} {
Denton Liue2445882020-09-10 21:36:33 -07009740 notbusy cherrypick
9741 error_popup [mc "No changes committed"]
9742 return
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009743 }
Paul Mackerrase11f1232007-06-16 20:29:25 +10009744 addnewchild $newhead $oldhead
Paul Mackerras7fcc92b2007-12-03 10:33:01 +11009745 if {[commitinview $oldhead $curview]} {
Denton Liue2445882020-09-10 21:36:33 -07009746 # XXX this isn't right if we have a path limit...
9747 insertrow $newhead $oldhead $curview
9748 if {$mainhead ne {}} {
9749 movehead $newhead $mainhead
9750 movedhead $newhead $mainhead
9751 }
9752 set mainheadid $newhead
9753 redrawtags $oldhead
9754 redrawtags $newhead
9755 selbyid $newhead
Paul Mackerrasca6d8f52006-08-06 21:08:05 +10009756 }
9757 notbusy cherrypick
9758}
9759
Knut Franke8f3ff932013-04-27 16:36:13 +02009760proc revert {} {
9761 global rowmenuid curview
9762 global mainhead mainheadid
9763 global gitdir
9764
9765 set oldhead [exec git rev-parse HEAD]
9766 set dheads [descheads $rowmenuid]
9767 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } {
9768 set ok [confirm_popup [mc "Commit %s is not\
9769 included in branch %s -- really revert it?" \
9770 [string range $rowmenuid 0 7] $mainhead]]
9771 if {!$ok} return
9772 }
9773 nowbusy revert [mc "Reverting"]
9774 update
9775
9776 if [catch {exec git revert --no-edit $rowmenuid} err] {
9777 notbusy revert
9778 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\
9779 $err match files] {
9780 regsub {\n( |\t)+} $files "\n" files
9781 error_popup [mc "Revert failed because of local changes to\
9782 the following files:%s Please commit, reset or stash \
9783 your changes and try again." $files]
9784 } elseif [regexp {error: could not revert} $err] {
9785 if [confirm_popup [mc "Revert failed because of merge conflict.\n\
9786 Do you wish to run git citool to resolve it?"]] {
9787 # Force citool to read MERGE_MSG
9788 file delete [file join $gitdir "GITGUI_MSG"]
9789 exec_citool {} $rowmenuid
9790 }
9791 } else { error_popup $err }
9792 run updatecommits
9793 return
9794 }
9795
9796 set newhead [exec git rev-parse HEAD]
9797 if { $newhead eq $oldhead } {
9798 notbusy revert
9799 error_popup [mc "No changes committed"]
9800 return
9801 }
9802
9803 addnewchild $newhead $oldhead
9804
9805 if [commitinview $oldhead $curview] {
9806 # XXX this isn't right if we have a path limit...
9807 insertrow $newhead $oldhead $curview
9808 if {$mainhead ne {}} {
9809 movehead $newhead $mainhead
9810 movedhead $newhead $mainhead
9811 }
9812 set mainheadid $newhead
9813 redrawtags $oldhead
9814 redrawtags $newhead
9815 selbyid $newhead
9816 }
9817
9818 notbusy revert
9819}
9820
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009821proc resethead {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +01009822 global mainhead rowmenuid confirm_ok resettype NS
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009823
9824 set confirm_ok 0
9825 set w ".confirmreset"
Pat Thoytsd93f1712009-04-17 01:24:35 +01009826 ttk_toplevel $w
Alexander Gavrilove7d64002008-11-11 23:55:42 +03009827 make_transient $w .
Christian Stimmingd990ced2007-11-07 18:42:55 +01009828 wm title $w [mc "Confirm reset"]
Pat Thoytsd93f1712009-04-17 01:24:35 +01009829 ${NS}::label $w.m -text \
Denton Liue2445882020-09-10 21:36:33 -07009830 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009831 pack $w.m -side top -fill x -padx 20 -pady 20
Pat Thoytsd93f1712009-04-17 01:24:35 +01009832 ${NS}::labelframe $w.f -text [mc "Reset type:"]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009833 set resettype mixed
Pat Thoytsd93f1712009-04-17 01:24:35 +01009834 ${NS}::radiobutton $w.f.soft -value soft -variable resettype \
Denton Liue2445882020-09-10 21:36:33 -07009835 -text [mc "Soft: Leave working tree and index untouched"]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009836 grid $w.f.soft -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009837 ${NS}::radiobutton $w.f.mixed -value mixed -variable resettype \
Denton Liue2445882020-09-10 21:36:33 -07009838 -text [mc "Mixed: Leave working tree untouched, reset index"]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009839 grid $w.f.mixed -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009840 ${NS}::radiobutton $w.f.hard -value hard -variable resettype \
Denton Liue2445882020-09-10 21:36:33 -07009841 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009842 grid $w.f.hard -sticky w
Pat Thoytsd93f1712009-04-17 01:24:35 +01009843 pack $w.f -side top -fill x -padx 4
9844 ${NS}::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w"
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009845 pack $w.ok -side left -fill x -padx 20 -pady 20
Pat Thoytsd93f1712009-04-17 01:24:35 +01009846 ${NS}::button $w.cancel -text [mc Cancel] -command "destroy $w"
Alexander Gavrilov76f15942008-11-02 21:59:44 +03009847 bind $w <Key-Escape> [list destroy $w]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009848 pack $w.cancel -side right -fill x -padx 20 -pady 20
9849 bind $w <Visibility> "grab $w; focus $w"
9850 tkwait window $w
9851 if {!$confirm_ok} return
Paul Mackerras706d6c32007-06-26 11:09:49 +10009852 if {[catch {set fd [open \
Denton Liue2445882020-09-10 21:36:33 -07009853 [list | git reset --$resettype $rowmenuid 2>@1] r]} err]} {
9854 error_popup $err
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009855 } else {
Denton Liue2445882020-09-10 21:36:33 -07009856 dohidelocalchanges
9857 filerun $fd [list readresetstat $fd]
9858 nowbusy reset [mc "Resetting"]
9859 selbyid $rowmenuid
Paul Mackerras706d6c32007-06-26 11:09:49 +10009860 }
9861}
9862
Paul Mackerrasa137a902007-10-23 21:12:49 +10009863proc readresetstat {fd} {
9864 global mainhead mainheadid showlocalchanges rprogcoord
Paul Mackerras706d6c32007-06-26 11:09:49 +10009865
9866 if {[gets $fd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07009867 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9868 set rprogcoord [expr {1.0 * $m / $n}]
9869 adjustprogress
9870 }
9871 return 1
Paul Mackerras706d6c32007-06-26 11:09:49 +10009872 }
Paul Mackerrasa137a902007-10-23 21:12:49 +10009873 set rprogcoord 0
9874 adjustprogress
Paul Mackerras706d6c32007-06-26 11:09:49 +10009875 notbusy reset
9876 if {[catch {close $fd} err]} {
Denton Liue2445882020-09-10 21:36:33 -07009877 error_popup $err
Paul Mackerras706d6c32007-06-26 11:09:49 +10009878 }
9879 set oldhead $mainheadid
9880 set newhead [exec git rev-parse HEAD]
9881 if {$newhead ne $oldhead} {
Denton Liue2445882020-09-10 21:36:33 -07009882 movehead $newhead $mainhead
9883 movedhead $newhead $mainhead
9884 set mainheadid $newhead
9885 redrawtags $oldhead
9886 redrawtags $newhead
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009887 }
9888 if {$showlocalchanges} {
Denton Liue2445882020-09-10 21:36:33 -07009889 doshowlocalchanges
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009890 }
Paul Mackerras706d6c32007-06-26 11:09:49 +10009891 return 0
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009892}
9893
Paul Mackerras10299152006-08-02 09:52:01 +10009894# context menu for a head
9895proc headmenu {x y id head} {
Rogier Goossens02e6a062016-03-19 19:33:03 +01009896 global headmenuid headmenuhead headctxmenu mainhead headids
Paul Mackerras10299152006-08-02 09:52:01 +10009897
Paul Mackerrasbb3edc82007-09-27 11:00:25 +10009898 stopfinding
Paul Mackerras10299152006-08-02 09:52:01 +10009899 set headmenuid $id
9900 set headmenuhead $head
Rogier Goossens5a046c52016-03-19 19:32:16 +01009901 array set state {0 normal 1 normal 2 normal}
Sitaram Chamarty70a5fc42009-11-03 21:30:12 +05309902 if {[string match "remotes/*" $head]} {
Denton Liue2445882020-09-10 21:36:33 -07009903 set localhead [string range $head [expr [string last / $head] + 1] end]
9904 if {[info exists headids($localhead)]} {
9905 set state(0) disabled
9906 }
9907 array set state {1 disabled 2 disabled}
Sitaram Chamarty70a5fc42009-11-03 21:30:12 +05309908 }
Paul Mackerras00609462007-06-17 17:08:35 +10009909 if {$head eq $mainhead} {
Denton Liue2445882020-09-10 21:36:33 -07009910 array set state {0 disabled 2 disabled}
Paul Mackerras00609462007-06-17 17:08:35 +10009911 }
Rogier Goossens5a046c52016-03-19 19:32:16 +01009912 foreach i {0 1 2} {
Denton Liue2445882020-09-10 21:36:33 -07009913 $headctxmenu entryconfigure $i -state $state($i)
Rogier Goossens5a046c52016-03-19 19:32:16 +01009914 }
Paul Mackerras10299152006-08-02 09:52:01 +10009915 tk_popup $headctxmenu $x $y
9916}
9917
9918proc cobranch {} {
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009919 global headmenuid headmenuhead headids
Paul Mackerrascdc84292008-11-18 19:54:14 +11009920 global showlocalchanges
Paul Mackerras10299152006-08-02 09:52:01 +10009921
9922 # check the tree is clean first??
Rogier Goossens02e6a062016-03-19 19:33:03 +01009923 set newhead $headmenuhead
9924 set command [list | git checkout]
9925 if {[string match "remotes/*" $newhead]} {
Denton Liue2445882020-09-10 21:36:33 -07009926 set remote $newhead
9927 set newhead [string range $newhead [expr [string last / $newhead] + 1] end]
9928 # The following check is redundant - the menu option should
9929 # be disabled to begin with...
9930 if {[info exists headids($newhead)]} {
9931 error_popup [mc "A local branch named %s exists already" $newhead]
9932 return
9933 }
9934 lappend command -b $newhead --track $remote
Rogier Goossens02e6a062016-03-19 19:33:03 +01009935 } else {
Denton Liue2445882020-09-10 21:36:33 -07009936 lappend command $newhead
Rogier Goossens02e6a062016-03-19 19:33:03 +01009937 }
9938 lappend command 2>@1
Christian Stimmingd990ced2007-11-07 18:42:55 +01009939 nowbusy checkout [mc "Checking out"]
Paul Mackerras10299152006-08-02 09:52:01 +10009940 update
Paul Mackerras219ea3a2006-09-07 10:21:39 +10009941 dohidelocalchanges
Paul Mackerras10299152006-08-02 09:52:01 +10009942 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -07009943 set fd [open $command r]
Paul Mackerras10299152006-08-02 09:52:01 +10009944 } err]} {
Denton Liue2445882020-09-10 21:36:33 -07009945 notbusy checkout
9946 error_popup $err
9947 if {$showlocalchanges} {
9948 dodiffindex
9949 }
Paul Mackerras08ba8202008-05-12 10:18:38 +10009950 } else {
Denton Liue2445882020-09-10 21:36:33 -07009951 filerun $fd [list readcheckoutstat $fd $newhead $headmenuid]
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009952 }
Paul Mackerras08ba8202008-05-12 10:18:38 +10009953}
9954
9955proc readcheckoutstat {fd newhead newheadid} {
Rogier Goossens02e6a062016-03-19 19:33:03 +01009956 global mainhead mainheadid headids idheads showlocalchanges progresscoords
Paul Mackerrascdc84292008-11-18 19:54:14 +11009957 global viewmainheadid curview
Paul Mackerras08ba8202008-05-12 10:18:38 +10009958
9959 if {[gets $fd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -07009960 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} {
9961 set progresscoords [list 0 [expr {1.0 * $m / $n}]]
9962 adjustprogress
9963 }
9964 return 1
Paul Mackerras08ba8202008-05-12 10:18:38 +10009965 }
9966 set progresscoords {0 0}
9967 adjustprogress
9968 notbusy checkout
9969 if {[catch {close $fd} err]} {
Denton Liue2445882020-09-10 21:36:33 -07009970 error_popup $err
9971 return
Paul Mackerras08ba8202008-05-12 10:18:38 +10009972 }
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009973 set oldmainid $mainheadid
Rogier Goossens02e6a062016-03-19 19:33:03 +01009974 if {! [info exists headids($newhead)]} {
Denton Liue2445882020-09-10 21:36:33 -07009975 set headids($newhead) $newheadid
9976 lappend idheads($newheadid) $newhead
9977 addedhead $newheadid $newhead
Rogier Goossens02e6a062016-03-19 19:33:03 +01009978 }
Paul Mackerras08ba8202008-05-12 10:18:38 +10009979 set mainhead $newhead
9980 set mainheadid $newheadid
Paul Mackerrascdc84292008-11-18 19:54:14 +11009981 set viewmainheadid($curview) $newheadid
Paul Mackerrasc11ff122008-05-26 10:11:33 +10009982 redrawtags $oldmainid
Paul Mackerras08ba8202008-05-12 10:18:38 +10009983 redrawtags $newheadid
9984 selbyid $newheadid
Paul Mackerras6fb735a2006-10-19 10:09:06 +10009985 if {$showlocalchanges} {
Denton Liue2445882020-09-10 21:36:33 -07009986 dodiffindex
Paul Mackerras10299152006-08-02 09:52:01 +10009987 }
9988}
9989
9990proc rmbranch {} {
Paul Mackerrase11f1232007-06-16 20:29:25 +10009991 global headmenuid headmenuhead mainhead
Paul Mackerrasb1054ac2007-08-15 10:09:47 +10009992 global idheads
Paul Mackerras10299152006-08-02 09:52:01 +10009993
9994 set head $headmenuhead
9995 set id $headmenuid
Paul Mackerras00609462007-06-17 17:08:35 +10009996 # this check shouldn't be needed any more...
Paul Mackerras10299152006-08-02 09:52:01 +10009997 if {$head eq $mainhead} {
Denton Liue2445882020-09-10 21:36:33 -07009998 error_popup [mc "Cannot delete the currently checked-out branch"]
9999 return
Paul Mackerras10299152006-08-02 09:52:01 +100010000 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010001 set dheads [descheads $id]
Paul Mackerrasd7b16112007-08-17 17:57:31 +100010002 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
Denton Liue2445882020-09-10 21:36:33 -070010003 # the stuff on this branch isn't on any other branch
10004 if {![confirm_popup [mc "The commits on branch %s aren't on any other\
10005 branch.\nReally delete branch %s?" $head $head]]} return
Paul Mackerras10299152006-08-02 09:52:01 +100010006 }
10007 nowbusy rmbranch
10008 update
10009 if {[catch {exec git branch -D $head} err]} {
Denton Liue2445882020-09-10 21:36:33 -070010010 notbusy rmbranch
10011 error_popup $err
10012 return
Paul Mackerras10299152006-08-02 09:52:01 +100010013 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010014 removehead $id $head
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100010015 removedhead $id $head
Paul Mackerras10299152006-08-02 09:52:01 +100010016 redrawtags $id
10017 notbusy rmbranch
Paul Mackerrase11f1232007-06-16 20:29:25 +100010018 dispneartags 0
Paul Mackerras887c9962007-08-20 19:36:20 +100010019 run refill_reflist
10020}
10021
10022# Display a list of tags and heads
10023proc showrefs {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +010010024 global showrefstop bgcolor fgcolor selectbgcolor NS
Paul Mackerras9c311b32007-10-04 22:27:13 +100010025 global bglist fglist reflistfilter reflist maincursor
Paul Mackerras887c9962007-08-20 19:36:20 +100010026
10027 set top .showrefs
10028 set showrefstop $top
10029 if {[winfo exists $top]} {
Denton Liue2445882020-09-10 21:36:33 -070010030 raise $top
10031 refill_reflist
10032 return
Paul Mackerras887c9962007-08-20 19:36:20 +100010033 }
Pat Thoytsd93f1712009-04-17 01:24:35 +010010034 ttk_toplevel $top
Christian Stimmingd990ced2007-11-07 18:42:55 +010010035 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]]
Alexander Gavrilove7d64002008-11-11 23:55:42 +030010036 make_transient $top .
Paul Mackerras887c9962007-08-20 19:36:20 +100010037 text $top.list -background $bgcolor -foreground $fgcolor \
Denton Liue2445882020-09-10 21:36:33 -070010038 -selectbackground $selectbgcolor -font mainfont \
10039 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
10040 -width 30 -height 20 -cursor $maincursor \
10041 -spacing1 1 -spacing3 1 -state disabled
Paul Mackerras887c9962007-08-20 19:36:20 +100010042 $top.list tag configure highlight -background $selectbgcolor
Paul Mackerraseb859df2015-05-03 15:11:29 +100010043 if {![lsearch -exact $bglist $top.list]} {
Denton Liue2445882020-09-10 21:36:33 -070010044 lappend bglist $top.list
10045 lappend fglist $top.list
Paul Mackerraseb859df2015-05-03 15:11:29 +100010046 }
Pat Thoytsd93f1712009-04-17 01:24:35 +010010047 ${NS}::scrollbar $top.ysb -command "$top.list yview" -orient vertical
10048 ${NS}::scrollbar $top.xsb -command "$top.list xview" -orient horizontal
Paul Mackerras887c9962007-08-20 19:36:20 +100010049 grid $top.list $top.ysb -sticky nsew
10050 grid $top.xsb x -sticky ew
Pat Thoytsd93f1712009-04-17 01:24:35 +010010051 ${NS}::frame $top.f
10052 ${NS}::label $top.f.l -text "[mc "Filter"]: "
10053 ${NS}::entry $top.f.e -width 20 -textvariable reflistfilter
Paul Mackerras887c9962007-08-20 19:36:20 +100010054 set reflistfilter "*"
10055 trace add variable reflistfilter write reflistfilter_change
10056 pack $top.f.e -side right -fill x -expand 1
10057 pack $top.f.l -side left
10058 grid $top.f - -sticky ew -pady 2
Pat Thoytsd93f1712009-04-17 01:24:35 +010010059 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
Alexander Gavrilov76f15942008-11-02 21:59:44 +030010060 bind $top <Key-Escape> [list destroy $top]
Paul Mackerras887c9962007-08-20 19:36:20 +100010061 grid $top.close -
10062 grid columnconfigure $top 0 -weight 1
10063 grid rowconfigure $top 0 -weight 1
10064 bind $top.list <1> {break}
10065 bind $top.list <B1-Motion> {break}
10066 bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
10067 set reflist {}
10068 refill_reflist
10069}
10070
10071proc sel_reflist {w x y} {
10072 global showrefstop reflist headids tagids otherrefids
10073
10074 if {![winfo exists $showrefstop]} return
10075 set l [lindex [split [$w index "@$x,$y"] "."] 0]
10076 set ref [lindex $reflist [expr {$l-1}]]
10077 set n [lindex $ref 0]
10078 switch -- [lindex $ref 1] {
Denton Liue2445882020-09-10 21:36:33 -070010079 "H" {selbyid $headids($n)}
10080 "R" {selbyid $headids($n)}
10081 "T" {selbyid $tagids($n)}
10082 "o" {selbyid $otherrefids($n)}
Paul Mackerras887c9962007-08-20 19:36:20 +100010083 }
10084 $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
10085}
10086
10087proc unsel_reflist {} {
10088 global showrefstop
10089
10090 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
10091 $showrefstop.list tag remove highlight 0.0 end
10092}
10093
10094proc reflistfilter_change {n1 n2 op} {
10095 global reflistfilter
10096
10097 after cancel refill_reflist
10098 after 200 refill_reflist
10099}
10100
10101proc refill_reflist {} {
10102 global reflist reflistfilter showrefstop headids tagids otherrefids
Paul Mackerrasd375ef92008-10-21 10:18:12 +110010103 global curview
Paul Mackerras887c9962007-08-20 19:36:20 +100010104
10105 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
10106 set refs {}
10107 foreach n [array names headids] {
Denton Liue2445882020-09-10 21:36:33 -070010108 if {[string match $reflistfilter $n]} {
10109 if {[commitinview $headids($n) $curview]} {
10110 if {[string match "remotes/*" $n]} {
10111 lappend refs [list $n R]
10112 } else {
10113 lappend refs [list $n H]
10114 }
10115 } else {
10116 interestedin $headids($n) {run refill_reflist}
10117 }
10118 }
Paul Mackerras887c9962007-08-20 19:36:20 +100010119 }
10120 foreach n [array names tagids] {
Denton Liue2445882020-09-10 21:36:33 -070010121 if {[string match $reflistfilter $n]} {
10122 if {[commitinview $tagids($n) $curview]} {
10123 lappend refs [list $n T]
10124 } else {
10125 interestedin $tagids($n) {run refill_reflist}
10126 }
10127 }
Paul Mackerras887c9962007-08-20 19:36:20 +100010128 }
10129 foreach n [array names otherrefids] {
Denton Liue2445882020-09-10 21:36:33 -070010130 if {[string match $reflistfilter $n]} {
10131 if {[commitinview $otherrefids($n) $curview]} {
10132 lappend refs [list $n o]
10133 } else {
10134 interestedin $otherrefids($n) {run refill_reflist}
10135 }
10136 }
Paul Mackerras887c9962007-08-20 19:36:20 +100010137 }
10138 set refs [lsort -index 0 $refs]
10139 if {$refs eq $reflist} return
10140
10141 # Update the contents of $showrefstop.list according to the
10142 # differences between $reflist (old) and $refs (new)
10143 $showrefstop.list conf -state normal
10144 $showrefstop.list insert end "\n"
10145 set i 0
10146 set j 0
10147 while {$i < [llength $reflist] || $j < [llength $refs]} {
Denton Liue2445882020-09-10 21:36:33 -070010148 if {$i < [llength $reflist]} {
10149 if {$j < [llength $refs]} {
10150 set cmp [string compare [lindex $reflist $i 0] \
10151 [lindex $refs $j 0]]
10152 if {$cmp == 0} {
10153 set cmp [string compare [lindex $reflist $i 1] \
10154 [lindex $refs $j 1]]
10155 }
10156 } else {
10157 set cmp -1
10158 }
10159 } else {
10160 set cmp 1
10161 }
10162 switch -- $cmp {
10163 -1 {
10164 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
10165 incr i
10166 }
10167 0 {
10168 incr i
10169 incr j
10170 }
10171 1 {
10172 set l [expr {$j + 1}]
10173 $showrefstop.list image create $l.0 -align baseline \
10174 -image reficon-[lindex $refs $j 1] -padx 2
10175 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
10176 incr j
10177 }
10178 }
Paul Mackerras887c9962007-08-20 19:36:20 +100010179 }
10180 set reflist $refs
10181 # delete last newline
10182 $showrefstop.list delete end-2c end-1c
10183 $showrefstop.list conf -state disabled
Paul Mackerras10299152006-08-02 09:52:01 +100010184}
10185
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010186# Stuff for finding nearby tags
10187proc getallcommits {} {
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010188 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate
10189 global idheads idtags idotherrefs allparents tagobjid
Martin von Zweigbergkda616db2011-04-04 22:14:17 -040010190 global gitdir
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100010191
Paul Mackerrasa69b2d12007-08-13 15:02:02 +100010192 if {![info exists allcommits]} {
Denton Liue2445882020-09-10 21:36:33 -070010193 set nextarc 0
10194 set allcommits 0
10195 set seeds {}
10196 set allcwait 0
10197 set cachedarcs 0
10198 set allccache [file join $gitdir "gitk.cache"]
10199 if {![catch {
10200 set f [open $allccache r]
10201 set allcwait 1
10202 getcache $f
10203 }]} return
Paul Mackerrasa69b2d12007-08-13 15:02:02 +100010204 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010205
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010206 if {$allcwait} {
Denton Liue2445882020-09-10 21:36:33 -070010207 return
Paul Mackerrase11f1232007-06-16 20:29:25 +100010208 }
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010209 set cmd [list | git rev-list --parents]
10210 set allcupdate [expr {$seeds ne {}}]
10211 if {!$allcupdate} {
Denton Liue2445882020-09-10 21:36:33 -070010212 set ids "--all"
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010213 } else {
Denton Liue2445882020-09-10 21:36:33 -070010214 set refs [concat [array names idheads] [array names idtags] \
10215 [array names idotherrefs]]
10216 set ids {}
10217 set tagobjs {}
10218 foreach name [array names tagobjid] {
10219 lappend tagobjs $tagobjid($name)
10220 }
10221 foreach id [lsort -unique $refs] {
10222 if {![info exists allparents($id)] &&
10223 [lsearch -exact $tagobjs $id] < 0} {
10224 lappend ids $id
10225 }
10226 }
10227 if {$ids ne {}} {
10228 foreach id $seeds {
10229 lappend ids "^$id"
10230 }
10231 }
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010232 }
10233 if {$ids ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070010234 set fd [open [concat $cmd $ids] r]
10235 fconfigure $fd -blocking 0
10236 incr allcommits
10237 nowbusy allcommits
10238 filerun $fd [list getallclines $fd]
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010239 } else {
Denton Liue2445882020-09-10 21:36:33 -070010240 dispneartags 0
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010241 }
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010242}
10243
Paul Mackerrase11f1232007-06-16 20:29:25 +100010244# Since most commits have 1 parent and 1 child, we group strings of
10245# such commits into "arcs" joining branch/merge points (BMPs), which
10246# are commits that either don't have 1 parent or don't have 1 child.
10247#
10248# arcnos(id) - incoming arcs for BMP, arc we're on for other nodes
10249# arcout(id) - outgoing arcs for BMP
10250# arcids(a) - list of IDs on arc including end but not start
10251# arcstart(a) - BMP ID at start of arc
10252# arcend(a) - BMP ID at end of arc
10253# growing(a) - arc a is still growing
10254# arctags(a) - IDs out of arcids (excluding end) that have tags
10255# archeads(a) - IDs out of arcids (excluding end) that have heads
10256# The start of an arc is at the descendent end, so "incoming" means
10257# coming from descendents, and "outgoing" means going towards ancestors.
Paul Mackerrascec7bec2006-08-02 09:38:10 +100010258
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010259proc getallclines {fd} {
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010260 global allparents allchildren idtags idheads nextarc
Paul Mackerrase11f1232007-06-16 20:29:25 +100010261 global arcnos arcids arctags arcout arcend arcstart archeads growing
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010262 global seeds allcommits cachedarcs allcupdate
Pat Thoytsd93f1712009-04-17 01:24:35 +010010263
Paul Mackerrase11f1232007-06-16 20:29:25 +100010264 set nid 0
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100010265 while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
Denton Liue2445882020-09-10 21:36:33 -070010266 set id [lindex $line 0]
10267 if {[info exists allparents($id)]} {
10268 # seen it already
10269 continue
10270 }
10271 set cachedarcs 0
10272 set olds [lrange $line 1 end]
10273 set allparents($id) $olds
10274 if {![info exists allchildren($id)]} {
10275 set allchildren($id) {}
10276 set arcnos($id) {}
10277 lappend seeds $id
10278 } else {
10279 set a $arcnos($id)
10280 if {[llength $olds] == 1 && [llength $a] == 1} {
10281 lappend arcids($a) $id
10282 if {[info exists idtags($id)]} {
10283 lappend arctags($a) $id
10284 }
10285 if {[info exists idheads($id)]} {
10286 lappend archeads($a) $id
10287 }
10288 if {[info exists allparents($olds)]} {
10289 # seen parent already
10290 if {![info exists arcout($olds)]} {
10291 splitarc $olds
10292 }
10293 lappend arcids($a) $olds
10294 set arcend($a) $olds
10295 unset growing($a)
10296 }
10297 lappend allchildren($olds) $id
10298 lappend arcnos($olds) $a
10299 continue
10300 }
10301 }
10302 foreach a $arcnos($id) {
10303 lappend arcids($a) $id
10304 set arcend($a) $id
10305 unset growing($a)
10306 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010307
Denton Liue2445882020-09-10 21:36:33 -070010308 set ao {}
10309 foreach p $olds {
10310 lappend allchildren($p) $id
10311 set a [incr nextarc]
10312 set arcstart($a) $id
10313 set archeads($a) {}
10314 set arctags($a) {}
10315 set archeads($a) {}
10316 set arcids($a) {}
10317 lappend ao $a
10318 set growing($a) 1
10319 if {[info exists allparents($p)]} {
10320 # seen it already, may need to make a new branch
10321 if {![info exists arcout($p)]} {
10322 splitarc $p
10323 }
10324 lappend arcids($a) $p
10325 set arcend($a) $p
10326 unset growing($a)
10327 }
10328 lappend arcnos($p) $a
10329 }
10330 set arcout($id) $ao
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100010331 }
Paul Mackerrasf3326b62007-06-18 22:39:21 +100010332 if {$nid > 0} {
Denton Liue2445882020-09-10 21:36:33 -070010333 global cached_dheads cached_dtags cached_atags
10334 unset -nocomplain cached_dheads
10335 unset -nocomplain cached_dtags
10336 unset -nocomplain cached_atags
Paul Mackerrasf3326b62007-06-18 22:39:21 +100010337 }
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100010338 if {![eof $fd]} {
Denton Liue2445882020-09-10 21:36:33 -070010339 return [expr {$nid >= 1000? 2: 1}]
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100010340 }
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010341 set cacheok 1
10342 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -070010343 fconfigure $fd -blocking 1
10344 close $fd
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010345 } err]} {
Denton Liue2445882020-09-10 21:36:33 -070010346 # got an error reading the list of commits
10347 # if we were updating, try rereading the whole thing again
10348 if {$allcupdate} {
10349 incr allcommits -1
10350 dropcache $err
10351 return
10352 }
10353 error_popup "[mc "Error reading commit topology information;\
10354 branch and preceding/following tag information\
10355 will be incomplete."]\n($err)"
10356 set cacheok 0
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010357 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010358 if {[incr allcommits -1] == 0} {
Denton Liue2445882020-09-10 21:36:33 -070010359 notbusy allcommits
10360 if {$cacheok} {
10361 run savecache
10362 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010363 }
10364 dispneartags 0
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100010365 return 0
Paul Mackerrase11f1232007-06-16 20:29:25 +100010366}
10367
10368proc recalcarc {a} {
10369 global arctags archeads arcids idtags idheads
10370
10371 set at {}
10372 set ah {}
10373 foreach id [lrange $arcids($a) 0 end-1] {
Denton Liue2445882020-09-10 21:36:33 -070010374 if {[info exists idtags($id)]} {
10375 lappend at $id
10376 }
10377 if {[info exists idheads($id)]} {
10378 lappend ah $id
10379 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010380 }
10381 set arctags($a) $at
10382 set archeads($a) $ah
10383}
10384
10385proc splitarc {p} {
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010386 global arcnos arcids nextarc arctags archeads idtags idheads
Paul Mackerrase11f1232007-06-16 20:29:25 +100010387 global arcstart arcend arcout allparents growing
10388
10389 set a $arcnos($p)
10390 if {[llength $a] != 1} {
Denton Liue2445882020-09-10 21:36:33 -070010391 puts "oops splitarc called but [llength $a] arcs already"
10392 return
Paul Mackerrase11f1232007-06-16 20:29:25 +100010393 }
10394 set a [lindex $a 0]
10395 set i [lsearch -exact $arcids($a) $p]
10396 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -070010397 puts "oops splitarc $p not in arc $a"
10398 return
Paul Mackerrase11f1232007-06-16 20:29:25 +100010399 }
10400 set na [incr nextarc]
10401 if {[info exists arcend($a)]} {
Denton Liue2445882020-09-10 21:36:33 -070010402 set arcend($na) $arcend($a)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010403 } else {
Denton Liue2445882020-09-10 21:36:33 -070010404 set l [lindex $allparents([lindex $arcids($a) end]) 0]
10405 set j [lsearch -exact $arcnos($l) $a]
10406 set arcnos($l) [lreplace $arcnos($l) $j $j $na]
Paul Mackerrase11f1232007-06-16 20:29:25 +100010407 }
10408 set tail [lrange $arcids($a) [expr {$i+1}] end]
10409 set arcids($a) [lrange $arcids($a) 0 $i]
10410 set arcend($a) $p
10411 set arcstart($na) $p
10412 set arcout($p) $na
10413 set arcids($na) $tail
10414 if {[info exists growing($a)]} {
Denton Liue2445882020-09-10 21:36:33 -070010415 set growing($na) 1
10416 unset growing($a)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010417 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010418
10419 foreach id $tail {
Denton Liue2445882020-09-10 21:36:33 -070010420 if {[llength $arcnos($id)] == 1} {
10421 set arcnos($id) $na
10422 } else {
10423 set j [lsearch -exact $arcnos($id) $a]
10424 set arcnos($id) [lreplace $arcnos($id) $j $j $na]
10425 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010426 }
10427
10428 # reconstruct tags and heads lists
10429 if {$arctags($a) ne {} || $archeads($a) ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070010430 recalcarc $a
10431 recalcarc $na
Paul Mackerrase11f1232007-06-16 20:29:25 +100010432 } else {
Denton Liue2445882020-09-10 21:36:33 -070010433 set arctags($na) {}
10434 set archeads($na) {}
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010435 }
10436}
10437
Paul Mackerrase11f1232007-06-16 20:29:25 +100010438# Update things for a new commit added that is a child of one
10439# existing commit. Used when cherry-picking.
10440proc addnewchild {id p} {
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010441 global allparents allchildren idtags nextarc
Paul Mackerrase11f1232007-06-16 20:29:25 +100010442 global arcnos arcids arctags arcout arcend arcstart archeads growing
Paul Mackerras719c2b92007-08-29 22:41:34 +100010443 global seeds allcommits
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010444
Paul Mackerras3ebba3c2007-10-20 22:10:52 +100010445 if {![info exists allcommits] || ![info exists arcnos($p)]} return
Paul Mackerrase11f1232007-06-16 20:29:25 +100010446 set allparents($id) [list $p]
10447 set allchildren($id) {}
10448 set arcnos($id) {}
10449 lappend seeds $id
Paul Mackerrase11f1232007-06-16 20:29:25 +100010450 lappend allchildren($p) $id
10451 set a [incr nextarc]
10452 set arcstart($a) $id
10453 set archeads($a) {}
10454 set arctags($a) {}
10455 set arcids($a) [list $p]
10456 set arcend($a) $p
10457 if {![info exists arcout($p)]} {
Denton Liue2445882020-09-10 21:36:33 -070010458 splitarc $p
Paul Mackerrase11f1232007-06-16 20:29:25 +100010459 }
10460 lappend arcnos($p) $a
10461 set arcout($id) [list $a]
10462}
10463
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010464# This implements a cache for the topology information.
10465# The cache saves, for each arc, the start and end of the arc,
10466# the ids on the arc, and the outgoing arcs from the end.
10467proc readcache {f} {
10468 global arcnos arcids arcout arcstart arcend arctags archeads nextarc
10469 global idtags idheads allparents cachedarcs possible_seeds seeds growing
10470 global allcwait
10471
10472 set a $nextarc
10473 set lim $cachedarcs
10474 if {$lim - $a > 500} {
Denton Liue2445882020-09-10 21:36:33 -070010475 set lim [expr {$a + 500}]
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010476 }
10477 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -070010478 if {$a == $lim} {
10479 # finish reading the cache and setting up arctags, etc.
10480 set line [gets $f]
10481 if {$line ne "1"} {error "bad final version"}
10482 close $f
10483 foreach id [array names idtags] {
10484 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10485 [llength $allparents($id)] == 1} {
10486 set a [lindex $arcnos($id) 0]
10487 if {$arctags($a) eq {}} {
10488 recalcarc $a
10489 }
10490 }
10491 }
10492 foreach id [array names idheads] {
10493 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 &&
10494 [llength $allparents($id)] == 1} {
10495 set a [lindex $arcnos($id) 0]
10496 if {$archeads($a) eq {}} {
10497 recalcarc $a
10498 }
10499 }
10500 }
10501 foreach id [lsort -unique $possible_seeds] {
10502 if {$arcnos($id) eq {}} {
10503 lappend seeds $id
10504 }
10505 }
10506 set allcwait 0
10507 } else {
10508 while {[incr a] <= $lim} {
10509 set line [gets $f]
10510 if {[llength $line] != 3} {error "bad line"}
10511 set s [lindex $line 0]
10512 set arcstart($a) $s
10513 lappend arcout($s) $a
10514 if {![info exists arcnos($s)]} {
10515 lappend possible_seeds $s
10516 set arcnos($s) {}
10517 }
10518 set e [lindex $line 1]
10519 if {$e eq {}} {
10520 set growing($a) 1
10521 } else {
10522 set arcend($a) $e
10523 if {![info exists arcout($e)]} {
10524 set arcout($e) {}
10525 }
10526 }
10527 set arcids($a) [lindex $line 2]
10528 foreach id $arcids($a) {
10529 lappend allparents($s) $id
10530 set s $id
10531 lappend arcnos($id) $a
10532 }
10533 if {![info exists allparents($s)]} {
10534 set allparents($s) {}
10535 }
10536 set arctags($a) {}
10537 set archeads($a) {}
10538 }
10539 set nextarc [expr {$a - 1}]
10540 }
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010541 } err]} {
Denton Liue2445882020-09-10 21:36:33 -070010542 dropcache $err
10543 return 0
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010544 }
10545 if {!$allcwait} {
Denton Liue2445882020-09-10 21:36:33 -070010546 getallcommits
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010547 }
10548 return $allcwait
10549}
10550
10551proc getcache {f} {
10552 global nextarc cachedarcs possible_seeds
10553
10554 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -070010555 set line [gets $f]
10556 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"}
10557 # make sure it's an integer
10558 set cachedarcs [expr {int([lindex $line 1])}]
10559 if {$cachedarcs < 0} {error "bad number of arcs"}
10560 set nextarc 0
10561 set possible_seeds {}
10562 run readcache $f
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010563 } err]} {
Denton Liue2445882020-09-10 21:36:33 -070010564 dropcache $err
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010565 }
10566 return 0
10567}
10568
10569proc dropcache {err} {
10570 global allcwait nextarc cachedarcs seeds
10571
10572 #puts "dropping cache ($err)"
10573 foreach v {arcnos arcout arcids arcstart arcend growing \
Denton Liue2445882020-09-10 21:36:33 -070010574 arctags archeads allparents allchildren} {
10575 global $v
10576 unset -nocomplain $v
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010577 }
10578 set allcwait 0
10579 set nextarc 0
10580 set cachedarcs 0
10581 set seeds {}
10582 getallcommits
10583}
10584
10585proc writecache {f} {
10586 global cachearc cachedarcs allccache
10587 global arcstart arcend arcnos arcids arcout
10588
10589 set a $cachearc
10590 set lim $cachedarcs
10591 if {$lim - $a > 1000} {
Denton Liue2445882020-09-10 21:36:33 -070010592 set lim [expr {$a + 1000}]
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010593 }
10594 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -070010595 while {[incr a] <= $lim} {
10596 if {[info exists arcend($a)]} {
10597 puts $f [list $arcstart($a) $arcend($a) $arcids($a)]
10598 } else {
10599 puts $f [list $arcstart($a) {} $arcids($a)]
10600 }
10601 }
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010602 } err]} {
Denton Liue2445882020-09-10 21:36:33 -070010603 catch {close $f}
10604 catch {file delete $allccache}
10605 #puts "writing cache failed ($err)"
10606 return 0
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010607 }
10608 set cachearc [expr {$a - 1}]
10609 if {$a > $cachedarcs} {
Denton Liue2445882020-09-10 21:36:33 -070010610 puts $f "1"
10611 close $f
10612 return 0
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010613 }
10614 return 1
10615}
10616
10617proc savecache {} {
10618 global nextarc cachedarcs cachearc allccache
10619
10620 if {$nextarc == $cachedarcs} return
10621 set cachearc 0
10622 set cachedarcs $nextarc
10623 catch {
Denton Liue2445882020-09-10 21:36:33 -070010624 set f [open $allccache w]
10625 puts $f [list 1 $cachedarcs]
10626 run writecache $f
Paul Mackerras5cd15b62007-08-30 21:54:17 +100010627 }
10628}
10629
Paul Mackerrase11f1232007-06-16 20:29:25 +100010630# Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a,
10631# or 0 if neither is true.
10632proc anc_or_desc {a b} {
10633 global arcout arcstart arcend arcnos cached_isanc
10634
10635 if {$arcnos($a) eq $arcnos($b)} {
Denton Liue2445882020-09-10 21:36:33 -070010636 # Both are on the same arc(s); either both are the same BMP,
10637 # or if one is not a BMP, the other is also not a BMP or is
10638 # the BMP at end of the arc (and it only has 1 incoming arc).
10639 # Or both can be BMPs with no incoming arcs.
10640 if {$a eq $b || $arcnos($a) eq {}} {
10641 return 0
10642 }
10643 # assert {[llength $arcnos($a)] == 1}
10644 set arc [lindex $arcnos($a) 0]
10645 set i [lsearch -exact $arcids($arc) $a]
10646 set j [lsearch -exact $arcids($arc) $b]
10647 if {$i < 0 || $i > $j} {
10648 return 1
10649 } else {
10650 return -1
10651 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010652 }
10653
10654 if {![info exists arcout($a)]} {
Denton Liue2445882020-09-10 21:36:33 -070010655 set arc [lindex $arcnos($a) 0]
10656 if {[info exists arcend($arc)]} {
10657 set aend $arcend($arc)
10658 } else {
10659 set aend {}
10660 }
10661 set a $arcstart($arc)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010662 } else {
Denton Liue2445882020-09-10 21:36:33 -070010663 set aend $a
Paul Mackerrase11f1232007-06-16 20:29:25 +100010664 }
10665 if {![info exists arcout($b)]} {
Denton Liue2445882020-09-10 21:36:33 -070010666 set arc [lindex $arcnos($b) 0]
10667 if {[info exists arcend($arc)]} {
10668 set bend $arcend($arc)
10669 } else {
10670 set bend {}
10671 }
10672 set b $arcstart($arc)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010673 } else {
Denton Liue2445882020-09-10 21:36:33 -070010674 set bend $b
Paul Mackerrase11f1232007-06-16 20:29:25 +100010675 }
10676 if {$a eq $bend} {
Denton Liue2445882020-09-10 21:36:33 -070010677 return 1
Paul Mackerrase11f1232007-06-16 20:29:25 +100010678 }
10679 if {$b eq $aend} {
Denton Liue2445882020-09-10 21:36:33 -070010680 return -1
Paul Mackerrase11f1232007-06-16 20:29:25 +100010681 }
10682 if {[info exists cached_isanc($a,$bend)]} {
Denton Liue2445882020-09-10 21:36:33 -070010683 if {$cached_isanc($a,$bend)} {
10684 return 1
10685 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010686 }
10687 if {[info exists cached_isanc($b,$aend)]} {
Denton Liue2445882020-09-10 21:36:33 -070010688 if {$cached_isanc($b,$aend)} {
10689 return -1
10690 }
10691 if {[info exists cached_isanc($a,$bend)]} {
10692 return 0
10693 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010694 }
10695
10696 set todo [list $a $b]
10697 set anc($a) a
10698 set anc($b) b
10699 for {set i 0} {$i < [llength $todo]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070010700 set x [lindex $todo $i]
10701 if {$anc($x) eq {}} {
10702 continue
10703 }
10704 foreach arc $arcnos($x) {
10705 set xd $arcstart($arc)
10706 if {$xd eq $bend} {
10707 set cached_isanc($a,$bend) 1
10708 set cached_isanc($b,$aend) 0
10709 return 1
10710 } elseif {$xd eq $aend} {
10711 set cached_isanc($b,$aend) 1
10712 set cached_isanc($a,$bend) 0
10713 return -1
10714 }
10715 if {![info exists anc($xd)]} {
10716 set anc($xd) $anc($x)
10717 lappend todo $xd
10718 } elseif {$anc($xd) ne $anc($x)} {
10719 set anc($xd) {}
10720 }
10721 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010722 }
10723 set cached_isanc($a,$bend) 0
10724 set cached_isanc($b,$aend) 0
10725 return 0
10726}
10727
10728# This identifies whether $desc has an ancestor that is
10729# a growing tip of the graph and which is not an ancestor of $anc
10730# and returns 0 if so and 1 if not.
10731# If we subsequently discover a tag on such a growing tip, and that
10732# turns out to be a descendent of $anc (which it could, since we
10733# don't necessarily see children before parents), then $desc
10734# isn't a good choice to display as a descendent tag of
10735# $anc (since it is the descendent of another tag which is
10736# a descendent of $anc). Similarly, $anc isn't a good choice to
10737# display as a ancestor tag of $desc.
10738#
10739proc is_certain {desc anc} {
10740 global arcnos arcout arcstart arcend growing problems
10741
10742 set certain {}
10743 if {[llength $arcnos($anc)] == 1} {
Denton Liue2445882020-09-10 21:36:33 -070010744 # tags on the same arc are certain
10745 if {$arcnos($desc) eq $arcnos($anc)} {
10746 return 1
10747 }
10748 if {![info exists arcout($anc)]} {
10749 # if $anc is partway along an arc, use the start of the arc instead
10750 set a [lindex $arcnos($anc) 0]
10751 set anc $arcstart($a)
10752 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010753 }
10754 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} {
Denton Liue2445882020-09-10 21:36:33 -070010755 set x $desc
Paul Mackerrase11f1232007-06-16 20:29:25 +100010756 } else {
Denton Liue2445882020-09-10 21:36:33 -070010757 set a [lindex $arcnos($desc) 0]
10758 set x $arcend($a)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010759 }
10760 if {$x == $anc} {
Denton Liue2445882020-09-10 21:36:33 -070010761 return 1
Paul Mackerrase11f1232007-06-16 20:29:25 +100010762 }
10763 set anclist [list $x]
10764 set dl($x) 1
10765 set nnh 1
10766 set ngrowanc 0
10767 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070010768 set x [lindex $anclist $i]
10769 if {$dl($x)} {
10770 incr nnh -1
10771 }
10772 set done($x) 1
10773 foreach a $arcout($x) {
10774 if {[info exists growing($a)]} {
10775 if {![info exists growanc($x)] && $dl($x)} {
10776 set growanc($x) 1
10777 incr ngrowanc
10778 }
10779 } else {
10780 set y $arcend($a)
10781 if {[info exists dl($y)]} {
10782 if {$dl($y)} {
10783 if {!$dl($x)} {
10784 set dl($y) 0
10785 if {![info exists done($y)]} {
10786 incr nnh -1
10787 }
10788 if {[info exists growanc($x)]} {
10789 incr ngrowanc -1
10790 }
10791 set xl [list $y]
10792 for {set k 0} {$k < [llength $xl]} {incr k} {
10793 set z [lindex $xl $k]
10794 foreach c $arcout($z) {
10795 if {[info exists arcend($c)]} {
10796 set v $arcend($c)
10797 if {[info exists dl($v)] && $dl($v)} {
10798 set dl($v) 0
10799 if {![info exists done($v)]} {
10800 incr nnh -1
10801 }
10802 if {[info exists growanc($v)]} {
10803 incr ngrowanc -1
10804 }
10805 lappend xl $v
10806 }
10807 }
10808 }
10809 }
10810 }
10811 }
10812 } elseif {$y eq $anc || !$dl($x)} {
10813 set dl($y) 0
10814 lappend anclist $y
10815 } else {
10816 set dl($y) 1
10817 lappend anclist $y
10818 incr nnh
10819 }
10820 }
10821 }
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100010822 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010823 foreach x [array names growanc] {
Denton Liue2445882020-09-10 21:36:33 -070010824 if {$dl($x)} {
10825 return 0
10826 }
10827 return 0
Paul Mackerrase11f1232007-06-16 20:29:25 +100010828 }
10829 return 1
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100010830}
10831
Paul Mackerrase11f1232007-06-16 20:29:25 +100010832proc validate_arctags {a} {
10833 global arctags idtags
10834
10835 set i -1
10836 set na $arctags($a)
10837 foreach id $arctags($a) {
Denton Liue2445882020-09-10 21:36:33 -070010838 incr i
10839 if {![info exists idtags($id)]} {
10840 set na [lreplace $na $i $i]
10841 incr i -1
10842 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010843 }
10844 set arctags($a) $na
10845}
10846
10847proc validate_archeads {a} {
10848 global archeads idheads
10849
10850 set i -1
10851 set na $archeads($a)
10852 foreach id $archeads($a) {
Denton Liue2445882020-09-10 21:36:33 -070010853 incr i
10854 if {![info exists idheads($id)]} {
10855 set na [lreplace $na $i $i]
10856 incr i -1
10857 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010858 }
10859 set archeads($a) $na
10860}
10861
10862# Return the list of IDs that have tags that are descendents of id,
10863# ignoring IDs that are descendents of IDs already reported.
10864proc desctags {id} {
10865 global arcnos arcstart arcids arctags idtags allparents
10866 global growing cached_dtags
10867
10868 if {![info exists allparents($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070010869 return {}
Paul Mackerrase11f1232007-06-16 20:29:25 +100010870 }
10871 set t1 [clock clicks -milliseconds]
10872 set argid $id
10873 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
Denton Liue2445882020-09-10 21:36:33 -070010874 # part-way along an arc; check that arc first
10875 set a [lindex $arcnos($id) 0]
10876 if {$arctags($a) ne {}} {
10877 validate_arctags $a
10878 set i [lsearch -exact $arcids($a) $id]
10879 set tid {}
10880 foreach t $arctags($a) {
10881 set j [lsearch -exact $arcids($a) $t]
10882 if {$j >= $i} break
10883 set tid $t
10884 }
10885 if {$tid ne {}} {
10886 return $tid
10887 }
10888 }
10889 set id $arcstart($a)
10890 if {[info exists idtags($id)]} {
10891 return $id
10892 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010893 }
10894 if {[info exists cached_dtags($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070010895 return $cached_dtags($id)
Paul Mackerrase11f1232007-06-16 20:29:25 +100010896 }
10897
10898 set origid $id
10899 set todo [list $id]
10900 set queued($id) 1
10901 set nc 1
10902 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070010903 set id [lindex $todo $i]
10904 set done($id) 1
10905 set ta [info exists hastaggedancestor($id)]
10906 if {!$ta} {
10907 incr nc -1
10908 }
10909 # ignore tags on starting node
10910 if {!$ta && $i > 0} {
10911 if {[info exists idtags($id)]} {
10912 set tagloc($id) $id
10913 set ta 1
10914 } elseif {[info exists cached_dtags($id)]} {
10915 set tagloc($id) $cached_dtags($id)
10916 set ta 1
10917 }
10918 }
10919 foreach a $arcnos($id) {
10920 set d $arcstart($a)
10921 if {!$ta && $arctags($a) ne {}} {
10922 validate_arctags $a
10923 if {$arctags($a) ne {}} {
10924 lappend tagloc($id) [lindex $arctags($a) end]
10925 }
10926 }
10927 if {$ta || $arctags($a) ne {}} {
10928 set tomark [list $d]
10929 for {set j 0} {$j < [llength $tomark]} {incr j} {
10930 set dd [lindex $tomark $j]
10931 if {![info exists hastaggedancestor($dd)]} {
10932 if {[info exists done($dd)]} {
10933 foreach b $arcnos($dd) {
10934 lappend tomark $arcstart($b)
10935 }
10936 if {[info exists tagloc($dd)]} {
10937 unset tagloc($dd)
10938 }
10939 } elseif {[info exists queued($dd)]} {
10940 incr nc -1
10941 }
10942 set hastaggedancestor($dd) 1
10943 }
10944 }
10945 }
10946 if {![info exists queued($d)]} {
10947 lappend todo $d
10948 set queued($d) 1
10949 if {![info exists hastaggedancestor($d)]} {
10950 incr nc
10951 }
10952 }
10953 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010954 }
10955 set tags {}
10956 foreach id [array names tagloc] {
Denton Liue2445882020-09-10 21:36:33 -070010957 if {![info exists hastaggedancestor($id)]} {
10958 foreach t $tagloc($id) {
10959 if {[lsearch -exact $tags $t] < 0} {
10960 lappend tags $t
10961 }
10962 }
10963 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010964 }
10965 set t2 [clock clicks -milliseconds]
10966 set loopix $i
10967
10968 # remove tags that are descendents of other tags
10969 for {set i 0} {$i < [llength $tags]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070010970 set a [lindex $tags $i]
10971 for {set j 0} {$j < $i} {incr j} {
10972 set b [lindex $tags $j]
10973 set r [anc_or_desc $a $b]
10974 if {$r == 1} {
10975 set tags [lreplace $tags $j $j]
10976 incr j -1
10977 incr i -1
10978 } elseif {$r == -1} {
10979 set tags [lreplace $tags $i $i]
10980 incr i -1
10981 break
10982 }
10983 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100010984 }
10985
10986 if {[array names growing] ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070010987 # graph isn't finished, need to check if any tag could get
10988 # eclipsed by another tag coming later. Simply ignore any
10989 # tags that could later get eclipsed.
10990 set ctags {}
10991 foreach t $tags {
10992 if {[is_certain $t $origid]} {
10993 lappend ctags $t
10994 }
10995 }
10996 if {$tags eq $ctags} {
10997 set cached_dtags($origid) $tags
10998 } else {
10999 set tags $ctags
11000 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011001 } else {
Denton Liue2445882020-09-10 21:36:33 -070011002 set cached_dtags($origid) $tags
Paul Mackerrase11f1232007-06-16 20:29:25 +100011003 }
11004 set t3 [clock clicks -milliseconds]
11005 if {0 && $t3 - $t1 >= 100} {
Denton Liue2445882020-09-10 21:36:33 -070011006 puts "iterating descendents ($loopix/[llength $todo] nodes) took\
11007 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
Paul Mackerrase11f1232007-06-16 20:29:25 +100011008 }
11009 return $tags
11010}
11011
11012proc anctags {id} {
11013 global arcnos arcids arcout arcend arctags idtags allparents
11014 global growing cached_atags
11015
11016 if {![info exists allparents($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011017 return {}
Paul Mackerrase11f1232007-06-16 20:29:25 +100011018 }
11019 set t1 [clock clicks -milliseconds]
11020 set argid $id
11021 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} {
Denton Liue2445882020-09-10 21:36:33 -070011022 # part-way along an arc; check that arc first
11023 set a [lindex $arcnos($id) 0]
11024 if {$arctags($a) ne {}} {
11025 validate_arctags $a
11026 set i [lsearch -exact $arcids($a) $id]
11027 foreach t $arctags($a) {
11028 set j [lsearch -exact $arcids($a) $t]
11029 if {$j > $i} {
11030 return $t
11031 }
11032 }
11033 }
11034 if {![info exists arcend($a)]} {
11035 return {}
11036 }
11037 set id $arcend($a)
11038 if {[info exists idtags($id)]} {
11039 return $id
11040 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011041 }
11042 if {[info exists cached_atags($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011043 return $cached_atags($id)
Paul Mackerrase11f1232007-06-16 20:29:25 +100011044 }
11045
11046 set origid $id
11047 set todo [list $id]
11048 set queued($id) 1
11049 set taglist {}
11050 set nc 1
11051 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070011052 set id [lindex $todo $i]
11053 set done($id) 1
11054 set td [info exists hastaggeddescendent($id)]
11055 if {!$td} {
11056 incr nc -1
11057 }
11058 # ignore tags on starting node
11059 if {!$td && $i > 0} {
11060 if {[info exists idtags($id)]} {
11061 set tagloc($id) $id
11062 set td 1
11063 } elseif {[info exists cached_atags($id)]} {
11064 set tagloc($id) $cached_atags($id)
11065 set td 1
11066 }
11067 }
11068 foreach a $arcout($id) {
11069 if {!$td && $arctags($a) ne {}} {
11070 validate_arctags $a
11071 if {$arctags($a) ne {}} {
11072 lappend tagloc($id) [lindex $arctags($a) 0]
11073 }
11074 }
11075 if {![info exists arcend($a)]} continue
11076 set d $arcend($a)
11077 if {$td || $arctags($a) ne {}} {
11078 set tomark [list $d]
11079 for {set j 0} {$j < [llength $tomark]} {incr j} {
11080 set dd [lindex $tomark $j]
11081 if {![info exists hastaggeddescendent($dd)]} {
11082 if {[info exists done($dd)]} {
11083 foreach b $arcout($dd) {
11084 if {[info exists arcend($b)]} {
11085 lappend tomark $arcend($b)
11086 }
11087 }
11088 if {[info exists tagloc($dd)]} {
11089 unset tagloc($dd)
11090 }
11091 } elseif {[info exists queued($dd)]} {
11092 incr nc -1
11093 }
11094 set hastaggeddescendent($dd) 1
11095 }
11096 }
11097 }
11098 if {![info exists queued($d)]} {
11099 lappend todo $d
11100 set queued($d) 1
11101 if {![info exists hastaggeddescendent($d)]} {
11102 incr nc
11103 }
11104 }
11105 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011106 }
11107 set t2 [clock clicks -milliseconds]
11108 set loopix $i
11109 set tags {}
11110 foreach id [array names tagloc] {
Denton Liue2445882020-09-10 21:36:33 -070011111 if {![info exists hastaggeddescendent($id)]} {
11112 foreach t $tagloc($id) {
11113 if {[lsearch -exact $tags $t] < 0} {
11114 lappend tags $t
11115 }
11116 }
11117 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011118 }
11119
11120 # remove tags that are ancestors of other tags
11121 for {set i 0} {$i < [llength $tags]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070011122 set a [lindex $tags $i]
11123 for {set j 0} {$j < $i} {incr j} {
11124 set b [lindex $tags $j]
11125 set r [anc_or_desc $a $b]
11126 if {$r == -1} {
11127 set tags [lreplace $tags $j $j]
11128 incr j -1
11129 incr i -1
11130 } elseif {$r == 1} {
11131 set tags [lreplace $tags $i $i]
11132 incr i -1
11133 break
11134 }
11135 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011136 }
11137
11138 if {[array names growing] ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070011139 # graph isn't finished, need to check if any tag could get
11140 # eclipsed by another tag coming later. Simply ignore any
11141 # tags that could later get eclipsed.
11142 set ctags {}
11143 foreach t $tags {
11144 if {[is_certain $origid $t]} {
11145 lappend ctags $t
11146 }
11147 }
11148 if {$tags eq $ctags} {
11149 set cached_atags($origid) $tags
11150 } else {
11151 set tags $ctags
11152 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011153 } else {
Denton Liue2445882020-09-10 21:36:33 -070011154 set cached_atags($origid) $tags
Paul Mackerrase11f1232007-06-16 20:29:25 +100011155 }
11156 set t3 [clock clicks -milliseconds]
11157 if {0 && $t3 - $t1 >= 100} {
Denton Liue2445882020-09-10 21:36:33 -070011158 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\
11159 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left"
Paul Mackerrase11f1232007-06-16 20:29:25 +100011160 }
11161 return $tags
11162}
11163
11164# Return the list of IDs that have heads that are descendents of id,
11165# including id itself if it has a head.
11166proc descheads {id} {
11167 global arcnos arcstart arcids archeads idheads cached_dheads
Paul Mackerrasd809fb12013-01-01 16:51:03 +110011168 global allparents arcout
Paul Mackerrase11f1232007-06-16 20:29:25 +100011169
11170 if {![info exists allparents($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011171 return {}
Paul Mackerrase11f1232007-06-16 20:29:25 +100011172 }
Paul Mackerrasf3326b62007-06-18 22:39:21 +100011173 set aret {}
Paul Mackerrasd809fb12013-01-01 16:51:03 +110011174 if {![info exists arcout($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011175 # part-way along an arc; check it first
11176 set a [lindex $arcnos($id) 0]
11177 if {$archeads($a) ne {}} {
11178 validate_archeads $a
11179 set i [lsearch -exact $arcids($a) $id]
11180 foreach t $archeads($a) {
11181 set j [lsearch -exact $arcids($a) $t]
11182 if {$j > $i} break
11183 lappend aret $t
11184 }
11185 }
11186 set id $arcstart($a)
Paul Mackerrase11f1232007-06-16 20:29:25 +100011187 }
11188 set origid $id
11189 set todo [list $id]
11190 set seen($id) 1
Paul Mackerrasf3326b62007-06-18 22:39:21 +100011191 set ret {}
Paul Mackerrase11f1232007-06-16 20:29:25 +100011192 for {set i 0} {$i < [llength $todo]} {incr i} {
Denton Liue2445882020-09-10 21:36:33 -070011193 set id [lindex $todo $i]
11194 if {[info exists cached_dheads($id)]} {
11195 set ret [concat $ret $cached_dheads($id)]
11196 } else {
11197 if {[info exists idheads($id)]} {
11198 lappend ret $id
11199 }
11200 foreach a $arcnos($id) {
11201 if {$archeads($a) ne {}} {
11202 validate_archeads $a
11203 if {$archeads($a) ne {}} {
11204 set ret [concat $ret $archeads($a)]
11205 }
11206 }
11207 set d $arcstart($a)
11208 if {![info exists seen($d)]} {
11209 lappend todo $d
11210 set seen($d) 1
11211 }
11212 }
11213 }
Paul Mackerrase11f1232007-06-16 20:29:25 +100011214 }
11215 set ret [lsort -unique $ret]
11216 set cached_dheads($origid) $ret
Paul Mackerrasf3326b62007-06-18 22:39:21 +100011217 return [concat $ret $aret]
Paul Mackerrase11f1232007-06-16 20:29:25 +100011218}
11219
Paul Mackerrasceadfe92006-08-08 20:55:36 +100011220proc addedtag {id} {
Paul Mackerrase11f1232007-06-16 20:29:25 +100011221 global arcnos arcout cached_dtags cached_atags
Paul Mackerrasceadfe92006-08-08 20:55:36 +100011222
Paul Mackerrase11f1232007-06-16 20:29:25 +100011223 if {![info exists arcnos($id)]} return
11224 if {![info exists arcout($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011225 recalcarc [lindex $arcnos($id) 0]
Paul Mackerrasceadfe92006-08-08 20:55:36 +100011226 }
Paul Mackerras009409f2015-05-02 20:53:36 +100011227 unset -nocomplain cached_dtags
11228 unset -nocomplain cached_atags
Paul Mackerrasceadfe92006-08-08 20:55:36 +100011229}
11230
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011231proc addedhead {hid head} {
Paul Mackerrase11f1232007-06-16 20:29:25 +100011232 global arcnos arcout cached_dheads
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011233
Paul Mackerrase11f1232007-06-16 20:29:25 +100011234 if {![info exists arcnos($hid)]} return
11235 if {![info exists arcout($hid)]} {
Denton Liue2445882020-09-10 21:36:33 -070011236 recalcarc [lindex $arcnos($hid) 0]
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +100011237 }
Paul Mackerras009409f2015-05-02 20:53:36 +100011238 unset -nocomplain cached_dheads
Paul Mackerrasd6ac1a82006-08-02 09:41:04 +100011239}
11240
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011241proc removedhead {hid head} {
Paul Mackerrase11f1232007-06-16 20:29:25 +100011242 global cached_dheads
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011243
Paul Mackerras009409f2015-05-02 20:53:36 +100011244 unset -nocomplain cached_dheads
Paul Mackerras10299152006-08-02 09:52:01 +100011245}
11246
Paul Mackerrase11f1232007-06-16 20:29:25 +100011247proc movedhead {hid head} {
11248 global arcnos arcout cached_dheads
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011249
Paul Mackerrase11f1232007-06-16 20:29:25 +100011250 if {![info exists arcnos($hid)]} return
11251 if {![info exists arcout($hid)]} {
Denton Liue2445882020-09-10 21:36:33 -070011252 recalcarc [lindex $arcnos($hid) 0]
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011253 }
Paul Mackerras009409f2015-05-02 20:53:36 +100011254 unset -nocomplain cached_dheads
Paul Mackerrasca6d8f52006-08-06 21:08:05 +100011255}
11256
Paul Mackerrascec7bec2006-08-02 09:38:10 +100011257proc changedrefs {} {
David Aguilar587277f2012-09-08 12:53:16 -070011258 global cached_dheads cached_dtags cached_atags cached_tagcontent
Paul Mackerrase11f1232007-06-16 20:29:25 +100011259 global arctags archeads arcnos arcout idheads idtags
Paul Mackerrascec7bec2006-08-02 09:38:10 +100011260
Paul Mackerrase11f1232007-06-16 20:29:25 +100011261 foreach id [concat [array names idheads] [array names idtags]] {
Denton Liue2445882020-09-10 21:36:33 -070011262 if {[info exists arcnos($id)] && ![info exists arcout($id)]} {
11263 set a [lindex $arcnos($id) 0]
11264 if {![info exists donearc($a)]} {
11265 recalcarc $a
11266 set donearc($a) 1
11267 }
11268 }
Paul Mackerrascec7bec2006-08-02 09:38:10 +100011269 }
Paul Mackerras009409f2015-05-02 20:53:36 +100011270 unset -nocomplain cached_tagcontent
11271 unset -nocomplain cached_dtags
11272 unset -nocomplain cached_atags
11273 unset -nocomplain cached_dheads
Paul Mackerrascec7bec2006-08-02 09:38:10 +100011274}
11275
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011276proc rereadrefs {} {
Paul Mackerrasfc2a2562007-12-26 23:03:43 +110011277 global idtags idheads idotherrefs mainheadid
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011278
11279 set refids [concat [array names idtags] \
Denton Liue2445882020-09-10 21:36:33 -070011280 [array names idheads] [array names idotherrefs]]
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011281 foreach id $refids {
Denton Liue2445882020-09-10 21:36:33 -070011282 if {![info exists ref($id)]} {
11283 set ref($id) [listrefs $id]
11284 }
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011285 }
Paul Mackerrasfc2a2562007-12-26 23:03:43 +110011286 set oldmainhead $mainheadid
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011287 readrefs
Paul Mackerrascec7bec2006-08-02 09:38:10 +100011288 changedrefs
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011289 set refids [lsort -unique [concat $refids [array names idtags] \
Denton Liue2445882020-09-10 21:36:33 -070011290 [array names idheads] [array names idotherrefs]]]
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011291 foreach id $refids {
Denton Liue2445882020-09-10 21:36:33 -070011292 set v [listrefs $id]
11293 if {![info exists ref($id)] || $ref($id) != $v} {
11294 redrawtags $id
11295 }
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011296 }
Paul Mackerrasc11ff122008-05-26 10:11:33 +100011297 if {$oldmainhead ne $mainheadid} {
Denton Liue2445882020-09-10 21:36:33 -070011298 redrawtags $oldmainhead
11299 redrawtags $mainheadid
Paul Mackerrasc11ff122008-05-26 10:11:33 +100011300 }
Paul Mackerras887c9962007-08-20 19:36:20 +100011301 run refill_reflist
Paul Mackerrasf1d83ba2005-08-19 22:14:28 +100011302}
11303
Junio C Hamano2e1ded42006-06-11 09:50:47 -070011304proc listrefs {id} {
11305 global idtags idheads idotherrefs
11306
11307 set x {}
11308 if {[info exists idtags($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011309 set x $idtags($id)
Junio C Hamano2e1ded42006-06-11 09:50:47 -070011310 }
11311 set y {}
11312 if {[info exists idheads($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011313 set y $idheads($id)
Junio C Hamano2e1ded42006-06-11 09:50:47 -070011314 }
11315 set z {}
11316 if {[info exists idotherrefs($id)]} {
Denton Liue2445882020-09-10 21:36:33 -070011317 set z $idotherrefs($id)
Junio C Hamano2e1ded42006-06-11 09:50:47 -070011318 }
11319 return [list $x $y $z]
11320}
11321
Paul Mackerras4399fe32013-01-03 10:10:31 +110011322proc add_tag_ctext {tag} {
11323 global ctext cached_tagcontent tagids
11324
11325 if {![info exists cached_tagcontent($tag)]} {
Denton Liue2445882020-09-10 21:36:33 -070011326 catch {
11327 set cached_tagcontent($tag) [exec git cat-file -p $tag]
11328 }
Paul Mackerras4399fe32013-01-03 10:10:31 +110011329 }
11330 $ctext insert end "[mc "Tag"]: $tag\n" bold
11331 if {[info exists cached_tagcontent($tag)]} {
Denton Liue2445882020-09-10 21:36:33 -070011332 set text $cached_tagcontent($tag)
Paul Mackerras4399fe32013-01-03 10:10:31 +110011333 } else {
Denton Liue2445882020-09-10 21:36:33 -070011334 set text "[mc "Id"]: $tagids($tag)"
Paul Mackerras4399fe32013-01-03 10:10:31 +110011335 }
11336 appendwithlinks $text {}
11337}
11338
Paul Mackerras106288c2005-08-19 23:11:39 +100011339proc showtag {tag isnew} {
David Aguilar587277f2012-09-08 12:53:16 -070011340 global ctext cached_tagcontent tagids linknum tagobjid
Paul Mackerras106288c2005-08-19 23:11:39 +100011341
11342 if {$isnew} {
Denton Liue2445882020-09-10 21:36:33 -070011343 addtohistory [list showtag $tag 0] savectextpos
Paul Mackerras106288c2005-08-19 23:11:39 +100011344 }
11345 $ctext conf -state normal
Paul Mackerras3ea06f92006-05-24 10:16:03 +100011346 clear_ctext
Paul Mackerras32f1b3e2007-09-28 21:27:39 +100011347 settabs 0
Paul Mackerras106288c2005-08-19 23:11:39 +100011348 set linknum 0
Paul Mackerras4399fe32013-01-03 10:10:31 +110011349 add_tag_ctext $tag
11350 maybe_scroll_ctext 1
11351 $ctext conf -state disabled
11352 init_flist {}
11353}
11354
11355proc showtags {id isnew} {
11356 global idtags ctext linknum
11357
11358 if {$isnew} {
Denton Liue2445882020-09-10 21:36:33 -070011359 addtohistory [list showtags $id 0] savectextpos
Paul Mackerras62d3ea62006-09-11 10:36:53 +100011360 }
Paul Mackerras4399fe32013-01-03 10:10:31 +110011361 $ctext conf -state normal
11362 clear_ctext
11363 settabs 0
11364 set linknum 0
11365 set sep {}
11366 foreach tag $idtags($id) {
Denton Liue2445882020-09-10 21:36:33 -070011367 $ctext insert end $sep
11368 add_tag_ctext $tag
11369 set sep "\n\n"
Paul Mackerras106288c2005-08-19 23:11:39 +100011370 }
Pat Thoytsa80e82f2009-11-14 13:21:09 +000011371 maybe_scroll_ctext 1
Paul Mackerras106288c2005-08-19 23:11:39 +100011372 $ctext conf -state disabled
Paul Mackerras7fcceed2006-04-27 19:21:49 +100011373 init_flist {}
Paul Mackerras106288c2005-08-19 23:11:39 +100011374}
11375
Paul Mackerras1d10f362005-05-15 12:55:47 +000011376proc doquit {} {
11377 global stopped
Thomas Arcila314f5de2008-03-24 12:55:36 +010011378 global gitktmpdir
11379
Paul Mackerras1d10f362005-05-15 12:55:47 +000011380 set stopped 100
Mark Levedahlb6047c52007-02-08 22:22:24 -050011381 savestuff .
Paul Mackerras1d10f362005-05-15 12:55:47 +000011382 destroy .
Thomas Arcila314f5de2008-03-24 12:55:36 +010011383
11384 if {[info exists gitktmpdir]} {
Denton Liue2445882020-09-10 21:36:33 -070011385 catch {file delete -force $gitktmpdir}
Thomas Arcila314f5de2008-03-24 12:55:36 +010011386 }
Paul Mackerras1d10f362005-05-15 12:55:47 +000011387}
11388
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011389proc mkfontdisp {font top which} {
Pat Thoytsd93f1712009-04-17 01:24:35 +010011390 global fontattr fontpref $font NS use_ttk
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011391
11392 set fontpref($font) [set $font]
Pat Thoytsd93f1712009-04-17 01:24:35 +010011393 ${NS}::button $top.${font}but -text $which \
Denton Liue2445882020-09-10 21:36:33 -070011394 -command [list choosefont $font $which]
Pat Thoytsd93f1712009-04-17 01:24:35 +010011395 ${NS}::label $top.$font -relief flat -font $font \
Denton Liue2445882020-09-10 21:36:33 -070011396 -text $fontattr($font,family) -justify left
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011397 grid x $top.${font}but $top.$font -sticky w
11398}
11399
11400proc choosefont {font which} {
11401 global fontparam fontlist fonttop fontattr
Pat Thoytsd93f1712009-04-17 01:24:35 +010011402 global prefstop NS
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011403
11404 set fontparam(which) $which
11405 set fontparam(font) $font
11406 set fontparam(family) [font actual $font -family]
11407 set fontparam(size) $fontattr($font,size)
11408 set fontparam(weight) $fontattr($font,weight)
11409 set fontparam(slant) $fontattr($font,slant)
11410 set top .gitkfont
11411 set fonttop $top
11412 if {![winfo exists $top]} {
Denton Liue2445882020-09-10 21:36:33 -070011413 font create sample
11414 eval font config sample [font actual $font]
11415 ttk_toplevel $top
11416 make_transient $top $prefstop
11417 wm title $top [mc "Gitk font chooser"]
11418 ${NS}::label $top.l -textvariable fontparam(which)
11419 pack $top.l -side top
11420 set fontlist [lsort [font families]]
11421 ${NS}::frame $top.f
11422 listbox $top.f.fam -listvariable fontlist \
11423 -yscrollcommand [list $top.f.sb set]
11424 bind $top.f.fam <<ListboxSelect>> selfontfam
11425 ${NS}::scrollbar $top.f.sb -command [list $top.f.fam yview]
11426 pack $top.f.sb -side right -fill y
11427 pack $top.f.fam -side left -fill both -expand 1
11428 pack $top.f -side top -fill both -expand 1
11429 ${NS}::frame $top.g
11430 spinbox $top.g.size -from 4 -to 40 -width 4 \
11431 -textvariable fontparam(size) \
11432 -validatecommand {string is integer -strict %s}
11433 checkbutton $top.g.bold -padx 5 \
11434 -font {{Times New Roman} 12 bold} -text [mc "B"] -indicatoron 0 \
11435 -variable fontparam(weight) -onvalue bold -offvalue normal
11436 checkbutton $top.g.ital -padx 5 \
11437 -font {{Times New Roman} 12 italic} -text [mc "I"] -indicatoron 0 \
11438 -variable fontparam(slant) -onvalue italic -offvalue roman
11439 pack $top.g.size $top.g.bold $top.g.ital -side left
11440 pack $top.g -side top
11441 canvas $top.c -width 150 -height 50 -border 2 -relief sunk \
11442 -background white
11443 $top.c create text 100 25 -anchor center -text $which -font sample \
11444 -fill black -tags text
11445 bind $top.c <Configure> [list centertext $top.c]
11446 pack $top.c -side top -fill x
11447 ${NS}::frame $top.buts
11448 ${NS}::button $top.buts.ok -text [mc "OK"] -command fontok -default active
11449 ${NS}::button $top.buts.can -text [mc "Cancel"] -command fontcan -default normal
11450 bind $top <Key-Return> fontok
11451 bind $top <Key-Escape> fontcan
11452 grid $top.buts.ok $top.buts.can
11453 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11454 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11455 pack $top.buts -side bottom -fill x
11456 trace add variable fontparam write chg_fontparam
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011457 } else {
Denton Liue2445882020-09-10 21:36:33 -070011458 raise $top
11459 $top.c itemconf text -text $which
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011460 }
11461 set i [lsearch -exact $fontlist $fontparam(family)]
11462 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -070011463 $top.f.fam selection set $i
11464 $top.f.fam see $i
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011465 }
11466}
11467
11468proc centertext {w} {
11469 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}]
11470}
11471
11472proc fontok {} {
11473 global fontparam fontpref prefstop
11474
11475 set f $fontparam(font)
11476 set fontpref($f) [list $fontparam(family) $fontparam(size)]
11477 if {$fontparam(weight) eq "bold"} {
Denton Liue2445882020-09-10 21:36:33 -070011478 lappend fontpref($f) "bold"
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011479 }
11480 if {$fontparam(slant) eq "italic"} {
Denton Liue2445882020-09-10 21:36:33 -070011481 lappend fontpref($f) "italic"
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011482 }
Pat Thoyts39ddf992012-04-01 23:00:52 +010011483 set w $prefstop.notebook.fonts.$f
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011484 $w conf -text $fontparam(family) -font $fontpref($f)
Pat Thoytsd93f1712009-04-17 01:24:35 +010011485
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011486 fontcan
11487}
11488
11489proc fontcan {} {
11490 global fonttop fontparam
11491
11492 if {[info exists fonttop]} {
Denton Liue2445882020-09-10 21:36:33 -070011493 catch {destroy $fonttop}
11494 catch {font delete sample}
11495 unset fonttop
11496 unset fontparam
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011497 }
11498}
11499
Pat Thoytsd93f1712009-04-17 01:24:35 +010011500if {[package vsatisfies [package provide Tk] 8.6]} {
11501 # In Tk 8.6 we have a native font chooser dialog. Overwrite the above
11502 # function to make use of it.
11503 proc choosefont {font which} {
Denton Liue2445882020-09-10 21:36:33 -070011504 tk fontchooser configure -title $which -font $font \
11505 -command [list on_choosefont $font $which]
11506 tk fontchooser show
Pat Thoytsd93f1712009-04-17 01:24:35 +010011507 }
11508 proc on_choosefont {font which newfont} {
Denton Liue2445882020-09-10 21:36:33 -070011509 global fontparam
11510 puts stderr "$font $newfont"
11511 array set f [font actual $newfont]
11512 set fontparam(which) $which
11513 set fontparam(font) $font
11514 set fontparam(family) $f(-family)
11515 set fontparam(size) $f(-size)
11516 set fontparam(weight) $f(-weight)
11517 set fontparam(slant) $f(-slant)
11518 fontok
Pat Thoytsd93f1712009-04-17 01:24:35 +010011519 }
11520}
11521
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011522proc selfontfam {} {
11523 global fonttop fontparam
11524
11525 set i [$fonttop.f.fam curselection]
11526 if {$i ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070011527 set fontparam(family) [$fonttop.f.fam get $i]
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011528 }
11529}
11530
11531proc chg_fontparam {v sub op} {
11532 global fontparam
11533
11534 font config sample -$sub $fontparam($sub)
11535}
11536
Pat Thoyts44acce02011-12-13 14:56:49 +000011537# Create a property sheet tab page
11538proc create_prefs_page {w} {
11539 global NS
11540 set parent [join [lrange [split $w .] 0 end-1] .]
11541 if {[winfo class $parent] eq "TNotebook"} {
Denton Liue2445882020-09-10 21:36:33 -070011542 ${NS}::frame $w
Pat Thoyts44acce02011-12-13 14:56:49 +000011543 } else {
Denton Liue2445882020-09-10 21:36:33 -070011544 ${NS}::labelframe $w
Pat Thoyts44acce02011-12-13 14:56:49 +000011545 }
11546}
11547
11548proc prefspage_general {notebook} {
11549 global NS maxwidth maxgraphpct showneartags showlocalchanges
11550 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
Paul Mackerras3441de52019-08-27 08:12:34 +100011551 global hideremotes want_ttk have_ttk maxrefs web_browser
Pat Thoyts44acce02011-12-13 14:56:49 +000011552
11553 set page [create_prefs_page $notebook.general]
11554
11555 ${NS}::label $page.ldisp -text [mc "Commit list display options"]
11556 grid $page.ldisp - -sticky w -pady 10
11557 ${NS}::label $page.spacer -text " "
11558 ${NS}::label $page.maxwidthl -text [mc "Maximum graph width (lines)"]
11559 spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
11560 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w
Alex Henrie8a1692f2015-01-22 01:19:39 -070011561 #xgettext:no-tcl-format
Pat Thoyts44acce02011-12-13 14:56:49 +000011562 ${NS}::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"]
11563 spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
11564 grid x $page.maxpctl $page.maxpct -sticky w
11565 ${NS}::checkbutton $page.showlocal -text [mc "Show local changes"] \
Denton Liue2445882020-09-10 21:36:33 -070011566 -variable showlocalchanges
Pat Thoyts44acce02011-12-13 14:56:49 +000011567 grid x $page.showlocal -sticky w
11568 ${NS}::checkbutton $page.autoselect -text [mc "Auto-select SHA1 (length)"] \
Denton Liue2445882020-09-10 21:36:33 -070011569 -variable autoselect
Pat Thoyts44acce02011-12-13 14:56:49 +000011570 spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
11571 grid x $page.autoselect $page.autosellen -sticky w
11572 ${NS}::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \
Denton Liue2445882020-09-10 21:36:33 -070011573 -variable hideremotes
Pat Thoyts44acce02011-12-13 14:56:49 +000011574 grid x $page.hideremotes -sticky w
11575
11576 ${NS}::label $page.ddisp -text [mc "Diff display options"]
11577 grid $page.ddisp - -sticky w -pady 10
11578 ${NS}::label $page.tabstopl -text [mc "Tab spacing"]
11579 spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop
11580 grid x $page.tabstopl $page.tabstop -sticky w
Paul Mackerrasd34835c2013-01-01 23:08:12 +110011581 ${NS}::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \
Denton Liue2445882020-09-10 21:36:33 -070011582 -variable showneartags
Pat Thoyts44acce02011-12-13 14:56:49 +000011583 grid x $page.ntag -sticky w
Paul Mackerrasd34835c2013-01-01 23:08:12 +110011584 ${NS}::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"]
11585 spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs
11586 grid x $page.maxrefsl $page.maxrefs -sticky w
Pat Thoyts44acce02011-12-13 14:56:49 +000011587 ${NS}::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \
Denton Liue2445882020-09-10 21:36:33 -070011588 -variable limitdiffs
Pat Thoyts44acce02011-12-13 14:56:49 +000011589 grid x $page.ldiff -sticky w
11590 ${NS}::checkbutton $page.lattr -text [mc "Support per-file encodings"] \
Denton Liue2445882020-09-10 21:36:33 -070011591 -variable perfile_attrs
Pat Thoyts44acce02011-12-13 14:56:49 +000011592 grid x $page.lattr -sticky w
11593
11594 ${NS}::entry $page.extdifft -textvariable extdifftool
11595 ${NS}::frame $page.extdifff
11596 ${NS}::label $page.extdifff.l -text [mc "External diff tool" ]
11597 ${NS}::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff
11598 pack $page.extdifff.l $page.extdifff.b -side left
11599 pack configure $page.extdifff.l -padx 10
11600 grid x $page.extdifff $page.extdifft -sticky ew
11601
Paul Mackerras3441de52019-08-27 08:12:34 +100011602 ${NS}::entry $page.webbrowser -textvariable web_browser
11603 ${NS}::frame $page.webbrowserf
11604 ${NS}::label $page.webbrowserf.l -text [mc "Web browser" ]
11605 pack $page.webbrowserf.l -side left
11606 pack configure $page.webbrowserf.l -padx 10
11607 grid x $page.webbrowserf $page.webbrowser -sticky ew
11608
Pat Thoyts44acce02011-12-13 14:56:49 +000011609 ${NS}::label $page.lgen -text [mc "General options"]
11610 grid $page.lgen - -sticky w -pady 10
11611 ${NS}::checkbutton $page.want_ttk -variable want_ttk \
Denton Liue2445882020-09-10 21:36:33 -070011612 -text [mc "Use themed widgets"]
Pat Thoyts44acce02011-12-13 14:56:49 +000011613 if {$have_ttk} {
Denton Liue2445882020-09-10 21:36:33 -070011614 ${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
Pat Thoyts44acce02011-12-13 14:56:49 +000011615 } else {
Denton Liue2445882020-09-10 21:36:33 -070011616 ${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
Pat Thoyts44acce02011-12-13 14:56:49 +000011617 }
11618 grid x $page.want_ttk $page.ttk_note -sticky w
11619 return $page
11620}
11621
11622proc prefspage_colors {notebook} {
11623 global NS uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
Stefan Dotterweich113ce122020-02-11 22:24:48 +010011624 global diffbgcolors
Pat Thoyts44acce02011-12-13 14:56:49 +000011625
11626 set page [create_prefs_page $notebook.colors]
11627
11628 ${NS}::label $page.cdisp -text [mc "Colors: press to choose"]
11629 grid $page.cdisp - -sticky w -pady 10
11630 label $page.ui -padx 40 -relief sunk -background $uicolor
11631 ${NS}::button $page.uibut -text [mc "Interface"] \
11632 -command [list choosecolor uicolor {} $page.ui [mc "interface"] setui]
11633 grid x $page.uibut $page.ui -sticky w
11634 label $page.bg -padx 40 -relief sunk -background $bgcolor
11635 ${NS}::button $page.bgbut -text [mc "Background"] \
Denton Liue2445882020-09-10 21:36:33 -070011636 -command [list choosecolor bgcolor {} $page.bg [mc "background"] setbg]
Pat Thoyts44acce02011-12-13 14:56:49 +000011637 grid x $page.bgbut $page.bg -sticky w
11638 label $page.fg -padx 40 -relief sunk -background $fgcolor
11639 ${NS}::button $page.fgbut -text [mc "Foreground"] \
Denton Liue2445882020-09-10 21:36:33 -070011640 -command [list choosecolor fgcolor {} $page.fg [mc "foreground"] setfg]
Pat Thoyts44acce02011-12-13 14:56:49 +000011641 grid x $page.fgbut $page.fg -sticky w
11642 label $page.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
11643 ${NS}::button $page.diffoldbut -text [mc "Diff: old lines"] \
Denton Liue2445882020-09-10 21:36:33 -070011644 -command [list choosecolor diffcolors 0 $page.diffold [mc "diff old lines"] \
11645 [list $ctext tag conf d0 -foreground]]
Pat Thoyts44acce02011-12-13 14:56:49 +000011646 grid x $page.diffoldbut $page.diffold -sticky w
Stefan Dotterweich113ce122020-02-11 22:24:48 +010011647 label $page.diffoldbg -padx 40 -relief sunk -background [lindex $diffbgcolors 0]
11648 ${NS}::button $page.diffoldbgbut -text [mc "Diff: old lines bg"] \
Denton Liue2445882020-09-10 21:36:33 -070011649 -command [list choosecolor diffbgcolors 0 $page.diffoldbg \
11650 [mc "diff old lines bg"] \
11651 [list $ctext tag conf d0 -background]]
Stefan Dotterweich113ce122020-02-11 22:24:48 +010011652 grid x $page.diffoldbgbut $page.diffoldbg -sticky w
Pat Thoyts44acce02011-12-13 14:56:49 +000011653 label $page.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
11654 ${NS}::button $page.diffnewbut -text [mc "Diff: new lines"] \
Denton Liue2445882020-09-10 21:36:33 -070011655 -command [list choosecolor diffcolors 1 $page.diffnew [mc "diff new lines"] \
11656 [list $ctext tag conf dresult -foreground]]
Pat Thoyts44acce02011-12-13 14:56:49 +000011657 grid x $page.diffnewbut $page.diffnew -sticky w
Stefan Dotterweich113ce122020-02-11 22:24:48 +010011658 label $page.diffnewbg -padx 40 -relief sunk -background [lindex $diffbgcolors 1]
11659 ${NS}::button $page.diffnewbgbut -text [mc "Diff: new lines bg"] \
Denton Liue2445882020-09-10 21:36:33 -070011660 -command [list choosecolor diffbgcolors 1 $page.diffnewbg \
11661 [mc "diff new lines bg"] \
11662 [list $ctext tag conf dresult -background]]
Stefan Dotterweich113ce122020-02-11 22:24:48 +010011663 grid x $page.diffnewbgbut $page.diffnewbg -sticky w
Pat Thoyts44acce02011-12-13 14:56:49 +000011664 label $page.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
11665 ${NS}::button $page.hunksepbut -text [mc "Diff: hunk header"] \
Denton Liue2445882020-09-10 21:36:33 -070011666 -command [list choosecolor diffcolors 2 $page.hunksep \
11667 [mc "diff hunk header"] \
11668 [list $ctext tag conf hunksep -foreground]]
Pat Thoyts44acce02011-12-13 14:56:49 +000011669 grid x $page.hunksepbut $page.hunksep -sticky w
11670 label $page.markbgsep -padx 40 -relief sunk -background $markbgcolor
11671 ${NS}::button $page.markbgbut -text [mc "Marked line bg"] \
Denton Liue2445882020-09-10 21:36:33 -070011672 -command [list choosecolor markbgcolor {} $page.markbgsep \
11673 [mc "marked line background"] \
11674 [list $ctext tag conf omark -background]]
Pat Thoyts44acce02011-12-13 14:56:49 +000011675 grid x $page.markbgbut $page.markbgsep -sticky w
11676 label $page.selbgsep -padx 40 -relief sunk -background $selectbgcolor
11677 ${NS}::button $page.selbgbut -text [mc "Select bg"] \
Denton Liue2445882020-09-10 21:36:33 -070011678 -command [list choosecolor selectbgcolor {} $page.selbgsep [mc "background"] setselbg]
Pat Thoyts44acce02011-12-13 14:56:49 +000011679 grid x $page.selbgbut $page.selbgsep -sticky w
11680 return $page
11681}
11682
11683proc prefspage_fonts {notebook} {
11684 global NS
11685 set page [create_prefs_page $notebook.fonts]
11686 ${NS}::label $page.cfont -text [mc "Fonts: press to choose"]
11687 grid $page.cfont - -sticky w -pady 10
11688 mkfontdisp mainfont $page [mc "Main font"]
11689 mkfontdisp textfont $page [mc "Diff display font"]
11690 mkfontdisp uifont $page [mc "User interface font"]
11691 return $page
11692}
11693
Paul Mackerras712fcc02005-11-30 09:28:16 +110011694proc doprefs {} {
Pat Thoytsd93f1712009-04-17 01:24:35 +010011695 global maxwidth maxgraphpct use_ttk NS
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011696 global oldprefs prefstop showneartags showlocalchanges
Guillermo S. Romero5497f7a2009-10-15 18:51:49 +020011697 global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
Paul Mackerras21ac8a82011-03-09 20:52:38 +110011698 global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100011699 global hideremotes want_ttk have_ttk
Paul Mackerras232475d2005-11-15 10:34:03 +110011700
Paul Mackerras712fcc02005-11-30 09:28:16 +110011701 set top .gitkprefs
11702 set prefstop $top
11703 if {[winfo exists $top]} {
Denton Liue2445882020-09-10 21:36:33 -070011704 raise $top
11705 return
Paul Mackerras757f17b2005-11-21 09:56:07 +110011706 }
Paul Mackerras3de07112007-10-23 22:40:50 +100011707 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
Denton Liue2445882020-09-10 21:36:33 -070011708 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11709 set oldprefs($v) [set $v]
Paul Mackerras232475d2005-11-15 10:34:03 +110011710 }
Pat Thoytsd93f1712009-04-17 01:24:35 +010011711 ttk_toplevel $top
Christian Stimmingd990ced2007-11-07 18:42:55 +010011712 wm title $top [mc "Gitk preferences"]
Alexander Gavrilove7d64002008-11-11 23:55:42 +030011713 make_transient $top .
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011714
Pat Thoyts44acce02011-12-13 14:56:49 +000011715 if {[set use_notebook [expr {$use_ttk && [info command ::ttk::notebook] ne ""}]]} {
Denton Liue2445882020-09-10 21:36:33 -070011716 set notebook [ttk::notebook $top.notebook]
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100011717 } else {
Denton Liue2445882020-09-10 21:36:33 -070011718 set notebook [${NS}::frame $top.notebook -borderwidth 0 -relief flat]
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100011719 }
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100011720
Pat Thoyts44acce02011-12-13 14:56:49 +000011721 lappend pages [prefspage_general $notebook] [mc "General"]
11722 lappend pages [prefspage_colors $notebook] [mc "Colors"]
11723 lappend pages [prefspage_fonts $notebook] [mc "Fonts"]
Pat Thoyts28cb7072012-04-01 23:00:51 +010011724 set col 0
Pat Thoyts44acce02011-12-13 14:56:49 +000011725 foreach {page title} $pages {
Denton Liue2445882020-09-10 21:36:33 -070011726 if {$use_notebook} {
11727 $notebook add $page -text $title
11728 } else {
11729 set btn [${NS}::button $notebook.b_[string map {. X} $page] \
11730 -text $title -command [list raise $page]]
11731 $page configure -text $title
11732 grid $btn -row 0 -column [incr col] -sticky w
11733 grid $page -row 1 -column 0 -sticky news -columnspan 100
11734 }
Pat Thoyts44acce02011-12-13 14:56:49 +000011735 }
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011736
Pat Thoyts44acce02011-12-13 14:56:49 +000011737 if {!$use_notebook} {
Denton Liue2445882020-09-10 21:36:33 -070011738 grid columnconfigure $notebook 0 -weight 1
11739 grid rowconfigure $notebook 1 -weight 1
11740 raise [lindex $pages 0]
Pat Thoyts44acce02011-12-13 14:56:49 +000011741 }
11742
11743 grid $notebook -sticky news -padx 2 -pady 2
11744 grid rowconfigure $top 0 -weight 1
11745 grid columnconfigure $top 0 -weight 1
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011746
Pat Thoytsd93f1712009-04-17 01:24:35 +010011747 ${NS}::frame $top.buts
11748 ${NS}::button $top.buts.ok -text [mc "OK"] -command prefsok -default active
11749 ${NS}::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal
Alexander Gavrilov76f15942008-11-02 21:59:44 +030011750 bind $top <Key-Return> prefsok
11751 bind $top <Key-Escape> prefscan
Paul Mackerras712fcc02005-11-30 09:28:16 +110011752 grid $top.buts.ok $top.buts.can
11753 grid columnconfigure $top.buts 0 -weight 1 -uniform a
11754 grid columnconfigure $top.buts 1 -weight 1 -uniform a
11755 grid $top.buts - - -pady 10 -sticky ew
Pat Thoytsd93f1712009-04-17 01:24:35 +010011756 grid columnconfigure $top 2 -weight 1
Pat Thoyts44acce02011-12-13 14:56:49 +000011757 bind $top <Visibility> [list focus $top.buts.ok]
Paul Mackerras712fcc02005-11-30 09:28:16 +110011758}
11759
Thomas Arcila314f5de2008-03-24 12:55:36 +010011760proc choose_extdiff {} {
11761 global extdifftool
11762
Michele Ballabiob56e0a92009-03-30 21:17:25 +020011763 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false]
Thomas Arcila314f5de2008-03-24 12:55:36 +010011764 if {$prog ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070011765 set extdifftool $prog
Thomas Arcila314f5de2008-03-24 12:55:36 +010011766 }
11767}
11768
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011769proc choosecolor {v vi w x cmd} {
11770 global $v
11771
11772 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
Denton Liue2445882020-09-10 21:36:33 -070011773 -title [mc "Gitk: choose color for %s" $x]]
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011774 if {$c eq {}} return
11775 $w conf -background $c
11776 lset $v $vi $c
11777 eval $cmd $c
11778}
11779
Mark Levedahl60378c02007-05-20 12:12:48 -040011780proc setselbg {c} {
11781 global bglist cflist
11782 foreach w $bglist {
Denton Liue2445882020-09-10 21:36:33 -070011783 if {[winfo exists $w]} {
11784 $w configure -selectbackground $c
11785 }
Mark Levedahl60378c02007-05-20 12:12:48 -040011786 }
11787 $cflist tag configure highlight \
Denton Liue2445882020-09-10 21:36:33 -070011788 -background [$cflist cget -selectbackground]
Mark Levedahl60378c02007-05-20 12:12:48 -040011789 allcanvs itemconf secsel -fill $c
11790}
11791
Paul Mackerras51a7e8b2009-11-14 21:15:01 +110011792# This sets the background color and the color scheme for the whole UI.
11793# For some reason, tk_setPalette chooses a nasty dark red for selectColor
11794# if we don't specify one ourselves, which makes the checkbuttons and
11795# radiobuttons look bad. This chooses white for selectColor if the
11796# background color is light, or black if it is dark.
Guillermo S. Romero5497f7a2009-10-15 18:51:49 +020011797proc setui {c} {
Pat Thoyts2e58c942010-03-12 18:31:47 +000011798 if {[tk windowingsystem] eq "win32"} { return }
Paul Mackerras51a7e8b2009-11-14 21:15:01 +110011799 set bg [winfo rgb . $c]
11800 set selc black
11801 if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
Denton Liue2445882020-09-10 21:36:33 -070011802 set selc white
Paul Mackerras51a7e8b2009-11-14 21:15:01 +110011803 }
11804 tk_setPalette background $c selectColor $selc
Guillermo S. Romero5497f7a2009-10-15 18:51:49 +020011805}
11806
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011807proc setbg {c} {
11808 global bglist
11809
11810 foreach w $bglist {
Denton Liue2445882020-09-10 21:36:33 -070011811 if {[winfo exists $w]} {
11812 $w conf -background $c
11813 }
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011814 }
11815}
11816
11817proc setfg {c} {
11818 global fglist canv
11819
11820 foreach w $fglist {
Denton Liue2445882020-09-10 21:36:33 -070011821 if {[winfo exists $w]} {
11822 $w conf -foreground $c
11823 }
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011824 }
11825 allcanvs itemconf text -fill $c
11826 $canv itemconf circle -outline $c
Paul Mackerrasb9fdba72009-04-09 09:34:46 +100011827 $canv itemconf markid -outline $c
Paul Mackerrasf8a2c0d2006-07-05 22:56:37 +100011828}
11829
Paul Mackerras712fcc02005-11-30 09:28:16 +110011830proc prefscan {} {
Paul Mackerras94503912007-10-23 10:33:38 +100011831 global oldprefs prefstop
Paul Mackerras712fcc02005-11-30 09:28:16 +110011832
Paul Mackerras3de07112007-10-23 22:40:50 +100011833 foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
Denton Liue2445882020-09-10 21:36:33 -070011834 limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11835 global $v
11836 set $v $oldprefs($v)
Paul Mackerras712fcc02005-11-30 09:28:16 +110011837 }
11838 catch {destroy $prefstop}
11839 unset prefstop
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011840 fontcan
Paul Mackerras712fcc02005-11-30 09:28:16 +110011841}
11842
11843proc prefsok {} {
11844 global maxwidth maxgraphpct
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011845 global oldprefs prefstop showneartags showlocalchanges
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011846 global fontpref mainfont textfont uifont
Paul Mackerras39ee47e2008-10-15 22:23:03 +110011847 global limitdiffs treediffs perfile_attrs
Thomas Rastffe15292009-08-03 23:53:36 +020011848 global hideremotes
Paul Mackerras712fcc02005-11-30 09:28:16 +110011849
11850 catch {destroy $prefstop}
11851 unset prefstop
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011852 fontcan
11853 set fontchanged 0
11854 if {$mainfont ne $fontpref(mainfont)} {
Denton Liue2445882020-09-10 21:36:33 -070011855 set mainfont $fontpref(mainfont)
11856 parsefont mainfont $mainfont
11857 eval font configure mainfont [fontflags mainfont]
11858 eval font configure mainfontbold [fontflags mainfont 1]
11859 setcoords
11860 set fontchanged 1
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011861 }
11862 if {$textfont ne $fontpref(textfont)} {
Denton Liue2445882020-09-10 21:36:33 -070011863 set textfont $fontpref(textfont)
11864 parsefont textfont $textfont
11865 eval font configure textfont [fontflags textfont]
11866 eval font configure textfontbold [fontflags textfont 1]
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011867 }
11868 if {$uifont ne $fontpref(uifont)} {
Denton Liue2445882020-09-10 21:36:33 -070011869 set uifont $fontpref(uifont)
11870 parsefont uifont $uifont
11871 eval font configure uifont [fontflags uifont]
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011872 }
Paul Mackerras32f1b3e2007-09-28 21:27:39 +100011873 settabs
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011874 if {$showlocalchanges != $oldprefs(showlocalchanges)} {
Denton Liue2445882020-09-10 21:36:33 -070011875 if {$showlocalchanges} {
11876 doshowlocalchanges
11877 } else {
11878 dohidelocalchanges
11879 }
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011880 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110011881 if {$limitdiffs != $oldprefs(limitdiffs) ||
Denton Liue2445882020-09-10 21:36:33 -070011882 ($perfile_attrs && !$oldprefs(perfile_attrs))} {
11883 # treediffs elements are limited by path;
11884 # won't have encodings cached if perfile_attrs was just turned on
11885 unset -nocomplain treediffs
Paul Mackerras74a40c72007-10-24 10:16:56 +100011886 }
Paul Mackerras9a7558f2007-10-06 20:16:06 +100011887 if {$fontchanged || $maxwidth != $oldprefs(maxwidth)
Denton Liue2445882020-09-10 21:36:33 -070011888 || $maxgraphpct != $oldprefs(maxgraphpct)} {
11889 redisplay
Paul Mackerras7a39a172007-10-23 10:15:11 +100011890 } elseif {$showneartags != $oldprefs(showneartags) ||
Denton Liue2445882020-09-10 21:36:33 -070011891 $limitdiffs != $oldprefs(limitdiffs)} {
11892 reselectline
Paul Mackerras712fcc02005-11-30 09:28:16 +110011893 }
Thomas Rastffe15292009-08-03 23:53:36 +020011894 if {$hideremotes != $oldprefs(hideremotes)} {
Denton Liue2445882020-09-10 21:36:33 -070011895 rereadrefs
Thomas Rastffe15292009-08-03 23:53:36 +020011896 }
Paul Mackerras712fcc02005-11-30 09:28:16 +110011897}
11898
11899proc formatdate {d} {
Arjen Laarhovene8b5f4b2007-08-14 22:02:04 +020011900 global datetimeformat
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011901 if {$d ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070011902 # If $datetimeformat includes a timezone, display in the
11903 # timezone of the argument. Otherwise, display in local time.
11904 if {[string match {*%[zZ]*} $datetimeformat]} {
11905 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} {
11906 # Tcl < 8.5 does not support -timezone. Emulate it by
11907 # setting TZ (e.g. TZ=<-0430>+04:30).
11908 global env
11909 if {[info exists env(TZ)]} {
11910 set savedTZ $env(TZ)
11911 }
11912 set zone [lindex $d 1]
11913 set sign [string map {+ - - +} [string index $zone 0]]
11914 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4]
11915 set d [clock format [lindex $d 0] -format $datetimeformat]
11916 if {[info exists savedTZ]} {
11917 set env(TZ) $savedTZ
11918 } else {
11919 unset env(TZ)
11920 }
11921 }
11922 } else {
11923 set d [clock format [lindex $d 0] -format $datetimeformat]
11924 }
Paul Mackerras219ea3a2006-09-07 10:21:39 +100011925 }
11926 return $d
Paul Mackerras232475d2005-11-15 10:34:03 +110011927}
11928
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110011929# This list of encoding names and aliases is distilled from
11930# http://www.iana.org/assignments/character-sets.
11931# Not all of them are supported by Tcl.
11932set encoding_aliases {
11933 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII
11934 ISO646-US US-ASCII us IBM367 cp367 csASCII }
11935 { ISO-10646-UTF-1 csISO10646UTF1 }
11936 { ISO_646.basic:1983 ref csISO646basic1983 }
11937 { INVARIANT csINVARIANT }
11938 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion }
11939 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom }
11940 { NATS-SEFI iso-ir-8-1 csNATSSEFI }
11941 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD }
11942 { NATS-DANO iso-ir-9-1 csNATSDANO }
11943 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD }
11944 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish }
11945 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames }
11946 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 }
11947 { ISO-2022-KR csISO2022KR }
11948 { EUC-KR csEUCKR }
11949 { ISO-2022-JP csISO2022JP }
11950 { ISO-2022-JP-2 csISO2022JP2 }
11951 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7
11952 csISO13JISC6220jp }
11953 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro }
11954 { IT iso-ir-15 ISO646-IT csISO15Italian }
11955 { PT iso-ir-16 ISO646-PT csISO16Portuguese }
11956 { ES iso-ir-17 ISO646-ES csISO17Spanish }
11957 { greek7-old iso-ir-18 csISO18Greek7Old }
11958 { latin-greek iso-ir-19 csISO19LatinGreek }
11959 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German }
11960 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French }
11961 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 }
11962 { ISO_5427 iso-ir-37 csISO5427Cyrillic }
11963 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 }
11964 { BS_viewdata iso-ir-47 csISO47BSViewdata }
11965 { INIS iso-ir-49 csISO49INIS }
11966 { INIS-8 iso-ir-50 csISO50INIS8 }
11967 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic }
11968 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 }
11969 { ISO_5428:1980 iso-ir-55 csISO5428Greek }
11970 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 }
11971 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 }
11972 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian
11973 csISO60Norwegian1 }
11974 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 }
11975 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French }
11976 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 }
11977 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 }
11978 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 }
11979 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian }
11980 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 }
11981 { greek7 iso-ir-88 csISO88Greek7 }
11982 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 }
11983 { iso-ir-90 csISO90 }
11984 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a }
11985 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b
11986 csISO92JISC62991984b }
11987 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd }
11988 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand }
11989 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add
11990 csISO95JIS62291984handadd }
11991 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana }
11992 { ISO_2033-1983 iso-ir-98 e13b csISO2033 }
11993 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS }
11994 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819
11995 CP819 csISOLatin1 }
11996 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 }
11997 { T.61-7bit iso-ir-102 csISO102T617bit }
11998 { T.61-8bit T.61 iso-ir-103 csISO103T618bit }
11999 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 }
12000 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 }
12001 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic }
12002 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 }
12003 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 }
12004 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr }
12005 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708
12006 arabic csISOLatinArabic }
12007 { ISO_8859-6-E csISO88596E ISO-8859-6-E }
12008 { ISO_8859-6-I csISO88596I ISO-8859-6-I }
12009 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118
12010 greek greek8 csISOLatinGreek }
12011 { T.101-G2 iso-ir-128 csISO128T101G2 }
12012 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew
12013 csISOLatinHebrew }
12014 { ISO_8859-8-E csISO88598E ISO-8859-8-E }
12015 { ISO_8859-8-I csISO88598I ISO-8859-8-I }
12016 { CSN_369103 iso-ir-139 csISO139CSN369103 }
12017 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 }
12018 { ISO_6937-2-add iso-ir-142 csISOTextComm }
12019 { IEC_P27-1 iso-ir-143 csISO143IECP271 }
12020 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic
12021 csISOLatinCyrillic }
12022 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian }
12023 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian }
12024 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 }
12025 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT }
12026 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba }
12027 { ISO_6937-2-25 iso-ir-152 csISO6937Add }
12028 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 }
12029 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp }
12030 { ISO_10367-box iso-ir-155 csISO10367Box }
12031 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 }
12032 { latin-lap lap iso-ir-158 csISO158Lap }
12033 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 }
12034 { DS_2089 DS2089 ISO646-DK dk csISO646Danish }
12035 { us-dk csUSDK }
12036 { dk-us csDKUS }
12037 { JIS_X0201 X0201 csHalfWidthKatakana }
12038 { KSC5636 ISO646-KR csKSC5636 }
12039 { ISO-10646-UCS-2 csUnicode }
12040 { ISO-10646-UCS-4 csUCS4 }
12041 { DEC-MCS dec csDECMCS }
12042 { hp-roman8 roman8 r8 csHPRoman8 }
12043 { macintosh mac csMacintosh }
12044 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl
12045 csIBM037 }
12046 { IBM038 EBCDIC-INT cp038 csIBM038 }
12047 { IBM273 CP273 csIBM273 }
12048 { IBM274 EBCDIC-BE CP274 csIBM274 }
12049 { IBM275 EBCDIC-BR cp275 csIBM275 }
12050 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 }
12051 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 }
12052 { IBM280 CP280 ebcdic-cp-it csIBM280 }
12053 { IBM281 EBCDIC-JP-E cp281 csIBM281 }
12054 { IBM284 CP284 ebcdic-cp-es csIBM284 }
12055 { IBM285 CP285 ebcdic-cp-gb csIBM285 }
12056 { IBM290 cp290 EBCDIC-JP-kana csIBM290 }
12057 { IBM297 cp297 ebcdic-cp-fr csIBM297 }
12058 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 }
12059 { IBM423 cp423 ebcdic-cp-gr csIBM423 }
12060 { IBM424 cp424 ebcdic-cp-he csIBM424 }
12061 { IBM437 cp437 437 csPC8CodePage437 }
12062 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 }
12063 { IBM775 cp775 csPC775Baltic }
12064 { IBM850 cp850 850 csPC850Multilingual }
12065 { IBM851 cp851 851 csIBM851 }
12066 { IBM852 cp852 852 csPCp852 }
12067 { IBM855 cp855 855 csIBM855 }
12068 { IBM857 cp857 857 csIBM857 }
12069 { IBM860 cp860 860 csIBM860 }
12070 { IBM861 cp861 861 cp-is csIBM861 }
12071 { IBM862 cp862 862 csPC862LatinHebrew }
12072 { IBM863 cp863 863 csIBM863 }
12073 { IBM864 cp864 csIBM864 }
12074 { IBM865 cp865 865 csIBM865 }
12075 { IBM866 cp866 866 csIBM866 }
12076 { IBM868 CP868 cp-ar csIBM868 }
12077 { IBM869 cp869 869 cp-gr csIBM869 }
12078 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 }
12079 { IBM871 CP871 ebcdic-cp-is csIBM871 }
12080 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 }
12081 { IBM891 cp891 csIBM891 }
12082 { IBM903 cp903 csIBM903 }
12083 { IBM904 cp904 904 csIBBM904 }
12084 { IBM905 CP905 ebcdic-cp-tr csIBM905 }
12085 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 }
12086 { IBM1026 CP1026 csIBM1026 }
12087 { EBCDIC-AT-DE csIBMEBCDICATDE }
12088 { EBCDIC-AT-DE-A csEBCDICATDEA }
12089 { EBCDIC-CA-FR csEBCDICCAFR }
12090 { EBCDIC-DK-NO csEBCDICDKNO }
12091 { EBCDIC-DK-NO-A csEBCDICDKNOA }
12092 { EBCDIC-FI-SE csEBCDICFISE }
12093 { EBCDIC-FI-SE-A csEBCDICFISEA }
12094 { EBCDIC-FR csEBCDICFR }
12095 { EBCDIC-IT csEBCDICIT }
12096 { EBCDIC-PT csEBCDICPT }
12097 { EBCDIC-ES csEBCDICES }
12098 { EBCDIC-ES-A csEBCDICESA }
12099 { EBCDIC-ES-S csEBCDICESS }
12100 { EBCDIC-UK csEBCDICUK }
12101 { EBCDIC-US csEBCDICUS }
12102 { UNKNOWN-8BIT csUnknown8BiT }
12103 { MNEMONIC csMnemonic }
12104 { MNEM csMnem }
12105 { VISCII csVISCII }
12106 { VIQR csVIQR }
12107 { KOI8-R csKOI8R }
12108 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro }
12109 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro }
12110 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro }
12111 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro }
12112 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro }
12113 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro }
12114 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro }
12115 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro }
12116 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro }
12117 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro }
12118 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro }
12119 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro }
12120 { IBM1047 IBM-1047 }
12121 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian }
12122 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 }
12123 { UNICODE-1-1 csUnicode11 }
12124 { CESU-8 csCESU-8 }
12125 { BOCU-1 csBOCU-1 }
12126 { UNICODE-1-1-UTF-7 csUnicode11UTF7 }
12127 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic
12128 l8 }
12129 { ISO-8859-15 ISO_8859-15 Latin-9 }
12130 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
12131 { GBK CP936 MS936 windows-936 }
12132 { JIS_Encoding csJISEncoding }
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012133 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012134 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
12135 EUC-JP }
12136 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
12137 { ISO-10646-UCS-Basic csUnicodeASCII }
12138 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 }
12139 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 }
12140 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 }
12141 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 }
12142 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 }
12143 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 }
12144 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 }
12145 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 }
12146 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 }
12147 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 }
12148 { Adobe-Standard-Encoding csAdobeStandardEncoding }
12149 { Ventura-US csVenturaUS }
12150 { Ventura-International csVenturaInternational }
12151 { PC8-Danish-Norwegian csPC8DanishNorwegian }
12152 { PC8-Turkish csPC8Turkish }
12153 { IBM-Symbols csIBMSymbols }
12154 { IBM-Thai csIBMThai }
12155 { HP-Legal csHPLegal }
12156 { HP-Pi-font csHPPiFont }
12157 { HP-Math8 csHPMath8 }
12158 { Adobe-Symbol-Encoding csHPPSMath }
12159 { HP-DeskTop csHPDesktop }
12160 { Ventura-Math csVenturaMath }
12161 { Microsoft-Publishing csMicrosoftPublishing }
12162 { Windows-31J csWindows31J }
12163 { GB2312 csGB2312 }
12164 { Big5 csBig5 }
12165}
12166
12167proc tcl_encoding {enc} {
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012168 global encoding_aliases tcl_encoding_cache
12169 if {[info exists tcl_encoding_cache($enc)]} {
Denton Liue2445882020-09-10 21:36:33 -070012170 return $tcl_encoding_cache($enc)
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012171 }
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012172 set names [encoding names]
12173 set lcnames [string tolower $names]
12174 set enc [string tolower $enc]
12175 set i [lsearch -exact $lcnames $enc]
12176 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -070012177 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
12178 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
12179 set i [lsearch -exact $lcnames $encx]
12180 }
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012181 }
12182 if {$i < 0} {
Denton Liue2445882020-09-10 21:36:33 -070012183 foreach l $encoding_aliases {
12184 set ll [string tolower $l]
12185 if {[lsearch -exact $ll $enc] < 0} continue
12186 # look through the aliases for one that tcl knows about
12187 foreach e $ll {
12188 set i [lsearch -exact $lcnames $e]
12189 if {$i < 0} {
12190 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
12191 set i [lsearch -exact $lcnames $ex]
12192 }
12193 }
12194 if {$i >= 0} break
12195 }
12196 break
12197 }
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012198 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012199 set tclenc {}
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012200 if {$i >= 0} {
Denton Liue2445882020-09-10 21:36:33 -070012201 set tclenc [lindex $names $i]
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012202 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012203 set tcl_encoding_cache($enc) $tclenc
12204 return $tclenc
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012205}
12206
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012207proc gitattr {path attr default} {
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012208 global path_attr_cache
12209 if {[info exists path_attr_cache($attr,$path)]} {
Denton Liue2445882020-09-10 21:36:33 -070012210 set r $path_attr_cache($attr,$path)
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012211 } else {
Denton Liue2445882020-09-10 21:36:33 -070012212 set r "unspecified"
12213 if {![catch {set line [exec git check-attr $attr -- $path]}]} {
12214 regexp "(.*): $attr: (.*)" $line m f r
12215 }
12216 set path_attr_cache($attr,$path) $r
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012217 }
12218 if {$r eq "unspecified"} {
Denton Liue2445882020-09-10 21:36:33 -070012219 return $default
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012220 }
12221 return $r
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012222}
12223
Alexander Gavrilov4db09302008-10-13 12:12:33 +040012224proc cache_gitattr {attr pathlist} {
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012225 global path_attr_cache
12226 set newlist {}
12227 foreach path $pathlist {
Denton Liue2445882020-09-10 21:36:33 -070012228 if {![info exists path_attr_cache($attr,$path)]} {
12229 lappend newlist $path
12230 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012231 }
12232 set lim 1000
12233 if {[tk windowingsystem] == "win32"} {
Denton Liue2445882020-09-10 21:36:33 -070012234 # windows has a 32k limit on the arguments to a command...
12235 set lim 30
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012236 }
12237 while {$newlist ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070012238 set head [lrange $newlist 0 [expr {$lim - 1}]]
12239 set newlist [lrange $newlist $lim end]
12240 if {![catch {set rlist [eval exec git check-attr $attr -- $head]}]} {
12241 foreach row [split $rlist "\n"] {
12242 if {[regexp "(.*): $attr: (.*)" $row m path value]} {
12243 if {[string index $path 0] eq "\""} {
12244 set path [encoding convertfrom [lindex $path 0]]
12245 }
12246 set path_attr_cache($attr,$path) $value
12247 }
12248 }
12249 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012250 }
Alexander Gavrilov4db09302008-10-13 12:12:33 +040012251}
12252
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012253proc get_path_encoding {path} {
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012254 global gui_encoding perfile_attrs
12255 set tcl_enc $gui_encoding
12256 if {$path ne {} && $perfile_attrs} {
Denton Liue2445882020-09-10 21:36:33 -070012257 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
12258 if {$enc2 ne {}} {
12259 set tcl_enc $enc2
12260 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012261 }
12262 return $tcl_enc
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012263}
12264
Alex Henrieef87a482015-05-11 13:26:41 -060012265## For msgcat loading, first locate the installation location.
12266if { [info exists ::env(GITK_MSGSDIR)] } {
12267 ## Msgsdir was manually set in the environment.
12268 set gitk_msgsdir $::env(GITK_MSGSDIR)
12269} else {
12270 ## Let's guess the prefix from argv0.
12271 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]]
12272 set gitk_libdir [file join $gitk_prefix share gitk lib]
12273 set gitk_msgsdir [file join $gitk_libdir msgs]
12274 unset gitk_prefix
12275}
12276
12277## Internationalization (i18n) through msgcat and gettext. See
12278## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
12279package require msgcat
12280namespace import ::msgcat::mc
12281## And eventually load the actual message catalog
12282::msgcat::mcload $gitk_msgsdir
12283
Paul Mackerras5d7589d2007-10-20 21:21:03 +100012284# First check that Tcl/Tk is recent enough
12285if {[catch {package require Tk 8.4} err]} {
Alex Henrieef87a482015-05-11 13:26:41 -060012286 show_error {} . [mc "Sorry, gitk cannot run with this version of Tcl/Tk.\n\
Denton Liue2445882020-09-10 21:36:33 -070012287 Gitk requires at least Tcl/Tk 8.4."]
Paul Mackerras5d7589d2007-10-20 21:21:03 +100012288 exit 1
12289}
12290
Tair Sabirgaliev76bf6ff2013-04-24 15:48:27 +060012291# on OSX bring the current Wish process window to front
12292if {[tk windowingsystem] eq "aqua"} {
12293 exec osascript -e [format {
12294 tell application "System Events"
12295 set frontmost of processes whose unix id is %d to true
12296 end tell
12297 } [pid] ]
12298}
12299
Aske Olsson0ae10352012-05-10 12:13:43 +020012300# Unset GIT_TRACE var if set
12301if { [info exists ::env(GIT_TRACE)] } {
12302 unset ::env(GIT_TRACE)
12303}
12304
Paul Mackerras1d10f362005-05-15 12:55:47 +000012305# defaults...
Chris Packhame203d1d2014-11-02 21:37:50 +130012306set wrcomcmd "git diff-tree --stdin -p --pretty=email"
Junio C Hamano671bc152005-11-27 16:12:51 -080012307
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012308set gitencoding {}
Junio C Hamano671bc152005-11-27 16:12:51 -080012309catch {
Paul Mackerras27cb61c2007-02-15 08:54:34 +110012310 set gitencoding [exec git config --get i18n.commitencoding]
Junio C Hamano671bc152005-11-27 16:12:51 -080012311}
Alexander Gavrilov590915d2008-11-09 18:06:07 +030012312catch {
12313 set gitencoding [exec git config --get i18n.logoutputencoding]
12314}
Junio C Hamano671bc152005-11-27 16:12:51 -080012315if {$gitencoding == ""} {
Paul Mackerrasfd8ccbe2005-12-07 23:28:22 +110012316 set gitencoding "utf-8"
12317}
12318set tclencoding [tcl_encoding $gitencoding]
12319if {$tclencoding == {}} {
12320 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk"
Junio C Hamano671bc152005-11-27 16:12:51 -080012321}
Paul Mackerras1d10f362005-05-15 12:55:47 +000012322
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012323set gui_encoding [encoding system]
12324catch {
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012325 set enc [exec git config --get gui.encoding]
12326 if {$enc ne {}} {
Denton Liue2445882020-09-10 21:36:33 -070012327 set tclenc [tcl_encoding $enc]
12328 if {$tclenc ne {}} {
12329 set gui_encoding $tclenc
12330 } else {
12331 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk"
12332 }
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012333 }
Alexander Gavrilov09c70292008-10-13 12:12:31 +040012334}
12335
Marcus Karlssonb2b76d12011-10-04 22:08:13 +020012336set log_showroot true
12337catch {
12338 set log_showroot [exec git config --bool --get log.showroot]
12339}
12340
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +010012341if {[tk windowingsystem] eq "aqua"} {
12342 set mainfont {{Lucida Grande} 9}
12343 set textfont {Monaco 9}
12344 set uifont {{Lucida Grande} 9 bold}
Jonathan Nieder5c9096f2012-03-08 06:30:11 -060012345} elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} {
12346 # fontconfig!
12347 set mainfont {sans 9}
12348 set textfont {monospace 9}
12349 set uifont {sans 9 bold}
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +010012350} else {
12351 set mainfont {Helvetica 9}
12352 set textfont {Courier 9}
12353 set uifont {Helvetica 9 bold}
12354}
Mark Levedahl7e12f1a2007-05-20 11:45:50 -040012355set tabstop 8
Paul Mackerrasb74fd572005-07-16 07:46:13 -040012356set findmergefiles 0
Paul Mackerras8d858d12005-08-05 09:52:16 +100012357set maxgraphpct 50
Paul Mackerrasf6075eb2005-08-18 09:30:10 +100012358set maxwidth 16
Paul Mackerras232475d2005-11-15 10:34:03 +110012359set revlistorder 0
Paul Mackerras757f17b2005-11-21 09:56:07 +110012360set fastdate 0
Paul Mackerras6e8c8702007-07-31 21:03:06 +100012361set uparrowlen 5
12362set downarrowlen 5
12363set mingaplen 100
Paul Mackerrasf8b28a42006-05-01 09:50:57 +100012364set cmitmode "patch"
Sergey Vlasovf1b86292006-05-15 19:13:14 +040012365set wrapcomment "none"
Paul Mackerrasb8ab2e12006-06-03 19:11:13 +100012366set showneartags 1
Thomas Rastffe15292009-08-03 23:53:36 +020012367set hideremotes 0
Paul Mackerras0a4dd8b2007-06-16 21:21:57 +100012368set maxrefs 20
Max Kirillovbde4a0f2014-06-24 08:19:44 +030012369set visiblerefs {"master"}
Paul Mackerras322a8cc2006-10-15 18:03:46 +100012370set maxlinelen 200
Paul Mackerras219ea3a2006-09-07 10:21:39 +100012371set showlocalchanges 1
Paul Mackerras7a39a172007-10-23 10:15:11 +100012372set limitdiffs 1
Arjen Laarhovene8b5f4b2007-08-14 22:02:04 +020012373set datetimeformat "%Y-%m-%d %H:%M:%S"
Jeff King95293b52008-03-06 06:49:25 -050012374set autoselect 1
Paul Mackerras21ac8a82011-03-09 20:52:38 +110012375set autosellen 40
Paul Mackerras39ee47e2008-10-15 22:23:03 +110012376set perfile_attrs 0
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100012377set want_ttk 1
Paul Mackerras1d10f362005-05-15 12:55:47 +000012378
Daniel A. Steffen5fdcbb12009-03-23 12:17:38 +010012379if {[tk windowingsystem] eq "aqua"} {
12380 set extdifftool "opendiff"
12381} else {
12382 set extdifftool "meld"
12383}
Thomas Arcila314f5de2008-03-24 12:55:36 +010012384
Paul Mackerras6e8fda52016-12-12 11:29:21 +110012385set colors {"#00ff00" red blue magenta darkgrey brown orange}
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012386if {[tk windowingsystem] eq "win32"} {
12387 set uicolor SystemButtonFace
Gauthier Östervall252c52d2013-03-27 14:40:51 +010012388 set uifgcolor SystemButtonText
12389 set uifgdisabledcolor SystemDisabledText
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012390 set bgcolor SystemWindow
Gauthier Östervall252c52d2013-03-27 14:40:51 +010012391 set fgcolor SystemWindowText
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012392 set selectbgcolor SystemHighlight
Paul Mackerras3441de52019-08-27 08:12:34 +100012393 set web_browser "cmd /c start"
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012394} else {
12395 set uicolor grey85
Gauthier Östervall252c52d2013-03-27 14:40:51 +010012396 set uifgcolor black
12397 set uifgdisabledcolor "#999"
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012398 set bgcolor white
12399 set fgcolor black
12400 set selectbgcolor gray85
Paul Mackerras3441de52019-08-27 08:12:34 +100012401 if {[tk windowingsystem] eq "aqua"} {
Denton Liue2445882020-09-10 21:36:33 -070012402 set web_browser "open"
Paul Mackerras3441de52019-08-27 08:12:34 +100012403 } else {
Denton Liue2445882020-09-10 21:36:33 -070012404 set web_browser "xdg-open"
Paul Mackerras3441de52019-08-27 08:12:34 +100012405 }
Pat Thoyts1924d1b2009-11-06 23:28:01 +000012406}
Stefan Dotterweich113ce122020-02-11 22:24:48 +010012407set diffcolors {"#c30000" "#009800" blue}
12408set diffbgcolors {"#fff3f3" "#f0fff0"}
Steffen Prohaska890fae72007-08-12 12:05:46 +020012409set diffcontext 3
Paul Mackerras6e8fda52016-12-12 11:29:21 +110012410set mergecolors {red blue "#00ff00" purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
Steffen Prohaskab9b86002008-01-17 23:42:55 +010012411set ignorespace 0
Thomas Rastae4e3ff2010-10-16 12:15:10 +020012412set worddiff ""
Paul Mackerrase3e901b2008-10-27 22:37:21 +110012413set markbgcolor "#e0e0ff"
Paul Mackerras1d10f362005-05-15 12:55:47 +000012414
Paul Mackerras6e8fda52016-12-12 11:29:21 +110012415set headbgcolor "#00ff00"
Gauthier Östervall252c52d2013-03-27 14:40:51 +010012416set headfgcolor black
12417set headoutlinecolor black
12418set remotebgcolor #ffddaa
12419set tagbgcolor yellow
12420set tagfgcolor black
12421set tagoutlinecolor black
12422set reflinecolor black
12423set filesepbgcolor #aaaaaa
12424set filesepfgcolor black
12425set linehoverbgcolor #ffff80
12426set linehoverfgcolor black
12427set linehoveroutlinecolor black
12428set mainheadcirclecolor yellow
12429set workingfilescirclecolor red
Paul Mackerras6e8fda52016-12-12 11:29:21 +110012430set indexcirclecolor "#00ff00"
Paul Mackerrasc11ff122008-05-26 10:11:33 +100012431set circlecolors {white blue gray blue blue}
Gauthier Östervall252c52d2013-03-27 14:40:51 +010012432set linkfgcolor blue
12433set circleoutlinecolor $fgcolor
12434set foundbgcolor yellow
12435set currentsearchhitbgcolor orange
Paul Mackerrasc11ff122008-05-26 10:11:33 +100012436
Paul Mackerrasd277e892008-09-21 18:11:37 -050012437# button for popping up context menus
12438if {[tk windowingsystem] eq "aqua"} {
12439 set ctxbut <Button-2>
12440} else {
12441 set ctxbut <Button-3>
12442}
12443
Astril Hayato8f863392014-01-21 19:10:16 +000012444catch {
12445 # follow the XDG base directory specification by default. See
12446 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
12447 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} {
Denton Liue2445882020-09-10 21:36:33 -070012448 # XDG_CONFIG_HOME environment variable is set
12449 set config_file [file join $env(XDG_CONFIG_HOME) git gitk]
12450 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp]
Astril Hayato8f863392014-01-21 19:10:16 +000012451 } else {
Denton Liue2445882020-09-10 21:36:33 -070012452 # default XDG_CONFIG_HOME
12453 set config_file "~/.config/git/gitk"
12454 set config_file_tmp "~/.config/git/gitk-tmp"
Astril Hayato8f863392014-01-21 19:10:16 +000012455 }
12456 if {![file exists $config_file]} {
Denton Liue2445882020-09-10 21:36:33 -070012457 # for backward compatibility use the old config file if it exists
12458 if {[file exists "~/.gitk"]} {
12459 set config_file "~/.gitk"
12460 set config_file_tmp "~/.gitk-tmp"
12461 } elseif {![file exists [file dirname $config_file]]} {
12462 file mkdir [file dirname $config_file]
12463 }
Astril Hayato8f863392014-01-21 19:10:16 +000012464 }
12465 source $config_file
12466}
Max Kirilloveaf7e832015-03-04 05:58:18 +020012467config_check_tmp_exists 50
Paul Mackerras1d10f362005-05-15 12:55:47 +000012468
Max Kirillov9fabefb2014-09-14 23:35:57 +030012469set config_variables {
12470 mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
12471 cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12472 hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12473 bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
12474 markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
12475 extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor
12476 remotebgcolor tagbgcolor tagfgcolor tagoutlinecolor reflinecolor
12477 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12478 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
Stefan Dotterweich113ce122020-02-11 22:24:48 +010012479 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors
Paul Mackerras3441de52019-08-27 08:12:34 +100012480 web_browser
Max Kirillov9fabefb2014-09-14 23:35:57 +030012481}
Max Kirillov995f7922015-03-04 05:58:16 +020012482foreach var $config_variables {
12483 config_init_trace $var
12484 trace add variable $var write config_variable_change_cb
12485}
Max Kirillov9fabefb2014-09-14 23:35:57 +030012486
Paul Mackerras0ed1dd32007-10-06 18:27:37 +100012487parsefont mainfont $mainfont
12488eval font create mainfont [fontflags mainfont]
12489eval font create mainfontbold [fontflags mainfont 1]
12490
12491parsefont textfont $textfont
12492eval font create textfont [fontflags textfont]
12493eval font create textfontbold [fontflags textfont 1]
12494
12495parsefont uifont $uifont
12496eval font create uifont [fontflags uifont]
Paul Mackerras17386062005-05-18 22:51:00 +000012497
Paul Mackerras51a7e8b2009-11-14 21:15:01 +110012498setui $uicolor
Guillermo S. Romero5497f7a2009-10-15 18:51:49 +020012499
Paul Mackerrasb039f0a2008-01-06 15:54:46 +110012500setoptions
12501
Paul Mackerrasaa81d972006-02-28 11:27:12 +110012502# check that we can find a .git directory somewhere...
Martin von Zweigbergk86e847b2011-04-04 22:14:18 -040012503if {[catch {set gitdir [exec git rev-parse --git-dir]}]} {
Christian Stimmingd990ced2007-11-07 18:42:55 +010012504 show_error {} . [mc "Cannot find a git repository here."]
Alex Riesen6c87d602007-07-29 22:29:45 +020012505 exit 1
12506}
Paul Mackerrasaa81d972006-02-28 11:27:12 +110012507
Alexander Gavrilov39816d62008-08-23 12:27:44 +040012508set selecthead {}
12509set selectheadid {}
12510
Paul Mackerrascdaee5d2007-07-12 22:29:49 +100012511set revtreeargs {}
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012512set cmdline_files {}
Paul Mackerrascdaee5d2007-07-12 22:29:49 +100012513set i 0
Yann Dirson2d480852008-02-21 21:23:31 +010012514set revtreeargscmd {}
Paul Mackerrascdaee5d2007-07-12 22:29:49 +100012515foreach arg $argv {
Yann Dirson2d480852008-02-21 21:23:31 +010012516 switch -glob -- $arg {
Denton Liue2445882020-09-10 21:36:33 -070012517 "" { }
12518 "--" {
12519 set cmdline_files [lrange $argv [expr {$i + 1}] end]
12520 break
12521 }
12522 "--select-commit=*" {
12523 set selecthead [string range $arg 16 end]
12524 }
12525 "--argscmd=*" {
12526 set revtreeargscmd [string range $arg 10 end]
12527 }
12528 default {
12529 lappend revtreeargs $arg
12530 }
Paul Mackerrascdaee5d2007-07-12 22:29:49 +100012531 }
12532 incr i
12533}
12534
Alexander Gavrilov39816d62008-08-23 12:27:44 +040012535if {$selecthead eq "HEAD"} {
12536 set selecthead {}
12537}
12538
Paul Mackerrascdaee5d2007-07-12 22:29:49 +100012539if {$i >= [llength $argv] && $revtreeargs ne {}} {
Paul Mackerras3ed31a82008-04-26 16:00:00 +100012540 # no -- on command line, but some arguments (other than --argscmd)
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012541 if {[catch {
Denton Liue2445882020-09-10 21:36:33 -070012542 set f [eval exec git rev-parse --no-revs --no-flags $revtreeargs]
12543 set cmdline_files [split $f "\n"]
12544 set n [llength $cmdline_files]
12545 set revtreeargs [lrange $revtreeargs 0 end-$n]
12546 # Unfortunately git rev-parse doesn't produce an error when
12547 # something is both a revision and a filename. To be consistent
12548 # with git log and git rev-list, check revtreeargs for filenames.
12549 foreach arg $revtreeargs {
12550 if {[file exists $arg]} {
12551 show_error {} . [mc "Ambiguous argument '%s': both revision\
12552 and filename" $arg]
12553 exit 1
12554 }
12555 }
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012556 } err]} {
Denton Liue2445882020-09-10 21:36:33 -070012557 # unfortunately we get both stdout and stderr in $err,
12558 # so look for "fatal:".
12559 set i [string first "fatal:" $err]
12560 if {$i > 0} {
12561 set err [string range $err [expr {$i + 6}] end]
12562 }
12563 show_error {} . "[mc "Bad arguments to gitk:"]\n$err"
12564 exit 1
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012565 }
12566}
12567
Paul Mackerras219ea3a2006-09-07 10:21:39 +100012568set nullid "0000000000000000000000000000000000000000"
Paul Mackerras8f489362007-07-13 19:49:37 +100012569set nullid2 "0000000000000000000000000000000000000001"
Thomas Arcila314f5de2008-03-24 12:55:36 +010012570set nullfile "/dev/null"
Paul Mackerras8f489362007-07-13 19:49:37 +100012571
Paul Mackerras32f1b3e2007-09-28 21:27:39 +100012572set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100012573if {![info exists have_ttk]} {
12574 set have_ttk [llength [info commands ::ttk::style]]
Pat Thoytsd93f1712009-04-17 01:24:35 +010012575}
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100012576set use_ttk [expr {$have_ttk && $want_ttk}]
Pat Thoytsd93f1712009-04-17 01:24:35 +010012577set NS [expr {$use_ttk ? "ttk" : ""}]
Paul Mackerras0cc08ff2009-09-05 22:06:46 +100012578
Giuseppe Bilotta6cb73c82015-12-08 08:05:50 +010012579if {$use_ttk} {
12580 setttkstyle
12581}
12582
Anders Kaseorg7add5af2011-01-06 17:42:33 -070012583regexp {^git version ([\d.]*\d)} [exec git version] _ git_version
Paul Mackerras219ea3a2006-09-07 10:21:39 +100012584
Kirill Smelkov7defefb2010-05-20 13:50:41 +040012585set show_notes {}
12586if {[package vcompare $git_version "1.6.6.2"] >= 0} {
12587 set show_notes "--show-notes"
12588}
12589
Zbigniew Jędrzejewski-Szmek3878e632011-11-09 17:28:28 +010012590set appname "gitk"
12591
Paul Mackerras7eb3cb92007-06-17 14:45:00 +100012592set runq {}
Paul Mackerrasd6982062005-08-06 22:06:06 +100012593set history {}
12594set historyindex 0
Paul Mackerras908c3582006-05-20 09:38:11 +100012595set fh_serial 0
Paul Mackerras908c3582006-05-20 09:38:11 +100012596set nhl_names {}
Paul Mackerras63b79192006-05-20 21:31:52 +100012597set highlight_paths {}
Paul Mackerras687c8762007-09-22 12:49:33 +100012598set findpattern {}
Paul Mackerras1902c272006-05-25 21:25:13 +100012599set searchdirn -forwards
Paul Mackerras28593d32008-11-13 23:01:46 +110012600set boldids {}
12601set boldnameids {}
Paul Mackerrasa8d610a2007-04-19 11:39:12 +100012602set diffelide {0 0}
Paul Mackerras4fb0fa12007-07-04 19:43:51 +100012603set markingmatches 0
Paul Mackerras97645682007-08-23 22:24:38 +100012604set linkentercount 0
Paul Mackerras03800812007-08-29 21:45:21 +100012605set need_redisplay 0
12606set nrows_drawn 0
Paul Mackerras32f1b3e2007-09-28 21:27:39 +100012607set firsttabstop 0
Paul Mackerras9f1afe02006-02-19 22:44:47 +110012608
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012609set nextviewnum 1
12610set curview 0
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012611set selectedview 0
Christian Stimmingb007ee22007-11-07 18:44:35 +010012612set selectedhlview [mc "None"]
12613set highlight_related [mc "None"]
Paul Mackerras687c8762007-09-22 12:49:33 +100012614set highlight_files {}
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012615set viewfiles(0) {}
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012616set viewperm(0) 0
Max Kirillov995f7922015-03-04 05:58:16 +020012617set viewchanged(0) 0
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012618set viewargs(0) {}
Yann Dirson2d480852008-02-21 21:23:31 +010012619set viewargscmd(0) {}
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012620
Paul Mackerras94b4a692008-05-20 20:51:06 +100012621set selectedline {}
Paul Mackerras6df74032008-05-11 22:13:02 +100012622set numcommits 0
Paul Mackerras7fcc92b2007-12-03 10:33:01 +110012623set loginstance 0
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012624set cmdlineok 0
Paul Mackerras1d10f362005-05-15 12:55:47 +000012625set stopped 0
Paul Mackerras0fba86b2005-05-16 23:54:58 +000012626set stuffsaved 0
Paul Mackerras74daedb2005-06-27 19:27:32 +100012627set patchnum 0
Paul Mackerras219ea3a2006-09-07 10:21:39 +100012628set lserial 0
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -040012629set hasworktree [hasworktree]
Martin von Zweigbergkc332f442011-04-04 22:14:12 -040012630set cdup {}
Martin von Zweigbergk74cb8842011-05-23 22:44:08 -040012631if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} {
Martin von Zweigbergkc332f442011-04-04 22:14:12 -040012632 set cdup [exec git rev-parse --show-cdup]
12633}
Junio C Hamanoe272a772020-01-23 11:20:36 -080012634set worktree [gitworktree]
Paul Mackerras1d10f362005-05-15 12:55:47 +000012635setcoords
Paul Mackerrasd94f8cd2006-04-06 10:18:23 +100012636makewindow
Giuseppe Bilotta37871b72009-03-19 01:54:17 -070012637catch {
12638 image create photo gitlogo -width 16 -height 16
12639
12640 image create photo gitlogominus -width 4 -height 2
12641 gitlogominus put #C00000 -to 0 0 4 2
12642 gitlogo copy gitlogominus -to 1 5
12643 gitlogo copy gitlogominus -to 6 5
12644 gitlogo copy gitlogominus -to 11 5
12645 image delete gitlogominus
12646
12647 image create photo gitlogoplus -width 4 -height 4
12648 gitlogoplus put #008000 -to 1 0 3 4
12649 gitlogoplus put #008000 -to 0 1 4 3
12650 gitlogo copy gitlogoplus -to 1 9
12651 gitlogo copy gitlogoplus -to 6 9
12652 gitlogo copy gitlogoplus -to 11 9
12653 image delete gitlogoplus
12654
Stephen Boydd38d7d42009-03-19 01:54:18 -070012655 image create photo gitlogo32 -width 32 -height 32
12656 gitlogo32 copy gitlogo -zoom 2 2
12657
12658 wm iconphoto . -default gitlogo gitlogo32
Giuseppe Bilotta37871b72009-03-19 01:54:17 -070012659}
Paul Mackerras0eafba12007-07-23 21:35:03 +100012660# wait for the window to become visible
12661tkwait visibility .
Marc Branchaud9922c5a2015-04-07 11:51:51 -040012662set_window_title
Pat Thoyts478afad2009-04-15 17:14:03 +010012663update
Paul Mackerras887fe3c2005-05-21 07:35:37 +000012664readrefs
Paul Mackerrasa8aaf192006-04-23 22:45:55 +100012665
Yann Dirson2d480852008-02-21 21:23:31 +010012666if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} {
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012667 # create a view for the files/dirs specified on the command line
12668 set curview 1
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012669 set selectedview 1
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012670 set nextviewnum 2
Christian Stimmingd990ced2007-11-07 18:42:55 +010012671 set viewname(1) [mc "Command line"]
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012672 set viewfiles(1) $cmdline_files
Paul Mackerras098dd8a2006-05-03 09:32:53 +100012673 set viewargs(1) $revtreeargs
Yann Dirson2d480852008-02-21 21:23:31 +010012674 set viewargscmd(1) $revtreeargscmd
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012675 set viewperm(1) 0
Max Kirillov995f7922015-03-04 05:58:16 +020012676 set viewchanged(1) 0
Paul Mackerras3ed31a82008-04-26 16:00:00 +100012677 set vdatemode(1) 0
Paul Mackerrasda7c24d2006-05-02 11:15:29 +100012678 addviewmenu 1
Beat Bolli28de5682015-09-30 21:50:11 +020012679 .bar.view entryconf [mca "&Edit view..."] -state normal
12680 .bar.view entryconf [mca "&Delete view"] -state normal
Paul Mackerras50b44ec2006-04-04 10:16:22 +100012681}
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012682
12683if {[info exists permviews]} {
12684 foreach v $permviews {
Denton Liue2445882020-09-10 21:36:33 -070012685 set n $nextviewnum
12686 incr nextviewnum
12687 set viewname($n) [lindex $v 0]
12688 set viewfiles($n) [lindex $v 1]
12689 set viewargs($n) [lindex $v 2]
12690 set viewargscmd($n) [lindex $v 3]
12691 set viewperm($n) 1
12692 set viewchanged($n) 0
12693 addviewmenu $n
Paul Mackerrasa90a6d22006-04-25 17:12:46 +100012694 }
12695}
Johannes Sixte4df5192008-12-18 08:30:49 +010012696
12697if {[tk windowingsystem] eq "win32"} {
12698 focus -force .
12699}
12700
Alexander Gavrilov567c34e2008-07-26 20:13:45 +040012701getcommits {}
Pat Thoytsadab0da2010-03-12 18:31:48 +000012702
12703# Local variables:
12704# mode: tcl
12705# indent-tabs-mode: t
12706# tab-width: 8
12707# End: