##// 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 1 #!/usr/bin/env wish
2 2
3 3 # Copyright (C) 2005 Paul Mackerras. All rights reserved.
4 4 # This program is free software; it may be used, copied, modified
5 5 # and distributed under the terms of the GNU General Public Licence,
6 6 # either version 2, or (at your option) any later version.
7 7 #
8 8 # See hgk.py for extension usage and configuration.
9 9
10 10
11 11 # Modified version of Tip 171:
12 12 # http://www.tcl.tk/cgi-bin/tct/tip/171.html
13 13 #
14 14 # The in_mousewheel global was added to fix strange reentrancy issues.
15 15 # The whole snipped is activated only under windows, mouse wheel
16 16 # bindings working already under MacOSX and Linux.
17 17
18 18 if {[catch {package require Ttk}]} {
19 19 # use a shim
20 20 namespace eval ttk {
21 21 proc style args {}
22 22
23 23 proc entry args {
24 24 eval [linsert $args 0 ::entry] -relief flat
25 25 }
26 26 }
27 27
28 28 interp alias {} ttk::button {} button
29 29 interp alias {} ttk::frame {} frame
30 30 interp alias {} ttk::label {} label
31 31 interp alias {} ttk::scrollbar {} scrollbar
32 32 interp alias {} ttk::optionMenu {} tk_optionMenu
33 33
34 34 proc updatepalette {} {}
35 35 } else {
36 36 proc ::ttk::optionMenu {w varName firstValue args} {
37 37 upvar #0 $varName var
38 38
39 39 if {![info exists var]} {
40 40 set var $firstValue
41 41 }
42 42 ttk::menubutton $w -textvariable $varName -menu $w.menu \
43 43 -direction flush
44 44 menu $w.menu -tearoff 0
45 45 $w.menu add radiobutton -label $firstValue -variable $varName
46 46 foreach i $args {
47 47 $w.menu add radiobutton -label $i -variable $varName
48 48 }
49 49 return $w.menu
50 50 }
51 51 proc updatepalette {} {
52 52 catch {
53 53 tk_setPalette background [ttk::style lookup client -background]
54 54 }
55 55 }
56 56 }
57 57
58 58 if {[tk windowingsystem] eq "win32"} {
59 59
60 60 ttk::style theme use xpnative
61 61
62 62 set mw_classes [list Text Listbox Table TreeCtrl]
63 63 foreach class $mw_classes { bind $class <MouseWheel> {} }
64 64
65 65 set in_mousewheel 0
66 66
67 67 proc ::tk::MouseWheel {wFired X Y D {shifted 0}} {
68 68 global in_mousewheel
69 69 if { $in_mousewheel != 0 } { return }
70 70 # Set event to check based on call
71 71 set evt "<[expr {$shifted?{Shift-}:{}}]MouseWheel>"
72 72 # do not double-fire in case the class already has a binding
73 73 if {[bind [winfo class $wFired] $evt] ne ""} { return }
74 74 # obtain the window the mouse is over
75 75 set w [winfo containing $X $Y]
76 76 # if we are outside the app, try and scroll the focus widget
77 77 if {![winfo exists $w]} { catch {set w [focus]} }
78 78 if {[winfo exists $w]} {
79 79
80 80 if {[bind $w $evt] ne ""} {
81 81 # Awkward ... this widget has a MouseWheel binding, but to
82 82 # trigger successfully in it, we must give it focus.
83 83 catch {focus} old
84 84 if {$w ne $old} { focus $w }
85 85 set in_mousewheel 1
86 86 event generate $w $evt -rootx $X -rooty $Y -delta $D
87 87 set in_mousewheel 0
88 88 if {$w ne $old} { focus $old }
89 89 return
90 90 }
91 91
92 92 # aqua and x11/win32 have different delta handling
93 93 if {[tk windowingsystem] ne "aqua"} {
94 94 set delta [expr {- ($D / 30)}]
95 95 } else {
96 96 set delta [expr {- ($D)}]
97 97 }
98 98 # scrollbars have different call conventions
99 99 if {[string match "*Scrollbar" [winfo class $w]]} {
100 100 catch {tk::ScrollByUnits $w \
101 101 [string index [$w cget -orient] 0] $delta}
102 102 } else {
103 103 set cmd [list $w [expr {$shifted ? "xview" : "yview"}] \
104 104 scroll $delta units]
105 105 # Walking up to find the proper widget (handles cases like
106 106 # embedded widgets in a canvas)
107 107 while {[catch $cmd] && [winfo toplevel $w] ne $w} {
108 108 set w [winfo parent $w]
109 109 }
110 110 }
111 111 }
112 112 }
113 113
114 114 bind all <MouseWheel> [list ::tk::MouseWheel %W %X %Y %D 0]
115 115
116 116 # end of win32 section
117 117 } else {
118 118
119 119 if {[catch {
120 120 set theme [ttk::style theme use]
121 121 }]} {
122 122 set theme $::ttk::currentTheme
123 123 }
124 124 if {$theme eq "default"} {
125 125 ttk::style theme use clam
126 126 }
127 127
128 128 }
129 129
130 130 updatepalette
131 131
132 132 # Unify right mouse button handling.
133 133 # See "mouse buttons on macintosh" thread on comp.lang.tcl
134 134 if {[tk windowingsystem] eq "aqua"} {
135 135 event add <<B3>> <Control-ButtonPress-1>
136 136 event add <<B3>> <Button-2>
137 137 } else {
138 138 event add <<B3>> <Button-3>
139 139 }
140 140
141 141 proc gitdir {} {
142 142 global env
143 143 if {[info exists env(GIT_DIR)]} {
144 144 return $env(GIT_DIR)
145 145 } else {
146 146 return ".hg"
147 147 }
148 148 }
149 149
150 150 proc popupify {w} {
151 151 wm resizable $w 0 0
152 152 wm withdraw $w
153 153 update
154 154 set x [expr {([winfo screenwidth .]-[winfo reqwidth $w])/2}]
155 155 set y [expr {([winfo screenheight .]-[winfo reqheight $w])/2}]
156 156 wm geometry $w +$x+$y
157 157 wm transient $w .
158 158 wm deiconify $w
159 159 wm resizable $w 1 1
160 160 }
161 161
162 162 proc getcommits {rargs} {
163 163 global commits commfd phase canv mainfont env
164 164 global startmsecs nextupdate ncmupdate
165 165 global ctext maincursor textcursor leftover
166 166
167 167 # check that we can find a .git directory somewhere...
168 168 set gitdir [gitdir]
169 169 if {![file isdirectory $gitdir]} {
170 170 error_popup "Cannot find the git directory \"$gitdir\"."
171 171 exit 1
172 172 }
173 173 set commits {}
174 174 set phase getcommits
175 175 set startmsecs [clock clicks -milliseconds]
176 176 set nextupdate [expr $startmsecs + 100]
177 177 set ncmupdate 1
178 178 set limit 0
179 179 set revargs {}
180 180 for {set i 0} {$i < [llength $rargs]} {incr i} {
181 181 set opt [lindex $rargs $i]
182 182 if {$opt == "--limit"} {
183 183 incr i
184 184 set limit [lindex $rargs $i]
185 185 } else {
186 186 lappend revargs $opt
187 187 }
188 188 }
189 189 if [catch {
190 190 set parse_args [concat --default HEAD $revargs]
191 191 set parse_temp [eval exec {$env(HG)} --config ui.report_untrusted=false debug-rev-parse $parse_args]
192 192 regsub -all "\r\n" $parse_temp "\n" parse_temp
193 193 set parsed_args [split $parse_temp "\n"]
194 194 } err] {
195 195 # if git-rev-parse failed for some reason...
196 196 if {$rargs == {}} {
197 197 set revargs HEAD
198 198 }
199 199 set parsed_args $revargs
200 200 }
201 201 if {$limit > 0} {
202 202 set parsed_args [concat -n $limit $parsed_args]
203 203 }
204 204 if [catch {
205 205 set commfd [open "|{$env(HG)} --config ui.report_untrusted=false debug-rev-list --header --topo-order --parents $parsed_args" r]
206 206 } err] {
207 207 puts stderr "Error executing hg debug-rev-list: $err"
208 208 exit 1
209 209 }
210 210 set leftover {}
211 211 fconfigure $commfd -blocking 0 -translation lf
212 212 fileevent $commfd readable [list getcommitlines $commfd]
213 213 $canv delete all
214 214 $canv create text 3 3 -anchor nw -text "Reading commits..." \
215 215 -font $mainfont -tags textitems
216 216 . config -cursor watch
217 217 settextcursor watch
218 218 }
219 219
220 220 proc getcommitlines {commfd} {
221 221 global commits parents cdate children
222 222 global commitlisted phase commitinfo nextupdate
223 223 global stopped redisplaying leftover
224 224
225 225 set stuff [read $commfd]
226 226 if {$stuff == {}} {
227 227 if {![eof $commfd]} return
228 228 # set it blocking so we wait for the process to terminate
229 229 fconfigure $commfd -blocking 1
230 230 if {![catch {close $commfd} err]} {
231 231 after idle finishcommits
232 232 return
233 233 }
234 234 if {[string range $err 0 4] == "usage"} {
235 235 set err \
236 236 {Gitk: error reading commits: bad arguments to git-rev-list.
237 237 (Note: arguments to gitk are passed to git-rev-list
238 238 to allow selection of commits to be displayed.)}
239 239 } else {
240 240 set err "Error reading commits: $err"
241 241 }
242 242 error_popup $err
243 243 exit 1
244 244 }
245 245 set start 0
246 246 while 1 {
247 247 set i [string first "\0" $stuff $start]
248 248 if {$i < 0} {
249 249 append leftover [string range $stuff $start end]
250 250 return
251 251 }
252 252 set cmit [string range $stuff $start [expr {$i - 1}]]
253 253 if {$start == 0} {
254 254 set cmit "$leftover$cmit"
255 255 set leftover {}
256 256 }
257 257 set start [expr {$i + 1}]
258 258 regsub -all "\r\n" $cmit "\n" cmit
259 259 set j [string first "\n" $cmit]
260 260 set ok 0
261 261 if {$j >= 0} {
262 262 set ids [string range $cmit 0 [expr {$j - 1}]]
263 263 set ok 1
264 264 foreach id $ids {
265 265 if {![regexp {^[0-9a-f]{12}$} $id]} {
266 266 set ok 0
267 267 break
268 268 }
269 269 }
270 270 }
271 271 if {!$ok} {
272 272 set shortcmit $cmit
273 273 if {[string length $shortcmit] > 80} {
274 274 set shortcmit "[string range $shortcmit 0 80]..."
275 275 }
276 276 error_popup "Can't parse hg debug-rev-list output: {$shortcmit}"
277 277 exit 1
278 278 }
279 279 set id [lindex $ids 0]
280 280 set olds [lrange $ids 1 end]
281 281 set cmit [string range $cmit [expr {$j + 1}] end]
282 282 lappend commits $id
283 283 set commitlisted($id) 1
284 284 parsecommit $id $cmit 1 [lrange $ids 1 end]
285 285 drawcommit $id
286 286 if {[clock clicks -milliseconds] >= $nextupdate} {
287 287 doupdate 1
288 288 }
289 289 while {$redisplaying} {
290 290 set redisplaying 0
291 291 if {$stopped == 1} {
292 292 set stopped 0
293 293 set phase "getcommits"
294 294 foreach id $commits {
295 295 drawcommit $id
296 296 if {$stopped} break
297 297 if {[clock clicks -milliseconds] >= $nextupdate} {
298 298 doupdate 1
299 299 }
300 300 }
301 301 }
302 302 }
303 303 }
304 304 }
305 305
306 306 proc doupdate {reading} {
307 307 global commfd nextupdate numcommits ncmupdate
308 308
309 309 if {$reading} {
310 310 fileevent $commfd readable {}
311 311 }
312 312 update
313 313 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
314 314 if {$numcommits < 100} {
315 315 set ncmupdate [expr {$numcommits + 1}]
316 316 } elseif {$numcommits < 10000} {
317 317 set ncmupdate [expr {$numcommits + 10}]
318 318 } else {
319 319 set ncmupdate [expr {$numcommits + 100}]
320 320 }
321 321 if {$reading} {
322 322 fileevent $commfd readable [list getcommitlines $commfd]
323 323 }
324 324 }
325 325
326 326 proc readcommit {id} {
327 327 global env
328 328 if [catch {set contents [exec $env(HG) --config ui.report_untrusted=false debug-cat-file commit $id]}] return
329 329 parsecommit $id $contents 0 {}
330 330 }
331 331
332 332 proc parsecommit {id contents listed olds} {
333 333 global commitinfo children nchildren parents nparents cdate ncleft
334 334 global firstparents
335 335
336 336 set inhdr 1
337 337 set comment {}
338 338 set headline {}
339 339 set auname {}
340 340 set audate {}
341 341 set comname {}
342 342 set comdate {}
343 343 set rev {}
344 344 set branch {}
345 345 set bookmark {}
346 346 if {![info exists nchildren($id)]} {
347 347 set children($id) {}
348 348 set nchildren($id) 0
349 349 set ncleft($id) 0
350 350 }
351 351 set parents($id) $olds
352 352 set nparents($id) [llength $olds]
353 353 foreach p $olds {
354 354 if {![info exists nchildren($p)]} {
355 355 set children($p) [list $id]
356 356 set nchildren($p) 1
357 357 set ncleft($p) 1
358 358 } elseif {[lsearch -exact $children($p) $id] < 0} {
359 359 lappend children($p) $id
360 360 incr nchildren($p)
361 361 incr ncleft($p)
362 362 }
363 363 }
364 364 regsub -all "\r\n" $contents "\n" contents
365 365 foreach line [split $contents "\n"] {
366 366 if {$inhdr} {
367 367 set line [split $line]
368 368 if {$line == {}} {
369 369 set inhdr 0
370 370 } else {
371 371 set tag [lindex $line 0]
372 372 if {$tag == "author"} {
373 373 set x [expr {[llength $line] - 2}]
374 374 set audate [lindex $line $x]
375 375 set auname [join [lrange $line 1 [expr {$x - 1}]]]
376 376 } elseif {$tag == "committer"} {
377 377 set x [expr {[llength $line] - 2}]
378 378 set comdate [lindex $line $x]
379 379 set comname [join [lrange $line 1 [expr {$x - 1}]]]
380 380 } elseif {$tag == "revision"} {
381 381 set rev [lindex $line 1]
382 382 } elseif {$tag == "branch"} {
383 383 set branch [join [lrange $line 1 end]]
384 384 } elseif {$tag == "bookmark"} {
385 385 set bookmark [join [lrange $line 1 end]]
386 386 }
387 387 }
388 388 } else {
389 389 if {$comment == {}} {
390 390 set headline [string trim $line]
391 391 } else {
392 392 append comment "\n"
393 393 }
394 394 if {!$listed} {
395 395 # git-rev-list indents the comment by 4 spaces;
396 396 # if we got this via git-cat-file, add the indentation
397 397 append comment " "
398 398 }
399 399 append comment $line
400 400 }
401 401 }
402 402 if {$audate != {}} {
403 403 set audate [clock format $audate]
404 404 }
405 405 if {$comdate != {}} {
406 406 set cdate($id) $comdate
407 407 set comdate [clock format $comdate]
408 408 }
409 409 set commitinfo($id) [list $headline $auname $audate \
410 410 $comname $comdate $comment $rev $branch $bookmark]
411 411
412 412 if {[info exists firstparents]} {
413 413 set i [lsearch $firstparents $id]
414 414 if {$i != -1} {
415 415 # remove the parent from firstparents, possible building
416 416 # an empty list
417 417 set firstparents [concat \
418 418 [lrange $firstparents 0 [expr $i - 1]] \
419 419 [lrange $firstparents [expr $i + 1] end]]
420 420 if {$firstparents eq {}} {
421 421 # we have found all parents of the first changeset
422 422 # which means that we can safely select the first line
423 423 after idle {
424 424 selectline 0 0
425 425 }
426 426 }
427 427 }
428 428 } else {
429 429 # this is the first changeset, save the parents
430 430 set firstparents $olds
431 431 if {$firstparents eq {}} {
432 432 # a repository with a single changeset
433 433 after idle {
434 434 selectline 0 0
435 435 }
436 436 }
437 437 }
438 438 }
439 439
440 440 proc readrefs {} {
441 441 global bookmarkcurrent bookmarkids tagids idtags idbookmarks headids idheads tagcontents env curid
442 442
443 443 set status [catch {exec $env(HG) --config ui.report_untrusted=false id} curid]
444 444 if { $status != 0 } {
445 445 puts $::errorInfo
446 446 if { ![string equal $::errorCode NONE] } {
447 447 exit 2
448 448 }
449 449 }
450 450 regexp -- {[[:xdigit:]]+} $curid curid
451 451
452 452 set status [catch {exec $env(HG) --config ui.report_untrusted=false tags} tags]
453 453 if { $status != 0 } {
454 454 puts $::errorInfo
455 455 if { ![string equal $::errorCode NONE] } {
456 456 exit 2
457 457 }
458 458 }
459 459
460 460 foreach {tag rev} $tags {
461 461 # we use foreach as Tcl8.4 doesn't support lassign
462 462 foreach {- id} [split $rev :] {
463 463 lappend tagids($tag) $id
464 464 lappend idtags($id) $tag
465 465 }
466 466 }
467 467
468 468 set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads]
469 469 if { $status != 0 } {
470 470 puts $::errorInfo
471 471 if { ![string equal $::errorCode NONE] } {
472 472 exit 2
473 473 }
474 474 }
475 475
476 476 set lines [split $heads \r\n]
477 477 foreach f $lines {
478 478 set match ""
479 479 regexp {changeset:\s+(\S+):(\S+)$} $f match id sha
480 480 if {$match != ""} {
481 481 lappend idheads($sha) $id
482 482 }
483 483 }
484 484
485 485 set status [catch {exec $env(HG) --config ui.report_untrusted=false bookmarks} bookmarks]
486 486 if { $status != 0 } {
487 487 puts $::errorInfo
488 488 if { ![string equal $::errorCode NONE] } {
489 489 exit 2
490 490 }
491 491 }
492 492 set lines [split $bookmarks "\n"]
493 493 set bookmarkcurrent 0
494 494 foreach f $lines {
495 495 regexp {(\S+)$} $f full
496 496 regsub {\s+(\S+)$} $f "" direct
497 497 set sha [split $full ':']
498 498 set bookmark [lindex $sha 1]
499 499 set current [string first " * " $direct)]
500 500 regsub {^\s(\*|\s)\s} $direct "" direct
501 501 lappend bookmarkids($direct) $bookmark
502 502 lappend idbookmarks($bookmark) $direct
503 503 if {$current >= 0} {
504 504 set bookmarkcurrent $direct
505 505 }
506 506 }
507 507 }
508 508
509 509 proc readotherrefs {base dname excl} {
510 510 global otherrefids idotherrefs
511 511
512 512 set git [gitdir]
513 513 set files [glob -nocomplain -types f [file join $git $base *]]
514 514 foreach f $files {
515 515 catch {
516 516 set fd [open $f r]
517 517 set line [read $fd 40]
518 518 if {[regexp {^[0-9a-f]{12}} $line id]} {
519 519 set name "$dname[file tail $f]"
520 520 set otherrefids($name) $id
521 521 lappend idotherrefs($id) $name
522 522 }
523 523 close $fd
524 524 }
525 525 }
526 526 set dirs [glob -nocomplain -types d [file join $git $base *]]
527 527 foreach d $dirs {
528 528 set dir [file tail $d]
529 529 if {[lsearch -exact $excl $dir] >= 0} continue
530 530 readotherrefs [file join $base $dir] "$dname$dir/" {}
531 531 }
532 532 }
533 533
534 534 proc allcansmousewheel {delta} {
535 535 set delta [expr -5*(int($delta)/abs($delta))]
536 536 allcanvs yview scroll $delta units
537 537 }
538 538
539 539 proc error_popup msg {
540 540 set w .error
541 541 toplevel $w
542 542 wm transient $w .
543 543 message $w.m -text $msg -justify center -aspect 400
544 544 pack $w.m -side top -fill x -padx 20 -pady 20
545 545 ttk::button $w.ok -text OK -command "destroy $w"
546 546 pack $w.ok -side bottom -fill x
547 547 bind $w <Visibility> "grab $w; focus $w"
548 548 popupify $w
549 549 tkwait window $w
550 550 }
551 551
552 552 proc makewindow {} {
553 553 global canv canv2 canv3 linespc charspc ctext cflist textfont
554 554 global findtype findtypemenu findloc findstring fstring geometry
555 555 global entries sha1entry sha1string sha1but
556 556 global maincursor textcursor curtextcursor
557 557 global rowctxmenu gaudydiff mergemax
558 558 global hgvdiff bgcolor fgcolor diffremcolor diffaddcolor diffmerge1color
559 559 global diffmerge2color hunksepcolor
560 560 global posx posy
561 561
562 562 if {[info exists posx]} {
563 563 wm geometry . +$posx+$posy
564 564 }
565
565
566 566 menu .bar
567 567 .bar add cascade -label "File" -menu .bar.file
568 568 menu .bar.file
569 569 .bar.file add command -label "Reread references" -command rereadrefs
570 570 .bar.file add command -label "Quit" -command doquit
571 571 menu .bar.help
572 572 .bar add cascade -label "Help" -menu .bar.help
573 573 .bar.help add command -label "About hgk" -command about
574 574 . configure -menu .bar
575 575
576 576 if {![info exists geometry(canv1)]} {
577 577 set geometry(canv1) [expr 45 * $charspc]
578 578 set geometry(canv2) [expr 30 * $charspc]
579 579 set geometry(canv3) [expr 15 * $charspc]
580 580 set geometry(canvh) [expr 25 * $linespc + 4]
581 581 set geometry(ctextw) 80
582 582 set geometry(ctexth) 30
583 583 set geometry(cflistw) 30
584 584 }
585 585 panedwindow .ctop -orient vertical
586 586 if {[info exists geometry(width)]} {
587 587 .ctop conf -width $geometry(width) -height $geometry(height)
588 588 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
589 589 set geometry(ctexth) [expr {($texth - 8) /
590 590 [font metrics $textfont -linespace]}]
591 591 }
592 592 ttk::frame .ctop.top
593 593 ttk::frame .ctop.top.bar
594 594 pack .ctop.top.bar -side bottom -fill x
595 595 set cscroll .ctop.top.csb
596 596 ttk::scrollbar $cscroll -command {allcanvs yview}
597 597 pack $cscroll -side right -fill y
598 598 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
599 599 pack .ctop.top.clist -side top -fill both -expand 1
600 600 .ctop add .ctop.top
601 601 set canv .ctop.top.clist.canv
602 602 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
603 603 -bg $bgcolor -bd 0 \
604 604 -yscrollincr $linespc -yscrollcommand "$cscroll set" -selectbackground "#c0c0c0"
605 605 .ctop.top.clist add $canv
606 606 set canv2 .ctop.top.clist.canv2
607 607 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
608 608 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
609 609 .ctop.top.clist add $canv2
610 610 set canv3 .ctop.top.clist.canv3
611 611 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
612 612 -bg $bgcolor -bd 0 -yscrollincr $linespc -selectbackground "#c0c0c0"
613 613 .ctop.top.clist add $canv3
614 614 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
615 615
616 616 set sha1entry .ctop.top.bar.sha1
617 617 set entries $sha1entry
618 618 set sha1but .ctop.top.bar.sha1label
619 619 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
620 620 -command gotocommit -width 8
621 621 $sha1but conf -disabledforeground [$sha1but cget -foreground]
622 622 pack .ctop.top.bar.sha1label -side left
623 623 ttk::entry $sha1entry -width 40 -font $textfont -textvariable sha1string
624 624 trace add variable sha1string write sha1change
625 625 pack $sha1entry -side left -pady 2
626 626
627 627 image create bitmap bm-left -data {
628 628 #define left_width 16
629 629 #define left_height 16
630 630 static unsigned char left_bits[] = {
631 631 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
632 632 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
633 633 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
634 634 }
635 635 image create bitmap bm-right -data {
636 636 #define right_width 16
637 637 #define right_height 16
638 638 static unsigned char right_bits[] = {
639 639 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
640 640 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
641 641 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
642 642 }
643 643 ttk::button .ctop.top.bar.leftbut -image bm-left -command goback \
644 644 -state disabled -width 26
645 645 pack .ctop.top.bar.leftbut -side left -fill y
646 646 ttk::button .ctop.top.bar.rightbut -image bm-right -command goforw \
647 647 -state disabled -width 26
648 648 pack .ctop.top.bar.rightbut -side left -fill y
649 649
650 650 ttk::button .ctop.top.bar.findbut -text "Find" -command dofind
651 651 pack .ctop.top.bar.findbut -side left
652 652 set findstring {}
653 653 set fstring .ctop.top.bar.findstring
654 654 lappend entries $fstring
655 655 ttk::entry $fstring -width 30 -font $textfont -textvariable findstring
656 656 pack $fstring -side left -expand 1 -fill x
657 657 set findtype Exact
658 658 set findtypemenu [ttk::optionMenu .ctop.top.bar.findtype \
659 659 findtype Exact IgnCase Regexp]
660 660 set findloc "All fields"
661 661 ttk::optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
662 662 Comments Author Files Pickaxe
663 663 pack .ctop.top.bar.findloc -side right
664 664 pack .ctop.top.bar.findtype -side right
665 665 # for making sure type==Exact whenever loc==Pickaxe
666 666 trace add variable findloc write findlocchange
667 667
668 668 panedwindow .ctop.cdet -orient horizontal
669 669 .ctop add .ctop.cdet
670 670 ttk::frame .ctop.cdet.left
671 671 set ctext .ctop.cdet.left.ctext
672 672 text $ctext -fg $fgcolor -bg $bgcolor -state disabled -font $textfont \
673 673 -width $geometry(ctextw) -height $geometry(ctexth) \
674 674 -yscrollcommand ".ctop.cdet.left.sb set" \
675 675 -xscrollcommand ".ctop.cdet.left.hb set" -wrap none
676 676 ttk::scrollbar .ctop.cdet.left.sb -command "$ctext yview"
677 677 ttk::scrollbar .ctop.cdet.left.hb -orient horizontal -command "$ctext xview"
678 678 pack .ctop.cdet.left.sb -side right -fill y
679 679 pack .ctop.cdet.left.hb -side bottom -fill x
680 680 pack $ctext -side left -fill both -expand 1
681 681 .ctop.cdet add .ctop.cdet.left
682 682
683 683 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
684 684 if {$gaudydiff} {
685 685 $ctext tag conf hunksep -back blue -fore white
686 686 $ctext tag conf d0 -back "#ff8080"
687 687 $ctext tag conf d1 -back green
688 688 } else {
689 689 $ctext tag conf hunksep -fore $hunksepcolor
690 690 $ctext tag conf d0 -fore $diffremcolor
691 691 $ctext tag conf d1 -fore $diffaddcolor
692 692
693 693 # The mX colours seem to be used in merge changesets, where m0
694 694 # is first parent, m1 is second parent and so on. Git can have
695 695 # several parents, Hg cannot, so I think the m2..mmax would be
696 696 # unused.
697 697 $ctext tag conf m0 -fore $diffmerge1color
698 698 $ctext tag conf m1 -fore $diffmerge2color
699 699 $ctext tag conf m2 -fore green
700 700 $ctext tag conf m3 -fore purple
701 701 $ctext tag conf m4 -fore brown
702 702 $ctext tag conf mmax -fore darkgrey
703 703 set mergemax 5
704 704 $ctext tag conf mresult -font [concat $textfont bold]
705 705 $ctext tag conf msep -font [concat $textfont bold]
706 706 $ctext tag conf found -back yellow
707 707 }
708 708
709 709 ttk::frame .ctop.cdet.right
710 710 set cflist .ctop.cdet.right.cfiles
711 711 listbox $cflist -fg $fgcolor -bg $bgcolor \
712 712 -selectmode extended -width $geometry(cflistw) \
713 713 -yscrollcommand ".ctop.cdet.right.sb set"
714 714 ttk::scrollbar .ctop.cdet.right.sb -command "$cflist yview"
715 715 pack .ctop.cdet.right.sb -side right -fill y
716 716 pack $cflist -side left -fill both -expand 1
717 717 .ctop.cdet add .ctop.cdet.right
718 718 bind .ctop.cdet <Configure> {resizecdetpanes %W %w}
719 719
720 720 pack .ctop -side top -fill both -expand 1
721 721
722 722 bindall <1> {selcanvline %W %x %y}
723 723 #bindall <B1-Motion> {selcanvline %W %x %y}
724 724 bindall <MouseWheel> "allcansmousewheel %D"
725 725 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
726 726 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
727 727 bindall <2> "allcanvs scan mark 0 %y"
728 728 bindall <B2-Motion> "allcanvs scan dragto 0 %y"
729 729 bind . <Key-Up> "selnextline -1"
730 730 bind . <Key-Down> "selnextline 1"
731 731 bind . <Key-Prior> "allcanvs yview scroll -1 pages"
732 732 bind . <Key-Next> "allcanvs yview scroll 1 pages"
733 733 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
734 734 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
735 735 bindkey <Key-space> "$ctext yview scroll 1 pages"
736 736 bindkey p "selnextline -1"
737 737 bindkey n "selnextline 1"
738 738 bindkey b "$ctext yview scroll -1 pages"
739 739 bindkey d "$ctext yview scroll 18 units"
740 740 bindkey u "$ctext yview scroll -18 units"
741 741 bindkey / {findnext 1}
742 742 bindkey <Key-Return> {findnext 0}
743 743 bindkey ? findprev
744 744 bindkey f nextfile
745 745 bind . <Control-q> doquit
746 746 bind . <Control-w> doquit
747 747 bind . <Control-f> dofind
748 748 bind . <Control-g> {findnext 0}
749 749 bind . <Control-r> findprev
750 750 bind . <Control-equal> {incrfont 1}
751 751 bind . <Control-KP_Add> {incrfont 1}
752 752 bind . <Control-minus> {incrfont -1}
753 753 bind . <Control-KP_Subtract> {incrfont -1}
754 754 bind $cflist <<ListboxSelect>> listboxsel
755 755 bind . <Destroy> {savestuff %W}
756 756 bind . <Button-1> "click %W"
757 757 bind $fstring <Key-Return> dofind
758 758 bind $sha1entry <Key-Return> gotocommit
759 759 bind $sha1entry <<PasteSelection>> clearsha1
760 760
761 761 set maincursor [. cget -cursor]
762 762 set textcursor [$ctext cget -cursor]
763 763 set curtextcursor $textcursor
764 764
765 765 set rowctxmenu .rowctxmenu
766 766 menu $rowctxmenu -tearoff 0
767 767 $rowctxmenu add command -label "Diff this -> selected" \
768 768 -command {diffvssel 0}
769 769 $rowctxmenu add command -label "Diff selected -> this" \
770 770 -command {diffvssel 1}
771 771 $rowctxmenu add command -label "Make patch" -command mkpatch
772 772 $rowctxmenu add command -label "Create tag" -command mktag
773 773 $rowctxmenu add command -label "Write commit to file" -command writecommit
774 774 if { $hgvdiff ne "" } {
775 775 $rowctxmenu add command -label "Visual diff with parent" \
776 776 -command {vdiff 1}
777 777 $rowctxmenu add command -label "Visual diff with selected" \
778 778 -command {vdiff 0}
779 779 }
780 780 }
781 781
782 782 # when we make a key binding for the toplevel, make sure
783 783 # it doesn't get triggered when that key is pressed in the
784 784 # find string entry widget.
785 785 proc bindkey {ev script} {
786 786 global entries
787 787 bind . $ev $script
788 788 set escript [bind Entry $ev]
789 789 if {$escript == {}} {
790 790 set escript [bind Entry <Key>]
791 791 }
792 792 foreach e $entries {
793 793 bind $e $ev "$escript; break"
794 794 }
795 795 }
796 796
797 797 # set the focus back to the toplevel for any click outside
798 798 # the entry widgets
799 799 proc click {w} {
800 800 global entries
801 801 foreach e $entries {
802 802 if {$w == $e} return
803 803 }
804 804 focus .
805 805 }
806 806
807 807 proc savestuff {w} {
808 808 global canv canv2 canv3 ctext cflist mainfont textfont
809 809 global stuffsaved findmergefiles gaudydiff maxgraphpct
810 810 global maxwidth authorcolors curidfont bgcolor fgcolor
811 811 global diffremcolor diffaddcolor hunksepcolor
812 812 global diffmerge1color diffmerge2color
813 813
814 814 if {$stuffsaved} return
815 815 if {![winfo viewable .]} return
816 816 catch {
817 817 set f [open "~/.hgk-new" w]
818 818 puts $f [list set mainfont $mainfont]
819 819 puts $f [list set curidfont $curidfont]
820 820 puts $f [list set textfont $textfont]
821 821 puts $f [list set findmergefiles $findmergefiles]
822 822 puts $f [list set gaudydiff $gaudydiff]
823 823 puts $f [list set maxgraphpct $maxgraphpct]
824 824 puts $f [list set maxwidth $maxwidth]
825 825 puts $f "set geometry(width) [winfo width .ctop]"
826 826 puts $f "set geometry(height) [winfo height .ctop]"
827 827 puts $f "set geometry(canv1) [expr [winfo width $canv]-2]"
828 828 puts $f "set geometry(canv2) [expr [winfo width $canv2]-2]"
829 829 puts $f "set geometry(canv3) [expr [winfo width $canv3]-2]"
830 830 puts $f "set geometry(canvh) [expr [winfo height $canv]-2]"
831 831 set wid [expr {([winfo width $ctext] - 8) \
832 832 / [font measure $textfont "0"]}]
833 833 puts $f "set geometry(ctextw) $wid"
834 834 set wid [expr {([winfo width $cflist] - 11) \
835 835 / [font measure [$cflist cget -font] "0"]}]
836 836 puts $f "set geometry(cflistw) $wid"
837 837 puts $f "#"
838 838 puts $f "# main window position:"
839 839 puts $f "set posx [winfo x .]"
840 840 puts $f "set posy [winfo y .]"
841 841 puts $f "#"
842 842 puts $f "# authorcolors format:"
843 843 puts $f "#"
844 844 puts $f "# zero or more sublists of"
845 845 puts $f "#"
846 846 puts $f "# { regex color }"
847 847 puts $f "#"
848 848 puts $f "# followed by a list of colors"
849 849 puts $f "#"
850 850 puts $f "# If the commit author matches a regex in a sublist,"
851 851 puts $f "# the commit will be colored by that color"
852 852 puts $f "# otherwise the next unused entry from the list of colors"
853 853 puts $f "# will be assigned to this commit and also all other commits"
854 854 puts $f "# of the same author. When the list of colors is exhausted,"
855 855 puts $f "# the last entry will be reused."
856 856 puts $f "#"
857 857 puts $f "set authorcolors {$authorcolors}"
858 858 puts $f "#"
859 859 puts $f "# The background color in the text windows"
860 860 puts $f "set bgcolor $bgcolor"
861 861 puts $f "#"
862 862 puts $f "# The text color used in the diff and file list view"
863 863 puts $f "set fgcolor $fgcolor"
864 864 puts $f "#"
865 865 puts $f "# Color to display + lines in diffs"
866 866 puts $f "set diffaddcolor $diffaddcolor"
867 867 puts $f "#"
868 868 puts $f "# Color to display - lines in diffs"
869 869 puts $f "set diffremcolor $diffremcolor"
870 870 puts $f "#"
871 871 puts $f "# Merge diffs: Color to signal lines from first parent"
872 872 puts $f "set diffmerge1color $diffmerge1color"
873 873 puts $f "#"
874 874 puts $f "# Merge diffs: Color to signal lines from second parent"
875 875 puts $f "set diffmerge2color $diffmerge2color"
876 876 puts $f "#"
877 877 puts $f "# Hunkseparator (@@ -lineno,lines +lineno,lines @@) color"
878 878 puts $f "set hunksepcolor $hunksepcolor"
879 879 close $f
880 880 file rename -force "~/.hgk-new" "~/.hgk"
881 881 }
882 882 set stuffsaved 1
883 883 }
884 884
885 885 proc resizeclistpanes {win w} {
886 886 global oldwidth
887 887 if [info exists oldwidth($win)] {
888 888 set s0 [$win sash coord 0]
889 889 set s1 [$win sash coord 1]
890 890 if {$w < 60} {
891 891 set sash0 [expr {int($w/2 - 2)}]
892 892 set sash1 [expr {int($w*5/6 - 2)}]
893 893 } else {
894 894 set factor [expr {1.0 * $w / $oldwidth($win)}]
895 895 set sash0 [expr {int($factor * [lindex $s0 0])}]
896 896 set sash1 [expr {int($factor * [lindex $s1 0])}]
897 897 if {$sash0 < 30} {
898 898 set sash0 30
899 899 }
900 900 if {$sash1 < $sash0 + 20} {
901 901 set sash1 [expr $sash0 + 20]
902 902 }
903 903 if {$sash1 > $w - 10} {
904 904 set sash1 [expr $w - 10]
905 905 if {$sash0 > $sash1 - 20} {
906 906 set sash0 [expr $sash1 - 20]
907 907 }
908 908 }
909 909 }
910 910 $win sash place 0 $sash0 [lindex $s0 1]
911 911 $win sash place 1 $sash1 [lindex $s1 1]
912 912 }
913 913 set oldwidth($win) $w
914 914 }
915 915
916 916 proc resizecdetpanes {win w} {
917 917 global oldwidth
918 918 if [info exists oldwidth($win)] {
919 919 set s0 [$win sash coord 0]
920 920 if {$w < 60} {
921 921 set sash0 [expr {int($w*3/4 - 2)}]
922 922 } else {
923 923 set factor [expr {1.0 * $w / $oldwidth($win)}]
924 924 set sash0 [expr {int($factor * [lindex $s0 0])}]
925 925 if {$sash0 < 45} {
926 926 set sash0 45
927 927 }
928 928 if {$sash0 > $w - 15} {
929 929 set sash0 [expr $w - 15]
930 930 }
931 931 }
932 932 $win sash place 0 $sash0 [lindex $s0 1]
933 933 }
934 934 set oldwidth($win) $w
935 935 }
936 936
937 937 proc allcanvs args {
938 938 global canv canv2 canv3
939 939 eval $canv $args
940 940 eval $canv2 $args
941 941 eval $canv3 $args
942 942 }
943 943
944 944 proc bindall {event action} {
945 945 global canv canv2 canv3
946 946 bind $canv $event $action
947 947 bind $canv2 $event $action
948 948 bind $canv3 $event $action
949 949 }
950 950
951 951 proc about {} {
952 952 set w .about
953 953 if {[winfo exists $w]} {
954 954 raise $w
955 955 return
956 956 }
957 957 toplevel $w
958 958 wm title $w "About hgk"
959 959 message $w.m -text {
960 960 Hgk version 1.2
961 961
962 962 Copyright � 2005 Paul Mackerras
963 963
964 964 Use and redistribute under the terms of the GNU General Public License} \
965 965 -justify center -aspect 400
966 966 pack $w.m -side top -fill x -padx 20 -pady 20
967 967 ttk::button $w.ok -text Close -command "destroy $w"
968 968 pack $w.ok -side bottom
969 969 popupify $w
970 970 }
971 971
972 972 set aunextcolor 0
973 973 proc assignauthorcolor {name} {
974 974 global authorcolors aucolormap aunextcolor
975 975 if [info exists aucolormap($name)] return
976 976
977 977 set randomcolors {black}
978 978 for {set i 0} {$i < [llength $authorcolors]} {incr i} {
979 979 set col [lindex $authorcolors $i]
980 980 if {[llength $col] > 1} {
981 981 set re [lindex $col 0]
982 982 set c [lindex $col 1]
983 983 if {[regexp -- $re $name]} {
984 984 set aucolormap($name) $c
985 985 return
986 986 }
987 987 } else {
988 988 set randomcolors [lrange $authorcolors $i end]
989 989 break
990 990 }
991 991 }
992 992
993 993 set ncolors [llength $randomcolors]
994 994 set c [lindex $randomcolors $aunextcolor]
995 995 if {[incr aunextcolor] >= $ncolors} {
996 996 incr aunextcolor -1
997 997 }
998 998 set aucolormap($name) $c
999 999 }
1000 1000
1001 1001 proc assigncolor {id} {
1002 1002 global commitinfo colormap commcolors colors nextcolor
1003 1003 global parents nparents children nchildren
1004 1004 global cornercrossings crossings
1005 1005
1006 1006 if [info exists colormap($id)] return
1007 1007 set ncolors [llength $colors]
1008 1008 if {$nparents($id) <= 1 && $nchildren($id) == 1} {
1009 1009 set child [lindex $children($id) 0]
1010 1010 if {[info exists colormap($child)]
1011 1011 && $nparents($child) == 1} {
1012 1012 set colormap($id) $colormap($child)
1013 1013 return
1014 1014 }
1015 1015 }
1016 1016 set badcolors {}
1017 1017 if {[info exists cornercrossings($id)]} {
1018 1018 foreach x $cornercrossings($id) {
1019 1019 if {[info exists colormap($x)]
1020 1020 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1021 1021 lappend badcolors $colormap($x)
1022 1022 }
1023 1023 }
1024 1024 if {[llength $badcolors] >= $ncolors} {
1025 1025 set badcolors {}
1026 1026 }
1027 1027 }
1028 1028 set origbad $badcolors
1029 1029 if {[llength $badcolors] < $ncolors - 1} {
1030 1030 if {[info exists crossings($id)]} {
1031 1031 foreach x $crossings($id) {
1032 1032 if {[info exists colormap($x)]
1033 1033 && [lsearch -exact $badcolors $colormap($x)] < 0} {
1034 1034 lappend badcolors $colormap($x)
1035 1035 }
1036 1036 }
1037 1037 if {[llength $badcolors] >= $ncolors} {
1038 1038 set badcolors $origbad
1039 1039 }
1040 1040 }
1041 1041 set origbad $badcolors
1042 1042 }
1043 1043 if {[llength $badcolors] < $ncolors - 1} {
1044 1044 foreach child $children($id) {
1045 1045 if {[info exists colormap($child)]
1046 1046 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1047 1047 lappend badcolors $colormap($child)
1048 1048 }
1049 1049 if {[info exists parents($child)]} {
1050 1050 foreach p $parents($child) {
1051 1051 if {[info exists colormap($p)]
1052 1052 && [lsearch -exact $badcolors $colormap($p)] < 0} {
1053 1053 lappend badcolors $colormap($p)
1054 1054 }
1055 1055 }
1056 1056 }
1057 1057 }
1058 1058 if {[llength $badcolors] >= $ncolors} {
1059 1059 set badcolors $origbad
1060 1060 }
1061 1061 }
1062 1062 for {set i 0} {$i <= $ncolors} {incr i} {
1063 1063 set c [lindex $colors $nextcolor]
1064 1064 if {[incr nextcolor] >= $ncolors} {
1065 1065 set nextcolor 0
1066 1066 }
1067 1067 if {[lsearch -exact $badcolors $c]} break
1068 1068 }
1069 1069 set colormap($id) $c
1070 1070 }
1071 1071
1072 1072 proc initgraph {} {
1073 1073 global canvy canvy0 lineno numcommits nextcolor linespc
1074 1074 global mainline mainlinearrow sidelines
1075 1075 global nchildren ncleft
1076 1076 global displist nhyperspace
1077 1077
1078 1078 allcanvs delete all
1079 1079 set nextcolor 0
1080 1080 set canvy $canvy0
1081 1081 set lineno -1
1082 1082 set numcommits 0
1083 1083 catch {unset mainline}
1084 1084 catch {unset mainlinearrow}
1085 1085 catch {unset sidelines}
1086 1086 foreach id [array names nchildren] {
1087 1087 set ncleft($id) $nchildren($id)
1088 1088 }
1089 1089 set displist {}
1090 1090 set nhyperspace 0
1091 1091 }
1092 1092
1093 1093 proc bindline {t id} {
1094 1094 global canv
1095 1095
1096 1096 $canv bind $t <Enter> "lineenter %x %y $id"
1097 1097 $canv bind $t <Motion> "linemotion %x %y $id"
1098 1098 $canv bind $t <Leave> "lineleave $id"
1099 1099 $canv bind $t <Button-1> "lineclick %x %y $id 1"
1100 1100 }
1101 1101
1102 1102 proc drawlines {id xtra} {
1103 1103 global mainline mainlinearrow sidelines lthickness colormap canv
1104 1104
1105 1105 $canv delete lines.$id
1106 1106 if {[info exists mainline($id)]} {
1107 1107 set t [$canv create line $mainline($id) \
1108 1108 -width [expr {($xtra + 1) * $lthickness}] \
1109 1109 -fill $colormap($id) -tags lines.$id \
1110 1110 -arrow $mainlinearrow($id)]
1111 1111 $canv lower $t
1112 1112 bindline $t $id
1113 1113 }
1114 1114 if {[info exists sidelines($id)]} {
1115 1115 foreach ls $sidelines($id) {
1116 1116 set coords [lindex $ls 0]
1117 1117 set thick [lindex $ls 1]
1118 1118 set arrow [lindex $ls 2]
1119 1119 set t [$canv create line $coords -fill $colormap($id) \
1120 1120 -width [expr {($thick + $xtra) * $lthickness}] \
1121 1121 -arrow $arrow -tags lines.$id]
1122 1122 $canv lower $t
1123 1123 bindline $t $id
1124 1124 }
1125 1125 }
1126 1126 }
1127 1127
1128 1128 # level here is an index in displist
1129 1129 proc drawcommitline {level} {
1130 1130 global parents children nparents displist
1131 1131 global canv canv2 canv3 mainfont namefont canvy linespc
1132 1132 global lineid linehtag linentag linedtag commitinfo
1133 1133 global colormap numcommits currentparents dupparents
1134 1134 global idtags idline idheads idotherrefs idbookmarks
1135 1135 global lineno lthickness mainline mainlinearrow sidelines
1136 1136 global commitlisted rowtextx idpos lastuse displist
1137 1137 global oldnlines olddlevel olddisplist
1138 1138 global aucolormap curid curidfont
1139 1139
1140 1140 incr numcommits
1141 1141 incr lineno
1142 1142 set id [lindex $displist $level]
1143 1143 set lastuse($id) $lineno
1144 1144 set lineid($lineno) $id
1145 1145 set idline($id) $lineno
1146 1146 set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
1147 1147 if {![info exists commitinfo($id)]} {
1148 1148 readcommit $id
1149 1149 if {![info exists commitinfo($id)]} {
1150 1150 set commitinfo($id) {"No commit information available"}
1151 1151 set nparents($id) 0
1152 1152 }
1153 1153 }
1154 1154 assigncolor $id
1155 1155 set currentparents {}
1156 1156 set dupparents {}
1157 1157 if {[info exists commitlisted($id)] && [info exists parents($id)]} {
1158 1158 foreach p $parents($id) {
1159 1159 if {[lsearch -exact $currentparents $p] < 0} {
1160 1160 lappend currentparents $p
1161 1161 } else {
1162 1162 # remember that this parent was listed twice
1163 1163 lappend dupparents $p
1164 1164 }
1165 1165 }
1166 1166 }
1167 1167 set x [xcoord $level $level $lineno]
1168 1168 set y1 $canvy
1169 1169 set canvy [expr $canvy + $linespc]
1170 1170 allcanvs conf -scrollregion \
1171 1171 [list 0 0 0 [expr $y1 + 0.5 * $linespc + 2]]
1172 1172 if {[info exists mainline($id)]} {
1173 1173 lappend mainline($id) $x $y1
1174 1174 if {$mainlinearrow($id) ne "none"} {
1175 1175 set mainline($id) [trimdiagstart $mainline($id)]
1176 1176 }
1177 1177 }
1178 1178 drawlines $id 0
1179 1179 set orad [expr {$linespc / 3}]
1180 1180 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
1181 1181 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
1182 1182 -fill $ofill -outline black -width 1]
1183 1183 $canv raise $t
1184 1184 $canv bind $t <1> {selcanvline {} %x %y}
1185 1185 set xt [xcoord [llength $displist] $level $lineno]
1186 1186 if {[llength $currentparents] > 2} {
1187 1187 set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
1188 1188 }
1189 1189 set rowtextx($lineno) $xt
1190 1190 set idpos($id) [list $x $xt $y1]
1191 1191 if {[info exists idtags($id)] || [info exists idheads($id)]
1192 1192 || [info exists idotherrefs($id)] || [info exists idbookmarks($id)]} {
1193 1193 set xt [drawtags $id $x $xt $y1]
1194 1194 }
1195 1195 set headline [lindex $commitinfo($id) 0]
1196 1196 set name [lindex $commitinfo($id) 1]
1197 1197 assignauthorcolor $name
1198 1198 set fg $aucolormap($name)
1199 1199 if {$id == $curid} {
1200 1200 set fn $curidfont
1201 1201 } else {
1202 1202 set fn $mainfont
1203 1203 }
1204 1204
1205 1205 set date [lindex $commitinfo($id) 2]
1206 1206 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
1207 1207 -text $headline -font $fn \
1208 1208 -fill $fg]
1209 1209 $canv bind $linehtag($lineno) <<B3>> "rowmenu %X %Y $id"
1210 1210 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
1211 1211 -text $name -font $namefont \
1212 1212 -fill $fg]
1213 1213 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
1214 1214 -text $date -font $mainfont \
1215 1215 -fill $fg]
1216 1216
1217 1217 set olddlevel $level
1218 1218 set olddisplist $displist
1219 1219 set oldnlines [llength $displist]
1220 1220 }
1221 1221
1222 1222 proc drawtags {id x xt y1} {
1223 1223 global bookmarkcurrent idtags idbookmarks idheads idotherrefs commitinfo
1224 1224 global linespc lthickness
1225 1225 global canv mainfont idline rowtextx
1226 1226
1227 1227 set marks {}
1228 1228 set nbookmarks 0
1229 1229 set ntags 0
1230 1230 set nheads 0
1231 1231 if {[info exists idtags($id)]} {
1232 1232 set marks $idtags($id)
1233 1233 set ntags [llength $marks]
1234 1234 }
1235 1235 if {[info exists idbookmarks($id)]} {
1236 1236 set marks [concat $marks $idbookmarks($id)]
1237 1237 set nbookmarks [llength $idbookmarks($id)]
1238 1238 }
1239 1239 if {[info exists idheads($id)]} {
1240 1240 set headmark [lindex $commitinfo($id) 7]
1241 1241 if {$headmark ne "default"} {
1242 1242 lappend marks $headmark
1243 1243 set nheads 1
1244 1244 }
1245 1245 }
1246 1246 if {$marks eq {}} {
1247 1247 return $xt
1248 1248 }
1249 1249
1250 1250 set delta [expr {int(0.5 * ($linespc - $lthickness))}]
1251 1251 set yt [expr $y1 - 0.5 * $linespc]
1252 1252 set yb [expr $yt + $linespc - 1]
1253 1253 set xvals {}
1254 1254 set wvals {}
1255 1255 foreach tag $marks {
1256 1256 set wid [font measure $mainfont $tag]
1257 1257 lappend xvals $xt
1258 1258 lappend wvals $wid
1259 1259 set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
1260 1260 }
1261 1261 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
1262 1262 -width $lthickness -fill black -tags tag.$id]
1263 1263 $canv lower $t
1264 1264 foreach tag $marks x $xvals wid $wvals {
1265 1265 set xl [expr $x + $delta]
1266 1266 set xr [expr $x + $delta + $wid + $lthickness]
1267 1267 if {[incr ntags -1] >= 0} {
1268 1268 # draw a tag
1269 1269 set t [$canv create polygon $x [expr $yt + $delta] $xl $yt \
1270 1270 $xr $yt $xr $yb $xl $yb $x [expr $yb - $delta] \
1271 1271 -width 1 -outline black -fill yellow -tags tag.$id]
1272 1272 $canv bind $t <1> [list showtag $tag 1]
1273 1273 set rowtextx($idline($id)) [expr {$xr + $linespc}]
1274 1274 } elseif {[incr nbookmarks -1] >= 0} {
1275 1275 # draw a tag
1276 1276 set col gray50
1277 1277 if {[string compare $bookmarkcurrent $tag] == 0} {
1278 1278 set col gray
1279 1279 }
1280 1280 set xl [expr $xl - $delta/2]
1281 1281 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1282 1282 -width 1 -outline black -fill $col -tags tag.$id
1283 1283 } else {
1284 1284 # draw a head or other ref
1285 1285 if {[incr nheads -1] >= 0} {
1286 1286 set col "#00ff00"
1287 1287 } else {
1288 1288 set col "#ddddff"
1289 1289 }
1290 1290 set xl [expr $xl - $delta/2]
1291 1291 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \
1292 1292 -width 1 -outline black -fill $col -tags tag.$id
1293 1293 }
1294 1294 set t [$canv create text $xl $y1 -anchor w -text $tag \
1295 1295 -font $mainfont -tags tag.$id]
1296 1296 if {$ntags >= 0} {
1297 1297 $canv bind $t <1> [list showtag $tag 1]
1298 1298 }
1299 1299 }
1300 1300 return $xt
1301 1301 }
1302 1302
1303 1303 proc notecrossings {id lo hi corner} {
1304 1304 global olddisplist crossings cornercrossings
1305 1305
1306 1306 for {set i $lo} {[incr i] < $hi} {} {
1307 1307 set p [lindex $olddisplist $i]
1308 1308 if {$p == {}} continue
1309 1309 if {$i == $corner} {
1310 1310 if {![info exists cornercrossings($id)]
1311 1311 || [lsearch -exact $cornercrossings($id) $p] < 0} {
1312 1312 lappend cornercrossings($id) $p
1313 1313 }
1314 1314 if {![info exists cornercrossings($p)]
1315 1315 || [lsearch -exact $cornercrossings($p) $id] < 0} {
1316 1316 lappend cornercrossings($p) $id
1317 1317 }
1318 1318 } else {
1319 1319 if {![info exists crossings($id)]
1320 1320 || [lsearch -exact $crossings($id) $p] < 0} {
1321 1321 lappend crossings($id) $p
1322 1322 }
1323 1323 if {![info exists crossings($p)]
1324 1324 || [lsearch -exact $crossings($p) $id] < 0} {
1325 1325 lappend crossings($p) $id
1326 1326 }
1327 1327 }
1328 1328 }
1329 1329 }
1330 1330
1331 1331 proc xcoord {i level ln} {
1332 1332 global canvx0 xspc1 xspc2
1333 1333
1334 1334 set x [expr {$canvx0 + $i * $xspc1($ln)}]
1335 1335 if {$i > 0 && $i == $level} {
1336 1336 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}]
1337 1337 } elseif {$i > $level} {
1338 1338 set x [expr {$x + $xspc2 - $xspc1($ln)}]
1339 1339 }
1340 1340 return $x
1341 1341 }
1342 1342
1343 1343 # it seems Tk can't draw arrows on the end of diagonal line segments...
1344 1344 proc trimdiagend {line} {
1345 1345 while {[llength $line] > 4} {
1346 1346 set x1 [lindex $line end-3]
1347 1347 set y1 [lindex $line end-2]
1348 1348 set x2 [lindex $line end-1]
1349 1349 set y2 [lindex $line end]
1350 1350 if {($x1 == $x2) != ($y1 == $y2)} break
1351 1351 set line [lreplace $line end-1 end]
1352 1352 }
1353 1353 return $line
1354 1354 }
1355 1355
1356 1356 proc trimdiagstart {line} {
1357 1357 while {[llength $line] > 4} {
1358 1358 set x1 [lindex $line 0]
1359 1359 set y1 [lindex $line 1]
1360 1360 set x2 [lindex $line 2]
1361 1361 set y2 [lindex $line 3]
1362 1362 if {($x1 == $x2) != ($y1 == $y2)} break
1363 1363 set line [lreplace $line 0 1]
1364 1364 }
1365 1365 return $line
1366 1366 }
1367 1367
1368 1368 proc drawslants {id needonscreen nohs} {
1369 1369 global canv mainline mainlinearrow sidelines
1370 1370 global canvx0 canvy xspc1 xspc2 lthickness
1371 1371 global currentparents dupparents
1372 1372 global lthickness linespc canvy colormap lineno geometry
1373 1373 global maxgraphpct maxwidth
1374 1374 global displist onscreen lastuse
1375 1375 global parents commitlisted
1376 1376 global oldnlines olddlevel olddisplist
1377 1377 global nhyperspace numcommits nnewparents
1378 1378
1379 1379 if {$lineno < 0} {
1380 1380 lappend displist $id
1381 1381 set onscreen($id) 1
1382 1382 return 0
1383 1383 }
1384 1384
1385 1385 set y1 [expr {$canvy - $linespc}]
1386 1386 set y2 $canvy
1387 1387
1388 1388 # work out what we need to get back on screen
1389 1389 set reins {}
1390 1390 if {$onscreen($id) < 0} {
1391 1391 # next to do isn't displayed, better get it on screen...
1392 1392 lappend reins [list $id 0]
1393 1393 }
1394 1394 # make sure all the previous commits's parents are on the screen
1395 1395 foreach p $currentparents {
1396 1396 if {$onscreen($p) < 0} {
1397 1397 lappend reins [list $p 0]
1398 1398 }
1399 1399 }
1400 1400 # bring back anything requested by caller
1401 1401 if {$needonscreen ne {}} {
1402 1402 lappend reins $needonscreen
1403 1403 }
1404 1404
1405 1405 # try the shortcut
1406 1406 if {$currentparents == $id && $onscreen($id) == 0 && $reins eq {}} {
1407 1407 set dlevel $olddlevel
1408 1408 set x [xcoord $dlevel $dlevel $lineno]
1409 1409 set mainline($id) [list $x $y1]
1410 1410 set mainlinearrow($id) none
1411 1411 set lastuse($id) $lineno
1412 1412 set displist [lreplace $displist $dlevel $dlevel $id]
1413 1413 set onscreen($id) 1
1414 1414 set xspc1([expr {$lineno + 1}]) $xspc1($lineno)
1415 1415 return $dlevel
1416 1416 }
1417 1417
1418 1418 # update displist
1419 1419 set displist [lreplace $displist $olddlevel $olddlevel]
1420 1420 set j $olddlevel
1421 1421 foreach p $currentparents {
1422 1422 set lastuse($p) $lineno
1423 1423 if {$onscreen($p) == 0} {
1424 1424 set displist [linsert $displist $j $p]
1425 1425 set onscreen($p) 1
1426 1426 incr j
1427 1427 }
1428 1428 }
1429 1429 if {$onscreen($id) == 0} {
1430 1430 lappend displist $id
1431 1431 set onscreen($id) 1
1432 1432 }
1433 1433
1434 1434 # remove the null entry if present
1435 1435 set nullentry [lsearch -exact $displist {}]
1436 1436 if {$nullentry >= 0} {
1437 1437 set displist [lreplace $displist $nullentry $nullentry]
1438 1438 }
1439 1439
1440 1440 # bring back the ones we need now (if we did it earlier
1441 1441 # it would change displist and invalidate olddlevel)
1442 1442 foreach pi $reins {
1443 1443 # test again in case of duplicates in reins
1444 1444 set p [lindex $pi 0]
1445 1445 if {$onscreen($p) < 0} {
1446 1446 set onscreen($p) 1
1447 1447 set lastuse($p) $lineno
1448 1448 set displist [linsert $displist [lindex $pi 1] $p]
1449 1449 incr nhyperspace -1
1450 1450 }
1451 1451 }
1452 1452
1453 1453 set lastuse($id) $lineno
1454 1454
1455 1455 # see if we need to make any lines jump off into hyperspace
1456 1456 set displ [llength $displist]
1457 1457 if {$displ > $maxwidth} {
1458 1458 set ages {}
1459 1459 foreach x $displist {
1460 1460 lappend ages [list $lastuse($x) $x]
1461 1461 }
1462 1462 set ages [lsort -integer -index 0 $ages]
1463 1463 set k 0
1464 1464 while {$displ > $maxwidth} {
1465 1465 set use [lindex $ages $k 0]
1466 1466 set victim [lindex $ages $k 1]
1467 1467 if {$use >= $lineno - 5} break
1468 1468 incr k
1469 1469 if {[lsearch -exact $nohs $victim] >= 0} continue
1470 1470 set i [lsearch -exact $displist $victim]
1471 1471 set displist [lreplace $displist $i $i]
1472 1472 set onscreen($victim) -1
1473 1473 incr nhyperspace
1474 1474 incr displ -1
1475 1475 if {$i < $nullentry} {
1476 1476 incr nullentry -1
1477 1477 }
1478 1478 set x [lindex $mainline($victim) end-1]
1479 1479 lappend mainline($victim) $x $y1
1480 1480 set line [trimdiagend $mainline($victim)]
1481 1481 set arrow "last"
1482 1482 if {$mainlinearrow($victim) ne "none"} {
1483 1483 set line [trimdiagstart $line]
1484 1484 set arrow "both"
1485 1485 }
1486 1486 lappend sidelines($victim) [list $line 1 $arrow]
1487 1487 unset mainline($victim)
1488 1488 }
1489 1489 }
1490 1490
1491 1491 set dlevel [lsearch -exact $displist $id]
1492 1492
1493 1493 # If we are reducing, put in a null entry
1494 1494 if {$displ < $oldnlines} {
1495 1495 # does the next line look like a merge?
1496 1496 # i.e. does it have > 1 new parent?
1497 1497 if {$nnewparents($id) > 1} {
1498 1498 set i [expr {$dlevel + 1}]
1499 1499 } elseif {$nnewparents([lindex $olddisplist $olddlevel]) == 0} {
1500 1500 set i $olddlevel
1501 1501 if {$nullentry >= 0 && $nullentry < $i} {
1502 1502 incr i -1
1503 1503 }
1504 1504 } elseif {$nullentry >= 0} {
1505 1505 set i $nullentry
1506 1506 while {$i < $displ
1507 1507 && [lindex $olddisplist $i] == [lindex $displist $i]} {
1508 1508 incr i
1509 1509 }
1510 1510 } else {
1511 1511 set i $olddlevel
1512 1512 if {$dlevel >= $i} {
1513 1513 incr i
1514 1514 }
1515 1515 }
1516 1516 if {$i < $displ} {
1517 1517 set displist [linsert $displist $i {}]
1518 1518 incr displ
1519 1519 if {$dlevel >= $i} {
1520 1520 incr dlevel
1521 1521 }
1522 1522 }
1523 1523 }
1524 1524
1525 1525 # decide on the line spacing for the next line
1526 1526 set lj [expr {$lineno + 1}]
1527 1527 set maxw [expr {$maxgraphpct * $geometry(canv1) / 100}]
1528 1528 if {$displ <= 1 || $canvx0 + $displ * $xspc2 <= $maxw} {
1529 1529 set xspc1($lj) $xspc2
1530 1530 } else {
1531 1531 set xspc1($lj) [expr {($maxw - $canvx0 - $xspc2) / ($displ - 1)}]
1532 1532 if {$xspc1($lj) < $lthickness} {
1533 1533 set xspc1($lj) $lthickness
1534 1534 }
1535 1535 }
1536 1536
1537 1537 foreach idi $reins {
1538 1538 set id [lindex $idi 0]
1539 1539 set j [lsearch -exact $displist $id]
1540 1540 set xj [xcoord $j $dlevel $lj]
1541 1541 set mainline($id) [list $xj $y2]
1542 1542 set mainlinearrow($id) first
1543 1543 }
1544 1544
1545 1545 set i -1
1546 1546 foreach id $olddisplist {
1547 1547 incr i
1548 1548 if {$id == {}} continue
1549 1549 if {$onscreen($id) <= 0} continue
1550 1550 set xi [xcoord $i $olddlevel $lineno]
1551 1551 if {$i == $olddlevel} {
1552 1552 foreach p $currentparents {
1553 1553 set j [lsearch -exact $displist $p]
1554 1554 set coords [list $xi $y1]
1555 1555 set xj [xcoord $j $dlevel $lj]
1556 1556 if {$xj < $xi - $linespc} {
1557 1557 lappend coords [expr {$xj + $linespc}] $y1
1558 1558 notecrossings $p $j $i [expr {$j + 1}]
1559 1559 } elseif {$xj > $xi + $linespc} {
1560 1560 lappend coords [expr {$xj - $linespc}] $y1
1561 1561 notecrossings $p $i $j [expr {$j - 1}]
1562 1562 }
1563 1563 if {[lsearch -exact $dupparents $p] >= 0} {
1564 1564 # draw a double-width line to indicate the doubled parent
1565 1565 lappend coords $xj $y2
1566 1566 lappend sidelines($p) [list $coords 2 none]
1567 1567 if {![info exists mainline($p)]} {
1568 1568 set mainline($p) [list $xj $y2]
1569 1569 set mainlinearrow($p) none
1570 1570 }
1571 1571 } else {
1572 1572 # normal case, no parent duplicated
1573 1573 set yb $y2
1574 1574 set dx [expr {abs($xi - $xj)}]
1575 1575 if {0 && $dx < $linespc} {
1576 1576 set yb [expr {$y1 + $dx}]
1577 1577 }
1578 1578 if {![info exists mainline($p)]} {
1579 1579 if {$xi != $xj} {
1580 1580 lappend coords $xj $yb
1581 1581 }
1582 1582 set mainline($p) $coords
1583 1583 set mainlinearrow($p) none
1584 1584 } else {
1585 1585 lappend coords $xj $yb
1586 1586 if {$yb < $y2} {
1587 1587 lappend coords $xj $y2
1588 1588 }
1589 1589 lappend sidelines($p) [list $coords 1 none]
1590 1590 }
1591 1591 }
1592 1592 }
1593 1593 } else {
1594 1594 set j $i
1595 1595 if {[lindex $displist $i] != $id} {
1596 1596 set j [lsearch -exact $displist $id]
1597 1597 }
1598 1598 if {$j != $i || $xspc1($lineno) != $xspc1($lj)
1599 1599 || ($olddlevel < $i && $i < $dlevel)
1600 1600 || ($dlevel < $i && $i < $olddlevel)} {
1601 1601 set xj [xcoord $j $dlevel $lj]
1602 1602 lappend mainline($id) $xi $y1 $xj $y2
1603 1603 }
1604 1604 }
1605 1605 }
1606 1606 return $dlevel
1607 1607 }
1608 1608
1609 1609 # search for x in a list of lists
1610 1610 proc llsearch {llist x} {
1611 1611 set i 0
1612 1612 foreach l $llist {
1613 1613 if {$l == $x || [lsearch -exact $l $x] >= 0} {
1614 1614 return $i
1615 1615 }
1616 1616 incr i
1617 1617 }
1618 1618 return -1
1619 1619 }
1620 1620
1621 1621 proc drawmore {reading} {
1622 1622 global displayorder numcommits ncmupdate nextupdate
1623 1623 global stopped nhyperspace parents commitlisted
1624 1624 global maxwidth onscreen displist currentparents olddlevel
1625 1625
1626 1626 set n [llength $displayorder]
1627 1627 while {$numcommits < $n} {
1628 1628 set id [lindex $displayorder $numcommits]
1629 1629 set ctxend [expr {$numcommits + 10}]
1630 1630 if {!$reading && $ctxend > $n} {
1631 1631 set ctxend $n
1632 1632 }
1633 1633 set dlist {}
1634 1634 if {$numcommits > 0} {
1635 1635 set dlist [lreplace $displist $olddlevel $olddlevel]
1636 1636 set i $olddlevel
1637 1637 foreach p $currentparents {
1638 1638 if {$onscreen($p) == 0} {
1639 1639 set dlist [linsert $dlist $i $p]
1640 1640 incr i
1641 1641 }
1642 1642 }
1643 1643 }
1644 1644 set nohs {}
1645 1645 set reins {}
1646 1646 set isfat [expr {[llength $dlist] > $maxwidth}]
1647 1647 if {$nhyperspace > 0 || $isfat} {
1648 1648 if {$ctxend > $n} break
1649 1649 # work out what to bring back and
1650 1650 # what we want to don't want to send into hyperspace
1651 1651 set room 1
1652 1652 for {set k $numcommits} {$k < $ctxend} {incr k} {
1653 1653 set x [lindex $displayorder $k]
1654 1654 set i [llsearch $dlist $x]
1655 1655 if {$i < 0} {
1656 1656 set i [llength $dlist]
1657 1657 lappend dlist $x
1658 1658 }
1659 1659 if {[lsearch -exact $nohs $x] < 0} {
1660 1660 lappend nohs $x
1661 1661 }
1662 1662 if {$reins eq {} && $onscreen($x) < 0 && $room} {
1663 1663 set reins [list $x $i]
1664 1664 }
1665 1665 set newp {}
1666 1666 if {[info exists commitlisted($x)]} {
1667 1667 set right 0
1668 1668 foreach p $parents($x) {
1669 1669 if {[llsearch $dlist $p] < 0} {
1670 1670 lappend newp $p
1671 1671 if {[lsearch -exact $nohs $p] < 0} {
1672 1672 lappend nohs $p
1673 1673 }
1674 1674 if {$reins eq {} && $onscreen($p) < 0 && $room} {
1675 1675 set reins [list $p [expr {$i + $right}]]
1676 1676 }
1677 1677 }
1678 1678 set right 1
1679 1679 }
1680 1680 }
1681 1681 set l [lindex $dlist $i]
1682 1682 if {[llength $l] == 1} {
1683 1683 set l $newp
1684 1684 } else {
1685 1685 set j [lsearch -exact $l $x]
1686 1686 set l [concat [lreplace $l $j $j] $newp]
1687 1687 }
1688 1688 set dlist [lreplace $dlist $i $i $l]
1689 1689 if {$room && $isfat && [llength $newp] <= 1} {
1690 1690 set room 0
1691 1691 }
1692 1692 }
1693 1693 }
1694 1694
1695 1695 set dlevel [drawslants $id $reins $nohs]
1696 1696 drawcommitline $dlevel
1697 1697 if {[clock clicks -milliseconds] >= $nextupdate
1698 1698 && $numcommits >= $ncmupdate} {
1699 1699 doupdate $reading
1700 1700 if {$stopped} break
1701 1701 }
1702 1702 }
1703 1703 }
1704 1704
1705 1705 # level here is an index in todo
1706 1706 proc updatetodo {level noshortcut} {
1707 1707 global ncleft todo nnewparents
1708 1708 global commitlisted parents onscreen
1709 1709
1710 1710 set id [lindex $todo $level]
1711 1711 set olds {}
1712 1712 if {[info exists commitlisted($id)]} {
1713 1713 foreach p $parents($id) {
1714 1714 if {[lsearch -exact $olds $p] < 0} {
1715 1715 lappend olds $p
1716 1716 }
1717 1717 }
1718 1718 }
1719 1719 if {!$noshortcut && [llength $olds] == 1} {
1720 1720 set p [lindex $olds 0]
1721 1721 if {$ncleft($p) == 1 && [lsearch -exact $todo $p] < 0} {
1722 1722 set ncleft($p) 0
1723 1723 set todo [lreplace $todo $level $level $p]
1724 1724 set onscreen($p) 0
1725 1725 set nnewparents($id) 1
1726 1726 return 0
1727 1727 }
1728 1728 }
1729 1729
1730 1730 set todo [lreplace $todo $level $level]
1731 1731 set i $level
1732 1732 set n 0
1733 1733 foreach p $olds {
1734 1734 incr ncleft($p) -1
1735 1735 set k [lsearch -exact $todo $p]
1736 1736 if {$k < 0} {
1737 1737 set todo [linsert $todo $i $p]
1738 1738 set onscreen($p) 0
1739 1739 incr i
1740 1740 incr n
1741 1741 }
1742 1742 }
1743 1743 set nnewparents($id) $n
1744 1744
1745 1745 return 1
1746 1746 }
1747 1747
1748 1748 proc decidenext {{noread 0}} {
1749 1749 global ncleft todo
1750 1750 global datemode cdate
1751 1751 global commitinfo
1752 1752
1753 1753 # choose which one to do next time around
1754 1754 set todol [llength $todo]
1755 1755 set level -1
1756 1756 set latest {}
1757 1757 for {set k $todol} {[incr k -1] >= 0} {} {
1758 1758 set p [lindex $todo $k]
1759 1759 if {$ncleft($p) == 0} {
1760 1760 if {$datemode} {
1761 1761 if {![info exists commitinfo($p)]} {
1762 1762 if {$noread} {
1763 1763 return {}
1764 1764 }
1765 1765 readcommit $p
1766 1766 }
1767 1767 if {$latest == {} || $cdate($p) > $latest} {
1768 1768 set level $k
1769 1769 set latest $cdate($p)
1770 1770 }
1771 1771 } else {
1772 1772 set level $k
1773 1773 break
1774 1774 }
1775 1775 }
1776 1776 }
1777 1777 if {$level < 0} {
1778 1778 if {$todo != {}} {
1779 1779 puts "ERROR: none of the pending commits can be done yet:"
1780 1780 foreach p $todo {
1781 1781 puts " $p ($ncleft($p))"
1782 1782 }
1783 1783 }
1784 1784 return -1
1785 1785 }
1786 1786
1787 1787 return $level
1788 1788 }
1789 1789
1790 1790 proc drawcommit {id} {
1791 1791 global phase todo nchildren datemode nextupdate
1792 1792 global numcommits ncmupdate displayorder todo onscreen
1793 1793
1794 1794 if {$phase != "incrdraw"} {
1795 1795 set phase incrdraw
1796 1796 set displayorder {}
1797 1797 set todo {}
1798 1798 initgraph
1799 1799 }
1800 1800 if {$nchildren($id) == 0} {
1801 1801 lappend todo $id
1802 1802 set onscreen($id) 0
1803 1803 }
1804 1804 set level [decidenext 1]
1805 1805 if {$level == {} || $id != [lindex $todo $level]} {
1806 1806 return
1807 1807 }
1808 1808 while 1 {
1809 1809 lappend displayorder [lindex $todo $level]
1810 1810 if {[updatetodo $level $datemode]} {
1811 1811 set level [decidenext 1]
1812 1812 if {$level == {}} break
1813 1813 }
1814 1814 set id [lindex $todo $level]
1815 1815 if {![info exists commitlisted($id)]} {
1816 1816 break
1817 1817 }
1818 1818 }
1819 1819 drawmore 1
1820 1820 }
1821 1821
1822 1822 proc finishcommits {} {
1823 1823 global phase
1824 1824 global canv mainfont ctext maincursor textcursor
1825 1825
1826 1826 if {$phase != "incrdraw"} {
1827 1827 $canv delete all
1828 1828 $canv create text 3 3 -anchor nw -text "No commits selected" \
1829 1829 -font $mainfont -tags textitems
1830 1830 set phase {}
1831 1831 } else {
1832 1832 drawrest
1833 1833 }
1834 1834 . config -cursor $maincursor
1835 1835 settextcursor $textcursor
1836 1836 }
1837 1837
1838 1838 # Don't change the text pane cursor if it is currently the hand cursor,
1839 1839 # showing that we are over a sha1 ID link.
1840 1840 proc settextcursor {c} {
1841 1841 global ctext curtextcursor
1842 1842
1843 1843 if {[$ctext cget -cursor] == $curtextcursor} {
1844 1844 $ctext config -cursor $c
1845 1845 }
1846 1846 set curtextcursor $c
1847 1847 }
1848 1848
1849 1849 proc drawgraph {} {
1850 1850 global nextupdate startmsecs ncmupdate
1851 1851 global displayorder onscreen
1852 1852
1853 1853 if {$displayorder == {}} return
1854 1854 set startmsecs [clock clicks -milliseconds]
1855 1855 set nextupdate [expr $startmsecs + 100]
1856 1856 set ncmupdate 1
1857 1857 initgraph
1858 1858 foreach id $displayorder {
1859 1859 set onscreen($id) 0
1860 1860 }
1861 1861 drawmore 0
1862 1862 }
1863 1863
1864 1864 proc drawrest {} {
1865 1865 global phase stopped redisplaying selectedline
1866 1866 global datemode todo displayorder
1867 1867 global numcommits ncmupdate
1868 1868 global nextupdate startmsecs
1869 1869
1870 1870 set level [decidenext]
1871 1871 if {$level >= 0} {
1872 1872 set phase drawgraph
1873 1873 while 1 {
1874 1874 lappend displayorder [lindex $todo $level]
1875 1875 set hard [updatetodo $level $datemode]
1876 1876 if {$hard} {
1877 1877 set level [decidenext]
1878 1878 if {$level < 0} break
1879 1879 }
1880 1880 }
1881 1881 drawmore 0
1882 1882 }
1883 1883 set phase {}
1884 1884 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1885 1885 #puts "overall $drawmsecs ms for $numcommits commits"
1886 1886 if {$redisplaying} {
1887 1887 if {$stopped == 0 && [info exists selectedline]} {
1888 1888 selectline $selectedline 0
1889 1889 }
1890 1890 if {$stopped == 1} {
1891 1891 set stopped 0
1892 1892 after idle drawgraph
1893 1893 } else {
1894 1894 set redisplaying 0
1895 1895 }
1896 1896 }
1897 1897 }
1898 1898
1899 1899 proc findmatches {f} {
1900 1900 global findtype foundstring foundstrlen
1901 1901 if {$findtype == "Regexp"} {
1902 1902 set matches [regexp -indices -all -inline $foundstring $f]
1903 1903 } else {
1904 1904 if {$findtype == "IgnCase"} {
1905 1905 set str [string tolower $f]
1906 1906 } else {
1907 1907 set str $f
1908 1908 }
1909 1909 set matches {}
1910 1910 set i 0
1911 1911 while {[set j [string first $foundstring $str $i]] >= 0} {
1912 1912 lappend matches [list $j [expr $j+$foundstrlen-1]]
1913 1913 set i [expr $j + $foundstrlen]
1914 1914 }
1915 1915 }
1916 1916 return $matches
1917 1917 }
1918 1918
1919 1919 proc dofind {} {
1920 1920 global findtype findloc findstring markedmatches commitinfo
1921 1921 global numcommits lineid linehtag linentag linedtag
1922 1922 global mainfont namefont canv canv2 canv3 selectedline
1923 1923 global matchinglines foundstring foundstrlen
1924 1924
1925 1925 stopfindproc
1926 1926 unmarkmatches
1927 1927 focus .
1928 1928 set matchinglines {}
1929 1929 if {$findloc == "Pickaxe"} {
1930 1930 findpatches
1931 1931 return
1932 1932 }
1933 1933 if {$findtype == "IgnCase"} {
1934 1934 set foundstring [string tolower $findstring]
1935 1935 } else {
1936 1936 set foundstring $findstring
1937 1937 }
1938 1938 set foundstrlen [string length $findstring]
1939 1939 if {$foundstrlen == 0} return
1940 1940 if {$findloc == "Files"} {
1941 1941 findfiles
1942 1942 return
1943 1943 }
1944 1944 if {![info exists selectedline]} {
1945 1945 set oldsel -1
1946 1946 } else {
1947 1947 set oldsel $selectedline
1948 1948 }
1949 1949 set didsel 0
1950 1950 set fldtypes {Headline Author Date CDate Comment}
1951 1951 for {set l 0} {$l < $numcommits} {incr l} {
1952 1952 set id $lineid($l)
1953 1953 set info $commitinfo($id)
1954 1954 set doesmatch 0
1955 1955 foreach f $info ty $fldtypes {
1956 1956 if {$findloc != "All fields" && $findloc != $ty} {
1957 1957 continue
1958 1958 }
1959 1959 set matches [findmatches $f]
1960 1960 if {$matches == {}} continue
1961 1961 set doesmatch 1
1962 1962 if {$ty == "Headline"} {
1963 1963 markmatches $canv $l $f $linehtag($l) $matches $mainfont
1964 1964 } elseif {$ty == "Author"} {
1965 1965 markmatches $canv2 $l $f $linentag($l) $matches $namefont
1966 1966 } elseif {$ty == "Date"} {
1967 1967 markmatches $canv3 $l $f $linedtag($l) $matches $mainfont
1968 1968 }
1969 1969 }
1970 1970 if {$doesmatch} {
1971 1971 lappend matchinglines $l
1972 1972 if {!$didsel && $l > $oldsel} {
1973 1973 findselectline $l
1974 1974 set didsel 1
1975 1975 }
1976 1976 }
1977 1977 }
1978 1978 if {$matchinglines == {}} {
1979 1979 bell
1980 1980 } elseif {!$didsel} {
1981 1981 findselectline [lindex $matchinglines 0]
1982 1982 }
1983 1983 }
1984 1984
1985 1985 proc findselectline {l} {
1986 1986 global findloc commentend ctext
1987 1987 selectline $l 1
1988 1988 if {$findloc == "All fields" || $findloc == "Comments"} {
1989 1989 # highlight the matches in the comments
1990 1990 set f [$ctext get 1.0 $commentend]
1991 1991 set matches [findmatches $f]
1992 1992 foreach match $matches {
1993 1993 set start [lindex $match 0]
1994 1994 set end [expr [lindex $match 1] + 1]
1995 1995 $ctext tag add found "1.0 + $start c" "1.0 + $end c"
1996 1996 }
1997 1997 }
1998 1998 }
1999 1999
2000 2000 proc findnext {restart} {
2001 2001 global matchinglines selectedline
2002 2002 if {![info exists matchinglines]} {
2003 2003 if {$restart} {
2004 2004 dofind
2005 2005 }
2006 2006 return
2007 2007 }
2008 2008 if {![info exists selectedline]} return
2009 2009 foreach l $matchinglines {
2010 2010 if {$l > $selectedline} {
2011 2011 findselectline $l
2012 2012 return
2013 2013 }
2014 2014 }
2015 2015 bell
2016 2016 }
2017 2017
2018 2018 proc findprev {} {
2019 2019 global matchinglines selectedline
2020 2020 if {![info exists matchinglines]} {
2021 2021 dofind
2022 2022 return
2023 2023 }
2024 2024 if {![info exists selectedline]} return
2025 2025 set prev {}
2026 2026 foreach l $matchinglines {
2027 2027 if {$l >= $selectedline} break
2028 2028 set prev $l
2029 2029 }
2030 2030 if {$prev != {}} {
2031 2031 findselectline $prev
2032 2032 } else {
2033 2033 bell
2034 2034 }
2035 2035 }
2036 2036
2037 2037 proc findlocchange {name ix op} {
2038 2038 global findloc findtype findtypemenu
2039 2039 if {$findloc == "Pickaxe"} {
2040 2040 set findtype Exact
2041 2041 set state disabled
2042 2042 } else {
2043 2043 set state normal
2044 2044 }
2045 2045 $findtypemenu entryconf 1 -state $state
2046 2046 $findtypemenu entryconf 2 -state $state
2047 2047 }
2048 2048
2049 2049 proc stopfindproc {{done 0}} {
2050 2050 global findprocpid findprocfile findids
2051 2051 global ctext findoldcursor phase maincursor textcursor
2052 2052 global findinprogress
2053 2053
2054 2054 catch {unset findids}
2055 2055 if {[info exists findprocpid]} {
2056 2056 if {!$done} {
2057 2057 catch {exec kill $findprocpid}
2058 2058 }
2059 2059 catch {close $findprocfile}
2060 2060 unset findprocpid
2061 2061 }
2062 2062 if {[info exists findinprogress]} {
2063 2063 unset findinprogress
2064 2064 if {$phase != "incrdraw"} {
2065 2065 . config -cursor $maincursor
2066 2066 settextcursor $textcursor
2067 2067 }
2068 2068 }
2069 2069 }
2070 2070
2071 2071 proc findpatches {} {
2072 2072 global findstring selectedline numcommits
2073 2073 global findprocpid findprocfile
2074 2074 global finddidsel ctext lineid findinprogress
2075 2075 global findinsertpos
2076 2076 global env
2077 2077
2078 2078 if {$numcommits == 0} return
2079 2079
2080 2080 # make a list of all the ids to search, starting at the one
2081 2081 # after the selected line (if any)
2082 2082 if {[info exists selectedline]} {
2083 2083 set l $selectedline
2084 2084 } else {
2085 2085 set l -1
2086 2086 }
2087 2087 set inputids {}
2088 2088 for {set i 0} {$i < $numcommits} {incr i} {
2089 2089 if {[incr l] >= $numcommits} {
2090 2090 set l 0
2091 2091 }
2092 2092 append inputids $lineid($l) "\n"
2093 2093 }
2094 2094
2095 2095 if {[catch {
2096 2096 set f [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree --stdin -s -r -S$findstring << $inputids] r]
2097 2097 } err]} {
2098 2098 error_popup "Error starting search process: $err"
2099 2099 return
2100 2100 }
2101 2101
2102 2102 set findinsertpos end
2103 2103 set findprocfile $f
2104 2104 set findprocpid [pid $f]
2105 2105 fconfigure $f -blocking 0
2106 2106 fileevent $f readable readfindproc
2107 2107 set finddidsel 0
2108 2108 . config -cursor watch
2109 2109 settextcursor watch
2110 2110 set findinprogress 1
2111 2111 }
2112 2112
2113 2113 proc readfindproc {} {
2114 2114 global findprocfile finddidsel
2115 2115 global idline matchinglines findinsertpos
2116 2116
2117 2117 set n [gets $findprocfile line]
2118 2118 if {$n < 0} {
2119 2119 if {[eof $findprocfile]} {
2120 2120 stopfindproc 1
2121 2121 if {!$finddidsel} {
2122 2122 bell
2123 2123 }
2124 2124 }
2125 2125 return
2126 2126 }
2127 2127 if {![regexp {^[0-9a-f]{12}} $line id]} {
2128 2128 error_popup "Can't parse git-diff-tree output: $line"
2129 2129 stopfindproc
2130 2130 return
2131 2131 }
2132 2132 if {![info exists idline($id)]} {
2133 2133 puts stderr "spurious id: $id"
2134 2134 return
2135 2135 }
2136 2136 set l $idline($id)
2137 2137 insertmatch $l $id
2138 2138 }
2139 2139
2140 2140 proc insertmatch {l id} {
2141 2141 global matchinglines findinsertpos finddidsel
2142 2142
2143 2143 if {$findinsertpos == "end"} {
2144 2144 if {$matchinglines != {} && $l < [lindex $matchinglines 0]} {
2145 2145 set matchinglines [linsert $matchinglines 0 $l]
2146 2146 set findinsertpos 1
2147 2147 } else {
2148 2148 lappend matchinglines $l
2149 2149 }
2150 2150 } else {
2151 2151 set matchinglines [linsert $matchinglines $findinsertpos $l]
2152 2152 incr findinsertpos
2153 2153 }
2154 2154 markheadline $l $id
2155 2155 if {!$finddidsel} {
2156 2156 findselectline $l
2157 2157 set finddidsel 1
2158 2158 }
2159 2159 }
2160 2160
2161 2161 proc findfiles {} {
2162 2162 global selectedline numcommits lineid ctext
2163 2163 global ffileline finddidsel parents nparents
2164 2164 global findinprogress findstartline findinsertpos
2165 2165 global treediffs fdiffids fdiffsneeded fdiffpos
2166 2166 global findmergefiles
2167 2167 global env
2168 2168
2169 2169 if {$numcommits == 0} return
2170 2170
2171 2171 if {[info exists selectedline]} {
2172 2172 set l [expr {$selectedline + 1}]
2173 2173 } else {
2174 2174 set l 0
2175 2175 }
2176 2176 set ffileline $l
2177 2177 set findstartline $l
2178 2178 set diffsneeded {}
2179 2179 set fdiffsneeded {}
2180 2180 while 1 {
2181 2181 set id $lineid($l)
2182 2182 if {$findmergefiles || $nparents($id) == 1} {
2183 2183 foreach p $parents($id) {
2184 2184 if {![info exists treediffs([list $id $p])]} {
2185 2185 append diffsneeded "$id $p\n"
2186 2186 lappend fdiffsneeded [list $id $p]
2187 2187 }
2188 2188 }
2189 2189 }
2190 2190 if {[incr l] >= $numcommits} {
2191 2191 set l 0
2192 2192 }
2193 2193 if {$l == $findstartline} break
2194 2194 }
2195 2195
2196 2196 # start off a git-diff-tree process if needed
2197 2197 if {$diffsneeded ne {}} {
2198 2198 if {[catch {
2199 2199 set df [open [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r --stdin << $diffsneeded] r]
2200 2200 } err ]} {
2201 2201 error_popup "Error starting search process: $err"
2202 2202 return
2203 2203 }
2204 2204 catch {unset fdiffids}
2205 2205 set fdiffpos 0
2206 2206 fconfigure $df -blocking 0
2207 2207 fileevent $df readable [list readfilediffs $df]
2208 2208 }
2209 2209
2210 2210 set finddidsel 0
2211 2211 set findinsertpos end
2212 2212 set id $lineid($l)
2213 2213 set p [lindex $parents($id) 0]
2214 2214 . config -cursor watch
2215 2215 settextcursor watch
2216 2216 set findinprogress 1
2217 2217 findcont [list $id $p]
2218 2218 update
2219 2219 }
2220 2220
2221 2221 proc readfilediffs {df} {
2222 2222 global findids fdiffids fdiffs
2223 2223
2224 2224 set n [gets $df line]
2225 2225 if {$n < 0} {
2226 2226 if {[eof $df]} {
2227 2227 donefilediff
2228 2228 if {[catch {close $df} err]} {
2229 2229 stopfindproc
2230 2230 bell
2231 2231 error_popup "Error in hg debug-diff-tree: $err"
2232 2232 } elseif {[info exists findids]} {
2233 2233 set ids $findids
2234 2234 stopfindproc
2235 2235 bell
2236 2236 error_popup "Couldn't find diffs for {$ids}"
2237 2237 }
2238 2238 }
2239 2239 return
2240 2240 }
2241 2241 if {[regexp {^([0-9a-f]{12}) \(from ([0-9a-f]{12})\)} $line match id p]} {
2242 2242 # start of a new string of diffs
2243 2243 donefilediff
2244 2244 set fdiffids [list $id $p]
2245 2245 set fdiffs {}
2246 2246 } elseif {[string match ":*" $line]} {
2247 2247 lappend fdiffs [lindex $line 5]
2248 2248 }
2249 2249 }
2250 2250
2251 2251 proc donefilediff {} {
2252 2252 global fdiffids fdiffs treediffs findids
2253 2253 global fdiffsneeded fdiffpos
2254 2254
2255 2255 if {[info exists fdiffids]} {
2256 2256 while {[lindex $fdiffsneeded $fdiffpos] ne $fdiffids
2257 2257 && $fdiffpos < [llength $fdiffsneeded]} {
2258 2258 # git-diff-tree doesn't output anything for a commit
2259 2259 # which doesn't change anything
2260 2260 set nullids [lindex $fdiffsneeded $fdiffpos]
2261 2261 set treediffs($nullids) {}
2262 2262 if {[info exists findids] && $nullids eq $findids} {
2263 2263 unset findids
2264 2264 findcont $nullids
2265 2265 }
2266 2266 incr fdiffpos
2267 2267 }
2268 2268 incr fdiffpos
2269 2269
2270 2270 if {![info exists treediffs($fdiffids)]} {
2271 2271 set treediffs($fdiffids) $fdiffs
2272 2272 }
2273 2273 if {[info exists findids] && $fdiffids eq $findids} {
2274 2274 unset findids
2275 2275 findcont $fdiffids
2276 2276 }
2277 2277 }
2278 2278 }
2279 2279
2280 2280 proc findcont {ids} {
2281 2281 global findids treediffs parents nparents
2282 2282 global ffileline findstartline finddidsel
2283 2283 global lineid numcommits matchinglines findinprogress
2284 2284 global findmergefiles
2285 2285
2286 2286 set id [lindex $ids 0]
2287 2287 set p [lindex $ids 1]
2288 2288 set pi [lsearch -exact $parents($id) $p]
2289 2289 set l $ffileline
2290 2290 while 1 {
2291 2291 if {$findmergefiles || $nparents($id) == 1} {
2292 2292 if {![info exists treediffs($ids)]} {
2293 2293 set findids $ids
2294 2294 set ffileline $l
2295 2295 return
2296 2296 }
2297 2297 set doesmatch 0
2298 2298 foreach f $treediffs($ids) {
2299 2299 set x [findmatches $f]
2300 2300 if {$x != {}} {
2301 2301 set doesmatch 1
2302 2302 break
2303 2303 }
2304 2304 }
2305 2305 if {$doesmatch} {
2306 2306 insertmatch $l $id
2307 2307 set pi $nparents($id)
2308 2308 }
2309 2309 } else {
2310 2310 set pi $nparents($id)
2311 2311 }
2312 2312 if {[incr pi] >= $nparents($id)} {
2313 2313 set pi 0
2314 2314 if {[incr l] >= $numcommits} {
2315 2315 set l 0
2316 2316 }
2317 2317 if {$l == $findstartline} break
2318 2318 set id $lineid($l)
2319 2319 }
2320 2320 set p [lindex $parents($id) $pi]
2321 2321 set ids [list $id $p]
2322 2322 }
2323 2323 stopfindproc
2324 2324 if {!$finddidsel} {
2325 2325 bell
2326 2326 }
2327 2327 }
2328 2328
2329 2329 # mark a commit as matching by putting a yellow background
2330 2330 # behind the headline
2331 2331 proc markheadline {l id} {
2332 2332 global canv mainfont linehtag commitinfo
2333 2333
2334 2334 set bbox [$canv bbox $linehtag($l)]
2335 2335 set t [$canv create rect $bbox -outline {} -tags matches -fill yellow]
2336 2336 $canv lower $t
2337 2337 }
2338 2338
2339 2339 # mark the bits of a headline, author or date that match a find string
2340 2340 proc markmatches {canv l str tag matches font} {
2341 2341 set bbox [$canv bbox $tag]
2342 2342 set x0 [lindex $bbox 0]
2343 2343 set y0 [lindex $bbox 1]
2344 2344 set y1 [lindex $bbox 3]
2345 2345 foreach match $matches {
2346 2346 set start [lindex $match 0]
2347 2347 set end [lindex $match 1]
2348 2348 if {$start > $end} continue
2349 2349 set xoff [font measure $font [string range $str 0 [expr $start-1]]]
2350 2350 set xlen [font measure $font [string range $str 0 [expr $end]]]
2351 2351 set t [$canv create rect [expr $x0+$xoff] $y0 [expr $x0+$xlen+2] $y1 \
2352 2352 -outline {} -tags matches -fill yellow]
2353 2353 $canv lower $t
2354 2354 }
2355 2355 }
2356 2356
2357 2357 proc unmarkmatches {} {
2358 2358 global matchinglines findids
2359 2359 allcanvs delete matches
2360 2360 catch {unset matchinglines}
2361 2361 catch {unset findids}
2362 2362 }
2363 2363
2364 2364 proc selcanvline {w x y} {
2365 2365 global canv canvy0 ctext linespc
2366 2366 global lineid linehtag linentag linedtag rowtextx
2367 2367 set ymax [lindex [$canv cget -scrollregion] 3]
2368 2368 if {$ymax == {}} return
2369 2369 set yfrac [lindex [$canv yview] 0]
2370 2370 set y [expr {$y + $yfrac * $ymax}]
2371 2371 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}]
2372 2372 if {$l < 0} {
2373 2373 set l 0
2374 2374 }
2375 2375 if {$w eq $canv} {
2376 2376 if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
2377 2377 }
2378 2378 unmarkmatches
2379 2379 selectline $l 1
2380 2380 }
2381 2381
2382 2382 proc commit_descriptor {p} {
2383 2383 global commitinfo
2384 2384 set l "..."
2385 2385 if {[info exists commitinfo($p)]} {
2386 2386 set l [lindex $commitinfo($p) 0]
2387 2387 set r [lindex $commitinfo($p) 6]
2388 2388 }
2389 2389 return "$r:$p ($l)"
2390 2390 }
2391 2391
2392 2392 # append some text to the ctext widget, and make any SHA1 ID
2393 2393 # that we know about be a clickable link.
2394 2394 proc appendwithlinks {text} {
2395 2395 global ctext idline linknum
2396 2396
2397 2397 set start [$ctext index "end - 1c"]
2398 2398 $ctext insert end $text
2399 2399 $ctext insert end "\n"
2400 2400 set links [regexp -indices -all -inline {[0-9a-f]{12}} $text]
2401 2401 foreach l $links {
2402 2402 set s [lindex $l 0]
2403 2403 set e [lindex $l 1]
2404 2404 set linkid [string range $text $s $e]
2405 2405 if {![info exists idline($linkid)]} continue
2406 2406 incr e
2407 2407 $ctext tag add link "$start + $s c" "$start + $e c"
2408 2408 $ctext tag add link$linknum "$start + $s c" "$start + $e c"
2409 2409 $ctext tag bind link$linknum <1> [list selectline $idline($linkid) 1]
2410 2410 incr linknum
2411 2411 }
2412 2412 $ctext tag conf link -foreground blue -underline 1
2413 2413 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
2414 2414 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2415 2415 }
2416 2416
2417 2417 proc selectline {l isnew} {
2418 2418 global canv canv2 canv3 ctext commitinfo selectedline
2419 2419 global lineid linehtag linentag linedtag
2420 2420 global canvy0 linespc parents nparents children
2421 2421 global cflist currentid sha1entry
2422 2422 global commentend idtags idbookmarks idline linknum
2423 2423
2424 2424 $canv delete hover
2425 2425 normalline
2426 2426 if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
2427 2427 $canv delete secsel
2428 2428 set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \
2429 2429 -tags secsel -fill [$canv cget -selectbackground]]
2430 2430 $canv lower $t
2431 2431 $canv2 delete secsel
2432 2432 set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \
2433 2433 -tags secsel -fill [$canv2 cget -selectbackground]]
2434 2434 $canv2 lower $t
2435 2435 $canv3 delete secsel
2436 2436 set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \
2437 2437 -tags secsel -fill [$canv3 cget -selectbackground]]
2438 2438 $canv3 lower $t
2439 2439 set y [expr {$canvy0 + $l * $linespc}]
2440 2440 set ymax [lindex [$canv cget -scrollregion] 3]
2441 2441 set ytop [expr {$y - $linespc - 1}]
2442 2442 set ybot [expr {$y + $linespc + 1}]
2443 2443 set wnow [$canv yview]
2444 2444 set wtop [expr [lindex $wnow 0] * $ymax]
2445 2445 set wbot [expr [lindex $wnow 1] * $ymax]
2446 2446 set wh [expr {$wbot - $wtop}]
2447 2447 set newtop $wtop
2448 2448 if {$ytop < $wtop} {
2449 2449 if {$ybot < $wtop} {
2450 2450 set newtop [expr {$y - $wh / 2.0}]
2451 2451 } else {
2452 2452 set newtop $ytop
2453 2453 if {$newtop > $wtop - $linespc} {
2454 2454 set newtop [expr {$wtop - $linespc}]
2455 2455 }
2456 2456 }
2457 2457 } elseif {$ybot > $wbot} {
2458 2458 if {$ytop > $wbot} {
2459 2459 set newtop [expr {$y - $wh / 2.0}]
2460 2460 } else {
2461 2461 set newtop [expr {$ybot - $wh}]
2462 2462 if {$newtop < $wtop + $linespc} {
2463 2463 set newtop [expr {$wtop + $linespc}]
2464 2464 }
2465 2465 }
2466 2466 }
2467 2467 if {$newtop != $wtop} {
2468 2468 if {$newtop < 0} {
2469 2469 set newtop 0
2470 2470 }
2471 2471 allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
2472 2472 }
2473 2473
2474 2474 if {$isnew} {
2475 2475 addtohistory [list selectline $l 0]
2476 2476 }
2477 2477
2478 2478 set selectedline $l
2479 2479
2480 2480 set id $lineid($l)
2481 2481 set currentid $id
2482 2482 $sha1entry delete 0 end
2483 2483 $sha1entry insert 0 $id
2484 2484 $sha1entry selection range 0 end
2485 2485
2486 2486 $ctext conf -state normal
2487 2487 $ctext delete 0.0 end
2488 2488 set linknum 0
2489 2489 $ctext mark set fmark.0 0.0
2490 2490 $ctext mark gravity fmark.0 left
2491 2491 set info $commitinfo($id)
2492 2492 $ctext insert end "Changeset: [lindex $info 6]\n"
2493 2493 if {[llength [lindex $info 7]] > 0} {
2494 2494 $ctext insert end "Branch: [lindex $info 7]\n"
2495 2495 }
2496 2496 $ctext insert end "User: [lindex $info 1]\n"
2497 2497 $ctext insert end "Date: [lindex $info 2]\n"
2498 2498 if {[info exists idbookmarks($id)]} {
2499 2499 $ctext insert end "Bookmarks:"
2500 2500 foreach bookmark $idbookmarks($id) {
2501 2501 $ctext insert end " $bookmark"
2502 2502 }
2503 2503 $ctext insert end "\n"
2504 2504 }
2505 2505
2506 2506 if {[info exists idtags($id)]} {
2507 2507 $ctext insert end "Tags:"
2508 2508 foreach tag $idtags($id) {
2509 2509 $ctext insert end " $tag"
2510 2510 }
2511 2511 $ctext insert end "\n"
2512 2512 }
2513 2513
2514 2514 set comment {}
2515 2515 if {[info exists parents($id)]} {
2516 2516 foreach p $parents($id) {
2517 2517 append comment "Parent: [commit_descriptor $p]\n"
2518 2518 }
2519 2519 }
2520 2520 if {[info exists children($id)]} {
2521 2521 foreach c $children($id) {
2522 2522 append comment "Child: [commit_descriptor $c]\n"
2523 2523 }
2524 2524 }
2525 2525 append comment "\n"
2526 2526 append comment [lindex $info 5]
2527 2527
2528 2528 # make anything that looks like a SHA1 ID be a clickable link
2529 2529 appendwithlinks $comment
2530 2530
2531 2531 $ctext tag delete Comments
2532 2532 $ctext tag remove found 1.0 end
2533 2533 $ctext conf -state disabled
2534 2534 set commentend [$ctext index "end - 1c"]
2535 2535
2536 2536 $cflist delete 0 end
2537 2537 $cflist insert end "Comments"
2538 2538 if {$nparents($id) <= 1} {
2539 2539 set parent "null"
2540 2540 if {$nparents($id) == 1} {
2541 2541 set parent $parents($id)
2542 2542 }
2543 2543 startdiff [concat $id $parent]
2544 2544 } elseif {$nparents($id) > 1} {
2545 2545 mergediff $id
2546 2546 }
2547 2547 }
2548 2548
2549 2549 proc selnextline {dir} {
2550 2550 global selectedline
2551 2551 if {![info exists selectedline]} return
2552 2552 set l [expr $selectedline + $dir]
2553 2553 unmarkmatches
2554 2554 selectline $l 1
2555 2555 }
2556 2556
2557 2557 proc unselectline {} {
2558 2558 global selectedline
2559 2559
2560 2560 catch {unset selectedline}
2561 2561 allcanvs delete secsel
2562 2562 }
2563 2563
2564 2564 proc addtohistory {cmd} {
2565 2565 global history historyindex
2566 2566
2567 2567 if {$historyindex > 0
2568 2568 && [lindex $history [expr {$historyindex - 1}]] == $cmd} {
2569 2569 return
2570 2570 }
2571 2571
2572 2572 if {$historyindex < [llength $history]} {
2573 2573 set history [lreplace $history $historyindex end $cmd]
2574 2574 } else {
2575 2575 lappend history $cmd
2576 2576 }
2577 2577 incr historyindex
2578 2578 if {$historyindex > 1} {
2579 2579 .ctop.top.bar.leftbut conf -state normal
2580 2580 } else {
2581 2581 .ctop.top.bar.leftbut conf -state disabled
2582 2582 }
2583 2583 .ctop.top.bar.rightbut conf -state disabled
2584 2584 }
2585 2585
2586 2586 proc goback {} {
2587 2587 global history historyindex
2588 2588
2589 2589 if {$historyindex > 1} {
2590 2590 incr historyindex -1
2591 2591 set cmd [lindex $history [expr {$historyindex - 1}]]
2592 2592 eval $cmd
2593 2593 .ctop.top.bar.rightbut conf -state normal
2594 2594 }
2595 2595 if {$historyindex <= 1} {
2596 2596 .ctop.top.bar.leftbut conf -state disabled
2597 2597 }
2598 2598 }
2599 2599
2600 2600 proc goforw {} {
2601 2601 global history historyindex
2602 2602
2603 2603 if {$historyindex < [llength $history]} {
2604 2604 set cmd [lindex $history $historyindex]
2605 2605 incr historyindex
2606 2606 eval $cmd
2607 2607 .ctop.top.bar.leftbut conf -state normal
2608 2608 }
2609 2609 if {$historyindex >= [llength $history]} {
2610 2610 .ctop.top.bar.rightbut conf -state disabled
2611 2611 }
2612 2612 }
2613 2613
2614 2614 proc mergediff {id} {
2615 2615 global parents diffmergeid diffmergegca mergefilelist diffpindex
2616 2616
2617 2617 set diffmergeid $id
2618 2618 set diffpindex -1
2619 2619 set diffmergegca [findgca $parents($id)]
2620 2620 if {[info exists mergefilelist($id)]} {
2621 2621 if {$mergefilelist($id) ne {}} {
2622 2622 showmergediff
2623 2623 }
2624 2624 } else {
2625 2625 contmergediff {}
2626 2626 }
2627 2627 }
2628 2628
2629 2629 proc findgca {ids} {
2630 2630 global env
2631 2631 set gca {}
2632 2632 foreach id $ids {
2633 2633 if {$gca eq {}} {
2634 2634 set gca $id
2635 2635 } else {
2636 2636 if {[catch {
2637 2637 set gca [exec $env(HG) --config ui.report_untrusted=false debug-merge-base $gca $id]
2638 2638 } err]} {
2639 2639 return {}
2640 2640 }
2641 2641 }
2642 2642 }
2643 2643 return $gca
2644 2644 }
2645 2645
2646 2646 proc contmergediff {ids} {
2647 2647 global diffmergeid diffpindex parents nparents diffmergegca
2648 2648 global treediffs mergefilelist diffids treepending
2649 2649
2650 2650 # diff the child against each of the parents, and diff
2651 2651 # each of the parents against the GCA.
2652 2652 while 1 {
2653 2653 if {[lindex $ids 0] == $diffmergeid && $diffmergegca ne {}} {
2654 2654 set ids [list [lindex $ids 1] $diffmergegca]
2655 2655 } else {
2656 2656 if {[incr diffpindex] >= $nparents($diffmergeid)} break
2657 2657 set p [lindex $parents($diffmergeid) $diffpindex]
2658 2658 set ids [list $diffmergeid $p]
2659 2659 }
2660 2660 if {![info exists treediffs($ids)]} {
2661 2661 set diffids $ids
2662 2662 if {![info exists treepending]} {
2663 2663 gettreediffs $ids
2664 2664 }
2665 2665 return
2666 2666 }
2667 2667 }
2668 2668
2669 2669 # If a file in some parent is different from the child and also
2670 2670 # different from the GCA, then it's interesting.
2671 2671 # If we don't have a GCA, then a file is interesting if it is
2672 2672 # different from the child in all the parents.
2673 2673 if {$diffmergegca ne {}} {
2674 2674 set files {}
2675 2675 foreach p $parents($diffmergeid) {
2676 2676 set gcadiffs $treediffs([list $p $diffmergegca])
2677 2677 foreach f $treediffs([list $diffmergeid $p]) {
2678 2678 if {[lsearch -exact $files $f] < 0
2679 2679 && [lsearch -exact $gcadiffs $f] >= 0} {
2680 2680 lappend files $f
2681 2681 }
2682 2682 }
2683 2683 }
2684 2684 set files [lsort $files]
2685 2685 } else {
2686 2686 set p [lindex $parents($diffmergeid) 0]
2687 2687 set files $treediffs([list $diffmergeid $p])
2688 2688 for {set i 1} {$i < $nparents($diffmergeid) && $files ne {}} {incr i} {
2689 2689 set p [lindex $parents($diffmergeid) $i]
2690 2690 set df $treediffs([list $diffmergeid $p])
2691 2691 set nf {}
2692 2692 foreach f $files {
2693 2693 if {[lsearch -exact $df $f] >= 0} {
2694 2694 lappend nf $f
2695 2695 }
2696 2696 }
2697 2697 set files $nf
2698 2698 }
2699 2699 }
2700 2700
2701 2701 set mergefilelist($diffmergeid) $files
2702 2702 if {$files ne {}} {
2703 2703 showmergediff
2704 2704 }
2705 2705 }
2706 2706
2707 2707 proc showmergediff {} {
2708 2708 global cflist diffmergeid mergefilelist parents
2709 2709 global diffopts diffinhunk currentfile currenthunk filelines
2710 2710 global diffblocked groupfilelast mergefds groupfilenum grouphunks
2711 2711 global env
2712 2712
2713 2713 set files $mergefilelist($diffmergeid)
2714 2714 foreach f $files {
2715 2715 $cflist insert end $f
2716 2716 }
2717 2717 set env(GIT_DIFF_OPTS) $diffopts
2718 2718 set flist {}
2719 2719 catch {unset currentfile}
2720 2720 catch {unset currenthunk}
2721 2721 catch {unset filelines}
2722 2722 catch {unset groupfilenum}
2723 2723 catch {unset grouphunks}
2724 2724 set groupfilelast -1
2725 2725 foreach p $parents($diffmergeid) {
2726 2726 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $p $diffmergeid]
2727 2727 set cmd [concat $cmd $mergefilelist($diffmergeid)]
2728 2728 if {[catch {set f [open $cmd r]} err]} {
2729 2729 error_popup "Error getting diffs: $err"
2730 2730 foreach f $flist {
2731 2731 catch {close $f}
2732 2732 }
2733 2733 return
2734 2734 }
2735 2735 lappend flist $f
2736 2736 set ids [list $diffmergeid $p]
2737 2737 set mergefds($ids) $f
2738 2738 set diffinhunk($ids) 0
2739 2739 set diffblocked($ids) 0
2740 2740 fconfigure $f -blocking 0
2741 2741 fileevent $f readable [list getmergediffline $f $ids $diffmergeid]
2742 2742 }
2743 2743 }
2744 2744
2745 2745 proc getmergediffline {f ids id} {
2746 2746 global diffmergeid diffinhunk diffoldlines diffnewlines
2747 2747 global currentfile currenthunk
2748 2748 global diffoldstart diffnewstart diffoldlno diffnewlno
2749 2749 global diffblocked mergefilelist
2750 2750 global noldlines nnewlines difflcounts filelines
2751 2751
2752 2752 set n [gets $f line]
2753 2753 if {$n < 0} {
2754 2754 if {![eof $f]} return
2755 2755 }
2756 2756
2757 2757 if {!([info exists diffmergeid] && $diffmergeid == $id)} {
2758 2758 if {$n < 0} {
2759 2759 close $f
2760 2760 }
2761 2761 return
2762 2762 }
2763 2763
2764 2764 if {$diffinhunk($ids) != 0} {
2765 2765 set fi $currentfile($ids)
2766 2766 if {$n > 0 && [regexp {^[-+ \\]} $line match]} {
2767 2767 # continuing an existing hunk
2768 2768 set line [string range $line 1 end]
2769 2769 set p [lindex $ids 1]
2770 2770 if {$match eq "-" || $match eq " "} {
2771 2771 set filelines($p,$fi,$diffoldlno($ids)) $line
2772 2772 incr diffoldlno($ids)
2773 2773 }
2774 2774 if {$match eq "+" || $match eq " "} {
2775 2775 set filelines($id,$fi,$diffnewlno($ids)) $line
2776 2776 incr diffnewlno($ids)
2777 2777 }
2778 2778 if {$match eq " "} {
2779 2779 if {$diffinhunk($ids) == 2} {
2780 2780 lappend difflcounts($ids) \
2781 2781 [list $noldlines($ids) $nnewlines($ids)]
2782 2782 set noldlines($ids) 0
2783 2783 set diffinhunk($ids) 1
2784 2784 }
2785 2785 incr noldlines($ids)
2786 2786 } elseif {$match eq "-" || $match eq "+"} {
2787 2787 if {$diffinhunk($ids) == 1} {
2788 2788 lappend difflcounts($ids) [list $noldlines($ids)]
2789 2789 set noldlines($ids) 0
2790 2790 set nnewlines($ids) 0
2791 2791 set diffinhunk($ids) 2
2792 2792 }
2793 2793 if {$match eq "-"} {
2794 2794 incr noldlines($ids)
2795 2795 } else {
2796 2796 incr nnewlines($ids)
2797 2797 }
2798 2798 }
2799 2799 # and if it's \ No newline at end of line, then what?
2800 2800 return
2801 2801 }
2802 2802 # end of a hunk
2803 2803 if {$diffinhunk($ids) == 1 && $noldlines($ids) != 0} {
2804 2804 lappend difflcounts($ids) [list $noldlines($ids)]
2805 2805 } elseif {$diffinhunk($ids) == 2
2806 2806 && ($noldlines($ids) != 0 || $nnewlines($ids) != 0)} {
2807 2807 lappend difflcounts($ids) [list $noldlines($ids) $nnewlines($ids)]
2808 2808 }
2809 2809 set currenthunk($ids) [list $currentfile($ids) \
2810 2810 $diffoldstart($ids) $diffnewstart($ids) \
2811 2811 $diffoldlno($ids) $diffnewlno($ids) \
2812 2812 $difflcounts($ids)]
2813 2813 set diffinhunk($ids) 0
2814 2814 # -1 = need to block, 0 = unblocked, 1 = is blocked
2815 2815 set diffblocked($ids) -1
2816 2816 processhunks
2817 2817 if {$diffblocked($ids) == -1} {
2818 2818 fileevent $f readable {}
2819 2819 set diffblocked($ids) 1
2820 2820 }
2821 2821 }
2822 2822
2823 2823 if {$n < 0} {
2824 2824 # eof
2825 2825 if {!$diffblocked($ids)} {
2826 2826 close $f
2827 2827 set currentfile($ids) [llength $mergefilelist($diffmergeid)]
2828 2828 set currenthunk($ids) [list $currentfile($ids) 0 0 0 0 {}]
2829 2829 processhunks
2830 2830 }
2831 2831 } elseif {[regexp {^diff --git a/(.*) b/} $line match fname]} {
2832 2832 # start of a new file
2833 2833 set currentfile($ids) \
2834 2834 [lsearch -exact $mergefilelist($diffmergeid) $fname]
2835 2835 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2836 2836 $line match f1l f1c f2l f2c rest]} {
2837 2837 if {[info exists currentfile($ids)] && $currentfile($ids) >= 0} {
2838 2838 # start of a new hunk
2839 2839 if {$f1l == 0 && $f1c == 0} {
2840 2840 set f1l 1
2841 2841 }
2842 2842 if {$f2l == 0 && $f2c == 0} {
2843 2843 set f2l 1
2844 2844 }
2845 2845 set diffinhunk($ids) 1
2846 2846 set diffoldstart($ids) $f1l
2847 2847 set diffnewstart($ids) $f2l
2848 2848 set diffoldlno($ids) $f1l
2849 2849 set diffnewlno($ids) $f2l
2850 2850 set difflcounts($ids) {}
2851 2851 set noldlines($ids) 0
2852 2852 set nnewlines($ids) 0
2853 2853 }
2854 2854 }
2855 2855 }
2856 2856
2857 2857 proc processhunks {} {
2858 2858 global diffmergeid parents nparents currenthunk
2859 2859 global mergefilelist diffblocked mergefds
2860 2860 global grouphunks grouplinestart grouplineend groupfilenum
2861 2861
2862 2862 set nfiles [llength $mergefilelist($diffmergeid)]
2863 2863 while 1 {
2864 2864 set fi $nfiles
2865 2865 set lno 0
2866 2866 # look for the earliest hunk
2867 2867 foreach p $parents($diffmergeid) {
2868 2868 set ids [list $diffmergeid $p]
2869 2869 if {![info exists currenthunk($ids)]} return
2870 2870 set i [lindex $currenthunk($ids) 0]
2871 2871 set l [lindex $currenthunk($ids) 2]
2872 2872 if {$i < $fi || ($i == $fi && $l < $lno)} {
2873 2873 set fi $i
2874 2874 set lno $l
2875 2875 set pi $p
2876 2876 }
2877 2877 }
2878 2878
2879 2879 if {$fi < $nfiles} {
2880 2880 set ids [list $diffmergeid $pi]
2881 2881 set hunk $currenthunk($ids)
2882 2882 unset currenthunk($ids)
2883 2883 if {$diffblocked($ids) > 0} {
2884 2884 fileevent $mergefds($ids) readable \
2885 2885 [list getmergediffline $mergefds($ids) $ids $diffmergeid]
2886 2886 }
2887 2887 set diffblocked($ids) 0
2888 2888
2889 2889 if {[info exists groupfilenum] && $groupfilenum == $fi
2890 2890 && $lno <= $grouplineend} {
2891 2891 # add this hunk to the pending group
2892 2892 lappend grouphunks($pi) $hunk
2893 2893 set endln [lindex $hunk 4]
2894 2894 if {$endln > $grouplineend} {
2895 2895 set grouplineend $endln
2896 2896 }
2897 2897 continue
2898 2898 }
2899 2899 }
2900 2900
2901 2901 # succeeding stuff doesn't belong in this group, so
2902 2902 # process the group now
2903 2903 if {[info exists groupfilenum]} {
2904 2904 processgroup
2905 2905 unset groupfilenum
2906 2906 unset grouphunks
2907 2907 }
2908 2908
2909 2909 if {$fi >= $nfiles} break
2910 2910
2911 2911 # start a new group
2912 2912 set groupfilenum $fi
2913 2913 set grouphunks($pi) [list $hunk]
2914 2914 set grouplinestart $lno
2915 2915 set grouplineend [lindex $hunk 4]
2916 2916 }
2917 2917 }
2918 2918
2919 2919 proc processgroup {} {
2920 2920 global groupfilelast groupfilenum difffilestart
2921 2921 global mergefilelist diffmergeid ctext filelines
2922 2922 global parents diffmergeid diffoffset
2923 2923 global grouphunks grouplinestart grouplineend nparents
2924 2924 global mergemax
2925 2925
2926 2926 $ctext conf -state normal
2927 2927 set id $diffmergeid
2928 2928 set f $groupfilenum
2929 2929 if {$groupfilelast != $f} {
2930 2930 $ctext insert end "\n"
2931 2931 set here [$ctext index "end - 1c"]
2932 2932 set difffilestart($f) $here
2933 2933 set mark fmark.[expr {$f + 1}]
2934 2934 $ctext mark set $mark $here
2935 2935 $ctext mark gravity $mark left
2936 2936 set header [lindex $mergefilelist($id) $f]
2937 2937 set l [expr {(78 - [string length $header]) / 2}]
2938 2938 set pad [string range "----------------------------------------" 1 $l]
2939 2939 $ctext insert end "$pad $header $pad\n" filesep
2940 2940 set groupfilelast $f
2941 2941 foreach p $parents($id) {
2942 2942 set diffoffset($p) 0
2943 2943 }
2944 2944 }
2945 2945
2946 2946 $ctext insert end "@@" msep
2947 2947 set nlines [expr {$grouplineend - $grouplinestart}]
2948 2948 set events {}
2949 2949 set pnum 0
2950 2950 foreach p $parents($id) {
2951 2951 set startline [expr {$grouplinestart + $diffoffset($p)}]
2952 2952 set ol $startline
2953 2953 set nl $grouplinestart
2954 2954 if {[info exists grouphunks($p)]} {
2955 2955 foreach h $grouphunks($p) {
2956 2956 set l [lindex $h 2]
2957 2957 if {$nl < $l} {
2958 2958 for {} {$nl < $l} {incr nl} {
2959 2959 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2960 2960 incr ol
2961 2961 }
2962 2962 }
2963 2963 foreach chunk [lindex $h 5] {
2964 2964 if {[llength $chunk] == 2} {
2965 2965 set olc [lindex $chunk 0]
2966 2966 set nlc [lindex $chunk 1]
2967 2967 set nnl [expr {$nl + $nlc}]
2968 2968 lappend events [list $nl $nnl $pnum $olc $nlc]
2969 2969 incr ol $olc
2970 2970 set nl $nnl
2971 2971 } else {
2972 2972 incr ol [lindex $chunk 0]
2973 2973 incr nl [lindex $chunk 0]
2974 2974 }
2975 2975 }
2976 2976 }
2977 2977 }
2978 2978 if {$nl < $grouplineend} {
2979 2979 for {} {$nl < $grouplineend} {incr nl} {
2980 2980 set filelines($p,$f,$ol) $filelines($id,$f,$nl)
2981 2981 incr ol
2982 2982 }
2983 2983 }
2984 2984 set nlines [expr {$ol - $startline}]
2985 2985 $ctext insert end " -$startline,$nlines" msep
2986 2986 incr pnum
2987 2987 }
2988 2988
2989 2989 set nlines [expr {$grouplineend - $grouplinestart}]
2990 2990 $ctext insert end " +$grouplinestart,$nlines @@\n" msep
2991 2991
2992 2992 set events [lsort -integer -index 0 $events]
2993 2993 set nevents [llength $events]
2994 2994 set nmerge $nparents($diffmergeid)
2995 2995 set l $grouplinestart
2996 2996 for {set i 0} {$i < $nevents} {set i $j} {
2997 2997 set nl [lindex $events $i 0]
2998 2998 while {$l < $nl} {
2999 2999 $ctext insert end " $filelines($id,$f,$l)\n"
3000 3000 incr l
3001 3001 }
3002 3002 set e [lindex $events $i]
3003 3003 set enl [lindex $e 1]
3004 3004 set j $i
3005 3005 set active {}
3006 3006 while 1 {
3007 3007 set pnum [lindex $e 2]
3008 3008 set olc [lindex $e 3]
3009 3009 set nlc [lindex $e 4]
3010 3010 if {![info exists delta($pnum)]} {
3011 3011 set delta($pnum) [expr {$olc - $nlc}]
3012 3012 lappend active $pnum
3013 3013 } else {
3014 3014 incr delta($pnum) [expr {$olc - $nlc}]
3015 3015 }
3016 3016 if {[incr j] >= $nevents} break
3017 3017 set e [lindex $events $j]
3018 3018 if {[lindex $e 0] >= $enl} break
3019 3019 if {[lindex $e 1] > $enl} {
3020 3020 set enl [lindex $e 1]
3021 3021 }
3022 3022 }
3023 3023 set nlc [expr {$enl - $l}]
3024 3024 set ncol mresult
3025 3025 set bestpn -1
3026 3026 if {[llength $active] == $nmerge - 1} {
3027 3027 # no diff for one of the parents, i.e. it's identical
3028 3028 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3029 3029 if {![info exists delta($pnum)]} {
3030 3030 if {$pnum < $mergemax} {
3031 3031 lappend ncol m$pnum
3032 3032 } else {
3033 3033 lappend ncol mmax
3034 3034 }
3035 3035 break
3036 3036 }
3037 3037 }
3038 3038 } elseif {[llength $active] == $nmerge} {
3039 3039 # all parents are different, see if one is very similar
3040 3040 set bestsim 30
3041 3041 for {set pnum 0} {$pnum < $nmerge} {incr pnum} {
3042 3042 set sim [similarity $pnum $l $nlc $f \
3043 3043 [lrange $events $i [expr {$j-1}]]]
3044 3044 if {$sim > $bestsim} {
3045 3045 set bestsim $sim
3046 3046 set bestpn $pnum
3047 3047 }
3048 3048 }
3049 3049 if {$bestpn >= 0} {
3050 3050 lappend ncol m$bestpn
3051 3051 }
3052 3052 }
3053 3053 set pnum -1
3054 3054 foreach p $parents($id) {
3055 3055 incr pnum
3056 3056 if {![info exists delta($pnum)] || $pnum == $bestpn} continue
3057 3057 set olc [expr {$nlc + $delta($pnum)}]
3058 3058 set ol [expr {$l + $diffoffset($p)}]
3059 3059 incr diffoffset($p) $delta($pnum)
3060 3060 unset delta($pnum)
3061 3061 for {} {$olc > 0} {incr olc -1} {
3062 3062 $ctext insert end "-$filelines($p,$f,$ol)\n" m$pnum
3063 3063 incr ol
3064 3064 }
3065 3065 }
3066 3066 set endl [expr {$l + $nlc}]
3067 3067 if {$bestpn >= 0} {
3068 3068 # show this pretty much as a normal diff
3069 3069 set p [lindex $parents($id) $bestpn]
3070 3070 set ol [expr {$l + $diffoffset($p)}]
3071 3071 incr diffoffset($p) $delta($bestpn)
3072 3072 unset delta($bestpn)
3073 3073 for {set k $i} {$k < $j} {incr k} {
3074 3074 set e [lindex $events $k]
3075 3075 if {[lindex $e 2] != $bestpn} continue
3076 3076 set nl [lindex $e 0]
3077 3077 set ol [expr {$ol + $nl - $l}]
3078 3078 for {} {$l < $nl} {incr l} {
3079 3079 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3080 3080 }
3081 3081 set c [lindex $e 3]
3082 3082 for {} {$c > 0} {incr c -1} {
3083 3083 $ctext insert end "-$filelines($p,$f,$ol)\n" m$bestpn
3084 3084 incr ol
3085 3085 }
3086 3086 set nl [lindex $e 1]
3087 3087 for {} {$l < $nl} {incr l} {
3088 3088 $ctext insert end "+$filelines($id,$f,$l)\n" mresult
3089 3089 }
3090 3090 }
3091 3091 }
3092 3092 for {} {$l < $endl} {incr l} {
3093 3093 $ctext insert end "+$filelines($id,$f,$l)\n" $ncol
3094 3094 }
3095 3095 }
3096 3096 while {$l < $grouplineend} {
3097 3097 $ctext insert end " $filelines($id,$f,$l)\n"
3098 3098 incr l
3099 3099 }
3100 3100 $ctext conf -state disabled
3101 3101 }
3102 3102
3103 3103 proc similarity {pnum l nlc f events} {
3104 3104 global diffmergeid parents diffoffset filelines
3105 3105
3106 3106 set id $diffmergeid
3107 3107 set p [lindex $parents($id) $pnum]
3108 3108 set ol [expr {$l + $diffoffset($p)}]
3109 3109 set endl [expr {$l + $nlc}]
3110 3110 set same 0
3111 3111 set diff 0
3112 3112 foreach e $events {
3113 3113 if {[lindex $e 2] != $pnum} continue
3114 3114 set nl [lindex $e 0]
3115 3115 set ol [expr {$ol + $nl - $l}]
3116 3116 for {} {$l < $nl} {incr l} {
3117 3117 incr same [string length $filelines($id,$f,$l)]
3118 3118 incr same
3119 3119 }
3120 3120 set oc [lindex $e 3]
3121 3121 for {} {$oc > 0} {incr oc -1} {
3122 3122 incr diff [string length $filelines($p,$f,$ol)]
3123 3123 incr diff
3124 3124 incr ol
3125 3125 }
3126 3126 set nl [lindex $e 1]
3127 3127 for {} {$l < $nl} {incr l} {
3128 3128 incr diff [string length $filelines($id,$f,$l)]
3129 3129 incr diff
3130 3130 }
3131 3131 }
3132 3132 for {} {$l < $endl} {incr l} {
3133 3133 incr same [string length $filelines($id,$f,$l)]
3134 3134 incr same
3135 3135 }
3136 3136 if {$same == 0} {
3137 3137 return 0
3138 3138 }
3139 3139 return [expr {200 * $same / (2 * $same + $diff)}]
3140 3140 }
3141 3141
3142 3142 proc startdiff {ids} {
3143 3143 global treediffs diffids treepending diffmergeid
3144 3144
3145 3145 set diffids $ids
3146 3146 catch {unset diffmergeid}
3147 3147 if {![info exists treediffs($ids)]} {
3148 3148 if {![info exists treepending]} {
3149 3149 gettreediffs $ids
3150 3150 }
3151 3151 } else {
3152 3152 addtocflist $ids
3153 3153 }
3154 3154 }
3155 3155
3156 3156 proc addtocflist {ids} {
3157 3157 global treediffs cflist
3158 3158 foreach f $treediffs($ids) {
3159 3159 $cflist insert end $f
3160 3160 }
3161 3161 getblobdiffs $ids
3162 3162 }
3163 3163
3164 3164 proc gettreediffs {ids} {
3165 3165 global treediff parents treepending env
3166 3166 set treepending $ids
3167 3167 set treediff {}
3168 3168 set id [lindex $ids 0]
3169 3169 set p [lindex $ids 1]
3170 3170 if [catch {set gdtf [open "|{$env(HG)} --config ui.report_untrusted=false debug-diff-tree -r $p $id" r]}] return
3171 3171 fconfigure $gdtf -blocking 0
3172 3172 fileevent $gdtf readable [list gettreediffline $gdtf $ids]
3173 3173 }
3174 3174
3175 3175 proc gettreediffline {gdtf ids} {
3176 3176 global treediff treediffs treepending diffids diffmergeid
3177 3177
3178 3178 set n [gets $gdtf line]
3179 3179 if {$n < 0} {
3180 3180 if {![eof $gdtf]} return
3181 3181 close $gdtf
3182 3182 set treediffs($ids) $treediff
3183 3183 unset treepending
3184 3184 if {$ids != $diffids} {
3185 3185 gettreediffs $diffids
3186 3186 } else {
3187 3187 if {[info exists diffmergeid]} {
3188 3188 contmergediff $ids
3189 3189 } else {
3190 3190 addtocflist $ids
3191 3191 }
3192 3192 }
3193 3193 return
3194 3194 }
3195 3195 set tab1 [expr [string first "\t" $line] + 1]
3196 3196 set tab2 [expr [string first "\t" $line $tab1] - 1]
3197 3197 set file [string range $line $tab1 $tab2]
3198 3198 lappend treediff $file
3199 3199 }
3200 3200
3201 3201 proc getblobdiffs {ids} {
3202 3202 global diffopts blobdifffd diffids env curdifftag curtagstart
3203 3203 global difffilestart nextupdate diffinhdr treediffs
3204 3204
3205 3205 set id [lindex $ids 0]
3206 3206 set p [lindex $ids 1]
3207 3207 set env(GIT_DIFF_OPTS) $diffopts
3208 3208 set cmd [list | $env(HG) --config ui.report_untrusted=false debug-diff-tree -r -p -C $p $id]
3209 3209 if {[catch {set bdf [open $cmd r]} err]} {
3210 3210 puts "error getting diffs: $err"
3211 3211 return
3212 3212 }
3213 3213 set diffinhdr 0
3214 3214 fconfigure $bdf -blocking 0
3215 3215 set blobdifffd($ids) $bdf
3216 3216 set curdifftag Comments
3217 3217 set curtagstart 0.0
3218 3218 catch {unset difffilestart}
3219 3219 fileevent $bdf readable [list getblobdiffline $bdf $diffids]
3220 3220 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
3221 3221 }
3222 3222
3223 3223 proc getblobdiffline {bdf ids} {
3224 3224 global diffids blobdifffd ctext curdifftag curtagstart
3225 3225 global diffnexthead diffnextnote difffilestart
3226 3226 global nextupdate diffinhdr treediffs
3227 3227 global gaudydiff
3228 3228
3229 3229 set n [gets $bdf line]
3230 3230 if {$n < 0} {
3231 3231 if {[eof $bdf]} {
3232 3232 close $bdf
3233 3233 if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
3234 3234 $ctext tag add $curdifftag $curtagstart end
3235 3235 }
3236 3236 }
3237 3237 return
3238 3238 }
3239 3239 if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
3240 3240 return
3241 3241 }
3242 3242 regsub -all "\r" $line "" line
3243 3243 $ctext conf -state normal
3244 3244 if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
3245 3245 # start of a new file
3246 3246 $ctext insert end "\n"
3247 3247 $ctext tag add $curdifftag $curtagstart end
3248 3248 set curtagstart [$ctext index "end - 1c"]
3249 3249 set header $newname
3250 3250 set here [$ctext index "end - 1c"]
3251 3251 set i [lsearch -exact $treediffs($diffids) $fname]
3252 3252 if {$i >= 0} {
3253 3253 set difffilestart($i) $here
3254 3254 incr i
3255 3255 $ctext mark set fmark.$i $here
3256 3256 $ctext mark gravity fmark.$i left
3257 3257 }
3258 3258 if {$newname != $fname} {
3259 3259 set i [lsearch -exact $treediffs($diffids) $newname]
3260 3260 if {$i >= 0} {
3261 3261 set difffilestart($i) $here
3262 3262 incr i
3263 3263 $ctext mark set fmark.$i $here
3264 3264 $ctext mark gravity fmark.$i left
3265 3265 }
3266 3266 }
3267 3267 set curdifftag "f:$fname"
3268 3268 $ctext tag delete $curdifftag
3269 3269 set l [expr {(78 - [string length $header]) / 2}]
3270 3270 set pad [string range "----------------------------------------" 1 $l]
3271 3271 $ctext insert end "$pad $header $pad\n" filesep
3272 3272 set diffinhdr 1
3273 3273 } elseif {[regexp {^(---|\+\+\+) } $line] && $diffinhdr} {
3274 3274 set diffinhdr 1
3275 3275 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
3276 3276 $line match f1l f1c f2l f2c rest]} {
3277 3277 if {$gaudydiff} {
3278 3278 $ctext insert end "\t" hunksep
3279 3279 $ctext insert end " $f1l " d0 " $f2l " d1
3280 3280 $ctext insert end " $rest \n" hunksep
3281 3281 } else {
3282 3282 $ctext insert end "$line\n" hunksep
3283 3283 }
3284 3284 set diffinhdr 0
3285 3285 } else {
3286 3286 set x [string range $line 0 0]
3287 3287 if {$x == "-" || $x == "+"} {
3288 3288 set tag [expr {$x == "+"}]
3289 3289 if {$gaudydiff} {
3290 3290 set line [string range $line 1 end]
3291 3291 }
3292 3292 $ctext insert end "$line\n" d$tag
3293 3293 } elseif {$x == " "} {
3294 3294 if {$gaudydiff} {
3295 3295 set line [string range $line 1 end]
3296 3296 }
3297 3297 $ctext insert end "$line\n"
3298 3298 } elseif {$diffinhdr || $x == "\\"} {
3299 3299 # e.g. "\ No newline at end of file"
3300 3300 $ctext insert end "$line\n" filesep
3301 3301 } elseif {$line != ""} {
3302 3302 # Something else we don't recognize
3303 3303 if {$curdifftag != "Comments"} {
3304 3304 $ctext insert end "\n"
3305 3305 $ctext tag add $curdifftag $curtagstart end
3306 3306 set curtagstart [$ctext index "end - 1c"]
3307 3307 set curdifftag Comments
3308 3308 }
3309 3309 $ctext insert end "$line\n" filesep
3310 3310 }
3311 3311 }
3312 3312 $ctext conf -state disabled
3313 3313 if {[clock clicks -milliseconds] >= $nextupdate} {
3314 3314 incr nextupdate 100
3315 3315 fileevent $bdf readable {}
3316 3316 update
3317 3317 fileevent $bdf readable "getblobdiffline $bdf {$ids}"
3318 3318 }
3319 3319 }
3320 3320
3321 3321 proc nextfile {} {
3322 3322 global difffilestart ctext
3323 3323 set here [$ctext index @0,0]
3324 3324 for {set i 0} {[info exists difffilestart($i)]} {incr i} {
3325 3325 if {[$ctext compare $difffilestart($i) > $here]} {
3326 3326 if {![info exists pos]
3327 3327 || [$ctext compare $difffilestart($i) < $pos]} {
3328 3328 set pos $difffilestart($i)
3329 3329 }
3330 3330 }
3331 3331 }
3332 3332 if {[info exists pos]} {
3333 3333 $ctext yview $pos
3334 3334 }
3335 3335 }
3336 3336
3337 3337 proc listboxsel {} {
3338 3338 global ctext cflist currentid
3339 3339 if {![info exists currentid]} return
3340 3340 set sel [lsort [$cflist curselection]]
3341 3341 if {$sel eq {}} return
3342 3342 set first [lindex $sel 0]
3343 3343 catch {$ctext yview fmark.$first}
3344 3344 }
3345 3345
3346 3346 proc setcoords {} {
3347 3347 global linespc charspc canvx0 canvy0 mainfont
3348 3348 global xspc1 xspc2 lthickness
3349 3349
3350 3350 set linespc [font metrics $mainfont -linespace]
3351 3351 set charspc [font measure $mainfont "m"]
3352 3352 set canvy0 [expr 3 + 0.5 * $linespc]
3353 3353 set canvx0 [expr 3 + 0.5 * $linespc]
3354 3354 set lthickness [expr {int($linespc / 9) + 1}]
3355 3355 set xspc1(0) $linespc
3356 3356 set xspc2 $linespc
3357 3357 }
3358 3358
3359 3359 proc redisplay {} {
3360 3360 global stopped redisplaying phase
3361 3361 if {$stopped > 1} return
3362 3362 if {$phase == "getcommits"} return
3363 3363 set redisplaying 1
3364 3364 if {$phase == "drawgraph" || $phase == "incrdraw"} {
3365 3365 set stopped 1
3366 3366 } else {
3367 3367 drawgraph
3368 3368 }
3369 3369 }
3370 3370
3371 3371 proc incrfont {inc} {
3372 3372 global mainfont namefont textfont ctext canv phase
3373 3373 global stopped entries curidfont
3374 3374 unmarkmatches
3375 3375 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
3376 3376 set curidfont [lreplace $curidfont 1 1 [expr {[lindex $curidfont 1] + $inc}]]
3377 3377 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]]
3378 3378 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]]
3379 3379 setcoords
3380 3380 $ctext conf -font $textfont
3381 3381 $ctext tag conf filesep -font [concat $textfont bold]
3382 3382 foreach e $entries {
3383 3383 $e conf -font $mainfont
3384 3384 }
3385 3385 if {$phase == "getcommits"} {
3386 3386 $canv itemconf textitems -font $mainfont
3387 3387 }
3388 3388 redisplay
3389 3389 }
3390 3390
3391 3391 proc clearsha1 {} {
3392 3392 global sha1entry sha1string
3393 3393 if {[string length $sha1string] == 40} {
3394 3394 $sha1entry delete 0 end
3395 3395 }
3396 3396 }
3397 3397
3398 3398 proc sha1change {n1 n2 op} {
3399 3399 global sha1string currentid sha1but
3400 3400 if {$sha1string == {}
3401 3401 || ([info exists currentid] && $sha1string == $currentid)} {
3402 3402 set state disabled
3403 3403 } else {
3404 3404 set state normal
3405 3405 }
3406 3406 if {[$sha1but cget -state] == $state} return
3407 3407 if {$state == "normal"} {
3408 3408 $sha1but conf -state normal -relief raised -text "Goto: "
3409 3409 } else {
3410 3410 $sha1but conf -state disabled -relief flat -text "SHA1 ID: "
3411 3411 }
3412 3412 }
3413 3413
3414 3414 proc gotocommit {} {
3415 3415 global sha1string currentid idline tagids
3416 3416 global lineid numcommits
3417 3417
3418 3418 if {$sha1string == {}
3419 3419 || ([info exists currentid] && $sha1string == $currentid)} return
3420 3420 if {[info exists tagids($sha1string)]} {
3421 3421 set id $tagids($sha1string)
3422 3422 } else {
3423 3423 set id [string tolower $sha1string]
3424 3424 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
3425 3425 set matches {}
3426 3426 for {set l 0} {$l < $numcommits} {incr l} {
3427 3427 if {[string match $id* $lineid($l)]} {
3428 3428 lappend matches $lineid($l)
3429 3429 }
3430 3430 }
3431 3431 if {$matches ne {}} {
3432 3432 if {[llength $matches] > 1} {
3433 3433 error_popup "Short SHA1 id $id is ambiguous"
3434 3434 return
3435 3435 }
3436 3436 set id [lindex $matches 0]
3437 3437 }
3438 3438 }
3439 3439 }
3440 3440 if {[info exists idline($id)]} {
3441 3441 selectline $idline($id) 1
3442 3442 return
3443 3443 }
3444 3444 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
3445 3445 set type "SHA1 id"
3446 3446 } else {
3447 3447 set type "Tag"
3448 3448 }
3449 3449 error_popup "$type $sha1string is not known"
3450 3450 }
3451 3451
3452 3452 proc lineenter {x y id} {
3453 3453 global hoverx hovery hoverid hovertimer
3454 3454 global commitinfo canv
3455 3455
3456 3456 if {![info exists commitinfo($id)]} return
3457 3457 set hoverx $x
3458 3458 set hovery $y
3459 3459 set hoverid $id
3460 3460 if {[info exists hovertimer]} {
3461 3461 after cancel $hovertimer
3462 3462 }
3463 3463 set hovertimer [after 500 linehover]
3464 3464 $canv delete hover
3465 3465 }
3466 3466
3467 3467 proc linemotion {x y id} {
3468 3468 global hoverx hovery hoverid hovertimer
3469 3469
3470 3470 if {[info exists hoverid] && $id == $hoverid} {
3471 3471 set hoverx $x
3472 3472 set hovery $y
3473 3473 if {[info exists hovertimer]} {
3474 3474 after cancel $hovertimer
3475 3475 }
3476 3476 set hovertimer [after 500 linehover]
3477 3477 }
3478 3478 }
3479 3479
3480 3480 proc lineleave {id} {
3481 3481 global hoverid hovertimer canv
3482 3482
3483 3483 if {[info exists hoverid] && $id == $hoverid} {
3484 3484 $canv delete hover
3485 3485 if {[info exists hovertimer]} {
3486 3486 after cancel $hovertimer
3487 3487 unset hovertimer
3488 3488 }
3489 3489 unset hoverid
3490 3490 }
3491 3491 }
3492 3492
3493 3493 proc linehover {} {
3494 3494 global hoverx hovery hoverid hovertimer
3495 3495 global canv linespc lthickness
3496 3496 global commitinfo mainfont
3497 3497
3498 3498 set text [lindex $commitinfo($hoverid) 0]
3499 3499 set ymax [lindex [$canv cget -scrollregion] 3]
3500 3500 if {$ymax == {}} return
3501 3501 set yfrac [lindex [$canv yview] 0]
3502 3502 set x [expr {$hoverx + 2 * $linespc}]
3503 3503 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}]
3504 3504 set x0 [expr {$x - 2 * $lthickness}]
3505 3505 set y0 [expr {$y - 2 * $lthickness}]
3506 3506 set x1 [expr {$x + [font measure $mainfont $text] + 2 * $lthickness}]
3507 3507 set y1 [expr {$y + $linespc + 2 * $lthickness}]
3508 3508 set t [$canv create rectangle $x0 $y0 $x1 $y1 \
3509 3509 -fill \#ffff80 -outline black -width 1 -tags hover]
3510 3510 $canv raise $t
3511 3511 set t [$canv create text $x $y -anchor nw -text $text -tags hover]
3512 3512 $canv raise $t
3513 3513 }
3514 3514
3515 3515 proc clickisonarrow {id y} {
3516 3516 global mainline mainlinearrow sidelines lthickness
3517 3517
3518 3518 set thresh [expr {2 * $lthickness + 6}]
3519 3519 if {[info exists mainline($id)]} {
3520 3520 if {$mainlinearrow($id) ne "none"} {
3521 3521 if {abs([lindex $mainline($id) 1] - $y) < $thresh} {
3522 3522 return "up"
3523 3523 }
3524 3524 }
3525 3525 }
3526 3526 if {[info exists sidelines($id)]} {
3527 3527 foreach ls $sidelines($id) {
3528 3528 set coords [lindex $ls 0]
3529 3529 set arrow [lindex $ls 2]
3530 3530 if {$arrow eq "first" || $arrow eq "both"} {
3531 3531 if {abs([lindex $coords 1] - $y) < $thresh} {
3532 3532 return "up"
3533 3533 }
3534 3534 }
3535 3535 if {$arrow eq "last" || $arrow eq "both"} {
3536 3536 if {abs([lindex $coords end] - $y) < $thresh} {
3537 3537 return "down"
3538 3538 }
3539 3539 }
3540 3540 }
3541 3541 }
3542 3542 return {}
3543 3543 }
3544 3544
3545 3545 proc arrowjump {id dirn y} {
3546 3546 global mainline sidelines canv
3547 3547
3548 3548 set yt {}
3549 3549 if {$dirn eq "down"} {
3550 3550 if {[info exists mainline($id)]} {
3551 3551 set y1 [lindex $mainline($id) 1]
3552 3552 if {$y1 > $y} {
3553 3553 set yt $y1
3554 3554 }
3555 3555 }
3556 3556 if {[info exists sidelines($id)]} {
3557 3557 foreach ls $sidelines($id) {
3558 3558 set y1 [lindex $ls 0 1]
3559 3559 if {$y1 > $y && ($yt eq {} || $y1 < $yt)} {
3560 3560 set yt $y1
3561 3561 }
3562 3562 }
3563 3563 }
3564 3564 } else {
3565 3565 if {[info exists sidelines($id)]} {
3566 3566 foreach ls $sidelines($id) {
3567 3567 set y1 [lindex $ls 0 end]
3568 3568 if {$y1 < $y && ($yt eq {} || $y1 > $yt)} {
3569 3569 set yt $y1
3570 3570 }
3571 3571 }
3572 3572 }
3573 3573 }
3574 3574 if {$yt eq {}} return
3575 3575 set ymax [lindex [$canv cget -scrollregion] 3]
3576 3576 if {$ymax eq {} || $ymax <= 0} return
3577 3577 set view [$canv yview]
3578 3578 set yspan [expr {[lindex $view 1] - [lindex $view 0]}]
3579 3579 set yfrac [expr {$yt / $ymax - $yspan / 2}]
3580 3580 if {$yfrac < 0} {
3581 3581 set yfrac 0
3582 3582 }
3583 3583 $canv yview moveto $yfrac
3584 3584 }
3585 3585
3586 3586 proc lineclick {x y id isnew} {
3587 3587 global ctext commitinfo children cflist canv thickerline
3588 3588
3589 3589 unmarkmatches
3590 3590 unselectline
3591 3591 normalline
3592 3592 $canv delete hover
3593 3593 # draw this line thicker than normal
3594 3594 drawlines $id 1
3595 3595 set thickerline $id
3596 3596 if {$isnew} {
3597 3597 set ymax [lindex [$canv cget -scrollregion] 3]
3598 3598 if {$ymax eq {}} return
3599 3599 set yfrac [lindex [$canv yview] 0]
3600 3600 set y [expr {$y + $yfrac * $ymax}]
3601 3601 }
3602 3602 set dirn [clickisonarrow $id $y]
3603 3603 if {$dirn ne {}} {
3604 3604 arrowjump $id $dirn $y
3605 3605 return
3606 3606 }
3607 3607
3608 3608 if {$isnew} {
3609 3609 addtohistory [list lineclick $x $y $id 0]
3610 3610 }
3611 3611 # fill the details pane with info about this line
3612 3612 $ctext conf -state normal
3613 3613 $ctext delete 0.0 end
3614 3614 $ctext tag conf link -foreground blue -underline 1
3615 3615 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3616 3616 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3617 3617 $ctext insert end "Parent:\t"
3618 3618 $ctext insert end $id [list link link0]
3619 3619 $ctext tag bind link0 <1> [list selbyid $id]
3620 3620 set info $commitinfo($id)
3621 3621 $ctext insert end "\n\t[lindex $info 0]\n"
3622 3622 $ctext insert end "\tUser:\t[lindex $info 1]\n"
3623 3623 $ctext insert end "\tDate:\t[lindex $info 2]\n"
3624 3624 if {[info exists children($id)]} {
3625 3625 $ctext insert end "\nChildren:"
3626 3626 set i 0
3627 3627 foreach child $children($id) {
3628 3628 incr i
3629 3629 set info $commitinfo($child)
3630 3630 $ctext insert end "\n\t"
3631 3631 $ctext insert end $child [list link link$i]
3632 3632 $ctext tag bind link$i <1> [list selbyid $child]
3633 3633 $ctext insert end "\n\t[lindex $info 0]"
3634 3634 $ctext insert end "\n\tUser:\t[lindex $info 1]"
3635 3635 $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3636 3636 }
3637 3637 }
3638 3638 $ctext conf -state disabled
3639 3639
3640 3640 $cflist delete 0 end
3641 3641 }
3642 3642
3643 3643 proc normalline {} {
3644 3644 global thickerline
3645 3645 if {[info exists thickerline]} {
3646 3646 drawlines $thickerline 0
3647 3647 unset thickerline
3648 3648 }
3649 3649 }
3650 3650
3651 3651 proc selbyid {id} {
3652 3652 global idline
3653 3653 if {[info exists idline($id)]} {
3654 3654 selectline $idline($id) 1
3655 3655 }
3656 3656 }
3657 3657
3658 3658 proc mstime {} {
3659 3659 global startmstime
3660 3660 if {![info exists startmstime]} {
3661 3661 set startmstime [clock clicks -milliseconds]
3662 3662 }
3663 3663 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
3664 3664 }
3665 3665
3666 3666 proc rowmenu {x y id} {
3667 3667 global rowctxmenu idline selectedline rowmenuid hgvdiff
3668 3668
3669 3669 if {![info exists selectedline] || $idline($id) eq $selectedline} {
3670 3670 set state disabled
3671 3671 } else {
3672 3672 set state normal
3673 3673 }
3674 3674 $rowctxmenu entryconfigure 0 -state $state
3675 3675 $rowctxmenu entryconfigure 1 -state $state
3676 3676 $rowctxmenu entryconfigure 2 -state $state
3677 3677 if { $hgvdiff ne "" } {
3678 3678 $rowctxmenu entryconfigure 6 -state $state
3679 3679 }
3680 3680 set rowmenuid $id
3681 3681 tk_popup $rowctxmenu $x $y
3682 3682 }
3683 3683
3684 3684 proc diffvssel {dirn} {
3685 3685 global rowmenuid selectedline lineid
3686 3686
3687 3687 if {![info exists selectedline]} return
3688 3688 if {$dirn} {
3689 3689 set oldid $lineid($selectedline)
3690 3690 set newid $rowmenuid
3691 3691 } else {
3692 3692 set oldid $rowmenuid
3693 3693 set newid $lineid($selectedline)
3694 3694 }
3695 3695 addtohistory [list doseldiff $oldid $newid]
3696 3696 doseldiff $oldid $newid
3697 3697 }
3698 3698
3699 3699 proc doseldiff {oldid newid} {
3700 3700 global ctext cflist
3701 3701 global commitinfo
3702 3702
3703 3703 $ctext conf -state normal
3704 3704 $ctext delete 0.0 end
3705 3705 $ctext mark set fmark.0 0.0
3706 3706 $ctext mark gravity fmark.0 left
3707 3707 $cflist delete 0 end
3708 3708 $cflist insert end "Top"
3709 3709 $ctext insert end "From "
3710 3710 $ctext tag conf link -foreground blue -underline 1
3711 3711 $ctext tag bind link <Enter> { %W configure -cursor hand2 }
3712 3712 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
3713 3713 $ctext tag bind link0 <1> [list selbyid $oldid]
3714 3714 $ctext insert end $oldid [list link link0]
3715 3715 $ctext insert end "\n "
3716 3716 $ctext insert end [lindex $commitinfo($oldid) 0]
3717 3717 $ctext insert end "\n\nTo "
3718 3718 $ctext tag bind link1 <1> [list selbyid $newid]
3719 3719 $ctext insert end $newid [list link link1]
3720 3720 $ctext insert end "\n "
3721 3721 $ctext insert end [lindex $commitinfo($newid) 0]
3722 3722 $ctext insert end "\n"
3723 3723 $ctext conf -state disabled
3724 3724 $ctext tag delete Comments
3725 3725 $ctext tag remove found 1.0 end
3726 3726 startdiff [list $newid $oldid]
3727 3727 }
3728 3728
3729 3729 proc mkpatch {} {
3730 3730 global rowmenuid currentid commitinfo patchtop patchnum
3731 3731
3732 3732 if {![info exists currentid]} return
3733 3733 set oldid $currentid
3734 3734 set oldhead [lindex $commitinfo($oldid) 0]
3735 3735 set newid $rowmenuid
3736 3736 set newhead [lindex $commitinfo($newid) 0]
3737 3737 set top .patch
3738 3738 set patchtop $top
3739 3739 catch {destroy $top}
3740 3740 toplevel $top
3741 3741 ttk::label $top.from -text "From:"
3742 3742 ttk::entry $top.fromsha1 -width 40
3743 3743 $top.fromsha1 insert 0 $oldid
3744 3744 $top.fromsha1 conf -state readonly
3745 3745 grid $top.from $top.fromsha1 -sticky w -pady {10 0}
3746 3746 ttk::entry $top.fromhead -width 60
3747 3747 $top.fromhead insert 0 $oldhead
3748 3748 $top.fromhead conf -state readonly
3749 3749 grid x $top.fromhead -sticky w
3750 3750 ttk::label $top.to -text "To:"
3751 3751 ttk::entry $top.tosha1 -width 40
3752 3752 $top.tosha1 insert 0 $newid
3753 3753 $top.tosha1 conf -state readonly
3754 3754 grid $top.to $top.tosha1 -sticky w
3755 3755 ttk::entry $top.tohead -width 60
3756 3756 $top.tohead insert 0 $newhead
3757 3757 $top.tohead conf -state readonly
3758 3758 grid x $top.tohead -sticky w
3759 3759 ttk::button $top.rev -text "Reverse" -command mkpatchrev
3760 3760 grid $top.rev x -pady 10
3761 3761 ttk::label $top.flab -text "Output file:"
3762 3762 ttk::entry $top.fname -width 60
3763 3763 $top.fname insert 0 [file normalize "patch$patchnum.patch"]
3764 3764 incr patchnum
3765 3765 grid $top.flab $top.fname -sticky w
3766 3766 ttk::frame $top.buts
3767 3767 ttk::button $top.buts.gen -text "Generate" -command mkpatchgo
3768 3768 ttk::button $top.buts.can -text "Cancel" -command mkpatchcan
3769 3769 grid $top.buts.gen $top.buts.can
3770 3770 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3771 3771 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3772 3772 grid $top.buts - -pady 10 -sticky ew
3773 3773 focus $top.fname
3774 3774 popupify $top
3775 3775 wm title $top "Generate a patch"
3776 3776 }
3777 3777
3778 3778 proc mkpatchrev {} {
3779 3779 global patchtop
3780 3780
3781 3781 set oldid [$patchtop.fromsha1 get]
3782 3782 set oldhead [$patchtop.fromhead get]
3783 3783 set newid [$patchtop.tosha1 get]
3784 3784 set newhead [$patchtop.tohead get]
3785 3785 foreach e [list fromsha1 fromhead tosha1 tohead] \
3786 3786 v [list $newid $newhead $oldid $oldhead] {
3787 3787 $patchtop.$e conf -state normal
3788 3788 $patchtop.$e delete 0 end
3789 3789 $patchtop.$e insert 0 $v
3790 3790 $patchtop.$e conf -state readonly
3791 3791 }
3792 3792 }
3793 3793
3794 3794 proc mkpatchgo {} {
3795 3795 global patchtop env
3796 3796
3797 3797 set oldid [$patchtop.fromsha1 get]
3798 3798 set newid [$patchtop.tosha1 get]
3799 3799 set fname [$patchtop.fname get]
3800 3800 if {[catch {exec $env(HG) --config ui.report_untrusted=false debug-diff-tree -p $oldid $newid >$fname &} err]} {
3801 3801 error_popup "Error creating patch: $err"
3802 3802 }
3803 3803 catch {destroy $patchtop}
3804 3804 unset patchtop
3805 3805 }
3806 3806
3807 3807 proc mkpatchcan {} {
3808 3808 global patchtop
3809 3809
3810 3810 catch {destroy $patchtop}
3811 3811 unset patchtop
3812 3812 }
3813 3813
3814 3814 proc mktag {} {
3815 3815 global rowmenuid mktagtop commitinfo
3816 3816
3817 3817 set top .maketag
3818 3818 set mktagtop $top
3819 3819 catch {destroy $top}
3820 3820 toplevel $top
3821 3821 ttk::label $top.id -text "ID:"
3822 3822 ttk::entry $top.sha1 -width 40
3823 3823 $top.sha1 insert 0 $rowmenuid
3824 3824 $top.sha1 conf -state readonly
3825 3825 grid $top.id $top.sha1 -sticky w -pady {10 0}
3826 3826 ttk::entry $top.head -width 60
3827 3827 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3828 3828 $top.head conf -state readonly
3829 3829 grid x $top.head -sticky w
3830 3830 ttk::label $top.tlab -text "Tag name:"
3831 3831 ttk::entry $top.tag -width 60
3832 3832 grid $top.tlab $top.tag -sticky w
3833 3833 ttk::frame $top.buts
3834 3834 ttk::button $top.buts.gen -text "Create" -command mktaggo
3835 3835 ttk::button $top.buts.can -text "Cancel" -command mktagcan
3836 3836 grid $top.buts.gen $top.buts.can
3837 3837 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3838 3838 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3839 3839 grid $top.buts - -pady 10 -sticky ew
3840 3840 focus $top.tag
3841 3841 popupify $top
3842 3842 wm title $top "Create a tag"
3843 3843 }
3844 3844
3845 3845 proc domktag {} {
3846 3846 global mktagtop env tagids idtags
3847 3847
3848 3848 set id [$mktagtop.sha1 get]
3849 3849 set tag [$mktagtop.tag get]
3850 3850 if {$tag == {}} {
3851 3851 error_popup "No tag name specified"
3852 3852 return
3853 3853 }
3854 3854 if {[info exists tagids($tag)]} {
3855 3855 error_popup "Tag \"$tag\" already exists"
3856 3856 return
3857 3857 }
3858 3858 if {[catch {
3859 3859 set out [exec $env(HG) --config ui.report_untrusted=false tag -r $id $tag]
3860 3860 } err]} {
3861 3861 error_popup "Error creating tag: $err"
3862 3862 return
3863 3863 }
3864 3864
3865 3865 set tagids($tag) $id
3866 3866 lappend idtags($id) $tag
3867 3867 redrawtags $id
3868 3868 }
3869 3869
3870 3870 proc redrawtags {id} {
3871 3871 global canv linehtag idline idpos selectedline
3872 3872
3873 3873 if {![info exists idline($id)]} return
3874 3874 $canv delete tag.$id
3875 3875 set xt [eval drawtags $id $idpos($id)]
3876 3876 $canv coords $linehtag($idline($id)) $xt [lindex $idpos($id) 2]
3877 3877 if {[info exists selectedline] && $selectedline == $idline($id)} {
3878 3878 selectline $selectedline 0
3879 3879 }
3880 3880 }
3881 3881
3882 3882 proc mktagcan {} {
3883 3883 global mktagtop
3884 3884
3885 3885 catch {destroy $mktagtop}
3886 3886 unset mktagtop
3887 3887 }
3888 3888
3889 3889 proc mktaggo {} {
3890 3890 domktag
3891 3891 mktagcan
3892 3892 }
3893 3893
3894 3894 proc writecommit {} {
3895 3895 global rowmenuid wrcomtop commitinfo wrcomcmd
3896 3896
3897 3897 set top .writecommit
3898 3898 set wrcomtop $top
3899 3899 catch {destroy $top}
3900 3900 toplevel $top
3901 3901 ttk::label $top.id -text "ID:"
3902 3902 ttk::entry $top.sha1 -width 40
3903 3903 $top.sha1 insert 0 $rowmenuid
3904 3904 $top.sha1 conf -state readonly
3905 3905 grid $top.id $top.sha1 -sticky w -pady {10 0}
3906 3906 ttk::entry $top.head -width 60
3907 3907 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0]
3908 3908 $top.head conf -state readonly
3909 3909 grid x $top.head -sticky w
3910 3910 ttk::label $top.clab -text "Command:"
3911 3911 ttk::entry $top.cmd -width 60 -textvariable wrcomcmd
3912 3912 grid $top.clab $top.cmd -sticky w -pady 10
3913 3913 ttk::label $top.flab -text "Output file:"
3914 3914 ttk::entry $top.fname -width 60
3915 3915 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"]
3916 3916 grid $top.flab $top.fname -sticky w
3917 3917 ttk::frame $top.buts
3918 3918 ttk::button $top.buts.gen -text "Write" -command wrcomgo
3919 3919 ttk::button $top.buts.can -text "Cancel" -command wrcomcan
3920 3920 grid $top.buts.gen $top.buts.can
3921 3921 grid columnconfigure $top.buts 0 -weight 1 -uniform a
3922 3922 grid columnconfigure $top.buts 1 -weight 1 -uniform a
3923 3923 grid $top.buts - -pady 10 -sticky ew
3924 3924 focus $top.fname
3925 3925 popupify $top
3926 3926 wm title $top "Write commit to a file"
3927 3927 }
3928 3928
3929 3929 proc wrcomgo {} {
3930 3930 global wrcomtop
3931 3931
3932 3932 set id [$wrcomtop.sha1 get]
3933 3933 set cmd "echo $id | [$wrcomtop.cmd get]"
3934 3934 set fname [$wrcomtop.fname get]
3935 3935 if {[catch {exec sh -c $cmd > $fname &} err]} {
3936 3936 error_popup "Error writing commit: $err"
3937 3937 }
3938 3938 catch {destroy $wrcomtop}
3939 3939 unset wrcomtop
3940 3940 }
3941 3941
3942 3942 proc wrcomcan {} {
3943 3943 global wrcomtop
3944 3944
3945 3945 catch {destroy $wrcomtop}
3946 3946 unset wrcomtop
3947 3947 }
3948 3948
3949 3949 proc listrefs {id} {
3950 3950 global idtags idheads idotherrefs idbookmarks
3951 3951
3952 3952 set w {}
3953 3953 if {[info exists idbookmarks($id)]} {
3954 3954 set w $idbookmarks($id)
3955 3955 }
3956 3956 set x {}
3957 3957 if {[info exists idtags($id)]} {
3958 3958 set x $idtags($id)
3959 3959 }
3960 3960 set y {}
3961 3961 if {[info exists idheads($id)]} {
3962 3962 set y $idheads($id)
3963 3963 }
3964 3964 set z {}
3965 3965 if {[info exists idotherrefs($id)]} {
3966 3966 set z $idotherrefs($id)
3967 3967 }
3968 3968 return [list $w $x $y $z]
3969 3969 }
3970 3970
3971 3971 proc rereadrefs {} {
3972 3972 global idbookmarks idtags idheads idotherrefs
3973 3973 global bookmarkids tagids headids otherrefids
3974 3974
3975 3975 set refids [concat [array names idtags] \
3976 3976 [array names idheads] [array names idotherrefs] \
3977 3977 [array names idbookmarks]]
3978 3978 foreach id $refids {
3979 3979 if {![info exists ref($id)]} {
3980 3980 set ref($id) [listrefs $id]
3981 3981 }
3982 3982 }
3983 3983 foreach v {tagids idtags headids idheads otherrefids idotherrefs \
3984 3984 bookmarkids idbookmarks} {
3985 3985 catch {unset $v}
3986 3986 }
3987 3987 readrefs
3988 3988 set refids [lsort -unique [concat $refids [array names idtags] \
3989 3989 [array names idheads] [array names idotherrefs] \
3990 3990 [array names idbookmarks]]]
3991 3991 foreach id $refids {
3992 3992 set v [listrefs $id]
3993 3993 if {![info exists ref($id)] || $ref($id) != $v} {
3994 3994 redrawtags $id
3995 3995 }
3996 3996 }
3997 3997 }
3998 3998
3999 3999 proc vdiff {withparent} {
4000 4000 global env rowmenuid selectedline lineid hgvdiff
4001 4001
4002 4002 if {![info exists rowmenuid]} return
4003 4003 set curid $rowmenuid
4004 4004
4005 4005 if {$withparent} {
4006 4006 set parents [exec $env(HG) --config ui.report_untrusted=false parents --rev $curid --template "{node}\n"]
4007 4007 set firstparent [lindex [split $parents "\n"] 0]
4008 4008 set otherid $firstparent
4009 4009 } else {
4010 4010 if {![info exists selectedline]} return
4011 4011 set otherid $lineid($selectedline)
4012 4012 }
4013 4013 set range "$otherid:$curid"
4014 4014 if {[catch {exec $env(HG) --config ui.report_untrusted=false $hgvdiff -r $range} err]} {
4015 4015 # Ignore errors, this is just visualization
4016 4016 }
4017 4017 }
4018 4018
4019 4019 proc showtag {tag isnew} {
4020 4020 global ctext cflist tagcontents tagids linknum
4021 4021
4022 4022 if {$isnew} {
4023 4023 addtohistory [list showtag $tag 0]
4024 4024 }
4025 4025 $ctext conf -state normal
4026 4026 $ctext delete 0.0 end
4027 4027 set linknum 0
4028 4028 if {[info exists tagcontents($tag)]} {
4029 4029 set text $tagcontents($tag)
4030 4030 } else {
4031 4031 set text "Tag: $tag\nId: $tagids($tag)"
4032 4032 }
4033 4033 appendwithlinks $text
4034 4034 $ctext conf -state disabled
4035 4035 $cflist delete 0 end
4036 4036 }
4037 4037
4038 4038 proc doquit {} {
4039 4039 global stopped
4040 4040 set stopped 100
4041 4041 destroy .
4042 4042 }
4043 4043
4044 4044 proc getconfig {} {
4045 4045 global env
4046 4046
4047 4047 set lines [exec $env(HG) debug-config]
4048 4048 regsub -all "\r\n" $lines "\n" config
4049 4049 set config {}
4050 4050 foreach line [split $lines "\n"] {
4051 4051 regsub "^(k|v)=" $line "" line
4052 4052 lappend config $line
4053 4053 }
4054 4054 return $config
4055 4055 }
4056 4056
4057 4057 # defaults...
4058 4058 set datemode 0
4059 4059 set boldnames 0
4060 4060 set diffopts "-U 5 -p"
4061 4061 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty"
4062 4062
4063 4063 set mainfont {Helvetica 9}
4064 4064 set curidfont {}
4065 4065 set textfont {Courier 9}
4066 4066 set findmergefiles 0
4067 4067 set gaudydiff 0
4068 4068 set maxgraphpct 50
4069 4069 set maxwidth 16
4070 4070
4071 4071 set colors {green red blue magenta darkgrey brown orange}
4072 4072 set authorcolors {
4073 4073 black blue deeppink mediumorchid blue burlywood4 goldenrod slateblue red2 navy dimgrey
4074 4074 }
4075 4075 set bgcolor white
4076 4076
4077 4077 # This color should probably be some system color (provided by tk),
4078 4078 # but as the bgcolor has always been set to white, I choose to ignore
4079 4079 set fgcolor black
4080 4080 set diffaddcolor "#00a000"
4081 4081 set diffremcolor red
4082 4082 set diffmerge1color red
4083 4083 set diffmerge2color blue
4084 4084 set hunksepcolor blue
4085 4085
4086 4086 catch {source ~/.hgk}
4087 4087
4088 4088 if {$curidfont == ""} { # initialize late based on current mainfont
4089 4089 set curidfont "$mainfont bold italic underline"
4090 4090 }
4091 4091
4092 4092 set namefont $mainfont
4093 4093 if {$boldnames} {
4094 4094 lappend namefont bold
4095 4095 }
4096 4096
4097 4097 set revtreeargs {}
4098 4098 foreach arg $argv {
4099 4099 switch -regexp -- $arg {
4100 4100 "^$" { }
4101 4101 "^-b" { set boldnames 1 }
4102 4102 "^-d" { set datemode 1 }
4103 4103 default {
4104 4104 lappend revtreeargs $arg
4105 4105 }
4106 4106 }
4107 4107 }
4108 4108
4109 4109 set history {}
4110 4110 set historyindex 0
4111 4111
4112 4112 set stopped 0
4113 4113 set redisplaying 0
4114 4114 set stuffsaved 0
4115 4115 set patchnum 0
4116 4116
4117 4117 array set config [getconfig]
4118 4118 set hgvdiff $config(vdiff)
4119 4119 setcoords
4120 4120 makewindow
4121 4121 readrefs
4122 4122 set hgroot [exec $env(HG) root]
4123 4123 wm title . "hgk $hgroot"
4124 4124 getcommits $revtreeargs
@@ -1,313 +1,313
1 1 # lint Python modules using external checkers.
2 #
2 #
3 3 # This is the main checker controlling the other ones and the reports
4 4 # generation. It is itself both a raw checker and an astng checker in order
5 5 # to:
6 6 # * handle message activation / deactivation at the module level
7 7 # * handle some basic but necessary stats'data (number of classes, methods...)
8 #
8 #
9 9 [MASTER]
10 10
11 11 # Specify a configuration file.
12 12 #rcfile=
13 13
14 14 # Python code to execute, usually for sys.path manipulation such as
15 15 # pygtk.require().
16 16 #init-hook=
17 17
18 18 # Profiled execution.
19 19 profile=no
20 20
21 21 # Add <file or directory> to the black list. It should be a base name, not a
22 22 # path. You may set this option multiple times.
23 23 ignore=CVS
24 24
25 25 # Pickle collected data for later comparisons.
26 26 persistent=yes
27 27
28 28 # Set the cache size for astng objects.
29 29 cache-size=500
30 30
31 31 # List of plugins (as comma separated values of python modules names) to load,
32 32 # usually to register additional checkers.
33 33 load-plugins=
34 34
35 35
36 36 [MESSAGES CONTROL]
37 37
38 38 # Enable only checker(s) with the given id(s). This option conflicts with the
39 39 # disable-checker option
40 40 #enable-checker=
41 41
42 42 # Enable all checker(s) except those with the given id(s). This option
43 43 # conflicts with the enable-checker option
44 44 #disable-checker=
45 45
46 46 # Enable all messages in the listed categories (IRCWEF).
47 47 #enable-msg-cat=
48 48
49 49 # Disable all messages in the listed categories (IRCWEF).
50 50 disable-msg-cat=I
51 51
52 52 # Enable the message(s) with the given id(s).
53 53 #enable-msg=
54 54
55 55 # Disable the message(s) with the given id(s).
56 56 # W0704: except: pass
57 57 # C0111: missing docstring
58 58 # W0403: for the time being absolute imports don't play nice with demandimport
59 59 disable-msg=W0704,C0111,W0403
60 60
61 61
62 62 [REPORTS]
63 63
64 64 # Set the output format. Available formats are text, parseable, colorized, msvs
65 65 # (visual studio) and html
66 66 output-format=text
67 67
68 68 # Include message's id in output
69 69 include-ids=yes
70 70
71 71 # Put messages in a separate file for each module / package specified on the
72 72 # command line instead of printing them on stdout. Reports (if any) will be
73 73 # written in a file name "pylint_global.[txt|html]".
74 74 files-output=no
75 75
76 76 # Tells whether to display a full report or only the messages
77 77 reports=yes
78 78
79 79 # Python expression which should return a note less than 10 (10 is the highest
80 80 # note). You have access to the variables errors warning, statement which
81 81 # respectively contain the number of errors / warnings messages and the total
82 82 # number of statements analyzed. This is used by the global evaluation report
83 83 # (R0004).
84 84 evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
85 85
86 86 # Add a comment according to your evaluation note. This is used by the global
87 87 # evaluation report (R0004).
88 88 comment=no
89 89
90 90 # Enable the report(s) with the given id(s).
91 91 #enable-report=
92 92
93 93 # Disable the report(s) with the given id(s).
94 94 #disable-report=
95 95
96 96
97 97 # try to find bugs in the code using type inference
98 #
98 #
99 99 [TYPECHECK]
100 100
101 101 # Tells whether missing members accessed in mixin class should be ignored. A
102 102 # mixin class is detected if its name ends with "mixin" (case insensitive).
103 103 ignore-mixin-members=yes
104 104
105 105 # List of classes names for which member attributes should not be checked
106 106 # (useful for classes with attributes dynamically set).
107 107 ignored-classes=SQLObject
108 108
109 109 # When zope mode is activated, add a predefined set of Zope acquired attributes
110 110 # to generated-members.
111 111 zope=no
112 112
113 113 # List of members which are set dynamically and missed by pylint inference
114 114 # system, and so shouldn't trigger E0201 when accessed.
115 115 generated-members=REQUEST,acl_users,aq_parent
116 116
117 117
118 118 # checks for
119 119 # * unused variables / imports
120 120 # * undefined variables
121 121 # * redefinition of variable from builtins or from an outer scope
122 122 # * use of variable before assignment
123 #
123 #
124 124 [VARIABLES]
125 125
126 126 # Tells whether we should check for unused import in __init__ files.
127 127 init-import=yes
128 128
129 129 # A regular expression matching names used for dummy variables (i.e. not used).
130 130 dummy-variables-rgx=dummy
131 131
132 132 # List of additional names supposed to be defined in builtins. Remember that
133 133 # you should avoid to define new builtins when possible.
134 134 additional-builtins=
135 135
136 136
137 137 # checks for :
138 138 # * doc strings
139 139 # * modules / classes / functions / methods / arguments / variables name
140 140 # * number of arguments, local variables, branches, returns and statements in
141 141 # functions, methods
142 142 # * required module attributes
143 143 # * dangerous default values as arguments
144 144 # * redefinition of function / method / class
145 145 # * uses of the global statement
146 #
146 #
147 147 [BASIC]
148 148
149 149 # Required attributes for module, separated by a comma
150 150 required-attributes=
151 151
152 152 # Regular expression which should only match functions or classes name which do
153 153 # not require a docstring
154 154 no-docstring-rgx=__.*__
155 155
156 156 # Regular expression which should only match correct module names
157 157 module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
158 158
159 159 # Regular expression which should only match correct module level names
160 160 const-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
161 161
162 162 # Regular expression which should only match correct class names
163 163 class-rgx=[a-zA-Z_][a-zA-Z0-9]+$
164 164
165 165 # Regular expression which should only match correct function names
166 166 function-rgx=[a-z_][a-z0-9_]{2,30}$
167 167
168 168 # Regular expression which should only match correct method names
169 169 method-rgx=[a-z_][a-z0-9_]{2,30}$
170 170
171 171 # Regular expression which should only match correct instance attribute names
172 172 attr-rgx=[a-z_][a-z0-9_]{1,30}$
173 173
174 174 # Regular expression which should only match correct argument names
175 175 argument-rgx=[a-z_][a-z0-9_]{0,30}$
176 176
177 177 # Regular expression which should only match correct variable names
178 178 variable-rgx=[a-z_][a-z0-9_]{0,30}$
179 179
180 180 # Regular expression which should only match correct list comprehension /
181 181 # generator expression variable names
182 182 inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
183 183
184 184 # Good variable names which should always be accepted, separated by a comma
185 185 good-names=i,j,k,ex,Run,_,ui,c,fn,f,fd,l
186 186
187 187 # Bad variable names which should always be refused, separated by a comma
188 188 bad-names=foo,bar,baz,toto,tutu,tata
189 189
190 190 # List of builtins function names that should not be used, separated by a comma
191 191 #bad-functions=map,filter,apply,input
192 192 bad-functions=map,filter,apply,input
193 193
194 194
195 195 # checks for
196 196 # * external modules dependencies
197 197 # * relative / wildcard imports
198 198 # * cyclic imports
199 199 # * uses of deprecated modules
200 #
200 #
201 201 [IMPORTS]
202 202
203 203 # Deprecated modules which should not be used, separated by a comma
204 204 deprecated-modules=regsub,TERMIOS,Bastion,rexec
205 205
206 206 # Create a graph of every (i.e. internal and external) dependencies in the
207 207 # given file (report R0402 must not be disabled)
208 208 import-graph=
209 209
210 210 # Create a graph of external dependencies in the given file (report R0402 must
211 211 # not be disabled)
212 212 ext-import-graph=
213 213
214 214 # Create a graph of internal dependencies in the given file (report R0402 must
215 215 # not be disabled)
216 216 int-import-graph=
217 217
218 218
219 219 # checks for sign of poor/misdesign:
220 220 # * number of methods, attributes, local variables...
221 221 # * size, complexity of functions, methods
222 #
222 #
223 223 [DESIGN]
224 224
225 225 # Maximum number of arguments for function / method
226 226 max-args=5
227 227
228 228 # Maximum number of locals for function / method body
229 229 max-locals=15
230 230
231 231 # Maximum number of return / yield for function / method body
232 232 max-returns=6
233 233
234 234 # Maximum number of branch for function / method body
235 235 max-branchs=12
236 236
237 237 # Maximum number of statements in function / method body
238 238 max-statements=50
239 239
240 240 # Maximum number of parents for a class (see R0901).
241 241 max-parents=7
242 242
243 243 # Maximum number of attributes for a class (see R0902).
244 244 max-attributes=7
245 245
246 246 # Minimum number of public methods for a class (see R0903).
247 247 min-public-methods=2
248 248
249 249 # Maximum number of public methods for a class (see R0904).
250 250 max-public-methods=20
251 251
252 252
253 253 # checks for :
254 254 # * methods without self as first argument
255 255 # * overridden methods signature
256 256 # * access only to existent members via self
257 257 # * attributes not defined in the __init__ method
258 258 # * supported interfaces implementation
259 259 # * unreachable code
260 #
260 #
261 261 [CLASSES]
262 262
263 263 # List of interface methods to ignore, separated by a comma. This is used for
264 264 # instance to not check methods defines in Zope's Interface base class.
265 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 267 # List of method names used to declare (i.e. assign) instance attributes.
268 268 defining-attr-methods=__init__,__new__,setUp
269 269
270 270
271 271 # checks for :
272 272 # * unauthorized constructions
273 273 # * strict indentation
274 274 # * line length
275 275 # * use of <> instead of !=
276 #
276 #
277 277 [FORMAT]
278 278
279 279 # Maximum number of characters on a single line.
280 280 max-line-length=80
281 281
282 282 # Maximum number of lines in a module
283 283 max-module-lines=1000
284 284
285 285 # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
286 286 # tab).
287 287 indent-string=' '
288 288
289 289
290 290 # checks for:
291 291 # * warning notes in the code like FIXME, XXX
292 292 # * PEP 263: source code with non ascii character but no encoding declaration
293 #
293 #
294 294 [MISCELLANEOUS]
295 295
296 296 # List of note tags to take in consideration, separated by a comma.
297 297 notes=FIXME,XXX,TODO
298 298
299 299
300 300 # checks for similarities and duplicated code. This computation may be
301 301 # memory / CPU intensive, so you should disable it if you experiments some
302 302 # problems.
303 #
303 #
304 304 [SIMILARITIES]
305 305
306 306 # Minimum lines number of a similarity.
307 307 min-similarity-lines=4
308 308
309 309 # Ignore comments when computing similarities.
310 310 ignore-comments=yes
311 311
312 312 # Ignore docstrings when computing similarities.
313 313 ignore-docstrings=yes
@@ -1,1703 +1,1703
1 1 " vim600: set foldmethod=marker:
2 2 "
3 3 " Vim plugin to assist in working with HG-controlled files.
4 4 "
5 5 " Last Change: 2006/02/22
6 6 " Version: 1.77
7 7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
8 8 " License: This file is placed in the public domain.
9 9 " Credits:
10 10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
11 11 " cvscommand.vim from which this script was directly created by
12 12 " means of sed commands and minor tweaks.
13 " Note:
13 " Note:
14 14 " For Vim7 the use of Bob Hiestand's vcscommand.vim
15 15 " <http://www.vim.org/scripts/script.php?script_id=90>
16 16 " in conjunction with Vladmir Marek's Hg backend
17 17 " <http://www.vim.org/scripts/script.php?script_id=1898>
18 18 " is recommended.
19 19
20 20 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
21 21 "
22 22 " Section: Documentation
23 23 "----------------------------
24 24 "
25 25 " Documentation should be available by ":help hgcommand" command, once the
26 26 " script has been copied in you .vim/plugin directory.
27 27 "
28 28 " You still can read the documentation at the end of this file. Locate it by
29 29 " searching the "hgcommand-contents" string (and set ft=help to have
30 30 " appropriate syntactic coloration).
31 31
32 32 " Section: Plugin header {{{1
33 33
34 34 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
35 35 " completes. This allows various actions to only be taken by functions after
36 36 " system initialization.
37 37
38 38 if exists("g:loaded_hgcommand")
39 39 finish
40 40 endif
41 41 let g:loaded_hgcommand = 1
42 42
43 43 " store 'compatible' settings
44 44 let s:save_cpo = &cpo
45 45 set cpo&vim
46 46
47 47 " run checks
48 48 let s:script_name = expand("<sfile>:t:r")
49 49
50 50 function! s:HGCleanupOnFailure(err)
51 51 echohl WarningMsg
52 52 echomsg s:script_name . ":" a:err "Plugin not loaded"
53 53 echohl None
54 54 let g:loaded_hgcommand = "no"
55 55 unlet s:save_cpo s:script_name
56 56 endfunction
57 57
58 58 if v:version < 602
59 59 call <SID>HGCleanupOnFailure("VIM 6.2 or later required.")
60 60 finish
61 61 endif
62 62
63 63 if !exists("*system")
64 64 call <SID>HGCleanupOnFailure("builtin system() function required.")
65 65 finish
66 66 endif
67 67
68 68 let s:script_version = "v0.2"
69 69
70 70 " Section: Event group setup {{{1
71 71
72 72 augroup HGCommand
73 73 augroup END
74 74
75 75 " Section: Plugin initialization {{{1
76 76 silent do HGCommand User HGPluginInit
77 77
78 78 " Section: Script variable initialization {{{1
79 79
80 80 let s:HGCommandEditFileRunning = 0
81 81 unlet! s:vimDiffRestoreCmd
82 82 unlet! s:vimDiffSourceBuffer
83 83 unlet! s:vimDiffBufferCount
84 84 unlet! s:vimDiffScratchList
85 85
86 86 " Section: Utility functions {{{1
87 87
88 88 " Function: s:HGResolveLink() {{{2
89 89 " Fully resolve the given file name to remove shortcuts or symbolic links.
90 90
91 91 function! s:HGResolveLink(fileName)
92 92 let resolved = resolve(a:fileName)
93 93 if resolved != a:fileName
94 94 let resolved = <SID>HGResolveLink(resolved)
95 95 endif
96 96 return resolved
97 97 endfunction
98 98
99 99 " Function: s:HGChangeToCurrentFileDir() {{{2
100 100 " Go to the directory in which the current HG-controlled file is located.
101 101 " If this is a HG command buffer, first switch to the original file.
102 102
103 103 function! s:HGChangeToCurrentFileDir(fileName)
104 104 let oldCwd=getcwd()
105 105 let fileName=<SID>HGResolveLink(a:fileName)
106 106 let newCwd=fnamemodify(fileName, ':h')
107 107 if strlen(newCwd) > 0
108 108 execute 'cd' escape(newCwd, ' ')
109 109 endif
110 110 return oldCwd
111 111 endfunction
112 112
113 113 " Function: <SID>HGGetOption(name, default) {{{2
114 114 " Grab a user-specified option to override the default provided. Options are
115 115 " searched in the window, buffer, then global spaces.
116 116
117 117 function! s:HGGetOption(name, default)
118 118 if exists("s:" . a:name . "Override")
119 119 execute "return s:".a:name."Override"
120 120 elseif exists("w:" . a:name)
121 121 execute "return w:".a:name
122 122 elseif exists("b:" . a:name)
123 123 execute "return b:".a:name
124 124 elseif exists("g:" . a:name)
125 125 execute "return g:".a:name
126 126 else
127 127 return a:default
128 128 endif
129 129 endfunction
130 130
131 131 " Function: s:HGEditFile(name, origBuffNR) {{{2
132 132 " Wrapper around the 'edit' command to provide some helpful error text if the
133 133 " current buffer can't be abandoned. If name is provided, it is used;
134 134 " otherwise, a nameless scratch buffer is used.
135 135 " Returns: 0 if successful, -1 if an error occurs.
136 136
137 137 function! s:HGEditFile(name, origBuffNR)
138 138 "Name parameter will be pasted into expression.
139 139 let name = escape(a:name, ' *?\')
140 140
141 141 let editCommand = <SID>HGGetOption('HGCommandEdit', 'edit')
142 142 if editCommand != 'edit'
143 143 if <SID>HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
144 144 if name == ""
145 145 let editCommand = 'rightbelow new'
146 146 else
147 147 let editCommand = 'rightbelow split ' . name
148 148 endif
149 149 else
150 150 if name == ""
151 151 let editCommand = 'vert rightbelow new'
152 152 else
153 153 let editCommand = 'vert rightbelow split ' . name
154 154 endif
155 155 endif
156 156 else
157 157 if name == ""
158 158 let editCommand = 'enew'
159 159 else
160 160 let editCommand = 'edit ' . name
161 161 endif
162 162 endif
163 163
164 164 " Protect against useless buffer set-up
165 165 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
166 166 try
167 167 execute editCommand
168 168 finally
169 169 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
170 170 endtry
171 171
172 172 let b:HGOrigBuffNR=a:origBuffNR
173 173 let b:HGCommandEdit='split'
174 174 endfunction
175 175
176 176 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
177 177 " Creates a new scratch buffer and captures the output from execution of the
178 178 " given command. The name of the scratch buffer is returned.
179 179
180 180 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
181 181 let fileName=bufname(a:origBuffNR)
182 182
183 183 let resultBufferName=''
184 184
185 185 if <SID>HGGetOption("HGCommandNameResultBuffers", 0)
186 186 let nameMarker = <SID>HGGetOption("HGCommandNameMarker", '_')
187 187 if strlen(a:statusText) > 0
188 188 let bufName=a:cmdName . ' -- ' . a:statusText
189 189 else
190 190 let bufName=a:cmdName
191 191 endif
192 192 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
193 193 let counter=0
194 194 let resultBufferName = bufName
195 195 while buflisted(resultBufferName)
196 196 let counter=counter + 1
197 197 let resultBufferName=bufName . ' (' . counter . ')'
198 198 endwhile
199 199 endif
200 200
201 201 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
202 202 "echomsg "DBG :".hgCommand
203 203 let hgOut = system(hgCommand)
204 204 " HACK: diff command does not return proper error codes
205 205 if v:shell_error && a:cmdName != 'hgdiff'
206 206 if strlen(hgOut) == 0
207 207 echoerr "HG command failed"
208 208 else
209 209 echoerr "HG command failed: " . hgOut
210 210 endif
211 211 return -1
212 212 endif
213 213 if strlen(hgOut) == 0
214 214 " Handle case of no output. In this case, it is important to check the
215 215 " file status, especially since hg edit/unedit may change the attributes
216 216 " of the file with no visible output.
217 217
218 218 echomsg "No output from HG command"
219 219 checktime
220 220 return -1
221 221 endif
222 222
223 223 if <SID>HGEditFile(resultBufferName, a:origBuffNR) == -1
224 224 return -1
225 225 endif
226 226
227 227 set buftype=nofile
228 228 set noswapfile
229 229 set filetype=
230 230
231 231 if <SID>HGGetOption("HGCommandDeleteOnHide", 0)
232 232 set bufhidden=delete
233 233 endif
234 234
235 235 silent 0put=hgOut
236 236
237 237 " The last command left a blank line at the end of the buffer. If the
238 238 " last line is folded (a side effect of the 'put') then the attempt to
239 239 " remove the blank line will kill the last fold.
240 240 "
241 241 " This could be fixed by explicitly detecting whether the last line is
242 242 " within a fold, but I prefer to simply unfold the result buffer altogether.
243 243
244 244 if has("folding")
245 245 setlocal nofoldenable
246 246 endif
247 247
248 248 $d
249 249 1
250 250
251 251 " Define the environment and execute user-defined hooks.
252 252
253 253 let b:HGSourceFile=fileName
254 254 let b:HGCommand=a:cmdName
255 255 if a:statusText != ""
256 256 let b:HGStatusText=a:statusText
257 257 endif
258 258
259 259 silent do HGCommand User HGBufferCreated
260 260 return bufnr("%")
261 261 endfunction
262 262
263 263 " Function: s:HGBufferCheck(hgBuffer) {{{2
264 264 " Attempts to locate the original file to which HG operations were applied
265 265 " for a given buffer.
266 266
267 267 function! s:HGBufferCheck(hgBuffer)
268 268 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
269 269 if origBuffer
270 270 if bufexists(origBuffer)
271 271 return origBuffer
272 272 else
273 273 " Original buffer no longer exists.
274 274 return -1
275 275 endif
276 276 else
277 277 " No original buffer
278 278 return a:hgBuffer
279 279 endif
280 280 endfunction
281 281
282 282 " Function: s:HGCurrentBufferCheck() {{{2
283 283 " Attempts to locate the original file to which HG operations were applied
284 284 " for the current buffer.
285 285
286 286 function! s:HGCurrentBufferCheck()
287 287 return <SID>HGBufferCheck(bufnr("%"))
288 288 endfunction
289 289
290 290 " Function: s:HGToggleDeleteOnHide() {{{2
291 291 " Toggles on and off the delete-on-hide behavior of HG buffers
292 292
293 293 function! s:HGToggleDeleteOnHide()
294 294 if exists("g:HGCommandDeleteOnHide")
295 295 unlet g:HGCommandDeleteOnHide
296 296 else
297 297 let g:HGCommandDeleteOnHide=1
298 298 endif
299 299 endfunction
300 300
301 301 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
302 302 " General skeleton for HG function execution.
303 303 " Returns: name of the new command buffer containing the command results
304 304
305 305 function! s:HGDoCommand(cmd, cmdName, statusText)
306 306 let hgBufferCheck=<SID>HGCurrentBufferCheck()
307 307 if hgBufferCheck == -1
308 308 echo "Original buffer no longer exists, aborting."
309 309 return -1
310 310 endif
311 311
312 312 let fileName=bufname(hgBufferCheck)
313 313 if isdirectory(fileName)
314 314 let fileName=fileName . "/" . getline(".")
315 315 endif
316 316 let realFileName = fnamemodify(<SID>HGResolveLink(fileName), ':t')
317 317 let oldCwd=<SID>HGChangeToCurrentFileDir(fileName)
318 318 try
319 319 " TODO
320 320 "if !filereadable('HG/Root')
321 321 "throw fileName . ' is not a HG-controlled file.'
322 322 "endif
323 323 let fullCmd = a:cmd . ' "' . realFileName . '"'
324 324 "echomsg "DEBUG".fullCmd
325 325 let resultBuffer=<SID>HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
326 326 return resultBuffer
327 327 catch
328 328 echoerr v:exception
329 329 return -1
330 330 finally
331 331 execute 'cd' escape(oldCwd, ' ')
332 332 endtry
333 333 endfunction
334 334
335 335
336 336 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
337 337 "
338 338 " Obtains a HG revision number and branch name. The 'revisionVar',
339 339 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
340 340 " the corresponding results.
341 341 "
342 342 " Returns: string to be exec'd that sets the multiple return values.
343 343
344 344 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
345 345 let hgBufferCheck=<SID>HGCurrentBufferCheck()
346 346 "echomsg "DBG : in HGGetStatusVars"
347 347 if hgBufferCheck == -1
348 348 return ""
349 349 endif
350 350 let fileName=bufname(hgBufferCheck)
351 351 let fileNameWithoutLink=<SID>HGResolveLink(fileName)
352 352 let realFileName = fnamemodify(fileNameWithoutLink, ':t')
353 353 let oldCwd=<SID>HGChangeToCurrentFileDir(realFileName)
354 354 try
355 355 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " root "
356 356 let roottext=system(hgCommand)
357 357 " Suppress ending null char ! Does it work in window ?
358 358 let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
359 359 if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
360 360 return ""
361 361 endif
362 362 let returnExpression = ""
363 363 if a:repositoryVar != ""
364 364 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
365 365 endif
366 366 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
367 367 let statustext=system(hgCommand)
368 368 if(v:shell_error)
369 369 return ""
370 370 endif
371 371 if match(statustext, '^[?I]') >= 0
372 372 let revision="NEW"
373 373 elseif match(statustext, '^[R]') >= 0
374 374 let revision="REMOVED"
375 375 elseif match(statustext, '^[D]') >= 0
376 376 let revision="DELETED"
377 377 elseif match(statustext, '^[A]') >= 0
378 378 let revision="ADDED"
379 379 else
380 380 " The file is tracked, we can try to get is revision number
381 381 let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " parents "
382 382 let statustext=system(hgCommand)
383 383 if(v:shell_error)
384 384 return ""
385 385 endif
386 386 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
387 387
388 388 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
389 389 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
390 390 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
391 391 endif
392 392 endif
393 393 if (exists('revision'))
394 394 let returnExpression = "let " . a:revisionVar . "='" . revision . "' " . returnExpression
395 395 endif
396 396
397 397 return returnExpression
398 398 finally
399 399 execute 'cd' escape(oldCwd, ' ')
400 400 endtry
401 401 endfunction
402 402
403 403 " Function: s:HGSetupBuffer() {{{2
404 404 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
405 405
406 406 function! s:HGSetupBuffer(...)
407 407 if (exists("b:HGBufferSetup") && b:HGBufferSetup && !exists('a:1'))
408 408 " This buffer is already set up.
409 409 return
410 410 endif
411 411
412 412 if !<SID>HGGetOption("HGCommandEnableBufferSetup", 0)
413 413 \ || @% == ""
414 414 \ || s:HGCommandEditFileRunning > 0
415 415 \ || exists("b:HGOrigBuffNR")
416 416 unlet! b:HGRevision
417 417 unlet! b:HGBranch
418 418 unlet! b:HGRepository
419 419 return
420 420 endif
421 421
422 422 if !filereadable(expand("%"))
423 423 return -1
424 424 endif
425 425
426 426 let revision=""
427 427 let branch=""
428 428 let repository=""
429 429
430 430 exec <SID>HGGetStatusVars('revision', 'branch', 'repository')
431 431 "echomsg "DBG ".revision."#".branch."#".repository
432 432 if revision != ""
433 433 let b:HGRevision=revision
434 434 else
435 435 unlet! b:HGRevision
436 436 endif
437 437 if branch != ""
438 438 let b:HGBranch=branch
439 439 else
440 440 unlet! b:HGBranch
441 441 endif
442 442 if repository != ""
443 443 let b:HGRepository=repository
444 444 else
445 445 unlet! b:HGRepository
446 446 endif
447 447 silent do HGCommand User HGBufferSetup
448 448 let b:HGBufferSetup=1
449 449 endfunction
450 450
451 451 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
452 452 " Resets the buffer setup state of the original buffer for a given HG buffer.
453 453 " Returns: The HG buffer number in a passthrough mode.
454 454
455 455 function! s:HGMarkOrigBufferForSetup(hgBuffer)
456 456 checktime
457 457 if a:hgBuffer != -1
458 458 let origBuffer = <SID>HGBufferCheck(a:hgBuffer)
459 459 "This should never not work, but I'm paranoid
460 460 if origBuffer != a:hgBuffer
461 461 call setbufvar(origBuffer, "HGBufferSetup", 0)
462 462 endif
463 463 else
464 464 "We are presumably in the original buffer
465 465 let b:HGBufferSetup = 0
466 466 "We do the setup now as now event will be triggered allowing it later.
467 467 call <SID>HGSetupBuffer()
468 468 endif
469 469 return a:hgBuffer
470 470 endfunction
471 471
472 472 " Function: s:HGOverrideOption(option, [value]) {{{2
473 473 " Provides a temporary override for the given HG option. If no value is
474 474 " passed, the override is disabled.
475 475
476 476 function! s:HGOverrideOption(option, ...)
477 477 if a:0 == 0
478 478 unlet! s:{a:option}Override
479 479 else
480 480 let s:{a:option}Override = a:1
481 481 endif
482 482 endfunction
483 483
484 484 " Function: s:HGWipeoutCommandBuffers() {{{2
485 485 " Clears all current HG buffers of the specified type for a given source.
486 486
487 487 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
488 488 let buffer = 1
489 489 while buffer <= bufnr('$')
490 490 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
491 491 if getbufvar(buffer, 'HGCommand') == a:hgCommand
492 492 execute 'bw' buffer
493 493 endif
494 494 endif
495 495 let buffer = buffer + 1
496 496 endwhile
497 497 endfunction
498 498
499 499 " Function: s:HGInstallDocumentation(full_name, revision) {{{2
500 500 " Install help documentation.
501 501 " Arguments:
502 502 " full_name: Full name of this vim plugin script, including path name.
503 503 " revision: Revision of the vim script. #version# mark in the document file
504 504 " will be replaced with this string with 'v' prefix.
505 505 " Return:
506 506 " 1 if new document installed, 0 otherwise.
507 507 " Note: Cleaned and generalized by guo-peng Wen
508 508 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
509 509 " Helper function to make mkdir as portable as possible
510 510 function! s:HGFlexiMkdir(dir)
511 511 if exists("*mkdir") " we can use Vim's own mkdir()
512 512 call mkdir(a:dir)
513 513 elseif !exists("+shellslash")
514 514 call system("mkdir -p '".a:dir."'")
515 515 else " M$
516 516 let l:ssl = &shellslash
517 517 try
518 518 set shellslash
519 519 " no single quotes?
520 520 call system('mkdir "'.a:dir.'"')
521 521 finally
522 522 let &shellslash = l:ssl
523 523 endtry
524 524 endif
525 525 endfunction
526 526
527 527 function! s:HGInstallDocumentation(full_name)
528 528 " Figure out document path based on full name of this script:
529 529 let l:vim_doc_path = fnamemodify(a:full_name, ":h:h") . "/doc"
530 530 if filewritable(l:vim_doc_path) != 2
531 531 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
532 532 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
533 533 if filewritable(l:vim_doc_path) != 2
534 534 " Try first item in 'runtimepath':
535 535 let l:vim_doc_path =
536 536 \ substitute(&runtimepath, '^\([^,]*\).*', '\1/doc', 'e')
537 537 if filewritable(l:vim_doc_path) != 2
538 538 echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
539 539 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
540 540 if filewritable(l:vim_doc_path) != 2
541 541 " Put a warning:
542 542 echomsg "Unable to open documentation directory"
543 543 echomsg " type `:help add-local-help' for more information."
544 544 return 0
545 545 endif
546 546 endif
547 547 endif
548 548 endif
549 549
550 550 " Full name of documentation file:
551 551 let l:doc_file =
552 552 \ l:vim_doc_path . "/" . s:script_name . ".txt"
553 553 " Bail out if document file is still up to date:
554 554 if filereadable(l:doc_file) &&
555 555 \ getftime(a:full_name) < getftime(l:doc_file)
556 556 return 0
557 557 endif
558 558
559 559 " temporary global settings
560 560 let l:lz = &lazyredraw
561 561 let l:hls = &hlsearch
562 562 set lazyredraw nohlsearch
563 563 " Create a new buffer & read in the plugin file (me):
564 564 1 new
565 565 setlocal noswapfile modifiable nomodeline
566 566 if has("folding")
567 567 setlocal nofoldenable
568 568 endif
569 569 silent execute "read" escape(a:full_name, " ")
570 570 let l:doc_buf = bufnr("%")
571 571
572 572 1
573 573 " Delete from first line to a line starts with
574 574 " === START_DOC
575 575 silent 1,/^=\{3,}\s\+START_DOC\C/ delete _
576 576 " Delete from a line starts with
577 577 " === END_DOC
578 578 " to the end of the documents:
579 579 silent /^=\{3,}\s\+END_DOC\C/,$ delete _
580 580
581 581 " Add modeline for help doc: the modeline string is mangled intentionally
582 582 " to avoid it be recognized by VIM:
583 583 call append(line("$"), "")
584 584 call append(line("$"), " v" . "im:tw=78:ts=8:ft=help:norl:")
585 585
586 586 " Replace revision:
587 587 silent execute "normal :1s/#version#/" . s:script_version . "/\<CR>"
588 588 " Save the help document and wipe out buffer:
589 589 silent execute "wq!" escape(l:doc_file, " ") "| bw" l:doc_buf
590 590 " Build help tags:
591 591 silent execute "helptags" l:vim_doc_path
592 592
593 593 let &hlsearch = l:hls
594 594 let &lazyredraw = l:lz
595 595 return 1
596 596 endfunction
597 597
598 598 " Section: Public functions {{{1
599 599
600 600 " Function: HGGetRevision() {{{2
601 601 " Global function for retrieving the current buffer's HG revision number.
602 602 " Returns: Revision number or an empty string if an error occurs.
603 603
604 604 function! HGGetRevision()
605 605 let revision=""
606 606 exec <SID>HGGetStatusVars('revision', '', '')
607 607 return revision
608 608 endfunction
609 609
610 610 " Function: HGDisableBufferSetup() {{{2
611 611 " Global function for deactivating the buffer autovariables.
612 612
613 613 function! HGDisableBufferSetup()
614 614 let g:HGCommandEnableBufferSetup=0
615 615 silent! augroup! HGCommandPlugin
616 616 endfunction
617 617
618 618 " Function: HGEnableBufferSetup() {{{2
619 619 " Global function for activating the buffer autovariables.
620 620
621 621 function! HGEnableBufferSetup()
622 622 let g:HGCommandEnableBufferSetup=1
623 623 augroup HGCommandPlugin
624 624 au!
625 625 au BufEnter * call <SID>HGSetupBuffer()
626 626 au BufWritePost * call <SID>HGSetupBuffer()
627 627 " Force resetting up buffer on external file change (HG update)
628 628 au FileChangedShell * call <SID>HGSetupBuffer(1)
629 629 augroup END
630 630
631 631 " Only auto-load if the plugin is fully loaded. This gives other plugins a
632 632 " chance to run.
633 633 if g:loaded_hgcommand == 2
634 634 call <SID>HGSetupBuffer()
635 635 endif
636 636 endfunction
637 637
638 638 " Function: HGGetStatusLine() {{{2
639 639 " Default (sample) status line entry for HG files. This is only useful if
640 640 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
641 641 " for how to do this).
642 642
643 643 function! HGGetStatusLine()
644 644 if exists('b:HGSourceFile')
645 645 " This is a result buffer
646 646 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
647 647 if exists('b:HGStatusText')
648 648 let value=value . ' ' . b:HGStatusText
649 649 endif
650 650 let value = value . ']'
651 651 return value
652 652 endif
653 653
654 654 if exists('b:HGRevision')
655 655 \ && b:HGRevision != ''
656 656 \ && exists('b:HGRepository')
657 657 \ && b:HGRepository != ''
658 658 \ && exists('g:HGCommandEnableBufferSetup')
659 659 \ && g:HGCommandEnableBufferSetup
660 660 if !exists('b:HGBranch')
661 661 let l:branch=''
662 662 else
663 663 let l:branch=b:HGBranch
664 664 endif
665 665 return '[HG ' . b:HGRepository . '/' . l:branch .'/' . b:HGRevision . ']'
666 666 else
667 667 return ''
668 668 endif
669 669 endfunction
670 670
671 671 " Section: HG command functions {{{1
672 672
673 673 " Function: s:HGAdd() {{{2
674 674 function! s:HGAdd()
675 675 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('add', 'hgadd', ''))
676 676 endfunction
677 677
678 678 " Function: s:HGAnnotate(...) {{{2
679 679 function! s:HGAnnotate(...)
680 680 if a:0 == 0
681 681 if &filetype == "HGAnnotate"
682 682 " This is a HGAnnotate buffer. Perform annotation of the version
683 683 " indicated by the current line.
684 684 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
685 685 if <SID>HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
686 686 let revision = revision - 1
687 687 endif
688 688 else
689 689 let revision=HGGetRevision()
690 690 if revision == ""
691 691 echoerr "Unable to obtain HG version information."
692 692 return -1
693 693 endif
694 694 endif
695 695 else
696 696 let revision=a:1
697 697 endif
698 698
699 699 if revision == "NEW"
700 700 echo "No annotatation available for new file."
701 701 return -1
702 702 endif
703 703
704 704 let resultBuffer=<SID>HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
705 705 "echomsg "DBG: ".resultBuffer
706 706 if resultBuffer != -1
707 707 set filetype=HGAnnotate
708 708 endif
709 709
710 710 return resultBuffer
711 711 endfunction
712 712
713 713 " Function: s:HGCommit() {{{2
714 714 function! s:HGCommit(...)
715 715 " Handle the commit message being specified. If a message is supplied, it
716 716 " is used; if bang is supplied, an empty message is used; otherwise, the
717 717 " user is provided a buffer from which to edit the commit message.
718 718 if a:2 != "" || a:1 == "!"
719 719 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
720 720 endif
721 721
722 722 let hgBufferCheck=<SID>HGCurrentBufferCheck()
723 723 if hgBufferCheck == -1
724 724 echo "Original buffer no longer exists, aborting."
725 725 return -1
726 726 endif
727 727
728 728 " Protect against windows' backslashes in paths. They confuse exec'd
729 729 " commands.
730 730
731 731 let shellSlashBak = &shellslash
732 732 try
733 733 set shellslash
734 734
735 735 let messageFileName = tempname()
736 736
737 737 let fileName=bufname(hgBufferCheck)
738 738 let realFilePath=<SID>HGResolveLink(fileName)
739 739 let newCwd=fnamemodify(realFilePath, ':h')
740 740 if strlen(newCwd) == 0
741 741 " Account for autochdir being in effect, which will make this blank, but
742 742 " we know we'll be in the current directory for the original file.
743 743 let newCwd = getcwd()
744 744 endif
745 745
746 746 let realFileName=fnamemodify(realFilePath, ':t')
747 747
748 748 if <SID>HGEditFile(messageFileName, hgBufferCheck) == -1
749 749 return
750 750 endif
751 751
752 752 " Protect against case and backslash issues in Windows.
753 753 let autoPattern = '\c' . messageFileName
754 754
755 755 " Ensure existence of group
756 756 augroup HGCommit
757 757 augroup END
758 758
759 759 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
760 760 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
761 761
762 762 " Create a commit mapping. The mapping must clear all autocommands in case
763 763 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
764 764 " invoke the buffer deletion autocommand.
765 765
766 766 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
767 767 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
768 768 \ ':g/^HG:/d<CR>'.
769 769 \ ':update<CR>'.
770 770 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
771 771 \ '"' . newCwd . '",' .
772 772 \ '"' . realFileName . '",' .
773 773 \ hgBufferCheck . ')<CR>'
774 774
775 775 silent 0put ='HG: ----------------------------------------------------------------------'
776 776 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
777 777 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
778 778
779 779 if <SID>HGGetOption('HGCommandCommitOnWrite', 1) == 1
780 780 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
781 781 execute 'au HGCommit BufWritePost' autoPattern 'call <SID>HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
782 782 silent put ='HG: or write this buffer'
783 783 endif
784 784
785 785 silent put ='HG: to finish this commit operation'
786 786 silent put ='HG: ----------------------------------------------------------------------'
787 787 $
788 788 let b:HGSourceFile=fileName
789 789 let b:HGCommand='HGCommit'
790 790 set filetype=hg
791 791 finally
792 792 let &shellslash = shellSlashBak
793 793 endtry
794 794
795 795 endfunction
796 796
797 797 " Function: s:HGDiff(...) {{{2
798 798 function! s:HGDiff(...)
799 799 if a:0 == 1
800 800 let revOptions = '-r' . a:1
801 801 let caption = a:1 . ' -> current'
802 802 elseif a:0 == 2
803 803 let revOptions = '-r' . a:1 . ' -r' . a:2
804 804 let caption = a:1 . ' -> ' . a:2
805 805 else
806 806 let revOptions = ''
807 807 let caption = ''
808 808 endif
809 809
810 810 let hgdiffopt=<SID>HGGetOption('HGCommandDiffOpt', 'w')
811 811
812 812 if hgdiffopt == ""
813 813 let diffoptionstring=""
814 814 else
815 815 let diffoptionstring=" -" . hgdiffopt . " "
816 816 endif
817 817
818 818 let resultBuffer = <SID>HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
819 819 if resultBuffer != -1
820 820 set filetype=diff
821 821 endif
822 822 return resultBuffer
823 823 endfunction
824 824
825 825
826 826 " Function: s:HGGotoOriginal(["!]) {{{2
827 827 function! s:HGGotoOriginal(...)
828 828 let origBuffNR = <SID>HGCurrentBufferCheck()
829 829 if origBuffNR > 0
830 830 let origWinNR = bufwinnr(origBuffNR)
831 831 if origWinNR == -1
832 832 execute 'buffer' origBuffNR
833 833 else
834 834 execute origWinNR . 'wincmd w'
835 835 endif
836 836 if a:0 == 1
837 837 if a:1 == "!"
838 838 let buffnr = 1
839 839 let buffmaxnr = bufnr("$")
840 840 while buffnr <= buffmaxnr
841 841 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
842 842 execute "bw" buffnr
843 843 endif
844 844 let buffnr = buffnr + 1
845 845 endwhile
846 846 endif
847 847 endif
848 848 endif
849 849 endfunction
850 850
851 851 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
852 852 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
853 853 if filereadable(a:messageFile)
854 854 let oldCwd=getcwd()
855 855 if strlen(a:targetDir) > 0
856 856 execute 'cd' escape(a:targetDir, ' ')
857 857 endif
858 858 let resultBuffer=<SID>HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
859 859 execute 'cd' escape(oldCwd, ' ')
860 860 execute 'bw' escape(a:messageFile, ' *?\')
861 861 silent execute 'call delete("' . a:messageFile . '")'
862 862 return <SID>HGMarkOrigBufferForSetup(resultBuffer)
863 863 else
864 864 echoerr "Can't read message file; no commit is possible."
865 865 return -1
866 866 endif
867 867 endfunction
868 868
869 869 " Function: s:HGLog() {{{2
870 870 function! s:HGLog(...)
871 871 if a:0 == 0
872 872 let versionOption = ""
873 873 let caption = ''
874 874 else
875 875 let versionOption=" -r" . a:1
876 876 let caption = a:1
877 877 endif
878 878
879 879 let resultBuffer=<SID>HGDoCommand('log' . versionOption, 'hglog', caption)
880 880 if resultBuffer != ""
881 881 set filetype=rcslog
882 882 endif
883 883 return resultBuffer
884 884 endfunction
885 885
886 886 " Function: s:HGRevert() {{{2
887 887 function! s:HGRevert()
888 888 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('revert', 'hgrevert', ''))
889 889 endfunction
890 890
891 891 " Function: s:HGReview(...) {{{2
892 892 function! s:HGReview(...)
893 893 if a:0 == 0
894 894 let versiontag=""
895 895 if <SID>HGGetOption('HGCommandInteractive', 0)
896 896 let versiontag=input('Revision: ')
897 897 endif
898 898 if versiontag == ""
899 899 let versiontag="(current)"
900 900 let versionOption=""
901 901 else
902 902 let versionOption=" -r " . versiontag . " "
903 903 endif
904 904 else
905 905 let versiontag=a:1
906 906 let versionOption=" -r " . versiontag . " "
907 907 endif
908 908
909 909 let resultBuffer = <SID>HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
910 910 if resultBuffer > 0
911 911 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
912 912 endif
913 913
914 914 return resultBuffer
915 915 endfunction
916 916
917 917 " Function: s:HGStatus() {{{2
918 918 function! s:HGStatus()
919 919 return <SID>HGDoCommand('status', 'hgstatus', '')
920 920 endfunction
921 921
922 922
923 923 " Function: s:HGUpdate() {{{2
924 924 function! s:HGUpdate()
925 925 return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('update', 'update', ''))
926 926 endfunction
927 927
928 928 " Function: s:HGVimDiff(...) {{{2
929 929 function! s:HGVimDiff(...)
930 930 let originalBuffer = <SID>HGCurrentBufferCheck()
931 931 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
932 932 try
933 933 " If there's already a VimDiff'ed window, restore it.
934 934 " There may only be one HGVimDiff original window at a time.
935 935
936 936 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
937 937 " Clear the existing vimdiff setup by removing the result buffers.
938 938 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
939 939 endif
940 940
941 941 " Split and diff
942 942 if(a:0 == 2)
943 943 " Reset the vimdiff system, as 2 explicit versions were provided.
944 944 if exists('s:vimDiffSourceBuffer')
945 945 call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
946 946 endif
947 947 let resultBuffer = <SID>HGReview(a:1)
948 948 if resultBuffer < 0
949 949 echomsg "Can't open HG revision " . a:1
950 950 return resultBuffer
951 951 endif
952 952 let b:HGCommand = 'vimdiff'
953 953 diffthis
954 954 let s:vimDiffBufferCount = 1
955 955 let s:vimDiffScratchList = '{'. resultBuffer . '}'
956 956 " If no split method is defined, cheat, and set it to vertical.
957 957 try
958 958 call <SID>HGOverrideOption('HGCommandSplit', <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
959 959 let resultBuffer=<SID>HGReview(a:2)
960 960 finally
961 961 call <SID>HGOverrideOption('HGCommandSplit')
962 962 endtry
963 963 if resultBuffer < 0
964 964 echomsg "Can't open HG revision " . a:1
965 965 return resultBuffer
966 966 endif
967 967 let b:HGCommand = 'vimdiff'
968 968 diffthis
969 969 let s:vimDiffBufferCount = 2
970 970 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
971 971 else
972 972 " Add new buffer
973 973 try
974 974 " Force splitting behavior, otherwise why use vimdiff?
975 975 call <SID>HGOverrideOption("HGCommandEdit", "split")
976 976 call <SID>HGOverrideOption("HGCommandSplit", <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
977 977 if(a:0 == 0)
978 978 let resultBuffer=<SID>HGReview()
979 979 else
980 980 let resultBuffer=<SID>HGReview(a:1)
981 981 endif
982 982 finally
983 983 call <SID>HGOverrideOption("HGCommandEdit")
984 984 call <SID>HGOverrideOption("HGCommandSplit")
985 985 endtry
986 986 if resultBuffer < 0
987 987 echomsg "Can't open current HG revision"
988 988 return resultBuffer
989 989 endif
990 990 let b:HGCommand = 'vimdiff'
991 991 diffthis
992 992
993 993 if !exists('s:vimDiffBufferCount')
994 994 " New instance of vimdiff.
995 995 let s:vimDiffBufferCount = 2
996 996 let s:vimDiffScratchList = '{' . resultBuffer . '}'
997 997
998 998 " This could have been invoked on a HG result buffer, not the
999 999 " original buffer.
1000 1000 wincmd W
1001 1001 execute 'buffer' originalBuffer
1002 1002 " Store info for later original buffer restore
1003 1003 let s:vimDiffRestoreCmd =
1004 1004 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
1005 1005 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
1006 1006 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
1007 1007 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
1008 1008 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
1009 1009 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
1010 1010 \ . "|if &foldmethod=='manual'|execute 'normal! zE'|endif"
1011 1011 diffthis
1012 1012 wincmd w
1013 1013 else
1014 1014 " Adding a window to an existing vimdiff
1015 1015 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
1016 1016 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
1017 1017 endif
1018 1018 endif
1019 1019
1020 1020 let s:vimDiffSourceBuffer = originalBuffer
1021 1021
1022 1022 " Avoid executing the modeline in the current buffer after the autocommand.
1023 1023
1024 1024 let currentBuffer = bufnr('%')
1025 1025 let saveModeline = getbufvar(currentBuffer, '&modeline')
1026 1026 try
1027 1027 call setbufvar(currentBuffer, '&modeline', 0)
1028 1028 silent do HGCommand User HGVimDiffFinish
1029 1029 finally
1030 1030 call setbufvar(currentBuffer, '&modeline', saveModeline)
1031 1031 endtry
1032 1032 return resultBuffer
1033 1033 finally
1034 1034 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1035 1035 endtry
1036 1036 endfunction
1037 1037
1038 1038 " Section: Command definitions {{{1
1039 1039 " Section: Primary commands {{{2
1040 1040 com! HGAdd call <SID>HGAdd()
1041 1041 com! -nargs=? HGAnnotate call <SID>HGAnnotate(<f-args>)
1042 1042 com! -bang -nargs=? HGCommit call <SID>HGCommit(<q-bang>, <q-args>)
1043 1043 com! -nargs=* HGDiff call <SID>HGDiff(<f-args>)
1044 1044 com! -bang HGGotoOriginal call <SID>HGGotoOriginal(<q-bang>)
1045 1045 com! -nargs=? HGLog call <SID>HGLog(<f-args>)
1046 1046 com! HGRevert call <SID>HGRevert()
1047 1047 com! -nargs=? HGReview call <SID>HGReview(<f-args>)
1048 1048 com! HGStatus call <SID>HGStatus()
1049 1049 com! HGUpdate call <SID>HGUpdate()
1050 1050 com! -nargs=* HGVimDiff call <SID>HGVimDiff(<f-args>)
1051 1051
1052 1052 " Section: HG buffer management commands {{{2
1053 1053 com! HGDisableBufferSetup call HGDisableBufferSetup()
1054 1054 com! HGEnableBufferSetup call HGEnableBufferSetup()
1055 1055
1056 1056 " Allow reloading hgcommand.vim
1057 1057 com! HGReload unlet! g:loaded_hgcommand | runtime plugin/hgcommand.vim
1058 1058
1059 1059 " Section: Plugin command mappings {{{1
1060 1060 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
1061 1061 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
1062 1062 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
1063 1063 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
1064 1064 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
1065 1065 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
1066 1066 nnoremap <silent> <Plug>HGLog :HGLog<CR>
1067 1067 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
1068 1068 nnoremap <silent> <Plug>HGReview :HGReview<CR>
1069 1069 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
1070 1070 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
1071 1071 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
1072 1072
1073 1073 " Section: Default mappings {{{1
1074 1074 if !hasmapto('<Plug>HGAdd')
1075 1075 nmap <unique> <Leader>hga <Plug>HGAdd
1076 1076 endif
1077 1077 if !hasmapto('<Plug>HGAnnotate')
1078 1078 nmap <unique> <Leader>hgn <Plug>HGAnnotate
1079 1079 endif
1080 1080 if !hasmapto('<Plug>HGClearAndGotoOriginal')
1081 1081 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
1082 1082 endif
1083 1083 if !hasmapto('<Plug>HGCommit')
1084 1084 nmap <unique> <Leader>hgc <Plug>HGCommit
1085 1085 endif
1086 1086 if !hasmapto('<Plug>HGDiff')
1087 1087 nmap <unique> <Leader>hgd <Plug>HGDiff
1088 1088 endif
1089 1089 if !hasmapto('<Plug>HGGotoOriginal')
1090 1090 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
1091 1091 endif
1092 1092 if !hasmapto('<Plug>HGLog')
1093 1093 nmap <unique> <Leader>hgl <Plug>HGLog
1094 1094 endif
1095 1095 if !hasmapto('<Plug>HGRevert')
1096 1096 nmap <unique> <Leader>hgq <Plug>HGRevert
1097 1097 endif
1098 1098 if !hasmapto('<Plug>HGReview')
1099 1099 nmap <unique> <Leader>hgr <Plug>HGReview
1100 1100 endif
1101 1101 if !hasmapto('<Plug>HGStatus')
1102 1102 nmap <unique> <Leader>hgs <Plug>HGStatus
1103 1103 endif
1104 1104 if !hasmapto('<Plug>HGUpdate')
1105 1105 nmap <unique> <Leader>hgu <Plug>HGUpdate
1106 1106 endif
1107 1107 if !hasmapto('<Plug>HGVimDiff')
1108 1108 nmap <unique> <Leader>hgv <Plug>HGVimDiff
1109 1109 endif
1110 1110
1111 1111 " Section: Menu items {{{1
1112 1112 silent! aunmenu Plugin.HG
1113 1113 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
1114 1114 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
1115 1115 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
1116 1116 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
1117 1117 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
1118 1118 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
1119 1119 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
1120 1120 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
1121 1121 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
1122 1122 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
1123 1123
1124 1124 " Section: Autocommands to restore vimdiff state {{{1
1125 1125 function! s:HGVimDiffRestore(vimDiffBuff)
1126 1126 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1127 1127 try
1128 1128 if exists("s:vimDiffSourceBuffer")
1129 1129 if a:vimDiffBuff == s:vimDiffSourceBuffer
1130 1130 " Original file is being removed.
1131 1131 unlet! s:vimDiffSourceBuffer
1132 1132 unlet! s:vimDiffBufferCount
1133 1133 unlet! s:vimDiffRestoreCmd
1134 1134 unlet! s:vimDiffScratchList
1135 1135 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
1136 1136 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
1137 1137 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
1138 1138 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
1139 1139 " All scratch buffers are gone, reset the original.
1140 1140 " Only restore if the source buffer is still in Diff mode
1141 1141
1142 1142 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
1143 1143 if sourceWinNR != -1
1144 1144 " The buffer is visible in at least one window
1145 1145 let currentWinNR = winnr()
1146 1146 while winbufnr(sourceWinNR) != -1
1147 1147 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
1148 1148 execute sourceWinNR . 'wincmd w'
1149 1149 if getwinvar('', "&diff")
1150 1150 execute s:vimDiffRestoreCmd
1151 1151 endif
1152 1152 endif
1153 1153 let sourceWinNR = sourceWinNR + 1
1154 1154 endwhile
1155 1155 execute currentWinNR . 'wincmd w'
1156 1156 else
1157 1157 " The buffer is hidden. It must be visible in order to set the
1158 1158 " diff option.
1159 1159 let currentBufNR = bufnr('')
1160 1160 execute "hide buffer" s:vimDiffSourceBuffer
1161 1161 if getwinvar('', "&diff")
1162 1162 execute s:vimDiffRestoreCmd
1163 1163 endif
1164 1164 execute "hide buffer" currentBufNR
1165 1165 endif
1166 1166
1167 1167 unlet s:vimDiffRestoreCmd
1168 1168 unlet s:vimDiffSourceBuffer
1169 1169 unlet s:vimDiffBufferCount
1170 1170 unlet s:vimDiffScratchList
1171 1171 elseif s:vimDiffBufferCount == 0
1172 1172 " All buffers are gone.
1173 1173 unlet s:vimDiffSourceBuffer
1174 1174 unlet s:vimDiffBufferCount
1175 1175 unlet s:vimDiffScratchList
1176 1176 endif
1177 1177 endif
1178 1178 endif
1179 1179 finally
1180 1180 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1181 1181 endtry
1182 1182 endfunction
1183 1183
1184 1184 augroup HGVimDiffRestore
1185 1185 au!
1186 1186 au BufUnload * call <SID>HGVimDiffRestore(expand("<abuf>"))
1187 1187 augroup END
1188 1188
1189 1189 " Section: Optional activation of buffer management {{{1
1190 1190
1191 1191 if s:HGGetOption('HGCommandEnableBufferSetup', 1)
1192 1192 call HGEnableBufferSetup()
1193 1193 endif
1194 1194
1195 1195 " Section: Doc installation {{{1
1196 1196
1197 1197 if <SID>HGInstallDocumentation(expand("<sfile>:p"))
1198 1198 echomsg s:script_name s:script_version . ": updated documentation"
1199 1199 endif
1200 1200
1201 1201 " Section: Plugin completion {{{1
1202 1202
1203 1203 " delete one-time vars and functions
1204 1204 delfunction <SID>HGInstallDocumentation
1205 1205 delfunction <SID>HGFlexiMkdir
1206 1206 delfunction <SID>HGCleanupOnFailure
1207 1207 unlet s:script_version s:script_name
1208 1208
1209 1209 let g:loaded_hgcommand=2
1210 1210 silent do HGCommand User HGPluginFinish
1211 1211
1212 1212 let &cpo = s:save_cpo
1213 1213 unlet s:save_cpo
1214 1214 " vim:se expandtab sts=2 sw=2:
1215 1215 finish
1216 1216
1217 1217 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1218 1218 " Section: Documentation content {{{1
1219 1219 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1220 1220 === START_DOC
1221 1221 *hgcommand.txt* Mercurial vim integration #version#
1222 1222
1223 1223
1224 1224 HGCOMMAND REFERENCE MANUAL~
1225 1225
1226 1226
1227 1227 Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
1228 1228 Credits: Bob Hiestand <bob.hiestand@gmail.com>
1229 1229 Mercurial: http://mercurial.selenic.com/
1230 1230 Mercurial (noted Hg) is a fast, lightweight Source Control Management
1231 1231 system designed for efficient handling of very large distributed projects.
1232 1232
1233 1233 ==============================================================================
1234 1234 1. Contents *hgcommand-contents*
1235 1235
1236 1236 Installation : |hgcommand-install|
1237 1237 HGCommand Intro : |hgcommand|
1238 1238 HGCommand Manual : |hgcommand-manual|
1239 1239 Customization : |hgcommand-customize|
1240 1240 Bugs : |hgcommand-bugs|
1241 1241
1242 1242 ==============================================================================
1243 1243 2. HGCommand Installation *hgcommand-install*
1244 1244
1245 1245 In order to install the plugin, place the hgcommand.vim file into a plugin'
1246 1246 directory in your runtime path (please see |add-global-plugin| and
1247 1247 |'runtimepath'|.
1248 1248
1249 1249 HGCommand may be customized by setting variables, creating maps, and
1250 1250 specifying event handlers. Please see |hgcommand-customize| for more
1251 1251 details.
1252 1252
1253 1253 *hgcommand-auto-help*
1254 1254 The help file is automagically generated when the |hgcommand| script is
1255 1255 loaded for the first time.
1256 1256
1257 1257 ==============================================================================
1258 1258
1259 1259 3. HGCommand Intro *hgcommand*
1260 1260 *hgcommand-intro*
1261 1261
1262 1262 The HGCommand plugin provides global ex commands for manipulating
1263 1263 HG-controlled source files. In general, each command operates on the
1264 1264 current buffer and accomplishes a separate hg function, such as update,
1265 1265 commit, log, and others (please see |hgcommand-commands| for a list of all
1266 1266 available commands). The results of each operation are displayed in a
1267 1267 scratch buffer. Several buffer variables are defined for those scratch
1268 1268 buffers (please see |hgcommand-buffer-variables|).
1269 1269
1270 1270 The notion of "current file" means either the current buffer, or, in the
1271 1271 case of a directory buffer, the file on the current line within the buffer.
1272 1272
1273 1273 For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
1274 1274 as though it was invoked on the original file and splits the screen so that
1275 1275 the output appears in a new window.
1276 1276
1277 1277 Many of the commands accept revisions as arguments. By default, most
1278 1278 operate on the most recent revision on the current branch if no revision is
1279 1279 specified (though see |HGCommandInteractive| to prompt instead).
1280 1280
1281 1281 Each HGCommand is mapped to a key sequence starting with the <Leader>
1282 1282 keystroke. The default mappings may be overridden by supplying different
1283 1283 mappings before the plugin is loaded, such as in the vimrc, in the standard
1284 1284 fashion for plugin mappings. For examples, please see
1285 1285 |hgcommand-mappings-override|.
1286 1286
1287 1287 The HGCommand plugin may be configured in several ways. For more details,
1288 1288 please see |hgcommand-customize|.
1289 1289
1290 1290 ==============================================================================
1291 1291 4. HGCommand Manual *hgcommand-manual*
1292 1292
1293 1293 4.1 HGCommand commands *hgcommand-commands*
1294 1294
1295 1295 HGCommand defines the following commands:
1296 1296
1297 1297 |:HGAdd|
1298 1298 |:HGAnnotate|
1299 1299 |:HGCommit|
1300 1300 |:HGDiff|
1301 1301 |:HGGotoOriginal|
1302 1302 |:HGLog|
1303 1303 |:HGRevert|
1304 1304 |:HGReview|
1305 1305 |:HGStatus|
1306 1306 |:HGUpdate|
1307 1307 |:HGVimDiff|
1308 1308
1309 1309 :HGAdd *:HGAdd*
1310 1310
1311 1311 This command performs "hg add" on the current file. Please note, this does
1312 1312 not commit the newly-added file.
1313 1313
1314 1314 :HGAnnotate *:HGAnnotate*
1315 1315
1316 1316 This command performs "hg annotate" on the current file. If an argument is
1317 1317 given, the argument is used as a revision number to display. If not given
1318 1318 an argument, it uses the most recent version of the file on the current
1319 1319 branch. Additionally, if the current buffer is a HGAnnotate buffer
1320 1320 already, the version number on the current line is used.
1321 1321
1322 1322 If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
1323 1323 version previous to the one on the current line is used instead. This
1324 1324 allows one to navigate back to examine the previous version of a line.
1325 1325
1326 1326 The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
1327 1327 take advantage of the bundled syntax file.
1328 1328
1329 1329
1330 1330 :HGCommit[!] *:HGCommit*
1331 1331
1332 1332 If called with arguments, this performs "hg commit" using the arguments as
1333 1333 the log message.
1334 1334
1335 1335 If '!' is used with no arguments, an empty log message is committed.
1336 1336
1337 1337 If called with no arguments, this is a two-step command. The first step
1338 1338 opens a buffer to accept a log message. When that buffer is written, it is
1339 1339 automatically closed and the file is committed using the information from
1340 1340 that log message. The commit can be abandoned if the log message buffer is
1341 1341 deleted or wiped before being written.
1342 1342
1343 1343 Alternatively, the mapping that is used to invoke :HGCommit (by default
1344 1344 <Leader>hgc) can be used in the log message buffer to immediately commit.
1345 1345 This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
1346 1346 disable the normal commit-on-write behavior.
1347 1347
1348 1348 :HGDiff *:HGDiff*
1349 1349
1350 1350 With no arguments, this performs "hg diff" on the current file against the
1351 1351 current repository version.
1352 1352
1353 1353 With one argument, "hg diff" is performed on the current file against the
1354 1354 specified revision.
1355 1355
1356 1356 With two arguments, hg diff is performed between the specified revisions of
1357 1357 the current file.
1358 1358
1359 1359 This command uses the 'HGCommandDiffOpt' variable to specify diff options.
1360 1360 If that variable does not exist, then 'wbBc' is assumed. If you wish to
1361 1361 have no options, then set it to the empty string.
1362 1362
1363 1363
1364 1364 :HGGotoOriginal *:HGGotoOriginal*
1365 1365
1366 1366 This command returns the current window to the source buffer, if the
1367 1367 current buffer is a HG command output buffer.
1368 1368
1369 1369 :HGGotoOriginal!
1370 1370
1371 1371 Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
1372 1372 output buffers for the source buffer.
1373 1373
1374 1374 :HGLog *:HGLog*
1375 1375
1376 1376 Performs "hg log" on the current file.
1377 1377
1378 1378 If an argument is given, it is passed as an argument to the "-r" option of
1379 1379 "hg log".
1380 1380
1381 1381 :HGRevert *:HGRevert*
1382 1382
1383 1383 Replaces the current file with the most recent version from the repository
1384 1384 in order to wipe out any undesired changes.
1385 1385
1386 1386 :HGReview *:HGReview*
1387 1387
1388 1388 Retrieves a particular version of the current file. If no argument is
1389 1389 given, the most recent version of the file on the current branch is
1390 1390 retrieved. Otherwise, the specified version is retrieved.
1391 1391
1392 1392 :HGStatus *:HGStatus*
1393 1393
1394 1394 Performs "hg status" on the current file.
1395 1395
1396 1396 :HGUpdate *:HGUpdate*
1397 1397
1398 1398 Performs "hg update" on the current file. This intentionally does not
1399 1399 automatically reload the current buffer, though vim should prompt the user
1400 1400 to do so if the underlying file is altered by this command.
1401 1401
1402 1402 :HGVimDiff *:HGVimDiff*
1403 1403
1404 1404 With no arguments, this prompts the user for a revision and then uses
1405 1405 vimdiff to display the differences between the current file and the
1406 1406 specified revision. If no revision is specified, the most recent version
1407 1407 of the file on the current branch is used.
1408 1408
1409 1409 With one argument, that argument is used as the revision as above. With
1410 1410 two arguments, the differences between the two revisions is displayed using
1411 1411 vimdiff.
1412 1412
1413 1413 With either zero or one argument, the original buffer is used to perform
1414 1414 the vimdiff. When the other buffer is closed, the original buffer will be
1415 1415 returned to normal mode.
1416 1416
1417 1417 Once vimdiff mode is started using the above methods, additional vimdiff
1418 1418 buffers may be added by passing a single version argument to the command.
1419 1419 There may be up to 4 vimdiff buffers total.
1420 1420
1421 1421 Using the 2-argument form of the command resets the vimdiff to only those 2
1422 1422 versions. Additionally, invoking the command on a different file will
1423 1423 close the previous vimdiff buffers.
1424 1424
1425 1425
1426 1426 4.2 Mappings *hgcommand-mappings*
1427 1427
1428 1428 By default, a mapping is defined for each command. These mappings execute
1429 1429 the default (no-argument) form of each command.
1430 1430
1431 1431 <Leader>hga HGAdd
1432 1432 <Leader>hgn HGAnnotate
1433 1433 <Leader>hgc HGCommit
1434 1434 <Leader>hgd HGDiff
1435 1435 <Leader>hgg HGGotoOriginal
1436 1436 <Leader>hgG HGGotoOriginal!
1437 1437 <Leader>hgl HGLog
1438 1438 <Leader>hgr HGReview
1439 1439 <Leader>hgs HGStatus
1440 1440 <Leader>hgu HGUpdate
1441 1441 <Leader>hgv HGVimDiff
1442 1442
1443 1443 *hgcommand-mappings-override*
1444 1444
1445 1445 The default mappings can be overridden by user-provided instead by mapping
1446 1446 to <Plug>CommandName. This is especially useful when these mappings
1447 1447 collide with other existing mappings (vim will warn of this during plugin
1448 1448 initialization, but will not clobber the existing mappings).
1449 1449
1450 1450 For instance, to override the default mapping for :HGAdd to set it to
1451 1451 '\add', add the following to the vimrc: >
1452 1452
1453 1453 nmap \add <Plug>HGAdd
1454 1454 <
1455 1455 4.3 Automatic buffer variables *hgcommand-buffer-variables*
1456 1456
1457 1457 Several buffer variables are defined in each HGCommand result buffer.
1458 1458 These may be useful for additional customization in callbacks defined in
1459 1459 the event handlers (please see |hgcommand-events|).
1460 1460
1461 1461 The following variables are automatically defined:
1462 1462
1463 1463 b:hgOrigBuffNR *b:hgOrigBuffNR*
1464 1464
1465 1465 This variable is set to the buffer number of the source file.
1466 1466
1467 1467 b:hgcmd *b:hgcmd*
1468 1468
1469 1469 This variable is set to the name of the hg command that created the result
1470 1470 buffer.
1471 1471 ==============================================================================
1472 1472
1473 1473 5. Configuration and customization *hgcommand-customize*
1474 1474 *hgcommand-config*
1475 1475
1476 1476 The HGCommand plugin can be configured in two ways: by setting
1477 1477 configuration variables (see |hgcommand-options|) or by defining HGCommand
1478 1478 event handlers (see |hgcommand-events|). Additionally, the HGCommand
1479 1479 plugin provides several option for naming the HG result buffers (see
1480 1480 |hgcommand-naming|) and supported a customized status line (see
1481 1481 |hgcommand-statusline| and |hgcommand-buffer-management|).
1482 1482
1483 1483 5.1 HGCommand configuration variables *hgcommand-options*
1484 1484
1485 1485 Several variables affect the plugin's behavior. These variables are
1486 1486 checked at time of execution, and may be defined at the window, buffer, or
1487 1487 global level and are checked in that order of precedence.
1488 1488
1489 1489
1490 1490 The following variables are available:
1491 1491
1492 1492 |HGCommandAnnotateParent|
1493 1493 |HGCommandCommitOnWrite|
1494 1494 |HGCommandHGExec|
1495 1495 |HGCommandDeleteOnHide|
1496 1496 |HGCommandDiffOpt|
1497 1497 |HGCommandDiffSplit|
1498 1498 |HGCommandEdit|
1499 1499 |HGCommandEnableBufferSetup|
1500 1500 |HGCommandInteractive|
1501 1501 |HGCommandNameMarker|
1502 1502 |HGCommandNameResultBuffers|
1503 1503 |HGCommandSplit|
1504 1504
1505 1505 HGCommandAnnotateParent *HGCommandAnnotateParent*
1506 1506
1507 1507 This variable, if set to a non-zero value, causes the zero-argument form of
1508 1508 HGAnnotate when invoked on a HGAnnotate buffer to go to the version
1509 1509 previous to that displayed on the current line. If not set, it defaults to
1510 1510 0.
1511 1511
1512 1512 HGCommandCommitOnWrite *HGCommandCommitOnWrite*
1513 1513
1514 1514 This variable, if set to a non-zero value, causes the pending hg commit to
1515 1515 take place immediately as soon as the log message buffer is written. If
1516 1516 set to zero, only the HGCommit mapping will cause the pending commit to
1517 1517 occur. If not set, it defaults to 1.
1518 1518
1519 1519 HGCommandHGExec *HGCommandHGExec*
1520 1520
1521 1521 This variable controls the executable used for all HG commands. If not
1522 1522 set, it defaults to "hg".
1523 1523
1524 1524 HGCommandDeleteOnHide *HGCommandDeleteOnHide*
1525 1525
1526 1526 This variable, if set to a non-zero value, causes the temporary HG result
1527 1527 buffers to automatically delete themselves when hidden.
1528 1528
1529 1529 HGCommandDiffOpt *HGCommandDiffOpt*
1530 1530
1531 1531 This variable, if set, determines the options passed to the diff command of
1532 1532 HG. If not set, it defaults to 'w'.
1533 1533
1534 1534 HGCommandDiffSplit *HGCommandDiffSplit*
1535 1535
1536 1536 This variable overrides the |HGCommandSplit| variable, but only for buffers
1537 1537 created with |:HGVimDiff|.
1538 1538
1539 1539 HGCommandEdit *HGCommandEdit*
1540 1540
1541 1541 This variable controls whether the original buffer is replaced ('edit') or
1542 1542 split ('split'). If not set, it defaults to 'edit'.
1543 1543
1544 1544 HGCommandEnableBufferSetup *HGCommandEnableBufferSetup*
1545 1545
1546 1546 This variable, if set to a non-zero value, activates HG buffer management
1547 1547 mode see (|hgcommand-buffer-management|). This mode means that three
1548 1548 buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if
1549 1549 the file is HG-controlled. This is useful for displaying version
1550 1550 information in the status bar.
1551 1551
1552 1552 HGCommandInteractive *HGCommandInteractive*
1553 1553
1554 1554 This variable, if set to a non-zero value, causes appropriate commands (for
1555 1555 the moment, only |:HGReview|) to query the user for a revision to use
1556 1556 instead of the current revision if none is specified.
1557 1557
1558 1558 HGCommandNameMarker *HGCommandNameMarker*
1559 1559
1560 1560 This variable, if set, configures the special attention-getting characters
1561 1561 that appear on either side of the hg buffer type in the buffer name. This
1562 1562 has no effect unless |HGCommandNameResultBuffers| is set to a true value.
1563 1563 If not set, it defaults to '_'.
1564 1564
1565 1565 HGCommandNameResultBuffers *HGCommandNameResultBuffers*
1566 1566
1567 1567 This variable, if set to a true value, causes the hg result buffers to be
1568 1568 named in the old way ('<source file name> _<hg command>_'). If not set or
1569 1569 set to a false value, the result buffer is nameless.
1570 1570
1571 1571 HGCommandSplit *HGCommandSplit*
1572 1572
1573 1573 This variable controls the orientation of the various window splits that
1574 1574 may occur (such as with HGVimDiff, when using a HG command on a HG command
1575 1575 buffer, or when the |HGCommandEdit| variable is set to 'split'. If set to
1576 1576 'horizontal', the resulting windows will be on stacked on top of one
1577 1577 another. If set to 'vertical', the resulting windows will be side-by-side.
1578 1578 If not set, it defaults to 'horizontal' for all but HGVimDiff windows.
1579 1579
1580 1580 5.2 HGCommand events *hgcommand-events*
1581 1581
1582 1582 For additional customization, HGCommand can trigger user-defined events.
1583 1583 Event handlers are provided by defining User event autocommands (see
1584 1584 |autocommand|, |User|) in the HGCommand group with patterns matching the
1585 1585 event name.
1586 1586
1587 1587 For instance, the following could be added to the vimrc to provide a 'q'
1588 1588 mapping to quit a HGCommand scratch buffer: >
1589 1589
1590 1590 augroup HGCommand
1591 1591 au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q:
1592 1592 bwipeout<cr>
1593 1593 augroup END
1594 1594 <
1595 1595
1596 1596 The following hooks are available:
1597 1597
1598 1598 HGBufferCreated This event is fired just after a hg command result
1599 1599 buffer is created and filled with the result of a hg
1600 1600 command. It is executed within the context of the HG
1601 1601 command buffer. The HGCommand buffer variables may be
1602 1602 useful for handlers of this event (please see
1603 1603 |hgcommand-buffer-variables|).
1604 1604
1605 1605 HGBufferSetup This event is fired just after HG buffer setup occurs,
1606 1606 if enabled.
1607 1607
1608 1608 HGPluginInit This event is fired when the HGCommand plugin first
1609 1609 loads.
1610 1610
1611 1611 HGPluginFinish This event is fired just after the HGCommand plugin
1612 1612 loads.
1613 1613
1614 1614 HGVimDiffFinish This event is fired just after the HGVimDiff command
1615 1615 executes to allow customization of, for instance,
1616 1616 window placement and focus.
1617 1617
1618 1618 5.3 HGCommand buffer naming *hgcommand-naming*
1619 1619
1620 1620 By default, the buffers containing the result of HG commands are nameless
1621 1621 scratch buffers. It is intended that buffer variables of those buffers be
1622 1622 used to customize the statusline option so that the user may fully control
1623 1623 the display of result buffers.
1624 1624
1625 1625 If the old-style naming is desired, please enable the
1626 1626 |HGCommandNameResultBuffers| variable. Then, each result buffer will
1627 1627 receive a unique name that includes the source file name, the HG command,
1628 1628 and any extra data (such as revision numbers) that were part of the
1629 1629 command.
1630 1630
1631 1631 5.4 HGCommand status line support *hgcommand-statusline*
1632 1632
1633 1633 It is intended that the user will customize the |'statusline'| option to
1634 1634 include HG result buffer attributes. A sample function that may be used in
1635 1635 the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In
1636 1636 order to use that function in the status line, do something like the
1637 1637 following: >
1638 1638
1639 1639 set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
1640 1640 <
1641 1641 of which %{HGGetStatusLine()} is the relevant portion.
1642 1642
1643 1643 The sample HGGetStatusLine() function handles both HG result buffers and
1644 1644 HG-managed files if HGCommand buffer management is enabled (please see
1645 1645 |hgcommand-buffer-management|).
1646 1646
1647 1647 5.5 HGCommand buffer management *hgcommand-buffer-management*
1648 1648
1649 1649 The HGCommand plugin can operate in buffer management mode, which means
1650 1650 that it attempts to set two buffer variables ('HGRevision' and 'HGBranch')
1651 1651 upon entry into a buffer. This is rather slow because it means that 'hg
1652 1652 status' will be invoked at each entry into a buffer (during the |BufEnter|
1653 1653 autocommand).
1654 1654
1655 1655 This mode is enabled by default. In order to disable it, set the
1656 1656 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
1657 1657 this mode simply provides the buffer variables mentioned above. The user
1658 1658 must explicitly include those in the |'statusline'| option if they are to
1659 1659 appear in the status line (but see |hgcommand-statusline| for a simple way
1660 1660 to do that).
1661 1661
1662 1662 ==============================================================================
1663 1663 9. Tips *hgcommand-tips*
1664 1664
1665 1665 9.1 Split window annotation, by Michael Anderson >
1666 1666
1667 1667 :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR>
1668 1668 \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>
1669 1669 \:set nowrap<CR>
1670 1670 <
1671 1671
1672 1672 This splits the buffer vertically, puts an annotation on the left (minus
1673 1673 the header) with the width set to 40. An editable/normal copy is placed on
1674 1674 the right. The two versions are scroll locked so they move as one. and
1675 1675 wrapping is turned off so that the lines line up correctly. The advantages
1676 1676 are...
1677 1677
1678 1678 1) You get a versioning on the right.
1679 1679 2) You can still edit your own code.
1680 1680 3) Your own code still has syntax highlighting.
1681 1681
1682 1682 ==============================================================================
1683 1683
1684 1684 8. Known bugs *hgcommand-bugs*
1685 1685
1686 1686 Please let me know if you run across any.
1687 1687
1688 1688 HGVimDiff, when using the original (real) source buffer as one of the diff
1689 1689 buffers, uses some hacks to try to restore the state of the original buffer
1690 1690 when the scratch buffer containing the other version is destroyed. There
1691 1691 may still be bugs in here, depending on many configuration details.
1692 1692
1693 1693 ==============================================================================
1694 1694
1695 1695 9. TODO *hgcommand-todo*
1696 1696
1697 1697 Integrate symlink tracking once HG will support them.
1698 1698 ==============================================================================
1699 1699 === END_DOC
1700 1700 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1701 1701 " v im:tw=78:ts=8:ft=help:norl:
1702 1702 " vim600: set foldmethod=marker tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab :
1703 1703 "fileencoding=iso-8859-15
@@ -1,51 +1,51
1 1 <Include>
2 2 <!-- These are component GUIDs used for Mercurial installers.
3 3 YOU MUST CHANGE ALL GUIDs below when copying this file
4 4 and replace 'Mercurial' in this notice with the name of
5 5 your project. Component GUIDs have global namespace! -->
6 6
7 7 <!-- contrib.wxs -->
8 8 <?define contrib.guid = {F17D27B7-4A6B-4cd2-AE72-FED3CFAA585E} ?>
9 9 <?define contrib.vim.guid = {BB04903A-652D-4C4F-9590-2BD07A2304F2} ?>
10 10
11 11 <!-- dist.wxs -->
12 12 <?define dist.guid = {C3B634A4-1B05-4A40-94A9-38EE853CF693} ?>
13 13
14 14 <!-- doc.wxs -->
15 15 <?define doc.hg.1.html.guid = {AAAA3FDA-EDC5-4220-B59D-D342722358A2} ?>
16 16 <?define doc.hgignore.5.html.guid = {AA9118C4-F3A0-4429-A5F4-5A1906B2D67F} ?>
17 17 <?define doc.hgrc.5.html = {E0CEA1EB-FA01-408c-844B-EE5965165BAE} ?>
18 18 <?define doc.style.css = {172F8262-98E0-4711-BD39-4DAE0D77EF05} ?>
19 19
20 20 <!-- help.wxs -->
21 21 <?define helpFolder.guid = {9FA957DB-6DFE-44f2-AD03-293B2791CF17} ?>
22
22
23 23 <!-- i18n.wxs -->
24 24 <?define i18nFolder.guid = {1BF8026D-CF7C-4174-AEE6-D6B7BF119248} ?>
25 25
26 26 <!-- templates.wxs -->
27 27 <?define templates.root.guid = {8DF97574-33E9-412F-8414-65B48BB18783} ?>
28 28 <?define templates.atom.guid = {AB5D2908-BC95-44BE-9D79-069EF43D93E2} ?>
29 29 <?define templates.coal.guid = {B63CCAAB-4EAF-43b4-901E-4BD13F5B78FC} ?>
30 30 <?define templates.gitweb.guid = {827334AF-1EFD-421B-962C-5660A068F612} ?>
31 31 <?define templates.monoblue.guid = {8060A1E4-BD4C-453E-92CB-9536DC44A9E3} ?>
32 32 <?define templates.paper.guid = {61AB1DE9-645F-46ED-8AF8-0CF02267FFBB} ?>
33 33 <?define templates.raw.guid = {3F88E9B6-EA3C-41EB-8D8A-3F12E7DE9933} ?>
34 34 <?define templates.rss.guid = {36069748-1E2A-472B-A212-506CB656A9C1} ?>
35 35 <?define templates.spartan.guid = {80222625-FA8F-44b1-86CE-1781EF375D09} ?>
36 36 <?define templates.static.guid = {B27D7311-050A-4A96-9971-B674A0EA21D0} ?>
37 37
38 38 <!-- mercurial.wxs -->
39 39 <?define ProductUpgradeCode = {A1CC6134-E945-4399-BE36-EB0017FDF7CF} ?>
40 40
41 41 <?define ComponentMainExecutableGUID = {D102B8FA-059B-4ACC-9FA3-8C78C3B58EEF} ?>
42 42
43 43 <?define ReadMe.guid = {56A8E372-991D-4DCA-B91D-93D775974CF5} ?>
44 44 <?define COPYING.guid = {B7801DBA-1C49-4BF4-91AD-33C65F5C7895} ?>
45 45 <?define mercurial.rc.guid = {1D5FAEEE-7E6E-43B1-9F7F-802714316B15} ?>
46 46 <?define mergetools.rc.guid = {E8A1DC29-FF40-4B5F-BD12-80B9F7BF0CCD} ?>
47 47 <?define paths.rc.guid = {F9ADF21D-5F0B-4934-8CD9-14BE63664721} ?>
48 48 <?define cacert.pem.guid = {EC1B2630-FE21-46E6-915B-A6545AF703D4} ?>
49 49 <?define ProgramMenuDir.guid = {D5A63320-1238-489B-B68B-CF053E9577CA} ?>
50 50
51 51 </Include>
@@ -1,26 +1,26
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3 3
4 4 <?include guids.wxi ?>
5 5 <?include defines.wxi ?>
6 6
7 <?define hg_po_langs =
7 <?define hg_po_langs =
8 8 da;de;el;fr;it;ja;pt_BR;ro;ru;sv;zh_CN;zh_TW
9 9 ?>
10 10
11 11 <Fragment>
12 12 <DirectoryRef Id="INSTALLDIR">
13 13 <Directory Id="i18ndir" Name="i18n" FileSource="$(var.SourceDir)">
14 14 <Component Id="i18nFolder" Guid="$(var.i18nFolder.guid)" Win64='$(var.IsX64)'>
15 15 <File Name="hggettext" KeyPath="yes" />
16 16 <?foreach LANG in $(var.hg_po_langs) ?>
17 <File Id="hg.$(var.LANG).po"
18 Name="$(var.LANG).po"
17 <File Id="hg.$(var.LANG).po"
18 Name="$(var.LANG).po"
19 19 />
20 20 <?endforeach?>
21 21 </Component>
22 22 </Directory>
23 23 </DirectoryRef>
24 24 </Fragment>
25 25
26 26 </Wix>
@@ -1,172 +1,172
1 1 <?xml version='1.0' encoding='windows-1252'?>
2 2 <Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
3 3
4 4 <!-- Copyright 2010 Steve Borho <steve@borho.org>
5 5
6 6 This software may be used and distributed according to the terms of the
7 7 GNU General Public License version 2 or any later version. -->
8 8
9 9 <?include guids.wxi ?>
10 10 <?include defines.wxi ?>
11 11
12 12 <?if $(var.Platform) = "x64" ?>
13 13 <?define PFolder = ProgramFiles64Folder ?>
14 14 <?else?>
15 15 <?define PFolder = ProgramFilesFolder ?>
16 16 <?endif?>
17 17
18 18 <Product Id='*'
19 Name='Mercurial $(var.Version) ($(var.Platform))'
19 Name='Mercurial $(var.Version) ($(var.Platform))'
20 20 UpgradeCode='$(var.ProductUpgradeCode)'
21 21 Language='1033' Codepage='1252' Version='$(var.Version)'
22 22 Manufacturer='Matt Mackall and others'>
23 23
24 24 <Package Id='*'
25 25 Keywords='Installer'
26 26 Description="Mercurial distributed SCM (version $(var.Version))"
27 27 Comments='$(var.Comments)'
28 28 Platform='$(var.Platform)'
29 29 Manufacturer='Matt Mackall and others'
30 30 InstallerVersion='300' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
31 31
32 32 <Media Id='1' Cabinet='mercurial.cab' EmbedCab='yes' DiskPrompt='CD-ROM #1'
33 33 CompressionLevel='high' />
34 34 <Property Id='DiskPrompt' Value="Mercurial $(var.Version) Installation [1]" />
35 35
36 36 <Condition Message='Mercurial MSI installers require Windows XP or higher'>
37 37 VersionNT >= 501
38 38 </Condition>
39 39
40 40 <Property Id="INSTALLDIR">
41 41 <ComponentSearch Id='SearchForMainExecutableComponent'
42 42 Guid='$(var.ComponentMainExecutableGUID)' />
43 43 </Property>
44 44
45 45 <!--Property Id='ARPCOMMENTS'>any comments</Property-->
46 46 <Property Id='ARPCONTACT'>mercurial@selenic.com</Property>
47 47 <Property Id='ARPHELPLINK'>http://mercurial.selenic.com/wiki/</Property>
48 48 <Property Id='ARPURLINFOABOUT'>http://mercurial.selenic.com/about/</Property>
49 49 <Property Id='ARPURLUPDATEINFO'>http://mercurial.selenic.com/downloads/</Property>
50 50 <Property Id='ARPHELPTELEPHONE'>http://mercurial.selenic.com/wiki/Support</Property>
51 51 <Property Id='ARPPRODUCTICON'>hgIcon.ico</Property>
52 52
53 53 <Property Id='INSTALLEDMERCURIALPRODUCTS' Secure='yes'></Property>
54 54 <Property Id='REINSTALLMODE'>amus</Property>
55 55
56 56 <!--Auto-accept the license page-->
57 57 <Property Id='LicenseAccepted'>1</Property>
58 58
59 59 <Directory Id='TARGETDIR' Name='SourceDir'>
60 60 <Directory Id='$(var.PFolder)' Name='PFiles'>
61 61 <Directory Id='INSTALLDIR' Name='Mercurial'>
62 62 <Component Id='MainExecutable' Guid='$(var.ComponentMainExecutableGUID)' Win64='$(var.IsX64)'>
63 63 <File Id='hgEXE' Name='hg.exe' Source='dist\hg.exe' KeyPath='yes' />
64 64 <Environment Id="Environment" Name="PATH" Part="last" System="yes"
65 65 Permanent="no" Value="[INSTALLDIR]" Action="set" />
66 66 </Component>
67 67 <Component Id='ReadMe' Guid='$(var.ReadMe.guid)' Win64='$(var.IsX64)'>
68 68 <File Id='ReadMe' Name='ReadMe.html' Source='contrib\win32\ReadMe.html'
69 69 KeyPath='yes'/>
70 70 </Component>
71 71 <Component Id='COPYING' Guid='$(var.COPYING.guid)' Win64='$(var.IsX64)'>
72 72 <File Id='COPYING' Name='COPYING.rtf' Source='contrib\wix\COPYING.rtf'
73 73 KeyPath='yes'/>
74 74 </Component>
75 75
76 76 <Directory Id='HGRCD' Name='hgrc.d'>
77 77 <Component Id='mercurial.rc' Guid='$(var.mercurial.rc.guid)' Win64='$(var.IsX64)'>
78 78 <File Id='mercurial.rc' Name='Mercurial.rc' Source='contrib\win32\mercurial.ini'
79 79 ReadOnly='yes' KeyPath='yes'/>
80 80 </Component>
81 81 <Component Id='mergetools.rc' Guid='$(var.mergetools.rc.guid)' Win64='$(var.IsX64)'>
82 82 <File Id='mergetools.rc' Name='MergeTools.rc' Source='contrib\mergetools.hgrc'
83 83 ReadOnly='yes' KeyPath='yes'/>
84 84 </Component>
85 85 <Component Id='paths.rc' Guid='$(var.paths.rc.guid)' Win64='$(var.IsX64)'>
86 86 <CreateFolder/>
87 87 <IniFile Id="ini0" Action="createLine" Directory="HGRCD" Name="Paths.rc"
88 88 Section="web" Key="cacerts" Value="[INSTALLDIR]hgrc.d\cacert.pem" />
89 89 </Component>
90 90 <Component Id='cacert.pem' Guid='$(var.cacert.pem.guid)' Win64='$(var.IsX64)'>
91 91 <File Id='cacert.pem' Name='cacert.pem' Source='..\misc\cacert.pem'
92 92 ReadOnly='yes' KeyPath='yes'/>
93 93 </Component>
94 94 </Directory>
95 95
96 96 </Directory>
97 97 </Directory>
98 98
99 99 <Directory Id="ProgramMenuFolder" Name="Programs">
100 100 <Directory Id="ProgramMenuDir" Name="Mercurial $(var.Version)">
101 101 <Component Id="ProgramMenuDir" Guid="$(var.ProgramMenuDir.guid)" Win64='$(var.IsX64)'>
102 102 <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
103 103 <RegistryValue Root='HKCU' Key='Software\Mercurial\InstallDir' Type='string'
104 104 Value='[INSTALLDIR]' KeyPath='yes' />
105 105 <Shortcut Id='UrlShortcut' Directory='ProgramMenuDir' Name='Mercurial Web Site'
106 106 Target='[ARPHELPLINK]' Icon="hgIcon.ico" IconIndex='0' />
107 107 </Component>
108 108 </Directory>
109 109 </Directory>
110 110
111 111 <?if $(var.Platform) = "x86" ?>
112 112 <Merge Id='VCRuntime' DiskId='1' Language='1033'
113 113 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x86_msm.msm' />
114 114 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
115 115 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x86_msm.msm' />
116 116 <?else?>
117 117 <Merge Id='VCRuntime' DiskId='1' Language='1033'
118 118 SourceFile='$(var.VCRedistSrcDir)\microsoft.vcxx.crt.x64_msm.msm' />
119 119 <Merge Id='VCRuntimePolicy' DiskId='1' Language='1033'
120 120 SourceFile='$(var.VCRedistSrcDir)\policy.x.xx.microsoft.vcxx.crt.x64_msm.msm' />
121 121 <?endif?>
122 122 </Directory>
123 123
124 124 <Feature Id='Complete' Title='Mercurial' Description='The complete package'
125 125 Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR' >
126 126 <Feature Id='MainProgram' Title='Program' Description='Mercurial command line app'
127 127 Level='1' Absent='disallow' >
128 128 <ComponentRef Id='MainExecutable' />
129 129 <ComponentRef Id='distOutput' />
130 130 <ComponentRef Id='ProgramMenuDir' />
131 131 <ComponentRef Id='ReadMe' />
132 132 <ComponentRef Id='COPYING' />
133 133 <ComponentRef Id='mercurial.rc' />
134 134 <ComponentRef Id='mergetools.rc' />
135 135 <ComponentRef Id='paths.rc' />
136 136 <ComponentRef Id='cacert.pem' />
137 137 <ComponentRef Id='helpFolder' />
138 138 <ComponentGroupRef Id='templatesFolder' />
139 139 <MergeRef Id='VCRuntime' />
140 140 <MergeRef Id='VCRuntimePolicy' />
141 141 </Feature>
142 142 <Feature Id='Locales' Title='Translations' Description='Translations' Level='1'>
143 143 <ComponentGroupRef Id='localeFolder' />
144 144 <ComponentRef Id='i18nFolder' />
145 145 </Feature>
146 146 <Feature Id='Documentation' Title='Documentation' Description='HTML man pages' Level='1'>
147 147 <ComponentGroupRef Id='docFolder' />
148 148 </Feature>
149 149 <Feature Id='Misc' Title='Miscellaneous' Description='Contributed scripts' Level='1'>
150 150 <ComponentGroupRef Id='contribFolder' />
151 151 </Feature>
152 152 </Feature>
153 153
154 154 <UIRef Id="WixUI_FeatureTree" />
155 155 <UIRef Id="WixUI_ErrorProgressText" />
156 156
157 157 <WixVariable Id="WixUILicenseRtf" Value="contrib\wix\COPYING.rtf" />
158 158
159 159 <Icon Id="hgIcon.ico" SourceFile="contrib/win32/mercurial.ico" />
160 160
161 161 <Upgrade Id='$(var.ProductUpgradeCode)'>
162 162 <UpgradeVersion
163 163 IncludeMinimum='yes' Minimum='0.0.0' IncludeMaximum='no' OnlyDetect='no'
164 164 Property='INSTALLEDMERCURIALPRODUCTS' />
165 165 </Upgrade>
166 166
167 167 <InstallExecuteSequence>
168 168 <RemoveExistingProducts After='InstallInitialize'/>
169 169 </InstallExecuteSequence>
170 170
171 171 </Product>
172 172 </Wix>
@@ -1,309 +1,309
1 1 /*
2 2 * Styles for man pages, which match with http://mercurial.selenic.com/
3 3 *
4 4 * Color scheme & layout are borrowed from
5 5 * http://mercurial.selenic.com/css/styles.css
6 6 *
7 7 * Some styles are from html4css1.css from Docutils, which is in the
8 8 * public domain.
9 9 */
10 10
11 11 body {
12 12 margin: 0;
13 13 padding: 0;
14 14 font-family: sans-serif;
15 15 }
16 16
17 17 .document {
18 18 position: relative; /* be a top of absolute positioning */
19 19 margin: 1.5em 1.8em;
20 20 padding: 0;
21 21 line-height: 1.3;
22 22 }
23 23
24 24 /* layout: toc to right */
25 25 #contents {
26 26 position: absolute;
27 27 right: 0;
28 28 top: 0;
29 29 width: 26%;
30 30 }
31 31
32 32 /* layout: others to left */
33 33 h1.title, h2.subtitle, .section { width: 72%; }
34 34 .section .section { width: auto; }
35 35 table.docinfo { max-width: 72%; }
36 36
37 37 /* headings */
38 38 h1, h2, .topic-title, .admonition-title {
39 39 font-family: "MgOpen Cosmetica", "Lucida Sans Unicode", sans-serif;
40 40 font-weight: normal;
41 41 }
42 42 h1, h2, .topic-title, .admonition-title {
43 43 margin: 1em 0 0.5em;
44 44 }
45 45 h1.title { font-size: 300%; }
46 46 h2.subtitle, h1 { font-size: 200%; }
47 47 h2, .topic-title, .admonition-title { font-size: 140%; }
48 48
49 49 /* subtitle starts with lowercase in man pages, but not in HTML */
50 50 h2.subtitle:first-letter { text-transform: uppercase; }
51 51
52 52 /* override first/last margin */
53 53 .first, h1.title, h2.subtitle { margin-top: 0 !important; }
54 54 .last, .with-subtitle { margin-bottom: 0 !important; }
55 55
56 56 blockquote, pre, dd .option-list, .field-list {
57 57 margin: 0.2em 0 1em 2em;
58 58 }
59 59
60 60 kbd, tt, pre { font-family: monospace; }
61 61
62 62 dt { font-weight: bold; }
63 63 dd { margin-bottom: 0.5em; }
64 64
65 65 th, td { padding: 0.1em 0.2em; border: 0 none; }
66 66 th { font-weight: bold; text-align: left; }
67 67
68 68 a:link, a:visited { text-decoration: underline; }
69 69 a:hover, a:focus { text-decoration: none; }
70 70 a:link { color: #00b5f1; }
71 71 a:visited { color: #5c9caf; }
72 72 a:link.toc-backref, a:visited.toc-backref {
73 73 text-decoration: none;
74 74 color: inherit; /* NOTE: `inherit' is not supported by IE6 */
75 75 }
76 76
77 77 div.admonition, div.attention, div.caution,
78 78 div.danger, div.error, div.hint, div.important,
79 79 div.note, div.tip, div.warning {
80 80 border-top: 1px #ccc solid;
81 81 border-bottom: 1px #ccc solid;
82 82 padding: 0.3em 1em;
83 83 margin: 1em;
84 84 }
85 85
86 86 div.note {
87 87 border-color: #fcc200;
88 88 }
89 89
90 90
91 91 /*
92 92 * The following styles are from Docutils.
93 93 * Please refine if necessary.
94 94 */
95 95
96 96 table.borderless td, table.borderless th {
97 97 /* Override padding for "table.docutils td" with "! important".
98 98 The right padding separates the table cells. */
99 99 padding: 0 0.5em 0 0 ! important;
100 100 }
101 101
102 102 .hidden {
103 103 display: none;
104 104 }
105 105
106 106 blockquote.epigraph {
107 107 margin: 2em 5em;
108 108 }
109 109
110 110 div.abstract {
111 111 margin: 2em 5em;
112 112 }
113 113
114 114 div.dedication {
115 115 margin: 2em 5em;
116 116 text-align: center;
117 117 font-style: italic;
118 118 }
119 119
120 120 div.figure {
121 121 margin-left: 2em;
122 122 margin-right: 2em;
123 123 }
124 124
125 125 div.footer, div.header {
126 126 clear: both;
127 127 font-size: smaller;
128 128 }
129 129
130 130 div.line-block {
131 131 display: block;
132 132 margin-top: 1em;
133 133 margin-bottom: 1em;
134 134 }
135 135
136 136 div.line-block div.line-block {
137 137 margin-top: 0;
138 138 margin-bottom: 0;
139 139 margin-left: 1.5em;
140 140 }
141 141
142 142 div.sidebar {
143 143 margin: 0 0 0.5em 1em;
144 144 border: medium outset;
145 145 padding: 1em;
146 146 background-color: #ffffee;
147 147 width: 40%;
148 148 float: right;
149 149 clear: right;
150 150 }
151 151
152 152 div.sidebar p.rubric {
153 153 font-family: sans-serif;
154 154 font-size: medium;
155 155 }
156 156
157 157 div.system-messages {
158 158 margin: 5em;
159 159 }
160 160
161 161 div.system-messages h1 {
162 162 color: red;
163 163 }
164 164
165 165 div.system-message {
166 166 border: medium outset;
167 167 padding: 1em;
168 168 }
169 169
170 170 div.system-message p.system-message-title {
171 171 color: red;
172 172 font-weight: bold;
173 173 }
174 174
175 175 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
176 176 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
177 177 margin-top: 0.4em;
178 178 }
179 179
180 180 hr.docutils {
181 181 width: 75%;
182 182 }
183 183
184 184 img.align-left {
185 185 clear: left;
186 186 }
187 187
188 188 img.align-right {
189 189 clear: right;
190 190 }
191 191
192 192 ol.simple, ul.simple {
193 193 margin-bottom: 1em;
194 194 }
195 195
196 196 ol.arabic {
197 197 list-style: decimal;
198 198 }
199 199
200 200 ol.loweralpha {
201 201 list-style: lower-alpha;
202 202 }
203 203
204 204 ol.upperalpha {
205 205 list-style: upper-alpha;
206 206 }
207 207
208 208 ol.lowerroman {
209 209 list-style: lower-roman;
210 210 }
211 211
212 212 ol.upperroman {
213 213 list-style: upper-roman;
214 214 }
215 215
216 216 p.attribution {
217 217 text-align: right;
218 218 margin-left: 50%;
219 219 }
220 220
221 221 p.caption {
222 222 font-style: italic;
223 223 }
224 224
225 225 p.credits {
226 226 font-style: italic;
227 227 font-size: smaller;
228 228 }
229 229
230 230 p.label {
231 231 white-space: nowrap;
232 232 }
233 233
234 234 p.rubric {
235 235 font-weight: bold;
236 236 font-size: larger;
237 237 color: maroon;
238 238 text-align: center;
239 239 }
240 240
241 241 pre.address {
242 242 margin-bottom: 0;
243 243 margin-top: 0;
244 244 font-family: serif;
245 245 font-size: 100%;
246 246 }
247 247
248 248 pre.literal-block, pre.doctest-block {
249 249 margin-left: 2em;
250 250 margin-right: 2em;
251 251 }
252 252
253 253 span.classifier {
254 254 font-family: sans-serif;
255 255 font-style: oblique;
256 256 }
257 257
258 258 span.classifier-delimiter {
259 259 font-family: sans-serif;
260 260 font-weight: bold;
261 261 }
262 262
263 263 span.interpreted {
264 264 font-family: sans-serif;
265 265 }
266 266
267 267 span.option {
268 268 white-space: nowrap;
269 269 }
270 270
271 271 span.pre {
272 272 white-space: pre;
273 273 }
274 274
275 275 span.problematic {
276 276 color: red;
277 277 }
278 278
279 279 span.section-subtitle {
280 280 /* font-size relative to parent (h1..h6 element) */
281 281 font-size: 80%;
282 282 }
283 283
284 284 table.citation {
285 285 border-left: solid 1px gray;
286 286 margin-left: 1px;
287 287 }
288 288
289 289 table.footnote {
290 290 border-left: solid 1px black;
291 291 margin-left: 1px;
292 292 }
293 293
294 294 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
295 295 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
296 296 font-size: 100%;
297 297 }
298 298
299 299 ul.auto-toc {
300 300 list-style-type: none;
301 301 }
302 302
303 303 div.contents.local {
304 304 -moz-column-width: 10em;
305 305 -moz-column-gap: 1em;
306
306
307 307 -webkit-column-width: 10em;
308 308 -webkit-column-gap: 1em;
309 309 }
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 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