##// END OF EJS Templates
hgk: enable mouse wheel on MouseWheel events....
Patrick Mezard -
r4968:71342663 default
parent child Browse files
Show More
@@ -1,3684 +1,3690 b''
1 #!/usr/bin/env wish
1 #!/usr/bin/env wish
2
2
3 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
3 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
4 # This program is free software; it may be used, copied, modified
4 # This program is free software; it may be used, copied, modified
5 # and distributed under the terms of the GNU General Public Licence,
5 # and distributed under the terms of the GNU General Public Licence,
6 # either version 2, or (at your option) any later version.
6 # either version 2, or (at your option) any later version.
7
7
8 proc gitdir {} {
8 proc gitdir {} {
9 global env
9 global env
10 if {[info exists env(GIT_DIR)]} {
10 if {[info exists env(GIT_DIR)]} {
11 return $env(GIT_DIR)
11 return $env(GIT_DIR)
12 } else {
12 } else {
13 return ".hg"
13 return ".hg"
14 }
14 }
15 }
15 }
16
16
17 proc getcommits {rargs} {
17 proc getcommits {rargs} {
18 global commits commfd phase canv mainfont env
18 global commits commfd phase canv mainfont env
19 global startmsecs nextupdate ncmupdate
19 global startmsecs nextupdate ncmupdate
20 global ctext maincursor textcursor leftover
20 global ctext maincursor textcursor leftover
21
21
22 # check that we can find a .git directory somewhere...
22 # check that we can find a .git directory somewhere...
23 set gitdir [gitdir]
23 set gitdir [gitdir]
24 if {![file isdirectory $gitdir]} {
24 if {![file isdirectory $gitdir]} {
25 error_popup "Cannot find the git directory \"$gitdir\"."
25 error_popup "Cannot find the git directory \"$gitdir\"."
26 exit 1
26 exit 1
27 }
27 }
28 set commits {}
28 set commits {}
29 set phase getcommits
29 set phase getcommits
30 set startmsecs [clock clicks -milliseconds]
30 set startmsecs [clock clicks -milliseconds]
31 set nextupdate [expr $startmsecs + 100]
31 set nextupdate [expr $startmsecs + 100]
32 set ncmupdate 1
32 set ncmupdate 1
33 set limit 0
33 set limit 0
34 set revargs {}
34 set revargs {}
35 for {set i 0} {$i < [llength $rargs]} {incr i} {
35 for {set i 0} {$i < [llength $rargs]} {incr i} {
36 set opt [lindex $rargs $i]
36 set opt [lindex $rargs $i]
37 if {$opt == "--limit"} {
37 if {$opt == "--limit"} {
38 incr i
38 incr i
39 set limit [lindex $rargs $i]
39 set limit [lindex $rargs $i]
40 } else {
40 } else {
41 lappend revargs $opt
41 lappend revargs $opt
42 }
42 }
43 }
43 }
44 if [catch {
44 if [catch {
45 set parse_args [concat --default HEAD $revargs]
45 set parse_args [concat --default HEAD $revargs]
46 set parse_temp [eval exec {$env(HG)} --config ui.report_untrusted=false debug-rev-parse $parse_args]
46 set parse_temp [eval exec {$env(HG)} --config ui.report_untrusted=false debug-rev-parse $parse_args]
47 regsub -all "\r\n" $parse_temp "\n" parse_temp
47 regsub -all "\r\n" $parse_temp "\n" parse_temp
48 set parsed_args [split $parse_temp "\n"]
48 set parsed_args [split $parse_temp "\n"]
49 } err] {
49 } err] {
50 # if git-rev-parse failed for some reason...
50 # if git-rev-parse failed for some reason...
51 if {$rargs == {}} {
51 if {$rargs == {}} {
52 set revargs HEAD
52 set revargs HEAD
53 }
53 }
54 set parsed_args $revargs
54 set parsed_args $revargs
55 }
55 }
56 if {$limit > 0} {
56 if {$limit > 0} {
57 set parsed_args [concat -n $limit $parsed_args]
57 set parsed_args [concat -n $limit $parsed_args]
58 }
58 }
59 if [catch {
59 if [catch {
60 set commfd [open "|{$env(HG)} --config ui.report_untrusted=false debug-rev-list --header --topo-order --parents $parsed_args" r]
60 set commfd [open "|{$env(HG)} --config ui.report_untrusted=false debug-rev-list --header --topo-order --parents $parsed_args" r]
61 } err] {
61 } err] {
62 puts stderr "Error executing hg debug-rev-list: $err"
62 puts stderr "Error executing hg debug-rev-list: $err"
63 exit 1
63 exit 1
64 }
64 }
65 set leftover {}
65 set leftover {}
66 fconfigure $commfd -blocking 0 -translation lf
66 fconfigure $commfd -blocking 0 -translation lf
67 fileevent $commfd readable [list getcommitlines $commfd]
67 fileevent $commfd readable [list getcommitlines $commfd]
68 $canv delete all
68 $canv delete all
69 $canv create text 3 3 -anchor nw -text "Reading commits..." \
69 $canv create text 3 3 -anchor nw -text "Reading commits..." \
70 -font $mainfont -tags textitems
70 -font $mainfont -tags textitems
71 . config -cursor watch
71 . config -cursor watch
72 settextcursor watch
72 settextcursor watch
73 }
73 }
74
74
75 proc getcommitlines {commfd} {
75 proc getcommitlines {commfd} {
76 global commits parents cdate children
76 global commits parents cdate children
77 global commitlisted phase commitinfo nextupdate
77 global commitlisted phase commitinfo nextupdate
78 global stopped redisplaying leftover
78 global stopped redisplaying leftover
79
79
80 set stuff [read $commfd]
80 set stuff [read $commfd]
81 if {$stuff == {}} {
81 if {$stuff == {}} {
82 if {![eof $commfd]} return
82 if {![eof $commfd]} return
83 # set it blocking so we wait for the process to terminate
83 # set it blocking so we wait for the process to terminate
84 fconfigure $commfd -blocking 1
84 fconfigure $commfd -blocking 1
85 if {![catch {close $commfd} err]} {
85 if {![catch {close $commfd} err]} {
86 after idle finishcommits
86 after idle finishcommits
87 return
87 return
88 }
88 }
89 if {[string range $err 0 4] == "usage"} {
89 if {[string range $err 0 4] == "usage"} {
90 set err \
90 set err \
91 {Gitk: error reading commits: bad arguments to git-rev-list.
91 {Gitk: error reading commits: bad arguments to git-rev-list.
92 (Note: arguments to gitk are passed to git-rev-list
92 (Note: arguments to gitk are passed to git-rev-list
93 to allow selection of commits to be displayed.)}
93 to allow selection of commits to be displayed.)}
94 } else {
94 } else {
95 set err "Error reading commits: $err"
95 set err "Error reading commits: $err"
96 }
96 }
97 error_popup $err
97 error_popup $err
98 exit 1
98 exit 1
99 }
99 }
100 set start 0
100 set start 0
101 while 1 {
101 while 1 {
102 set i [string first "\0" $stuff $start]
102 set i [string first "\0" $stuff $start]
103 if {$i < 0} {
103 if {$i < 0} {
104 append leftover [string range $stuff $start end]
104 append leftover [string range $stuff $start end]
105 return
105 return
106 }
106 }
107 set cmit [string range $stuff $start [expr {$i - 1}]]
107 set cmit [string range $stuff $start [expr {$i - 1}]]
108 if {$start == 0} {
108 if {$start == 0} {
109 set cmit "$leftover$cmit"
109 set cmit "$leftover$cmit"
110 set leftover {}
110 set leftover {}
111 }
111 }
112 set start [expr {$i + 1}]
112 set start [expr {$i + 1}]
113 regsub -all "\r\n" $cmit "\n" cmit
113 regsub -all "\r\n" $cmit "\n" cmit
114 set j [string first "\n" $cmit]
114 set j [string first "\n" $cmit]
115 set ok 0
115 set ok 0
116 if {$j >= 0} {
116 if {$j >= 0} {
117 set ids [string range $cmit 0 [expr {$j - 1}]]
117 set ids [string range $cmit 0 [expr {$j - 1}]]
118 set ok 1
118 set ok 1
119 foreach id $ids {
119 foreach id $ids {
120 if {![regexp {^[0-9a-f]{12}$} $id]} {
120 if {![regexp {^[0-9a-f]{12}$} $id]} {
121 set ok 0
121 set ok 0
122 break
122 break
123 }
123 }
124 }
124 }
125 }
125 }
126 if {!$ok} {
126 if {!$ok} {
127 set shortcmit $cmit
127 set shortcmit $cmit
128 if {[string length $shortcmit] > 80} {
128 if {[string length $shortcmit] > 80} {
129 set shortcmit "[string range $shortcmit 0 80]..."
129 set shortcmit "[string range $shortcmit 0 80]..."
130 }
130 }
131 error_popup "Can't parse hg debug-rev-list output: {$shortcmit}"
131 error_popup "Can't parse hg debug-rev-list output: {$shortcmit}"
132 exit 1
132 exit 1
133 }
133 }
134 set id [lindex $ids 0]
134 set id [lindex $ids 0]
135 set olds [lrange $ids 1 end]
135 set olds [lrange $ids 1 end]
136 set cmit [string range $cmit [expr {$j + 1}] end]
136 set cmit [string range $cmit [expr {$j + 1}] end]
137 lappend commits $id
137 lappend commits $id
138 set commitlisted($id) 1
138 set commitlisted($id) 1
139 parsecommit $id $cmit 1 [lrange $ids 1 end]
139 parsecommit $id $cmit 1 [lrange $ids 1 end]
140 drawcommit $id
140 drawcommit $id
141 if {[clock clicks -milliseconds] >= $nextupdate} {
141 if {[clock clicks -milliseconds] >= $nextupdate} {
142 doupdate 1
142 doupdate 1
143 }
143 }
144 while {$redisplaying} {
144 while {$redisplaying} {
145 set redisplaying 0
145 set redisplaying 0
146 if {$stopped == 1} {
146 if {$stopped == 1} {
147 set stopped 0
147 set stopped 0
148 set phase "getcommits"
148 set phase "getcommits"
149 foreach id $commits {
149 foreach id $commits {
150 drawcommit $id
150 drawcommit $id
151 if {$stopped} break
151 if {$stopped} break
152 if {[clock clicks -milliseconds] >= $nextupdate} {
152 if {[clock clicks -milliseconds] >= $nextupdate} {
153 doupdate 1
153 doupdate 1
154 }
154 }
155 }
155 }
156 }
156 }
157 }
157 }
158 }
158 }
159 }
159 }
160
160
161 proc doupdate {reading} {
161 proc doupdate {reading} {
162 global commfd nextupdate numcommits ncmupdate
162 global commfd nextupdate numcommits ncmupdate
163
163
164 if {$reading} {
164 if {$reading} {
165 fileevent $commfd readable {}
165 fileevent $commfd readable {}
166 }
166 }
167 update
167 update
168 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
168 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
169 if {$numcommits < 100} {
169 if {$numcommits < 100} {
170 set ncmupdate [expr {$numcommits + 1}]
170 set ncmupdate [expr {$numcommits + 1}]
171 } elseif {$numcommits < 10000} {
171 } elseif {$numcommits < 10000} {
172 set ncmupdate [expr {$numcommits + 10}]
172 set ncmupdate [expr {$numcommits + 10}]
173 } else {
173 } else {
174 set ncmupdate [expr {$numcommits + 100}]
174 set ncmupdate [expr {$numcommits + 100}]
175 }
175 }
176 if {$reading} {
176 if {$reading} {
177 fileevent $commfd readable [list getcommitlines $commfd]
177 fileevent $commfd readable [list getcommitlines $commfd]
178 }
178 }
179 }
179 }
180
180
181 proc readcommit {id} {
181 proc readcommit {id} {
182 global env
182 global env
183 if [catch {set contents [exec $env(HG) --config ui.report_untrusted=false debug-cat-file commit $id]}] return
183 if [catch {set contents [exec $env(HG) --config ui.report_untrusted=false debug-cat-file commit $id]}] return
184 parsecommit $id $contents 0 {}
184 parsecommit $id $contents 0 {}
185 }
185 }
186
186
187 proc parsecommit {id contents listed olds} {
187 proc parsecommit {id contents listed olds} {
188 global commitinfo children nchildren parents nparents cdate ncleft
188 global commitinfo children nchildren parents nparents cdate ncleft
189
189
190 set inhdr 1
190 set inhdr 1
191 set comment {}
191 set comment {}
192 set headline {}
192 set headline {}
193 set auname {}
193 set auname {}
194 set audate {}
194 set audate {}
195 set comname {}
195 set comname {}
196 set comdate {}
196 set comdate {}
197 set rev {}
197 set rev {}
198 if {![info exists nchildren($id)]} {
198 if {![info exists nchildren($id)]} {
199 set children($id) {}
199 set children($id) {}
200 set nchildren($id) 0
200 set nchildren($id) 0
201 set ncleft($id) 0
201 set ncleft($id) 0
202 }
202 }
203 set parents($id) $olds
203 set parents($id) $olds
204 set nparents($id) [llength $olds]
204 set nparents($id) [llength $olds]
205 foreach p $olds {
205 foreach p $olds {
206 if {![info exists nchildren($p)]} {
206 if {![info exists nchildren($p)]} {
207 set children($p) [list $id]
207 set children($p) [list $id]
208 set nchildren($p) 1
208 set nchildren($p) 1
209 set ncleft($p) 1
209 set ncleft($p) 1
210 } elseif {[lsearch -exact $children($p) $id] < 0} {
210 } elseif {[lsearch -exact $children($p) $id] < 0} {
211 lappend children($p) $id
211 lappend children($p) $id
212 incr nchildren($p)
212 incr nchildren($p)
213 incr ncleft($p)
213 incr ncleft($p)
214 }
214 }
215 }
215 }
216 regsub -all "\r\n" $contents "\n" contents
216 regsub -all "\r\n" $contents "\n" contents
217 foreach line [split $contents "\n"] {
217 foreach line [split $contents "\n"] {
218 if {$inhdr} {
218 if {$inhdr} {
219 set line [split $line]
219 set line [split $line]
220 if {$line == {}} {
220 if {$line == {}} {
221 set inhdr 0
221 set inhdr 0
222 } else {
222 } else {
223 set tag [lindex $line 0]
223 set tag [lindex $line 0]
224 if {$tag == "author"} {
224 if {$tag == "author"} {
225 set x [expr {[llength $line] - 2}]
225 set x [expr {[llength $line] - 2}]
226 set audate [lindex $line $x]
226 set audate [lindex $line $x]
227 set auname [join [lrange $line 1 [expr {$x - 1}]]]
227 set auname [join [lrange $line 1 [expr {$x - 1}]]]
228 } elseif {$tag == "committer"} {
228 } elseif {$tag == "committer"} {
229 set x [expr {[llength $line] - 2}]
229 set x [expr {[llength $line] - 2}]
230 set comdate [lindex $line $x]
230 set comdate [lindex $line $x]
231 set comname [join [lrange $line 1 [expr {$x - 1}]]]
231 set comname [join [lrange $line 1 [expr {$x - 1}]]]
232 } elseif {$tag == "revision"} {
232 } elseif {$tag == "revision"} {
233 set rev [lindex $line 1]
233 set rev [lindex $line 1]
234 }
234 }
235 }
235 }
236 } else {
236 } else {
237 if {$comment == {}} {
237 if {$comment == {}} {
238 set headline [string trim $line]
238 set headline [string trim $line]
239 } else {
239 } else {
240 append comment "\n"
240 append comment "\n"
241 }
241 }
242 if {!$listed} {
242 if {!$listed} {
243 # git-rev-list indents the comment by 4 spaces;
243 # git-rev-list indents the comment by 4 spaces;
244 # if we got this via git-cat-file, add the indentation
244 # if we got this via git-cat-file, add the indentation
245 append comment " "
245 append comment " "
246 }
246 }
247 append comment $line
247 append comment $line
248 }
248 }
249 }
249 }
250 if {$audate != {}} {
250 if {$audate != {}} {
251 set audate [clock format $audate -format "%Y-%m-%d %H:%M:%S"]
251 set audate [clock format $audate -format "%Y-%m-%d %H:%M:%S"]
252 }
252 }
253 if {$comdate != {}} {
253 if {$comdate != {}} {
254 set cdate($id) $comdate
254 set cdate($id) $comdate
255 set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
255 set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
256 }
256 }
257 set commitinfo($id) [list $headline $auname $audate \
257 set commitinfo($id) [list $headline $auname $audate \
258 $comname $comdate $comment $rev]
258 $comname $comdate $comment $rev]
259 }
259 }
260
260
261 proc readrefs {} {
261 proc readrefs {} {
262 global tagids idtags headids idheads tagcontents env
262 global tagids idtags headids idheads tagcontents env
263
263
264 set tags [exec $env(HG) --config ui.report_untrusted=false tags]
264 set tags [exec $env(HG) --config ui.report_untrusted=false tags]
265 regsub -all "\r\n" $tags "\n" tags
265 regsub -all "\r\n" $tags "\n" tags
266 set lines [split $tags "\n"]
266 set lines [split $tags "\n"]
267 foreach f $lines {
267 foreach f $lines {
268 regexp {(\S+)$} $f full
268 regexp {(\S+)$} $f full
269 regsub {\s+(\S+)$} $f "" direct
269 regsub {\s+(\S+)$} $f "" direct
270 set sha [split $full ':']
270 set sha [split $full ':']
271 set tag [lindex $sha 1]
271 set tag [lindex $sha 1]
272 lappend tagids($direct) $tag
272 lappend tagids($direct) $tag
273 lappend idtags($tag) $direct
273 lappend idtags($tag) $direct
274 }
274 }
275 }
275 }
276
276
277 proc readotherrefs {base dname excl} {
277 proc readotherrefs {base dname excl} {
278 global otherrefids idotherrefs
278 global otherrefids idotherrefs
279
279
280 set git [gitdir]
280 set git [gitdir]
281 set files [glob -nocomplain -types f [file join $git $base *]]
281 set files [glob -nocomplain -types f [file join $git $base *]]
282 foreach f $files {
282 foreach f $files {
283 catch {
283 catch {
284 set fd [open $f r]
284 set fd [open $f r]
285 set line [read $fd 40]
285 set line [read $fd 40]
286 if {[regexp {^[0-9a-f]{12}} $line id]} {
286 if {[regexp {^[0-9a-f]{12}} $line id]} {
287 set name "$dname[file tail $f]"
287 set name "$dname[file tail $f]"
288 set otherrefids($name) $id
288 set otherrefids($name) $id
289 lappend idotherrefs($id) $name
289 lappend idotherrefs($id) $name
290 }
290 }
291 close $fd
291 close $fd
292 }
292 }
293 }
293 }
294 set dirs [glob -nocomplain -types d [file join $git $base *]]
294 set dirs [glob -nocomplain -types d [file join $git $base *]]
295 foreach d $dirs {
295 foreach d $dirs {
296 set dir [file tail $d]
296 set dir [file tail $d]
297 if {[lsearch -exact $excl $dir] >= 0} continue
297 if {[lsearch -exact $excl $dir] >= 0} continue
298 readotherrefs [file join $base $dir] "$dname$dir/" {}
298 readotherrefs [file join $base $dir] "$dname$dir/" {}
299 }
299 }
300 }
300 }
301
301
302 proc allcansmousewheel {delta} {
303 set delta [expr -5*(int($delta)/abs($delta))]
304 allcanvs yview scroll $delta units
305 }
306
302 proc error_popup msg {
307 proc error_popup msg {
303 set w .error
308 set w .error
304 toplevel $w
309 toplevel $w
305 wm transient $w .
310 wm transient $w .
306 message $w.m -text $msg -justify center -aspect 400
311 message $w.m -text $msg -justify center -aspect 400
307 pack $w.m -side top -fill x -padx 20 -pady 20
312 pack $w.m -side top -fill x -padx 20 -pady 20
308 button $w.ok -text OK -command "destroy $w"
313 button $w.ok -text OK -command "destroy $w"
309 pack $w.ok -side bottom -fill x
314 pack $w.ok -side bottom -fill x
310 bind $w <Visibility> "grab $w; focus $w"
315 bind $w <Visibility> "grab $w; focus $w"
311 tkwait window $w
316 tkwait window $w
312 }
317 }
313
318
314 proc makewindow {} {
319 proc makewindow {} {
315 global canv canv2 canv3 linespc charspc ctext cflist textfont
320 global canv canv2 canv3 linespc charspc ctext cflist textfont
316 global findtype findtypemenu findloc findstring fstring geometry
321 global findtype findtypemenu findloc findstring fstring geometry
317 global entries sha1entry sha1string sha1but
322 global entries sha1entry sha1string sha1but
318 global maincursor textcursor curtextcursor
323 global maincursor textcursor curtextcursor
319 global rowctxmenu gaudydiff mergemax
324 global rowctxmenu gaudydiff mergemax
320
325
321 menu .bar
326 menu .bar
322 .bar add cascade -label "File" -menu .bar.file
327 .bar add cascade -label "File" -menu .bar.file
323 menu .bar.file
328 menu .bar.file
324 .bar.file add command -label "Reread references" -command rereadrefs
329 .bar.file add command -label "Reread references" -command rereadrefs
325 .bar.file add command -label "Quit" -command doquit
330 .bar.file add command -label "Quit" -command doquit
326 menu .bar.help
331 menu .bar.help
327 .bar add cascade -label "Help" -menu .bar.help
332 .bar add cascade -label "Help" -menu .bar.help
328 .bar.help add command -label "About gitk" -command about
333 .bar.help add command -label "About gitk" -command about
329 . configure -menu .bar
334 . configure -menu .bar
330
335
331 if {![info exists geometry(canv1)]} {
336 if {![info exists geometry(canv1)]} {
332 set geometry(canv1) [expr 45 * $charspc]
337 set geometry(canv1) [expr 45 * $charspc]
333 set geometry(canv2) [expr 30 * $charspc]
338 set geometry(canv2) [expr 30 * $charspc]
334 set geometry(canv3) [expr 15 * $charspc]
339 set geometry(canv3) [expr 15 * $charspc]
335 set geometry(canvh) [expr 25 * $linespc + 4]
340 set geometry(canvh) [expr 25 * $linespc + 4]
336 set geometry(ctextw) 80
341 set geometry(ctextw) 80
337 set geometry(ctexth) 30
342 set geometry(ctexth) 30
338 set geometry(cflistw) 30
343 set geometry(cflistw) 30
339 }
344 }
340 panedwindow .ctop -orient vertical
345 panedwindow .ctop -orient vertical
341 if {[info exists geometry(width)]} {
346 if {[info exists geometry(width)]} {
342 .ctop conf -width $geometry(width) -height $geometry(height)
347 .ctop conf -width $geometry(width) -height $geometry(height)
343 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
348 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
344 set geometry(ctexth) [expr {($texth - 8) /
349 set geometry(ctexth) [expr {($texth - 8) /
345 [font metrics $textfont -linespace]}]
350 [font metrics $textfont -linespace]}]
346 }
351 }
347 frame .ctop.top
352 frame .ctop.top
348 frame .ctop.top.bar
353 frame .ctop.top.bar
349 pack .ctop.top.bar -side bottom -fill x
354 pack .ctop.top.bar -side bottom -fill x
350 set cscroll .ctop.top.csb
355 set cscroll .ctop.top.csb
351 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
356 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
352 pack $cscroll -side right -fill y
357 pack $cscroll -side right -fill y
353 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
358 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
354 pack .ctop.top.clist -side top -fill both -expand 1
359 pack .ctop.top.clist -side top -fill both -expand 1
355 .ctop add .ctop.top
360 .ctop add .ctop.top
356 set canv .ctop.top.clist.canv
361 set canv .ctop.top.clist.canv
357 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
362 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
358 -bg white -bd 0 \
363 -bg white -bd 0 \
359 -yscrollincr $linespc -yscrollcommand "$cscroll set" -selectbackground grey
364 -yscrollincr $linespc -yscrollcommand "$cscroll set" -selectbackground grey
360 .ctop.top.clist add $canv
365 .ctop.top.clist add $canv
361 set canv2 .ctop.top.clist.canv2
366 set canv2 .ctop.top.clist.canv2
362 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
367 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
363 -bg white -bd 0 -yscrollincr $linespc -selectbackground grey
368 -bg white -bd 0 -yscrollincr $linespc -selectbackground grey
364 .ctop.top.clist add $canv2
369 .ctop.top.clist add $canv2
365 set canv3 .ctop.top.clist.canv3
370 set canv3 .ctop.top.clist.canv3
366 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
371 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
367 -bg white -bd 0 -yscrollincr $linespc -selectbackground grey
372 -bg white -bd 0 -yscrollincr $linespc -selectbackground grey
368 .ctop.top.clist add $canv3
373 .ctop.top.clist add $canv3
369 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
374 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
370
375
371 set sha1entry .ctop.top.bar.sha1
376 set sha1entry .ctop.top.bar.sha1
372 set entries $sha1entry
377 set entries $sha1entry
373 set sha1but .ctop.top.bar.sha1label
378 set sha1but .ctop.top.bar.sha1label
374 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
379 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
375 -command gotocommit -width 8
380 -command gotocommit -width 8
376 $sha1but conf -disabledforeground [$sha1but cget -foreground]
381 $sha1but conf -disabledforeground [$sha1but cget -foreground]
377 pack .ctop.top.bar.sha1label -side left
382 pack .ctop.top.bar.sha1label -side left
378 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
383 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
379 trace add variable sha1string write sha1change
384 trace add variable sha1string write sha1change
380 pack $sha1entry -side left -pady 2
385 pack $sha1entry -side left -pady 2
381
386
382 image create bitmap bm-left -data {
387 image create bitmap bm-left -data {
383 #define left_width 16
388 #define left_width 16
384 #define left_height 16
389 #define left_height 16
385 static unsigned char left_bits[] = {
390 static unsigned char left_bits[] = {
386 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
391 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
387 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
392 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
388 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
393 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
389 }
394 }
390 image create bitmap bm-right -data {
395 image create bitmap bm-right -data {
391 #define right_width 16
396 #define right_width 16
392 #define right_height 16
397 #define right_height 16
393 static unsigned char right_bits[] = {
398 static unsigned char right_bits[] = {
394 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
399 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
395 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
400 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
396 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
401 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
397 }
402 }
398 button .ctop.top.bar.leftbut -image bm-left -command goback \
403 button .ctop.top.bar.leftbut -image bm-left -command goback \
399 -state disabled -width 26
404 -state disabled -width 26
400 pack .ctop.top.bar.leftbut -side left -fill y
405 pack .ctop.top.bar.leftbut -side left -fill y
401 button .ctop.top.bar.rightbut -image bm-right -command goforw \
406 button .ctop.top.bar.rightbut -image bm-right -command goforw \
402 -state disabled -width 26
407 -state disabled -width 26
403 pack .ctop.top.bar.rightbut -side left -fill y
408 pack .ctop.top.bar.rightbut -side left -fill y
404
409
405 button .ctop.top.bar.findbut -text "Find" -command dofind
410 button .ctop.top.bar.findbut -text "Find" -command dofind
406 pack .ctop.top.bar.findbut -side left
411 pack .ctop.top.bar.findbut -side left
407 set findstring {}
412 set findstring {}
408 set fstring .ctop.top.bar.findstring
413 set fstring .ctop.top.bar.findstring
409 lappend entries $fstring
414 lappend entries $fstring
410 entry $fstring -width 30 -font $textfont -textvariable findstring
415 entry $fstring -width 30 -font $textfont -textvariable findstring
411 pack $fstring -side left -expand 1 -fill x
416 pack $fstring -side left -expand 1 -fill x
412 set findtype Exact
417 set findtype Exact
413 set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
418 set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
414 findtype Exact IgnCase Regexp]
419 findtype Exact IgnCase Regexp]
415 set findloc "All fields"
420 set findloc "All fields"
416 tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
421 tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
417 Comments Author Committer Files Pickaxe
422 Comments Author Committer Files Pickaxe
418 pack .ctop.top.bar.findloc -side right
423 pack .ctop.top.bar.findloc -side right
419 pack .ctop.top.bar.findtype -side right
424 pack .ctop.top.bar.findtype -side right
420 # for making sure type==Exact whenever loc==Pickaxe
425 # for making sure type==Exact whenever loc==Pickaxe
421 trace add variable findloc write findlocchange
426 trace add variable findloc write findlocchange
422
427
423 panedwindow .ctop.cdet -orient horizontal
428 panedwindow .ctop.cdet -orient horizontal
424 .ctop add .ctop.cdet
429 .ctop add .ctop.cdet
425 frame .ctop.cdet.left
430 frame .ctop.cdet.left
426 set ctext .ctop.cdet.left.ctext
431 set ctext .ctop.cdet.left.ctext
427 text $ctext -bg white -state disabled -font $textfont \
432 text $ctext -bg white -state disabled -font $textfont \
428 -width $geometry(ctextw) -height $geometry(ctexth) \
433 -width $geometry(ctextw) -height $geometry(ctexth) \
429 -yscrollcommand ".ctop.cdet.left.sb set" \
434 -yscrollcommand ".ctop.cdet.left.sb set" \
430 -xscrollcommand ".ctop.cdet.left.hb set" -wrap none
435 -xscrollcommand ".ctop.cdet.left.hb set" -wrap none
431 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
436 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
432 scrollbar .ctop.cdet.left.hb -orient horizontal -command "$ctext xview"
437 scrollbar .ctop.cdet.left.hb -orient horizontal -command "$ctext xview"
433 pack .ctop.cdet.left.sb -side right -fill y
438 pack .ctop.cdet.left.sb -side right -fill y
434 pack .ctop.cdet.left.hb -side bottom -fill x
439 pack .ctop.cdet.left.hb -side bottom -fill x
435 pack $ctext -side left -fill both -expand 1
440 pack $ctext -side left -fill both -expand 1
436 .ctop.cdet add .ctop.cdet.left
441 .ctop.cdet add .ctop.cdet.left
437
442
438 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
443 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
439 if {$gaudydiff} {
444 if {$gaudydiff} {
440 $ctext tag conf hunksep -back blue -fore white
445 $ctext tag conf hunksep -back blue -fore white
441 $ctext tag conf d0 -back "#ff8080"
446 $ctext tag conf d0 -back "#ff8080"
442 $ctext tag conf d1 -back green
447 $ctext tag conf d1 -back green
443 } else {
448 } else {
444 $ctext tag conf hunksep -fore blue
449 $ctext tag conf hunksep -fore blue
445 $ctext tag conf d0 -fore red
450 $ctext tag conf d0 -fore red
446 $ctext tag conf d1 -fore "#00a000"
451 $ctext tag conf d1 -fore "#00a000"
447 $ctext tag conf m0 -fore red
452 $ctext tag conf m0 -fore red
448 $ctext tag conf m1 -fore blue
453 $ctext tag conf m1 -fore blue
449 $ctext tag conf m2 -fore green
454 $ctext tag conf m2 -fore green
450 $ctext tag conf m3 -fore purple
455 $ctext tag conf m3 -fore purple
451 $ctext tag conf m4 -fore brown
456 $ctext tag conf m4 -fore brown
452 $ctext tag conf mmax -fore darkgrey
457 $ctext tag conf mmax -fore darkgrey
453 set mergemax 5
458 set mergemax 5
454 $ctext tag conf mresult -font [concat $textfont bold]
459 $ctext tag conf mresult -font [concat $textfont bold]
455 $ctext tag conf msep -font [concat $textfont bold]
460 $ctext tag conf msep -font [concat $textfont bold]
456 $ctext tag conf found -back yellow
461 $ctext tag conf found -back yellow
457 }
462 }
458
463
459 frame .ctop.cdet.right
464 frame .ctop.cdet.right
460 set cflist .ctop.cdet.right.cfiles
465 set cflist .ctop.cdet.right.cfiles
461 listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
466 listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \
462 -yscrollcommand ".ctop.cdet.right.sb set"
467 -yscrollcommand ".ctop.cdet.right.sb set"
463 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
468 scrollbar .ctop.cdet.right.sb -command "$cflist yview"
464 pack .ctop.cdet.right.sb -side right -fill y
469 pack .ctop.cdet.right.sb -side right -fill y
465 pack $cflist -side left -fill both -expand 1
470 pack $cflist -side left -fill both -expand 1
466 .ctop.cdet add .ctop.cdet.right
471 .ctop.cdet add .ctop.cdet.right
467 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
472 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
468
473
469 pack .ctop -side top -fill both -expand 1
474 pack .ctop -side top -fill both -expand 1
470
475
471 bindall <1> {selcanvline %W %x %y}
476 bindall <1> {selcanvline %W %x %y}
472 #bindall <B1-Motion> {selcanvline %W %x %y}
477 #bindall <B1-Motion> {selcanvline %W %x %y}
478 bindall <MouseWheel> "allcansmousewheel %D"
473 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
479 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
474 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
480 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
475 bindall <2> "allcanvs scan mark 0 %y"
481 bindall <2> "allcanvs scan mark 0 %y"
476 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
482 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
477 bind . <Key-Up> "selnextline -1"
483 bind . <Key-Up> "selnextline -1"
478 bind . <Key-Down> "selnextline 1"
484 bind . <Key-Down> "selnextline 1"
479 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
485 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
480 bind . <Key-Next> "allcanvs yview scroll 1 pages"
486 bind . <Key-Next> "allcanvs yview scroll 1 pages"
481 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
487 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
482 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
488 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
483 bindkey <Key-space> "$ctext yview scroll 1 pages"
489 bindkey <Key-space> "$ctext yview scroll 1 pages"
484 bindkey p "selnextline -1"
490 bindkey p "selnextline -1"
485 bindkey n "selnextline 1"
491 bindkey n "selnextline 1"
486 bindkey b "$ctext yview scroll -1 pages"
492 bindkey b "$ctext yview scroll -1 pages"
487 bindkey d "$ctext yview scroll 18 units"
493 bindkey d "$ctext yview scroll 18 units"
488 bindkey u "$ctext yview scroll -18 units"
494 bindkey u "$ctext yview scroll -18 units"
489 bindkey / {findnext 1}
495 bindkey / {findnext 1}
490 bindkey <Key-Return> {findnext 0}
496 bindkey <Key-Return> {findnext 0}
491 bindkey ? findprev
497 bindkey ? findprev
492 bindkey f nextfile
498 bindkey f nextfile
493 bind . <Control-q> doquit
499 bind . <Control-q> doquit
494 bind . <Control-w> doquit
500 bind . <Control-w> doquit
495 bind . <Control-f> dofind
501 bind . <Control-f> dofind
496 bind . <Control-g> {findnext 0}
502 bind . <Control-g> {findnext 0}
497 bind . <Control-r> findprev
503 bind . <Control-r> findprev
498 bind . <Control-equal> {incrfont 1}
504 bind . <Control-equal> {incrfont 1}
499 bind . <Control-KP_Add> {incrfont 1}
505 bind . <Control-KP_Add> {incrfont 1}
500 bind . <Control-minus> {incrfont -1}
506 bind . <Control-minus> {incrfont -1}
501 bind . <Control-KP_Subtract> {incrfont -1}
507 bind . <Control-KP_Subtract> {incrfont -1}
502 bind $cflist <<ListboxSelect>> listboxsel
508 bind $cflist <<ListboxSelect>> listboxsel
503 bind . <Destroy> {savestuff %W}
509 bind . <Destroy> {savestuff %W}
504 bind . <Button-1> "click %W"
510 bind . <Button-1> "click %W"
505 bind $fstring <Key-Return> dofind
511 bind $fstring <Key-Return> dofind
506 bind $sha1entry <Key-Return> gotocommit
512 bind $sha1entry <Key-Return> gotocommit
507 bind $sha1entry <<PasteSelection>> clearsha1
513 bind $sha1entry <<PasteSelection>> clearsha1
508
514
509 set maincursor [. cget -cursor]
515 set maincursor [. cget -cursor]
510 set textcursor [$ctext cget -cursor]
516 set textcursor [$ctext cget -cursor]
511 set curtextcursor $textcursor
517 set curtextcursor $textcursor
512
518
513 set rowctxmenu .rowctxmenu
519 set rowctxmenu .rowctxmenu
514 menu $rowctxmenu -tearoff 0
520 menu $rowctxmenu -tearoff 0
515 $rowctxmenu add command -label "Diff this -> selected" \
521 $rowctxmenu add command -label "Diff this -> selected" \
516 -command {diffvssel 0}
522 -command {diffvssel 0}
517 $rowctxmenu add command -label "Diff selected -> this" \
523 $rowctxmenu add command -label "Diff selected -> this" \
518 -command {diffvssel 1}
524 -command {diffvssel 1}
519 $rowctxmenu add command -label "Make patch" -command mkpatch
525 $rowctxmenu add command -label "Make patch" -command mkpatch
520 $rowctxmenu add command -label "Create tag" -command mktag
526 $rowctxmenu add command -label "Create tag" -command mktag
521 $rowctxmenu add command -label "Write commit to file" -command writecommit
527 $rowctxmenu add command -label "Write commit to file" -command writecommit
522 }
528 }
523
529
524 # when we make a key binding for the toplevel, make sure
530 # when we make a key binding for the toplevel, make sure
525 # it doesn't get triggered when that key is pressed in the
531 # it doesn't get triggered when that key is pressed in the
526 # find string entry widget.
532 # find string entry widget.
527 proc bindkey {ev script} {
533 proc bindkey {ev script} {
528 global entries
534 global entries
529 bind . $ev $script
535 bind . $ev $script
530 set escript [bind Entry $ev]
536 set escript [bind Entry $ev]
531 if {$escript == {}} {
537 if {$escript == {}} {
532 set escript [bind Entry <Key>]
538 set escript [bind Entry <Key>]
533 }
539 }
534 foreach e $entries {
540 foreach e $entries {
535 bind $e $ev "$escript; break"
541 bind $e $ev "$escript; break"
536 }
542 }
537 }
543 }
538
544
539 # set the focus back to the toplevel for any click outside
545 # set the focus back to the toplevel for any click outside
540 # the entry widgets
546 # the entry widgets
541 proc click {w} {
547 proc click {w} {
542 global entries
548 global entries
543 foreach e $entries {
549 foreach e $entries {
544 if {$w == $e} return
550 if {$w == $e} return
545 }
551 }
546 focus .
552 focus .
547 }
553 }
548
554
549 proc savestuff {w} {
555 proc savestuff {w} {
550 global canv canv2 canv3 ctext cflist mainfont textfont
556 global canv canv2 canv3 ctext cflist mainfont textfont
551 global stuffsaved findmergefiles gaudydiff maxgraphpct
557 global stuffsaved findmergefiles gaudydiff maxgraphpct
552 global maxwidth
558 global maxwidth
553
559
554 if {$stuffsaved} return
560 if {$stuffsaved} return
555 if {![winfo viewable .]} return
561 if {![winfo viewable .]} return
556 catch {
562 catch {
557 set f [open "~/.gitk-new" w]
563 set f [open "~/.gitk-new" w]
558 puts $f [list set mainfont $mainfont]
564 puts $f [list set mainfont $mainfont]
559 puts $f [list set textfont $textfont]
565 puts $f [list set textfont $textfont]
560 puts $f [list set findmergefiles $findmergefiles]
566 puts $f [list set findmergefiles $findmergefiles]
561 puts $f [list set gaudydiff $gaudydiff]
567 puts $f [list set gaudydiff $gaudydiff]
562 puts $f [list set maxgraphpct $maxgraphpct]
568 puts $f [list set maxgraphpct $maxgraphpct]
563 puts $f [list set maxwidth $maxwidth]
569 puts $f [list set maxwidth $maxwidth]
564 puts $f "set geometry(width) [winfo width .ctop]"
570 puts $f "set geometry(width) [winfo width .ctop]"
565 puts $f "set geometry(height) [winfo height .ctop]"
571 puts $f "set geometry(height) [winfo height .ctop]"
566 puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
572 puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
567 puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
573 puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
568 puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
574 puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
569 puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
575 puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
570 set wid [expr {([winfo width $ctext] - 8) \
576 set wid [expr {([winfo width $ctext] - 8) \
571 / [font measure $textfont "0"]}]
577 / [font measure $textfont "0"]}]
572 puts $f "set geometry(ctextw) $wid"
578 puts $f "set geometry(ctextw) $wid"
573 set wid [expr {([winfo width $cflist] - 11) \
579 set wid [expr {([winfo width $cflist] - 11) \
574 / [font measure [$cflist cget -font] "0"]}]
580 / [font measure [$cflist cget -font] "0"]}]
575 puts $f "set geometry(cflistw) $wid"
581 puts $f "set geometry(cflistw) $wid"
576 close $f
582 close $f
577 file rename -force "~/.gitk-new" "~/.gitk"
583 file rename -force "~/.gitk-new" "~/.gitk"
578 }
584 }
579 set stuffsaved 1
585 set stuffsaved 1
580 }
586 }
581
587
582 proc resizeclistpanes {win w} {
588 proc resizeclistpanes {win w} {
583 global oldwidth
589 global oldwidth
584 if [info exists oldwidth($win)] {
590 if [info exists oldwidth($win)] {
585 set s0 [$win sash coord 0]
591 set s0 [$win sash coord 0]
586 set s1 [$win sash coord 1]
592 set s1 [$win sash coord 1]
587 if {$w < 60} {
593 if {$w < 60} {
588 set sash0 [expr {int($w/2 - 2)}]
594 set sash0 [expr {int($w/2 - 2)}]
589 set sash1 [expr {int($w*5/6 - 2)}]
595 set sash1 [expr {int($w*5/6 - 2)}]
590 } else {
596 } else {
591 set factor [expr {1.0 * $w / $oldwidth($win)}]
597 set factor [expr {1.0 * $w / $oldwidth($win)}]
592 set sash0 [expr {int($factor * [lindex $s0 0])}]
598 set sash0 [expr {int($factor * [lindex $s0 0])}]
593 set sash1 [expr {int($factor * [lindex $s1 0])}]
599 set sash1 [expr {int($factor * [lindex $s1 0])}]
594 if {$sash0 < 30} {
600 if {$sash0 < 30} {
595 set sash0 30
601 set sash0 30
596 }
602 }
597 if {$sash1 < $sash0 + 20} {
603 if {$sash1 < $sash0 + 20} {
598 set sash1 [expr $sash0 + 20]
604 set sash1 [expr $sash0 + 20]
599 }
605 }
600 if {$sash1 > $w - 10} {
606 if {$sash1 > $w - 10} {
601 set sash1 [expr $w - 10]
607 set sash1 [expr $w - 10]
602 if {$sash0 > $sash1 - 20} {
608 if {$sash0 > $sash1 - 20} {
603 set sash0 [expr $sash1 - 20]
609 set sash0 [expr $sash1 - 20]
604 }
610 }
605 }
611 }
606 }
612 }
607 $win sash place 0 $sash0 [lindex $s0 1]
613 $win sash place 0 $sash0 [lindex $s0 1]
608 $win sash place 1 $sash1 [lindex $s1 1]
614 $win sash place 1 $sash1 [lindex $s1 1]
609 }
615 }
610 set oldwidth($win) $w
616 set oldwidth($win) $w
611 }
617 }
612
618
613 proc resizecdetpanes {win w} {
619 proc resizecdetpanes {win w} {
614 global oldwidth
620 global oldwidth
615 if [info exists oldwidth($win)] {
621 if [info exists oldwidth($win)] {
616 set s0 [$win sash coord 0]
622 set s0 [$win sash coord 0]
617 if {$w < 60} {
623 if {$w < 60} {
618 set sash0 [expr {int($w*3/4 - 2)}]
624 set sash0 [expr {int($w*3/4 - 2)}]
619 } else {
625 } else {
620 set factor [expr {1.0 * $w / $oldwidth($win)}]
626 set factor [expr {1.0 * $w / $oldwidth($win)}]
621 set sash0 [expr {int($factor * [lindex $s0 0])}]
627 set sash0 [expr {int($factor * [lindex $s0 0])}]
622 if {$sash0 < 45} {
628 if {$sash0 < 45} {
623 set sash0 45
629 set sash0 45
624 }
630 }
625 if {$sash0 > $w - 15} {
631 if {$sash0 > $w - 15} {
626 set sash0 [expr $w - 15]
632 set sash0 [expr $w - 15]
627 }
633 }
628 }
634 }
629 $win sash place 0 $sash0 [lindex $s0 1]
635 $win sash place 0 $sash0 [lindex $s0 1]
630 }
636 }
631 set oldwidth($win) $w
637 set oldwidth($win) $w
632 }
638 }
633
639
634 proc allcanvs args {
640 proc allcanvs args {
635 global canv canv2 canv3
641 global canv canv2 canv3
636 eval $canv $args
642 eval $canv $args
637 eval $canv2 $args
643 eval $canv2 $args
638 eval $canv3 $args
644 eval $canv3 $args
639 }
645 }
640
646
641 proc bindall {event action} {
647 proc bindall {event action} {
642 global canv canv2 canv3
648 global canv canv2 canv3
643 bind $canv $event $action
649 bind $canv $event $action
644 bind $canv2 $event $action
650 bind $canv2 $event $action
645 bind $canv3 $event $action
651 bind $canv3 $event $action
646 }
652 }
647
653
648 proc about {} {
654 proc about {} {
649 set w .about
655 set w .about
650 if {[winfo exists $w]} {
656 if {[winfo exists $w]} {
651 raise $w
657 raise $w
652 return
658 return
653 }
659 }
654 toplevel $w
660 toplevel $w
655 wm title $w "About gitk"
661 wm title $w "About gitk"
656 message $w.m -text {
662 message $w.m -text {
657 Gitk version 1.2
663 Gitk version 1.2
658
664
659 Copyright οΏ½ 2005 Paul Mackerras
665 Copyright οΏ½ 2005 Paul Mackerras
660
666
661 Use and redistribute under the terms of the GNU General Public License} \
667 Use and redistribute under the terms of the GNU General Public License} \
662 -justify center -aspect 400
668 -justify center -aspect 400
663 pack $w.m -side top -fill x -padx 20 -pady 20
669 pack $w.m -side top -fill x -padx 20 -pady 20
664 button $w.ok -text Close -command "destroy $w"
670 button $w.ok -text Close -command "destroy $w"
665 pack $w.ok -side bottom
671 pack $w.ok -side bottom
666 }
672 }
667
673
668 proc assigncolor {id} {
674 proc assigncolor {id} {
669 global commitinfo colormap commcolors colors nextcolor
675 global commitinfo colormap commcolors colors nextcolor
670 global parents nparents children nchildren
676 global parents nparents children nchildren
671 global cornercrossings crossings
677 global cornercrossings crossings
672
678
673 if [info exists colormap($id)] return
679 if [info exists colormap($id)] return
674 set ncolors [llength $colors]
680 set ncolors [llength $colors]
675 if {$nparents($id) <= 1 && $nchildren($id) == 1} {
681 if {$nparents($id) <= 1 && $nchildren($id) == 1} {
676 set child [lindex $children($id) 0]
682 set child [lindex $children($id) 0]
677 if {[info exists colormap($child)]
683 if {[info exists colormap($child)]
678 && $nparents($child) == 1} {
684 && $nparents($child) == 1} {
679 set colormap($id) $colormap($child)
685 set colormap($id) $colormap($child)
680 return
686 return
681 }
687 }
682 }
688 }
683 set badcolors {}
689 set badcolors {}
684 if {[info exists cornercrossings($id)]} {
690 if {[info exists cornercrossings($id)]} {
685 foreach x $cornercrossings($id) {
691 foreach x $cornercrossings($id) {
686 if {[info exists colormap($x)]
692 if {[info exists colormap($x)]
687 && [lsearch -exact $badcolors $colormap($x)] < 0} {
693 && [lsearch -exact $badcolors $colormap($x)] < 0} {
688 lappend badcolors $colormap($x)
694 lappend badcolors $colormap($x)
689 }
695 }
690 }
696 }
691 if {[llength $badcolors] >= $ncolors} {
697 if {[llength $badcolors] >= $ncolors} {
692 set badcolors {}
698 set badcolors {}
693 }
699 }
694 }
700 }
695 set origbad $badcolors
701 set origbad $badcolors
696 if {[llength $badcolors] < $ncolors - 1} {
702 if {[llength $badcolors] < $ncolors - 1} {
697 if {[info exists crossings($id)]} {
703 if {[info exists crossings($id)]} {
698 foreach x $crossings($id) {
704 foreach x $crossings($id) {
699 if {[info exists colormap($x)]
705 if {[info exists colormap($x)]
700 && [lsearch -exact $badcolors $colormap($x)] < 0} {
706 && [lsearch -exact $badcolors $colormap($x)] < 0} {
701 lappend badcolors $colormap($x)
707 lappend badcolors $colormap($x)
702 }
708 }
703 }
709 }
704 if {[llength $badcolors] >= $ncolors} {
710 if {[llength $badcolors] >= $ncolors} {
705 set badcolors $origbad
711 set badcolors $origbad
706 }
712 }
707 }
713 }
708 set origbad $badcolors
714 set origbad $badcolors
709 }
715 }
710 if {[llength $badcolors] < $ncolors - 1} {
716 if {[llength $badcolors] < $ncolors - 1} {
711 foreach child $children($id) {
717 foreach child $children($id) {
712 if {[info exists colormap($child)]
718 if {[info exists colormap($child)]
713 && [lsearch -exact $badcolors $colormap($child)] < 0} {
719 && [lsearch -exact $badcolors $colormap($child)] < 0} {
714 lappend badcolors $colormap($child)
720 lappend badcolors $colormap($child)
715 }
721 }
716 if {[info exists parents($child)]} {
722 if {[info exists parents($child)]} {
717 foreach p $parents($child) {
723 foreach p $parents($child) {
718 if {[info exists colormap($p)]
724 if {[info exists colormap($p)]
719 && [lsearch -exact $badcolors $colormap($p)] < 0} {
725 && [lsearch -exact $badcolors $colormap($p)] < 0} {
720 lappend badcolors $colormap($p)
726 lappend badcolors $colormap($p)
721 }
727 }
722 }
728 }
723 }
729 }
724 }
730 }
725 if {[llength $badcolors] >= $ncolors} {
731 if {[llength $badcolors] >= $ncolors} {
726 set badcolors $origbad
732 set badcolors $origbad
727 }
733 }
728 }
734 }
729 for {set i 0} {$i <= $ncolors} {incr i} {
735 for {set i 0} {$i <= $ncolors} {incr i} {
730 set c [lindex $colors $nextcolor]
736 set c [lindex $colors $nextcolor]
731 if {[incr nextcolor] >= $ncolors} {
737 if {[incr nextcolor] >= $ncolors} {
732 set nextcolor 0
738 set nextcolor 0
733 }
739 }
734 if {[lsearch -exact $badcolors $c]} break
740 if {[lsearch -exact $badcolors $c]} break
735 }
741 }
736 set colormap($id) $c
742 set colormap($id) $c
737 }
743 }
738
744
739 proc initgraph {} {
745 proc initgraph {} {
740 global canvy canvy0 lineno numcommits nextcolor linespc
746 global canvy canvy0 lineno numcommits nextcolor linespc
741 global mainline mainlinearrow sidelines
747 global mainline mainlinearrow sidelines
742 global nchildren ncleft
748 global nchildren ncleft
743 global displist nhyperspace
749 global displist nhyperspace
744
750
745 allcanvs delete all
751 allcanvs delete all
746 set nextcolor 0
752 set nextcolor 0
747 set canvy $canvy0
753 set canvy $canvy0
748 set lineno -1
754 set lineno -1
749 set numcommits 0
755 set numcommits 0
750 catch {unset mainline}
756 catch {unset mainline}
751 catch {unset mainlinearrow}
757 catch {unset mainlinearrow}
752 catch {unset sidelines}
758 catch {unset sidelines}
753 foreach id [array names nchildren] {
759 foreach id [array names nchildren] {
754 set ncleft($id) $nchildren($id)
760 set ncleft($id) $nchildren($id)
755 }
761 }
756 set displist {}
762 set displist {}
757 set nhyperspace 0
763 set nhyperspace 0
758 }
764 }
759
765
760 proc bindline {t id} {
766 proc bindline {t id} {
761 global canv
767 global canv
762
768
763 $canv bind $t <Enter> "lineenter %x %y $id"
769 $canv bind $t <Enter> "lineenter %x %y $id"
764 $canv bind $t <Motion> "linemotion %x %y $id"
770 $canv bind $t <Motion> "linemotion %x %y $id"
765 $canv bind $t <Leave> "lineleave $id"
771 $canv bind $t <Leave> "lineleave $id"
766 $canv bind $t <Button-1> "lineclick %x %y $id 1"
772 $canv bind $t <Button-1> "lineclick %x %y $id 1"
767 }
773 }
768
774
769 proc drawlines {id xtra} {
775 proc drawlines {id xtra} {
770 global mainline mainlinearrow sidelines lthickness colormap canv
776 global mainline mainlinearrow sidelines lthickness colormap canv
771
777
772 $canv delete lines.$id
778 $canv delete lines.$id
773 if {[info exists mainline($id)]} {
779 if {[info exists mainline($id)]} {
774 set t [$canv create line $mainline($id) \
780 set t [$canv create line $mainline($id) \
775 -width [expr {($xtra + 1) * $lthickness}] \
781 -width [expr {($xtra + 1) * $lthickness}] \
776 -fill $colormap($id) -tags lines.$id \
782 -fill $colormap($id) -tags lines.$id \
777 -arrow $mainlinearrow($id)]
783 -arrow $mainlinearrow($id)]
778 $canv lower $t
784 $canv lower $t
779 bindline $t $id
785 bindline $t $id
780 }
786 }
781 if {[info exists sidelines($id)]} {
787 if {[info exists sidelines($id)]} {
782 foreach ls $sidelines($id) {
788 foreach ls $sidelines($id) {
783 set coords [lindex $ls 0]
789 set coords [lindex $ls 0]
784 set thick [lindex $ls 1]
790 set thick [lindex $ls 1]
785 set arrow [lindex $ls 2]
791 set arrow [lindex $ls 2]
786 set t [$canv create line $coords -fill $colormap($id) \
792 set t [$canv create line $coords -fill $colormap($id) \
787 -width [expr {($thick + $xtra) * $lthickness}] \
793 -width [expr {($thick + $xtra) * $lthickness}] \
788 -arrow $arrow -tags lines.$id]
794 -arrow $arrow -tags lines.$id]
789 $canv lower $t
795 $canv lower $t
790 bindline $t $id
796 bindline $t $id
791 }
797 }
792 }
798 }
793 }
799 }
794
800
795 # level here is an index in displist
801 # level here is an index in displist
796 proc drawcommitline {level} {
802 proc drawcommitline {level} {
797 global parents children nparents displist
803 global parents children nparents displist
798 global canv canv2 canv3 mainfont namefont canvy linespc
804 global canv canv2 canv3 mainfont namefont canvy linespc
799 global lineid linehtag linentag linedtag commitinfo
805 global lineid linehtag linentag linedtag commitinfo
800 global colormap numcommits currentparents dupparents
806 global colormap numcommits currentparents dupparents
801 global idtags idline idheads idotherrefs
807 global idtags idline idheads idotherrefs
802 global lineno lthickness mainline mainlinearrow sidelines
808 global lineno lthickness mainline mainlinearrow sidelines
803 global commitlisted rowtextx idpos lastuse displist
809 global commitlisted rowtextx idpos lastuse displist
804 global oldnlines olddlevel olddisplist
810 global oldnlines olddlevel olddisplist
805
811
806 incr numcommits
812 incr numcommits
807 incr lineno
813 incr lineno
808 set id [lindex $displist $level]
814 set id [lindex $displist $level]
809 set lastuse($id) $lineno
815 set lastuse($id) $lineno
810 set lineid($lineno) $id
816 set lineid($lineno) $id
811 set idline($id) $lineno
817 set idline($id) $lineno
812 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
818 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
813 if {![info exists commitinfo($id)]} {
819 if {![info exists commitinfo($id)]} {
814 readcommit $id
820 readcommit $id
815 if {![info exists commitinfo($id)]} {
821 if {![info exists commitinfo($id)]} {
816 set commitinfo($id) {"No commit information available"}
822 set commitinfo($id) {"No commit information available"}
817 set nparents($id) 0
823 set nparents($id) 0
818 }
824 }
819 }
825 }
820 assigncolor $id
826 assigncolor $id
821 set currentparents {}
827 set currentparents {}
822 set dupparents {}
828 set dupparents {}
823 if {[info exists commitlisted($id)] && [info exists parents($id)]} {
829 if {[info exists commitlisted($id)] && [info exists parents($id)]} {
824 foreach p $parents($id) {
830 foreach p $parents($id) {
825 if {[lsearch -exact $currentparents $p] < 0} {
831 if {[lsearch -exact $currentparents $p] < 0} {
826 lappend currentparents $p
832 lappend currentparents $p
827 } else {
833 } else {
828 # remember that this parent was listed twice
834 # remember that this parent was listed twice
829 lappend dupparents $p
835 lappend dupparents $p
830 }
836 }
831 }
837 }
832 }
838 }
833 set x [xcoord $level $level $lineno]
839 set x [xcoord $level $level $lineno]
834 set y1 $canvy
840 set y1 $canvy
835 set canvy [expr $canvy + $linespc]
841 set canvy [expr $canvy + $linespc]
836 allcanvs conf -scrollregion \
842 allcanvs conf -scrollregion \
837 [list 0 0 0 [expr $y1 + 0.5 * $linespc + 2]]
843 [list 0 0 0 [expr $y1 + 0.5 * $linespc + 2]]
838 if {[info exists mainline($id)]} {
844 if {[info exists mainline($id)]} {
839 lappend mainline($id) $x $y1
845 lappend mainline($id) $x $y1
840 if {$mainlinearrow($id) ne "none"} {
846 if {$mainlinearrow($id) ne "none"} {
841 set mainline($id) [trimdiagstart $mainline($id)]
847 set mainline($id) [trimdiagstart $mainline($id)]
842 }
848 }
843 }
849 }
844 drawlines $id 0
850 drawlines $id 0
845 set orad [expr {$linespc / 3}]
851 set orad [expr {$linespc / 3}]
846 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
852 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
847 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
853 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
848 -fill $ofill -outline black -width 1]
854 -fill $ofill -outline black -width 1]
849 $canv raise $t
855 $canv raise $t
850 $canv bind $t <1> {selcanvline {} %x %y}
856 $canv bind $t <1> {selcanvline {} %x %y}
851 set xt [xcoord [llength $displist] $level $lineno]
857 set xt [xcoord [llength $displist] $level $lineno]
852 if {[llength $currentparents] > 2} {
858 if {[llength $currentparents] > 2} {
853 set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
859 set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
854 }
860 }
855 set rowtextx($lineno) $xt
861 set rowtextx($lineno) $xt
856 set idpos($id) [list $x $xt $y1]
862 set idpos($id) [list $x $xt $y1]
857 if {[info exists idtags($id)] || [info exists idheads($id)]
863 if {[info exists idtags($id)] || [info exists idheads($id)]
858 || [info exists idotherrefs($id)]} {
864 || [info exists idotherrefs($id)]} {
859 set xt [drawtags $id $x $xt $y1]
865 set xt [drawtags $id $x $xt $y1]
860 }
866 }
861 set headline [lindex $commitinfo($id) 0]
867 set headline [lindex $commitinfo($id) 0]
862 set name [lindex $commitinfo($id) 1]
868 set name [lindex $commitinfo($id) 1]
863 set date [lindex $commitinfo($id) 2]
869 set date [lindex $commitinfo($id) 2]
864 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
870 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
865 -text $headline -font $mainfont ]
871 -text $headline -font $mainfont ]
866 $canv bind $linehtag($lineno) <Button-3> "rowmenu %X %Y $id"
872 $canv bind $linehtag($lineno) <Button-3> "rowmenu %X %Y $id"
867 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
873 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
868 -text $name -font $namefont]
874 -text $name -font $namefont]
869 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
875 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
870 -text $date -font $mainfont]
876 -text $date -font $mainfont]
871
877
872 set olddlevel $level
878 set olddlevel $level
873 set olddisplist $displist
879 set olddisplist $displist
874 set oldnlines [llength $displist]
880 set oldnlines [llength $displist]
875 }
881 }
876
882
877 proc drawtags {id x xt y1} {
883 proc drawtags {id x xt y1} {
878 global idtags idheads idotherrefs
884 global idtags idheads idotherrefs
879 global linespc lthickness
885 global linespc lthickness
880 global canv mainfont idline rowtextx
886 global canv mainfont idline rowtextx
881
887
882 set marks {}
888 set marks {}
883 set ntags 0
889 set ntags 0
884 set nheads 0
890 set nheads 0
885 if {[info exists idtags($id)]} {
891 if {[info exists idtags($id)]} {
886 set marks $idtags($id)
892 set marks $idtags($id)
887 set ntags [llength $marks]
893 set ntags [llength $marks]
888 }
894 }
889 if {[info exists idheads($id)]} {
895 if {[info exists idheads($id)]} {
890 set marks [concat $marks $idheads($id)]
896 set marks [concat $marks $idheads($id)]
891 set nheads [llength $idheads($id)]
897 set nheads [llength $idheads($id)]
892 }
898 }
893 if {[info exists idotherrefs($id)]} {
899 if {[info exists idotherrefs($id)]} {
894 set marks [concat $marks $idotherrefs($id)]
900 set marks [concat $marks $idotherrefs($id)]
895 }
901 }
896 if {$marks eq {}} {
902 if {$marks eq {}} {
897 return $xt
903 return $xt
898 }
904 }
899
905
900 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
906 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
901 set yt [expr $y1 - 0.5 * $linespc]
907 set yt [expr $y1 - 0.5 * $linespc]
902 set yb [expr $yt + $linespc - 1]
908 set yb [expr $yt + $linespc - 1]
903 set xvals {}
909 set xvals {}
904 set wvals {}
910 set wvals {}
905 foreach tag $marks {
911 foreach tag $marks {
906 set wid [font measure $mainfont $tag]
912 set wid [font measure $mainfont $tag]
907 lappend xvals $xt
913 lappend xvals $xt
908 lappend wvals $wid
914 lappend wvals $wid
909 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
915 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
910 }
916 }
911 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
917 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
912 -width $lthickness -fill black -tags tag.$id]
918 -width $lthickness -fill black -tags tag.$id]
913 $canv lower $t
919 $canv lower $t
914 foreach tag $marks x $xvals wid $wvals {
920 foreach tag $marks x $xvals wid $wvals {
915 set xl [expr $x + $delta]
921 set xl [expr $x + $delta]
916 set xr [expr $x + $delta + $wid + $lthickness]
922 set xr [expr $x + $delta + $wid + $lthickness]
917 if {[incr ntags -1] >= 0} {
923 if {[incr ntags -1] >= 0} {
918 # draw a tag
924 # draw a tag
919 set t [$canv create polygon $x [expr $yt + $delta] $xl $yt \
925 set t [$canv create polygon $x [expr $yt + $delta] $xl $yt \
920 $xr $yt $xr $yb $xl $yb $x [expr $yb - $delta] \
926 $xr $yt $xr $yb $xl $yb $x [expr $yb - $delta] \
921 -width 1 -outline black -fill yellow -tags tag.$id]
927 -width 1 -outline black -fill yellow -tags tag.$id]
922 $canv bind $t <1> [list showtag $tag 1]
928 $canv bind $t <1> [list showtag $tag 1]
923 set rowtextx($idline($id)) [expr {$xr + $linespc}]
929 set rowtextx($idline($id)) [expr {$xr + $linespc}]
924 } else {
930 } else {
925 # draw a head or other ref
931 # draw a head or other ref
926 if {[incr nheads -1] >= 0} {
932 if {[incr nheads -1] >= 0} {
927 set col green
933 set col green
928 } else {
934 } else {
929 set col "#ddddff"
935 set col "#ddddff"
930 }
936 }
931 set xl [expr $xl - $delta/2]
937 set xl [expr $xl - $delta/2]
932 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
938 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
933 -width 1 -outline black -fill $col -tags tag.$id
939 -width 1 -outline black -fill $col -tags tag.$id
934 }
940 }
935 set t [$canv create text $xl $y1 -anchor w -text $tag \
941 set t [$canv create text $xl $y1 -anchor w -text $tag \
936 -font $mainfont -tags tag.$id]
942 -font $mainfont -tags tag.$id]
937 if {$ntags >= 0} {
943 if {$ntags >= 0} {
938 $canv bind $t <1> [list showtag $tag 1]
944 $canv bind $t <1> [list showtag $tag 1]
939 }
945 }
940 }
946 }
941 return $xt
947 return $xt
942 }
948 }
943
949
944 proc notecrossings {id lo hi corner} {
950 proc notecrossings {id lo hi corner} {
945 global olddisplist crossings cornercrossings
951 global olddisplist crossings cornercrossings
946
952
947 for {set i $lo} {[incr i] < $hi} {} {
953 for {set i $lo} {[incr i] < $hi} {} {
948 set p [lindex $olddisplist $i]
954 set p [lindex $olddisplist $i]
949 if {$p == {}} continue
955 if {$p == {}} continue
950 if {$i == $corner} {
956 if {$i == $corner} {
951 if {![info exists cornercrossings($id)]
957 if {![info exists cornercrossings($id)]
952 || [lsearch -exact $cornercrossings($id) $p] < 0} {
958 || [lsearch -exact $cornercrossings($id) $p] < 0} {
953 lappend cornercrossings($id) $p
959 lappend cornercrossings($id) $p
954 }
960 }
955 if {![info exists cornercrossings($p)]
961 if {![info exists cornercrossings($p)]
956 || [lsearch -exact $cornercrossings($p) $id] < 0} {
962 || [lsearch -exact $cornercrossings($p) $id] < 0} {
957 lappend cornercrossings($p) $id
963 lappend cornercrossings($p) $id
958 }
964 }
959 } else {
965 } else {
960 if {![info exists crossings($id)]
966 if {![info exists crossings($id)]
961 || [lsearch -exact $crossings($id) $p] < 0} {
967 || [lsearch -exact $crossings($id) $p] < 0} {
962 lappend crossings($id) $p
968 lappend crossings($id) $p
963 }
969 }
964 if {![info exists crossings($p)]
970 if {![info exists crossings($p)]
965 || [lsearch -exact $crossings($p) $id] < 0} {
971 || [lsearch -exact $crossings($p) $id] < 0} {
966 lappend crossings($p) $id
972 lappend crossings($p) $id
967 }
973 }
968 }
974 }
969 }
975 }
970 }
976 }
971
977
972 proc xcoord {i level ln} {
978 proc xcoord {i level ln} {
973 global canvx0 xspc1 xspc2
979 global canvx0 xspc1 xspc2
974
980
975 set x [expr {$canvx0 + $i * $xspc1($ln)}]
981 set x [expr {$canvx0 + $i * $xspc1($ln)}]
976 if {$i > 0 && $i == $level} {
982 if {$i > 0 && $i == $level} {
977 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
983 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
978 } elseif {$i > $level} {
984 } elseif {$i > $level} {
979 set x [expr {$x + $xspc2 - $xspc1($ln)}]
985 set x [expr {$x + $xspc2 - $xspc1($ln)}]
980 }
986 }
981 return $x
987 return $x
982 }
988 }
983
989
984 # it seems Tk can't draw arrows on the end of diagonal line segments...
990 # it seems Tk can't draw arrows on the end of diagonal line segments...
985 proc trimdiagend {line} {
991 proc trimdiagend {line} {
986 while {[llength $line] > 4} {
992 while {[llength $line] > 4} {
987 set x1 [lindex $line end-3]
993 set x1 [lindex $line end-3]
988 set y1 [lindex $line end-2]
994 set y1 [lindex $line end-2]
989 set x2 [lindex $line end-1]
995 set x2 [lindex $line end-1]
990 set y2 [lindex $line end]
996 set y2 [lindex $line end]
991 if {($x1 == $x2) != ($y1 == $y2)} break
997 if {($x1 == $x2) != ($y1 == $y2)} break
992 set line [lreplace $line end-1 end]
998 set line [lreplace $line end-1 end]
993 }
999 }
994 return $line
1000 return $line
995 }
1001 }
996
1002
997 proc trimdiagstart {line} {
1003 proc trimdiagstart {line} {
998 while {[llength $line] > 4} {
1004 while {[llength $line] > 4} {
999 set x1 [lindex $line 0]
1005 set x1 [lindex $line 0]
1000 set y1 [lindex $line 1]
1006 set y1 [lindex $line 1]
1001 set x2 [lindex $line 2]
1007 set x2 [lindex $line 2]
1002 set y2 [lindex $line 3]
1008 set y2 [lindex $line 3]
1003 if {($x1 == $x2) != ($y1 == $y2)} break
1009 if {($x1 == $x2) != ($y1 == $y2)} break
1004 set line [lreplace $line 0 1]
1010 set line [lreplace $line 0 1]
1005 }
1011 }
1006 return $line
1012 return $line
1007 }
1013 }
1008
1014
1009 proc drawslants {id needonscreen nohs} {
1015 proc drawslants {id needonscreen nohs} {
1010 global canv mainline mainlinearrow sidelines
1016 global canv mainline mainlinearrow sidelines
1011 global canvx0 canvy xspc1 xspc2 lthickness
1017 global canvx0 canvy xspc1 xspc2 lthickness
1012 global currentparents dupparents
1018 global currentparents dupparents
1013 global lthickness linespc canvy colormap lineno geometry
1019 global lthickness linespc canvy colormap lineno geometry
1014 global maxgraphpct maxwidth
1020 global maxgraphpct maxwidth
1015 global displist onscreen lastuse
1021 global displist onscreen lastuse
1016 global parents commitlisted
1022 global parents commitlisted
1017 global oldnlines olddlevel olddisplist
1023 global oldnlines olddlevel olddisplist
1018 global nhyperspace numcommits nnewparents
1024 global nhyperspace numcommits nnewparents
1019
1025
1020 if {$lineno < 0} {
1026 if {$lineno < 0} {
1021 lappend displist $id
1027 lappend displist $id
1022 set onscreen($id) 1
1028 set onscreen($id) 1
1023 return 0
1029 return 0
1024 }
1030 }
1025
1031
1026 set y1 [expr {$canvy - $linespc}]
1032 set y1 [expr {$canvy - $linespc}]
1027 set y2 $canvy
1033 set y2 $canvy
1028
1034
1029 # work out what we need to get back on screen
1035 # work out what we need to get back on screen
1030 set reins {}
1036 set reins {}
1031 if {$onscreen($id) < 0} {
1037 if {$onscreen($id) < 0} {
1032 # next to do isn't displayed, better get it on screen...
1038 # next to do isn't displayed, better get it on screen...
1033 lappend reins [list $id 0]
1039 lappend reins [list $id 0]
1034 }
1040 }
1035 # make sure all the previous commits's parents are on the screen
1041 # make sure all the previous commits's parents are on the screen
1036 foreach p $currentparents {
1042 foreach p $currentparents {
1037 if {$onscreen($p) < 0} {
1043 if {$onscreen($p) < 0} {
1038 lappend reins [list $p 0]
1044 lappend reins [list $p 0]
1039 }
1045 }
1040 }
1046 }
1041 # bring back anything requested by caller
1047 # bring back anything requested by caller
1042 if {$needonscreen ne {}} {
1048 if {$needonscreen ne {}} {
1043 lappend reins $needonscreen
1049 lappend reins $needonscreen
1044 }
1050 }
1045
1051
1046 # try the shortcut
1052 # try the shortcut
1047 if {$currentparents == $id && $onscreen($id) == 0 && $reins eq {}} {
1053 if {$currentparents == $id && $onscreen($id) == 0 && $reins eq {}} {
1048 set dlevel $olddlevel
1054 set dlevel $olddlevel
1049 set x [xcoord $dlevel $dlevel $lineno]
1055 set x [xcoord $dlevel $dlevel $lineno]
1050 set mainline($id) [list $x $y1]
1056 set mainline($id) [list $x $y1]
1051 set mainlinearrow($id) none
1057 set mainlinearrow($id) none
1052 set lastuse($id) $lineno
1058 set lastuse($id) $lineno
1053 set displist [lreplace $displist $dlevel $dlevel $id]
1059 set displist [lreplace $displist $dlevel $dlevel $id]
1054 set onscreen($id) 1
1060 set onscreen($id) 1
1055 set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
1061 set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
1056 return $dlevel
1062 return $dlevel
1057 }
1063 }
1058
1064
1059 # update displist
1065 # update displist
1060 set displist [lreplace $displist $olddlevel $olddlevel]
1066 set displist [lreplace $displist $olddlevel $olddlevel]
1061 set j $olddlevel
1067 set j $olddlevel
1062 foreach p $currentparents {
1068 foreach p $currentparents {
1063 set lastuse($p) $lineno
1069 set lastuse($p) $lineno
1064 if {$onscreen($p) == 0} {
1070 if {$onscreen($p) == 0} {
1065 set displist [linsert $displist $j $p]
1071 set displist [linsert $displist $j $p]
1066 set onscreen($p) 1
1072 set onscreen($p) 1
1067 incr j
1073 incr j
1068 }
1074 }
1069 }
1075 }
1070 if {$onscreen($id) == 0} {
1076 if {$onscreen($id) == 0} {
1071 lappend displist $id
1077 lappend displist $id
1072 set onscreen($id) 1
1078 set onscreen($id) 1
1073 }
1079 }
1074
1080
1075 # remove the null entry if present
1081 # remove the null entry if present
1076 set nullentry [lsearch -exact $displist {}]
1082 set nullentry [lsearch -exact $displist {}]
1077 if {$nullentry >= 0} {
1083 if {$nullentry >= 0} {
1078 set displist [lreplace $displist $nullentry $nullentry]
1084 set displist [lreplace $displist $nullentry $nullentry]
1079 }
1085 }
1080
1086
1081 # bring back the ones we need now (if we did it earlier
1087 # bring back the ones we need now (if we did it earlier
1082 # it would change displist and invalidate olddlevel)
1088 # it would change displist and invalidate olddlevel)
1083 foreach pi $reins {
1089 foreach pi $reins {
1084 # test again in case of duplicates in reins
1090 # test again in case of duplicates in reins
1085 set p [lindex $pi 0]
1091 set p [lindex $pi 0]
1086 if {$onscreen($p) < 0} {
1092 if {$onscreen($p) < 0} {
1087 set onscreen($p) 1
1093 set onscreen($p) 1
1088 set lastuse($p) $lineno
1094 set lastuse($p) $lineno
1089 set displist [linsert $displist [lindex $pi 1] $p]
1095 set displist [linsert $displist [lindex $pi 1] $p]
1090 incr nhyperspace -1
1096 incr nhyperspace -1
1091 }
1097 }
1092 }
1098 }
1093
1099
1094 set lastuse($id) $lineno
1100 set lastuse($id) $lineno
1095
1101
1096 # see if we need to make any lines jump off into hyperspace
1102 # see if we need to make any lines jump off into hyperspace
1097 set displ [llength $displist]
1103 set displ [llength $displist]
1098 if {$displ > $maxwidth} {
1104 if {$displ > $maxwidth} {
1099 set ages {}
1105 set ages {}
1100 foreach x $displist {
1106 foreach x $displist {
1101 lappend ages [list $lastuse($x) $x]
1107 lappend ages [list $lastuse($x) $x]
1102 }
1108 }
1103 set ages [lsort -integer -index 0 $ages]
1109 set ages [lsort -integer -index 0 $ages]
1104 set k 0
1110 set k 0
1105 while {$displ > $maxwidth} {
1111 while {$displ > $maxwidth} {
1106 set use [lindex $ages $k 0]
1112 set use [lindex $ages $k 0]
1107 set victim [lindex $ages $k 1]
1113 set victim [lindex $ages $k 1]
1108 if {$use >= $lineno - 5} break
1114 if {$use >= $lineno - 5} break
1109 incr k
1115 incr k
1110 if {[lsearch -exact $nohs $victim] >= 0} continue
1116 if {[lsearch -exact $nohs $victim] >= 0} continue
1111 set i [lsearch -exact $displist $victim]
1117 set i [lsearch -exact $displist $victim]
1112 set displist [lreplace $displist $i $i]
1118 set displist [lreplace $displist $i $i]
1113 set onscreen($victim) -1
1119 set onscreen($victim) -1
1114 incr nhyperspace
1120 incr nhyperspace
1115 incr displ -1
1121 incr displ -1
1116 if {$i < $nullentry} {
1122 if {$i < $nullentry} {
1117 incr nullentry -1
1123 incr nullentry -1
1118 }
1124 }
1119 set x [lindex $mainline($victim) end-1]
1125 set x [lindex $mainline($victim) end-1]
1120 lappend mainline($victim) $x $y1
1126 lappend mainline($victim) $x $y1
1121 set line [trimdiagend $mainline($victim)]
1127 set line [trimdiagend $mainline($victim)]
1122 set arrow "last"
1128 set arrow "last"
1123 if {$mainlinearrow($victim) ne "none"} {
1129 if {$mainlinearrow($victim) ne "none"} {
1124 set line [trimdiagstart $line]
1130 set line [trimdiagstart $line]
1125 set arrow "both"
1131 set arrow "both"
1126 }
1132 }
1127 lappend sidelines($victim) [list $line 1 $arrow]
1133 lappend sidelines($victim) [list $line 1 $arrow]
1128 unset mainline($victim)
1134 unset mainline($victim)
1129 }
1135 }
1130 }
1136 }
1131
1137
1132 set dlevel [lsearch -exact $displist $id]
1138 set dlevel [lsearch -exact $displist $id]
1133
1139
1134 # If we are reducing, put in a null entry
1140 # If we are reducing, put in a null entry
1135 if {$displ < $oldnlines} {
1141 if {$displ < $oldnlines} {
1136 # does the next line look like a merge?
1142 # does the next line look like a merge?
1137 # i.e. does it have > 1 new parent?
1143 # i.e. does it have > 1 new parent?
1138 if {$nnewparents($id) > 1} {
1144 if {$nnewparents($id) > 1} {
1139 set i [expr {$dlevel + 1}]
1145 set i [expr {$dlevel + 1}]
1140 } elseif {$nnewparents([lindex $olddisplist $olddlevel]) == 0} {
1146 } elseif {$nnewparents([lindex $olddisplist $olddlevel]) == 0} {
1141 set i $olddlevel
1147 set i $olddlevel
1142 if {$nullentry >= 0 && $nullentry < $i} {
1148 if {$nullentry >= 0 && $nullentry < $i} {
1143 incr i -1
1149 incr i -1
1144 }
1150 }
1145 } elseif {$nullentry >= 0} {
1151 } elseif {$nullentry >= 0} {
1146 set i $nullentry
1152 set i $nullentry
1147 while {$i < $displ
1153 while {$i < $displ
1148 && [lindex $olddisplist $i] == [lindex $displist $i]} {
1154 && [lindex $olddisplist $i] == [lindex $displist $i]} {
1149 incr i
1155 incr i
1150 }
1156 }
1151 } else {
1157 } else {
1152 set i $olddlevel
1158 set i $olddlevel
1153 if {$dlevel >= $i} {
1159 if {$dlevel >= $i} {
1154 incr i
1160 incr i
1155 }
1161 }
1156 }
1162 }
1157 if {$i < $displ} {
1163 if {$i < $displ} {
1158 set displist [linsert $displist $i {}]
1164 set displist [linsert $displist $i {}]
1159 incr displ
1165 incr displ
1160 if {$dlevel >= $i} {
1166 if {$dlevel >= $i} {
1161 incr dlevel
1167 incr dlevel
1162 }
1168 }
1163 }
1169 }
1164 }
1170 }
1165
1171
1166 # decide on the line spacing for the next line
1172 # decide on the line spacing for the next line
1167 set lj [expr {$lineno + 1}]
1173 set lj [expr {$lineno + 1}]
1168 set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
1174 set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
1169 if {$displ <= 1 || $canvx0 + $displ * $xspc2 <= $maxw} {
1175 if {$displ <= 1 || $canvx0 + $displ * $xspc2 <= $maxw} {
1170 set xspc1($lj) $xspc2
1176 set xspc1($lj) $xspc2
1171 } else {
1177 } else {
1172 set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($displ - 1)}]
1178 set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($displ - 1)}]
1173 if {$xspc1($lj) < $lthickness} {
1179 if {$xspc1($lj) < $lthickness} {
1174 set xspc1($lj) $lthickness
1180 set xspc1($lj) $lthickness
1175 }
1181 }
1176 }
1182 }
1177
1183
1178 foreach idi $reins {
1184 foreach idi $reins {
1179 set id [lindex $idi 0]
1185 set id [lindex $idi 0]
1180 set j [lsearch -exact $displist $id]
1186 set j [lsearch -exact $displist $id]
1181 set xj [xcoord $j $dlevel $lj]
1187 set xj [xcoord $j $dlevel $lj]
1182 set mainline($id) [list $xj $y2]
1188 set mainline($id) [list $xj $y2]
1183 set mainlinearrow($id) first
1189 set mainlinearrow($id) first
1184 }
1190 }
1185
1191
1186 set i -1
1192 set i -1
1187 foreach id $olddisplist {
1193 foreach id $olddisplist {
1188 incr i
1194 incr i
1189 if {$id == {}} continue
1195 if {$id == {}} continue
1190 if {$onscreen($id) <= 0} continue
1196 if {$onscreen($id) <= 0} continue
1191 set xi [xcoord $i $olddlevel $lineno]
1197 set xi [xcoord $i $olddlevel $lineno]
1192 if {$i == $olddlevel} {
1198 if {$i == $olddlevel} {
1193 foreach p $currentparents {
1199 foreach p $currentparents {
1194 set j [lsearch -exact $displist $p]
1200 set j [lsearch -exact $displist $p]
1195 set coords [list $xi $y1]
1201 set coords [list $xi $y1]
1196 set xj [xcoord $j $dlevel $lj]
1202 set xj [xcoord $j $dlevel $lj]
1197 if {$xj < $xi - $linespc} {
1203 if {$xj < $xi - $linespc} {
1198 lappend coords [expr {$xj + $linespc}] $y1
1204 lappend coords [expr {$xj + $linespc}] $y1
1199 notecrossings $p $j $i [expr {$j + 1}]
1205 notecrossings $p $j $i [expr {$j + 1}]
1200 } elseif {$xj > $xi + $linespc} {
1206 } elseif {$xj > $xi + $linespc} {
1201 lappend coords [expr {$xj - $linespc}] $y1
1207 lappend coords [expr {$xj - $linespc}] $y1
1202 notecrossings $p $i $j [expr {$j - 1}]
1208 notecrossings $p $i $j [expr {$j - 1}]
1203 }
1209 }
1204 if {[lsearch -exact $dupparents $p] >= 0} {
1210 if {[lsearch -exact $dupparents $p] >= 0} {
1205 # draw a double-width line to indicate the doubled parent
1211 # draw a double-width line to indicate the doubled parent
1206 lappend coords $xj $y2
1212 lappend coords $xj $y2
1207 lappend sidelines($p) [list $coords 2 none]
1213 lappend sidelines($p) [list $coords 2 none]
1208 if {![info exists mainline($p)]} {
1214 if {![info exists mainline($p)]} {
1209 set mainline($p) [list $xj $y2]
1215 set mainline($p) [list $xj $y2]
1210 set mainlinearrow($p) none
1216 set mainlinearrow($p) none
1211 }
1217 }
1212 } else {
1218 } else {
1213 # normal case, no parent duplicated
1219 # normal case, no parent duplicated
1214 set yb $y2
1220 set yb $y2
1215 set dx [expr {abs($xi - $xj)}]
1221 set dx [expr {abs($xi - $xj)}]
1216 if {0 && $dx < $linespc} {
1222 if {0 && $dx < $linespc} {
1217 set yb [expr {$y1 + $dx}]
1223 set yb [expr {$y1 + $dx}]
1218 }
1224 }
1219 if {![info exists mainline($p)]} {
1225 if {![info exists mainline($p)]} {
1220 if {$xi != $xj} {
1226 if {$xi != $xj} {
1221 lappend coords $xj $yb
1227 lappend coords $xj $yb
1222 }
1228 }
1223 set mainline($p) $coords
1229 set mainline($p) $coords
1224 set mainlinearrow($p) none
1230 set mainlinearrow($p) none
1225 } else {
1231 } else {
1226 lappend coords $xj $yb
1232 lappend coords $xj $yb
1227 if {$yb < $y2} {
1233 if {$yb < $y2} {
1228 lappend coords $xj $y2
1234 lappend coords $xj $y2
1229 }
1235 }
1230 lappend sidelines($p) [list $coords 1 none]
1236 lappend sidelines($p) [list $coords 1 none]
1231 }
1237 }
1232 }
1238 }
1233 }
1239 }
1234 } else {
1240 } else {
1235 set j $i
1241 set j $i
1236 if {[lindex $displist $i] != $id} {
1242 if {[lindex $displist $i] != $id} {
1237 set j [lsearch -exact $displist $id]
1243 set j [lsearch -exact $displist $id]
1238 }
1244 }
1239 if {$j != $i || $xspc1($lineno) != $xspc1($lj)
1245 if {$j != $i || $xspc1($lineno) != $xspc1($lj)
1240 || ($olddlevel < $i && $i < $dlevel)
1246 || ($olddlevel < $i && $i < $dlevel)
1241 || ($dlevel < $i && $i < $olddlevel)} {
1247 || ($dlevel < $i && $i < $olddlevel)} {
1242 set xj [xcoord $j $dlevel $lj]
1248 set xj [xcoord $j $dlevel $lj]
1243 lappend mainline($id) $xi $y1 $xj $y2
1249 lappend mainline($id) $xi $y1 $xj $y2
1244 }
1250 }
1245 }
1251 }
1246 }
1252 }
1247 return $dlevel
1253 return $dlevel
1248 }
1254 }
1249
1255
1250 # search for x in a list of lists
1256 # search for x in a list of lists
1251 proc llsearch {llist x} {
1257 proc llsearch {llist x} {
1252 set i 0
1258 set i 0
1253 foreach l $llist {
1259 foreach l $llist {
1254 if {$l == $x || [lsearch -exact $l $x] >= 0} {
1260 if {$l == $x || [lsearch -exact $l $x] >= 0} {
1255 return $i
1261 return $i
1256 }
1262 }
1257 incr i
1263 incr i
1258 }
1264 }
1259 return -1
1265 return -1
1260 }
1266 }
1261
1267
1262 proc drawmore {reading} {
1268 proc drawmore {reading} {
1263 global displayorder numcommits ncmupdate nextupdate
1269 global displayorder numcommits ncmupdate nextupdate
1264 global stopped nhyperspace parents commitlisted
1270 global stopped nhyperspace parents commitlisted
1265 global maxwidth onscreen displist currentparents olddlevel
1271 global maxwidth onscreen displist currentparents olddlevel
1266
1272
1267 set n [llength $displayorder]
1273 set n [llength $displayorder]
1268 while {$numcommits < $n} {
1274 while {$numcommits < $n} {
1269 set id [lindex $displayorder $numcommits]
1275 set id [lindex $displayorder $numcommits]
1270 set ctxend [expr {$numcommits + 10}]
1276 set ctxend [expr {$numcommits + 10}]
1271 if {!$reading && $ctxend > $n} {
1277 if {!$reading && $ctxend > $n} {
1272 set ctxend $n
1278 set ctxend $n
1273 }
1279 }
1274 set dlist {}
1280 set dlist {}
1275 if {$numcommits > 0} {
1281 if {$numcommits > 0} {
1276 set dlist [lreplace $displist $olddlevel $olddlevel]
1282 set dlist [lreplace $displist $olddlevel $olddlevel]
1277 set i $olddlevel
1283 set i $olddlevel
1278 foreach p $currentparents {
1284 foreach p $currentparents {
1279 if {$onscreen($p) == 0} {
1285 if {$onscreen($p) == 0} {
1280 set dlist [linsert $dlist $i $p]
1286 set dlist [linsert $dlist $i $p]
1281 incr i
1287 incr i
1282 }
1288 }
1283 }
1289 }
1284 }
1290 }
1285 set nohs {}
1291 set nohs {}
1286 set reins {}
1292 set reins {}
1287 set isfat [expr {[llength $dlist] > $maxwidth}]
1293 set isfat [expr {[llength $dlist] > $maxwidth}]
1288 if {$nhyperspace > 0 || $isfat} {
1294 if {$nhyperspace > 0 || $isfat} {
1289 if {$ctxend > $n} break
1295 if {$ctxend > $n} break
1290 # work out what to bring back and
1296 # work out what to bring back and
1291 # what we want to don't want to send into hyperspace
1297 # what we want to don't want to send into hyperspace
1292 set room 1
1298 set room 1
1293 for {set k $numcommits} {$k < $ctxend} {incr k} {
1299 for {set k $numcommits} {$k < $ctxend} {incr k} {
1294 set x [lindex $displayorder $k]
1300 set x [lindex $displayorder $k]
1295 set i [llsearch $dlist $x]
1301 set i [llsearch $dlist $x]
1296 if {$i < 0} {
1302 if {$i < 0} {
1297 set i [llength $dlist]
1303 set i [llength $dlist]
1298 lappend dlist $x
1304 lappend dlist $x
1299 }
1305 }
1300 if {[lsearch -exact $nohs $x] < 0} {
1306 if {[lsearch -exact $nohs $x] < 0} {
1301 lappend nohs $x
1307 lappend nohs $x
1302 }
1308 }
1303 if {$reins eq {} && $onscreen($x) < 0 && $room} {
1309 if {$reins eq {} && $onscreen($x) < 0 && $room} {
1304 set reins [list $x $i]
1310 set reins [list $x $i]
1305 }
1311 }
1306 set newp {}
1312 set newp {}
1307 if {[info exists commitlisted($x)]} {
1313 if {[info exists commitlisted($x)]} {
1308 set right 0
1314 set right 0
1309 foreach p $parents($x) {
1315 foreach p $parents($x) {
1310 if {[llsearch $dlist $p] < 0} {
1316 if {[llsearch $dlist $p] < 0} {
1311 lappend newp $p
1317 lappend newp $p
1312 if {[lsearch -exact $nohs $p] < 0} {
1318 if {[lsearch -exact $nohs $p] < 0} {
1313 lappend nohs $p
1319 lappend nohs $p
1314 }
1320 }
1315 if {$reins eq {} && $onscreen($p) < 0 && $room} {
1321 if {$reins eq {} && $onscreen($p) < 0 && $room} {
1316 set reins [list $p [expr {$i + $right}]]
1322 set reins [list $p [expr {$i + $right}]]
1317 }
1323 }
1318 }
1324 }
1319 set right 1
1325 set right 1
1320 }
1326 }
1321 }
1327 }
1322 set l [lindex $dlist $i]
1328 set l [lindex $dlist $i]
1323 if {[llength $l] == 1} {
1329 if {[llength $l] == 1} {
1324 set l $newp
1330 set l $newp
1325 } else {
1331 } else {
1326 set j [lsearch -exact $l $x]
1332 set j [lsearch -exact $l $x]
1327 set l [concat [lreplace $l $j $j] $newp]
1333 set l [concat [lreplace $l $j $j] $newp]
1328 }
1334 }
1329 set dlist [lreplace $dlist $i $i $l]
1335 set dlist [lreplace $dlist $i $i $l]
1330 if {$room && $isfat && [llength $newp] <= 1} {
1336 if {$room && $isfat && [llength $newp] <= 1} {
1331 set room 0
1337 set room 0
1332 }
1338 }
1333 }
1339 }
1334 }
1340 }
1335
1341
1336 set dlevel [drawslants $id $reins $nohs]
1342 set dlevel [drawslants $id $reins $nohs]
1337 drawcommitline $dlevel
1343 drawcommitline $dlevel
1338 if {[clock clicks -milliseconds] >= $nextupdate
1344 if {[clock clicks -milliseconds] >= $nextupdate
1339 && $numcommits >= $ncmupdate} {
1345 && $numcommits >= $ncmupdate} {
1340 doupdate $reading
1346 doupdate $reading
1341 if {$stopped} break
1347 if {$stopped} break
1342 }
1348 }
1343 }
1349 }
1344 }
1350 }
1345
1351
1346 # level here is an index in todo
1352 # level here is an index in todo
1347 proc updatetodo {level noshortcut} {
1353 proc updatetodo {level noshortcut} {
1348 global ncleft todo nnewparents
1354 global ncleft todo nnewparents
1349 global commitlisted parents onscreen
1355 global commitlisted parents onscreen
1350
1356
1351 set id [lindex $todo $level]
1357 set id [lindex $todo $level]
1352 set olds {}
1358 set olds {}
1353 if {[info exists commitlisted($id)]} {
1359 if {[info exists commitlisted($id)]} {
1354 foreach p $parents($id) {
1360 foreach p $parents($id) {
1355 if {[lsearch -exact $olds $p] < 0} {
1361 if {[lsearch -exact $olds $p] < 0} {
1356 lappend olds $p
1362 lappend olds $p
1357 }
1363 }
1358 }
1364 }
1359 }
1365 }
1360 if {!$noshortcut && [llength $olds] == 1} {
1366 if {!$noshortcut && [llength $olds] == 1} {
1361 set p [lindex $olds 0]
1367 set p [lindex $olds 0]
1362 if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
1368 if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
1363 set ncleft($p) 0
1369 set ncleft($p) 0
1364 set todo [lreplace $todo $level $level $p]
1370 set todo [lreplace $todo $level $level $p]
1365 set onscreen($p) 0
1371 set onscreen($p) 0
1366 set nnewparents($id) 1
1372 set nnewparents($id) 1
1367 return 0
1373 return 0
1368 }
1374 }
1369 }
1375 }
1370
1376
1371 set todo [lreplace $todo $level $level]
1377 set todo [lreplace $todo $level $level]
1372 set i $level
1378 set i $level
1373 set n 0
1379 set n 0
1374 foreach p $olds {
1380 foreach p $olds {
1375 incr ncleft($p) -1
1381 incr ncleft($p) -1
1376 set k [lsearch -exact $todo $p]
1382 set k [lsearch -exact $todo $p]
1377 if {$k < 0} {
1383 if {$k < 0} {
1378 set todo [linsert $todo $i $p]
1384 set todo [linsert $todo $i $p]
1379 set onscreen($p) 0
1385 set onscreen($p) 0
1380 incr i
1386 incr i
1381 incr n
1387 incr n
1382 }
1388 }
1383 }
1389 }
1384 set nnewparents($id) $n
1390 set nnewparents($id) $n
1385
1391
1386 return 1
1392 return 1
1387 }
1393 }
1388
1394
1389 proc decidenext {{noread 0}} {
1395 proc decidenext {{noread 0}} {
1390 global ncleft todo
1396 global ncleft todo
1391 global datemode cdate
1397 global datemode cdate
1392 global commitinfo
1398 global commitinfo
1393
1399
1394 # choose which one to do next time around
1400 # choose which one to do next time around
1395 set todol [llength $todo]
1401 set todol [llength $todo]
1396 set level -1
1402 set level -1
1397 set latest {}
1403 set latest {}
1398 for {set k $todol} {[incr k -1] >= 0} {} {
1404 for {set k $todol} {[incr k -1] >= 0} {} {
1399 set p [lindex $todo $k]
1405 set p [lindex $todo $k]
1400 if {$ncleft($p) == 0} {
1406 if {$ncleft($p) == 0} {
1401 if {$datemode} {
1407 if {$datemode} {
1402 if {![info exists commitinfo($p)]} {
1408 if {![info exists commitinfo($p)]} {
1403 if {$noread} {
1409 if {$noread} {
1404 return {}
1410 return {}
1405 }
1411 }
1406 readcommit $p
1412 readcommit $p
1407 }
1413 }
1408 if {$latest == {} || $cdate($p) > $latest} {
1414 if {$latest == {} || $cdate($p) > $latest} {
1409 set level $k
1415 set level $k
1410 set latest $cdate($p)
1416 set latest $cdate($p)
1411 }
1417 }
1412 } else {
1418 } else {
1413 set level $k
1419 set level $k
1414 break
1420 break
1415 }
1421 }
1416 }
1422 }
1417 }
1423 }
1418 if {$level < 0} {
1424 if {$level < 0} {
1419 if {$todo != {}} {
1425 if {$todo != {}} {
1420 puts "ERROR: none of the pending commits can be done yet:"
1426 puts "ERROR: none of the pending commits can be done yet:"
1421 foreach p $todo {
1427 foreach p $todo {
1422 puts " $p ($ncleft($p))"
1428 puts " $p ($ncleft($p))"
1423 }
1429 }
1424 }
1430 }
1425 return -1
1431 return -1
1426 }
1432 }
1427
1433
1428 return $level
1434 return $level
1429 }
1435 }
1430
1436
1431 proc drawcommit {id} {
1437 proc drawcommit {id} {
1432 global phase todo nchildren datemode nextupdate
1438 global phase todo nchildren datemode nextupdate
1433 global numcommits ncmupdate displayorder todo onscreen
1439 global numcommits ncmupdate displayorder todo onscreen
1434
1440
1435 if {$phase != "incrdraw"} {
1441 if {$phase != "incrdraw"} {
1436 set phase incrdraw
1442 set phase incrdraw
1437 set displayorder {}
1443 set displayorder {}
1438 set todo {}
1444 set todo {}
1439 initgraph
1445 initgraph
1440 }
1446 }
1441 if {$nchildren($id) == 0} {
1447 if {$nchildren($id) == 0} {
1442 lappend todo $id
1448 lappend todo $id
1443 set onscreen($id) 0
1449 set onscreen($id) 0
1444 }
1450 }
1445 set level [decidenext 1]
1451 set level [decidenext 1]
1446 if {$level == {} || $id != [lindex $todo $level]} {
1452 if {$level == {} || $id != [lindex $todo $level]} {
1447 return
1453 return
1448 }
1454 }
1449 while 1 {
1455 while 1 {
1450 lappend displayorder [lindex $todo $level]
1456 lappend displayorder [lindex $todo $level]
1451 if {[updatetodo $level $datemode]} {
1457 if {[updatetodo $level $datemode]} {
1452 set level [decidenext 1]
1458 set level [decidenext 1]
1453 if {$level == {}} break
1459 if {$level == {}} break
1454 }
1460 }
1455 set id [lindex $todo $level]
1461 set id [lindex $todo $level]
1456 if {![info exists commitlisted($id)]} {
1462 if {![info exists commitlisted($id)]} {
1457 break
1463 break
1458 }
1464 }
1459 }
1465 }
1460 drawmore 1
1466 drawmore 1
1461 }
1467 }
1462
1468
1463 proc finishcommits {} {
1469 proc finishcommits {} {
1464 global phase
1470 global phase
1465 global canv mainfont ctext maincursor textcursor
1471 global canv mainfont ctext maincursor textcursor
1466
1472
1467 if {$phase != "incrdraw"} {
1473 if {$phase != "incrdraw"} {
1468 $canv delete all
1474 $canv delete all
1469 $canv create text 3 3 -anchor nw -text "No commits selected" \
1475 $canv create text 3 3 -anchor nw -text "No commits selected" \
1470 -font $mainfont -tags textitems
1476 -font $mainfont -tags textitems
1471 set phase {}
1477 set phase {}
1472 } else {
1478 } else {
1473 drawrest
1479 drawrest
1474 }
1480 }
1475 . config -cursor $maincursor
1481 . config -cursor $maincursor
1476 settextcursor $textcursor
1482 settextcursor $textcursor
1477 }
1483 }
1478
1484
1479 # Don't change the text pane cursor if it is currently the hand cursor,
1485 # Don't change the text pane cursor if it is currently the hand cursor,
1480 # showing that we are over a sha1 ID link.
1486 # showing that we are over a sha1 ID link.
1481 proc settextcursor {c} {
1487 proc settextcursor {c} {
1482 global ctext curtextcursor
1488 global ctext curtextcursor
1483
1489
1484 if {[$ctext cget -cursor] == $curtextcursor} {
1490 if {[$ctext cget -cursor] == $curtextcursor} {
1485 $ctext config -cursor $c
1491 $ctext config -cursor $c
1486 }
1492 }
1487 set curtextcursor $c
1493 set curtextcursor $c
1488 }
1494 }
1489
1495
1490 proc drawgraph {} {
1496 proc drawgraph {} {
1491 global nextupdate startmsecs ncmupdate
1497 global nextupdate startmsecs ncmupdate
1492 global displayorder onscreen
1498 global displayorder onscreen
1493
1499
1494 if {$displayorder == {}} return
1500 if {$displayorder == {}} return
1495 set startmsecs [clock clicks -milliseconds]
1501 set startmsecs [clock clicks -milliseconds]
1496 set nextupdate [expr $startmsecs + 100]
1502 set nextupdate [expr $startmsecs + 100]
1497 set ncmupdate 1
1503 set ncmupdate 1
1498 initgraph
1504 initgraph
1499 foreach id $displayorder {
1505 foreach id $displayorder {
1500 set onscreen($id) 0
1506 set onscreen($id) 0
1501 }
1507 }
1502 drawmore 0
1508 drawmore 0
1503 }
1509 }
1504
1510
1505 proc drawrest {} {
1511 proc drawrest {} {
1506 global phase stopped redisplaying selectedline
1512 global phase stopped redisplaying selectedline
1507 global datemode todo displayorder
1513 global datemode todo displayorder
1508 global numcommits ncmupdate
1514 global numcommits ncmupdate
1509 global nextupdate startmsecs
1515 global nextupdate startmsecs
1510
1516
1511 set level [decidenext]
1517 set level [decidenext]
1512 if {$level >= 0} {
1518 if {$level >= 0} {
1513 set phase drawgraph
1519 set phase drawgraph
1514 while 1 {
1520 while 1 {
1515 lappend displayorder [lindex $todo $level]
1521 lappend displayorder [lindex $todo $level]
1516 set hard [updatetodo $level $datemode]
1522 set hard [updatetodo $level $datemode]
1517 if {$hard} {
1523 if {$hard} {
1518 set level [decidenext]
1524 set level [decidenext]
1519 if {$level < 0} break
1525 if {$level < 0} break
1520 }
1526 }
1521 }
1527 }
1522 drawmore 0
1528 drawmore 0
1523 }
1529 }
1524 set phase {}
1530 set phase {}
1525 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1531 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1526 #puts "overall $drawmsecs ms for $numcommits commits"
1532 #puts "overall $drawmsecs ms for $numcommits commits"
1527 if {$redisplaying} {
1533 if {$redisplaying} {
1528 if {$stopped == 0 && [info exists selectedline]} {
1534 if {$stopped == 0 && [info exists selectedline]} {
1529 selectline $selectedline 0
1535 selectline $selectedline 0
1530 }
1536 }
1531 if {$stopped == 1} {
1537 if {$stopped == 1} {
1532 set stopped 0
1538 set stopped 0
1533 after idle drawgraph
1539 after idle drawgraph
1534 } else {
1540 } else {
1535 set redisplaying 0
1541 set redisplaying 0
1536 }
1542 }
1537 }
1543 }
1538 }
1544 }
1539
1545
1540 proc findmatches {f} {
1546 proc findmatches {f} {
1541 global findtype foundstring foundstrlen
1547 global findtype foundstring foundstrlen
1542 if {$findtype == "Regexp"} {
1548 if {$findtype == "Regexp"} {
1543 set matches [regexp -indices -all -inline $foundstring $f]
1549 set matches [regexp -indices -all -inline $foundstring $f]
1544 } else {
1550 } else {
1545 if {$findtype == "IgnCase"} {
1551 if {$findtype == "IgnCase"} {
1546 set str [string tolower $f]
1552 set str [string tolower $f]
1547 } else {
1553 } else {
1548 set str $f
1554 set str $f
1549 }
1555 }
1550 set matches {}
1556 set matches {}
1551 set i 0
1557 set i 0
1552 while {[set j [string first $foundstring $str $i]] >= 0} {
1558 while {[set j [string first $foundstring $str $i]] >= 0} {
1553 lappend matches [list $j [expr $j+$foundstrlen-1]]
1559 lappend matches [list $j [expr $j+$foundstrlen-1]]
1554 set i [expr $j + $foundstrlen]
1560 set i [expr $j + $foundstrlen]
1555 }
1561 }
1556 }
1562 }
1557 return $matches
1563 return $matches
1558 }
1564 }
1559
1565
1560 proc dofind {} {
1566 proc dofind {} {
1561 global findtype findloc findstring markedmatches commitinfo
1567 global findtype findloc findstring markedmatches commitinfo
1562 global numcommits lineid linehtag linentag linedtag
1568 global numcommits lineid linehtag linentag linedtag
1563 global mainfont namefont canv canv2 canv3 selectedline
1569 global mainfont namefont canv canv2 canv3 selectedline
1564 global matchinglines foundstring foundstrlen
1570 global matchinglines foundstring foundstrlen
1565
1571
1566 stopfindproc
1572 stopfindproc
1567 unmarkmatches
1573 unmarkmatches
1568 focus .
1574 focus .
1569 set matchinglines {}
1575 set matchinglines {}
1570 if {$findloc == "Pickaxe"} {
1576 if {$findloc == "Pickaxe"} {
1571 findpatches
1577 findpatches
1572 return
1578 return
1573 }
1579 }
1574 if {$findtype == "IgnCase"} {
1580 if {$findtype == "IgnCase"} {
1575 set foundstring [string tolower $findstring]
1581 set foundstring [string tolower $findstring]
1576 } else {
1582 } else {
1577 set foundstring $findstring
1583 set foundstring $findstring
1578 }
1584 }
1579 set foundstrlen [string length $findstring]
1585 set foundstrlen [string length $findstring]
1580 if {$foundstrlen == 0} return
1586 if {$foundstrlen == 0} return
1581 if {$findloc == "Files"} {
1587 if {$findloc == "Files"} {
1582 findfiles
1588 findfiles
1583 return
1589 return
1584 }
1590 }
1585 if {![info exists selectedline]} {
1591 if {![info exists selectedline]} {
1586 set oldsel -1
1592 set oldsel -1
1587 } else {
1593 } else {
1588 set oldsel $selectedline
1594 set oldsel $selectedline
1589 }
1595 }
1590 set didsel 0
1596 set didsel 0
1591 set fldtypes {Headline Author Date Committer CDate Comment}
1597 set fldtypes {Headline Author Date Committer CDate Comment}
1592 for {set l 0} {$l < $numcommits} {incr l} {
1598 for {set l 0} {$l < $numcommits} {incr l} {
1593 set id $lineid($l)
1599 set id $lineid($l)
1594 set info $commitinfo($id)
1600 set info $commitinfo($id)
1595 set doesmatch 0
1601 set doesmatch 0
1596 foreach f $info ty $fldtypes {
1602 foreach f $info ty $fldtypes {
1597 if {$findloc != "All fields" && $findloc != $ty} {
1603 if {$findloc != "All fields" && $findloc != $ty} {
1598 continue
1604 continue
1599 }
1605 }
1600 set matches [findmatches $f]
1606 set matches [findmatches $f]
1601 if {$matches == {}} continue
1607 if {$matches == {}} continue
1602 set doesmatch 1
1608 set doesmatch 1
1603 if {$ty == "Headline"} {
1609 if {$ty == "Headline"} {
1604 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1610 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1605 } elseif {$ty == "Author"} {
1611 } elseif {$ty == "Author"} {
1606 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1612 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1607 } elseif {$ty == "Date"} {
1613 } elseif {$ty == "Date"} {
1608 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1614 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1609 }
1615 }
1610 }
1616 }
1611 if {$doesmatch} {
1617 if {$doesmatch} {
1612 lappend matchinglines $l
1618 lappend matchinglines $l
1613 if {!$didsel && $l > $oldsel} {
1619 if {!$didsel && $l > $oldsel} {
1614 findselectline $l
1620 findselectline $l
1615 set didsel 1
1621 set didsel 1
1616 }
1622 }
1617 }
1623 }
1618 }
1624 }
1619 if {$matchinglines == {}} {
1625 if {$matchinglines == {}} {
1620 bell
1626 bell
1621 } elseif {!$didsel} {
1627 } elseif {!$didsel} {
1622 findselectline [lindex $matchinglines 0]
1628 findselectline [lindex $matchinglines 0]
1623 }
1629 }
1624 }
1630 }
1625
1631
1626 proc findselectline {l} {
1632 proc findselectline {l} {
1627 global findloc commentend ctext
1633 global findloc commentend ctext
1628 selectline $l 1
1634 selectline $l 1
1629 if {$findloc == "All fields" || $findloc == "Comments"} {
1635 if {$findloc == "All fields" || $findloc == "Comments"} {
1630 # highlight the matches in the comments
1636 # highlight the matches in the comments
1631 set f [$ctext get 1.0 $commentend]
1637 set f [$ctext get 1.0 $commentend]
1632 set matches [findmatches $f]
1638 set matches [findmatches $f]
1633 foreach match $matches {
1639 foreach match $matches {
1634 set start [lindex $match 0]
1640 set start [lindex $match 0]
1635 set end [expr [lindex $match 1] + 1]
1641 set end [expr [lindex $match 1] + 1]
1636 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1642 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1637 }
1643 }
1638 }
1644 }
1639 }
1645 }
1640
1646
1641 proc findnext {restart} {
1647 proc findnext {restart} {
1642 global matchinglines selectedline
1648 global matchinglines selectedline
1643 if {![info exists matchinglines]} {
1649 if {![info exists matchinglines]} {
1644 if {$restart} {
1650 if {$restart} {
1645 dofind
1651 dofind
1646 }
1652 }
1647 return
1653 return
1648 }
1654 }
1649 if {![info exists selectedline]} return
1655 if {![info exists selectedline]} return
1650 foreach l $matchinglines {
1656 foreach l $matchinglines {
1651 if {$l > $selectedline} {
1657 if {$l > $selectedline} {
1652 findselectline $l
1658 findselectline $l
1653 return
1659 return
1654 }
1660 }
1655 }
1661 }
1656 bell
1662 bell
1657 }
1663 }
1658
1664
1659 proc findprev {} {
1665 proc findprev {} {
1660 global matchinglines selectedline
1666 global matchinglines selectedline
1661 if {![info exists matchinglines]} {
1667 if {![info exists matchinglines]} {
1662 dofind
1668 dofind
1663 return
1669 return
1664 }
1670 }
1665 if {![info exists selectedline]} return
1671 if {![info exists selectedline]} return
1666 set prev {}
1672 set prev {}
1667 foreach l $matchinglines {
1673 foreach l $matchinglines {
1668 if {$l >= $selectedline} break
1674 if {$l >= $selectedline} break
1669 set prev $l
1675 set prev $l
1670 }
1676 }
1671 if {$prev != {}} {
1677 if {$prev != {}} {
1672 findselectline $prev
1678 findselectline $prev
1673 } else {
1679 } else {
1674 bell
1680 bell
1675 }
1681 }
1676 }
1682 }
1677
1683
1678 proc findlocchange {name ix op} {
1684 proc findlocchange {name ix op} {
1679 global findloc findtype findtypemenu
1685 global findloc findtype findtypemenu
1680 if {$findloc == "Pickaxe"} {
1686 if {$findloc == "Pickaxe"} {
1681 set findtype Exact
1687 set findtype Exact
1682 set state disabled
1688 set state disabled
1683 } else {
1689 } else {
1684 set state normal
1690 set state normal
1685 }
1691 }
1686 $findtypemenu entryconf 1 -state $state
1692 $findtypemenu entryconf 1 -state $state
1687 $findtypemenu entryconf 2 -state $state
1693 $findtypemenu entryconf 2 -state $state
1688 }
1694 }
1689
1695
1690 proc stopfindproc {{done 0}} {
1696 proc stopfindproc {{done 0}} {
1691 global findprocpid findprocfile findids
1697 global findprocpid findprocfile findids
1692 global ctext findoldcursor phase maincursor textcursor
1698 global ctext findoldcursor phase maincursor textcursor
1693 global findinprogress
1699 global findinprogress
1694
1700
1695 catch {unset findids}
1701 catch {unset findids}
1696 if {[info exists findprocpid]} {
1702 if {[info exists findprocpid]} {
1697 if {!$done} {
1703 if {!$done} {
1698 catch {exec kill $findprocpid}
1704 catch {exec kill $findprocpid}
1699 }
1705 }
1700 catch {close $findprocfile}
1706 catch {close $findprocfile}
1701 unset findprocpid
1707 unset findprocpid
1702 }
1708 }
1703 if {[info exists findinprogress]} {
1709 if {[info exists findinprogress]} {
1704 unset findinprogress
1710 unset findinprogress
1705 if {$phase != "incrdraw"} {
1711 if {$phase != "incrdraw"} {
1706 . config -cursor $maincursor
1712 . config -cursor $maincursor
1707 settextcursor $textcursor
1713 settextcursor $textcursor
1708 }
1714 }
1709 }
1715 }
1710 }
1716 }
1711
1717
1712 proc findpatches {} {
1718 proc findpatches {} {
1713 global findstring selectedline numcommits
1719 global findstring selectedline numcommits
1714 global findprocpid findprocfile
1720 global findprocpid findprocfile
1715 global finddidsel ctext lineid findinprogress
1721 global finddidsel ctext lineid findinprogress
1716 global findinsertpos
1722 global findinsertpos
1717 global env
1723 global env
1718
1724
1719 if {$numcommits == 0} return
1725 if {$numcommits == 0} return
1720
1726
1721 # make a list of all the ids to search, starting at the one
1727 # make a list of all the ids to search, starting at the one
1722 # after the selected line (if any)
1728 # after the selected line (if any)
1723 if {[info exists selectedline]} {
1729 if {[info exists selectedline]} {
1724 set l $selectedline
1730 set l $selectedline
1725 } else {
1731 } else {
1726 set l -1
1732 set l -1
1727 }
1733 }
1728 set inputids {}
1734 set inputids {}
1729 for {set i 0} {$i < $numcommits} {incr i} {
1735 for {set i 0} {$i < $numcommits} {incr i} {
1730 if {[incr l] >= $numcommits} {
1736 if {[incr l] >= $numcommits} {
1731 set l 0
1737 set l 0
1732 }
1738 }
1733 append inputids $lineid($l) "\n"
1739 append inputids $lineid($l) "\n"
1734 }
1740 }
1735
1741
1736 if {[catch {
1742 if {[catch {
1737 set f [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree --stdin -s -r -S$findstring << $inputids] r]
1743 set f [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree --stdin -s -r -S$findstring << $inputids] r]
1738 } err]} {
1744 } err]} {
1739 error_popup "Error starting search process: $err"
1745 error_popup "Error starting search process: $err"
1740 return
1746 return
1741 }
1747 }
1742
1748
1743 set findinsertpos end
1749 set findinsertpos end
1744 set findprocfile $f
1750 set findprocfile $f
1745 set findprocpid [pid $f]
1751 set findprocpid [pid $f]
1746 fconfigure $f -blocking 0
1752 fconfigure $f -blocking 0
1747 fileevent $f readable readfindproc
1753 fileevent $f readable readfindproc
1748 set finddidsel 0
1754 set finddidsel 0
1749 . config -cursor watch
1755 . config -cursor watch
1750 settextcursor watch
1756 settextcursor watch
1751 set findinprogress 1
1757 set findinprogress 1
1752 }
1758 }
1753
1759
1754 proc readfindproc {} {
1760 proc readfindproc {} {
1755 global findprocfile finddidsel
1761 global findprocfile finddidsel
1756 global idline matchinglines findinsertpos
1762 global idline matchinglines findinsertpos
1757
1763
1758 set n [gets $findprocfile line]
1764 set n [gets $findprocfile line]
1759 if {$n < 0} {
1765 if {$n < 0} {
1760 if {[eof $findprocfile]} {
1766 if {[eof $findprocfile]} {
1761 stopfindproc 1
1767 stopfindproc 1
1762 if {!$finddidsel} {
1768 if {!$finddidsel} {
1763 bell
1769 bell
1764 }
1770 }
1765 }
1771 }
1766 return
1772 return
1767 }
1773 }
1768 if {![regexp {^[0-9a-f]{12}} $line id]} {
1774 if {![regexp {^[0-9a-f]{12}} $line id]} {
1769 error_popup "Can't parse git-diff-tree output: $line"
1775 error_popup "Can't parse git-diff-tree output: $line"
1770 stopfindproc
1776 stopfindproc
1771 return
1777 return
1772 }
1778 }
1773 if {![info exists idline($id)]} {
1779 if {![info exists idline($id)]} {
1774 puts stderr "spurious id: $id"
1780 puts stderr "spurious id: $id"
1775 return
1781 return
1776 }
1782 }
1777 set l $idline($id)
1783 set l $idline($id)
1778 insertmatch $l $id
1784 insertmatch $l $id
1779 }
1785 }
1780
1786
1781 proc insertmatch {l id} {
1787 proc insertmatch {l id} {
1782 global matchinglines findinsertpos finddidsel
1788 global matchinglines findinsertpos finddidsel
1783
1789
1784 if {$findinsertpos == "end"} {
1790 if {$findinsertpos == "end"} {
1785 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
1791 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
1786 set matchinglines [linsert $matchinglines 0 $l]
1792 set matchinglines [linsert $matchinglines 0 $l]
1787 set findinsertpos 1
1793 set findinsertpos 1
1788 } else {
1794 } else {
1789 lappend matchinglines $l
1795 lappend matchinglines $l
1790 }
1796 }
1791 } else {
1797 } else {
1792 set matchinglines [linsert $matchinglines $findinsertpos $l]
1798 set matchinglines [linsert $matchinglines $findinsertpos $l]
1793 incr findinsertpos
1799 incr findinsertpos
1794 }
1800 }
1795 markheadline $l $id
1801 markheadline $l $id
1796 if {!$finddidsel} {
1802 if {!$finddidsel} {
1797 findselectline $l
1803 findselectline $l
1798 set finddidsel 1
1804 set finddidsel 1
1799 }
1805 }
1800 }
1806 }
1801
1807
1802 proc findfiles {} {
1808 proc findfiles {} {
1803 global selectedline numcommits lineid ctext
1809 global selectedline numcommits lineid ctext
1804 global ffileline finddidsel parents nparents
1810 global ffileline finddidsel parents nparents
1805 global findinprogress findstartline findinsertpos
1811 global findinprogress findstartline findinsertpos
1806 global treediffs fdiffids fdiffsneeded fdiffpos
1812 global treediffs fdiffids fdiffsneeded fdiffpos
1807 global findmergefiles
1813 global findmergefiles
1808 global env
1814 global env
1809
1815
1810 if {$numcommits == 0} return
1816 if {$numcommits == 0} return
1811
1817
1812 if {[info exists selectedline]} {
1818 if {[info exists selectedline]} {
1813 set l [expr {$selectedline + 1}]
1819 set l [expr {$selectedline + 1}]
1814 } else {
1820 } else {
1815 set l 0
1821 set l 0
1816 }
1822 }
1817 set ffileline $l
1823 set ffileline $l
1818 set findstartline $l
1824 set findstartline $l
1819 set diffsneeded {}
1825 set diffsneeded {}
1820 set fdiffsneeded {}
1826 set fdiffsneeded {}
1821 while 1 {
1827 while 1 {
1822 set id $lineid($l)
1828 set id $lineid($l)
1823 if {$findmergefiles || $nparents($id) == 1} {
1829 if {$findmergefiles || $nparents($id) == 1} {
1824 foreach p $parents($id) {
1830 foreach p $parents($id) {
1825 if {![info exists treediffs([list $id $p])]} {
1831 if {![info exists treediffs([list $id $p])]} {
1826 append diffsneeded "$id $p\n"
1832 append diffsneeded "$id $p\n"
1827 lappend fdiffsneeded [list $id $p]
1833 lappend fdiffsneeded [list $id $p]
1828 }
1834 }
1829 }
1835 }
1830 }
1836 }
1831 if {[incr l] >= $numcommits} {
1837 if {[incr l] >= $numcommits} {
1832 set l 0
1838 set l 0
1833 }
1839 }
1834 if {$l == $findstartline} break
1840 if {$l == $findstartline} break
1835 }
1841 }
1836
1842
1837 # start off a git-diff-tree process if needed
1843 # start off a git-diff-tree process if needed
1838 if {$diffsneeded ne {}} {
1844 if {$diffsneeded ne {}} {
1839 if {[catch {
1845 if {[catch {
1840 set df [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r --stdin << $diffsneeded] r]
1846 set df [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r --stdin << $diffsneeded] r]
1841 } err ]} {
1847 } err ]} {
1842 error_popup "Error starting search process: $err"
1848 error_popup "Error starting search process: $err"
1843 return
1849 return
1844 }
1850 }
1845 catch {unset fdiffids}
1851 catch {unset fdiffids}
1846 set fdiffpos 0
1852 set fdiffpos 0
1847 fconfigure $df -blocking 0
1853 fconfigure $df -blocking 0
1848 fileevent $df readable [list readfilediffs $df]
1854 fileevent $df readable [list readfilediffs $df]
1849 }
1855 }
1850
1856
1851 set finddidsel 0
1857 set finddidsel 0
1852 set findinsertpos end
1858 set findinsertpos end
1853 set id $lineid($l)
1859 set id $lineid($l)
1854 set p [lindex $parents($id) 0]
1860 set p [lindex $parents($id) 0]
1855 . config -cursor watch
1861 . config -cursor watch
1856 settextcursor watch
1862 settextcursor watch
1857 set findinprogress 1
1863 set findinprogress 1
1858 findcont [list $id $p]
1864 findcont [list $id $p]
1859 update
1865 update
1860 }
1866 }
1861
1867
1862 proc readfilediffs {df} {
1868 proc readfilediffs {df} {
1863 global findids fdiffids fdiffs
1869 global findids fdiffids fdiffs
1864
1870
1865 set n [gets $df line]
1871 set n [gets $df line]
1866 if {$n < 0} {
1872 if {$n < 0} {
1867 if {[eof $df]} {
1873 if {[eof $df]} {
1868 donefilediff
1874 donefilediff
1869 if {[catch {close $df} err]} {
1875 if {[catch {close $df} err]} {
1870 stopfindproc
1876 stopfindproc
1871 bell
1877 bell
1872 error_popup "Error in hg debug-diff-tree: $err"
1878 error_popup "Error in hg debug-diff-tree: $err"
1873 } elseif {[info exists findids]} {
1879 } elseif {[info exists findids]} {
1874 set ids $findids
1880 set ids $findids
1875 stopfindproc
1881 stopfindproc
1876 bell
1882 bell
1877 error_popup "Couldn't find diffs for {$ids}"
1883 error_popup "Couldn't find diffs for {$ids}"
1878 }
1884 }
1879 }
1885 }
1880 return
1886 return
1881 }
1887 }
1882 if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
1888 if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
1883 # start of a new string of diffs
1889 # start of a new string of diffs
1884 donefilediff
1890 donefilediff
1885 set fdiffids [list $id $p]
1891 set fdiffids [list $id $p]
1886 set fdiffs {}
1892 set fdiffs {}
1887 } elseif {[string match ":*" $line]} {
1893 } elseif {[string match ":*" $line]} {
1888 lappend fdiffs [lindex $line 5]
1894 lappend fdiffs [lindex $line 5]
1889 }
1895 }
1890 }
1896 }
1891
1897
1892 proc donefilediff {} {
1898 proc donefilediff {} {
1893 global fdiffids fdiffs treediffs findids
1899 global fdiffids fdiffs treediffs findids
1894 global fdiffsneeded fdiffpos
1900 global fdiffsneeded fdiffpos
1895
1901
1896 if {[info exists fdiffids]} {
1902 if {[info exists fdiffids]} {
1897 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffids
1903 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffids
1898 && $fdiffpos < [llength $fdiffsneeded]} {
1904 && $fdiffpos < [llength $fdiffsneeded]} {
1899 # git-diff-tree doesn't output anything for a commit
1905 # git-diff-tree doesn't output anything for a commit
1900 # which doesn't change anything
1906 # which doesn't change anything
1901 set nullids [lindex $fdiffsneeded $fdiffpos]
1907 set nullids [lindex $fdiffsneeded $fdiffpos]
1902 set treediffs($nullids) {}
1908 set treediffs($nullids) {}
1903 if {[info exists findids] && $nullids eq $findids} {
1909 if {[info exists findids] && $nullids eq $findids} {
1904 unset findids
1910 unset findids
1905 findcont $nullids
1911 findcont $nullids
1906 }
1912 }
1907 incr fdiffpos
1913 incr fdiffpos
1908 }
1914 }
1909 incr fdiffpos
1915 incr fdiffpos
1910
1916
1911 if {![info exists treediffs($fdiffids)]} {
1917 if {![info exists treediffs($fdiffids)]} {
1912 set treediffs($fdiffids) $fdiffs
1918 set treediffs($fdiffids) $fdiffs
1913 }
1919 }
1914 if {[info exists findids] && $fdiffids eq $findids} {
1920 if {[info exists findids] && $fdiffids eq $findids} {
1915 unset findids
1921 unset findids
1916 findcont $fdiffids
1922 findcont $fdiffids
1917 }
1923 }
1918 }
1924 }
1919 }
1925 }
1920
1926
1921 proc findcont {ids} {
1927 proc findcont {ids} {
1922 global findids treediffs parents nparents
1928 global findids treediffs parents nparents
1923 global ffileline findstartline finddidsel
1929 global ffileline findstartline finddidsel
1924 global lineid numcommits matchinglines findinprogress
1930 global lineid numcommits matchinglines findinprogress
1925 global findmergefiles
1931 global findmergefiles
1926
1932
1927 set id [lindex $ids 0]
1933 set id [lindex $ids 0]
1928 set p [lindex $ids 1]
1934 set p [lindex $ids 1]
1929 set pi [lsearch -exact $parents($id) $p]
1935 set pi [lsearch -exact $parents($id) $p]
1930 set l $ffileline
1936 set l $ffileline
1931 while 1 {
1937 while 1 {
1932 if {$findmergefiles || $nparents($id) == 1} {
1938 if {$findmergefiles || $nparents($id) == 1} {
1933 if {![info exists treediffs($ids)]} {
1939 if {![info exists treediffs($ids)]} {
1934 set findids $ids
1940 set findids $ids
1935 set ffileline $l
1941 set ffileline $l
1936 return
1942 return
1937 }
1943 }
1938 set doesmatch 0
1944 set doesmatch 0
1939 foreach f $treediffs($ids) {
1945 foreach f $treediffs($ids) {
1940 set x [findmatches $f]
1946 set x [findmatches $f]
1941 if {$x != {}} {
1947 if {$x != {}} {
1942 set doesmatch 1
1948 set doesmatch 1
1943 break
1949 break
1944 }
1950 }
1945 }
1951 }
1946 if {$doesmatch} {
1952 if {$doesmatch} {
1947 insertmatch $l $id
1953 insertmatch $l $id
1948 set pi $nparents($id)
1954 set pi $nparents($id)
1949 }
1955 }
1950 } else {
1956 } else {
1951 set pi $nparents($id)
1957 set pi $nparents($id)
1952 }
1958 }
1953 if {[incr pi] >= $nparents($id)} {
1959 if {[incr pi] >= $nparents($id)} {
1954 set pi 0
1960 set pi 0
1955 if {[incr l] >= $numcommits} {
1961 if {[incr l] >= $numcommits} {
1956 set l 0
1962 set l 0
1957 }
1963 }
1958 if {$l == $findstartline} break
1964 if {$l == $findstartline} break
1959 set id $lineid($l)
1965 set id $lineid($l)
1960 }
1966 }
1961 set p [lindex $parents($id) $pi]
1967 set p [lindex $parents($id) $pi]
1962 set ids [list $id $p]
1968 set ids [list $id $p]
1963 }
1969 }
1964 stopfindproc
1970 stopfindproc
1965 if {!$finddidsel} {
1971 if {!$finddidsel} {
1966 bell
1972 bell
1967 }
1973 }
1968 }
1974 }
1969
1975
1970 # mark a commit as matching by putting a yellow background
1976 # mark a commit as matching by putting a yellow background
1971 # behind the headline
1977 # behind the headline
1972 proc markheadline {l id} {
1978 proc markheadline {l id} {
1973 global canv mainfont linehtag commitinfo
1979 global canv mainfont linehtag commitinfo
1974
1980
1975 set bbox [$canv bbox $linehtag($l)]
1981 set bbox [$canv bbox $linehtag($l)]
1976 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
1982 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
1977 $canv lower $t
1983 $canv lower $t
1978 }
1984 }
1979
1985
1980 # mark the bits of a headline, author or date that match a find string
1986 # mark the bits of a headline, author or date that match a find string
1981 proc markmatches {canv l str tag matches font} {
1987 proc markmatches {canv l str tag matches font} {
1982 set bbox [$canv bbox $tag]
1988 set bbox [$canv bbox $tag]
1983 set x0 [lindex $bbox 0]
1989 set x0 [lindex $bbox 0]
1984 set y0 [lindex $bbox 1]
1990 set y0 [lindex $bbox 1]
1985 set y1 [lindex $bbox 3]
1991 set y1 [lindex $bbox 3]
1986 foreach match $matches {
1992 foreach match $matches {
1987 set start [lindex $match 0]
1993 set start [lindex $match 0]
1988 set end [lindex $match 1]
1994 set end [lindex $match 1]
1989 if {$start > $end} continue
1995 if {$start > $end} continue
1990 set xoff [font measure $font [string range $str 0 [expr $start-1]]]
1996 set xoff [font measure $font [string range $str 0 [expr $start-1]]]
1991 set xlen [font measure $font [string range $str 0 [expr $end]]]
1997 set xlen [font measure $font [string range $str 0 [expr $end]]]
1992 set t [$canv create rect [expr $x0+$xoff] $y0 [expr $x0+$xlen+2] $y1 \
1998 set t [$canv create rect [expr $x0+$xoff] $y0 [expr $x0+$xlen+2] $y1 \
1993 -outline {} -tags matches -fill yellow]
1999 -outline {} -tags matches -fill yellow]
1994 $canv lower $t
2000 $canv lower $t
1995 }
2001 }
1996 }
2002 }
1997
2003
1998 proc unmarkmatches {} {
2004 proc unmarkmatches {} {
1999 global matchinglines findids
2005 global matchinglines findids
2000 allcanvs delete matches
2006 allcanvs delete matches
2001 catch {unset matchinglines}
2007 catch {unset matchinglines}
2002 catch {unset findids}
2008 catch {unset findids}
2003 }
2009 }
2004
2010
2005 proc selcanvline {w x y} {
2011 proc selcanvline {w x y} {
2006 global canv canvy0 ctext linespc
2012 global canv canvy0 ctext linespc
2007 global lineid linehtag linentag linedtag rowtextx
2013 global lineid linehtag linentag linedtag rowtextx
2008 set ymax [lindex [$canv cget -scrollregion] 3]
2014 set ymax [lindex [$canv cget -scrollregion] 3]
2009 if {$ymax == {}} return
2015 if {$ymax == {}} return
2010 set yfrac [lindex [$canv yview] 0]
2016 set yfrac [lindex [$canv yview] 0]
2011 set y [expr {$y + $yfrac * $ymax}]
2017 set y [expr {$y + $yfrac * $ymax}]
2012 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2018 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2013 if {$l < 0} {
2019 if {$l < 0} {
2014 set l 0
2020 set l 0
2015 }
2021 }
2016 if {$w eq $canv} {
2022 if {$w eq $canv} {
2017 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2023 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2018 }
2024 }
2019 unmarkmatches
2025 unmarkmatches
2020 selectline $l 1
2026 selectline $l 1
2021 }
2027 }
2022
2028
2023 proc commit_descriptor {p} {
2029 proc commit_descriptor {p} {
2024 global commitinfo
2030 global commitinfo
2025 set l "..."
2031 set l "..."
2026 if {[info exists commitinfo($p)]} {
2032 if {[info exists commitinfo($p)]} {
2027 set l [lindex $commitinfo($p) 0]
2033 set l [lindex $commitinfo($p) 0]
2028 set r [lindex $commitinfo($p) 6]
2034 set r [lindex $commitinfo($p) 6]
2029 }
2035 }
2030 return "$r:$p ($l)"
2036 return "$r:$p ($l)"
2031 }
2037 }
2032
2038
2033 # append some text to the ctext widget, and make any SHA1 ID
2039 # append some text to the ctext widget, and make any SHA1 ID
2034 # that we know about be a clickable link.
2040 # that we know about be a clickable link.
2035 proc appendwithlinks {text} {
2041 proc appendwithlinks {text} {
2036 global ctext idline linknum
2042 global ctext idline linknum
2037
2043
2038 set start [$ctext index "end - 1c"]
2044 set start [$ctext index "end - 1c"]
2039 $ctext insert end $text
2045 $ctext insert end $text
2040 $ctext insert end "\n"
2046 $ctext insert end "\n"
2041 set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
2047 set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
2042 foreach l $links {
2048 foreach l $links {
2043 set s [lindex $l 0]
2049 set s [lindex $l 0]
2044 set e [lindex $l 1]
2050 set e [lindex $l 1]
2045 set linkid [string range $text $s $e]
2051 set linkid [string range $text $s $e]
2046 if {![info exists idline($linkid)]} continue
2052 if {![info exists idline($linkid)]} continue
2047 incr e
2053 incr e
2048 $ctext tag add link "$start + $s c" "$start + $e c"
2054 $ctext tag add link "$start + $s c" "$start + $e c"
2049 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2055 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2050 $ctext tag bind link$linknum <1> [list selectline $idline($linkid) 1]
2056 $ctext tag bind link$linknum <1> [list selectline $idline($linkid) 1]
2051 incr linknum
2057 incr linknum
2052 }
2058 }
2053 $ctext tag conf link -foreground blue -underline 1
2059 $ctext tag conf link -foreground blue -underline 1
2054 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2060 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2055 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2061 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2056 }
2062 }
2057
2063
2058 proc selectline {l isnew} {
2064 proc selectline {l isnew} {
2059 global canv canv2 canv3 ctext commitinfo selectedline
2065 global canv canv2 canv3 ctext commitinfo selectedline
2060 global lineid linehtag linentag linedtag
2066 global lineid linehtag linentag linedtag
2061 global canvy0 linespc parents nparents children
2067 global canvy0 linespc parents nparents children
2062 global cflist currentid sha1entry
2068 global cflist currentid sha1entry
2063 global commentend idtags idline linknum
2069 global commentend idtags idline linknum
2064
2070
2065 $canv delete hover
2071 $canv delete hover
2066 normalline
2072 normalline
2067 if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
2073 if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
2068 $canv delete secsel
2074 $canv delete secsel
2069 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2075 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2070 -tags secsel -fill [$canv cget -selectbackground]]
2076 -tags secsel -fill [$canv cget -selectbackground]]
2071 $canv lower $t
2077 $canv lower $t
2072 $canv2 delete secsel
2078 $canv2 delete secsel
2073 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2079 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2074 -tags secsel -fill [$canv2 cget -selectbackground]]
2080 -tags secsel -fill [$canv2 cget -selectbackground]]
2075 $canv2 lower $t
2081 $canv2 lower $t
2076 $canv3 delete secsel
2082 $canv3 delete secsel
2077 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2083 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2078 -tags secsel -fill [$canv3 cget -selectbackground]]
2084 -tags secsel -fill [$canv3 cget -selectbackground]]
2079 $canv3 lower $t
2085 $canv3 lower $t
2080 set y [expr {$canvy0 + $l * $linespc}]
2086 set y [expr {$canvy0 + $l * $linespc}]
2081 set ymax [lindex [$canv cget -scrollregion] 3]
2087 set ymax [lindex [$canv cget -scrollregion] 3]
2082 set ytop [expr {$y - $linespc - 1}]
2088 set ytop [expr {$y - $linespc - 1}]
2083 set ybot [expr {$y + $linespc + 1}]
2089 set ybot [expr {$y + $linespc + 1}]
2084 set wnow [$canv yview]
2090 set wnow [$canv yview]
2085 set wtop [expr [lindex $wnow 0] * $ymax]
2091 set wtop [expr [lindex $wnow 0] * $ymax]
2086 set wbot [expr [lindex $wnow 1] * $ymax]
2092 set wbot [expr [lindex $wnow 1] * $ymax]
2087 set wh [expr {$wbot - $wtop}]
2093 set wh [expr {$wbot - $wtop}]
2088 set newtop $wtop
2094 set newtop $wtop
2089 if {$ytop < $wtop} {
2095 if {$ytop < $wtop} {
2090 if {$ybot < $wtop} {
2096 if {$ybot < $wtop} {
2091 set newtop [expr {$y - $wh / 2.0}]
2097 set newtop [expr {$y - $wh / 2.0}]
2092 } else {
2098 } else {
2093 set newtop $ytop
2099 set newtop $ytop
2094 if {$newtop > $wtop - $linespc} {
2100 if {$newtop > $wtop - $linespc} {
2095 set newtop [expr {$wtop - $linespc}]
2101 set newtop [expr {$wtop - $linespc}]
2096 }
2102 }
2097 }
2103 }
2098 } elseif {$ybot > $wbot} {
2104 } elseif {$ybot > $wbot} {
2099 if {$ytop > $wbot} {
2105 if {$ytop > $wbot} {
2100 set newtop [expr {$y - $wh / 2.0}]
2106 set newtop [expr {$y - $wh / 2.0}]
2101 } else {
2107 } else {
2102 set newtop [expr {$ybot - $wh}]
2108 set newtop [expr {$ybot - $wh}]
2103 if {$newtop < $wtop + $linespc} {
2109 if {$newtop < $wtop + $linespc} {
2104 set newtop [expr {$wtop + $linespc}]
2110 set newtop [expr {$wtop + $linespc}]
2105 }
2111 }
2106 }
2112 }
2107 }
2113 }
2108 if {$newtop != $wtop} {
2114 if {$newtop != $wtop} {
2109 if {$newtop < 0} {
2115 if {$newtop < 0} {
2110 set newtop 0
2116 set newtop 0
2111 }
2117 }
2112 allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
2118 allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
2113 }
2119 }
2114
2120
2115 if {$isnew} {
2121 if {$isnew} {
2116 addtohistory [list selectline $l 0]
2122 addtohistory [list selectline $l 0]
2117 }
2123 }
2118
2124
2119 set selectedline $l
2125 set selectedline $l
2120
2126
2121 set id $lineid($l)
2127 set id $lineid($l)
2122 set currentid $id
2128 set currentid $id
2123 $sha1entry delete 0 end
2129 $sha1entry delete 0 end
2124 $sha1entry insert 0 $id
2130 $sha1entry insert 0 $id
2125 $sha1entry selection from 0
2131 $sha1entry selection from 0
2126 $sha1entry selection to end
2132 $sha1entry selection to end
2127
2133
2128 $ctext conf -state normal
2134 $ctext conf -state normal
2129 $ctext delete 0.0 end
2135 $ctext delete 0.0 end
2130 set linknum 0
2136 set linknum 0
2131 $ctext mark set fmark.0 0.0
2137 $ctext mark set fmark.0 0.0
2132 $ctext mark gravity fmark.0 left
2138 $ctext mark gravity fmark.0 left
2133 set info $commitinfo($id)
2139 set info $commitinfo($id)
2134 $ctext insert end "Revision: [lindex $info 6]\n"
2140 $ctext insert end "Revision: [lindex $info 6]\n"
2135 $ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n"
2141 $ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n"
2136 $ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n"
2142 $ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n"
2137 if {[info exists idtags($id)]} {
2143 if {[info exists idtags($id)]} {
2138 $ctext insert end "Tags:"
2144 $ctext insert end "Tags:"
2139 foreach tag $idtags($id) {
2145 foreach tag $idtags($id) {
2140 $ctext insert end " $tag"
2146 $ctext insert end " $tag"
2141 }
2147 }
2142 $ctext insert end "\n"
2148 $ctext insert end "\n"
2143 }
2149 }
2144
2150
2145 set comment {}
2151 set comment {}
2146 if {[info exists parents($id)]} {
2152 if {[info exists parents($id)]} {
2147 foreach p $parents($id) {
2153 foreach p $parents($id) {
2148 append comment "Parent: [commit_descriptor $p]\n"
2154 append comment "Parent: [commit_descriptor $p]\n"
2149 }
2155 }
2150 }
2156 }
2151 if {[info exists children($id)]} {
2157 if {[info exists children($id)]} {
2152 foreach c $children($id) {
2158 foreach c $children($id) {
2153 append comment "Child: [commit_descriptor $c]\n"
2159 append comment "Child: [commit_descriptor $c]\n"
2154 }
2160 }
2155 }
2161 }
2156 append comment "\n"
2162 append comment "\n"
2157 append comment [lindex $info 5]
2163 append comment [lindex $info 5]
2158
2164
2159 # make anything that looks like a SHA1 ID be a clickable link
2165 # make anything that looks like a SHA1 ID be a clickable link
2160 appendwithlinks $comment
2166 appendwithlinks $comment
2161
2167
2162 $ctext tag delete Comments
2168 $ctext tag delete Comments
2163 $ctext tag remove found 1.0 end
2169 $ctext tag remove found 1.0 end
2164 $ctext conf -state disabled
2170 $ctext conf -state disabled
2165 set commentend [$ctext index "end - 1c"]
2171 set commentend [$ctext index "end - 1c"]
2166
2172
2167 $cflist delete 0 end
2173 $cflist delete 0 end
2168 $cflist insert end "Comments"
2174 $cflist insert end "Comments"
2169 if {$nparents($id) == 1} {
2175 if {$nparents($id) == 1} {
2170 startdiff [concat $id $parents($id)]
2176 startdiff [concat $id $parents($id)]
2171 } elseif {$nparents($id) > 1} {
2177 } elseif {$nparents($id) > 1} {
2172 mergediff $id
2178 mergediff $id
2173 }
2179 }
2174 }
2180 }
2175
2181
2176 proc selnextline {dir} {
2182 proc selnextline {dir} {
2177 global selectedline
2183 global selectedline
2178 if {![info exists selectedline]} return
2184 if {![info exists selectedline]} return
2179 set l [expr $selectedline + $dir]
2185 set l [expr $selectedline + $dir]
2180 unmarkmatches
2186 unmarkmatches
2181 selectline $l 1
2187 selectline $l 1
2182 }
2188 }
2183
2189
2184 proc unselectline {} {
2190 proc unselectline {} {
2185 global selectedline
2191 global selectedline
2186
2192
2187 catch {unset selectedline}
2193 catch {unset selectedline}
2188 allcanvs delete secsel
2194 allcanvs delete secsel
2189 }
2195 }
2190
2196
2191 proc addtohistory {cmd} {
2197 proc addtohistory {cmd} {
2192 global history historyindex
2198 global history historyindex
2193
2199
2194 if {$historyindex > 0
2200 if {$historyindex > 0
2195 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2201 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2196 return
2202 return
2197 }
2203 }
2198
2204
2199 if {$historyindex < [llength $history]} {
2205 if {$historyindex < [llength $history]} {
2200 set history [lreplace $history $historyindex end $cmd]
2206 set history [lreplace $history $historyindex end $cmd]
2201 } else {
2207 } else {
2202 lappend history $cmd
2208 lappend history $cmd
2203 }
2209 }
2204 incr historyindex
2210 incr historyindex
2205 if {$historyindex > 1} {
2211 if {$historyindex > 1} {
2206 .ctop.top.bar.leftbut conf -state normal
2212 .ctop.top.bar.leftbut conf -state normal
2207 } else {
2213 } else {
2208 .ctop.top.bar.leftbut conf -state disabled
2214 .ctop.top.bar.leftbut conf -state disabled
2209 }
2215 }
2210 .ctop.top.bar.rightbut conf -state disabled
2216 .ctop.top.bar.rightbut conf -state disabled
2211 }
2217 }
2212
2218
2213 proc goback {} {
2219 proc goback {} {
2214 global history historyindex
2220 global history historyindex
2215
2221
2216 if {$historyindex > 1} {
2222 if {$historyindex > 1} {
2217 incr historyindex -1
2223 incr historyindex -1
2218 set cmd [lindex $history [expr {$historyindex - 1}]]
2224 set cmd [lindex $history [expr {$historyindex - 1}]]
2219 eval $cmd
2225 eval $cmd
2220 .ctop.top.bar.rightbut conf -state normal
2226 .ctop.top.bar.rightbut conf -state normal
2221 }
2227 }
2222 if {$historyindex <= 1} {
2228 if {$historyindex <= 1} {
2223 .ctop.top.bar.leftbut conf -state disabled
2229 .ctop.top.bar.leftbut conf -state disabled
2224 }
2230 }
2225 }
2231 }
2226
2232
2227 proc goforw {} {
2233 proc goforw {} {
2228 global history historyindex
2234 global history historyindex
2229
2235
2230 if {$historyindex < [llength $history]} {
2236 if {$historyindex < [llength $history]} {
2231 set cmd [lindex $history $historyindex]
2237 set cmd [lindex $history $historyindex]
2232 incr historyindex
2238 incr historyindex
2233 eval $cmd
2239 eval $cmd
2234 .ctop.top.bar.leftbut conf -state normal
2240 .ctop.top.bar.leftbut conf -state normal
2235 }
2241 }
2236 if {$historyindex >= [llength $history]} {
2242 if {$historyindex >= [llength $history]} {
2237 .ctop.top.bar.rightbut conf -state disabled
2243 .ctop.top.bar.rightbut conf -state disabled
2238 }
2244 }
2239 }
2245 }
2240
2246
2241 proc mergediff {id} {
2247 proc mergediff {id} {
2242 global parents diffmergeid diffmergegca mergefilelist diffpindex
2248 global parents diffmergeid diffmergegca mergefilelist diffpindex
2243
2249
2244 set diffmergeid $id
2250 set diffmergeid $id
2245 set diffpindex -1
2251 set diffpindex -1
2246 set diffmergegca [findgca $parents($id)]
2252 set diffmergegca [findgca $parents($id)]
2247 if {[info exists mergefilelist($id)]} {
2253 if {[info exists mergefilelist($id)]} {
2248 if {$mergefilelist($id) ne {}} {
2254 if {$mergefilelist($id) ne {}} {
2249 showmergediff
2255 showmergediff
2250 }
2256 }
2251 } else {
2257 } else {
2252 contmergediff {}
2258 contmergediff {}
2253 }
2259 }
2254 }
2260 }
2255
2261
2256 proc findgca {ids} {
2262 proc findgca {ids} {
2257 global env
2263 global env
2258 set gca {}
2264 set gca {}
2259 foreach id $ids {
2265 foreach id $ids {
2260 if {$gca eq {}} {
2266 if {$gca eq {}} {
2261 set gca $id
2267 set gca $id
2262 } else {
2268 } else {
2263 if {[catch {
2269 if {[catch {
2264 set gca [exec $env(HG) --config ui.report_untrusted=false debug-merge-base $gca $id]
2270 set gca [exec $env(HG) --config ui.report_untrusted=false debug-merge-base $gca $id]
2265 } err]} {
2271 } err]} {
2266 return {}
2272 return {}
2267 }
2273 }
2268 }
2274 }
2269 }
2275 }
2270 return $gca
2276 return $gca
2271 }
2277 }
2272
2278
2273 proc contmergediff {ids} {
2279 proc contmergediff {ids} {
2274 global diffmergeid diffpindex parents nparents diffmergegca
2280 global diffmergeid diffpindex parents nparents diffmergegca
2275 global treediffs mergefilelist diffids treepending
2281 global treediffs mergefilelist diffids treepending
2276
2282
2277 # diff the child against each of the parents, and diff
2283 # diff the child against each of the parents, and diff
2278 # each of the parents against the GCA.
2284 # each of the parents against the GCA.
2279 while 1 {
2285 while 1 {
2280 if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
2286 if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
2281 set ids [list [lindex $ids 1] $diffmergegca]
2287 set ids [list [lindex $ids 1] $diffmergegca]
2282 } else {
2288 } else {
2283 if {[incr diffpindex] >= $nparents($diffmergeid)} break
2289 if {[incr diffpindex] >= $nparents($diffmergeid)} break
2284 set p [lindex $parents($diffmergeid) $diffpindex]
2290 set p [lindex $parents($diffmergeid) $diffpindex]
2285 set ids [list $diffmergeid $p]
2291 set ids [list $diffmergeid $p]
2286 }
2292 }
2287 if {![info exists treediffs($ids)]} {
2293 if {![info exists treediffs($ids)]} {
2288 set diffids $ids
2294 set diffids $ids
2289 if {![info exists treepending]} {
2295 if {![info exists treepending]} {
2290 gettreediffs $ids
2296 gettreediffs $ids
2291 }
2297 }
2292 return
2298 return
2293 }
2299 }
2294 }
2300 }
2295
2301
2296 # If a file in some parent is different from the child and also
2302 # If a file in some parent is different from the child and also
2297 # different from the GCA, then it's interesting.
2303 # different from the GCA, then it's interesting.
2298 # If we don't have a GCA, then a file is interesting if it is
2304 # If we don't have a GCA, then a file is interesting if it is
2299 # different from the child in all the parents.
2305 # different from the child in all the parents.
2300 if {$diffmergegca ne {}} {
2306 if {$diffmergegca ne {}} {
2301 set files {}
2307 set files {}
2302 foreach p $parents($diffmergeid) {
2308 foreach p $parents($diffmergeid) {
2303 set gcadiffs $treediffs([list $p $diffmergegca])
2309 set gcadiffs $treediffs([list $p $diffmergegca])
2304 foreach f $treediffs([list $diffmergeid $p]) {
2310 foreach f $treediffs([list $diffmergeid $p]) {
2305 if {[lsearch -exact $files $f] < 0
2311 if {[lsearch -exact $files $f] < 0
2306 && [lsearch -exact $gcadiffs $f] >= 0} {
2312 && [lsearch -exact $gcadiffs $f] >= 0} {
2307 lappend files $f
2313 lappend files $f
2308 }
2314 }
2309 }
2315 }
2310 }
2316 }
2311 set files [lsort $files]
2317 set files [lsort $files]
2312 } else {
2318 } else {
2313 set p [lindex $parents($diffmergeid) 0]
2319 set p [lindex $parents($diffmergeid) 0]
2314 set files $treediffs([list $diffmergeid $p])
2320 set files $treediffs([list $diffmergeid $p])
2315 for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
2321 for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
2316 set p [lindex $parents($diffmergeid) $i]
2322 set p [lindex $parents($diffmergeid) $i]
2317 set df $treediffs([list $diffmergeid $p])
2323 set df $treediffs([list $diffmergeid $p])
2318 set nf {}
2324 set nf {}
2319 foreach f $files {
2325 foreach f $files {
2320 if {[lsearch -exact $df $f] >= 0} {
2326 if {[lsearch -exact $df $f] >= 0} {
2321 lappend nf $f
2327 lappend nf $f
2322 }
2328 }
2323 }
2329 }
2324 set files $nf
2330 set files $nf
2325 }
2331 }
2326 }
2332 }
2327
2333
2328 set mergefilelist($diffmergeid) $files
2334 set mergefilelist($diffmergeid) $files
2329 if {$files ne {}} {
2335 if {$files ne {}} {
2330 showmergediff
2336 showmergediff
2331 }
2337 }
2332 }
2338 }
2333
2339
2334 proc showmergediff {} {
2340 proc showmergediff {} {
2335 global cflist diffmergeid mergefilelist parents
2341 global cflist diffmergeid mergefilelist parents
2336 global diffopts diffinhunk currentfile currenthunk filelines
2342 global diffopts diffinhunk currentfile currenthunk filelines
2337 global diffblocked groupfilelast mergefds groupfilenum grouphunks
2343 global diffblocked groupfilelast mergefds groupfilenum grouphunks
2338 global env
2344 global env
2339
2345
2340 set files $mergefilelist($diffmergeid)
2346 set files $mergefilelist($diffmergeid)
2341 foreach f $files {
2347 foreach f $files {
2342 $cflist insert end $f
2348 $cflist insert end $f
2343 }
2349 }
2344 set env(GIT_DIFF_OPTS) $diffopts
2350 set env(GIT_DIFF_OPTS) $diffopts
2345 set flist {}
2351 set flist {}
2346 catch {unset currentfile}
2352 catch {unset currentfile}
2347 catch {unset currenthunk}
2353 catch {unset currenthunk}
2348 catch {unset filelines}
2354 catch {unset filelines}
2349 catch {unset groupfilenum}
2355 catch {unset groupfilenum}
2350 catch {unset grouphunks}
2356 catch {unset grouphunks}
2351 set groupfilelast -1
2357 set groupfilelast -1
2352 foreach p $parents($diffmergeid) {
2358 foreach p $parents($diffmergeid) {
2353 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $p $diffmergeid]
2359 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $p $diffmergeid]
2354 set cmd [concat $cmd $mergefilelist($diffmergeid)]
2360 set cmd [concat $cmd $mergefilelist($diffmergeid)]
2355 if {[catch {set f [open $cmd r]} err]} {
2361 if {[catch {set f [open $cmd r]} err]} {
2356 error_popup "Error getting diffs: $err"
2362 error_popup "Error getting diffs: $err"
2357 foreach f $flist {
2363 foreach f $flist {
2358 catch {close $f}
2364 catch {close $f}
2359 }
2365 }
2360 return
2366 return
2361 }
2367 }
2362 lappend flist $f
2368 lappend flist $f
2363 set ids [list $diffmergeid $p]
2369 set ids [list $diffmergeid $p]
2364 set mergefds($ids) $f
2370 set mergefds($ids) $f
2365 set diffinhunk($ids) 0
2371 set diffinhunk($ids) 0
2366 set diffblocked($ids) 0
2372 set diffblocked($ids) 0
2367 fconfigure $f -blocking 0
2373 fconfigure $f -blocking 0
2368 fileevent $f readable [list getmergediffline $f $ids $diffmergeid]
2374 fileevent $f readable [list getmergediffline $f $ids $diffmergeid]
2369 }
2375 }
2370 }
2376 }
2371
2377
2372 proc getmergediffline {f ids id} {
2378 proc getmergediffline {f ids id} {
2373 global diffmergeid diffinhunk diffoldlines diffnewlines
2379 global diffmergeid diffinhunk diffoldlines diffnewlines
2374 global currentfile currenthunk
2380 global currentfile currenthunk
2375 global diffoldstart diffnewstart diffoldlno diffnewlno
2381 global diffoldstart diffnewstart diffoldlno diffnewlno
2376 global diffblocked mergefilelist
2382 global diffblocked mergefilelist
2377 global noldlines nnewlines difflcounts filelines
2383 global noldlines nnewlines difflcounts filelines
2378
2384
2379 set n [gets $f line]
2385 set n [gets $f line]
2380 if {$n < 0} {
2386 if {$n < 0} {
2381 if {![eof $f]} return
2387 if {![eof $f]} return
2382 }
2388 }
2383
2389
2384 if {!([info exists diffmergeid] && $diffmergeid == $id)} {
2390 if {!([info exists diffmergeid] && $diffmergeid == $id)} {
2385 if {$n < 0} {
2391 if {$n < 0} {
2386 close $f
2392 close $f
2387 }
2393 }
2388 return
2394 return
2389 }
2395 }
2390
2396
2391 if {$diffinhunk($ids) != 0} {
2397 if {$diffinhunk($ids) != 0} {
2392 set fi $currentfile($ids)
2398 set fi $currentfile($ids)
2393 if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
2399 if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
2394 # continuing an existing hunk
2400 # continuing an existing hunk
2395 set line [string range $line 1 end]
2401 set line [string range $line 1 end]
2396 set p [lindex $ids 1]
2402 set p [lindex $ids 1]
2397 if {$match eq "-" || $match eq " "} {
2403 if {$match eq "-" || $match eq " "} {
2398 set filelines($p,$fi,$diffoldlno($ids)) $line
2404 set filelines($p,$fi,$diffoldlno($ids)) $line
2399 incr diffoldlno($ids)
2405 incr diffoldlno($ids)
2400 }
2406 }
2401 if {$match eq "+" || $match eq " "} {
2407 if {$match eq "+" || $match eq " "} {
2402 set filelines($id,$fi,$diffnewlno($ids)) $line
2408 set filelines($id,$fi,$diffnewlno($ids)) $line
2403 incr diffnewlno($ids)
2409 incr diffnewlno($ids)
2404 }
2410 }
2405 if {$match eq " "} {
2411 if {$match eq " "} {
2406 if {$diffinhunk($ids) == 2} {
2412 if {$diffinhunk($ids) == 2} {
2407 lappend difflcounts($ids) \
2413 lappend difflcounts($ids) \
2408 [list $noldlines($ids) $nnewlines($ids)]
2414 [list $noldlines($ids) $nnewlines($ids)]
2409 set noldlines($ids) 0
2415 set noldlines($ids) 0
2410 set diffinhunk($ids) 1
2416 set diffinhunk($ids) 1
2411 }
2417 }
2412 incr noldlines($ids)
2418 incr noldlines($ids)
2413 } elseif {$match eq "-" || $match eq "+"} {
2419 } elseif {$match eq "-" || $match eq "+"} {
2414 if {$diffinhunk($ids) == 1} {
2420 if {$diffinhunk($ids) == 1} {
2415 lappend difflcounts($ids) [list $noldlines($ids)]
2421 lappend difflcounts($ids) [list $noldlines($ids)]
2416 set noldlines($ids) 0
2422 set noldlines($ids) 0
2417 set nnewlines($ids) 0
2423 set nnewlines($ids) 0
2418 set diffinhunk($ids) 2
2424 set diffinhunk($ids) 2
2419 }
2425 }
2420 if {$match eq "-"} {
2426 if {$match eq "-"} {
2421 incr noldlines($ids)
2427 incr noldlines($ids)
2422 } else {
2428 } else {
2423 incr nnewlines($ids)
2429 incr nnewlines($ids)
2424 }
2430 }
2425 }
2431 }
2426 # and if it's \ No newline at end of line, then what?
2432 # and if it's \ No newline at end of line, then what?
2427 return
2433 return
2428 }
2434 }
2429 # end of a hunk
2435 # end of a hunk
2430 if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
2436 if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
2431 lappend difflcounts($ids) [list $noldlines($ids)]
2437 lappend difflcounts($ids) [list $noldlines($ids)]
2432 } elseif {$diffinhunk($ids) == 2
2438 } elseif {$diffinhunk($ids) == 2
2433 && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
2439 && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
2434 lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
2440 lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
2435 }
2441 }
2436 set currenthunk($ids) [list $currentfile($ids) \
2442 set currenthunk($ids) [list $currentfile($ids) \
2437 $diffoldstart($ids) $diffnewstart($ids) \
2443 $diffoldstart($ids) $diffnewstart($ids) \
2438 $diffoldlno($ids) $diffnewlno($ids) \
2444 $diffoldlno($ids) $diffnewlno($ids) \
2439 $difflcounts($ids)]
2445 $difflcounts($ids)]
2440 set diffinhunk($ids) 0
2446 set diffinhunk($ids) 0
2441 # -1 = need to block, 0 = unblocked, 1 = is blocked
2447 # -1 = need to block, 0 = unblocked, 1 = is blocked
2442 set diffblocked($ids) -1
2448 set diffblocked($ids) -1
2443 processhunks
2449 processhunks
2444 if {$diffblocked($ids) == -1} {
2450 if {$diffblocked($ids) == -1} {
2445 fileevent $f readable {}
2451 fileevent $f readable {}
2446 set diffblocked($ids) 1
2452 set diffblocked($ids) 1
2447 }
2453 }
2448 }
2454 }
2449
2455
2450 if {$n < 0} {
2456 if {$n < 0} {
2451 # eof
2457 # eof
2452 if {!$diffblocked($ids)} {
2458 if {!$diffblocked($ids)} {
2453 close $f
2459 close $f
2454 set currentfile($ids) [llength $mergefilelist($diffmergeid)]
2460 set currentfile($ids) [llength $mergefilelist($diffmergeid)]
2455 set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
2461 set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
2456 processhunks
2462 processhunks
2457 }
2463 }
2458 } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
2464 } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
2459 # start of a new file
2465 # start of a new file
2460 set currentfile($ids) \
2466 set currentfile($ids) \
2461 [lsearch -exact $mergefilelist($diffmergeid) $fname]
2467 [lsearch -exact $mergefilelist($diffmergeid) $fname]
2462 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2468 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2463 $line match f1l f1c f2l f2c rest]} {
2469 $line match f1l f1c f2l f2c rest]} {
2464 if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
2470 if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
2465 # start of a new hunk
2471 # start of a new hunk
2466 if {$f1l == 0 && $f1c == 0} {
2472 if {$f1l == 0 && $f1c == 0} {
2467 set f1l 1
2473 set f1l 1
2468 }
2474 }
2469 if {$f2l == 0 && $f2c == 0} {
2475 if {$f2l == 0 && $f2c == 0} {
2470 set f2l 1
2476 set f2l 1
2471 }
2477 }
2472 set diffinhunk($ids) 1
2478 set diffinhunk($ids) 1
2473 set diffoldstart($ids) $f1l
2479 set diffoldstart($ids) $f1l
2474 set diffnewstart($ids) $f2l
2480 set diffnewstart($ids) $f2l
2475 set diffoldlno($ids) $f1l
2481 set diffoldlno($ids) $f1l
2476 set diffnewlno($ids) $f2l
2482 set diffnewlno($ids) $f2l
2477 set difflcounts($ids) {}
2483 set difflcounts($ids) {}
2478 set noldlines($ids) 0
2484 set noldlines($ids) 0
2479 set nnewlines($ids) 0
2485 set nnewlines($ids) 0
2480 }
2486 }
2481 }
2487 }
2482 }
2488 }
2483
2489
2484 proc processhunks {} {
2490 proc processhunks {} {
2485 global diffmergeid parents nparents currenthunk
2491 global diffmergeid parents nparents currenthunk
2486 global mergefilelist diffblocked mergefds
2492 global mergefilelist diffblocked mergefds
2487 global grouphunks grouplinestart grouplineend groupfilenum
2493 global grouphunks grouplinestart grouplineend groupfilenum
2488
2494
2489 set nfiles [llength $mergefilelist($diffmergeid)]
2495 set nfiles [llength $mergefilelist($diffmergeid)]
2490 while 1 {
2496 while 1 {
2491 set fi $nfiles
2497 set fi $nfiles
2492 set lno 0
2498 set lno 0
2493 # look for the earliest hunk
2499 # look for the earliest hunk
2494 foreach p $parents($diffmergeid) {
2500 foreach p $parents($diffmergeid) {
2495 set ids [list $diffmergeid $p]
2501 set ids [list $diffmergeid $p]
2496 if {![info exists currenthunk($ids)]} return
2502 if {![info exists currenthunk($ids)]} return
2497 set i [lindex $currenthunk($ids) 0]
2503 set i [lindex $currenthunk($ids) 0]
2498 set l [lindex $currenthunk($ids) 2]
2504 set l [lindex $currenthunk($ids) 2]
2499 if {$i < $fi || ($i == $fi && $l < $lno)} {
2505 if {$i < $fi || ($i == $fi && $l < $lno)} {
2500 set fi $i
2506 set fi $i
2501 set lno $l
2507 set lno $l
2502 set pi $p
2508 set pi $p
2503 }
2509 }
2504 }
2510 }
2505
2511
2506 if {$fi < $nfiles} {
2512 if {$fi < $nfiles} {
2507 set ids [list $diffmergeid $pi]
2513 set ids [list $diffmergeid $pi]
2508 set hunk $currenthunk($ids)
2514 set hunk $currenthunk($ids)
2509 unset currenthunk($ids)
2515 unset currenthunk($ids)
2510 if {$diffblocked($ids) > 0} {
2516 if {$diffblocked($ids) > 0} {
2511 fileevent $mergefds($ids) readable \
2517 fileevent $mergefds($ids) readable \
2512 [list getmergediffline $mergefds($ids) $ids $diffmergeid]
2518 [list getmergediffline $mergefds($ids) $ids $diffmergeid]
2513 }
2519 }
2514 set diffblocked($ids) 0
2520 set diffblocked($ids) 0
2515
2521
2516 if {[info exists groupfilenum] && $groupfilenum == $fi
2522 if {[info exists groupfilenum] && $groupfilenum == $fi
2517 && $lno <= $grouplineend} {
2523 && $lno <= $grouplineend} {
2518 # add this hunk to the pending group
2524 # add this hunk to the pending group
2519 lappend grouphunks($pi) $hunk
2525 lappend grouphunks($pi) $hunk
2520 set endln [lindex $hunk 4]
2526 set endln [lindex $hunk 4]
2521 if {$endln > $grouplineend} {
2527 if {$endln > $grouplineend} {
2522 set grouplineend $endln
2528 set grouplineend $endln
2523 }
2529 }
2524 continue
2530 continue
2525 }
2531 }
2526 }
2532 }
2527
2533
2528 # succeeding stuff doesn't belong in this group, so
2534 # succeeding stuff doesn't belong in this group, so
2529 # process the group now
2535 # process the group now
2530 if {[info exists groupfilenum]} {
2536 if {[info exists groupfilenum]} {
2531 processgroup
2537 processgroup
2532 unset groupfilenum
2538 unset groupfilenum
2533 unset grouphunks
2539 unset grouphunks
2534 }
2540 }
2535
2541
2536 if {$fi >= $nfiles} break
2542 if {$fi >= $nfiles} break
2537
2543
2538 # start a new group
2544 # start a new group
2539 set groupfilenum $fi
2545 set groupfilenum $fi
2540 set grouphunks($pi) [list $hunk]
2546 set grouphunks($pi) [list $hunk]
2541 set grouplinestart $lno
2547 set grouplinestart $lno
2542 set grouplineend [lindex $hunk 4]
2548 set grouplineend [lindex $hunk 4]
2543 }
2549 }
2544 }
2550 }
2545
2551
2546 proc processgroup {} {
2552 proc processgroup {} {
2547 global groupfilelast groupfilenum difffilestart
2553 global groupfilelast groupfilenum difffilestart
2548 global mergefilelist diffmergeid ctext filelines
2554 global mergefilelist diffmergeid ctext filelines
2549 global parents diffmergeid diffoffset
2555 global parents diffmergeid diffoffset
2550 global grouphunks grouplinestart grouplineend nparents
2556 global grouphunks grouplinestart grouplineend nparents
2551 global mergemax
2557 global mergemax
2552
2558
2553 $ctext conf -state normal
2559 $ctext conf -state normal
2554 set id $diffmergeid
2560 set id $diffmergeid
2555 set f $groupfilenum
2561 set f $groupfilenum
2556 if {$groupfilelast != $f} {
2562 if {$groupfilelast != $f} {
2557 $ctext insert end "\n"
2563 $ctext insert end "\n"
2558 set here [$ctext index "end - 1c"]
2564 set here [$ctext index "end - 1c"]
2559 set difffilestart($f) $here
2565 set difffilestart($f) $here
2560 set mark fmark.[expr {$f + 1}]
2566 set mark fmark.[expr {$f + 1}]
2561 $ctext mark set $mark $here
2567 $ctext mark set $mark $here
2562 $ctext mark gravity $mark left
2568 $ctext mark gravity $mark left
2563 set header [lindex $mergefilelist($id) $f]
2569 set header [lindex $mergefilelist($id) $f]
2564 set l [expr {(78 - [string length $header]) / 2}]
2570 set l [expr {(78 - [string length $header]) / 2}]
2565 set pad [string range "----------------------------------------" 1 $l]
2571 set pad [string range "----------------------------------------" 1 $l]
2566 $ctext insert end "$pad $header $pad\n" filesep
2572 $ctext insert end "$pad $header $pad\n" filesep
2567 set groupfilelast $f
2573 set groupfilelast $f
2568 foreach p $parents($id) {
2574 foreach p $parents($id) {
2569 set diffoffset($p) 0
2575 set diffoffset($p) 0
2570 }
2576 }
2571 }
2577 }
2572
2578
2573 $ctext insert end "@@" msep
2579 $ctext insert end "@@" msep
2574 set nlines [expr {$grouplineend - $grouplinestart}]
2580 set nlines [expr {$grouplineend - $grouplinestart}]
2575 set events {}
2581 set events {}
2576 set pnum 0
2582 set pnum 0
2577 foreach p $parents($id) {
2583 foreach p $parents($id) {
2578 set startline [expr {$grouplinestart + $diffoffset($p)}]
2584 set startline [expr {$grouplinestart + $diffoffset($p)}]
2579 set ol $startline
2585 set ol $startline
2580 set nl $grouplinestart
2586 set nl $grouplinestart
2581 if {[info exists grouphunks($p)]} {
2587 if {[info exists grouphunks($p)]} {
2582 foreach h $grouphunks($p) {
2588 foreach h $grouphunks($p) {
2583 set l [lindex $h 2]
2589 set l [lindex $h 2]
2584 if {$nl < $l} {
2590 if {$nl < $l} {
2585 for {} {$nl < $l} {incr nl} {
2591 for {} {$nl < $l} {incr nl} {
2586 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2592 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2587 incr ol
2593 incr ol
2588 }
2594 }
2589 }
2595 }
2590 foreach chunk [lindex $h 5] {
2596 foreach chunk [lindex $h 5] {
2591 if {[llength $chunk] == 2} {
2597 if {[llength $chunk] == 2} {
2592 set olc [lindex $chunk 0]
2598 set olc [lindex $chunk 0]
2593 set nlc [lindex $chunk 1]
2599 set nlc [lindex $chunk 1]
2594 set nnl [expr {$nl + $nlc}]
2600 set nnl [expr {$nl + $nlc}]
2595 lappend events [list $nl $nnl $pnum $olc $nlc]
2601 lappend events [list $nl $nnl $pnum $olc $nlc]
2596 incr ol $olc
2602 incr ol $olc
2597 set nl $nnl
2603 set nl $nnl
2598 } else {
2604 } else {
2599 incr ol [lindex $chunk 0]
2605 incr ol [lindex $chunk 0]
2600 incr nl [lindex $chunk 0]
2606 incr nl [lindex $chunk 0]
2601 }
2607 }
2602 }
2608 }
2603 }
2609 }
2604 }
2610 }
2605 if {$nl < $grouplineend} {
2611 if {$nl < $grouplineend} {
2606 for {} {$nl < $grouplineend} {incr nl} {
2612 for {} {$nl < $grouplineend} {incr nl} {
2607 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2613 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2608 incr ol
2614 incr ol
2609 }
2615 }
2610 }
2616 }
2611 set nlines [expr {$ol - $startline}]
2617 set nlines [expr {$ol - $startline}]
2612 $ctext insert end " -$startline,$nlines" msep
2618 $ctext insert end " -$startline,$nlines" msep
2613 incr pnum
2619 incr pnum
2614 }
2620 }
2615
2621
2616 set nlines [expr {$grouplineend - $grouplinestart}]
2622 set nlines [expr {$grouplineend - $grouplinestart}]
2617 $ctext insert end " +$grouplinestart,$nlines @@\n" msep
2623 $ctext insert end " +$grouplinestart,$nlines @@\n" msep
2618
2624
2619 set events [lsort -integer -index 0 $events]
2625 set events [lsort -integer -index 0 $events]
2620 set nevents [llength $events]
2626 set nevents [llength $events]
2621 set nmerge $nparents($diffmergeid)
2627 set nmerge $nparents($diffmergeid)
2622 set l $grouplinestart
2628 set l $grouplinestart
2623 for {set i 0} {$i < $nevents} {set i $j} {
2629 for {set i 0} {$i < $nevents} {set i $j} {
2624 set nl [lindex $events $i 0]
2630 set nl [lindex $events $i 0]
2625 while {$l < $nl} {
2631 while {$l < $nl} {
2626 $ctext insert end " $filelines($id,$f,$l)\n"
2632 $ctext insert end " $filelines($id,$f,$l)\n"
2627 incr l
2633 incr l
2628 }
2634 }
2629 set e [lindex $events $i]
2635 set e [lindex $events $i]
2630 set enl [lindex $e 1]
2636 set enl [lindex $e 1]
2631 set j $i
2637 set j $i
2632 set active {}
2638 set active {}
2633 while 1 {
2639 while 1 {
2634 set pnum [lindex $e 2]
2640 set pnum [lindex $e 2]
2635 set olc [lindex $e 3]
2641 set olc [lindex $e 3]
2636 set nlc [lindex $e 4]
2642 set nlc [lindex $e 4]
2637 if {![info exists delta($pnum)]} {
2643 if {![info exists delta($pnum)]} {
2638 set delta($pnum) [expr {$olc - $nlc}]
2644 set delta($pnum) [expr {$olc - $nlc}]
2639 lappend active $pnum
2645 lappend active $pnum
2640 } else {
2646 } else {
2641 incr delta($pnum) [expr {$olc - $nlc}]
2647 incr delta($pnum) [expr {$olc - $nlc}]
2642 }
2648 }
2643 if {[incr j] >= $nevents} break
2649 if {[incr j] >= $nevents} break
2644 set e [lindex $events $j]
2650 set e [lindex $events $j]
2645 if {[lindex $e 0] >= $enl} break
2651 if {[lindex $e 0] >= $enl} break
2646 if {[lindex $e 1] > $enl} {
2652 if {[lindex $e 1] > $enl} {
2647 set enl [lindex $e 1]
2653 set enl [lindex $e 1]
2648 }
2654 }
2649 }
2655 }
2650 set nlc [expr {$enl - $l}]
2656 set nlc [expr {$enl - $l}]
2651 set ncol mresult
2657 set ncol mresult
2652 set bestpn -1
2658 set bestpn -1
2653 if {[llength $active] == $nmerge - 1} {
2659 if {[llength $active] == $nmerge - 1} {
2654 # no diff for one of the parents, i.e. it's identical
2660 # no diff for one of the parents, i.e. it's identical
2655 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
2661 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
2656 if {![info exists delta($pnum)]} {
2662 if {![info exists delta($pnum)]} {
2657 if {$pnum < $mergemax} {
2663 if {$pnum < $mergemax} {
2658 lappend ncol m$pnum
2664 lappend ncol m$pnum
2659 } else {
2665 } else {
2660 lappend ncol mmax
2666 lappend ncol mmax
2661 }
2667 }
2662 break
2668 break
2663 }
2669 }
2664 }
2670 }
2665 } elseif {[llength $active] == $nmerge} {
2671 } elseif {[llength $active] == $nmerge} {
2666 # all parents are different, see if one is very similar
2672 # all parents are different, see if one is very similar
2667 set bestsim 30
2673 set bestsim 30
2668 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
2674 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
2669 set sim [similarity $pnum $l $nlc $f \
2675 set sim [similarity $pnum $l $nlc $f \
2670 [lrange $events $i [expr {$j-1}]]]
2676 [lrange $events $i [expr {$j-1}]]]
2671 if {$sim > $bestsim} {
2677 if {$sim > $bestsim} {
2672 set bestsim $sim
2678 set bestsim $sim
2673 set bestpn $pnum
2679 set bestpn $pnum
2674 }
2680 }
2675 }
2681 }
2676 if {$bestpn >= 0} {
2682 if {$bestpn >= 0} {
2677 lappend ncol m$bestpn
2683 lappend ncol m$bestpn
2678 }
2684 }
2679 }
2685 }
2680 set pnum -1
2686 set pnum -1
2681 foreach p $parents($id) {
2687 foreach p $parents($id) {
2682 incr pnum
2688 incr pnum
2683 if {![info exists delta($pnum)] || $pnum == $bestpn} continue
2689 if {![info exists delta($pnum)] || $pnum == $bestpn} continue
2684 set olc [expr {$nlc + $delta($pnum)}]
2690 set olc [expr {$nlc + $delta($pnum)}]
2685 set ol [expr {$l + $diffoffset($p)}]
2691 set ol [expr {$l + $diffoffset($p)}]
2686 incr diffoffset($p) $delta($pnum)
2692 incr diffoffset($p) $delta($pnum)
2687 unset delta($pnum)
2693 unset delta($pnum)
2688 for {} {$olc > 0} {incr olc -1} {
2694 for {} {$olc > 0} {incr olc -1} {
2689 $ctext insert end "-$filelines($p,$f,$ol)\n" m$pnum
2695 $ctext insert end "-$filelines($p,$f,$ol)\n" m$pnum
2690 incr ol
2696 incr ol
2691 }
2697 }
2692 }
2698 }
2693 set endl [expr {$l + $nlc}]
2699 set endl [expr {$l + $nlc}]
2694 if {$bestpn >= 0} {
2700 if {$bestpn >= 0} {
2695 # show this pretty much as a normal diff
2701 # show this pretty much as a normal diff
2696 set p [lindex $parents($id) $bestpn]
2702 set p [lindex $parents($id) $bestpn]
2697 set ol [expr {$l + $diffoffset($p)}]
2703 set ol [expr {$l + $diffoffset($p)}]
2698 incr diffoffset($p) $delta($bestpn)
2704 incr diffoffset($p) $delta($bestpn)
2699 unset delta($bestpn)
2705 unset delta($bestpn)
2700 for {set k $i} {$k < $j} {incr k} {
2706 for {set k $i} {$k < $j} {incr k} {
2701 set e [lindex $events $k]
2707 set e [lindex $events $k]
2702 if {[lindex $e 2] != $bestpn} continue
2708 if {[lindex $e 2] != $bestpn} continue
2703 set nl [lindex $e 0]
2709 set nl [lindex $e 0]
2704 set ol [expr {$ol + $nl - $l}]
2710 set ol [expr {$ol + $nl - $l}]
2705 for {} {$l < $nl} {incr l} {
2711 for {} {$l < $nl} {incr l} {
2706 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2712 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2707 }
2713 }
2708 set c [lindex $e 3]
2714 set c [lindex $e 3]
2709 for {} {$c > 0} {incr c -1} {
2715 for {} {$c > 0} {incr c -1} {
2710 $ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
2716 $ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
2711 incr ol
2717 incr ol
2712 }
2718 }
2713 set nl [lindex $e 1]
2719 set nl [lindex $e 1]
2714 for {} {$l < $nl} {incr l} {
2720 for {} {$l < $nl} {incr l} {
2715 $ctext insert end "+$filelines($id,$f,$l)\n" mresult
2721 $ctext insert end "+$filelines($id,$f,$l)\n" mresult
2716 }
2722 }
2717 }
2723 }
2718 }
2724 }
2719 for {} {$l < $endl} {incr l} {
2725 for {} {$l < $endl} {incr l} {
2720 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2726 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
2721 }
2727 }
2722 }
2728 }
2723 while {$l < $grouplineend} {
2729 while {$l < $grouplineend} {
2724 $ctext insert end " $filelines($id,$f,$l)\n"
2730 $ctext insert end " $filelines($id,$f,$l)\n"
2725 incr l
2731 incr l
2726 }
2732 }
2727 $ctext conf -state disabled
2733 $ctext conf -state disabled
2728 }
2734 }
2729
2735
2730 proc similarity {pnum l nlc f events} {
2736 proc similarity {pnum l nlc f events} {
2731 global diffmergeid parents diffoffset filelines
2737 global diffmergeid parents diffoffset filelines
2732
2738
2733 set id $diffmergeid
2739 set id $diffmergeid
2734 set p [lindex $parents($id) $pnum]
2740 set p [lindex $parents($id) $pnum]
2735 set ol [expr {$l + $diffoffset($p)}]
2741 set ol [expr {$l + $diffoffset($p)}]
2736 set endl [expr {$l + $nlc}]
2742 set endl [expr {$l + $nlc}]
2737 set same 0
2743 set same 0
2738 set diff 0
2744 set diff 0
2739 foreach e $events {
2745 foreach e $events {
2740 if {[lindex $e 2] != $pnum} continue
2746 if {[lindex $e 2] != $pnum} continue
2741 set nl [lindex $e 0]
2747 set nl [lindex $e 0]
2742 set ol [expr {$ol + $nl - $l}]
2748 set ol [expr {$ol + $nl - $l}]
2743 for {} {$l < $nl} {incr l} {
2749 for {} {$l < $nl} {incr l} {
2744 incr same [string length $filelines($id,$f,$l)]
2750 incr same [string length $filelines($id,$f,$l)]
2745 incr same
2751 incr same
2746 }
2752 }
2747 set oc [lindex $e 3]
2753 set oc [lindex $e 3]
2748 for {} {$oc > 0} {incr oc -1} {
2754 for {} {$oc > 0} {incr oc -1} {
2749 incr diff [string length $filelines($p,$f,$ol)]
2755 incr diff [string length $filelines($p,$f,$ol)]
2750 incr diff
2756 incr diff
2751 incr ol
2757 incr ol
2752 }
2758 }
2753 set nl [lindex $e 1]
2759 set nl [lindex $e 1]
2754 for {} {$l < $nl} {incr l} {
2760 for {} {$l < $nl} {incr l} {
2755 incr diff [string length $filelines($id,$f,$l)]
2761 incr diff [string length $filelines($id,$f,$l)]
2756 incr diff
2762 incr diff
2757 }
2763 }
2758 }
2764 }
2759 for {} {$l < $endl} {incr l} {
2765 for {} {$l < $endl} {incr l} {
2760 incr same [string length $filelines($id,$f,$l)]
2766 incr same [string length $filelines($id,$f,$l)]
2761 incr same
2767 incr same
2762 }
2768 }
2763 if {$same == 0} {
2769 if {$same == 0} {
2764 return 0
2770 return 0
2765 }
2771 }
2766 return [expr {200 * $same / (2 * $same + $diff)}]
2772 return [expr {200 * $same / (2 * $same + $diff)}]
2767 }
2773 }
2768
2774
2769 proc startdiff {ids} {
2775 proc startdiff {ids} {
2770 global treediffs diffids treepending diffmergeid
2776 global treediffs diffids treepending diffmergeid
2771
2777
2772 set diffids $ids
2778 set diffids $ids
2773 catch {unset diffmergeid}
2779 catch {unset diffmergeid}
2774 if {![info exists treediffs($ids)]} {
2780 if {![info exists treediffs($ids)]} {
2775 if {![info exists treepending]} {
2781 if {![info exists treepending]} {
2776 gettreediffs $ids
2782 gettreediffs $ids
2777 }
2783 }
2778 } else {
2784 } else {
2779 addtocflist $ids
2785 addtocflist $ids
2780 }
2786 }
2781 }
2787 }
2782
2788
2783 proc addtocflist {ids} {
2789 proc addtocflist {ids} {
2784 global treediffs cflist
2790 global treediffs cflist
2785 foreach f $treediffs($ids) {
2791 foreach f $treediffs($ids) {
2786 $cflist insert end $f
2792 $cflist insert end $f
2787 }
2793 }
2788 getblobdiffs $ids
2794 getblobdiffs $ids
2789 }
2795 }
2790
2796
2791 proc gettreediffs {ids} {
2797 proc gettreediffs {ids} {
2792 global treediff parents treepending env
2798 global treediff parents treepending env
2793 set treepending $ids
2799 set treepending $ids
2794 set treediff {}
2800 set treediff {}
2795 set id [lindex $ids 0]
2801 set id [lindex $ids 0]
2796 set p [lindex $ids 1]
2802 set p [lindex $ids 1]
2797 if [catch {set gdtf [open "|{$env(HG)} --config ui.report_untrusted=false debug-diff-tree -r $p $id" r]}] return
2803 if [catch {set gdtf [open "|{$env(HG)} --config ui.report_untrusted=false debug-diff-tree -r $p $id" r]}] return
2798 fconfigure $gdtf -blocking 0
2804 fconfigure $gdtf -blocking 0
2799 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
2805 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
2800 }
2806 }
2801
2807
2802 proc gettreediffline {gdtf ids} {
2808 proc gettreediffline {gdtf ids} {
2803 global treediff treediffs treepending diffids diffmergeid
2809 global treediff treediffs treepending diffids diffmergeid
2804
2810
2805 set n [gets $gdtf line]
2811 set n [gets $gdtf line]
2806 if {$n < 0} {
2812 if {$n < 0} {
2807 if {![eof $gdtf]} return
2813 if {![eof $gdtf]} return
2808 close $gdtf
2814 close $gdtf
2809 set treediffs($ids) $treediff
2815 set treediffs($ids) $treediff
2810 unset treepending
2816 unset treepending
2811 if {$ids != $diffids} {
2817 if {$ids != $diffids} {
2812 gettreediffs $diffids
2818 gettreediffs $diffids
2813 } else {
2819 } else {
2814 if {[info exists diffmergeid]} {
2820 if {[info exists diffmergeid]} {
2815 contmergediff $ids
2821 contmergediff $ids
2816 } else {
2822 } else {
2817 addtocflist $ids
2823 addtocflist $ids
2818 }
2824 }
2819 }
2825 }
2820 return
2826 return
2821 }
2827 }
2822 set tab1 [expr [string first "\t" $line] + 1]
2828 set tab1 [expr [string first "\t" $line] + 1]
2823 set tab2 [expr [string first "\t" $line $tab1] - 1]
2829 set tab2 [expr [string first "\t" $line $tab1] - 1]
2824 set file [string range $line $tab1 $tab2]
2830 set file [string range $line $tab1 $tab2]
2825 lappend treediff $file
2831 lappend treediff $file
2826 }
2832 }
2827
2833
2828 proc getblobdiffs {ids} {
2834 proc getblobdiffs {ids} {
2829 global diffopts blobdifffd diffids env curdifftag curtagstart
2835 global diffopts blobdifffd diffids env curdifftag curtagstart
2830 global difffilestart nextupdate diffinhdr treediffs
2836 global difffilestart nextupdate diffinhdr treediffs
2831
2837
2832 set id [lindex $ids 0]
2838 set id [lindex $ids 0]
2833 set p [lindex $ids 1]
2839 set p [lindex $ids 1]
2834 set env(GIT_DIFF_OPTS) $diffopts
2840 set env(GIT_DIFF_OPTS) $diffopts
2835 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r -p -C $p $id]
2841 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r -p -C $p $id]
2836 if {[catch {set bdf [open $cmd r]} err]} {
2842 if {[catch {set bdf [open $cmd r]} err]} {
2837 puts "error getting diffs: $err"
2843 puts "error getting diffs: $err"
2838 return
2844 return
2839 }
2845 }
2840 set diffinhdr 0
2846 set diffinhdr 0
2841 fconfigure $bdf -blocking 0
2847 fconfigure $bdf -blocking 0
2842 set blobdifffd($ids) $bdf
2848 set blobdifffd($ids) $bdf
2843 set curdifftag Comments
2849 set curdifftag Comments
2844 set curtagstart 0.0
2850 set curtagstart 0.0
2845 catch {unset difffilestart}
2851 catch {unset difffilestart}
2846 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
2852 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
2847 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2853 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2848 }
2854 }
2849
2855
2850 proc getblobdiffline {bdf ids} {
2856 proc getblobdiffline {bdf ids} {
2851 global diffids blobdifffd ctext curdifftag curtagstart
2857 global diffids blobdifffd ctext curdifftag curtagstart
2852 global diffnexthead diffnextnote difffilestart
2858 global diffnexthead diffnextnote difffilestart
2853 global nextupdate diffinhdr treediffs
2859 global nextupdate diffinhdr treediffs
2854 global gaudydiff
2860 global gaudydiff
2855
2861
2856 set n [gets $bdf line]
2862 set n [gets $bdf line]
2857 if {$n < 0} {
2863 if {$n < 0} {
2858 if {[eof $bdf]} {
2864 if {[eof $bdf]} {
2859 close $bdf
2865 close $bdf
2860 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
2866 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
2861 $ctext tag add $curdifftag $curtagstart end
2867 $ctext tag add $curdifftag $curtagstart end
2862 }
2868 }
2863 }
2869 }
2864 return
2870 return
2865 }
2871 }
2866 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
2872 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
2867 return
2873 return
2868 }
2874 }
2869 regsub -all "\r" $line "" line
2875 regsub -all "\r" $line "" line
2870 $ctext conf -state normal
2876 $ctext conf -state normal
2871 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
2877 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
2872 # start of a new file
2878 # start of a new file
2873 $ctext insert end "\n"
2879 $ctext insert end "\n"
2874 $ctext tag add $curdifftag $curtagstart end
2880 $ctext tag add $curdifftag $curtagstart end
2875 set curtagstart [$ctext index "end - 1c"]
2881 set curtagstart [$ctext index "end - 1c"]
2876 set header $newname
2882 set header $newname
2877 set here [$ctext index "end - 1c"]
2883 set here [$ctext index "end - 1c"]
2878 set i [lsearch -exact $treediffs($diffids) $fname]
2884 set i [lsearch -exact $treediffs($diffids) $fname]
2879 if {$i >= 0} {
2885 if {$i >= 0} {
2880 set difffilestart($i) $here
2886 set difffilestart($i) $here
2881 incr i
2887 incr i
2882 $ctext mark set fmark.$i $here
2888 $ctext mark set fmark.$i $here
2883 $ctext mark gravity fmark.$i left
2889 $ctext mark gravity fmark.$i left
2884 }
2890 }
2885 if {$newname != $fname} {
2891 if {$newname != $fname} {
2886 set i [lsearch -exact $treediffs($diffids) $newname]
2892 set i [lsearch -exact $treediffs($diffids) $newname]
2887 if {$i >= 0} {
2893 if {$i >= 0} {
2888 set difffilestart($i) $here
2894 set difffilestart($i) $here
2889 incr i
2895 incr i
2890 $ctext mark set fmark.$i $here
2896 $ctext mark set fmark.$i $here
2891 $ctext mark gravity fmark.$i left
2897 $ctext mark gravity fmark.$i left
2892 }
2898 }
2893 }
2899 }
2894 set curdifftag "f:$fname"
2900 set curdifftag "f:$fname"
2895 $ctext tag delete $curdifftag
2901 $ctext tag delete $curdifftag
2896 set l [expr {(78 - [string length $header]) / 2}]
2902 set l [expr {(78 - [string length $header]) / 2}]
2897 set pad [string range "----------------------------------------" 1 $l]
2903 set pad [string range "----------------------------------------" 1 $l]
2898 $ctext insert end "$pad $header $pad\n" filesep
2904 $ctext insert end "$pad $header $pad\n" filesep
2899 set diffinhdr 1
2905 set diffinhdr 1
2900 } elseif {[regexp {^(---|\+\+\+)} $line]} {
2906 } elseif {[regexp {^(---|\+\+\+)} $line]} {
2901 set diffinhdr 0
2907 set diffinhdr 0
2902 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2908 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2903 $line match f1l f1c f2l f2c rest]} {
2909 $line match f1l f1c f2l f2c rest]} {
2904 if {$gaudydiff} {
2910 if {$gaudydiff} {
2905 $ctext insert end "\t" hunksep
2911 $ctext insert end "\t" hunksep
2906 $ctext insert end " $f1l " d0 " $f2l " d1
2912 $ctext insert end " $f1l " d0 " $f2l " d1
2907 $ctext insert end " $rest \n" hunksep
2913 $ctext insert end " $rest \n" hunksep
2908 } else {
2914 } else {
2909 $ctext insert end "$line\n" hunksep
2915 $ctext insert end "$line\n" hunksep
2910 }
2916 }
2911 set diffinhdr 0
2917 set diffinhdr 0
2912 } else {
2918 } else {
2913 set x [string range $line 0 0]
2919 set x [string range $line 0 0]
2914 if {$x == "-" || $x == "+"} {
2920 if {$x == "-" || $x == "+"} {
2915 set tag [expr {$x == "+"}]
2921 set tag [expr {$x == "+"}]
2916 if {$gaudydiff} {
2922 if {$gaudydiff} {
2917 set line [string range $line 1 end]
2923 set line [string range $line 1 end]
2918 }
2924 }
2919 $ctext insert end "$line\n" d$tag
2925 $ctext insert end "$line\n" d$tag
2920 } elseif {$x == " "} {
2926 } elseif {$x == " "} {
2921 if {$gaudydiff} {
2927 if {$gaudydiff} {
2922 set line [string range $line 1 end]
2928 set line [string range $line 1 end]
2923 }
2929 }
2924 $ctext insert end "$line\n"
2930 $ctext insert end "$line\n"
2925 } elseif {$diffinhdr || $x == "\\"} {
2931 } elseif {$diffinhdr || $x == "\\"} {
2926 # e.g. "\ No newline at end of file"
2932 # e.g. "\ No newline at end of file"
2927 $ctext insert end "$line\n" filesep
2933 $ctext insert end "$line\n" filesep
2928 } elseif {$line != ""} {
2934 } elseif {$line != ""} {
2929 # Something else we don't recognize
2935 # Something else we don't recognize
2930 if {$curdifftag != "Comments"} {
2936 if {$curdifftag != "Comments"} {
2931 $ctext insert end "\n"
2937 $ctext insert end "\n"
2932 $ctext tag add $curdifftag $curtagstart end
2938 $ctext tag add $curdifftag $curtagstart end
2933 set curtagstart [$ctext index "end - 1c"]
2939 set curtagstart [$ctext index "end - 1c"]
2934 set curdifftag Comments
2940 set curdifftag Comments
2935 }
2941 }
2936 $ctext insert end "$line\n" filesep
2942 $ctext insert end "$line\n" filesep
2937 }
2943 }
2938 }
2944 }
2939 $ctext conf -state disabled
2945 $ctext conf -state disabled
2940 if {[clock clicks -milliseconds] >= $nextupdate} {
2946 if {[clock clicks -milliseconds] >= $nextupdate} {
2941 incr nextupdate 100
2947 incr nextupdate 100
2942 fileevent $bdf readable {}
2948 fileevent $bdf readable {}
2943 update
2949 update
2944 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
2950 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
2945 }
2951 }
2946 }
2952 }
2947
2953
2948 proc nextfile {} {
2954 proc nextfile {} {
2949 global difffilestart ctext
2955 global difffilestart ctext
2950 set here [$ctext index @0,0]
2956 set here [$ctext index @0,0]
2951 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
2957 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
2952 if {[$ctext compare $difffilestart($i) > $here]} {
2958 if {[$ctext compare $difffilestart($i) > $here]} {
2953 if {![info exists pos]
2959 if {![info exists pos]
2954 || [$ctext compare $difffilestart($i) < $pos]} {
2960 || [$ctext compare $difffilestart($i) < $pos]} {
2955 set pos $difffilestart($i)
2961 set pos $difffilestart($i)
2956 }
2962 }
2957 }
2963 }
2958 }
2964 }
2959 if {[info exists pos]} {
2965 if {[info exists pos]} {
2960 $ctext yview $pos
2966 $ctext yview $pos
2961 }
2967 }
2962 }
2968 }
2963
2969
2964 proc listboxsel {} {
2970 proc listboxsel {} {
2965 global ctext cflist currentid
2971 global ctext cflist currentid
2966 if {![info exists currentid]} return
2972 if {![info exists currentid]} return
2967 set sel [lsort [$cflist curselection]]
2973 set sel [lsort [$cflist curselection]]
2968 if {$sel eq {}} return
2974 if {$sel eq {}} return
2969 set first [lindex $sel 0]
2975 set first [lindex $sel 0]
2970 catch {$ctext yview fmark.$first}
2976 catch {$ctext yview fmark.$first}
2971 }
2977 }
2972
2978
2973 proc setcoords {} {
2979 proc setcoords {} {
2974 global linespc charspc canvx0 canvy0 mainfont
2980 global linespc charspc canvx0 canvy0 mainfont
2975 global xspc1 xspc2 lthickness
2981 global xspc1 xspc2 lthickness
2976
2982
2977 set linespc [font metrics $mainfont -linespace]
2983 set linespc [font metrics $mainfont -linespace]
2978 set charspc [font measure $mainfont "m"]
2984 set charspc [font measure $mainfont "m"]
2979 set canvy0 [expr 3 + 0.5 * $linespc]
2985 set canvy0 [expr 3 + 0.5 * $linespc]
2980 set canvx0 [expr 3 + 0.5 * $linespc]
2986 set canvx0 [expr 3 + 0.5 * $linespc]
2981 set lthickness [expr {int($linespc / 9) + 1}]
2987 set lthickness [expr {int($linespc / 9) + 1}]
2982 set xspc1(0) $linespc
2988 set xspc1(0) $linespc
2983 set xspc2 $linespc
2989 set xspc2 $linespc
2984 }
2990 }
2985
2991
2986 proc redisplay {} {
2992 proc redisplay {} {
2987 global stopped redisplaying phase
2993 global stopped redisplaying phase
2988 if {$stopped > 1} return
2994 if {$stopped > 1} return
2989 if {$phase == "getcommits"} return
2995 if {$phase == "getcommits"} return
2990 set redisplaying 1
2996 set redisplaying 1
2991 if {$phase == "drawgraph" || $phase == "incrdraw"} {
2997 if {$phase == "drawgraph" || $phase == "incrdraw"} {
2992 set stopped 1
2998 set stopped 1
2993 } else {
2999 } else {
2994 drawgraph
3000 drawgraph
2995 }
3001 }
2996 }
3002 }
2997
3003
2998 proc incrfont {inc} {
3004 proc incrfont {inc} {
2999 global mainfont namefont textfont ctext canv phase
3005 global mainfont namefont textfont ctext canv phase
3000 global stopped entries
3006 global stopped entries
3001 unmarkmatches
3007 unmarkmatches
3002 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3008 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3003 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3009 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3004 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3010 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3005 setcoords
3011 setcoords
3006 $ctext conf -font $textfont
3012 $ctext conf -font $textfont
3007 $ctext tag conf filesep -font [concat $textfont bold]
3013 $ctext tag conf filesep -font [concat $textfont bold]
3008 foreach e $entries {
3014 foreach e $entries {
3009 $e conf -font $mainfont
3015 $e conf -font $mainfont
3010 }
3016 }
3011 if {$phase == "getcommits"} {
3017 if {$phase == "getcommits"} {
3012 $canv itemconf textitems -font $mainfont
3018 $canv itemconf textitems -font $mainfont
3013 }
3019 }
3014 redisplay
3020 redisplay
3015 }
3021 }
3016
3022
3017 proc clearsha1 {} {
3023 proc clearsha1 {} {
3018 global sha1entry sha1string
3024 global sha1entry sha1string
3019 if {[string length $sha1string] == 40} {
3025 if {[string length $sha1string] == 40} {
3020 $sha1entry delete 0 end
3026 $sha1entry delete 0 end
3021 }
3027 }
3022 }
3028 }
3023
3029
3024 proc sha1change {n1 n2 op} {
3030 proc sha1change {n1 n2 op} {
3025 global sha1string currentid sha1but
3031 global sha1string currentid sha1but
3026 if {$sha1string == {}
3032 if {$sha1string == {}
3027 || ([info exists currentid] && $sha1string == $currentid)} {
3033 || ([info exists currentid] && $sha1string == $currentid)} {
3028 set state disabled
3034 set state disabled
3029 } else {
3035 } else {
3030 set state normal
3036 set state normal
3031 }
3037 }
3032 if {[$sha1but cget -state] == $state} return
3038 if {[$sha1but cget -state] == $state} return
3033 if {$state == "normal"} {
3039 if {$state == "normal"} {
3034 $sha1but conf -state normal -relief raised -text "Goto: "
3040 $sha1but conf -state normal -relief raised -text "Goto: "
3035 } else {
3041 } else {
3036 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3042 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3037 }
3043 }
3038 }
3044 }
3039
3045
3040 proc gotocommit {} {
3046 proc gotocommit {} {
3041 global sha1string currentid idline tagids
3047 global sha1string currentid idline tagids
3042 global lineid numcommits
3048 global lineid numcommits
3043
3049
3044 if {$sha1string == {}
3050 if {$sha1string == {}
3045 || ([info exists currentid] && $sha1string == $currentid)} return
3051 || ([info exists currentid] && $sha1string == $currentid)} return
3046 if {[info exists tagids($sha1string)]} {
3052 if {[info exists tagids($sha1string)]} {
3047 set id $tagids($sha1string)
3053 set id $tagids($sha1string)
3048 } else {
3054 } else {
3049 set id [string tolower $sha1string]
3055 set id [string tolower $sha1string]
3050 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3056 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3051 set matches {}
3057 set matches {}
3052 for {set l 0} {$l < $numcommits} {incr l} {
3058 for {set l 0} {$l < $numcommits} {incr l} {
3053 if {[string match $id* $lineid($l)]} {
3059 if {[string match $id* $lineid($l)]} {
3054 lappend matches $lineid($l)
3060 lappend matches $lineid($l)
3055 }
3061 }
3056 }
3062 }
3057 if {$matches ne {}} {
3063 if {$matches ne {}} {
3058 if {[llength $matches] > 1} {
3064 if {[llength $matches] > 1} {
3059 error_popup "Short SHA1 id $id is ambiguous"
3065 error_popup "Short SHA1 id $id is ambiguous"
3060 return
3066 return
3061 }
3067 }
3062 set id [lindex $matches 0]
3068 set id [lindex $matches 0]
3063 }
3069 }
3064 }
3070 }
3065 }
3071 }
3066 if {[info exists idline($id)]} {
3072 if {[info exists idline($id)]} {
3067 selectline $idline($id) 1
3073 selectline $idline($id) 1
3068 return
3074 return
3069 }
3075 }
3070 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3076 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3071 set type "SHA1 id"
3077 set type "SHA1 id"
3072 } else {
3078 } else {
3073 set type "Tag"
3079 set type "Tag"
3074 }
3080 }
3075 error_popup "$type $sha1string is not known"
3081 error_popup "$type $sha1string is not known"
3076 }
3082 }
3077
3083
3078 proc lineenter {x y id} {
3084 proc lineenter {x y id} {
3079 global hoverx hovery hoverid hovertimer
3085 global hoverx hovery hoverid hovertimer
3080 global commitinfo canv
3086 global commitinfo canv
3081
3087
3082 if {![info exists commitinfo($id)]} return
3088 if {![info exists commitinfo($id)]} return
3083 set hoverx $x
3089 set hoverx $x
3084 set hovery $y
3090 set hovery $y
3085 set hoverid $id
3091 set hoverid $id
3086 if {[info exists hovertimer]} {
3092 if {[info exists hovertimer]} {
3087 after cancel $hovertimer
3093 after cancel $hovertimer
3088 }
3094 }
3089 set hovertimer [after 500 linehover]
3095 set hovertimer [after 500 linehover]
3090 $canv delete hover
3096 $canv delete hover
3091 }
3097 }
3092
3098
3093 proc linemotion {x y id} {
3099 proc linemotion {x y id} {
3094 global hoverx hovery hoverid hovertimer
3100 global hoverx hovery hoverid hovertimer
3095
3101
3096 if {[info exists hoverid] && $id == $hoverid} {
3102 if {[info exists hoverid] && $id == $hoverid} {
3097 set hoverx $x
3103 set hoverx $x
3098 set hovery $y
3104 set hovery $y
3099 if {[info exists hovertimer]} {
3105 if {[info exists hovertimer]} {
3100 after cancel $hovertimer
3106 after cancel $hovertimer
3101 }
3107 }
3102 set hovertimer [after 500 linehover]
3108 set hovertimer [after 500 linehover]
3103 }
3109 }
3104 }
3110 }
3105
3111
3106 proc lineleave {id} {
3112 proc lineleave {id} {
3107 global hoverid hovertimer canv
3113 global hoverid hovertimer canv
3108
3114
3109 if {[info exists hoverid] && $id == $hoverid} {
3115 if {[info exists hoverid] && $id == $hoverid} {
3110 $canv delete hover
3116 $canv delete hover
3111 if {[info exists hovertimer]} {
3117 if {[info exists hovertimer]} {
3112 after cancel $hovertimer
3118 after cancel $hovertimer
3113 unset hovertimer
3119 unset hovertimer
3114 }
3120 }
3115 unset hoverid
3121 unset hoverid
3116 }
3122 }
3117 }
3123 }
3118
3124
3119 proc linehover {} {
3125 proc linehover {} {
3120 global hoverx hovery hoverid hovertimer
3126 global hoverx hovery hoverid hovertimer
3121 global canv linespc lthickness
3127 global canv linespc lthickness
3122 global commitinfo mainfont
3128 global commitinfo mainfont
3123
3129
3124 set text [lindex $commitinfo($hoverid) 0]
3130 set text [lindex $commitinfo($hoverid) 0]
3125 set ymax [lindex [$canv cget -scrollregion] 3]
3131 set ymax [lindex [$canv cget -scrollregion] 3]
3126 if {$ymax == {}} return
3132 if {$ymax == {}} return
3127 set yfrac [lindex [$canv yview] 0]
3133 set yfrac [lindex [$canv yview] 0]
3128 set x [expr {$hoverx + 2 * $linespc}]
3134 set x [expr {$hoverx + 2 * $linespc}]
3129 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3135 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3130 set x0 [expr {$x - 2 * $lthickness}]
3136 set x0 [expr {$x - 2 * $lthickness}]
3131 set y0 [expr {$y - 2 * $lthickness}]
3137 set y0 [expr {$y - 2 * $lthickness}]
3132 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3138 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3133 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3139 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3134 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3140 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3135 -fill \#ffff80 -outline black -width 1 -tags hover]
3141 -fill \#ffff80 -outline black -width 1 -tags hover]
3136 $canv raise $t
3142 $canv raise $t
3137 set t [$canv create text $x $y -anchor nw -text $text -tags hover]
3143 set t [$canv create text $x $y -anchor nw -text $text -tags hover]
3138 $canv raise $t
3144 $canv raise $t
3139 }
3145 }
3140
3146
3141 proc clickisonarrow {id y} {
3147 proc clickisonarrow {id y} {
3142 global mainline mainlinearrow sidelines lthickness
3148 global mainline mainlinearrow sidelines lthickness
3143
3149
3144 set thresh [expr {2 * $lthickness + 6}]
3150 set thresh [expr {2 * $lthickness + 6}]
3145 if {[info exists mainline($id)]} {
3151 if {[info exists mainline($id)]} {
3146 if {$mainlinearrow($id) ne "none"} {
3152 if {$mainlinearrow($id) ne "none"} {
3147 if {abs([lindex $mainline($id) 1] - $y) < $thresh} {
3153 if {abs([lindex $mainline($id) 1] - $y) < $thresh} {
3148 return "up"
3154 return "up"
3149 }
3155 }
3150 }
3156 }
3151 }
3157 }
3152 if {[info exists sidelines($id)]} {
3158 if {[info exists sidelines($id)]} {
3153 foreach ls $sidelines($id) {
3159 foreach ls $sidelines($id) {
3154 set coords [lindex $ls 0]
3160 set coords [lindex $ls 0]
3155 set arrow [lindex $ls 2]
3161 set arrow [lindex $ls 2]
3156 if {$arrow eq "first" || $arrow eq "both"} {
3162 if {$arrow eq "first" || $arrow eq "both"} {
3157 if {abs([lindex $coords 1] - $y) < $thresh} {
3163 if {abs([lindex $coords 1] - $y) < $thresh} {
3158 return "up"
3164 return "up"
3159 }
3165 }
3160 }
3166 }
3161 if {$arrow eq "last" || $arrow eq "both"} {
3167 if {$arrow eq "last" || $arrow eq "both"} {
3162 if {abs([lindex $coords end] - $y) < $thresh} {
3168 if {abs([lindex $coords end] - $y) < $thresh} {
3163 return "down"
3169 return "down"
3164 }
3170 }
3165 }
3171 }
3166 }
3172 }
3167 }
3173 }
3168 return {}
3174 return {}
3169 }
3175 }
3170
3176
3171 proc arrowjump {id dirn y} {
3177 proc arrowjump {id dirn y} {
3172 global mainline sidelines canv
3178 global mainline sidelines canv
3173
3179
3174 set yt {}
3180 set yt {}
3175 if {$dirn eq "down"} {
3181 if {$dirn eq "down"} {
3176 if {[info exists mainline($id)]} {
3182 if {[info exists mainline($id)]} {
3177 set y1 [lindex $mainline($id) 1]
3183 set y1 [lindex $mainline($id) 1]
3178 if {$y1 > $y} {
3184 if {$y1 > $y} {
3179 set yt $y1
3185 set yt $y1
3180 }
3186 }
3181 }
3187 }
3182 if {[info exists sidelines($id)]} {
3188 if {[info exists sidelines($id)]} {
3183 foreach ls $sidelines($id) {
3189 foreach ls $sidelines($id) {
3184 set y1 [lindex $ls 0 1]
3190 set y1 [lindex $ls 0 1]
3185 if {$y1 > $y && ($yt eq {} || $y1 < $yt)} {
3191 if {$y1 > $y && ($yt eq {} || $y1 < $yt)} {
3186 set yt $y1
3192 set yt $y1
3187 }
3193 }
3188 }
3194 }
3189 }
3195 }
3190 } else {
3196 } else {
3191 if {[info exists sidelines($id)]} {
3197 if {[info exists sidelines($id)]} {
3192 foreach ls $sidelines($id) {
3198 foreach ls $sidelines($id) {
3193 set y1 [lindex $ls 0 end]
3199 set y1 [lindex $ls 0 end]
3194 if {$y1 < $y && ($yt eq {} || $y1 > $yt)} {
3200 if {$y1 < $y && ($yt eq {} || $y1 > $yt)} {
3195 set yt $y1
3201 set yt $y1
3196 }
3202 }
3197 }
3203 }
3198 }
3204 }
3199 }
3205 }
3200 if {$yt eq {}} return
3206 if {$yt eq {}} return
3201 set ymax [lindex [$canv cget -scrollregion] 3]
3207 set ymax [lindex [$canv cget -scrollregion] 3]
3202 if {$ymax eq {} || $ymax <= 0} return
3208 if {$ymax eq {} || $ymax <= 0} return
3203 set view [$canv yview]
3209 set view [$canv yview]
3204 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3210 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3205 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3211 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3206 if {$yfrac < 0} {
3212 if {$yfrac < 0} {
3207 set yfrac 0
3213 set yfrac 0
3208 }
3214 }
3209 $canv yview moveto $yfrac
3215 $canv yview moveto $yfrac
3210 }
3216 }
3211
3217
3212 proc lineclick {x y id isnew} {
3218 proc lineclick {x y id isnew} {
3213 global ctext commitinfo children cflist canv thickerline
3219 global ctext commitinfo children cflist canv thickerline
3214
3220
3215 unmarkmatches
3221 unmarkmatches
3216 unselectline
3222 unselectline
3217 normalline
3223 normalline
3218 $canv delete hover
3224 $canv delete hover
3219 # draw this line thicker than normal
3225 # draw this line thicker than normal
3220 drawlines $id 1
3226 drawlines $id 1
3221 set thickerline $id
3227 set thickerline $id
3222 if {$isnew} {
3228 if {$isnew} {
3223 set ymax [lindex [$canv cget -scrollregion] 3]
3229 set ymax [lindex [$canv cget -scrollregion] 3]
3224 if {$ymax eq {}} return
3230 if {$ymax eq {}} return
3225 set yfrac [lindex [$canv yview] 0]
3231 set yfrac [lindex [$canv yview] 0]
3226 set y [expr {$y + $yfrac * $ymax}]
3232 set y [expr {$y + $yfrac * $ymax}]
3227 }
3233 }
3228 set dirn [clickisonarrow $id $y]
3234 set dirn [clickisonarrow $id $y]
3229 if {$dirn ne {}} {
3235 if {$dirn ne {}} {
3230 arrowjump $id $dirn $y
3236 arrowjump $id $dirn $y
3231 return
3237 return
3232 }
3238 }
3233
3239
3234 if {$isnew} {
3240 if {$isnew} {
3235 addtohistory [list lineclick $x $y $id 0]
3241 addtohistory [list lineclick $x $y $id 0]
3236 }
3242 }
3237 # fill the details pane with info about this line
3243 # fill the details pane with info about this line
3238 $ctext conf -state normal
3244 $ctext conf -state normal
3239 $ctext delete 0.0 end
3245 $ctext delete 0.0 end
3240 $ctext tag conf link -foreground blue -underline 1
3246 $ctext tag conf link -foreground blue -underline 1
3241 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3247 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3242 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3248 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3243 $ctext insert end "Parent:\t"
3249 $ctext insert end "Parent:\t"
3244 $ctext insert end $id [list link link0]
3250 $ctext insert end $id [list link link0]
3245 $ctext tag bind link0 <1> [list selbyid $id]
3251 $ctext tag bind link0 <1> [list selbyid $id]
3246 set info $commitinfo($id)
3252 set info $commitinfo($id)
3247 $ctext insert end "\n\t[lindex $info 0]\n"
3253 $ctext insert end "\n\t[lindex $info 0]\n"
3248 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3254 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3249 $ctext insert end "\tDate:\t[lindex $info 2]\n"
3255 $ctext insert end "\tDate:\t[lindex $info 2]\n"
3250 if {[info exists children($id)]} {
3256 if {[info exists children($id)]} {
3251 $ctext insert end "\nChildren:"
3257 $ctext insert end "\nChildren:"
3252 set i 0
3258 set i 0
3253 foreach child $children($id) {
3259 foreach child $children($id) {
3254 incr i
3260 incr i
3255 set info $commitinfo($child)
3261 set info $commitinfo($child)
3256 $ctext insert end "\n\t"
3262 $ctext insert end "\n\t"
3257 $ctext insert end $child [list link link$i]
3263 $ctext insert end $child [list link link$i]
3258 $ctext tag bind link$i <1> [list selbyid $child]
3264 $ctext tag bind link$i <1> [list selbyid $child]
3259 $ctext insert end "\n\t[lindex $info 0]"
3265 $ctext insert end "\n\t[lindex $info 0]"
3260 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3266 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3261 $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3267 $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3262 }
3268 }
3263 }
3269 }
3264 $ctext conf -state disabled
3270 $ctext conf -state disabled
3265
3271
3266 $cflist delete 0 end
3272 $cflist delete 0 end
3267 }
3273 }
3268
3274
3269 proc normalline {} {
3275 proc normalline {} {
3270 global thickerline
3276 global thickerline
3271 if {[info exists thickerline]} {
3277 if {[info exists thickerline]} {
3272 drawlines $thickerline 0
3278 drawlines $thickerline 0
3273 unset thickerline
3279 unset thickerline
3274 }
3280 }
3275 }
3281 }
3276
3282
3277 proc selbyid {id} {
3283 proc selbyid {id} {
3278 global idline
3284 global idline
3279 if {[info exists idline($id)]} {
3285 if {[info exists idline($id)]} {
3280 selectline $idline($id) 1
3286 selectline $idline($id) 1
3281 }
3287 }
3282 }
3288 }
3283
3289
3284 proc mstime {} {
3290 proc mstime {} {
3285 global startmstime
3291 global startmstime
3286 if {![info exists startmstime]} {
3292 if {![info exists startmstime]} {
3287 set startmstime [clock clicks -milliseconds]
3293 set startmstime [clock clicks -milliseconds]
3288 }
3294 }
3289 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3295 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3290 }
3296 }
3291
3297
3292 proc rowmenu {x y id} {
3298 proc rowmenu {x y id} {
3293 global rowctxmenu idline selectedline rowmenuid
3299 global rowctxmenu idline selectedline rowmenuid
3294
3300
3295 if {![info exists selectedline] || $idline($id) eq $selectedline} {
3301 if {![info exists selectedline] || $idline($id) eq $selectedline} {
3296 set state disabled
3302 set state disabled
3297 } else {
3303 } else {
3298 set state normal
3304 set state normal
3299 }
3305 }
3300 $rowctxmenu entryconfigure 0 -state $state
3306 $rowctxmenu entryconfigure 0 -state $state
3301 $rowctxmenu entryconfigure 1 -state $state
3307 $rowctxmenu entryconfigure 1 -state $state
3302 $rowctxmenu entryconfigure 2 -state $state
3308 $rowctxmenu entryconfigure 2 -state $state
3303 set rowmenuid $id
3309 set rowmenuid $id
3304 tk_popup $rowctxmenu $x $y
3310 tk_popup $rowctxmenu $x $y
3305 }
3311 }
3306
3312
3307 proc diffvssel {dirn} {
3313 proc diffvssel {dirn} {
3308 global rowmenuid selectedline lineid
3314 global rowmenuid selectedline lineid
3309
3315
3310 if {![info exists selectedline]} return
3316 if {![info exists selectedline]} return
3311 if {$dirn} {
3317 if {$dirn} {
3312 set oldid $lineid($selectedline)
3318 set oldid $lineid($selectedline)
3313 set newid $rowmenuid
3319 set newid $rowmenuid
3314 } else {
3320 } else {
3315 set oldid $rowmenuid
3321 set oldid $rowmenuid
3316 set newid $lineid($selectedline)
3322 set newid $lineid($selectedline)
3317 }
3323 }
3318 addtohistory [list doseldiff $oldid $newid]
3324 addtohistory [list doseldiff $oldid $newid]
3319 doseldiff $oldid $newid
3325 doseldiff $oldid $newid
3320 }
3326 }
3321
3327
3322 proc doseldiff {oldid newid} {
3328 proc doseldiff {oldid newid} {
3323 global ctext cflist
3329 global ctext cflist
3324 global commitinfo
3330 global commitinfo
3325
3331
3326 $ctext conf -state normal
3332 $ctext conf -state normal
3327 $ctext delete 0.0 end
3333 $ctext delete 0.0 end
3328 $ctext mark set fmark.0 0.0
3334 $ctext mark set fmark.0 0.0
3329 $ctext mark gravity fmark.0 left
3335 $ctext mark gravity fmark.0 left
3330 $cflist delete 0 end
3336 $cflist delete 0 end
3331 $cflist insert end "Top"
3337 $cflist insert end "Top"
3332 $ctext insert end "From "
3338 $ctext insert end "From "
3333 $ctext tag conf link -foreground blue -underline 1
3339 $ctext tag conf link -foreground blue -underline 1
3334 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3340 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3335 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3341 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3336 $ctext tag bind link0 <1> [list selbyid $oldid]
3342 $ctext tag bind link0 <1> [list selbyid $oldid]
3337 $ctext insert end $oldid [list link link0]
3343 $ctext insert end $oldid [list link link0]
3338 $ctext insert end "\n "
3344 $ctext insert end "\n "
3339 $ctext insert end [lindex $commitinfo($oldid) 0]
3345 $ctext insert end [lindex $commitinfo($oldid) 0]
3340 $ctext insert end "\n\nTo "
3346 $ctext insert end "\n\nTo "
3341 $ctext tag bind link1 <1> [list selbyid $newid]
3347 $ctext tag bind link1 <1> [list selbyid $newid]
3342 $ctext insert end $newid [list link link1]
3348 $ctext insert end $newid [list link link1]
3343 $ctext insert end "\n "
3349 $ctext insert end "\n "
3344 $ctext insert end [lindex $commitinfo($newid) 0]
3350 $ctext insert end [lindex $commitinfo($newid) 0]
3345 $ctext insert end "\n"
3351 $ctext insert end "\n"
3346 $ctext conf -state disabled
3352 $ctext conf -state disabled
3347 $ctext tag delete Comments
3353 $ctext tag delete Comments
3348 $ctext tag remove found 1.0 end
3354 $ctext tag remove found 1.0 end
3349 startdiff [list $newid $oldid]
3355 startdiff [list $newid $oldid]
3350 }
3356 }
3351
3357
3352 proc mkpatch {} {
3358 proc mkpatch {} {
3353 global rowmenuid currentid commitinfo patchtop patchnum
3359 global rowmenuid currentid commitinfo patchtop patchnum
3354
3360
3355 if {![info exists currentid]} return
3361 if {![info exists currentid]} return
3356 set oldid $currentid
3362 set oldid $currentid
3357 set oldhead [lindex $commitinfo($oldid) 0]
3363 set oldhead [lindex $commitinfo($oldid) 0]
3358 set newid $rowmenuid
3364 set newid $rowmenuid
3359 set newhead [lindex $commitinfo($newid) 0]
3365 set newhead [lindex $commitinfo($newid) 0]
3360 set top .patch
3366 set top .patch
3361 set patchtop $top
3367 set patchtop $top
3362 catch {destroy $top}
3368 catch {destroy $top}
3363 toplevel $top
3369 toplevel $top
3364 label $top.title -text "Generate patch"
3370 label $top.title -text "Generate patch"
3365 grid $top.title - -pady 10
3371 grid $top.title - -pady 10
3366 label $top.from -text "From:"
3372 label $top.from -text "From:"
3367 entry $top.fromsha1 -width 40 -relief flat
3373 entry $top.fromsha1 -width 40 -relief flat
3368 $top.fromsha1 insert 0 $oldid
3374 $top.fromsha1 insert 0 $oldid
3369 $top.fromsha1 conf -state readonly
3375 $top.fromsha1 conf -state readonly
3370 grid $top.from $top.fromsha1 -sticky w
3376 grid $top.from $top.fromsha1 -sticky w
3371 entry $top.fromhead -width 60 -relief flat
3377 entry $top.fromhead -width 60 -relief flat
3372 $top.fromhead insert 0 $oldhead
3378 $top.fromhead insert 0 $oldhead
3373 $top.fromhead conf -state readonly
3379 $top.fromhead conf -state readonly
3374 grid x $top.fromhead -sticky w
3380 grid x $top.fromhead -sticky w
3375 label $top.to -text "To:"
3381 label $top.to -text "To:"
3376 entry $top.tosha1 -width 40 -relief flat
3382 entry $top.tosha1 -width 40 -relief flat
3377 $top.tosha1 insert 0 $newid
3383 $top.tosha1 insert 0 $newid
3378 $top.tosha1 conf -state readonly
3384 $top.tosha1 conf -state readonly
3379 grid $top.to $top.tosha1 -sticky w
3385 grid $top.to $top.tosha1 -sticky w
3380 entry $top.tohead -width 60 -relief flat
3386 entry $top.tohead -width 60 -relief flat
3381 $top.tohead insert 0 $newhead
3387 $top.tohead insert 0 $newhead
3382 $top.tohead conf -state readonly
3388 $top.tohead conf -state readonly
3383 grid x $top.tohead -sticky w
3389 grid x $top.tohead -sticky w
3384 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
3390 button $top.rev -text "Reverse" -command mkpatchrev -padx 5
3385 grid $top.rev x -pady 10
3391 grid $top.rev x -pady 10
3386 label $top.flab -text "Output file:"
3392 label $top.flab -text "Output file:"
3387 entry $top.fname -width 60
3393 entry $top.fname -width 60
3388 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3394 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3389 incr patchnum
3395 incr patchnum
3390 grid $top.flab $top.fname -sticky w
3396 grid $top.flab $top.fname -sticky w
3391 frame $top.buts
3397 frame $top.buts
3392 button $top.buts.gen -text "Generate" -command mkpatchgo
3398 button $top.buts.gen -text "Generate" -command mkpatchgo
3393 button $top.buts.can -text "Cancel" -command mkpatchcan
3399 button $top.buts.can -text "Cancel" -command mkpatchcan
3394 grid $top.buts.gen $top.buts.can
3400 grid $top.buts.gen $top.buts.can
3395 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3401 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3396 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3402 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3397 grid $top.buts - -pady 10 -sticky ew
3403 grid $top.buts - -pady 10 -sticky ew
3398 focus $top.fname
3404 focus $top.fname
3399 }
3405 }
3400
3406
3401 proc mkpatchrev {} {
3407 proc mkpatchrev {} {
3402 global patchtop
3408 global patchtop
3403
3409
3404 set oldid [$patchtop.fromsha1 get]
3410 set oldid [$patchtop.fromsha1 get]
3405 set oldhead [$patchtop.fromhead get]
3411 set oldhead [$patchtop.fromhead get]
3406 set newid [$patchtop.tosha1 get]
3412 set newid [$patchtop.tosha1 get]
3407 set newhead [$patchtop.tohead get]
3413 set newhead [$patchtop.tohead get]
3408 foreach e [list fromsha1 fromhead tosha1 tohead] \
3414 foreach e [list fromsha1 fromhead tosha1 tohead] \
3409 v [list $newid $newhead $oldid $oldhead] {
3415 v [list $newid $newhead $oldid $oldhead] {
3410 $patchtop.$e conf -state normal
3416 $patchtop.$e conf -state normal
3411 $patchtop.$e delete 0 end
3417 $patchtop.$e delete 0 end
3412 $patchtop.$e insert 0 $v
3418 $patchtop.$e insert 0 $v
3413 $patchtop.$e conf -state readonly
3419 $patchtop.$e conf -state readonly
3414 }
3420 }
3415 }
3421 }
3416
3422
3417 proc mkpatchgo {} {
3423 proc mkpatchgo {} {
3418 global patchtop env
3424 global patchtop env
3419
3425
3420 set oldid [$patchtop.fromsha1 get]
3426 set oldid [$patchtop.fromsha1 get]
3421 set newid [$patchtop.tosha1 get]
3427 set newid [$patchtop.tosha1 get]
3422 set fname [$patchtop.fname get]
3428 set fname [$patchtop.fname get]
3423 if {[catch {exec $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $oldid $newid >$fname &} err]} {
3429 if {[catch {exec $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $oldid $newid >$fname &} err]} {
3424 error_popup "Error creating patch: $err"
3430 error_popup "Error creating patch: $err"
3425 }
3431 }
3426 catch {destroy $patchtop}
3432 catch {destroy $patchtop}
3427 unset patchtop
3433 unset patchtop
3428 }
3434 }
3429
3435
3430 proc mkpatchcan {} {
3436 proc mkpatchcan {} {
3431 global patchtop
3437 global patchtop
3432
3438
3433 catch {destroy $patchtop}
3439 catch {destroy $patchtop}
3434 unset patchtop
3440 unset patchtop
3435 }
3441 }
3436
3442
3437 proc mktag {} {
3443 proc mktag {} {
3438 global rowmenuid mktagtop commitinfo
3444 global rowmenuid mktagtop commitinfo
3439
3445
3440 set top .maketag
3446 set top .maketag
3441 set mktagtop $top
3447 set mktagtop $top
3442 catch {destroy $top}
3448 catch {destroy $top}
3443 toplevel $top
3449 toplevel $top
3444 label $top.title -text "Create tag"
3450 label $top.title -text "Create tag"
3445 grid $top.title - -pady 10
3451 grid $top.title - -pady 10
3446 label $top.id -text "ID:"
3452 label $top.id -text "ID:"
3447 entry $top.sha1 -width 40 -relief flat
3453 entry $top.sha1 -width 40 -relief flat
3448 $top.sha1 insert 0 $rowmenuid
3454 $top.sha1 insert 0 $rowmenuid
3449 $top.sha1 conf -state readonly
3455 $top.sha1 conf -state readonly
3450 grid $top.id $top.sha1 -sticky w
3456 grid $top.id $top.sha1 -sticky w
3451 entry $top.head -width 60 -relief flat
3457 entry $top.head -width 60 -relief flat
3452 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3458 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3453 $top.head conf -state readonly
3459 $top.head conf -state readonly
3454 grid x $top.head -sticky w
3460 grid x $top.head -sticky w
3455 label $top.tlab -text "Tag name:"
3461 label $top.tlab -text "Tag name:"
3456 entry $top.tag -width 60
3462 entry $top.tag -width 60
3457 grid $top.tlab $top.tag -sticky w
3463 grid $top.tlab $top.tag -sticky w
3458 frame $top.buts
3464 frame $top.buts
3459 button $top.buts.gen -text "Create" -command mktaggo
3465 button $top.buts.gen -text "Create" -command mktaggo
3460 button $top.buts.can -text "Cancel" -command mktagcan
3466 button $top.buts.can -text "Cancel" -command mktagcan
3461 grid $top.buts.gen $top.buts.can
3467 grid $top.buts.gen $top.buts.can
3462 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3468 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3463 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3469 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3464 grid $top.buts - -pady 10 -sticky ew
3470 grid $top.buts - -pady 10 -sticky ew
3465 focus $top.tag
3471 focus $top.tag
3466 }
3472 }
3467
3473
3468 proc domktag {} {
3474 proc domktag {} {
3469 global mktagtop env tagids idtags
3475 global mktagtop env tagids idtags
3470
3476
3471 set id [$mktagtop.sha1 get]
3477 set id [$mktagtop.sha1 get]
3472 set tag [$mktagtop.tag get]
3478 set tag [$mktagtop.tag get]
3473 if {$tag == {}} {
3479 if {$tag == {}} {
3474 error_popup "No tag name specified"
3480 error_popup "No tag name specified"
3475 return
3481 return
3476 }
3482 }
3477 if {[info exists tagids($tag)]} {
3483 if {[info exists tagids($tag)]} {
3478 error_popup "Tag \"$tag\" already exists"
3484 error_popup "Tag \"$tag\" already exists"
3479 return
3485 return
3480 }
3486 }
3481 if {[catch {
3487 if {[catch {
3482 set out [exec $env(HG) --config ui.report_untrusted=false tag -r $id $tag]
3488 set out [exec $env(HG) --config ui.report_untrusted=false tag -r $id $tag]
3483 } err]} {
3489 } err]} {
3484 error_popup "Error creating tag: $err"
3490 error_popup "Error creating tag: $err"
3485 return
3491 return
3486 }
3492 }
3487
3493
3488 set tagids($tag) $id
3494 set tagids($tag) $id
3489 lappend idtags($id) $tag
3495 lappend idtags($id) $tag
3490 redrawtags $id
3496 redrawtags $id
3491 }
3497 }
3492
3498
3493 proc redrawtags {id} {
3499 proc redrawtags {id} {
3494 global canv linehtag idline idpos selectedline
3500 global canv linehtag idline idpos selectedline
3495
3501
3496 if {![info exists idline($id)]} return
3502 if {![info exists idline($id)]} return
3497 $canv delete tag.$id
3503 $canv delete tag.$id
3498 set xt [eval drawtags $id $idpos($id)]
3504 set xt [eval drawtags $id $idpos($id)]
3499 $canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
3505 $canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
3500 if {[info exists selectedline] && $selectedline == $idline($id)} {
3506 if {[info exists selectedline] && $selectedline == $idline($id)} {
3501 selectline $selectedline 0
3507 selectline $selectedline 0
3502 }
3508 }
3503 }
3509 }
3504
3510
3505 proc mktagcan {} {
3511 proc mktagcan {} {
3506 global mktagtop
3512 global mktagtop
3507
3513
3508 catch {destroy $mktagtop}
3514 catch {destroy $mktagtop}
3509 unset mktagtop
3515 unset mktagtop
3510 }
3516 }
3511
3517
3512 proc mktaggo {} {
3518 proc mktaggo {} {
3513 domktag
3519 domktag
3514 mktagcan
3520 mktagcan
3515 }
3521 }
3516
3522
3517 proc writecommit {} {
3523 proc writecommit {} {
3518 global rowmenuid wrcomtop commitinfo wrcomcmd
3524 global rowmenuid wrcomtop commitinfo wrcomcmd
3519
3525
3520 set top .writecommit
3526 set top .writecommit
3521 set wrcomtop $top
3527 set wrcomtop $top
3522 catch {destroy $top}
3528 catch {destroy $top}
3523 toplevel $top
3529 toplevel $top
3524 label $top.title -text "Write commit to file"
3530 label $top.title -text "Write commit to file"
3525 grid $top.title - -pady 10
3531 grid $top.title - -pady 10
3526 label $top.id -text "ID:"
3532 label $top.id -text "ID:"
3527 entry $top.sha1 -width 40 -relief flat
3533 entry $top.sha1 -width 40 -relief flat
3528 $top.sha1 insert 0 $rowmenuid
3534 $top.sha1 insert 0 $rowmenuid
3529 $top.sha1 conf -state readonly
3535 $top.sha1 conf -state readonly
3530 grid $top.id $top.sha1 -sticky w
3536 grid $top.id $top.sha1 -sticky w
3531 entry $top.head -width 60 -relief flat
3537 entry $top.head -width 60 -relief flat
3532 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3538 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3533 $top.head conf -state readonly
3539 $top.head conf -state readonly
3534 grid x $top.head -sticky w
3540 grid x $top.head -sticky w
3535 label $top.clab -text "Command:"
3541 label $top.clab -text "Command:"
3536 entry $top.cmd -width 60 -textvariable wrcomcmd
3542 entry $top.cmd -width 60 -textvariable wrcomcmd
3537 grid $top.clab $top.cmd -sticky w -pady 10
3543 grid $top.clab $top.cmd -sticky w -pady 10
3538 label $top.flab -text "Output file:"
3544 label $top.flab -text "Output file:"
3539 entry $top.fname -width 60
3545 entry $top.fname -width 60
3540 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3546 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3541 grid $top.flab $top.fname -sticky w
3547 grid $top.flab $top.fname -sticky w
3542 frame $top.buts
3548 frame $top.buts
3543 button $top.buts.gen -text "Write" -command wrcomgo
3549 button $top.buts.gen -text "Write" -command wrcomgo
3544 button $top.buts.can -text "Cancel" -command wrcomcan
3550 button $top.buts.can -text "Cancel" -command wrcomcan
3545 grid $top.buts.gen $top.buts.can
3551 grid $top.buts.gen $top.buts.can
3546 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3552 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3547 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3553 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3548 grid $top.buts - -pady 10 -sticky ew
3554 grid $top.buts - -pady 10 -sticky ew
3549 focus $top.fname
3555 focus $top.fname
3550 }
3556 }
3551
3557
3552 proc wrcomgo {} {
3558 proc wrcomgo {} {
3553 global wrcomtop
3559 global wrcomtop
3554
3560
3555 set id [$wrcomtop.sha1 get]
3561 set id [$wrcomtop.sha1 get]
3556 set cmd "echo $id | [$wrcomtop.cmd get]"
3562 set cmd "echo $id | [$wrcomtop.cmd get]"
3557 set fname [$wrcomtop.fname get]
3563 set fname [$wrcomtop.fname get]
3558 if {[catch {exec sh -c $cmd > $fname &} err]} {
3564 if {[catch {exec sh -c $cmd > $fname &} err]} {
3559 error_popup "Error writing commit: $err"
3565 error_popup "Error writing commit: $err"
3560 }
3566 }
3561 catch {destroy $wrcomtop}
3567 catch {destroy $wrcomtop}
3562 unset wrcomtop
3568 unset wrcomtop
3563 }
3569 }
3564
3570
3565 proc wrcomcan {} {
3571 proc wrcomcan {} {
3566 global wrcomtop
3572 global wrcomtop
3567
3573
3568 catch {destroy $wrcomtop}
3574 catch {destroy $wrcomtop}
3569 unset wrcomtop
3575 unset wrcomtop
3570 }
3576 }
3571
3577
3572 proc listrefs {id} {
3578 proc listrefs {id} {
3573 global idtags idheads idotherrefs
3579 global idtags idheads idotherrefs
3574
3580
3575 set x {}
3581 set x {}
3576 if {[info exists idtags($id)]} {
3582 if {[info exists idtags($id)]} {
3577 set x $idtags($id)
3583 set x $idtags($id)
3578 }
3584 }
3579 set y {}
3585 set y {}
3580 if {[info exists idheads($id)]} {
3586 if {[info exists idheads($id)]} {
3581 set y $idheads($id)
3587 set y $idheads($id)
3582 }
3588 }
3583 set z {}
3589 set z {}
3584 if {[info exists idotherrefs($id)]} {
3590 if {[info exists idotherrefs($id)]} {
3585 set z $idotherrefs($id)
3591 set z $idotherrefs($id)
3586 }
3592 }
3587 return [list $x $y $z]
3593 return [list $x $y $z]
3588 }
3594 }
3589
3595
3590 proc rereadrefs {} {
3596 proc rereadrefs {} {
3591 global idtags idheads idotherrefs
3597 global idtags idheads idotherrefs
3592 global tagids headids otherrefids
3598 global tagids headids otherrefids
3593
3599
3594 set refids [concat [array names idtags] \
3600 set refids [concat [array names idtags] \
3595 [array names idheads] [array names idotherrefs]]
3601 [array names idheads] [array names idotherrefs]]
3596 foreach id $refids {
3602 foreach id $refids {
3597 if {![info exists ref($id)]} {
3603 if {![info exists ref($id)]} {
3598 set ref($id) [listrefs $id]
3604 set ref($id) [listrefs $id]
3599 }
3605 }
3600 }
3606 }
3601 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
3607 foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
3602 catch {unset $v}
3608 catch {unset $v}
3603 }
3609 }
3604 readrefs
3610 readrefs
3605 set refids [lsort -unique [concat $refids [array names idtags] \
3611 set refids [lsort -unique [concat $refids [array names idtags] \
3606 [array names idheads] [array names idotherrefs]]]
3612 [array names idheads] [array names idotherrefs]]]
3607 foreach id $refids {
3613 foreach id $refids {
3608 set v [listrefs $id]
3614 set v [listrefs $id]
3609 if {![info exists ref($id)] || $ref($id) != $v} {
3615 if {![info exists ref($id)] || $ref($id) != $v} {
3610 redrawtags $id
3616 redrawtags $id
3611 }
3617 }
3612 }
3618 }
3613 }
3619 }
3614
3620
3615 proc showtag {tag isnew} {
3621 proc showtag {tag isnew} {
3616 global ctext cflist tagcontents tagids linknum
3622 global ctext cflist tagcontents tagids linknum
3617
3623
3618 if {$isnew} {
3624 if {$isnew} {
3619 addtohistory [list showtag $tag 0]
3625 addtohistory [list showtag $tag 0]
3620 }
3626 }
3621 $ctext conf -state normal
3627 $ctext conf -state normal
3622 $ctext delete 0.0 end
3628 $ctext delete 0.0 end
3623 set linknum 0
3629 set linknum 0
3624 if {[info exists tagcontents($tag)]} {
3630 if {[info exists tagcontents($tag)]} {
3625 set text $tagcontents($tag)
3631 set text $tagcontents($tag)
3626 } else {
3632 } else {
3627 set text "Tag: $tag\nId: $tagids($tag)"
3633 set text "Tag: $tag\nId: $tagids($tag)"
3628 }
3634 }
3629 appendwithlinks $text
3635 appendwithlinks $text
3630 $ctext conf -state disabled
3636 $ctext conf -state disabled
3631 $cflist delete 0 end
3637 $cflist delete 0 end
3632 }
3638 }
3633
3639
3634 proc doquit {} {
3640 proc doquit {} {
3635 global stopped
3641 global stopped
3636 set stopped 100
3642 set stopped 100
3637 destroy .
3643 destroy .
3638 }
3644 }
3639
3645
3640 # defaults...
3646 # defaults...
3641 set datemode 0
3647 set datemode 0
3642 set boldnames 0
3648 set boldnames 0
3643 set diffopts "-U 5 -p"
3649 set diffopts "-U 5 -p"
3644 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty"
3650 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty"
3645
3651
3646 set mainfont {Helvetica 9}
3652 set mainfont {Helvetica 9}
3647 set textfont {Courier 9}
3653 set textfont {Courier 9}
3648 set findmergefiles 0
3654 set findmergefiles 0
3649 set gaudydiff 0
3655 set gaudydiff 0
3650 set maxgraphpct 50
3656 set maxgraphpct 50
3651 set maxwidth 16
3657 set maxwidth 16
3652
3658
3653 set colors {green red blue magenta darkgrey brown orange}
3659 set colors {green red blue magenta darkgrey brown orange}
3654
3660
3655 catch {source ~/.gitk}
3661 catch {source ~/.gitk}
3656
3662
3657 set namefont $mainfont
3663 set namefont $mainfont
3658 if {$boldnames} {
3664 if {$boldnames} {
3659 lappend namefont bold
3665 lappend namefont bold
3660 }
3666 }
3661
3667
3662 set revtreeargs {}
3668 set revtreeargs {}
3663 foreach arg $argv {
3669 foreach arg $argv {
3664 switch -regexp -- $arg {
3670 switch -regexp -- $arg {
3665 "^$" { }
3671 "^$" { }
3666 "^-b" { set boldnames 1 }
3672 "^-b" { set boldnames 1 }
3667 "^-d" { set datemode 1 }
3673 "^-d" { set datemode 1 }
3668 default {
3674 default {
3669 lappend revtreeargs $arg
3675 lappend revtreeargs $arg
3670 }
3676 }
3671 }
3677 }
3672 }
3678 }
3673
3679
3674 set history {}
3680 set history {}
3675 set historyindex 0
3681 set historyindex 0
3676
3682
3677 set stopped 0
3683 set stopped 0
3678 set redisplaying 0
3684 set redisplaying 0
3679 set stuffsaved 0
3685 set stuffsaved 0
3680 set patchnum 0
3686 set patchnum 0
3681 setcoords
3687 setcoords
3682 makewindow
3688 makewindow
3683 readrefs
3689 readrefs
3684 getcommits $revtreeargs
3690 getcommits $revtreeargs
General Comments 0
You need to be logged in to leave comments. Login now