Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/gitk-git/gitk # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / gitk-git / gitk` 13031 lines · 408017 bytes Raw Blame History 1 #!/bin/sh 2 # Tcl ignores the next line -*- tcl -*- \ 3 exec wish "$0" -- "$@" 4 5 # Copyright © 2005-2016 Paul Mackerras. All rights reserved. 6 # This program is free software; it may be used, copied, modified 7 # and distributed under the terms of the GNU General Public Licence, 8 # either version 2, or (at your option) any later version. 9 10 if {[catch {package require Tcl 8.6-} err]} { 11 catch {wm withdraw .} 12 tk_messageBox \ 13 -icon error \ 14 -type ok \ 15 -title "gitk: fatal error" \ 16 -message $err 17 exit 1 18 } 19 20 set MIN_GIT_VERSION 2.20 21 regexp {^git version ([\d.]*\d)} [exec git version] _ git_version 22 if {[package vcompare $git_version $MIN_GIT_VERSION] < 0} { 23 set message "The git executable found is too old. 24 The minimum required version is $MIN_GIT_VERSION.0. 25 The version of git found is $git_version." 26 27 catch {wm withdraw .} 28 tk_messageBox \ 29 -icon error \ 30 -type ok \ 31 -title "gitk: fatal error" \ 32 -message $message 33 exit 1 34 } 35 36 ###################################################################### 37 ## Enable Tcl8 profile in Tcl9, allowing consumption of data that has 38 ## bytes not conforming to the assumed encoding profile. 39 40 if {[package vcompare $::tcl_version 9.0] >= 0} { 41 rename open _strict_open 42 proc open args { 43 set f [_strict_open {*}$args] 44 chan configure $f -profile tcl8 45 return $f 46 } 47 proc convertfrom args { 48 return [encoding convertfrom -profile tcl8 {*}$args] 49 } 50 } else { 51 proc convertfrom args { 52 return [encoding convertfrom {*}$args] 53 } 54 } 55 56 ###################################################################### 57 ## 58 ## Enabling platform-specific code paths 59 60 proc is_Windows {} { 61 if {$::tcl_platform(platform) eq {windows}} { 62 return 1 63 } 64 return 0 65 } 66 67 ###################################################################### 68 ## 69 ## PATH lookup 70 71 if {[is_Windows]} { 72 set _search_path {} 73 proc _which {what args} { 74 global env _search_path 75 76 if {$_search_path eq {}} { 77 set gitguidir [file dirname [info script]] 78 regsub -all ";" $gitguidir "\\;" gitguidir 79 set env(PATH) "$gitguidir;$env(PATH)" 80 set _search_path [split $env(PATH) {;}] 81 # Skip empty `PATH` elements 82 set _search_path [lsearch -all -inline -not -exact \ 83 $_search_path ""] 84 } 85 86 if {[lsearch -exact $args -script] >= 0} { 87 set suffix {} 88 } else { 89 set suffix .exe 90 } 91 92 foreach p $_search_path { 93 set p [file join $p $what$suffix] 94 if {[file exists $p]} { 95 return [file normalize $p] 96 } 97 } 98 return {} 99 } 100 101 proc sanitize_command_line {command_line from_index} { 102 set i $from_index 103 while {$i < [llength $command_line]} { 104 set cmd [lindex $command_line $i] 105 if {[llength [file split $cmd]] < 2} { 106 set fullpath [_which $cmd] 107 if {$fullpath eq ""} { 108 throw {NOT-FOUND} "$cmd not found in PATH" 109 } 110 lset command_line $i $fullpath 111 } 112 113 # handle piped commands, e.g. `exec A | B` 114 for {incr i} {$i < [llength $command_line]} {incr i} { 115 if {[lindex $command_line $i] eq "|"} { 116 incr i 117 break 118 } 119 } 120 } 121 return $command_line 122 } 123 124 # Override `exec` to avoid unsafe PATH lookup 125 126 rename exec real_exec 127 128 proc exec {args} { 129 # skip options 130 for {set i 0} {$i < [llength $args]} {incr i} { 131 set arg [lindex $args $i] 132 if {$arg eq "--"} { 133 incr i 134 break 135 } 136 if {[string range $arg 0 0] ne "-"} { 137 break 138 } 139 } 140 set args [sanitize_command_line $args $i] 141 uplevel 1 real_exec $args 142 } 143 144 # Override `open` to avoid unsafe PATH lookup 145 146 rename open real_open 147 148 proc open {args} { 149 set arg0 [lindex $args 0] 150 if {[string range $arg0 0 0] eq "|"} { 151 set command_line [string trim [string range $arg0 1 end]] 152 lset args 0 "| [sanitize_command_line $command_line 0]" 153 } 154 uplevel 1 real_open $args 155 } 156 } 157 158 # End of safe PATH lookup stuff 159 160 # Wrap exec/open to sanitize arguments 161 162 # unsafe arguments begin with redirections or the pipe or background operators 163 proc is_arg_unsafe {arg} { 164 regexp {^([<|>&]|2>)} $arg 165 } 166 167 proc make_arg_safe {arg} { 168 if {[is_arg_unsafe $arg]} { 169 set arg [file join . $arg] 170 } 171 return $arg 172 } 173 174 proc make_arglist_safe {arglist} { 175 set res {} 176 foreach arg $arglist { 177 lappend res [make_arg_safe $arg] 178 } 179 return $res 180 } 181 182 # executes one command 183 # no redirections or pipelines are possible 184 # cmd is a list that specifies the command and its arguments 185 # calls `exec` and returns its value 186 proc safe_exec {cmd} { 187 eval exec [make_arglist_safe $cmd] 188 } 189 190 # executes one command with redirections 191 # no pipelines are possible 192 # cmd is a list that specifies the command and its arguments 193 # redir is a list that specifies redirections (output, background, constant(!) commands) 194 # calls `exec` and returns its value 195 proc safe_exec_redirect {cmd redir} { 196 eval exec [make_arglist_safe $cmd] $redir 197 } 198 199 proc safe_open_file {filename flags} { 200 # a file name starting with "|" would attempt to run a process 201 # but such a file name must be treated as a relative path 202 # hide the "|" behind "./" 203 if {[string index $filename 0] eq "|"} { 204 set filename [file join . $filename] 205 } 206 open $filename $flags 207 } 208 209 # opens a command pipeline for reading 210 # cmd is a list that specifies the command and its arguments 211 # calls `open` and returns the file id 212 proc safe_open_command {cmd} { 213 open |[make_arglist_safe $cmd] r 214 } 215 216 # opens a command pipeline for reading and writing 217 # cmd is a list that specifies the command and its arguments 218 # calls `open` and returns the file id 219 proc safe_open_command_rw {cmd} { 220 open |[make_arglist_safe $cmd] r+ 221 } 222 223 # opens a command pipeline for reading with redirections 224 # cmd is a list that specifies the command and its arguments 225 # redir is a list that specifies redirections 226 # calls `open` and returns the file id 227 proc safe_open_command_redirect {cmd redir} { 228 set cmd [make_arglist_safe $cmd] 229 open |[concat $cmd $redir] r 230 } 231 232 # opens a pipeline with several commands for reading 233 # cmds is a list of lists, each of which specifies a command and its arguments 234 # calls `open` and returns the file id 235 proc safe_open_pipeline {cmds} { 236 set cmd {} 237 foreach subcmd $cmds { 238 set cmd [concat $cmd | [make_arglist_safe $subcmd]] 239 } 240 open $cmd r 241 } 242 243 # End exec/open wrappers 244 245 proc hasworktree {} { 246 return [expr {[exec git rev-parse --is-bare-repository] == "false" && 247 [exec git rev-parse --is-inside-git-dir] == "false"}] 248 } 249 250 proc reponame {} { 251 global gitdir 252 set n [file normalize $gitdir] 253 if {[string match "*/.git" $n]} { 254 set n [string range $n 0 end-5] 255 } 256 return [file tail $n] 257 } 258 259 proc gitworktree {} { 260 variable _gitworktree 261 if {[info exists _gitworktree]} { 262 return $_gitworktree 263 } 264 # v1.7.0 introduced --show-toplevel to return the canonical work-tree 265 if {[catch {set _gitworktree [exec git rev-parse --show-toplevel]}]} { 266 # try to set work tree from environment, core.worktree or use 267 # cdup to obtain a relative path to the top of the worktree. If 268 # run from the top, the ./ prefix ensures normalize expands pwd. 269 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} { 270 if {[catch {set _gitworktree [exec git config --get core.worktree]}]} { 271 set _gitworktree [file normalize ./[exec git rev-parse --show-cdup]] 272 } 273 } 274 } 275 return $_gitworktree 276 } 277 278 # A simple scheduler for compute-intensive stuff. 279 # The aim is to make sure that event handlers for GUI actions can 280 # run at least every 50-100 ms. Unfortunately fileevent handlers are 281 # run before X event handlers, so reading from a fast source can 282 # make the GUI completely unresponsive. 283 proc run args { 284 global isonrunq runq currunq 285 286 set script $args 287 if {[info exists isonrunq($script)]} return 288 if {$runq eq {} && ![info exists currunq]} { 289 after idle dorunq 290 } 291 lappend runq [list {} $script] 292 set isonrunq($script) 1 293 } 294 295 proc filerun {fd script} { 296 fileevent $fd readable [list filereadable $fd $script] 297 } 298 299 proc filereadable {fd script} { 300 global runq currunq 301 302 fileevent $fd readable {} 303 if {$runq eq {} && ![info exists currunq]} { 304 after idle dorunq 305 } 306 lappend runq [list $fd $script] 307 } 308 309 proc nukefile {fd} { 310 global runq 311 312 for {set i 0} {$i < [llength $runq]} {} { 313 if {[lindex $runq $i 0] eq $fd} { 314 set runq [lreplace $runq $i $i] 315 } else { 316 incr i 317 } 318 } 319 } 320 321 proc dorunq {} { 322 global isonrunq runq currunq 323 324 set tstart [clock clicks -milliseconds] 325 set t0 $tstart 326 while {[llength $runq] > 0} { 327 set fd [lindex $runq 0 0] 328 set script [lindex $runq 0 1] 329 set currunq [lindex $runq 0] 330 set runq [lrange $runq 1 end] 331 set repeat [eval $script] 332 unset currunq 333 set t1 [clock clicks -milliseconds] 334 set t [expr {$t1 - $t0}] 335 if {$repeat ne {} && $repeat} { 336 if {$fd eq {} || $repeat == 2} { 337 # script returns 1 if it wants to be readded 338 # file readers return 2 if they could do more straight away 339 lappend runq [list $fd $script] 340 } else { 341 fileevent $fd readable [list filereadable $fd $script] 342 } 343 } elseif {$fd eq {}} { 344 unset isonrunq($script) 345 } 346 set t0 $t1 347 if {$t1 - $tstart >= 80} break 348 } 349 if {$runq ne {}} { 350 after idle dorunq 351 } 352 } 353 354 proc reg_instance {fd} { 355 global commfd leftover loginstance 356 357 set i [incr loginstance] 358 set commfd($i) $fd 359 set leftover($i) {} 360 return $i 361 } 362 363 proc unmerged_files {files} { 364 global nr_unmerged 365 366 # find the list of unmerged files 367 set mlist {} 368 set nr_unmerged 0 369 if {[catch { 370 set fd [safe_open_command {git ls-files -u}] 371 } err]} { 372 show_error {} . "[mc "Couldn't get list of unmerged files:"] $err" 373 exit 1 374 } 375 while {[gets $fd line] >= 0} { 376 set i [string first "\t" $line] 377 if {$i < 0} continue 378 set fname [string range $line [expr {$i+1}] end] 379 if {[lsearch -exact $mlist $fname] >= 0} continue 380 incr nr_unmerged 381 if {$files eq {} || [path_filter $files $fname]} { 382 lappend mlist $fname 383 } 384 } 385 catch {close $fd} 386 return $mlist 387 } 388 389 proc parseviewargs {n arglist} { 390 global vdatemode vmergeonly vflags vdflags vrevs vfiltered vorigargs env 391 global vinlinediff 392 global worddiff 393 394 set vdatemode($n) 0 395 set vmergeonly($n) 0 396 set vinlinediff($n) 0 397 set glflags {} 398 set diffargs {} 399 set nextisval 0 400 set revargs {} 401 set origargs $arglist 402 set allknown 1 403 set filtered 0 404 set i -1 405 foreach arg $arglist { 406 incr i 407 if {$nextisval} { 408 lappend glflags $arg 409 set nextisval 0 410 continue 411 } 412 switch -glob -- $arg { 413 "-d" - 414 "--date-order" { 415 set vdatemode($n) 1 416 # remove from origargs in case we hit an unknown option 417 set origargs [lreplace $origargs $i $i] 418 incr i -1 419 } 420 "-[puabwcrRBMC]" - 421 "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" - 422 "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" - 423 "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" - 424 "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" - 425 "--ignore-space-change" - "-U*" - "--unified=*" { 426 # These request or affect diff output, which we don't want. 427 # Some could be used to set our defaults for diff display. 428 lappend diffargs $arg 429 } 430 "--raw" - "--patch-with-raw" - "--patch-with-stat" - 431 "--name-only" - "--name-status" - "--color" - 432 "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" - 433 "--cc" - "-z" - "--header" - "--parents" - "--boundary" - 434 "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" - 435 "--timestamp" - "relative-date" - "--date=*" - "--stdin" - 436 "--objects" - "--objects-edge" - "--reverse" { 437 # These cause our parsing of git log's output to fail, or else 438 # they're options we want to set ourselves, so ignore them. 439 } 440 "--color-words*" - "--word-diff=color" { 441 # These trigger a word diff in the console interface, 442 # so help the user by enabling our own support 443 set worddiff [mc "Color words"] 444 } 445 "--word-diff*" { 446 set worddiff [mc "Markup words"] 447 } 448 "--stat=*" - "--numstat" - "--shortstat" - "--summary" - 449 "--check" - "--exit-code" - "--quiet" - "--topo-order" - 450 "--full-history" - "--dense" - "--sparse" - 451 "--follow" - "--left-right" - "--encoding=*" { 452 # These are harmless, and some are even useful 453 lappend glflags $arg 454 } 455 "--diff-filter=*" - "--no-merges" - "--unpacked" - 456 "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" - 457 "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - 458 "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - 459 "--remove-empty" - "--first-parent" - "--cherry-pick" - 460 "-S*" - "-G*" - "--pickaxe-all" - "--pickaxe-regex" - 461 "--simplify-by-decoration" { 462 # These mean that we get a subset of the commits 463 set filtered 1 464 lappend glflags $arg 465 } 466 "-L*" { 467 # Line-log with 'stuck' argument (unstuck form is 468 # not supported) 469 set filtered 1 470 set vinlinediff($n) 1 471 set allknown 0 472 lappend glflags $arg 473 } 474 "-n" { 475 # This appears to be the only one that has a value as a 476 # separate word following it 477 set filtered 1 478 set nextisval 1 479 lappend glflags $arg 480 } 481 "--not" - "--all" { 482 lappend revargs $arg 483 } 484 "--merge" { 485 set vmergeonly($n) 1 486 # git rev-parse doesn't understand --merge 487 lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD 488 } 489 "--no-replace-objects" { 490 set env(GIT_NO_REPLACE_OBJECTS) "1" 491 } 492 "-*" { 493 # Other flag arguments including - 494 if {[string is digit -strict [string range $arg 1 end]]} { 495 set filtered 1 496 } else { 497 # a flag argument that we don't recognize; 498 # that means we can't optimize 499 set allknown 0 500 } 501 lappend glflags $arg 502 } 503 default { 504 # Non-flag arguments specify commits or ranges of commits 505 if {[string match "*...*" $arg]} { 506 lappend revargs --gitk-symmetric-diff-marker 507 } 508 lappend revargs $arg 509 } 510 } 511 } 512 set vdflags($n) $diffargs 513 set vflags($n) $glflags 514 set vrevs($n) $revargs 515 set vfiltered($n) $filtered 516 set vorigargs($n) $origargs 517 return $allknown 518 } 519 520 proc parseviewrevs {view revs} { 521 global vposids vnegids 522 global hashlength 523 524 if {$revs eq {}} { 525 set revs HEAD 526 } elseif {[lsearch -exact $revs --all] >= 0} { 527 lappend revs HEAD 528 } 529 if {[catch {set ids [safe_exec [concat git rev-parse $revs]]} err]} { 530 # we get stdout followed by stderr in $err 531 # for an unknown rev, git rev-parse echoes it and then errors out 532 set errlines [split $err "\n"] 533 set badrev {} 534 for {set l 0} {$l < [llength $errlines]} {incr l} { 535 set line [lindex $errlines $l] 536 if {!([string length $line] == $hashlength && [string is xdigit $line])} { 537 if {[string match "fatal:*" $line]} { 538 if {[string match "fatal: ambiguous argument*" $line] 539 && $badrev ne {}} { 540 if {[llength $badrev] == 1} { 541 set err "unknown revision $badrev" 542 } else { 543 set err "unknown revisions: [join $badrev ", "]" 544 } 545 } else { 546 set err [join [lrange $errlines $l end] "\n"] 547 } 548 break 549 } 550 lappend badrev $line 551 } 552 } 553 error_popup "[mc "Error parsing revisions:"] $err" 554 return {} 555 } 556 set ret {} 557 set pos {} 558 set neg {} 559 set sdm 0 560 foreach id [split $ids "\n"] { 561 if {$id eq "--gitk-symmetric-diff-marker"} { 562 set sdm 4 563 } elseif {[string match "^*" $id]} { 564 if {$sdm != 1} { 565 lappend ret $id 566 if {$sdm == 3} { 567 set sdm 0 568 } 569 } 570 lappend neg [string range $id 1 end] 571 } else { 572 if {$sdm != 2} { 573 lappend ret $id 574 } else { 575 lset ret end $id...[lindex $ret end] 576 } 577 lappend pos $id 578 } 579 incr sdm -1 580 } 581 set vposids($view) $pos 582 set vnegids($view) $neg 583 return $ret 584 } 585 586 # Start off a git log process and arrange to read its output 587 proc start_rev_list {view} { 588 global startmsecs commitidx viewcomplete curview 589 global tclencoding 590 global viewargs viewargscmd viewfiles vfilelimit 591 global showlocalchanges 592 global viewactive viewinstances vmergeonly 593 global mainheadid viewmainheadid viewmainheadid_orig 594 global vcanopt vflags vrevs vorigargs 595 596 set startmsecs [clock clicks -milliseconds] 597 set commitidx($view) 0 598 # these are set this way for the error exits 599 set viewcomplete($view) 1 600 set viewactive($view) 0 601 varcinit $view 602 603 set args $viewargs($view) 604 if {$viewargscmd($view) ne {}} { 605 if {[catch { 606 set str [safe_exec [list sh -c $viewargscmd($view)]] 607 } err]} { 608 error_popup "[mc "Error executing --argscmd command:"] $err" 609 return 0 610 } 611 set args [concat $args [split $str "\n"]] 612 } 613 set vcanopt($view) [parseviewargs $view $args] 614 615 set files $viewfiles($view) 616 if {$vmergeonly($view)} { 617 set files [unmerged_files $files] 618 if {$files eq {}} { 619 global nr_unmerged 620 if {$nr_unmerged == 0} { 621 error_popup [mc "No files selected: --merge specified but\ 622 no files are unmerged."] 623 } else { 624 error_popup [mc "No files selected: --merge specified but\ 625 no unmerged files are within file limit."] 626 } 627 return 0 628 } 629 } 630 set vfilelimit($view) $files 631 632 if {$vcanopt($view)} { 633 set revs [parseviewrevs $view $vrevs($view)] 634 if {$revs eq {}} { 635 return 0 636 } 637 set args $vflags($view) 638 } else { 639 set revs {} 640 set args $vorigargs($view) 641 } 642 643 if {[catch { 644 set fd [safe_open_command_redirect [concat git log --no-color -z --pretty=raw --show-notes \ 645 --parents --boundary $args --stdin] \ 646 [list "<<[join [concat $revs "--" $files] "\n"]"]] 647 } err]} { 648 error_popup "[mc "Error executing git log:"] $err" 649 return 0 650 } 651 set i [reg_instance $fd] 652 set viewinstances($view) [list $i] 653 set viewmainheadid($view) $mainheadid 654 set viewmainheadid_orig($view) $mainheadid 655 if {$files ne {} && $mainheadid ne {}} { 656 get_viewmainhead $view 657 } 658 if {$showlocalchanges && $viewmainheadid($view) ne {}} { 659 interestedin $viewmainheadid($view) dodiffindex 660 } 661 fconfigure $fd -blocking 0 -translation lf -eofchar {} 662 if {$tclencoding != {}} { 663 fconfigure $fd -encoding $tclencoding 664 } 665 filerun $fd [list getcommitlines $fd $i $view 0] 666 nowbusy $view [mc "Reading"] 667 set viewcomplete($view) 0 668 set viewactive($view) 1 669 return 1 670 } 671 672 proc stop_instance {inst} { 673 global commfd leftover 674 675 set fd $commfd($inst) 676 catch { 677 set pid [pid $fd] 678 679 if {$::tcl_platform(platform) eq {windows}} { 680 safe_exec [list taskkill /pid $pid] 681 } else { 682 safe_exec [list kill $pid] 683 } 684 } 685 catch {close $fd} 686 nukefile $fd 687 unset commfd($inst) 688 unset leftover($inst) 689 } 690 691 proc stop_backends {} { 692 global commfd 693 694 foreach inst [array names commfd] { 695 stop_instance $inst 696 } 697 } 698 699 proc stop_rev_list {view} { 700 global viewinstances 701 702 foreach inst $viewinstances($view) { 703 stop_instance $inst 704 } 705 set viewinstances($view) {} 706 } 707 708 proc reset_pending_select {selid} { 709 global pending_select mainheadid selectheadid 710 711 if {$selid ne {}} { 712 set pending_select $selid 713 } elseif {$selectheadid ne {}} { 714 set pending_select $selectheadid 715 } else { 716 set pending_select $mainheadid 717 } 718 } 719 720 proc getcommits {selid} { 721 global canv curview need_redisplay viewactive 722 723 initlayout 724 if {[start_rev_list $curview]} { 725 reset_pending_select $selid 726 show_status [mc "Reading commits..."] 727 set need_redisplay 1 728 } else { 729 show_status [mc "No commits selected"] 730 } 731 } 732 733 proc updatecommits {} { 734 global curview vcanopt vorigargs vfilelimit viewinstances 735 global viewactive viewcomplete tclencoding 736 global startmsecs showneartags showlocalchanges 737 global mainheadid viewmainheadid viewmainheadid_orig pending_select 738 global hasworktree 739 global varcid vposids vnegids vflags vrevs 740 global hashlength 741 742 set hasworktree [hasworktree] 743 rereadrefs 744 set view $curview 745 if {$mainheadid ne $viewmainheadid_orig($view)} { 746 if {$showlocalchanges} { 747 dohidelocalchanges 748 } 749 set viewmainheadid($view) $mainheadid 750 set viewmainheadid_orig($view) $mainheadid 751 if {$vfilelimit($view) ne {}} { 752 get_viewmainhead $view 753 } 754 } 755 if {$showlocalchanges} { 756 doshowlocalchanges 757 } 758 if {$vcanopt($view)} { 759 set oldpos $vposids($view) 760 set oldneg $vnegids($view) 761 set revs [parseviewrevs $view $vrevs($view)] 762 if {$revs eq {}} { 763 return 764 } 765 # note: getting the delta when negative refs change is hard, 766 # and could require multiple git log invocations, so in that 767 # case we ask git log for all the commits (not just the delta) 768 if {$oldneg eq $vnegids($view)} { 769 set newrevs {} 770 set npos 0 771 # take out positive refs that we asked for before or 772 # that we have already seen 773 foreach rev $revs { 774 if {[string length $rev] == $hashlength} { 775 if {[lsearch -exact $oldpos $rev] < 0 776 && ![info exists varcid($view,$rev)]} { 777 lappend newrevs $rev 778 incr npos 779 } 780 } else { 781 lappend $newrevs $rev 782 } 783 } 784 if {$npos == 0} return 785 set revs $newrevs 786 set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]] 787 } 788 set args $vflags($view) 789 foreach r $oldpos { 790 lappend revs "^$r" 791 } 792 } else { 793 set revs {} 794 set args $vorigargs($view) 795 } 796 if {[catch { 797 set fd [safe_open_command_redirect [concat git log --no-color -z --pretty=raw --show-notes \ 798 --parents --boundary $args --stdin] \ 799 [list "<<[join [concat $revs "--" $vfilelimit($view)] "\n"]"]] 800 } err]} { 801 error_popup "[mc "Error executing git log:"] $err" 802 return 803 } 804 if {$viewactive($view) == 0} { 805 set startmsecs [clock clicks -milliseconds] 806 } 807 set i [reg_instance $fd] 808 lappend viewinstances($view) $i 809 fconfigure $fd -blocking 0 -translation lf -eofchar {} 810 if {$tclencoding != {}} { 811 fconfigure $fd -encoding $tclencoding 812 } 813 filerun $fd [list getcommitlines $fd $i $view 1] 814 incr viewactive($view) 815 set viewcomplete($view) 0 816 reset_pending_select {} 817 nowbusy $view [mc "Reading"] 818 if {$showneartags} { 819 getallcommits 820 } 821 } 822 823 proc reloadcommits {} { 824 global curview viewcomplete selectedline currentid thickerline 825 global showneartags treediffs commitinterest cached_commitrow 826 global targetid commitinfo 827 828 set selid {} 829 if {$selectedline ne {}} { 830 set selid $currentid 831 } 832 833 if {!$viewcomplete($curview)} { 834 stop_rev_list $curview 835 } 836 resetvarcs $curview 837 set selectedline {} 838 unset -nocomplain currentid 839 unset -nocomplain thickerline 840 unset -nocomplain treediffs 841 readrefs 842 changedrefs 843 if {$showneartags} { 844 getallcommits 845 } 846 clear_display 847 unset -nocomplain commitinfo 848 unset -nocomplain commitinterest 849 unset -nocomplain cached_commitrow 850 unset -nocomplain targetid 851 setcanvscroll 852 getcommits $selid 853 return 0 854 } 855 856 # This makes a string representation of a positive integer which 857 # sorts as a string in numerical order 858 proc strrep {n} { 859 if {$n < 16} { 860 return [format "%x" $n] 861 } elseif {$n < 256} { 862 return [format "x%.2x" $n] 863 } elseif {$n < 65536} { 864 return [format "y%.4x" $n] 865 } 866 return [format "z%.8x" $n] 867 } 868 869 # Procedures used in reordering commits from git log (without 870 # --topo-order) into the order for display. 871 872 proc varcinit {view} { 873 global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow 874 global vtokmod varcmod vrowmod varcix vlastins 875 876 set varcstart($view) {{}} 877 set vupptr($view) {0} 878 set vdownptr($view) {0} 879 set vleftptr($view) {0} 880 set vbackptr($view) {0} 881 set varctok($view) {{}} 882 set varcrow($view) {{}} 883 set vtokmod($view) {} 884 set varcmod($view) 0 885 set vrowmod($view) 0 886 set varcix($view) {{}} 887 set vlastins($view) {0} 888 } 889 890 proc resetvarcs {view} { 891 global varcid varccommits parents children vseedcount ordertok 892 global vshortids 893 894 foreach vid [array names varcid $view,*] { 895 unset varcid($vid) 896 unset children($vid) 897 unset parents($vid) 898 } 899 foreach vid [array names vshortids $view,*] { 900 unset vshortids($vid) 901 } 902 # some commits might have children but haven't been seen yet 903 foreach vid [array names children $view,*] { 904 unset children($vid) 905 } 906 foreach va [array names varccommits $view,*] { 907 unset varccommits($va) 908 } 909 foreach vd [array names vseedcount $view,*] { 910 unset vseedcount($vd) 911 } 912 unset -nocomplain ordertok 913 } 914 915 # returns a list of the commits with no children 916 proc seeds {v} { 917 global vdownptr vleftptr varcstart 918 919 set ret {} 920 set a [lindex $vdownptr($v) 0] 921 while {$a != 0} { 922 lappend ret [lindex $varcstart($v) $a] 923 set a [lindex $vleftptr($v) $a] 924 } 925 return $ret 926 } 927 928 proc newvarc {view id} { 929 global varcid varctok parents children vdatemode 930 global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart 931 global commitdata commitinfo vseedcount varccommits vlastins 932 933 set a [llength $varctok($view)] 934 set vid $view,$id 935 if {[llength $children($vid)] == 0 || $vdatemode($view)} { 936 if {![info exists commitinfo($id)]} { 937 parsecommit $id $commitdata($id) 1 938 } 939 set cdate [lindex [lindex $commitinfo($id) 4] 0] 940 if {![string is integer -strict $cdate]} { 941 set cdate 0 942 } 943 if {![info exists vseedcount($view,$cdate)]} { 944 set vseedcount($view,$cdate) -1 945 } 946 set c [incr vseedcount($view,$cdate)] 947 set cdate [expr {$cdate ^ 0xffffffff}] 948 set tok "s[strrep $cdate][strrep $c]" 949 } else { 950 set tok {} 951 } 952 set ka 0 953 if {[llength $children($vid)] > 0} { 954 set kid [lindex $children($vid) end] 955 set k $varcid($view,$kid) 956 if {[string compare [lindex $varctok($view) $k] $tok] > 0} { 957 set ki $kid 958 set ka $k 959 set tok [lindex $varctok($view) $k] 960 } 961 } 962 if {$ka != 0} { 963 set i [lsearch -exact $parents($view,$ki) $id] 964 set j [expr {[llength $parents($view,$ki)] - 1 - $i}] 965 append tok [strrep $j] 966 } 967 set c [lindex $vlastins($view) $ka] 968 if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} { 969 set c $ka 970 set b [lindex $vdownptr($view) $ka] 971 } else { 972 set b [lindex $vleftptr($view) $c] 973 } 974 while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} { 975 set c $b 976 set b [lindex $vleftptr($view) $c] 977 } 978 if {$c == $ka} { 979 lset vdownptr($view) $ka $a 980 lappend vbackptr($view) 0 981 } else { 982 lset vleftptr($view) $c $a 983 lappend vbackptr($view) $c 984 } 985 lset vlastins($view) $ka $a 986 lappend vupptr($view) $ka 987 lappend vleftptr($view) $b 988 if {$b != 0} { 989 lset vbackptr($view) $b $a 990 } 991 lappend varctok($view) $tok 992 lappend varcstart($view) $id 993 lappend vdownptr($view) 0 994 lappend varcrow($view) {} 995 lappend varcix($view) {} 996 set varccommits($view,$a) {} 997 lappend vlastins($view) 0 998 return $a 999 } 1000 1001 proc splitvarc {p v} { 1002 global varcid varcstart varccommits varctok vtokmod 1003 global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins 1004 1005 set oa $varcid($v,$p) 1006 set otok [lindex $varctok($v) $oa] 1007 set ac $varccommits($v,$oa) 1008 set i [lsearch -exact $varccommits($v,$oa) $p] 1009 if {$i <= 0} return 1010 set na [llength $varctok($v)] 1011 # "%" sorts before "0"... 1012 set tok "$otok%[strrep $i]" 1013 lappend varctok($v) $tok 1014 lappend varcrow($v) {} 1015 lappend varcix($v) {} 1016 set varccommits($v,$oa) [lrange $ac 0 [expr {$i - 1}]] 1017 set varccommits($v,$na) [lrange $ac $i end] 1018 lappend varcstart($v) $p 1019 foreach id $varccommits($v,$na) { 1020 set varcid($v,$id) $na 1021 } 1022 lappend vdownptr($v) [lindex $vdownptr($v) $oa] 1023 lappend vlastins($v) [lindex $vlastins($v) $oa] 1024 lset vdownptr($v) $oa $na 1025 lset vlastins($v) $oa 0 1026 lappend vupptr($v) $oa 1027 lappend vleftptr($v) 0 1028 lappend vbackptr($v) 0 1029 for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} { 1030 lset vupptr($v) $b $na 1031 } 1032 if {[string compare $otok $vtokmod($v)] <= 0} { 1033 modify_arc $v $oa 1034 } 1035 } 1036 1037 proc renumbervarc {a v} { 1038 global parents children varctok varcstart varccommits 1039 global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod vdatemode 1040 1041 set t1 [clock clicks -milliseconds] 1042 set todo {} 1043 set isrelated($a) 1 1044 set kidchanged($a) 1 1045 set ntot 0 1046 while {$a != 0} { 1047 if {[info exists isrelated($a)]} { 1048 lappend todo $a 1049 set id [lindex $varccommits($v,$a) end] 1050 foreach p $parents($v,$id) { 1051 if {[info exists varcid($v,$p)]} { 1052 set isrelated($varcid($v,$p)) 1 1053 } 1054 } 1055 } 1056 incr ntot 1057 set b [lindex $vdownptr($v) $a] 1058 if {$b == 0} { 1059 while {$a != 0} { 1060 set b [lindex $vleftptr($v) $a] 1061 if {$b != 0} break 1062 set a [lindex $vupptr($v) $a] 1063 } 1064 } 1065 set a $b 1066 } 1067 foreach a $todo { 1068 if {![info exists kidchanged($a)]} continue 1069 set id [lindex $varcstart($v) $a] 1070 if {[llength $children($v,$id)] > 1} { 1071 set children($v,$id) [lsort -command [list vtokcmp $v] \ 1072 $children($v,$id)] 1073 } 1074 set oldtok [lindex $varctok($v) $a] 1075 if {!$vdatemode($v)} { 1076 set tok {} 1077 } else { 1078 set tok $oldtok 1079 } 1080 set ka 0 1081 set kid [last_real_child $v,$id] 1082 if {$kid ne {}} { 1083 set k $varcid($v,$kid) 1084 if {[string compare [lindex $varctok($v) $k] $tok] > 0} { 1085 set ki $kid 1086 set ka $k 1087 set tok [lindex $varctok($v) $k] 1088 } 1089 } 1090 if {$ka != 0} { 1091 set i [lsearch -exact $parents($v,$ki) $id] 1092 set j [expr {[llength $parents($v,$ki)] - 1 - $i}] 1093 append tok [strrep $j] 1094 } 1095 if {$tok eq $oldtok} { 1096 continue 1097 } 1098 set id [lindex $varccommits($v,$a) end] 1099 foreach p $parents($v,$id) { 1100 if {[info exists varcid($v,$p)]} { 1101 set kidchanged($varcid($v,$p)) 1 1102 } else { 1103 set sortkids($p) 1 1104 } 1105 } 1106 lset varctok($v) $a $tok 1107 set b [lindex $vupptr($v) $a] 1108 if {$b != $ka} { 1109 if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} { 1110 modify_arc $v $ka 1111 } 1112 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} { 1113 modify_arc $v $b 1114 } 1115 set c [lindex $vbackptr($v) $a] 1116 set d [lindex $vleftptr($v) $a] 1117 if {$c == 0} { 1118 lset vdownptr($v) $b $d 1119 } else { 1120 lset vleftptr($v) $c $d 1121 } 1122 if {$d != 0} { 1123 lset vbackptr($v) $d $c 1124 } 1125 if {[lindex $vlastins($v) $b] == $a} { 1126 lset vlastins($v) $b $c 1127 } 1128 lset vupptr($v) $a $ka 1129 set c [lindex $vlastins($v) $ka] 1130 if {$c == 0 || \ 1131 [string compare $tok [lindex $varctok($v) $c]] < 0} { 1132 set c $ka 1133 set b [lindex $vdownptr($v) $ka] 1134 } else { 1135 set b [lindex $vleftptr($v) $c] 1136 } 1137 while {$b != 0 && \ 1138 [string compare $tok [lindex $varctok($v) $b]] >= 0} { 1139 set c $b 1140 set b [lindex $vleftptr($v) $c] 1141 } 1142 if {$c == $ka} { 1143 lset vdownptr($v) $ka $a 1144 lset vbackptr($v) $a 0 1145 } else { 1146 lset vleftptr($v) $c $a 1147 lset vbackptr($v) $a $c 1148 } 1149 lset vleftptr($v) $a $b 1150 if {$b != 0} { 1151 lset vbackptr($v) $b $a 1152 } 1153 lset vlastins($v) $ka $a 1154 } 1155 } 1156 foreach id [array names sortkids] { 1157 if {[llength $children($v,$id)] > 1} { 1158 set children($v,$id) [lsort -command [list vtokcmp $v] \ 1159 $children($v,$id)] 1160 } 1161 } 1162 set t2 [clock clicks -milliseconds] 1163 #puts "renumbervarc did [llength $todo] of $ntot arcs in [expr {$t2-$t1}]ms" 1164 } 1165 1166 # Fix up the graph after we have found out that in view $v, 1167 # $p (a commit that we have already seen) is actually the parent 1168 # of the last commit in arc $a. 1169 proc fix_reversal {p a v} { 1170 global varcid varcstart varctok vupptr 1171 1172 set pa $varcid($v,$p) 1173 if {$p ne [lindex $varcstart($v) $pa]} { 1174 splitvarc $p $v 1175 set pa $varcid($v,$p) 1176 } 1177 # seeds always need to be renumbered 1178 if {[lindex $vupptr($v) $pa] == 0 || 1179 [string compare [lindex $varctok($v) $a] \ 1180 [lindex $varctok($v) $pa]] > 0} { 1181 renumbervarc $pa $v 1182 } 1183 } 1184 1185 proc insertrow {id p v} { 1186 global cmitlisted children parents varcid varctok vtokmod 1187 global varccommits ordertok commitidx numcommits curview 1188 global targetid targetrow vshortids 1189 1190 readcommit $id 1191 set vid $v,$id 1192 set cmitlisted($vid) 1 1193 set children($vid) {} 1194 set parents($vid) [list $p] 1195 set a [newvarc $v $id] 1196 set varcid($vid) $a 1197 lappend vshortids($v,[string range $id 0 3]) $id 1198 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] < 0} { 1199 modify_arc $v $a 1200 } 1201 lappend varccommits($v,$a) $id 1202 set vp $v,$p 1203 if {[llength [lappend children($vp) $id]] > 1} { 1204 set children($vp) [lsort -command [list vtokcmp $v] $children($vp)] 1205 unset -nocomplain ordertok 1206 } 1207 fix_reversal $p $a $v 1208 incr commitidx($v) 1209 if {$v == $curview} { 1210 set numcommits $commitidx($v) 1211 setcanvscroll 1212 if {[info exists targetid]} { 1213 if {![comes_before $targetid $p]} { 1214 incr targetrow 1215 } 1216 } 1217 } 1218 } 1219 1220 proc insertfakerow {id p} { 1221 global varcid varccommits parents children cmitlisted 1222 global commitidx varctok vtokmod targetid targetrow curview numcommits 1223 1224 set v $curview 1225 set a $varcid($v,$p) 1226 set i [lsearch -exact $varccommits($v,$a) $p] 1227 if {$i < 0} { 1228 puts "oops: insertfakerow can't find [shortids $p] on arc $a" 1229 return 1230 } 1231 set children($v,$id) {} 1232 set parents($v,$id) [list $p] 1233 set varcid($v,$id) $a 1234 lappend children($v,$p) $id 1235 set cmitlisted($v,$id) 1 1236 set numcommits [incr commitidx($v)] 1237 # note we deliberately don't update varcstart($v) even if $i == 0 1238 set varccommits($v,$a) [linsert $varccommits($v,$a) $i $id] 1239 modify_arc $v $a $i 1240 if {[info exists targetid]} { 1241 if {![comes_before $targetid $p]} { 1242 incr targetrow 1243 } 1244 } 1245 setcanvscroll 1246 drawvisible 1247 } 1248 1249 proc removefakerow {id} { 1250 global varcid varccommits parents children commitidx 1251 global varctok vtokmod cmitlisted currentid selectedline 1252 global targetid curview numcommits 1253 1254 set v $curview 1255 if {[llength $parents($v,$id)] != 1} { 1256 puts "oops: removefakerow [shortids $id] has [llength $parents($v,$id)] parents" 1257 return 1258 } 1259 set p [lindex $parents($v,$id) 0] 1260 set a $varcid($v,$id) 1261 set i [lsearch -exact $varccommits($v,$a) $id] 1262 if {$i < 0} { 1263 puts "oops: removefakerow can't find [shortids $id] on arc $a" 1264 return 1265 } 1266 unset varcid($v,$id) 1267 set varccommits($v,$a) [lreplace $varccommits($v,$a) $i $i] 1268 unset parents($v,$id) 1269 unset children($v,$id) 1270 unset cmitlisted($v,$id) 1271 set numcommits [incr commitidx($v) -1] 1272 set j [lsearch -exact $children($v,$p) $id] 1273 if {$j >= 0} { 1274 set children($v,$p) [lreplace $children($v,$p) $j $j] 1275 } 1276 modify_arc $v $a $i 1277 if {[info exist currentid] && $id eq $currentid} { 1278 unset currentid 1279 set selectedline {} 1280 } 1281 if {[info exists targetid] && $targetid eq $id} { 1282 set targetid $p 1283 } 1284 setcanvscroll 1285 drawvisible 1286 } 1287 1288 proc real_children {vp} { 1289 global children nullid nullid2 1290 1291 set kids {} 1292 foreach id $children($vp) { 1293 if {$id ne $nullid && $id ne $nullid2} { 1294 lappend kids $id 1295 } 1296 } 1297 return $kids 1298 } 1299 1300 proc first_real_child {vp} { 1301 global children nullid nullid2 1302 1303 foreach id $children($vp) { 1304 if {$id ne $nullid && $id ne $nullid2} { 1305 return $id 1306 } 1307 } 1308 return {} 1309 } 1310 1311 proc last_real_child {vp} { 1312 global children nullid nullid2 1313 1314 set kids $children($vp) 1315 for {set i [llength $kids]} {[incr i -1] >= 0} {} { 1316 set id [lindex $kids $i] 1317 if {$id ne $nullid && $id ne $nullid2} { 1318 return $id 1319 } 1320 } 1321 return {} 1322 } 1323 1324 proc vtokcmp {v a b} { 1325 global varctok varcid 1326 1327 return [string compare [lindex $varctok($v) $varcid($v,$a)] \ 1328 [lindex $varctok($v) $varcid($v,$b)]] 1329 } 1330 1331 # This assumes that if lim is not given, the caller has checked that 1332 # arc a's token is less than $vtokmod($v) 1333 proc modify_arc {v a {lim {}}} { 1334 global varctok vtokmod varcmod varcrow vupptr curview vrowmod varccommits 1335 1336 if {$lim ne {}} { 1337 set c [string compare [lindex $varctok($v) $a] $vtokmod($v)] 1338 if {$c > 0} return 1339 if {$c == 0} { 1340 set r [lindex $varcrow($v) $a] 1341 if {$r ne {} && $vrowmod($v) <= $r + $lim} return 1342 } 1343 } 1344 set vtokmod($v) [lindex $varctok($v) $a] 1345 set varcmod($v) $a 1346 if {$v == $curview} { 1347 while {$a != 0 && [lindex $varcrow($v) $a] eq {}} { 1348 set a [lindex $vupptr($v) $a] 1349 set lim {} 1350 } 1351 set r 0 1352 if {$a != 0} { 1353 if {$lim eq {}} { 1354 set lim [llength $varccommits($v,$a)] 1355 } 1356 set r [expr {[lindex $varcrow($v) $a] + $lim}] 1357 } 1358 set vrowmod($v) $r 1359 undolayout $r 1360 } 1361 } 1362 1363 proc update_arcrows {v} { 1364 global vtokmod varcmod vrowmod varcrow commitidx currentid selectedline 1365 global varcid vrownum varcorder varcix varccommits 1366 global vupptr vdownptr vleftptr varctok 1367 global displayorder parentlist curview cached_commitrow 1368 1369 if {$vrowmod($v) == $commitidx($v)} return 1370 if {$v == $curview} { 1371 if {[llength $displayorder] > $vrowmod($v)} { 1372 set displayorder [lrange $displayorder 0 [expr {$vrowmod($v) - 1}]] 1373 set parentlist [lrange $parentlist 0 [expr {$vrowmod($v) - 1}]] 1374 } 1375 unset -nocomplain cached_commitrow 1376 } 1377 set narctot [expr {[llength $varctok($v)] - 1}] 1378 set a $varcmod($v) 1379 while {$a != 0 && [lindex $varcix($v) $a] eq {}} { 1380 # go up the tree until we find something that has a row number, 1381 # or we get to a seed 1382 set a [lindex $vupptr($v) $a] 1383 } 1384 if {$a == 0} { 1385 set a [lindex $vdownptr($v) 0] 1386 if {$a == 0} return 1387 set vrownum($v) {0} 1388 set varcorder($v) [list $a] 1389 lset varcix($v) $a 0 1390 lset varcrow($v) $a 0 1391 set arcn 0 1392 set row 0 1393 } else { 1394 set arcn [lindex $varcix($v) $a] 1395 if {[llength $vrownum($v)] > $arcn + 1} { 1396 set vrownum($v) [lrange $vrownum($v) 0 $arcn] 1397 set varcorder($v) [lrange $varcorder($v) 0 $arcn] 1398 } 1399 set row [lindex $varcrow($v) $a] 1400 } 1401 while {1} { 1402 set p $a 1403 incr row [llength $varccommits($v,$a)] 1404 # go down if possible 1405 set b [lindex $vdownptr($v) $a] 1406 if {$b == 0} { 1407 # if not, go left, or go up until we can go left 1408 while {$a != 0} { 1409 set b [lindex $vleftptr($v) $a] 1410 if {$b != 0} break 1411 set a [lindex $vupptr($v) $a] 1412 } 1413 if {$a == 0} break 1414 } 1415 set a $b 1416 incr arcn 1417 lappend vrownum($v) $row 1418 lappend varcorder($v) $a 1419 lset varcix($v) $a $arcn 1420 lset varcrow($v) $a $row 1421 } 1422 set vtokmod($v) [lindex $varctok($v) $p] 1423 set varcmod($v) $p 1424 set vrowmod($v) $row 1425 if {[info exists currentid]} { 1426 set selectedline [rowofcommit $currentid] 1427 } 1428 } 1429 1430 # Test whether view $v contains commit $id 1431 proc commitinview {id v} { 1432 global varcid 1433 1434 return [info exists varcid($v,$id)] 1435 } 1436 1437 # Return the row number for commit $id in the current view 1438 proc rowofcommit {id} { 1439 global varcid varccommits varcrow curview cached_commitrow 1440 global varctok vtokmod 1441 1442 set v $curview 1443 if {![info exists varcid($v,$id)]} { 1444 puts "oops rowofcommit no arc for [shortids $id]" 1445 return {} 1446 } 1447 set a $varcid($v,$id) 1448 if {[string compare [lindex $varctok($v) $a] $vtokmod($v)] >= 0} { 1449 update_arcrows $v 1450 } 1451 if {[info exists cached_commitrow($id)]} { 1452 return $cached_commitrow($id) 1453 } 1454 set i [lsearch -exact $varccommits($v,$a) $id] 1455 if {$i < 0} { 1456 puts "oops didn't find commit [shortids $id] in arc $a" 1457 return {} 1458 } 1459 incr i [lindex $varcrow($v) $a] 1460 set cached_commitrow($id) $i 1461 return $i 1462 } 1463 1464 # Returns 1 if a is on an earlier row than b, otherwise 0 1465 proc comes_before {a b} { 1466 global varcid varctok curview 1467 1468 set v $curview 1469 if {$a eq $b || ![info exists varcid($v,$a)] || \ 1470 ![info exists varcid($v,$b)]} { 1471 return 0 1472 } 1473 if {$varcid($v,$a) != $varcid($v,$b)} { 1474 return [expr {[string compare [lindex $varctok($v) $varcid($v,$a)] \ 1475 [lindex $varctok($v) $varcid($v,$b)]] < 0}] 1476 } 1477 return [expr {[rowofcommit $a] < [rowofcommit $b]}] 1478 } 1479 1480 proc bsearch {l elt} { 1481 if {[llength $l] == 0 || $elt <= [lindex $l 0]} { 1482 return 0 1483 } 1484 set lo 0 1485 set hi [llength $l] 1486 while {$hi - $lo > 1} { 1487 set mid [expr {int(($lo + $hi) / 2)}] 1488 set t [lindex $l $mid] 1489 if {$elt < $t} { 1490 set hi $mid 1491 } elseif {$elt > $t} { 1492 set lo $mid 1493 } else { 1494 return $mid 1495 } 1496 } 1497 return $lo 1498 } 1499 1500 # Make sure rows $start..$end-1 are valid in displayorder and parentlist 1501 proc make_disporder {start end} { 1502 global vrownum curview commitidx displayorder parentlist 1503 global varccommits varcorder parents vrowmod varcrow 1504 global d_valid_start d_valid_end 1505 1506 if {$end > $vrowmod($curview)} { 1507 update_arcrows $curview 1508 } 1509 set ai [bsearch $vrownum($curview) $start] 1510 set start [lindex $vrownum($curview) $ai] 1511 set narc [llength $vrownum($curview)] 1512 for {set r $start} {$ai < $narc && $r < $end} {incr ai} { 1513 set a [lindex $varcorder($curview) $ai] 1514 set l [llength $displayorder] 1515 set al [llength $varccommits($curview,$a)] 1516 if {$l < $r + $al} { 1517 if {$l < $r} { 1518 set pad [ntimes [expr {$r - $l}] {}] 1519 set displayorder [concat $displayorder $pad] 1520 set parentlist [concat $parentlist $pad] 1521 } elseif {$l > $r} { 1522 set displayorder [lrange $displayorder 0 [expr {$r - 1}]] 1523 set parentlist [lrange $parentlist 0 [expr {$r - 1}]] 1524 } 1525 foreach id $varccommits($curview,$a) { 1526 lappend displayorder $id 1527 lappend parentlist $parents($curview,$id) 1528 } 1529 } elseif {[lindex $displayorder [expr {$r + $al - 1}]] eq {}} { 1530 set i $r 1531 foreach id $varccommits($curview,$a) { 1532 lset displayorder $i $id 1533 lset parentlist $i $parents($curview,$id) 1534 incr i 1535 } 1536 } 1537 incr r $al 1538 } 1539 } 1540 1541 proc commitonrow {row} { 1542 global displayorder 1543 1544 set id [lindex $displayorder $row] 1545 if {$id eq {}} { 1546 make_disporder $row [expr {$row + 1}] 1547 set id [lindex $displayorder $row] 1548 } 1549 return $id 1550 } 1551 1552 proc closevarcs {v} { 1553 global varctok varccommits varcid parents children 1554 global cmitlisted commitidx vtokmod curview numcommits 1555 1556 set missing_parents 0 1557 set scripts {} 1558 set narcs [llength $varctok($v)] 1559 for {set a 1} {$a < $narcs} {incr a} { 1560 set id [lindex $varccommits($v,$a) end] 1561 foreach p $parents($v,$id) { 1562 if {[info exists varcid($v,$p)]} continue 1563 # add p as a new commit 1564 incr missing_parents 1565 set cmitlisted($v,$p) 0 1566 set parents($v,$p) {} 1567 if {[llength $children($v,$p)] == 1 && 1568 [llength $parents($v,$id)] == 1} { 1569 set b $a 1570 } else { 1571 set b [newvarc $v $p] 1572 } 1573 set varcid($v,$p) $b 1574 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} { 1575 modify_arc $v $b 1576 } 1577 lappend varccommits($v,$b) $p 1578 incr commitidx($v) 1579 if {$v == $curview} { 1580 set numcommits $commitidx($v) 1581 } 1582 set scripts [check_interest $p $scripts] 1583 } 1584 } 1585 if {$missing_parents > 0} { 1586 foreach s $scripts { 1587 eval $s 1588 } 1589 } 1590 } 1591 1592 # Use $rwid as a substitute for $id, i.e. reparent $id's children to $rwid 1593 # Assumes we already have an arc for $rwid. 1594 proc rewrite_commit {v id rwid} { 1595 global children parents varcid varctok vtokmod varccommits 1596 1597 foreach ch $children($v,$id) { 1598 # make $rwid be $ch's parent in place of $id 1599 set i [lsearch -exact $parents($v,$ch) $id] 1600 if {$i < 0} { 1601 puts "oops rewrite_commit didn't find $id in parent list for $ch" 1602 } 1603 set parents($v,$ch) [lreplace $parents($v,$ch) $i $i $rwid] 1604 # add $ch to $rwid's children and sort the list if necessary 1605 if {[llength [lappend children($v,$rwid) $ch]] > 1} { 1606 set children($v,$rwid) [lsort -command [list vtokcmp $v] \ 1607 $children($v,$rwid)] 1608 } 1609 # fix the graph after joining $id to $rwid 1610 set a $varcid($v,$ch) 1611 fix_reversal $rwid $a $v 1612 # parentlist is wrong for the last element of arc $a 1613 # even if displayorder is right, hence the 3rd arg here 1614 modify_arc $v $a [expr {[llength $varccommits($v,$a)] - 1}] 1615 } 1616 } 1617 1618 # Mechanism for registering a command to be executed when we come 1619 # across a particular commit. To handle the case when only the 1620 # prefix of the commit is known, the commitinterest array is now 1621 # indexed by the first 4 characters of the ID. Each element is a 1622 # list of id, cmd pairs. 1623 proc interestedin {id cmd} { 1624 global commitinterest 1625 1626 lappend commitinterest([string range $id 0 3]) $id $cmd 1627 } 1628 1629 proc check_interest {id scripts} { 1630 global commitinterest 1631 1632 set prefix [string range $id 0 3] 1633 if {[info exists commitinterest($prefix)]} { 1634 set newlist {} 1635 foreach {i script} $commitinterest($prefix) { 1636 if {[string match "$i*" $id]} { 1637 lappend scripts [string map [list "%I" $id "%P" $i] $script] 1638 } else { 1639 lappend newlist $i $script 1640 } 1641 } 1642 if {$newlist ne {}} { 1643 set commitinterest($prefix) $newlist 1644 } else { 1645 unset commitinterest($prefix) 1646 } 1647 } 1648 return $scripts 1649 } 1650 1651 proc getcommitlines {fd inst view updating} { 1652 global cmitlisted leftover 1653 global commitidx commitdata vdatemode 1654 global parents children curview hlview 1655 global idpending ordertok 1656 global varccommits varcid varctok vtokmod vfilelimit vshortids 1657 global hashlength 1658 1659 set stuff [read $fd 500000] 1660 # git log doesn't terminate the last commit with a null... 1661 if {$stuff == {} && $leftover($inst) ne {} && [eof $fd]} { 1662 set stuff "\0" 1663 } 1664 if {$stuff == {}} { 1665 if {![eof $fd]} { 1666 return 1 1667 } 1668 global commfd viewcomplete viewactive viewname 1669 global viewinstances 1670 unset commfd($inst) 1671 set i [lsearch -exact $viewinstances($view) $inst] 1672 if {$i >= 0} { 1673 set viewinstances($view) [lreplace $viewinstances($view) $i $i] 1674 } 1675 # set it blocking so we wait for the process to terminate 1676 fconfigure $fd -blocking 1 1677 if {[catch {close $fd} err]} { 1678 set fv {} 1679 if {$view != $curview} { 1680 set fv " for the \"$viewname($view)\" view" 1681 } 1682 if {[string range $err 0 4] == "usage"} { 1683 set err "Gitk: error reading commits$fv:\ 1684 bad arguments to git log." 1685 if {$viewname($view) eq [mc "Command line"]} { 1686 append err \ 1687 " (Note: arguments to gitk are passed to git log\ 1688 to allow selection of commits to be displayed.)" 1689 } 1690 } else { 1691 set err "Error reading commits$fv: $err" 1692 } 1693 error_popup $err 1694 } 1695 if {[incr viewactive($view) -1] <= 0} { 1696 set viewcomplete($view) 1 1697 # Check if we have seen any ids listed as parents that haven't 1698 # appeared in the list 1699 closevarcs $view 1700 notbusy $view 1701 } 1702 if {$view == $curview} { 1703 run chewcommits 1704 } 1705 return 0 1706 } 1707 set start 0 1708 set gotsome 0 1709 set scripts {} 1710 while 1 { 1711 set i [string first "\0" $stuff $start] 1712 if {$i < 0} { 1713 append leftover($inst) [string range $stuff $start end] 1714 break 1715 } 1716 if {$start == 0} { 1717 set cmit $leftover($inst) 1718 append cmit [string range $stuff 0 [expr {$i - 1}]] 1719 set leftover($inst) {} 1720 } else { 1721 set cmit [string range $stuff $start [expr {$i - 1}]] 1722 } 1723 set start [expr {$i + 1}] 1724 set j [string first "\n" $cmit] 1725 set ok 0 1726 set listed 1 1727 if {$j >= 0 && [string match "commit *" $cmit]} { 1728 set ids [string range $cmit 7 [expr {$j - 1}]] 1729 if {[string match {[-^<>]*} $ids]} { 1730 switch -- [string index $ids 0] { 1731 "-" {set listed 0} 1732 "^" {set listed 2} 1733 "<" {set listed 3} 1734 ">" {set listed 4} 1735 } 1736 set ids [string range $ids 1 end] 1737 } 1738 set ok 1 1739 foreach id $ids { 1740 if {[string length $id] != $hashlength} { 1741 set ok 0 1742 break 1743 } 1744 } 1745 } 1746 if {!$ok} { 1747 set shortcmit $cmit 1748 if {[string length $shortcmit] > 80} { 1749 set shortcmit "[string range $shortcmit 0 80]..." 1750 } 1751 error_popup "[mc "Can't parse git log output:"] {$shortcmit}" 1752 exit 1 1753 } 1754 set id [lindex $ids 0] 1755 set vid $view,$id 1756 1757 lappend vshortids($view,[string range $id 0 3]) $id 1758 1759 if {!$listed && $updating && ![info exists varcid($vid)] && 1760 $vfilelimit($view) ne {}} { 1761 # git log doesn't rewrite parents for unlisted commits 1762 # when doing path limiting, so work around that here 1763 # by working out the rewritten parent with git rev-list 1764 # and if we already know about it, using the rewritten 1765 # parent as a substitute parent for $id's children. 1766 if {![catch { 1767 set rwid [safe_exec [list git rev-list --first-parent --max-count=1 \ 1768 $id -- $vfilelimit($view)]] 1769 }]} { 1770 if {$rwid ne {} && [info exists varcid($view,$rwid)]} { 1771 # use $rwid in place of $id 1772 rewrite_commit $view $id $rwid 1773 continue 1774 } 1775 } 1776 } 1777 1778 set a 0 1779 if {[info exists varcid($vid)]} { 1780 if {$cmitlisted($vid) || !$listed} continue 1781 set a $varcid($vid) 1782 } 1783 if {$listed} { 1784 set olds [lrange $ids 1 end] 1785 } else { 1786 set olds {} 1787 } 1788 set commitdata($id) [string range $cmit [expr {$j + 1}] end] 1789 set cmitlisted($vid) $listed 1790 set parents($vid) $olds 1791 if {![info exists children($vid)]} { 1792 set children($vid) {} 1793 } elseif {$a == 0 && [llength $children($vid)] == 1} { 1794 set k [lindex $children($vid) 0] 1795 if {[llength $parents($view,$k)] == 1 && 1796 (!$vdatemode($view) || 1797 $varcid($view,$k) == [llength $varctok($view)] - 1)} { 1798 set a $varcid($view,$k) 1799 } 1800 } 1801 if {$a == 0} { 1802 # new arc 1803 set a [newvarc $view $id] 1804 } 1805 if {[string compare [lindex $varctok($view) $a] $vtokmod($view)] < 0} { 1806 modify_arc $view $a 1807 } 1808 if {![info exists varcid($vid)]} { 1809 set varcid($vid) $a 1810 lappend varccommits($view,$a) $id 1811 incr commitidx($view) 1812 } 1813 1814 set i 0 1815 foreach p $olds { 1816 if {$i == 0 || [lsearch -exact $olds $p] >= $i} { 1817 set vp $view,$p 1818 if {[llength [lappend children($vp) $id]] > 1 && 1819 [vtokcmp $view [lindex $children($vp) end-1] $id] > 0} { 1820 set children($vp) [lsort -command [list vtokcmp $view] \ 1821 $children($vp)] 1822 unset -nocomplain ordertok 1823 } 1824 if {[info exists varcid($view,$p)]} { 1825 fix_reversal $p $a $view 1826 } 1827 } 1828 incr i 1829 } 1830 1831 set scripts [check_interest $id $scripts] 1832 set gotsome 1 1833 } 1834 if {$gotsome} { 1835 global numcommits hlview 1836 1837 if {$view == $curview} { 1838 set numcommits $commitidx($view) 1839 run chewcommits 1840 } 1841 if {[info exists hlview] && $view == $hlview} { 1842 # we never actually get here... 1843 run vhighlightmore 1844 } 1845 foreach s $scripts { 1846 eval $s 1847 } 1848 } 1849 return 2 1850 } 1851 1852 proc chewcommits {} { 1853 global curview hlview viewcomplete 1854 global pending_select 1855 1856 layoutmore 1857 if {$viewcomplete($curview)} { 1858 global commitidx varctok 1859 global numcommits startmsecs 1860 1861 if {[info exists pending_select]} { 1862 update 1863 reset_pending_select {} 1864 1865 if {[commitinview $pending_select $curview]} { 1866 selectline [rowofcommit $pending_select] 1 1867 } else { 1868 set row [first_real_row] 1869 selectline $row 1 1870 } 1871 } 1872 if {$commitidx($curview) > 0} { 1873 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}] 1874 #puts "overall $ms ms for $numcommits commits" 1875 #puts "[llength $varctok($view)] arcs, $commitidx($view) commits" 1876 } else { 1877 show_status [mc "No commits selected"] 1878 } 1879 notbusy layout 1880 } 1881 return 0 1882 } 1883 1884 proc do_readcommit {id} { 1885 global tclencoding 1886 1887 # Invoke git-log to handle automatic encoding conversion 1888 set fd [safe_open_command [concat git log --no-color --pretty=raw -1 $id]] 1889 # Read the results using i18n.logoutputencoding 1890 fconfigure $fd -translation lf -eofchar {} 1891 if {$tclencoding != {}} { 1892 fconfigure $fd -encoding $tclencoding 1893 } 1894 set contents [read $fd] 1895 close $fd 1896 # Remove the heading line 1897 regsub {^commit [0-9a-f]+\n} $contents {} contents 1898 1899 return $contents 1900 } 1901 1902 proc readcommit {id} { 1903 if {[catch {set contents [do_readcommit $id]}]} return 1904 parsecommit $id $contents 1 1905 } 1906 1907 proc parsecommit {id contents listed} { 1908 global commitinfo 1909 1910 set inhdr 1 1911 set comment {} 1912 set headline {} 1913 set auname {} 1914 set audate {} 1915 set comname {} 1916 set comdate {} 1917 set hdrend [string first "\n\n" $contents] 1918 if {$hdrend < 0} { 1919 # should never happen... 1920 set hdrend [string length $contents] 1921 } 1922 set header [string range $contents 0 [expr {$hdrend - 1}]] 1923 set comment [string range $contents [expr {$hdrend + 2}] end] 1924 foreach line [split $header "\n"] { 1925 set line [split $line " "] 1926 set tag [lindex $line 0] 1927 if {$tag == "author"} { 1928 set audate [lrange $line end-1 end] 1929 set auname [join [lrange $line 1 end-2] " "] 1930 } elseif {$tag == "committer"} { 1931 set comdate [lrange $line end-1 end] 1932 set comname [join [lrange $line 1 end-2] " "] 1933 } 1934 } 1935 set headline {} 1936 # take the first non-blank line of the comment as the headline 1937 set headline [string trimleft $comment] 1938 set i [string first "\n" $headline] 1939 if {$i >= 0} { 1940 set headline [string range $headline 0 $i] 1941 } 1942 set headline [string trimright $headline] 1943 set i [string first "\r" $headline] 1944 if {$i >= 0} { 1945 set headline [string trimright [string range $headline 0 $i]] 1946 } 1947 if {!$listed} { 1948 # git log indents the comment by 4 spaces; 1949 # if we got this via git cat-file, add the indentation 1950 set newcomment {} 1951 foreach line [split $comment "\n"] { 1952 append newcomment " " 1953 append newcomment $line 1954 append newcomment "\n" 1955 } 1956 set comment $newcomment 1957 } 1958 set hasnote [string first "\nNotes:\n" $contents] 1959 set diff "" 1960 # If there is diff output shown in the git-log stream, split it 1961 # out. But get rid of the empty line that always precedes the 1962 # diff. 1963 set i [string first "\n\ndiff" $comment] 1964 if {$i >= 0} { 1965 set diff [string range $comment $i+1 end] 1966 set comment [string range $comment 0 $i-1] 1967 } 1968 set commitinfo($id) [list $headline $auname $audate \ 1969 $comname $comdate $comment $hasnote $diff] 1970 } 1971 1972 proc getcommit {id} { 1973 global commitdata commitinfo 1974 1975 if {[info exists commitdata($id)]} { 1976 parsecommit $id $commitdata($id) 1 1977 } else { 1978 readcommit $id 1979 if {![info exists commitinfo($id)]} { 1980 set commitinfo($id) [list [mc "No commit information available"]] 1981 } 1982 } 1983 return 1 1984 } 1985 1986 # Expand an abbreviated commit ID to a list of full 40-char (or 64-char 1987 # for SHA256 repo) IDs that match and are present in the current view. 1988 # This is fairly slow... 1989 proc longid {prefix} { 1990 global varcid curview vshortids 1991 1992 set ids {} 1993 if {[string length $prefix] >= 4} { 1994 set vshortid $curview,[string range $prefix 0 3] 1995 if {[info exists vshortids($vshortid)]} { 1996 foreach id $vshortids($vshortid) { 1997 if {[string match "$prefix*" $id]} { 1998 if {[lsearch -exact $ids $id] < 0} { 1999 lappend ids $id 2000 if {[llength $ids] >= 2} break 2001 } 2002 } 2003 } 2004 } 2005 } else { 2006 foreach match [array names varcid "$curview,$prefix*"] { 2007 lappend ids [lindex [split $match ","] 1] 2008 if {[llength $ids] >= 2} break 2009 } 2010 } 2011 return $ids 2012 } 2013 2014 proc readrefs {} { 2015 global tagids idtags headids idheads tagobjid upstreamofref 2016 global otherrefids idotherrefs mainhead mainheadid 2017 global selecthead selectheadid 2018 global hideremotes 2019 global tclencoding 2020 global hashlength 2021 2022 foreach v {tagids idtags headids idheads otherrefids idotherrefs upstreamofref} { 2023 unset -nocomplain $v 2024 } 2025 set refd [safe_open_command [list git show-ref -d]] 2026 if {$tclencoding != {}} { 2027 fconfigure $refd -encoding $tclencoding 2028 } 2029 while {[gets $refd line] >= 0} { 2030 if {[string index $line $hashlength] ne " "} continue 2031 set id [string range $line 0 [expr {$hashlength - 1}]] 2032 set ref [string range $line [expr {$hashlength + 1}] end] 2033 if {![string match "refs/*" $ref]} continue 2034 set name [string range $ref 5 end] 2035 if {[string match "remotes/*" $name]} { 2036 if {![string match "*/HEAD" $name] && !$hideremotes} { 2037 set headids($name) $id 2038 lappend idheads($id) $name 2039 } 2040 } elseif {[string match "heads/*" $name]} { 2041 set name [string range $name 6 end] 2042 set headids($name) $id 2043 lappend idheads($id) $name 2044 } elseif {[string match "tags/*" $name]} { 2045 # this lets refs/tags/foo^{} overwrite refs/tags/foo, 2046 # which is what we want since the former is the commit ID 2047 set name [string range $name 5 end] 2048 if {[string match "*^{}" $name]} { 2049 set name [string range $name 0 end-3] 2050 } else { 2051 set tagobjid($name) $id 2052 } 2053 set tagids($name) $id 2054 lappend idtags($id) $name 2055 } else { 2056 if [is_other_ref_visible $name] { 2057 set otherrefids($name) $id 2058 lappend idotherrefs($id) $name 2059 } 2060 } 2061 } 2062 catch {close $refd} 2063 set mainhead {} 2064 set mainheadid {} 2065 catch { 2066 set mainheadid [exec git rev-parse HEAD] 2067 set thehead [exec git symbolic-ref HEAD] 2068 if {[string match "refs/heads/*" $thehead]} { 2069 set mainhead [string range $thehead 11 end] 2070 } 2071 } 2072 set selectheadid {} 2073 if {$selecthead ne {}} { 2074 catch { 2075 set selectheadid [safe_exec [list git rev-parse --verify $selecthead]] 2076 } 2077 } 2078 #load the local_branch->upstream mapping 2079 # the result of the for-each-ref command produces: local_branch NUL upstream 2080 set refd [safe_open_command [list git for-each-ref {--format=%(refname:short)%00%(upstream)} refs/heads/]] 2081 while {[gets $refd local_tracking] >= 0} { 2082 set line [split $local_tracking \0] 2083 if {[lindex $line 1] ne {}} { 2084 set upstream_ref [string map {"refs/" ""} [lindex $line 1]] 2085 set upstreamofref([lindex $line 0]) $upstream_ref 2086 } 2087 } 2088 catch {close $refd} 2089 } 2090 2091 # skip over fake commits 2092 proc first_real_row {} { 2093 global nullid nullid2 numcommits 2094 2095 for {set row 0} {$row < $numcommits} {incr row} { 2096 set id [commitonrow $row] 2097 if {$id ne $nullid && $id ne $nullid2} { 2098 break 2099 } 2100 } 2101 return $row 2102 } 2103 2104 # update things for a head moved to a child of its previous location 2105 proc movehead {id name} { 2106 global headids idheads 2107 2108 removehead $headids($name) $name 2109 set headids($name) $id 2110 lappend idheads($id) $name 2111 } 2112 2113 # update things when a head has been removed 2114 proc removehead {id name} { 2115 global headids idheads 2116 2117 if {$idheads($id) eq $name} { 2118 unset idheads($id) 2119 } else { 2120 set i [lsearch -exact $idheads($id) $name] 2121 if {$i >= 0} { 2122 set idheads($id) [lreplace $idheads($id) $i $i] 2123 } 2124 } 2125 unset headids($name) 2126 } 2127 2128 proc ttk_toplevel {w args} { 2129 eval [linsert $args 0 ::toplevel $w] 2130 place [ttk::frame $w._toplevel_background] -x 0 -y 0 -relwidth 1 -relheight 1 2131 return $w 2132 } 2133 2134 proc make_transient {window origin {geometry ""}} { 2135 wm transient $window $origin 2136 2137 if {$geometry ne ""} { 2138 after idle [list wm geometry $window $geometry] 2139 } elseif {[tk windowingsystem] eq {win32}} { 2140 # Windows fails to place transient windows normally, so 2141 # schedule a callback to center them on the parent. 2142 after idle [list tk::PlaceWindow $window widget $origin] 2143 } 2144 } 2145 2146 proc show_error {w top msg} { 2147 if {[wm state $top] eq "withdrawn"} { wm deiconify $top } 2148 message $w.m -text $msg -justify center -aspect 400 2149 pack $w.m -side top -fill x -padx 20 -pady 20 2150 ttk::button $w.ok -default active -text [mc OK] -command "destroy $top" 2151 pack $w.ok -side bottom -fill x 2152 bind $top "grab $top; focus $top" 2153 bind $top "destroy $top" 2154 bind $top "destroy $top" 2155 bind $top "destroy $top" 2156 tkwait window $top 2157 } 2158 2159 proc error_popup {msg {owner .}} { 2160 if {[tk windowingsystem] eq "win32"} { 2161 tk_messageBox -icon error -type ok -title [wm title .] \ 2162 -parent $owner -message $msg 2163 } else { 2164 set w .error 2165 ttk_toplevel $w 2166 make_transient $w $owner 2167 show_error $w $w $msg 2168 } 2169 } 2170 2171 proc confirm_popup {msg {owner .}} { 2172 global confirm_ok 2173 set confirm_ok 0 2174 set w .confirm 2175 ttk_toplevel $w 2176 make_transient $w $owner 2177 message $w.m -text $msg -justify center -aspect 400 2178 pack $w.m -side top -fill x -padx 20 -pady 20 2179 ttk::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" 2180 pack $w.ok -side left -fill x 2181 ttk::button $w.cancel -text [mc Cancel] -command "destroy $w" 2182 pack $w.cancel -side right -fill x 2183 bind $w "grab $w; focus $w" 2184 bind $w "set confirm_ok 1; destroy $w" 2185 bind $w "set confirm_ok 1; destroy $w" 2186 bind $w "destroy $w" 2187 tk::PlaceWindow $w widget $owner 2188 tkwait window $w 2189 return $confirm_ok 2190 } 2191 2192 proc haveselectionclipboard {} { 2193 return [expr {[tk windowingsystem] eq "x11"}] 2194 } 2195 2196 proc setoptions {} { 2197 if {[tk windowingsystem] ne "win32"} { 2198 option add *Panedwindow.showHandle 1 startupFile 2199 option add *Panedwindow.sashRelief raised startupFile 2200 if {[tk windowingsystem] ne "aqua"} { 2201 option add *Menu.font uifont startupFile 2202 } 2203 } else { 2204 option add *Menu.TearOff 0 startupFile 2205 } 2206 option add *Button.font uifont startupFile 2207 option add *Checkbutton.font uifont startupFile 2208 option add *Radiobutton.font uifont startupFile 2209 option add *Menubutton.font uifont startupFile 2210 option add *Label.font uifont startupFile 2211 option add *Message.font uifont startupFile 2212 option add *Entry.font textfont startupFile 2213 option add *Text.font textfont startupFile 2214 option add *Labelframe.font uifont startupFile 2215 option add *Spinbox.font textfont startupFile 2216 option add *Listbox.font mainfont startupFile 2217 } 2218 2219 proc setttkstyle {} { 2220 global theme 2221 eval font configure TkDefaultFont [fontflags mainfont] 2222 eval font configure TkTextFont [fontflags textfont] 2223 eval font configure TkHeadingFont [fontflags mainfont] 2224 eval font configure TkCaptionFont [fontflags mainfont] -weight bold 2225 eval font configure TkTooltipFont [fontflags uifont] 2226 eval font configure TkFixedFont [fontflags textfont] 2227 eval font configure TkIconFont [fontflags uifont] 2228 eval font configure TkMenuFont [fontflags uifont] 2229 eval font configure TkSmallCaptionFont [fontflags uifont] 2230 2231 if {[catch {ttk::style theme use $theme} err]} { 2232 set theme [ttk::style theme use] 2233 } 2234 } 2235 2236 # Make a menu and submenus. 2237 # m is the window name for the menu, items is the list of menu items to add. 2238 # Each item is a list {mc label type description options...} 2239 # mc is ignored; it's so we can put mc there to alert xgettext 2240 # label is the string that appears in the menu 2241 # type is cascade, command or radiobutton (should add checkbutton) 2242 # description depends on type; it's the sublist for cascade, the 2243 # command to invoke for command, or {variable value} for radiobutton 2244 proc makemenu {m items} { 2245 menu $m 2246 if {[tk windowingsystem] eq {aqua}} { 2247 set Meta1 Cmd 2248 } else { 2249 set Meta1 Ctrl 2250 } 2251 foreach i $items { 2252 set name [mc [lindex $i 1]] 2253 set type [lindex $i 2] 2254 set thing [lindex $i 3] 2255 set params [list $type] 2256 if {$name ne {}} { 2257 set u [string first "&" [string map {&& x} $name]] 2258 lappend params -label [string map {&& & & {}} $name] 2259 if {$u >= 0} { 2260 lappend params -underline $u 2261 } 2262 } 2263 switch -- $type { 2264 "cascade" { 2265 set submenu [string tolower [string map {& ""} [lindex $i 1]]] 2266 lappend params -menu $m.$submenu 2267 } 2268 "command" { 2269 lappend params -command $thing 2270 } 2271 "radiobutton" { 2272 lappend params -variable [lindex $thing 0] \ 2273 -value [lindex $thing 1] 2274 } 2275 } 2276 set tail [lrange $i 4 end] 2277 regsub -all {\yMeta1\y} $tail $Meta1 tail 2278 eval $m add $params $tail 2279 if {$type eq "cascade"} { 2280 makemenu $m.$submenu $thing 2281 } 2282 } 2283 } 2284 2285 # translate string and remove ampersands 2286 proc mca {str} { 2287 return [string map {&& & & {}} [mc $str]] 2288 } 2289 2290 proc cleardropsel {w} { 2291 $w selection clear 2292 } 2293 proc makedroplist {w varname args} { 2294 set width 0 2295 foreach label $args { 2296 set cx [string length $label] 2297 if {$cx > $width} {set width $cx} 2298 } 2299 set gm [ttk::combobox $w -width $width -state readonly\ 2300 -textvariable $varname -values $args \ 2301 -exportselection false] 2302 bind $gm <> [list $gm selection clear] 2303 return $gm 2304 } 2305 2306 proc scrollval {D {koff 0}} { 2307 global kscroll scroll_D0 2308 return [expr int(-($D / $scroll_D0) * max(1, $kscroll-$koff))] 2309 } 2310 2311 proc precisescrollval {D {koff 0}} { 2312 global kscroll 2313 return [expr (-($D / 10.0) * max(1, $kscroll-$koff))] 2314 } 2315 2316 proc bind_mousewheel {} { 2317 global canv cflist ctext 2318 bindall {allcanvs yview scroll [scrollval %D] units} 2319 bindall break 2320 bind $ctext {$ctext yview scroll [scrollval %D 2] units} 2321 bind $ctext {$ctext xview scroll [scrollval %D 2] units} 2322 bind $cflist {$cflist yview scroll [scrollval %D 2] units} 2323 bind $cflist break 2324 bind $canv {$canv xview scroll [scrollval %D] units} 2325 2326 if {[package vcompare $::tcl_version 8.7] >= 0} { 2327 bindall {allcanvs yview scroll [scrollval 5*%D] units} 2328 bindall break 2329 bind $ctext {$ctext yview scroll [scrollval 5*%D 2] units} 2330 bind $ctext {$ctext xview scroll [scrollval 5*%D 2] units} 2331 bind $cflist {$cflist yview scroll [scrollval 5*%D 2] units} 2332 bind $cflist break 2333 bind $canv {$canv xview scroll [scrollval 5*%D] units} 2334 2335 bindall { 2336 lassign [tk::PreciseScrollDeltas %D] deltaX deltaY 2337 allcanvs yview scroll [precisescrollval $deltaY] units 2338 } 2339 bind $ctext { 2340 lassign [tk::PreciseScrollDeltas %D] deltaX deltaY 2341 $ctext yview scroll [precisescrollval $deltaY 2] units 2342 $ctext xview scroll [precisescrollval $deltaX 2] units 2343 } 2344 bind $cflist { 2345 lassign [tk::PreciseScrollDeltas %D] deltaX deltaY 2346 $cflist yview scroll [precisescrollval $deltaY 2] units 2347 } 2348 bind $canv { 2349 lassign [tk::PreciseScrollDeltas %D] deltaX deltaY 2350 $canv xview scroll [precisescrollval $deltaX] units 2351 allcanvs yview scroll [precisescrollval $deltaY] units 2352 } 2353 } 2354 } 2355 2356 proc bind_mousewheel_buttons {} { 2357 global canv cflist ctext 2358 bindall {allcanvs yview scroll [scrollval 1] units} 2359 bindall {allcanvs yview scroll [scrollval -1] units} 2360 bindall break 2361 bindall break 2362 bind $ctext {$ctext yview scroll [scrollval 1 2] units} 2363 bind $ctext {$ctext yview scroll [scrollval -1 2] units} 2364 bind $ctext {$ctext xview scroll [scrollval 1 2] units} 2365 bind $ctext {$ctext xview scroll [scrollval -1 2] units} 2366 bind $cflist {$cflist yview scroll [scrollval 1 2] units} 2367 bind $cflist {$cflist yview scroll [scrollval -1 2] units} 2368 bind $cflist break 2369 bind $cflist break 2370 bind $canv {$canv xview scroll [scrollval 1] units} 2371 bind $canv {$canv xview scroll [scrollval -1] units} 2372 } 2373 2374 proc makewindow {} { 2375 global canv canv2 canv3 linespc charspc ctext cflist cscroll 2376 global tabstop 2377 global findtype findtypemenu findloc findstring fstring geometry 2378 global entries sha1entry sha1string sha1but 2379 global diffcontextstring diffcontext 2380 global ignorespace 2381 global maincursor textcursor curtextcursor 2382 global rowctxmenu fakerowmenu mergemax wrapcomment wrapdefault 2383 global highlight_files gdttype 2384 global searchstring sstring 2385 global bgcolor fgcolor bglist fglist diffcolors diffbgcolors selectbgcolor 2386 global filesepbgcolor filesepfgcolor 2387 global mergecolors foundbgcolor currentsearchhitbgcolor 2388 global headctxmenu progresscanv progressitem progresscoords statusw 2389 global fprogitem fprogcoord lastprogupdate progupdatepending 2390 global rprogitem rprogcoord rownumsel numcommits 2391 global worddiff 2392 global hashlength scroll_D0 2393 2394 # The "mc" arguments here are purely so that xgettext 2395 # sees the following string as needing to be translated 2396 set file { 2397 mc "&File" cascade { 2398 {mc "&Update" command updatecommits -accelerator F5} 2399 {mc "&Reload" command reloadcommits -accelerator Shift-F5} 2400 {mc "Reread re&ferences" command rereadrefs} 2401 {mc "&List references" command showrefs -accelerator F2} 2402 {xx "" separator} 2403 {mc "Start git &gui" command {safe_exec_redirect [list git gui] [list &]}} 2404 {xx "" separator} 2405 {mc "&Quit" command doquit -accelerator Meta1-Q} 2406 }} 2407 set edit { 2408 mc "&Edit" cascade { 2409 {mc "&Preferences" command doprefs} 2410 }} 2411 set view { 2412 mc "&View" cascade { 2413 {mc "&New view..." command {newview 0} -accelerator Shift-F4} 2414 {mc "&Edit view..." command editview -state disabled -accelerator F4} 2415 {mc "&Delete view" command delview -state disabled} 2416 {xx "" separator} 2417 {mc "&All files" radiobutton {selectedview 0} -command {showview 0}} 2418 }} 2419 if {[tk windowingsystem] ne "aqua"} { 2420 set help { 2421 mc "&Help" cascade { 2422 {mc "&About gitk" command about} 2423 {mc "&Key bindings" command keys} 2424 }} 2425 set bar [list $file $edit $view $help] 2426 } else { 2427 proc ::tk::mac::ShowPreferences {} {doprefs} 2428 proc ::tk::mac::Quit {} {doquit} 2429 lset file end [lreplace [lindex $file end] end-1 end] 2430 set apple { 2431 xx "&Apple" cascade { 2432 {mc "&About gitk" command about} 2433 {xx "" separator} 2434 }} 2435 set help { 2436 mc "&Help" cascade { 2437 {mc "&Key bindings" command keys} 2438 }} 2439 set bar [list $apple $file $view $help] 2440 } 2441 makemenu .bar $bar 2442 . configure -menu .bar 2443 2444 # cover the non-themed toplevel with a themed frame. 2445 place [ttk::frame ._main_background] -x 0 -y 0 -relwidth 1 -relheight 1 2446 2447 # the gui has upper and lower half, parts of a paned window. 2448 ttk::panedwindow .ctop -orient vertical 2449 2450 # possibly use assumed geometry 2451 if {![info exists geometry(pwsash0)]} { 2452 set geometry(topheight) [expr {15 * $linespc}] 2453 set geometry(topwidth) [expr {80 * $charspc}] 2454 set geometry(botheight) [expr {15 * $linespc}] 2455 set geometry(botwidth) [expr {50 * $charspc}] 2456 set geometry(pwsash0) [list [expr {40 * $charspc}] 2] 2457 set geometry(pwsash1) [list [expr {60 * $charspc}] 2] 2458 } 2459 2460 # the upper half will have a paned window, a scroll bar to the right, and some stuff below 2461 ttk::frame .tf -height $geometry(topheight) -width $geometry(topwidth) 2462 ttk::frame .tf.histframe 2463 ttk::panedwindow .tf.histframe.pwclist -orient horizontal 2464 2465 # create three canvases 2466 set cscroll .tf.histframe.csb 2467 set canv .tf.histframe.pwclist.canv 2468 canvas $canv \ 2469 -selectbackground $selectbgcolor \ 2470 -background $bgcolor -bd 0 \ 2471 -xscrollincr $linespc \ 2472 -yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll" \ 2473 -xscrollcommand ".tf.histframe.cxsb set" 2474 .tf.histframe.pwclist add $canv 2475 set canv2 .tf.histframe.pwclist.canv2 2476 canvas $canv2 \ 2477 -selectbackground $selectbgcolor \ 2478 -background $bgcolor -bd 0 -yscrollincr $linespc 2479 .tf.histframe.pwclist add $canv2 2480 set canv3 .tf.histframe.pwclist.canv3 2481 canvas $canv3 \ 2482 -selectbackground $selectbgcolor \ 2483 -background $bgcolor -bd 0 -yscrollincr $linespc 2484 .tf.histframe.pwclist add $canv3 2485 bind .tf.histframe.pwclist { 2486 bind %W {} 2487 .tf.histframe.pwclist sashpos 1 [lindex $::geometry(pwsash1) 0] 2488 .tf.histframe.pwclist sashpos 0 [lindex $::geometry(pwsash0) 0] 2489 } 2490 2491 # a scroll bar to rule them (vertical), and one for horizontal scroll of left pane 2492 ttk::scrollbar $cscroll -command {allcanvs yview} 2493 pack $cscroll -side right -fill y 2494 ttk::scrollbar .tf.histframe.cxsb -orient horizontal -command "$canv xview" 2495 pack .tf.histframe.cxsb -side bottom -fill x 2496 bind .tf.histframe.pwclist {resizeclistpanes %W %w} 2497 lappend bglist $canv $canv2 $canv3 2498 pack .tf.histframe.pwclist -fill both -expand 1 -side left 2499 2500 # we have two button bars at bottom of top frame. Bar 1 2501 ttk::frame .tf.bar 2502 ttk::frame .tf.lbar -height 15 2503 2504 set sha1entry .tf.bar.sha1 2505 set entries $sha1entry 2506 set sha1but .tf.bar.sha1label 2507 ttk::button $sha1but -text "[mc "Commit ID:"] " -state disabled \ 2508 -command gotocommit -width 8 2509 pack .tf.bar.sha1label -side left 2510 ttk::entry $sha1entry -width $hashlength -font textfont -textvariable sha1string 2511 trace add variable sha1string write sha1change 2512 pack $sha1entry -side left -pady 2 2513 2514 ttk::button .tf.bar.leftbut -command goback -state disabled 2515 .tf.bar.leftbut configure -text \u2190 -width 3 2516 pack .tf.bar.leftbut -side left -fill y 2517 ttk::button .tf.bar.rightbut -command goforw -state disabled 2518 .tf.bar.rightbut configure -text \u2192 -width 3 2519 pack .tf.bar.rightbut -side left -fill y 2520 2521 ttk::label .tf.bar.rowlabel -text [mc "Row"] 2522 set rownumsel {} 2523 ttk::label .tf.bar.rownum -width 7 -textvariable rownumsel \ 2524 -relief sunken -anchor e 2525 ttk::label .tf.bar.rowlabel2 -text "/" 2526 ttk::label .tf.bar.numcommits -width 7 -textvariable numcommits \ 2527 -relief sunken -anchor e 2528 pack .tf.bar.rowlabel .tf.bar.rownum .tf.bar.rowlabel2 .tf.bar.numcommits \ 2529 -side left 2530 global selectedline 2531 trace add variable selectedline write selectedline_change 2532 2533 # Status label and progress bar 2534 set statusw .tf.bar.status 2535 ttk::label $statusw -width 15 -relief sunken 2536 pack $statusw -side left -padx 5 2537 set progresscanv [ttk::progressbar .tf.bar.progress] 2538 pack $progresscanv -side right -expand 1 -fill x -padx {0 2} 2539 set progresscoords {0 0} 2540 set fprogcoord 0 2541 set rprogcoord 0 2542 bind $progresscanv adjustprogress 2543 set lastprogupdate [clock clicks -milliseconds] 2544 set progupdatepending 0 2545 2546 # build up the bottom bar of upper window 2547 ttk::label .tf.lbar.flabel -text "[mc "Find"] " 2548 2549 ttk::button .tf.lbar.fnext -command {dofind 1 1} -text \u2193 -width 3 2550 ttk::button .tf.lbar.fprev -command {dofind -1 1} -text \u2191 -width 3 2551 2552 ttk::label .tf.lbar.flab2 -text " [mc "commit"] " 2553 2554 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \ 2555 -side left -fill y 2556 set gdttype [mc "containing:"] 2557 set gm [makedroplist .tf.lbar.gdttype gdttype \ 2558 [mc "containing:"] \ 2559 [mc "touching paths:"] \ 2560 [mc "adding/removing string:"] \ 2561 [mc "changing lines matching:"]] 2562 trace add variable gdttype write gdttype_change 2563 pack .tf.lbar.gdttype -side left -fill y 2564 2565 set findstring {} 2566 set fstring .tf.lbar.findstring 2567 lappend entries $fstring 2568 ttk::entry $fstring -width 30 -textvariable findstring 2569 trace add variable findstring write find_change 2570 set findtype [mc "Exact"] 2571 set findtypemenu [makedroplist .tf.lbar.findtype \ 2572 findtype [mc "Exact"] [mc "IgnCase"] [mc "Regexp"]] 2573 trace add variable findtype write findcom_change 2574 set findloc [mc "All fields"] 2575 makedroplist .tf.lbar.findloc findloc [mc "All fields"] [mc "Headline"] \ 2576 [mc "Comments"] [mc "Author"] [mc "Committer"] 2577 trace add variable findloc write find_change 2578 pack .tf.lbar.findloc -side right 2579 pack .tf.lbar.findtype -side right 2580 pack $fstring -side left -expand 1 -fill x 2581 2582 # Finish putting the upper half of the viewer together 2583 pack .tf.lbar -in .tf -side bottom -fill x 2584 pack .tf.bar -in .tf -side bottom -fill x 2585 pack .tf.histframe -fill both -side top -expand 1 2586 .ctop add .tf 2587 2588 # now build up the bottom 2589 ttk::panedwindow .pwbottom -orient horizontal 2590 2591 # lower left, a text box over search bar, scroll bar to the right 2592 # if we know window height, then that will set the lower text height, otherwise 2593 # we set lower text height which will drive window height 2594 if {[info exists geometry(main)]} { 2595 ttk::frame .bleft -width $geometry(botwidth) 2596 } else { 2597 ttk::frame .bleft -width $geometry(botwidth) -height $geometry(botheight) 2598 } 2599 ttk::frame .bleft.top 2600 ttk::frame .bleft.mid 2601 ttk::frame .bleft.bottom 2602 2603 # gap between sub-widgets 2604 set wgap [font measure uifont "i"] 2605 2606 ttk::button .bleft.top.search -text [mc "Search"] -command dosearch 2607 pack .bleft.top.search -side left -padx 5 2608 set sstring .bleft.top.sstring 2609 set searchstring "" 2610 ttk::entry $sstring -width 20 -textvariable searchstring 2611 lappend entries $sstring 2612 trace add variable searchstring write incrsearch 2613 pack $sstring -side left -expand 1 -fill x 2614 ttk::radiobutton .bleft.mid.diff -text [mc "Diff"] \ 2615 -command changediffdisp -variable diffelide -value {0 0} 2616 ttk::radiobutton .bleft.mid.old -text [mc "Old version"] \ 2617 -command changediffdisp -variable diffelide -value {0 1} 2618 ttk::radiobutton .bleft.mid.new -text [mc "New version"] \ 2619 -command changediffdisp -variable diffelide -value {1 0} 2620 2621 ttk::label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: " 2622 pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left -ipadx $wgap 2623 ttk::spinbox .bleft.mid.diffcontext -width 5 \ 2624 -from 0 -increment 1 -to `10000000` \ 2625 -validate all -validatecommand "diffcontextvalidate %P" \ 2626 -textvariable diffcontextstring 2627 .bleft.mid.diffcontext set $diffcontext 2628 trace add variable diffcontextstring write diffcontextchange 2629 lappend entries .bleft.mid.diffcontext 2630 pack .bleft.mid.labeldiffcontext .bleft.mid.diffcontext -side left -ipadx $wgap 2631 ttk::checkbutton .bleft.mid.ignspace -text [mc "Ignore space change"] \ 2632 -command changeignorespace -variable ignorespace 2633 pack .bleft.mid.ignspace -side left -padx 5 2634 2635 set worddiff [mc "Line diff"] 2636 makedroplist .bleft.mid.worddiff worddiff [mc "Line diff"] \ 2637 [mc "Markup words"] [mc "Color words"] 2638 trace add variable worddiff write changeworddiff 2639 pack .bleft.mid.worddiff -side left -padx 5 2640 2641 set ctext .bleft.bottom.ctext 2642 text $ctext -background $bgcolor -foreground $fgcolor \ 2643 -state disabled -undo 0 -font textfont \ 2644 -yscrollcommand scrolltext -wrap $wrapdefault \ 2645 -xscrollcommand ".bleft.bottom.sbhorizontal set" 2646 $ctext conf -tabstyle wordprocessor 2647 ttk::scrollbar .bleft.bottom.sb -command "$ctext yview" 2648 ttk::scrollbar .bleft.bottom.sbhorizontal -command "$ctext xview" -orient h 2649 pack .bleft.top -side top -fill x 2650 pack .bleft.mid -side top -fill x 2651 grid $ctext .bleft.bottom.sb -sticky nsew 2652 grid .bleft.bottom.sbhorizontal -sticky ew 2653 grid columnconfigure .bleft.bottom 0 -weight 1 2654 grid rowconfigure .bleft.bottom 0 -weight 1 2655 grid rowconfigure .bleft.bottom 1 -weight 0 2656 pack .bleft.bottom -side top -fill both -expand 1 2657 lappend bglist $ctext 2658 lappend fglist $ctext 2659 2660 $ctext tag conf comment -wrap $wrapcomment 2661 $ctext tag conf filesep -font textfontbold -fore $filesepfgcolor -back $filesepbgcolor 2662 $ctext tag conf hunksep -fore [lindex $diffcolors 2] 2663 $ctext tag conf d0 -fore [lindex $diffcolors 0] 2664 $ctext tag conf d0 -back [lindex $diffbgcolors 0] 2665 $ctext tag conf dresult -fore [lindex $diffcolors 1] 2666 $ctext tag conf dresult -back [lindex $diffbgcolors 1] 2667 $ctext tag conf m0 -fore [lindex $mergecolors 0] 2668 $ctext tag conf m1 -fore [lindex $mergecolors 1] 2669 $ctext tag conf m2 -fore [lindex $mergecolors 2] 2670 $ctext tag conf m3 -fore [lindex $mergecolors 3] 2671 $ctext tag conf m4 -fore [lindex $mergecolors 4] 2672 $ctext tag conf m5 -fore [lindex $mergecolors 5] 2673 $ctext tag conf m6 -fore [lindex $mergecolors 6] 2674 $ctext tag conf m7 -fore [lindex $mergecolors 7] 2675 $ctext tag conf m8 -fore [lindex $mergecolors 8] 2676 $ctext tag conf m9 -fore [lindex $mergecolors 9] 2677 $ctext tag conf m10 -fore [lindex $mergecolors 10] 2678 $ctext tag conf m11 -fore [lindex $mergecolors 11] 2679 $ctext tag conf m12 -fore [lindex $mergecolors 12] 2680 $ctext tag conf m13 -fore [lindex $mergecolors 13] 2681 $ctext tag conf m14 -fore [lindex $mergecolors 14] 2682 $ctext tag conf m15 -fore [lindex $mergecolors 15] 2683 $ctext tag conf mmax -fore darkgrey 2684 set mergemax 16 2685 $ctext tag conf mresult -font textfontbold 2686 $ctext tag conf msep -font textfontbold 2687 $ctext tag conf found -back $foundbgcolor 2688 $ctext tag conf currentsearchhit -back $currentsearchhitbgcolor 2689 $ctext tag conf wwrap -wrap word -lmargin2 1c 2690 $ctext tag conf bold -font textfontbold 2691 # set these to the lowest priority: 2692 $ctext tag lower currentsearchhit 2693 $ctext tag lower found 2694 $ctext tag lower filesep 2695 $ctext tag lower dresult 2696 $ctext tag lower d0 2697 2698 .pwbottom add .bleft 2699 2700 # lower right 2701 ttk::frame .bright 2702 ttk::frame .bright.mode 2703 ttk::radiobutton .bright.mode.patch -text [mc "Patch"] \ 2704 -command reselectline -variable cmitmode -value "patch" 2705 ttk::radiobutton .bright.mode.tree -text [mc "Tree"] \ 2706 -command reselectline -variable cmitmode -value "tree" 2707 grid .bright.mode.patch .bright.mode.tree -sticky ew 2708 pack .bright.mode -side top -fill x 2709 set cflist .bright.cfiles 2710 set indent [font measure mainfont "nn"] 2711 text $cflist \ 2712 -selectbackground $selectbgcolor \ 2713 -background $bgcolor -foreground $fgcolor \ 2714 -font mainfont \ 2715 -tabs [list $indent [expr {2 * $indent}]] \ 2716 -yscrollcommand ".bright.sb set" \ 2717 -cursor [. cget -cursor] \ 2718 -spacing1 1 -spacing3 1 2719 lappend bglist $cflist 2720 lappend fglist $cflist 2721 ttk::scrollbar .bright.sb -command "$cflist yview" 2722 pack .bright.sb -side right -fill y 2723 pack $cflist -side left -fill both -expand 1 2724 $cflist tag configure highlight \ 2725 -background [$cflist cget -selectbackground] 2726 $cflist tag configure bold -font mainfontbold 2727 2728 .pwbottom add .bright 2729 .ctop add .pwbottom 2730 2731 # restore window position if known 2732 if {[info exists geometry(main)]} { 2733 wm geometry . "$geometry(main)" 2734 } 2735 2736 if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} { 2737 wm state . $geometry(state) 2738 } 2739 2740 if {[tk windowingsystem] eq {aqua}} { 2741 set M1B M1 2742 set ::BM "3" 2743 } else { 2744 set M1B Control 2745 set ::BM "2" 2746 } 2747 2748 bind .ctop { 2749 bind %W {} 2750 %W sashpos 0 $::geometry(topheight) 2751 } 2752 bind .pwbottom { 2753 bind %W {} 2754 %W sashpos 0 $::geometry(botwidth) 2755 } 2756 bind .pwbottom {resizecdetpanes %W %w} 2757 2758 pack .ctop -fill both -expand 1 2759 bindall <1> {selcanvline %W %x %y} 2760 2761 #Mouse / touchpad scrolling 2762 if {[tk windowingsystem] == "win32" || [package vcompare $::tcl_version 8.7] >= 0} { 2763 set scroll_D0 120 2764 bind_mousewheel 2765 } elseif {[tk windowingsystem] == "x11"} { 2766 set scroll_D0 1 2767 bind_mousewheel_buttons 2768 } elseif {[tk windowingsystem] == "aqua"} { 2769 set scroll_D0 1 2770 bind_mousewheel 2771 } else { 2772 puts stderr [mc "Unknown windowing system, cannot bind mouse"] 2773 } 2774 bindall <$::BM> "canvscan mark %W %x %y" 2775 bindall "canvscan dragto %W %x %y" 2776 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]} 2777 bind . <$M1B-Key-w> doquit 2778 bindkey selfirstline 2779 bindkey sellastline 2780 bind . "selnextline -1" 2781 bind . "selnextline 1" 2782 bind . "dofind -1 0" 2783 bind . "dofind 1 0" 2784 bindkey <> "goforw" 2785 bindkey <> "goback" 2786 bind . "selnextpage -1" 2787 bind . "selnextpage 1" 2788 bind . <$M1B-Home> "allcanvs yview moveto 0.0" 2789 bind . <$M1B-End> "allcanvs yview moveto 1.0" 2790 bind . <$M1B-Key-Up> "allcanvs yview scroll -1 units" 2791 bind . <$M1B-Key-Down> "allcanvs yview scroll 1 units" 2792 bind . <$M1B-Key-Prior> "allcanvs yview scroll -1 pages" 2793 bind . <$M1B-Key-Next> "allcanvs yview scroll 1 pages" 2794 bindkey "$ctext yview scroll -1 pages" 2795 bindkey "$ctext yview scroll -1 pages" 2796 bindkey "$ctext yview scroll 1 pages" 2797 bindkey p "selnextline -1" 2798 bindkey n "selnextline 1" 2799 bindkey z "goback" 2800 bindkey x "goforw" 2801 bindkey k "selnextline -1" 2802 bindkey j "selnextline 1" 2803 bindkey h "goback" 2804 bindkey l "goforw" 2805 bindkey b prevfile 2806 bindkey d "$ctext yview scroll 18 units" 2807 bindkey u "$ctext yview scroll -18 units" 2808 bindkey g {$sha1entry delete 0 end; focus $sha1entry} 2809 bindkey / {focus $fstring} 2810 bindkey {focus $fstring} 2811 bindkey {dofind 1 1} 2812 bindkey ? {dofind -1 1} 2813 bindkey f nextfile 2814 bind . updatecommits 2815 bindmodfunctionkey Shift 5 reloadcommits 2816 bind . showrefs 2817 bindmodfunctionkey Shift 4 {newview 0} 2818 bind . edit_or_newview 2819 bind . <$M1B-q> doquit 2820 bind . <$M1B-f> {dofind 1 1} 2821 bind . <$M1B-g> {dofind 1 0} 2822 bind . <$M1B-r> dosearchback 2823 bind . <$M1B-s> dosearch 2824 bind . <$M1B-equal> {incrfont 1} 2825 bind . <$M1B-plus> {incrfont 1} 2826 bind . <$M1B-KP_Add> {incrfont 1} 2827 bind . <$M1B-minus> {incrfont -1} 2828 bind . <$M1B-KP_Subtract> {incrfont -1} 2829 wm protocol . WM_DELETE_WINDOW doquit 2830 bind . {stop_backends} 2831 bind . "click %W" 2832 bind $fstring {dofind 1 1} 2833 bind $sha1entry {gotocommit; break} 2834 bind $sha1entry <> clearsha1 2835 bind $sha1entry <> clearsha1 2836 bind $cflist <1> {sel_flist %W %x %y; break} 2837 bind $cflist {sel_flist %W %x %y; break} 2838 bind $cflist {treeclick %W %x %y} 2839 global ctxbut 2840 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y} 2841 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y} 2842 bind $ctext {focus %W} 2843 bind $ctext <> rehighlight_search_results 2844 for {set i 1} {$i < 10} {incr i} { 2845 bind . <$M1B-Key-$i> [list go_to_parent $i] 2846 } 2847 2848 set maincursor [. cget -cursor] 2849 set textcursor [$ctext cget -cursor] 2850 set curtextcursor $textcursor 2851 2852 set rowctxmenu .rowctxmenu 2853 makemenu $rowctxmenu { 2854 {mc "Diff this -> selected" command {diffvssel 0}} 2855 {mc "Diff selected -> this" command {diffvssel 1}} 2856 {mc "Make patch" command mkpatch} 2857 {mc "Create tag" command mktag} 2858 {mc "Copy commit reference" command copyreference} 2859 {mc "Write commit to file" command writecommit} 2860 {mc "Create new branch" command mkbranch} 2861 {mc "Cherry-pick this commit" command cherrypick} 2862 {mc "Reset HEAD branch to here" command resethead} 2863 {mc "Mark this commit" command markhere} 2864 {mc "Return to mark" command gotomark} 2865 {mc "Find descendant of this and mark" command find_common_desc} 2866 {mc "Compare with marked commit" command compare_commits} 2867 {mc "Diff this -> marked commit" command {diffvsmark 0}} 2868 {mc "Diff marked commit -> this" command {diffvsmark 1}} 2869 {mc "Revert this commit" command revert} 2870 } 2871 $rowctxmenu configure -tearoff 0 2872 2873 set fakerowmenu .fakerowmenu 2874 makemenu $fakerowmenu { 2875 {mc "Diff this -> selected" command {diffvssel 0}} 2876 {mc "Diff selected -> this" command {diffvssel 1}} 2877 {mc "Make patch" command mkpatch} 2878 {mc "Diff this -> marked commit" command {diffvsmark 0}} 2879 {mc "Diff marked commit -> this" command {diffvsmark 1}} 2880 } 2881 $fakerowmenu configure -tearoff 0 2882 2883 set headctxmenu .headctxmenu 2884 makemenu $headctxmenu { 2885 {mc "Check out this branch" command cobranch} 2886 {mc "Rename this branch" command mvbranch} 2887 {mc "Remove this branch" command rmbranch} 2888 {mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}} 2889 } 2890 $headctxmenu configure -tearoff 0 2891 2892 global flist_menu 2893 set flist_menu .flistctxmenu 2894 makemenu $flist_menu { 2895 {mc "Highlight this too" command {flist_hl 0}} 2896 {mc "Highlight this only" command {flist_hl 1}} 2897 {mc "External diff" command {external_diff}} 2898 {mc "Blame parent commit" command {external_blame 1}} 2899 {mc "Copy path" command {clipboard clear; clipboard append $flist_menu_file}} 2900 } 2901 $flist_menu configure -tearoff 0 2902 2903 global diff_menu 2904 set diff_menu .diffctxmenu 2905 makemenu $diff_menu { 2906 {mc "Show origin of this line" command show_line_source} 2907 {mc "Run git gui blame on this line" command {external_blame_diff}} 2908 } 2909 $diff_menu configure -tearoff 0 2910 } 2911 2912 # Update row number label when selectedline changes 2913 proc selectedline_change {n1 n2 op} { 2914 global selectedline rownumsel 2915 2916 if {$selectedline eq {}} { 2917 set rownumsel {} 2918 } else { 2919 set rownumsel [expr {$selectedline + 1}] 2920 } 2921 } 2922 2923 # mouse-2 makes all windows scan vertically, but only the one 2924 # the cursor is in scans horizontally 2925 proc canvscan {op w x y} { 2926 global canv canv2 canv3 2927 foreach c [list $canv $canv2 $canv3] { 2928 if {$c == $w} { 2929 $c scan $op $x $y 2930 } else { 2931 $c scan $op 0 $y 2932 } 2933 } 2934 } 2935 2936 proc scrollcanv {cscroll f0 f1} { 2937 $cscroll set $f0 $f1 2938 drawvisible 2939 flushhighlights 2940 } 2941 2942 # when we make a key binding for the toplevel, make sure 2943 # it doesn't get triggered when that key is pressed in the 2944 # find string entry widget. 2945 proc bindkey {ev script} { 2946 global entries 2947 bind . $ev $script 2948 set escript [bind Entry $ev] 2949 if {$escript == {}} { 2950 set escript [bind Entry ] 2951 } 2952 foreach e $entries { 2953 bind $e $ev "$escript; break" 2954 } 2955 } 2956 2957 proc bindmodfunctionkey {mod n script} { 2958 bind . <$mod-F$n> $script 2959 catch { bind . <$mod-XF86_Switch_VT_$n> $script } 2960 } 2961 2962 # set the focus back to the toplevel for any click outside 2963 # the entry widgets 2964 proc click {w} { 2965 global ctext entries 2966 foreach e [concat $entries $ctext] { 2967 if {$w == $e} return 2968 } 2969 focus . 2970 } 2971 2972 # Adjust the progress bar for a change in requested extent or canvas size 2973 proc adjustprogress {} { 2974 global progresscanv 2975 global fprogcoord 2976 2977 $progresscanv configure -value [expr {int($fprogcoord * 100)}] 2978 } 2979 2980 proc doprogupdate {} { 2981 global lastprogupdate progupdatepending 2982 2983 if {$progupdatepending} { 2984 set progupdatepending 0 2985 set lastprogupdate [clock clicks -milliseconds] 2986 update 2987 } 2988 } 2989 2990 proc config_check_tmp_exists {tries_left} { 2991 global config_file_tmp 2992 2993 if {[file exists $config_file_tmp]} { 2994 incr tries_left -1 2995 if {$tries_left > 0} { 2996 after 100 [list config_check_tmp_exists $tries_left] 2997 } else { 2998 error_popup "There appears to be a stale $config_file_tmp\ 2999 file, which will prevent gitk from saving its configuration on exit.\ 3000 Please remove it if it is not being used by any existing gitk process." 3001 } 3002 } 3003 } 3004 3005 proc config_init_trace {name} { 3006 global config_variable_changed config_variable_original 3007 3008 upvar #0 $name var 3009 set config_variable_changed($name) 0 3010 set config_variable_original($name) $var 3011 } 3012 3013 proc config_variable_change_cb {name name2 op} { 3014 global config_variable_changed config_variable_original 3015 3016 upvar #0 $name var 3017 if {$op eq "write" && 3018 (![info exists config_variable_original($name)] || 3019 $config_variable_original($name) ne $var)} { 3020 set config_variable_changed($name) 1 3021 } 3022 } 3023 3024 proc savestuff {w} { 3025 global stuffsaved 3026 global config_file config_file_tmp 3027 global config_variables config_variable_changed 3028 global viewchanged 3029 3030 upvar #0 viewname current_viewname 3031 upvar #0 viewfiles current_viewfiles 3032 upvar #0 viewargs current_viewargs 3033 upvar #0 viewargscmd current_viewargscmd 3034 upvar #0 viewperm current_viewperm 3035 upvar #0 nextviewnum current_nextviewnum 3036 3037 if {$stuffsaved} return 3038 if {![winfo viewable .]} return 3039 set remove_tmp 0 3040 if {[catch { 3041 set try_count 0 3042 while {[catch {set f [safe_open_file $config_file_tmp {WRONLY CREAT EXCL}]}]} { 3043 if {[incr try_count] > 50} { 3044 error "Unable to write config file: $config_file_tmp exists" 3045 } 3046 after 100 3047 } 3048 set remove_tmp 1 3049 if {$::tcl_platform(platform) eq {windows}} { 3050 file attributes $config_file_tmp -hidden true 3051 } 3052 if {[file exists $config_file]} { 3053 source $config_file 3054 } 3055 foreach var_name $config_variables { 3056 upvar #0 $var_name var 3057 upvar 0 $var_name old_var 3058 if {!$config_variable_changed($var_name) && [info exists old_var]} { 3059 puts $f [list set $var_name $old_var] 3060 } else { 3061 puts $f [list set $var_name $var] 3062 } 3063 } 3064 3065 puts $f "set geometry(main) [wm geometry .]" 3066 puts $f "set geometry(state) [wm state .]" 3067 puts $f "set geometry(topwidth) [winfo width .tf]" 3068 puts $f "set geometry(topheight) [winfo height .tf]" 3069 puts $f "set geometry(pwsash0) \"[.tf.histframe.pwclist sashpos 0] 1\"" 3070 puts $f "set geometry(pwsash1) \"[.tf.histframe.pwclist sashpos 1] 1\"" 3071 puts $f "set geometry(botwidth) [winfo width .bleft]" 3072 puts $f "set geometry(botheight) [winfo height .bleft]" 3073 unset -nocomplain geometry 3074 global geometry 3075 if {[info exists geometry(showrefs)]} { 3076 puts $f "set geometry(showrefs) $geometry(showrefs)" 3077 } 3078 3079 array set view_save {} 3080 array set views {} 3081 if {![info exists permviews]} { set permviews {} } 3082 foreach view $permviews { 3083 set view_save([lindex $view 0]) 1 3084 set views([lindex $view 0]) $view 3085 } 3086 puts -nonewline $f "set permviews {" 3087 for {set v 1} {$v < $current_nextviewnum} {incr v} { 3088 if {$viewchanged($v)} { 3089 if {$current_viewperm($v)} { 3090 set views($current_viewname($v)) [list $current_viewname($v) $current_viewfiles($v) $current_viewargs($v) $current_viewargscmd($v)] 3091 } else { 3092 set view_save($current_viewname($v)) 0 3093 } 3094 } 3095 } 3096 # write old and updated view to their places and append remaining to the end 3097 foreach view $permviews { 3098 set view_name [lindex $view 0] 3099 if {$view_save($view_name)} { 3100 puts $f "{$views($view_name)}" 3101 } 3102 unset views($view_name) 3103 } 3104 foreach view_name [array names views] { 3105 puts $f "{$views($view_name)}" 3106 } 3107 puts $f "}" 3108 close $f 3109 file rename -force $config_file_tmp $config_file 3110 set remove_tmp 0 3111 } err]} { 3112 puts "Error saving config: $err" 3113 } 3114 if {$remove_tmp} { 3115 file delete -force $config_file_tmp 3116 } 3117 set stuffsaved 1 3118 } 3119 3120 proc resizeclistpanes {win w} { 3121 global oldwidth oldsash 3122 if {[info exists oldwidth($win)]} { 3123 if {[info exists oldsash($win)]} { 3124 set s0 [lindex $oldsash($win) 0] 3125 set s1 [lindex $oldsash($win) 1] 3126 } else { 3127 set s0 [$win sashpos 0] 3128 set s1 [$win sashpos 1] 3129 } 3130 if {$w < 60} { 3131 set sash0 [expr {int($w/2 - 2)}] 3132 set sash1 [expr {int($w*5/6 - 2)}] 3133 } else { 3134 set factor [expr {1.0 * $w / $oldwidth($win)}] 3135 set sash0 [expr {int($factor * [lindex $s0 0])}] 3136 set sash1 [expr {int($factor * [lindex $s1 0])}] 3137 if {$sash0 < 30} { 3138 set sash0 30 3139 } 3140 if {$sash1 < $sash0 + 20} { 3141 set sash1 [expr {$sash0 + 20}] 3142 } 3143 if {$sash1 > $w - 10} { 3144 set sash1 [expr {$w - 10}] 3145 if {$sash0 > $sash1 - 20} { 3146 set sash0 [expr {$sash1 - 20}] 3147 } 3148 } 3149 } 3150 $win sashpos 0 $sash0 3151 $win sashpos 1 $sash1 3152 set oldsash($win) [list $sash0 $sash1] 3153 } 3154 set oldwidth($win) $w 3155 } 3156 3157 proc resizecdetpanes {win w} { 3158 global oldwidth oldsash 3159 if {[info exists oldwidth($win)]} { 3160 if {[info exists oldsash($win)]} { 3161 set s0 $oldsash($win) 3162 } else { 3163 set s0 [$win sashpos 0] 3164 } 3165 if {$w < 60} { 3166 set sash0 [expr {int($w*3/4 - 2)}] 3167 } else { 3168 set factor [expr {1.0 * $w / $oldwidth($win)}] 3169 set sash0 [expr {int($factor * [lindex $s0 0])}] 3170 if {$sash0 < 45} { 3171 set sash0 45 3172 } 3173 if {$sash0 > $w - 15} { 3174 set sash0 [expr {$w - 15}] 3175 } 3176 } 3177 $win sashpos 0 $sash0 3178 set oldsash($win) $sash0 3179 } 3180 set oldwidth($win) $w 3181 } 3182 3183 proc allcanvs args { 3184 global canv canv2 canv3 3185 eval $canv $args 3186 eval $canv2 $args 3187 eval $canv3 $args 3188 } 3189 3190 proc bindall {event action} { 3191 global canv canv2 canv3 3192 bind $canv $event $action 3193 bind $canv2 $event $action 3194 bind $canv3 $event $action 3195 } 3196 3197 proc about {} { 3198 global bgcolor 3199 set w .about 3200 if {[winfo exists $w]} { 3201 raise $w 3202 return 3203 } 3204 ttk_toplevel $w 3205 wm title $w [mc "About gitk"] 3206 make_transient $w . 3207 message $w.m -text [mc " 3208 Gitk - a commit viewer for git 3209 3210 Copyright \u00a9 2005-2016 Paul Mackerras 3211 3212 Use and redistribute under the terms of the GNU General Public License"] \ 3213 -justify center -aspect 400 -border 2 -bg $bgcolor -relief groove 3214 pack $w.m -side top -fill x -padx 2 -pady 2 3215 ttk::button $w.ok -text [mc "Close"] -command "destroy $w" -default active 3216 pack $w.ok -side bottom 3217 bind $w "focus $w.ok" 3218 bind $w "destroy $w" 3219 bind $w "destroy $w" 3220 tk::PlaceWindow $w widget . 3221 } 3222 3223 proc keys {} { 3224 global bgcolor 3225 set w .keys 3226 if {[winfo exists $w]} { 3227 raise $w 3228 return 3229 } 3230 if {[tk windowingsystem] eq {aqua}} { 3231 set M1T Cmd 3232 } else { 3233 set M1T Ctrl 3234 } 3235 ttk_toplevel $w 3236 wm title $w [mc "Gitk key bindings"] 3237 make_transient $w . 3238 message $w.m -text " 3239 [mc "Gitk key bindings:"] 3240 3241 [mc "<%s-Q> Quit" $M1T] 3242 [mc "<%s-W> Close window" $M1T] 3243 [mc " Move to first commit"] 3244 [mc " Move to last commit"] 3245 [mc ", p, k Move up one commit"] 3246 [mc ", n, j Move down one commit"] 3247 [mc ", z, h Go back in history list"] 3248 [mc ", x, l Go forward in history list"] 3249 [mc "<%s-n> Go to n-th parent of current commit in history list" $M1T] 3250 [mc " Move up one page in commit list"] 3251 [mc " Move down one page in commit list"] 3252 [mc "<%s-Home> Scroll to top of commit list" $M1T] 3253 [mc "<%s-End> Scroll to bottom of commit list" $M1T] 3254 [mc "<%s-Up> Scroll commit list up one line" $M1T] 3255 [mc "<%s-Down> Scroll commit list down one line" $M1T] 3256 [mc "<%s-PageUp> Scroll commit list up one page" $M1T] 3257 [mc "<%s-PageDown> Scroll commit list down one page" $M1T] 3258 [mc " Find backwards (upwards, later commits)"] 3259 [mc " Find forwards (downwards, earlier commits)"] 3260 [mc ", b Scroll diff view up one page"] 3261 [mc " Scroll diff view up one page"] 3262 [mc " Scroll diff view down one page"] 3263 [mc "u Scroll diff view up 18 lines"] 3264 [mc "d Scroll diff view down 18 lines"] 3265 [mc "<%s-F> Find" $M1T] 3266 [mc "<%s-G> Move to next find hit" $M1T] 3267 [mc " Move to next find hit"] 3268 [mc "g Go to commit"] 3269 [mc "/ Focus the search box"] 3270 [mc "? Move to previous find hit"] 3271 [mc "f Scroll diff view to next file"] 3272 [mc "<%s-S> Search for next hit in diff view" $M1T] 3273 [mc "<%s-R> Search for previous hit in diff view" $M1T] 3274 [mc "<%s-KP+> Increase font size" $M1T] 3275 [mc "<%s-plus> Increase font size" $M1T] 3276 [mc "<%s-KP-> Decrease font size" $M1T] 3277 [mc "<%s-minus> Decrease font size" $M1T] 3278 [mc " Update"] 3279 " \ 3280 -justify left -bg $bgcolor -border 2 -relief groove 3281 pack $w.m -side top -fill both -padx 2 -pady 2 3282 ttk::button $w.ok -text [mc "Close"] -command "destroy $w" -default active 3283 bind $w [list destroy $w] 3284 pack $w.ok -side bottom 3285 bind $w "focus $w.ok" 3286 bind $w "destroy $w" 3287 bind $w "destroy $w" 3288 } 3289 3290 # Procedures for manipulating the file list window at the 3291 # bottom right of the overall window. 3292 3293 proc treeview {w l openlevs} { 3294 global treecontents treediropen treeheight treeparent treeindex 3295 3296 set ix 0 3297 set treeindex() 0 3298 set lev 0 3299 set prefix {} 3300 set prefixend -1 3301 set prefendstack {} 3302 set htstack {} 3303 set ht 0 3304 set treecontents() {} 3305 $w conf -state normal 3306 foreach f $l { 3307 while {[string range $f 0 $prefixend] ne $prefix} { 3308 if {$lev <= $openlevs} { 3309 $w mark set e:$treeindex($prefix) "end -1c" 3310 $w mark gravity e:$treeindex($prefix) left 3311 } 3312 set treeheight($prefix) $ht 3313 incr ht [lindex $htstack end] 3314 set htstack [lreplace $htstack end end] 3315 set prefixend [lindex $prefendstack end] 3316 set prefendstack [lreplace $prefendstack end end] 3317 set prefix [string range $prefix 0 $prefixend] 3318 incr lev -1 3319 } 3320 set tail [string range $f [expr {$prefixend+1}] end] 3321 while {[set slash [string first "/" $tail]] >= 0} { 3322 lappend htstack $ht 3323 set ht 0 3324 lappend prefendstack $prefixend 3325 incr prefixend [expr {$slash + 1}] 3326 set d [string range $tail 0 $slash] 3327 lappend treecontents($prefix) $d 3328 set oldprefix $prefix 3329 append prefix $d 3330 set treecontents($prefix) {} 3331 set treeindex($prefix) [incr ix] 3332 set treeparent($prefix) $oldprefix 3333 set tail [string range $tail [expr {$slash+1}] end] 3334 if {$lev <= $openlevs} { 3335 set ht 1 3336 set treediropen($prefix) [expr {$lev < $openlevs}] 3337 set bm [expr {$lev == $openlevs? "tri-rt": "tri-dn"}] 3338 $w mark set d:$ix "end -1c" 3339 $w mark gravity d:$ix left 3340 set str "\n" 3341 for {set i 0} {$i < $lev} {incr i} {append str "\t"} 3342 $w insert end $str 3343 $w image create end -align center -image $bm -padx 1 \ 3344 -name a:$ix 3345 $w insert end $d [highlight_tag $prefix] 3346 $w mark set s:$ix "end -1c" 3347 $w mark gravity s:$ix left 3348 } 3349 incr lev 3350 } 3351 if {$tail ne {}} { 3352 if {$lev <= $openlevs} { 3353 incr ht 3354 set str "\n" 3355 for {set i 0} {$i < $lev} {incr i} {append str "\t"} 3356 $w insert end $str 3357 $w insert end $tail [highlight_tag $f] 3358 } 3359 lappend treecontents($prefix) $tail 3360 } 3361 } 3362 while {$htstack ne {}} { 3363 set treeheight($prefix) $ht 3364 incr ht [lindex $htstack end] 3365 set htstack [lreplace $htstack end end] 3366 set prefixend [lindex $prefendstack end] 3367 set prefendstack [lreplace $prefendstack end end] 3368 set prefix [string range $prefix 0 $prefixend] 3369 } 3370 $w conf -state disabled 3371 } 3372 3373 proc linetoelt {l} { 3374 global treeheight treecontents 3375 3376 set y 2 3377 set prefix {} 3378 while {1} { 3379 foreach e $treecontents($prefix) { 3380 if {$y == $l} { 3381 return "$prefix$e" 3382 } 3383 set n 1 3384 if {[string index $e end] eq "/"} { 3385 set n $treeheight($prefix$e) 3386 if {$y + $n > $l} { 3387 append prefix $e 3388 incr y 3389 break 3390 } 3391 } 3392 incr y $n 3393 } 3394 } 3395 } 3396 3397 proc highlight_tree {y prefix} { 3398 global treeheight treecontents cflist 3399 3400 foreach e $treecontents($prefix) { 3401 set path $prefix$e 3402 if {[highlight_tag $path] ne {}} { 3403 $cflist tag add bold $y.0 "$y.0 lineend" 3404 } 3405 incr y 3406 if {[string index $e end] eq "/" && $treeheight($path) > 1} { 3407 set y [highlight_tree $y $path] 3408 } 3409 } 3410 return $y 3411 } 3412 3413 proc treeclosedir {w dir} { 3414 global treediropen treeheight treeparent treeindex 3415 3416 set ix $treeindex($dir) 3417 $w conf -state normal 3418 $w delete s:$ix e:$ix 3419 set treediropen($dir) 0 3420 $w image configure a:$ix -image tri-rt 3421 $w conf -state disabled 3422 set n [expr {1 - $treeheight($dir)}] 3423 while {$dir ne {}} { 3424 incr treeheight($dir) $n 3425 set dir $treeparent($dir) 3426 } 3427 } 3428 3429 proc treeopendir {w dir} { 3430 global treediropen treeheight treeparent treecontents treeindex 3431 3432 set ix $treeindex($dir) 3433 $w conf -state normal 3434 $w image configure a:$ix -image tri-dn 3435 $w mark set e:$ix s:$ix 3436 $w mark gravity e:$ix right 3437 set lev 0 3438 set str "\n" 3439 set n [llength $treecontents($dir)] 3440 for {set x $dir} {$x ne {}} {set x $treeparent($x)} { 3441 incr lev 3442 append str "\t" 3443 incr treeheight($x) $n 3444 } 3445 foreach e $treecontents($dir) { 3446 set de $dir$e 3447 if {[string index $e end] eq "/"} { 3448 set iy $treeindex($de) 3449 $w mark set d:$iy e:$ix 3450 $w mark gravity d:$iy left 3451 $w insert e:$ix $str 3452 set treediropen($de) 0 3453 $w image create e:$ix -align center -image tri-rt -padx 1 \ 3454 -name a:$iy 3455 $w insert e:$ix $e [highlight_tag $de] 3456 $w mark set s:$iy e:$ix 3457 $w mark gravity s:$iy left 3458 set treeheight($de) 1 3459 } else { 3460 $w insert e:$ix $str 3461 $w insert e:$ix $e [highlight_tag $de] 3462 } 3463 } 3464 $w mark gravity e:$ix right 3465 $w conf -state disabled 3466 set treediropen($dir) 1 3467 set top [lindex [split [$w index @0,0] .] 0] 3468 set ht [$w cget -height] 3469 set l [lindex [split [$w index s:$ix] .] 0] 3470 if {$l < $top} { 3471 $w yview $l.0 3472 } elseif {$l + $n + 1 > $top + $ht} { 3473 set top [expr {$l + $n + 2 - $ht}] 3474 if {$l < $top} { 3475 set top $l 3476 } 3477 $w yview $top.0 3478 } 3479 } 3480 3481 proc treeclick {w x y} { 3482 global treediropen cmitmode ctext cflist cflist_top 3483 3484 if {$cmitmode ne "tree"} return 3485 if {![info exists cflist_top]} return 3486 set l [lindex [split [$w index "@$x,$y"] "."] 0] 3487 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" 3488 $cflist tag add highlight $l.0 "$l.0 lineend" 3489 set cflist_top $l 3490 if {$l == 1} { 3491 $ctext yview 1.0 3492 return 3493 } 3494 set e [linetoelt $l] 3495 if {[string index $e end] ne "/"} { 3496 showfile $e 3497 } elseif {$treediropen($e)} { 3498 treeclosedir $w $e 3499 } else { 3500 treeopendir $w $e 3501 } 3502 } 3503 3504 proc setfilelist {id} { 3505 global treefilelist cflist jump_to_here 3506 3507 treeview $cflist $treefilelist($id) 0 3508 if {$jump_to_here ne {}} { 3509 set f [lindex $jump_to_here 0] 3510 if {[lsearch -exact $treefilelist($id) $f] >= 0} { 3511 showfile $f 3512 } 3513 } 3514 } 3515 3516 image create bitmap tri-rt -background black -foreground blue -data { 3517 #define tri-rt_width 13 3518 #define tri-rt_height 13 3519 static unsigned char tri-rt_bits[] = { 3520 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x70, 0x00, 0xf0, 0x00, 3521 0xf0, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x30, 0x00, 0x10, 0x00, 0x00, 0x00, 3522 0x00, 0x00}; 3523 } -maskdata { 3524 #define tri-rt-mask_width 13 3525 #define tri-rt-mask_height 13 3526 static unsigned char tri-rt-mask_bits[] = { 3527 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x01, 3528 0xf8, 0x03, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0x38, 0x00, 0x18, 0x00, 3529 0x08, 0x00}; 3530 } 3531 image create bitmap tri-dn -background black -foreground blue -data { 3532 #define tri-dn_width 13 3533 #define tri-dn_height 13 3534 static unsigned char tri-dn_bits[] = { 3535 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xf8, 0x03, 3536 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3537 0x00, 0x00}; 3538 } -maskdata { 3539 #define tri-dn-mask_width 13 3540 #define tri-dn-mask_height 13 3541 static unsigned char tri-dn-mask_bits[] = { 3542 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0x0f, 0xfc, 0x07, 3543 0xf8, 0x03, 0xf0, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 3544 0x00, 0x00}; 3545 } 3546 3547 image create bitmap reficon-T -background black -foreground yellow -data { 3548 #define tagicon_width 13 3549 #define tagicon_height 9 3550 static unsigned char tagicon_bits[] = { 3551 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07, 3552 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00}; 3553 } -maskdata { 3554 #define tagicon-mask_width 13 3555 #define tagicon-mask_height 9 3556 static unsigned char tagicon-mask_bits[] = { 3557 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f, 3558 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00}; 3559 } 3560 set rectdata { 3561 #define headicon_width 13 3562 #define headicon_height 9 3563 static unsigned char headicon_bits[] = { 3564 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07, 3565 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00}; 3566 } 3567 set rectmask { 3568 #define headicon-mask_width 13 3569 #define headicon-mask_height 9 3570 static unsigned char headicon-mask_bits[] = { 3571 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 3572 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00}; 3573 } 3574 image create bitmap reficon-H -background black -foreground "#00ff00" \ 3575 -data $rectdata -maskdata $rectmask 3576 image create bitmap reficon-R -background black -foreground "#ffddaa" \ 3577 -data $rectdata -maskdata $rectmask 3578 image create bitmap reficon-o -background black -foreground "#ddddff" \ 3579 -data $rectdata -maskdata $rectmask 3580 3581 proc init_flist {first} { 3582 global cflist cflist_top difffilestart 3583 3584 $cflist conf -state normal 3585 $cflist delete 0.0 end 3586 if {$first ne {}} { 3587 $cflist insert end $first 3588 set cflist_top 1 3589 $cflist tag add highlight 1.0 "1.0 lineend" 3590 } else { 3591 unset -nocomplain cflist_top 3592 } 3593 $cflist conf -state disabled 3594 set difffilestart {} 3595 } 3596 3597 proc highlight_tag {f} { 3598 global highlight_paths 3599 3600 foreach p $highlight_paths { 3601 if {[string match $p $f]} { 3602 return "bold" 3603 } 3604 } 3605 return {} 3606 } 3607 3608 proc highlight_filelist {} { 3609 global cmitmode cflist 3610 3611 $cflist conf -state normal 3612 if {$cmitmode ne "tree"} { 3613 set end [lindex [split [$cflist index end] .] 0] 3614 for {set l 2} {$l < $end} {incr l} { 3615 set line [$cflist get $l.0 "$l.0 lineend"] 3616 if {[highlight_tag $line] ne {}} { 3617 $cflist tag add bold $l.0 "$l.0 lineend" 3618 } 3619 } 3620 } else { 3621 highlight_tree 2 {} 3622 } 3623 $cflist conf -state disabled 3624 } 3625 3626 proc unhighlight_filelist {} { 3627 global cflist 3628 3629 $cflist conf -state normal 3630 $cflist tag remove bold 1.0 end 3631 $cflist conf -state disabled 3632 } 3633 3634 proc add_flist {fl} { 3635 global cflist 3636 3637 $cflist conf -state normal 3638 foreach f $fl { 3639 $cflist insert end "\n" 3640 $cflist insert end $f [highlight_tag $f] 3641 } 3642 $cflist conf -state disabled 3643 } 3644 3645 proc sel_flist {w x y} { 3646 global ctext difffilestart cflist cflist_top cmitmode 3647 3648 if {$cmitmode eq "tree"} return 3649 if {![info exists cflist_top]} return 3650 set l [lindex [split [$w index "@$x,$y"] "."] 0] 3651 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" 3652 $cflist tag add highlight $l.0 "$l.0 lineend" 3653 set cflist_top $l 3654 if {$l == 1} { 3655 $ctext yview 1.0 3656 } else { 3657 catch {$ctext yview [lindex $difffilestart [expr {$l - 2}]]} 3658 } 3659 suppress_highlighting_file_for_current_scrollpos 3660 } 3661 3662 proc pop_flist_menu {w X Y x y} { 3663 global ctext cflist cmitmode flist_menu flist_menu_file 3664 global treediffs diffids 3665 3666 stopfinding 3667 set l [lindex [split [$w index "@$x,$y"] "."] 0] 3668 if {$l <= 1} return 3669 if {$cmitmode eq "tree"} { 3670 set e [linetoelt $l] 3671 if {[string index $e end] eq "/"} return 3672 } else { 3673 set e [lindex $treediffs($diffids) [expr {$l-2}]] 3674 } 3675 set flist_menu_file $e 3676 set xdiffstate "normal" 3677 if {$cmitmode eq "tree"} { 3678 set xdiffstate "disabled" 3679 } 3680 # Disable "External diff" item in tree mode 3681 $flist_menu entryconf 2 -state $xdiffstate 3682 tk_popup $flist_menu $X $Y 3683 } 3684 3685 proc find_ctext_fileinfo {line} { 3686 global ctext_file_names ctext_file_lines 3687 3688 set ok [bsearch $ctext_file_lines $line] 3689 set tline [lindex $ctext_file_lines $ok] 3690 3691 if {$ok >= [llength $ctext_file_lines] || $line < $tline} { 3692 return {} 3693 } else { 3694 return [list [lindex $ctext_file_names $ok] $tline] 3695 } 3696 } 3697 3698 proc pop_diff_menu {w X Y x y} { 3699 global ctext diff_menu flist_menu_file 3700 global diff_menu_txtpos diff_menu_line 3701 global diff_menu_filebase 3702 3703 set diff_menu_txtpos [split [$w index "@$x,$y"] "."] 3704 set diff_menu_line [lindex $diff_menu_txtpos 0] 3705 # don't pop up the menu on hunk-separator or file-separator lines 3706 if {[lsearch -glob [$ctext tag names $diff_menu_line.0] "*sep"] >= 0} { 3707 return 3708 } 3709 stopfinding 3710 set f [find_ctext_fileinfo $diff_menu_line] 3711 if {$f eq {}} return 3712 set flist_menu_file [lindex $f 0] 3713 set diff_menu_filebase [lindex $f 1] 3714 tk_popup $diff_menu $X $Y 3715 } 3716 3717 proc flist_hl {only} { 3718 global flist_menu_file findstring gdttype 3719 3720 set x [shellquote $flist_menu_file] 3721 if {$only || $findstring eq {} || $gdttype ne [mc "touching paths:"]} { 3722 set findstring $x 3723 } else { 3724 append findstring " " $x 3725 } 3726 set gdttype [mc "touching paths:"] 3727 } 3728 3729 proc gitknewtmpdir {} { 3730 global diffnum gitktmpdir gitdir env 3731 3732 if {![info exists gitktmpdir]} { 3733 if {[info exists env(GITK_TMPDIR)]} { 3734 set tmpdir $env(GITK_TMPDIR) 3735 } elseif {[info exists env(TMPDIR)]} { 3736 set tmpdir $env(TMPDIR) 3737 } else { 3738 set tmpdir $gitdir 3739 } 3740 set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"] 3741 if {[catch {set gitktmpdir [safe_exec [list mktemp -d $gitktmpformat]]}]} { 3742 set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]] 3743 } 3744 if {[catch {file mkdir $gitktmpdir} err]} { 3745 error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" 3746 unset gitktmpdir 3747 return {} 3748 } 3749 set diffnum 0 3750 } 3751 incr diffnum 3752 set diffdir [file join $gitktmpdir $diffnum] 3753 if {[catch {file mkdir $diffdir} err]} { 3754 error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err" 3755 return {} 3756 } 3757 return $diffdir 3758 } 3759 3760 proc save_file_from_commit {filename output what} { 3761 global nullfile 3762 3763 if {[catch {safe_exec_redirect [list git show $filename --] [list > $output]} err]} { 3764 if {[string match "fatal: bad revision *" $err]} { 3765 return $nullfile 3766 } 3767 error_popup "[mc "Error getting \"%s\" from %s:" $filename $what] $err" 3768 return {} 3769 } 3770 return $output 3771 } 3772 3773 proc external_diff_get_one_file {diffid filename diffdir} { 3774 global nullid nullid2 nullfile 3775 global worktree 3776 3777 if {$diffid == $nullid} { 3778 set difffile [file join $worktree $filename] 3779 if {[file exists $difffile]} { 3780 return $difffile 3781 } 3782 return $nullfile 3783 } 3784 if {$diffid == $nullid2} { 3785 set difffile [file join $diffdir "\[index\] [file tail $filename]"] 3786 return [save_file_from_commit :$filename $difffile index] 3787 } 3788 set difffile [file join $diffdir "\[$diffid\] [file tail $filename]"] 3789 return [save_file_from_commit $diffid:$filename $difffile \ 3790 "revision $diffid"] 3791 } 3792 3793 proc check_for_renames_in_diff {filepath} { # renames 3794 global difffilestart ctext 3795 3796 set filename [file tail $filepath] 3797 set renames {} 3798 3799 foreach loc $difffilestart { 3800 set loclineend [string map {.0 .end} $loc] 3801 set fromlineloc "$loc + 2 lines" 3802 set tolineloc "$loc + 3 lines" 3803 set renfromline [$ctext get $fromlineloc [string map {.0 .end} $fromlineloc]] 3804 set rentoline [$ctext get $tolineloc [string map {.0 .end} $tolineloc]] 3805 if {[string equal -length 12 "rename from " $renfromline] 3806 && [string equal -length 10 "rename to " $rentoline]} { 3807 set renfrom [string range $renfromline 12 end] 3808 set rento [string range $rentoline 10 end] 3809 if {[string first $filename $renfrom] != -1 3810 || [string first $filename $rento] != -1} { 3811 lappend renames $renfrom 3812 lappend renames $rento 3813 break 3814 } 3815 } 3816 } 3817 3818 return $renames 3819 } 3820 3821 proc external_diff {} { 3822 global nullid nullid2 3823 global flist_menu_file 3824 global diffids 3825 global extdifftool 3826 3827 if {[llength $diffids] == 1} { 3828 # no reference commit given 3829 set diffidto [lindex $diffids 0] 3830 if {$diffidto eq $nullid} { 3831 # diffing working copy with index 3832 set diffidfrom $nullid2 3833 } elseif {$diffidto eq $nullid2} { 3834 # diffing index with HEAD 3835 set diffidfrom "HEAD" 3836 } else { 3837 # use first parent commit 3838 global parentlist selectedline 3839 set diffidfrom [lindex $parentlist $selectedline 0] 3840 } 3841 } else { 3842 set diffidfrom [lindex $diffids 0] 3843 set diffidto [lindex $diffids 1] 3844 } 3845 3846 # make sure that several diffs wont collide 3847 set diffdir [gitknewtmpdir] 3848 if {$diffdir eq {}} return 3849 3850 # gather files to diff 3851 set renames [check_for_renames_in_diff $flist_menu_file] 3852 set renamefrom [lindex $renames 0] 3853 set renameto [lindex $renames 1] 3854 if {$renamefrom ne {} && $renameto ne {}} { 3855 set difffromfile [external_diff_get_one_file $diffidfrom $renamefrom $diffdir] 3856 set difftofile [external_diff_get_one_file $diffidto $renameto $diffdir] 3857 } else { 3858 set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir] 3859 set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir] 3860 } 3861 3862 if {$difffromfile ne {} && $difftofile ne {}} { 3863 set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile] 3864 if {[catch {set fl [safe_open_command $cmd]} err]} { 3865 file delete -force $diffdir 3866 error_popup "$extdifftool: [mc "command failed:"] $err" 3867 } else { 3868 fconfigure $fl -blocking 0 3869 filerun $fl [list delete_at_eof $fl $diffdir] 3870 } 3871 } 3872 } 3873 3874 proc find_hunk_blamespec {base line} { 3875 global ctext 3876 3877 # Find and parse the hunk header 3878 set s_lix [$ctext search -backwards -regexp ^@@ "$line.0 lineend" $base.0] 3879 if {$s_lix eq {}} return 3880 3881 set s_line [$ctext get $s_lix "$s_lix + 1 lines"] 3882 if {![regexp {^@@@*(( -\d+(,\d+)?)+) \+(\d+)(,\d+)? @@} $s_line \ 3883 s_line old_specs osz osz1 new_line nsz]} { 3884 return 3885 } 3886 3887 # base lines for the parents 3888 set base_lines [list $new_line] 3889 foreach old_spec [lrange [split $old_specs " "] 1 end] { 3890 if {![regexp -- {-(\d+)(,\d+)?} $old_spec \ 3891 old_spec old_line osz]} { 3892 return 3893 } 3894 lappend base_lines $old_line 3895 } 3896 3897 # Now scan the lines to determine offset within the hunk 3898 set max_parent [expr {[llength $base_lines]-2}] 3899 set dline 0 3900 set s_lno [lindex [split $s_lix "."] 0] 3901 3902 # Determine if the line is removed 3903 set chunk [$ctext get $line.0 "$line.1 + $max_parent chars"] 3904 if {[string match {[-+ ]*} $chunk]} { 3905 set removed_idx [string first "-" $chunk] 3906 # Choose a parent index 3907 if {$removed_idx >= 0} { 3908 set parent $removed_idx 3909 } else { 3910 set unchanged_idx [string first " " $chunk] 3911 if {$unchanged_idx >= 0} { 3912 set parent $unchanged_idx 3913 } else { 3914 # blame the current commit 3915 set parent -1 3916 } 3917 } 3918 # then count other lines that belong to it 3919 for {set i $line} {[incr i -1] > $s_lno} {} { 3920 set chunk [$ctext get $i.0 "$i.1 + $max_parent chars"] 3921 # Determine if the line is removed 3922 set removed_idx [string first "-" $chunk] 3923 if {$parent >= 0} { 3924 set code [string index $chunk $parent] 3925 if {$code eq "-" || ($removed_idx < 0 && $code ne "+")} { 3926 incr dline 3927 } 3928 } else { 3929 if {$removed_idx < 0} { 3930 incr dline 3931 } 3932 } 3933 } 3934 incr parent 3935 } else { 3936 set parent 0 3937 } 3938 3939 incr dline [lindex $base_lines $parent] 3940 return [list $parent $dline] 3941 } 3942 3943 proc external_blame_diff {} { 3944 global currentid cmitmode 3945 global diff_menu_txtpos diff_menu_line 3946 global diff_menu_filebase flist_menu_file 3947 3948 if {$cmitmode eq "tree"} { 3949 set parent_idx 0 3950 set line [expr {$diff_menu_line - $diff_menu_filebase}] 3951 } else { 3952 set hinfo [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] 3953 if {$hinfo ne {}} { 3954 set parent_idx [lindex $hinfo 0] 3955 set line [lindex $hinfo 1] 3956 } else { 3957 set parent_idx 0 3958 set line 0 3959 } 3960 } 3961 3962 external_blame $parent_idx $line 3963 } 3964 3965 # Find the SHA1 ID of the blob for file $fname in the index 3966 # at stage 0 or 2 3967 proc index_sha1 {fname} { 3968 set f [safe_open_command [list git ls-files -s $fname]] 3969 while {[gets $f line] >= 0} { 3970 set info [lindex [split $line "\t"] 0] 3971 set stage [lindex $info 2] 3972 if {$stage eq "0" || $stage eq "2"} { 3973 close $f 3974 return [lindex $info 1] 3975 } 3976 } 3977 close $f 3978 return {} 3979 } 3980 3981 # Turn an absolute path into one relative to the current directory 3982 proc make_relative {f} { 3983 if {[file pathtype $f] eq "relative"} { 3984 return $f 3985 } 3986 set elts [file split $f] 3987 set here [file split [pwd]] 3988 set ei 0 3989 set hi 0 3990 set res {} 3991 foreach d $here { 3992 if {$ei < $hi || $ei >= [llength $elts] || [lindex $elts $ei] ne $d} { 3993 lappend res ".." 3994 } else { 3995 incr ei 3996 } 3997 incr hi 3998 } 3999 set elts [concat $res [lrange $elts $ei end]] 4000 return [eval file join $elts] 4001 } 4002 4003 proc external_blame {parent_idx {line {}}} { 4004 global flist_menu_file cdup 4005 global nullid nullid2 4006 global parentlist selectedline currentid 4007 4008 if {$parent_idx > 0} { 4009 set base_commit [lindex $parentlist $selectedline [expr {$parent_idx-1}]] 4010 } else { 4011 set base_commit $currentid 4012 } 4013 4014 if {$base_commit eq {} || $base_commit eq $nullid || $base_commit eq $nullid2} { 4015 error_popup [mc "No such commit"] 4016 return 4017 } 4018 4019 set cmdline [list git gui blame] 4020 if {$line ne {} && $line > 1} { 4021 lappend cmdline "--line=$line" 4022 } 4023 set f [file join $cdup $flist_menu_file] 4024 # Unfortunately it seems git gui blame doesn't like 4025 # being given an absolute path... 4026 set f [make_relative $f] 4027 lappend cmdline $base_commit $f 4028 if {[catch {safe_exec_redirect $cmdline [list &]} err]} { 4029 error_popup "[mc "git gui blame: command failed:"] $err" 4030 } 4031 } 4032 4033 proc show_line_source {} { 4034 global cmitmode currentid parents curview blamestuff blameinst 4035 global diff_menu_line diff_menu_filebase flist_menu_file 4036 global nullid nullid2 gitdir cdup 4037 4038 set from_index {} 4039 if {$cmitmode eq "tree"} { 4040 set id $currentid 4041 set line [expr {$diff_menu_line - $diff_menu_filebase}] 4042 } else { 4043 set h [find_hunk_blamespec $diff_menu_filebase $diff_menu_line] 4044 if {$h eq {}} return 4045 set pi [lindex $h 0] 4046 if {$pi == 0} { 4047 mark_ctext_line $diff_menu_line 4048 return 4049 } 4050 incr pi -1 4051 if {$currentid eq $nullid} { 4052 if {$pi > 0} { 4053 # must be a merge in progress... 4054 if {[catch { 4055 # get the last line from .git/MERGE_HEAD 4056 set f [safe_open_file [file join $gitdir MERGE_HEAD] r] 4057 set id [lindex [split [read $f] "\n"] end-1] 4058 close $f 4059 } err]} { 4060 error_popup [mc "Couldn't read merge head: %s" $err] 4061 return 4062 } 4063 } elseif {$parents($curview,$currentid) eq $nullid2} { 4064 # need to do the blame from the index 4065 if {[catch { 4066 set from_index [index_sha1 $flist_menu_file] 4067 } err]} { 4068 error_popup [mc "Error reading index: %s" $err] 4069 return 4070 } 4071 } else { 4072 set id $parents($curview,$currentid) 4073 } 4074 } else { 4075 set id [lindex $parents($curview,$currentid) $pi] 4076 } 4077 set line [lindex $h 1] 4078 } 4079 set blamefile [file join $cdup $flist_menu_file] 4080 if {$from_index ne {}} { 4081 set blameargs [list \ 4082 [list git cat-file blob $from_index] \ 4083 [list git blame -p -L$line,+1 --contents - -- $blamefile]] 4084 } else { 4085 set blameargs [list \ 4086 [list git blame -p -L$line,+1 $id -- $blamefile]] 4087 } 4088 if {[catch { 4089 set f [safe_open_pipeline $blameargs] 4090 } err]} { 4091 error_popup [mc "Couldn't start git blame: %s" $err] 4092 return 4093 } 4094 nowbusy blaming [mc "Searching"] 4095 fconfigure $f -blocking 0 4096 set i [reg_instance $f] 4097 set blamestuff($i) {} 4098 set blameinst $i 4099 filerun $f [list read_line_source $f $i] 4100 } 4101 4102 proc stopblaming {} { 4103 global blameinst 4104 4105 if {[info exists blameinst]} { 4106 stop_instance $blameinst 4107 unset blameinst 4108 notbusy blaming 4109 } 4110 } 4111 4112 proc read_line_source {fd inst} { 4113 global blamestuff curview commfd blameinst nullid nullid2 4114 global hashlength 4115 4116 while {[gets $fd line] >= 0} { 4117 lappend blamestuff($inst) $line 4118 } 4119 if {![eof $fd]} { 4120 return 1 4121 } 4122 unset commfd($inst) 4123 unset blameinst 4124 notbusy blaming 4125 fconfigure $fd -blocking 1 4126 if {[catch {close $fd} err]} { 4127 error_popup [mc "Error running git blame: %s" $err] 4128 return 0 4129 } 4130 4131 set fname {} 4132 set line [split [lindex $blamestuff($inst) 0] " "] 4133 set id [lindex $line 0] 4134 set lnum [lindex $line 1] 4135 if {[string length $id] == $hashlength && [string is xdigit $id] && 4136 [string is digit -strict $lnum]} { 4137 # look for "filename" line 4138 foreach l $blamestuff($inst) { 4139 if {[string match "filename *" $l]} { 4140 set fname [string range $l 9 end] 4141 break 4142 } 4143 } 4144 } 4145 if {$fname ne {}} { 4146 # all looks good, select it 4147 if {$id eq $nullid} { 4148 # blame uses all-zeroes to mean not committed, 4149 # which would mean a change in the index 4150 set id $nullid2 4151 } 4152 if {[commitinview $id $curview]} { 4153 selectline [rowofcommit $id] 1 [list $fname $lnum] 1 4154 } else { 4155 error_popup [mc "That line comes from commit %s, \ 4156 which is not in this view" [shortids $id]] 4157 } 4158 } else { 4159 puts "oops couldn't parse git blame output" 4160 } 4161 return 0 4162 } 4163 4164 # delete $dir when we see eof on $f (presumably because the child has exited) 4165 proc delete_at_eof {f dir} { 4166 while {[gets $f line] >= 0} {} 4167 if {[eof $f]} { 4168 if {[catch {close $f} err]} { 4169 error_popup "[mc "External diff viewer failed:"] $err" 4170 } 4171 file delete -force $dir 4172 return 0 4173 } 4174 return 1 4175 } 4176 4177 # Functions for adding and removing shell-type quoting 4178 4179 proc shellquote {str} { 4180 if {![string match "*\['\"\\ \t]*" $str]} { 4181 return $str 4182 } 4183 if {![string match "*\['\"\\]*" $str]} { 4184 return "\"$str\"" 4185 } 4186 if {![string match "*'*" $str]} { 4187 return "'$str'" 4188 } 4189 return "\"[string map {\" \\\" \\ \\\\} $str]\"" 4190 } 4191 4192 proc shellarglist {l} { 4193 set str {} 4194 foreach a $l { 4195 if {$str ne {}} { 4196 append str " " 4197 } 4198 append str [shellquote $a] 4199 } 4200 return $str 4201 } 4202 4203 proc shelldequote {str} { 4204 set ret {} 4205 set used -1 4206 while {1} { 4207 incr used 4208 if {![regexp -start $used -indices "\['\"\\\\ \t]" $str first]} { 4209 append ret [string range $str $used end] 4210 set used [string length $str] 4211 break 4212 } 4213 set first [lindex $first 0] 4214 set ch [string index $str $first] 4215 if {$first > $used} { 4216 append ret [string range $str $used [expr {$first - 1}]] 4217 set used $first 4218 } 4219 if {$ch eq " " || $ch eq "\t"} break 4220 incr used 4221 if {$ch eq "'"} { 4222 set first [string first "'" $str $used] 4223 if {$first < 0} { 4224 error "unmatched single-quote" 4225 } 4226 append ret [string range $str $used [expr {$first - 1}]] 4227 set used $first 4228 continue 4229 } 4230 if {$ch eq "\\"} { 4231 if {$used >= [string length $str]} { 4232 error "trailing backslash" 4233 } 4234 append ret [string index $str $used] 4235 continue 4236 } 4237 # here ch == "\"" 4238 while {1} { 4239 if {![regexp -start $used -indices "\[\"\\\\]" $str first]} { 4240 error "unmatched double-quote" 4241 } 4242 set first [lindex $first 0] 4243 set ch [string index $str $first] 4244 if {$first > $used} { 4245 append ret [string range $str $used [expr {$first - 1}]] 4246 set used $first 4247 } 4248 if {$ch eq "\""} break 4249 incr used 4250 append ret [string index $str $used] 4251 incr used 4252 } 4253 } 4254 return [list $used $ret] 4255 } 4256 4257 proc shellsplit {str} { 4258 set l {} 4259 while {1} { 4260 set str [string trimleft $str] 4261 if {$str eq {}} break 4262 set dq [shelldequote $str] 4263 set n [lindex $dq 0] 4264 set word [lindex $dq 1] 4265 set str [string range $str $n end] 4266 lappend l $word 4267 } 4268 return $l 4269 } 4270 4271 proc set_window_title {} { 4272 global appname curview viewname vrevs 4273 set rev [mc "All files"] 4274 if {$curview ne 0} { 4275 if {$viewname($curview) eq [mc "Command line"]} { 4276 set rev [string map {"--gitk-symmetric-diff-marker" "--merge"} $vrevs($curview)] 4277 } else { 4278 set rev $viewname($curview) 4279 } 4280 } 4281 wm title . "[reponame]: $rev - $appname" 4282 } 4283 4284 # Code to implement multiple views 4285 4286 proc newview {ishighlight} { 4287 global nextviewnum newviewname newishighlight 4288 global revtreeargs viewargscmd newviewopts curview 4289 4290 set newishighlight $ishighlight 4291 set top .gitkview 4292 if {[winfo exists $top]} { 4293 raise $top 4294 return 4295 } 4296 decode_view_opts $nextviewnum $revtreeargs 4297 set newviewname($nextviewnum) "[mc "View"] $nextviewnum" 4298 set newviewopts($nextviewnum,perm) 0 4299 set newviewopts($nextviewnum,cmd) $viewargscmd($curview) 4300 vieweditor $top $nextviewnum [mc "Gitk view definition"] 4301 } 4302 4303 set known_view_options { 4304 {perm b . {} {mc "Remember this view"}} 4305 {reflabel l + {} {mc "References (space separated list):"}} 4306 {refs t15 .. {} {mc "Branches & tags:"}} 4307 {allrefs b *. "--all" {mc "All refs"}} 4308 {branches b . "--branches" {mc "All (local) branches"}} 4309 {tags b . "--tags" {mc "All tags"}} 4310 {remotes b . "--remotes" {mc "All remote-tracking branches"}} 4311 {commitlbl l + {} {mc "Commit Info (regular expressions):"}} 4312 {author t15 .. "--author=*" {mc "Author:"}} 4313 {committer t15 . "--committer=*" {mc "Committer:"}} 4314 {loginfo t15 .. "--grep=*" {mc "Commit Message:"}} 4315 {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}} 4316 {igrep b .. "--invert-grep" {mc "Matches no Commit Info criteria"}} 4317 {changes_l l + {} {mc "Changes to Files:"}} 4318 {pickaxe_s r0 . {} {mc "Fixed String"}} 4319 {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}} 4320 {pickaxe t15 .. "-S*" {mc "Search string:"}} 4321 {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}} 4322 {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}} 4323 {until t15 . {"--until=*" "--before=*"} {mc "Until:"}} 4324 {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}} 4325 {limit t10 *. "--max-count=*" {mc "Number to show:"}} 4326 {skip t10 . "--skip=*" {mc "Number to skip:"}} 4327 {misc_lbl l + {} {mc "Miscellaneous options:"}} 4328 {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}} 4329 {lright b . "--left-right" {mc "Mark branch sides"}} 4330 {first b . "--first-parent" {mc "Limit to first parent"}} 4331 {smplhst b . "--simplify-by-decoration" {mc "Simple history"}} 4332 {args t50 *. {} {mc "Additional arguments to git log:"}} 4333 {allpaths path + {} {mc "Enter files and directories to include, one per line:"}} 4334 {cmd t50= + {} {mc "Command to generate more commits to include:"}} 4335 } 4336 4337 # Convert $newviewopts($n, ...) into args for git log. 4338 proc encode_view_opts {n} { 4339 global known_view_options newviewopts 4340 4341 set rargs [list] 4342 foreach opt $known_view_options { 4343 set patterns [lindex $opt 3] 4344 if {$patterns eq {}} continue 4345 set pattern [lindex $patterns 0] 4346 4347 if {[lindex $opt 1] eq "b"} { 4348 set val $newviewopts($n,[lindex $opt 0]) 4349 if {$val} { 4350 lappend rargs $pattern 4351 } 4352 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} { 4353 regexp {^(.*_)} [lindex $opt 0] uselessvar button_id 4354 set val $newviewopts($n,$button_id) 4355 if {$val eq $value} { 4356 lappend rargs $pattern 4357 } 4358 } else { 4359 set val $newviewopts($n,[lindex $opt 0]) 4360 set val [string trim $val] 4361 if {$val ne {}} { 4362 set pfix [string range $pattern 0 end-1] 4363 lappend rargs $pfix$val 4364 } 4365 } 4366 } 4367 set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]] 4368 return [concat $rargs [shellsplit $newviewopts($n,args)]] 4369 } 4370 4371 # Fill $newviewopts($n, ...) based on args for git log. 4372 proc decode_view_opts {n view_args} { 4373 global known_view_options newviewopts 4374 4375 foreach opt $known_view_options { 4376 set id [lindex $opt 0] 4377 if {[lindex $opt 1] eq "b"} { 4378 # Checkboxes 4379 set val 0 4380 } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} { 4381 # Radiobuttons 4382 regexp {^(.*_)} $id uselessvar id 4383 set val 0 4384 } else { 4385 # Text fields 4386 set val {} 4387 } 4388 set newviewopts($n,$id) $val 4389 } 4390 set oargs [list] 4391 set refargs [list] 4392 foreach arg $view_args { 4393 if {[regexp -- {^-([0-9]+)$} $arg arg cnt] 4394 && ![info exists found(limit)]} { 4395 set newviewopts($n,limit) $cnt 4396 set found(limit) 1 4397 continue 4398 } 4399 catch { unset val } 4400 foreach opt $known_view_options { 4401 set id [lindex $opt 0] 4402 if {[info exists found($id)]} continue 4403 foreach pattern [lindex $opt 3] { 4404 if {![string match $pattern $arg]} continue 4405 if {[lindex $opt 1] eq "b"} { 4406 # Check buttons 4407 set val 1 4408 } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} { 4409 # Radio buttons 4410 regexp {^(.*_)} $id uselessvar id 4411 set val $num 4412 } else { 4413 # Text input fields 4414 set size [string length $pattern] 4415 set val [string range $arg [expr {$size-1}] end] 4416 } 4417 set newviewopts($n,$id) $val 4418 set found($id) 1 4419 break 4420 } 4421 if {[info exists val]} break 4422 } 4423 if {[info exists val]} continue 4424 if {[regexp {^-} $arg]} { 4425 lappend oargs $arg 4426 } else { 4427 lappend refargs $arg 4428 } 4429 } 4430 set newviewopts($n,refs) [shellarglist $refargs] 4431 set newviewopts($n,args) [shellarglist $oargs] 4432 } 4433 4434 proc edit_or_newview {} { 4435 global curview 4436 4437 if {$curview > 0} { 4438 editview 4439 } else { 4440 newview 0 4441 } 4442 } 4443 4444 proc editview {} { 4445 global curview 4446 global viewname viewperm newviewname newviewopts 4447 global viewargs viewargscmd 4448 4449 set top .gitkvedit-$curview 4450 if {[winfo exists $top]} { 4451 raise $top 4452 return 4453 } 4454 decode_view_opts $curview $viewargs($curview) 4455 set newviewname($curview) $viewname($curview) 4456 set newviewopts($curview,perm) $viewperm($curview) 4457 set newviewopts($curview,cmd) $viewargscmd($curview) 4458 vieweditor $top $curview "[mc "Gitk: edit view"] $viewname($curview)" 4459 } 4460 4461 proc vieweditor {top n title} { 4462 global newviewname newviewopts viewfiles bgcolor 4463 global known_view_options 4464 4465 ttk_toplevel $top 4466 wm title $top [concat $title [mc "-- criteria for selecting revisions"]] 4467 make_transient $top . 4468 4469 # View name 4470 ttk::frame $top.nfr 4471 ttk::label $top.nl -text [mc "View Name"] 4472 ttk::entry $top.name -width 20 -textvariable newviewname($n) 4473 pack $top.nfr -in $top -fill x -pady 5 -padx 3 4474 pack $top.nl -in $top.nfr -side left -padx {0 5} 4475 pack $top.name -in $top.nfr -side left -padx {0 25} 4476 4477 # View options 4478 set cframe $top.nfr 4479 set cexpand 0 4480 set cnt 0 4481 foreach opt $known_view_options { 4482 set id [lindex $opt 0] 4483 set type [lindex $opt 1] 4484 set flags [lindex $opt 2] 4485 set title [eval [lindex $opt 4]] 4486 set lxpad 0 4487 4488 if {$flags eq "+" || $flags eq "*"} { 4489 set cframe $top.fr$cnt 4490 incr cnt 4491 ttk::frame $cframe 4492 pack $cframe -in $top -fill x -pady 3 -padx 3 4493 set cexpand [expr {$flags eq "*"}] 4494 } elseif {$flags eq ".." || $flags eq "*."} { 4495 set cframe $top.fr$cnt 4496 incr cnt 4497 ttk::frame $cframe 4498 pack $cframe -in $top -fill x -pady 3 -padx [list 15 3] 4499 set cexpand [expr {$flags eq "*."}] 4500 } else { 4501 set lxpad 5 4502 } 4503 4504 if {$type eq "l"} { 4505 ttk::label $cframe.l_$id -text $title 4506 pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w 4507 } elseif {$type eq "b"} { 4508 ttk::checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id) 4509 pack $cframe.c_$id -in $cframe -side left \ 4510 -padx [list $lxpad 0] -expand $cexpand -anchor w 4511 } elseif {[regexp {^r(\d+)$} $type type sz]} { 4512 regexp {^(.*_)} $id uselessvar button_id 4513 ttk::radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz 4514 pack $cframe.c_$id -in $cframe -side left \ 4515 -padx [list $lxpad 0] -expand $cexpand -anchor w 4516 } elseif {[regexp {^t(\d+)$} $type type sz]} { 4517 ttk::label $cframe.l_$id -text $title 4518 ttk::entry $cframe.e_$id -width $sz -background $bgcolor \ 4519 -textvariable newviewopts($n,$id) 4520 pack $cframe.l_$id -in $cframe -side left -padx [list $lxpad 0] 4521 pack $cframe.e_$id -in $cframe -side left -expand 1 -fill x 4522 } elseif {[regexp {^t(\d+)=$} $type type sz]} { 4523 ttk::label $cframe.l_$id -text $title 4524 ttk::entry $cframe.e_$id -width $sz -background $bgcolor \ 4525 -textvariable newviewopts($n,$id) 4526 pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w 4527 pack $cframe.e_$id -in $cframe -side top -fill x 4528 } elseif {$type eq "path"} { 4529 ttk::label $top.l -text $title 4530 pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3 4531 text $top.t -width 40 -height 5 -background $bgcolor 4532 if {[info exists viewfiles($n)]} { 4533 foreach f $viewfiles($n) { 4534 $top.t insert end $f 4535 $top.t insert end "\n" 4536 } 4537 $top.t delete {end - 1c} end 4538 $top.t mark set insert 0.0 4539 } 4540 pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3 4541 } 4542 } 4543 4544 ttk::frame $top.buts 4545 ttk::button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] 4546 ttk::button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1] 4547 ttk::button $top.buts.can -text [mc "Cancel"] -command [list destroy $top] 4548 bind $top [list newviewok $top $n] 4549 bind $top [list newviewok $top $n 1] 4550 bind $top [list destroy $top] 4551 grid $top.buts.ok $top.buts.apply $top.buts.can 4552 grid columnconfigure $top.buts 0 -weight 1 -uniform a 4553 grid columnconfigure $top.buts 1 -weight 1 -uniform a 4554 grid columnconfigure $top.buts 2 -weight 1 -uniform a 4555 pack $top.buts -in $top -side top -fill x 4556 focus $top.t 4557 } 4558 4559 proc doviewmenu {m first cmd op argv} { 4560 set nmenu [$m index end] 4561 for {set i $first} {$i <= $nmenu} {incr i} { 4562 if {[$m entrycget $i -command] eq $cmd} { 4563 eval $m $op $i $argv 4564 break 4565 } 4566 } 4567 } 4568 4569 proc allviewmenus {n op args} { 4570 # global viewhlmenu 4571 4572 doviewmenu .bar.view 5 [list showview $n] $op $args 4573 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args 4574 } 4575 4576 proc newviewok {top n {apply 0}} { 4577 global nextviewnum newviewperm newviewname newishighlight 4578 global viewname viewfiles viewperm viewchanged selectedview curview 4579 global viewargs viewargscmd newviewopts viewhlmenu 4580 4581 if {[catch { 4582 set newargs [encode_view_opts $n] 4583 } err]} { 4584 error_popup "[mc "Error in commit selection arguments:"] $err" $top 4585 return 4586 } 4587 set files {} 4588 foreach f [split [$top.t get 0.0 end] "\n"] { 4589 set ft [string trim $f] 4590 if {$ft ne {}} { 4591 lappend files $ft 4592 } 4593 } 4594 if {![info exists viewfiles($n)]} { 4595 # creating a new view 4596 incr nextviewnum 4597 set viewname($n) $newviewname($n) 4598 set viewperm($n) $newviewopts($n,perm) 4599 set viewchanged($n) 1 4600 set viewfiles($n) $files 4601 set viewargs($n) $newargs 4602 set viewargscmd($n) $newviewopts($n,cmd) 4603 addviewmenu $n 4604 if {!$newishighlight} { 4605 run showview $n 4606 } else { 4607 run addvhighlight $n 4608 } 4609 } else { 4610 # editing an existing view 4611 set viewperm($n) $newviewopts($n,perm) 4612 set viewchanged($n) 1 4613 if {$newviewname($n) ne $viewname($n)} { 4614 set viewname($n) $newviewname($n) 4615 doviewmenu .bar.view 5 [list showview $n] \ 4616 entryconf [list -label $viewname($n)] 4617 # doviewmenu $viewhlmenu 1 [list addvhighlight $n] \ 4618 # entryconf [list -label $viewname($n) -value $viewname($n)] 4619 } 4620 if {$files ne $viewfiles($n) || $newargs ne $viewargs($n) || \ 4621 $newviewopts($n,cmd) ne $viewargscmd($n)} { 4622 set viewfiles($n) $files 4623 set viewargs($n) $newargs 4624 set viewargscmd($n) $newviewopts($n,cmd) 4625 if {$curview == $n} { 4626 run reloadcommits 4627 } 4628 } 4629 } 4630 if {$apply} return 4631 catch {destroy $top} 4632 } 4633 4634 proc delview {} { 4635 global curview viewperm hlview selectedhlview viewchanged 4636 4637 if {$curview == 0} return 4638 if {[info exists hlview] && $hlview == $curview} { 4639 set selectedhlview [mc "None"] 4640 unset hlview 4641 } 4642 allviewmenus $curview delete 4643 set viewperm($curview) 0 4644 set viewchanged($curview) 1 4645 showview 0 4646 } 4647 4648 proc addviewmenu {n} { 4649 global viewname viewhlmenu 4650 4651 .bar.view add radiobutton -label $viewname($n) \ 4652 -command [list showview $n] -variable selectedview -value $n 4653 #$viewhlmenu add radiobutton -label $viewname($n) \ 4654 # -command [list addvhighlight $n] -variable selectedhlview 4655 } 4656 4657 proc showview {n} { 4658 global curview cached_commitrow ordertok 4659 global displayorder parentlist rowidlist rowisopt rowfinal 4660 global colormap rowtextx nextcolor canvxmax 4661 global numcommits viewcomplete 4662 global selectedline currentid canv canvy0 4663 global treediffs 4664 global pending_select mainheadid 4665 global commitidx 4666 global selectedview 4667 global hlview selectedhlview commitinterest 4668 4669 if {$n == $curview} return 4670 set selid {} 4671 set ymax [lindex [$canv cget -scrollregion] 3] 4672 set span [$canv yview] 4673 set ytop [expr {[lindex $span 0] * $ymax}] 4674 set ybot [expr {[lindex $span 1] * $ymax}] 4675 set yscreen [expr {($ybot - $ytop) / 2}] 4676 if {$selectedline ne {}} { 4677 set selid $currentid 4678 set y [yc $selectedline] 4679 if {$ytop < $y && $y < $ybot} { 4680 set yscreen [expr {$y - $ytop}] 4681 } 4682 } elseif {[info exists pending_select]} { 4683 set selid $pending_select 4684 unset pending_select 4685 } 4686 unselectline 4687 normalline 4688 unset -nocomplain treediffs 4689 clear_display 4690 if {[info exists hlview] && $hlview == $n} { 4691 unset hlview 4692 set selectedhlview [mc "None"] 4693 } 4694 unset -nocomplain commitinterest 4695 unset -nocomplain cached_commitrow 4696 unset -nocomplain ordertok 4697 4698 set curview $n 4699 set selectedview $n 4700 .bar.view entryconf [mca "&Edit view..."] -state [expr {$n == 0? "disabled": "normal"}] 4701 .bar.view entryconf [mca "&Delete view"] -state [expr {$n == 0? "disabled": "normal"}] 4702 4703 run refill_reflist 4704 if {![info exists viewcomplete($n)]} { 4705 getcommits $selid 4706 return 4707 } 4708 4709 set displayorder {} 4710 set parentlist {} 4711 set rowidlist {} 4712 set rowisopt {} 4713 set rowfinal {} 4714 set numcommits $commitidx($n) 4715 4716 unset -nocomplain colormap 4717 unset -nocomplain rowtextx 4718 set nextcolor 0 4719 set canvxmax [$canv cget -width] 4720 set curview $n 4721 set row 0 4722 setcanvscroll 4723 set yf 0 4724 set row {} 4725 if {$selid ne {} && [commitinview $selid $n]} { 4726 set row [rowofcommit $selid] 4727 # try to get the selected row in the same position on the screen 4728 set ymax [lindex [$canv cget -scrollregion] 3] 4729 set ytop [expr {[yc $row] - $yscreen}] 4730 if {$ytop < 0} { 4731 set ytop 0 4732 } 4733 set yf [expr {$ytop * 1.0 / $ymax}] 4734 } 4735 allcanvs yview moveto $yf 4736 drawvisible 4737 if {$row ne {}} { 4738 selectline $row 0 4739 } elseif {!$viewcomplete($n)} { 4740 reset_pending_select $selid 4741 } else { 4742 reset_pending_select {} 4743 4744 if {[commitinview $pending_select $curview]} { 4745 selectline [rowofcommit $pending_select] 1 4746 } else { 4747 set row [first_real_row] 4748 if {$row < $numcommits} { 4749 selectline $row 0 4750 } 4751 } 4752 } 4753 if {!$viewcomplete($n)} { 4754 if {$numcommits == 0} { 4755 show_status [mc "Reading commits..."] 4756 } 4757 } elseif {$numcommits == 0} { 4758 show_status [mc "No commits selected"] 4759 } 4760 set_window_title 4761 } 4762 4763 # Stuff relating to the highlighting facility 4764 4765 proc ishighlighted {id} { 4766 global vhighlights fhighlights nhighlights rhighlights 4767 4768 if {[info exists nhighlights($id)] && $nhighlights($id) > 0} { 4769 return $nhighlights($id) 4770 } 4771 if {[info exists vhighlights($id)] && $vhighlights($id) > 0} { 4772 return $vhighlights($id) 4773 } 4774 if {[info exists fhighlights($id)] && $fhighlights($id) > 0} { 4775 return $fhighlights($id) 4776 } 4777 if {[info exists rhighlights($id)] && $rhighlights($id) > 0} { 4778 return $rhighlights($id) 4779 } 4780 return 0 4781 } 4782 4783 proc bolden {id font} { 4784 global canv linehtag currentid boldids need_redisplay markedid 4785 4786 # need_redisplay = 1 means the display is stale and about to be redrawn 4787 if {$need_redisplay} return 4788 lappend boldids $id 4789 $canv itemconf $linehtag($id) -font $font 4790 if {[info exists currentid] && $id eq $currentid} { 4791 $canv delete secsel 4792 set t [eval $canv create rect [$canv bbox $linehtag($id)] \ 4793 -outline {{}} -tags secsel \ 4794 -fill [$canv cget -selectbackground]] 4795 $canv lower $t 4796 } 4797 if {[info exists markedid] && $id eq $markedid} { 4798 make_idmark $id 4799 } 4800 } 4801 4802 proc bolden_name {id font} { 4803 global canv2 linentag currentid boldnameids need_redisplay 4804 4805 if {$need_redisplay} return 4806 lappend boldnameids $id 4807 $canv2 itemconf $linentag($id) -font $font 4808 if {[info exists currentid] && $id eq $currentid} { 4809 $canv2 delete secsel 4810 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \ 4811 -outline {{}} -tags secsel \ 4812 -fill [$canv2 cget -selectbackground]] 4813 $canv2 lower $t 4814 } 4815 } 4816 4817 proc unbolden {} { 4818 global boldids 4819 4820 set stillbold {} 4821 foreach id $boldids { 4822 if {![ishighlighted $id]} { 4823 bolden $id mainfont 4824 } else { 4825 lappend stillbold $id 4826 } 4827 } 4828 set boldids $stillbold 4829 } 4830 4831 proc addvhighlight {n} { 4832 global hlview viewcomplete curview vhl_done commitidx 4833 4834 if {[info exists hlview]} { 4835 delvhighlight 4836 } 4837 set hlview $n 4838 if {$n != $curview && ![info exists viewcomplete($n)]} { 4839 start_rev_list $n 4840 } 4841 set vhl_done $commitidx($hlview) 4842 if {$vhl_done > 0} { 4843 drawvisible 4844 } 4845 } 4846 4847 proc delvhighlight {} { 4848 global hlview vhighlights 4849 4850 if {![info exists hlview]} return 4851 unset hlview 4852 unset -nocomplain vhighlights 4853 unbolden 4854 } 4855 4856 proc vhighlightmore {} { 4857 global hlview vhl_done commitidx vhighlights curview 4858 4859 set max $commitidx($hlview) 4860 set vr [visiblerows] 4861 set r0 [lindex $vr 0] 4862 set r1 [lindex $vr 1] 4863 for {set i $vhl_done} {$i < $max} {incr i} { 4864 set id [commitonrow $i $hlview] 4865 if {[commitinview $id $curview]} { 4866 set row [rowofcommit $id] 4867 if {$r0 <= $row && $row <= $r1} { 4868 if {![highlighted $row]} { 4869 bolden $id mainfontbold 4870 } 4871 set vhighlights($id) 1 4872 } 4873 } 4874 } 4875 set vhl_done $max 4876 return 0 4877 } 4878 4879 proc askvhighlight {row id} { 4880 global hlview vhighlights iddrawn 4881 4882 if {[commitinview $id $hlview]} { 4883 if {[info exists iddrawn($id)] && ![ishighlighted $id]} { 4884 bolden $id mainfontbold 4885 } 4886 set vhighlights($id) 1 4887 } else { 4888 set vhighlights($id) 0 4889 } 4890 } 4891 4892 proc hfiles_change {} { 4893 global highlight_files filehighlight fhighlights fh_serial 4894 global highlight_paths 4895 4896 if {[info exists filehighlight]} { 4897 # delete previous highlights 4898 catch {close $filehighlight} 4899 unset filehighlight 4900 unset -nocomplain fhighlights 4901 unbolden 4902 unhighlight_filelist 4903 } 4904 set highlight_paths {} 4905 after cancel do_file_hl $fh_serial 4906 incr fh_serial 4907 if {$highlight_files ne {}} { 4908 after 300 do_file_hl $fh_serial 4909 } 4910 } 4911 4912 proc gdttype_change {name ix op} { 4913 global gdttype highlight_files findstring findpattern 4914 4915 stopfinding 4916 if {$findstring ne {}} { 4917 if {$gdttype eq [mc "containing:"]} { 4918 if {$highlight_files ne {}} { 4919 set highlight_files {} 4920 hfiles_change 4921 } 4922 findcom_change 4923 } else { 4924 if {$findpattern ne {}} { 4925 set findpattern {} 4926 findcom_change 4927 } 4928 set highlight_files $findstring 4929 hfiles_change 4930 } 4931 drawvisible 4932 } 4933 # enable/disable findtype/findloc menus too 4934 } 4935 4936 proc find_change {name ix op} { 4937 global gdttype findstring highlight_files 4938 4939 stopfinding 4940 if {$gdttype eq [mc "containing:"]} { 4941 findcom_change 4942 } else { 4943 if {$highlight_files ne $findstring} { 4944 set highlight_files $findstring 4945 hfiles_change 4946 } 4947 } 4948 drawvisible 4949 } 4950 4951 proc findcom_change args { 4952 global nhighlights boldnameids 4953 global findpattern findtype findstring gdttype 4954 4955 stopfinding 4956 # delete previous highlights, if any 4957 foreach id $boldnameids { 4958 bolden_name $id mainfont 4959 } 4960 set boldnameids {} 4961 unset -nocomplain nhighlights 4962 unbolden 4963 unmarkmatches 4964 if {$gdttype ne [mc "containing:"] || $findstring eq {}} { 4965 set findpattern {} 4966 } elseif {$findtype eq [mc "Regexp"]} { 4967 set findpattern $findstring 4968 } else { 4969 set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \ 4970 $findstring] 4971 set findpattern "*$e*" 4972 } 4973 } 4974 4975 proc makepatterns {l} { 4976 set ret {} 4977 foreach e $l { 4978 set ee [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} $e] 4979 if {[string index $ee end] eq "/"} { 4980 lappend ret "$ee*" 4981 } else { 4982 lappend ret $ee 4983 lappend ret "$ee/*" 4984 } 4985 } 4986 return $ret 4987 } 4988 4989 proc do_file_hl {serial} { 4990 global highlight_files filehighlight highlight_paths gdttype fhl_list 4991 global cdup findtype 4992 4993 if {$gdttype eq [mc "touching paths:"]} { 4994 # If "exact" match then convert backslashes to forward slashes. 4995 # Most useful to support Windows-flavoured file paths. 4996 if {$findtype eq [mc "Exact"]} { 4997 set highlight_files [string map {"\\" "/"} $highlight_files] 4998 } 4999 if {[catch {set paths [shellsplit $highlight_files]}]} return 5000 set highlight_paths [makepatterns $paths] 5001 highlight_filelist 5002 set relative_paths {} 5003 foreach path $paths { 5004 lappend relative_paths [file join $cdup $path] 5005 } 5006 set gdtargs [concat -- $relative_paths] 5007 } elseif {$gdttype eq [mc "adding/removing string:"]} { 5008 set gdtargs [list "-S$highlight_files"] 5009 } elseif {$gdttype eq [mc "changing lines matching:"]} { 5010 set gdtargs [list "-G$highlight_files"] 5011 } else { 5012 # must be "containing:", i.e. we're searching commit info 5013 return 5014 } 5015 set cmd [concat git diff-tree -r -s --stdin $gdtargs] 5016 set filehighlight [safe_open_command_rw $cmd] 5017 fconfigure $filehighlight -blocking 0 5018 filerun $filehighlight readfhighlight 5019 set fhl_list {} 5020 drawvisible 5021 flushhighlights 5022 } 5023 5024 proc flushhighlights {} { 5025 global filehighlight fhl_list 5026 5027 if {[info exists filehighlight]} { 5028 lappend fhl_list {} 5029 puts $filehighlight "" 5030 flush $filehighlight 5031 } 5032 } 5033 5034 proc askfilehighlight {row id} { 5035 global filehighlight fhighlights fhl_list 5036 5037 lappend fhl_list $id 5038 set fhighlights($id) -1 5039 puts $filehighlight $id 5040 } 5041 5042 proc readfhighlight {} { 5043 global filehighlight fhighlights curview iddrawn 5044 global fhl_list find_dirn 5045 5046 if {![info exists filehighlight]} { 5047 return 0 5048 } 5049 set nr 0 5050 while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} { 5051 set line [string trim $line] 5052 set i [lsearch -exact $fhl_list $line] 5053 if {$i < 0} continue 5054 for {set j 0} {$j < $i} {incr j} { 5055 set id [lindex $fhl_list $j] 5056 set fhighlights($id) 0 5057 } 5058 set fhl_list [lrange $fhl_list [expr {$i+1}] end] 5059 if {$line eq {}} continue 5060 if {![commitinview $line $curview]} continue 5061 if {[info exists iddrawn($line)] && ![ishighlighted $line]} { 5062 bolden $line mainfontbold 5063 } 5064 set fhighlights($line) 1 5065 } 5066 if {[eof $filehighlight]} { 5067 # strange... 5068 puts "oops, git diff-tree died" 5069 catch {close $filehighlight} 5070 unset filehighlight 5071 return 0 5072 } 5073 if {[info exists find_dirn]} { 5074 run findmore 5075 } 5076 return 1 5077 } 5078 5079 proc doesmatch {f} { 5080 global findtype findpattern 5081 5082 if {$findtype eq [mc "Regexp"]} { 5083 return [regexp $findpattern $f] 5084 } elseif {$findtype eq [mc "IgnCase"]} { 5085 return [string match -nocase $findpattern $f] 5086 } else { 5087 return [string match $findpattern $f] 5088 } 5089 } 5090 5091 proc askfindhighlight {row id} { 5092 global nhighlights commitinfo iddrawn 5093 global findloc 5094 global markingmatches 5095 5096 if {![info exists commitinfo($id)]} { 5097 getcommit $id 5098 } 5099 set info $commitinfo($id) 5100 set isbold 0 5101 set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]] 5102 foreach f $info ty $fldtypes { 5103 if {$ty eq ""} continue 5104 if {($findloc eq [mc "All fields"] || $findloc eq $ty) && 5105 [doesmatch $f]} { 5106 if {$ty eq [mc "Author"]} { 5107 set isbold 2 5108 break 5109 } 5110 set isbold 1 5111 } 5112 } 5113 if {$isbold && [info exists iddrawn($id)]} { 5114 if {![ishighlighted $id]} { 5115 bolden $id mainfontbold 5116 if {$isbold > 1} { 5117 bolden_name $id mainfontbold 5118 } 5119 } 5120 if {$markingmatches} { 5121 markrowmatches $row $id 5122 } 5123 } 5124 set nhighlights($id) $isbold 5125 } 5126 5127 proc markrowmatches {row id} { 5128 global canv canv2 linehtag linentag commitinfo findloc 5129 5130 set headline [lindex $commitinfo($id) 0] 5131 set author [lindex $commitinfo($id) 1] 5132 $canv delete match$row 5133 $canv2 delete match$row 5134 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} { 5135 set m [findmatches $headline] 5136 if {$m ne {}} { 5137 markmatches $canv $row $headline $linehtag($id) $m \ 5138 [$canv itemcget $linehtag($id) -font] $row 5139 } 5140 } 5141 if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} { 5142 set m [findmatches $author] 5143 if {$m ne {}} { 5144 markmatches $canv2 $row $author $linentag($id) $m \ 5145 [$canv2 itemcget $linentag($id) -font] $row 5146 } 5147 } 5148 } 5149 5150 proc vrel_change {name ix op} { 5151 global highlight_related 5152 5153 rhighlight_none 5154 if {$highlight_related ne [mc "None"]} { 5155 run drawvisible 5156 } 5157 } 5158 5159 # prepare for testing whether commits are descendents or ancestors of a 5160 proc rhighlight_sel {a} { 5161 global descendent desc_todo ancestor anc_todo 5162 global highlight_related 5163 5164 unset -nocomplain descendent 5165 set desc_todo [list $a] 5166 unset -nocomplain ancestor 5167 set anc_todo [list $a] 5168 if {$highlight_related ne [mc "None"]} { 5169 rhighlight_none 5170 run drawvisible 5171 } 5172 } 5173 5174 proc rhighlight_none {} { 5175 global rhighlights 5176 5177 unset -nocomplain rhighlights 5178 unbolden 5179 } 5180 5181 proc is_descendent {a} { 5182 global curview children descendent desc_todo 5183 5184 set v $curview 5185 set la [rowofcommit $a] 5186 set todo $desc_todo 5187 set leftover {} 5188 set done 0 5189 for {set i 0} {$i < [llength $todo]} {incr i} { 5190 set do [lindex $todo $i] 5191 if {[rowofcommit $do] < $la} { 5192 lappend leftover $do 5193 continue 5194 } 5195 foreach nk $children($v,$do) { 5196 if {![info exists descendent($nk)]} { 5197 set descendent($nk) 1 5198 lappend todo $nk 5199 if {$nk eq $a} { 5200 set done 1 5201 } 5202 } 5203 } 5204 if {$done} { 5205 set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]] 5206 return 5207 } 5208 } 5209 set descendent($a) 0 5210 set desc_todo $leftover 5211 } 5212 5213 proc is_ancestor {a} { 5214 global curview parents ancestor anc_todo 5215 5216 set v $curview 5217 set la [rowofcommit $a] 5218 set todo $anc_todo 5219 set leftover {} 5220 set done 0 5221 for {set i 0} {$i < [llength $todo]} {incr i} { 5222 set do [lindex $todo $i] 5223 if {![commitinview $do $v] || [rowofcommit $do] > $la} { 5224 lappend leftover $do 5225 continue 5226 } 5227 foreach np $parents($v,$do) { 5228 if {![info exists ancestor($np)]} { 5229 set ancestor($np) 1 5230 lappend todo $np 5231 if {$np eq $a} { 5232 set done 1 5233 } 5234 } 5235 } 5236 if {$done} { 5237 set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]] 5238 return 5239 } 5240 } 5241 set ancestor($a) 0 5242 set anc_todo $leftover 5243 } 5244 5245 proc askrelhighlight {row id} { 5246 global descendent highlight_related iddrawn rhighlights 5247 global selectedline ancestor 5248 5249 if {$selectedline eq {}} return 5250 set isbold 0 5251 if {$highlight_related eq [mc "Descendant"] || 5252 $highlight_related eq [mc "Not descendant"]} { 5253 if {![info exists descendent($id)]} { 5254 is_descendent $id 5255 } 5256 if {$descendent($id) == ($highlight_related eq [mc "Descendant"])} { 5257 set isbold 1 5258 } 5259 } elseif {$highlight_related eq [mc "Ancestor"] || 5260 $highlight_related eq [mc "Not ancestor"]} { 5261 if {![info exists ancestor($id)]} { 5262 is_ancestor $id 5263 } 5264 if {$ancestor($id) == ($highlight_related eq [mc "Ancestor"])} { 5265 set isbold 1 5266 } 5267 } 5268 if {[info exists iddrawn($id)]} { 5269 if {$isbold && ![ishighlighted $id]} { 5270 bolden $id mainfontbold 5271 } 5272 } 5273 set rhighlights($id) $isbold 5274 } 5275 5276 # Graph layout functions 5277 5278 proc shortids {ids} { 5279 global hashlength 5280 5281 set res {} 5282 foreach id $ids { 5283 if {[llength $id] > 1} { 5284 lappend res [shortids $id] 5285 } elseif {[regexp [string map "@@ $hashlength" {^[0-9a-f]{@@}$}] $id]} { 5286 lappend res [string range $id 0 7] 5287 } else { 5288 lappend res $id 5289 } 5290 } 5291 return $res 5292 } 5293 5294 proc ntimes {n o} { 5295 set ret {} 5296 set o [list $o] 5297 for {set mask 1} {$mask <= $n} {incr mask $mask} { 5298 if {($n & $mask) != 0} { 5299 set ret [concat $ret $o] 5300 } 5301 set o [concat $o $o] 5302 } 5303 return $ret 5304 } 5305 5306 proc ordertoken {id} { 5307 global ordertok curview varcid varcstart varctok curview parents children 5308 global nullid nullid2 5309 5310 if {[info exists ordertok($id)]} { 5311 return $ordertok($id) 5312 } 5313 set origid $id 5314 set todo {} 5315 while {1} { 5316 if {[info exists varcid($curview,$id)]} { 5317 set a $varcid($curview,$id) 5318 set p [lindex $varcstart($curview) $a] 5319 } else { 5320 set p [lindex $children($curview,$id) 0] 5321 } 5322 if {[info exists ordertok($p)]} { 5323 set tok $ordertok($p) 5324 break 5325 } 5326 set id [first_real_child $curview,$p] 5327 if {$id eq {}} { 5328 # it's a root 5329 set tok [lindex $varctok($curview) $varcid($curview,$p)] 5330 break 5331 } 5332 if {[llength $parents($curview,$id)] == 1} { 5333 lappend todo [list $p {}] 5334 } else { 5335 set j [lsearch -exact $parents($curview,$id) $p] 5336 if {$j < 0} { 5337 puts "oops didn't find [shortids $p] in parents of [shortids $id]" 5338 } 5339 lappend todo [list $p [strrep $j]] 5340 } 5341 } 5342 for {set i [llength $todo]} {[incr i -1] >= 0} {} { 5343 set p [lindex $todo $i 0] 5344 append tok [lindex $todo $i 1] 5345 set ordertok($p) $tok 5346 } 5347 set ordertok($origid) $tok 5348 return $tok 5349 } 5350 5351 # Work out where id should go in idlist so that order-token 5352 # values increase from left to right 5353 proc idcol {idlist id {i 0}} { 5354 set t [ordertoken $id] 5355 if {$i < 0} { 5356 set i 0 5357 } 5358 if {$i >= [llength $idlist] || $t < [ordertoken [lindex $idlist $i]]} { 5359 if {$i > [llength $idlist]} { 5360 set i [llength $idlist] 5361 } 5362 while {[incr i -1] >= 0 && $t < [ordertoken [lindex $idlist $i]]} {} 5363 incr i 5364 } else { 5365 if {$t > [ordertoken [lindex $idlist $i]]} { 5366 while {[incr i] < [llength $idlist] && 5367 $t >= [ordertoken [lindex $idlist $i]]} {} 5368 } 5369 } 5370 return $i 5371 } 5372 5373 proc initlayout {} { 5374 global rowidlist rowisopt rowfinal displayorder parentlist 5375 global numcommits canvxmax canv 5376 global nextcolor 5377 global colormap rowtextx 5378 5379 set numcommits 0 5380 set displayorder {} 5381 set parentlist {} 5382 set nextcolor 0 5383 set rowidlist {} 5384 set rowisopt {} 5385 set rowfinal {} 5386 set canvxmax [$canv cget -width] 5387 unset -nocomplain colormap 5388 unset -nocomplain rowtextx 5389 setcanvscroll 5390 } 5391 5392 proc setcanvscroll {} { 5393 global canv canv2 canv3 numcommits linespc canvxmax canvy0 5394 global lastscrollset lastscrollrows 5395 5396 set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}] 5397 $canv conf -scrollregion [list 0 0 $canvxmax $ymax] 5398 $canv2 conf -scrollregion [list 0 0 0 $ymax] 5399 $canv3 conf -scrollregion [list 0 0 0 $ymax] 5400 set lastscrollset [clock clicks -milliseconds] 5401 set lastscrollrows $numcommits 5402 } 5403 5404 proc visiblerows {} { 5405 global canv numcommits linespc 5406 5407 set ymax [lindex [$canv cget -scrollregion] 3] 5408 if {$ymax eq {} || $ymax == 0} return 5409 set f [$canv yview] 5410 set y0 [expr {int([lindex $f 0] * $ymax)}] 5411 set r0 [expr {int(($y0 - 3) / $linespc) - 1}] 5412 if {$r0 < 0} { 5413 set r0 0 5414 } 5415 set y1 [expr {int([lindex $f 1] * $ymax)}] 5416 set r1 [expr {int(($y1 - 3) / $linespc) + 1}] 5417 if {$r1 >= $numcommits} { 5418 set r1 [expr {$numcommits - 1}] 5419 } 5420 return [list $r0 $r1] 5421 } 5422 5423 proc layoutmore {} { 5424 global commitidx viewcomplete curview 5425 global numcommits pending_select curview 5426 global lastscrollset lastscrollrows 5427 5428 if {$lastscrollrows < 100 || $viewcomplete($curview) || 5429 [clock clicks -milliseconds] - $lastscrollset > 500} { 5430 setcanvscroll 5431 } 5432 if {[info exists pending_select] && 5433 [commitinview $pending_select $curview]} { 5434 update 5435 selectline [rowofcommit $pending_select] 1 5436 } 5437 drawvisible 5438 } 5439 5440 # With path limiting, we mightn't get the actual HEAD commit, 5441 # so ask git rev-list what is the first ancestor of HEAD that 5442 # touches a file in the path limit. 5443 proc get_viewmainhead {view} { 5444 global viewmainheadid vfilelimit viewinstances mainheadid 5445 5446 catch { 5447 set rfd [safe_open_command [concat git rev-list -1 $mainheadid \ 5448 -- $vfilelimit($view)]] 5449 set j [reg_instance $rfd] 5450 lappend viewinstances($view) $j 5451 fconfigure $rfd -blocking 0 5452 filerun $rfd [list getviewhead $rfd $j $view] 5453 set viewmainheadid($curview) {} 5454 } 5455 } 5456 5457 # git rev-list should give us just 1 line to use as viewmainheadid($view) 5458 proc getviewhead {fd inst view} { 5459 global viewmainheadid commfd curview viewinstances showlocalchanges 5460 global hashlength 5461 5462 set id {} 5463 if {[gets $fd line] < 0} { 5464 if {![eof $fd]} { 5465 return 1 5466 } 5467 } elseif {[string length $line] == $hashlength && [string is xdigit $line]} { 5468 set id $line 5469 } 5470 set viewmainheadid($view) $id 5471 close $fd 5472 unset commfd($inst) 5473 set i [lsearch -exact $viewinstances($view) $inst] 5474 if {$i >= 0} { 5475 set viewinstances($view) [lreplace $viewinstances($view) $i $i] 5476 } 5477 if {$showlocalchanges && $id ne {} && $view == $curview} { 5478 doshowlocalchanges 5479 } 5480 return 0 5481 } 5482 5483 proc doshowlocalchanges {} { 5484 global curview viewmainheadid 5485 5486 if {$viewmainheadid($curview) eq {}} return 5487 if {[commitinview $viewmainheadid($curview) $curview]} { 5488 dodiffindex 5489 } else { 5490 interestedin $viewmainheadid($curview) dodiffindex 5491 } 5492 } 5493 5494 proc dohidelocalchanges {} { 5495 global nullid nullid2 lserial curview 5496 5497 if {[commitinview $nullid $curview]} { 5498 removefakerow $nullid 5499 } 5500 if {[commitinview $nullid2 $curview]} { 5501 removefakerow $nullid2 5502 } 5503 incr lserial 5504 } 5505 5506 # spawn off a process to do git diff-index --cached HEAD 5507 proc dodiffindex {} { 5508 global lserial showlocalchanges vfilelimit curview 5509 global hasworktree 5510 5511 if {!$showlocalchanges || !$hasworktree} return 5512 incr lserial 5513 set cmd "git diff-index --cached --ignore-submodules=dirty HEAD" 5514 if {$vfilelimit($curview) ne {}} { 5515 set cmd [concat $cmd -- $vfilelimit($curview)] 5516 } 5517 set fd [safe_open_command $cmd] 5518 fconfigure $fd -blocking 0 5519 set i [reg_instance $fd] 5520 filerun $fd [list readdiffindex $fd $lserial $i] 5521 } 5522 5523 proc readdiffindex {fd serial inst} { 5524 global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial 5525 global vfilelimit 5526 5527 set isdiff 1 5528 if {[gets $fd line] < 0} { 5529 if {![eof $fd]} { 5530 return 1 5531 } 5532 set isdiff 0 5533 } 5534 # we only need to see one line and we don't really care what it says... 5535 stop_instance $inst 5536 5537 if {$serial != $lserial} { 5538 return 0 5539 } 5540 5541 # now see if there are any local changes not checked in to the index 5542 set cmd "git diff-files" 5543 if {$vfilelimit($curview) ne {}} { 5544 set cmd [concat $cmd -- $vfilelimit($curview)] 5545 } 5546 set fd [safe_open_command $cmd] 5547 fconfigure $fd -blocking 0 5548 set i [reg_instance $fd] 5549 filerun $fd [list readdifffiles $fd $serial $i] 5550 5551 if {$isdiff && ![commitinview $nullid2 $curview]} { 5552 # add the line for the changes in the index to the graph 5553 set hl [mc "Local changes checked in to index but not committed"] 5554 set commitinfo($nullid2) [list $hl {} {} {} {} " $hl\n"] 5555 set commitdata($nullid2) "\n $hl\n" 5556 if {[commitinview $nullid $curview]} { 5557 removefakerow $nullid 5558 } 5559 insertfakerow $nullid2 $viewmainheadid($curview) 5560 } elseif {!$isdiff && [commitinview $nullid2 $curview]} { 5561 if {[commitinview $nullid $curview]} { 5562 removefakerow $nullid 5563 } 5564 removefakerow $nullid2 5565 } 5566 return 0 5567 } 5568 5569 proc readdifffiles {fd serial inst} { 5570 global viewmainheadid nullid nullid2 curview 5571 global commitinfo commitdata lserial 5572 5573 set isdiff 1 5574 if {[gets $fd line] < 0} { 5575 if {![eof $fd]} { 5576 return 1 5577 } 5578 set isdiff 0 5579 } 5580 # we only need to see one line and we don't really care what it says... 5581 stop_instance $inst 5582 5583 if {$serial != $lserial} { 5584 return 0 5585 } 5586 5587 if {$isdiff && ![commitinview $nullid $curview]} { 5588 # add the line for the local diff to the graph 5589 set hl [mc "Local uncommitted changes, not checked in to index"] 5590 set commitinfo($nullid) [list $hl {} {} {} {} " $hl\n"] 5591 set commitdata($nullid) "\n $hl\n" 5592 if {[commitinview $nullid2 $curview]} { 5593 set p $nullid2 5594 } else { 5595 set p $viewmainheadid($curview) 5596 } 5597 insertfakerow $nullid $p 5598 } elseif {!$isdiff && [commitinview $nullid $curview]} { 5599 removefakerow $nullid 5600 } 5601 return 0 5602 } 5603 5604 proc nextuse {id row} { 5605 global curview children 5606 5607 if {[info exists children($curview,$id)]} { 5608 foreach kid $children($curview,$id) { 5609 if {![commitinview $kid $curview]} { 5610 return -1 5611 } 5612 if {[rowofcommit $kid] > $row} { 5613 return [rowofcommit $kid] 5614 } 5615 } 5616 } 5617 if {[commitinview $id $curview]} { 5618 return [rowofcommit $id] 5619 } 5620 return -1 5621 } 5622 5623 proc prevuse {id row} { 5624 global curview children 5625 5626 set ret -1 5627 if {[info exists children($curview,$id)]} { 5628 foreach kid $children($curview,$id) { 5629 if {![commitinview $kid $curview]} break 5630 if {[rowofcommit $kid] < $row} { 5631 set ret [rowofcommit $kid] 5632 } 5633 } 5634 } 5635 return $ret 5636 } 5637 5638 proc make_idlist {row} { 5639 global displayorder parentlist uparrowlen downarrowlen mingaplen 5640 global commitidx curview children 5641 5642 set r [expr {$row - $mingaplen - $downarrowlen - 1}] 5643 if {$r < 0} { 5644 set r 0 5645 } 5646 set ra [expr {$row - $downarrowlen}] 5647 if {$ra < 0} { 5648 set ra 0 5649 } 5650 set rb [expr {$row + $uparrowlen}] 5651 if {$rb > $commitidx($curview)} { 5652 set rb $commitidx($curview) 5653 } 5654 make_disporder $r [expr {$rb + 1}] 5655 set ids {} 5656 for {} {$r < $ra} {incr r} { 5657 set nextid [lindex $displayorder [expr {$r + 1}]] 5658 foreach p [lindex $parentlist $r] { 5659 if {$p eq $nextid} continue 5660 set rn [nextuse $p $r] 5661 if {$rn >= $row && 5662 $rn <= $r + $downarrowlen + $mingaplen + $uparrowlen} { 5663 lappend ids [list [ordertoken $p] $p] 5664 } 5665 } 5666 } 5667 for {} {$r < $row} {incr r} { 5668 set nextid [lindex $displayorder [expr {$r + 1}]] 5669 foreach p [lindex $parentlist $r] { 5670 if {$p eq $nextid} continue 5671 set rn [nextuse $p $r] 5672 if {$rn < 0 || $rn >= $row} { 5673 lappend ids [list [ordertoken $p] $p] 5674 } 5675 } 5676 } 5677 set id [lindex $displayorder $row] 5678 lappend ids [list [ordertoken $id] $id] 5679 while {$r < $rb} { 5680 foreach p [lindex $parentlist $r] { 5681 set firstkid [lindex $children($curview,$p) 0] 5682 if {[rowofcommit $firstkid] < $row} { 5683 lappend ids [list [ordertoken $p] $p] 5684 } 5685 } 5686 incr r 5687 set id [lindex $displayorder $r] 5688 if {$id ne {}} { 5689 set firstkid [lindex $children($curview,$id) 0] 5690 if {$firstkid ne {} && [rowofcommit $firstkid] < $row} { 5691 lappend ids [list [ordertoken $id] $id] 5692 } 5693 } 5694 } 5695 set idlist {} 5696 foreach idx [lsort -unique $ids] { 5697 lappend idlist [lindex $idx 1] 5698 } 5699 return $idlist 5700 } 5701 5702 proc rowsequal {a b} { 5703 while {[set i [lsearch -exact $a {}]] >= 0} { 5704 set a [lreplace $a $i $i] 5705 } 5706 while {[set i [lsearch -exact $b {}]] >= 0} { 5707 set b [lreplace $b $i $i] 5708 } 5709 return [expr {$a eq $b}] 5710 } 5711 5712 proc makeupline {id row rend col} { 5713 global rowidlist uparrowlen downarrowlen mingaplen 5714 5715 for {set r $rend} {1} {set r $rstart} { 5716 set rstart [prevuse $id $r] 5717 if {$rstart < 0} return 5718 if {$rstart < $row} break 5719 } 5720 if {$rstart + $uparrowlen + $mingaplen + $downarrowlen < $rend} { 5721 set rstart [expr {$rend - $uparrowlen - 1}] 5722 } 5723 for {set r $rstart} {[incr r] <= $row} {} { 5724 set idlist [lindex $rowidlist $r] 5725 if {$idlist ne {} && [lsearch -exact $idlist $id] < 0} { 5726 set col [idcol $idlist $id $col] 5727 lset rowidlist $r [linsert $idlist $col $id] 5728 changedrow $r 5729 } 5730 } 5731 } 5732 5733 proc layoutrows {row endrow} { 5734 global rowidlist rowisopt rowfinal displayorder 5735 global uparrowlen downarrowlen maxwidth mingaplen 5736 global children parentlist 5737 global commitidx viewcomplete curview 5738 5739 make_disporder [expr {$row - 1}] [expr {$endrow + $uparrowlen}] 5740 set idlist {} 5741 if {$row > 0} { 5742 set rm1 [expr {$row - 1}] 5743 foreach id [lindex $rowidlist $rm1] { 5744 if {$id ne {}} { 5745 lappend idlist $id 5746 } 5747 } 5748 set final [lindex $rowfinal $rm1] 5749 } 5750 for {} {$row < $endrow} {incr row} { 5751 set rm1 [expr {$row - 1}] 5752 if {$rm1 < 0 || $idlist eq {}} { 5753 set idlist [make_idlist $row] 5754 set final 1 5755 } else { 5756 set id [lindex $displayorder $rm1] 5757 set col [lsearch -exact $idlist $id] 5758 set idlist [lreplace $idlist $col $col] 5759 foreach p [lindex $parentlist $rm1] { 5760 if {[lsearch -exact $idlist $p] < 0} { 5761 set col [idcol $idlist $p $col] 5762 set idlist [linsert $idlist $col $p] 5763 # if not the first child, we have to insert a line going up 5764 if {$id ne [lindex $children($curview,$p) 0]} { 5765 makeupline $p $rm1 $row $col 5766 } 5767 } 5768 } 5769 set id [lindex $displayorder $row] 5770 if {$row > $downarrowlen} { 5771 set termrow [expr {$row - $downarrowlen - 1}] 5772 foreach p [lindex $parentlist $termrow] { 5773 set i [lsearch -exact $idlist $p] 5774 if {$i < 0} continue 5775 set nr [nextuse $p $termrow] 5776 if {$nr < 0 || $nr >= $row + $mingaplen + $uparrowlen} { 5777 set idlist [lreplace $idlist $i $i] 5778 } 5779 } 5780 } 5781 set col [lsearch -exact $idlist $id] 5782 if {$col < 0} { 5783 set col [idcol $idlist $id] 5784 set idlist [linsert $idlist $col $id] 5785 if {$children($curview,$id) ne {}} { 5786 makeupline $id $rm1 $row $col 5787 } 5788 } 5789 set r [expr {$row + $uparrowlen - 1}] 5790 if {$r < $commitidx($curview)} { 5791 set x $col 5792 foreach p [lindex $parentlist $r] { 5793 if {[lsearch -exact $idlist $p] >= 0} continue 5794 set fk [lindex $children($curview,$p) 0] 5795 if {[rowofcommit $fk] < $row} { 5796 set x [idcol $idlist $p $x] 5797 set idlist [linsert $idlist $x $p] 5798 } 5799 } 5800 if {[incr r] < $commitidx($curview)} { 5801 set p [lindex $displayorder $r] 5802 if {[lsearch -exact $idlist $p] < 0} { 5803 set fk [lindex $children($curview,$p) 0] 5804 if {$fk ne {} && [rowofcommit $fk] < $row} { 5805 set x [idcol $idlist $p $x] 5806 set idlist [linsert $idlist $x $p] 5807 } 5808 } 5809 } 5810 } 5811 } 5812 if {$final && !$viewcomplete($curview) && 5813 $row + $uparrowlen + $mingaplen + $downarrowlen 5814 >= $commitidx($curview)} { 5815 set final 0 5816 } 5817 set l [llength $rowidlist] 5818 if {$row == $l} { 5819 lappend rowidlist $idlist 5820 lappend rowisopt 0 5821 lappend rowfinal $final 5822 } elseif {$row < $l} { 5823 if {![rowsequal $idlist [lindex $rowidlist $row]]} { 5824 lset rowidlist $row $idlist 5825 changedrow $row 5826 } 5827 lset rowfinal $row $final 5828 } else { 5829 set pad [ntimes [expr {$row - $l}] {}] 5830 set rowidlist [concat $rowidlist $pad] 5831 lappend rowidlist $idlist 5832 set rowfinal [concat $rowfinal $pad] 5833 lappend rowfinal $final 5834 set rowisopt [concat $rowisopt [ntimes [expr {$row - $l + 1}] 0]] 5835 } 5836 } 5837 return $row 5838 } 5839 5840 proc changedrow {row} { 5841 global displayorder iddrawn rowisopt need_redisplay 5842 5843 set l [llength $rowisopt] 5844 if {$row < $l} { 5845 lset rowisopt $row 0 5846 if {$row + 1 < $l} { 5847 lset rowisopt [expr {$row + 1}] 0 5848 if {$row + 2 < $l} { 5849 lset rowisopt [expr {$row + 2}] 0 5850 } 5851 } 5852 } 5853 set id [lindex $displayorder $row] 5854 if {[info exists iddrawn($id)]} { 5855 set need_redisplay 1 5856 } 5857 } 5858 5859 proc insert_pad {row col npad} { 5860 global rowidlist 5861 5862 set pad [ntimes $npad {}] 5863 set idlist [lindex $rowidlist $row] 5864 set bef [lrange $idlist 0 [expr {$col - 1}]] 5865 set aft [lrange $idlist $col end] 5866 set i [lsearch -exact $aft {}] 5867 if {$i > 0} { 5868 set aft [lreplace $aft $i $i] 5869 } 5870 lset rowidlist $row [concat $bef $pad $aft] 5871 changedrow $row 5872 } 5873 5874 proc optimize_rows {row col endrow} { 5875 global rowidlist rowisopt displayorder curview children 5876 5877 if {$row < 1} { 5878 set row 1 5879 } 5880 for {} {$row < $endrow} {incr row; set col 0} { 5881 if {[lindex $rowisopt $row]} continue 5882 set haspad 0 5883 set y0 [expr {$row - 1}] 5884 set ym [expr {$row - 2}] 5885 set idlist [lindex $rowidlist $row] 5886 set previdlist [lindex $rowidlist $y0] 5887 if {$idlist eq {} || $previdlist eq {}} continue 5888 if {$ym >= 0} { 5889 set pprevidlist [lindex $rowidlist $ym] 5890 if {$pprevidlist eq {}} continue 5891 } else { 5892 set pprevidlist {} 5893 } 5894 set x0 -1 5895 set xm -1 5896 for {} {$col < [llength $idlist]} {incr col} { 5897 set id [lindex $idlist $col] 5898 if {[lindex $previdlist $col] eq $id} continue 5899 if {$id eq {}} { 5900 set haspad 1 5901 continue 5902 } 5903 set x0 [lsearch -exact $previdlist $id] 5904 if {$x0 < 0} continue 5905 set z [expr {$x0 - $col}] 5906 set isarrow 0 5907 set z0 {} 5908 if {$ym >= 0} { 5909 set xm [lsearch -exact $pprevidlist $id] 5910 if {$xm >= 0} { 5911 set z0 [expr {$xm - $x0}] 5912 } 5913 } 5914 if {$z0 eq {}} { 5915 # if row y0 is the first child of $id then it's not an arrow 5916 if {[lindex $children($curview,$id) 0] ne 5917 [lindex $displayorder $y0]} { 5918 set isarrow 1 5919 } 5920 } 5921 if {!$isarrow && $id ne [lindex $displayorder $row] && 5922 [lsearch -exact [lindex $rowidlist [expr {$row+1}]] $id] < 0} { 5923 set isarrow 1 5924 } 5925 # Looking at lines from this row to the previous row, 5926 # make them go straight up if they end in an arrow on 5927 # the previous row; otherwise make them go straight up 5928 # or at 45 degrees. 5929 if {$z < -1 || ($z < 0 && $isarrow)} { 5930 # Line currently goes left too much; 5931 # insert pads in the previous row, then optimize it 5932 set npad [expr {-1 - $z + $isarrow}] 5933 insert_pad $y0 $x0 $npad 5934 if {$y0 > 0} { 5935 optimize_rows $y0 $x0 $row 5936 } 5937 set previdlist [lindex $rowidlist $y0] 5938 set x0 [lsearch -exact $previdlist $id] 5939 set z [expr {$x0 - $col}] 5940 if {$z0 ne {}} { 5941 set pprevidlist [lindex $rowidlist $ym] 5942 set xm [lsearch -exact $pprevidlist $id] 5943 set z0 [expr {$xm - $x0}] 5944 } 5945 } elseif {$z > 1 || ($z > 0 && $isarrow)} { 5946 # Line currently goes right too much; 5947 # insert pads in this line 5948 set npad [expr {$z - 1 + $isarrow}] 5949 insert_pad $row $col $npad 5950 set idlist [lindex $rowidlist $row] 5951 incr col $npad 5952 set z [expr {$x0 - $col}] 5953 set haspad 1 5954 } 5955 if {$z0 eq {} && !$isarrow && $ym >= 0} { 5956 # this line links to its first child on row $row-2 5957 set id [lindex $displayorder $ym] 5958 set xc [lsearch -exact $pprevidlist $id] 5959 if {$xc >= 0} { 5960 set z0 [expr {$xc - $x0}] 5961 } 5962 } 5963 # avoid lines jigging left then immediately right 5964 if {$z0 ne {} && $z < 0 && $z0 > 0} { 5965 insert_pad $y0 $x0 1 5966 incr x0 5967 optimize_rows $y0 $x0 $row 5968 set previdlist [lindex $rowidlist $y0] 5969 } 5970 } 5971 if {!$haspad} { 5972 # Find the first column that doesn't have a line going right 5973 for {set col [llength $idlist]} {[incr col -1] >= 0} {} { 5974 set id [lindex $idlist $col] 5975 if {$id eq {}} break 5976 set x0 [lsearch -exact $previdlist $id] 5977 if {$x0 < 0} { 5978 # check if this is the link to the first child 5979 set kid [lindex $displayorder $y0] 5980 if {[lindex $children($curview,$id) 0] eq $kid} { 5981 # it is, work out offset to child 5982 set x0 [lsearch -exact $previdlist $kid] 5983 } 5984 } 5985 if {$x0 <= $col} break 5986 } 5987 # Insert a pad at that column as long as it has a line and 5988 # isn't the last column 5989 if {$x0 >= 0 && [incr col] < [llength $idlist]} { 5990 set idlist [linsert $idlist $col {}] 5991 lset rowidlist $row $idlist 5992 changedrow $row 5993 } 5994 } 5995 } 5996 } 5997 5998 proc xc {row col} { 5999 global canvx0 linespc 6000 return [expr {$canvx0 + $col * $linespc}] 6001 } 6002 6003 proc yc {row} { 6004 global canvy0 linespc 6005 return [expr {$canvy0 + $row * $linespc}] 6006 } 6007 6008 proc linewidth {id} { 6009 global thickerline lthickness 6010 6011 set wid $lthickness 6012 if {[info exists thickerline] && $id eq $thickerline} { 6013 set wid [expr {2 * $lthickness}] 6014 } 6015 return $wid 6016 } 6017 6018 proc rowranges {id} { 6019 global curview children uparrowlen downarrowlen 6020 global rowidlist 6021 6022 set kids $children($curview,$id) 6023 if {$kids eq {}} { 6024 return {} 6025 } 6026 set ret {} 6027 lappend kids $id 6028 foreach child $kids { 6029 if {![commitinview $child $curview]} break 6030 set row [rowofcommit $child] 6031 if {![info exists prev]} { 6032 lappend ret [expr {$row + 1}] 6033 } else { 6034 if {$row <= $prevrow} { 6035 puts "oops children of [shortids $id] out of order [shortids $child] $row <= [shortids $prev] $prevrow" 6036 } 6037 # see if the line extends the whole way from prevrow to row 6038 if {$row > $prevrow + $uparrowlen + $downarrowlen && 6039 [lsearch -exact [lindex $rowidlist \ 6040 [expr {int(($row + $prevrow) / 2)}]] $id] < 0} { 6041 # it doesn't, see where it ends 6042 set r [expr {$prevrow + $downarrowlen}] 6043 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} { 6044 while {[incr r -1] > $prevrow && 6045 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {} 6046 } else { 6047 while {[incr r] <= $row && 6048 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {} 6049 incr r -1 6050 } 6051 lappend ret $r 6052 # see where it starts up again 6053 set r [expr {$row - $uparrowlen}] 6054 if {[lsearch -exact [lindex $rowidlist $r] $id] < 0} { 6055 while {[incr r] < $row && 6056 [lsearch -exact [lindex $rowidlist $r] $id] < 0} {} 6057 } else { 6058 while {[incr r -1] >= $prevrow && 6059 [lsearch -exact [lindex $rowidlist $r] $id] >= 0} {} 6060 incr r 6061 } 6062 lappend ret $r 6063 } 6064 } 6065 if {$child eq $id} { 6066 lappend ret $row 6067 } 6068 set prev $child 6069 set prevrow $row 6070 } 6071 return $ret 6072 } 6073 6074 proc drawlineseg {id row endrow arrowlow} { 6075 global rowidlist displayorder iddrawn linesegs 6076 global canv colormap linespc curview maxlinelen parentlist 6077 6078 set cols [list [lsearch -exact [lindex $rowidlist $row] $id]] 6079 set le [expr {$row + 1}] 6080 set arrowhigh 1 6081 while {1} { 6082 set c [lsearch -exact [lindex $rowidlist $le] $id] 6083 if {$c < 0} { 6084 incr le -1 6085 break 6086 } 6087 lappend cols $c 6088 set x [lindex $displayorder $le] 6089 if {$x eq $id} { 6090 set arrowhigh 0 6091 break 6092 } 6093 if {[info exists iddrawn($x)] || $le == $endrow} { 6094 set c [lsearch -exact [lindex $rowidlist [expr {$le+1}]] $id] 6095 if {$c >= 0} { 6096 lappend cols $c 6097 set arrowhigh 0 6098 } 6099 break 6100 } 6101 incr le 6102 } 6103 if {$le <= $row} { 6104 return $row 6105 } 6106 6107 set lines {} 6108 set i 0 6109 set joinhigh 0 6110 if {[info exists linesegs($id)]} { 6111 set lines $linesegs($id) 6112 foreach li $lines { 6113 set r0 [lindex $li 0] 6114 if {$r0 > $row} { 6115 if {$r0 == $le && [lindex $li 1] - $row <= $maxlinelen} { 6116 set joinhigh 1 6117 } 6118 break 6119 } 6120 incr i 6121 } 6122 } 6123 set joinlow 0 6124 if {$i > 0} { 6125 set li [lindex $lines [expr {$i-1}]] 6126 set r1 [lindex $li 1] 6127 if {$r1 == $row && $le - [lindex $li 0] <= $maxlinelen} { 6128 set joinlow 1 6129 } 6130 } 6131 6132 set x [lindex $cols [expr {$le - $row}]] 6133 set xp [lindex $cols [expr {$le - 1 - $row}]] 6134 set dir [expr {$xp - $x}] 6135 if {$joinhigh} { 6136 set ith [lindex $lines $i 2] 6137 set coords [$canv coords $ith] 6138 set ah [$canv itemcget $ith -arrow] 6139 set arrowhigh [expr {$ah eq "first" || $ah eq "both"}] 6140 set x2 [lindex $cols [expr {$le + 1 - $row}]] 6141 if {$x2 ne {} && $x - $x2 == $dir} { 6142 set coords [lrange $coords 0 end-2] 6143 } 6144 } else { 6145 set coords [list [xc $le $x] [yc $le]] 6146 } 6147 if {$joinlow} { 6148 set itl [lindex $lines [expr {$i-1}] 2] 6149 set al [$canv itemcget $itl -arrow] 6150 set arrowlow [expr {$al eq "last" || $al eq "both"}] 6151 } elseif {$arrowlow} { 6152 if {[lsearch -exact [lindex $rowidlist [expr {$row-1}]] $id] >= 0 || 6153 [lsearch -exact [lindex $parentlist [expr {$row-1}]] $id] >= 0} { 6154 set arrowlow 0 6155 } 6156 } 6157 set arrow [lindex {none first last both} [expr {$arrowhigh + 2*$arrowlow}]] 6158 for {set y $le} {[incr y -1] > $row} {} { 6159 set x $xp 6160 set xp [lindex $cols [expr {$y - 1 - $row}]] 6161 set ndir [expr {$xp - $x}] 6162 if {$dir != $ndir || $xp < 0} { 6163 lappend coords [xc $y $x] [yc $y] 6164 } 6165 set dir $ndir 6166 } 6167 if {!$joinlow} { 6168 if {$xp < 0} { 6169 # join parent line to first child 6170 set ch [lindex $displayorder $row] 6171 set xc [lsearch -exact [lindex $rowidlist $row] $ch] 6172 if {$xc < 0} { 6173 puts "oops: drawlineseg: child $ch not on row $row" 6174 } elseif {$xc != $x} { 6175 if {($arrowhigh && $le == $row + 1) || $dir == 0} { 6176 set d [expr {int(0.5 * $linespc)}] 6177 set x1 [xc $row $x] 6178 if {$xc < $x} { 6179 set x2 [expr {$x1 - $d}] 6180 } else { 6181 set x2 [expr {$x1 + $d}] 6182 } 6183 set y2 [yc $row] 6184 set y1 [expr {$y2 + $d}] 6185 lappend coords $x1 $y1 $x2 $y2 6186 } elseif {$xc < $x - 1} { 6187 lappend coords [xc $row [expr {$x-1}]] [yc $row] 6188 } elseif {$xc > $x + 1} { 6189 lappend coords [xc $row [expr {$x+1}]] [yc $row] 6190 } 6191 set x $xc 6192 } 6193 lappend coords [xc $row $x] [yc $row] 6194 } else { 6195 set xn [xc $row $xp] 6196 set yn [yc $row] 6197 lappend coords $xn $yn 6198 } 6199 if {!$joinhigh} { 6200 assigncolor $id 6201 set t [$canv create line $coords -width [linewidth $id] \ 6202 -fill $colormap($id) -tags lines.$id -arrow $arrow] 6203 $canv lower $t 6204 bindline $t $id 6205 set lines [linsert $lines $i [list $row $le $t]] 6206 } else { 6207 $canv coords $ith $coords 6208 if {$arrow ne $ah} { 6209 $canv itemconf $ith -arrow $arrow 6210 } 6211 lset lines $i 0 $row 6212 } 6213 } else { 6214 set xo [lsearch -exact [lindex $rowidlist [expr {$row - 1}]] $id] 6215 set ndir [expr {$xo - $xp}] 6216 set clow [$canv coords $itl] 6217 if {$dir == $ndir} { 6218 set clow [lrange $clow 2 end] 6219 } 6220 set coords [concat $coords $clow] 6221 if {!$joinhigh} { 6222 lset lines [expr {$i-1}] 1 $le 6223 } else { 6224 # coalesce two pieces 6225 $canv delete $ith 6226 set b [lindex $lines [expr {$i-1}] 0] 6227 set e [lindex $lines $i 1] 6228 set lines [lreplace $lines [expr {$i-1}] $i [list $b $e $itl]] 6229 } 6230 $canv coords $itl $coords 6231 if {$arrow ne $al} { 6232 $canv itemconf $itl -arrow $arrow 6233 } 6234 } 6235 6236 set linesegs($id) $lines 6237 return $le 6238 } 6239 6240 proc drawparentlinks {id row} { 6241 global rowidlist canv colormap curview parentlist 6242 global idpos linespc 6243 6244 set rowids [lindex $rowidlist $row] 6245 set col [lsearch -exact $rowids $id] 6246 if {$col < 0} return 6247 set olds [lindex $parentlist $row] 6248 set row2 [expr {$row + 1}] 6249 set x [xc $row $col] 6250 set y [yc $row] 6251 set y2 [yc $row2] 6252 set d [expr {int(0.5 * $linespc)}] 6253 set ymid [expr {$y + $d}] 6254 set ids [lindex $rowidlist $row2] 6255 # rmx = right-most X coord used 6256 set rmx 0 6257 foreach p $olds { 6258 set i [lsearch -exact $ids $p] 6259 if {$i < 0} { 6260 puts "oops, parent $p of $id not in list" 6261 continue 6262 } 6263 set x2 [xc $row2 $i] 6264 if {$x2 > $rmx} { 6265 set rmx $x2 6266 } 6267 set j [lsearch -exact $rowids $p] 6268 if {$j < 0} { 6269 # drawlineseg will do this one for us 6270 continue 6271 } 6272 assigncolor $p 6273 # should handle duplicated parents here... 6274 set coords [list $x $y] 6275 if {$i != $col} { 6276 # if attaching to a vertical segment, draw a smaller 6277 # slant for visual distinctness 6278 if {$i == $j} { 6279 if {$i < $col} { 6280 lappend coords [expr {$x2 + $d}] $y $x2 $ymid 6281 } else { 6282 lappend coords [expr {$x2 - $d}] $y $x2 $ymid 6283 } 6284 } elseif {$i < $col && $i < $j} { 6285 # segment slants towards us already 6286 lappend coords [xc $row $j] $y 6287 } else { 6288 if {$i < $col - 1} { 6289 lappend coords [expr {$x2 + $linespc}] $y 6290 } elseif {$i > $col + 1} { 6291 lappend coords [expr {$x2 - $linespc}] $y 6292 } 6293 lappend coords $x2 $y2 6294 } 6295 } else { 6296 lappend coords $x2 $y2 6297 } 6298 set t [$canv create line $coords -width [linewidth $p] \ 6299 -fill $colormap($p) -tags lines.$p] 6300 $canv lower $t 6301 bindline $t $p 6302 } 6303 if {$rmx > [lindex $idpos($id) 1]} { 6304 lset idpos($id) 1 $rmx 6305 redrawtags $id 6306 } 6307 } 6308 6309 proc drawlines {id} { 6310 global canv 6311 6312 $canv itemconf lines.$id -width [linewidth $id] 6313 } 6314 6315 proc drawcmittext {id row col} { 6316 global linespc canv canv2 canv3 fgcolor curview 6317 global cmitlisted commitinfo rowidlist parentlist 6318 global rowtextx idpos idtags idheads idotherrefs 6319 global linehtag linentag linedtag selectedline 6320 global canvxmax boldids boldnameids fgcolor markedid 6321 global mainheadid nullid nullid2 circleitem circlecolors ctxbut 6322 global mainheadcirclecolor workingfilescirclecolor indexcirclecolor 6323 global circleoutlinecolor 6324 6325 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right 6326 set listed $cmitlisted($curview,$id) 6327 if {$id eq $nullid} { 6328 set ofill $workingfilescirclecolor 6329 } elseif {$id eq $nullid2} { 6330 set ofill $indexcirclecolor 6331 } elseif {$id eq $mainheadid} { 6332 set ofill $mainheadcirclecolor 6333 } else { 6334 set ofill [lindex $circlecolors $listed] 6335 } 6336 set x [xc $row $col] 6337 set y [yc $row] 6338 set orad [expr {$linespc / 3}] 6339 if {$listed <= 2} { 6340 set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \ 6341 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \ 6342 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle] 6343 } elseif {$listed == 3} { 6344 # triangle pointing left for left-side commits 6345 set t [$canv create polygon \ 6346 [expr {$x - $orad}] $y \ 6347 [expr {$x + $orad - 1}] [expr {$y - $orad}] \ 6348 [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \ 6349 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle] 6350 } else { 6351 # triangle pointing right for right-side commits 6352 set t [$canv create polygon \ 6353 [expr {$x + $orad - 1}] $y \ 6354 [expr {$x - $orad}] [expr {$y - $orad}] \ 6355 [expr {$x - $orad}] [expr {$y + $orad - 1}] \ 6356 -fill $ofill -outline $circleoutlinecolor -width 1 -tags circle] 6357 } 6358 set circleitem($row) $t 6359 $canv raise $t 6360 $canv bind $t <1> {selcanvline {} %x %y} 6361 set rmx [llength [lindex $rowidlist $row]] 6362 set olds [lindex $parentlist $row] 6363 if {$olds ne {}} { 6364 set nextids [lindex $rowidlist [expr {$row + 1}]] 6365 foreach p $olds { 6366 set i [lsearch -exact $nextids $p] 6367 if {$i > $rmx} { 6368 set rmx $i 6369 } 6370 } 6371 } 6372 set xt [xc $row $rmx] 6373 set rowtextx($row) $xt 6374 set idpos($id) [list $x $xt $y] 6375 if {[info exists idtags($id)] || [info exists idheads($id)] 6376 || [info exists idotherrefs($id)]} { 6377 set xt [drawtags $id $x $xt $y] 6378 } 6379 if {[lindex $commitinfo($id) 6] > 0} { 6380 set xt [drawnotesign $xt $y] 6381 } 6382 set headline [lindex $commitinfo($id) 0] 6383 set name [lindex $commitinfo($id) 1] 6384 set date [lindex $commitinfo($id) 2] 6385 set date [formatdate $date] 6386 set font mainfont 6387 set nfont mainfont 6388 set isbold [ishighlighted $id] 6389 if {$isbold > 0} { 6390 lappend boldids $id 6391 set font mainfontbold 6392 if {$isbold > 1} { 6393 lappend boldnameids $id 6394 set nfont mainfontbold 6395 } 6396 } 6397 set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \ 6398 -text $headline -font $font -tags text] 6399 $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id" 6400 set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \ 6401 -text $name -font $nfont -tags text] 6402 set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ 6403 -text $date -font mainfont -tags text] 6404 if {$selectedline == $row} { 6405 make_secsel $id 6406 } 6407 if {[info exists markedid] && $markedid eq $id} { 6408 make_idmark $id 6409 } 6410 set xr [expr {$xt + [font measure $font $headline]}] 6411 if {$xr > $canvxmax} { 6412 set canvxmax $xr 6413 setcanvscroll 6414 } 6415 } 6416 6417 proc drawcmitrow {row} { 6418 global displayorder rowidlist nrows_drawn 6419 global iddrawn markingmatches 6420 global commitinfo numcommits 6421 global filehighlight fhighlights findpattern nhighlights 6422 global hlview vhighlights 6423 global highlight_related rhighlights 6424 6425 if {$row >= $numcommits} return 6426 6427 set id [lindex $displayorder $row] 6428 if {[info exists hlview] && ![info exists vhighlights($id)]} { 6429 askvhighlight $row $id 6430 } 6431 if {[info exists filehighlight] && ![info exists fhighlights($id)]} { 6432 askfilehighlight $row $id 6433 } 6434 if {$findpattern ne {} && ![info exists nhighlights($id)]} { 6435 askfindhighlight $row $id 6436 } 6437 if {$highlight_related ne [mc "None"] && ![info exists rhighlights($id)]} { 6438 askrelhighlight $row $id 6439 } 6440 if {![info exists iddrawn($id)]} { 6441 set col [lsearch -exact [lindex $rowidlist $row] $id] 6442 if {$col < 0} { 6443 puts "oops, row $row id $id not in list" 6444 return 6445 } 6446 if {![info exists commitinfo($id)]} { 6447 getcommit $id 6448 } 6449 assigncolor $id 6450 drawcmittext $id $row $col 6451 set iddrawn($id) 1 6452 incr nrows_drawn 6453 } 6454 if {$markingmatches} { 6455 markrowmatches $row $id 6456 } 6457 } 6458 6459 proc drawcommits {row {endrow {}}} { 6460 global numcommits iddrawn displayorder curview need_redisplay 6461 global parentlist rowidlist rowfinal uparrowlen downarrowlen nrows_drawn 6462 6463 if {$row < 0} { 6464 set row 0 6465 } 6466 if {$endrow eq {}} { 6467 set endrow $row 6468 } 6469 if {$endrow >= $numcommits} { 6470 set endrow [expr {$numcommits - 1}] 6471 } 6472 6473 set rl1 [expr {$row - $downarrowlen - 3}] 6474 if {$rl1 < 0} { 6475 set rl1 0 6476 } 6477 set ro1 [expr {$row - 3}] 6478 if {$ro1 < 0} { 6479 set ro1 0 6480 } 6481 set r2 [expr {$endrow + $uparrowlen + 3}] 6482 if {$r2 > $numcommits} { 6483 set r2 $numcommits 6484 } 6485 for {set r $rl1} {$r < $r2} {incr r} { 6486 if {[lindex $rowidlist $r] ne {} && [lindex $rowfinal $r]} { 6487 if {$rl1 < $r} { 6488 layoutrows $rl1 $r 6489 } 6490 set rl1 [expr {$r + 1}] 6491 } 6492 } 6493 if {$rl1 < $r} { 6494 layoutrows $rl1 $r 6495 } 6496 optimize_rows $ro1 0 $r2 6497 if {$need_redisplay || $nrows_drawn > 2000} { 6498 clear_display 6499 } 6500 6501 # make the lines join to already-drawn rows either side 6502 set r [expr {$row - 1}] 6503 if {$r < 0 || ![info exists iddrawn([lindex $displayorder $r])]} { 6504 set r $row 6505 } 6506 set er [expr {$endrow + 1}] 6507 if {$er >= $numcommits || 6508 ![info exists iddrawn([lindex $displayorder $er])]} { 6509 set er $endrow 6510 } 6511 for {} {$r <= $er} {incr r} { 6512 set id [lindex $displayorder $r] 6513 set wasdrawn [info exists iddrawn($id)] 6514 drawcmitrow $r 6515 if {$r == $er} break 6516 set nextid [lindex $displayorder [expr {$r + 1}]] 6517 if {$wasdrawn && [info exists iddrawn($nextid)]} continue 6518 drawparentlinks $id $r 6519 6520 set rowids [lindex $rowidlist $r] 6521 foreach lid $rowids { 6522 if {$lid eq {}} continue 6523 if {[info exists lineend($lid)] && $lineend($lid) > $r} continue 6524 if {$lid eq $id} { 6525 # see if this is the first child of any of its parents 6526 foreach p [lindex $parentlist $r] { 6527 if {[lsearch -exact $rowids $p] < 0} { 6528 # make this line extend up to the child 6529 set lineend($p) [drawlineseg $p $r $er 0] 6530 } 6531 } 6532 } else { 6533 set lineend($lid) [drawlineseg $lid $r $er 1] 6534 } 6535 } 6536 } 6537 } 6538 6539 proc undolayout {row} { 6540 global uparrowlen mingaplen downarrowlen 6541 global rowidlist rowisopt rowfinal need_redisplay 6542 6543 set r [expr {$row - ($uparrowlen + $mingaplen + $downarrowlen)}] 6544 if {$r < 0} { 6545 set r 0 6546 } 6547 if {[llength $rowidlist] > $r} { 6548 incr r -1 6549 set rowidlist [lrange $rowidlist 0 $r] 6550 set rowfinal [lrange $rowfinal 0 $r] 6551 set rowisopt [lrange $rowisopt 0 $r] 6552 set need_redisplay 1 6553 run drawvisible 6554 } 6555 } 6556 6557 proc drawvisible {} { 6558 global canv linespc curview vrowmod selectedline targetrow targetid 6559 global need_redisplay cscroll numcommits 6560 6561 set fs [$canv yview] 6562 set ymax [lindex [$canv cget -scrollregion] 3] 6563 if {$ymax eq {} || $ymax == 0 || $numcommits == 0} return 6564 set f0 [lindex $fs 0] 6565 set f1 [lindex $fs 1] 6566 set y0 [expr {int($f0 * $ymax)}] 6567 set y1 [expr {int($f1 * $ymax)}] 6568 6569 if {[info exists targetid]} { 6570 if {[commitinview $targetid $curview]} { 6571 set r [rowofcommit $targetid] 6572 if {$r != $targetrow} { 6573 # Fix up the scrollregion and change the scrolling position 6574 # now that our target row has moved. 6575 set diff [expr {($r - $targetrow) * $linespc}] 6576 set targetrow $r 6577 setcanvscroll 6578 set ymax [lindex [$canv cget -scrollregion] 3] 6579 incr y0 $diff 6580 incr y1 $diff 6581 set f0 [expr {$y0 / $ymax}] 6582 set f1 [expr {$y1 / $ymax}] 6583 allcanvs yview moveto $f0 6584 $cscroll set $f0 $f1 6585 set need_redisplay 1 6586 } 6587 } else { 6588 unset targetid 6589 } 6590 } 6591 6592 set row [expr {int(($y0 - 3) / $linespc) - 1}] 6593 set endrow [expr {int(($y1 - 3) / $linespc) + 1}] 6594 if {$endrow >= $vrowmod($curview)} { 6595 update_arcrows $curview 6596 } 6597 if {$selectedline ne {} && 6598 $row <= $selectedline && $selectedline <= $endrow} { 6599 set targetrow $selectedline 6600 } elseif {[info exists targetid]} { 6601 set targetrow [expr {int(($row + $endrow) / 2)}] 6602 } 6603 if {[info exists targetrow]} { 6604 if {$targetrow >= $numcommits} { 6605 set targetrow [expr {$numcommits - 1}] 6606 } 6607 set targetid [commitonrow $targetrow] 6608 } 6609 drawcommits $row $endrow 6610 } 6611 6612 proc clear_display {} { 6613 global iddrawn linesegs need_redisplay nrows_drawn 6614 global vhighlights fhighlights nhighlights rhighlights 6615 global linehtag linentag linedtag boldids boldnameids 6616 6617 allcanvs delete all 6618 unset -nocomplain iddrawn 6619 unset -nocomplain linesegs 6620 unset -nocomplain linehtag 6621 unset -nocomplain linentag 6622 unset -nocomplain linedtag 6623 set boldids {} 6624 set boldnameids {} 6625 unset -nocomplain vhighlights 6626 unset -nocomplain fhighlights 6627 unset -nocomplain nhighlights 6628 unset -nocomplain rhighlights 6629 set need_redisplay 0 6630 set nrows_drawn 0 6631 } 6632 6633 proc findcrossings {id} { 6634 global rowidlist parentlist numcommits displayorder 6635 6636 set cross {} 6637 set ccross {} 6638 foreach {s e} [rowranges $id] { 6639 if {$e >= $numcommits} { 6640 set e [expr {$numcommits - 1}] 6641 } 6642 if {$e <= $s} continue 6643 for {set row $e} {[incr row -1] >= $s} {} { 6644 set x [lsearch -exact [lindex $rowidlist $row] $id] 6645 if {$x < 0} break 6646 set olds [lindex $parentlist $row] 6647 set kid [lindex $displayorder $row] 6648 set kidx [lsearch -exact [lindex $rowidlist $row] $kid] 6649 if {$kidx < 0} continue 6650 set nextrow [lindex $rowidlist [expr {$row + 1}]] 6651 foreach p $olds { 6652 set px [lsearch -exact $nextrow $p] 6653 if {$px < 0} continue 6654 if {($kidx < $x && $x < $px) || ($px < $x && $x < $kidx)} { 6655 if {[lsearch -exact $ccross $p] >= 0} continue 6656 if {$x == $px + ($kidx < $px? -1: 1)} { 6657 lappend ccross $p 6658 } elseif {[lsearch -exact $cross $p] < 0} { 6659 lappend cross $p 6660 } 6661 } 6662 } 6663 } 6664 } 6665 return [concat $ccross {{}} $cross] 6666 } 6667 6668 proc assigncolor {id} { 6669 global colormap colors nextcolor 6670 global parents children children curview 6671 6672 if {[info exists colormap($id)]} return 6673 set ncolors [llength $colors] 6674 if {[info exists children($curview,$id)]} { 6675 set kids $children($curview,$id) 6676 } else { 6677 set kids {} 6678 } 6679 if {[llength $kids] == 1} { 6680 set child [lindex $kids 0] 6681 if {[info exists colormap($child)] 6682 && [llength $parents($curview,$child)] == 1} { 6683 set colormap($id) $colormap($child) 6684 return 6685 } 6686 } 6687 set badcolors {} 6688 set origbad {} 6689 foreach x [findcrossings $id] { 6690 if {$x eq {}} { 6691 # delimiter between corner crossings and other crossings 6692 if {[llength $badcolors] >= $ncolors - 1} break 6693 set origbad $badcolors 6694 } 6695 if {[info exists colormap($x)] 6696 && [lsearch -exact $badcolors $colormap($x)] < 0} { 6697 lappend badcolors $colormap($x) 6698 } 6699 } 6700 if {[llength $badcolors] >= $ncolors} { 6701 set badcolors $origbad 6702 } 6703 set origbad $badcolors 6704 if {[llength $badcolors] < $ncolors - 1} { 6705 foreach child $kids { 6706 if {[info exists colormap($child)] 6707 && [lsearch -exact $badcolors $colormap($child)] < 0} { 6708 lappend badcolors $colormap($child) 6709 } 6710 foreach p $parents($curview,$child) { 6711 if {[info exists colormap($p)] 6712 && [lsearch -exact $badcolors $colormap($p)] < 0} { 6713 lappend badcolors $colormap($p) 6714 } 6715 } 6716 } 6717 if {[llength $badcolors] >= $ncolors} { 6718 set badcolors $origbad 6719 } 6720 } 6721 for {set i 0} {$i <= $ncolors} {incr i} { 6722 set c [lindex $colors $nextcolor] 6723 if {[incr nextcolor] >= $ncolors} { 6724 set nextcolor 0 6725 } 6726 if {[lsearch -exact $badcolors $c]} break 6727 } 6728 set colormap($id) $c 6729 } 6730 6731 proc bindline {t id} { 6732 global canv 6733 6734 $canv bind $t "lineenter %x %y $id" 6735 $canv bind $t "linemotion %x %y $id" 6736 $canv bind $t "lineleave $id" 6737 $canv bind $t "lineclick %x %y $id 1" 6738 } 6739 6740 proc graph_pane_width {} { 6741 set g [.tf.histframe.pwclist sashpos 0] 6742 return [lindex $g 0] 6743 } 6744 6745 proc totalwidth {l font extra} { 6746 set tot 0 6747 foreach str $l { 6748 set tot [expr {$tot + [font measure $font $str] + $extra}] 6749 } 6750 return $tot 6751 } 6752 6753 proc drawtags {id x xt y1} { 6754 global idtags idheads idotherrefs mainhead 6755 global linespc lthickness 6756 global canv rowtextx curview fgcolor bgcolor ctxbut 6757 global headbgcolor headfgcolor headoutlinecolor remotebgcolor 6758 global tagbgcolor tagfgcolor tagoutlinecolor 6759 global reflinecolor 6760 6761 set marks {} 6762 set ntags 0 6763 set nheads 0 6764 set singletag 0 6765 set maxtags 3 6766 set maxtagpct 25 6767 set maxwidth [expr {[graph_pane_width] * $maxtagpct / 100}] 6768 set delta [expr {int(0.5 * ($linespc - $lthickness))}] 6769 set extra [expr {$delta + $lthickness + $linespc}] 6770 6771 if {[info exists idtags($id)]} { 6772 set marks $idtags($id) 6773 set ntags [llength $marks] 6774 if {$ntags > $maxtags || 6775 [totalwidth $marks mainfont $extra] > $maxwidth} { 6776 # show just a single "n tags..." tag 6777 set singletag 1 6778 if {$ntags == 1} { 6779 set marks [list "tag..."] 6780 } else { 6781 set marks [list [format "%d tags..." $ntags]] 6782 } 6783 set ntags 1 6784 } 6785 } 6786 if {[info exists idheads($id)]} { 6787 set marks [concat $marks $idheads($id)] 6788 set nheads [llength $idheads($id)] 6789 } 6790 if {[info exists idotherrefs($id)]} { 6791 set marks [concat $marks $idotherrefs($id)] 6792 } 6793 if {$marks eq {}} { 6794 return $xt 6795 } 6796 6797 set yt [expr {$y1 - 0.5 * $linespc}] 6798 set yb [expr {$yt + $linespc - 1}] 6799 set xvals {} 6800 set wvals {} 6801 set i -1 6802 foreach tag $marks { 6803 incr i 6804 if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} { 6805 set wid [font measure mainfontbold $tag] 6806 } else { 6807 set wid [font measure mainfont $tag] 6808 } 6809 lappend xvals $xt 6810 lappend wvals $wid 6811 set xt [expr {$xt + $wid + $extra}] 6812 } 6813 set t [$canv create line $x $y1 [lindex $xvals end] $y1 \ 6814 -width $lthickness -fill $reflinecolor -tags tag.$id] 6815 $canv lower $t 6816 foreach tag $marks x $xvals wid $wvals { 6817 set tag_quoted [string map {% %%} $tag] 6818 set xl [expr {$x + $delta}] 6819 set xr [expr {$x + $delta + $wid + $lthickness}] 6820 set font mainfont 6821 if {[incr ntags -1] >= 0} { 6822 # draw a tag 6823 set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \ 6824 $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \ 6825 -width 1 -outline $tagoutlinecolor -fill $tagbgcolor \ 6826 -tags tag.$id] 6827 if {$singletag} { 6828 set tagclick [list showtags $id 1] 6829 } else { 6830 set tagclick [list showtag $tag_quoted 1] 6831 } 6832 $canv bind $t <1> $tagclick 6833 set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}] 6834 } else { 6835 # draw a head or other ref 6836 if {[incr nheads -1] >= 0} { 6837 set refoutlinecol $headoutlinecolor 6838 set reffillcol $headbgcolor 6839 if {$tag eq $mainhead} { 6840 set font mainfontbold 6841 } 6842 } else { 6843 set refoutlinecol black 6844 set reffillcol "#ddddff" 6845 } 6846 set xl [expr {$xl - $delta/2}] 6847 $canv create polygon $x $yt $xr $yt $xr $yb $x $yb \ 6848 -width 1 -outline $refoutlinecol -fill $reffillcol -tags tag.$id 6849 if {[regexp {^(remotes/[^/]*/|remotes/)} $tag match remoteprefix]} { 6850 set rwid [font measure mainfont $remoteprefix] 6851 set xi [expr {$x + 1}] 6852 set yti [expr {$yt + 1}] 6853 set xri [expr {$x + $rwid}] 6854 $canv create polygon $xi $yti $xri $yti $xri $yb $xi $yb \ 6855 -width 0 -fill $remotebgcolor -tags tag.$id 6856 } 6857 } 6858 set textfgcolor [expr {$ntags >= 0 ? $tagfgcolor : $headfgcolor}] 6859 set t [$canv create text $xl $y1 -anchor w -text $tag -fill $textfgcolor \ 6860 -font $font -tags [list tag.$id text]] 6861 if {$ntags >= 0} { 6862 $canv bind $t <1> $tagclick 6863 } elseif {$nheads >= 0} { 6864 $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted] 6865 } 6866 } 6867 return $xt 6868 } 6869 6870 proc drawnotesign {xt y} { 6871 global linespc canv fgcolor 6872 6873 set orad [expr {$linespc / 3}] 6874 set t [$canv create rectangle [expr {$xt - $orad}] [expr {$y - $orad}] \ 6875 [expr {$xt + $orad - 1}] [expr {$y + $orad - 1}] \ 6876 -fill yellow -outline $fgcolor -width 1 -tags circle] 6877 set xt [expr {$xt + $orad * 3}] 6878 return $xt 6879 } 6880 6881 proc xcoord {i level ln} { 6882 global canvx0 xspc1 xspc2 6883 6884 set x [expr {$canvx0 + $i * $xspc1($ln)}] 6885 if {$i > 0 && $i == $level} { 6886 set x [expr {$x + 0.5 * ($xspc2 - $xspc1($ln))}] 6887 } elseif {$i > $level} { 6888 set x [expr {$x + $xspc2 - $xspc1($ln)}] 6889 } 6890 return $x 6891 } 6892 6893 proc show_status {msg} { 6894 global canv fgcolor 6895 6896 clear_display 6897 set_window_title 6898 $canv create text 3 3 -anchor nw -text $msg -font mainfont \ 6899 -tags text -fill $fgcolor 6900 } 6901 6902 # Don't change the text pane cursor if it is currently the hand cursor, 6903 # showing that we are over a sha1 ID link. 6904 proc settextcursor {c} { 6905 global ctext curtextcursor 6906 6907 if {[$ctext cget -cursor] == $curtextcursor} { 6908 $ctext config -cursor $c 6909 } 6910 set curtextcursor $c 6911 } 6912 6913 proc nowbusy {what {name {}}} { 6914 global isbusy busyname statusw 6915 6916 if {[array names isbusy] eq {}} { 6917 . config -cursor watch 6918 settextcursor watch 6919 } 6920 set isbusy($what) 1 6921 set busyname($what) $name 6922 if {$name ne {}} { 6923 $statusw conf -text $name 6924 } 6925 } 6926 6927 proc notbusy {what} { 6928 global isbusy maincursor textcursor busyname statusw 6929 6930 catch { 6931 unset isbusy($what) 6932 if {$busyname($what) ne {} && 6933 [$statusw cget -text] eq $busyname($what)} { 6934 $statusw conf -text {} 6935 } 6936 } 6937 if {[array names isbusy] eq {}} { 6938 . config -cursor $maincursor 6939 settextcursor $textcursor 6940 } 6941 } 6942 6943 proc findmatches {f} { 6944 global findtype findstring 6945 if {$findtype == [mc "Regexp"]} { 6946 set matches [regexp -indices -all -inline $findstring $f] 6947 } else { 6948 set fs $findstring 6949 if {$findtype == [mc "IgnCase"]} { 6950 set f [string tolower $f] 6951 set fs [string tolower $fs] 6952 } 6953 set matches {} 6954 set i 0 6955 set l [string length $fs] 6956 while {[set j [string first $fs $f $i]] >= 0} { 6957 lappend matches [list $j [expr {$j+$l-1}]] 6958 set i [expr {$j + $l}] 6959 } 6960 } 6961 return $matches 6962 } 6963 6964 proc dofind {{dirn 1} {wrap 1}} { 6965 global findstring findstartline findcurline selectedline numcommits 6966 global gdttype filehighlight fh_serial find_dirn findallowwrap 6967 6968 if {[info exists find_dirn]} { 6969 if {$find_dirn == $dirn} return 6970 stopfinding 6971 } 6972 focus . 6973 if {$findstring eq {} || $numcommits == 0} return 6974 if {$selectedline eq {}} { 6975 set findstartline [lindex [visiblerows] [expr {$dirn < 0}]] 6976 } else { 6977 set findstartline $selectedline 6978 } 6979 set findcurline $findstartline 6980 nowbusy finding [mc "Searching"] 6981 if {$gdttype ne [mc "containing:"] && ![info exists filehighlight]} { 6982 after cancel do_file_hl $fh_serial 6983 do_file_hl $fh_serial 6984 } 6985 set find_dirn $dirn 6986 set findallowwrap $wrap 6987 run findmore 6988 } 6989 6990 proc stopfinding {} { 6991 global find_dirn findcurline fprogcoord 6992 6993 if {[info exists find_dirn]} { 6994 unset find_dirn 6995 unset findcurline 6996 notbusy finding 6997 set fprogcoord 0 6998 adjustprogress 6999 } 7000 stopblaming 7001 } 7002 7003 proc findmore {} { 7004 global commitdata commitinfo numcommits findpattern findloc 7005 global findstartline findcurline findallowwrap 7006 global find_dirn gdttype fhighlights fprogcoord 7007 global curview varcorder vrownum varccommits vrowmod 7008 7009 if {![info exists find_dirn]} { 7010 return 0 7011 } 7012 set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]] 7013 set l $findcurline 7014 set moretodo 0 7015 if {$find_dirn > 0} { 7016 incr l 7017 if {$l >= $numcommits} { 7018 set l 0 7019 } 7020 if {$l <= $findstartline} { 7021 set lim [expr {$findstartline + 1}] 7022 } else { 7023 set lim $numcommits 7024 set moretodo $findallowwrap 7025 } 7026 } else { 7027 if {$l == 0} { 7028 set l $numcommits 7029 } 7030 incr l -1 7031 if {$l >= $findstartline} { 7032 set lim [expr {$findstartline - 1}] 7033 } else { 7034 set lim -1 7035 set moretodo $findallowwrap 7036 } 7037 } 7038 set n [expr {($lim - $l) * $find_dirn}] 7039 if {$n > 500} { 7040 set n 500 7041 set moretodo 1 7042 } 7043 if {$l + ($find_dirn > 0? $n: 1) > $vrowmod($curview)} { 7044 update_arcrows $curview 7045 } 7046 set found 0 7047 set domore 1 7048 set ai [bsearch $vrownum($curview) $l] 7049 set a [lindex $varcorder($curview) $ai] 7050 set arow [lindex $vrownum($curview) $ai] 7051 set ids [lindex $varccommits($curview,$a)] 7052 set arowend [expr {$arow + [llength $ids]}] 7053 if {$gdttype eq [mc "containing:"]} { 7054 for {} {$n > 0} {incr n -1; incr l $find_dirn} { 7055 if {$l < $arow || $l >= $arowend} { 7056 incr ai $find_dirn 7057 set a [lindex $varcorder($curview) $ai] 7058 set arow [lindex $vrownum($curview) $ai] 7059 set ids [lindex $varccommits($curview,$a)] 7060 set arowend [expr {$arow + [llength $ids]}] 7061 } 7062 set id [lindex $ids [expr {$l - $arow}]] 7063 # shouldn't happen unless git log doesn't give all the commits... 7064 if {![info exists commitdata($id)] || 7065 ![doesmatch $commitdata($id)]} { 7066 continue 7067 } 7068 if {![info exists commitinfo($id)]} { 7069 getcommit $id 7070 } 7071 set info $commitinfo($id) 7072 foreach f $info ty $fldtypes { 7073 if {$ty eq ""} continue 7074 if {($findloc eq [mc "All fields"] || $findloc eq $ty) && 7075 [doesmatch $f]} { 7076 set found 1 7077 break 7078 } 7079 } 7080 if {$found} break 7081 } 7082 } else { 7083 for {} {$n > 0} {incr n -1; incr l $find_dirn} { 7084 if {$l < $arow || $l >= $arowend} { 7085 incr ai $find_dirn 7086 set a [lindex $varcorder($curview) $ai] 7087 set arow [lindex $vrownum($curview) $ai] 7088 set ids [lindex $varccommits($curview,$a)] 7089 set arowend [expr {$arow + [llength $ids]}] 7090 } 7091 set id [lindex $ids [expr {$l - $arow}]] 7092 if {![info exists fhighlights($id)]} { 7093 # this sets fhighlights($id) to -1 7094 askfilehighlight $l $id 7095 } 7096 if {$fhighlights($id) > 0} { 7097 set found $domore 7098 break 7099 } 7100 if {$fhighlights($id) < 0} { 7101 if {$domore} { 7102 set domore 0 7103 set findcurline [expr {$l - $find_dirn}] 7104 } 7105 } 7106 } 7107 } 7108 if {$found || ($domore && !$moretodo)} { 7109 unset findcurline 7110 unset find_dirn 7111 notbusy finding 7112 set fprogcoord 0 7113 adjustprogress 7114 if {$found} { 7115 findselectline $l 7116 } else { 7117 bell 7118 } 7119 return 0 7120 } 7121 if {!$domore} { 7122 flushhighlights 7123 } else { 7124 set findcurline [expr {$l - $find_dirn}] 7125 } 7126 set n [expr {($findcurline - $findstartline) * $find_dirn - 1}] 7127 if {$n < 0} { 7128 incr n $numcommits 7129 } 7130 set fprogcoord [expr {$n * 1.0 / $numcommits}] 7131 adjustprogress 7132 return $domore 7133 } 7134 7135 proc findselectline {l} { 7136 global findloc commentend ctext findcurline markingmatches gdttype 7137 7138 set markingmatches [expr {$gdttype eq [mc "containing:"]}] 7139 set findcurline $l 7140 selectline $l 1 7141 if {$markingmatches && 7142 ($findloc eq [mc "All fields"] || $findloc eq [mc "Comments"])} { 7143 # highlight the matches in the comments 7144 set f [$ctext get 1.0 $commentend] 7145 set matches [findmatches $f] 7146 foreach match $matches { 7147 set start [lindex $match 0] 7148 set end [expr {[lindex $match 1] + 1}] 7149 $ctext tag add found "1.0 + $start c" "1.0 + $end c" 7150 } 7151 } 7152 drawvisible 7153 } 7154 7155 # mark the bits of a headline or author that match a find string 7156 proc markmatches {canv l str tag matches font row} { 7157 global selectedline foundbgcolor 7158 7159 set bbox [$canv bbox $tag] 7160 set x0 [lindex $bbox 0] 7161 set y0 [lindex $bbox 1] 7162 set y1 [lindex $bbox 3] 7163 foreach match $matches { 7164 set start [lindex $match 0] 7165 set end [lindex $match 1] 7166 if {$start > $end} continue 7167 set xoff [font measure $font [string range $str 0 [expr {$start-1}]]] 7168 set xlen [font measure $font [string range $str 0 [expr {$end}]]] 7169 set t [$canv create rect [expr {$x0+$xoff}] $y0 \ 7170 [expr {$x0+$xlen+2}] $y1 \ 7171 -outline {} -tags [list match$l matches] -fill $foundbgcolor] 7172 $canv lower $t 7173 if {$row == $selectedline} { 7174 $canv raise $t secsel 7175 } 7176 } 7177 } 7178 7179 proc unmarkmatches {} { 7180 global markingmatches 7181 7182 allcanvs delete matches 7183 set markingmatches 0 7184 stopfinding 7185 } 7186 7187 proc selcanvline {w x y} { 7188 global canv canvy0 ctext linespc 7189 global rowtextx 7190 set ymax [lindex [$canv cget -scrollregion] 3] 7191 if {$ymax == {}} return 7192 set yfrac [lindex [$canv yview] 0] 7193 set y [expr {$y + $yfrac * $ymax}] 7194 set l [expr {int(($y - $canvy0) / $linespc + 0.5)}] 7195 if {$l < 0} { 7196 set l 0 7197 } 7198 if {$w eq $canv} { 7199 set xmax [lindex [$canv cget -scrollregion] 2] 7200 set xleft [expr {[lindex [$canv xview] 0] * $xmax}] 7201 if {![info exists rowtextx($l)] || $xleft + $x < $rowtextx($l)} return 7202 } 7203 unmarkmatches 7204 selectline $l 1 7205 } 7206 7207 proc commit_descriptor {p} { 7208 global commitinfo 7209 if {![info exists commitinfo($p)]} { 7210 getcommit $p 7211 } 7212 set l "..." 7213 if {[llength $commitinfo($p)] > 1} { 7214 set l [lindex $commitinfo($p) 0] 7215 } 7216 return "$p ($l)\n" 7217 } 7218 7219 # append some text to the ctext widget, and make any SHA1 ID 7220 # that we know about be a clickable link. 7221 # Also look for URLs of the form "http[s]://..." and make them web links. 7222 proc appendwithlinks {text tags} { 7223 global ctext linknum curview 7224 global hashlength 7225 7226 set start [$ctext index "end - 1c"] 7227 $ctext insert end $text $tags 7228 set links [regexp -indices -all -inline [string map "@@ $hashlength" {(?:\m|-g)[0-9a-f]{6,@@}\M}] $text] 7229 foreach l $links { 7230 set s [lindex $l 0] 7231 set e [lindex $l 1] 7232 set linkid [string range $text $s $e] 7233 incr e 7234 $ctext tag delete link$linknum 7235 $ctext tag add link$linknum "$start + $s c" "$start + $e c" 7236 setlink $linkid link$linknum 7237 incr linknum 7238 } 7239 set wlinks [regexp -indices -all -inline -line \ 7240 {https?://[^[:space:]]+} $text] 7241 foreach l $wlinks { 7242 set s2 [lindex $l 0] 7243 set e2 [lindex $l 1] 7244 set url [string range $text $s2 $e2] 7245 incr e2 7246 $ctext tag delete link$linknum 7247 $ctext tag add link$linknum "$start + $s2 c" "$start + $e2 c" 7248 setwlink $url link$linknum 7249 incr linknum 7250 } 7251 } 7252 7253 proc setlink {id lk} { 7254 global curview ctext pendinglinks 7255 global linkfgcolor 7256 global hashlength 7257 7258 if {[string range $id 0 1] eq "-g"} { 7259 set id [string range $id 2 end] 7260 } 7261 7262 set known 0 7263 if {[string length $id] < $hashlength} { 7264 set matches [longid $id] 7265 if {[llength $matches] > 0} { 7266 if {[llength $matches] > 1} return 7267 set known 1 7268 set id [lindex $matches 0] 7269 } 7270 } else { 7271 set known [commitinview $id $curview] 7272 } 7273 if {$known} { 7274 $ctext tag conf $lk -foreground $linkfgcolor -underline 1 7275 $ctext tag bind $lk <1> [list selbyid $id] 7276 $ctext tag bind $lk {linkcursor %W 1} 7277 $ctext tag bind $lk {linkcursor %W -1} 7278 } else { 7279 lappend pendinglinks($id) $lk 7280 interestedin $id {makelink %P} 7281 } 7282 } 7283 7284 proc setwlink {url lk} { 7285 global ctext 7286 global linkfgcolor 7287 global web_browser 7288 7289 if {$web_browser eq {}} return 7290 $ctext tag conf $lk -foreground $linkfgcolor -underline 1 7291 $ctext tag bind $lk <1> [list browseweb $url] 7292 $ctext tag bind $lk {linkcursor %W 1} 7293 $ctext tag bind $lk {linkcursor %W -1} 7294 } 7295 7296 proc appendshortlink {id {pre {}} {post {}}} { 7297 global ctext linknum 7298 7299 $ctext insert end $pre 7300 $ctext tag delete link$linknum 7301 $ctext insert end [string range $id 0 7] link$linknum 7302 $ctext insert end $post 7303 setlink $id link$linknum 7304 incr linknum 7305 } 7306 7307 proc makelink {id} { 7308 global pendinglinks 7309 7310 if {![info exists pendinglinks($id)]} return 7311 foreach lk $pendinglinks($id) { 7312 setlink $id $lk 7313 } 7314 unset pendinglinks($id) 7315 } 7316 7317 proc linkcursor {w inc} { 7318 global linkentercount curtextcursor 7319 7320 if {[incr linkentercount $inc] > 0} { 7321 $w configure -cursor hand2 7322 } else { 7323 $w configure -cursor $curtextcursor 7324 if {$linkentercount < 0} { 7325 set linkentercount 0 7326 } 7327 } 7328 } 7329 7330 proc browseweb {url} { 7331 global web_browser 7332 7333 if {$web_browser eq {}} return 7334 # Use concat here in case $web_browser is a command plus some arguments 7335 if {[catch {safe_exec_redirect [concat $web_browser [list $url]] [list &]} err]} { 7336 error_popup "[mc "Error starting web browser:"] $err" 7337 } 7338 } 7339 7340 proc viewnextline {dir} { 7341 global canv linespc 7342 7343 $canv delete hover 7344 set ymax [lindex [$canv cget -scrollregion] 3] 7345 set wnow [$canv yview] 7346 set wtop [expr {[lindex $wnow 0] * $ymax}] 7347 set newtop [expr {$wtop + $dir * $linespc}] 7348 if {$newtop < 0} { 7349 set newtop 0 7350 } elseif {$newtop > $ymax} { 7351 set newtop $ymax 7352 } 7353 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}] 7354 } 7355 7356 # add a list of tag or branch names at position pos 7357 # returns the number of names inserted 7358 proc appendrefs {pos ids var} { 7359 global ctext linknum curview $var maxrefs visiblerefs mainheadid 7360 7361 if {[catch {$ctext index $pos}]} { 7362 return 0 7363 } 7364 $ctext conf -state normal 7365 $ctext delete $pos "$pos lineend" 7366 set tags {} 7367 foreach id $ids { 7368 foreach tag [set $var\($id\)] { 7369 lappend tags [list $tag $id] 7370 } 7371 } 7372 7373 set sep {} 7374 set tags [lsort -index 0 -decreasing $tags] 7375 set nutags 0 7376 7377 if {[llength $tags] > $maxrefs} { 7378 # If we are displaying heads, and there are too many, 7379 # see if there are some important heads to display. 7380 # Currently that are the current head and heads listed in $visiblerefs option 7381 set itags {} 7382 if {$var eq "idheads"} { 7383 set utags {} 7384 foreach ti $tags { 7385 set hname [lindex $ti 0] 7386 set id [lindex $ti 1] 7387 if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) && 7388 [llength $itags] < $maxrefs} { 7389 lappend itags $ti 7390 } else { 7391 lappend utags $ti 7392 } 7393 } 7394 set tags $utags 7395 } 7396 if {$itags ne {}} { 7397 set str [mc "and many more"] 7398 set sep " " 7399 } else { 7400 set str [mc "many"] 7401 } 7402 $ctext insert $pos "$str ([llength $tags])" 7403 set nutags [llength $tags] 7404 set tags $itags 7405 } 7406 7407 foreach ti $tags { 7408 set id [lindex $ti 1] 7409 set lk link$linknum 7410 incr linknum 7411 $ctext tag delete $lk 7412 $ctext insert $pos $sep 7413 $ctext insert $pos [lindex $ti 0] $lk 7414 setlink $id $lk 7415 set sep ", " 7416 } 7417 $ctext tag add wwrap "$pos linestart" "$pos lineend" 7418 $ctext conf -state disabled 7419 return [expr {[llength $tags] + $nutags}] 7420 } 7421 7422 # called when we have finished computing the nearby tags 7423 proc dispneartags {delay} { 7424 global selectedline currentid showneartags tagphase 7425 7426 if {$selectedline eq {} || !$showneartags} return 7427 after cancel dispnexttag 7428 if {$delay} { 7429 after 200 dispnexttag 7430 set tagphase -1 7431 } else { 7432 after idle dispnexttag 7433 set tagphase 0 7434 } 7435 } 7436 7437 proc dispnexttag {} { 7438 global selectedline currentid showneartags tagphase ctext 7439 7440 if {$selectedline eq {} || !$showneartags} return 7441 switch -- $tagphase { 7442 0 { 7443 set dtags [desctags $currentid] 7444 if {$dtags ne {}} { 7445 appendrefs precedes $dtags idtags 7446 } 7447 } 7448 1 { 7449 set atags [anctags $currentid] 7450 if {$atags ne {}} { 7451 appendrefs follows $atags idtags 7452 } 7453 } 7454 2 { 7455 set dheads [descheads $currentid] 7456 if {$dheads ne {}} { 7457 if {[appendrefs branch $dheads idheads] > 1 7458 && [$ctext get "branch -3c"] eq "h"} { 7459 # turn "Branch" into "Branches" 7460 $ctext conf -state normal 7461 $ctext insert "branch -2c" "es" 7462 $ctext conf -state disabled 7463 } 7464 } 7465 } 7466 } 7467 if {[incr tagphase] <= 2} { 7468 after idle dispnexttag 7469 } 7470 } 7471 7472 proc make_secsel {id} { 7473 global linehtag linentag linedtag canv canv2 canv3 7474 7475 if {![info exists linehtag($id)]} return 7476 $canv delete secsel 7477 set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \ 7478 -tags secsel -fill [$canv cget -selectbackground]] 7479 $canv lower $t 7480 $canv2 delete secsel 7481 set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \ 7482 -tags secsel -fill [$canv2 cget -selectbackground]] 7483 $canv2 lower $t 7484 $canv3 delete secsel 7485 set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \ 7486 -tags secsel -fill [$canv3 cget -selectbackground]] 7487 $canv3 lower $t 7488 } 7489 7490 proc make_idmark {id} { 7491 global linehtag canv fgcolor 7492 7493 if {![info exists linehtag($id)]} return 7494 $canv delete markid 7495 set t [eval $canv create rect [$canv bbox $linehtag($id)] \ 7496 -tags markid -outline $fgcolor] 7497 $canv raise $t 7498 } 7499 7500 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} { 7501 global canv ctext commitinfo selectedline 7502 global canvy0 linespc parents children curview 7503 global currentid sha1entry 7504 global commentend idtags linknum 7505 global mergemax numcommits pending_select 7506 global cmitmode showneartags allcommits 7507 global targetrow targetid lastscrollrows 7508 global autocopy autoselect autosellen jump_to_here 7509 global vinlinediff 7510 7511 unset -nocomplain pending_select 7512 $canv delete hover 7513 normalline 7514 unsel_reflist 7515 stopfinding 7516 if {$l < 0 || $l >= $numcommits} return 7517 set id [commitonrow $l] 7518 set targetid $id 7519 set targetrow $l 7520 set selectedline $l 7521 set currentid $id 7522 if {$lastscrollrows < $numcommits} { 7523 setcanvscroll 7524 } 7525 7526 if {$cmitmode ne "patch" && $switch_to_patch} { 7527 set cmitmode "patch" 7528 } 7529 7530 set y [expr {$canvy0 + $l * $linespc}] 7531 set ymax [lindex [$canv cget -scrollregion] 3] 7532 set ytop [expr {$y - $linespc - 1}] 7533 set ybot [expr {$y + $linespc + 1}] 7534 set wnow [$canv yview] 7535 set wtop [expr {[lindex $wnow 0] * $ymax}] 7536 set wbot [expr {[lindex $wnow 1] * $ymax}] 7537 set wh [expr {$wbot - $wtop}] 7538 set newtop $wtop 7539 if {$ytop < $wtop} { 7540 if {$ybot < $wtop} { 7541 set newtop [expr {$y - $wh / 2.0}] 7542 } else { 7543 set newtop $ytop 7544 if {$newtop > $wtop - $linespc} { 7545 set newtop [expr {$wtop - $linespc}] 7546 } 7547 } 7548 } elseif {$ybot > $wbot} { 7549 if {$ytop > $wbot} { 7550 set newtop [expr {$y - $wh / 2.0}] 7551 } else { 7552 set newtop [expr {$ybot - $wh}] 7553 if {$newtop < $wtop + $linespc} { 7554 set newtop [expr {$wtop + $linespc}] 7555 } 7556 } 7557 } 7558 if {$newtop != $wtop} { 7559 if {$newtop < 0} { 7560 set newtop 0 7561 } 7562 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}] 7563 drawvisible 7564 } 7565 7566 make_secsel $id 7567 7568 if {$isnew} { 7569 addtohistory [list selbyid $id 0] savecmitpos 7570 } 7571 7572 $sha1entry delete 0 end 7573 $sha1entry insert 0 $id 7574 if {$autoselect && [haveselectionclipboard]} { 7575 $sha1entry selection range 0 $autosellen 7576 } 7577 if {$autocopy} { 7578 clipboard clear 7579 clipboard append [string range $id 0 [expr $autosellen - 1]] 7580 } 7581 rhighlight_sel $id 7582 7583 $ctext conf -state normal 7584 clear_ctext 7585 set linknum 0 7586 if {![info exists commitinfo($id)]} { 7587 getcommit $id 7588 } 7589 set info $commitinfo($id) 7590 set date [formatdate [lindex $info 2]] 7591 $ctext insert end "[mc "Author"]: [lindex $info 1] $date\n" 7592 set date [formatdate [lindex $info 4]] 7593 $ctext insert end "[mc "Committer"]: [lindex $info 3] $date\n" 7594 if {[info exists idtags($id)]} { 7595 $ctext insert end [mc "Tags:"] 7596 foreach tag $idtags($id) { 7597 $ctext insert end " $tag" 7598 } 7599 $ctext insert end "\n" 7600 } 7601 7602 set headers {} 7603 set olds $parents($curview,$id) 7604 if {[llength $olds] > 1} { 7605 set np 0 7606 foreach p $olds { 7607 if {$np >= $mergemax} { 7608 set tag mmax 7609 } else { 7610 set tag m$np 7611 } 7612 $ctext insert end "[mc "Parent"]: " $tag 7613 appendwithlinks [commit_descriptor $p] {} 7614 incr np 7615 } 7616 } else { 7617 foreach p $olds { 7618 append headers "[mc "Parent"]: [commit_descriptor $p]" 7619 } 7620 } 7621 7622 foreach c $children($curview,$id) { 7623 append headers "[mc "Child"]: [commit_descriptor $c]" 7624 } 7625 7626 # make anything that looks like a SHA1 ID be a clickable link 7627 appendwithlinks $headers {} 7628 if {$showneartags} { 7629 if {![info exists allcommits]} { 7630 getallcommits 7631 } 7632 $ctext insert end "[mc "Branch"]: " 7633 $ctext mark set branch "end -1c" 7634 $ctext mark gravity branch left 7635 $ctext insert end "\n[mc "Follows"]: " 7636 $ctext mark set follows "end -1c" 7637 $ctext mark gravity follows left 7638 $ctext insert end "\n[mc "Precedes"]: " 7639 $ctext mark set precedes "end -1c" 7640 $ctext mark gravity precedes left 7641 $ctext insert end "\n" 7642 dispneartags 1 7643 } 7644 $ctext insert end "\n" 7645 set comment [lindex $info 5] 7646 if {[string first "\r" $comment] >= 0} { 7647 set comment [string map {"\r" "\n "} $comment] 7648 } 7649 appendwithlinks $comment {comment} 7650 7651 $ctext tag remove found 1.0 end 7652 $ctext conf -state disabled 7653 set commentend [$ctext index "end - 1c"] 7654 7655 set jump_to_here $desired_loc 7656 init_flist [mc "Comments"] 7657 if {$cmitmode eq "tree"} { 7658 gettree $id 7659 } elseif {$vinlinediff($curview) == 1} { 7660 showinlinediff $id 7661 } elseif {[llength $olds] <= 1} { 7662 startdiff $id 7663 } else { 7664 mergediff $id 7665 } 7666 } 7667 7668 proc selfirstline {} { 7669 unmarkmatches 7670 selectline 0 1 7671 } 7672 7673 proc sellastline {} { 7674 global numcommits 7675 unmarkmatches 7676 set l [expr {$numcommits - 1}] 7677 selectline $l 1 7678 } 7679 7680 proc selnextline {dir} { 7681 global selectedline 7682 focus . 7683 if {$selectedline eq {}} return 7684 set l [expr {$selectedline + $dir}] 7685 unmarkmatches 7686 selectline $l 1 7687 } 7688 7689 proc selnextpage {dir} { 7690 global canv linespc selectedline numcommits 7691 7692 set lpp [expr {([winfo height $canv] - 2) / $linespc}] 7693 if {$lpp < 1} { 7694 set lpp 1 7695 } 7696 allcanvs yview scroll [expr {$dir * $lpp}] units 7697 drawvisible 7698 if {$selectedline eq {}} return 7699 set l [expr {$selectedline + $dir * $lpp}] 7700 if {$l < 0} { 7701 set l 0 7702 } elseif {$l >= $numcommits} { 7703 set l [expr $numcommits - 1] 7704 } 7705 unmarkmatches 7706 selectline $l 1 7707 } 7708 7709 proc unselectline {} { 7710 global selectedline currentid 7711 7712 set selectedline {} 7713 unset -nocomplain currentid 7714 allcanvs delete secsel 7715 rhighlight_none 7716 } 7717 7718 proc reselectline {} { 7719 global selectedline 7720 7721 if {$selectedline ne {}} { 7722 selectline $selectedline 0 7723 } 7724 } 7725 7726 proc addtohistory {cmd {saveproc {}}} { 7727 global history historyindex curview 7728 7729 unset_posvars 7730 save_position 7731 set elt [list $curview $cmd $saveproc {}] 7732 if {$historyindex > 0 7733 && [lindex $history [expr {$historyindex - 1}]] == $elt} { 7734 return 7735 } 7736 7737 if {$historyindex < [llength $history]} { 7738 set history [lreplace $history $historyindex end $elt] 7739 } else { 7740 lappend history $elt 7741 } 7742 incr historyindex 7743 if {$historyindex > 1} { 7744 .tf.bar.leftbut conf -state normal 7745 } else { 7746 .tf.bar.leftbut conf -state disabled 7747 } 7748 .tf.bar.rightbut conf -state disabled 7749 } 7750 7751 # save the scrolling position of the diff display pane 7752 proc save_position {} { 7753 global historyindex history 7754 7755 if {$historyindex < 1} return 7756 set hi [expr {$historyindex - 1}] 7757 set fn [lindex $history $hi 2] 7758 if {$fn ne {}} { 7759 lset history $hi 3 [eval $fn] 7760 } 7761 } 7762 7763 proc unset_posvars {} { 7764 global last_posvars 7765 7766 if {[info exists last_posvars]} { 7767 foreach {var val} $last_posvars { 7768 global $var 7769 unset -nocomplain $var 7770 } 7771 unset last_posvars 7772 } 7773 } 7774 7775 proc godo {elt} { 7776 global curview last_posvars 7777 7778 set view [lindex $elt 0] 7779 set cmd [lindex $elt 1] 7780 set pv [lindex $elt 3] 7781 if {$curview != $view} { 7782 showview $view 7783 } 7784 unset_posvars 7785 foreach {var val} $pv { 7786 global $var 7787 set $var $val 7788 } 7789 set last_posvars $pv 7790 eval $cmd 7791 } 7792 7793 proc goback {} { 7794 global history historyindex 7795 focus . 7796 7797 if {$historyindex > 1} { 7798 save_position 7799 incr historyindex -1 7800 godo [lindex $history [expr {$historyindex - 1}]] 7801 .tf.bar.rightbut conf -state normal 7802 } 7803 if {$historyindex <= 1} { 7804 .tf.bar.leftbut conf -state disabled 7805 } 7806 } 7807 7808 proc goforw {} { 7809 global history historyindex 7810 focus . 7811 7812 if {$historyindex < [llength $history]} { 7813 save_position 7814 set cmd [lindex $history $historyindex] 7815 incr historyindex 7816 godo $cmd 7817 .tf.bar.leftbut conf -state normal 7818 } 7819 if {$historyindex >= [llength $history]} { 7820 .tf.bar.rightbut conf -state disabled 7821 } 7822 } 7823 7824 proc go_to_parent {i} { 7825 global parents curview targetid 7826 set ps $parents($curview,$targetid) 7827 if {[llength $ps] >= $i} { 7828 selbyid [lindex $ps [expr $i - 1]] 7829 } 7830 } 7831 7832 proc gettree {id} { 7833 global treefilelist treeidlist diffids diffmergeid treepending 7834 global nullid nullid2 7835 7836 set diffids $id 7837 unset -nocomplain diffmergeid 7838 if {![info exists treefilelist($id)]} { 7839 if {![info exists treepending]} { 7840 if {$id eq $nullid} { 7841 set cmd [list git ls-files] 7842 } elseif {$id eq $nullid2} { 7843 set cmd [list git ls-files --stage -t] 7844 } else { 7845 set cmd [list git ls-tree -r $id] 7846 } 7847 if {[catch {set gtf [safe_open_command $cmd]}]} { 7848 return 7849 } 7850 set treepending $id 7851 set treefilelist($id) {} 7852 set treeidlist($id) {} 7853 fconfigure $gtf -blocking 0 -translation binary 7854 filerun $gtf [list gettreeline $gtf $id] 7855 } 7856 } else { 7857 setfilelist $id 7858 } 7859 } 7860 7861 proc gettreeline {gtf id} { 7862 global treefilelist treeidlist treepending cmitmode diffids nullid nullid2 7863 7864 set nl 0 7865 while {[incr nl] <= 1000 && [gets $gtf line] >= 0} { 7866 if {$diffids eq $nullid} { 7867 set fname $line 7868 } else { 7869 set i [string first "\t" $line] 7870 if {$i < 0} continue 7871 set fname [string range $line [expr {$i+1}] end] 7872 set line [string range $line 0 [expr {$i-1}]] 7873 if {$diffids ne $nullid2 && [lindex $line 1] ne "blob"} continue 7874 set sha1 [lindex $line 2] 7875 lappend treeidlist($id) $sha1 7876 } 7877 if {[string index $fname 0] eq "\""} { 7878 set fname [lindex $fname 0] 7879 } 7880 set fname [convertfrom utf-8 $fname] 7881 lappend treefilelist($id) $fname 7882 } 7883 if {![eof $gtf]} { 7884 return [expr {$nl >= 1000? 2: 1}] 7885 } 7886 close $gtf 7887 unset treepending 7888 if {$cmitmode ne "tree"} { 7889 if {![info exists diffmergeid]} { 7890 gettreediffs $diffids 7891 } 7892 } elseif {$id ne $diffids} { 7893 gettree $diffids 7894 } else { 7895 setfilelist $id 7896 } 7897 return 0 7898 } 7899 7900 proc showfile {f} { 7901 global treefilelist treeidlist diffids nullid nullid2 7902 global ctext_file_names ctext_file_lines 7903 global ctext commentend 7904 7905 set i [lsearch -exact $treefilelist($diffids) $f] 7906 if {$i < 0} { 7907 puts "oops, $f not in list for id $diffids" 7908 return 7909 } 7910 if {$diffids eq $nullid} { 7911 if {[catch {set bf [safe_open_file $f r]} err]} { 7912 puts "oops, can't read $f: $err" 7913 return 7914 } 7915 } else { 7916 set blob [lindex $treeidlist($diffids) $i] 7917 if {[catch {set bf [safe_open_command [concat git cat-file blob $blob]]} err]} { 7918 puts "oops, error reading blob $blob: $err" 7919 return 7920 } 7921 } 7922 fconfigure $bf -blocking 0 -encoding [get_path_encoding $f] 7923 filerun $bf [list getblobline $bf $diffids] 7924 $ctext config -state normal 7925 clear_ctext $commentend 7926 lappend ctext_file_names $f 7927 lappend ctext_file_lines [lindex [split $commentend "."] 0] 7928 $ctext insert end "\n" 7929 $ctext insert end "$f\n" filesep 7930 $ctext config -state disabled 7931 $ctext yview $commentend 7932 settabs 0 7933 } 7934 7935 proc getblobline {bf id} { 7936 global diffids cmitmode ctext 7937 7938 if {$id ne $diffids || $cmitmode ne "tree"} { 7939 catch {close $bf} 7940 return 0 7941 } 7942 $ctext config -state normal 7943 set nl 0 7944 while {[incr nl] <= 1000 && [gets $bf line] >= 0} { 7945 $ctext insert end "$line\n" 7946 } 7947 if {[eof $bf]} { 7948 global jump_to_here ctext_file_names commentend 7949 7950 # delete last newline 7951 $ctext delete "end - 2c" "end - 1c" 7952 close $bf 7953 if {$jump_to_here ne {} && 7954 [lindex $jump_to_here 0] eq [lindex $ctext_file_names 0]} { 7955 set lnum [expr {[lindex $jump_to_here 1] + 7956 [lindex [split $commentend .] 0]}] 7957 mark_ctext_line $lnum 7958 } 7959 $ctext config -state disabled 7960 return 0 7961 } 7962 $ctext config -state disabled 7963 return [expr {$nl >= 1000? 2: 1}] 7964 } 7965 7966 proc mark_ctext_line {lnum} { 7967 global ctext markbgcolor 7968 7969 $ctext tag delete omark 7970 $ctext tag add omark $lnum.0 "$lnum.0 + 1 line" 7971 $ctext tag conf omark -background $markbgcolor 7972 $ctext see $lnum.0 7973 } 7974 7975 proc mergediff {id} { 7976 global diffmergeid 7977 global diffids treediffs 7978 global parents curview 7979 7980 set diffmergeid $id 7981 set diffids $id 7982 set treediffs($id) {} 7983 set np [llength $parents($curview,$id)] 7984 settabs $np 7985 getblobdiffs $id 7986 } 7987 7988 proc startdiff {ids} { 7989 global treediffs diffids treepending diffmergeid nullid nullid2 7990 7991 settabs 1 7992 set diffids $ids 7993 unset -nocomplain diffmergeid 7994 if {![info exists treediffs($ids)] || 7995 [lsearch -exact $ids $nullid] >= 0 || 7996 [lsearch -exact $ids $nullid2] >= 0} { 7997 if {![info exists treepending]} { 7998 gettreediffs $ids 7999 } 8000 } else { 8001 addtocflist $ids 8002 } 8003 } 8004 8005 proc showinlinediff {ids} { 8006 global commitinfo commitdata ctext 8007 global treediffs 8008 8009 set info $commitinfo($ids) 8010 set diff [lindex $info 7] 8011 set difflines [split $diff "\n"] 8012 8013 initblobdiffvars 8014 set treediff {} 8015 8016 set inhdr 0 8017 foreach line $difflines { 8018 if {![string compare -length 5 "diff " $line]} { 8019 set inhdr 1 8020 } elseif {$inhdr && ![string compare -length 4 "+++ " $line]} { 8021 # offset also accounts for the b/ prefix 8022 lappend treediff [string range $line 6 end] 8023 set inhdr 0 8024 } 8025 } 8026 8027 set treediffs($ids) $treediff 8028 add_flist $treediff 8029 8030 $ctext conf -state normal 8031 foreach line $difflines { 8032 parseblobdiffline $ids $line 8033 } 8034 maybe_scroll_ctext 1 8035 $ctext conf -state disabled 8036 } 8037 8038 # If the filename (name) is under any of the passed filter paths 8039 # then return true to include the file in the listing. 8040 proc path_filter {filter name} { 8041 set worktree [gitworktree] 8042 foreach p $filter { 8043 set fq_p [file normalize $p] 8044 set fq_n [file normalize [file join $worktree $name]] 8045 if {[string match [file normalize $fq_p]* $fq_n]} { 8046 return 1 8047 } 8048 } 8049 return 0 8050 } 8051 8052 proc addtocflist {ids} { 8053 global treediffs 8054 8055 add_flist $treediffs($ids) 8056 getblobdiffs $ids 8057 } 8058 8059 proc diffcmd {ids flags} { 8060 global log_showroot nullid nullid2 8061 8062 set i [lsearch -exact $ids $nullid] 8063 set j [lsearch -exact $ids $nullid2] 8064 if {$i >= 0} { 8065 if {[llength $ids] > 1 && $j < 0} { 8066 # comparing working directory with some specific revision 8067 set cmd [concat git diff-index $flags] 8068 if {$i == 0} { 8069 lappend cmd -R [lindex $ids 1] 8070 } else { 8071 lappend cmd [lindex $ids 0] 8072 } 8073 } else { 8074 # comparing working directory with index 8075 set cmd [concat git diff-files $flags] 8076 if {$j == 1} { 8077 lappend cmd -R 8078 } 8079 } 8080 } elseif {$j >= 0} { 8081 set flags "$flags --ignore-submodules=dirty" 8082 set cmd [concat git diff-index --cached $flags] 8083 if {[llength $ids] > 1} { 8084 # comparing index with specific revision 8085 if {$j == 0} { 8086 lappend cmd -R [lindex $ids 1] 8087 } else { 8088 lappend cmd [lindex $ids 0] 8089 } 8090 } else { 8091 # comparing index with HEAD 8092 lappend cmd HEAD 8093 } 8094 } else { 8095 if {$log_showroot} { 8096 lappend flags --root 8097 } 8098 set cmd [concat git diff-tree -r $flags $ids] 8099 } 8100 return $cmd 8101 } 8102 8103 proc gettreediffs {ids} { 8104 global treediff treepending limitdiffs vfilelimit curview 8105 8106 set cmd [diffcmd $ids {--no-commit-id}] 8107 if {$limitdiffs && $vfilelimit($curview) ne {}} { 8108 set cmd [concat $cmd -- $vfilelimit($curview)] 8109 } 8110 if {[catch {set gdtf [safe_open_command $cmd]}]} return 8111 8112 set treepending $ids 8113 set treediff {} 8114 fconfigure $gdtf -blocking 0 -translation binary 8115 filerun $gdtf [list gettreediffline $gdtf $ids] 8116 } 8117 8118 proc gettreediffline {gdtf ids} { 8119 global treediff treediffs treepending diffids diffmergeid 8120 global cmitmode vfilelimit curview limitdiffs perfile_attrs 8121 8122 set nr 0 8123 set sublist {} 8124 set max 1000 8125 if {$perfile_attrs} { 8126 # cache_gitattr is slow, and even slower on win32 where we 8127 # have to invoke it for only about 30 paths at a time 8128 set max 500 8129 if {[tk windowingsystem] == "win32"} { 8130 set max 120 8131 } 8132 } 8133 while {[incr nr] <= $max && [gets $gdtf line] >= 0} { 8134 set i [string first "\t" $line] 8135 if {$i >= 0} { 8136 set file [string range $line [expr {$i+1}] end] 8137 if {[string index $file 0] eq "\""} { 8138 set file [lindex $file 0] 8139 } 8140 set file [convertfrom utf-8 $file] 8141 if {$file ne [lindex $treediff end]} { 8142 lappend treediff $file 8143 lappend sublist $file 8144 } 8145 } 8146 } 8147 if {$perfile_attrs} { 8148 cache_gitattr encoding $sublist 8149 } 8150 if {![eof $gdtf]} { 8151 return [expr {$nr >= $max? 2: 1}] 8152 } 8153 close $gdtf 8154 set treediffs($ids) $treediff 8155 unset treepending 8156 if {$cmitmode eq "tree" && [llength $diffids] == 1} { 8157 gettree $diffids 8158 } elseif {$ids != $diffids} { 8159 if {![info exists diffmergeid]} { 8160 gettreediffs $diffids 8161 } 8162 } else { 8163 addtocflist $ids 8164 } 8165 return 0 8166 } 8167 8168 # empty string or positive integer 8169 proc diffcontextvalidate {v} { 8170 return [regexp {^(|[1-9][0-9]*)$} $v] 8171 } 8172 8173 proc diffcontextchange {n1 n2 op} { 8174 global diffcontextstring diffcontext 8175 8176 if {[string is integer -strict $diffcontextstring]} { 8177 if {$diffcontextstring >= 0} { 8178 set diffcontext $diffcontextstring 8179 reselectline 8180 } 8181 } 8182 } 8183 8184 proc changeignorespace {} { 8185 reselectline 8186 } 8187 8188 proc changeworddiff {name ix op} { 8189 reselectline 8190 } 8191 8192 proc initblobdiffvars {} { 8193 global diffencoding targetline diffnparents 8194 global diffinhdr currdiffsubmod diffseehere 8195 set targetline {} 8196 set diffnparents 0 8197 set diffinhdr 0 8198 set diffencoding [get_path_encoding {}] 8199 set currdiffsubmod "" 8200 set diffseehere -1 8201 } 8202 8203 proc getblobdiffs {ids} { 8204 global blobdifffd diffids env 8205 global treediffs 8206 global diffcontext 8207 global ignorespace 8208 global worddiff 8209 global limitdiffs vfilelimit curview 8210 8211 set cmd [diffcmd $ids "-p --textconv --submodule -C --cc --no-commit-id -U$diffcontext"] 8212 if {$ignorespace} { 8213 append cmd " -w" 8214 } 8215 if {$worddiff ne [mc "Line diff"]} { 8216 append cmd " --word-diff=porcelain" 8217 } 8218 if {$limitdiffs && $vfilelimit($curview) ne {}} { 8219 set cmd [concat $cmd -- $vfilelimit($curview)] 8220 } 8221 if {[catch {set bdf [safe_open_command $cmd]} err]} { 8222 error_popup [mc "Error getting diffs: %s" $err] 8223 return 8224 } 8225 fconfigure $bdf -blocking 0 -translation binary 8226 set blobdifffd($ids) $bdf 8227 initblobdiffvars 8228 filerun $bdf [list getblobdiffline $bdf $diffids] 8229 } 8230 8231 proc savecmitpos {} { 8232 global ctext cmitmode 8233 8234 if {$cmitmode eq "tree"} { 8235 return {} 8236 } 8237 return [list target_scrollpos [$ctext index @0,0]] 8238 } 8239 8240 proc savectextpos {} { 8241 global ctext 8242 8243 return [list target_scrollpos [$ctext index @0,0]] 8244 } 8245 8246 proc maybe_scroll_ctext {ateof} { 8247 global ctext target_scrollpos 8248 8249 if {![info exists target_scrollpos]} return 8250 if {!$ateof} { 8251 set nlines [expr {[winfo height $ctext] 8252 / [font metrics textfont -linespace]}] 8253 if {[$ctext compare "$target_scrollpos + $nlines lines" <= end]} return 8254 } 8255 $ctext yview $target_scrollpos 8256 unset target_scrollpos 8257 } 8258 8259 proc setinlist {var i val} { 8260 global $var 8261 8262 while {[llength [set $var]] < $i} { 8263 lappend $var {} 8264 } 8265 if {[llength [set $var]] == $i} { 8266 lappend $var $val 8267 } else { 8268 lset $var $i $val 8269 } 8270 } 8271 8272 proc makediffhdr {fname ids} { 8273 global ctext curdiffstart treediffs diffencoding 8274 global ctext_file_names jump_to_here targetline diffline 8275 8276 set fname [convertfrom utf-8 $fname] 8277 set diffencoding [get_path_encoding $fname] 8278 set i [lsearch -exact $treediffs($ids) $fname] 8279 if {$i >= 0} { 8280 setinlist difffilestart $i $curdiffstart 8281 } 8282 lset ctext_file_names end $fname 8283 set l [expr {(78 - [string length $fname]) / 2}] 8284 set pad [string range "----------------------------------------" 1 $l] 8285 $ctext insert $curdiffstart "$pad $fname $pad" filesep 8286 set targetline {} 8287 if {$jump_to_here ne {} && [lindex $jump_to_here 0] eq $fname} { 8288 set targetline [lindex $jump_to_here 1] 8289 } 8290 set diffline 0 8291 } 8292 8293 proc blobdiffmaybeseehere {ateof} { 8294 global diffseehere 8295 if {$diffseehere >= 0} { 8296 mark_ctext_line [lindex [split $diffseehere .] 0] 8297 } 8298 maybe_scroll_ctext $ateof 8299 } 8300 8301 proc getblobdiffline {bdf ids} { 8302 global diffids blobdifffd 8303 global ctext 8304 8305 set nr 0 8306 $ctext conf -state normal 8307 while {[incr nr] <= 1000 && [gets $bdf line] >= 0} { 8308 if {$ids != $diffids || $bdf != $blobdifffd($ids)} { 8309 # Older diff read. Abort it. 8310 catch {close $bdf} 8311 if {$ids != $diffids} { 8312 array unset blobdifffd $ids 8313 } 8314 return 0 8315 } 8316 parseblobdiffline $ids $line 8317 } 8318 $ctext conf -state disabled 8319 blobdiffmaybeseehere [eof $bdf] 8320 if {[eof $bdf]} { 8321 catch {close $bdf} 8322 array unset blobdifffd $ids 8323 return 0 8324 } 8325 return [expr {$nr >= 1000? 2: 1}] 8326 } 8327 8328 proc parseblobdiffline {ids line} { 8329 global ctext curdiffstart 8330 global diffnexthead diffnextnote difffilestart 8331 global ctext_file_names ctext_file_lines 8332 global diffinhdr treediffs mergemax diffnparents 8333 global diffencoding jump_to_here targetline diffline currdiffsubmod 8334 global worddiff diffseehere 8335 8336 if {![string compare -length 5 "diff " $line]} { 8337 if {![regexp {^diff (--cc|--git) } $line m type]} { 8338 set line [convertfrom utf-8 $line] 8339 $ctext insert end "$line\n" hunksep 8340 return 8341 } 8342 # start of a new file 8343 set diffinhdr 1 8344 set currdiffsubmod "" 8345 8346 $ctext insert end "\n" 8347 set curdiffstart [$ctext index "end - 1c"] 8348 lappend ctext_file_names "" 8349 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] 8350 $ctext insert end "\n" filesep 8351 8352 if {$type eq "--cc"} { 8353 # start of a new file in a merge diff 8354 set fname [string range $line 10 end] 8355 if {[lsearch -exact $treediffs($ids) $fname] < 0} { 8356 lappend treediffs($ids) $fname 8357 add_flist [list $fname] 8358 } 8359 8360 } else { 8361 set line [string range $line 11 end] 8362 # If the name hasn't changed the length will be odd, 8363 # the middle char will be a space, and the two bits either 8364 # side will be a/name and b/name, or "a/name" and "b/name". 8365 # If the name has changed we'll get "rename from" and 8366 # "rename to" or "copy from" and "copy to" lines following 8367 # this, and we'll use them to get the filenames. 8368 # This complexity is necessary because spaces in the 8369 # filename(s) don't get escaped. 8370 set l [string length $line] 8371 set i [expr {$l / 2}] 8372 if {!(($l & 1) && [string index $line $i] eq " " && 8373 [string range $line 2 [expr {$i - 1}]] eq \ 8374 [string range $line [expr {$i + 3}] end])} { 8375 return 8376 } 8377 # unescape if quoted and chop off the a/ from the front 8378 if {[string index $line 0] eq "\""} { 8379 set fname [string range [lindex $line 0] 2 end] 8380 } else { 8381 set fname [string range $line 2 [expr {$i - 1}]] 8382 } 8383 } 8384 makediffhdr $fname $ids 8385 8386 } elseif {![string compare -length 16 "* Unmerged path " $line]} { 8387 set fname [convertfrom utf-8 [string range $line 16 end]] 8388 $ctext insert end "\n" 8389 set curdiffstart [$ctext index "end - 1c"] 8390 lappend ctext_file_names $fname 8391 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] 8392 $ctext insert end "$line\n" filesep 8393 set i [lsearch -exact $treediffs($ids) $fname] 8394 if {$i >= 0} { 8395 setinlist difffilestart $i $curdiffstart 8396 } 8397 8398 } elseif {![string compare -length 2 "@@" $line]} { 8399 regexp {^@@+} $line ats 8400 set line [convertfrom $diffencoding $line] 8401 $ctext insert end "$line\n" hunksep 8402 if {[regexp { \+(\d+),\d+ @@} $line m nl]} { 8403 set diffline $nl 8404 } 8405 set diffnparents [expr {[string length $ats] - 1}] 8406 set diffinhdr 0 8407 8408 } elseif {![string compare -length 10 "Submodule " $line]} { 8409 # start of a new submodule 8410 if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} { 8411 set fname [string range $line 10 [expr [lindex $nameend 0] - 2]] 8412 } else { 8413 set fname [string range $line 10 [expr [string first "contains " $line] - 2]] 8414 } 8415 if {$currdiffsubmod != $fname} { 8416 $ctext insert end "\n"; # Add newline after commit message 8417 } 8418 if {$currdiffsubmod != $fname} { 8419 set curdiffstart [$ctext index "end - 1c"] 8420 lappend ctext_file_names "" 8421 lappend ctext_file_lines [lindex [split $curdiffstart "."] 0] 8422 makediffhdr $fname $ids 8423 set currdiffsubmod $fname 8424 $ctext insert end "\n$line\n" filesep 8425 } else { 8426 $ctext insert end "$line\n" filesep 8427 } 8428 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} { 8429 set line [convertfrom $diffencoding $line] 8430 $ctext insert end "$line\n" dresult 8431 } elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} { 8432 set line [convertfrom $diffencoding $line] 8433 $ctext insert end "$line\n" d0 8434 } elseif {$diffinhdr} { 8435 if {![string compare -length 12 "rename from " $line]} { 8436 set fname [string range $line [expr 6 + [string first " from " $line] ] end] 8437 if {[string index $fname 0] eq "\""} { 8438 set fname [lindex $fname 0] 8439 } 8440 set fname [convertfrom utf-8 $fname] 8441 set i [lsearch -exact $treediffs($ids) $fname] 8442 if {$i >= 0} { 8443 setinlist difffilestart $i $curdiffstart 8444 } 8445 set line "rename from $fname" 8446 } elseif {![string compare -length 10 $line "rename to "] || 8447 ![string compare -length 8 $line "copy to "]} { 8448 set fname [string range $line [expr 4 + [string first " to " $line] ] end] 8449 if {[string index $fname 0] eq "\""} { 8450 set fname [lindex $fname 0] 8451 } 8452 makediffhdr $fname $ids 8453 set line "[lindex $line 0] to $fname" 8454 } elseif {![string compare -length 10 $line "copy from "]} { 8455 set fname [string range $line 10 end] 8456 if {[string index $fname 0] eq "\""} { 8457 set fname [lindex $fname 0] 8458 } 8459 set line "copy from $fname" 8460 } elseif {[string compare -length 3 $line "---"] == 0} { 8461 # do nothing 8462 return 8463 } elseif {[string compare -length 3 $line "+++"] == 0} { 8464 set diffinhdr 0 8465 return 8466 } 8467 set line [convertfrom utf-8 $line] 8468 $ctext insert end "$line\n" filesep 8469 8470 } else { 8471 set line [string map {\x1A ^Z} \ 8472 [convertfrom $diffencoding $line]] 8473 # parse the prefix - one ' ', '-' or '+' for each parent 8474 set prefix [string range $line 0 [expr {$diffnparents - 1}]] 8475 set tag [expr {$diffnparents > 1? "m": "d"}] 8476 set dowords [expr {$worddiff ne [mc "Line diff"] && $diffnparents == 1}] 8477 set words_pre_markup "" 8478 set words_post_markup "" 8479 if {[string trim $prefix " -+"] eq {}} { 8480 # prefix only has " ", "-" and "+" in it: normal diff line 8481 set num [string first "-" $prefix] 8482 if {$dowords} { 8483 set line [string range $line 1 end] 8484 } 8485 if {$num >= 0} { 8486 # removed line, first parent with line is $num 8487 if {$num >= $mergemax} { 8488 set num "max" 8489 } 8490 if {$dowords && $worddiff eq [mc "Markup words"]} { 8491 $ctext insert end "\[-$line-\]" $tag$num 8492 } else { 8493 $ctext insert end "$line" $tag$num 8494 } 8495 if {!$dowords} { 8496 $ctext insert end "\n" $tag$num 8497 } 8498 } else { 8499 set tags {} 8500 if {[string first "+" $prefix] >= 0} { 8501 # added line 8502 lappend tags ${tag}result 8503 if {$diffnparents > 1} { 8504 set num [string first " " $prefix] 8505 if {$num >= 0} { 8506 if {$num >= $mergemax} { 8507 set num "max" 8508 } 8509 lappend tags m$num 8510 } 8511 } 8512 set words_pre_markup "{+" 8513 set words_post_markup "+}" 8514 } 8515 if {$targetline ne {}} { 8516 if {$diffline == $targetline} { 8517 set diffseehere [$ctext index "end - 1 chars"] 8518 set targetline {} 8519 } else { 8520 incr diffline 8521 } 8522 } 8523 if {$dowords && $worddiff eq [mc "Markup words"]} { 8524 $ctext insert end "$words_pre_markup$line$words_post_markup" $tags 8525 } else { 8526 $ctext insert end "$line" $tags 8527 } 8528 if {!$dowords} { 8529 $ctext insert end "\n" $tags 8530 } 8531 } 8532 } elseif {$dowords && $prefix eq "~"} { 8533 $ctext insert end "\n" {} 8534 } else { 8535 # "\ No newline at end of file", 8536 # or something else we don't recognize 8537 $ctext insert end "$line\n" hunksep 8538 } 8539 } 8540 } 8541 8542 proc changediffdisp {} { 8543 global ctext diffelide 8544 8545 $ctext tag conf d0 -elide [lindex $diffelide 0] 8546 $ctext tag conf dresult -elide [lindex $diffelide 1] 8547 } 8548 8549 proc highlightfile {cline} { 8550 global cflist cflist_top 8551 8552 if {![info exists cflist_top]} return 8553 8554 $cflist tag remove highlight $cflist_top.0 "$cflist_top.0 lineend" 8555 $cflist tag add highlight $cline.0 "$cline.0 lineend" 8556 $cflist see $cline.0 8557 set cflist_top $cline 8558 } 8559 8560 proc highlightfile_for_scrollpos {topidx} { 8561 global cmitmode difffilestart 8562 8563 if {$cmitmode eq "tree"} return 8564 if {![info exists difffilestart]} return 8565 8566 set top [lindex [split $topidx .] 0] 8567 if {$difffilestart eq {} || $top < [lindex $difffilestart 0]} { 8568 highlightfile 0 8569 } else { 8570 highlightfile [expr {[bsearch $difffilestart $top] + 2}] 8571 } 8572 } 8573 8574 proc prevfile {} { 8575 global difffilestart ctext cmitmode 8576 8577 if {$cmitmode eq "tree"} return 8578 set prev 0.0 8579 set here [$ctext index @0,0] 8580 foreach loc $difffilestart { 8581 if {[$ctext compare $loc >= $here]} { 8582 $ctext yview $prev 8583 return 8584 } 8585 set prev $loc 8586 } 8587 $ctext yview $prev 8588 } 8589 8590 proc nextfile {} { 8591 global difffilestart ctext cmitmode 8592 8593 if {$cmitmode eq "tree"} return 8594 set here [$ctext index @0,0] 8595 foreach loc $difffilestart { 8596 if {[$ctext compare $loc > $here]} { 8597 $ctext yview $loc 8598 return 8599 } 8600 } 8601 } 8602 8603 proc clear_ctext {{first 1.0}} { 8604 global ctext smarktop smarkbot 8605 global ctext_file_names ctext_file_lines 8606 global pendinglinks 8607 8608 set l [lindex [split $first .] 0] 8609 if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} { 8610 set smarktop $l 8611 } 8612 if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} { 8613 set smarkbot $l 8614 } 8615 $ctext delete $first end 8616 if {$first eq "1.0"} { 8617 unset -nocomplain pendinglinks 8618 } 8619 set ctext_file_names {} 8620 set ctext_file_lines {} 8621 } 8622 8623 proc settabs {{firstab {}}} { 8624 global firsttabstop tabstop ctext 8625 8626 if {$firstab ne {}} { 8627 set firsttabstop $firstab 8628 } 8629 set w [font measure textfont "0"] 8630 if {$firsttabstop != 0} { 8631 $ctext conf -tabs [list [expr {($firsttabstop + $tabstop) * $w}] \ 8632 [expr {($firsttabstop + 2 * $tabstop) * $w}]] 8633 } else { 8634 $ctext conf -tabs [expr {$tabstop * $w}] 8635 } 8636 } 8637 8638 proc incrsearch {name ix op} { 8639 global ctext searchstring searchdirn 8640 8641 if {[catch {$ctext index anchor}]} { 8642 # no anchor set, use start of selection, or of visible area 8643 set sel [$ctext tag ranges sel] 8644 if {$sel ne {}} { 8645 $ctext mark set anchor [lindex $sel 0] 8646 } elseif {$searchdirn eq "-forwards"} { 8647 $ctext mark set anchor @0,0 8648 } else { 8649 $ctext mark set anchor @0,[winfo height $ctext] 8650 } 8651 } 8652 if {$searchstring ne {}} { 8653 set here [$ctext search -count mlen $searchdirn -- $searchstring anchor] 8654 if {$here ne {}} { 8655 $ctext see $here 8656 set mend "$here + $mlen c" 8657 $ctext tag remove sel 1.0 end 8658 $ctext tag add sel $here $mend 8659 suppress_highlighting_file_for_current_scrollpos 8660 highlightfile_for_scrollpos $here 8661 } 8662 } 8663 rehighlight_search_results 8664 } 8665 8666 proc dosearch {} { 8667 global sstring ctext searchstring searchdirn 8668 8669 focus $sstring 8670 $sstring icursor end 8671 set searchdirn -forwards 8672 if {$searchstring ne {}} { 8673 set sel [$ctext tag ranges sel] 8674 if {$sel ne {}} { 8675 set start "[lindex $sel 0] + 1c" 8676 } elseif {[catch {set start [$ctext index anchor]}]} { 8677 set start "@0,0" 8678 } 8679 set match [$ctext search -count mlen -- $searchstring $start] 8680 $ctext tag remove sel 1.0 end 8681 if {$match eq {}} { 8682 bell 8683 return 8684 } 8685 $ctext see $match 8686 suppress_highlighting_file_for_current_scrollpos 8687 highlightfile_for_scrollpos $match 8688 set mend "$match + $mlen c" 8689 $ctext tag add sel $match $mend 8690 $ctext mark unset anchor 8691 rehighlight_search_results 8692 } 8693 } 8694 8695 proc dosearchback {} { 8696 global sstring ctext searchstring searchdirn 8697 8698 focus $sstring 8699 $sstring icursor end 8700 set searchdirn -backwards 8701 if {$searchstring ne {}} { 8702 set sel [$ctext tag ranges sel] 8703 if {$sel ne {}} { 8704 set start [lindex $sel 0] 8705 } elseif {[catch {set start [$ctext index anchor]}]} { 8706 set start @0,[winfo height $ctext] 8707 } 8708 set match [$ctext search -backwards -count ml -- $searchstring $start] 8709 $ctext tag remove sel 1.0 end 8710 if {$match eq {}} { 8711 bell 8712 return 8713 } 8714 $ctext see $match 8715 suppress_highlighting_file_for_current_scrollpos 8716 highlightfile_for_scrollpos $match 8717 set mend "$match + $ml c" 8718 $ctext tag add sel $match $mend 8719 $ctext mark unset anchor 8720 rehighlight_search_results 8721 } 8722 } 8723 8724 proc rehighlight_search_results {} { 8725 global ctext searchstring 8726 8727 $ctext tag remove found 1.0 end 8728 $ctext tag remove currentsearchhit 1.0 end 8729 8730 if {$searchstring ne {}} { 8731 searchmarkvisible 1 8732 } 8733 } 8734 8735 proc searchmark {first last} { 8736 global ctext searchstring 8737 8738 set sel [$ctext tag ranges sel] 8739 8740 set mend $first.0 8741 while {1} { 8742 set match [$ctext search -count mlen -- $searchstring $mend $last.end] 8743 if {$match eq {}} break 8744 set mend "$match + $mlen c" 8745 if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} { 8746 $ctext tag add currentsearchhit $match $mend 8747 } else { 8748 $ctext tag add found $match $mend 8749 } 8750 } 8751 } 8752 8753 proc searchmarkvisible {doall} { 8754 global ctext smarktop smarkbot 8755 8756 set topline [lindex [split [$ctext index @0,0] .] 0] 8757 set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0] 8758 if {$doall || $botline < $smarktop || $topline > $smarkbot} { 8759 # no overlap with previous 8760 searchmark $topline $botline 8761 set smarktop $topline 8762 set smarkbot $botline 8763 } else { 8764 if {$topline < $smarktop} { 8765 searchmark $topline [expr {$smarktop-1}] 8766 set smarktop $topline 8767 } 8768 if {$botline > $smarkbot} { 8769 searchmark [expr {$smarkbot+1}] $botline 8770 set smarkbot $botline 8771 } 8772 } 8773 } 8774 8775 proc suppress_highlighting_file_for_current_scrollpos {} { 8776 global ctext suppress_highlighting_file_for_this_scrollpos 8777 8778 set suppress_highlighting_file_for_this_scrollpos [$ctext index @0,0] 8779 } 8780 8781 proc scrolltext {f0 f1} { 8782 global searchstring cmitmode ctext 8783 global suppress_highlighting_file_for_this_scrollpos 8784 8785 set topidx [$ctext index @0,0] 8786 if {![info exists suppress_highlighting_file_for_this_scrollpos] 8787 || $topidx ne $suppress_highlighting_file_for_this_scrollpos} { 8788 highlightfile_for_scrollpos $topidx 8789 } 8790 8791 unset -nocomplain suppress_highlighting_file_for_this_scrollpos 8792 8793 .bleft.bottom.sb set $f0 $f1 8794 if {$searchstring ne {}} { 8795 searchmarkvisible 0 8796 } 8797 } 8798 8799 proc setcoords {} { 8800 global linespc charspc canvx0 canvy0 8801 global xspc1 xspc2 lthickness 8802 8803 set linespc [font metrics mainfont -linespace] 8804 set charspc [font measure mainfont "m"] 8805 set canvy0 [expr {int(3 + 0.5 * $linespc)}] 8806 set canvx0 [expr {int(3 + 0.5 * $linespc)}] 8807 set lthickness [expr {int($linespc / 9) + 1}] 8808 set xspc1(0) $linespc 8809 set xspc2 $linespc 8810 } 8811 8812 proc redisplay {} { 8813 global canv 8814 global selectedline 8815 8816 set ymax [lindex [$canv cget -scrollregion] 3] 8817 if {$ymax eq {} || $ymax == 0} return 8818 set span [$canv yview] 8819 clear_display 8820 setcanvscroll 8821 allcanvs yview moveto [lindex $span 0] 8822 drawvisible 8823 if {$selectedline ne {}} { 8824 selectline $selectedline 0 8825 allcanvs yview moveto [lindex $span 0] 8826 } 8827 } 8828 8829 proc parsefont {f n} { 8830 global fontattr 8831 8832 set fontattr($f,family) [lindex $n 0] 8833 set s [lindex $n 1] 8834 if {$s eq {} || $s == 0} { 8835 set s 10 8836 } elseif {$s < 0} { 8837 set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}] 8838 } 8839 set fontattr($f,size) $s 8840 set fontattr($f,weight) normal 8841 set fontattr($f,slant) roman 8842 foreach style [lrange $n 2 end] { 8843 switch -- $style { 8844 "normal" - 8845 "bold" {set fontattr($f,weight) $style} 8846 "roman" - 8847 "italic" {set fontattr($f,slant) $style} 8848 } 8849 } 8850 } 8851 8852 proc fontflags {f {isbold 0}} { 8853 global fontattr 8854 8855 return [list -family $fontattr($f,family) -size $fontattr($f,size) \ 8856 -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \ 8857 -slant $fontattr($f,slant)] 8858 } 8859 8860 proc fontname {f} { 8861 global fontattr 8862 8863 set n [list $fontattr($f,family) $fontattr($f,size)] 8864 if {$fontattr($f,weight) eq "bold"} { 8865 lappend n "bold" 8866 } 8867 if {$fontattr($f,slant) eq "italic"} { 8868 lappend n "italic" 8869 } 8870 return $n 8871 } 8872 8873 proc incrfont {inc} { 8874 global mainfont textfont ctext canv cflist showrefstop 8875 global stopped entries fontattr 8876 8877 unmarkmatches 8878 set s $fontattr(mainfont,size) 8879 incr s $inc 8880 if {$s < 1} { 8881 set s 1 8882 } 8883 set fontattr(mainfont,size) $s 8884 font config mainfont -size $s 8885 font config mainfontbold -size $s 8886 set mainfont [fontname mainfont] 8887 set s $fontattr(textfont,size) 8888 incr s $inc 8889 if {$s < 1} { 8890 set s 1 8891 } 8892 set fontattr(textfont,size) $s 8893 font config textfont -size $s 8894 font config textfontbold -size $s 8895 set textfont [fontname textfont] 8896 setcoords 8897 settabs 8898 redisplay 8899 } 8900 8901 proc clearsha1 {} { 8902 global sha1entry sha1string 8903 global hashlength 8904 8905 if {[string length $sha1string] == $hashlength} { 8906 $sha1entry delete 0 end 8907 } 8908 } 8909 8910 proc sha1change {n1 n2 op} { 8911 global sha1string currentid sha1but 8912 8913 if {$sha1string == {} 8914 || ([info exists currentid] && $sha1string == $currentid)} { 8915 set state disabled 8916 } else { 8917 set state normal 8918 } 8919 if {[$sha1but cget -state] == $state} return 8920 if {$state == "normal"} { 8921 $sha1but conf -state normal -text "[mc "Goto:"] " 8922 } else { 8923 $sha1but conf -state disabled -text "[mc "Commit ID:"] " 8924 } 8925 } 8926 8927 proc gotocommit {} { 8928 global sha1string tagids headids curview varcid 8929 global hashlength 8930 8931 if {$sha1string == {} 8932 || ([info exists currentid] && $sha1string == $currentid)} return 8933 if {[info exists tagids($sha1string)]} { 8934 set id $tagids($sha1string) 8935 } elseif {[info exists headids($sha1string)]} { 8936 set id $headids($sha1string) 8937 } else { 8938 set id [string tolower $sha1string] 8939 if {[regexp {^[0-9a-f]{4,63}$} $id]} { 8940 set matches [longid $id] 8941 if {$matches ne {}} { 8942 if {[llength $matches] > 1} { 8943 error_popup [mc "Short commit ID %s is ambiguous" $id] 8944 return 8945 } 8946 set id [lindex $matches 0] 8947 } 8948 } else { 8949 if {[catch {set id [safe_exec [list git rev-parse --verify $sha1string]]}]} { 8950 error_popup [mc "Revision %s is not known" $sha1string] 8951 return 8952 } 8953 } 8954 } 8955 if {[commitinview $id $curview]} { 8956 selectline [rowofcommit $id] 1 8957 return 8958 } 8959 if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} { 8960 set msg [mc "Commit ID %s is not known" $sha1string] 8961 } else { 8962 set msg [mc "Revision %s is not in the current view" $sha1string] 8963 } 8964 error_popup $msg 8965 } 8966 8967 proc lineenter {x y id} { 8968 global hoverx hovery hoverid hovertimer 8969 global commitinfo canv 8970 8971 if {![info exists commitinfo($id)] && ![getcommit $id]} return 8972 set hoverx $x 8973 set hovery $y 8974 set hoverid $id 8975 if {[info exists hovertimer]} { 8976 after cancel $hovertimer 8977 } 8978 set hovertimer [after 500 linehover] 8979 $canv delete hover 8980 } 8981 8982 proc linemotion {x y id} { 8983 global hoverx hovery hoverid hovertimer 8984 8985 if {[info exists hoverid] && $id == $hoverid} { 8986 set hoverx $x 8987 set hovery $y 8988 if {[info exists hovertimer]} { 8989 after cancel $hovertimer 8990 } 8991 set hovertimer [after 500 linehover] 8992 } 8993 } 8994 8995 proc lineleave {id} { 8996 global hoverid hovertimer canv 8997 8998 if {[info exists hoverid] && $id == $hoverid} { 8999 $canv delete hover 9000 if {[info exists hovertimer]} { 9001 after cancel $hovertimer 9002 unset hovertimer 9003 } 9004 unset hoverid 9005 } 9006 } 9007 9008 proc linehover {} { 9009 global hoverx hovery hoverid hovertimer 9010 global canv linespc lthickness 9011 global linehoverbgcolor linehoverfgcolor linehoveroutlinecolor 9012 9013 global commitinfo 9014 9015 set text [lindex $commitinfo($hoverid) 0] 9016 set ymax [lindex [$canv cget -scrollregion] 3] 9017 if {$ymax == {}} return 9018 set yfrac [lindex [$canv yview] 0] 9019 set x [expr {$hoverx + 2 * $linespc}] 9020 set y [expr {$hovery + $yfrac * $ymax - $linespc / 2}] 9021 set x0 [expr {$x - 2 * $lthickness}] 9022 set y0 [expr {$y - 2 * $lthickness}] 9023 set x1 [expr {$x + [font measure mainfont $text] + 2 * $lthickness}] 9024 set y1 [expr {$y + $linespc + 2 * $lthickness}] 9025 set t [$canv create rectangle $x0 $y0 $x1 $y1 \ 9026 -fill $linehoverbgcolor -outline $linehoveroutlinecolor \ 9027 -width 1 -tags hover] 9028 $canv raise $t 9029 set t [$canv create text $x $y -anchor nw -text $text -tags hover \ 9030 -font mainfont -fill $linehoverfgcolor] 9031 $canv raise $t 9032 } 9033 9034 proc clickisonarrow {id y} { 9035 global lthickness 9036 9037 set ranges [rowranges $id] 9038 set thresh [expr {2 * $lthickness + 6}] 9039 set n [expr {[llength $ranges] - 1}] 9040 for {set i 1} {$i < $n} {incr i} { 9041 set row [lindex $ranges $i] 9042 if {abs([yc $row] - $y) < $thresh} { 9043 return $i 9044 } 9045 } 9046 return {} 9047 } 9048 9049 proc arrowjump {id n y} { 9050 global canv 9051 9052 # 1 <-> 2, 3 <-> 4, etc... 9053 set n [expr {(($n - 1) ^ 1) + 1}] 9054 set row [lindex [rowranges $id] $n] 9055 set yt [yc $row] 9056 set ymax [lindex [$canv cget -scrollregion] 3] 9057 if {$ymax eq {} || $ymax <= 0} return 9058 set view [$canv yview] 9059 set yspan [expr {[lindex $view 1] - [lindex $view 0]}] 9060 set yfrac [expr {$yt / $ymax - $yspan / 2}] 9061 if {$yfrac < 0} { 9062 set yfrac 0 9063 } 9064 allcanvs yview moveto $yfrac 9065 } 9066 9067 proc lineclick {x y id isnew} { 9068 global ctext commitinfo children canv thickerline curview 9069 9070 if {![info exists commitinfo($id)] && ![getcommit $id]} return 9071 unmarkmatches 9072 unselectline 9073 normalline 9074 $canv delete hover 9075 # draw this line thicker than normal 9076 set thickerline $id 9077 drawlines $id 9078 if {$isnew} { 9079 set ymax [lindex [$canv cget -scrollregion] 3] 9080 if {$ymax eq {}} return 9081 set yfrac [lindex [$canv yview] 0] 9082 set y [expr {$y + $yfrac * $ymax}] 9083 } 9084 set dirn [clickisonarrow $id $y] 9085 if {$dirn ne {}} { 9086 arrowjump $id $dirn $y 9087 return 9088 } 9089 9090 if {$isnew} { 9091 addtohistory [list lineclick $x $y $id 0] savectextpos 9092 } 9093 # fill the details pane with info about this line 9094 $ctext conf -state normal 9095 clear_ctext 9096 settabs 0 9097 $ctext insert end "[mc "Parent"]:\t" 9098 $ctext insert end $id link0 9099 setlink $id link0 9100 set info $commitinfo($id) 9101 $ctext insert end "\n\t[lindex $info 0]\n" 9102 $ctext insert end "\t[mc "Author"]:\t[lindex $info 1]\n" 9103 set date [formatdate [lindex $info 2]] 9104 $ctext insert end "\t[mc "Date"]:\t$date\n" 9105 set kids $children($curview,$id) 9106 if {$kids ne {}} { 9107 $ctext insert end "\n[mc "Children"]:" 9108 set i 0 9109 foreach child $kids { 9110 incr i 9111 if {![info exists commitinfo($child)] && ![getcommit $child]} continue 9112 set info $commitinfo($child) 9113 $ctext insert end "\n\t" 9114 $ctext insert end $child link$i 9115 setlink $child link$i 9116 $ctext insert end "\n\t[lindex $info 0]" 9117 $ctext insert end "\n\t[mc "Author"]:\t[lindex $info 1]" 9118 set date [formatdate [lindex $info 2]] 9119 $ctext insert end "\n\t[mc "Date"]:\t$date\n" 9120 } 9121 } 9122 maybe_scroll_ctext 1 9123 $ctext conf -state disabled 9124 init_flist {} 9125 } 9126 9127 proc normalline {} { 9128 global thickerline 9129 if {[info exists thickerline]} { 9130 set id $thickerline 9131 unset thickerline 9132 drawlines $id 9133 } 9134 } 9135 9136 proc selbyid {id {isnew 1}} { 9137 global curview 9138 if {[commitinview $id $curview]} { 9139 selectline [rowofcommit $id] $isnew 9140 } 9141 } 9142 9143 proc mstime {} { 9144 global startmstime 9145 if {![info exists startmstime]} { 9146 set startmstime [clock clicks -milliseconds] 9147 } 9148 return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]] 9149 } 9150 9151 proc rowmenu {x y id} { 9152 global rowctxmenu selectedline rowmenuid curview 9153 global nullid nullid2 fakerowmenu mainhead markedid 9154 9155 stopfinding 9156 set rowmenuid $id 9157 if {$selectedline eq {} || [rowofcommit $id] eq $selectedline} { 9158 set state disabled 9159 } else { 9160 set state normal 9161 } 9162 if {[info exists markedid] && $markedid ne $id} { 9163 set mstate normal 9164 } else { 9165 set mstate disabled 9166 } 9167 if {$id ne $nullid && $id ne $nullid2} { 9168 set menu $rowctxmenu 9169 if {$mainhead ne {}} { 9170 $menu entryconfigure 8 -label [mc "Reset %s branch to here" $mainhead] -state normal 9171 } else { 9172 $menu entryconfigure 8 -label [mc "Detached head: can't reset" $mainhead] -state disabled 9173 } 9174 $menu entryconfigure 10 -state $mstate 9175 $menu entryconfigure 11 -state $mstate 9176 $menu entryconfigure 12 -state $mstate 9177 } else { 9178 set menu $fakerowmenu 9179 } 9180 $menu entryconfigure [mca "Diff this -> selected"] -state $state 9181 $menu entryconfigure [mca "Diff selected -> this"] -state $state 9182 $menu entryconfigure [mca "Make patch"] -state $state 9183 $menu entryconfigure [mca "Diff this -> marked commit"] -state $mstate 9184 $menu entryconfigure [mca "Diff marked commit -> this"] -state $mstate 9185 tk_popup $menu $x $y 9186 } 9187 9188 proc markhere {} { 9189 global rowmenuid markedid canv 9190 9191 set markedid $rowmenuid 9192 make_idmark $markedid 9193 } 9194 9195 proc gotomark {} { 9196 global markedid 9197 9198 if {[info exists markedid]} { 9199 selbyid $markedid 9200 } 9201 } 9202 9203 proc replace_by_kids {l r} { 9204 global curview children 9205 9206 set id [commitonrow $r] 9207 set l [lreplace $l 0 0] 9208 foreach kid $children($curview,$id) { 9209 lappend l [rowofcommit $kid] 9210 } 9211 return [lsort -integer -decreasing -unique $l] 9212 } 9213 9214 proc find_common_desc {} { 9215 global markedid rowmenuid curview children 9216 9217 if {![info exists markedid]} return 9218 if {![commitinview $markedid $curview] || 9219 ![commitinview $rowmenuid $curview]} return 9220 #set t1 [clock clicks -milliseconds] 9221 set l1 [list [rowofcommit $markedid]] 9222 set l2 [list [rowofcommit $rowmenuid]] 9223 while 1 { 9224 set r1 [lindex $l1 0] 9225 set r2 [lindex $l2 0] 9226 if {$r1 eq {} || $r2 eq {}} break 9227 if {$r1 == $r2} { 9228 selectline $r1 1 9229 break 9230 } 9231 if {$r1 > $r2} { 9232 set l1 [replace_by_kids $l1 $r1] 9233 } else { 9234 set l2 [replace_by_kids $l2 $r2] 9235 } 9236 } 9237 #set t2 [clock clicks -milliseconds] 9238 #puts "took [expr {$t2-$t1}]ms" 9239 } 9240 9241 proc compare_commits {} { 9242 global markedid rowmenuid curview children 9243 9244 if {![info exists markedid]} return 9245 if {![commitinview $markedid $curview]} return 9246 addtohistory [list do_cmp_commits $markedid $rowmenuid] 9247 do_cmp_commits $markedid $rowmenuid 9248 } 9249 9250 proc getpatchid {id} { 9251 global patchids 9252 9253 if {![info exists patchids($id)]} { 9254 set cmd [diffcmd [list $id] {-p --root}] 9255 if {[catch { 9256 set x [safe_exec_redirect $cmd [list | git patch-id]] 9257 set patchids($id) [lindex $x 0] 9258 }]} { 9259 set patchids($id) "error" 9260 } 9261 } 9262 return $patchids($id) 9263 } 9264 9265 proc do_cmp_commits {a b} { 9266 global ctext curview parents children patchids commitinfo 9267 9268 $ctext conf -state normal 9269 clear_ctext 9270 init_flist {} 9271 for {set i 0} {$i < 100} {incr i} { 9272 set skipa 0 9273 set skipb 0 9274 if {[llength $parents($curview,$a)] > 1} { 9275 appendshortlink $a [mc "Skipping merge commit "] "\n" 9276 set skipa 1 9277 } else { 9278 set patcha [getpatchid $a] 9279 } 9280 if {[llength $parents($curview,$b)] > 1} { 9281 appendshortlink $b [mc "Skipping merge commit "] "\n" 9282 set skipb 1 9283 } else { 9284 set patchb [getpatchid $b] 9285 } 9286 if {!$skipa && !$skipb} { 9287 set heada [lindex $commitinfo($a) 0] 9288 set headb [lindex $commitinfo($b) 0] 9289 if {$patcha eq "error"} { 9290 appendshortlink $a [mc "Error getting patch ID for "] \ 9291 [mc " - stopping\n"] 9292 break 9293 } 9294 if {$patchb eq "error"} { 9295 appendshortlink $b [mc "Error getting patch ID for "] \ 9296 [mc " - stopping\n"] 9297 break 9298 } 9299 if {$patcha eq $patchb} { 9300 if {$heada eq $headb} { 9301 appendshortlink $a [mc "Commit "] 9302 appendshortlink $b " == " " $heada\n" 9303 } else { 9304 appendshortlink $a [mc "Commit "] " $heada\n" 9305 appendshortlink $b [mc " is the same patch as\n "] \ 9306 " $headb\n" 9307 } 9308 set skipa 1 9309 set skipb 1 9310 } else { 9311 $ctext insert end "\n" 9312 appendshortlink $a [mc "Commit "] " $heada\n" 9313 appendshortlink $b [mc " differs from\n "] \ 9314 " $headb\n" 9315 $ctext insert end [mc "Diff of commits:\n\n"] 9316 $ctext conf -state disabled 9317 update 9318 diffcommits $a $b 9319 return 9320 } 9321 } 9322 if {$skipa} { 9323 set kids [real_children $curview,$a] 9324 if {[llength $kids] != 1} { 9325 $ctext insert end "\n" 9326 appendshortlink $a [mc "Commit "] \ 9327 [mc " has %s children - stopping\n" [llength $kids]] 9328 break 9329 } 9330 set a [lindex $kids 0] 9331 } 9332 if {$skipb} { 9333 set kids [real_children $curview,$b] 9334 if {[llength $kids] != 1} { 9335 appendshortlink $b [mc "Commit "] \ 9336 [mc " has %s children - stopping\n" [llength $kids]] 9337 break 9338 } 9339 set b [lindex $kids 0] 9340 } 9341 } 9342 $ctext conf -state disabled 9343 } 9344 9345 proc diffcommits {a b} { 9346 global diffcontext diffids blobdifffd diffinhdr currdiffsubmod 9347 9348 set tmpdir [gitknewtmpdir] 9349 set fna [file join $tmpdir "commit-[string range $a 0 7]"] 9350 set fnb [file join $tmpdir "commit-[string range $b 0 7]"] 9351 if {[catch { 9352 safe_exec_redirect [list git diff-tree -p --pretty $a] [list >$fna] 9353 safe_exec_redirect [list git diff-tree -p --pretty $b] [list >$fnb] 9354 } err]} { 9355 error_popup [mc "Error writing commit to file: %s" $err] 9356 return 9357 } 9358 if {[catch { 9359 set fd [safe_open_command "diff -U$diffcontext $fna $fnb"] 9360 } err]} { 9361 error_popup [mc "Error diffing commits: %s" $err] 9362 return 9363 } 9364 set diffids [list commits $a $b] 9365 set blobdifffd($diffids) $fd 9366 set diffinhdr 0 9367 set currdiffsubmod "" 9368 filerun $fd [list getblobdiffline $fd $diffids] 9369 } 9370 9371 proc diffvssel {dirn} { 9372 global rowmenuid selectedline 9373 9374 if {$selectedline eq {}} return 9375 if {$dirn} { 9376 set oldid [commitonrow $selectedline] 9377 set newid $rowmenuid 9378 } else { 9379 set oldid $rowmenuid 9380 set newid [commitonrow $selectedline] 9381 } 9382 addtohistory [list doseldiff $oldid $newid] savectextpos 9383 doseldiff $oldid $newid 9384 } 9385 9386 proc diffvsmark {dirn} { 9387 global rowmenuid markedid 9388 9389 if {![info exists markedid]} return 9390 if {$dirn} { 9391 set oldid $markedid 9392 set newid $rowmenuid 9393 } else { 9394 set oldid $rowmenuid 9395 set newid $markedid 9396 } 9397 addtohistory [list doseldiff $oldid $newid] savectextpos 9398 doseldiff $oldid $newid 9399 } 9400 9401 proc doseldiff {oldid newid} { 9402 global ctext 9403 global commitinfo 9404 9405 $ctext conf -state normal 9406 clear_ctext 9407 init_flist [mc "Top"] 9408 $ctext insert end "[mc "From"] " 9409 $ctext insert end $oldid link0 9410 setlink $oldid link0 9411 $ctext insert end "\n " 9412 $ctext insert end [lindex $commitinfo($oldid) 0] 9413 $ctext insert end "\n\n[mc "To"] " 9414 $ctext insert end $newid link1 9415 setlink $newid link1 9416 $ctext insert end "\n " 9417 $ctext insert end [lindex $commitinfo($newid) 0] 9418 $ctext insert end "\n" 9419 $ctext conf -state disabled 9420 $ctext tag remove found 1.0 end 9421 startdiff [list $oldid $newid] 9422 } 9423 9424 proc mkpatch {} { 9425 global rowmenuid currentid commitinfo patchtop patchnum 9426 global hashlength 9427 9428 if {![info exists currentid]} return 9429 set oldid $currentid 9430 set oldhead [lindex $commitinfo($oldid) 0] 9431 set newid $rowmenuid 9432 set newhead [lindex $commitinfo($newid) 0] 9433 set top .patch 9434 set patchtop $top 9435 catch {destroy $top} 9436 ttk_toplevel $top 9437 make_transient $top . 9438 ttk::label $top.title -text [mc "Generate patch"] 9439 grid $top.title - -pady 10 9440 ttk::label $top.from -text [mc "From:"] 9441 ttk::entry $top.fromsha1 -width $hashlength 9442 $top.fromsha1 insert 0 $oldid 9443 $top.fromsha1 conf -state readonly 9444 grid $top.from $top.fromsha1 -sticky w 9445 ttk::entry $top.fromhead -width 60 9446 $top.fromhead insert 0 $oldhead 9447 $top.fromhead conf -state readonly 9448 grid x $top.fromhead -sticky w 9449 ttk::label $top.to -text [mc "To:"] 9450 ttk::entry $top.tosha1 -width $hashlength 9451 $top.tosha1 insert 0 $newid 9452 $top.tosha1 conf -state readonly 9453 grid $top.to $top.tosha1 -sticky w 9454 ttk::entry $top.tohead -width 60 9455 $top.tohead insert 0 $newhead 9456 $top.tohead conf -state readonly 9457 grid x $top.tohead -sticky w 9458 ttk::button $top.rev -text [mc "Reverse"] -command mkpatchrev 9459 grid $top.rev x -pady 10 -padx 5 9460 ttk::label $top.flab -text [mc "Output file:"] 9461 ttk::entry $top.fname -width 60 9462 $top.fname insert 0 [file normalize "patch$patchnum.patch"] 9463 incr patchnum 9464 grid $top.flab $top.fname -sticky w 9465 ttk::frame $top.buts 9466 ttk::button $top.buts.gen -text [mc "Generate"] -command mkpatchgo 9467 ttk::button $top.buts.can -text [mc "Cancel"] -command mkpatchcan 9468 bind $top mkpatchgo 9469 bind $top mkpatchcan 9470 grid $top.buts.gen $top.buts.can 9471 grid columnconfigure $top.buts 0 -weight 1 -uniform a 9472 grid columnconfigure $top.buts 1 -weight 1 -uniform a 9473 grid $top.buts - -pady 10 -sticky ew 9474 focus $top.fname 9475 } 9476 9477 proc mkpatchrev {} { 9478 global patchtop 9479 9480 set oldid [$patchtop.fromsha1 get] 9481 set oldhead [$patchtop.fromhead get] 9482 set newid [$patchtop.tosha1 get] 9483 set newhead [$patchtop.tohead get] 9484 foreach e [list fromsha1 fromhead tosha1 tohead] \ 9485 v [list $newid $newhead $oldid $oldhead] { 9486 $patchtop.$e conf -state normal 9487 $patchtop.$e delete 0 end 9488 $patchtop.$e insert 0 $v 9489 $patchtop.$e conf -state readonly 9490 } 9491 } 9492 9493 proc mkpatchgo {} { 9494 global patchtop nullid nullid2 9495 9496 set oldid [$patchtop.fromsha1 get] 9497 set newid [$patchtop.tosha1 get] 9498 set fname [$patchtop.fname get] 9499 set cmd [diffcmd [list $oldid $newid] -p] 9500 if {[catch {safe_exec_redirect $cmd [list >$fname &]} err]} { 9501 error_popup "[mc "Error creating patch:"] $err" $patchtop 9502 } 9503 catch {destroy $patchtop} 9504 unset patchtop 9505 } 9506 9507 proc mkpatchcan {} { 9508 global patchtop 9509 9510 catch {destroy $patchtop} 9511 unset patchtop 9512 } 9513 9514 proc mktag {} { 9515 global rowmenuid mktagtop commitinfo 9516 global hashlength 9517 9518 set top .maketag 9519 set mktagtop $top 9520 catch {destroy $top} 9521 ttk_toplevel $top 9522 make_transient $top . 9523 ttk::label $top.title -text [mc "Create tag"] 9524 grid $top.title - -pady 10 9525 ttk::label $top.id -text [mc "ID:"] 9526 ttk::entry $top.sha1 -width $hashlength 9527 $top.sha1 insert 0 $rowmenuid 9528 $top.sha1 conf -state readonly 9529 grid $top.id $top.sha1 -sticky w 9530 ttk::entry $top.head -width 60 9531 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0] 9532 $top.head conf -state readonly 9533 grid x $top.head -sticky w 9534 ttk::label $top.tlab -text [mc "Tag name:"] 9535 ttk::entry $top.tag -width 60 9536 grid $top.tlab $top.tag -sticky w 9537 ttk::label $top.op -text [mc "Tag message is optional"] 9538 grid $top.op -columnspan 2 -sticky we 9539 ttk::label $top.mlab -text [mc "Tag message:"] 9540 ttk::entry $top.msg -width 60 9541 grid $top.mlab $top.msg -sticky w 9542 ttk::frame $top.buts 9543 ttk::button $top.buts.gen -text [mc "Create"] -command mktaggo 9544 ttk::button $top.buts.can -text [mc "Cancel"] -command mktagcan 9545 bind $top mktaggo 9546 bind $top mktagcan 9547 grid $top.buts.gen $top.buts.can 9548 grid columnconfigure $top.buts 0 -weight 1 -uniform a 9549 grid columnconfigure $top.buts 1 -weight 1 -uniform a 9550 grid $top.buts - -pady 10 -sticky ew 9551 focus $top.tag 9552 } 9553 9554 proc domktag {} { 9555 global mktagtop env tagids idtags 9556 9557 set id [$mktagtop.sha1 get] 9558 set tag [$mktagtop.tag get] 9559 set msg [$mktagtop.msg get] 9560 if {$tag == {}} { 9561 error_popup [mc "No tag name specified"] $mktagtop 9562 return 0 9563 } 9564 if {[info exists tagids($tag)]} { 9565 error_popup [mc "Tag \"%s\" already exists" $tag] $mktagtop 9566 return 0 9567 } 9568 if {[catch { 9569 if {$msg != {}} { 9570 safe_exec [list git tag -a -m $msg $tag $id] 9571 } else { 9572 safe_exec [list git tag $tag $id] 9573 } 9574 } err]} { 9575 error_popup "[mc "Error creating tag:"] $err" $mktagtop 9576 return 0 9577 } 9578 9579 set tagids($tag) $id 9580 lappend idtags($id) $tag 9581 redrawtags $id 9582 addedtag $id 9583 dispneartags 0 9584 run refill_reflist 9585 return 1 9586 } 9587 9588 proc redrawtags {id} { 9589 global canv linehtag idpos currentid curview cmitlisted markedid 9590 global canvxmax iddrawn circleitem mainheadid circlecolors 9591 global mainheadcirclecolor 9592 9593 if {![commitinview $id $curview]} return 9594 if {![info exists iddrawn($id)]} return 9595 set row [rowofcommit $id] 9596 if {$id eq $mainheadid} { 9597 set ofill $mainheadcirclecolor 9598 } else { 9599 set ofill [lindex $circlecolors $cmitlisted($curview,$id)] 9600 } 9601 $canv itemconf $circleitem($row) -fill $ofill 9602 $canv delete tag.$id 9603 set xt [eval drawtags $id $idpos($id)] 9604 $canv coords $linehtag($id) $xt [lindex $idpos($id) 2] 9605 set text [$canv itemcget $linehtag($id) -text] 9606 set font [$canv itemcget $linehtag($id) -font] 9607 set xr [expr {$xt + [font measure $font $text]}] 9608 if {$xr > $canvxmax} { 9609 set canvxmax $xr 9610 setcanvscroll 9611 } 9612 if {[info exists currentid] && $currentid == $id} { 9613 make_secsel $id 9614 } 9615 if {[info exists markedid] && $markedid eq $id} { 9616 make_idmark $id 9617 } 9618 } 9619 9620 proc mktagcan {} { 9621 global mktagtop 9622 9623 catch {destroy $mktagtop} 9624 unset mktagtop 9625 } 9626 9627 proc mktaggo {} { 9628 if {![domktag]} return 9629 mktagcan 9630 } 9631 9632 proc copyreference {} { 9633 global rowmenuid autosellen 9634 global hashlength 9635 9636 set format "%h (\"%s\", %ad)" 9637 set cmd [list git show -s --pretty=format:$format --date=short] 9638 if {$autosellen < $hashlength} { 9639 lappend cmd --abbrev=$autosellen 9640 } 9641 set reference [safe_exec [concat $cmd $rowmenuid]] 9642 9643 clipboard clear 9644 clipboard append $reference 9645 } 9646 9647 proc writecommit {} { 9648 global rowmenuid wrcomtop commitinfo wrcomcmd 9649 global hashlength 9650 9651 set top .writecommit 9652 set wrcomtop $top 9653 catch {destroy $top} 9654 ttk_toplevel $top 9655 make_transient $top . 9656 ttk::label $top.title -text [mc "Write commit to file"] 9657 grid $top.title - -pady 10 9658 ttk::label $top.id -text [mc "ID:"] 9659 ttk::entry $top.sha1 -width $hashlength 9660 $top.sha1 insert 0 $rowmenuid 9661 $top.sha1 conf -state readonly 9662 grid $top.id $top.sha1 -sticky w 9663 ttk::entry $top.head -width 60 9664 $top.head insert 0 [lindex $commitinfo($rowmenuid) 0] 9665 $top.head conf -state readonly 9666 grid x $top.head -sticky w 9667 ttk::label $top.clab -text [mc "Command:"] 9668 ttk::entry $top.cmd -width 60 -textvariable wrcomcmd 9669 grid $top.clab $top.cmd -sticky w -pady 10 9670 ttk::label $top.flab -text [mc "Output file:"] 9671 ttk::entry $top.fname -width 60 9672 $top.fname insert 0 [file normalize "commit-[string range $rowmenuid 0 6]"] 9673 grid $top.flab $top.fname -sticky w 9674 ttk::frame $top.buts 9675 ttk::button $top.buts.gen -text [mc "Write"] -command wrcomgo 9676 ttk::button $top.buts.can -text [mc "Cancel"] -command wrcomcan 9677 bind $top wrcomgo 9678 bind $top wrcomcan 9679 grid $top.buts.gen $top.buts.can 9680 grid columnconfigure $top.buts 0 -weight 1 -uniform a 9681 grid columnconfigure $top.buts 1 -weight 1 -uniform a 9682 grid $top.buts - -pady 10 -sticky ew 9683 focus $top.fname 9684 } 9685 9686 proc wrcomgo {} { 9687 global wrcomtop 9688 9689 set id [$wrcomtop.sha1 get] 9690 set cmd "echo $id | [$wrcomtop.cmd get]" 9691 set fname [$wrcomtop.fname get] 9692 if {[catch {safe_exec_redirect [list sh -c $cmd] [list >$fname &]} err]} { 9693 error_popup "[mc "Error writing commit:"] $err" $wrcomtop 9694 } 9695 catch {destroy $wrcomtop} 9696 unset wrcomtop 9697 } 9698 9699 proc wrcomcan {} { 9700 global wrcomtop 9701 9702 catch {destroy $wrcomtop} 9703 unset wrcomtop 9704 } 9705 9706 proc mkbranch {} { 9707 global rowmenuid 9708 9709 set top .branchdialog 9710 9711 set val(name) "" 9712 set val(id) $rowmenuid 9713 set val(command) [list mkbrgo $top] 9714 9715 set ui(title) [mc "Create branch"] 9716 set ui(accept) [mc "Create"] 9717 9718 branchdia $top val ui 9719 } 9720 9721 proc mvbranch {} { 9722 global headmenuid headmenuhead 9723 9724 set top .branchdialog 9725 9726 set val(name) $headmenuhead 9727 set val(id) $headmenuid 9728 set val(command) [list mvbrgo $top $headmenuhead] 9729 9730 set ui(title) [mc "Rename branch %s" $headmenuhead] 9731 set ui(accept) [mc "Rename"] 9732 9733 branchdia $top val ui 9734 } 9735 9736 proc branchdia {top valvar uivar} { 9737 global commitinfo 9738 global hashlength 9739 upvar $valvar val $uivar ui 9740 9741 catch {destroy $top} 9742 ttk_toplevel $top 9743 make_transient $top . 9744 ttk::label $top.title -text $ui(title) 9745 grid $top.title - -pady 10 9746 ttk::label $top.id -text [mc "ID:"] 9747 ttk::entry $top.sha1 -width $hashlength 9748 $top.sha1 insert 0 $val(id) 9749 $top.sha1 conf -state readonly 9750 grid $top.id $top.sha1 -sticky w 9751 ttk::entry $top.head -width 60 9752 $top.head insert 0 [lindex $commitinfo($val(id)) 0] 9753 $top.head conf -state readonly 9754 grid x $top.head -sticky ew 9755 grid columnconfigure $top 1 -weight 1 9756 ttk::label $top.nlab -text [mc "Name:"] 9757 ttk::entry $top.name -width $hashlength 9758 $top.name insert 0 $val(name) 9759 grid $top.nlab $top.name -sticky w 9760 ttk::frame $top.buts 9761 ttk::button $top.buts.go -text $ui(accept) -command $val(command) 9762 ttk::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}" 9763 bind $top $val(command) 9764 bind $top "catch {destroy $top}" 9765 grid $top.buts.go $top.buts.can 9766 grid columnconfigure $top.buts 0 -weight 1 -uniform a 9767 grid columnconfigure $top.buts 1 -weight 1 -uniform a 9768 grid $top.buts - -pady 10 -sticky ew 9769 focus $top.name 9770 } 9771 9772 proc mkbrgo {top} { 9773 global headids idheads 9774 9775 set name [$top.name get] 9776 set id [$top.sha1 get] 9777 set cmdargs {} 9778 set old_id {} 9779 if {$name eq {}} { 9780 error_popup [mc "Please specify a name for the new branch"] $top 9781 return 9782 } 9783 if {[info exists headids($name)]} { 9784 if {![confirm_popup [mc \ 9785 "Branch '%s' already exists. Overwrite?" $name] $top]} { 9786 return 9787 } 9788 set old_id $headids($name) 9789 lappend cmdargs -f 9790 } 9791 catch {destroy $top} 9792 lappend cmdargs $name $id 9793 nowbusy newbranch 9794 update 9795 if {[catch { 9796 safe_exec [concat git branch $cmdargs] 9797 } err]} { 9798 notbusy newbranch 9799 error_popup $err 9800 } else { 9801 notbusy newbranch 9802 if {$old_id ne {}} { 9803 movehead $id $name 9804 movedhead $id $name 9805 redrawtags $old_id 9806 redrawtags $id 9807 } else { 9808 set headids($name) $id 9809 lappend idheads($id) $name 9810 addedhead $id $name 9811 redrawtags $id 9812 } 9813 dispneartags 0 9814 run refill_reflist 9815 } 9816 } 9817 9818 proc mvbrgo {top prevname} { 9819 global headids idheads mainhead mainheadid 9820 9821 set name [$top.name get] 9822 set id [$top.sha1 get] 9823 set cmdargs {} 9824 if {$name eq $prevname} { 9825 catch {destroy $top} 9826 return 9827 } 9828 if {$name eq {}} { 9829 error_popup [mc "Please specify a new name for the branch"] $top 9830 return 9831 } 9832 catch {destroy $top} 9833 lappend cmdargs -m $prevname $name 9834 nowbusy renamebranch 9835 update 9836 if {[catch { 9837 safe_exec [concat git branch $cmdargs] 9838 } err]} { 9839 notbusy renamebranch 9840 error_popup $err 9841 } else { 9842 notbusy renamebranch 9843 removehead $id $prevname 9844 removedhead $id $prevname 9845 set headids($name) $id 9846 lappend idheads($id) $name 9847 addedhead $id $name 9848 if {$prevname eq $mainhead} { 9849 set mainhead $name 9850 set mainheadid $id 9851 } 9852 redrawtags $id 9853 dispneartags 0 9854 run refill_reflist 9855 } 9856 } 9857 9858 proc exec_citool {tool_args {baseid {}}} { 9859 global commitinfo env 9860 9861 set save_env [array get env GIT_AUTHOR_*] 9862 9863 if {$baseid ne {}} { 9864 if {![info exists commitinfo($baseid)]} { 9865 getcommit $baseid 9866 } 9867 set author [lindex $commitinfo($baseid) 1] 9868 set date [lindex $commitinfo($baseid) 2] 9869 if {[regexp {^\s*(\S.*\S|\S)\s*<(.*)>\s*$} \ 9870 $author author name email] 9871 && $date ne {}} { 9872 set env(GIT_AUTHOR_NAME) $name 9873 set env(GIT_AUTHOR_EMAIL) $email 9874 set env(GIT_AUTHOR_DATE) $date 9875 } 9876 } 9877 9878 safe_exec_redirect [concat git citool $tool_args] [list &] 9879 9880 array unset env GIT_AUTHOR_* 9881 array set env $save_env 9882 } 9883 9884 proc cherrypick {} { 9885 global rowmenuid curview 9886 global mainhead mainheadid 9887 global gitdir 9888 9889 set oldhead [exec git rev-parse HEAD] 9890 set dheads [descheads $rowmenuid] 9891 if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} { 9892 set ok [confirm_popup [mc "Commit %s is already\ 9893 included in branch %s -- really re-apply it?" \ 9894 [string range $rowmenuid 0 7] $mainhead]] 9895 if {!$ok} return 9896 } 9897 nowbusy cherrypick [mc "Cherry-picking"] 9898 update 9899 # Unfortunately git-cherry-pick writes stuff to stderr even when 9900 # no error occurs, and exec takes that as an indication of error... 9901 if {[catch {safe_exec [list sh -c "git cherry-pick -r $rowmenuid 2>&1"]} err]} { 9902 notbusy cherrypick 9903 if {[regexp -line \ 9904 {Entry '(.*)' (would be overwritten by merge|not uptodate)} \ 9905 $err msg fname]} { 9906 error_popup [mc "Cherry-pick failed because of local changes\ 9907 to file '%s'.\nPlease commit, reset or stash\ 9908 your changes and try again." $fname] 9909 } elseif {[regexp -line \ 9910 {^(CONFLICT \(.*\):|Automatic cherry-pick failed|error: could not apply)} \ 9911 $err]} { 9912 if {[confirm_popup [mc "Cherry-pick failed because of merge\ 9913 conflict.\nDo you wish to run git citool to\ 9914 resolve it?"]]} { 9915 # Force citool to read MERGE_MSG 9916 file delete [file join $gitdir "GITGUI_MSG"] 9917 exec_citool {} $rowmenuid 9918 } 9919 } else { 9920 error_popup $err 9921 } 9922 run updatecommits 9923 return 9924 } 9925 set newhead [exec git rev-parse HEAD] 9926 if {$newhead eq $oldhead} { 9927 notbusy cherrypick 9928 error_popup [mc "No changes committed"] 9929 return 9930 } 9931 addnewchild $newhead $oldhead 9932 if {[commitinview $oldhead $curview]} { 9933 # XXX this isn't right if we have a path limit... 9934 insertrow $newhead $oldhead $curview 9935 if {$mainhead ne {}} { 9936 movehead $newhead $mainhead 9937 movedhead $newhead $mainhead 9938 } 9939 set mainheadid $newhead 9940 redrawtags $oldhead 9941 redrawtags $newhead 9942 selbyid $newhead 9943 } 9944 notbusy cherrypick 9945 } 9946 9947 proc revert {} { 9948 global rowmenuid curview 9949 global mainhead mainheadid 9950 global gitdir 9951 9952 set oldhead [exec git rev-parse HEAD] 9953 set dheads [descheads $rowmenuid] 9954 if { $dheads eq {} || [lsearch -exact $dheads $oldhead] == -1 } { 9955 set ok [confirm_popup [mc "Commit %s is not\ 9956 included in branch %s -- really revert it?" \ 9957 [string range $rowmenuid 0 7] $mainhead]] 9958 if {!$ok} return 9959 } 9960 nowbusy revert [mc "Reverting"] 9961 update 9962 9963 if [catch {safe_exec [list git revert --no-edit $rowmenuid]} err] { 9964 notbusy revert 9965 if [regexp {files would be overwritten by merge:(\n(( |\t)+[^\n]+\n)+)}\ 9966 $err match files] { 9967 regsub {\n( |\t)+} $files "\n" files 9968 error_popup [mc "Revert failed because of local changes to\ 9969 the following files:%s Please commit, reset or stash \ 9970 your changes and try again." $files] 9971 } elseif [regexp {error: could not revert} $err] { 9972 if [confirm_popup [mc "Revert failed because of merge conflict.\n\ 9973 Do you wish to run git citool to resolve it?"]] { 9974 # Force citool to read MERGE_MSG 9975 file delete [file join $gitdir "GITGUI_MSG"] 9976 exec_citool {} $rowmenuid 9977 } 9978 } else { error_popup $err } 9979 run updatecommits 9980 return 9981 } 9982 9983 set newhead [exec git rev-parse HEAD] 9984 if { $newhead eq $oldhead } { 9985 notbusy revert 9986 error_popup [mc "No changes committed"] 9987 return 9988 } 9989 9990 addnewchild $newhead $oldhead 9991 9992 if [commitinview $oldhead $curview] { 9993 # XXX this isn't right if we have a path limit... 9994 insertrow $newhead $oldhead $curview 9995 if {$mainhead ne {}} { 9996 movehead $newhead $mainhead 9997 movedhead $newhead $mainhead 9998 } 9999 set mainheadid $newhead 10000 redrawtags $oldhead 10001 redrawtags $newhead 10002 selbyid $newhead 10003 } 10004 10005 notbusy revert 10006 } 10007 10008 proc resethead {} { 10009 global mainhead rowmenuid confirm_ok resettype 10010 10011 set confirm_ok 0 10012 set w ".confirmreset" 10013 ttk_toplevel $w 10014 make_transient $w . 10015 wm title $w [mc "Confirm reset"] 10016 ttk::label $w.m -text \ 10017 [mc "Reset branch %s to %s?" $mainhead [string range $rowmenuid 0 7]] 10018 pack $w.m -side top -fill x -padx 20 -pady 20 10019 ttk::labelframe $w.f -text [mc "Reset type:"] 10020 set resettype mixed 10021 ttk::radiobutton $w.f.soft -value soft -variable resettype \ 10022 -text [mc "Soft: Leave working tree and index untouched"] 10023 grid $w.f.soft -sticky w 10024 ttk::radiobutton $w.f.mixed -value mixed -variable resettype \ 10025 -text [mc "Mixed: Leave working tree untouched, reset index"] 10026 grid $w.f.mixed -sticky w 10027 ttk::radiobutton $w.f.hard -value hard -variable resettype \ 10028 -text [mc "Hard: Reset working tree and index\n(discard ALL local changes)"] 10029 grid $w.f.hard -sticky w 10030 pack $w.f -side top -fill x -padx 4 10031 ttk::button $w.ok -text [mc OK] -command "set confirm_ok 1; destroy $w" 10032 pack $w.ok -side left -fill x -padx 20 -pady 20 10033 ttk::button $w.cancel -text [mc Cancel] -command "destroy $w" 10034 bind $w [list destroy $w] 10035 pack $w.cancel -side right -fill x -padx 20 -pady 20 10036 bind $w "grab $w; focus $w" 10037 tkwait window $w 10038 if {!$confirm_ok} return 10039 if {[catch {set fd [safe_open_command_redirect \ 10040 [list git reset --$resettype $rowmenuid] [list 2>@1]]} err]} { 10041 error_popup $err 10042 } else { 10043 dohidelocalchanges 10044 filerun $fd [list readresetstat $fd] 10045 nowbusy reset [mc "Resetting"] 10046 selbyid $rowmenuid 10047 } 10048 } 10049 10050 proc readresetstat {fd} { 10051 global mainhead mainheadid showlocalchanges rprogcoord 10052 10053 if {[gets $fd line] >= 0} { 10054 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} { 10055 set rprogcoord [expr {1.0 * $m / $n}] 10056 adjustprogress 10057 } 10058 return 1 10059 } 10060 set rprogcoord 0 10061 adjustprogress 10062 notbusy reset 10063 if {[catch {close $fd} err]} { 10064 error_popup $err 10065 } 10066 set oldhead $mainheadid 10067 set newhead [exec git rev-parse HEAD] 10068 if {$newhead ne $oldhead} { 10069 movehead $newhead $mainhead 10070 movedhead $newhead $mainhead 10071 set mainheadid $newhead 10072 redrawtags $oldhead 10073 redrawtags $newhead 10074 } 10075 if {$showlocalchanges} { 10076 doshowlocalchanges 10077 } 10078 return 0 10079 } 10080 10081 # context menu for a head 10082 proc headmenu {x y id head} { 10083 global headmenuid headmenuhead headctxmenu mainhead headids 10084 10085 stopfinding 10086 set headmenuid $id 10087 set headmenuhead $head 10088 array set state {0 normal 1 normal 2 normal} 10089 if {[string match "remotes/*" $head]} { 10090 set localhead [string range $head [expr [string last / $head] + 1] end] 10091 if {[info exists headids($localhead)]} { 10092 set state(0) disabled 10093 } 10094 array set state {1 disabled 2 disabled} 10095 } 10096 if {$head eq $mainhead} { 10097 array set state {0 disabled 2 disabled} 10098 } 10099 foreach i {0 1 2} { 10100 $headctxmenu entryconfigure $i -state $state($i) 10101 } 10102 tk_popup $headctxmenu $x $y 10103 } 10104 10105 proc cobranch {} { 10106 global headmenuid headmenuhead headids 10107 global showlocalchanges 10108 10109 # check the tree is clean first?? 10110 set newhead $headmenuhead 10111 set command [list git checkout] 10112 if {[string match "remotes/*" $newhead]} { 10113 set remote $newhead 10114 set newhead [string range $newhead [expr [string last / $newhead] + 1] end] 10115 # The following check is redundant - the menu option should 10116 # be disabled to begin with... 10117 if {[info exists headids($newhead)]} { 10118 error_popup [mc "A local branch named %s exists already" $newhead] 10119 return 10120 } 10121 lappend command -b $newhead --track $remote 10122 } else { 10123 lappend command $newhead 10124 } 10125 nowbusy checkout [mc "Checking out"] 10126 update 10127 dohidelocalchanges 10128 if {[catch { 10129 set fd [safe_open_command_redirect $command [list 2>@1]] 10130 } err]} { 10131 notbusy checkout 10132 error_popup $err 10133 if {$showlocalchanges} { 10134 dodiffindex 10135 } 10136 } else { 10137 filerun $fd [list readcheckoutstat $fd $newhead $headmenuid] 10138 } 10139 } 10140 10141 proc readcheckoutstat {fd newhead newheadid} { 10142 global mainhead mainheadid headids idheads showlocalchanges progresscoords 10143 global viewmainheadid curview 10144 10145 if {[gets $fd line] >= 0} { 10146 if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} { 10147 set progresscoords [list 0 [expr {1.0 * $m / $n}]] 10148 adjustprogress 10149 } 10150 return 1 10151 } 10152 set progresscoords {0 0} 10153 adjustprogress 10154 notbusy checkout 10155 if {[catch {close $fd} err]} { 10156 error_popup $err 10157 return 10158 } 10159 set oldmainid $mainheadid 10160 if {! [info exists headids($newhead)]} { 10161 set headids($newhead) $newheadid 10162 lappend idheads($newheadid) $newhead 10163 addedhead $newheadid $newhead 10164 } 10165 set mainhead $newhead 10166 set mainheadid $newheadid 10167 set viewmainheadid($curview) $newheadid 10168 redrawtags $oldmainid 10169 redrawtags $newheadid 10170 selbyid $newheadid 10171 if {$showlocalchanges} { 10172 dodiffindex 10173 } 10174 } 10175 10176 proc rmbranch {} { 10177 global headmenuid headmenuhead mainhead 10178 global idheads 10179 10180 set head $headmenuhead 10181 set id $headmenuid 10182 # this check shouldn't be needed any more... 10183 if {$head eq $mainhead} { 10184 error_popup [mc "Cannot delete the currently checked-out branch"] 10185 return 10186 } 10187 set dheads [descheads $id] 10188 if {[llength $dheads] == 1 && $idheads($dheads) eq $head} { 10189 # the stuff on this branch isn't on any other branch 10190 if {![confirm_popup [mc "The commits on branch %s aren't on any other\ 10191 branch.\nReally delete branch %s?" $head $head]]} return 10192 } 10193 nowbusy rmbranch 10194 update 10195 if {[catch {safe_exec [list git branch -D $head]} err]} { 10196 notbusy rmbranch 10197 error_popup $err 10198 return 10199 } 10200 removehead $id $head 10201 removedhead $id $head 10202 redrawtags $id 10203 notbusy rmbranch 10204 dispneartags 0 10205 run refill_reflist 10206 } 10207 10208 # Display a list of tags and heads 10209 proc showrefs {} { 10210 global showrefstop bgcolor fgcolor selectbgcolor 10211 global bglist fglist reflistfilter reflist maincursor 10212 global geometry 10213 10214 set top .showrefs 10215 set showrefstop $top 10216 if {[winfo exists $top]} { 10217 raise $top 10218 refill_reflist 10219 return 10220 } 10221 ttk_toplevel $top 10222 wm title $top [mc "Tags and heads: %s" [file tail [pwd]]] 10223 if {[info exists geometry(showrefs)]} { 10224 make_transient $top . $geometry(showrefs) 10225 } else { 10226 make_transient $top . 10227 } 10228 text $top.list -background $bgcolor -foreground $fgcolor \ 10229 -selectbackground $selectbgcolor -font mainfont \ 10230 -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \ 10231 -width 60 -height 20 -cursor $maincursor \ 10232 -spacing1 1 -spacing3 1 -state disabled 10233 $top.list tag configure highlight -background $selectbgcolor 10234 if {![lsearch -exact $bglist $top.list]} { 10235 lappend bglist $top.list 10236 lappend fglist $top.list 10237 } 10238 ttk::scrollbar $top.ysb -command "$top.list yview" -orient vertical 10239 ttk::scrollbar $top.xsb -command "$top.list xview" -orient horizontal 10240 grid $top.list $top.ysb -sticky nsew 10241 grid $top.xsb x -sticky ew 10242 ttk::frame $top.f 10243 ttk::label $top.f.l -text "[mc "Filter"]: " 10244 ttk::entry $top.f.e -width 20 -textvariable reflistfilter 10245 set reflistfilter "*" 10246 trace add variable reflistfilter write reflistfilter_change 10247 pack $top.f.e -side right -fill x -expand 1 10248 pack $top.f.l -side left 10249 grid $top.f - -sticky ew -pady 2 10250 ttk::checkbutton $top.sort -text [mc "Sort refs by type"] \ 10251 -variable sortrefsbytype -command {refill_reflist} 10252 grid $top.sort - -sticky w -pady 2 10253 ttk::button $top.close -command [list destroy $top] -text [mc "Close"] 10254 bind $top [list destroy $top] 10255 grid $top.close - 10256 grid columnconfigure $top 0 -weight 1 10257 grid rowconfigure $top 0 -weight 1 10258 bind $top.list <1> {break} 10259 bind $top.list {break} 10260 bind $top.list {sel_reflist %W %x %y; break} 10261 set reflist {} 10262 refill_reflist 10263 # avoid being bound to child windows 10264 bindtags $top [linsert [bindtags $top] 1 bind$top] 10265 bind bind$top {set geometry(showrefs) [wm geometry %W]} 10266 } 10267 10268 proc sel_reflist {w x y} { 10269 global showrefstop reflist headids tagids otherrefids 10270 10271 if {![winfo exists $showrefstop]} return 10272 set l [lindex [split [$w index "@$x,$y"] "."] 0] 10273 set ref [lindex $reflist [expr {$l-1}]] 10274 set n [lindex $ref 0] 10275 switch -- [lindex $ref 1] { 10276 "H" {selbyid $headids($n)} 10277 "R" {selbyid $headids($n)} 10278 "T" {selbyid $tagids($n)} 10279 "o" {selbyid $otherrefids($n)} 10280 } 10281 $showrefstop.list tag add highlight $l.0 "$l.0 lineend" 10282 } 10283 10284 proc unsel_reflist {} { 10285 global showrefstop 10286 10287 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return 10288 $showrefstop.list tag remove highlight 0.0 end 10289 } 10290 10291 proc reflistfilter_change {n1 n2 op} { 10292 global reflistfilter 10293 10294 after cancel refill_reflist 10295 after 200 refill_reflist 10296 } 10297 10298 proc refill_reflist {} { 10299 global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype 10300 global curview upstreamofref 10301 10302 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return 10303 set localrefs {} 10304 set remoterefs {} 10305 set trackedremoterefs {} 10306 set tagrefs {} 10307 set otherrefs {} 10308 10309 foreach n [array names headids] { 10310 if {![string match "remotes/*" $n] && [string match $reflistfilter $n]} { 10311 if {[commitinview $headids($n) $curview]} { 10312 lappend localrefs [list $n H] 10313 if {[info exists upstreamofref($n)] && \ 10314 [info exists headids($upstreamofref($n))] && \ 10315 [commitinview $headids($upstreamofref($n)) $curview]} { 10316 lappend trackedremoterefs [list $upstreamofref($n) R] 10317 } 10318 } else { 10319 interestedin $headids($n) {run refill_reflist} 10320 } 10321 } 10322 } 10323 set trackedremoterefs [lsort -index 0 -unique $trackedremoterefs] 10324 set localrefs [lsort -index 0 $localrefs] 10325 10326 foreach n [array names headids] { 10327 if {[string match "remotes/*" $n] && [string match $reflistfilter $n]} { 10328 if {[commitinview $headids($n) $curview]} { 10329 if {[lsearch -exact $trackedremoterefs [list $n R]] < 0} { 10330 lappend remoterefs [list $n R] 10331 } 10332 } else { 10333 interestedin $headids($n) {run refill_reflist} 10334 } 10335 } 10336 } 10337 set remoterefs [lsort -index 0 $remoterefs] 10338 10339 foreach n [array names tagids] { 10340 if {[string match $reflistfilter $n]} { 10341 if {[commitinview $tagids($n) $curview]} { 10342 lappend tagrefs [list $n T] 10343 } else { 10344 interestedin $tagids($n) {run refill_reflist} 10345 } 10346 } 10347 } 10348 set tagrefs [lsort -index 0 $tagrefs] 10349 10350 foreach n [array names otherrefids] { 10351 if {[string match $reflistfilter $n]} { 10352 if {[commitinview $otherrefids($n) $curview]} { 10353 lappend otherrefs [list "$n" o] 10354 } else { 10355 interestedin $otherrefids($n) {run refill_reflist} 10356 } 10357 } 10358 } 10359 set otherrefs [lsort -index 0 $otherrefs] 10360 10361 set refs [concat $localrefs $trackedremoterefs $remoterefs $tagrefs $otherrefs] 10362 if {!$sortrefsbytype} { 10363 set refs [lsort -index 0 $refs] 10364 } 10365 10366 if {$refs eq $reflist} return 10367 10368 # Update the contents of $showrefstop.list according to the 10369 # differences between $reflist (old) and $refs (new) 10370 $showrefstop.list conf -state normal 10371 $showrefstop.list insert end "\n" 10372 set i 0 10373 set j 0 10374 while {$i < [llength $reflist] || $j < [llength $refs]} { 10375 if {$i < [llength $reflist]} { 10376 if {$j < [llength $refs]} { 10377 set cmp [string compare [lindex $reflist $i 0] \ 10378 [lindex $refs $j 0]] 10379 if {$cmp == 0} { 10380 set cmp [string compare [lindex $reflist $i 1] \ 10381 [lindex $refs $j 1]] 10382 } 10383 } else { 10384 set cmp -1 10385 } 10386 } else { 10387 set cmp 1 10388 } 10389 switch -- $cmp { 10390 -1 { 10391 $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0" 10392 incr i 10393 } 10394 0 { 10395 incr i 10396 incr j 10397 } 10398 1 { 10399 set l [expr {$j + 1}] 10400 $showrefstop.list image create $l.0 -align baseline \ 10401 -image reficon-[lindex $refs $j 1] -padx 2 10402 $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n" 10403 incr j 10404 } 10405 } 10406 } 10407 set reflist $refs 10408 # delete last newline 10409 $showrefstop.list delete end-2c end-1c 10410 $showrefstop.list conf -state disabled 10411 } 10412 10413 # Stuff for finding nearby tags 10414 proc getallcommits {} { 10415 global allcommits nextarc seeds allccache allcwait cachedarcs allcupdate 10416 global idheads idtags idotherrefs allparents tagobjid 10417 global gitdir 10418 10419 if {![info exists allcommits]} { 10420 set nextarc 0 10421 set allcommits 0 10422 set seeds {} 10423 set allcwait 0 10424 set cachedarcs 0 10425 set allccache [file join $gitdir "gitk.cache"] 10426 if {![catch { 10427 set f [safe_open_file $allccache r] 10428 set allcwait 1 10429 getcache $f 10430 }]} return 10431 } 10432 10433 if {$allcwait} { 10434 return 10435 } 10436 set cmd [list git rev-list --parents] 10437 set allcupdate [expr {$seeds ne {}}] 10438 if {!$allcupdate} { 10439 set ids "--all" 10440 } else { 10441 set refs [concat [array names idheads] [array names idtags] \ 10442 [array names idotherrefs]] 10443 set ids {} 10444 set tagobjs {} 10445 foreach name [array names tagobjid] { 10446 lappend tagobjs $tagobjid($name) 10447 } 10448 foreach id [lsort -unique $refs] { 10449 if {![info exists allparents($id)] && 10450 [lsearch -exact $tagobjs $id] < 0} { 10451 lappend ids $id 10452 } 10453 } 10454 if {$ids ne {}} { 10455 foreach id $seeds { 10456 lappend ids "^$id" 10457 } 10458 lappend ids "--" 10459 } 10460 } 10461 if {$ids ne {}} { 10462 if {$ids eq "--all"} { 10463 set cmd [concat $cmd "--all"] 10464 set fd [safe_open_command $cmd] 10465 } else { 10466 set cmd [concat $cmd --stdin] 10467 set fd [safe_open_command_redirect $cmd [list "<<[join $ids "\n"]"]] 10468 } 10469 fconfigure $fd -blocking 0 10470 incr allcommits 10471 nowbusy allcommits 10472 filerun $fd [list getallclines $fd] 10473 } else { 10474 dispneartags 0 10475 } 10476 } 10477 10478 # Since most commits have 1 parent and 1 child, we group strings of 10479 # such commits into "arcs" joining branch/merge points (BMPs), which 10480 # are commits that either don't have 1 parent or don't have 1 child. 10481 # 10482 # arcnos(id) - incoming arcs for BMP, arc we're on for other nodes 10483 # arcout(id) - outgoing arcs for BMP 10484 # arcids(a) - list of IDs on arc including end but not start 10485 # arcstart(a) - BMP ID at start of arc 10486 # arcend(a) - BMP ID at end of arc 10487 # growing(a) - arc a is still growing 10488 # arctags(a) - IDs out of arcids (excluding end) that have tags 10489 # archeads(a) - IDs out of arcids (excluding end) that have heads 10490 # The start of an arc is at the descendent end, so "incoming" means 10491 # coming from descendents, and "outgoing" means going towards ancestors. 10492 10493 proc getallclines {fd} { 10494 global allparents allchildren idtags idheads nextarc 10495 global arcnos arcids arctags arcout arcend arcstart archeads growing 10496 global seeds allcommits cachedarcs allcupdate 10497 10498 set nid 0 10499 while {[incr nid] <= 1000 && [gets $fd line] >= 0} { 10500 set id [lindex $line 0] 10501 if {[info exists allparents($id)]} { 10502 # seen it already 10503 continue 10504 } 10505 set cachedarcs 0 10506 set olds [lrange $line 1 end] 10507 set allparents($id) $olds 10508 if {![info exists allchildren($id)]} { 10509 set allchildren($id) {} 10510 set arcnos($id) {} 10511 lappend seeds $id 10512 } else { 10513 set a $arcnos($id) 10514 if {[llength $olds] == 1 && [llength $a] == 1} { 10515 lappend arcids($a) $id 10516 if {[info exists idtags($id)]} { 10517 lappend arctags($a) $id 10518 } 10519 if {[info exists idheads($id)]} { 10520 lappend archeads($a) $id 10521 } 10522 if {[info exists allparents($olds)]} { 10523 # seen parent already 10524 if {![info exists arcout($olds)]} { 10525 splitarc $olds 10526 } 10527 lappend arcids($a) $olds 10528 set arcend($a) $olds 10529 unset growing($a) 10530 } 10531 lappend allchildren($olds) $id 10532 lappend arcnos($olds) $a 10533 continue 10534 } 10535 } 10536 foreach a $arcnos($id) { 10537 lappend arcids($a) $id 10538 set arcend($a) $id 10539 unset growing($a) 10540 } 10541 10542 set ao {} 10543 foreach p $olds { 10544 lappend allchildren($p) $id 10545 set a [incr nextarc] 10546 set arcstart($a) $id 10547 set archeads($a) {} 10548 set arctags($a) {} 10549 set archeads($a) {} 10550 set arcids($a) {} 10551 lappend ao $a 10552 set growing($a) 1 10553 if {[info exists allparents($p)]} { 10554 # seen it already, may need to make a new branch 10555 if {![info exists arcout($p)]} { 10556 splitarc $p 10557 } 10558 lappend arcids($a) $p 10559 set arcend($a) $p 10560 unset growing($a) 10561 } 10562 lappend arcnos($p) $a 10563 } 10564 set arcout($id) $ao 10565 } 10566 if {$nid > 0} { 10567 global cached_dheads cached_dtags cached_atags 10568 unset -nocomplain cached_dheads 10569 unset -nocomplain cached_dtags 10570 unset -nocomplain cached_atags 10571 } 10572 if {![eof $fd]} { 10573 return [expr {$nid >= 1000? 2: 1}] 10574 } 10575 set cacheok 1 10576 if {[catch { 10577 fconfigure $fd -blocking 1 10578 close $fd 10579 } err]} { 10580 # got an error reading the list of commits 10581 # if we were updating, try rereading the whole thing again 10582 if {$allcupdate} { 10583 incr allcommits -1 10584 dropcache $err 10585 return 10586 } 10587 error_popup "[mc "Error reading commit topology information;\ 10588 branch and preceding/following tag information\ 10589 will be incomplete."]\n($err)" 10590 set cacheok 0 10591 } 10592 if {[incr allcommits -1] == 0} { 10593 notbusy allcommits 10594 if {$cacheok} { 10595 run savecache 10596 } 10597 } 10598 dispneartags 0 10599 return 0 10600 } 10601 10602 proc recalcarc {a} { 10603 global arctags archeads arcids idtags idheads 10604 10605 set at {} 10606 set ah {} 10607 foreach id [lrange $arcids($a) 0 end-1] { 10608 if {[info exists idtags($id)]} { 10609 lappend at $id 10610 } 10611 if {[info exists idheads($id)]} { 10612 lappend ah $id 10613 } 10614 } 10615 set arctags($a) $at 10616 set archeads($a) $ah 10617 } 10618 10619 proc splitarc {p} { 10620 global arcnos arcids nextarc arctags archeads idtags idheads 10621 global arcstart arcend arcout allparents growing 10622 10623 set a $arcnos($p) 10624 if {[llength $a] != 1} { 10625 puts "oops splitarc called but [llength $a] arcs already" 10626 return 10627 } 10628 set a [lindex $a 0] 10629 set i [lsearch -exact $arcids($a) $p] 10630 if {$i < 0} { 10631 puts "oops splitarc $p not in arc $a" 10632 return 10633 } 10634 set na [incr nextarc] 10635 if {[info exists arcend($a)]} { 10636 set arcend($na) $arcend($a) 10637 } else { 10638 set l [lindex $allparents([lindex $arcids($a) end]) 0] 10639 set j [lsearch -exact $arcnos($l) $a] 10640 set arcnos($l) [lreplace $arcnos($l) $j $j $na] 10641 } 10642 set tail [lrange $arcids($a) [expr {$i+1}] end] 10643 set arcids($a) [lrange $arcids($a) 0 $i] 10644 set arcend($a) $p 10645 set arcstart($na) $p 10646 set arcout($p) $na 10647 set arcids($na) $tail 10648 if {[info exists growing($a)]} { 10649 set growing($na) 1 10650 unset growing($a) 10651 } 10652 10653 foreach id $tail { 10654 if {[llength $arcnos($id)] == 1} { 10655 set arcnos($id) $na 10656 } else { 10657 set j [lsearch -exact $arcnos($id) $a] 10658 set arcnos($id) [lreplace $arcnos($id) $j $j $na] 10659 } 10660 } 10661 10662 # reconstruct tags and heads lists 10663 if {$arctags($a) ne {} || $archeads($a) ne {}} { 10664 recalcarc $a 10665 recalcarc $na 10666 } else { 10667 set arctags($na) {} 10668 set archeads($na) {} 10669 } 10670 } 10671 10672 # Update things for a new commit added that is a child of one 10673 # existing commit. Used when cherry-picking. 10674 proc addnewchild {id p} { 10675 global allparents allchildren idtags nextarc 10676 global arcnos arcids arctags arcout arcend arcstart archeads growing 10677 global seeds allcommits 10678 10679 if {![info exists allcommits] || ![info exists arcnos($p)]} return 10680 set allparents($id) [list $p] 10681 set allchildren($id) {} 10682 set arcnos($id) {} 10683 lappend seeds $id 10684 lappend allchildren($p) $id 10685 set a [incr nextarc] 10686 set arcstart($a) $id 10687 set archeads($a) {} 10688 set arctags($a) {} 10689 set arcids($a) [list $p] 10690 set arcend($a) $p 10691 if {![info exists arcout($p)]} { 10692 splitarc $p 10693 } 10694 lappend arcnos($p) $a 10695 set arcout($id) [list $a] 10696 } 10697 10698 # This implements a cache for the topology information. 10699 # The cache saves, for each arc, the start and end of the arc, 10700 # the ids on the arc, and the outgoing arcs from the end. 10701 proc readcache {f} { 10702 global arcnos arcids arcout arcstart arcend arctags archeads nextarc 10703 global idtags idheads allparents cachedarcs possible_seeds seeds growing 10704 global allcwait 10705 10706 set a $nextarc 10707 set lim $cachedarcs 10708 if {$lim - $a > 500} { 10709 set lim [expr {$a + 500}] 10710 } 10711 if {[catch { 10712 if {$a == $lim} { 10713 # finish reading the cache and setting up arctags, etc. 10714 set line [gets $f] 10715 if {$line ne "1"} {error "bad final version"} 10716 close $f 10717 foreach id [array names idtags] { 10718 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 && 10719 [llength $allparents($id)] == 1} { 10720 set a [lindex $arcnos($id) 0] 10721 if {$arctags($a) eq {}} { 10722 recalcarc $a 10723 } 10724 } 10725 } 10726 foreach id [array names idheads] { 10727 if {[info exists arcnos($id)] && [llength $arcnos($id)] == 1 && 10728 [llength $allparents($id)] == 1} { 10729 set a [lindex $arcnos($id) 0] 10730 if {$archeads($a) eq {}} { 10731 recalcarc $a 10732 } 10733 } 10734 } 10735 foreach id [lsort -unique $possible_seeds] { 10736 if {$arcnos($id) eq {}} { 10737 lappend seeds $id 10738 } 10739 } 10740 set allcwait 0 10741 } else { 10742 while {[incr a] <= $lim} { 10743 set line [gets $f] 10744 if {[llength $line] != 3} {error "bad line"} 10745 set s [lindex $line 0] 10746 set arcstart($a) $s 10747 lappend arcout($s) $a 10748 if {![info exists arcnos($s)]} { 10749 lappend possible_seeds $s 10750 set arcnos($s) {} 10751 } 10752 set e [lindex $line 1] 10753 if {$e eq {}} { 10754 set growing($a) 1 10755 } else { 10756 set arcend($a) $e 10757 if {![info exists arcout($e)]} { 10758 set arcout($e) {} 10759 } 10760 } 10761 set arcids($a) [lindex $line 2] 10762 foreach id $arcids($a) { 10763 lappend allparents($s) $id 10764 set s $id 10765 lappend arcnos($id) $a 10766 } 10767 if {![info exists allparents($s)]} { 10768 set allparents($s) {} 10769 } 10770 set arctags($a) {} 10771 set archeads($a) {} 10772 } 10773 set nextarc [expr {$a - 1}] 10774 } 10775 } err]} { 10776 dropcache $err 10777 return 0 10778 } 10779 if {!$allcwait} { 10780 getallcommits 10781 } 10782 return $allcwait 10783 } 10784 10785 proc getcache {f} { 10786 global nextarc cachedarcs possible_seeds 10787 10788 if {[catch { 10789 set line [gets $f] 10790 if {[llength $line] != 2 || [lindex $line 0] ne "1"} {error "bad version"} 10791 # make sure it's an integer 10792 set cachedarcs [expr {int([lindex $line 1])}] 10793 if {$cachedarcs < 0} {error "bad number of arcs"} 10794 set nextarc 0 10795 set possible_seeds {} 10796 run readcache $f 10797 } err]} { 10798 dropcache $err 10799 } 10800 return 0 10801 } 10802 10803 proc dropcache {err} { 10804 global allcwait nextarc cachedarcs seeds 10805 10806 #puts "dropping cache ($err)" 10807 foreach v {arcnos arcout arcids arcstart arcend growing \ 10808 arctags archeads allparents allchildren} { 10809 global $v 10810 unset -nocomplain $v 10811 } 10812 set allcwait 0 10813 set nextarc 0 10814 set cachedarcs 0 10815 set seeds {} 10816 getallcommits 10817 } 10818 10819 proc writecache {f} { 10820 global cachearc cachedarcs allccache 10821 global arcstart arcend arcnos arcids arcout 10822 10823 set a $cachearc 10824 set lim $cachedarcs 10825 if {$lim - $a > 1000} { 10826 set lim [expr {$a + 1000}] 10827 } 10828 if {[catch { 10829 while {[incr a] <= $lim} { 10830 if {[info exists arcend($a)]} { 10831 puts $f [list $arcstart($a) $arcend($a) $arcids($a)] 10832 } else { 10833 puts $f [list $arcstart($a) {} $arcids($a)] 10834 } 10835 } 10836 } err]} { 10837 catch {close $f} 10838 catch {file delete $allccache} 10839 #puts "writing cache failed ($err)" 10840 return 0 10841 } 10842 set cachearc [expr {$a - 1}] 10843 if {$a > $cachedarcs} { 10844 puts $f "1" 10845 close $f 10846 return 0 10847 } 10848 return 1 10849 } 10850 10851 proc savecache {} { 10852 global nextarc cachedarcs cachearc allccache 10853 10854 if {$nextarc == $cachedarcs} return 10855 set cachearc 0 10856 set cachedarcs $nextarc 10857 catch { 10858 set f [safe_open_file $allccache w] 10859 puts $f [list 1 $cachedarcs] 10860 run writecache $f 10861 } 10862 } 10863 10864 # Returns 1 if a is an ancestor of b, -1 if b is an ancestor of a, 10865 # or 0 if neither is true. 10866 proc anc_or_desc {a b} { 10867 global arcout arcstart arcend arcnos cached_isanc 10868 10869 if {$arcnos($a) eq $arcnos($b)} { 10870 # Both are on the same arc(s); either both are the same BMP, 10871 # or if one is not a BMP, the other is also not a BMP or is 10872 # the BMP at end of the arc (and it only has 1 incoming arc). 10873 # Or both can be BMPs with no incoming arcs. 10874 if {$a eq $b || $arcnos($a) eq {}} { 10875 return 0 10876 } 10877 # assert {[llength $arcnos($a)] == 1} 10878 set arc [lindex $arcnos($a) 0] 10879 set i [lsearch -exact $arcids($arc) $a] 10880 set j [lsearch -exact $arcids($arc) $b] 10881 if {$i < 0 || $i > $j} { 10882 return 1 10883 } else { 10884 return -1 10885 } 10886 } 10887 10888 if {![info exists arcout($a)]} { 10889 set arc [lindex $arcnos($a) 0] 10890 if {[info exists arcend($arc)]} { 10891 set aend $arcend($arc) 10892 } else { 10893 set aend {} 10894 } 10895 set a $arcstart($arc) 10896 } else { 10897 set aend $a 10898 } 10899 if {![info exists arcout($b)]} { 10900 set arc [lindex $arcnos($b) 0] 10901 if {[info exists arcend($arc)]} { 10902 set bend $arcend($arc) 10903 } else { 10904 set bend {} 10905 } 10906 set b $arcstart($arc) 10907 } else { 10908 set bend $b 10909 } 10910 if {$a eq $bend} { 10911 return 1 10912 } 10913 if {$b eq $aend} { 10914 return -1 10915 } 10916 if {[info exists cached_isanc($a,$bend)]} { 10917 if {$cached_isanc($a,$bend)} { 10918 return 1 10919 } 10920 } 10921 if {[info exists cached_isanc($b,$aend)]} { 10922 if {$cached_isanc($b,$aend)} { 10923 return -1 10924 } 10925 if {[info exists cached_isanc($a,$bend)]} { 10926 return 0 10927 } 10928 } 10929 10930 set todo [list $a $b] 10931 set anc($a) a 10932 set anc($b) b 10933 for {set i 0} {$i < [llength $todo]} {incr i} { 10934 set x [lindex $todo $i] 10935 if {$anc($x) eq {}} { 10936 continue 10937 } 10938 foreach arc $arcnos($x) { 10939 set xd $arcstart($arc) 10940 if {$xd eq $bend} { 10941 set cached_isanc($a,$bend) 1 10942 set cached_isanc($b,$aend) 0 10943 return 1 10944 } elseif {$xd eq $aend} { 10945 set cached_isanc($b,$aend) 1 10946 set cached_isanc($a,$bend) 0 10947 return -1 10948 } 10949 if {![info exists anc($xd)]} { 10950 set anc($xd) $anc($x) 10951 lappend todo $xd 10952 } elseif {$anc($xd) ne $anc($x)} { 10953 set anc($xd) {} 10954 } 10955 } 10956 } 10957 set cached_isanc($a,$bend) 0 10958 set cached_isanc($b,$aend) 0 10959 return 0 10960 } 10961 10962 # This identifies whether $desc has an ancestor that is 10963 # a growing tip of the graph and which is not an ancestor of $anc 10964 # and returns 0 if so and 1 if not. 10965 # If we subsequently discover a tag on such a growing tip, and that 10966 # turns out to be a descendent of $anc (which it could, since we 10967 # don't necessarily see children before parents), then $desc 10968 # isn't a good choice to display as a descendent tag of 10969 # $anc (since it is the descendent of another tag which is 10970 # a descendent of $anc). Similarly, $anc isn't a good choice to 10971 # display as a ancestor tag of $desc. 10972 # 10973 proc is_certain {desc anc} { 10974 global arcnos arcout arcstart arcend growing problems 10975 10976 set certain {} 10977 if {[llength $arcnos($anc)] == 1} { 10978 # tags on the same arc are certain 10979 if {$arcnos($desc) eq $arcnos($anc)} { 10980 return 1 10981 } 10982 if {![info exists arcout($anc)]} { 10983 # if $anc is partway along an arc, use the start of the arc instead 10984 set a [lindex $arcnos($anc) 0] 10985 set anc $arcstart($a) 10986 } 10987 } 10988 if {[llength $arcnos($desc)] > 1 || [info exists arcout($desc)]} { 10989 set x $desc 10990 } else { 10991 set a [lindex $arcnos($desc) 0] 10992 set x $arcend($a) 10993 } 10994 if {$x == $anc} { 10995 return 1 10996 } 10997 set anclist [list $x] 10998 set dl($x) 1 10999 set nnh 1 11000 set ngrowanc 0 11001 for {set i 0} {$i < [llength $anclist] && ($nnh > 0 || $ngrowanc > 0)} {incr i} { 11002 set x [lindex $anclist $i] 11003 if {$dl($x)} { 11004 incr nnh -1 11005 } 11006 set done($x) 1 11007 foreach a $arcout($x) { 11008 if {[info exists growing($a)]} { 11009 if {![info exists growanc($x)] && $dl($x)} { 11010 set growanc($x) 1 11011 incr ngrowanc 11012 } 11013 } else { 11014 set y $arcend($a) 11015 if {[info exists dl($y)]} { 11016 if {$dl($y)} { 11017 if {!$dl($x)} { 11018 set dl($y) 0 11019 if {![info exists done($y)]} { 11020 incr nnh -1 11021 } 11022 if {[info exists growanc($x)]} { 11023 incr ngrowanc -1 11024 } 11025 set xl [list $y] 11026 for {set k 0} {$k < [llength $xl]} {incr k} { 11027 set z [lindex $xl $k] 11028 foreach c $arcout($z) { 11029 if {[info exists arcend($c)]} { 11030 set v $arcend($c) 11031 if {[info exists dl($v)] && $dl($v)} { 11032 set dl($v) 0 11033 if {![info exists done($v)]} { 11034 incr nnh -1 11035 } 11036 if {[info exists growanc($v)]} { 11037 incr ngrowanc -1 11038 } 11039 lappend xl $v 11040 } 11041 } 11042 } 11043 } 11044 } 11045 } 11046 } elseif {$y eq $anc || !$dl($x)} { 11047 set dl($y) 0 11048 lappend anclist $y 11049 } else { 11050 set dl($y) 1 11051 lappend anclist $y 11052 incr nnh 11053 } 11054 } 11055 } 11056 } 11057 foreach x [array names growanc] { 11058 if {$dl($x)} { 11059 return 0 11060 } 11061 return 0 11062 } 11063 return 1 11064 } 11065 11066 proc validate_arctags {a} { 11067 global arctags idtags 11068 11069 set i -1 11070 set na $arctags($a) 11071 foreach id $arctags($a) { 11072 incr i 11073 if {![info exists idtags($id)]} { 11074 set na [lreplace $na $i $i] 11075 incr i -1 11076 } 11077 } 11078 set arctags($a) $na 11079 } 11080 11081 proc validate_archeads {a} { 11082 global archeads idheads 11083 11084 set i -1 11085 set na $archeads($a) 11086 foreach id $archeads($a) { 11087 incr i 11088 if {![info exists idheads($id)]} { 11089 set na [lreplace $na $i $i] 11090 incr i -1 11091 } 11092 } 11093 set archeads($a) $na 11094 } 11095 11096 # Return the list of IDs that have tags that are descendents of id, 11097 # ignoring IDs that are descendents of IDs already reported. 11098 proc desctags {id} { 11099 global arcnos arcstart arcids arctags idtags allparents 11100 global growing cached_dtags 11101 11102 if {![info exists allparents($id)]} { 11103 return {} 11104 } 11105 set t1 [clock clicks -milliseconds] 11106 set argid $id 11107 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} { 11108 # part-way along an arc; check that arc first 11109 set a [lindex $arcnos($id) 0] 11110 if {$arctags($a) ne {}} { 11111 validate_arctags $a 11112 set i [lsearch -exact $arcids($a) $id] 11113 set tid {} 11114 foreach t $arctags($a) { 11115 set j [lsearch -exact $arcids($a) $t] 11116 if {$j >= $i} break 11117 set tid $t 11118 } 11119 if {$tid ne {}} { 11120 return $tid 11121 } 11122 } 11123 set id $arcstart($a) 11124 if {[info exists idtags($id)]} { 11125 return $id 11126 } 11127 } 11128 if {[info exists cached_dtags($id)]} { 11129 return $cached_dtags($id) 11130 } 11131 11132 set origid $id 11133 set todo [list $id] 11134 set queued($id) 1 11135 set nc 1 11136 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} { 11137 set id [lindex $todo $i] 11138 set done($id) 1 11139 set ta [info exists hastaggedancestor($id)] 11140 if {!$ta} { 11141 incr nc -1 11142 } 11143 # ignore tags on starting node 11144 if {!$ta && $i > 0} { 11145 if {[info exists idtags($id)]} { 11146 set tagloc($id) $id 11147 set ta 1 11148 } elseif {[info exists cached_dtags($id)]} { 11149 set tagloc($id) $cached_dtags($id) 11150 set ta 1 11151 } 11152 } 11153 foreach a $arcnos($id) { 11154 set d $arcstart($a) 11155 if {!$ta && $arctags($a) ne {}} { 11156 validate_arctags $a 11157 if {$arctags($a) ne {}} { 11158 lappend tagloc($id) [lindex $arctags($a) end] 11159 } 11160 } 11161 if {$ta || $arctags($a) ne {}} { 11162 set tomark [list $d] 11163 for {set j 0} {$j < [llength $tomark]} {incr j} { 11164 set dd [lindex $tomark $j] 11165 if {![info exists hastaggedancestor($dd)]} { 11166 if {[info exists done($dd)]} { 11167 foreach b $arcnos($dd) { 11168 lappend tomark $arcstart($b) 11169 } 11170 if {[info exists tagloc($dd)]} { 11171 unset tagloc($dd) 11172 } 11173 } elseif {[info exists queued($dd)]} { 11174 incr nc -1 11175 } 11176 set hastaggedancestor($dd) 1 11177 } 11178 } 11179 } 11180 if {![info exists queued($d)]} { 11181 lappend todo $d 11182 set queued($d) 1 11183 if {![info exists hastaggedancestor($d)]} { 11184 incr nc 11185 } 11186 } 11187 } 11188 } 11189 set tags {} 11190 foreach id [array names tagloc] { 11191 if {![info exists hastaggedancestor($id)]} { 11192 foreach t $tagloc($id) { 11193 if {[lsearch -exact $tags $t] < 0} { 11194 lappend tags $t 11195 } 11196 } 11197 } 11198 } 11199 set t2 [clock clicks -milliseconds] 11200 set loopix $i 11201 11202 # remove tags that are descendents of other tags 11203 for {set i 0} {$i < [llength $tags]} {incr i} { 11204 set a [lindex $tags $i] 11205 for {set j 0} {$j < $i} {incr j} { 11206 set b [lindex $tags $j] 11207 set r [anc_or_desc $a $b] 11208 if {$r == 1} { 11209 set tags [lreplace $tags $j $j] 11210 incr j -1 11211 incr i -1 11212 } elseif {$r == -1} { 11213 set tags [lreplace $tags $i $i] 11214 incr i -1 11215 break 11216 } 11217 } 11218 } 11219 11220 if {[array names growing] ne {}} { 11221 # graph isn't finished, need to check if any tag could get 11222 # eclipsed by another tag coming later. Simply ignore any 11223 # tags that could later get eclipsed. 11224 set ctags {} 11225 foreach t $tags { 11226 if {[is_certain $t $origid]} { 11227 lappend ctags $t 11228 } 11229 } 11230 if {$tags eq $ctags} { 11231 set cached_dtags($origid) $tags 11232 } else { 11233 set tags $ctags 11234 } 11235 } else { 11236 set cached_dtags($origid) $tags 11237 } 11238 set t3 [clock clicks -milliseconds] 11239 if {0 && $t3 - $t1 >= 100} { 11240 puts "iterating descendents ($loopix/[llength $todo] nodes) took\ 11241 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left" 11242 } 11243 return $tags 11244 } 11245 11246 proc anctags {id} { 11247 global arcnos arcids arcout arcend arctags idtags allparents 11248 global growing cached_atags 11249 11250 if {![info exists allparents($id)]} { 11251 return {} 11252 } 11253 set t1 [clock clicks -milliseconds] 11254 set argid $id 11255 if {[llength $arcnos($id)] == 1 && [llength $allparents($id)] == 1} { 11256 # part-way along an arc; check that arc first 11257 set a [lindex $arcnos($id) 0] 11258 if {$arctags($a) ne {}} { 11259 validate_arctags $a 11260 set i [lsearch -exact $arcids($a) $id] 11261 foreach t $arctags($a) { 11262 set j [lsearch -exact $arcids($a) $t] 11263 if {$j > $i} { 11264 return $t 11265 } 11266 } 11267 } 11268 if {![info exists arcend($a)]} { 11269 return {} 11270 } 11271 set id $arcend($a) 11272 if {[info exists idtags($id)]} { 11273 return $id 11274 } 11275 } 11276 if {[info exists cached_atags($id)]} { 11277 return $cached_atags($id) 11278 } 11279 11280 set origid $id 11281 set todo [list $id] 11282 set queued($id) 1 11283 set taglist {} 11284 set nc 1 11285 for {set i 0} {$i < [llength $todo] && $nc > 0} {incr i} { 11286 set id [lindex $todo $i] 11287 set done($id) 1 11288 set td [info exists hastaggeddescendent($id)] 11289 if {!$td} { 11290 incr nc -1 11291 } 11292 # ignore tags on starting node 11293 if {!$td && $i > 0} { 11294 if {[info exists idtags($id)]} { 11295 set tagloc($id) $id 11296 set td 1 11297 } elseif {[info exists cached_atags($id)]} { 11298 set tagloc($id) $cached_atags($id) 11299 set td 1 11300 } 11301 } 11302 foreach a $arcout($id) { 11303 if {!$td && $arctags($a) ne {}} { 11304 validate_arctags $a 11305 if {$arctags($a) ne {}} { 11306 lappend tagloc($id) [lindex $arctags($a) 0] 11307 } 11308 } 11309 if {![info exists arcend($a)]} continue 11310 set d $arcend($a) 11311 if {$td || $arctags($a) ne {}} { 11312 set tomark [list $d] 11313 for {set j 0} {$j < [llength $tomark]} {incr j} { 11314 set dd [lindex $tomark $j] 11315 if {![info exists hastaggeddescendent($dd)]} { 11316 if {[info exists done($dd)]} { 11317 foreach b $arcout($dd) { 11318 if {[info exists arcend($b)]} { 11319 lappend tomark $arcend($b) 11320 } 11321 } 11322 if {[info exists tagloc($dd)]} { 11323 unset tagloc($dd) 11324 } 11325 } elseif {[info exists queued($dd)]} { 11326 incr nc -1 11327 } 11328 set hastaggeddescendent($dd) 1 11329 } 11330 } 11331 } 11332 if {![info exists queued($d)]} { 11333 lappend todo $d 11334 set queued($d) 1 11335 if {![info exists hastaggeddescendent($d)]} { 11336 incr nc 11337 } 11338 } 11339 } 11340 } 11341 set t2 [clock clicks -milliseconds] 11342 set loopix $i 11343 set tags {} 11344 foreach id [array names tagloc] { 11345 if {![info exists hastaggeddescendent($id)]} { 11346 foreach t $tagloc($id) { 11347 if {[lsearch -exact $tags $t] < 0} { 11348 lappend tags $t 11349 } 11350 } 11351 } 11352 } 11353 11354 # remove tags that are ancestors of other tags 11355 for {set i 0} {$i < [llength $tags]} {incr i} { 11356 set a [lindex $tags $i] 11357 for {set j 0} {$j < $i} {incr j} { 11358 set b [lindex $tags $j] 11359 set r [anc_or_desc $a $b] 11360 if {$r == -1} { 11361 set tags [lreplace $tags $j $j] 11362 incr j -1 11363 incr i -1 11364 } elseif {$r == 1} { 11365 set tags [lreplace $tags $i $i] 11366 incr i -1 11367 break 11368 } 11369 } 11370 } 11371 11372 if {[array names growing] ne {}} { 11373 # graph isn't finished, need to check if any tag could get 11374 # eclipsed by another tag coming later. Simply ignore any 11375 # tags that could later get eclipsed. 11376 set ctags {} 11377 foreach t $tags { 11378 if {[is_certain $origid $t]} { 11379 lappend ctags $t 11380 } 11381 } 11382 if {$tags eq $ctags} { 11383 set cached_atags($origid) $tags 11384 } else { 11385 set tags $ctags 11386 } 11387 } else { 11388 set cached_atags($origid) $tags 11389 } 11390 set t3 [clock clicks -milliseconds] 11391 if {0 && $t3 - $t1 >= 100} { 11392 puts "iterating ancestors ($loopix/[llength $todo] nodes) took\ 11393 [expr {$t2-$t1}]+[expr {$t3-$t2}]ms, $nc candidates left" 11394 } 11395 return $tags 11396 } 11397 11398 # Return the list of IDs that have heads that are descendents of id, 11399 # including id itself if it has a head. 11400 proc descheads {id} { 11401 global arcnos arcstart arcids archeads idheads cached_dheads 11402 global allparents arcout 11403 11404 if {![info exists allparents($id)]} { 11405 return {} 11406 } 11407 set aret {} 11408 if {![info exists arcout($id)]} { 11409 # part-way along an arc; check it first 11410 set a [lindex $arcnos($id) 0] 11411 if {$archeads($a) ne {}} { 11412 validate_archeads $a 11413 set i [lsearch -exact $arcids($a) $id] 11414 foreach t $archeads($a) { 11415 set j [lsearch -exact $arcids($a) $t] 11416 if {$j > $i} break 11417 lappend aret $t 11418 } 11419 } 11420 set id $arcstart($a) 11421 } 11422 set origid $id 11423 set todo [list $id] 11424 set seen($id) 1 11425 set ret {} 11426 for {set i 0} {$i < [llength $todo]} {incr i} { 11427 set id [lindex $todo $i] 11428 if {[info exists cached_dheads($id)]} { 11429 set ret [concat $ret $cached_dheads($id)] 11430 } else { 11431 if {[info exists idheads($id)]} { 11432 lappend ret $id 11433 } 11434 foreach a $arcnos($id) { 11435 if {$archeads($a) ne {}} { 11436 validate_archeads $a 11437 if {$archeads($a) ne {}} { 11438 set ret [concat $ret $archeads($a)] 11439 } 11440 } 11441 set d $arcstart($a) 11442 if {![info exists seen($d)]} { 11443 lappend todo $d 11444 set seen($d) 1 11445 } 11446 } 11447 } 11448 } 11449 set ret [lsort -unique $ret] 11450 set cached_dheads($origid) $ret 11451 return [concat $ret $aret] 11452 } 11453 11454 proc addedtag {id} { 11455 global arcnos arcout cached_dtags cached_atags 11456 11457 if {![info exists arcnos($id)]} return 11458 if {![info exists arcout($id)]} { 11459 recalcarc [lindex $arcnos($id) 0] 11460 } 11461 unset -nocomplain cached_dtags 11462 unset -nocomplain cached_atags 11463 } 11464 11465 proc addedhead {hid head} { 11466 global arcnos arcout cached_dheads 11467 11468 if {![info exists arcnos($hid)]} return 11469 if {![info exists arcout($hid)]} { 11470 recalcarc [lindex $arcnos($hid) 0] 11471 } 11472 unset -nocomplain cached_dheads 11473 } 11474 11475 proc removedhead {hid head} { 11476 global cached_dheads 11477 11478 unset -nocomplain cached_dheads 11479 } 11480 11481 proc movedhead {hid head} { 11482 global arcnos arcout cached_dheads 11483 11484 if {![info exists arcnos($hid)]} return 11485 if {![info exists arcout($hid)]} { 11486 recalcarc [lindex $arcnos($hid) 0] 11487 } 11488 unset -nocomplain cached_dheads 11489 } 11490 11491 proc changedrefs {} { 11492 global cached_dheads cached_dtags cached_atags cached_tagcontent 11493 global arctags archeads arcnos arcout idheads idtags 11494 11495 foreach id [concat [array names idheads] [array names idtags]] { 11496 if {[info exists arcnos($id)] && ![info exists arcout($id)]} { 11497 set a [lindex $arcnos($id) 0] 11498 if {![info exists donearc($a)]} { 11499 recalcarc $a 11500 set donearc($a) 1 11501 } 11502 } 11503 } 11504 unset -nocomplain cached_tagcontent 11505 unset -nocomplain cached_dtags 11506 unset -nocomplain cached_atags 11507 unset -nocomplain cached_dheads 11508 } 11509 11510 proc rereadrefs {} { 11511 global idtags idheads idotherrefs mainheadid 11512 11513 set refids [concat [array names idtags] \ 11514 [array names idheads] [array names idotherrefs]] 11515 foreach id $refids { 11516 if {![info exists ref($id)]} { 11517 set ref($id) [listrefs $id] 11518 } 11519 } 11520 set oldmainhead $mainheadid 11521 readrefs 11522 changedrefs 11523 set refids [lsort -unique [concat $refids [array names idtags] \ 11524 [array names idheads] [array names idotherrefs]]] 11525 foreach id $refids { 11526 set v [listrefs $id] 11527 if {![info exists ref($id)] || $ref($id) != $v} { 11528 redrawtags $id 11529 } 11530 } 11531 if {$oldmainhead ne $mainheadid} { 11532 redrawtags $oldmainhead 11533 redrawtags $mainheadid 11534 } 11535 run refill_reflist 11536 } 11537 11538 proc listrefs {id} { 11539 global idtags idheads idotherrefs 11540 11541 set x {} 11542 if {[info exists idtags($id)]} { 11543 set x $idtags($id) 11544 } 11545 set y {} 11546 if {[info exists idheads($id)]} { 11547 set y $idheads($id) 11548 } 11549 set z {} 11550 if {[info exists idotherrefs($id)]} { 11551 set z $idotherrefs($id) 11552 } 11553 return [list $x $y $z] 11554 } 11555 11556 proc add_tag_ctext {tag} { 11557 global ctext cached_tagcontent tagids 11558 11559 if {![info exists cached_tagcontent($tag)]} { 11560 catch { 11561 set cached_tagcontent($tag) [safe_exec [list git cat-file -p $tag]] 11562 } 11563 } 11564 $ctext insert end "[mc "Tag"]: $tag\n" bold 11565 if {[info exists cached_tagcontent($tag)]} { 11566 set text $cached_tagcontent($tag) 11567 } else { 11568 set text "[mc "Id"]: $tagids($tag)" 11569 } 11570 appendwithlinks $text {} 11571 } 11572 11573 proc showtag {tag isnew} { 11574 global ctext cached_tagcontent tagids linknum tagobjid 11575 11576 if {$isnew} { 11577 addtohistory [list showtag $tag 0] savectextpos 11578 } 11579 $ctext conf -state normal 11580 clear_ctext 11581 settabs 0 11582 set linknum 0 11583 add_tag_ctext $tag 11584 maybe_scroll_ctext 1 11585 $ctext conf -state disabled 11586 init_flist {} 11587 } 11588 11589 proc showtags {id isnew} { 11590 global idtags ctext linknum 11591 11592 if {$isnew} { 11593 addtohistory [list showtags $id 0] savectextpos 11594 } 11595 $ctext conf -state normal 11596 clear_ctext 11597 settabs 0 11598 set linknum 0 11599 set sep {} 11600 foreach tag $idtags($id) { 11601 $ctext insert end $sep 11602 add_tag_ctext $tag 11603 set sep "\n\n" 11604 } 11605 maybe_scroll_ctext 1 11606 $ctext conf -state disabled 11607 init_flist {} 11608 } 11609 11610 proc doquit {} { 11611 global stopped 11612 global gitktmpdir 11613 11614 set stopped 100 11615 savestuff . 11616 destroy . 11617 11618 if {[info exists gitktmpdir]} { 11619 catch {file delete -force $gitktmpdir} 11620 } 11621 } 11622 11623 proc mkfontdisp {font top which} { 11624 global fontattr fontpref $font 11625 11626 set fontpref($font) [set $font] 11627 ttk::button $top.${font}but -text $which \ 11628 -command [list choosefont $font $which] 11629 ttk::label $top.$font -font $font \ 11630 -text $fontattr($font,family) 11631 grid x $top.${font}but $top.$font -sticky w 11632 grid configure $top.$font -sticky ew 11633 } 11634 11635 proc centertext {w} { 11636 $w coords text [expr {[winfo width $w] / 2}] [expr {[winfo height $w] / 2}] 11637 } 11638 11639 proc fontok {} { 11640 global fontparam fontpref prefstop 11641 11642 set f $fontparam(font) 11643 set fontpref($f) [list $fontparam(family) $fontparam(size)] 11644 if {$fontparam(weight) eq "bold"} { 11645 lappend fontpref($f) "bold" 11646 } 11647 if {$fontparam(slant) eq "italic"} { 11648 lappend fontpref($f) "italic" 11649 } 11650 set w $prefstop.notebook.fonts.$f 11651 $w conf -text $fontparam(family) -font $fontpref($f) 11652 11653 fontcan 11654 } 11655 11656 proc fontcan {} { 11657 global fonttop fontparam 11658 11659 if {[info exists fonttop]} { 11660 catch {destroy $fonttop} 11661 catch {font delete sample} 11662 unset fonttop 11663 unset fontparam 11664 } 11665 } 11666 11667 proc choosefont {font which} { 11668 tk fontchooser configure -title $which -font $font \ 11669 -command [list on_choosefont $font $which] 11670 tk fontchooser show 11671 } 11672 proc on_choosefont {font which newfont} { 11673 global fontparam 11674 array set f [font actual $newfont] 11675 set fontparam(which) $which 11676 set fontparam(font) $font 11677 set fontparam(family) $f(-family) 11678 set fontparam(size) $f(-size) 11679 set fontparam(weight) $f(-weight) 11680 set fontparam(slant) $f(-slant) 11681 fontok 11682 } 11683 11684 proc selfontfam {} { 11685 global fonttop fontparam 11686 11687 set i [$fonttop.f.fam curselection] 11688 if {$i ne {}} { 11689 set fontparam(family) [$fonttop.f.fam get $i] 11690 } 11691 } 11692 11693 proc chg_fontparam {v sub op} { 11694 global fontparam 11695 11696 font config sample -$sub $fontparam($sub) 11697 } 11698 11699 # Create a property sheet tab page 11700 proc create_prefs_page {w} { 11701 ttk::frame $w 11702 } 11703 11704 proc prefspage_general {notebook} { 11705 global {*}$::config_variables 11706 global hashlength 11707 11708 set page [create_prefs_page $notebook.general] 11709 11710 ttk::label $page.ldisp -text [mc "Commit list display options"] -font mainfontbold 11711 grid $page.ldisp - -sticky w -pady 10 11712 11713 ttk::label $page.spacer -text " " 11714 ttk::label $page.maxwidthl -text [mc "Maximum graph width (lines)"] 11715 ttk::spinbox $page.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth 11716 grid $page.spacer $page.maxwidthl $page.maxwidth -sticky w 11717 #xgettext:no-tcl-format 11718 ttk::label $page.maxpctl -text [mc "Maximum graph width (% of pane)"] 11719 ttk::spinbox $page.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct 11720 grid x $page.maxpctl $page.maxpct -sticky w 11721 11722 ttk::checkbutton $page.showlocal -text [mc "Show local changes"] \ 11723 -variable showlocalchanges 11724 grid x $page.showlocal -sticky w 11725 11726 ttk::checkbutton $page.hideremotes -text [mc "Hide remote refs"] \ 11727 -variable hideremotes 11728 grid x $page.hideremotes -sticky w 11729 11730 ttk::entry $page.refstohide -textvariable refstohide 11731 ttk::label $page.refstohidel -text [mc "Refs to hide (space-separated globs)"] 11732 grid x $page.refstohidel $page.refstohide -sticky ew 11733 grid configure $page.refstohide -padx {0 5} 11734 11735 ttk::checkbutton $page.autocopy -text [mc "Copy commit ID to clipboard"] \ 11736 -variable autocopy 11737 grid x $page.autocopy -sticky w 11738 11739 if {[haveselectionclipboard]} { 11740 ttk::checkbutton $page.autoselect -text [mc "Copy commit ID to X11 selection"] \ 11741 -variable autoselect 11742 grid x $page.autoselect -sticky w 11743 } 11744 11745 ttk::spinbox $page.autosellen -from 1 -to $hashlength -width 4 -textvariable autosellen 11746 ttk::label $page.autosellenl -text [mc "Length of commit ID to copy"] 11747 grid x $page.autosellenl $page.autosellen -sticky w 11748 11749 ttk::label $page.kscroll1 -text [mc "Wheel scrolling multiplier"] 11750 ttk::spinbox $page.kscroll -from 1 -to 20 -width 4 -textvariable kscroll 11751 grid x $page.kscroll1 $page.kscroll -sticky w 11752 11753 ttk::label $page.ddisp -text [mc "Diff display options"] -font mainfontbold 11754 grid $page.ddisp - -sticky w -pady 10 11755 11756 ttk::label $page.tabstopl -text [mc "Tab spacing"] 11757 ttk::spinbox $page.tabstop -from 1 -to 20 -width 4 -textvariable tabstop 11758 grid x $page.tabstopl $page.tabstop -sticky w 11759 11760 ttk::label $page.wrapcommentl -text [mc "Wrap comment text"] 11761 makedroplist $page.wrapcomment wrapcomment none char word 11762 grid x $page.wrapcommentl $page.wrapcomment -sticky w 11763 11764 ttk::label $page.wrapdefaultl -text [mc "Wrap other text"] 11765 makedroplist $page.wrapdefault wrapdefault none char word 11766 grid x $page.wrapdefaultl $page.wrapdefault -sticky w 11767 11768 ttk::checkbutton $page.ntag -text [mc "Display nearby tags/heads"] \ 11769 -variable showneartags 11770 grid x $page.ntag -sticky w 11771 11772 ttk::label $page.maxrefsl -text [mc "Maximum # tags/heads to show"] 11773 ttk::spinbox $page.maxrefs -from 1 -to 1000 -width 4 -textvariable maxrefs 11774 grid x $page.maxrefsl $page.maxrefs -sticky w 11775 11776 ttk::checkbutton $page.ldiff -text [mc "Limit diffs to listed paths"] \ 11777 -variable limitdiffs 11778 grid x $page.ldiff -sticky w 11779 11780 ttk::checkbutton $page.lattr -text [mc "Support per-file encodings"] \ 11781 -variable perfile_attrs 11782 grid x $page.lattr -sticky w 11783 11784 ttk::entry $page.extdifft -textvariable extdifftool 11785 ttk::frame $page.extdifff 11786 ttk::label $page.extdifff.l -text [mc "External diff tool" ] 11787 ttk::button $page.extdifff.b -text [mc "Choose..."] -command choose_extdiff 11788 pack $page.extdifff.l -side left 11789 pack $page.extdifff.b -side right -padx {0 5} 11790 grid x $page.extdifff $page.extdifft -sticky ew 11791 grid configure $page.extdifft -padx {0 5} 11792 11793 ttk::entry $page.webbrowser -textvariable web_browser 11794 ttk::label $page.webbrowserl -text [mc "Web browser" ] 11795 grid x $page.webbrowserl $page.webbrowser -sticky ew 11796 grid configure $page.webbrowser -padx {0 5} 11797 11798 grid columnconfigure $page 2 -weight 1 11799 11800 return $page 11801 } 11802 11803 proc prefspage_colors {notebook} { 11804 global themeloader 11805 11806 set page [create_prefs_page $notebook.colors] 11807 11808 ttk::label $page.themesel -font mainfontbold \ 11809 -text [mc "Themes - change requires restart"] 11810 grid $page.themesel - -sticky w -pady 10 11811 11812 ttk::label $page.themelabel -text [mc "Theme to use after restart"] 11813 makedroplist $page.theme theme {*}[lsort [ttk::style theme names]] 11814 grid x $page.themelabel $page.theme -sticky w 11815 11816 ttk::entry $page.tloadvar -textvariable themeloader 11817 ttk::frame $page.tloadframe 11818 ttk::label $page.tloadframe.l -text [mc "Theme definition file"] 11819 ttk::button $page.tloadframe.b -text [mc "Choose..."] \ 11820 -command [list choose_themeloader $page] 11821 pack $page.tloadframe.l -side left 11822 pack $page.tloadframe.b -side right -padx {0 5} 11823 pack configure $page.tloadframe.l -padx 0 11824 grid x $page.tloadframe $page.tloadvar -sticky ew 11825 grid configure $page.tloadvar -padx {0 5} 11826 11827 ttk::label $page.themelabel2 -text \ 11828 [mc "The theme definition file may affect all themes."] 11829 ttk::button $page.themebut2 -text [mc "Apply theme"] \ 11830 -command [list updatetheme $page] 11831 grid x $page.themebut2 $page.themelabel2 -sticky w 11832 11833 ttk::label $page.cdisp -text [mc "Colors: press to choose"] -font mainfontbold 11834 grid $page.cdisp - -sticky w -pady 10 11835 11836 set coloruielems [list \ 11837 bg bgcolor {} \ 11838 [mc "Background"] \ 11839 [mc "choose background color"] \ 11840 fg fgcolor {} \ 11841 [mc "Main text"] \ 11842 [mc "choose main text color"] \ 11843 selbg selectbgcolor {} \ 11844 [mc "Selected text background"] \ 11845 [mc "choose background color of selected text"] \ 11846 linkfg linkfgcolor {} \ 11847 [mc "Link text"] \ 11848 [mc "choose color of link text"] \ 11849 diffold diffcolors 0 \ 11850 [mc "Old line text"] \ 11851 [mc "choose text color of old lines"] \ 11852 diffoldbg diffbgcolors 0 \ 11853 [mc "Old line background"] \ 11854 [mc "choose background color of old lines"] \ 11855 diffnew diffcolors 1 \ 11856 [mc "New line text"] \ 11857 [mc "choose text color of new lines"] \ 11858 diffnewbg diffbgcolors 1 \ 11859 [mc "New line background"] \ 11860 [mc "choose background color of new lines"] \ 11861 hunksep diffcolors 2 \ 11862 [mc "Hunk header text"] \ 11863 [mc "choose text color of hunk headers"] \ 11864 markbg markbgcolor {} \ 11865 [mc "Marked line background"] \ 11866 [mc "choose background color of marked lines"] \ 11867 ] 11868 11869 foreach {uielem colorvar idx label title} $coloruielems { 11870 ttk::label $page.$uielem -text $label 11871 button $page.${uielem}btn -padx 40 -pady 0 -borderwidth 2 \ 11872 -command [list choosecolor $colorvar $idx $page $title] 11873 grid x $page.$uielem $page.${uielem}btn -sticky w -pady 1 11874 } 11875 11876 grid columnconfigure $page 2 -weight 1 11877 prefspage_set_colorswatches $page 11878 11879 return $page 11880 } 11881 11882 proc prefspage_set_colorswatches {page} { 11883 global bgcolor fgcolor diffcolors selectbgcolor markbgcolor 11884 global diffbgcolors linkfgcolor 11885 11886 set coloruielems [list \ 11887 bg $bgcolor \ 11888 fg $fgcolor \ 11889 diffold [lindex $diffcolors 0] \ 11890 diffoldbg [lindex $diffbgcolors 0] \ 11891 diffnew [lindex $diffcolors 1] \ 11892 diffnewbg [lindex $diffbgcolors 1] \ 11893 hunksep [lindex $diffcolors 2] \ 11894 markbg $markbgcolor \ 11895 selbg $selectbgcolor \ 11896 linkfg $linkfgcolor \ 11897 ] 11898 foreach {uielem color} $coloruielems { 11899 $page.${uielem}btn configure -background $color -activebackground $color 11900 } 11901 } 11902 11903 proc prefspage_fonts {notebook} { 11904 set page [create_prefs_page $notebook.fonts] 11905 ttk::label $page.cfont -text [mc "Fonts: press to choose"] -font mainfontbold 11906 grid $page.cfont - -sticky w -pady 10 11907 mkfontdisp mainfont $page [mc "Main font"] 11908 mkfontdisp textfont $page [mc "Diff display font"] 11909 mkfontdisp uifont $page [mc "User interface font"] 11910 grid columnconfigure $page 2 -weight 1 11911 return $page 11912 } 11913 11914 proc doprefs {} { 11915 global oldprefs prefstop 11916 global {*}$::config_variables 11917 11918 set top .gitkprefs 11919 set prefstop $top 11920 if {[winfo exists $top]} { 11921 raise $top 11922 return 11923 } 11924 foreach v $::config_variables { 11925 set oldprefs($v) [set $v] 11926 } 11927 ttk_toplevel $top 11928 wm title $top [mc "Gitk preferences"] 11929 make_transient $top . 11930 11931 set notebook [ttk::notebook $top.notebook] 11932 11933 lappend pages [prefspage_general $notebook] [mc "General"] 11934 lappend pages [prefspage_colors $notebook] [mc "Colors"] 11935 lappend pages [prefspage_fonts $notebook] [mc "Fonts"] 11936 set col 0 11937 foreach {page title} $pages { 11938 $notebook add $page -text $title 11939 } 11940 11941 grid columnconfigure $notebook 0 -weight 1 11942 grid rowconfigure $notebook 1 -weight 1 11943 raise [lindex $pages 0] 11944 11945 grid $notebook -sticky news -padx 3 -pady 3 11946 grid rowconfigure $top 0 -weight 1 11947 grid columnconfigure $top 0 -weight 1 11948 11949 ttk::frame $top.buts 11950 ttk::button $top.buts.ok -text [mc "OK"] -command prefsok -default active 11951 ttk::button $top.buts.can -text [mc "Cancel"] -command prefscan -default normal 11952 bind $top prefsok 11953 bind $top prefscan 11954 grid $top.buts.ok $top.buts.can -padx 20 11955 grid $top.buts -sticky w -pady 10 11956 bind $top [list focus $top.buts.ok] 11957 11958 # let geometry manager determine run, set minimum size 11959 update idletasks 11960 wm minsize $top [winfo reqwidth $top] [winfo reqheight $top] 11961 } 11962 11963 proc choose_extdiff {} { 11964 global extdifftool 11965 11966 set prog [tk_getOpenFile -title [mc "External diff tool"] -multiple false] 11967 if {$prog ne {}} { 11968 set extdifftool $prog 11969 } 11970 } 11971 11972 proc run_themeloader {f} { 11973 if {![info exists ::_themefiles_seen]} { 11974 set ::_themefiles_seen [dict create] 11975 } 11976 11977 set fn [file normalize $f] 11978 if {![dict exists $::_themefiles_seen $fn]} { 11979 if {[catch {source $fn} err]} { 11980 error_popup "could not interpret: $fn\n$err" 11981 dict set ::_themefiles_seen $fn 0 11982 } else { 11983 dict set ::_themefiles_seen $fn 1 11984 } 11985 } 11986 return [dict get $::_themefiles_seen $fn] 11987 } 11988 11989 proc updatetheme {prefspage {dotheme 1}} { 11990 global theme 11991 global themeloader 11992 if {$themeloader ne {}} { 11993 if {![run_themeloader $themeloader]} { 11994 set themeloader {} 11995 return 11996 } else { 11997 $prefspage.theme configure -values \ 11998 [lsort [ttk::style theme names]] 11999 } 12000 } 12001 if {$dotheme} { 12002 ttk::style theme use $theme 12003 set_gui_colors 12004 prefspage_set_colorswatches $prefspage 12005 } 12006 } 12007 12008 proc choose_themeloader {prefspage} { 12009 global themeloader 12010 set tfile [tk_getOpenFile -title [mc "Gitk: select theme definition"] -multiple false] 12011 if {$tfile ne {}} { 12012 set themeloader $tfile 12013 updatetheme $prefspage 0 12014 } 12015 } 12016 12017 proc choosecolor {v vi prefspage title} { 12018 global $v 12019 12020 set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \ 12021 -title "Gitk: $title"] 12022 if {$c eq {}} return 12023 lset $v $vi $c 12024 set_gui_colors 12025 prefspage_set_colorswatches $prefspage 12026 } 12027 12028 proc setselbg {c} { 12029 global bglist cflist 12030 foreach w $bglist { 12031 if {[winfo exists $w]} { 12032 $w configure -selectbackground $c 12033 } 12034 } 12035 $cflist tag configure highlight \ 12036 -background [$cflist cget -selectbackground] 12037 allcanvs itemconf secsel -fill $c 12038 } 12039 12040 proc setbg {c} { 12041 global bglist 12042 12043 foreach w $bglist { 12044 if {[winfo exists $w]} { 12045 $w conf -background $c 12046 } 12047 } 12048 } 12049 12050 proc setfg {c} { 12051 global fglist canv 12052 12053 foreach w $fglist { 12054 if {[winfo exists $w]} { 12055 $w conf -foreground $c 12056 } 12057 } 12058 allcanvs itemconf text -fill $c 12059 $canv itemconf circle -outline $c 12060 $canv itemconf markid -outline $c 12061 } 12062 12063 proc set_gui_colors {} { 12064 global bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor 12065 global diffbgcolors 12066 12067 setbg $bgcolor 12068 setfg $fgcolor 12069 $ctext tag conf d0 -foreground [lindex $diffcolors 0] 12070 $ctext tag conf d0 -background [lindex $diffbgcolors 0] 12071 $ctext tag conf dresult -foreground [lindex $diffcolors 1] 12072 $ctext tag conf dresult -background [lindex $diffbgcolors 1] 12073 $ctext tag conf hunksep -foreground [lindex $diffcolors 2] 12074 $ctext tag conf omark -background $markbgcolor 12075 setselbg $selectbgcolor 12076 } 12077 12078 proc prefscan {} { 12079 global oldprefs prefstop 12080 global {*}$::config_variables 12081 12082 foreach v $::config_variables { 12083 set $v $oldprefs($v) 12084 } 12085 catch {destroy $prefstop} 12086 unset prefstop 12087 fontcan 12088 setttkstyle 12089 set_gui_colors 12090 } 12091 12092 proc prefsok {} { 12093 global oldprefs prefstop fontpref treediffs 12094 global {*}$::config_variables 12095 global ctext 12096 12097 catch {destroy $prefstop} 12098 unset prefstop 12099 fontcan 12100 set fontchanged 0 12101 if {$mainfont ne $fontpref(mainfont)} { 12102 set mainfont $fontpref(mainfont) 12103 parsefont mainfont $mainfont 12104 eval font configure mainfont [fontflags mainfont] 12105 eval font configure mainfontbold [fontflags mainfont 1] 12106 setcoords 12107 set fontchanged 1 12108 } 12109 if {$textfont ne $fontpref(textfont)} { 12110 set textfont $fontpref(textfont) 12111 parsefont textfont $textfont 12112 eval font configure textfont [fontflags textfont] 12113 eval font configure textfontbold [fontflags textfont 1] 12114 } 12115 if {$uifont ne $fontpref(uifont)} { 12116 set uifont $fontpref(uifont) 12117 parsefont uifont $uifont 12118 eval font configure uifont [fontflags uifont] 12119 } 12120 settabs 12121 if {$showlocalchanges != $oldprefs(showlocalchanges)} { 12122 if {$showlocalchanges} { 12123 doshowlocalchanges 12124 } else { 12125 dohidelocalchanges 12126 } 12127 } 12128 if {$limitdiffs != $oldprefs(limitdiffs) || 12129 ($perfile_attrs && !$oldprefs(perfile_attrs))} { 12130 # treediffs elements are limited by path; 12131 # won't have encodings cached if perfile_attrs was just turned on 12132 unset -nocomplain treediffs 12133 } 12134 if {$fontchanged || $maxwidth != $oldprefs(maxwidth) 12135 || $maxgraphpct != $oldprefs(maxgraphpct)} { 12136 redisplay 12137 } elseif {$showneartags != $oldprefs(showneartags) || 12138 $limitdiffs != $oldprefs(limitdiffs)} { 12139 reselectline 12140 } 12141 if {$hideremotes != $oldprefs(hideremotes) || $refstohide != $oldprefs(refstohide)} { 12142 rereadrefs 12143 } 12144 if {$wrapcomment != $oldprefs(wrapcomment)} { 12145 $ctext tag conf comment -wrap $wrapcomment 12146 } 12147 if {$wrapdefault != $oldprefs(wrapdefault)} { 12148 $ctext configure -wrap $wrapdefault 12149 } 12150 } 12151 12152 proc formatdate {d} { 12153 global datetimeformat 12154 if {$d ne {}} { 12155 # If $datetimeformat includes a timezone, display in the 12156 # timezone of the argument. Otherwise, display in local time. 12157 if {[string match {*%[zZ]*} $datetimeformat]} { 12158 if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} { 12159 # Tcl < 8.5 does not support -timezone. Emulate it by 12160 # setting TZ (e.g. TZ=<-0430>+04:30). 12161 global env 12162 if {[info exists env(TZ)]} { 12163 set savedTZ $env(TZ) 12164 } 12165 set zone [lindex $d 1] 12166 set sign [string map {+ - - +} [string index $zone 0]] 12167 set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4] 12168 set d [clock format [lindex $d 0] -format $datetimeformat] 12169 if {[info exists savedTZ]} { 12170 set env(TZ) $savedTZ 12171 } else { 12172 unset env(TZ) 12173 } 12174 } 12175 } else { 12176 set d [clock format [lindex $d 0] -format $datetimeformat] 12177 } 12178 } 12179 return $d 12180 } 12181 12182 # This list of encoding names and aliases is distilled from 12183 # https://www.iana.org/assignments/character-sets. 12184 # Not all of them are supported by Tcl. 12185 set encoding_aliases { 12186 { ANSI_X3.4-1968 iso-ir-6 ANSI_X3.4-1986 ISO_646.irv:1991 ASCII 12187 ISO646-US US-ASCII us IBM367 cp367 csASCII } 12188 { ISO-10646-UTF-1 csISO10646UTF1 } 12189 { ISO_646.basic:1983 ref csISO646basic1983 } 12190 { INVARIANT csINVARIANT } 12191 { ISO_646.irv:1983 iso-ir-2 irv csISO2IntlRefVersion } 12192 { BS_4730 iso-ir-4 ISO646-GB gb uk csISO4UnitedKingdom } 12193 { NATS-SEFI iso-ir-8-1 csNATSSEFI } 12194 { NATS-SEFI-ADD iso-ir-8-2 csNATSSEFIADD } 12195 { NATS-DANO iso-ir-9-1 csNATSDANO } 12196 { NATS-DANO-ADD iso-ir-9-2 csNATSDANOADD } 12197 { SEN_850200_B iso-ir-10 FI ISO646-FI ISO646-SE se csISO10Swedish } 12198 { SEN_850200_C iso-ir-11 ISO646-SE2 se2 csISO11SwedishForNames } 12199 { KS_C_5601-1987 iso-ir-149 KS_C_5601-1989 KSC_5601 korean csKSC56011987 } 12200 { ISO-2022-KR csISO2022KR } 12201 { EUC-KR csEUCKR } 12202 { ISO-2022-JP csISO2022JP } 12203 { ISO-2022-JP-2 csISO2022JP2 } 12204 { JIS_C6220-1969-jp JIS_C6220-1969 iso-ir-13 katakana x0201-7 12205 csISO13JISC6220jp } 12206 { JIS_C6220-1969-ro iso-ir-14 jp ISO646-JP csISO14JISC6220ro } 12207 { IT iso-ir-15 ISO646-IT csISO15Italian } 12208 { PT iso-ir-16 ISO646-PT csISO16Portuguese } 12209 { ES iso-ir-17 ISO646-ES csISO17Spanish } 12210 { greek7-old iso-ir-18 csISO18Greek7Old } 12211 { latin-greek iso-ir-19 csISO19LatinGreek } 12212 { DIN_66003 iso-ir-21 de ISO646-DE csISO21German } 12213 { NF_Z_62-010_(1973) iso-ir-25 ISO646-FR1 csISO25French } 12214 { Latin-greek-1 iso-ir-27 csISO27LatinGreek1 } 12215 { ISO_5427 iso-ir-37 csISO5427Cyrillic } 12216 { JIS_C6226-1978 iso-ir-42 csISO42JISC62261978 } 12217 { BS_viewdata iso-ir-47 csISO47BSViewdata } 12218 { INIS iso-ir-49 csISO49INIS } 12219 { INIS-8 iso-ir-50 csISO50INIS8 } 12220 { INIS-cyrillic iso-ir-51 csISO51INISCyrillic } 12221 { ISO_5427:1981 iso-ir-54 ISO5427Cyrillic1981 } 12222 { ISO_5428:1980 iso-ir-55 csISO5428Greek } 12223 { GB_1988-80 iso-ir-57 cn ISO646-CN csISO57GB1988 } 12224 { GB_2312-80 iso-ir-58 chinese csISO58GB231280 } 12225 { NS_4551-1 iso-ir-60 ISO646-NO no csISO60DanishNorwegian 12226 csISO60Norwegian1 } 12227 { NS_4551-2 ISO646-NO2 iso-ir-61 no2 csISO61Norwegian2 } 12228 { NF_Z_62-010 iso-ir-69 ISO646-FR fr csISO69French } 12229 { videotex-suppl iso-ir-70 csISO70VideotexSupp1 } 12230 { PT2 iso-ir-84 ISO646-PT2 csISO84Portuguese2 } 12231 { ES2 iso-ir-85 ISO646-ES2 csISO85Spanish2 } 12232 { MSZ_7795.3 iso-ir-86 ISO646-HU hu csISO86Hungarian } 12233 { JIS_C6226-1983 iso-ir-87 x0208 JIS_X0208-1983 csISO87JISX0208 } 12234 { greek7 iso-ir-88 csISO88Greek7 } 12235 { ASMO_449 ISO_9036 arabic7 iso-ir-89 csISO89ASMO449 } 12236 { iso-ir-90 csISO90 } 12237 { JIS_C6229-1984-a iso-ir-91 jp-ocr-a csISO91JISC62291984a } 12238 { JIS_C6229-1984-b iso-ir-92 ISO646-JP-OCR-B jp-ocr-b 12239 csISO92JISC62991984b } 12240 { JIS_C6229-1984-b-add iso-ir-93 jp-ocr-b-add csISO93JIS62291984badd } 12241 { JIS_C6229-1984-hand iso-ir-94 jp-ocr-hand csISO94JIS62291984hand } 12242 { JIS_C6229-1984-hand-add iso-ir-95 jp-ocr-hand-add 12243 csISO95JIS62291984handadd } 12244 { JIS_C6229-1984-kana iso-ir-96 csISO96JISC62291984kana } 12245 { ISO_2033-1983 iso-ir-98 e13b csISO2033 } 12246 { ANSI_X3.110-1983 iso-ir-99 CSA_T500-1983 NAPLPS csISO99NAPLPS } 12247 { ISO_8859-1:1987 iso-ir-100 ISO_8859-1 ISO-8859-1 latin1 l1 IBM819 12248 CP819 csISOLatin1 } 12249 { ISO_8859-2:1987 iso-ir-101 ISO_8859-2 ISO-8859-2 latin2 l2 csISOLatin2 } 12250 { T.61-7bit iso-ir-102 csISO102T617bit } 12251 { T.61-8bit T.61 iso-ir-103 csISO103T618bit } 12252 { ISO_8859-3:1988 iso-ir-109 ISO_8859-3 ISO-8859-3 latin3 l3 csISOLatin3 } 12253 { ISO_8859-4:1988 iso-ir-110 ISO_8859-4 ISO-8859-4 latin4 l4 csISOLatin4 } 12254 { ECMA-cyrillic iso-ir-111 KOI8-E csISO111ECMACyrillic } 12255 { CSA_Z243.4-1985-1 iso-ir-121 ISO646-CA csa7-1 ca csISO121Canadian1 } 12256 { CSA_Z243.4-1985-2 iso-ir-122 ISO646-CA2 csa7-2 csISO122Canadian2 } 12257 { CSA_Z243.4-1985-gr iso-ir-123 csISO123CSAZ24341985gr } 12258 { ISO_8859-6:1987 iso-ir-127 ISO_8859-6 ISO-8859-6 ECMA-114 ASMO-708 12259 arabic csISOLatinArabic } 12260 { ISO_8859-6-E csISO88596E ISO-8859-6-E } 12261 { ISO_8859-6-I csISO88596I ISO-8859-6-I } 12262 { ISO_8859-7:1987 iso-ir-126 ISO_8859-7 ISO-8859-7 ELOT_928 ECMA-118 12263 greek greek8 csISOLatinGreek } 12264 { T.101-G2 iso-ir-128 csISO128T101G2 } 12265 { ISO_8859-8:1988 iso-ir-138 ISO_8859-8 ISO-8859-8 hebrew 12266 csISOLatinHebrew } 12267 { ISO_8859-8-E csISO88598E ISO-8859-8-E } 12268 { ISO_8859-8-I csISO88598I ISO-8859-8-I } 12269 { CSN_369103 iso-ir-139 csISO139CSN369103 } 12270 { JUS_I.B1.002 iso-ir-141 ISO646-YU js yu csISO141JUSIB1002 } 12271 { ISO_6937-2-add iso-ir-142 csISOTextComm } 12272 { IEC_P27-1 iso-ir-143 csISO143IECP271 } 12273 { ISO_8859-5:1988 iso-ir-144 ISO_8859-5 ISO-8859-5 cyrillic 12274 csISOLatinCyrillic } 12275 { JUS_I.B1.003-serb iso-ir-146 serbian csISO146Serbian } 12276 { JUS_I.B1.003-mac macedonian iso-ir-147 csISO147Macedonian } 12277 { ISO_8859-9:1989 iso-ir-148 ISO_8859-9 ISO-8859-9 latin5 l5 csISOLatin5 } 12278 { greek-ccitt iso-ir-150 csISO150 csISO150GreekCCITT } 12279 { NC_NC00-10:81 cuba iso-ir-151 ISO646-CU csISO151Cuba } 12280 { ISO_6937-2-25 iso-ir-152 csISO6937Add } 12281 { GOST_19768-74 ST_SEV_358-88 iso-ir-153 csISO153GOST1976874 } 12282 { ISO_8859-supp iso-ir-154 latin1-2-5 csISO8859Supp } 12283 { ISO_10367-box iso-ir-155 csISO10367Box } 12284 { ISO-8859-10 iso-ir-157 l6 ISO_8859-10:1992 csISOLatin6 latin6 } 12285 { latin-lap lap iso-ir-158 csISO158Lap } 12286 { JIS_X0212-1990 x0212 iso-ir-159 csISO159JISX02121990 } 12287 { DS_2089 DS2089 ISO646-DK dk csISO646Danish } 12288 { us-dk csUSDK } 12289 { dk-us csDKUS } 12290 { JIS_X0201 X0201 csHalfWidthKatakana } 12291 { KSC5636 ISO646-KR csKSC5636 } 12292 { ISO-10646-UCS-2 csUnicode } 12293 { ISO-10646-UCS-4 csUCS4 } 12294 { DEC-MCS dec csDECMCS } 12295 { hp-roman8 roman8 r8 csHPRoman8 } 12296 { macintosh mac csMacintosh } 12297 { IBM037 cp037 ebcdic-cp-us ebcdic-cp-ca ebcdic-cp-wt ebcdic-cp-nl 12298 csIBM037 } 12299 { IBM038 EBCDIC-INT cp038 csIBM038 } 12300 { IBM273 CP273 csIBM273 } 12301 { IBM274 EBCDIC-BE CP274 csIBM274 } 12302 { IBM275 EBCDIC-BR cp275 csIBM275 } 12303 { IBM277 EBCDIC-CP-DK EBCDIC-CP-NO csIBM277 } 12304 { IBM278 CP278 ebcdic-cp-fi ebcdic-cp-se csIBM278 } 12305 { IBM280 CP280 ebcdic-cp-it csIBM280 } 12306 { IBM281 EBCDIC-JP-E cp281 csIBM281 } 12307 { IBM284 CP284 ebcdic-cp-es csIBM284 } 12308 { IBM285 CP285 ebcdic-cp-gb csIBM285 } 12309 { IBM290 cp290 EBCDIC-JP-kana csIBM290 } 12310 { IBM297 cp297 ebcdic-cp-fr csIBM297 } 12311 { IBM420 cp420 ebcdic-cp-ar1 csIBM420 } 12312 { IBM423 cp423 ebcdic-cp-gr csIBM423 } 12313 { IBM424 cp424 ebcdic-cp-he csIBM424 } 12314 { IBM437 cp437 437 csPC8CodePage437 } 12315 { IBM500 CP500 ebcdic-cp-be ebcdic-cp-ch csIBM500 } 12316 { IBM775 cp775 csPC775Baltic } 12317 { IBM850 cp850 850 csPC850Multilingual } 12318 { IBM851 cp851 851 csIBM851 } 12319 { IBM852 cp852 852 csPCp852 } 12320 { IBM855 cp855 855 csIBM855 } 12321 { IBM857 cp857 857 csIBM857 } 12322 { IBM860 cp860 860 csIBM860 } 12323 { IBM861 cp861 861 cp-is csIBM861 } 12324 { IBM862 cp862 862 csPC862LatinHebrew } 12325 { IBM863 cp863 863 csIBM863 } 12326 { IBM864 cp864 csIBM864 } 12327 { IBM865 cp865 865 csIBM865 } 12328 { IBM866 cp866 866 csIBM866 } 12329 { IBM868 CP868 cp-ar csIBM868 } 12330 { IBM869 cp869 869 cp-gr csIBM869 } 12331 { IBM870 CP870 ebcdic-cp-roece ebcdic-cp-yu csIBM870 } 12332 { IBM871 CP871 ebcdic-cp-is csIBM871 } 12333 { IBM880 cp880 EBCDIC-Cyrillic csIBM880 } 12334 { IBM891 cp891 csIBM891 } 12335 { IBM903 cp903 csIBM903 } 12336 { IBM904 cp904 904 csIBBM904 } 12337 { IBM905 CP905 ebcdic-cp-tr csIBM905 } 12338 { IBM918 CP918 ebcdic-cp-ar2 csIBM918 } 12339 { IBM1026 CP1026 csIBM1026 } 12340 { EBCDIC-AT-DE csIBMEBCDICATDE } 12341 { EBCDIC-AT-DE-A csEBCDICATDEA } 12342 { EBCDIC-CA-FR csEBCDICCAFR } 12343 { EBCDIC-DK-NO csEBCDICDKNO } 12344 { EBCDIC-DK-NO-A csEBCDICDKNOA } 12345 { EBCDIC-FI-SE csEBCDICFISE } 12346 { EBCDIC-FI-SE-A csEBCDICFISEA } 12347 { EBCDIC-FR csEBCDICFR } 12348 { EBCDIC-IT csEBCDICIT } 12349 { EBCDIC-PT csEBCDICPT } 12350 { EBCDIC-ES csEBCDICES } 12351 { EBCDIC-ES-A csEBCDICESA } 12352 { EBCDIC-ES-S csEBCDICESS } 12353 { EBCDIC-UK csEBCDICUK } 12354 { EBCDIC-US csEBCDICUS } 12355 { UNKNOWN-8BIT csUnknown8BiT } 12356 { MNEMONIC csMnemonic } 12357 { MNEM csMnem } 12358 { VISCII csVISCII } 12359 { VIQR csVIQR } 12360 { KOI8-R csKOI8R } 12361 { IBM00858 CCSID00858 CP00858 PC-Multilingual-850+euro } 12362 { IBM00924 CCSID00924 CP00924 ebcdic-Latin9--euro } 12363 { IBM01140 CCSID01140 CP01140 ebcdic-us-37+euro } 12364 { IBM01141 CCSID01141 CP01141 ebcdic-de-273+euro } 12365 { IBM01142 CCSID01142 CP01142 ebcdic-dk-277+euro ebcdic-no-277+euro } 12366 { IBM01143 CCSID01143 CP01143 ebcdic-fi-278+euro ebcdic-se-278+euro } 12367 { IBM01144 CCSID01144 CP01144 ebcdic-it-280+euro } 12368 { IBM01145 CCSID01145 CP01145 ebcdic-es-284+euro } 12369 { IBM01146 CCSID01146 CP01146 ebcdic-gb-285+euro } 12370 { IBM01147 CCSID01147 CP01147 ebcdic-fr-297+euro } 12371 { IBM01148 CCSID01148 CP01148 ebcdic-international-500+euro } 12372 { IBM01149 CCSID01149 CP01149 ebcdic-is-871+euro } 12373 { IBM1047 IBM-1047 } 12374 { PTCP154 csPTCP154 PT154 CP154 Cyrillic-Asian } 12375 { Amiga-1251 Ami1251 Amiga1251 Ami-1251 } 12376 { UNICODE-1-1 csUnicode11 } 12377 { CESU-8 csCESU-8 } 12378 { BOCU-1 csBOCU-1 } 12379 { UNICODE-1-1-UTF-7 csUnicode11UTF7 } 12380 { ISO-8859-14 iso-ir-199 ISO_8859-14:1998 ISO_8859-14 latin8 iso-celtic 12381 l8 } 12382 { ISO-8859-15 ISO_8859-15 Latin-9 } 12383 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 } 12384 { GBK CP936 MS936 windows-936 } 12385 { JIS_Encoding csJISEncoding } 12386 { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS } 12387 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese 12388 EUC-JP } 12389 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese } 12390 { ISO-10646-UCS-Basic csUnicodeASCII } 12391 { ISO-10646-Unicode-Latin1 csUnicodeLatin1 ISO-10646 } 12392 { ISO-Unicode-IBM-1261 csUnicodeIBM1261 } 12393 { ISO-Unicode-IBM-1268 csUnicodeIBM1268 } 12394 { ISO-Unicode-IBM-1276 csUnicodeIBM1276 } 12395 { ISO-Unicode-IBM-1264 csUnicodeIBM1264 } 12396 { ISO-Unicode-IBM-1265 csUnicodeIBM1265 } 12397 { ISO-8859-1-Windows-3.0-Latin-1 csWindows30Latin1 } 12398 { ISO-8859-1-Windows-3.1-Latin-1 csWindows31Latin1 } 12399 { ISO-8859-2-Windows-Latin-2 csWindows31Latin2 } 12400 { ISO-8859-9-Windows-Latin-5 csWindows31Latin5 } 12401 { Adobe-Standard-Encoding csAdobeStandardEncoding } 12402 { Ventura-US csVenturaUS } 12403 { Ventura-International csVenturaInternational } 12404 { PC8-Danish-Norwegian csPC8DanishNorwegian } 12405 { PC8-Turkish csPC8Turkish } 12406 { IBM-Symbols csIBMSymbols } 12407 { IBM-Thai csIBMThai } 12408 { HP-Legal csHPLegal } 12409 { HP-Pi-font csHPPiFont } 12410 { HP-Math8 csHPMath8 } 12411 { Adobe-Symbol-Encoding csHPPSMath } 12412 { HP-DeskTop csHPDesktop } 12413 { Ventura-Math csVenturaMath } 12414 { Microsoft-Publishing csMicrosoftPublishing } 12415 { Windows-31J csWindows31J } 12416 { GB2312 csGB2312 } 12417 { Big5 csBig5 } 12418 } 12419 12420 proc tcl_encoding {enc} { 12421 global encoding_aliases tcl_encoding_cache 12422 if {[info exists tcl_encoding_cache($enc)]} { 12423 return $tcl_encoding_cache($enc) 12424 } 12425 set names [encoding names] 12426 set lcnames [string tolower $names] 12427 set enc [string tolower $enc] 12428 set i [lsearch -exact $lcnames $enc] 12429 if {$i < 0} { 12430 # look for "isonnn" instead of "iso-nnn" or "iso_nnn" 12431 if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} { 12432 set i [lsearch -exact $lcnames $encx] 12433 } 12434 } 12435 if {$i < 0} { 12436 foreach l $encoding_aliases { 12437 set ll [string tolower $l] 12438 if {[lsearch -exact $ll $enc] < 0} continue 12439 # look through the aliases for one that tcl knows about 12440 foreach e $ll { 12441 set i [lsearch -exact $lcnames $e] 12442 if {$i < 0} { 12443 if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} { 12444 set i [lsearch -exact $lcnames $ex] 12445 } 12446 } 12447 if {$i >= 0} break 12448 } 12449 break 12450 } 12451 } 12452 set tclenc {} 12453 if {$i >= 0} { 12454 set tclenc [lindex $names $i] 12455 } 12456 set tcl_encoding_cache($enc) $tclenc 12457 return $tclenc 12458 } 12459 12460 proc gitattr {path attr default} { 12461 global path_attr_cache 12462 if {[info exists path_attr_cache($attr,$path)]} { 12463 set r $path_attr_cache($attr,$path) 12464 } else { 12465 set r "unspecified" 12466 if {![catch {set line [safe_exec [list git check-attr $attr -- $path]]}]} { 12467 regexp "(.*): $attr: (.*)" $line m f r 12468 } 12469 set path_attr_cache($attr,$path) $r 12470 } 12471 if {$r eq "unspecified"} { 12472 return $default 12473 } 12474 return $r 12475 } 12476 12477 proc cache_gitattr {attr pathlist} { 12478 global path_attr_cache 12479 set newlist {} 12480 foreach path $pathlist { 12481 if {![info exists path_attr_cache($attr,$path)]} { 12482 lappend newlist $path 12483 } 12484 } 12485 set lim 1000 12486 if {[tk windowingsystem] == "win32"} { 12487 # windows has a 32k limit on the arguments to a command... 12488 set lim 30 12489 } 12490 while {$newlist ne {}} { 12491 set head [lrange $newlist 0 [expr {$lim - 1}]] 12492 set newlist [lrange $newlist $lim end] 12493 if {![catch {set rlist [safe_exec [concat git check-attr $attr -- $head]]}]} { 12494 foreach row [split $rlist "\n"] { 12495 if {[regexp "(.*): $attr: (.*)" $row m path value]} { 12496 if {[string index $path 0] eq "\""} { 12497 set path [convertfrom utf-8 [lindex $path 0]] 12498 } 12499 set path_attr_cache($attr,$path) $value 12500 } 12501 } 12502 } 12503 } 12504 } 12505 12506 proc get_path_encoding {path} { 12507 global gui_encoding perfile_attrs 12508 set tcl_enc $gui_encoding 12509 if {$path ne {} && $perfile_attrs} { 12510 set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]] 12511 if {$enc2 ne {}} { 12512 set tcl_enc $enc2 12513 } 12514 } 12515 return $tcl_enc 12516 } 12517 12518 proc is_other_ref_visible {ref} { 12519 global refstohide 12520 12521 if {$refstohide eq {}} { 12522 return 1 12523 } 12524 12525 foreach pat [split $refstohide " "] { 12526 if {$pat eq {}} continue 12527 if {[string match $pat $ref]} { 12528 return 0 12529 } 12530 } 12531 12532 return 1 12533 } 12534 12535 ## For msgcat loading, first locate the installation location. 12536 if { [info exists ::env(GITK_MSGSDIR)] } { 12537 ## Msgsdir was manually set in the environment. 12538 set gitk_msgsdir $::env(GITK_MSGSDIR) 12539 } else { 12540 ## Let's guess the prefix from argv0. 12541 set gitk_prefix [file dirname [file dirname [file normalize $argv0]]] 12542 set gitk_libdir [file join $gitk_prefix share gitk lib] 12543 set gitk_msgsdir [file join $gitk_libdir msgs] 12544 } 12545 12546 ## Internationalization (i18n) through msgcat and gettext. See 12547 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html 12548 package require msgcat 12549 namespace import ::msgcat::mc 12550 ## And eventually load the actual message catalog 12551 ::msgcat::mcload $gitk_msgsdir 12552 12553 # on OSX bring the current Wish process window to front 12554 if {[tk windowingsystem] eq "aqua"} { 12555 catch { 12556 safe_exec [list osascript -e [format { 12557 tell application "System Events" 12558 set frontmost of processes whose unix id is %d to true 12559 end tell 12560 } [pid] ]] 12561 } 12562 } 12563 12564 # Unset GIT_TRACE var if set 12565 if { [info exists ::env(GIT_TRACE)] } { 12566 unset ::env(GIT_TRACE) 12567 } 12568 12569 # defaults... 12570 set wrcomcmd "git diff-tree --stdin -p --pretty=email" 12571 12572 set gitencoding {} 12573 catch { 12574 set gitencoding [exec git config --get i18n.commitencoding] 12575 } 12576 catch { 12577 set gitencoding [exec git config --get i18n.logoutputencoding] 12578 } 12579 if {$gitencoding == ""} { 12580 set gitencoding "utf-8" 12581 } 12582 set tclencoding [tcl_encoding $gitencoding] 12583 if {$tclencoding == {}} { 12584 puts stderr "Warning: encoding $gitencoding is not supported by Tcl/Tk" 12585 } 12586 12587 set gui_encoding [encoding system] 12588 catch { 12589 set enc [exec git config --get gui.encoding] 12590 if {$enc ne {}} { 12591 set tclenc [tcl_encoding $enc] 12592 if {$tclenc ne {}} { 12593 set gui_encoding $tclenc 12594 } else { 12595 puts stderr "Warning: encoding $enc is not supported by Tcl/Tk" 12596 } 12597 } 12598 } 12599 12600 # Use object format as hash algorightm (either "sha1" or "sha256") 12601 set hashalgorithm [exec git rev-parse --show-object-format] 12602 if {$hashalgorithm eq "sha1"} { 12603 set hashlength 40 12604 } elseif {$hashalgorithm eq "sha256"} { 12605 set hashlength 64 12606 } else { 12607 puts stderr "Unknown hash algorithm: $hashalgorithm" 12608 exit 1 12609 } 12610 12611 set log_showroot true 12612 catch { 12613 set log_showroot [exec git config --bool --get log.showroot] 12614 } 12615 12616 if {[tk windowingsystem] eq "aqua"} { 12617 set mainfont {{Lucida Grande} 9} 12618 set textfont {Monaco 9} 12619 set uifont {{Lucida Grande} 9 bold} 12620 } elseif {![catch {::tk::pkgconfig get fontsystem} xft] && $xft eq "xft"} { 12621 # fontconfig! 12622 set mainfont {sans 9} 12623 set textfont {monospace 9} 12624 set uifont {sans 9 bold} 12625 } else { 12626 set mainfont {Helvetica 9} 12627 set textfont {Courier 9} 12628 set uifont {Helvetica 9 bold} 12629 } 12630 set tabstop 8 12631 set findmergefiles 0 12632 set maxgraphpct 50 12633 set maxwidth 16 12634 set revlistorder 0 12635 set fastdate 0 12636 set uparrowlen 5 12637 set downarrowlen 5 12638 set mingaplen 100 12639 set cmitmode "patch" 12640 set wrapcomment "none" 12641 set wrapdefault "none" 12642 set showneartags 1 12643 set hideremotes 0 12644 set refstohide "" 12645 set sortrefsbytype 1 12646 set maxrefs 20 12647 set visiblerefs {"master"} 12648 set maxlinelen 200 12649 set showlocalchanges 1 12650 set limitdiffs 1 12651 set kscroll 3 12652 set datetimeformat "%Y-%m-%d %H:%M:%S" 12653 set autocopy 0 12654 set autoselect 1 12655 set autosellen $hashlength 12656 set perfile_attrs 0 12657 12658 if {[tk windowingsystem] eq "aqua"} { 12659 set extdifftool "opendiff" 12660 } else { 12661 set extdifftool "meld" 12662 } 12663 12664 set colors {"#00ff00" red blue magenta darkgrey brown orange} 12665 if {[tk windowingsystem] eq "win32"} { 12666 set bgcolor SystemWindow 12667 set fgcolor SystemWindowText 12668 set selectbgcolor SystemHighlight 12669 set web_browser "cmd /c start" 12670 } else { 12671 set bgcolor white 12672 set fgcolor black 12673 set selectbgcolor gray85 12674 if {[tk windowingsystem] eq "aqua"} { 12675 set web_browser "open" 12676 } else { 12677 set web_browser "xdg-open" 12678 } 12679 } 12680 set diffcolors {"#c30000" "#009800" blue} 12681 set diffbgcolors {"#fff3f3" "#f0fff0"} 12682 set diffcontext 3 12683 set mergecolors {red blue "#00ff00" purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"} 12684 set ignorespace 0 12685 set worddiff "" 12686 set markbgcolor "#e0e0ff" 12687 12688 set headbgcolor "#00ff00" 12689 set headfgcolor black 12690 set headoutlinecolor black 12691 set remotebgcolor #ffddaa 12692 set tagbgcolor yellow 12693 set tagfgcolor black 12694 set tagoutlinecolor black 12695 set reflinecolor black 12696 set filesepbgcolor #aaaaaa 12697 set filesepfgcolor black 12698 set linehoverbgcolor #ffff80 12699 set linehoverfgcolor black 12700 set linehoveroutlinecolor black 12701 set mainheadcirclecolor yellow 12702 set workingfilescirclecolor red 12703 set indexcirclecolor "#00ff00" 12704 set circlecolors {white blue gray blue blue} 12705 set linkfgcolor blue 12706 set circleoutlinecolor $fgcolor 12707 set foundbgcolor yellow 12708 set currentsearchhitbgcolor orange 12709 12710 set theme [ttk::style theme use] 12711 set themeloader {} 12712 set uicolor {} 12713 set uifgcolor {} 12714 set uifgdisabledcolor {} 12715 12716 # button for popping up context menus 12717 if {[tk windowingsystem] eq "aqua" && [package vcompare $::tcl_version 8.7] < 0} { 12718 set ctxbut 12719 } else { 12720 set ctxbut 12721 } 12722 12723 catch { 12724 # follow the XDG base directory specification by default. See 12725 # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html 12726 if {[info exists env(XDG_CONFIG_HOME)] && $env(XDG_CONFIG_HOME) ne ""} { 12727 # XDG_CONFIG_HOME environment variable is set 12728 set config_file [file join $env(XDG_CONFIG_HOME) git gitk] 12729 set config_file_tmp [file join $env(XDG_CONFIG_HOME) git gitk-tmp] 12730 } else { 12731 # default XDG_CONFIG_HOME 12732 set config_file "$env(HOME)/.config/git/gitk" 12733 set config_file_tmp "$env(HOME)/.config/git/gitk-tmp" 12734 } 12735 if {![file exists $config_file]} { 12736 # for backward compatibility use the old config file if it exists 12737 if {[file exists "$env(HOME)/.gitk"]} { 12738 set config_file "$env(HOME)/.gitk" 12739 set config_file_tmp "$env(HOME)/.gitk-tmp" 12740 } elseif {![file exists [file dirname $config_file]]} { 12741 file mkdir [file dirname $config_file] 12742 } 12743 } 12744 source $config_file 12745 } 12746 config_check_tmp_exists 50 12747 12748 set config_variables { 12749 autocopy 12750 autoselect 12751 autosellen 12752 bgcolor 12753 circlecolors 12754 circleoutlinecolor 12755 cmitmode 12756 colors 12757 currentsearchhitbgcolor 12758 datetimeformat 12759 diffbgcolors 12760 diffcolors 12761 diffcontext 12762 extdifftool 12763 fgcolor 12764 filesepbgcolor 12765 filesepfgcolor 12766 findmergefiles 12767 foundbgcolor 12768 headbgcolor 12769 headfgcolor 12770 headoutlinecolor 12771 hideremotes 12772 indexcirclecolor 12773 kscroll 12774 limitdiffs 12775 linehoverbgcolor 12776 linehoverfgcolor 12777 linehoveroutlinecolor 12778 linkfgcolor 12779 mainfont 12780 mainheadcirclecolor 12781 markbgcolor 12782 maxgraphpct 12783 maxrefs 12784 maxwidth 12785 mergecolors 12786 perfile_attrs 12787 reflinecolor 12788 refstohide 12789 remotebgcolor 12790 selectbgcolor 12791 showlocalchanges 12792 showneartags 12793 sortrefsbytype 12794 tabstop 12795 tagbgcolor 12796 tagfgcolor 12797 tagoutlinecolor 12798 textfont 12799 theme 12800 themeloader 12801 uicolor 12802 uifgcolor 12803 uifgdisabledcolor 12804 uifont 12805 visiblerefs 12806 web_browser 12807 workingfilescirclecolor 12808 wrapcomment 12809 wrapdefault 12810 } 12811 12812 foreach var $config_variables { 12813 config_init_trace $var 12814 trace add variable $var write config_variable_change_cb 12815 } 12816 12817 parsefont mainfont $mainfont 12818 eval font create mainfont [fontflags mainfont] 12819 eval font create mainfontbold [fontflags mainfont 1] 12820 12821 parsefont textfont $textfont 12822 eval font create textfont [fontflags textfont] 12823 eval font create textfontbold [fontflags textfont 1] 12824 12825 parsefont uifont $uifont 12826 eval font create uifont [fontflags uifont] 12827 12828 setoptions 12829 12830 # check that we can find a .git directory somewhere... 12831 if {[catch {set gitdir [exec git rev-parse --git-dir]}]} { 12832 show_error {} . [mc "Cannot find a git repository here."] 12833 exit 1 12834 } 12835 12836 set selecthead {} 12837 set selectheadid {} 12838 12839 set revtreeargs {} 12840 set cmdline_files {} 12841 set i 0 12842 set revtreeargscmd {} 12843 foreach arg $argv { 12844 switch -glob -- $arg { 12845 "" { } 12846 "--" { 12847 set cmdline_files [lrange $argv [expr {$i + 1}] end] 12848 break 12849 } 12850 "--select-commit=*" { 12851 set selecthead [string range $arg 16 end] 12852 } 12853 "--argscmd=*" { 12854 set revtreeargscmd [string range $arg 10 end] 12855 } 12856 default { 12857 lappend revtreeargs $arg 12858 } 12859 } 12860 incr i 12861 } 12862 12863 if {$selecthead eq "HEAD"} { 12864 set selecthead {} 12865 } 12866 12867 if {$i >= [llength $argv] && $revtreeargs ne {}} { 12868 # no -- on command line, but some arguments (other than --argscmd) 12869 if {[catch { 12870 set f [safe_exec [concat git rev-parse --no-revs --no-flags $revtreeargs]] 12871 set cmdline_files [split $f "\n"] 12872 set n [llength $cmdline_files] 12873 set revtreeargs [lrange $revtreeargs 0 end-$n] 12874 # Unfortunately git rev-parse doesn't produce an error when 12875 # something is both a revision and a filename. To be consistent 12876 # with git log and git rev-list, check revtreeargs for filenames. 12877 foreach arg $revtreeargs { 12878 if {[file exists $arg]} { 12879 show_error {} . [mc "Ambiguous argument '%s': both revision\ 12880 and filename" $arg] 12881 exit 1 12882 } 12883 } 12884 } err]} { 12885 # unfortunately we get both stdout and stderr in $err, 12886 # so look for "fatal:". 12887 set i [string first "fatal:" $err] 12888 if {$i > 0} { 12889 set err [string range $err [expr {$i + 6}] end] 12890 } 12891 show_error {} . "[mc "Bad arguments to gitk:"]\n$err" 12892 exit 1 12893 } 12894 } 12895 12896 set nullid "`0000000000000000000000000000000000000000`" 12897 set nullid2 "`0000000000000000000000000000000000000001`" 12898 set nullfile "/dev/null" 12899 12900 if {[file exists $themeloader]} { 12901 if {![run_themeloader $themeloader]} { 12902 puts stderr "Could not interpret themeloader: $themeloader" 12903 exit 1 12904 } 12905 } 12906 12907 set appname "gitk" 12908 12909 set runq {} 12910 set history {} 12911 set historyindex 0 12912 set fh_serial 0 12913 set nhl_names {} 12914 set highlight_paths {} 12915 set findpattern {} 12916 set searchdirn -forwards 12917 set boldids {} 12918 set boldnameids {} 12919 set diffelide {0 0} 12920 set markingmatches 0 12921 set linkentercount 0 12922 set need_redisplay 0 12923 set nrows_drawn 0 12924 set firsttabstop 0 12925 12926 set nextviewnum 1 12927 set curview 0 12928 set selectedview 0 12929 set selectedhlview [mc "None"] 12930 set highlight_related [mc "None"] 12931 set highlight_files {} 12932 set viewfiles(0) {} 12933 set viewperm(0) 0 12934 set viewchanged(0) 0 12935 set viewargs(0) {} 12936 set viewargscmd(0) {} 12937 12938 set selectedline {} 12939 set numcommits 0 12940 set loginstance 0 12941 set cmdlineok 0 12942 set stopped 0 12943 set stuffsaved 0 12944 set patchnum 0 12945 set lserial 0 12946 set hasworktree [hasworktree] 12947 set cdup {} 12948 if {[expr {[exec git rev-parse --is-inside-work-tree] == "true"}]} { 12949 set cdup [exec git rev-parse --show-cdup] 12950 } 12951 set worktree [gitworktree] 12952 setcoords 12953 makewindow 12954 if {$::tcl_platform(platform) eq {windows} && [file exists $gitk_prefix/etc/git.ico]} { 12955 wm iconbitmap . -default $gitk_prefix/etc/git.ico 12956 } else { 12957 catch { 12958 image create photo gitlogo -width 16 -height 16 12959 12960 image create photo gitlogominus -width 4 -height 2 12961 gitlogominus put #C00000 -to 0 0 4 2 12962 gitlogo copy gitlogominus -to 1 5 12963 gitlogo copy gitlogominus -to 6 5 12964 gitlogo copy gitlogominus -to 11 5 12965 image delete gitlogominus 12966 12967 image create photo gitlogoplus -width 4 -height 4 12968 gitlogoplus put #008000 -to 1 0 3 4 12969 gitlogoplus put #008000 -to 0 1 4 3 12970 gitlogo copy gitlogoplus -to 1 9 12971 gitlogo copy gitlogoplus -to 6 9 12972 gitlogo copy gitlogoplus -to 11 9 12973 image delete gitlogoplus 12974 12975 image create photo gitlogo32 -width 32 -height 32 12976 gitlogo32 copy gitlogo -zoom 2 2 12977 12978 wm iconphoto . -default gitlogo gitlogo32 12979 } 12980 } 12981 # wait for the window to become visible 12982 if {![winfo viewable .]} {tkwait visibility .} 12983 set_window_title 12984 update 12985 readrefs 12986 12987 if {$cmdline_files ne {} || $revtreeargs ne {} || $revtreeargscmd ne {}} { 12988 # create a view for the files/dirs specified on the command line 12989 set curview 1 12990 set selectedview 1 12991 set nextviewnum 2 12992 set viewname(1) [mc "Command line"] 12993 set viewfiles(1) $cmdline_files 12994 set viewargs(1) $revtreeargs 12995 set viewargscmd(1) $revtreeargscmd 12996 set viewperm(1) 0 12997 set viewchanged(1) 0 12998 set vdatemode(1) 0 12999 addviewmenu 1 13000 .bar.view entryconf [mca "&Edit view..."] -state normal 13001 .bar.view entryconf [mca "&Delete view"] -state normal 13002 } 13003 13004 if {[info exists permviews]} { 13005 foreach v $permviews { 13006 set n $nextviewnum 13007 incr nextviewnum 13008 set viewname($n) [lindex $v 0] 13009 set viewfiles($n) [lindex $v 1] 13010 set viewargs($n) [lindex $v 2] 13011 set viewargscmd($n) [lindex $v 3] 13012 set viewperm($n) 1 13013 set viewchanged($n) 0 13014 addviewmenu $n 13015 } 13016 } 13017 13018 if {[tk windowingsystem] eq "win32"} { 13019 focus -force . 13020 } 13021 13022 setttkstyle 13023 set_gui_colors 13024 13025 getcommits {} 13026 13027 # Local variables: 13028 # mode: tcl 13029 # indent-tabs-mode: t 13030 # tab-width: 8 13031 # End: