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