##// END OF EJS Templates
codingstyle: remove trailing spaces in various text files...
Mads Kiilerich -
r19023:86531a70 default
parent child Browse files
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,4124 +1,4124
1 #!/usr/bin/env wish
1 #!/usr/bin/env wish
2
2
3 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
3 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
4 # This program is free software; it may be used, copied, modified
4 # This program is free software; it may be used, copied, modified
5 # and distributed under the terms of the GNU General Public Licence,
5 # and distributed under the terms of the GNU General Public Licence,
6 # either version 2, or (at your option) any later version.
6 # either version 2, or (at your option) any later version.
7 #
7 #
8 # See hgk.py for extension usage and configuration.
8 # See hgk.py for extension usage and configuration.
9
9
10
10
11 # Modified version of Tip 171:
11 # Modified version of Tip 171:
12 # http://www.tcl.tk/cgi-bin/tct/tip/171.html
12 # http://www.tcl.tk/cgi-bin/tct/tip/171.html
13 #
13 #
14 # The in_mousewheel global was added to fix strange reentrancy issues.
14 # The in_mousewheel global was added to fix strange reentrancy issues.
15 # The whole snipped is activated only under windows, mouse wheel
15 # The whole snipped is activated only under windows, mouse wheel
16 # bindings working already under MacOSX and Linux.
16 # bindings working already under MacOSX and Linux.
17
17
18 if {[catch {package require Ttk}]} {
18 if {[catch {package require Ttk}]} {
19 # use a shim
19 # use a shim
20 namespace eval ttk {
20 namespace eval ttk {
21 proc style args {}
21 proc style args {}
22
22
23 proc entry args {
23 proc entry args {
24 eval [linsert $args 0 ::entry] -relief flat
24 eval [linsert $args 0 ::entry] -relief flat
25 }
25 }
26 }
26 }
27
27
28 interp alias {} ttk::button {} button
28 interp alias {} ttk::button {} button
29 interp alias {} ttk::frame {} frame
29 interp alias {} ttk::frame {} frame
30 interp alias {} ttk::label {} label
30 interp alias {} ttk::label {} label
31 interp alias {} ttk::scrollbar {} scrollbar
31 interp alias {} ttk::scrollbar {} scrollbar
32 interp alias {} ttk::optionMenu {} tk_optionMenu
32 interp alias {} ttk::optionMenu {} tk_optionMenu
33
33
34 proc updatepalette {} {}
34 proc updatepalette {} {}
35 } else {
35 } else {
36 proc ::ttk::optionMenu {w varName firstValue args} {
36 proc ::ttk::optionMenu {w varName firstValue args} {
37 upvar #0 $varName var
37 upvar #0 $varName var
38
38
39 if {![info exists var]} {
39 if {![info exists var]} {
40 set var $firstValue
40 set var $firstValue
41 }
41 }
42 ttk::menubutton $w -textvariable $varName -menu $w.menu \
42 ttk::menubutton $w -textvariable $varName -menu $w.menu \
43 -direction flush
43 -direction flush
44 menu $w.menu -tearoff 0
44 menu $w.menu -tearoff 0
45 $w.menu add radiobutton -label $firstValue -variable $varName
45 $w.menu add radiobutton -label $firstValue -variable $varName
46 foreach i $args {
46 foreach i $args {
47 $w.menu add radiobutton -label $i -variable $varName
47 $w.menu add radiobutton -label $i -variable $varName
48 }
48 }
49 return $w.menu
49 return $w.menu
50 }
50 }
51 proc updatepalette {} {
51 proc updatepalette {} {
52 catch {
52 catch {
53 tk_setPalette background [ttk::style lookup client -background]
53 tk_setPalette background [ttk::style lookup client -background]
54 }
54 }
55 }
55 }
56 }
56 }
57
57
58 if {[tk windowingsystem] eq "win32"} {
58 if {[tk windowingsystem] eq "win32"} {
59
59
60 ttk::style theme use xpnative
60 ttk::style theme use xpnative
61
61
62 set mw_classes [list Text Listbox Table TreeCtrl]
62 set mw_classes [list Text Listbox Table TreeCtrl]
63 foreach class $mw_classes { bind $class <MouseWheel> {} }
63 foreach class $mw_classes { bind $class <MouseWheel> {} }
64
64
65 set in_mousewheel 0
65 set in_mousewheel 0
66
66
67 proc ::tk::MouseWheel {wFired X Y D {shifted 0}} {
67 proc ::tk::MouseWheel {wFired X Y D {shifted 0}} {
68 global in_mousewheel
68 global in_mousewheel
69 if { $in_mousewheel != 0 } { return }
69 if { $in_mousewheel != 0 } { return }
70 # Set event to check based on call
70 # Set event to check based on call
71 set evt "<[expr {$shifted?{Shift-}:{}}]MouseWheel>"
71 set evt "<[expr {$shifted?{Shift-}:{}}]MouseWheel>"
72 # do not double-fire in case the class already has a binding
72 # do not double-fire in case the class already has a binding
73 if {[bind [winfo class $wFired] $evt] ne ""} { return }
73 if {[bind [winfo class $wFired] $evt] ne ""} { return }
74 # obtain the window the mouse is over
74 # obtain the window the mouse is over
75 set w [winfo containing $X $Y]
75 set w [winfo containing $X $Y]
76 # if we are outside the app, try and scroll the focus widget
76 # if we are outside the app, try and scroll the focus widget
77 if {![winfo exists $w]} { catch {set w [focus]} }
77 if {![winfo exists $w]} { catch {set w [focus]} }
78 if {[winfo exists $w]} {
78 if {[winfo exists $w]} {
79
79
80 if {[bind $w $evt] ne ""} {
80 if {[bind $w $evt] ne ""} {
81 # Awkward ... this widget has a MouseWheel binding, but to
81 # Awkward ... this widget has a MouseWheel binding, but to
82 # trigger successfully in it, we must give it focus.
82 # trigger successfully in it, we must give it focus.
83 catch {focus} old
83 catch {focus} old
84 if {$w ne $old} { focus $w }
84 if {$w ne $old} { focus $w }
85 set in_mousewheel 1
85 set in_mousewheel 1
86 event generate $w $evt -rootx $X -rooty $Y -delta $D
86 event generate $w $evt -rootx $X -rooty $Y -delta $D
87 set in_mousewheel 0
87 set in_mousewheel 0
88 if {$w ne $old} { focus $old }
88 if {$w ne $old} { focus $old }
89 return
89 return
90 }
90 }
91
91
92 # aqua and x11/win32 have different delta handling
92 # aqua and x11/win32 have different delta handling
93 if {[tk windowingsystem] ne "aqua"} {
93 if {[tk windowingsystem] ne "aqua"} {
94 set delta [expr {- ($D / 30)}]
94 set delta [expr {- ($D / 30)}]
95 } else {
95 } else {
96 set delta [expr {- ($D)}]
96 set delta [expr {- ($D)}]
97 }
97 }
98 # scrollbars have different call conventions
98 # scrollbars have different call conventions
99 if {[string match "*Scrollbar" [winfo class $w]]} {
99 if {[string match "*Scrollbar" [winfo class $w]]} {
100 catch {tk::ScrollByUnits $w \
100 catch {tk::ScrollByUnits $w \
101 [string index [$w cget -orient] 0] $delta}
101 [string index [$w cget -orient] 0] $delta}
102 } else {
102 } else {
103 set cmd [list $w [expr {$shifted ? "xview" : "yview"}] \
103 set cmd [list $w [expr {$shifted ? "xview" : "yview"}] \
104 scroll $delta units]
104 scroll $delta units]
105 # Walking up to find the proper widget (handles cases like
105 # Walking up to find the proper widget (handles cases like
106 # embedded widgets in a canvas)
106 # embedded widgets in a canvas)
107 while {[catch $cmd] && [winfo toplevel $w] ne $w} {
107 while {[catch $cmd] && [winfo toplevel $w] ne $w} {
108 set w [winfo parent $w]
108 set w [winfo parent $w]
109 }
109 }
110 }
110 }
111 }
111 }
112 }
112 }
113
113
114 bind all <MouseWheel> [list ::tk::MouseWheel %W %X %Y %D 0]
114 bind all <MouseWheel> [list ::tk::MouseWheel %W %X %Y %D 0]
115
115
116 # end of win32 section
116 # end of win32 section
117 } else {
117 } else {
118
118
119 if {[catch {
119 if {[catch {
120 set theme [ttk::style theme use]
120 set theme [ttk::style theme use]
121 }]} {
121 }]} {
122 set theme $::ttk::currentTheme
122 set theme $::ttk::currentTheme
123 }
123 }
124 if {$theme eq "default"} {
124 if {$theme eq "default"} {
125 ttk::style theme use clam
125 ttk::style theme use clam
126 }
126 }
127
127
128 }
128 }
129
129
130 updatepalette
130 updatepalette
131
131
132 # Unify right mouse button handling.
132 # Unify right mouse button handling.
133 # See "mouse buttons on macintosh" thread on comp.lang.tcl
133 # See "mouse buttons on macintosh" thread on comp.lang.tcl
134 if {[tk windowingsystem] eq "aqua"} {
134 if {[tk windowingsystem] eq "aqua"} {
135 event add <<B3>> <Control-ButtonPress-1>
135 event add <<B3>> <Control-ButtonPress-1>
136 event add <<B3>> <Button-2>
136 event add <<B3>> <Button-2>
137 } else {
137 } else {
138 event add <<B3>> <Button-3>
138 event add <<B3>> <Button-3>
139 }
139 }
140
140
141 proc gitdir {} {
141 proc gitdir {} {
142 global env
142 global env
143 if {[info exists env(GIT_DIR)]} {
143 if {[info exists env(GIT_DIR)]} {
144 return $env(GIT_DIR)
144 return $env(GIT_DIR)
145 } else {
145 } else {
146 return ".hg"
146 return ".hg"
147 }
147 }
148 }
148 }
149
149
150 proc popupify {w} {
150 proc popupify {w} {
151 wm resizable $w 0 0
151 wm resizable $w 0 0
152 wm withdraw $w
152 wm withdraw $w
153 update
153 update
154 set x [expr {([winfo screenwidth .]-[winfo reqwidth $w])/2}]
154 set x [expr {([winfo screenwidth .]-[winfo reqwidth $w])/2}]
155 set y [expr {([winfo screenheight .]-[winfo reqheight $w])/2}]
155 set y [expr {([winfo screenheight .]-[winfo reqheight $w])/2}]
156 wm geometry $w +$x+$y
156 wm geometry $w +$x+$y
157 wm transient $w .
157 wm transient $w .
158 wm deiconify $w
158 wm deiconify $w
159 wm resizable $w 1 1
159 wm resizable $w 1 1
160 }
160 }
161
161
162 proc getcommits {rargs} {
162 proc getcommits {rargs} {
163 global commits commfd phase canv mainfont env
163 global commits commfd phase canv mainfont env
164 global startmsecs nextupdate ncmupdate
164 global startmsecs nextupdate ncmupdate
165 global ctext maincursor textcursor leftover
165 global ctext maincursor textcursor leftover
166
166
167 # check that we can find a .git directory somewhere...
167 # check that we can find a .git directory somewhere...
168 set gitdir [gitdir]
168 set gitdir [gitdir]
169 if {![file isdirectory $gitdir]} {
169 if {![file isdirectory $gitdir]} {
170 error_popup "Cannot find the git directory \"$gitdir\"."
170 error_popup "Cannot find the git directory \"$gitdir\"."
171 exit 1
171 exit 1
172 }
172 }
173 set commits {}
173 set commits {}
174 set phase getcommits
174 set phase getcommits
175 set startmsecs [clock clicks -milliseconds]
175 set startmsecs [clock clicks -milliseconds]
176 set nextupdate [expr $startmsecs + 100]
176 set nextupdate [expr $startmsecs + 100]
177 set ncmupdate 1
177 set ncmupdate 1
178 set limit 0
178 set limit 0
179 set revargs {}
179 set revargs {}
180 for {set i 0} {$i < [llength $rargs]} {incr i} {
180 for {set i 0} {$i < [llength $rargs]} {incr i} {
181 set opt [lindex $rargs $i]
181 set opt [lindex $rargs $i]
182 if {$opt == "--limit"} {
182 if {$opt == "--limit"} {
183 incr i
183 incr i
184 set limit [lindex $rargs $i]
184 set limit [lindex $rargs $i]
185 } else {
185 } else {
186 lappend revargs $opt
186 lappend revargs $opt
187 }
187 }
188 }
188 }
189 if [catch {
189 if [catch {
190 set parse_args [concat --default HEAD $revargs]
190 set parse_args [concat --default HEAD $revargs]
191 set parse_temp [eval exec {$env(HG)} --config ui.report_untrusted=false debug-rev-parse $parse_args]
191 set parse_temp [eval exec {$env(HG)} --config ui.report_untrusted=false debug-rev-parse $parse_args]
192 regsub -all "\r\n" $parse_temp "\n" parse_temp
192 regsub -all "\r\n" $parse_temp "\n" parse_temp
193 set parsed_args [split $parse_temp "\n"]
193 set parsed_args [split $parse_temp "\n"]
194 } err] {
194 } err] {
195 # if git-rev-parse failed for some reason...
195 # if git-rev-parse failed for some reason...
196 if {$rargs == {}} {
196 if {$rargs == {}} {
197 set revargs HEAD
197 set revargs HEAD
198 }
198 }
199 set parsed_args $revargs
199 set parsed_args $revargs
200 }
200 }
201 if {$limit > 0} {
201 if {$limit > 0} {
202 set parsed_args [concat -n $limit $parsed_args]
202 set parsed_args [concat -n $limit $parsed_args]
203 }
203 }
204 if [catch {
204 if [catch {
205 set commfd [open "|{$env(HG)} --config ui.report_untrusted=false debug-rev-list --header --topo-order --parents $parsed_args" r]
205 set commfd [open "|{$env(HG)} --config ui.report_untrusted=false debug-rev-list --header --topo-order --parents $parsed_args" r]
206 } err] {
206 } err] {
207 puts stderr "Error executing hg debug-rev-list: $err"
207 puts stderr "Error executing hg debug-rev-list: $err"
208 exit 1
208 exit 1
209 }
209 }
210 set leftover {}
210 set leftover {}
211 fconfigure $commfd -blocking 0 -translation lf
211 fconfigure $commfd -blocking 0 -translation lf
212 fileevent $commfd readable [list getcommitlines $commfd]
212 fileevent $commfd readable [list getcommitlines $commfd]
213 $canv delete all
213 $canv delete all
214 $canv create text 3 3 -anchor nw -text "Reading commits..." \
214 $canv create text 3 3 -anchor nw -text "Reading commits..." \
215 -font $mainfont -tags textitems
215 -font $mainfont -tags textitems
216 . config -cursor watch
216 . config -cursor watch
217 settextcursor watch
217 settextcursor watch
218 }
218 }
219
219
220 proc getcommitlines {commfd} {
220 proc getcommitlines {commfd} {
221 global commits parents cdate children
221 global commits parents cdate children
222 global commitlisted phase commitinfo nextupdate
222 global commitlisted phase commitinfo nextupdate
223 global stopped redisplaying leftover
223 global stopped redisplaying leftover
224
224
225 set stuff [read $commfd]
225 set stuff [read $commfd]
226 if {$stuff == {}} {
226 if {$stuff == {}} {
227 if {![eof $commfd]} return
227 if {![eof $commfd]} return
228 # set it blocking so we wait for the process to terminate
228 # set it blocking so we wait for the process to terminate
229 fconfigure $commfd -blocking 1
229 fconfigure $commfd -blocking 1
230 if {![catch {close $commfd} err]} {
230 if {![catch {close $commfd} err]} {
231 after idle finishcommits
231 after idle finishcommits
232 return
232 return
233 }
233 }
234 if {[string range $err 0 4] == "usage"} {
234 if {[string range $err 0 4] == "usage"} {
235 set err \
235 set err \
236 {Gitk: error reading commits: bad arguments to git-rev-list.
236 {Gitk: error reading commits: bad arguments to git-rev-list.
237 (Note: arguments to gitk are passed to git-rev-list
237 (Note: arguments to gitk are passed to git-rev-list
238 to allow selection of commits to be displayed.)}
238 to allow selection of commits to be displayed.)}
239 } else {
239 } else {
240 set err "Error reading commits: $err"
240 set err "Error reading commits: $err"
241 }
241 }
242 error_popup $err
242 error_popup $err
243 exit 1
243 exit 1
244 }
244 }
245 set start 0
245 set start 0
246 while 1 {
246 while 1 {
247 set i [string first "\0" $stuff $start]
247 set i [string first "\0" $stuff $start]
248 if {$i < 0} {
248 if {$i < 0} {
249 append leftover [string range $stuff $start end]
249 append leftover [string range $stuff $start end]
250 return
250 return
251 }
251 }
252 set cmit [string range $stuff $start [expr {$i - 1}]]
252 set cmit [string range $stuff $start [expr {$i - 1}]]
253 if {$start == 0} {
253 if {$start == 0} {
254 set cmit "$leftover$cmit"
254 set cmit "$leftover$cmit"
255 set leftover {}
255 set leftover {}
256 }
256 }
257 set start [expr {$i + 1}]
257 set start [expr {$i + 1}]
258 regsub -all "\r\n" $cmit "\n" cmit
258 regsub -all "\r\n" $cmit "\n" cmit
259 set j [string first "\n" $cmit]
259 set j [string first "\n" $cmit]
260 set ok 0
260 set ok 0
261 if {$j >= 0} {
261 if {$j >= 0} {
262 set ids [string range $cmit 0 [expr {$j - 1}]]
262 set ids [string range $cmit 0 [expr {$j - 1}]]
263 set ok 1
263 set ok 1
264 foreach id $ids {
264 foreach id $ids {
265 if {![regexp {^[0-9a-f]{12}$} $id]} {
265 if {![regexp {^[0-9a-f]{12}$} $id]} {
266 set ok 0
266 set ok 0
267 break
267 break
268 }
268 }
269 }
269 }
270 }
270 }
271 if {!$ok} {
271 if {!$ok} {
272 set shortcmit $cmit
272 set shortcmit $cmit
273 if {[string length $shortcmit] > 80} {
273 if {[string length $shortcmit] > 80} {
274 set shortcmit "[string range $shortcmit 0 80]..."
274 set shortcmit "[string range $shortcmit 0 80]..."
275 }
275 }
276 error_popup "Can't parse hg debug-rev-list output: {$shortcmit}"
276 error_popup "Can't parse hg debug-rev-list output: {$shortcmit}"
277 exit 1
277 exit 1
278 }
278 }
279 set id [lindex $ids 0]
279 set id [lindex $ids 0]
280 set olds [lrange $ids 1 end]
280 set olds [lrange $ids 1 end]
281 set cmit [string range $cmit [expr {$j + 1}] end]
281 set cmit [string range $cmit [expr {$j + 1}] end]
282 lappend commits $id
282 lappend commits $id
283 set commitlisted($id) 1
283 set commitlisted($id) 1
284 parsecommit $id $cmit 1 [lrange $ids 1 end]
284 parsecommit $id $cmit 1 [lrange $ids 1 end]
285 drawcommit $id
285 drawcommit $id
286 if {[clock clicks -milliseconds] >= $nextupdate} {
286 if {[clock clicks -milliseconds] >= $nextupdate} {
287 doupdate 1
287 doupdate 1
288 }
288 }
289 while {$redisplaying} {
289 while {$redisplaying} {
290 set redisplaying 0
290 set redisplaying 0
291 if {$stopped == 1} {
291 if {$stopped == 1} {
292 set stopped 0
292 set stopped 0
293 set phase "getcommits"
293 set phase "getcommits"
294 foreach id $commits {
294 foreach id $commits {
295 drawcommit $id
295 drawcommit $id
296 if {$stopped} break
296 if {$stopped} break
297 if {[clock clicks -milliseconds] >= $nextupdate} {
297 if {[clock clicks -milliseconds] >= $nextupdate} {
298 doupdate 1
298 doupdate 1
299 }
299 }
300 }
300 }
301 }
301 }
302 }
302 }
303 }
303 }
304 }
304 }
305
305
306 proc doupdate {reading} {
306 proc doupdate {reading} {
307 global commfd nextupdate numcommits ncmupdate
307 global commfd nextupdate numcommits ncmupdate
308
308
309 if {$reading} {
309 if {$reading} {
310 fileevent $commfd readable {}
310 fileevent $commfd readable {}
311 }
311 }
312 update
312 update
313 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
313 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
314 if {$numcommits < 100} {
314 if {$numcommits < 100} {
315 set ncmupdate [expr {$numcommits + 1}]
315 set ncmupdate [expr {$numcommits + 1}]
316 } elseif {$numcommits < 10000} {
316 } elseif {$numcommits < 10000} {
317 set ncmupdate [expr {$numcommits + 10}]
317 set ncmupdate [expr {$numcommits + 10}]
318 } else {
318 } else {
319 set ncmupdate [expr {$numcommits + 100}]
319 set ncmupdate [expr {$numcommits + 100}]
320 }
320 }
321 if {$reading} {
321 if {$reading} {
322 fileevent $commfd readable [list getcommitlines $commfd]
322 fileevent $commfd readable [list getcommitlines $commfd]
323 }
323 }
324 }
324 }
325
325
326 proc readcommit {id} {
326 proc readcommit {id} {
327 global env
327 global env
328 if [catch {set contents [exec $env(HG) --config ui.report_untrusted=false debug-cat-file commit $id]}] return
328 if [catch {set contents [exec $env(HG) --config ui.report_untrusted=false debug-cat-file commit $id]}] return
329 parsecommit $id $contents 0 {}
329 parsecommit $id $contents 0 {}
330 }
330 }
331
331
332 proc parsecommit {id contents listed olds} {
332 proc parsecommit {id contents listed olds} {
333 global commitinfo children nchildren parents nparents cdate ncleft
333 global commitinfo children nchildren parents nparents cdate ncleft
334 global firstparents
334 global firstparents
335
335
336 set inhdr 1
336 set inhdr 1
337 set comment {}
337 set comment {}
338 set headline {}
338 set headline {}
339 set auname {}
339 set auname {}
340 set audate {}
340 set audate {}
341 set comname {}
341 set comname {}
342 set comdate {}
342 set comdate {}
343 set rev {}
343 set rev {}
344 set branch {}
344 set branch {}
345 set bookmark {}
345 set bookmark {}
346 if {![info exists nchildren($id)]} {
346 if {![info exists nchildren($id)]} {
347 set children($id) {}
347 set children($id) {}
348 set nchildren($id) 0
348 set nchildren($id) 0
349 set ncleft($id) 0
349 set ncleft($id) 0
350 }
350 }
351 set parents($id) $olds
351 set parents($id) $olds
352 set nparents($id) [llength $olds]
352 set nparents($id) [llength $olds]
353 foreach p $olds {
353 foreach p $olds {
354 if {![info exists nchildren($p)]} {
354 if {![info exists nchildren($p)]} {
355 set children($p) [list $id]
355 set children($p) [list $id]
356 set nchildren($p) 1
356 set nchildren($p) 1
357 set ncleft($p) 1
357 set ncleft($p) 1
358 } elseif {[lsearch -exact $children($p) $id] < 0} {
358 } elseif {[lsearch -exact $children($p) $id] < 0} {
359 lappend children($p) $id
359 lappend children($p) $id
360 incr nchildren($p)
360 incr nchildren($p)
361 incr ncleft($p)
361 incr ncleft($p)
362 }
362 }
363 }
363 }
364 regsub -all "\r\n" $contents "\n" contents
364 regsub -all "\r\n" $contents "\n" contents
365 foreach line [split $contents "\n"] {
365 foreach line [split $contents "\n"] {
366 if {$inhdr} {
366 if {$inhdr} {
367 set line [split $line]
367 set line [split $line]
368 if {$line == {}} {
368 if {$line == {}} {
369 set inhdr 0
369 set inhdr 0
370 } else {
370 } else {
371 set tag [lindex $line 0]
371 set tag [lindex $line 0]
372 if {$tag == "author"} {
372 if {$tag == "author"} {
373 set x [expr {[llength $line] - 2}]
373 set x [expr {[llength $line] - 2}]
374 set audate [lindex $line $x]
374 set audate [lindex $line $x]
375 set auname [join [lrange $line 1 [expr {$x - 1}]]]
375 set auname [join [lrange $line 1 [expr {$x - 1}]]]
376 } elseif {$tag == "committer"} {
376 } elseif {$tag == "committer"} {
377 set x [expr {[llength $line] - 2}]
377 set x [expr {[llength $line] - 2}]
378 set comdate [lindex $line $x]
378 set comdate [lindex $line $x]
379 set comname [join [lrange $line 1 [expr {$x - 1}]]]
379 set comname [join [lrange $line 1 [expr {$x - 1}]]]
380 } elseif {$tag == "revision"} {
380 } elseif {$tag == "revision"} {
381 set rev [lindex $line 1]
381 set rev [lindex $line 1]
382 } elseif {$tag == "branch"} {
382 } elseif {$tag == "branch"} {
383 set branch [join [lrange $line 1 end]]
383 set branch [join [lrange $line 1 end]]
384 } elseif {$tag == "bookmark"} {
384 } elseif {$tag == "bookmark"} {
385 set bookmark [join [lrange $line 1 end]]
385 set bookmark [join [lrange $line 1 end]]
386 }
386 }
387 }
387 }
388 } else {
388 } else {
389 if {$comment == {}} {
389 if {$comment == {}} {
390 set headline [string trim $line]
390 set headline [string trim $line]
391 } else {
391 } else {
392 append comment "\n"
392 append comment "\n"
393 }
393 }
394 if {!$listed} {
394 if {!$listed} {
395 # git-rev-list indents the comment by 4 spaces;
395 # git-rev-list indents the comment by 4 spaces;
396 # if we got this via git-cat-file, add the indentation
396 # if we got this via git-cat-file, add the indentation
397 append comment " "
397 append comment " "
398 }
398 }
399 append comment $line
399 append comment $line
400 }
400 }
401 }
401 }
402 if {$audate != {}} {
402 if {$audate != {}} {
403 set audate [clock format $audate]
403 set audate [clock format $audate]
404 }
404 }
405 if {$comdate != {}} {
405 if {$comdate != {}} {
406 set cdate($id) $comdate
406 set cdate($id) $comdate
407 set comdate [clock format $comdate]
407 set comdate [clock format $comdate]
408 }
408 }
409 set commitinfo($id) [list $headline $auname $audate \
409 set commitinfo($id) [list $headline $auname $audate \
410 $comname $comdate $comment $rev $branch $bookmark]
410 $comname $comdate $comment $rev $branch $bookmark]
411
411
412 if {[info exists firstparents]} {
412 if {[info exists firstparents]} {
413 set i [lsearch $firstparents $id]
413 set i [lsearch $firstparents $id]
414 if {$i != -1} {
414 if {$i != -1} {
415 # remove the parent from firstparents, possible building
415 # remove the parent from firstparents, possible building
416 # an empty list
416 # an empty list
417 set firstparents [concat \
417 set firstparents [concat \
418 [lrange $firstparents 0 [expr $i - 1]] \
418 [lrange $firstparents 0 [expr $i - 1]] \
419 [lrange $firstparents [expr $i + 1] end]]
419 [lrange $firstparents [expr $i + 1] end]]
420 if {$firstparents eq {}} {
420 if {$firstparents eq {}} {
421 # we have found all parents of the first changeset
421 # we have found all parents of the first changeset
422 # which means that we can safely select the first line
422 # which means that we can safely select the first line
423 after idle {
423 after idle {
424 selectline 0 0
424 selectline 0 0
425 }
425 }
426 }
426 }
427 }
427 }
428 } else {
428 } else {
429 # this is the first changeset, save the parents
429 # this is the first changeset, save the parents
430 set firstparents $olds
430 set firstparents $olds
431 if {$firstparents eq {}} {
431 if {$firstparents eq {}} {
432 # a repository with a single changeset
432 # a repository with a single changeset
433 after idle {
433 after idle {
434 selectline 0 0
434 selectline 0 0
435 }
435 }
436 }
436 }
437 }
437 }
438 }
438 }
439
439
440 proc readrefs {} {
440 proc readrefs {} {
441 global bookmarkcurrent bookmarkids tagids idtags idbookmarks headids idheads tagcontents env curid
441 global bookmarkcurrent bookmarkids tagids idtags idbookmarks headids idheads tagcontents env curid
442
442
443 set status [catch {exec $env(HG) --config ui.report_untrusted=false id} curid]
443 set status [catch {exec $env(HG) --config ui.report_untrusted=false id} curid]
444 if { $status != 0 } {
444 if { $status != 0 } {
445 puts $::errorInfo
445 puts $::errorInfo
446 if { ![string equal $::errorCode NONE] } {
446 if { ![string equal $::errorCode NONE] } {
447 exit 2
447 exit 2
448 }
448 }
449 }
449 }
450 regexp -- {[[:xdigit:]]+} $curid curid
450 regexp -- {[[:xdigit:]]+} $curid curid
451
451
452 set status [catch {exec $env(HG) --config ui.report_untrusted=false tags} tags]
452 set status [catch {exec $env(HG) --config ui.report_untrusted=false tags} tags]
453 if { $status != 0 } {
453 if { $status != 0 } {
454 puts $::errorInfo
454 puts $::errorInfo
455 if { ![string equal $::errorCode NONE] } {
455 if { ![string equal $::errorCode NONE] } {
456 exit 2
456 exit 2
457 }
457 }
458 }
458 }
459
459
460 foreach {tag rev} $tags {
460 foreach {tag rev} $tags {
461 # we use foreach as Tcl8.4 doesn't support lassign
461 # we use foreach as Tcl8.4 doesn't support lassign
462 foreach {- id} [split $rev :] {
462 foreach {- id} [split $rev :] {
463 lappend tagids($tag) $id
463 lappend tagids($tag) $id
464 lappend idtags($id) $tag
464 lappend idtags($id) $tag
465 }
465 }
466 }
466 }
467
467
468 set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads]
468 set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads]
469 if { $status != 0 } {
469 if { $status != 0 } {
470 puts $::errorInfo
470 puts $::errorInfo
471 if { ![string equal $::errorCode NONE] } {
471 if { ![string equal $::errorCode NONE] } {
472 exit 2
472 exit 2
473 }
473 }
474 }
474 }
475
475
476 set lines [split $heads \r\n]
476 set lines [split $heads \r\n]
477 foreach f $lines {
477 foreach f $lines {
478 set match ""
478 set match ""
479 regexp {changeset:\s+(\S+):(\S+)$} $f match id sha
479 regexp {changeset:\s+(\S+):(\S+)$} $f match id sha
480 if {$match != ""} {
480 if {$match != ""} {
481 lappend idheads($sha) $id
481 lappend idheads($sha) $id
482 }
482 }
483 }
483 }
484
484
485 set status [catch {exec $env(HG) --config ui.report_untrusted=false bookmarks} bookmarks]
485 set status [catch {exec $env(HG) --config ui.report_untrusted=false bookmarks} bookmarks]
486 if { $status != 0 } {
486 if { $status != 0 } {
487 puts $::errorInfo
487 puts $::errorInfo
488 if { ![string equal $::errorCode NONE] } {
488 if { ![string equal $::errorCode NONE] } {
489 exit 2
489 exit 2
490 }
490 }
491 }
491 }
492 set lines [split $bookmarks "\n"]
492 set lines [split $bookmarks "\n"]
493 set bookmarkcurrent 0
493 set bookmarkcurrent 0
494 foreach f $lines {
494 foreach f $lines {
495 regexp {(\S+)$} $f full
495 regexp {(\S+)$} $f full
496 regsub {\s+(\S+)$} $f "" direct
496 regsub {\s+(\S+)$} $f "" direct
497 set sha [split $full ':']
497 set sha [split $full ':']
498 set bookmark [lindex $sha 1]
498 set bookmark [lindex $sha 1]
499 set current [string first " * " $direct)]
499 set current [string first " * " $direct)]
500 regsub {^\s(\*|\s)\s} $direct "" direct
500 regsub {^\s(\*|\s)\s} $direct "" direct
501 lappend bookmarkids($direct) $bookmark
501 lappend bookmarkids($direct) $bookmark
502 lappend idbookmarks($bookmark) $direct
502 lappend idbookmarks($bookmark) $direct
503 if {$current >= 0} {
503 if {$current >= 0} {
504 set bookmarkcurrent $direct
504 set bookmarkcurrent $direct
505 }
505 }
506 }
506 }
507 }
507 }
508
508
509 proc readotherrefs {base dname excl} {
509 proc readotherrefs {base dname excl} {
510 global otherrefids idotherrefs
510 global otherrefids idotherrefs
511
511
512 set git [gitdir]
512 set git [gitdir]
513 set files [glob -nocomplain -types f [file join $git $base *]]
513 set files [glob -nocomplain -types f [file join $git $base *]]
514 foreach f $files {
514 foreach f $files {
515 catch {
515 catch {
516 set fd [open $f r]
516 set fd [open $f r]
517 set line [read $fd 40]
517 set line [read $fd 40]
518 if {[regexp {^[0-9a-f]{12}} $line id]} {
518 if {[regexp {^[0-9a-f]{12}} $line id]} {
519 set name "$dname[file tail $f]"
519 set name "$dname[file tail $f]"
520 set otherrefids($name) $id
520 set otherrefids($name) $id
521 lappend idotherrefs($id) $name
521 lappend idotherrefs($id) $name
522 }
522 }
523 close $fd
523 close $fd
524 }
524 }
525 }
525 }
526 set dirs [glob -nocomplain -types d [file join $git $base *]]
526 set dirs [glob -nocomplain -types d [file join $git $base *]]
527 foreach d $dirs {
527 foreach d $dirs {
528 set dir [file tail $d]
528 set dir [file tail $d]
529 if {[lsearch -exact $excl $dir] >= 0} continue
529 if {[lsearch -exact $excl $dir] >= 0} continue
530 readotherrefs [file join $base $dir] "$dname$dir/" {}
530 readotherrefs [file join $base $dir] "$dname$dir/" {}
531 }
531 }
532 }
532 }
533
533
534 proc allcansmousewheel {delta} {
534 proc allcansmousewheel {delta} {
535 set delta [expr -5*(int($delta)/abs($delta))]
535 set delta [expr -5*(int($delta)/abs($delta))]
536 allcanvs yview scroll $delta units
536 allcanvs yview scroll $delta units
537 }
537 }
538
538
539 proc error_popup msg {
539 proc error_popup msg {
540 set w .error
540 set w .error
541 toplevel $w
541 toplevel $w
542 wm transient $w .
542 wm transient $w .
543 message $w.m -text $msg -justify center -aspect 400
543 message $w.m -text $msg -justify center -aspect 400
544 pack $w.m -side top -fill x -padx 20 -pady 20
544 pack $w.m -side top -fill x -padx 20 -pady 20
545 ttk::button $w.ok -text OK -command "destroy $w"
545 ttk::button $w.ok -text OK -command "destroy $w"
546 pack $w.ok -side bottom -fill x
546 pack $w.ok -side bottom -fill x
547 bind $w <Visibility> "grab $w; focus $w"
547 bind $w <Visibility> "grab $w; focus $w"
548 popupify $w
548 popupify $w
549 tkwait window $w
549 tkwait window $w
550 }
550 }
551
551
552 proc makewindow {} {
552 proc makewindow {} {
553 global canv canv2 canv3 linespc charspc ctext cflist textfont
553 global canv canv2 canv3 linespc charspc ctext cflist textfont
554 global findtype findtypemenu findloc findstring fstring geometry
554 global findtype findtypemenu findloc findstring fstring geometry
555 global entries sha1entry sha1string sha1but
555 global entries sha1entry sha1string sha1but
556 global maincursor textcursor curtextcursor
556 global maincursor textcursor curtextcursor
557 global rowctxmenu gaudydiff mergemax
557 global rowctxmenu gaudydiff mergemax
558 global hgvdiff bgcolor fgcolor diffremcolor diffaddcolor diffmerge1color
558 global hgvdiff bgcolor fgcolor diffremcolor diffaddcolor diffmerge1color
559 global diffmerge2color hunksepcolor
559 global diffmerge2color hunksepcolor
560 global posx posy
560 global posx posy
561
561
562 if {[info exists posx]} {
562 if {[info exists posx]} {
563 wm geometry . +$posx+$posy
563 wm geometry . +$posx+$posy
564 }
564 }
565
565
566 menu .bar
566 menu .bar
567 .bar add cascade -label "File" -menu .bar.file
567 .bar add cascade -label "File" -menu .bar.file
568 menu .bar.file
568 menu .bar.file
569 .bar.file add command -label "Reread references" -command rereadrefs
569 .bar.file add command -label "Reread references" -command rereadrefs
570 .bar.file add command -label "Quit" -command doquit
570 .bar.file add command -label "Quit" -command doquit
571 menu .bar.help
571 menu .bar.help
572 .bar add cascade -label "Help" -menu .bar.help
572 .bar add cascade -label "Help" -menu .bar.help
573 .bar.help add command -label "About hgk" -command about
573 .bar.help add command -label "About hgk" -command about
574 . configure -menu .bar
574 . configure -menu .bar
575
575
576 if {![info exists geometry(canv1)]} {
576 if {![info exists geometry(canv1)]} {
577 set geometry(canv1) [expr 45 * $charspc]
577 set geometry(canv1) [expr 45 * $charspc]
578 set geometry(canv2) [expr 30 * $charspc]
578 set geometry(canv2) [expr 30 * $charspc]
579 set geometry(canv3) [expr 15 * $charspc]
579 set geometry(canv3) [expr 15 * $charspc]
580 set geometry(canvh) [expr 25 * $linespc + 4]
580 set geometry(canvh) [expr 25 * $linespc + 4]
581 set geometry(ctextw) 80
581 set geometry(ctextw) 80
582 set geometry(ctexth) 30
582 set geometry(ctexth) 30
583 set geometry(cflistw) 30
583 set geometry(cflistw) 30
584 }
584 }
585 panedwindow .ctop -orient vertical
585 panedwindow .ctop -orient vertical
586 if {[info exists geometry(width)]} {
586 if {[info exists geometry(width)]} {
587 .ctop conf -width $geometry(width) -height $geometry(height)
587 .ctop conf -width $geometry(width) -height $geometry(height)
588 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
588 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
589 set geometry(ctexth) [expr {($texth - 8) /
589 set geometry(ctexth) [expr {($texth - 8) /
590 [font metrics $textfont -linespace]}]
590 [font metrics $textfont -linespace]}]
591 }
591 }
592 ttk::frame .ctop.top
592 ttk::frame .ctop.top
593 ttk::frame .ctop.top.bar
593 ttk::frame .ctop.top.bar
594 pack .ctop.top.bar -side bottom -fill x
594 pack .ctop.top.bar -side bottom -fill x
595 set cscroll .ctop.top.csb
595 set cscroll .ctop.top.csb
596 ttk::scrollbar $cscroll -command {allcanvs yview}
596 ttk::scrollbar $cscroll -command {allcanvs yview}
597 pack $cscroll -side right -fill y
597 pack $cscroll -side right -fill y
598 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
598 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
599 pack .ctop.top.clist -side top -fill both -expand 1
599 pack .ctop.top.clist -side top -fill both -expand 1
600 .ctop add .ctop.top
600 .ctop add .ctop.top
601 set canv .ctop.top.clist.canv
601 set canv .ctop.top.clist.canv
602 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
602 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
603 -bg $bgcolor -bd 0 \
603 -bg $bgcolor -bd 0 \
604 -yscrollincr $linespc -yscrollcommand "$cscroll set" -selectbackground "#c0c0c0"
604 -yscrollincr $linespc -yscrollcommand "$cscroll set" -selectbackground "#c0c0c0"
605 .ctop.top.clist add $canv
605 .ctop.top.clist add $canv
606 set canv2 .ctop.top.clist.canv2
606 set canv2 .ctop.top.clist.canv2
607 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
607 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
608 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
608 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
609 .ctop.top.clist add $canv2
609 .ctop.top.clist add $canv2
610 set canv3 .ctop.top.clist.canv3
610 set canv3 .ctop.top.clist.canv3
611 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
611 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
612 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
612 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
613 .ctop.top.clist add $canv3
613 .ctop.top.clist add $canv3
614 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
614 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
615
615
616 set sha1entry .ctop.top.bar.sha1
616 set sha1entry .ctop.top.bar.sha1
617 set entries $sha1entry
617 set entries $sha1entry
618 set sha1but .ctop.top.bar.sha1label
618 set sha1but .ctop.top.bar.sha1label
619 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
619 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
620 -command gotocommit -width 8
620 -command gotocommit -width 8
621 $sha1but conf -disabledforeground [$sha1but cget -foreground]
621 $sha1but conf -disabledforeground [$sha1but cget -foreground]
622 pack .ctop.top.bar.sha1label -side left
622 pack .ctop.top.bar.sha1label -side left
623 ttk::entry $sha1entry -width 40 -font $textfont -textvariable sha1string
623 ttk::entry $sha1entry -width 40 -font $textfont -textvariable sha1string
624 trace add variable sha1string write sha1change
624 trace add variable sha1string write sha1change
625 pack $sha1entry -side left -pady 2
625 pack $sha1entry -side left -pady 2
626
626
627 image create bitmap bm-left -data {
627 image create bitmap bm-left -data {
628 #define left_width 16
628 #define left_width 16
629 #define left_height 16
629 #define left_height 16
630 static unsigned char left_bits[] = {
630 static unsigned char left_bits[] = {
631 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
631 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
632 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
632 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
633 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
633 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
634 }
634 }
635 image create bitmap bm-right -data {
635 image create bitmap bm-right -data {
636 #define right_width 16
636 #define right_width 16
637 #define right_height 16
637 #define right_height 16
638 static unsigned char right_bits[] = {
638 static unsigned char right_bits[] = {
639 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
639 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
640 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
640 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
641 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
641 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
642 }
642 }
643 ttk::button .ctop.top.bar.leftbut -image bm-left -command goback \
643 ttk::button .ctop.top.bar.leftbut -image bm-left -command goback \
644 -state disabled -width 26
644 -state disabled -width 26
645 pack .ctop.top.bar.leftbut -side left -fill y
645 pack .ctop.top.bar.leftbut -side left -fill y
646 ttk::button .ctop.top.bar.rightbut -image bm-right -command goforw \
646 ttk::button .ctop.top.bar.rightbut -image bm-right -command goforw \
647 -state disabled -width 26
647 -state disabled -width 26
648 pack .ctop.top.bar.rightbut -side left -fill y
648 pack .ctop.top.bar.rightbut -side left -fill y
649
649
650 ttk::button .ctop.top.bar.findbut -text "Find" -command dofind
650 ttk::button .ctop.top.bar.findbut -text "Find" -command dofind
651 pack .ctop.top.bar.findbut -side left
651 pack .ctop.top.bar.findbut -side left
652 set findstring {}
652 set findstring {}
653 set fstring .ctop.top.bar.findstring
653 set fstring .ctop.top.bar.findstring
654 lappend entries $fstring
654 lappend entries $fstring
655 ttk::entry $fstring -width 30 -font $textfont -textvariable findstring
655 ttk::entry $fstring -width 30 -font $textfont -textvariable findstring
656 pack $fstring -side left -expand 1 -fill x
656 pack $fstring -side left -expand 1 -fill x
657 set findtype Exact
657 set findtype Exact
658 set findtypemenu [ttk::optionMenu .ctop.top.bar.findtype \
658 set findtypemenu [ttk::optionMenu .ctop.top.bar.findtype \
659 findtype Exact IgnCase Regexp]
659 findtype Exact IgnCase Regexp]
660 set findloc "All fields"
660 set findloc "All fields"
661 ttk::optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
661 ttk::optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
662 Comments Author Files Pickaxe
662 Comments Author Files Pickaxe
663 pack .ctop.top.bar.findloc -side right
663 pack .ctop.top.bar.findloc -side right
664 pack .ctop.top.bar.findtype -side right
664 pack .ctop.top.bar.findtype -side right
665 # for making sure type==Exact whenever loc==Pickaxe
665 # for making sure type==Exact whenever loc==Pickaxe
666 trace add variable findloc write findlocchange
666 trace add variable findloc write findlocchange
667
667
668 panedwindow .ctop.cdet -orient horizontal
668 panedwindow .ctop.cdet -orient horizontal
669 .ctop add .ctop.cdet
669 .ctop add .ctop.cdet
670 ttk::frame .ctop.cdet.left
670 ttk::frame .ctop.cdet.left
671 set ctext .ctop.cdet.left.ctext
671 set ctext .ctop.cdet.left.ctext
672 text $ctext -fg $fgcolor -bg $bgcolor -state disabled -font $textfont \
672 text $ctext -fg $fgcolor -bg $bgcolor -state disabled -font $textfont \
673 -width $geometry(ctextw) -height $geometry(ctexth) \
673 -width $geometry(ctextw) -height $geometry(ctexth) \
674 -yscrollcommand ".ctop.cdet.left.sb set" \
674 -yscrollcommand ".ctop.cdet.left.sb set" \
675 -xscrollcommand ".ctop.cdet.left.hb set" -wrap none
675 -xscrollcommand ".ctop.cdet.left.hb set" -wrap none
676 ttk::scrollbar .ctop.cdet.left.sb -command "$ctext yview"
676 ttk::scrollbar .ctop.cdet.left.sb -command "$ctext yview"
677 ttk::scrollbar .ctop.cdet.left.hb -orient horizontal -command "$ctext xview"
677 ttk::scrollbar .ctop.cdet.left.hb -orient horizontal -command "$ctext xview"
678 pack .ctop.cdet.left.sb -side right -fill y
678 pack .ctop.cdet.left.sb -side right -fill y
679 pack .ctop.cdet.left.hb -side bottom -fill x
679 pack .ctop.cdet.left.hb -side bottom -fill x
680 pack $ctext -side left -fill both -expand 1
680 pack $ctext -side left -fill both -expand 1
681 .ctop.cdet add .ctop.cdet.left
681 .ctop.cdet add .ctop.cdet.left
682
682
683 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
683 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
684 if {$gaudydiff} {
684 if {$gaudydiff} {
685 $ctext tag conf hunksep -back blue -fore white
685 $ctext tag conf hunksep -back blue -fore white
686 $ctext tag conf d0 -back "#ff8080"
686 $ctext tag conf d0 -back "#ff8080"
687 $ctext tag conf d1 -back green
687 $ctext tag conf d1 -back green
688 } else {
688 } else {
689 $ctext tag conf hunksep -fore $hunksepcolor
689 $ctext tag conf hunksep -fore $hunksepcolor
690 $ctext tag conf d0 -fore $diffremcolor
690 $ctext tag conf d0 -fore $diffremcolor
691 $ctext tag conf d1 -fore $diffaddcolor
691 $ctext tag conf d1 -fore $diffaddcolor
692
692
693 # The mX colours seem to be used in merge changesets, where m0
693 # The mX colours seem to be used in merge changesets, where m0
694 # is first parent, m1 is second parent and so on. Git can have
694 # is first parent, m1 is second parent and so on. Git can have
695 # several parents, Hg cannot, so I think the m2..mmax would be
695 # several parents, Hg cannot, so I think the m2..mmax would be
696 # unused.
696 # unused.
697 $ctext tag conf m0 -fore $diffmerge1color
697 $ctext tag conf m0 -fore $diffmerge1color
698 $ctext tag conf m1 -fore $diffmerge2color
698 $ctext tag conf m1 -fore $diffmerge2color
699 $ctext tag conf m2 -fore green
699 $ctext tag conf m2 -fore green
700 $ctext tag conf m3 -fore purple
700 $ctext tag conf m3 -fore purple
701 $ctext tag conf m4 -fore brown
701 $ctext tag conf m4 -fore brown
702 $ctext tag conf mmax -fore darkgrey
702 $ctext tag conf mmax -fore darkgrey
703 set mergemax 5
703 set mergemax 5
704 $ctext tag conf mresult -font [concat $textfont bold]
704 $ctext tag conf mresult -font [concat $textfont bold]
705 $ctext tag conf msep -font [concat $textfont bold]
705 $ctext tag conf msep -font [concat $textfont bold]
706 $ctext tag conf found -back yellow
706 $ctext tag conf found -back yellow
707 }
707 }
708
708
709 ttk::frame .ctop.cdet.right
709 ttk::frame .ctop.cdet.right
710 set cflist .ctop.cdet.right.cfiles
710 set cflist .ctop.cdet.right.cfiles
711 listbox $cflist -fg $fgcolor -bg $bgcolor \
711 listbox $cflist -fg $fgcolor -bg $bgcolor \
712 -selectmode extended -width $geometry(cflistw) \
712 -selectmode extended -width $geometry(cflistw) \
713 -yscrollcommand ".ctop.cdet.right.sb set"
713 -yscrollcommand ".ctop.cdet.right.sb set"
714 ttk::scrollbar .ctop.cdet.right.sb -command "$cflist yview"
714 ttk::scrollbar .ctop.cdet.right.sb -command "$cflist yview"
715 pack .ctop.cdet.right.sb -side right -fill y
715 pack .ctop.cdet.right.sb -side right -fill y
716 pack $cflist -side left -fill both -expand 1
716 pack $cflist -side left -fill both -expand 1
717 .ctop.cdet add .ctop.cdet.right
717 .ctop.cdet add .ctop.cdet.right
718 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
718 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
719
719
720 pack .ctop -side top -fill both -expand 1
720 pack .ctop -side top -fill both -expand 1
721
721
722 bindall <1> {selcanvline %W %x %y}
722 bindall <1> {selcanvline %W %x %y}
723 #bindall <B1-Motion> {selcanvline %W %x %y}
723 #bindall <B1-Motion> {selcanvline %W %x %y}
724 bindall <MouseWheel> "allcansmousewheel %D"
724 bindall <MouseWheel> "allcansmousewheel %D"
725 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
725 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
726 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
726 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
727 bindall <2> "allcanvs scan mark 0 %y"
727 bindall <2> "allcanvs scan mark 0 %y"
728 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
728 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
729 bind . <Key-Up> "selnextline -1"
729 bind . <Key-Up> "selnextline -1"
730 bind . <Key-Down> "selnextline 1"
730 bind . <Key-Down> "selnextline 1"
731 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
731 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
732 bind . <Key-Next> "allcanvs yview scroll 1 pages"
732 bind . <Key-Next> "allcanvs yview scroll 1 pages"
733 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
733 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
734 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
734 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
735 bindkey <Key-space> "$ctext yview scroll 1 pages"
735 bindkey <Key-space> "$ctext yview scroll 1 pages"
736 bindkey p "selnextline -1"
736 bindkey p "selnextline -1"
737 bindkey n "selnextline 1"
737 bindkey n "selnextline 1"
738 bindkey b "$ctext yview scroll -1 pages"
738 bindkey b "$ctext yview scroll -1 pages"
739 bindkey d "$ctext yview scroll 18 units"
739 bindkey d "$ctext yview scroll 18 units"
740 bindkey u "$ctext yview scroll -18 units"
740 bindkey u "$ctext yview scroll -18 units"
741 bindkey / {findnext 1}
741 bindkey / {findnext 1}
742 bindkey <Key-Return> {findnext 0}
742 bindkey <Key-Return> {findnext 0}
743 bindkey ? findprev
743 bindkey ? findprev
744 bindkey f nextfile
744 bindkey f nextfile
745 bind . <Control-q> doquit
745 bind . <Control-q> doquit
746 bind . <Control-w> doquit
746 bind . <Control-w> doquit
747 bind . <Control-f> dofind
747 bind . <Control-f> dofind
748 bind . <Control-g> {findnext 0}
748 bind . <Control-g> {findnext 0}
749 bind . <Control-r> findprev
749 bind . <Control-r> findprev
750 bind . <Control-equal> {incrfont 1}
750 bind . <Control-equal> {incrfont 1}
751 bind . <Control-KP_Add> {incrfont 1}
751 bind . <Control-KP_Add> {incrfont 1}
752 bind . <Control-minus> {incrfont -1}
752 bind . <Control-minus> {incrfont -1}
753 bind . <Control-KP_Subtract> {incrfont -1}
753 bind . <Control-KP_Subtract> {incrfont -1}
754 bind $cflist <<ListboxSelect>> listboxsel
754 bind $cflist <<ListboxSelect>> listboxsel
755 bind . <Destroy> {savestuff %W}
755 bind . <Destroy> {savestuff %W}
756 bind . <Button-1> "click %W"
756 bind . <Button-1> "click %W"
757 bind $fstring <Key-Return> dofind
757 bind $fstring <Key-Return> dofind
758 bind $sha1entry <Key-Return> gotocommit
758 bind $sha1entry <Key-Return> gotocommit
759 bind $sha1entry <<PasteSelection>> clearsha1
759 bind $sha1entry <<PasteSelection>> clearsha1
760
760
761 set maincursor [. cget -cursor]
761 set maincursor [. cget -cursor]
762 set textcursor [$ctext cget -cursor]
762 set textcursor [$ctext cget -cursor]
763 set curtextcursor $textcursor
763 set curtextcursor $textcursor
764
764
765 set rowctxmenu .rowctxmenu
765 set rowctxmenu .rowctxmenu
766 menu $rowctxmenu -tearoff 0
766 menu $rowctxmenu -tearoff 0
767 $rowctxmenu add command -label "Diff this -> selected" \
767 $rowctxmenu add command -label "Diff this -> selected" \
768 -command {diffvssel 0}
768 -command {diffvssel 0}
769 $rowctxmenu add command -label "Diff selected -> this" \
769 $rowctxmenu add command -label "Diff selected -> this" \
770 -command {diffvssel 1}
770 -command {diffvssel 1}
771 $rowctxmenu add command -label "Make patch" -command mkpatch
771 $rowctxmenu add command -label "Make patch" -command mkpatch
772 $rowctxmenu add command -label "Create tag" -command mktag
772 $rowctxmenu add command -label "Create tag" -command mktag
773 $rowctxmenu add command -label "Write commit to file" -command writecommit
773 $rowctxmenu add command -label "Write commit to file" -command writecommit
774 if { $hgvdiff ne "" } {
774 if { $hgvdiff ne "" } {
775 $rowctxmenu add command -label "Visual diff with parent" \
775 $rowctxmenu add command -label "Visual diff with parent" \
776 -command {vdiff 1}
776 -command {vdiff 1}
777 $rowctxmenu add command -label "Visual diff with selected" \
777 $rowctxmenu add command -label "Visual diff with selected" \
778 -command {vdiff 0}
778 -command {vdiff 0}
779 }
779 }
780 }
780 }
781
781
782 # when we make a key binding for the toplevel, make sure
782 # when we make a key binding for the toplevel, make sure
783 # it doesn't get triggered when that key is pressed in the
783 # it doesn't get triggered when that key is pressed in the
784 # find string entry widget.
784 # find string entry widget.
785 proc bindkey {ev script} {
785 proc bindkey {ev script} {
786 global entries
786 global entries
787 bind . $ev $script
787 bind . $ev $script
788 set escript [bind Entry $ev]
788 set escript [bind Entry $ev]
789 if {$escript == {}} {
789 if {$escript == {}} {
790 set escript [bind Entry <Key>]
790 set escript [bind Entry <Key>]
791 }
791 }
792 foreach e $entries {
792 foreach e $entries {
793 bind $e $ev "$escript; break"
793 bind $e $ev "$escript; break"
794 }
794 }
795 }
795 }
796
796
797 # set the focus back to the toplevel for any click outside
797 # set the focus back to the toplevel for any click outside
798 # the entry widgets
798 # the entry widgets
799 proc click {w} {
799 proc click {w} {
800 global entries
800 global entries
801 foreach e $entries {
801 foreach e $entries {
802 if {$w == $e} return
802 if {$w == $e} return
803 }
803 }
804 focus .
804 focus .
805 }
805 }
806
806
807 proc savestuff {w} {
807 proc savestuff {w} {
808 global canv canv2 canv3 ctext cflist mainfont textfont
808 global canv canv2 canv3 ctext cflist mainfont textfont
809 global stuffsaved findmergefiles gaudydiff maxgraphpct
809 global stuffsaved findmergefiles gaudydiff maxgraphpct
810 global maxwidth authorcolors curidfont bgcolor fgcolor
810 global maxwidth authorcolors curidfont bgcolor fgcolor
811 global diffremcolor diffaddcolor hunksepcolor
811 global diffremcolor diffaddcolor hunksepcolor
812 global diffmerge1color diffmerge2color
812 global diffmerge1color diffmerge2color
813
813
814 if {$stuffsaved} return
814 if {$stuffsaved} return
815 if {![winfo viewable .]} return
815 if {![winfo viewable .]} return
816 catch {
816 catch {
817 set f [open "~/.hgk-new" w]
817 set f [open "~/.hgk-new" w]
818 puts $f [list set mainfont $mainfont]
818 puts $f [list set mainfont $mainfont]
819 puts $f [list set curidfont $curidfont]
819 puts $f [list set curidfont $curidfont]
820 puts $f [list set textfont $textfont]
820 puts $f [list set textfont $textfont]
821 puts $f [list set findmergefiles $findmergefiles]
821 puts $f [list set findmergefiles $findmergefiles]
822 puts $f [list set gaudydiff $gaudydiff]
822 puts $f [list set gaudydiff $gaudydiff]
823 puts $f [list set maxgraphpct $maxgraphpct]
823 puts $f [list set maxgraphpct $maxgraphpct]
824 puts $f [list set maxwidth $maxwidth]
824 puts $f [list set maxwidth $maxwidth]
825 puts $f "set geometry(width) [winfo width .ctop]"
825 puts $f "set geometry(width) [winfo width .ctop]"
826 puts $f "set geometry(height) [winfo height .ctop]"
826 puts $f "set geometry(height) [winfo height .ctop]"
827 puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
827 puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
828 puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
828 puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
829 puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
829 puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
830 puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
830 puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
831 set wid [expr {([winfo width $ctext] - 8) \
831 set wid [expr {([winfo width $ctext] - 8) \
832 / [font measure $textfont "0"]}]
832 / [font measure $textfont "0"]}]
833 puts $f "set geometry(ctextw) $wid"
833 puts $f "set geometry(ctextw) $wid"
834 set wid [expr {([winfo width $cflist] - 11) \
834 set wid [expr {([winfo width $cflist] - 11) \
835 / [font measure [$cflist cget -font] "0"]}]
835 / [font measure [$cflist cget -font] "0"]}]
836 puts $f "set geometry(cflistw) $wid"
836 puts $f "set geometry(cflistw) $wid"
837 puts $f "#"
837 puts $f "#"
838 puts $f "# main window position:"
838 puts $f "# main window position:"
839 puts $f "set posx [winfo x .]"
839 puts $f "set posx [winfo x .]"
840 puts $f "set posy [winfo y .]"
840 puts $f "set posy [winfo y .]"
841 puts $f "#"
841 puts $f "#"
842 puts $f "# authorcolors format:"
842 puts $f "# authorcolors format:"
843 puts $f "#"
843 puts $f "#"
844 puts $f "# zero or more sublists of"
844 puts $f "# zero or more sublists of"
845 puts $f "#"
845 puts $f "#"
846 puts $f "# { regex color }"
846 puts $f "# { regex color }"
847 puts $f "#"
847 puts $f "#"
848 puts $f "# followed by a list of colors"
848 puts $f "# followed by a list of colors"
849 puts $f "#"
849 puts $f "#"
850 puts $f "# If the commit author matches a regex in a sublist,"
850 puts $f "# If the commit author matches a regex in a sublist,"
851 puts $f "# the commit will be colored by that color"
851 puts $f "# the commit will be colored by that color"
852 puts $f "# otherwise the next unused entry from the list of colors"
852 puts $f "# otherwise the next unused entry from the list of colors"
853 puts $f "# will be assigned to this commit and also all other commits"
853 puts $f "# will be assigned to this commit and also all other commits"
854 puts $f "# of the same author. When the list of colors is exhausted,"
854 puts $f "# of the same author. When the list of colors is exhausted,"
855 puts $f "# the last entry will be reused."
855 puts $f "# the last entry will be reused."
856 puts $f "#"
856 puts $f "#"
857 puts $f "set authorcolors {$authorcolors}"
857 puts $f "set authorcolors {$authorcolors}"
858 puts $f "#"
858 puts $f "#"
859 puts $f "# The background color in the text windows"
859 puts $f "# The background color in the text windows"
860 puts $f "set bgcolor $bgcolor"
860 puts $f "set bgcolor $bgcolor"
861 puts $f "#"
861 puts $f "#"
862 puts $f "# The text color used in the diff and file list view"
862 puts $f "# The text color used in the diff and file list view"
863 puts $f "set fgcolor $fgcolor"
863 puts $f "set fgcolor $fgcolor"
864 puts $f "#"
864 puts $f "#"
865 puts $f "# Color to display + lines in diffs"
865 puts $f "# Color to display + lines in diffs"
866 puts $f "set diffaddcolor $diffaddcolor"
866 puts $f "set diffaddcolor $diffaddcolor"
867 puts $f "#"
867 puts $f "#"
868 puts $f "# Color to display - lines in diffs"
868 puts $f "# Color to display - lines in diffs"
869 puts $f "set diffremcolor $diffremcolor"
869 puts $f "set diffremcolor $diffremcolor"
870 puts $f "#"
870 puts $f "#"
871 puts $f "# Merge diffs: Color to signal lines from first parent"
871 puts $f "# Merge diffs: Color to signal lines from first parent"
872 puts $f "set diffmerge1color $diffmerge1color"
872 puts $f "set diffmerge1color $diffmerge1color"
873 puts $f "#"
873 puts $f "#"
874 puts $f "# Merge diffs: Color to signal lines from second parent"
874 puts $f "# Merge diffs: Color to signal lines from second parent"
875 puts $f "set diffmerge2color $diffmerge2color"
875 puts $f "set diffmerge2color $diffmerge2color"
876 puts $f "#"
876 puts $f "#"
877 puts $f "# Hunkseparator (@@ -lineno,lines +lineno,lines @@) color"
877 puts $f "# Hunkseparator (@@ -lineno,lines +lineno,lines @@) color"
878 puts $f "set hunksepcolor $hunksepcolor"
878 puts $f "set hunksepcolor $hunksepcolor"
879 close $f
879 close $f
880 file rename -force "~/.hgk-new" "~/.hgk"
880 file rename -force "~/.hgk-new" "~/.hgk"
881 }
881 }
882 set stuffsaved 1
882 set stuffsaved 1
883 }
883 }
884
884
885 proc resizeclistpanes {win w} {
885 proc resizeclistpanes {win w} {
886 global oldwidth
886 global oldwidth
887 if [info exists oldwidth($win)] {
887 if [info exists oldwidth($win)] {
888 set s0 [$win sash coord 0]
888 set s0 [$win sash coord 0]
889 set s1 [$win sash coord 1]
889 set s1 [$win sash coord 1]
890 if {$w < 60} {
890 if {$w < 60} {
891 set sash0 [expr {int($w/2 - 2)}]
891 set sash0 [expr {int($w/2 - 2)}]
892 set sash1 [expr {int($w*5/6 - 2)}]
892 set sash1 [expr {int($w*5/6 - 2)}]
893 } else {
893 } else {
894 set factor [expr {1.0 * $w / $oldwidth($win)}]
894 set factor [expr {1.0 * $w / $oldwidth($win)}]
895 set sash0 [expr {int($factor * [lindex $s0 0])}]
895 set sash0 [expr {int($factor * [lindex $s0 0])}]
896 set sash1 [expr {int($factor * [lindex $s1 0])}]
896 set sash1 [expr {int($factor * [lindex $s1 0])}]
897 if {$sash0 < 30} {
897 if {$sash0 < 30} {
898 set sash0 30
898 set sash0 30
899 }
899 }
900 if {$sash1 < $sash0 + 20} {
900 if {$sash1 < $sash0 + 20} {
901 set sash1 [expr $sash0 + 20]
901 set sash1 [expr $sash0 + 20]
902 }
902 }
903 if {$sash1 > $w - 10} {
903 if {$sash1 > $w - 10} {
904 set sash1 [expr $w - 10]
904 set sash1 [expr $w - 10]
905 if {$sash0 > $sash1 - 20} {
905 if {$sash0 > $sash1 - 20} {
906 set sash0 [expr $sash1 - 20]
906 set sash0 [expr $sash1 - 20]
907 }
907 }
908 }
908 }
909 }
909 }
910 $win sash place 0 $sash0 [lindex $s0 1]
910 $win sash place 0 $sash0 [lindex $s0 1]
911 $win sash place 1 $sash1 [lindex $s1 1]
911 $win sash place 1 $sash1 [lindex $s1 1]
912 }
912 }
913 set oldwidth($win) $w
913 set oldwidth($win) $w
914 }
914 }
915
915
916 proc resizecdetpanes {win w} {
916 proc resizecdetpanes {win w} {
917 global oldwidth
917 global oldwidth
918 if [info exists oldwidth($win)] {
918 if [info exists oldwidth($win)] {
919 set s0 [$win sash coord 0]
919 set s0 [$win sash coord 0]
920 if {$w < 60} {
920 if {$w < 60} {
921 set sash0 [expr {int($w*3/4 - 2)}]
921 set sash0 [expr {int($w*3/4 - 2)}]
922 } else {
922 } else {
923 set factor [expr {1.0 * $w / $oldwidth($win)}]
923 set factor [expr {1.0 * $w / $oldwidth($win)}]
924 set sash0 [expr {int($factor * [lindex $s0 0])}]
924 set sash0 [expr {int($factor * [lindex $s0 0])}]
925 if {$sash0 < 45} {
925 if {$sash0 < 45} {
926 set sash0 45
926 set sash0 45
927 }
927 }
928 if {$sash0 > $w - 15} {
928 if {$sash0 > $w - 15} {
929 set sash0 [expr $w - 15]
929 set sash0 [expr $w - 15]
930 }
930 }
931 }
931 }
932 $win sash place 0 $sash0 [lindex $s0 1]
932 $win sash place 0 $sash0 [lindex $s0 1]
933 }
933 }
934 set oldwidth($win) $w
934 set oldwidth($win) $w
935 }
935 }
936
936
937 proc allcanvs args {
937 proc allcanvs args {
938 global canv canv2 canv3
938 global canv canv2 canv3
939 eval $canv $args
939 eval $canv $args
940 eval $canv2 $args
940 eval $canv2 $args
941 eval $canv3 $args
941 eval $canv3 $args
942 }
942 }
943
943
944 proc bindall {event action} {
944 proc bindall {event action} {
945 global canv canv2 canv3
945 global canv canv2 canv3
946 bind $canv $event $action
946 bind $canv $event $action
947 bind $canv2 $event $action
947 bind $canv2 $event $action
948 bind $canv3 $event $action
948 bind $canv3 $event $action
949 }
949 }
950
950
951 proc about {} {
951 proc about {} {
952 set w .about
952 set w .about
953 if {[winfo exists $w]} {
953 if {[winfo exists $w]} {
954 raise $w
954 raise $w
955 return
955 return
956 }
956 }
957 toplevel $w
957 toplevel $w
958 wm title $w "About hgk"
958 wm title $w "About hgk"
959 message $w.m -text {
959 message $w.m -text {
960 Hgk version 1.2
960 Hgk version 1.2
961
961
962 Copyright � 2005 Paul Mackerras
962 Copyright � 2005 Paul Mackerras
963
963
964 Use and redistribute under the terms of the GNU General Public License} \
964 Use and redistribute under the terms of the GNU General Public License} \
965 -justify center -aspect 400
965 -justify center -aspect 400
966 pack $w.m -side top -fill x -padx 20 -pady 20
966 pack $w.m -side top -fill x -padx 20 -pady 20
967 ttk::button $w.ok -text Close -command "destroy $w"
967 ttk::button $w.ok -text Close -command "destroy $w"
968 pack $w.ok -side bottom
968 pack $w.ok -side bottom
969 popupify $w
969 popupify $w
970 }
970 }
971
971
972 set aunextcolor 0
972 set aunextcolor 0
973 proc assignauthorcolor {name} {
973 proc assignauthorcolor {name} {
974 global authorcolors aucolormap aunextcolor
974 global authorcolors aucolormap aunextcolor
975 if [info exists aucolormap($name)] return
975 if [info exists aucolormap($name)] return
976
976
977 set randomcolors {black}
977 set randomcolors {black}
978 for {set i 0} {$i < [llength $authorcolors]} {incr i} {
978 for {set i 0} {$i < [llength $authorcolors]} {incr i} {
979 set col [lindex $authorcolors $i]
979 set col [lindex $authorcolors $i]
980 if {[llength $col] > 1} {
980 if {[llength $col] > 1} {
981 set re [lindex $col 0]
981 set re [lindex $col 0]
982 set c [lindex $col 1]
982 set c [lindex $col 1]
983 if {[regexp -- $re $name]} {
983 if {[regexp -- $re $name]} {
984 set aucolormap($name) $c
984 set aucolormap($name) $c
985 return
985 return
986 }
986 }
987 } else {
987 } else {
988 set randomcolors [lrange $authorcolors $i end]
988 set randomcolors [lrange $authorcolors $i end]
989 break
989 break
990 }
990 }
991 }
991 }
992
992
993 set ncolors [llength $randomcolors]
993 set ncolors [llength $randomcolors]
994 set c [lindex $randomcolors $aunextcolor]
994 set c [lindex $randomcolors $aunextcolor]
995 if {[incr aunextcolor] >= $ncolors} {
995 if {[incr aunextcolor] >= $ncolors} {
996 incr aunextcolor -1
996 incr aunextcolor -1
997 }
997 }
998 set aucolormap($name) $c
998 set aucolormap($name) $c
999 }
999 }
1000
1000
1001 proc assigncolor {id} {
1001 proc assigncolor {id} {
1002 global commitinfo colormap commcolors colors nextcolor
1002 global commitinfo colormap commcolors colors nextcolor
1003 global parents nparents children nchildren
1003 global parents nparents children nchildren
1004 global cornercrossings crossings
1004 global cornercrossings crossings
1005
1005
1006 if [info exists colormap($id)] return
1006 if [info exists colormap($id)] return
1007 set ncolors [llength $colors]
1007 set ncolors [llength $colors]
1008 if {$nparents($id) <= 1 && $nchildren($id) == 1} {
1008 if {$nparents($id) <= 1 && $nchildren($id) == 1} {
1009 set child [lindex $children($id) 0]
1009 set child [lindex $children($id) 0]
1010 if {[info exists colormap($child)]
1010 if {[info exists colormap($child)]
1011 && $nparents($child) == 1} {
1011 && $nparents($child) == 1} {
1012 set colormap($id) $colormap($child)
1012 set colormap($id) $colormap($child)
1013 return
1013 return
1014 }
1014 }
1015 }
1015 }
1016 set badcolors {}
1016 set badcolors {}
1017 if {[info exists cornercrossings($id)]} {
1017 if {[info exists cornercrossings($id)]} {
1018 foreach x $cornercrossings($id) {
1018 foreach x $cornercrossings($id) {
1019 if {[info exists colormap($x)]
1019 if {[info exists colormap($x)]
1020 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1020 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1021 lappend badcolors $colormap($x)
1021 lappend badcolors $colormap($x)
1022 }
1022 }
1023 }
1023 }
1024 if {[llength $badcolors] >= $ncolors} {
1024 if {[llength $badcolors] >= $ncolors} {
1025 set badcolors {}
1025 set badcolors {}
1026 }
1026 }
1027 }
1027 }
1028 set origbad $badcolors
1028 set origbad $badcolors
1029 if {[llength $badcolors] < $ncolors - 1} {
1029 if {[llength $badcolors] < $ncolors - 1} {
1030 if {[info exists crossings($id)]} {
1030 if {[info exists crossings($id)]} {
1031 foreach x $crossings($id) {
1031 foreach x $crossings($id) {
1032 if {[info exists colormap($x)]
1032 if {[info exists colormap($x)]
1033 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1033 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1034 lappend badcolors $colormap($x)
1034 lappend badcolors $colormap($x)
1035 }
1035 }
1036 }
1036 }
1037 if {[llength $badcolors] >= $ncolors} {
1037 if {[llength $badcolors] >= $ncolors} {
1038 set badcolors $origbad
1038 set badcolors $origbad
1039 }
1039 }
1040 }
1040 }
1041 set origbad $badcolors
1041 set origbad $badcolors
1042 }
1042 }
1043 if {[llength $badcolors] < $ncolors - 1} {
1043 if {[llength $badcolors] < $ncolors - 1} {
1044 foreach child $children($id) {
1044 foreach child $children($id) {
1045 if {[info exists colormap($child)]
1045 if {[info exists colormap($child)]
1046 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1046 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1047 lappend badcolors $colormap($child)
1047 lappend badcolors $colormap($child)
1048 }
1048 }
1049 if {[info exists parents($child)]} {
1049 if {[info exists parents($child)]} {
1050 foreach p $parents($child) {
1050 foreach p $parents($child) {
1051 if {[info exists colormap($p)]
1051 if {[info exists colormap($p)]
1052 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1052 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1053 lappend badcolors $colormap($p)
1053 lappend badcolors $colormap($p)
1054 }
1054 }
1055 }
1055 }
1056 }
1056 }
1057 }
1057 }
1058 if {[llength $badcolors] >= $ncolors} {
1058 if {[llength $badcolors] >= $ncolors} {
1059 set badcolors $origbad
1059 set badcolors $origbad
1060 }
1060 }
1061 }
1061 }
1062 for {set i 0} {$i <= $ncolors} {incr i} {
1062 for {set i 0} {$i <= $ncolors} {incr i} {
1063 set c [lindex $colors $nextcolor]
1063 set c [lindex $colors $nextcolor]
1064 if {[incr nextcolor] >= $ncolors} {
1064 if {[incr nextcolor] >= $ncolors} {
1065 set nextcolor 0
1065 set nextcolor 0
1066 }
1066 }
1067 if {[lsearch -exact $badcolors $c]} break
1067 if {[lsearch -exact $badcolors $c]} break
1068 }
1068 }
1069 set colormap($id) $c
1069 set colormap($id) $c
1070 }
1070 }
1071
1071
1072 proc initgraph {} {
1072 proc initgraph {} {
1073 global canvy canvy0 lineno numcommits nextcolor linespc
1073 global canvy canvy0 lineno numcommits nextcolor linespc
1074 global mainline mainlinearrow sidelines
1074 global mainline mainlinearrow sidelines
1075 global nchildren ncleft
1075 global nchildren ncleft
1076 global displist nhyperspace
1076 global displist nhyperspace
1077
1077
1078 allcanvs delete all
1078 allcanvs delete all
1079 set nextcolor 0
1079 set nextcolor 0
1080 set canvy $canvy0
1080 set canvy $canvy0
1081 set lineno -1
1081 set lineno -1
1082 set numcommits 0
1082 set numcommits 0
1083 catch {unset mainline}
1083 catch {unset mainline}
1084 catch {unset mainlinearrow}
1084 catch {unset mainlinearrow}
1085 catch {unset sidelines}
1085 catch {unset sidelines}
1086 foreach id [array names nchildren] {
1086 foreach id [array names nchildren] {
1087 set ncleft($id) $nchildren($id)
1087 set ncleft($id) $nchildren($id)
1088 }
1088 }
1089 set displist {}
1089 set displist {}
1090 set nhyperspace 0
1090 set nhyperspace 0
1091 }
1091 }
1092
1092
1093 proc bindline {t id} {
1093 proc bindline {t id} {
1094 global canv
1094 global canv
1095
1095
1096 $canv bind $t <Enter> "lineenter %x %y $id"
1096 $canv bind $t <Enter> "lineenter %x %y $id"
1097 $canv bind $t <Motion> "linemotion %x %y $id"
1097 $canv bind $t <Motion> "linemotion %x %y $id"
1098 $canv bind $t <Leave> "lineleave $id"
1098 $canv bind $t <Leave> "lineleave $id"
1099 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1099 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1100 }
1100 }
1101
1101
1102 proc drawlines {id xtra} {
1102 proc drawlines {id xtra} {
1103 global mainline mainlinearrow sidelines lthickness colormap canv
1103 global mainline mainlinearrow sidelines lthickness colormap canv
1104
1104
1105 $canv delete lines.$id
1105 $canv delete lines.$id
1106 if {[info exists mainline($id)]} {
1106 if {[info exists mainline($id)]} {
1107 set t [$canv create line $mainline($id) \
1107 set t [$canv create line $mainline($id) \
1108 -width [expr {($xtra + 1) * $lthickness}] \
1108 -width [expr {($xtra + 1) * $lthickness}] \
1109 -fill $colormap($id) -tags lines.$id \
1109 -fill $colormap($id) -tags lines.$id \
1110 -arrow $mainlinearrow($id)]
1110 -arrow $mainlinearrow($id)]
1111 $canv lower $t
1111 $canv lower $t
1112 bindline $t $id
1112 bindline $t $id
1113 }
1113 }
1114 if {[info exists sidelines($id)]} {
1114 if {[info exists sidelines($id)]} {
1115 foreach ls $sidelines($id) {
1115 foreach ls $sidelines($id) {
1116 set coords [lindex $ls 0]
1116 set coords [lindex $ls 0]
1117 set thick [lindex $ls 1]
1117 set thick [lindex $ls 1]
1118 set arrow [lindex $ls 2]
1118 set arrow [lindex $ls 2]
1119 set t [$canv create line $coords -fill $colormap($id) \
1119 set t [$canv create line $coords -fill $colormap($id) \
1120 -width [expr {($thick + $xtra) * $lthickness}] \
1120 -width [expr {($thick + $xtra) * $lthickness}] \
1121 -arrow $arrow -tags lines.$id]
1121 -arrow $arrow -tags lines.$id]
1122 $canv lower $t
1122 $canv lower $t
1123 bindline $t $id
1123 bindline $t $id
1124 }
1124 }
1125 }
1125 }
1126 }
1126 }
1127
1127
1128 # level here is an index in displist
1128 # level here is an index in displist
1129 proc drawcommitline {level} {
1129 proc drawcommitline {level} {
1130 global parents children nparents displist
1130 global parents children nparents displist
1131 global canv canv2 canv3 mainfont namefont canvy linespc
1131 global canv canv2 canv3 mainfont namefont canvy linespc
1132 global lineid linehtag linentag linedtag commitinfo
1132 global lineid linehtag linentag linedtag commitinfo
1133 global colormap numcommits currentparents dupparents
1133 global colormap numcommits currentparents dupparents
1134 global idtags idline idheads idotherrefs idbookmarks
1134 global idtags idline idheads idotherrefs idbookmarks
1135 global lineno lthickness mainline mainlinearrow sidelines
1135 global lineno lthickness mainline mainlinearrow sidelines
1136 global commitlisted rowtextx idpos lastuse displist
1136 global commitlisted rowtextx idpos lastuse displist
1137 global oldnlines olddlevel olddisplist
1137 global oldnlines olddlevel olddisplist
1138 global aucolormap curid curidfont
1138 global aucolormap curid curidfont
1139
1139
1140 incr numcommits
1140 incr numcommits
1141 incr lineno
1141 incr lineno
1142 set id [lindex $displist $level]
1142 set id [lindex $displist $level]
1143 set lastuse($id) $lineno
1143 set lastuse($id) $lineno
1144 set lineid($lineno) $id
1144 set lineid($lineno) $id
1145 set idline($id) $lineno
1145 set idline($id) $lineno
1146 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
1146 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
1147 if {![info exists commitinfo($id)]} {
1147 if {![info exists commitinfo($id)]} {
1148 readcommit $id
1148 readcommit $id
1149 if {![info exists commitinfo($id)]} {
1149 if {![info exists commitinfo($id)]} {
1150 set commitinfo($id) {"No commit information available"}
1150 set commitinfo($id) {"No commit information available"}
1151 set nparents($id) 0
1151 set nparents($id) 0
1152 }
1152 }
1153 }
1153 }
1154 assigncolor $id
1154 assigncolor $id
1155 set currentparents {}
1155 set currentparents {}
1156 set dupparents {}
1156 set dupparents {}
1157 if {[info exists commitlisted($id)] && [info exists parents($id)]} {
1157 if {[info exists commitlisted($id)] && [info exists parents($id)]} {
1158 foreach p $parents($id) {
1158 foreach p $parents($id) {
1159 if {[lsearch -exact $currentparents $p] < 0} {
1159 if {[lsearch -exact $currentparents $p] < 0} {
1160 lappend currentparents $p
1160 lappend currentparents $p
1161 } else {
1161 } else {
1162 # remember that this parent was listed twice
1162 # remember that this parent was listed twice
1163 lappend dupparents $p
1163 lappend dupparents $p
1164 }
1164 }
1165 }
1165 }
1166 }
1166 }
1167 set x [xcoord $level $level $lineno]
1167 set x [xcoord $level $level $lineno]
1168 set y1 $canvy
1168 set y1 $canvy
1169 set canvy [expr $canvy + $linespc]
1169 set canvy [expr $canvy + $linespc]
1170 allcanvs conf -scrollregion \
1170 allcanvs conf -scrollregion \
1171 [list 0 0 0 [expr $y1 + 0.5 * $linespc + 2]]
1171 [list 0 0 0 [expr $y1 + 0.5 * $linespc + 2]]
1172 if {[info exists mainline($id)]} {
1172 if {[info exists mainline($id)]} {
1173 lappend mainline($id) $x $y1
1173 lappend mainline($id) $x $y1
1174 if {$mainlinearrow($id) ne "none"} {
1174 if {$mainlinearrow($id) ne "none"} {
1175 set mainline($id) [trimdiagstart $mainline($id)]
1175 set mainline($id) [trimdiagstart $mainline($id)]
1176 }
1176 }
1177 }
1177 }
1178 drawlines $id 0
1178 drawlines $id 0
1179 set orad [expr {$linespc / 3}]
1179 set orad [expr {$linespc / 3}]
1180 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
1180 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
1181 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
1181 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
1182 -fill $ofill -outline black -width 1]
1182 -fill $ofill -outline black -width 1]
1183 $canv raise $t
1183 $canv raise $t
1184 $canv bind $t <1> {selcanvline {} %x %y}
1184 $canv bind $t <1> {selcanvline {} %x %y}
1185 set xt [xcoord [llength $displist] $level $lineno]
1185 set xt [xcoord [llength $displist] $level $lineno]
1186 if {[llength $currentparents] > 2} {
1186 if {[llength $currentparents] > 2} {
1187 set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
1187 set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
1188 }
1188 }
1189 set rowtextx($lineno) $xt
1189 set rowtextx($lineno) $xt
1190 set idpos($id) [list $x $xt $y1]
1190 set idpos($id) [list $x $xt $y1]
1191 if {[info exists idtags($id)] || [info exists idheads($id)]
1191 if {[info exists idtags($id)] || [info exists idheads($id)]
1192 || [info exists idotherrefs($id)] || [info exists idbookmarks($id)]} {
1192 || [info exists idotherrefs($id)] || [info exists idbookmarks($id)]} {
1193 set xt [drawtags $id $x $xt $y1]
1193 set xt [drawtags $id $x $xt $y1]
1194 }
1194 }
1195 set headline [lindex $commitinfo($id) 0]
1195 set headline [lindex $commitinfo($id) 0]
1196 set name [lindex $commitinfo($id) 1]
1196 set name [lindex $commitinfo($id) 1]
1197 assignauthorcolor $name
1197 assignauthorcolor $name
1198 set fg $aucolormap($name)
1198 set fg $aucolormap($name)
1199 if {$id == $curid} {
1199 if {$id == $curid} {
1200 set fn $curidfont
1200 set fn $curidfont
1201 } else {
1201 } else {
1202 set fn $mainfont
1202 set fn $mainfont
1203 }
1203 }
1204
1204
1205 set date [lindex $commitinfo($id) 2]
1205 set date [lindex $commitinfo($id) 2]
1206 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
1206 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
1207 -text $headline -font $fn \
1207 -text $headline -font $fn \
1208 -fill $fg]
1208 -fill $fg]
1209 $canv bind $linehtag($lineno) <<B3>> "rowmenu %X %Y $id"
1209 $canv bind $linehtag($lineno) <<B3>> "rowmenu %X %Y $id"
1210 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
1210 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
1211 -text $name -font $namefont \
1211 -text $name -font $namefont \
1212 -fill $fg]
1212 -fill $fg]
1213 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
1213 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
1214 -text $date -font $mainfont \
1214 -text $date -font $mainfont \
1215 -fill $fg]
1215 -fill $fg]
1216
1216
1217 set olddlevel $level
1217 set olddlevel $level
1218 set olddisplist $displist
1218 set olddisplist $displist
1219 set oldnlines [llength $displist]
1219 set oldnlines [llength $displist]
1220 }
1220 }
1221
1221
1222 proc drawtags {id x xt y1} {
1222 proc drawtags {id x xt y1} {
1223 global bookmarkcurrent idtags idbookmarks idheads idotherrefs commitinfo
1223 global bookmarkcurrent idtags idbookmarks idheads idotherrefs commitinfo
1224 global linespc lthickness
1224 global linespc lthickness
1225 global canv mainfont idline rowtextx
1225 global canv mainfont idline rowtextx
1226
1226
1227 set marks {}
1227 set marks {}
1228 set nbookmarks 0
1228 set nbookmarks 0
1229 set ntags 0
1229 set ntags 0
1230 set nheads 0
1230 set nheads 0
1231 if {[info exists idtags($id)]} {
1231 if {[info exists idtags($id)]} {
1232 set marks $idtags($id)
1232 set marks $idtags($id)
1233 set ntags [llength $marks]
1233 set ntags [llength $marks]
1234 }
1234 }
1235 if {[info exists idbookmarks($id)]} {
1235 if {[info exists idbookmarks($id)]} {
1236 set marks [concat $marks $idbookmarks($id)]
1236 set marks [concat $marks $idbookmarks($id)]
1237 set nbookmarks [llength $idbookmarks($id)]
1237 set nbookmarks [llength $idbookmarks($id)]
1238 }
1238 }
1239 if {[info exists idheads($id)]} {
1239 if {[info exists idheads($id)]} {
1240 set headmark [lindex $commitinfo($id) 7]
1240 set headmark [lindex $commitinfo($id) 7]
1241 if {$headmark ne "default"} {
1241 if {$headmark ne "default"} {
1242 lappend marks $headmark
1242 lappend marks $headmark
1243 set nheads 1
1243 set nheads 1
1244 }
1244 }
1245 }
1245 }
1246 if {$marks eq {}} {
1246 if {$marks eq {}} {
1247 return $xt
1247 return $xt
1248 }
1248 }
1249
1249
1250 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1250 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1251 set yt [expr $y1 - 0.5 * $linespc]
1251 set yt [expr $y1 - 0.5 * $linespc]
1252 set yb [expr $yt + $linespc - 1]
1252 set yb [expr $yt + $linespc - 1]
1253 set xvals {}
1253 set xvals {}
1254 set wvals {}
1254 set wvals {}
1255 foreach tag $marks {
1255 foreach tag $marks {
1256 set wid [font measure $mainfont $tag]
1256 set wid [font measure $mainfont $tag]
1257 lappend xvals $xt
1257 lappend xvals $xt
1258 lappend wvals $wid
1258 lappend wvals $wid
1259 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1259 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1260 }
1260 }
1261 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1261 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1262 -width $lthickness -fill black -tags tag.$id]
1262 -width $lthickness -fill black -tags tag.$id]
1263 $canv lower $t
1263 $canv lower $t
1264 foreach tag $marks x $xvals wid $wvals {
1264 foreach tag $marks x $xvals wid $wvals {
1265 set xl [expr $x + $delta]
1265 set xl [expr $x + $delta]
1266 set xr [expr $x + $delta + $wid + $lthickness]
1266 set xr [expr $x + $delta + $wid + $lthickness]
1267 if {[incr ntags -1] >= 0} {
1267 if {[incr ntags -1] >= 0} {
1268 # draw a tag
1268 # draw a tag
1269 set t [$canv create polygon $x [expr $yt + $delta] $xl $yt \
1269 set t [$canv create polygon $x [expr $yt + $delta] $xl $yt \
1270 $xr $yt $xr $yb $xl $yb $x [expr $yb - $delta] \
1270 $xr $yt $xr $yb $xl $yb $x [expr $yb - $delta] \
1271 -width 1 -outline black -fill yellow -tags tag.$id]
1271 -width 1 -outline black -fill yellow -tags tag.$id]
1272 $canv bind $t <1> [list showtag $tag 1]
1272 $canv bind $t <1> [list showtag $tag 1]
1273 set rowtextx($idline($id)) [expr {$xr + $linespc}]
1273 set rowtextx($idline($id)) [expr {$xr + $linespc}]
1274 } elseif {[incr nbookmarks -1] >= 0} {
1274 } elseif {[incr nbookmarks -1] >= 0} {
1275 # draw a tag
1275 # draw a tag
1276 set col gray50
1276 set col gray50
1277 if {[string compare $bookmarkcurrent $tag] == 0} {
1277 if {[string compare $bookmarkcurrent $tag] == 0} {
1278 set col gray
1278 set col gray
1279 }
1279 }
1280 set xl [expr $xl - $delta/2]
1280 set xl [expr $xl - $delta/2]
1281 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1281 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1282 -width 1 -outline black -fill $col -tags tag.$id
1282 -width 1 -outline black -fill $col -tags tag.$id
1283 } else {
1283 } else {
1284 # draw a head or other ref
1284 # draw a head or other ref
1285 if {[incr nheads -1] >= 0} {
1285 if {[incr nheads -1] >= 0} {
1286 set col "#00ff00"
1286 set col "#00ff00"
1287 } else {
1287 } else {
1288 set col "#ddddff"
1288 set col "#ddddff"
1289 }
1289 }
1290 set xl [expr $xl - $delta/2]
1290 set xl [expr $xl - $delta/2]
1291 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1291 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1292 -width 1 -outline black -fill $col -tags tag.$id
1292 -width 1 -outline black -fill $col -tags tag.$id
1293 }
1293 }
1294 set t [$canv create text $xl $y1 -anchor w -text $tag \
1294 set t [$canv create text $xl $y1 -anchor w -text $tag \
1295 -font $mainfont -tags tag.$id]
1295 -font $mainfont -tags tag.$id]
1296 if {$ntags >= 0} {
1296 if {$ntags >= 0} {
1297 $canv bind $t <1> [list showtag $tag 1]
1297 $canv bind $t <1> [list showtag $tag 1]
1298 }
1298 }
1299 }
1299 }
1300 return $xt
1300 return $xt
1301 }
1301 }
1302
1302
1303 proc notecrossings {id lo hi corner} {
1303 proc notecrossings {id lo hi corner} {
1304 global olddisplist crossings cornercrossings
1304 global olddisplist crossings cornercrossings
1305
1305
1306 for {set i $lo} {[incr i] < $hi} {} {
1306 for {set i $lo} {[incr i] < $hi} {} {
1307 set p [lindex $olddisplist $i]
1307 set p [lindex $olddisplist $i]
1308 if {$p == {}} continue
1308 if {$p == {}} continue
1309 if {$i == $corner} {
1309 if {$i == $corner} {
1310 if {![info exists cornercrossings($id)]
1310 if {![info exists cornercrossings($id)]
1311 || [lsearch -exact $cornercrossings($id) $p] < 0} {
1311 || [lsearch -exact $cornercrossings($id) $p] < 0} {
1312 lappend cornercrossings($id) $p
1312 lappend cornercrossings($id) $p
1313 }
1313 }
1314 if {![info exists cornercrossings($p)]
1314 if {![info exists cornercrossings($p)]
1315 || [lsearch -exact $cornercrossings($p) $id] < 0} {
1315 || [lsearch -exact $cornercrossings($p) $id] < 0} {
1316 lappend cornercrossings($p) $id
1316 lappend cornercrossings($p) $id
1317 }
1317 }
1318 } else {
1318 } else {
1319 if {![info exists crossings($id)]
1319 if {![info exists crossings($id)]
1320 || [lsearch -exact $crossings($id) $p] < 0} {
1320 || [lsearch -exact $crossings($id) $p] < 0} {
1321 lappend crossings($id) $p
1321 lappend crossings($id) $p
1322 }
1322 }
1323 if {![info exists crossings($p)]
1323 if {![info exists crossings($p)]
1324 || [lsearch -exact $crossings($p) $id] < 0} {
1324 || [lsearch -exact $crossings($p) $id] < 0} {
1325 lappend crossings($p) $id
1325 lappend crossings($p) $id
1326 }
1326 }
1327 }
1327 }
1328 }
1328 }
1329 }
1329 }
1330
1330
1331 proc xcoord {i level ln} {
1331 proc xcoord {i level ln} {
1332 global canvx0 xspc1 xspc2
1332 global canvx0 xspc1 xspc2
1333
1333
1334 set x [expr {$canvx0 + $i * $xspc1($ln)}]
1334 set x [expr {$canvx0 + $i * $xspc1($ln)}]
1335 if {$i > 0 && $i == $level} {
1335 if {$i > 0 && $i == $level} {
1336 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
1336 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
1337 } elseif {$i > $level} {
1337 } elseif {$i > $level} {
1338 set x [expr {$x + $xspc2 - $xspc1($ln)}]
1338 set x [expr {$x + $xspc2 - $xspc1($ln)}]
1339 }
1339 }
1340 return $x
1340 return $x
1341 }
1341 }
1342
1342
1343 # it seems Tk can't draw arrows on the end of diagonal line segments...
1343 # it seems Tk can't draw arrows on the end of diagonal line segments...
1344 proc trimdiagend {line} {
1344 proc trimdiagend {line} {
1345 while {[llength $line] > 4} {
1345 while {[llength $line] > 4} {
1346 set x1 [lindex $line end-3]
1346 set x1 [lindex $line end-3]
1347 set y1 [lindex $line end-2]
1347 set y1 [lindex $line end-2]
1348 set x2 [lindex $line end-1]
1348 set x2 [lindex $line end-1]
1349 set y2 [lindex $line end]
1349 set y2 [lindex $line end]
1350 if {($x1 == $x2) != ($y1 == $y2)} break
1350 if {($x1 == $x2) != ($y1 == $y2)} break
1351 set line [lreplace $line end-1 end]
1351 set line [lreplace $line end-1 end]
1352 }
1352 }
1353 return $line
1353 return $line
1354 }
1354 }
1355
1355
1356 proc trimdiagstart {line} {
1356 proc trimdiagstart {line} {
1357 while {[llength $line] > 4} {
1357 while {[llength $line] > 4} {
1358 set x1 [lindex $line 0]
1358 set x1 [lindex $line 0]
1359 set y1 [lindex $line 1]
1359 set y1 [lindex $line 1]
1360 set x2 [lindex $line 2]
1360 set x2 [lindex $line 2]
1361 set y2 [lindex $line 3]
1361 set y2 [lindex $line 3]
1362 if {($x1 == $x2) != ($y1 == $y2)} break
1362 if {($x1 == $x2) != ($y1 == $y2)} break
1363 set line [lreplace $line 0 1]
1363 set line [lreplace $line 0 1]
1364 }
1364 }
1365 return $line
1365 return $line
1366 }
1366 }
1367
1367
1368 proc drawslants {id needonscreen nohs} {
1368 proc drawslants {id needonscreen nohs} {
1369 global canv mainline mainlinearrow sidelines
1369 global canv mainline mainlinearrow sidelines
1370 global canvx0 canvy xspc1 xspc2 lthickness
1370 global canvx0 canvy xspc1 xspc2 lthickness
1371 global currentparents dupparents
1371 global currentparents dupparents
1372 global lthickness linespc canvy colormap lineno geometry
1372 global lthickness linespc canvy colormap lineno geometry
1373 global maxgraphpct maxwidth
1373 global maxgraphpct maxwidth
1374 global displist onscreen lastuse
1374 global displist onscreen lastuse
1375 global parents commitlisted
1375 global parents commitlisted
1376 global oldnlines olddlevel olddisplist
1376 global oldnlines olddlevel olddisplist
1377 global nhyperspace numcommits nnewparents
1377 global nhyperspace numcommits nnewparents
1378
1378
1379 if {$lineno < 0} {
1379 if {$lineno < 0} {
1380 lappend displist $id
1380 lappend displist $id
1381 set onscreen($id) 1
1381 set onscreen($id) 1
1382 return 0
1382 return 0
1383 }
1383 }
1384
1384
1385 set y1 [expr {$canvy - $linespc}]
1385 set y1 [expr {$canvy - $linespc}]
1386 set y2 $canvy
1386 set y2 $canvy
1387
1387
1388 # work out what we need to get back on screen
1388 # work out what we need to get back on screen
1389 set reins {}
1389 set reins {}
1390 if {$onscreen($id) < 0} {
1390 if {$onscreen($id) < 0} {
1391 # next to do isn't displayed, better get it on screen...
1391 # next to do isn't displayed, better get it on screen...
1392 lappend reins [list $id 0]
1392 lappend reins [list $id 0]
1393 }
1393 }
1394 # make sure all the previous commits's parents are on the screen
1394 # make sure all the previous commits's parents are on the screen
1395 foreach p $currentparents {
1395 foreach p $currentparents {
1396 if {$onscreen($p) < 0} {
1396 if {$onscreen($p) < 0} {
1397 lappend reins [list $p 0]
1397 lappend reins [list $p 0]
1398 }
1398 }
1399 }
1399 }
1400 # bring back anything requested by caller
1400 # bring back anything requested by caller
1401 if {$needonscreen ne {}} {
1401 if {$needonscreen ne {}} {
1402 lappend reins $needonscreen
1402 lappend reins $needonscreen
1403 }
1403 }
1404
1404
1405 # try the shortcut
1405 # try the shortcut
1406 if {$currentparents == $id && $onscreen($id) == 0 && $reins eq {}} {
1406 if {$currentparents == $id && $onscreen($id) == 0 && $reins eq {}} {
1407 set dlevel $olddlevel
1407 set dlevel $olddlevel
1408 set x [xcoord $dlevel $dlevel $lineno]
1408 set x [xcoord $dlevel $dlevel $lineno]
1409 set mainline($id) [list $x $y1]
1409 set mainline($id) [list $x $y1]
1410 set mainlinearrow($id) none
1410 set mainlinearrow($id) none
1411 set lastuse($id) $lineno
1411 set lastuse($id) $lineno
1412 set displist [lreplace $displist $dlevel $dlevel $id]
1412 set displist [lreplace $displist $dlevel $dlevel $id]
1413 set onscreen($id) 1
1413 set onscreen($id) 1
1414 set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
1414 set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
1415 return $dlevel
1415 return $dlevel
1416 }
1416 }
1417
1417
1418 # update displist
1418 # update displist
1419 set displist [lreplace $displist $olddlevel $olddlevel]
1419 set displist [lreplace $displist $olddlevel $olddlevel]
1420 set j $olddlevel
1420 set j $olddlevel
1421 foreach p $currentparents {
1421 foreach p $currentparents {
1422 set lastuse($p) $lineno
1422 set lastuse($p) $lineno
1423 if {$onscreen($p) == 0} {
1423 if {$onscreen($p) == 0} {
1424 set displist [linsert $displist $j $p]
1424 set displist [linsert $displist $j $p]
1425 set onscreen($p) 1
1425 set onscreen($p) 1
1426 incr j
1426 incr j
1427 }
1427 }
1428 }
1428 }
1429 if {$onscreen($id) == 0} {
1429 if {$onscreen($id) == 0} {
1430 lappend displist $id
1430 lappend displist $id
1431 set onscreen($id) 1
1431 set onscreen($id) 1
1432 }
1432 }
1433
1433
1434 # remove the null entry if present
1434 # remove the null entry if present
1435 set nullentry [lsearch -exact $displist {}]
1435 set nullentry [lsearch -exact $displist {}]
1436 if {$nullentry >= 0} {
1436 if {$nullentry >= 0} {
1437 set displist [lreplace $displist $nullentry $nullentry]
1437 set displist [lreplace $displist $nullentry $nullentry]
1438 }
1438 }
1439
1439
1440 # bring back the ones we need now (if we did it earlier
1440 # bring back the ones we need now (if we did it earlier
1441 # it would change displist and invalidate olddlevel)
1441 # it would change displist and invalidate olddlevel)
1442 foreach pi $reins {
1442 foreach pi $reins {
1443 # test again in case of duplicates in reins
1443 # test again in case of duplicates in reins
1444 set p [lindex $pi 0]
1444 set p [lindex $pi 0]
1445 if {$onscreen($p) < 0} {
1445 if {$onscreen($p) < 0} {
1446 set onscreen($p) 1
1446 set onscreen($p) 1
1447 set lastuse($p) $lineno
1447 set lastuse($p) $lineno
1448 set displist [linsert $displist [lindex $pi 1] $p]
1448 set displist [linsert $displist [lindex $pi 1] $p]
1449 incr nhyperspace -1
1449 incr nhyperspace -1
1450 }
1450 }
1451 }
1451 }
1452
1452
1453 set lastuse($id) $lineno
1453 set lastuse($id) $lineno
1454
1454
1455 # see if we need to make any lines jump off into hyperspace
1455 # see if we need to make any lines jump off into hyperspace
1456 set displ [llength $displist]
1456 set displ [llength $displist]
1457 if {$displ > $maxwidth} {
1457 if {$displ > $maxwidth} {
1458 set ages {}
1458 set ages {}
1459 foreach x $displist {
1459 foreach x $displist {
1460 lappend ages [list $lastuse($x) $x]
1460 lappend ages [list $lastuse($x) $x]
1461 }
1461 }
1462 set ages [lsort -integer -index 0 $ages]
1462 set ages [lsort -integer -index 0 $ages]
1463 set k 0
1463 set k 0
1464 while {$displ > $maxwidth} {
1464 while {$displ > $maxwidth} {
1465 set use [lindex $ages $k 0]
1465 set use [lindex $ages $k 0]
1466 set victim [lindex $ages $k 1]
1466 set victim [lindex $ages $k 1]
1467 if {$use >= $lineno - 5} break
1467 if {$use >= $lineno - 5} break
1468 incr k
1468 incr k
1469 if {[lsearch -exact $nohs $victim] >= 0} continue
1469 if {[lsearch -exact $nohs $victim] >= 0} continue
1470 set i [lsearch -exact $displist $victim]
1470 set i [lsearch -exact $displist $victim]
1471 set displist [lreplace $displist $i $i]
1471 set displist [lreplace $displist $i $i]
1472 set onscreen($victim) -1
1472 set onscreen($victim) -1
1473 incr nhyperspace
1473 incr nhyperspace
1474 incr displ -1
1474 incr displ -1
1475 if {$i < $nullentry} {
1475 if {$i < $nullentry} {
1476 incr nullentry -1
1476 incr nullentry -1
1477 }
1477 }
1478 set x [lindex $mainline($victim) end-1]
1478 set x [lindex $mainline($victim) end-1]
1479 lappend mainline($victim) $x $y1
1479 lappend mainline($victim) $x $y1
1480 set line [trimdiagend $mainline($victim)]
1480 set line [trimdiagend $mainline($victim)]
1481 set arrow "last"
1481 set arrow "last"
1482 if {$mainlinearrow($victim) ne "none"} {
1482 if {$mainlinearrow($victim) ne "none"} {
1483 set line [trimdiagstart $line]
1483 set line [trimdiagstart $line]
1484 set arrow "both"
1484 set arrow "both"
1485 }
1485 }
1486 lappend sidelines($victim) [list $line 1 $arrow]
1486 lappend sidelines($victim) [list $line 1 $arrow]
1487 unset mainline($victim)
1487 unset mainline($victim)
1488 }
1488 }
1489 }
1489 }
1490
1490
1491 set dlevel [lsearch -exact $displist $id]
1491 set dlevel [lsearch -exact $displist $id]
1492
1492
1493 # If we are reducing, put in a null entry
1493 # If we are reducing, put in a null entry
1494 if {$displ < $oldnlines} {
1494 if {$displ < $oldnlines} {
1495 # does the next line look like a merge?
1495 # does the next line look like a merge?
1496 # i.e. does it have > 1 new parent?
1496 # i.e. does it have > 1 new parent?
1497 if {$nnewparents($id) > 1} {
1497 if {$nnewparents($id) > 1} {
1498 set i [expr {$dlevel + 1}]
1498 set i [expr {$dlevel + 1}]
1499 } elseif {$nnewparents([lindex $olddisplist $olddlevel]) == 0} {
1499 } elseif {$nnewparents([lindex $olddisplist $olddlevel]) == 0} {
1500 set i $olddlevel
1500 set i $olddlevel
1501 if {$nullentry >= 0 && $nullentry < $i} {
1501 if {$nullentry >= 0 && $nullentry < $i} {
1502 incr i -1
1502 incr i -1
1503 }
1503 }
1504 } elseif {$nullentry >= 0} {
1504 } elseif {$nullentry >= 0} {
1505 set i $nullentry
1505 set i $nullentry
1506 while {$i < $displ
1506 while {$i < $displ
1507 && [lindex $olddisplist $i] == [lindex $displist $i]} {
1507 && [lindex $olddisplist $i] == [lindex $displist $i]} {
1508 incr i
1508 incr i
1509 }
1509 }
1510 } else {
1510 } else {
1511 set i $olddlevel
1511 set i $olddlevel
1512 if {$dlevel >= $i} {
1512 if {$dlevel >= $i} {
1513 incr i
1513 incr i
1514 }
1514 }
1515 }
1515 }
1516 if {$i < $displ} {
1516 if {$i < $displ} {
1517 set displist [linsert $displist $i {}]
1517 set displist [linsert $displist $i {}]
1518 incr displ
1518 incr displ
1519 if {$dlevel >= $i} {
1519 if {$dlevel >= $i} {
1520 incr dlevel
1520 incr dlevel
1521 }
1521 }
1522 }
1522 }
1523 }
1523 }
1524
1524
1525 # decide on the line spacing for the next line
1525 # decide on the line spacing for the next line
1526 set lj [expr {$lineno + 1}]
1526 set lj [expr {$lineno + 1}]
1527 set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
1527 set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
1528 if {$displ <= 1 || $canvx0 + $displ * $xspc2 <= $maxw} {
1528 if {$displ <= 1 || $canvx0 + $displ * $xspc2 <= $maxw} {
1529 set xspc1($lj) $xspc2
1529 set xspc1($lj) $xspc2
1530 } else {
1530 } else {
1531 set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($displ - 1)}]
1531 set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($displ - 1)}]
1532 if {$xspc1($lj) < $lthickness} {
1532 if {$xspc1($lj) < $lthickness} {
1533 set xspc1($lj) $lthickness
1533 set xspc1($lj) $lthickness
1534 }
1534 }
1535 }
1535 }
1536
1536
1537 foreach idi $reins {
1537 foreach idi $reins {
1538 set id [lindex $idi 0]
1538 set id [lindex $idi 0]
1539 set j [lsearch -exact $displist $id]
1539 set j [lsearch -exact $displist $id]
1540 set xj [xcoord $j $dlevel $lj]
1540 set xj [xcoord $j $dlevel $lj]
1541 set mainline($id) [list $xj $y2]
1541 set mainline($id) [list $xj $y2]
1542 set mainlinearrow($id) first
1542 set mainlinearrow($id) first
1543 }
1543 }
1544
1544
1545 set i -1
1545 set i -1
1546 foreach id $olddisplist {
1546 foreach id $olddisplist {
1547 incr i
1547 incr i
1548 if {$id == {}} continue
1548 if {$id == {}} continue
1549 if {$onscreen($id) <= 0} continue
1549 if {$onscreen($id) <= 0} continue
1550 set xi [xcoord $i $olddlevel $lineno]
1550 set xi [xcoord $i $olddlevel $lineno]
1551 if {$i == $olddlevel} {
1551 if {$i == $olddlevel} {
1552 foreach p $currentparents {
1552 foreach p $currentparents {
1553 set j [lsearch -exact $displist $p]
1553 set j [lsearch -exact $displist $p]
1554 set coords [list $xi $y1]
1554 set coords [list $xi $y1]
1555 set xj [xcoord $j $dlevel $lj]
1555 set xj [xcoord $j $dlevel $lj]
1556 if {$xj < $xi - $linespc} {
1556 if {$xj < $xi - $linespc} {
1557 lappend coords [expr {$xj + $linespc}] $y1
1557 lappend coords [expr {$xj + $linespc}] $y1
1558 notecrossings $p $j $i [expr {$j + 1}]
1558 notecrossings $p $j $i [expr {$j + 1}]
1559 } elseif {$xj > $xi + $linespc} {
1559 } elseif {$xj > $xi + $linespc} {
1560 lappend coords [expr {$xj - $linespc}] $y1
1560 lappend coords [expr {$xj - $linespc}] $y1
1561 notecrossings $p $i $j [expr {$j - 1}]
1561 notecrossings $p $i $j [expr {$j - 1}]
1562 }
1562 }
1563 if {[lsearch -exact $dupparents $p] >= 0} {
1563 if {[lsearch -exact $dupparents $p] >= 0} {
1564 # draw a double-width line to indicate the doubled parent
1564 # draw a double-width line to indicate the doubled parent
1565 lappend coords $xj $y2
1565 lappend coords $xj $y2
1566 lappend sidelines($p) [list $coords 2 none]
1566 lappend sidelines($p) [list $coords 2 none]
1567 if {![info exists mainline($p)]} {
1567 if {![info exists mainline($p)]} {
1568 set mainline($p) [list $xj $y2]
1568 set mainline($p) [list $xj $y2]
1569 set mainlinearrow($p) none
1569 set mainlinearrow($p) none
1570 }
1570 }
1571 } else {
1571 } else {
1572 # normal case, no parent duplicated
1572 # normal case, no parent duplicated
1573 set yb $y2
1573 set yb $y2
1574 set dx [expr {abs($xi - $xj)}]
1574 set dx [expr {abs($xi - $xj)}]
1575 if {0 && $dx < $linespc} {
1575 if {0 && $dx < $linespc} {
1576 set yb [expr {$y1 + $dx}]
1576 set yb [expr {$y1 + $dx}]
1577 }
1577 }
1578 if {![info exists mainline($p)]} {
1578 if {![info exists mainline($p)]} {
1579 if {$xi != $xj} {
1579 if {$xi != $xj} {
1580 lappend coords $xj $yb
1580 lappend coords $xj $yb
1581 }
1581 }
1582 set mainline($p) $coords
1582 set mainline($p) $coords
1583 set mainlinearrow($p) none
1583 set mainlinearrow($p) none
1584 } else {
1584 } else {
1585 lappend coords $xj $yb
1585 lappend coords $xj $yb
1586 if {$yb < $y2} {
1586 if {$yb < $y2} {
1587 lappend coords $xj $y2
1587 lappend coords $xj $y2
1588 }
1588 }
1589 lappend sidelines($p) [list $coords 1 none]
1589 lappend sidelines($p) [list $coords 1 none]
1590 }
1590 }
1591 }
1591 }
1592 }
1592 }
1593 } else {
1593 } else {
1594 set j $i
1594 set j $i
1595 if {[lindex $displist $i] != $id} {
1595 if {[lindex $displist $i] != $id} {
1596 set j [lsearch -exact $displist $id]
1596 set j [lsearch -exact $displist $id]
1597 }
1597 }
1598 if {$j != $i || $xspc1($lineno) != $xspc1($lj)
1598 if {$j != $i || $xspc1($lineno) != $xspc1($lj)
1599 || ($olddlevel < $i && $i < $dlevel)
1599 || ($olddlevel < $i && $i < $dlevel)
1600 || ($dlevel < $i && $i < $olddlevel)} {
1600 || ($dlevel < $i && $i < $olddlevel)} {
1601 set xj [xcoord $j $dlevel $lj]
1601 set xj [xcoord $j $dlevel $lj]
1602 lappend mainline($id) $xi $y1 $xj $y2
1602 lappend mainline($id) $xi $y1 $xj $y2
1603 }
1603 }
1604 }
1604 }
1605 }
1605 }
1606 return $dlevel
1606 return $dlevel
1607 }
1607 }
1608
1608
1609 # search for x in a list of lists
1609 # search for x in a list of lists
1610 proc llsearch {llist x} {
1610 proc llsearch {llist x} {
1611 set i 0
1611 set i 0
1612 foreach l $llist {
1612 foreach l $llist {
1613 if {$l == $x || [lsearch -exact $l $x] >= 0} {
1613 if {$l == $x || [lsearch -exact $l $x] >= 0} {
1614 return $i
1614 return $i
1615 }
1615 }
1616 incr i
1616 incr i
1617 }
1617 }
1618 return -1
1618 return -1
1619 }
1619 }
1620
1620
1621 proc drawmore {reading} {
1621 proc drawmore {reading} {
1622 global displayorder numcommits ncmupdate nextupdate
1622 global displayorder numcommits ncmupdate nextupdate
1623 global stopped nhyperspace parents commitlisted
1623 global stopped nhyperspace parents commitlisted
1624 global maxwidth onscreen displist currentparents olddlevel
1624 global maxwidth onscreen displist currentparents olddlevel
1625
1625
1626 set n [llength $displayorder]
1626 set n [llength $displayorder]
1627 while {$numcommits < $n} {
1627 while {$numcommits < $n} {
1628 set id [lindex $displayorder $numcommits]
1628 set id [lindex $displayorder $numcommits]
1629 set ctxend [expr {$numcommits + 10}]
1629 set ctxend [expr {$numcommits + 10}]
1630 if {!$reading && $ctxend > $n} {
1630 if {!$reading && $ctxend > $n} {
1631 set ctxend $n
1631 set ctxend $n
1632 }
1632 }
1633 set dlist {}
1633 set dlist {}
1634 if {$numcommits > 0} {
1634 if {$numcommits > 0} {
1635 set dlist [lreplace $displist $olddlevel $olddlevel]
1635 set dlist [lreplace $displist $olddlevel $olddlevel]
1636 set i $olddlevel
1636 set i $olddlevel
1637 foreach p $currentparents {
1637 foreach p $currentparents {
1638 if {$onscreen($p) == 0} {
1638 if {$onscreen($p) == 0} {
1639 set dlist [linsert $dlist $i $p]
1639 set dlist [linsert $dlist $i $p]
1640 incr i
1640 incr i
1641 }
1641 }
1642 }
1642 }
1643 }
1643 }
1644 set nohs {}
1644 set nohs {}
1645 set reins {}
1645 set reins {}
1646 set isfat [expr {[llength $dlist] > $maxwidth}]
1646 set isfat [expr {[llength $dlist] > $maxwidth}]
1647 if {$nhyperspace > 0 || $isfat} {
1647 if {$nhyperspace > 0 || $isfat} {
1648 if {$ctxend > $n} break
1648 if {$ctxend > $n} break
1649 # work out what to bring back and
1649 # work out what to bring back and
1650 # what we want to don't want to send into hyperspace
1650 # what we want to don't want to send into hyperspace
1651 set room 1
1651 set room 1
1652 for {set k $numcommits} {$k < $ctxend} {incr k} {
1652 for {set k $numcommits} {$k < $ctxend} {incr k} {
1653 set x [lindex $displayorder $k]
1653 set x [lindex $displayorder $k]
1654 set i [llsearch $dlist $x]
1654 set i [llsearch $dlist $x]
1655 if {$i < 0} {
1655 if {$i < 0} {
1656 set i [llength $dlist]
1656 set i [llength $dlist]
1657 lappend dlist $x
1657 lappend dlist $x
1658 }
1658 }
1659 if {[lsearch -exact $nohs $x] < 0} {
1659 if {[lsearch -exact $nohs $x] < 0} {
1660 lappend nohs $x
1660 lappend nohs $x
1661 }
1661 }
1662 if {$reins eq {} && $onscreen($x) < 0 && $room} {
1662 if {$reins eq {} && $onscreen($x) < 0 && $room} {
1663 set reins [list $x $i]
1663 set reins [list $x $i]
1664 }
1664 }
1665 set newp {}
1665 set newp {}
1666 if {[info exists commitlisted($x)]} {
1666 if {[info exists commitlisted($x)]} {
1667 set right 0
1667 set right 0
1668 foreach p $parents($x) {
1668 foreach p $parents($x) {
1669 if {[llsearch $dlist $p] < 0} {
1669 if {[llsearch $dlist $p] < 0} {
1670 lappend newp $p
1670 lappend newp $p
1671 if {[lsearch -exact $nohs $p] < 0} {
1671 if {[lsearch -exact $nohs $p] < 0} {
1672 lappend nohs $p
1672 lappend nohs $p
1673 }
1673 }
1674 if {$reins eq {} && $onscreen($p) < 0 && $room} {
1674 if {$reins eq {} && $onscreen($p) < 0 && $room} {
1675 set reins [list $p [expr {$i + $right}]]
1675 set reins [list $p [expr {$i + $right}]]
1676 }
1676 }
1677 }
1677 }
1678 set right 1
1678 set right 1
1679 }
1679 }
1680 }
1680 }
1681 set l [lindex $dlist $i]
1681 set l [lindex $dlist $i]
1682 if {[llength $l] == 1} {
1682 if {[llength $l] == 1} {
1683 set l $newp
1683 set l $newp
1684 } else {
1684 } else {
1685 set j [lsearch -exact $l $x]
1685 set j [lsearch -exact $l $x]
1686 set l [concat [lreplace $l $j $j] $newp]
1686 set l [concat [lreplace $l $j $j] $newp]
1687 }
1687 }
1688 set dlist [lreplace $dlist $i $i $l]
1688 set dlist [lreplace $dlist $i $i $l]
1689 if {$room && $isfat && [llength $newp] <= 1} {
1689 if {$room && $isfat && [llength $newp] <= 1} {
1690 set room 0
1690 set room 0
1691 }
1691 }
1692 }
1692 }
1693 }
1693 }
1694
1694
1695 set dlevel [drawslants $id $reins $nohs]
1695 set dlevel [drawslants $id $reins $nohs]
1696 drawcommitline $dlevel
1696 drawcommitline $dlevel
1697 if {[clock clicks -milliseconds] >= $nextupdate
1697 if {[clock clicks -milliseconds] >= $nextupdate
1698 && $numcommits >= $ncmupdate} {
1698 && $numcommits >= $ncmupdate} {
1699 doupdate $reading
1699 doupdate $reading
1700 if {$stopped} break
1700 if {$stopped} break
1701 }
1701 }
1702 }
1702 }
1703 }
1703 }
1704
1704
1705 # level here is an index in todo
1705 # level here is an index in todo
1706 proc updatetodo {level noshortcut} {
1706 proc updatetodo {level noshortcut} {
1707 global ncleft todo nnewparents
1707 global ncleft todo nnewparents
1708 global commitlisted parents onscreen
1708 global commitlisted parents onscreen
1709
1709
1710 set id [lindex $todo $level]
1710 set id [lindex $todo $level]
1711 set olds {}
1711 set olds {}
1712 if {[info exists commitlisted($id)]} {
1712 if {[info exists commitlisted($id)]} {
1713 foreach p $parents($id) {
1713 foreach p $parents($id) {
1714 if {[lsearch -exact $olds $p] < 0} {
1714 if {[lsearch -exact $olds $p] < 0} {
1715 lappend olds $p
1715 lappend olds $p
1716 }
1716 }
1717 }
1717 }
1718 }
1718 }
1719 if {!$noshortcut && [llength $olds] == 1} {
1719 if {!$noshortcut && [llength $olds] == 1} {
1720 set p [lindex $olds 0]
1720 set p [lindex $olds 0]
1721 if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
1721 if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
1722 set ncleft($p) 0
1722 set ncleft($p) 0
1723 set todo [lreplace $todo $level $level $p]
1723 set todo [lreplace $todo $level $level $p]
1724 set onscreen($p) 0
1724 set onscreen($p) 0
1725 set nnewparents($id) 1
1725 set nnewparents($id) 1
1726 return 0
1726 return 0
1727 }
1727 }
1728 }
1728 }
1729
1729
1730 set todo [lreplace $todo $level $level]
1730 set todo [lreplace $todo $level $level]
1731 set i $level
1731 set i $level
1732 set n 0
1732 set n 0
1733 foreach p $olds {
1733 foreach p $olds {
1734 incr ncleft($p) -1
1734 incr ncleft($p) -1
1735 set k [lsearch -exact $todo $p]
1735 set k [lsearch -exact $todo $p]
1736 if {$k < 0} {
1736 if {$k < 0} {
1737 set todo [linsert $todo $i $p]
1737 set todo [linsert $todo $i $p]
1738 set onscreen($p) 0
1738 set onscreen($p) 0
1739 incr i
1739 incr i
1740 incr n
1740 incr n
1741 }
1741 }
1742 }
1742 }
1743 set nnewparents($id) $n
1743 set nnewparents($id) $n
1744
1744
1745 return 1
1745 return 1
1746 }
1746 }
1747
1747
1748 proc decidenext {{noread 0}} {
1748 proc decidenext {{noread 0}} {
1749 global ncleft todo
1749 global ncleft todo
1750 global datemode cdate
1750 global datemode cdate
1751 global commitinfo
1751 global commitinfo
1752
1752
1753 # choose which one to do next time around
1753 # choose which one to do next time around
1754 set todol [llength $todo]
1754 set todol [llength $todo]
1755 set level -1
1755 set level -1
1756 set latest {}
1756 set latest {}
1757 for {set k $todol} {[incr k -1] >= 0} {} {
1757 for {set k $todol} {[incr k -1] >= 0} {} {
1758 set p [lindex $todo $k]
1758 set p [lindex $todo $k]
1759 if {$ncleft($p) == 0} {
1759 if {$ncleft($p) == 0} {
1760 if {$datemode} {
1760 if {$datemode} {
1761 if {![info exists commitinfo($p)]} {
1761 if {![info exists commitinfo($p)]} {
1762 if {$noread} {
1762 if {$noread} {
1763 return {}
1763 return {}
1764 }
1764 }
1765 readcommit $p
1765 readcommit $p
1766 }
1766 }
1767 if {$latest == {} || $cdate($p) > $latest} {
1767 if {$latest == {} || $cdate($p) > $latest} {
1768 set level $k
1768 set level $k
1769 set latest $cdate($p)
1769 set latest $cdate($p)
1770 }
1770 }
1771 } else {
1771 } else {
1772 set level $k
1772 set level $k
1773 break
1773 break
1774 }
1774 }
1775 }
1775 }
1776 }
1776 }
1777 if {$level < 0} {
1777 if {$level < 0} {
1778 if {$todo != {}} {
1778 if {$todo != {}} {
1779 puts "ERROR: none of the pending commits can be done yet:"
1779 puts "ERROR: none of the pending commits can be done yet:"
1780 foreach p $todo {
1780 foreach p $todo {
1781 puts " $p ($ncleft($p))"
1781 puts " $p ($ncleft($p))"
1782 }
1782 }
1783 }
1783 }
1784 return -1
1784 return -1
1785 }
1785 }
1786
1786
1787 return $level
1787 return $level
1788 }
1788 }
1789
1789
1790 proc drawcommit {id} {
1790 proc drawcommit {id} {
1791 global phase todo nchildren datemode nextupdate
1791 global phase todo nchildren datemode nextupdate
1792 global numcommits ncmupdate displayorder todo onscreen
1792 global numcommits ncmupdate displayorder todo onscreen
1793
1793
1794 if {$phase != "incrdraw"} {
1794 if {$phase != "incrdraw"} {
1795 set phase incrdraw
1795 set phase incrdraw
1796 set displayorder {}
1796 set displayorder {}
1797 set todo {}
1797 set todo {}
1798 initgraph
1798 initgraph
1799 }
1799 }
1800 if {$nchildren($id) == 0} {
1800 if {$nchildren($id) == 0} {
1801 lappend todo $id
1801 lappend todo $id
1802 set onscreen($id) 0
1802 set onscreen($id) 0
1803 }
1803 }
1804 set level [decidenext 1]
1804 set level [decidenext 1]
1805 if {$level == {} || $id != [lindex $todo $level]} {
1805 if {$level == {} || $id != [lindex $todo $level]} {
1806 return
1806 return
1807 }
1807 }
1808 while 1 {
1808 while 1 {
1809 lappend displayorder [lindex $todo $level]
1809 lappend displayorder [lindex $todo $level]
1810 if {[updatetodo $level $datemode]} {
1810 if {[updatetodo $level $datemode]} {
1811 set level [decidenext 1]
1811 set level [decidenext 1]
1812 if {$level == {}} break
1812 if {$level == {}} break
1813 }
1813 }
1814 set id [lindex $todo $level]
1814 set id [lindex $todo $level]
1815 if {![info exists commitlisted($id)]} {
1815 if {![info exists commitlisted($id)]} {
1816 break
1816 break
1817 }
1817 }
1818 }
1818 }
1819 drawmore 1
1819 drawmore 1
1820 }
1820 }
1821
1821
1822 proc finishcommits {} {
1822 proc finishcommits {} {
1823 global phase
1823 global phase
1824 global canv mainfont ctext maincursor textcursor
1824 global canv mainfont ctext maincursor textcursor
1825
1825
1826 if {$phase != "incrdraw"} {
1826 if {$phase != "incrdraw"} {
1827 $canv delete all
1827 $canv delete all
1828 $canv create text 3 3 -anchor nw -text "No commits selected" \
1828 $canv create text 3 3 -anchor nw -text "No commits selected" \
1829 -font $mainfont -tags textitems
1829 -font $mainfont -tags textitems
1830 set phase {}
1830 set phase {}
1831 } else {
1831 } else {
1832 drawrest
1832 drawrest
1833 }
1833 }
1834 . config -cursor $maincursor
1834 . config -cursor $maincursor
1835 settextcursor $textcursor
1835 settextcursor $textcursor
1836 }
1836 }
1837
1837
1838 # Don't change the text pane cursor if it is currently the hand cursor,
1838 # Don't change the text pane cursor if it is currently the hand cursor,
1839 # showing that we are over a sha1 ID link.
1839 # showing that we are over a sha1 ID link.
1840 proc settextcursor {c} {
1840 proc settextcursor {c} {
1841 global ctext curtextcursor
1841 global ctext curtextcursor
1842
1842
1843 if {[$ctext cget -cursor] == $curtextcursor} {
1843 if {[$ctext cget -cursor] == $curtextcursor} {
1844 $ctext config -cursor $c
1844 $ctext config -cursor $c
1845 }
1845 }
1846 set curtextcursor $c
1846 set curtextcursor $c
1847 }
1847 }
1848
1848
1849 proc drawgraph {} {
1849 proc drawgraph {} {
1850 global nextupdate startmsecs ncmupdate
1850 global nextupdate startmsecs ncmupdate
1851 global displayorder onscreen
1851 global displayorder onscreen
1852
1852
1853 if {$displayorder == {}} return
1853 if {$displayorder == {}} return
1854 set startmsecs [clock clicks -milliseconds]
1854 set startmsecs [clock clicks -milliseconds]
1855 set nextupdate [expr $startmsecs + 100]
1855 set nextupdate [expr $startmsecs + 100]
1856 set ncmupdate 1
1856 set ncmupdate 1
1857 initgraph
1857 initgraph
1858 foreach id $displayorder {
1858 foreach id $displayorder {
1859 set onscreen($id) 0
1859 set onscreen($id) 0
1860 }
1860 }
1861 drawmore 0
1861 drawmore 0
1862 }
1862 }
1863
1863
1864 proc drawrest {} {
1864 proc drawrest {} {
1865 global phase stopped redisplaying selectedline
1865 global phase stopped redisplaying selectedline
1866 global datemode todo displayorder
1866 global datemode todo displayorder
1867 global numcommits ncmupdate
1867 global numcommits ncmupdate
1868 global nextupdate startmsecs
1868 global nextupdate startmsecs
1869
1869
1870 set level [decidenext]
1870 set level [decidenext]
1871 if {$level >= 0} {
1871 if {$level >= 0} {
1872 set phase drawgraph
1872 set phase drawgraph
1873 while 1 {
1873 while 1 {
1874 lappend displayorder [lindex $todo $level]
1874 lappend displayorder [lindex $todo $level]
1875 set hard [updatetodo $level $datemode]
1875 set hard [updatetodo $level $datemode]
1876 if {$hard} {
1876 if {$hard} {
1877 set level [decidenext]
1877 set level [decidenext]
1878 if {$level < 0} break
1878 if {$level < 0} break
1879 }
1879 }
1880 }
1880 }
1881 drawmore 0
1881 drawmore 0
1882 }
1882 }
1883 set phase {}
1883 set phase {}
1884 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1884 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1885 #puts "overall $drawmsecs ms for $numcommits commits"
1885 #puts "overall $drawmsecs ms for $numcommits commits"
1886 if {$redisplaying} {
1886 if {$redisplaying} {
1887 if {$stopped == 0 && [info exists selectedline]} {
1887 if {$stopped == 0 && [info exists selectedline]} {
1888 selectline $selectedline 0
1888 selectline $selectedline 0
1889 }
1889 }
1890 if {$stopped == 1} {
1890 if {$stopped == 1} {
1891 set stopped 0
1891 set stopped 0
1892 after idle drawgraph
1892 after idle drawgraph
1893 } else {
1893 } else {
1894 set redisplaying 0
1894 set redisplaying 0
1895 }
1895 }
1896 }
1896 }
1897 }
1897 }
1898
1898
1899 proc findmatches {f} {
1899 proc findmatches {f} {
1900 global findtype foundstring foundstrlen
1900 global findtype foundstring foundstrlen
1901 if {$findtype == "Regexp"} {
1901 if {$findtype == "Regexp"} {
1902 set matches [regexp -indices -all -inline $foundstring $f]
1902 set matches [regexp -indices -all -inline $foundstring $f]
1903 } else {
1903 } else {
1904 if {$findtype == "IgnCase"} {
1904 if {$findtype == "IgnCase"} {
1905 set str [string tolower $f]
1905 set str [string tolower $f]
1906 } else {
1906 } else {
1907 set str $f
1907 set str $f
1908 }
1908 }
1909 set matches {}
1909 set matches {}
1910 set i 0
1910 set i 0
1911 while {[set j [string first $foundstring $str $i]] >= 0} {
1911 while {[set j [string first $foundstring $str $i]] >= 0} {
1912 lappend matches [list $j [expr $j+$foundstrlen-1]]
1912 lappend matches [list $j [expr $j+$foundstrlen-1]]
1913 set i [expr $j + $foundstrlen]
1913 set i [expr $j + $foundstrlen]
1914 }
1914 }
1915 }
1915 }
1916 return $matches
1916 return $matches
1917 }
1917 }
1918
1918
1919 proc dofind {} {
1919 proc dofind {} {
1920 global findtype findloc findstring markedmatches commitinfo
1920 global findtype findloc findstring markedmatches commitinfo
1921 global numcommits lineid linehtag linentag linedtag
1921 global numcommits lineid linehtag linentag linedtag
1922 global mainfont namefont canv canv2 canv3 selectedline
1922 global mainfont namefont canv canv2 canv3 selectedline
1923 global matchinglines foundstring foundstrlen
1923 global matchinglines foundstring foundstrlen
1924
1924
1925 stopfindproc
1925 stopfindproc
1926 unmarkmatches
1926 unmarkmatches
1927 focus .
1927 focus .
1928 set matchinglines {}
1928 set matchinglines {}
1929 if {$findloc == "Pickaxe"} {
1929 if {$findloc == "Pickaxe"} {
1930 findpatches
1930 findpatches
1931 return
1931 return
1932 }
1932 }
1933 if {$findtype == "IgnCase"} {
1933 if {$findtype == "IgnCase"} {
1934 set foundstring [string tolower $findstring]
1934 set foundstring [string tolower $findstring]
1935 } else {
1935 } else {
1936 set foundstring $findstring
1936 set foundstring $findstring
1937 }
1937 }
1938 set foundstrlen [string length $findstring]
1938 set foundstrlen [string length $findstring]
1939 if {$foundstrlen == 0} return
1939 if {$foundstrlen == 0} return
1940 if {$findloc == "Files"} {
1940 if {$findloc == "Files"} {
1941 findfiles
1941 findfiles
1942 return
1942 return
1943 }
1943 }
1944 if {![info exists selectedline]} {
1944 if {![info exists selectedline]} {
1945 set oldsel -1
1945 set oldsel -1
1946 } else {
1946 } else {
1947 set oldsel $selectedline
1947 set oldsel $selectedline
1948 }
1948 }
1949 set didsel 0
1949 set didsel 0
1950 set fldtypes {Headline Author Date CDate Comment}
1950 set fldtypes {Headline Author Date CDate Comment}
1951 for {set l 0} {$l < $numcommits} {incr l} {
1951 for {set l 0} {$l < $numcommits} {incr l} {
1952 set id $lineid($l)
1952 set id $lineid($l)
1953 set info $commitinfo($id)
1953 set info $commitinfo($id)
1954 set doesmatch 0
1954 set doesmatch 0
1955 foreach f $info ty $fldtypes {
1955 foreach f $info ty $fldtypes {
1956 if {$findloc != "All fields" && $findloc != $ty} {
1956 if {$findloc != "All fields" && $findloc != $ty} {
1957 continue
1957 continue
1958 }
1958 }
1959 set matches [findmatches $f]
1959 set matches [findmatches $f]
1960 if {$matches == {}} continue
1960 if {$matches == {}} continue
1961 set doesmatch 1
1961 set doesmatch 1
1962 if {$ty == "Headline"} {
1962 if {$ty == "Headline"} {
1963 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1963 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1964 } elseif {$ty == "Author"} {
1964 } elseif {$ty == "Author"} {
1965 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1965 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1966 } elseif {$ty == "Date"} {
1966 } elseif {$ty == "Date"} {
1967 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1967 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1968 }
1968 }
1969 }
1969 }
1970 if {$doesmatch} {
1970 if {$doesmatch} {
1971 lappend matchinglines $l
1971 lappend matchinglines $l
1972 if {!$didsel && $l > $oldsel} {
1972 if {!$didsel && $l > $oldsel} {
1973 findselectline $l
1973 findselectline $l
1974 set didsel 1
1974 set didsel 1
1975 }
1975 }
1976 }
1976 }
1977 }
1977 }
1978 if {$matchinglines == {}} {
1978 if {$matchinglines == {}} {
1979 bell
1979 bell
1980 } elseif {!$didsel} {
1980 } elseif {!$didsel} {
1981 findselectline [lindex $matchinglines 0]
1981 findselectline [lindex $matchinglines 0]
1982 }
1982 }
1983 }
1983 }
1984
1984
1985 proc findselectline {l} {
1985 proc findselectline {l} {
1986 global findloc commentend ctext
1986 global findloc commentend ctext
1987 selectline $l 1
1987 selectline $l 1
1988 if {$findloc == "All fields" || $findloc == "Comments"} {
1988 if {$findloc == "All fields" || $findloc == "Comments"} {
1989 # highlight the matches in the comments
1989 # highlight the matches in the comments
1990 set f [$ctext get 1.0 $commentend]
1990 set f [$ctext get 1.0 $commentend]
1991 set matches [findmatches $f]
1991 set matches [findmatches $f]
1992 foreach match $matches {
1992 foreach match $matches {
1993 set start [lindex $match 0]
1993 set start [lindex $match 0]
1994 set end [expr [lindex $match 1] + 1]
1994 set end [expr [lindex $match 1] + 1]
1995 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1995 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1996 }
1996 }
1997 }
1997 }
1998 }
1998 }
1999
1999
2000 proc findnext {restart} {
2000 proc findnext {restart} {
2001 global matchinglines selectedline
2001 global matchinglines selectedline
2002 if {![info exists matchinglines]} {
2002 if {![info exists matchinglines]} {
2003 if {$restart} {
2003 if {$restart} {
2004 dofind
2004 dofind
2005 }
2005 }
2006 return
2006 return
2007 }
2007 }
2008 if {![info exists selectedline]} return
2008 if {![info exists selectedline]} return
2009 foreach l $matchinglines {
2009 foreach l $matchinglines {
2010 if {$l > $selectedline} {
2010 if {$l > $selectedline} {
2011 findselectline $l
2011 findselectline $l
2012 return
2012 return
2013 }
2013 }
2014 }
2014 }
2015 bell
2015 bell
2016 }
2016 }
2017
2017
2018 proc findprev {} {
2018 proc findprev {} {
2019 global matchinglines selectedline
2019 global matchinglines selectedline
2020 if {![info exists matchinglines]} {
2020 if {![info exists matchinglines]} {
2021 dofind
2021 dofind
2022 return
2022 return
2023 }
2023 }
2024 if {![info exists selectedline]} return
2024 if {![info exists selectedline]} return
2025 set prev {}
2025 set prev {}
2026 foreach l $matchinglines {
2026 foreach l $matchinglines {
2027 if {$l >= $selectedline} break
2027 if {$l >= $selectedline} break
2028 set prev $l
2028 set prev $l
2029 }
2029 }
2030 if {$prev != {}} {
2030 if {$prev != {}} {
2031 findselectline $prev
2031 findselectline $prev
2032 } else {
2032 } else {
2033 bell
2033 bell
2034 }
2034 }
2035 }
2035 }
2036
2036
2037 proc findlocchange {name ix op} {
2037 proc findlocchange {name ix op} {
2038 global findloc findtype findtypemenu
2038 global findloc findtype findtypemenu
2039 if {$findloc == "Pickaxe"} {
2039 if {$findloc == "Pickaxe"} {
2040 set findtype Exact
2040 set findtype Exact
2041 set state disabled
2041 set state disabled
2042 } else {
2042 } else {
2043 set state normal
2043 set state normal
2044 }
2044 }
2045 $findtypemenu entryconf 1 -state $state
2045 $findtypemenu entryconf 1 -state $state
2046 $findtypemenu entryconf 2 -state $state
2046 $findtypemenu entryconf 2 -state $state
2047 }
2047 }
2048
2048
2049 proc stopfindproc {{done 0}} {
2049 proc stopfindproc {{done 0}} {
2050 global findprocpid findprocfile findids
2050 global findprocpid findprocfile findids
2051 global ctext findoldcursor phase maincursor textcursor
2051 global ctext findoldcursor phase maincursor textcursor
2052 global findinprogress
2052 global findinprogress
2053
2053
2054 catch {unset findids}
2054 catch {unset findids}
2055 if {[info exists findprocpid]} {
2055 if {[info exists findprocpid]} {
2056 if {!$done} {
2056 if {!$done} {
2057 catch {exec kill $findprocpid}
2057 catch {exec kill $findprocpid}
2058 }
2058 }
2059 catch {close $findprocfile}
2059 catch {close $findprocfile}
2060 unset findprocpid
2060 unset findprocpid
2061 }
2061 }
2062 if {[info exists findinprogress]} {
2062 if {[info exists findinprogress]} {
2063 unset findinprogress
2063 unset findinprogress
2064 if {$phase != "incrdraw"} {
2064 if {$phase != "incrdraw"} {
2065 . config -cursor $maincursor
2065 . config -cursor $maincursor
2066 settextcursor $textcursor
2066 settextcursor $textcursor
2067 }
2067 }
2068 }
2068 }
2069 }
2069 }
2070
2070
2071 proc findpatches {} {
2071 proc findpatches {} {
2072 global findstring selectedline numcommits
2072 global findstring selectedline numcommits
2073 global findprocpid findprocfile
2073 global findprocpid findprocfile
2074 global finddidsel ctext lineid findinprogress
2074 global finddidsel ctext lineid findinprogress
2075 global findinsertpos
2075 global findinsertpos
2076 global env
2076 global env
2077
2077
2078 if {$numcommits == 0} return
2078 if {$numcommits == 0} return
2079
2079
2080 # make a list of all the ids to search, starting at the one
2080 # make a list of all the ids to search, starting at the one
2081 # after the selected line (if any)
2081 # after the selected line (if any)
2082 if {[info exists selectedline]} {
2082 if {[info exists selectedline]} {
2083 set l $selectedline
2083 set l $selectedline
2084 } else {
2084 } else {
2085 set l -1
2085 set l -1
2086 }
2086 }
2087 set inputids {}
2087 set inputids {}
2088 for {set i 0} {$i < $numcommits} {incr i} {
2088 for {set i 0} {$i < $numcommits} {incr i} {
2089 if {[incr l] >= $numcommits} {
2089 if {[incr l] >= $numcommits} {
2090 set l 0
2090 set l 0
2091 }
2091 }
2092 append inputids $lineid($l) "\n"
2092 append inputids $lineid($l) "\n"
2093 }
2093 }
2094
2094
2095 if {[catch {
2095 if {[catch {
2096 set f [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree --stdin -s -r -S$findstring << $inputids] r]
2096 set f [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree --stdin -s -r -S$findstring << $inputids] r]
2097 } err]} {
2097 } err]} {
2098 error_popup "Error starting search process: $err"
2098 error_popup "Error starting search process: $err"
2099 return
2099 return
2100 }
2100 }
2101
2101
2102 set findinsertpos end
2102 set findinsertpos end
2103 set findprocfile $f
2103 set findprocfile $f
2104 set findprocpid [pid $f]
2104 set findprocpid [pid $f]
2105 fconfigure $f -blocking 0
2105 fconfigure $f -blocking 0
2106 fileevent $f readable readfindproc
2106 fileevent $f readable readfindproc
2107 set finddidsel 0
2107 set finddidsel 0
2108 . config -cursor watch
2108 . config -cursor watch
2109 settextcursor watch
2109 settextcursor watch
2110 set findinprogress 1
2110 set findinprogress 1
2111 }
2111 }
2112
2112
2113 proc readfindproc {} {
2113 proc readfindproc {} {
2114 global findprocfile finddidsel
2114 global findprocfile finddidsel
2115 global idline matchinglines findinsertpos
2115 global idline matchinglines findinsertpos
2116
2116
2117 set n [gets $findprocfile line]
2117 set n [gets $findprocfile line]
2118 if {$n < 0} {
2118 if {$n < 0} {
2119 if {[eof $findprocfile]} {
2119 if {[eof $findprocfile]} {
2120 stopfindproc 1
2120 stopfindproc 1
2121 if {!$finddidsel} {
2121 if {!$finddidsel} {
2122 bell
2122 bell
2123 }
2123 }
2124 }
2124 }
2125 return
2125 return
2126 }
2126 }
2127 if {![regexp {^[0-9a-f]{12}} $line id]} {
2127 if {![regexp {^[0-9a-f]{12}} $line id]} {
2128 error_popup "Can't parse git-diff-tree output: $line"
2128 error_popup "Can't parse git-diff-tree output: $line"
2129 stopfindproc
2129 stopfindproc
2130 return
2130 return
2131 }
2131 }
2132 if {![info exists idline($id)]} {
2132 if {![info exists idline($id)]} {
2133 puts stderr "spurious id: $id"
2133 puts stderr "spurious id: $id"
2134 return
2134 return
2135 }
2135 }
2136 set l $idline($id)
2136 set l $idline($id)
2137 insertmatch $l $id
2137 insertmatch $l $id
2138 }
2138 }
2139
2139
2140 proc insertmatch {l id} {
2140 proc insertmatch {l id} {
2141 global matchinglines findinsertpos finddidsel
2141 global matchinglines findinsertpos finddidsel
2142
2142
2143 if {$findinsertpos == "end"} {
2143 if {$findinsertpos == "end"} {
2144 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
2144 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
2145 set matchinglines [linsert $matchinglines 0 $l]
2145 set matchinglines [linsert $matchinglines 0 $l]
2146 set findinsertpos 1
2146 set findinsertpos 1
2147 } else {
2147 } else {
2148 lappend matchinglines $l
2148 lappend matchinglines $l
2149 }
2149 }
2150 } else {
2150 } else {
2151 set matchinglines [linsert $matchinglines $findinsertpos $l]
2151 set matchinglines [linsert $matchinglines $findinsertpos $l]
2152 incr findinsertpos
2152 incr findinsertpos
2153 }
2153 }
2154 markheadline $l $id
2154 markheadline $l $id
2155 if {!$finddidsel} {
2155 if {!$finddidsel} {
2156 findselectline $l
2156 findselectline $l
2157 set finddidsel 1
2157 set finddidsel 1
2158 }
2158 }
2159 }
2159 }
2160
2160
2161 proc findfiles {} {
2161 proc findfiles {} {
2162 global selectedline numcommits lineid ctext
2162 global selectedline numcommits lineid ctext
2163 global ffileline finddidsel parents nparents
2163 global ffileline finddidsel parents nparents
2164 global findinprogress findstartline findinsertpos
2164 global findinprogress findstartline findinsertpos
2165 global treediffs fdiffids fdiffsneeded fdiffpos
2165 global treediffs fdiffids fdiffsneeded fdiffpos
2166 global findmergefiles
2166 global findmergefiles
2167 global env
2167 global env
2168
2168
2169 if {$numcommits == 0} return
2169 if {$numcommits == 0} return
2170
2170
2171 if {[info exists selectedline]} {
2171 if {[info exists selectedline]} {
2172 set l [expr {$selectedline + 1}]
2172 set l [expr {$selectedline + 1}]
2173 } else {
2173 } else {
2174 set l 0
2174 set l 0
2175 }
2175 }
2176 set ffileline $l
2176 set ffileline $l
2177 set findstartline $l
2177 set findstartline $l
2178 set diffsneeded {}
2178 set diffsneeded {}
2179 set fdiffsneeded {}
2179 set fdiffsneeded {}
2180 while 1 {
2180 while 1 {
2181 set id $lineid($l)
2181 set id $lineid($l)
2182 if {$findmergefiles || $nparents($id) == 1} {
2182 if {$findmergefiles || $nparents($id) == 1} {
2183 foreach p $parents($id) {
2183 foreach p $parents($id) {
2184 if {![info exists treediffs([list $id $p])]} {
2184 if {![info exists treediffs([list $id $p])]} {
2185 append diffsneeded "$id $p\n"
2185 append diffsneeded "$id $p\n"
2186 lappend fdiffsneeded [list $id $p]
2186 lappend fdiffsneeded [list $id $p]
2187 }
2187 }
2188 }
2188 }
2189 }
2189 }
2190 if {[incr l] >= $numcommits} {
2190 if {[incr l] >= $numcommits} {
2191 set l 0
2191 set l 0
2192 }
2192 }
2193 if {$l == $findstartline} break
2193 if {$l == $findstartline} break
2194 }
2194 }
2195
2195
2196 # start off a git-diff-tree process if needed
2196 # start off a git-diff-tree process if needed
2197 if {$diffsneeded ne {}} {
2197 if {$diffsneeded ne {}} {
2198 if {[catch {
2198 if {[catch {
2199 set df [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r --stdin << $diffsneeded] r]
2199 set df [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r --stdin << $diffsneeded] r]
2200 } err ]} {
2200 } err ]} {
2201 error_popup "Error starting search process: $err"
2201 error_popup "Error starting search process: $err"
2202 return
2202 return
2203 }
2203 }
2204 catch {unset fdiffids}
2204 catch {unset fdiffids}
2205 set fdiffpos 0
2205 set fdiffpos 0
2206 fconfigure $df -blocking 0
2206 fconfigure $df -blocking 0
2207 fileevent $df readable [list readfilediffs $df]
2207 fileevent $df readable [list readfilediffs $df]
2208 }
2208 }
2209
2209
2210 set finddidsel 0
2210 set finddidsel 0
2211 set findinsertpos end
2211 set findinsertpos end
2212 set id $lineid($l)
2212 set id $lineid($l)
2213 set p [lindex $parents($id) 0]
2213 set p [lindex $parents($id) 0]
2214 . config -cursor watch
2214 . config -cursor watch
2215 settextcursor watch
2215 settextcursor watch
2216 set findinprogress 1
2216 set findinprogress 1
2217 findcont [list $id $p]
2217 findcont [list $id $p]
2218 update
2218 update
2219 }
2219 }
2220
2220
2221 proc readfilediffs {df} {
2221 proc readfilediffs {df} {
2222 global findids fdiffids fdiffs
2222 global findids fdiffids fdiffs
2223
2223
2224 set n [gets $df line]
2224 set n [gets $df line]
2225 if {$n < 0} {
2225 if {$n < 0} {
2226 if {[eof $df]} {
2226 if {[eof $df]} {
2227 donefilediff
2227 donefilediff
2228 if {[catch {close $df} err]} {
2228 if {[catch {close $df} err]} {
2229 stopfindproc
2229 stopfindproc
2230 bell
2230 bell
2231 error_popup "Error in hg debug-diff-tree: $err"
2231 error_popup "Error in hg debug-diff-tree: $err"
2232 } elseif {[info exists findids]} {
2232 } elseif {[info exists findids]} {
2233 set ids $findids
2233 set ids $findids
2234 stopfindproc
2234 stopfindproc
2235 bell
2235 bell
2236 error_popup "Couldn't find diffs for {$ids}"
2236 error_popup "Couldn't find diffs for {$ids}"
2237 }
2237 }
2238 }
2238 }
2239 return
2239 return
2240 }
2240 }
2241 if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
2241 if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
2242 # start of a new string of diffs
2242 # start of a new string of diffs
2243 donefilediff
2243 donefilediff
2244 set fdiffids [list $id $p]
2244 set fdiffids [list $id $p]
2245 set fdiffs {}
2245 set fdiffs {}
2246 } elseif {[string match ":*" $line]} {
2246 } elseif {[string match ":*" $line]} {
2247 lappend fdiffs [lindex $line 5]
2247 lappend fdiffs [lindex $line 5]
2248 }
2248 }
2249 }
2249 }
2250
2250
2251 proc donefilediff {} {
2251 proc donefilediff {} {
2252 global fdiffids fdiffs treediffs findids
2252 global fdiffids fdiffs treediffs findids
2253 global fdiffsneeded fdiffpos
2253 global fdiffsneeded fdiffpos
2254
2254
2255 if {[info exists fdiffids]} {
2255 if {[info exists fdiffids]} {
2256 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffids
2256 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffids
2257 && $fdiffpos < [llength $fdiffsneeded]} {
2257 && $fdiffpos < [llength $fdiffsneeded]} {
2258 # git-diff-tree doesn't output anything for a commit
2258 # git-diff-tree doesn't output anything for a commit
2259 # which doesn't change anything
2259 # which doesn't change anything
2260 set nullids [lindex $fdiffsneeded $fdiffpos]
2260 set nullids [lindex $fdiffsneeded $fdiffpos]
2261 set treediffs($nullids) {}
2261 set treediffs($nullids) {}
2262 if {[info exists findids] && $nullids eq $findids} {
2262 if {[info exists findids] && $nullids eq $findids} {
2263 unset findids
2263 unset findids
2264 findcont $nullids
2264 findcont $nullids
2265 }
2265 }
2266 incr fdiffpos
2266 incr fdiffpos
2267 }
2267 }
2268 incr fdiffpos
2268 incr fdiffpos
2269
2269
2270 if {![info exists treediffs($fdiffids)]} {
2270 if {![info exists treediffs($fdiffids)]} {
2271 set treediffs($fdiffids) $fdiffs
2271 set treediffs($fdiffids) $fdiffs
2272 }
2272 }
2273 if {[info exists findids] && $fdiffids eq $findids} {
2273 if {[info exists findids] && $fdiffids eq $findids} {
2274 unset findids
2274 unset findids
2275 findcont $fdiffids
2275 findcont $fdiffids
2276 }
2276 }
2277 }
2277 }
2278 }
2278 }
2279
2279
2280 proc findcont {ids} {
2280 proc findcont {ids} {
2281 global findids treediffs parents nparents
2281 global findids treediffs parents nparents
2282 global ffileline findstartline finddidsel
2282 global ffileline findstartline finddidsel
2283 global lineid numcommits matchinglines findinprogress
2283 global lineid numcommits matchinglines findinprogress
2284 global findmergefiles
2284 global findmergefiles
2285
2285
2286 set id [lindex $ids 0]
2286 set id [lindex $ids 0]
2287 set p [lindex $ids 1]
2287 set p [lindex $ids 1]
2288 set pi [lsearch -exact $parents($id) $p]
2288 set pi [lsearch -exact $parents($id) $p]
2289 set l $ffileline
2289 set l $ffileline
2290 while 1 {
2290 while 1 {
2291 if {$findmergefiles || $nparents($id) == 1} {
2291 if {$findmergefiles || $nparents($id) == 1} {
2292 if {![info exists treediffs($ids)]} {
2292 if {![info exists treediffs($ids)]} {
2293 set findids $ids
2293 set findids $ids
2294 set ffileline $l
2294 set ffileline $l
2295 return
2295 return
2296 }
2296 }
2297 set doesmatch 0
2297 set doesmatch 0
2298 foreach f $treediffs($ids) {
2298 foreach f $treediffs($ids) {
2299 set x [findmatches $f]
2299 set x [findmatches $f]
2300 if {$x != {}} {
2300 if {$x != {}} {
2301 set doesmatch 1
2301 set doesmatch 1
2302 break
2302 break
2303 }
2303 }
2304 }
2304 }
2305 if {$doesmatch} {
2305 if {$doesmatch} {
2306 insertmatch $l $id
2306 insertmatch $l $id
2307 set pi $nparents($id)
2307 set pi $nparents($id)
2308 }
2308 }
2309 } else {
2309 } else {
2310 set pi $nparents($id)
2310 set pi $nparents($id)
2311 }
2311 }
2312 if {[incr pi] >= $nparents($id)} {
2312 if {[incr pi] >= $nparents($id)} {
2313 set pi 0
2313 set pi 0
2314 if {[incr l] >= $numcommits} {
2314 if {[incr l] >= $numcommits} {
2315 set l 0
2315 set l 0
2316 }
2316 }
2317 if {$l == $findstartline} break
2317 if {$l == $findstartline} break
2318 set id $lineid($l)
2318 set id $lineid($l)
2319 }
2319 }
2320 set p [lindex $parents($id) $pi]
2320 set p [lindex $parents($id) $pi]
2321 set ids [list $id $p]
2321 set ids [list $id $p]
2322 }
2322 }
2323 stopfindproc
2323 stopfindproc
2324 if {!$finddidsel} {
2324 if {!$finddidsel} {
2325 bell
2325 bell
2326 }
2326 }
2327 }
2327 }
2328
2328
2329 # mark a commit as matching by putting a yellow background
2329 # mark a commit as matching by putting a yellow background
2330 # behind the headline
2330 # behind the headline
2331 proc markheadline {l id} {
2331 proc markheadline {l id} {
2332 global canv mainfont linehtag commitinfo
2332 global canv mainfont linehtag commitinfo
2333
2333
2334 set bbox [$canv bbox $linehtag($l)]
2334 set bbox [$canv bbox $linehtag($l)]
2335 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2335 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2336 $canv lower $t
2336 $canv lower $t
2337 }
2337 }
2338
2338
2339 # mark the bits of a headline, author or date that match a find string
2339 # mark the bits of a headline, author or date that match a find string
2340 proc markmatches {canv l str tag matches font} {
2340 proc markmatches {canv l str tag matches font} {
2341 set bbox [$canv bbox $tag]
2341 set bbox [$canv bbox $tag]
2342 set x0 [lindex $bbox 0]
2342 set x0 [lindex $bbox 0]
2343 set y0 [lindex $bbox 1]
2343 set y0 [lindex $bbox 1]
2344 set y1 [lindex $bbox 3]
2344 set y1 [lindex $bbox 3]
2345 foreach match $matches {
2345 foreach match $matches {
2346 set start [lindex $match 0]
2346 set start [lindex $match 0]
2347 set end [lindex $match 1]
2347 set end [lindex $match 1]
2348 if {$start > $end} continue
2348 if {$start > $end} continue
2349 set xoff [font measure $font [string range $str 0 [expr $start-1]]]
2349 set xoff [font measure $font [string range $str 0 [expr $start-1]]]
2350 set xlen [font measure $font [string range $str 0 [expr $end]]]
2350 set xlen [font measure $font [string range $str 0 [expr $end]]]
2351 set t [$canv create rect [expr $x0+$xoff] $y0 [expr $x0+$xlen+2] $y1 \
2351 set t [$canv create rect [expr $x0+$xoff] $y0 [expr $x0+$xlen+2] $y1 \
2352 -outline {} -tags matches -fill yellow]
2352 -outline {} -tags matches -fill yellow]
2353 $canv lower $t
2353 $canv lower $t
2354 }
2354 }
2355 }
2355 }
2356
2356
2357 proc unmarkmatches {} {
2357 proc unmarkmatches {} {
2358 global matchinglines findids
2358 global matchinglines findids
2359 allcanvs delete matches
2359 allcanvs delete matches
2360 catch {unset matchinglines}
2360 catch {unset matchinglines}
2361 catch {unset findids}
2361 catch {unset findids}
2362 }
2362 }
2363
2363
2364 proc selcanvline {w x y} {
2364 proc selcanvline {w x y} {
2365 global canv canvy0 ctext linespc
2365 global canv canvy0 ctext linespc
2366 global lineid linehtag linentag linedtag rowtextx
2366 global lineid linehtag linentag linedtag rowtextx
2367 set ymax [lindex [$canv cget -scrollregion] 3]
2367 set ymax [lindex [$canv cget -scrollregion] 3]
2368 if {$ymax == {}} return
2368 if {$ymax == {}} return
2369 set yfrac [lindex [$canv yview] 0]
2369 set yfrac [lindex [$canv yview] 0]
2370 set y [expr {$y + $yfrac * $ymax}]
2370 set y [expr {$y + $yfrac * $ymax}]
2371 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2371 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2372 if {$l < 0} {
2372 if {$l < 0} {
2373 set l 0
2373 set l 0
2374 }
2374 }
2375 if {$w eq $canv} {
2375 if {$w eq $canv} {
2376 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2376 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2377 }
2377 }
2378 unmarkmatches
2378 unmarkmatches
2379 selectline $l 1
2379 selectline $l 1
2380 }
2380 }
2381
2381
2382 proc commit_descriptor {p} {
2382 proc commit_descriptor {p} {
2383 global commitinfo
2383 global commitinfo
2384 set l "..."
2384 set l "..."
2385 if {[info exists commitinfo($p)]} {
2385 if {[info exists commitinfo($p)]} {
2386 set l [lindex $commitinfo($p) 0]
2386 set l [lindex $commitinfo($p) 0]
2387 set r [lindex $commitinfo($p) 6]
2387 set r [lindex $commitinfo($p) 6]
2388 }
2388 }
2389 return "$r:$p ($l)"
2389 return "$r:$p ($l)"
2390 }
2390 }
2391
2391
2392 # append some text to the ctext widget, and make any SHA1 ID
2392 # append some text to the ctext widget, and make any SHA1 ID
2393 # that we know about be a clickable link.
2393 # that we know about be a clickable link.
2394 proc appendwithlinks {text} {
2394 proc appendwithlinks {text} {
2395 global ctext idline linknum
2395 global ctext idline linknum
2396
2396
2397 set start [$ctext index "end - 1c"]
2397 set start [$ctext index "end - 1c"]
2398 $ctext insert end $text
2398 $ctext insert end $text
2399 $ctext insert end "\n"
2399 $ctext insert end "\n"
2400 set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
2400 set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
2401 foreach l $links {
2401 foreach l $links {
2402 set s [lindex $l 0]
2402 set s [lindex $l 0]
2403 set e [lindex $l 1]
2403 set e [lindex $l 1]
2404 set linkid [string range $text $s $e]
2404 set linkid [string range $text $s $e]
2405 if {![info exists idline($linkid)]} continue
2405 if {![info exists idline($linkid)]} continue
2406 incr e
2406 incr e
2407 $ctext tag add link "$start + $s c" "$start + $e c"
2407 $ctext tag add link "$start + $s c" "$start + $e c"
2408 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2408 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2409 $ctext tag bind link$linknum <1> [list selectline $idline($linkid) 1]
2409 $ctext tag bind link$linknum <1> [list selectline $idline($linkid) 1]
2410 incr linknum
2410 incr linknum
2411 }
2411 }
2412 $ctext tag conf link -foreground blue -underline 1
2412 $ctext tag conf link -foreground blue -underline 1
2413 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2413 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2414 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2414 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2415 }
2415 }
2416
2416
2417 proc selectline {l isnew} {
2417 proc selectline {l isnew} {
2418 global canv canv2 canv3 ctext commitinfo selectedline
2418 global canv canv2 canv3 ctext commitinfo selectedline
2419 global lineid linehtag linentag linedtag
2419 global lineid linehtag linentag linedtag
2420 global canvy0 linespc parents nparents children
2420 global canvy0 linespc parents nparents children
2421 global cflist currentid sha1entry
2421 global cflist currentid sha1entry
2422 global commentend idtags idbookmarks idline linknum
2422 global commentend idtags idbookmarks idline linknum
2423
2423
2424 $canv delete hover
2424 $canv delete hover
2425 normalline
2425 normalline
2426 if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
2426 if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
2427 $canv delete secsel
2427 $canv delete secsel
2428 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2428 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2429 -tags secsel -fill [$canv cget -selectbackground]]
2429 -tags secsel -fill [$canv cget -selectbackground]]
2430 $canv lower $t
2430 $canv lower $t
2431 $canv2 delete secsel
2431 $canv2 delete secsel
2432 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2432 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2433 -tags secsel -fill [$canv2 cget -selectbackground]]
2433 -tags secsel -fill [$canv2 cget -selectbackground]]
2434 $canv2 lower $t
2434 $canv2 lower $t
2435 $canv3 delete secsel
2435 $canv3 delete secsel
2436 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2436 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2437 -tags secsel -fill [$canv3 cget -selectbackground]]
2437 -tags secsel -fill [$canv3 cget -selectbackground]]
2438 $canv3 lower $t
2438 $canv3 lower $t
2439 set y [expr {$canvy0 + $l * $linespc}]
2439 set y [expr {$canvy0 + $l * $linespc}]
2440 set ymax [lindex [$canv cget -scrollregion] 3]
2440 set ymax [lindex [$canv cget -scrollregion] 3]
2441 set ytop [expr {$y - $linespc - 1}]
2441 set ytop [expr {$y - $linespc - 1}]
2442 set ybot [expr {$y + $linespc + 1}]
2442 set ybot [expr {$y + $linespc + 1}]
2443 set wnow [$canv yview]
2443 set wnow [$canv yview]
2444 set wtop [expr [lindex $wnow 0] * $ymax]
2444 set wtop [expr [lindex $wnow 0] * $ymax]
2445 set wbot [expr [lindex $wnow 1] * $ymax]
2445 set wbot [expr [lindex $wnow 1] * $ymax]
2446 set wh [expr {$wbot - $wtop}]
2446 set wh [expr {$wbot - $wtop}]
2447 set newtop $wtop
2447 set newtop $wtop
2448 if {$ytop < $wtop} {
2448 if {$ytop < $wtop} {
2449 if {$ybot < $wtop} {
2449 if {$ybot < $wtop} {
2450 set newtop [expr {$y - $wh / 2.0}]
2450 set newtop [expr {$y - $wh / 2.0}]
2451 } else {
2451 } else {
2452 set newtop $ytop
2452 set newtop $ytop
2453 if {$newtop > $wtop - $linespc} {
2453 if {$newtop > $wtop - $linespc} {
2454 set newtop [expr {$wtop - $linespc}]
2454 set newtop [expr {$wtop - $linespc}]
2455 }
2455 }
2456 }
2456 }
2457 } elseif {$ybot > $wbot} {
2457 } elseif {$ybot > $wbot} {
2458 if {$ytop > $wbot} {
2458 if {$ytop > $wbot} {
2459 set newtop [expr {$y - $wh / 2.0}]
2459 set newtop [expr {$y - $wh / 2.0}]
2460 } else {
2460 } else {
2461 set newtop [expr {$ybot - $wh}]
2461 set newtop [expr {$ybot - $wh}]
2462 if {$newtop < $wtop + $linespc} {
2462 if {$newtop < $wtop + $linespc} {
2463 set newtop [expr {$wtop + $linespc}]
2463 set newtop [expr {$wtop + $linespc}]
2464 }
2464 }
2465 }
2465 }
2466 }
2466 }
2467 if {$newtop != $wtop} {
2467 if {$newtop != $wtop} {
2468 if {$newtop < 0} {
2468 if {$newtop < 0} {
2469 set newtop 0
2469 set newtop 0
2470 }
2470 }
2471 allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
2471 allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
2472 }
2472 }
2473
2473
2474 if {$isnew} {
2474 if {$isnew} {
2475 addtohistory [list selectline $l 0]
2475 addtohistory [list selectline $l 0]
2476 }
2476 }
2477
2477
2478 set selectedline $l
2478 set selectedline $l
2479
2479
2480 set id $lineid($l)
2480 set id $lineid($l)
2481 set currentid $id
2481 set currentid $id
2482 $sha1entry delete 0 end
2482 $sha1entry delete 0 end
2483 $sha1entry insert 0 $id
2483 $sha1entry insert 0 $id
2484 $sha1entry selection range 0 end
2484 $sha1entry selection range 0 end
2485
2485
2486 $ctext conf -state normal
2486 $ctext conf -state normal
2487 $ctext delete 0.0 end
2487 $ctext delete 0.0 end
2488 set linknum 0
2488 set linknum 0
2489 $ctext mark set fmark.0 0.0
2489 $ctext mark set fmark.0 0.0
2490 $ctext mark gravity fmark.0 left
2490 $ctext mark gravity fmark.0 left
2491 set info $commitinfo($id)
2491 set info $commitinfo($id)
2492 $ctext insert end "Changeset: [lindex $info 6]\n"
2492 $ctext insert end "Changeset: [lindex $info 6]\n"
2493 if {[llength [lindex $info 7]] > 0} {
2493 if {[llength [lindex $info 7]] > 0} {
2494 $ctext insert end "Branch: [lindex $info 7]\n"
2494 $ctext insert end "Branch: [lindex $info 7]\n"
2495 }
2495 }
2496 $ctext insert end "User: [lindex $info 1]\n"
2496 $ctext insert end "User: [lindex $info 1]\n"
2497 $ctext insert end "Date: [lindex $info 2]\n"
2497 $ctext insert end "Date: [lindex $info 2]\n"
2498 if {[info exists idbookmarks($id)]} {
2498 if {[info exists idbookmarks($id)]} {
2499 $ctext insert end "Bookmarks:"
2499 $ctext insert end "Bookmarks:"
2500 foreach bookmark $idbookmarks($id) {
2500 foreach bookmark $idbookmarks($id) {
2501 $ctext insert end " $bookmark"
2501 $ctext insert end " $bookmark"
2502 }
2502 }
2503 $ctext insert end "\n"
2503 $ctext insert end "\n"
2504 }
2504 }
2505
2505
2506 if {[info exists idtags($id)]} {
2506 if {[info exists idtags($id)]} {
2507 $ctext insert end "Tags:"
2507 $ctext insert end "Tags:"
2508 foreach tag $idtags($id) {
2508 foreach tag $idtags($id) {
2509 $ctext insert end " $tag"
2509 $ctext insert end " $tag"
2510 }
2510 }
2511 $ctext insert end "\n"
2511 $ctext insert end "\n"
2512 }
2512 }
2513
2513
2514 set comment {}
2514 set comment {}
2515 if {[info exists parents($id)]} {
2515 if {[info exists parents($id)]} {
2516 foreach p $parents($id) {
2516 foreach p $parents($id) {
2517 append comment "Parent: [commit_descriptor $p]\n"
2517 append comment "Parent: [commit_descriptor $p]\n"
2518 }
2518 }
2519 }
2519 }
2520 if {[info exists children($id)]} {
2520 if {[info exists children($id)]} {
2521 foreach c $children($id) {
2521 foreach c $children($id) {
2522 append comment "Child: [commit_descriptor $c]\n"
2522 append comment "Child: [commit_descriptor $c]\n"
2523 }
2523 }
2524 }
2524 }
2525 append comment "\n"
2525 append comment "\n"
2526 append comment [lindex $info 5]
2526 append comment [lindex $info 5]
2527
2527
2528 # make anything that looks like a SHA1 ID be a clickable link
2528 # make anything that looks like a SHA1 ID be a clickable link
2529 appendwithlinks $comment
2529 appendwithlinks $comment
2530
2530
2531 $ctext tag delete Comments
2531 $ctext tag delete Comments
2532 $ctext tag remove found 1.0 end
2532 $ctext tag remove found 1.0 end
2533 $ctext conf -state disabled
2533 $ctext conf -state disabled
2534 set commentend [$ctext index "end - 1c"]
2534 set commentend [$ctext index "end - 1c"]
2535
2535
2536 $cflist delete 0 end
2536 $cflist delete 0 end
2537 $cflist insert end "Comments"
2537 $cflist insert end "Comments"
2538 if {$nparents($id) <= 1} {
2538 if {$nparents($id) <= 1} {
2539 set parent "null"
2539 set parent "null"
2540 if {$nparents($id) == 1} {
2540 if {$nparents($id) == 1} {
2541 set parent $parents($id)
2541 set parent $parents($id)
2542 }
2542 }
2543 startdiff [concat $id $parent]
2543 startdiff [concat $id $parent]
2544 } elseif {$nparents($id) > 1} {
2544 } elseif {$nparents($id) > 1} {
2545 mergediff $id
2545 mergediff $id
2546 }
2546 }
2547 }
2547 }
2548
2548
2549 proc selnextline {dir} {
2549 proc selnextline {dir} {
2550 global selectedline
2550 global selectedline
2551 if {![info exists selectedline]} return
2551 if {![info exists selectedline]} return
2552 set l [expr $selectedline + $dir]
2552 set l [expr $selectedline + $dir]
2553 unmarkmatches
2553 unmarkmatches
2554 selectline $l 1
2554 selectline $l 1
2555 }
2555 }
2556
2556
2557 proc unselectline {} {
2557 proc unselectline {} {
2558 global selectedline
2558 global selectedline
2559
2559
2560 catch {unset selectedline}
2560 catch {unset selectedline}
2561 allcanvs delete secsel
2561 allcanvs delete secsel
2562 }
2562 }
2563
2563
2564 proc addtohistory {cmd} {
2564 proc addtohistory {cmd} {
2565 global history historyindex
2565 global history historyindex
2566
2566
2567 if {$historyindex > 0
2567 if {$historyindex > 0
2568 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2568 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2569 return
2569 return
2570 }
2570 }
2571
2571
2572 if {$historyindex < [llength $history]} {
2572 if {$historyindex < [llength $history]} {
2573 set history [lreplace $history $historyindex end $cmd]
2573 set history [lreplace $history $historyindex end $cmd]
2574 } else {
2574 } else {
2575 lappend history $cmd
2575 lappend history $cmd
2576 }
2576 }
2577 incr historyindex
2577 incr historyindex
2578 if {$historyindex > 1} {
2578 if {$historyindex > 1} {
2579 .ctop.top.bar.leftbut conf -state normal
2579 .ctop.top.bar.leftbut conf -state normal
2580 } else {
2580 } else {
2581 .ctop.top.bar.leftbut conf -state disabled
2581 .ctop.top.bar.leftbut conf -state disabled
2582 }
2582 }
2583 .ctop.top.bar.rightbut conf -state disabled
2583 .ctop.top.bar.rightbut conf -state disabled
2584 }
2584 }
2585
2585
2586 proc goback {} {
2586 proc goback {} {
2587 global history historyindex
2587 global history historyindex
2588
2588
2589 if {$historyindex > 1} {
2589 if {$historyindex > 1} {
2590 incr historyindex -1
2590 incr historyindex -1
2591 set cmd [lindex $history [expr {$historyindex - 1}]]
2591 set cmd [lindex $history [expr {$historyindex - 1}]]
2592 eval $cmd
2592 eval $cmd
2593 .ctop.top.bar.rightbut conf -state normal
2593 .ctop.top.bar.rightbut conf -state normal
2594 }
2594 }
2595 if {$historyindex <= 1} {
2595 if {$historyindex <= 1} {
2596 .ctop.top.bar.leftbut conf -state disabled
2596 .ctop.top.bar.leftbut conf -state disabled
2597 }
2597 }
2598 }
2598 }
2599
2599
2600 proc goforw {} {
2600 proc goforw {} {
2601 global history historyindex
2601 global history historyindex
2602
2602
2603 if {$historyindex < [llength $history]} {
2603 if {$historyindex < [llength $history]} {
2604 set cmd [lindex $history $historyindex]
2604 set cmd [lindex $history $historyindex]
2605 incr historyindex
2605 incr historyindex
2606 eval $cmd
2606 eval $cmd
2607 .ctop.top.bar.leftbut conf -state normal
2607 .ctop.top.bar.leftbut conf -state normal
2608 }
2608 }
2609 if {$historyindex >= [llength $history]} {
2609 if {$historyindex >= [llength $history]} {
2610 .ctop.top.bar.rightbut conf -state disabled
2610 .ctop.top.bar.rightbut conf -state disabled
2611 }
2611 }
2612 }
2612 }
2613
2613
2614 proc mergediff {id} {
2614 proc mergediff {id} {
2615 global parents diffmergeid diffmergegca mergefilelist diffpindex
2615 global parents diffmergeid diffmergegca mergefilelist diffpindex
2616
2616
2617 set diffmergeid $id
2617 set diffmergeid $id
2618 set diffpindex -1
2618 set diffpindex -1
2619 set diffmergegca [findgca $parents($id)]
2619 set diffmergegca [findgca $parents($id)]
2620 if {[info exists mergefilelist($id)]} {
2620 if {[info exists mergefilelist($id)]} {
2621 if {$mergefilelist($id) ne {}} {
2621 if {$mergefilelist($id) ne {}} {
2622 showmergediff
2622 showmergediff
2623 }
2623 }
2624 } else {
2624 } else {
2625 contmergediff {}
2625 contmergediff {}
2626 }
2626 }
2627 }
2627 }
2628
2628
2629 proc findgca {ids} {
2629 proc findgca {ids} {
2630 global env
2630 global env
2631 set gca {}
2631 set gca {}
2632 foreach id $ids {
2632 foreach id $ids {
2633 if {$gca eq {}} {
2633 if {$gca eq {}} {
2634 set gca $id
2634 set gca $id
2635 } else {
2635 } else {
2636 if {[catch {
2636 if {[catch {
2637 set gca [exec $env(HG) --config ui.report_untrusted=false debug-merge-base $gca $id]
2637 set gca [exec $env(HG) --config ui.report_untrusted=false debug-merge-base $gca $id]
2638 } err]} {
2638 } err]} {
2639 return {}
2639 return {}
2640 }
2640 }
2641 }
2641 }
2642 }
2642 }
2643 return $gca
2643 return $gca
2644 }
2644 }
2645
2645
2646 proc contmergediff {ids} {
2646 proc contmergediff {ids} {
2647 global diffmergeid diffpindex parents nparents diffmergegca
2647 global diffmergeid diffpindex parents nparents diffmergegca
2648 global treediffs mergefilelist diffids treepending
2648 global treediffs mergefilelist diffids treepending
2649
2649
2650 # diff the child against each of the parents, and diff
2650 # diff the child against each of the parents, and diff
2651 # each of the parents against the GCA.
2651 # each of the parents against the GCA.
2652 while 1 {
2652 while 1 {
2653 if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
2653 if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
2654 set ids [list [lindex $ids 1] $diffmergegca]
2654 set ids [list [lindex $ids 1] $diffmergegca]
2655 } else {
2655 } else {
2656 if {[incr diffpindex] >= $nparents($diffmergeid)} break
2656 if {[incr diffpindex] >= $nparents($diffmergeid)} break
2657 set p [lindex $parents($diffmergeid) $diffpindex]
2657 set p [lindex $parents($diffmergeid) $diffpindex]
2658 set ids [list $diffmergeid $p]
2658 set ids [list $diffmergeid $p]
2659 }
2659 }
2660 if {![info exists treediffs($ids)]} {
2660 if {![info exists treediffs($ids)]} {
2661 set diffids $ids
2661 set diffids $ids
2662 if {![info exists treepending]} {
2662 if {![info exists treepending]} {
2663 gettreediffs $ids
2663 gettreediffs $ids
2664 }
2664 }
2665 return
2665 return
2666 }
2666 }
2667 }
2667 }
2668
2668
2669 # If a file in some parent is different from the child and also
2669 # If a file in some parent is different from the child and also
2670 # different from the GCA, then it's interesting.
2670 # different from the GCA, then it's interesting.
2671 # If we don't have a GCA, then a file is interesting if it is
2671 # If we don't have a GCA, then a file is interesting if it is
2672 # different from the child in all the parents.
2672 # different from the child in all the parents.
2673 if {$diffmergegca ne {}} {
2673 if {$diffmergegca ne {}} {
2674 set files {}
2674 set files {}
2675 foreach p $parents($diffmergeid) {
2675 foreach p $parents($diffmergeid) {
2676 set gcadiffs $treediffs([list $p $diffmergegca])
2676 set gcadiffs $treediffs([list $p $diffmergegca])
2677 foreach f $treediffs([list $diffmergeid $p]) {
2677 foreach f $treediffs([list $diffmergeid $p]) {
2678 if {[lsearch -exact $files $f] < 0
2678 if {[lsearch -exact $files $f] < 0
2679 && [lsearch -exact $gcadiffs $f] >= 0} {
2679 && [lsearch -exact $gcadiffs $f] >= 0} {
2680 lappend files $f
2680 lappend files $f
2681 }
2681 }
2682 }
2682 }
2683 }
2683 }
2684 set files [lsort $files]
2684 set files [lsort $files]
2685 } else {
2685 } else {
2686 set p [lindex $parents($diffmergeid) 0]
2686 set p [lindex $parents($diffmergeid) 0]
2687 set files $treediffs([list $diffmergeid $p])
2687 set files $treediffs([list $diffmergeid $p])
2688 for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
2688 for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
2689 set p [lindex $parents($diffmergeid) $i]
2689 set p [lindex $parents($diffmergeid) $i]
2690 set df $treediffs([list $diffmergeid $p])
2690 set df $treediffs([list $diffmergeid $p])
2691 set nf {}
2691 set nf {}
2692 foreach f $files {
2692 foreach f $files {
2693 if {[lsearch -exact $df $f] >= 0} {
2693 if {[lsearch -exact $df $f] >= 0} {
2694 lappend nf $f
2694 lappend nf $f
2695 }
2695 }
2696 }
2696 }
2697 set files $nf
2697 set files $nf
2698 }
2698 }
2699 }
2699 }
2700
2700
2701 set mergefilelist($diffmergeid) $files
2701 set mergefilelist($diffmergeid) $files
2702 if {$files ne {}} {
2702 if {$files ne {}} {
2703 showmergediff
2703 showmergediff
2704 }
2704 }
2705 }
2705 }
2706
2706
2707 proc showmergediff {} {
2707 proc showmergediff {} {
2708 global cflist diffmergeid mergefilelist parents
2708 global cflist diffmergeid mergefilelist parents
2709 global diffopts diffinhunk currentfile currenthunk filelines
2709 global diffopts diffinhunk currentfile currenthunk filelines
2710 global diffblocked groupfilelast mergefds groupfilenum grouphunks
2710 global diffblocked groupfilelast mergefds groupfilenum grouphunks
2711 global env
2711 global env
2712
2712
2713 set files $mergefilelist($diffmergeid)
2713 set files $mergefilelist($diffmergeid)
2714 foreach f $files {
2714 foreach f $files {
2715 $cflist insert end $f
2715 $cflist insert end $f
2716 }
2716 }
2717 set env(GIT_DIFF_OPTS) $diffopts
2717 set env(GIT_DIFF_OPTS) $diffopts
2718 set flist {}
2718 set flist {}
2719 catch {unset currentfile}
2719 catch {unset currentfile}
2720 catch {unset currenthunk}
2720 catch {unset currenthunk}
2721 catch {unset filelines}
2721 catch {unset filelines}
2722 catch {unset groupfilenum}
2722 catch {unset groupfilenum}
2723 catch {unset grouphunks}
2723 catch {unset grouphunks}
2724 set groupfilelast -1
2724 set groupfilelast -1
2725 foreach p $parents($diffmergeid) {
2725 foreach p $parents($diffmergeid) {
2726 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $p $diffmergeid]
2726 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $p $diffmergeid]
2727 set cmd [concat $cmd $mergefilelist($diffmergeid)]
2727 set cmd [concat $cmd $mergefilelist($diffmergeid)]
2728 if {[catch {set f [open $cmd r]} err]} {
2728 if {[catch {set f [open $cmd r]} err]} {
2729 error_popup "Error getting diffs: $err"
2729 error_popup "Error getting diffs: $err"
2730 foreach f $flist {
2730 foreach f $flist {
2731 catch {close $f}
2731 catch {close $f}
2732 }
2732 }
2733 return
2733 return
2734 }
2734 }
2735 lappend flist $f
2735 lappend flist $f
2736 set ids [list $diffmergeid $p]
2736 set ids [list $diffmergeid $p]
2737 set mergefds($ids) $f
2737 set mergefds($ids) $f
2738 set diffinhunk($ids) 0
2738 set diffinhunk($ids) 0
2739 set diffblocked($ids) 0
2739 set diffblocked($ids) 0
2740 fconfigure $f -blocking 0
2740 fconfigure $f -blocking 0
2741 fileevent $f readable [list getmergediffline $f $ids $diffmergeid]
2741 fileevent $f readable [list getmergediffline $f $ids $diffmergeid]
2742 }
2742 }
2743 }
2743 }
2744
2744
2745 proc getmergediffline {f ids id} {
2745 proc getmergediffline {f ids id} {
2746 global diffmergeid diffinhunk diffoldlines diffnewlines
2746 global diffmergeid diffinhunk diffoldlines diffnewlines
2747 global currentfile currenthunk
2747 global currentfile currenthunk
2748 global diffoldstart diffnewstart diffoldlno diffnewlno
2748 global diffoldstart diffnewstart diffoldlno diffnewlno
2749 global diffblocked mergefilelist
2749 global diffblocked mergefilelist
2750 global noldlines nnewlines difflcounts filelines
2750 global noldlines nnewlines difflcounts filelines
2751
2751
2752 set n [gets $f line]
2752 set n [gets $f line]
2753 if {$n < 0} {
2753 if {$n < 0} {
2754 if {![eof $f]} return
2754 if {![eof $f]} return
2755 }
2755 }
2756
2756
2757 if {!([info exists diffmergeid] && $diffmergeid == $id)} {
2757 if {!([info exists diffmergeid] && $diffmergeid == $id)} {
2758 if {$n < 0} {
2758 if {$n < 0} {
2759 close $f
2759 close $f
2760 }
2760 }
2761 return
2761 return
2762 }
2762 }
2763
2763
2764 if {$diffinhunk($ids) != 0} {
2764 if {$diffinhunk($ids) != 0} {
2765 set fi $currentfile($ids)
2765 set fi $currentfile($ids)
2766 if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
2766 if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
2767 # continuing an existing hunk
2767 # continuing an existing hunk
2768 set line [string range $line 1 end]
2768 set line [string range $line 1 end]
2769 set p [lindex $ids 1]
2769 set p [lindex $ids 1]
2770 if {$match eq "-" || $match eq " "} {
2770 if {$match eq "-" || $match eq " "} {
2771 set filelines($p,$fi,$diffoldlno($ids)) $line
2771 set filelines($p,$fi,$diffoldlno($ids)) $line
2772 incr diffoldlno($ids)
2772 incr diffoldlno($ids)
2773 }
2773 }
2774 if {$match eq "+" || $match eq " "} {
2774 if {$match eq "+" || $match eq " "} {
2775 set filelines($id,$fi,$diffnewlno($ids)) $line
2775 set filelines($id,$fi,$diffnewlno($ids)) $line
2776 incr diffnewlno($ids)
2776 incr diffnewlno($ids)
2777 }
2777 }
2778 if {$match eq " "} {
2778 if {$match eq " "} {
2779 if {$diffinhunk($ids) == 2} {
2779 if {$diffinhunk($ids) == 2} {
2780 lappend difflcounts($ids) \
2780 lappend difflcounts($ids) \
2781 [list $noldlines($ids) $nnewlines($ids)]
2781 [list $noldlines($ids) $nnewlines($ids)]
2782 set noldlines($ids) 0
2782 set noldlines($ids) 0
2783 set diffinhunk($ids) 1
2783 set diffinhunk($ids) 1
2784 }
2784 }
2785 incr noldlines($ids)
2785 incr noldlines($ids)
2786 } elseif {$match eq "-" || $match eq "+"} {
2786 } elseif {$match eq "-" || $match eq "+"} {
2787 if {$diffinhunk($ids) == 1} {
2787 if {$diffinhunk($ids) == 1} {
2788 lappend difflcounts($ids) [list $noldlines($ids)]
2788 lappend difflcounts($ids) [list $noldlines($ids)]
2789 set noldlines($ids) 0
2789 set noldlines($ids) 0
2790 set nnewlines($ids) 0
2790 set nnewlines($ids) 0
2791 set diffinhunk($ids) 2
2791 set diffinhunk($ids) 2
2792 }
2792 }
2793 if {$match eq "-"} {
2793 if {$match eq "-"} {
2794 incr noldlines($ids)
2794 incr noldlines($ids)
2795 } else {
2795 } else {
2796 incr nnewlines($ids)
2796 incr nnewlines($ids)
2797 }
2797 }
2798 }
2798 }
2799 # and if it's \ No newline at end of line, then what?
2799 # and if it's \ No newline at end of line, then what?
2800 return
2800 return
2801 }
2801 }
2802 # end of a hunk
2802 # end of a hunk
2803 if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
2803 if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
2804 lappend difflcounts($ids) [list $noldlines($ids)]
2804 lappend difflcounts($ids) [list $noldlines($ids)]
2805 } elseif {$diffinhunk($ids) == 2
2805 } elseif {$diffinhunk($ids) == 2
2806 && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
2806 && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
2807 lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
2807 lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
2808 }
2808 }
2809 set currenthunk($ids) [list $currentfile($ids) \
2809 set currenthunk($ids) [list $currentfile($ids) \
2810 $diffoldstart($ids) $diffnewstart($ids) \
2810 $diffoldstart($ids) $diffnewstart($ids) \
2811 $diffoldlno($ids) $diffnewlno($ids) \
2811 $diffoldlno($ids) $diffnewlno($ids) \
2812 $difflcounts($ids)]
2812 $difflcounts($ids)]
2813 set diffinhunk($ids) 0
2813 set diffinhunk($ids) 0
2814 # -1 = need to block, 0 = unblocked, 1 = is blocked
2814 # -1 = need to block, 0 = unblocked, 1 = is blocked
2815 set diffblocked($ids) -1
2815 set diffblocked($ids) -1
2816 processhunks
2816 processhunks
2817 if {$diffblocked($ids) == -1} {
2817 if {$diffblocked($ids) == -1} {
2818 fileevent $f readable {}
2818 fileevent $f readable {}
2819 set diffblocked($ids) 1
2819 set diffblocked($ids) 1
2820 }
2820 }
2821 }
2821 }
2822
2822
2823 if {$n < 0} {
2823 if {$n < 0} {
2824 # eof
2824 # eof
2825 if {!$diffblocked($ids)} {
2825 if {!$diffblocked($ids)} {
2826 close $f
2826 close $f
2827 set currentfile($ids) [llength $mergefilelist($diffmergeid)]
2827 set currentfile($ids) [llength $mergefilelist($diffmergeid)]
2828 set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
2828 set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
2829 processhunks
2829 processhunks
2830 }
2830 }
2831 } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
2831 } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
2832 # start of a new file
2832 # start of a new file
2833 set currentfile($ids) \
2833 set currentfile($ids) \
2834 [lsearch -exact $mergefilelist($diffmergeid) $fname]
2834 [lsearch -exact $mergefilelist($diffmergeid) $fname]
2835 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2835 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2836 $line match f1l f1c f2l f2c rest]} {
2836 $line match f1l f1c f2l f2c rest]} {
2837 if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
2837 if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
2838 # start of a new hunk
2838 # start of a new hunk
2839 if {$f1l == 0 && $f1c == 0} {
2839 if {$f1l == 0 && $f1c == 0} {
2840 set f1l 1
2840 set f1l 1
2841 }
2841 }
2842 if {$f2l == 0 && $f2c == 0} {
2842 if {$f2l == 0 && $f2c == 0} {
2843 set f2l 1
2843 set f2l 1
2844 }
2844 }
2845 set diffinhunk($ids) 1
2845 set diffinhunk($ids) 1
2846 set diffoldstart($ids) $f1l
2846 set diffoldstart($ids) $f1l
2847 set diffnewstart($ids) $f2l
2847 set diffnewstart($ids) $f2l
2848 set diffoldlno($ids) $f1l
2848 set diffoldlno($ids) $f1l
2849 set diffnewlno($ids) $f2l
2849 set diffnewlno($ids) $f2l
2850 set difflcounts($ids) {}
2850 set difflcounts($ids) {}
2851 set noldlines($ids) 0
2851 set noldlines($ids) 0
2852 set nnewlines($ids) 0
2852 set nnewlines($ids) 0
2853 }
2853 }
2854 }
2854 }
2855 }
2855 }
2856
2856
2857 proc processhunks {} {
2857 proc processhunks {} {
2858 global diffmergeid parents nparents currenthunk
2858 global diffmergeid parents nparents currenthunk
2859 global mergefilelist diffblocked mergefds
2859 global mergefilelist diffblocked mergefds
2860 global grouphunks grouplinestart grouplineend groupfilenum
2860 global grouphunks grouplinestart grouplineend groupfilenum
2861
2861
2862 set nfiles [llength $mergefilelist($diffmergeid)]
2862 set nfiles [llength $mergefilelist($diffmergeid)]
2863 while 1 {
2863 while 1 {
2864 set fi $nfiles
2864 set fi $nfiles
2865 set lno 0
2865 set lno 0
2866 # look for the earliest hunk
2866 # look for the earliest hunk
2867 foreach p $parents($diffmergeid) {
2867 foreach p $parents($diffmergeid) {
2868 set ids [list $diffmergeid $p]
2868 set ids [list $diffmergeid $p]
2869 if {![info exists currenthunk($ids)]} return
2869 if {![info exists currenthunk($ids)]} return
2870 set i [lindex $currenthunk($ids) 0]
2870 set i [lindex $currenthunk($ids) 0]
2871 set l [lindex $currenthunk($ids) 2]
2871 set l [lindex $currenthunk($ids) 2]
2872 if {$i < $fi || ($i == $fi && $l < $lno)} {
2872 if {$i < $fi || ($i == $fi && $l < $lno)} {
2873 set fi $i
2873 set fi $i
2874 set lno $l
2874 set lno $l
2875 set pi $p
2875 set pi $p
2876 }
2876 }
2877 }
2877 }
2878
2878
2879 if {$fi < $nfiles} {
2879 if {$fi < $nfiles} {
2880 set ids [list $diffmergeid $pi]
2880 set ids [list $diffmergeid $pi]
2881 set hunk $currenthunk($ids)
2881 set hunk $currenthunk($ids)
2882 unset currenthunk($ids)
2882 unset currenthunk($ids)
2883 if {$diffblocked($ids) > 0} {
2883 if {$diffblocked($ids) > 0} {
2884 fileevent $mergefds($ids) readable \
2884 fileevent $mergefds($ids) readable \
2885 [list getmergediffline $mergefds($ids) $ids $diffmergeid]
2885 [list getmergediffline $mergefds($ids) $ids $diffmergeid]
2886 }
2886 }
2887 set diffblocked($ids) 0
2887 set diffblocked($ids) 0
2888
2888
2889 if {[info exists groupfilenum] && $groupfilenum == $fi
2889 if {[info exists groupfilenum] && $groupfilenum == $fi
2890 && $lno <= $grouplineend} {
2890 && $lno <= $grouplineend} {
2891 # add this hunk to the pending group
2891 # add this hunk to the pending group
2892 lappend grouphunks($pi) $hunk
2892 lappend grouphunks($pi) $hunk
2893 set endln [lindex $hunk 4]
2893 set endln [lindex $hunk 4]
2894 if {$endln > $grouplineend} {
2894 if {$endln > $grouplineend} {
2895 set grouplineend $endln
2895 set grouplineend $endln
2896 }
2896 }
2897 continue
2897 continue
2898 }
2898 }
2899 }
2899 }
2900
2900
2901 # succeeding stuff doesn't belong in this group, so
2901 # succeeding stuff doesn't belong in this group, so
2902 # process the group now
2902 # process the group now
2903 if {[info exists groupfilenum]} {
2903 if {[info exists groupfilenum]} {
2904 processgroup
2904 processgroup
2905 unset groupfilenum
2905 unset groupfilenum
2906 unset grouphunks
2906 unset grouphunks
2907 }
2907 }
2908
2908
2909 if {$fi >= $nfiles} break
2909 if {$fi >= $nfiles} break
2910
2910
2911 # start a new group
2911 # start a new group
2912 set groupfilenum $fi
2912 set groupfilenum $fi
2913 set grouphunks($pi) [list $hunk]
2913 set grouphunks($pi) [list $hunk]
2914 set grouplinestart $lno
2914 set grouplinestart $lno
2915 set grouplineend [lindex $hunk 4]
2915 set grouplineend [lindex $hunk 4]
2916 }
2916 }
2917 }
2917 }
2918
2918
2919 proc processgroup {} {
2919 proc processgroup {} {
2920 global groupfilelast groupfilenum difffilestart
2920 global groupfilelast groupfilenum difffilestart
2921 global mergefilelist diffmergeid ctext filelines
2921 global mergefilelist diffmergeid ctext filelines
2922 global parents diffmergeid diffoffset
2922 global parents diffmergeid diffoffset
2923 global grouphunks grouplinestart grouplineend nparents
2923 global grouphunks grouplinestart grouplineend nparents
2924 global mergemax
2924 global mergemax
2925
2925
2926 $ctext conf -state normal
2926 $ctext conf -state normal
2927 set id $diffmergeid
2927 set id $diffmergeid
2928 set f $groupfilenum
2928 set f $groupfilenum
2929 if {$groupfilelast != $f} {
2929 if {$groupfilelast != $f} {
2930 $ctext insert end "\n"
2930 $ctext insert end "\n"
2931 set here [$ctext index "end - 1c"]
2931 set here [$ctext index "end - 1c"]
2932 set difffilestart($f) $here
2932 set difffilestart($f) $here
2933 set mark fmark.[expr {$f + 1}]
2933 set mark fmark.[expr {$f + 1}]
2934 $ctext mark set $mark $here
2934 $ctext mark set $mark $here
2935 $ctext mark gravity $mark left
2935 $ctext mark gravity $mark left
2936 set header [lindex $mergefilelist($id) $f]
2936 set header [lindex $mergefilelist($id) $f]
2937 set l [expr {(78 - [string length $header]) / 2}]
2937 set l [expr {(78 - [string length $header]) / 2}]
2938 set pad [string range "----------------------------------------" 1 $l]
2938 set pad [string range "----------------------------------------" 1 $l]
2939 $ctext insert end "$pad $header $pad\n" filesep
2939 $ctext insert end "$pad $header $pad\n" filesep
2940 set groupfilelast $f
2940 set groupfilelast $f
2941 foreach p $parents($id) {
2941 foreach p $parents($id) {
2942 set diffoffset($p) 0
2942 set diffoffset($p) 0
2943 }
2943 }
2944 }
2944 }
2945
2945
2946 $ctext insert end "@@" msep
2946 $ctext insert end "@@" msep
2947 set nlines [expr {$grouplineend - $grouplinestart}]
2947 set nlines [expr {$grouplineend - $grouplinestart}]
2948 set events {}
2948 set events {}
2949 set pnum 0
2949 set pnum 0
2950 foreach p $parents($id) {
2950 foreach p $parents($id) {
2951 set startline [expr {$grouplinestart + $diffoffset($p)}]
2951 set startline [expr {$grouplinestart + $diffoffset($p)}]
2952 set ol $startline
2952 set ol $startline
2953 set nl $grouplinestart
2953 set nl $grouplinestart
2954 if {[info exists grouphunks($p)]} {
2954 if {[info exists grouphunks($p)]} {
2955 foreach h $grouphunks($p) {
2955 foreach h $grouphunks($p) {
2956 set l [lindex $h 2]
2956 set l [lindex $h 2]
2957 if {$nl < $l} {
2957 if {$nl < $l} {
2958 for {} {$nl < $l} {incr nl} {
2958 for {} {$nl < $l} {incr nl} {
2959 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2959 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2960 incr ol
2960 incr ol
2961 }
2961 }
2962 }
2962 }
2963 foreach chunk [lindex $h 5] {
2963 foreach chunk [lindex $h 5] {
2964 if {[llength $chunk] == 2} {
2964 if {[llength $chunk] == 2} {
2965 set olc [lindex $chunk 0]
2965 set olc [lindex $chunk 0]
2966 set nlc [lindex $chunk 1]
2966 set nlc [lindex $chunk 1]
2967 set nnl [expr {$nl + $nlc}]
2967 set nnl [expr {$nl + $nlc}]
2968 lappend events [list $nl $nnl $pnum $olc $nlc]
2968 lappend events [list $nl $nnl $pnum $olc $nlc]
2969 incr ol $olc
2969 incr ol $olc
2970 set nl $nnl
2970 set nl $nnl
2971 } else {
2971 } else {
2972 incr ol [lindex $chunk 0]
2972 incr ol [lindex $chunk 0]
2973 incr nl [lindex $chunk 0]
2973 incr nl [lindex $chunk 0]
2974 }
2974 }
2975 }
2975 }
2976 }
2976 }
2977 }
2977 }
2978 if {$nl < $grouplineend} {
2978 if {$nl < $grouplineend} {
2979 for {} {$nl < $grouplineend} {incr nl} {
2979 for {} {$nl < $grouplineend} {incr nl} {
2980 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2980 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2981 incr ol
2981 incr ol
2982 }
2982 }
2983 }
2983 }
2984 set nlines [expr {$ol - $startline}]
2984 set nlines [expr {$ol - $startline}]
2985 $ctext insert end " -$startline,$nlines" msep
2985 $ctext insert end " -$startline,$nlines" msep
2986 incr pnum
2986 incr pnum
2987 }
2987 }
2988
2988
2989 set nlines [expr {$grouplineend - $grouplinestart}]
2989 set nlines [expr {$grouplineend - $grouplinestart}]
2990 $ctext insert end " +$grouplinestart,$nlines @@\n" msep
2990 $ctext insert end " +$grouplinestart,$nlines @@\n" msep
2991
2991
2992 set events [lsort -integer -index 0 $events]
2992 set events [lsort -integer -index 0 $events]
2993 set nevents [llength $events]
2993 set nevents [llength $events]
2994 set nmerge $nparents($diffmergeid)
2994 set nmerge $nparents($diffmergeid)
2995 set l $grouplinestart
2995 set l $grouplinestart
2996 for {set i 0} {$i < $nevents} {set i $j} {
2996 for {set i 0} {$i < $nevents} {set i $j} {
2997 set nl [lindex $events $i 0]
2997 set nl [lindex $events $i 0]
2998 while {$l < $nl} {
2998 while {$l < $nl} {
2999 $ctext insert end " $filelines($id,$f,$l)\n"
2999 $ctext insert end " $filelines($id,$f,$l)\n"
3000 incr l
3000 incr l
3001 }
3001 }
3002 set e [lindex $events $i]
3002 set e [lindex $events $i]
3003 set enl [lindex $e 1]
3003 set enl [lindex $e 1]
3004 set j $i
3004 set j $i
3005 set active {}
3005 set active {}
3006 while 1 {
3006 while 1 {
3007 set pnum [lindex $e 2]
3007 set pnum [lindex $e 2]
3008 set olc [lindex $e 3]
3008 set olc [lindex $e 3]
3009 set nlc [lindex $e 4]
3009 set nlc [lindex $e 4]
3010 if {![info exists delta($pnum)]} {
3010 if {![info exists delta($pnum)]} {
3011 set delta($pnum) [expr {$olc - $nlc}]
3011 set delta($pnum) [expr {$olc - $nlc}]
3012 lappend active $pnum
3012 lappend active $pnum
3013 } else {
3013 } else {
3014 incr delta($pnum) [expr {$olc - $nlc}]
3014 incr delta($pnum) [expr {$olc - $nlc}]
3015 }
3015 }
3016 if {[incr j] >= $nevents} break
3016 if {[incr j] >= $nevents} break
3017 set e [lindex $events $j]
3017 set e [lindex $events $j]
3018 if {[lindex $e 0] >= $enl} break
3018 if {[lindex $e 0] >= $enl} break
3019 if {[lindex $e 1] > $enl} {
3019 if {[lindex $e 1] > $enl} {
3020 set enl [lindex $e 1]
3020 set enl [lindex $e 1]
3021 }
3021 }
3022 }
3022 }
3023 set nlc [expr {$enl - $l}]
3023 set nlc [expr {$enl - $l}]
3024 set ncol mresult
3024 set ncol mresult
3025 set bestpn -1
3025 set bestpn -1
3026 if {[llength $active] == $nmerge - 1} {
3026 if {[llength $active] == $nmerge - 1} {
3027 # no diff for one of the parents, i.e. it's identical
3027 # no diff for one of the parents, i.e. it's identical
3028 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3028 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3029 if {![info exists delta($pnum)]} {
3029 if {![info exists delta($pnum)]} {
3030 if {$pnum < $mergemax} {
3030 if {$pnum < $mergemax} {
3031 lappend ncol m$pnum
3031 lappend ncol m$pnum
3032 } else {
3032 } else {
3033 lappend ncol mmax
3033 lappend ncol mmax
3034 }
3034 }
3035 break
3035 break
3036 }
3036 }
3037 }
3037 }
3038 } elseif {[llength $active] == $nmerge} {
3038 } elseif {[llength $active] == $nmerge} {
3039 # all parents are different, see if one is very similar
3039 # all parents are different, see if one is very similar
3040 set bestsim 30
3040 set bestsim 30
3041 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3041 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3042 set sim [similarity $pnum $l $nlc $f \
3042 set sim [similarity $pnum $l $nlc $f \
3043 [lrange $events $i [expr {$j-1}]]]
3043 [lrange $events $i [expr {$j-1}]]]
3044 if {$sim > $bestsim} {
3044 if {$sim > $bestsim} {
3045 set bestsim $sim
3045 set bestsim $sim
3046 set bestpn $pnum
3046 set bestpn $pnum
3047 }
3047 }
3048 }
3048 }
3049 if {$bestpn >= 0} {
3049 if {$bestpn >= 0} {
3050 lappend ncol m$bestpn
3050 lappend ncol m$bestpn
3051 }
3051 }
3052 }
3052 }
3053 set pnum -1
3053 set pnum -1
3054 foreach p $parents($id) {
3054 foreach p $parents($id) {
3055 incr pnum
3055 incr pnum
3056 if {![info exists delta($pnum)] || $pnum == $bestpn} continue
3056 if {![info exists delta($pnum)] || $pnum == $bestpn} continue
3057 set olc [expr {$nlc + $delta($pnum)}]
3057 set olc [expr {$nlc + $delta($pnum)}]
3058 set ol [expr {$l + $diffoffset($p)}]
3058 set ol [expr {$l + $diffoffset($p)}]
3059 incr diffoffset($p) $delta($pnum)
3059 incr diffoffset($p) $delta($pnum)
3060 unset delta($pnum)
3060 unset delta($pnum)
3061 for {} {$olc > 0} {incr olc -1} {
3061 for {} {$olc > 0} {incr olc -1} {
3062 $ctext insert end "-$filelines($p,$f,$ol)\n" m$pnum
3062 $ctext insert end "-$filelines($p,$f,$ol)\n" m$pnum
3063 incr ol
3063 incr ol
3064 }
3064 }
3065 }
3065 }
3066 set endl [expr {$l + $nlc}]
3066 set endl [expr {$l + $nlc}]
3067 if {$bestpn >= 0} {
3067 if {$bestpn >= 0} {
3068 # show this pretty much as a normal diff
3068 # show this pretty much as a normal diff
3069 set p [lindex $parents($id) $bestpn]
3069 set p [lindex $parents($id) $bestpn]
3070 set ol [expr {$l + $diffoffset($p)}]
3070 set ol [expr {$l + $diffoffset($p)}]
3071 incr diffoffset($p) $delta($bestpn)
3071 incr diffoffset($p) $delta($bestpn)
3072 unset delta($bestpn)
3072 unset delta($bestpn)
3073 for {set k $i} {$k < $j} {incr k} {
3073 for {set k $i} {$k < $j} {incr k} {
3074 set e [lindex $events $k]
3074 set e [lindex $events $k]
3075 if {[lindex $e 2] != $bestpn} continue
3075 if {[lindex $e 2] != $bestpn} continue
3076 set nl [lindex $e 0]
3076 set nl [lindex $e 0]
3077 set ol [expr {$ol + $nl - $l}]
3077 set ol [expr {$ol + $nl - $l}]
3078 for {} {$l < $nl} {incr l} {
3078 for {} {$l < $nl} {incr l} {
3079 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3079 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3080 }
3080 }
3081 set c [lindex $e 3]
3081 set c [lindex $e 3]
3082 for {} {$c > 0} {incr c -1} {
3082 for {} {$c > 0} {incr c -1} {
3083 $ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
3083 $ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
3084 incr ol
3084 incr ol
3085 }
3085 }
3086 set nl [lindex $e 1]
3086 set nl [lindex $e 1]
3087 for {} {$l < $nl} {incr l} {
3087 for {} {$l < $nl} {incr l} {
3088 $ctext insert end "+$filelines($id,$f,$l)\n" mresult
3088 $ctext insert end "+$filelines($id,$f,$l)\n" mresult
3089 }
3089 }
3090 }
3090 }
3091 }
3091 }
3092 for {} {$l < $endl} {incr l} {
3092 for {} {$l < $endl} {incr l} {
3093 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3093 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3094 }
3094 }
3095 }
3095 }
3096 while {$l < $grouplineend} {
3096 while {$l < $grouplineend} {
3097 $ctext insert end " $filelines($id,$f,$l)\n"
3097 $ctext insert end " $filelines($id,$f,$l)\n"
3098 incr l
3098 incr l
3099 }
3099 }
3100 $ctext conf -state disabled
3100 $ctext conf -state disabled
3101 }
3101 }
3102
3102
3103 proc similarity {pnum l nlc f events} {
3103 proc similarity {pnum l nlc f events} {
3104 global diffmergeid parents diffoffset filelines
3104 global diffmergeid parents diffoffset filelines
3105
3105
3106 set id $diffmergeid
3106 set id $diffmergeid
3107 set p [lindex $parents($id) $pnum]
3107 set p [lindex $parents($id) $pnum]
3108 set ol [expr {$l + $diffoffset($p)}]
3108 set ol [expr {$l + $diffoffset($p)}]
3109 set endl [expr {$l + $nlc}]
3109 set endl [expr {$l + $nlc}]
3110 set same 0
3110 set same 0
3111 set diff 0
3111 set diff 0
3112 foreach e $events {
3112 foreach e $events {
3113 if {[lindex $e 2] != $pnum} continue
3113 if {[lindex $e 2] != $pnum} continue
3114 set nl [lindex $e 0]
3114 set nl [lindex $e 0]
3115 set ol [expr {$ol + $nl - $l}]
3115 set ol [expr {$ol + $nl - $l}]
3116 for {} {$l < $nl} {incr l} {
3116 for {} {$l < $nl} {incr l} {
3117 incr same [string length $filelines($id,$f,$l)]
3117 incr same [string length $filelines($id,$f,$l)]
3118 incr same
3118 incr same
3119 }
3119 }
3120 set oc [lindex $e 3]
3120 set oc [lindex $e 3]
3121 for {} {$oc > 0} {incr oc -1} {
3121 for {} {$oc > 0} {incr oc -1} {
3122 incr diff [string length $filelines($p,$f,$ol)]
3122 incr diff [string length $filelines($p,$f,$ol)]
3123 incr diff
3123 incr diff
3124 incr ol
3124 incr ol
3125 }
3125 }
3126 set nl [lindex $e 1]
3126 set nl [lindex $e 1]
3127 for {} {$l < $nl} {incr l} {
3127 for {} {$l < $nl} {incr l} {
3128 incr diff [string length $filelines($id,$f,$l)]
3128 incr diff [string length $filelines($id,$f,$l)]
3129 incr diff
3129 incr diff
3130 }
3130 }
3131 }
3131 }
3132 for {} {$l < $endl} {incr l} {
3132 for {} {$l < $endl} {incr l} {
3133 incr same [string length $filelines($id,$f,$l)]
3133 incr same [string length $filelines($id,$f,$l)]
3134 incr same
3134 incr same
3135 }
3135 }
3136 if {$same == 0} {
3136 if {$same == 0} {
3137 return 0
3137 return 0
3138 }
3138 }
3139 return [expr {200 * $same / (2 * $same + $diff)}]
3139 return [expr {200 * $same / (2 * $same + $diff)}]
3140 }
3140 }
3141
3141
3142 proc startdiff {ids} {
3142 proc startdiff {ids} {
3143 global treediffs diffids treepending diffmergeid
3143 global treediffs diffids treepending diffmergeid
3144
3144
3145 set diffids $ids
3145 set diffids $ids
3146 catch {unset diffmergeid}
3146 catch {unset diffmergeid}
3147 if {![info exists treediffs($ids)]} {
3147 if {![info exists treediffs($ids)]} {
3148 if {![info exists treepending]} {
3148 if {![info exists treepending]} {
3149 gettreediffs $ids
3149 gettreediffs $ids
3150 }
3150 }
3151 } else {
3151 } else {
3152 addtocflist $ids
3152 addtocflist $ids
3153 }
3153 }
3154 }
3154 }
3155
3155
3156 proc addtocflist {ids} {
3156 proc addtocflist {ids} {
3157 global treediffs cflist
3157 global treediffs cflist
3158 foreach f $treediffs($ids) {
3158 foreach f $treediffs($ids) {
3159 $cflist insert end $f
3159 $cflist insert end $f
3160 }
3160 }
3161 getblobdiffs $ids
3161 getblobdiffs $ids
3162 }
3162 }
3163
3163
3164 proc gettreediffs {ids} {
3164 proc gettreediffs {ids} {
3165 global treediff parents treepending env
3165 global treediff parents treepending env
3166 set treepending $ids
3166 set treepending $ids
3167 set treediff {}
3167 set treediff {}
3168 set id [lindex $ids 0]
3168 set id [lindex $ids 0]
3169 set p [lindex $ids 1]
3169 set p [lindex $ids 1]
3170 if [catch {set gdtf [open "|{$env(HG)} --config ui.report_untrusted=false debug-diff-tree -r $p $id" r]}] return
3170 if [catch {set gdtf [open "|{$env(HG)} --config ui.report_untrusted=false debug-diff-tree -r $p $id" r]}] return
3171 fconfigure $gdtf -blocking 0
3171 fconfigure $gdtf -blocking 0
3172 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
3172 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
3173 }
3173 }
3174
3174
3175 proc gettreediffline {gdtf ids} {
3175 proc gettreediffline {gdtf ids} {
3176 global treediff treediffs treepending diffids diffmergeid
3176 global treediff treediffs treepending diffids diffmergeid
3177
3177
3178 set n [gets $gdtf line]
3178 set n [gets $gdtf line]
3179 if {$n < 0} {
3179 if {$n < 0} {
3180 if {![eof $gdtf]} return
3180 if {![eof $gdtf]} return
3181 close $gdtf
3181 close $gdtf
3182 set treediffs($ids) $treediff
3182 set treediffs($ids) $treediff
3183 unset treepending
3183 unset treepending
3184 if {$ids != $diffids} {
3184 if {$ids != $diffids} {
3185 gettreediffs $diffids
3185 gettreediffs $diffids
3186 } else {
3186 } else {
3187 if {[info exists diffmergeid]} {
3187 if {[info exists diffmergeid]} {
3188 contmergediff $ids
3188 contmergediff $ids
3189 } else {
3189 } else {
3190 addtocflist $ids
3190 addtocflist $ids
3191 }
3191 }
3192 }
3192 }
3193 return
3193 return
3194 }
3194 }
3195 set tab1 [expr [string first "\t" $line] + 1]
3195 set tab1 [expr [string first "\t" $line] + 1]
3196 set tab2 [expr [string first "\t" $line $tab1] - 1]
3196 set tab2 [expr [string first "\t" $line $tab1] - 1]
3197 set file [string range $line $tab1 $tab2]
3197 set file [string range $line $tab1 $tab2]
3198 lappend treediff $file
3198 lappend treediff $file
3199 }
3199 }
3200
3200
3201 proc getblobdiffs {ids} {
3201 proc getblobdiffs {ids} {
3202 global diffopts blobdifffd diffids env curdifftag curtagstart
3202 global diffopts blobdifffd diffids env curdifftag curtagstart
3203 global difffilestart nextupdate diffinhdr treediffs
3203 global difffilestart nextupdate diffinhdr treediffs
3204
3204
3205 set id [lindex $ids 0]
3205 set id [lindex $ids 0]
3206 set p [lindex $ids 1]
3206 set p [lindex $ids 1]
3207 set env(GIT_DIFF_OPTS) $diffopts
3207 set env(GIT_DIFF_OPTS) $diffopts
3208 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r -p -C $p $id]
3208 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r -p -C $p $id]
3209 if {[catch {set bdf [open $cmd r]} err]} {
3209 if {[catch {set bdf [open $cmd r]} err]} {
3210 puts "error getting diffs: $err"
3210 puts "error getting diffs: $err"
3211 return
3211 return
3212 }
3212 }
3213 set diffinhdr 0
3213 set diffinhdr 0
3214 fconfigure $bdf -blocking 0
3214 fconfigure $bdf -blocking 0
3215 set blobdifffd($ids) $bdf
3215 set blobdifffd($ids) $bdf
3216 set curdifftag Comments
3216 set curdifftag Comments
3217 set curtagstart 0.0
3217 set curtagstart 0.0
3218 catch {unset difffilestart}
3218 catch {unset difffilestart}
3219 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
3219 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
3220 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3220 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3221 }
3221 }
3222
3222
3223 proc getblobdiffline {bdf ids} {
3223 proc getblobdiffline {bdf ids} {
3224 global diffids blobdifffd ctext curdifftag curtagstart
3224 global diffids blobdifffd ctext curdifftag curtagstart
3225 global diffnexthead diffnextnote difffilestart
3225 global diffnexthead diffnextnote difffilestart
3226 global nextupdate diffinhdr treediffs
3226 global nextupdate diffinhdr treediffs
3227 global gaudydiff
3227 global gaudydiff
3228
3228
3229 set n [gets $bdf line]
3229 set n [gets $bdf line]
3230 if {$n < 0} {
3230 if {$n < 0} {
3231 if {[eof $bdf]} {
3231 if {[eof $bdf]} {
3232 close $bdf
3232 close $bdf
3233 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
3233 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
3234 $ctext tag add $curdifftag $curtagstart end
3234 $ctext tag add $curdifftag $curtagstart end
3235 }
3235 }
3236 }
3236 }
3237 return
3237 return
3238 }
3238 }
3239 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
3239 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
3240 return
3240 return
3241 }
3241 }
3242 regsub -all "\r" $line "" line
3242 regsub -all "\r" $line "" line
3243 $ctext conf -state normal
3243 $ctext conf -state normal
3244 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
3244 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
3245 # start of a new file
3245 # start of a new file
3246 $ctext insert end "\n"
3246 $ctext insert end "\n"
3247 $ctext tag add $curdifftag $curtagstart end
3247 $ctext tag add $curdifftag $curtagstart end
3248 set curtagstart [$ctext index "end - 1c"]
3248 set curtagstart [$ctext index "end - 1c"]
3249 set header $newname
3249 set header $newname
3250 set here [$ctext index "end - 1c"]
3250 set here [$ctext index "end - 1c"]
3251 set i [lsearch -exact $treediffs($diffids) $fname]
3251 set i [lsearch -exact $treediffs($diffids) $fname]
3252 if {$i >= 0} {
3252 if {$i >= 0} {
3253 set difffilestart($i) $here
3253 set difffilestart($i) $here
3254 incr i
3254 incr i
3255 $ctext mark set fmark.$i $here
3255 $ctext mark set fmark.$i $here
3256 $ctext mark gravity fmark.$i left
3256 $ctext mark gravity fmark.$i left
3257 }
3257 }
3258 if {$newname != $fname} {
3258 if {$newname != $fname} {
3259 set i [lsearch -exact $treediffs($diffids) $newname]
3259 set i [lsearch -exact $treediffs($diffids) $newname]
3260 if {$i >= 0} {
3260 if {$i >= 0} {
3261 set difffilestart($i) $here
3261 set difffilestart($i) $here
3262 incr i
3262 incr i
3263 $ctext mark set fmark.$i $here
3263 $ctext mark set fmark.$i $here
3264 $ctext mark gravity fmark.$i left
3264 $ctext mark gravity fmark.$i left
3265 }
3265 }
3266 }
3266 }
3267 set curdifftag "f:$fname"
3267 set curdifftag "f:$fname"
3268 $ctext tag delete $curdifftag
3268 $ctext tag delete $curdifftag
3269 set l [expr {(78 - [string length $header]) / 2}]
3269 set l [expr {(78 - [string length $header]) / 2}]
3270 set pad [string range "----------------------------------------" 1 $l]
3270 set pad [string range "----------------------------------------" 1 $l]
3271 $ctext insert end "$pad $header $pad\n" filesep
3271 $ctext insert end "$pad $header $pad\n" filesep
3272 set diffinhdr 1
3272 set diffinhdr 1
3273 } elseif {[regexp {^(---|\+\+\+) } $line] && $diffinhdr} {
3273 } elseif {[regexp {^(---|\+\+\+) } $line] && $diffinhdr} {
3274 set diffinhdr 1
3274 set diffinhdr 1
3275 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
3275 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
3276 $line match f1l f1c f2l f2c rest]} {
3276 $line match f1l f1c f2l f2c rest]} {
3277 if {$gaudydiff} {
3277 if {$gaudydiff} {
3278 $ctext insert end "\t" hunksep
3278 $ctext insert end "\t" hunksep
3279 $ctext insert end " $f1l " d0 " $f2l " d1
3279 $ctext insert end " $f1l " d0 " $f2l " d1
3280 $ctext insert end " $rest \n" hunksep
3280 $ctext insert end " $rest \n" hunksep
3281 } else {
3281 } else {
3282 $ctext insert end "$line\n" hunksep
3282 $ctext insert end "$line\n" hunksep
3283 }
3283 }
3284 set diffinhdr 0
3284 set diffinhdr 0
3285 } else {
3285 } else {
3286 set x [string range $line 0 0]
3286 set x [string range $line 0 0]
3287 if {$x == "-" || $x == "+"} {
3287 if {$x == "-" || $x == "+"} {
3288 set tag [expr {$x == "+"}]
3288 set tag [expr {$x == "+"}]
3289 if {$gaudydiff} {
3289 if {$gaudydiff} {
3290 set line [string range $line 1 end]
3290 set line [string range $line 1 end]
3291 }
3291 }
3292 $ctext insert end "$line\n" d$tag
3292 $ctext insert end "$line\n" d$tag
3293 } elseif {$x == " "} {
3293 } elseif {$x == " "} {
3294 if {$gaudydiff} {
3294 if {$gaudydiff} {
3295 set line [string range $line 1 end]
3295 set line [string range $line 1 end]
3296 }
3296 }
3297 $ctext insert end "$line\n"
3297 $ctext insert end "$line\n"
3298 } elseif {$diffinhdr || $x == "\\"} {
3298 } elseif {$diffinhdr || $x == "\\"} {
3299 # e.g. "\ No newline at end of file"
3299 # e.g. "\ No newline at end of file"
3300 $ctext insert end "$line\n" filesep
3300 $ctext insert end "$line\n" filesep
3301 } elseif {$line != ""} {
3301 } elseif {$line != ""} {
3302 # Something else we don't recognize
3302 # Something else we don't recognize
3303 if {$curdifftag != "Comments"} {
3303 if {$curdifftag != "Comments"} {
3304 $ctext insert end "\n"
3304 $ctext insert end "\n"
3305 $ctext tag add $curdifftag $curtagstart end
3305 $ctext tag add $curdifftag $curtagstart end
3306 set curtagstart [$ctext index "end - 1c"]
3306 set curtagstart [$ctext index "end - 1c"]
3307 set curdifftag Comments
3307 set curdifftag Comments
3308 }
3308 }
3309 $ctext insert end "$line\n" filesep
3309 $ctext insert end "$line\n" filesep
3310 }
3310 }
3311 }
3311 }
3312 $ctext conf -state disabled
3312 $ctext conf -state disabled
3313 if {[clock clicks -milliseconds] >= $nextupdate} {
3313 if {[clock clicks -milliseconds] >= $nextupdate} {
3314 incr nextupdate 100
3314 incr nextupdate 100
3315 fileevent $bdf readable {}
3315 fileevent $bdf readable {}
3316 update
3316 update
3317 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
3317 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
3318 }
3318 }
3319 }
3319 }
3320
3320
3321 proc nextfile {} {
3321 proc nextfile {} {
3322 global difffilestart ctext
3322 global difffilestart ctext
3323 set here [$ctext index @0,0]
3323 set here [$ctext index @0,0]
3324 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
3324 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
3325 if {[$ctext compare $difffilestart($i) > $here]} {
3325 if {[$ctext compare $difffilestart($i) > $here]} {
3326 if {![info exists pos]
3326 if {![info exists pos]
3327 || [$ctext compare $difffilestart($i) < $pos]} {
3327 || [$ctext compare $difffilestart($i) < $pos]} {
3328 set pos $difffilestart($i)
3328 set pos $difffilestart($i)
3329 }
3329 }
3330 }
3330 }
3331 }
3331 }
3332 if {[info exists pos]} {
3332 if {[info exists pos]} {
3333 $ctext yview $pos
3333 $ctext yview $pos
3334 }
3334 }
3335 }
3335 }
3336
3336
3337 proc listboxsel {} {
3337 proc listboxsel {} {
3338 global ctext cflist currentid
3338 global ctext cflist currentid
3339 if {![info exists currentid]} return
3339 if {![info exists currentid]} return
3340 set sel [lsort [$cflist curselection]]
3340 set sel [lsort [$cflist curselection]]
3341 if {$sel eq {}} return
3341 if {$sel eq {}} return
3342 set first [lindex $sel 0]
3342 set first [lindex $sel 0]
3343 catch {$ctext yview fmark.$first}
3343 catch {$ctext yview fmark.$first}
3344 }
3344 }
3345
3345
3346 proc setcoords {} {
3346 proc setcoords {} {
3347 global linespc charspc canvx0 canvy0 mainfont
3347 global linespc charspc canvx0 canvy0 mainfont
3348 global xspc1 xspc2 lthickness
3348 global xspc1 xspc2 lthickness
3349
3349
3350 set linespc [font metrics $mainfont -linespace]
3350 set linespc [font metrics $mainfont -linespace]
3351 set charspc [font measure $mainfont "m"]
3351 set charspc [font measure $mainfont "m"]
3352 set canvy0 [expr 3 + 0.5 * $linespc]
3352 set canvy0 [expr 3 + 0.5 * $linespc]
3353 set canvx0 [expr 3 + 0.5 * $linespc]
3353 set canvx0 [expr 3 + 0.5 * $linespc]
3354 set lthickness [expr {int($linespc / 9) + 1}]
3354 set lthickness [expr {int($linespc / 9) + 1}]
3355 set xspc1(0) $linespc
3355 set xspc1(0) $linespc
3356 set xspc2 $linespc
3356 set xspc2 $linespc
3357 }
3357 }
3358
3358
3359 proc redisplay {} {
3359 proc redisplay {} {
3360 global stopped redisplaying phase
3360 global stopped redisplaying phase
3361 if {$stopped > 1} return
3361 if {$stopped > 1} return
3362 if {$phase == "getcommits"} return
3362 if {$phase == "getcommits"} return
3363 set redisplaying 1
3363 set redisplaying 1
3364 if {$phase == "drawgraph" || $phase == "incrdraw"} {
3364 if {$phase == "drawgraph" || $phase == "incrdraw"} {
3365 set stopped 1
3365 set stopped 1
3366 } else {
3366 } else {
3367 drawgraph
3367 drawgraph
3368 }
3368 }
3369 }
3369 }
3370
3370
3371 proc incrfont {inc} {
3371 proc incrfont {inc} {
3372 global mainfont namefont textfont ctext canv phase
3372 global mainfont namefont textfont ctext canv phase
3373 global stopped entries curidfont
3373 global stopped entries curidfont
3374 unmarkmatches
3374 unmarkmatches
3375 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3375 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3376 set curidfont [lreplace $curidfont 1 1 [expr {[lindex $curidfont 1] + $inc}]]
3376 set curidfont [lreplace $curidfont 1 1 [expr {[lindex $curidfont 1] + $inc}]]
3377 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3377 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3378 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3378 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3379 setcoords
3379 setcoords
3380 $ctext conf -font $textfont
3380 $ctext conf -font $textfont
3381 $ctext tag conf filesep -font [concat $textfont bold]
3381 $ctext tag conf filesep -font [concat $textfont bold]
3382 foreach e $entries {
3382 foreach e $entries {
3383 $e conf -font $mainfont
3383 $e conf -font $mainfont
3384 }
3384 }
3385 if {$phase == "getcommits"} {
3385 if {$phase == "getcommits"} {
3386 $canv itemconf textitems -font $mainfont
3386 $canv itemconf textitems -font $mainfont
3387 }
3387 }
3388 redisplay
3388 redisplay
3389 }
3389 }
3390
3390
3391 proc clearsha1 {} {
3391 proc clearsha1 {} {
3392 global sha1entry sha1string
3392 global sha1entry sha1string
3393 if {[string length $sha1string] == 40} {
3393 if {[string length $sha1string] == 40} {
3394 $sha1entry delete 0 end
3394 $sha1entry delete 0 end
3395 }
3395 }
3396 }
3396 }
3397
3397
3398 proc sha1change {n1 n2 op} {
3398 proc sha1change {n1 n2 op} {
3399 global sha1string currentid sha1but
3399 global sha1string currentid sha1but
3400 if {$sha1string == {}
3400 if {$sha1string == {}
3401 || ([info exists currentid] && $sha1string == $currentid)} {
3401 || ([info exists currentid] && $sha1string == $currentid)} {
3402 set state disabled
3402 set state disabled
3403 } else {
3403 } else {
3404 set state normal
3404 set state normal
3405 }
3405 }
3406 if {[$sha1but cget -state] == $state} return
3406 if {[$sha1but cget -state] == $state} return
3407 if {$state == "normal"} {
3407 if {$state == "normal"} {
3408 $sha1but conf -state normal -relief raised -text "Goto: "
3408 $sha1but conf -state normal -relief raised -text "Goto: "
3409 } else {
3409 } else {
3410 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3410 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3411 }
3411 }
3412 }
3412 }
3413
3413
3414 proc gotocommit {} {
3414 proc gotocommit {} {
3415 global sha1string currentid idline tagids
3415 global sha1string currentid idline tagids
3416 global lineid numcommits
3416 global lineid numcommits
3417
3417
3418 if {$sha1string == {}
3418 if {$sha1string == {}
3419 || ([info exists currentid] && $sha1string == $currentid)} return
3419 || ([info exists currentid] && $sha1string == $currentid)} return
3420 if {[info exists tagids($sha1string)]} {
3420 if {[info exists tagids($sha1string)]} {
3421 set id $tagids($sha1string)
3421 set id $tagids($sha1string)
3422 } else {
3422 } else {
3423 set id [string tolower $sha1string]
3423 set id [string tolower $sha1string]
3424 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3424 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3425 set matches {}
3425 set matches {}
3426 for {set l 0} {$l < $numcommits} {incr l} {
3426 for {set l 0} {$l < $numcommits} {incr l} {
3427 if {[string match $id* $lineid($l)]} {
3427 if {[string match $id* $lineid($l)]} {
3428 lappend matches $lineid($l)
3428 lappend matches $lineid($l)
3429 }
3429 }
3430 }
3430 }
3431 if {$matches ne {}} {
3431 if {$matches ne {}} {
3432 if {[llength $matches] > 1} {
3432 if {[llength $matches] > 1} {
3433 error_popup "Short SHA1 id $id is ambiguous"
3433 error_popup "Short SHA1 id $id is ambiguous"
3434 return
3434 return
3435 }
3435 }
3436 set id [lindex $matches 0]
3436 set id [lindex $matches 0]
3437 }
3437 }
3438 }
3438 }
3439 }
3439 }
3440 if {[info exists idline($id)]} {
3440 if {[info exists idline($id)]} {
3441 selectline $idline($id) 1
3441 selectline $idline($id) 1
3442 return
3442 return
3443 }
3443 }
3444 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3444 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3445 set type "SHA1 id"
3445 set type "SHA1 id"
3446 } else {
3446 } else {
3447 set type "Tag"
3447 set type "Tag"
3448 }
3448 }
3449 error_popup "$type $sha1string is not known"
3449 error_popup "$type $sha1string is not known"
3450 }
3450 }
3451
3451
3452 proc lineenter {x y id} {
3452 proc lineenter {x y id} {
3453 global hoverx hovery hoverid hovertimer
3453 global hoverx hovery hoverid hovertimer
3454 global commitinfo canv
3454 global commitinfo canv
3455
3455
3456 if {![info exists commitinfo($id)]} return
3456 if {![info exists commitinfo($id)]} return
3457 set hoverx $x
3457 set hoverx $x
3458 set hovery $y
3458 set hovery $y
3459 set hoverid $id
3459 set hoverid $id
3460 if {[info exists hovertimer]} {
3460 if {[info exists hovertimer]} {
3461 after cancel $hovertimer
3461 after cancel $hovertimer
3462 }
3462 }
3463 set hovertimer [after 500 linehover]
3463 set hovertimer [after 500 linehover]
3464 $canv delete hover
3464 $canv delete hover
3465 }
3465 }
3466
3466
3467 proc linemotion {x y id} {
3467 proc linemotion {x y id} {
3468 global hoverx hovery hoverid hovertimer
3468 global hoverx hovery hoverid hovertimer
3469
3469
3470 if {[info exists hoverid] && $id == $hoverid} {
3470 if {[info exists hoverid] && $id == $hoverid} {
3471 set hoverx $x
3471 set hoverx $x
3472 set hovery $y
3472 set hovery $y
3473 if {[info exists hovertimer]} {
3473 if {[info exists hovertimer]} {
3474 after cancel $hovertimer
3474 after cancel $hovertimer
3475 }
3475 }
3476 set hovertimer [after 500 linehover]
3476 set hovertimer [after 500 linehover]
3477 }
3477 }
3478 }
3478 }
3479
3479
3480 proc lineleave {id} {
3480 proc lineleave {id} {
3481 global hoverid hovertimer canv
3481 global hoverid hovertimer canv
3482
3482
3483 if {[info exists hoverid] && $id == $hoverid} {
3483 if {[info exists hoverid] && $id == $hoverid} {
3484 $canv delete hover
3484 $canv delete hover
3485 if {[info exists hovertimer]} {
3485 if {[info exists hovertimer]} {
3486 after cancel $hovertimer
3486 after cancel $hovertimer
3487 unset hovertimer
3487 unset hovertimer
3488 }
3488 }
3489 unset hoverid
3489 unset hoverid
3490 }
3490 }
3491 }
3491 }
3492
3492
3493 proc linehover {} {
3493 proc linehover {} {
3494 global hoverx hovery hoverid hovertimer
3494 global hoverx hovery hoverid hovertimer
3495 global canv linespc lthickness
3495 global canv linespc lthickness
3496 global commitinfo mainfont
3496 global commitinfo mainfont
3497
3497
3498 set text [lindex $commitinfo($hoverid) 0]
3498 set text [lindex $commitinfo($hoverid) 0]
3499 set ymax [lindex [$canv cget -scrollregion] 3]
3499 set ymax [lindex [$canv cget -scrollregion] 3]
3500 if {$ymax == {}} return
3500 if {$ymax == {}} return
3501 set yfrac [lindex [$canv yview] 0]
3501 set yfrac [lindex [$canv yview] 0]
3502 set x [expr {$hoverx + 2 * $linespc}]
3502 set x [expr {$hoverx + 2 * $linespc}]
3503 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3503 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3504 set x0 [expr {$x - 2 * $lthickness}]
3504 set x0 [expr {$x - 2 * $lthickness}]
3505 set y0 [expr {$y - 2 * $lthickness}]
3505 set y0 [expr {$y - 2 * $lthickness}]
3506 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3506 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3507 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3507 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3508 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3508 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3509 -fill \#ffff80 -outline black -width 1 -tags hover]
3509 -fill \#ffff80 -outline black -width 1 -tags hover]
3510 $canv raise $t
3510 $canv raise $t
3511 set t [$canv create text $x $y -anchor nw -text $text -tags hover]
3511 set t [$canv create text $x $y -anchor nw -text $text -tags hover]
3512 $canv raise $t
3512 $canv raise $t
3513 }
3513 }
3514
3514
3515 proc clickisonarrow {id y} {
3515 proc clickisonarrow {id y} {
3516 global mainline mainlinearrow sidelines lthickness
3516 global mainline mainlinearrow sidelines lthickness
3517
3517
3518 set thresh [expr {2 * $lthickness + 6}]
3518 set thresh [expr {2 * $lthickness + 6}]
3519 if {[info exists mainline($id)]} {
3519 if {[info exists mainline($id)]} {
3520 if {$mainlinearrow($id) ne "none"} {
3520 if {$mainlinearrow($id) ne "none"} {
3521 if {abs([lindex $mainline($id) 1] - $y) < $thresh} {
3521 if {abs([lindex $mainline($id) 1] - $y) < $thresh} {
3522 return "up"
3522 return "up"
3523 }
3523 }
3524 }
3524 }
3525 }
3525 }
3526 if {[info exists sidelines($id)]} {
3526 if {[info exists sidelines($id)]} {
3527 foreach ls $sidelines($id) {
3527 foreach ls $sidelines($id) {
3528 set coords [lindex $ls 0]
3528 set coords [lindex $ls 0]
3529 set arrow [lindex $ls 2]
3529 set arrow [lindex $ls 2]
3530 if {$arrow eq "first" || $arrow eq "both"} {
3530 if {$arrow eq "first" || $arrow eq "both"} {
3531 if {abs([lindex $coords 1] - $y) < $thresh} {
3531 if {abs([lindex $coords 1] - $y) < $thresh} {
3532 return "up"
3532 return "up"
3533 }
3533 }
3534 }
3534 }
3535 if {$arrow eq "last" || $arrow eq "both"} {
3535 if {$arrow eq "last" || $arrow eq "both"} {
3536 if {abs([lindex $coords end] - $y) < $thresh} {
3536 if {abs([lindex $coords end] - $y) < $thresh} {
3537 return "down"
3537 return "down"
3538 }
3538 }
3539 }
3539 }
3540 }
3540 }
3541 }
3541 }
3542 return {}
3542 return {}
3543 }
3543 }
3544
3544
3545 proc arrowjump {id dirn y} {
3545 proc arrowjump {id dirn y} {
3546 global mainline sidelines canv
3546 global mainline sidelines canv
3547
3547
3548 set yt {}
3548 set yt {}
3549 if {$dirn eq "down"} {
3549 if {$dirn eq "down"} {
3550 if {[info exists mainline($id)]} {
3550 if {[info exists mainline($id)]} {
3551 set y1 [lindex $mainline($id) 1]
3551 set y1 [lindex $mainline($id) 1]
3552 if {$y1 > $y} {
3552 if {$y1 > $y} {
3553 set yt $y1
3553 set yt $y1
3554 }
3554 }
3555 }
3555 }
3556 if {[info exists sidelines($id)]} {
3556 if {[info exists sidelines($id)]} {
3557 foreach ls $sidelines($id) {
3557 foreach ls $sidelines($id) {
3558 set y1 [lindex $ls 0 1]
3558 set y1 [lindex $ls 0 1]
3559 if {$y1 > $y && ($yt eq {} || $y1 < $yt)} {
3559 if {$y1 > $y && ($yt eq {} || $y1 < $yt)} {
3560 set yt $y1
3560 set yt $y1
3561 }
3561 }
3562 }
3562 }
3563 }
3563 }
3564 } else {
3564 } else {
3565 if {[info exists sidelines($id)]} {
3565 if {[info exists sidelines($id)]} {
3566 foreach ls $sidelines($id) {
3566 foreach ls $sidelines($id) {
3567 set y1 [lindex $ls 0 end]
3567 set y1 [lindex $ls 0 end]
3568 if {$y1 < $y && ($yt eq {} || $y1 > $yt)} {
3568 if {$y1 < $y && ($yt eq {} || $y1 > $yt)} {
3569 set yt $y1
3569 set yt $y1
3570 }
3570 }
3571 }
3571 }
3572 }
3572 }
3573 }
3573 }
3574 if {$yt eq {}} return
3574 if {$yt eq {}} return
3575 set ymax [lindex [$canv cget -scrollregion] 3]
3575 set ymax [lindex [$canv cget -scrollregion] 3]
3576 if {$ymax eq {} || $ymax <= 0} return
3576 if {$ymax eq {} || $ymax <= 0} return
3577 set view [$canv yview]
3577 set view [$canv yview]
3578 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3578 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3579 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3579 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3580 if {$yfrac < 0} {
3580 if {$yfrac < 0} {
3581 set yfrac 0
3581 set yfrac 0
3582 }
3582 }
3583 $canv yview moveto $yfrac
3583 $canv yview moveto $yfrac
3584 }
3584 }
3585
3585
3586 proc lineclick {x y id isnew} {
3586 proc lineclick {x y id isnew} {
3587 global ctext commitinfo children cflist canv thickerline
3587 global ctext commitinfo children cflist canv thickerline
3588
3588
3589 unmarkmatches
3589 unmarkmatches
3590 unselectline
3590 unselectline
3591 normalline
3591 normalline
3592 $canv delete hover
3592 $canv delete hover
3593 # draw this line thicker than normal
3593 # draw this line thicker than normal
3594 drawlines $id 1
3594 drawlines $id 1
3595 set thickerline $id
3595 set thickerline $id
3596 if {$isnew} {
3596 if {$isnew} {
3597 set ymax [lindex [$canv cget -scrollregion] 3]
3597 set ymax [lindex [$canv cget -scrollregion] 3]
3598 if {$ymax eq {}} return
3598 if {$ymax eq {}} return
3599 set yfrac [lindex [$canv yview] 0]
3599 set yfrac [lindex [$canv yview] 0]
3600 set y [expr {$y + $yfrac * $ymax}]
3600 set y [expr {$y + $yfrac * $ymax}]
3601 }
3601 }
3602 set dirn [clickisonarrow $id $y]
3602 set dirn [clickisonarrow $id $y]
3603 if {$dirn ne {}} {
3603 if {$dirn ne {}} {
3604 arrowjump $id $dirn $y
3604 arrowjump $id $dirn $y
3605 return
3605 return
3606 }
3606 }
3607
3607
3608 if {$isnew} {
3608 if {$isnew} {
3609 addtohistory [list lineclick $x $y $id 0]
3609 addtohistory [list lineclick $x $y $id 0]
3610 }
3610 }
3611 # fill the details pane with info about this line
3611 # fill the details pane with info about this line
3612 $ctext conf -state normal
3612 $ctext conf -state normal
3613 $ctext delete 0.0 end
3613 $ctext delete 0.0 end
3614 $ctext tag conf link -foreground blue -underline 1
3614 $ctext tag conf link -foreground blue -underline 1
3615 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3615 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3616 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3616 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3617 $ctext insert end "Parent:\t"
3617 $ctext insert end "Parent:\t"
3618 $ctext insert end $id [list link link0]
3618 $ctext insert end $id [list link link0]
3619 $ctext tag bind link0 <1> [list selbyid $id]
3619 $ctext tag bind link0 <1> [list selbyid $id]
3620 set info $commitinfo($id)
3620 set info $commitinfo($id)
3621 $ctext insert end "\n\t[lindex $info 0]\n"
3621 $ctext insert end "\n\t[lindex $info 0]\n"
3622 $ctext insert end "\tUser:\t[lindex $info 1]\n"
3622 $ctext insert end "\tUser:\t[lindex $info 1]\n"
3623 $ctext insert end "\tDate:\t[lindex $info 2]\n"
3623 $ctext insert end "\tDate:\t[lindex $info 2]\n"
3624 if {[info exists children($id)]} {
3624 if {[info exists children($id)]} {
3625 $ctext insert end "\nChildren:"
3625 $ctext insert end "\nChildren:"
3626 set i 0
3626 set i 0
3627 foreach child $children($id) {
3627 foreach child $children($id) {
3628 incr i
3628 incr i
3629 set info $commitinfo($child)
3629 set info $commitinfo($child)
3630 $ctext insert end "\n\t"
3630 $ctext insert end "\n\t"
3631 $ctext insert end $child [list link link$i]
3631 $ctext insert end $child [list link link$i]
3632 $ctext tag bind link$i <1> [list selbyid $child]
3632 $ctext tag bind link$i <1> [list selbyid $child]
3633 $ctext insert end "\n\t[lindex $info 0]"
3633 $ctext insert end "\n\t[lindex $info 0]"
3634 $ctext insert end "\n\tUser:\t[lindex $info 1]"
3634 $ctext insert end "\n\tUser:\t[lindex $info 1]"
3635 $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3635 $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3636 }
3636 }
3637 }
3637 }
3638 $ctext conf -state disabled
3638 $ctext conf -state disabled
3639
3639
3640 $cflist delete 0 end
3640 $cflist delete 0 end
3641 }
3641 }
3642
3642
3643 proc normalline {} {
3643 proc normalline {} {
3644 global thickerline
3644 global thickerline
3645 if {[info exists thickerline]} {
3645 if {[info exists thickerline]} {
3646 drawlines $thickerline 0
3646 drawlines $thickerline 0
3647 unset thickerline
3647 unset thickerline
3648 }
3648 }
3649 }
3649 }
3650
3650
3651 proc selbyid {id} {
3651 proc selbyid {id} {
3652 global idline
3652 global idline
3653 if {[info exists idline($id)]} {
3653 if {[info exists idline($id)]} {
3654 selectline $idline($id) 1
3654 selectline $idline($id) 1
3655 }
3655 }
3656 }
3656 }
3657
3657
3658 proc mstime {} {
3658 proc mstime {} {
3659 global startmstime
3659 global startmstime
3660 if {![info exists startmstime]} {
3660 if {![info exists startmstime]} {
3661 set startmstime [clock clicks -milliseconds]
3661 set startmstime [clock clicks -milliseconds]
3662 }
3662 }
3663 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3663 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3664 }
3664 }
3665
3665
3666 proc rowmenu {x y id} {
3666 proc rowmenu {x y id} {
3667 global rowctxmenu idline selectedline rowmenuid hgvdiff
3667 global rowctxmenu idline selectedline rowmenuid hgvdiff
3668
3668
3669 if {![info exists selectedline] || $idline($id) eq $selectedline} {
3669 if {![info exists selectedline] || $idline($id) eq $selectedline} {
3670 set state disabled
3670 set state disabled
3671 } else {
3671 } else {
3672 set state normal
3672 set state normal
3673 }
3673 }
3674 $rowctxmenu entryconfigure 0 -state $state
3674 $rowctxmenu entryconfigure 0 -state $state
3675 $rowctxmenu entryconfigure 1 -state $state
3675 $rowctxmenu entryconfigure 1 -state $state
3676 $rowctxmenu entryconfigure 2 -state $state
3676 $rowctxmenu entryconfigure 2 -state $state
3677 if { $hgvdiff ne "" } {
3677 if { $hgvdiff ne "" } {
3678 $rowctxmenu entryconfigure 6 -state $state
3678 $rowctxmenu entryconfigure 6 -state $state
3679 }
3679 }
3680 set rowmenuid $id
3680 set rowmenuid $id
3681 tk_popup $rowctxmenu $x $y
3681 tk_popup $rowctxmenu $x $y
3682 }
3682 }
3683
3683
3684 proc diffvssel {dirn} {
3684 proc diffvssel {dirn} {
3685 global rowmenuid selectedline lineid
3685 global rowmenuid selectedline lineid
3686
3686
3687 if {![info exists selectedline]} return
3687 if {![info exists selectedline]} return
3688 if {$dirn} {
3688 if {$dirn} {
3689 set oldid $lineid($selectedline)
3689 set oldid $lineid($selectedline)
3690 set newid $rowmenuid
3690 set newid $rowmenuid
3691 } else {
3691 } else {
3692 set oldid $rowmenuid
3692 set oldid $rowmenuid
3693 set newid $lineid($selectedline)
3693 set newid $lineid($selectedline)
3694 }
3694 }
3695 addtohistory [list doseldiff $oldid $newid]
3695 addtohistory [list doseldiff $oldid $newid]
3696 doseldiff $oldid $newid
3696 doseldiff $oldid $newid
3697 }
3697 }
3698
3698
3699 proc doseldiff {oldid newid} {
3699 proc doseldiff {oldid newid} {
3700 global ctext cflist
3700 global ctext cflist
3701 global commitinfo
3701 global commitinfo
3702
3702
3703 $ctext conf -state normal
3703 $ctext conf -state normal
3704 $ctext delete 0.0 end
3704 $ctext delete 0.0 end
3705 $ctext mark set fmark.0 0.0
3705 $ctext mark set fmark.0 0.0
3706 $ctext mark gravity fmark.0 left
3706 $ctext mark gravity fmark.0 left
3707 $cflist delete 0 end
3707 $cflist delete 0 end
3708 $cflist insert end "Top"
3708 $cflist insert end "Top"
3709 $ctext insert end "From "
3709 $ctext insert end "From "
3710 $ctext tag conf link -foreground blue -underline 1
3710 $ctext tag conf link -foreground blue -underline 1
3711 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3711 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3712 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3712 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3713 $ctext tag bind link0 <1> [list selbyid $oldid]
3713 $ctext tag bind link0 <1> [list selbyid $oldid]
3714 $ctext insert end $oldid [list link link0]
3714 $ctext insert end $oldid [list link link0]
3715 $ctext insert end "\n "
3715 $ctext insert end "\n "
3716 $ctext insert end [lindex $commitinfo($oldid) 0]
3716 $ctext insert end [lindex $commitinfo($oldid) 0]
3717 $ctext insert end "\n\nTo "
3717 $ctext insert end "\n\nTo "
3718 $ctext tag bind link1 <1> [list selbyid $newid]
3718 $ctext tag bind link1 <1> [list selbyid $newid]
3719 $ctext insert end $newid [list link link1]
3719 $ctext insert end $newid [list link link1]
3720 $ctext insert end "\n "
3720 $ctext insert end "\n "
3721 $ctext insert end [lindex $commitinfo($newid) 0]
3721 $ctext insert end [lindex $commitinfo($newid) 0]
3722 $ctext insert end "\n"
3722 $ctext insert end "\n"
3723 $ctext conf -state disabled
3723 $ctext conf -state disabled
3724 $ctext tag delete Comments
3724 $ctext tag delete Comments
3725 $ctext tag remove found 1.0 end
3725 $ctext tag remove found 1.0 end
3726 startdiff [list $newid $oldid]
3726 startdiff [list $newid $oldid]
3727 }
3727 }
3728
3728
3729 proc mkpatch {} {
3729 proc mkpatch {} {
3730 global rowmenuid currentid commitinfo patchtop patchnum
3730 global rowmenuid currentid commitinfo patchtop patchnum
3731
3731
3732 if {![info exists currentid]} return
3732 if {![info exists currentid]} return
3733 set oldid $currentid
3733 set oldid $currentid
3734 set oldhead [lindex $commitinfo($oldid) 0]
3734 set oldhead [lindex $commitinfo($oldid) 0]
3735 set newid $rowmenuid
3735 set newid $rowmenuid
3736 set newhead [lindex $commitinfo($newid) 0]
3736 set newhead [lindex $commitinfo($newid) 0]
3737 set top .patch
3737 set top .patch
3738 set patchtop $top
3738 set patchtop $top
3739 catch {destroy $top}
3739 catch {destroy $top}
3740 toplevel $top
3740 toplevel $top
3741 ttk::label $top.from -text "From:"
3741 ttk::label $top.from -text "From:"
3742 ttk::entry $top.fromsha1 -width 40
3742 ttk::entry $top.fromsha1 -width 40
3743 $top.fromsha1 insert 0 $oldid
3743 $top.fromsha1 insert 0 $oldid
3744 $top.fromsha1 conf -state readonly
3744 $top.fromsha1 conf -state readonly
3745 grid $top.from $top.fromsha1 -sticky w -pady {10 0}
3745 grid $top.from $top.fromsha1 -sticky w -pady {10 0}
3746 ttk::entry $top.fromhead -width 60
3746 ttk::entry $top.fromhead -width 60
3747 $top.fromhead insert 0 $oldhead
3747 $top.fromhead insert 0 $oldhead
3748 $top.fromhead conf -state readonly
3748 $top.fromhead conf -state readonly
3749 grid x $top.fromhead -sticky w
3749 grid x $top.fromhead -sticky w
3750 ttk::label $top.to -text "To:"
3750 ttk::label $top.to -text "To:"
3751 ttk::entry $top.tosha1 -width 40
3751 ttk::entry $top.tosha1 -width 40
3752 $top.tosha1 insert 0 $newid
3752 $top.tosha1 insert 0 $newid
3753 $top.tosha1 conf -state readonly
3753 $top.tosha1 conf -state readonly
3754 grid $top.to $top.tosha1 -sticky w
3754 grid $top.to $top.tosha1 -sticky w
3755 ttk::entry $top.tohead -width 60
3755 ttk::entry $top.tohead -width 60
3756 $top.tohead insert 0 $newhead
3756 $top.tohead insert 0 $newhead
3757 $top.tohead conf -state readonly
3757 $top.tohead conf -state readonly
3758 grid x $top.tohead -sticky w
3758 grid x $top.tohead -sticky w
3759 ttk::button $top.rev -text "Reverse" -command mkpatchrev
3759 ttk::button $top.rev -text "Reverse" -command mkpatchrev
3760 grid $top.rev x -pady 10
3760 grid $top.rev x -pady 10
3761 ttk::label $top.flab -text "Output file:"
3761 ttk::label $top.flab -text "Output file:"
3762 ttk::entry $top.fname -width 60
3762 ttk::entry $top.fname -width 60
3763 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3763 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3764 incr patchnum
3764 incr patchnum
3765 grid $top.flab $top.fname -sticky w
3765 grid $top.flab $top.fname -sticky w
3766 ttk::frame $top.buts
3766 ttk::frame $top.buts
3767 ttk::button $top.buts.gen -text "Generate" -command mkpatchgo
3767 ttk::button $top.buts.gen -text "Generate" -command mkpatchgo
3768 ttk::button $top.buts.can -text "Cancel" -command mkpatchcan
3768 ttk::button $top.buts.can -text "Cancel" -command mkpatchcan
3769 grid $top.buts.gen $top.buts.can
3769 grid $top.buts.gen $top.buts.can
3770 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3770 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3771 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3771 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3772 grid $top.buts - -pady 10 -sticky ew
3772 grid $top.buts - -pady 10 -sticky ew
3773 focus $top.fname
3773 focus $top.fname
3774 popupify $top
3774 popupify $top
3775 wm title $top "Generate a patch"
3775 wm title $top "Generate a patch"
3776 }
3776 }
3777
3777
3778 proc mkpatchrev {} {
3778 proc mkpatchrev {} {
3779 global patchtop
3779 global patchtop
3780
3780
3781 set oldid [$patchtop.fromsha1 get]
3781 set oldid [$patchtop.fromsha1 get]
3782 set oldhead [$patchtop.fromhead get]
3782 set oldhead [$patchtop.fromhead get]
3783 set newid [$patchtop.tosha1 get]
3783 set newid [$patchtop.tosha1 get]
3784 set newhead [$patchtop.tohead get]
3784 set newhead [$patchtop.tohead get]
3785 foreach e [list fromsha1 fromhead tosha1 tohead] \
3785 foreach e [list fromsha1 fromhead tosha1 tohead] \
3786 v [list $newid $newhead $oldid $oldhead] {
3786 v [list $newid $newhead $oldid $oldhead] {
3787 $patchtop.$e conf -state normal
3787 $patchtop.$e conf -state normal
3788 $patchtop.$e delete 0 end
3788 $patchtop.$e delete 0 end
3789 $patchtop.$e insert 0 $v
3789 $patchtop.$e insert 0 $v
3790 $patchtop.$e conf -state readonly
3790 $patchtop.$e conf -state readonly
3791 }
3791 }
3792 }
3792 }
3793
3793
3794 proc mkpatchgo {} {
3794 proc mkpatchgo {} {
3795 global patchtop env
3795 global patchtop env
3796
3796
3797 set oldid [$patchtop.fromsha1 get]
3797 set oldid [$patchtop.fromsha1 get]
3798 set newid [$patchtop.tosha1 get]
3798 set newid [$patchtop.tosha1 get]
3799 set fname [$patchtop.fname get]
3799 set fname [$patchtop.fname get]
3800 if {[catch {exec $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $oldid $newid >$fname &} err]} {
3800 if {[catch {exec $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $oldid $newid >$fname &} err]} {
3801 error_popup "Error creating patch: $err"
3801 error_popup "Error creating patch: $err"
3802 }
3802 }
3803 catch {destroy $patchtop}
3803 catch {destroy $patchtop}
3804 unset patchtop
3804 unset patchtop
3805 }
3805 }
3806
3806
3807 proc mkpatchcan {} {
3807 proc mkpatchcan {} {
3808 global patchtop
3808 global patchtop
3809
3809
3810 catch {destroy $patchtop}
3810 catch {destroy $patchtop}
3811 unset patchtop
3811 unset patchtop
3812 }
3812 }
3813
3813
3814 proc mktag {} {
3814 proc mktag {} {
3815 global rowmenuid mktagtop commitinfo
3815 global rowmenuid mktagtop commitinfo
3816
3816
3817 set top .maketag
3817 set top .maketag
3818 set mktagtop $top
3818 set mktagtop $top
3819 catch {destroy $top}
3819 catch {destroy $top}
3820 toplevel $top
3820 toplevel $top
3821 ttk::label $top.id -text "ID:"
3821 ttk::label $top.id -text "ID:"
3822 ttk::entry $top.sha1 -width 40
3822 ttk::entry $top.sha1 -width 40
3823 $top.sha1 insert 0 $rowmenuid
3823 $top.sha1 insert 0 $rowmenuid
3824 $top.sha1 conf -state readonly
3824 $top.sha1 conf -state readonly
3825 grid $top.id $top.sha1 -sticky w -pady {10 0}
3825 grid $top.id $top.sha1 -sticky w -pady {10 0}
3826 ttk::entry $top.head -width 60
3826 ttk::entry $top.head -width 60
3827 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3827 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3828 $top.head conf -state readonly
3828 $top.head conf -state readonly
3829 grid x $top.head -sticky w
3829 grid x $top.head -sticky w
3830 ttk::label $top.tlab -text "Tag name:"
3830 ttk::label $top.tlab -text "Tag name:"
3831 ttk::entry $top.tag -width 60
3831 ttk::entry $top.tag -width 60
3832 grid $top.tlab $top.tag -sticky w
3832 grid $top.tlab $top.tag -sticky w
3833 ttk::frame $top.buts
3833 ttk::frame $top.buts
3834 ttk::button $top.buts.gen -text "Create" -command mktaggo
3834 ttk::button $top.buts.gen -text "Create" -command mktaggo
3835 ttk::button $top.buts.can -text "Cancel" -command mktagcan
3835 ttk::button $top.buts.can -text "Cancel" -command mktagcan
3836 grid $top.buts.gen $top.buts.can
3836 grid $top.buts.gen $top.buts.can
3837 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3837 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3838 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3838 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3839 grid $top.buts - -pady 10 -sticky ew
3839 grid $top.buts - -pady 10 -sticky ew
3840 focus $top.tag
3840 focus $top.tag
3841 popupify $top
3841 popupify $top
3842 wm title $top "Create a tag"
3842 wm title $top "Create a tag"
3843 }
3843 }
3844
3844
3845 proc domktag {} {
3845 proc domktag {} {
3846 global mktagtop env tagids idtags
3846 global mktagtop env tagids idtags
3847
3847
3848 set id [$mktagtop.sha1 get]
3848 set id [$mktagtop.sha1 get]
3849 set tag [$mktagtop.tag get]
3849 set tag [$mktagtop.tag get]
3850 if {$tag == {}} {
3850 if {$tag == {}} {
3851 error_popup "No tag name specified"
3851 error_popup "No tag name specified"
3852 return
3852 return
3853 }
3853 }
3854 if {[info exists tagids($tag)]} {
3854 if {[info exists tagids($tag)]} {
3855 error_popup "Tag \"$tag\" already exists"
3855 error_popup "Tag \"$tag\" already exists"
3856 return
3856 return
3857 }
3857 }
3858 if {[catch {
3858 if {[catch {
3859 set out [exec $env(HG) --config ui.report_untrusted=false tag -r $id $tag]
3859 set out [exec $env(HG) --config ui.report_untrusted=false tag -r $id $tag]
3860 } err]} {
3860 } err]} {
3861 error_popup "Error creating tag: $err"
3861 error_popup "Error creating tag: $err"
3862 return
3862 return
3863 }
3863 }
3864
3864
3865 set tagids($tag) $id
3865 set tagids($tag) $id
3866 lappend idtags($id) $tag
3866 lappend idtags($id) $tag
3867 redrawtags $id
3867 redrawtags $id
3868 }
3868 }
3869
3869
3870 proc redrawtags {id} {
3870 proc redrawtags {id} {
3871 global canv linehtag idline idpos selectedline
3871 global canv linehtag idline idpos selectedline
3872
3872
3873 if {![info exists idline($id)]} return
3873 if {![info exists idline($id)]} return
3874 $canv delete tag.$id
3874 $canv delete tag.$id
3875 set xt [eval drawtags $id $idpos($id)]
3875 set xt [eval drawtags $id $idpos($id)]
3876 $canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
3876 $canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
3877 if {[info exists selectedline] && $selectedline == $idline($id)} {
3877 if {[info exists selectedline] && $selectedline == $idline($id)} {
3878 selectline $selectedline 0
3878 selectline $selectedline 0
3879 }
3879 }
3880 }
3880 }
3881
3881
3882 proc mktagcan {} {
3882 proc mktagcan {} {
3883 global mktagtop
3883 global mktagtop
3884
3884
3885 catch {destroy $mktagtop}
3885 catch {destroy $mktagtop}
3886 unset mktagtop
3886 unset mktagtop
3887 }
3887 }
3888
3888
3889 proc mktaggo {} {
3889 proc mktaggo {} {
3890 domktag
3890 domktag
3891 mktagcan
3891 mktagcan
3892 }
3892 }
3893
3893
3894 proc writecommit {} {
3894 proc writecommit {} {
3895 global rowmenuid wrcomtop commitinfo wrcomcmd
3895 global rowmenuid wrcomtop commitinfo wrcomcmd
3896
3896
3897 set top .writecommit
3897 set top .writecommit
3898 set wrcomtop $top
3898 set wrcomtop $top
3899 catch {destroy $top}
3899 catch {destroy $top}
3900 toplevel $top
3900 toplevel $top
3901 ttk::label $top.id -text "ID:"
3901 ttk::label $top.id -text "ID:"
3902 ttk::entry $top.sha1 -width 40
3902 ttk::entry $top.sha1 -width 40
3903 $top.sha1 insert 0 $rowmenuid
3903 $top.sha1 insert 0 $rowmenuid
3904 $top.sha1 conf -state readonly
3904 $top.sha1 conf -state readonly
3905 grid $top.id $top.sha1 -sticky w -pady {10 0}
3905 grid $top.id $top.sha1 -sticky w -pady {10 0}
3906 ttk::entry $top.head -width 60
3906 ttk::entry $top.head -width 60
3907 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3907 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3908 $top.head conf -state readonly
3908 $top.head conf -state readonly
3909 grid x $top.head -sticky w
3909 grid x $top.head -sticky w
3910 ttk::label $top.clab -text "Command:"
3910 ttk::label $top.clab -text "Command:"
3911 ttk::entry $top.cmd -width 60 -textvariable wrcomcmd
3911 ttk::entry $top.cmd -width 60 -textvariable wrcomcmd
3912 grid $top.clab $top.cmd -sticky w -pady 10
3912 grid $top.clab $top.cmd -sticky w -pady 10
3913 ttk::label $top.flab -text "Output file:"
3913 ttk::label $top.flab -text "Output file:"
3914 ttk::entry $top.fname -width 60
3914 ttk::entry $top.fname -width 60
3915 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3915 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3916 grid $top.flab $top.fname -sticky w
3916 grid $top.flab $top.fname -sticky w
3917 ttk::frame $top.buts
3917 ttk::frame $top.buts
3918 ttk::button $top.buts.gen -text "Write" -command wrcomgo
3918 ttk::button $top.buts.gen -text "Write" -command wrcomgo
3919 ttk::button $top.buts.can -text "Cancel" -command wrcomcan
3919 ttk::button $top.buts.can -text "Cancel" -command wrcomcan
3920 grid $top.buts.gen $top.buts.can
3920 grid $top.buts.gen $top.buts.can
3921 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3921 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3922 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3922 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3923 grid $top.buts - -pady 10 -sticky ew
3923 grid $top.buts - -pady 10 -sticky ew
3924 focus $top.fname
3924 focus $top.fname
3925 popupify $top
3925 popupify $top
3926 wm title $top "Write commit to a file"
3926 wm title $top "Write commit to a file"
3927 }
3927 }
3928
3928
3929 proc wrcomgo {} {
3929 proc wrcomgo {} {
3930 global wrcomtop
3930 global wrcomtop
3931
3931
3932 set id [$wrcomtop.sha1 get]
3932 set id [$wrcomtop.sha1 get]
3933 set cmd "echo $id | [$wrcomtop.cmd get]"
3933 set cmd "echo $id | [$wrcomtop.cmd get]"
3934 set fname [$wrcomtop.fname get]
3934 set fname [$wrcomtop.fname get]
3935 if {[catch {exec sh -c $cmd > $fname &} err]} {
3935 if {[catch {exec sh -c $cmd > $fname &} err]} {
3936 error_popup "Error writing commit: $err"
3936 error_popup "Error writing commit: $err"
3937 }
3937 }
3938 catch {destroy $wrcomtop}
3938 catch {destroy $wrcomtop}
3939 unset wrcomtop
3939 unset wrcomtop
3940 }
3940 }
3941
3941
3942 proc wrcomcan {} {
3942 proc wrcomcan {} {
3943 global wrcomtop
3943 global wrcomtop
3944
3944
3945 catch {destroy $wrcomtop}
3945 catch {destroy $wrcomtop}
3946 unset wrcomtop
3946 unset wrcomtop
3947 }
3947 }
3948
3948
3949 proc listrefs {id} {
3949 proc listrefs {id} {
3950 global idtags idheads idotherrefs idbookmarks
3950 global idtags idheads idotherrefs idbookmarks
3951
3951
3952 set w {}
3952 set w {}
3953 if {[info exists idbookmarks($id)]} {
3953 if {[info exists idbookmarks($id)]} {
3954 set w $idbookmarks($id)
3954 set w $idbookmarks($id)
3955 }
3955 }
3956 set x {}
3956 set x {}
3957 if {[info exists idtags($id)]} {
3957 if {[info exists idtags($id)]} {
3958 set x $idtags($id)
3958 set x $idtags($id)
3959 }
3959 }
3960 set y {}
3960 set y {}
3961 if {[info exists idheads($id)]} {
3961 if {[info exists idheads($id)]} {
3962 set y $idheads($id)
3962 set y $idheads($id)
3963 }
3963 }
3964 set z {}
3964 set z {}
3965 if {[info exists idotherrefs($id)]} {
3965 if {[info exists idotherrefs($id)]} {
3966 set z $idotherrefs($id)
3966 set z $idotherrefs($id)
3967 }
3967 }
3968 return [list $w $x $y $z]
3968 return [list $w $x $y $z]
3969 }
3969 }
3970
3970
3971 proc rereadrefs {} {
3971 proc rereadrefs {} {
3972 global idbookmarks idtags idheads idotherrefs
3972 global idbookmarks idtags idheads idotherrefs
3973 global bookmarkids tagids headids otherrefids
3973 global bookmarkids tagids headids otherrefids
3974
3974
3975 set refids [concat [array names idtags] \
3975 set refids [concat [array names idtags] \
3976 [array names idheads] [array names idotherrefs] \
3976 [array names idheads] [array names idotherrefs] \
3977 [array names idbookmarks]]
3977 [array names idbookmarks]]
3978 foreach id $refids {
3978 foreach id $refids {
3979 if {![info exists ref($id)]} {
3979 if {![info exists ref($id)]} {
3980 set ref($id) [listrefs $id]
3980 set ref($id) [listrefs $id]
3981 }
3981 }
3982 }
3982 }
3983 foreach v {tagids idtags headids idheads otherrefids idotherrefs \
3983 foreach v {tagids idtags headids idheads otherrefids idotherrefs \
3984 bookmarkids idbookmarks} {
3984 bookmarkids idbookmarks} {
3985 catch {unset $v}
3985 catch {unset $v}
3986 }
3986 }
3987 readrefs
3987 readrefs
3988 set refids [lsort -unique [concat $refids [array names idtags] \
3988 set refids [lsort -unique [concat $refids [array names idtags] \
3989 [array names idheads] [array names idotherrefs] \
3989 [array names idheads] [array names idotherrefs] \
3990 [array names idbookmarks]]]
3990 [array names idbookmarks]]]
3991 foreach id $refids {
3991 foreach id $refids {
3992 set v [listrefs $id]
3992 set v [listrefs $id]
3993 if {![info exists ref($id)] || $ref($id) != $v} {
3993 if {![info exists ref($id)] || $ref($id) != $v} {
3994 redrawtags $id
3994 redrawtags $id
3995 }
3995 }
3996 }
3996 }
3997 }
3997 }
3998
3998
3999 proc vdiff {withparent} {
3999 proc vdiff {withparent} {
4000 global env rowmenuid selectedline lineid hgvdiff
4000 global env rowmenuid selectedline lineid hgvdiff
4001
4001
4002 if {![info exists rowmenuid]} return
4002 if {![info exists rowmenuid]} return
4003 set curid $rowmenuid
4003 set curid $rowmenuid
4004
4004
4005 if {$withparent} {
4005 if {$withparent} {
4006 set parents [exec $env(HG) --config ui.report_untrusted=false parents --rev $curid --template "{node}\n"]
4006 set parents [exec $env(HG) --config ui.report_untrusted=false parents --rev $curid --template "{node}\n"]
4007 set firstparent [lindex [split $parents "\n"] 0]
4007 set firstparent [lindex [split $parents "\n"] 0]
4008 set otherid $firstparent
4008 set otherid $firstparent
4009 } else {
4009 } else {
4010 if {![info exists selectedline]} return
4010 if {![info exists selectedline]} return
4011 set otherid $lineid($selectedline)
4011 set otherid $lineid($selectedline)
4012 }
4012 }
4013 set range "$otherid:$curid"
4013 set range "$otherid:$curid"
4014 if {[catch {exec $env(HG) --config ui.report_untrusted=false $hgvdiff -r $range} err]} {
4014 if {[catch {exec $env(HG) --config ui.report_untrusted=false $hgvdiff -r $range} err]} {
4015 # Ignore errors, this is just visualization
4015 # Ignore errors, this is just visualization
4016 }
4016 }
4017 }
4017 }
4018
4018
4019 proc showtag {tag isnew} {
4019 proc showtag {tag isnew} {
4020 global ctext cflist tagcontents tagids linknum
4020 global ctext cflist tagcontents tagids linknum
4021
4021
4022 if {$isnew} {
4022 if {$isnew} {
4023 addtohistory [list showtag $tag 0]
4023 addtohistory [list showtag $tag 0]
4024 }
4024 }
4025 $ctext conf -state normal
4025 $ctext conf -state normal
4026 $ctext delete 0.0 end
4026 $ctext delete 0.0 end
4027 set linknum 0
4027 set linknum 0
4028 if {[info exists tagcontents($tag)]} {
4028 if {[info exists tagcontents($tag)]} {
4029 set text $tagcontents($tag)
4029 set text $tagcontents($tag)
4030 } else {
4030 } else {
4031 set text "Tag: $tag\nId: $tagids($tag)"
4031 set text "Tag: $tag\nId: $tagids($tag)"
4032 }
4032 }
4033 appendwithlinks $text
4033 appendwithlinks $text
4034 $ctext conf -state disabled
4034 $ctext conf -state disabled
4035 $cflist delete 0 end
4035 $cflist delete 0 end
4036 }
4036 }
4037
4037
4038 proc doquit {} {
4038 proc doquit {} {
4039 global stopped
4039 global stopped
4040 set stopped 100
4040 set stopped 100
4041 destroy .
4041 destroy .
4042 }
4042 }
4043
4043
4044 proc getconfig {} {
4044 proc getconfig {} {
4045 global env
4045 global env
4046
4046
4047 set lines [exec $env(HG) debug-config]
4047 set lines [exec $env(HG) debug-config]
4048 regsub -all "\r\n" $lines "\n" config
4048 regsub -all "\r\n" $lines "\n" config
4049 set config {}
4049 set config {}
4050 foreach line [split $lines "\n"] {
4050 foreach line [split $lines "\n"] {
4051 regsub "^(k|v)=" $line "" line
4051 regsub "^(k|v)=" $line "" line
4052 lappend config $line
4052 lappend config $line
4053 }
4053 }
4054 return $config
4054 return $config
4055 }
4055 }
4056
4056
4057 # defaults...
4057 # defaults...
4058 set datemode 0
4058 set datemode 0
4059 set boldnames 0
4059 set boldnames 0
4060 set diffopts "-U 5 -p"
4060 set diffopts "-U 5 -p"
4061 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty"
4061 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty"
4062
4062
4063 set mainfont {Helvetica 9}
4063 set mainfont {Helvetica 9}
4064 set curidfont {}
4064 set curidfont {}
4065 set textfont {Courier 9}
4065 set textfont {Courier 9}
4066 set findmergefiles 0
4066 set findmergefiles 0
4067 set gaudydiff 0
4067 set gaudydiff 0
4068 set maxgraphpct 50
4068 set maxgraphpct 50
4069 set maxwidth 16
4069 set maxwidth 16
4070
4070
4071 set colors {green red blue magenta darkgrey brown orange}
4071 set colors {green red blue magenta darkgrey brown orange}
4072 set authorcolors {
4072 set authorcolors {
4073 black blue deeppink mediumorchid blue burlywood4 goldenrod slateblue red2 navy dimgrey
4073 black blue deeppink mediumorchid blue burlywood4 goldenrod slateblue red2 navy dimgrey
4074 }
4074 }
4075 set bgcolor white
4075 set bgcolor white
4076
4076
4077 # This color should probably be some system color (provided by tk),
4077 # This color should probably be some system color (provided by tk),
4078 # but as the bgcolor has always been set to white, I choose to ignore
4078 # but as the bgcolor has always been set to white, I choose to ignore
4079 set fgcolor black
4079 set fgcolor black
4080 set diffaddcolor "#00a000"
4080 set diffaddcolor "#00a000"
4081 set diffremcolor red
4081 set diffremcolor red
4082 set diffmerge1color red
4082 set diffmerge1color red
4083 set diffmerge2color blue
4083 set diffmerge2color blue
4084 set hunksepcolor blue
4084 set hunksepcolor blue
4085
4085
4086 catch {source ~/.hgk}
4086 catch {source ~/.hgk}
4087
4087
4088 if {$curidfont == ""} { # initialize late based on current mainfont
4088 if {$curidfont == ""} { # initialize late based on current mainfont
4089 set curidfont "$mainfont bold italic underline"
4089 set curidfont "$mainfont bold italic underline"
4090 }
4090 }
4091
4091
4092 set namefont $mainfont
4092 set namefont $mainfont
4093 if {$boldnames} {
4093 if {$boldnames} {
4094 lappend namefont bold
4094 lappend namefont bold
4095 }
4095 }
4096
4096
4097 set revtreeargs {}
4097 set revtreeargs {}
4098 foreach arg $argv {
4098 foreach arg $argv {
4099 switch -regexp -- $arg {
4099 switch -regexp -- $arg {
4100 "^$" { }
4100 "^$" { }
4101 "^-b" { set boldnames 1 }
4101 "^-b" { set boldnames 1 }
4102 "^-d" { set datemode 1 }
4102 "^-d" { set datemode 1 }
4103 default {
4103 default {
4104 lappend revtreeargs $arg
4104 lappend revtreeargs $arg
4105 }
4105 }
4106 }
4106 }
4107 }
4107 }
4108
4108
4109 set history {}
4109 set history {}
4110 set historyindex 0
4110 set historyindex 0
4111
4111
4112 set stopped 0
4112 set stopped 0
4113 set redisplaying 0
4113 set redisplaying 0
4114 set stuffsaved 0
4114 set stuffsaved 0
4115 set patchnum 0
4115 set patchnum 0
4116
4116
4117 array set config [getconfig]
4117 array set config [getconfig]
4118 set hgvdiff $config(vdiff)
4118 set hgvdiff $config(vdiff)
4119 setcoords
4119 setcoords
4120 makewindow
4120 makewindow
4121 readrefs
4121 readrefs
4122 set hgroot [exec $env(HG) root]
4122 set hgroot [exec $env(HG) root]
4123 wm title . "hgk $hgroot"
4123 wm title . "hgk $hgroot"
4124 getcommits $revtreeargs
4124 getcommits $revtreeargs
@@ -1,313 +1,313
1 # lint Python modules using external checkers.
1 # lint Python modules using external checkers.
2 #
2 #
3 # This is the main checker controlling the other ones and the reports
3 # This is the main checker controlling the other ones and the reports
4 # generation. It is itself both a raw checker and an astng checker in order
4 # generation. It is itself both a raw checker and an astng checker in order
5 # to:
5 # to:
6 # * handle message activation / deactivation at the module level
6 # * handle message activation / deactivation at the module level
7 # * handle some basic but necessary stats'data (number of classes, methods...)
7 # * handle some basic but necessary stats'data (number of classes, methods...)
8 #
8 #
9 [MASTER]
9 [MASTER]
10
10
11 # Specify a configuration file.
11 # Specify a configuration file.
12 #rcfile=
12 #rcfile=
13
13
14 # Python code to execute, usually for sys.path manipulation such as
14 # Python code to execute, usually for sys.path manipulation such as
15 # pygtk.require().
15 # pygtk.require().
16 #init-hook=
16 #init-hook=
17
17
18 # Profiled execution.
18 # Profiled execution.
19 profile=no
19 profile=no
20
20
21 # Add <file or directory> to the black list. It should be a base name, not a
21 # Add <file or directory> to the black list. It should be a base name, not a
22 # path. You may set this option multiple times.
22 # path. You may set this option multiple times.
23 ignore=CVS
23 ignore=CVS
24
24
25 # Pickle collected data for later comparisons.
25 # Pickle collected data for later comparisons.
26 persistent=yes
26 persistent=yes
27
27
28 # Set the cache size for astng objects.
28 # Set the cache size for astng objects.
29 cache-size=500
29 cache-size=500
30
30
31 # List of plugins (as comma separated values of python modules names) to load,
31 # List of plugins (as comma separated values of python modules names) to load,
32 # usually to register additional checkers.
32 # usually to register additional checkers.
33 load-plugins=
33 load-plugins=
34
34
35
35
36 [MESSAGES CONTROL]
36 [MESSAGES CONTROL]
37
37
38 # Enable only checker(s) with the given id(s). This option conflicts with the
38 # Enable only checker(s) with the given id(s). This option conflicts with the
39 # disable-checker option
39 # disable-checker option
40 #enable-checker=
40 #enable-checker=
41
41
42 # Enable all checker(s) except those with the given id(s). This option
42 # Enable all checker(s) except those with the given id(s). This option
43 # conflicts with the enable-checker option
43 # conflicts with the enable-checker option
44 #disable-checker=
44 #disable-checker=
45
45
46 # Enable all messages in the listed categories (IRCWEF).
46 # Enable all messages in the listed categories (IRCWEF).
47 #enable-msg-cat=
47 #enable-msg-cat=
48
48
49 # Disable all messages in the listed categories (IRCWEF).
49 # Disable all messages in the listed categories (IRCWEF).
50 disable-msg-cat=I
50 disable-msg-cat=I
51
51
52 # Enable the message(s) with the given id(s).
52 # Enable the message(s) with the given id(s).
53 #enable-msg=
53 #enable-msg=
54
54
55 # Disable the message(s) with the given id(s).
55 # Disable the message(s) with the given id(s).
56 # W0704: except: pass
56 # W0704: except: pass
57 # C0111: missing docstring
57 # C0111: missing docstring
58 # W0403: for the time being absolute imports don't play nice with demandimport
58 # W0403: for the time being absolute imports don't play nice with demandimport
59 disable-msg=W0704,C0111,W0403
59 disable-msg=W0704,C0111,W0403
60
60
61
61
62 [REPORTS]
62 [REPORTS]
63
63
64 # Set the output format. Available formats are text, parseable, colorized, msvs
64 # Set the output format. Available formats are text, parseable, colorized, msvs
65 # (visual studio) and html
65 # (visual studio) and html
66 output-format=text
66 output-format=text
67
67
68 # Include message's id in output
68 # Include message's id in output
69 include-ids=yes
69 include-ids=yes
70
70
71 # Put messages in a separate file for each module / package specified on the
71 # Put messages in a separate file for each module / package specified on the
72 # command line instead of printing them on stdout. Reports (if any) will be
72 # command line instead of printing them on stdout. Reports (if any) will be
73 # written in a file name "pylint_global.[txt|html]".
73 # written in a file name "pylint_global.[txt|html]".
74 files-output=no
74 files-output=no
75
75
76 # Tells whether to display a full report or only the messages
76 # Tells whether to display a full report or only the messages
77 reports=yes
77 reports=yes
78
78
79 # Python expression which should return a note less than 10 (10 is the highest
79 # Python expression which should return a note less than 10 (10 is the highest
80 # note). You have access to the variables errors warning, statement which
80 # note). You have access to the variables errors warning, statement which
81 # respectively contain the number of errors / warnings messages and the total
81 # respectively contain the number of errors / warnings messages and the total
82 # number of statements analyzed. This is used by the global evaluation report
82 # number of statements analyzed. This is used by the global evaluation report
83 # (R0004).
83 # (R0004).
84 evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
84 evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
85
85
86 # Add a comment according to your evaluation note. This is used by the global
86 # Add a comment according to your evaluation note. This is used by the global
87 # evaluation report (R0004).
87 # evaluation report (R0004).
88 comment=no
88 comment=no
89
89
90 # Enable the report(s) with the given id(s).
90 # Enable the report(s) with the given id(s).
91 #enable-report=
91 #enable-report=
92
92
93 # Disable the report(s) with the given id(s).
93 # Disable the report(s) with the given id(s).
94 #disable-report=
94 #disable-report=
95
95
96
96
97 # try to find bugs in the code using type inference
97 # try to find bugs in the code using type inference
98 #
98 #
99 [TYPECHECK]
99 [TYPECHECK]
100
100
101 # Tells whether missing members accessed in mixin class should be ignored. A
101 # Tells whether missing members accessed in mixin class should be ignored. A
102 # mixin class is detected if its name ends with "mixin" (case insensitive).
102 # mixin class is detected if its name ends with "mixin" (case insensitive).
103 ignore-mixin-members=yes
103 ignore-mixin-members=yes
104
104
105 # List of classes names for which member attributes should not be checked
105 # List of classes names for which member attributes should not be checked
106 # (useful for classes with attributes dynamically set).
106 # (useful for classes with attributes dynamically set).
107 ignored-classes=SQLObject
107 ignored-classes=SQLObject
108
108
109 # When zope mode is activated, add a predefined set of Zope acquired attributes
109 # When zope mode is activated, add a predefined set of Zope acquired attributes
110 # to generated-members.
110 # to generated-members.
111 zope=no
111 zope=no
112
112
113 # List of members which are set dynamically and missed by pylint inference
113 # List of members which are set dynamically and missed by pylint inference
114 # system, and so shouldn't trigger E0201 when accessed.
114 # system, and so shouldn't trigger E0201 when accessed.
115 generated-members=REQUEST,acl_users,aq_parent
115 generated-members=REQUEST,acl_users,aq_parent
116
116
117
117
118 # checks for
118 # checks for
119 # * unused variables / imports
119 # * unused variables / imports
120 # * undefined variables
120 # * undefined variables
121 # * redefinition of variable from builtins or from an outer scope
121 # * redefinition of variable from builtins or from an outer scope
122 # * use of variable before assignment
122 # * use of variable before assignment
123 #
123 #
124 [VARIABLES]
124 [VARIABLES]
125
125
126 # Tells whether we should check for unused import in __init__ files.
126 # Tells whether we should check for unused import in __init__ files.
127 init-import=yes
127 init-import=yes
128
128
129 # A regular expression matching names used for dummy variables (i.e. not used).
129 # A regular expression matching names used for dummy variables (i.e. not used).
130 dummy-variables-rgx=dummy
130 dummy-variables-rgx=dummy
131
131
132 # List of additional names supposed to be defined in builtins. Remember that
132 # List of additional names supposed to be defined in builtins. Remember that
133 # you should avoid to define new builtins when possible.
133 # you should avoid to define new builtins when possible.
134 additional-builtins=
134 additional-builtins=
135
135
136
136
137 # checks for :
137 # checks for :
138 # * doc strings
138 # * doc strings
139 # * modules / classes / functions / methods / arguments / variables name
139 # * modules / classes / functions / methods / arguments / variables name
140 # * number of arguments, local variables, branches, returns and statements in
140 # * number of arguments, local variables, branches, returns and statements in
141 # functions, methods
141 # functions, methods
142 # * required module attributes
142 # * required module attributes
143 # * dangerous default values as arguments
143 # * dangerous default values as arguments
144 # * redefinition of function / method / class
144 # * redefinition of function / method / class
145 # * uses of the global statement
145 # * uses of the global statement
146 #
146 #
147 [BASIC]
147 [BASIC]
148
148
149 # Required attributes for module, separated by a comma
149 # Required attributes for module, separated by a comma
150 required-attributes=
150 required-attributes=
151
151
152 # Regular expression which should only match functions or classes name which do
152 # Regular expression which should only match functions or classes name which do
153 # not require a docstring
153 # not require a docstring
154 no-docstring-rgx=__.*__
154 no-docstring-rgx=__.*__
155
155
156 # Regular expression which should only match correct module names
156 # Regular expression which should only match correct module names
157 module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
157 module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
158
158
159 # Regular expression which should only match correct module level names
159 # Regular expression which should only match correct module level names
160 const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
160 const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
161
161
162 # Regular expression which should only match correct class names
162 # Regular expression which should only match correct class names
163 class-rgx=[a-zA-Z_][a-zA-Z0-9]+$
163 class-rgx=[a-zA-Z_][a-zA-Z0-9]+$
164
164
165 # Regular expression which should only match correct function names
165 # Regular expression which should only match correct function names
166 function-rgx=[a-z_][a-z0-9_]{2,30}$
166 function-rgx=[a-z_][a-z0-9_]{2,30}$
167
167
168 # Regular expression which should only match correct method names
168 # Regular expression which should only match correct method names
169 method-rgx=[a-z_][a-z0-9_]{2,30}$
169 method-rgx=[a-z_][a-z0-9_]{2,30}$
170
170
171 # Regular expression which should only match correct instance attribute names
171 # Regular expression which should only match correct instance attribute names
172 attr-rgx=[a-z_][a-z0-9_]{1,30}$
172 attr-rgx=[a-z_][a-z0-9_]{1,30}$
173
173
174 # Regular expression which should only match correct argument names
174 # Regular expression which should only match correct argument names
175 argument-rgx=[a-z_][a-z0-9_]{0,30}$
175 argument-rgx=[a-z_][a-z0-9_]{0,30}$
176
176
177 # Regular expression which should only match correct variable names
177 # Regular expression which should only match correct variable names
178 variable-rgx=[a-z_][a-z0-9_]{0,30}$
178 variable-rgx=[a-z_][a-z0-9_]{0,30}$
179
179
180 # Regular expression which should only match correct list comprehension /
180 # Regular expression which should only match correct list comprehension /
181 # generator expression variable names
181 # generator expression variable names
182 inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
182 inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
183
183
184 # Good variable names which should always be accepted, separated by a comma
184 # Good variable names which should always be accepted, separated by a comma
185 good-names=i,j,k,ex,Run,_,ui,c,fn,f,fd,l
185 good-names=i,j,k,ex,Run,_,ui,c,fn,f,fd,l
186
186
187 # Bad variable names which should always be refused, separated by a comma
187 # Bad variable names which should always be refused, separated by a comma
188 bad-names=foo,bar,baz,toto,tutu,tata
188 bad-names=foo,bar,baz,toto,tutu,tata
189
189
190 # List of builtins function names that should not be used, separated by a comma
190 # List of builtins function names that should not be used, separated by a comma
191 #bad-functions=map,filter,apply,input
191 #bad-functions=map,filter,apply,input
192 bad-functions=map,filter,apply,input
192 bad-functions=map,filter,apply,input
193
193
194
194
195 # checks for
195 # checks for
196 # * external modules dependencies
196 # * external modules dependencies
197 # * relative / wildcard imports
197 # * relative / wildcard imports
198 # * cyclic imports
198 # * cyclic imports
199 # * uses of deprecated modules
199 # * uses of deprecated modules
200 #
200 #
201 [IMPORTS]
201 [IMPORTS]
202
202
203 # Deprecated modules which should not be used, separated by a comma
203 # Deprecated modules which should not be used, separated by a comma
204 deprecated-modules=regsub,TERMIOS,Bastion,rexec
204 deprecated-modules=regsub,TERMIOS,Bastion,rexec
205
205
206 # Create a graph of every (i.e. internal and external) dependencies in the
206 # Create a graph of every (i.e. internal and external) dependencies in the
207 # given file (report R0402 must not be disabled)
207 # given file (report R0402 must not be disabled)
208 import-graph=
208 import-graph=
209
209
210 # Create a graph of external dependencies in the given file (report R0402 must
210 # Create a graph of external dependencies in the given file (report R0402 must
211 # not be disabled)
211 # not be disabled)
212 ext-import-graph=
212 ext-import-graph=
213
213
214 # Create a graph of internal dependencies in the given file (report R0402 must
214 # Create a graph of internal dependencies in the given file (report R0402 must
215 # not be disabled)
215 # not be disabled)
216 int-import-graph=
216 int-import-graph=
217
217
218
218
219 # checks for sign of poor/misdesign:
219 # checks for sign of poor/misdesign:
220 # * number of methods, attributes, local variables...
220 # * number of methods, attributes, local variables...
221 # * size, complexity of functions, methods
221 # * size, complexity of functions, methods
222 #
222 #
223 [DESIGN]
223 [DESIGN]
224
224
225 # Maximum number of arguments for function / method
225 # Maximum number of arguments for function / method
226 max-args=5
226 max-args=5
227
227
228 # Maximum number of locals for function / method body
228 # Maximum number of locals for function / method body
229 max-locals=15
229 max-locals=15
230
230
231 # Maximum number of return / yield for function / method body
231 # Maximum number of return / yield for function / method body
232 max-returns=6
232 max-returns=6
233
233
234 # Maximum number of branch for function / method body
234 # Maximum number of branch for function / method body
235 max-branchs=12
235 max-branchs=12
236
236
237 # Maximum number of statements in function / method body
237 # Maximum number of statements in function / method body
238 max-statements=50
238 max-statements=50
239
239
240 # Maximum number of parents for a class (see R0901).
240 # Maximum number of parents for a class (see R0901).
241 max-parents=7
241 max-parents=7
242
242
243 # Maximum number of attributes for a class (see R0902).
243 # Maximum number of attributes for a class (see R0902).
244 max-attributes=7
244 max-attributes=7
245
245
246 # Minimum number of public methods for a class (see R0903).
246 # Minimum number of public methods for a class (see R0903).
247 min-public-methods=2
247 min-public-methods=2
248
248
249 # Maximum number of public methods for a class (see R0904).
249 # Maximum number of public methods for a class (see R0904).
250 max-public-methods=20
250 max-public-methods=20
251
251
252
252
253 # checks for :
253 # checks for :
254 # * methods without self as first argument
254 # * methods without self as first argument
255 # * overridden methods signature
255 # * overridden methods signature
256 # * access only to existent members via self
256 # * access only to existent members via self
257 # * attributes not defined in the __init__ method
257 # * attributes not defined in the __init__ method
258 # * supported interfaces implementation
258 # * supported interfaces implementation
259 # * unreachable code
259 # * unreachable code
260 #
260 #
261 [CLASSES]
261 [CLASSES]
262
262
263 # List of interface methods to ignore, separated by a comma. This is used for
263 # List of interface methods to ignore, separated by a comma. This is used for
264 # instance to not check methods defines in Zope's Interface base class.
264 # instance to not check methods defines in Zope's Interface base class.
265 ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
265 ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
266
266
267 # List of method names used to declare (i.e. assign) instance attributes.
267 # List of method names used to declare (i.e. assign) instance attributes.
268 defining-attr-methods=__init__,__new__,setUp
268 defining-attr-methods=__init__,__new__,setUp
269
269
270
270
271 # checks for :
271 # checks for :
272 # * unauthorized constructions
272 # * unauthorized constructions
273 # * strict indentation
273 # * strict indentation
274 # * line length
274 # * line length
275 # * use of <> instead of !=
275 # * use of <> instead of !=
276 #
276 #
277 [FORMAT]
277 [FORMAT]
278
278
279 # Maximum number of characters on a single line.
279 # Maximum number of characters on a single line.
280 max-line-length=80
280 max-line-length=80
281
281
282 # Maximum number of lines in a module
282 # Maximum number of lines in a module
283 max-module-lines=1000
283 max-module-lines=1000
284
284
285 # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
285 # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
286 # tab).
286 # tab).
287 indent-string=' '
287 indent-string=' '
288
288
289
289
290 # checks for:
290 # checks for:
291 # * warning notes in the code like FIXME, XXX
291 # * warning notes in the code like FIXME, XXX
292 # * PEP 263: source code with non ascii character but no encoding declaration
292 # * PEP 263: source code with non ascii character but no encoding declaration
293 #
293 #
294 [MISCELLANEOUS]
294 [MISCELLANEOUS]
295
295
296 # List of note tags to take in consideration, separated by a comma.
296 # List of note tags to take in consideration, separated by a comma.
297 notes=FIXME,XXX,TODO
297 notes=FIXME,XXX,TODO
298
298
299
299
300 # checks for similarities and duplicated code. This computation may be
300 # checks for similarities and duplicated code. This computation may be
301 # memory / CPU intensive, so you should disable it if you experiments some
301 # memory / CPU intensive, so you should disable it if you experiments some
302 # problems.
302 # problems.
303 #
303 #
304 [SIMILARITIES]
304 [SIMILARITIES]
305
305
306 # Minimum lines number of a similarity.
306 # Minimum lines number of a similarity.
307 min-similarity-lines=4
307 min-similarity-lines=4
308
308
309 # Ignore comments when computing similarities.
309 # Ignore comments when computing similarities.
310 ignore-comments=yes
310 ignore-comments=yes
311
311
312 # Ignore docstrings when computing similarities.
312 # Ignore docstrings when computing similarities.
313 ignore-docstrings=yes
313 ignore-docstrings=yes
@@ -1,1703 +1,1703
1 " vim600: set foldmethod=marker:
1 " vim600: set foldmethod=marker:
2 "
2 "
3 " Vim plugin to assist in working with HG-controlled files.
3 " Vim plugin to assist in working with HG-controlled files.
4 "
4 "
5 " Last Change: 2006/02/22
5 " Last Change: 2006/02/22
6 " Version: 1.77
6 " Version: 1.77
7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
8 " License: This file is placed in the public domain.
8 " License: This file is placed in the public domain.
9 " Credits:
9 " Credits:
10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
11 " cvscommand.vim from which this script was directly created by
11 " cvscommand.vim from which this script was directly created by
12 " means of sed commands and minor tweaks.
12 " means of sed commands and minor tweaks.
13 " Note:
13 " Note:
14 " For Vim7 the use of Bob Hiestand's vcscommand.vim
14 " For Vim7 the use of Bob Hiestand's vcscommand.vim
15 " <http://www.vim.org/scripts/script.php?script_id=90>
15 " <http://www.vim.org/scripts/script.php?script_id=90>
16 " in conjunction with Vladmir Marek's Hg backend
16 " in conjunction with Vladmir Marek's Hg backend
17 " <http://www.vim.org/scripts/script.php?script_id=1898>
17 " <http://www.vim.org/scripts/script.php?script_id=1898>
18 " is recommended.
18 " is recommended.
19
19
20 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
20 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
21 "
21 "
22 " Section: Documentation
22 " Section: Documentation
23 "----------------------------
23 "----------------------------
24 "
24 "
25 " Documentation should be available by ":help hgcommand" command, once the
25 " Documentation should be available by ":help hgcommand" command, once the
26 " script has been copied in you .vim/plugin directory.
26 " script has been copied in you .vim/plugin directory.
27 "
27 "
28 " You still can read the documentation at the end of this file. Locate it by
28 " You still can read the documentation at the end of this file. Locate it by
29 " searching the "hgcommand-contents" string (and set ft=help to have
29 " searching the "hgcommand-contents" string (and set ft=help to have
30 " appropriate syntactic coloration).
30 " appropriate syntactic coloration).
31
31
32 " Section: Plugin header {{{1
32 " Section: Plugin header {{{1
33
33
34 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
34 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
35 " completes. This allows various actions to only be taken by functions after
35 " completes. This allows various actions to only be taken by functions after
36 " system initialization.
36 " system initialization.
37
37
38 if exists("g:loaded_hgcommand")
38 if exists("g:loaded_hgcommand")
39 finish
39 finish
40 endif
40 endif
41 let g:loaded_hgcommand = 1
41 let g:loaded_hgcommand = 1
42
42
43 " store 'compatible' settings
43 " store 'compatible' settings
44 let s:save_cpo = &cpo
44 let s:save_cpo = &cpo
45 set cpo&vim
45 set cpo&vim
46
46
47 " run checks
47 " run checks
48 let s:script_name = expand("<sfile>:t:r")
48 let s:script_name = expand("<sfile>:t:r")
49
49
50 function! s:HGCleanupOnFailure(err)
50 function! s:HGCleanupOnFailure(err)
51 echohl WarningMsg
51 echohl WarningMsg
52 echomsg s:script_name . ":" a:err "Plugin not loaded"
52 echomsg s:script_name . ":" a:err "Plugin not loaded"
53 echohl None
53 echohl None
54 let g:loaded_hgcommand = "no"
54 let g:loaded_hgcommand = "no"
55 unlet s:save_cpo s:script_name
55 unlet s:save_cpo s:script_name
56 endfunction
56 endfunction
57
57
58 if v:version < 602
58 if v:version < 602
59 call <SID>HGCleanupOnFailure("VIM 6.2 or later required.")
59 call <SID>HGCleanupOnFailure("VIM 6.2 or later required.")
60 finish
60 finish
61 endif
61 endif
62
62
63 if !exists("*system")
63 if !exists("*system")
64 call <SID>HGCleanupOnFailure("builtin system() function required.")
64 call <SID>HGCleanupOnFailure("builtin system() function required.")
65 finish
65 finish
66 endif
66 endif
67
67
68 let s:script_version = "v0.2"
68 let s:script_version = "v0.2"
69
69
70 " Section: Event group setup {{{1
70 " Section: Event group setup {{{1
71
71
72 augroup HGCommand
72 augroup HGCommand
73 augroup END
73 augroup END
74
74
75 " Section: Plugin initialization {{{1
75 " Section: Plugin initialization {{{1
76 silent do HGCommand User HGPluginInit
76 silent do HGCommand User HGPluginInit
77
77
78 " Section: Script variable initialization {{{1
78 " Section: Script variable initialization {{{1
79
79
80 let s:HGCommandEditFileRunning = 0
80 let s:HGCommandEditFileRunning = 0
81 unlet! s:vimDiffRestoreCmd
81 unlet! s:vimDiffRestoreCmd
82 unlet! s:vimDiffSourceBuffer
82 unlet! s:vimDiffSourceBuffer
83 unlet! s:vimDiffBufferCount
83 unlet! s:vimDiffBufferCount
84 unlet! s:vimDiffScratchList
84 unlet! s:vimDiffScratchList
85
85
86 " Section: Utility functions {{{1
86 " Section: Utility functions {{{1
87
87
88 " Function: s:HGResolveLink() {{{2
88 " Function: s:HGResolveLink() {{{2
89 " Fully resolve the given file name to remove shortcuts or symbolic links.
89 " Fully resolve the given file name to remove shortcuts or symbolic links.
90
90
91 function! s:HGResolveLink(fileName)
91 function! s:HGResolveLink(fileName)
92 let resolved = resolve(a:fileName)
92 let resolved = resolve(a:fileName)
93 if resolved != a:fileName
93 if resolved != a:fileName
94 let resolved = <SID>HGResolveLink(resolved)
94 let resolved = <SID>HGResolveLink(resolved)
95 endif
95 endif
96 return resolved
96 return resolved
97 endfunction
97 endfunction
98
98
99 " Function: s:HGChangeToCurrentFileDir() {{{2
99 " Function: s:HGChangeToCurrentFileDir() {{{2
100 " Go to the directory in which the current HG-controlled file is located.
100 " Go to the directory in which the current HG-controlled file is located.
101 " If this is a HG command buffer, first switch to the original file.
101 " If this is a HG command buffer, first switch to the original file.
102
102
103 function! s:HGChangeToCurrentFileDir(fileName)
103 function! s:HGChangeToCurrentFileDir(fileName)
104 let oldCwd=getcwd()
104 let oldCwd=getcwd()
105 let fileName=<SID>HGResolveLink(a:fileName)
105 let fileName=<SID>HGResolveLink(a:fileName)
106 let newCwd=fnamemodify(fileName, ':h')
106 let newCwd=fnamemodify(fileName, ':h')
107 if strlen(newCwd) > 0
107 if strlen(newCwd) > 0
108 execute 'cd' escape(newCwd, ' ')
108 execute 'cd' escape(newCwd, ' ')
109 endif
109 endif
110 return oldCwd
110 return oldCwd
111 endfunction
111 endfunction
112
112
113 " Function: <SID>HGGetOption(name, default) {{{2
113 " Function: <SID>HGGetOption(name, default) {{{2
114 " Grab a user-specified option to override the default provided. Options are
114 " Grab a user-specified option to override the default provided. Options are
115 " searched in the window, buffer, then global spaces.
115 " searched in the window, buffer, then global spaces.
116
116
117 function! s:HGGetOption(name, default)
117 function! s:HGGetOption(name, default)
118 if exists("s:" . a:name . "Override")
118 if exists("s:" . a:name . "Override")
119 execute "return s:".a:name."Override"
119 execute "return s:".a:name."Override"
120 elseif exists("w:" . a:name)
120 elseif exists("w:" . a:name)
121 execute "return w:".a:name
121 execute "return w:".a:name
122 elseif exists("b:" . a:name)
122 elseif exists("b:" . a:name)
123 execute "return b:".a:name
123 execute "return b:".a:name
124 elseif exists("g:" . a:name)
124 elseif exists("g:" . a:name)
125 execute "return g:".a:name
125 execute "return g:".a:name
126 else
126 else
127 return a:default
127 return a:default
128 endif
128 endif
129 endfunction
129 endfunction
130
130
131 " Function: s:HGEditFile(name, origBuffNR) {{{2
131 " Function: s:HGEditFile(name, origBuffNR) {{{2
132 " Wrapper around the 'edit' command to provide some helpful error text if the
132 " Wrapper around the 'edit' command to provide some helpful error text if the
133 " current buffer can't be abandoned. If name is provided, it is used;
133 " current buffer can't be abandoned. If name is provided, it is used;
134 " otherwise, a nameless scratch buffer is used.
134 " otherwise, a nameless scratch buffer is used.
135 " Returns: 0 if successful, -1 if an error occurs.
135 " Returns: 0 if successful, -1 if an error occurs.
136
136
137 function! s:HGEditFile(name, origBuffNR)
137 function! s:HGEditFile(name, origBuffNR)
138 "Name parameter will be pasted into expression.
138 "Name parameter will be pasted into expression.
139 let name = escape(a:name, ' *?\')
139 let name = escape(a:name, ' *?\')
140
140
141 let editCommand = <SID>HGGetOption('HGCommandEdit', 'edit')
141 let editCommand = <SID>HGGetOption('HGCommandEdit', 'edit')
142 if editCommand != 'edit'
142 if editCommand != 'edit'
143 if <SID>HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
143 if <SID>HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
144 if name == ""
144 if name == ""
145 let editCommand = 'rightbelow new'
145 let editCommand = 'rightbelow new'
146 else
146 else
147 let editCommand = 'rightbelow split ' . name
147 let editCommand = 'rightbelow split ' . name
148 endif
148 endif
149 else
149 else
150 if name == ""
150 if name == ""
151 let editCommand = 'vert rightbelow new'
151 let editCommand = 'vert rightbelow new'
152 else
152 else
153 let editCommand = 'vert rightbelow split ' . name
153 let editCommand = 'vert rightbelow split ' . name
154 endif
154 endif
155 endif
155 endif
156 else
156 else
157 if name == ""
157 if name == ""
158 let editCommand = 'enew'
158 let editCommand = 'enew'
159 else
159 else
160 let editCommand = 'edit ' . name
160 let editCommand = 'edit ' . name
161 endif
161 endif
162 endif
162 endif
163
163
164 " Protect against useless buffer set-up
164 " Protect against useless buffer set-up
165 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
165 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
166 try
166 try
167 execute editCommand
167 execute editCommand
168 finally
168 finally
169 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
169 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
170 endtry
170 endtry
171
171
172 let b:HGOrigBuffNR=a:origBuffNR
172 let b:HGOrigBuffNR=a:origBuffNR
173 let b:HGCommandEdit='split'
173 let b:HGCommandEdit='split'
174 endfunction
174 endfunction
175
175
176 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
176 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
177 " Creates a new scratch buffer and captures the output from execution of the
177 " Creates a new scratch buffer and captures the output from execution of the
178 " given command. The name of the scratch buffer is returned.
178 " given command. The name of the scratch buffer is returned.
179
179
180 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
180 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
181 let fileName=bufname(a:origBuffNR)
181 let fileName=bufname(a:origBuffNR)
182
182
183 let resultBufferName=''
183 let resultBufferName=''
184
184
185 if <SID>HGGetOption("HGCommandNameResultBuffers", 0)
185 if <SID>HGGetOption("HGCommandNameResultBuffers", 0)
186 let nameMarker = <SID>HGGetOption("HGCommandNameMarker", '_')
186 let nameMarker = <SID>HGGetOption("HGCommandNameMarker", '_')
187 if strlen(a:statusText) > 0
187 if strlen(a:statusText) > 0
188 let bufName=a:cmdName . ' -- ' . a:statusText
188 let bufName=a:cmdName . ' -- ' . a:statusText
189 else
189 else
190 let bufName=a:cmdName
190 let bufName=a:cmdName
191 endif
191 endif
192 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
192 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
193 let counter=0
193 let counter=0
194 let resultBufferName = bufName
194 let resultBufferName = bufName
195 while buflisted(resultBufferName)
195 while buflisted(resultBufferName)
196 let counter=counter + 1
196 let counter=counter + 1
197 let resultBufferName=bufName . ' (' . counter . ')'
197 let resultBufferName=bufName . ' (' . counter . ')'
198 endwhile
198 endwhile
199 endif
199 endif
200
200
201 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
201 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
202 "echomsg "DBG :".hgCommand
202 "echomsg "DBG :".hgCommand
203 let hgOut = system(hgCommand)
203 let hgOut = system(hgCommand)
204 " HACK: diff command does not return proper error codes
204 " HACK: diff command does not return proper error codes
205 if v:shell_error && a:cmdName != 'hgdiff'
205 if v:shell_error && a:cmdName != 'hgdiff'
206 if strlen(hgOut) == 0
206 if strlen(hgOut) == 0
207 echoerr "HG command failed"
207 echoerr "HG command failed"
208 else
208 else
209 echoerr "HG command failed: " . hgOut
209 echoerr "HG command failed: " . hgOut
210 endif
210 endif
211 return -1
211 return -1
212 endif
212 endif
213 if strlen(hgOut) == 0
213 if strlen(hgOut) == 0
214 " Handle case of no output. In this case, it is important to check the
214 " Handle case of no output. In this case, it is important to check the
215 " file status, especially since hg edit/unedit may change the attributes
215 " file status, especially since hg edit/unedit may change the attributes
216 " of the file with no visible output.
216 " of the file with no visible output.
217
217
218 echomsg "No output from HG command"
218 echomsg "No output from HG command"
219 checktime
219 checktime
220 return -1
220 return -1
221 endif
221 endif
222
222
223 if <SID>HGEditFile(resultBufferName, a:origBuffNR) == -1
223 if <SID>HGEditFile(resultBufferName, a:origBuffNR) == -1
224 return -1
224 return -1
225 endif
225 endif
226
226
227 set buftype=nofile
227 set buftype=nofile
228 set noswapfile
228 set noswapfile
229 set filetype=
229 set filetype=
230
230
231 if <SID>HGGetOption("HGCommandDeleteOnHide", 0)
231 if <SID>HGGetOption("HGCommandDeleteOnHide", 0)
232 set bufhidden=delete
232 set bufhidden=delete
233 endif
233 endif
234
234
235 silent 0put=hgOut
235 silent 0put=hgOut
236
236
237 " The last command left a blank line at the end of the buffer. If the
237 " The last command left a blank line at the end of the buffer. If the
238 " last line is folded (a side effect of the 'put') then the attempt to
238 " last line is folded (a side effect of the 'put') then the attempt to
239 " remove the blank line will kill the last fold.
239 " remove the blank line will kill the last fold.
240 "
240 "
241 " This could be fixed by explicitly detecting whether the last line is
241 " This could be fixed by explicitly detecting whether the last line is
242 " within a fold, but I prefer to simply unfold the result buffer altogether.
242 " within a fold, but I prefer to simply unfold the result buffer altogether.
243
243
244 if has("folding")
244 if has("folding")
245 setlocal nofoldenable
245 setlocal nofoldenable
246 endif
246 endif
247
247
248 $d
248 $d
249 1
249 1
250
250
251 " Define the environment and execute user-defined hooks.
251 " Define the environment and execute user-defined hooks.
252
252
253 let b:HGSourceFile=fileName
253 let b:HGSourceFile=fileName
254 let b:HGCommand=a:cmdName
254 let b:HGCommand=a:cmdName
255 if a:statusText != ""
255 if a:statusText != ""
256 let b:HGStatusText=a:statusText
256 let b:HGStatusText=a:statusText
257 endif
257 endif
258
258
259 silent do HGCommand User HGBufferCreated
259 silent do HGCommand User HGBufferCreated
260 return bufnr("%")
260 return bufnr("%")
261 endfunction
261 endfunction
262
262
263 " Function: s:HGBufferCheck(hgBuffer) {{{2
263 " Function: s:HGBufferCheck(hgBuffer) {{{2
264 " Attempts to locate the original file to which HG operations were applied
264 " Attempts to locate the original file to which HG operations were applied
265 " for a given buffer.
265 " for a given buffer.
266
266
267 function! s:HGBufferCheck(hgBuffer)
267 function! s:HGBufferCheck(hgBuffer)
268 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
268 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
269 if origBuffer
269 if origBuffer
270 if bufexists(origBuffer)
270 if bufexists(origBuffer)
271 return origBuffer
271 return origBuffer
272 else
272 else
273 " Original buffer no longer exists.
273 " Original buffer no longer exists.
274 return -1
274 return -1
275 endif
275 endif
276 else
276 else
277 " No original buffer
277 " No original buffer
278 return a:hgBuffer
278 return a:hgBuffer
279 endif
279 endif
280 endfunction
280 endfunction
281
281
282 " Function: s:HGCurrentBufferCheck() {{{2
282 " Function: s:HGCurrentBufferCheck() {{{2
283 " Attempts to locate the original file to which HG operations were applied
283 " Attempts to locate the original file to which HG operations were applied
284 " for the current buffer.
284 " for the current buffer.
285
285
286 function! s:HGCurrentBufferCheck()
286 function! s:HGCurrentBufferCheck()
287 return <SID>HGBufferCheck(bufnr("%"))
287 return <SID>HGBufferCheck(bufnr("%"))
288 endfunction
288 endfunction
289
289
290 " Function: s:HGToggleDeleteOnHide() {{{2
290 " Function: s:HGToggleDeleteOnHide() {{{2
291 " Toggles on and off the delete-on-hide behavior of HG buffers
291 " Toggles on and off the delete-on-hide behavior of HG buffers
292
292
293 function! s:HGToggleDeleteOnHide()
293 function! s:HGToggleDeleteOnHide()
294 if exists("g:HGCommandDeleteOnHide")
294 if exists("g:HGCommandDeleteOnHide")
295 unlet g:HGCommandDeleteOnHide
295 unlet g:HGCommandDeleteOnHide
296 else
296 else
297 let g:HGCommandDeleteOnHide=1
297 let g:HGCommandDeleteOnHide=1
298 endif
298 endif
299 endfunction
299 endfunction
300
300
301 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
301 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
302 " General skeleton for HG function execution.
302 " General skeleton for HG function execution.
303 " Returns: name of the new command buffer containing the command results
303 " Returns: name of the new command buffer containing the command results
304
304
305 function! s:HGDoCommand(cmd, cmdName, statusText)
305 function! s:HGDoCommand(cmd, cmdName, statusText)
306 let hgBufferCheck=<SID>HGCurrentBufferCheck()
306 let hgBufferCheck=<SID>HGCurrentBufferCheck()
307 if hgBufferCheck == -1
307 if hgBufferCheck == -1
308 echo "Original buffer no longer exists, aborting."
308 echo "Original buffer no longer exists, aborting."
309 return -1
309 return -1
310 endif
310 endif
311
311
312 let fileName=bufname(hgBufferCheck)
312 let fileName=bufname(hgBufferCheck)
313 if isdirectory(fileName)
313 if isdirectory(fileName)
314 let fileName=fileName . "/" . getline(".")
314 let fileName=fileName . "/" . getline(".")
315 endif
315 endif
316 let realFileName = fnamemodify(<SID>HGResolveLink(fileName), ':t')
316 let realFileName = fnamemodify(<SID>HGResolveLink(fileName), ':t')
317 let oldCwd=<SID>HGChangeToCurrentFileDir(fileName)
317 let oldCwd=<SID>HGChangeToCurrentFileDir(fileName)
318 try
318 try
319 " TODO
319 " TODO
320 "if !filereadable('HG/Root')
320 "if !filereadable('HG/Root')
321 "throw fileName . ' is not a HG-controlled file.'
321 "throw fileName . ' is not a HG-controlled file.'
322 "endif
322 "endif
323 let fullCmd = a:cmd . ' "' . realFileName . '"'
323 let fullCmd = a:cmd . ' "' . realFileName . '"'
324 "echomsg "DEBUG".fullCmd
324 "echomsg "DEBUG".fullCmd
325 let resultBuffer=<SID>HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
325 let resultBuffer=<SID>HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
326 return resultBuffer
326 return resultBuffer
327 catch
327 catch
328 echoerr v:exception
328 echoerr v:exception
329 return -1
329 return -1
330 finally
330 finally
331 execute 'cd' escape(oldCwd, ' ')
331 execute 'cd' escape(oldCwd, ' ')
332 endtry
332 endtry
333 endfunction
333 endfunction
334
334
335
335
336 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
336 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
337 "
337 "
338 " Obtains a HG revision number and branch name. The 'revisionVar',
338 " Obtains a HG revision number and branch name. The 'revisionVar',
339 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
339 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
340 " the corresponding results.
340 " the corresponding results.
341 "
341 "
342 " Returns: string to be exec'd that sets the multiple return values.
342 " Returns: string to be exec'd that sets the multiple return values.
343
343
344 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
344 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
345 let hgBufferCheck=<SID>HGCurrentBufferCheck()
345 let hgBufferCheck=<SID>HGCurrentBufferCheck()
346 "echomsg "DBG : in HGGetStatusVars"
346 "echomsg "DBG : in HGGetStatusVars"
347 if hgBufferCheck == -1
347 if hgBufferCheck == -1
348 return ""
348 return ""
349 endif
349 endif
350 let fileName=bufname(hgBufferCheck)
350 let fileName=bufname(hgBufferCheck)
351 let fileNameWithoutLink=<SID>HGResolveLink(fileName)
351 let fileNameWithoutLink=<SID>HGResolveLink(fileName)
352 let realFileName = fnamemodify(fileNameWithoutLink, ':t')
352 let realFileName = fnamemodify(fileNameWithoutLink, ':t')
353 let oldCwd=<SID>HGChangeToCurrentFileDir(realFileName)
353 let oldCwd=<SID>HGChangeToCurrentFileDir(realFileName)
354 try
354 try
355 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " root "
355 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " root "
356 let roottext=system(hgCommand)
356 let roottext=system(hgCommand)
357 " Suppress ending null char ! Does it work in window ?
357 " Suppress ending null char ! Does it work in window ?
358 let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
358 let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
359 if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
359 if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
360 return ""
360 return ""
361 endif
361 endif
362 let returnExpression = ""
362 let returnExpression = ""
363 if a:repositoryVar != ""
363 if a:repositoryVar != ""
364 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
364 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
365 endif
365 endif
366 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
366 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
367 let statustext=system(hgCommand)
367 let statustext=system(hgCommand)
368 if(v:shell_error)
368 if(v:shell_error)
369 return ""
369 return ""
370 endif
370 endif
371 if match(statustext, '^[?I]') >= 0
371 if match(statustext, '^[?I]') >= 0
372 let revision="NEW"
372 let revision="NEW"
373 elseif match(statustext, '^[R]') >= 0
373 elseif match(statustext, '^[R]') >= 0
374 let revision="REMOVED"
374 let revision="REMOVED"
375 elseif match(statustext, '^[D]') >= 0
375 elseif match(statustext, '^[D]') >= 0
376 let revision="DELETED"
376 let revision="DELETED"
377 elseif match(statustext, '^[A]') >= 0
377 elseif match(statustext, '^[A]') >= 0
378 let revision="ADDED"
378 let revision="ADDED"
379 else
379 else
380 " The file is tracked, we can try to get is revision number
380 " The file is tracked, we can try to get is revision number
381 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " parents "
381 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " parents "
382 let statustext=system(hgCommand)
382 let statustext=system(hgCommand)
383 if(v:shell_error)
383 if(v:shell_error)
384 return ""
384 return ""
385 endif
385 endif
386 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
386 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
387
387
388 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
388 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
389 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
389 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
390 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
390 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
391 endif
391 endif
392 endif
392 endif
393 if (exists('revision'))
393 if (exists('revision'))
394 let returnExpression = "let " . a:revisionVar . "='" . revision . "' " . returnExpression
394 let returnExpression = "let " . a:revisionVar . "='" . revision . "' " . returnExpression
395 endif
395 endif
396
396
397 return returnExpression
397 return returnExpression
398 finally
398 finally
399 execute 'cd' escape(oldCwd, ' ')
399 execute 'cd' escape(oldCwd, ' ')
400 endtry
400 endtry
401 endfunction
401 endfunction
402
402
403 " Function: s:HGSetupBuffer() {{{2
403 " Function: s:HGSetupBuffer() {{{2
404 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
404 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
405
405
406 function! s:HGSetupBuffer(...)
406 function! s:HGSetupBuffer(...)
407 if (exists("b:HGBufferSetup") && b:HGBufferSetup && !exists('a:1'))
407 if (exists("b:HGBufferSetup") && b:HGBufferSetup && !exists('a:1'))
408 " This buffer is already set up.
408 " This buffer is already set up.
409 return
409 return
410 endif
410 endif
411
411
412 if !<SID>HGGetOption("HGCommandEnableBufferSetup", 0)
412 if !<SID>HGGetOption("HGCommandEnableBufferSetup", 0)
413 \ || @% == ""
413 \ || @% == ""
414 \ || s:HGCommandEditFileRunning > 0
414 \ || s:HGCommandEditFileRunning > 0
415 \ || exists("b:HGOrigBuffNR")
415 \ || exists("b:HGOrigBuffNR")
416 unlet! b:HGRevision
416 unlet! b:HGRevision
417 unlet! b:HGBranch
417 unlet! b:HGBranch
418 unlet! b:HGRepository
418 unlet! b:HGRepository
419 return
419 return
420 endif
420 endif
421
421
422 if !filereadable(expand("%"))
422 if !filereadable(expand("%"))
423 return -1
423 return -1
424 endif
424 endif
425
425
426 let revision=""
426 let revision=""
427 let branch=""
427 let branch=""
428 let repository=""
428 let repository=""
429
429
430 exec <SID>HGGetStatusVars('revision', 'branch', 'repository')
430 exec <SID>HGGetStatusVars('revision', 'branch', 'repository')
431 "echomsg "DBG ".revision."#".branch."#".repository
431 "echomsg "DBG ".revision."#".branch."#".repository
432 if revision != ""
432 if revision != ""
433 let b:HGRevision=revision
433 let b:HGRevision=revision
434 else
434 else
435 unlet! b:HGRevision
435 unlet! b:HGRevision
436 endif
436 endif
437 if branch != ""
437 if branch != ""
438 let b:HGBranch=branch
438 let b:HGBranch=branch
439 else
439 else
440 unlet! b:HGBranch
440 unlet! b:HGBranch
441 endif
441 endif
442 if repository != ""
442 if repository != ""
443 let b:HGRepository=repository
443 let b:HGRepository=repository
444 else
444 else
445 unlet! b:HGRepository
445 unlet! b:HGRepository
446 endif
446 endif
447 silent do HGCommand User HGBufferSetup
447 silent do HGCommand User HGBufferSetup
448 let b:HGBufferSetup=1
448 let b:HGBufferSetup=1
449 endfunction
449 endfunction
450
450
451 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
451 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
452 " Resets the buffer setup state of the original buffer for a given HG buffer.
452 " Resets the buffer setup state of the original buffer for a given HG buffer.
453 " Returns: The HG buffer number in a passthrough mode.
453 " Returns: The HG buffer number in a passthrough mode.
454
454
455 function! s:HGMarkOrigBufferForSetup(hgBuffer)
455 function! s:HGMarkOrigBufferForSetup(hgBuffer)
456 checktime
456 checktime
457 if a:hgBuffer != -1
457 if a:hgBuffer != -1
458 let origBuffer = <SID>HGBufferCheck(a:hgBuffer)
458 let origBuffer = <SID>HGBufferCheck(a:hgBuffer)
459 "This should never not work, but I'm paranoid
459 "This should never not work, but I'm paranoid
460 if origBuffer != a:hgBuffer
460 if origBuffer != a:hgBuffer
461 call setbufvar(origBuffer, "HGBufferSetup", 0)
461 call setbufvar(origBuffer, "HGBufferSetup", 0)
462 endif
462 endif
463 else
463 else
464 "We are presumably in the original buffer
464 "We are presumably in the original buffer
465 let b:HGBufferSetup = 0
465 let b:HGBufferSetup = 0
466 "We do the setup now as now event will be triggered allowing it later.
466 "We do the setup now as now event will be triggered allowing it later.
467 call <SID>HGSetupBuffer()
467 call <SID>HGSetupBuffer()
468 endif
468 endif
469 return a:hgBuffer
469 return a:hgBuffer
470 endfunction
470 endfunction
471
471
472 " Function: s:HGOverrideOption(option, [value]) {{{2
472 " Function: s:HGOverrideOption(option, [value]) {{{2
473 " Provides a temporary override for the given HG option. If no value is
473 " Provides a temporary override for the given HG option. If no value is
474 " passed, the override is disabled.
474 " passed, the override is disabled.
475
475
476 function! s:HGOverrideOption(option, ...)
476 function! s:HGOverrideOption(option, ...)
477 if a:0 == 0
477 if a:0 == 0
478 unlet! s:{a:option}Override
478 unlet! s:{a:option}Override
479 else
479 else
480 let s:{a:option}Override = a:1
480 let s:{a:option}Override = a:1
481 endif
481 endif
482 endfunction
482 endfunction
483
483
484 " Function: s:HGWipeoutCommandBuffers() {{{2
484 " Function: s:HGWipeoutCommandBuffers() {{{2
485 " Clears all current HG buffers of the specified type for a given source.
485 " Clears all current HG buffers of the specified type for a given source.
486
486
487 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
487 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
488 let buffer = 1
488 let buffer = 1
489 while buffer <= bufnr('$')
489 while buffer <= bufnr('$')
490 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
490 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
491 if getbufvar(buffer, 'HGCommand') == a:hgCommand
491 if getbufvar(buffer, 'HGCommand') == a:hgCommand
492 execute 'bw' buffer
492 execute 'bw' buffer
493 endif
493 endif
494 endif
494 endif
495 let buffer = buffer + 1
495 let buffer = buffer + 1
496 endwhile
496 endwhile
497 endfunction
497 endfunction
498
498
499 " Function: s:HGInstallDocumentation(full_name, revision) {{{2
499 " Function: s:HGInstallDocumentation(full_name, revision) {{{2
500 " Install help documentation.
500 " Install help documentation.
501 " Arguments:
501 " Arguments:
502 " full_name: Full name of this vim plugin script, including path name.
502 " full_name: Full name of this vim plugin script, including path name.
503 " revision: Revision of the vim script. #version# mark in the document file
503 " revision: Revision of the vim script. #version# mark in the document file
504 " will be replaced with this string with 'v' prefix.
504 " will be replaced with this string with 'v' prefix.
505 " Return:
505 " Return:
506 " 1 if new document installed, 0 otherwise.
506 " 1 if new document installed, 0 otherwise.
507 " Note: Cleaned and generalized by guo-peng Wen
507 " Note: Cleaned and generalized by guo-peng Wen
508 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
508 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
509 " Helper function to make mkdir as portable as possible
509 " Helper function to make mkdir as portable as possible
510 function! s:HGFlexiMkdir(dir)
510 function! s:HGFlexiMkdir(dir)
511 if exists("*mkdir") " we can use Vim's own mkdir()
511 if exists("*mkdir") " we can use Vim's own mkdir()
512 call mkdir(a:dir)
512 call mkdir(a:dir)
513 elseif !exists("+shellslash")
513 elseif !exists("+shellslash")
514 call system("mkdir -p '".a:dir."'")
514 call system("mkdir -p '".a:dir."'")
515 else " M$
515 else " M$
516 let l:ssl = &shellslash
516 let l:ssl = &shellslash
517 try
517 try
518 set shellslash
518 set shellslash
519 " no single quotes?
519 " no single quotes?
520 call system('mkdir "'.a:dir.'"')
520 call system('mkdir "'.a:dir.'"')
521 finally
521 finally
522 let &shellslash = l:ssl
522 let &shellslash = l:ssl
523 endtry
523 endtry
524 endif
524 endif
525 endfunction
525 endfunction
526
526
527 function! s:HGInstallDocumentation(full_name)
527 function! s:HGInstallDocumentation(full_name)
528 " Figure out document path based on full name of this script:
528 " Figure out document path based on full name of this script:
529 let l:vim_doc_path = fnamemodify(a:full_name, ":h:h") . "/doc"
529 let l:vim_doc_path = fnamemodify(a:full_name, ":h:h") . "/doc"
530 if filewritable(l:vim_doc_path) != 2
530 if filewritable(l:vim_doc_path) != 2
531 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
531 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
532 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
532 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
533 if filewritable(l:vim_doc_path) != 2
533 if filewritable(l:vim_doc_path) != 2
534 " Try first item in 'runtimepath':
534 " Try first item in 'runtimepath':
535 let l:vim_doc_path =
535 let l:vim_doc_path =
536 \ substitute(&runtimepath, '^\([^,]*\).*', '\1/doc', 'e')
536 \ substitute(&runtimepath, '^\([^,]*\).*', '\1/doc', 'e')
537 if filewritable(l:vim_doc_path) != 2
537 if filewritable(l:vim_doc_path) != 2
538 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
538 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
539 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
539 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
540 if filewritable(l:vim_doc_path) != 2
540 if filewritable(l:vim_doc_path) != 2
541 " Put a warning:
541 " Put a warning:
542 echomsg "Unable to open documentation directory"
542 echomsg "Unable to open documentation directory"
543 echomsg " type `:help add-local-help' for more information."
543 echomsg " type `:help add-local-help' for more information."
544 return 0
544 return 0
545 endif
545 endif
546 endif
546 endif
547 endif
547 endif
548 endif
548 endif
549
549
550 " Full name of documentation file:
550 " Full name of documentation file:
551 let l:doc_file =
551 let l:doc_file =
552 \ l:vim_doc_path . "/" . s:script_name . ".txt"
552 \ l:vim_doc_path . "/" . s:script_name . ".txt"
553 " Bail out if document file is still up to date:
553 " Bail out if document file is still up to date:
554 if filereadable(l:doc_file) &&
554 if filereadable(l:doc_file) &&
555 \ getftime(a:full_name) < getftime(l:doc_file)
555 \ getftime(a:full_name) < getftime(l:doc_file)
556 return 0
556 return 0
557 endif
557 endif
558
558
559 " temporary global settings
559 " temporary global settings
560 let l:lz = &lazyredraw
560 let l:lz = &lazyredraw
561 let l:hls = &hlsearch
561 let l:hls = &hlsearch
562 set lazyredraw nohlsearch
562 set lazyredraw nohlsearch
563 " Create a new buffer & read in the plugin file (me):
563 " Create a new buffer & read in the plugin file (me):
564 1 new
564 1 new
565 setlocal noswapfile modifiable nomodeline
565 setlocal noswapfile modifiable nomodeline
566 if has("folding")
566 if has("folding")
567 setlocal nofoldenable
567 setlocal nofoldenable
568 endif
568 endif
569 silent execute "read" escape(a:full_name, " ")
569 silent execute "read" escape(a:full_name, " ")
570 let l:doc_buf = bufnr("%")
570 let l:doc_buf = bufnr("%")
571
571
572 1
572 1
573 " Delete from first line to a line starts with
573 " Delete from first line to a line starts with
574 " === START_DOC
574 " === START_DOC
575 silent 1,/^=\{3,}\s\+START_DOC\C/ delete _
575 silent 1,/^=\{3,}\s\+START_DOC\C/ delete _
576 " Delete from a line starts with
576 " Delete from a line starts with
577 " === END_DOC
577 " === END_DOC
578 " to the end of the documents:
578 " to the end of the documents:
579 silent /^=\{3,}\s\+END_DOC\C/,$ delete _
579 silent /^=\{3,}\s\+END_DOC\C/,$ delete _
580
580
581 " Add modeline for help doc: the modeline string is mangled intentionally
581 " Add modeline for help doc: the modeline string is mangled intentionally
582 " to avoid it be recognized by VIM:
582 " to avoid it be recognized by VIM:
583 call append(line("$"), "")
583 call append(line("$"), "")
584 call append(line("$"), " v" . "im:tw=78:ts=8:ft=help:norl:")
584 call append(line("$"), " v" . "im:tw=78:ts=8:ft=help:norl:")
585
585
586 " Replace revision:
586 " Replace revision:
587 silent execute "normal :1s/#version#/" . s:script_version . "/\<CR>"
587 silent execute "normal :1s/#version#/" . s:script_version . "/\<CR>"
588 " Save the help document and wipe out buffer:
588 " Save the help document and wipe out buffer:
589 silent execute "wq!" escape(l:doc_file, " ") "| bw" l:doc_buf
589 silent execute "wq!" escape(l:doc_file, " ") "| bw" l:doc_buf
590 " Build help tags:
590 " Build help tags:
591 silent execute "helptags" l:vim_doc_path
591 silent execute "helptags" l:vim_doc_path
592
592
593 let &hlsearch = l:hls
593 let &hlsearch = l:hls
594 let &lazyredraw = l:lz
594 let &lazyredraw = l:lz
595 return 1
595 return 1
596 endfunction
596 endfunction
597
597
598 " Section: Public functions {{{1
598 " Section: Public functions {{{1
599
599
600 " Function: HGGetRevision() {{{2
600 " Function: HGGetRevision() {{{2
601 " Global function for retrieving the current buffer's HG revision number.
601 " Global function for retrieving the current buffer's HG revision number.
602 " Returns: Revision number or an empty string if an error occurs.
602 " Returns: Revision number or an empty string if an error occurs.
603
603
604 function! HGGetRevision()
604 function! HGGetRevision()
605 let revision=""
605 let revision=""
606 exec <SID>HGGetStatusVars('revision', '', '')
606 exec <SID>HGGetStatusVars('revision', '', '')
607 return revision
607 return revision
608 endfunction
608 endfunction
609
609
610 " Function: HGDisableBufferSetup() {{{2
610 " Function: HGDisableBufferSetup() {{{2
611 " Global function for deactivating the buffer autovariables.
611 " Global function for deactivating the buffer autovariables.
612
612
613 function! HGDisableBufferSetup()
613 function! HGDisableBufferSetup()
614 let g:HGCommandEnableBufferSetup=0
614 let g:HGCommandEnableBufferSetup=0
615 silent! augroup! HGCommandPlugin
615 silent! augroup! HGCommandPlugin
616 endfunction
616 endfunction
617
617
618 " Function: HGEnableBufferSetup() {{{2
618 " Function: HGEnableBufferSetup() {{{2
619 " Global function for activating the buffer autovariables.
619 " Global function for activating the buffer autovariables.
620
620
621 function! HGEnableBufferSetup()
621 function! HGEnableBufferSetup()
622 let g:HGCommandEnableBufferSetup=1
622 let g:HGCommandEnableBufferSetup=1
623 augroup HGCommandPlugin
623 augroup HGCommandPlugin
624 au!
624 au!
625 au BufEnter * call <SID>HGSetupBuffer()
625 au BufEnter * call <SID>HGSetupBuffer()
626 au BufWritePost * call <SID>HGSetupBuffer()
626 au BufWritePost * call <SID>HGSetupBuffer()
627 " Force resetting up buffer on external file change (HG update)
627 " Force resetting up buffer on external file change (HG update)
628 au FileChangedShell * call <SID>HGSetupBuffer(1)
628 au FileChangedShell * call <SID>HGSetupBuffer(1)
629 augroup END
629 augroup END
630
630
631 " Only auto-load if the plugin is fully loaded. This gives other plugins a
631 " Only auto-load if the plugin is fully loaded. This gives other plugins a
632 " chance to run.
632 " chance to run.
633 if g:loaded_hgcommand == 2
633 if g:loaded_hgcommand == 2
634 call <SID>HGSetupBuffer()
634 call <SID>HGSetupBuffer()
635 endif
635 endif
636 endfunction
636 endfunction
637
637
638 " Function: HGGetStatusLine() {{{2
638 " Function: HGGetStatusLine() {{{2
639 " Default (sample) status line entry for HG files. This is only useful if
639 " Default (sample) status line entry for HG files. This is only useful if
640 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
640 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
641 " for how to do this).
641 " for how to do this).
642
642
643 function! HGGetStatusLine()
643 function! HGGetStatusLine()
644 if exists('b:HGSourceFile')
644 if exists('b:HGSourceFile')
645 " This is a result buffer
645 " This is a result buffer
646 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
646 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
647 if exists('b:HGStatusText')
647 if exists('b:HGStatusText')
648 let value=value . ' ' . b:HGStatusText
648 let value=value . ' ' . b:HGStatusText
649 endif
649 endif
650 let value = value . ']'
650 let value = value . ']'
651 return value
651 return value
652 endif
652 endif
653
653
654 if exists('b:HGRevision')
654 if exists('b:HGRevision')
655 \ && b:HGRevision != ''
655 \ && b:HGRevision != ''
656 \ && exists('b:HGRepository')
656 \ && exists('b:HGRepository')
657 \ && b:HGRepository != ''
657 \ && b:HGRepository != ''
658 \ && exists('g:HGCommandEnableBufferSetup')
658 \ && exists('g:HGCommandEnableBufferSetup')
659 \ && g:HGCommandEnableBufferSetup
659 \ && g:HGCommandEnableBufferSetup
660 if !exists('b:HGBranch')
660 if !exists('b:HGBranch')
661 let l:branch=''
661 let l:branch=''
662 else
662 else
663 let l:branch=b:HGBranch
663 let l:branch=b:HGBranch
664 endif
664 endif
665 return '[HG ' . b:HGRepository . '/' . l:branch .'/' . b:HGRevision . ']'
665 return '[HG ' . b:HGRepository . '/' . l:branch .'/' . b:HGRevision . ']'
666 else
666 else
667 return ''
667 return ''
668 endif
668 endif
669 endfunction
669 endfunction
670
670
671 " Section: HG command functions {{{1
671 " Section: HG command functions {{{1
672
672
673 " Function: s:HGAdd() {{{2
673 " Function: s:HGAdd() {{{2
674 function! s:HGAdd()
674 function! s:HGAdd()
675 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('add', 'hgadd', ''))
675 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('add', 'hgadd', ''))
676 endfunction
676 endfunction
677
677
678 " Function: s:HGAnnotate(...) {{{2
678 " Function: s:HGAnnotate(...) {{{2
679 function! s:HGAnnotate(...)
679 function! s:HGAnnotate(...)
680 if a:0 == 0
680 if a:0 == 0
681 if &filetype == "HGAnnotate"
681 if &filetype == "HGAnnotate"
682 " This is a HGAnnotate buffer. Perform annotation of the version
682 " This is a HGAnnotate buffer. Perform annotation of the version
683 " indicated by the current line.
683 " indicated by the current line.
684 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
684 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
685 if <SID>HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
685 if <SID>HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
686 let revision = revision - 1
686 let revision = revision - 1
687 endif
687 endif
688 else
688 else
689 let revision=HGGetRevision()
689 let revision=HGGetRevision()
690 if revision == ""
690 if revision == ""
691 echoerr "Unable to obtain HG version information."
691 echoerr "Unable to obtain HG version information."
692 return -1
692 return -1
693 endif
693 endif
694 endif
694 endif
695 else
695 else
696 let revision=a:1
696 let revision=a:1
697 endif
697 endif
698
698
699 if revision == "NEW"
699 if revision == "NEW"
700 echo "No annotatation available for new file."
700 echo "No annotatation available for new file."
701 return -1
701 return -1
702 endif
702 endif
703
703
704 let resultBuffer=<SID>HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
704 let resultBuffer=<SID>HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
705 "echomsg "DBG: ".resultBuffer
705 "echomsg "DBG: ".resultBuffer
706 if resultBuffer != -1
706 if resultBuffer != -1
707 set filetype=HGAnnotate
707 set filetype=HGAnnotate
708 endif
708 endif
709
709
710 return resultBuffer
710 return resultBuffer
711 endfunction
711 endfunction
712
712
713 " Function: s:HGCommit() {{{2
713 " Function: s:HGCommit() {{{2
714 function! s:HGCommit(...)
714 function! s:HGCommit(...)
715 " Handle the commit message being specified. If a message is supplied, it
715 " Handle the commit message being specified. If a message is supplied, it
716 " is used; if bang is supplied, an empty message is used; otherwise, the
716 " is used; if bang is supplied, an empty message is used; otherwise, the
717 " user is provided a buffer from which to edit the commit message.
717 " user is provided a buffer from which to edit the commit message.
718 if a:2 != "" || a:1 == "!"
718 if a:2 != "" || a:1 == "!"
719 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
719 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
720 endif
720 endif
721
721
722 let hgBufferCheck=<SID>HGCurrentBufferCheck()
722 let hgBufferCheck=<SID>HGCurrentBufferCheck()
723 if hgBufferCheck == -1
723 if hgBufferCheck == -1
724 echo "Original buffer no longer exists, aborting."
724 echo "Original buffer no longer exists, aborting."
725 return -1
725 return -1
726 endif
726 endif
727
727
728 " Protect against windows' backslashes in paths. They confuse exec'd
728 " Protect against windows' backslashes in paths. They confuse exec'd
729 " commands.
729 " commands.
730
730
731 let shellSlashBak = &shellslash
731 let shellSlashBak = &shellslash
732 try
732 try
733 set shellslash
733 set shellslash
734
734
735 let messageFileName = tempname()
735 let messageFileName = tempname()
736
736
737 let fileName=bufname(hgBufferCheck)
737 let fileName=bufname(hgBufferCheck)
738 let realFilePath=<SID>HGResolveLink(fileName)
738 let realFilePath=<SID>HGResolveLink(fileName)
739 let newCwd=fnamemodify(realFilePath, ':h')
739 let newCwd=fnamemodify(realFilePath, ':h')
740 if strlen(newCwd) == 0
740 if strlen(newCwd) == 0
741 " Account for autochdir being in effect, which will make this blank, but
741 " Account for autochdir being in effect, which will make this blank, but
742 " we know we'll be in the current directory for the original file.
742 " we know we'll be in the current directory for the original file.
743 let newCwd = getcwd()
743 let newCwd = getcwd()
744 endif
744 endif
745
745
746 let realFileName=fnamemodify(realFilePath, ':t')
746 let realFileName=fnamemodify(realFilePath, ':t')
747
747
748 if <SID>HGEditFile(messageFileName, hgBufferCheck) == -1
748 if <SID>HGEditFile(messageFileName, hgBufferCheck) == -1
749 return
749 return
750 endif
750 endif
751
751
752 " Protect against case and backslash issues in Windows.
752 " Protect against case and backslash issues in Windows.
753 let autoPattern = '\c' . messageFileName
753 let autoPattern = '\c' . messageFileName
754
754
755 " Ensure existence of group
755 " Ensure existence of group
756 augroup HGCommit
756 augroup HGCommit
757 augroup END
757 augroup END
758
758
759 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
759 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
760 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
760 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
761
761
762 " Create a commit mapping. The mapping must clear all autocommands in case
762 " Create a commit mapping. The mapping must clear all autocommands in case
763 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
763 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
764 " invoke the buffer deletion autocommand.
764 " invoke the buffer deletion autocommand.
765
765
766 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
766 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
767 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
767 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
768 \ ':g/^HG:/d<CR>'.
768 \ ':g/^HG:/d<CR>'.
769 \ ':update<CR>'.
769 \ ':update<CR>'.
770 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
770 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
771 \ '"' . newCwd . '",' .
771 \ '"' . newCwd . '",' .
772 \ '"' . realFileName . '",' .
772 \ '"' . realFileName . '",' .
773 \ hgBufferCheck . ')<CR>'
773 \ hgBufferCheck . ')<CR>'
774
774
775 silent 0put ='HG: ----------------------------------------------------------------------'
775 silent 0put ='HG: ----------------------------------------------------------------------'
776 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
776 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
777 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
777 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
778
778
779 if <SID>HGGetOption('HGCommandCommitOnWrite', 1) == 1
779 if <SID>HGGetOption('HGCommandCommitOnWrite', 1) == 1
780 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
780 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
781 execute 'au HGCommit BufWritePost' autoPattern 'call <SID>HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
781 execute 'au HGCommit BufWritePost' autoPattern 'call <SID>HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
782 silent put ='HG: or write this buffer'
782 silent put ='HG: or write this buffer'
783 endif
783 endif
784
784
785 silent put ='HG: to finish this commit operation'
785 silent put ='HG: to finish this commit operation'
786 silent put ='HG: ----------------------------------------------------------------------'
786 silent put ='HG: ----------------------------------------------------------------------'
787 $
787 $
788 let b:HGSourceFile=fileName
788 let b:HGSourceFile=fileName
789 let b:HGCommand='HGCommit'
789 let b:HGCommand='HGCommit'
790 set filetype=hg
790 set filetype=hg
791 finally
791 finally
792 let &shellslash = shellSlashBak
792 let &shellslash = shellSlashBak
793 endtry
793 endtry
794
794
795 endfunction
795 endfunction
796
796
797 " Function: s:HGDiff(...) {{{2
797 " Function: s:HGDiff(...) {{{2
798 function! s:HGDiff(...)
798 function! s:HGDiff(...)
799 if a:0 == 1
799 if a:0 == 1
800 let revOptions = '-r' . a:1
800 let revOptions = '-r' . a:1
801 let caption = a:1 . ' -> current'
801 let caption = a:1 . ' -> current'
802 elseif a:0 == 2
802 elseif a:0 == 2
803 let revOptions = '-r' . a:1 . ' -r' . a:2
803 let revOptions = '-r' . a:1 . ' -r' . a:2
804 let caption = a:1 . ' -> ' . a:2
804 let caption = a:1 . ' -> ' . a:2
805 else
805 else
806 let revOptions = ''
806 let revOptions = ''
807 let caption = ''
807 let caption = ''
808 endif
808 endif
809
809
810 let hgdiffopt=<SID>HGGetOption('HGCommandDiffOpt', 'w')
810 let hgdiffopt=<SID>HGGetOption('HGCommandDiffOpt', 'w')
811
811
812 if hgdiffopt == ""
812 if hgdiffopt == ""
813 let diffoptionstring=""
813 let diffoptionstring=""
814 else
814 else
815 let diffoptionstring=" -" . hgdiffopt . " "
815 let diffoptionstring=" -" . hgdiffopt . " "
816 endif
816 endif
817
817
818 let resultBuffer = <SID>HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
818 let resultBuffer = <SID>HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
819 if resultBuffer != -1
819 if resultBuffer != -1
820 set filetype=diff
820 set filetype=diff
821 endif
821 endif
822 return resultBuffer
822 return resultBuffer
823 endfunction
823 endfunction
824
824
825
825
826 " Function: s:HGGotoOriginal(["!]) {{{2
826 " Function: s:HGGotoOriginal(["!]) {{{2
827 function! s:HGGotoOriginal(...)
827 function! s:HGGotoOriginal(...)
828 let origBuffNR = <SID>HGCurrentBufferCheck()
828 let origBuffNR = <SID>HGCurrentBufferCheck()
829 if origBuffNR > 0
829 if origBuffNR > 0
830 let origWinNR = bufwinnr(origBuffNR)
830 let origWinNR = bufwinnr(origBuffNR)
831 if origWinNR == -1
831 if origWinNR == -1
832 execute 'buffer' origBuffNR
832 execute 'buffer' origBuffNR
833 else
833 else
834 execute origWinNR . 'wincmd w'
834 execute origWinNR . 'wincmd w'
835 endif
835 endif
836 if a:0 == 1
836 if a:0 == 1
837 if a:1 == "!"
837 if a:1 == "!"
838 let buffnr = 1
838 let buffnr = 1
839 let buffmaxnr = bufnr("$")
839 let buffmaxnr = bufnr("$")
840 while buffnr <= buffmaxnr
840 while buffnr <= buffmaxnr
841 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
841 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
842 execute "bw" buffnr
842 execute "bw" buffnr
843 endif
843 endif
844 let buffnr = buffnr + 1
844 let buffnr = buffnr + 1
845 endwhile
845 endwhile
846 endif
846 endif
847 endif
847 endif
848 endif
848 endif
849 endfunction
849 endfunction
850
850
851 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
851 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
852 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
852 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
853 if filereadable(a:messageFile)
853 if filereadable(a:messageFile)
854 let oldCwd=getcwd()
854 let oldCwd=getcwd()
855 if strlen(a:targetDir) > 0
855 if strlen(a:targetDir) > 0
856 execute 'cd' escape(a:targetDir, ' ')
856 execute 'cd' escape(a:targetDir, ' ')
857 endif
857 endif
858 let resultBuffer=<SID>HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
858 let resultBuffer=<SID>HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
859 execute 'cd' escape(oldCwd, ' ')
859 execute 'cd' escape(oldCwd, ' ')
860 execute 'bw' escape(a:messageFile, ' *?\')
860 execute 'bw' escape(a:messageFile, ' *?\')
861 silent execute 'call delete("' . a:messageFile . '")'
861 silent execute 'call delete("' . a:messageFile . '")'
862 return <SID>HGMarkOrigBufferForSetup(resultBuffer)
862 return <SID>HGMarkOrigBufferForSetup(resultBuffer)
863 else
863 else
864 echoerr "Can't read message file; no commit is possible."
864 echoerr "Can't read message file; no commit is possible."
865 return -1
865 return -1
866 endif
866 endif
867 endfunction
867 endfunction
868
868
869 " Function: s:HGLog() {{{2
869 " Function: s:HGLog() {{{2
870 function! s:HGLog(...)
870 function! s:HGLog(...)
871 if a:0 == 0
871 if a:0 == 0
872 let versionOption = ""
872 let versionOption = ""
873 let caption = ''
873 let caption = ''
874 else
874 else
875 let versionOption=" -r" . a:1
875 let versionOption=" -r" . a:1
876 let caption = a:1
876 let caption = a:1
877 endif
877 endif
878
878
879 let resultBuffer=<SID>HGDoCommand('log' . versionOption, 'hglog', caption)
879 let resultBuffer=<SID>HGDoCommand('log' . versionOption, 'hglog', caption)
880 if resultBuffer != ""
880 if resultBuffer != ""
881 set filetype=rcslog
881 set filetype=rcslog
882 endif
882 endif
883 return resultBuffer
883 return resultBuffer
884 endfunction
884 endfunction
885
885
886 " Function: s:HGRevert() {{{2
886 " Function: s:HGRevert() {{{2
887 function! s:HGRevert()
887 function! s:HGRevert()
888 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('revert', 'hgrevert', ''))
888 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('revert', 'hgrevert', ''))
889 endfunction
889 endfunction
890
890
891 " Function: s:HGReview(...) {{{2
891 " Function: s:HGReview(...) {{{2
892 function! s:HGReview(...)
892 function! s:HGReview(...)
893 if a:0 == 0
893 if a:0 == 0
894 let versiontag=""
894 let versiontag=""
895 if <SID>HGGetOption('HGCommandInteractive', 0)
895 if <SID>HGGetOption('HGCommandInteractive', 0)
896 let versiontag=input('Revision: ')
896 let versiontag=input('Revision: ')
897 endif
897 endif
898 if versiontag == ""
898 if versiontag == ""
899 let versiontag="(current)"
899 let versiontag="(current)"
900 let versionOption=""
900 let versionOption=""
901 else
901 else
902 let versionOption=" -r " . versiontag . " "
902 let versionOption=" -r " . versiontag . " "
903 endif
903 endif
904 else
904 else
905 let versiontag=a:1
905 let versiontag=a:1
906 let versionOption=" -r " . versiontag . " "
906 let versionOption=" -r " . versiontag . " "
907 endif
907 endif
908
908
909 let resultBuffer = <SID>HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
909 let resultBuffer = <SID>HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
910 if resultBuffer > 0
910 if resultBuffer > 0
911 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
911 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
912 endif
912 endif
913
913
914 return resultBuffer
914 return resultBuffer
915 endfunction
915 endfunction
916
916
917 " Function: s:HGStatus() {{{2
917 " Function: s:HGStatus() {{{2
918 function! s:HGStatus()
918 function! s:HGStatus()
919 return <SID>HGDoCommand('status', 'hgstatus', '')
919 return <SID>HGDoCommand('status', 'hgstatus', '')
920 endfunction
920 endfunction
921
921
922
922
923 " Function: s:HGUpdate() {{{2
923 " Function: s:HGUpdate() {{{2
924 function! s:HGUpdate()
924 function! s:HGUpdate()
925 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('update', 'update', ''))
925 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('update', 'update', ''))
926 endfunction
926 endfunction
927
927
928 " Function: s:HGVimDiff(...) {{{2
928 " Function: s:HGVimDiff(...) {{{2
929 function! s:HGVimDiff(...)
929 function! s:HGVimDiff(...)
930 let originalBuffer = <SID>HGCurrentBufferCheck()
930 let originalBuffer = <SID>HGCurrentBufferCheck()
931 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
931 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
932 try
932 try
933 " If there's already a VimDiff'ed window, restore it.
933 " If there's already a VimDiff'ed window, restore it.
934 " There may only be one HGVimDiff original window at a time.
934 " There may only be one HGVimDiff original window at a time.
935
935
936 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
936 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
937 " Clear the existing vimdiff setup by removing the result buffers.
937 " Clear the existing vimdiff setup by removing the result buffers.
938 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
938 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
939 endif
939 endif
940
940
941 " Split and diff
941 " Split and diff
942 if(a:0 == 2)
942 if(a:0 == 2)
943 " Reset the vimdiff system, as 2 explicit versions were provided.
943 " Reset the vimdiff system, as 2 explicit versions were provided.
944 if exists('s:vimDiffSourceBuffer')
944 if exists('s:vimDiffSourceBuffer')
945 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
945 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
946 endif
946 endif
947 let resultBuffer = <SID>HGReview(a:1)
947 let resultBuffer = <SID>HGReview(a:1)
948 if resultBuffer < 0
948 if resultBuffer < 0
949 echomsg "Can't open HG revision " . a:1
949 echomsg "Can't open HG revision " . a:1
950 return resultBuffer
950 return resultBuffer
951 endif
951 endif
952 let b:HGCommand = 'vimdiff'
952 let b:HGCommand = 'vimdiff'
953 diffthis
953 diffthis
954 let s:vimDiffBufferCount = 1
954 let s:vimDiffBufferCount = 1
955 let s:vimDiffScratchList = '{'. resultBuffer . '}'
955 let s:vimDiffScratchList = '{'. resultBuffer . '}'
956 " If no split method is defined, cheat, and set it to vertical.
956 " If no split method is defined, cheat, and set it to vertical.
957 try
957 try
958 call <SID>HGOverrideOption('HGCommandSplit', <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
958 call <SID>HGOverrideOption('HGCommandSplit', <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
959 let resultBuffer=<SID>HGReview(a:2)
959 let resultBuffer=<SID>HGReview(a:2)
960 finally
960 finally
961 call <SID>HGOverrideOption('HGCommandSplit')
961 call <SID>HGOverrideOption('HGCommandSplit')
962 endtry
962 endtry
963 if resultBuffer < 0
963 if resultBuffer < 0
964 echomsg "Can't open HG revision " . a:1
964 echomsg "Can't open HG revision " . a:1
965 return resultBuffer
965 return resultBuffer
966 endif
966 endif
967 let b:HGCommand = 'vimdiff'
967 let b:HGCommand = 'vimdiff'
968 diffthis
968 diffthis
969 let s:vimDiffBufferCount = 2
969 let s:vimDiffBufferCount = 2
970 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
970 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
971 else
971 else
972 " Add new buffer
972 " Add new buffer
973 try
973 try
974 " Force splitting behavior, otherwise why use vimdiff?
974 " Force splitting behavior, otherwise why use vimdiff?
975 call <SID>HGOverrideOption("HGCommandEdit", "split")
975 call <SID>HGOverrideOption("HGCommandEdit", "split")
976 call <SID>HGOverrideOption("HGCommandSplit", <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
976 call <SID>HGOverrideOption("HGCommandSplit", <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
977 if(a:0 == 0)
977 if(a:0 == 0)
978 let resultBuffer=<SID>HGReview()
978 let resultBuffer=<SID>HGReview()
979 else
979 else
980 let resultBuffer=<SID>HGReview(a:1)
980 let resultBuffer=<SID>HGReview(a:1)
981 endif
981 endif
982 finally
982 finally
983 call <SID>HGOverrideOption("HGCommandEdit")
983 call <SID>HGOverrideOption("HGCommandEdit")
984 call <SID>HGOverrideOption("HGCommandSplit")
984 call <SID>HGOverrideOption("HGCommandSplit")
985 endtry
985 endtry
986 if resultBuffer < 0
986 if resultBuffer < 0
987 echomsg "Can't open current HG revision"
987 echomsg "Can't open current HG revision"
988 return resultBuffer
988 return resultBuffer
989 endif
989 endif
990 let b:HGCommand = 'vimdiff'
990 let b:HGCommand = 'vimdiff'
991 diffthis
991 diffthis
992
992
993 if !exists('s:vimDiffBufferCount')
993 if !exists('s:vimDiffBufferCount')
994 " New instance of vimdiff.
994 " New instance of vimdiff.
995 let s:vimDiffBufferCount = 2
995 let s:vimDiffBufferCount = 2
996 let s:vimDiffScratchList = '{' . resultBuffer . '}'
996 let s:vimDiffScratchList = '{' . resultBuffer . '}'
997
997
998 " This could have been invoked on a HG result buffer, not the
998 " This could have been invoked on a HG result buffer, not the
999 " original buffer.
999 " original buffer.
1000 wincmd W
1000 wincmd W
1001 execute 'buffer' originalBuffer
1001 execute 'buffer' originalBuffer
1002 " Store info for later original buffer restore
1002 " Store info for later original buffer restore
1003 let s:vimDiffRestoreCmd =
1003 let s:vimDiffRestoreCmd =
1004 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
1004 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
1005 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
1005 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
1006 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
1006 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
1007 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
1007 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
1008 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
1008 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
1009 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
1009 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
1010 \ . "|if &foldmethod=='manual'|execute 'normal! zE'|endif"
1010 \ . "|if &foldmethod=='manual'|execute 'normal! zE'|endif"
1011 diffthis
1011 diffthis
1012 wincmd w
1012 wincmd w
1013 else
1013 else
1014 " Adding a window to an existing vimdiff
1014 " Adding a window to an existing vimdiff
1015 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
1015 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
1016 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
1016 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
1017 endif
1017 endif
1018 endif
1018 endif
1019
1019
1020 let s:vimDiffSourceBuffer = originalBuffer
1020 let s:vimDiffSourceBuffer = originalBuffer
1021
1021
1022 " Avoid executing the modeline in the current buffer after the autocommand.
1022 " Avoid executing the modeline in the current buffer after the autocommand.
1023
1023
1024 let currentBuffer = bufnr('%')
1024 let currentBuffer = bufnr('%')
1025 let saveModeline = getbufvar(currentBuffer, '&modeline')
1025 let saveModeline = getbufvar(currentBuffer, '&modeline')
1026 try
1026 try
1027 call setbufvar(currentBuffer, '&modeline', 0)
1027 call setbufvar(currentBuffer, '&modeline', 0)
1028 silent do HGCommand User HGVimDiffFinish
1028 silent do HGCommand User HGVimDiffFinish
1029 finally
1029 finally
1030 call setbufvar(currentBuffer, '&modeline', saveModeline)
1030 call setbufvar(currentBuffer, '&modeline', saveModeline)
1031 endtry
1031 endtry
1032 return resultBuffer
1032 return resultBuffer
1033 finally
1033 finally
1034 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1034 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1035 endtry
1035 endtry
1036 endfunction
1036 endfunction
1037
1037
1038 " Section: Command definitions {{{1
1038 " Section: Command definitions {{{1
1039 " Section: Primary commands {{{2
1039 " Section: Primary commands {{{2
1040 com! HGAdd call <SID>HGAdd()
1040 com! HGAdd call <SID>HGAdd()
1041 com! -nargs=? HGAnnotate call <SID>HGAnnotate(<f-args>)
1041 com! -nargs=? HGAnnotate call <SID>HGAnnotate(<f-args>)
1042 com! -bang -nargs=? HGCommit call <SID>HGCommit(<q-bang>, <q-args>)
1042 com! -bang -nargs=? HGCommit call <SID>HGCommit(<q-bang>, <q-args>)
1043 com! -nargs=* HGDiff call <SID>HGDiff(<f-args>)
1043 com! -nargs=* HGDiff call <SID>HGDiff(<f-args>)
1044 com! -bang HGGotoOriginal call <SID>HGGotoOriginal(<q-bang>)
1044 com! -bang HGGotoOriginal call <SID>HGGotoOriginal(<q-bang>)
1045 com! -nargs=? HGLog call <SID>HGLog(<f-args>)
1045 com! -nargs=? HGLog call <SID>HGLog(<f-args>)
1046 com! HGRevert call <SID>HGRevert()
1046 com! HGRevert call <SID>HGRevert()
1047 com! -nargs=? HGReview call <SID>HGReview(<f-args>)
1047 com! -nargs=? HGReview call <SID>HGReview(<f-args>)
1048 com! HGStatus call <SID>HGStatus()
1048 com! HGStatus call <SID>HGStatus()
1049 com! HGUpdate call <SID>HGUpdate()
1049 com! HGUpdate call <SID>HGUpdate()
1050 com! -nargs=* HGVimDiff call <SID>HGVimDiff(<f-args>)
1050 com! -nargs=* HGVimDiff call <SID>HGVimDiff(<f-args>)
1051
1051
1052 " Section: HG buffer management commands {{{2
1052 " Section: HG buffer management commands {{{2
1053 com! HGDisableBufferSetup call HGDisableBufferSetup()
1053 com! HGDisableBufferSetup call HGDisableBufferSetup()
1054 com! HGEnableBufferSetup call HGEnableBufferSetup()
1054 com! HGEnableBufferSetup call HGEnableBufferSetup()
1055
1055
1056 " Allow reloading hgcommand.vim
1056 " Allow reloading hgcommand.vim
1057 com! HGReload unlet! g:loaded_hgcommand | runtime plugin/hgcommand.vim
1057 com! HGReload unlet! g:loaded_hgcommand | runtime plugin/hgcommand.vim
1058
1058
1059 " Section: Plugin command mappings {{{1
1059 " Section: Plugin command mappings {{{1
1060 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
1060 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
1061 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
1061 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
1062 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
1062 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
1063 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
1063 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
1064 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
1064 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
1065 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
1065 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
1066 nnoremap <silent> <Plug>HGLog :HGLog<CR>
1066 nnoremap <silent> <Plug>HGLog :HGLog<CR>
1067 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
1067 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
1068 nnoremap <silent> <Plug>HGReview :HGReview<CR>
1068 nnoremap <silent> <Plug>HGReview :HGReview<CR>
1069 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
1069 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
1070 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
1070 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
1071 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
1071 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
1072
1072
1073 " Section: Default mappings {{{1
1073 " Section: Default mappings {{{1
1074 if !hasmapto('<Plug>HGAdd')
1074 if !hasmapto('<Plug>HGAdd')
1075 nmap <unique> <Leader>hga <Plug>HGAdd
1075 nmap <unique> <Leader>hga <Plug>HGAdd
1076 endif
1076 endif
1077 if !hasmapto('<Plug>HGAnnotate')
1077 if !hasmapto('<Plug>HGAnnotate')
1078 nmap <unique> <Leader>hgn <Plug>HGAnnotate
1078 nmap <unique> <Leader>hgn <Plug>HGAnnotate
1079 endif
1079 endif
1080 if !hasmapto('<Plug>HGClearAndGotoOriginal')
1080 if !hasmapto('<Plug>HGClearAndGotoOriginal')
1081 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
1081 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
1082 endif
1082 endif
1083 if !hasmapto('<Plug>HGCommit')
1083 if !hasmapto('<Plug>HGCommit')
1084 nmap <unique> <Leader>hgc <Plug>HGCommit
1084 nmap <unique> <Leader>hgc <Plug>HGCommit
1085 endif
1085 endif
1086 if !hasmapto('<Plug>HGDiff')
1086 if !hasmapto('<Plug>HGDiff')
1087 nmap <unique> <Leader>hgd <Plug>HGDiff
1087 nmap <unique> <Leader>hgd <Plug>HGDiff
1088 endif
1088 endif
1089 if !hasmapto('<Plug>HGGotoOriginal')
1089 if !hasmapto('<Plug>HGGotoOriginal')
1090 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
1090 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
1091 endif
1091 endif
1092 if !hasmapto('<Plug>HGLog')
1092 if !hasmapto('<Plug>HGLog')
1093 nmap <unique> <Leader>hgl <Plug>HGLog
1093 nmap <unique> <Leader>hgl <Plug>HGLog
1094 endif
1094 endif
1095 if !hasmapto('<Plug>HGRevert')
1095 if !hasmapto('<Plug>HGRevert')
1096 nmap <unique> <Leader>hgq <Plug>HGRevert
1096 nmap <unique> <Leader>hgq <Plug>HGRevert
1097 endif
1097 endif
1098 if !hasmapto('<Plug>HGReview')
1098 if !hasmapto('<Plug>HGReview')
1099 nmap <unique> <Leader>hgr <Plug>HGReview
1099 nmap <unique> <Leader>hgr <Plug>HGReview
1100 endif
1100 endif
1101 if !hasmapto('<Plug>HGStatus')
1101 if !hasmapto('<Plug>HGStatus')
1102 nmap <unique> <Leader>hgs <Plug>HGStatus
1102 nmap <unique> <Leader>hgs <Plug>HGStatus
1103 endif
1103 endif
1104 if !hasmapto('<Plug>HGUpdate')
1104 if !hasmapto('<Plug>HGUpdate')
1105 nmap <unique> <Leader>hgu <Plug>HGUpdate
1105 nmap <unique> <Leader>hgu <Plug>HGUpdate
1106 endif
1106 endif
1107 if !hasmapto('<Plug>HGVimDiff')
1107 if !hasmapto('<Plug>HGVimDiff')
1108 nmap <unique> <Leader>hgv <Plug>HGVimDiff
1108 nmap <unique> <Leader>hgv <Plug>HGVimDiff
1109 endif
1109 endif
1110
1110
1111 " Section: Menu items {{{1
1111 " Section: Menu items {{{1
1112 silent! aunmenu Plugin.HG
1112 silent! aunmenu Plugin.HG
1113 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
1113 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
1114 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
1114 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
1115 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
1115 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
1116 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
1116 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
1117 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
1117 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
1118 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
1118 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
1119 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
1119 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
1120 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
1120 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
1121 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
1121 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
1122 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
1122 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
1123
1123
1124 " Section: Autocommands to restore vimdiff state {{{1
1124 " Section: Autocommands to restore vimdiff state {{{1
1125 function! s:HGVimDiffRestore(vimDiffBuff)
1125 function! s:HGVimDiffRestore(vimDiffBuff)
1126 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1126 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1127 try
1127 try
1128 if exists("s:vimDiffSourceBuffer")
1128 if exists("s:vimDiffSourceBuffer")
1129 if a:vimDiffBuff == s:vimDiffSourceBuffer
1129 if a:vimDiffBuff == s:vimDiffSourceBuffer
1130 " Original file is being removed.
1130 " Original file is being removed.
1131 unlet! s:vimDiffSourceBuffer
1131 unlet! s:vimDiffSourceBuffer
1132 unlet! s:vimDiffBufferCount
1132 unlet! s:vimDiffBufferCount
1133 unlet! s:vimDiffRestoreCmd
1133 unlet! s:vimDiffRestoreCmd
1134 unlet! s:vimDiffScratchList
1134 unlet! s:vimDiffScratchList
1135 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
1135 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
1136 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
1136 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
1137 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
1137 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
1138 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
1138 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
1139 " All scratch buffers are gone, reset the original.
1139 " All scratch buffers are gone, reset the original.
1140 " Only restore if the source buffer is still in Diff mode
1140 " Only restore if the source buffer is still in Diff mode
1141
1141
1142 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
1142 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
1143 if sourceWinNR != -1
1143 if sourceWinNR != -1
1144 " The buffer is visible in at least one window
1144 " The buffer is visible in at least one window
1145 let currentWinNR = winnr()
1145 let currentWinNR = winnr()
1146 while winbufnr(sourceWinNR) != -1
1146 while winbufnr(sourceWinNR) != -1
1147 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
1147 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
1148 execute sourceWinNR . 'wincmd w'
1148 execute sourceWinNR . 'wincmd w'
1149 if getwinvar('', "&diff")
1149 if getwinvar('', "&diff")
1150 execute s:vimDiffRestoreCmd
1150 execute s:vimDiffRestoreCmd
1151 endif
1151 endif
1152 endif
1152 endif
1153 let sourceWinNR = sourceWinNR + 1
1153 let sourceWinNR = sourceWinNR + 1
1154 endwhile
1154 endwhile
1155 execute currentWinNR . 'wincmd w'
1155 execute currentWinNR . 'wincmd w'
1156 else
1156 else
1157 " The buffer is hidden. It must be visible in order to set the
1157 " The buffer is hidden. It must be visible in order to set the
1158 " diff option.
1158 " diff option.
1159 let currentBufNR = bufnr('')
1159 let currentBufNR = bufnr('')
1160 execute "hide buffer" s:vimDiffSourceBuffer
1160 execute "hide buffer" s:vimDiffSourceBuffer
1161 if getwinvar('', "&diff")
1161 if getwinvar('', "&diff")
1162 execute s:vimDiffRestoreCmd
1162 execute s:vimDiffRestoreCmd
1163 endif
1163 endif
1164 execute "hide buffer" currentBufNR
1164 execute "hide buffer" currentBufNR
1165 endif
1165 endif
1166
1166
1167 unlet s:vimDiffRestoreCmd
1167 unlet s:vimDiffRestoreCmd
1168 unlet s:vimDiffSourceBuffer
1168 unlet s:vimDiffSourceBuffer
1169 unlet s:vimDiffBufferCount
1169 unlet s:vimDiffBufferCount
1170 unlet s:vimDiffScratchList
1170 unlet s:vimDiffScratchList
1171 elseif s:vimDiffBufferCount == 0
1171 elseif s:vimDiffBufferCount == 0
1172 " All buffers are gone.
1172 " All buffers are gone.
1173 unlet s:vimDiffSourceBuffer
1173 unlet s:vimDiffSourceBuffer
1174 unlet s:vimDiffBufferCount
1174 unlet s:vimDiffBufferCount
1175 unlet s:vimDiffScratchList
1175 unlet s:vimDiffScratchList
1176 endif
1176 endif
1177 endif
1177 endif
1178 endif
1178 endif
1179 finally
1179 finally
1180 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1180 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1181 endtry
1181 endtry
1182 endfunction
1182 endfunction
1183
1183
1184 augroup HGVimDiffRestore
1184 augroup HGVimDiffRestore
1185 au!
1185 au!
1186 au BufUnload * call <SID>HGVimDiffRestore(expand("<abuf>"))
1186 au BufUnload * call <SID>HGVimDiffRestore(expand("<abuf>"))
1187 augroup END
1187 augroup END
1188
1188
1189 " Section: Optional activation of buffer management {{{1
1189 " Section: Optional activation of buffer management {{{1
1190
1190
1191 if s:HGGetOption('HGCommandEnableBufferSetup', 1)
1191 if s:HGGetOption('HGCommandEnableBufferSetup', 1)
1192 call HGEnableBufferSetup()
1192 call HGEnableBufferSetup()
1193 endif
1193 endif
1194
1194
1195 " Section: Doc installation {{{1
1195 " Section: Doc installation {{{1
1196
1196
1197 if <SID>HGInstallDocumentation(expand("<sfile>:p"))
1197 if <SID>HGInstallDocumentation(expand("<sfile>:p"))
1198 echomsg s:script_name s:script_version . ": updated documentation"
1198 echomsg s:script_name s:script_version . ": updated documentation"
1199 endif
1199 endif
1200
1200
1201 " Section: Plugin completion {{{1
1201 " Section: Plugin completion {{{1
1202
1202
1203 " delete one-time vars and functions
1203 " delete one-time vars and functions
1204 delfunction <SID>HGInstallDocumentation
1204 delfunction <SID>HGInstallDocumentation
1205 delfunction <SID>HGFlexiMkdir
1205 delfunction <SID>HGFlexiMkdir
1206 delfunction <SID>HGCleanupOnFailure
1206 delfunction <SID>HGCleanupOnFailure
1207 unlet s:script_version s:script_name
1207 unlet s:script_version s:script_name
1208
1208
1209 let g:loaded_hgcommand=2
1209 let g:loaded_hgcommand=2
1210 silent do HGCommand User HGPluginFinish
1210 silent do HGCommand User HGPluginFinish
1211
1211
1212 let &cpo = s:save_cpo
1212 let &cpo = s:save_cpo
1213 unlet s:save_cpo
1213 unlet s:save_cpo
1214 " vim:se expandtab sts=2 sw=2:
1214 " vim:se expandtab sts=2 sw=2:
1215 finish
1215 finish
1216
1216
1217 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1217 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1218 " Section: Documentation content {{{1
1218 " Section: Documentation content {{{1
1219 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1219 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1220 === START_DOC
1220 === START_DOC
1221 *hgcommand.txt* Mercurial vim integration #version#
1221 *hgcommand.txt* Mercurial vim integration #version#
1222
1222
1223
1223
1224 HGCOMMAND REFERENCE MANUAL~
1224 HGCOMMAND REFERENCE MANUAL~
1225
1225
1226
1226
1227 Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
1227 Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
1228 Credits: Bob Hiestand <bob.hiestand@gmail.com>
1228 Credits: Bob Hiestand <bob.hiestand@gmail.com>
1229 Mercurial: http://mercurial.selenic.com/
1229 Mercurial: http://mercurial.selenic.com/
1230 Mercurial (noted Hg) is a fast, lightweight Source Control Management
1230 Mercurial (noted Hg) is a fast, lightweight Source Control Management
1231 system designed for efficient handling of very large distributed projects.
1231 system designed for efficient handling of very large distributed projects.
1232
1232
1233 ==============================================================================
1233 ==============================================================================
1234 1. Contents *hgcommand-contents*
1234 1. Contents *hgcommand-contents*
1235
1235
1236 Installation : |hgcommand-install|
1236 Installation : |hgcommand-install|
1237 HGCommand Intro : |hgcommand|
1237 HGCommand Intro : |hgcommand|
1238 HGCommand Manual : |hgcommand-manual|
1238 HGCommand Manual : |hgcommand-manual|
1239 Customization : |hgcommand-customize|
1239 Customization : |hgcommand-customize|
1240 Bugs : |hgcommand-bugs|
1240 Bugs : |hgcommand-bugs|
1241
1241
1242 ==============================================================================
1242 ==============================================================================
1243 2. HGCommand Installation *hgcommand-install*
1243 2. HGCommand Installation *hgcommand-install*
1244
1244
1245 In order to install the plugin, place the hgcommand.vim file into a plugin'
1245 In order to install the plugin, place the hgcommand.vim file into a plugin'
1246 directory in your runtime path (please see |add-global-plugin| and
1246 directory in your runtime path (please see |add-global-plugin| and
1247 |'runtimepath'|.
1247 |'runtimepath'|.
1248
1248
1249 HGCommand may be customized by setting variables, creating maps, and
1249 HGCommand may be customized by setting variables, creating maps, and
1250 specifying event handlers. Please see |hgcommand-customize| for more
1250 specifying event handlers. Please see |hgcommand-customize| for more
1251 details.
1251 details.
1252
1252
1253 *hgcommand-auto-help*
1253 *hgcommand-auto-help*
1254 The help file is automagically generated when the |hgcommand| script is
1254 The help file is automagically generated when the |hgcommand| script is
1255 loaded for the first time.
1255 loaded for the first time.
1256
1256
1257 ==============================================================================
1257 ==============================================================================
1258
1258
1259 3. HGCommand Intro *hgcommand*
1259 3. HGCommand Intro *hgcommand*
1260 *hgcommand-intro*
1260 *hgcommand-intro*
1261
1261
1262 The HGCommand plugin provides global ex commands for manipulating
1262 The HGCommand plugin provides global ex commands for manipulating
1263 HG-controlled source files. In general, each command operates on the
1263 HG-controlled source files. In general, each command operates on the
1264 current buffer and accomplishes a separate hg function, such as update,
1264 current buffer and accomplishes a separate hg function, such as update,
1265 commit, log, and others (please see |hgcommand-commands| for a list of all
1265 commit, log, and others (please see |hgcommand-commands| for a list of all
1266 available commands). The results of each operation are displayed in a
1266 available commands). The results of each operation are displayed in a
1267 scratch buffer. Several buffer variables are defined for those scratch
1267 scratch buffer. Several buffer variables are defined for those scratch
1268 buffers (please see |hgcommand-buffer-variables|).
1268 buffers (please see |hgcommand-buffer-variables|).
1269
1269
1270 The notion of "current file" means either the current buffer, or, in the
1270 The notion of "current file" means either the current buffer, or, in the
1271 case of a directory buffer, the file on the current line within the buffer.
1271 case of a directory buffer, the file on the current line within the buffer.
1272
1272
1273 For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
1273 For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
1274 as though it was invoked on the original file and splits the screen so that
1274 as though it was invoked on the original file and splits the screen so that
1275 the output appears in a new window.
1275 the output appears in a new window.
1276
1276
1277 Many of the commands accept revisions as arguments. By default, most
1277 Many of the commands accept revisions as arguments. By default, most
1278 operate on the most recent revision on the current branch if no revision is
1278 operate on the most recent revision on the current branch if no revision is
1279 specified (though see |HGCommandInteractive| to prompt instead).
1279 specified (though see |HGCommandInteractive| to prompt instead).
1280
1280
1281 Each HGCommand is mapped to a key sequence starting with the <Leader>
1281 Each HGCommand is mapped to a key sequence starting with the <Leader>
1282 keystroke. The default mappings may be overridden by supplying different
1282 keystroke. The default mappings may be overridden by supplying different
1283 mappings before the plugin is loaded, such as in the vimrc, in the standard
1283 mappings before the plugin is loaded, such as in the vimrc, in the standard
1284 fashion for plugin mappings. For examples, please see
1284 fashion for plugin mappings. For examples, please see
1285 |hgcommand-mappings-override|.
1285 |hgcommand-mappings-override|.
1286
1286
1287 The HGCommand plugin may be configured in several ways. For more details,
1287 The HGCommand plugin may be configured in several ways. For more details,
1288 please see |hgcommand-customize|.
1288 please see |hgcommand-customize|.
1289
1289
1290 ==============================================================================
1290 ==============================================================================
1291 4. HGCommand Manual *hgcommand-manual*
1291 4. HGCommand Manual *hgcommand-manual*
1292
1292
1293 4.1 HGCommand commands *hgcommand-commands*
1293 4.1 HGCommand commands *hgcommand-commands*
1294
1294
1295 HGCommand defines the following commands:
1295 HGCommand defines the following commands:
1296
1296
1297 |:HGAdd|
1297 |:HGAdd|
1298 |:HGAnnotate|
1298 |:HGAnnotate|
1299 |:HGCommit|
1299 |:HGCommit|
1300 |:HGDiff|
1300 |:HGDiff|
1301 |:HGGotoOriginal|
1301 |:HGGotoOriginal|
1302 |:HGLog|
1302 |:HGLog|
1303 |:HGRevert|
1303 |:HGRevert|
1304 |:HGReview|
1304 |:HGReview|
1305 |:HGStatus|
1305 |:HGStatus|
1306 |:HGUpdate|
1306 |:HGUpdate|
1307 |:HGVimDiff|
1307 |:HGVimDiff|
1308
1308
1309 :HGAdd *:HGAdd*
1309 :HGAdd *:HGAdd*
1310
1310
1311 This command performs "hg add" on the current file. Please note, this does
1311 This command performs "hg add" on the current file. Please note, this does
1312 not commit the newly-added file.
1312 not commit the newly-added file.
1313
1313
1314 :HGAnnotate *:HGAnnotate*
1314 :HGAnnotate *:HGAnnotate*
1315
1315
1316 This command performs "hg annotate" on the current file. If an argument is
1316 This command performs "hg annotate" on the current file. If an argument is
1317 given, the argument is used as a revision number to display. If not given
1317 given, the argument is used as a revision number to display. If not given
1318 an argument, it uses the most recent version of the file on the current
1318 an argument, it uses the most recent version of the file on the current
1319 branch. Additionally, if the current buffer is a HGAnnotate buffer
1319 branch. Additionally, if the current buffer is a HGAnnotate buffer
1320 already, the version number on the current line is used.
1320 already, the version number on the current line is used.
1321
1321
1322 If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
1322 If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
1323 version previous to the one on the current line is used instead. This
1323 version previous to the one on the current line is used instead. This
1324 allows one to navigate back to examine the previous version of a line.
1324 allows one to navigate back to examine the previous version of a line.
1325
1325
1326 The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
1326 The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
1327 take advantage of the bundled syntax file.
1327 take advantage of the bundled syntax file.
1328
1328
1329
1329
1330 :HGCommit[!] *:HGCommit*
1330 :HGCommit[!] *:HGCommit*
1331
1331
1332 If called with arguments, this performs "hg commit" using the arguments as
1332 If called with arguments, this performs "hg commit" using the arguments as
1333 the log message.
1333 the log message.
1334
1334
1335 If '!' is used with no arguments, an empty log message is committed.
1335 If '!' is used with no arguments, an empty log message is committed.
1336
1336
1337 If called with no arguments, this is a two-step command. The first step
1337 If called with no arguments, this is a two-step command. The first step
1338 opens a buffer to accept a log message. When that buffer is written, it is
1338 opens a buffer to accept a log message. When that buffer is written, it is
1339 automatically closed and the file is committed using the information from
1339 automatically closed and the file is committed using the information from
1340 that log message. The commit can be abandoned if the log message buffer is
1340 that log message. The commit can be abandoned if the log message buffer is
1341 deleted or wiped before being written.
1341 deleted or wiped before being written.
1342
1342
1343 Alternatively, the mapping that is used to invoke :HGCommit (by default
1343 Alternatively, the mapping that is used to invoke :HGCommit (by default
1344 <Leader>hgc) can be used in the log message buffer to immediately commit.
1344 <Leader>hgc) can be used in the log message buffer to immediately commit.
1345 This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
1345 This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
1346 disable the normal commit-on-write behavior.
1346 disable the normal commit-on-write behavior.
1347
1347
1348 :HGDiff *:HGDiff*
1348 :HGDiff *:HGDiff*
1349
1349
1350 With no arguments, this performs "hg diff" on the current file against the
1350 With no arguments, this performs "hg diff" on the current file against the
1351 current repository version.
1351 current repository version.
1352
1352
1353 With one argument, "hg diff" is performed on the current file against the
1353 With one argument, "hg diff" is performed on the current file against the
1354 specified revision.
1354 specified revision.
1355
1355
1356 With two arguments, hg diff is performed between the specified revisions of
1356 With two arguments, hg diff is performed between the specified revisions of
1357 the current file.
1357 the current file.
1358
1358
1359 This command uses the 'HGCommandDiffOpt' variable to specify diff options.
1359 This command uses the 'HGCommandDiffOpt' variable to specify diff options.
1360 If that variable does not exist, then 'wbBc' is assumed. If you wish to
1360 If that variable does not exist, then 'wbBc' is assumed. If you wish to
1361 have no options, then set it to the empty string.
1361 have no options, then set it to the empty string.
1362
1362
1363
1363
1364 :HGGotoOriginal *:HGGotoOriginal*
1364 :HGGotoOriginal *:HGGotoOriginal*
1365
1365
1366 This command returns the current window to the source buffer, if the
1366 This command returns the current window to the source buffer, if the
1367 current buffer is a HG command output buffer.
1367 current buffer is a HG command output buffer.
1368
1368
1369 :HGGotoOriginal!
1369 :HGGotoOriginal!
1370
1370
1371 Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
1371 Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
1372 output buffers for the source buffer.
1372 output buffers for the source buffer.
1373
1373
1374 :HGLog *:HGLog*
1374 :HGLog *:HGLog*
1375
1375
1376 Performs "hg log" on the current file.
1376 Performs "hg log" on the current file.
1377
1377
1378 If an argument is given, it is passed as an argument to the "-r" option of
1378 If an argument is given, it is passed as an argument to the "-r" option of
1379 "hg log".
1379 "hg log".
1380
1380
1381 :HGRevert *:HGRevert*
1381 :HGRevert *:HGRevert*
1382
1382
1383 Replaces the current file with the most recent version from the repository
1383 Replaces the current file with the most recent version from the repository
1384 in order to wipe out any undesired changes.
1384 in order to wipe out any undesired changes.
1385
1385
1386 :HGReview *:HGReview*
1386 :HGReview *:HGReview*
1387
1387
1388 Retrieves a particular version of the current file. If no argument is
1388 Retrieves a particular version of the current file. If no argument is
1389 given, the most recent version of the file on the current branch is
1389 given, the most recent version of the file on the current branch is
1390 retrieved. Otherwise, the specified version is retrieved.
1390 retrieved. Otherwise, the specified version is retrieved.
1391
1391
1392 :HGStatus *:HGStatus*
1392 :HGStatus *:HGStatus*
1393
1393
1394 Performs "hg status" on the current file.
1394 Performs "hg status" on the current file.
1395
1395
1396 :HGUpdate *:HGUpdate*
1396 :HGUpdate *:HGUpdate*
1397
1397
1398 Performs "hg update" on the current file. This intentionally does not
1398 Performs "hg update" on the current file. This intentionally does not
1399 automatically reload the current buffer, though vim should prompt the user
1399 automatically reload the current buffer, though vim should prompt the user
1400 to do so if the underlying file is altered by this command.
1400 to do so if the underlying file is altered by this command.
1401
1401
1402 :HGVimDiff *:HGVimDiff*
1402 :HGVimDiff *:HGVimDiff*
1403
1403
1404 With no arguments, this prompts the user for a revision and then uses
1404 With no arguments, this prompts the user for a revision and then uses
1405 vimdiff to display the differences between the current file and the
1405 vimdiff to display the differences between the current file and the
1406 specified revision. If no revision is specified, the most recent version
1406 specified revision. If no revision is specified, the most recent version
1407 of the file on the current branch is used.
1407 of the file on the current branch is used.
1408
1408
1409 With one argument, that argument is used as the revision as above. With
1409 With one argument, that argument is used as the revision as above. With
1410 two arguments, the differences between the two revisions is displayed using
1410 two arguments, the differences between the two revisions is displayed using
1411 vimdiff.
1411 vimdiff.
1412
1412
1413 With either zero or one argument, the original buffer is used to perform
1413 With either zero or one argument, the original buffer is used to perform
1414 the vimdiff. When the other buffer is closed, the original buffer will be
1414 the vimdiff. When the other buffer is closed, the original buffer will be
1415 returned to normal mode.
1415 returned to normal mode.
1416
1416
1417 Once vimdiff mode is started using the above methods, additional vimdiff
1417 Once vimdiff mode is started using the above methods, additional vimdiff
1418 buffers may be added by passing a single version argument to the command.
1418 buffers may be added by passing a single version argument to the command.
1419 There may be up to 4 vimdiff buffers total.
1419 There may be up to 4 vimdiff buffers total.
1420
1420
1421 Using the 2-argument form of the command resets the vimdiff to only those 2
1421 Using the 2-argument form of the command resets the vimdiff to only those 2
1422 versions. Additionally, invoking the command on a different file will
1422 versions. Additionally, invoking the command on a different file will
1423 close the previous vimdiff buffers.
1423 close the previous vimdiff buffers.
1424
1424
1425
1425
1426 4.2 Mappings *hgcommand-mappings*
1426 4.2 Mappings *hgcommand-mappings*
1427
1427
1428 By default, a mapping is defined for each command. These mappings execute
1428 By default, a mapping is defined for each command. These mappings execute
1429 the default (no-argument) form of each command.
1429 the default (no-argument) form of each command.
1430
1430
1431 <Leader>hga HGAdd
1431 <Leader>hga HGAdd
1432 <Leader>hgn HGAnnotate
1432 <Leader>hgn HGAnnotate
1433 <Leader>hgc HGCommit
1433 <Leader>hgc HGCommit
1434 <Leader>hgd HGDiff
1434 <Leader>hgd HGDiff
1435 <Leader>hgg HGGotoOriginal
1435 <Leader>hgg HGGotoOriginal
1436 <Leader>hgG HGGotoOriginal!
1436 <Leader>hgG HGGotoOriginal!
1437 <Leader>hgl HGLog
1437 <Leader>hgl HGLog
1438 <Leader>hgr HGReview
1438 <Leader>hgr HGReview
1439 <Leader>hgs HGStatus
1439 <Leader>hgs HGStatus
1440 <Leader>hgu HGUpdate
1440 <Leader>hgu HGUpdate
1441 <Leader>hgv HGVimDiff
1441 <Leader>hgv HGVimDiff
1442
1442
1443 *hgcommand-mappings-override*
1443 *hgcommand-mappings-override*
1444
1444
1445 The default mappings can be overridden by user-provided instead by mapping
1445 The default mappings can be overridden by user-provided instead by mapping
1446 to <Plug>CommandName. This is especially useful when these mappings
1446 to <Plug>CommandName. This is especially useful when these mappings
1447 collide with other existing mappings (vim will warn of this during plugin
1447 collide with other existing mappings (vim will warn of this during plugin
1448 initialization, but will not clobber the existing mappings).
1448 initialization, but will not clobber the existing mappings).
1449
1449
1450 For instance, to override the default mapping for :HGAdd to set it to
1450 For instance, to override the default mapping for :HGAdd to set it to
1451 '\add', add the following to the vimrc: >
1451 '\add', add the following to the vimrc: >
1452
1452
1453 nmap \add <Plug>HGAdd
1453 nmap \add <Plug>HGAdd
1454 <
1454 <
1455 4.3 Automatic buffer variables *hgcommand-buffer-variables*
1455 4.3 Automatic buffer variables *hgcommand-buffer-variables*
1456
1456
1457 Several buffer variables are defined in each HGCommand result buffer.
1457 Several buffer variables are defined in each HGCommand result buffer.
1458 These may be useful for additional customization in callbacks defined in
1458 These may be useful for additional customization in callbacks defined in
1459 the event handlers (please see |hgcommand-events|).
1459 the event handlers (please see |hgcommand-events|).
1460
1460
1461 The following variables are automatically defined:
1461 The following variables are automatically defined:
1462
1462
1463 b:hgOrigBuffNR *b:hgOrigBuffNR*
1463 b:hgOrigBuffNR *b:hgOrigBuffNR*
1464
1464
1465 This variable is set to the buffer number of the source file.
1465 This variable is set to the buffer number of the source file.
1466
1466
1467 b:hgcmd *b:hgcmd*
1467 b:hgcmd *b:hgcmd*
1468
1468
1469 This variable is set to the name of the hg command that created the result
1469 This variable is set to the name of the hg command that created the result
1470 buffer.
1470 buffer.
1471 ==============================================================================
1471 ==============================================================================
1472
1472
1473 5. Configuration and customization *hgcommand-customize*
1473 5. Configuration and customization *hgcommand-customize*
1474 *hgcommand-config*
1474 *hgcommand-config*
1475
1475
1476 The HGCommand plugin can be configured in two ways: by setting
1476 The HGCommand plugin can be configured in two ways: by setting
1477 configuration variables (see |hgcommand-options|) or by defining HGCommand
1477 configuration variables (see |hgcommand-options|) or by defining HGCommand
1478 event handlers (see |hgcommand-events|). Additionally, the HGCommand
1478 event handlers (see |hgcommand-events|). Additionally, the HGCommand
1479 plugin provides several option for naming the HG result buffers (see
1479 plugin provides several option for naming the HG result buffers (see
1480 |hgcommand-naming|) and supported a customized status line (see
1480 |hgcommand-naming|) and supported a customized status line (see
1481 |hgcommand-statusline| and |hgcommand-buffer-management|).
1481 |hgcommand-statusline| and |hgcommand-buffer-management|).
1482
1482
1483 5.1 HGCommand configuration variables *hgcommand-options*
1483 5.1 HGCommand configuration variables *hgcommand-options*
1484
1484
1485 Several variables affect the plugin's behavior. These variables are
1485 Several variables affect the plugin's behavior. These variables are
1486 checked at time of execution, and may be defined at the window, buffer, or
1486 checked at time of execution, and may be defined at the window, buffer, or
1487 global level and are checked in that order of precedence.
1487 global level and are checked in that order of precedence.
1488
1488
1489
1489
1490 The following variables are available:
1490 The following variables are available:
1491
1491
1492 |HGCommandAnnotateParent|
1492 |HGCommandAnnotateParent|
1493 |HGCommandCommitOnWrite|
1493 |HGCommandCommitOnWrite|
1494 |HGCommandHGExec|
1494 |HGCommandHGExec|
1495 |HGCommandDeleteOnHide|
1495 |HGCommandDeleteOnHide|
1496 |HGCommandDiffOpt|
1496 |HGCommandDiffOpt|
1497 |HGCommandDiffSplit|
1497 |HGCommandDiffSplit|
1498 |HGCommandEdit|
1498 |HGCommandEdit|
1499 |HGCommandEnableBufferSetup|
1499 |HGCommandEnableBufferSetup|
1500 |HGCommandInteractive|
1500 |HGCommandInteractive|
1501 |HGCommandNameMarker|
1501 |HGCommandNameMarker|
1502 |HGCommandNameResultBuffers|
1502 |HGCommandNameResultBuffers|
1503 |HGCommandSplit|
1503 |HGCommandSplit|
1504
1504
1505 HGCommandAnnotateParent *HGCommandAnnotateParent*
1505 HGCommandAnnotateParent *HGCommandAnnotateParent*
1506
1506
1507 This variable, if set to a non-zero value, causes the zero-argument form of
1507 This variable, if set to a non-zero value, causes the zero-argument form of
1508 HGAnnotate when invoked on a HGAnnotate buffer to go to the version
1508 HGAnnotate when invoked on a HGAnnotate buffer to go to the version
1509 previous to that displayed on the current line. If not set, it defaults to
1509 previous to that displayed on the current line. If not set, it defaults to
1510 0.
1510 0.
1511
1511
1512 HGCommandCommitOnWrite *HGCommandCommitOnWrite*
1512 HGCommandCommitOnWrite *HGCommandCommitOnWrite*
1513
1513
1514 This variable, if set to a non-zero value, causes the pending hg commit to
1514 This variable, if set to a non-zero value, causes the pending hg commit to
1515 take place immediately as soon as the log message buffer is written. If
1515 take place immediately as soon as the log message buffer is written. If
1516 set to zero, only the HGCommit mapping will cause the pending commit to
1516 set to zero, only the HGCommit mapping will cause the pending commit to
1517 occur. If not set, it defaults to 1.
1517 occur. If not set, it defaults to 1.
1518
1518
1519 HGCommandHGExec *HGCommandHGExec*
1519 HGCommandHGExec *HGCommandHGExec*
1520
1520
1521 This variable controls the executable used for all HG commands. If not
1521 This variable controls the executable used for all HG commands. If not
1522 set, it defaults to "hg".
1522 set, it defaults to "hg".
1523
1523
1524 HGCommandDeleteOnHide *HGCommandDeleteOnHide*
1524 HGCommandDeleteOnHide *HGCommandDeleteOnHide*
1525
1525
1526 This variable, if set to a non-zero value, causes the temporary HG result
1526 This variable, if set to a non-zero value, causes the temporary HG result
1527 buffers to automatically delete themselves when hidden.
1527 buffers to automatically delete themselves when hidden.
1528
1528
1529 HGCommandDiffOpt *HGCommandDiffOpt*
1529 HGCommandDiffOpt *HGCommandDiffOpt*
1530
1530
1531 This variable, if set, determines the options passed to the diff command of
1531 This variable, if set, determines the options passed to the diff command of
1532 HG. If not set, it defaults to 'w'.
1532 HG. If not set, it defaults to 'w'.
1533
1533
1534 HGCommandDiffSplit *HGCommandDiffSplit*
1534 HGCommandDiffSplit *HGCommandDiffSplit*
1535
1535
1536 This variable overrides the |HGCommandSplit| variable, but only for buffers
1536 This variable overrides the |HGCommandSplit| variable, but only for buffers
1537 created with |:HGVimDiff|.
1537 created with |:HGVimDiff|.
1538
1538
1539 HGCommandEdit *HGCommandEdit*
1539 HGCommandEdit *HGCommandEdit*
1540
1540
1541 This variable controls whether the original buffer is replaced ('edit') or
1541 This variable controls whether the original buffer is replaced ('edit') or
1542 split ('split'). If not set, it defaults to 'edit'.
1542 split ('split'). If not set, it defaults to 'edit'.
1543
1543
1544 HGCommandEnableBufferSetup *HGCommandEnableBufferSetup*
1544 HGCommandEnableBufferSetup *HGCommandEnableBufferSetup*
1545
1545
1546 This variable, if set to a non-zero value, activates HG buffer management
1546 This variable, if set to a non-zero value, activates HG buffer management
1547 mode see (|hgcommand-buffer-management|). This mode means that three
1547 mode see (|hgcommand-buffer-management|). This mode means that three
1548 buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if
1548 buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if
1549 the file is HG-controlled. This is useful for displaying version
1549 the file is HG-controlled. This is useful for displaying version
1550 information in the status bar.
1550 information in the status bar.
1551
1551
1552 HGCommandInteractive *HGCommandInteractive*
1552 HGCommandInteractive *HGCommandInteractive*
1553
1553
1554 This variable, if set to a non-zero value, causes appropriate commands (for
1554 This variable, if set to a non-zero value, causes appropriate commands (for
1555 the moment, only |:HGReview|) to query the user for a revision to use
1555 the moment, only |:HGReview|) to query the user for a revision to use
1556 instead of the current revision if none is specified.
1556 instead of the current revision if none is specified.
1557
1557
1558 HGCommandNameMarker *HGCommandNameMarker*
1558 HGCommandNameMarker *HGCommandNameMarker*
1559
1559
1560 This variable, if set, configures the special attention-getting characters
1560 This variable, if set, configures the special attention-getting characters
1561 that appear on either side of the hg buffer type in the buffer name. This
1561 that appear on either side of the hg buffer type in the buffer name. This
1562 has no effect unless |HGCommandNameResultBuffers| is set to a true value.
1562 has no effect unless |HGCommandNameResultBuffers| is set to a true value.
1563 If not set, it defaults to '_'.
1563 If not set, it defaults to '_'.
1564
1564
1565 HGCommandNameResultBuffers *HGCommandNameResultBuffers*
1565 HGCommandNameResultBuffers *HGCommandNameResultBuffers*
1566
1566
1567 This variable, if set to a true value, causes the hg result buffers to be
1567 This variable, if set to a true value, causes the hg result buffers to be
1568 named in the old way ('<source file name> _<hg command>_'). If not set or
1568 named in the old way ('<source file name> _<hg command>_'). If not set or
1569 set to a false value, the result buffer is nameless.
1569 set to a false value, the result buffer is nameless.
1570
1570
1571 HGCommandSplit *HGCommandSplit*
1571 HGCommandSplit *HGCommandSplit*
1572
1572
1573 This variable controls the orientation of the various window splits that
1573 This variable controls the orientation of the various window splits that
1574 may occur (such as with HGVimDiff, when using a HG command on a HG command
1574 may occur (such as with HGVimDiff, when using a HG command on a HG command
1575 buffer, or when the |HGCommandEdit| variable is set to 'split'. If set to
1575 buffer, or when the |HGCommandEdit| variable is set to 'split'. If set to
1576 'horizontal', the resulting windows will be on stacked on top of one
1576 'horizontal', the resulting windows will be on stacked on top of one
1577 another. If set to 'vertical', the resulting windows will be side-by-side.
1577 another. If set to 'vertical', the resulting windows will be side-by-side.
1578 If not set, it defaults to 'horizontal' for all but HGVimDiff windows.
1578 If not set, it defaults to 'horizontal' for all but HGVimDiff windows.
1579
1579
1580 5.2 HGCommand events *hgcommand-events*
1580 5.2 HGCommand events *hgcommand-events*
1581
1581
1582 For additional customization, HGCommand can trigger user-defined events.
1582 For additional customization, HGCommand can trigger user-defined events.
1583 Event handlers are provided by defining User event autocommands (see
1583 Event handlers are provided by defining User event autocommands (see
1584 |autocommand|, |User|) in the HGCommand group with patterns matching the
1584 |autocommand|, |User|) in the HGCommand group with patterns matching the
1585 event name.
1585 event name.
1586
1586
1587 For instance, the following could be added to the vimrc to provide a 'q'
1587 For instance, the following could be added to the vimrc to provide a 'q'
1588 mapping to quit a HGCommand scratch buffer: >
1588 mapping to quit a HGCommand scratch buffer: >
1589
1589
1590 augroup HGCommand
1590 augroup HGCommand
1591 au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q:
1591 au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q:
1592 bwipeout<cr>
1592 bwipeout<cr>
1593 augroup END
1593 augroup END
1594 <
1594 <
1595
1595
1596 The following hooks are available:
1596 The following hooks are available:
1597
1597
1598 HGBufferCreated This event is fired just after a hg command result
1598 HGBufferCreated This event is fired just after a hg command result
1599 buffer is created and filled with the result of a hg
1599 buffer is created and filled with the result of a hg
1600 command. It is executed within the context of the HG
1600 command. It is executed within the context of the HG
1601 command buffer. The HGCommand buffer variables may be
1601 command buffer. The HGCommand buffer variables may be
1602 useful for handlers of this event (please see
1602 useful for handlers of this event (please see
1603 |hgcommand-buffer-variables|).
1603 |hgcommand-buffer-variables|).
1604
1604
1605 HGBufferSetup This event is fired just after HG buffer setup occurs,
1605 HGBufferSetup This event is fired just after HG buffer setup occurs,
1606 if enabled.
1606 if enabled.
1607
1607
1608 HGPluginInit This event is fired when the HGCommand plugin first
1608 HGPluginInit This event is fired when the HGCommand plugin first
1609 loads.
1609 loads.
1610
1610
1611 HGPluginFinish This event is fired just after the HGCommand plugin
1611 HGPluginFinish This event is fired just after the HGCommand plugin
1612 loads.
1612 loads.
1613
1613
1614 HGVimDiffFinish This event is fired just after the HGVimDiff command
1614 HGVimDiffFinish This event is fired just after the HGVimDiff command
1615 executes to allow customization of, for instance,
1615 executes to allow customization of, for instance,
1616 window placement and focus.
1616 window placement and focus.
1617
1617
1618 5.3 HGCommand buffer naming *hgcommand-naming*
1618 5.3 HGCommand buffer naming *hgcommand-naming*
1619
1619
1620 By default, the buffers containing the result of HG commands are nameless
1620 By default, the buffers containing the result of HG commands are nameless
1621 scratch buffers. It is intended that buffer variables of those buffers be
1621 scratch buffers. It is intended that buffer variables of those buffers be
1622 used to customize the statusline option so that the user may fully control
1622 used to customize the statusline option so that the user may fully control
1623 the display of result buffers.
1623 the display of result buffers.
1624
1624
1625 If the old-style naming is desired, please enable the
1625 If the old-style naming is desired, please enable the
1626 |HGCommandNameResultBuffers| variable. Then, each result buffer will
1626 |HGCommandNameResultBuffers| variable. Then, each result buffer will
1627 receive a unique name that includes the source file name, the HG command,
1627 receive a unique name that includes the source file name, the HG command,
1628 and any extra data (such as revision numbers) that were part of the
1628 and any extra data (such as revision numbers) that were part of the
1629 command.
1629 command.
1630
1630
1631 5.4 HGCommand status line support *hgcommand-statusline*
1631 5.4 HGCommand status line support *hgcommand-statusline*
1632
1632
1633 It is intended that the user will customize the |'statusline'| option to
1633 It is intended that the user will customize the |'statusline'| option to
1634 include HG result buffer attributes. A sample function that may be used in
1634 include HG result buffer attributes. A sample function that may be used in
1635 the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In
1635 the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In
1636 order to use that function in the status line, do something like the
1636 order to use that function in the status line, do something like the
1637 following: >
1637 following: >
1638
1638
1639 set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
1639 set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
1640 <
1640 <
1641 of which %{HGGetStatusLine()} is the relevant portion.
1641 of which %{HGGetStatusLine()} is the relevant portion.
1642
1642
1643 The sample HGGetStatusLine() function handles both HG result buffers and
1643 The sample HGGetStatusLine() function handles both HG result buffers and
1644 HG-managed files if HGCommand buffer management is enabled (please see
1644 HG-managed files if HGCommand buffer management is enabled (please see
1645 |hgcommand-buffer-management|).
1645 |hgcommand-buffer-management|).
1646
1646
1647 5.5 HGCommand buffer management *hgcommand-buffer-management*
1647 5.5 HGCommand buffer management *hgcommand-buffer-management*
1648
1648
1649 The HGCommand plugin can operate in buffer management mode, which means
1649 The HGCommand plugin can operate in buffer management mode, which means
1650 that it attempts to set two buffer variables ('HGRevision' and 'HGBranch')
1650 that it attempts to set two buffer variables ('HGRevision' and 'HGBranch')
1651 upon entry into a buffer. This is rather slow because it means that 'hg
1651 upon entry into a buffer. This is rather slow because it means that 'hg
1652 status' will be invoked at each entry into a buffer (during the |BufEnter|
1652 status' will be invoked at each entry into a buffer (during the |BufEnter|
1653 autocommand).
1653 autocommand).
1654
1654
1655 This mode is enabled by default. In order to disable it, set the
1655 This mode is enabled by default. In order to disable it, set the
1656 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
1656 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
1657 this mode simply provides the buffer variables mentioned above. The user
1657 this mode simply provides the buffer variables mentioned above. The user
1658 must explicitly include those in the |'statusline'| option if they are to
1658 must explicitly include those in the |'statusline'| option if they are to
1659 appear in the status line (but see |hgcommand-statusline| for a simple way
1659 appear in the status line (but see |hgcommand-statusline| for a simple way
1660 to do that).
1660 to do that).
1661
1661
1662 ==============================================================================
1662 ==============================================================================
1663 9. Tips *hgcommand-tips*
1663 9. Tips *hgcommand-tips*
1664
1664
1665 9.1 Split window annotation, by Michael Anderson >
1665 9.1 Split window annotation, by Michael Anderson >
1666
1666
1667 :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR>
1667 :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR>
1668 \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>
1668 \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>
1669 \:set nowrap<CR>
1669 \:set nowrap<CR>
1670 <
1670 <
1671
1671
1672 This splits the buffer vertically, puts an annotation on the left (minus
1672 This splits the buffer vertically, puts an annotation on the left (minus
1673 the header) with the width set to 40. An editable/normal copy is placed on
1673 the header) with the width set to 40. An editable/normal copy is placed on
1674 the right. The two versions are scroll locked so they move as one. and
1674 the right. The two versions are scroll locked so they move as one. and
1675 wrapping is turned off so that the lines line up correctly. The advantages
1675 wrapping is turned off so that the lines line up correctly. The advantages
1676 are...
1676 are...
1677
1677
1678 1) You get a versioning on the right.
1678 1) You get a versioning on the right.
1679 2) You can still edit your own code.
1679 2) You can still edit your own code.
1680 3) Your own code still has syntax highlighting.
1680 3) Your own code still has syntax highlighting.
1681
1681
1682 ==============================================================================
1682 ==============================================================================
1683
1683
1684 8. Known bugs *hgcommand-bugs*
1684 8. Known bugs *hgcommand-bugs*
1685
1685
1686 Please let me know if you run across any.
1686 Please let me know if you run across any.
1687
1687
1688 HGVimDiff, when using the original (real) source buffer as one of the diff
1688 HGVimDiff, when using the original (real) source buffer as one of the diff
1689 buffers, uses some hacks to try to restore the state of the original buffer
1689 buffers, uses some hacks to try to restore the state of the original buffer
1690 when the scratch buffer containing the other version is destroyed. There
1690 when the scratch buffer containing the other version is destroyed. There
1691 may still be bugs in here, depending on many configuration details.
1691 may still be bugs in here, depending on many configuration details.
1692
1692
1693 ==============================================================================
1693 ==============================================================================
1694
1694
1695 9. TODO *hgcommand-todo*
1695 9. TODO *hgcommand-todo*
1696
1696
1697 Integrate symlink tracking once HG will support them.
1697 Integrate symlink tracking once HG will support them.
1698 ==============================================================================
1698 ==============================================================================
1699 === END_DOC
1699 === END_DOC
1700 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1700 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1701 " v im:tw=78:ts=8:ft=help:norl:
1701 " v im:tw=78:ts=8:ft=help:norl:
1702 " vim600: set foldmethod=marker tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab :
1702 " vim600: set foldmethod=marker tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab :
1703 "fileencoding=iso-8859-15
1703 "fileencoding=iso-8859-15
@@ -1,51 +1,51
1 <Include>
1 <Include>
2 <!-- These are component GUIDs used for Mercurial installers.
2 <!-- These are component GUIDs used for Mercurial installers.
3 YOU MUST CHANGE ALL GUIDs below when copying this file
3 YOU MUST CHANGE ALL GUIDs below when copying this file
4 and replace 'Mercurial' in this notice with the name of
4 and replace 'Mercurial' in this notice with the name of
5 your project. Component GUIDs have global namespace! -->
5 your project. Component GUIDs have global namespace! -->
6
6
7 <!-- contrib.wxs -->
7 <!-- contrib.wxs -->
8 <?define contrib.guid = {F17D27B7-4A6B-4cd2-AE72-FED3CFAA585E} ?>
8 <?define contrib.guid = {F17D27B7-4A6B-4cd2-AE72-FED3CFAA585E} ?>
9 <?define contrib.vim.guid = {BB04903A-652D-4C4F-9590-2BD07A2304F2} ?>
9 <?define contrib.vim.guid = {BB04903A-652D-4C4F-9590-2BD07A2304F2} ?>
10
10
11 <!-- dist.wxs -->
11 <!-- dist.wxs -->
12 <?define dist.guid = {C3B634A4-1B05-4A40-94A9-38EE853CF693} ?>
12 <?define dist.guid = {C3B634A4-1B05-4A40-94A9-38EE853CF693} ?>
13
13
14 <!-- doc.wxs -->
14 <!-- doc.wxs -->
15 <?define doc.hg.1.html.guid = {AAAA3FDA-EDC5-4220-B59D-D342722358A2} ?>
15 <?define doc.hg.1.html.guid = {AAAA3FDA-EDC5-4220-B59D-D342722358A2} ?>
16 <?define doc.hgignore.5.html.guid = {AA9118C4-F3A0-4429-A5F4-5A1906B2D67F} ?>
16 <?define doc.hgignore.5.html.guid = {AA9118C4-F3A0-4429-A5F4-5A1906B2D67F} ?>
17 <?define doc.hgrc.5.html = {E0CEA1EB-FA01-408c-844B-EE5965165BAE} ?>
17 <?define doc.hgrc.5.html = {E0CEA1EB-FA01-408c-844B-EE5965165BAE} ?>
18 <?define doc.style.css = {172F8262-98E0-4711-BD39-4DAE0D77EF05} ?>
18 <?define doc.style.css = {172F8262-98E0-4711-BD39-4DAE0D77EF05} ?>
19
19
20 <!-- help.wxs -->
20 <!-- help.wxs -->
21 <?define helpFolder.guid = {9FA957DB-6DFE-44f2-AD03-293B2791CF17} ?>
21 <?define helpFolder.guid = {9FA957DB-6DFE-44f2-AD03-293B2791CF17} ?>
22
22
23 <!-- i18n.wxs -->
23 <!-- i18n.wxs -->
24 <?define i18nFolder.guid = {1BF8026D-CF7C-4174-AEE6-D6B7BF119248} ?>
24 <?define i18nFolder.guid = {1BF8026D-CF7C-4174-AEE6-D6B7BF119248} ?>
25
25
26 <!-- templates.wxs -->
26 <!-- templates.wxs -->
27 <?define templates.root.guid = {8DF97574-33E9-412F-8414-65B48BB18783} ?>
27 <?define templates.root.guid = {8DF97574-33E9-412F-8414-65B48BB18783} ?>
28 <?define templates.atom.guid = {AB5D2908-BC95-44BE-9D79-069EF43D93E2} ?>
28 <?define templates.atom.guid = {AB5D2908-BC95-44BE-9D79-069EF43D93E2} ?>
29 <?define templates.coal.guid = {B63CCAAB-4EAF-43b4-901E-4BD13F5B78FC} ?>
29 <?define templates.coal.guid = {B63CCAAB-4EAF-43b4-901E-4BD13F5B78FC} ?>
30 <?define templates.gitweb.guid = {827334AF-1EFD-421B-962C-5660A068F612} ?>
30 <?define templates.gitweb.guid = {827334AF-1EFD-421B-962C-5660A068F612} ?>
31 <?define templates.monoblue.guid = {8060A1E4-BD4C-453E-92CB-9536DC44A9E3} ?>
31 <?define templates.monoblue.guid = {8060A1E4-BD4C-453E-92CB-9536DC44A9E3} ?>
32 <?define templates.paper.guid = {61AB1DE9-645F-46ED-8AF8-0CF02267FFBB} ?>
32 <?define templates.paper.guid = {61AB1DE9-645F-46ED-8AF8-0CF02267FFBB} ?>
33 <?define templates.raw.guid = {3F88E9B6-EA3C-41EB-8D8A-3F12E7DE9933} ?>
33 <?define templates.raw.guid = {3F88E9B6-EA3C-41EB-8D8A-3F12E7DE9933} ?>
34 <?define templates.rss.guid = {36069748-1E2A-472B-A212-506CB656A9C1} ?>
34 <?define templates.rss.guid = {36069748-1E2A-472B-A212-506CB656A9C1} ?>
35 <?define templates.spartan.guid = {80222625-FA8F-44b1-86CE-1781EF375D09} ?>
35 <?define templates.spartan.guid = {80222625-FA8F-44b1-86CE-1781EF375D09} ?>
36 <?define templates.static.guid = {B27D7311-050A-4A96-9971-B674A0EA21D0} ?>
36 <?define templates.static.guid = {B27D7311-050A-4A96-9971-B674A0EA21D0} ?>
37
37
38 <!-- mercurial.wxs -->
38 <!-- mercurial.wxs -->
39 <?define ProductUpgradeCode = {A1CC6134-E945-4399-BE36-EB0017FDF7CF} ?>
39 <?define ProductUpgradeCode = {A1CC6134-E945-4399-BE36-EB0017FDF7CF} ?>
40
40
41 <?define ComponentMainExecutableGUID = {D102B8FA-059B-4ACC-9FA3-8C78C3B58EEF} ?>
41 <?define ComponentMainExecutableGUID = {D102B8FA-059B-4ACC-9FA3-8C78C3B58EEF} ?>
42
42
43 <?define ReadMe.guid = {56A8E372-991D-4DCA-B91D-93D775974CF5} ?>
43 <?define ReadMe.guid = {56A8E372-991D-4DCA-B91D-93D775974CF5} ?>
44 <?define COPYING.guid = {B7801DBA-1C49-4BF4-91AD-33C65F5C7895} ?>
44 <?define COPYING.guid = {B7801DBA-1C49-4BF4-91AD-33C65F5C7895} ?>
45 <?define mercurial.rc.guid = {1D5FAEEE-7E6E-43B1-9F7F-802714316B15} ?>
45 <?define mercurial.rc.guid = {1D5FAEEE-7E6E-43B1-9F7F-802714316B15} ?>
46 <?define mergetools.rc.guid = {E8A1DC29-FF40-4B5F-BD12-80B9F7BF0CCD} ?>
46 <?define mergetools.rc.guid = {E8A1DC29-FF40-4B5F-BD12-80B9F7BF0CCD} ?>
47 <?define paths.rc.guid = {F9ADF21D-5F0B-4934-8CD9-14BE63664721} ?>
47 <?define paths.rc.guid = {F9ADF21D-5F0B-4934-8CD9-14BE63664721} ?>
48 <?define cacert.pem.guid = {EC1B2630-FE21-46E6-915B-A6545AF703D4} ?>
48 <?define cacert.pem.guid = {EC1B2630-FE21-46E6-915B-A6545AF703D4} ?>
49 <?define ProgramMenuDir.guid = {D5A63320-1238-489B-B68B-CF053E9577CA} ?>
49 <?define ProgramMenuDir.guid = {D5A63320-1238-489B-B68B-CF053E9577CA} ?>
50
50
51 </Include>
51 </Include>
@@ -1,26 +1,26
1 <?xml version="1.0" encoding="utf-8"?>
1 <?xml version="1.0" encoding="utf-8"?>
2 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
2 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3
3
4 <?include guids.wxi ?>
4 <?include guids.wxi ?>
5 <?include defines.wxi ?>
5 <?include defines.wxi ?>
6
6
7 <?define hg_po_langs =
7 <?define hg_po_langs =
8 da;de;el;fr;it;ja;pt_BR;ro;ru;sv;zh_CN;zh_TW
8 da;de;el;fr;it;ja;pt_BR;ro;ru;sv;zh_CN;zh_TW
9 ?>
9 ?>
10
10
11 <Fragment>
11 <Fragment>
12 <DirectoryRef Id="INSTALLDIR">
12 <DirectoryRef Id="INSTALLDIR">
13 <Directory Id="i18ndir" Name="i18n" FileSource="$(var.SourceDir)">
13 <Directory Id="i18ndir" Name="i18n" FileSource="$(var.SourceDir)">
14 <Component Id="i18nFolder" Guid="$(var.i18nFolder.guid)" Win64='$(var.IsX64)'>
14 <Component Id="i18nFolder" Guid="$(var.i18nFolder.guid)" Win64='$(var.IsX64)'>
15 <File Name="hggettext" KeyPath="yes" />
15 <File Name="hggettext" KeyPath="yes" />
16 <?foreach LANG in $(var.hg_po_langs) ?>
16 <?foreach LANG in $(var.hg_po_langs) ?>
17 <File Id="hg.$(var.LANG).po"
17 <File Id="hg.$(var.LANG).po"
18 Name="$(var.LANG).po"
18 Name="$(var.LANG).po"
19 />
19 />
20 <?endforeach?>
20 <?endforeach?>
21 </Component>
21 </Component>
22 </Directory>
22 </Directory>
23 </DirectoryRef>
23 </DirectoryRef>
24 </Fragment>
24 </Fragment>
25
25
26 </Wix>
26 </Wix>
@@ -1,172 +1,172
1 <?xml version='1.0' encoding='windows-1252'?>
1 <?xml version='1.0' encoding='windows-1252'?>
2 <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
2 <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
3
3
4 <!-- Copyright 2010 Steve Borho <steve@borho.org>
4 <!-- Copyright 2010 Steve Borho <steve@borho.org>
5
5
6 This software may be used and distributed according to the terms of the
6 This software may be used and distributed according to the terms of the
7 GNU General Public License version 2 or any later version. -->
7 GNU General Public License version 2 or any later version. -->
8
8
9 <?include guids.wxi ?>
9 <?include guids.wxi ?>
10 <?include defines.wxi ?>
10 <?include defines.wxi ?>
11
11
12 <?if $(var.Platform) = "x64" ?>
12 <?if $(var.Platform) = "x64" ?>
13 <?define PFolder = ProgramFiles64Folder ?>
13 <?define PFolder = ProgramFiles64Folder ?>
14 <?else?>
14 <?else?>
15 <?define PFolder = ProgramFilesFolder ?>
15 <?define PFolder = ProgramFilesFolder ?>
16 <?endif?>
16 <?endif?>
17
17
18 <Product Id='*'
18 <Product Id='*'
19 Name='Mercurial $(var.Version) ($(var.Platform))'
19 Name='Mercurial $(var.Version) ($(var.Platform))'
20 UpgradeCode='$(var.ProductUpgradeCode)'
20 UpgradeCode='$(var.ProductUpgradeCode)'
21 Language='1033' Codepage='1252' Version='$(var.Version)'
21 Language='1033' Codepage='1252' Version='$(var.Version)'
22 Manufacturer='Matt Mackall and others'>
22 Manufacturer='Matt Mackall and others'>
23
23
24 <Package Id='*'
24 <Package Id='*'
25 Keywords='Installer'
25 Keywords='Installer'
26 Description="Mercurial distributed SCM (version $(var.Version))"
26 Description="Mercurial distributed SCM (version $(var.Version))"
27 Comments='$(var.Comments)'
27 Comments='$(var.Comments)'
28 Platform='$(var.Platform)'
28 Platform='$(var.Platform)'
29 Manufacturer='Matt Mackall and others'
29 Manufacturer='Matt Mackall and others'
30 InstallerVersion='300' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
30 InstallerVersion='300' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
31
31
32 <Media Id='1' Cabinet='mercurial.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1'
32 <Media Id='1' Cabinet='mercurial.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1'
33 CompressionLevel='high' />
33 CompressionLevel='high' />
34 <Property Id='DiskPrompt' Value="Mercurial $(var.Version) Installation [1]" />
34 <Property Id='DiskPrompt' Value="Mercurial $(var.Version) Installation [1]" />
35
35
36 <Condition Message='Mercurial MSI installers require Windows XP or higher'>
36 <Condition Message='Mercurial MSI installers require Windows XP or higher'>
37 VersionNT >= 501
37 VersionNT >= 501
38 </Condition>
38 </Condition>
39
39
40 <Property Id="INSTALLDIR">
40 <Property Id="INSTALLDIR">
41 <ComponentSearch Id='SearchForMainExecutableComponent'
41 <ComponentSearch Id='SearchForMainExecutableComponent'
42 Guid='$(var.ComponentMainExecutableGUID)' />
42 Guid='$(var.ComponentMainExecutableGUID)' />
43 </Property>
43 </Property>
44
44
45 <!--Property Id='ARPCOMMENTS'>any comments</Property-->
45 <!--Property Id='ARPCOMMENTS'>any comments</Property-->
46 <Property Id='ARPCONTACT'>mercurial@selenic.com</Property>
46 <Property Id='ARPCONTACT'>mercurial@selenic.com</Property>
47 <Property Id='ARPHELPLINK'>http://mercurial.selenic.com/wiki/</Property>
47 <Property Id='ARPHELPLINK'>http://mercurial.selenic.com/wiki/</Property>
48 <Property Id='ARPURLINFOABOUT'>http://mercurial.selenic.com/about/</Property>
48 <Property Id='ARPURLINFOABOUT'>http://mercurial.selenic.com/about/</Property>
49 <Property Id='ARPURLUPDATEINFO'>http://mercurial.selenic.com/downloads/</Property>
49 <Property Id='ARPURLUPDATEINFO'>http://mercurial.selenic.com/downloads/</Property>
50 <Property Id='ARPHELPTELEPHONE'>http://mercurial.selenic.com/wiki/Support</Property>
50 <Property Id='ARPHELPTELEPHONE'>http://mercurial.selenic.com/wiki/Support</Property>
51 <Property Id='ARPPRODUCTICON'>hgIcon.ico</Property>
51 <Property Id='ARPPRODUCTICON'>hgIcon.ico</Property>
52
52
53 <Property Id='INSTALLEDMERCURIALPRODUCTS' Secure='yes'></Property>
53 <Property Id='INSTALLEDMERCURIALPRODUCTS' Secure='yes'></Property>
54 <Property Id='REINSTALLMODE'>amus</Property>
54 <Property Id='REINSTALLMODE'>amus</Property>
55
55
56 <!--Auto-accept the license page-->
56 <!--Auto-accept the license page-->
57 <Property Id='LicenseAccepted'>1</Property>
57 <Property Id='LicenseAccepted'>1</Property>
58
58
59 <Directory Id='TARGETDIR' Name='SourceDir'>
59 <Directory Id='TARGETDIR' Name='SourceDir'>
60 <Directory Id='$(var.PFolder)' Name='PFiles'>
60 <Directory Id='$(var.PFolder)' Name='PFiles'>
61 <Directory Id='INSTALLDIR' Name='Mercurial'>
61 <Directory Id='INSTALLDIR' Name='Mercurial'>
62 <Component Id='MainExecutable' Guid='$(var.ComponentMainExecutableGUID)' Win64='$(var.IsX64)'>
62 <Component Id='MainExecutable' Guid='$(var.ComponentMainExecutableGUID)' Win64='$(var.IsX64)'>
63 <File Id='hgEXE' Name='hg.exe' Source='dist\hg.exe' KeyPath='yes' />
63 <File Id='hgEXE' Name='hg.exe' Source='dist\hg.exe' KeyPath='yes' />
64 <Environment Id="Environment" Name="PATH" Part="last" System="yes"
64 <Environment Id="Environment" Name="PATH" Part="last" System="yes"
65 Permanent="no" Value="[INSTALLDIR]" Action="set" />
65 Permanent="no" Value="[INSTALLDIR]" Action="set" />
66 </Component>
66 </Component>
67 <Component Id='ReadMe' Guid='$(var.ReadMe.guid)' Win64='$(var.IsX64)'>
67 <Component Id='ReadMe' Guid='$(var.ReadMe.guid)' Win64='$(var.IsX64)'>
68 <File Id='ReadMe' Name='ReadMe.html' Source='contrib\win32\ReadMe.html'
68 <File Id='ReadMe' Name='ReadMe.html' Source='contrib\win32\ReadMe.html'
69 KeyPath='yes'/>
69 KeyPath='yes'/>
70 </Component>
70 </Component>
71 <Component Id='COPYING' Guid='$(var.COPYING.guid)' Win64='$(var.IsX64)'>
71 <Component Id='COPYING' Guid='$(var.COPYING.guid)' Win64='$(var.IsX64)'>
72 <File Id='COPYING' Name='COPYING.rtf' Source='contrib\wix\COPYING.rtf'
72 <File Id='COPYING' Name='COPYING.rtf' Source='contrib\wix\COPYING.rtf'
73 KeyPath='yes'/>
73 KeyPath='yes'/>
74 </Component>
74 </Component>
75
75
76 <Directory Id='HGRCD' Name='hgrc.d'>
76 <Directory Id='HGRCD' Name='hgrc.d'>
77 <Component Id='mercurial.rc' Guid='$(var.mercurial.rc.guid)' Win64='$(var.IsX64)'>
77 <Component Id='mercurial.rc' Guid='$(var.mercurial.rc.guid)' Win64='$(var.IsX64)'>
78 <File Id='mercurial.rc' Name='Mercurial.rc' Source='contrib\win32\mercurial.ini'
78 <File Id='mercurial.rc' Name='Mercurial.rc' Source='contrib\win32\mercurial.ini'
79 ReadOnly='yes' KeyPath='yes'/>
79 ReadOnly='yes' KeyPath='yes'/>
80 </Component>
80 </Component>
81 <Component Id='mergetools.rc' Guid='$(var.mergetools.rc.guid)' Win64='$(var.IsX64)'>
81 <Component Id='mergetools.rc' Guid='$(var.mergetools.rc.guid)' Win64='$(var.IsX64)'>
82 <File Id='mergetools.rc' Name='MergeTools.rc' Source='contrib\mergetools.hgrc'
82 <File Id='mergetools.rc' Name='MergeTools.rc' Source='contrib\mergetools.hgrc'
83 ReadOnly='yes' KeyPath='yes'/>
83 ReadOnly='yes' KeyPath='yes'/>
84 </Component>
84 </Component>
85 <Component Id='paths.rc' Guid='$(var.paths.rc.guid)' Win64='$(var.IsX64)'>
85 <Component Id='paths.rc' Guid='$(var.paths.rc.guid)' Win64='$(var.IsX64)'>
86 <CreateFolder/>
86 <CreateFolder/>
87 <IniFile Id="ini0" Action="createLine" Directory="HGRCD" Name="Paths.rc"
87 <IniFile Id="ini0" Action="createLine" Directory="HGRCD" Name="Paths.rc"
88 Section="web" Key="cacerts" Value="[INSTALLDIR]hgrc.d\cacert.pem" />
88 Section="web" Key="cacerts" Value="[INSTALLDIR]hgrc.d\cacert.pem" />
89 </Component>
89 </Component>
90 <Component Id='cacert.pem' Guid='$(var.cacert.pem.guid)' Win64='$(var.IsX64)'>
90 <Component Id='cacert.pem' Guid='$(var.cacert.pem.guid)' Win64='$(var.IsX64)'>
91 <File Id='cacert.pem' Name='cacert.pem' Source='..\misc\cacert.pem'
91 <File Id='cacert.pem' Name='cacert.pem' Source='..\misc\cacert.pem'
92 ReadOnly='yes' KeyPath='yes'/>
92 ReadOnly='yes' KeyPath='yes'/>
93 </Component>
93 </Component>
94 </Directory>
94 </Directory>
95
95
96 </Directory>
96 </Directory>
97 </Directory>
97 </Directory>
98
98
99 <Directory Id="ProgramMenuFolder" Name="Programs">
99 <Directory Id="ProgramMenuFolder" Name="Programs">
100 <Directory Id="ProgramMenuDir" Name="Mercurial $(var.Version)">
100 <Directory Id="ProgramMenuDir" Name="Mercurial $(var.Version)">
101 <Component Id="ProgramMenuDir" Guid="$(var.ProgramMenuDir.guid)" Win64='$(var.IsX64)'>
101 <Component Id="ProgramMenuDir" Guid="$(var.ProgramMenuDir.guid)" Win64='$(var.IsX64)'>
102 <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
102 <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
103 <RegistryValue Root='HKCU' Key='Software\Mercurial\InstallDir' Type='string'
103 <RegistryValue Root='HKCU' Key='Software\Mercurial\InstallDir' Type='string'
104 Value='[INSTALLDIR]' KeyPath='yes' />
104 Value='[INSTALLDIR]' KeyPath='yes' />
105 <Shortcut Id='UrlShortcut' Directory='ProgramMenuDir' Name='Mercurial Web Site'
105 <Shortcut Id='UrlShortcut' Directory='ProgramMenuDir' Name='Mercurial Web Site'
106 Target='[ARPHELPLINK]' Icon="hgIcon.ico" IconIndex='0' />
106 Target='[ARPHELPLINK]' Icon="hgIcon.ico" IconIndex='0' />
107 </Component>
107 </Component>
108 </Directory>
108 </Directory>
109 </Directory>
109 </Directory>
110
110
111 <?if $(var.Platform) = "x86" ?>
111 <?if $(var.Platform) = "x86" ?>
112 <Merge Id='VCRuntime' DiskId='1' Language='1033'
112 <Merge Id='VCRuntime' DiskId='1' Language='1033'
113 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x86_msm.msm' />
113 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x86_msm.msm' />
114 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
114 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
115 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x86_msm.msm' />
115 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x86_msm.msm' />
116 <?else?>
116 <?else?>
117 <Merge Id='VCRuntime' DiskId='1' Language='1033'
117 <Merge Id='VCRuntime' DiskId='1' Language='1033'
118 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x64_msm.msm' />
118 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x64_msm.msm' />
119 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
119 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
120 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x64_msm.msm' />
120 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x64_msm.msm' />
121 <?endif?>
121 <?endif?>
122 </Directory>
122 </Directory>
123
123
124 <Feature Id='Complete' Title='Mercurial' Description='The complete package'
124 <Feature Id='Complete' Title='Mercurial' Description='The complete package'
125 Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR' >
125 Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR' >
126 <Feature Id='MainProgram' Title='Program' Description='Mercurial command line app'
126 <Feature Id='MainProgram' Title='Program' Description='Mercurial command line app'
127 Level='1' Absent='disallow' >
127 Level='1' Absent='disallow' >
128 <ComponentRef Id='MainExecutable' />
128 <ComponentRef Id='MainExecutable' />
129 <ComponentRef Id='distOutput' />
129 <ComponentRef Id='distOutput' />
130 <ComponentRef Id='ProgramMenuDir' />
130 <ComponentRef Id='ProgramMenuDir' />
131 <ComponentRef Id='ReadMe' />
131 <ComponentRef Id='ReadMe' />
132 <ComponentRef Id='COPYING' />
132 <ComponentRef Id='COPYING' />
133 <ComponentRef Id='mercurial.rc' />
133 <ComponentRef Id='mercurial.rc' />
134 <ComponentRef Id='mergetools.rc' />
134 <ComponentRef Id='mergetools.rc' />
135 <ComponentRef Id='paths.rc' />
135 <ComponentRef Id='paths.rc' />
136 <ComponentRef Id='cacert.pem' />
136 <ComponentRef Id='cacert.pem' />
137 <ComponentRef Id='helpFolder' />
137 <ComponentRef Id='helpFolder' />
138 <ComponentGroupRef Id='templatesFolder' />
138 <ComponentGroupRef Id='templatesFolder' />
139 <MergeRef Id='VCRuntime' />
139 <MergeRef Id='VCRuntime' />
140 <MergeRef Id='VCRuntimePolicy' />
140 <MergeRef Id='VCRuntimePolicy' />
141 </Feature>
141 </Feature>
142 <Feature Id='Locales' Title='Translations' Description='Translations' Level='1'>
142 <Feature Id='Locales' Title='Translations' Description='Translations' Level='1'>
143 <ComponentGroupRef Id='localeFolder' />
143 <ComponentGroupRef Id='localeFolder' />
144 <ComponentRef Id='i18nFolder' />
144 <ComponentRef Id='i18nFolder' />
145 </Feature>
145 </Feature>
146 <Feature Id='Documentation' Title='Documentation' Description='HTML man pages' Level='1'>
146 <Feature Id='Documentation' Title='Documentation' Description='HTML man pages' Level='1'>
147 <ComponentGroupRef Id='docFolder' />
147 <ComponentGroupRef Id='docFolder' />
148 </Feature>
148 </Feature>
149 <Feature Id='Misc' Title='Miscellaneous' Description='Contributed scripts' Level='1'>
149 <Feature Id='Misc' Title='Miscellaneous' Description='Contributed scripts' Level='1'>
150 <ComponentGroupRef Id='contribFolder' />
150 <ComponentGroupRef Id='contribFolder' />
151 </Feature>
151 </Feature>
152 </Feature>
152 </Feature>
153
153
154 <UIRef Id="WixUI_FeatureTree" />
154 <UIRef Id="WixUI_FeatureTree" />
155 <UIRef Id="WixUI_ErrorProgressText" />
155 <UIRef Id="WixUI_ErrorProgressText" />
156
156
157 <WixVariable Id="WixUILicenseRtf" Value="contrib\wix\COPYING.rtf" />
157 <WixVariable Id="WixUILicenseRtf" Value="contrib\wix\COPYING.rtf" />
158
158
159 <Icon Id="hgIcon.ico" SourceFile="contrib/win32/mercurial.ico" />
159 <Icon Id="hgIcon.ico" SourceFile="contrib/win32/mercurial.ico" />
160
160
161 <Upgrade Id='$(var.ProductUpgradeCode)'>
161 <Upgrade Id='$(var.ProductUpgradeCode)'>
162 <UpgradeVersion
162 <UpgradeVersion
163 IncludeMinimum='yes' Minimum='0.0.0' IncludeMaximum='no' OnlyDetect='no'
163 IncludeMinimum='yes' Minimum='0.0.0' IncludeMaximum='no' OnlyDetect='no'
164 Property='INSTALLEDMERCURIALPRODUCTS' />
164 Property='INSTALLEDMERCURIALPRODUCTS' />
165 </Upgrade>
165 </Upgrade>
166
166
167 <InstallExecuteSequence>
167 <InstallExecuteSequence>
168 <RemoveExistingProducts After='InstallInitialize'/>
168 <RemoveExistingProducts After='InstallInitialize'/>
169 </InstallExecuteSequence>
169 </InstallExecuteSequence>
170
170
171 </Product>
171 </Product>
172 </Wix>
172 </Wix>
@@ -1,309 +1,309
1 /*
1 /*
2 * Styles for man pages, which match with http://mercurial.selenic.com/
2 * Styles for man pages, which match with http://mercurial.selenic.com/
3 *
3 *
4 * Color scheme & layout are borrowed from
4 * Color scheme & layout are borrowed from
5 * http://mercurial.selenic.com/css/styles.css
5 * http://mercurial.selenic.com/css/styles.css
6 *
6 *
7 * Some styles are from html4css1.css from Docutils, which is in the
7 * Some styles are from html4css1.css from Docutils, which is in the
8 * public domain.
8 * public domain.
9 */
9 */
10
10
11 body {
11 body {
12 margin: 0;
12 margin: 0;
13 padding: 0;
13 padding: 0;
14 font-family: sans-serif;
14 font-family: sans-serif;
15 }
15 }
16
16
17 .document {
17 .document {
18 position: relative; /* be a top of absolute positioning */
18 position: relative; /* be a top of absolute positioning */
19 margin: 1.5em 1.8em;
19 margin: 1.5em 1.8em;
20 padding: 0;
20 padding: 0;
21 line-height: 1.3;
21 line-height: 1.3;
22 }
22 }
23
23
24 /* layout: toc to right */
24 /* layout: toc to right */
25 #contents {
25 #contents {
26 position: absolute;
26 position: absolute;
27 right: 0;
27 right: 0;
28 top: 0;
28 top: 0;
29 width: 26%;
29 width: 26%;
30 }
30 }
31
31
32 /* layout: others to left */
32 /* layout: others to left */
33 h1.title, h2.subtitle, .section { width: 72%; }
33 h1.title, h2.subtitle, .section { width: 72%; }
34 .section .section { width: auto; }
34 .section .section { width: auto; }
35 table.docinfo { max-width: 72%; }
35 table.docinfo { max-width: 72%; }
36
36
37 /* headings */
37 /* headings */
38 h1, h2, .topic-title, .admonition-title {
38 h1, h2, .topic-title, .admonition-title {
39 font-family: "MgOpen Cosmetica", "Lucida Sans Unicode", sans-serif;
39 font-family: "MgOpen Cosmetica", "Lucida Sans Unicode", sans-serif;
40 font-weight: normal;
40 font-weight: normal;
41 }
41 }
42 h1, h2, .topic-title, .admonition-title {
42 h1, h2, .topic-title, .admonition-title {
43 margin: 1em 0 0.5em;
43 margin: 1em 0 0.5em;
44 }
44 }
45 h1.title { font-size: 300%; }
45 h1.title { font-size: 300%; }
46 h2.subtitle, h1 { font-size: 200%; }
46 h2.subtitle, h1 { font-size: 200%; }
47 h2, .topic-title, .admonition-title { font-size: 140%; }
47 h2, .topic-title, .admonition-title { font-size: 140%; }
48
48
49 /* subtitle starts with lowercase in man pages, but not in HTML */
49 /* subtitle starts with lowercase in man pages, but not in HTML */
50 h2.subtitle:first-letter { text-transform: uppercase; }
50 h2.subtitle:first-letter { text-transform: uppercase; }
51
51
52 /* override first/last margin */
52 /* override first/last margin */
53 .first, h1.title, h2.subtitle { margin-top: 0 !important; }
53 .first, h1.title, h2.subtitle { margin-top: 0 !important; }
54 .last, .with-subtitle { margin-bottom: 0 !important; }
54 .last, .with-subtitle { margin-bottom: 0 !important; }
55
55
56 blockquote, pre, dd .option-list, .field-list {
56 blockquote, pre, dd .option-list, .field-list {
57 margin: 0.2em 0 1em 2em;
57 margin: 0.2em 0 1em 2em;
58 }
58 }
59
59
60 kbd, tt, pre { font-family: monospace; }
60 kbd, tt, pre { font-family: monospace; }
61
61
62 dt { font-weight: bold; }
62 dt { font-weight: bold; }
63 dd { margin-bottom: 0.5em; }
63 dd { margin-bottom: 0.5em; }
64
64
65 th, td { padding: 0.1em 0.2em; border: 0 none; }
65 th, td { padding: 0.1em 0.2em; border: 0 none; }
66 th { font-weight: bold; text-align: left; }
66 th { font-weight: bold; text-align: left; }
67
67
68 a:link, a:visited { text-decoration: underline; }
68 a:link, a:visited { text-decoration: underline; }
69 a:hover, a:focus { text-decoration: none; }
69 a:hover, a:focus { text-decoration: none; }
70 a:link { color: #00b5f1; }
70 a:link { color: #00b5f1; }
71 a:visited { color: #5c9caf; }
71 a:visited { color: #5c9caf; }
72 a:link.toc-backref, a:visited.toc-backref {
72 a:link.toc-backref, a:visited.toc-backref {
73 text-decoration: none;
73 text-decoration: none;
74 color: inherit; /* NOTE: `inherit' is not supported by IE6 */
74 color: inherit; /* NOTE: `inherit' is not supported by IE6 */
75 }
75 }
76
76
77 div.admonition, div.attention, div.caution,
77 div.admonition, div.attention, div.caution,
78 div.danger, div.error, div.hint, div.important,
78 div.danger, div.error, div.hint, div.important,
79 div.note, div.tip, div.warning {
79 div.note, div.tip, div.warning {
80 border-top: 1px #ccc solid;
80 border-top: 1px #ccc solid;
81 border-bottom: 1px #ccc solid;
81 border-bottom: 1px #ccc solid;
82 padding: 0.3em 1em;
82 padding: 0.3em 1em;
83 margin: 1em;
83 margin: 1em;
84 }
84 }
85
85
86 div.note {
86 div.note {
87 border-color: #fcc200;
87 border-color: #fcc200;
88 }
88 }
89
89
90
90
91 /*
91 /*
92 * The following styles are from Docutils.
92 * The following styles are from Docutils.
93 * Please refine if necessary.
93 * Please refine if necessary.
94 */
94 */
95
95
96 table.borderless td, table.borderless th {
96 table.borderless td, table.borderless th {
97 /* Override padding for "table.docutils td" with "! important".
97 /* Override padding for "table.docutils td" with "! important".
98 The right padding separates the table cells. */
98 The right padding separates the table cells. */
99 padding: 0 0.5em 0 0 ! important;
99 padding: 0 0.5em 0 0 ! important;
100 }
100 }
101
101
102 .hidden {
102 .hidden {
103 display: none;
103 display: none;
104 }
104 }
105
105
106 blockquote.epigraph {
106 blockquote.epigraph {
107 margin: 2em 5em;
107 margin: 2em 5em;
108 }
108 }
109
109
110 div.abstract {
110 div.abstract {
111 margin: 2em 5em;
111 margin: 2em 5em;
112 }
112 }
113
113
114 div.dedication {
114 div.dedication {
115 margin: 2em 5em;
115 margin: 2em 5em;
116 text-align: center;
116 text-align: center;
117 font-style: italic;
117 font-style: italic;
118 }
118 }
119
119
120 div.figure {
120 div.figure {
121 margin-left: 2em;
121 margin-left: 2em;
122 margin-right: 2em;
122 margin-right: 2em;
123 }
123 }
124
124
125 div.footer, div.header {
125 div.footer, div.header {
126 clear: both;
126 clear: both;
127 font-size: smaller;
127 font-size: smaller;
128 }
128 }
129
129
130 div.line-block {
130 div.line-block {
131 display: block;
131 display: block;
132 margin-top: 1em;
132 margin-top: 1em;
133 margin-bottom: 1em;
133 margin-bottom: 1em;
134 }
134 }
135
135
136 div.line-block div.line-block {
136 div.line-block div.line-block {
137 margin-top: 0;
137 margin-top: 0;
138 margin-bottom: 0;
138 margin-bottom: 0;
139 margin-left: 1.5em;
139 margin-left: 1.5em;
140 }
140 }
141
141
142 div.sidebar {
142 div.sidebar {
143 margin: 0 0 0.5em 1em;
143 margin: 0 0 0.5em 1em;
144 border: medium outset;
144 border: medium outset;
145 padding: 1em;
145 padding: 1em;
146 background-color: #ffffee;
146 background-color: #ffffee;
147 width: 40%;
147 width: 40%;
148 float: right;
148 float: right;
149 clear: right;
149 clear: right;
150 }
150 }
151
151
152 div.sidebar p.rubric {
152 div.sidebar p.rubric {
153 font-family: sans-serif;
153 font-family: sans-serif;
154 font-size: medium;
154 font-size: medium;
155 }
155 }
156
156
157 div.system-messages {
157 div.system-messages {
158 margin: 5em;
158 margin: 5em;
159 }
159 }
160
160
161 div.system-messages h1 {
161 div.system-messages h1 {
162 color: red;
162 color: red;
163 }
163 }
164
164
165 div.system-message {
165 div.system-message {
166 border: medium outset;
166 border: medium outset;
167 padding: 1em;
167 padding: 1em;
168 }
168 }
169
169
170 div.system-message p.system-message-title {
170 div.system-message p.system-message-title {
171 color: red;
171 color: red;
172 font-weight: bold;
172 font-weight: bold;
173 }
173 }
174
174
175 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
175 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
176 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
176 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
177 margin-top: 0.4em;
177 margin-top: 0.4em;
178 }
178 }
179
179
180 hr.docutils {
180 hr.docutils {
181 width: 75%;
181 width: 75%;
182 }
182 }
183
183
184 img.align-left {
184 img.align-left {
185 clear: left;
185 clear: left;
186 }
186 }
187
187
188 img.align-right {
188 img.align-right {
189 clear: right;
189 clear: right;
190 }
190 }
191
191
192 ol.simple, ul.simple {
192 ol.simple, ul.simple {
193 margin-bottom: 1em;
193 margin-bottom: 1em;
194 }
194 }
195
195
196 ol.arabic {
196 ol.arabic {
197 list-style: decimal;
197 list-style: decimal;
198 }
198 }
199
199
200 ol.loweralpha {
200 ol.loweralpha {
201 list-style: lower-alpha;
201 list-style: lower-alpha;
202 }
202 }
203
203
204 ol.upperalpha {
204 ol.upperalpha {
205 list-style: upper-alpha;
205 list-style: upper-alpha;
206 }
206 }
207
207
208 ol.lowerroman {
208 ol.lowerroman {
209 list-style: lower-roman;
209 list-style: lower-roman;
210 }
210 }
211
211
212 ol.upperroman {
212 ol.upperroman {
213 list-style: upper-roman;
213 list-style: upper-roman;
214 }
214 }
215
215
216 p.attribution {
216 p.attribution {
217 text-align: right;
217 text-align: right;
218 margin-left: 50%;
218 margin-left: 50%;
219 }
219 }
220
220
221 p.caption {
221 p.caption {
222 font-style: italic;
222 font-style: italic;
223 }
223 }
224
224
225 p.credits {
225 p.credits {
226 font-style: italic;
226 font-style: italic;
227 font-size: smaller;
227 font-size: smaller;
228 }
228 }
229
229
230 p.label {
230 p.label {
231 white-space: nowrap;
231 white-space: nowrap;
232 }
232 }
233
233
234 p.rubric {
234 p.rubric {
235 font-weight: bold;
235 font-weight: bold;
236 font-size: larger;
236 font-size: larger;
237 color: maroon;
237 color: maroon;
238 text-align: center;
238 text-align: center;
239 }
239 }
240
240
241 pre.address {
241 pre.address {
242 margin-bottom: 0;
242 margin-bottom: 0;
243 margin-top: 0;
243 margin-top: 0;
244 font-family: serif;
244 font-family: serif;
245 font-size: 100%;
245 font-size: 100%;
246 }
246 }
247
247
248 pre.literal-block, pre.doctest-block {
248 pre.literal-block, pre.doctest-block {
249 margin-left: 2em;
249 margin-left: 2em;
250 margin-right: 2em;
250 margin-right: 2em;
251 }
251 }
252
252
253 span.classifier {
253 span.classifier {
254 font-family: sans-serif;
254 font-family: sans-serif;
255 font-style: oblique;
255 font-style: oblique;
256 }
256 }
257
257
258 span.classifier-delimiter {
258 span.classifier-delimiter {
259 font-family: sans-serif;
259 font-family: sans-serif;
260 font-weight: bold;
260 font-weight: bold;
261 }
261 }
262
262
263 span.interpreted {
263 span.interpreted {
264 font-family: sans-serif;
264 font-family: sans-serif;
265 }
265 }
266
266
267 span.option {
267 span.option {
268 white-space: nowrap;
268 white-space: nowrap;
269 }
269 }
270
270
271 span.pre {
271 span.pre {
272 white-space: pre;
272 white-space: pre;
273 }
273 }
274
274
275 span.problematic {
275 span.problematic {
276 color: red;
276 color: red;
277 }
277 }
278
278
279 span.section-subtitle {
279 span.section-subtitle {
280 /* font-size relative to parent (h1..h6 element) */
280 /* font-size relative to parent (h1..h6 element) */
281 font-size: 80%;
281 font-size: 80%;
282 }
282 }
283
283
284 table.citation {
284 table.citation {
285 border-left: solid 1px gray;
285 border-left: solid 1px gray;
286 margin-left: 1px;
286 margin-left: 1px;
287 }
287 }
288
288
289 table.footnote {
289 table.footnote {
290 border-left: solid 1px black;
290 border-left: solid 1px black;
291 margin-left: 1px;
291 margin-left: 1px;
292 }
292 }
293
293
294 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
294 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
295 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
295 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
296 font-size: 100%;
296 font-size: 100%;
297 }
297 }
298
298
299 ul.auto-toc {
299 ul.auto-toc {
300 list-style-type: none;
300 list-style-type: none;
301 }
301 }
302
302
303 div.contents.local {
303 div.contents.local {
304 -moz-column-width: 10em;
304 -moz-column-width: 10em;
305 -moz-column-gap: 1em;
305 -moz-column-gap: 1em;
306
306
307 -webkit-column-width: 10em;
307 -webkit-column-width: 10em;
308 -webkit-column-gap: 1em;
308 -webkit-column-gap: 1em;
309 }
309 }
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now