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