Merge branch 'maint'
[git/kirr.git] / git-gui / git-gui.sh
blobd3acf0d2134b40b8ffb3d0e8c3229f71fa6db663
1 #!/bin/sh
2 # Tcl ignores the next line -*- tcl -*- \
3 if test "z$*" = zversion \
4 || test "z$*" = z--version; \
5 then \
6 echo 'git-gui version @@GITGUI_VERSION@@'; \
7 exit; \
8 fi; \
9 argv0=$0; \
10 exec wish "$argv0" -- "$@"
12 set appvers {@@GITGUI_VERSION@@}
13 set copyright [string map [list (c) \u00a9] {
14 Copyright (c) 2006-2010 Shawn Pearce, et. al.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}]
30 ######################################################################
32 ## Tcl/Tk sanity check
34 if {[catch {package require Tcl 8.4} err]
35 || [catch {package require Tk 8.4} err]
36 } {
37 catch {wm withdraw .}
38 tk_messageBox \
39 -icon error \
40 -type ok \
41 -title "git-gui: fatal error" \
42 -message $err
43 exit 1
46 catch {rename send {}} ; # What an evil concept...
48 ######################################################################
50 ## locate our library
52 set oguilib {@@GITGUI_LIBDIR@@}
53 set oguirel {@@GITGUI_RELATIVE@@}
54 if {$oguirel eq {1}} {
55 set oguilib [file dirname [file normalize $argv0]]
56 if {[file tail $oguilib] eq {git-core}} {
57 set oguilib [file dirname $oguilib]
59 set oguilib [file dirname $oguilib]
60 set oguilib [file join $oguilib share git-gui lib]
61 set oguimsg [file join $oguilib msgs]
62 } elseif {[string match @@* $oguirel]} {
63 set oguilib [file join [file dirname [file normalize $argv0]] lib]
64 set oguimsg [file join [file dirname [file normalize $argv0]] po]
65 } else {
66 set oguimsg [file join $oguilib msgs]
68 unset oguirel
70 ######################################################################
72 ## enable verbose loading?
74 if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
75 unset _verbose
76 rename auto_load real__auto_load
77 proc auto_load {name args} {
78 puts stderr "auto_load $name"
79 return [uplevel 1 real__auto_load $name $args]
81 rename source real__source
82 proc source {name} {
83 puts stderr "source $name"
84 uplevel 1 real__source $name
86 if {[tk windowingsystem] eq "win32"} { console show }
89 ######################################################################
91 ## Internationalization (i18n) through msgcat and gettext. See
92 ## http://www.gnu.org/software/gettext/manual/html_node/Tcl.html
94 package require msgcat
96 proc _mc_trim {fmt} {
97 set cmk [string first @@ $fmt]
98 if {$cmk > 0} {
99 return [string range $fmt 0 [expr {$cmk - 1}]]
101 return $fmt
104 proc mc {en_fmt args} {
105 set fmt [_mc_trim [::msgcat::mc $en_fmt]]
106 if {[catch {set msg [eval [list format $fmt] $args]} err]} {
107 set msg [eval [list format [_mc_trim $en_fmt]] $args]
109 return $msg
112 proc strcat {args} {
113 return [join $args {}]
116 ::msgcat::mcload $oguimsg
117 unset oguimsg
119 ######################################################################
121 ## read only globals
123 set _appname {Git Gui}
124 set _gitdir {}
125 set _gitworktree {}
126 set _isbare {}
127 set _gitexec {}
128 set _githtmldir {}
129 set _reponame {}
130 set _iscygwin {}
131 set _search_path {}
132 set _shellpath {@@SHELL_PATH@@}
134 set _trace [lsearch -exact $argv --trace]
135 if {$_trace >= 0} {
136 set argv [lreplace $argv $_trace $_trace]
137 set _trace 1
138 } else {
139 set _trace 0
142 proc shellpath {} {
143 global _shellpath env
144 if {[string match @@* $_shellpath]} {
145 if {[info exists env(SHELL)]} {
146 return $env(SHELL)
147 } else {
148 return /bin/sh
151 return $_shellpath
154 proc appname {} {
155 global _appname
156 return $_appname
159 proc gitdir {args} {
160 global _gitdir
161 if {$args eq {}} {
162 return $_gitdir
164 return [eval [list file join $_gitdir] $args]
167 proc gitexec {args} {
168 global _gitexec
169 if {$_gitexec eq {}} {
170 if {[catch {set _gitexec [git --exec-path]} err]} {
171 error "Git not installed?\n\n$err"
173 if {[is_Cygwin]} {
174 set _gitexec [exec cygpath \
175 --windows \
176 --absolute \
177 $_gitexec]
178 } else {
179 set _gitexec [file normalize $_gitexec]
182 if {$args eq {}} {
183 return $_gitexec
185 return [eval [list file join $_gitexec] $args]
188 proc githtmldir {args} {
189 global _githtmldir
190 if {$_githtmldir eq {}} {
191 if {[catch {set _githtmldir [git --html-path]}]} {
192 # Git not installed or option not yet supported
193 return {}
195 if {[is_Cygwin]} {
196 set _githtmldir [exec cygpath \
197 --windows \
198 --absolute \
199 $_githtmldir]
200 } else {
201 set _githtmldir [file normalize $_githtmldir]
204 if {$args eq {}} {
205 return $_githtmldir
207 return [eval [list file join $_githtmldir] $args]
210 proc reponame {} {
211 return $::_reponame
214 proc is_MacOSX {} {
215 if {[tk windowingsystem] eq {aqua}} {
216 return 1
218 return 0
221 proc is_Windows {} {
222 if {$::tcl_platform(platform) eq {windows}} {
223 return 1
225 return 0
228 proc is_Cygwin {} {
229 global _iscygwin
230 if {$_iscygwin eq {}} {
231 if {$::tcl_platform(platform) eq {windows}} {
232 if {[catch {set p [exec cygpath --windir]} err]} {
233 set _iscygwin 0
234 } else {
235 set _iscygwin 1
237 } else {
238 set _iscygwin 0
241 return $_iscygwin
244 proc is_enabled {option} {
245 global enabled_options
246 if {[catch {set on $enabled_options($option)}]} {return 0}
247 return $on
250 proc enable_option {option} {
251 global enabled_options
252 set enabled_options($option) 1
255 proc disable_option {option} {
256 global enabled_options
257 set enabled_options($option) 0
260 ######################################################################
262 ## config
264 proc is_many_config {name} {
265 switch -glob -- $name {
266 gui.recentrepo -
267 remote.*.fetch -
268 remote.*.push
269 {return 1}
271 {return 0}
275 proc is_config_true {name} {
276 global repo_config
277 if {[catch {set v $repo_config($name)}]} {
278 return 0
279 } elseif {$v eq {true} || $v eq {1} || $v eq {yes}} {
280 return 1
281 } else {
282 return 0
286 proc is_config_false {name} {
287 global repo_config
288 if {[catch {set v $repo_config($name)}]} {
289 return 0
290 } elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
291 return 1
292 } else {
293 return 0
297 proc get_config {name} {
298 global repo_config
299 if {[catch {set v $repo_config($name)}]} {
300 return {}
301 } else {
302 return $v
306 proc is_bare {} {
307 global _isbare
308 global _gitdir
309 global _gitworktree
311 if {$_isbare eq {}} {
312 if {[catch {
313 set _bare [git rev-parse --is-bare-repository]
314 switch -- $_bare {
315 true { set _isbare 1 }
316 false { set _isbare 0}
317 default { throw }
319 }]} {
320 if {[is_config_true core.bare]
321 || ($_gitworktree eq {}
322 && [lindex [file split $_gitdir] end] ne {.git})} {
323 set _isbare 1
324 } else {
325 set _isbare 0
329 return $_isbare
332 ######################################################################
334 ## handy utils
336 proc _trace_exec {cmd} {
337 if {!$::_trace} return
338 set d {}
339 foreach v $cmd {
340 if {$d ne {}} {
341 append d { }
343 if {[regexp {[ \t\r\n'"$?*]} $v]} {
344 set v [sq $v]
346 append d $v
348 puts stderr $d
351 #'" fix poor old emacs font-lock mode
353 proc _git_cmd {name} {
354 global _git_cmd_path
356 if {[catch {set v $_git_cmd_path($name)}]} {
357 switch -- $name {
358 version -
359 --version -
360 --exec-path { return [list $::_git $name] }
363 set p [gitexec git-$name$::_search_exe]
364 if {[file exists $p]} {
365 set v [list $p]
366 } elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
367 # Try to determine what sort of magic will make
368 # git-$name go and do its thing, because native
369 # Tcl on Windows doesn't know it.
371 set p [gitexec git-$name]
372 set f [open $p r]
373 set s [gets $f]
374 close $f
376 switch -glob -- [lindex $s 0] {
377 #!*sh { set i sh }
378 #!*perl { set i perl }
379 #!*python { set i python }
380 default { error "git-$name is not supported: $s" }
383 upvar #0 _$i interp
384 if {![info exists interp]} {
385 set interp [_which $i]
387 if {$interp eq {}} {
388 error "git-$name requires $i (not in PATH)"
390 set v [concat [list $interp] [lrange $s 1 end] [list $p]]
391 } else {
392 # Assume it is builtin to git somehow and we
393 # aren't actually able to see a file for it.
395 set v [list $::_git $name]
397 set _git_cmd_path($name) $v
399 return $v
402 proc _which {what args} {
403 global env _search_exe _search_path
405 if {$_search_path eq {}} {
406 if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
407 set _search_path [split [exec cygpath \
408 --windows \
409 --path \
410 --absolute \
411 $env(PATH)] {;}]
412 set _search_exe .exe
413 } elseif {[is_Windows]} {
414 set gitguidir [file dirname [info script]]
415 regsub -all ";" $gitguidir "\\;" gitguidir
416 set env(PATH) "$gitguidir;$env(PATH)"
417 set _search_path [split $env(PATH) {;}]
418 set _search_exe .exe
419 } else {
420 set _search_path [split $env(PATH) :]
421 set _search_exe {}
425 if {[is_Windows] && [lsearch -exact $args -script] >= 0} {
426 set suffix {}
427 } else {
428 set suffix $_search_exe
431 foreach p $_search_path {
432 set p [file join $p $what$suffix]
433 if {[file exists $p]} {
434 return [file normalize $p]
437 return {}
440 proc _lappend_nice {cmd_var} {
441 global _nice
442 upvar $cmd_var cmd
444 if {![info exists _nice]} {
445 set _nice [_which nice]
446 if {[catch {exec $_nice git version}]} {
447 set _nice {}
448 } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} {
449 set _nice {}
452 if {$_nice ne {}} {
453 lappend cmd $_nice
457 proc git {args} {
458 set opt [list]
460 while {1} {
461 switch -- [lindex $args 0] {
462 --nice {
463 _lappend_nice opt
466 default {
467 break
472 set args [lrange $args 1 end]
475 set cmdp [_git_cmd [lindex $args 0]]
476 set args [lrange $args 1 end]
478 _trace_exec [concat $opt $cmdp $args]
479 set result [eval exec $opt $cmdp $args]
480 if {$::_trace} {
481 puts stderr "< $result"
483 return $result
486 proc _open_stdout_stderr {cmd} {
487 _trace_exec $cmd
488 if {[catch {
489 set fd [open [concat [list | ] $cmd] r]
490 } err]} {
491 if { [lindex $cmd end] eq {2>@1}
492 && $err eq {can not find channel named "1"}
494 # Older versions of Tcl 8.4 don't have this 2>@1 IO
495 # redirect operator. Fallback to |& cat for those.
496 # The command was not actually started, so its safe
497 # to try to start it a second time.
499 set fd [open [concat \
500 [list | ] \
501 [lrange $cmd 0 end-1] \
502 [list |& cat] \
503 ] r]
504 } else {
505 error $err
508 fconfigure $fd -eofchar {}
509 return $fd
512 proc git_read {args} {
513 set opt [list]
515 while {1} {
516 switch -- [lindex $args 0] {
517 --nice {
518 _lappend_nice opt
521 --stderr {
522 lappend args 2>@1
525 default {
526 break
531 set args [lrange $args 1 end]
534 set cmdp [_git_cmd [lindex $args 0]]
535 set args [lrange $args 1 end]
537 return [_open_stdout_stderr [concat $opt $cmdp $args]]
540 proc git_write {args} {
541 set opt [list]
543 while {1} {
544 switch -- [lindex $args 0] {
545 --nice {
546 _lappend_nice opt
549 default {
550 break
555 set args [lrange $args 1 end]
558 set cmdp [_git_cmd [lindex $args 0]]
559 set args [lrange $args 1 end]
561 _trace_exec [concat $opt $cmdp $args]
562 return [open [concat [list | ] $opt $cmdp $args] w]
565 proc githook_read {hook_name args} {
566 set pchook [gitdir hooks $hook_name]
567 lappend args 2>@1
569 # On Windows [file executable] might lie so we need to ask
570 # the shell if the hook is executable. Yes that's annoying.
572 if {[is_Windows]} {
573 upvar #0 _sh interp
574 if {![info exists interp]} {
575 set interp [_which sh]
577 if {$interp eq {}} {
578 error "hook execution requires sh (not in PATH)"
581 set scr {if test -x "$1";then exec "$@";fi}
582 set sh_c [list $interp -c $scr $interp $pchook]
583 return [_open_stdout_stderr [concat $sh_c $args]]
586 if {[file executable $pchook]} {
587 return [_open_stdout_stderr [concat [list $pchook] $args]]
590 return {}
593 proc kill_file_process {fd} {
594 set process [pid $fd]
596 catch {
597 if {[is_Windows]} {
598 # Use a Cygwin-specific flag to allow killing
599 # native Windows processes
600 exec kill -f $process
601 } else {
602 exec kill $process
607 proc gitattr {path attr default} {
608 if {[catch {set r [git check-attr $attr -- $path]}]} {
609 set r unspecified
610 } else {
611 set r [join [lrange [split $r :] 2 end] :]
612 regsub {^ } $r {} r
614 if {$r eq {unspecified}} {
615 return $default
617 return $r
620 proc sq {value} {
621 regsub -all ' $value "'\\''" value
622 return "'$value'"
625 proc load_current_branch {} {
626 global current_branch is_detached
628 set fd [open [gitdir HEAD] r]
629 if {[gets $fd ref] < 1} {
630 set ref {}
632 close $fd
634 set pfx {ref: refs/heads/}
635 set len [string length $pfx]
636 if {[string equal -length $len $pfx $ref]} {
637 # We're on a branch. It might not exist. But
638 # HEAD looks good enough to be a branch.
640 set current_branch [string range $ref $len end]
641 set is_detached 0
642 } else {
643 # Assume this is a detached head.
645 set current_branch HEAD
646 set is_detached 1
650 auto_load tk_optionMenu
651 rename tk_optionMenu real__tkOptionMenu
652 proc tk_optionMenu {w varName args} {
653 set m [eval real__tkOptionMenu $w $varName $args]
654 $m configure -font font_ui
655 $w configure -font font_ui
656 return $m
659 proc rmsel_tag {text} {
660 $text tag conf sel \
661 -background [$text cget -background] \
662 -foreground [$text cget -foreground] \
663 -borderwidth 0
664 $text tag conf in_sel -background lightgray
665 bind $text <Motion> break
666 return $text
669 wm withdraw .
670 set root_exists 0
671 bind . <Visibility> {
672 bind . <Visibility> {}
673 set root_exists 1
676 if {[is_Windows]} {
677 wm iconbitmap . -default $oguilib/git-gui.ico
678 set ::tk::AlwaysShowSelection 1
679 bind . <Control-F2> {console show}
681 # Spoof an X11 display for SSH
682 if {![info exists env(DISPLAY)]} {
683 set env(DISPLAY) :9999
685 } else {
686 catch {
687 image create photo gitlogo -width 16 -height 16
689 gitlogo put #33CC33 -to 7 0 9 2
690 gitlogo put #33CC33 -to 4 2 12 4
691 gitlogo put #33CC33 -to 7 4 9 6
692 gitlogo put #CC3333 -to 4 6 12 8
693 gitlogo put gray26 -to 4 9 6 10
694 gitlogo put gray26 -to 3 10 6 12
695 gitlogo put gray26 -to 8 9 13 11
696 gitlogo put gray26 -to 8 11 10 12
697 gitlogo put gray26 -to 11 11 13 14
698 gitlogo put gray26 -to 3 12 5 14
699 gitlogo put gray26 -to 5 13
700 gitlogo put gray26 -to 10 13
701 gitlogo put gray26 -to 4 14 12 15
702 gitlogo put gray26 -to 5 15 11 16
703 gitlogo redither
705 wm iconphoto . -default gitlogo
709 ######################################################################
711 ## config defaults
713 set cursor_ptr arrow
714 font create font_ui
715 if {[lsearch -exact [font names] TkDefaultFont] != -1} {
716 eval [linsert [font actual TkDefaultFont] 0 font configure font_ui]
717 eval [linsert [font actual TkFixedFont] 0 font create font_diff]
718 } else {
719 font create font_diff -family Courier -size 10
720 catch {
721 label .dummy
722 eval font configure font_ui [font actual [.dummy cget -font]]
723 destroy .dummy
727 font create font_uiitalic
728 font create font_uibold
729 font create font_diffbold
730 font create font_diffitalic
732 foreach class {Button Checkbutton Entry Label
733 Labelframe Listbox Message
734 Radiobutton Spinbox Text} {
735 option add *$class.font font_ui
737 if {![is_MacOSX]} {
738 option add *Menu.font font_ui
739 option add *Entry.borderWidth 1 startupFile
740 option add *Entry.relief sunken startupFile
741 option add *RadioButton.anchor w startupFile
743 unset class
745 if {[is_Windows] || [is_MacOSX]} {
746 option add *Menu.tearOff 0
749 if {[is_MacOSX]} {
750 set M1B M1
751 set M1T Cmd
752 } else {
753 set M1B Control
754 set M1T Ctrl
757 proc bind_button3 {w cmd} {
758 bind $w <Any-Button-3> $cmd
759 if {[is_MacOSX]} {
760 # Mac OS X sends Button-2 on right click through three-button mouse,
761 # or through trackpad right-clicking (two-finger touch + click).
762 bind $w <Any-Button-2> $cmd
763 bind $w <Control-Button-1> $cmd
767 proc apply_config {} {
768 global repo_config font_descs
770 foreach option $font_descs {
771 set name [lindex $option 0]
772 set font [lindex $option 1]
773 if {[catch {
774 set need_weight 1
775 foreach {cn cv} $repo_config(gui.$name) {
776 if {$cn eq {-weight}} {
777 set need_weight 0
779 font configure $font $cn $cv
781 if {$need_weight} {
782 font configure $font -weight normal
784 } err]} {
785 error_popup [strcat [mc "Invalid font specified in %s:" "gui.$name"] "\n\n$err"]
787 foreach {cn cv} [font configure $font] {
788 font configure ${font}bold $cn $cv
789 font configure ${font}italic $cn $cv
791 font configure ${font}bold -weight bold
792 font configure ${font}italic -slant italic
795 global use_ttk NS
796 set use_ttk 0
797 set NS {}
798 if {$repo_config(gui.usettk)} {
799 set use_ttk [package vsatisfies [package provide Tk] 8.5]
800 if {$use_ttk} {
801 set NS ttk
802 bind [winfo class .] <<ThemeChanged>> [list InitTheme]
803 pave_toplevel .
808 set default_config(branch.autosetupmerge) true
809 set default_config(merge.tool) {}
810 set default_config(mergetool.keepbackup) true
811 set default_config(merge.diffstat) true
812 set default_config(merge.summary) false
813 set default_config(merge.verbosity) 2
814 set default_config(user.name) {}
815 set default_config(user.email) {}
817 set default_config(gui.encoding) [encoding system]
818 set default_config(gui.matchtrackingbranch) false
819 set default_config(gui.textconv) true
820 set default_config(gui.pruneduringfetch) false
821 set default_config(gui.trustmtime) false
822 set default_config(gui.fastcopyblame) false
823 set default_config(gui.copyblamethreshold) 40
824 set default_config(gui.blamehistoryctx) 7
825 set default_config(gui.diffcontext) 5
826 set default_config(gui.commitmsgwidth) 75
827 set default_config(gui.newbranchtemplate) {}
828 set default_config(gui.spellingdictionary) {}
829 set default_config(gui.fontui) [font configure font_ui]
830 set default_config(gui.fontdiff) [font configure font_diff]
831 # TODO: this option should be added to the git-config documentation
832 set default_config(gui.maxfilesdisplayed) 5000
833 set default_config(gui.usettk) 1
834 set font_descs {
835 {fontui font_ui {mc "Main Font"}}
836 {fontdiff font_diff {mc "Diff/Console Font"}}
839 ######################################################################
841 ## find git
843 set _git [_which git]
844 if {$_git eq {}} {
845 catch {wm withdraw .}
846 tk_messageBox \
847 -icon error \
848 -type ok \
849 -title [mc "git-gui: fatal error"] \
850 -message [mc "Cannot find git in PATH."]
851 exit 1
854 ######################################################################
856 ## version check
858 if {[catch {set _git_version [git --version]} err]} {
859 catch {wm withdraw .}
860 tk_messageBox \
861 -icon error \
862 -type ok \
863 -title [mc "git-gui: fatal error"] \
864 -message "Cannot determine Git version:
866 $err
868 [appname] requires Git 1.5.0 or later."
869 exit 1
871 if {![regsub {^git version } $_git_version {} _git_version]} {
872 catch {wm withdraw .}
873 tk_messageBox \
874 -icon error \
875 -type ok \
876 -title [mc "git-gui: fatal error"] \
877 -message [strcat [mc "Cannot parse Git version string:"] "\n\n$_git_version"]
878 exit 1
881 proc get_trimmed_version {s} {
882 set r {}
883 foreach x [split $s -._] {
884 if {[string is integer -strict $x]} {
885 lappend r $x
886 } else {
887 break
890 return [join $r .]
892 set _real_git_version $_git_version
893 set _git_version [get_trimmed_version $_git_version]
895 if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
896 catch {wm withdraw .}
897 if {[tk_messageBox \
898 -icon warning \
899 -type yesno \
900 -default no \
901 -title "[appname]: warning" \
902 -message [mc "Git version cannot be determined.
904 %s claims it is version '%s'.
906 %s requires at least Git 1.5.0 or later.
908 Assume '%s' is version 1.5.0?
909 " $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
910 set _git_version 1.5.0
911 } else {
912 exit 1
915 unset _real_git_version
917 proc git-version {args} {
918 global _git_version
920 switch [llength $args] {
922 return $_git_version
926 set op [lindex $args 0]
927 set vr [lindex $args 1]
928 set cm [package vcompare $_git_version $vr]
929 return [expr $cm $op 0]
933 set type [lindex $args 0]
934 set name [lindex $args 1]
935 set parm [lindex $args 2]
936 set body [lindex $args 3]
938 if {($type ne {proc} && $type ne {method})} {
939 error "Invalid arguments to git-version"
941 if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
942 error "Last arm of $type $name must be default"
945 foreach {op vr cb} [lrange $body 0 end-2] {
946 if {[git-version $op $vr]} {
947 return [uplevel [list $type $name $parm $cb]]
951 return [uplevel [list $type $name $parm [lindex $body end]]]
954 default {
955 error "git-version >= x"
961 if {[git-version < 1.5]} {
962 catch {wm withdraw .}
963 tk_messageBox \
964 -icon error \
965 -type ok \
966 -title [mc "git-gui: fatal error"] \
967 -message "[appname] requires Git 1.5.0 or later.
969 You are using [git-version]:
971 [git --version]"
972 exit 1
975 ######################################################################
977 ## configure our library
979 set idx [file join $oguilib tclIndex]
980 if {[catch {set fd [open $idx r]} err]} {
981 catch {wm withdraw .}
982 tk_messageBox \
983 -icon error \
984 -type ok \
985 -title [mc "git-gui: fatal error"] \
986 -message $err
987 exit 1
989 if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
990 set idx [list]
991 while {[gets $fd n] >= 0} {
992 if {$n ne {} && ![string match #* $n]} {
993 lappend idx $n
996 } else {
997 set idx {}
999 close $fd
1001 if {$idx ne {}} {
1002 set loaded [list]
1003 foreach p $idx {
1004 if {[lsearch -exact $loaded $p] >= 0} continue
1005 source [file join $oguilib $p]
1006 lappend loaded $p
1008 unset loaded p
1009 } else {
1010 set auto_path [concat [list $oguilib] $auto_path]
1012 unset -nocomplain idx fd
1014 ######################################################################
1016 ## config file parsing
1018 git-version proc _parse_config {arr_name args} {
1019 >= 1.5.3 {
1020 upvar $arr_name arr
1021 array unset arr
1022 set buf {}
1023 catch {
1024 set fd_rc [eval \
1025 [list git_read config] \
1026 $args \
1027 [list --null --list]]
1028 fconfigure $fd_rc -translation binary
1029 set buf [read $fd_rc]
1030 close $fd_rc
1032 foreach line [split $buf "\0"] {
1033 if {[regexp {^([^\n]+)\n(.*)$} $line line name value]} {
1034 if {[is_many_config $name]} {
1035 lappend arr($name) $value
1036 } else {
1037 set arr($name) $value
1042 default {
1043 upvar $arr_name arr
1044 array unset arr
1045 catch {
1046 set fd_rc [eval [list git_read config --list] $args]
1047 while {[gets $fd_rc line] >= 0} {
1048 if {[regexp {^([^=]+)=(.*)$} $line line name value]} {
1049 if {[is_many_config $name]} {
1050 lappend arr($name) $value
1051 } else {
1052 set arr($name) $value
1056 close $fd_rc
1061 proc load_config {include_global} {
1062 global repo_config global_config system_config default_config
1064 if {$include_global} {
1065 _parse_config system_config --system
1066 _parse_config global_config --global
1068 _parse_config repo_config
1070 foreach name [array names default_config] {
1071 if {[catch {set v $system_config($name)}]} {
1072 set system_config($name) $default_config($name)
1075 foreach name [array names system_config] {
1076 if {[catch {set v $global_config($name)}]} {
1077 set global_config($name) $system_config($name)
1079 if {[catch {set v $repo_config($name)}]} {
1080 set repo_config($name) $system_config($name)
1085 ######################################################################
1087 ## feature option selection
1089 if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
1090 unset _junk
1091 } else {
1092 set subcommand gui
1094 if {$subcommand eq {gui.sh}} {
1095 set subcommand gui
1097 if {$subcommand eq {gui} && [llength $argv] > 0} {
1098 set subcommand [lindex $argv 0]
1099 set argv [lrange $argv 1 end]
1102 enable_option multicommit
1103 enable_option branch
1104 enable_option transport
1105 disable_option bare
1107 switch -- $subcommand {
1108 browser -
1109 blame {
1110 enable_option bare
1112 disable_option multicommit
1113 disable_option branch
1114 disable_option transport
1116 citool {
1117 enable_option singlecommit
1118 enable_option retcode
1120 disable_option multicommit
1121 disable_option branch
1122 disable_option transport
1124 while {[llength $argv] > 0} {
1125 set a [lindex $argv 0]
1126 switch -- $a {
1127 --amend {
1128 enable_option initialamend
1130 --nocommit {
1131 enable_option nocommit
1132 enable_option nocommitmsg
1134 --commitmsg {
1135 disable_option nocommitmsg
1137 default {
1138 break
1142 set argv [lrange $argv 1 end]
1147 ######################################################################
1149 ## execution environment
1151 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1153 # Suggest our implementation of askpass, if none is set
1154 if {![info exists env(SSH_ASKPASS)]} {
1155 set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1158 ######################################################################
1160 ## repository setup
1162 set picked 0
1163 if {[catch {
1164 set _gitdir $env(GIT_DIR)
1165 set _prefix {}
1167 && [catch {
1168 # beware that from the .git dir this sets _gitdir to .
1169 # and _prefix to the empty string
1170 set _gitdir [git rev-parse --git-dir]
1171 set _prefix [git rev-parse --show-prefix]
1172 } err]} {
1173 load_config 1
1174 apply_config
1175 choose_repository::pick
1176 set picked 1
1179 # we expand the _gitdir when it's just a single dot (i.e. when we're being
1180 # run from the .git dir itself) lest the routines to find the worktree
1181 # get confused
1182 if {$_gitdir eq "."} {
1183 set _gitdir [pwd]
1186 if {![file isdirectory $_gitdir] && [is_Cygwin]} {
1187 catch {set _gitdir [exec cygpath --windows $_gitdir]}
1189 if {![file isdirectory $_gitdir]} {
1190 catch {wm withdraw .}
1191 error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
1192 exit 1
1194 # _gitdir exists, so try loading the config
1195 load_config 0
1196 apply_config
1198 # v1.7.0 introduced --show-toplevel to return the canonical work-tree
1199 if {[package vsatisfies $_git_version 1.7.0]} {
1200 set _gitworktree [git rev-parse --show-toplevel]
1201 } else {
1202 # try to set work tree from environment, core.worktree or use
1203 # cdup to obtain a relative path to the top of the worktree. If
1204 # run from the top, the ./ prefix ensures normalize expands pwd.
1205 if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1206 set _gitworktree [get_config core.worktree]
1207 if {$_gitworktree eq ""} {
1208 set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1213 if {$_prefix ne {}} {
1214 if {$_gitworktree eq {}} {
1215 regsub -all {[^/]+/} $_prefix ../ cdup
1216 } else {
1217 set cdup $_gitworktree
1219 if {[catch {cd $cdup} err]} {
1220 catch {wm withdraw .}
1221 error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
1222 exit 1
1224 set _gitworktree [pwd]
1225 unset cdup
1226 } elseif {![is_enabled bare]} {
1227 if {[is_bare]} {
1228 catch {wm withdraw .}
1229 error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
1230 exit 1
1232 if {$_gitworktree eq {}} {
1233 set _gitworktree [file dirname $_gitdir]
1235 if {[catch {cd $_gitworktree} err]} {
1236 catch {wm withdraw .}
1237 error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
1238 exit 1
1240 set _gitworktree [pwd]
1242 set _reponame [file split [file normalize $_gitdir]]
1243 if {[lindex $_reponame end] eq {.git}} {
1244 set _reponame [lindex $_reponame end-1]
1245 } else {
1246 set _reponame [lindex $_reponame end]
1249 set env(GIT_DIR) $_gitdir
1250 set env(GIT_WORK_TREE) $_gitworktree
1252 ######################################################################
1254 ## global init
1256 set current_diff_path {}
1257 set current_diff_side {}
1258 set diff_actions [list]
1260 set HEAD {}
1261 set PARENT {}
1262 set MERGE_HEAD [list]
1263 set commit_type {}
1264 set empty_tree {}
1265 set current_branch {}
1266 set is_detached 0
1267 set current_diff_path {}
1268 set is_3way_diff 0
1269 set is_submodule_diff 0
1270 set is_conflict_diff 0
1271 set selected_commit_type new
1272 set diff_empty_count 0
1274 set nullid "0000000000000000000000000000000000000000"
1275 set nullid2 "0000000000000000000000000000000000000001"
1277 ######################################################################
1279 ## task management
1281 set rescan_active 0
1282 set diff_active 0
1283 set last_clicked {}
1285 set disable_on_lock [list]
1286 set index_lock_type none
1288 proc lock_index {type} {
1289 global index_lock_type disable_on_lock
1291 if {$index_lock_type eq {none}} {
1292 set index_lock_type $type
1293 foreach w $disable_on_lock {
1294 uplevel #0 $w disabled
1296 return 1
1297 } elseif {$index_lock_type eq "begin-$type"} {
1298 set index_lock_type $type
1299 return 1
1301 return 0
1304 proc unlock_index {} {
1305 global index_lock_type disable_on_lock
1307 set index_lock_type none
1308 foreach w $disable_on_lock {
1309 uplevel #0 $w normal
1313 ######################################################################
1315 ## status
1317 proc repository_state {ctvar hdvar mhvar} {
1318 global current_branch
1319 upvar $ctvar ct $hdvar hd $mhvar mh
1321 set mh [list]
1323 load_current_branch
1324 if {[catch {set hd [git rev-parse --verify HEAD]}]} {
1325 set hd {}
1326 set ct initial
1327 return
1330 set merge_head [gitdir MERGE_HEAD]
1331 if {[file exists $merge_head]} {
1332 set ct merge
1333 set fd_mh [open $merge_head r]
1334 while {[gets $fd_mh line] >= 0} {
1335 lappend mh $line
1337 close $fd_mh
1338 return
1341 set ct normal
1344 proc PARENT {} {
1345 global PARENT empty_tree
1347 set p [lindex $PARENT 0]
1348 if {$p ne {}} {
1349 return $p
1351 if {$empty_tree eq {}} {
1352 set empty_tree [git mktree << {}]
1354 return $empty_tree
1357 proc force_amend {} {
1358 global selected_commit_type
1359 global HEAD PARENT MERGE_HEAD commit_type
1361 repository_state newType newHEAD newMERGE_HEAD
1362 set HEAD $newHEAD
1363 set PARENT $newHEAD
1364 set MERGE_HEAD $newMERGE_HEAD
1365 set commit_type $newType
1367 set selected_commit_type amend
1368 do_select_commit_type
1371 proc rescan {after {honor_trustmtime 1}} {
1372 global HEAD PARENT MERGE_HEAD commit_type
1373 global ui_index ui_workdir ui_comm
1374 global rescan_active file_states
1375 global repo_config
1377 if {$rescan_active > 0 || ![lock_index read]} return
1379 repository_state newType newHEAD newMERGE_HEAD
1380 if {[string match amend* $commit_type]
1381 && $newType eq {normal}
1382 && $newHEAD eq $HEAD} {
1383 } else {
1384 set HEAD $newHEAD
1385 set PARENT $newHEAD
1386 set MERGE_HEAD $newMERGE_HEAD
1387 set commit_type $newType
1390 array unset file_states
1392 if {!$::GITGUI_BCK_exists &&
1393 (![$ui_comm edit modified]
1394 || [string trim [$ui_comm get 0.0 end]] eq {})} {
1395 if {[string match amend* $commit_type]} {
1396 } elseif {[load_message GITGUI_MSG]} {
1397 } elseif {[run_prepare_commit_msg_hook]} {
1398 } elseif {[load_message MERGE_MSG]} {
1399 } elseif {[load_message SQUASH_MSG]} {
1401 $ui_comm edit reset
1402 $ui_comm edit modified false
1405 if {$honor_trustmtime && $repo_config(gui.trustmtime) eq {true}} {
1406 rescan_stage2 {} $after
1407 } else {
1408 set rescan_active 1
1409 ui_status [mc "Refreshing file status..."]
1410 set fd_rf [git_read update-index \
1411 -q \
1412 --unmerged \
1413 --ignore-missing \
1414 --refresh \
1416 fconfigure $fd_rf -blocking 0 -translation binary
1417 fileevent $fd_rf readable \
1418 [list rescan_stage2 $fd_rf $after]
1422 if {[is_Cygwin]} {
1423 set is_git_info_exclude {}
1424 proc have_info_exclude {} {
1425 global is_git_info_exclude
1427 if {$is_git_info_exclude eq {}} {
1428 if {[catch {exec test -f [gitdir info exclude]}]} {
1429 set is_git_info_exclude 0
1430 } else {
1431 set is_git_info_exclude 1
1434 return $is_git_info_exclude
1436 } else {
1437 proc have_info_exclude {} {
1438 return [file readable [gitdir info exclude]]
1442 proc rescan_stage2 {fd after} {
1443 global rescan_active buf_rdi buf_rdf buf_rlo
1445 if {$fd ne {}} {
1446 read $fd
1447 if {![eof $fd]} return
1448 close $fd
1451 set ls_others [list --exclude-per-directory=.gitignore]
1452 if {[have_info_exclude]} {
1453 lappend ls_others "--exclude-from=[gitdir info exclude]"
1455 set user_exclude [get_config core.excludesfile]
1456 if {$user_exclude ne {} && [file readable $user_exclude]} {
1457 lappend ls_others "--exclude-from=$user_exclude"
1460 set buf_rdi {}
1461 set buf_rdf {}
1462 set buf_rlo {}
1464 set rescan_active 3
1465 ui_status [mc "Scanning for modified files ..."]
1466 set fd_di [git_read diff-index --cached -z [PARENT]]
1467 set fd_df [git_read diff-files -z]
1468 set fd_lo [eval git_read ls-files --others -z $ls_others]
1470 fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1471 fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1472 fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1473 fileevent $fd_di readable [list read_diff_index $fd_di $after]
1474 fileevent $fd_df readable [list read_diff_files $fd_df $after]
1475 fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
1478 proc load_message {file} {
1479 global ui_comm
1481 set f [gitdir $file]
1482 if {[file isfile $f]} {
1483 if {[catch {set fd [open $f r]}]} {
1484 return 0
1486 fconfigure $fd -eofchar {}
1487 set content [string trim [read $fd]]
1488 close $fd
1489 regsub -all -line {[ \r\t]+$} $content {} content
1490 $ui_comm delete 0.0 end
1491 $ui_comm insert end $content
1492 return 1
1494 return 0
1497 proc run_prepare_commit_msg_hook {} {
1498 global pch_error
1500 # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui
1501 # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
1502 # empty file but existant file.
1504 set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
1506 if {[file isfile [gitdir MERGE_MSG]]} {
1507 set pcm_source "merge"
1508 set fd_mm [open [gitdir MERGE_MSG] r]
1509 puts -nonewline $fd_pcm [read $fd_mm]
1510 close $fd_mm
1511 } elseif {[file isfile [gitdir SQUASH_MSG]]} {
1512 set pcm_source "squash"
1513 set fd_sm [open [gitdir SQUASH_MSG] r]
1514 puts -nonewline $fd_pcm [read $fd_sm]
1515 close $fd_sm
1516 } else {
1517 set pcm_source ""
1520 close $fd_pcm
1522 set fd_ph [githook_read prepare-commit-msg \
1523 [gitdir PREPARE_COMMIT_MSG] $pcm_source]
1524 if {$fd_ph eq {}} {
1525 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1526 return 0;
1529 ui_status [mc "Calling prepare-commit-msg hook..."]
1530 set pch_error {}
1532 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1533 fileevent $fd_ph readable \
1534 [list prepare_commit_msg_hook_wait $fd_ph]
1536 return 1;
1539 proc prepare_commit_msg_hook_wait {fd_ph} {
1540 global pch_error
1542 append pch_error [read $fd_ph]
1543 fconfigure $fd_ph -blocking 1
1544 if {[eof $fd_ph]} {
1545 if {[catch {close $fd_ph}]} {
1546 ui_status [mc "Commit declined by prepare-commit-msg hook."]
1547 hook_failed_popup prepare-commit-msg $pch_error
1548 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1549 exit 1
1550 } else {
1551 load_message PREPARE_COMMIT_MSG
1553 set pch_error {}
1554 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1555 return
1557 fconfigure $fd_ph -blocking 0
1558 catch {file delete [gitdir PREPARE_COMMIT_MSG]}
1561 proc read_diff_index {fd after} {
1562 global buf_rdi
1564 append buf_rdi [read $fd]
1565 set c 0
1566 set n [string length $buf_rdi]
1567 while {$c < $n} {
1568 set z1 [string first "\0" $buf_rdi $c]
1569 if {$z1 == -1} break
1570 incr z1
1571 set z2 [string first "\0" $buf_rdi $z1]
1572 if {$z2 == -1} break
1574 incr c
1575 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1576 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1577 merge_state \
1578 [encoding convertfrom $p] \
1579 [lindex $i 4]? \
1580 [list [lindex $i 0] [lindex $i 2]] \
1581 [list]
1582 set c $z2
1583 incr c
1585 if {$c < $n} {
1586 set buf_rdi [string range $buf_rdi $c end]
1587 } else {
1588 set buf_rdi {}
1591 rescan_done $fd buf_rdi $after
1594 proc read_diff_files {fd after} {
1595 global buf_rdf
1597 append buf_rdf [read $fd]
1598 set c 0
1599 set n [string length $buf_rdf]
1600 while {$c < $n} {
1601 set z1 [string first "\0" $buf_rdf $c]
1602 if {$z1 == -1} break
1603 incr z1
1604 set z2 [string first "\0" $buf_rdf $z1]
1605 if {$z2 == -1} break
1607 incr c
1608 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1609 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1610 merge_state \
1611 [encoding convertfrom $p] \
1612 ?[lindex $i 4] \
1613 [list] \
1614 [list [lindex $i 0] [lindex $i 2]]
1615 set c $z2
1616 incr c
1618 if {$c < $n} {
1619 set buf_rdf [string range $buf_rdf $c end]
1620 } else {
1621 set buf_rdf {}
1624 rescan_done $fd buf_rdf $after
1627 proc read_ls_others {fd after} {
1628 global buf_rlo
1630 append buf_rlo [read $fd]
1631 set pck [split $buf_rlo "\0"]
1632 set buf_rlo [lindex $pck end]
1633 foreach p [lrange $pck 0 end-1] {
1634 set p [encoding convertfrom $p]
1635 if {[string index $p end] eq {/}} {
1636 set p [string range $p 0 end-1]
1638 merge_state $p ?O
1640 rescan_done $fd buf_rlo $after
1643 proc rescan_done {fd buf after} {
1644 global rescan_active current_diff_path
1645 global file_states repo_config
1646 upvar $buf to_clear
1648 if {![eof $fd]} return
1649 set to_clear {}
1650 close $fd
1651 if {[incr rescan_active -1] > 0} return
1653 prune_selection
1654 unlock_index
1655 display_all_files
1656 if {$current_diff_path ne {}} { reshow_diff $after }
1657 if {$current_diff_path eq {}} { select_first_diff $after }
1660 proc prune_selection {} {
1661 global file_states selected_paths
1663 foreach path [array names selected_paths] {
1664 if {[catch {set still_here $file_states($path)}]} {
1665 unset selected_paths($path)
1670 ######################################################################
1672 ## ui helpers
1674 proc mapicon {w state path} {
1675 global all_icons
1677 if {[catch {set r $all_icons($state$w)}]} {
1678 puts "error: no icon for $w state={$state} $path"
1679 return file_plain
1681 return $r
1684 proc mapdesc {state path} {
1685 global all_descs
1687 if {[catch {set r $all_descs($state)}]} {
1688 puts "error: no desc for state={$state} $path"
1689 return $state
1691 return $r
1694 proc ui_status {msg} {
1695 global main_status
1696 if {[info exists main_status]} {
1697 $main_status show $msg
1701 proc ui_ready {{test {}}} {
1702 global main_status
1703 if {[info exists main_status]} {
1704 $main_status show [mc "Ready."] $test
1708 proc escape_path {path} {
1709 regsub -all {\\} $path "\\\\" path
1710 regsub -all "\n" $path "\\n" path
1711 return $path
1714 proc short_path {path} {
1715 return [escape_path [lindex [file split $path] end]]
1718 set next_icon_id 0
1719 set null_sha1 [string repeat 0 40]
1721 proc merge_state {path new_state {head_info {}} {index_info {}}} {
1722 global file_states next_icon_id null_sha1
1724 set s0 [string index $new_state 0]
1725 set s1 [string index $new_state 1]
1727 if {[catch {set info $file_states($path)}]} {
1728 set state __
1729 set icon n[incr next_icon_id]
1730 } else {
1731 set state [lindex $info 0]
1732 set icon [lindex $info 1]
1733 if {$head_info eq {}} {set head_info [lindex $info 2]}
1734 if {$index_info eq {}} {set index_info [lindex $info 3]}
1737 if {$s0 eq {?}} {set s0 [string index $state 0]} \
1738 elseif {$s0 eq {_}} {set s0 _}
1740 if {$s1 eq {?}} {set s1 [string index $state 1]} \
1741 elseif {$s1 eq {_}} {set s1 _}
1743 if {$s0 eq {A} && $s1 eq {_} && $head_info eq {}} {
1744 set head_info [list 0 $null_sha1]
1745 } elseif {$s0 ne {_} && [string index $state 0] eq {_}
1746 && $head_info eq {}} {
1747 set head_info $index_info
1748 } elseif {$s0 eq {_} && [string index $state 0] ne {_}} {
1749 set index_info $head_info
1750 set head_info {}
1753 set file_states($path) [list $s0$s1 $icon \
1754 $head_info $index_info \
1756 return $state
1759 proc display_file_helper {w path icon_name old_m new_m} {
1760 global file_lists
1762 if {$new_m eq {_}} {
1763 set lno [lsearch -sorted -exact $file_lists($w) $path]
1764 if {$lno >= 0} {
1765 set file_lists($w) [lreplace $file_lists($w) $lno $lno]
1766 incr lno
1767 $w conf -state normal
1768 $w delete $lno.0 [expr {$lno + 1}].0
1769 $w conf -state disabled
1771 } elseif {$old_m eq {_} && $new_m ne {_}} {
1772 lappend file_lists($w) $path
1773 set file_lists($w) [lsort -unique $file_lists($w)]
1774 set lno [lsearch -sorted -exact $file_lists($w) $path]
1775 incr lno
1776 $w conf -state normal
1777 $w image create $lno.0 \
1778 -align center -padx 5 -pady 1 \
1779 -name $icon_name \
1780 -image [mapicon $w $new_m $path]
1781 $w insert $lno.1 "[escape_path $path]\n"
1782 $w conf -state disabled
1783 } elseif {$old_m ne $new_m} {
1784 $w conf -state normal
1785 $w image conf $icon_name -image [mapicon $w $new_m $path]
1786 $w conf -state disabled
1790 proc display_file {path state} {
1791 global file_states selected_paths
1792 global ui_index ui_workdir
1794 set old_m [merge_state $path $state]
1795 set s $file_states($path)
1796 set new_m [lindex $s 0]
1797 set icon_name [lindex $s 1]
1799 set o [string index $old_m 0]
1800 set n [string index $new_m 0]
1801 if {$o eq {U}} {
1802 set o _
1804 if {$n eq {U}} {
1805 set n _
1807 display_file_helper $ui_index $path $icon_name $o $n
1809 if {[string index $old_m 0] eq {U}} {
1810 set o U
1811 } else {
1812 set o [string index $old_m 1]
1814 if {[string index $new_m 0] eq {U}} {
1815 set n U
1816 } else {
1817 set n [string index $new_m 1]
1819 display_file_helper $ui_workdir $path $icon_name $o $n
1821 if {$new_m eq {__}} {
1822 unset file_states($path)
1823 catch {unset selected_paths($path)}
1827 proc display_all_files_helper {w path icon_name m} {
1828 global file_lists
1830 lappend file_lists($w) $path
1831 set lno [expr {[lindex [split [$w index end] .] 0] - 1}]
1832 $w image create end \
1833 -align center -padx 5 -pady 1 \
1834 -name $icon_name \
1835 -image [mapicon $w $m $path]
1836 $w insert end "[escape_path $path]\n"
1839 set files_warning 0
1840 proc display_all_files {} {
1841 global ui_index ui_workdir
1842 global file_states file_lists
1843 global last_clicked
1844 global files_warning
1846 $ui_index conf -state normal
1847 $ui_workdir conf -state normal
1849 $ui_index delete 0.0 end
1850 $ui_workdir delete 0.0 end
1851 set last_clicked {}
1853 set file_lists($ui_index) [list]
1854 set file_lists($ui_workdir) [list]
1856 set to_display [lsort [array names file_states]]
1857 set display_limit [get_config gui.maxfilesdisplayed]
1858 if {[llength $to_display] > $display_limit} {
1859 if {!$files_warning} {
1860 # do not repeatedly warn:
1861 set files_warning 1
1862 info_popup [mc "Displaying only %s of %s files." \
1863 $display_limit [llength $to_display]]
1865 set to_display [lrange $to_display 0 [expr {$display_limit-1}]]
1867 foreach path $to_display {
1868 set s $file_states($path)
1869 set m [lindex $s 0]
1870 set icon_name [lindex $s 1]
1872 set s [string index $m 0]
1873 if {$s ne {U} && $s ne {_}} {
1874 display_all_files_helper $ui_index $path \
1875 $icon_name $s
1878 if {[string index $m 0] eq {U}} {
1879 set s U
1880 } else {
1881 set s [string index $m 1]
1883 if {$s ne {_}} {
1884 display_all_files_helper $ui_workdir $path \
1885 $icon_name $s
1889 $ui_index conf -state disabled
1890 $ui_workdir conf -state disabled
1893 ######################################################################
1895 ## icons
1897 set filemask {
1898 #define mask_width 14
1899 #define mask_height 15
1900 static unsigned char mask_bits[] = {
1901 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1902 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f,
1903 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f};
1906 image create bitmap file_plain -background white -foreground black -data {
1907 #define plain_width 14
1908 #define plain_height 15
1909 static unsigned char plain_bits[] = {
1910 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1911 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10, 0x02, 0x10,
1912 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1913 } -maskdata $filemask
1915 image create bitmap file_mod -background white -foreground blue -data {
1916 #define mod_width 14
1917 #define mod_height 15
1918 static unsigned char mod_bits[] = {
1919 0xfe, 0x01, 0x02, 0x03, 0x7a, 0x05, 0x02, 0x09, 0x7a, 0x1f, 0x02, 0x10,
1920 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1921 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1922 } -maskdata $filemask
1924 image create bitmap file_fulltick -background white -foreground "#007000" -data {
1925 #define file_fulltick_width 14
1926 #define file_fulltick_height 15
1927 static unsigned char file_fulltick_bits[] = {
1928 0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
1929 0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
1930 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1931 } -maskdata $filemask
1933 image create bitmap file_question -background white -foreground black -data {
1934 #define file_question_width 14
1935 #define file_question_height 15
1936 static unsigned char file_question_bits[] = {
1937 0xfe, 0x01, 0x02, 0x02, 0xe2, 0x04, 0xf2, 0x09, 0x1a, 0x1b, 0x0a, 0x13,
1938 0x82, 0x11, 0xc2, 0x10, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10, 0x62, 0x10,
1939 0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1940 } -maskdata $filemask
1942 image create bitmap file_removed -background white -foreground red -data {
1943 #define file_removed_width 14
1944 #define file_removed_height 15
1945 static unsigned char file_removed_bits[] = {
1946 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x02, 0x10,
1947 0x1a, 0x16, 0x32, 0x13, 0xe2, 0x11, 0xc2, 0x10, 0xe2, 0x11, 0x32, 0x13,
1948 0x1a, 0x16, 0x02, 0x10, 0xfe, 0x1f};
1949 } -maskdata $filemask
1951 image create bitmap file_merge -background white -foreground blue -data {
1952 #define file_merge_width 14
1953 #define file_merge_height 15
1954 static unsigned char file_merge_bits[] = {
1955 0xfe, 0x01, 0x02, 0x03, 0x62, 0x05, 0x62, 0x09, 0x62, 0x1f, 0x62, 0x10,
1956 0xfa, 0x11, 0xf2, 0x10, 0x62, 0x10, 0x02, 0x10, 0xfa, 0x17, 0x02, 0x10,
1957 0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
1958 } -maskdata $filemask
1960 image create bitmap file_statechange -background white -foreground green -data {
1961 #define file_merge_width 14
1962 #define file_merge_height 15
1963 static unsigned char file_statechange_bits[] = {
1964 0xfe, 0x01, 0x02, 0x03, 0x02, 0x05, 0x02, 0x09, 0x02, 0x1f, 0x62, 0x10,
1965 0x62, 0x10, 0xba, 0x11, 0xba, 0x11, 0x62, 0x10, 0x62, 0x10, 0x02, 0x10,
1966 0x02, 0x10, 0x02, 0x10, 0xfe, 0x1f};
1967 } -maskdata $filemask
1969 set ui_index .vpane.files.index.list
1970 set ui_workdir .vpane.files.workdir.list
1972 set all_icons(_$ui_index) file_plain
1973 set all_icons(A$ui_index) file_plain
1974 set all_icons(M$ui_index) file_fulltick
1975 set all_icons(D$ui_index) file_removed
1976 set all_icons(U$ui_index) file_merge
1977 set all_icons(T$ui_index) file_statechange
1979 set all_icons(_$ui_workdir) file_plain
1980 set all_icons(M$ui_workdir) file_mod
1981 set all_icons(D$ui_workdir) file_question
1982 set all_icons(U$ui_workdir) file_merge
1983 set all_icons(O$ui_workdir) file_plain
1984 set all_icons(T$ui_workdir) file_statechange
1986 set max_status_desc 0
1987 foreach i {
1988 {__ {mc "Unmodified"}}
1990 {_M {mc "Modified, not staged"}}
1991 {M_ {mc "Staged for commit"}}
1992 {MM {mc "Portions staged for commit"}}
1993 {MD {mc "Staged for commit, missing"}}
1995 {_T {mc "File type changed, not staged"}}
1996 {T_ {mc "File type changed, staged"}}
1998 {_O {mc "Untracked, not staged"}}
1999 {A_ {mc "Staged for commit"}}
2000 {AM {mc "Portions staged for commit"}}
2001 {AD {mc "Staged for commit, missing"}}
2003 {_D {mc "Missing"}}
2004 {D_ {mc "Staged for removal"}}
2005 {DO {mc "Staged for removal, still present"}}
2007 {_U {mc "Requires merge resolution"}}
2008 {U_ {mc "Requires merge resolution"}}
2009 {UU {mc "Requires merge resolution"}}
2010 {UM {mc "Requires merge resolution"}}
2011 {UD {mc "Requires merge resolution"}}
2012 {UT {mc "Requires merge resolution"}}
2014 set text [eval [lindex $i 1]]
2015 if {$max_status_desc < [string length $text]} {
2016 set max_status_desc [string length $text]
2018 set all_descs([lindex $i 0]) $text
2020 unset i
2022 ######################################################################
2024 ## util
2026 proc scrollbar2many {list mode args} {
2027 foreach w $list {eval $w $mode $args}
2030 proc many2scrollbar {list mode sb top bottom} {
2031 $sb set $top $bottom
2032 foreach w $list {$w $mode moveto $top}
2035 proc incr_font_size {font {amt 1}} {
2036 set sz [font configure $font -size]
2037 incr sz $amt
2038 font configure $font -size $sz
2039 font configure ${font}bold -size $sz
2040 font configure ${font}italic -size $sz
2043 ######################################################################
2045 ## ui commands
2047 set starting_gitk_msg [mc "Starting gitk... please wait..."]
2049 proc do_gitk {revs {is_submodule false}} {
2050 global current_diff_path file_states current_diff_side ui_index
2051 global _gitdir _gitworktree
2053 # -- Always start gitk through whatever we were loaded with. This
2054 # lets us bypass using shell process on Windows systems.
2056 set exe [_which gitk -script]
2057 set cmd [list [info nameofexecutable] $exe]
2058 if {$exe eq {}} {
2059 error_popup [mc "Couldn't find gitk in PATH"]
2060 } else {
2061 global env
2063 set pwd [pwd]
2065 if {!$is_submodule} {
2066 if {![is_bare]} {
2067 cd $_gitworktree
2069 } else {
2070 cd $current_diff_path
2071 if {$revs eq {--}} {
2072 set s $file_states($current_diff_path)
2073 set old_sha1 {}
2074 set new_sha1 {}
2075 switch -glob -- [lindex $s 0] {
2076 M_ { set old_sha1 [lindex [lindex $s 2] 1] }
2077 _M { set old_sha1 [lindex [lindex $s 3] 1] }
2078 MM {
2079 if {$current_diff_side eq $ui_index} {
2080 set old_sha1 [lindex [lindex $s 2] 1]
2081 set new_sha1 [lindex [lindex $s 3] 1]
2082 } else {
2083 set old_sha1 [lindex [lindex $s 3] 1]
2087 set revs $old_sha1...$new_sha1
2089 # GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2090 # we've been using for the main repository, so unset them.
2091 # TODO we could make life easier (start up faster?) for gitk
2092 # by setting these to the appropriate values to allow gitk
2093 # to skip the heuristics to find their proper value
2094 unset env(GIT_DIR)
2095 unset env(GIT_WORK_TREE)
2097 eval exec $cmd $revs "--" "--" &
2099 set env(GIT_DIR) $_gitdir
2100 set env(GIT_WORK_TREE) $_gitworktree
2101 cd $pwd
2103 ui_status $::starting_gitk_msg
2104 after 10000 {
2105 ui_ready $starting_gitk_msg
2110 proc do_git_gui {} {
2111 global current_diff_path
2113 # -- Always start git gui through whatever we were loaded with. This
2114 # lets us bypass using shell process on Windows systems.
2116 set exe [list [_which git]]
2117 if {$exe eq {}} {
2118 error_popup [mc "Couldn't find git gui in PATH"]
2119 } else {
2120 global env
2121 global _gitdir _gitworktree
2123 # see note in do_gitk about unsetting these vars when
2124 # running tools in a submodule
2125 unset env(GIT_DIR)
2126 unset env(GIT_WORK_TREE)
2128 set pwd [pwd]
2129 cd $current_diff_path
2131 eval exec $exe gui &
2133 set env(GIT_DIR) $_gitdir
2134 set env(GIT_WORK_TREE) $_gitworktree
2135 cd $pwd
2137 ui_status $::starting_gitk_msg
2138 after 10000 {
2139 ui_ready $starting_gitk_msg
2144 proc do_explore {} {
2145 global _gitworktree
2146 set explorer {}
2147 if {[is_Cygwin] || [is_Windows]} {
2148 set explorer "explorer.exe"
2149 } elseif {[is_MacOSX]} {
2150 set explorer "open"
2151 } else {
2152 # freedesktop.org-conforming system is our best shot
2153 set explorer "xdg-open"
2155 eval exec $explorer [list [file nativename $_gitworktree]] &
2158 set is_quitting 0
2159 set ret_code 1
2161 proc terminate_me {win} {
2162 global ret_code
2163 if {$win ne {.}} return
2164 exit $ret_code
2167 proc do_quit {{rc {1}}} {
2168 global ui_comm is_quitting repo_config commit_type
2169 global GITGUI_BCK_exists GITGUI_BCK_i
2170 global ui_comm_spell
2171 global ret_code use_ttk
2173 if {$is_quitting} return
2174 set is_quitting 1
2176 if {[winfo exists $ui_comm]} {
2177 # -- Stash our current commit buffer.
2179 set save [gitdir GITGUI_MSG]
2180 if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
2181 file rename -force [gitdir GITGUI_BCK] $save
2182 set GITGUI_BCK_exists 0
2183 } else {
2184 set msg [string trim [$ui_comm get 0.0 end]]
2185 regsub -all -line {[ \r\t]+$} $msg {} msg
2186 if {(![string match amend* $commit_type]
2187 || [$ui_comm edit modified])
2188 && $msg ne {}} {
2189 catch {
2190 set fd [open $save w]
2191 puts -nonewline $fd $msg
2192 close $fd
2194 } else {
2195 catch {file delete $save}
2199 # -- Cancel our spellchecker if its running.
2201 if {[info exists ui_comm_spell]} {
2202 $ui_comm_spell stop
2205 # -- Remove our editor backup, its not needed.
2207 after cancel $GITGUI_BCK_i
2208 if {$GITGUI_BCK_exists} {
2209 catch {file delete [gitdir GITGUI_BCK]}
2212 # -- Stash our current window geometry into this repository.
2214 set cfg_wmstate [wm state .]
2215 if {[catch {set rc_wmstate $repo_config(gui.wmstate)}]} {
2216 set rc_wmstate {}
2218 if {$cfg_wmstate ne $rc_wmstate} {
2219 catch {git config gui.wmstate $cfg_wmstate}
2221 if {$cfg_wmstate eq {zoomed}} {
2222 # on Windows wm geometry will lie about window
2223 # position (but not size) when window is zoomed
2224 # restore the window before querying wm geometry
2225 wm state . normal
2227 set cfg_geometry [list]
2228 lappend cfg_geometry [wm geometry .]
2229 if {$use_ttk} {
2230 lappend cfg_geometry [.vpane sashpos 0]
2231 lappend cfg_geometry [.vpane.files sashpos 0]
2232 } else {
2233 lappend cfg_geometry [lindex [.vpane sash coord 0] 0]
2234 lappend cfg_geometry [lindex [.vpane.files sash coord 0] 1]
2236 if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
2237 set rc_geometry {}
2239 if {$cfg_geometry ne $rc_geometry} {
2240 catch {git config gui.geometry $cfg_geometry}
2244 set ret_code $rc
2246 # Briefly enable send again, working around Tk bug
2247 # http://sourceforge.net/tracker/?func=detail&atid=112997&aid=1821174&group_id=12997
2248 tk appname [appname]
2250 destroy .
2253 proc do_rescan {} {
2254 rescan ui_ready
2257 proc ui_do_rescan {} {
2258 rescan {force_first_diff ui_ready}
2261 proc do_commit {} {
2262 commit_tree
2265 proc next_diff {{after {}}} {
2266 global next_diff_p next_diff_w next_diff_i
2267 show_diff $next_diff_p $next_diff_w {} {} $after
2270 proc find_anchor_pos {lst name} {
2271 set lid [lsearch -sorted -exact $lst $name]
2273 if {$lid == -1} {
2274 set lid 0
2275 foreach lname $lst {
2276 if {$lname >= $name} break
2277 incr lid
2281 return $lid
2284 proc find_file_from {flist idx delta path mmask} {
2285 global file_states
2287 set len [llength $flist]
2288 while {$idx >= 0 && $idx < $len} {
2289 set name [lindex $flist $idx]
2291 if {$name ne $path && [info exists file_states($name)]} {
2292 set state [lindex $file_states($name) 0]
2294 if {$mmask eq {} || [regexp $mmask $state]} {
2295 return $idx
2299 incr idx $delta
2302 return {}
2305 proc find_next_diff {w path {lno {}} {mmask {}}} {
2306 global next_diff_p next_diff_w next_diff_i
2307 global file_lists ui_index ui_workdir
2309 set flist $file_lists($w)
2310 if {$lno eq {}} {
2311 set lno [find_anchor_pos $flist $path]
2312 } else {
2313 incr lno -1
2316 if {$mmask ne {} && ![regexp {(^\^)|(\$$)} $mmask]} {
2317 if {$w eq $ui_index} {
2318 set mmask "^$mmask"
2319 } else {
2320 set mmask "$mmask\$"
2324 set idx [find_file_from $flist $lno 1 $path $mmask]
2325 if {$idx eq {}} {
2326 incr lno -1
2327 set idx [find_file_from $flist $lno -1 $path $mmask]
2330 if {$idx ne {}} {
2331 set next_diff_w $w
2332 set next_diff_p [lindex $flist $idx]
2333 set next_diff_i [expr {$idx+1}]
2334 return 1
2335 } else {
2336 return 0
2340 proc next_diff_after_action {w path {lno {}} {mmask {}}} {
2341 global current_diff_path
2343 if {$path ne $current_diff_path} {
2344 return {}
2345 } elseif {[find_next_diff $w $path $lno $mmask]} {
2346 return {next_diff;}
2347 } else {
2348 return {reshow_diff;}
2352 proc select_first_diff {after} {
2353 global ui_workdir
2355 if {[find_next_diff $ui_workdir {} 1 {^_?U}] ||
2356 [find_next_diff $ui_workdir {} 1 {[^O]$}]} {
2357 next_diff $after
2358 } else {
2359 uplevel #0 $after
2363 proc force_first_diff {after} {
2364 global ui_workdir current_diff_path file_states
2366 if {[info exists file_states($current_diff_path)]} {
2367 set state [lindex $file_states($current_diff_path) 0]
2368 } else {
2369 set state {OO}
2372 set reselect 0
2373 if {[string first {U} $state] >= 0} {
2374 # Already a conflict, do nothing
2375 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {^_?U}]} {
2376 set reselect 1
2377 } elseif {[string index $state 1] ne {O}} {
2378 # Already a diff & no conflicts, do nothing
2379 } elseif {[find_next_diff $ui_workdir $current_diff_path {} {[^O]$}]} {
2380 set reselect 1
2383 if {$reselect} {
2384 next_diff $after
2385 } else {
2386 uplevel #0 $after
2390 proc toggle_or_diff {w x y} {
2391 global file_states file_lists current_diff_path ui_index ui_workdir
2392 global last_clicked selected_paths
2394 set pos [split [$w index @$x,$y] .]
2395 set lno [lindex $pos 0]
2396 set col [lindex $pos 1]
2397 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2398 if {$path eq {}} {
2399 set last_clicked {}
2400 return
2403 set last_clicked [list $w $lno]
2404 array unset selected_paths
2405 $ui_index tag remove in_sel 0.0 end
2406 $ui_workdir tag remove in_sel 0.0 end
2408 # Determine the state of the file
2409 if {[info exists file_states($path)]} {
2410 set state [lindex $file_states($path) 0]
2411 } else {
2412 set state {__}
2415 # Restage the file, or simply show the diff
2416 if {$col == 0 && $y > 1} {
2417 # Conflicts need special handling
2418 if {[string first {U} $state] >= 0} {
2419 # $w must always be $ui_workdir, but...
2420 if {$w ne $ui_workdir} { set lno {} }
2421 merge_stage_workdir $path $lno
2422 return
2425 if {[string index $state 1] eq {O}} {
2426 set mmask {}
2427 } else {
2428 set mmask {[^O]}
2431 set after [next_diff_after_action $w $path $lno $mmask]
2433 if {$w eq $ui_index} {
2434 update_indexinfo \
2435 "Unstaging [short_path $path] from commit" \
2436 [list $path] \
2437 [concat $after [list ui_ready]]
2438 } elseif {$w eq $ui_workdir} {
2439 update_index \
2440 "Adding [short_path $path]" \
2441 [list $path] \
2442 [concat $after [list ui_ready]]
2444 } else {
2445 show_diff $path $w $lno
2449 proc add_one_to_selection {w x y} {
2450 global file_lists last_clicked selected_paths
2452 set lno [lindex [split [$w index @$x,$y] .] 0]
2453 set path [lindex $file_lists($w) [expr {$lno - 1}]]
2454 if {$path eq {}} {
2455 set last_clicked {}
2456 return
2459 if {$last_clicked ne {}
2460 && [lindex $last_clicked 0] ne $w} {
2461 array unset selected_paths
2462 [lindex $last_clicked 0] tag remove in_sel 0.0 end
2465 set last_clicked [list $w $lno]
2466 if {[catch {set in_sel $selected_paths($path)}]} {
2467 set in_sel 0
2469 if {$in_sel} {
2470 unset selected_paths($path)
2471 $w tag remove in_sel $lno.0 [expr {$lno + 1}].0
2472 } else {
2473 set selected_paths($path) 1
2474 $w tag add in_sel $lno.0 [expr {$lno + 1}].0
2478 proc add_range_to_selection {w x y} {
2479 global file_lists last_clicked selected_paths
2481 if {[lindex $last_clicked 0] ne $w} {
2482 toggle_or_diff $w $x $y
2483 return
2486 set lno [lindex [split [$w index @$x,$y] .] 0]
2487 set lc [lindex $last_clicked 1]
2488 if {$lc < $lno} {
2489 set begin $lc
2490 set end $lno
2491 } else {
2492 set begin $lno
2493 set end $lc
2496 foreach path [lrange $file_lists($w) \
2497 [expr {$begin - 1}] \
2498 [expr {$end - 1}]] {
2499 set selected_paths($path) 1
2501 $w tag add in_sel $begin.0 [expr {$end + 1}].0
2504 proc show_more_context {} {
2505 global repo_config
2506 if {$repo_config(gui.diffcontext) < 99} {
2507 incr repo_config(gui.diffcontext)
2508 reshow_diff
2512 proc show_less_context {} {
2513 global repo_config
2514 if {$repo_config(gui.diffcontext) > 1} {
2515 incr repo_config(gui.diffcontext) -1
2516 reshow_diff
2520 ######################################################################
2522 ## ui construction
2524 set ui_comm {}
2526 # -- Menu Bar
2528 menu .mbar -tearoff 0
2529 if {[is_MacOSX]} {
2530 # -- Apple Menu (Mac OS X only)
2532 .mbar add cascade -label Apple -menu .mbar.apple
2533 menu .mbar.apple
2535 .mbar add cascade -label [mc Repository] -menu .mbar.repository
2536 .mbar add cascade -label [mc Edit] -menu .mbar.edit
2537 if {[is_enabled branch]} {
2538 .mbar add cascade -label [mc Branch] -menu .mbar.branch
2540 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2541 .mbar add cascade -label [mc Commit@@noun] -menu .mbar.commit
2543 if {[is_enabled transport]} {
2544 .mbar add cascade -label [mc Merge] -menu .mbar.merge
2545 .mbar add cascade -label [mc Remote] -menu .mbar.remote
2547 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2548 .mbar add cascade -label [mc Tools] -menu .mbar.tools
2551 # -- Repository Menu
2553 menu .mbar.repository
2555 if {![is_bare]} {
2556 .mbar.repository add command \
2557 -label [mc "Explore Working Copy"] \
2558 -command {do_explore}
2559 .mbar.repository add separator
2562 .mbar.repository add command \
2563 -label [mc "Browse Current Branch's Files"] \
2564 -command {browser::new $current_branch}
2565 set ui_browse_current [.mbar.repository index last]
2566 .mbar.repository add command \
2567 -label [mc "Browse Branch Files..."] \
2568 -command browser_open::dialog
2569 .mbar.repository add separator
2571 .mbar.repository add command \
2572 -label [mc "Visualize Current Branch's History"] \
2573 -command {do_gitk $current_branch}
2574 set ui_visualize_current [.mbar.repository index last]
2575 .mbar.repository add command \
2576 -label [mc "Visualize All Branch History"] \
2577 -command {do_gitk --all}
2578 .mbar.repository add separator
2580 proc current_branch_write {args} {
2581 global current_branch
2582 .mbar.repository entryconf $::ui_browse_current \
2583 -label [mc "Browse %s's Files" $current_branch]
2584 .mbar.repository entryconf $::ui_visualize_current \
2585 -label [mc "Visualize %s's History" $current_branch]
2587 trace add variable current_branch write current_branch_write
2589 if {[is_enabled multicommit]} {
2590 .mbar.repository add command -label [mc "Database Statistics"] \
2591 -command do_stats
2593 .mbar.repository add command -label [mc "Compress Database"] \
2594 -command do_gc
2596 .mbar.repository add command -label [mc "Verify Database"] \
2597 -command do_fsck_objects
2599 .mbar.repository add separator
2601 if {[is_Cygwin]} {
2602 .mbar.repository add command \
2603 -label [mc "Create Desktop Icon"] \
2604 -command do_cygwin_shortcut
2605 } elseif {[is_Windows]} {
2606 .mbar.repository add command \
2607 -label [mc "Create Desktop Icon"] \
2608 -command do_windows_shortcut
2609 } elseif {[is_MacOSX]} {
2610 .mbar.repository add command \
2611 -label [mc "Create Desktop Icon"] \
2612 -command do_macosx_app
2616 if {[is_MacOSX]} {
2617 proc ::tk::mac::Quit {args} { do_quit }
2618 } else {
2619 .mbar.repository add command -label [mc Quit] \
2620 -command do_quit \
2621 -accelerator $M1T-Q
2624 # -- Edit Menu
2626 menu .mbar.edit
2627 .mbar.edit add command -label [mc Undo] \
2628 -command {catch {[focus] edit undo}} \
2629 -accelerator $M1T-Z
2630 .mbar.edit add command -label [mc Redo] \
2631 -command {catch {[focus] edit redo}} \
2632 -accelerator $M1T-Y
2633 .mbar.edit add separator
2634 .mbar.edit add command -label [mc Cut] \
2635 -command {catch {tk_textCut [focus]}} \
2636 -accelerator $M1T-X
2637 .mbar.edit add command -label [mc Copy] \
2638 -command {catch {tk_textCopy [focus]}} \
2639 -accelerator $M1T-C
2640 .mbar.edit add command -label [mc Paste] \
2641 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
2642 -accelerator $M1T-V
2643 .mbar.edit add command -label [mc Delete] \
2644 -command {catch {[focus] delete sel.first sel.last}} \
2645 -accelerator Del
2646 .mbar.edit add separator
2647 .mbar.edit add command -label [mc "Select All"] \
2648 -command {catch {[focus] tag add sel 0.0 end}} \
2649 -accelerator $M1T-A
2651 # -- Branch Menu
2653 if {[is_enabled branch]} {
2654 menu .mbar.branch
2656 .mbar.branch add command -label [mc "Create..."] \
2657 -command branch_create::dialog \
2658 -accelerator $M1T-N
2659 lappend disable_on_lock [list .mbar.branch entryconf \
2660 [.mbar.branch index last] -state]
2662 .mbar.branch add command -label [mc "Checkout..."] \
2663 -command branch_checkout::dialog \
2664 -accelerator $M1T-O
2665 lappend disable_on_lock [list .mbar.branch entryconf \
2666 [.mbar.branch index last] -state]
2668 .mbar.branch add command -label [mc "Rename..."] \
2669 -command branch_rename::dialog
2670 lappend disable_on_lock [list .mbar.branch entryconf \
2671 [.mbar.branch index last] -state]
2673 .mbar.branch add command -label [mc "Delete..."] \
2674 -command branch_delete::dialog
2675 lappend disable_on_lock [list .mbar.branch entryconf \
2676 [.mbar.branch index last] -state]
2678 .mbar.branch add command -label [mc "Reset..."] \
2679 -command merge::reset_hard
2680 lappend disable_on_lock [list .mbar.branch entryconf \
2681 [.mbar.branch index last] -state]
2684 # -- Commit Menu
2686 proc commit_btn_caption {} {
2687 if {[is_enabled nocommit]} {
2688 return [mc "Done"]
2689 } else {
2690 return [mc Commit@@verb]
2694 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2695 menu .mbar.commit
2697 if {![is_enabled nocommit]} {
2698 .mbar.commit add radiobutton \
2699 -label [mc "New Commit"] \
2700 -command do_select_commit_type \
2701 -variable selected_commit_type \
2702 -value new
2703 lappend disable_on_lock \
2704 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2706 .mbar.commit add radiobutton \
2707 -label [mc "Amend Last Commit"] \
2708 -command do_select_commit_type \
2709 -variable selected_commit_type \
2710 -value amend
2711 lappend disable_on_lock \
2712 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2714 .mbar.commit add separator
2717 .mbar.commit add command -label [mc Rescan] \
2718 -command ui_do_rescan \
2719 -accelerator F5
2720 lappend disable_on_lock \
2721 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2723 .mbar.commit add command -label [mc "Stage To Commit"] \
2724 -command do_add_selection \
2725 -accelerator $M1T-T
2726 lappend disable_on_lock \
2727 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2729 .mbar.commit add command -label [mc "Stage Changed Files To Commit"] \
2730 -command do_add_all \
2731 -accelerator $M1T-I
2732 lappend disable_on_lock \
2733 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2735 .mbar.commit add command -label [mc "Unstage From Commit"] \
2736 -command do_unstage_selection \
2737 -accelerator $M1T-U
2738 lappend disable_on_lock \
2739 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2741 .mbar.commit add command -label [mc "Revert Changes"] \
2742 -command do_revert_selection \
2743 -accelerator $M1T-J
2744 lappend disable_on_lock \
2745 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2747 .mbar.commit add separator
2749 .mbar.commit add command -label [mc "Show Less Context"] \
2750 -command show_less_context \
2751 -accelerator $M1T-\-
2753 .mbar.commit add command -label [mc "Show More Context"] \
2754 -command show_more_context \
2755 -accelerator $M1T-=
2757 .mbar.commit add separator
2759 if {![is_enabled nocommitmsg]} {
2760 .mbar.commit add command -label [mc "Sign Off"] \
2761 -command do_signoff \
2762 -accelerator $M1T-S
2765 .mbar.commit add command -label [commit_btn_caption] \
2766 -command do_commit \
2767 -accelerator $M1T-Return
2768 lappend disable_on_lock \
2769 [list .mbar.commit entryconf [.mbar.commit index last] -state]
2772 # -- Merge Menu
2774 if {[is_enabled branch]} {
2775 menu .mbar.merge
2776 .mbar.merge add command -label [mc "Local Merge..."] \
2777 -command merge::dialog \
2778 -accelerator $M1T-M
2779 lappend disable_on_lock \
2780 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2781 .mbar.merge add command -label [mc "Abort Merge..."] \
2782 -command merge::reset_hard
2783 lappend disable_on_lock \
2784 [list .mbar.merge entryconf [.mbar.merge index last] -state]
2787 # -- Transport Menu
2789 if {[is_enabled transport]} {
2790 menu .mbar.remote
2792 .mbar.remote add command \
2793 -label [mc "Add..."] \
2794 -command remote_add::dialog \
2795 -accelerator $M1T-A
2796 .mbar.remote add command \
2797 -label [mc "Push..."] \
2798 -command do_push_anywhere \
2799 -accelerator $M1T-P
2800 .mbar.remote add command \
2801 -label [mc "Delete Branch..."] \
2802 -command remote_branch_delete::dialog
2805 if {[is_MacOSX]} {
2806 proc ::tk::mac::ShowPreferences {} {do_options}
2807 } else {
2808 # -- Edit Menu
2810 .mbar.edit add separator
2811 .mbar.edit add command -label [mc "Options..."] \
2812 -command do_options
2815 # -- Tools Menu
2817 if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2818 set tools_menubar .mbar.tools
2819 menu $tools_menubar
2820 $tools_menubar add separator
2821 $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog
2822 $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog
2823 set tools_tailcnt 3
2824 if {[array names repo_config guitool.*.cmd] ne {}} {
2825 tools_populate_all
2829 # -- Help Menu
2831 .mbar add cascade -label [mc Help] -menu .mbar.help
2832 menu .mbar.help
2834 if {[is_MacOSX]} {
2835 .mbar.apple add command -label [mc "About %s" [appname]] \
2836 -command do_about
2837 .mbar.apple add separator
2838 } else {
2839 .mbar.help add command -label [mc "About %s" [appname]] \
2840 -command do_about
2842 . configure -menu .mbar
2844 set doc_path [githtmldir]
2845 if {$doc_path ne {}} {
2846 set doc_path [file join $doc_path index.html]
2848 if {[is_Cygwin]} {
2849 set doc_path [exec cygpath --mixed $doc_path]
2853 if {[file isfile $doc_path]} {
2854 set doc_url "file:$doc_path"
2855 } else {
2856 set doc_url {http://www.kernel.org/pub/software/scm/git/docs/}
2859 proc start_browser {url} {
2860 git "web--browse" $url
2863 .mbar.help add command -label [mc "Online Documentation"] \
2864 -command [list start_browser $doc_url]
2866 .mbar.help add command -label [mc "Show SSH Key"] \
2867 -command do_ssh_key
2869 unset doc_path doc_url
2871 # -- Standard bindings
2873 wm protocol . WM_DELETE_WINDOW do_quit
2874 bind all <$M1B-Key-q> do_quit
2875 bind all <$M1B-Key-Q> do_quit
2876 bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
2877 bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
2879 set subcommand_args {}
2880 proc usage {} {
2881 set s "usage: $::argv0 $::subcommand $::subcommand_args"
2882 if {[tk windowingsystem] eq "win32"} {
2883 wm withdraw .
2884 tk_messageBox -icon info -message $s \
2885 -title [mc "Usage"]
2886 } else {
2887 puts stderr $s
2889 exit 1
2892 proc normalize_relpath {path} {
2893 set elements {}
2894 foreach item [file split $path] {
2895 if {$item eq {.}} continue
2896 if {$item eq {..} && [llength $elements] > 0
2897 && [lindex $elements end] ne {..}} {
2898 set elements [lrange $elements 0 end-1]
2899 continue
2901 lappend elements $item
2903 return [eval file join $elements]
2906 # -- Not a normal commit type invocation? Do that instead!
2908 switch -- $subcommand {
2909 browser -
2910 blame {
2911 if {$subcommand eq "blame"} {
2912 set subcommand_args {[--line=<num>] rev? path}
2913 } else {
2914 set subcommand_args {rev? path}
2916 if {$argv eq {}} usage
2917 set head {}
2918 set path {}
2919 set jump_spec {}
2920 set is_path 0
2921 foreach a $argv {
2922 if {$is_path || [file exists $_prefix$a]} {
2923 if {$path ne {}} usage
2924 set path [normalize_relpath $_prefix$a]
2925 break
2926 } elseif {$a eq {--}} {
2927 if {$path ne {}} {
2928 if {$head ne {}} usage
2929 set head $path
2930 set path {}
2932 set is_path 1
2933 } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
2934 if {$jump_spec ne {} || $head ne {}} usage
2935 set jump_spec [list $lnum]
2936 } elseif {$head eq {}} {
2937 if {$head ne {}} usage
2938 set head $a
2939 set is_path 1
2940 } else {
2941 usage
2944 unset is_path
2946 if {$head ne {} && $path eq {}} {
2947 set path [normalize_relpath $_prefix$head]
2948 set head {}
2951 if {$head eq {}} {
2952 load_current_branch
2953 } else {
2954 if {[regexp {^[0-9a-f]{1,39}$} $head]} {
2955 if {[catch {
2956 set head [git rev-parse --verify $head]
2957 } err]} {
2958 if {[tk windowingsystem] eq "win32"} {
2959 tk_messageBox -icon error -title [mc Error] -message $err
2960 } else {
2961 puts stderr $err
2963 exit 1
2966 set current_branch $head
2969 wm deiconify .
2970 switch -- $subcommand {
2971 browser {
2972 if {$jump_spec ne {}} usage
2973 if {$head eq {}} {
2974 if {$path ne {} && [file isdirectory $path]} {
2975 set head $current_branch
2976 } else {
2977 set head $path
2978 set path {}
2981 browser::new $head $path
2983 blame {
2984 if {$head eq {} && ![file exists $path]} {
2985 catch {wm withdraw .}
2986 tk_messageBox \
2987 -icon error \
2988 -type ok \
2989 -title [mc "git-gui: fatal error"] \
2990 -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
2991 exit 1
2993 blame::new $head $path $jump_spec
2996 return
2998 citool -
2999 gui {
3000 if {[llength $argv] != 0} {
3001 usage
3003 # fall through to setup UI for commits
3005 default {
3006 set err "usage: $argv0 \[{blame|browser|citool}\]"
3007 if {[tk windowingsystem] eq "win32"} {
3008 wm withdraw .
3009 tk_messageBox -icon error -message $err \
3010 -title [mc "Usage"]
3011 } else {
3012 puts stderr $err
3014 exit 1
3018 # -- Branch Control
3020 ${NS}::frame .branch
3021 if {!$use_ttk} {.branch configure -borderwidth 1 -relief sunken}
3022 ${NS}::label .branch.l1 \
3023 -text [mc "Current Branch:"] \
3024 -anchor w \
3025 -justify left
3026 ${NS}::label .branch.cb \
3027 -textvariable current_branch \
3028 -anchor w \
3029 -justify left
3030 pack .branch.l1 -side left
3031 pack .branch.cb -side left -fill x
3032 pack .branch -side top -fill x
3034 # -- Main Window Layout
3036 ${NS}::panedwindow .vpane -orient horizontal
3037 ${NS}::panedwindow .vpane.files -orient vertical
3038 if {$use_ttk} {
3039 .vpane add .vpane.files
3040 } else {
3041 .vpane add .vpane.files -sticky nsew -height 100 -width 200
3043 pack .vpane -anchor n -side top -fill both -expand 1
3045 # -- Index File List
3047 ${NS}::frame .vpane.files.index -height 100 -width 200
3048 tlabel .vpane.files.index.title \
3049 -text [mc "Staged Changes (Will Commit)"] \
3050 -background lightgreen -foreground black
3051 text $ui_index -background white -foreground black \
3052 -borderwidth 0 \
3053 -width 20 -height 10 \
3054 -wrap none \
3055 -cursor $cursor_ptr \
3056 -xscrollcommand {.vpane.files.index.sx set} \
3057 -yscrollcommand {.vpane.files.index.sy set} \
3058 -state disabled
3059 ${NS}::scrollbar .vpane.files.index.sx -orient h -command [list $ui_index xview]
3060 ${NS}::scrollbar .vpane.files.index.sy -orient v -command [list $ui_index yview]
3061 pack .vpane.files.index.title -side top -fill x
3062 pack .vpane.files.index.sx -side bottom -fill x
3063 pack .vpane.files.index.sy -side right -fill y
3064 pack $ui_index -side left -fill both -expand 1
3066 # -- Working Directory File List
3068 ${NS}::frame .vpane.files.workdir -height 100 -width 200
3069 tlabel .vpane.files.workdir.title -text [mc "Unstaged Changes"] \
3070 -background lightsalmon -foreground black
3071 text $ui_workdir -background white -foreground black \
3072 -borderwidth 0 \
3073 -width 20 -height 10 \
3074 -wrap none \
3075 -cursor $cursor_ptr \
3076 -xscrollcommand {.vpane.files.workdir.sx set} \
3077 -yscrollcommand {.vpane.files.workdir.sy set} \
3078 -state disabled
3079 ${NS}::scrollbar .vpane.files.workdir.sx -orient h -command [list $ui_workdir xview]
3080 ${NS}::scrollbar .vpane.files.workdir.sy -orient v -command [list $ui_workdir yview]
3081 pack .vpane.files.workdir.title -side top -fill x
3082 pack .vpane.files.workdir.sx -side bottom -fill x
3083 pack .vpane.files.workdir.sy -side right -fill y
3084 pack $ui_workdir -side left -fill both -expand 1
3086 .vpane.files add .vpane.files.workdir
3087 .vpane.files add .vpane.files.index
3088 if {!$use_ttk} {
3089 .vpane.files paneconfigure .vpane.files.workdir -sticky news
3090 .vpane.files paneconfigure .vpane.files.index -sticky news
3093 foreach i [list $ui_index $ui_workdir] {
3094 rmsel_tag $i
3095 $i tag conf in_diff -background [$i tag cget in_sel -background]
3097 unset i
3099 # -- Diff and Commit Area
3101 ${NS}::frame .vpane.lower -height 300 -width 400
3102 ${NS}::frame .vpane.lower.commarea
3103 ${NS}::frame .vpane.lower.diff -relief sunken -borderwidth 1
3104 pack .vpane.lower.diff -fill both -expand 1
3105 pack .vpane.lower.commarea -side bottom -fill x
3106 .vpane add .vpane.lower
3107 if {!$use_ttk} {.vpane paneconfigure .vpane.lower -sticky nsew}
3109 # -- Commit Area Buttons
3111 ${NS}::frame .vpane.lower.commarea.buttons
3112 ${NS}::label .vpane.lower.commarea.buttons.l -text {} \
3113 -anchor w \
3114 -justify left
3115 pack .vpane.lower.commarea.buttons.l -side top -fill x
3116 pack .vpane.lower.commarea.buttons -side left -fill y
3118 ${NS}::button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
3119 -command ui_do_rescan
3120 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
3121 lappend disable_on_lock \
3122 {.vpane.lower.commarea.buttons.rescan conf -state}
3124 ${NS}::button .vpane.lower.commarea.buttons.incall -text [mc "Stage Changed"] \
3125 -command do_add_all
3126 pack .vpane.lower.commarea.buttons.incall -side top -fill x
3127 lappend disable_on_lock \
3128 {.vpane.lower.commarea.buttons.incall conf -state}
3130 if {![is_enabled nocommitmsg]} {
3131 ${NS}::button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \
3132 -command do_signoff
3133 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
3136 ${NS}::button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \
3137 -command do_commit
3138 pack .vpane.lower.commarea.buttons.commit -side top -fill x
3139 lappend disable_on_lock \
3140 {.vpane.lower.commarea.buttons.commit conf -state}
3142 if {![is_enabled nocommit]} {
3143 ${NS}::button .vpane.lower.commarea.buttons.push -text [mc Push] \
3144 -command do_push_anywhere
3145 pack .vpane.lower.commarea.buttons.push -side top -fill x
3148 # -- Commit Message Buffer
3150 ${NS}::frame .vpane.lower.commarea.buffer
3151 ${NS}::frame .vpane.lower.commarea.buffer.header
3152 set ui_comm .vpane.lower.commarea.buffer.t
3153 set ui_coml .vpane.lower.commarea.buffer.header.l
3155 if {![is_enabled nocommit]} {
3156 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.new \
3157 -text [mc "New Commit"] \
3158 -command do_select_commit_type \
3159 -variable selected_commit_type \
3160 -value new
3161 lappend disable_on_lock \
3162 [list .vpane.lower.commarea.buffer.header.new conf -state]
3163 ${NS}::radiobutton .vpane.lower.commarea.buffer.header.amend \
3164 -text [mc "Amend Last Commit"] \
3165 -command do_select_commit_type \
3166 -variable selected_commit_type \
3167 -value amend
3168 lappend disable_on_lock \
3169 [list .vpane.lower.commarea.buffer.header.amend conf -state]
3172 ${NS}::label $ui_coml \
3173 -anchor w \
3174 -justify left
3175 proc trace_commit_type {varname args} {
3176 global ui_coml commit_type
3177 switch -glob -- $commit_type {
3178 initial {set txt [mc "Initial Commit Message:"]}
3179 amend {set txt [mc "Amended Commit Message:"]}
3180 amend-initial {set txt [mc "Amended Initial Commit Message:"]}
3181 amend-merge {set txt [mc "Amended Merge Commit Message:"]}
3182 merge {set txt [mc "Merge Commit Message:"]}
3183 * {set txt [mc "Commit Message:"]}
3185 $ui_coml conf -text $txt
3187 trace add variable commit_type write trace_commit_type
3188 pack $ui_coml -side left -fill x
3190 if {![is_enabled nocommit]} {
3191 pack .vpane.lower.commarea.buffer.header.amend -side right
3192 pack .vpane.lower.commarea.buffer.header.new -side right
3195 text $ui_comm -background white -foreground black \
3196 -borderwidth 1 \
3197 -undo true \
3198 -maxundo 20 \
3199 -autoseparators true \
3200 -relief sunken \
3201 -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
3202 -font font_diff \
3203 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
3204 ${NS}::scrollbar .vpane.lower.commarea.buffer.sby \
3205 -command [list $ui_comm yview]
3206 pack .vpane.lower.commarea.buffer.header -side top -fill x
3207 pack .vpane.lower.commarea.buffer.sby -side right -fill y
3208 pack $ui_comm -side left -fill y
3209 pack .vpane.lower.commarea.buffer -side left -fill y
3211 # -- Commit Message Buffer Context Menu
3213 set ctxm .vpane.lower.commarea.buffer.ctxm
3214 menu $ctxm -tearoff 0
3215 $ctxm add command \
3216 -label [mc Cut] \
3217 -command {tk_textCut $ui_comm}
3218 $ctxm add command \
3219 -label [mc Copy] \
3220 -command {tk_textCopy $ui_comm}
3221 $ctxm add command \
3222 -label [mc Paste] \
3223 -command {tk_textPaste $ui_comm}
3224 $ctxm add command \
3225 -label [mc Delete] \
3226 -command {catch {$ui_comm delete sel.first sel.last}}
3227 $ctxm add separator
3228 $ctxm add command \
3229 -label [mc "Select All"] \
3230 -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
3231 $ctxm add command \
3232 -label [mc "Copy All"] \
3233 -command {
3234 $ui_comm tag add sel 0.0 end
3235 tk_textCopy $ui_comm
3236 $ui_comm tag remove sel 0.0 end
3238 $ctxm add separator
3239 $ctxm add command \
3240 -label [mc "Sign Off"] \
3241 -command do_signoff
3242 set ui_comm_ctxm $ctxm
3244 # -- Diff Header
3246 proc trace_current_diff_path {varname args} {
3247 global current_diff_path diff_actions file_states
3248 if {$current_diff_path eq {}} {
3249 set s {}
3250 set f {}
3251 set p {}
3252 set o disabled
3253 } else {
3254 set p $current_diff_path
3255 set s [mapdesc [lindex $file_states($p) 0] $p]
3256 set f [mc "File:"]
3257 set p [escape_path $p]
3258 set o normal
3261 .vpane.lower.diff.header.status configure -text $s
3262 .vpane.lower.diff.header.file configure -text $f
3263 .vpane.lower.diff.header.path configure -text $p
3264 foreach w $diff_actions {
3265 uplevel #0 $w $o
3268 trace add variable current_diff_path write trace_current_diff_path
3270 gold_frame .vpane.lower.diff.header
3271 tlabel .vpane.lower.diff.header.status \
3272 -background gold \
3273 -foreground black \
3274 -width $max_status_desc \
3275 -anchor w \
3276 -justify left
3277 tlabel .vpane.lower.diff.header.file \
3278 -background gold \
3279 -foreground black \
3280 -anchor w \
3281 -justify left
3282 tlabel .vpane.lower.diff.header.path \
3283 -background gold \
3284 -foreground black \
3285 -anchor w \
3286 -justify left
3287 pack .vpane.lower.diff.header.status -side left
3288 pack .vpane.lower.diff.header.file -side left
3289 pack .vpane.lower.diff.header.path -fill x
3290 set ctxm .vpane.lower.diff.header.ctxm
3291 menu $ctxm -tearoff 0
3292 $ctxm add command \
3293 -label [mc Copy] \
3294 -command {
3295 clipboard clear
3296 clipboard append \
3297 -format STRING \
3298 -type STRING \
3299 -- $current_diff_path
3301 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3302 bind_button3 .vpane.lower.diff.header.path "tk_popup $ctxm %X %Y"
3304 # -- Diff Body
3306 ${NS}::frame .vpane.lower.diff.body
3307 set ui_diff .vpane.lower.diff.body.t
3308 text $ui_diff -background white -foreground black \
3309 -borderwidth 0 \
3310 -width 80 -height 5 -wrap none \
3311 -font font_diff \
3312 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
3313 -yscrollcommand {.vpane.lower.diff.body.sby set} \
3314 -state disabled
3315 catch {$ui_diff configure -tabstyle wordprocessor}
3316 ${NS}::scrollbar .vpane.lower.diff.body.sbx -orient horizontal \
3317 -command [list $ui_diff xview]
3318 ${NS}::scrollbar .vpane.lower.diff.body.sby -orient vertical \
3319 -command [list $ui_diff yview]
3320 pack .vpane.lower.diff.body.sbx -side bottom -fill x
3321 pack .vpane.lower.diff.body.sby -side right -fill y
3322 pack $ui_diff -side left -fill both -expand 1
3323 pack .vpane.lower.diff.header -side top -fill x
3324 pack .vpane.lower.diff.body -side bottom -fill both -expand 1
3326 foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {
3327 $ui_diff tag configure clr4$n -background $c
3328 $ui_diff tag configure clri4$n -foreground $c
3329 $ui_diff tag configure clr3$n -foreground $c
3330 $ui_diff tag configure clri3$n -background $c
3332 $ui_diff tag configure clr1 -font font_diffbold
3334 $ui_diff tag conf d_cr -elide true
3335 $ui_diff tag conf d_@ -font font_diffbold
3336 $ui_diff tag conf d_+ -foreground {#00a000}
3337 $ui_diff tag conf d_- -foreground red
3339 $ui_diff tag conf d_++ -foreground {#00a000}
3340 $ui_diff tag conf d_-- -foreground red
3341 $ui_diff tag conf d_+s \
3342 -foreground {#00a000} \
3343 -background {#e2effa}
3344 $ui_diff tag conf d_-s \
3345 -foreground red \
3346 -background {#e2effa}
3347 $ui_diff tag conf d_s+ \
3348 -foreground {#00a000} \
3349 -background ivory1
3350 $ui_diff tag conf d_s- \
3351 -foreground red \
3352 -background ivory1
3354 $ui_diff tag conf d<<<<<<< \
3355 -foreground orange \
3356 -font font_diffbold
3357 $ui_diff tag conf d======= \
3358 -foreground orange \
3359 -font font_diffbold
3360 $ui_diff tag conf d>>>>>>> \
3361 -foreground orange \
3362 -font font_diffbold
3364 $ui_diff tag raise sel
3366 # -- Diff Body Context Menu
3369 proc create_common_diff_popup {ctxm} {
3370 $ctxm add command \
3371 -label [mc Refresh] \
3372 -command reshow_diff
3373 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3374 $ctxm add command \
3375 -label [mc Copy] \
3376 -command {tk_textCopy $ui_diff}
3377 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3378 $ctxm add command \
3379 -label [mc "Select All"] \
3380 -command {focus $ui_diff;$ui_diff tag add sel 0.0 end}
3381 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3382 $ctxm add command \
3383 -label [mc "Copy All"] \
3384 -command {
3385 $ui_diff tag add sel 0.0 end
3386 tk_textCopy $ui_diff
3387 $ui_diff tag remove sel 0.0 end
3389 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3390 $ctxm add separator
3391 $ctxm add command \
3392 -label [mc "Decrease Font Size"] \
3393 -command {incr_font_size font_diff -1}
3394 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3395 $ctxm add command \
3396 -label [mc "Increase Font Size"] \
3397 -command {incr_font_size font_diff 1}
3398 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3399 $ctxm add separator
3400 set emenu $ctxm.enc
3401 menu $emenu
3402 build_encoding_menu $emenu [list force_diff_encoding]
3403 $ctxm add cascade \
3404 -label [mc "Encoding"] \
3405 -menu $emenu
3406 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3407 $ctxm add separator
3408 $ctxm add command -label [mc "Options..."] \
3409 -command do_options
3412 set ctxm .vpane.lower.diff.body.ctxm
3413 menu $ctxm -tearoff 0
3414 $ctxm add command \
3415 -label [mc "Apply/Reverse Hunk"] \
3416 -command {apply_hunk $cursorX $cursorY}
3417 set ui_diff_applyhunk [$ctxm index last]
3418 lappend diff_actions [list $ctxm entryconf $ui_diff_applyhunk -state]
3419 $ctxm add command \
3420 -label [mc "Apply/Reverse Line"] \
3421 -command {apply_range_or_line $cursorX $cursorY; do_rescan}
3422 set ui_diff_applyline [$ctxm index last]
3423 lappend diff_actions [list $ctxm entryconf $ui_diff_applyline -state]
3424 $ctxm add separator
3425 $ctxm add command \
3426 -label [mc "Show Less Context"] \
3427 -command show_less_context
3428 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3429 $ctxm add command \
3430 -label [mc "Show More Context"] \
3431 -command show_more_context
3432 lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3433 $ctxm add separator
3434 create_common_diff_popup $ctxm
3436 set ctxmmg .vpane.lower.diff.body.ctxmmg
3437 menu $ctxmmg -tearoff 0
3438 $ctxmmg add command \
3439 -label [mc "Run Merge Tool"] \
3440 -command {merge_resolve_tool}
3441 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3442 $ctxmmg add separator
3443 $ctxmmg add command \
3444 -label [mc "Use Remote Version"] \
3445 -command {merge_resolve_one 3}
3446 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3447 $ctxmmg add command \
3448 -label [mc "Use Local Version"] \
3449 -command {merge_resolve_one 2}
3450 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3451 $ctxmmg add command \
3452 -label [mc "Revert To Base"] \
3453 -command {merge_resolve_one 1}
3454 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3455 $ctxmmg add separator
3456 $ctxmmg add command \
3457 -label [mc "Show Less Context"] \
3458 -command show_less_context
3459 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3460 $ctxmmg add command \
3461 -label [mc "Show More Context"] \
3462 -command show_more_context
3463 lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state]
3464 $ctxmmg add separator
3465 create_common_diff_popup $ctxmmg
3467 set ctxmsm .vpane.lower.diff.body.ctxmsm
3468 menu $ctxmsm -tearoff 0
3469 $ctxmsm add command \
3470 -label [mc "Visualize These Changes In The Submodule"] \
3471 -command {do_gitk -- true}
3472 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3473 $ctxmsm add command \
3474 -label [mc "Visualize Current Branch History In The Submodule"] \
3475 -command {do_gitk {} true}
3476 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3477 $ctxmsm add command \
3478 -label [mc "Visualize All Branch History In The Submodule"] \
3479 -command {do_gitk --all true}
3480 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3481 $ctxmsm add separator
3482 $ctxmsm add command \
3483 -label [mc "Start git gui In The Submodule"] \
3484 -command {do_git_gui}
3485 lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
3486 $ctxmsm add separator
3487 create_common_diff_popup $ctxmsm
3489 proc has_textconv {path} {
3490 if {[is_config_false gui.textconv]} {
3491 return 0
3493 set filter [gitattr $path diff set]
3494 set textconv [get_config [join [list diff $filter textconv] .]]
3495 if {$filter ne {set} && $textconv ne {}} {
3496 return 1
3497 } else {
3498 return 0
3502 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
3503 global current_diff_path file_states
3504 set ::cursorX $x
3505 set ::cursorY $y
3506 if {[info exists file_states($current_diff_path)]} {
3507 set state [lindex $file_states($current_diff_path) 0]
3508 } else {
3509 set state {__}
3511 if {[string first {U} $state] >= 0} {
3512 tk_popup $ctxmmg $X $Y
3513 } elseif {$::is_submodule_diff} {
3514 tk_popup $ctxmsm $X $Y
3515 } else {
3516 set has_range [expr {[$::ui_diff tag nextrange sel 0.0] != {}}]
3517 if {$::ui_index eq $::current_diff_side} {
3518 set l [mc "Unstage Hunk From Commit"]
3519 if {$has_range} {
3520 set t [mc "Unstage Lines From Commit"]
3521 } else {
3522 set t [mc "Unstage Line From Commit"]
3524 } else {
3525 set l [mc "Stage Hunk For Commit"]
3526 if {$has_range} {
3527 set t [mc "Stage Lines For Commit"]
3528 } else {
3529 set t [mc "Stage Line For Commit"]
3532 if {$::is_3way_diff
3533 || $current_diff_path eq {}
3534 || {__} eq $state
3535 || {_O} eq $state
3536 || {_T} eq $state
3537 || {T_} eq $state
3538 || [has_textconv $current_diff_path]} {
3539 set s disabled
3540 } else {
3541 set s normal
3543 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
3544 $ctxm entryconf $::ui_diff_applyline -state $s -label $t
3545 tk_popup $ctxm $X $Y
3548 bind_button3 $ui_diff [list popup_diff_menu $ctxm $ctxmmg $ctxmsm %x %y %X %Y]
3550 # -- Status Bar
3552 set main_status [::status_bar::new .status]
3553 pack .status -anchor w -side bottom -fill x
3554 $main_status show [mc "Initializing..."]
3556 # -- Load geometry
3558 proc on_ttk_pane_mapped {w pane pos} {
3559 bind $w <Map> {}
3560 after 0 [list after idle [list $w sashpos $pane $pos]]
3562 proc on_tk_pane_mapped {w pane x y} {
3563 bind $w <Map> {}
3564 after 0 [list after idle [list $w sash place $pane $x $y]]
3566 proc on_application_mapped {} {
3567 global repo_config use_ttk
3568 bind . <Map> {}
3569 set gm $repo_config(gui.geometry)
3570 if {$use_ttk} {
3571 bind .vpane <Map> \
3572 [list on_ttk_pane_mapped %W 0 [lindex $gm 1]]
3573 bind .vpane.files <Map> \
3574 [list on_ttk_pane_mapped %W 0 [lindex $gm 2]]
3575 } else {
3576 bind .vpane <Map> \
3577 [list on_tk_pane_mapped %W 0 \
3578 [lindex $gm 1] \
3579 [lindex [.vpane sash coord 0] 1]]
3580 bind .vpane.files <Map> \
3581 [list on_tk_pane_mapped %W 0 \
3582 [lindex [.vpane.files sash coord 0] 0] \
3583 [lindex $gm 2]]
3585 wm geometry . [lindex $gm 0]
3587 if {[info exists repo_config(gui.geometry)]} {
3588 bind . <Map> [list on_application_mapped]
3589 wm geometry . [lindex $repo_config(gui.geometry) 0]
3592 # -- Load window state
3594 if {[info exists repo_config(gui.wmstate)]} {
3595 catch {wm state . $repo_config(gui.wmstate)}
3598 # -- Key Bindings
3600 bind $ui_comm <$M1B-Key-Return> {do_commit;break}
3601 bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
3602 bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
3603 bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
3604 bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
3605 bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
3606 bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
3607 bind $ui_comm <$M1B-Key-i> {do_add_all;break}
3608 bind $ui_comm <$M1B-Key-I> {do_add_all;break}
3609 bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
3610 bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
3611 bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
3612 bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
3613 bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
3614 bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
3615 bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3616 bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3617 bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
3618 bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
3619 bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
3620 bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
3621 bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
3623 bind $ui_diff <$M1B-Key-x> {tk_textCopy %W;break}
3624 bind $ui_diff <$M1B-Key-X> {tk_textCopy %W;break}
3625 bind $ui_diff <$M1B-Key-c> {tk_textCopy %W;break}
3626 bind $ui_diff <$M1B-Key-C> {tk_textCopy %W;break}
3627 bind $ui_diff <$M1B-Key-v> {break}
3628 bind $ui_diff <$M1B-Key-V> {break}
3629 bind $ui_diff <$M1B-Key-a> {%W tag add sel 0.0 end;break}
3630 bind $ui_diff <$M1B-Key-A> {%W tag add sel 0.0 end;break}
3631 bind $ui_diff <Key-Up> {catch {%W yview scroll -1 units};break}
3632 bind $ui_diff <Key-Down> {catch {%W yview scroll 1 units};break}
3633 bind $ui_diff <Key-Left> {catch {%W xview scroll -1 units};break}
3634 bind $ui_diff <Key-Right> {catch {%W xview scroll 1 units};break}
3635 bind $ui_diff <Key-k> {catch {%W yview scroll -1 units};break}
3636 bind $ui_diff <Key-j> {catch {%W yview scroll 1 units};break}
3637 bind $ui_diff <Key-h> {catch {%W xview scroll -1 units};break}
3638 bind $ui_diff <Key-l> {catch {%W xview scroll 1 units};break}
3639 bind $ui_diff <Control-Key-b> {catch {%W yview scroll -1 pages};break}
3640 bind $ui_diff <Control-Key-f> {catch {%W yview scroll 1 pages};break}
3641 bind $ui_diff <Button-1> {focus %W}
3643 if {[is_enabled branch]} {
3644 bind . <$M1B-Key-n> branch_create::dialog
3645 bind . <$M1B-Key-N> branch_create::dialog
3646 bind . <$M1B-Key-o> branch_checkout::dialog
3647 bind . <$M1B-Key-O> branch_checkout::dialog
3648 bind . <$M1B-Key-m> merge::dialog
3649 bind . <$M1B-Key-M> merge::dialog
3651 if {[is_enabled transport]} {
3652 bind . <$M1B-Key-p> do_push_anywhere
3653 bind . <$M1B-Key-P> do_push_anywhere
3656 bind . <Key-F5> ui_do_rescan
3657 bind . <$M1B-Key-r> ui_do_rescan
3658 bind . <$M1B-Key-R> ui_do_rescan
3659 bind . <$M1B-Key-s> do_signoff
3660 bind . <$M1B-Key-S> do_signoff
3661 bind . <$M1B-Key-t> do_add_selection
3662 bind . <$M1B-Key-T> do_add_selection
3663 bind . <$M1B-Key-j> do_revert_selection
3664 bind . <$M1B-Key-J> do_revert_selection
3665 bind . <$M1B-Key-i> do_add_all
3666 bind . <$M1B-Key-I> do_add_all
3667 bind . <$M1B-Key-minus> {show_less_context;break}
3668 bind . <$M1B-Key-KP_Subtract> {show_less_context;break}
3669 bind . <$M1B-Key-equal> {show_more_context;break}
3670 bind . <$M1B-Key-plus> {show_more_context;break}
3671 bind . <$M1B-Key-KP_Add> {show_more_context;break}
3672 bind . <$M1B-Key-Return> do_commit
3673 foreach i [list $ui_index $ui_workdir] {
3674 bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3675 bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3676 bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3678 unset i
3680 set file_lists($ui_index) [list]
3681 set file_lists($ui_workdir) [list]
3683 wm title . "[appname] ([reponame]) [file normalize $_gitworktree]"
3684 focus -force $ui_comm
3686 # -- Warn the user about environmental problems. Cygwin's Tcl
3687 # does *not* pass its env array onto any processes it spawns.
3688 # This means that git processes get none of our environment.
3690 if {[is_Cygwin]} {
3691 set ignored_env 0
3692 set suggest_user {}
3693 set msg [mc "Possible environment issues exist.
3695 The following environment variables are probably
3696 going to be ignored by any Git subprocess run
3697 by %s:
3699 " [appname]]
3700 foreach name [array names env] {
3701 switch -regexp -- $name {
3702 {^GIT_INDEX_FILE$} -
3703 {^GIT_OBJECT_DIRECTORY$} -
3704 {^GIT_ALTERNATE_OBJECT_DIRECTORIES$} -
3705 {^GIT_DIFF_OPTS$} -
3706 {^GIT_EXTERNAL_DIFF$} -
3707 {^GIT_PAGER$} -
3708 {^GIT_TRACE$} -
3709 {^GIT_CONFIG$} -
3710 {^GIT_(AUTHOR|COMMITTER)_DATE$} {
3711 append msg " - $name\n"
3712 incr ignored_env
3714 {^GIT_(AUTHOR|COMMITTER)_(NAME|EMAIL)$} {
3715 append msg " - $name\n"
3716 incr ignored_env
3717 set suggest_user $name
3721 if {$ignored_env > 0} {
3722 append msg [mc "
3723 This is due to a known issue with the
3724 Tcl binary distributed by Cygwin."]
3726 if {$suggest_user ne {}} {
3727 append msg [mc "
3729 A good replacement for %s
3730 is placing values for the user.name and
3731 user.email settings into your personal
3732 ~/.gitconfig file.
3733 " $suggest_user]
3735 warn_popup $msg
3737 unset ignored_env msg suggest_user name
3740 # -- Only initialize complex UI if we are going to stay running.
3742 if {[is_enabled transport]} {
3743 load_all_remotes
3745 set n [.mbar.remote index end]
3746 populate_remotes_menu
3747 set n [expr {[.mbar.remote index end] - $n}]
3748 if {$n > 0} {
3749 if {[.mbar.remote type 0] eq "tearoff"} { incr n }
3750 .mbar.remote insert $n separator
3752 unset n
3755 if {[winfo exists $ui_comm]} {
3756 set GITGUI_BCK_exists [load_message GITGUI_BCK]
3758 # -- If both our backup and message files exist use the
3759 # newer of the two files to initialize the buffer.
3761 if {$GITGUI_BCK_exists} {
3762 set m [gitdir GITGUI_MSG]
3763 if {[file isfile $m]} {
3764 if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
3765 catch {file delete [gitdir GITGUI_MSG]}
3766 } else {
3767 $ui_comm delete 0.0 end
3768 $ui_comm edit reset
3769 $ui_comm edit modified false
3770 catch {file delete [gitdir GITGUI_BCK]}
3771 set GITGUI_BCK_exists 0
3774 unset m
3777 proc backup_commit_buffer {} {
3778 global ui_comm GITGUI_BCK_exists
3780 set m [$ui_comm edit modified]
3781 if {$m || $GITGUI_BCK_exists} {
3782 set msg [string trim [$ui_comm get 0.0 end]]
3783 regsub -all -line {[ \r\t]+$} $msg {} msg
3785 if {$msg eq {}} {
3786 if {$GITGUI_BCK_exists} {
3787 catch {file delete [gitdir GITGUI_BCK]}
3788 set GITGUI_BCK_exists 0
3790 } elseif {$m} {
3791 catch {
3792 set fd [open [gitdir GITGUI_BCK] w]
3793 puts -nonewline $fd $msg
3794 close $fd
3795 set GITGUI_BCK_exists 1
3799 $ui_comm edit modified false
3802 set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
3805 backup_commit_buffer
3807 # -- If the user has aspell available we can drive it
3808 # in pipe mode to spellcheck the commit message.
3810 set spell_cmd [list |]
3811 set spell_dict [get_config gui.spellingdictionary]
3812 lappend spell_cmd aspell
3813 if {$spell_dict ne {}} {
3814 lappend spell_cmd --master=$spell_dict
3816 lappend spell_cmd --mode=none
3817 lappend spell_cmd --encoding=utf-8
3818 lappend spell_cmd pipe
3819 if {$spell_dict eq {none}
3820 || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} {
3821 bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y]
3822 } else {
3823 set ui_comm_spell [spellcheck::init \
3824 $spell_fd \
3825 $ui_comm \
3826 $ui_comm_ctxm \
3829 unset -nocomplain spell_cmd spell_fd spell_err spell_dict
3832 lock_index begin-read
3833 if {![winfo ismapped .]} {
3834 wm deiconify .
3836 after 1 {
3837 if {[is_enabled initialamend]} {
3838 force_amend
3839 } else {
3840 do_rescan
3843 if {[is_enabled nocommitmsg]} {
3844 $ui_comm configure -state disabled -background gray
3847 if {[is_enabled multicommit]} {
3848 after 1000 hint_gc
3850 if {[is_enabled retcode]} {
3851 bind . <Destroy> {+terminate_me %W}
3853 if {$picked && [is_config_true gui.autoexplore]} {
3854 do_explore
3857 # Local variables:
3858 # mode: tcl
3859 # indent-tabs-mode: t
3860 # tab-width: 4
3861 # End: