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